just-bash 3.6.1 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -796,7 +796,7 @@ sys 0m0.000s
796
796
  `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],c=l>0?t.operators[l-1]:null;if(c==="&&"&&r!==0||c==="||"&&r===0)continue;let f=await this.executePipeline(u);n.appendResult(f,zs(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new Me(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return bf(this.ctx,t,(n,r,s)=>this.executeCommand(n,r,s))}async executeCommand(t,n,r=!1){let s=qu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await Bi(this.ctx,s).catch(()=>{}),a}let o=await Bi(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?_t(i)+o.stdout:i.stdout,stdoutKind:o.stdout?"bytes":i.stdoutKind,stderr:i.stderr+o.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n,r);case"If":return hf(this.ctx,t);case"For":return mf(this.ctx,t);case"CStyleFor":return yf(this.ctx,t);case"While":return gf(this.ctx,t,n);case"Until":return wf(this.ctx,t,n);case"Case":return Ef(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return xc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Cm(t)}}async executeSimpleCommand(t,n,r){let s;try{return await this.executeSimpleCommandInner(t,n,r,i=>{s=i})}catch(i){if(s?.finish(),i instanceof Lt)return L(i.stderr);throw i}}async executeSimpleCommandInner(t,n,r,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let D=t,R=0;for(;;){let B=this.expandAlias(D);if(B===D)break;if(R>=this.ctx.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");R++,D=B}this.aliasExpansionStack.clear(),D!==t&&(t=D)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let i=await tf(this.ctx,t);if(i.error)return i.error;let o=i.tempAssignments,a=i.xtraceOutput,l=()=>{for(let[D,R]of o)R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R)};if(!t.name){if(t.redirections.length>0){let R=Un(this.ctx,t.redirections,Ac);s(R);let B=await R.prepare(n);if(B.error){if(l(),!B.errorCause)return R.finish(),B.error;try{return jn(B)}finally{R.finish()}}let k=T("",a,Jr(this.ctx.state,t.redirections)),M=await sn(this.ctx,k,t.redirections.length>0,B.outputRoutes);return R.finish(),M}this.ctx.state.lastArg="";let D=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",T("",D,Jr(this.ctx.state,[]))}let u=t.name&&ea(t.name,["local","declare","typeset","export","readonly"]),c=Array.from(o.keys());if(c.length>0&&!u){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let D of c)this.ctx.state.tempExportedVars.add(D)}let f=await ne(this.ctx,t.name),d=[],p=[],h=(D,R)=>{if(d.length>=this.ctx.limits.maxArrayElements)throw new C(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");d.push(D),p.push(R)};if(ea(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let D of t.args){let R=await ec(this.ctx,D);if(R)h(R,!0);else{let B=await tc(this.ctx,D);if(B!==null)h(B,!0);else{let k=await gt(this.ctx,D);for(let M of k.values)h(M,k.quoted)}}}else for(let D of t.args){let R=await gt(this.ctx,D);for(let B of R.values)h(B,R.quoted)}let y=t.name.parts.every(D=>D.type==="CommandSubstitution"||D.type==="ParameterExpansion"||D.type==="ArithmeticExpansion");!f&&y&&d.length>0&&(f=d.shift(),p.shift());let b=Un(this.ctx,t.redirections,f==="exec"?vc:mr);s(b);let w=await b.prepare(n);if(w.error)return l(),w.errorCause?jn(w):(b.finish(),w.error);let E=w.stdinSourceFd,S=w.stdin!==void 0,v=r||w.stdinReplaced;if(w.stdin!==void 0&&(n=w.stdin),!f)return y?(b.finish(),T("","",Jr(this.ctx.state,t.redirections))):(b.finish(),L(`bash: : command not found
