@taco-ai/cli 0.1.1 → 0.1.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.
Files changed (3) hide show
  1. package/dist/taco.mjs +19 -17
  2. package/lib/start.ts +65 -26
  3. package/package.json +2 -2
package/dist/taco.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{spawn as $n}from"node:child_process";import{existsSync as We,readFileSync as Mr}from"node:fs";import{createRequire as Un}from"node:module";import{dirname as zn,join as Ei}from"node:path";var pe=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"],Fn="@taco-ai/sidecar-";function Nr(){let e=Bn();return{key:e,pkg:`${Fn}${e}`}}function Bn(){let e=process.platform,t=process.arch,i=`${e}-${t}`;if(pe.includes(i))return i;throw new Error(`unsupported platform ${e}/${t} (known: ${pe.join(", ")})`)}function Rt(){let e=[process.env.TACO_SIDECAR_NODE,process.env.TACO_SIDECAR_BUNDLE,process.env.TACO_SIDECAR_RESOURCES];if(e.every(i=>i!==void 0)){let[i,r,s]=e;if(We(i)&&We(r))return{pkgDir:s,nodeBin:i,bundle:r,resources:s,daemonMode:Cr(r)}}let t=Un(import.meta.url);for(let i of pe)try{let r=t.resolve(`@taco-ai/sidecar-${i}/package.json`),s=zn(r),n=Ei(s,"manifest.json");if(!We(n))continue;let o=JSON.parse(Mr(n,"utf8")),a=Ei(s,"bin",o.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!We(a))continue;let h=Ei(s,"lib","index.mjs");if(!We(h))continue;let l=o.daemonMode===!0?!0:Cr(h);return{pkgDir:s,nodeBin:a,bundle:h,resources:s,daemonMode:l}}catch{}return null}function Cr(e){try{return Mr(e,"utf8").includes("TACO_DAEMON_MODE")}catch{return!1}}function H(e,t,i={}){return new Promise((r,s)=>{let n=$n(e,t,{stdio:["ignore","pipe","pipe"]}),o=[],a=[];n.stdout.on("data",h=>o.push(h)),n.stderr.on("data",h=>a.push(h)),n.once("error",h=>s(h)),n.once("close",h=>{let l=Buffer.concat(o).toString("utf8"),c=Buffer.concat(a).toString("utf8"),m={code:h??-1,stdout:l,stderr:c};h===0||i.allowFailure===!0?r(m):s(new Error(`${e} ${t.join(" ")} exited ${h}: ${c.trim()}`))})})}import{writeFileSync as Fr}from"node:fs";import{connect as Hn}from"node:net";import{homedir as jn}from"node:os";import{join as Br}from"node:path";var $r="com.taco-ai.sidecar";function Si(){return Br(jn(),"Library","LaunchAgents",`${$r}.plist`)}function Wn(e){return Br(e,"bin","taco-sidecar-daemon")}function kt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Ge(e){return`'${e.replace(/'/g,"'\\''")}'`}function Gn(e){return`#!/bin/sh
1
+ import{spawn as $n}from"node:child_process";import{existsSync as We,readFileSync as Mr}from"node:fs";import{createRequire as Un}from"node:module";import{dirname as zn,join as Ei}from"node:path";var pe=["darwin-arm64","darwin-x64","linux-x64","linux-arm64","win32-x64","win32-arm64"],Fn="@taco-ai/sidecar-";function Nr(){let e=Bn();return{key:e,pkg:`${Fn}${e}`}}function Bn(){let e=process.platform,t=process.arch,i=`${e}-${t}`;if(pe.includes(i))return i;throw new Error(`unsupported platform ${e}/${t} (known: ${pe.join(", ")})`)}function Rt(){let e=[process.env.TACO_SIDECAR_NODE,process.env.TACO_SIDECAR_BUNDLE,process.env.TACO_SIDECAR_RESOURCES];if(e.every(i=>i!==void 0)){let[i,r,s]=e;if(We(i)&&We(r))return{pkgDir:s,nodeBin:i,bundle:r,resources:s,daemonMode:Cr(r)}}let t=Un(import.meta.url);for(let i of pe)try{let r=t.resolve(`@taco-ai/sidecar-${i}/package.json`),s=zn(r),n=Ei(s,"manifest.json");if(!We(n))continue;let o=JSON.parse(Mr(n,"utf8")),a=Ei(s,"bin",o.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!We(a))continue;let h=Ei(s,"lib","index.mjs");if(!We(h))continue;let l=o.daemonMode===!0?!0:Cr(h);return{pkgDir:s,nodeBin:a,bundle:h,resources:s,daemonMode:l}}catch{}return null}function Cr(e){try{return Mr(e,"utf8").includes("TACO_DAEMON_MODE")}catch{return!1}}function H(e,t,i={}){return new Promise((r,s)=>{let n=$n(e,t,{stdio:["ignore","pipe","pipe"]}),o=[],a=[];n.stdout.on("data",h=>o.push(h)),n.stderr.on("data",h=>a.push(h)),n.once("error",h=>s(h)),n.once("close",h=>{let l=Buffer.concat(o).toString("utf8"),c=Buffer.concat(a).toString("utf8"),u={code:h??-1,stdout:l,stderr:c};h===0||i.allowFailure===!0?r(u):s(new Error(`${e} ${t.join(" ")} exited ${h}: ${c.trim()}`))})})}import{writeFileSync as Fr}from"node:fs";import{connect as Hn}from"node:net";import{homedir as jn}from"node:os";import{join as Br}from"node:path";var $r="com.taco-ai.sidecar";function Si(){return Br(jn(),"Library","LaunchAgents",`${$r}.plist`)}function Wn(e){return Br(e,"bin","taco-sidecar-daemon")}function kt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Ge(e){return`'${e.replace(/'/g,"'\\''")}'`}function Gn(e){return`#!/bin/sh
2
2
  # Generated by 'taco install' \u2014 do not edit.
3
3
  set -e
4
4
 
@@ -40,7 +40,7 @@ exec "$NODE_BIN" "$BUNDLE"
40
40
  </dict>
41
41
  </dict>
42
42
  </plist>
43
- `}function Kn(e,t){let i=Date.now()+t;return new Promise((r,s)=>{let n=()=>{let o=Hn(e),a=h=>{o.removeAllListeners(),o.destroy(),h?s(h):r()};o.once("connect",()=>a()),o.once("error",h=>{Date.now()>=i?a(new Error(`socket ${e} not ready in ${t}ms (${h.message})`)):setTimeout(n,100)})};n()})}async function Ur(e){let t=Wn(e.tacoHome),i=Si(),r=Gn({socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});Fr(t,r,{mode:493});let s=Zn({wrapperPath:t,tacoHome:e.tacoHome,logDir:e.logDir});Fr(i,s,{mode:420});try{await H("launchctl",["bootout",i],{allowFailure:!0})}catch{}await H("launchctl",["load","-w",i]);try{await Kn(e.socket,1e4)}catch(n){throw new Error(`launchctl load succeeded but daemon socket ${e.socket} did not appear: ${n}`)}return{serviceManager:"launchd",wrapperPath:t,plistPath:i}}import{writeFileSync as Yn}from"node:fs";import{join as Vn}from"node:path";var Ze="TacoSidecar";function Jn(e){return Vn(e,"bin","taco-sidecar-daemon.cmd")}function Le(e){return e.replace(/[&|<>^"%!]/g,"^$&")}function qn(e){let t=Le(e.tacoHome),i=Le(e.socketPath),r=Le(e.controlSocketPath),s=Le(e.nodeBin),n=Le(e.bundle),o=Le(e.resourcesRoot);return`@echo off
43
+ `}function Kn(e,t){let i=Date.now()+t;return new Promise((r,s)=>{let n=()=>{let o=Hn(e),a=h=>{o.removeAllListeners(),o.destroy(),h?s(h):r()};o.once("connect",()=>a()),o.once("error",h=>{Date.now()>=i?a(new Error(`socket ${e} not ready in ${t}ms (${h.message})`)):setTimeout(n,100)})};n()})}async function Ur(e){let t=Wn(e.tacoHome),i=Si(),r=Gn({socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});Fr(t,r,{mode:493});let s=Zn({wrapperPath:t,tacoHome:e.tacoHome,logDir:e.logDir});Fr(i,s,{mode:420});try{await H("launchctl",["bootout",i],{allowFailure:!0})}catch{}await H("launchctl",["load","-w",i]);try{await Kn(e.socket,1e4)}catch(n){throw new Error(`launchctl load succeeded but daemon socket ${e.socket} did not appear: ${n}`)}return{serviceManager:"launchd",wrapperPath:t,plistPath:i}}import{writeFileSync as Vn}from"node:fs";import{join as Yn}from"node:path";var Ze="TacoSidecar";function Jn(e){return Yn(e,"bin","taco-sidecar-daemon.cmd")}function Le(e){return e.replace(/[&|<>^"%!]/g,"^$&")}function qn(e){let t=Le(e.tacoHome),i=Le(e.socketPath),r=Le(e.controlSocketPath),s=Le(e.nodeBin),n=Le(e.bundle),o=Le(e.resourcesRoot);return`@echo off
44
44
  rem Generated by 'taco install' \u2014 do not edit.
45
45
  rem Invokes the bundled sidecar in daemon mode under schtasks.
46
46
  setlocal EnableExtensions EnableDelayedExpansion
@@ -63,26 +63,28 @@ set "BUNDLE=${n}"
63
63
 
64
64
  "!NODE_BIN!" "!BUNDLE!"
65
65
  endlocal
66
- `}async function zr(e){let t=Jn(e.tacoHome),i=qn({tacoHome:e.tacoHome,socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});return Yn(t,i,{mode:493}),await H("schtasks",["/Create","/SC","ONSTART","/TN",Ze,"/TR",`"${t}"`,"/RL","HIGHEST","/F"]),await H("schtasks",["/Run","/TN",Ze],{allowFailure:!0}),{serviceManager:"schtasks",wrapperPath:t,taskName:Ze}}import{mkdir as Ke}from"node:fs/promises";import{homedir as Xn}from"node:os";import{join as D}from"node:path";function Qn(){let e=process.env.TACO_HOME?.trim();return e&&e.length>0?e:D(Xn(),".taco")}var T=Qn();function vi(e=T){return D(e,"run")}function _t(e=T,t=process.env.TACO_RUNTIME_DIR){let i=t?.trim();return i&&i.length>0?i:vi(e)}var Hr=_t(),Tl=D(T,"bin");function Ot(e=Hr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar":D(e,"sidecar.sock")}function ie(e=Hr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar-ctl":D(e,"sidecar-ctl.sock")}var Ri=D(T,"upgrade-marker.json"),xl=D(T,"logs"),Pl=D(T,"staging"),Ll=D(T,"jobs");async function Tt(e=T,t=_t(e)){await Ke(t,{recursive:!0,mode:493}),await Ke(D(e,"bin"),{recursive:!0,mode:493}),await Ke(D(e,"logs"),{recursive:!0,mode:493}),await Ke(D(e,"staging"),{recursive:!0,mode:493}),await Ke(D(e,"jobs"),{recursive:!0,mode:493})}async function jr(e={}){let t=e.tacoHome??T,i=vi(t);await Tt(t,i);let r=Rt();if(!r)throw new Error("no @taco-ai/sidecar-<platform> bundle installed. Run `pnpm install` on a supported platform to install the optional dep, then retry `taco install`.");if(!r.daemonMode)throw new Error(`stale sidecar bundle at ${r.bundle}: missing daemon-mode support. Rebuild the runtime (\`pnpm --filter @taco-ai/sidecar package:runtime\`) and re-run \`taco install\`.`);let s={tacoHome:t,pkg:r,socket:Ot(i),control:ie(i)};if(process.platform==="darwin")return Ur({...s,logDir:`${t}/logs`});if(process.platform==="win32")return zr({...s});throw new Error(`unsupported platform: ${process.platform}`)}import{existsSync as _o,readFileSync as Oo,unlinkSync as To}from"node:fs";import{createRequire as xo}from"node:module";import{connect as os}from"node:net";import*as At from"node:path";import{join as It}from"node:path";import{fileURLToPath as Po}from"node:url";import{createHash as eo}from"node:crypto";function ki(e,t){let i=eo("sha256");return i.update(e),i.update("\0"),i.update(t),i.digest("hex").slice(0,16)}function Wr(e){let t=e.trim();if(t.length===0)return null;if(t.startsWith("{"))try{let r=JSON.parse(t);if(r.version!==1)return null;let s=typeof r.pid=="number"?r.pid:Number.NaN,n=typeof r.install_id=="string"?r.install_id:null,o=typeof r.started_at=="string"?r.started_at:null;return!Number.isFinite(s)||s<=0?null:{pid:s,installId:n,startedAt:o,version:1}}catch{return null}let i=Number.parseInt(t,10);return!Number.isFinite(i)||i<=0?null:{pid:i,installId:null,startedAt:null,version:null}}import{spawn as to}from"node:child_process";import{existsSync as Ye,readFileSync as io}from"node:fs";import{createRequire as ro}from"node:module";import{dirname as _i,join as fe}from"node:path";import{fileURLToPath as so}from"node:url";function no(){let e=_i(so(import.meta.url));for(let t=0;t<8;t++){if(Ye(fe(e,"pnpm-workspace.yaml")))return e;let i=_i(e);if(i===e)break;e=i}return null}function oo(e){let t=fe(e,"node_modules",".bin",process.platform==="win32"?"tsx.cmd":"tsx");return{program:Ye(t)?t:"tsx",args:[fe(e,"packages","sidecar","src","index.ts")],cwd:e}}function ao(){let e=ro(import.meta.url);for(let t of pe)try{let i=e.resolve(`@taco-ai/sidecar-${t}/package.json`),r=_i(i),s=fe(r,"manifest.json");if(!Ye(s))continue;let n=JSON.parse(io(s,"utf8")),o=fe(r,"bin",n.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ye(o))continue;let a=fe(r,"lib","index.mjs");if(!Ye(a))continue;return{nodeBin:o,bundle:a,resources:r}}catch{}return null}function Gr(e){let t=no(),i=e.forceDev===!0||t!==null&&process.env.TACO_SIDECAR_DEV!=="0",r,s;if(i&&t)r=oo(t),s=fe(t,"packages","sidecar","src");else{let a=ao();if(!a)throw new Error(`no @taco-ai/sidecar-<platform> bundle installed. Run \`pnpm install\` on a supported platform (${pe.join(", ")}) or set TACO_SIDECAR_DEV=1.`);r={program:a.nodeBin,args:[a.bundle]},s=a.resources}let n={...process.env,...e.extraEnv??{},TACO_DAEMON_MODE:"1",TACO_SOCKET:e.socketPath,TACO_CONTROL_SOCKET:e.controlSocketPath,TACO_HOME:e.tacoHome,TACO_RUNTIME_DIR:e.runtimeDir,TACO_SIDECAR_RESOURCES:s};return{child:to(r.program,r.args,{cwd:r.cwd,env:n,detached:!0,stdio:["ignore","ignore","inherit"],...process.platform==="win32"?{windowsHide:!0}:{}}),dev:i}}import{mkdir as ho,readFile as lo,unlink as Zr,writeFile as Kr}from"node:fs/promises";import{join as co}from"node:path";var uo=15e3;async function Oi(e){try{let t=await lo(e,"utf8"),i=JSON.parse(t);return typeof i=="object"&&i!==null&&typeof i.pid=="number"&&typeof i.acquiredAt=="number"?i:null}catch{return null}}async function Yr(e,t=Date.now){let i=co(e,"start.lock");await ho(e,{recursive:!0});let r={pid:process.pid,acquiredAt:t()},s=JSON.stringify(r),n=!1;try{await Kr(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(o){if(o.code==="EEXIST"){let a=await Oi(i);if(a===null||t()-a.acquiredAt>uo){try{await Zr(i)}catch{}try{await Kr(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(l){if(l.code==="EEXIST")return null;throw l}}else return null}else throw o}return n?{path:i,async release(){try{await Zr(i)}catch(o){if(o.code!=="ENOENT")throw o}}}:null}import{copyFile as Eo,mkdir as So,rename as vo,rm as Pt,stat as Qr}from"node:fs/promises";import{join as Lt}from"node:path";function Ti(e,t,i){let r=new Date().toISOString();process.stderr.write(`${r} [${e}] [${t}] ${i}
67
- `)}function De(e){return{info(t){Ti("info",e,t)},warn(t){Ti("warn",e,t)},error(t){Ti("error",e,t)}}}import{mkdir as mo,readFile as po,rename as fo,unlink as go,writeFile as yo}from"node:fs/promises";import{dirname as wo,resolve as Vr}from"node:path";var Jr=De("taco.cli.upgrade.marker"),bo=2;function qr(e,t){if(!t)return!1;let i=Vr(e.live_dir),r=Vr(t);return process.platform==="win32"?i.toLowerCase()===r.toLowerCase():i===r}async function xt(e){let t;try{t=await po(e,"utf8")}catch(i){return i.code==="ENOENT"||Jr.warn(`failed to read marker ${e}: ${String(i)}`),null}try{return JSON.parse(t)}catch(i){return Jr.warn(`malformed marker ${e}: ${String(i)}`),null}}async function Xr(e,t){await mo(wo(e),{recursive:!0});let i=`${e}.tmp`;await yo(i,JSON.stringify(t,null,bo),"utf8"),await fo(i,e)}async function xi(e){await go(e).catch(t=>{if(t.code!=="ENOENT")throw t})}var ge=De("taco.cli.upgrade.apply");async function Dt(e={}){let t=e.tacoHome??T,i=Ri.startsWith(t)?Ri:Lt(t,"upgrade-marker.json"),r=await xt(i);if(!r)throw new Error("no upgrade pending; marker absent at "+i);if(ge.info(`applying upgrade \u2192 version=${r.version}, live=${r.live_dir}`),!await Ro(r.staging_dir))throw ge.warn(`staging dir missing (${r.staging_dir}); clearing unusable marker`),await xi(i),new Error(`staging dir missing: ${r.staging_dir}`);await ko(r.staging_dir);let s=`${r.live_dir}.prev`;await Pt(s,{recursive:!0,force:!0});let n=e.rename??vo;try{await n(r.live_dir,s)}catch(o){throw new Error(`failed to move live_dir \u2192 prev: ${String(o)}`)}try{try{await n(r.staging_dir,r.live_dir)}catch(o){if(o.code!=="EXDEV")throw o;ge.warn("cross-device rename; falling back to copyFile + unlink"),await es(r.staging_dir,r.live_dir),await Pt(r.staging_dir,{recursive:!0,force:!0})}}catch(o){ge.error(`swap failed, rolling back: ${String(o)}`);try{await Pt(r.live_dir,{recursive:!0,force:!0}),await n(s,r.live_dir)}catch(a){ge.error(`rollback also failed: ${String(a)}`)}throw o}if(await xi(i),e.stop)try{await e.stop()}catch(o){ge.warn(`best-effort stop failed (ignored): ${String(o)}`)}return await Pt(s,{recursive:!0,force:!0}).catch(()=>{}),ge.info(`upgrade applied \u2192 version=${r.version}`),{version:r.version}}async function Ro(e){try{return(await Qr(e)).isDirectory()}catch{return!1}}async function ko(e){try{await Qr(Lt(e,"manifest.json"))}catch{throw new Error(`staging dir missing manifest.json: ${e}`)}}async function es(e,t){await So(t,{recursive:!0});for await(let i of await import("node:fs/promises").then(r=>r.readdir(e,{withFileTypes:!0}))){let r=Lt(e,i.name),s=Lt(t,i.name);i.isDirectory()?await es(r,s):i.isFile()&&await Eo(r,s)}}var Lo=15e3,Do=50,Ao=2e4,Io=3e3;function ts(e,t=5e3){return new Promise(i=>{let r=os(e),s="",n=setTimeout(()=>o("wedged"),t);function o(a){clearTimeout(n),r.destroy(),i(a)}r.on("data",a=>{s+=a.toString("utf8");let h=s.indexOf(`
68
- `);if(h!==-1)try{let l=JSON.parse(s.slice(0,h));o(l.method==="sidecar.hello"?"ready":"wedged")}catch{o("wedged")}}),r.once("error",()=>o("absent"))})}function is(e){try{return process.kill(e,0),!0}catch(t){return t?.code==="EPERM"}}async function rs(e,t,i,r){let s=It(e,"sidecar.pid"),n=null;try{n=Wr(Oo(s,"utf8"))}catch{n=null}let o=n!==null&&(n.installId===null||n.installId===r);if(n!==null&&o){let a=n.pid;try{process.kill(a,"SIGTERM")}catch{}let h=Date.now()+Io;for(;Date.now()<h&&is(a);)await new Promise(l=>setTimeout(l,100));if(is(a))try{process.kill(a,"SIGKILL")}catch{}}for(let a of[t,i,s])try{To(a)}catch{}}async function ss(e,t){let i=Date.now()+t,r;for(;Date.now()<i;)try{await new Promise((s,n)=>{let o=os(e);o.once("connect",()=>{o.destroy(),s()}),o.once("error",n)});return}catch(s){r=s,await new Promise(n=>setTimeout(n,Do))}throw new Error(`socket ${e} did not become ready in ${t}ms (${String(r)})`)}function ns(){let e=(()=>{try{let i=new URL(import.meta.url),r=At.dirname(Po(i));for(let s=0;s<8;s++){if(_o(It(r,"pnpm-workspace.yaml")))return r;let n=At.dirname(r);if(n===r)break;r=n}return null}catch{return null}})();if(e!==null&&process.env.TACO_SIDECAR_DEV!=="0"&&e)return It(e,"packages","sidecar","src");try{let i=xo(import.meta.url);for(let r of["@taco-ai/sidecar-darwin-arm64","@taco-ai/sidecar-darwin-x64","@taco-ai/sidecar-linux-arm64","@taco-ai/sidecar-linux-x64","@taco-ai/sidecar-win32-arm64","@taco-ai/sidecar-win32-x64"])try{let s=i.resolve(`${r}/package.json`);return At.dirname(s)}catch{}}catch{}}async function No(e){let t=await xt(It(e,"upgrade-marker.json"));if(t&&qr(t,Rt()?.resources))try{let{version:i}=await Dt({tacoHome:e});process.stderr.write(`[taco] applied pending upgrade \u2192 ${i}
66
+ `}async function zr(e){let t=Jn(e.tacoHome),i=qn({tacoHome:e.tacoHome,socketPath:e.socket,controlSocketPath:e.control,nodeBin:e.pkg.nodeBin,bundle:e.pkg.bundle,resourcesRoot:e.pkg.resources});return Vn(t,i,{mode:493}),await H("schtasks",["/Create","/SC","ONSTART","/TN",Ze,"/TR",`"${t}"`,"/RL","HIGHEST","/F"]),await H("schtasks",["/Run","/TN",Ze],{allowFailure:!0}),{serviceManager:"schtasks",wrapperPath:t,taskName:Ze}}import{mkdir as Ke}from"node:fs/promises";import{homedir as Xn}from"node:os";import{join as D}from"node:path";function Qn(){let e=process.env.TACO_HOME?.trim();return e&&e.length>0?e:D(Xn(),".taco")}var T=Qn();function vi(e=T){return D(e,"run")}function _t(e=T,t=process.env.TACO_RUNTIME_DIR){let i=t?.trim();return i&&i.length>0?i:vi(e)}var Hr=_t(),xl=D(T,"bin");function Ot(e=Hr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar":D(e,"sidecar.sock")}function ie(e=Hr){return process.platform==="win32"?"\\\\.\\pipe\\taco-sidecar-ctl":D(e,"sidecar-ctl.sock")}var Ri=D(T,"upgrade-marker.json"),Pl=D(T,"logs"),Ll=D(T,"staging"),Dl=D(T,"jobs");async function Tt(e=T,t=_t(e)){await Ke(t,{recursive:!0,mode:493}),await Ke(D(e,"bin"),{recursive:!0,mode:493}),await Ke(D(e,"logs"),{recursive:!0,mode:493}),await Ke(D(e,"staging"),{recursive:!0,mode:493}),await Ke(D(e,"jobs"),{recursive:!0,mode:493})}async function jr(e={}){let t=e.tacoHome??T,i=vi(t);await Tt(t,i);let r=Rt();if(!r)throw new Error("no @taco-ai/sidecar-<platform> bundle installed. Run `pnpm install` on a supported platform to install the optional dep, then retry `taco install`.");if(!r.daemonMode)throw new Error(`stale sidecar bundle at ${r.bundle}: missing daemon-mode support. Rebuild the runtime (\`pnpm --filter @taco-ai/sidecar package:runtime\`) and re-run \`taco install\`.`);let s={tacoHome:t,pkg:r,socket:Ot(i),control:ie(i)};if(process.platform==="darwin")return Ur({...s,logDir:`${t}/logs`});if(process.platform==="win32")return zr({...s});throw new Error(`unsupported platform: ${process.platform}`)}import{existsSync as _o,readFileSync as Oo,unlinkSync as To}from"node:fs";import{createRequire as xo}from"node:module";import{connect as os}from"node:net";import*as At from"node:path";import{join as It}from"node:path";import{fileURLToPath as Po}from"node:url";import{createHash as eo}from"node:crypto";function ki(e,t){let i=eo("sha256");return i.update(e),i.update("\0"),i.update(t),i.digest("hex").slice(0,16)}function Wr(e){let t=e.trim();if(t.length===0)return null;if(t.startsWith("{"))try{let r=JSON.parse(t);if(r.version!==1)return null;let s=typeof r.pid=="number"?r.pid:Number.NaN,n=typeof r.install_id=="string"?r.install_id:null,o=typeof r.started_at=="string"?r.started_at:null;return!Number.isFinite(s)||s<=0?null:{pid:s,installId:n,startedAt:o,version:1}}catch{return null}let i=Number.parseInt(t,10);return!Number.isFinite(i)||i<=0?null:{pid:i,installId:null,startedAt:null,version:null}}import{spawn as to}from"node:child_process";import{existsSync as Ve,readFileSync as io}from"node:fs";import{createRequire as ro}from"node:module";import{dirname as _i,join as fe}from"node:path";import{fileURLToPath as so}from"node:url";function no(){let e=_i(so(import.meta.url));for(let t=0;t<8;t++){if(Ve(fe(e,"pnpm-workspace.yaml")))return e;let i=_i(e);if(i===e)break;e=i}return null}function oo(e){let t=fe(e,"node_modules",".bin",process.platform==="win32"?"tsx.cmd":"tsx");return{program:Ve(t)?t:"tsx",args:[fe(e,"packages","sidecar","src","index.ts")],cwd:e}}function ao(){let e=ro(import.meta.url);for(let t of pe)try{let i=e.resolve(`@taco-ai/sidecar-${t}/package.json`),r=_i(i),s=fe(r,"manifest.json");if(!Ve(s))continue;let n=JSON.parse(io(s,"utf8")),o=fe(r,"bin",n.target?.endsWith("-pc-windows-msvc")?"taco-sidecar-node.exe":"taco-sidecar-node");if(!Ve(o))continue;let a=fe(r,"lib","index.mjs");if(!Ve(a))continue;return{nodeBin:o,bundle:a,resources:r}}catch{}return null}function Gr(e){let t=no(),i=e.forceDev===!0||t!==null&&process.env.TACO_SIDECAR_DEV!=="0",r,s;if(i&&t)r=oo(t),s=fe(t,"packages","sidecar","src");else{let a=ao();if(!a)throw new Error(`no @taco-ai/sidecar-<platform> bundle installed. Run \`pnpm install\` on a supported platform (${pe.join(", ")}) or set TACO_SIDECAR_DEV=1.`);r={program:a.nodeBin,args:[a.bundle]},s=a.resources}let n={...process.env,...e.extraEnv??{},TACO_DAEMON_MODE:"1",TACO_SOCKET:e.socketPath,TACO_CONTROL_SOCKET:e.controlSocketPath,TACO_HOME:e.tacoHome,TACO_RUNTIME_DIR:e.runtimeDir,TACO_SIDECAR_RESOURCES:s};return{child:to(r.program,r.args,{cwd:r.cwd,env:n,detached:!0,stdio:["ignore","ignore","inherit"],...process.platform==="win32"?{windowsHide:!0}:{}}),dev:i}}import{mkdir as ho,readFile as lo,unlink as Zr,writeFile as Kr}from"node:fs/promises";import{join as co}from"node:path";var uo=15e3;async function Oi(e){try{let t=await lo(e,"utf8"),i=JSON.parse(t);return typeof i=="object"&&i!==null&&typeof i.pid=="number"&&typeof i.acquiredAt=="number"?i:null}catch{return null}}async function Vr(e,t=Date.now){let i=co(e,"start.lock");await ho(e,{recursive:!0});let r={pid:process.pid,acquiredAt:t()},s=JSON.stringify(r),n=!1;try{await Kr(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(o){if(o.code==="EEXIST"){let a=await Oi(i);if(a===null||t()-a.acquiredAt>uo){try{await Zr(i)}catch{}try{await Kr(i,s,{flag:"wx",encoding:"utf8"}),n=!0}catch(l){if(l.code==="EEXIST")return null;throw l}}else return null}else throw o}return n?{path:i,async release(){try{await Zr(i)}catch(o){if(o.code!=="ENOENT")throw o}}}:null}import{copyFile as Eo,mkdir as So,rename as vo,rm as Pt,stat as Qr}from"node:fs/promises";import{join as Lt}from"node:path";function Ti(e,t,i){let r=new Date().toISOString();process.stderr.write(`${r} [${e}] [${t}] ${i}
67
+ `)}function De(e){return{info(t){Ti("info",e,t)},warn(t){Ti("warn",e,t)},error(t){Ti("error",e,t)}}}import{mkdir as mo,readFile as po,rename as fo,unlink as go,writeFile as yo}from"node:fs/promises";import{dirname as wo,resolve as Yr}from"node:path";var Jr=De("taco.cli.upgrade.marker"),bo=2;function qr(e,t){if(!t)return!1;let i=Yr(e.live_dir),r=Yr(t);return process.platform==="win32"?i.toLowerCase()===r.toLowerCase():i===r}async function xt(e){let t;try{t=await po(e,"utf8")}catch(i){return i.code==="ENOENT"||Jr.warn(`failed to read marker ${e}: ${String(i)}`),null}try{return JSON.parse(t)}catch(i){return Jr.warn(`malformed marker ${e}: ${String(i)}`),null}}async function Xr(e,t){await mo(wo(e),{recursive:!0});let i=`${e}.tmp`;await yo(i,JSON.stringify(t,null,bo),"utf8"),await fo(i,e)}async function xi(e){await go(e).catch(t=>{if(t.code!=="ENOENT")throw t})}var ge=De("taco.cli.upgrade.apply");async function Dt(e={}){let t=e.tacoHome??T,i=Ri.startsWith(t)?Ri:Lt(t,"upgrade-marker.json"),r=await xt(i);if(!r)throw new Error("no upgrade pending; marker absent at "+i);if(ge.info(`applying upgrade \u2192 version=${r.version}, live=${r.live_dir}`),!await Ro(r.staging_dir))throw ge.warn(`staging dir missing (${r.staging_dir}); clearing unusable marker`),await xi(i),new Error(`staging dir missing: ${r.staging_dir}`);await ko(r.staging_dir);let s=`${r.live_dir}.prev`;await Pt(s,{recursive:!0,force:!0});let n=e.rename??vo;try{await n(r.live_dir,s)}catch(o){throw new Error(`failed to move live_dir \u2192 prev: ${String(o)}`)}try{try{await n(r.staging_dir,r.live_dir)}catch(o){if(o.code!=="EXDEV")throw o;ge.warn("cross-device rename; falling back to copyFile + unlink"),await es(r.staging_dir,r.live_dir),await Pt(r.staging_dir,{recursive:!0,force:!0})}}catch(o){ge.error(`swap failed, rolling back: ${String(o)}`);try{await Pt(r.live_dir,{recursive:!0,force:!0}),await n(s,r.live_dir)}catch(a){ge.error(`rollback also failed: ${String(a)}`)}throw o}if(await xi(i),e.stop)try{await e.stop()}catch(o){ge.warn(`best-effort stop failed (ignored): ${String(o)}`)}return await Pt(s,{recursive:!0,force:!0}).catch(()=>{}),ge.info(`upgrade applied \u2192 version=${r.version}`),{version:r.version}}async function Ro(e){try{return(await Qr(e)).isDirectory()}catch{return!1}}async function ko(e){try{await Qr(Lt(e,"manifest.json"))}catch{throw new Error(`staging dir missing manifest.json: ${e}`)}}async function es(e,t){await So(t,{recursive:!0});for await(let i of await import("node:fs/promises").then(r=>r.readdir(e,{withFileTypes:!0}))){let r=Lt(e,i.name),s=Lt(t,i.name);i.isDirectory()?await es(r,s):i.isFile()&&await Eo(r,s)}}var Lo=15e3,Do=50,Ao=2e4,Io=3e3,No={major:2,minor:0};function ts(e,t=5e3){return new Promise(i=>{let r=os(e),s="",n=!1,o=setTimeout(()=>a("wedged"),t);function a(h){n||(n=!0,clearTimeout(o),r.destroy(),i(h))}r.on("connect",()=>{let h={id:"probe",commandId:"probe",method:"initialize",params:{protocolVersion:No,clientCapabilities:{}}};r.write(`${JSON.stringify(h)}
68
+ `)}),r.on("data",h=>{s+=h.toString("utf8");let l=s.indexOf(`
69
+ `);for(;l!==-1;){let c=s.slice(0,l);s=s.slice(l+1);let u;try{u=JSON.parse(c)}catch{continue}if(!(typeof u.id!="string"||typeof u.ok!="boolean")){a("ready");return}}l=s.indexOf(`
70
+ `)}),r.once("error",()=>a("absent"))})}function is(e){try{return process.kill(e,0),!0}catch(t){return t?.code==="EPERM"}}async function rs(e,t,i,r){let s=It(e,"sidecar.pid"),n=null;try{n=Wr(Oo(s,"utf8"))}catch{n=null}let o=n!==null&&(n.installId===null||n.installId===r);if(n!==null&&o){let a=n.pid;try{process.kill(a,"SIGTERM")}catch{}let h=Date.now()+Io;for(;Date.now()<h&&is(a);)await new Promise(l=>setTimeout(l,100));if(is(a))try{process.kill(a,"SIGKILL")}catch{}}for(let a of[t,i,s])try{To(a)}catch{}}async function ss(e,t){let i=Date.now()+t,r;for(;Date.now()<i;)try{await new Promise((s,n)=>{let o=os(e);o.once("connect",()=>{o.destroy(),s()}),o.once("error",n)});return}catch(s){r=s,await new Promise(n=>setTimeout(n,Do))}throw new Error(`socket ${e} did not become ready in ${t}ms (${String(r)})`)}function ns(){let e=(()=>{try{let i=new URL(import.meta.url),r=At.dirname(Po(i));for(let s=0;s<8;s++){if(_o(It(r,"pnpm-workspace.yaml")))return r;let n=At.dirname(r);if(n===r)break;r=n}return null}catch{return null}})();if(e!==null&&process.env.TACO_SIDECAR_DEV!=="0"&&e)return It(e,"packages","sidecar","src");try{let i=xo(import.meta.url);for(let r of["@taco-ai/sidecar-darwin-arm64","@taco-ai/sidecar-darwin-x64","@taco-ai/sidecar-linux-arm64","@taco-ai/sidecar-linux-x64","@taco-ai/sidecar-win32-arm64","@taco-ai/sidecar-win32-x64"])try{let s=i.resolve(`${r}/package.json`);return At.dirname(s)}catch{}}catch{}}async function Co(e){let t=await xt(It(e,"upgrade-marker.json"));if(t&&qr(t,Rt()?.resources))try{let{version:i}=await Dt({tacoHome:e});process.stderr.write(`[taco] applied pending upgrade \u2192 ${i}
69
71
  `)}catch(i){process.stderr.write(`[taco] pending upgrade could not be applied (${String(i)}); starting existing version
70
72
  `)}}async function as(e={}){let t=e.tacoHome??T,i=_t(t,e.runtimeDir);await Tt(t,i);let r=Ot(i),s=ie(i),n=await ts(r);if(n==="wedged"&&(await new Promise(l=>setTimeout(l,500)),n=await ts(r)),n==="ready"){process.stdout.write(`${r}
71
73
  `),process.stderr.write(`[taco] sidecar daemon already running (socket=${r})
72
74
  `);return}if(n==="wedged"){process.stderr.write(`[taco] sidecar daemon accepts connections but does not serve; killing it
73
- `);let l=ns(),c=ki(l??"",t);await rs(i,r,s,c)}let o=ns(),a=ki(o??"",t);await rs(i,r,s,a);let h=await Yr(i);if(!h){let l=await Oi(`${i}/start.lock`);try{await ss(r,Ao)}catch(c){throw new Error(`another process (pid=${l?.pid??"unknown"}) holds the start lock but its daemon did not become ready: ${String(c)}`)}process.stdout.write(`${r}
75
+ `);let l=ns(),c=ki(l??"",t);await rs(i,r,s,c)}let o=ns(),a=ki(o??"",t);await rs(i,r,s,a);let h=await Vr(i);if(!h){let l=await Oi(`${i}/start.lock`);try{await ss(r,Ao)}catch(c){throw new Error(`another process (pid=${l?.pid??"unknown"}) holds the start lock but its daemon did not become ready: ${String(c)}`)}process.stdout.write(`${r}
74
76
  `),process.stderr.write(`[taco] sidecar daemon started by pid=${l?.pid??"unknown"}
75
- `);return}try{await No(t);let{child:l,dev:c}=Gr({socketPath:r,controlSocketPath:s,tacoHome:t,runtimeDir:i}),m=new Promise((d,O)=>{l.once("exit",(y,E)=>{O(new Error(`sidecar exited before binding socket (code=${y} sig=${E})`))})});try{await Promise.race([ss(r,Lo),m])}catch(d){throw l.killed||l.kill(),d}l.unref(),process.stdout.write(`${r}
77
+ `);return}try{await Co(t);let{child:l,dev:c}=Gr({socketPath:r,controlSocketPath:s,tacoHome:t,runtimeDir:i}),u=new Promise((d,O)=>{l.once("exit",(y,E)=>{O(new Error(`sidecar exited before binding socket (code=${y} sig=${E})`))})});try{await Promise.race([ss(r,Lo),u])}catch(d){throw l.killed||l.kill(),d}l.unref(),process.stdout.write(`${r}
76
78
  `),process.stderr.write(`[taco] sidecar daemon started (dev=${c}, socket=${r}, control=${s}, tacoHome=${t})
77
- `)}finally{await h.release()}}import{connect as Co}from"node:net";var hs=2e3;function Mo(e,t){return new Promise((i,r)=>{let s=Co(e),n="",o=!1,a=l=>{o||(o=!0,s.destroy(),l())},h=setTimeout(()=>{a(()=>r(new Error(`${t} timed out after ${hs}ms`)))},hs);s.once("error",l=>{clearTimeout(h),a(()=>r(new Error(`${t}: ${l.message}`)))}),s.once("connect",()=>{s.write(`${JSON.stringify({method:t,id:1})}
79
+ `)}finally{await h.release()}}import{connect as Mo}from"node:net";var hs=2e3;function Fo(e,t){return new Promise((i,r)=>{let s=Mo(e),n="",o=!1,a=l=>{o||(o=!0,s.destroy(),l())},h=setTimeout(()=>{a(()=>r(new Error(`${t} timed out after ${hs}ms`)))},hs);s.once("error",l=>{clearTimeout(h),a(()=>r(new Error(`${t}: ${l.message}`)))}),s.once("connect",()=>{s.write(`${JSON.stringify({method:t,id:1})}
78
80
  `)}),s.on("data",l=>{n+=l.toString("utf8");let c=n.indexOf(`
79
- `);if(c<0)return;let m=n.slice(0,c);clearTimeout(h);try{let d=JSON.parse(m);"error"in d?a(()=>r(new Error(`${d.error.code}: ${d.error.message}`))):a(()=>i(d.result))}catch(d){a(()=>r(new Error(`malformed reply: ${String(d)}`)))}}),s.on("close",()=>{clearTimeout(h),o||a(()=>r(new Error("socket closed before reply")))})})}async function ls(){let e=ie(),t=await Mo(e,"control.ping");process.stdout.write(`${JSON.stringify(t)}
80
- `)}import{connect as Fo}from"node:net";var cs=3e3,ds=3e3;function Bo(e,t){return new Promise((i,r)=>{let s=Fo(e),n="",o=!1,a=l=>{o||(o=!0,s.destroy(),l())},h=setTimeout(()=>{a(()=>r(new Error(`${t} timed out after ${cs}ms`)))},cs);s.once("error",l=>{clearTimeout(h),a(()=>r(new Error(`${t}: ${l.message}`)))}),s.once("connect",()=>{s.write(`${JSON.stringify({method:t,id:1})}
81
+ `);if(c<0)return;let u=n.slice(0,c);clearTimeout(h);try{let d=JSON.parse(u);"error"in d?a(()=>r(new Error(`${d.error.code}: ${d.error.message}`))):a(()=>i(d.result))}catch(d){a(()=>r(new Error(`malformed reply: ${String(d)}`)))}}),s.on("close",()=>{clearTimeout(h),o||a(()=>r(new Error("socket closed before reply")))})})}async function ls(){let e=ie(),t=await Fo(e,"control.ping");process.stdout.write(`${JSON.stringify(t)}
82
+ `)}import{connect as Bo}from"node:net";var cs=3e3,ds=3e3;function $o(e,t){return new Promise((i,r)=>{let s=Bo(e),n="",o=!1,a=l=>{o||(o=!0,s.destroy(),l())},h=setTimeout(()=>{a(()=>r(new Error(`${t} timed out after ${cs}ms`)))},cs);s.once("error",l=>{clearTimeout(h),a(()=>r(new Error(`${t}: ${l.message}`)))}),s.once("connect",()=>{s.write(`${JSON.stringify({method:t,id:1})}
81
83
  `)}),s.on("data",l=>{n+=l.toString("utf8");let c=n.indexOf(`
82
- `);if(c<0)return;let m=n.slice(0,c);clearTimeout(h);try{let d=JSON.parse(m);"error"in d?a(()=>r(new Error(`${t}: ${d.error.code} ${d.error.message}`))):a(()=>i(d.result))}catch(d){a(()=>r(new Error(`${t}: malformed reply: ${String(d)}`)))}}),s.on("close",()=>{clearTimeout(h),o||a(()=>r(new Error(`${t}: socket closed before reply`)))})})}async function $o(e){let t=Date.now();for(;Date.now()-t<ds;){if(process.platform==="win32")return;let i=!0;try{i=(await import("node:fs")).existsSync(e)}catch{i=!1}if(!i)return;await new Promise(r=>setTimeout(r,100))}throw new Error(`socket ${e} still present after ${ds}ms`)}async function us(){let e=ie(),t=await Bo(e,"control.shutdown");await $o(e),process.stdout.write(`${JSON.stringify(t??{ok:!0})}
83
- `)}import{existsSync as Uo,unlinkSync as zo}from"node:fs";async function ms(){let e=Si();if(Uo(e)){await H("launchctl",["unload",e],{allowFailure:!0});try{zo(e)}catch{}}return{serviceManager:"launchd"}}async function ps(){return await H("schtasks",["/Delete","/TN",Ze,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function fs(){return process.platform==="darwin"?ms():process.platform==="win32"?ps():{serviceManager:"none"}}import{createHash as Yh}from"node:crypto";import{createReadStream as Vh}from"node:fs";import{mkdir as Ir,open as Jh,rm as qh,stat as Xh}from"node:fs/promises";import{dirname as In,join as bi}from"node:path";import Wo from"events";import L from"fs";import{EventEmitter as Rr}from"node:events";import qs from"node:stream";import{StringDecoder as Go}from"node:string_decoder";import en from"node:path";import Ue from"node:fs";import{dirname as sa,parse as na}from"path";import{EventEmitter as ma}from"events";import sr from"assert";import{Buffer as Oe}from"buffer";import*as Es from"zlib";import pa from"zlib";import{posix as Ie}from"node:path";import{basename as Ha}from"node:path";import ai from"fs";import K from"fs";import xs from"path";import{win32 as th}from"node:path";import Cs from"path";import gn from"node:fs";import wh from"node:assert";import{randomBytes as yn}from"node:crypto";import p from"node:fs";import S from"node:path";import wn from"fs";import yi from"node:fs";import mt from"node:path";import N from"node:fs";import _h from"node:fs/promises";import ci from"node:path";import{join as Pn}from"node:path";import I from"node:fs";import An from"node:path";var Ho=Object.defineProperty,jo=(e,t)=>{for(var i in t)Ho(e,i,{get:t[i],enumerable:!0})},gs=typeof process=="object"&&process?process:{stdout:null,stderr:null},Zo=e=>!!e&&typeof e=="object"&&(e instanceof Pe||e instanceof qs||Ko(e)||Yo(e)),Ko=e=>!!e&&typeof e=="object"&&e instanceof Rr&&typeof e.pipe=="function"&&e.pipe!==qs.Writable.prototype.pipe,Yo=e=>!!e&&typeof e=="object"&&e instanceof Rr&&typeof e.write=="function"&&typeof e.end=="function",J=Symbol("EOF"),q=Symbol("maybeEmitEnd"),re=Symbol("emittedEnd"),Nt=Symbol("emittingEnd"),Ve=Symbol("emittedError"),Ct=Symbol("closed"),ys=Symbol("read"),Mt=Symbol("flush"),ws=Symbol("flushChunk"),F=Symbol("encoding"),Ae=Symbol("decoder"),v=Symbol("flowing"),Je=Symbol("paused"),Fe=Symbol("resume"),R=Symbol("buffer"),P=Symbol("pipes"),k=Symbol("bufferLength"),Pi=Symbol("bufferPush"),Ft=Symbol("bufferShift"),x=Symbol("objectMode"),b=Symbol("destroyed"),Li=Symbol("error"),Di=Symbol("emitData"),bs=Symbol("emitEnd"),Ai=Symbol("emitEnd2"),j=Symbol("async"),Ii=Symbol("abort"),Bt=Symbol("aborted"),qe=Symbol("signal"),ye=Symbol("dataListeners"),A=Symbol("discarded"),Xe=e=>Promise.resolve().then(e),Vo=e=>e(),Jo=e=>e==="end"||e==="finish"||e==="prefinish",qo=e=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,Xo=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),Xs=class{src;dest;opts;ondrain;constructor(e,t,i){this.src=e,this.dest=t,this.opts=i,this.ondrain=()=>e[Fe](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Qo=class extends Xs{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,i){super(e,t,i),this.proxyErrors=r=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},ea=e=>!!e.objectMode,ta=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",Pe=class extends Rr{[v]=!1;[Je]=!1;[P]=[];[R]=[];[x];[F];[j];[Ae];[J]=!1;[re]=!1;[Nt]=!1;[Ct]=!1;[Ve]=null;[k]=0;[b]=!1;[qe];[Bt]=!1;[ye]=0;[A]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");ea(t)?(this[x]=!0,this[F]=null):ta(t)?(this[F]=t.encoding,this[x]=!1):(this[x]=!1,this[F]=null),this[j]=!!t.async,this[Ae]=this[F]?new Go(this[F]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[R]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[P]});let{signal:i}=t;i&&(this[qe]=i,i.aborted?this[Ii]():i.addEventListener("abort",()=>this[Ii]()))}get bufferLength(){return this[k]}get encoding(){return this[F]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[x]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[j]}set async(e){this[j]=this[j]||!!e}[Ii](){this[Bt]=!0,this.emit("abort",this[qe]?.reason),this.destroy(this[qe]?.reason)}get aborted(){return this[Bt]}set aborted(e){}write(e,t,i){if(this[Bt])return!1;if(this[J])throw new Error("write after end");if(this[b])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(i=t,t="utf8"),t||(t="utf8");let r=this[j]?Xe:Vo;if(!this[x]&&!Buffer.isBuffer(e)){if(Xo(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(qo(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[x]?(this[v]&&this[k]!==0&&this[Mt](!0),this[v]?this.emit("data",e):this[Pi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[v]):e.length?(typeof e=="string"&&!(t===this[F]&&!this[Ae]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[F]&&(e=this[Ae].write(e)),this[v]&&this[k]!==0&&this[Mt](!0),this[v]?this.emit("data",e):this[Pi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[v]):(this[k]!==0&&this.emit("readable"),i&&r(i),this[v])}read(e){if(this[b])return null;if(this[A]=!1,this[k]===0||e===0||e&&e>this[k])return this[q](),null;this[x]&&(e=null),this[R].length>1&&!this[x]&&(this[R]=[this[F]?this[R].join(""):Buffer.concat(this[R],this[k])]);let t=this[ys](e||null,this[R][0]);return this[q](),t}[ys](e,t){if(this[x])this[Ft]();else{let i=t;e===i.length||e===null?this[Ft]():typeof i=="string"?(this[R][0]=i.slice(e),t=i.slice(0,e),this[k]-=e):(this[R][0]=i.subarray(e),t=i.subarray(0,e),this[k]-=e)}return this.emit("data",t),!this[R].length&&!this[J]&&this.emit("drain"),t}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t="utf8"),e!==void 0&&this.write(e,t),i&&this.once("end",i),this[J]=!0,this.writable=!1,(this[v]||!this[Je])&&this[q](),this}[Fe](){this[b]||(!this[ye]&&!this[P].length&&(this[A]=!0),this[Je]=!1,this[v]=!0,this.emit("resume"),this[R].length?this[Mt]():this[J]?this[q]():this.emit("drain"))}resume(){return this[Fe]()}pause(){this[v]=!1,this[Je]=!0,this[A]=!1}get destroyed(){return this[b]}get flowing(){return this[v]}get paused(){return this[Je]}[Pi](e){this[x]?this[k]+=1:this[k]+=e.length,this[R].push(e)}[Ft](){return this[x]?this[k]-=1:this[k]-=this[R][0].length,this[R].shift()}[Mt](e=!1){do;while(this[ws](this[Ft]())&&this[R].length);!e&&!this[R].length&&!this[J]&&this.emit("drain")}[ws](e){return this.emit("data",e),this[v]}pipe(e,t){if(this[b])return e;this[A]=!1;let i=this[re];return t=t||{},e===gs.stdout||e===gs.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[P].push(t.proxyErrors?new Qo(this,e,t):new Xs(this,e,t)),this[j]?Xe(()=>this[Fe]()):this[Fe]()),e}unpipe(e){let t=this[P].find(i=>i.dest===e);t&&(this[P].length===1?(this[v]&&this[ye]===0&&(this[v]=!1),this[P]=[]):this[P].splice(this[P].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[A]=!1,this[ye]++,!this[P].length&&!this[v]&&this[Fe]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(Jo(e)&&this[re])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[Ve]){let r=t;this[j]?Xe(()=>r.call(this,this[Ve])):r.call(this,this[Ve])}return i}removeListener(e,t){return this.off(e,t)}off(e,t){let i=super.off(e,t);return e==="data"&&(this[ye]=this.listeners("data").length,this[ye]===0&&!this[A]&&!this[P].length&&(this[v]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[ye]=0,!this[A]&&!this[P].length&&(this[v]=!1)),t}get emittedEnd(){return this[re]}[q](){!this[Nt]&&!this[re]&&!this[b]&&this[R].length===0&&this[J]&&(this[Nt]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Ct]&&this.emit("close"),this[Nt]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==b&&this[b])return!1;if(e==="data")return!this[x]&&!i?!1:this[j]?(Xe(()=>this[Di](i)),!0):this[Di](i);if(e==="end")return this[bs]();if(e==="close"){if(this[Ct]=!0,!this[re]&&!this[b])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[Ve]=i,super.emit(Li,i);let s=!this[qe]||this.listeners("error").length?super.emit("error",i):!1;return this[q](),s}else if(e==="resume"){let s=super.emit("resume");return this[q](),s}else if(e==="finish"||e==="prefinish"){let s=super.emit(e);return this.removeAllListeners(e),s}let r=super.emit(e,...t);return this[q](),r}[Di](e){for(let i of this[P])i.dest.write(e)===!1&&this.pause();let t=this[A]?!1:super.emit("data",e);return this[q](),t}[bs](){return this[re]?!1:(this[re]=!0,this.readable=!1,this[j]?(Xe(()=>this[Ai]()),!0):this[Ai]())}[Ai](){if(this[Ae]){let t=this[Ae].end();if(t){for(let i of this[P])i.dest.write(t);this[A]||super.emit("data",t)}}for(let t of this[P])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[x]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[x]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[x])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[F]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(b,()=>t(new Error("stream destroyed"))),this.on("error",i=>t(i)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[A]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let i=this.read();if(i!==null)return Promise.resolve({done:!1,value:i});if(this[J])return t();let r,s,n=l=>{this.off("data",o),this.off("end",a),this.off(b,h),t(),s(l)},o=l=>{this.off("error",n),this.off("end",a),this.off(b,h),this.pause(),r({value:l,done:!!this[J]})},a=()=>{this.off("error",n),this.off("data",o),this.off(b,h),t(),r({done:!0,value:void 0})},h=()=>n(new Error("stream destroyed"));return new Promise((l,c)=>{s=c,r=l,this.once(b,h),this.once("error",n),this.once("end",a),this.once("data",o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[A]=!1;let e=!1,t=()=>(this.pause(),this.off(Li,t),this.off(b,t),this.off("end",t),e=!0,{done:!0,value:void 0}),i=()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}};return this.once("end",t),this.once(Li,t),this.once(b,t),{next:i,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[b])return e?this.emit("error",e):this.emit(b),this;this[b]=!0,this[A]=!0,this[R].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[Ct]&&t.close(),e?this.emit("error",e):this.emit(b),this}static get isStream(){return Zo}},ia=L.writev,ue=Symbol("_autoClose"),z=Symbol("_close"),Qe=Symbol("_ended"),f=Symbol("_fd"),Ni=Symbol("_finished"),te=Symbol("_flags"),Ci=Symbol("_flush"),ir=Symbol("_handleChunk"),rr=Symbol("_makeBuf"),dt=Symbol("_mode"),$t=Symbol("_needDrain"),He=Symbol("_onerror"),je=Symbol("_onopen"),Mi=Symbol("_onread"),Be=Symbol("_onwrite"),me=Symbol("_open"),U=Symbol("_path"),ae=Symbol("_pos"),W=Symbol("_queue"),$e=Symbol("_read"),Fi=Symbol("_readSize"),ee=Symbol("_reading"),et=Symbol("_remain"),Bi=Symbol("_size"),Vt=Symbol("_write"),we=Symbol("_writing"),Jt=Symbol("_defaultFlag"),_e=Symbol("_errored"),kr=class extends Pe{[_e]=!1;[f];[U];[Fi];[ee]=!1;[Bi];[et];[ue];constructor(e,t){if(t=t||{},super(t),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[_e]=!1,this[f]=typeof t.fd=="number"?t.fd:void 0,this[U]=e,this[Fi]=t.readSize||16*1024*1024,this[ee]=!1,this[Bi]=typeof t.size=="number"?t.size:1/0,this[et]=this[Bi],this[ue]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[f]=="number"?this[$e]():this[me]()}get fd(){return this[f]}get path(){return this[U]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[me](){L.open(this[U],"r",(e,t)=>this[je](e,t))}[je](e,t){e?this[He](e):(this[f]=t,this.emit("open",t),this[$e]())}[rr](){return Buffer.allocUnsafe(Math.min(this[Fi],this[et]))}[$e](){if(!this[ee]){this[ee]=!0;let e=this[rr]();if(e.length===0)return process.nextTick(()=>this[Mi](null,0,e));L.read(this[f],e,0,e.length,null,(t,i,r)=>this[Mi](t,i,r))}}[Mi](e,t,i){this[ee]=!1,e?this[He](e):this[ir](t,i)&&this[$e]()}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[He](e){this[ee]=!0,this[z](),this.emit("error",e)}[ir](e,t){let i=!1;return this[et]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[et]<=0)&&(i=!1,this[z](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[f]=="number"&&this[$e](),!1;case"error":return this[_e]?!1:(this[_e]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},ra=class extends kr{[me](){let e=!0;try{this[je](null,L.openSync(this[U],"r")),e=!1}finally{e&&this[z]()}}[$e](){let e=!0;try{if(!this[ee]){this[ee]=!0;do{let t=this[rr](),i=t.length===0?0:L.readSync(this[f],t,0,t.length,null);if(!this[ir](i,t))break}while(!0);this[ee]=!1}e=!1}finally{e&&this[z]()}}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}},di=class extends Wo{readable=!1;writable=!0;[_e]=!1;[we]=!1;[Qe]=!1;[W]=[];[$t]=!1;[U];[dt];[ue];[f];[Jt];[te];[Ni]=!1;[ae];constructor(e,t){t=t||{},super(t),this[U]=e,this[f]=typeof t.fd=="number"?t.fd:void 0,this[dt]=t.mode===void 0?438:t.mode,this[ae]=typeof t.start=="number"?t.start:void 0,this[ue]=typeof t.autoClose=="boolean"?t.autoClose:!0;let i=this[ae]!==void 0?"r+":"w";this[Jt]=t.flags===void 0,this[te]=t.flags===void 0?i:t.flags,this[f]===void 0&&this[me]()}emit(e,...t){if(e==="error"){if(this[_e])return!1;this[_e]=!0}return super.emit(e,...t)}get fd(){return this[f]}get path(){return this[U]}[He](e){this[z](),this[we]=!0,this.emit("error",e)}[me](){L.open(this[U],this[te],this[dt],(e,t)=>this[je](e,t))}[je](e,t){this[Jt]&&this[te]==="r+"&&e&&e.code==="ENOENT"?(this[te]="w",this[me]()):e?this[He](e):(this[f]=t,this.emit("open",t),this[we]||this[Ci]())}end(e,t){return e&&this.write(e,t),this[Qe]=!0,!this[we]&&!this[W].length&&typeof this[f]=="number"&&this[Be](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[Qe]?(this.emit("error",new Error("write() after end()")),!1):this[f]===void 0||this[we]||this[W].length?(this[W].push(e),this[$t]=!0,!1):(this[we]=!0,this[Vt](e),!0)}[Vt](e){L.write(this[f],e,0,e.length,this[ae],(t,i)=>this[Be](t,i))}[Be](e,t){e?this[He](e):(this[ae]!==void 0&&typeof t=="number"&&(this[ae]+=t),this[W].length?this[Ci]():(this[we]=!1,this[Qe]&&!this[Ni]?(this[Ni]=!0,this[z](),this.emit("finish")):this[$t]&&(this[$t]=!1,this.emit("drain"))))}[Ci](){if(this[W].length===0)this[Qe]&&this[Be](null,0);else if(this[W].length===1)this[Vt](this[W].pop());else{let e=this[W];this[W]=[],ia(this[f],e,this[ae],(t,i)=>this[Be](t,i))}}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},Qs=class extends di{[me](){let e;if(this[Jt]&&this[te]==="r+")try{e=L.openSync(this[U],this[te],this[dt])}catch(t){if(t?.code==="ENOENT")return this[te]="w",this[me]();throw t}else e=L.openSync(this[U],this[te],this[dt]);this[je](null,e)}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}[Vt](e){let t=!0;try{this[Be](null,L.writeSync(this[f],e,0,e.length,this[ae])),t=!1}finally{if(t)try{this[z]()}catch{}}}},oa=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),aa=e=>!!e.sync&&!!e.file,ha=e=>!e.sync&&!!e.file,la=e=>!!e.sync&&!e.file,ca=e=>!e.sync&&!e.file,da=e=>!!e.file,ua=e=>oa.get(e)||e,_r=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=ua(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Et=(e,t,i,r,s)=>Object.assign((n=[],o,a)=>{Array.isArray(n)&&(o=n,n={}),typeof o=="function"&&(a=o,o=void 0),o=o?Array.from(o):[];let h=_r(n);if(s?.(h,o),aa(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(ha(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(la(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(ca(h)){if(typeof a=="function")throw new TypeError("callback only supported with file option");return r(h,o)}throw new Error("impossible options??")},{syncFile:e,asyncFile:t,syncNoFile:i,asyncNoFile:r,validate:s}),fa=pa.constants||{ZLIB_VERNUM:4736},V=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},fa)),ga=Oe.concat,Ss=Object.getOwnPropertyDescriptor(Oe,"concat"),ya=e=>e,$i=Ss?.writable===!0||Ss?.set!==void 0?e=>{Oe.concat=e?ya:ga}:e=>{},Te=Symbol("_superWrite"),Ut=class extends Error{code;errno;constructor(e,t){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return"ZlibError"}},Ui=Symbol("flushFlag"),Or=class extends Pe{#e=!1;#i=!1;#r;#n;#s;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(e,t){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#r=e.flush??0,this.#n=e.finishFlush??0,this.#s=e.fullFlushFlag??0,typeof Es[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Es[t](e)}catch(i){throw new Ut(i,this.constructor)}this.#o=i=>{this.#e||(this.#e=!0,this.close(),this.emit("error",i))},this.#t?.on("error",i=>this.#o(new Ut(i))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return sr(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#s),this.write(Object.assign(Oe.alloc(0),{[Ui]:e})))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#n),this.#i=!0,super.end(i)}get ended(){return this.#i}[Te](e){return super.write(e)}write(e,t,i){if(typeof t=="function"&&(i=t,t="utf8"),typeof e=="string"&&(e=Oe.from(e,t)),this.#e)return;sr(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},$i(!0);let o;try{let h=typeof e[Ui]=="number"?e[Ui]:this.#r;o=this.#t._processChunk(e,h),$i(!1)}catch(h){$i(!1),this.#o(new Ut(h,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=s,this.#t.close=n,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Ut(h,this.write)));let a;if(o)if(Array.isArray(o)&&o.length>0){let h=o[0];a=this[Te](Oe.from(h));for(let l=1;l<o.length;l++)a=this[Te](o[l])}else a=this[Te](Oe.from(o));return i&&i(),a}},tn=class extends Or{#e;#i;constructor(e,t){e=e||{},e.flush=e.flush||V.Z_NO_FLUSH,e.finishFlush=e.finishFlush||V.Z_FINISH,e.fullFlushFlag=V.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#i=e.strategy}params(e,t){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#i!==t){this.flush(V.Z_SYNC_FLUSH),sr(this.handle,"zlib binding closed");let i=this.handle.flush;this.handle.flush=(r,s)=>{typeof r=="function"&&(s=r,r=this.flushFlag),this.flush(r),s?.()};try{this.handle.params(e,t)}finally{this.handle.flush=i}this.handle&&(this.#e=e,this.#i=t)}}}},wa=class extends tn{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[Te](e){return this.#e?(this.#e=!1,e[9]=255,super[Te](e)):super[Te](e)}},ba=class extends tn{constructor(e){super(e,"Unzip")}},rn=class extends Or{constructor(e,t){e=e||{},e.flush=e.flush||V.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||V.BROTLI_OPERATION_FINISH,e.fullFlushFlag=V.BROTLI_OPERATION_FLUSH,super(e,t)}},Ea=class extends rn{constructor(e){super(e,"BrotliCompress")}},Sa=class extends rn{constructor(e){super(e,"BrotliDecompress")}},sn=class extends Or{constructor(e,t){e=e||{},e.flush=e.flush||V.ZSTD_e_continue,e.finishFlush=e.finishFlush||V.ZSTD_e_end,e.fullFlushFlag=V.ZSTD_e_flush,super(e,t)}},va=class extends sn{constructor(e){super(e,"ZstdCompress")}},Ra=class extends sn{constructor(e){super(e,"ZstdDecompress")}},ka=(e,t)=>{if(Number.isSafeInteger(e))e<0?Oa(e,t):_a(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},_a=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},Oa=(e,t)=>{t[0]=255;var i=!1;e=e*-1;for(var r=t.length;r>1;r--){var s=e&255;e=Math.floor(e/256),i?t[r-1]=nn(s):s===0?t[r-1]=0:(i=!0,t[r-1]=on(s))}},Ta=e=>{let t=e[0],i=t===128?Pa(e.subarray(1,e.length)):t===255?xa(e):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},xa=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=nn(n):n===0?o=n:(r=!0,o=on(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},Pa=e=>{for(var t=e.length,i=0,r=t-1;r>-1;r--){var s=Number(e[r]);s!==0&&(i+=s*Math.pow(256,t-r-1))}return i},nn=e=>(255^e)&255,on=e=>(255^e)+1&255,La={};jo(La,{code:()=>Tr,isCode:()=>qt,isName:()=>Da,name:()=>ui,normalFsTypes:()=>an});var qt=e=>ui.has(e),Da=e=>Tr.has(e),an=new Set(["0","","1","2","3","4","5","6","7","D"]),ui=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Tr=new Map(Array.from(ui).map(e=>[e[1],e[0]])),Aa=e=>e===void 0||e<0?void 0:e,xe=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,i,r){Buffer.isBuffer(e)?this.decode(e,t||0,i,r):e&&this.#i(e)}decode(e,t,i,r){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=be(e,t+156,1),n=an.has(s),o=n?i:void 0,a=n?r:void 0;if(this.path=o?.path??be(e,t,100),this.mode=o?.mode??a?.mode??he(e,t+100,8),this.uid=o?.uid??a?.uid??he(e,t+108,8),this.gid=o?.gid??a?.gid??he(e,t+116,8),this.size=Aa(o?.size??a?.size??he(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??zi(e,t+136,12),this.cksum=he(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),qt(s)&&(this.#e=s||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=be(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=o?.uname??a?.uname??be(e,t+265,32),this.gname=o?.gname??a?.gname??be(e,t+297,32),this.devmaj=o?.devmaj??a?.devmaj??he(e,t+329,8)??0,this.devmin=o?.devmin??a?.devmin??he(e,t+337,8)??0,e[t+475]!==0){let l=be(e,t+345,155);this.path=l+"/"+this.path}else{let l=be(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=i?.atime??r?.atime??zi(e,t+476,12),this.ctime=i?.ctime??r?.ctime??zi(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#i(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="size"&&Number(r)<0||i==="path"&&t||i==="linkpath"&&t||i==="global"))))}encode(e,t=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let i=this.ctime||this.atime?130:155,r=Ia(this.path||"",i),s=r[0],n=r[1];this.needPax=!!r[2],this.needPax=Ee(e,t,100,s)||this.needPax,this.needPax=le(e,t+100,8,this.mode)||this.needPax,this.needPax=le(e,t+108,8,this.uid)||this.needPax,this.needPax=le(e,t+116,8,this.gid)||this.needPax,this.needPax=le(e,t+124,12,this.size)||this.needPax,this.needPax=Hi(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Ee(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=Ee(e,t+265,32,this.uname)||this.needPax,this.needPax=Ee(e,t+297,32,this.gname)||this.needPax,this.needPax=le(e,t+329,8,this.devmaj)||this.needPax,this.needPax=le(e,t+337,8,this.devmin)||this.needPax,this.needPax=Ee(e,t+345,i,n)||this.needPax,e[t+475]!==0?this.needPax=Ee(e,t+345,155,n)||this.needPax:(this.needPax=Ee(e,t+345,130,n)||this.needPax,this.needPax=Hi(e,t+476,12,this.atime)||this.needPax,this.needPax=Hi(e,t+488,12,this.ctime)||this.needPax);let o=256;for(let a=t;a<t+148;a++)o+=e[a];for(let a=t+156;a<t+512;a++)o+=e[a];return this.cksum=o,le(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:ui.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Tr.get(e));if(qt(t)||t==="Unsupported")this.#e=t;else if(qt(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Ia=(e,t)=>{let i=e,r="",s,n=Ie.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Ie.dirname(i),i=Ie.basename(i);do Buffer.byteLength(i)<=100&&Buffer.byteLength(r)<=t?s=[i,r,!1]:Buffer.byteLength(i)>100&&Buffer.byteLength(r)<=t?s=[i.slice(0,99),r,!0]:(i=Ie.join(Ie.basename(r),i),r=Ie.dirname(r));while(r!==n&&s===void 0);s||(s=[e.slice(0,99),"",!0])}return s},be=(e,t,i)=>e.subarray(t,t+i).toString("utf8").replace(/\0.*/,""),zi=(e,t,i)=>Na(he(e,t,i)),Na=e=>e===void 0?void 0:new Date(e*1e3),he=(e,t,i)=>Number(e[t])&128?Ta(e.subarray(t,t+i)):Ma(e,t,i),Ca=e=>isNaN(e)?void 0:e,Ma=(e,t,i)=>Ca(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),Fa={12:8589934591,8:2097151},le=(e,t,i,r)=>r===void 0?!1:r>Fa[i]||r<0?(ka(r,e.subarray(t,t+i)),!0):(Ba(e,t,i,r),!1),Ba=(e,t,i,r)=>e.write($a(r,i),t,i,"ascii"),$a=(e,t)=>Ua(Math.floor(e).toString(8),t),Ua=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",Hi=(e,t,i,r)=>r===void 0?!1:le(e,t,i,r.getTime()/1e3),za=new Array(156).join("\0"),Ee=(e,t,i,r)=>r===void 0?!1:(e.write(r+za,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),oi=class hn{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,i=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=i,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){let t=this.encodeBody();if(t==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(t),r=512*Math.ceil(1+i/512),s=Buffer.allocUnsafe(r);for(let n=0;n<512;n++)s[n]=0;new xe({path:("PaxHeader/"+Ha(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(s),s.write(t,512,i,"utf8");for(let n=i+512;n<s.length;n++)s[n]=0;return s}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(t){if(this[t]===void 0)return"";let i=this[t],r=i instanceof Date?i.getTime()/1e3:i,s=" "+(t==="dev"||t==="ino"||t==="nlink"?"SCHILY.":"")+t+"="+r+`
84
- `,n=Buffer.byteLength(s),o=Math.floor(Math.log(n)/Math.log(10))+1;return n+o>=Math.pow(10,o)&&(o+=1),o+n+s}static parse(t,i,r=!1){return new hn(ja(Wa(t),i),r)}},ja=(e,t)=>t?Object.assign({},t,e):e,Wa=e=>e.replace(/\n$/,"").split(`
85
- `).reduce(Ga,Object.create(null)),Ga=(e,t)=>{let i=parseInt(t,10);if(i!==Buffer.byteLength(t)+1)return e;t=t.slice((i+" ").length);let r=t.split("="),s=r.shift();if(!s)return e;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),o=r.join("=").replace(/\0.*/,"");switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":e[n]=o;break;case"ctime":case"atime":case"mtime":e[n]=new Date(Number(o)*1e3);break;case"size":let a=+o;a>=0&&(e[n]=a);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":e[n]=+o;break}return e},Za=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,u=Za!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),Ka=class extends Pe{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(e,t,i){switch(super({}),this.pause(),this.extended=t,this.globalExtended=i,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.path=u(e.path),this.mode=e.mode,this.mode&&(this.mode=this.mode&4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?u(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),i&&this.#e(i,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw new Error("writing more to entry than is appropriate");let i=this.remain,r=this.blockRemain;return this.remain=Math.max(0,i-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:i>=t?super.write(e):super.write(e.subarray(0,i))}#e(e,t=!1){e.path&&(e.path=u(e.path)),e.linkpath&&(e.linkpath=u(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},mi=(e,t,i,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=i instanceof Error&&i.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(i instanceof Error&&(r=Object.assign(i,r),i=i.message),e.emit("warn",t,i,r)):i instanceof Error?e.emit("error",Object.assign(i,r)):e.emit("error",Object.assign(new Error(`${t}: ${i}`),r))},Ya=1024*1024,nr=Buffer.from([31,139]),or=Buffer.from([40,181,47,253]),Va=Math.max(nr.length,or.length),C=Symbol("state"),Se=Symbol("writeEntry"),X=Symbol("readEntry"),ji=Symbol("nextEntry"),vs=Symbol("processEntry"),G=Symbol("extendedHeader"),tt=Symbol("globalExtendedHeader"),se=Symbol("meta"),Rs=Symbol("emitMeta"),g=Symbol("buffer"),Q=Symbol("queue"),ne=Symbol("ended"),Wi=Symbol("emittedEnd"),ve=Symbol("emit"),w=Symbol("unzip"),zt=Symbol("consumeChunk"),Ht=Symbol("consumeChunkSub"),Gi=Symbol("consumeBody"),ks=Symbol("consumeMeta"),_s=Symbol("consumeHeader"),it=Symbol("consuming"),Zi=Symbol("bufferConcat"),jt=Symbol("maybeEnd"),Ne=Symbol("writing"),Z=Symbol("aborted"),Wt=Symbol("onDone"),Re=Symbol("sawValidEntry"),Gt=Symbol("sawNullBlock"),Zt=Symbol("sawEOF"),Os=Symbol("closeStream"),Ja=1e3,rt=Symbol("compressedBytesRead"),Ki=Symbol("decompressedBytesRead"),Ts=Symbol("checkDecompressionRatio"),qa=()=>!0,bt=class extends ma{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[Q]=[];[g];[X];[Se];[C]="begin";[se]="";[G];[tt];[ne]=!1;[w];[Z]=!1;[Re];[Gt]=!1;[Zt]=!1;[Ne]=!1;[it]=!1;[Wi]=!1;[rt]=0;[Ki]=0;constructor(e={}){super(),this.file=e.file||"",this.on(Wt,()=>{(this[C]==="begin"||this[Re]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(Wt,e.ondone):this.on(Wt,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:Ja,this.maxMetaEntrySize=e.maxMetaEntrySize||Ya,this.filter=typeof e.filter=="function"?e.filter:qa;let t=e.file&&(e.file.endsWith(".tar.br")||e.file.endsWith(".tbr"));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:t?void 0:!1;let i=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:i?!0:void 0,this.on("end",()=>this[Os]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){mi(this,e,t,i)}[_s](e,t){this[Re]===void 0&&(this[Re]=!1);let i;try{i=new xe(e,t,this[G],this[tt])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[Gt]?(this[Zt]=!0,this[C]==="begin"&&(this[C]="header"),this[ve]("eof")):(this[Gt]=!0,this[ve]("nullBlock"));else if(this[Gt]=!1,!i.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:i});else if(!i.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:i});else{let r=i.type;if(/^(Symbolic)?Link$/.test(r)&&!i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:i});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:i});else{let s=this[Se]=new Ka(i,this[G],this[tt]);if(!this[Re])if(s.remain){let n=()=>{s.invalid||(this[Re]=!0)};s.on("end",n)}else this[Re]=!0;s.meta?s.size>this.maxMetaEntrySize?(s.ignore=!0,this[ve]("ignoredEntry",s),this[C]="ignore",s.resume()):s.size>0&&(this[se]="",s.on("data",n=>this[se]+=n),this[C]="meta"):(this[G]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[ve]("ignoredEntry",s),this[C]=s.remain?"ignore":"header",s.resume()):(s.remain?this[C]="body":(this[C]="header",s.end()),this[X]?this[Q].push(s):(this[Q].push(s),this[ji]())))}}}[Os](){queueMicrotask(()=>this.emit("close"))}[vs](e){let t=!0;if(!e)this[X]=void 0,t=!1;else if(Array.isArray(e)){let[i,...r]=e;this.emit(i,...r)}else this[X]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[ji]()),t=!1);return t}[ji](){do;while(this[vs](this[Q].shift()));if(this[Q].length===0){let e=this[X];!e||e.flowing||e.size===e.remain?this[Ne]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Gi](e,t){let i=this[Se];if(!i)throw new Error("attempt to consume body without entry??");let r=i.blockRemain??0,s=r>=e.length&&t===0?e:e.subarray(t,t+r);return i.write(s),i.blockRemain||(this[C]="header",this[Se]=void 0,i.end()),s.length}[ks](e,t){let i=this[Se],r=this[Gi](e,t);return!this[Se]&&i&&this[Rs](i),r}[ve](e,t,i){this[Q].length===0&&!this[X]?this.emit(e,t,i):this[Q].push([e,t,i])}[Rs](e){switch(this[ve]("meta",this[se]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[G]=oi.parse(this[se],this[G],!1);break;case"GlobalExtendedHeader":this[tt]=oi.parse(this[se],this[tt],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[G]??Object.create(null);this[G]=t,t.path=this[se].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[G]||Object.create(null);this[G]=t,t.linkpath=this[se].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){if(!this[Z]){if(this[w]){let t=this[w];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[Z]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[Ts](e){this[Ki]+=e.length;let t=this[Ki]/this[rt];return t>this.maxDecompressionRatio?(this.abort(new Error(`max decompression ratio exceeded: ${t.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this[Z])return i?.(),!1;if((this[w]===void 0||this.brotli===void 0&&this[w]===!1)&&e){if(this[g]&&(e=Buffer.concat([this[g],e]),this[g]=void 0),e.length<Va)return this[g]=e,i?.(),!0;for(let o=0;this[w]===void 0&&o<nr.length;o++)e[o]!==nr[o]&&(this[w]=!1);let s=!1;if(this[w]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<or.length;o++)if(e[o]!==or[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[w]===!1&&n)if(e.length<512)if(this[ne])this.brotli=!0;else return this[g]=e,i?.(),!0;else try{new xe(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[w]===void 0||this[w]===!1&&(this.brotli||s)){let o=this[ne];this[ne]=!1,this[w]=this[w]===void 0?new ba({}):s?new Ra({}):new Sa({}),this[w].on("data",h=>{this[Ts](h)&&this[zt](h)}),this[w].on("error",h=>{this[Z]||this.abort(h)}),this[w].on("end",()=>{this[ne]=!0,this[zt]()}),this[Ne]=!0,this[rt]+=e.length;let a=!!this[w][o?"end":"write"](e);return this[Ne]=!1,i?.(),a}}this[Ne]=!0,this[w]?(this[rt]+=e.length,this[w].write(e)):this[zt](e),this[Ne]=!1;let r=this[Q].length>0?!1:this[X]?this[X].flowing:!0;return!r&&this[Q].length===0&&this[X]?.once("drain",()=>this.emit("drain")),i?.(),r}[Zi](e){e&&!this[Z]&&(this[g]=this[g]?Buffer.concat([this[g],e]):e)}[jt](){if(this[ne]&&!this[Wi]&&!this[Z]&&!this[it]){this[Wi]=!0;let e=this[Se];if(e?.blockRemain){let t=this[g]?this[g].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[g]&&e.write(this[g]),e.end()}this[ve](Wt)}}[zt](e){if(this[it]&&e)this[Zi](e);else if(!e&&!this[g])this[jt]();else if(e){if(this[it]=!0,this[g]){this[Zi](e);let t=this[g];this[g]=void 0,this[Ht](t)}else this[Ht](e);for(;this[g]&&this[g]?.length>=512&&!this[Z]&&!this[Zt];){let t=this[g];this[g]=void 0,this[Ht](t)}this[it]=!1}(!this[g]||this[ne])&&this[jt]()}[Ht](e){let t=0,i=e.length;for(;t+512<=i&&!this[Z]&&!this[Zt];)switch(this[C]){case"begin":case"header":this[_s](e,t),t+=512;break;case"ignore":case"body":t+=this[Gi](e,t);break;case"meta":t+=this[ks](e,t);break;default:throw new Error("invalid state: "+this[C])}t<i&&(this[g]=this[g]?Buffer.concat([e.subarray(t),this[g]]):e.subarray(t))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t)),i&&this.once("finish",i),this[Z]||(this[w]?(e&&(this[rt]+=e.length,this[w].write(e)),this[w].end()):(this[ne]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[jt]())),this}},ut=e=>{let t=e.length-1,i=-1;for(;t>-1&&e.charAt(t)==="/";)i=t,t--;return i===-1?e:e.slice(0,i)},Xa=e=>{let t=e.onReadEntry;e.onReadEntry=t?i=>{t(i),i.resume()}:i=>i.resume()},ln=(e,t)=>{let i=new Map(t.map(o=>[ut(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||na(o).root||".",c;if(o===l)c=!1;else{let m=i.get(o);c=m!==void 0?m:n(sa(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(ut(o)):o=>n(ut(o))},Qa=e=>{let t=new bt(e),i=e.file,r;try{r=Ue.openSync(i,"r");let s=Ue.fstatSync(r),n=e.maxReadSize||16*1024*1024;if(s.size<n){let o=Buffer.allocUnsafe(s.size),a=Ue.readSync(r,o,0,s.size,0);t.end(a===o.byteLength?o:o.subarray(0,a))}else{let o=0,a=Buffer.allocUnsafe(n);for(;o<s.size;){let h=Ue.readSync(r,a,0,n,o);if(h===0)break;o+=h,t.write(a.subarray(0,h))}t.end()}}finally{if(typeof r=="number")try{Ue.closeSync(r)}catch{}}},eh=(e,t)=>{let i=new bt(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("end",n),Ue.stat(s,(a,h)=>{if(a)o(a);else{let l=new kr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},pi=Et(Qa,eh,e=>new bt(e),e=>new bt(e),(e,t)=>{t?.length&&ln(e,t),e.noResume||Xa(e)}),cn=(e,t,i)=>(e&=4095,i&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:ih,parse:Ps}=th,xr=e=>{let t="",i=Ps(e);for(;ih(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Ps(e)}return[t,e]},fi=["|","<",">","?",":"],Pr=fi.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),rh=new Map(fi.map((e,t)=>[e,Pr[t]])),sh=new Map(Pr.map((e,t)=>[e,fi[t]])),Ls=e=>fi.reduce((t,i)=>t.split(i).join(rh.get(i)),e),nh=e=>Pr.reduce((t,i)=>t.split(i).join(sh.get(i)),e),dn=(e,t)=>t?(e=u(e).replace(/^\.(\/|$)/,""),ut(t)+"/"+e):u(e),oh=16*1024*1024,Ds=Symbol("process"),As=Symbol("file"),Is=Symbol("directory"),ar=Symbol("symlink"),Ns=Symbol("hardlink"),st=Symbol("header"),Xt=Symbol("read"),hr=Symbol("lstat"),Qt=Symbol("onlstat"),lr=Symbol("onread"),cr=Symbol("onreadlink"),dr=Symbol("openfile"),ur=Symbol("onopenfile"),ce=Symbol("close"),hi=Symbol("mode"),mr=Symbol("awaitDrain"),Yi=Symbol("ondrain"),Y=Symbol("prefix"),un=class extends Pe{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(e,t={}){let i=_r(t);super(),this.path=u(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||oh,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=u(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?u(i.prefix):void 0,this.onWriteEntry=i.onWriteEntry,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let r=!1;if(!this.preservePaths){let[n,o]=xr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=nh(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=u(i.absolute||xs.resolve(this.cwd,e)),this.path===""&&(this.path="./"),r&&this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:this,path:r+this.path});let s=this.statCache.get(this.absolute);s?this[Qt](s):this[hr]()}warn(e,t,i={}){return mi(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[hr](){K.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[Qt](t)})}[Qt](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=lh(e),this.emit("stat",e),this[Ds]()}[Ds](){switch(this.type){case"File":return this[As]();case"Directory":return this[Is]();case"SymbolicLink":return this[ar]();default:return this.end()}}[hi](e){return cn(e,this.type==="Directory",this.portable)}[Y](e){return dn(e,this.prefix)}[st](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new xe({path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this[hi](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new oi({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let e=this.header?.block;if(!e)throw new Error("failed to encode header");super.write(e)}[Is](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[st](),this.end()}[ar](){K.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[cr](t)})}[cr](e){this.linkpath=u(e),this[st](),this.end()}[Ns](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=u(xs.relative(this.cwd,e)),this.stat.size=0,this[st](),this.end()}[As](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,t=this.linkCache.get(e);if(t?.indexOf(this.cwd)===0)return this[Ns](t);this.linkCache.set(e,this.absolute)}if(this[st](),this.stat.size===0)return this.end();this[dr]()}[dr](){K.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[ur](t)})}[ur](e){if(this.fd=e,this.#e)return this[ce]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let t=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(t),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Xt]()}[Xt](){let{fd:e,buf:t,offset:i,length:r,pos:s}=this;if(e===void 0||t===void 0)throw new Error("cannot read file without first opening");K.read(e,t,i,r,s,(n,o)=>{if(n)return this[ce](()=>this.emit("error",n));this[lr](o)})}[ce](e=()=>{}){this.fd!==void 0&&K.close(this.fd,e)}[lr](e){if(e<=0&&this.remain>0){let i=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ce](()=>this.emit("error",i))}if(e>this.remain){let i=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ce](()=>this.emit("error",i))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let i=e;i<this.length&&e<this.blockRemain;i++)this.buf[i+this.offset]=0,e++,this.remain++;let t=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(t)?this[Yi]():this[mr](()=>this[Yi]())}[mr](e){this.once("drain",e)}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this.blockRemain<e.length){let r=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",r)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,i)}[Yi](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[ce](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Xt]()}},ah=class extends un{sync=!0;[hr](){this[Qt](K.lstatSync(this.absolute))}[ar](){this[cr](K.readlinkSync(this.absolute))}[dr](){this[ur](K.openSync(this.absolute,"r"))}[Xt](){let e=!0;try{let{fd:t,buf:i,offset:r,length:s,pos:n}=this;if(t===void 0||i===void 0)throw new Error("fd and buf must be set in READ method");let o=K.readSync(t,i,r,s,n);this[lr](o),e=!1}finally{if(e)try{this[ce](()=>{})}catch{}}}[mr](e){e()}[ce](e=()=>{}){this.fd!==void 0&&K.closeSync(this.fd),e()}},hh=class extends Pe{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(e,t,i={}){return mi(this,e,t,i)}constructor(e,t={}){let i=_r(t);super(),this.preservePaths=!!i.preservePaths,this.portable=!!i.portable,this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.onWriteEntry=i.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw new Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=i.prefix,this.path=u(e.path),this.mode=e.mode!==void 0?this[hi](e.mode):void 0,this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:i.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath!==void 0?u(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=xr(this.path);o&&typeof a=="string"&&(this.path=a,s=o)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new xe({path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path}),this.header.encode()&&!this.noPax&&super.write(new oi({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Y](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Y](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let n=this.header?.block;if(!n)throw new Error("failed to encode header");super.write(n),e.pipe(this)}[Y](e){return dn(e,this.prefix)}[hi](e){return cn(e,this.type==="Directory",this.portable)}write(e,t,i){typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8"));let r=e.length;if(r>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,i)}end(e,t,i){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t??"utf8")),i&&this.once("finish",i),e?super.end(e,i):super.end(i),this}},lh=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",ch=class ze{tail;head;length=0;static create(t=[]){return new ze(t)}constructor(t=[]){for(let i of t)this.push(i)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");let i=t.next,r=t.prev;return i&&(i.prev=r),r&&(r.next=i),t===this.head&&(this.head=i),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,i}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let i=this.head;t.list=this,t.next=i,i&&(i.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);let i=this.tail;t.list=this,t.prev=i,i&&(i.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let i=0,r=t.length;i<r;i++)uh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)mh(this,t[i]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,t}forEach(t,i){i=i||this;for(let r=this.head,s=0;r;s++)t.call(i,r.value,s,this),r=r.next}forEachReverse(t,i){i=i||this;for(let r=this.tail,s=this.length-1;r;s--)t.call(i,r.value,s,this),r=r.prev}get(t){let i=0,r=this.head;for(;r&&i<t;i++)r=r.next;if(i===t&&r)return r.value}getReverse(t){let i=0,r=this.tail;for(;r&&i<t;i++)r=r.prev;if(i===t&&r)return r.value}map(t,i){i=i||this;let r=new ze;for(let s=this.head;s;)r.push(t.call(i,s.value,this)),s=s.next;return r}mapReverse(t,i){i=i||this;var r=new ze;for(let s=this.tail;s;)r.push(t.call(i,s.value,this)),s=s.prev;return r}reduce(t,i){let r,s=this.head;if(arguments.length>1)r=i;else if(this.head)s=this.head.next,r=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var n=0;s;n++)r=t(r,s.value,n),s=s.next;return r}reduceReverse(t,i){let r,s=this.tail;if(arguments.length>1)r=i;else if(this.tail)s=this.tail.prev,r=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let n=this.length-1;s;n--)r=t(r,s.value,n),s=s.prev;return r}toArray(){let t=new Array(this.length);for(let i=0,r=this.head;r;i++)t[i]=r.value,r=r.next;return t}toArrayReverse(){let t=new Array(this.length);for(let i=0,r=this.tail;r;i++)t[i]=r.value,r=r.prev;return t}slice(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new ze;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.head,n=0;for(n=0;s&&n<t;n++)s=s.next;for(;s&&n<i;n++,s=s.next)r.push(s.value);return r}sliceReverse(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new ze;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.length,n=this.tail;for(;n&&s>i;s--)n=n.prev;for(;n&&s>t;s--,n=n.prev)r.push(n.value);return r}splice(t,i=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let s=this.head;for(let o=0;s&&o<t;o++)s=s.next;let n=[];for(let o=0;s&&o<i;o++)n.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(let o of r)s=dh(this,s,o);return n}reverse(){let t=this.head,i=this.tail;for(let r=t;r;r=r.prev){let s=r.prev;r.prev=r.next,r.next=s}return this.head=i,this.tail=t,this}};function dh(e,t,i){let r=t,s=t?t.next:e.head,n=new Lr(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function uh(e,t){e.tail=new Lr(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function mh(e,t){e.head=new Lr(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Lr=class{list;next;prev;value;constructor(e,t,i,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,i?(i.prev=this,this.next=i):this.next=void 0}},Ms=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},Fs=Buffer.alloc(1024),ei=Symbol("onStat"),nt=Symbol("ended"),B=Symbol("queue"),ot=Symbol("pendingLinks"),oe=Symbol("current"),ke=Symbol("process"),at=Symbol("processing"),Kt=Symbol("processJob"),$=Symbol("jobs"),Vi=Symbol("jobDone"),ti=Symbol("addFSEntry"),Bs=Symbol("addTarEntry"),pr=Symbol("stat"),fr=Symbol("readdir"),ii=Symbol("onreaddir"),ri=Symbol("pipe"),$s=Symbol("entry"),Ji=Symbol("entryOpt"),si=Symbol("writeEntryClass"),mn=Symbol("write"),qi=Symbol("ondrain"),gi=class extends Pe{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[si];onWriteEntry;[B];[ot]=new Map;[$]=0;[at]=!1;[nt]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||"",this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=u(e.prefix||""),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[si]=un,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(e.gzip&&(typeof e.gzip!="object"&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new wa(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new Ea(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new va(e.zstd)),!this.zip)throw new Error("impossible");let t=this.zip;t.on("data",i=>super.write(i)),t.on("end",()=>super.end()),t.on("drain",()=>this[qi]()),this.on("resume",()=>t.resume())}else this.on("drain",this[qi]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter=="function"?e.filter:()=>!0,this[B]=new ch,this[$]=0,this.jobs=Number(e.jobs)||4,this[at]=!1,this[nt]=!1}[mn](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&this.add(e),this[nt]=!0,this[ke](),i&&i(),this}write(e){if(this[nt])throw new Error("write after end");return typeof e=="string"?this[ti](e):this[Bs](e),this.flowing}[Bs](e){let t=u(Cs.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new Ms(e.path,t);i.entry=new hh(e,this[Ji](i)),i.entry.on("end",()=>this[Vi](i)),this[$]+=1,this[B].push(i)}this[ke]()}[ti](e){let t=u(Cs.resolve(this.cwd,e));this[B].push(new Ms(e,t)),this[ke]()}[pr](e){e.pending=!0,this[$]+=1;let t=this.follow?"stat":"lstat";ai[t](e.absolute,(i,r)=>{e.pending=!1,this[$]-=1,i?this.emit("error",i):this[ei](e,r)})}[ei](e,t){if(this.statCache.set(e.absolute,t),e.stat=t,!this.filter(e.path,t))e.ignore=!0;else if(t.isFile()&&t.nlink>1&&!this.linkCache.get(`${t.dev}:${t.ino}`)&&!this.sync)if(e===this[oe])this[Kt](e);else{let i=`${t.dev}:${t.ino}`,r=this[ot].get(i);r?r.push(e):this[ot].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[ke]()}[fr](e){e.pending=!0,this[$]+=1,ai.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[$]-=1,t)return this.emit("error",t);this[ii](e,i)})}[ii](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[ke]()}[ke](){if(!this[at]){this[at]=!0;for(let e=this[B].head;e&&this[$]<this.jobs;e=e.next)if(this[Kt](e.value),e.value.ignore){let t=e.next;this[B].removeNode(e),e.next=t}this[at]=!1,this[nt]&&this[B].length===0&&this[$]===0&&(this.zip?this.zip.end(Fs):(super.write(Fs),super.end()))}}get[oe](){return this[B]&&this[B].head&&this[B].head.value}[Vi](e){this[B].shift(),this[$]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[ot].get(i);if(r){this[ot].delete(i);for(let s of r)s.pending=!1,this[Kt](s)}}this[ke]()}[Kt](e){if(e.pending&&e.pendingLink&&e===this[oe]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[oe]&&!e.piped&&this[ri](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[ei](e,t):this[pr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[ii](e,t):this[fr](e),!e.readdir)return}if(e.entry=this[$s](e),!e.entry){e.ignore=!0;return}e===this[oe]&&!e.piped&&this[ri](e)}}}[Ji](e){return{onwarn:(t,i,r)=>this.warn(t,i,r),noPax:this.noPax,cwd:this.cwd,absolute:e.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[$s](e){this[$]+=1;try{return new this[si](e.path,this[Ji](e)).on("end",()=>this[Vi](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[qi](){this[oe]&&this[oe].entry&&this[oe].entry.resume()}[ri](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ti](n+r)});let t=e.entry,i=this.zip;if(!t)throw new Error("cannot pipe without source");i?t.on("data",r=>{i.write(r)||t.pause()}):t.on("data",r=>{super.write(r)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,i={}){mi(this,e,t,i)}},Dr=class extends gi{sync=!0;constructor(e){super(e),this[si]=ah}pause(){}resume(){}[pr](e){let t=this.follow?"statSync":"lstatSync";this[ei](e,ai[t](e.absolute))}[fr](e){this[ii](e,ai.readdirSync(e.absolute))}[ri](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ti](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[mn](r)})}},ph=(e,t)=>{let i=new Dr(e),r=new Qs(e.file,{mode:e.mode||438});i.pipe(r),pn(i,t)},fh=(e,t)=>{let i=new gi(e),r=new di(e.file,{mode:e.mode||438});i.pipe(r);let s=new Promise((n,o)=>{r.on("error",o),r.on("close",n),i.on("error",o)});return fn(i,t).catch(n=>i.emit("error",n)),s},pn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?pi({file:en.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},fn=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await pi({file:en.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},gh=(e,t)=>{let i=new Dr(e);return pn(i,t),i},yh=(e,t)=>{let i=new gi(e);return fn(i,t).catch(r=>i.emit("error",r)),i},ed=Et(ph,fh,gh,yh,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),bh=process.env.__FAKE_PLATFORM__||process.platform,bn=bh==="win32",{O_CREAT:En,O_NOFOLLOW:Us,O_TRUNC:Sn,O_WRONLY:vn}=wn.constants,Rn=Number(process.env.__FAKE_FS_O_FILENAME__)||wn.constants.UV_FS_O_FILEMAP||0,Eh=bn&&!!Rn,Sh=512*1024,vh=Rn|Sn|En|vn,zs=!bn&&typeof Us=="number"?Us|Sn|En|vn:null,kn=zs!==null?()=>zs:Eh?e=>e<Sh?vh:"w":()=>"w",gr=(e,t,i)=>{try{return yi.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},li=(e,t,i,r)=>{yi.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},Rh=(e,t,i,r,s)=>{if(t.isDirectory())_n(mt.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=mt.resolve(e,t.name);li(o,i,r,s)});else{let n=mt.resolve(e,t.name);li(n,i,r,s)}},_n=(e,t,i,r)=>{yi.readdir(e,{withFileTypes:!0},(s,n)=>{if(s){if(s.code==="ENOENT")return r();if(s.code!=="ENOTDIR"&&s.code!=="ENOTSUP")return r(s)}if(s||!n.length)return li(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return li(e,t,i,r)}};for(let l of n)Rh(e,l,t,i,h)})},kh=(e,t,i,r)=>{t.isDirectory()&&On(mt.resolve(e,t.name),i,r),gr(mt.resolve(e,t.name),i,r)},On=(e,t,i)=>{let r;try{r=yi.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return gr(e,t,i);throw n}for(let s of r)kh(e,s,t,i);return gr(e,t,i)},Tn=class extends Error{path;code;syscall="chdir";constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return"CwdError"}},wi=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,t){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=t}get name(){return"SymlinkError"}},Oh=(e,t)=>{N.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new Tn(e,i?.code||"ENOTDIR")),t(i)})},Th=(e,t,i)=>{e=u(e);let r=t.umask??18,s=t.mode|448,n=(s&r)!==0,o=t.uid,a=t.gid,h=typeof o=="number"&&typeof a=="number"&&(o!==t.processUid||a!==t.processGid),l=t.preserve,c=t.unlink,m=u(t.cwd),d=(y,E)=>{y?i(y):E&&h?_n(E,o,a,vt=>d(vt)):n?N.chmod(e,s,i):i()};if(e===m)return Oh(e,d);if(l)return _h.mkdir(e,{mode:s,recursive:!0}).then(y=>d(null,y??void 0),d);let O=u(ci.relative(m,e)).split("/");yr(m,O,s,c,m,void 0,d)},yr=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=u(ci.resolve(e+"/"+a));N.mkdir(h,i,xn(h,t,i,r,s,n,o))},xn=(e,t,i,r,s,n,o)=>a=>{a?N.lstat(e,(h,l)=>{if(h)h.path=h.path&&u(h.path),o(h);else if(l.isDirectory())yr(e,t,i,r,s,n,o);else if(r)N.unlink(e,c=>{if(c)return o(c);N.mkdir(e,i,xn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new wi(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,yr(e,t,i,r,s,n,o))},xh=e=>{let t=!1,i;try{t=N.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new Tn(e,i??"ENOTDIR")}},Ph=(e,t)=>{e=u(e);let i=t.umask??18,r=t.mode|448,s=(r&i)!==0,n=t.uid,o=t.gid,a=typeof n=="number"&&typeof o=="number"&&(n!==t.processUid||o!==t.processGid),h=t.preserve,l=t.unlink,c=u(t.cwd),m=y=>{y&&a&&On(y,n,o),s&&N.chmodSync(e,r)};if(e===c)return xh(c),m();if(h)return m(N.mkdirSync(e,{mode:r,recursive:!0})??void 0);let d=u(ci.relative(c,e)).split("/"),O;for(let y=d.shift(),E=c;y&&(E+="/"+y);y=d.shift()){E=u(ci.resolve(E));try{N.mkdirSync(E,r),O=O||E}catch{let vt=N.lstatSync(E);if(vt.isDirectory())continue;if(l){N.unlinkSync(E),N.mkdirSync(E,r),O=O||E;continue}else if(vt.isSymbolicLink())return new wi(E,E+"/"+d.join("/"))}}return m(O)},Xi=Object.create(null),Hs=1e4,Ce=new Set,Lh=e=>{Ce.has(e)?Ce.delete(e):Xi[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Ce.add(e);let t=Xi[e],i=Ce.size-Hs;if(i>Hs/10){for(let r of Ce)if(Ce.delete(r),delete Xi[r],--i<=0)break}return t},Dh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ah=Dh==="win32",Ih=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Pn(r,i)),t.push(i||"/"),t},[]),Nh=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=Ah?["win32 parallelization disabled"]:e.map(r=>ut(Pn(Lh(r))));let i=new Set(e.map(r=>Ih(r)).reduce((r,s)=>r.concat(s)));this.#i.set(t,{dirs:i,paths:e});for(let r of e){let s=this.#e.get(r);s?s.push(t):this.#e.set(r,[t])}for(let r of i){let s=this.#e.get(r);if(!s)this.#e.set(r,[new Set([t])]);else{let n=s.at(-1);n instanceof Set?n.add(t):s.push(new Set([t]))}}return this.#s(t)}#n(e){let t=this.#i.get(e);if(!t)throw new Error("function does not have any path reservations");return{paths:t.paths.map(i=>this.#e.get(i)),dirs:[...t.dirs].map(i=>this.#e.get(i))}}check(e){let{paths:t,dirs:i}=this.#n(e);return t.every(r=>r&&r[0]===e)&&i.every(r=>r&&r[0]instanceof Set&&r[0].has(e))}#s(e){return this.#r.has(e)||!this.check(e)?!1:(this.#r.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#r.has(e))return!1;let t=this.#i.get(e);if(!t)throw new Error("invalid reservation");let{paths:i,dirs:r}=t,s=new Set;for(let n of i){let o=this.#e.get(n);if(!o||o?.[0]!==e)continue;let a=o[1];if(!a){this.#e.delete(n);continue}if(o.shift(),typeof a=="function")s.add(a);else for(let h of a)s.add(h)}for(let n of r){let o=this.#e.get(n),a=o?.[0];if(!(!o||!(a instanceof Set)))if(a.size===1&&o.length===1){this.#e.delete(n);continue}else if(a.size===1){o.shift();let h=o[0];typeof h=="function"&&s.add(h)}else a.delete(e)}return this.#r.delete(e),s.forEach(n=>this.#s(n)),!0}},Ch=()=>process.umask(),js=Symbol("onEntry"),wr=Symbol("checkFs"),Ws=Symbol("checkFs2"),br=Symbol("isReusable"),M=Symbol("makeFs"),Er=Symbol("file"),Sr=Symbol("directory"),ni=Symbol("link"),Gs=Symbol("symlink"),Zs=Symbol("hardlink"),ct=Symbol("ensureNoSymlink"),Ks=Symbol("unsupported"),Ys=Symbol("checkPath"),Qi=Symbol("stripAbsolutePath"),de=Symbol("mkdir"),_=Symbol("onError"),Yt=Symbol("pending"),Vs=Symbol("pend"),Me=Symbol("unpend"),er=Symbol("ended"),tr=Symbol("maybeClose"),vr=Symbol("skip"),pt=Symbol("doChown"),ft=Symbol("uid"),gt=Symbol("gid"),yt=Symbol("checkedCwd"),Mh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,wt=Mh==="win32",Fh=1024,Bh=(e,t)=>{if(!wt)return p.unlink(e,t);let i=e+".DELETE."+yn(16).toString("hex");p.rename(e,i,r=>{if(r)return t(r);p.unlink(i,t)})},$h=e=>{if(!wt)return p.unlinkSync(e);let t=e+".DELETE."+yn(16).toString("hex");p.renameSync(e,t),p.unlinkSync(t)},Js=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,Ar=class extends bt{[er]=!1;[yt]=!1;[Yt]=0;reservations=new Nh;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(e={}){if(e.ondone=()=>{this[er]=!0,this[tr]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid=="number"||typeof e.gid=="number"){if(typeof e.uid!="number"||typeof e.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=e.preserveOwner===void 0&&typeof e.uid!="number"?process.getuid?.()===0:!!e.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:Fh,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||wt,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=u(S.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:Ch():0,this.umask=typeof e.umask=="number"?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on("entry",t=>this[js](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[tr](){this[er]&&this[Yt]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Qi](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=xr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||wt&&/^[a-z]:\.\.$/i.test(o[0]??"")){if(t==="path"||r==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:i}),!1;let a=S.posix.dirname(e.path),h=S.posix.normalize(S.posix.join(a,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:i}),!1}return s&&(e[t]=String(n),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute ${t}`,{entry:e,[t]:i})),!0}[Ys](e){let t=u(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=u(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}i.splice(0,this.strip),e.path=i.join("/")}if(isFinite(this.maxDepth)&&i.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:i.length,maxDepth:this.maxDepth}),!1;if(!this[Qi](e,"path")||!this[Qi](e,"linkpath"))return!1;if(e.absolute=S.isAbsolute(e.path)?u(S.resolve(e.path)):u(S.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute=="string"&&e.absolute.indexOf(this.cwd+"/")!==0&&e.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:u(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!=="Directory"&&e.type!=="GNUDumpDir")return!1;if(this.win32){let{root:r}=S.win32.parse(String(e.absolute));e.absolute=r+Ls(String(e.absolute).slice(r.length));let{root:s}=S.win32.parse(e.path);e.path=s+Ls(e.path.slice(s.length))}return!0}[js](e){if(!this[Ys](e))return e.resume();switch(wh.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[wr](e);default:return this[Ks](e)}}[_](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[Me](),t.resume())}[de](e,t,i){Th(u(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:t},i)}[pt](e){return this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[ft](e){return Js(this.uid,e.uid,this.processUid)}[gt](e){return Js(this.gid,e.gid,this.processGid)}[Er](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new di(String(e.absolute),{flags:kn(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&p.close(r.fd,()=>{}),r.write=()=>!0,this[_](a,e),t()});let s=1,n=a=>{if(a){r.fd&&p.close(r.fd,()=>{}),this[_](a,e),t();return}--s===0&&r.fd!==void 0&&p.close(r.fd,h=>{h?this[_](h,e):this[Me](),t()})};r.on("finish",()=>{let a=String(e.absolute),h=r.fd;if(typeof h=="number"&&e.mtime&&!this.noMtime){s++;let l=e.atime||new Date,c=e.mtime;p.futimes(h,l,c,m=>m?p.utimes(a,l,c,d=>n(d&&m)):n())}if(typeof h=="number"&&this[pt](e)){s++;let l=this[ft](e),c=this[gt](e);typeof l=="number"&&typeof c=="number"&&p.fchown(h,l,c,m=>m?p.chown(a,l,c,d=>n(d&&m)):n())}n()});let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",a=>{this[_](a,e),t()}),e.pipe(o)),o.pipe(r)}[Sr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode;this[de](String(e.absolute),i,r=>{if(r){this[_](r,e),t();return}let s=1,n=()=>{--s===0&&(t(),this[Me](),e.resume())};e.mtime&&!this.noMtime&&(s++,p.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[pt](e)&&(s++,p.chown(String(e.absolute),Number(this[ft](e)),Number(this[gt](e)),n)),n()})}[Ks](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Gs](e,t){let i=u(S.relative(this.cwd,S.resolve(S.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[ct](e,this.cwd,i,()=>this[ni](e,String(e.linkpath),"symlink",t),r=>{this[_](r,e),t()})}[Zs](e,t){let i=u(S.resolve(this.cwd,String(e.linkpath))),r=u(String(e.linkpath)).split("/");this[ct](e,this.cwd,r,()=>this[ni](e,i,"link",t),s=>{this[_](s,e),t()})}[ct](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=S.resolve(t,n);p.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new wi(o,S.resolve(o,i.join("/"))));this[ct](e,o,i,r,s)})}[Vs](){this[Yt]++}[Me](){this[Yt]--,this[tr]()}[vr](e){this[Me](),e.resume()}[br](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!wt}[wr](e){this[Vs]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[Ws](e,i))}[Ws](e,t){let i=o=>{t(o)},r=()=>{this[de](this.cwd,this.dmode,o=>{if(o){this[_](o,e),i();return}this[yt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=u(S.dirname(String(e.absolute)));if(o!==this.cwd)return this[de](o,this.dmode,a=>{if(a){this[_](a,e),i();return}n()})}n()},n=()=>{p.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[vr](e),i();return}if(o||this[br](e,a))return this[M](null,e,i);if(a.isDirectory()){if(e.type==="Directory"){let h=this.chmod&&e.mode&&(a.mode&4095)!==e.mode,l=c=>this[M](c??null,e,i);return h?p.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return p.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);Bh(String(e.absolute),h=>this[M](h??null,e,i))})};this[yt]?s():r()}[M](e,t,i){if(e){this[_](e,t),i();return}switch(t.type){case"File":case"OldFile":case"ContiguousFile":return this[Er](t,i);case"Link":return this[Zs](t,i);case"SymbolicLink":return this[Gs](t,i);case"Directory":case"GNUDumpDir":return this[Sr](t,i)}}[ni](e,t,i,r){p[i](t,String(e.absolute),s=>{s?this[_](s,e):(this[Me](),e.resume()),r()})}},ht=e=>{try{return[null,e()]}catch(t){return[t,null]}},Ln=class extends Ar{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[wr](e){if(!this[yt]){let s=this[de](this.cwd,this.dmode);if(s)return this[_](s,e);this[yt]=!0}if(e.absolute!==this.cwd){let s=u(S.dirname(String(e.absolute)));if(s!==this.cwd){let n=this[de](s,this.dmode);if(n)return this[_](n,e)}}let[t,i]=ht(()=>p.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[vr](e);if(t||this[br](e,i))return this[M](null,e);if(i.isDirectory()){if(e.type==="Directory"){let n=this.chmod&&e.mode&&(i.mode&4095)!==e.mode,[o]=n?ht(()=>{p.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=ht(()=>p.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:ht(()=>$h(String(e.absolute)));this[M](r,e)}[Er](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{p.closeSync(s)}catch(h){a=h}(o||a)&&this[_](o||a,e),t()},s;try{s=p.openSync(String(e.absolute),kn(e.size),i)}catch(o){return r(o)}let n=this.transform&&this.transform(e)||e;n!==e&&(n.on("error",o=>this[_](o,e)),e.pipe(n)),n.on("data",o=>{try{p.writeSync(s,o,0,o.length)}catch(a){r(a)}}),n.on("end",()=>{let o=null;if(e.mtime&&!this.noMtime){let a=e.atime||new Date,h=e.mtime;try{p.futimesSync(s,a,h)}catch(l){try{p.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[pt](e)){let a=this[ft](e),h=this[gt](e);try{p.fchownSync(s,Number(a),Number(h))}catch(l){try{p.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[Sr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[de](String(e.absolute),i);if(r){this[_](r,e),t();return}if(e.mtime&&!this.noMtime)try{p.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[pt](e))try{p.chownSync(String(e.absolute),Number(this[ft](e)),Number(this[gt](e)))}catch{}t(),e.resume()}[de](e,t){try{return Ph(u(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:t})}catch(i){return i}}[ct](e,t,i,r,s){if(this.preservePaths||i.length===0)return r();let n=t;for(let o of i){n=S.resolve(n,o);let[a,h]=ht(()=>p.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new wi(n,S.resolve(t,i.join("/"))))}r()}[ni](e,t,i,r){let s=`${i}Sync`;try{p[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[_](n,e)}}},Uh=e=>{let t=new Ln(e),i=e.file,r=gn.statSync(i),s=e.maxReadSize||16*1024*1024;new ra(i,{readSize:s,size:r.size}).pipe(t)},zh=(e,t)=>{let i=new Ar(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),gn.stat(s,(a,h)=>{if(a)o(a);else{let l=new kr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Dn=Et(Uh,zh,e=>new Ln(e),e=>new Ar(e),(e,t)=>{t?.length&&ln(e,t)}),Hh=(e,t)=>{let i=new Dr(e),r=!0,s,n;try{try{s=I.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=I.openSync(e.file,"w+");else throw h}let o=I.fstatSync(s),a=Buffer.alloc(512);e:for(n=0;n<o.size;n+=512){for(let c=0,m=0;c<512;c+=m){if(m=I.readSync(s,a,c,a.length-c,n+c),n===0&&a[0]===31&&a[1]===139)throw new Error("cannot append to compressed archives");if(!m)break e}let h=new xe(a);if(!h.cksumValid)break;let l=512*Math.ceil((h.size||0)/512);if(n+l+512>o.size)break;n+=l,e.mtimeCache&&h.mtime&&e.mtimeCache.set(String(h.path),h.mtime)}r=!1,jh(e,i,n,s,t)}finally{if(r)try{I.closeSync(s)}catch{}}},jh=(e,t,i,r,s)=>{let n=new Qs(e.file,{fd:r,start:i});t.pipe(n),Gh(t,s)},Wh=(e,t)=>{t=Array.from(t);let i=new gi(e),r=(s,n,o)=>{let a=(d,O)=>{d?I.close(s,y=>o(d)):o(null,O)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),m=(d,O)=>{if(d||O===void 0)return a(d);if(l+=O,l<512&&O)return I.read(s,c,l,c.length-l,h+l,m);if(h===0&&c[0]===31&&c[1]===139)return a(new Error("cannot append to compressed archives"));if(l<512)return a(null,h);let y=new xe(c);if(!y.cksumValid)return a(null,h);let E=512*Math.ceil((y.size??0)/512);if(h+E+512>n||(h+=E+512,h>=n))return a(null,h);e.mtimeCache&&y.mtime&&e.mtimeCache.set(String(y.path),y.mtime),l=0,I.read(s,c,0,512,h,m)};I.read(s,c,0,512,h,m)};return new Promise((s,n)=>{i.on("error",n);let o="r+",a=(h,l)=>{if(h&&h.code==="ENOENT"&&o==="r+")return o="w+",I.open(e.file,o,a);if(h||!l)return n(h);I.fstat(l,(c,m)=>{if(c)return I.close(l,()=>n(c));r(l,m.size,(d,O)=>{if(d)return n(d);let y=new di(e.file,{fd:l,start:O});i.pipe(y),y.on("error",n),y.on("close",s),Zh(i,t)})})};I.open(e.file,o,a)})},Gh=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?pi({file:An.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},Zh=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await pi({file:An.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},lt=Et(Hh,Wh,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!da(e))throw new TypeError("file is required");if(e.gzip||e.brotli||e.zstd||e.file.endsWith(".br")||e.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!t?.length)throw new TypeError("no paths specified to add/replace")}),fd=Et(lt.syncFile,lt.asyncFile,lt.syncNoFile,lt.asyncNoFile,(e,t=[])=>{lt.validate?.(e,t),Kh(e)}),Kh=e=>{let t=e.filter;e.mtimeCache||(e.mtimeCache=new Map),e.filter=t?(i,r)=>t(i,r)&&!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0)):(i,r)=>!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0))};var St=De("taco.cli.upgrade"),Qh="https://registry.npmjs.org",Nn=3e4;async function el(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),Nn);try{let a=await r(s,{signal:n.signal});if(!a.ok)throw new Error(`registry returned ${a.status} ${a.statusText} for ${t}@${i}`);return await a.json()}finally{clearTimeout(o)}}async function tl(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),Nn);try{let n=await i(e,{signal:r.signal});if(!n.ok)throw new Error(`tarball download ${n.status} ${n.statusText} for ${e}`);if(!n.body)throw new Error(`tarball response had no body for ${e}`);await Ir(In(t),{recursive:!0});let o=await Jh(t,"w");try{let a=0,h=n.body.getReader();for(;;){let{done:l,value:c}=await h.read();if(l)break;await o.write(c),a+=c.byteLength}return a}finally{await o.close()}}finally{clearTimeout(s)}}async function il(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=Yh("sha512");await new Promise((o,a)=>{let h=Vh(e);h.on("data",l=>s.update(l)),h.on("end",()=>o()),h.on("error",a)});let n=s.digest("base64");if(n!==r)throw new Error(`integrity mismatch: expected ${r}, got ${n}`)}async function Cn(e={}){let t=e.fetcher??globalThis.fetch;if(typeof t!="function")throw new Error("global fetch is not available; pass opts.fetcher explicitly");let i=e.tacoHome??T,r=e.registry??Qh,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:Nr(),n=e.version??"latest";St.info(`fetching metadata for ${s.pkg}@${n}`);let o=await el(r,s.pkg,n,t);if(!o.dist?.tarball||!o.dist?.integrity)throw new Error(`registry response missing dist.tarball/integrity for ${s.pkg}@${n}`);let a=o.version,h=bi(i,"staging",`sidecar-${s.key}-${a}`),l=bi(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);St.info(`downloading tarball \u2192 ${l}`),await Ir(In(l),{recursive:!0}),await tl(o.dist.tarball,l,t),St.info("verifying integrity"),await il(l,o.dist.integrity),await qh(h,{recursive:!0,force:!0}),await Ir(h,{recursive:!0}),St.info(`extracting \u2192 ${h}`),await Dn({file:l,cwd:h,strip:1}),await rl(h);let c=e.liveDirOverride??await sl(s.key);if(!c)throw new Error(`no current @taco-ai/sidecar-${s.key} install found; run 'taco install' first`);let m={version:a,staging_dir:h,live_dir:c,written_at:new Date().toISOString()},d=bi(i,"upgrade-marker.json");return await Xr(d,m),St.info(`upgrade staged \u2192 version=${a}, marker=${d}`),{version:a,stagingDir:h,liveDir:c}}async function rl(e){for(let t of["manifest.json","bin","lib"]){let i=bi(e,t);try{await Xh(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function sl(e){let{createRequire:t}=await import("node:module"),i=t(import.meta.url);try{let r=i.resolve(`@taco-ai/sidecar-${e}/package.json`),s=r.lastIndexOf("/package.json");return s<0?r:r.slice(0,s)}catch{return null}}var Mn=`taco \u2014 launcher + supervisor for the sidecar daemon
84
+ `);if(c<0)return;let u=n.slice(0,c);clearTimeout(h);try{let d=JSON.parse(u);"error"in d?a(()=>r(new Error(`${t}: ${d.error.code} ${d.error.message}`))):a(()=>i(d.result))}catch(d){a(()=>r(new Error(`${t}: malformed reply: ${String(d)}`)))}}),s.on("close",()=>{clearTimeout(h),o||a(()=>r(new Error(`${t}: socket closed before reply`)))})})}async function Uo(e){let t=Date.now();for(;Date.now()-t<ds;){if(process.platform==="win32")return;let i=!0;try{i=(await import("node:fs")).existsSync(e)}catch{i=!1}if(!i)return;await new Promise(r=>setTimeout(r,100))}throw new Error(`socket ${e} still present after ${ds}ms`)}async function us(){let e=ie(),t=await $o(e,"control.shutdown");await Uo(e),process.stdout.write(`${JSON.stringify(t??{ok:!0})}
85
+ `)}import{existsSync as zo,unlinkSync as Ho}from"node:fs";async function ms(){let e=Si();if(zo(e)){await H("launchctl",["unload",e],{allowFailure:!0});try{Ho(e)}catch{}}return{serviceManager:"launchd"}}async function ps(){return await H("schtasks",["/Delete","/TN",Ze,"/F"],{allowFailure:!0}),{serviceManager:"schtasks"}}async function fs(){return process.platform==="darwin"?ms():process.platform==="win32"?ps():{serviceManager:"none"}}import{createHash as Yh}from"node:crypto";import{createReadStream as Jh}from"node:fs";import{mkdir as Ir,open as qh,rm as Xh,stat as Qh}from"node:fs/promises";import{dirname as In,join as bi}from"node:path";import Go from"events";import L from"fs";import{EventEmitter as Rr}from"node:events";import qs from"node:stream";import{StringDecoder as Zo}from"node:string_decoder";import en from"node:path";import Ue from"node:fs";import{dirname as na,parse as oa}from"path";import{EventEmitter as pa}from"events";import sr from"assert";import{Buffer as Oe}from"buffer";import*as Es from"zlib";import fa from"zlib";import{posix as Ie}from"node:path";import{basename as ja}from"node:path";import ai from"fs";import K from"fs";import xs from"path";import{win32 as ih}from"node:path";import Cs from"path";import gn from"node:fs";import bh from"node:assert";import{randomBytes as yn}from"node:crypto";import p from"node:fs";import S from"node:path";import wn from"fs";import yi from"node:fs";import mt from"node:path";import N from"node:fs";import Oh from"node:fs/promises";import ci from"node:path";import{join as Pn}from"node:path";import I from"node:fs";import An from"node:path";var jo=Object.defineProperty,Wo=(e,t)=>{for(var i in t)jo(e,i,{get:t[i],enumerable:!0})},gs=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ko=e=>!!e&&typeof e=="object"&&(e instanceof Pe||e instanceof qs||Vo(e)||Yo(e)),Vo=e=>!!e&&typeof e=="object"&&e instanceof Rr&&typeof e.pipe=="function"&&e.pipe!==qs.Writable.prototype.pipe,Yo=e=>!!e&&typeof e=="object"&&e instanceof Rr&&typeof e.write=="function"&&typeof e.end=="function",J=Symbol("EOF"),q=Symbol("maybeEmitEnd"),re=Symbol("emittedEnd"),Nt=Symbol("emittingEnd"),Ye=Symbol("emittedError"),Ct=Symbol("closed"),ys=Symbol("read"),Mt=Symbol("flush"),ws=Symbol("flushChunk"),F=Symbol("encoding"),Ae=Symbol("decoder"),v=Symbol("flowing"),Je=Symbol("paused"),Fe=Symbol("resume"),R=Symbol("buffer"),P=Symbol("pipes"),k=Symbol("bufferLength"),Pi=Symbol("bufferPush"),Ft=Symbol("bufferShift"),x=Symbol("objectMode"),b=Symbol("destroyed"),Li=Symbol("error"),Di=Symbol("emitData"),bs=Symbol("emitEnd"),Ai=Symbol("emitEnd2"),j=Symbol("async"),Ii=Symbol("abort"),Bt=Symbol("aborted"),qe=Symbol("signal"),ye=Symbol("dataListeners"),A=Symbol("discarded"),Xe=e=>Promise.resolve().then(e),Jo=e=>e(),qo=e=>e==="end"||e==="finish"||e==="prefinish",Xo=e=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,Qo=e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),Xs=class{src;dest;opts;ondrain;constructor(e,t,i){this.src=e,this.dest=t,this.opts=i,this.ondrain=()=>e[Fe](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ea=class extends Xs{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,i){super(e,t,i),this.proxyErrors=r=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},ta=e=>!!e.objectMode,ia=e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",Pe=class extends Rr{[v]=!1;[Je]=!1;[P]=[];[R]=[];[x];[F];[j];[Ae];[J]=!1;[re]=!1;[Nt]=!1;[Ct]=!1;[Ye]=null;[k]=0;[b]=!1;[qe];[Bt]=!1;[ye]=0;[A]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");ta(t)?(this[x]=!0,this[F]=null):ia(t)?(this[F]=t.encoding,this[x]=!1):(this[x]=!1,this[F]=null),this[j]=!!t.async,this[Ae]=this[F]?new Zo(this[F]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[R]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[P]});let{signal:i}=t;i&&(this[qe]=i,i.aborted?this[Ii]():i.addEventListener("abort",()=>this[Ii]()))}get bufferLength(){return this[k]}get encoding(){return this[F]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[x]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[j]}set async(e){this[j]=this[j]||!!e}[Ii](){this[Bt]=!0,this.emit("abort",this[qe]?.reason),this.destroy(this[qe]?.reason)}get aborted(){return this[Bt]}set aborted(e){}write(e,t,i){if(this[Bt])return!1;if(this[J])throw new Error("write after end");if(this[b])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(i=t,t="utf8"),t||(t="utf8");let r=this[j]?Xe:Jo;if(!this[x]&&!Buffer.isBuffer(e)){if(Qo(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Xo(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[x]?(this[v]&&this[k]!==0&&this[Mt](!0),this[v]?this.emit("data",e):this[Pi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[v]):e.length?(typeof e=="string"&&!(t===this[F]&&!this[Ae]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[F]&&(e=this[Ae].write(e)),this[v]&&this[k]!==0&&this[Mt](!0),this[v]?this.emit("data",e):this[Pi](e),this[k]!==0&&this.emit("readable"),i&&r(i),this[v]):(this[k]!==0&&this.emit("readable"),i&&r(i),this[v])}read(e){if(this[b])return null;if(this[A]=!1,this[k]===0||e===0||e&&e>this[k])return this[q](),null;this[x]&&(e=null),this[R].length>1&&!this[x]&&(this[R]=[this[F]?this[R].join(""):Buffer.concat(this[R],this[k])]);let t=this[ys](e||null,this[R][0]);return this[q](),t}[ys](e,t){if(this[x])this[Ft]();else{let i=t;e===i.length||e===null?this[Ft]():typeof i=="string"?(this[R][0]=i.slice(e),t=i.slice(0,e),this[k]-=e):(this[R][0]=i.subarray(e),t=i.subarray(0,e),this[k]-=e)}return this.emit("data",t),!this[R].length&&!this[J]&&this.emit("drain"),t}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t="utf8"),e!==void 0&&this.write(e,t),i&&this.once("end",i),this[J]=!0,this.writable=!1,(this[v]||!this[Je])&&this[q](),this}[Fe](){this[b]||(!this[ye]&&!this[P].length&&(this[A]=!0),this[Je]=!1,this[v]=!0,this.emit("resume"),this[R].length?this[Mt]():this[J]?this[q]():this.emit("drain"))}resume(){return this[Fe]()}pause(){this[v]=!1,this[Je]=!0,this[A]=!1}get destroyed(){return this[b]}get flowing(){return this[v]}get paused(){return this[Je]}[Pi](e){this[x]?this[k]+=1:this[k]+=e.length,this[R].push(e)}[Ft](){return this[x]?this[k]-=1:this[k]-=this[R][0].length,this[R].shift()}[Mt](e=!1){do;while(this[ws](this[Ft]())&&this[R].length);!e&&!this[R].length&&!this[J]&&this.emit("drain")}[ws](e){return this.emit("data",e),this[v]}pipe(e,t){if(this[b])return e;this[A]=!1;let i=this[re];return t=t||{},e===gs.stdout||e===gs.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,i?t.end&&e.end():(this[P].push(t.proxyErrors?new ea(this,e,t):new Xs(this,e,t)),this[j]?Xe(()=>this[Fe]()):this[Fe]()),e}unpipe(e){let t=this[P].find(i=>i.dest===e);t&&(this[P].length===1?(this[v]&&this[ye]===0&&(this[v]=!1),this[P]=[]):this[P].splice(this[P].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let i=super.on(e,t);if(e==="data")this[A]=!1,this[ye]++,!this[P].length&&!this[v]&&this[Fe]();else if(e==="readable"&&this[k]!==0)super.emit("readable");else if(qo(e)&&this[re])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[Ye]){let r=t;this[j]?Xe(()=>r.call(this,this[Ye])):r.call(this,this[Ye])}return i}removeListener(e,t){return this.off(e,t)}off(e,t){let i=super.off(e,t);return e==="data"&&(this[ye]=this.listeners("data").length,this[ye]===0&&!this[A]&&!this[P].length&&(this[v]=!1)),i}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[ye]=0,!this[A]&&!this[P].length&&(this[v]=!1)),t}get emittedEnd(){return this[re]}[q](){!this[Nt]&&!this[re]&&!this[b]&&this[R].length===0&&this[J]&&(this[Nt]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Ct]&&this.emit("close"),this[Nt]=!1)}emit(e,...t){let i=t[0];if(e!=="error"&&e!=="close"&&e!==b&&this[b])return!1;if(e==="data")return!this[x]&&!i?!1:this[j]?(Xe(()=>this[Di](i)),!0):this[Di](i);if(e==="end")return this[bs]();if(e==="close"){if(this[Ct]=!0,!this[re]&&!this[b])return!1;let s=super.emit("close");return this.removeAllListeners("close"),s}else if(e==="error"){this[Ye]=i,super.emit(Li,i);let s=!this[qe]||this.listeners("error").length?super.emit("error",i):!1;return this[q](),s}else if(e==="resume"){let s=super.emit("resume");return this[q](),s}else if(e==="finish"||e==="prefinish"){let s=super.emit(e);return this.removeAllListeners(e),s}let r=super.emit(e,...t);return this[q](),r}[Di](e){for(let i of this[P])i.dest.write(e)===!1&&this.pause();let t=this[A]?!1:super.emit("data",e);return this[q](),t}[bs](){return this[re]?!1:(this[re]=!0,this.readable=!1,this[j]?(Xe(()=>this[Ai]()),!0):this[Ai]())}[Ai](){if(this[Ae]){let t=this[Ae].end();if(t){for(let i of this[P])i.dest.write(t);this[A]||super.emit("data",t)}}for(let t of this[P])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[x]||(e.dataLength=0);let t=this.promise();return this.on("data",i=>{e.push(i),this[x]||(e.dataLength+=i.length)}),await t,e}async concat(){if(this[x])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[F]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(b,()=>t(new Error("stream destroyed"))),this.on("error",i=>t(i)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[A]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let i=this.read();if(i!==null)return Promise.resolve({done:!1,value:i});if(this[J])return t();let r,s,n=l=>{this.off("data",o),this.off("end",a),this.off(b,h),t(),s(l)},o=l=>{this.off("error",n),this.off("end",a),this.off(b,h),this.pause(),r({value:l,done:!!this[J]})},a=()=>{this.off("error",n),this.off("data",o),this.off(b,h),t(),r({done:!0,value:void 0})},h=()=>n(new Error("stream destroyed"));return new Promise((l,c)=>{s=c,r=l,this.once(b,h),this.once("error",n),this.once("end",a),this.once("data",o)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[A]=!1;let e=!1,t=()=>(this.pause(),this.off(Li,t),this.off(b,t),this.off("end",t),e=!0,{done:!0,value:void 0}),i=()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}};return this.once("end",t),this.once(Li,t),this.once(b,t),{next:i,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[b])return e?this.emit("error",e):this.emit(b),this;this[b]=!0,this[A]=!0,this[R].length=0,this[k]=0;let t=this;return typeof t.close=="function"&&!this[Ct]&&t.close(),e?this.emit("error",e):this.emit(b),this}static get isStream(){return Ko}},ra=L.writev,ue=Symbol("_autoClose"),z=Symbol("_close"),Qe=Symbol("_ended"),f=Symbol("_fd"),Ni=Symbol("_finished"),te=Symbol("_flags"),Ci=Symbol("_flush"),ir=Symbol("_handleChunk"),rr=Symbol("_makeBuf"),dt=Symbol("_mode"),$t=Symbol("_needDrain"),He=Symbol("_onerror"),je=Symbol("_onopen"),Mi=Symbol("_onread"),Be=Symbol("_onwrite"),me=Symbol("_open"),U=Symbol("_path"),ae=Symbol("_pos"),W=Symbol("_queue"),$e=Symbol("_read"),Fi=Symbol("_readSize"),ee=Symbol("_reading"),et=Symbol("_remain"),Bi=Symbol("_size"),Yt=Symbol("_write"),we=Symbol("_writing"),Jt=Symbol("_defaultFlag"),_e=Symbol("_errored"),kr=class extends Pe{[_e]=!1;[f];[U];[Fi];[ee]=!1;[Bi];[et];[ue];constructor(e,t){if(t=t||{},super(t),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[_e]=!1,this[f]=typeof t.fd=="number"?t.fd:void 0,this[U]=e,this[Fi]=t.readSize||16*1024*1024,this[ee]=!1,this[Bi]=typeof t.size=="number"?t.size:1/0,this[et]=this[Bi],this[ue]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[f]=="number"?this[$e]():this[me]()}get fd(){return this[f]}get path(){return this[U]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[me](){L.open(this[U],"r",(e,t)=>this[je](e,t))}[je](e,t){e?this[He](e):(this[f]=t,this.emit("open",t),this[$e]())}[rr](){return Buffer.allocUnsafe(Math.min(this[Fi],this[et]))}[$e](){if(!this[ee]){this[ee]=!0;let e=this[rr]();if(e.length===0)return process.nextTick(()=>this[Mi](null,0,e));L.read(this[f],e,0,e.length,null,(t,i,r)=>this[Mi](t,i,r))}}[Mi](e,t,i){this[ee]=!1,e?this[He](e):this[ir](t,i)&&this[$e]()}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}[He](e){this[ee]=!0,this[z](),this.emit("error",e)}[ir](e,t){let i=!1;return this[et]-=e,e>0&&(i=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[et]<=0)&&(i=!1,this[z](),super.end()),i}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[f]=="number"&&this[$e](),!1;case"error":return this[_e]?!1:(this[_e]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},sa=class extends kr{[me](){let e=!0;try{this[je](null,L.openSync(this[U],"r")),e=!1}finally{e&&this[z]()}}[$e](){let e=!0;try{if(!this[ee]){this[ee]=!0;do{let t=this[rr](),i=t.length===0?0:L.readSync(this[f],t,0,t.length,null);if(!this[ir](i,t))break}while(!0);this[ee]=!1}e=!1}finally{e&&this[z]()}}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}},di=class extends Go{readable=!1;writable=!0;[_e]=!1;[we]=!1;[Qe]=!1;[W]=[];[$t]=!1;[U];[dt];[ue];[f];[Jt];[te];[Ni]=!1;[ae];constructor(e,t){t=t||{},super(t),this[U]=e,this[f]=typeof t.fd=="number"?t.fd:void 0,this[dt]=t.mode===void 0?438:t.mode,this[ae]=typeof t.start=="number"?t.start:void 0,this[ue]=typeof t.autoClose=="boolean"?t.autoClose:!0;let i=this[ae]!==void 0?"r+":"w";this[Jt]=t.flags===void 0,this[te]=t.flags===void 0?i:t.flags,this[f]===void 0&&this[me]()}emit(e,...t){if(e==="error"){if(this[_e])return!1;this[_e]=!0}return super.emit(e,...t)}get fd(){return this[f]}get path(){return this[U]}[He](e){this[z](),this[we]=!0,this.emit("error",e)}[me](){L.open(this[U],this[te],this[dt],(e,t)=>this[je](e,t))}[je](e,t){this[Jt]&&this[te]==="r+"&&e&&e.code==="ENOENT"?(this[te]="w",this[me]()):e?this[He](e):(this[f]=t,this.emit("open",t),this[we]||this[Ci]())}end(e,t){return e&&this.write(e,t),this[Qe]=!0,!this[we]&&!this[W].length&&typeof this[f]=="number"&&this[Be](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[Qe]?(this.emit("error",new Error("write() after end()")),!1):this[f]===void 0||this[we]||this[W].length?(this[W].push(e),this[$t]=!0,!1):(this[we]=!0,this[Yt](e),!0)}[Yt](e){L.write(this[f],e,0,e.length,this[ae],(t,i)=>this[Be](t,i))}[Be](e,t){e?this[He](e):(this[ae]!==void 0&&typeof t=="number"&&(this[ae]+=t),this[W].length?this[Ci]():(this[we]=!1,this[Qe]&&!this[Ni]?(this[Ni]=!0,this[z](),this.emit("finish")):this[$t]&&(this[$t]=!1,this.emit("drain"))))}[Ci](){if(this[W].length===0)this[Qe]&&this[Be](null,0);else if(this[W].length===1)this[Yt](this[W].pop());else{let e=this[W];this[W]=[],ra(this[f],e,this[ae],(t,i)=>this[Be](t,i))}}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.close(e,t=>t?this.emit("error",t):this.emit("close"))}}},Qs=class extends di{[me](){let e;if(this[Jt]&&this[te]==="r+")try{e=L.openSync(this[U],this[te],this[dt])}catch(t){if(t?.code==="ENOENT")return this[te]="w",this[me]();throw t}else e=L.openSync(this[U],this[te],this[dt]);this[je](null,e)}[z](){if(this[ue]&&typeof this[f]=="number"){let e=this[f];this[f]=void 0,L.closeSync(e),this.emit("close")}}[Yt](e){let t=!0;try{this[Be](null,L.writeSync(this[f],e,0,e.length,this[ae])),t=!1}finally{if(t)try{this[z]()}catch{}}}},aa=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),ha=e=>!!e.sync&&!!e.file,la=e=>!e.sync&&!!e.file,ca=e=>!!e.sync&&!e.file,da=e=>!e.sync&&!e.file,ua=e=>!!e.file,ma=e=>aa.get(e)||e,_r=(e={})=>{if(!e)return{};let t={};for(let[i,r]of Object.entries(e)){let s=ma(i);t[s]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Et=(e,t,i,r,s)=>Object.assign((n=[],o,a)=>{Array.isArray(n)&&(o=n,n={}),typeof o=="function"&&(a=o,o=void 0),o=o?Array.from(o):[];let h=_r(n);if(s?.(h,o),ha(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return e(h,o)}else if(la(h)){let l=t(h,o);return a?l.then(()=>a(),a):l}else if(ca(h)){if(typeof a=="function")throw new TypeError("callback not supported for sync tar functions");return i(h,o)}else if(da(h)){if(typeof a=="function")throw new TypeError("callback only supported with file option");return r(h,o)}throw new Error("impossible options??")},{syncFile:e,asyncFile:t,syncNoFile:i,asyncNoFile:r,validate:s}),ga=fa.constants||{ZLIB_VERNUM:4736},Y=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},ga)),ya=Oe.concat,Ss=Object.getOwnPropertyDescriptor(Oe,"concat"),wa=e=>e,$i=Ss?.writable===!0||Ss?.set!==void 0?e=>{Oe.concat=e?wa:ya}:e=>{},Te=Symbol("_superWrite"),Ut=class extends Error{code;errno;constructor(e,t){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,t??this.constructor)}get name(){return"ZlibError"}},Ui=Symbol("flushFlag"),Or=class extends Pe{#e=!1;#i=!1;#r;#n;#s;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(e,t){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#r=e.flush??0,this.#n=e.finishFlush??0,this.#s=e.fullFlushFlag??0,typeof Es[t]!="function")throw new TypeError("Compression method not supported: "+t);try{this.#t=new Es[t](e)}catch(i){throw new Ut(i,this.constructor)}this.#o=i=>{this.#e||(this.#e=!0,this.close(),this.emit("error",i))},this.#t?.on("error",i=>this.#o(new Ut(i))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return sr(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#s),this.write(Object.assign(Oe.alloc(0),{[Ui]:e})))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#n),this.#i=!0,super.end(i)}get ended(){return this.#i}[Te](e){return super.write(e)}write(e,t,i){if(typeof t=="function"&&(i=t,t="utf8"),typeof e=="string"&&(e=Oe.from(e,t)),this.#e)return;sr(this.#t,"zlib binding closed");let r=this.#t._handle,s=r.close;r.close=()=>{};let n=this.#t.close;this.#t.close=()=>{},$i(!0);let o;try{let h=typeof e[Ui]=="number"?e[Ui]:this.#r;o=this.#t._processChunk(e,h),$i(!1)}catch(h){$i(!1),this.#o(new Ut(h,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=s,this.#t.close=n,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Ut(h,this.write)));let a;if(o)if(Array.isArray(o)&&o.length>0){let h=o[0];a=this[Te](Oe.from(h));for(let l=1;l<o.length;l++)a=this[Te](o[l])}else a=this[Te](Oe.from(o));return i&&i(),a}},tn=class extends Or{#e;#i;constructor(e,t){e=e||{},e.flush=e.flush||Y.Z_NO_FLUSH,e.finishFlush=e.finishFlush||Y.Z_FINISH,e.fullFlushFlag=Y.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#i=e.strategy}params(e,t){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#i!==t){this.flush(Y.Z_SYNC_FLUSH),sr(this.handle,"zlib binding closed");let i=this.handle.flush;this.handle.flush=(r,s)=>{typeof r=="function"&&(s=r,r=this.flushFlag),this.flush(r),s?.()};try{this.handle.params(e,t)}finally{this.handle.flush=i}this.handle&&(this.#e=e,this.#i=t)}}}},ba=class extends tn{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[Te](e){return this.#e?(this.#e=!1,e[9]=255,super[Te](e)):super[Te](e)}},Ea=class extends tn{constructor(e){super(e,"Unzip")}},rn=class extends Or{constructor(e,t){e=e||{},e.flush=e.flush||Y.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||Y.BROTLI_OPERATION_FINISH,e.fullFlushFlag=Y.BROTLI_OPERATION_FLUSH,super(e,t)}},Sa=class extends rn{constructor(e){super(e,"BrotliCompress")}},va=class extends rn{constructor(e){super(e,"BrotliDecompress")}},sn=class extends Or{constructor(e,t){e=e||{},e.flush=e.flush||Y.ZSTD_e_continue,e.finishFlush=e.finishFlush||Y.ZSTD_e_end,e.fullFlushFlag=Y.ZSTD_e_flush,super(e,t)}},Ra=class extends sn{constructor(e){super(e,"ZstdCompress")}},ka=class extends sn{constructor(e){super(e,"ZstdDecompress")}},_a=(e,t)=>{if(Number.isSafeInteger(e))e<0?Ta(e,t):Oa(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},Oa=(e,t)=>{t[0]=128;for(var i=t.length;i>1;i--)t[i-1]=e&255,e=Math.floor(e/256)},Ta=(e,t)=>{t[0]=255;var i=!1;e=e*-1;for(var r=t.length;r>1;r--){var s=e&255;e=Math.floor(e/256),i?t[r-1]=nn(s):s===0?t[r-1]=0:(i=!0,t[r-1]=on(s))}},xa=e=>{let t=e[0],i=t===128?La(e.subarray(1,e.length)):t===255?Pa(e):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},Pa=e=>{for(var t=e.length,i=0,r=!1,s=t-1;s>-1;s--){var n=Number(e[s]),o;r?o=nn(n):n===0?o=n:(r=!0,o=on(n)),o!==0&&(i-=o*Math.pow(256,t-s-1))}return i},La=e=>{for(var t=e.length,i=0,r=t-1;r>-1;r--){var s=Number(e[r]);s!==0&&(i+=s*Math.pow(256,t-r-1))}return i},nn=e=>(255^e)&255,on=e=>(255^e)+1&255,Da={};Wo(Da,{code:()=>Tr,isCode:()=>qt,isName:()=>Aa,name:()=>ui,normalFsTypes:()=>an});var qt=e=>ui.has(e),Aa=e=>Tr.has(e),an=new Set(["0","","1","2","3","4","5","6","7","D"]),ui=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Tr=new Map(Array.from(ui).map(e=>[e[1],e[0]])),Ia=e=>e===void 0||e<0?void 0:e,xe=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,i,r){Buffer.isBuffer(e)?this.decode(e,t||0,i,r):e&&this.#i(e)}decode(e,t,i,r){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=be(e,t+156,1),n=an.has(s),o=n?i:void 0,a=n?r:void 0;if(this.path=o?.path??be(e,t,100),this.mode=o?.mode??a?.mode??he(e,t+100,8),this.uid=o?.uid??a?.uid??he(e,t+108,8),this.gid=o?.gid??a?.gid??he(e,t+116,8),this.size=Ia(o?.size??a?.size??he(e,t+124,12)),this.mtime=o?.mtime??a?.mtime??zi(e,t+136,12),this.cksum=he(e,t+148,12),a&&this.#i(a,!0),o&&this.#i(o),qt(s)&&(this.#e=s||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=be(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=o?.uname??a?.uname??be(e,t+265,32),this.gname=o?.gname??a?.gname??be(e,t+297,32),this.devmaj=o?.devmaj??a?.devmaj??he(e,t+329,8)??0,this.devmin=o?.devmin??a?.devmin??he(e,t+337,8)??0,e[t+475]!==0){let l=be(e,t+345,155);this.path=l+"/"+this.path}else{let l=be(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=i?.atime??r?.atime??zi(e,t+476,12),this.ctime=i?.ctime??r?.ctime??zi(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#i(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="size"&&Number(r)<0||i==="path"&&t||i==="linkpath"&&t||i==="global"))))}encode(e,t=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let i=this.ctime||this.atime?130:155,r=Na(this.path||"",i),s=r[0],n=r[1];this.needPax=!!r[2],this.needPax=Ee(e,t,100,s)||this.needPax,this.needPax=le(e,t+100,8,this.mode)||this.needPax,this.needPax=le(e,t+108,8,this.uid)||this.needPax,this.needPax=le(e,t+116,8,this.gid)||this.needPax,this.needPax=le(e,t+124,12,this.size)||this.needPax,this.needPax=Hi(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Ee(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=Ee(e,t+265,32,this.uname)||this.needPax,this.needPax=Ee(e,t+297,32,this.gname)||this.needPax,this.needPax=le(e,t+329,8,this.devmaj)||this.needPax,this.needPax=le(e,t+337,8,this.devmin)||this.needPax,this.needPax=Ee(e,t+345,i,n)||this.needPax,e[t+475]!==0?this.needPax=Ee(e,t+345,155,n)||this.needPax:(this.needPax=Ee(e,t+345,130,n)||this.needPax,this.needPax=Hi(e,t+476,12,this.atime)||this.needPax,this.needPax=Hi(e,t+488,12,this.ctime)||this.needPax);let o=256;for(let a=t;a<t+148;a++)o+=e[a];for(let a=t+156;a<t+512;a++)o+=e[a];return this.cksum=o,le(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:ui.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Tr.get(e));if(qt(t)||t==="Unsupported")this.#e=t;else if(qt(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Na=(e,t)=>{let i=e,r="",s,n=Ie.parse(e).root||".";if(Buffer.byteLength(i)<100)s=[i,r,!1];else{r=Ie.dirname(i),i=Ie.basename(i);do Buffer.byteLength(i)<=100&&Buffer.byteLength(r)<=t?s=[i,r,!1]:Buffer.byteLength(i)>100&&Buffer.byteLength(r)<=t?s=[i.slice(0,99),r,!0]:(i=Ie.join(Ie.basename(r),i),r=Ie.dirname(r));while(r!==n&&s===void 0);s||(s=[e.slice(0,99),"",!0])}return s},be=(e,t,i)=>e.subarray(t,t+i).toString("utf8").replace(/\0.*/,""),zi=(e,t,i)=>Ca(he(e,t,i)),Ca=e=>e===void 0?void 0:new Date(e*1e3),he=(e,t,i)=>Number(e[t])&128?xa(e.subarray(t,t+i)):Fa(e,t,i),Ma=e=>isNaN(e)?void 0:e,Fa=(e,t,i)=>Ma(parseInt(e.subarray(t,t+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),Ba={12:8589934591,8:2097151},le=(e,t,i,r)=>r===void 0?!1:r>Ba[i]||r<0?(_a(r,e.subarray(t,t+i)),!0):($a(e,t,i,r),!1),$a=(e,t,i,r)=>e.write(Ua(r,i),t,i,"ascii"),Ua=(e,t)=>za(Math.floor(e).toString(8),t),za=(e,t)=>(e.length===t-1?e:new Array(t-e.length-1).join("0")+e+" ")+"\0",Hi=(e,t,i,r)=>r===void 0?!1:le(e,t,i,r.getTime()/1e3),Ha=new Array(156).join("\0"),Ee=(e,t,i,r)=>r===void 0?!1:(e.write(r+Ha,t,i,"utf8"),r.length!==Buffer.byteLength(r)||r.length>i),oi=class hn{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,i=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=i,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){let t=this.encodeBody();if(t==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(t),r=512*Math.ceil(1+i/512),s=Buffer.allocUnsafe(r);for(let n=0;n<512;n++)s[n]=0;new xe({path:("PaxHeader/"+ja(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(s),s.write(t,512,i,"utf8");for(let n=i+512;n<s.length;n++)s[n]=0;return s}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(t){if(this[t]===void 0)return"";let i=this[t],r=i instanceof Date?i.getTime()/1e3:i,s=" "+(t==="dev"||t==="ino"||t==="nlink"?"SCHILY.":"")+t+"="+r+`
86
+ `,n=Buffer.byteLength(s),o=Math.floor(Math.log(n)/Math.log(10))+1;return n+o>=Math.pow(10,o)&&(o+=1),o+n+s}static parse(t,i,r=!1){return new hn(Wa(Ga(t),i),r)}},Wa=(e,t)=>t?Object.assign({},t,e):e,Ga=e=>e.replace(/\n$/,"").split(`
87
+ `).reduce(Za,Object.create(null)),Za=(e,t)=>{let i=parseInt(t,10);if(i!==Buffer.byteLength(t)+1)return e;t=t.slice((i+" ").length);let r=t.split("="),s=r.shift();if(!s)return e;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),o=r.join("=").replace(/\0.*/,"");switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":e[n]=o;break;case"ctime":case"atime":case"mtime":e[n]=new Date(Number(o)*1e3);break;case"size":let a=+o;a>=0&&(e[n]=a);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":e[n]=+o;break}return e},Ka=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,m=Ka!=="win32"?e=>String(e):e=>String(e).replaceAll(/\\/g,"/"),Va=class extends Pe{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(e,t,i){switch(super({}),this.pause(),this.extended=t,this.globalExtended=i,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.path=m(e.path),this.mode=e.mode,this.mode&&(this.mode=this.mode&4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?m(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),i&&this.#e(i,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw new Error("writing more to entry than is appropriate");let i=this.remain,r=this.blockRemain;return this.remain=Math.max(0,i-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:i>=t?super.write(e):super.write(e.subarray(0,i))}#e(e,t=!1){e.path&&(e.path=m(e.path)),e.linkpath&&(e.linkpath=m(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([i,r])=>!(r==null||i==="path"&&t))))}},mi=(e,t,i,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=i instanceof Error&&i.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(i instanceof Error&&(r=Object.assign(i,r),i=i.message),e.emit("warn",t,i,r)):i instanceof Error?e.emit("error",Object.assign(i,r)):e.emit("error",Object.assign(new Error(`${t}: ${i}`),r))},Ya=1024*1024,nr=Buffer.from([31,139]),or=Buffer.from([40,181,47,253]),Ja=Math.max(nr.length,or.length),C=Symbol("state"),Se=Symbol("writeEntry"),X=Symbol("readEntry"),ji=Symbol("nextEntry"),vs=Symbol("processEntry"),G=Symbol("extendedHeader"),tt=Symbol("globalExtendedHeader"),se=Symbol("meta"),Rs=Symbol("emitMeta"),g=Symbol("buffer"),Q=Symbol("queue"),ne=Symbol("ended"),Wi=Symbol("emittedEnd"),ve=Symbol("emit"),w=Symbol("unzip"),zt=Symbol("consumeChunk"),Ht=Symbol("consumeChunkSub"),Gi=Symbol("consumeBody"),ks=Symbol("consumeMeta"),_s=Symbol("consumeHeader"),it=Symbol("consuming"),Zi=Symbol("bufferConcat"),jt=Symbol("maybeEnd"),Ne=Symbol("writing"),Z=Symbol("aborted"),Wt=Symbol("onDone"),Re=Symbol("sawValidEntry"),Gt=Symbol("sawNullBlock"),Zt=Symbol("sawEOF"),Os=Symbol("closeStream"),qa=1e3,rt=Symbol("compressedBytesRead"),Ki=Symbol("decompressedBytesRead"),Ts=Symbol("checkDecompressionRatio"),Xa=()=>!0,bt=class extends pa{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[Q]=[];[g];[X];[Se];[C]="begin";[se]="";[G];[tt];[ne]=!1;[w];[Z]=!1;[Re];[Gt]=!1;[Zt]=!1;[Ne]=!1;[it]=!1;[Wi]=!1;[rt]=0;[Ki]=0;constructor(e={}){super(),this.file=e.file||"",this.on(Wt,()=>{(this[C]==="begin"||this[Re]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(Wt,e.ondone):this.on(Wt,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:qa,this.maxMetaEntrySize=e.maxMetaEntrySize||Ya,this.filter=typeof e.filter=="function"?e.filter:Xa;let t=e.file&&(e.file.endsWith(".tar.br")||e.file.endsWith(".tbr"));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:t?void 0:!1;let i=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:i?!0:void 0,this.on("end",()=>this[Os]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,i={}){mi(this,e,t,i)}[_s](e,t){this[Re]===void 0&&(this[Re]=!1);let i;try{i=new xe(e,t,this[G],this[tt])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(i.nullBlock)this[Gt]?(this[Zt]=!0,this[C]==="begin"&&(this[C]="header"),this[ve]("eof")):(this[Gt]=!0,this[ve]("nullBlock"));else if(this[Gt]=!1,!i.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:i});else if(!i.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:i});else{let r=i.type;if(/^(Symbolic)?Link$/.test(r)&&!i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:i});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:i});else{let s=this[Se]=new Va(i,this[G],this[tt]);if(!this[Re])if(s.remain){let n=()=>{s.invalid||(this[Re]=!0)};s.on("end",n)}else this[Re]=!0;s.meta?s.size>this.maxMetaEntrySize?(s.ignore=!0,this[ve]("ignoredEntry",s),this[C]="ignore",s.resume()):s.size>0&&(this[se]="",s.on("data",n=>this[se]+=n),this[C]="meta"):(this[G]=void 0,s.ignore=s.ignore||!this.filter(s.path,s),s.ignore?(this[ve]("ignoredEntry",s),this[C]=s.remain?"ignore":"header",s.resume()):(s.remain?this[C]="body":(this[C]="header",s.end()),this[X]?this[Q].push(s):(this[Q].push(s),this[ji]())))}}}[Os](){queueMicrotask(()=>this.emit("close"))}[vs](e){let t=!0;if(!e)this[X]=void 0,t=!1;else if(Array.isArray(e)){let[i,...r]=e;this.emit(i,...r)}else this[X]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[ji]()),t=!1);return t}[ji](){do;while(this[vs](this[Q].shift()));if(this[Q].length===0){let e=this[X];!e||e.flowing||e.size===e.remain?this[Ne]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Gi](e,t){let i=this[Se];if(!i)throw new Error("attempt to consume body without entry??");let r=i.blockRemain??0,s=r>=e.length&&t===0?e:e.subarray(t,t+r);return i.write(s),i.blockRemain||(this[C]="header",this[Se]=void 0,i.end()),s.length}[ks](e,t){let i=this[Se],r=this[Gi](e,t);return!this[Se]&&i&&this[Rs](i),r}[ve](e,t,i){this[Q].length===0&&!this[X]?this.emit(e,t,i):this[Q].push([e,t,i])}[Rs](e){switch(this[ve]("meta",this[se]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[G]=oi.parse(this[se],this[G],!1);break;case"GlobalExtendedHeader":this[tt]=oi.parse(this[se],this[tt],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[G]??Object.create(null);this[G]=t,t.path=this[se].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[G]||Object.create(null);this[G]=t,t.linkpath=this[se].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){if(!this[Z]){if(this[w]){let t=this[w];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[Z]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[Ts](e){this[Ki]+=e.length;let t=this[Ki]/this[rt];return t>this.maxDecompressionRatio?(this.abort(new Error(`max decompression ratio exceeded: ${t.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this[Z])return i?.(),!1;if((this[w]===void 0||this.brotli===void 0&&this[w]===!1)&&e){if(this[g]&&(e=Buffer.concat([this[g],e]),this[g]=void 0),e.length<Ja)return this[g]=e,i?.(),!0;for(let o=0;this[w]===void 0&&o<nr.length;o++)e[o]!==nr[o]&&(this[w]=!1);let s=!1;if(this[w]===!1&&this.zstd!==!1){s=!0;for(let o=0;o<or.length;o++)if(e[o]!==or[o]){s=!1;break}}let n=this.brotli===void 0&&!s;if(this[w]===!1&&n)if(e.length<512)if(this[ne])this.brotli=!0;else return this[g]=e,i?.(),!0;else try{new xe(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[w]===void 0||this[w]===!1&&(this.brotli||s)){let o=this[ne];this[ne]=!1,this[w]=this[w]===void 0?new Ea({}):s?new ka({}):new va({}),this[w].on("data",h=>{this[Ts](h)&&this[zt](h)}),this[w].on("error",h=>{this[Z]||this.abort(h)}),this[w].on("end",()=>{this[ne]=!0,this[zt]()}),this[Ne]=!0,this[rt]+=e.length;let a=!!this[w][o?"end":"write"](e);return this[Ne]=!1,i?.(),a}}this[Ne]=!0,this[w]?(this[rt]+=e.length,this[w].write(e)):this[zt](e),this[Ne]=!1;let r=this[Q].length>0?!1:this[X]?this[X].flowing:!0;return!r&&this[Q].length===0&&this[X]?.once("drain",()=>this.emit("drain")),i?.(),r}[Zi](e){e&&!this[Z]&&(this[g]=this[g]?Buffer.concat([this[g],e]):e)}[jt](){if(this[ne]&&!this[Wi]&&!this[Z]&&!this[it]){this[Wi]=!0;let e=this[Se];if(e?.blockRemain){let t=this[g]?this[g].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[g]&&e.write(this[g]),e.end()}this[ve](Wt)}}[zt](e){if(this[it]&&e)this[Zi](e);else if(!e&&!this[g])this[jt]();else if(e){if(this[it]=!0,this[g]){this[Zi](e);let t=this[g];this[g]=void 0,this[Ht](t)}else this[Ht](e);for(;this[g]&&this[g]?.length>=512&&!this[Z]&&!this[Zt];){let t=this[g];this[g]=void 0,this[Ht](t)}this[it]=!1}(!this[g]||this[ne])&&this[jt]()}[Ht](e){let t=0,i=e.length;for(;t+512<=i&&!this[Z]&&!this[Zt];)switch(this[C]){case"begin":case"header":this[_s](e,t),t+=512;break;case"ignore":case"body":t+=this[Gi](e,t);break;case"meta":t+=this[ks](e,t);break;default:throw new Error("invalid state: "+this[C])}t<i&&(this[g]=this[g]?Buffer.concat([e.subarray(t),this[g]]):e.subarray(t))}end(e,t,i){return typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t)),i&&this.once("finish",i),this[Z]||(this[w]?(e&&(this[rt]+=e.length,this[w].write(e)),this[w].end()):(this[ne]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[jt]())),this}},ut=e=>{let t=e.length-1,i=-1;for(;t>-1&&e.charAt(t)==="/";)i=t,t--;return i===-1?e:e.slice(0,i)},Qa=e=>{let t=e.onReadEntry;e.onReadEntry=t?i=>{t(i),i.resume()}:i=>i.resume()},ln=(e,t)=>{let i=new Map(t.map(o=>[ut(o),!0])),r=e.filter,s=100,n=(o,a="",h=0)=>{if(h>=s)return i.set(o,!1),!1;let l=a||oa(o).root||".",c;if(o===l)c=!1;else{let u=i.get(o);c=u!==void 0?u:n(na(o),l,h+1)}return i.set(o,c),c};e.filter=r?(o,a)=>r(o,a)&&n(ut(o)):o=>n(ut(o))},eh=e=>{let t=new bt(e),i=e.file,r;try{r=Ue.openSync(i,"r");let s=Ue.fstatSync(r),n=e.maxReadSize||16*1024*1024;if(s.size<n){let o=Buffer.allocUnsafe(s.size),a=Ue.readSync(r,o,0,s.size,0);t.end(a===o.byteLength?o:o.subarray(0,a))}else{let o=0,a=Buffer.allocUnsafe(n);for(;o<s.size;){let h=Ue.readSync(r,a,0,n,o);if(h===0)break;o+=h,t.write(a.subarray(0,h))}t.end()}}finally{if(typeof r=="number")try{Ue.closeSync(r)}catch{}}},th=(e,t)=>{let i=new bt(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("end",n),Ue.stat(s,(a,h)=>{if(a)o(a);else{let l=new kr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},pi=Et(eh,th,e=>new bt(e),e=>new bt(e),(e,t)=>{t?.length&&ln(e,t),e.noResume||Qa(e)}),cn=(e,t,i)=>(e&=4095,i&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),{isAbsolute:rh,parse:Ps}=ih,xr=e=>{let t="",i=Ps(e);for(;rh(e)||i.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":i.root;e=e.slice(r.length),t+=r,i=Ps(e)}return[t,e]},fi=["|","<",">","?",":"],Pr=fi.map(e=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),sh=new Map(fi.map((e,t)=>[e,Pr[t]])),nh=new Map(Pr.map((e,t)=>[e,fi[t]])),Ls=e=>fi.reduce((t,i)=>t.split(i).join(sh.get(i)),e),oh=e=>Pr.reduce((t,i)=>t.split(i).join(nh.get(i)),e),dn=(e,t)=>t?(e=m(e).replace(/^\.(\/|$)/,""),ut(t)+"/"+e):m(e),ah=16*1024*1024,Ds=Symbol("process"),As=Symbol("file"),Is=Symbol("directory"),ar=Symbol("symlink"),Ns=Symbol("hardlink"),st=Symbol("header"),Xt=Symbol("read"),hr=Symbol("lstat"),Qt=Symbol("onlstat"),lr=Symbol("onread"),cr=Symbol("onreadlink"),dr=Symbol("openfile"),ur=Symbol("onopenfile"),ce=Symbol("close"),hi=Symbol("mode"),mr=Symbol("awaitDrain"),Vi=Symbol("ondrain"),V=Symbol("prefix"),un=class extends Pe{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(e,t={}){let i=_r(t);super(),this.path=m(e),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||ah,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=m(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?m(i.prefix):void 0,this.onWriteEntry=i.onWriteEntry,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let r=!1;if(!this.preservePaths){let[n,o]=xr(this.path);n&&typeof o=="string"&&(this.path=o,r=n)}this.win32=!!i.win32||process.platform==="win32",this.win32&&(this.path=oh(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=m(i.absolute||xs.resolve(this.cwd,e)),this.path===""&&(this.path="./"),r&&this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:this,path:r+this.path});let s=this.statCache.get(this.absolute);s?this[Qt](s):this[hr]()}warn(e,t,i={}){return mi(this,e,t,i)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[hr](){K.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[Qt](t)})}[Qt](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=ch(e),this.emit("stat",e),this[Ds]()}[Ds](){switch(this.type){case"File":return this[As]();case"Directory":return this[Is]();case"SymbolicLink":return this[ar]();default:return this.end()}}[hi](e){return cn(e,this.type==="Directory",this.portable)}[V](e){return dn(e,this.prefix)}[st](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new xe({path:this[V](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[V](this.linkpath):this.linkpath,mode:this[hi](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new oi({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[V](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[V](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let e=this.header?.block;if(!e)throw new Error("failed to encode header");super.write(e)}[Is](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[st](),this.end()}[ar](){K.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[cr](t)})}[cr](e){this.linkpath=m(e),this[st](),this.end()}[Ns](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=m(xs.relative(this.cwd,e)),this.stat.size=0,this[st](),this.end()}[As](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,t=this.linkCache.get(e);if(t?.indexOf(this.cwd)===0)return this[Ns](t);this.linkCache.set(e,this.absolute)}if(this[st](),this.stat.size===0)return this.end();this[dr]()}[dr](){K.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[ur](t)})}[ur](e){if(this.fd=e,this.#e)return this[ce]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let t=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(t),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Xt]()}[Xt](){let{fd:e,buf:t,offset:i,length:r,pos:s}=this;if(e===void 0||t===void 0)throw new Error("cannot read file without first opening");K.read(e,t,i,r,s,(n,o)=>{if(n)return this[ce](()=>this.emit("error",n));this[lr](o)})}[ce](e=()=>{}){this.fd!==void 0&&K.close(this.fd,e)}[lr](e){if(e<=0&&this.remain>0){let i=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ce](()=>this.emit("error",i))}if(e>this.remain){let i=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ce](()=>this.emit("error",i))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let i=e;i<this.length&&e<this.blockRemain;i++)this.buf[i+this.offset]=0,e++,this.remain++;let t=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(t)?this[Vi]():this[mr](()=>this[Vi]())}[mr](e){this.once("drain",e)}write(e,t,i){if(typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this.blockRemain<e.length){let r=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",r)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,i)}[Vi](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[ce](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Xt]()}},hh=class extends un{sync=!0;[hr](){this[Qt](K.lstatSync(this.absolute))}[ar](){this[cr](K.readlinkSync(this.absolute))}[dr](){this[ur](K.openSync(this.absolute,"r"))}[Xt](){let e=!0;try{let{fd:t,buf:i,offset:r,length:s,pos:n}=this;if(t===void 0||i===void 0)throw new Error("fd and buf must be set in READ method");let o=K.readSync(t,i,r,s,n);this[lr](o),e=!1}finally{if(e)try{this[ce](()=>{})}catch{}}}[mr](e){e()}[ce](e=()=>{}){this.fd!==void 0&&K.closeSync(this.fd),e()}},lh=class extends Pe{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(e,t,i={}){return mi(this,e,t,i)}constructor(e,t={}){let i=_r(t);super(),this.preservePaths=!!i.preservePaths,this.portable=!!i.portable,this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.onWriteEntry=i.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw new Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=i.prefix,this.path=m(e.path),this.mode=e.mode!==void 0?this[hi](e.mode):void 0,this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:i.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath!==void 0?m(e.linkpath):void 0,typeof i.onwarn=="function"&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){let[o,a]=xr(this.path);o&&typeof a=="string"&&(this.path=a,s=o)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new xe({path:this[V](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[V](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path}),this.header.encode()&&!this.noPax&&super.write(new oi({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[V](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[V](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let n=this.header?.block;if(!n)throw new Error("failed to encode header");super.write(n),e.pipe(this)}[V](e){return dn(e,this.prefix)}[hi](e){return cn(e,this.type==="Directory",this.portable)}write(e,t,i){typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8"));let r=e.length;if(r>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,i)}end(e,t,i){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(i=e,t=void 0,e=void 0),typeof t=="function"&&(i=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t??"utf8")),i&&this.once("finish",i),e?super.end(e,i):super.end(i),this}},ch=e=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",dh=class ze{tail;head;length=0;static create(t=[]){return new ze(t)}constructor(t=[]){for(let i of t)this.push(i)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");let i=t.next,r=t.prev;return i&&(i.prev=r),r&&(r.next=i),t===this.head&&(this.head=i),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,i}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let i=this.head;t.list=this,t.next=i,i&&(i.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);let i=this.tail;t.list=this,t.prev=i,i&&(i.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let i=0,r=t.length;i<r;i++)mh(this,t[i]);return this.length}unshift(...t){for(var i=0,r=t.length;i<r;i++)ph(this,t[i]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,t}forEach(t,i){i=i||this;for(let r=this.head,s=0;r;s++)t.call(i,r.value,s,this),r=r.next}forEachReverse(t,i){i=i||this;for(let r=this.tail,s=this.length-1;r;s--)t.call(i,r.value,s,this),r=r.prev}get(t){let i=0,r=this.head;for(;r&&i<t;i++)r=r.next;if(i===t&&r)return r.value}getReverse(t){let i=0,r=this.tail;for(;r&&i<t;i++)r=r.prev;if(i===t&&r)return r.value}map(t,i){i=i||this;let r=new ze;for(let s=this.head;s;)r.push(t.call(i,s.value,this)),s=s.next;return r}mapReverse(t,i){i=i||this;var r=new ze;for(let s=this.tail;s;)r.push(t.call(i,s.value,this)),s=s.prev;return r}reduce(t,i){let r,s=this.head;if(arguments.length>1)r=i;else if(this.head)s=this.head.next,r=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var n=0;s;n++)r=t(r,s.value,n),s=s.next;return r}reduceReverse(t,i){let r,s=this.tail;if(arguments.length>1)r=i;else if(this.tail)s=this.tail.prev,r=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let n=this.length-1;s;n--)r=t(r,s.value,n),s=s.prev;return r}toArray(){let t=new Array(this.length);for(let i=0,r=this.head;r;i++)t[i]=r.value,r=r.next;return t}toArrayReverse(){let t=new Array(this.length);for(let i=0,r=this.tail;r;i++)t[i]=r.value,r=r.prev;return t}slice(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new ze;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.head,n=0;for(n=0;s&&n<t;n++)s=s.next;for(;s&&n<i;n++,s=s.next)r.push(s.value);return r}sliceReverse(t=0,i=this.length){i<0&&(i+=this.length),t<0&&(t+=this.length);let r=new ze;if(i<t||i<0)return r;t<0&&(t=0),i>this.length&&(i=this.length);let s=this.length,n=this.tail;for(;n&&s>i;s--)n=n.prev;for(;n&&s>t;s--,n=n.prev)r.push(n.value);return r}splice(t,i=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let s=this.head;for(let o=0;s&&o<t;o++)s=s.next;let n=[];for(let o=0;s&&o<i;o++)n.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(let o of r)s=uh(this,s,o);return n}reverse(){let t=this.head,i=this.tail;for(let r=t;r;r=r.prev){let s=r.prev;r.prev=r.next,r.next=s}return this.head=i,this.tail=t,this}};function uh(e,t,i){let r=t,s=t?t.next:e.head,n=new Lr(i,r,s,e);return n.next===void 0&&(e.tail=n),n.prev===void 0&&(e.head=n),e.length++,n}function mh(e,t){e.tail=new Lr(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function ph(e,t){e.head=new Lr(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Lr=class{list;next;prev;value;constructor(e,t,i,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,i?(i.prev=this,this.next=i):this.next=void 0}},Ms=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},Fs=Buffer.alloc(1024),ei=Symbol("onStat"),nt=Symbol("ended"),B=Symbol("queue"),ot=Symbol("pendingLinks"),oe=Symbol("current"),ke=Symbol("process"),at=Symbol("processing"),Kt=Symbol("processJob"),$=Symbol("jobs"),Yi=Symbol("jobDone"),ti=Symbol("addFSEntry"),Bs=Symbol("addTarEntry"),pr=Symbol("stat"),fr=Symbol("readdir"),ii=Symbol("onreaddir"),ri=Symbol("pipe"),$s=Symbol("entry"),Ji=Symbol("entryOpt"),si=Symbol("writeEntryClass"),mn=Symbol("write"),qi=Symbol("ondrain"),gi=class extends Pe{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[si];onWriteEntry;[B];[ot]=new Map;[$]=0;[at]=!1;[nt]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||"",this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=m(e.prefix||""),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[si]=un,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(e.gzip&&(typeof e.gzip!="object"&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new ba(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new Sa(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new Ra(e.zstd)),!this.zip)throw new Error("impossible");let t=this.zip;t.on("data",i=>super.write(i)),t.on("end",()=>super.end()),t.on("drain",()=>this[qi]()),this.on("resume",()=>t.resume())}else this.on("drain",this[qi]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter=="function"?e.filter:()=>!0,this[B]=new dh,this[$]=0,this.jobs=Number(e.jobs)||4,this[at]=!1,this[nt]=!1}[mn](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,i){return typeof e=="function"&&(i=e,e=void 0),typeof t=="function"&&(i=t,t=void 0),e&&this.add(e),this[nt]=!0,this[ke](),i&&i(),this}write(e){if(this[nt])throw new Error("write after end");return typeof e=="string"?this[ti](e):this[Bs](e),this.flowing}[Bs](e){let t=m(Cs.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let i=new Ms(e.path,t);i.entry=new lh(e,this[Ji](i)),i.entry.on("end",()=>this[Yi](i)),this[$]+=1,this[B].push(i)}this[ke]()}[ti](e){let t=m(Cs.resolve(this.cwd,e));this[B].push(new Ms(e,t)),this[ke]()}[pr](e){e.pending=!0,this[$]+=1;let t=this.follow?"stat":"lstat";ai[t](e.absolute,(i,r)=>{e.pending=!1,this[$]-=1,i?this.emit("error",i):this[ei](e,r)})}[ei](e,t){if(this.statCache.set(e.absolute,t),e.stat=t,!this.filter(e.path,t))e.ignore=!0;else if(t.isFile()&&t.nlink>1&&!this.linkCache.get(`${t.dev}:${t.ino}`)&&!this.sync)if(e===this[oe])this[Kt](e);else{let i=`${t.dev}:${t.ino}`,r=this[ot].get(i);r?r.push(e):this[ot].set(i,[e]),e.pendingLink=!0,e.pending=!0}this[ke]()}[fr](e){e.pending=!0,this[$]+=1,ai.readdir(e.absolute,(t,i)=>{if(e.pending=!1,this[$]-=1,t)return this.emit("error",t);this[ii](e,i)})}[ii](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[ke]()}[ke](){if(!this[at]){this[at]=!0;for(let e=this[B].head;e&&this[$]<this.jobs;e=e.next)if(this[Kt](e.value),e.value.ignore){let t=e.next;this[B].removeNode(e),e.next=t}this[at]=!1,this[nt]&&this[B].length===0&&this[$]===0&&(this.zip?this.zip.end(Fs):(super.write(Fs),super.end()))}}get[oe](){return this[B]&&this[B].head&&this[B].head.value}[Yi](e){this[B].shift(),this[$]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let i=`${t.dev}:${t.ino}`,r=this[ot].get(i);if(r){this[ot].delete(i);for(let s of r)s.pending=!1,this[Kt](s)}}this[ke]()}[Kt](e){if(e.pending&&e.pendingLink&&e===this[oe]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[oe]&&!e.piped&&this[ri](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[ei](e,t):this[pr](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[ii](e,t):this[fr](e),!e.readdir)return}if(e.entry=this[$s](e),!e.entry){e.ignore=!0;return}e===this[oe]&&!e.piped&&this[ri](e)}}}[Ji](e){return{onwarn:(t,i,r)=>this.warn(t,i,r),noPax:this.noPax,cwd:this.cwd,absolute:e.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[$s](e){this[$]+=1;try{return new this[si](e.path,this[Ji](e)).on("end",()=>this[Yi](e)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[qi](){this[oe]&&this[oe].entry&&this[oe].entry.resume()}[ri](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ti](n+r)});let t=e.entry,i=this.zip;if(!t)throw new Error("cannot pipe without source");i?t.on("data",r=>{i.write(r)||t.pause()}):t.on("data",r=>{super.write(r)||t.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,t,i={}){mi(this,e,t,i)}},Dr=class extends gi{sync=!0;constructor(e){super(e),this[si]=hh}pause(){}resume(){}[pr](e){let t=this.follow?"statSync":"lstatSync";this[ei](e,ai[t](e.absolute))}[fr](e){this[ii](e,ai.readdirSync(e.absolute))}[ri](e){let t=e.entry,i=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let s=e.path,n=s==="./"?"":s.replace(/\/*$/,"/");this[ti](n+r)}),!t)throw new Error("Cannot pipe without source");i?t.on("data",r=>{i.write(r)}):t.on("data",r=>{super[mn](r)})}},fh=(e,t)=>{let i=new Dr(e),r=new Qs(e.file,{mode:e.mode||438});i.pipe(r),pn(i,t)},gh=(e,t)=>{let i=new gi(e),r=new di(e.file,{mode:e.mode||438});i.pipe(r);let s=new Promise((n,o)=>{r.on("error",o),r.on("close",n),i.on("error",o)});return fn(i,t).catch(n=>i.emit("error",n)),s},pn=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?pi({file:en.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},fn=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await pi({file:en.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>{e.add(r)}}):e.add(i);e.end()},yh=(e,t)=>{let i=new Dr(e);return pn(i,t),i},wh=(e,t)=>{let i=new gi(e);return fn(i,t).catch(r=>i.emit("error",r)),i},td=Et(fh,gh,yh,wh,(e,t)=>{if(!t?.length)throw new TypeError("no paths specified to add to archive")}),Eh=process.env.__FAKE_PLATFORM__||process.platform,bn=Eh==="win32",{O_CREAT:En,O_NOFOLLOW:Us,O_TRUNC:Sn,O_WRONLY:vn}=wn.constants,Rn=Number(process.env.__FAKE_FS_O_FILENAME__)||wn.constants.UV_FS_O_FILEMAP||0,Sh=bn&&!!Rn,vh=512*1024,Rh=Rn|Sn|En|vn,zs=!bn&&typeof Us=="number"?Us|Sn|En|vn:null,kn=zs!==null?()=>zs:Sh?e=>e<vh?Rh:"w":()=>"w",gr=(e,t,i)=>{try{return yi.lchownSync(e,t,i)}catch(r){if(r?.code!=="ENOENT")throw r}},li=(e,t,i,r)=>{yi.lchown(e,t,i,s=>{r(s&&s?.code!=="ENOENT"?s:null)})},kh=(e,t,i,r,s)=>{if(t.isDirectory())_n(mt.resolve(e,t.name),i,r,n=>{if(n)return s(n);let o=mt.resolve(e,t.name);li(o,i,r,s)});else{let n=mt.resolve(e,t.name);li(n,i,r,s)}},_n=(e,t,i,r)=>{yi.readdir(e,{withFileTypes:!0},(s,n)=>{if(s){if(s.code==="ENOENT")return r();if(s.code!=="ENOTDIR"&&s.code!=="ENOTSUP")return r(s)}if(s||!n.length)return li(e,t,i,r);let o=n.length,a=null,h=l=>{if(!a){if(l)return r(a=l);if(--o===0)return li(e,t,i,r)}};for(let l of n)kh(e,l,t,i,h)})},_h=(e,t,i,r)=>{t.isDirectory()&&On(mt.resolve(e,t.name),i,r),gr(mt.resolve(e,t.name),i,r)},On=(e,t,i)=>{let r;try{r=yi.readdirSync(e,{withFileTypes:!0})}catch(s){let n=s;if(n?.code==="ENOENT")return;if(n?.code==="ENOTDIR"||n?.code==="ENOTSUP")return gr(e,t,i);throw n}for(let s of r)_h(e,s,t,i);return gr(e,t,i)},Tn=class extends Error{path;code;syscall="chdir";constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return"CwdError"}},wi=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,t){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=t}get name(){return"SymlinkError"}},Th=(e,t)=>{N.stat(e,(i,r)=>{(i||!r.isDirectory())&&(i=new Tn(e,i?.code||"ENOTDIR")),t(i)})},xh=(e,t,i)=>{e=m(e);let r=t.umask??18,s=t.mode|448,n=(s&r)!==0,o=t.uid,a=t.gid,h=typeof o=="number"&&typeof a=="number"&&(o!==t.processUid||a!==t.processGid),l=t.preserve,c=t.unlink,u=m(t.cwd),d=(y,E)=>{y?i(y):E&&h?_n(E,o,a,vt=>d(vt)):n?N.chmod(e,s,i):i()};if(e===u)return Th(e,d);if(l)return Oh.mkdir(e,{mode:s,recursive:!0}).then(y=>d(null,y??void 0),d);let O=m(ci.relative(u,e)).split("/");yr(u,O,s,c,u,void 0,d)},yr=(e,t,i,r,s,n,o)=>{if(t.length===0)return o(null,n);let a=t.shift(),h=m(ci.resolve(e+"/"+a));N.mkdir(h,i,xn(h,t,i,r,s,n,o))},xn=(e,t,i,r,s,n,o)=>a=>{a?N.lstat(e,(h,l)=>{if(h)h.path=h.path&&m(h.path),o(h);else if(l.isDirectory())yr(e,t,i,r,s,n,o);else if(r)N.unlink(e,c=>{if(c)return o(c);N.mkdir(e,i,xn(e,t,i,r,s,n,o))});else{if(l.isSymbolicLink())return o(new wi(e,e+"/"+t.join("/")));o(a)}}):(n=n||e,yr(e,t,i,r,s,n,o))},Ph=e=>{let t=!1,i;try{t=N.statSync(e).isDirectory()}catch(r){i=r?.code}finally{if(!t)throw new Tn(e,i??"ENOTDIR")}},Lh=(e,t)=>{e=m(e);let i=t.umask??18,r=t.mode|448,s=(r&i)!==0,n=t.uid,o=t.gid,a=typeof n=="number"&&typeof o=="number"&&(n!==t.processUid||o!==t.processGid),h=t.preserve,l=t.unlink,c=m(t.cwd),u=y=>{y&&a&&On(y,n,o),s&&N.chmodSync(e,r)};if(e===c)return Ph(c),u();if(h)return u(N.mkdirSync(e,{mode:r,recursive:!0})??void 0);let d=m(ci.relative(c,e)).split("/"),O;for(let y=d.shift(),E=c;y&&(E+="/"+y);y=d.shift()){E=m(ci.resolve(E));try{N.mkdirSync(E,r),O=O||E}catch{let vt=N.lstatSync(E);if(vt.isDirectory())continue;if(l){N.unlinkSync(E),N.mkdirSync(E,r),O=O||E;continue}else if(vt.isSymbolicLink())return new wi(E,E+"/"+d.join("/"))}}return u(O)},Xi=Object.create(null),Hs=1e4,Ce=new Set,Dh=e=>{Ce.has(e)?Ce.delete(e):Xi[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),Ce.add(e);let t=Xi[e],i=Ce.size-Hs;if(i>Hs/10){for(let r of Ce)if(Ce.delete(r),delete Xi[r],--i<=0)break}return t},Ah=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ih=Ah==="win32",Nh=e=>e.split("/").slice(0,-1).reduce((t,i)=>{let r=t.at(-1);return r!==void 0&&(i=Pn(r,i)),t.push(i||"/"),t},[]),Ch=class{#e=new Map;#i=new Map;#r=new Set;reserve(e,t){e=Ih?["win32 parallelization disabled"]:e.map(r=>ut(Pn(Dh(r))));let i=new Set(e.map(r=>Nh(r)).reduce((r,s)=>r.concat(s)));this.#i.set(t,{dirs:i,paths:e});for(let r of e){let s=this.#e.get(r);s?s.push(t):this.#e.set(r,[t])}for(let r of i){let s=this.#e.get(r);if(!s)this.#e.set(r,[new Set([t])]);else{let n=s.at(-1);n instanceof Set?n.add(t):s.push(new Set([t]))}}return this.#s(t)}#n(e){let t=this.#i.get(e);if(!t)throw new Error("function does not have any path reservations");return{paths:t.paths.map(i=>this.#e.get(i)),dirs:[...t.dirs].map(i=>this.#e.get(i))}}check(e){let{paths:t,dirs:i}=this.#n(e);return t.every(r=>r&&r[0]===e)&&i.every(r=>r&&r[0]instanceof Set&&r[0].has(e))}#s(e){return this.#r.has(e)||!this.check(e)?!1:(this.#r.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#r.has(e))return!1;let t=this.#i.get(e);if(!t)throw new Error("invalid reservation");let{paths:i,dirs:r}=t,s=new Set;for(let n of i){let o=this.#e.get(n);if(!o||o?.[0]!==e)continue;let a=o[1];if(!a){this.#e.delete(n);continue}if(o.shift(),typeof a=="function")s.add(a);else for(let h of a)s.add(h)}for(let n of r){let o=this.#e.get(n),a=o?.[0];if(!(!o||!(a instanceof Set)))if(a.size===1&&o.length===1){this.#e.delete(n);continue}else if(a.size===1){o.shift();let h=o[0];typeof h=="function"&&s.add(h)}else a.delete(e)}return this.#r.delete(e),s.forEach(n=>this.#s(n)),!0}},Mh=()=>process.umask(),js=Symbol("onEntry"),wr=Symbol("checkFs"),Ws=Symbol("checkFs2"),br=Symbol("isReusable"),M=Symbol("makeFs"),Er=Symbol("file"),Sr=Symbol("directory"),ni=Symbol("link"),Gs=Symbol("symlink"),Zs=Symbol("hardlink"),ct=Symbol("ensureNoSymlink"),Ks=Symbol("unsupported"),Vs=Symbol("checkPath"),Qi=Symbol("stripAbsolutePath"),de=Symbol("mkdir"),_=Symbol("onError"),Vt=Symbol("pending"),Ys=Symbol("pend"),Me=Symbol("unpend"),er=Symbol("ended"),tr=Symbol("maybeClose"),vr=Symbol("skip"),pt=Symbol("doChown"),ft=Symbol("uid"),gt=Symbol("gid"),yt=Symbol("checkedCwd"),Fh=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,wt=Fh==="win32",Bh=1024,$h=(e,t)=>{if(!wt)return p.unlink(e,t);let i=e+".DELETE."+yn(16).toString("hex");p.rename(e,i,r=>{if(r)return t(r);p.unlink(i,t)})},Uh=e=>{if(!wt)return p.unlinkSync(e);let t=e+".DELETE."+yn(16).toString("hex");p.renameSync(e,t),p.unlinkSync(t)},Js=(e,t,i)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:i,Ar=class extends bt{[er]=!1;[yt]=!1;[Vt]=0;reservations=new Ch;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(e={}){if(e.ondone=()=>{this[er]=!0,this[tr]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid=="number"||typeof e.gid=="number"){if(typeof e.uid!="number"||typeof e.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=e.preserveOwner===void 0&&typeof e.uid!="number"?process.getuid?.()===0:!!e.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:Bh,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||wt,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=m(S.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:Mh():0,this.umask=typeof e.umask=="number"?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on("entry",t=>this[js](t))}warn(e,t,i={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(i.recoverable=!1),super.warn(e,t,i)}[tr](){this[er]&&this[Vt]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Qi](e,t){let i=e[t],{type:r}=e;if(!i||this.preservePaths)return!0;let[s,n]=xr(i),o=n.replaceAll(/\\/g,"/").split("/");if(o.includes("..")||wt&&/^[a-z]:\.\.$/i.test(o[0]??"")){if(t==="path"||r==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:i}),!1;let a=S.posix.dirname(e.path),h=S.posix.normalize(S.posix.join(a,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:i}),!1}return s&&(e[t]=String(n),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute ${t}`,{entry:e,[t]:i})),!0}[Vs](e){let t=m(e.path),i=t.split("/");if(this.strip){if(i.length<this.strip)return!1;if(e.type==="Link"){let r=m(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}i.splice(0,this.strip),e.path=i.join("/")}if(isFinite(this.maxDepth)&&i.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:i.length,maxDepth:this.maxDepth}),!1;if(!this[Qi](e,"path")||!this[Qi](e,"linkpath"))return!1;if(e.absolute=S.isAbsolute(e.path)?m(S.resolve(e.path)):m(S.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute=="string"&&e.absolute.indexOf(this.cwd+"/")!==0&&e.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:m(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!=="Directory"&&e.type!=="GNUDumpDir")return!1;if(this.win32){let{root:r}=S.win32.parse(String(e.absolute));e.absolute=r+Ls(String(e.absolute).slice(r.length));let{root:s}=S.win32.parse(e.path);e.path=s+Ls(e.path.slice(s.length))}return!0}[js](e){if(!this[Vs](e))return e.resume();switch(bh.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[wr](e);default:return this[Ks](e)}}[_](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[Me](),t.resume())}[de](e,t,i){xh(m(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:t},i)}[pt](e){return this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[ft](e){return Js(this.uid,e.uid,this.processUid)}[gt](e){return Js(this.gid,e.gid,this.processGid)}[Er](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new di(String(e.absolute),{flags:kn(e.size),mode:i,autoClose:!1});r.on("error",a=>{r.fd&&p.close(r.fd,()=>{}),r.write=()=>!0,this[_](a,e),t()});let s=1,n=a=>{if(a){r.fd&&p.close(r.fd,()=>{}),this[_](a,e),t();return}--s===0&&r.fd!==void 0&&p.close(r.fd,h=>{h?this[_](h,e):this[Me](),t()})};r.on("finish",()=>{let a=String(e.absolute),h=r.fd;if(typeof h=="number"&&e.mtime&&!this.noMtime){s++;let l=e.atime||new Date,c=e.mtime;p.futimes(h,l,c,u=>u?p.utimes(a,l,c,d=>n(d&&u)):n())}if(typeof h=="number"&&this[pt](e)){s++;let l=this[ft](e),c=this[gt](e);typeof l=="number"&&typeof c=="number"&&p.fchown(h,l,c,u=>u?p.chown(a,l,c,d=>n(d&&u)):n())}n()});let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",a=>{this[_](a,e),t()}),e.pipe(o)),o.pipe(r)}[Sr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode;this[de](String(e.absolute),i,r=>{if(r){this[_](r,e),t();return}let s=1,n=()=>{--s===0&&(t(),this[Me](),e.resume())};e.mtime&&!this.noMtime&&(s++,p.utimes(String(e.absolute),e.atime||new Date,e.mtime,n)),this[pt](e)&&(s++,p.chown(String(e.absolute),Number(this[ft](e)),Number(this[gt](e)),n)),n()})}[Ks](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[Gs](e,t){let i=m(S.relative(this.cwd,S.resolve(S.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[ct](e,this.cwd,i,()=>this[ni](e,String(e.linkpath),"symlink",t),r=>{this[_](r,e),t()})}[Zs](e,t){let i=m(S.resolve(this.cwd,String(e.linkpath))),r=m(String(e.linkpath)).split("/");this[ct](e,this.cwd,r,()=>this[ni](e,i,"link",t),s=>{this[_](s,e),t()})}[ct](e,t,i,r,s){let n=i.shift();if(this.preservePaths||n===void 0)return r();let o=S.resolve(t,n);p.lstat(o,(a,h)=>{if(a)return r();if(h?.isSymbolicLink())return s(new wi(o,S.resolve(o,i.join("/"))));this[ct](e,o,i,r,s)})}[Ys](){this[Vt]++}[Me](){this[Vt]--,this[tr]()}[vr](e){this[Me](),e.resume()}[br](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!wt}[wr](e){this[Ys]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,i=>this[Ws](e,i))}[Ws](e,t){let i=o=>{t(o)},r=()=>{this[de](this.cwd,this.dmode,o=>{if(o){this[_](o,e),i();return}this[yt]=!0,s()})},s=()=>{if(e.absolute!==this.cwd){let o=m(S.dirname(String(e.absolute)));if(o!==this.cwd)return this[de](o,this.dmode,a=>{if(a){this[_](a,e),i();return}n()})}n()},n=()=>{p.lstat(String(e.absolute),(o,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[vr](e),i();return}if(o||this[br](e,a))return this[M](null,e,i);if(a.isDirectory()){if(e.type==="Directory"){let h=this.chmod&&e.mode&&(a.mode&4095)!==e.mode,l=c=>this[M](c??null,e,i);return h?p.chmod(String(e.absolute),Number(e.mode),l):l()}if(e.absolute!==this.cwd)return p.rmdir(String(e.absolute),h=>this[M](h??null,e,i))}if(e.absolute===this.cwd)return this[M](null,e,i);$h(String(e.absolute),h=>this[M](h??null,e,i))})};this[yt]?s():r()}[M](e,t,i){if(e){this[_](e,t),i();return}switch(t.type){case"File":case"OldFile":case"ContiguousFile":return this[Er](t,i);case"Link":return this[Zs](t,i);case"SymbolicLink":return this[Gs](t,i);case"Directory":case"GNUDumpDir":return this[Sr](t,i)}}[ni](e,t,i,r){p[i](t,String(e.absolute),s=>{s?this[_](s,e):(this[Me](),e.resume()),r()})}},ht=e=>{try{return[null,e()]}catch(t){return[t,null]}},Ln=class extends Ar{sync=!0;[M](e,t){return super[M](e,t,()=>{})}[wr](e){if(!this[yt]){let s=this[de](this.cwd,this.dmode);if(s)return this[_](s,e);this[yt]=!0}if(e.absolute!==this.cwd){let s=m(S.dirname(String(e.absolute)));if(s!==this.cwd){let n=this[de](s,this.dmode);if(n)return this[_](n,e)}}let[t,i]=ht(()=>p.lstatSync(String(e.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(e.mtime??i.mtime)))return this[vr](e);if(t||this[br](e,i))return this[M](null,e);if(i.isDirectory()){if(e.type==="Directory"){let n=this.chmod&&e.mode&&(i.mode&4095)!==e.mode,[o]=n?ht(()=>{p.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[M](o,e)}let[s]=ht(()=>p.rmdirSync(String(e.absolute)));this[M](s,e)}let[r]=e.absolute===this.cwd?[]:ht(()=>Uh(String(e.absolute)));this[M](r,e)}[Er](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.fmode,r=o=>{let a;try{p.closeSync(s)}catch(h){a=h}(o||a)&&this[_](o||a,e),t()},s;try{s=p.openSync(String(e.absolute),kn(e.size),i)}catch(o){return r(o)}let n=this.transform&&this.transform(e)||e;n!==e&&(n.on("error",o=>this[_](o,e)),e.pipe(n)),n.on("data",o=>{try{p.writeSync(s,o,0,o.length)}catch(a){r(a)}}),n.on("end",()=>{let o=null;if(e.mtime&&!this.noMtime){let a=e.atime||new Date,h=e.mtime;try{p.futimesSync(s,a,h)}catch(l){try{p.utimesSync(String(e.absolute),a,h)}catch{o=l}}}if(this[pt](e)){let a=this[ft](e),h=this[gt](e);try{p.fchownSync(s,Number(a),Number(h))}catch(l){try{p.chownSync(String(e.absolute),Number(a),Number(h))}catch{o=o||l}}}r(o)})}[Sr](e,t){let i=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[de](String(e.absolute),i);if(r){this[_](r,e),t();return}if(e.mtime&&!this.noMtime)try{p.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[pt](e))try{p.chownSync(String(e.absolute),Number(this[ft](e)),Number(this[gt](e)))}catch{}t(),e.resume()}[de](e,t){try{return Lh(m(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:t})}catch(i){return i}}[ct](e,t,i,r,s){if(this.preservePaths||i.length===0)return r();let n=t;for(let o of i){n=S.resolve(n,o);let[a,h]=ht(()=>p.lstatSync(n));if(a)return r();if(h.isSymbolicLink())return s(new wi(n,S.resolve(t,i.join("/"))))}r()}[ni](e,t,i,r){let s=`${i}Sync`;try{p[s](t,String(e.absolute)),r(),e.resume()}catch(n){return this[_](n,e)}}},zh=e=>{let t=new Ln(e),i=e.file,r=gn.statSync(i),s=e.maxReadSize||16*1024*1024;new sa(i,{readSize:s,size:r.size}).pipe(t)},Hh=(e,t)=>{let i=new Ar(e),r=e.maxReadSize||16*1024*1024,s=e.file;return new Promise((n,o)=>{i.on("error",o),i.on("close",n),gn.stat(s,(a,h)=>{if(a)o(a);else{let l=new kr(s,{readSize:r,size:h.size});l.on("error",o),l.pipe(i)}})})},Dn=Et(zh,Hh,e=>new Ln(e),e=>new Ar(e),(e,t)=>{t?.length&&ln(e,t)}),jh=(e,t)=>{let i=new Dr(e),r=!0,s,n;try{try{s=I.openSync(e.file,"r+")}catch(h){if(h?.code==="ENOENT")s=I.openSync(e.file,"w+");else throw h}let o=I.fstatSync(s),a=Buffer.alloc(512);e:for(n=0;n<o.size;n+=512){for(let c=0,u=0;c<512;c+=u){if(u=I.readSync(s,a,c,a.length-c,n+c),n===0&&a[0]===31&&a[1]===139)throw new Error("cannot append to compressed archives");if(!u)break e}let h=new xe(a);if(!h.cksumValid)break;let l=512*Math.ceil((h.size||0)/512);if(n+l+512>o.size)break;n+=l,e.mtimeCache&&h.mtime&&e.mtimeCache.set(String(h.path),h.mtime)}r=!1,Wh(e,i,n,s,t)}finally{if(r)try{I.closeSync(s)}catch{}}},Wh=(e,t,i,r,s)=>{let n=new Qs(e.file,{fd:r,start:i});t.pipe(n),Zh(t,s)},Gh=(e,t)=>{t=Array.from(t);let i=new gi(e),r=(s,n,o)=>{let a=(d,O)=>{d?I.close(s,y=>o(d)):o(null,O)},h=0;if(n===0)return a(null,0);let l=0,c=Buffer.alloc(512),u=(d,O)=>{if(d||O===void 0)return a(d);if(l+=O,l<512&&O)return I.read(s,c,l,c.length-l,h+l,u);if(h===0&&c[0]===31&&c[1]===139)return a(new Error("cannot append to compressed archives"));if(l<512)return a(null,h);let y=new xe(c);if(!y.cksumValid)return a(null,h);let E=512*Math.ceil((y.size??0)/512);if(h+E+512>n||(h+=E+512,h>=n))return a(null,h);e.mtimeCache&&y.mtime&&e.mtimeCache.set(String(y.path),y.mtime),l=0,I.read(s,c,0,512,h,u)};I.read(s,c,0,512,h,u)};return new Promise((s,n)=>{i.on("error",n);let o="r+",a=(h,l)=>{if(h&&h.code==="ENOENT"&&o==="r+")return o="w+",I.open(e.file,o,a);if(h||!l)return n(h);I.fstat(l,(c,u)=>{if(c)return I.close(l,()=>n(c));r(l,u.size,(d,O)=>{if(d)return n(d);let y=new di(e.file,{fd:l,start:O});i.pipe(y),y.on("error",n),y.on("close",s),Kh(i,t)})})};I.open(e.file,o,a)})},Zh=(e,t)=>{t.forEach(i=>{i.charAt(0)==="@"?pi({file:An.resolve(e.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i)}),e.end()},Kh=async(e,t)=>{for(let i of t)i.charAt(0)==="@"?await pi({file:An.resolve(String(e.cwd),i.slice(1)),noResume:!0,onReadEntry:r=>e.add(r)}):e.add(i);e.end()},lt=Et(jh,Gh,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(e,t)=>{if(!ua(e))throw new TypeError("file is required");if(e.gzip||e.brotli||e.zstd||e.file.endsWith(".br")||e.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!t?.length)throw new TypeError("no paths specified to add/replace")}),gd=Et(lt.syncFile,lt.asyncFile,lt.syncNoFile,lt.asyncNoFile,(e,t=[])=>{lt.validate?.(e,t),Vh(e)}),Vh=e=>{let t=e.filter;e.mtimeCache||(e.mtimeCache=new Map),e.filter=t?(i,r)=>t(i,r)&&!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0)):(i,r)=>!((e.mtimeCache?.get(i)??r.mtime??0)>(r.mtime??0))};var St=De("taco.cli.upgrade"),el="https://registry.npmjs.org",Nn=3e4;async function tl(e,t,i,r){let s=i==="latest"?`${e}/${t}/latest`:`${e}/${t}/${i}`,n=new AbortController,o=setTimeout(()=>n.abort(),Nn);try{let a=await r(s,{signal:n.signal});if(!a.ok)throw new Error(`registry returned ${a.status} ${a.statusText} for ${t}@${i}`);return await a.json()}finally{clearTimeout(o)}}async function il(e,t,i){let r=new AbortController,s=setTimeout(()=>r.abort(),Nn);try{let n=await i(e,{signal:r.signal});if(!n.ok)throw new Error(`tarball download ${n.status} ${n.statusText} for ${e}`);if(!n.body)throw new Error(`tarball response had no body for ${e}`);await Ir(In(t),{recursive:!0});let o=await qh(t,"w");try{let a=0,h=n.body.getReader();for(;;){let{done:l,value:c}=await h.read();if(l)break;await o.write(c),a+=c.byteLength}return a}finally{await o.close()}}finally{clearTimeout(s)}}async function rl(e,t){let[i,r]=t.split("-");if(i!=="sha512")throw new Error(`unsupported integrity algorithm: ${i}`);let s=Yh("sha512");await new Promise((o,a)=>{let h=Jh(e);h.on("data",l=>s.update(l)),h.on("end",()=>o()),h.on("error",a)});let n=s.digest("base64");if(n!==r)throw new Error(`integrity mismatch: expected ${r}, got ${n}`)}async function Cn(e={}){let t=e.fetcher??globalThis.fetch;if(typeof t!="function")throw new Error("global fetch is not available; pass opts.fetcher explicitly");let i=e.tacoHome??T,r=e.registry??el,s=e.platformKey?{key:e.platformKey,pkg:`@taco-ai/sidecar-${e.platformKey}`}:Nr(),n=e.version??"latest";St.info(`fetching metadata for ${s.pkg}@${n}`);let o=await tl(r,s.pkg,n,t);if(!o.dist?.tarball||!o.dist?.integrity)throw new Error(`registry response missing dist.tarball/integrity for ${s.pkg}@${n}`);let a=o.version,h=bi(i,"staging",`sidecar-${s.key}-${a}`),l=bi(i,"cache","sidecar",`sidecar-${s.key}-${a}.tgz`);St.info(`downloading tarball \u2192 ${l}`),await Ir(In(l),{recursive:!0}),await il(o.dist.tarball,l,t),St.info("verifying integrity"),await rl(l,o.dist.integrity),await Xh(h,{recursive:!0,force:!0}),await Ir(h,{recursive:!0}),St.info(`extracting \u2192 ${h}`),await Dn({file:l,cwd:h,strip:1}),await sl(h);let c=e.liveDirOverride??await nl(s.key);if(!c)throw new Error(`no current @taco-ai/sidecar-${s.key} install found; run 'taco install' first`);let u={version:a,staging_dir:h,live_dir:c,written_at:new Date().toISOString()},d=bi(i,"upgrade-marker.json");return await Xr(d,u),St.info(`upgrade staged \u2192 version=${a}, marker=${d}`),{version:a,stagingDir:h,liveDir:c}}async function sl(e){for(let t of["manifest.json","bin","lib"]){let i=bi(e,t);try{await Qh(i)}catch{throw new Error(`staged bundle missing ${t} at ${i}`)}}}async function nl(e){let{createRequire:t}=await import("node:module"),i=t(import.meta.url);try{let r=i.resolve(`@taco-ai/sidecar-${e}/package.json`),s=r.lastIndexOf("/package.json");return s<0?r:r.slice(0,s)}catch{return null}}var Mn=`taco \u2014 launcher + supervisor for the sidecar daemon
86
88
 
87
89
  Usage:
88
90
  taco start Spawn the daemon; prints its NDJSON socket path.
@@ -98,7 +100,7 @@ Environment:
98
100
  TACO_HOME Root directory for daemon state (default ~/.taco).
99
101
  TACO_SIDECAR_DEV=1 Force dev launcher (tsx + repo source) even when a
100
102
  @taco-ai/sidecar-<platform> bundle is installed.
101
- `;async function nl(e){let t=e[2];switch(t){case"start":return await as(),0;case"status":return await ls(),0;case"stop":return await us(),0;case"install":return await jr(),0;case"uninstall":return await fs(),0;case"upgrade":return e.includes("--apply")?await Dt():await Cn(),0;case"help":case"--help":case"-h":case void 0:return process.stdout.write(Mn),0;default:return process.stderr.write(`unknown subcommand: ${t}
103
+ `;async function ol(e){let t=e[2];switch(t){case"start":return await as(),0;case"status":return await ls(),0;case"stop":return await us(),0;case"install":return await jr(),0;case"uninstall":return await fs(),0;case"upgrade":return e.includes("--apply")?await Dt():await Cn(),0;case"help":case"--help":case"-h":case void 0:return process.stdout.write(Mn),0;default:return process.stderr.write(`unknown subcommand: ${t}
102
104
 
103
- ${Mn}`),1}}var ol=(()=>{try{let e=process.argv[1];if(!e)return!1;let t=new URL(`file://${e}`).href;return import.meta.url===t}catch{return!1}})();ol&&nl(process.argv).then(e=>process.exit(e??0),e=>{process.stderr.write(`[taco] error: ${e?.stack??e}
104
- `),process.exit(1)});export{nl as run};
105
+ ${Mn}`),1}}var al=(()=>{try{let e=process.argv[1];if(!e)return!1;let t=new URL(`file://${e}`).href;return import.meta.url===t}catch{return!1}})();al&&ol(process.argv).then(e=>process.exit(e??0),e=>{process.stderr.write(`[taco] error: ${e?.stack??e}
106
+ `),process.exit(1)});export{ol as run};
package/lib/start.ts CHANGED
@@ -51,38 +51,76 @@ const KILL_GRACE_MS = 3_000;
51
51
  /** Result of probing the NDJSON socket for a live, serving daemon. */
52
52
  type DaemonProbe = "ready" | "absent" | "wedged";
53
53
 
54
- /** True readiness probe: connect to the NDJSON socket and wait for the
55
- * daemon's one-shot `sidecar.hello` frame. A bare TCP connect is NOT a
56
- * valid probe — the kernel completes connections from the listen backlog
57
- * even when the daemon's event loop is wedged, and the control socket is
58
- * bound early in boot (long before the NDJSON listener exists), so both
59
- * older probes reported "ready" against daemons that couldn't serve a
60
- * single frame. The desktop then timed out waiting for a hello that was
61
- * never going to come.
54
+ /** Protocol version this CLI advertises in its probe initialize request.
55
+ * Duplicates @taco-ai/protocol's SIDECAR_PROTOCOL_VERSION because the probe
56
+ * must stay self-contained (see probeDaemonInitialize). An incompatible
57
+ * version still gets an error response, which proves liveness — bump in
58
+ * lockstep when the major changes. */
59
+ const PROBE_PROTOCOL_VERSION = { major: 2, minor: 0 };
60
+
61
+ /** True readiness probe: connect to the NDJSON socket, send a literal
62
+ * `initialize` request, and wait for its RPC response. A bare TCP connect
63
+ * is NOT a valid probe — the kernel completes connections from the listen
64
+ * backlog even when the daemon's event loop is wedged, and the control
65
+ * socket is bound early in boot (long before the NDJSON listener exists),
66
+ * so both older probes reported "ready" against daemons that couldn't
67
+ * serve a single frame.
62
68
  *
63
69
  * Deliberately self-contained rather than imported from the sidecar: the
64
70
  * CLI does not depend on sidecar TS source (only the bundled platform pkg
65
- * ships at runtime). Same reasoning as the note atop `upgradeMarker.ts`. */
66
- function probeDaemonHello(path: string, timeoutMs = 5_000): Promise<DaemonProbe> {
71
+ * ships at runtime). Same reasoning as the note atop `upgradeMarker.ts`.
72
+ * The frame duplicates the wire format in @taco-ai/protocol; keep the
73
+ * shape in sync when RpcRequest / InitializeRpcParams change. */
74
+ function probeDaemonInitialize(path: string, timeoutMs = 5_000): Promise<DaemonProbe> {
67
75
  return new Promise((resolve) => {
68
76
  const sock: Socket = connect(path);
69
77
  let buf = "";
78
+ let settled = false;
70
79
  const timer = setTimeout(() => finish("wedged"), timeoutMs);
71
80
  function finish(result: DaemonProbe): void {
81
+ if (settled) return;
82
+ settled = true;
72
83
  clearTimeout(timer);
73
84
  sock.destroy();
74
85
  resolve(result);
75
86
  }
87
+ sock.on("connect", () => {
88
+ const req = {
89
+ id: "probe",
90
+ commandId: "probe",
91
+ method: "initialize",
92
+ params: {
93
+ protocolVersion: PROBE_PROTOCOL_VERSION,
94
+ clientCapabilities: {},
95
+ },
96
+ };
97
+ sock.write(`${JSON.stringify(req)}\n`);
98
+ });
76
99
  sock.on("data", (chunk) => {
77
100
  buf += chunk.toString("utf8");
78
- const nl = buf.indexOf("\n");
79
- if (nl === -1) return;
80
- try {
81
- const frame = JSON.parse(buf.slice(0, nl)) as { method?: unknown };
82
- finish(frame.method === "sidecar.hello" ? "ready" : "wedged");
83
- } catch {
84
- finish("wedged");
101
+ // Drain every newline-terminated frame: a healthy daemon may push
102
+ // `session.*` / IM / channel frames ahead of the probe's RPC
103
+ // response (push fan-out to late-attaching connections), and the
104
+ // probe must not mistake those for an unresponsive event loop.
105
+ // Only the response carrying id === "probe" + ok:boolean settles.
106
+ let nl = buf.indexOf("\n");
107
+ while (nl !== -1) {
108
+ const line = buf.slice(0, nl);
109
+ buf = buf.slice(nl + 1);
110
+ let frame: { id?: unknown; ok?: unknown };
111
+ try {
112
+ frame = JSON.parse(line) as { id?: unknown; ok?: unknown };
113
+ } catch {
114
+ continue;
115
+ }
116
+ if (typeof frame.id !== "string" || typeof frame.ok !== "boolean") continue;
117
+ // Any RPC response (success or error) means the event loop
118
+ // reached our request and answered — the daemon is alive and
119
+ // serving frames, regardless of protocol-version outcome.
120
+ finish("ready");
121
+ return;
85
122
  }
123
+ nl = buf.indexOf("\n");
86
124
  });
87
125
  sock.once("error", () => finish("absent"));
88
126
  });
@@ -269,16 +307,16 @@ export async function startCommand(opts: StartOptions = {}): Promise<void> {
269
307
 
270
308
  // Fast path: a healthy daemon already owns this runtime directory. The desktop
271
309
  // reaches `taco start` from more than one place, so this is the common
272
- // case, not an edge case. The probe reads the NDJSON hello rather than
273
- // touching the control socket, which is bound long before the daemon
274
- // can serve (see probeDaemonHello).
275
- let probe = await probeDaemonHello(socket);
310
+ // case, not an edge case. The probe exchanges an initialize request over
311
+ // the NDJSON socket rather than touching the control socket, which is
312
+ // bound long before the daemon can serve (see probeDaemonInitialize).
313
+ let probe = await probeDaemonInitialize(socket);
276
314
  if (probe === "wedged") {
277
315
  // A daemon mid-initialization or serving a burst of connections can
278
316
  // miss one probe. Killing on a single miss turned slow boots into a
279
317
  // kill/restart loop, so re-probe once before declaring it wedged.
280
318
  await new Promise((r) => setTimeout(r, 500));
281
- probe = await probeDaemonHello(socket);
319
+ probe = await probeDaemonInitialize(socket);
282
320
  }
283
321
  if (probe === "ready") {
284
322
  process.stdout.write(`${socket}\n`);
@@ -286,10 +324,11 @@ export async function startCommand(opts: StartOptions = {}): Promise<void> {
286
324
  return;
287
325
  }
288
326
  if (probe === "wedged") {
289
- // The socket answers connects but no hello arrives across two probes —
290
- // the daemon is alive at the kernel level and dead at the application
291
- // level. Reap it and fall through to a fresh spawn, or every launch
292
- // from here on would attach to the same unresponsive process.
327
+ // The socket answers connects but no RPC response arrives across two
328
+ // probes — the daemon is alive at the kernel level and dead at the
329
+ // application level. Reap it and fall through to a fresh spawn, or
330
+ // every launch from here on would attach to the same unresponsive
331
+ // process.
293
332
  process.stderr.write(
294
333
  "[taco] sidecar daemon accepts connections but does not serve; killing it\n",
295
334
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taco-ai/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "Taco CLI — launcher + daemon supervisor for the sidecar. Wraps @taco-ai/sidecar with user-facing subcommands (start, status, install, upgrade).",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "tar": "^7.4.3",
25
- "@taco-ai/sidecar": "0.1.1"
25
+ "@taco-ai/sidecar": "0.1.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.7.0",