just-bash 2.5.3 → 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-DV5HL4K2.js +17 -0
- package/dist/bin/chunks/{grep-JUSJYJL4.js → grep-IIVQXFNI.js} +1 -1
- package/dist/bin/{shell/chunks/rg-4VGBMMUO.js → chunks/rg-Q4OTJOEF.js} +1 -1
- package/dist/bin/just-bash.js +77 -77
- package/dist/bin/shell/chunks/chunk-DV5HL4K2.js +17 -0
- package/dist/bin/shell/chunks/{grep-JUSJYJL4.js → grep-IIVQXFNI.js} +1 -1
- package/dist/bin/{chunks/rg-4VGBMMUO.js → shell/chunks/rg-Q4OTJOEF.js} +1 -1
- package/dist/bin/shell/shell.js +8 -8
- package/dist/bundle/browser.js +160 -160
- package/dist/bundle/chunks/chunk-BOJ3OAZB.js +16 -0
- package/dist/bundle/chunks/{grep-TKGBN6VV.js → grep-ACVE42JK.js} +1 -1
- package/dist/bundle/chunks/{rg-QWPJPSNC.js → rg-YLZJWCEJ.js} +1 -1
- package/dist/bundle/index.js +101 -101
- package/package.json +1 -1
- package/dist/bin/chunks/chunk-UKYJ3JMW.js +0 -17
- package/dist/bin/shell/chunks/chunk-UKYJ3JMW.js +0 -17
- package/dist/bundle/chunks/chunk-PINJ2PBS.js +0 -16
package/dist/bundle/browser.js
CHANGED
|
@@ -148,25 +148,25 @@ Notes:
|
|
|
148
148
|
`)}
|
|
149
149
|
`:"",matched:A.length>0,matchCount:A.length}}if(W.length===0)return{output:"",matched:!1,matchCount:0};let z=new Set,X=-1,K=[];for(let _ of W){let A=Math.max(0,_.startLine-c),R=Math.min(E-1,_.endLine+u);X>=0&&A>X+1&&K.push(d);for(let $=A;$<_.startLine;$++)if(!z.has($)){z.add($),X=$;let P=w[$];s&&(P=`${$+1}-${P}`),a&&(P=`${a}-${P}`),K.push(P)}if(l){let $=g!==null?g:_.matchText,P=a?`${a}:`:"";h&&(P+=`${_.byteOffset}:`),s&&(P+=`${_.startLine+1}:`),p&&(P+=`${_.column}:`),K.push(P+$);for(let O=_.startLine;O<=_.endLine;O++)z.add(O),X=O}else for(let $=_.startLine;$<=_.endLine&&$<E;$++)if(!z.has($)){z.add($),X=$;let P=w[$];g!==null&&$===_.startLine&&(e.lastIndex=0,P=P.replace(e,g));let O=a?`${a}:`:"";h&&$===_.startLine&&(O+=`${_.byteOffset}:`),s&&(O+=`${$+1}:`),p&&$===_.startLine&&(O+=`${_.column}:`),K.push(O+P)}for(let $=_.endLine+1;$<=R;$++)if(!z.has($)){z.add($),X=$;let P=w[$];s&&(P=`${$+1}-${P}`),a&&(P=`${a}-${P}`),K.push(P)}}return{output:K.length>0?`${K.join(`
|
|
150
150
|
`)}
|
|
151
|
-
`:"",matched:!0,matchCount:W.length}}var ta=C(()=>{"use strict"});function bn(t,e){let n,r;switch(e.mode){case"fixed":n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(n=t.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),e.mode==="perl"){let
|
|
151
|
+
`:"",matched:!0,matchCount:W.length}}var ta=C(()=>{"use strict"});function bn(t,e){let n,r;switch(e.mode){case"fixed":n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");break;case"extended":case"perl":{if(n=t.replace(/\(\?P<([^>]+)>/g,"(?<$1>"),e.mode==="perl"){n=Yp(n),n=eh(n),n=th(n);let o=ih(n);n=o.pattern,r=o.kResetGroup}break}default:n=lh(t);break}e.wholeWord&&(n=`(?<![\\w])(?:${n})(?![\\w])`),e.lineRegexp&&(n=`^${n}$`);let s=/\\u\{[0-9A-Fa-f]+\}/.test(n),i="g"+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.multilineDotall?"s":"")+(s?"u":"");return{regex:new RegExp(n,i),kResetGroup:r}}function Yp(t){let e="",n=0;for(;n<t.length;)if(t[n]==="\\"&&n+1<t.length&&t[n+1]==="Q"){n+=2;let r="";for(;n<t.length;){if(t[n]==="\\"&&n+1<t.length&&t[n+1]==="E"){n+=2;break}r+=t[n],n++}e+=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}else e+=t[n],n++;return e}function eh(t){return t.replace(/\\x\{([0-9A-Fa-f]+)\}/g,"\\u{$1}")}function th(t){let e="",n=0;for(;n<t.length;){if(t[n]==="("&&n+1<t.length&&t[n+1]==="?"){let r=t.slice(n).match(/^\(\?([imsx]*)(-[imsx]*)?(:|$|\))/);if(r){let s=r[1]||"",i=r[2]||"",o=r[3];if(o===":"){let a=n+r[0].length-1,l=nh(t,n);if(l!==-1){let c=t.slice(a+1,l),u=rh(c,s,i);e+=`(?:${u})`,n=l+1;continue}}else if(o===")"||o===""){n+=r[0].length;continue}}}e+=t[n],n++}return e}function nh(t,e){let n=0,r=e;for(;r<t.length;){if(t[r]==="\\"){r+=2;continue}if(t[r]==="["){for(r++;r<t.length&&t[r]!=="]";)t[r]==="\\"&&r++,r++;r++;continue}if(t[r]==="(")n++;else if(t[r]===")"&&(n--,n===0))return r;r++}return-1}function rh(t,e,n){let r=t;return e.includes("i")&&(r=sh(r)),r}function sh(t){let e="",n=0;for(;n<t.length;){let r=t[n];if(r==="\\"){n+1<t.length?(e+=r+t[n+1],n+=2):(e+=r,n++);continue}if(r==="["){e+=r,n++,n<t.length&&t[n]==="^"&&(e+=t[n],n++);let s=[];for(;n<t.length&&t[n]!=="]";)if(t[n]==="\\")s.push(t[n]),n++,n<t.length&&(s.push(t[n]),n++);else if(t[n]==="-"&&s.length>0&&n+1<t.length&&t[n+1]!=="]"){let i=s[s.length-1],o=t[n+1];s.push("-"),s.push(o),/[a-z]/.test(i)&&/[a-z]/.test(o)?(s.push(i.toUpperCase()),s.push("-"),s.push(o.toUpperCase())):/[A-Z]/.test(i)&&/[A-Z]/.test(o)&&(s.push(i.toLowerCase()),s.push("-"),s.push(o.toLowerCase())),n+=2}else{let i=t[n];if(s.push(i),/[a-zA-Z]/.test(i)){let o=i===i.toLowerCase()?i.toUpperCase():i.toLowerCase();s.includes(o)||s.push(o)}n++}e+=s.join(""),n<t.length&&(e+=t[n],n++);continue}if(/[a-zA-Z]/.test(r)){let s=r.toLowerCase(),i=r.toUpperCase();e+=`[${i}${s}]`}else e+=r;n++}return e}function ih(t){let e=oh(t);if(e===-1)return{pattern:t};let n=t.slice(0,e),r=t.slice(e+2),s=ah(n);return{pattern:`(?:${n})(${r})`,kResetGroup:s+1}}function oh(t){let e=0;for(;e<t.length-1;)if(t[e]==="\\"){if(t[e+1]==="K"){let n=0,r=e-1;for(;r>=0&&t[r]==="\\";)n++,r--;if(n%2===0)return e}e+=2}else e++;return-1}function ah(t){let e=0,n=0;for(;n<t.length;){if(t[n]==="\\"){n+=2;continue}if(t[n]==="["){for(n++;n<t.length&&t[n]!=="]";)t[n]==="\\"&&n++,n++;n++;continue}if(t[n]==="(")if(n+1<t.length&&t[n+1]==="?"){if(n+2<t.length){let r=t[n+2];if(r===":"||r==="="||r==="!"){n++;continue}if(r==="<"&&n+3<t.length){let s=t[n+3];if(s==="="||s==="!"){n++;continue}e++,n++;continue}}}else e++;n++}return e}function ds(t){let e=t.replace(/\$\{0\}|\$0(?![0-9])/g,"$$&");return e=e.replace(/\$\{([^0-9}][^}]*)\}/g,"$$<$1>"),e=e.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)(?![>0-9])/g,"$$<$1>"),e}function lh(t){let e="",n=0;for(;n<t.length;){let r=t[n];if(r==="\\"&&n+1<t.length){let s=t[n+1];if(s==="|"||s==="("||s===")"){e+=s,n+=2;continue}else if(s==="{"||s==="}"){e+=`\\${s}`,n+=2;continue}}r==="+"||r==="?"||r==="|"||r==="("||r===")"||r==="{"||r==="}"?e+=`\\${r}`:e+=r,n++}return e}var na=C(()=>{"use strict"});var ps=C(()=>{"use strict";ta();na()});var rr={};M(rr,{egrepCommand:()=>dh,fgrepCommand:()=>fh,grepCommand:()=>hs});async function ra(t,e,n,r){let s=n.fs.resolvePath(n.cwd,t);try{if(!(await n.fs.stat(s)).isDirectory){let a=t.split("/").pop()||"";if(e){let l=e.replace(/^\//,"");De(a,l,{stripQuotes:!0})&&r.push(t)}return}let o=await n.fs.readdir(s);for(let a of o){let l=t==="."?a:`${t}/${a}`,c=n.fs.resolvePath(n.cwd,l);if((await n.fs.stat(c)).isDirectory)await ra(l,e,n,r);else if(e){let f=e.replace(/^\//,"");De(a,f,{stripQuotes:!0})&&r.push(l)}}}catch{}}async function uh(t,e){let n=[],r=t.lastIndexOf("/"),s,i;if(r===-1?(s=e.cwd,i=t):(s=t.slice(0,r)||"/",i=t.slice(r+1)),t.includes("**")){let a=[],l=t.split("**"),c=l[0].replace(/\/$/,"")||".",u=l[1]||"";return await ra(c,u,e,a),a.map(f=>({path:f}))}let o=e.fs.resolvePath(e.cwd,s);try{if(e.fs.readdirWithFileTypes){let a=await e.fs.readdirWithFileTypes(o);for(let l of a)if(De(l.name,i,{stripQuotes:!0})){let c=r===-1?l.name:`${s}/${l.name}`;n.push({path:c,isFile:l.isFile})}}else{let a=await e.fs.readdir(o);for(let l of a)if(De(l,i,{stripQuotes:!0})){let c=r===-1?l:`${s}/${l}`;n.push({path:c})}}}catch{}return n.sort((a,l)=>a.path.localeCompare(l.path))}async function nr(t,e,n=[],r=[],s=[],i){let o=e.fs.resolvePath(e.cwd,t),a=[];try{let l,c;if(i!==void 0)l=i,c=!i;else{let f=await e.fs.stat(o);l=f.isFile,c=f.isDirectory}if(l){let f=t.split("/").pop()||t;return r.length>0&&r.some(d=>De(f,d,{stripQuotes:!0}))?[]:n.length>0&&!n.some(d=>De(f,d,{stripQuotes:!0}))?[]:[{path:t,isFile:!0}]}if(!c)return[];let u=t.split("/").pop()||t;if(s.length>0&&s.some(f=>De(u,f,{stripQuotes:!0})))return[];if(e.fs.readdirWithFileTypes){let f=await e.fs.readdirWithFileTypes(o);for(let d of f){if(d.name.startsWith("."))continue;let p=t==="."?d.name:`${t}/${d.name}`,h=await nr(p,e,n,r,s,d.isFile);a.push(...h)}}else{let f=await e.fs.readdir(o);for(let d of f){if(d.startsWith("."))continue;let p=t==="."?d:`${t}/${d}`,h=await nr(p,e,n,r,s);a.push(...h)}}}catch{}return a}var ch,hs,fh,dh,sr=C(()=>{"use strict";fs();j();ps();ch={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"]},hs={name:"grep",async execute(t,e){if(I(t))return N(ch);let n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,p=!1,h=!1,g=!1,m=!1,w=0,b=0,E=0,S=[],v=[],F=[],W=null,z=[];for(let D=0;D<t.length;D++){let q=t[D];if(q.startsWith("-")&&q!=="-"){if(q==="-e"&&D+1<t.length){W=t[++D];continue}if(q.startsWith("--include=")){S.push(q.slice(10));continue}if(q.startsWith("--exclude=")){v.push(q.slice(10));continue}if(q.startsWith("--exclude-dir=")){F.push(q.slice(14));continue}if(q.startsWith("--max-count=")){w=parseInt(q.slice(12),10);continue}let se=q.match(/^-m(\d+)$/);if(se){w=parseInt(se[1],10);continue}if(q==="-m"&&D+1<t.length){w=parseInt(t[++D],10);continue}let V=q.match(/^-([ABC])(\d+)$/);if(V){let T=parseInt(V[2],10);V[1]==="A"?E=T:V[1]==="B"?b=T:V[1]==="C"&&(b=T,E=T);continue}if((q==="-A"||q==="-B"||q==="-C")&&D+1<t.length){let T=parseInt(t[++D],10);q==="-A"?E=T:q==="-B"?b=T:(b=T,E=T);continue}let ae=q.startsWith("--")?[q]:q.slice(1).split("");for(let T of ae)if(T==="i"||T==="--ignore-case")n=!0;else if(T==="n"||T==="--line-number")r=!0;else if(T==="v"||T==="--invert-match")s=!0;else if(T==="c"||T==="--count")i=!0;else if(T==="l"||T==="--files-with-matches")o=!0;else if(T==="L"||T==="--files-without-match")a=!0;else if(T==="r"||T==="R"||T==="--recursive")l=!0;else if(T==="w"||T==="--word-regexp")c=!0;else if(T==="x"||T==="--line-regexp")u=!0;else if(T==="E"||T==="--extended-regexp")f=!0;else if(T==="P"||T==="--perl-regexp")d=!0;else if(T==="F"||T==="--fixed-strings")p=!0;else if(T==="o"||T==="--only-matching")h=!0;else if(T==="h"||T==="--no-filename")g=!0;else if(T==="q"||T==="--quiet"||T==="--silent")m=!0;else{if(T.startsWith("--"))return L("grep",T);if(T.length===1)return L("grep",`-${T}`)}}else W===null?W=q:z.push(q)}if(W===null)return{stdout:"",stderr:`grep: missing pattern
|
|
152
152
|
`,exitCode:2};let X=p?"fixed":f?"extended":d?"perl":"basic",K,_;try{let D=bn(W,{mode:X,ignoreCase:n,wholeWord:c,lineRegexp:u});K=D.regex,_=D.kResetGroup}catch{return{stdout:"",stderr:`grep: invalid regular expression: ${W}
|
|
153
153
|
`,exitCode:2}}if(z.length===0&&e.stdin){let D=Zt(e.stdin,K,{invertMatch:s,showLineNumbers:r,countOnly:i,filename:"",onlyMatching:h,beforeContext:b,afterContext:E,maxCount:w,kResetGroup:_});return m?{stdout:"",stderr:"",exitCode:D.matched?0:1}:{stdout:D.output,stderr:"",exitCode:D.matched?0:1}}if(z.length===0)return{stdout:"",stderr:`grep: no input files
|
|
154
|
-
`,exitCode:2};let A="",R="",$=!1,P=!1,O=[];for(let D of z)if(D.includes("*")||D.includes("?")||D.includes("[")){let q=await
|
|
154
|
+
`,exitCode:2};let A="",R="",$=!1,P=!1,O=[];for(let D of z)if(D.includes("*")||D.includes("?")||D.includes("[")){let q=await uh(D,e);if(l)for(let se of q){let V=await nr(se.path,e,S,v,F,se.isFile);O.push(...V)}else O.push(...q)}else if(l){let q=await nr(D,e,S,v,F);O.push(...q)}else O.push({path:D});let ue=(O.length>1||l)&&!g,ot=50;for(let D=0;D<O.length;D+=ot){let q=O.slice(D,D+ot),se=await Promise.all(q.map(async V=>{let ae=V.path,T=ae.split("/").pop()||ae;if(v.length>0&&!l&&v.some(ne=>De(T,ne,{stripQuotes:!0}))||S.length>0&&!l&&!S.some(ne=>De(T,ne,{stripQuotes:!0})))return null;try{let ne=e.fs.resolvePath(e.cwd,ae),le=!1;if(V.isFile===void 0?le=(await e.fs.stat(ne)).isDirectory:le=!V.isFile,le)return l?null:{error:`grep: ${ae}: Is a directory
|
|
155
155
|
`};let me=await e.fs.readFile(ne),Ee=Zt(me,K,{invertMatch:s,showLineNumbers:r,countOnly:i,filename:ue?ae:"",onlyMatching:h,beforeContext:b,afterContext:E,maxCount:w,kResetGroup:_});return{file:ae,result:Ee}}catch{return{error:`grep: ${ae}: No such file or directory
|
|
156
156
|
`}}}));for(let V of se){if(V===null)continue;if("error"in V&&V.error){R+=V.error,V.error.includes("Is a directory")||(P=!0);continue}if(!("file"in V)||!V.result)continue;let{file:ae,result:T}=V;if(T.matched){if($=!0,m)return{stdout:"",stderr:"",exitCode:0};o?A+=`${ae}
|
|
157
157
|
`:a||(A+=T.output)}else a?A+=`${ae}
|
|
158
|
-
`:i&&!o&&(A+=T.output)}}let Y;return P?Y=2:a?Y=A.length>0?0:1:Y=$?0:1,m?{stdout:"",stderr:"",exitCode:Y}:{stdout:A,stderr:R,exitCode:Y}}};
|
|
158
|
+
`:i&&!o&&(A+=T.output)}}let Y;return P?Y=2:a?Y=A.length>0?0:1:Y=$?0:1,m?{stdout:"",stderr:"",exitCode:Y}:{stdout:A,stderr:R,exitCode:Y}}};fh={name:"fgrep",async execute(t,e){return hs.execute(["-F",...t],e)}},dh={name:"egrep",async execute(t,e){return hs.execute(["-E",...t],e)}}});function ia(){let t=[];for(let[e,n]of Object.entries(sa).sort()){let r=[];for(let s of n.extensions)r.push(`*${s}`);for(let s of n.globs)r.push(s);t.push(`${e}: ${r.join(", ")}`)}return`${t.join(`
|
|
159
159
|
`)}
|
|
160
|
-
`}var sa,En,ms=C(()=>{"use strict";sa={js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}},En=class{types;constructor(){this.types=new Map(Object.entries(sa).map(([e,n])=>[e,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(e){let n=e.indexOf(":");if(n===-1)return;let r=e.slice(0,n),s=e.slice(n+1);if(s.startsWith("include:")){let i=s.slice(8),o=this.types.get(i);if(o){let a=this.types.get(r)||{extensions:[],globs:[]};a.extensions.push(...o.extensions),a.globs.push(...o.globs),this.types.set(r,a)}}else{let i=this.types.get(r)||{extensions:[],globs:[]};if(s.startsWith("*.")&&!s.slice(2).includes("*")){let o=s.slice(1);i.extensions.includes(o)||i.extensions.push(o)}else i.globs.includes(s)||i.globs.push(s);this.types.set(r,i)}}clearType(e){let n=this.types.get(e);n&&(n.extensions=[],n.globs=[])}getType(e){return this.types.get(e)}getAllTypes(){return this.types}matchesType(e,n){let r=e.toLowerCase();for(let s of n){if(s==="all"){if(this.matchesAnyType(e))return!0;continue}let i=this.types.get(s);if(i){for(let o of i.extensions)if(r.endsWith(o))return!0;for(let o of i.globs)if(o.includes("*")){let a=o.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${a}$`,"i").test(e))return!0}else if(r===o.toLowerCase())return!0}}return!1}matchesAnyType(e){let n=e.toLowerCase();for(let r of this.types.values()){for(let s of r.extensions)if(n.endsWith(s))return!0;for(let s of r.globs)if(s.includes("*")){let i=s.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${i}$`,"i").test(e))return!0}else if(n===s.toLowerCase())return!0}return!1}}});function oa(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:1/0,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}var aa=C(()=>{"use strict"});function
|
|
161
|
-
`,exitCode:1}}function la(t){return null}function
|
|
162
|
-
`,exitCode:1}};if(m.length===1){let b=
|
|
163
|
-
`);for(let r of n){let s=r.replace(/\s+$/,"");if(!s||s.startsWith("#"))continue;let i=!1;s.startsWith("!")&&(i=!0,s=s.slice(1));let o=!1;s.endsWith("/")&&(o=!0,s=s.slice(0,-1));let a=!1;s.startsWith("/")?(a=!0,s=s.slice(1)):s.includes("/")&&!s.startsWith("**/")&&(a=!0);let l=this.patternToRegex(s,a);this.patterns.push({pattern:r,regex:l,negated:i,directoryOnly:o,rooted:a})}}patternToRegex(e,n){let r="";n?r="^":r="(?:^|/)";let s=0;for(;s<e.length;){let i=e[s];if(i==="*")e[s+1]==="*"?e[s+2]==="/"?(r+="(?:.*/)?",s+=3):(s+2>=e.length,r+=".*",s+=2):(r+="[^/]*",s++);else if(i==="?")r+="[^/]",s++;else if(i==="["){let o=s+1;for(o<e.length&&e[o]==="!"&&o++,o<e.length&&e[o]==="]"&&o++;o<e.length&&e[o]!=="]";)o++;if(o<e.length){let a=e.slice(s,o+1);a.startsWith("[!")&&(a=`[^${a.slice(2)}`),r+=a,s=o+1}else r+="\\[",s++}else i==="/"?(r+="/",s++):(r+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s++)}return r+="(?:/.*)?$",new RegExp(r)}matches(e,n){let r=e.replace(/^\.\//,"");r=r.replace(/^\//,"");let s=!1;for(let i of this.patterns)i.directoryOnly&&!n||i.regex.test(r)&&(s=!i.negated);return s}isWhitelisted(e,n){let r=e.replace(/^\.\//,"");r=r.replace(/^\//,"");for(let s of this.patterns)if(!(s.directoryOnly&&!n)&&s.negated&&s.regex.test(r))return!0;return!1}getBasePath(){return this.basePath}},Cn=class{parsers=[];fs;skipDotIgnore;skipVcsIgnore;loadedDirs=new Set;constructor(e,n,r=!1,s=!1){this.fs=e,this.skipDotIgnore=r,this.skipVcsIgnore=s}async load(e){let n=[],r=e;for(;;){n.unshift(r);let i=this.fs.resolvePath(r,"..");if(i===r)break;r=i}let s=[];this.skipVcsIgnore||s.push(".gitignore"),this.skipDotIgnore||s.push(".rgignore",".ignore");for(let i of n){this.loadedDirs.add(i);for(let o of s){let a=this.fs.resolvePath(i,o);try{let l=await this.fs.readFile(a),c=new Sn(i);c.parse(l),this.parsers.push(c)}catch{}}}}async loadForDirectory(e){if(this.loadedDirs.has(e))return;this.loadedDirs.add(e);let n=[];this.skipVcsIgnore||n.push(".gitignore"),this.skipDotIgnore||n.push(".rgignore",".ignore");for(let r of n){let s=this.fs.resolvePath(e,r);try{let i=await this.fs.readFile(s),o=new Sn(e);o.parse(i),this.parsers.push(o)}catch{}}}addPatternsFromContent(e,n){let r=new Sn(n);r.parse(e),this.parsers.push(r)}matches(e,n){for(let r of this.parsers){let s=r.getBasePath();if(!e.startsWith(s))continue;let i=e.slice(s.length).replace(/^\//,"");if(r.matches(i,n))return!0}return!1}isWhitelisted(e,n){for(let r of this.parsers){let s=r.getBasePath();if(!e.startsWith(s))continue;let i=e.slice(s.length).replace(/^\//,"");if(r.isWhitelisted(i,n))return!0}return!1}static isCommonIgnored(e){return new Set(["node_modules",".git",".svn",".hg","__pycache__",".pytest_cache",".mypy_cache","venv",".venv",".next",".nuxt",".cargo"]).has(e)}}});import{gunzipSync as
|
|
164
|
-
`,exitCode:1}}if(n.files){let m=[...n.patterns,...r];return
|
|
160
|
+
`}var sa,En,ms=C(()=>{"use strict";sa={js:{extensions:[".js",".mjs",".cjs",".jsx"],globs:[]},ts:{extensions:[".ts",".tsx",".mts",".cts"],globs:[]},html:{extensions:[".html",".htm",".xhtml"],globs:[]},css:{extensions:[".css",".scss",".sass",".less"],globs:[]},json:{extensions:[".json",".jsonc",".json5"],globs:[]},xml:{extensions:[".xml",".xsl",".xslt"],globs:[]},c:{extensions:[".c",".h"],globs:[]},cpp:{extensions:[".cpp",".cc",".cxx",".hpp",".hh",".hxx",".h"],globs:[]},rust:{extensions:[".rs"],globs:[]},go:{extensions:[".go"],globs:[]},zig:{extensions:[".zig"],globs:[]},java:{extensions:[".java"],globs:[]},kotlin:{extensions:[".kt",".kts"],globs:[]},scala:{extensions:[".scala",".sc"],globs:[]},clojure:{extensions:[".clj",".cljc",".cljs",".edn"],globs:[]},py:{extensions:[".py",".pyi",".pyw"],globs:[]},rb:{extensions:[".rb",".rake",".gemspec"],globs:["Rakefile","Gemfile"]},php:{extensions:[".php",".phtml",".php3",".php4",".php5"],globs:[]},perl:{extensions:[".pl",".pm",".pod",".t"],globs:[]},lua:{extensions:[".lua"],globs:[]},sh:{extensions:[".sh",".bash",".zsh",".fish"],globs:[".bashrc",".zshrc",".profile"]},bat:{extensions:[".bat",".cmd"],globs:[]},ps:{extensions:[".ps1",".psm1",".psd1"],globs:[]},yaml:{extensions:[".yaml",".yml"],globs:[]},toml:{extensions:[".toml"],globs:["Cargo.toml","pyproject.toml"]},ini:{extensions:[".ini",".cfg",".conf"],globs:[]},csv:{extensions:[".csv",".tsv"],globs:[]},md:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},markdown:{extensions:[".md",".mdx",".markdown",".mdown",".mkd"],globs:[]},rst:{extensions:[".rst"],globs:[]},txt:{extensions:[".txt",".text"],globs:[]},tex:{extensions:[".tex",".ltx",".sty",".cls"],globs:[]},sql:{extensions:[".sql"],globs:[]},graphql:{extensions:[".graphql",".gql"],globs:[]},proto:{extensions:[".proto"],globs:[]},make:{extensions:[".mk",".mak"],globs:["Makefile","GNUmakefile","makefile"]},docker:{extensions:[],globs:["Dockerfile","Dockerfile.*","*.dockerfile"]},tf:{extensions:[".tf",".tfvars"],globs:[]}},En=class{types;constructor(){this.types=new Map(Object.entries(sa).map(([e,n])=>[e,{extensions:[...n.extensions],globs:[...n.globs]}]))}addType(e){let n=e.indexOf(":");if(n===-1)return;let r=e.slice(0,n),s=e.slice(n+1);if(s.startsWith("include:")){let i=s.slice(8),o=this.types.get(i);if(o){let a=this.types.get(r)||{extensions:[],globs:[]};a.extensions.push(...o.extensions),a.globs.push(...o.globs),this.types.set(r,a)}}else{let i=this.types.get(r)||{extensions:[],globs:[]};if(s.startsWith("*.")&&!s.slice(2).includes("*")){let o=s.slice(1);i.extensions.includes(o)||i.extensions.push(o)}else i.globs.includes(s)||i.globs.push(s);this.types.set(r,i)}}clearType(e){let n=this.types.get(e);n&&(n.extensions=[],n.globs=[])}getType(e){return this.types.get(e)}getAllTypes(){return this.types}matchesType(e,n){let r=e.toLowerCase();for(let s of n){if(s==="all"){if(this.matchesAnyType(e))return!0;continue}let i=this.types.get(s);if(i){for(let o of i.extensions)if(r.endsWith(o))return!0;for(let o of i.globs)if(o.includes("*")){let a=o.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${a}$`,"i").test(e))return!0}else if(r===o.toLowerCase())return!0}}return!1}matchesAnyType(e){let n=e.toLowerCase();for(let r of this.types.values()){for(let s of r.extensions)if(n.endsWith(s))return!0;for(let s of r.globs)if(s.includes("*")){let i=s.replace(/\./g,"\\.").replace(/\*/g,".*");if(new RegExp(`^${i}$`,"i").test(e))return!0}else if(n===s.toLowerCase())return!0}return!1}}});function oa(){return{ignoreCase:!1,caseSensitive:!1,smartCase:!0,fixedStrings:!1,wordRegexp:!1,lineRegexp:!1,invertMatch:!1,multiline:!1,multilineDotall:!1,patterns:[],patternFiles:[],count:!1,countMatches:!1,files:!1,filesWithMatches:!1,filesWithoutMatch:!1,stats:!1,onlyMatching:!1,maxCount:0,lineNumber:!0,noFilename:!1,withFilename:!1,nullSeparator:!1,byteOffset:!1,column:!1,vimgrep:!1,replace:null,afterContext:0,beforeContext:0,contextSeparator:"--",quiet:!1,heading:!1,passthru:!1,includeZero:!1,sort:"path",json:!1,globs:[],iglobs:[],globCaseInsensitive:!1,types:[],typesNot:[],typeAdd:[],typeClear:[],hidden:!1,noIgnore:!1,noIgnoreDot:!1,noIgnoreVcs:!1,ignoreFiles:[],maxDepth:1/0,maxFilesize:0,followSymlinks:!1,searchZip:!1,searchBinary:!1,preprocessor:null,preprocessorGlobs:[]}}var aa=C(()=>{"use strict"});function ph(t){let e=t.match(/^(\d+)([KMG])?$/i);if(!e)return 0;let n=parseInt(e[1],10);switch((e[2]||"").toUpperCase()){case"K":return n*1024;case"M":return n*1024*1024;case"G":return n*1024*1024*1024;default:return n}}function hh(t){return/^\d+[KMG]?$/i.test(t)?null:{stdout:"",stderr:`rg: invalid --max-filesize value: ${t}
|
|
161
|
+
`,exitCode:1}}function la(t){return null}function yh(t){t.hidden?t.searchBinary=!0:t.noIgnore?t.hidden=!0:t.noIgnore=!0}function xh(t,e,n){let r=t[e];for(let s of ca){if(r.startsWith(`--${s.long}=`)){let i=r.slice(`--${s.long}=`.length),o=ir(n,s,i);return o?{newIndex:e,error:o}:{newIndex:e}}if(s.short&&r.startsWith(`-${s.short}`)&&r.length>2){let i=r.slice(2),o=ir(n,s,i);return o?{newIndex:e,error:o}:{newIndex:e}}if(s.short&&r===`-${s.short}`||r===`--${s.long}`){if(e+1>=t.length)return null;let i=t[e+1],o=ir(n,s,i);return o?{newIndex:e+1,error:o}:{newIndex:e+1}}}return null}function wh(t){return ca.find(e=>e.short===t)}function ir(t,e,n){if(e.validate){let s=e.validate(n);if(s)return s}let r=e.parse?e.parse(n):n;e.multi?t[e.target].push(r):t[e.target]=r}function bh(t,e){let n=t[e];if(n==="--sort"&&e+1<t.length){let r=t[e+1];if(r==="path"||r==="none")return{value:r,newIndex:e+1}}if(n.startsWith("--sort=")){let r=n.slice(7);if(r==="path"||r==="none")return{value:r,newIndex:e}}return null}function Eh(t,e){let n=t[e],r=n.match(/^-([ABC])(\d+)$/);return r?{flag:r[1],value:parseInt(r[2],10),newIndex:e}:(n==="-A"||n==="-B"||n==="-C")&&e+1<t.length?{flag:n[1],value:parseInt(t[e+1],10),newIndex:e+1}:null}function Sh(t){let e=t.match(/^-m(\d+)$/);return e?parseInt(e[1],10):null}function ua(t){let e=oa(),n=null,r=[],s=-1,i=-1,o=-1,a=!1;for(let l=0;l<t.length;l++){let c=t[l];if(c.startsWith("-")&&c!=="-"){let u=Eh(t,l);if(u){let{flag:m,value:w,newIndex:b}=u;m==="A"?s=Math.max(s,w):m==="B"?i=Math.max(i,w):o=w,l=b;continue}let f=Sh(c);if(f!==null){e.maxCount=f;continue}let d=xh(t,l,e);if(d){if(d.error)return{success:!1,error:d.error};l=d.newIndex;continue}let p=bh(t,l);if(p){e.sort=p.value,l=p.newIndex;continue}let h=c.startsWith("--")?[c]:c.slice(1).split(""),g=!1;for(let m of h){if(gh.has(m)){e.lineNumber=!0,a=!0;continue}if(m==="u"||m==="--unrestricted"){yh(e);continue}if(m==="P"||m==="--pcre2")return{success:!1,error:{stdout:"",stderr:`rg: PCRE2 is not supported. Use standard regex syntax instead.
|
|
162
|
+
`,exitCode:1}};if(m.length===1){let b=wh(m);if(b){if(l+1>=t.length)return{success:!1,error:L("rg",`-${m}`)};let E=ir(e,b,t[l+1]);if(E)return{success:!1,error:E};l++,g=!0;continue}}let w=mh[m];if(w){w(e);continue}if(m.startsWith("--"))return{success:!1,error:L("rg",m)};if(m.length===1)return{success:!1,error:L("rg",`-${m}`)}}}else n===null&&e.patterns.length===0&&e.patternFiles.length===0?n=c:r.push(c)}return(s>=0||o>=0)&&(e.afterContext=Math.max(s>=0?s:0,o>=0?o:0)),(i>=0||o>=0)&&(e.beforeContext=Math.max(i>=0?i:0,o>=0?o:0)),n!==null&&e.patterns.push(n),(e.column||e.vimgrep)&&(a=!0),{success:!0,options:e,paths:r,explicitLineNumbers:a}}var ca,mh,gh,fa=C(()=>{"use strict";j();aa();ca=[{short:"g",long:"glob",target:"globs",multi:!0},{long:"iglob",target:"iglobs",multi:!0},{short:"t",long:"type",target:"types",multi:!0,validate:la},{short:"T",long:"type-not",target:"typesNot",multi:!0,validate:la},{long:"type-add",target:"typeAdd",multi:!0},{long:"type-clear",target:"typeClear",multi:!0},{short:"m",long:"max-count",target:"maxCount",parse:parseInt},{short:"e",long:"regexp",target:"patterns",multi:!0},{short:"f",long:"file",target:"patternFiles",multi:!0},{short:"r",long:"replace",target:"replace"},{short:"d",long:"max-depth",target:"maxDepth",parse:parseInt},{long:"max-filesize",target:"maxFilesize",parse:ph,validate:hh},{long:"context-separator",target:"contextSeparator"},{short:"j",long:"threads",target:"maxDepth",parse:()=>1/0},{long:"ignore-file",target:"ignoreFiles",multi:!0},{long:"pre",target:"preprocessor"},{long:"pre-glob",target:"preprocessorGlobs",multi:!0}],mh={i:t=>{t.ignoreCase=!0,t.caseSensitive=!1,t.smartCase=!1},"--ignore-case":t=>{t.ignoreCase=!0,t.caseSensitive=!1,t.smartCase=!1},s:t=>{t.caseSensitive=!0,t.ignoreCase=!1,t.smartCase=!1},"--case-sensitive":t=>{t.caseSensitive=!0,t.ignoreCase=!1,t.smartCase=!1},S:t=>{t.smartCase=!0,t.ignoreCase=!1,t.caseSensitive=!1},"--smart-case":t=>{t.smartCase=!0,t.ignoreCase=!1,t.caseSensitive=!1},F:t=>{t.fixedStrings=!0},"--fixed-strings":t=>{t.fixedStrings=!0},w:t=>{t.wordRegexp=!0},"--word-regexp":t=>{t.wordRegexp=!0},x:t=>{t.lineRegexp=!0},"--line-regexp":t=>{t.lineRegexp=!0},v:t=>{t.invertMatch=!0},"--invert-match":t=>{t.invertMatch=!0},U:t=>{t.multiline=!0},"--multiline":t=>{t.multiline=!0},"--multiline-dotall":t=>{t.multilineDotall=!0,t.multiline=!0},c:t=>{t.count=!0},"--count":t=>{t.count=!0},"--count-matches":t=>{t.countMatches=!0},l:t=>{t.filesWithMatches=!0},"--files":t=>{t.files=!0},"--files-with-matches":t=>{t.filesWithMatches=!0},"--files-without-match":t=>{t.filesWithoutMatch=!0},"--stats":t=>{t.stats=!0},o:t=>{t.onlyMatching=!0},"--only-matching":t=>{t.onlyMatching=!0},q:t=>{t.quiet=!0},"--quiet":t=>{t.quiet=!0},N:t=>{t.lineNumber=!1},"--no-line-number":t=>{t.lineNumber=!1},H:t=>{t.withFilename=!0},"--with-filename":t=>{t.withFilename=!0},I:t=>{t.noFilename=!0},"--no-filename":t=>{t.noFilename=!0},0:t=>{t.nullSeparator=!0},"--null":t=>{t.nullSeparator=!0},b:t=>{t.byteOffset=!0},"--byte-offset":t=>{t.byteOffset=!0},"--column":t=>{t.column=!0,t.lineNumber=!0},"--no-column":t=>{t.column=!1},"--vimgrep":t=>{t.vimgrep=!0,t.column=!0,t.lineNumber=!0},"--json":t=>{t.json=!0},"--hidden":t=>{t.hidden=!0},"--no-ignore":t=>{t.noIgnore=!0},"--no-ignore-dot":t=>{t.noIgnoreDot=!0},"--no-ignore-vcs":t=>{t.noIgnoreVcs=!0},L:t=>{t.followSymlinks=!0},"--follow":t=>{t.followSymlinks=!0},z:t=>{t.searchZip=!0},"--search-zip":t=>{t.searchZip=!0},a:t=>{t.searchBinary=!0},"--text":t=>{t.searchBinary=!0},"--heading":t=>{t.heading=!0},"--passthru":t=>{t.passthru=!0},"--include-zero":t=>{t.includeZero=!0},"--glob-case-insensitive":t=>{t.globCaseInsensitive=!0}},gh=new Set(["n","--line-number"])});async function gs(t,e,n=!1,r=!1,s=[]){let i=new Cn(t,e,n,r);await i.load(e);for(let o of s)try{let a=t.resolvePath(e,o),l=await t.readFile(a);i.addPatternsFromContent(l,e)}catch{}return i}var Sn,Cn,da=C(()=>{"use strict";Sn=class{patterns=[];basePath;constructor(e="/"){this.basePath=e}parse(e){let n=e.split(`
|
|
163
|
+
`);for(let r of n){let s=r.replace(/\s+$/,"");if(!s||s.startsWith("#"))continue;let i=!1;s.startsWith("!")&&(i=!0,s=s.slice(1));let o=!1;s.endsWith("/")&&(o=!0,s=s.slice(0,-1));let a=!1;s.startsWith("/")?(a=!0,s=s.slice(1)):s.includes("/")&&!s.startsWith("**/")&&(a=!0);let l=this.patternToRegex(s,a);this.patterns.push({pattern:r,regex:l,negated:i,directoryOnly:o,rooted:a})}}patternToRegex(e,n){let r="";n?r="^":r="(?:^|/)";let s=0;for(;s<e.length;){let i=e[s];if(i==="*")e[s+1]==="*"?e[s+2]==="/"?(r+="(?:.*/)?",s+=3):(s+2>=e.length,r+=".*",s+=2):(r+="[^/]*",s++);else if(i==="?")r+="[^/]",s++;else if(i==="["){let o=s+1;for(o<e.length&&e[o]==="!"&&o++,o<e.length&&e[o]==="]"&&o++;o<e.length&&e[o]!=="]";)o++;if(o<e.length){let a=e.slice(s,o+1);a.startsWith("[!")&&(a=`[^${a.slice(2)}`),r+=a,s=o+1}else r+="\\[",s++}else i==="/"?(r+="/",s++):(r+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s++)}return r+="(?:/.*)?$",new RegExp(r)}matches(e,n){let r=e.replace(/^\.\//,"");r=r.replace(/^\//,"");let s=!1;for(let i of this.patterns)i.directoryOnly&&!n||i.regex.test(r)&&(s=!i.negated);return s}isWhitelisted(e,n){let r=e.replace(/^\.\//,"");r=r.replace(/^\//,"");for(let s of this.patterns)if(!(s.directoryOnly&&!n)&&s.negated&&s.regex.test(r))return!0;return!1}getBasePath(){return this.basePath}},Cn=class{parsers=[];fs;skipDotIgnore;skipVcsIgnore;loadedDirs=new Set;constructor(e,n,r=!1,s=!1){this.fs=e,this.skipDotIgnore=r,this.skipVcsIgnore=s}async load(e){let n=[],r=e;for(;;){n.unshift(r);let i=this.fs.resolvePath(r,"..");if(i===r)break;r=i}let s=[];this.skipVcsIgnore||s.push(".gitignore"),this.skipDotIgnore||s.push(".rgignore",".ignore");for(let i of n){this.loadedDirs.add(i);for(let o of s){let a=this.fs.resolvePath(i,o);try{let l=await this.fs.readFile(a),c=new Sn(i);c.parse(l),this.parsers.push(c)}catch{}}}}async loadForDirectory(e){if(this.loadedDirs.has(e))return;this.loadedDirs.add(e);let n=[];this.skipVcsIgnore||n.push(".gitignore"),this.skipDotIgnore||n.push(".rgignore",".ignore");for(let r of n){let s=this.fs.resolvePath(e,r);try{let i=await this.fs.readFile(s),o=new Sn(e);o.parse(i),this.parsers.push(o)}catch{}}}addPatternsFromContent(e,n){let r=new Sn(n);r.parse(e),this.parsers.push(r)}matches(e,n){for(let r of this.parsers){let s=r.getBasePath();if(!e.startsWith(s))continue;let i=e.slice(s.length).replace(/^\//,"");if(r.matches(i,n))return!0}return!1}isWhitelisted(e,n){for(let r of this.parsers){let s=r.getBasePath();if(!e.startsWith(s))continue;let i=e.slice(s.length).replace(/^\//,"");if(r.isWhitelisted(i,n))return!0}return!1}static isCommonIgnored(e){return new Set(["node_modules",".git",".svn",".hg","__pycache__",".pytest_cache",".mypy_cache","venv",".venv",".next",".nuxt",".cargo"]).has(e)}}});import{gunzipSync as Ch}from"node:zlib";function Ah(t){return t.length>=2&&t[0]===31&&t[1]===139}function kh(t){let e=!1;for(let n=0;n<t.length;n++){let r=t[n];r==="["&&!e?e=!0:r==="]"&&e&&(e=!1)}return e?`rg: glob '${t}' has an unclosed character class`:null}async function pa(t){let{ctx:e,options:n,paths:r,explicitLineNumbers:s}=t;for(let m of n.globs){let w=m.startsWith("!")?m.slice(1):m,b=kh(w);if(b)return{stdout:"",stderr:`${b}
|
|
164
|
+
`,exitCode:1}}if(n.files){let m=[...n.patterns,...r];return vh(e,m,n)}let i=[...n.patterns];for(let m of n.patternFiles)try{let w;if(m==="-")w=e.stdin;else{let E=e.fs.resolvePath(e.cwd,m);w=await e.fs.readFile(E)}let b=w.split(`
|
|
165
165
|
`).filter(E=>E.length>0);i.push(...b)}catch{return{stdout:"",stderr:`rg: ${m}: No such file or directory
|
|
166
166
|
`,exitCode:2}}if(i.length===0)return n.patternFiles.length>0?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`rg: no pattern given
|
|
167
|
-
`,exitCode:2};let o=r.length===0?["."]:r,a=
|
|
168
|
-
`,exitCode:2}}let u=null;n.noIgnore||(u=await gs(e.fs,e.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let f=new En;for(let m of n.typeClear)f.clearType(m);for(let m of n.typeAdd)f.addType(m);let{files:d,singleExplicitFile:p}=await ha(e,o,n,u,f);if(d.length===0)return{stdout:"",stderr:"",exitCode:1};let h=!n.noFilename&&(n.withFilename||!p||d.length>1),g=n.lineNumber;return s||(p&&d.length===1&&(g=!1),n.onlyMatching&&(g=!1)),
|
|
169
|
-
`;return{stdout:o.map(c=>c+a).join(""),stderr:"",exitCode:0}}function
|
|
167
|
+
`,exitCode:2};let o=r.length===0?["."]:r,a=Nh(n,i),l,c;try{let m=Ih(i,n,a);l=m.regex,c=m.kResetGroup}catch{return{stdout:"",stderr:`rg: invalid regex: ${i.join(", ")}
|
|
168
|
+
`,exitCode:2}}let u=null;n.noIgnore||(u=await gs(e.fs,e.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let f=new En;for(let m of n.typeClear)f.clearType(m);for(let m of n.typeAdd)f.addType(m);let{files:d,singleExplicitFile:p}=await ha(e,o,n,u,f);if(d.length===0)return{stdout:"",stderr:"",exitCode:1};let h=!n.noFilename&&(n.withFilename||!p||d.length>1),g=n.lineNumber;return s||(p&&d.length===1&&(g=!1),n.onlyMatching&&(g=!1)),Fh(e,d,l,n,h,g,c)}function Nh(t,e){return t.caseSensitive?!1:t.ignoreCase?!0:t.smartCase?!e.some(n=>/[A-Z]/.test(n)):!1}function Ih(t,e,n){let r;return t.length===1?r=t[0]:r=t.map(s=>e.fixedStrings?s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):`(?:${s})`).join("|"),bn(r,{mode:e.fixedStrings&&t.length===1?"fixed":"perl",ignoreCase:n,wholeWord:e.wordRegexp,lineRegexp:e.lineRegexp,multiline:e.multiline,multilineDotall:e.multilineDotall})}async function ha(t,e,n,r,s){let i=[],o=0,a=0;for(let c of e){let u=t.fs.resolvePath(t.cwd,c);try{let f=await t.fs.stat(u);if(f.isFile){if(o++,n.maxFilesize>0&&f.size>n.maxFilesize)continue;ga(c,n,r,u,s)&&i.push(c)}else f.isDirectory&&(a++,await ma(t,c,u,0,n,r,s,i))}catch{}}return{files:n.sort==="path"?i.sort():i,singleExplicitFile:o===1&&a===0}}async function ma(t,e,n,r,s,i,o,a){if(!(r>=s.maxDepth)){i&&await i.loadForDirectory(n);try{let l=t.fs.readdirWithFileTypes?await t.fs.readdirWithFileTypes(n):(await t.fs.readdir(n)).map(c=>({name:c,isFile:void 0}));for(let c of l){let u=c.name;if(!s.noIgnore&&Cn.isCommonIgnored(u))continue;let f=u.startsWith("."),d=e==="."?u:e==="./"?`./${u}`:e.endsWith("/")?`${e}${u}`:`${e}/${u}`,p=t.fs.resolvePath(n,u),h,g,m=!1;if(c.isFile!==void 0&&"isDirectory"in c){let E=c;if(m=E.isSymbolicLink===!0,m&&!s.followSymlinks)continue;if(m&&s.followSymlinks)try{let S=await t.fs.stat(p);h=S.isFile,g=S.isDirectory}catch{continue}else h=E.isFile,g=E.isDirectory}else try{let E=t.fs.lstat?await t.fs.lstat(p):await t.fs.stat(p);if(m=E.isSymbolicLink===!0,m&&!s.followSymlinks)continue;let S=m&&s.followSymlinks?await t.fs.stat(p):E;h=S.isFile,g=S.isDirectory}catch{continue}if(!i?.matches(p,g)&&!(f&&!s.hidden&&!i?.isWhitelisted(p,g))){if(g)await ma(t,d,p,r+1,s,i,o,a);else if(h){if(s.maxFilesize>0)try{if((await t.fs.stat(p)).size>s.maxFilesize)continue}catch{continue}ga(d,s,i,p,o)&&a.push(d)}}}}catch{}}}function ga(t,e,n,r,s){let i=t.split("/").pop()||t;if(n?.matches(r,!1)||e.types.length>0&&!s.matchesType(i,e.types)||e.typesNot.length>0&&s.matchesType(i,e.typesNot))return!1;if(e.globs.length>0){let o=e.globCaseInsensitive,a=e.globs.filter(c=>!c.startsWith("!")),l=e.globs.filter(c=>c.startsWith("!")).map(c=>c.slice(1));if(a.length>0){let c=!1;for(let u of a)if(st(i,u,o)||st(t,u,o)){c=!0;break}if(!c)return!1}for(let c of l)if(c.startsWith("/")){let u=c.slice(1);if(st(t,u,o))return!1}else if(st(i,c,o)||st(t,c,o))return!1}if(e.iglobs.length>0){let o=e.iglobs.filter(l=>!l.startsWith("!")),a=e.iglobs.filter(l=>l.startsWith("!")).map(l=>l.slice(1));if(o.length>0){let l=!1;for(let c of o)if(st(i,c,!0)||st(t,c,!0)){l=!0;break}if(!l)return!1}for(let l of a)if(l.startsWith("/")){let c=l.slice(1);if(st(t,c,!0))return!1}else if(st(i,l,!0)||st(t,l,!0))return!1}return!0}function st(t,e,n=!1){let r="^";for(let s=0;s<e.length;s++){let i=e[s];if(i==="*")e[s+1]==="*"?(r+=".*",s++):r+="[^/]*";else if(i==="?")r+="[^/]";else if(i==="["){let o=s+1;for(o<e.length&&e[o]==="!"&&o++,o<e.length&&e[o]==="]"&&o++;o<e.length&&e[o]!=="]";)o++;if(o<e.length){let a=e.slice(s,o+1);a.startsWith("[!")&&(a=`[^${a.slice(2)}`),r+=a,s=o}else r+="\\["}else r+=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return r+="$",new RegExp(r,n?"i":"").test(t)}async function vh(t,e,n){let r=null;n.noIgnore||(r=await gs(t.fs,t.cwd,n.noIgnoreDot,n.noIgnoreVcs,n.ignoreFiles));let s=new En;for(let c of n.typeClear)s.clearType(c);for(let c of n.typeAdd)s.addType(c);let i=e.length===0?["."]:e,{files:o}=await ha(t,i,n,r,s);if(o.length===0)return{stdout:"",stderr:"",exitCode:1};if(n.quiet)return{stdout:"",stderr:"",exitCode:0};let a=n.nullSeparator?"\0":`
|
|
169
|
+
`;return{stdout:o.map(c=>c+a).join(""),stderr:"",exitCode:0}}function $h(t,e){if(e.length===0)return!0;for(let n of e)if(st(t,n,!1))return!0;return!1}async function Rh(t,e,n,r){try{if(r.preprocessor&&t.exec){let o=n.split("/").pop()||n;if($h(o,r.preprocessorGlobs)){let a=await t.exec(`${r.preprocessor} "${e}"`,{cwd:t.cwd});if(a.exitCode===0&&a.stdout){let l=a.stdout.slice(0,8192);return{content:a.stdout,isBinary:l.includes("\0")}}}}if(r.searchZip&&n.endsWith(".gz")){let o=await t.fs.readFileBuffer(e);if(Ah(o))try{let a=Ch(o),l=new TextDecoder().decode(a),c=l.slice(0,8192);return{content:l,isBinary:c.includes("\0")}}catch{return null}}let s=await t.fs.readFile(e),i=s.slice(0,8192);return{content:s,isBinary:i.includes("\0")}}catch{return null}}async function Fh(t,e,n,r,s,i,o){let a="",l=!1,c=[],u=0,f=0,d=0,p=50;e:for(let m=0;m<e.length;m+=p){let w=e.slice(m,m+p),b=await Promise.all(w.map(async E=>{let S=t.fs.resolvePath(t.cwd,E),v=await Rh(t,S,E,r);if(!v)return null;let{content:F,isBinary:W}=v;if(d+=F.length,W&&!r.searchBinary)return null;let z=s&&!r.heading?E:"",X=Zt(F,n,{invertMatch:r.invertMatch,showLineNumbers:i,countOnly:r.count,countMatches:r.countMatches,filename:z,onlyMatching:r.onlyMatching,beforeContext:r.beforeContext,afterContext:r.afterContext,maxCount:r.maxCount,contextSeparator:r.contextSeparator,showColumn:r.column,vimgrep:r.vimgrep,showByteOffset:r.byteOffset,replace:r.replace!==null?ds(r.replace):null,passthru:r.passthru,multiline:r.multiline,kResetGroup:o});return r.json&&X.matched?{file:E,result:X,content:F,isBinary:!1}:{file:E,result:X}}));for(let E of b){if(!E)continue;let{file:S,result:v}=E;if(v.matched){if(l=!0,f++,u+=v.matchCount,r.quiet&&!r.json)break e;if(r.json&&!r.quiet){let F=E.content||"";c.push(JSON.stringify({type:"begin",data:{path:{text:S}}}));let W=F.split(`
|
|
170
170
|
`);n.lastIndex=0;let z=0;for(let X=0;X<W.length;X++){let K=W[X];n.lastIndex=0;let _=[];for(let A=n.exec(K);A!==null;A=n.exec(K)){let R={match:{text:A[0]},start:A.index,end:A.index+A[0].length};r.replace!==null&&(R.replacement={text:r.replace}),_.push(R),A[0].length===0&&n.lastIndex++}if(_.length>0){let A={type:"match",data:{path:{text:S},lines:{text:`${K}
|
|
171
171
|
`},line_number:X+1,absolute_offset:z,submatches:_}};c.push(JSON.stringify(A))}z+=K.length+1}c.push(JSON.stringify({type:"end",data:{path:{text:S},binary_offset:null,stats:{elapsed:{secs:0,nanos:0,human:"0s"},searches:1,searches_with_match:1,bytes_searched:F.length,bytes_printed:0,matched_lines:v.matchCount,matches:v.matchCount}}}))}else if(r.filesWithMatches){let F=r.nullSeparator?"\0":`
|
|
172
172
|
`;a+=`${S}${F}`}else r.filesWithoutMatch||(r.heading&&!r.noFilename&&(a+=`${S}
|
|
@@ -175,7 +175,7 @@ Notes:
|
|
|
175
175
|
`)}
|
|
176
176
|
`);let h=r.quiet&&!r.json?"":a;if(r.stats&&!r.json){let m=["",`${u} matches`,`${u} matched lines`,`${f} files contained matches`,`${e.length} files searched`,`${d} bytes searched`].join(`
|
|
177
177
|
`);h+=`${m}
|
|
178
|
-
`}let g;return r.filesWithoutMatch?g=a.length>0?0:1:g=l?0:1,{stdout:h,stderr:"",exitCode:g}}var ya=C(()=>{"use strict";ps();ms();da()});var xa={};M(xa,{rgCommand:()=>
|
|
178
|
+
`}let g;return r.filesWithoutMatch?g=a.length>0?0:1:g=l?0:1,{stdout:h,stderr:"",exitCode:g}}var ya=C(()=>{"use strict";ps();ms();da()});var xa={};M(xa,{rgCommand:()=>Th});var Ph,Th,wa=C(()=>{"use strict";j();ms();fa();ya();Ph={name:"rg",summary:"recursively search for a pattern",usage:"rg [OPTIONS] PATTERN [PATH ...]",description:`rg (ripgrep) recursively searches directories for a regex pattern.
|
|
179
179
|
Unlike grep, rg is recursive by default and respects .gitignore files.
|
|
180
180
|
|
|
181
181
|
EXAMPLES:
|
|
@@ -186,22 +186,22 @@ EXAMPLES:
|
|
|
186
186
|
rg -t js foo Search only JavaScript files
|
|
187
187
|
rg -g '*.ts' foo Search files matching glob
|
|
188
188
|
rg --hidden foo Include hidden files
|
|
189
|
-
rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},
|
|
189
|
+
rg -l foo List files with matches only`,options:["-e, --regexp PATTERN search for PATTERN (can be used multiple times)","-f, --file FILE read patterns from FILE, one per line","-i, --ignore-case case-insensitive search","-s, --case-sensitive case-sensitive search (overrides smart-case)","-S, --smart-case smart case (default: case-insensitive unless pattern has uppercase)","-F, --fixed-strings treat pattern as literal string","-w, --word-regexp match whole words only","-x, --line-regexp match whole lines only","-v, --invert-match select non-matching lines","-r, --replace TEXT replace matches with TEXT","-c, --count print count of matching lines per file"," --count-matches print count of individual matches per file","-l, --files-with-matches print only file names with matches"," --files-without-match print file names without matches"," --files list files that would be searched","-o, --only-matching print only matching parts","-m, --max-count NUM stop after NUM matches per file","-q, --quiet suppress output, exit 0 on match"," --stats print search statistics","-n, --line-number print line numbers (default: on)","-N, --no-line-number do not print line numbers","-I, --no-filename suppress the prefixing of file names","-0, --null use NUL as filename separator","-b, --byte-offset show byte offset of each match"," --column show column number of first match"," --vimgrep show results in vimgrep format"," --json show results in JSON Lines format","-A NUM print NUM lines after each match","-B NUM print NUM lines before each match","-C NUM print NUM lines before and after each match"," --context-separator SEP separator for context groups (default: --)","-U, --multiline match patterns across lines","-z, --search-zip search in compressed files (gzip only)","-g, --glob GLOB include files matching GLOB","-t, --type TYPE only search files of TYPE (e.g., js, py, ts)","-T, --type-not TYPE exclude files of TYPE","-L, --follow follow symbolic links","-u, --unrestricted reduce filtering (-u: no ignore, -uu: +hidden, -uuu: +binary)","-a, --text search binary files as text"," --hidden search hidden files and directories"," --no-ignore don't respect .gitignore/.ignore files","-d, --max-depth NUM maximum search depth"," --sort TYPE sort files (path, none)"," --heading show file path above matches"," --passthru print all lines (non-matches use - separator)"," --include-zero include files with 0 matches in count output"," --type-list list all available file types"," --help display this help and exit"]},Th={name:"rg",async execute(t,e){if(I(t))return N(Ph);if(t.includes("--type-list"))return{stdout:ia(),stderr:"",exitCode:0};let n=ua(t);return n.success?pa({ctx:e,options:n.options,paths:n.paths,explicitLineNumbers:n.explicitLineNumbers}):n.error}}});function or(t){return t instanceof Fe||t instanceof _e||t instanceof Pe}var Ke,Fe,_e,Pe,it,Qe,fe,ke,ut,Q,at,de=C(()=>{"use strict";Ke=class extends Error{stdout;stderr;constructor(e,n="",r=""){super(e),this.stdout=n,this.stderr=r}prependOutput(e,n){this.stdout=e+this.stdout,this.stderr=n+this.stderr}},Fe=class extends Ke{levels;name="BreakError";constructor(e=1,n="",r=""){super("break",n,r),this.levels=e}},_e=class extends Ke{levels;name="ContinueError";constructor(e=1,n="",r=""){super("continue",n,r),this.levels=e}},Pe=class extends Ke{exitCode;name="ReturnError";constructor(e=0,n="",r=""){super("return",n,r),this.exitCode=e}},it=class extends Ke{exitCode;name="ErrexitError";constructor(e,n="",r=""){super(`errexit: command exited with status ${e}`,n,r),this.exitCode=e}},Qe=class extends Ke{varName;name="NounsetError";constructor(e,n=""){super(`${e}: unbound variable`,n,`bash: ${e}: unbound variable
|
|
190
190
|
`),this.varName=e}},fe=class extends Ke{exitCode;name="ExitError";constructor(e,n="",r=""){super("exit",n,r),this.exitCode=e}},ke=class extends Ke{name="ArithmeticError";constructor(e,n="",r=""){super(e,n,r),this.stderr=r||`bash: ${e}
|
|
191
191
|
`}},ut=class extends Ke{name="BadSubstitutionError";constructor(e,n="",r=""){super(e,n,r),this.stderr=r||`bash: ${e}: bad substitution
|
|
192
192
|
`}},Q=class extends Ke{limitType;name="ExecutionLimitError";static EXIT_CODE=126;constructor(e,n,r="",s=""){super(e,r,s),this.limitType=n,this.stderr=s||`bash: ${e}
|
|
193
|
-
`}},at=class extends Ke{name="SubshellExitError";constructor(e="",n=""){super("subshell exit",e,n)}}});function Ea(t,e,n){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:n||new Map}}function
|
|
193
|
+
`}},at=class extends Ke{name="SubshellExitError";constructor(e="",n=""){super("subshell exit",e,n)}}});function Ea(t,e,n){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:n||new Map}}function Dh(t){return typeof t=="object"&&"first"in t&&"step"in t}function An(t,e,n,r){if(t==="$")return e===n;if(typeof t=="number")return e===t;if(Dh(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(r)}catch{return!1}return!1}function Lh(t){let e=n=>n===void 0?"undefined":n==="$"?"$":typeof n=="number"?String(n):"pattern"in n?`/${n.pattern}/`:"first"in n?`${n.first}~${n.step}`:"unknown";return`${e(t.start)},${e(t.end)}`}function Kt(t,e,n,r,s){if(!t||!t.start&&!t.end)return!0;let i=t.start,o=t.end;if(i!==void 0&&o===void 0)return An(i,e,n,r);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==="$"?n:1,f=typeof o=="number"?o:n;return e>=u&&e<=f}if(s){let u=Lh(t),f=s.get(u);return f||(f={active:!1},s.set(u,f)),f.active?(An(o,e,n,r)&&(f.active=!1,s.set(u,f)),!0):An(i,e,n,r)?(f.active=!0,f.startLine=e,s.set(u,f),An(o,e,n,r)&&(f.active=!1,s.set(u,f)),!0):!1}return An(i,e,n,r)}return!0}function Mh(t){let e="",n=0;for(;n<t.length;){if(t[n]==="\\"&&n+1<t.length){let r=t[n+1];if(r==="+"||r==="?"||r==="|"){e+=r,n+=2;continue}if(r==="("||r===")"){e+=r,n+=2;continue}if(r==="{"||r==="}"){e+=r,n+=2;continue}e+=t[n]+r,n+=2;continue}if(t[n]==="+"||t[n]==="?"||t[n]==="|"||t[n]==="("||t[n]===")"){e+=`\\${t[n]}`,n++;continue}e+=t[n],n++}return e}function _h(t){let e="";for(let n=0;n<t.length;n++){let r=t[n],s=r.charCodeAt(0);r==="\\"?e+="\\\\":r===" "?e+="\\t":r===`
|
|
194
194
|
`?e+=`$
|
|
195
195
|
`:r==="\r"?e+="\\r":r==="\x07"?e+="\\a":r==="\b"?e+="\\b":r==="\f"?e+="\\f":r==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=r}return`${e}$`}function ba(t,e,n){let r="",s=0;for(;s<t.length;){if(t[s]==="\\"&&s+1<t.length){let i=t[s+1];if(i==="&"){r+="&",s+=2;continue}if(i==="n"){r+=`
|
|
196
|
-
`,s+=2;continue}if(i==="t"){r+=" ",s+=2;continue}let o=parseInt(i,10);if(o>=1&&o<=9){r+=n[o-1]||"",s+=2;continue}r+=i,s+=2;continue}if(t[s]==="&"){r+=e,s++;continue}r+=t[s],s++}return r}function
|
|
196
|
+
`,s+=2;continue}if(i==="t"){r+=" ",s+=2;continue}let o=parseInt(i,10);if(o>=1&&o<=9){r+=n[o-1]||"",s+=2;continue}r+=i,s+=2;continue}if(t[s]==="&"){r+=e,s++;continue}r+=t[s],s++}return r}function Bh(t,e){let{lineNumber:n,totalLines:r,patternSpace:s}=e;if(t.type!=="label"&&Kt(t.address,n,r,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:Mh(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 ba(i.replacement,d,h)}return d})}else e.patternSpace=e.patternSpace.replace(l,(u,...f)=>{let d=f.slice(0,-2);return ba(i.replacement,u,d)});i.printOnMatch&&(e.printed=!0)}}catch{}break}case"print":e.printed=!0;break;case"printFirstLine":{let i=e.patternSpace.indexOf(`
|
|
197
197
|
`);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(`
|
|
198
198
|
`);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+=`
|
|
199
199
|
${e.patternSpace}`:e.holdSpace=e.patternSpace;break;case"get":e.patternSpace=e.holdSpace;break;case"getAppend":e.patternSpace+=`
|
|
200
|
-
${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=
|
|
200
|
+
${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=_h(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}
|
|
201
201
|
`});break;case"writeFirstLine":{let i=e.patternSpace.indexOf(`
|
|
202
202
|
`),o=i!==-1?e.patternSpace.slice(0,i):e.patternSpace;e.pendingFileWrites.push({filename:t.filename,content:`${o}
|
|
203
|
-
`});break}case"execute":t.command?e.pendingExecute={command:t.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=
|
|
204
|
-
${u}`,e.lineNumber=n.currentLineIndex+a+1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(c.type==="branch"){let u=c;if(Kt(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(Kt(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(Kt(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;Kt(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&ys(u.commands,e,n,r),l++;continue}
|
|
203
|
+
`});break}case"execute":t.command?e.pendingExecute={command:t.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=Wh(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 Wh(t,e){let n="";for(let r of t){let s=e.source.indexOf(r);s!==-1?n+=e.dest[s]:n+=r}return n}function ys(t,e,n,r){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=r?.maxIterations??Oh,o=0,a=0,l=0;for(;l<t.length;){if(o++,o>i)throw new Q(`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(Kt(c.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates))if(n&&n.currentLineIndex+a+1<n.lines.length){a++;let u=n.lines[n.currentLineIndex+a];e.patternSpace+=`
|
|
204
|
+
${u}`,e.lineNumber=n.currentLineIndex+a+1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(c.type==="branch"){let u=c;if(Kt(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(Kt(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(Kt(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;Kt(u.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates)&&ys(u.commands,e,n,r),l++;continue}Bh(c,e),l++}return a}var Oh,Sa=C(()=>{"use strict";de();Oh=1e4});var U,ar,Ca=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"})(U||(U={}));ar=class{input;pos=0;line=1;column=1;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&e.push(n)}return e.push(this.makeToken(U.EOF,"")),e}makeToken(e,n,r){return{type:e,value:n,line:this.line,column:this.column,...r}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
205
205
|
`?(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()!==`
|
|
206
206
|
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,n=this.column,r=this.peek();return r===`
|
|
207
207
|
`?(this.advance(),{type:U.NEWLINE,value:`
|
|
@@ -221,14 +221,14 @@ ${u}`,e.lineNumber=n.currentLineIndex+a+1}else{e.quit=!0,e.deleted=!0;break}l++;
|
|
|
221
221
|
`;)s+=this.advance();return{type:U.TEXT_CMD,value:e,text:s.trim(),line:n,column:r}}readBranch(e,n,r,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let o=this.peek();if(o===" "||o===" "||o===`
|
|
222
222
|
`||o===";"||o==="}"||o==="{")break;i+=this.advance()}return{type:e,value:n,label:i||void 0,line:r,column:s}}readFileCommand(e,n,r,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let o=this.peek();if(o===`
|
|
223
223
|
`||o===";")break;i+=this.advance()}return{type:e,value:n,filename:i.trim(),line:r,column:s}}readExecute(e,n){for(;this.peek()===" "||this.peek()===" ";)this.advance();let r="";for(;this.pos<this.input.length;){let s=this.peek();if(s===`
|
|
224
|
-
`||s===";")break;r+=this.advance()}return{type:U.EXECUTE,value:"e",command:r.trim()||void 0,line:e,column:n}}isDigit(e){return e>="0"&&e<="9"}}});function Aa(t,e=!1){return new xs(t,e).parse()}var xs,ka=C(()=>{"use strict";Ca();xs=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,n=!1){this.scripts=e,this.extendedRegex=n}parse(){let e=[];for(let n of this.scripts){let r=new ar(n);for(this.tokens=r.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(U.NEWLINE)||this.check(U.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(U.NEWLINE)||this.check(U.SEMICOLON);)this.advance();if(this.isAtEnd())return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null};let n=this.peek();switch(n.type){case U.COMMAND:return this.parseSimpleCommand(n,e);case U.SUBSTITUTE:return this.parseSubstituteFromToken(n,e);case U.TRANSLITERATE:return this.parseTransliterateFromToken(n,e);case U.LABEL_DEF:return this.advance(),{command:{type:"label",name:n.label||""}};case U.BRANCH:return this.advance(),{command:{type:"branch",address:e,label:n.label}};case U.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:e,label:n.label}};case U.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:e,label:n.label}};case U.TEXT_CMD:return this.advance(),this.parseTextCommand(n,e);case U.FILE_READ:return this.advance(),{command:{type:"readFile",address:e,filename:n.filename||""}};case U.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:e,filename:n.filename||""}};case U.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:e,filename:n.filename||""}};case U.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:e,filename:n.filename||""}};case U.EXECUTE:return this.advance(),{command:{type:"execute",address:e,command:n.command}};case U.LBRACE:return this.parseGroup(e);case U.RBRACE:return{command:null};case U.ERROR:return{command:null,error:`invalid command: ${n.value}`};default:return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null}}}parseSimpleCommand(e,n){this.advance();let r=e.value;switch(r){case"p":return{command:{type:"print",address:n}};case"P":return{command:{type:"printFirstLine",address:n}};case"d":return{command:{type:"delete",address:n}};case"D":return{command:{type:"deleteFirstLine",address:n}};case"h":return{command:{type:"hold",address:n}};case"H":return{command:{type:"holdAppend",address:n}};case"g":return{command:{type:"get",address:n}};case"G":return{command:{type:"getAppend",address:n}};case"x":return{command:{type:"exchange",address:n}};case"n":return{command:{type:"next",address:n}};case"N":return{command:{type:"nextAppend",address:n}};case"q":return{command:{type:"quit",address:n}};case"Q":return{command:{type:"quitSilent",address:n}};case"z":return{command:{type:"zap",address:n}};case"=":return{command:{type:"lineNumber",address:n}};case"l":return{command:{type:"list",address:n}};case"F":return{command:{type:"printFilename",address:n}};case"v":return{command:{type:"version",address:n}};default:return{command:null,error:`unknown command: ${r}`}}}parseSubstituteFromToken(e,n){this.advance();let r=e.flags||"",s,i=r.match(/(\d+)/);return i&&(s=parseInt(i[1],10)),{command:{type:"substitute",address:n,pattern:e.pattern||"",replacement:e.replacement||"",global:r.includes("g"),ignoreCase:r.includes("i")||r.includes("I"),printOnMatch:r.includes("p"),nthOccurrence:s,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,n){this.advance();let r=e.source||"",s=e.dest||"";return r.length!==s.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:n,source:r,dest:s}}}parseTextCommand(e,n){let r=e.value,s=e.text||"";switch(r){case"a":return{command:{type:"append",address:n,text:s}};case"i":return{command:{type:"insert",address:n,text:s}};case"c":return{command:{type:"change",address:n,text:s}};default:return{command:null,error:`unknown text command: ${r}`}}}parseGroup(e){this.advance();let n=[];for(;!this.isAtEnd()&&!this.check(U.RBRACE);){if(this.check(U.NEWLINE)||this.check(U.SEMICOLON)){this.advance();continue}let r=this.parseCommand();if(r.error)return{command:null,error:r.error};r.command&&n.push(r.command)}return this.check(U.RBRACE)?(this.advance(),{command:{type:"group",address:e,commands:n}}):{command:null,error:"unmatched brace in grouped commands"}}parseAddressRange(){let e=this.parseAddress();if(e===void 0)return;let n;return this.check(U.COMMA)&&(this.advance(),n=this.parseAddress()),{start:e,end:n}}parseAddress(){let e=this.peek();switch(e.type){case U.NUMBER:return this.advance(),e.value;case U.DOLLAR:return this.advance(),"$";case U.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case U.STEP:return this.advance(),{first:e.first||0,step:e.step||0};default:return}}peek(){return this.tokens[this.pos]||{type:U.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===U.EOF}}});var Na={};M(Na,{sedCommand:()=>
|
|
224
|
+
`||s===";")break;r+=this.advance()}return{type:U.EXECUTE,value:"e",command:r.trim()||void 0,line:e,column:n}}isDigit(e){return e>="0"&&e<="9"}}});function Aa(t,e=!1){return new xs(t,e).parse()}var xs,ka=C(()=>{"use strict";Ca();xs=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,n=!1){this.scripts=e,this.extendedRegex=n}parse(){let e=[];for(let n of this.scripts){let r=new ar(n);for(this.tokens=r.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(U.NEWLINE)||this.check(U.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(U.NEWLINE)||this.check(U.SEMICOLON);)this.advance();if(this.isAtEnd())return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null};let n=this.peek();switch(n.type){case U.COMMAND:return this.parseSimpleCommand(n,e);case U.SUBSTITUTE:return this.parseSubstituteFromToken(n,e);case U.TRANSLITERATE:return this.parseTransliterateFromToken(n,e);case U.LABEL_DEF:return this.advance(),{command:{type:"label",name:n.label||""}};case U.BRANCH:return this.advance(),{command:{type:"branch",address:e,label:n.label}};case U.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:e,label:n.label}};case U.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:e,label:n.label}};case U.TEXT_CMD:return this.advance(),this.parseTextCommand(n,e);case U.FILE_READ:return this.advance(),{command:{type:"readFile",address:e,filename:n.filename||""}};case U.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:e,filename:n.filename||""}};case U.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:e,filename:n.filename||""}};case U.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:e,filename:n.filename||""}};case U.EXECUTE:return this.advance(),{command:{type:"execute",address:e,command:n.command}};case U.LBRACE:return this.parseGroup(e);case U.RBRACE:return{command:null};case U.ERROR:return{command:null,error:`invalid command: ${n.value}`};default:return e&&(e.start!==void 0||e.end!==void 0)?{command:{type:"print",address:e}}:{command:null}}}parseSimpleCommand(e,n){this.advance();let r=e.value;switch(r){case"p":return{command:{type:"print",address:n}};case"P":return{command:{type:"printFirstLine",address:n}};case"d":return{command:{type:"delete",address:n}};case"D":return{command:{type:"deleteFirstLine",address:n}};case"h":return{command:{type:"hold",address:n}};case"H":return{command:{type:"holdAppend",address:n}};case"g":return{command:{type:"get",address:n}};case"G":return{command:{type:"getAppend",address:n}};case"x":return{command:{type:"exchange",address:n}};case"n":return{command:{type:"next",address:n}};case"N":return{command:{type:"nextAppend",address:n}};case"q":return{command:{type:"quit",address:n}};case"Q":return{command:{type:"quitSilent",address:n}};case"z":return{command:{type:"zap",address:n}};case"=":return{command:{type:"lineNumber",address:n}};case"l":return{command:{type:"list",address:n}};case"F":return{command:{type:"printFilename",address:n}};case"v":return{command:{type:"version",address:n}};default:return{command:null,error:`unknown command: ${r}`}}}parseSubstituteFromToken(e,n){this.advance();let r=e.flags||"",s,i=r.match(/(\d+)/);return i&&(s=parseInt(i[1],10)),{command:{type:"substitute",address:n,pattern:e.pattern||"",replacement:e.replacement||"",global:r.includes("g"),ignoreCase:r.includes("i")||r.includes("I"),printOnMatch:r.includes("p"),nthOccurrence:s,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,n){this.advance();let r=e.source||"",s=e.dest||"";return r.length!==s.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:n,source:r,dest:s}}}parseTextCommand(e,n){let r=e.value,s=e.text||"";switch(r){case"a":return{command:{type:"append",address:n,text:s}};case"i":return{command:{type:"insert",address:n,text:s}};case"c":return{command:{type:"change",address:n,text:s}};default:return{command:null,error:`unknown text command: ${r}`}}}parseGroup(e){this.advance();let n=[];for(;!this.isAtEnd()&&!this.check(U.RBRACE);){if(this.check(U.NEWLINE)||this.check(U.SEMICOLON)){this.advance();continue}let r=this.parseCommand();if(r.error)return{command:null,error:r.error};r.command&&n.push(r.command)}return this.check(U.RBRACE)?(this.advance(),{command:{type:"group",address:e,commands:n}}):{command:null,error:"unmatched brace in grouped commands"}}parseAddressRange(){let e=this.parseAddress();if(e===void 0)return;let n;return this.check(U.COMMA)&&(this.advance(),n=this.parseAddress()),{start:e,end:n}}parseAddress(){let e=this.peek();switch(e.type){case U.NUMBER:return this.advance(),e.value;case U.DOLLAR:return this.advance(),"$";case U.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case U.STEP:return this.advance(),{first:e.first||0,step:e.step||0};default:return}}peek(){return this.tokens[this.pos]||{type:U.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===U.EOF}}});var Na={};M(Na,{sedCommand:()=>jh});async function ws(t,e,n,r={}){let{limits:s,filename:i,fs:o,cwd:a}=r,l=t.split(`
|
|
225
225
|
`);l.length>0&&l[l.length-1]===""&&l.pop();let c=l.length,u="",f,d="",p=new Map,h=new Map,g=new Map,m=new Map,w=s?{maxIterations:s.maxSedIterations}:void 0;for(let b=0;b<l.length;b++){let E={...Ea(c,i,p),patternSpace:l[b],holdSpace:d,lineNumber:b+1,totalLines:c,substitutionMade:!1},S={lines:l,currentLineIndex:b},v=0,F=1e4,W=0;do{if(v++,v>F)break;E.restartCycle=!1,E.pendingFileReads=[],E.pendingFileWrites=[];let K=ys(e,E,S,w);if(W+=K,o&&a){for(let _ of E.pendingFileReads){let A=o.resolvePath(a,_.filename);try{if(_.wholeFile){let R=await o.readFile(A);E.appendBuffer.push(R.replace(/\n$/,""))}else{if(!h.has(A)){let P=await o.readFile(A);h.set(A,P.split(`
|
|
226
226
|
`)),g.set(A,0)}let R=h.get(A),$=g.get(A);R&&$!==void 0&&$<R.length&&(E.appendBuffer.push(R[$]),g.set(A,$+1))}}catch{}}for(let _ of E.pendingFileWrites){let A=o.resolvePath(a,_.filename),R=m.get(A)||"";m.set(A,R+_.content)}}S.currentLineIndex+=K}while(E.restartCycle&&!E.deleted&&!E.quit&&!E.quitSilent);b+=W,d=E.holdSpace;for(let K of E.lineNumberOutput)u+=`${K}
|
|
227
227
|
`;let z=[],X=[];for(let K of E.appendBuffer)K.startsWith("__INSERT__")?z.push(K.slice(10)):X.push(K);for(let K of z)u+=`${K}
|
|
228
228
|
`;!E.deleted&&!E.quitSilent&&(n?E.printed&&(u+=`${E.patternSpace}
|
|
229
229
|
`):u+=`${E.patternSpace}
|
|
230
230
|
`);for(let K of X)u+=`${K}
|
|
231
|
-
`;if(E.quit||E.quitSilent){E.exitCode!==void 0&&(f=E.exitCode);break}}if(o&&a)for(let[b,E]of m)try{await o.writeFile(b,E)}catch{}return{output:u,exitCode:f}}var
|
|
231
|
+
`;if(E.quit||E.quitSilent){E.exitCode!==void 0&&(f=E.exitCode);break}}if(o&&a)for(let[b,E]of m)try{await o.writeFile(b,E)}catch{}return{output:u,exitCode:f}}var Uh,jh,Ia=C(()=>{"use strict";de();j();Sa();ka();Uh={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:
|
|
232
232
|
s/regexp/replacement/[flags] substitute
|
|
233
233
|
d delete pattern space
|
|
234
234
|
p print pattern space
|
|
@@ -257,7 +257,7 @@ Addresses:
|
|
|
257
257
|
$ last line
|
|
258
258
|
/regexp/ lines matching regexp
|
|
259
259
|
N,M range from line N to M
|
|
260
|
-
first~step every step-th line starting at first`};
|
|
260
|
+
first~step every step-th line starting at first`};jh={name:"sed",async execute(t,e){if(I(t))return N(Uh);let n=[],r=[],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&&n.push(t[++f]);else if(d==="-f")f+1<t.length&&r.push(t[++f]);else{if(d.startsWith("--"))return L("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 L("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&&n.push(t[++f]),d.includes("f")&&!d.includes("e")&&f+1<t.length&&r.push(t[++f])}else!d.startsWith("-")&&n.length===0&&r.length===0?n.push(d):d.startsWith("-")||a.push(d)}}for(let f of r){let d=e.fs.resolvePath(e.cwd,f);try{let p=await e.fs.readFile(d);for(let h of p.split(`
|
|
261
261
|
`)){let g=h.trim();g&&!g.startsWith("#")&&n.push(g)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${f}: No such file or directory
|
|
262
262
|
`,exitCode:1}}}if(n.length===0)return{stdout:"",stderr:`sed: no script specified
|
|
263
263
|
`,exitCode:1};let{commands:l,error:c}=Aa(n,o);if(c)return{stdout:"",stderr:`sed: ${c}
|
|
@@ -269,24 +269,24 @@ Addresses:
|
|
|
269
269
|
`,exitCode:Q.EXIT_CODE}:{stdout:"",stderr:`sed: ${f}: No such file or directory
|
|
270
270
|
`,exitCode:1}}}try{let f=await ws(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 Q)return{stdout:"",stderr:`sed: ${f.message}
|
|
271
271
|
`,exitCode:Q.EXIT_CODE};throw f}}}});function bs(t={}){let{fieldSep:e=/\s+/,maxIterations:n=1e4,maxRecursionDepth:r=100,fs:s,cwd:i}=t;return{FS:" ",OFS:" ",ORS:`
|
|
272
|
-
`,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:n,maxRecursionDepth:r,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 va=C(()=>{"use strict"});function $a(t,e,n){switch(n){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 Ra=C(()=>{"use strict"});function He(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function we(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}async function
|
|
273
|
-
`,s+=2):i==="t"?(r+=" ",s+=2):(r+=i,s+=2)}else t[s]==="&"?(r+=e,s++):(r+=t[s],s++);return r}async function
|
|
274
|
-
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;default:r+=i}s+=2}else r+=t[s++];return r}var Ta,As=C(()=>{"use strict";Ta={length:
|
|
275
|
-
`),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?yt(t,e,u):Nn(t,u),1}async function
|
|
272
|
+
`,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:n,maxRecursionDepth:r,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 va=C(()=>{"use strict"});function $a(t,e,n){switch(n){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 Ra=C(()=>{"use strict"});function He(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function we(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}async function zh(t,e,n){return t.length===0?e.line.length:we(await n.evalExpr(t[0])).length}async function Hh(t,e,n){if(t.length<2)return"";let r=we(await n.evalExpr(t[0])),s=Math.floor(He(await n.evalExpr(t[1])))-1;if(t.length>=3){let i=Math.floor(He(await n.evalExpr(t[2])));return r.substr(Math.max(0,s),i)}return r.substr(Math.max(0,s))}async function Gh(t,e,n){if(t.length<2)return 0;let r=we(await n.evalExpr(t[0])),s=we(await n.evalExpr(t[1])),i=r.indexOf(s);return i===-1?0:i+1}async function qh(t,e,n){if(t.length<2)return 0;let r=we(await n.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=we(await n.evalExpr(t[2]));o=l===" "?/\s+/:l}else e.FS===" "&&(o=/\s+/);let a=r.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 Vh(t,e,n){if(t.length<2)return 0;let r;t[0].type==="regex"?r=t[0].pattern:(r=we(await n.evalExpr(t[0])),r.startsWith("/")&&r.endsWith("/")&&(r=r.slice(1,-1)));let s=we(await n.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(He(await n.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=we(e.vars[i]??"");try{let a=new RegExp(r),l=o.replace(a,Pa(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 Zh(t,e,n){if(t.length<2)return 0;let r;t[0].type==="regex"?r=t[0].pattern:(r=we(await n.evalExpr(t[0])),r.startsWith("/")&&r.endsWith("/")&&(r=r.slice(1,-1)));let s=we(await n.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(He(await n.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=we(e.vars[i]??"");try{let a=new RegExp(r,"g"),l=o.match(a),c=l?l.length:0,u=o.replace(a,Pa(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 Pa(t){return e=>{let n="",r=0;for(;r<t.length;)if(t[r]==="\\"&&r+1<t.length){let s=t[r+1];s==="&"?(n+="&",r+=2):s==="\\"?(n+="\\",r+=2):(n+=t[r+1],r+=2)}else t[r]==="&"?(n+=e,r++):(n+=t[r],r++);return n}}async function Kh(t,e,n){if(t.length<2)return e.RSTART=0,e.RLENGTH=-1,0;let r=we(await n.evalExpr(t[0])),s;t[1].type==="regex"?s=t[1].pattern:(s=we(await n.evalExpr(t[1])),s.startsWith("/")&&s.endsWith("/")&&(s=s.slice(1,-1)));try{let o=new RegExp(s).exec(r);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 Qh(t,e,n){if(t.length<3)return"";let r;t[0].type==="regex"?r=t[0].pattern:(r=we(await n.evalExpr(t[0])),r.startsWith("/")&&r.endsWith("/")&&(r=r.slice(1,-1)));let s=we(await n.evalExpr(t[1])),i=we(await n.evalExpr(t[2])),o=t.length>=4?we(await n.evalExpr(t[3])):e.line;try{let a=i.toLowerCase()==="g",l=a?0:parseInt(i,10)||1;if(a){let c=new RegExp(r,"g");return o.replace(c,(u,...f)=>Fa(s,u,f.slice(0,-2)))}else{let c=0,u=new RegExp(r,"g");return o.replace(u,(f,...d)=>(c++,c===l?Fa(s,f,d.slice(0,-2)):f))}}catch{return o}}function Fa(t,e,n){let r="",s=0;for(;s<t.length;)if(t[s]==="\\"&&s+1<t.length){let i=t[s+1];if(i==="&")r+="&",s+=2;else if(i==="0")r+=e,s+=2;else if(i>="1"&&i<="9"){let o=parseInt(i,10)-1;r+=n[o]||"",s+=2}else i==="n"?(r+=`
|
|
273
|
+
`,s+=2):i==="t"?(r+=" ",s+=2):(r+=i,s+=2)}else t[s]==="&"?(r+=e,s++):(r+=t[s],s++);return r}async function Xh(t,e,n){return t.length===0?"":we(await n.evalExpr(t[0])).toLowerCase()}async function Jh(t,e,n){return t.length===0?"":we(await n.evalExpr(t[0])).toUpperCase()}async function Yh(t,e,n){if(t.length===0)return"";let r=we(await n.evalExpr(t[0])),s=[];for(let i=1;i<t.length;i++)s.push(await n.evalExpr(t[i]));return Cs(r,s)}async function em(t,e,n){return t.length===0?0:Math.floor(He(await n.evalExpr(t[0])))}async function tm(t,e,n){return t.length===0?0:Math.sqrt(He(await n.evalExpr(t[0])))}async function nm(t,e,n){return t.length===0?0:Math.sin(He(await n.evalExpr(t[0])))}async function rm(t,e,n){return t.length===0?0:Math.cos(He(await n.evalExpr(t[0])))}async function sm(t,e,n){let r=t.length>0?He(await n.evalExpr(t[0])):0,s=t.length>1?He(await n.evalExpr(t[1])):0;return Math.atan2(r,s)}async function im(t,e,n){return t.length===0?0:Math.log(He(await n.evalExpr(t[0])))}async function om(t,e,n){return t.length===0?1:Math.exp(He(await n.evalExpr(t[0])))}function am(t,e,n){return e.random?e.random():Math.random()}async function lm(t,e,n){let r=t.length>0?He(await n.evalExpr(t[0])):Date.now();return e.vars._srand_seed=r,r}function Es(t,e){return()=>{throw new Error(`${t}() is not supported - ${e}`)}}function Ss(t){return()=>{throw new Error(`function '${t}()' is not implemented`)}}function Cs(t,e){let n=0,r="",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[n];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)}r+=f,n++;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)}r+=d,n++;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)}r+=p,n++;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)}r+=p,n++;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 g=parseInt(a,10);o.includes("-")?h=h.padEnd(g):h=h.padStart(g)}r+=h,n++;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)}r+=f<0?`-${d}`:d,n++;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)}r+=f<0?`-${d}`:d,n++;break}case"c":{typeof u=="number"?r+=String.fromCharCode(u):r+=String(u??"").charAt(0)||"",n++;break}case"%":r+="%";break;default:r+=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":r+=`
|
|
274
|
+
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;default:r+=i}s+=2}else r+=t[s++];return r}var Ta,As=C(()=>{"use strict";Ta={length:zh,substr:Hh,index:Gh,split:qh,sub:Vh,gsub:Zh,match:Kh,gensub:Qh,tolower:Xh,toupper:Jh,sprintf:Yh,int:em,sqrt:tm,sin:nm,cos:rm,atan2:sm,log:im,exp:om,rand:am,srand:lm,system:Es("system","shell execution not allowed in sandboxed environment"),close:Es("close","file operations not allowed"),fflush:Es("fflush","file operations not allowed"),systime:Ss("systime"),mktime:Ss("mktime"),strftime:Ss("strftime")}});function Le(t){return typeof t=="number"?t!==0:t!==""}function ee(t){if(typeof t=="number")return t;let e=parseFloat(t);return Number.isNaN(e)?0:e}function te(t){return typeof t=="string"?t:(Number.isInteger(t),String(t))}function ks(t){if(typeof t=="number")return!0;let e=String(t).trim();return e===""?!1:!Number.isNaN(Number(e))}function kn(t,e){try{return new RegExp(t).test(e)}catch{return!1}}var Qt=C(()=>{"use strict"});function Oa(t,e){return t.FS===" "?e.trim().split(/\s+/).filter(Boolean):e.split(t.fieldSep)}function vt(t,e){return e===0?t.line:e<0||e>t.fields.length?"":t.fields[e-1]??""}function Xt(t,e,n){if(e===0)t.line=te(n),t.fields=Oa(t,t.line),t.NF=t.fields.length;else if(e>0){for(;t.fields.length<e;)t.fields.push("");t.fields[e-1]=te(n),t.NF=t.fields.length,t.line=t.fields.join(t.OFS)}}function Nn(t,e){t.line=e,t.fields=Oa(t,e),t.NF=t.fields.length}function Da(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 lr=C(()=>{"use strict";Qt()});function $t(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 yt(t,e,n){switch(e){case"FS":Da(t,te(n));return;case"OFS":t.OFS=te(n);return;case"ORS":t.ORS=te(n);return;case"NR":t.NR=Math.floor(ee(n));return;case"NF":{let r=Math.floor(ee(n));if(r<t.NF)t.fields=t.fields.slice(0,r),t.line=t.fields.join(t.OFS);else if(r>t.NF){for(;t.fields.length<r;)t.fields.push("");t.line=t.fields.join(t.OFS)}t.NF=r;return}case"FNR":t.FNR=Math.floor(ee(n));return;case"FILENAME":t.FILENAME=te(n);return;case"RSTART":t.RSTART=Math.floor(ee(n));return;case"RLENGTH":t.RLENGTH=Math.floor(ee(n));return;case"SUBSEP":t.SUBSEP=te(n);return}t.vars[e]=n}function Rt(t,e,n){return e==="ARGV"?t.ARGV[n]??"":t.arrays[e]?.[n]??""}function Jt(t,e,n,r){t.arrays[e]||(t.arrays[e]={}),t.arrays[e][n]=r}function La(t,e,n){return e==="ARGV"?t.ARGV[n]!==void 0:t.arrays[e]?.[n]!==void 0}function Ma(t,e,n){t.arrays[e]&&delete t.arrays[e][n]}function _a(t,e){delete t.arrays[e]}var Ns=C(()=>{"use strict";lr();Qt()});function Ba(t){Is=t}async function G(t,e){switch(e.type){case"number":return e.value;case"string":return e.value;case"regex":return kn(e.pattern,t.line)?1:0;case"field":return cm(t,e);case"variable":return $t(t,e.name);case"array_access":return um(t,e);case"binary":return fm(t,e);case"unary":return hm(t,e);case"ternary":return Le(await G(t,e.condition))?G(t,e.consequent):G(t,e.alternate);case"call":return mm(t,e.name,e.args);case"assignment":return ym(t,e);case"pre_increment":return xm(t,e.operand);case"pre_decrement":return wm(t,e.operand);case"post_increment":return bm(t,e.operand);case"post_decrement":return Em(t,e.operand);case"in":return Sm(t,e.key,e.array);case"getline":return Cm(t,e.variable,e.file);case"tuple":return km(t,e.elements);default:return""}}async function cm(t,e){let n=Math.floor(ee(await G(t,e.index)));return vt(t,n)}async function um(t,e){let n=te(await G(t,e.key));return Rt(t,e.array,n)}async function fm(t,e){let n=e.operator;if(n==="||")return Le(await G(t,e.left))||Le(await G(t,e.right))?1:0;if(n==="&&")return Le(await G(t,e.left))&&Le(await G(t,e.right))?1:0;if(n==="~"){let a=await G(t,e.left),l=e.right.type==="regex"?e.right.pattern:te(await G(t,e.right));try{return new RegExp(l).test(te(a))?1:0}catch{return 0}}if(n==="!~"){let a=await G(t,e.left),l=e.right.type==="regex"?e.right.pattern:te(await G(t,e.right));try{return new RegExp(l).test(te(a))?0:1}catch{return 1}}let r=await G(t,e.left),s=await G(t,e.right);if(n===" ")return te(r)+te(s);if(dm(n))return pm(r,s,n);let i=ee(r),o=ee(s);return $a(i,o,n)}function dm(t){return["<","<=",">",">=","==","!="].includes(t)}function pm(t,e,n){let r=ks(t),s=ks(e);if(r&&s){let a=ee(t),l=ee(e);switch(n){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=te(t),o=te(e);switch(n){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 hm(t,e){let n=await G(t,e.operand);switch(e.operator){case"!":return Le(n)?0:1;case"-":return-ee(n);case"+":return+ee(n);default:return n}}async function mm(t,e,n){let r=Ta[e];if(r)return r(n,t,{evalExpr:i=>G(t,i)});let s=t.functions.get(e);return s?gm(t,s,n):""}async function gm(t,e,n){if(t.currentRecursionDepth++,t.currentRecursionDepth>t.maxRecursionDepth)throw t.currentRecursionDepth--,new Q(`awk: recursion depth exceeded maximum (${t.maxRecursionDepth})`,"recursion",t.output);let r={};for(let i of e.params)r[i]=t.vars[i];for(let i=0;i<e.params.length;i++){let o=e.params[i],a=i<n.length?await G(t,n[i]):"";t.vars[o]=a}t.hasReturn=!1,t.returnValue=void 0,Is&&await Is(t,e.body.statements);let s=t.returnValue??"";for(let i of e.params)r[i]!==void 0?t.vars[i]=r[i]:delete t.vars[i];return t.hasReturn=!1,t.returnValue=void 0,t.currentRecursionDepth--,s}async function ym(t,e){let n=await G(t,e.value),r=e.target,s=e.operator,i;if(s==="=")i=n;else{let o;if(r.type==="field"){let c=Math.floor(ee(await G(t,r.index)));o=vt(t,c)}else if(r.type==="variable")o=$t(t,r.name);else{let c=te(await G(t,r.key));o=Rt(t,r.array,c)}let a=ee(o),l=ee(n);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=n}}if(r.type==="field"){let o=Math.floor(ee(await G(t,r.index)));Xt(t,o,i)}else if(r.type==="variable")yt(t,r.name,i);else{let o=te(await G(t,r.key));Jt(t,r.array,o,i)}return i}async function xm(t,e){let n;if(e.type==="field"){let r=Math.floor(ee(await G(t,e.index)));n=ee(vt(t,r))+1,Xt(t,r,n)}else if(e.type==="variable")n=ee($t(t,e.name))+1,yt(t,e.name,n);else{let r=te(await G(t,e.key));n=ee(Rt(t,e.array,r))+1,Jt(t,e.array,r,n)}return n}async function wm(t,e){let n;if(e.type==="field"){let r=Math.floor(ee(await G(t,e.index)));n=ee(vt(t,r))-1,Xt(t,r,n)}else if(e.type==="variable")n=ee($t(t,e.name))-1,yt(t,e.name,n);else{let r=te(await G(t,e.key));n=ee(Rt(t,e.array,r))-1,Jt(t,e.array,r,n)}return n}async function bm(t,e){let n;if(e.type==="field"){let r=Math.floor(ee(await G(t,e.index)));n=ee(vt(t,r)),Xt(t,r,n+1)}else if(e.type==="variable")n=ee($t(t,e.name)),yt(t,e.name,n+1);else{let r=te(await G(t,e.key));n=ee(Rt(t,e.array,r)),Jt(t,e.array,r,n+1)}return n}async function Em(t,e){let n;if(e.type==="field"){let r=Math.floor(ee(await G(t,e.index)));n=ee(vt(t,r)),Xt(t,r,n-1)}else if(e.type==="variable")n=ee($t(t,e.name)),yt(t,e.name,n-1);else{let r=te(await G(t,e.key));n=ee(Rt(t,e.array,r)),Jt(t,e.array,r,n-1)}return n}async function Sm(t,e,n){let r;if(e.type==="tuple"){let s=[];for(let i of e.elements)s.push(te(await G(t,i)));r=s.join(t.SUBSEP)}else r=te(await G(t,e));return La(t,n,r)?1:0}async function Cm(t,e,n){if(n)return Am(t,e,n);if(!t.lines||t.lineIndex===void 0)return-1;let r=t.lineIndex+1;if(r>=t.lines.length)return 0;let s=t.lines[r];return e?yt(t,e,s):Nn(t,s),t.NR++,t.lineIndex=r,1}async function Am(t,e,n){if(!t.fs||!t.cwd)return-1;let r=te(await G(t,n)),s=t.fs.resolvePath(t.cwd,r),i=`__fc_${s}`,o=`__fi_${s}`,a,l;if(t.vars[i]===void 0)try{a=(await t.fs.readFile(s)).split(`
|
|
275
|
+
`),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?yt(t,e,u):Nn(t,u),1}async function km(t,e){if(e.length===0)return"";for(let n=0;n<e.length-1;n++)await G(t,e[n]);return G(t,e[e.length-1])}var Is,vs=C(()=>{"use strict";de();Ra();As();lr();Qt();Ns();Is=null});async function Yt(t,e){for(let n of e)if(await Ft(t,n),Nm(t))break}function Nm(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 Yt(t,e.statements);break;case"expr_stmt":await G(t,e.expression);break;case"print":await Im(t,e.args,e.output);break;case"printf":await vm(t,e.format,e.args,e.output);break;case"if":await $m(t,e);break;case"while":await Rm(t,e);break;case"do_while":await Fm(t,e);break;case"for":await Pm(t,e);break;case"for_in":await Tm(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(ee(await G(t,e.code))):0;break;case"return":t.hasReturn=!0,t.returnValue=e.value?await G(t,e.value):"";break;case"delete":await Om(t,e.target);break}}async function Im(t,e,n){let r=[];for(let i of e)r.push(te(await G(t,i)));let s=r.join(t.OFS)+t.ORS;n?await Wa(t,n.redirect,n.file,s):t.output+=s}async function vm(t,e,n,r){let s=te(await G(t,e)),i=[];for(let a of n)i.push(await G(t,a));let o=Cs(s,i);r?await Wa(t,r.redirect,r.file,o):t.output+=o}async function Wa(t,e,n,r){if(!t.fs||!t.cwd){t.output+=r;return}let s=te(await G(t,n)),i=t.fs.resolvePath(t.cwd,s);e===">"?t.openedFiles.has(i)?await t.fs.appendFile(i,r):(await t.fs.writeFile(i,r),t.openedFiles.add(i)):(t.openedFiles.has(i)||t.openedFiles.add(i),await t.fs.appendFile(i,r))}async function $m(t,e){Le(await G(t,e.condition))?await Ft(t,e.consequent):e.alternate&&await Ft(t,e.alternate)}async function Rm(t,e){let n=0;for(;Le(await G(t,e.condition));){if(n++,n>t.maxIterations)throw new Q(`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 Fm(t,e){let n=0;do{if(n++,n>t.maxIterations)throw new Q(`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(Le(await G(t,e.condition)))}async function Pm(t,e){e.init&&await G(t,e.init);let n=0;for(;!e.condition||Le(await G(t,e.condition));){if(n++,n>t.maxIterations)throw new Q(`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 G(t,e.update)}}async function Tm(t,e){let n=t.arrays[e.array];if(n)for(let r of Object.keys(n)){if(t.vars[e.variable]=r,t.loopContinue=!1,await Ft(t,e.body),t.loopBreak){t.loopBreak=!1;break}if(t.shouldExit||t.shouldNext||t.hasReturn)break}}async function Om(t,e){if(e.type==="array_access"){let n=te(await G(t,e.key));Ma(t,e.array,n)}else e.type==="variable"&&_a(t,e.name)}var Ua=C(()=>{"use strict";de();As();vs();Qt();Ns();Ba(Yt)});var In,ja=C(()=>{"use strict";vs();lr();Qt();Ua();In=class{ctx;program=null;rangeStates=[];constructor(e){this.ctx=e}execute(e){this.program=e,this.ctx.output="";for(let n of e.functions)this.ctx.functions.set(n.name,n);this.rangeStates=e.rules.map(()=>!1)}async executeBegin(){if(this.program){for(let e of this.program.rules)if(e.pattern?.type==="begin"&&(await Yt(this.ctx,e.action.statements),this.ctx.shouldExit))break}}async executeLine(e){if(!(!this.program||this.ctx.shouldExit)){Nn(this.ctx,e),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let r=this.program.rules[n];r.pattern?.type==="begin"||r.pattern?.type==="end"||await this.matchesRule(r,n)&&await Yt(this.ctx,r.action.statements)}}}async executeEnd(){if(!(!this.program||this.ctx.shouldExit)){for(let e of this.program.rules)if(e.pattern?.type==="end"&&(await Yt(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,n){let r=e.pattern;if(!r)return!0;switch(r.type){case"begin":case"end":return!1;case"regex_pattern":return kn(r.pattern,this.ctx.line);case"expr_pattern":return Le(await G(this.ctx,r.expression));case"range":{let s=await this.matchPattern(r.start),i=await this.matchPattern(r.end);return this.rangeStates[n]?(i&&(this.rangeStates[n]=!1),!0):s?(this.rangeStates[n]=!0,i&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(e){switch(e.type){case"regex_pattern":return kn(e.pattern,this.ctx.line);case"expr_pattern":return Le(await G(this.ctx,e.expression));default:return!1}}}});var za=C(()=>{"use strict";va();ja()});function Lm(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,Dm,cr,Ha=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={}));Dm={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};cr=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 n=this.nextToken();n&&(e.push(n),this.lastTokenType=n.type)}return e.push(this.makeToken(x.EOF,"")),e}makeToken(e,n){return{type:e,value:n,line:this.line,column:this.column}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
276
276
|
`?(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)===`
|
|
277
277
|
`)this.advance(),this.advance();else break;else if(e==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
278
278
|
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,n=this.column,r=this.peek();return r===`
|
|
279
279
|
`?(this.advance(),{type:x.NEWLINE,value:`
|
|
280
280
|
`,line:e,column:n}):r==='"'?this.readString():r==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(r)||r==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(r)||r==="_"?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,n=this.column;this.advance();let r="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let s=this.advance();switch(s){case"n":r+=`
|
|
281
281
|
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case'"':r+='"';break;case"/":r+="/";break;default:r+=s}}else r+=this.advance();return this.peek()==='"'&&this.advance(),{type:x.STRING,value:r,line:e,column:n}}readRegex(){let e=this.line,n=this.column;this.advance();let r="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")r+=this.advance(),this.pos<this.input.length&&(r+=this.advance());else{if(this.peek()===`
|
|
282
|
-
`)break;r+=this.advance()}return this.peek()==="/"&&this.advance(),r=Rm(r),{type:x.REGEX,value:r,line:e,column:n}}readNumber(){let e=this.line,n=this.column,r="";for(;this.isDigit(this.peek());)r+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(r+=this.advance();this.isDigit(this.peek());)r+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(r+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(r+=this.advance());this.isDigit(this.peek());)r+=this.advance();return{type:x.NUMBER,value:parseFloat(r),line:e,column:n}}readIdentifier(){let e=this.line,n=this.column,r="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)r+=this.advance();let s=$m[r];return s?{type:s,value:r,line:e,column:n}:{type:x.IDENT,value:r,line:e,column:n}}readOperator(){let e=this.line,n=this.column,r=this.advance(),s=this.peek();switch(r){case"+":return s==="+"?(this.advance(),{type:x.INCREMENT,value:"++",line:e,column:n}):s==="="?(this.advance(),{type:x.PLUS_ASSIGN,value:"+=",line:e,column:n}):{type:x.PLUS,value:"+",line:e,column:n};case"-":return s==="-"?(this.advance(),{type:x.DECREMENT,value:"--",line:e,column:n}):s==="="?(this.advance(),{type:x.MINUS_ASSIGN,value:"-=",line:e,column:n}):{type:x.MINUS,value:"-",line:e,column:n};case"*":return s==="*"?(this.advance(),{type:x.CARET,value:"**",line:e,column:n}):s==="="?(this.advance(),{type:x.STAR_ASSIGN,value:"*=",line:e,column:n}):{type:x.STAR,value:"*",line:e,column:n};case"/":return s==="="?(this.advance(),{type:x.SLASH_ASSIGN,value:"/=",line:e,column:n}):{type:x.SLASH,value:"/",line:e,column:n};case"%":return s==="="?(this.advance(),{type:x.PERCENT_ASSIGN,value:"%=",line:e,column:n}):{type:x.PERCENT,value:"%",line:e,column:n};case"^":return s==="="?(this.advance(),{type:x.CARET_ASSIGN,value:"^=",line:e,column:n}):{type:x.CARET,value:"^",line:e,column:n};case"=":return s==="="?(this.advance(),{type:x.EQ,value:"==",line:e,column:n}):{type:x.ASSIGN,value:"=",line:e,column:n};case"!":return s==="="?(this.advance(),{type:x.NE,value:"!=",line:e,column:n}):s==="~"?(this.advance(),{type:x.NOT_MATCH,value:"!~",line:e,column:n}):{type:x.NOT,value:"!",line:e,column:n};case"<":return s==="="?(this.advance(),{type:x.LE,value:"<=",line:e,column:n}):{type:x.LT,value:"<",line:e,column:n};case">":return s==="="?(this.advance(),{type:x.GE,value:">=",line:e,column:n}):s===">"?(this.advance(),{type:x.APPEND,value:">>",line:e,column:n}):{type:x.GT,value:">",line:e,column:n};case"&":return s==="&"?(this.advance(),{type:x.AND,value:"&&",line:e,column:n}):{type:x.IDENT,value:"&",line:e,column:n};case"|":return s==="|"?(this.advance(),{type:x.OR,value:"||",line:e,column:n}):{type:x.PIPE,value:"|",line:e,column:n};case"~":return{type:x.MATCH,value:"~",line:e,column:n};case"?":return{type:x.QUESTION,value:"?",line:e,column:n};case":":return{type:x.COLON,value:":",line:e,column:n};case",":return{type:x.COMMA,value:",",line:e,column:n};case";":return{type:x.SEMICOLON,value:";",line:e,column:n};case"(":return{type:x.LPAREN,value:"(",line:e,column:n};case")":return{type:x.RPAREN,value:")",line:e,column:n};case"{":return{type:x.LBRACE,value:"{",line:e,column:n};case"}":return{type:x.RBRACE,value:"}",line:e,column:n};case"[":return{type:x.LBRACKET,value:"[",line:e,column:n};case"]":return{type:x.RBRACKET,value:"]",line:e,column:n};case"$":return{type:x.DOLLAR,value:"$",line:e,column:n};default:return{type:x.IDENT,value:r,line:e,column:n}}}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 ur,Ga=C(()=>{"use strict";Ha();ur=class{tokens=[];pos=0;parse(e){let n=new cr(e);return this.tokens=n.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,n){if(!this.check(e)){let r=this.current();throw new Error(n||`Expected ${e}, got ${r.type} at line ${r.line}:${r.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=[],n=[];for(this.skipNewlines();!this.check(x.EOF)&&(this.skipNewlines(),!this.check(x.EOF));)this.check(x.FUNCTION)?e.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:n}}parseFunction(){this.expect(x.FUNCTION);let e=this.expect(x.IDENT).value;this.expect(x.LPAREN);let n=[];if(!this.check(x.RPAREN))for(n.push(this.expect(x.IDENT).value);this.check(x.COMMA);)this.advance(),n.push(this.expect(x.IDENT).value);this.expect(x.RPAREN),this.skipNewlines();let r=this.parseBlock();return{name:e,params:n,body:r}}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 r=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:r.value}};e={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:r.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 n;return this.check(x.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:e,action:n}}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 n;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(x.RETURN)){this.advance();let n;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(x.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}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 n=this.parseStatement();this.skipTerminators();let r;return this.check(x.ELSE)&&(this.advance(),this.skipNewlines(),r=this.parseStatement()),{type:"if",condition:e,consequent:n,alternate:r}}parseWhile(){this.expect(x.WHILE),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:e,body:n}}parseDoWhile(){this.expect(x.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(x.WHILE),this.expect(x.LPAREN);let n=this.parseExpression();return this.expect(x.RPAREN),{type:"do_while",body:e,condition:n}}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 n;this.check(x.SEMICOLON)||(n=this.parseExpression()),this.expect(x.SEMICOLON);let r;this.check(x.RPAREN)||(r=this.parseExpression()),this.expect(x.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:n,update:r,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 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:"print",args:e,output:n}}parsePrintArg(){return this.lookAheadForTernary()?this.parseTernary():this.parsePrintOr()}lookAheadForTernary(){let e=0,n=this.pos;for(;n<this.tokens.length;){let r=this.tokens[n];if(r.type===x.LPAREN&&e++,r.type===x.RPAREN&&e--,r.type===x.QUESTION&&e===0)return!0;if(r.type===x.NEWLINE||r.type===x.SEMICOLON||r.type===x.RBRACE||r.type===x.COMMA||r.type===x.PIPE)return!1;n++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(x.OR);){this.advance();let n=this.parsePrintAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parsePrintAnd(){let e=this.parsePrintIn();for(;this.check(x.AND);){this.advance();let n=this.parsePrintIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parsePrintIn(){let e=this.parsePrintMatch();if(this.check(x.IN)){this.advance();let n=String(this.expect(x.IDENT).value);return{type:"in",key:e,array:n}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let n=this.advance().type===x.MATCH?"~":"!~",r=this.parsePrintComparison();e={type:"binary",operator:n,left:e,right:r}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GE,x.EQ,x.NE);){let n=this.advance(),r=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[n.value],left:e,right:r}}return e}parsePrintf(){this.expect(x.PRINTF);let e=this.parsePrintArg(),n=[];for(;this.check(x.COMMA);)this.advance(),n.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:"printf",format:e,args:n,output:r}}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 n=this.advance(),r=this.parseAssignment();if(e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],target:e,value:r}}return e}parseTernary(){let e=this.parseOr();if(this.check(x.QUESTION)){this.advance();let n=this.parseExpression();this.expect(x.COLON);let r=this.parseExpression();e={type:"ternary",condition:e,consequent:n,alternate:r}}return e}parseOr(){let e=this.parseAnd();for(;this.check(x.OR);){this.advance();let n=this.parseAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parseLogicalOrRest(e){for(e=this.parseLogicalAndRest(e);this.check(x.OR);){this.advance();let n=this.parseAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parseLogicalAndRest(e){for(;this.check(x.AND);){this.advance();let n=this.parseIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parseAnd(){let e=this.parseIn();for(;this.check(x.AND);){this.advance();let n=this.parseIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parseIn(){let e=this.parseMatch();if(this.check(x.IN)){this.advance();let n=this.expect(x.IDENT).value;return{type:"in",key:e,array:n}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let n=this.advance().type===x.MATCH?"~":"!~",r=this.parseComparison();e={type:"binary",operator:n,left:e,right:r}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.NE);){let n=this.advance(),r=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[n.value],left:e,right:r}}return e}parseConcatenation(){let e=this.parseAddSub();for(;this.canStartExpression()&&!this.isComparisonOrHigherOp();){let n=this.parseAddSub();e={type:"binary",operator:" ",left:e,right:n}}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 n=this.advance().value,r=this.parseMulDiv();e={type:"binary",operator:n,left:e,right:r}}return e}parseMulDiv(){let e=this.parseUnary();for(;this.match(x.STAR,x.SLASH,x.PERCENT);){let n=this.advance(),r=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[n.value],left:e,right:r}}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,n=this.parseUnary();return{type:"unary",operator:e,operand:n}}return this.parsePower()}parsePower(){let e=this.parsePostfix();if(this.check(x.CARET)){this.advance();let n=this.parsePower();e={type:"binary",operator:"^",left:e,right:n}}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 n=[e];for(;this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(x.RPAREN),{type:"tuple",elements:n}}return this.expect(x.RPAREN),e}if(this.check(x.GETLINE)){this.advance();let e,n;return this.check(x.IDENT)&&(e=this.advance().value),this.check(x.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:e,file:n}}if(this.check(x.IDENT)){let e=this.advance().value;if(this.check(x.LPAREN)){this.advance();let n=[];if(!this.check(x.RPAREN))for(n.push(this.parseExpression());this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(x.RPAREN),{type:"call",name:e,args:n}}if(this.check(x.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(x.RBRACKET);let r;if(n.length===1)r=n[0];else{r=n[0];for(let s=1;s<n.length;s++)r={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:r,right:{type:"variable",name:"SUBSEP"}},right:n[s]}}return{type:"array_access",array:e,key:r}}return{type:"variable",name:e}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}}});var Ka={};M(Ka,{awkCommand2:()=>Pm});function qa(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
|
|
283
|
-
`).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Va(t){if(t===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(t))try{return new RegExp(t)}catch{return new RegExp(Za(t))}return new RegExp(Za(t))}function Za(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var
|
|
282
|
+
`)break;r+=this.advance()}return this.peek()==="/"&&this.advance(),r=Lm(r),{type:x.REGEX,value:r,line:e,column:n}}readNumber(){let e=this.line,n=this.column,r="";for(;this.isDigit(this.peek());)r+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(r+=this.advance();this.isDigit(this.peek());)r+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(r+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(r+=this.advance());this.isDigit(this.peek());)r+=this.advance();return{type:x.NUMBER,value:parseFloat(r),line:e,column:n}}readIdentifier(){let e=this.line,n=this.column,r="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)r+=this.advance();let s=Dm[r];return s?{type:s,value:r,line:e,column:n}:{type:x.IDENT,value:r,line:e,column:n}}readOperator(){let e=this.line,n=this.column,r=this.advance(),s=this.peek();switch(r){case"+":return s==="+"?(this.advance(),{type:x.INCREMENT,value:"++",line:e,column:n}):s==="="?(this.advance(),{type:x.PLUS_ASSIGN,value:"+=",line:e,column:n}):{type:x.PLUS,value:"+",line:e,column:n};case"-":return s==="-"?(this.advance(),{type:x.DECREMENT,value:"--",line:e,column:n}):s==="="?(this.advance(),{type:x.MINUS_ASSIGN,value:"-=",line:e,column:n}):{type:x.MINUS,value:"-",line:e,column:n};case"*":return s==="*"?(this.advance(),{type:x.CARET,value:"**",line:e,column:n}):s==="="?(this.advance(),{type:x.STAR_ASSIGN,value:"*=",line:e,column:n}):{type:x.STAR,value:"*",line:e,column:n};case"/":return s==="="?(this.advance(),{type:x.SLASH_ASSIGN,value:"/=",line:e,column:n}):{type:x.SLASH,value:"/",line:e,column:n};case"%":return s==="="?(this.advance(),{type:x.PERCENT_ASSIGN,value:"%=",line:e,column:n}):{type:x.PERCENT,value:"%",line:e,column:n};case"^":return s==="="?(this.advance(),{type:x.CARET_ASSIGN,value:"^=",line:e,column:n}):{type:x.CARET,value:"^",line:e,column:n};case"=":return s==="="?(this.advance(),{type:x.EQ,value:"==",line:e,column:n}):{type:x.ASSIGN,value:"=",line:e,column:n};case"!":return s==="="?(this.advance(),{type:x.NE,value:"!=",line:e,column:n}):s==="~"?(this.advance(),{type:x.NOT_MATCH,value:"!~",line:e,column:n}):{type:x.NOT,value:"!",line:e,column:n};case"<":return s==="="?(this.advance(),{type:x.LE,value:"<=",line:e,column:n}):{type:x.LT,value:"<",line:e,column:n};case">":return s==="="?(this.advance(),{type:x.GE,value:">=",line:e,column:n}):s===">"?(this.advance(),{type:x.APPEND,value:">>",line:e,column:n}):{type:x.GT,value:">",line:e,column:n};case"&":return s==="&"?(this.advance(),{type:x.AND,value:"&&",line:e,column:n}):{type:x.IDENT,value:"&",line:e,column:n};case"|":return s==="|"?(this.advance(),{type:x.OR,value:"||",line:e,column:n}):{type:x.PIPE,value:"|",line:e,column:n};case"~":return{type:x.MATCH,value:"~",line:e,column:n};case"?":return{type:x.QUESTION,value:"?",line:e,column:n};case":":return{type:x.COLON,value:":",line:e,column:n};case",":return{type:x.COMMA,value:",",line:e,column:n};case";":return{type:x.SEMICOLON,value:";",line:e,column:n};case"(":return{type:x.LPAREN,value:"(",line:e,column:n};case")":return{type:x.RPAREN,value:")",line:e,column:n};case"{":return{type:x.LBRACE,value:"{",line:e,column:n};case"}":return{type:x.RBRACE,value:"}",line:e,column:n};case"[":return{type:x.LBRACKET,value:"[",line:e,column:n};case"]":return{type:x.RBRACKET,value:"]",line:e,column:n};case"$":return{type:x.DOLLAR,value:"$",line:e,column:n};default:return{type:x.IDENT,value:r,line:e,column:n}}}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 ur,Ga=C(()=>{"use strict";Ha();ur=class{tokens=[];pos=0;parse(e){let n=new cr(e);return this.tokens=n.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,n){if(!this.check(e)){let r=this.current();throw new Error(n||`Expected ${e}, got ${r.type} at line ${r.line}:${r.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=[],n=[];for(this.skipNewlines();!this.check(x.EOF)&&(this.skipNewlines(),!this.check(x.EOF));)this.check(x.FUNCTION)?e.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:e,rules:n}}parseFunction(){this.expect(x.FUNCTION);let e=this.expect(x.IDENT).value;this.expect(x.LPAREN);let n=[];if(!this.check(x.RPAREN))for(n.push(this.expect(x.IDENT).value);this.check(x.COMMA);)this.advance(),n.push(this.expect(x.IDENT).value);this.expect(x.RPAREN),this.skipNewlines();let r=this.parseBlock();return{name:e,params:n,body:r}}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 r=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:r.value}};e={type:"expr_pattern",expression:this.parseLogicalOrRest(s)}}else{let s={type:"regex_pattern",pattern:r.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 n;return this.check(x.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:e,action:n}}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 n;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(x.RETURN)){this.advance();let n;return!this.check(x.NEWLINE)&&!this.check(x.SEMICOLON)&&!this.check(x.RBRACE)&&!this.check(x.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(x.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}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 n=this.parseStatement();this.skipTerminators();let r;return this.check(x.ELSE)&&(this.advance(),this.skipNewlines(),r=this.parseStatement()),{type:"if",condition:e,consequent:n,alternate:r}}parseWhile(){this.expect(x.WHILE),this.expect(x.LPAREN);let e=this.parseExpression();this.expect(x.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:e,body:n}}parseDoWhile(){this.expect(x.DO),this.skipNewlines();let e=this.parseStatement();this.skipNewlines(),this.expect(x.WHILE),this.expect(x.LPAREN);let n=this.parseExpression();return this.expect(x.RPAREN),{type:"do_while",body:e,condition:n}}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 n;this.check(x.SEMICOLON)||(n=this.parseExpression()),this.expect(x.SEMICOLON);let r;this.check(x.RPAREN)||(r=this.parseExpression()),this.expect(x.RPAREN),this.skipNewlines();let s=this.parseStatement();return{type:"for",init:e,condition:n,update:r,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 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:"print",args:e,output:n}}parsePrintArg(){return this.lookAheadForTernary()?this.parseTernary():this.parsePrintOr()}lookAheadForTernary(){let e=0,n=this.pos;for(;n<this.tokens.length;){let r=this.tokens[n];if(r.type===x.LPAREN&&e++,r.type===x.RPAREN&&e--,r.type===x.QUESTION&&e===0)return!0;if(r.type===x.NEWLINE||r.type===x.SEMICOLON||r.type===x.RBRACE||r.type===x.COMMA||r.type===x.PIPE)return!1;n++}return!1}parsePrintOr(){let e=this.parsePrintAnd();for(;this.check(x.OR);){this.advance();let n=this.parsePrintAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parsePrintAnd(){let e=this.parsePrintIn();for(;this.check(x.AND);){this.advance();let n=this.parsePrintIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parsePrintIn(){let e=this.parsePrintMatch();if(this.check(x.IN)){this.advance();let n=String(this.expect(x.IDENT).value);return{type:"in",key:e,array:n}}return e}parsePrintMatch(){let e=this.parsePrintComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let n=this.advance().type===x.MATCH?"~":"!~",r=this.parsePrintComparison();e={type:"binary",operator:n,left:e,right:r}}return e}parsePrintComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GE,x.EQ,x.NE);){let n=this.advance(),r=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[n.value],left:e,right:r}}return e}parsePrintf(){this.expect(x.PRINTF);let e=this.parsePrintArg(),n=[];for(;this.check(x.COMMA);)this.advance(),n.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:"printf",format:e,args:n,output:r}}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 n=this.advance(),r=this.parseAssignment();if(e.type!=="variable"&&e.type!=="field"&&e.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],target:e,value:r}}return e}parseTernary(){let e=this.parseOr();if(this.check(x.QUESTION)){this.advance();let n=this.parseExpression();this.expect(x.COLON);let r=this.parseExpression();e={type:"ternary",condition:e,consequent:n,alternate:r}}return e}parseOr(){let e=this.parseAnd();for(;this.check(x.OR);){this.advance();let n=this.parseAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parseLogicalOrRest(e){for(e=this.parseLogicalAndRest(e);this.check(x.OR);){this.advance();let n=this.parseAnd();e={type:"binary",operator:"||",left:e,right:n}}return e}parseLogicalAndRest(e){for(;this.check(x.AND);){this.advance();let n=this.parseIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parseAnd(){let e=this.parseIn();for(;this.check(x.AND);){this.advance();let n=this.parseIn();e={type:"binary",operator:"&&",left:e,right:n}}return e}parseIn(){let e=this.parseMatch();if(this.check(x.IN)){this.advance();let n=this.expect(x.IDENT).value;return{type:"in",key:e,array:n}}return e}parseMatch(){let e=this.parseComparison();for(;this.match(x.MATCH,x.NOT_MATCH);){let n=this.advance().type===x.MATCH?"~":"!~",r=this.parseComparison();e={type:"binary",operator:n,left:e,right:r}}return e}parseComparison(){let e=this.parseConcatenation();for(;this.match(x.LT,x.LE,x.GT,x.GE,x.EQ,x.NE);){let n=this.advance(),r=this.parseConcatenation();e={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[n.value],left:e,right:r}}return e}parseConcatenation(){let e=this.parseAddSub();for(;this.canStartExpression()&&!this.isComparisonOrHigherOp();){let n=this.parseAddSub();e={type:"binary",operator:" ",left:e,right:n}}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 n=this.advance().value,r=this.parseMulDiv();e={type:"binary",operator:n,left:e,right:r}}return e}parseMulDiv(){let e=this.parseUnary();for(;this.match(x.STAR,x.SLASH,x.PERCENT);){let n=this.advance(),r=this.parseUnary();e={type:"binary",operator:{"*":"*","/":"/","%":"%"}[n.value],left:e,right:r}}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,n=this.parseUnary();return{type:"unary",operator:e,operand:n}}return this.parsePower()}parsePower(){let e=this.parsePostfix();if(this.check(x.CARET)){this.advance();let n=this.parsePower();e={type:"binary",operator:"^",left:e,right:n}}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 n=[e];for(;this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(x.RPAREN),{type:"tuple",elements:n}}return this.expect(x.RPAREN),e}if(this.check(x.GETLINE)){this.advance();let e,n;return this.check(x.IDENT)&&(e=this.advance().value),this.check(x.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:e,file:n}}if(this.check(x.IDENT)){let e=this.advance().value;if(this.check(x.LPAREN)){this.advance();let n=[];if(!this.check(x.RPAREN))for(n.push(this.parseExpression());this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(x.RPAREN),{type:"call",name:e,args:n}}if(this.check(x.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(x.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(x.RBRACKET);let r;if(n.length===1)r=n[0];else{r=n[0];for(let s=1;s<n.length;s++)r={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:r,right:{type:"variable",name:"SUBSEP"}},right:n[s]}}return{type:"array_access",array:e,key:r}}return{type:"variable",name:e}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}}});var Ka={};M(Ka,{awkCommand2:()=>_m});function qa(t){return t.replace(/\\t/g," ").replace(/\\n/g,`
|
|
283
|
+
`).replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function Va(t){if(t===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(t))try{return new RegExp(t)}catch{return new RegExp(Za(t))}return new RegExp(Za(t))}function Za(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Mm,_m,Qa=C(()=>{"use strict";de();j();za();Ga();Mm={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"]},_m={name:"awk",async execute(t,e){if(I(t))return N(Mm);let n=/\s+/,r=" ",s={},i=0;for(let p=0;p<t.length;p++){let h=t[p];if(h==="-F"&&p+1<t.length)r=qa(t[++p]),n=Va(r),i=p+1;else if(h.startsWith("-F"))r=qa(h.slice(2)),n=Va(r),i=p+1;else if(h==="-v"&&p+1<t.length){let g=t[++p],m=g.indexOf("=");if(m>0){let w=g.slice(0,m),b=g.slice(m+1);s[w]=b}i=p+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=p+1}else if(!h.startsWith("-")){i=p;break}}}if(i>=t.length)return{stdout:"",stderr:`awk: missing program
|
|
284
284
|
`,exitCode:1};let o=t[i],a=t.slice(i+1),l=new ur,c;try{c=l.parse(o)}catch(p){return{stdout:"",stderr:`awk: ${p instanceof Error?p.message:String(p)}
|
|
285
285
|
`,exitCode:1}}let u={readFile:e.fs.readFile.bind(e.fs),writeFile:e.fs.writeFile.bind(e.fs),appendFile:async(p,h)=>{try{let g=await e.fs.readFile(p);await e.fs.writeFile(p,g+h)}catch{await e.fs.writeFile(p,h)}},resolvePath:e.fs.resolvePath.bind(e.fs)},f=bs({fieldSep:n,maxIterations:e.limits?.maxAwkIterations,fs:u,cwd:e.cwd});f.FS=r,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 In(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 g=e.fs.resolvePath(e.cwd,h),w=(await e.fs.readFile(g)).split(`
|
|
286
286
|
`);w.length>0&&w[w.length-1]===""&&w.pop(),p.push({filename:h,lines:w})}catch{return{stdout:"",stderr:`awk: ${h}: No such file or directory
|
|
287
287
|
`,exitCode:1}}else{let h=e.stdin.split(`
|
|
288
288
|
`);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),g=p instanceof Q?Q.EXIT_CODE:2;return{stdout:d.getOutput(),stderr:`awk: ${h}
|
|
289
|
-
`,exitCode:g}}}}});function Xa(t){let e=t.trim(),n=e.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!n){let o=parseFloat(e);return Number.isNaN(o)?0:o}let r=parseFloat(n[1]),s=(n[2]||"").toLowerCase(),i=
|
|
289
|
+
`,exitCode:g}}}}});function Xa(t){let e=t.trim(),n=e.match(/^([+-]?\d*\.?\d+)\s*([kmgtpeKMGTPE])?[iI]?[bB]?$/);if(!n){let o=parseFloat(e);return Number.isNaN(o)?0:o}let r=parseFloat(n[1]),s=(n[2]||"").toLowerCase(),i=Bm[s]||1;return r*i}function Ja(t){let e=t.trim().toLowerCase().slice(0,3);return Wm[e]||0}function Um(t,e){let n=t.split(/(\d+)/),r=e.split(/(\d+)/),s=Math.max(n.length,r.length);for(let i=0;i<s;i++){let o=n[i]||"",a=r[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 Ya(t){return t.replace(/[^a-zA-Z0-9\s]/g,"")}function $s(t,e,n){let r=n!==null?n:/\s+/,s=t.split(r),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+=n||" "),a+=c}return e.ignoreLeading&&(a=a.trimStart()),a}function el(t,e,n){let r=t,s=e;if(n.dictionaryOrder&&(r=Ya(r),s=Ya(s)),n.ignoreCase&&(r=r.toLowerCase(),s=s.toLowerCase()),n.monthSort){let i=Ja(r),o=Ja(s);return i-o}if(n.humanNumeric){let i=Xa(r),o=Xa(s);return i-o}if(n.versionSort)return Um(r,s);if(n.numeric){let i=parseFloat(r)||0,o=parseFloat(s)||0;return i-o}return r.localeCompare(s)}function tl(t){let{keys:e,fieldDelimiter:n,numeric:r,ignoreCase:s,reverse:i,humanNumeric:o,versionSort:a,dictionaryOrder:l,monthSort:c,ignoreLeadingBlanks:u,stable:f}=t;return(d,p)=>{let h=d,g=p;if(u&&(h=h.trimStart(),g=g.trimStart()),e.length===0){let w=el(h,g,{numeric:r,ignoreCase:s,humanNumeric:o,versionSort:a,dictionaryOrder:l,monthSort:c});if(w!==0)return i?-w:w;if(!f){let b=d.localeCompare(p);return i?-b:b}return 0}for(let m of e){let w=$s(h,m,n),b=$s(g,m,n);m.ignoreLeading&&(w=w.trimStart(),b=b.trimStart());let E={numeric:m.numeric??r,ignoreCase:m.ignoreCase??s,humanNumeric:m.humanNumeric??o,versionSort:m.versionSort??a,dictionaryOrder:m.dictionaryOrder??l,monthSort:m.monthSort??c},S=m.reverse??i,v=el(w,b,E);if(v!==0)return S?-v:v}if(!f){let m=d.localeCompare(p);return i?-m:m}return 0}}function nl(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 n=e.keys[0],r=new Set;return t.filter(s=>{let i=$s(s,n,e.fieldDelimiter);return(n.ignoreCase??e.ignoreCase)&&(i=i.toLowerCase()),r.has(i)?!1:(r.add(i),!0)})}var Bm,Wm,rl=C(()=>{"use strict";Bm={"":1,k:1024,m:1048576,g:1073741824,t:1099511627776,p:0x4000000000000,e:1152921504606847e3},Wm={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 fr(t){let e={startField:1},n="",r=t,s=r.match(/([bdfhMnrV]+)$/);s&&(n=s[1],r=r.slice(0,-n.length)),n.includes("n")&&(e.numeric=!0),n.includes("r")&&(e.reverse=!0),n.includes("f")&&(e.ignoreCase=!0),n.includes("b")&&(e.ignoreLeading=!0),n.includes("h")&&(e.humanNumeric=!0),n.includes("V")&&(e.versionSort=!0),n.includes("d")&&(e.dictionaryOrder=!0),n.includes("M")&&(e.monthSort=!0);let i=r.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 sl=C(()=>{"use strict"});var il={};M(il,{sortCommand:()=>zm});var jm,zm,ol=C(()=>{"use strict";It();j();rl();sl();jm={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]]
|
|
290
290
|
F is a field number (1-indexed)
|
|
291
291
|
C is a character position within the field (1-indexed)
|
|
292
292
|
OPTS can be: b d f h M n r V (per-key modifiers)
|
|
@@ -296,14 +296,14 @@ Examples:
|
|
|
296
296
|
-k2,2 sort by second field only
|
|
297
297
|
-k1.3 sort by first field starting at 3rd character
|
|
298
298
|
-k1,2n sort by fields 1-2 numerically
|
|
299
|
-
-k2 -k1 sort by field 2, then by field 1`},
|
|
299
|
+
-k2 -k1 sort by field 2, then by field 1`},zm={name:"sort",async execute(t,e){if(I(t))return N(jm);let n={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},r=[];for(let c=0;c<t.length;c++){let u=t[c];if(u==="-r"||u==="--reverse")n.reverse=!0;else if(u==="-n"||u==="--numeric-sort")n.numeric=!0;else if(u==="-u"||u==="--unique")n.unique=!0;else if(u==="-f"||u==="--ignore-case")n.ignoreCase=!0;else if(u==="-h"||u==="--human-numeric-sort")n.humanNumeric=!0;else if(u==="-V"||u==="--version-sort")n.versionSort=!0;else if(u==="-d"||u==="--dictionary-order")n.dictionaryOrder=!0;else if(u==="-M"||u==="--month-sort")n.monthSort=!0;else if(u==="-b"||u==="--ignore-leading-blanks")n.ignoreLeadingBlanks=!0;else if(u==="-s"||u==="--stable")n.stable=!0;else if(u==="-c"||u==="--check")n.checkOnly=!0;else if(u==="-o"||u==="--output")n.outputFile=t[++c]||null;else if(u.startsWith("-o"))n.outputFile=u.slice(2)||null;else if(u.startsWith("--output="))n.outputFile=u.slice(9)||null;else if(u==="-t"||u==="--field-separator")n.fieldDelimiter=t[++c]||null;else if(u.startsWith("-t"))n.fieldDelimiter=u.slice(2)||null;else if(u.startsWith("--field-separator="))n.fieldDelimiter=u.slice(18)||null;else if(u==="-k"||u==="--key"){let f=t[++c];if(f){let d=fr(f);d&&n.keys.push(d)}}else if(u.startsWith("-k")){let f=fr(u.slice(2));f&&n.keys.push(f)}else if(u.startsWith("--key=")){let f=fr(u.slice(6));f&&n.keys.push(f)}else{if(u.startsWith("--"))return L("sort",u);if(u.startsWith("-")&&!u.startsWith("--")){let f=!1;for(let d of u.slice(1))if(d==="r")n.reverse=!0;else if(d==="n")n.numeric=!0;else if(d==="u")n.unique=!0;else if(d==="f")n.ignoreCase=!0;else if(d==="h")n.humanNumeric=!0;else if(d==="V")n.versionSort=!0;else if(d==="d")n.dictionaryOrder=!0;else if(d==="M")n.monthSort=!0;else if(d==="b")n.ignoreLeadingBlanks=!0;else if(d==="s")n.stable=!0;else if(d==="c")n.checkOnly=!0;else{f=!0;break}if(f)return L("sort",u)}else r.push(u)}}let s=await qt(e,r,{cmdName:"sort"});if(!s.ok)return s.error;let o=s.content.split(`
|
|
300
300
|
`);o.length>0&&o[o.length-1]===""&&o.pop();let a=tl(n);if(n.checkOnly){let c=r.length>0?r[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]}
|
|
301
301
|
`,exitCode:1};return{stdout:"",stderr:"",exitCode:0}}o.sort(a),n.unique&&(o=nl(o,n));let l=o.length>0?`${o.join(`
|
|
302
302
|
`)}
|
|
303
|
-
`:"";if(n.outputFile){let c=e.fs.resolvePath(e.cwd,n.outputFile);return await e.fs.writeFile(c,l),{stdout:"",stderr:"",exitCode:0}}return{stdout:l,stderr:"",exitCode:0}}}});var al={};M(al,{uniqCommand:()=>
|
|
303
|
+
`:"";if(n.outputFile){let c=e.fs.resolvePath(e.cwd,n.outputFile);return await e.fs.writeFile(c,l),{stdout:"",stderr:"",exitCode:0}}return{stdout:l,stderr:"",exitCode:0}}}});var al={};M(al,{uniqCommand:()=>qm});var Hm,Gm,qm,ll=C(()=>{"use strict";Ae();It();j();Hm={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"]},Gm={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"}},qm={name:"uniq",async execute(t,e){if(I(t))return N(Hm);let n=J("uniq",t,Gm);if(!n.ok)return n.error;let{count:r,duplicatesOnly:s,uniqueOnly:i,ignoreCase:o}=n.result.flags,a=n.result.positional,l=await qt(e,a,{cmdName:"uniq"});if(!l.ok)return l.error;let u=l.content.split(`
|
|
304
304
|
`);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=(w,b)=>o?w.toLowerCase()===b.toLowerCase():w===b;for(let w=1;w<u.length;w++)h(u[w],d)?p++:(f.push({line:d,count:p}),d=u[w],p=1);f.push({line:d,count:p});let g=f;s?g=f.filter(w=>w.count>1):i&&(g=f.filter(w=>w.count===1));let m="";for(let{line:w,count:b}of g)r?m+=`${String(b).padStart(4)} ${w}
|
|
305
305
|
`:m+=`${w}
|
|
306
|
-
`;return{stdout:m,stderr:"",exitCode:0}}}});var cl={};M(cl,{commCommand:()=>
|
|
306
|
+
`;return{stdout:m,stderr:"",exitCode:0}}}});var cl={};M(cl,{commCommand:()=>Zm});var Vm,Zm,ul=C(()=>{"use strict";j();Vm={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"]},Zm={name:"comm",async execute(t,e){if(I(t))return N(Vm);let n=!1,r=!1,s=!1,i=[];for(let m of t)if(m==="-1")n=!0;else if(m==="-2")r=!0;else if(m==="-3")s=!0;else if(m==="-12"||m==="-21")n=!0,r=!0;else if(m==="-13"||m==="-31")n=!0,s=!0;else if(m==="-23"||m==="-32")r=!0,s=!0;else if(m==="-123"||m==="-132"||m==="-213"||m==="-231"||m==="-312"||m==="-321")n=!0,r=!0,s=!0;else{if(m.startsWith("-")&&m!=="-")return L("comm",m);i.push(m)}if(i.length!==2)return{stdout:"",stderr:`comm: missing operand
|
|
307
307
|
Try 'comm --help' for more information.
|
|
308
308
|
`,exitCode:1};let o=async m=>{if(m==="-")return e.stdin;try{let w=e.fs.resolvePath(e.cwd,m);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
|
|
309
309
|
`,exitCode:1};let l=await o(i[1]);if(l===null)return{stdout:"",stderr:`comm: ${i[1]}: No such file or directory
|
|
@@ -314,18 +314,18 @@ Try 'comm --help' for more information.
|
|
|
314
314
|
`),f++):c[f]<u[d]?(n||(p+=`${c[f]}
|
|
315
315
|
`),f++):c[f]>u[d]?(r||(p+=`${h}${u[d]}
|
|
316
316
|
`),d++):(s||(p+=`${g}${c[f]}
|
|
317
|
-
`),f++,d++);return{stdout:p,stderr:"",exitCode:0}}}});var fl={};M(fl,{cutCommand:()=>
|
|
317
|
+
`),f++,d++);return{stdout:p,stderr:"",exitCode:0}}}});var fl={};M(fl,{cutCommand:()=>Jm});function Qm(t){let e=[],n=t.split(",");for(let r of n)if(r.includes("-")){let[s,i]=r.split("-");e.push({start:s?parseInt(s,10):1,end:i?parseInt(i,10):null})}else{let s=parseInt(r,10);e.push({start:s,end:s})}return e}function Xm(t,e){let n=[];for(let r of e){let s=r.start-1,i=r.end===null?t.length:r.end;for(let o=s;o<i&&o<t.length;o++)o>=0&&!n.includes(t[o])&&n.push(t[o])}return n}var Km,Jm,dl=C(()=>{"use strict";It();j();Km={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"]};Jm={name:"cut",async execute(t,e){if(I(t))return N(Km);let n=" ",r=null,s=null,i=!1,o=[];for(let d=0;d<t.length;d++){let p=t[d];if(p==="-d")n=t[++d]||" ";else if(p.startsWith("-d"))n=p.slice(2);else if(p==="-f")r=t[++d];else if(p.startsWith("-f"))r=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 L("cut",p);if(p.startsWith("-")){let h=!1;for(let g of p.slice(1))if(g==="s")i=!0;else if(!"dfc".includes(g)){h=!0;break}if(h)return L("cut",p)}else o.push(p)}}if(!r&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
|
|
318
318
|
`,exitCode:1};let a=await qt(e,o,{cmdName:"cut"});if(!a.ok)return a.error;let c=a.content.split(`
|
|
319
|
-
`);c.length>0&&c[c.length-1]===""&&c.pop();let u=
|
|
320
|
-
`}else{if(i&&!d.includes(n))continue;let p=d.split(n),h=
|
|
321
|
-
`}return{stdout:f,stderr:"",exitCode:0}}}});var hl={};M(hl,{pasteCommand:()=>
|
|
319
|
+
`);c.length>0&&c[c.length-1]===""&&c.pop();let u=Qm(r||s||"1"),f="";for(let d of c)if(s){let p=d.split(""),h=[];for(let g of u){let m=g.start-1,w=g.end===null?p.length:g.end;for(let b=m;b<w&&b<p.length;b++)b>=0&&h.push(p[b])}f+=`${h.join("")}
|
|
320
|
+
`}else{if(i&&!d.includes(n))continue;let p=d.split(n),h=Xm(p,u);f+=`${h.join(n)}
|
|
321
|
+
`}return{stdout:f,stderr:"",exitCode:0}}}});var hl={};M(hl,{pasteCommand:()=>t0});function pl(t,e){if(t.length===0)return"";if(t.length===1)return t[0];let n=t[0];for(let r=1;r<t.length;r++){let s=(r-1)%e.length;n+=e[s]+t[r]}return n}var Ym,e0,t0,ml=C(()=>{"use strict";Ae();j();Ym={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"]},e0={delimiter:{short:"d",long:"delimiters",type:"string",default:" "},serial:{short:"s",long:"serial",type:"boolean"}},t0={name:"paste",async execute(t,e){if(I(t))return N(Ym);let n=J("paste",t,e0);if(!n.ok)return n.error;let r=n.result.flags.delimiter,s=n.result.flags.serial,i=n.result.positional;if(i.length===0)return{stdout:"",stderr:`usage: paste [-s] [-d delimiters] file ...
|
|
322
322
|
`,exitCode:1};let o=e.stdin?e.stdin.split(`
|
|
323
323
|
`):[""];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(`
|
|
324
324
|
`);h.length>0&&h[h.length-1]===""&&h.pop(),l.push(h)}catch{return{stdout:"",stderr:`paste: ${f}: No such file or directory
|
|
325
325
|
`,exitCode:1}}}let u="";if(s)for(let f of l)f&&(u+=`${pl(f,r)}
|
|
326
326
|
`);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+=`${pl(p,r)}
|
|
327
|
-
`}}return{stdout:u,stderr:"",exitCode:0}}}});var yl={};M(yl,{trCommand:()=>
|
|
328
|
-
`:r==="t"?e+=" ":r==="r"?e+="\r":e+=r,n+=2;continue}if(n+2<t.length&&t[n+1]==="-"){let r=t.charCodeAt(n),s=t.charCodeAt(n+2);for(let i=r;i<=s;i++)e+=String.fromCharCode(i);n+=3;continue}e+=t[n],n++}return e}var
|
|
327
|
+
`}}return{stdout:u,stderr:"",exitCode:0}}}});var yl={};M(yl,{trCommand:()=>i0});function gl(t){let e="",n=0;for(;n<t.length;){if(t[n]==="["&&t[n+1]===":"){let r=!1;for(let[s,i]of Object.entries(r0))if(t.slice(n).startsWith(s)){e+=i,n+=s.length,r=!0;break}if(r)continue}if(t[n]==="\\"&&n+1<t.length){let r=t[n+1];r==="n"?e+=`
|
|
328
|
+
`:r==="t"?e+=" ":r==="r"?e+="\r":e+=r,n+=2;continue}if(n+2<t.length&&t[n+1]==="-"){let r=t.charCodeAt(n),s=t.charCodeAt(n+2);for(let i=r;i<=s;i++)e+=String.fromCharCode(i);n+=3;continue}e+=t[n],n++}return e}var n0,r0,s0,i0,xl=C(()=>{"use strict";Ae();j();n0={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:
|
|
329
329
|
a-z character range
|
|
330
330
|
[:alnum:] all letters and digits
|
|
331
331
|
[:alpha:] all letters
|
|
@@ -339,19 +339,19 @@ Try 'comm --help' for more information.
|
|
|
339
339
|
[:graph:] all printable characters except space
|
|
340
340
|
[:cntrl:] all control characters
|
|
341
341
|
[:xdigit:] all hexadecimal digits
|
|
342
|
-
\\n, \\t, \\r escape sequences`},
|
|
343
|
-
\r\f\v`,"[:upper:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","[:xdigit:]":"0123456789ABCDEFabcdef"};
|
|
342
|
+
\\n, \\t, \\r escape sequences`},r0={"[: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:]":`
|
|
343
|
+
\r\f\v`,"[:upper:]":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","[:xdigit:]":"0123456789ABCDEFabcdef"};s0={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"}},i0={name:"tr",async execute(t,e){if(I(t))return N(n0);let n=J("tr",t,s0);if(!n.ok)return n.error;let r=n.result.flags.complement||n.result.flags.complementUpper,s=n.result.flags.delete,i=n.result.flags.squeeze,o=n.result.positional;if(o.length<1)return{stdout:"",stderr:`tr: missing operand
|
|
344
344
|
`,exitCode:1};if(!s&&!i&&o.length<2)return{stdout:"",stderr:`tr: missing operand after SET1
|
|
345
|
-
`,exitCode:1};let a=gl(o[0]),l=o.length>1?gl(o[1]):"",c=e.stdin,u=d=>{let p=a.includes(d);return r?!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(r){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 wl={};M(wl,{rev:()=>
|
|
345
|
+
`,exitCode:1};let a=gl(o[0]),l=o.length>1?gl(o[1]):"",c=e.stdin,u=d=>{let p=a.includes(d);return r?!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(r){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 wl={};M(wl,{rev:()=>l0});function a0(t){return Array.from(t).reverse().join("")}var o0,l0,bl=C(()=>{"use strict";j();o0={name:"rev",summary:"reverse lines characterwise",usage:"rev [file ...]",description:"Copies the specified files to standard output, reversing the order of characters in every line. If no files are specified, standard input is read.",examples:["echo 'hello' | rev # Output: olleh","rev file.txt # Reverse each line in file"]};l0={name:"rev",execute:async(t,e)=>{if(I(t))return N(o0);let n=[];for(let i of t)if(i==="--"){let o=t.indexOf(i);n.push(...t.slice(o+1));break}else{if(i.startsWith("-")&&i!=="-")return L("rev",i);n.push(i)}let r="",s=i=>{let o=i.split(`
|
|
346
346
|
`),a=i.endsWith(`
|
|
347
|
-
`)&&o[o.length-1]==="";return a&&o.pop(),o.map(
|
|
347
|
+
`)&&o[o.length-1]==="";return a&&o.pop(),o.map(a0).join(`
|
|
348
348
|
`)+(a?`
|
|
349
349
|
`:"")};if(n.length===0){let i=e.stdin??"";r=s(i)}else for(let i of n)if(i==="-"){let o=e.stdin??"";r+=s(o)}else{let o=e.fs.resolvePath(e.cwd,i),a=await e.fs.readFile(o);if(a===null)return{exitCode:1,stdout:r,stderr:`rev: ${i}: No such file or directory
|
|
350
|
-
`};r+=s(a)}return{exitCode:0,stdout:r,stderr:""}}}});var Sl={};M(Sl,{nl:()=>
|
|
350
|
+
`};r+=s(a)}return{exitCode:0,stdout:r,stderr:""}}}});var Sl={};M(Sl,{nl:()=>d0});function u0(t,e,n){let r=String(t);switch(e){case"ln":return r.padEnd(n);case"rn":return r.padStart(n);case"rz":return r.padStart(n,"0");default:return e}}function f0(t,e){switch(e){case"a":return!0;case"t":return t.trim().length>0;case"n":return!1;default:return e}}function El(t,e,n){if(t==="")return{output:"",nextNumber:n};let r=t.split(`
|
|
351
351
|
`),s=[],i=n,o=t.endsWith(`
|
|
352
|
-
`)&&r[r.length-1]==="";o&&r.pop();for(let a of r)if(
|
|
352
|
+
`)&&r[r.length-1]==="";o&&r.pop();for(let a of r)if(f0(a,e.bodyStyle)){let l=u0(i,e.numberFormat,e.width);s.push(`${l}${e.separator}${a}`),i+=e.increment}else{let l=" ".repeat(e.width);s.push(`${l}${e.separator}${a}`)}return{output:s.join(`
|
|
353
353
|
`)+(o?`
|
|
354
|
-
`:""),nextNumber:i}}var
|
|
354
|
+
`:""),nextNumber:i}}var c0,d0,Cl=C(()=>{"use strict";j();c0={name:"nl",summary:"number lines of files",usage:"nl [OPTION]... [FILE]...",description:"Write each FILE to standard output, with line numbers added. If no FILE is specified, standard input is read.",options:["-b STYLE Body numbering style: a (all), t (non-empty), n (none)","-n FORMAT Number format: ln (left), rn (right), rz (right zeros)","-w WIDTH Number width (default: 6)","-s SEP Separator after number (default: TAB)","-v START Starting line number (default: 1)","-i INCR Line number increment (default: 1)"],examples:["nl file.txt # Number non-empty lines","nl -ba file.txt # Number all lines","nl -n rz -w 3 file.txt # Right-justified with zeros","nl -s ': ' file.txt # Use ': ' as separator"]};d0={name:"nl",execute:async(t,e)=>{if(I(t))return N(c0);let n={bodyStyle:"t",numberFormat:"rn",width:6,separator:" ",startNumber:1,increment:1},r=[],s=0;for(;s<t.length;){let a=t[s];if(a==="-b"&&s+1<t.length){let l=t[s+1];if(l!=="a"&&l!=="t"&&l!=="n")return{exitCode:1,stdout:"",stderr:`nl: invalid body numbering style: '${l}'
|
|
355
355
|
`};n.bodyStyle=l,s+=2}else if(a.startsWith("-b")){let l=a.slice(2);if(l!=="a"&&l!=="t"&&l!=="n")return{exitCode:1,stdout:"",stderr:`nl: invalid body numbering style: '${l}'
|
|
356
356
|
`};n.bodyStyle=l,s++}else if(a==="-n"&&s+1<t.length){let l=t[s+1];if(l!=="ln"&&l!=="rn"&&l!=="rz")return{exitCode:1,stdout:"",stderr:`nl: invalid line numbering format: '${l}'
|
|
357
357
|
`};n.numberFormat=l,s+=2}else if(a.startsWith("-n")){let l=a.slice(2);if(l!=="ln"&&l!=="rn"&&l!=="rz")return{exitCode:1,stdout:"",stderr:`nl: invalid line numbering format: '${l}'
|
|
@@ -362,35 +362,35 @@ Try 'comm --help' for more information.
|
|
|
362
362
|
`};n.startNumber=l,s++}else if(a==="-i"&&s+1<t.length){let l=parseInt(t[s+1],10);if(Number.isNaN(l))return{exitCode:1,stdout:"",stderr:`nl: invalid line number increment: '${t[s+1]}'
|
|
363
363
|
`};n.increment=l,s+=2}else if(a.startsWith("-i")){let l=parseInt(a.slice(2),10);if(Number.isNaN(l))return{exitCode:1,stdout:"",stderr:`nl: invalid line number increment: '${a.slice(2)}'
|
|
364
364
|
`};n.increment=l,s++}else if(a==="--"){r.push(...t.slice(s+1));break}else{if(a.startsWith("-")&&a!=="-")return L("nl",a);r.push(a),s++}}let i="",o=n.startNumber;if(r.length===0){let a=e.stdin??"";i=El(a,n,o).output}else for(let a of r){let l=e.fs.resolvePath(e.cwd,a),c=await e.fs.readFile(l);if(c===null)return{exitCode:1,stdout:i,stderr:`nl: ${a}: No such file or directory
|
|
365
|
-
`};let u=El(c,n,o);i+=u.output,o=u.nextNumber}return{exitCode:0,stdout:i,stderr:""}}}});var kl={};M(kl,{fold:()=>
|
|
365
|
+
`};let u=El(c,n,o);i+=u.output,o=u.nextNumber}return{exitCode:0,stdout:i,stderr:""}}}});var kl={};M(kl,{fold:()=>g0});function h0(t,e,n){return n?new TextEncoder().encode(t).length:t===" "?8-e%8:t==="\b"?-1:1}function m0(t,e){if(t.length===0)return t;let{width:n,breakAtSpaces:r,countBytes:s}=e,i=[],o="",a=0,l=-1,c=0;for(let u=0;u<t.length;u++){let f=t[u],d=h0(f,a,s);a+d>n&&o.length>0?r&&l>=0?(i.push(o.slice(0,l+1)),o=o.slice(l+1)+f,a=a-c-1+d,l=-1,c=0):(i.push(o),o=f,a=d,l=-1,c=0):(o+=f,a+=d,(f===" "||f===" ")&&(l=o.length-1,c=a-d))}return o.length>0&&i.push(o),i.join(`
|
|
366
366
|
`)}function Al(t,e){if(t==="")return"";let n=t.split(`
|
|
367
367
|
`),r=t.endsWith(`
|
|
368
|
-
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>
|
|
368
|
+
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>m0(i,e)).join(`
|
|
369
369
|
`)+(r?`
|
|
370
|
-
`:"")}var
|
|
370
|
+
`:"")}var p0,g0,Nl=C(()=>{"use strict";j();p0={name:"fold",summary:"wrap each input line to fit in specified width",usage:"fold [OPTION]... [FILE]...",description:"Wrap input lines in each FILE, writing to standard output. If no FILE is specified, standard input is read.",options:["-w WIDTH Use WIDTH columns instead of 80","-s Break at spaces","-b Count bytes rather than columns"],examples:["fold -w 40 file.txt # Wrap at 40 columns","fold -sw 40 file.txt # Word wrap at 40 columns","echo 'long line' | fold -w 5 # Force wrap at 5"]};g0={name:"fold",execute:async(t,e)=>{if(I(t))return N(p0);let n={width:80,breakAtSpaces:!1,countBytes:!1},r=[],s=0;for(;s<t.length;){let o=t[s];if(o==="-w"&&s+1<t.length){let a=parseInt(t[s+1],10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`fold: invalid number of columns: '${t[s+1]}'
|
|
371
371
|
`};n.width=a,s+=2}else if(o.startsWith("-w")&&o.length>2){let a=parseInt(o.slice(2),10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`fold: invalid number of columns: '${o.slice(2)}'
|
|
372
372
|
`};n.width=a,s++}else if(o==="-s")n.breakAtSpaces=!0,s++;else if(o==="-b")n.countBytes=!0,s++;else if(o==="-bs"||o==="-sb")n.breakAtSpaces=!0,n.countBytes=!0,s++;else if(o.match(/^-[sb]+w\d+$/)){o.includes("s")&&(n.breakAtSpaces=!0),o.includes("b")&&(n.countBytes=!0);let a=o.replace(/^-[sb]+w/,""),l=parseInt(a,10);if(Number.isNaN(l)||l<1)return{exitCode:1,stdout:"",stderr:`fold: invalid number of columns: '${a}'
|
|
373
373
|
`};n.width=l,s++}else if(o.match(/^-[sb]+w$/)&&s+1<t.length){o.includes("s")&&(n.breakAtSpaces=!0),o.includes("b")&&(n.countBytes=!0);let a=parseInt(t[s+1],10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`fold: invalid number of columns: '${t[s+1]}'
|
|
374
374
|
`};n.width=a,s+=2}else if(o==="--"){r.push(...t.slice(s+1));break}else if(o.startsWith("-")&&o!=="-"){let a=o.slice(1),l=!1;for(let c of a)if(c==="s")n.breakAtSpaces=!0;else if(c==="b")n.countBytes=!0;else{l=!0;break}if(l)return L("fold",o);s++}else r.push(o),s++}let i="";if(r.length===0){let o=e.stdin??"";i=Al(o,n)}else for(let o of r){let a=e.fs.resolvePath(e.cwd,o),l=await e.fs.readFile(a);if(l===null)return{exitCode:1,stdout:i,stderr:`fold: ${o}: No such file or directory
|
|
375
|
-
`};i+=Al(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var vl={};M(vl,{expand:()=>
|
|
375
|
+
`};i+=Al(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var vl={};M(vl,{expand:()=>b0});function dr(t){let e=t.split(",").map(r=>r.trim()),n=[];for(let r of e){let s=parseInt(r,10);if(Number.isNaN(s)||s<1)return null;n.push(s)}for(let r=1;r<n.length;r++)if(n[r]<=n[r-1])return null;return n}function x0(t,e){if(e.length===1){let n=e[0];return n-t%n}for(let n of e)if(n>t)return n-t;if(e.length>=2){let n=e[e.length-1]-e[e.length-2],r=e[e.length-1],s=Math.floor((t-r)/n)+1;return r+s*n-t}return 1}function w0(t,e){let{tabStops:n,leadingOnly:r}=e,s="",i=0,o=!0;for(let a of t)if(a===" ")if(r&&!o)s+=a,i++;else{let l=x0(i,n);s+=" ".repeat(l),i+=l}else a!==" "&&a!==" "&&(o=!1),s+=a,i++;return s}function Il(t,e){if(t==="")return"";let n=t.split(`
|
|
376
376
|
`),r=t.endsWith(`
|
|
377
|
-
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>
|
|
377
|
+
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>w0(i,e)).join(`
|
|
378
378
|
`)+(r?`
|
|
379
|
-
`:"")}var
|
|
379
|
+
`:"")}var y0,b0,$l=C(()=>{"use strict";j();y0={name:"expand",summary:"convert tabs to spaces",usage:"expand [OPTION]... [FILE]...",description:"Convert TABs in each FILE to spaces, writing to standard output. If no FILE is specified, standard input is read.",options:["-t N Use N spaces per tab (default: 8)","-t LIST Use comma-separated list of tab stops","-i Only convert leading tabs on each line"],examples:["expand file.txt # Convert all tabs to 8 spaces","expand -t 4 file.txt # Use 4-space tabs","expand -t 4,8,12 file.txt # Custom tab stops"]};b0={name:"expand",execute:async(t,e)=>{if(I(t))return N(y0);let n={tabStops:[8],leadingOnly:!1},r=[],s=0;for(;s<t.length;){let o=t[s];if(o==="-t"&&s+1<t.length){let a=dr(t[s+1]);if(!a)return{exitCode:1,stdout:"",stderr:`expand: invalid tab size: '${t[s+1]}'
|
|
380
380
|
`};n.tabStops=a,s+=2}else if(o.startsWith("-t")&&o.length>2){let a=dr(o.slice(2));if(!a)return{exitCode:1,stdout:"",stderr:`expand: invalid tab size: '${o.slice(2)}'
|
|
381
381
|
`};n.tabStops=a,s++}else if(o==="--tabs"&&s+1<t.length){let a=dr(t[s+1]);if(!a)return{exitCode:1,stdout:"",stderr:`expand: invalid tab size: '${t[s+1]}'
|
|
382
382
|
`};n.tabStops=a,s+=2}else if(o.startsWith("--tabs=")){let a=dr(o.slice(7));if(!a)return{exitCode:1,stdout:"",stderr:`expand: invalid tab size: '${o.slice(7)}'
|
|
383
383
|
`};n.tabStops=a,s++}else if(o==="-i"||o==="--initial")n.leadingOnly=!0,s++;else if(o==="--"){r.push(...t.slice(s+1));break}else{if(o.startsWith("-")&&o!=="-")return L("expand",o);r.push(o),s++}}let i="";if(r.length===0){let o=e.stdin??"";i=Il(o,n)}else for(let o of r){let a=e.fs.resolvePath(e.cwd,o),l=await e.fs.readFile(a);if(l===null)return{exitCode:1,stdout:i,stderr:`expand: ${o}: No such file or directory
|
|
384
|
-
`};i+=Il(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var Pl={};M(Pl,{unexpand:()=>
|
|
384
|
+
`};i+=Il(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var Pl={};M(Pl,{unexpand:()=>C0});function pr(t){let e=t.split(",").map(r=>r.trim()),n=[];for(let r of e){let s=parseInt(r,10);if(Number.isNaN(s)||s<1)return null;n.push(s)}for(let r=1;r<n.length;r++)if(n[r]<=n[r-1])return null;return n}function Rl(t,e){if(e.length===1){let n=e[0];return t+(n-t%n)}for(let n of e)if(n>t)return n;if(e.length>=2){let n=e[e.length-1]-e[e.length-2],r=e[e.length-1],s=Math.floor((t-r)/n)+1;return r+s*n}return-1}function S0(t,e){let{tabStops:n,allBlanks:r}=e,s="",i=0,o="",a=0,l=!0,c=()=>{if(o.length===0)return;let u=a+o.length;if(!r&&!l){s+=o,o="";return}let f=a,d="";for(;f<u;){let h=Rl(f,n);if(h<=u&&h>f)d+=" ",f=h;else break}let p=u-f;p>0&&(d+=" ".repeat(p)),s+=d,o=""};for(let u of t)u===" "?(o.length===0&&(a=i),o+=u,i++):u===" "?(c(),s+=u,i=Rl(i,n)):(c(),s+=u,i++,l=!1);return c(),s}function Fl(t,e){if(t==="")return"";let n=t.split(`
|
|
385
385
|
`),r=t.endsWith(`
|
|
386
|
-
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>
|
|
386
|
+
`)&&n[n.length-1]==="";return r&&n.pop(),n.map(i=>S0(i,e)).join(`
|
|
387
387
|
`)+(r?`
|
|
388
|
-
`:"")}var
|
|
388
|
+
`:"")}var E0,C0,Tl=C(()=>{"use strict";j();E0={name:"unexpand",summary:"convert spaces to tabs",usage:"unexpand [OPTION]... [FILE]...",description:"Convert blanks in each FILE to TABs, writing to standard output. If no FILE is specified, standard input is read.",options:["-t N Use N spaces per tab (default: 8)","-t LIST Use comma-separated list of tab stops","-a Convert all sequences of blanks (not just leading)"],examples:["unexpand file.txt # Convert leading spaces to tabs","unexpand -a file.txt # Convert all space sequences","unexpand -t 4 file.txt # Use 4-space tabs"]};C0={name:"unexpand",execute:async(t,e)=>{if(I(t))return N(E0);let n={tabStops:[8],allBlanks:!1},r=[],s=0;for(;s<t.length;){let o=t[s];if(o==="-t"&&s+1<t.length){let a=pr(t[s+1]);if(!a)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${t[s+1]}'
|
|
389
389
|
`};n.tabStops=a,s+=2}else if(o.startsWith("-t")&&o.length>2){let a=pr(o.slice(2));if(!a)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${o.slice(2)}'
|
|
390
390
|
`};n.tabStops=a,s++}else if(o==="--tabs"&&s+1<t.length){let a=pr(t[s+1]);if(!a)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${t[s+1]}'
|
|
391
391
|
`};n.tabStops=a,s+=2}else if(o.startsWith("--tabs=")){let a=pr(o.slice(7));if(!a)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${o.slice(7)}'
|
|
392
392
|
`};n.tabStops=a,s++}else if(o==="-a"||o==="--all")n.allBlanks=!0,s++;else if(o==="--"){r.push(...t.slice(s+1));break}else{if(o.startsWith("-")&&o!=="-")return L("unexpand",o);r.push(o),s++}}let i="";if(r.length===0){let o=e.stdin??"";i=Fl(o,n)}else for(let o of r){let a=e.fs.resolvePath(e.cwd,o),l=await e.fs.readFile(a);if(l===null)return{exitCode:1,stdout:i,stderr:`unexpand: ${o}: No such file or directory
|
|
393
|
-
`};i+=Fl(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var Ll={};M(Ll,{strings:()=>
|
|
393
|
+
`};i+=Fl(l,n)}return{exitCode:0,stdout:i,stderr:""}}}});var Ll={};M(Ll,{strings:()=>N0});function k0(t){return t>=32&&t<=126||t===9}function Ol(t,e){if(e===null)return"";switch(e){case"o":return`${t.toString(8).padStart(7," ")} `;case"x":return`${t.toString(16).padStart(7," ")} `;case"d":return`${t.toString(10).padStart(7," ")} `;default:return e}}function Dl(t,e){let n=[],r="",s=0,i=typeof t=="string"?new TextEncoder().encode(t):t;for(let o=0;o<i.length;o++){let a=i[o];if(k0(a))r.length===0&&(s=o),r+=String.fromCharCode(a);else{if(r.length>=e.minLength){let l=Ol(s,e.offsetFormat);n.push(`${l}${r}`)}r=""}}if(r.length>=e.minLength){let o=Ol(s,e.offsetFormat);n.push(`${o}${r}`)}return n}var A0,N0,Ml=C(()=>{"use strict";j();A0={name:"strings",summary:"print the sequences of printable characters in files",usage:"strings [OPTION]... [FILE]...",description:"For each FILE, print the printable character sequences that are at least MIN characters long. If no FILE is specified, standard input is read.",options:["-n MIN Print sequences of at least MIN characters (default: 4)","-t FORMAT Print offset before each string (o=octal, x=hex, d=decimal)","-a Scan the entire file (default behavior)","-e ENCODING Select character encoding (s=7-bit, S=8-bit)"],examples:["strings file.bin # Extract strings (min 4 chars)","strings -n 8 file.bin # Extract strings (min 8 chars)","strings -t x file.bin # Show hex offset","echo 'hello' | strings # Read from stdin"]};N0={name:"strings",execute:async(t,e)=>{if(I(t))return N(A0);let n={minLength:4,offsetFormat:null},r=[],s=0;for(;s<t.length;){let o=t[s];if(o==="-n"&&s+1<t.length){let a=Number.parseInt(t[s+1],10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${t[s+1]}'
|
|
394
394
|
`};n.minLength=a,s+=2}else if(o.match(/^-n\d+$/)){let a=Number.parseInt(o.slice(2),10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${o.slice(2)}'
|
|
395
395
|
`};n.minLength=a,s++}else if(o.match(/^-\d+$/)){let a=Number.parseInt(o.slice(1),10);if(Number.isNaN(a)||a<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${o.slice(1)}'
|
|
396
396
|
`};n.minLength=a,s++}else if(o==="-t"&&s+1<t.length){let a=t[s+1];if(a!=="o"&&a!=="x"&&a!=="d")return{exitCode:1,stdout:"",stderr:`strings: invalid radix: '${a}'
|
|
@@ -402,12 +402,12 @@ Try 'comm --help' for more information.
|
|
|
402
402
|
`:""}else for(let o of r){let a;if(o==="-")a=e.stdin??"";else{let c=e.fs.resolvePath(e.cwd,o);if(a=await e.fs.readFile(c),a===null)return{exitCode:1,stdout:i,stderr:`strings: ${o}: No such file or directory
|
|
403
403
|
`}}let l=Dl(a,n);l.length>0&&(i+=`${l.join(`
|
|
404
404
|
`)}
|
|
405
|
-
`)}return{exitCode:0,stdout:i,stderr:""}}}});var Bl={};M(Bl,{split:()=>
|
|
405
|
+
`)}return{exitCode:0,stdout:i,stderr:""}}}});var Bl={};M(Bl,{split:()=>P0});function _l(t){let e=t.match(/^(\d+)([KMGTPEZY]?)([B]?)$/i);if(!e)return null;let n=Number.parseInt(e[1],10);if(Number.isNaN(n)||n<1)return null;let r=(e[2]||"").toUpperCase(),i={"":1,K:1024,M:1024*1024,G:1024*1024*1024,T:1024*1024*1024*1024,P:1024*1024*1024*1024*1024}[r];return i===void 0?null:n*i}function v0(t,e,n){if(e)return t.toString().padStart(n,"0");let r="abcdefghijklmnopqrstuvwxyz",s="",i=t;for(let o=0;o<n;o++)s=r[i%26]+s,i=Math.floor(i/26);return s}function $0(t,e){let n=t.split(`
|
|
406
406
|
`),r=t.endsWith(`
|
|
407
407
|
`)&&n[n.length-1]==="";r&&n.pop();let s=[];for(let i=0;i<n.length;i+=e){let o=n.slice(i,i+e),l=i+e>=n.length&&!r?o.join(`
|
|
408
408
|
`):`${o.join(`
|
|
409
409
|
`)}
|
|
410
|
-
`;s.push({content:l,hasContent:!0})}return s}function
|
|
410
|
+
`;s.push({content:l,hasContent:!0})}return s}function R0(t,e){let r=new TextEncoder().encode(t),s=new TextDecoder,i=[];for(let o=0;o<r.length;o+=e){let a=r.slice(o,o+e);i.push({content:s.decode(a),hasContent:a.length>0})}return i}function F0(t,e){let r=new TextEncoder().encode(t),s=new TextDecoder,i=[],o=Math.ceil(r.length/e);for(let a=0;a<e;a++){let l=a*o,c=Math.min(l+o,r.length),u=r.slice(l,c);i.push({content:s.decode(u),hasContent:u.length>0})}return i}var I0,P0,Wl=C(()=>{"use strict";j();I0={name:"split",summary:"split a file into pieces",usage:"split [OPTION]... [FILE [PREFIX]]",description:"Output pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'.",options:["-l N Put N lines per output file","-b SIZE Put SIZE bytes per output file (K, M, G suffixes)","-n CHUNKS Split into CHUNKS equal-sized files","-d Use numeric suffixes (00, 01, ...) instead of alphabetic","-a LENGTH Use suffixes of length LENGTH (default: 2)","--additional-suffix=SUFFIX Append SUFFIX to file names"],examples:["split -l 100 file.txt # Split into 100-line chunks","split -b 1M file.bin # Split into 1MB chunks","split -n 5 file.txt # Split into 5 equal parts","split -d file.txt part_ # part_00, part_01, ...","split -a 3 -d file.txt x # x000, x001, ..."]};P0={name:"split",execute:async(t,e)=>{if(I(t))return N(I0);let n={mode:"lines",lines:1e3,bytes:0,chunks:0,useNumericSuffix:!1,suffixLength:2,additionalSuffix:""},r=[],s=0;for(;s<t.length;){let c=t[s];if(c==="-l"&&s+1<t.length){let u=Number.parseInt(t[s+1],10);if(Number.isNaN(u)||u<1)return{exitCode:1,stdout:"",stderr:`split: invalid number of lines: '${t[s+1]}'
|
|
411
411
|
`};n.mode="lines",n.lines=u,s+=2}else if(c.match(/^-l\d+$/)){let u=Number.parseInt(c.slice(2),10);if(Number.isNaN(u)||u<1)return{exitCode:1,stdout:"",stderr:`split: invalid number of lines: '${c.slice(2)}'
|
|
412
412
|
`};n.mode="lines",n.lines=u,s++}else if(c==="-b"&&s+1<t.length){let u=_l(t[s+1]);if(u===null)return{exitCode:1,stdout:"",stderr:`split: invalid number of bytes: '${t[s+1]}'
|
|
413
413
|
`};n.mode="bytes",n.bytes=u,s+=2}else if(c.match(/^-b.+$/)){let u=_l(c.slice(2));if(u===null)return{exitCode:1,stdout:"",stderr:`split: invalid number of bytes: '${c.slice(2)}'
|
|
@@ -416,42 +416,42 @@ Try 'comm --help' for more information.
|
|
|
416
416
|
`};n.mode="chunks",n.chunks=u,s++}else if(c==="-a"&&s+1<t.length){let u=Number.parseInt(t[s+1],10);if(Number.isNaN(u)||u<1)return{exitCode:1,stdout:"",stderr:`split: invalid suffix length: '${t[s+1]}'
|
|
417
417
|
`};n.suffixLength=u,s+=2}else if(c.match(/^-a\d+$/)){let u=Number.parseInt(c.slice(2),10);if(Number.isNaN(u)||u<1)return{exitCode:1,stdout:"",stderr:`split: invalid suffix length: '${c.slice(2)}'
|
|
418
418
|
`};n.suffixLength=u,s++}else if(c==="-d"||c==="--numeric-suffixes")n.useNumericSuffix=!0,s++;else if(c.startsWith("--additional-suffix="))n.additionalSuffix=c.slice(20),s++;else if(c==="--additional-suffix"&&s+1<t.length)n.additionalSuffix=t[s+1],s+=2;else if(c==="--"){r.push(...t.slice(s+1));break}else{if(c.startsWith("-")&&c!=="-")return L("split",c);r.push(c),s++}}let i="-",o="x";r.length>=1&&(i=r[0]),r.length>=2&&(o=r[1]);let a;if(i==="-")a=e.stdin??"";else{let c=e.fs.resolvePath(e.cwd,i),u=await e.fs.readFile(c);if(u===null)return{exitCode:1,stdout:"",stderr:`split: ${i}: No such file or directory
|
|
419
|
-
`};a=u}if(a==="")return{exitCode:0,stdout:"",stderr:""};let l;switch(n.mode){case"lines":l
|
|
420
|
-
`)}function
|
|
421
|
-
`)}var
|
|
419
|
+
`};a=u}if(a==="")return{exitCode:0,stdout:"",stderr:""};let l;switch(n.mode){case"lines":l=$0(a,n.lines);break;case"bytes":l=R0(a,n.bytes);break;case"chunks":l=F0(a,n.chunks);break;default:return n.mode}for(let c=0;c<l.length;c++){let u=l[c];if(!u.hasContent)continue;let f=v0(c,n.useNumericSuffix,n.suffixLength),d=`${o}${f}${n.additionalSuffix}`,p=e.fs.resolvePath(e.cwd,d);await e.fs.writeFile(p,u.content)}return{exitCode:0,stdout:"",stderr:""}}}});var jl={};M(jl,{column:()=>_0});function Ul(t,e,n){return e?n?t.split(e):t.split(e).filter(r=>r.length>0):n?t.split(/[ \t]/):t.split(/[ \t]+/).filter(r=>r.length>0)}function D0(t){let e=[];for(let n of t)for(let r=0;r<n.length;r++){let s=n[r].length;(e[r]===void 0||s>e[r])&&(e[r]=s)}return e}function L0(t,e){if(t.length===0)return"";let n=D0(t),r=[];for(let s of t){let i=[];for(let o=0;o<s.length;o++)o===s.length-1?i.push(s[o]):i.push(s[o].padEnd(n[o]));r.push(i.join(e))}return r.join(`
|
|
420
|
+
`)}function M0(t,e,n){if(t.length===0)return"";let r=Math.max(...t.map(c=>c.length)),s=n.length,i=r+s,o=Math.max(1,Math.floor((e+s)/i)),a=Math.ceil(t.length/o),l=[];for(let c=0;c<a;c++){let u=[];for(let f=0;f<o;f++){let d=f*a+c;d<t.length&&(f===o-1||(f+1)*a+c>=t.length?u.push(t[d]):u.push(t[d].padEnd(r)))}l.push(u.join(n))}return l.join(`
|
|
421
|
+
`)}var T0,O0,_0,zl=C(()=>{"use strict";Ae();j();T0={name:"column",summary:"columnate lists",usage:"column [OPTION]... [FILE]...",description:"Format input into multiple columns. By default, fills rows first. Use -t to create a table based on whitespace-delimited input.",options:["-t Create a table (determine columns from input)","-s SEP Input field delimiter (default: whitespace)","-o SEP Output field delimiter (default: two spaces)","-c WIDTH Output width for fill mode (default: 80)","-n Don't merge multiple adjacent delimiters"],examples:["ls | column # Fill columns with ls output","cat data | column -t # Format as table","column -t -s ',' file # Format CSV as table","column -c 40 file # Fill 40-char wide columns"]},O0={table:{short:"t",long:"table",type:"boolean"},separator:{short:"s",type:"string"},outputSep:{short:"o",type:"string"},width:{short:"c",type:"number",default:80},noMerge:{short:"n",type:"boolean"}};_0={name:"column",execute:async(t,e)=>{if(I(t))return N(T0);let n=J("column",t,O0);if(!n.ok)return n.error;let{table:r,separator:s,outputSep:i,width:o,noMerge:a}=n.result.flags,l=n.result.positional,c=i??" ",u;if(l.length===0)u=e.stdin??"";else{let g=[];for(let m of l)if(m==="-")g.push(e.stdin??"");else{let w=e.fs.resolvePath(e.cwd,m),b=await e.fs.readFile(w);if(b===null)return{exitCode:1,stdout:"",stderr:`column: ${m}: No such file or directory
|
|
422
422
|
`};g.push(b)}u=g.join("")}if(u===""||u.trim()==="")return{exitCode:0,stdout:"",stderr:""};let f=u.split(`
|
|
423
423
|
`);u.endsWith(`
|
|
424
|
-
`)&&f[f.length-1]===""&&f.pop();let p=f.filter(g=>g.trim().length>0),h;if(r){let g=p.map(m=>Ul(m,s,a));h=
|
|
425
|
-
`),{exitCode:0,stdout:h,stderr:""}}}});var Hl={};M(Hl,{join:()=>
|
|
424
|
+
`)&&f[f.length-1]===""&&f.pop();let p=f.filter(g=>g.trim().length>0),h;if(r){let g=p.map(m=>Ul(m,s,a));h=L0(g,c)}else{let g=[];for(let m of p){let w=Ul(m,s,a);g.push(...w)}h=M0(g,o,c)}return h.length>0&&(h+=`
|
|
425
|
+
`),{exitCode:0,stdout:h,stderr:""}}}});var Hl={};M(Hl,{join:()=>z0});function W0(t,e){return e?t.split(e):t.split(/[ \t]+/).filter(n=>n.length>0)}function U0(t,e,n,r){let s=W0(t,e),i=s[n-1]??"";return r&&(i=i.toLowerCase()),{fields:s,joinKey:i,original:t}}function Rs(t,e,n){let r=n.separator??" ";if(n.outputFormat){let o=[];for(let{file:a,field:l}of n.outputFormat){let c=a===1?t:e;c&&l===0?o.push(c.joinKey):c&&c.fields[l-1]!==void 0?o.push(c.fields[l-1]):o.push(n.emptyString)}return o.join(r)}let s=[],i=t?.joinKey??e?.joinKey??"";if(s.push(i),t)for(let o=0;o<t.fields.length;o++)o!==n.field1-1&&s.push(t.fields[o]);if(e)for(let o=0;o<e.fields.length;o++)o!==n.field2-1&&s.push(e.fields[o]);return s.join(r)}function j0(t){let e=t.split(","),n=[];for(let r of e){let s=r.trim().match(/^(\d+)\.(\d+)$/);if(!s)return null;let i=Number.parseInt(s[1],10),o=Number.parseInt(s[2],10);if(i!==1&&i!==2)return null;n.push({file:i,field:o})}return n}var B0,z0,Gl=C(()=>{"use strict";j();B0={name:"join",summary:"join lines of two files on a common field",usage:"join [OPTION]... FILE1 FILE2",description:"For each pair of input lines with identical join fields, write a line to standard output. The default join field is the first, delimited by blanks.",options:["-1 FIELD Join on this FIELD of file 1 (default: 1)","-2 FIELD Join on this FIELD of file 2 (default: 1)","-t CHAR Use CHAR as input and output field separator","-a FILENUM Also print unpairable lines from file FILENUM (1 or 2)","-v FILENUM Like -a but only output unpairable lines","-e STRING Replace missing fields with STRING","-o FORMAT Output format (comma-separated list of FILENUM.FIELD)","-i Ignore case when comparing fields"],examples:["join file1 file2 # Join on first field","join -1 2 -2 1 file1 file2 # Join file1 col 2 with file2 col 1","join -t ',' file1.csv file2.csv # Join CSV files","join -a 1 file1 file2 # Left outer join"]};z0={name:"join",execute:async(t,e)=>{if(I(t))return N(B0);let n={field1:1,field2:1,separator:null,printUnpairable:new Set,onlyUnpairable:new Set,emptyString:"",outputFormat:null,ignoreCase:!1},r=[],s=0;for(;s<t.length;){let d=t[s];if(d==="-1"&&s+1<t.length){let p=Number.parseInt(t[s+1],10);if(Number.isNaN(p)||p<1)return{exitCode:1,stdout:"",stderr:`join: invalid field number: '${t[s+1]}'
|
|
426
426
|
`};n.field1=p,s+=2}else if(d==="-2"&&s+1<t.length){let p=Number.parseInt(t[s+1],10);if(Number.isNaN(p)||p<1)return{exitCode:1,stdout:"",stderr:`join: invalid field number: '${t[s+1]}'
|
|
427
427
|
`};n.field2=p,s+=2}else if((d==="-t"||d==="--field-separator")&&s+1<t.length)n.separator=t[s+1],s+=2;else if(d.startsWith("-t")&&d.length>2)n.separator=d.slice(2),s++;else if(d==="-a"&&s+1<t.length){let p=Number.parseInt(t[s+1],10);if(p!==1&&p!==2)return{exitCode:1,stdout:"",stderr:`join: invalid file number: '${t[s+1]}'
|
|
428
428
|
`};n.printUnpairable.add(p),s+=2}else if(d.match(/^-a[12]$/))n.printUnpairable.add(Number.parseInt(d[2],10)),s++;else if(d==="-v"&&s+1<t.length){let p=Number.parseInt(t[s+1],10);if(p!==1&&p!==2)return{exitCode:1,stdout:"",stderr:`join: invalid file number: '${t[s+1]}'
|
|
429
|
-
`};n.onlyUnpairable.add(p),s+=2}else if(d.match(/^-v[12]$/))n.onlyUnpairable.add(Number.parseInt(d[2],10)),s++;else if(d==="-e"&&s+1<t.length)n.emptyString=t[s+1],s+=2;else if(d==="-o"&&s+1<t.length){let p=
|
|
429
|
+
`};n.onlyUnpairable.add(p),s+=2}else if(d.match(/^-v[12]$/))n.onlyUnpairable.add(Number.parseInt(d[2],10)),s++;else if(d==="-e"&&s+1<t.length)n.emptyString=t[s+1],s+=2;else if(d==="-o"&&s+1<t.length){let p=j0(t[s+1]);if(!p)return{exitCode:1,stdout:"",stderr:`join: invalid field spec: '${t[s+1]}'
|
|
430
430
|
`};n.outputFormat=p,s+=2}else if(d==="-i"||d==="--ignore-case")n.ignoreCase=!0,s++;else if(d==="--"){r.push(...t.slice(s+1));break}else{if(d.startsWith("-")&&d!=="-")return L("join",d);r.push(d),s++}}if(r.length!==2)return{exitCode:1,stdout:"",stderr:r.length<2?`join: missing file operand
|
|
431
431
|
`:`join: extra operand
|
|
432
432
|
`};let i=[];for(let d of r)if(d==="-")i.push(e.stdin??"");else{let p=e.fs.resolvePath(e.cwd,d),h=await e.fs.readFile(p);if(h===null)return{exitCode:1,stdout:"",stderr:`join: ${d}: No such file or directory
|
|
433
433
|
`};i.push(h)}let o=(d,p)=>{let h=d.split(`
|
|
434
434
|
`);return d.endsWith(`
|
|
435
|
-
`)&&h[h.length-1]===""&&h.pop(),h.filter(g=>g.length>0).map(g=>
|
|
435
|
+
`)&&h[h.length-1]===""&&h.pop(),h.filter(g=>g.length>0).map(g=>U0(g,n.separator,p,n.ignoreCase))},a=o(i[0],n.field1),l=o(i[1],n.field2),c=new Map;for(let d of l){let p=c.get(d.joinKey);p?p.push(d):c.set(d.joinKey,[d])}let u=[],f=new Set;for(let d of a){let p=c.get(d.joinKey);if(p&&p.length>0){if(f.add(d.joinKey),n.onlyUnpairable.size===0)for(let h of p)u.push(Rs(d,h,n))}else(n.printUnpairable.has(1)||n.onlyUnpairable.has(1))&&u.push(Rs(d,null,n))}if(n.printUnpairable.has(2)||n.onlyUnpairable.has(2))for(let d of l)f.has(d.joinKey)||u.push(Rs(null,d,n));return{exitCode:0,stdout:u.length>0?`${u.join(`
|
|
436
436
|
`)}
|
|
437
|
-
`:"",stderr:""}}}});var ql={};M(ql,{teeCommand:()=>
|
|
438
|
-
`,a=1}return{stdout:i,stderr:o,exitCode:a}}}});function Xe(t,e){switch(t.type){case"name":{let n=t.pattern,r=n.match(/^\*(\.[a-zA-Z0-9]+)$/);if(r){let s=r[1],i=e.name;if(t.ignoreCase){if(!i.toLowerCase().endsWith(s.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!i.endsWith(s))return{matches:!1,pruned:!1,printed:!1};return{matches:!0,pruned:!1,printed:!1}}return{matches:De(e.name,n,t.ignoreCase),pruned:!1,printed:!1}}case"path":{let n=t.pattern,r=e.relativePath,s=n.split("/");for(let o=0;o<s.length-1;o++){let a=s[o];if(a&&a!=="."&&a!==".."&&!a.includes("*")&&!a.includes("?")&&!a.includes("[")){let l=`/${a}/`;if(t.ignoreCase){if(!r.toLowerCase().includes(l.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!r.includes(l))return{matches:!1,pruned:!1,printed:!1}}}let i=n.match(/\*(\.[a-zA-Z0-9]+)$/);if(i){let o=i[1];if(t.ignoreCase){if(!r.toLowerCase().endsWith(o.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!r.endsWith(o))return{matches:!1,pruned:!1,printed:!1}}return{matches:De(r,n,t.ignoreCase),pruned:!1,printed:!1}}case"regex":try{let n=t.ignoreCase?"i":"";return{matches:new RegExp(t.pattern,n).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 r=(Date.now()-e.mtime)/(1e3*60*60*24),s;return t.comparison==="more"?s=r>t.days:t.comparison==="less"?s=r<t.days:s=Math.floor(r)===t.days,{matches:s,pruned:!1,printed:!1}}case"newer":{let n=e.newerRefTimes.get(t.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:e.mtime>n,pruned:!1,printed:!1}}case"size":{let n=t.value;switch(t.unit){case"c":n=t.value;break;case"k":n=t.value*1024;break;case"M":n=t.value*1024*1024;break;case"G":n=t.value*1024*1024*1024;break;case"b":n=t.value*512;break}let r;return t.comparison==="more"?r=e.size>n:t.comparison==="less"?r=e.size<n:t.unit==="b"?r=Math.ceil(e.size/512)===t.value:r=e.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=e.mode&511,r=t.mode&511,s;return t.matchType==="exact"?s=n===r:t.matchType==="all"?s=(n&r)===r:s=(n&r)!==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 n=Xe(t.expr,e);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=Xe(t.left,e);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=Xe(t.right,e);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=Xe(t.left,e);if(n.matches)return n;let r=Xe(t.right,e);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function vn(t){if(!t)return!1;switch(t.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!1;case"empty":case"mtime":case"newer":case"size":case"perm":return!0;case"not":return vn(t.expr);case"and":case"or":return vn(t.left)||vn(t.right)}}function $n(t){if(!t)return!1;switch(t.type){case"empty":return!0;case"not":return $n(t.expr);case"and":case"or":return $n(t.left)||$n(t.right);default:return!1}}function Zl(t){let e={terminalDirName:null,requiredExtension:null};if(!t)return e;let n=
|
|
437
|
+
`:"",stderr:""}}}});var ql={};M(ql,{teeCommand:()=>q0});var H0,G0,q0,Vl=C(()=>{"use strict";Ae();j();H0={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"]},G0={append:{short:"a",long:"append",type:"boolean"}},q0={name:"tee",async execute(t,e){if(I(t))return N(H0);let n=J("tee",t,G0);if(!n.ok)return n.error;let{append:r}=n.result.flags,s=n.result.positional,i=e.stdin,o="",a=0;for(let l of s)try{let c=e.fs.resolvePath(e.cwd,l);r?await e.fs.appendFile(c,i):await e.fs.writeFile(c,i)}catch{o+=`tee: ${l}: No such file or directory
|
|
438
|
+
`,a=1}return{stdout:i,stderr:o,exitCode:a}}}});function Xe(t,e){switch(t.type){case"name":{let n=t.pattern,r=n.match(/^\*(\.[a-zA-Z0-9]+)$/);if(r){let s=r[1],i=e.name;if(t.ignoreCase){if(!i.toLowerCase().endsWith(s.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!i.endsWith(s))return{matches:!1,pruned:!1,printed:!1};return{matches:!0,pruned:!1,printed:!1}}return{matches:De(e.name,n,t.ignoreCase),pruned:!1,printed:!1}}case"path":{let n=t.pattern,r=e.relativePath,s=n.split("/");for(let o=0;o<s.length-1;o++){let a=s[o];if(a&&a!=="."&&a!==".."&&!a.includes("*")&&!a.includes("?")&&!a.includes("[")){let l=`/${a}/`;if(t.ignoreCase){if(!r.toLowerCase().includes(l.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!r.includes(l))return{matches:!1,pruned:!1,printed:!1}}}let i=n.match(/\*(\.[a-zA-Z0-9]+)$/);if(i){let o=i[1];if(t.ignoreCase){if(!r.toLowerCase().endsWith(o.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!r.endsWith(o))return{matches:!1,pruned:!1,printed:!1}}return{matches:De(r,n,t.ignoreCase),pruned:!1,printed:!1}}case"regex":try{let n=t.ignoreCase?"i":"";return{matches:new RegExp(t.pattern,n).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 r=(Date.now()-e.mtime)/(1e3*60*60*24),s;return t.comparison==="more"?s=r>t.days:t.comparison==="less"?s=r<t.days:s=Math.floor(r)===t.days,{matches:s,pruned:!1,printed:!1}}case"newer":{let n=e.newerRefTimes.get(t.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:e.mtime>n,pruned:!1,printed:!1}}case"size":{let n=t.value;switch(t.unit){case"c":n=t.value;break;case"k":n=t.value*1024;break;case"M":n=t.value*1024*1024;break;case"G":n=t.value*1024*1024*1024;break;case"b":n=t.value*512;break}let r;return t.comparison==="more"?r=e.size>n:t.comparison==="less"?r=e.size<n:t.unit==="b"?r=Math.ceil(e.size/512)===t.value:r=e.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=e.mode&511,r=t.mode&511,s;return t.matchType==="exact"?s=n===r:t.matchType==="all"?s=(n&r)===r:s=(n&r)!==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 n=Xe(t.expr,e);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=Xe(t.left,e);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=Xe(t.right,e);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=Xe(t.left,e);if(n.matches)return n;let r=Xe(t.right,e);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function vn(t){if(!t)return!1;switch(t.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!1;case"empty":case"mtime":case"newer":case"size":case"perm":return!0;case"not":return vn(t.expr);case"and":case"or":return vn(t.left)||vn(t.right)}}function $n(t){if(!t)return!1;switch(t.type){case"empty":return!0;case"not":return $n(t.expr);case"and":case"or":return $n(t.left)||$n(t.right);default:return!1}}function Zl(t){let e={terminalDirName:null,requiredExtension:null};if(!t)return e;let n=V0(t);if(Z0(t)&&n.length===1){let i=n[0].split("/").filter(o=>o.length>0);if(i.length>=2)for(let o=i.length-2;o>=0;o--){let a=i[o];if(!a.includes("*")&&!a.includes("?")&&!a.includes("[")&&a!=="."&&a!==".."){let l=i[o+1];if(l&&(l.includes("*")||l.includes("?"))){e.terminalDirName=a;let c=l.match(/^\*(\.[a-zA-Z0-9]+)$/);c&&(e.requiredExtension=c[1])}break}}}return e}function V0(t){let e=[],n=r=>{r.type==="path"?e.push(r.pattern):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right))};return n(t),e}function Z0(t){let e=n=>n.type==="type"&&n.fileType==="f"?!0:n.type==="not"?e(n.expr):n.type==="and"||n.type==="or"?e(n.left)||e(n.right):!1;return e(t)}function Kl(t){let e=[],n=r=>{r&&(r.type==="newer"?e.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(t),e}function Rn(t){if(!t)return!0;switch(t.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!0;case"empty":case"mtime":case"newer":case"size":case"perm":return!1;case"not":return Rn(t.expr);case"and":case"or":return Rn(t.left)&&Rn(t.right)}}function Pt(t,e,n,r,s){switch(t.type){case"name":{let i=t.pattern,o=i.match(/^\*(\.[a-zA-Z0-9]+)$/);if(o){let a=o[1];if(t.ignoreCase){if(!e.toLowerCase().endsWith(a.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!e.endsWith(a))return{matches:!1,pruned:!1,printed:!1};return{matches:!0,pruned:!1,printed:!1}}return{matches:De(e,i,t.ignoreCase),pruned:!1,printed:!1}}case"path":{let i=t.pattern,o=i.split("/");for(let l=0;l<o.length-1;l++){let c=o[l];if(c&&c!=="."&&c!==".."&&!c.includes("*")&&!c.includes("?")&&!c.includes("[")){let u=`/${c}/`;if(t.ignoreCase){if(!n.toLowerCase().includes(u.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!n.includes(u))return{matches:!1,pruned:!1,printed:!1}}}let a=i.match(/\*(\.[a-zA-Z0-9]+)$/);if(a){let l=a[1];if(t.ignoreCase){if(!n.toLowerCase().endsWith(l.toLowerCase()))return{matches:!1,pruned:!1,printed:!1}}else if(!n.endsWith(l))return{matches:!1,pruned:!1,printed:!1}}return{matches:De(n,i,t.ignoreCase),pruned:!1,printed:!1}}case"regex":try{let i=t.ignoreCase?"i":"";return{matches:new RegExp(t.pattern,i).test(n),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return t.fileType==="f"?{matches:r,pruned:!1,printed:!1}:t.fileType==="d"?{matches:s,pruned:!1,printed:!1}:{matches:!1,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 i=Pt(t.expr,e,n,r,s);return{matches:!i.matches,pruned:i.pruned,printed:!1}}case"and":{let i=Pt(t.left,e,n,r,s);if(!i.matches)return{matches:!1,pruned:i.pruned,printed:!1};let o=Pt(t.right,e,n,r,s);return{matches:o.matches,pruned:i.pruned||o.pruned,printed:i.printed||o.printed}}case"or":{let i=Pt(t.left,e,n,r,s);if(i.matches)return i;let o=Pt(t.right,e,n,r,s);return{matches:o.matches,pruned:i.pruned||o.pruned,printed:o.printed}}default:return{matches:!1,pruned:!1,printed:!1}}}function Fn(t){if(!t)return!1;switch(t.type){case"prune":return!0;case"not":return Fn(t.expr);case"and":case"or":return Fn(t.left)||Fn(t.right);default:return!1}}function xt(t){switch(t.type){case"name":case"path":case"regex":case"type":case"prune":case"print":return!0;case"empty":case"mtime":case"newer":case"size":case"perm":return!1;case"not":return xt(t.expr);case"and":case"or":return xt(t.left)&&xt(t.right)}}function Ql(t,e){if(!t||!e.isDirectory)return{shouldPrune:!1};if(!xt(t))return Fs(t,e);let n={name:e.name,relativePath:e.relativePath,isFile:e.isFile,isDirectory:e.isDirectory,isEmpty:!1,mtime:0,size:0,mode:0,newerRefTimes:new Map};return{shouldPrune:Xe(t,n).pruned}}function Fs(t,e){switch(t.type){case"or":{if(xt(t.left)){let n={name:e.name,relativePath:e.relativePath,isFile:e.isFile,isDirectory:e.isDirectory,isEmpty:!1,mtime:0,size:0,mode:0,newerRefTimes:new Map};if(Xe(t.left,n).pruned)return{shouldPrune:!0}}return Fs(t.right,e)}case"and":{if(xt(t.left)&&xt(t.right)){let n={name:e.name,relativePath:e.relativePath,isFile:e.isFile,isDirectory:e.isDirectory,isEmpty:!1,mtime:0,size:0,mode:0,newerRefTimes:new Map};return{shouldPrune:Xe(t,n).pruned}}if(xt(t.left)){let n={name:e.name,relativePath:e.relativePath,isFile:e.isFile,isDirectory:e.isDirectory,isEmpty:!1,mtime:0,size:0,mode:0,newerRefTimes:new Map};return Xe(t.left,n).matches?Fs(t.right,e):{shouldPrune:!1}}return{shouldPrune:!1}}case"not":return{shouldPrune:!1};default:return{shouldPrune:!1}}}var Xl=C(()=>{"use strict";fs()});function Jl(t,e){let n=[],r=[],s=e;for(;s<t.length;){let o=t[s];if(o==="("||o==="\\("){n.push({type:"lparen"}),s++;continue}if(o===")"||o==="\\)"){n.push({type:"rparen"}),s++;continue}if(o==="-name"&&s+1<t.length)n.push({type:"expr",expr:{type:"name",pattern:t[++s]}});else if(o==="-iname"&&s+1<t.length)n.push({type:"expr",expr:{type:"name",pattern:t[++s],ignoreCase:!0}});else if(o==="-path"&&s+1<t.length)n.push({type:"expr",expr:{type:"path",pattern:t[++s]}});else if(o==="-ipath"&&s+1<t.length)n.push({type:"expr",expr:{type:"path",pattern:t[++s],ignoreCase:!0}});else if(o==="-regex"&&s+1<t.length)n.push({type:"expr",expr:{type:"regex",pattern:t[++s]}});else if(o==="-iregex"&&s+1<t.length)n.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")n.push({type:"expr",expr:{type:"type",fileType:a}});else return{expr:null,pathIndex:s,error:`find: Unknown argument to -type: ${a}
|
|
439
439
|
`,actions:[]}}else if(o==="-empty")n.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)||n.push({type:"expr",expr:{type:"mtime",days:u,comparison:l}})}else if(o==="-newer"&&s+1<t.length){let a=t[++s];n.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";n.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)||n.push({type:"expr",expr:{type:"perm",mode:u,matchType:l}})}else if(o==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(o==="-not"||o==="!")n.push({type:"not"});else if(o==="-o"||o==="-or")n.push({type:"op",op:"or"});else if(o==="-a"||o==="-and")n.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]==="+";r.push({type:"exec",command:a,batchMode:l})}else if(o==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(o==="-print0")r.push({type:"print0"});else if(o==="-printf"&&s+1<t.length){let a=t[++s];r.push({type:"printf",format:a})}else if(o==="-delete")r.push({type:"delete"});else{if(o.startsWith("-"))return{expr:null,pathIndex:s,error:`find: unknown predicate '${o}'
|
|
440
|
-
`,actions:[]};if(n.length===0){s++;continue}break}s++}if(n.length===0)return{expr:null,pathIndex:s,actions:r};let i=
|
|
441
|
-
`,m=1;continue}let $=
|
|
440
|
+
`,actions:[]};if(n.length===0){s++;continue}break}s++}if(n.length===0)return{expr:null,pathIndex:s,actions:r};let i=K0(n);return i.error?{expr:null,pathIndex:s,error:i.error,actions:r}:{expr:i.expr,pathIndex:s,actions:r}}function K0(t){let e=0;function n(){let a=r();if(!a)return null;for(;e<t.length;){let l=t[e];if(l.type==="op"&&l.op==="or"){e++;let c=r();if(!c)return a;a={type:"or",left:a,right:c}}else break}return a}function r(){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=n();return e<t.length&&t[e].type==="rparen"&&e++,l}return a.type==="expr"?(e++,a.expr):(a.type==="rparen",null)}return{expr:n()}}var Yl=C(()=>{"use strict"});var tc={};M(tc,{findCommand:()=>eg});function Q0(){return{readdirCalls:0,readdirTime:0,statCalls:0,statTime:0,evalCalls:0,evalTime:0,nodeCount:0,batchCount:0,batchTime:0,earlyPrunes:0}}function X0(t,e,n){t({category:"find",name:"summary",durationMs:n,details:{readdirCalls:e.readdirCalls,readdirTimeMs:e.readdirTime,statCalls:e.statCalls,statTimeMs:e.statTime,evalCalls:e.evalCalls,evalTimeMs:e.evalTime,nodeCount:e.nodeCount,batchCount:e.batchCount,batchTimeMs:e.batchTime,earlyPrunes:e.earlyPrunes,otherTimeMs:n-e.readdirTime-e.statTime-e.evalTime-e.batchTime}})}function tg(t,e){let n=Qn(t),r="",s=0;for(;s<n.length;)if(n[s]==="%"&&s+1<n.length){if(s++,n[s]==="%"){r+="%",s++;continue}let[i,o,a]=ho(n,s);if(s+=a,s>=n.length){r+="%";break}let l=n[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=ng(e.mode,e.isDirectory),s++;break;case"t":{let u=new Date(e.mtime);c=rg(u),s++;break}case"T":{if(s+1<n.length){let u=n[s+1],f=new Date(e.mtime);c=sg(f,u),s+=2}else c="%T",s++;break}default:r+=`%${i!==0||o!==-1?`${i}.${o}`:""}${l}`,s++;continue}r+=Kn(c,i,o)}else r+=n[s],s++;return r}function ng(t,e){let n=t&511,r=e?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function rg(t){let e=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=e[t.getDay()],s=n[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`${r} ${s} ${i} ${o}:${a}:${l} ${c}`}function sg(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 ec,J0,Y0,eg,nc=C(()=>{"use strict";j();ls();Xl();Yl();ec=500;J0={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"]},Y0=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),eg={name:"find",async execute(t,e){if(I(t))return N(J0);let n=[],r=null,s=null,i=!1,o=!1;for(let A=0;A<t.length;A++){let R=t[A];if(R==="-maxdepth"&&A+1<t.length)o=!0,r=parseInt(t[++A],10);else if(R==="-mindepth"&&A+1<t.length)o=!0,s=parseInt(t[++A],10);else if(R==="-depth")o=!0,i=!0;else if(R==="-exec")for(o=!0,A++;A<t.length&&t[A]!==";"&&t[A]!=="+";)A++;else!R.startsWith("-")&&R!==";"&&R!=="+"&&R!=="("&&R!==")"&&R!=="\\("&&R!=="\\)"&&R!=="!"?o||n.push(R):Y0.has(R)?(o=!0,A++):(R.startsWith("-")||R==="("||R==="\\("||R==="!")&&(o=!0)}n.length===0&&n.push(".");let{expr:a,error:l,actions:c}=Jl(t,0);if(l)return{stdout:"",stderr:l,exitCode:1};let u=c.some(A=>A.type==="print"),f=c.length===0,d=[],p=c.some(A=>A.type==="printf"),h=[],g="",m=0,w=Kl(a),b=new Map;for(let A of w){let R=e.fs.resolvePath(e.cwd,A);try{let $=await e.fs.stat(R);b.set(A,$.mtime?.getTime()??Date.now())}catch{}}let E=c.some(A=>{if(A.type!=="printf")return!1;let R=A.format.replace(/%%/g,"");return/%[-+]?[0-9]*\.?[0-9]*(s|m|M|t|T)/.test(R)}),S=vn(a)||E,v=$n(a),F=Zl(a),W=Fn(a),z=Rn(a),X=typeof e.fs.readdirWithFileTypes=="function";for(let A of n){let ue=function(D){let se=s===null||D.depth>=s,V=!1;if(se&&a!==null){let T=Date.now(),ne;if(z)ne=Pt(a,D.name,D.relativePath,D.isFile,D.isDirectory);else{let le={name:D.name,relativePath:D.relativePath,isFile:D.isFile,isDirectory:D.isDirectory,isEmpty:D.isEmpty,mtime:D.stat?.mtime?.getTime()??Date.now(),size:D.stat?.size??0,mode:D.stat?.mode??420,newerRefTimes:b};ne=Xe(a,le)}se=ne.matches,V=u?ne.printed:se,$.evalCalls++,$.evalTime+=Date.now()-T}else se&&(V=!0);return V?{print:!0,printfData:p?{path:D.relativePath,name:D.name,size:D.stat?.size??0,mtime:D.stat?.mtime?.getTime()??Date.now(),mode:D.stat?.mode??420,isDirectory:D.isDirectory,depth:D.depth,startingPoint:A}:null}:{print:!1,printfData:null}};var _=ue;A.length>1&&A.endsWith("/")&&(A=A.slice(0,-1));let R=e.fs.resolvePath(e.cwd,A);try{await e.fs.stat(R)}catch{g+=`find: ${A}: No such file or directory
|
|
441
|
+
`,m=1;continue}let $=Q0(),P=Date.now();async function O(D){let{path:q,depth:se,typeInfo:V}=D;if($.nodeCount++,r!==null&&se>r)return null;let ae,T,ne;if(V&&!S)ae=V.isFile,T=V.isDirectory;else{try{let kt=Date.now();ne=await e.fs.stat(q),$.statCalls++,$.statTime+=Date.now()-kt}catch{return null}if(!ne)return null;ae=ne.isFile,T=ne.isDirectory}let le;q===R?le=A.split("/").pop()||A:le=q.split("/").pop()||"";let me=q===R?A:A==="."?`./${q.slice(R==="/"?R.length:R.length+1)}`:A+q.slice(R.length),Ee=[],Ie=null,Se=null,Ce=!1;T&&W&&!i&&(Ce=Ql(a,{name:le,relativePath:me,isFile:ae,isDirectory:T}).shouldPrune,Ce&&$.earlyPrunes++);let je=r!==null&&se>=r,ze=F.terminalDirName!==null&&le===F.terminalDirName,wn=!je&&!ze&&!Ce;if(T&&((wn||v||ze)&&!Ce)){let kt=Date.now();if(X&&e.fs.readdirWithFileTypes){if(Ie=await e.fs.readdirWithFileTypes(q),Se=Ie.map(Me=>Me.name),$.readdirCalls++,$.readdirTime+=Date.now()-kt,wn)Ee=Ie.map((Me,Ze)=>({path:q==="/"?`/${Me.name}`:`${q}/${Me.name}`,depth:se+1,typeInfo:{isFile:Me.isFile,isDirectory:Me.isDirectory},resultIndex:Ze}));else if(ze){let Me=F.requiredExtension;Ee=Ie.filter(Ze=>Ze.isFile&&(!Me||Ze.name.endsWith(Me))).map((Ze,Zd)=>({path:q==="/"?`/${Ze.name}`:`${q}/${Ze.name}`,depth:se+1,typeInfo:{isFile:Ze.isFile,isDirectory:Ze.isDirectory},resultIndex:Zd}))}}else Se=await e.fs.readdir(q),$.readdirCalls++,$.readdirTime+=Date.now()-kt,wn&&(Ee=Se.map((Me,Ze)=>({path:q==="/"?`/${Me}`:`${q}/${Me}`,depth:se+1,resultIndex:Ze})))}let Vn=ae?(ne?.size??0)===0:Se!==null&&Se.length===0,Ht=Ce;if(!i&&a!==null&&!Ce&&W){let kt=Date.now(),Me={name:le,relativePath:me,isFile:ae,isDirectory:T,isEmpty:Vn,mtime:ne?.mtime?.getTime()??Date.now(),size:ne?.size??0,mode:ne?.mode??420,newerRefTimes:b};Ht=Xe(a,Me).pruned,$.evalCalls++,$.evalTime+=Date.now()-kt}return{relativePath:me,name:le,isFile:ae,isDirectory:T,isEmpty:Vn,stat:ne,depth:se,children:Ht?[]:Ee,pruned:Ht}}async function ot(){let D={paths:[],printfData:[]};if(i){let ne=function(le){let me={paths:[],printfData:[]},Ee=V[le];if(!Ee)return me;for(let Ce of Ee.childIndices){let je=ne(Ce);me.paths.push(...je.paths),me.printfData.push(...je.printfData)}let{print:Ie,printfData:Se}=ue(Ee.node);return Ie&&(me.paths.push(Ee.node.relativePath),Se&&me.printfData.push(Se)),me};var q=ne;let V=[],ae=[{item:{path:R,depth:0,resultIndex:0},parentIndex:-1,childOrderInParent:0}],T=new Map;for(;ae.length>0;){let le=Date.now(),me=ae.splice(0,ec),Ee=await Promise.all(me.map(Ie=>O(Ie.item)));$.batchCount++,$.batchTime+=Date.now()-le;for(let Ie=0;Ie<me.length;Ie++){let Se=Ee[Ie],Ce=me[Ie];if(!Se)continue;let je=V.length;if(Ce.parentIndex>=0){let ze=T.get(Ce.parentIndex)||[];ze.push(je),T.set(Ce.parentIndex,ze)}V.push({node:Se,parentIndex:Ce.parentIndex,childIndices:[]});for(let ze=0;ze<Se.children.length;ze++)ae.push({item:Se.children[ze],parentIndex:je,childOrderInParent:ze})}}for(let[le,me]of T)le>=0&&le<V.length&&(V[le].childIndices=me);if(V.length>0){let le=ne(0);D.paths.push(...le.paths),D.printfData.push(...le.printfData)}}else{let le=function(me){let Ee=V.get(me);Ee&&(D.paths.push(Ee.path),Ee.printfData&&D.printfData.push(Ee.printfData));let Ie=ne.get(me);if(Ie)for(let Se of Ie)le(Se)};var se=le;let V=new Map,ae=0,T=[{item:{path:R,depth:0,resultIndex:0},orderIndex:ae++}],ne=new Map;for(;T.length>0;){let me=Date.now(),Ee=T.splice(0,ec),Ie=await Promise.all(Ee.map(async({item:Se,orderIndex:Ce})=>{let je=await O(Se);return je?{node:je,orderIndex:Ce}:null}));$.batchCount++,$.batchTime+=Date.now()-me;for(let Se of Ie){if(!Se)continue;let{node:Ce,orderIndex:je}=Se,{print:ze,printfData:wn}=ue(Ce);if(ze&&V.set(je,{path:Ce.relativePath,printfData:wn}),Ce.children.length>0){let os=[];for(let Vn of Ce.children){let Ht=ae++;os.push(Ht),T.push({item:Vn,orderIndex:Ht})}ne.set(je,os)}}}le(0)}return D}let Y=await ot();if(d.push(...Y.paths),h.push(...Y.printfData),e.trace){let D=Date.now()-P;X0(e.trace,$,D),e.trace({category:"find",name:"searchPath",durationMs:D,details:{path:A,resultsFound:Y.paths.length}})}}let K="";if(c.length>0)for(let A of c)switch(A.type){case"print":K+=d.length>0?`${d.join(`
|
|
442
442
|
`)}
|
|
443
443
|
`:"";break;case"print0":K+=d.length>0?`${d.join("\0")}\0`:"";break;case"delete":{let R=[...d].sort(($,P)=>P.length-$.length);for(let $ of R){let P=e.fs.resolvePath(e.cwd,$);try{await e.fs.rm(P,{recursive:!1})}catch(O){let ue=O instanceof Error?O.message:String(O);g+=`find: cannot delete '${$}': ${ue}
|
|
444
|
-
`,m=1}}break}case"printf":for(let R of h)K+=
|
|
444
|
+
`,m=1}}break}case"printf":for(let R of h)K+=tg(A.format,R);break;case"exec":if(!e.exec)return{stdout:"",stderr:`find: -exec not supported in this context
|
|
445
445
|
`,exitCode:1};if(A.batchMode){let R=[];for(let O of A.command)O==="{}"?R.push(...d):R.push(O);let $=R.map(O=>`"${O}"`).join(" "),P=await e.exec($,{cwd:e.cwd});K+=P.stdout,g+=P.stderr,P.exitCode!==0&&(m=P.exitCode)}else for(let R of d){let P=A.command.map(ue=>ue==="{}"?R:ue).map(ue=>`"${ue}"`).join(" "),O=await e.exec(P,{cwd:e.cwd});K+=O.stdout,g+=O.stderr,O.exitCode!==0&&(m=O.exitCode)}break}else f&&(K=d.length>0?`${d.join(`
|
|
446
446
|
`)}
|
|
447
|
-
`:"");return{stdout:K,stderr:g,exitCode:m}}}});var rc={};M(rc,{basenameCommand:()=>
|
|
448
|
-
basename OPTION... NAME...`,options:["-a, --multiple support multiple arguments","-s, --suffix=SUFFIX remove a trailing SUFFIX"," --help display this help and exit"]},
|
|
447
|
+
`:"");return{stdout:K,stderr:g,exitCode:m}}}});var rc={};M(rc,{basenameCommand:()=>og});var ig,og,sc=C(()=>{"use strict";j();ig={name:"basename",summary:"strip directory and suffix from filenames",usage:`basename NAME [SUFFIX]
|
|
448
|
+
basename OPTION... NAME...`,options:["-a, --multiple support multiple arguments","-s, --suffix=SUFFIX remove a trailing SUFFIX"," --help display this help and exit"]},og={name:"basename",async execute(t,e){if(I(t))return N(ig);let n=!1,r="",s=[];for(let o=0;o<t.length;o++){let a=t[o];a==="-a"||a==="--multiple"?n=!0:a==="-s"&&o+1<t.length?(r=t[++o],n=!0):a.startsWith("--suffix=")?(r=a.slice(9),n=!0):a.startsWith("-")||s.push(a)}if(s.length===0)return{stdout:"",stderr:`basename: missing operand
|
|
449
449
|
`,exitCode:1};!n&&s.length>=2&&(r=s.pop()??"");let i=[];for(let o of s){let a=o.replace(/\/+$/,""),l=a.split("/").pop()||a;r&&l.endsWith(r)&&(l=l.slice(0,-r.length)),i.push(l)}return{stdout:`${i.join(`
|
|
450
450
|
`)}
|
|
451
|
-
`,stderr:"",exitCode:0}}}});var ic={};M(ic,{dirnameCommand:()=>
|
|
451
|
+
`,stderr:"",exitCode:0}}}});var ic={};M(ic,{dirnameCommand:()=>lg});var ag,lg,oc=C(()=>{"use strict";j();ag={name:"dirname",summary:"strip last component from file name",usage:"dirname [OPTION] NAME...",options:[" --help display this help and exit"]},lg={name:"dirname",async execute(t,e){if(I(t))return N(ag);let n=t.filter(s=>!s.startsWith("-"));if(n.length===0)return{stdout:"",stderr:`dirname: missing operand
|
|
452
452
|
`,exitCode:1};let r=[];for(let s of n){let i=s.replace(/\/+$/,""),o=i.lastIndexOf("/");o===-1?r.push("."):o===0?r.push("/"):r.push(i.slice(0,o))}return{stdout:`${r.join(`
|
|
453
453
|
`)}
|
|
454
|
-
`,stderr:"",exitCode:0}}}});var lc={};M(lc,{treeCommand:()=>
|
|
454
|
+
`,stderr:"",exitCode:0}}}});var lc={};M(lc,{treeCommand:()=>fg});async function dg(t,e,n,r,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}
|
|
455
455
|
`,i.fileCount=1,i}catch{return i.stderr=`tree: ${e}: No such file or directory
|
|
456
456
|
`,i}if(i.output=`${e}
|
|
457
457
|
`,n.maxDepth!==null&&s>=n.maxDepth)return i;try{let a=[];if(t.fs.readdirWithFileTypes)a=(await t.fs.readdirWithFileTypes(o)).map(u=>({name:u.name,isDirectory:u.isDirectory}));else{let c=await t.fs.readdir(o);for(let u=0;u<c.length;u+=100){let f=c.slice(u,u+100),d=await Promise.all(f.map(async p=>{let h=o==="/"?`/${p}`:`${o}/${p}`;try{let g=await t.fs.stat(h);return{name:p,isDirectory:g.isDirectory}}catch{return null}}));a.push(...d.filter(p=>p!==null))}}let l=a.filter(c=>!(!n.showHidden&&c.name.startsWith(".")||n.directoriesOnly&&!c.isDirectory));l.sort((c,u)=>c.name.localeCompare(u.name));for(let c=0;c<l.length;c++){let u=l[c],f=o==="/"?`/${u.name}`:`${o}/${u.name}`,d=c===l.length-1,p=d?"`-- ":"|-- ",h=r+(d?" ":"| ");if(u.isDirectory){i.dirCount++;let g=n.fullPath?f:u.name;if(i.output+=`${r+p+g}
|
|
@@ -459,116 +459,116 @@ basename OPTION... NAME...`,options:["-a, --multiple support multiple argument
|
|
|
459
459
|
`}}}catch{i.stderr=`tree: ${e}: Permission denied
|
|
460
460
|
`}return i}async function ac(t,e,n,r,s){let i={output:"",stderr:"",dirCount:0,fileCount:0};if(n.maxDepth!==null&&s>=n.maxDepth)return i;try{let o=[];if(t.fs.readdirWithFileTypes)o=(await t.fs.readdirWithFileTypes(e)).map(c=>({name:c.name,isDirectory:c.isDirectory}));else{let l=await t.fs.readdir(e);for(let c=0;c<l.length;c+=100){let u=l.slice(c,c+100),f=await Promise.all(u.map(async d=>{let p=e==="/"?`/${d}`:`${e}/${d}`;try{let h=await t.fs.stat(p);return{name:d,isDirectory:h.isDirectory}}catch{return null}}));o.push(...f.filter(d=>d!==null))}}let a=o.filter(l=>!(!n.showHidden&&l.name.startsWith(".")||n.directoriesOnly&&!l.isDirectory));a.sort((l,c)=>l.name.localeCompare(c.name));for(let l=0;l<a.length;l++){let c=a[l],u=e==="/"?`/${c.name}`:`${e}/${c.name}`,f=l===a.length-1,d=f?"`-- ":"|-- ",p=r+(f?" ":"| ");if(c.isDirectory){i.dirCount++;let h=n.fullPath?u:c.name;i.output+=`${r+d+h}
|
|
461
461
|
`;let g=await ac(t,u,n,p,s+1);i.output+=g.output,i.dirCount+=g.dirCount,i.fileCount+=g.fileCount}else{i.fileCount++;let h=n.fullPath?u:c.name;i.output+=`${r+d+h}
|
|
462
|
-
`}}}catch{}return i}var
|
|
462
|
+
`}}}catch{}return i}var cg,ug,fg,cc=C(()=>{"use strict";Ae();Gt();j();cg={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"]},ug={showHidden:{short:"a",type:"boolean"},directoriesOnly:{short:"d",type:"boolean"},fullPath:{short:"f",type:"boolean"},maxDepth:{short:"L",type:"number"}},fg={name:"tree",async execute(t,e){if(I(t))return N(cg);let n=J("tree",t,ug);if(!n.ok)return n.error;let r={showHidden:n.result.flags.showHidden,directoriesOnly:n.result.flags.directoriesOnly,maxDepth:n.result.flags.maxDepth??null,fullPath:n.result.flags.fullPath},s=n.result.positional;s.length===0&&s.push(".");let i="",o="",a=0,l=0;for(let c of s){let u=await dg(e,c,r,"",0);i+=u.output,o+=u.stderr,a+=u.dirCount,l+=u.fileCount}return i+=`
|
|
463
463
|
${a} director${a===1?"y":"ies"}`,r.directoriesOnly||(i+=`, ${l} file${l===1?"":"s"}`),i+=`
|
|
464
|
-
`,{stdout:i,stderr:o,exitCode:o?1:0}}}});var fc={};M(fc,{duCommand:()=>
|
|
464
|
+
`,{stdout:i,stderr:o,exitCode:o?1:0}}}});var fc={};M(fc,{duCommand:()=>mg});async function uc(t,e,n,r,s){let i={output:"",totalSize:0,stderr:""};try{let o=await t.fs.stat(e);if(!o.isDirectory)return i.totalSize=o.size,(r.allFiles||s===0)&&(i.output=hr(o.size,r.humanReadable)+" "+n+`
|
|
465
465
|
`),i;let a=0,l=[];if(t.fs.readdirWithFileTypes){let f=await t.fs.readdirWithFileTypes(e),d=f.filter(h=>h.isFile),p=f.filter(h=>h.isDirectory);for(let h=0;h<d.length;h+=100){let g=d.slice(h,h+100),m=await Promise.all(g.map(async w=>{let b=e==="/"?`/${w.name}`:`${e}/${w.name}`;try{let E=await t.fs.stat(b);return{name:w.name,isDirectory:!1,size:E.size}}catch{return{name:w.name,isDirectory:!1,size:0}}}));l.push(...m)}l.push(...p.map(h=>({name:h.name,isDirectory:!0})))}else{let f=await t.fs.readdir(e);for(let d=0;d<f.length;d+=100){let p=f.slice(d,d+100),h=await Promise.all(p.map(async g=>{let m=e==="/"?`/${g}`:`${e}/${g}`;try{let w=await t.fs.stat(m);return{name:g,isDirectory:w.isDirectory,size:w.isDirectory?void 0:w.size}}catch{return{name:g,isDirectory:!1,size:0}}}));l.push(...h)}}l.sort((f,d)=>f.name.localeCompare(d.name));let c=l.filter(f=>!f.isDirectory);for(let f of c){let d=f.size??0;if(a+=d,r.allFiles&&!r.summarize){let p=n==="."?f.name:`${n}/${f.name}`;i.output+=hr(d,r.humanReadable)+" "+p+`
|
|
466
466
|
`}}let u=l.filter(f=>f.isDirectory);for(let f=0;f<u.length;f+=100){let d=u.slice(f,f+100),p=await Promise.all(d.map(async h=>{let g=e==="/"?`/${h.name}`:`${e}/${h.name}`,m=n==="."?h.name:`${n}/${h.name}`;return{name:h.name,result:await uc(t,g,m,r,s+1)}}));p.sort((h,g)=>h.name.localeCompare(g.name));for(let{result:h}of p)a+=h.totalSize,r.summarize||(r.maxDepth===null||s+1<=r.maxDepth)&&(i.output+=h.output)}i.totalSize=a,(r.summarize||r.maxDepth===null||s<=r.maxDepth)&&(i.output+=`${hr(a,r.humanReadable)} ${n}
|
|
467
467
|
`)}catch{i.stderr=`du: cannot read directory '${n}': Permission denied
|
|
468
|
-
`}return i}function hr(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
|
|
468
|
+
`}return i}function hr(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 pg,hg,mg,dc=C(()=>{"use strict";Ae();Gt();j();pg={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"]},hg={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"}},mg={name:"du",async execute(t,e){if(I(t))return N(pg);let n=J("du",t,hg);if(!n.ok)return n.error;let r={allFiles:n.result.flags.allFiles,humanReadable:n.result.flags.humanReadable,summarize:n.result.flags.summarize,grandTotal:n.result.flags.grandTotal,maxDepth:n.result.flags.maxDepth??null},s=n.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 uc(e,c,l,r,0);i+=u.output,a+=u.totalSize,o+=u.stderr}catch{o+=`du: cannot access '${l}': No such file or directory
|
|
469
469
|
`}}return r.grandTotal&&s.length>0&&(i+=`${hr(a,r.humanReadable)} total
|
|
470
|
-
`),{stdout:i,stderr:o,exitCode:o?1:0}}}});var Ps={};M(Ps,{envCommand:()=>
|
|
470
|
+
`),{stdout:i,stderr:o,exitCode:o?1:0}}}});var Ps={};M(Ps,{envCommand:()=>yg,printenvCommand:()=>wg});var gg,yg,xg,wg,Ts=C(()=>{"use strict";j();gg={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"]},yg={name:"env",async execute(t,e){if(I(t))return N(gg);let n=!1,r=[],s={},i=-1;for(let u=0;u<t.length;u++){let f=t[u];if(f==="-i"||f==="--ignore-environment")n=!0;else if(f==="-u"&&u+1<t.length)r.push(t[++u]);else if(f.startsWith("-u"))r.push(f.slice(2));else if(f.startsWith("--unset="))r.push(f.slice(8));else{if(f.startsWith("--")&&f!=="--")return L("env",f);if(f.startsWith("-")&&f!=="-"){for(let d of f.slice(1))if(d!=="i"&&d!=="u")return L("env",`-${d}`);f.includes("i")&&(n=!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(n)o={...s};else{o={...e.env};for(let u of r)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(`
|
|
471
471
|
`)+(u.length>0?`
|
|
472
472
|
`:""),stderr:"",exitCode:0}}if(!e.exec)return{stdout:"",stderr:`env: command execution not supported in this context
|
|
473
|
-
`,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})}},
|
|
473
|
+
`,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})}},xg={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:[" --help display this help and exit"]},wg={name:"printenv",async execute(t,e){if(I(t))return N(xg);let n=t.filter(i=>!i.startsWith("-"));if(n.length===0){let i=[];for(let[o,a]of Object.entries(e.env))i.push(`${o}=${a}`);return{stdout:i.join(`
|
|
474
474
|
`)+(i.length>0?`
|
|
475
475
|
`:""),stderr:"",exitCode:0}}let r=[],s=0;for(let i of n)i in e.env?r.push(e.env[i]):s=1;return{stdout:r.join(`
|
|
476
476
|
`)+(r.length>0?`
|
|
477
|
-
`:""),stderr:"",exitCode:s}}}});var Os={};M(Os,{aliasCommand:()=>
|
|
477
|
+
`:""),stderr:"",exitCode:s}}}});var Os={};M(Os,{aliasCommand:()=>Eg,unaliasCommand:()=>Sg});var bg,en,Eg,Sg,Ds=C(()=>{"use strict";j();bg={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},en="BASH_ALIAS_",Eg={name:"alias",async execute(t,e){if(I(t))return N(bg);if(t.length===0){let n="";for(let[r,s]of Object.entries(e.env))if(r.startsWith(en)){let i=r.slice(en.length);n+=`alias ${i}='${s}'
|
|
478
478
|
`}return{stdout:n,stderr:"",exitCode:0}}for(let n of t){let r=n.indexOf("=");if(r===-1){let s=en+n;return e.env[s]?{stdout:`alias ${n}='${e.env[s]}'
|
|
479
479
|
`,stderr:"",exitCode:0}:{stdout:"",stderr:`alias: ${n}: not found
|
|
480
|
-
`,exitCode:1}}else{let s=n.slice(0,r),i=n.slice(r+1);(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1)),e.env[en+s]=i}}return{stdout:"",stderr:"",exitCode:0}}},
|
|
480
|
+
`,exitCode:1}}else{let s=n.slice(0,r),i=n.slice(r+1);(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1)),e.env[en+s]=i}}return{stdout:"",stderr:"",exitCode:0}}},Sg={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 ...]
|
|
481
481
|
`,exitCode:1};if(t[0]==="-a"){for(let s of Object.keys(e.env))s.startsWith(en)&&delete e.env[s];return{stdout:"",stderr:"",exitCode:0}}let n=!1,r="";for(let s of t){let i=en+s;e.env[i]?delete e.env[i]:(r+=`unalias: ${s}: not found
|
|
482
|
-
`,n=!0)}return{stdout:"",stderr:r,exitCode:n?1:0}}}});var hc={};M(hc,{historyCommand:()=>
|
|
483
|
-
`}return{stdout:o,stderr:"",exitCode:0}}}});var gc={};M(gc,{xargsCommand:()=>
|
|
482
|
+
`,n=!0)}return{stdout:"",stderr:r,exitCode:n?1:0}}}});var hc={};M(hc,{historyCommand:()=>Ag});var Cg,pc,Ag,mc=C(()=>{"use strict";j();Cg={name:"history",summary:"display command history",usage:"history [n]",options:["-c clear the history list"," --help display this help and exit"]},pc="BASH_HISTORY",Ag={name:"history",async execute(t,e){if(I(t))return N(Cg);let n=e.env[pc]||"[]",r;try{r=JSON.parse(n)}catch{r=[]}if(t[0]==="-c")return e.env[pc]="[]",{stdout:"",stderr:"",exitCode:0};let s=r.length;t[0]&&/^\d+$/.test(t[0])&&(s=Math.min(parseInt(t[0],10),r.length));let i=r.length-s,o="";for(let a=i;a<r.length;a++){let l=(a+1).toString().padStart(5," ");o+=`${l} ${r[a]}
|
|
483
|
+
`}return{stdout:o,stderr:"",exitCode:0}}}});var gc={};M(gc,{xargsCommand:()=>Ng});var kg,Ng,yc=C(()=>{"use strict";j();kg={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","-d DELIM use DELIM as input delimiter (e.g., -d '\\n' for newline)","-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"]},Ng={name:"xargs",async execute(t,e){if(I(t))return N(kg);let n=null,r=null,s=null,i=null,o=!1,a=!1,l=!1,c=0;for(let b=0;b<t.length;b++){let E=t[b];if(E==="-I"&&b+1<t.length)n=t[++b],c=b+1;else if(E==="-d"&&b+1<t.length)r=t[++b].replace(/\\n/g,`
|
|
484
484
|
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\0/g,"\0").replace(/\\\\/g,"\\"),c=b+1;else if(E==="-n"&&b+1<t.length)s=parseInt(t[++b],10),c=b+1;else if(E==="-P"&&b+1<t.length)i=parseInt(t[++b],10),c=b+1;else if(E==="-0"||E==="--null")o=!0,c=b+1;else if(E==="-t"||E==="--verbose")a=!0,c=b+1;else if(E==="-r"||E==="--no-run-if-empty")l=!0,c=b+1;else{if(E.startsWith("--"))return L("xargs",E);if(E.startsWith("-")&&E.length>1){for(let S of E.slice(1))if(!"0tr".includes(S))return L("xargs",`-${S}`);E.includes("0")&&(o=!0),E.includes("t")&&(a=!0),E.includes("r")&&(l=!0),c=b+1}else if(!E.startsWith("-")){c=b;break}}}let u=t.slice(c);u.length===0&&u.push("echo");let f;if(o?f=e.stdin.split("\0").filter(b=>b.length>0):r!==null?f=e.stdin.replace(/\n$/,"").split(r).filter(E=>E.length>0):f=e.stdin.split(/\s+/).map(b=>b.trim()).filter(b=>b.length>0),f.length===0)return l?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let d="",p="",h=0,g=b=>/[\s"'\\$`!*?[\]{}();&|<>#]/.test(b)?`"${b.replace(/([\\"`$])/g,"\\$1")}"`:b,m=async b=>{let E=b.map(g).join(" ");return a&&(p+=`${E}
|
|
485
485
|
`),e.exec?e.exec(E,{cwd:e.cwd}):{stdout:`${E}
|
|
486
|
-
`,stderr:"",exitCode:0}},w=async b=>{if(i!==null&&i>1)for(let E=0;E<b.length;E+=i){let S=b.slice(E,E+i),v=await Promise.all(S.map(m));for(let F of v)d+=F.stdout,p+=F.stderr,F.exitCode!==0&&(h=F.exitCode)}else for(let E of b){let S=await m(E);d+=S.stdout,p+=S.stderr,S.exitCode!==0&&(h=S.exitCode)}};if(n!==null){let b=f.map(E=>u.map(S=>S.replaceAll(n,E)));await w(b)}else if(s!==null){let b=[];for(let E=0;E<f.length;E+=s){let S=f.slice(E,E+s);b.push([...u,...S])}await w(b)}else{let b=[...u,...f],E=await m(b);d+=E.stdout,p+=E.stderr,h=E.exitCode}return{stdout:d,stderr:p,exitCode:h}}}});var Ls={};M(Ls,{falseCommand:()=>
|
|
486
|
+
`,stderr:"",exitCode:0}},w=async b=>{if(i!==null&&i>1)for(let E=0;E<b.length;E+=i){let S=b.slice(E,E+i),v=await Promise.all(S.map(m));for(let F of v)d+=F.stdout,p+=F.stderr,F.exitCode!==0&&(h=F.exitCode)}else for(let E of b){let S=await m(E);d+=S.stdout,p+=S.stderr,S.exitCode!==0&&(h=S.exitCode)}};if(n!==null){let b=f.map(E=>u.map(S=>S.replaceAll(n,E)));await w(b)}else if(s!==null){let b=[];for(let E=0;E<f.length;E+=s){let S=f.slice(E,E+s);b.push([...u,...S])}await w(b)}else{let b=[...u,...f],E=await m(b);d+=E.stdout,p+=E.stderr,h=E.exitCode}return{stdout:d,stderr:p,exitCode:h}}}});var Ls={};M(Ls,{falseCommand:()=>vg,trueCommand:()=>Ig});var Ig,vg,Ms=C(()=>{"use strict";Ig={name:"true",async execute(){return{stdout:"",stderr:"",exitCode:0}}},vg={name:"false",async execute(){return{stdout:"",stderr:"",exitCode:1}}}});var xc={};M(xc,{clearCommand:()=>Rg});var $g,Rg,wc=C(()=>{"use strict";j();$g={name:"clear",summary:"clear the terminal screen",usage:"clear [OPTIONS]",options:[" --help display this help and exit"]},Rg={name:"clear",async execute(t,e){return I(t)?N($g):{stdout:"\x1B[2J\x1B[H",stderr:"",exitCode:0}}}});var _s={};M(_s,{bashCommand:()=>Fg,shCommand:()=>Pg});async function mr(t,e,n,r){if(!r.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
|
|
487
487
|
`,exitCode:1};let s={0:e,"#":String(n.length),"@":n.join(" "),"*":n.join(" ")};n.forEach((u,f)=>{s[String(f+1)]=u});let i=t;if(i.startsWith("#!")){let u=i.indexOf(`
|
|
488
488
|
`);u!==-1&&(i=i.slice(u+1))}let o=i.split(`
|
|
489
|
-
`),a=[];for(let u of o){let f=u.trim();f&&!f.startsWith("#")&&a.push(f)}let l=a.join("; ");return await r.exec(l,{env:s,cwd:r.cwd})}var bc,
|
|
490
|
-
`,exitCode:127}}}},
|
|
491
|
-
`,exitCode:127}}}}});function vg(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??Ig},env:t?.env}}function Ws(t,e,n){let r=new Map(t.vars);return r.set(e,n),{vars:r,limits:t.limits,env:t.env,root:t.root,currentPath:t.currentPath}}function Us(t,e){let n=t;for(let r of e)if(n&&typeof n=="object")n=n[r];else return;return n}function tn(t){if(t.type==="Identity")return[];if(t.type==="Field"){let e=t.base?tn(t.base):[];return e===null?null:[...e,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let e=t.base?tn(t.base):[];if(e===null)return null;let n=t.index.value;return typeof n=="number"||typeof n=="string"?[...e,n]:null}if(t.type==="Pipe"){let e=tn(t.left);return e===null?null:js(e,t.right)}return t.type==="Call"&&(t.name==="parent"||t.name==="root"),null}function js(t,e){if(e.type==="Call"){if(e.name==="parent"){let n=1;if(e.args.length>0&&e.args[0].type==="Literal"){let r=e.args[0].value;typeof r=="number"&&(n=r)}if(n>=0)return t.slice(0,Math.max(0,t.length-n));{let r=-n-1;return t.slice(0,Math.min(r,t.length))}}if(e.name==="root")return[]}if(e.type==="Field"){let n=tn(e);if(n!==null)return[...t,...n]}if(e.type==="Index"&&e.index.type==="Literal"){let n=tn(e);if(n!==null)return[...t,...n]}if(e.type==="Pipe"){let n=js(t,e.left);return n===null?null:js(n,e.right)}return e.type==="Identity"?t:null}function k(t,e,n){let r=n&&"vars"in n?n:vg(n);switch(r.root===void 0&&(r={...r,root:t,currentPath:[]}),e.type){case"Identity":return[t];case"Field":return(e.base?k(t,e.base,r):[t]).flatMap(i=>{if(i&&typeof i=="object"&&!Array.isArray(i)){let o=i[e.name];return[o===void 0?null:o]}return[null]});case"Index":return(e.base?k(t,e.base,r):[t]).flatMap(i=>k(i,e.index,r).flatMap(a=>{if(typeof a=="number"&&Array.isArray(i)){let l=a<0?i.length+a:a;return l>=0&&l<i.length?[i[l]]:[null]}return typeof a=="string"&&i&&typeof i=="object"&&!Array.isArray(i)?[i[a]]:[null]}));case"Slice":return(e.base?k(t,e.base,r):[t]).flatMap(i=>{if(!Array.isArray(i)&&typeof i!="string")return[null];let o=i.length,a=e.start?k(t,e.start,r):[0],l=e.end?k(t,e.end,r):[o];return a.flatMap(c=>l.map(u=>{let f=Ec(c,o),d=Ec(u,o);return Array.isArray(i),i.slice(f,d)}))});case"Iterate":return(e.base?k(t,e.base,r):[t]).flatMap(i=>Array.isArray(i)?i:i&&typeof i=="object"?Object.values(i):[]);case"Pipe":{let s=k(t,e.left,r),i=tn(e.left);return s.flatMap(o=>{if(i!==null){let a={...r,currentPath:[...r.currentPath??[],...i]};return k(o,e.right,a)}return k(o,e.right,r)})}case"Comma":{let s=k(t,e.left,r),i=k(t,e.right,r);return[...s,...i]}case"Literal":return[e.value];case"Array":return e.elements?[k(t,e.elements,r)]:[[]];case"Object":{let s=[{}];for(let i of e.entries){let o=typeof i.key=="string"?[i.key]:k(t,i.key,r),a=k(t,i.value,r),l=[];for(let c of s)for(let u of o)for(let f of a)l.push({...c,[String(u)]:f});s.length=0,s.push(...l)}return s}case"Paren":return k(t,e.expr,r);case"BinaryOp":return Fg(t,e.op,e.left,e.right,r);case"UnaryOp":return k(t,e.operand,r).map(i=>e.op==="-"?typeof i=="number"?-i:null:e.op==="not"?!Te(i):null);case"Cond":return k(t,e.cond,r).flatMap(i=>{if(Te(i))return k(t,e.then,r);for(let o of e.elifs)if(k(t,o.cond,r).some(Te))return k(t,o.then,r);return e.else?k(t,e.else,r):[null]});case"Try":try{return k(t,e.body,r)}catch{return e.catch?k(t,e.catch,r):[]}case"Call":return Cc(t,e.name,e.args,r);case"VarBind":return k(t,e.value,r).flatMap(i=>{let o=Ws(r,e.name,i);return k(t,e.body,o)});case"VarRef":{if(e.name==="$ENV")return[r.env??{}];let s=r.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 l of a)o(l);else if(a&&typeof a=="object")for(let l of Object.keys(a))o(a[l])};return o(t),s}case"Optional":try{return k(t,e.expr,r)}catch{return[]}case"StringInterp":return[e.parts.map(i=>typeof i=="string"?i:k(t,i,r).map(a=>typeof a=="string"?a:JSON.stringify(a)).join("")).join("")];case"UpdateOp":return[$g(t,e.path,e.op,e.value,r)];case"Reduce":{let s=k(t,e.expr,r),i=k(t,e.init,r)[0];for(let o of s){let a=Ws(r,e.varName,o);i=k(i,e.update,a)[0]}return[i]}case"Foreach":{let s=k(t,e.expr,r),i=k(t,e.init,r)[0],o=[];for(let a of s){let l=Ws(r,e.varName,a);if(i=k(i,e.update,l)[0],e.extract){let c=k(i,e.extract,l);o.push(...c)}else o.push(i)}return o}default:{let s=e;throw new Error(`Unknown AST node type: ${s.type}`)}}}function Ec(t,e){return t<0?Math.max(0,e+t):Math.min(t,e)}function $g(t,e,n,r,s){function i(l,c){switch(n){case"=":return c;case"|=":return k(l,r,s)[0]??null;case"+=":return typeof l=="number"&&typeof c=="number"||typeof l=="string"&&typeof c=="string"?l+c:Array.isArray(l)&&Array.isArray(c)?[...l,...c]:l&&c&&typeof l=="object"&&typeof c=="object"?{...l,...c}:c;case"-=":return typeof l=="number"&&typeof c=="number"?l-c:l;case"*=":return typeof l=="number"&&typeof c=="number"?l*c:l;case"/=":return typeof l=="number"&&typeof c=="number"?l/c:l;case"%=":return typeof l=="number"&&typeof c=="number"?l%c:l;case"//=":return l===null||l===!1?c:l;default:return c}}function o(l,c,u){switch(c.type){case"Identity":return u(l);case"Field":{if(c.base)return o(l,c.base,f=>{if(f&&typeof f=="object"&&!Array.isArray(f)){let d={...f};return d[c.name]=u(d[c.name]),d}return f});if(l&&typeof l=="object"&&!Array.isArray(l)){let f={...l};return f[c.name]=u(f[c.name]),f}return l}case"Index":{let d=k(t,c.index,s)[0];if(c.base)return o(l,c.base,p=>{if(typeof d=="number"&&Array.isArray(p)){let h=[...p],g=d<0?h.length+d:d;return g>=0&&g<h.length&&(h[g]=u(h[g])),h}if(typeof d=="string"&&p&&typeof p=="object"&&!Array.isArray(p)){let h={...p};return h[d]=u(h[d]),h}return p});if(typeof d=="number"&&Array.isArray(l)){let p=[...l],h=d<0?p.length+d:d;return h>=0&&h<p.length&&(p[h]=u(p[h])),p}if(typeof d=="string"&&l&&typeof l=="object"&&!Array.isArray(l)){let p={...l};return p[d]=u(p[d]),p}return l}case"Iterate":{let f=d=>{if(Array.isArray(d))return d.map(p=>u(p));if(d&&typeof d=="object"){let p={};for(let[h,g]of Object.entries(d))p[h]=u(g);return p}return d};return c.base?o(l,c.base,f):f(l)}case"Pipe":{let f=o(l,c.left,d=>d);return o(f,c.right,u)}default:return u(l)}}return o(t,e,l=>{if(n==="|=")return i(l,l);let c=k(t,r,s);return i(l,c[0]??null)})}function Rg(t,e,n){function r(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,n)[0];if(typeof a=="number"&&Array.isArray(s)){let l=[...s],c=a<0?l.length+a:a;return c>=0&&c<l.length&&l.splice(c,1),l}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){let l={...s};return delete l[a],l}return s}case"Iterate":return Array.isArray(s)?[]:s&&typeof s=="object"?{}:s;default:return s}}return r(t,e)}function Te(t){return t!==null&&t!==!1}function Fg(t,e,n,r,s){if(e==="and")return k(t,n,s).flatMap(l=>Te(l)?k(t,r,s).map(u=>Te(u)):[!1]);if(e==="or")return k(t,n,s).flatMap(l=>Te(l)?[!0]:k(t,r,s).map(u=>Te(u)));if(e==="//"){let l=k(t,n,s).filter(c=>c!=null&&c!==!1);return l.length>0?l:k(t,r,s)}let i=k(t,n,s),o=k(t,r,s);return i.flatMap(a=>o.map(l=>{switch(e){case"+":return typeof a=="number"&&typeof l=="number"||typeof a=="string"&&typeof l=="string"?a+l:Array.isArray(a)&&Array.isArray(l)?[...a,...l]:a&&l&&typeof a=="object"&&typeof l=="object"&&!Array.isArray(a)&&!Array.isArray(l)?{...a,...l}:null;case"-":if(typeof a=="number"&&typeof l=="number")return a-l;if(Array.isArray(a)&&Array.isArray(l)){let c=new Set(l.map(u=>JSON.stringify(u)));return a.filter(u=>!c.has(JSON.stringify(u)))}return null;case"*":return typeof a=="number"&&typeof l=="number"?a*l:typeof a=="string"&&typeof l=="number"?a.repeat(l):a&&l&&typeof a=="object"&&typeof l=="object"&&!Array.isArray(a)&&!Array.isArray(l)?Sc(a,l):null;case"/":return typeof a=="number"&&typeof l=="number"?a/l:typeof a=="string"&&typeof l=="string"?a.split(l):null;case"%":return typeof a=="number"&&typeof l=="number"?a%l:null;case"==":return nn(a,l);case"!=":return!nn(a,l);case"<":return gr(a,l)<0;case"<=":return gr(a,l)<=0;case">":return gr(a,l)>0;case">=":return gr(a,l)>=0;default:return null}}))}function nn(t,e){return JSON.stringify(t)===JSON.stringify(e)}function gr(t,e){return typeof t=="number"&&typeof e=="number"?t-e:typeof t=="string"&&typeof e=="string"?t.localeCompare(e):0}function Sc(t,e){let n={...t};for(let r of Object.keys(e))r in n&&n[r]&&typeof n[r]=="object"&&!Array.isArray(n[r])&&e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?n[r]=Sc(n[r],e[r]):n[r]=e[r];return n}function Cc(t,e,n,r){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=n.length>0?k(t,n[0],r)[0]:t;throw new Error(String(s))}case"not":return[!Te(t)];case"null":return[null];case"true":return[!0];case"false":return[!1];case"first":if(n.length>0){let s=k(t,n[0],r);return s.length>0?[s[0]]:[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(n.length>0){let s=k(t,n[0],r);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(n.length<1)return[null];let i=k(t,n[0],r)[0];if(n.length>1){let o=k(t,n[1],r);return i>=0&&i<o.length?[o[i]]:[]}return Array.isArray(t)?i>=0&&i<t.length?[t[i]]:[null]:[null]}case"range":{if(n.length===0)return[];let s=k(t,n[0],r);if(n.length===1){let c=s[0];return Array.from({length:c},(u,f)=>f)}let i=k(t,n[1],r),o=s[0],a=i[0],l=[];for(let c=o;c<a;c++)l.push(c);return l}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"sort":return Array.isArray(t)?[[...t].sort(Tt)]:[null];case"sort_by":return!Array.isArray(t)||n.length===0?[null]:[[...t].sort((i,o)=>{let a=k(i,n[0],r)[0],l=k(o,n[0],r)[0];return Tt(a,l)})];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)||n.length===0)return[null];let s=new Set,i=[];for(let o of t){let a=JSON.stringify(k(o,n[0],r)[0]);s.has(a)||(s.add(a),i.push(o))}return[i]}case"group_by":{if(!Array.isArray(t)||n.length===0)return[null];let s=new Map;for(let i of t){let o=JSON.stringify(k(i,n[0],r)[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)=>Tt(s,i)>0?s:i)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,n[0],r)[0],a=k(i,n[0],r)[0];return Tt(o,a)>0?s:i})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((s,i)=>Tt(s,i)<0?s:i)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,n[0],r)[0],a=k(i,n[0],r)[0];return Tt(o,a)<0?s:i})];case"flatten":{if(!Array.isArray(t))return[null];let s=n.length>0?k(t,n[0],r)[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 n.length>0?Array.isArray(t)?[t.some(s=>Te(k(s,n[0],r)[0]))]:[!1]:Array.isArray(t)?[t.some(Te)]:[!1];case"all":return n.length>0?Array.isArray(t)?[t.every(s=>Te(k(s,n[0],r)[0]))]:[!0]:Array.isArray(t)?[t.every(Te)]:[!0];case"select":return n.length===0?[t]:k(t,n[0],r).some(Te)?[t]:[];case"map":return n.length===0||!Array.isArray(t)?[null]:[t.flatMap(i=>k(i,n[0],r))];case"map_values":{if(n.length===0)return[null];if(Array.isArray(t))return[t.flatMap(s=>k(s,n[0],r))];if(t&&typeof t=="object"){let s={};for(let[i,o]of Object.entries(t)){let a=k(o,n[0],r);a.length>0&&(s[i]=a[0])}return[s]}return[null]}case"has":{if(n.length===0)return[!1];let i=k(t,n[0],r)[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(n.length===0)return[!1];let i=k(t,n[0],r)[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(n.length===0)return[!1];let s=k(t,n[0],r);return[yr(t,s[0])]}case"inside":{if(n.length===0)return[!1];let s=k(t,n[0],r);return[yr(s[0],t)]}case"getpath":{if(n.length===0)return[null];let i=k(t,n[0],r)[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(n.length<2)return[null];let i=k(t,n[0],r)[0],a=k(t,n[1],r)[0];return[zs(t,i,a)]}case"delpaths":{if(n.length===0)return[t];let i=k(t,n[0],r)[0],o=t;for(let a of i.sort((l,c)=>c.length-l.length))o=Hs(o,a);return[o]}case"path":{if(n.length===0)return[[]];let s=[];return Pg(t,n[0],r,[],s),s}case"del":return n.length===0?[t]:[Rg(t,n[0],r)];case"paths":{let s=[],i=(o,a)=>{if(o&&typeof o=="object")if(Array.isArray(o))for(let l=0;l<o.length;l++)s.push([...a,l]),i(o[l],[...a,l]);else for(let l of Object.keys(o))s.push([...a,l]),i(o[l],[...a,l])};return i(t,[]),n.length>0?s.filter(o=>{let a=t;for(let c of o)if(Array.isArray(a)&&typeof c=="number")a=a[c];else if(a&&typeof a=="object"&&typeof c=="string")a=a[c];else return!1;return k(a,n[0],r).some(Te)}):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 l=0;l<o.length;l++)i(o[l],[...a,l]);else for(let l of Object.keys(o))i(o[l],[...a,l])};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,l=o.value??o.v;a!==void 0&&(s[String(a)]=l)}return[s]}return[null];case"with_entries":{if(n.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let i=Object.entries(t).map(([a,l])=>({key:a,value:l})).flatMap(a=>k(a,n[0],r)),o={};for(let a of i)if(a&&typeof a=="object"){let l=a,c=l.key??l.name??l.k,u=l.value??l.v;c!==void 0&&(o[String(c)]=u)}return[o]}return[null]}case"join":{if(!Array.isArray(t))return[null];let s=n.length>0?k(t,n[0],r):[""],i=String(s[0]);return[t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(i)]}case"split":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);return[t.split(i)]}case"test":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"";return[new RegExp(i,o).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"",l=new RegExp(i,`${o}d`).exec(t);if(!l)return[];let c=l.indices;return[{offset:l.index,length:l[0].length,string:l[0],captures:l.slice(1).map((u,f)=>({offset:c?.[f+1]?.[0]??null,length:u?.length??0,string:u??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"",a=new RegExp(i,o),l=t.match(a);return!l||!l.groups?[{}]:[l.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||n.length<2)return[null];let s=k(t,n[0],r),i=k(t,n[1],r),o=String(s[0]),a=String(i[0]);try{let l=n.length>2?String(k(t,n[2],r)[0]):"";return[t.replace(new RegExp(o,l),a)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||n.length<2)return[null];let s=k(t,n[0],r),i=k(t,n[1],r),o=String(s[0]),a=String(i[0]);try{let l=n.length>2?String(k(t,n[2],r)[0]):"g",c=l.includes("g")?l:`${l}g`;return[t.replace(new RegExp(o,c),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"||n.length===0)return[t];let s=k(t,n[0],r),i=String(s[0]);return[t.startsWith(i)?t.slice(i.length):t]}case"rtrimstr":{if(typeof t!="string"||n.length===0)return[t];let s=k(t,n[0],r),i=String(s[0]);return[t.endsWith(i)?t.slice(0,-i.length):t]}case"trim":return typeof t=="string"?[t.trim()]:[t];case"startswith":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r);return[t.startsWith(String(s[0]))]}case"endswith":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r);return[t.endsWith(String(s[0]))]}case"index":{if(n.length===0)return[null];let i=k(t,n[0],r)[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=>nn(a,i));return[o>=0?o:null]}return[null]}case"rindex":{if(n.length===0)return[null];let i=k(t,n[0],r)[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(nn(t[o],i))return[o];return[null]}return[null]}case"indices":{if(n.length===0)return[[]];let i=k(t,n[0],r)[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++)nn(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"||n.length===0)return[null];let i=k(t,n[0],r)[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[r.env??{}];case"recurse":{if(n.length===0){let a=[],l=c=>{if(a.push(c),Array.isArray(c))for(let u of c)l(u);else if(c&&typeof c=="object")for(let u of Object.keys(c))l(c[u])};return l(t),a}let s=[],i=new Set,o=a=>{let l=JSON.stringify(a);if(i.has(l))return;i.add(l),s.push(a);let c=k(a,n[0],r);for(let u of c)u!=null&&o(u)};return o(t),s}case"recurse_down":return Cc(t,"recurse",n,r);case"walk":{if(n.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 c={};for(let[u,f]of Object.entries(o))c[u]=i(f);a=c}else a=o;return k(a,n[0],r)[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(n.length<2)return[];let i=k(t,n[0],r)[0];return k(t,n[1],r).slice(0,i)}case"until":{if(n.length<2)return[t];let s=t,i=r.limits.maxIterations;for(let o=0;o<i;o++){if(k(s,n[0],r).some(Te))return[s];let l=k(s,n[1],r);if(l.length===0)return[s];s=l[0]}throw new Q(`jq until: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(n.length<2)return[t];let s=[],i=t,o=r.limits.maxIterations;for(let a=0;a<o&&k(i,n[0],r).some(Te);a++){s.push(i);let c=k(i,n[1],r);if(c.length===0)break;i=c[0]}if(s.length>=o)throw new Q(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(n.length===0)return[t];let s=[],i=t,o=r.limits.maxIterations;for(let a=0;a<o;a++){s.push(i);let l=k(i,n[0],r);if(l.length===0)break;i=l[0]}if(s.length>=o)throw new Q(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"debug":return[t];case"input_line_number":return[1];case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(i=>{let o=String(i??"");return o.includes(",")||o.includes('"')||o.includes(`
|
|
492
|
-
`)?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(s=>String(s??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":return[JSON.stringify(t)];case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];case"parent":{if(r.root===void 0||r.currentPath===void 0)return[];let s=r.currentPath;if(s.length===0)return[];let i=n.length>0?k(t,n[0],r)[0]:1;if(i>=0){if(i>s.length)return[];let o=s.slice(0,s.length-i);return[Us(r.root,o)]}else{let o=-i-1;if(o>=s.length)return[t];let a=s.slice(0,o);return[Us(r.root,a)]}}case"parents":{if(r.root===void 0||r.currentPath===void 0)return[[]];let s=r.currentPath,i=[];for(let o=s.length-1;o>=0;o--)i.push(Us(r.root,s.slice(0,o)));return[i]}case"root":return r.root!==void 0?[r.root]:[];default:throw new Error(`Unknown function: ${e}`)}}function Tt(t,e){let n=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,r=n(t),s=n(e);if(r!==s)return r-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=Tt(t[i],e[i]);if(o!==0)return o}return t.length-e.length}return 0}function yr(t,e){if(nn(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return e.every(n=>t.some(r=>yr(r,n)));if(t&&e&&typeof t=="object"&&typeof e=="object"&&!Array.isArray(t)&&!Array.isArray(e)){let n=t,r=e;return Object.keys(r).every(s=>s in n&&yr(n[s],r[s]))}return!1}function zs(t,e,n){if(e.length===0)return n;let[r,...s]=e;if(typeof r=="number"){let o=Array.isArray(t)?[...t]:[];for(;o.length<=r;)o.push(null);return o[r]=zs(o[r],s,n),o}let i=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{};return i[r]=zs(i[r],s,n),i}function Hs(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[n,...r]=e;if(Array.isArray(t)&&typeof n=="number"){let s=[...t];return s[n]=Hs(s[n],r),s}if(t&&typeof t=="object"&&!Array.isArray(t)){let s={...t};return s[String(n)]=Hs(s[String(n)],r),s}return t}function
|
|
489
|
+
`),a=[];for(let u of o){let f=u.trim();f&&!f.startsWith("#")&&a.push(f)}let l=a.join("; ");return await r.exec(l,{env:s,cwd:r.cwd})}var bc,Fg,Pg,Bs=C(()=>{"use strict";j();bc={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).']},Fg={name:"bash",async execute(t,e){if(I(t))return N(bc);if(t[0]==="-c"&&t.length>=2){let s=t[1],i=t[2]||"bash",o=t.slice(3);return mr(s,i,o,e)}if(t.length===0)return{stdout:"",stderr:"",exitCode:0};let n=t[0],r=t.slice(1);try{let s=e.fs.resolvePath(e.cwd,n),i=await e.fs.readFile(s);return mr(i,n,r,e)}catch{return{stdout:"",stderr:`bash: ${n}: No such file or directory
|
|
490
|
+
`,exitCode:127}}}},Pg={name:"sh",async execute(t,e){if(I(t))return N({...bc,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 mr(s,i,o,e)}if(t.length===0)return{stdout:"",stderr:"",exitCode:0};let n=t[0],r=t.slice(1);try{let s=e.fs.resolvePath(e.cwd,n),i=await e.fs.readFile(s);return mr(i,n,r,e)}catch{return{stdout:"",stderr:`sh: ${n}: No such file or directory
|
|
491
|
+
`,exitCode:127}}}}});function Og(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??Tg},env:t?.env}}function Ws(t,e,n){let r=new Map(t.vars);return r.set(e,n),{vars:r,limits:t.limits,env:t.env,root:t.root,currentPath:t.currentPath}}function Us(t,e){let n=t;for(let r of e)if(n&&typeof n=="object")n=n[r];else return;return n}function tn(t){if(t.type==="Identity")return[];if(t.type==="Field"){let e=t.base?tn(t.base):[];return e===null?null:[...e,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let e=t.base?tn(t.base):[];if(e===null)return null;let n=t.index.value;return typeof n=="number"||typeof n=="string"?[...e,n]:null}if(t.type==="Pipe"){let e=tn(t.left);return e===null?null:js(e,t.right)}return t.type==="Call"&&(t.name==="parent"||t.name==="root"),null}function js(t,e){if(e.type==="Call"){if(e.name==="parent"){let n=1;if(e.args.length>0&&e.args[0].type==="Literal"){let r=e.args[0].value;typeof r=="number"&&(n=r)}if(n>=0)return t.slice(0,Math.max(0,t.length-n));{let r=-n-1;return t.slice(0,Math.min(r,t.length))}}if(e.name==="root")return[]}if(e.type==="Field"){let n=tn(e);if(n!==null)return[...t,...n]}if(e.type==="Index"&&e.index.type==="Literal"){let n=tn(e);if(n!==null)return[...t,...n]}if(e.type==="Pipe"){let n=js(t,e.left);return n===null?null:js(n,e.right)}return e.type==="Identity"?t:null}function k(t,e,n){let r=n&&"vars"in n?n:Og(n);switch(r.root===void 0&&(r={...r,root:t,currentPath:[]}),e.type){case"Identity":return[t];case"Field":return(e.base?k(t,e.base,r):[t]).flatMap(i=>{if(i&&typeof i=="object"&&!Array.isArray(i)){let o=i[e.name];return[o===void 0?null:o]}return[null]});case"Index":return(e.base?k(t,e.base,r):[t]).flatMap(i=>k(i,e.index,r).flatMap(a=>{if(typeof a=="number"&&Array.isArray(i)){let l=a<0?i.length+a:a;return l>=0&&l<i.length?[i[l]]:[null]}return typeof a=="string"&&i&&typeof i=="object"&&!Array.isArray(i)?[i[a]]:[null]}));case"Slice":return(e.base?k(t,e.base,r):[t]).flatMap(i=>{if(!Array.isArray(i)&&typeof i!="string")return[null];let o=i.length,a=e.start?k(t,e.start,r):[0],l=e.end?k(t,e.end,r):[o];return a.flatMap(c=>l.map(u=>{let f=Ec(c,o),d=Ec(u,o);return Array.isArray(i),i.slice(f,d)}))});case"Iterate":return(e.base?k(t,e.base,r):[t]).flatMap(i=>Array.isArray(i)?i:i&&typeof i=="object"?Object.values(i):[]);case"Pipe":{let s=k(t,e.left,r),i=tn(e.left);return s.flatMap(o=>{if(i!==null){let a={...r,currentPath:[...r.currentPath??[],...i]};return k(o,e.right,a)}return k(o,e.right,r)})}case"Comma":{let s=k(t,e.left,r),i=k(t,e.right,r);return[...s,...i]}case"Literal":return[e.value];case"Array":return e.elements?[k(t,e.elements,r)]:[[]];case"Object":{let s=[{}];for(let i of e.entries){let o=typeof i.key=="string"?[i.key]:k(t,i.key,r),a=k(t,i.value,r),l=[];for(let c of s)for(let u of o)for(let f of a)l.push({...c,[String(u)]:f});s.length=0,s.push(...l)}return s}case"Paren":return k(t,e.expr,r);case"BinaryOp":return Mg(t,e.op,e.left,e.right,r);case"UnaryOp":return k(t,e.operand,r).map(i=>e.op==="-"?typeof i=="number"?-i:null:e.op==="not"?!Te(i):null);case"Cond":return k(t,e.cond,r).flatMap(i=>{if(Te(i))return k(t,e.then,r);for(let o of e.elifs)if(k(t,o.cond,r).some(Te))return k(t,o.then,r);return e.else?k(t,e.else,r):[null]});case"Try":try{return k(t,e.body,r)}catch{return e.catch?k(t,e.catch,r):[]}case"Call":return Cc(t,e.name,e.args,r);case"VarBind":return k(t,e.value,r).flatMap(i=>{let o=Ws(r,e.name,i);return k(t,e.body,o)});case"VarRef":{if(e.name==="$ENV")return[r.env??{}];let s=r.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 l of a)o(l);else if(a&&typeof a=="object")for(let l of Object.keys(a))o(a[l])};return o(t),s}case"Optional":try{return k(t,e.expr,r)}catch{return[]}case"StringInterp":return[e.parts.map(i=>typeof i=="string"?i:k(t,i,r).map(a=>typeof a=="string"?a:JSON.stringify(a)).join("")).join("")];case"UpdateOp":return[Dg(t,e.path,e.op,e.value,r)];case"Reduce":{let s=k(t,e.expr,r),i=k(t,e.init,r)[0];for(let o of s){let a=Ws(r,e.varName,o);i=k(i,e.update,a)[0]}return[i]}case"Foreach":{let s=k(t,e.expr,r),i=k(t,e.init,r)[0],o=[];for(let a of s){let l=Ws(r,e.varName,a);if(i=k(i,e.update,l)[0],e.extract){let c=k(i,e.extract,l);o.push(...c)}else o.push(i)}return o}default:{let s=e;throw new Error(`Unknown AST node type: ${s.type}`)}}}function Ec(t,e){return t<0?Math.max(0,e+t):Math.min(t,e)}function Dg(t,e,n,r,s){function i(l,c){switch(n){case"=":return c;case"|=":return k(l,r,s)[0]??null;case"+=":return typeof l=="number"&&typeof c=="number"||typeof l=="string"&&typeof c=="string"?l+c:Array.isArray(l)&&Array.isArray(c)?[...l,...c]:l&&c&&typeof l=="object"&&typeof c=="object"?{...l,...c}:c;case"-=":return typeof l=="number"&&typeof c=="number"?l-c:l;case"*=":return typeof l=="number"&&typeof c=="number"?l*c:l;case"/=":return typeof l=="number"&&typeof c=="number"?l/c:l;case"%=":return typeof l=="number"&&typeof c=="number"?l%c:l;case"//=":return l===null||l===!1?c:l;default:return c}}function o(l,c,u){switch(c.type){case"Identity":return u(l);case"Field":{if(c.base)return o(l,c.base,f=>{if(f&&typeof f=="object"&&!Array.isArray(f)){let d={...f};return d[c.name]=u(d[c.name]),d}return f});if(l&&typeof l=="object"&&!Array.isArray(l)){let f={...l};return f[c.name]=u(f[c.name]),f}return l}case"Index":{let d=k(t,c.index,s)[0];if(c.base)return o(l,c.base,p=>{if(typeof d=="number"&&Array.isArray(p)){let h=[...p],g=d<0?h.length+d:d;return g>=0&&g<h.length&&(h[g]=u(h[g])),h}if(typeof d=="string"&&p&&typeof p=="object"&&!Array.isArray(p)){let h={...p};return h[d]=u(h[d]),h}return p});if(typeof d=="number"&&Array.isArray(l)){let p=[...l],h=d<0?p.length+d:d;return h>=0&&h<p.length&&(p[h]=u(p[h])),p}if(typeof d=="string"&&l&&typeof l=="object"&&!Array.isArray(l)){let p={...l};return p[d]=u(p[d]),p}return l}case"Iterate":{let f=d=>{if(Array.isArray(d))return d.map(p=>u(p));if(d&&typeof d=="object"){let p={};for(let[h,g]of Object.entries(d))p[h]=u(g);return p}return d};return c.base?o(l,c.base,f):f(l)}case"Pipe":{let f=o(l,c.left,d=>d);return o(f,c.right,u)}default:return u(l)}}return o(t,e,l=>{if(n==="|=")return i(l,l);let c=k(t,r,s);return i(l,c[0]??null)})}function Lg(t,e,n){function r(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,n)[0];if(typeof a=="number"&&Array.isArray(s)){let l=[...s],c=a<0?l.length+a:a;return c>=0&&c<l.length&&l.splice(c,1),l}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){let l={...s};return delete l[a],l}return s}case"Iterate":return Array.isArray(s)?[]:s&&typeof s=="object"?{}:s;default:return s}}return r(t,e)}function Te(t){return t!==null&&t!==!1}function Mg(t,e,n,r,s){if(e==="and")return k(t,n,s).flatMap(l=>Te(l)?k(t,r,s).map(u=>Te(u)):[!1]);if(e==="or")return k(t,n,s).flatMap(l=>Te(l)?[!0]:k(t,r,s).map(u=>Te(u)));if(e==="//"){let l=k(t,n,s).filter(c=>c!=null&&c!==!1);return l.length>0?l:k(t,r,s)}let i=k(t,n,s),o=k(t,r,s);return i.flatMap(a=>o.map(l=>{switch(e){case"+":return typeof a=="number"&&typeof l=="number"||typeof a=="string"&&typeof l=="string"?a+l:Array.isArray(a)&&Array.isArray(l)?[...a,...l]:a&&l&&typeof a=="object"&&typeof l=="object"&&!Array.isArray(a)&&!Array.isArray(l)?{...a,...l}:null;case"-":if(typeof a=="number"&&typeof l=="number")return a-l;if(Array.isArray(a)&&Array.isArray(l)){let c=new Set(l.map(u=>JSON.stringify(u)));return a.filter(u=>!c.has(JSON.stringify(u)))}return null;case"*":return typeof a=="number"&&typeof l=="number"?a*l:typeof a=="string"&&typeof l=="number"?a.repeat(l):a&&l&&typeof a=="object"&&typeof l=="object"&&!Array.isArray(a)&&!Array.isArray(l)?Sc(a,l):null;case"/":return typeof a=="number"&&typeof l=="number"?a/l:typeof a=="string"&&typeof l=="string"?a.split(l):null;case"%":return typeof a=="number"&&typeof l=="number"?a%l:null;case"==":return nn(a,l);case"!=":return!nn(a,l);case"<":return gr(a,l)<0;case"<=":return gr(a,l)<=0;case">":return gr(a,l)>0;case">=":return gr(a,l)>=0;default:return null}}))}function nn(t,e){return JSON.stringify(t)===JSON.stringify(e)}function gr(t,e){return typeof t=="number"&&typeof e=="number"?t-e:typeof t=="string"&&typeof e=="string"?t.localeCompare(e):0}function Sc(t,e){let n={...t};for(let r of Object.keys(e))r in n&&n[r]&&typeof n[r]=="object"&&!Array.isArray(n[r])&&e[r]&&typeof e[r]=="object"&&!Array.isArray(e[r])?n[r]=Sc(n[r],e[r]):n[r]=e[r];return n}function Cc(t,e,n,r){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=n.length>0?k(t,n[0],r)[0]:t;throw new Error(String(s))}case"not":return[!Te(t)];case"null":return[null];case"true":return[!0];case"false":return[!1];case"first":if(n.length>0){let s=k(t,n[0],r);return s.length>0?[s[0]]:[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(n.length>0){let s=k(t,n[0],r);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(n.length<1)return[null];let i=k(t,n[0],r)[0];if(n.length>1){let o=k(t,n[1],r);return i>=0&&i<o.length?[o[i]]:[]}return Array.isArray(t)?i>=0&&i<t.length?[t[i]]:[null]:[null]}case"range":{if(n.length===0)return[];let s=k(t,n[0],r);if(n.length===1){let c=s[0];return Array.from({length:c},(u,f)=>f)}let i=k(t,n[1],r),o=s[0],a=i[0],l=[];for(let c=o;c<a;c++)l.push(c);return l}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"sort":return Array.isArray(t)?[[...t].sort(Tt)]:[null];case"sort_by":return!Array.isArray(t)||n.length===0?[null]:[[...t].sort((i,o)=>{let a=k(i,n[0],r)[0],l=k(o,n[0],r)[0];return Tt(a,l)})];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)||n.length===0)return[null];let s=new Set,i=[];for(let o of t){let a=JSON.stringify(k(o,n[0],r)[0]);s.has(a)||(s.add(a),i.push(o))}return[i]}case"group_by":{if(!Array.isArray(t)||n.length===0)return[null];let s=new Map;for(let i of t){let o=JSON.stringify(k(i,n[0],r)[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)=>Tt(s,i)>0?s:i)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,n[0],r)[0],a=k(i,n[0],r)[0];return Tt(o,a)>0?s:i})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((s,i)=>Tt(s,i)<0?s:i)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((s,i)=>{let o=k(s,n[0],r)[0],a=k(i,n[0],r)[0];return Tt(o,a)<0?s:i})];case"flatten":{if(!Array.isArray(t))return[null];let s=n.length>0?k(t,n[0],r)[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 n.length>0?Array.isArray(t)?[t.some(s=>Te(k(s,n[0],r)[0]))]:[!1]:Array.isArray(t)?[t.some(Te)]:[!1];case"all":return n.length>0?Array.isArray(t)?[t.every(s=>Te(k(s,n[0],r)[0]))]:[!0]:Array.isArray(t)?[t.every(Te)]:[!0];case"select":return n.length===0?[t]:k(t,n[0],r).some(Te)?[t]:[];case"map":return n.length===0||!Array.isArray(t)?[null]:[t.flatMap(i=>k(i,n[0],r))];case"map_values":{if(n.length===0)return[null];if(Array.isArray(t))return[t.flatMap(s=>k(s,n[0],r))];if(t&&typeof t=="object"){let s={};for(let[i,o]of Object.entries(t)){let a=k(o,n[0],r);a.length>0&&(s[i]=a[0])}return[s]}return[null]}case"has":{if(n.length===0)return[!1];let i=k(t,n[0],r)[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(n.length===0)return[!1];let i=k(t,n[0],r)[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(n.length===0)return[!1];let s=k(t,n[0],r);return[yr(t,s[0])]}case"inside":{if(n.length===0)return[!1];let s=k(t,n[0],r);return[yr(s[0],t)]}case"getpath":{if(n.length===0)return[null];let i=k(t,n[0],r)[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(n.length<2)return[null];let i=k(t,n[0],r)[0],a=k(t,n[1],r)[0];return[zs(t,i,a)]}case"delpaths":{if(n.length===0)return[t];let i=k(t,n[0],r)[0],o=t;for(let a of i.sort((l,c)=>c.length-l.length))o=Hs(o,a);return[o]}case"path":{if(n.length===0)return[[]];let s=[];return _g(t,n[0],r,[],s),s}case"del":return n.length===0?[t]:[Lg(t,n[0],r)];case"paths":{let s=[],i=(o,a)=>{if(o&&typeof o=="object")if(Array.isArray(o))for(let l=0;l<o.length;l++)s.push([...a,l]),i(o[l],[...a,l]);else for(let l of Object.keys(o))s.push([...a,l]),i(o[l],[...a,l])};return i(t,[]),n.length>0?s.filter(o=>{let a=t;for(let c of o)if(Array.isArray(a)&&typeof c=="number")a=a[c];else if(a&&typeof a=="object"&&typeof c=="string")a=a[c];else return!1;return k(a,n[0],r).some(Te)}):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 l=0;l<o.length;l++)i(o[l],[...a,l]);else for(let l of Object.keys(o))i(o[l],[...a,l])};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,l=o.value??o.v;a!==void 0&&(s[String(a)]=l)}return[s]}return[null];case"with_entries":{if(n.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let i=Object.entries(t).map(([a,l])=>({key:a,value:l})).flatMap(a=>k(a,n[0],r)),o={};for(let a of i)if(a&&typeof a=="object"){let l=a,c=l.key??l.name??l.k,u=l.value??l.v;c!==void 0&&(o[String(c)]=u)}return[o]}return[null]}case"join":{if(!Array.isArray(t))return[null];let s=n.length>0?k(t,n[0],r):[""],i=String(s[0]);return[t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(i)]}case"split":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);return[t.split(i)]}case"test":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"";return[new RegExp(i,o).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"",l=new RegExp(i,`${o}d`).exec(t);if(!l)return[];let c=l.indices;return[{offset:l.index,length:l[0].length,string:l[0],captures:l.slice(1).map((u,f)=>({offset:c?.[f+1]?.[0]??null,length:u?.length??0,string:u??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||n.length===0)return[null];let s=k(t,n[0],r),i=String(s[0]);try{let o=n.length>1?String(k(t,n[1],r)[0]):"",a=new RegExp(i,o),l=t.match(a);return!l||!l.groups?[{}]:[l.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||n.length<2)return[null];let s=k(t,n[0],r),i=k(t,n[1],r),o=String(s[0]),a=String(i[0]);try{let l=n.length>2?String(k(t,n[2],r)[0]):"";return[t.replace(new RegExp(o,l),a)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||n.length<2)return[null];let s=k(t,n[0],r),i=k(t,n[1],r),o=String(s[0]),a=String(i[0]);try{let l=n.length>2?String(k(t,n[2],r)[0]):"g",c=l.includes("g")?l:`${l}g`;return[t.replace(new RegExp(o,c),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"||n.length===0)return[t];let s=k(t,n[0],r),i=String(s[0]);return[t.startsWith(i)?t.slice(i.length):t]}case"rtrimstr":{if(typeof t!="string"||n.length===0)return[t];let s=k(t,n[0],r),i=String(s[0]);return[t.endsWith(i)?t.slice(0,-i.length):t]}case"trim":return typeof t=="string"?[t.trim()]:[t];case"startswith":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r);return[t.startsWith(String(s[0]))]}case"endswith":{if(typeof t!="string"||n.length===0)return[!1];let s=k(t,n[0],r);return[t.endsWith(String(s[0]))]}case"index":{if(n.length===0)return[null];let i=k(t,n[0],r)[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=>nn(a,i));return[o>=0?o:null]}return[null]}case"rindex":{if(n.length===0)return[null];let i=k(t,n[0],r)[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(nn(t[o],i))return[o];return[null]}return[null]}case"indices":{if(n.length===0)return[[]];let i=k(t,n[0],r)[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++)nn(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"||n.length===0)return[null];let i=k(t,n[0],r)[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[r.env??{}];case"recurse":{if(n.length===0){let a=[],l=c=>{if(a.push(c),Array.isArray(c))for(let u of c)l(u);else if(c&&typeof c=="object")for(let u of Object.keys(c))l(c[u])};return l(t),a}let s=[],i=new Set,o=a=>{let l=JSON.stringify(a);if(i.has(l))return;i.add(l),s.push(a);let c=k(a,n[0],r);for(let u of c)u!=null&&o(u)};return o(t),s}case"recurse_down":return Cc(t,"recurse",n,r);case"walk":{if(n.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 c={};for(let[u,f]of Object.entries(o))c[u]=i(f);a=c}else a=o;return k(a,n[0],r)[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(n.length<2)return[];let i=k(t,n[0],r)[0];return k(t,n[1],r).slice(0,i)}case"until":{if(n.length<2)return[t];let s=t,i=r.limits.maxIterations;for(let o=0;o<i;o++){if(k(s,n[0],r).some(Te))return[s];let l=k(s,n[1],r);if(l.length===0)return[s];s=l[0]}throw new Q(`jq until: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(n.length<2)return[t];let s=[],i=t,o=r.limits.maxIterations;for(let a=0;a<o&&k(i,n[0],r).some(Te);a++){s.push(i);let c=k(i,n[1],r);if(c.length===0)break;i=c[0]}if(s.length>=o)throw new Q(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(n.length===0)return[t];let s=[],i=t,o=r.limits.maxIterations;for(let a=0;a<o;a++){s.push(i);let l=k(i,n[0],r);if(l.length===0)break;i=l[0]}if(s.length>=o)throw new Q(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"debug":return[t];case"input_line_number":return[1];case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(i=>{let o=String(i??"");return o.includes(",")||o.includes('"')||o.includes(`
|
|
492
|
+
`)?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(s=>String(s??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":return[JSON.stringify(t)];case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];case"parent":{if(r.root===void 0||r.currentPath===void 0)return[];let s=r.currentPath;if(s.length===0)return[];let i=n.length>0?k(t,n[0],r)[0]:1;if(i>=0){if(i>s.length)return[];let o=s.slice(0,s.length-i);return[Us(r.root,o)]}else{let o=-i-1;if(o>=s.length)return[t];let a=s.slice(0,o);return[Us(r.root,a)]}}case"parents":{if(r.root===void 0||r.currentPath===void 0)return[[]];let s=r.currentPath,i=[];for(let o=s.length-1;o>=0;o--)i.push(Us(r.root,s.slice(0,o)));return[i]}case"root":return r.root!==void 0?[r.root]:[];default:throw new Error(`Unknown function: ${e}`)}}function Tt(t,e){let n=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,r=n(t),s=n(e);if(r!==s)return r-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=Tt(t[i],e[i]);if(o!==0)return o}return t.length-e.length}return 0}function yr(t,e){if(nn(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return e.every(n=>t.some(r=>yr(r,n)));if(t&&e&&typeof t=="object"&&typeof e=="object"&&!Array.isArray(t)&&!Array.isArray(e)){let n=t,r=e;return Object.keys(r).every(s=>s in n&&yr(n[s],r[s]))}return!1}function zs(t,e,n){if(e.length===0)return n;let[r,...s]=e;if(typeof r=="number"){let o=Array.isArray(t)?[...t]:[];for(;o.length<=r;)o.push(null);return o[r]=zs(o[r],s,n),o}let i=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{};return i[r]=zs(i[r],s,n),i}function Hs(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[n,...r]=e;if(Array.isArray(t)&&typeof n=="number"){let s=[...t];return s[n]=Hs(s[n],r),s}if(t&&typeof t=="object"&&!Array.isArray(t)){let s={...t};return s[String(n)]=Hs(s[String(n)],r),s}return t}function _g(t,e,n,r,s){k(t,e,n).length>0&&s.push(r)}var Tg,Ac=C(()=>{"use strict";de();Tg=1e4});function kc(t){let e=[],n=0,r=(c=0)=>t[n+c],s=()=>t[n++],i=()=>n>=t.length,o=c=>c>="0"&&c<="9",a=c=>c>="a"&&c<="z"||c>="A"&&c<="Z"||c==="_",l=c=>a(c)||o(c);for(;!i();){let c=n,u=s();if(!(u===" "||u===" "||u===`
|
|
493
493
|
`||u==="\r")){if(u==="#"){for(;!i()&&r()!==`
|
|
494
494
|
`;)s();continue}if(u==="."&&r()==="."){s(),e.push({type:"DOTDOT",pos:c});continue}if(u==="="&&r()==="="){s(),e.push({type:"EQ",pos:c});continue}if(u==="!"&&r()==="="){s(),e.push({type:"NE",pos:c});continue}if(u==="<"&&r()==="="){s(),e.push({type:"LE",pos:c});continue}if(u===">"&&r()==="="){s(),e.push({type:"GE",pos:c});continue}if(u==="/"&&r()==="/"){s(),r()==="="?(s(),e.push({type:"UPDATE_ALT",pos:c})):e.push({type:"ALT",pos:c});continue}if(u==="+"&&r()==="="){s(),e.push({type:"UPDATE_ADD",pos:c});continue}if(u==="-"&&r()==="="){s(),e.push({type:"UPDATE_SUB",pos:c});continue}if(u==="*"&&r()==="="){s(),e.push({type:"UPDATE_MUL",pos:c});continue}if(u==="/"&&r()==="="){s(),e.push({type:"UPDATE_DIV",pos:c});continue}if(u==="%"&&r()==="="){s(),e.push({type:"UPDATE_MOD",pos:c});continue}if(u==="="&&r()!=="="){e.push({type:"ASSIGN",pos:c});continue}if(u==="."){e.push({type:"DOT",pos:c});continue}if(u==="|"){r()==="="?(s(),e.push({type:"UPDATE_PIPE",pos:c})):e.push({type:"PIPE",pos:c});continue}if(u===","){e.push({type:"COMMA",pos:c});continue}if(u===":"){e.push({type:"COLON",pos:c});continue}if(u===";"){e.push({type:"SEMICOLON",pos:c});continue}if(u==="("){e.push({type:"LPAREN",pos:c});continue}if(u===")"){e.push({type:"RPAREN",pos:c});continue}if(u==="["){e.push({type:"LBRACKET",pos:c});continue}if(u==="]"){e.push({type:"RBRACKET",pos:c});continue}if(u==="{"){e.push({type:"LBRACE",pos:c});continue}if(u==="}"){e.push({type:"RBRACE",pos:c});continue}if(u==="?"){e.push({type:"QUESTION",pos:c});continue}if(u==="+"){e.push({type:"PLUS",pos:c});continue}if(u==="-"){if(o(r())){let f=u;for(;!i()&&(o(r())||r()===".");)f+=s();e.push({type:"NUMBER",value:Number(f),pos:c});continue}e.push({type:"MINUS",pos:c});continue}if(u==="*"){e.push({type:"STAR",pos:c});continue}if(u==="/"){e.push({type:"SLASH",pos:c});continue}if(u==="%"){e.push({type:"PERCENT",pos:c});continue}if(u==="<"){e.push({type:"LT",pos:c});continue}if(u===">"){e.push({type:"GT",pos:c});continue}if(o(u)){let f=u;for(;!i()&&(o(r())||r()==="."||r()==="e"||r()==="E");)(r()==="e"||r()==="E")&&(t[n+1]==="+"||t[n+1]==="-")&&(f+=s()),f+=s();e.push({type:"NUMBER",value:Number(f),pos:c});continue}if(u==='"'){let f="";for(;!i()&&r()!=='"';)if(r()==="\\"){if(s(),i())break;let d=s();switch(d){case"n":f+=`
|
|
495
|
-
`;break;case"r":f+="\r";break;case"t":f+=" ";break;case"\\":f+="\\";break;case'"':f+='"';break;case"(":f+="\\(";break;default:f+=d}}else f+=s();i()||s(),e.push({type:"STRING",value:f,pos:c});continue}if(a(u)||u==="$"||u==="@"){let f=u;for(;!i()&&l(r());)f+=s();let d=Tg[f];d?e.push({type:d,pos:c}):e.push({type:"IDENT",value:f,pos:c});continue}throw new Error(`Unexpected character '${u}' at position ${c}`)}}return e.push({type:"EOF",pos:n}),e}function Nc(t){let e=kc(t);return new Gs(e).parse()}var Tg,Gs,Ic=C(()=>{"use strict";Tg={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"};Gs=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 n of e)if(this.check(n))return this.advance();return null}expect(e,n){if(!this.check(e))throw new Error(`${n} 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 n=this.parseComma();e={type:"Pipe",left:e,right:n}}return e}parseComma(){let e=this.parseVarBind();for(;this.match("COMMA");){let n=this.parseVarBind();e={type:"Comma",left:e,right:n}}return e}parseVarBind(){let e=this.parseUpdate();if(this.match("AS")){let n=this.expect("IDENT","Expected variable name after 'as'"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.pos}`);this.expect("PIPE","Expected '|' after variable binding");let s=this.parseExpr();return{type:"VarBind",name:r,value:e,body:s}}return e}parseUpdate(){let e=this.parseAlt(),n={ASSIGN:"=",UPDATE_ADD:"+=",UPDATE_SUB:"-=",UPDATE_MUL:"*=",UPDATE_DIV:"/=",UPDATE_MOD:"%=",UPDATE_ALT:"//=",UPDATE_PIPE:"|="},r=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(r){let s=this.parseVarBind();return{type:"UpdateOp",op:n[r.type],path:e,value:s}}return e}parseAlt(){let e=this.parseOr();for(;this.match("ALT");){let n=this.parseOr();e={type:"BinaryOp",op:"//",left:e,right:n}}return e}parseOr(){let e=this.parseAnd();for(;this.match("OR");){let n=this.parseAnd();e={type:"BinaryOp",op:"or",left:e,right:n}}return e}parseAnd(){let e=this.parseNot();for(;this.match("AND");){let n=this.parseNot();e={type:"BinaryOp",op:"and",left:e,right:n}}return e}parseNot(){return this.parseComparison()}parseComparison(){let e=this.parseAddSub(),n={EQ:"==",NE:"!=",LT:"<",LE:"<=",GT:">",GE:">="},r=this.match("EQ","NE","LT","LE","GT","GE");if(r){let s=this.parseAddSub();e={type:"BinaryOp",op:n[r.type],left:e,right:s}}return e}parseAddSub(){let e=this.parseMulDiv();for(;;)if(this.match("PLUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"+",left:e,right:n}}else if(this.match("MINUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"-",left:e,right:n}}else break;return e}parseMulDiv(){let e=this.parseUnary();for(;;)if(this.match("STAR")){let n=this.parseUnary();e={type:"BinaryOp",op:"*",left:e,right:n}}else if(this.match("SLASH")){let n=this.parseUnary();e={type:"BinaryOp",op:"/",left:e,right:n}}else if(this.match("PERCENT")){let n=this.parseUnary();e={type:"BinaryOp",op:"%",left:e,right:n}}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 n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",end:n,base:e}}else{let n=this.parseExpr();if(this.match("COLON")){let r=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",start:n,end:r,base:e}}else this.expect("RBRACKET","Expected ']'"),e={type:"Index",index:n,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 n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:n}}let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:e,end:n}}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 n=this.advance().value;return n.includes("\\(")?this.parseStringInterpolation(n):{type:"Literal",value:n}}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(),n;return this.match("CATCH")&&(n=this.parsePostfix()),{type:"Try",body:e,catch:n}}if(this.match("REDUCE")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after reduce expression");let n=this.expect("IDENT","Expected variable name"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.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:r,init:s,update:i}}if(this.match("FOREACH")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after foreach expression");let n=this.expect("IDENT","Expected variable name"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.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:r,init:s,update:i,extract:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let n=this.advance().value;if(n.startsWith("$"))return{type:"VarRef",name:n};if(this.match("LPAREN")){let r=[];if(!this.check("RPAREN"))for(r.push(this.parseExpr());this.match("SEMICOLON");)r.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:n,args:r}}return{type:"Call",name:n,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let e=[];if(!this.check("RBRACE"))do{let n,r;if(this.match("LPAREN"))n=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),r=this.parseObjectValue();else if(this.check("IDENT")){let s=this.advance().value;this.match("COLON")?(n=s,r=this.parseObjectValue()):(n=s,r={type:"Field",name:s})}else if(this.check("STRING"))n=this.advance().value,this.expect("COLON","Expected ':'"),r=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);e.push({key:n,value:r})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:e}}parseObjectValue(){let e=this.parseVarBind();for(;this.match("PIPE");){let n=this.parseVarBind();e={type:"Pipe",left:e,right:n}}return e}parseIf(){let e=this.parseExpr();this.expect("THEN","Expected 'then'");let n=this.parseExpr(),r=[];for(;this.match("ELIF");){let i=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let o=this.parseExpr();r.push({cond:i,then:o})}let s;return this.match("ELSE")&&(s=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:e,then:n,elifs:r,else:s}}parseStringInterpolation(e){let n=[],r="",s=0;for(;s<e.length;)if(e[s]==="\\"&&e[s+1]==="("){r&&(n.push(r),r=""),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=kc(o),l=new t(a);n.push(l.parse())}else r+=e[s],s++;return r&&n.push(r),{type:"StringInterp",parts:n}}}});var vc=C(()=>{"use strict";Ac();Ic()});var Rc={};M(Rc,{jqCommand:()=>Dg});function $c(t){let e=[],n=0,r=t.length;for(;n<r;){for(;n<r&&/\s/.test(t[n]);)n++;if(n>=r)break;let s=n,i=t[n];if(i==="{"||i==="["){let o=i,a=i==="{"?"}":"]",l=1,c=!1,u=!1;for(n++;n<r&&l>0;){let f=t[n];u?u=!1:f==="\\"?u=!0:f==='"'?c=!c:c||(f===o?l++:f===a&&l--),n++}if(l!==0)throw new Error(`Unexpected end of JSON input at position ${n} (unclosed ${o})`);e.push(JSON.parse(t.slice(s,n)))}else if(i==='"'){let o=!1;for(n++;n<r;){let a=t[n];if(o)o=!1;else if(a==="\\")o=!0;else if(a==='"'){n++;break}n++}e.push(JSON.parse(t.slice(s,n)))}else if(i==="-"||i>="0"&&i<="9"){for(;n<r&&/[\d.eE+-]/.test(t[n]);)n++;e.push(JSON.parse(t.slice(s,n)))}else if(t.slice(n,n+4)==="true")e.push(!0),n+=4;else if(t.slice(n,n+5)==="false")e.push(!1),n+=5;else if(t.slice(n,n+4)==="null")e.push(null),n+=4;else{let o=t.slice(n,n+10);throw new Error(`Invalid JSON at position ${s}: unexpected '${o.split(/\s/)[0]}'`)}}return e}function Pn(t,e,n,r,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 n?t:JSON.stringify(t);let o=s?" ":" ";if(Array.isArray(t))return t.length===0?"[]":e?`[${t.map(l=>Pn(l,!0,!1,r,s)).join(",")}]`:`[
|
|
495
|
+
`;break;case"r":f+="\r";break;case"t":f+=" ";break;case"\\":f+="\\";break;case'"':f+='"';break;case"(":f+="\\(";break;default:f+=d}}else f+=s();i()||s(),e.push({type:"STRING",value:f,pos:c});continue}if(a(u)||u==="$"||u==="@"){let f=u;for(;!i()&&l(r());)f+=s();let d=Bg[f];d?e.push({type:d,pos:c}):e.push({type:"IDENT",value:f,pos:c});continue}throw new Error(`Unexpected character '${u}' at position ${c}`)}}return e.push({type:"EOF",pos:n}),e}function Nc(t){let e=kc(t);return new Gs(e).parse()}var Bg,Gs,Ic=C(()=>{"use strict";Bg={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"};Gs=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 n of e)if(this.check(n))return this.advance();return null}expect(e,n){if(!this.check(e))throw new Error(`${n} 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 n=this.parseComma();e={type:"Pipe",left:e,right:n}}return e}parseComma(){let e=this.parseVarBind();for(;this.match("COMMA");){let n=this.parseVarBind();e={type:"Comma",left:e,right:n}}return e}parseVarBind(){let e=this.parseUpdate();if(this.match("AS")){let n=this.expect("IDENT","Expected variable name after 'as'"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.pos}`);this.expect("PIPE","Expected '|' after variable binding");let s=this.parseExpr();return{type:"VarBind",name:r,value:e,body:s}}return e}parseUpdate(){let e=this.parseAlt(),n={ASSIGN:"=",UPDATE_ADD:"+=",UPDATE_SUB:"-=",UPDATE_MUL:"*=",UPDATE_DIV:"/=",UPDATE_MOD:"%=",UPDATE_ALT:"//=",UPDATE_PIPE:"|="},r=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(r){let s=this.parseVarBind();return{type:"UpdateOp",op:n[r.type],path:e,value:s}}return e}parseAlt(){let e=this.parseOr();for(;this.match("ALT");){let n=this.parseOr();e={type:"BinaryOp",op:"//",left:e,right:n}}return e}parseOr(){let e=this.parseAnd();for(;this.match("OR");){let n=this.parseAnd();e={type:"BinaryOp",op:"or",left:e,right:n}}return e}parseAnd(){let e=this.parseNot();for(;this.match("AND");){let n=this.parseNot();e={type:"BinaryOp",op:"and",left:e,right:n}}return e}parseNot(){return this.parseComparison()}parseComparison(){let e=this.parseAddSub(),n={EQ:"==",NE:"!=",LT:"<",LE:"<=",GT:">",GE:">="},r=this.match("EQ","NE","LT","LE","GT","GE");if(r){let s=this.parseAddSub();e={type:"BinaryOp",op:n[r.type],left:e,right:s}}return e}parseAddSub(){let e=this.parseMulDiv();for(;;)if(this.match("PLUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"+",left:e,right:n}}else if(this.match("MINUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"-",left:e,right:n}}else break;return e}parseMulDiv(){let e=this.parseUnary();for(;;)if(this.match("STAR")){let n=this.parseUnary();e={type:"BinaryOp",op:"*",left:e,right:n}}else if(this.match("SLASH")){let n=this.parseUnary();e={type:"BinaryOp",op:"/",left:e,right:n}}else if(this.match("PERCENT")){let n=this.parseUnary();e={type:"BinaryOp",op:"%",left:e,right:n}}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 n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",end:n,base:e}}else{let n=this.parseExpr();if(this.match("COLON")){let r=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",start:n,end:r,base:e}}else this.expect("RBRACKET","Expected ']'"),e={type:"Index",index:n,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 n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:n}}let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:e,end:n}}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 n=this.advance().value;return n.includes("\\(")?this.parseStringInterpolation(n):{type:"Literal",value:n}}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(),n;return this.match("CATCH")&&(n=this.parsePostfix()),{type:"Try",body:e,catch:n}}if(this.match("REDUCE")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after reduce expression");let n=this.expect("IDENT","Expected variable name"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.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:r,init:s,update:i}}if(this.match("FOREACH")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after foreach expression");let n=this.expect("IDENT","Expected variable name"),r=n.value;if(!r.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.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:r,init:s,update:i,extract:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let n=this.advance().value;if(n.startsWith("$"))return{type:"VarRef",name:n};if(this.match("LPAREN")){let r=[];if(!this.check("RPAREN"))for(r.push(this.parseExpr());this.match("SEMICOLON");)r.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:n,args:r}}return{type:"Call",name:n,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let e=[];if(!this.check("RBRACE"))do{let n,r;if(this.match("LPAREN"))n=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),r=this.parseObjectValue();else if(this.check("IDENT")){let s=this.advance().value;this.match("COLON")?(n=s,r=this.parseObjectValue()):(n=s,r={type:"Field",name:s})}else if(this.check("STRING"))n=this.advance().value,this.expect("COLON","Expected ':'"),r=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);e.push({key:n,value:r})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:e}}parseObjectValue(){let e=this.parseVarBind();for(;this.match("PIPE");){let n=this.parseVarBind();e={type:"Pipe",left:e,right:n}}return e}parseIf(){let e=this.parseExpr();this.expect("THEN","Expected 'then'");let n=this.parseExpr(),r=[];for(;this.match("ELIF");){let i=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let o=this.parseExpr();r.push({cond:i,then:o})}let s;return this.match("ELSE")&&(s=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:e,then:n,elifs:r,else:s}}parseStringInterpolation(e){let n=[],r="",s=0;for(;s<e.length;)if(e[s]==="\\"&&e[s+1]==="("){r&&(n.push(r),r=""),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=kc(o),l=new t(a);n.push(l.parse())}else r+=e[s],s++;return r&&n.push(r),{type:"StringInterp",parts:n}}}});var vc=C(()=>{"use strict";Ac();Ic()});var Rc={};M(Rc,{jqCommand:()=>Ug});function $c(t){let e=[],n=0,r=t.length;for(;n<r;){for(;n<r&&/\s/.test(t[n]);)n++;if(n>=r)break;let s=n,i=t[n];if(i==="{"||i==="["){let o=i,a=i==="{"?"}":"]",l=1,c=!1,u=!1;for(n++;n<r&&l>0;){let f=t[n];u?u=!1:f==="\\"?u=!0:f==='"'?c=!c:c||(f===o?l++:f===a&&l--),n++}if(l!==0)throw new Error(`Unexpected end of JSON input at position ${n} (unclosed ${o})`);e.push(JSON.parse(t.slice(s,n)))}else if(i==='"'){let o=!1;for(n++;n<r;){let a=t[n];if(o)o=!1;else if(a==="\\")o=!0;else if(a==='"'){n++;break}n++}e.push(JSON.parse(t.slice(s,n)))}else if(i==="-"||i>="0"&&i<="9"){for(;n<r&&/[\d.eE+-]/.test(t[n]);)n++;e.push(JSON.parse(t.slice(s,n)))}else if(t.slice(n,n+4)==="true")e.push(!0),n+=4;else if(t.slice(n,n+5)==="false")e.push(!1),n+=5;else if(t.slice(n,n+4)==="null")e.push(null),n+=4;else{let o=t.slice(n,n+10);throw new Error(`Invalid JSON at position ${s}: unexpected '${o.split(/\s/)[0]}'`)}}return e}function Pn(t,e,n,r,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 n?t:JSON.stringify(t);let o=s?" ":" ";if(Array.isArray(t))return t.length===0?"[]":e?`[${t.map(l=>Pn(l,!0,!1,r,s)).join(",")}]`:`[
|
|
496
496
|
${t.map(l=>o.repeat(i+1)+Pn(l,!1,!1,r,s,i+1)).join(`,
|
|
497
497
|
`)}
|
|
498
498
|
${o.repeat(i)}]`;if(typeof t=="object"){let a=Object.keys(t);return r&&(a=a.sort()),a.length===0?"{}":e?`{${a.map(c=>`${JSON.stringify(c)}:${Pn(t[c],!0,!1,r,s)}`).join(",")}}`:`{
|
|
499
499
|
${a.map(c=>{let u=Pn(t[c],!1,!1,r,s,i+1);return`${o.repeat(i+1)}${JSON.stringify(c)}: ${u}`}).join(`,
|
|
500
500
|
`)}
|
|
501
|
-
${o.repeat(i)}}`}return String(t)}var
|
|
501
|
+
${o.repeat(i)}}`}return String(t)}var Wg,Ug,Fc=C(()=>{"use strict";de();It();j();vc();Wg={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"]};Ug={name:"jq",async execute(t,e){if(I(t))return N(Wg);let n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=".",f=!1,d=[];for(let h=0;h<t.length;h++){let g=t[h];if(g==="-r"||g==="--raw-output")n=!0;else if(g==="-c"||g==="--compact-output")r=!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")l=!0;else if(!(g==="-C"||g==="--color")){if(!(g==="-M"||g==="--monochrome"))if(g==="--tab")c=!0;else if(g==="-")d.push("-");else{if(g.startsWith("--"))return L("jq",g);if(g.startsWith("-")){for(let m of g.slice(1))if(m==="r")n=!0;else if(m==="c")r=!0;else if(m==="e")s=!0;else if(m==="s")i=!0;else if(m==="n")o=!0;else if(m==="j")a=!0;else if(m!=="a"){if(m==="S")l=!0;else if(m!=="C"){if(m!=="M")return L("jq",`-${m}`)}}}else f?d.push(g):(u=g,f=!0)}}}}let p=[];if(!o)if(d.length===0||d.length===1&&d[0]==="-")p.push({source:"stdin",content:e.stdin});else{let h=await Nt(e,d,{cmdName:"jq",stopOnError:!0});if(h.exitCode!==0)return{stdout:"",stderr:h.stderr,exitCode:2};p=h.files.map(g=>({source:g.filename||"stdin",content:g.content}))}try{let h=Nc(u),g=[],m={limits:e.limits?{maxIterations:e.limits.maxJqIterations}:void 0,env:e.env};if(o)g=k(null,h,m);else if(i){let v=[];for(let{content:F}of p){let W=F.trim();W&&v.push(...$c(W))}g=k(v,h,m)}else for(let{content:v}of p){let F=v.trim();if(!F)continue;let W=$c(F);for(let z of W)g.push(...k(z,h,m))}let w=g.map(v=>Pn(v,r,n,l,c)),b=a?"":`
|
|
502
502
|
`,E=w.join(b),S=s&&(g.length===0||g.every(v=>v==null||v===!1))?1:0;return{stdout:E?a?E:`${E}
|
|
503
503
|
`:"",stderr:"",exitCode:S}}catch(h){if(h instanceof Q)return{stdout:"",stderr:`jq: ${h.message}
|
|
504
504
|
`,exitCode:Q.EXIT_CODE};let g=h.message;return g.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${g}
|
|
505
505
|
`,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${g}
|
|
506
|
-
`,exitCode:5}}}}});var Tc={};M(Tc,{base64Command:()=>
|
|
507
|
-
`,exitCode:1}}}}let s=r.reduce((a,l)=>a+l.length,0),i=new Uint8Array(s),o=0;for(let a of r)i.set(a,o),o+=a.length;return{ok:!0,data:i}}var
|
|
506
|
+
`,exitCode:5}}}}});var Tc={};M(Tc,{base64Command:()=>Hg});async function Pc(t,e,n){if(e.length===0||e.length===1&&e[0]==="-")return{ok:!0,data:Uint8Array.from(t.stdin,a=>a.charCodeAt(0))};let r=[];for(let a of e){if(a==="-"){r.push(Uint8Array.from(t.stdin,l=>l.charCodeAt(0)));continue}try{let l=t.fs.resolvePath(t.cwd,a),c=await t.fs.readFileBuffer(l);r.push(c)}catch{return{ok:!1,error:{stdout:"",stderr:`${n}: ${a}: No such file or directory
|
|
507
|
+
`,exitCode:1}}}}let s=r.reduce((a,l)=>a+l.length,0),i=new Uint8Array(s),o=0;for(let a of r)i.set(a,o),o+=a.length;return{ok:!0,data:i}}var jg,zg,Hg,Oc=C(()=>{"use strict";Ae();j();jg={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"]},zg={decode:{short:"d",long:"decode",type:"boolean"},wrap:{short:"w",long:"wrap",type:"number",default:76}};Hg={name:"base64",async execute(t,e){if(I(t))return N(jg);let n=J("base64",t,zg);if(!n.ok)return n.error;let r=n.result.flags.decode,s=n.result.flags.wrap,i=n.result.positional;try{if(r){let l=await Pc(e,i,"base64");if(!l.ok)return l.error;let u=String.fromCharCode(...l.data).replace(/\s/g,"");return{stdout:atob(u),stderr:"",exitCode:0}}let o=await Pc(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(`
|
|
508
508
|
`)+(a.length>0?`
|
|
509
509
|
`:"")}return{stdout:a,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`base64: invalid input
|
|
510
|
-
`,exitCode:1}}}}});var Lc={};M(Lc,{diffCommand:()=>
|
|
510
|
+
`,exitCode:1}}}}});var Lc={};M(Lc,{diffCommand:()=>Vg});import*as Dc from"diff";var Gg,qg,Vg,Mc=C(()=>{"use strict";Ae();j();Gg={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"]},qg={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"}},Vg={name:"diff",async execute(t,e){if(I(t))return N(Gg);let n=J("diff",t,qg);if(!n.ok)return n.error;let r=n.result.flags.brief,s=n.result.flags.reportSame,i=n.result.flags.ignoreCase,o=n.result.positional;if(n.result.flags.unified,o.length<2)return{stdout:"",stderr:`diff: missing operand
|
|
511
511
|
`,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
|
|
512
512
|
`,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
|
|
513
513
|
`,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
|
|
514
514
|
`,stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0}:r?{stdout:`Files ${c} and ${u} differ
|
|
515
|
-
`,stderr:"",exitCode:1}:{stdout:Dc.createTwoFilesPatch(c,u,a,l,"","",{context:3}),stderr:"",exitCode:1}}}});var _c={};M(_c,{dateCommand:()=>
|
|
516
|
-
`;break;case"p":s+=r.H<12?"AM":"PM";break;case"P":s+=r.H<12?"am":"pm";break;case"R":s+=`${Oe(r.H)}:${Oe(r.M)}`;break;case"s":s+=Math.floor(t.getTime()/1e3);break;case"S":s+=Oe(r.S);break;case"t":s+=" ";break;case"T":s+=`${Oe(r.H)}:${Oe(r.M)}:${Oe(r.S)}`;break;case"u":s+=r.w||7;break;case"w":s+=r.w;break;case"y":s+=Oe(r.Y%100);break;case"Y":s+=r.Y;break;case"z":s+=n?"+0000":
|
|
515
|
+
`,stderr:"",exitCode:1}:{stdout:Dc.createTwoFilesPatch(c,u,a,l,"","",{context:3}),stderr:"",exitCode:1}}}});var _c={};M(_c,{dateCommand:()=>Yg});function Oe(t,e=2){return String(t).padStart(e,"0")}function Xg(t){let e=-t.getTimezoneOffset();return`${e>=0?"+":"-"}${Oe(Math.floor(Math.abs(e)/60))}${Oe(Math.abs(e)%60)}`}function xr(t,e,n){let r=n?{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+=Kg[r.w];break;case"b":case"h":s+=Qg[r.m];break;case"d":s+=Oe(r.D);break;case"e":s+=String(r.D).padStart(2," ");break;case"F":s+=`${r.Y}-${Oe(r.m+1)}-${Oe(r.D)}`;break;case"H":s+=Oe(r.H);break;case"I":s+=Oe(r.H%12||12);break;case"m":s+=Oe(r.m+1);break;case"M":s+=Oe(r.M);break;case"n":s+=`
|
|
516
|
+
`;break;case"p":s+=r.H<12?"AM":"PM";break;case"P":s+=r.H<12?"am":"pm";break;case"R":s+=`${Oe(r.H)}:${Oe(r.M)}`;break;case"s":s+=Math.floor(t.getTime()/1e3);break;case"S":s+=Oe(r.S);break;case"t":s+=" ";break;case"T":s+=`${Oe(r.H)}:${Oe(r.M)}:${Oe(r.S)}`;break;case"u":s+=r.w||7;break;case"w":s+=r.w;break;case"y":s+=Oe(r.Y%100);break;case"Y":s+=r.Y;break;case"z":s+=n?"+0000":Xg(t);break;case"Z":s+=n?"UTC":Intl.DateTimeFormat().resolvedOptions().timeZone;break;default:s+=`%${o}`}}else s+=e[i];i++}return s}function Jg(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 n=t.toLowerCase();return n==="now"||n==="today"?new Date:n==="yesterday"?new Date(Date.now()-864e5):n==="tomorrow"?new Date(Date.now()+864e5):null}var Zg,Kg,Qg,Yg,Bc=C(()=>{"use strict";j();Zg={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"]},Kg=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Qg=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];Yg={name:"date",async execute(t,e){if(I(t))return N(Zg);let n=!1,r=null,s=null,i=!1,o=!1;for(let c=0;c<t.length;c++){let u=t[c];if(u==="-u"||u==="--utc")n=!0;else if(u==="-d"||u==="--date")r=t[++c]??"";else if(u.startsWith("--date="))r=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")n=!0;else if(f==="I")i=!0;else if(f==="R")o=!0;else return L("date",`-${f}`)}}let a=r!==null?Jg(r):new Date;if(!a)return{stdout:"",stderr:`date: invalid date '${r}'
|
|
517
517
|
`,exitCode:1};let l;return s?l=xr(a,s,n):i?l=xr(a,"%Y-%m-%dT%H:%M:%S%z",n):o?l=xr(a,"%a, %d %b %Y %H:%M:%S %z",n):l=xr(a,"%a %b %e %H:%M:%S %Z %Y",n),{stdout:`${l}
|
|
518
|
-
`,stderr:"",exitCode:0}}}});var Wc={};M(Wc,{sleepCommand:()=>
|
|
518
|
+
`,stderr:"",exitCode:0}}}});var Wc={};M(Wc,{sleepCommand:()=>ny});function ty(t){let e=t.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!e)return null;let n=parseFloat(e[1]);switch(e[2]||"s"){case"s":return n*1e3;case"m":return n*60*1e3;case"h":return n*60*60*1e3;case"d":return n*24*60*60*1e3;default:return null}}var ey,ny,Uc=C(()=>{"use strict";j();ey={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
519
519
|
s - seconds (default)
|
|
520
520
|
m - minutes
|
|
521
521
|
h - hours
|
|
522
522
|
d - days
|
|
523
523
|
|
|
524
|
-
NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};
|
|
525
|
-
`,exitCode:1};let n=0;for(let r of t){let s=
|
|
526
|
-
`,exitCode:1};n+=s}return e.sleep?await e.sleep(n):await new Promise(r=>setTimeout(r,n)),{stdout:"",stderr:"",exitCode:0}}}});var jc={};M(jc,{timeoutCommand:()=>
|
|
524
|
+
NUMBER may be a decimal number.`,options:[" --help display this help and exit"]};ny={name:"sleep",async execute(t,e){if(I(t))return N(ey);if(t.length===0)return{stdout:"",stderr:`sleep: missing operand
|
|
525
|
+
`,exitCode:1};let n=0;for(let r of t){let s=ty(r);if(s===null)return{stdout:"",stderr:`sleep: invalid time interval '${r}'
|
|
526
|
+
`,exitCode:1};n+=s}return e.sleep?await e.sleep(n):await new Promise(r=>setTimeout(r,n)),{stdout:"",stderr:"",exitCode:0}}}});var jc={};M(jc,{timeoutCommand:()=>iy});function sy(t){let e=t.match(/^(\d+\.?\d*)(s|m|h|d)?$/);if(!e)return null;let n=parseFloat(e[1]);switch(e[2]||"s"){case"s":return n*1e3;case"m":return n*60*1e3;case"h":return n*60*60*1e3;case"d":return n*24*60*60*1e3;default:return null}}var ry,iy,zc=C(()=>{"use strict";j();ry={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.
|
|
527
527
|
|
|
528
528
|
DURATION is a number with optional suffix:
|
|
529
529
|
s - seconds (default)
|
|
530
530
|
m - minutes
|
|
531
531
|
h - hours
|
|
532
|
-
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"]};
|
|
533
|
-
`,exitCode:1};let i=s[0],o=
|
|
532
|
+
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"]};iy={name:"timeout",async execute(t,e){if(I(t))return N(ry);let n=!1,r=0;for(let d=0;d<t.length;d++){let p=t[d];if(p==="--preserve-status")n=!0,r=d+1;else if(p==="--foreground")r=d+1;else if(p==="-k"||p==="--kill-after")d++,r=d+1;else if(p.startsWith("--kill-after="))r=d+1;else if(p==="-s"||p==="--signal")d++,r=d+1;else if(p.startsWith("--signal="))r=d+1;else{if(p.startsWith("--")&&p!=="--")return L("timeout",p);if(p.startsWith("-")&&p.length>1&&p!=="--")if(p.startsWith("-k"))r=d+1;else if(p.startsWith("-s"))r=d+1;else return L("timeout",p);else{r=d;break}}}let s=t.slice(r);if(s.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
533
|
+
`,exitCode:1};let i=s[0],o=sy(i);if(o===null)return{stdout:"",stderr:`timeout: invalid time interval '${i}'
|
|
534
534
|
`,exitCode:1};let a=s.slice(1);if(a.length===0)return{stdout:"",stderr:`timeout: missing operand
|
|
535
535
|
`,exitCode:1};if(!e.exec)return{stdout:"",stderr:`timeout: exec not available
|
|
536
|
-
`,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 Hc={};M(Hc,{seqCommand:()=>
|
|
536
|
+
`,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 Hc={};M(Hc,{seqCommand:()=>oy});var oy,Gc=C(()=>{"use strict";oy={name:"seq",async execute(t){let e=`
|
|
537
537
|
`,n=!1,r=[],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"){n=!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")&&(n=!0,s+1<t.length)){e=t[s+1],s+=2;continue}}r.push(h),s++}for(;s<t.length;)r.push(t[s]),s++;if(r.length===0)return{stdout:"",stderr:`seq: missing operand
|
|
538
538
|
`,exitCode:1};let i=1,o=1,a;if(r.length===1?a=parseFloat(r[0]):r.length===2?(i=parseFloat(r[0]),a=parseFloat(r[1])):(i=parseFloat(r[0]),o=parseFloat(r[1]),a=parseFloat(r[2])),Number.isNaN(i)||Number.isNaN(o)||Number.isNaN(a))return{stdout:"",stderr:`seq: invalid floating point argument: '${r.find(g=>Number.isNaN(parseFloat(g)))}'
|
|
539
539
|
`,exitCode:1};if(o===0)return{stdout:"",stderr:`seq: invalid Zero increment value: '0'
|
|
540
540
|
`,exitCode:1};let l=[],c=h=>{let g=String(h),m=g.indexOf(".");return m===-1?0:g.length-m-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(n&&l.length>0){let h=Math.max(...l.map(g=>g.replace("-","").length));for(let g=0;g<l.length;g++){let m=l[g].startsWith("-"),b=(m?l[g].slice(1):l[g]).padStart(h,"0");l[g]=m?`-${b}`:b}}let p=l.join(e);return{stdout:p?`${p}
|
|
541
|
-
`:"",stderr:"",exitCode:0}}}});var qc={};M(qc,{exprCommand:()=>
|
|
542
|
-
`,exitCode:2};try{let n=
|
|
541
|
+
`:"",stderr:"",exitCode:0}}}});var qc={};M(qc,{exprCommand:()=>ay});function ly(t){if(t.length===1)return t[0];let e=0;function n(){let c=r();for(;e<t.length&&t[e]==="|";){e++;let u=r();if(c!=="0"&&c!=="")return c;c=u}return c}function r(){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),g;u==="="?g=h?d===p:c===f:u==="!="?g=h?d!==p:c!==f:u==="<"?g=h?d<p:c<f:u===">"?g=h?d>p:c>f:u==="<="?g=h?d<=p:c<=f:g=h?d>=p:c>=f,c=g?"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=n();if(e>=t.length||t[e]!==")")throw new Error("syntax error");return e++,u}return e++,c}return n()}var ay,Vc=C(()=>{"use strict";ay={name:"expr",async execute(t,e){if(t.length===0)return{stdout:"",stderr:`expr: missing operand
|
|
542
|
+
`,exitCode:2};try{let n=ly(t),r=n==="0"||n===""?1:0;return{stdout:`${n}
|
|
543
543
|
`,stderr:"",exitCode:r}}catch(n){return{stdout:"",stderr:`expr: ${n.message}
|
|
544
|
-
`,exitCode:2}}}}});function
|
|
544
|
+
`,exitCode:2}}}}});function uy(t){function e(p,h){return p<<h|p>>>32-h}let n=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]),r=[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 E=0;E<16;E++)h[E]=a.getUint32(p+E*4,!0);let g=l,m=c,w=u,b=f;for(let E=0;E<64;E++){let S,v;E<16?(S=m&w|~m&b,v=E):E<32?(S=b&m|~b&w,v=(5*E+1)%16):E<48?(S=m^w^b,v=(3*E+5)%16):(S=w^(m|~b),v=7*E%16),S=S+g+n[E]+h[v]>>>0,g=b,b=w,w=m,m=m+e(S,r[E])>>>0}l=l+g>>>0,c=c+m>>>0,u=u+w>>>0,f=f+b>>>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 Zc(t,e){if(t==="md5")return uy(e);let n=await globalThis.crypto.subtle.digest(cy[t],new Uint8Array(e).buffer);return Array.from(new Uint8Array(n)).map(r=>r.toString(16).padStart(2,"0")).join("")}function rn(t,e,n){let r={name:t,summary:n,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(r);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 l=async f=>{if(f==="-")return Uint8Array.from(i.stdin,d=>d.charCodeAt(0));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
|
|
545
545
|
`,exitCode:1};for(let g of h.split(`
|
|
546
546
|
`)){let m=g.match(/^([a-fA-F0-9]+)\s+[* ]?(.+)$/);if(!m)continue;let[,w,b]=m,E=await l(b);if(E===null){d+=`${b}: FAILED open or read
|
|
547
547
|
`,f++;continue}let S=await Zc(e,E)===w.toLowerCase();d+=`${b}: ${S?"OK":"FAILED"}
|
|
548
548
|
`,S||f++}}return f>0&&(d+=`${t}: WARNING: ${f} computed checksum${f>1?"s":""} did NOT match
|
|
549
549
|
`),{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
|
|
550
550
|
`,u=1;continue}c+=`${await Zc(e,d)} ${f}
|
|
551
|
-
`}return{stdout:c,stderr:"",exitCode:u}}}}var ry,wr=C(()=>{"use strict";j();ry={sha1:"SHA-1",sha256:"SHA-256"}});var Kc={};M(Kc,{md5sumCommand:()=>iy});var iy,Qc=C(()=>{"use strict";wr();iy=rn("md5sum","md5","compute MD5 message digest")});var Xc={};M(Xc,{sha1sumCommand:()=>oy});var oy,Jc=C(()=>{"use strict";wr();oy=rn("sha1sum","sha1","compute SHA1 message digest")});var Yc={};M(Yc,{sha256sumCommand:()=>ay});var ay,eu=C(()=>{"use strict";wr();ay=rn("sha256sum","sha256","compute SHA256 message digest")});var tu=Zn(qs=>{qs.read=function(t,e,n,r,s){var i,o,a=s*8-r-1,l=(1<<a)-1,c=l>>1,u=-7,f=n?s-1:0,d=n?-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+=r;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,r),i=i-c}return(p?-1:1)*o*Math.pow(2,i-r)};qs.write=function(t,e,n,r,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=r?0:i-1,h=r?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*(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[n+p]=a&255,p+=h,a/=256,s-=8);for(o=o<<s|a,c+=s;c>0;t[n+p]=o&255,p+=h,o/=256,c-=8);t[n+p-h]|=g*128}});function nu(t,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":return typeof globalThis.TextDecoder<"u"?new globalThis.TextDecoder("utf-8").decode(t):cy(t);case"utf-16le":return uy(t);case"ascii":return fy(t);case"latin1":case"iso-8859-1":return dy(t);case"windows-1252":return py(t);default:throw new RangeError(`Encoding '${e}' not supported`)}}function cy(t){let e="",n=0;for(;n<t.length;){let r=t[n++];if(r<128)e+=String.fromCharCode(r);else if(r<224){let s=t[n++]&63;e+=String.fromCharCode((r&31)<<6|s)}else if(r<240){let s=t[n++]&63,i=t[n++]&63;e+=String.fromCharCode((r&15)<<12|s<<6|i)}else{let s=t[n++]&63,i=t[n++]&63,o=t[n++]&63,a=(r&7)<<18|s<<12|i<<6|o;a-=65536,e+=String.fromCharCode(55296+(a>>10&1023),56320+(a&1023))}}return e}function uy(t){let e="";for(let n=0;n<t.length;n+=2)e+=String.fromCharCode(t[n]|t[n+1]<<8);return e}function fy(t){return String.fromCharCode(...t.map(e=>e&127))}function dy(t){return String.fromCharCode(...t)}function py(t){let e="";for(let n of t)n>=128&&n<=159&&Vs[n]?e+=Vs[n]:e+=String.fromCharCode(n);return e}var Vs,ly,ru=C(()=>{Vs={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"},ly={};for(let[t,e]of Object.entries(Vs))ly[e]=Number.parseInt(t)});function Be(t){return new DataView(t.buffer,t.byteOffset)}var su,iu,ge,sn,be,ou,au,lu,We,Tn=C(()=>{su=lo(tu(),1);ru();iu={len:1,get(t,e){return Be(t).getUint8(e)},put(t,e,n){return Be(t).setUint8(e,n),e+1}},ge={len:2,get(t,e){return Be(t).getUint16(e,!0)},put(t,e,n){return Be(t).setUint16(e,n,!0),e+2}},sn={len:2,get(t,e){return Be(t).getUint16(e)},put(t,e,n){return Be(t).setUint16(e,n),e+2}},be={len:4,get(t,e){return Be(t).getUint32(e,!0)},put(t,e,n){return Be(t).setUint32(e,n,!0),e+4}},ou={len:4,get(t,e){return Be(t).getUint32(e)},put(t,e,n){return Be(t).setUint32(e,n),e+4}},au={len:4,get(t,e){return Be(t).getInt32(e)},put(t,e,n){return Be(t).setInt32(e,n),e+4}},lu={len:8,get(t,e){return Be(t).getBigUint64(e,!0)},put(t,e,n){return Be(t).setBigUint64(e,n,!0),e+8}},We=class{constructor(e,n){this.len=e,this.encoding=n}get(e,n=0){let r=e.subarray(n,n+this.len);return nu(r,this.encoding)}}});var my,pe,Ot,On=C(()=>{my="End-Of-Stream",pe=class extends Error{constructor(){super(my),this.name="EndOfStreamError"}},Ot=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}}});var cu=C(()=>{});var Dt,br=C(()=>{On();Dt=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,n=!1){let r=await this.read(e,n);return this.peekQueue.push(e.subarray(0,r)),r}async read(e,n=!1){if(e.length===0)return 0;let r=this.readFromPeekBuffer(e);if(this.endOfStream||(r+=await this.readRemainderFromStream(e.subarray(r),n)),r===0&&!n)throw new pe;return r}readFromPeekBuffer(e){let n=e.length,r=0;for(;this.peekQueue.length>0&&n>0;){let s=this.peekQueue.pop();if(!s)throw new Error("peekData should be defined");let i=Math.min(s.length,n);e.set(s.subarray(0,i),r),r+=i,n-=i,i<s.length&&this.peekQueue.push(s.subarray(i))}return r}async readRemainderFromStream(e,n){let r=0;for(;r<e.length&&!this.endOfStream;){if(this.interrupted)throw new Ot;let s=await this.readFromStream(e.subarray(r),n);if(s===0)break;r+=s}if(!n&&r<e.length)throw new pe;return r}}});var uu=C(()=>{On();cu();br()});var Er,fu=C(()=>{br();Er=class extends Dt{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}}});var Dn,Zs=C(()=>{fu();Dn=class extends Er{async readFromStream(e,n){if(e.length===0)return 0;let r=await this.reader.read(new Uint8Array(e.length),{min:n?void 0:e.length});return r.done&&(this.endOfStream=r.done),r.value?(e.set(r.value),r.value.length):0}}});var on,Ks=C(()=>{On();br();on=class extends Dt{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,n){let r=Math.min(n.length,e.length);return e.set(n.subarray(0,r)),r<n.length?this.buffer=n.subarray(r):this.buffer=null,r}async readFromStream(e,n){if(e.length===0)return 0;let r=0;for(this.buffer&&(r+=this.writeChunk(e,this.buffer));r<e.length&&!this.endOfStream;){let s=await this.reader.read();if(s.done){this.endOfStream=!0;break}s.value&&(r+=this.writeChunk(e.subarray(r),s.value))}if(!n&&r===0&&this.endOfStream)throw new pe;return r}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}}});function Qs(t){try{let e=t.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new on(e):new Dn(e)}catch(e){if(e instanceof TypeError)return new on(t.getReader());throw e}}var du=C(()=>{Zs();Ks()});var Lt=C(()=>{On();uu();Zs();Ks();du()});var ft,Ln=C(()=>{Lt();ft=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,n=this.position){let r=new Uint8Array(e.len);if(await this.readBuffer(r,{position:n})<e.len)throw new pe;return e.get(r,0)}async peekToken(e,n=this.position){let r=new Uint8Array(e.len);if(await this.peekBuffer(r,{position:n})<e.len)throw new pe;return e.get(r,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new pe;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new pe;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let n=this.fileInfo.size-this.position;if(e>n)return this.position+=n,n}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,n){if(!this.supportsRandomAccess()&&n&&n.position!==void 0&&n.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,...n}}abort(){return Promise.resolve()}}});var yy,Sr,pu=C(()=>{Ln();Lt();yy=256e3,Sr=class extends ft{constructor(e,n){super(n),this.streamReader=e,this.fileInfo=n?.fileInfo??{}}async readBuffer(e,n){let r=this.normalizeOptions(e,n),s=r.position-this.position;if(s>0)return await this.ignore(s),this.readBuffer(e,n);if(s<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(r.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,r.length),r.mayBeLess);if(this.position+=i,(!n||!n.mayBeLess)&&i<r.length)throw new pe;return i}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=0;if(r.position){let i=r.position-this.position;if(i>0){let o=new Uint8Array(r.length+i);return s=await this.peekBuffer(o,{mayBeLess:r.mayBeLess}),e.set(o.subarray(i)),s-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(r.length>0){try{s=await this.streamReader.peek(e.subarray(0,r.length),r.mayBeLess)}catch(i){if(n?.mayBeLess&&i instanceof pe)return 0;throw i}if(!r.mayBeLess&&s<r.length)throw new pe}return s}async ignore(e){let n=Math.min(yy,e),r=new Uint8Array(n),s=0;for(;s<e;){let i=e-s,o=await this.readBuffer(r,{length:Math.min(n,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 Cr,hu=C(()=>{Lt();Ln();Cr=class extends ft{constructor(e,n){super(n),this.uint8Array=e,this.fileInfo={...n?.fileInfo??{},size:e.length}}async readBuffer(e,n){n?.position&&(this.position=n.position);let r=await this.peekBuffer(e,n);return this.position+=r,r}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=Math.min(this.uint8Array.length-r.position,r.length);if(!r.mayBeLess&&s<r.length)throw new pe;return e.set(this.uint8Array.subarray(r.position,r.position+s)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});var Ar,mu=C(()=>{Lt();Ln();Ar=class extends ft{constructor(e,n){super(n),this.blob=e,this.fileInfo={...n?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,n){n?.position&&(this.position=n.position);let r=await this.peekBuffer(e,n);return this.position+=r,r}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=Math.min(this.blob.size-r.position,r.length);if(!r.mayBeLess&&s<r.length)throw new pe;let i=await this.blob.slice(r.position,r.position+s).arrayBuffer();return e.set(new Uint8Array(i)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});function gu(t,e){let n=Qs(t),r=e??{},s=r.onClose;return r.onClose=async()=>{if(await n.close(),s)return s()},new Sr(n,r)}function yu(t,e){return new Cr(t,e)}function xu(t,e){return new Ar(t,e)}var wu=C(()=>{Lt();pu();hu();mu();Lt();Ln()});var Eu=Zn((XS,bu)=>{var an=1e3,ln=an*60,cn=ln*60,Mt=cn*24,wy=Mt*7,by=Mt*365.25;bu.exports=function(t,e){e=e||{};var n=typeof t;if(n==="string"&&t.length>0)return Ey(t);if(n==="number"&&isFinite(t))return e.long?Cy(t):Sy(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Ey(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 n=parseFloat(e[1]),r=(e[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*by;case"weeks":case"week":case"w":return n*wy;case"days":case"day":case"d":return n*Mt;case"hours":case"hour":case"hrs":case"hr":case"h":return n*cn;case"minutes":case"minute":case"mins":case"min":case"m":return n*ln;case"seconds":case"second":case"secs":case"sec":case"s":return n*an;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function Sy(t){var e=Math.abs(t);return e>=Mt?Math.round(t/Mt)+"d":e>=cn?Math.round(t/cn)+"h":e>=ln?Math.round(t/ln)+"m":e>=an?Math.round(t/an)+"s":t+"ms"}function Cy(t){var e=Math.abs(t);return e>=Mt?kr(t,e,Mt,"day"):e>=cn?kr(t,e,cn,"hour"):e>=ln?kr(t,e,ln,"minute"):e>=an?kr(t,e,an,"second"):t+" ms"}function kr(t,e,n,r){var s=e>=n*1.5;return Math.round(t/n)+" "+r+(s?"s":"")}});var Cu=Zn((JS,Su)=>{function Ay(t){n.debug=n,n.default=n,n.coerce=l,n.disable=o,n.enable=s,n.enabled=a,n.humanize=Eu(),n.destroy=c,Object.keys(t).forEach(u=>{n[u]=t[u]}),n.names=[],n.skips=[],n.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 n.colors[Math.abs(f)%n.colors.length]}n.selectColor=e;function n(u){let f,d=null,p,h;function g(...m){if(!g.enabled)return;let w=g,b=Number(new Date),E=b-(f||b);w.diff=E,w.prev=f,w.curr=b,f=b,m[0]=n.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let S=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(F,W)=>{if(F==="%%")return"%";S++;let z=n.formatters[W];if(typeof z=="function"){let X=m[S];F=z.call(w,X),m.splice(S,1),S--}return F}),n.formatArgs.call(w,m),(w.log||n.log).apply(w,m)}return g.namespace=u,g.useColors=n.useColors(),g.color=n.selectColor(u),g.extend=r,g.destroy=n.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(p!==n.namespaces&&(p=n.namespaces,h=n.enabled(u)),h),set:m=>{d=m}}),typeof n.init=="function"&&n.init(g),g}function r(u,f){let d=n(this.namespace+(typeof f>"u"?":":f)+u);return d.log=this.log,d}function s(u){n.save(u),n.namespaces=u,n.names=[],n.skips=[];let f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let d of f)d[0]==="-"?n.skips.push(d.slice(1)):n.names.push(d)}function i(u,f){let d=0,p=0,h=-1,g=0;for(;d<u.length;)if(p<f.length&&(f[p]===u[d]||f[p]==="*"))f[p]==="*"?(h=p,g=d,p++):(d++,p++);else if(h!==-1)p=h+1,g++,d=g;else return!1;for(;p<f.length&&f[p]==="*";)p++;return p===f.length}function o(){let u=[...n.names,...n.skips.map(f=>"-"+f)].join(",");return n.enable(""),u}function a(u){for(let f of n.skips)if(i(u,f))return!1;for(let f of n.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 n.enable(n.load()),n}Su.exports=Ay});var Au=Zn((Ue,Nr)=>{Ue.formatArgs=Ny;Ue.save=Iy;Ue.load=vy;Ue.useColors=ky;Ue.storage=$y();Ue.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`."))}})();Ue.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 ky(){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 Ny(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Nr.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let n=0,r=0;t[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(n++,s==="%c"&&(r=n))}),t.splice(r,0,e)}Ue.log=console.debug||console.log||(()=>{});function Iy(t){try{t?Ue.storage.setItem("debug",t):Ue.storage.removeItem("debug")}catch{}}function vy(){let t;try{t=Ue.storage.getItem("debug")||Ue.storage.getItem("DEBUG")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function $y(){try{return localStorage}catch{}}Nr.exports=Cu()(Ue);var{formatters:Ry}=Nr.exports;Ry.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var _t,Xs,ku,Nu,Iu,vu=C(()=>{Tn();_t={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},Xs={get(t){return{signature:be.get(t,0),compressedSize:be.get(t,8),uncompressedSize:be.get(t,12)}},len:16},ku={get(t){let e=ge.get(t,6);return{signature:be.get(t,0),minVersion:ge.get(t,4),dataDescriptor:!!(e&8),compressedMethod:ge.get(t,8),compressedSize:be.get(t,18),uncompressedSize:be.get(t,22),filenameLength:ge.get(t,26),extraFieldLength:ge.get(t,28),filename:null}},len:30},Nu={get(t){return{signature:be.get(t,0),nrOfThisDisk:ge.get(t,4),nrOfThisDiskWithTheStart:ge.get(t,6),nrOfEntriesOnThisDisk:ge.get(t,8),nrOfEntriesOfSize:ge.get(t,10),sizeOfCd:be.get(t,12),offsetOfStartOfCd:be.get(t,16),zipFileCommentLength:ge.get(t,20)}},len:22},Iu={get(t){let e=ge.get(t,8);return{signature:be.get(t,0),minVersion:ge.get(t,6),dataDescriptor:!!(e&8),compressedMethod:ge.get(t,10),compressedSize:be.get(t,20),uncompressedSize:be.get(t,24),filenameLength:ge.get(t,28),extraFieldLength:ge.get(t,30),fileCommentLength:ge.get(t,32),relativeOffsetOfLocalHeader:be.get(t,42),filename:null}},len:46}});function Ru(t){let e=new Uint8Array(be.len);return be.put(e,0,t),e}function Py(t,e){let n=t.length,r=e.length;if(r>n)return-1;for(let s=0;s<=n-r;s++){let i=!0;for(let o=0;o<r;o++)if(t[s+o]!==e[o]){i=!1;break}if(i)return s}return-1}function Ty(t){let e=t.reduce((s,i)=>s+i.length,0),n=new Uint8Array(e),r=0;for(let s of t)n.set(s,r),r+=s.length;return n}var $u,lt,Js,Fy,Ir,Mn,Fu=C(()=>{Tn();$u=lo(Au(),1);vu();lt=(0,$u.default)("tokenizer:inflate"),Js=256*1024,Fy=Ru(_t.DataDescriptor),Ir=Ru(_t.EndOfCentralDirectory),Mn=class t{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(Js)}async isZip(){return await this.peekSignature()===_t.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(be)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,n=Math.min(16*1024,e.fileInfo.size),r=this.syncBuffer.subarray(0,n);await this.tokenizer.readBuffer(r,{position:e.fileInfo.size-n});for(let s=r.length-4;s>=0;s--)if(r[s]===Ir[0]&&r[s+1]===Ir[1]&&r[s+2]===Ir[2]&&r[s+3]===Ir[3])return e.fileInfo.size-n+s;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){lt("Cannot reading central-directory without random-read support");return}lt("Reading central-directory...");let e=this.tokenizer.position,n=await this.findEndOfCentralDirectoryLocator();if(n>0){lt("Central-directory 32-bit signature found");let r=await this.tokenizer.readToken(Nu,n),s=[];this.tokenizer.setPosition(r.offsetOfStartOfCd);for(let i=0;i<r.nrOfEntriesOfSize;++i){let o=await this.tokenizer.readToken(Iu);if(o.signature!==_t.CentralFileHeader)throw new Error("Expected Central-File-Header signature");o.filename=await this.tokenizer.readToken(new We(o.filenameLength,"utf-8")),await this.tokenizer.ignore(o.extraFieldLength),await this.tokenizer.ignore(o.fileCommentLength),s.push(o),lt(`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 n=await this.readCentralDirectory();if(n)return this.iterateOverCentralDirectory(n,e);let r=!1;do{let s=await this.readLocalFileHeader();if(!s)break;let i=e(s);r=!!i.stop;let o;if(await this.tokenizer.ignore(s.extraFieldLength),s.dataDescriptor&&s.compressedSize===0){let a=[],l=Js;lt("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let c=-1;for(;c<0&&l===Js;){l=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),c=Py(this.syncBuffer.subarray(0,l),Fy);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)}lt(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(s,Ty(a),i.handler)}else i.handler?(lt(`Reading compressed-file-data: ${s.compressedSize} bytes`),o=new Uint8Array(s.compressedSize),await this.tokenizer.readBuffer(o),await this.inflate(s,o,i.handler)):(lt(`Ignoring compressed-file-data: ${s.compressedSize} bytes`),await this.tokenizer.ignore(s.compressedSize));if(lt(`Reading data-descriptor at pos=${this.tokenizer.position}`),s.dataDescriptor&&(await this.tokenizer.readToken(Xs)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-Xs.len}`)}while(!r)}async iterateOverCentralDirectory(e,n){for(let r of e){let s=n(r);if(s.handler){this.tokenizer.setPosition(r.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let o=new Uint8Array(r.compressedSize);await this.tokenizer.readBuffer(o),await this.inflate(i,o,s.handler)}}if(s.stop)break}}async inflate(e,n,r){if(e.compressedMethod===0)return r(n);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);lt(`Decompress filename=${e.filename}, compressed-size=${n.length}`);let s=await t.decompressDeflateRaw(n);return r(s)}static async decompressDeflateRaw(e){let n=new ReadableStream({start(i){i.enqueue(e),i.close()}}),r=new DecompressionStream("deflate-raw"),s=n.pipeThrough(r);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(be);if(e===_t.LocalFileHeader){let n=await this.tokenizer.readToken(ku);return n.filename=await this.tokenizer.readToken(new We(n.filenameLength,"utf-8")),n}if(e===_t.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}}});var _n,Pu=C(()=>{_n=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(n){let r=new Uint8Array(1024),s=await e.readBuffer(r,{mayBeLess:!0});if(s===0){n.close();return}n.enqueue(r.subarray(0,s))}}).pipeThrough(new DecompressionStream("gzip"))}}});var Tu=C(()=>{Fu();Pu()});function Ys(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 lC,cC,uC,Ou=C(()=>{lC={utf8:new globalThis.TextDecoder("utf8")},cC=new globalThis.TextEncoder,uC=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"))});function Du(t,e){if(e==="utf-16le"){let n=[];for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);n.push(s&255,s>>8&255)}return n}if(e==="utf-16be"){let n=[];for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);n.push(s>>8&255,s&255)}return n}return[...t].map(n=>n.charCodeAt(0))}function Lu(t,e=0){let n=Number.parseInt(new We(6).get(t,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(n))return!1;let r=256;for(let s=e;s<e+148;s++)r+=t[s];for(let s=e+156;s<e+512;s++)r+=t[s];return n===r}var Mu,_u=C(()=>{Tn();Mu={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4}});var Bu,Wu,Uu=C(()=>{Bu=["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"],Wu=["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 ju(t,e){return new ni(e).fromBuffer(t)}function ti(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 ct(t,e,n){n={offset:0,...n};for(let[r,s]of e.entries())if(n.mask){if(s!==(n.mask[r]&t[r+n.offset]))return!1}else if(s!==t[r+n.offset])return!1;return!0}var ei,ni,wC,bC,zu=C(()=>{Tn();wu();Tu();Ou();_u();Uu();ei=4100;ni=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 n=e.position;for(let r of this.detectors){let s=await r.detect(e);if(s)return s;if(n!==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 n=e instanceof Uint8Array?e:new Uint8Array(e);if(n?.length>1)return this.fromTokenizer(yu(n,this.tokenizerOptions))}async fromBlob(e){let n=xu(e,this.tokenizerOptions);try{return await this.fromTokenizer(n)}finally{await n.close()}}async fromStream(e){let n=gu(e,this.tokenizerOptions);try{return await this.fromTokenizer(n)}finally{await n.close()}}async toDetectionStream(e,n){let{sampleSize:r=ei}=n,s,i,o=e.getReader({mode:"byob"});try{let{value:c,done:u}=await o.read(new Uint8Array(r));if(i=c,!u&&c)try{s=await this.fromBuffer(c.subarray(0,r))}catch(f){if(!(f instanceof pe))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,n){return ct(this.buffer,e,n)}checkString(e,n){return this.check(Du(e,n?.encoding),n)}detectConfident=async e=>{if(this.buffer=new Uint8Array(ei),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 r=new _n(e).inflate(),s=!0;try{let i;try{i=await this.fromStream(r)}catch{s=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{s&&await r.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 n=await e.readToken(Mu);return e.position+n>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(n),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 n;return await new Mn(e).unzip(r=>{switch(r.filename){case"META-INF/mozilla.rsa":return n={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return n={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(s){let i=new TextDecoder("utf-8").decode(s).trim();n=ti(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}"`)&&(n=ti(a))}else{i=i.slice(0,Math.max(0,o));let a=i.lastIndexOf('"'),l=i.slice(Math.max(0,a+1));n=ti(l)}},stop:!0};default:return/classes\d*\.dex/.test(r.filename)?(n={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(r=>{if(!(r instanceof pe))throw r}),n??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let n=new Uint8Array(8);return await e.readBuffer(n),ct(n,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:ct(n,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:ct(n,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:ct(n,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:ct(n,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:ct(n,[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 n=await this.readTiffHeader(!1);if(n)return n}if(this.check([77,77])){let n=await this.readTiffHeader(!0);if(n)return n}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function n(){let a=await e.peekNumber(iu),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 r(){let a=await n(),l=await n();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:Ys(u),len:Ys(f)}}async function s(a){for(;a>0;){let l=await r();if(l.id===17026)return(await e.readToken(new We(l.len))).replaceAll(/\00.*$/g,"");await e.ignore(l.len),--a}}let i=await r();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 n=new We(4,"latin1").get(this.buffer,2);if(n.match("^d*")&&n>=1e3&&n<=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 We(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
551
|
+
`}return{stdout:c,stderr:"",exitCode:u}}}}var cy,wr=C(()=>{"use strict";j();cy={sha1:"SHA-1",sha256:"SHA-256"}});var Kc={};M(Kc,{md5sumCommand:()=>fy});var fy,Qc=C(()=>{"use strict";wr();fy=rn("md5sum","md5","compute MD5 message digest")});var Xc={};M(Xc,{sha1sumCommand:()=>dy});var dy,Jc=C(()=>{"use strict";wr();dy=rn("sha1sum","sha1","compute SHA1 message digest")});var Yc={};M(Yc,{sha256sumCommand:()=>py});var py,eu=C(()=>{"use strict";wr();py=rn("sha256sum","sha256","compute SHA256 message digest")});var tu=Zn(qs=>{qs.read=function(t,e,n,r,s){var i,o,a=s*8-r-1,l=(1<<a)-1,c=l>>1,u=-7,f=n?s-1:0,d=n?-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+=r;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,r),i=i-c}return(p?-1:1)*o*Math.pow(2,i-r)};qs.write=function(t,e,n,r,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=r?0:i-1,h=r?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*(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[n+p]=a&255,p+=h,a/=256,s-=8);for(o=o<<s|a,c+=s;c>0;t[n+p]=o&255,p+=h,o/=256,c-=8);t[n+p-h]|=g*128}});function nu(t,e="utf-8"){switch(e.toLowerCase()){case"utf-8":case"utf8":return typeof globalThis.TextDecoder<"u"?new globalThis.TextDecoder("utf-8").decode(t):my(t);case"utf-16le":return gy(t);case"ascii":return yy(t);case"latin1":case"iso-8859-1":return xy(t);case"windows-1252":return wy(t);default:throw new RangeError(`Encoding '${e}' not supported`)}}function my(t){let e="",n=0;for(;n<t.length;){let r=t[n++];if(r<128)e+=String.fromCharCode(r);else if(r<224){let s=t[n++]&63;e+=String.fromCharCode((r&31)<<6|s)}else if(r<240){let s=t[n++]&63,i=t[n++]&63;e+=String.fromCharCode((r&15)<<12|s<<6|i)}else{let s=t[n++]&63,i=t[n++]&63,o=t[n++]&63,a=(r&7)<<18|s<<12|i<<6|o;a-=65536,e+=String.fromCharCode(55296+(a>>10&1023),56320+(a&1023))}}return e}function gy(t){let e="";for(let n=0;n<t.length;n+=2)e+=String.fromCharCode(t[n]|t[n+1]<<8);return e}function yy(t){return String.fromCharCode(...t.map(e=>e&127))}function xy(t){return String.fromCharCode(...t)}function wy(t){let e="";for(let n of t)n>=128&&n<=159&&Vs[n]?e+=Vs[n]:e+=String.fromCharCode(n);return e}var Vs,hy,ru=C(()=>{Vs={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"},hy={};for(let[t,e]of Object.entries(Vs))hy[e]=Number.parseInt(t)});function Be(t){return new DataView(t.buffer,t.byteOffset)}var su,iu,ge,sn,be,ou,au,lu,We,Tn=C(()=>{su=lo(tu(),1);ru();iu={len:1,get(t,e){return Be(t).getUint8(e)},put(t,e,n){return Be(t).setUint8(e,n),e+1}},ge={len:2,get(t,e){return Be(t).getUint16(e,!0)},put(t,e,n){return Be(t).setUint16(e,n,!0),e+2}},sn={len:2,get(t,e){return Be(t).getUint16(e)},put(t,e,n){return Be(t).setUint16(e,n),e+2}},be={len:4,get(t,e){return Be(t).getUint32(e,!0)},put(t,e,n){return Be(t).setUint32(e,n,!0),e+4}},ou={len:4,get(t,e){return Be(t).getUint32(e)},put(t,e,n){return Be(t).setUint32(e,n),e+4}},au={len:4,get(t,e){return Be(t).getInt32(e)},put(t,e,n){return Be(t).setInt32(e,n),e+4}},lu={len:8,get(t,e){return Be(t).getBigUint64(e,!0)},put(t,e,n){return Be(t).setBigUint64(e,n,!0),e+8}},We=class{constructor(e,n){this.len=e,this.encoding=n}get(e,n=0){let r=e.subarray(n,n+this.len);return nu(r,this.encoding)}}});var Ey,pe,Ot,On=C(()=>{Ey="End-Of-Stream",pe=class extends Error{constructor(){super(Ey),this.name="EndOfStreamError"}},Ot=class extends Error{constructor(e="The operation was aborted"){super(e),this.name="AbortError"}}});var cu=C(()=>{});var Dt,br=C(()=>{On();Dt=class{constructor(){this.endOfStream=!1,this.interrupted=!1,this.peekQueue=[]}async peek(e,n=!1){let r=await this.read(e,n);return this.peekQueue.push(e.subarray(0,r)),r}async read(e,n=!1){if(e.length===0)return 0;let r=this.readFromPeekBuffer(e);if(this.endOfStream||(r+=await this.readRemainderFromStream(e.subarray(r),n)),r===0&&!n)throw new pe;return r}readFromPeekBuffer(e){let n=e.length,r=0;for(;this.peekQueue.length>0&&n>0;){let s=this.peekQueue.pop();if(!s)throw new Error("peekData should be defined");let i=Math.min(s.length,n);e.set(s.subarray(0,i),r),r+=i,n-=i,i<s.length&&this.peekQueue.push(s.subarray(i))}return r}async readRemainderFromStream(e,n){let r=0;for(;r<e.length&&!this.endOfStream;){if(this.interrupted)throw new Ot;let s=await this.readFromStream(e.subarray(r),n);if(s===0)break;r+=s}if(!n&&r<e.length)throw new pe;return r}}});var uu=C(()=>{On();cu();br()});var Er,fu=C(()=>{br();Er=class extends Dt{constructor(e){super(),this.reader=e}async abort(){return this.close()}async close(){this.reader.releaseLock()}}});var Dn,Zs=C(()=>{fu();Dn=class extends Er{async readFromStream(e,n){if(e.length===0)return 0;let r=await this.reader.read(new Uint8Array(e.length),{min:n?void 0:e.length});return r.done&&(this.endOfStream=r.done),r.value?(e.set(r.value),r.value.length):0}}});var on,Ks=C(()=>{On();br();on=class extends Dt{constructor(e){super(),this.reader=e,this.buffer=null}writeChunk(e,n){let r=Math.min(n.length,e.length);return e.set(n.subarray(0,r)),r<n.length?this.buffer=n.subarray(r):this.buffer=null,r}async readFromStream(e,n){if(e.length===0)return 0;let r=0;for(this.buffer&&(r+=this.writeChunk(e,this.buffer));r<e.length&&!this.endOfStream;){let s=await this.reader.read();if(s.done){this.endOfStream=!0;break}s.value&&(r+=this.writeChunk(e.subarray(r),s.value))}if(!n&&r===0&&this.endOfStream)throw new pe;return r}abort(){return this.interrupted=!0,this.reader.cancel()}async close(){await this.abort(),this.reader.releaseLock()}}});function Qs(t){try{let e=t.getReader({mode:"byob"});return e instanceof ReadableStreamDefaultReader?new on(e):new Dn(e)}catch(e){if(e instanceof TypeError)return new on(t.getReader());throw e}}var du=C(()=>{Zs();Ks()});var Lt=C(()=>{On();uu();Zs();Ks();du()});var ft,Ln=C(()=>{Lt();ft=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,n=this.position){let r=new Uint8Array(e.len);if(await this.readBuffer(r,{position:n})<e.len)throw new pe;return e.get(r,0)}async peekToken(e,n=this.position){let r=new Uint8Array(e.len);if(await this.peekBuffer(r,{position:n})<e.len)throw new pe;return e.get(r,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new pe;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new pe;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let n=this.fileInfo.size-this.position;if(e>n)return this.position+=n,n}return this.position+=e,e}async close(){await this.abort(),await this.onClose?.()}normalizeOptions(e,n){if(!this.supportsRandomAccess()&&n&&n.position!==void 0&&n.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,...n}}abort(){return Promise.resolve()}}});var Cy,Sr,pu=C(()=>{Ln();Lt();Cy=256e3,Sr=class extends ft{constructor(e,n){super(n),this.streamReader=e,this.fileInfo=n?.fileInfo??{}}async readBuffer(e,n){let r=this.normalizeOptions(e,n),s=r.position-this.position;if(s>0)return await this.ignore(s),this.readBuffer(e,n);if(s<0)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");if(r.length===0)return 0;let i=await this.streamReader.read(e.subarray(0,r.length),r.mayBeLess);if(this.position+=i,(!n||!n.mayBeLess)&&i<r.length)throw new pe;return i}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=0;if(r.position){let i=r.position-this.position;if(i>0){let o=new Uint8Array(r.length+i);return s=await this.peekBuffer(o,{mayBeLess:r.mayBeLess}),e.set(o.subarray(i)),s-i}if(i<0)throw new Error("Cannot peek from a negative offset in a stream")}if(r.length>0){try{s=await this.streamReader.peek(e.subarray(0,r.length),r.mayBeLess)}catch(i){if(n?.mayBeLess&&i instanceof pe)return 0;throw i}if(!r.mayBeLess&&s<r.length)throw new pe}return s}async ignore(e){let n=Math.min(Cy,e),r=new Uint8Array(n),s=0;for(;s<e;){let i=e-s,o=await this.readBuffer(r,{length:Math.min(n,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 Cr,hu=C(()=>{Lt();Ln();Cr=class extends ft{constructor(e,n){super(n),this.uint8Array=e,this.fileInfo={...n?.fileInfo??{},size:e.length}}async readBuffer(e,n){n?.position&&(this.position=n.position);let r=await this.peekBuffer(e,n);return this.position+=r,r}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=Math.min(this.uint8Array.length-r.position,r.length);if(!r.mayBeLess&&s<r.length)throw new pe;return e.set(this.uint8Array.subarray(r.position,r.position+s)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});var Ar,mu=C(()=>{Lt();Ln();Ar=class extends ft{constructor(e,n){super(n),this.blob=e,this.fileInfo={...n?.fileInfo??{},size:e.size,mimeType:e.type}}async readBuffer(e,n){n?.position&&(this.position=n.position);let r=await this.peekBuffer(e,n);return this.position+=r,r}async peekBuffer(e,n){let r=this.normalizeOptions(e,n),s=Math.min(this.blob.size-r.position,r.length);if(!r.mayBeLess&&s<r.length)throw new pe;let i=await this.blob.slice(r.position,r.position+s).arrayBuffer();return e.set(new Uint8Array(i)),s}close(){return super.close()}supportsRandomAccess(){return!0}setPosition(e){this.position=e}}});function gu(t,e){let n=Qs(t),r=e??{},s=r.onClose;return r.onClose=async()=>{if(await n.close(),s)return s()},new Sr(n,r)}function yu(t,e){return new Cr(t,e)}function xu(t,e){return new Ar(t,e)}var wu=C(()=>{Lt();pu();hu();mu();Lt();Ln()});var Eu=Zn((sC,bu)=>{var an=1e3,ln=an*60,cn=ln*60,Mt=cn*24,ky=Mt*7,Ny=Mt*365.25;bu.exports=function(t,e){e=e||{};var n=typeof t;if(n==="string"&&t.length>0)return Iy(t);if(n==="number"&&isFinite(t))return e.long?$y(t):vy(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Iy(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 n=parseFloat(e[1]),r=(e[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*Ny;case"weeks":case"week":case"w":return n*ky;case"days":case"day":case"d":return n*Mt;case"hours":case"hour":case"hrs":case"hr":case"h":return n*cn;case"minutes":case"minute":case"mins":case"min":case"m":return n*ln;case"seconds":case"second":case"secs":case"sec":case"s":return n*an;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function vy(t){var e=Math.abs(t);return e>=Mt?Math.round(t/Mt)+"d":e>=cn?Math.round(t/cn)+"h":e>=ln?Math.round(t/ln)+"m":e>=an?Math.round(t/an)+"s":t+"ms"}function $y(t){var e=Math.abs(t);return e>=Mt?kr(t,e,Mt,"day"):e>=cn?kr(t,e,cn,"hour"):e>=ln?kr(t,e,ln,"minute"):e>=an?kr(t,e,an,"second"):t+" ms"}function kr(t,e,n,r){var s=e>=n*1.5;return Math.round(t/n)+" "+r+(s?"s":"")}});var Cu=Zn((iC,Su)=>{function Ry(t){n.debug=n,n.default=n,n.coerce=l,n.disable=o,n.enable=s,n.enabled=a,n.humanize=Eu(),n.destroy=c,Object.keys(t).forEach(u=>{n[u]=t[u]}),n.names=[],n.skips=[],n.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 n.colors[Math.abs(f)%n.colors.length]}n.selectColor=e;function n(u){let f,d=null,p,h;function g(...m){if(!g.enabled)return;let w=g,b=Number(new Date),E=b-(f||b);w.diff=E,w.prev=f,w.curr=b,f=b,m[0]=n.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let S=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(F,W)=>{if(F==="%%")return"%";S++;let z=n.formatters[W];if(typeof z=="function"){let X=m[S];F=z.call(w,X),m.splice(S,1),S--}return F}),n.formatArgs.call(w,m),(w.log||n.log).apply(w,m)}return g.namespace=u,g.useColors=n.useColors(),g.color=n.selectColor(u),g.extend=r,g.destroy=n.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(p!==n.namespaces&&(p=n.namespaces,h=n.enabled(u)),h),set:m=>{d=m}}),typeof n.init=="function"&&n.init(g),g}function r(u,f){let d=n(this.namespace+(typeof f>"u"?":":f)+u);return d.log=this.log,d}function s(u){n.save(u),n.namespaces=u,n.names=[],n.skips=[];let f=(typeof u=="string"?u:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let d of f)d[0]==="-"?n.skips.push(d.slice(1)):n.names.push(d)}function i(u,f){let d=0,p=0,h=-1,g=0;for(;d<u.length;)if(p<f.length&&(f[p]===u[d]||f[p]==="*"))f[p]==="*"?(h=p,g=d,p++):(d++,p++);else if(h!==-1)p=h+1,g++,d=g;else return!1;for(;p<f.length&&f[p]==="*";)p++;return p===f.length}function o(){let u=[...n.names,...n.skips.map(f=>"-"+f)].join(",");return n.enable(""),u}function a(u){for(let f of n.skips)if(i(u,f))return!1;for(let f of n.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 n.enable(n.load()),n}Su.exports=Ry});var Au=Zn((Ue,Nr)=>{Ue.formatArgs=Py;Ue.save=Ty;Ue.load=Oy;Ue.useColors=Fy;Ue.storage=Dy();Ue.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`."))}})();Ue.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 Fy(){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 Py(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Nr.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let n=0,r=0;t[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(n++,s==="%c"&&(r=n))}),t.splice(r,0,e)}Ue.log=console.debug||console.log||(()=>{});function Ty(t){try{t?Ue.storage.setItem("debug",t):Ue.storage.removeItem("debug")}catch{}}function Oy(){let t;try{t=Ue.storage.getItem("debug")||Ue.storage.getItem("DEBUG")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function Dy(){try{return localStorage}catch{}}Nr.exports=Cu()(Ue);var{formatters:Ly}=Nr.exports;Ly.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var _t,Xs,ku,Nu,Iu,vu=C(()=>{Tn();_t={LocalFileHeader:67324752,DataDescriptor:134695760,CentralFileHeader:33639248,EndOfCentralDirectory:101010256},Xs={get(t){return{signature:be.get(t,0),compressedSize:be.get(t,8),uncompressedSize:be.get(t,12)}},len:16},ku={get(t){let e=ge.get(t,6);return{signature:be.get(t,0),minVersion:ge.get(t,4),dataDescriptor:!!(e&8),compressedMethod:ge.get(t,8),compressedSize:be.get(t,18),uncompressedSize:be.get(t,22),filenameLength:ge.get(t,26),extraFieldLength:ge.get(t,28),filename:null}},len:30},Nu={get(t){return{signature:be.get(t,0),nrOfThisDisk:ge.get(t,4),nrOfThisDiskWithTheStart:ge.get(t,6),nrOfEntriesOnThisDisk:ge.get(t,8),nrOfEntriesOfSize:ge.get(t,10),sizeOfCd:be.get(t,12),offsetOfStartOfCd:be.get(t,16),zipFileCommentLength:ge.get(t,20)}},len:22},Iu={get(t){let e=ge.get(t,8);return{signature:be.get(t,0),minVersion:ge.get(t,6),dataDescriptor:!!(e&8),compressedMethod:ge.get(t,10),compressedSize:be.get(t,20),uncompressedSize:be.get(t,24),filenameLength:ge.get(t,28),extraFieldLength:ge.get(t,30),fileCommentLength:ge.get(t,32),relativeOffsetOfLocalHeader:be.get(t,42),filename:null}},len:46}});function Ru(t){let e=new Uint8Array(be.len);return be.put(e,0,t),e}function _y(t,e){let n=t.length,r=e.length;if(r>n)return-1;for(let s=0;s<=n-r;s++){let i=!0;for(let o=0;o<r;o++)if(t[s+o]!==e[o]){i=!1;break}if(i)return s}return-1}function By(t){let e=t.reduce((s,i)=>s+i.length,0),n=new Uint8Array(e),r=0;for(let s of t)n.set(s,r),r+=s.length;return n}var $u,lt,Js,My,Ir,Mn,Fu=C(()=>{Tn();$u=lo(Au(),1);vu();lt=(0,$u.default)("tokenizer:inflate"),Js=256*1024,My=Ru(_t.DataDescriptor),Ir=Ru(_t.EndOfCentralDirectory),Mn=class t{constructor(e){this.tokenizer=e,this.syncBuffer=new Uint8Array(Js)}async isZip(){return await this.peekSignature()===_t.LocalFileHeader}peekSignature(){return this.tokenizer.peekToken(be)}async findEndOfCentralDirectoryLocator(){let e=this.tokenizer,n=Math.min(16*1024,e.fileInfo.size),r=this.syncBuffer.subarray(0,n);await this.tokenizer.readBuffer(r,{position:e.fileInfo.size-n});for(let s=r.length-4;s>=0;s--)if(r[s]===Ir[0]&&r[s+1]===Ir[1]&&r[s+2]===Ir[2]&&r[s+3]===Ir[3])return e.fileInfo.size-n+s;return-1}async readCentralDirectory(){if(!this.tokenizer.supportsRandomAccess()){lt("Cannot reading central-directory without random-read support");return}lt("Reading central-directory...");let e=this.tokenizer.position,n=await this.findEndOfCentralDirectoryLocator();if(n>0){lt("Central-directory 32-bit signature found");let r=await this.tokenizer.readToken(Nu,n),s=[];this.tokenizer.setPosition(r.offsetOfStartOfCd);for(let i=0;i<r.nrOfEntriesOfSize;++i){let o=await this.tokenizer.readToken(Iu);if(o.signature!==_t.CentralFileHeader)throw new Error("Expected Central-File-Header signature");o.filename=await this.tokenizer.readToken(new We(o.filenameLength,"utf-8")),await this.tokenizer.ignore(o.extraFieldLength),await this.tokenizer.ignore(o.fileCommentLength),s.push(o),lt(`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 n=await this.readCentralDirectory();if(n)return this.iterateOverCentralDirectory(n,e);let r=!1;do{let s=await this.readLocalFileHeader();if(!s)break;let i=e(s);r=!!i.stop;let o;if(await this.tokenizer.ignore(s.extraFieldLength),s.dataDescriptor&&s.compressedSize===0){let a=[],l=Js;lt("Compressed-file-size unknown, scanning for next data-descriptor-signature....");let c=-1;for(;c<0&&l===Js;){l=await this.tokenizer.peekBuffer(this.syncBuffer,{mayBeLess:!0}),c=_y(this.syncBuffer.subarray(0,l),My);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)}lt(`Found data-descriptor-signature at pos=${this.tokenizer.position}`),i.handler&&await this.inflate(s,By(a),i.handler)}else i.handler?(lt(`Reading compressed-file-data: ${s.compressedSize} bytes`),o=new Uint8Array(s.compressedSize),await this.tokenizer.readBuffer(o),await this.inflate(s,o,i.handler)):(lt(`Ignoring compressed-file-data: ${s.compressedSize} bytes`),await this.tokenizer.ignore(s.compressedSize));if(lt(`Reading data-descriptor at pos=${this.tokenizer.position}`),s.dataDescriptor&&(await this.tokenizer.readToken(Xs)).signature!==134695760)throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position-Xs.len}`)}while(!r)}async iterateOverCentralDirectory(e,n){for(let r of e){let s=n(r);if(s.handler){this.tokenizer.setPosition(r.relativeOffsetOfLocalHeader);let i=await this.readLocalFileHeader();if(i){await this.tokenizer.ignore(i.extraFieldLength);let o=new Uint8Array(r.compressedSize);await this.tokenizer.readBuffer(o),await this.inflate(i,o,s.handler)}}if(s.stop)break}}async inflate(e,n,r){if(e.compressedMethod===0)return r(n);if(e.compressedMethod!==8)throw new Error(`Unsupported ZIP compression method: ${e.compressedMethod}`);lt(`Decompress filename=${e.filename}, compressed-size=${n.length}`);let s=await t.decompressDeflateRaw(n);return r(s)}static async decompressDeflateRaw(e){let n=new ReadableStream({start(i){i.enqueue(e),i.close()}}),r=new DecompressionStream("deflate-raw"),s=n.pipeThrough(r);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(be);if(e===_t.LocalFileHeader){let n=await this.tokenizer.readToken(ku);return n.filename=await this.tokenizer.readToken(new We(n.filenameLength,"utf-8")),n}if(e===_t.CentralFileHeader)return!1;throw e===3759263696?new Error("Encrypted ZIP"):new Error("Unexpected signature")}}});var _n,Pu=C(()=>{_n=class{constructor(e){this.tokenizer=e}inflate(){let e=this.tokenizer;return new ReadableStream({async pull(n){let r=new Uint8Array(1024),s=await e.readBuffer(r,{mayBeLess:!0});if(s===0){n.close();return}n.enqueue(r.subarray(0,s))}}).pipeThrough(new DecompressionStream("gzip"))}}});var Tu=C(()=>{Fu();Pu()});function Ys(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 mC,gC,yC,Ou=C(()=>{mC={utf8:new globalThis.TextDecoder("utf8")},gC=new globalThis.TextEncoder,yC=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"))});function Du(t,e){if(e==="utf-16le"){let n=[];for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);n.push(s&255,s>>8&255)}return n}if(e==="utf-16be"){let n=[];for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);n.push(s>>8&255,s&255)}return n}return[...t].map(n=>n.charCodeAt(0))}function Lu(t,e=0){let n=Number.parseInt(new We(6).get(t,148).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(n))return!1;let r=256;for(let s=e;s<e+148;s++)r+=t[s];for(let s=e+156;s<e+512;s++)r+=t[s];return n===r}var Mu,_u=C(()=>{Tn();Mu={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4}});var Bu,Wu,Uu=C(()=>{Bu=["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"],Wu=["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 ju(t,e){return new ni(e).fromBuffer(t)}function ti(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 ct(t,e,n){n={offset:0,...n};for(let[r,s]of e.entries())if(n.mask){if(s!==(n.mask[r]&t[r+n.offset]))return!1}else if(s!==t[r+n.offset])return!1;return!0}var ei,ni,NC,IC,zu=C(()=>{Tn();wu();Tu();Ou();_u();Uu();ei=4100;ni=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 n=e.position;for(let r of this.detectors){let s=await r.detect(e);if(s)return s;if(n!==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 n=e instanceof Uint8Array?e:new Uint8Array(e);if(n?.length>1)return this.fromTokenizer(yu(n,this.tokenizerOptions))}async fromBlob(e){let n=xu(e,this.tokenizerOptions);try{return await this.fromTokenizer(n)}finally{await n.close()}}async fromStream(e){let n=gu(e,this.tokenizerOptions);try{return await this.fromTokenizer(n)}finally{await n.close()}}async toDetectionStream(e,n){let{sampleSize:r=ei}=n,s,i,o=e.getReader({mode:"byob"});try{let{value:c,done:u}=await o.read(new Uint8Array(r));if(i=c,!u&&c)try{s=await this.fromBuffer(c.subarray(0,r))}catch(f){if(!(f instanceof pe))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,n){return ct(this.buffer,e,n)}checkString(e,n){return this.check(Du(e,n?.encoding),n)}detectConfident=async e=>{if(this.buffer=new Uint8Array(ei),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 r=new _n(e).inflate(),s=!0;try{let i;try{i=await this.fromStream(r)}catch{s=!1}if(i&&i.ext==="tar")return{ext:"tar.gz",mime:"application/gzip"}}finally{s&&await r.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 n=await e.readToken(Mu);return e.position+n>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(n),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 n;return await new Mn(e).unzip(r=>{switch(r.filename){case"META-INF/mozilla.rsa":return n={ext:"xpi",mime:"application/x-xpinstall"},{stop:!0};case"META-INF/MANIFEST.MF":return n={ext:"jar",mime:"application/java-archive"},{stop:!0};case"mimetype":return{async handler(s){let i=new TextDecoder("utf-8").decode(s).trim();n=ti(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}"`)&&(n=ti(a))}else{i=i.slice(0,Math.max(0,o));let a=i.lastIndexOf('"'),l=i.slice(Math.max(0,a+1));n=ti(l)}},stop:!0};default:return/classes\d*\.dex/.test(r.filename)?(n={ext:"apk",mime:"application/vnd.android.package-archive"},{stop:!0}):{}}}).catch(r=>{if(!(r instanceof pe))throw r}),n??{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let n=new Uint8Array(8);return await e.readBuffer(n),ct(n,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/ogg; codecs=opus"}:ct(n,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:ct(n,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:ct(n,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:ct(n,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:ct(n,[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 n=await this.readTiffHeader(!1);if(n)return n}if(this.check([77,77])){let n=await this.readTiffHeader(!0);if(n)return n}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function n(){let a=await e.peekNumber(iu),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 r(){let a=await n(),l=await n();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:Ys(u),len:Ys(f)}}async function s(a){for(;a>0;){let l=await r();if(l.id===17026)return(await e.readToken(new We(l.len))).replaceAll(/\00.*$/g,"");await e.ignore(l.len),--a}}let i=await r();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 n=new We(4,"latin1").get(this.buffer,2);if(n.match("^d*")&&n>=1e3&&n<=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 We(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("WEBVTT")&&[`
|
|
552
552
|
`,"\r"," "," ","\0"].some(n=>this.checkString(n,{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 n(){return{length:await e.readToken(au),type:await e.readToken(new We(4,"latin1"))}}do{let r=await n();if(r.length<0)return;switch(r.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(r.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 n=new We(4,"latin1").get(this.buffer,8).replace("\0"," ").trim();switch(n){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 n.startsWith("3g")?n.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.checkString(`REGEDIT4\r
|
|
553
553
|
`))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 n(){let r=new Uint8Array(16);return await e.readBuffer(r),{id:r,size:Number(await e.readToken(lu))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let r=await n(),s=r.size-24;if(ct(r.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),ct(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(ct(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 We(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 n=new DataView(this.buffer.buffer).getUint32(12,!0);if(n>12&&this.buffer.length>=n+16)try{let r=new TextDecoder().decode(this.buffer.subarray(16,n+16));if(JSON.parse(r).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})&&Lu(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254])){let n="utf-16le";return this.checkString("<?xml ",{offset:2,encoding:n})?{ext:"xml",mime:"application/xml"}:this.check([255,14],{offset:2})&&this.checkString("SketchUp Model",{offset:4,encoding:n})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:this.checkString(`Windows Registry Editor Version 5.00\r
|
|
554
|
-
`,{offset:2,encoding:n})?{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(ei),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 n=0;n<=this.options.mpegOffsetTolerance;++n){let r=this.scanMpeg(n);if(r)return r}};async readTiffTag(e){let n=await this.tokenizer.readToken(e?sn:ge);switch(this.tokenizer.ignore(10),n){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 n=await this.tokenizer.readToken(e?sn:ge);for(let r=0;r<n;++r){let s=await this.readTiffTag(e);if(s)return s}}async readTiffHeader(e){let n=(e?sn:ge).get(this.buffer,2),r=(e?ou:be).get(this.buffer,4);if(n===42){if(r>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(r>=8){let i=(e?sn:ge).get(this.buffer,8),o=(e?sn:ge).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(r),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(n===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"}}}},
|
|
554
|
+
`,{offset:2,encoding:n})?{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(ei),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 n=0;n<=this.options.mpegOffsetTolerance;++n){let r=this.scanMpeg(n);if(r)return r}};async readTiffTag(e){let n=await this.tokenizer.readToken(e?sn:ge);switch(this.tokenizer.ignore(10),n){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 n=await this.tokenizer.readToken(e?sn:ge);for(let r=0;r<n;++r){let s=await this.readTiffTag(e);if(s)return s}}async readTiffHeader(e){let n=(e?sn:ge).get(this.buffer,2),r=(e?ou:be).get(this.buffer,4);if(n===42){if(r>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(r>=8){let i=(e?sn:ge).get(this.buffer,8),o=(e?sn:ge).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(r),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(n===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"}}}},NC=new Set(Bu),IC=new Set(Wu)});var qu={};M(qu,{fileCommand:()=>Gy});function Uy(t,e){if(Gu[t])return Gu[t];let[n,r]=e.split("/"),s=r?.split("+")[0]?.replace(/-/g," ")||t;switch(n){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 r?.includes("zip")||r?.includes("compressed")?`${s} archive data`:r?.includes("executable")?`${s} executable`:`${t.toUpperCase()} data`;default:return`${t.toUpperCase()} data`}}function jy(t){let e=t.split("/").pop()||t;if(e.startsWith(".")&&!e.includes(".",1))return e;let n=e.lastIndexOf(".");return n===-1||n===0?"":e.slice(n).toLowerCase()}function zy(t,e){if(t.startsWith("#!")){let l=t.split(`
|
|
555
555
|
`)[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 n=t.trimStart();if(n.startsWith("<?xml"))return{description:"XML document",mime:"application/xml"};if(n.startsWith("<!DOCTYPE html")||n.toLowerCase().startsWith("<html"))return{description:"HTML document",mime:"text/html"};let r=t.includes(`\r
|
|
556
|
-
`),s=t.includes("\r")&&!r,i="";r?i=", with CRLF line terminators":s&&(i=", with CR line terminators");let o=
|
|
556
|
+
`),s=t.includes("\r")&&!r,i="";r?i=", with CRLF line terminators":s&&(i=", with CR line terminators");let o=jy(e);if(o&&Hu[o]){let l=Hu[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 Hy(t,e){if(e.length===0)return{description:"empty",mime:"inode/x-empty"};let n=await ju(e);if(n)return{description:Uy(n.ext,n.mime),mime:n.mime};let r=new TextDecoder("utf-8",{fatal:!1}).decode(e);return zy(r,t)}var Wy,Hu,Gu,Gy,Vu=C(()=>{"use strict";zu();j();Wy={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"]},Hu={".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"}},Gu={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"};Gy={name:"file",async execute(t,e){if(I(t))return N(Wy);let n=!1,r=!1,s=[];for(let a of t)if(a.startsWith("--")){if(a==="--brief")n=!0;else if(a==="--mime"||a==="--mime-type")r=!0;else if(a!=="--dereference")return L("file",a)}else if(a.startsWith("-")&&a!=="-"){for(let l of a.slice(1))if(l==="b")n=!0;else if(l==="i")r=!0;else if(l!=="L")return L("file",`-${l}`)}else s.push(a);if(s.length===0)return{stdout:"",stderr:`Usage: file [-bLi] FILE...
|
|
557
557
|
`,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=r?"inode/directory":"directory";i+=n?`${p}
|
|
558
558
|
`:`${a}: ${p}
|
|
559
|
-
`;continue}let u=await e.fs.readFileBuffer(l),f=await
|
|
559
|
+
`;continue}let u=await e.fs.readFileBuffer(l),f=await Hy(a,u),d=r?f.mime:f.description;i+=n?`${d}
|
|
560
560
|
`:`${a}: ${d}
|
|
561
561
|
`}catch{i+=n?`cannot open
|
|
562
562
|
`:`${a}: cannot open (No such file or directory)
|
|
563
|
-
`,o=1}return{stdout:i,stderr:"",exitCode:o}}}});var Zu={};M(Zu,{htmlToMarkdownCommand:()=>
|
|
564
|
-
`,exitCode:1}}if(!a.trim())return{stdout:"",stderr:"",exitCode:0};try{let l=new
|
|
563
|
+
`,o=1}return{stdout:i,stderr:"",exitCode:o}}}});var Zu={};M(Zu,{htmlToMarkdownCommand:()=>Zy});import qy from"turndown";var Vy,Zy,Ku=C(()=>{"use strict";j();Vy={name:"html-to-markdown",summary:"convert HTML to Markdown (BashEnv extension)",usage:"html-to-markdown [OPTION]... [FILE]",description:["Convert HTML content to Markdown format using the turndown library.","This is a non-standard BashEnv extension command, not available in regular bash.","","Read HTML from FILE or standard input and output Markdown to standard output.","Commonly used with curl to convert web pages:"," curl -s https://example.com | html-to-markdown","","Supported HTML elements:"," - Headings (h1-h6) \u2192 # Markdown headings"," - Paragraphs (p) \u2192 Plain text with blank lines"," - Links (a) \u2192 [text](url)"," - Images (img) \u2192 "," - Bold/Strong \u2192 **text**"," - Italic/Em \u2192 _text_"," - Code (code, pre) \u2192 `inline` or fenced blocks"," - Lists (ul, ol, li) \u2192 - or 1. items"," - Blockquotes \u2192 > quoted text"," - Horizontal rules (hr) \u2192 ---"],options:["-b, --bullet=CHAR bullet character for unordered lists (-, +, or *)","-c, --code=FENCE fence style for code blocks (``` or ~~~)","-r, --hr=STRING string for horizontal rules (default: ---)"," --heading-style=STYLE"," heading style: 'atx' for # headings (default),"," 'setext' for underlined headings (h1/h2 only)"," --help display this help and exit"],examples:["echo '<h1>Hello</h1><p>World</p>' | html-to-markdown","html-to-markdown page.html","curl -s https://example.com | html-to-markdown > page.md"]},Zy={name:"html-to-markdown",async execute(t,e){if(I(t))return N(Vy);let n="-",r="```",s="---",i="atx",o=[];for(let l=0;l<t.length;l++){let c=t[l];if(c==="-b"||c==="--bullet")n=t[++l]??"-";else if(c.startsWith("--bullet="))n=c.slice(9);else if(c==="-c"||c==="--code")r=t[++l]??"```";else if(c.startsWith("--code="))r=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 L("html-to-markdown",c);if(c.startsWith("-"))return L("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
|
|
564
|
+
`,exitCode:1}}if(!a.trim())return{stdout:"",stderr:"",exitCode:0};try{let l=new qy({bulletListMarker:n,codeBlockStyle:"fenced",fence:r,hr:s,headingStyle:i});return l.remove(["script","style","footer"]),{stdout:`${l.turndown(a).trim()}
|
|
565
565
|
`,stderr:"",exitCode:0}}catch(l){return{stdout:"",stderr:`html-to-markdown: conversion error: ${l.message}
|
|
566
|
-
`,exitCode:1}}}}});var Qu={};M(Qu,{helpCommand:()=>
|
|
567
|
-
`);let r=[];for(let[s,i]of Object.entries(
|
|
566
|
+
`,exitCode:1}}}}});var Qu={};M(Qu,{helpCommand:()=>Xy});function Qy(t){let e=[],n=new Set(t);e.push(`Available commands:
|
|
567
|
+
`);let r=[];for(let[s,i]of Object.entries(Ky)){let o=i.filter(a=>n.has(a));if(o.length>0){e.push(` ${s}:`),e.push(` ${o.join(", ")}
|
|
568
568
|
`);for(let a of o)n.delete(a)}}for(let s of n)r.push(s);return r.length>0&&(e.push(" Other:"),e.push(` ${r.sort().join(", ")}
|
|
569
569
|
`)),e.push("Use '<command> --help' for details on a specific command."),`${e.join(`
|
|
570
570
|
`)}
|
|
571
|
-
`}var
|
|
571
|
+
`}var Ky,Xy,Xu=C(()=>{"use strict";Ky={"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"]};Xy={name:"help",async execute(t,e){if(t.includes("--help")||t.includes("-h"))return{stdout:`help - display available commands
|
|
572
572
|
|
|
573
573
|
Usage: help [command]
|
|
574
574
|
|
|
@@ -577,21 +577,21 @@ Options:
|
|
|
577
577
|
|
|
578
578
|
If a command name is provided, shows help for that command.
|
|
579
579
|
Otherwise, lists all available commands.
|
|
580
|
-
`,stderr:"",exitCode:0};if(t.length>0&&e.exec){let r=t[0];return e.exec(`${r} --help`,{cwd:e.cwd})}let n=e.getRegisteredCommands?.()??[];return{stdout:
|
|
581
|
-
`),!r))break}f||(c=!1)}return{stdout:l,stderr:"",exitCode:c?0:1}}}});var ef={};M(ef,{tac:()=>
|
|
580
|
+
`,stderr:"",exitCode:0};if(t.length>0&&e.exec){let r=t[0];return e.exec(`${r} --help`,{cwd:e.cwd})}let n=e.getRegisteredCommands?.()??[];return{stdout:Qy(n),stderr:"",exitCode:0}}}});var Ju={};M(Ju,{whichCommand:()=>ex});var Jy,Yy,ex,Yu=C(()=>{"use strict";Ae();j();Jy={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"]},Yy={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},ex={name:"which",async execute(t,e){if(I(t))return N(Jy);let n=J("which",t,Yy);if(!n.ok)return n.error;let r=n.result.flags.showAll,s=n.result.flags.silent,i=n.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}
|
|
581
|
+
`),!r))break}f||(c=!1)}return{stdout:l,stderr:"",exitCode:c?0:1}}}});var ef={};M(ef,{tac:()=>nx});async function tx(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(`
|
|
582
582
|
`);o[o.length-1]===""&&o.pop();let a=o.reverse();return{stdout:a.length>0?`${a.join(`
|
|
583
583
|
`)}
|
|
584
584
|
`:"",stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`tac: ${t[0]}: No such file or directory
|
|
585
585
|
`,exitCode:1}}}let n=e.stdin.split(`
|
|
586
586
|
`);n[n.length-1]===""&&n.pop();let r=n.reverse();return{stdout:r.length>0?`${r.join(`
|
|
587
587
|
`)}
|
|
588
|
-
`:"",stderr:"",exitCode:0}}var
|
|
589
|
-
`,stderr:"",exitCode:0}}var
|
|
588
|
+
`:"",stderr:"",exitCode:0}}var nx,tf=C(()=>{"use strict";nx={name:"tac",execute:tx}});var nf={};M(nf,{hostname:()=>sx});async function rx(t,e){return{stdout:`localhost
|
|
589
|
+
`,stderr:"",exitCode:0}}var sx,rf=C(()=>{"use strict";sx={name:"hostname",execute:rx}});var sf={};M(sf,{od:()=>ox});async function ix(t,e){let n=t.includes("-c"),r=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
|
|
590
590
|
`,exitCode:1}}}if(n){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=r==="none"?"":`${u.toString(8).padStart(7,"0")} `;c.push(d+f.join(" "))}return r!=="none"&&c.push(s.length.toString(8).padStart(7,"0")),{stdout:`${c.join(`
|
|
591
591
|
`)}
|
|
592
592
|
`,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=r==="none"?"":`${l.toString(8).padStart(7,"0")} `;a.push(u+c.join(" "))}return r!=="none"&&o.length>0&&a.push(s.length.toString(8).padStart(7,"0")),{stdout:a.length>0?`${a.join(`
|
|
593
593
|
`)}
|
|
594
|
-
`:"",stderr:"",exitCode:0}}var
|
|
594
|
+
`:"",stderr:"",exitCode:0}}var ox,of=C(()=>{"use strict";ox={name:"od",execute:ix}});var $r={};M($r,{gunzipCommand:()=>mx,gzipCommand:()=>hx,zcatCommand:()=>gx});import{constants as ri,gunzipSync as si,gzipSync as af}from"node:zlib";function lf(t){return t.best?ri.Z_BEST_COMPRESSION:t.level8?8:t.level7?7:t.level6?6:t.level5?5:t.level4?4:t.level3?3:t.level2?2:t.fast?ri.Z_BEST_SPEED:ri.Z_DEFAULT_COMPRESSION}function cf(t){if(t.length<10)return{originalName:null,mtime:null,headerSize:0};if(t[0]!==31||t[1]!==139)return{originalName:null,mtime:null,headerSize:0};let e=t[3],n=t[4]|t[5]<<8|t[6]<<16|t[7]<<24,r=10;if(e&4){if(r+2>t.length)return{originalName:null,mtime:null,headerSize:0};let i=t[r]|t[r+1]<<8;r+=2+i}let s=null;if(e&8){let i=r;for(;r<t.length&&t[r]!==0;)r++;r<t.length&&(s=new TextDecoder().decode(t.slice(i,r)),r++)}if(e&16){for(;r<t.length&&t[r]!==0;)r++;r++}return e&2&&(r+=2),{originalName:s,mtime:n>0?new Date(n*1e3):null,headerSize:r}}function fx(t){if(t.length<4)return 0;let e=t.length;return t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24}function vr(t){return t.length>=2&&t[0]===31&&t[1]===139}async function uf(t,e,n,r,s,i){let o=n.suffix,a,l,c;if(e==="-"||e==="")if(c=Uint8Array.from(t.stdin,u=>u.charCodeAt(0)),s){if(!vr(c))return n.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: stdin: not in gzip format
|
|
595
595
|
`,exitCode:1};try{let u=si(c);return{stdout:String.fromCharCode(...u),stderr:"",exitCode:0}}catch(u){let f=u instanceof Error?u.message:"unknown error";return{stdout:"",stderr:`${r}: stdin: ${f}
|
|
596
596
|
`,exitCode:1}}}else{let u=lf(n),f=af(c,{level:u});return{stdout:String.fromCharCode(...f),stderr:"",exitCode:0}}a=t.fs.resolvePath(t.cwd,e);try{if((await t.fs.stat(a)).isDirectory)return n.recursive?await ff(t,a,n,r,s,i):n.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${e}: is a directory -- ignored
|
|
597
597
|
`,exitCode:1}}catch{return{stdout:"",stderr:`${r}: ${e}: No such file or directory
|
|
@@ -605,23 +605,23 @@ Otherwise, lists all available commands.
|
|
|
605
605
|
`,exitCode:1};let u=lf(n),f;try{f=af(c,{level:u})}catch(d){let p=d instanceof Error?d.message:"unknown error";return{stdout:"",stderr:`${r}: ${e}: ${p}
|
|
606
606
|
`,exitCode:1}}if(i)return{stdout:String.fromCharCode(...f),stderr:"",exitCode:0};if(l=a+o,!n.force)try{return await t.fs.stat(l),{stdout:"",stderr:`${r}: ${l} already exists; not overwritten
|
|
607
607
|
`,exitCode:1}}catch{}if(await t.fs.writeFile(l,f),!n.keep&&!i&&await t.fs.rm(a),n.verbose){let d=c.length>0?((1-f.length/c.length)*100).toFixed(1):"0.0";return{stdout:"",stderr:`${e}: ${d}% -- replaced with ${l.split("/").pop()}
|
|
608
|
-
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}}async function ff(t,e,n,r,s,i){let o=await t.fs.readdir(e),a="",l="",c=0;for(let u of o){let f=t.fs.resolvePath(e,u),d=await t.fs.stat(f);if(d.isDirectory){let p=await ff(t,f,n,r,s,i);a+=p.stdout,l+=p.stderr,p.exitCode!==0&&(c=p.exitCode)}else if(d.isFile){let p=n.suffix;if(s&&!u.endsWith(p)||!s&&u.endsWith(p))continue;let h=f.startsWith(`${t.cwd}/`)?f.slice(t.cwd.length+1):f,g=await uf(t,h,n,r,s,i);a+=g.stdout,l+=g.stderr,g.exitCode!==0&&(c=g.exitCode)}}return{stdout:a,stderr:l,exitCode:c}}async function
|
|
608
|
+
`,exitCode:0}}return{stdout:"",stderr:"",exitCode:0}}}async function ff(t,e,n,r,s,i){let o=await t.fs.readdir(e),a="",l="",c=0;for(let u of o){let f=t.fs.resolvePath(e,u),d=await t.fs.stat(f);if(d.isDirectory){let p=await ff(t,f,n,r,s,i);a+=p.stdout,l+=p.stderr,p.exitCode!==0&&(c=p.exitCode)}else if(d.isFile){let p=n.suffix;if(s&&!u.endsWith(p)||!s&&u.endsWith(p))continue;let h=f.startsWith(`${t.cwd}/`)?f.slice(t.cwd.length+1):f,g=await uf(t,h,n,r,s,i);a+=g.stdout,l+=g.stderr,g.exitCode!==0&&(c=g.exitCode)}}return{stdout:a,stderr:l,exitCode:c}}async function dx(t,e,n,r){let s;if(e==="-"||e==="")s=Uint8Array.from(t.stdin,f=>f.charCodeAt(0));else{let f=t.fs.resolvePath(t.cwd,e);try{s=await t.fs.readFileBuffer(f)}catch{return{stdout:"",stderr:`${r}: ${e}: No such file or directory
|
|
609
609
|
`,exitCode:1}}}if(!vr(s))return n.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${e}: not in gzip format
|
|
610
|
-
`,exitCode:1};let i=s.length,o=
|
|
611
|
-
`,stderr:"",exitCode:0}}async function
|
|
610
|
+
`,exitCode:1};let i=s.length,o=fx(s),a=o>0?((1-i/o)*100).toFixed(1):"0.0",c=cf(s).originalName||(e==="-"?"":e.replace(/\.gz$/,""));return{stdout:`${i.toString().padStart(10)} ${o.toString().padStart(10)} ${a.padStart(5)}% ${c}
|
|
611
|
+
`,stderr:"",exitCode:0}}async function px(t,e,n,r){let s;if(e==="-"||e==="")s=Uint8Array.from(t.stdin,i=>i.charCodeAt(0));else{let i=t.fs.resolvePath(t.cwd,e);try{s=await t.fs.readFileBuffer(i)}catch{return{stdout:"",stderr:`${r}: ${e}: No such file or directory
|
|
612
612
|
`,exitCode:1}}}if(!vr(s))return n.quiet?{stdout:"",stderr:"",exitCode:1}:{stdout:"",stderr:`${r}: ${e}: not in gzip format
|
|
613
613
|
`,exitCode:1};try{return si(s),n.verbose?{stdout:"",stderr:`${e}: OK
|
|
614
614
|
`,exitCode:0}:{stdout:"",stderr:"",exitCode:0}}catch(i){let o=i instanceof Error?i.message:"invalid";return{stdout:"",stderr:`${r}: ${e}: ${o}
|
|
615
|
-
`,exitCode:1}}}async function ii(t,e,n){let r=n==="zcat"?
|
|
616
|
-
`,p="",h=0;for(let g of o){let m=await
|
|
615
|
+
`,exitCode:1}}}async function ii(t,e,n){let r=n==="zcat"?cx:n==="gunzip"?lx:ax;if(I(t))return N(r);let s=J(n,t,ux);if(!s.ok)return s.error.stderr.includes("unrecognized option"),s.error;let i=s.result.flags,o=s.result.positional,a=n==="gunzip"||n==="zcat"||i.decompress||i.uncompress,l=n==="zcat"||i.stdout||i.toStdout;if(i.list){o.length===0&&(o=["-"]);let d=` compressed uncompressed ratio uncompressed_name
|
|
616
|
+
`,p="",h=0;for(let g of o){let m=await dx(e,g,i,n);d+=m.stdout,p+=m.stderr,m.exitCode!==0&&(h=m.exitCode)}return{stdout:d,stderr:p,exitCode:h}}if(i.test){o.length===0&&(o=["-"]);let d="",p="",h=0;for(let g of o){let m=await px(e,g,i,n);d+=m.stdout,p+=m.stderr,m.exitCode!==0&&(h=m.exitCode)}return{stdout:d,stderr:p,exitCode:h}}o.length===0&&(o=["-"]);let c="",u="",f=0;for(let d of o){let p=await uf(e,d,i,n,a,l);c+=p.stdout,u+=p.stderr,p.exitCode!==0&&(f=p.exitCode)}return{stdout:c,stderr:u,exitCode:f}}var ax,lx,cx,ux,hx,mx,gx,Rr=C(()=>{"use strict";Ae();j();ax={name:"gzip",summary:"compress or expand files",usage:"gzip [OPTION]... [FILE]...",description:`Compress FILEs (by default, in-place).
|
|
617
617
|
|
|
618
618
|
When no FILE is given, or when FILE is -, read from standard input.
|
|
619
619
|
|
|
620
|
-
With -d, decompress instead.`,options:["-c, --stdout write to standard output, keep original files","-d, --decompress decompress","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not save or restore the original name and timestamp","-N, --name save or restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode","-1, --fast compress faster","-9, --best compress better"," --help display this help and exit"]},
|
|
620
|
+
With -d, decompress instead.`,options:["-c, --stdout write to standard output, keep original files","-d, --decompress decompress","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not save or restore the original name and timestamp","-N, --name save or restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode","-1, --fast compress faster","-9, --best compress better"," --help display this help and exit"]},lx={name:"gunzip",summary:"decompress files",usage:"gunzip [OPTION]... [FILE]...",description:`Decompress FILEs (by default, in-place).
|
|
621
621
|
|
|
622
|
-
When no FILE is given, or when FILE is -, read from standard input.`,options:["-c, --stdout write to standard output, keep original files","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not restore the original name and timestamp","-N, --name restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},
|
|
622
|
+
When no FILE is given, or when FILE is -, read from standard input.`,options:["-c, --stdout write to standard output, keep original files","-f, --force force overwrite of output file","-k, --keep keep (don't delete) input files","-l, --list list compressed file contents","-n, --no-name do not restore the original name and timestamp","-N, --name restore the original file name and timestamp","-q, --quiet suppress all warnings","-r, --recursive operate recursively on directories","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},cx={name:"zcat",summary:"decompress files to stdout",usage:"zcat [OPTION]... [FILE]...",description:`Decompress FILEs to standard output.
|
|
623
623
|
|
|
624
|
-
When no FILE is given, or when FILE is -, read from standard input.`,options:["-f, --force force; read compressed data even from a terminal","-l, --list list compressed file contents","-q, --quiet suppress all warnings","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},
|
|
624
|
+
When no FILE is given, or when FILE is -, read from standard input.`,options:["-f, --force force; read compressed data even from a terminal","-l, --list list compressed file contents","-q, --quiet suppress all warnings","-S, --suffix=SUF use suffix SUF on compressed files (default: .gz)","-t, --test test compressed file integrity","-v, --verbose verbose mode"," --help display this help and exit"]},ux={stdout:{short:"c",long:"stdout",type:"boolean"},toStdout:{long:"to-stdout",type:"boolean"},decompress:{short:"d",long:"decompress",type:"boolean"},uncompress:{long:"uncompress",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},keep:{short:"k",long:"keep",type:"boolean"},list:{short:"l",long:"list",type:"boolean"},noName:{short:"n",long:"no-name",type:"boolean"},name:{short:"N",long:"name",type:"boolean"},quiet:{short:"q",long:"quiet",type:"boolean"},recursive:{short:"r",long:"recursive",type:"boolean"},suffix:{short:"S",long:"suffix",type:"string",default:".gz"},test:{short:"t",long:"test",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"},fast:{short:"1",long:"fast",type:"boolean"},level2:{short:"2",type:"boolean"},level3:{short:"3",type:"boolean"},level4:{short:"4",type:"boolean"},level5:{short:"5",type:"boolean"},level6:{short:"6",type:"boolean"},level7:{short:"7",type:"boolean"},level8:{short:"8",type:"boolean"},best:{short:"9",long:"best",type:"boolean"}};hx={name:"gzip",async execute(t,e){return ii(t,e,"gzip")}},mx={name:"gunzip",async execute(t,e){return ii(t,e,"gunzip")}},gx={name:"zcat",async execute(t,e){return ii(t,e,"zcat")}}});function oi(t){let e=t.indexOf("=");if(e>=0){let n=t.slice(0,e),r=t.slice(e+1);return n?`${encodeURIComponent(n)}=${encodeURIComponent(r)}`:encodeURIComponent(r)}return encodeURIComponent(t)}function ai(t){let e=t.indexOf("=");if(e<0)return null;let n=t.slice(0,e),r=t.slice(e+1),s,i,o=r.match(/;type=([^;]+)$/);o&&(i=o[1],r=r.slice(0,-o[0].length));let a=r.match(/;filename=([^;]+)/);return a&&(s=a[1],r=r.replace(a[0],"")),(r.startsWith("@")||r.startsWith("<"))&&(s=s??r.slice(1).split("/").pop()),{name:n,value:r,filename:s,contentType:i}}function df(t,e){let n=`----CurlFormBoundary${Date.now().toString(36)}`,r=[];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=`--${n}\r
|
|
625
625
|
`;s.filename?(o+=`Content-Disposition: form-data; name="${s.name}"; filename="${s.filename}"\r
|
|
626
626
|
`,s.contentType&&(o+=`Content-Type: ${s.contentType}\r
|
|
627
627
|
`)):o+=`Content-Disposition: form-data; name="${s.name}"\r
|
|
@@ -630,7 +630,7 @@ ${i}\r
|
|
|
630
630
|
`,r.push(o)}return r.push(`--${n}--\r
|
|
631
631
|
`),{body:r.join(""),boundary:n}}var li=C(()=>{"use strict"});var pf,hf=C(()=>{"use strict";pf={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 mf(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 n=0;n<t.length;n++){let r=t[n];if(r==="-X"||r==="--request")e.method=t[++n]??"GET";else if(r.startsWith("-X"))e.method=r.slice(2);else if(r.startsWith("--request="))e.method=r.slice(10);else if(r==="-H"||r==="--header"){let s=t[++n];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(r.startsWith("--header=")){let s=r.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(r==="-d"||r==="--data"||r==="--data-raw")e.data=t[++n]??"",e.method==="GET"&&(e.method="POST");else if(r.startsWith("-d"))e.data=r.slice(2),e.method==="GET"&&(e.method="POST");else if(r.startsWith("--data="))e.data=r.slice(7),e.method==="GET"&&(e.method="POST");else if(r.startsWith("--data-raw="))e.data=r.slice(11),e.method==="GET"&&(e.method="POST");else if(r==="--data-binary")e.data=t[++n]??"",e.dataBinary=!0,e.method==="GET"&&(e.method="POST");else if(r.startsWith("--data-binary="))e.data=r.slice(14),e.dataBinary=!0,e.method==="GET"&&(e.method="POST");else if(r==="--data-urlencode"){let s=t[++n]??"";e.data=(e.data?`${e.data}&`:"")+oi(s),e.method==="GET"&&(e.method="POST")}else if(r.startsWith("--data-urlencode=")){let s=r.slice(17);e.data=(e.data?`${e.data}&`:"")+oi(s),e.method==="GET"&&(e.method="POST")}else if(r==="-F"||r==="--form"){let s=t[++n]??"",i=ai(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(r.startsWith("--form=")){let s=r.slice(7),i=ai(s);i&&e.formFields.push(i),e.method==="GET"&&(e.method="POST")}else if(r==="-u"||r==="--user")e.user=t[++n];else if(r.startsWith("-u"))e.user=r.slice(2);else if(r.startsWith("--user="))e.user=r.slice(7);else if(r==="-A"||r==="--user-agent")e.headers["User-Agent"]=t[++n]??"";else if(r.startsWith("-A"))e.headers["User-Agent"]=r.slice(2);else if(r.startsWith("--user-agent="))e.headers["User-Agent"]=r.slice(13);else if(r==="-e"||r==="--referer")e.headers.Referer=t[++n]??"";else if(r.startsWith("-e"))e.headers.Referer=r.slice(2);else if(r.startsWith("--referer="))e.headers.Referer=r.slice(10);else if(r==="-b"||r==="--cookie")e.headers.Cookie=t[++n]??"";else if(r.startsWith("-b"))e.headers.Cookie=r.slice(2);else if(r.startsWith("--cookie="))e.headers.Cookie=r.slice(9);else if(r==="-c"||r==="--cookie-jar")e.cookieJar=t[++n];else if(r.startsWith("--cookie-jar="))e.cookieJar=r.slice(13);else if(r==="-T"||r==="--upload-file")e.uploadFile=t[++n],e.method==="GET"&&(e.method="PUT");else if(r.startsWith("--upload-file="))e.uploadFile=r.slice(14),e.method==="GET"&&(e.method="PUT");else if(r==="-m"||r==="--max-time"){let s=parseFloat(t[++n]??"0");!Number.isNaN(s)&&s>0&&(e.timeoutMs=s*1e3)}else if(r.startsWith("--max-time=")){let s=parseFloat(r.slice(11));!Number.isNaN(s)&&s>0&&(e.timeoutMs=s*1e3)}else if(r==="--connect-timeout"){let s=parseFloat(t[++n]??"0");!Number.isNaN(s)&&s>0&&e.timeoutMs===void 0&&(e.timeoutMs=s*1e3)}else if(r.startsWith("--connect-timeout=")){let s=parseFloat(r.slice(18));!Number.isNaN(s)&&s>0&&e.timeoutMs===void 0&&(e.timeoutMs=s*1e3)}else if(r==="-o"||r==="--output")e.outputFile=t[++n];else if(r.startsWith("--output="))e.outputFile=r.slice(9);else if(r==="-O"||r==="--remote-name")e.useRemoteName=!0;else if(r==="-I"||r==="--head")e.headOnly=!0,e.method="HEAD";else if(r==="-i"||r==="--include")e.includeHeaders=!0;else if(r==="-s"||r==="--silent")e.silent=!0;else if(r==="-S"||r==="--show-error")e.showError=!0;else if(r==="-f"||r==="--fail")e.failSilently=!0;else if(r==="-L"||r==="--location")e.followRedirects=!0;else if(r==="--max-redirs")n++;else if(!r.startsWith("--max-redirs="))if(r==="-w"||r==="--write-out")e.writeOut=t[++n];else if(r.startsWith("--write-out="))e.writeOut=r.slice(12);else if(r==="-v"||r==="--verbose")e.verbose=!0;else{if(r.startsWith("--")&&r!=="--")return L("curl",r);if(r.startsWith("-")&&r!=="-")for(let s of r.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 r.startsWith("-")||(e.url=r)}}return e}var gf=C(()=>{"use strict";j();li()});function ci(t){return Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(`\r
|
|
632
632
|
`)}function yf(t){try{return new URL(t).pathname.split("/").pop()||"index.html"}catch{return"index.html"}}function ui(t,e){let n=t;return n=n.replace(/%\{http_code\}/g,String(e.status)),n=n.replace(/%\{content_type\}/g,e.headers["content-type"]||""),n=n.replace(/%\{url_effective\}/g,e.url),n=n.replace(/%\{size_download\}/g,String(e.bodyLength)),n=n.replace(/\\n/g,`
|
|
633
|
-
`),n}var xf=C(()=>{"use strict"});var wf={};M(wf,{curlCommand:()=>
|
|
633
|
+
`),n}var xf=C(()=>{"use strict"});var wf={};M(wf,{curlCommand:()=>Ex});async function yx(t,e){if(t.uploadFile){let n=e.fs.resolvePath(e.cwd,t.uploadFile);return{body:await e.fs.readFile(n)}}if(t.formFields.length>0){let n=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);n.set(i.value.slice(1),a)}catch{n.set(i.value.slice(1),"")}}let{body:r,boundary:s}=df(t.formFields,n);return{body:r,contentType:`multipart/form-data; boundary=${s}`}}return t.data!==void 0?{body:t.data}:{}}function xx(t,e){let n={...t.headers};if(t.user){let r=Buffer.from(t.user).toString("base64");n.Authorization=`Basic ${r}`}return e&&!n["Content-Type"]&&(n["Content-Type"]=e),n}async function wx(t,e,n){if(!t.cookieJar)return;let r=e["set-cookie"];if(!r)return;let s=n.fs.resolvePath(n.cwd,t.cookieJar);await n.fs.writeFile(s,r)}function bx(t,e,n){let r="";if(t.verbose){r+=`> ${t.method} ${n}
|
|
634
634
|
`;for(let[s,i]of Object.entries(t.headers))r+=`> ${s}: ${i}
|
|
635
635
|
`;r+=`>
|
|
636
636
|
`,r+=`< HTTP/1.1 ${e.status} ${e.statusText}
|
|
@@ -641,23 +641,23 @@ ${i}\r
|
|
|
641
641
|
\r
|
|
642
642
|
`),t.headOnly?t.includeHeaders||t.verbose||(r+=`HTTP/1.1 ${e.status} ${e.statusText}\r
|
|
643
643
|
`,r+=ci(e.headers),r+=`\r
|
|
644
|
-
`):r+=e.body,t.writeOut&&(r+=ui(t.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.length})),r}var
|
|
644
|
+
`):r+=e.body,t.writeOut&&(r+=ui(t.writeOut,{status:e.status,headers:e.headers,url:e.url,bodyLength:e.body.length})),r}var Ex,bf=C(()=>{"use strict";nt();j();li();hf();gf();xf();Ex={name:"curl",async execute(t,e){if(I(t))return N(pf);let n=mf(t);if("exitCode"in n)return n;let r=n;if(!r.url)return{stdout:"",stderr:`curl: no URL specified
|
|
645
645
|
`,exitCode:2};if(!e.fetch)return{stdout:"",stderr:`curl: internal error: fetch not available
|
|
646
|
-
`,exitCode:1};let s=r.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:o}=await
|
|
647
|
-
`:"",exitCode:22};let c=
|
|
648
|
-
`:"",exitCode:a}}}}});var fi=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(uo(),co))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(po(),fo))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>(yo(),go))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(Eo(),bo))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(Co(),So))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(ko(),Ao))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>(Io(),No))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>($o(),vo))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(Fo(),Ro))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>(To(),Po))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Lo(),Do))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(_o(),Mo))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Wo(),Bo))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(Ho(),zo))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(qo(),Go))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(Ko(),Zo))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(Jo(),Xo))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).egrepCommand},{name:"rg",load:async()=>(await Promise.resolve().then(()=>(wa(),xa))).rgCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(Ia(),Na))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(Qa(),Ka))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(ol(),il))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(ll(),al))).uniqCommand},{name:"comm",load:async()=>(await Promise.resolve().then(()=>(ul(),cl))).commCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(dl(),fl))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(ml(),hl))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(xl(),yl))).trCommand},{name:"rev",load:async()=>(await Promise.resolve().then(()=>(bl(),wl))).rev},{name:"nl",load:async()=>(await Promise.resolve().then(()=>(Cl(),Sl))).nl},{name:"fold",load:async()=>(await Promise.resolve().then(()=>(Nl(),kl))).fold},{name:"expand",load:async()=>(await Promise.resolve().then(()=>($l(),vl))).expand},{name:"unexpand",load:async()=>(await Promise.resolve().then(()=>(Tl(),Pl))).unexpand},{name:"strings",load:async()=>(await Promise.resolve().then(()=>(Ml(),Ll))).strings},{name:"split",load:async()=>(await Promise.resolve().then(()=>(Wl(),Bl))).split},{name:"column",load:async()=>(await Promise.resolve().then(()=>(zl(),jl))).column},{name:"join",load:async()=>(await Promise.resolve().then(()=>(Gl(),Hl))).join},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(Vl(),ql))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(nc(),tc))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(sc(),rc))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(oc(),ic))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(cc(),lc))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(dc(),fc))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Ts(),Ps))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Ts(),Ps))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(Ds(),Os))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(Ds(),Os))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(mc(),hc))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>(yc(),gc))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(Ms(),Ls))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(Ms(),Ls))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(wc(),xc))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(Bs(),_s))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(Bs(),_s))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(Fc(),Rc))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(Oc(),Tc))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(Mc(),Lc))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(Bc(),_c))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(Uc(),Wc))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>(zc(),jc))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(Gc(),Hc))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(Vc(),qc))).exprCommand},{name:"md5sum",load:async()=>(await Promise.resolve().then(()=>(Qc(),Kc))).md5sumCommand},{name:"sha1sum",load:async()=>(await Promise.resolve().then(()=>(Jc(),Xc))).sha1sumCommand},{name:"sha256sum",load:async()=>(await Promise.resolve().then(()=>(eu(),Yc))).sha256sumCommand},{name:"file",load:async()=>(await Promise.resolve().then(()=>(Vu(),qu))).fileCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(Ku(),Zu))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(Xu(),Qu))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(Yu(),Ju))).whichCommand},{name:"tac",load:async()=>(await Promise.resolve().then(()=>(tf(),ef))).tac},{name:"hostname",load:async()=>(await Promise.resolve().then(()=>(rf(),nf))).hostname},{name:"od",load:async()=>(await Promise.resolve().then(()=>(of(),sf))).od},{name:"gzip",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).gzipCommand},{name:"gunzip",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).gunzipCommand},{name:"zcat",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).zcatCommand}],Sf=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(bf(),wf))).curlCommand}],Ef=new Map;function Cf(t){return{name:t.name,async execute(e,n){let r=Ef.get(t.name);return r||(r=await t.load(),Ef.set(t.name,r)),r.execute(e,n)}}}function gx(){return fi.map(t=>t.name)}function yx(){return Sf.map(t=>t.name)}function Af(t){return(t?fi.filter(n=>t.includes(n.name)):fi).map(Cf)}function kf(){return Sf.map(Cf)}function Nf(t){return"load"in t&&typeof t.load=="function"}function xx(t,e){return{name:t,execute:e}}function If(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var wx=new TextEncoder,bx=new TextDecoder;function di(t,e){if(t instanceof Uint8Array)return t;if(e==="base64")return Uint8Array.from(atob(t),n=>n.charCodeAt(0));if(e==="hex"){let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}return e==="binary"||e==="latin1"?Uint8Array.from(t,n=>n.charCodeAt(0)):wx.encode(t)}function vf(t,e){return e==="base64"?btoa(String.fromCharCode(...t)):e==="hex"?Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join(""):e==="binary"||e==="latin1"?String.fromCharCode(...t):bx.decode(t)}function Fr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Pr=new TextEncoder;function Ex(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var Bt=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))Ex(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(i=>i&&i!=="."),s=[];for(let i of r)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let i=this.normalizePath(e);this.ensureParentDirs(i);let o=Fr(r),a=di(n,o);this.data.set(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=Fr(n);return vf(r,s)}async readFileBuffer(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Pr.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){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=Fr(r),a=di(n,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:Pr.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,n,r)}async exists(e){try{let n=this.resolvePathWithSymlinks(e);return this.data.has(n)}catch{return!1}}async stat(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Pr.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.resolveIntermediateSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Pr.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}resolveIntermediateSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`);i.add(s),s=this.resolveSymlink(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);i.add(s),s=this.resolveSymlink(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`)}return s}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){return(await this.readdirWithFileTypes(e)).map(r=>r.name)}async readdirWithFileTypes(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);s.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let o of i){let a=r==="/"?`/${o}`:`${r}/${o}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),i=this.normalizePath(n),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(!r?.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,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),i=this.data.get(r);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 '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};var $f="5.1.0(1)-release",Rf="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Bn(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function Ff(){let{pid:t,ppid:e,uid:n,gid:r}=Bn();return`Name: bash
|
|
646
|
+
`,exitCode:1};let s=r.url;s.match(/^https?:\/\//)||(s=`https://${s}`);try{let{body:i,contentType:o}=await yx(r,e),a=xx(r,o),l=await e.fetch(s,{method:r.method,headers:Object.keys(a).length>0?a:void 0,body:i,followRedirects:r.followRedirects,timeoutMs:r.timeoutMs});if(await wx(r,l.headers,e),r.failSilently&&l.status>=400)return{stdout:"",stderr:r.showError||!r.silent?`curl: (22) The requested URL returned error: ${l.status}
|
|
647
|
+
`:"",exitCode:22};let c=bx(r,l,s);if(r.outputFile||r.useRemoteName){let u=r.outputFile||yf(s),f=e.fs.resolvePath(e.cwd,u);await e.fs.writeFile(f,r.headOnly?"":l.body),r.verbose||(c=""),r.writeOut&&(c=ui(r.writeOut,{status:l.status,headers:l.headers,url:l.url,bodyLength:l.body.length}))}return{stdout:c,stderr:"",exitCode:0}}catch(i){let o=ye(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:!r.silent||r.showError?`curl: (${a}) ${o}
|
|
648
|
+
`:"",exitCode:a}}}}});var fi=[{name:"echo",load:async()=>(await Promise.resolve().then(()=>(uo(),co))).echoCommand},{name:"cat",load:async()=>(await Promise.resolve().then(()=>(po(),fo))).catCommand},{name:"printf",load:async()=>(await Promise.resolve().then(()=>(yo(),go))).printfCommand},{name:"ls",load:async()=>(await Promise.resolve().then(()=>(Eo(),bo))).lsCommand},{name:"mkdir",load:async()=>(await Promise.resolve().then(()=>(Co(),So))).mkdirCommand},{name:"touch",load:async()=>(await Promise.resolve().then(()=>(ko(),Ao))).touchCommand},{name:"rm",load:async()=>(await Promise.resolve().then(()=>(Io(),No))).rmCommand},{name:"cp",load:async()=>(await Promise.resolve().then(()=>($o(),vo))).cpCommand},{name:"mv",load:async()=>(await Promise.resolve().then(()=>(Fo(),Ro))).mvCommand},{name:"ln",load:async()=>(await Promise.resolve().then(()=>(To(),Po))).lnCommand},{name:"chmod",load:async()=>(await Promise.resolve().then(()=>(Lo(),Do))).chmodCommand},{name:"pwd",load:async()=>(await Promise.resolve().then(()=>(_o(),Mo))).pwdCommand},{name:"readlink",load:async()=>(await Promise.resolve().then(()=>(Wo(),Bo))).readlinkCommand},{name:"head",load:async()=>(await Promise.resolve().then(()=>(Ho(),zo))).headCommand},{name:"tail",load:async()=>(await Promise.resolve().then(()=>(qo(),Go))).tailCommand},{name:"wc",load:async()=>(await Promise.resolve().then(()=>(Ko(),Zo))).wcCommand},{name:"stat",load:async()=>(await Promise.resolve().then(()=>(Jo(),Xo))).statCommand},{name:"grep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).grepCommand},{name:"fgrep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).fgrepCommand},{name:"egrep",load:async()=>(await Promise.resolve().then(()=>(sr(),rr))).egrepCommand},{name:"rg",load:async()=>(await Promise.resolve().then(()=>(wa(),xa))).rgCommand},{name:"sed",load:async()=>(await Promise.resolve().then(()=>(Ia(),Na))).sedCommand},{name:"awk",load:async()=>(await Promise.resolve().then(()=>(Qa(),Ka))).awkCommand2},{name:"sort",load:async()=>(await Promise.resolve().then(()=>(ol(),il))).sortCommand},{name:"uniq",load:async()=>(await Promise.resolve().then(()=>(ll(),al))).uniqCommand},{name:"comm",load:async()=>(await Promise.resolve().then(()=>(ul(),cl))).commCommand},{name:"cut",load:async()=>(await Promise.resolve().then(()=>(dl(),fl))).cutCommand},{name:"paste",load:async()=>(await Promise.resolve().then(()=>(ml(),hl))).pasteCommand},{name:"tr",load:async()=>(await Promise.resolve().then(()=>(xl(),yl))).trCommand},{name:"rev",load:async()=>(await Promise.resolve().then(()=>(bl(),wl))).rev},{name:"nl",load:async()=>(await Promise.resolve().then(()=>(Cl(),Sl))).nl},{name:"fold",load:async()=>(await Promise.resolve().then(()=>(Nl(),kl))).fold},{name:"expand",load:async()=>(await Promise.resolve().then(()=>($l(),vl))).expand},{name:"unexpand",load:async()=>(await Promise.resolve().then(()=>(Tl(),Pl))).unexpand},{name:"strings",load:async()=>(await Promise.resolve().then(()=>(Ml(),Ll))).strings},{name:"split",load:async()=>(await Promise.resolve().then(()=>(Wl(),Bl))).split},{name:"column",load:async()=>(await Promise.resolve().then(()=>(zl(),jl))).column},{name:"join",load:async()=>(await Promise.resolve().then(()=>(Gl(),Hl))).join},{name:"tee",load:async()=>(await Promise.resolve().then(()=>(Vl(),ql))).teeCommand},{name:"find",load:async()=>(await Promise.resolve().then(()=>(nc(),tc))).findCommand},{name:"basename",load:async()=>(await Promise.resolve().then(()=>(sc(),rc))).basenameCommand},{name:"dirname",load:async()=>(await Promise.resolve().then(()=>(oc(),ic))).dirnameCommand},{name:"tree",load:async()=>(await Promise.resolve().then(()=>(cc(),lc))).treeCommand},{name:"du",load:async()=>(await Promise.resolve().then(()=>(dc(),fc))).duCommand},{name:"env",load:async()=>(await Promise.resolve().then(()=>(Ts(),Ps))).envCommand},{name:"printenv",load:async()=>(await Promise.resolve().then(()=>(Ts(),Ps))).printenvCommand},{name:"alias",load:async()=>(await Promise.resolve().then(()=>(Ds(),Os))).aliasCommand},{name:"unalias",load:async()=>(await Promise.resolve().then(()=>(Ds(),Os))).unaliasCommand},{name:"history",load:async()=>(await Promise.resolve().then(()=>(mc(),hc))).historyCommand},{name:"xargs",load:async()=>(await Promise.resolve().then(()=>(yc(),gc))).xargsCommand},{name:"true",load:async()=>(await Promise.resolve().then(()=>(Ms(),Ls))).trueCommand},{name:"false",load:async()=>(await Promise.resolve().then(()=>(Ms(),Ls))).falseCommand},{name:"clear",load:async()=>(await Promise.resolve().then(()=>(wc(),xc))).clearCommand},{name:"bash",load:async()=>(await Promise.resolve().then(()=>(Bs(),_s))).bashCommand},{name:"sh",load:async()=>(await Promise.resolve().then(()=>(Bs(),_s))).shCommand},{name:"jq",load:async()=>(await Promise.resolve().then(()=>(Fc(),Rc))).jqCommand},{name:"base64",load:async()=>(await Promise.resolve().then(()=>(Oc(),Tc))).base64Command},{name:"diff",load:async()=>(await Promise.resolve().then(()=>(Mc(),Lc))).diffCommand},{name:"date",load:async()=>(await Promise.resolve().then(()=>(Bc(),_c))).dateCommand},{name:"sleep",load:async()=>(await Promise.resolve().then(()=>(Uc(),Wc))).sleepCommand},{name:"timeout",load:async()=>(await Promise.resolve().then(()=>(zc(),jc))).timeoutCommand},{name:"seq",load:async()=>(await Promise.resolve().then(()=>(Gc(),Hc))).seqCommand},{name:"expr",load:async()=>(await Promise.resolve().then(()=>(Vc(),qc))).exprCommand},{name:"md5sum",load:async()=>(await Promise.resolve().then(()=>(Qc(),Kc))).md5sumCommand},{name:"sha1sum",load:async()=>(await Promise.resolve().then(()=>(Jc(),Xc))).sha1sumCommand},{name:"sha256sum",load:async()=>(await Promise.resolve().then(()=>(eu(),Yc))).sha256sumCommand},{name:"file",load:async()=>(await Promise.resolve().then(()=>(Vu(),qu))).fileCommand},{name:"html-to-markdown",load:async()=>(await Promise.resolve().then(()=>(Ku(),Zu))).htmlToMarkdownCommand},{name:"help",load:async()=>(await Promise.resolve().then(()=>(Xu(),Qu))).helpCommand},{name:"which",load:async()=>(await Promise.resolve().then(()=>(Yu(),Ju))).whichCommand},{name:"tac",load:async()=>(await Promise.resolve().then(()=>(tf(),ef))).tac},{name:"hostname",load:async()=>(await Promise.resolve().then(()=>(rf(),nf))).hostname},{name:"od",load:async()=>(await Promise.resolve().then(()=>(of(),sf))).od},{name:"gzip",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).gzipCommand},{name:"gunzip",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).gunzipCommand},{name:"zcat",load:async()=>(await Promise.resolve().then(()=>(Rr(),$r))).zcatCommand}],Sf=[{name:"curl",load:async()=>(await Promise.resolve().then(()=>(bf(),wf))).curlCommand}],Ef=new Map;function Cf(t){return{name:t.name,async execute(e,n){let r=Ef.get(t.name);return r||(r=await t.load(),Ef.set(t.name,r)),r.execute(e,n)}}}function Sx(){return fi.map(t=>t.name)}function Cx(){return Sf.map(t=>t.name)}function Af(t){return(t?fi.filter(n=>t.includes(n.name)):fi).map(Cf)}function kf(){return Sf.map(Cf)}function Nf(t){return"load"in t&&typeof t.load=="function"}function Ax(t,e){return{name:t,execute:e}}function If(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var kx=new TextEncoder,Nx=new TextDecoder;function di(t,e){if(t instanceof Uint8Array)return t;if(e==="base64")return Uint8Array.from(atob(t),n=>n.charCodeAt(0));if(e==="hex"){let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}return e==="binary"||e==="latin1"?Uint8Array.from(t,n=>n.charCodeAt(0)):kx.encode(t)}function vf(t,e){return e==="base64"?btoa(String.fromCharCode(...t)):e==="hex"?Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join(""):e==="binary"||e==="latin1"?String.fromCharCode(...t):Nx.decode(t)}function Fr(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Pr=new TextEncoder;function Ix(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var Bt=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))Ix(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(i=>i&&i!=="."),s=[];for(let i of r)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let i=this.normalizePath(e);this.ensureParentDirs(i);let o=Fr(r),a=di(n,o);this.data.set(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=Fr(n);return vf(r,s)}async readFileBuffer(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Pr.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){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=Fr(r),a=di(n,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:Pr.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,n,r)}async exists(e){try{let n=this.resolvePathWithSymlinks(e);return this.data.has(n)}catch{return!1}}async stat(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Pr.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.resolveIntermediateSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Pr.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}resolveIntermediateSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`);i.add(s),s=this.resolveSymlink(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);i.add(s),s=this.resolveSymlink(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`)}return s}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){return(await this.readdirWithFileTypes(e)).map(r=>r.name)}async readdirWithFileTypes(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);s.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let o of i){let a=r==="/"?`/${o}`:`${r}/${o}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),i=this.normalizePath(n),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(!r?.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,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),i=this.data.get(r);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 '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};var $f="5.1.0(1)-release",Rf="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Bn(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function Ff(){let{pid:t,ppid:e,uid:n,gid:r}=Bn();return`Name: bash
|
|
649
649
|
State: R (running)
|
|
650
650
|
Pid: ${t}
|
|
651
651
|
PPid: ${e}
|
|
652
652
|
Uid: ${n} ${n} ${n} ${n}
|
|
653
653
|
Gid: ${r} ${r} ${r} ${r}
|
|
654
|
-
`}function
|
|
654
|
+
`}function vx(t){let e=t;return typeof e.mkdirSync=="function"&&typeof e.writeFileSync=="function"}function $x(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 Rx(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 Fx(t){t.mkdirSync("/proc/self/fd",{recursive:!0}),t.writeFileSync("/proc/version",`${Rf}
|
|
655
655
|
`),t.writeFileSync("/proc/self/exe","/bin/bash"),t.writeFileSync("/proc/self/cmdline","bash\0"),t.writeFileSync("/proc/self/comm",`bash
|
|
656
|
-
`),t.writeFileSync("/proc/self/status",Ff()),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 Pf(t,e){
|
|
657
|
-
`){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var B={script(t){return{type:"Script",statements:t}},statement(t,e=[],n=!1){return{type:"Statement",pipelines:t,operators:e,background:n}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],n=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:n,redirections:r}},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,n=!1,r=null){return{type:"Assignment",name:t,value:e,append:n,array:r}},redirection(t,e,n=null){return{type:"Redirection",fd:n,operator:t,target:e}},hereDoc(t,e,n=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:n,quoted:r}},ifNode(t,e=null,n=[]){return{type:"If",clauses:t,elseBody:e,redirections:n}},forNode(t,e,n,r=[]){return{type:"For",variable:t,words:e,body:n,redirections:r}},whileNode(t,e,n=[]){return{type:"While",condition:t,body:e,redirections:n}},untilNode(t,e,n=[]){return{type:"Until",condition:t,body:e,redirections:n}},caseNode(t,e,n=[]){return{type:"Case",word:t,items:e,redirections:n}},caseItem(t,e,n=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:n}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,n=[]){return{type:"FunctionDef",name:t,body:e,redirections:n}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var y;(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"})(y||(y={}));var Dr={if:y.IF,then:y.THEN,else:y.ELSE,elif:y.ELIF,fi:y.FI,for:y.FOR,while:y.WHILE,until:y.UNTIL,do:y.DO,done:y.DONE,case:y.CASE,esac:y.ESAC,in:y.IN,function:y.FUNCTION,select:y.SELECT,time:y.TIME,coproc:y.COPROC};function Hf(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let n=t.slice(e[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}var
|
|
656
|
+
`),t.writeFileSync("/proc/self/status",Ff()),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 Pf(t,e){vx(t)&&($x(t,e),Rx(t),Fx(t))}de();var Px=["tar","yq","xan","sqlite3"];function Tf(t){return Px.includes(t)}de();function ve(t,e){return{type:"ArithmeticExpression",expression:dt(t,e,0).expr}}function dt(t,e,n){return Tx(t,e,n)}function Tx(t,e,n){let{expr:r,pos:s}=Or(t,e,n);for(s=xe(e,s);e[s]===",";){s++;let{expr:i,pos:o}=Or(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:i},s=xe(e,o)}return{expr:r,pos:s}}function Or(t,e,n){let{expr:r,pos:s}=Ox(t,e,n);if(s=xe(e,s),e[s]==="?"){s++;let{expr:i,pos:o}=dt(t,e,s);if(s=xe(e,o),e[s]===":"){s++;let{expr:a,pos:l}=dt(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Ox(t,e,n){let{expr:r,pos:s}=Of(t,e,n);for(;s=xe(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:i,pos:o}=Of(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:i},s=o}return{expr:r,pos:s}}function Of(t,e,n){let{expr:r,pos:s}=Df(t,e,n);for(;s=xe(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:i,pos:o}=Df(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:i},s=o}return{expr:r,pos:s}}function Df(t,e,n){let{expr:r,pos:s}=Lf(t,e,n);for(;s=xe(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:i,pos:o}=Lf(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:i},s=o}return{expr:r,pos:s}}function Lf(t,e,n){let{expr:r,pos:s}=Mf(t,e,n);for(;s=xe(e,s),e[s]==="^";){s++;let{expr:i,pos:o}=Mf(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:i},s=o}return{expr:r,pos:s}}function Mf(t,e,n){let{expr:r,pos:s}=_f(t,e,n);for(;s=xe(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:i,pos:o}=_f(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:i},s=o}return{expr:r,pos:s}}function _f(t,e,n){let{expr:r,pos:s}=Bf(t,e,n);for(;s=xe(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}=Bf(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Bf(t,e,n){let{expr:r,pos:s}=pi(t,e,n);for(;;)if(s=xe(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}=pi(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(e[s]==="<"||e[s]===">"){let i=e[s];s++;let{expr:o,pos:a}=pi(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function pi(t,e,n){let{expr:r,pos:s}=Wf(t,e,n);for(;s=xe(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}=Wf(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Wf(t,e,n){let{expr:r,pos:s}=Uf(t,e,n);for(;s=xe(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let i=e[s];s++;let{expr:o,pos:a}=Uf(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Uf(t,e,n){let{expr:r,pos:s}=Tr(t,e,n);for(;;)if(s=xe(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:i,pos:o}=Tr(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:i},s=o}else if(e[s]==="/"||e[s]==="%"){let i=e[s];s++;let{expr:o,pos:a}=Tr(t,e,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Tr(t,e,n){let{expr:r,pos:s}=hi(t,e,n),i=xe(e,s);if(e.slice(i,i+2)==="**"){i+=2;let{expr:o,pos:a}=Tr(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:a}}return{expr:r,pos:s}}function hi(t,e,n){let r=xe(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:i,pos:o}=hi(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:i,pos:o}=hi(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Lx(t,e,r)}function Dx(t,e){let n=t[e];return n==="$"||n==="`"}function Lx(t,e,n){let{expr:r,pos:s}=jf(t,e,n),i=[r];for(;Dx(e,s);){let{expr:o,pos:a}=jf(t,e,s);i.push(o),s=a}if(i.length>1&&(r={type:"ArithConcat",parts:i}),s=xe(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:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function jf(t,e,n){let r=xe(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,i=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let o=e.slice(i,r),{expr:a}=dt(t,o,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,i=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let o=e.slice(i,r);return r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let i=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:i}=dt(t,e,r);return r=xe(e,i),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",i=!1;for(;r<e.length;){let a=e[r];if(i)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")i=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new ke(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:un(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+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 r=l,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let o;if(e[r]==="'"||e[r]==='"'){let c=e[r];for(r++,o="";r<e.length&&e[r]!==c;)o+=e[r],r++;e[r]===c&&r++,r=xe(e,r),e[r]==="]"&&r++}let a;if(o===void 0){let{expr:c,pos:u}=dt(t,e,r);a=c,r=u,e[r]==="]"&&r++}if(r=xe(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},pos:r};let l=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let c of l)if(e.slice(r,r+c.length)===c&&e.slice(r,r+c.length+1)!=="=="){r+=c.length;let{expr:u,pos:f}=Or(t,e,r);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:r}}r=xe(e,r);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let o of i)if(e.slice(r,r+o.length)===o&&e.slice(r,r+o.length+1)!=="=="){r+=o.length;let{expr:a,pos:l}=Or(t,e,r);return{expr:{type:"ArithAssignment",operator:o,variable:s,value:a},pos:l}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function un(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let i of n){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>=r)return Number.NaN;s=s*r+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 xe(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
|
|
657
|
+
`){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var B={script(t){return{type:"Script",statements:t}},statement(t,e=[],n=!1){return{type:"Statement",pipelines:t,operators:e,background:n}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],n=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:n,redirections:r}},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,n=!1,r=null){return{type:"Assignment",name:t,value:e,append:n,array:r}},redirection(t,e,n=null){return{type:"Redirection",fd:n,operator:t,target:e}},hereDoc(t,e,n=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:n,quoted:r}},ifNode(t,e=null,n=[]){return{type:"If",clauses:t,elseBody:e,redirections:n}},forNode(t,e,n,r=[]){return{type:"For",variable:t,words:e,body:n,redirections:r}},whileNode(t,e,n=[]){return{type:"While",condition:t,body:e,redirections:n}},untilNode(t,e,n=[]){return{type:"Until",condition:t,body:e,redirections:n}},caseNode(t,e,n=[]){return{type:"Case",word:t,items:e,redirections:n}},caseItem(t,e,n=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:n}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,n=[]){return{type:"FunctionDef",name:t,body:e,redirections:n}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var y;(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"})(y||(y={}));var Dr={if:y.IF,then:y.THEN,else:y.ELSE,elif:y.ELIF,fi:y.FI,for:y.FOR,while:y.WHILE,until:y.UNTIL,do:y.DO,done:y.DONE,case:y.CASE,esac:y.ESAC,in:y.IN,function:y.FUNCTION,select:y.SELECT,time:y.TIME,coproc:y.COPROC};function Hf(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let n=t.slice(e[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}var Mx=[[";",";","&",y.SEMI_SEMI_AND],["<","<","<",y.TLESS],["&",">",">",y.AND_DGREAT]],_x=[["[","[",y.DBRACK_START],["]","]",y.DBRACK_END],["(","(",y.DPAREN_START],[")",")",y.DPAREN_END],["&","&",y.AND_AND],["|","|",y.OR_OR],[";",";",y.DSEMI],[";","&",y.SEMI_AND],["|","&",y.PIPE_AMP],[">",">",y.DGREAT],["<","&",y.LESSAND],[">","&",y.GREATAND],["<",">",y.LESSGREAT],[">","|",y.CLOBBER],["&",">",y.AND_GREAT]],Bx={"|":y.PIPE,"&":y.AMP,";":y.SEMICOLON,"(":y.LPAREN,")":y.RPAREN,"<":y.LESS,">":y.GREAT};function Wx(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Lr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===y.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:y.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let e=this.input,n=e.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=e[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&e[r+1]===`
|
|
658
658
|
`)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let e=this.input,n=this.pos,r=this.line,s=this.column,i=e[n],o=e[n+1],a=e[n+2];if(i==="#")return this.readComment(n,r,s);if(i===`
|
|
659
659
|
`)return this.pos=n+1,this.line++,this.column=1,{type:y.NEWLINE,value:`
|
|
660
|
-
`,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(y.DLESSDASH,"<<-",n,r,s);for(let[c,u,f,d]of
|
|
660
|
+
`,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(y.DLESSDASH,"<<-",n,r,s);for(let[c,u,f,d]of Mx)if(i===c&&o===u&&a===f)return this.pos=n+3,this.column=s+3,this.makeToken(d,c+u+f,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(y.DLESS,"<<",n,r,s);for(let[c,u,f]of _x)if(i===c&&o===u)return this.pos=n+2,this.column=s+2,this.makeToken(f,c+u,n,r,s);let l=Bx[i];return l?(this.pos=n+1,this.column=s+1,this.makeToken(l,i,n,r,s)):i==="{"?o==="}"?(this.pos=n+2,this.column=s+2,{type:y.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
|
|
661
661
|
`?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(y.LBRACE,"{",n,r,s)):i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(y.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(y.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(y.BANG,"!",n,r,s)):this.readWord(n,r,s)}makeToken(e,n,r,s,i){return{type:e,value:n,start:r,end:this.pos,line:s,column:i}}readComment(e,n,r){let s=this.input,i=s.length,o=this.pos;for(;o<i&&s[o]!==`
|
|
662
662
|
`;)o++;let a=s.slice(e,o);return this.pos=o,this.column=r+(o-e),{type:y.COMMENT,value:a,start:e,end:o,line:n,column:r}}readWord(e,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let m=s[o];if(m===" "||m===" "||m===`
|
|
663
663
|
`||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">"||m==="'"||m==='"'||m==="\\"||m==="$"||m==="`"||m==="{"||m==="}"||m==="~"||m==="*"||m==="?"||m==="[")break;o++}if(o>a){let m=s[o];if(o>=i||m===" "||m===" "||m===`
|
|
@@ -670,7 +670,7 @@ Gid: ${r} ${r} ${r} ${r}
|
|
|
670
670
|
`&&(c++,l=0),o++,l++}continue}if(m==="$"&&o+1<i&&s[o+1]==="{"){u+=m,o++,l++,u+=s[o],o++,l++;let w=1;for(;w>0&&o<i;){let b=s[o];u+=b,b==="{"?w++:b==="}"?w--:b===`
|
|
671
671
|
`&&(c++,l=0),o++,l++}continue}if(m==="$"&&o+1<i){let w=s[o+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){u+=m+w,o+=2,l+=2;continue}}if(m==="`"){for(u+=m,o++,l++;o<i&&s[o]!=="`";){let w=s[o];u+=w,w==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),w===`
|
|
672
672
|
`&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=m,o++,m===`
|
|
673
|
-
`?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,u==="")return{type:y.WORD,value:"",start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d};if(!f&&Dr[u])return{type:Dr[u],value:u,start:e,end:o,line:n,column:r};if(!g){let m=u.indexOf("=");if(m>0&&Hf(u.slice(0,m)))return{type:y.ASSIGNMENT_WORD,value:u,start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:y.NUMBER,value:u,start:e,end:o,line:n,column:r}:
|
|
673
|
+
`?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,u==="")return{type:y.WORD,value:"",start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d};if(!f&&Dr[u])return{type:Dr[u],value:u,start:e,end:o,line:n,column:r};if(!g){let m=u.indexOf("=");if(m>0&&Hf(u.slice(0,m)))return{type:y.ASSIGNMENT_WORD,value:u,start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:y.NUMBER,value:u,start:e,end:o,line:n,column:r}:Wx(u)?{type:y.NAME,value:u,start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:y.WORD,value:u,start:e,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let e=this.pendingHeredocs.shift();if(!e)break;let n=this.pos,r=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]!==`
|
|
674
674
|
`;)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]===`
|
|
675
675
|
`&&(this.pos++,this.line++,this.column=1);break}i+=a,this.pos<this.input.length&&this.input[this.pos]===`
|
|
676
676
|
`&&(i+=`
|
|
@@ -678,48 +678,48 @@ Gid: ${r} ${r} ${r} ${r}
|
|
|
678
678
|
`||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(e,n,r){let s=this.input,i=s.length,o=e,a=r;for(;o<i;){let c=s[o];if(c===" "||c===" "||c===`
|
|
679
679
|
`||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:y.WORD,value:l,start:e,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let n=this.input,r=n.length,s=e+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
|
|
680
680
|
`||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(o||a)?n.slice(e,s):null}scanLiteralBraceWord(e){let n=this.input,r=n.length,s=e+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return n.slice(e,s+1);s++}else{if(o===" "||o===" "||o===`
|
|
681
|
-
`||o===";"||o==="&"||o==="|")return null;s++}}return null}};var mi=1e6,gi=1e5,Gf=1e6,qf=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.AND_DGREAT]),Vf=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS]),pt=class extends Error{line;column;token;constructor(e,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${e}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}};function Kf(t,e,n){let r=n+1;for(;r<e.length&&/[a-zA-Z0-9_-]/.test(e[r]);)r++;return r}function yi(t,e,n,r,s){let i=1,o=n+1;for(;o<e.length&&i>0;)e[o]===r?i++:e[o]===s&&i--,i>0&&o++;return i===0?o:-1}function Wt(t,e,n){let r=n,s=1;for(;r<e.length&&s>0;){let i=e[r];if(i==="\\"&&r+1<e.length){r+=2;continue}if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function Qf(t,e,n){let r=n,s=!1;for(;r<e.length;){let i=e[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function Xf(t,e,n){let r=n,s="";for(;r<e.length;){let i=e[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=
|
|
682
|
-
`,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=e.slice(s+2,s+4),l=parseInt(a,16);Number.isNaN(l)?(r+="\\x",s+=2):(r+=String.fromCharCode(l),s+=4);break}case"u":{let a=e.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=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);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<e.length&&e[s]==="'"&&s++,{part:B.literal(r),endIndex:s}}function xi(t,e){let n=e.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:ve(t,n)}function Zf(t){let e=[],n="",r=0;for(let s=0;s<t.length;s++){let i=t[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(e.push(n),n=""):n+=i}return e.push(n),e}function Yf(t,e,n,r){let s=yi(t,e,n,"{","}");if(s===-1)return null;let i=e.slice(n+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(",")&&r?{part:{type:"BraceExpansion",items:Zf(i).map(u=>({type:"Word",word:B.word(r(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Zf(i).map(u=>({type:"Word",word:B.word([B.literal(u)])}))},endIndex:s+1}:null}function ed(t,e){let n="";for(let r of e.parts)switch(r.type){case"Literal":case"SingleQuoted":case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;default:n+=r.type}return n}function td(t,e){return{[y.LESS]:"<",[y.GREAT]:">",[y.DGREAT]:">>",[y.LESSAND]:"<&",[y.GREATAND]:">&",[y.LESSGREAT]:"<>",[y.CLOBBER]:">|",[y.TLESS]:"<<<",[y.AND_GREAT]:"&>",[y.AND_DGREAT]:"&>>",[y.DLESS]:"<",[y.DLESSDASH]:"<"}[e]||">"}function Mr(t){let e=t.current(),n=e.type;if(n===y.NUMBER){let r=t.peek(1);return e.end!==r.start?!1:Vf.has(r.type)}return qf.has(n)}function _r(t){let e=null;t.check(y.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let n=t.advance(),r=td(t,n.type);if(n.type===y.DLESS||n.type===y.DLESSDASH)return Lx(t,r,e,n.type===y.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return B.redirection(r,s,e)}function Lx(t,e,n,r){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=B.redirection(r?"<<-":"<<",B.hereDoc(i,B.word([]),r,o),n);return t.addPendingHeredoc(a,i,r,o),a}function rd(t){let e=t.current().line,n=[],r=null,s=[],i=[];for(;t.check(y.ASSIGNMENT_WORD);)t.checkIterationLimit(),n.push(Mx(t));for(;Mr(t);)t.checkIterationLimit(),i.push(_r(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(y.RBRACE))&&!t.check(y.PIPE,y.PIPE_AMP);)if(t.checkIterationLimit(),Mr(t))i.push(_r(t));else if(t.check(y.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(y.ASSIGNMENT_WORD)){let a=t.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||t.check(y.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||t.expect(y.LPAREN);let d=wi(t);t.expect(y.RPAREN);let p=d.map(g=>ed(t,g)),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(y.LPAREN))t.error("syntax error near unexpected token `('");else break;let o=B.simpleCommand(r,s,n,i);return o.line=e,o}function Mx(t){let e=t.expect(y.ASSIGNMENT_WORD),n=e.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||t.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${n}`),i=n.slice(d,o),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&t.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=wi(t);t.expect(y.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return B.assignment(d,null,a,f)}if(l===""&&t.check(y.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let d=wi(t);t.expect(y.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return B.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 B.assignment(u,c,a,null)}function wi(t){let e=[];for(t.skipNewlines();!t.check(y.RPAREN,y.EOF);)t.checkIterationLimit(),t.isWord()?e.push(t.parseWord()):t.advance(),t.skipNewlines();return e}function bi(t){t.expect(y.IF);let e=[],n=t.parseCompoundList();t.expect(y.THEN);let r=t.parseCompoundList();if(r.length===0){let o=t.check(y.FI)?"fi":t.check(y.ELSE)?"else":t.check(y.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${o}'`)}for(e.push({condition:n,body:r});t.check(y.ELIF);){t.advance();let o=t.parseCompoundList();t.expect(y.THEN);let a=t.parseCompoundList();if(a.length===0){let l=t.check(y.FI)?"fi":t.check(y.ELSE)?"else":t.check(y.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${l}'`)}e.push({condition:o,body:a})}let s=null;t.check(y.ELSE)&&(t.advance(),s=t.parseCompoundList(),s.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(y.FI);let i=t.parseOptionalRedirections();return B.ifNode(e,s,i)}function Ei(t){if(t.expect(y.FOR),t.check(y.DPAREN_START))return Bx(t);t.isWord()||t.error("Expected variable name in for loop");let n=t.advance().value,r=null;if(t.skipNewlines(),t.check(y.IN))for(t.advance(),r=[];!t.check(y.SEMICOLON,y.NEWLINE,y.DO,y.EOF)&&t.isWord();)r.push(t.parseWord());t.check(y.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(y.DO);let s=t.parseCompoundList();t.expect(y.DONE);let i=t.parseOptionalRedirections();return B.forNode(n,r,s,i)}function Bx(t){t.expect(y.DPAREN_START);let e=null,n=null,r=null,s=["","",""],i=0,o=0;for(;!t.check(y.DPAREN_END,y.EOF);){let c=t.advance();if(c.type===y.SEMICOLON&&o===0){if(i++,i>2)break}else c.value==="("&&o++,c.value===")"&&o--,s[i]+=c.value}t.expect(y.DPAREN_END),s[0].trim()&&(e=ve(t,s[0].trim())),s[1].trim()&&(n=ve(t,s[1].trim())),s[2].trim()&&(r=ve(t,s[2].trim())),t.skipNewlines(),t.check(y.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(y.DO);let a=t.parseCompoundList();t.expect(y.DONE);let l=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:n,update:r,body:a,redirections:l}}function Si(t){t.expect(y.WHILE);let e=t.parseCompoundList();t.expect(y.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(y.DONE);let r=t.parseOptionalRedirections();return B.whileNode(e,n,r)}function Ci(t){t.expect(y.UNTIL);let e=t.parseCompoundList();t.expect(y.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(y.DONE);let r=t.parseOptionalRedirections();return B.untilNode(e,n,r)}function Ai(t){t.expect(y.CASE),t.isWord()||t.error("Expected word after 'case'");let e=t.parseWord();t.skipNewlines(),t.expect(y.IN),t.skipNewlines();let n=[];for(;!t.check(y.ESAC,y.EOF);){t.checkIterationLimit();let s=t.getPos(),i=Wx(t);if(i&&n.push(i),t.skipNewlines(),t.getPos()===s&&!i)break}t.expect(y.ESAC);let r=t.parseOptionalRedirections();return B.caseNode(e,n,r)}function Wx(t){t.check(y.LPAREN)&&t.advance();let e=[];for(;t.isWord()&&(e.push(t.parseWord()),t.check(y.PIPE));)t.advance();if(e.length===0)return null;t.expect(y.RPAREN),t.skipNewlines();let n=[];for(;!t.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND,y.ESAC,y.EOF);){t.checkIterationLimit(),t.isWord()&&t.peek(1).type===y.RPAREN&&t.error("syntax error near unexpected token `)'"),t.check(y.LPAREN)&&t.peek(1).type===y.WORD&&t.error(`syntax error near unexpected token \`${t.peek(1).value}'`);let s=t.getPos(),i=t.parseStatement();if(i&&n.push(i),t.skipSeparators(!1),t.getPos()===s&&!i)break}let r=";;";return t.check(y.DSEMI)?(t.advance(),r=";;"):t.check(y.SEMI_AND)?(t.advance(),r=";&"):t.check(y.SEMI_SEMI_AND)&&(t.advance(),r=";;&"),B.caseItem(e,n,r)}function ki(t){t.peek(1).type,y.LPAREN,t.expect(y.LPAREN),t.check(y.LPAREN)&&t.advance();let e=t.parseCompoundList();t.expect(y.RPAREN);let n=t.parseOptionalRedirections();return B.subshell(e,n)}function Ni(t){t.expect(y.LBRACE);let e=t.parseCompoundList();t.expect(y.RBRACE);let n=t.parseOptionalRedirections();return B.group(e,n)}var jx=["-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"],zx=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function vi(t){return t.skipNewlines(),Hx(t)}function Hx(t){let e=sd(t);for(t.skipNewlines();t.check(y.OR_OR);){t.advance(),t.skipNewlines();let n=sd(t);e={type:"CondOr",left:e,right:n},t.skipNewlines()}return e}function sd(t){let e=Ii(t);for(t.skipNewlines();t.check(y.AND_AND);){t.advance(),t.skipNewlines();let n=Ii(t);e={type:"CondAnd",left:e,right:n},t.skipNewlines()}return e}function Ii(t){return t.skipNewlines(),t.check(y.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Ii(t)}):Gx(t)}function Gx(t){if(t.check(y.LPAREN)){t.advance();let e=vi(t);return t.expect(y.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),n=e.value;if(jx.includes(n)&&!e.quoted&&(t.advance(),t.check(y.DBRACK_END)&&t.error(`Expected operand after ${n}`),t.isWord())){let s=t.parseWord();return{type:"CondUnary",operator:n,operand:s}}let r=t.parseWord();if(t.isWord()&&zx.includes(t.current().value)){let s=t.advance().value,i=t.parseWord();return{type:"CondBinary",operator:s,left:r,right:i}}if(t.check(y.LESS)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"<",left:r,right:s}}if(t.check(y.GREAT)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:">",left:r,right:s}}if(t.isWord()&&t.current().value==="="){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}t.error("Expected conditional expression")}function Vx(t,e,n){let r=n+1,s=e[r];if("@*#?$!-0123456789".includes(s))return{part:B.parameterExpansion(s),endIndex:r+1};let i="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)i+=e[r],r++;return{part:B.parameterExpansion(i),endIndex:r}}function Zx(t,e,n,r=!1){let s=n+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=yi(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=Kx(t,e,s,a,r);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(n,f+1);t.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:B.parameterExpansion(a,c),endIndex:s+1}}function Kx(t,e,n,r,s=!1){let i=n,o=e[i],a=e[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let w=Wt(t,e,i),b=e.slice(i,w),E=wt(t,b,!1,!1,!0,!1,s),S=B.word(E.length>0?E:[B.literal("")]);if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:w};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:w};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:w};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:w}}i++;let c=Wt(t,e,i),u=e.slice(i,c),f=-1,d=0,p=0;for(let m=0;m<u.length;m++){let w=u[m];if(w==="("||w==="[")d++;else if(w===")"||w==="]")d--;else if(w==="?"&&d===0)p++;else if(w===":"&&d===0)if(p>0)p--;else{f=m;break}}let h=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:xi(t,h),length:g?xi(t,g):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=Wt(t,e,i),c=e.slice(i,l),u=wt(t,c,!1,!1,!0,!1,s),f=B.word(u.length>0?u:[B.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=Wt(t,e,i),f=e.slice(i,u),d=wt(t,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:B.word(d.length>0?d:[B.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=Qf(t,e,i),f=e.slice(i,u),d=wt(t,f,!1,!1,!1),p=B.word(d.length>0?d:[B.literal("")]),h=null,g=u;if(e[u]==="/"){let m=u+1,w=Wt(t,e,m),b=e.slice(m,w),E=wt(t,b,!1,!1,!1);h=B.word(E.length>0?E:[B.literal("")]),g=w}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:g}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=Wt(t,e,i),f=e.slice(i,u),d=f?B.word([B.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 $i(t,e,n,r=!1){let s=n+1;if(s>=e.length)return{part:B.literal("$"),endIndex:s};let i=e[s];if(i==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,n);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=ve(t,l);return{part:B.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?t.parseCommandSubstitution(e,n):i==="{"?Zx(t,e,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Vx(t,e,n):{part:B.literal("$"),endIndex:s}}function Qx(t,e){let n=[],r=0,s="",i=()=>{s&&(n.push(B.literal(s)),s="")};for(;r<e.length;){let o=e[r];if(o==="\\"&&r+1<e.length){let a=e[r+1];if(a==="$"||a==="`"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=$i(t,e,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=t.parseBacktickSubstitution(e,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function Xx(t,e,n){let r=[],s=n,i="",o=()=>{i&&(r.push(B.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}=$i(t,e,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=t.parseBacktickSubstitution(e,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:B.doubleQuoted(r),endIndex:s}}function wt(t,e,n=!1,r=!1,s=!1,i=!1,o=!1){if(r)return[B.singleQuoted(e)];if(n){let f=Qx(t,e);return[B.doubleQuoted(f)]}let a=[],l=0,c="",u=()=>{c&&(a.push(B.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===`
|
|
681
|
+
`||o===";"||o==="&"||o==="|")return null;s++}}return null}};var mi=1e6,gi=1e5,Gf=1e6,qf=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.AND_DGREAT]),Vf=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS]),pt=class extends Error{line;column;token;constructor(e,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${e}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}};function Kf(t,e,n){let r=n+1;for(;r<e.length&&/[a-zA-Z0-9_-]/.test(e[r]);)r++;return r}function yi(t,e,n,r,s){let i=1,o=n+1;for(;o<e.length&&i>0;)e[o]===r?i++:e[o]===s&&i--,i>0&&o++;return i===0?o:-1}function Wt(t,e,n){let r=n,s=1;for(;r<e.length&&s>0;){let i=e[r];if(i==="\\"&&r+1<e.length){r+=2;continue}if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function Qf(t,e,n){let r=n,s=!1;for(;r<e.length;){let i=e[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function Xf(t,e,n){let r=n,s="";for(;r<e.length;){let i=e[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=Ux(e,r);o===-1?(s+=i,r++):(s+=e.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Ux(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){let r=t[n];if(r==="\\"&&n+1<t.length){n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=t.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<t.length&&(t[n+1]==="."||t[n+1]==="=")){let i=`${t[n+1]}]`,o=t.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function Jf(t,e,n){let r="",s=n;for(;s<e.length&&e[s]!=="'";){let i=e[s];if(i==="\\"&&s+1<e.length)switch(e[s+1]){case"n":r+=`
|
|
682
|
+
`,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=e.slice(s+2,s+4),l=parseInt(a,16);Number.isNaN(l)?(r+="\\x",s+=2):(r+=String.fromCharCode(l),s+=4);break}case"u":{let a=e.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=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);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<e.length&&e[s]==="'"&&s++,{part:B.literal(r),endIndex:s}}function xi(t,e){let n=e.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:ve(t,n)}function Zf(t){let e=[],n="",r=0;for(let s=0;s<t.length;s++){let i=t[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(e.push(n),n=""):n+=i}return e.push(n),e}function Yf(t,e,n,r){let s=yi(t,e,n,"{","}");if(s===-1)return null;let i=e.slice(n+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(",")&&r?{part:{type:"BraceExpansion",items:Zf(i).map(u=>({type:"Word",word:B.word(r(t,u,!1,!1,!1))}))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Zf(i).map(u=>({type:"Word",word:B.word([B.literal(u)])}))},endIndex:s+1}:null}function ed(t,e){let n="";for(let r of e.parts)switch(r.type){case"Literal":case"SingleQuoted":case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;default:n+=r.type}return n}function td(t,e){return{[y.LESS]:"<",[y.GREAT]:">",[y.DGREAT]:">>",[y.LESSAND]:"<&",[y.GREATAND]:">&",[y.LESSGREAT]:"<>",[y.CLOBBER]:">|",[y.TLESS]:"<<<",[y.AND_GREAT]:"&>",[y.AND_DGREAT]:"&>>",[y.DLESS]:"<",[y.DLESSDASH]:"<"}[e]||">"}function Mr(t){let e=t.current(),n=e.type;if(n===y.NUMBER){let r=t.peek(1);return e.end!==r.start?!1:Vf.has(r.type)}return qf.has(n)}function _r(t){let e=null;t.check(y.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let n=t.advance(),r=td(t,n.type);if(n.type===y.DLESS||n.type===y.DLESSDASH)return jx(t,r,e,n.type===y.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return B.redirection(r,s,e)}function jx(t,e,n,r){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=B.redirection(r?"<<-":"<<",B.hereDoc(i,B.word([]),r,o),n);return t.addPendingHeredoc(a,i,r,o),a}function rd(t){let e=t.current().line,n=[],r=null,s=[],i=[];for(;t.check(y.ASSIGNMENT_WORD);)t.checkIterationLimit(),n.push(zx(t));for(;Mr(t);)t.checkIterationLimit(),i.push(_r(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(y.RBRACE))&&!t.check(y.PIPE,y.PIPE_AMP);)if(t.checkIterationLimit(),Mr(t))i.push(_r(t));else if(t.check(y.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(y.ASSIGNMENT_WORD)){let a=t.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||t.check(y.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||t.expect(y.LPAREN);let d=wi(t);t.expect(y.RPAREN);let p=d.map(g=>ed(t,g)),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(y.LPAREN))t.error("syntax error near unexpected token `('");else break;let o=B.simpleCommand(r,s,n,i);return o.line=e,o}function zx(t){let e=t.expect(y.ASSIGNMENT_WORD),n=e.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||t.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&t.error(`Invalid assignment: ${n}`),i=n.slice(d,o),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&t.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=wi(t);t.expect(y.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return B.assignment(d,null,a,f)}if(l===""&&t.check(y.LPAREN)){let f=t.current();if(e.end===f.start){t.advance();let d=wi(t);t.expect(y.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return B.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 B.assignment(u,c,a,null)}function wi(t){let e=[];for(t.skipNewlines();!t.check(y.RPAREN,y.EOF);)t.checkIterationLimit(),t.isWord()?e.push(t.parseWord()):t.advance(),t.skipNewlines();return e}function bi(t){t.expect(y.IF);let e=[],n=t.parseCompoundList();t.expect(y.THEN);let r=t.parseCompoundList();if(r.length===0){let o=t.check(y.FI)?"fi":t.check(y.ELSE)?"else":t.check(y.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${o}'`)}for(e.push({condition:n,body:r});t.check(y.ELIF);){t.advance();let o=t.parseCompoundList();t.expect(y.THEN);let a=t.parseCompoundList();if(a.length===0){let l=t.check(y.FI)?"fi":t.check(y.ELSE)?"else":t.check(y.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${l}'`)}e.push({condition:o,body:a})}let s=null;t.check(y.ELSE)&&(t.advance(),s=t.parseCompoundList(),s.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(y.FI);let i=t.parseOptionalRedirections();return B.ifNode(e,s,i)}function Ei(t){if(t.expect(y.FOR),t.check(y.DPAREN_START))return Gx(t);t.isWord()||t.error("Expected variable name in for loop");let n=t.advance().value,r=null;if(t.skipNewlines(),t.check(y.IN))for(t.advance(),r=[];!t.check(y.SEMICOLON,y.NEWLINE,y.DO,y.EOF)&&t.isWord();)r.push(t.parseWord());t.check(y.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(y.DO);let s=t.parseCompoundList();t.expect(y.DONE);let i=t.parseOptionalRedirections();return B.forNode(n,r,s,i)}function Gx(t){t.expect(y.DPAREN_START);let e=null,n=null,r=null,s=["","",""],i=0,o=0;for(;!t.check(y.DPAREN_END,y.EOF);){let c=t.advance();if(c.type===y.SEMICOLON&&o===0){if(i++,i>2)break}else c.value==="("&&o++,c.value===")"&&o--,s[i]+=c.value}t.expect(y.DPAREN_END),s[0].trim()&&(e=ve(t,s[0].trim())),s[1].trim()&&(n=ve(t,s[1].trim())),s[2].trim()&&(r=ve(t,s[2].trim())),t.skipNewlines(),t.check(y.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(y.DO);let a=t.parseCompoundList();t.expect(y.DONE);let l=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:n,update:r,body:a,redirections:l}}function Si(t){t.expect(y.WHILE);let e=t.parseCompoundList();t.expect(y.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(y.DONE);let r=t.parseOptionalRedirections();return B.whileNode(e,n,r)}function Ci(t){t.expect(y.UNTIL);let e=t.parseCompoundList();t.expect(y.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(y.DONE);let r=t.parseOptionalRedirections();return B.untilNode(e,n,r)}function Ai(t){t.expect(y.CASE),t.isWord()||t.error("Expected word after 'case'");let e=t.parseWord();t.skipNewlines(),t.expect(y.IN),t.skipNewlines();let n=[];for(;!t.check(y.ESAC,y.EOF);){t.checkIterationLimit();let s=t.getPos(),i=qx(t);if(i&&n.push(i),t.skipNewlines(),t.getPos()===s&&!i)break}t.expect(y.ESAC);let r=t.parseOptionalRedirections();return B.caseNode(e,n,r)}function qx(t){t.check(y.LPAREN)&&t.advance();let e=[];for(;t.isWord()&&(e.push(t.parseWord()),t.check(y.PIPE));)t.advance();if(e.length===0)return null;t.expect(y.RPAREN),t.skipNewlines();let n=[];for(;!t.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND,y.ESAC,y.EOF);){t.checkIterationLimit(),t.isWord()&&t.peek(1).type===y.RPAREN&&t.error("syntax error near unexpected token `)'"),t.check(y.LPAREN)&&t.peek(1).type===y.WORD&&t.error(`syntax error near unexpected token \`${t.peek(1).value}'`);let s=t.getPos(),i=t.parseStatement();if(i&&n.push(i),t.skipSeparators(!1),t.getPos()===s&&!i)break}let r=";;";return t.check(y.DSEMI)?(t.advance(),r=";;"):t.check(y.SEMI_AND)?(t.advance(),r=";&"):t.check(y.SEMI_SEMI_AND)&&(t.advance(),r=";;&"),B.caseItem(e,n,r)}function ki(t){t.peek(1).type,y.LPAREN,t.expect(y.LPAREN),t.check(y.LPAREN)&&t.advance();let e=t.parseCompoundList();t.expect(y.RPAREN);let n=t.parseOptionalRedirections();return B.subshell(e,n)}function Ni(t){t.expect(y.LBRACE);let e=t.parseCompoundList();t.expect(y.RBRACE);let n=t.parseOptionalRedirections();return B.group(e,n)}var Zx=["-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"],Kx=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function vi(t){return t.skipNewlines(),Qx(t)}function Qx(t){let e=sd(t);for(t.skipNewlines();t.check(y.OR_OR);){t.advance(),t.skipNewlines();let n=sd(t);e={type:"CondOr",left:e,right:n},t.skipNewlines()}return e}function sd(t){let e=Ii(t);for(t.skipNewlines();t.check(y.AND_AND);){t.advance(),t.skipNewlines();let n=Ii(t);e={type:"CondAnd",left:e,right:n},t.skipNewlines()}return e}function Ii(t){return t.skipNewlines(),t.check(y.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Ii(t)}):Xx(t)}function Xx(t){if(t.check(y.LPAREN)){t.advance();let e=vi(t);return t.expect(y.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),n=e.value;if(Zx.includes(n)&&!e.quoted&&(t.advance(),t.check(y.DBRACK_END)&&t.error(`Expected operand after ${n}`),t.isWord())){let s=t.parseWord();return{type:"CondUnary",operator:n,operand:s}}let r=t.parseWord();if(t.isWord()&&Kx.includes(t.current().value)){let s=t.advance().value,i=t.parseWord();return{type:"CondBinary",operator:s,left:r,right:i}}if(t.check(y.LESS)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"<",left:r,right:s}}if(t.check(y.GREAT)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:">",left:r,right:s}}if(t.isWord()&&t.current().value==="="){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}t.error("Expected conditional expression")}function Yx(t,e,n){let r=n+1,s=e[r];if("@*#?$!-0123456789".includes(s))return{part:B.parameterExpansion(s),endIndex:r+1};let i="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)i+=e[r],r++;return{part:B.parameterExpansion(i),endIndex:r}}function ew(t,e,n,r=!1){let s=n+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=yi(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=tw(t,e,s,a,r);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(n,f+1);t.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:B.parameterExpansion(a,c),endIndex:s+1}}function tw(t,e,n,r,s=!1){let i=n,o=e[i],a=e[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let w=Wt(t,e,i),b=e.slice(i,w),E=wt(t,b,!1,!1,!0,!1,s),S=B.word(E.length>0?E:[B.literal("")]);if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:w};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:w};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:w};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:w}}i++;let c=Wt(t,e,i),u=e.slice(i,c),f=-1,d=0,p=0;for(let m=0;m<u.length;m++){let w=u[m];if(w==="("||w==="[")d++;else if(w===")"||w==="]")d--;else if(w==="?"&&d===0)p++;else if(w===":"&&d===0)if(p>0)p--;else{f=m;break}}let h=f>=0?u.slice(0,f):u,g=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:xi(t,h),length:g?xi(t,g):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=Wt(t,e,i),c=e.slice(i,l),u=wt(t,c,!1,!1,!0,!1,s),f=B.word(u.length>0?u:[B.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=Wt(t,e,i),f=e.slice(i,u),d=wt(t,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:B.word(d.length>0?d:[B.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=Qf(t,e,i),f=e.slice(i,u),d=wt(t,f,!1,!1,!1),p=B.word(d.length>0?d:[B.literal("")]),h=null,g=u;if(e[u]==="/"){let m=u+1,w=Wt(t,e,m),b=e.slice(m,w),E=wt(t,b,!1,!1,!1);h=B.word(E.length>0?E:[B.literal("")]),g=w}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:g}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=Wt(t,e,i),f=e.slice(i,u),d=f?B.word([B.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 $i(t,e,n,r=!1){let s=n+1;if(s>=e.length)return{part:B.literal("$"),endIndex:s};let i=e[s];if(i==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,n);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=ve(t,l);return{part:B.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?t.parseCommandSubstitution(e,n):i==="{"?ew(t,e,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Yx(t,e,n):{part:B.literal("$"),endIndex:s}}function nw(t,e){let n=[],r=0,s="",i=()=>{s&&(n.push(B.literal(s)),s="")};for(;r<e.length;){let o=e[r];if(o==="\\"&&r+1<e.length){let a=e[r+1];if(a==="$"||a==="`"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=$i(t,e,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=t.parseBacktickSubstitution(e,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function rw(t,e,n){let r=[],s=n,i="",o=()=>{i&&(r.push(B.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}=$i(t,e,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=t.parseBacktickSubstitution(e,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:B.doubleQuoted(r),endIndex:s}}function wt(t,e,n=!1,r=!1,s=!1,i=!1,o=!1){if(r)return[B.singleQuoted(e)];if(n){let f=nw(t,e);return[B.doubleQuoted(f)]}let a=[],l=0,c="",u=()=>{c&&(a.push(B.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===`
|
|
683
683
|
`:d==="$"||d==="`"||d==="\\"||d==='"'||d===`
|
|
684
|
-
`)?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(B.singleQuoted(e.slice(l+1,d))),l=d+1;continue}if(f==='"'&&!i){u();let{part:d,endIndex:p}=
|
|
684
|
+
`)?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(B.singleQuoted(e.slice(l+1,d))),l=d+1;continue}if(f==='"'&&!i){u();let{part:d,endIndex:p}=rw(t,e,l+1);a.push(d),l=p+1;continue}if(f==="$"&&e[l+1]==="'"){u();let{part:d,endIndex:p}=Jf(t,e,l+2);a.push(d),l=p;continue}if(f==="$"){u();let{part:d,endIndex:p}=$i(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=Kf(t,e,l),g=e[h];if(g===void 0||g==="/"||g===":"){u();let m=e.slice(l+1,h)||null;a.push({type:"TildeExpansion",user:m}),l=h;continue}}}if(f==="*"||f==="?"||f==="["){u();let{pattern:d,endIndex:p}=Xf(t,e,l);a.push({type:"Glob",pattern:d}),l=p;continue}if(f==="{"&&!s){let d=Yf(t,e,l,wt);if(d){u(),a.push(d.part),l=d.endIndex;continue}}c+=f,l++}return u(),a}var Re=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Gf)throw new pt("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>mi)throw new pt(`Input too large: ${e.length} bytes exceeds limit of ${mi}`,1,1);let n=new Lr(e);if(this.tokens=n.tokenize(),this.tokens.length>gi)throw new pt(`Too many tokens: ${this.tokens.length} exceeds limit of ${gi}`,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,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===e||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(e,n){if(this.check(e))return this.advance();let r=this.current();throw new pt(n||`Expected ${e}, got ${r.type}`,r.line,r.column,r)}error(e){let n=this.current();throw new pt(e,n.line,n.column,n)}skipNewlines(){for(;this.check(y.NEWLINE,y.COMMENT);)this.check(y.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(e=!0){for(;;){if(this.check(y.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(y.SEMICOLON,y.COMMENT)){this.advance();continue}if(e&&this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(e,n,r,s){this.pendingHeredocs.push({redirect:e,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let e of this.pendingHeredocs)if(this.check(y.HEREDOC_CONTENT)){let n=this.advance(),r;e.quoted?r=B.word([B.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),e.redirect.target=B.hereDoc(e.delimiter,r,e.stripTabs,e.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(y.EOF,y.NEWLINE,y.SEMICOLON,y.AMP,y.AND_AND,y.OR_OR,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)}isCommandStart(){let e=this.current().type;return e===y.WORD||e===y.NAME||e===y.NUMBER||e===y.ASSIGNMENT_WORD||e===y.IF||e===y.FOR||e===y.WHILE||e===y.UNTIL||e===y.CASE||e===y.LPAREN||e===y.LBRACE||e===y.DPAREN_START||e===y.DBRACK_START||e===y.FUNCTION||e===y.BANG||e===y.IN||e===y.LESS||e===y.GREAT||e===y.DLESS||e===y.DGREAT||e===y.LESSAND||e===y.GREATAND||e===y.LESSGREAT||e===y.DLESSDASH||e===y.CLOBBER||e===y.TLESS||e===y.AND_GREAT||e===y.AND_DGREAT}parseScript(){let e=[],r=0;for(this.skipNewlines();!this.check(y.EOF);){r++,r>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(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===s&&!this.check(y.EOF)&&this.advance()}return B.script(e)}checkUnexpectedToken(){let e=this.current().type,n=this.current().value;(e===y.DO||e===y.DONE||e===y.THEN||e===y.ELSE||e===y.ELIF||e===y.FI||e===y.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),(e===y.RBRACE||e===y.RPAREN)&&this.error(`syntax error near unexpected token \`${n}'`),(e===y.DSEMI||e===y.SEMI_AND||e===y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),e===y.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`)}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let e=[],n=[],r=!1,s=this.parsePipeline();for(e.push(s);this.check(y.AND_AND,y.OR_OR);){let i=this.advance();n.push(i.type===y.AND_AND?"&&":"||"),this.skipNewlines();let o=this.parsePipeline();e.push(o)}return this.check(y.AMP)&&(this.advance(),r=!0),B.statement(e,n,r)}parsePipeline(){let e=0;for(;this.check(y.BANG);)this.advance(),e++;let n=e%2===1,r=[],s=this.parseCommand();for(r.push(s);this.check(y.PIPE,y.PIPE_AMP);){let i=this.advance();this.skipNewlines();let o=this.parseCommand();i.type===y.PIPE_AMP&&o.type==="SimpleCommand"&&o.redirections.unshift(B.redirection(">&",B.word([B.literal("1")]),2)),r.push(o)}return B.pipeline(r,n)}parseCommand(){return this.check(y.IF)?bi(this):this.check(y.FOR)?Ei(this):this.check(y.WHILE)?Si(this):this.check(y.UNTIL)?Ci(this):this.check(y.CASE)?Ai(this):this.check(y.LPAREN)?ki(this):this.check(y.LBRACE)?Ni(this):this.check(y.DPAREN_START)?this.parseArithmeticCommand():this.check(y.DBRACK_START)?this.parseConditionalCommand():this.check(y.FUNCTION)?this.parseFunctionDef():this.check(y.NAME,y.WORD)&&this.peek(1).type===y.LPAREN&&this.peek(2).type===y.RPAREN?this.parseFunctionDef():rd(this)}isWord(){let e=this.current().type;return e===y.WORD||e===y.NAME||e===y.NUMBER||e===y.IF||e===y.FOR||e===y.WHILE||e===y.UNTIL||e===y.CASE||e===y.FUNCTION||e===y.ELSE||e===y.ELIF||e===y.FI||e===y.THEN||e===y.DO||e===y.DONE||e===y.ESAC||e===y.IN||e===y.SELECT||e===y.TIME||e===y.COPROC||e===y.BANG}parseWord(){let e=this.advance();return this.parseWordFromString(e.value,e.quoted,e.singleQuoted)}parseWordFromString(e,n=!1,r=!1,s=!1,i=!1){let o=wt(this,e,n,r,s,i);return B.word(o)}parseCommandSubstitution(e,n){let r=n+2,s=1,i=r,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(r,i),p=new t().parse(f);return{part:B.commandSubstitution(p,!1),endIndex:i+1}}parseBacktickSubstitution(e,n,r=!1){let i=n+1,o="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let c=e[i+1];c==="$"||c==="`"||c==="\\"||c===`
|
|
685
685
|
`||r&&c==='"'?(c!==`
|
|
686
|
-
`&&(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:B.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,n){let r=n+3,s=1,i=0,o=r;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(r,o),l=this.parseArithmeticExpression(a);return{part:B.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){this.expect(y.DPAREN_START);let e="",n=1,r=0,s=!1,i=!1;for(;n>0&&!this.check(y.EOF);){if(s){if(s=!1,r>0){r--,e+=")";continue}if(this.check(y.RPAREN)){n--,i=!0,this.advance();continue}if(this.check(y.DPAREN_END)){n--,i=!0;continue}e+=")";continue}this.check(y.DPAREN_START)?(n++,e+="((",this.advance()):this.check(y.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",s=!0,this.advance()):(n--,i=!0,n>0&&(e+="))"),this.advance()):this.check(y.LPAREN)?(r++,e+="(",this.advance()):this.check(y.RPAREN)?(r>0&&r--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return B.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(y.DBRACK_START);let e=vi(this);this.expect(y.DBRACK_END);let n=this.parseOptionalRedirections();return B.conditionalCommand(e,n)}parseFunctionDef(){let e;this.check(y.FUNCTION)?(this.advance(),e=this.expect(y.NAME,"Expected function name").value,this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))):(e=this.advance().value,this.expect(y.LPAREN),this.expect(y.RPAREN)),this.skipNewlines();let n=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return B.functionDef(e,n,r)}parseCompoundCommandBody(){if(this.check(y.LBRACE))return Ni(this);if(this.check(y.LPAREN))return ki(this);if(this.check(y.IF))return bi(this);if(this.check(y.FOR))return Ei(this);if(this.check(y.WHILE))return Si(this);if(this.check(y.UNTIL))return Ci(this);if(this.check(y.CASE))return Ai(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let n=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===n&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Mr(this);){this.checkIterationLimit();let n=this.pos;if(e.push(_r(this)),this.pos===n)break}return e}parseArithmeticExpression(e){return ve(this,e)}};function bt(t){return new Re().parse(t)}de();Gt();var fn=class{fs;cwd;constructor(e,n){this.fs=e,this.cwd=n}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,n){let r=e.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<e.length;o++){let a=s[o];a===null?i.push(e[o]):a.length>0?i.push(...a):i.push(e[o])}return i}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}hasGlobChars(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandSimple(e){let n=e.startsWith("/"),r=e.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[e];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(e,n,r){if(r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){let a=await this.fs.readdirWithFileTypes(e),l=[];for(let u of a)if(!(u.name.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u.name,s)){let f=e==="/"?`/${u.name}`:`${e}/${u.name}`,d;n===""?d=u.name:n==="/"?d=`/${u.name}`:d=`${n}/${u.name}`,i.length===0?l.push(Promise.resolve([d])):u.isDirectory&&l.push(this.expandSegments(f,d,i))}let c=await Promise.all(l);for(let u of c)o.push(...u)}else{let a=await this.fs.readdir(e),l=[];for(let u of a)if(!(u.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u,s)){let f=e==="/"?`/${u}`:`${e}/${u}`,d;n===""?d=u:n==="/"?d=`/${u}`:d=`${n}/${u}`,i.length===0?l.push(Promise.resolve([d])):l.push((async()=>{try{if((await this.fs.stat(f)).isDirectory)return this.expandSegments(f,d,i)}catch{}return[]})())}let c=await Promise.all(l);for(let u of c)o.push(...u)}}catch{}return o}async expandRecursive(e){let n=[],r=e.indexOf("**"),s=e.slice(0,r).replace(/\/$/,"")||".",o=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(s,o,n),n.sort()}async walkDirectory(e,n,r){let s=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=e==="."?l.name:`${e}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=e==="."?f:`${e}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch{return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch{}}matchPattern(e,n){return this.patternToRegex(n).test(e)}patternToRegex(e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=r+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+="]",n+=o,r=i}else if(s==="\\"&&r+1<e.length){let i=e[r+1];/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i,r++}else/[.+^${}()|]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n)}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]||""}};de();function Je(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Je(t.expression);case"ArithBinary":return Je(t.left)||Je(t.right);case"ArithUnary":return Je(t.operand);case"ArithTernary":return Je(t.condition)||Je(t.consequent)||Je(t.alternate);case"ArithAssignment":return Je(t.value);case"ArithGroup":return Je(t.expression);case"ArithArrayElement":return t.index?Je(t.index):!1;case"ArithConcat":return t.parts.some(Je);default:return!1}}function Ri(t){let e=t.operation;return e?!!("word"in e&&e.word&&ht(e.word)||e.type==="PatternReplacement"&&(e.pattern&&ht(e.pattern)||e.replacement&&ht(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&ht(e.pattern)):!1}function Br(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Je(t.expression.expression);case"DoubleQuoted":return t.parts.some(Br);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&ht(e.word));case"ParameterExpansion":return Ri(t);default:return!1}}function ht(t){return t.parts.some(Br)}function Fi(t){if(!t.operation)return!1;let e=t.operation,n;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(n=e.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function id(t){let e=!1,n=!1,r=!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"&&(n=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),Fi(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i}}function Yx(t,e,n,r,s){let i=n??1;i===0&&(i=1);let o=Math.abs(i),a=[],l=0;r?.match(/^-?0\d/)&&(l=Math.max(l,r.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 ew(t,e,n){let r=n??1;r===0&&(r=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(r),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 Wn(t,e,n,r,s){let i=n!==void 0?`..${n}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:Yx(t,e,n,r,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:ew(t,e,n),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function Ge(t,e){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\")if(r+1<t.length){let i=t[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r+=2}else n+="\\\\",r++;else if(s==="*")n+=e?".*":".*?",r++;else if(s==="?")n+=".",r++;else if(s==="["){let i=tw(t,r);if(i===-1)n+="\\[",r++;else{let o=t.slice(r+1,i);n+=nw(o),r=i+1}}else/[\^$.|+(){}]/.test(s)?(n+=`\\${s}`,r++):(n+=s,r++)}return n}function tw(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){if(t[n]==="\\"&&n+1<t.length){n+=2;continue}if(t[n]==="]")return n;if(t[n]==="'"){let r=t.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let r=t.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function nw(t){let e="[",n=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",n++);n<t.length;){if(t[n]==="'"){let s=t.indexOf("'",n+1);if(s!==-1){let i=t.slice(n+1,s);for(let o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;n=s+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){let i=t.slice(n+2,s);e+=sw(i),n=s+2;continue}}let r=t[n];r==="\\"?n+1<t.length?(e+=`\\${t[n+1]}`,n+=2):(e+="\\\\",n++):r==="-"&&n>0&&n<t.length-1?(e+="-",n++):r==="^"&&n===0?(e+="^",n++):(r==="]"&&n===0?e+="\\]":e+=r,n++)}return e+="]",e}var rw={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 sw(t){return rw[t]??""}de();function Un(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)){let i=s.slice(n.length),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&r.push(o)}return r.sort((s,i)=>s-i)}function jn(t,e){let n=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(n)&&delete t.state.env[r]}function Pi(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)&&!s.includes("__")){let i=s.slice(n.length);r.push(i)}return r.sort()}function od(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Wr(t){return t.IFS??`
|
|
686
|
+
`&&(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:B.commandSubstitution(l,!0),endIndex:i+1}}parseArithmeticExpansion(e,n){let r=n+3,s=1,i=0,o=r;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(r,o),l=this.parseArithmeticExpression(a);return{part:B.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){this.expect(y.DPAREN_START);let e="",n=1,r=0,s=!1,i=!1;for(;n>0&&!this.check(y.EOF);){if(s){if(s=!1,r>0){r--,e+=")";continue}if(this.check(y.RPAREN)){n--,i=!0,this.advance();continue}if(this.check(y.DPAREN_END)){n--,i=!0;continue}e+=")";continue}this.check(y.DPAREN_START)?(n++,e+="((",this.advance()):this.check(y.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",s=!0,this.advance()):(n--,i=!0,n>0&&(e+="))"),this.advance()):this.check(y.LPAREN)?(r++,e+="(",this.advance()):this.check(y.RPAREN)?(r>0&&r--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return B.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(y.DBRACK_START);let e=vi(this);this.expect(y.DBRACK_END);let n=this.parseOptionalRedirections();return B.conditionalCommand(e,n)}parseFunctionDef(){let e;this.check(y.FUNCTION)?(this.advance(),e=this.expect(y.NAME,"Expected function name").value,this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))):(e=this.advance().value,this.expect(y.LPAREN),this.expect(y.RPAREN)),this.skipNewlines();let n=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return B.functionDef(e,n,r)}parseCompoundCommandBody(){if(this.check(y.LBRACE))return Ni(this);if(this.check(y.LPAREN))return ki(this);if(this.check(y.IF))return bi(this);if(this.check(y.FOR))return Ei(this);if(this.check(y.WHILE))return Si(this);if(this.check(y.UNTIL))return Ci(this);if(this.check(y.CASE))return Ai(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let n=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===n&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Mr(this);){this.checkIterationLimit();let n=this.pos;if(e.push(_r(this)),this.pos===n)break}return e}parseArithmeticExpression(e){return ve(this,e)}};function bt(t){return new Re().parse(t)}de();Gt();var fn=class{fs;cwd;constructor(e,n){this.fs=e,this.cwd=n}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,n){let r=e.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<e.length;o++){let a=s[o];a===null?i.push(e[o]):a.length>0?i.push(...a):i.push(e[o])}return i}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}hasGlobChars(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandSimple(e){let n=e.startsWith("/"),r=e.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[e];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(e,n,r){if(r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){let a=await this.fs.readdirWithFileTypes(e),l=[];for(let u of a)if(!(u.name.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u.name,s)){let f=e==="/"?`/${u.name}`:`${e}/${u.name}`,d;n===""?d=u.name:n==="/"?d=`/${u.name}`:d=`${n}/${u.name}`,i.length===0?l.push(Promise.resolve([d])):u.isDirectory&&l.push(this.expandSegments(f,d,i))}let c=await Promise.all(l);for(let u of c)o.push(...u)}else{let a=await this.fs.readdir(e),l=[];for(let u of a)if(!(u.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u,s)){let f=e==="/"?`/${u}`:`${e}/${u}`,d;n===""?d=u:n==="/"?d=`/${u}`:d=`${n}/${u}`,i.length===0?l.push(Promise.resolve([d])):l.push((async()=>{try{if((await this.fs.stat(f)).isDirectory)return this.expandSegments(f,d,i)}catch{}return[]})())}let c=await Promise.all(l);for(let u of c)o.push(...u)}}catch{}return o}async expandRecursive(e){let n=[],r=e.indexOf("**"),s=e.slice(0,r).replace(/\/$/,"")||".",o=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(s,o,n),n.sort()}async walkDirectory(e,n,r){let s=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=e==="."?l.name:`${e}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=e==="."?f:`${e}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch{return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch{}}matchPattern(e,n){return this.patternToRegex(n).test(e)}patternToRegex(e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=r+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+="]",n+=o,r=i}else if(s==="\\"&&r+1<e.length){let i=e[r+1];/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i,r++}else/[.+^${}()|]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n)}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]||""}};de();function Je(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Je(t.expression);case"ArithBinary":return Je(t.left)||Je(t.right);case"ArithUnary":return Je(t.operand);case"ArithTernary":return Je(t.condition)||Je(t.consequent)||Je(t.alternate);case"ArithAssignment":return Je(t.value);case"ArithGroup":return Je(t.expression);case"ArithArrayElement":return t.index?Je(t.index):!1;case"ArithConcat":return t.parts.some(Je);default:return!1}}function Ri(t){let e=t.operation;return e?!!("word"in e&&e.word&&ht(e.word)||e.type==="PatternReplacement"&&(e.pattern&&ht(e.pattern)||e.replacement&&ht(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&ht(e.pattern)):!1}function Br(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Je(t.expression.expression);case"DoubleQuoted":return t.parts.some(Br);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&ht(e.word));case"ParameterExpansion":return Ri(t);default:return!1}}function ht(t){return t.parts.some(Br)}function Fi(t){if(!t.operation)return!1;let e=t.operation,n;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(n=e.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function id(t){let e=!1,n=!1,r=!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"&&(n=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),Fi(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i}}function iw(t,e,n,r,s){let i=n??1;i===0&&(i=1);let o=Math.abs(i),a=[],l=0;r?.match(/^-?0\d/)&&(l=Math.max(l,r.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 ow(t,e,n){let r=n??1;r===0&&(r=1);let s=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(r),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 Wn(t,e,n,r,s){let i=n!==void 0?`..${n}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:iw(t,e,n,r,s),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:ow(t,e,n),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function Ge(t,e){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\")if(r+1<t.length){let i=t[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r+=2}else n+="\\\\",r++;else if(s==="*")n+=e?".*":".*?",r++;else if(s==="?")n+=".",r++;else if(s==="["){let i=aw(t,r);if(i===-1)n+="\\[",r++;else{let o=t.slice(r+1,i);n+=lw(o),r=i+1}}else/[\^$.|+(){}]/.test(s)?(n+=`\\${s}`,r++):(n+=s,r++)}return n}function aw(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){if(t[n]==="\\"&&n+1<t.length){n+=2;continue}if(t[n]==="]")return n;if(t[n]==="'"){let r=t.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let r=t.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function lw(t){let e="[",n=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",n++);n<t.length;){if(t[n]==="'"){let s=t.indexOf("'",n+1);if(s!==-1){let i=t.slice(n+1,s);for(let o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;n=s+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){let i=t.slice(n+2,s);e+=uw(i),n=s+2;continue}}let r=t[n];r==="\\"?n+1<t.length?(e+=`\\${t[n+1]}`,n+=2):(e+="\\\\",n++):r==="-"&&n>0&&n<t.length-1?(e+="-",n++):r==="^"&&n===0?(e+="^",n++):(r==="]"&&n===0?e+="\\]":e+=r,n++)}return e+="]",e}var cw={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 uw(t){return cw[t]??""}de();function Un(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)){let i=s.slice(n.length),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&r.push(o)}return r.sort((s,i)=>s-i)}function jn(t,e){let n=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(n)&&delete t.state.env[r]}function Pi(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)&&!s.includes("__")){let i=s.slice(n.length);r.push(i)}return r.sort()}function od(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Wr(t){return t.IFS??`
|
|
687
687
|
`}function ad(t){return t.IFS===""}function zn(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
|
|
688
|
-
`?"\\n":e).join("")}function
|
|
688
|
+
`?"\\n":e).join("")}function fw(t,e){let n=zn(t);return new RegExp(`[${n}]+`,e)}function dw(t){let e=zn(t);return new RegExp(`^[${e}]+`)}function pw(t){let e=zn(t);return new RegExp(`[${e}]+$`)}function dn(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function ld(t,e){if(e==="")return{words:[t],wordStarts:[0]};let n=[],r=[],s=fw(e,"g"),i=0,o=t.match(dw(e));o&&(i=o[0].length),s.lastIndex=i;let a=s.exec(t);for(;a!==null;)a.index>i&&(r.push(i),n.push(t.substring(i,a.index))),i=s.lastIndex,a=s.exec(t);return i<t.length&&(r.push(i),n.push(t.substring(i))),{words:n,wordStarts:r}}function cd(t,e){return e===""?t:t.replace(pw(e),"")}function $e(t,e){return t.state.associativeArrays?.has(e)?Pi(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):Un(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function ud(t,e){return t.state.associativeArrays?.has(e)?Pi(t,e).length>0:Un(t,e).length>0}function Ye(t,e,n=!0,r=!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(dn(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}=Bn();return String(o)}case"UID":{let{uid:o}=Bn();return String(o)}case"EUID":return String(process.geteuid?.()??Bn().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 $f;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 ut(`\${${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=$e(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=od(a),d=t.state.env[`${o}_${f}`];if(d===void 0&&n&&t.state.options.nounset)throw new Qe(`${o}[${a}]`);return d||""}let c;if(/^-?\d+$/.test(a))c=Number.parseInt(a,10);else try{let f=new Re,d=ve(f,a);c=ie(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=$e(t,o);if(f.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
|
|
689
689
|
`,"";let p=Math.max(...f.map(([g])=>typeof g=="number"?g:0))+1+c;return p<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
|
|
690
690
|
`,""):t.state.env[`${o}_${p}`]||""}let u=t.state.env[`${o}_${c}`];if(u===void 0&&n&&t.state.options.nounset)throw new Qe(`${o}[${c}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let o=t.state.env[e];if(o===void 0&&n&&t.state.options.nounset)throw new Qe(e);return o||""}let i=t.state.env[e];if(i===void 0&&n&&t.state.options.nounset)throw new Qe(e);return i||""}async function fd(t,e,n,r,s){let i=[];for(let u of e){let f=u.type==="ParameterExpansion"||u.type==="CommandSubstitution"||u.type==="ArithmeticExpansion";if(u.type==="ParameterExpansion"&&Fi(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(`[${r}]`).test(u.value))){let u=i.map(f=>f.value).join("");return u?[u]:[]}let a=new RegExp(`[${r}]+`),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 qe(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dd(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function pd(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Ti(t){if(t==="")return"''";if(!/['\\\n\r\t\x00-\x1f\x7f]/.test(t))return`'${t}'`;let e="$'";for(let n of t)switch(n){case"'":e+="\\'";break;case"\\":e+="\\\\";break;case`
|
|
691
|
-
`:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let r=n.charCodeAt(0);r<32||r===127?e+=`\\x${r.toString(16).padStart(2,"0")}`:e+=n}}return`${e}'`}function Ut(t,e,n=!1){return e.map(r=>mt(t,r,n)).join("")}async function jt(t,e,n=!1){let r=[];for(let s of e)r.push(await et(t,s));return r.join("")}function
|
|
691
|
+
`:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let r=n.charCodeAt(0);r<32||r===127?e+=`\\x${r.toString(16).padStart(2,"0")}`:e+=n}}return`${e}'`}function Ut(t,e,n=!1){return e.map(r=>mt(t,r,n)).join("")}async function jt(t,e,n=!1){let r=[];for(let s of e)r.push(await et(t,s));return r.join("")}function hw(t){return pd(t)}function hd(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!hw(e))return!1;return!0}function md(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function gd(t,e,n=!1){let r=dd(e);if(r!==null)return r;switch(e.type){case"ParameterExpansion":return Ed(t,e,n);case"TildeExpansion":return n?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 mt(t,e,n=!1){let r=gd(t,e,n);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let s=[];for(let i of e.parts)s.push(mt(t,i,!0));return s.join("")}case"ArithmeticExpansion":return String(ie(t,e.expression.expression));case"BraceExpansion":{let s=[];for(let i of e.items)if(i.type==="Range"){let o=Wn(i.start,i.end,i.step,i.startStr,i.endStr);if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(Ur(t,i.word));return s.join(" ")}default:return""}}function Ur(t,e){let n=e.parts,r=n.length;if(r===1)return mt(t,n[0]);let s=[];for(let i=0;i<r;i++)s.push(mt(t,n[i]));return s.join("")}async function he(t,e){return ht(e)?bd(t,e):Ur(t,e)}function jr(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&jr(e.parts))return!0;return!1}function mw(t){for(let e of t){if(e.type==="BraceExpansion"){for(let n of e.items)if(n.type==="Word"&&ht(n.word))return!0}if(Br(e))return!0}return!1}var yd=1e4,pn=1e5;function xd(t,e,n={count:0}){if(n.count>pn)return[[]];let r=[[]];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=Wn(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let d of f.expanded)n.count++,i.push(d);else{o=!0,a=f.literal;break}}else{let f=xd(t,u.word.parts,n);for(let d of f)n.count++,i.push(d.join(""))}if(o){for(let u of r)n.count++,u.push(a);continue}if(r.length*i.length>yd||n.count>pn)return r;let c=[];for(let u of r)for(let f of i){if(n.count++,n.count>pn)return c.length>0?c:r;c.push([...u,f])}r=c}else{let i=mt(t,s);for(let o of r)n.count++,o.push(i)}return r}function gw(t,e){let n=e.parts;return jr(n)?xd(t,n).map(s=>s.join("")):[Ur(t,e)]}async function wd(t,e,n={count:0}){if(n.count>pn)return[[]];let r=[[]];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=Wn(u.start,u.end,u.step,u.startStr,u.endStr);if(f.expanded)for(let d of f.expanded)n.count++,i.push(d);else{o=!0,a=f.literal;break}}else{let f=await wd(t,u.word.parts,n);for(let d of f)n.count++,i.push(d.join(""))}if(o){for(let u of r)n.count++,u.push(a);continue}if(r.length*i.length>yd||n.count>pn)return r;let c=[];for(let u of r)for(let f of i){if(n.count++,n.count>pn)return c.length>0?c:r;c.push([...u,f])}r=c}else{let i=await et(t,s);for(let o of r)n.count++,o.push(i)}return r}async function yw(t,e){let n=e.parts;return jr(n)?(await wd(t,n)).map(s=>s.join("")):[await he(t,e)]}async function Hn(t,e){let n=e.parts,{hasQuoted:r,hasCommandSub:s,hasArrayVar:i,hasArrayAtExpansion:o,hasParamExpansion:a}=id(n),c=jr(n)?mw(n)?await yw(t,e):gw(t,e):null;if(c&&c.length>1){let d=[];for(let p of c)if(!r&&/[*?[]/.test(p)){let g=await new fn(t.fs,t.state.cwd).expand(p);g.length>0?d.push(...g):d.push(p)}else d.push(p);return{values:d,quoted:!1}}if(o&&n.length===1&&n[0].type==="DoubleQuoted"){let d=n[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 g=h[1],m=$e(t,g);if(m.length>0)return{values:m.map(([,b])=>b),quoted:!0};let w=t.state.env[g];return w!==void 0?{values:[w],quoted:!0}:{values:[],quoted:!0}}}}if(n.length===1&&n[0].type==="DoubleQuoted"){let d=n[0],p=-1,h=!1;for(let g=0;g<d.parts.length;g++){let m=d.parts[g];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")){p=g,h=m.parameter==="*";break}}if(p!==-1){let g=d.parts[p];g.type==="ParameterExpansion"&&g.operation&&(p=-1)}if(p!==-1){let g=Number.parseInt(t.state.env["#"]||"0",10),m="";for(let S=0;S<p;S++)m+=await et(t,d.parts[S]);let w="";for(let S=p+1;S<d.parts.length;S++)w+=await et(t,d.parts[S]);if(g===0){if(h)return{values:[m+w],quoted:!0};let S=m+w;return{values:S?[S]:[],quoted:!0}}let b=[];for(let S=1;S<=g;S++)b.push(t.state.env[String(S)]||"");if(h){let S=dn(t.state.env);return{values:[m+b.join(S)+w],quoted:!0}}return b.length===1?{values:[m+b[0]+w],quoted:!0}:{values:[m+b[0],...b.slice(1,-1),b[b.length-1]+w],quoted:!0}}}if((s||i||a)&&!ad(t.state.env)){let d=Wr(t.state.env),p=zn(d),h=await fd(t,n,d,p,et),g=[],m=new fn(t.fs,t.state.cwd);for(let w of h)if(/[*?[]/.test(w)){let b=await m.expand(w);b.length>0?g.push(...b):g.push(w)}else g.push(w);return{values:g,quoted:!1}}let f=ht(e)?await bd(t,e):Ur(t,e);if(!r&&/[*?[]/.test(f)){let p=await new fn(t.fs,t.state.cwd).expand(f);if(p.length>0)return{values:p,quoted:!1}}return f===""&&!r?{values:[],quoted:!1}:{values:[f],quoted:r}}async function bd(t,e){let n=e.parts,r=n.length;if(r===1)return et(t,n[0]);let s=[];for(let i=0;i<r;i++)s.push(await et(t,n[i]));return s.join("")}async function et(t,e){if(e.type==="ParameterExpansion"&&Ri(e))return xw(t,e);let n=gd(t,e);if(n!==null)return n;switch(e.type){case"DoubleQuoted":{let r=[];for(let s of e.parts)r.push(await et(t,s));return r.join("")}case"CommandSubstitution":try{let r=await t.executeScript(e.body);return t.state.lastExitCode=r.exitCode,t.state.env["?"]=String(r.exitCode),r.stdout.replace(/\n+$/,"")}catch(r){if(r instanceof Q)throw r;if(r instanceof fe)return t.state.lastExitCode=r.exitCode,t.state.env["?"]=String(r.exitCode),r.stdout.replace(/\n+$/,"");throw r}case"ArithmeticExpansion":return String(await oe(t,e.expression.expression));case"BraceExpansion":{let r=[];for(let s of e.items)if(s.type==="Range"){let i=Wn(s.start,s.end,s.step,s.startStr,s.endStr);if(i.expanded)r.push(...i.expanded);else return i.literal}else r.push(await he(t,s.word));return r.join(" ")}default:return""}}function Ed(t,e,n=!1){let{parameter:r,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Ye(t,r,!i);if(!s)return o;let a=!(r in t.state.env),l=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&l)&&s.word?Ut(t,s.word.parts,n):o;case"AssignDefault":{if((a||s.checkEmpty&&l)&&s.word){let u=Ut(t,s.word.parts,n),f=r.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 m=new Re,w=ve(m,p);h=ie(t,w.expression)}catch{let m=t.state.env[p];h=m?Number.parseInt(m,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${d}_${h}`]=u;let g=Number.parseInt(t.state.env[`${d}__length`]||"0",10);h>=g&&(t.state.env[`${d}__length`]=String(h+1))}else t.state.env[r]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&l){let u=s.word?Ut(t,s.word.parts,n):`${r}: parameter null or not set`;throw new fe(1,"",`bash: ${u}
|
|
692
692
|
`)}return o}case"UseAlternative":return!(a||s.checkEmpty&&l)&&s.word?Ut(t,s.word.parts,n):"";case"Length":{let c=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(c){let u=$e(t,c[1]);return String(u.length)}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ud(t,r)){let u=t.state.env[`${r}_0`]||"";return String(u.length)}return String(o.length)}case"LengthSliceError":throw new ut(r);case"Substring":{let c=s.offset?ie(t,s.offset.expression):0,u=s.length?ie(t,s.length.expression):void 0;if(r==="@"||r==="*"){let h=(t.state.env["@"]||"").split(" ").filter(b=>b),g=t.state.env[0]||"bash",m=c===0?[g,...h]:h,w=c===0?0:c-1;if(w<0||w>=m.length)return"";if(u!==void 0){let b=u<0?m.length+u:w+u;return m.slice(w,Math.max(w,b)).join(" ")}return m.slice(w).join(" ")}let f=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(f){let g=$e(t,f[1]).map(([,w])=>w),m=c;if(m<0&&(m=g.length+m,m<0))return"";if(u!==void 0){if(u<0){let w=g.length+u;return g.slice(m,Math.max(m,w)).join(" ")}return g.slice(m,m+u).join(" ")}return g.slice(m).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+=Ge(f.pattern,s.greedy);else if(f.type==="Literal")c+=Ge(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")c+=qe(f.value);else if(f.type==="DoubleQuoted"){let d=Ut(t,f.parts);c+=qe(d)}else if(f.type==="ParameterExpansion"){let d=mt(t,f);c+=Ge(d,s.greedy)}else{let d=mt(t,f);c+=qe(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+=Ge(d.pattern,!0);else if(d.type==="Literal")c+=Ge(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")c+=qe(d.value);else if(d.type==="DoubleQuoted"){let p=Ut(t,d.parts);c+=qe(p)}else if(d.type==="ParameterExpansion"){let p=mt(t,d);c+=Ge(p,!0)}else{let p=mt(t,d);c+=qe(p)}let u=s.replacement?Ut(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,g=d.exec(o);for(;g!==null&&!(g[0].length===0&&g.index===o.length);)p+=o.slice(h,g.index)+u,h=g.index+g[0].length,g[0].length===0&&h++,g=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=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(c&&s.operator==="Q")return $e(t,c[1]).map(([,d])=>Ti(d)).join(" ");switch(s.operator){case"Q":return Ti(o);case"P":return o;case"a":return"";case"A":return`${r}=${Ti(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`
|
|
693
|
-
`;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 Ye(t,o);case"ArrayKeys":{let u=$e(t,s.array).map(([f])=>String(f));return s.star?u.join(dn(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(dn(t.state.env)):c.join(" ")}default:return o}}async function
|
|
694
|
-
`)}return o}case"UseAlternative":return!(a||s.checkEmpty&&l)&&s.word?jt(t,s.word.parts,n):"";case"PatternRemoval":{let c="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")c+=Ge(f.pattern,s.greedy);else if(f.type==="Literal")c+=Ge(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")c+=qe(f.value);else if(f.type==="DoubleQuoted"){let d=await jt(t,f.parts);c+=qe(d)}else if(f.type==="ParameterExpansion"){let d=await et(t,f);c+=Ge(d,s.greedy)}else{let d=await et(t,f);c+=qe(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+=Ge(d.pattern,!0);else if(d.type==="Literal")c+=Ge(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")c+=qe(d.value);else if(d.type==="DoubleQuoted"){let p=await jt(t,d.parts);c+=qe(p)}else if(d.type==="ParameterExpansion"){let p=await et(t,d);c+=Ge(p,!0)}else{let p=await et(t,d);c+=qe(p)}let u=s.replacement?await jt(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,g=d.exec(o);for(;g!==null&&!(g[0].length===0&&g.index===o.length);)p+=o.slice(h,g.index)+u,h=g.index+g[0].length,g[0].length===0&&h++,g=d.exec(o);return p+=o.slice(h),p}return o.replace(d,u)}catch{return o}}default:return Ed(t,e,n)}}function Oi(t,e,n){switch(n){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 ke("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 Sd(t,e,n){switch(n){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 Di(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function
|
|
693
|
+
`;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 Ye(t,o);case"ArrayKeys":{let u=$e(t,s.array).map(([f])=>String(f));return s.star?u.join(dn(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(dn(t.state.env)):c.join(" ")}default:return o}}async function xw(t,e,n=!1){let{parameter:r,operation:s}=e,i=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=Ye(t,r,!i);if(!s)return o;let a=!(r in t.state.env),l=o==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&l)&&s.word?jt(t,s.word.parts,n):o;case"AssignDefault":{if((a||s.checkEmpty&&l)&&s.word){let u=await jt(t,s.word.parts,n),f=r.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 m=new Re,w=ve(m,p);h=await oe(t,w.expression)}catch{let m=t.state.env[p];h=m?Number.parseInt(m,10):0}Number.isNaN(h)&&(h=0)}t.state.env[`${d}_${h}`]=u;let g=Number.parseInt(t.state.env[`${d}__length`]||"0",10);h>=g&&(t.state.env[`${d}__length`]=String(h+1))}else t.state.env[r]=u;return u}return o}case"ErrorIfUnset":{if(a||s.checkEmpty&&l){let u=s.word?await jt(t,s.word.parts,n):`${r}: parameter null or not set`;throw new fe(1,"",`bash: ${u}
|
|
694
|
+
`)}return o}case"UseAlternative":return!(a||s.checkEmpty&&l)&&s.word?jt(t,s.word.parts,n):"";case"PatternRemoval":{let c="";if(s.pattern)for(let f of s.pattern.parts)if(f.type==="Glob")c+=Ge(f.pattern,s.greedy);else if(f.type==="Literal")c+=Ge(f.value,s.greedy);else if(f.type==="SingleQuoted"||f.type==="Escaped")c+=qe(f.value);else if(f.type==="DoubleQuoted"){let d=await jt(t,f.parts);c+=qe(d)}else if(f.type==="ParameterExpansion"){let d=await et(t,f);c+=Ge(d,s.greedy)}else{let d=await et(t,f);c+=qe(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+=Ge(d.pattern,!0);else if(d.type==="Literal")c+=Ge(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")c+=qe(d.value);else if(d.type==="DoubleQuoted"){let p=await jt(t,d.parts);c+=qe(p)}else if(d.type==="ParameterExpansion"){let p=await et(t,d);c+=Ge(p,!0)}else{let p=await et(t,d);c+=qe(p)}let u=s.replacement?await jt(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,g=d.exec(o);for(;g!==null&&!(g[0].length===0&&g.index===o.length);)p+=o.slice(h,g.index)+u,h=g.index+g[0].length,g[0].length===0&&h++,g=d.exec(o);return p+=o.slice(h),p}return o.replace(d,u)}catch{return o}}default:return Ed(t,e,n)}}function Oi(t,e,n){switch(n){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 ke("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 Sd(t,e,n){switch(n){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 Di(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function ww(t,e){let n=t.state.env[e];if(n!==void 0)return n;let r=t.state.env[`${e}_0`];return r!==void 0?r:Ye(t,e)}function hn(t){if(!t)return 0;let e=Number.parseInt(t,10);if(!Number.isNaN(e)&&/^-?\d+$/.test(t.trim()))return e;let n=t.trim();if(!n)return 0;try{let r=new Re,{expr:s,pos:i}=dt(r,n,0);if(i<n.length){let o=n.slice(i).trim().split(/\s+/)[0];throw new ke(`${n}: syntax error in expression (error token is "${o}")`)}return s.type==="ArithNumber"?s.value:e||0}catch(r){if(r instanceof ke)throw r;let s=n.split(/\s+/).slice(1)[0]||n;throw new ke(`${n}: syntax error in expression (error token is "${s}")`)}}function zr(t,e,n=new Set){if(n.has(e))return 0;n.add(e);let r=ww(t,e);if(!r)return 0;let s=Number.parseInt(r,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(r.trim()))return s;let i=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return zr(t,i,n);try{let o=new Re,{expr:a}=dt(o,i,0);return tt(t,a,n)}catch{return 0}}function tt(t,e,n){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ke("value too great for base");return e.value;case"ArithVariable":return zr(t,e.name,n);case"ArithBinary":{if(e.operator==="||")return tt(t,e.left,n)||tt(t,e.right,n)?1:0;if(e.operator==="&&")return tt(t,e.left,n)&&tt(t,e.right,n)?1:0;let r=tt(t,e.left,n),s=tt(t,e.right,n);return Oi(r,s,e.operator)}case"ArithUnary":{let r=tt(t,e.operand,n);return Di(r,e.operator)}case"ArithTernary":return tt(t,e.condition,n)?tt(t,e.consequent,n):tt(t,e.alternate,n);case"ArithGroup":return tt(t,e.expression,n);default:return ie(t,e)}}function Et(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 n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=e.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return Ye(t,e);let i=e.slice(0,r),o=e.slice(r+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 ie(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ke("value too great for base");return e.value;case"ArithVariable":return zr(t,e.name);case"ArithNested":return ie(t,e.expression);case"ArithCommandSubst":return 0;case"ArithBracedExpansion":{let n=Et(t,e.content);return Number.parseInt(n,10)||0}case"ArithDynamicBase":{let n=Et(t,e.baseExpr),r=Number.parseInt(n,10);if(r<2||r>64)return 0;let s=`${r}#${e.value}`;return un(s)}case"ArithDynamicNumber":{let r=Et(t,e.prefix)+e.suffix;return un(r)}case"ArithArrayElement":{let n=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(n&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let i=ie(t,e.index);if(i<0){let a=$e(t,e.array);if(a.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
|
|
695
695
|
`,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
|
|
696
696
|
`,0;i=c}r=`${e.array}_${i}`;let o=t.state.env[r];if(o!==void 0)return hn(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return hn(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new Qe(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[r];return s!==void 0?hn(s):0}case"ArithDoubleSubscript":throw new ke("double subscript","","");case"ArithNumberSubscript":throw new ke(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return ie(t,e.left)||ie(t,e.right)?1:0;if(e.operator==="&&")return ie(t,e.left)&&ie(t,e.right)?1:0;let n=ie(t,e.left),r=ie(t,e.right);return Oi(n,r,e.operator)}case"ArithUnary":{let n=ie(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,s=Number.parseInt(Ye(t,r),10)||0,i=e.operator==="++"?s+1:s-1;return t.state.env[r]=String(i),e.prefix?i:s}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,s=t.state.associativeArrays?.has(r),i;if(e.operand.stringKey!==void 0)i=`${r}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")i=`${r}_${e.operand.index.name}`;else if(e.operand.index){let l=ie(t,e.operand.index);i=`${r}_${l}`}else return n;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 n}return Di(n,e.operator)}case"ArithTernary":return ie(t,e.condition)?ie(t,e.consequent):ie(t,e.alternate);case"ArithAssignment":{let n=e.variable,r=n;if(e.stringKey!==void 0)r=`${n}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(n);if(a&&e.subscript.type==="ArithVariable")r=`${n}_${e.subscript.name}`;else if(a){let l=ie(t,e.subscript);r=`${n}_${l}`}else{let l=ie(t,e.subscript);if(l<0){let c=$e(t,n);c.length>0&&(l=Math.max(...c.map(([f])=>typeof f=="number"?f:0))+1+l)}r=`${n}_${l}`}}let s=Number.parseInt(t.state.env[r]||"0",10)||0,i=ie(t,e.value),o=Sd(s,i,e.operator);return t.state.env[r]=String(o),o}case"ArithGroup":return ie(t,e.expression);case"ArithConcat":{let n="";for(let r of e.parts)n+=Cd(t,r);return Number.parseInt(n,10)||0}default:return 0}}function Cd(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Ye(t,e.name);case"ArithBracedExpansion":return Et(t,e.content);case"ArithCommandSubst":return"0";case"ArithConcat":{let n="";for(let r of e.parts)n+=Cd(t,r);return n}default:return String(ie(t,e))}}async function oe(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new ke("value too great for base");return e.value;case"ArithVariable":return zr(t,e.name);case"ArithNested":return oe(t,e.expression);case"ArithCommandSubst":{if(t.execFn){let r=(await t.execFn(e.command)).stdout.trim();return Number.parseInt(r,10)||0}return 0}case"ArithBracedExpansion":{let n=Et(t,e.content);return Number.parseInt(n,10)||0}case"ArithDynamicBase":{let n=Et(t,e.baseExpr),r=Number.parseInt(n,10);if(r<2||r>64)return 0;let s=`${r}#${e.value}`;return un(s)}case"ArithDynamicNumber":{let r=Et(t,e.prefix)+e.suffix;return un(r)}case"ArithArrayElement":{let n=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(n&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let i=await oe(t,e.index);r=`${e.array}_${i}`;let o=t.state.env[r];if(o!==void 0)return hn(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return hn(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(l=>l===e.array||l.startsWith(`${e.array}_`)))throw new Qe(`${e.array}[${i}]`);return 0}else return 0;let s=t.state.env[r];return s!==void 0?hn(s):0}case"ArithDoubleSubscript":throw new ke("double subscript","","");case"ArithNumberSubscript":throw new ke(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return await oe(t,e.left)||await oe(t,e.right)?1:0;if(e.operator==="&&")return await oe(t,e.left)&&await oe(t,e.right)?1:0;let n=await oe(t,e.left),r=await oe(t,e.right);return Oi(n,r,e.operator)}case"ArithUnary":{let n=await oe(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,s=Number.parseInt(Ye(t,r),10)||0,i=e.operator==="++"?s+1:s-1;return t.state.env[r]=String(i),e.prefix?i:s}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,s=t.state.associativeArrays?.has(r),i;if(e.operand.stringKey!==void 0)i=`${r}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")i=`${r}_${e.operand.index.name}`;else if(e.operand.index){let l=await oe(t,e.operand.index);i=`${r}_${l}`}else return n;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 n}return Di(n,e.operator)}case"ArithTernary":return await oe(t,e.condition)?await oe(t,e.consequent):await oe(t,e.alternate);case"ArithAssignment":{let n=e.variable,r=n;if(e.stringKey!==void 0)r=`${n}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(n);if(a&&e.subscript.type==="ArithVariable")r=`${n}_${e.subscript.name}`;else if(a){let l=await oe(t,e.subscript);r=`${n}_${l}`}else{let l=await oe(t,e.subscript);if(l<0){let c=$e(t,n);c.length>0&&(l=Math.max(...c.map(([f])=>typeof f=="number"?f:0))+1+l)}r=`${n}_${l}`}}let s=Number.parseInt(t.state.env[r]||"0",10)||0,i=await oe(t,e.value),o=Sd(s,i,e.operator);return t.state.env[r]=String(o),o}case"ArithGroup":return await oe(t,e.expression);case"ArithConcat":{let n="";for(let r of e.parts)n+=await Ad(t,r);return Number.parseInt(n,10)||0}default:return 0}}async function Ad(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Ye(t,e.name);case"ArithBracedExpansion":return Et(t,e.content);case"ArithCommandSubst":return t.execFn?(await t.execFn(e.command)).stdout.trim():"0";case"ArithConcat":{let n="";for(let r of e.parts)n+=await Ad(t,r);return n}default:return String(await oe(t,e))}}de();de();var re=Object.freeze({stdout:"",stderr:"",exitCode:0});function Ve(t=""){return{stdout:t,stderr:"",exitCode:0}}function Z(t,e=1){return{stdout:"",stderr:t,exitCode:e}}function H(t,e,n){return{stdout:t,stderr:e,exitCode:n}}function Ne(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function gt(t,e,n="",r=""){throw new Q(t,e,n,r)}function Li(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new at;return re}let n=1;if(e.length>0){let r=Number.parseInt(e[0],10);if(Number.isNaN(r)||r<1)throw new fe(128,"",`bash: break: ${e[0]}: numeric argument required
|
|
697
697
|
`);n=r}throw new Fe(n)}async function Mi(t,e){let n,r=!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]==="~"?n=t.state.env.HOME||"/":o[0]==="-"?(n=t.state.previousDir,r=!0):n=o[0],!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){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}/${n}`:`${t.state.cwd}/${p}/${n}`;try{if((await t.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${t.state.cwd}/${n}`).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 Z(`bash: cd: ${n}: Not a directory
|
|
698
698
|
`)}catch{return Z(`bash: cd: ${n}: No such file or directory
|
|
699
699
|
`)}}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,Ve(r?`${u}
|
|
700
700
|
`:"")}de();function _i(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new at;return re}if(e.length>1)throw new Fe(1);let n=1;if(e.length>0){let r=Number.parseInt(e[0],10);if(Number.isNaN(r)||r<1)return Z(`bash: continue: ${e[0]}: numeric argument required
|
|
701
|
-
`);n=r}throw new _e(n)}function zt(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function
|
|
701
|
+
`);n=r}throw new _e(n)}function zt(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function bw(t,e){return t.state.readonlyVars?.has(e)??!1}function St(t,e,n="bash"){return bw(t,e)?Z(`${n}: ${e}: readonly variable
|
|
702
702
|
`):null}function kd(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:Bi(e[2])};if(t.includes("=")){let n=t.indexOf("=");return{name:t.slice(0,n),isArray:!1,value:t.slice(n+1)}}return{name:t,isArray:!1}}function Nd(t,e,n={}){let{name:r,isArray:s,arrayElements:i,value:o}=e,{makeReadonly:a=!1,checkReadonly:l=!0}=n;if(l){let c=St(t,r);if(c)return c}if(s&&i){for(let c=0;c<i.length;c++)t.state.env[`${r}_${c}`]=i[c];t.state.env[`${r}__length`]=String(i.length)}else o!==void 0&&(t.state.env[r]=o);return a&&zt(t,r),null}function Wi(t,e){let n=!1,r=!1,s=!1,i=!1,o=!1,a=[];for(let l=0;l<e.length;l++){let c=e[l];if(c==="-a")n=!0;else if(c==="-A")r=!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"?n=!0:u==="A"?r=!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}"
|
|
703
703
|
`}}return Ve(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}'
|
|
704
|
-
`}return Ve(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(r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),r&&f.includes("[")){let d=
|
|
705
|
-
`)&&!r&&!s){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function
|
|
704
|
+
`}return Ve(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(r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),r&&f.includes("[")){let d=Ew(f);for(let[p,h]of d)t.state.env[`${u}_${p}`]=h}else{let d=Bi(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&&zt(t,u);continue}if(l.includes("=")){let u=l.indexOf("="),f=l.slice(0,u),d=l.slice(u+1),p=St(t,f);if(p)return p;t.state.env[f]=d,s&&zt(t,f)}else{let u=l;r&&(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&&(n||r?t.state.env[`${u}__length`]="0":t.state.env[u]=""),s&&zt(t,u)}}return re}function Bi(t){let e=[],n="",r=!1,s=!1,i=!1;for(let o of t){if(i){n+=o,i=!1;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!s){r=!r;continue}if(o==='"'&&!r){s=!s;continue}if((o===" "||o===" "||o===`
|
|
705
|
+
`)&&!r&&!s){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function Ew(t){let e=[],n=0;for(;n<t.length;){for(;n<t.length&&/\s/.test(t[n]);)n++;if(n>=t.length)break;if(t[n]!=="["){n++;continue}n++;let r="";if(t[n]==="'"||t[n]==='"'){let i=t[n];for(n++;n<t.length&&t[n]!==i;)r+=t[n],n++;t[n]===i&&n++}else for(;n<t.length&&t[n]!=="]"&&t[n]!=="=";)r+=t[n],n++;for(;n<t.length&&t[n]!=="]";)n++;if(t[n]==="]"&&n++,t[n]!=="=")continue;n++;let s="";if(t[n]==="'"||t[n]==='"'){let i=t[n];for(n++;n<t.length&&t[n]!==i;)t[n]==="\\"&&n+1<t.length&&n++,s+=t[n],n++;t[n]===i&&n++}else for(;n<t.length&&!/\s/.test(t[n]);)s+=t[n],n++;e.push([r,s])}return e}function Ui(t,e){let n=!1,r=!1,s=[];for(let i=0;i<e.length;i++){let o=e[i];if(o==="-a")n=!0;else if(o==="-A")r=!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}"
|
|
706
706
|
`)}return Ve(a)}}else if(o==="--"){s.push(...e.slice(i+1));break}else o.startsWith("-")||s.push(o)}for(let i of s){let o=kd(i);if(o.value===void 0&&!o.isArray){zt(t,o.name);continue}let a=Nd(t,o,{makeReadonly:!0});if(a)return a}return re}de();async function ji(t,e){let n=e;if(n.length>0){let s=n[0];if(s==="--")n=n.slice(1);else if(s.startsWith("-")&&s!=="-"&&s.length>1)return Z(`bash: eval: ${s}: invalid option
|
|
707
707
|
eval: usage: eval [arg ...]
|
|
708
708
|
`,2)}if(n.length===0)return re;let r=n.join(" ");if(r.trim()==="")return re;try{let s=bt(r);return t.executeScript(s)}catch(s){if(s instanceof Fe||s instanceof _e||s instanceof Pe||s instanceof fe)throw s;if(s.name==="ParseException")return Z(`bash: eval: ${s.message}
|
|
709
709
|
`);throw s}}de();function zi(t,e){let n,r="";if(e.length===0)n=t.state.lastExitCode;else{let s=e[0],i=Number.parseInt(s,10);s===""||Number.isNaN(i)||!/^-?\d+$/.test(s)?(r=`bash: exit: ${s}: numeric argument required
|
|
710
710
|
`,n=2):n=(i%256+256)%256}throw new fe(n,"",r)}function Hi(t,e){let n=!1,r=[];for(let o of e)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){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}'
|
|
711
711
|
`}return Ve(o)}if(n){for(let o of r){let a=o.split("=")[0];delete t.state.env[a]}return re}let s="",i=0;for(let o of r){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
|
|
712
|
-
`,i=1;continue}l!==void 0?t.state.env[a]=l:a in t.state.env||(t.state.env[a]="")}return H("",s,i)}function
|
|
713
|
-
`);let n=
|
|
714
|
-
`)}return H("","",r===0?1:0)}function
|
|
715
|
-
`);let n=t.state.localScopes[t.state.localScopes.length-1],r="",s=0;for(let i of e){let o,a;if(i.includes("=")){let l=i.indexOf("=");o=i.slice(0,l),a=
|
|
712
|
+
`,i=1;continue}l!==void 0?t.state.env[a]=l:a in t.state.env||(t.state.env[a]="")}return H("",s,i)}function Sw(t){let e=[],n="",r=0;for(let s of t){for(let i of s)i==="("?r++:i===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(e.push(n),n="")}return n&&e.push(n),e}async function Gi(t,e){if(e.length===0)return Z(`bash: let: expression expected
|
|
713
|
+
`);let n=Sw(e),r=0;for(let s of n)try{let o=bt(`(( ${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"&&(r=await oe(t,a.expression.expression))}}catch(i){return Z(`bash: let: ${s}: ${i.message}
|
|
714
|
+
`)}return H("","",r===0?1:0)}function Cw(t,e){let n=t.state.env.HOME||"/home/user";return e.split(":").map(i=>i==="~"?n:i==="~root"?"/root":i.startsWith("~/")?n+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function qi(t,e){if(t.state.localScopes.length===0)return Z(`bash: local: can only be used in a function
|
|
715
|
+
`);let n=t.state.localScopes[t.state.localScopes.length-1],r="",s=0;for(let i of e){let o,a;if(i.includes("=")){let l=i.indexOf("=");o=i.slice(0,l),a=Cw(t,i.slice(l+1))}else o=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: local: \`${i}': not a valid identifier
|
|
716
716
|
`,s=1;continue}n.has(o)||n.set(o,t.state.env[o]),a!==void 0&&(t.state.env[o]=a)}return H("",r,s)}function Vi(t,e,n){let r=`
|
|
717
717
|
`,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<e.length;){let g=e[c];g==="-d"&&c+1<e.length?(r=e[c+1]||`
|
|
718
718
|
`,c+=2):g==="-n"&&c+1<e.length?(s=Number.parseInt(e[c+1],10)||0,c+=2):g==="-O"&&c+1<e.length?(i=Number.parseInt(e[c+1],10)||0,c+=2):g==="-s"&&c+1<e.length?(o=Number.parseInt(e[c+1],10)||0,c+=2):g==="-t"?(a=!0,c++):g==="-u"||g==="-C"||g==="-c"?c+=2:(g.startsWith("-")||(l=g),c++)}let u=n;!u&&t.state.groupStdin!==void 0&&(u=t.state.groupStdin);let f=[],d=u,p=0,h=0;for(;d.length>0;){let g=d.indexOf(r);if(g===-1){d.length>0&&(h<o?h++:(s===0||p<s)&&(f.push(d),p++));break}let m=d.substring(0,g);if(a||(m+=r),d=d.substring(g+r.length),h<o){h++;continue}if(s>0&&p>=s)break;f.push(m),p++}jn(t,l);for(let g=0;g<f.length;g++)t.state.env[`${l}_${i+g}`]=f[g];return f.length>0&&(t.state.env[`${l}__length`]=String(i+f.length)),t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=""),H("","",0)}function Zi(t,e,n){let r=!1,s=`
|
|
719
719
|
`,i="",o=-1,a=null,l=[],c=0,u=!1;for(;c<e.length;){let b=e[c];b==="-r"?r=!0:b==="-d"&&c+1<e.length?(s=e[c+1],c++):b==="-p"&&c+1<e.length?(i=e[c+1],c++):b==="-n"&&c+1<e.length?(o=Number.parseInt(e[c+1],10),(Number.isNaN(o)||o<0)&&(u=!0,o=0),c++):b==="-a"&&c+1<e.length?(a=e[c+1],c++):b==="-t"?c+1<e.length&&!e[c+1].startsWith("-")&&c++:b==="-s"||b.startsWith("-")||l.push(b),c++}if(u)return H("","",1);l.length===0&&a===null&&l.push("REPLY");let f=n;!f&&t.state.groupStdin!==void 0&&(f=t.state.groupStdin);let d="",p=0,h=!0;if(o>=0){for(let b=0;b<f.length&&b<o;b++){let E=f[b];if(E===s){p=b+1;break}d+=E,p=b+1}t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=f.substring(p))}else{let b=f;for(p=0;;){let E=b.indexOf(s);if(E!==-1){let S=b.substring(0,E);if(p+=E+s.length,b=b.substring(E+s.length),!r&&S.endsWith("\\")){d+=S.slice(0,-1);continue}d+=S,h=!0;break}else if(b.length>0){d+=b,p+=b.length,h=!1,b="";break}else{if(d.length===0){for(let S of l)t.state.env[S]="";return a&&jn(t,a),H("","",1)}h=!1;break}}t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=f.substring(p))}if(s===`
|
|
720
720
|
`&&d.endsWith(`
|
|
721
721
|
`)&&(d=d.slice(0,-1)),r||(d=d.replace(/\\(.)/g,"$1")),l.length===1&&l[0]==="REPLY")return t.state.env.REPLY=d,H("","",h?0:1);let g=Wr(t.state.env),{words:m,wordStarts:w}=ld(d,g);if(a){jn(t,a);for(let b=0;b<m.length;b++)t.state.env[`${a}_${b}`]=m[b];return H("","",h?0:1)}for(let b=0;b<l.length;b++){let E=l[b];if(b<l.length-1)t.state.env[E]=m[b]??"";else if(b<w.length){let S=cd(d.substring(w[b]),g);t.state.env[E]=S}else t.state.env[E]=""}return H("","",h?0:1)}de();function Ki(t,e){if(t.state.callDepth===0&&t.state.sourceDepth===0)return Z("bash: return: can only `return' from a function or sourced script\n");let n=t.state.lastExitCode;if(e.length>0){let r=e[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return Z(`bash: return: ${r}: numeric argument required
|
|
722
|
-
`,2);n=(s%256+256)%256}throw new Pe(n)}function
|
|
722
|
+
`,2);n=(s%256+256)%256}throw new Pe(n)}function Aw(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var Hr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
|
|
723
723
|
Options:
|
|
724
724
|
-e Exit immediately if a command exits with non-zero status
|
|
725
725
|
+e Disable -e
|
|
@@ -735,9 +735,9 @@ Options:
|
|
|
735
735
|
+o pipefail Disable pipefail
|
|
736
736
|
-o xtrace Same as -x
|
|
737
737
|
+o xtrace Disable xtrace
|
|
738
|
-
`,Id={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},vd={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},$d=["errexit","nounset","pipefail","verbose","xtrace"],Rd=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function Fd(t,e,n){e!==null&&(t.state.options[e]=n)}function
|
|
738
|
+
`,Id={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},vd={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},$d=["errexit","nounset","pipefail","verbose","xtrace"],Rd=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function Fd(t,e,n){e!==null&&(t.state.options[e]=n)}function kw(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function Xi(t,e){if(e.includes("--help"))return Ve(Hr);if(e.length===0){let r=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}=${Aw(i)}`).join(`
|
|
739
739
|
`);return Ve(r?`${r}
|
|
740
|
-
`:"")}let n=0;for(;n<e.length;){let r=e[n];if((r==="-o"||r==="+o")&&
|
|
740
|
+
`:"")}let n=0;for(;n<e.length;){let r=e[n];if((r==="-o"||r==="+o")&&kw(e,n)){let s=e[n+1];if(!(s in vd))return Z(`bash: set: ${s}: invalid option name
|
|
741
741
|
${Hr}`);Fd(t,vd[s],r==="-o"),n+=2;continue}if(r==="-o"){let s=$d.map(a=>`${a.padEnd(16)}${t.state.options[a]?"on":"off"}`),i=Rd.map(a=>`${a.padEnd(16)}off`),o=[...s,...i].sort();return Ve(`${o.join(`
|
|
742
742
|
`)}
|
|
743
743
|
`)}if(r==="+o"){let s=$d.map(a=>`set ${t.state.options[a]?"-o":"+o"} ${a}`),i=Rd.map(a=>`set +o ${a}`),o=[...s,...i].sort();return Ve(`${o.join(`
|
|
@@ -751,10 +751,10 @@ ${Hr}`):(Qi(t,e.slice(n)),re)}return re}function Qi(t,e){let n=1;for(;t.state.en
|
|
|
751
751
|
`);let o={};if(n.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=n.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--,n.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=bt(i),c=await t.executeScript(l);return a(),c}catch(l){if(a(),l instanceof fe)throw l;if(l instanceof Pe)return H(l.stdout,l.stderr,l.exitCode);if(l.name==="ParseException")return Z(`bash: ${r}: ${l.message}
|
|
752
752
|
`);throw l}}function eo(t,e){let n="variable",r="",s=0;for(let i of e){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="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=$e(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=$e(t,a),f=u.length;if(f===0){r+=`bash: unset: [${c}]: bad array subscript
|
|
753
753
|
`,s=1;continue}let d=f+c;if(d<0){r+=`bash: unset: [${c}]: bad array subscript
|
|
754
|
-
`,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 H("",r,s)}function to(t,e){return t.fs.resolvePath(t.state.cwd,e)}var
|
|
754
|
+
`,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 H("",r,s)}function to(t,e){return t.fs.resolvePath(t.state.cwd,e)}var Nw=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Gr(t){return Nw.includes(t)}async function qr(t,e,n){let r=to(t,n);switch(e){case"-e":case"-a":return t.fs.exists(r);case"-f":return await t.fs.exists(r)?(await t.fs.stat(r)).isFile:!1;case"-d":return await t.fs.exists(r)?(await t.fs.stat(r)).isDirectory:!1;case"-r":case"-w":case"-x":return t.fs.exists(r);case"-s":return await t.fs.exists(r)?(await t.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await t.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&512)!==0:!1;case"-g":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return t.fs.exists(r);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=>r===i||r.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return t.fs.exists(r);default:return!1}}var Iw=["-nt","-ot","-ef"];function Vr(t){return Iw.includes(t)}async function Zr(t,e,n,r){let s=to(t,n),i=to(t,r);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 vw=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Kr(t){return vw.has(t)}function Qr(t,e,n){switch(t){case"-eq":return e===n;case"-ne":return e!==n;case"-lt":return e<n;case"-le":return e<=n;case"-gt":return e>n;case"-ge":return e>=n}}function Xr(t){return t==="="||t==="=="||t==="!="}function Jr(t,e,n,r=!1){let s=r?Yr(e,n):e===n;return t==="!="?!s:s}var $w=new Set(["-z","-n"]);function es(t){return $w.has(t)}function ts(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function ns(t,e){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[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=Un(t,r);if(o.length===0||(i=Math.max(...o)+1+i,i<0))return!1}return`${r}_${i}`in t.state.env}return e in t.state.env}async function Ct(t,e){switch(e.type){case"CondBinary":{let n=await he(t,e.left),r=await he(t,e.right),s=e.right.parts.length>0&&e.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped");if(Xr(e.operator))return Jr(e.operator,n,r,!s);if(Kr(e.operator))return Qr(e.operator,Td(t,n),Td(t,r));if(Vr(e.operator))return Zr(t,e.operator,n,r);switch(e.operator){case"=~":try{let i=new RegExp(r),o=n.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 n<r;case">":return n>r;default:return!1}}case"CondUnary":{let n=await he(t,e.operand);return Gr(e.operator)?qr(t,e.operator,n):es(e.operator)?ts(e.operator,n):e.operator==="-v"?ns(t,n):e.operator==="-o"?ro(t,n):!1}case"CondNot":return!await Ct(t,e.operand);case"CondAnd":return await Ct(t,e.left)?await Ct(t,e.right):!1;case"CondOr":return await Ct(t,e.left)?!0:await Ct(t,e.right);case"CondGroup":return await Ct(t,e.expression);case"CondWord":return await he(t,e.word)!=="";default:return!1}}async function mn(t,e){if(e.length===0)return H("","",1);if(e.length===1)return Ne(!!e[0]);if(e.length===2){let r=e[0],s=e[1];return r==="("?Z(`test: '(' without matching ')'
|
|
755
755
|
`,2):Gr(r)?Ne(await qr(t,r,s)):es(r)?Ne(ts(r,s)):r==="!"?Ne(!s):r==="-v"?Ne(ns(t,s)):r==="-o"?Ne(ro(t,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?Z(`test: ${r}: unary operator expected
|
|
756
756
|
`,2):H("","",1)}if(e.length===3){let r=e[0],s=e[1],i=e[2];if(Xr(s))return Ne(Jr(s,r,i));if(Kr(s)){let o=rs(r),a=rs(i);return!o.valid||!a.valid?H("","",2):Ne(Qr(s,o.value,a.value))}if(Vr(s))return Ne(await Zr(t,s,r,i));switch(s){case"-a":return Ne(r!==""&&i!=="");case"-o":return Ne(r!==""||i!=="");case">":return Ne(r>i);case"<":return Ne(r<i)}if(r==="!"){let o=await mn(t,[s,i]);return H("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return Ne(s!=="")}if(e.length===4){if(e[0]==="!"){let r=await mn(t,e.slice(1));return H("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(e[0]==="("&&e[3]===")")return mn(t,[e[1],e[2]])}let n=await Dd(t,e,0);return n.pos<e.length?Z(`test: too many arguments
|
|
757
|
-
`,2):Ne(n.value)}async function Dd(t,e,n){return
|
|
757
|
+
`,2):Ne(n.value)}async function Dd(t,e,n){return Rw(t,e,n)}async function Rw(t,e,n){let{value:r,pos:s}=await Pd(t,e,n);for(;e[s]==="-o";){let i=await Pd(t,e,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function Pd(t,e,n){let{value:r,pos:s}=await no(t,e,n);for(;e[s]==="-a";){let i=await no(t,e,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function no(t,e,n){if(e[n]==="!"){let{value:r,pos:s}=await no(t,e,n+1);return{value:!r,pos:s}}return Fw(t,e,n)}async function Fw(t,e,n){let r=e[n];if(r==="("){let{value:i,pos:o}=await Dd(t,e,n+1);return{value:i,pos:e[o]===")"?o+1:o}}if(Gr(r)){let i=e[n+1]??"";return{value:await qr(t,r,i),pos:n+2}}if(es(r)){let i=e[n+1]??"";return{value:ts(r,i),pos:n+2}}if(r==="-v"){let i=e[n+1]??"";return{value:ns(t,i),pos:n+2}}if(r==="-o"){let i=e[n+1]??"";return{value:ro(t,i),pos:n+2}}let s=e[n+1];if(Xr(s)){let i=r,o=e[n+2]??"";return{value:Jr(s,i,o),pos:n+3}}if(Kr(s)){let i=rs(r),o=rs(e[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:Qr(s,i.value,o.value),pos:n+3}}if(Vr(s)){let i=r,o=e[n+2]??"";return{value:await Zr(t,s,i,o),pos:n+3}}return{value:r!==void 0&&r!=="",pos:n+1}}function Yr(t,e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n).test(t)}function ro(t,e){let r={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 r?r():!1}function Td(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 Od(e);try{let n=new Re,r=ve(n,e);return ie(t,r.expression)}catch{return Od(e)}}function Pw(t,e){let n=0;for(let r of t){let s;if(r>="0"&&r<="9")s=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")s=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")s=r.charCodeAt(0)-65+36;else if(r==="@")s=62;else if(r==="_")s=63;else return Number.NaN;if(s>=e)return Number.NaN;n=n*e+s}return n}function Od(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 n,r=t.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let s=Number.parseInt(r[1],10);s>=2&&s<=64?n=Pw(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(t)?n=Number.parseInt(t,16):/^0[0-7]+$/.test(t)?n=Number.parseInt(t,8):n=Number.parseInt(t,10);return Number.isNaN(n)&&(n=0),e?-n:n}function rs(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 n=Number.parseInt(t,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:e?-n:n,valid:!0}}de();async function so(t,e){let n=t.state.inCondition;t.state.inCondition=!0;let r="",s="",i=0;try{for(let o of e){let a=await t.executeStatement(o);r+=a.stdout,s+=a.stderr,i=a.exitCode}}finally{t.state.inCondition=n}return{stdout:r,stderr:s,exitCode:i}}de();nt();function Gn(t,e,n,r){if(t instanceof Fe)return e+=t.stdout,n+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=n,{action:"rethrow",stdout:e,stderr:n,error:t}):{action:"break",stdout:e,stderr:n};if(t instanceof _e)return e+=t.stdout,n+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=n,{action:"rethrow",stdout:e,stderr:n,error:t}):{action:"continue",stdout:e,stderr:n};if(t instanceof Pe||t instanceof it||t instanceof fe||t instanceof Q)return t.prependOutput(e,n),{action:"rethrow",stdout:e,stderr:n,error:t};let s=ye(t);return{action:"error",stdout:e,stderr:`${n}${s}
|
|
758
758
|
`,exitCode:1}}de();nt();async function ss(t,e,n="",r=""){let s=n,i=r,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(or(a)||a instanceof it||a instanceof fe||a instanceof Q||a instanceof at)throw a.prependOutput(s,i),a;return{stdout:s,stderr:`${i}${ye(a)}
|
|
759
759
|
`,exitCode:1}}return{stdout:s,stderr:i,exitCode:o}}async function Ld(t,e){let n="",r="";for(let s of e.clauses){let i=await so(t,s.condition);if(n+=i.stdout,r+=i.stderr,i.exitCode===0)return ss(t,s.body,n,r)}return e.elseBody?ss(t,e.elseBody,n,r):H(n,r,0)}async function Md(t,e){let n="",r="",s=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.variable))return Z(`bash: \`${e.variable}': not a valid identifier
|
|
760
760
|
`);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 Hn(t,a);o.push(...l.values)}t.state.loopDepth++;try{for(let a of o){i++,i>t.limits.maxLoopIterations&>(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),t.state.env[e.variable]=a;try{for(let l of e.body){let c=await t.executeStatement(l);n+=c.stdout,r+=c.stderr,s=c.exitCode}}catch(l){let c=Gn(l,n,r,t.state.loopDepth);if(n=c.stdout,r=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return H(n,r,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return H(n,r,s)}async function _d(t,e){let n="",r="",s=0,i=0;e.init&&await oe(t,e.init.expression),t.state.loopDepth++;try{for(;i++,i>t.limits.maxLoopIterations&>(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),!(e.condition&&await oe(t,e.condition.expression)===0);){try{for(let o of e.body){let a=await t.executeStatement(o);n+=a.stdout,r+=a.stderr,s=a.exitCode}}catch(o){let a=Gn(o,n,r,t.state.loopDepth);if(n=a.stdout,r=a.stderr,a.action==="break")break;if(a.action==="continue"){e.update&&await oe(t,e.update.expression);continue}if(a.action==="error")return H(n,r,a.exitCode??1);throw a.error}e.update&&await oe(t,e.update.expression)}}finally{t.state.loopDepth--}return H(n,r,s)}async function Bd(t,e,n=""){let r="",s="",i=0,o=0,a=n;for(let c of e.redirections)if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let u=c.target,f=await he(t,u.content);u.stripTabs&&(f=f.split(`
|
|
@@ -788,15 +788,15 @@ ${Hr}`):(Qi(t,e.slice(n)),re)}return re}function Qi(t,e){let n=1;for(;t.state.en
|
|
|
788
788
|
`,1)}return this.ctx.state.env=r,this.ctx.state.cwd=s,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,H(l,c,u)}async executeGroup(e,n=""){let r="",s="",i=0,o=this.ctx.state.groupStdin;n&&(this.ctx.state.groupStdin=n);try{for(let a of e.body){let l=await this.executeStatement(a);r+=l.stdout,s+=l.stderr,i=l.exitCode}}catch(a){if(this.ctx.state.groupStdin=o,a instanceof Q)throw a;if(or(a)||a instanceof it||a instanceof fe)throw a.prependOutput(r,s),a;return H(r,`${s}${ye(a)}
|
|
789
789
|
`,1)}return this.ctx.state.groupStdin=o,H(r,s,i)}async executeArithmeticCommand(e){try{let n=await oe(this.ctx,e.expression.expression);return Ne(n!==0)}catch(n){return Z(`bash: arithmetic expression: ${n.message}
|
|
790
790
|
`)}}async executeConditionalCommand(e){try{let n=await Ct(this.ctx,e.expression);return Ne(n)}catch(n){return Z(`bash: conditional expression: ${n.message}
|
|
791
|
-
`,2)}}};var At={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Gd(t){return t?{maxCallDepth:t.maxCallDepth??At.maxCallDepth,maxCommandCount:t.maxCommandCount??At.maxCommandCount,maxLoopIterations:t.maxLoopIterations??At.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??At.maxAwkIterations,maxSedIterations:t.maxSedIterations??At.maxSedIterations,maxJqIterations:t.maxJqIterations??At.maxJqIterations,maxSqliteTimeoutMs:t.maxSqliteTimeoutMs??At.maxSqliteTimeoutMs}:{...At}}function qd(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function
|
|
791
|
+
`,2)}}};var At={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Gd(t){return t?{maxCallDepth:t.maxCallDepth??At.maxCallDepth,maxCommandCount:t.maxCommandCount??At.maxCommandCount,maxLoopIterations:t.maxLoopIterations??At.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??At.maxAwkIterations,maxSedIterations:t.maxSedIterations??At.maxSedIterations,maxJqIterations:t.maxJqIterations??At.maxJqIterations,maxSqliteTimeoutMs:t.maxSqliteTimeoutMs??At.maxSqliteTimeoutMs}:{...At}}function qd(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function Tw(t){let e=qd(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function Ow(t,e){let n=qd(t);if(!n)return!1;let r=Tw(e);return!r||n.origin!==r.origin?!1:r.pathPrefix==="/"||r.pathPrefix===""?!0:n.pathname.startsWith(r.pathPrefix)}function io(t,e){return!e||e.length===0?!1:e.some(n=>Ow(t,n))}var gn=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},yn=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},xn=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},is=class extends Error{constructor(e,n){super(`HTTP method '${e}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}};var Dw=20,Lw=3e4,Mw=["GET","HEAD"],_w=new Set(["GET","HEAD","OPTIONS"]),Bw=new Set([301,302,303,307,308]);function oo(t){let e=t.maxRedirects??Dw,n=t.timeoutMs??Lw,r=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??Mw;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!io(a,t.allowedUrlPrefixes??[]))throw new gn(a)}function i(a){if(t.dangerouslyAllowFullInternetAccess)return;let l=a.toUpperCase();if(!r.includes(l))throw new is(l,r)}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,n):n;for(;;){let h=new AbortController,g=setTimeout(()=>h.abort(),p);try{let m={method:c,headers:l.headers,signal:h.signal,redirect:"manual"};l.body&&!_w.has(c)&&(m.body=l.body);let w=await fetch(u,m);if(Bw.has(w.status)&&d){let b=w.headers.get("location");if(!b)return await Vd(w,u);let E=new URL(b,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!io(E,t.allowedUrlPrefixes??[]))throw new xn(E);if(f++,f>e)throw new yn(e);u=E;continue}return await Vd(w,u)}finally{clearTimeout(g)}}}return o}async function Vd(t,e){let n={};return t.headers.forEach((r,s)=>{n[s.toLowerCase()]=r}),{status:t.status,statusText:t.statusText,headers:n,body:await t.text(),url:e}}var ao=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(e={}){let n=e.fs??new Bt(e.files);this.fs=n,this.useDefaultLayout=!e.cwd&&!e.files;let r=e.cwd||(this.useDefaultLayout?"/home/user":"/"),s={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
|
|
792
792
|
`,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:r,OLDPWD:r,...e.env};if(this.limits=Gd({...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=oo(e.network)),this.sleepFn=e.sleep,this.traceFn=e.trace,this.logger=e.logger,this.state={env:s,cwd:r,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},Pf(n,this.useDefaultLayout),r!=="/"&&n instanceof Bt)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let i of Af(e.commands))this.registerCommand(i);if(e.network)for(let i of kf())this.registerCommand(i);if(e.customCommands)for(let i of e.customCommands)Nf(i)?this.registerCommand(If(i)):this.registerCommand(i)}registerCommand(e){this.commands.set(e.name,e);let n=this.fs;if(typeof n.writeFileSync=="function")try{n.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
|
|
793
793
|
# Built-in command: ${e.name}
|
|
794
794
|
`)}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,n){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.
|
|
795
|
-
`,exitCode:1,env:{...this.state.env,...n?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...n?.env}};this.logger?.info("exec",{command:e});let r=n?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...n?.env,...n?.cwd?{PWD:n.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},i=e;n?.rawScript||(i=e.
|
|
796
|
-
`).map(a=>a.trimStart()).join(`
|
|
797
|
-
`));try{let o=bt(i),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},c=await new qn(a,s).executeScript(o);return this.logResult(c)}catch(o){if(o instanceof fe)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,env:{...this.state.env,...n?.env}});if(o instanceof ke)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:1,env:{...this.state.env,...n?.env}});if(o instanceof Q)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:Q.EXIT_CODE,env:{...this.state.env,...n?.env}});if(o.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${o.message}
|
|
795
|
+
`,exitCode:1,env:{...this.state.env,...n?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...n?.env}};this.logger?.info("exec",{command:e});let r=n?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...n?.env,...n?.cwd?{PWD:n.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},i=e;n?.rawScript||(i=Ww(e));try{let o=bt(i),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},c=await new qn(a,s).executeScript(o);return this.logResult(c)}catch(o){if(o instanceof fe)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,env:{...this.state.env,...n?.env}});if(o instanceof ke)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:1,env:{...this.state.env,...n?.env}});if(o instanceof Q)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:Q.EXIT_CODE,env:{...this.state.env,...n?.env}});if(o.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${o.message}
|
|
798
796
|
`,exitCode:2,env:{...this.state.env,...n?.env}});if(o instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${o.message}
|
|
799
|
-
`,exitCode:1,env:{...this.state.env,...n?.env}});throw o}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),n)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};
|
|
797
|
+
`,exitCode:1,env:{...this.state.env,...n?.env}});throw o}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),n)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function Ww(t){let e=t.split(`
|
|
798
|
+
`),n=[],r=[];for(let s=0;s<e.length;s++){let i=e[s];if(r.length>0){let l=r[r.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){n.push(i.trimStart()),r.pop();continue}n.push(i);continue}let o=i.trimStart();n.push(o);let a=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of o.matchAll(a)){let c=l[1]==="-",u=l[3];r.push({delimiter:u,stripTabs:c})}}return n.join(`
|
|
799
|
+
`)}export{ao as Bash,Bt as InMemoryFs,gn as NetworkAccessDeniedError,xn as RedirectNotAllowedError,yn as TooManyRedirectsError,Ax as defineCommand,Sx as getCommandNames,Cx as getNetworkCommandNames};
|
|
800
800
|
/*! Bundled license information:
|
|
801
801
|
|
|
802
802
|
ieee754/index.js:
|