797
797
  `,127));if(f==="exec"&&(d.length===0||d[0]==="--")){for(let[D,R]of o)R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R);if(this.ctx.state.tempExportedVars)for(let D of o.keys())this.ctx.state.tempExportedVars.delete(D);return b.finish(),J}if(this.ctx.state.extraArgs){let D=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let R of D)h(R,!0)}let A=await Jc(this.ctx,f,d);o.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(o)));let x,$=null;try{x=await this.runCommand(f,d,p,n,!1,!1,E,S,v,w.stdinUnavailable)}catch(D){if(D instanceof Ge||D instanceof He)$=D,x=J;else throw D}E>=0&&f!=="read"&&nn(this.ctx,E,x.internalStdinConsumed??0);let I=a+A;if(I&&(x={...x,stderr:I+x.stderr}),x=await sn(this.ctx,x,t.redirections.length>0,w.outputRoutes,x.internalProducerCommand??f,x.internalProducerOmitsShellPrefix),b.finish(),$)throw $;if(d.length>0){let D=d[d.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(D)){let R=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);R&&(D=R[1])}this.ctx.state.lastArg=D}else this.ctx.state.lastArg=f;let P=yc(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!P)for(let[D,R]of o)this.ctx.state.fullyUnsetLocals?.has(D)||(R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R));if(this.ctx.state.tempExportedVars)for(let D of o.keys())this.ctx.state.tempExportedVars.delete(D);return o.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(x={...x,stderr:this.ctx.state.expansionStderr+x.stderr},this.ctx.state.expansionStderr=""),x}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1,u=!1,c=!1){let f={ctx:this.ctx,runCommand:(h,m,y,b,w,E,S,v,A,x)=>this.runCommand(h,m,y,b,w,E,S,v,A,x),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(h,m,y)=>this.executeUserScript(h,m,y)},d=await ff(f,t,n,r,s,i,o,a,l,u,c);return d!==null?d.internalProducerCommand===void 0?{...d,internalProducerCommand:t}:d:{...await df(f,t,n,s,o,u,c),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Pl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Ts(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Sf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return Af(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await X(this.ctx,t.expression.expression),r=ge(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return L(`bash: arithmetic expression: ${n.message}
798
798
  `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await Jt(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof oe?1:2;return L(`bash: conditional expression: ${n.message}
