clawdi 0.14.79 → 0.14.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import{createRequire as Pbe}from"node:module";var vbe=Object.create;var{getProto
|
|
|
4
4
|
`,"ascii"),pS=dS("sha256").update(Ube).digest("hex")});import Hbe from"events";import Kr from"fs";import{EventEmitter as oO}from"node:events";import u9 from"node:stream";import{StringDecoder as Bbe}from"node:string_decoder";import m9 from"node:path";import Cp from"node:fs";import{dirname as nSe,parse as rSe}from"path";import{EventEmitter as dSe}from"events";import FI from"assert";import{Buffer as mu}from"buffer";import*as DW from"zlib";import pSe from"zlib";import{posix as bp}from"node:path";import{basename as FSe}from"node:path";import FS from"fs";import bs from"fs";import zW from"path";import{win32 as QSe}from"node:path";import GW from"path";import P9 from"node:fs";import hke from"node:assert";import{randomBytes as C9}from"node:crypto";import Ke from"node:fs";import Pn from"node:path";import $9 from"fs";import JS from"node:fs";import $h from"node:path";import Ai from"node:fs";import kke from"node:fs/promises";import BS from"node:path";import{join as F9}from"node:path";import ki from"node:fs";import H9 from"node:path";function cke(e,t,n){let r=t,i=t?t.next:e.head,o=new pO(n,r,i,e);return o.next===void 0&&(e.tail=o),o.prev===void 0&&(e.head=o),e.length++,o}function uke(e,t){e.tail=new pO(t,e.tail,void 0,e),e.head||(e.head=e.tail),e.length++}function dke(e,t){e.head=new pO(t,void 0,e.head,e),e.tail||(e.tail=e.head),e.length++}var Fbe,zbe=(e,t)=>{for(var n in t)Fbe(e,n,{get:t[n],enumerable:!0})},$W,Vbe=(e)=>!!e&&typeof e=="object"&&(e instanceof hu||e instanceof u9||qbe(e)||Wbe(e)),qbe=(e)=>!!e&&typeof e=="object"&&e instanceof oO&&typeof e.pipe=="function"&&e.pipe!==u9.Writable.prototype.pipe,Wbe=(e)=>!!e&&typeof e=="object"&&e instanceof oO&&typeof e.write=="function"&&typeof e.end=="function",pa,ma,yl,mS,dh,fS,xW,gS,IW,Ro,_p,jn,ph,Ep,Nn,Rr,Mn,dI,hS,fr,mn,pI,mI,OW,fI,ys,gI,yS,mh,iu,Si,fh=(e)=>Promise.resolve().then(e),Kbe=(e)=>e(),Gbe=(e)=>e==="end"||e==="finish"||e==="prefinish",Jbe=(e)=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,Zbe=(e)=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),d9=class{src;dest;opts;ondrain;constructor(e,t,n){this.src=e,this.dest=t,this.opts=n,this.ondrain=()=>e[Ep](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Ybe,Xbe=(e)=>!!e.objectMode,Qbe=(e)=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer",hu,eSe,Rl,xo,gh,mt,hI,ya,yI,LI,UI,Ph,vS,$p,xp,vI,Rp,Pl,$o,bl,vs,Pp,wI,ha,hh,_I,CS,ou,$S,pu,sO,tSe,VS,p9,iSe,oSe=(e)=>!!e.sync&&!!e.file,sSe=(e)=>!e.sync&&!!e.file,aSe=(e)=>!!e.sync&&!e.file,lSe=(e)=>!e.sync&&!e.file,cSe=(e)=>!!e.file,uSe=(e)=>iSe.get(e)||e,aO=(e={})=>{if(!e)return{};let t={};for(let[n,r]of Object.entries(e)){let i=uSe(n);t[i]=r}return t.chmod===void 0&&t.noChmod===!1&&(t.chmod=!0),delete t.noChmod,t},Nh=(e,t,n,r,i)=>Object.assign((o=[],s,a)=>{Array.isArray(o)&&(s=o,o={}),typeof s=="function"&&(a=s,s=void 0),s=s?Array.from(s):[];let l=aO(o);if(i?.(l,s),oSe(l)){if(typeof a=="function")throw TypeError("callback not supported for sync tar functions");return e(l,s)}else if(sSe(l)){let c=t(l,s);return a?c.then(()=>a(),a):c}else if(aSe(l)){if(typeof a=="function")throw TypeError("callback not supported for sync tar functions");return n(l,s)}else if(lSe(l)){if(typeof a=="function")throw TypeError("callback only supported with file option");return r(l,s)}throw Error("impossible options??")},{syncFile:e,asyncFile:t,syncNoFile:n,asyncNoFile:r,validate:i}),mSe,ks,fSe,TW,gSe=(e)=>e,bI,fu,wS,SI,lO,f9,hSe,ySe,g9,vSe,wSe,h9,_Se,bSe,SSe=(e,t)=>{if(Number.isSafeInteger(e))e<0?ASe(e,t):kSe(e,t);else throw Error("cannot encode number outside of javascript safe integer range");return t},kSe=(e,t)=>{t[0]=128;for(var n=t.length;n>1;n--)t[n-1]=e&255,e=Math.floor(e/256)},ASe=(e,t)=>{t[0]=255;var n=!1;e=e*-1;for(var r=t.length;r>1;r--){var i=e&255;e=Math.floor(e/256),n?t[r-1]=y9(i):i===0?t[r-1]=0:(n=!0,t[r-1]=v9(i))}},ESe=(e)=>{let t=e[0],n=t===128?PSe(e.subarray(1,e.length)):t===255?RSe(e):null;if(n===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(n))throw Error("parsed number outside of javascript safe integer range");return n},RSe=(e)=>{for(var t=e.length,n=0,r=!1,i=t-1;i>-1;i--){var o=Number(e[i]),s;r?s=y9(o):o===0?s=o:(r=!0,s=v9(o)),s!==0&&(n-=s*Math.pow(256,t-i-1))}return n},PSe=(e)=>{for(var t=e.length,n=0,r=t-1;r>-1;r--){var i=Number(e[r]);i!==0&&(n+=i*Math.pow(256,t-r-1))}return n},y9=(e)=>(255^e)&255,v9=(e)=>(255^e)+1&255,CSe,xS=(e)=>qS.has(e),$Se=(e)=>cO.has(e),w9,qS,cO,xSe=(e)=>e===void 0||e<0?void 0:e,gu=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,n,r){Buffer.isBuffer(e)?this.decode(e,t||0,n,r):e&&this.#n(e)}decode(e,t,n,r){if(t||(t=0),!e||!(e.length>=t+512))throw Error("need 512 bytes for header");let i=su(e,t+156,1),o=w9.has(i),s=o?n:void 0,a=o?r:void 0;if(this.path=s?.path??su(e,t,100),this.mode=s?.mode??a?.mode??Sl(e,t+100,8),this.uid=s?.uid??a?.uid??Sl(e,t+108,8),this.gid=s?.gid??a?.gid??Sl(e,t+116,8),this.size=xSe(s?.size??a?.size??Sl(e,t+124,12)),this.mtime=s?.mtime??a?.mtime??kI(e,t+136,12),this.cksum=Sl(e,t+148,12),a&&this.#n(a,!0),s&&this.#n(s),xS(i)&&(this.#e=i||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=su(e,t+157,100),e.subarray(t+257,t+265).toString()==="ustar\x0000")if(this.uname=s?.uname??a?.uname??su(e,t+265,32),this.gname=s?.gname??a?.gname??su(e,t+297,32),this.devmaj=s?.devmaj??a?.devmaj??Sl(e,t+329,8)??0,this.devmin=s?.devmin??a?.devmin??Sl(e,t+337,8)??0,e[t+475]!==0){let c=su(e,t+345,155);this.path=c+"/"+this.path}else{let c=su(e,t+345,130);c&&(this.path=c+"/"+this.path),this.atime=n?.atime??r?.atime??kI(e,t+476,12),this.ctime=n?.ctime??r?.ctime??kI(e,t+488,12)}let l=256;for(let c=t;c<t+148;c++)l+=e[c];for(let c=t+156;c<t+512;c++)l+=e[c];this.cksumValid=l===this.cksum,this.cksum===void 0&&l===256&&(this.nullBlock=!0)}#n(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,r])=>!(r==null||n==="size"&&Number(r)<0||n==="path"&&t||n==="linkpath"&&t||n==="global"))))}encode(e,t=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,r=ISe(this.path||"",n),i=r[0],o=r[1];this.needPax=!!r[2],this.needPax=au(e,t,100,i)||this.needPax,this.needPax=kl(e,t+100,8,this.mode)||this.needPax,this.needPax=kl(e,t+108,8,this.uid)||this.needPax,this.needPax=kl(e,t+116,8,this.gid)||this.needPax,this.needPax=kl(e,t+124,12,this.size)||this.needPax,this.needPax=AI(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=au(e,t+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",t+257,8),this.needPax=au(e,t+265,32,this.uname)||this.needPax,this.needPax=au(e,t+297,32,this.gname)||this.needPax,this.needPax=kl(e,t+329,8,this.devmaj)||this.needPax,this.needPax=kl(e,t+337,8,this.devmin)||this.needPax,this.needPax=au(e,t+345,n,o)||this.needPax,e[t+475]!==0?this.needPax=au(e,t+345,155,o)||this.needPax:(this.needPax=au(e,t+345,130,o)||this.needPax,this.needPax=AI(e,t+476,12,this.atime)||this.needPax,this.needPax=AI(e,t+488,12,this.ctime)||this.needPax);let s=256;for(let a=t;a<t+148;a++)s+=e[a];for(let a=t+156;a<t+512;a++)s+=e[a];return this.cksum=s,kl(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:qS.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(cO.get(e));if(xS(t)||t==="Unsupported")this.#e=t;else if(xS(e))this.#e=e;else throw TypeError("invalid entry type: "+e)}},ISe=(e,t)=>{let n=e,r="",i,o=bp.parse(e).root||".";if(Buffer.byteLength(n)<100)i=[n,r,!1];else{r=bp.dirname(n),n=bp.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(r)<=t?i=[n,r,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(r)<=t?i=[n.slice(0,99),r,!0]:(n=bp.join(bp.basename(r),n),r=bp.dirname(r));while(r!==o&&i===void 0);i||(i=[e.slice(0,99),"",!0])}return i},su=(e,t,n)=>e.subarray(t,t+n).toString("utf8").replace(/\0.*/,""),kI=(e,t,n)=>OSe(Sl(e,t,n)),OSe=(e)=>e===void 0?void 0:new Date(e*1000),Sl=(e,t,n)=>Number(e[t])&128?ESe(e.subarray(t,t+n)):TSe(e,t,n),DSe=(e)=>isNaN(e)?void 0:e,TSe=(e,t,n)=>DSe(parseInt(e.subarray(t,t+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),jSe,kl=(e,t,n,r)=>r===void 0?!1:r>jSe[n]||r<0?(SSe(r,e.subarray(t,t+n)),!0):(NSe(e,t,n,r),!1),NSe=(e,t,n,r)=>e.write(MSe(r,n),t,n,"ascii"),MSe=(e,t)=>LSe(Math.floor(e).toString(8),t),LSe=(e,t)=>(e.length===t-1?e:Array(t-e.length-1).join("0")+e+" ")+"\x00",AI=(e,t,n,r)=>r===void 0?!1:kl(e,t,n,r.getTime()/1000),USe,au=(e,t,n,r)=>r===void 0?!1:(e.write(r+USe,t,n,"utf8"),r.length!==Buffer.byteLength(r)||r.length>n),US=class e{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,n=!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=n,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 n=Buffer.byteLength(t),r=512*Math.ceil(1+n/512),i=Buffer.allocUnsafe(r);for(let o=0;o<512;o++)i[o]=0;new gu({path:("PaxHeader/"+FSe(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:n,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(i),i.write(t,512,n,"utf8");for(let o=n+512;o<i.length;o++)i[o]=0;return i}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 n=this[t],r=n instanceof Date?n.getTime()/1000:n,i=" "+(t==="dev"||t==="ino"||t==="nlink"?"SCHILY.":"")+t+"="+r+`
|
|
5
5
|
`,o=Buffer.byteLength(i),s=Math.floor(Math.log(o)/Math.log(10))+1;return o+s>=Math.pow(10,s)&&(s+=1),s+o+i}static parse(t,n,r=!1){return new e(zSe(HSe(t),n),r)}},zSe=(e,t)=>t?Object.assign({},t,e):e,HSe=(e)=>e.replace(/\n$/,"").split(`
|
|
6
6
|
`).reduce(BSe,Object.create(null)),BSe=(e,t)=>{let n=parseInt(t,10);if(n!==Buffer.byteLength(t)+1)return e;t=t.slice((n+" ").length);let r=t.split("="),i=r.shift();if(!i)return e;let o=i.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),s=r.join("=").replace(/\0.*/,"");switch(o){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":e[o]=s;break;case"ctime":case"atime":case"mtime":e[o]=new Date(Number(s)*1000);break;case"size":let a=+s;a>=0&&(e[o]=a);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":e[o]=+s;break}return e},VSe,Ne,qSe,WS=(e,t,n,r={})=>{e.file&&(r.file=e.file),e.cwd&&(r.cwd=e.cwd),r.code=n instanceof Error&&n.code||t,r.tarCode=t,!e.strict&&r.recoverable!==!1?(n instanceof Error&&(r=Object.assign(n,r),n=n.message),e.emit("warn",t,n,r)):n instanceof Error?e.emit("error",Object.assign(n,r)):e.emit("error",Object.assign(Error(`${t}: ${n}`),r))},WSe=1048576,zI,HI,KSe,Gi,lu,fa,EI,jW,ws,yh,vl,NW,Ht,ga,wl,RI,cu,on,_S,bS,PI,MW,LW,vh,CI,SS,Sp,_s,kS,uu,AS,ES,UW,GSe=1000,wh,$I,FW,JSe=()=>!0,jh,Ch=(e)=>{let t=e.length-1,n=-1;for(;t>-1&&e.charAt(t)==="/";)n=t,t--;return n===-1?e:e.slice(0,n)},ZSe=(e)=>{let t=e.onReadEntry;e.onReadEntry=t?(n)=>{t(n),n.resume()}:(n)=>n.resume()},_9=(e,t)=>{let n=new Map(t.map((s)=>[Ch(s),!0])),r=e.filter,i=100,o=(s,a="",l=0)=>{if(l>=i)return n.set(s,!1),!1;let c=a||rSe(s).root||".",u;if(s===c)u=!1;else{let d=n.get(s);u=d!==void 0?d:o(nSe(s),c,l+1)}return n.set(s,u),u};e.filter=r?(s,a)=>r(s,a)&&o(Ch(s)):(s)=>o(Ch(s))},YSe=(e)=>{let t=new jh(e),n=e.file,r;try{r=Cp.openSync(n,"r");let i=Cp.fstatSync(r),o=e.maxReadSize||16777216;if(i.size<o){let s=Buffer.allocUnsafe(i.size),a=Cp.readSync(r,s,0,i.size,0);t.end(a===s.byteLength?s:s.subarray(0,a))}else{let s=0,a=Buffer.allocUnsafe(o);for(;s<i.size;){let l=Cp.readSync(r,a,0,o,s);if(l===0)break;s+=l,t.write(a.subarray(0,l))}t.end()}}finally{if(typeof r=="number")try{Cp.closeSync(r)}catch{}}},XSe=(e,t)=>{let n=new jh(e),r=e.maxReadSize||16777216,i=e.file;return new Promise((o,s)=>{n.on("error",s),n.on("end",o),Cp.stat(i,(a,l)=>{if(a)s(a);else{let c=new sO(i,{readSize:r,size:l.size});c.on("error",s),c.pipe(n)}})})},Cl,b9=(e,t,n)=>(e&=4095,n&&(e=(e|384)&-19),t&&(e&256&&(e|=64),e&32&&(e|=8),e&4&&(e|=1)),e),eke,HW,uO=(e)=>{let t="",n=HW(e);for(;eke(e)||n.root;){let r=e.charAt(0)==="/"&&e.slice(0,4)!=="//?/"?"/":n.root;e=e.slice(r.length),t+=r,n=HW(e)}return[t,e]},KS,dO,tke,nke,BW=(e)=>KS.reduce((t,n)=>t.split(n).join(tke.get(n)),e),rke=(e)=>dO.reduce((t,n)=>t.split(n).join(nke.get(n)),e),S9=(e,t)=>t?(e=Ne(e).replace(/^\.(\/|$)/,""),Ch(t)+"/"+e):Ne(e),ike=16777216,VW,qW,WW,BI,KW,_h,IS,VI,OS,qI,WI,KI,GI,Al,zS,JI,xI,Ss,k9,oke,ske,ake=(e)=>e.isFile()?"File":e.isDirectory()?"Directory":e.isSymbolicLink()?"SymbolicLink":"Unsupported",lke,pO=class{list;next;prev;value;constructor(e,t,n,r){this.list=r,this.value=e,t?(t.next=this,this.prev=t):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},JW=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(e,t){this.path=e||"./",this.absolute=t}},ZW,DS,bh,Po,Sh,_l,du,kh,RS,Co,II,TS,YW,ZI,YI,jS,NS,XW,OI,MS,A9,DI,GS,mO,pke=(e,t)=>{let n=new mO(e),r=new p9(e.file,{mode:e.mode||438});n.pipe(r),E9(n,t)},mke=(e,t)=>{let n=new GS(e),r=new VS(e.file,{mode:e.mode||438});n.pipe(r);let i=new Promise((o,s)=>{r.on("error",s),r.on("close",o),n.on("error",s)});return R9(n,t).catch((o)=>n.emit("error",o)),i},E9=(e,t)=>{t.forEach((n)=>{n.charAt(0)==="@"?Cl({file:m9.resolve(e.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:(r)=>e.add(r)}):e.add(n)}),e.end()},R9=async(e,t)=>{for(let n of t)n.charAt(0)==="@"?await Cl({file:m9.resolve(String(e.cwd),n.slice(1)),noResume:!0,onReadEntry:(r)=>{e.add(r)}}):e.add(n);e.end()},fke=(e,t)=>{let n=new mO(e);return E9(n,t),n},gke=(e,t)=>{let n=new GS(e);return R9(n,t).catch((r)=>n.emit("error",r)),n},fO,yke,x9,I9,QW,O9,D9,T9,vke,wke=524288,_ke,e9,j9,XI=(e,t,n)=>{try{return JS.lchownSync(e,t,n)}catch(r){if(r?.code!=="ENOENT")throw r}},HS=(e,t,n,r)=>{JS.lchown(e,t,n,(i)=>{r(i&&i?.code!=="ENOENT"?i:null)})},bke=(e,t,n,r,i)=>{if(t.isDirectory())N9($h.resolve(e,t.name),n,r,(o)=>{if(o)return i(o);let s=$h.resolve(e,t.name);HS(s,n,r,i)});else{let o=$h.resolve(e,t.name);HS(o,n,r,i)}},N9=(e,t,n,r)=>{JS.readdir(e,{withFileTypes:!0},(i,o)=>{if(i){if(i.code==="ENOENT")return r();if(i.code!=="ENOTDIR"&&i.code!=="ENOTSUP")return r(i)}if(i||!o.length)return HS(e,t,n,r);let s=o.length,a=null,l=(c)=>{if(!a){if(c)return r(a=c);if(--s===0)return HS(e,t,n,r)}};for(let c of o)bke(e,c,t,n,l)})},Ske=(e,t,n,r)=>{t.isDirectory()&&M9($h.resolve(e,t.name),n,r),XI($h.resolve(e,t.name),n,r)},M9=(e,t,n)=>{let r;try{r=JS.readdirSync(e,{withFileTypes:!0})}catch(i){let o=i;if(o?.code==="ENOENT")return;if(o?.code==="ENOTDIR"||o?.code==="ENOTSUP")return XI(e,t,n);throw o}for(let i of r)Ske(e,i,t,n);return XI(e,t,n)},L9,ZS,Ake=(e,t)=>{Ai.stat(e,(n,r)=>{(n||!r.isDirectory())&&(n=new L9(e,n?.code||"ENOTDIR")),t(n)})},Eke=(e,t,n)=>{e=Ne(e);let r=t.umask??18,i=t.mode|448,o=(i&r)!==0,s=t.uid,a=t.gid,l=typeof s=="number"&&typeof a=="number"&&(s!==t.processUid||a!==t.processGid),c=t.preserve,u=t.unlink,d=Ne(t.cwd),p=(g,f)=>{g?n(g):f&&l?N9(f,s,a,(v)=>p(v)):o?Ai.chmod(e,i,n):n()};if(e===d)return Ake(e,p);if(c)return kke.mkdir(e,{mode:i,recursive:!0}).then((g)=>p(null,g??void 0),p);let m=Ne(BS.relative(d,e)).split("/");QI(d,m,i,u,d,void 0,p)},QI=(e,t,n,r,i,o,s)=>{if(t.length===0)return s(null,o);let a=t.shift(),l=Ne(BS.resolve(e+"/"+a));Ai.mkdir(l,n,U9(l,t,n,r,i,o,s))},U9=(e,t,n,r,i,o,s)=>(a)=>{a?Ai.lstat(e,(l,c)=>{if(l)l.path=l.path&&Ne(l.path),s(l);else if(c.isDirectory())QI(e,t,n,r,i,o,s);else if(r)Ai.unlink(e,(u)=>{if(u)return s(u);Ai.mkdir(e,n,U9(e,t,n,r,i,o,s))});else{if(c.isSymbolicLink())return s(new ZS(e,e+"/"+t.join("/")));s(a)}}):(o=o||e,QI(e,t,n,r,i,o,s))},Rke=(e)=>{let t=!1,n;try{t=Ai.statSync(e).isDirectory()}catch(r){n=r?.code}finally{if(!t)throw new L9(e,n??"ENOTDIR")}},Pke=(e,t)=>{e=Ne(e);let n=t.umask??18,r=t.mode|448,i=(r&n)!==0,o=t.uid,s=t.gid,a=typeof o=="number"&&typeof s=="number"&&(o!==t.processUid||s!==t.processGid),l=t.preserve,c=t.unlink,u=Ne(t.cwd),d=(g)=>{g&&a&&M9(g,o,s),i&&Ai.chmodSync(e,r)};if(e===u)return Rke(u),d();if(l)return d(Ai.mkdirSync(e,{mode:r,recursive:!0})??void 0);let p=Ne(BS.relative(u,e)).split("/"),m;for(let g=p.shift(),f=u;g&&(f+="/"+g);g=p.shift()){f=Ne(BS.resolve(f));try{Ai.mkdirSync(f,r),m=m||f}catch{let v=Ai.lstatSync(f);if(v.isDirectory())continue;if(c){Ai.unlinkSync(f),Ai.mkdirSync(f,r),m=m||f;continue}else if(v.isSymbolicLink())return new ZS(f,f+"/"+p.join("/"))}}return d(m)},TI,t9=1e4,kp,Cke=(e)=>{kp.has(e)?kp.delete(e):TI[e]=e.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),kp.add(e);let t=TI[e],n=kp.size-t9;if(n>t9/10){for(let r of kp)if(kp.delete(r),delete TI[r],--n<=0)break}return t},$ke,xke,Ike=(e)=>e.split("/").slice(0,-1).reduce((t,n)=>{let r=t.at(-1);return r!==void 0&&(n=F9(r,n)),t.push(n||"/"),t},[]),Oke=class{#e=new Map;#n=new Map;#r=new Set;reserve(e,t){e=xke?["win32 parallelization disabled"]:e.map((r)=>Ch(F9(Cke(r))));let n=new Set(e.map((r)=>Ike(r)).reduce((r,i)=>r.concat(i)));this.#n.set(t,{dirs:n,paths:e});for(let r of e){let i=this.#e.get(r);i?i.push(t):this.#e.set(r,[t])}for(let r of n){let i=this.#e.get(r);if(!i)this.#e.set(r,[new Set([t])]);else{let o=i.at(-1);o instanceof Set?o.add(t):i.push(new Set([t]))}}return this.#i(t)}#o(e){let t=this.#n.get(e);if(!t)throw Error("function does not have any path reservations");return{paths:t.paths.map((n)=>this.#e.get(n)),dirs:[...t.dirs].map((n)=>this.#e.get(n))}}check(e){let{paths:t,dirs:n}=this.#o(e);return t.every((r)=>r&&r[0]===e)&&n.every((r)=>r&&r[0]instanceof Set&&r[0].has(e))}#i(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.#n.get(e);if(!t)throw Error("invalid reservation");let{paths:n,dirs:r}=t,i=new Set;for(let o of n){let s=this.#e.get(o);if(!s||s?.[0]!==e)continue;let a=s[1];if(!a){this.#e.delete(o);continue}if(s.shift(),typeof a=="function")i.add(a);else for(let l of a)i.add(l)}for(let o of r){let s=this.#e.get(o),a=s?.[0];if(!(!s||!(a instanceof Set)))if(a.size===1&&s.length===1){this.#e.delete(o);continue}else if(a.size===1){s.shift();let l=s[0];typeof l=="function"&&i.add(l)}else a.delete(e)}return this.#r.delete(e),i.forEach((o)=>this.#i(o)),!0}},Dke=()=>process.umask(),n9,eO,r9,tO,Ji,nO,rO,LS,i9,o9,Rh,s9,a9,jI,El,Ln,PS,l9,Ap,NI,MI,iO,xh,Ih,Oh,Dh,Tke,Th,jke=1024,Nke=(e,t)=>{if(!Th)return Ke.unlink(e,t);let n=e+".DELETE."+C9(16).toString("hex");Ke.rename(e,n,(r)=>{if(r)return t(r);Ke.unlink(n,t)})},Mke=(e)=>{if(!Th)return Ke.unlinkSync(e);let t=e+".DELETE."+C9(16).toString("hex");Ke.renameSync(e,t),Ke.unlinkSync(t)},c9=(e,t,n)=>e!==void 0&&e===e>>>0?e:t!==void 0&&t===t>>>0?t:n,gO,Ah=(e)=>{try{return[null,e()]}catch(t){return[t,null]}},z9,Lke=(e)=>{let t=new z9(e),n=e.file,r=P9.statSync(n),i=e.maxReadSize||16777216;new tSe(n,{readSize:i,size:r.size}).pipe(t)},Uke=(e,t)=>{let n=new gO(e),r=e.maxReadSize||16777216,i=e.file;return new Promise((o,s)=>{n.on("error",s),n.on("close",o),P9.stat(i,(a,l)=>{if(a)s(a);else{let c=new sO(i,{readSize:r,size:l.size});c.on("error",s),c.pipe(n)}})})},Mh,Fke=(e,t)=>{let n=new mO(e),r=!0,i,o;try{try{i=ki.openSync(e.file,"r+")}catch(l){if(l?.code==="ENOENT")i=ki.openSync(e.file,"w+");else throw l}let s=ki.fstatSync(i),a=Buffer.alloc(512);e:for(o=0;o<s.size;o+=512){for(let u=0,d=0;u<512;u+=d){if(d=ki.readSync(i,a,u,a.length-u,o+u),o===0&&a[0]===31&&a[1]===139)throw Error("cannot append to compressed archives");if(!d)break e}let l=new gu(a);if(!l.cksumValid)break;let c=512*Math.ceil((l.size||0)/512);if(o+c+512>s.size)break;o+=c,e.mtimeCache&&l.mtime&&e.mtimeCache.set(String(l.path),l.mtime)}r=!1,zke(e,n,o,i,t)}finally{if(r)try{ki.closeSync(i)}catch{}}},zke=(e,t,n,r,i)=>{let o=new p9(e.file,{fd:r,start:n});t.pipe(o),Bke(t,i)},Hke=(e,t)=>{t=Array.from(t);let n=new GS(e),r=(i,o,s)=>{let a=(p,m)=>{p?ki.close(i,(g)=>s(p)):s(null,m)},l=0;if(o===0)return a(null,0);let c=0,u=Buffer.alloc(512),d=(p,m)=>{if(p||m===void 0)return a(p);if(c+=m,c<512&&m)return ki.read(i,u,c,u.length-c,l+c,d);if(l===0&&u[0]===31&&u[1]===139)return a(Error("cannot append to compressed archives"));if(c<512)return a(null,l);let g=new gu(u);if(!g.cksumValid)return a(null,l);let f=512*Math.ceil((g.size??0)/512);if(l+f+512>o||(l+=f+512,l>=o))return a(null,l);e.mtimeCache&&g.mtime&&e.mtimeCache.set(String(g.path),g.mtime),c=0,ki.read(i,u,0,512,l,d)};ki.read(i,u,0,512,l,d)};return new Promise((i,o)=>{n.on("error",o);let s="r+",a=(l,c)=>{if(l&&l.code==="ENOENT"&&s==="r+")return s="w+",ki.open(e.file,s,a);if(l||!c)return o(l);ki.fstat(c,(u,d)=>{if(u)return ki.close(c,()=>o(u));r(c,d.size,(p,m)=>{if(p)return o(p);let g=new VS(e.file,{fd:c,start:m});n.pipe(g),g.on("error",o),g.on("close",i),Vke(n,t)})})};ki.open(e.file,s,a)})},Bke=(e,t)=>{t.forEach((n)=>{n.charAt(0)==="@"?Cl({file:H9.resolve(e.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:(r)=>e.add(r)}):e.add(n)}),e.end()},Vke=async(e,t)=>{for(let n of t)n.charAt(0)==="@"?await Cl({file:H9.resolve(String(e.cwd),n.slice(1)),noResume:!0,onReadEntry:(r)=>e.add(r)}):e.add(n);e.end()},Eh,cvt,qke=(e)=>{let t=e.filter;e.mtimeCache||(e.mtimeCache=new Map),e.filter=t?(n,r)=>t(n,r)&&!((e.mtimeCache?.get(n)??r.mtime??0)>(r.mtime??0)):(n,r)=>!((e.mtimeCache?.get(n)??r.mtime??0)>(r.mtime??0))};var hO=b(()=>{Fbe=Object.defineProperty,$W=typeof process=="object"&&process?process:{stdout:null,stderr:null},pa=Symbol("EOF"),ma=Symbol("maybeEmitEnd"),yl=Symbol("emittedEnd"),mS=Symbol("emittingEnd"),dh=Symbol("emittedError"),fS=Symbol("closed"),xW=Symbol("read"),gS=Symbol("flush"),IW=Symbol("flushChunk"),Ro=Symbol("encoding"),_p=Symbol("decoder"),jn=Symbol("flowing"),ph=Symbol("paused"),Ep=Symbol("resume"),Nn=Symbol("buffer"),Rr=Symbol("pipes"),Mn=Symbol("bufferLength"),dI=Symbol("bufferPush"),hS=Symbol("bufferShift"),fr=Symbol("objectMode"),mn=Symbol("destroyed"),pI=Symbol("error"),mI=Symbol("emitData"),OW=Symbol("emitEnd"),fI=Symbol("emitEnd2"),ys=Symbol("async"),gI=Symbol("abort"),yS=Symbol("aborted"),mh=Symbol("signal"),iu=Symbol("dataListeners"),Si=Symbol("discarded"),Ybe=class extends d9{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,n){super(e,t,n),this.proxyErrors=(r)=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},hu=class extends oO{[jn]=!1;[ph]=!1;[Rr]=[];[Nn]=[];[fr];[Ro];[ys];[_p];[pa]=!1;[yl]=!1;[mS]=!1;[fS]=!1;[dh]=null;[Mn]=0;[mn]=!1;[mh];[yS]=!1;[iu]=0;[Si]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw TypeError("Encoding and objectMode may not be used together");Xbe(t)?(this[fr]=!0,this[Ro]=null):Qbe(t)?(this[Ro]=t.encoding,this[fr]=!1):(this[fr]=!1,this[Ro]=null),this[ys]=!!t.async,this[_p]=this[Ro]?new Bbe(this[Ro]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Nn]}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Rr]});let{signal:n}=t;n&&(this[mh]=n,n.aborted?this[gI]():n.addEventListener("abort",()=>this[gI]()))}get bufferLength(){return this[Mn]}get encoding(){return this[Ro]}set encoding(e){throw Error("Encoding must be set at instantiation time")}setEncoding(e){throw Error("Encoding must be set at instantiation time")}get objectMode(){return this[fr]}set objectMode(e){throw Error("objectMode must be set at instantiation time")}get async(){return this[ys]}set async(e){this[ys]=this[ys]||!!e}[gI](){this[yS]=!0,this.emit("abort",this[mh]?.reason),this.destroy(this[mh]?.reason)}get aborted(){return this[yS]}set aborted(e){}write(e,t,n){if(this[yS])return!1;if(this[pa])throw Error("write after end");if(this[mn])return this.emit("error",Object.assign(Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(n=t,t="utf8"),t||(t="utf8");let r=this[ys]?fh:Kbe;if(!this[fr]&&!Buffer.isBuffer(e)){if(Zbe(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Jbe(e))e=Buffer.from(e);else if(typeof e!="string")throw Error("Non-contiguous data written to non-objectMode stream")}return this[fr]?(this[jn]&&this[Mn]!==0&&this[gS](!0),this[jn]?this.emit("data",e):this[dI](e),this[Mn]!==0&&this.emit("readable"),n&&r(n),this[jn]):e.length?(typeof e=="string"&&!(t===this[Ro]&&!this[_p]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[Ro]&&(e=this[_p].write(e)),this[jn]&&this[Mn]!==0&&this[gS](!0),this[jn]?this.emit("data",e):this[dI](e),this[Mn]!==0&&this.emit("readable"),n&&r(n),this[jn]):(this[Mn]!==0&&this.emit("readable"),n&&r(n),this[jn])}read(e){if(this[mn])return null;if(this[Si]=!1,this[Mn]===0||e===0||e&&e>this[Mn])return this[ma](),null;this[fr]&&(e=null),this[Nn].length>1&&!this[fr]&&(this[Nn]=[this[Ro]?this[Nn].join(""):Buffer.concat(this[Nn],this[Mn])]);let t=this[xW](e||null,this[Nn][0]);return this[ma](),t}[xW](e,t){if(this[fr])this[hS]();else{let n=t;e===n.length||e===null?this[hS]():typeof n=="string"?(this[Nn][0]=n.slice(e),t=n.slice(0,e),this[Mn]-=e):(this[Nn][0]=n.subarray(e),t=n.subarray(0,e),this[Mn]-=e)}return this.emit("data",t),!this[Nn].length&&!this[pa]&&this.emit("drain"),t}end(e,t,n){return typeof e=="function"&&(n=e,e=void 0),typeof t=="function"&&(n=t,t="utf8"),e!==void 0&&this.write(e,t),n&&this.once("end",n),this[pa]=!0,this.writable=!1,(this[jn]||!this[ph])&&this[ma](),this}[Ep](){this[mn]||(!this[iu]&&!this[Rr].length&&(this[Si]=!0),this[ph]=!1,this[jn]=!0,this.emit("resume"),this[Nn].length?this[gS]():this[pa]?this[ma]():this.emit("drain"))}resume(){return this[Ep]()}pause(){this[jn]=!1,this[ph]=!0,this[Si]=!1}get destroyed(){return this[mn]}get flowing(){return this[jn]}get paused(){return this[ph]}[dI](e){this[fr]?this[Mn]+=1:this[Mn]+=e.length,this[Nn].push(e)}[hS](){return this[fr]?this[Mn]-=1:this[Mn]-=this[Nn][0].length,this[Nn].shift()}[gS](e=!1){do;while(this[IW](this[hS]())&&this[Nn].length);!e&&!this[Nn].length&&!this[pa]&&this.emit("drain")}[IW](e){return this.emit("data",e),this[jn]}pipe(e,t){if(this[mn])return e;this[Si]=!1;let n=this[yl];return t=t||{},e===$W.stdout||e===$W.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,n?t.end&&e.end():(this[Rr].push(t.proxyErrors?new Ybe(this,e,t):new d9(this,e,t)),this[ys]?fh(()=>this[Ep]()):this[Ep]()),e}unpipe(e){let t=this[Rr].find((n)=>n.dest===e);t&&(this[Rr].length===1?(this[jn]&&this[iu]===0&&(this[jn]=!1),this[Rr]=[]):this[Rr].splice(this[Rr].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let n=super.on(e,t);if(e==="data")this[Si]=!1,this[iu]++,!this[Rr].length&&!this[jn]&&this[Ep]();else if(e==="readable"&&this[Mn]!==0)super.emit("readable");else if(Gbe(e)&&this[yl])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[dh]){let r=t;this[ys]?fh(()=>r.call(this,this[dh])):r.call(this,this[dh])}return n}removeListener(e,t){return this.off(e,t)}off(e,t){let n=super.off(e,t);return e==="data"&&(this[iu]=this.listeners("data").length,this[iu]===0&&!this[Si]&&!this[Rr].length&&(this[jn]=!1)),n}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[iu]=0,!this[Si]&&!this[Rr].length&&(this[jn]=!1)),t}get emittedEnd(){return this[yl]}[ma](){!this[mS]&&!this[yl]&&!this[mn]&&this[Nn].length===0&&this[pa]&&(this[mS]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[fS]&&this.emit("close"),this[mS]=!1)}emit(e,...t){let n=t[0];if(e!=="error"&&e!=="close"&&e!==mn&&this[mn])return!1;if(e==="data")return!this[fr]&&!n?!1:this[ys]?(fh(()=>this[mI](n)),!0):this[mI](n);if(e==="end")return this[OW]();if(e==="close"){if(this[fS]=!0,!this[yl]&&!this[mn])return!1;let i=super.emit("close");return this.removeAllListeners("close"),i}else if(e==="error"){this[dh]=n,super.emit(pI,n);let i=!this[mh]||this.listeners("error").length?super.emit("error",n):!1;return this[ma](),i}else if(e==="resume"){let i=super.emit("resume");return this[ma](),i}else if(e==="finish"||e==="prefinish"){let i=super.emit(e);return this.removeAllListeners(e),i}let r=super.emit(e,...t);return this[ma](),r}[mI](e){for(let n of this[Rr])n.dest.write(e)===!1&&this.pause();let t=this[Si]?!1:super.emit("data",e);return this[ma](),t}[OW](){return this[yl]?!1:(this[yl]=!0,this.readable=!1,this[ys]?(fh(()=>this[fI]()),!0):this[fI]())}[fI](){if(this[_p]){let t=this[_p].end();if(t){for(let n of this[Rr])n.dest.write(t);this[Si]||super.emit("data",t)}}for(let t of this[Rr])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[fr]||(e.dataLength=0);let t=this.promise();return this.on("data",(n)=>{e.push(n),this[fr]||(e.dataLength+=n.length)}),await t,e}async concat(){if(this[fr])throw Error("cannot concat in objectMode");let e=await this.collect();return this[Ro]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(mn,()=>t(Error("stream destroyed"))),this.on("error",(n)=>t(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[Si]=!1;let e=!1,t=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return t();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[pa])return t();let r,i,o=(c)=>{this.off("data",s),this.off("end",a),this.off(mn,l),t(),i(c)},s=(c)=>{this.off("error",o),this.off("end",a),this.off(mn,l),this.pause(),r({value:c,done:!!this[pa]})},a=()=>{this.off("error",o),this.off("data",s),this.off(mn,l),t(),r({done:!0,value:void 0})},l=()=>o(Error("stream destroyed"));return new Promise((c,u)=>{i=u,r=c,this.once(mn,l),this.once("error",o),this.once("end",a),this.once("data",s)})},throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Si]=!1;let e=!1,t=()=>(this.pause(),this.off(pI,t),this.off(mn,t),this.off("end",t),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}};return this.once("end",t),this.once(pI,t),this.once(mn,t),{next:n,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[mn])return e?this.emit("error",e):this.emit(mn),this;this[mn]=!0,this[Si]=!0,this[Nn].length=0,this[Mn]=0;let t=this;return typeof t.close=="function"&&!this[fS]&&t.close(),e?this.emit("error",e):this.emit(mn),this}static get isStream(){return Vbe}},eSe=Kr.writev,Rl=Symbol("_autoClose"),xo=Symbol("_close"),gh=Symbol("_ended"),mt=Symbol("_fd"),hI=Symbol("_finished"),ya=Symbol("_flags"),yI=Symbol("_flush"),LI=Symbol("_handleChunk"),UI=Symbol("_makeBuf"),Ph=Symbol("_mode"),vS=Symbol("_needDrain"),$p=Symbol("_onerror"),xp=Symbol("_onopen"),vI=Symbol("_onread"),Rp=Symbol("_onwrite"),Pl=Symbol("_open"),$o=Symbol("_path"),bl=Symbol("_pos"),vs=Symbol("_queue"),Pp=Symbol("_read"),wI=Symbol("_readSize"),ha=Symbol("_reading"),hh=Symbol("_remain"),_I=Symbol("_size"),CS=Symbol("_write"),ou=Symbol("_writing"),$S=Symbol("_defaultFlag"),pu=Symbol("_errored"),sO=class extends hu{[pu]=!1;[mt];[$o];[wI];[ha]=!1;[_I];[hh];[Rl];constructor(e,t){if(t=t||{},super(t),this.readable=!0,this.writable=!1,typeof e!="string")throw TypeError("path must be a string");this[pu]=!1,this[mt]=typeof t.fd=="number"?t.fd:void 0,this[$o]=e,this[wI]=t.readSize||16777216,this[ha]=!1,this[_I]=typeof t.size=="number"?t.size:1/0,this[hh]=this[_I],this[Rl]=typeof t.autoClose=="boolean"?t.autoClose:!0,typeof this[mt]=="number"?this[Pp]():this[Pl]()}get fd(){return this[mt]}get path(){return this[$o]}write(){throw TypeError("this is a readable stream")}end(){throw TypeError("this is a readable stream")}[Pl](){Kr.open(this[$o],"r",(e,t)=>this[xp](e,t))}[xp](e,t){e?this[$p](e):(this[mt]=t,this.emit("open",t),this[Pp]())}[UI](){return Buffer.allocUnsafe(Math.min(this[wI],this[hh]))}[Pp](){if(!this[ha]){this[ha]=!0;let e=this[UI]();if(e.length===0)return process.nextTick(()=>this[vI](null,0,e));Kr.read(this[mt],e,0,e.length,null,(t,n,r)=>this[vI](t,n,r))}}[vI](e,t,n){this[ha]=!1,e?this[$p](e):this[LI](t,n)&&this[Pp]()}[xo](){if(this[Rl]&&typeof this[mt]=="number"){let e=this[mt];this[mt]=void 0,Kr.close(e,(t)=>t?this.emit("error",t):this.emit("close"))}}[$p](e){this[ha]=!0,this[xo](),this.emit("error",e)}[LI](e,t){let n=!1;return this[hh]-=e,e>0&&(n=super.write(e<t.length?t.subarray(0,e):t)),(e===0||this[hh]<=0)&&(n=!1,this[xo](),super.end()),n}emit(e,...t){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[mt]=="number"&&this[Pp](),!1;case"error":return this[pu]?!1:(this[pu]=!0,super.emit(e,...t));default:return super.emit(e,...t)}}},tSe=class extends sO{[Pl](){let e=!0;try{this[xp](null,Kr.openSync(this[$o],"r")),e=!1}finally{e&&this[xo]()}}[Pp](){let e=!0;try{if(!this[ha]){this[ha]=!0;do{let t=this[UI](),n=t.length===0?0:Kr.readSync(this[mt],t,0,t.length,null);if(!this[LI](n,t))break}while(!0);this[ha]=!1}e=!1}finally{e&&this[xo]()}}[xo](){if(this[Rl]&&typeof this[mt]=="number"){let e=this[mt];this[mt]=void 0,Kr.closeSync(e),this.emit("close")}}},VS=class extends Hbe{readable=!1;writable=!0;[pu]=!1;[ou]=!1;[gh]=!1;[vs]=[];[vS]=!1;[$o];[Ph];[Rl];[mt];[$S];[ya];[hI]=!1;[bl];constructor(e,t){t=t||{},super(t),this[$o]=e,this[mt]=typeof t.fd=="number"?t.fd:void 0,this[Ph]=t.mode===void 0?438:t.mode,this[bl]=typeof t.start=="number"?t.start:void 0,this[Rl]=typeof t.autoClose=="boolean"?t.autoClose:!0;let n=this[bl]!==void 0?"r+":"w";this[$S]=t.flags===void 0,this[ya]=t.flags===void 0?n:t.flags,this[mt]===void 0&&this[Pl]()}emit(e,...t){if(e==="error"){if(this[pu])return!1;this[pu]=!0}return super.emit(e,...t)}get fd(){return this[mt]}get path(){return this[$o]}[$p](e){this[xo](),this[ou]=!0,this.emit("error",e)}[Pl](){Kr.open(this[$o],this[ya],this[Ph],(e,t)=>this[xp](e,t))}[xp](e,t){this[$S]&&this[ya]==="r+"&&e&&e.code==="ENOENT"?(this[ya]="w",this[Pl]()):e?this[$p](e):(this[mt]=t,this.emit("open",t),this[ou]||this[yI]())}end(e,t){return e&&this.write(e,t),this[gh]=!0,!this[ou]&&!this[vs].length&&typeof this[mt]=="number"&&this[Rp](null,0),this}write(e,t){return typeof e=="string"&&(e=Buffer.from(e,t)),this[gh]?(this.emit("error",Error("write() after end()")),!1):this[mt]===void 0||this[ou]||this[vs].length?(this[vs].push(e),this[vS]=!0,!1):(this[ou]=!0,this[CS](e),!0)}[CS](e){Kr.write(this[mt],e,0,e.length,this[bl],(t,n)=>this[Rp](t,n))}[Rp](e,t){e?this[$p](e):(this[bl]!==void 0&&typeof t=="number"&&(this[bl]+=t),this[vs].length?this[yI]():(this[ou]=!1,this[gh]&&!this[hI]?(this[hI]=!0,this[xo](),this.emit("finish")):this[vS]&&(this[vS]=!1,this.emit("drain"))))}[yI](){if(this[vs].length===0)this[gh]&&this[Rp](null,0);else if(this[vs].length===1)this[CS](this[vs].pop());else{let e=this[vs];this[vs]=[],eSe(this[mt],e,this[bl],(t,n)=>this[Rp](t,n))}}[xo](){if(this[Rl]&&typeof this[mt]=="number"){let e=this[mt];this[mt]=void 0,Kr.close(e,(t)=>t?this.emit("error",t):this.emit("close"))}}},p9=class extends VS{[Pl](){let e;if(this[$S]&&this[ya]==="r+")try{e=Kr.openSync(this[$o],this[ya],this[Ph])}catch(t){if(t?.code==="ENOENT")return this[ya]="w",this[Pl]();throw t}else e=Kr.openSync(this[$o],this[ya],this[Ph]);this[xp](null,e)}[xo](){if(this[Rl]&&typeof this[mt]=="number"){let e=this[mt];this[mt]=void 0,Kr.closeSync(e),this.emit("close")}}[CS](e){let t=!0;try{this[Rp](null,Kr.writeSync(this[mt],e,0,e.length,this[bl])),t=!1}finally{if(t)try{this[xo]()}catch{}}}},iSe=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"]]),mSe=pSe.constants||{ZLIB_VERNUM:4736},ks=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},mSe)),fSe=mu.concat,TW=Object.getOwnPropertyDescriptor(mu,"concat"),bI=TW?.writable===!0||TW?.set!==void 0?(e)=>{mu.concat=e?gSe:fSe}:(e)=>{},fu=Symbol("_superWrite"),wS=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"}},SI=Symbol("flushFlag"),lO=class extends hu{#e=!1;#n=!1;#r;#o;#i;#t;#s;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(e,t){if(!e||typeof e!="object")throw TypeError("invalid options for ZlibBase constructor");if(super(e),this.#r=e.flush??0,this.#o=e.finishFlush??0,this.#i=e.fullFlushFlag??0,typeof DW[t]!="function")throw TypeError("Compression method not supported: "+t);try{this.#t=new DW[t](e)}catch(n){throw new wS(n,this.constructor)}this.#s=(n)=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",(n)=>this.#s(new wS(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return FI(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#i),this.write(Object.assign(mu.alloc(0),{[SI]:e})))}end(e,t,n){return typeof e=="function"&&(n=e,t=void 0,e=void 0),typeof t=="function"&&(n=t,t=void 0),e&&(t?this.write(e,t):this.write(e)),this.flush(this.#o),this.#n=!0,super.end(n)}get ended(){return this.#n}[fu](e){return super.write(e)}write(e,t,n){if(typeof t=="function"&&(n=t,t="utf8"),typeof e=="string"&&(e=mu.from(e,t)),this.#e)return;FI(this.#t,"zlib binding closed");let r=this.#t._handle,i=r.close;r.close=()=>{};let o=this.#t.close;this.#t.close=()=>{},bI(!0);let s;try{let l=typeof e[SI]=="number"?e[SI]:this.#r;s=this.#t._processChunk(e,l),bI(!1)}catch(l){bI(!1),this.#s(new wS(l,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=i,this.#t.close=o,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",(l)=>this.#s(new wS(l,this.write)));let a;if(s)if(Array.isArray(s)&&s.length>0){let l=s[0];a=this[fu](mu.from(l));for(let c=1;c<s.length;c++)a=this[fu](s[c])}else a=this[fu](mu.from(s));return n&&n(),a}},f9=class extends lO{#e;#n;constructor(e,t){e=e||{},e.flush=e.flush||ks.Z_NO_FLUSH,e.finishFlush=e.finishFlush||ks.Z_FINISH,e.fullFlushFlag=ks.Z_FULL_FLUSH,super(e,t),this.#e=e.level,this.#n=e.strategy}params(e,t){if(!this.sawError){if(!this.handle)throw Error("cannot switch params when binding is closed");if(!this.handle.params)throw Error("not supported in this implementation");if(this.#e!==e||this.#n!==t){this.flush(ks.Z_SYNC_FLUSH),FI(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(r,i)=>{typeof r=="function"&&(i=r,r=this.flushFlag),this.flush(r),i?.()};try{this.handle.params(e,t)}finally{this.handle.flush=n}this.handle&&(this.#e=e,this.#n=t)}}}},hSe=class extends f9{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[fu](e){return this.#e?(this.#e=!1,e[9]=255,super[fu](e)):super[fu](e)}},ySe=class extends f9{constructor(e){super(e,"Unzip")}},g9=class extends lO{constructor(e,t){e=e||{},e.flush=e.flush||ks.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||ks.BROTLI_OPERATION_FINISH,e.fullFlushFlag=ks.BROTLI_OPERATION_FLUSH,super(e,t)}},vSe=class extends g9{constructor(e){super(e,"BrotliCompress")}},wSe=class extends g9{constructor(e){super(e,"BrotliDecompress")}},h9=class extends lO{constructor(e,t){e=e||{},e.flush=e.flush||ks.ZSTD_e_continue,e.finishFlush=e.finishFlush||ks.ZSTD_e_end,e.fullFlushFlag=ks.ZSTD_e_flush,super(e,t)}},_Se=class extends h9{constructor(e){super(e,"ZstdCompress")}},bSe=class extends h9{constructor(e){super(e,"ZstdDecompress")}},CSe={};zbe(CSe,{code:()=>cO,isCode:()=>xS,isName:()=>$Se,name:()=>qS,normalFsTypes:()=>w9});w9=new Set(["0","","1","2","3","4","5","6","7","D"]),qS=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"]]),cO=new Map(Array.from(qS).map((e)=>[e[1],e[0]])),jSe={12:8589934591,8:2097151},USe=Array(156).join("\x00"),VSe=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ne=VSe!=="win32"?(e)=>String(e):(e)=>String(e).replaceAll(/\\/g,"/"),qSe=class extends hu{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,n){switch(super({}),this.pause(),this.extended=t,this.globalExtended=n,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 Error("no path provided for tar.ReadEntry");this.path=Ne(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?Ne(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,t&&this.#e(t),n&&this.#e(n,!0)}write(e){let t=e.length;if(t>this.blockRemain)throw Error("writing more to entry than is appropriate");let n=this.remain,r=this.blockRemain;return this.remain=Math.max(0,n-t),this.blockRemain=Math.max(0,r-t),this.ignore?!0:n>=t?super.write(e):super.write(e.subarray(0,n))}#e(e,t=!1){e.path&&(e.path=Ne(e.path)),e.linkpath&&(e.linkpath=Ne(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,r])=>!(r==null||n==="path"&&t))))}},zI=Buffer.from([31,139]),HI=Buffer.from([40,181,47,253]),KSe=Math.max(zI.length,HI.length),Gi=Symbol("state"),lu=Symbol("writeEntry"),fa=Symbol("readEntry"),EI=Symbol("nextEntry"),jW=Symbol("processEntry"),ws=Symbol("extendedHeader"),yh=Symbol("globalExtendedHeader"),vl=Symbol("meta"),NW=Symbol("emitMeta"),Ht=Symbol("buffer"),ga=Symbol("queue"),wl=Symbol("ended"),RI=Symbol("emittedEnd"),cu=Symbol("emit"),on=Symbol("unzip"),_S=Symbol("consumeChunk"),bS=Symbol("consumeChunkSub"),PI=Symbol("consumeBody"),MW=Symbol("consumeMeta"),LW=Symbol("consumeHeader"),vh=Symbol("consuming"),CI=Symbol("bufferConcat"),SS=Symbol("maybeEnd"),Sp=Symbol("writing"),_s=Symbol("aborted"),kS=Symbol("onDone"),uu=Symbol("sawValidEntry"),AS=Symbol("sawNullBlock"),ES=Symbol("sawEOF"),UW=Symbol("closeStream"),wh=Symbol("compressedBytesRead"),$I=Symbol("decompressedBytesRead"),FW=Symbol("checkDecompressionRatio"),jh=class extends dSe{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[ga]=[];[Ht];[fa];[lu];[Gi]="begin";[vl]="";[ws];[yh];[wl]=!1;[on];[_s]=!1;[uu];[AS]=!1;[ES]=!1;[Sp]=!1;[vh]=!1;[RI]=!1;[wh]=0;[$I]=0;constructor(e={}){super(),this.file=e.file||"",this.on(kS,()=>{(this[Gi]==="begin"||this[uu]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(kS,e.ondone):this.on(kS,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxDecompressionRatio=typeof e.maxDecompressionRatio=="number"?e.maxDecompressionRatio:GSe,this.maxMetaEntrySize=e.maxMetaEntrySize||WSe,this.filter=typeof e.filter=="function"?e.filter:JSe;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 n=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:n?!0:void 0,this.on("end",()=>this[UW]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,t,n={}){WS(this,e,t,n)}[LW](e,t){this[uu]===void 0&&(this[uu]=!1);let n;try{n=new gu(e,t,this[ws],this[yh])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(n.nullBlock)this[AS]?(this[ES]=!0,this[Gi]==="begin"&&(this[Gi]="header"),this[cu]("eof")):(this[AS]=!0,this[cu]("nullBlock"));else if(this[AS]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let r=n.type;if(/^(Symbolic)?Link$/.test(r)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let i=this[lu]=new qSe(n,this[ws],this[yh]);if(!this[uu])if(i.remain){let o=()=>{i.invalid||(this[uu]=!0)};i.on("end",o)}else this[uu]=!0;i.meta?i.size>this.maxMetaEntrySize?(i.ignore=!0,this[cu]("ignoredEntry",i),this[Gi]="ignore",i.resume()):i.size>0&&(this[vl]="",i.on("data",(o)=>this[vl]+=o),this[Gi]="meta"):(this[ws]=void 0,i.ignore=i.ignore||!this.filter(i.path,i),i.ignore?(this[cu]("ignoredEntry",i),this[Gi]=i.remain?"ignore":"header",i.resume()):(i.remain?this[Gi]="body":(this[Gi]="header",i.end()),this[fa]?this[ga].push(i):(this[ga].push(i),this[EI]())))}}}[UW](){queueMicrotask(()=>this.emit("close"))}[jW](e){let t=!0;if(!e)this[fa]=void 0,t=!1;else if(Array.isArray(e)){let[n,...r]=e;this.emit(n,...r)}else this[fa]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[EI]()),t=!1);return t}[EI](){do;while(this[jW](this[ga].shift()));if(this[ga].length===0){let e=this[fa];!e||e.flowing||e.size===e.remain?this[Sp]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[PI](e,t){let n=this[lu];if(!n)throw Error("attempt to consume body without entry??");let r=n.blockRemain??0,i=r>=e.length&&t===0?e:e.subarray(t,t+r);return n.write(i),n.blockRemain||(this[Gi]="header",this[lu]=void 0,n.end()),i.length}[MW](e,t){let n=this[lu],r=this[PI](e,t);return!this[lu]&&n&&this[NW](n),r}[cu](e,t,n){this[ga].length===0&&!this[fa]?this.emit(e,t,n):this[ga].push([e,t,n])}[NW](e){switch(this[cu]("meta",this[vl]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[ws]=US.parse(this[vl],this[ws],!1);break;case"GlobalExtendedHeader":this[yh]=US.parse(this[vl],this[yh],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let t=this[ws]??Object.create(null);this[ws]=t,t.path=this[vl].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let t=this[ws]||Object.create(null);this[ws]=t,t.linkpath=this[vl].replace(/\0.*/,"");break}default:throw Error("unknown meta: "+e.type)}}abort(e){if(!this[_s]){if(this[on]){let t=this[on];t.write=()=>!0,t.end=()=>t,t.emit=()=>!1,t.destroy?.()}this[_s]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}}[FW](e){this[$I]+=e.length;let t=this[$I]/this[wh];return t>this.maxDecompressionRatio?(this.abort(Error(`max decompression ratio exceeded: ${t.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}write(e,t,n){if(typeof t=="function"&&(n=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this[_s])return n?.(),!1;if((this[on]===void 0||this.brotli===void 0&&this[on]===!1)&&e){if(this[Ht]&&(e=Buffer.concat([this[Ht],e]),this[Ht]=void 0),e.length<KSe)return this[Ht]=e,n?.(),!0;for(let s=0;this[on]===void 0&&s<zI.length;s++)e[s]!==zI[s]&&(this[on]=!1);let i=!1;if(this[on]===!1&&this.zstd!==!1){i=!0;for(let s=0;s<HI.length;s++)if(e[s]!==HI[s]){i=!1;break}}let o=this.brotli===void 0&&!i;if(this[on]===!1&&o)if(e.length<512)if(this[wl])this.brotli=!0;else return this[Ht]=e,n?.(),!0;else try{new gu(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[on]===void 0||this[on]===!1&&(this.brotli||i)){let s=this[wl];this[wl]=!1,this[on]=this[on]===void 0?new ySe({}):i?new bSe({}):new wSe({}),this[on].on("data",(l)=>{this[FW](l)&&this[_S](l)}),this[on].on("error",(l)=>{this[_s]||this.abort(l)}),this[on].on("end",()=>{this[wl]=!0,this[_S]()}),this[Sp]=!0,this[wh]+=e.length;let a=!!this[on][s?"end":"write"](e);return this[Sp]=!1,n?.(),a}}this[Sp]=!0,this[on]?(this[wh]+=e.length,this[on].write(e)):this[_S](e),this[Sp]=!1;let r=this[ga].length>0?!1:this[fa]?this[fa].flowing:!0;return!r&&this[ga].length===0&&this[fa]?.once("drain",()=>this.emit("drain")),n?.(),r}[CI](e){e&&!this[_s]&&(this[Ht]=this[Ht]?Buffer.concat([this[Ht],e]):e)}[SS](){if(this[wl]&&!this[RI]&&!this[_s]&&!this[vh]){this[RI]=!0;let e=this[lu];if(e?.blockRemain){let t=this[Ht]?this[Ht].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${t} available)`,{entry:e}),this[Ht]&&e.write(this[Ht]),e.end()}this[cu](kS)}}[_S](e){if(this[vh]&&e)this[CI](e);else if(!e&&!this[Ht])this[SS]();else if(e){if(this[vh]=!0,this[Ht]){this[CI](e);let t=this[Ht];this[Ht]=void 0,this[bS](t)}else this[bS](e);for(;this[Ht]&&this[Ht]?.length>=512&&!this[_s]&&!this[ES];){let t=this[Ht];this[Ht]=void 0,this[bS](t)}this[vh]=!1}(!this[Ht]||this[wl])&&this[SS]()}[bS](e){let t=0,n=e.length;for(;t+512<=n&&!this[_s]&&!this[ES];)switch(this[Gi]){case"begin":case"header":this[LW](e,t),t+=512;break;case"ignore":case"body":t+=this[PI](e,t);break;case"meta":t+=this[MW](e,t);break;default:throw Error("invalid state: "+this[Gi])}t<n&&(this[Ht]=this[Ht]?Buffer.concat([e.subarray(t),this[Ht]]):e.subarray(t))}end(e,t,n){return typeof e=="function"&&(n=e,t=void 0,e=void 0),typeof t=="function"&&(n=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t)),n&&this.once("finish",n),this[_s]||(this[on]?(e&&(this[wh]+=e.length,this[on].write(e)),this[on].end()):(this[wl]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[SS]())),this}},Cl=Nh(YSe,XSe,(e)=>new jh(e),(e)=>new jh(e),(e,t)=>{t?.length&&_9(e,t),e.noResume||ZSe(e)}),{isAbsolute:eke,parse:HW}=QSe,KS=["|","<",">","?",":"],dO=KS.map((e)=>String.fromCodePoint(61440+Number(e.codePointAt(0)))),tke=new Map(KS.map((e,t)=>[e,dO[t]])),nke=new Map(dO.map((e,t)=>[e,KS[t]])),VW=Symbol("process"),qW=Symbol("file"),WW=Symbol("directory"),BI=Symbol("symlink"),KW=Symbol("hardlink"),_h=Symbol("header"),IS=Symbol("read"),VI=Symbol("lstat"),OS=Symbol("onlstat"),qI=Symbol("onread"),WI=Symbol("onreadlink"),KI=Symbol("openfile"),GI=Symbol("onopenfile"),Al=Symbol("close"),zS=Symbol("mode"),JI=Symbol("awaitDrain"),xI=Symbol("ondrain"),Ss=Symbol("prefix"),k9=class extends hu{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 n=aO(t);super(),this.path=Ne(e),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||ike,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=Ne(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?Ne(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let r=!1;if(!this.preservePaths){let[o,s]=uO(this.path);o&&typeof s=="string"&&(this.path=s,r=o)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=rke(this.path.replaceAll(/\\/g,"/")),e=e.replaceAll(/\\/g,"/")),this.absolute=Ne(n.absolute||zW.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 i=this.statCache.get(this.absolute);i?this[OS](i):this[VI]()}warn(e,t,n={}){return WS(this,e,t,n)}emit(e,...t){return e==="error"&&(this.#e=!0),super.emit(e,...t)}[VI](){bs.lstat(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[OS](t)})}[OS](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=ake(e),this.emit("stat",e),this[VW]()}[VW](){switch(this.type){case"File":return this[qW]();case"Directory":return this[WW]();case"SymbolicLink":return this[BI]();default:return this.end()}}[zS](e){return b9(e,this.type==="Directory",this.portable)}[Ss](e){return S9(e,this.prefix)}[_h](){if(!this.stat)throw Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new gu({path:this[Ss](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ss](this.linkpath):this.linkpath,mode:this[zS](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 US({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[Ss](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ss](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 Error("failed to encode header");super.write(e)}[WW](){if(!this.stat)throw Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[_h](),this.end()}[BI](){bs.readlink(this.absolute,(e,t)=>{if(e)return this.emit("error",e);this[WI](t)})}[WI](e){this.linkpath=Ne(e),this[_h](),this.end()}[KW](e){if(!this.stat)throw Error("cannot create link entry without stat");this.type="Link",this.linkpath=Ne(zW.relative(this.cwd,e)),this.stat.size=0,this[_h](),this.end()}[qW](){if(!this.stat)throw 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[KW](t);this.linkCache.set(e,this.absolute)}if(this[_h](),this.stat.size===0)return this.end();this[KI]()}[KI](){bs.open(this.absolute,"r",(e,t)=>{if(e)return this.emit("error",e);this[GI](t)})}[GI](e){if(this.fd=e,this.#e)return this[Al]();if(!this.stat)throw 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[IS]()}[IS](){let{fd:e,buf:t,offset:n,length:r,pos:i}=this;if(e===void 0||t===void 0)throw Error("cannot read file without first opening");bs.read(e,t,n,r,i,(o,s)=>{if(o)return this[Al](()=>this.emit("error",o));this[qI](s)})}[Al](e=()=>{}){this.fd!==void 0&&bs.close(this.fd,e)}[qI](e){if(e<=0&&this.remain>0){let n=Object.assign(Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Al](()=>this.emit("error",n))}if(e>this.remain){let n=Object.assign(Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Al](()=>this.emit("error",n))}if(!this.buf)throw Error("should have created buffer prior to reading");if(e===this.remain)for(let n=e;n<this.length&&e<this.blockRemain;n++)this.buf[n+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[xI]():this[JI](()=>this[xI]())}[JI](e){this.once("drain",e)}write(e,t,n){if(typeof t=="function"&&(n=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof t=="string"?t:"utf8")),this.blockRemain<e.length){let r=Object.assign(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,n)}[xI](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[Al]((e)=>e?this.emit("error",e):this.end());if(!this.buf)throw 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[IS]()}},oke=class extends k9{sync=!0;[VI](){this[OS](bs.lstatSync(this.absolute))}[BI](){this[WI](bs.readlinkSync(this.absolute))}[KI](){this[GI](bs.openSync(this.absolute,"r"))}[IS](){let e=!0;try{let{fd:t,buf:n,offset:r,length:i,pos:o}=this;if(t===void 0||n===void 0)throw Error("fd and buf must be set in READ method");let s=bs.readSync(t,n,r,i,o);this[qI](s),e=!1}finally{if(e)try{this[Al](()=>{})}catch{}}}[JI](e){e()}[Al](e=()=>{}){this.fd!==void 0&&bs.closeSync(this.fd),e()}},ske=class extends hu{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,n={}){return WS(this,e,t,n)}constructor(e,t={}){let n=aO(t);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=Ne(e.path),this.mode=e.mode!==void 0?this[zS](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:n.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?Ne(e.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let i=!1;if(!this.preservePaths){let[s,a]=uO(this.path);s&&typeof a=="string"&&(this.path=a,i=s)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new gu({path:this[Ss](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ss](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}),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path}),this.header.encode()&&!this.noPax&&super.write(new US({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[Ss](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ss](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 o=this.header?.block;if(!o)throw Error("failed to encode header");super.write(o),e.pipe(this)}[Ss](e){return S9(e,this.prefix)}[zS](e){return b9(e,this.type==="Directory",this.portable)}write(e,t,n){typeof t=="function"&&(n=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 Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,n)}end(e,t,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(n=e,t=void 0,e=void 0),typeof t=="function"&&(n=t,t=void 0),typeof e=="string"&&(e=Buffer.from(e,t??"utf8")),n&&this.once("finish",n),e?super.end(e,n):super.end(n),this}},lke=class e{tail;head;length=0;static create(t=[]){return new e(t)}constructor(t=[]){for(let n of t)this.push(n)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw Error("removing node which does not belong to this list");let{next:n,prev:r}=t;return n&&(n.prev=r),r&&(r.next=n),t===this.head&&(this.head=n),t===this.tail&&(this.tail=r),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,n}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);let n=this.head;t.list=this,t.next=n,n&&(n.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 n=this.tail;t.list=this,t.prev=n,n&&(n.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let n=0,r=t.length;n<r;n++)uke(this,t[n]);return this.length}unshift(...t){for(var n=0,r=t.length;n<r;n++)dke(this,t[n]);return this.length}pop(){if(!this.tail)return;let t=this.tail.value,n=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,n.list=void 0,this.length--,t}shift(){if(!this.head)return;let t=this.head.value,n=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,n.list=void 0,this.length--,t}forEach(t,n){n=n||this;for(let r=this.head,i=0;r;i++)t.call(n,r.value,i,this),r=r.next}forEachReverse(t,n){n=n||this;for(let r=this.tail,i=this.length-1;r;i--)t.call(n,r.value,i,this),r=r.prev}get(t){let n=0,r=this.head;for(;r&&n<t;n++)r=r.next;if(n===t&&r)return r.value}getReverse(t){let n=0,r=this.tail;for(;r&&n<t;n++)r=r.prev;if(n===t&&r)return r.value}map(t,n){n=n||this;let r=new e;for(let i=this.head;i;)r.push(t.call(n,i.value,this)),i=i.next;return r}mapReverse(t,n){n=n||this;var r=new e;for(let i=this.tail;i;)r.push(t.call(n,i.value,this)),i=i.prev;return r}reduce(t,n){let r,i=this.head;if(arguments.length>1)r=n;else if(this.head)i=this.head.next,r=this.head.value;else throw TypeError("Reduce of empty list with no initial value");for(var o=0;i;o++)r=t(r,i.value,o),i=i.next;return r}reduceReverse(t,n){let r,i=this.tail;if(arguments.length>1)r=n;else if(this.tail)i=this.tail.prev,r=this.tail.value;else throw TypeError("Reduce of empty list with no initial value");for(let o=this.length-1;i;o--)r=t(r,i.value,o),i=i.prev;return r}toArray(){let t=Array(this.length);for(let n=0,r=this.head;r;n++)t[n]=r.value,r=r.next;return t}toArrayReverse(){let t=Array(this.length);for(let n=0,r=this.tail;r;n++)t[n]=r.value,r=r.prev;return t}slice(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.head,o=0;for(o=0;i&&o<t;o++)i=i.next;for(;i&&o<n;o++,i=i.next)r.push(i.value);return r}sliceReverse(t=0,n=this.length){n<0&&(n+=this.length),t<0&&(t+=this.length);let r=new e;if(n<t||n<0)return r;t<0&&(t=0),n>this.length&&(n=this.length);let i=this.length,o=this.tail;for(;o&&i>n;i--)o=o.prev;for(;o&&i>t;i--,o=o.prev)r.push(o.value);return r}splice(t,n=0,...r){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let i=this.head;for(let s=0;i&&s<t;s++)i=i.next;let o=[];for(let s=0;i&&s<n;s++)o.push(i.value),i=this.removeNode(i);i?i!==this.tail&&(i=i.prev):i=this.tail;for(let s of r)i=cke(this,i,s);return o}reverse(){let t=this.head,n=this.tail;for(let r=t;r;r=r.prev){let i=r.prev;r.prev=r.next,r.next=i}return this.head=n,this.tail=t,this}};ZW=Buffer.alloc(1024),DS=Symbol("onStat"),bh=Symbol("ended"),Po=Symbol("queue"),Sh=Symbol("pendingLinks"),_l=Symbol("current"),du=Symbol("process"),kh=Symbol("processing"),RS=Symbol("processJob"),Co=Symbol("jobs"),II=Symbol("jobDone"),TS=Symbol("addFSEntry"),YW=Symbol("addTarEntry"),ZI=Symbol("stat"),YI=Symbol("readdir"),jS=Symbol("onreaddir"),NS=Symbol("pipe"),XW=Symbol("entry"),OI=Symbol("entryOpt"),MS=Symbol("writeEntryClass"),A9=Symbol("write"),DI=Symbol("ondrain"),GS=class extends hu{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[MS];onWriteEntry;[Po];[Sh]=new Map;[Co]=0;[kh]=!1;[bh]=!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=Ne(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[MS]=k9,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 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 hSe(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new vSe(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new _Se(e.zstd)),!this.zip)throw Error("impossible");let t=this.zip;t.on("data",(n)=>super.write(n)),t.on("end",()=>super.end()),t.on("drain",()=>this[DI]()),this.on("resume",()=>t.resume())}else this.on("drain",this[DI]);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[Po]=new lke,this[Co]=0,this.jobs=Number(e.jobs)||4,this[kh]=!1,this[bh]=!1}[A9](e){return super.write(e)}add(e){return this.write(e),this}end(e,t,n){return typeof e=="function"&&(n=e,e=void 0),typeof t=="function"&&(n=t,t=void 0),e&&this.add(e),this[bh]=!0,this[du](),n&&n(),this}write(e){if(this[bh])throw Error("write after end");return typeof e=="string"?this[TS](e):this[YW](e),this.flowing}[YW](e){let t=Ne(GW.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let n=new JW(e.path,t);n.entry=new ske(e,this[OI](n)),n.entry.on("end",()=>this[II](n)),this[Co]+=1,this[Po].push(n)}this[du]()}[TS](e){let t=Ne(GW.resolve(this.cwd,e));this[Po].push(new JW(e,t)),this[du]()}[ZI](e){e.pending=!0,this[Co]+=1;let t=this.follow?"stat":"lstat";FS[t](e.absolute,(n,r)=>{e.pending=!1,this[Co]-=1,n?this.emit("error",n):this[DS](e,r)})}[DS](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[_l])this[RS](e);else{let n=`${t.dev}:${t.ino}`,r=this[Sh].get(n);r?r.push(e):this[Sh].set(n,[e]),e.pendingLink=!0,e.pending=!0}this[du]()}[YI](e){e.pending=!0,this[Co]+=1,FS.readdir(e.absolute,(t,n)=>{if(e.pending=!1,this[Co]-=1,t)return this.emit("error",t);this[jS](e,n)})}[jS](e,t){this.readdirCache.set(e.absolute,t),e.readdir=t,this[du]()}[du](){if(!this[kh]){this[kh]=!0;for(let e=this[Po].head;e&&this[Co]<this.jobs;e=e.next)if(this[RS](e.value),e.value.ignore){let t=e.next;this[Po].removeNode(e),e.next=t}this[kh]=!1,this[bh]&&this[Po].length===0&&this[Co]===0&&(this.zip?this.zip.end(ZW):(super.write(ZW),super.end()))}}get[_l](){return this[Po]&&this[Po].head&&this[Po].head.value}[II](e){this[Po].shift(),this[Co]-=1;let{stat:t}=e;if(t&&t.isFile()&&t.nlink>1){let n=`${t.dev}:${t.ino}`,r=this[Sh].get(n);if(r){this[Sh].delete(n);for(let i of r)i.pending=!1,this[RS](i)}}this[du]()}[RS](e){if(e.pending&&e.pendingLink&&e===this[_l]&&(e.pending=!1,e.pendingLink=!1),!e.pending){if(e.entry){e===this[_l]&&!e.piped&&this[NS](e);return}if(!e.stat){let t=this.statCache.get(e.absolute);t?this[DS](e,t):this[ZI](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let t=this.readdirCache.get(e.absolute);if(t?this[jS](e,t):this[YI](e),!e.readdir)return}if(e.entry=this[XW](e),!e.entry){e.ignore=!0;return}e===this[_l]&&!e.piped&&this[NS](e)}}}[OI](e){return{onwarn:(t,n,r)=>this.warn(t,n,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}}[XW](e){this[Co]+=1;try{return new this[MS](e.path,this[OI](e)).on("end",()=>this[II](e)).on("error",(t)=>this.emit("error",t))}catch(t){this.emit("error",t)}}[DI](){this[_l]&&this[_l].entry&&this[_l].entry.resume()}[NS](e){e.piped=!0,e.readdir&&e.readdir.forEach((r)=>{let i=e.path,o=i==="./"?"":i.replace(/\/*$/,"/");this[TS](o+r)});let t=e.entry,n=this.zip;if(!t)throw Error("cannot pipe without source");n?t.on("data",(r)=>{n.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,n={}){WS(this,e,t,n)}},mO=class extends GS{sync=!0;constructor(e){super(e),this[MS]=oke}pause(){}resume(){}[ZI](e){let t=this.follow?"statSync":"lstatSync";this[DS](e,FS[t](e.absolute))}[YI](e){this[jS](e,FS.readdirSync(e.absolute))}[NS](e){let t=e.entry,n=this.zip;if(e.readdir&&e.readdir.forEach((r)=>{let i=e.path,o=i==="./"?"":i.replace(/\/*$/,"/");this[TS](o+r)}),!t)throw Error("Cannot pipe without source");n?t.on("data",(r)=>{n.write(r)}):t.on("data",(r)=>{super[A9](r)})}},fO=Nh(pke,mke,fke,gke,(e,t)=>{if(!t?.length)throw TypeError("no paths specified to add to archive")}),yke=process.env.__FAKE_PLATFORM__||process.platform,x9=yke==="win32",{O_CREAT:I9,O_NOFOLLOW:QW,O_TRUNC:O9,O_WRONLY:D9}=$9.constants,T9=Number(process.env.__FAKE_FS_O_FILENAME__)||$9.constants.UV_FS_O_FILEMAP||0,vke=x9&&!!T9,_ke=T9|O9|I9|D9,e9=!x9&&typeof QW=="number"?QW|O9|I9|D9:null,j9=e9!==null?()=>e9:vke?(e)=>e<wke?_ke:"w":()=>"w",L9=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"}},ZS=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"}},TI=Object.create(null),kp=new Set,$ke=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,xke=$ke==="win32",n9=Symbol("onEntry"),eO=Symbol("checkFs"),r9=Symbol("checkFs2"),tO=Symbol("isReusable"),Ji=Symbol("makeFs"),nO=Symbol("file"),rO=Symbol("directory"),LS=Symbol("link"),i9=Symbol("symlink"),o9=Symbol("hardlink"),Rh=Symbol("ensureNoSymlink"),s9=Symbol("unsupported"),a9=Symbol("checkPath"),jI=Symbol("stripAbsolutePath"),El=Symbol("mkdir"),Ln=Symbol("onError"),PS=Symbol("pending"),l9=Symbol("pend"),Ap=Symbol("unpend"),NI=Symbol("ended"),MI=Symbol("maybeClose"),iO=Symbol("skip"),xh=Symbol("doChown"),Ih=Symbol("uid"),Oh=Symbol("gid"),Dh=Symbol("checkedCwd"),Tke=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Th=Tke==="win32",gO=class extends jh{[NI]=!1;[Dh]=!1;[PS]=0;reservations=new Oke;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[NI]=!0,this[MI]()},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 TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw 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:jke,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Th,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=Ne(Pn.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:Dke():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[n9](t))}warn(e,t,n={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(n.recoverable=!1),super.warn(e,t,n)}[MI](){this[NI]&&this[PS]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[jI](e,t){let n=e[t],{type:r}=e;if(!n||this.preservePaths)return!0;let[i,o]=uO(n),s=o.replaceAll(/\\/g,"/").split("/");if(s.includes("..")||Th&&/^[a-z]:\.\.$/i.test(s[0]??"")){if(t==="path"||r==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:n}),!1;let a=Pn.posix.dirname(e.path),l=Pn.posix.normalize(Pn.posix.join(a,s.join("/")));if(l.startsWith("../")||l==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:n}),!1}return i&&(e[t]=String(o),this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute ${t}`,{entry:e,[t]:n})),!0}[a9](e){let t=Ne(e.path),n=t.split("/");if(this.strip){if(n.length<this.strip)return!1;if(e.type==="Link"){let r=Ne(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}n.splice(0,this.strip),e.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this[jI](e,"path")||!this[jI](e,"linkpath"))return!1;if(e.absolute=Pn.isAbsolute(e.path)?Ne(Pn.resolve(e.path)):Ne(Pn.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:Ne(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}=Pn.win32.parse(String(e.absolute));e.absolute=r+BW(String(e.absolute).slice(r.length));let{root:i}=Pn.win32.parse(e.path);e.path=i+BW(e.path.slice(i.length))}return!0}[n9](e){if(!this[a9](e))return e.resume();switch(hke.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[eO](e);default:return this[s9](e)}}[Ln](e,t){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:t}),this[Ap](),t.resume())}[El](e,t,n){Eke(Ne(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},n)}[xh](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}[Ih](e){return c9(this.uid,e.uid,this.processUid)}[Oh](e){return c9(this.gid,e.gid,this.processGid)}[nO](e,t){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new VS(String(e.absolute),{flags:j9(e.size),mode:n,autoClose:!1});r.on("error",(a)=>{r.fd&&Ke.close(r.fd,()=>{}),r.write=()=>!0,this[Ln](a,e),t()});let i=1,o=(a)=>{if(a){r.fd&&Ke.close(r.fd,()=>{}),this[Ln](a,e),t();return}--i===0&&r.fd!==void 0&&Ke.close(r.fd,(l)=>{l?this[Ln](l,e):this[Ap](),t()})};r.on("finish",()=>{let a=String(e.absolute),l=r.fd;if(typeof l=="number"&&e.mtime&&!this.noMtime){i++;let c=e.atime||new Date,u=e.mtime;Ke.futimes(l,c,u,(d)=>d?Ke.utimes(a,c,u,(p)=>o(p&&d)):o())}if(typeof l=="number"&&this[xh](e)){i++;let c=this[Ih](e),u=this[Oh](e);typeof c=="number"&&typeof u=="number"&&Ke.fchown(l,c,u,(d)=>d?Ke.chown(a,c,u,(p)=>o(p&&d)):o())}o()});let s=this.transform&&this.transform(e)||e;s!==e&&(s.on("error",(a)=>{this[Ln](a,e),t()}),e.pipe(s)),s.pipe(r)}[rO](e,t){let n=typeof e.mode=="number"?e.mode&4095:this.dmode;this[El](String(e.absolute),n,(r)=>{if(r){this[Ln](r,e),t();return}let i=1,o=()=>{--i===0&&(t(),this[Ap](),e.resume())};e.mtime&&!this.noMtime&&(i++,Ke.utimes(String(e.absolute),e.atime||new Date,e.mtime,o)),this[xh](e)&&(i++,Ke.chown(String(e.absolute),Number(this[Ih](e)),Number(this[Oh](e)),o)),o()})}[s9](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[i9](e,t){let n=Ne(Pn.relative(this.cwd,Pn.resolve(Pn.dirname(String(e.absolute)),String(e.linkpath)))).split("/");this[Rh](e,this.cwd,n,()=>this[LS](e,String(e.linkpath),"symlink",t),(r)=>{this[Ln](r,e),t()})}[o9](e,t){let n=Ne(Pn.resolve(this.cwd,String(e.linkpath))),r=Ne(String(e.linkpath)).split("/");this[Rh](e,this.cwd,r,()=>this[LS](e,n,"link",t),(i)=>{this[Ln](i,e),t()})}[Rh](e,t,n,r,i){let o=n.shift();if(this.preservePaths||o===void 0)return r();let s=Pn.resolve(t,o);Ke.lstat(s,(a,l)=>{if(a)return r();if(l?.isSymbolicLink())return i(new ZS(s,Pn.resolve(s,n.join("/"))));this[Rh](e,s,n,r,i)})}[l9](){this[PS]++}[Ap](){this[PS]--,this[MI]()}[iO](e){this[Ap](),e.resume()}[tO](e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!Th}[eO](e){this[l9]();let t=[e.path];e.linkpath&&t.push(e.linkpath),this.reservations.reserve(t,(n)=>this[r9](e,n))}[r9](e,t){let n=(s)=>{t(s)},r=()=>{this[El](this.cwd,this.dmode,(s)=>{if(s){this[Ln](s,e),n();return}this[Dh]=!0,i()})},i=()=>{if(e.absolute!==this.cwd){let s=Ne(Pn.dirname(String(e.absolute)));if(s!==this.cwd)return this[El](s,this.dmode,(a)=>{if(a){this[Ln](a,e),n();return}o()})}o()},o=()=>{Ke.lstat(String(e.absolute),(s,a)=>{if(a&&(this.keep||this.newer&&a.mtime>(e.mtime??a.mtime))){this[iO](e),n();return}if(s||this[tO](e,a))return this[Ji](null,e,n);if(a.isDirectory()){if(e.type==="Directory"){let l=this.chmod&&e.mode&&(a.mode&4095)!==e.mode,c=(u)=>this[Ji](u??null,e,n);return l?Ke.chmod(String(e.absolute),Number(e.mode),c):c()}if(e.absolute!==this.cwd)return Ke.rmdir(String(e.absolute),(l)=>this[Ji](l??null,e,n))}if(e.absolute===this.cwd)return this[Ji](null,e,n);Nke(String(e.absolute),(l)=>this[Ji](l??null,e,n))})};this[Dh]?i():r()}[Ji](e,t,n){if(e){this[Ln](e,t),n();return}switch(t.type){case"File":case"OldFile":case"ContiguousFile":return this[nO](t,n);case"Link":return this[o9](t,n);case"SymbolicLink":return this[i9](t,n);case"Directory":case"GNUDumpDir":return this[rO](t,n)}}[LS](e,t,n,r){Ke[n](t,String(e.absolute),(i)=>{i?this[Ln](i,e):(this[Ap](),e.resume()),r()})}},z9=class extends gO{sync=!0;[Ji](e,t){return super[Ji](e,t,()=>{})}[eO](e){if(!this[Dh]){let i=this[El](this.cwd,this.dmode);if(i)return this[Ln](i,e);this[Dh]=!0}if(e.absolute!==this.cwd){let i=Ne(Pn.dirname(String(e.absolute)));if(i!==this.cwd){let o=this[El](i,this.dmode);if(o)return this[Ln](o,e)}}let[t,n]=Ah(()=>Ke.lstatSync(String(e.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(e.mtime??n.mtime)))return this[iO](e);if(t||this[tO](e,n))return this[Ji](null,e);if(n.isDirectory()){if(e.type==="Directory"){let o=this.chmod&&e.mode&&(n.mode&4095)!==e.mode,[s]=o?Ah(()=>{Ke.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[Ji](s,e)}let[i]=Ah(()=>Ke.rmdirSync(String(e.absolute)));this[Ji](i,e)}let[r]=e.absolute===this.cwd?[]:Ah(()=>Mke(String(e.absolute)));this[Ji](r,e)}[nO](e,t){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,r=(s)=>{let a;try{Ke.closeSync(i)}catch(l){a=l}(s||a)&&this[Ln](s||a,e),t()},i;try{i=Ke.openSync(String(e.absolute),j9(e.size),n)}catch(s){return r(s)}let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",(s)=>this[Ln](s,e)),e.pipe(o)),o.on("data",(s)=>{try{Ke.writeSync(i,s,0,s.length)}catch(a){r(a)}}),o.on("end",()=>{let s=null;if(e.mtime&&!this.noMtime){let a=e.atime||new Date,l=e.mtime;try{Ke.futimesSync(i,a,l)}catch(c){try{Ke.utimesSync(String(e.absolute),a,l)}catch{s=c}}}if(this[xh](e)){let a=this[Ih](e),l=this[Oh](e);try{Ke.fchownSync(i,Number(a),Number(l))}catch(c){try{Ke.chownSync(String(e.absolute),Number(a),Number(l))}catch{s=s||c}}}r(s)})}[rO](e,t){let n=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[El](String(e.absolute),n);if(r){this[Ln](r,e),t();return}if(e.mtime&&!this.noMtime)try{Ke.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[xh](e))try{Ke.chownSync(String(e.absolute),Number(this[Ih](e)),Number(this[Oh](e)))}catch{}t(),e.resume()}[El](e,t){try{return Pke(Ne(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(n){return n}}[Rh](e,t,n,r,i){if(this.preservePaths||n.length===0)return r();let o=t;for(let s of n){o=Pn.resolve(o,s);let[a,l]=Ah(()=>Ke.lstatSync(o));if(a)return r();if(l.isSymbolicLink())return i(new ZS(o,Pn.resolve(t,n.join("/"))))}r()}[LS](e,t,n,r){let i=`${n}Sync`;try{Ke[i](t,String(e.absolute)),r(),e.resume()}catch(o){return this[Ln](o,e)}}},Mh=Nh(Lke,Uke,(e)=>new z9(e),(e)=>new gO(e),(e,t)=>{t?.length&&_9(e,t)}),Eh=Nh(Fke,Hke,()=>{throw TypeError("file is required")},()=>{throw TypeError("file is required")},(e,t)=>{if(!cSe(e))throw TypeError("file is required");if(e.gzip||e.brotli||e.zstd||e.file.endsWith(".br")||e.file.endsWith(".tbr"))throw TypeError("cannot append to compressed archives");if(!t?.length)throw TypeError("no paths specified to add/replace")}),cvt=Nh(Eh.syncFile,Eh.asyncFile,Eh.syncNoFile,Eh.asyncNoFile,(e,t=[])=>{Eh.validate?.(e,t),qke(e)})});var V9=()=>{};function q9(e){return Array.from(e.trim()).length}var yO=2,vO=500;var wO=200,W9="^[A-Za-z0-9][A-Za-z0-9._-]{0,199}(/[A-Za-z0-9][A-Za-z0-9._-]{0,199}){0,3}$",K9;var G9=b(()=>{K9=["download","content","install"]});var YS=b(()=>{V9();G9()});function Gke(e){let t=e.split("/");return t.length>1&&Kke.has(t[t.length-1]??"")}function Qt(e){return e.length<=wO&&Wke.test(e)&&!Gke(e)}function yu(e){if(!Qt(e))throw new XS(e)}function Ip(e){let n=e.toLowerCase().replace(/[^a-z0-9._]+/g,"-").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g,"").substring(0,wO)||"unnamed-skill";return yu(n),n}var Wke,Kke,XS;var Io=b(()=>{YS();Wke=new RegExp(W9),Kke=new Set(K9);XS=class XS extends Error{constructor(e){super(`Invalid skill_key: ${JSON.stringify(e)}`);this.name="SkillKeyValidationError"}}});import{createHash as Jke}from"node:crypto";import{existsSync as _O,lstatSync as Zke,mkdirSync as J9,mkdtempSync as Yke,realpathSync as Xke,renameSync as bO,rmSync as Z9}from"node:fs";import{lstat as Y9,readdir as Qke,realpath as QS}from"node:fs/promises";import{basename as X9,dirname as SO,isAbsolute as eAe,join as ek,relative as tAe,resolve as nAe}from"node:path";import{createGunzip as rAe,gunzipSync as iAe}from"node:zlib";function AO(e){return e==="File"||e==="OldFile"||e==="ContiguousFile"}function oAe(e){return AO(e)||e==="Directory"}function Q9(e){return e.split(/[\\/]/).some((t)=>t.toLowerCase().startsWith(".clawdi-managed"))}function e5(e){let t=e.limits??tk,n="fileCount"in t?t.fileCount:void 0,r=e.resourceLabel??"Skill archive",i=0,o=0,s=0;return(a,l)=>{if(e.filter&&!e.filter(a,l))return!1;if(a.includes("..")||a.startsWith("/"))return!1;if(!e.allowReservedManagementPaths&&Q9(a))throw Error(`${r} contains reserved management metadata`);let c="type"in l?l.type:void 0;if(!oAe(c))throw Error(`${r} contains an unsupported entry type`);if(i+=1,i>t.entryCount)throw Error(`${r} exceeds ${t.entryCount} entries`);let u=l.size;if(!Number.isSafeInteger(u)||u<0)throw Error(`${r} contains an invalid entry size`);if(u>t.entryBytes)throw Error(`${r} entry exceeds ${t.entryBytes} bytes`);if(AO(c)){if(o+=1,n!==void 0&&o>n)throw Error(`${r} exceeds ${n} files`)}if(s+=u,s>t.totalEntryBytes)throw Error(`${r} exceeds ${t.totalEntryBytes} total entry bytes`);return!0}}function Oo(e,t,n={}){let r=n.limits??tk,i=n.resourceLabel??"Skill archive";return sAe(t,r.expandedTarBytes,i).then(()=>new Promise((o,s)=>{let a=Mh({cwd:e,gzip:!0,filter:e5(n)});a.on("close",()=>o()),a.on("error",s),a.end(t)}))}function t5(e,t,n={}){let r=n.limits??tk,i=n.resourceLabel??"Skill archive",o;try{o=iAe(t,{maxOutputLength:r.expandedTarBytes})}catch(a){throw Error(`${i} is invalid or exceeds ${r.expandedTarBytes} expanded tar bytes`,{cause:a})}Mh({cwd:e,sync:!0,filter:e5(n)}).end(o)}function sAe(e,t=tk.expandedTarBytes,n="Skill archive"){return new Promise((r,i)=>{let o=0,s=!1,a=rAe(),l=(c)=>{if(s)return;s=!0,a.destroy(),i(c)};a.on("error",(c)=>l(c)),a.on("data",(c)=>{if(o+=c.length,o>t)l(Error(`${n} exceeds ${t} expanded tar bytes`))}),a.on("end",()=>{if(s)return;s=!0,r()}),a.end(e)})}async function va(e,t,n,r,i,o=(s)=>s()){yu(e);let s=tAe(t,n);if(!s||s.startsWith("..")||eAe(s))throw Error(`Skill target must be inside skills root: ${n}`);J9(t,{recursive:!0});let a=Xke(t),l=SO(a),c=Yke(ek(l,`.${X9(t)}-stage-`)),u=ek(c,e),d=ek(c,".previous"),p=!1;try{if(await Oo(c,r),!_O(u)||!Zke(u).isDirectory())throw Error(`Skill tarball did not contain expected '${e}/' root entry`);J9(SO(n),{recursive:!0}),o(()=>{let m=!1;if(_O(n))bO(n,d),m=!0;try{i?.(),bO(u,n)}catch(g){if(!m)throw g;try{bO(d,n)}catch(f){p=!0;let v=g instanceof Error?g.message:String(g),w=f instanceof Error?f.message:String(f);throw Error(`Skill install failed: ${v}; restoring the previous version failed: ${w}; previous version retained at ${d}`,{cause:g})}throw g}if(_O(d))Z9(d,{recursive:!0,force:!0})})}finally{if(!p)Z9(c,{recursive:!0,force:!0})}}async function aAe(e,t){let n=await QS(e),r=Array.isArray(t)?t:t!==void 0?[t]:[SO(n)],i=await Promise.all(r.map((u)=>QS(u).catch(()=>u))),o=(u)=>{for(let d of i)if(u===d||u.startsWith(`${d}/`))return!0;return!1},s=[],a=new Set,l=new Set,c=async(u)=>{let d;try{d=await QS(u)}catch{s.push(u);return}if(l.has(d)){s.push(u);return}if(a.has(d))return;l.add(d);let p=await Qke(u,{withFileTypes:!0});try{for(let m of p){if(kO.has(m.name))continue;let g=ek(u,m.name);if(m.isSymbolicLink()){try{let f=await QS(g);if(!o(f)){s.push(g);continue}if((await Y9(f)).isDirectory())await c(f)}catch{s.push(g)}continue}if(m.isDirectory())try{if((await Y9(g)).isDirectory())await c(g)}catch{}}}finally{l.delete(d),a.add(d)}};return await c(e),s}async function EO(e,t,n){let r=n??X9(e),i=r.split("/").filter(Boolean),o=e;for(let l=0;l<i.length;l++)o=nAe(o,"..");let s=await aAe(e,t??o);if(s.length>0)throw Error(`Skill contains symlink(s) pointing outside the agent's skills directory, broken, or cyclic; refusing to upload: ${s.join(", ")}`);let a=[];return await fO({gzip:!0,cwd:o,follow:!0,filter:(l)=>{if(Q9(l))throw Error("Skill contains reserved management metadata");return!l.split("/").slice(i.length).some((u)=>kO.has(u))}},[r]).on("data",(l)=>a.push(l)).promise(),Buffer.concat(a)}async function lAe(e,t){let n=t?t.split("/").length:1,r=[],i=Cl({gzip:!0,onReadEntry:(a)=>{if(!AO(a.type)){a.resume();return}let c=a.path.split("/").slice(n),u=c.join("/");if(!u||c.some((d)=>kO.has(d))){a.resume();return}r.push(a.concat().then((d)=>({relativePath:u,content:Buffer.from(d)})))}});await new Promise((a,l)=>{i.on("end",a),i.on("error",l),i.end(e)});let o=await Promise.all(r);o.sort((a,l)=>cAe(a.relativePath,l.relativePath));let s=Jke("sha256");for(let a of o)s.update(a.relativePath),s.update(a.content);return s.digest("hex")}function cAe(e,t){let n=e[Symbol.iterator](),r=t[Symbol.iterator]();while(!0){let i=n.next(),o=r.next();if(i.done||o.done){if(i.done&&o.done)return 0;return i.done?-1:1}let s=i.value.codePointAt(0),a=o.value.codePointAt(0);if(s===void 0||a===void 0)throw Error("Unicode iterator returned an empty code point");if(s!==a)return s<a?-1:1}}async function gr(e,t,n){let r=await EO(e,t,n);return{archive:r,hash:await lAe(r,n)}}async function n5(e,t){let{mkdtempSync:n,writeFileSync:r,mkdirSync:i,rmSync:o}=await import("node:fs"),{tmpdir:s}=await import("node:os"),{join:a}=await import("node:path"),l=n(a(s(),"clawdi-skill-")),c=a(l,e);i(c,{recursive:!0}),r(a(c,"SKILL.md"),t);let u=[];await fO({gzip:!0,cwd:l},[e]).on("data",(p)=>u.push(p)).promise();let d=Buffer.concat(u);return o(l,{recursive:!0,force:!0}),d}var kO,tk;var Gr=b(()=>{hO();Io();kO=new Set(["node_modules",".git",".turbo",".cache","dist","build","out","target","__pycache__",".venv","venv",".pytest_cache",".mypy_cache",".ruff_cache",".tox","coverage",".agents",".cursor",".factory",".openclaw",".hermes",".gbrain",".claude",".codex"]),tk=Object.freeze({entryCount:1024,entryBytes:16777216,totalEntryBytes:33554432,expandedTarBytes:37748736})});import{createHash as r5}from"node:crypto";import{lstatSync as i5,readdirSync as uAe,readFileSync as dAe}from"node:fs";import{join as pAe}from"node:path";function $l(e,t){let n=t.resourceLabel??"file tree",r=i5(e);if(!r.isDirectory()||r.isSymbolicLink())throw Error(`${n} root is not a trusted directory`);let i=[],o=new Set,s=0,a=0,l=(c,u)=>{for(let d of uAe(c).sort((p,m)=>Buffer.compare(Buffer.from(p,"utf8"),Buffer.from(m,"utf8")))){let p=u?`${u}/${d}`:d;if(t.exclude?.(p))continue;t.validatePath?.(p);let m=t.collisionKey?.(p);if(m!==void 0){if(o.has(m))throw Error(t.collisionError??`${n} contains a path collision`);o.add(m)}if(s+=1,s>t.limits.entries)throw Error(`${n} exceeds ${t.limits.entries} entries`);let g=pAe(c,d),f=i5(g);if(f.isDirectory()&&!f.isSymbolicLink()){l(g,p);continue}if(!f.isFile()||f.isSymbolicLink())throw Error(`${n} contains a non-regular entry`);if(i.length>=t.limits.files)throw Error(`${n} exceeds ${t.limits.files} files`);if(f.size>t.limits.fileBytes)throw Error(`${n} file exceeds ${t.limits.fileBytes} bytes`);if(a+=f.size,a>t.limits.totalBytes)throw Error(`${n} exceeds ${t.limits.totalBytes} total file bytes`);let v=dAe(g);if(v.length!==f.size)throw Error(`${n} changed while reading`);i.push({path:p,mode:(f.mode&73)!==0?33261:33188,bytes:v})}};return l(e,""),i}function Op(e){let t=r5("sha256");for(let n of[...e].sort((r,i)=>Buffer.compare(Buffer.from(r.path,"utf8"),Buffer.from(i.path,"utf8")))){let r=r5("sha256").update(n.bytes).digest("hex");t.update(`${n.mode.toString(8)}\x00${n.path}\x00${n.bytes.length}\x00${r}
|
|
7
|
-
`,"utf8")}return`sha256-tree-v1:${t.digest("hex")}`}var Lh=()=>{};function s5(e){return Op($l(e,{limits:Uh,resourceLabel:"managed Skill tree"})).slice(15)}function sn(e){return s5(e)}function RO(){return[...o5.keys()]}function Fh(e,t){let n=o5.get(e);if(!n)throw Error(`no bundled hosted skill is registered for ${e}`);let r=n.get(t);if(!r)throw Error(`no bundled hosted skill ${e} version ${t} is registered`);return r}function a5(e,t){if(s5(t)!==e.digest)throw Error(`bundled hosted skill catalog digest mismatch for ${e.id} version ${e.version}`)}var o5,Uh;var Do=b(()=>{Lh();o5=new Map([["clawdi",new Map([[1,Object.freeze({id:"clawdi",version:1,assetDirectory:"hosted-versions/1/clawdi",digest:"
|
|
7
|
+
`,"utf8")}return`sha256-tree-v1:${t.digest("hex")}`}var Lh=()=>{};function s5(e){return Op($l(e,{limits:Uh,resourceLabel:"managed Skill tree"})).slice(15)}function sn(e){return s5(e)}function RO(){return[...o5.keys()]}function Fh(e,t){let n=o5.get(e);if(!n)throw Error(`no bundled hosted skill is registered for ${e}`);let r=n.get(t);if(!r)throw Error(`no bundled hosted skill ${e} version ${t} is registered`);return r}function a5(e,t){if(s5(t)!==e.digest)throw Error(`bundled hosted skill catalog digest mismatch for ${e.id} version ${e.version}`)}var o5,Uh;var Do=b(()=>{Lh();o5=new Map([["clawdi",new Map([[1,Object.freeze({id:"clawdi",version:1,assetDirectory:"hosted-versions/1/clawdi",digest:"205caf55b56e136dc8a676523b6d07eea541d42af75ff6c19d10ec8dd766dc9d"})]])]]),Uh=Object.freeze({entries:1024,files:1024,fileBytes:16777216,totalBytes:33554432})});function l5(e,t){if(typeof e!=="string"||e.length>2048)throw Error(`${t} must be a valid absolute http:// or https:// URL.`);let n=e.trim(),r;try{r=new URL(n)}catch{throw Error(`${t} must be a valid absolute http:// or https:// URL.`)}if(r.protocol!=="http:"&&r.protocol!=="https:")throw Error(`${t} must use http:// or https://.`);let i=n.indexOf("://")+3,o=n.slice(i).search(/[/?#]/),s=o===-1?n.slice(i):n.slice(i,i+o);if(r.username||r.password||s.includes("@"))throw Error(`${t} must not contain credentials.`);if(!r.hostname||!r.hostname.startsWith("[")&&!r.hostname.split(".").every((c)=>/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(c)))throw Error(`${t} must contain a canonical hostname.`);if(n.includes("?")||n.includes("#"))throw Error(`${t} must not contain a query or fragment.`);let a=n.indexOf("/",i),l=a===-1?"":n.slice(a);return{url:r,rawPath:l}}function mAe(e){return e==="localhost"||e==="127.0.0.1"||e==="[::1]"}function c5(e,t){if(e.protocol==="http:"&&!mAe(e.hostname))throw Error(`${t} must use HTTPS except on loopback localhost.`)}function Rt(e){let{url:n,rawPath:r}=l5(e,"Clawdi Cloud API URL");if(c5(n,"Clawdi Cloud API URL"),r!==""&&r!=="/"||n.pathname!=="/")throw Error("Clawdi Cloud API URL must not contain a non-root path.");return n.origin}function wa(e){let{url:n,rawPath:r}=l5(e,"Hosted deploy API URL");if(c5(n,"Hosted deploy API URL"),!["","/","/v2","/v2/"].includes(r))throw Error("Hosted deploy API URL must use the origin root or the compatible /v2 base.");if(n.pathname!=="/"&&n.pathname!=="/v2"&&n.pathname!=="/v2/")throw Error("Hosted deploy API URL must use the origin root or the compatible /v2 base.");return n.origin}function Bt(e){return new URL(e).origin}function PO(e){return e==="https://cloud-api.clawdi.ai"}import{chmodSync as fAe,lstatSync as d5,mkdirSync as gAe}from"node:fs";import{isAbsolute as hAe,join as yAe,relative as vAe,resolve as u5}from"node:path";function p5(e){return e instanceof Error&&"code"in e&&e.code==="ENOENT"}function vu(e,t="trusted directory"){let n;try{n=d5(e)}catch(r){if(p5(r))throw Error(`${t} is missing: ${e}`);throw r}if(!n.isDirectory()||n.isSymbolicLink())throw Error(`${t} is not a real directory: ${e}`)}function Pr(e,t,n={}){let r=u5(e),i=u5(t),o=vAe(r,i);if(o.startsWith("..")||hAe(o))throw Error(`directory is outside trusted root ${e}: ${t}`);if(vu(r),!o)return;let s=r;for(let a of o.split("/")){s=yAe(s,a);try{let l=d5(s);if(!l.isDirectory()||l.isSymbolicLink())throw Error(`trusted directory path contains a non-directory: ${s}`)}catch(l){if(!p5(l))throw l;if(gAe(s,n.mode===void 0?void 0:{mode:n.mode}),n.mode!==void 0)fAe(s,n.mode)}}}var Dp=()=>{};import{chmodSync as wAe,closeSync as _Ae,existsSync as bAe,fsyncSync as SAe,mkdirSync as kAe,openSync as AAe,renameSync as EAe,rmSync as RAe,writeFileSync as PAe}from"node:fs";import{basename as CAe,dirname as $Ae,join as xAe}from"node:path";function ie(e,t,n={}){let r=n.mode??lt,i=$Ae(e);if(n.trustedRoot)Pr(n.trustedRoot,i,{...n.dirMode===void 0?{}:{mode:n.dirMode}});else{let s=bAe(i);if(kAe(i,{recursive:!0,...n.dirMode===void 0?{}:{mode:n.dirMode}}),!s&&n.dirMode!==void 0)Tp(i,n.dirMode)}let o=xAe(i,`.${CAe(e)}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`);try{if(PAe(o,t,{mode:r}),Tp(o,r),n.durable)m5(o);if(EAe(o,e),Tp(e,r),n.durable)m5(i)}catch(s){throw RAe(o,{force:!0}),s}}function m5(e){let t=AAe(e,"r");try{SAe(t)}finally{_Ae(t)}}function Tp(e,t){try{wAe(e,t)}catch{}}var lt=384,Ge=448;var bt=b(()=>{Dp()});var y5={};ae(y5,{CONFIG_KEYS:()=>ok,clearAuth:()=>Bh,clearPendingAuth:()=>jp,getAuth:()=>we,getClawdiDir:()=>ge,getConfig:()=>ke,getPendingAuth:()=>Es,getStoredAuth:()=>As,getStoredConfig:()=>To,isLoggedIn:()=>Ve,readRecoverablePrivateJson:()=>xl,setAuth:()=>Hh,setConfig:()=>jAe,setConfigKey:()=>OO,setPendingAuth:()=>TO,unsetConfigKey:()=>DO});import{existsSync as $O,readFileSync as IAe,unlinkSync as f5}from"node:fs";import{homedir as OAe}from"node:os";import{join as nk}from"node:path";function rk(){let e=process.env.CLAWDI_HOME;if(e)return e;return nk(process.env.HOME||OAe(),".clawdi")}function ik(){return nk(rk(),"config.json")}function xO(){return nk(rk(),"auth.json")}function IO(){return nk(rk(),"pending-auth.json")}function g5(e){if(!$O(e))return null;return JSON.parse(IAe(e,"utf-8"))}function h5(){let e=g5(ik());if(typeof e!=="object"||e===null||Array.isArray(e))return{};let t={...e};if(t.autoUpdate==="true")t.autoUpdate=!0;else if(t.autoUpdate==="false")t.autoUpdate=!1;else if(typeof t.autoUpdate!=="boolean")delete t.autoUpdate;if(typeof t.apiUrl!=="string")delete t.apiUrl;if(typeof t.deployApiUrl!=="string")delete t.deployApiUrl;return t}function zh(e,t){ie(e,`${JSON.stringify(t,null,2)}
|
|
8
8
|
`,{mode:lt,dirMode:Ge})}function ke(){let e=h5();return{apiUrl:process.env.CLAWDI_API_URL||e.apiUrl||DAe,deployApiUrl:process.env.CLAWDI_DEPLOY_API_URL||e.deployApiUrl||TAe,autoUpdate:e.autoUpdate}}function To(){return h5()}function jAe(e){let t={...e,apiUrl:CO("apiUrl",e.apiUrl)};if(e.deployApiUrl!==void 0)t.deployApiUrl=CO("deployApiUrl",e.deployApiUrl);if(e.autoUpdate!==void 0&&typeof e.autoUpdate!=="boolean")throw Error("autoUpdate must be true or false.");zh(ik(),t)}function OO(e,t){let n=NAe(e,t),r=To();zh(ik(),{...r,[e]:n})}function NAe(e,t){if(e==="autoUpdate"){if(t==="true")return!0;if(t==="false")return!1;throw Error("autoUpdate must be true or false.")}return CO(e,t)}function CO(e,t){return e==="apiUrl"?Rt(t):wa(t)}function DO(e){let t=To();delete t[e],zh(ik(),t)}function we(){let e=process.env.CLAWDI_AUTH_TOKEN;if(e)return{apiKey:e};return As()}function As(){return xl(xO())}function Hh(e){zh(xO(),e)}function Bh(){let e=xO();if($O(e))f5(e)}function Ve(){return we()!==null}function Es(){return xl(IO())}function TO(e){zh(IO(),e)}function jp(){let e=IO();if($O(e))f5(e)}function xl(e,t=g5){try{return t(e)}catch{return null}}function ge(){return rk()}var ok,DAe="https://cloud-api.clawdi.ai",TAe="https://api.clawdi.ai";var Pe=b(()=>{bt();ok=["apiUrl","deployApiUrl","autoUpdate"]});var C5={};ae(C5,{PrivateDirectoryLockTimeoutError:()=>Vh,withPrivateDirectoryLock:()=>hr,withPrivateDirectoryLockSync:()=>Cn});import{randomUUID as jO}from"node:crypto";import{chmodSync as w5,mkdirSync as sk,readFileSync as MAe,renameSync as v5,rmSync as ak,statSync as _5}from"node:fs";import{dirname as b5,join as LAe}from"node:path";function Np(e,t){return e instanceof Error&&"code"in e&&e.code===t}function NO(e){return LAe(e,"owner.json")}function Mp(e){try{let t=JSON.parse(MAe(NO(e),"utf8"));if(!t||typeof t!=="object"||Array.isArray(t))return null;let n=t;if(n.schemaVersion!=="clawdi.privateDirectoryLockOwner.v1"||typeof n.pid!=="number"||!Number.isInteger(n.pid)||n.pid<=0||typeof n.acquiredAt!=="string"||!Number.isFinite(Date.parse(n.acquiredAt))||typeof n.token!=="string"||!n.token)return null;return n}catch{return null}}function E5(e){try{return process.kill(e,0),!0}catch(t){return!Np(t,"ESRCH")}}function UAe(e,t){let n=Mp(e);if(n)return t.isProcessAlive(n.pid)?null:{kind:"owner",owner:n};try{let r=_5(e).mtimeMs;return t.now()-r>t.staleMs?{kind:"ownerless",mtimeMs:r}:null}catch(r){if(Np(r,"ENOENT"))return{kind:"ownerless",mtimeMs:0};throw r}}function FAe(e,t){if(t.kind==="owner"){let n=Mp(e);return n?.token===t.owner.token&&n.pid===t.owner.pid&&n.acquiredAt===t.owner.acquiredAt}if(Mp(e)!==null)return!1;try{return _5(e).mtimeMs===t.mtimeMs}catch{return!1}}function R5(e,t){let n=UAe(e,t);if(!n)return!1;t.beforeReclaimRename?.();let r=`${e}.stale.${process.pid}.${t.now()}.${jO()}`;try{v5(e,r)}catch(i){if(Np(i,"ENOENT"))return!0;throw i}if(!FAe(r,n)){try{v5(r,e)}catch(i){if(!Np(i,"EEXIST"))throw i}return!1}return ak(r,{recursive:!0,force:!0}),!0}function P5(e,t){if(Mp(e)?.token!==t)return;ak(e,{recursive:!0,force:!0})}function zAe(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}function Cn(e,t,n={}){let r=n.timeoutMs??S5,i=n.staleMs??k5,o=n.retryMs??A5,s=n.now??Date.now,a=n.isProcessAlive??E5,l=b5(e);sk(l,{recursive:!0,mode:Ge});try{w5(l,Ge)}catch{}let c=s(),u=jO();for(;;)try{sk(e,{mode:Ge});try{ie(NO(e),`${JSON.stringify({schemaVersion:"clawdi.privateDirectoryLockOwner.v1",pid:process.pid,acquiredAt:new Date(s()).toISOString(),token:u})}
|
|
9
9
|
`,{mode:lt,dirMode:Ge})}catch(p){throw ak(e,{recursive:!0,force:!0}),p}break}catch(p){if(!Np(p,"EEXIST"))throw p;if(R5(e,{staleMs:i,now:s,isProcessAlive:a,beforeReclaimRename:n.beforeReclaimRename}))continue;if(s()-c>=r)throw Error(`timed out waiting for private lock at ${e}`);zAe(o)}let d={token:u,assertOwned(){if(Mp(e)?.token!==u)throw Error(`lost ownership of private lock at ${e}`)}};try{return d.assertOwned(),t(d)}finally{P5(e,u)}}async function hr(e,t,n={}){let r=n.timeoutMs??S5,i=n.staleMs??k5,o=n.retryMs??A5,s=n.now??Date.now,a=n.isProcessAlive??E5,l=b5(e);sk(l,{recursive:!0,mode:Ge});try{w5(l,Ge)}catch{}let c=s(),u=jO();for(;;)try{sk(e,{mode:Ge});try{let p={schemaVersion:"clawdi.privateDirectoryLockOwner.v1",pid:process.pid,acquiredAt:new Date(s()).toISOString(),token:u};ie(NO(e),`${JSON.stringify(p)}
|
|
10
10
|
`,{mode:lt,dirMode:Ge})}catch(p){throw ak(e,{recursive:!0,force:!0}),p}break}catch(p){if(!Np(p,"EEXIST"))throw p;if(R5(e,{staleMs:i,now:s,isProcessAlive:a,beforeReclaimRename:n.beforeReclaimRename}))continue;if(s()-c>=r)throw new Vh(e);await new Promise((m)=>setTimeout(m,o))}let d={token:u,assertOwned(){if(Mp(e)?.token!==u)throw Error(`lost ownership of private lock at ${e}`)}};try{return d.assertOwned(),await t(d)}finally{P5(e,u)}}var S5=30000,k5=60000,A5=50,Vh;var jo=b(()=>{bt();Vh=class Vh extends Error{lockDir;constructor(e){super(`timed out waiting for private lock at ${e}`);this.name="PrivateDirectoryLockTimeoutError",this.lockDir=e}}});import{mkdirSync as HAe,readFileSync as BAe,renameSync as $5,rmSync as qh,statSync as VAe,writeFileSync as qAe}from"node:fs";import{basename as WAe,dirname as x5,join as I5}from"node:path";function O5(e){return I5(e,"owner.json")}function KAe(e,t,n){let r=I5(x5(e),`.${WAe(e)}.${process.pid}.${Date.now()}.tmp`),i=!1;try{qAe(r,t,{mode:n}),$5(r,e),i=!0}finally{if(!i)qh(r,{force:!0})}}function GAe(e){KAe(O5(e),`${JSON.stringify({schemaVersion:"clawdi.runtimeConvergeLockOwner.v1",pid:process.pid,acquiredAt:new Date().toISOString()})}
|
|
@@ -637,7 +637,7 @@ ${i.generatedContents}`))}return r}function Gee(e,t,n){return r2(e,t==="system"?
|
|
|
637
637
|
`).trim()}function Xee(e,t){let n=vd();if(n!=="root"){let r=String(Tl(n)),i=Dl(n,e.userHome,Zo(),["--user",...t],{environment:Mee(r),preserveSession:!0});return qP(i.command,i.args,i.env)}return qP(Zo(),["--user",...t])}function Qee(e,t){let n=vd(),r=Dl(n,t,"test",["-r",e],{preserveSession:!0});ete(r.command,r.args,r.env)}function ete(e,t,n){let r=qP(e,t,n);return xw(e,t,r),[r.stdout,r.stderr].filter(Boolean).join(`
|
|
638
638
|
`).trim()}function qP(e,t,n,r=A4e){if(process.platform!=="linux")throw Error("systemd runtime commands require Linux");if(!Number.isSafeInteger(r)||r<=0)throw Error("systemd command timeout must be a positive integer");let i=w4e("/usr/bin/timeout",["--signal=KILL",`${r/1000}s`,e,...t],{encoding:"utf8",...n?{env:{...process.env,...n}}:{}});if(i.error&&"code"in i.error&&i.error.code==="ENOENT")throw Error("systemd runtime commands require GNU timeout at /usr/bin/timeout; install GNU coreutils");if(i.signal==="SIGKILL"||i.status===124||i.status===137)throw new Js;return{status:i.status,stdout:i.stdout??"",stderr:i.stderr??"",...i.error?{error:i.error}:{}}}function xw(e,t,n){if(n.status===0)return;let r=[n.stdout,n.stderr].filter(Boolean).join(`
|
|
639
639
|
`).trim();throw Error(`${e} ${t.join(" ")} failed${n.status===null?"":` (${n.status})`}${n.error?`: ${n.error.message}`:""}${r?`: ${r.slice(0,1000)}`:""}`)}var k4e="clawdi-runtime-watch.service",i2="clawdi-runtime-sidecar.service",Pw,A4e=120000,Js;var KP=b(()=>{so();et();Rw();Pw=new Set([k4e]);Js=class Js extends Error{constructor(e="systemd command timed out; job outcome is unknown and requires fresh observation"){super(e)}}});import{lstatSync as tte,readFileSync as nte}from"node:fs";import{dirname as $4e,join as rte}from"node:path";function l2(e){return rte($4e(e.appliedState),"component-activations.json")}function ste(e,t,n){if(t.mode!=="hosted")return;try{let r=yn(t);if(!r?.applyReceiptId||!r.bootNonce)return;let i={schemaVersion:1,appliedStateRevision:ut(r),entries:I4e(e,t,r.activated,n)};Ot(t,l2(t),`${JSON.stringify(ote.parse(i))}
|
|
640
|
-
`,{mode:384,dirMode:493})}catch{O.warn("runtime.component_proof_unavailable",{message:"Component activation proof could not be persisted; complete-runtime admission remains required."})}}function x4e(e,t){try{let n=tte(l2(e));if(!n.isFile()||n.size>16384)return;let r=ote.parse(JSON.parse(nte(l2(e),"utf8")));if(new Set(r.entries.map((i)=>i.component)).size!==r.entries.length)return;return r.appliedStateRevision===ut(t)?r.entries:void 0}catch{return}}function ate(e){if(!e||typeof e!=="object")return!1;return Object.hasOwn(e,"$include")||Object.values(e).some(ate)}function lte(e,t,n){try{let r=GP[e],i=Gee(t,r.scope,r.unit);if(!i||i!==n)return null;let o;if(e==="files")o=[t.fileBrowserConfig];else if(e==="openclaw-ui")o=[rte(t.userHome,".openclaw","openclaw.json")];else{let a=fP("hermes","dashboard",t);if(a.status!=="ok"
|
|
640
|
+
`,{mode:384,dirMode:493})}catch{O.warn("runtime.component_proof_unavailable",{message:"Component activation proof could not be persisted; complete-runtime admission remains required."})}}function x4e(e,t){try{let n=tte(l2(e));if(!n.isFile()||n.size>16384)return;let r=ote.parse(JSON.parse(nte(l2(e),"utf8")));if(new Set(r.entries.map((i)=>i.component)).size!==r.entries.length)return;return r.appliedStateRevision===ut(t)?r.entries:void 0}catch{return}}function ate(e){if(!e||typeof e!=="object")return!1;return Object.hasOwn(e,"$include")||Object.values(e).some(ate)}function lte(e,t,n){try{let r=GP[e],i=Gee(t,r.scope,r.unit);if(!i||i!==n)return null;let o;if(e==="files")o=[t.fileBrowserConfig];else if(e==="openclaw-ui")o=[rte(t.userHome,".openclaw","openclaw.json")];else{let a=fP("hermes","dashboard",t);if(a.status!=="ok")return null;if(o=[cw("hermes",t,"dashboard")],a.config.secretFilePath)o.push(a.config.secretFilePath)}let s=o.map((a)=>{let l=tte(a);if(!l.isFile()||l.size>1048576)throw Error("Component config unavailable");return nte(a,"utf8")});if(e==="openclaw-ui"){let a=ite.default.parse(s[0]??"null");if(ate(a)||!a||typeof a!=="object"||!("gateway"in a))return null;let l=a.gateway;if(!l||typeof l!=="object"||"port"in l&&l.port!==18789)return null}return ut([i,...s])}catch{return null}}function I4e(e,t,n,r){let i=e.manifest,o=e.secretValues??{},s={};if(i.companions?.filebrowser){let u=i.companions.filebrowser.auth;s.files=ut(["files",u.accessRevision,u.secret])}let a=i.openclawGatewayAuth;if(a){let u=Ze(o,a.tokenRef);if(u)s["openclaw-ui"]=ut(["openclaw-ui",u])}let l=i.hermesDashboardAuth;if(l){let u=Ze(o,l.passwordSecretRef),d=Ze(o,l.sessionSecretRef);if(u&&d)s["hermes-ui"]=ut(["hermes-ui",l.username,u,d])}let c=[];for(let u of Object.keys(GP)){let d=GP[u],p=s[u];if(!p||!n[d.unit])continue;let m=r(d.scope,d.unit),g=lte(u,t,n[d.unit]),f=r(d.scope,d.unit);if(m&&f&&g&&m.invocationId===f.invocationId&&m.configurationRevision===f.configurationRevision)c.push({component:u,configRevision:ut([g,m.configurationRevision]),accessRevision:p,invocationId:m.invocationId})}return c}async function cte(e,t,n,r){if(!t.applyReceiptId||!t.bootNonce)return;let i=x4e(e,t);if(!i)return;let o=await Promise.all(i.map(async(a)=>{let l=a.invocationId,c="unknown";try{let u=GP[a.component],d=n(u.scope,u.unit);l=d?.invocationId??l;let p=(m)=>{let g=lte(a.component,e,t.activated[u.unit]);return g!==null&&ut([g,m.configurationRevision])===a.configRevision};if(d&&p(d)&&await r(a.component)){let m=n(u.scope,u.unit);if(m?.invocationId===d.invocationId&&p(m))c="ok"}}catch{}return{...a,invocationId:l,status:c}})),s=yn(e);if(!s||ut(s)!==ut(t))return;return{schemaVersion:1,entries:o}}var ite,ote,GP;var c2=b(()=>{Lt();gn();so();Ma();rr();Fn();KP();ite=nu(PP(),1),ote=h.object({schemaVersion:h.literal(1),appliedStateRevision:h.string().regex(/^[a-f0-9]{64}$/),entries:h.array(h.object({component:h.enum(["files","hermes-ui","openclaw-ui"]),configRevision:h.string().regex(/^[a-f0-9]{64}$/),accessRevision:h.string().regex(/^[a-f0-9]{64}$/),invocationId:h.string().regex(/^[a-f0-9]{32}$/)}).strict()).max(3)}).strict();GP={files:{scope:"system",unit:"clawdi-files.service"},"hermes-ui":{scope:"user",unit:"clawdi-hermes-dashboard.service"},"openclaw-ui":{scope:"user",unit:"openclaw-gateway.service"}}});import{createHash as O4e}from"node:crypto";import{lstatSync as bd,readdirSync as pte,readFileSync as ute,rmSync as D4e}from"node:fs";import{dirname as T4e,join as JP}from"node:path";function dte(e){return O4e("sha256").update(e).digest("hex")}function Iw(e,t,n,r,i,o){if(!mte.test(n))throw Error("archive cache key is invalid");let s=JP(t,n);if(T4e(s)!==t)throw Error("archive cache key escapes its root");let a=JP(s,r),l=JP(s,"receipt.json"),c=()=>{try{return bd(s),!0}catch(p){if(p instanceof Error&&"code"in p&&p.code==="ENOENT")return!1;throw p}},u=()=>{try{let p=bd(a),m=bd(l);if(!p.isFile()||p.isSymbolicLink()||p.size>o||(p.mode&511)!==384||!m.isFile()||m.isSymbolicLink()||m.size>j4e||(m.mode&511)!==384||typeof process.getuid==="function"&&(p.uid!==process.getuid()||m.uid!==process.getuid()))return null;let g=i.parse(JSON.parse(ute(l,"utf8"))),f=ute(a);return g.key===n&&dte(f)===g.archiveSha256?f:null}catch{return null}},d=(p={})=>{try{let m=bd(t),g=bd(s);if(!m.isDirectory()||m.isSymbolicLink()||!g.isDirectory()||g.isSymbolicLink()||p.allowIncomplete!==!0&&u()===null)return!1;for(let f of pte(s)){if(f!==r&&f!=="receipt.json")return!1;let v=bd(JP(s,f));if(!v.isFile()||v.isSymbolicLink())return!1}return D4e(s,{recursive:!0}),!0}catch(m){if(m instanceof Error&&"code"in m&&m.code==="ENOENT")return!1;throw m}};return{exists:c,read:u,write:(p,m)=>{if(p.length>o)throw Error("archive exceeds its cache limit");let g=dte(p),f=m(g),v=i.parse(f);if(v.key!==n||v.archiveSha256!==g)throw Error("archive cache receipt does not match its entry");try{Ot(e,a,p,{mode:384,dirMode:448}),Ot(e,l,`${JSON.stringify(f,null,2)}
|
|
641
641
|
`,{mode:384,dirMode:448})}catch(w){throw d({allowIncomplete:!0}),w}},remove:d}}function ZP(e,t,n,r,i,o){let s;try{let a=bd(t);if(!a.isDirectory()||a.isSymbolicLink())return;s=pte(t)}catch(a){if(a instanceof Error&&"code"in a&&a.code==="ENOENT")return;throw a}for(let a of s)if(mte.test(a)&&!n.has(a))Iw(e,t,a,r,i,o).remove()}var mte,j4e=4096;var u2=b(()=>{Fn();mte=/^[a-f0-9]{64}$/});import{createHash as N4e}from"node:crypto";import{chmodSync as M4e,existsSync as L4e,lstatSync as hte,mkdirSync as fte,mkdtempSync as yte,readFileSync as vte,rmSync as p2,writeFileSync as U4e}from"node:fs";import{validateHeaderName as F4e,validateHeaderValue as z4e}from"node:http";import{isIP as H4e}from"node:net";import{tmpdir as wte}from"node:os";import{dirname as B4e,join as Sd}from"node:path";function t6e(e){return Op(e)}function u6e(e){let[t,n=""]=e.split(":");return[Number.parseInt(t??"",16),n.split(",").map((r)=>String.fromCodePoint(Number.parseInt(r,16))).join("")]}function Cte(e){let t="";for(let n of e){let r=n.codePointAt(0);if(r===void 0)continue;let i=d6e.get(r);if(i!==void 0)t+=i;else if(r>=5024&&r<=5109||r>=5112&&r<=5117||r>=43888&&r<=43967)t+=n.toUpperCase();else t+=n.toLowerCase()}return t}function $te(e){return N4e("sha256").update(e).digest("hex")}function xte(e,t){let n=t.source.type==="github"?[t.source.type,t.source.url,t.source.path,t.source.commit]:[t.source.type,t.source.url,t.source.archiveDigest];return $te(JSON.stringify([t.installationId,e,t.version,t.agentPluginsSchema,...n,t.contentDigest]))}function p6e(e,t){return f2.parse({...t,ownershipIdentity:xte(e,t)})}function Ite(e){return Sd(e.statusRoot,"runtime-agent-plugin-receipts.json")}function kd(e){let t=Ite(e),n;try{n=hte(t)}catch(r){if(r instanceof Error&&"code"in r&&r.code==="ENOENT")return null;throw Error("Agent Plugin receipts could not be inspected")}if(!n.isFile()||n.isSymbolicLink()||n.size>Y4e)throw Error("Agent Plugin receipts are not a trusted regular file");if((n.mode&511)!==384)throw Error("Agent Plugin receipts do not have private file permissions");if(typeof process.getuid==="function"&&n.uid!==process.getuid())throw Error("Agent Plugin receipts do not have the expected file owner");try{let r=JSON.parse(vte(t,"utf8"));return Rte.parse(r)}catch{throw Error("Agent Plugin receipts do not match the expected schema")}}function Ote(e,t){let n=Ite(t);if(!e||Object.keys(e.installations).length===0){p2(n,{force:!0});return}let r=Rte.parse(e),i=kd(t),o=`${JSON.stringify(r,null,2)}
|
|
642
642
|
`;if(i&&vte(n,"utf8")===o)return;Ot(t,n,o,{mode:384,dirMode:493});let s=kd(t);if(JSON.stringify(s)!==JSON.stringify(r))throw Error("Agent Plugin receipts did not pass post-write verification")}function Dte(e){return Sd(e.cacheRoot,"agent-plugins")}function g2(e,t){return Iw(e,Dte(e),t,"source.tar.gz",Pte,m2)}function Tte(e,t){if(!e)return;for(let n of e.transientCacheOwnerships)g2(t,n).remove({allowIncomplete:!0})}function jte(e,t,n=[]){let r=new Set(Object.values(e?.installations??{}).map((i)=>i.ownershipIdentity));for(let i of n)r.add(i);ZP(t,Dte(t),r,"source.tar.gz",Pte,m2)}function Ow(e){let t=e.split("/");return e.length>0&&Buffer.byteLength(e,"utf8")<=J4e&&!cd(e)&&!e.includes("\\")&&t.every((n)=>n&&n!=="."&&n!=="..")}async function m6e(e,t,n){let r=null;if(await Oo(e,t,{resourceLabel:"Agent Plugin package",allowReservedManagementPaths:!0,limits:{entryCount:bte,fileCount:Ste,entryBytes:Ate,totalEntryBytes:kte,expandedTarBytes:G4e},filter:(o)=>{let s=o.replace(/\/$/,"").split("/");if(o.startsWith("/")||o.includes("\\")||s.some((u)=>u==="."||u===".."||cd(u)))throw Error("Agent Plugin repository archive contains an unsafe path");let a=s[0];if(!a)return!1;if(r===null)r=a;if(r!==a)throw Error("Agent Plugin repository archive has multiple roots");let l=s.slice(1).join("/");if(n!==""&&l!==n&&!l.startsWith(`${n}/`))return!1;let c=n===""?l:l.slice(n.length).replace(/^\//,"");if(c&&!Ow(c))throw Error("Agent Plugin package contains an unsafe path");return!0}}),!r)throw Error("Agent Plugin repository archive is empty");let i=Sd(e,r,...n.split("/"));if(!L4e(i)||!hte(i).isDirectory())throw Error("Agent Plugin package path does not exist in the pinned source");return i}function Nte(e,t={}){let n=$l(e,{limits:{entries:bte,files:Ste,fileBytes:Ate,totalBytes:kte},exclude:(r)=>t.ignoreTopLevelGitMetadata===!0&&r===".git",validatePath:(r)=>{if(!Ow(r))throw Error("Agent Plugin package contains an unsafe path")},collisionKey:Cte,collisionError:"Agent Plugin package contains a case-fold path collision",resourceLabel:"Agent Plugin package"});return{digest:t6e(n),tree:n}}function Mte(e,t={}){return Nte(e,t).digest}function Lte(e,t){if(!e)throw Error(`${t} must be a regular file at the package root`);if(e.bytes.length>Z4e)throw Error(`${t} is too large`);try{let n=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e.bytes));return n6e.parse(n)}catch{throw Error(`${t} must be a valid JSON object`)}}function f6e(e,t){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e.bytes)}catch{throw Error(`${t} must be valid UTF-8`)}}function g6e(e){let t=e.filter((r)=>r.path.startsWith("skills/")),n=new Set;for(let r of t){let i=r.path.split("/"),o=i[1];if(!o||!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(o)||i.length<3)throw Error("Agent Plugin contains an invalid Skill path");n.add(o)}for(let r of n){let i=e.find((c)=>c.path===`skills/${r}/SKILL.md`);if(!i)throw Error("Agent Plugin Skill is missing SKILL.md");let s=f6e(i,"Agent Plugin SKILL.md").replace(/^\uFEFF/,"").match(/^---\r?\n([\s\S]*?)\r?\n---(?:\s*\r?\n|$)/);if(!s)throw Error("Agent Plugin SKILL.md has invalid frontmatter");let a=Ly(s[1]??"",{uniqueKeys:!0});if(a.errors.length>0)throw Error("Agent Plugin SKILL.md has invalid frontmatter");let l=h.object({name:h.string().min(1).max(64),description:h.string().min(1).max(1024).refine((c)=>c.trim().length>0),license:h.string().optional(),compatibility:h.string().min(1).max(500).optional(),metadata:h.record(h.string(),h.string()).optional(),"allowed-tools":h.string().optional()}).strict().safeParse(a.toJS());if(!l.success||l.data.name!==r)throw Error("Agent Plugin SKILL.md frontmatter does not match its Skill directory")}return n.size}function h6e(e){let t;if(e.startsWith("./"))t=e.slice(2);else if(e===Tf||e===jf)return;else if(e.startsWith(`${Tf}/`))t=e.slice(Tf.length+1);else if(e.startsWith(`${jf}/`))t=e.slice(jf.length+1);else throw Error("Agent Plugin MCP path is outside the portable package boundary");if(!Ow(t))throw Error("Agent Plugin MCP path is outside the portable package boundary")}function y6e(e,t){if(e==="./"||e===Tf||e===jf)return;let n,r=!1;if(e.startsWith("./"))n=e.slice(2),r=!0;else if(e.startsWith(`${Tf}/`))n=e.slice(Tf.length+1),r=!0;else if(e.startsWith(`${jf}/`))n=e.slice(jf.length+1);else throw Error("Agent Plugin MCP cwd is outside the portable package boundary");if(!Ow(n)||uP(n))throw Error("Agent Plugin MCP cwd is outside the portable package boundary");if(r&&!t.some((i)=>i.path.startsWith(`${n}/`)))throw Error("Agent Plugin MCP cwd is not a package directory")}function Ute(e){let t=e.indexOf("://");if(t<0)return null;let n=e.slice(t+3),r=n.search(/[/?#]/);return(r<0?n:n.slice(0,r))||null}function v6e(e){let t=Ute(e);if(!t||t.includes("@"))return null;if(t.startsWith("[")){let r=t.indexOf("]");if(r<0||!/^(?::[0-9]+)?$/.test(t.slice(r+1)))return null;return t.slice(1,r)}let n=t.lastIndexOf(":");if(n<0)return t;if(t.indexOf(":")!==n||!/^[0-9]+$/.test(t.slice(n+1)))return null;return t.slice(0,n)}function w6e(e){let t=v6e(e)?.toLowerCase();if(!t)return!1;return t==="localhost"||t==="::1"||t==="0:0:0:0:0:0:0:1"||H4e(t)===4&&t.split(".")[0]==="127"}function _6e(e){if(uP(e.url))throw Error("Agent Plugin remote MCP URL cannot contain credential templates");if(e.url.includes("\\")||/[\s\u0085]/u.test(e.url)||[...e.url].some((i)=>i.charCodeAt(0)<32))throw Error("Agent Plugin remote MCP URL is invalid");let t;try{t=new URL(e.url)}catch{throw Error("Agent Plugin remote MCP URL is invalid")}let n=Ute(e.url);if(t.protocol!=="https:"&&t.protocol!=="http:"||!n||n.includes("@")||e.url.includes("#")||t.username!==""||t.password!==""||t.hash!==""||!t.hostname)throw Error("Agent Plugin remote MCP URL is invalid");if(t.protocol==="http:"){if(!w6e(e.url))throw Error("Agent Plugin remote MCP URL must use HTTPS")}let r=new Set;if(Object.keys(e.headers??{}).length>128)throw Error("Agent Plugin remote MCP headers are invalid");for(let[i,o]of Object.entries(e.headers??{})){let s=i.toLowerCase();if(cP(i)||uP(o)||o.length>0&&hz(o))throw Error("Agent Plugin remote MCP headers cannot carry credentials");if(o.length>8192)throw Error("Agent Plugin remote MCP headers are invalid");try{F4e(i),z4e(i,o)}catch{throw Error("Agent Plugin remote MCP headers are invalid")}if(r.has(s))throw Error("Agent Plugin remote MCP headers are invalid");r.add(s)}}function b6e(e,t){let n=e.find((o)=>o.path==="mcp.json");if(!n)return{serverNames:[],bareCommands:[]};let r=c6e.safeParse(Lte(n,"Agent Plugin mcp.json"));if(!r.success)throw Error("Agent Plugin mcp.json does not match the 1.0.0 schema");let i=new Set;for(let o of Object.values(r.data.mcpServers)){if(o.type!=="stdio"){if(_6e(o),o.type==="sse"&&t==="hermes")throw Error(V4e);continue}if(o.command.includes("\x00"))throw Error("Agent Plugin stdio MCP command is invalid");if(o.command.startsWith("./")){if(h6e(o.command),e.find((l)=>l.path===o.command.slice(2))?.mode!==33261)throw Error("Agent Plugin stdio MCP command is not an executable package file")}else if(!/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(o.command))throw Error("Agent Plugin stdio MCP command is invalid");else i.add(o.command);if((o.args??[]).some((a)=>a.includes("\x00")))throw Error("Agent Plugin stdio MCP args are invalid");let s=new Set;for(let[a,l]of Object.entries(o.env??{})){let c=a.toLowerCase();if(!SQ(a)||a.toUpperCase()==="PLUGIN_ROOT"||a.toUpperCase()==="PLUGIN_DATA"||s.has(c)||a.includes("\x00")||l.includes("\x00"))throw Error("Agent Plugin stdio MCP environment is invalid");if(kQ(a)||l.length>0&&hz(l))throw Error("Agent Plugin stdio MCP environment cannot carry credentials");s.add(c)}if(o.cwd!==void 0)y6e(o.cwd,e)}return{serverNames:Object.keys(r.data.mcpServers).sort(),bareCommands:[...i].sort()}}function S6e(e,t){let n=r6e.safeParse(Lte(t.find((o)=>o.path==="plugin.json"),"Agent Plugin plugin.json"));if(!n.success||n.data.$schema!==e.installation.agentPluginsSchema||n.data.name!==e.name||n.data.version!==e.installation.version)throw Error("Agent Plugin package identity does not match the desired installation");let r=n.data.extensions?.["ai.clawdi"];if(r===void 0)throw Error("Agent Plugin ai.clawdi extension does not match the Store contract");let i=s6e.safeParse(r);if(!i.success)throw Error("Agent Plugin ai.clawdi extension does not match the Store contract");if(i.data.display.icon){let o=i.data.display.icon,s=o.startsWith("./")?o.slice(2):"";if(!Ow(s)||!t.some((a)=>a.path===s))throw Error("Agent Plugin ai.clawdi display icon is not a package file")}return i.data}function k6e(e,t,n){let r=e.compatibility;if(r?.runtimes&&!r.runtimes.includes(t))throw Error(`Agent Plugin ai.clawdi compatibility excludes ${t}`);let i=new Set(r?.executables??[]);if(n.some((o)=>!i.has(o)))throw Error("Agent Plugin bare MCP commands are not declared by ai.clawdi compatibility")}function A6e(e){for(let t of e){let n=t.path.split("/").map((r)=>r.toLowerCase());if(n.includes(".git")||n.at(-1)===".gitattributes")throw Error(q4e)}}async function gte(e,t){let n=yte(Sd(wte(),"clawdi-agent-plugin-validate-"));try{if(t.installation.source.type==="github-release"&&`sha256:${$te(e)}`!==t.installation.source.archiveDigest)throw Error("Agent Plugin release archive digest does not match the desired installation");let r=t.installation.source.type==="github"?t.installation.source.path:"",i=await m6e(n,e,r),o=Nte(i);if(o.digest!==t.installation.contentDigest)throw Error("Agent Plugin package content digest does not match the desired installation");let s=S6e(t,o.tree),a=g6e(o.tree),l=b6e(o.tree,t.runtime);if(a===0&&l.serverNames.length===0)throw Error("Agent Plugin package must declare at least one Skill or MCP server");if(k6e(s,t.runtime,l.bareCommands),t.runtime==="hermes")A6e(o.tree);return{name:t.name,installation:t.installation,mcpServerNames:l.serverNames,tree:o.tree}}finally{p2(n,{recursive:!0,force:!0})}}async function E6e(e,t){let n=e.installation.source,r=n.type==="github"?(()=>{let o=aP(n.url);return gz(o.owner,o.repo,n.commit)})():new URL(n.url),i=await t(r,{headers:{Accept:n.type==="github"?"application/vnd.github+json":"application/octet-stream"},redirect:"follow"});if(!i.ok)throw Error(`Agent Plugin package download failed (${i.status})`);return Na(i,m2,{resourceLabel:"Agent Plugin source archive",limitLabel:"100 MB"})}async function R6e(e,t,n,r,i){let o=g2(t,e.installation.ownershipIdentity),s=o.read();if(s)try{return{plugin:await gte(s,e),cacheCreated:!1}}catch(c){if(r)throw Error("offline Agent Plugin cache is invalid");if(i)throw c}if(r)throw Error(o.exists()?"offline Agent Plugin cache is invalid":"offline Agent Plugin cache is missing");if(o.exists()&&!o.remove({allowIncomplete:!0}))throw Error("Agent Plugin cache ownership path is not a managed cache entry");let a=await E6e(e,n),l=await gte(a,e);return o.write(a,(c)=>({schemaVersion:_te,ownershipIdentity:e.installation.ownershipIdentity,archiveSha256:c})),{plugin:l,cacheCreated:!0}}function P6e(e){if(e.runtime==="openclaw"||e.runtime==="hermes")return e.runtime;throw Error("Agent Plugins require a selected OpenClaw or Hermes runtime")}function C6e(e){if(!e)return new Map;let t=new Map;for(let[n,r]of Object.entries(e.installations).sort(([i],[o])=>i.localeCompare(o))){let{nativeId:i,...o}=r;if(xte(n,o)!==r.ownershipIdentity)throw Error("Agent Plugin receipt ownership identity is invalid");t.set(n,{runtime:e.runtime,name:n,installation:f2.parse(o),nativeId:i})}return t}async function Fte(e,t,n={}){let r=e.projection?.agentPlugins?.installations??{},i=kd(t);if(Object.keys(r).length===0&&!i)return null;let o=C6e(i),s=Object.keys(r).length>0?P6e(e):i?.runtime;if(!s)return null;let a=n.fetcher??fetch,l=new Map,c=new Set,u=new Set(Object.values(i?.installations??{}).map((p)=>p.ownershipIdentity)),d=async(p)=>{let m=p.installation.ownershipIdentity,g=`${p.runtime}\x00${m}`,f=l.get(g);if(f)return(await f).plugin;let v=R6e(p,t,a,n.offline===!0,u.has(m));l.set(g,v);let w=await v;if(w.cacheCreated)c.add(m);return w.plugin};try{let p=new Map;for(let[m,g]of Object.entries(r).sort(([f],[v])=>f.localeCompare(v))){let f=p6e(m,g);p.set(m,await d({name:m,runtime:s,installation:f}))}return{runtime:s,desired:p,previous:o,transientCacheOwnerships:new Set([...c].filter((m)=>!u.has(m)))}}catch(p){for(let m of c)if(!u.has(m))g2(t,m).remove({allowIncomplete:!0});throw p}}function h2(e,t){let n=yte(Sd(wte(),"clawdi-agent-plugin-stage-"));try{M4e(n,448);let r=Sd(n,"package");fte(r,{recursive:!0,mode:448});for(let i of e.tree){let o=Sd(r,...i.path.split("/"));fte(B4e(o),{recursive:!0,mode:448}),U4e(o,i.bytes,{mode:i.mode&511})}return t(r)}finally{p2(n,{recursive:!0,force:!0})}}var V4e="Hermes Agent Plugins only support the portable streamable-http remote transport",q4e="Hermes Agent Plugin package cannot preserve its verified bytes through local Git transport",_te="clawdi.hostedAgentPluginArchive.v1",W4e="clawdi.hostedAgentPluginReceipts.v2",K4e="https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",m2=104857600,G4e=268435456,bte=2000,Ste=1000,kte=52428800,Ate=10485760,J4e=512,Z4e=262144,Y4e=4194304,Ete="$",Tf,jf,f2,X4e,Q4e,Rte,e6e,Pte,n6e,r6e,d2=(e,t)=>h.array(h.string().min(1).max(t)).max(e).refine((n)=>new Set(n.map(Cte)).size===n.length,"must not contain case-folded duplicates"),i6e,o6e,s6e,a6e,l6e,c6e,d6e;var Dw=b(()=>{ql();Lt();Lh();vf();Gr();u2();_f();yz();Fn();Tf=`${Ete}{PLUGIN_ROOT}`,jf=`${Ete}{PLUGIN_DATA}`,f2=lw.extend({ownershipIdentity:h.string().regex(/^[a-f0-9]{64}$/)}).strict(),X4e=h.string().min(1).max(128).regex(/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/),Q4e=f2.extend({nativeId:X4e}).strict(),Rte=h.object({schemaVersion:h.literal(W4e),runtime:h.enum(["openclaw","hermes"]),installations:h.record(wf,Q4e)}).strict(),e6e=h.object({schemaVersion:h.literal(_te),ownershipIdentity:h.string().regex(/^[a-f0-9]{64}$/),archiveSha256:h.string().regex(/^[a-f0-9]{64}$/)}).strict(),Pte={parse(e){let t=e6e.parse(e);return{key:t.ownershipIdentity,archiveSha256:t.archiveSha256}}};n6e=h.record(h.string(),h.unknown()),r6e=h.object({$schema:h.literal(vz),name:wf,version:h.string().optional(),description:h.string().optional(),author:h.object({name:h.string().optional(),email:h.string().optional(),url:h.string().optional()}).strict().optional(),homepage:h.string().optional(),repository:h.string().optional(),license:h.string().optional(),keywords:h.array(h.string()).optional(),extensions:h.record(h.string(),h.record(h.string(),h.unknown())).optional()}).strict(),i6e=h.object({name:h.string().min(1).max(80),icon:h.string().min(1).max(512).optional(),category:h.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/),languages:d2(20,64).refine((e)=>e.every((t)=>/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(t)),"must contain language tags")}).strict(),o6e=h.object({runtimes:d2(2,16).min(1).refine((e)=>e.every((t)=>t==="openclaw"||t==="hermes"),"contains an unsupported runtime").optional(),executables:d2(32,128).min(1).refine((e)=>e.every((t)=>/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/.test(t)),"contains an invalid executable").optional()}).strict(),s6e=h.object({schemaVersion:h.literal(1),display:i6e,compatibility:o6e.optional()}).strict(),a6e=h.object({type:h.literal("stdio"),command:h.string().min(1).max(512),args:h.array(h.string()).max(256).optional(),env:h.record(h.string(),h.string()).optional(),cwd:h.string().min(1).max(512).optional()}).strict(),l6e=h.object({type:h.enum(["streamable-http","sse"]),url:h.string().min(1).max(2048),headers:h.record(h.string(),h.string()).optional()}).strict(),c6e=h.object({$schema:h.literal(K4e),mcpServers:h.record(h.string().min(1),h.union([a6e,l6e]))}).strict();d6e=new Map("b5:3bc;df:73,73;149:2bc,6e;17f:73;1f0:6a,30c;345:3b9;390:3b9,308,301;3b0:3c5,308,301;3c2:3c3;3d0:3b2;3d1:3b8;3d5:3c6;3d6:3c0;3f0:3ba;3f1:3c1;3f5:3b5;587:565,582;1c80:432;1c81:434;1c82:43e;1c83:441;1c84:442;1c85:442;1c86:44a;1c87:463;1c88:a64b;1e96:68,331;1e97:74,308;1e98:77,30a;1e99:79,30a;1e9a:61,2be;1e9b:1e61;1e9e:73,73;1f50:3c5,313;1f52:3c5,313,300;1f54:3c5,313,301;1f56:3c5,313,342;1f80:1f00,3b9;1f81:1f01,3b9;1f82:1f02,3b9;1f83:1f03,3b9;1f84:1f04,3b9;1f85:1f05,3b9;1f86:1f06,3b9;1f87:1f07,3b9;1f88:1f00,3b9;1f89:1f01,3b9;1f8a:1f02,3b9;1f8b:1f03,3b9;1f8c:1f04,3b9;1f8d:1f05,3b9;1f8e:1f06,3b9;1f8f:1f07,3b9;1f90:1f20,3b9;1f91:1f21,3b9;1f92:1f22,3b9;1f93:1f23,3b9;1f94:1f24,3b9;1f95:1f25,3b9;1f96:1f26,3b9;1f97:1f27,3b9;1f98:1f20,3b9;1f99:1f21,3b9;1f9a:1f22,3b9;1f9b:1f23,3b9;1f9c:1f24,3b9;1f9d:1f25,3b9;1f9e:1f26,3b9;1f9f:1f27,3b9;1fa0:1f60,3b9;1fa1:1f61,3b9;1fa2:1f62,3b9;1fa3:1f63,3b9;1fa4:1f64,3b9;1fa5:1f65,3b9;1fa6:1f66,3b9;1fa7:1f67,3b9;1fa8:1f60,3b9;1fa9:1f61,3b9;1faa:1f62,3b9;1fab:1f63,3b9;1fac:1f64,3b9;1fad:1f65,3b9;1fae:1f66,3b9;1faf:1f67,3b9;1fb2:1f70,3b9;1fb3:3b1,3b9;1fb4:3ac,3b9;1fb6:3b1,342;1fb7:3b1,342,3b9;1fbc:3b1,3b9;1fbe:3b9;1fc2:1f74,3b9;1fc3:3b7,3b9;1fc4:3ae,3b9;1fc6:3b7,342;1fc7:3b7,342,3b9;1fcc:3b7,3b9;1fd2:3b9,308,300;1fd3:3b9,308,301;1fd6:3b9,342;1fd7:3b9,308,342;1fe2:3c5,308,300;1fe3:3c5,308,301;1fe4:3c1,313;1fe6:3c5,342;1fe7:3c5,308,342;1ff2:1f7c,3b9;1ff3:3c9,3b9;1ff4:3ce,3b9;1ff6:3c9,342;1ff7:3c9,342,3b9;1ffc:3c9,3b9;fb00:66,66;fb01:66,69;fb02:66,6c;fb03:66,66,69;fb04:66,66,6c;fb05:73,74;fb06:73,74;fb13:574,576;fb14:574,565;fb15:574,56b;fb16:57e,576;fb17:574,56d".split(";").map(u6e))});import{readFileSync as $6e}from"node:fs";function I6e(e){try{let t=kd(e);return t?{status:"ok",receipt:t}:{status:"missing",receipt:null}}catch{return{status:"unreadable",receipt:null}}}function O6e(e,t){try{let n=Gs.parse(JSON.parse($6e(e.manifestLastGood,"utf-8"))).manifest;return n.instanceId===t.instanceId&&un(n)===un(t)?n:null}catch{return null}}function D6e(e,t,n){return y2.parse({installationId:t.installationId,name:e,version:t.version,contentDigest:t.contentDigest,sourceRevision:n.sourceRevision,generation:un(n),status:"installed"})}function T6e(e,t,n,r){return y2.parse({installationId:t.installationId,name:e,version:t.version,contentDigest:t.contentDigest,sourceRevision:n.sourceRevision,generation:un(n),status:"unknown",errorCode:r})}function j6e(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;let t=e.event;if(!t||typeof t!=="object"||Array.isArray(t))return null;let n=t;if(n.status!=="error")return null;let r=YP.safeParse(n.agentPlugins);if(!r.success||r.data.installations.some((i)=>i.status!=="failed"))return null;return r.data}function N6e(e,t,n){let r=n.status==="ok"?Object.entries(n.receipt.installations):Object.entries(O6e(e,t)?.projection?.agentPlugins?.installations??{});if(r.length===0)return null;return YP.parse({schemaVersion:1,installations:r.sort(([i],[o])=>i.localeCompare(o)).map(([i,o])=>n.status==="ok"?D6e(i,o,t):T6e(i,o,t,`receipt_${n.status}`))})}function zte(e){let t=I6e(e.paths),n=N6e(e.paths,e.applied,t),r=j6e(e.watchStatus);if(!r)return n;let i=un(e.applied),o=r.installations.filter((a)=>a.generation>=i);if(o.length===0)return n;let s=new Set(o.map((a)=>a.name));return YP.parse({schemaVersion:1,installations:[...n?.installations.filter((a)=>!s.has(a.name))??[],...o].sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)})}function Hte(e,t,n){let r=new Set(n),i=Object.entries(e.projection?.agentPlugins?.installations??{}).filter(([s])=>r.has(s)).sort(([s],[a])=>s<a?-1:s>a?1:0).map(([s,a])=>({installationId:a.installationId,name:s,version:a.version,contentDigest:a.contentDigest,sourceRevision:t,generation:un(e),status:"failed",errorCode:"reconcile_failed"}));if(i.length===0)return null;let o=YP.safeParse({schemaVersion:1,installations:i});return o.success?o.data:null}var x6e,y2,YP;var v2=b(()=>{Lt();Ks();Dw();_f();Ua();x6e=h.enum(["reconcile_failed","receipt_missing","receipt_unreadable","receipt_mismatch"]),y2=lw.pick({version:!0,contentDigest:!0}).extend({installationId:h.uuid().max(200),name:wf,sourceRevision:h.string().regex(/^[0-9a-f]{64}$/),generation:h.number().int().positive().safe(),status:h.enum(["installed","failed","unknown"]),errorCode:x6e.nullable().optional()}).strict().superRefine((e,t)=>{if(e.status==="installed"&&e.errorCode!=null)t.addIssue({code:"custom",message:"installed observation cannot include errorCode"});if(e.status==="failed"&&e.errorCode!=="reconcile_failed")t.addIssue({code:"custom",message:"failed observation requires reconcile_failed"});if(e.status==="unknown"&&!["receipt_missing","receipt_unreadable","receipt_mismatch"].includes(e.errorCode))t.addIssue({code:"custom",message:"unknown observation requires a receipt error"})}),YP=h.object({schemaVersion:h.literal(1),installations:h.array(y2).max(128)}).strict().superRefine((e,t)=>{let n=e.installations.map((i)=>i.name),r=e.installations.map((i)=>i.installationId);if(new Set(n).size!==n.length||new Set(r).size!==r.length)t.addIssue({code:"custom",message:"observation identities must be unique"});if(!n.every((i,o)=>o===0||(n[o-1]??"")<i))t.addIssue({code:"custom",message:"observations must be sorted by name"})})});function Tw(e,t){return XP(e.projection?.providers??{},t,e).filter(([,r])=>r.configurationMode==="connection"||r.configurationMode==="custom").map(([r,i])=>{if(t!=="openclaw"&&t!=="hermes"||i.managed_by!=="user"||!i.apiKeySecretRef||i.auth||i.nativeProvider||!i.baseUrl||!i.apiMode||i.status==="error")throw Error("Invalid custom provider connection");return{id:r,initialize:i.configurationMode==="custom",baseUrl:i.baseUrl,apiMode:i.apiMode,envName:QP(r,i,t),secretRef:i.apiKeySecretRef}})}function M6e(e,t){if(t!=="openclaw"&&t!=="hermes")return[];return XP(e.projection?.providers??{},t,e).filter(([,n])=>n.configurationMode==="native").map(([n,r])=>{let i=r.auth?.type==="agent_profile",o=Wl(t,r.nativeProvider??"",r.baseUrl??"",i);if(r.status==="error"||!o||o.type!==Bte(r)||o.api_mode!==b2(r))throw Error("Invalid native provider runtime identity");if(i)return{id:n,routing:o,auth:{kind:"codex"}};if(!r.apiKeySecretRef)throw Error("Native provider credential reference is unavailable");return{id:n,routing:o,auth:{kind:"api-key",secretRef:r.apiKeySecretRef,envName:QP(n,r,t)}}})}function Nf(e,t){Va(e,t,{validateOverlap:!0});let n=M6e(e,t),r=Tw(e,t),o=[...n.map(({routing:a})=>t==="hermes"?a.hermes.provider:a.openclaw.provider),...r.map((a)=>a.id)];if(new Set(o).size!==o.length)throw Error("Native provider credential identity is selected more than once");let s=w2(_2(e,t));if(e.runtimes[t]?.providerMode==="unmanaged"&&(s||n.length>0||r.length>0))throw Error(`runtime ${t} unmanaged provider mode has a provider projection`);return{native:n,catalog:s,connections:r}}function w2(e){if(!e)return null;let t=new Map,n=e.catalog.providers.map((s)=>{if(s.managed_by!=="clawdi")return s;let a=to(s.id)?Hn:s.id===Hy||s.id.startsWith("clawdi-managed")?s.id:Hy;return t.set(s.id,a),{...s,id:a,api_mode:to(a)?zT:s.api_mode}});if(t.size===0)return e;let r=e.primaryModel?t.get(e.primaryModel.provider_id)??e.primaryModel.provider_id:void 0,i=e.catalog.defaults?.chat_provider_id,o=e.catalog.defaults?.embedding_provider_id;return{catalog:{...e.catalog,providers:n,defaults:{...e.catalog.defaults,...r?{chat_provider_id:r}:i?{chat_provider_id:t.get(i)??i}:{},...o?{embedding_provider_id:t.get(o)??o}:{}}},primaryModel:e.primaryModel&&r?{...e.primaryModel,provider_id:r}:null}}function _2(e,t){let n=e.projection?.providers;if(!n||Object.keys(n).length===0)return null;let r=XP(n,t,e).filter(([,l])=>l.configurationMode!=="native"&&l.configurationMode!=="connection"&&l.configurationMode!=="custom"),i=L6e(e,t),o=i&&r.some(([l])=>l===i.provider_id)?i:null;if(!o&&!r.every(([,l])=>l.managed_by==="clawdi"&&l.models?.length&&l.models.every((c)=>c.capabilities?.embeddings===!0)))return null;let s=r.map(([l,c])=>{let u=c.baseUrl,d=b2(c),p=c.apiKeySecretRef??void 0,m=QP(l,c,t);if(c.status==="error")return null;if(!u)return null;let g=F6e(c,Boolean(p));if(!g)return null;let f=U6e(c,l===o?.provider_id?o:null);return{id:l,type:Bte(c),base_url:u,api_mode:d,managed_by:c.managed_by,auth:g,runtime_env_name:p||g.type!=="none"?m:void 0,models:f}}).filter((l)=>l!==null);if(s.length===0)return null;let a=s.find((l)=>l.models.some((c)=>c.capabilities?.embeddings===!0));return{catalog:{schema_version:1,providers:s,defaults:{...o?{chat_provider_id:o.provider_id}:{},...a?{embedding_provider_id:a.id}:{}}},primaryModel:o}}function XP(e,t,n){if(!t)return Object.entries(e).sort(([i],[o])=>i.localeCompare(o));return(n?.runtimes?.[t]?.provider_ids??[]).filter((i)=>Object.hasOwn(e,i)).map((i)=>[i,e[i]])}function L6e(e,t){return(t?e.runtimes[t]:void 0)?.primary_model??null}function U6e(e,t){let n=b2(e),r=[...e.models??[]];if(e.model&&!r.some((i)=>i.id===e.model))r.unshift({id:e.model,api_mode:n});if(t&&!r.some((i)=>i.id===t.model))r.unshift({id:t.model,api_mode:n});return r.filter((i,o,s)=>s.findIndex((a)=>a.id===i.id)===o)}function b2(e){return e.apiMode??"openai_chat"}function Bte(e){return e.type??"custom_openai_compatible"}function F6e(e,t){let n=e.auth;if(n){if(n.type==="agent_profile"&&n.tool==="codex"&&n.profile)return{type:"agent_profile",tool:"codex",profile:n.profile};if(n.type==="api_key"||n.type==="secret_ref"){if(t)return{type:"api_key",source:"managed"};return null}if(n.type!=="none")return null}if(t)return{type:"api_key",source:"managed"};if(S2(e))return null;return{type:"none"}}function S2(e){if(e.apiKeyRequired===!0)return!0;let t=H6e(e.auth);return t?.type==="api_key"||t?.type==="secret_ref"}function QP(e,t,n){if((n==="openclaw"||n==="hermes")&&hf(t))return Or;if(t.configurationMode==="native"&&(n==="openclaw"||n==="hermes")){let i=Wl(n,t.nativeProvider??"",t.baseUrl??"",t.auth?.type==="agent_profile");if(!i)throw Error("Invalid native provider runtime identity");let o=n==="hermes"?i.hermes.env:i.runtime_env_name;if(t.runtimeEnvName&&t.runtimeEnvName!==o)throw Error("Invalid native provider credential environment");return o}let r=t.runtimeEnvName;if(r&&Vte(r))return r;return`CLAWDI_PROVIDER_${e.toUpperCase().replace(/[^A-Z0-9]/g,"_")}_API_KEY`}function Va(e,t,n={}){let r={},i={},o={},s=new Map;for(let[a,l]of XP(e.projection?.providers??{},t,e)){if(l.configurationMode==="native"&&t==="hermes"){let d=Wl(t,l.nativeProvider??"",l.baseUrl??"",l.auth?.type==="agent_profile");if(!d)throw Error("Invalid Hermes native credential routing");if(d.hermes.base_url_env)i[d.hermes.base_url_env]=d.base_url}if(!l.apiKeySecretRef)continue;let c=QP(a,l,t);if(!Vte(c))continue;let u=s.get(c);if(u&&u!==a)throw Error(`runtime ${t??"default"} credential environment ${c} has multiple providers`);if(s.set(c,a),hf(l))r[c]=Wh;else o[c]=l.apiKeySecretRef}if(n.validateOverlap)z6e(t??"default",r,o);return{placeholderEnv:r,configEnv:i,secretEnv:o}}function z6e(e,t,n){for(let r of Object.keys(t)){if(n[r]===void 0)continue;throw Error(`runtime ${e} provider env ${r} is both managed and BYOK-backed`)}}function k2(e,t,n,r){if(Object.keys(n).length===0)return t;let i=t?.env??{};for(let o of Object.keys(n))if(t?.secretEnv?.[o]!==void 0)throw Error(`runtime ${e}${r?` service ${r}`:""} provider placeholder ${o} conflicts with secretEnv`);return{...t??{},prependPath:t?.prependPath??[],env:{...i,...n}}}function H6e(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)?e:null}function Vte(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}var bc=b(()=>{Ni();_a();yf()});import{spawnSync as Wte}from"node:child_process";import{createHash as B6e}from"node:crypto";import{chmodSync as qte,lstatSync as V6e,mkdtempSync as q6e,readFileSync as W6e,readlinkSync as K6e,rmSync as Kte,statSync as G6e}from"node:fs";import{tmpdir as J6e}from"node:os";import{isAbsolute as Z6e,join as Zs}from"node:path";import{fileURLToPath as Y6e}from"node:url";function Sc(e){return{executionUser:null,commandPath:null,appRoot:null,install:null,installerUrl:null,executedInstallerUrl:null,exitCode:null,error:null,...e}}function Ys(e,t){if(e==="openclaw")return Zs(t,".local","bin","openclaw");if(e==="hermes")return Zs(t,".local","bin","hermes");return null}function Ad(e,t){if(e==="openclaw")return Zs(t,".openclaw");if(e==="hermes")return Zs(t,".hermes","hermes-agent");return null}function eVe(){let e=process.env.CLAWDI_RUNTIME_INSTALL_TIMEOUT;if(e===void 0)return A2;let t=Number(e);if(Number.isSafeInteger(t)&&t>0&&t<=2147483647)return t;return console.warn(`CLAWDI_RUNTIME_INSTALL_TIMEOUT must be a valid positive integer; using ${A2}ms`),A2}function tVe(e,t){if(e!=="hermes"||!t.enabled||!t.install||!t.services?.dashboard)return null;let n=Zs(t.install.home,".hermes","hermes-agent","venv","bin","python");if(!an(n))return`Hermes dashboard runtime is missing its managed Python interpreter: ${n}`;let r;try{r=de(n,["-c",X6e],t.install.home,t.install.home,{timeoutMs:Q6e})}catch(i){return`Hermes dashboard runtime capability probe failed: ${i instanceof Error?i.message:String(i)}`}if(r.status===0)return null;return`Hermes dashboard runtime is incompatible: ${Mi(String(r.stderr??""))??(r.error instanceof Error?r.error.message:"uvicorn.Server.capture_signals is unavailable")}`}function nVe(e,t,n,r,i=[]){let o=process.env.CLAWDI_RUNTIME_USER?.trim(),s=rVe(e,t);if(!o||o==="root")return{command:"bash",args:[n,...t.args,...i],env:s,executionUser:null};let a=Dl(o,t.home,"bash",[n,...t.args,...i],{runtimeUid:r.uid,runtimeGid:r.gid});return{command:a.command,args:a.args,env:{...s,...a.env},executionUser:o}}function rVe(e,t){let n={...process.env,HOME:t.home,PATH:[Zs(t.home,".local","bin"),process.env.PATH].filter(Boolean).join(":")};if(VO(n),e==="openclaw")for(let r of["OPENCLAW_HOME","OPENCLAW_STATE_DIR","OPENCLAW_CONFIG_PATH","OPENCLAW_PREFIX","OPENCLAW_VERSION","OPENCLAW_INSTALL_METHOD","OPENCLAW_GIT_DIR","OPENCLAW_GIT_UPDATE"])delete n[r];return n.SSL_CERT_FILE=No,n.NODE_EXTRA_CA_CERTS=No,n.REQUESTS_CA_BUNDLE=No,n.CURL_CA_BUNDLE=No,n.GIT_SSL_CAINFO=No,n.NPM_CONFIG_CAFILE=No,n.npm_config_cafile=No,n}function Mi(e){if(!e)return null;return e.slice(-4000)}function iVe(e){if(e==="openclaw")return"CLAWDI_RUNTIME_TEST_OPENCLAW_INSTALLER";if(e==="hermes")return"CLAWDI_RUNTIME_TEST_HERMES_INSTALLER";return null}function oVe(e,t){let n=iVe(e),r=n?process.env[n]?.trim():void 0;if(r){if(process.env.CLAWDI_RUNTIME_ALLOW_TEST_INSTALLERS!=="1")throw Error(`${n} requires CLAWDI_RUNTIME_ALLOW_TEST_INSTALLERS=1`);return r}return t}function sVe(e,t,n){if(t.startsWith("file://"))return{path:Y6e(t)};if(t.startsWith("/"))return{path:t};if(!t.startsWith("https://"))throw Error(`runtime ${e} installer must use https:// or a test file URL`);let r=q6e(Zs(J6e(),`clawdi-${e}-installer-`));qte(r,493);let i=Zs(r,"install.sh"),o=Wte("curl",["-fsSL","--proto","=https","--tlsv1.2","--retry","3","-o",i,t],{encoding:"utf8"});if(o.status!==0){Kte(r,{recursive:!0,force:!0});let s=kc(n,`${e}-download`,o);throw Error(`could not download ${e} official installer; see ${s}`)}return qte(i,493),{path:i,cleanup:r}}function aVe(e,t,n,r){let i=new Date().toISOString(),o=Date.now(),s=(d)=>({...d,installStartedAt:i,installFinishedAt:new Date().toISOString(),installDurationMs:Math.max(0,Date.now()-o)}),a=Ys(e,t.home),l=Ad(e,t.home);if(!a||!l)return s(Sc({runtime:e,enabled:!0,status:"install_failed",commandPath:a,appRoot:l,install:t,installerUrl:t.url,error:`unsupported runtime ${e}`}));if(an(a))return s(Sc({runtime:e,enabled:!0,status:"present",commandPath:a,appRoot:l,install:t,installerUrl:t.url}));let c=oVe(e,t.url),u=sVe(e,c,n);try{let d=nVe(e,t,u.path,r),p=Wte(d.command,d.args,{cwd:t.home,env:d.env,encoding:"utf8",timeout:eVe()}),m=kc(n,e,p),g=p.status??1,f=g===0&&an(a);return s(Sc({runtime:e,enabled:!0,status:f?"installed":"install_failed",executionUser:d.executionUser,commandPath:a,appRoot:l,install:t,installerUrl:t.url,executedInstallerUrl:c===t.url?t.url:c,exitCode:g,error:f?null:`runtime ${e} installer failed or did not create ${a}; see ${m}`}))}catch(d){let p=kc(n,e,{error:d});return s(Sc({runtime:e,enabled:!0,status:"install_failed",commandPath:a,appRoot:l,install:t,installerUrl:t.url,executedInstallerUrl:c,error:`runtime ${e} installer failed; see ${p}`}))}finally{if(u.cleanup)Kte(u.cleanup,{recursive:!0,force:!0})}}function t0(e,t,n,r,i){if(!t.enabled)return Sc({runtime:e,enabled:!1,status:"disabled",install:t.install??null,installerUrl:t.install?.url??null});if(!t.install){if(t.run?.command?.trim()||bf(e)){let a=t.run?.command?.trim()||null,l=bf(e)&&a&&Jh(a)?a:null;return Sc({runtime:e,enabled:!0,status:"configured",commandPath:l,appRoot:l?Ad(e,n):null})}return Sc({runtime:e,enabled:!0,status:"install_failed",error:`runtime ${e} is enabled but missing install metadata`})}let o=aVe(e,t.install,r,i);if(o.error)return o;let s=tVe(e,t);return s?{...o,status:"install_failed",error:s}:o}function Gte(e,t,n,r,i){if(!t.install)return t0(e,t,n,r,i);if(!t.enabled)return t0(e,t,n,r,i);let o=Ys(e,t.install.home),s=Ad(e,t.install.home);return Sc({runtime:e,enabled:!0,status:o&&an(o)?"present":"configured",commandPath:o,appRoot:s,install:t.install,installerUrl:t.install.url,error:o&&s?null:`unsupported runtime ${e}`})}function kc(e,t,n){let r=Zs(e.statusRoot,"installer-logs",`${t}.log`),i=n.error?n.error instanceof Error?n.error.message:String(n.error):"",o=[`recordedAt=${new Date().toISOString()}`,`exitCode=${n.status??"unavailable"}`,`signal=${n.signal??"none"}`,`spawnError=${i}`,"--- stdout ---",String(n.stdout??""),"--- stderr ---",String(n.stderr??""),""].join(`
|
|
643
643
|
`),s={mode:384,dirMode:448};if(n.status!==0||n.signal||n.error)Ot(e,Zs(e.statusRoot,"installer-logs",`${t}.failed.log`),o,s);return Ot(e,r,o,s),r}function dn(e){if(!Z6e(e))return null;try{let t=V6e(e);if(!t.isFile()&&!t.isSymbolicLink())return null;let n=t.isSymbolicLink()?G6e(e):t;if(!n.isFile())return null;let r=W6e(e);return ut({path:e,contentsSha256:B6e("sha256").update(r).digest("hex"),kind:t.isSymbolicLink()?"symlink":"file",linkTarget:t.isSymbolicLink()?K6e(e):null,linkUid:t.uid,linkGid:t.gid,fileMode:n.mode&4095,fileUid:n.uid,fileGid:n.gid})}catch{return null}}function jw(e,t,n){let r=dn(e);if(!r)return null;let i=`${e}\x00${t}\x00${n}`,o=e0.get(i);if(o?.executableRevision===r)return o.commandRevision;if(!E2(e,t,n))return null;return e0.get(i)?.commandRevision??null}function E2(e,t,n){let r=dn(e);if(!r)return null;let i=`${e}\x00${t}\x00${n}`,o=e0.get(i);if(o?.executableRevision===r)return o.version;let s=e===Ys("hermes",t)?30000:1e4;try{let a=de(e,["--version"],t,n,{timeoutMs:s});if(a.error&&"code"in a.error&&a.error.code==="ETIMEDOUT")throw new Ol(`runtime --version probe for ${e}`,s);if(a.status!==0)return null;let l=Buffer.isBuffer(a.stdout)?a.stdout.toString("utf8"):a.stdout,c=Buffer.isBuffer(a.stderr)?a.stderr.toString("utf8"):a.stderr,u=[l,c].filter(Boolean).join(`
|
package/package.json
CHANGED
package/skills/clawdi/SKILL.md
CHANGED
|
@@ -137,7 +137,12 @@ when the user authorized updating them; do not delete them first. Existing Vault
|
|
|
137
137
|
remain unchanged until successful submission and are never shown or prefilled. Overlapping pending requests
|
|
138
138
|
are rejected; a change to any requested field conflicts with the entire batch.
|
|
139
139
|
Show the returned `url` unchanged to the user; do not ask them to paste secrets into chat.
|
|
140
|
-
Opening the link does not consume it.
|
|
140
|
+
Opening the link does not consume it. The user can add fields or import a pasted/uploaded
|
|
141
|
+
.env on the page, preview replacements, and apply them to the same form. Original requested
|
|
142
|
+
names remain mandatory; only the user chooses extras after link creation (32 fields total).
|
|
143
|
+
Saving the entire form consumes the link once. Selected fields must still match creation
|
|
144
|
+
state, and extras cannot overlap another pending request. Status includes saved extras and
|
|
145
|
+
their exact references; never assume only the originally requested names were saved.
|
|
141
146
|
|
|
142
147
|
Check `vault_request_status` with its `request_id` after the user finishes. `pending` is not
|
|
143
148
|
a secret value; `supplied` means the exact references are ready. On `expired` or `conflict`,
|
|
@@ -122,7 +122,12 @@ when the user authorized updating them; do not delete them first. Existing Vault
|
|
|
122
122
|
remain unchanged until successful submission and are never shown or prefilled. Overlapping pending requests
|
|
123
123
|
are rejected; a change to any requested field conflicts with the entire batch.
|
|
124
124
|
Show the returned `url` unchanged to the user; do not ask them to paste secrets into chat.
|
|
125
|
-
Opening the link does not consume it.
|
|
125
|
+
Opening the link does not consume it. The user can add fields or import a pasted/uploaded
|
|
126
|
+
.env on the page, preview replacements, and apply them to the same form. Original requested
|
|
127
|
+
names remain mandatory; only the user chooses extras after link creation (32 fields total).
|
|
128
|
+
Saving the entire form consumes the link once. Selected fields must still match creation
|
|
129
|
+
state, and extras cannot overlap another pending request. Status includes saved extras and
|
|
130
|
+
their exact references; never assume only the originally requested names were saved.
|
|
126
131
|
|
|
127
132
|
Check `vault_request_status` with its `request_id` after the user finishes. `pending` is not
|
|
128
133
|
a secret value; `supplied` means the exact references are ready. On `expired` or `conflict`,
|