799
- `,r)}})}};function ra(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Nm(e){let t=ra(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Rm=3;function xf(e){let t=e;for(let n=0;n<Rm;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function Dm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function sa(e,t){let n=ra(e);if(!n)return!1;let r=Nm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&xf(n.pathname)?!1:Dm(n.pathname,r.pathPrefix)}function $f(e){return typeof e=="string"?e:e.url}function kf(e,t){return!t||t.length===0?!1:t.some(n=>sa(e,$f(n)))}function ia(e){let t=Im(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Pf(t);if(n)return Bs(n);let r=_m(t);return r?Lm(r):!1}function Im(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Om(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function Pf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Om(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function _m(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Pf(y);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Bs(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function Lm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Bs(s)}return!1}function Cf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=$f(n);if(!ra(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&xf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Et=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Qn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ln=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ws=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},An=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Tm=20,Fm=3e4,Mm=10485760,Bm=["GET","HEAD"],xr;typeof __BROWSER__<"u"&&__BROWSER__?xr=null:(xr=import("./chunks/dist-4NZ74CRE.js"),xr.catch(()=>{}));var Wm=new Set(["GET","HEAD","OPTIONS"]),Vm=new Set([301,302,303,307,308]);function $r(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function zm(e){if(e?.aborted)throw $r(e)}function aa(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let S=Cf(t);if(S.length>0)throw new Error(`Invalid network allow-list:
799
+ `,r)}})}};function ra(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Nm(e){let t=ra(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Rm=3;function xf(e){let t=e;for(let n=0;n<Rm;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function Dm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function sa(e,t){let n=ra(e);if(!n)return!1;let r=Nm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&xf(n.pathname)?!1:Dm(n.pathname,r.pathPrefix)}function $f(e){return typeof e=="string"?e:e.url}function kf(e,t){return!t||t.length===0?!1:t.some(n=>sa(e,$f(n)))}function ia(e){let t=Im(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Pf(t);if(n)return Bs(n);let r=_m(t);return r?Lm(r):!1}function Im(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Om(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function Pf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Om(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function _m(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Pf(y);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Bs(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function Lm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Bs(s)}return!1}function Cf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=$f(n);if(!ra(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&xf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Et=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Qn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ln=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ws=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},An=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Tm=20,Fm=3e4,Mm=10485760,Bm=["GET","HEAD"],xr;typeof __BROWSER__<"u"&&__BROWSER__?xr=null:(xr=import("./chunks/dist-Q3QP7DWN.js"),xr.catch(()=>{}));var Wm=new Set(["GET","HEAD","OPTIONS"]),Vm=new Set([301,302,303,307,308]);function $r(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function zm(e){if(e?.aborted)throw $r(e)}function aa(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let S=Cf(t);if(S.length>0)throw new Error(`Invalid network allow-list:
800
800
  ${S.join(`
801
801
  `)}`)}let r=[];for(let S of t)typeof S=="object"&&S.transform&&S.transform.length>0&&r.push(S);function s(S){if(r.length===0)return null;let v=null;for(let A of r)if(sa(S,A.url)&&A.transform){v||(v=new Headers);for(let x of A.transform)for(let[$,I]of Object.entries(x.headers))v.set($,I)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??Tm,o=e.timeoutMs??Fm,a=e.maxResponseSize??Mm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Bm,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let S of t){let v=typeof S=="string"?S:S.url;try{c.push(new URL(v).hostname)}catch{}}function f(S){try{return new URL(S).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(S){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(S)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(S){try{return ia(new URL(S).hostname)}catch{return!1}}async function h(S,v){let A={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(A.body=v.body),await(n??globalThis.fetch)(S,A)}function m(S){if(!e.dangerouslyAllowFullInternetAccess&&!kf(S,t))throw new Et(S)}function y(S){if(!u)return;let v;try{v=new URL(S)}catch{throw new Et(S,"invalid URL")}if(ia(v.hostname))throw new Et(S,"private/loopback IP address blocked")}function b(S){if(e.dangerouslyAllowFullInternetAccess)return;let v=S.toUpperCase();if(!l.includes(v))throw new Ws(v,l)}function w(S,v,A,x){if(!A.isGuardedFetchError(S))return S;let $=S,{onRedirectHop:I,subReason:P}=x;switch($.code){case"host_not_allowed":case"protocol_not_allowed":return I?new ln(v):new Et(v);case"hostname_unsafe":return I?new ln(v):new Et(v,P==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new ln(v);case"too_many_redirects":return new Qn(i);case"response_too_large":return new An(a);default:return S}}async function E(S,v={}){let A=v.method?.toUpperCase()??"GET",x=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let $=v.maxRedirects??i,I=Math.min(i,$),P=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,N=new AbortController,D=ua(()=>N.abort(new DOMException("The operation was aborted","AbortError")),P),R=Rr(v.signal,N.signal);try{m(S),y(S),b(A);let B=xr?await xr:null,k=S,M=0,z=[],O=A,_=v.body,V=v.headers,ee=!1;for(;;){zm(R.signal);let K=await _e.runTrustedAsync(async()=>{let De=V;if(ee&&De){let Nt=De instanceof Headers?new Headers(De):new Headers(De);Nt.delete("authorization"),Nt.delete("cookie"),De=Nt}let at=s(k),Ct=Um(De,at),lt={method:O,headers:Ct,signal:R.signal,followRedirects:!1,timeoutMs:P,sanitizeHeaders:!1};if(_&&!Wm.has(O)&&(lt.body=_),Object.assign(lt,d(k)),!B||p(k)){if(u)throw new Et(k,"DNS pinning unavailable for private IP enforcement");return await h(k,lt)}u?n&&(lt.fetch=n):(lt.fetch=n??globalThis.fetch,lt.dispatcher=null);let ut;lt.onUrlBlocked=Nt=>{ut=Nt.subReason};try{return await B.guardedFetch(k,lt)}catch(Nt){throw w(Nt,k,B,{onRedirectHop:M>0,subReason:ut})}});if(Vm.has(K.status)&&x){let De=K.headers.get("location");if(!De)return await Nf(K,k,a,R.signal,z);z.push({status:K.status,statusText:K.statusText,headers:Rf(K.headers)});let at=new URL(De,k).href;await oa(qm(K),R.signal);try{m(at),y(at)}catch(ut){throw R.signal?.aborted?$r(R.signal):ut instanceof Et?new ln(at):ut}let Ct=K.status;if(((Ct===301||Ct===302)&&O==="POST"||Ct===303&&O!=="GET"&&O!=="HEAD")&&(O="GET",_=void 0,b(O)),new URL(at).origin!==new URL(k).origin&&(ee=!0),M++,M>I)throw new Qn(I);k=at;continue}return await Nf(K,k,a,R.signal,z)}}finally{ca(D),R.cleanup()}}return E}async function oa(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),$r(t);let n,r=new Promise((s,i)=>{n=()=>i($r(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function qm(e){e.body&&!e.body.locked&&await e.body.cancel()}function Um(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Rf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Nf(e,t,n,r,s){let i=Rf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new An(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await oa(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new An(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel($r(r)).catch(()=>{}),d}o=new Uint8Array(c);let f=0;for(let d of u)o.set(d,f),f+=d.byteLength}else{let l=await oa(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new An(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function la(e,t){if(e.length>t||W(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Df="/usr/bin:/bin",If=[["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"]],Vs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Zs({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new bt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH",Df],["IFS",`
802
802
  `],...If,["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=aa(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Lr(this.state.options)),this.state.env.set("BASHOPTS",Tr(this.state.shoptOptions)),Oa(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof bt||n instanceof fn))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of ga(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of wa())this.registerBundledCommand(o);if(t.python)for(let o of Ea())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of ba())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if($a(o)){let a=ka(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash