@oh-my-pi/pi-coding-agent 18.1.0 → 18.1.1
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/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var Oho=Object.create;var{getPrototypeOf:Pho,defineProperty:RVe,getOwnPropertyNames:Fho}=Object;var _ho=Object.prototype.hasOwnProperty;function Lho(e){return this[e]}var Dho,Nho,Cn=(e,t,s)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?Dho??=new WeakMap:Nho??=new WeakMap,r=o.get(e);if(r)return r}s=e!=null?Oho(Pho(e)):{};let i=t||!e||!e.__esModule?RVe(s,"default",{value:e,enumerable:!0}):s;if(e&&typeof e==="object"||typeof e==="function"){for(let a of Fho(e))if(!_ho.call(i,a))RVe(i,a,{get:Lho.bind(e,a),enumerable:!0})}if(n)o.set(e,i);return i};var Ie=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qho=(e)=>e;function Uho(e,t){this[e]=qho.bind(null,t)}var Ge=(e,t)=>{for(var s in t)RVe(e,s,{get:t[s],enumerable:!0,configurable:!0,set:Uho.bind(t,s)})};var S=(e,t)=>()=>(e&&(t=e(e=0)),t);var ti=import.meta.require;var Jjt="18.1.0",Xjt;var Yjt=S(()=>{Xjt={bun:">=1.3.14"}});function lR(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}function pe(e){return lR(e)&&e.code==="ENOENT"}function Ij(e){return lR(e)&&e.code==="EACCES"}function Qjt(e){return lR(e)&&e.code==="EISDIR"}function CP(e){return lR(e)&&e.code==="ENOTDIR"}function zw(e){return lR(e)&&e.code==="EEXIST"}function xl(e,t){return lR(e)&&e.code===t}import*as lo from"fs";import*as BA from"os";import*as vs from"path";function tU(e){let t=e?.trim();if(!t||t==="default")return;if(t==="."||t===".."||t.endsWith(".")||!Zjt.test(t)||Bho.test(t))throw Error(`Invalid OMP profile "${e}". Profile names must match ${Zjt.source}, cannot be "." or "..", cannot end with ".", and cannot be a Windows reserved device name (CON, PRN, AUX, NUL, COM0-9, LPT0-9, or any of those with an extension).`);return t}function SVe(e,t){return tU(e!==void 0?e:t)}function Who(){return SVe(process.env.OMP_PROFILE,process.env.PI_PROFILE)}function Gho(){try{return Who()}catch{return}}function wVe(){return vs.join(BA.homedir(),Gb())}function xVe(e){let t=wVe();return e?vs.join(t,"profiles",e):t}function EVe(){try{return tU(process.env.PI_PROFILE)}catch{return}}function jho(e){return vs.join(xVe(e),"agent")}function $ho(e,t){return e!==void 0&&t===jho(e)}function CVe(e){if(process.platform!=="darwin"||!e.startsWith("/private/"))return e;let t=e.slice(8);try{if(lo.realpathSync(e)===lo.realpathSync(t))return t}catch{}return e}function fQ(e){let t=vs.resolve(e);try{return lo.realpathSync(t)}catch{return t}}function Gp(e){let t=fQ(e);return process.platform==="win32"?t.toLowerCase():t}function $b(e,t){let s=Gp(e),n=Gp(t),o=vs.relative(s,n);return o===""||!o.startsWith("..")&&!vs.isAbsolute(o)}function Pj(e,t){if(!$b(e,t))return null;let s=Gp(e),n=Gp(t);return vs.relative(s,n)||null}function _e(){if(Oj===void 0)try{Oj=CVe(process.cwd())}catch{let e=[process.env.PWD,BA.homedir(),BA.tmpdir()];for(let t of e){if(!t||!vs.isAbsolute(t))continue;try{process.chdir(t),Oj=CVe(t);break}catch{}}if(Oj===void 0)throw Error("Unable to determine an accessible working directory")}return Oj}function wg(e){let t=CVe(vs.resolve(e));process.chdir(t),Oj=t}async function t$t(e){try{return!(await lo.promises.stat(e)).isDirectory()}catch(t){return pe(t)||CP(t)}}async function mQ(e){try{return(await lo.promises.stat(e)).isDirectory()}catch{return!1}}async function MVe(e){try{let[t]=await Promise.all([lo.promises.stat(e),lo.promises.access(e,lo.constants.X_OK)]);return t.isDirectory()}catch{return!1}}function gQ(e){try{return lo.accessSync(e,lo.constants.X_OK),lo.statSync(e).isDirectory()}catch{return!1}}function Fj(){try{let e=_e();if(gQ(e))return e}catch{}return BA.homedir()}function Gb(){return process.env.PI_CONFIG_DIR||Kw}function s$t(){let e=tT();return e?vs.join(Gb(),"profiles",e,"agent"):`${Gb()}/agent`}class dQ{configRoot;agentDir;#e;#t;#s=new Map;#n=new Map;constructor(e={}){let t=tU(e.profile);this.configRoot=xVe(t);let s=vs.join(this.configRoot,"agent"),n=t?void 0:e.agentDirOverride;this.agentDir=n?vs.resolve(n):s;let o=this.agentDir===s,r,i,a;if((process.platform==="linux"||process.platform==="darwin")&&o){let l=(u)=>{let p=process.env[u];if(!p)return;try{let c=vs.join(p,dt);if(t){let d=vs.join(c,"profiles",t);if(lo.existsSync(d))return d;return}if(lo.existsSync(c))return c}catch{}return};r=l("XDG_DATA_HOME"),i=l("XDG_STATE_HOME"),a=l("XDG_CACHE_HOME")}this.#e={data:r??this.configRoot,state:i??this.configRoot,cache:a??this.configRoot},this.#t={data:r??this.agentDir,state:i??this.agentDir,cache:a??this.agentDir}}rootSubdir(e,t){let s=this.#s.get(e);if(s)return s;let n=t?this.#e[t]:this.configRoot,o=vs.join(n,e);return this.#s.set(e,o),o}agentSubdir(e,t,s){if(!e||e===this.agentDir){let n=this.#n.get(t);if(n)return n;let o=s?this.#t[s]:this.agentDir,r=vs.join(o,t);return this.#n.set(t,r),r}return vs.join(e,t)}}function AVe(e,t,s=e){return $ho(e??s,t)?void 0:t}function n$t(){return uR?void 0:AVe(void 0,process.env.PI_CODING_AGENT_DIR,EVe())}function o$t(){bn=new dQ({agentDirOverride:n$t(),profile:uR})}function pR(){return bn.configRoot}function vVe(e){let t=tU(e);if(t&&!uR)Lhe=AVe(void 0,process.env.PI_CODING_AGENT_DIR,EVe());if(uR=t,uR)bn=new dQ({profile:uR}),process.env.OMP_PROFILE=uR,process.env.PI_PROFILE=uR,process.env.PI_CODING_AGENT_DIR=bn.agentDir;else{for(let s of Hho)delete process.env[s];if(Lhe===void 0)delete process.env.PI_CODING_AGENT_DIR;else process.env.PI_CODING_AGENT_DIR=Lhe;bn=new dQ({agentDirOverride:Lhe})}}function tT(){return uR}function r$t(e){return xVe(tU(e))}function os(){return bn.agentDir}function Dhe(e=_e()){return vs.join(e,Kw)}function i$t(){return bn.rootSubdir("reports","state")}function bP(){return bn.rootSubdir("logs","state")}function _j(e=new Date,t=process.pid){return vs.join(bP(),`${dt}.${e.toISOString().slice(0,10)}.${t}.log`)}function Ca(e){if(e!==void 0&&e!==zho)return vs.join(e,Gb(),"plugins");return bn.rootSubdir("plugins","data")}function xg(e){return vs.join(Ca(e),"node_modules")}function sU(e){return vs.join(Ca(e),"package.json")}function Nhe(e){return vs.join(Ca(e),"omp-plugins.lock.json")}function qhe(){return bn.rootSubdir("remote","data")}function a$t(e){let t=e?.trim();if(!t)return;let s=t;if(s==="~")s=BA.homedir();else if(s.startsWith("~/")||s.startsWith("~\\"))s=BA.homedir()+s.slice(1);return vs.isAbsolute(s)?vs.normalize(s):void 0}function IVe(e){return bVe=a$t(e),bVe}function Uhe(){return a$t(process.env.OMP_WORKTREE_DIR)??bVe??bn.rootSubdir("wt","data")}function l$t(){return bn.rootSubdir("ssh-control","state")}function u$t(){return bn.rootSubdir("remote-host","data")}function Hhe(){return bn.rootSubdir("python-env","data")}function Lj(){return bn.rootSubdir("puppeteer","cache")}function p$t(){return bn.rootSubdir("browser-relay","data")}function c$t(){return bn.rootSubdir("webcache","cache")}function d$t(){return bn.rootSubdir("autoqa.db","data")}function f$t(e){return Bun.hash(vs.resolve(e)).toString(16).padStart(16,"0").slice(-7)}function Bhe(e){return vs.join(Uhe(),e)}function OVe(){return bn.rootSubdir("gpu_cache.json","cache")}function PVe(){let e=process.env.OMP_GITHUB_CACHE_DB;if(e)return e;return bn.rootSubdir(vs.join("cache","github-cache.db"),"cache")}function m$t(){let e=process.env.OMP_COMMIT_CACHE_DB;if(e)return e;return bn.rootSubdir(vs.join("cache","commit-inference.db"),"cache")}function g$t(){return bn.rootSubdir(vs.join("cache","legacy-pi-extension-cache.db"),"cache")}function h$t(){let e=process.env.OMP_AUTH_BROKER_SNAPSHOT_CACHE;if(e)return e;return bn.rootSubdir(vs.join("cache","auth-broker-snapshot.enc"),"cache")}function T$t(){return bn.rootSubdir(vs.join("cache","avatars"),"cache")}function hQ(){return bn.rootSubdir(vs.join("cache","fastembed"),"cache")}function y$t(){return bn.rootSubdir(vs.join("cache","fastembed-runtime"),"cache")}function cR(){return bn.rootSubdir("stats.db","data")}function R$t(){return bn.rootSubdir("autoresearch","state")}function C$t(e){return vs.join(R$t(),e)}function b$t(e){return vs.join(R$t(),`${e}.db`)}function Kho(){return bn.rootSubdir("security","state")}function k$t(e){return vs.join(Kho(),e)}function Bo(e){return bn.agentSubdir(e,"agent.db","data")}function TQ(e){return bn.agentSubdir(e,"last-changelog-version","state")}function nU(e){return bn.agentSubdir(e,"history.db","data")}function Dj(e){return bn.agentSubdir(e,"models.db","data")}function mf(e){return bn.agentSubdir(e,vs.join("cache","tiny-models"),"cache")}function FVe(e){return bn.agentSubdir(e,vs.join("cache","document-conversions"),"cache")}function S$t(e){return bn.agentSubdir(e,vs.join("cache","composer"),"cache")}function jp(e){return bn.agentSubdir(e,"sessions","data")}function sT(e){return bn.agentSubdir(e,"blobs","data")}function kP(e){return bn.agentSubdir(e,"themes")}function w$t(e){return bn.agentSubdir(e,"tools")}function x$t(e){return bn.agentSubdir(e,"prompts")}function Nj(e){return bn.agentSubdir(e,"memories","state")}function _Ve(e){return bn.agentSubdir(e,"terminal-sessions","state")}function E$t(e){return bn.agentSubdir(e,`${dt}-debug.log`,"state")}function M$t(e,t){if(t===e)return;try{if(lo.existsSync(t)||!lo.existsSync(e))return;lo.mkdirSync(vs.dirname(t),{recursive:!0}),lo.copyFileSync(e,t,lo.constants.COPYFILE_EXCL)}catch{}}function Whe(){let e=bn.agentSubdir(void 0,"secret-placeholder.key","state");return M$t(vs.join(bn.agentDir,"secret-placeholder.key"),e),e}function Ghe(){return bn.rootSubdir(vs.join("run","daemons"),"state")}function hd(e){let t=Bun.hash.wyhash(vs.resolve(e)).toString(16).padStart(16,"0");return vs.join(Ghe(),t)}function jhe(){return vs.join(wVe(),"run","daemons","global")}function $he(e){if(!/^[a-z0-9][a-z0-9._-]*$/i.test(e))throw Error(`Invalid global daemon service name: ${JSON.stringify(e)}`);return vs.join(jhe(),e)}function A$t(){return bn.rootSubdir(vs.join("run","provider-inflight"),"state")}function nT(){let e=bn.rootSubdir("marketplaces.json","data");return M$t(vs.join(bn.configRoot,"marketplaces.json"),e),e}function v$t(e=_e()){return vs.join(Dhe(e),"prompts")}function I$t(e=_e()){return vs.join(Dhe(e),"plugin-overrides.json")}function Yo(e,t=_e()){if(e==="user")return vs.join(os(),"mcp.json");return vs.join(Dhe(t),"mcp.json")}function Lc(e,t=_e()){if(e==="user")return vs.join(os(),"ssh.json");return vs.join(Dhe(t),"ssh.json")}function zhe(){let e=process.env.OMP_APP_NAME?.trim();return e?e:"omp"}function Eg(){if(cQ)return cQ;let e=vs.join(wVe(),Vho),t=!1;try{let n=lo.readFileSync(e,"utf8").trim();if(e$t.test(n))return cQ=n,n;t=n.length>0}catch{}let s=crypto.randomUUID();try{if(lo.mkdirSync(vs.dirname(e),{recursive:!0}),t)try{lo.unlinkSync(e)}catch{}let n=lo.openSync(e,lo.constants.O_WRONLY|lo.constants.O_CREAT|lo.constants.O_EXCL,384);try{lo.writeSync(n,`${s}
|
|
3
|
+
var Oho=Object.create;var{getPrototypeOf:Pho,defineProperty:RVe,getOwnPropertyNames:Fho}=Object;var _ho=Object.prototype.hasOwnProperty;function Lho(e){return this[e]}var Dho,Nho,Cn=(e,t,s)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?Dho??=new WeakMap:Nho??=new WeakMap,r=o.get(e);if(r)return r}s=e!=null?Oho(Pho(e)):{};let i=t||!e||!e.__esModule?RVe(s,"default",{value:e,enumerable:!0}):s;if(e&&typeof e==="object"||typeof e==="function"){for(let a of Fho(e))if(!_ho.call(i,a))RVe(i,a,{get:Lho.bind(e,a),enumerable:!0})}if(n)o.set(e,i);return i};var Ie=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qho=(e)=>e;function Uho(e,t){this[e]=qho.bind(null,t)}var Ge=(e,t)=>{for(var s in t)RVe(e,s,{get:t[s],enumerable:!0,configurable:!0,set:Uho.bind(t,s)})};var S=(e,t)=>()=>(e&&(t=e(e=0)),t);var ti=import.meta.require;var Jjt="18.1.1",Xjt;var Yjt=S(()=>{Xjt={bun:">=1.3.14"}});function lR(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}function pe(e){return lR(e)&&e.code==="ENOENT"}function Ij(e){return lR(e)&&e.code==="EACCES"}function Qjt(e){return lR(e)&&e.code==="EISDIR"}function CP(e){return lR(e)&&e.code==="ENOTDIR"}function zw(e){return lR(e)&&e.code==="EEXIST"}function xl(e,t){return lR(e)&&e.code===t}import*as lo from"fs";import*as BA from"os";import*as vs from"path";function tU(e){let t=e?.trim();if(!t||t==="default")return;if(t==="."||t===".."||t.endsWith(".")||!Zjt.test(t)||Bho.test(t))throw Error(`Invalid OMP profile "${e}". Profile names must match ${Zjt.source}, cannot be "." or "..", cannot end with ".", and cannot be a Windows reserved device name (CON, PRN, AUX, NUL, COM0-9, LPT0-9, or any of those with an extension).`);return t}function SVe(e,t){return tU(e!==void 0?e:t)}function Who(){return SVe(process.env.OMP_PROFILE,process.env.PI_PROFILE)}function Gho(){try{return Who()}catch{return}}function wVe(){return vs.join(BA.homedir(),Gb())}function xVe(e){let t=wVe();return e?vs.join(t,"profiles",e):t}function EVe(){try{return tU(process.env.PI_PROFILE)}catch{return}}function jho(e){return vs.join(xVe(e),"agent")}function $ho(e,t){return e!==void 0&&t===jho(e)}function CVe(e){if(process.platform!=="darwin"||!e.startsWith("/private/"))return e;let t=e.slice(8);try{if(lo.realpathSync(e)===lo.realpathSync(t))return t}catch{}return e}function fQ(e){let t=vs.resolve(e);try{return lo.realpathSync(t)}catch{return t}}function Gp(e){let t=fQ(e);return process.platform==="win32"?t.toLowerCase():t}function $b(e,t){let s=Gp(e),n=Gp(t),o=vs.relative(s,n);return o===""||!o.startsWith("..")&&!vs.isAbsolute(o)}function Pj(e,t){if(!$b(e,t))return null;let s=Gp(e),n=Gp(t);return vs.relative(s,n)||null}function _e(){if(Oj===void 0)try{Oj=CVe(process.cwd())}catch{let e=[process.env.PWD,BA.homedir(),BA.tmpdir()];for(let t of e){if(!t||!vs.isAbsolute(t))continue;try{process.chdir(t),Oj=CVe(t);break}catch{}}if(Oj===void 0)throw Error("Unable to determine an accessible working directory")}return Oj}function wg(e){let t=CVe(vs.resolve(e));process.chdir(t),Oj=t}async function t$t(e){try{return!(await lo.promises.stat(e)).isDirectory()}catch(t){return pe(t)||CP(t)}}async function mQ(e){try{return(await lo.promises.stat(e)).isDirectory()}catch{return!1}}async function MVe(e){try{let[t]=await Promise.all([lo.promises.stat(e),lo.promises.access(e,lo.constants.X_OK)]);return t.isDirectory()}catch{return!1}}function gQ(e){try{return lo.accessSync(e,lo.constants.X_OK),lo.statSync(e).isDirectory()}catch{return!1}}function Fj(){try{let e=_e();if(gQ(e))return e}catch{}return BA.homedir()}function Gb(){return process.env.PI_CONFIG_DIR||Kw}function s$t(){let e=tT();return e?vs.join(Gb(),"profiles",e,"agent"):`${Gb()}/agent`}class dQ{configRoot;agentDir;#e;#t;#s=new Map;#n=new Map;constructor(e={}){let t=tU(e.profile);this.configRoot=xVe(t);let s=vs.join(this.configRoot,"agent"),n=t?void 0:e.agentDirOverride;this.agentDir=n?vs.resolve(n):s;let o=this.agentDir===s,r,i,a;if((process.platform==="linux"||process.platform==="darwin")&&o){let l=(u)=>{let p=process.env[u];if(!p)return;try{let c=vs.join(p,dt);if(t){let d=vs.join(c,"profiles",t);if(lo.existsSync(d))return d;return}if(lo.existsSync(c))return c}catch{}return};r=l("XDG_DATA_HOME"),i=l("XDG_STATE_HOME"),a=l("XDG_CACHE_HOME")}this.#e={data:r??this.configRoot,state:i??this.configRoot,cache:a??this.configRoot},this.#t={data:r??this.agentDir,state:i??this.agentDir,cache:a??this.agentDir}}rootSubdir(e,t){let s=this.#s.get(e);if(s)return s;let n=t?this.#e[t]:this.configRoot,o=vs.join(n,e);return this.#s.set(e,o),o}agentSubdir(e,t,s){if(!e||e===this.agentDir){let n=this.#n.get(t);if(n)return n;let o=s?this.#t[s]:this.agentDir,r=vs.join(o,t);return this.#n.set(t,r),r}return vs.join(e,t)}}function AVe(e,t,s=e){return $ho(e??s,t)?void 0:t}function n$t(){return uR?void 0:AVe(void 0,process.env.PI_CODING_AGENT_DIR,EVe())}function o$t(){bn=new dQ({agentDirOverride:n$t(),profile:uR})}function pR(){return bn.configRoot}function vVe(e){let t=tU(e);if(t&&!uR)Lhe=AVe(void 0,process.env.PI_CODING_AGENT_DIR,EVe());if(uR=t,uR)bn=new dQ({profile:uR}),process.env.OMP_PROFILE=uR,process.env.PI_PROFILE=uR,process.env.PI_CODING_AGENT_DIR=bn.agentDir;else{for(let s of Hho)delete process.env[s];if(Lhe===void 0)delete process.env.PI_CODING_AGENT_DIR;else process.env.PI_CODING_AGENT_DIR=Lhe;bn=new dQ({agentDirOverride:Lhe})}}function tT(){return uR}function r$t(e){return xVe(tU(e))}function os(){return bn.agentDir}function Dhe(e=_e()){return vs.join(e,Kw)}function i$t(){return bn.rootSubdir("reports","state")}function bP(){return bn.rootSubdir("logs","state")}function _j(e=new Date,t=process.pid){return vs.join(bP(),`${dt}.${e.toISOString().slice(0,10)}.${t}.log`)}function Ca(e){if(e!==void 0&&e!==zho)return vs.join(e,Gb(),"plugins");return bn.rootSubdir("plugins","data")}function xg(e){return vs.join(Ca(e),"node_modules")}function sU(e){return vs.join(Ca(e),"package.json")}function Nhe(e){return vs.join(Ca(e),"omp-plugins.lock.json")}function qhe(){return bn.rootSubdir("remote","data")}function a$t(e){let t=e?.trim();if(!t)return;let s=t;if(s==="~")s=BA.homedir();else if(s.startsWith("~/")||s.startsWith("~\\"))s=BA.homedir()+s.slice(1);return vs.isAbsolute(s)?vs.normalize(s):void 0}function IVe(e){return bVe=a$t(e),bVe}function Uhe(){return a$t(process.env.OMP_WORKTREE_DIR)??bVe??bn.rootSubdir("wt","data")}function l$t(){return bn.rootSubdir("ssh-control","state")}function u$t(){return bn.rootSubdir("remote-host","data")}function Hhe(){return bn.rootSubdir("python-env","data")}function Lj(){return bn.rootSubdir("puppeteer","cache")}function p$t(){return bn.rootSubdir("browser-relay","data")}function c$t(){return bn.rootSubdir("webcache","cache")}function d$t(){return bn.rootSubdir("autoqa.db","data")}function f$t(e){return Bun.hash(vs.resolve(e)).toString(16).padStart(16,"0").slice(-7)}function Bhe(e){return vs.join(Uhe(),e)}function OVe(){return bn.rootSubdir("gpu_cache.json","cache")}function PVe(){let e=process.env.OMP_GITHUB_CACHE_DB;if(e)return e;return bn.rootSubdir(vs.join("cache","github-cache.db"),"cache")}function m$t(){let e=process.env.OMP_COMMIT_CACHE_DB;if(e)return e;return bn.rootSubdir(vs.join("cache","commit-inference.db"),"cache")}function g$t(){return bn.rootSubdir(vs.join("cache","legacy-pi-extension-cache.db"),"cache")}function h$t(){let e=process.env.OMP_AUTH_BROKER_SNAPSHOT_CACHE;if(e)return e;return bn.rootSubdir(vs.join("cache","auth-broker-snapshot.enc"),"cache")}function T$t(){return bn.rootSubdir(vs.join("cache","avatars"),"cache")}function hQ(){return bn.rootSubdir(vs.join("cache","fastembed"),"cache")}function y$t(){return bn.rootSubdir(vs.join("cache","fastembed-runtime"),"cache")}function cR(){return bn.rootSubdir("stats.db","data")}function R$t(){return bn.rootSubdir("autoresearch","state")}function C$t(e){return vs.join(R$t(),e)}function b$t(e){return vs.join(R$t(),`${e}.db`)}function Kho(){return bn.rootSubdir("security","state")}function k$t(e){return vs.join(Kho(),e)}function Bo(e){return bn.agentSubdir(e,"agent.db","data")}function TQ(e){return bn.agentSubdir(e,"last-changelog-version","state")}function nU(e){return bn.agentSubdir(e,"history.db","data")}function Dj(e){return bn.agentSubdir(e,"models.db","data")}function mf(e){return bn.agentSubdir(e,vs.join("cache","tiny-models"),"cache")}function FVe(e){return bn.agentSubdir(e,vs.join("cache","document-conversions"),"cache")}function S$t(e){return bn.agentSubdir(e,vs.join("cache","composer"),"cache")}function jp(e){return bn.agentSubdir(e,"sessions","data")}function sT(e){return bn.agentSubdir(e,"blobs","data")}function kP(e){return bn.agentSubdir(e,"themes")}function w$t(e){return bn.agentSubdir(e,"tools")}function x$t(e){return bn.agentSubdir(e,"prompts")}function Nj(e){return bn.agentSubdir(e,"memories","state")}function _Ve(e){return bn.agentSubdir(e,"terminal-sessions","state")}function E$t(e){return bn.agentSubdir(e,`${dt}-debug.log`,"state")}function M$t(e,t){if(t===e)return;try{if(lo.existsSync(t)||!lo.existsSync(e))return;lo.mkdirSync(vs.dirname(t),{recursive:!0}),lo.copyFileSync(e,t,lo.constants.COPYFILE_EXCL)}catch{}}function Whe(){let e=bn.agentSubdir(void 0,"secret-placeholder.key","state");return M$t(vs.join(bn.agentDir,"secret-placeholder.key"),e),e}function Ghe(){return bn.rootSubdir(vs.join("run","daemons"),"state")}function hd(e){let t=Bun.hash.wyhash(vs.resolve(e)).toString(16).padStart(16,"0");return vs.join(Ghe(),t)}function jhe(){return vs.join(wVe(),"run","daemons","global")}function $he(e){if(!/^[a-z0-9][a-z0-9._-]*$/i.test(e))throw Error(`Invalid global daemon service name: ${JSON.stringify(e)}`);return vs.join(jhe(),e)}function A$t(){return bn.rootSubdir(vs.join("run","provider-inflight"),"state")}function nT(){let e=bn.rootSubdir("marketplaces.json","data");return M$t(vs.join(bn.configRoot,"marketplaces.json"),e),e}function v$t(e=_e()){return vs.join(Dhe(e),"prompts")}function I$t(e=_e()){return vs.join(Dhe(e),"plugin-overrides.json")}function Yo(e,t=_e()){if(e==="user")return vs.join(os(),"mcp.json");return vs.join(Dhe(t),"mcp.json")}function Lc(e,t=_e()){if(e==="user")return vs.join(os(),"ssh.json");return vs.join(Dhe(t),"ssh.json")}function zhe(){let e=process.env.OMP_APP_NAME?.trim();return e?e:"omp"}function Eg(){if(cQ)return cQ;let e=vs.join(wVe(),Vho),t=!1;try{let n=lo.readFileSync(e,"utf8").trim();if(e$t.test(n))return cQ=n,n;t=n.length>0}catch{}let s=crypto.randomUUID();try{if(lo.mkdirSync(vs.dirname(e),{recursive:!0}),t)try{lo.unlinkSync(e)}catch{}let n=lo.openSync(e,lo.constants.O_WRONLY|lo.constants.O_CREAT|lo.constants.O_EXCL,384);try{lo.writeSync(n,`${s}
|
|
4
4
|
`)}finally{lo.closeSync(n)}}catch(n){if(n.code==="EEXIST")try{let o=lo.readFileSync(e,"utf8").trim();if(e$t.test(o))return cQ=o,o}catch{}}return cQ=s,s}var dt="omp",Kw=".omp",jb,gr,to,kVe,Zjt,Hho,Bho,Oj,uR,bn,Lhe,zho,bVe,cQ=null,Vho="install-id",e$t;var $p=S(()=>{Yjt();jb=["config.yml","config.yaml"],gr=Jjt,to=`omp/${gr}`,kVe=Xjt.bun.replace(/[^0-9.]/g,""),Zjt=/^[a-z0-9][a-z0-9._-]{0,63}$/,Hho=["OMP_PROFILE","PI_PROFILE"],Bho=/^(?:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\..*)?$/i;uR=Gho();bn=new dQ({agentDirOverride:n$t(),profile:uR}),Lhe=AVe(uR,process.env.PI_CODING_AGENT_DIR,uR??EVe()),zho=BA.homedir();e$t=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i});import*as O$t from"crypto";import*as Mg from"fs";import*as P$t from"os";import*as F$t from"path";function Yho(e){if(e===null||typeof e!=="object")return!1;let t=e;return typeof t.date==="number"&&typeof t.name==="string"&&typeof t.hash==="string"}class LVe{#e;#t;#s;#n;#o;#r;#a;#i;#l=0;#u;#p=0;#c=!1;constructor(e){this.#e=e.directory,this.#t=e.filenamePrefix,this.#s=e.filenameSuffix,this.#n=e.auditFile,this.#o=e.maxBytes,this.#r=e.maxFiles,this.#a=this.#T();let t=new Date;this.#m(this.#d(t));let s=this.#u;if(s)this.#h(s,t.getTime()),Mg.closeSync(Mg.openSync(s,"a"))}write(e){if(this.#c)return;let t=new Date;this.#m(this.#d(t));let s=this.#u;if(!s)return;this.#h(s,t.getTime());let n=`${e}${P$t.EOL}`;Mg.appendFileSync(s,n,"utf8"),this.#p+=Buffer.byteLength(n)}close(){this.#c=!0}#d(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}#m(e){if(e!==this.#i)this.#i=e,this.#l=0,this.#f(e,0);while(this.#p>this.#o)this.#l++,this.#f(e,this.#l)}#f(e,t){let s=t===0?"":`.${t}`;this.#u=F$t.join(this.#e,`${this.#t}.${e}.${this.#s}.log${s}`);try{this.#p=Mg.statSync(this.#u).size}catch{this.#p=0}}#h(e,t){if(this.#a.some((n)=>n.name===e))return;let s=O$t.createHash("sha256").update(`${e}LOG_FILE${t}`).digest("hex");this.#a.push({date:t,name:e,hash:s});while(this.#a.length>this.#r){let n=this.#a.shift();if(!n)break;try{Mg.rmSync(n.name,{force:!0})}catch{}}this.#g()}#T(){try{let e=JSON.parse(Mg.readFileSync(this.#n,"utf8"));return Array.isArray(e.files)?e.files.filter(Yho):[]}catch{return[]}}#g(){let e={keep:{days:!1,amount:this.#r},auditLog:this.#n,files:this.#a,hashType:"sha256"};Mg.writeFileSync(this.#n,JSON.stringify(e,void 0,4),"utf8")}}var _$t=()=>{};function D$t(){let e=globalThis,t=e[L$t];if(!t||t.length===0)return[];return e[L$t]=[],t}var L$t;var N$t=S(()=>{L$t=Symbol.for("omp.moduleLoadBuffer")});var v={};Ge(v,{debug:()=>Td,endTiming:()=>yTo,error:()=>rU,info:()=>dTo,openSpanPath:()=>RTo,printTimings:()=>mTo,recordModuleLoadSpan:()=>G$t,registerLogSink:()=>Qho,setTransports:()=>HVe,shouldExitAfterTimings:()=>fTo,startTiming:()=>gTo,startupMarker:()=>Khe,time:()=>wTo,timingModeIncludes:()=>Jhe,warn:()=>si});import{AsyncLocalStorage as Jho}from"async_hooks";import*as fm from"fs";import*as H$t from"os";import*as UVe from"path";import{isPromise as Xho}from"util/types";function Qho(e){return Yhe.add(e),()=>{Yhe.delete(e)}}function Xhe(e,t,s){if(Yhe.size===0)return;let n={level:e,message:t,context:s,timestamp:new Date};for(let o of Yhe)try{o(n)}catch{}}function nTo(e){try{return process.kill(e,0),!0}catch(t){return!(t instanceof Error&&("code"in t)&&(t.code==="ESRCH"||t.code==="EINVAL"))}}function oTo(e){let t;try{t=fm.readdirSync(e,{withFileTypes:!0})}catch{return}let s=new Date,n=`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-`+String(s.getDate()).padStart(2,"0"),o=new Date(s);o.setDate(o.getDate()-(sTo-1));let r=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-`+String(o.getDate()).padStart(2,"0"),i=new Map;for(let a of t){if(!a.isFile())continue;let l=Zho.exec(a.name),u=eTo.exec(a.name),p=l?.[2]??u?.[1];if(!p||nTo(Number(p)))continue;let c=UVe.join(e,a.name);if(u){if(tTo===0)try{fm.rmSync(c,{force:!0})}catch{}continue}if(!l?.[1])continue;if(l[1]<r||l[1]>n){try{fm.rmSync(c,{force:!0})}catch{}continue}let d=`${p}:${l[1]}`,f=i.get(d)??[];f.push({path:c,rollover:Number(l[3]??0)}),i.set(d,f)}for(let a of i.values()){if(a.length<=q$t)continue;let l=[];for(let u of a)try{l.push({...u,mtimeMs:fm.statSync(u.path).mtimeMs})}catch{}l.sort((u,p)=>p.mtimeMs-u.mtimeMs||p.rollover-u.rollover||(u.path<p.path?-1:u.path>p.path?1:0));for(let u of l.slice(q$t))try{fm.rmSync(u.path,{force:!0})}catch{}}}function rTo(e){if(!fm.existsSync(e))fm.mkdirSync(e,{recursive:!0});return e}function iTo(e,t){if(t instanceof Error){let s={name:t.name,message:t.message,stack:t.stack},n=t;for(let o in n)s[o]=n[o];if(t.cause!==void 0)s.cause=t.cause;return s}return t}function WA(e,t=2){return String(e).padStart(t,"0")}function aTo(e){let t=-e.getTimezoneOffset(),s=Math.abs(t),n=t>=0?"+":"-";return`${WA(e.getFullYear(),4)}-${WA(e.getMonth()+1)}-${WA(e.getDate())}T${WA(e.getHours())}:${WA(e.getMinutes())}:${WA(e.getSeconds())}.${WA(e.getMilliseconds(),3)}${n}${WA(Math.floor(s/60))}:${WA(s%60)}`}function uTo(e,t,s){let n=!lTo.test(t)&&s!==null&&typeof s==="object"?s:void 0,o=Object.assign({},n,{level:e,message:t});if(n?.message)o.message=`${t} ${n.message}`;if(n?.stack)o.stack=n.stack;if(n?.cause)o.cause=n.cause;return o}function U$t(e){let t=aTo(new Date);e.timestamp=t;let s={timestamp:t,level:e.level,pid:process.pid,message:e.message};for(let[n,o]of Object.entries(e))if(n!=="level"&&n!=="timestamp"&&n!=="message")s[n]=o;return JSON.stringify(s,iTo)}function pTo(e){let t=rTo(e??bP());return oTo(t),new LVe({directory:t,filenamePrefix:"omp",filenameSuffix:String(process.pid),maxBytes:10485760,maxFiles:5,auditFile:UVe.join(t,`.omp.${process.pid}-audit.json`)})}function W$t(e){return{file:e.file?pTo(typeof e.file==="string"?e.file:void 0):void 0,console:e.console===!0}}function cTo(){return qj??=W$t(B$t),qj}function Qhe(e,t,s){let n=cTo(),o=uTo(e,t,s);if(!n.file&&!n.console)return;let r=U$t(o);if(n.file)n.file.write(r);if(n.console)fm.writeSync(1,`${U$t(o)}${H$t.EOL}`)}function HVe(e){if(B$t=e,!qj)return;let t=qj;qj={file:void 0,console:!1},t.file?.close(),qj=W$t(e)}function rU(e,t){try{Qhe("error",e,t)}catch{}Xhe("error",e,t)}function si(e,t){try{Qhe("warn",e,t)}catch{}Xhe("warn",e,t)}function dTo(e,t){try{Qhe("info",e,t)}catch{}Xhe("info",e,t)}function Td(e,t){try{Qhe("debug",e,t)}catch{}Xhe("debug",e,t)}function Khe(e){if(!process.env.PI_DEBUG_STARTUP)return;try{fm.writeSync(2,`[startup] ${e}
|
|
5
5
|
`)}catch{}}function Jhe(e){let t=process.env.PI_TIMING;if(!t)return!1;if(t===e)return!0;let s=0;for(let n=0;n<=t.length;n++){let o=n===t.length?44:t.charCodeAt(n);if(!(o===44||o===58||o===59||o===43||o<=32))continue;if(n>s&&t.slice(s,n)===e)return!0;s=n+1}return!1}function fTo(){return Jhe("x")||Jhe("full")}function mTo(){if(!Uj||!Ru){console.error(`
|
|
6
6
|
--- Startup Timings ---
|
|
@@ -1068,7 +1068,7 @@ ${e.content}
|
|
|
1068
1068
|
selectableModels { name ref }
|
|
1069
1069
|
pinnedModel { name ref }
|
|
1070
1070
|
}
|
|
1071
|
-
}`,bjo,ZZe="omp_agent",eet="omp_inline_prompt",kjo,Sjo,ret=(e,t,s)=>{let n=new ln,o=C$o(e);n.push({type:"start",partial:o});let r={stream:n,output:o,started:!0};return t$o(e,t,s,r).catch((i)=>{let a=HF(i);if(!n.done)o.stopReason="error",o.errorMessage=r.goalOverflowMessage??a,n.push({type:"error",reason:"error",error:o})}),n},Nns,Wns,P$o="<|im_start|>",F$o="<|im_end|>",X$o;var aet=S(()=>{kke();ut();_r();na();VU();Fns();$g();fjo=dSe.resolve(import.meta.dir,"../../../../.tmp/gitlab-duo-workflow-trace.log");bjo=["incremental_streaming","read_file_chunked","shell_command","command_timeout","tool_call_approval"],kjo=["on_agent_reasoning","on_agent_final_answer","on_tool_execution_success","on_tool_execution_failed"],Sjo=["runMCPTool","run_mcp_tool"];Nns=new Map;Wns=_ns.trim();X$o=["Chat Agent","context_builder"]});import{Buffer as nos}from"buffer";import*as aos from"os";import*as los from"path";function ozo(){return nye("GOOGLE_VERTEX_REFRESH_SKEW_MS",60000)}function rzo(){return los.join(aos.homedir(),".config","gcloud","application_default_credentials.json")}async function oos(e){try{return await Bun.file(e).json()}catch(t){if(pe(t))return;throw t}}async function izo(){let e=Bun.env.GOOGLE_APPLICATION_CREDENTIALS;if(e){let n=await oos(e);if(!n)throw new Vt(`GOOGLE_APPLICATION_CREDENTIALS points to a missing file: ${e}`);return{source:`gac:${e}`,creds:n}}let t=rzo(),s=await oos(t);if(s)return{source:`user:${t}`,creds:s};return}function cet(e){let t=typeof e==="string"?nos.from(e,"utf8"):e;return nos.from(t.buffer,t.byteOffset,t.byteLength).toString("base64url")}function azo(e){let t=e.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,"");if(!t)throw new Vt("Invalid PEM: empty body");return Uint8Array.fromBase64(t)}async function lzo(e,t,s){let n={alg:"RS256",typ:"JWT"};if(s)n.kid=s;let o=`${cet(JSON.stringify(n))}.${cet(JSON.stringify(e))}`,r=await globalThis.crypto.subtle.importKey("pkcs8",azo(t),{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"]),i=new Uint8Array(await globalThis.crypto.subtle.sign("RSASSA-PKCS1-v1_5",r,new TextEncoder().encode(o)));return`${o}.${cet(i)}`}async function ros(e,t,s){let n=Math.floor(Date.now()/1000),o=await lzo({iss:e.client_email,scope:uos,aud:det,exp:n+3600,iat:n},e.private_key,e.private_key_id),r=new URLSearchParams({grant_type:nzo,assertion:o});return pos(det,r,t,s)}async function ios(e,t,s){let n=new URLSearchParams({client_id:e.client_id,client_secret:e.client_secret,refresh_token:e.refresh_token,grant_type:"refresh_token"});return pos(det,n,t,s)}async function uzo(e,t){let s=AbortSignal.timeout(2000),n=e?AbortSignal.any([e,s]):s;try{let o=await t(szo,{method:"GET",headers:{"Metadata-Flavor":"Google"},signal:n});if(!o.ok)return;return await o.json()}catch{return}}async function pos(e,t,s,n){let o=await n(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t.toString(),signal:s});if(!o.ok){let r=await o.text().catch(()=>"");throw new qe(`Google OAuth token exchange failed (${o.status}): ${r}`,{kind:"token-exchange",provider:"google-vertex",status:o.status})}return await o.json()}async function pzo(e,t){let s=await izo();if(s){let o=s.creds,r;if(o.type==="impersonated_service_account"){let a=/(?<target>[^/]+):(generateAccessToken|generateIdToken)$/.exec(o.service_account_impersonation_url)?.groups?.target;if(!a)throw RangeError(`Cannot extract target principal from ${o.service_account_impersonation_url}`);let l=o.source_credentials.type==="service_account"?await ros(o.source_credentials,e,t):await ios(o.source_credentials,e,t),u=await t(`https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${a}:generateAccessToken`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l.access_token}`},body:JSON.stringify({delegates:o.delegates??[],scope:[uos],lifetime:"3600s"}),signal:e});if(!u.ok){let d=await u.text().catch(()=>"");throw new qe(`Google Impersonation token exchange failed (${u.status}): ${d}`,{kind:"token-exchange",provider:"google-vertex",status:u.status})}let p=await u.json(),c=Math.max(0,Math.floor((new Date(p.expireTime).getTime()-Date.now())/1000));r={access_token:p.accessToken,expires_in:c,token_type:"Bearer"}}else r=o.type==="service_account"?await ros(o,e,t):await ios(o,e,t);return{source:s.source,token:r}}let n=await uzo(e,t);if(n)return{source:"metadata",token:n};throw new br(void 0,"Vertex AI requires Application Default Credentials. Set GOOGLE_APPLICATION_CREDENTIALS, run `gcloud auth application-default login`, or run on a GCE/Cloud Run instance with a service account.")}async function fSe(e){let t=Bun.env.GOOGLE_CLOUD_ACCESS_TOKEN||Bun.env.CLOUDSDK_AUTH_ACCESS_TOKEN;if(t)return t;let s=e?.fetch??globalThis.fetch.bind(globalThis),n=ozo(),o=Date.now();for(let[l,u]of uet){if(u.expiresAtMs-n>o)return u.token;uet.delete(l)}let r="vertex-adc",i=pet.get(r);if(i)return fT(i,e?.signal);let a=(async()=>{try{let{source:l,token:u}=await pzo(AbortSignal.timeout(czo),s),p=Date.now()+Math.max(0,u.expires_in*1000);return uet.set(l,{token:u.access_token,expiresAtMs:p}),v.debug("vertex.adc acquired access token",{source:l,expiresInSec:u.expires_in}),u.access_token}finally{pet.delete(r)}})();return pet.set(r,a),fT(a,e?.signal)}var det="https://oauth2.googleapis.com/token",szo="http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token",uos="https://www.googleapis.com/auth/cloud-platform",nzo="urn:ietf:params:oauth:grant-type:jwt-bearer",uet,pet,czo=30000;var fet=S(()=>{B();ut();ok();uet=new Map,pet=new Map});var met;var cos=S(()=>{met={type:"module",name:"@oh-my-pi/pi-ai",version:"18.1.0",description:"Unified LLM API with automatic model discovery and provider configuration",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Mario Zechner"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/ai"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["ai","llm","openai","anthropic","gemini","unified","api"],main:"./src/index.ts",types:"./dist/types/index.d.ts",scripts:{check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun test --parallel",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"},dependencies:{"@oh-my-pi/omptype":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-utils":"catalog:","@oh-my-pi/pi-wire":"catalog:"},devDependencies:{"@types/bun":"catalog:"},engines:{bun:">=1.3.14"},files:["src","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./error":{types:"./dist/types/error/index.d.ts",import:"./src/error/index.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./auth-broker":{types:"./dist/types/auth-broker/index.d.ts",import:"./src/auth-broker/index.ts"},"./auth-broker/*":{types:"./dist/types/auth-broker/*.d.ts",import:"./src/auth-broker/*.ts"},"./auth-gateway":{types:"./dist/types/auth-gateway/index.d.ts",import:"./src/auth-gateway/index.ts"},"./auth-gateway/*":{types:"./dist/types/auth-gateway/*.d.ts",import:"./src/auth-gateway/*.ts"},"./providers/*":{types:"./dist/types/providers/*.d.ts",import:"./src/providers/*.ts"},"./providers/openai-codex/*":{types:"./dist/types/providers/openai-codex/*.d.ts",import:"./src/providers/openai-codex/*.ts"},"./usage/*":{types:"./dist/types/usage/*.d.ts",import:"./src/usage/*.ts"},"./utils/harmony-leak":{types:"./dist/types/utils/harmony-leak.d.ts",import:"./src/utils/harmony-leak.ts"},"./dialect":{types:"./dist/types/dialect/index.d.ts",import:"./src/dialect/index.ts"},"./utils/*":{types:"./dist/types/utils/*.d.ts",import:"./src/utils/*.ts"},"./oauth":{types:"./dist/types/registry/oauth/index.d.ts",import:"./src/registry/oauth/index.ts"},"./oauth/*":{types:"./dist/types/registry/oauth/*.d.ts",import:"./src/registry/oauth/*.ts"},"./registry":{types:"./dist/types/registry/index.d.ts",import:"./src/registry/index.ts"},"./registry/oauth":{types:"./dist/types/registry/oauth/index.d.ts",import:"./src/registry/oauth/index.ts"},"./utils/schema":{types:"./dist/types/utils/schema/index.d.ts",import:"./src/utils/schema/index.ts"},"./utils/schema/*":{types:"./dist/types/utils/schema/*.d.ts",import:"./src/utils/schema/*.ts"},"./*.js":"./src/*.ts"}}});var Ret={};Ge(Ret,{getKimiCommonHeaders:()=>Ck,loginKimi:()=>bzo,refreshKimiToken:()=>kzo});import*as fos from"crypto";import*as Xz from"fs";import*as Ax from"os";import*as gSe from"path";import{scheduler as dos}from"timers/promises";function yet(){return ce.KIMI_CODE_OAUTH_HOST||ce.KIMI_OAUTH_HOST||fzo}function get(e,t,s){return[e,t,s].filter(Boolean).join(" ").trim()}function yzo(){let e=Ax.platform(),t=Ax.release(),s=Ax.arch();if(e==="darwin")return get("macOS",t,s);if(e==="win32")return get("Windows",t,s);return get(e==="linux"?"Linux":e,t,s)}function mSe(e,t=""){return e.replace(/[^\x20-\x7E]/g,"").trim()||t}async function Rzo(){let e=await fetch(`${yet()}/api/oauth/device_authorization`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({client_id:Tet})});if(!e.ok){let l=await e.text();throw new qe(`Kimi device authorization failed: ${e.status} ${l}`,{kind:"device-auth",provider:"kimi",status:e.status})}let t=await e.json(),s=t.user_code,n=t.device_code,o=t.verification_uri,r=t.verification_uri_complete;if(!s||!n||!o)throw new qe("Kimi device authorization response missing required fields",{kind:"validation",provider:"kimi"});let i=typeof t.expires_in==="number"?t.expires_in*1000:hzo,a=typeof t.interval==="number"&&t.interval>0?t.interval*1000:gzo;return{userCode:s,deviceCode:n,verificationUri:o,verificationUriComplete:r||o,expiresInMs:i,intervalMs:a}}function mos(e,t){if(!e.access_token||typeof e.expires_in!=="number")throw new qe("Kimi token response missing required fields",{kind:"validation",provider:"kimi"});let s=e.refresh_token??t;if(!s)throw new qe("Kimi token response missing refresh token",{kind:"validation",provider:"kimi"});let n,o=e.access_token.split("."),r=o.length===3?o[1]:void 0;if(r)try{let i=JSON.parse(new TextDecoder("utf-8").decode(Uint8Array.fromBase64(r,{alphabet:"base64url"})));if(Z(i)){let a=typeof i.user_id==="string"?i.user_id.trim():"",l=typeof i.sub==="string"?i.sub.trim():"";n=a||l||void 0}}catch{}return{access:e.access_token,refresh:s,expires:Date.now()+e.expires_in*1000-Tzo,accountId:n}}async function Czo(e,t,s,n){let o=Date.now()+s,r=Math.max(1000,t);while(Date.now()<o){if(n?.aborted)throw new qs;let i=await fetch(`${yet()}/api/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({client_id:Tet,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})}),a=await i.json();if(i.ok&&a.access_token)return mos(a);let l=a.error;if(l==="authorization_pending"){await dos.wait(r,{signal:n});continue}if(l==="slow_down"){r+=5000;let p=typeof a.interval==="number"?a.interval*1000:void 0;if(p&&p>r)r=p;await dos.wait(r,{signal:n});continue}if(l==="expired_token")throw new qe("Kimi device authorization expired",{kind:"validation",provider:"kimi"});if(l==="access_denied")throw new qe("Kimi device authorization denied",{kind:"validation",provider:"kimi"});let u=a.error_description?`: ${a.error_description}`:"";throw new qe(`Kimi device flow failed: ${l??i.status}${u}`,{kind:"polling",provider:"kimi"})}throw new qe("Kimi device flow timed out",{kind:"timeout",provider:"kimi"})}async function bzo(e){let t=await Rzo();return e.onAuth?.({url:t.verificationUriComplete,instructions:`Enter code: ${t.userCode}`}),Czo(t.deviceCode,t.intervalMs,t.expiresInMs,e.signal)}async function kzo(e){let t=await fetch(`${yet()}/api/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:Tet})});if(!t.ok){let n=await t.json().catch(()=>{return}),o=n?.error_description?`: ${n.error_description}`:"";throw new qe(`Kimi token refresh failed: ${t.status}${o}`,{kind:"token-refresh",provider:"kimi",status:t.status})}let s=await t.json();return mos(s,e)}var Tet="17e5f671-d194-4dfb-9706-5516cb48c098",fzo="https://auth.kimi.com",mzo="kimi-device-id",gzo=5000,hzo=900000,Tzo=300000,het=()=>{let e=gSe.join(os(),mzo);try{let s=Xz.readFileSync(e,"utf-8").trim();if(s)return het=()=>s,s}catch{}let t=fos.randomUUID().replace(/-/g,"");try{Xz.mkdirSync(gSe.dirname(e),{recursive:!0}),Xz.writeFileSync(e,`${t}
|
|
1071
|
+
}`,bjo,ZZe="omp_agent",eet="omp_inline_prompt",kjo,Sjo,ret=(e,t,s)=>{let n=new ln,o=C$o(e);n.push({type:"start",partial:o});let r={stream:n,output:o,started:!0};return t$o(e,t,s,r).catch((i)=>{let a=HF(i);if(!n.done)o.stopReason="error",o.errorMessage=r.goalOverflowMessage??a,n.push({type:"error",reason:"error",error:o})}),n},Nns,Wns,P$o="<|im_start|>",F$o="<|im_end|>",X$o;var aet=S(()=>{kke();ut();_r();na();VU();Fns();$g();fjo=dSe.resolve(import.meta.dir,"../../../../.tmp/gitlab-duo-workflow-trace.log");bjo=["incremental_streaming","read_file_chunked","shell_command","command_timeout","tool_call_approval"],kjo=["on_agent_reasoning","on_agent_final_answer","on_tool_execution_success","on_tool_execution_failed"],Sjo=["runMCPTool","run_mcp_tool"];Nns=new Map;Wns=_ns.trim();X$o=["Chat Agent","context_builder"]});import{Buffer as nos}from"buffer";import*as aos from"os";import*as los from"path";function ozo(){return nye("GOOGLE_VERTEX_REFRESH_SKEW_MS",60000)}function rzo(){return los.join(aos.homedir(),".config","gcloud","application_default_credentials.json")}async function oos(e){try{return await Bun.file(e).json()}catch(t){if(pe(t))return;throw t}}async function izo(){let e=Bun.env.GOOGLE_APPLICATION_CREDENTIALS;if(e){let n=await oos(e);if(!n)throw new Vt(`GOOGLE_APPLICATION_CREDENTIALS points to a missing file: ${e}`);return{source:`gac:${e}`,creds:n}}let t=rzo(),s=await oos(t);if(s)return{source:`user:${t}`,creds:s};return}function cet(e){let t=typeof e==="string"?nos.from(e,"utf8"):e;return nos.from(t.buffer,t.byteOffset,t.byteLength).toString("base64url")}function azo(e){let t=e.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,"");if(!t)throw new Vt("Invalid PEM: empty body");return Uint8Array.fromBase64(t)}async function lzo(e,t,s){let n={alg:"RS256",typ:"JWT"};if(s)n.kid=s;let o=`${cet(JSON.stringify(n))}.${cet(JSON.stringify(e))}`,r=await globalThis.crypto.subtle.importKey("pkcs8",azo(t),{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["sign"]),i=new Uint8Array(await globalThis.crypto.subtle.sign("RSASSA-PKCS1-v1_5",r,new TextEncoder().encode(o)));return`${o}.${cet(i)}`}async function ros(e,t,s){let n=Math.floor(Date.now()/1000),o=await lzo({iss:e.client_email,scope:uos,aud:det,exp:n+3600,iat:n},e.private_key,e.private_key_id),r=new URLSearchParams({grant_type:nzo,assertion:o});return pos(det,r,t,s)}async function ios(e,t,s){let n=new URLSearchParams({client_id:e.client_id,client_secret:e.client_secret,refresh_token:e.refresh_token,grant_type:"refresh_token"});return pos(det,n,t,s)}async function uzo(e,t){let s=AbortSignal.timeout(2000),n=e?AbortSignal.any([e,s]):s;try{let o=await t(szo,{method:"GET",headers:{"Metadata-Flavor":"Google"},signal:n});if(!o.ok)return;return await o.json()}catch{return}}async function pos(e,t,s,n){let o=await n(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t.toString(),signal:s});if(!o.ok){let r=await o.text().catch(()=>"");throw new qe(`Google OAuth token exchange failed (${o.status}): ${r}`,{kind:"token-exchange",provider:"google-vertex",status:o.status})}return await o.json()}async function pzo(e,t){let s=await izo();if(s){let o=s.creds,r;if(o.type==="impersonated_service_account"){let a=/(?<target>[^/]+):(generateAccessToken|generateIdToken)$/.exec(o.service_account_impersonation_url)?.groups?.target;if(!a)throw RangeError(`Cannot extract target principal from ${o.service_account_impersonation_url}`);let l=o.source_credentials.type==="service_account"?await ros(o.source_credentials,e,t):await ios(o.source_credentials,e,t),u=await t(`https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${a}:generateAccessToken`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l.access_token}`},body:JSON.stringify({delegates:o.delegates??[],scope:[uos],lifetime:"3600s"}),signal:e});if(!u.ok){let d=await u.text().catch(()=>"");throw new qe(`Google Impersonation token exchange failed (${u.status}): ${d}`,{kind:"token-exchange",provider:"google-vertex",status:u.status})}let p=await u.json(),c=Math.max(0,Math.floor((new Date(p.expireTime).getTime()-Date.now())/1000));r={access_token:p.accessToken,expires_in:c,token_type:"Bearer"}}else r=o.type==="service_account"?await ros(o,e,t):await ios(o,e,t);return{source:s.source,token:r}}let n=await uzo(e,t);if(n)return{source:"metadata",token:n};throw new br(void 0,"Vertex AI requires Application Default Credentials. Set GOOGLE_APPLICATION_CREDENTIALS, run `gcloud auth application-default login`, or run on a GCE/Cloud Run instance with a service account.")}async function fSe(e){let t=Bun.env.GOOGLE_CLOUD_ACCESS_TOKEN||Bun.env.CLOUDSDK_AUTH_ACCESS_TOKEN;if(t)return t;let s=e?.fetch??globalThis.fetch.bind(globalThis),n=ozo(),o=Date.now();for(let[l,u]of uet){if(u.expiresAtMs-n>o)return u.token;uet.delete(l)}let r="vertex-adc",i=pet.get(r);if(i)return fT(i,e?.signal);let a=(async()=>{try{let{source:l,token:u}=await pzo(AbortSignal.timeout(czo),s),p=Date.now()+Math.max(0,u.expires_in*1000);return uet.set(l,{token:u.access_token,expiresAtMs:p}),v.debug("vertex.adc acquired access token",{source:l,expiresInSec:u.expires_in}),u.access_token}finally{pet.delete(r)}})();return pet.set(r,a),fT(a,e?.signal)}var det="https://oauth2.googleapis.com/token",szo="http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token",uos="https://www.googleapis.com/auth/cloud-platform",nzo="urn:ietf:params:oauth:grant-type:jwt-bearer",uet,pet,czo=30000;var fet=S(()=>{B();ut();ok();uet=new Map,pet=new Map});var met;var cos=S(()=>{met={type:"module",name:"@oh-my-pi/pi-ai",version:"18.1.1",description:"Unified LLM API with automatic model discovery and provider configuration",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Mario Zechner"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/ai"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["ai","llm","openai","anthropic","gemini","unified","api"],main:"./src/index.ts",types:"./dist/types/index.d.ts",scripts:{check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun test --parallel",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"},dependencies:{"@oh-my-pi/omptype":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-utils":"catalog:","@oh-my-pi/pi-wire":"catalog:"},devDependencies:{"@types/bun":"catalog:"},engines:{bun:">=1.3.14"},files:["src","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./error":{types:"./dist/types/error/index.d.ts",import:"./src/error/index.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./auth-broker":{types:"./dist/types/auth-broker/index.d.ts",import:"./src/auth-broker/index.ts"},"./auth-broker/*":{types:"./dist/types/auth-broker/*.d.ts",import:"./src/auth-broker/*.ts"},"./auth-gateway":{types:"./dist/types/auth-gateway/index.d.ts",import:"./src/auth-gateway/index.ts"},"./auth-gateway/*":{types:"./dist/types/auth-gateway/*.d.ts",import:"./src/auth-gateway/*.ts"},"./providers/*":{types:"./dist/types/providers/*.d.ts",import:"./src/providers/*.ts"},"./providers/openai-codex/*":{types:"./dist/types/providers/openai-codex/*.d.ts",import:"./src/providers/openai-codex/*.ts"},"./usage/*":{types:"./dist/types/usage/*.d.ts",import:"./src/usage/*.ts"},"./utils/harmony-leak":{types:"./dist/types/utils/harmony-leak.d.ts",import:"./src/utils/harmony-leak.ts"},"./dialect":{types:"./dist/types/dialect/index.d.ts",import:"./src/dialect/index.ts"},"./utils/*":{types:"./dist/types/utils/*.d.ts",import:"./src/utils/*.ts"},"./oauth":{types:"./dist/types/registry/oauth/index.d.ts",import:"./src/registry/oauth/index.ts"},"./oauth/*":{types:"./dist/types/registry/oauth/*.d.ts",import:"./src/registry/oauth/*.ts"},"./registry":{types:"./dist/types/registry/index.d.ts",import:"./src/registry/index.ts"},"./registry/oauth":{types:"./dist/types/registry/oauth/index.d.ts",import:"./src/registry/oauth/index.ts"},"./utils/schema":{types:"./dist/types/utils/schema/index.d.ts",import:"./src/utils/schema/index.ts"},"./utils/schema/*":{types:"./dist/types/utils/schema/*.d.ts",import:"./src/utils/schema/*.ts"},"./*.js":"./src/*.ts"}}});var Ret={};Ge(Ret,{getKimiCommonHeaders:()=>Ck,loginKimi:()=>bzo,refreshKimiToken:()=>kzo});import*as fos from"crypto";import*as Xz from"fs";import*as Ax from"os";import*as gSe from"path";import{scheduler as dos}from"timers/promises";function yet(){return ce.KIMI_CODE_OAUTH_HOST||ce.KIMI_OAUTH_HOST||fzo}function get(e,t,s){return[e,t,s].filter(Boolean).join(" ").trim()}function yzo(){let e=Ax.platform(),t=Ax.release(),s=Ax.arch();if(e==="darwin")return get("macOS",t,s);if(e==="win32")return get("Windows",t,s);return get(e==="linux"?"Linux":e,t,s)}function mSe(e,t=""){return e.replace(/[^\x20-\x7E]/g,"").trim()||t}async function Rzo(){let e=await fetch(`${yet()}/api/oauth/device_authorization`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({client_id:Tet})});if(!e.ok){let l=await e.text();throw new qe(`Kimi device authorization failed: ${e.status} ${l}`,{kind:"device-auth",provider:"kimi",status:e.status})}let t=await e.json(),s=t.user_code,n=t.device_code,o=t.verification_uri,r=t.verification_uri_complete;if(!s||!n||!o)throw new qe("Kimi device authorization response missing required fields",{kind:"validation",provider:"kimi"});let i=typeof t.expires_in==="number"?t.expires_in*1000:hzo,a=typeof t.interval==="number"&&t.interval>0?t.interval*1000:gzo;return{userCode:s,deviceCode:n,verificationUri:o,verificationUriComplete:r||o,expiresInMs:i,intervalMs:a}}function mos(e,t){if(!e.access_token||typeof e.expires_in!=="number")throw new qe("Kimi token response missing required fields",{kind:"validation",provider:"kimi"});let s=e.refresh_token??t;if(!s)throw new qe("Kimi token response missing refresh token",{kind:"validation",provider:"kimi"});let n,o=e.access_token.split("."),r=o.length===3?o[1]:void 0;if(r)try{let i=JSON.parse(new TextDecoder("utf-8").decode(Uint8Array.fromBase64(r,{alphabet:"base64url"})));if(Z(i)){let a=typeof i.user_id==="string"?i.user_id.trim():"",l=typeof i.sub==="string"?i.sub.trim():"";n=a||l||void 0}}catch{}return{access:e.access_token,refresh:s,expires:Date.now()+e.expires_in*1000-Tzo,accountId:n}}async function Czo(e,t,s,n){let o=Date.now()+s,r=Math.max(1000,t);while(Date.now()<o){if(n?.aborted)throw new qs;let i=await fetch(`${yet()}/api/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({client_id:Tet,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})}),a=await i.json();if(i.ok&&a.access_token)return mos(a);let l=a.error;if(l==="authorization_pending"){await dos.wait(r,{signal:n});continue}if(l==="slow_down"){r+=5000;let p=typeof a.interval==="number"?a.interval*1000:void 0;if(p&&p>r)r=p;await dos.wait(r,{signal:n});continue}if(l==="expired_token")throw new qe("Kimi device authorization expired",{kind:"validation",provider:"kimi"});if(l==="access_denied")throw new qe("Kimi device authorization denied",{kind:"validation",provider:"kimi"});let u=a.error_description?`: ${a.error_description}`:"";throw new qe(`Kimi device flow failed: ${l??i.status}${u}`,{kind:"polling",provider:"kimi"})}throw new qe("Kimi device flow timed out",{kind:"timeout",provider:"kimi"})}async function bzo(e){let t=await Rzo();return e.onAuth?.({url:t.verificationUriComplete,instructions:`Enter code: ${t.userCode}`}),Czo(t.deviceCode,t.intervalMs,t.expiresInMs,e.signal)}async function kzo(e){let t=await fetch(`${yet()}/api/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...Ck()},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:Tet})});if(!t.ok){let n=await t.json().catch(()=>{return}),o=n?.error_description?`: ${n.error_description}`:"";throw new qe(`Kimi token refresh failed: ${t.status}${o}`,{kind:"token-refresh",provider:"kimi",status:t.status})}let s=await t.json();return mos(s,e)}var Tet="17e5f671-d194-4dfb-9706-5516cb48c098",fzo="https://auth.kimi.com",mzo="kimi-device-id",gzo=5000,hzo=900000,Tzo=300000,het=()=>{let e=gSe.join(os(),mzo);try{let s=Xz.readFileSync(e,"utf-8").trim();if(s)return het=()=>s,s}catch{}let t=fos.randomUUID().replace(/-/g,"");try{Xz.mkdirSync(gSe.dirname(e),{recursive:!0}),Xz.writeFileSync(e,`${t}
|
|
1072
1072
|
`,{mode:384})}catch{}return het=()=>t,t},Ck=()=>{let e=Object.freeze({"User-Agent":`KimiCLI/${met.version}`,"X-Msh-Platform":"kimi_cli","X-Msh-Version":met.version,"X-Msh-Device-Name":mSe(Ax.hostname(),"unknown"),"X-Msh-Device-Model":mSe(yzo(),"unknown"),"X-Msh-Os-Version":mSe(Ax.version(),"unknown"),"X-Msh-Device-Id":mSe(het(),"unknown")});return Ck=()=>e,e};var Qz=S(()=>{B();cos();ut();_r()});function hSe(e,t){let s=t instanceof Error?t.message:String(t);return{role:"assistant",content:[],errorMessage:s,api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"error",timestamp:Date.now()}}function tte(e,t){if(e===void 0)return t;let s=Number(e);if(!Number.isFinite(s))return t;if(s<=0)return;return Math.trunc(s)}function Zz(e=hos){return tte(ce.PI_STREAM_IDLE_TIMEOUT_MS??ce.PI_OPENAI_STREAM_IDLE_TIMEOUT_MS,e)}function DR(e=hos){return tte(ce.PI_OPENAI_STREAM_IDLE_TIMEOUT_MS??ce.PI_STREAM_IDLE_TIMEOUT_MS,e)}function vx(e,t=Tos){let s=e===void 0?t:Math.max(t,e);return tte(ce.PI_STREAM_FIRST_EVENT_TIMEOUT_MS,s)}function NR(e,t=Tos){let s=ce.PI_OPENAI_STREAM_FIRST_EVENT_TIMEOUT_MS;if(s!==void 0)return tte(s,t)??0;let n=tte(ce.PI_STREAM_FIRST_EVENT_TIMEOUT_MS,t);if(n===void 0||n<=0)return 0;if(e===void 0||e<=0)return n;return Math.max(n,e)}function WF(e,t){if(t===void 0||t<=0)return{signal:e,clear:()=>{}};let s=new AbortController,n=setTimeout(()=>{s.abort(new DOMException("The operation timed out.","TimeoutError"))},t);return n.unref?.(),{signal:e?AbortSignal.any([e,s.signal]):s.signal,clear:()=>clearTimeout(n)}}async function*Af(e,t){let s=t.firstItemTimeoutMs??t.idleTimeoutMs,n=s!==void 0&&s>0?Date.now()+s:void 0,o=t.abortSignal,r=e[Symbol.asyncIterator](),i=!1,a=()=>{if(i)return;i=!0;let O=r.return?.();if(O)O.catch(()=>{})};if(o?.aborted)throw a(),gos(o);let l=(O)=>O.then((P)=>({kind:"next",result:P}),(P)=>({kind:"error",error:P})),u=!0,p=()=>{u=!1},c=(O)=>{if(!t.isProgressItem)return!0;try{return t.isProgressItem(O)}catch{return!0}},d=Date.now(),f=()=>{if(!t.hasPendingLocalWork)return!1;try{return t.hasPendingLocalWork()}catch{return!1}},m=()=>{if(u){if(n!==void 0&&s!==void 0)n=Date.now()+s}else d=Date.now()},g=(s===void 0||s<=0)&&(t.idleTimeoutMs===void 0||t.idleTimeoutMs<=0),h,T,y;if(o){let{promise:O,resolve:P}=Promise.withResolvers();y=P,T=()=>y?.({kind:"abort"}),o.addEventListener("abort",T,{once:!0}),h=O}let R,C,b=!1,w,E=1/0,x=()=>{if(u)return n;if(t.idleTimeoutMs!==void 0&&t.idleTimeoutMs>0)return d+t.idleTimeoutMs;return},A=()=>{w=void 0,E=1/0;let O=x();if(O===void 0)return;let P=O-Date.now();if(P>0){E=O,w=setTimeout(A,P);return}b=!0,C?.({kind:"timeout"})},M=(O)=>{if(R===void 0||b){let{promise:P,resolve:F}=Promise.withResolvers();R=P,C=F,b=!1}if(w!==void 0){if(E<=O)return;clearTimeout(w)}E=O,w=setTimeout(A,Math.max(0,O-Date.now()))},I;try{let O=0;while(!0){if(++O%Szo===0){if(h!==void 0&&!o.aborted){let{promise:L,resolve:N}=Promise.withResolvers();y=N,h=L}if(R!==void 0&&!b){let{promise:L,resolve:N}=Promise.withResolvers();C=N,R=L}}let P;if(u){if(n!==void 0){if(P=n-Date.now(),P<=0){if(!f())throw t.onFirstItemTimeout?.(),a(),new Qa(t.firstItemErrorMessage??t.errorMessage);m(),P=n-Date.now()}}}else if(t.idleTimeoutMs!==void 0&&t.idleTimeoutMs>0){if(P=t.idleTimeoutMs-(Date.now()-d),P<=0){if(!f())throw t.onIdle?.(),a(),new Qa(t.errorMessage);m(),P=t.idleTimeoutMs}}I??=l(r.next());let F=[I];if(!g&&P!==void 0&&P>0)M(Date.now()+P),F.push(R);if(h)F.push(h);let D=!1;try{let L=await Promise.race(F);if(L.kind==="next"||L.kind==="error")I=void 0;if(L.kind==="abort")throw a(),gos(o);if(L.kind==="timeout"){if(f()){m(),D=!0;continue}if(!u)t.onIdle?.();else t.onFirstItemTimeout?.();throw a(),new Qa(!u?t.errorMessage:t.firstItemErrorMessage??t.errorMessage)}if(L.kind==="error")throw L.error;if(L.result.done){p();return}let N=L.result.value;if(c(N))p(),d=Date.now();yield N,D=!0}finally{if(!D)a()}}}finally{if(w!==void 0)clearTimeout(w);if(C?.({kind:"timeout"}),T&&o)o.removeEventListener("abort",T);y?.({kind:"abort"})}}async function*yos(e,t){let s=e[Symbol.asyncIterator]();try{while(!0){let n=t.finishedAtMs();if(n===void 0){let l=await s.next();if(l.done)return;yield l.value;continue}let o=n+t.graceMs-Date.now();if(o<=0){t.onGraceEnd?.();return}let r=s.next(),i,a=new Promise((l)=>{i=setTimeout(()=>l("timeout"),o)});try{let l=await Promise.race([r,a]);if(l==="timeout"){r.catch(()=>{}),t.onGraceEnd?.();return}if(l.done)return;yield l.value}finally{if(i!==void 0)clearTimeout(i)}}}finally{let n=s.return?.();if(n)Promise.resolve(n).catch(()=>{})}}function gos(e){let t=e.reason;if(t instanceof Error)return t;if(typeof t==="string")return new Is(t);return new Is}var hos=300000,Tos=300000,Szo=1024;var bk=S(()=>{B();ut()});function wzo(e,t,s){let n={};e.headers.forEach((r,i)=>{n[i.toLowerCase()]=r});let o={status:e.status,headers:n};if(t!==void 0)o.requestId=t;if(s!==void 0)o.metadata=s;return o}async function Hv(e,t,s,n,o){if(!e?.onResponse)return;await e.onResponse(wzo(t,n,o),s)}function xzo(e){if(e===void 0)return;if(!Number.isFinite(e))return;if(e<=0)return;return Math.trunc(e)}function Cet(e,t){let s=xzo(t);if(s===void 0)return{signal:e};return{signal:e,timeout:s,maxRetries:0}}function k1(e,t){if(!e)return;try{e(t)}catch{}}import{scheduler as Ezo}from"timers/promises";function bet(){return new Is("Request was aborted.")}function Ozo(e){let t=e.headers.get("x-should-retry");if(t==="true")return!0;if(t==="false")return!1;let s=e.status;return cT(s)||s===409}function Ros(e){if(!e)return;let t=e.get("retry-after-ms");if(t){let n=Number.parseFloat(t);if(Number.isFinite(n)&&n>=0)return n}let s=e.get("retry-after");if(s){let n=Number.parseFloat(s);if(Number.isFinite(n)&&n>=0)return n*1000;let o=Date.parse(s)-Date.now();if(Number.isFinite(o)&&o>=0)return o}return}function wet(e){let t=Math.min(vzo*2**e,Izo),s=1-Math.random()*0.25;return t*s*1000}function Cos(e,t){for(let s in e)if(s.toLowerCase()===t)return!0;return!1}class bos{#e;#t;constructor(e){this.#e=e}asResponse(){return this.#t??=this.#e(),this.#t}}class ket{#e;#t;constructor(e,t){this.#e=e,this.#t=t}create(e,t){return this.#e.request(this.#t,e,t)}}class xet{messages;beta;#e;constructor(e){this.#e=e,this.messages=new ket(this,"/v1/messages"),this.beta={messages:new ket(this,"/v1/messages?beta=true")}}request(e,t,s){return new bos(()=>this.#s(e,t,s))}#t(e){let t=this.#e,s=t.defaultHeaders??{},n={};if(t.apiKey!=null&&!Cos(s,"x-api-key"))n["X-Api-Key"]=t.apiKey;if(t.authToken!=null&&!Cos(s,"authorization"))n.Authorization=`Bearer ${t.authToken}`;return Object.assign(n,s),Object.assign(n,e),n}async#s(e,t,s){let n=this.#e,o=n.fetch??fetch,r=s?.signal,i=s?.timeout??n.timeout??Mzo,a=Math.max(0,s?.maxRetries??n.maxRetries??Azo),l=s?.maxRetryDelayMs??n.maxRetryDelayMs??60000,u=`${n.baseURL??"https://api.anthropic.com"}${e}`,p=this.#t(s?.headers),c=JSON.stringify(t);for(let d=0;;d++){if(r?.aborted)throw bet();let f;try{f=await this.#n(o,u,p,c,i,r)}catch(m){if(r?.aborted)throw bet();if(d<a){await this.#o(d,void 0,r);continue}if(m instanceof av)throw m;throw new M$(m)}if(f.ok)return f;if(d<a&&Ozo(f)){let m=Ros(f.headers);if(m!==void 0&&l>0&&m>l)throw await AU.fromResponse(f,r);await f.body?.cancel().catch(()=>{}),await this.#o(d,f.headers,r);continue}throw await AU.fromResponse(f,r)}}async#n(e,t,s,n,o,r){let i=new AbortController,a=!1,l=setTimeout(()=>{a=!0,i.abort()},o),u=()=>i.abort();r?.addEventListener("abort",u,{once:!0});try{return await e(t,{...this.#e.fetchOptions,method:"POST",headers:s,body:n,signal:i.signal})}catch(p){if(a&&!r?.aborted)throw new av;throw p}finally{clearTimeout(l),r?.removeEventListener("abort",u)}}async#o(e,t,s){let n=Ros(t)??wet(e);try{await Ezo.wait(n,{signal:s})}catch{throw bet()}}}var Mzo=600000,Azo=2,vzo=0.5,Izo=8;var Eet=S(()=>{ut();ut()});function GF(e){if(e.type==="server_tool_use")return(e.name==="web_search"||e.name==="tool_search_tool_regex"||e.name==="tool_search_tool_bm25")&&typeof e.id==="string"&&e.id.length>0;if(e.type==="web_search_tool_result"||e.type==="tool_search_tool_result")return typeof e.tool_use_id==="string"&&e.tool_use_id.length>0&&Object.hasOwn(e,"content");return!1}var rrs={};Ge(rrs,{CLAUDE_CODE_MAX_OUTPUT_TOKENS:()=>$Re,applyAnthropicUsageExtras:()=>bSe,applyClaudeToolPrefix:()=>zos,buildAnthropicClientOptions:()=>trs,buildAnthropicHeaders:()=>ESe,buildAnthropicSystemBlocks:()=>_Se,buildBetaHeader:()=>xSe,claudeCodeSdkVersion:()=>_Z,claudeCodeSystemInstruction:()=>B9e,claudeCodeVersion:()=>uF,claudeToolPrefix:()=>pF,clearAnthropicFastModeFallback:()=>MSe,convertAnthropicMessages:()=>nrs,coworkHeaders:()=>ASe,coworkUserAgent:()=>H9e,deriveClaudeDeviceId:()=>ISe,generateClaudeCloakingUserId:()=>t5o,isAnthropicFastModeFallbackDisabled:()=>_et,isClaudeCloakingUserId:()=>qet,isInvalidThinkingSignatureError:()=>Bet,isProviderRetryableError:()=>Zos,mapStainlessArch:()=>jos,maybeAddReplayUnsignedThinkingHint:()=>ers,normalizeAnthropicBaseUrl:()=>$F,normalizeAnthropicToolSchema:()=>ors,normalizeExtraBetas:()=>Wet,resolveAnthropicCustomHeadersForBaseUrl:()=>FSe,resolveAnthropicMetadataUserId:()=>OSe,streamAnthropic:()=>B5o,stripClaudeToolPrefix:()=>PSe,wrapFetchForCch:()=>vSe});import*as Ix from"crypto";import*as SSe from"fs";import{scheduler as Pzo}from"timers/promises";import*as wSe from"tls";function $F(e){let t=e?.trim();if(!t)return;let s=t.replace(/\/+$/,"");return s.endsWith("/v1")?s.slice(0,-3):s}function xSe(e,t){let s=new Set,n=[];for(let o of[...e,...t]){let r=o.trim();if(r&&!s.has(r))s.add(r),n.push(r)}return n.join(",")}function Fzo(e,t){for(let s in e)if(s.toLowerCase()==="anthropic-beta")return{[s]:xSe(Wet(e[s]),[t])};return{"anthropic-beta":t}}function Hos({agentRequest:e,thinkingRequest:t,disableStrictTools:s=!1,supportsContextManagement:n=!0}){if(!e&&!s&&n)return kos;let o=[];for(let r of e?Lzo:kos){if(s&&r===qos)continue;if(!n&&r===rte)continue;o.push(r)}if(!e)return o;if(t)o.push(e5);return o.push(_zo),o}function nte(e,t){if(!e)return;let s=t.toLowerCase();for(let[n,o]of Object.entries(e))if(n.toLowerCase()===s)return o;return}function qzo(e){if(!e)return!1;return e.toLowerCase().startsWith("claude-cli")}function ESe(e){let t=e.isOAuth??sF(e.apiKey),s=e.extraBetas??[],n=e.stream??!1,o=nte(e.modelHeaders,"User-Agent"),r=nte(e.modelHeaders,"Authorization"),i=nte(e.modelHeaders,"X-Api-Key"),a=xSe(e.coworkBetas??(t?Hos({agentRequest:!0,thinkingRequest:!0}):[]),s),l=t?"application/json":n?"text/event-stream":"application/json",u=e.isCloudflareAiGateway??!1,p=!t&&!u,c=t&&e.allowAnthropicHeaderOverrides===!0&&!u&&!zg(e.baseUrl),d=!u,f={},m={},g=[],h=e.modelHeaders;if(h)for(let T in h){let y=h[T],R=T.toLowerCase();if($zo.has(R)){if(c&&zzo.has(R)){m[T]=y;continue}if(R==="user-agent")continue;if(R==="authorization"&&p)continue;if(R==="x-api-key"&&d)continue;g.push(T);continue}f[T]=y}if(g.length>0)v.debug("anthropic: ignoring caller-supplied enforced headers",{headers:g});if(u)return{...f,Accept:l,...Met,...o?{"User-Agent":o}:{},...a?{"anthropic-beta":a}:{},"cf-aig-authorization":`Bearer ${e.apiKey}`};if(t){let T=qzo(o)?o:H9e,y={...f,Accept:l,"Content-Type":"application/json","User-Agent":T,...e.claudeCodeSessionId?{"X-Claude-Code-Session-Id":e.claudeCodeSessionId}:{},...ASe,...a?{"anthropic-beta":a}:{},"anthropic-dangerous-direct-browser-access":"true","anthropic-version":"2023-06-01",Authorization:`Bearer ${e.apiKey}`,"x-app":"cli","x-client-request-id":Ix.randomUUID(),Connection:"keep-alive","Accept-Encoding":"gzip, deflate, br, zstd",...i?{"X-Api-Key":i}:{}};return c?ote(y,m):y}else if(!zg(e.baseUrl))return{...f,Accept:l,Authorization:r??`Bearer ${e.apiKey}`,...Met,...o?{"User-Agent":o}:{},...a?{"anthropic-beta":a}:{},...i?{"X-Api-Key":i}:{}};else return{...f,Accept:l,...Met,...o?{"User-Agent":o}:{},...a?{"anthropic-beta":a}:{},...r?{Authorization:r}:{},"X-Api-Key":i??e.apiKey}}function Uzo(e){let t=e.trim().toLowerCase();if(t==="image/jpg")return"image/jpeg";if(t==="image/jpeg"||t==="image/png"||t==="image/gif"||t==="image/webp")return t;return}function Bos(e){return{...e}}function Hzo(){let e={strictToolsDisabled:!1,fastModeDisabled:!1,replayUnsignedThinkingDisabled:!1,close:()=>{e.strictToolsDisabled=!1,e.fastModeDisabled=!1,e.replayUnsignedThinkingDisabled=!1}};return e}function Wos(e,t){return`${Pet}:${e}\x00${t}`}function Bzo(e,t,s){if(!e)return;let n=Wos(t,s),o=e.get(n);if(o)return o;let r=Hzo();return e.set(n,r),r}function MSe(e){if(!e)return;let t=`${Pet}:`;for(let[s,n]of e){if(s!==Pet&&!s.startsWith(t))continue;n.fastModeDisabled=!1}}function _et(e,t){if(!e||t.provider!=="anthropic"||t.api!=="anthropic-messages")return!1;let s=Het(t)??"https://api.anthropic.com",n=Wos(s,t.id);return e.get(n)?.fastModeDisabled??!1}function Wzo(e){return e.tools?.some((t)=>t.strict===!0)??!1}function Gzo(e){delete e.speed}function jzo(e){if(!e.tools)return;for(let t of e.tools)delete t.strict}function Gos(e,t){let s=pp(t,"short");if(s==="none")return{retention:s};let n=s==="long"&&e.compat.supportsLongCacheRetention?"1h":void 0;return{retention:s,cacheControl:{type:"ephemeral",...n&&{ttl:n}}}}function jos(e){switch(e.toLowerCase()){case"amd64":case"x64":return"x64";case"arm64":case"aarch64":return"arm64";case"386":case"x86":case"ia32":return"x86";default:return`other::${e.toLowerCase()}`}}function Kzo(e){let t=[4,7,20].map((n)=>e[n]??"0").join(""),s=Ix.createHash("sha256").update(`59cf53e54c78${t}${uF}`).digest("hex").slice(0,3);return`${Let} cc_version=${uF}.${s}; cc_entrypoint=claude-desktop; ${Det};`}function Xzo(e){let t=Buffer.from(e.buffer,e.byteOffset,e.byteLength),s=t.indexOf(Eos);if(s===-1)return"no-billing-header";let n=s+Eos.length,o=t.indexOf(Yzo,n);if(o===-1||o-n>Jzo)return"unanchored";let i=(Bun.hash.xxHash64(e,Vzo)&0xfffffn).toString(16).padStart(5,"0");for(let a=0;a<5;a++)e[o+4+a]=i.charCodeAt(a);return"patched"}function vSe(e){return(t,s)=>{if(s?.body&&typeof s.body==="string"&&s.body.includes(Det)){let n=Net.encode(s.body);if(Xzo(n)==="unanchored")v.warn("anthropic: cch billing placeholder present but not patched; sending unattested request");return e(t,{...s,body:n})}return e(t,s)}}function qet(e){return Qzo.test(e)}function Zzo(e){if(e.length===0||e[0]!=="{")return!1;let t;try{t=JSON.parse(e)}catch{return!1}if(!t||typeof t!=="object"||Array.isArray(t))return!1;let s=t;return typeof s.session_id==="string"&&s.session_id.length>0}function e5o(e){if(typeof e!=="string")return;if(qet(e))return e.slice(e.lastIndexOf("_session_")+9);if(e.length===0||e[0]!=="{")return;let t;try{t=JSON.parse(e)}catch{return}if(!t||typeof t!=="object"||Array.isArray(t))return;let s=t.session_id;return typeof s==="string"&&s.length>0?s:void 0}function t5o(){let e=Ix.randomBytes(32).toString("hex"),t=Ix.randomUUID().toLowerCase(),s=Ix.randomUUID().toLowerCase();return`user_${e}_account_${t}_session_${s}`}function ISe(e,t){let s=Ix.createHash("sha256");if(t&&t.length>0)return s.update(n5o).update("\x00").update(e).update("\x00").update(t).digest("hex");return s.update(s5o).update(e).digest("hex")}function CSe(e,t){let s=e?.[t];return typeof s==="string"&&s.length>0?s:void 0}function o5o(e){return CSe(e,"account_uuid")??CSe(e,"accountId")??CSe(e,"account_id")}function r5o(e){return ISe(Eg(),e)}function i5o(e,t){let s={device_id:r5o(t),session_id:e??Ix.randomUUID().toLowerCase()};if(t&&t.length>0)s.account_uuid=t;return JSON.stringify(s)}function OSe(e,t,s,n){if(typeof e==="string"){if(!t||qet(e)||Zzo(e))return e}if(!t)return;return i5o(s,n)}function Mos(e){let t=e?.trim().toLowerCase();return t==="native"||t==="exa"?t:void 0}function u5o(e){let t=nte(e,$os);if(t!==void 0)return Mos(t);return Mos(ce.UMANS_WEBSEARCH_PROVIDER)}function p5o(e){return e.provider==="umans"||e.baseUrl.toLowerCase().includes("api.code.umans.ai")}function Kos(e,t){if(!p5o(e))return;let s=u5o(t);return s?{[$os]:s}:void 0}function c5o(e,t){return t&&e.toLowerCase()===l5o}function Uet(e,t,s,n=!1){if(c5o(e,n))return e;if(s)return`${pF}${e}`;return t?zos(e):e}function d5o(e,t,s){if(t||s)return PSe(e);return e}function m5o(e){let t=0;for(let s of e){if(s.role!=="user"&&s.role!=="developer"&&s.role!=="toolResult")continue;if(!Array.isArray(s.content))continue;for(let n of s.content)if(n.type==="image")t++}return t}function h5o(e){let t=0,s=[];return async(n)=>{if(t>=e){let{promise:o,resolve:r}=Promise.withResolvers();s.push(r),await o}else t++;try{return await n()}finally{let o=s.shift();if(o)o();else t--}}}async function T5o(e){try{let t=Buffer.from(e.data,"base64"),{width:s,height:n}=await new Bun.Image(t).metadata();if(!s||!n)return e;if(s<=S1&&n<=S1)return e;let o=Math.min(S1/s,S1/n),r=Math.max(1,Math.min(S1,Math.round(s*o))),i=Math.max(1,Math.min(S1,Math.round(n*o))),[a,l]=await Promise.all([new Bun.Image(t).resize(r,i).png().bytes(),new Bun.Image(t).resize(r,i).jpeg({quality:85}).bytes()]),u=a.length<=l.length?{buffer:a,mimeType:"image/png"}:{buffer:l,mimeType:"image/jpeg"};return{type:"image",data:Buffer.from(u.buffer).toString("base64"),mimeType:u.mimeType}}catch(t){return v.warn("anthropic: failed to resize oversized image for many-image request",{mimeType:e.mimeType,error:t instanceof Error?t.message:String(t)}),e}}async function vos(e,t,s){let n=!1,o=await Promise.all(e.map(async(r)=>{if(r.type!=="image"||r.url||r.providerFile?.provider==="anthropic"&&r.providerFile.id)return r;let i=Aos.get(r);if(i===void 0)i=await s(()=>T5o(r)),Aos.set(r,i);if(i!==r)n=!0,t.resized++;return i}));return n?o:e}async function y5o(e,t,s){if(e.role==="user"||e.role==="developer"){if(!Array.isArray(e.content))return e;let n=await vos(e.content,t,s);return n===e.content?e:{...e,content:n}}if(e.role==="toolResult"){let n=await vos(e.content,t,s);return n===e.content?e:{...e,content:n}}return e}async function R5o(e,t){if(!t)return e;let s=m5o(e.messages);if(s<=f5o)return e;let n=!1,o={resized:0},r=h5o(g5o),i=await Promise.all(e.messages.map(async(a)=>{let l=await y5o(a,o,r);if(l!==a)n=!0;return l}));if(!n)return e;return v.debug("anthropic: resized oversized images for many-image request",{imageCount:s,resized:o.resized,maxDimension:S1}),{...e,messages:i}}function Vos(e,t=!0){let s=[],n=!1,o=!1;for(let r of e){if(r.type==="text"){let a=r.text.toWellFormed();if(a.trim().length===0)continue;n=!0,s.push({type:"text",text:a});continue}if(!t){s.push({type:"text",text:Pv});continue}let i;if(r.providerFile?.provider==="anthropic"&&r.providerFile.id)i={type:"file",file_id:r.providerFile.id};else if(r.url)i={type:"url",url:r.url};else{let a=Uzo(r.mimeType);if(!a){s.push({type:"text",text:`[unsupported image: ${r.mimeType}]`});continue}i={type:"base64",media_type:a,data:r.data}}o=!0,s.push({type:"image",source:i})}if(!t)return s.filter((r)=>r.type==="text").map((r)=>r.text).join(`
|
|
1073
1073
|
`).toWellFormed();if(o&&!n)s.unshift({type:"text",text:"(see attached image)"});return s}function vet(e){if(!e)return null;let t=e.trim();if(t&&!t.includes("-----BEGIN")&&Jos(t))try{return`${t}@${SSe.statSync(t).mtimeMs}`}catch{return t}return e}function C5o(){return JSON.stringify([vet(ce.NODE_EXTRA_CA_CERTS),vet(ce.CLAUDE_CODE_CLIENT_CERT),vet(ce.CLAUDE_CODE_CLIENT_KEY)])}function Het(e,t){if(e.provider==="github-copilot")return $F(gbe(e.baseUrl,t)??e.baseUrl);if(e.provider==="anthropic"&&fx()){let s=$F(ce.FOUNDRY_BASE_URL);if(s)return s}if(e.provider==="anthropic"){let s=$F(e.baseUrl);if(s&&!zg(s))return s;return $F(ce.ANTHROPIC_BASE_URL)??s??"https://api.anthropic.com"}return $F(e.baseUrl)}function Yos(e,t){if(!e.compat.supportsEagerToolInputStreaming)return!1;if(zg(t))return!0;return!e.compat.officialEndpoint}function b5o(e){let t=e?.trim();if(!t)return;let s={};for(let n of t.split(/\r?\n|,/)){let o=n.trim();if(!o)continue;let r=o.indexOf(":");if(r<=0)continue;let i=o.slice(0,r).trim(),a=o.slice(r+1).trim();if(!i||!a)continue;s[i]=a}return Object.keys(s).length>0?s:void 0}function FSe(e){if(!fx()&&zg(e))return;return b5o(ce.ANTHROPIC_CUSTOM_HEADERS)}function k5o(e,t){if(e.provider!=="anthropic")return;return FSe(t)}function Jos(e){return e.includes("/")||e.includes("\\")||/\.(pem|crt|cer|key)$/i.test(e)}function Iet(e,t){let s=e?.trim();if(!s)return;let n=s.replace(/\\n/g,`
|
|
1074
1074
|
`);if(n.includes("-----BEGIN"))return n;if(Jos(s))try{return SSe.readFileSync(s,"utf8")}catch(o){if(pe(o))throw new rn(`${t} path does not exist: ${s}`);throw o}return n}function S5o(e){if(e.provider!=="anthropic")return;if(!fx())return;let t=C5o();if(Aet.has(t))return Aet.get(t);let s=Iet(ce.NODE_EXTRA_CA_CERTS,"NODE_EXTRA_CA_CERTS"),n=Iet(ce.CLAUDE_CODE_CLIENT_CERT,"CLAUDE_CODE_CLIENT_CERT"),o=Iet(ce.CLAUDE_CODE_CLIENT_KEY,"CLAUDE_CODE_CLIENT_KEY");if(n&&!o||!n&&o)throw new Vt("Both CLAUDE_CODE_CLIENT_CERT and CLAUDE_CODE_CLIENT_KEY must be set for mTLS.");let r={};if(s)r.ca=[...wSe.rootCertificates,s];if(n)r.cert=n;if(o)r.key=o;let i=Object.keys(r).length>0?r:void 0;return Aet.set(t,i),i}function w5o(e,t){if(e.provider!=="anthropic")return;if(!t)return;let s;try{s=new URL(t).hostname}catch{return}if(!s)return;let n=S5o(e);return{tls:{rejectUnauthorized:!0,serverName:s,...Ios?{ciphers:Ios}:{},...n}}}function ote(...e){let t={},s=new Map;for(let n of e){if(!n)continue;for(let[o,r]of Object.entries(n)){let i=o.toLowerCase(),a=s.get(i);if(a!==void 0&&a!==o)delete t[a];s.set(i,o),t[o]=r}}return t}function E5o(e){try{let t=JSON.parse(e),s=typeof t?.error?.type==="string"?t.error.type:void 0,n=typeof t?.error?.message==="string"?t.error.message:void 0;if(n)return new Rs(s?`Anthropic stream error (${s}): ${n}`:`Anthropic stream error: ${n}`,{provider:"anthropic",kind:"output"})}catch{}return new Rs(e,{provider:"anthropic",kind:"output"})}async function*M5o(e,t,s){if(!e.body)throw new px("Attempted to iterate over an Anthropic response with no body");let n=!1,o=!1;for await(let r of lx(e.body,t)){if(k1(s,r),r.event==="error")throw E5o(r.data);if(r.event==="ping"){yield x5o;continue}if(!Xos.has(r.event??""))continue;try{let i=JSON.parse(r.data);if(i.type!==r.event)Vi(`event type ${i.type} does not match SSE event ${r.event}`);if(i.type==="message_start")n=!0;else if(i.type==="message_stop")o=!0;yield i}catch(i){let a=i instanceof Error?i.message:String(i);Vi(`could not parse SSE event ${r.event}: ${a}; skipping frame; data=${r.data}`)}}if(n&&!o&&!t?.aborted)Vi("stream ended before message_stop")}function Qos(e){return Z(e)&&typeof e.asResponse==="function"}function A5o(e){return Z(e)&&typeof e.withResponse==="function"}async function v5o(e,t,s){if(Qos(e)){let n=await e.asResponse();return{events:M5o(n,t,s),response:n,requestId:n.headers.get("request-id"),recordsRawSseEvents:!0}}if(A5o(e)){let{data:n,response:o,request_id:r}=await e.withResponse();return{events:n,response:o,requestId:r,recordsRawSseEvents:!1}}throw new px("Anthropic SDK request did not expose a stream response")}async function*I5o(e,t){for await(let s of e){let n=JSON.stringify(s);k1(t,{event:s.type,data:n,raw:[`event: ${s.type}`,`data: ${n}`]}),yield s}}function Vi(e){v.warn(`anthropic: ignoring malformed stream envelope: ${e}`)}function _5o(e){if(typeof e!=="string")return!1;if(e==="ping")return!0;return!Xos.has(e)}function Zos(e,t){return eF(e,{provider:t,isProviderTransient:t==="github-copilot"?(s)=>OU(s):void 0})}function L5o(e){let t=e.trim(),s=!1;while(t.startsWith(Oos)&&t.endsWith(Pos))t=t.slice(Oos.length,t.length-Pos.length).trim(),s=!0;return s?t:void 0}function t5(e){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,...e===void 0?{}:{premiumRequests:e},cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function bSe(e,t){let s=t.cache_creation;if(s!=null){let o=s.ephemeral_5m_input_tokens??0,r=s.ephemeral_1h_input_tokens??0;if(o>0||r>0)e.cttl={...o>0?{ephemeral5m:o}:{},...r>0?{ephemeral1h:r}:{}};else delete e.cttl}let n=t.server_tool_use;if(n!=null){let o=n.web_search_requests??0,r=n.web_fetch_requests??0;if(o>0||r>0)e.server={...o>0?{webSearch:o}:{},...r>0?{webFetch:r}:{}};else delete e.server}}function D5o(e){if(!Z(e))return;let t=Z(e.cache_creation)?{...typeof e.cache_creation.ephemeral_5m_input_tokens==="number"?{ephemeral_5m_input_tokens:e.cache_creation.ephemeral_5m_input_tokens}:{},...typeof e.cache_creation.ephemeral_1h_input_tokens==="number"?{ephemeral_1h_input_tokens:e.cache_creation.ephemeral_1h_input_tokens}:{}}:void 0;return{...typeof e.input_tokens==="number"?{input_tokens:e.input_tokens}:{},...typeof e.output_tokens==="number"?{output_tokens:e.output_tokens}:{},...typeof e.cache_read_input_tokens==="number"?{cache_read_input_tokens:e.cache_read_input_tokens}:{},...typeof e.cache_creation_input_tokens==="number"?{cache_creation_input_tokens:e.cache_creation_input_tokens}:{},...t===void 0?{}:{cache_creation:t}}}function N5o(e){if(!Z(e)||e.type!=="fallback")return;let t=Z(e.from)&&typeof e.from.model==="string"?e.from.model:void 0,s=Z(e.to)&&typeof e.to.model==="string"?e.to.model:void 0;if(!t?.trim()||!s?.trim())return;return{type:"fallback",from:{model:t},to:{model:s}}}function Fos(e){let t=e.iterations??[];for(let s=t.length-1;s>=0;s-=1){let n=t[s];if(n?.type==="fallback_message"&&n.model?.trim())return n.model}return}function q5o(e,t){let s=t?.trim();if(!s||s===e.id)return e;if(e.provider==="anthropic"){let n=HU("anthropic",s);if(n?.api==="anthropic-messages")return n}return e}function _os(e,t,s){let n=s.iterations??[];if(n.length===0)return!1;let o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},r=n.some((a)=>a.type==="fallback_message"),i=!1;for(let a of n){let l=a.input_tokens??0,u=a.output_tokens??0,p=a.cache_read_input_tokens??0,c=a.cache_creation_input_tokens??0,d=a.type==="fallback_message";if(r&&!d&&u===0&&c===0)continue;let f=t5();if(d)f.input=0,f.cacheRead=p+l;else f.input=l,f.cacheRead=p;f.output=u,f.cacheWrite=c,f.totalTokens=f.input+f.output+f.cacheRead+f.cacheWrite,el(q5o(e,a.model),f),o.input+=f.cost.input,o.output+=f.cost.output,o.cacheRead+=f.cost.cacheRead,o.cacheWrite+=f.cost.cacheWrite,o.total+=f.cost.total,i=!0}if(!i)return!1;return t.cost=o,!0}function Bet(e){return U5o.test(e)}function ers(e,t){if(!Bet(t))return t;if(e.compat.officialEndpoint)return t;if(e.compatConfig?.replayUnsignedThinking!==void 0)return t;return`${`Provider "${e.provider}" looks like an Anthropic-compatible signing proxy: it rejected a replayed unsigned thinking block. Set \`compat.replayUnsignedThinking: false\` under \`providers.${e.provider}\` in your models.yml and retry. See https://github.com/can1357/oh-my-pi/issues/4297.`}
|
|
@@ -4108,7 +4108,7 @@ Return JSON in this exact format:
|
|
|
4108
4108
|
|
|
4109
4109
|
User message: {text}
|
|
4110
4110
|
|
|
4111
|
-
Extraction:`;fOe=["fact","text","content","value","statement"],JNr=["instruction","rule",...fOe],XNr=["preference",...fOe],QNr=["description","event","timeline","date",...fOe]});function rqr(e){return Object.hasOwn(oqr,e)}function aWs(e,t="veracity"){if(e===null||e===void 0)return"unknown";let s=String(e).trim().toLowerCase();if(s==="")return"unknown";if(rqr(s))return s;let n=String(e),o=n.length>iWs?`${n.slice(0,iWs)}...[truncated]`:n;return console.warn(`${t} received unknown veracity ${JSON.stringify(o)}; clamping to 'unknown'`),"unknown"}var BNl,oqr,iWs=80,WNl;var lWs=S(()=>{yS();BNl=Object.freeze({stated:1,inferred:0.7,tool:0.5,imported:0.6,unknown:0.8}),oqr=Object.freeze({stated:!0,inferred:!0,tool:!0,imported:!0,unknown:!0}),WNl=Symbol("mnemopi.veracity.txDepth")});var uWs=()=>{};import*as Omt from"path";async function pWs(e,t="local_cache"){let s=aqr[e];if(s===void 0)return!1;let n=Omt.join(t,e);for(let o of iqr){let r=Omt.join(n,o);if(await Bun.file(r).exists())continue;let i=await fetch(`https://huggingface.co/${s}/resolve/main/${o}`);if(!i.ok)throw Error(`Failed to download ${e} ${o} from ${s}: ${i.status} ${i.statusText}`);await Bun.write(r,await i.arrayBuffer())}return!0}var iqr,aqr;var cWs=S(()=>{iqr=["config.json","tokenizer.json","tokenizer_config.json","special_tokens_map.json"],aqr={"fast-all-MiniLM-L6-v2":"sentence-transformers/all-MiniLM-L6-v2","fast-bge-base-en":"BAAI/bge-base-en","fast-bge-base-en-v1.5":"BAAI/bge-base-en-v1.5","fast-bge-small-en":"BAAI/bge-small-en","fast-bge-small-en-v1.5":"BAAI/bge-small-en-v1.5","fast-bge-small-zh-v1.5":"BAAI/bge-small-zh-v1.5","fast-multilingual-e5-large":"intfloat/multilingual-e5-large"}});var fWs;var dWs=S(()=>{fWs={type:"module",name:"@oh-my-pi/pi-mnemopi",version:"18.1.0",description:"Local SQLite memory engine for Oh My Pi agents",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Abdias J"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/mnemopi"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["memory","sqlite","agent","embeddings","mcp"],main:"./src/index.ts",module:"./src/index.ts",types:"./dist/types/index.d.ts",bin:{mnemopi:"src/cli.ts"},scripts:{check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun test --parallel",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"},dependencies:{"@oh-my-pi/pi-ai":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-natives":"catalog:","@oh-my-pi/pi-utils":"catalog:"},peerDependencies:{fastembed:"2.1.0","onnxruntime-node":"1.21.0"},peerDependenciesMeta:{fastembed:{optional:!0},"onnxruntime-node":{optional:!0}},devDependencies:{"@types/bun":"catalog:",fastembed:"catalog:","onnxruntime-node":"catalog:"},engines:{bun:">=1.3.14"},files:["src","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./core":{types:"./dist/types/core/index.d.ts",import:"./src/core/index.ts"},"./core/beam":{types:"./dist/types/core/beam/index.d.ts",import:"./src/core/beam/index.ts"},"./beam":{types:"./dist/types/core/beam/index.d.ts",import:"./src/core/beam/index.ts"},"./diagnose":{types:"./dist/types/diagnose.d.ts",import:"./src/diagnose.ts"},"./mcp":{types:"./dist/types/mcp-tools.d.ts",import:"./src/mcp-tools.ts"},"./cli":{types:"./dist/types/cli.d.ts",import:"./src/cli.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./*.js":"./src/*.ts"}}});import{createRequire as mWs}from"module";import*as Gf from"path";function uqr(){return{versionKey:`fastembed-${gOe}_transitive-ort`.replace(/[^A-Za-z0-9._-]/g,"_"),install:{dependencies:{fastembed:gOe},trustedDependencies:["onnxruntime-node"]}}}async function pqr({fastembedEntry:e,fastembedPackageDir:t,arch:s=process.arch,env:n=process.env}){let o=Gf.join(t,"node_modules"),r=Gf.dirname(t),i=Vp(o,"onnxruntime-node"),a=i??Vp(r,"onnxruntime-node"),l=Gf.join(i?o:r,"onnxruntime-node");if(!a)throw Error(`Cannot find module onnxruntime-node beside ${e}`);let u=new Bun.Glob(`bin/napi-*/win32/${s}/onnxruntime.dll`),p;for await(let m of u.scan({cwd:l,absolute:!0,onlyFiles:!0})){p=Gf.dirname(m);break}if(!p)throw Error(`Cannot find module onnxruntime-node Windows DLL for ${s} beside ${a}`);let c=n.PATH,d=Gf.resolve(p).toLowerCase();if(!c?.split(Gf.delimiter).some((m)=>Gf.resolve(m).toLowerCase()===d))n.PATH=c?`${p}${Gf.delimiter}${c}`:p;return{ortEntry:a,ortPackageDir:l,dllDir:p}}function gWs(){return Pmt??=cqr().catch((e)=>{throw Pmt=null,e}),Pmt}async function cqr(){try{let e=mWs(import.meta.url),t=e.resolve("fastembed/package.json"),s=e(t);if(s.version!==gOe)throw Error(`Cannot find package fastembed@${gOe}; resolved ${String(s.version)}`);return await hWs(e.resolve("fastembed"),Gf.dirname(t))}catch(e){if(!fqr(e))throw e;return v.debug("mnemopi: fastembed not loadable, using on-demand runtime install",{error:String(e)}),dqr()}}async function hWs(e,t){let s=mWs(e);if(process.platform==="win32"){let{ortEntry:o}=await pqr({fastembedEntry:e,fastembedPackageDir:t});s(o)}return s(e)}async function dqr(){let e=uqr(),t=await GP({runtimeDir:Gf.join(y$t(),e.versionKey),install:e.install,probePackage:"fastembed"}),s=Gf.join(t,"node_modules");Lye({runtimeNodeModules:s});let n=Vp(s,"fastembed");if(!n)throw Error(`fastembed runtime install at ${t} has no loadable entry`);return hWs(n,Gf.join(s,"fastembed"))}function fqr(e){if(typeof e!=="object"||e===null)return!1;let{name:t,code:s,message:n}=e;if(t==="ResolveMessage")return!0;if(s==="ERR_MODULE_NOT_FOUND"||s==="MODULE_NOT_FOUND"||s==="ERR_DLOPEN_FAILED")return!0;return typeof n==="string"&&/cannot find (module|package)/i.test(n)}var gOe,Pmt=null;var TWs=S(()=>{B();dWs();gOe=fWs.peerDependencies.fastembed});function NV(e,t){let s=e.length>t.length?e.length:t.length;if(s===0)return 0;let n=0,o=0,r=0;for(let i=0;i<s;i+=1){let a=e[i]??0,l=t[i]??0,u=Number.isFinite(a)?a:0,p=Number.isFinite(l)?l:0;n+=u*p,o+=u*u,r+=p*p}if(o===0||r===0)return 0;return n/(Math.sqrt(o)*Math.sqrt(r))}import{mkdirSync as mqr}from"fs";import*as mie from"fs/promises";import*as WE from"path";async function CWs(e,t){let s=/Load model from (.+?\.onnx) failed:.*Protobuf parsing failed/i.exec(e);if(!s)return!1;let n=WE.resolve(s[1]),o=WE.resolve(t??hQ());if(!n.startsWith(o+WE.sep))return!1;try{await mie.rename(n,`${n}.corrupt-${Date.now()}`),v.warn("mnemopi: quarantined corrupt local embedding model; retrying init",{modelFile:n})}catch{}return!0}async function bWs(e,t){let s=/Model file not found at (.+?\.onnx)\b/i.exec(e);if(!s)return!1;let n=WE.resolve(s[1]),o=WE.dirname(n),r=WE.resolve(t??hQ());if(WE.dirname(o)!==r)return!1;try{await mie.rm(o,{recursive:!0,force:!0}),await mie.rm(`${o}.tar.gz`,{force:!0}),v.warn("mnemopi: cleared incomplete local embedding model cache; re-downloading",{modelDir:o})}catch{}return!0}async function XL(e){let t=e.cacheDir??hQ(),s=e.cacheDir===void 0?{...e,cacheDir:t}:e,{FlagEmbedding:n}=await gWs(),o=async()=>{try{return await n.init(s)}catch(r){let i=r instanceof Error?r.message:"";if(!Tqr.test(i))throw r;if(!await pWs(e.model,t))throw r;return n.init(s)}};try{return await o()}catch(r){let i=r instanceof Error?r.message:"";if(/Protobuf parsing failed/i.test(i)&&await CWs(i,t))return o();if(await bWs(i,t))return o();throw r}}function l0(){return BE()?.embeddings}function Lmt(e){let t=l0(),s=t?.provider,n=0;if(s!==void 0){let i=yWs.get(s);if(i===void 0)n=hqr++,yWs.set(s,n);else n=i}let o=a0(),r=t?.apiUrl??"";return`${n}::${o}::${r}::${e}`}function kWs(){return ce.NODE_ENV==="test"||ce.BUN_ENV==="test"}function VB(){let e=l0();if(e?.disabled!==void 0)return e.disabled;return $n("MNEMOPI_NO_EMBEDDINGS")}function yqr(){let e=l0()?.maxInputChars;if(e!==void 0)return Math.max(0,Math.trunc(e));let t=Number.parseInt(ce.MNEMOPI_EMBEDDING_MAX_INPUT_CHARS??"",10);if(Number.isFinite(t)&&t>=0)return t;return 8192}function Rqr(e,t){if(e.length<=t)return e;if(t<=Fmt.length+16)return e.slice(e.length-t);let s=t-Fmt.length,n=s>>>1,o=s-n;return e.slice(0,n)+Fmt+e.slice(e.length-o)}function Cqr(e){let t=yqr();if(t===0)return e;let s=null,n=0,o=0;for(let r=0;r<e.length;r++){let i=e[r]??"";if(i.length<=t)continue;if(s===null)s=e.slice();if(s[r]=Rqr(i,t),n++,i.length>o)o=i.length}if(s===null)return e;return v[_V()?"warn":"debug"]("mnemopi: embedding input truncated",{inputCount:e.length,trimmedCount:n,maxOriginalLen:o,maxInputChars:t}),s}function SWs(){let e=l0();if(e?.apiKey!==void 0)return e.apiKey;return ce.MNEMOPI_EMBEDDING_API_KEY||ce.OPENROUTER_API_KEY||ce.OPENAI_API_KEY||""}function qmt(e=SWs()){return typeof e==="function"||e!==""}function bqr(){let e=l0();if(e?.apiUrl!==void 0)return e.apiUrl;return ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL||"https://openrouter.ai/api/v1"}function a0(){let e=l0();if(e?.model!==void 0)return e.model;return ce.MNEMOPI_EMBEDDING_MODEL||"BAAI/bge-small-en-v1.5"}function gie(){return a0()}function hOe(e){if(e.startsWith("openai/")||e.includes("text-embedding")||e.startsWith("text-embedding"))return!0;let s=l0()?.apiUrl??(ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL);if(s!==void 0&&s!==""&&!sn(s,"openrouter"))return!0;return $n("MNEMOPI_EMBEDDINGS_VIA_API")}function wWs(e){let t=Number.parseInt(ce.MNEMOPI_EMBEDDING_DIM??"",10);if(Number.isFinite(t))return t;return kqr[e]??384}async function _mt(e){let t=[];for await(let s of e)for(let n of s)t.push(new Float32Array(n));return t}function xWs(e){let t=Sqr[e];return t===void 0?null:t}async function wqr(){if(hOe(a0())||VB()||kWs())return null;if(zB!==null)return zB;let e=xWs(a0());if(e===null)return null;let t=hQ();mqr(t,{recursive:!0});let s=Dmt({model:e,cacheDir:t,showDownloadProgress:!1});zB=s;try{return await s}catch(n){if(v[_V()?"warn":"debug"]("mnemopi: local embedding model failed to load",{model:e,error:String(n)}),zB===s)zB=null;return null}}async function xqr(e){let t=bqr(),s=!sn(t,"openrouter"),n=SWs();if(!s&&!qmt(n))return null;let o=JSON.stringify({model:a0(),input:e});try{let r=await an(n,async(a)=>{let l={"Content-Type":"application/json",...Rz()};if(a!=="")l.Authorization=`Bearer ${a}`;let u=await zp(`${t.replace(/\/+$/,"")}/embeddings`,{method:"POST",headers:l,body:o,signal:AbortSignal.timeout(30000),maxAttempts:3,defaultDelayMs:(p)=>2**p*1000});if(u.status===401)throw new gs("mnemopi embedding request unauthorized (401)",401,{headers:u.headers});return u});if(!r.ok)return null;let{data:i}=await r.json();if(i===void 0)return null;return Nmt+=1,i.map((a)=>new Float32Array(a.embedding))}catch(r){return v.debug("mnemopi embedding request failed",{status:sp(r)}),null}}async function RWs(e){if(e.available===void 0)return!0;try{return await e.available()}catch{return!1}}function EWs(e){qV=e??null,KB.clear()}function MWs(e){Dmt=e??XL,zB=null,KB.clear()}function AWs(){qV=null,zB=null,Dmt=XL,Nmt=0,KB.clear()}async function Aqr(){if(VB())return!1;let e=l0(),t=pie(e?.provider);if(t!==void 0)return RWs(t);if(qV!==null)return RWs(qV);if(hOe(a0())){let s=e?.apiUrl??(ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL);if(s!==void 0&&s!==""&&!sn(s,"openrouter"))return!0;return qmt()}if(kWs())return!1;return xWs(a0())!==null}function vqr(){return qmt()}async function Hmt(e){if(e===""||VB())return null;let t=Lmt(e),s=KB.get(t);if(s!==void 0)return s;let o=(await TOe([e]))?.[0]??null;if(o!==null)KB.set(t,o);return o}async function TOe(e){if(e.length===0||VB())return null;e=Cqr(e);let t=pie(l0()?.provider);if(t!==void 0)try{return await _mt(await t.embed(e))}catch{return null}if(qV!==null)try{return await _mt(await qV.embed(e))}catch{return null}if(hOe(a0()))return xqr(e);if(e.length===1){let n=Lmt(e[0]??""),o=KB.get(n);if(o!==void 0)return[o]}let s=await wqr();if(s===null)return null;try{let n=await _mt(s.embed([...e]));if(n.length===1){let o=n[0];if(o!==void 0)KB.set(Lmt(e[0]??""),o)}return n}catch(n){return v[_V()?"warn":"debug"]("mnemopi: local embedding failed",{textCount:e.length,error:String(n)}),null}}function Iqr(){return Nmt}var gqr=512,qV=null,zB=null,Dmt,Nmt=0,KB,yWs,hqr=1,Tqr,Fmt=`
|
|
4111
|
+
Extraction:`;fOe=["fact","text","content","value","statement"],JNr=["instruction","rule",...fOe],XNr=["preference",...fOe],QNr=["description","event","timeline","date",...fOe]});function rqr(e){return Object.hasOwn(oqr,e)}function aWs(e,t="veracity"){if(e===null||e===void 0)return"unknown";let s=String(e).trim().toLowerCase();if(s==="")return"unknown";if(rqr(s))return s;let n=String(e),o=n.length>iWs?`${n.slice(0,iWs)}...[truncated]`:n;return console.warn(`${t} received unknown veracity ${JSON.stringify(o)}; clamping to 'unknown'`),"unknown"}var BNl,oqr,iWs=80,WNl;var lWs=S(()=>{yS();BNl=Object.freeze({stated:1,inferred:0.7,tool:0.5,imported:0.6,unknown:0.8}),oqr=Object.freeze({stated:!0,inferred:!0,tool:!0,imported:!0,unknown:!0}),WNl=Symbol("mnemopi.veracity.txDepth")});var uWs=()=>{};import*as Omt from"path";async function pWs(e,t="local_cache"){let s=aqr[e];if(s===void 0)return!1;let n=Omt.join(t,e);for(let o of iqr){let r=Omt.join(n,o);if(await Bun.file(r).exists())continue;let i=await fetch(`https://huggingface.co/${s}/resolve/main/${o}`);if(!i.ok)throw Error(`Failed to download ${e} ${o} from ${s}: ${i.status} ${i.statusText}`);await Bun.write(r,await i.arrayBuffer())}return!0}var iqr,aqr;var cWs=S(()=>{iqr=["config.json","tokenizer.json","tokenizer_config.json","special_tokens_map.json"],aqr={"fast-all-MiniLM-L6-v2":"sentence-transformers/all-MiniLM-L6-v2","fast-bge-base-en":"BAAI/bge-base-en","fast-bge-base-en-v1.5":"BAAI/bge-base-en-v1.5","fast-bge-small-en":"BAAI/bge-small-en","fast-bge-small-en-v1.5":"BAAI/bge-small-en-v1.5","fast-bge-small-zh-v1.5":"BAAI/bge-small-zh-v1.5","fast-multilingual-e5-large":"intfloat/multilingual-e5-large"}});var fWs;var dWs=S(()=>{fWs={type:"module",name:"@oh-my-pi/pi-mnemopi",version:"18.1.1",description:"Local SQLite memory engine for Oh My Pi agents",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Abdias J"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/mnemopi"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["memory","sqlite","agent","embeddings","mcp"],main:"./src/index.ts",module:"./src/index.ts",types:"./dist/types/index.d.ts",bin:{mnemopi:"src/cli.ts"},scripts:{check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun test --parallel",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"},dependencies:{"@oh-my-pi/pi-ai":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-natives":"catalog:","@oh-my-pi/pi-utils":"catalog:"},peerDependencies:{fastembed:"2.1.0","onnxruntime-node":"1.21.0"},peerDependenciesMeta:{fastembed:{optional:!0},"onnxruntime-node":{optional:!0}},devDependencies:{"@types/bun":"catalog:",fastembed:"catalog:","onnxruntime-node":"catalog:"},engines:{bun:">=1.3.14"},files:["src","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./core":{types:"./dist/types/core/index.d.ts",import:"./src/core/index.ts"},"./core/beam":{types:"./dist/types/core/beam/index.d.ts",import:"./src/core/beam/index.ts"},"./beam":{types:"./dist/types/core/beam/index.d.ts",import:"./src/core/beam/index.ts"},"./diagnose":{types:"./dist/types/diagnose.d.ts",import:"./src/diagnose.ts"},"./mcp":{types:"./dist/types/mcp-tools.d.ts",import:"./src/mcp-tools.ts"},"./cli":{types:"./dist/types/cli.d.ts",import:"./src/cli.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./*.js":"./src/*.ts"}}});import{createRequire as mWs}from"module";import*as Gf from"path";function uqr(){return{versionKey:`fastembed-${gOe}_transitive-ort`.replace(/[^A-Za-z0-9._-]/g,"_"),install:{dependencies:{fastembed:gOe},trustedDependencies:["onnxruntime-node"]}}}async function pqr({fastembedEntry:e,fastembedPackageDir:t,arch:s=process.arch,env:n=process.env}){let o=Gf.join(t,"node_modules"),r=Gf.dirname(t),i=Vp(o,"onnxruntime-node"),a=i??Vp(r,"onnxruntime-node"),l=Gf.join(i?o:r,"onnxruntime-node");if(!a)throw Error(`Cannot find module onnxruntime-node beside ${e}`);let u=new Bun.Glob(`bin/napi-*/win32/${s}/onnxruntime.dll`),p;for await(let m of u.scan({cwd:l,absolute:!0,onlyFiles:!0})){p=Gf.dirname(m);break}if(!p)throw Error(`Cannot find module onnxruntime-node Windows DLL for ${s} beside ${a}`);let c=n.PATH,d=Gf.resolve(p).toLowerCase();if(!c?.split(Gf.delimiter).some((m)=>Gf.resolve(m).toLowerCase()===d))n.PATH=c?`${p}${Gf.delimiter}${c}`:p;return{ortEntry:a,ortPackageDir:l,dllDir:p}}function gWs(){return Pmt??=cqr().catch((e)=>{throw Pmt=null,e}),Pmt}async function cqr(){try{let e=mWs(import.meta.url),t=e.resolve("fastembed/package.json"),s=e(t);if(s.version!==gOe)throw Error(`Cannot find package fastembed@${gOe}; resolved ${String(s.version)}`);return await hWs(e.resolve("fastembed"),Gf.dirname(t))}catch(e){if(!fqr(e))throw e;return v.debug("mnemopi: fastembed not loadable, using on-demand runtime install",{error:String(e)}),dqr()}}async function hWs(e,t){let s=mWs(e);if(process.platform==="win32"){let{ortEntry:o}=await pqr({fastembedEntry:e,fastembedPackageDir:t});s(o)}return s(e)}async function dqr(){let e=uqr(),t=await GP({runtimeDir:Gf.join(y$t(),e.versionKey),install:e.install,probePackage:"fastembed"}),s=Gf.join(t,"node_modules");Lye({runtimeNodeModules:s});let n=Vp(s,"fastembed");if(!n)throw Error(`fastembed runtime install at ${t} has no loadable entry`);return hWs(n,Gf.join(s,"fastembed"))}function fqr(e){if(typeof e!=="object"||e===null)return!1;let{name:t,code:s,message:n}=e;if(t==="ResolveMessage")return!0;if(s==="ERR_MODULE_NOT_FOUND"||s==="MODULE_NOT_FOUND"||s==="ERR_DLOPEN_FAILED")return!0;return typeof n==="string"&&/cannot find (module|package)/i.test(n)}var gOe,Pmt=null;var TWs=S(()=>{B();dWs();gOe=fWs.peerDependencies.fastembed});function NV(e,t){let s=e.length>t.length?e.length:t.length;if(s===0)return 0;let n=0,o=0,r=0;for(let i=0;i<s;i+=1){let a=e[i]??0,l=t[i]??0,u=Number.isFinite(a)?a:0,p=Number.isFinite(l)?l:0;n+=u*p,o+=u*u,r+=p*p}if(o===0||r===0)return 0;return n/(Math.sqrt(o)*Math.sqrt(r))}import{mkdirSync as mqr}from"fs";import*as mie from"fs/promises";import*as WE from"path";async function CWs(e,t){let s=/Load model from (.+?\.onnx) failed:.*Protobuf parsing failed/i.exec(e);if(!s)return!1;let n=WE.resolve(s[1]),o=WE.resolve(t??hQ());if(!n.startsWith(o+WE.sep))return!1;try{await mie.rename(n,`${n}.corrupt-${Date.now()}`),v.warn("mnemopi: quarantined corrupt local embedding model; retrying init",{modelFile:n})}catch{}return!0}async function bWs(e,t){let s=/Model file not found at (.+?\.onnx)\b/i.exec(e);if(!s)return!1;let n=WE.resolve(s[1]),o=WE.dirname(n),r=WE.resolve(t??hQ());if(WE.dirname(o)!==r)return!1;try{await mie.rm(o,{recursive:!0,force:!0}),await mie.rm(`${o}.tar.gz`,{force:!0}),v.warn("mnemopi: cleared incomplete local embedding model cache; re-downloading",{modelDir:o})}catch{}return!0}async function XL(e){let t=e.cacheDir??hQ(),s=e.cacheDir===void 0?{...e,cacheDir:t}:e,{FlagEmbedding:n}=await gWs(),o=async()=>{try{return await n.init(s)}catch(r){let i=r instanceof Error?r.message:"";if(!Tqr.test(i))throw r;if(!await pWs(e.model,t))throw r;return n.init(s)}};try{return await o()}catch(r){let i=r instanceof Error?r.message:"";if(/Protobuf parsing failed/i.test(i)&&await CWs(i,t))return o();if(await bWs(i,t))return o();throw r}}function l0(){return BE()?.embeddings}function Lmt(e){let t=l0(),s=t?.provider,n=0;if(s!==void 0){let i=yWs.get(s);if(i===void 0)n=hqr++,yWs.set(s,n);else n=i}let o=a0(),r=t?.apiUrl??"";return`${n}::${o}::${r}::${e}`}function kWs(){return ce.NODE_ENV==="test"||ce.BUN_ENV==="test"}function VB(){let e=l0();if(e?.disabled!==void 0)return e.disabled;return $n("MNEMOPI_NO_EMBEDDINGS")}function yqr(){let e=l0()?.maxInputChars;if(e!==void 0)return Math.max(0,Math.trunc(e));let t=Number.parseInt(ce.MNEMOPI_EMBEDDING_MAX_INPUT_CHARS??"",10);if(Number.isFinite(t)&&t>=0)return t;return 8192}function Rqr(e,t){if(e.length<=t)return e;if(t<=Fmt.length+16)return e.slice(e.length-t);let s=t-Fmt.length,n=s>>>1,o=s-n;return e.slice(0,n)+Fmt+e.slice(e.length-o)}function Cqr(e){let t=yqr();if(t===0)return e;let s=null,n=0,o=0;for(let r=0;r<e.length;r++){let i=e[r]??"";if(i.length<=t)continue;if(s===null)s=e.slice();if(s[r]=Rqr(i,t),n++,i.length>o)o=i.length}if(s===null)return e;return v[_V()?"warn":"debug"]("mnemopi: embedding input truncated",{inputCount:e.length,trimmedCount:n,maxOriginalLen:o,maxInputChars:t}),s}function SWs(){let e=l0();if(e?.apiKey!==void 0)return e.apiKey;return ce.MNEMOPI_EMBEDDING_API_KEY||ce.OPENROUTER_API_KEY||ce.OPENAI_API_KEY||""}function qmt(e=SWs()){return typeof e==="function"||e!==""}function bqr(){let e=l0();if(e?.apiUrl!==void 0)return e.apiUrl;return ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL||"https://openrouter.ai/api/v1"}function a0(){let e=l0();if(e?.model!==void 0)return e.model;return ce.MNEMOPI_EMBEDDING_MODEL||"BAAI/bge-small-en-v1.5"}function gie(){return a0()}function hOe(e){if(e.startsWith("openai/")||e.includes("text-embedding")||e.startsWith("text-embedding"))return!0;let s=l0()?.apiUrl??(ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL);if(s!==void 0&&s!==""&&!sn(s,"openrouter"))return!0;return $n("MNEMOPI_EMBEDDINGS_VIA_API")}function wWs(e){let t=Number.parseInt(ce.MNEMOPI_EMBEDDING_DIM??"",10);if(Number.isFinite(t))return t;return kqr[e]??384}async function _mt(e){let t=[];for await(let s of e)for(let n of s)t.push(new Float32Array(n));return t}function xWs(e){let t=Sqr[e];return t===void 0?null:t}async function wqr(){if(hOe(a0())||VB()||kWs())return null;if(zB!==null)return zB;let e=xWs(a0());if(e===null)return null;let t=hQ();mqr(t,{recursive:!0});let s=Dmt({model:e,cacheDir:t,showDownloadProgress:!1});zB=s;try{return await s}catch(n){if(v[_V()?"warn":"debug"]("mnemopi: local embedding model failed to load",{model:e,error:String(n)}),zB===s)zB=null;return null}}async function xqr(e){let t=bqr(),s=!sn(t,"openrouter"),n=SWs();if(!s&&!qmt(n))return null;let o=JSON.stringify({model:a0(),input:e});try{let r=await an(n,async(a)=>{let l={"Content-Type":"application/json",...Rz()};if(a!=="")l.Authorization=`Bearer ${a}`;let u=await zp(`${t.replace(/\/+$/,"")}/embeddings`,{method:"POST",headers:l,body:o,signal:AbortSignal.timeout(30000),maxAttempts:3,defaultDelayMs:(p)=>2**p*1000});if(u.status===401)throw new gs("mnemopi embedding request unauthorized (401)",401,{headers:u.headers});return u});if(!r.ok)return null;let{data:i}=await r.json();if(i===void 0)return null;return Nmt+=1,i.map((a)=>new Float32Array(a.embedding))}catch(r){return v.debug("mnemopi embedding request failed",{status:sp(r)}),null}}async function RWs(e){if(e.available===void 0)return!0;try{return await e.available()}catch{return!1}}function EWs(e){qV=e??null,KB.clear()}function MWs(e){Dmt=e??XL,zB=null,KB.clear()}function AWs(){qV=null,zB=null,Dmt=XL,Nmt=0,KB.clear()}async function Aqr(){if(VB())return!1;let e=l0(),t=pie(e?.provider);if(t!==void 0)return RWs(t);if(qV!==null)return RWs(qV);if(hOe(a0())){let s=e?.apiUrl??(ce.MNEMOPI_EMBEDDING_API_URL||ce.OPENROUTER_BASE_URL);if(s!==void 0&&s!==""&&!sn(s,"openrouter"))return!0;return qmt()}if(kWs())return!1;return xWs(a0())!==null}function vqr(){return qmt()}async function Hmt(e){if(e===""||VB())return null;let t=Lmt(e),s=KB.get(t);if(s!==void 0)return s;let o=(await TOe([e]))?.[0]??null;if(o!==null)KB.set(t,o);return o}async function TOe(e){if(e.length===0||VB())return null;e=Cqr(e);let t=pie(l0()?.provider);if(t!==void 0)try{return await _mt(await t.embed(e))}catch{return null}if(qV!==null)try{return await _mt(await qV.embed(e))}catch{return null}if(hOe(a0()))return xqr(e);if(e.length===1){let n=Lmt(e[0]??""),o=KB.get(n);if(o!==void 0)return[o]}let s=await wqr();if(s===null)return null;try{let n=await _mt(s.embed([...e]));if(n.length===1){let o=n[0];if(o!==void 0)KB.set(Lmt(e[0]??""),o)}return n}catch(n){return v[_V()?"warn":"debug"]("mnemopi: local embedding failed",{textCount:e.length,error:String(n)}),null}}function Iqr(){return Nmt}var gqr=512,qV=null,zB=null,Dmt,Nmt=0,KB,yWs,hqr=1,Tqr,Fmt=`
|
|
4112
4112
|
|
|
4113
4113
|
[...]
|
|
4114
4114
|
|
|
@@ -4619,7 +4619,7 @@ ${i.length} entr${i.length===1?"y":"ies"}:
|
|
|
4619
4619
|
|
|
4620
4620
|
${u}
|
|
4621
4621
|
`;return{url:e.url,content:c,contentType:"text/markdown",size:Buffer.byteLength(c,"utf-8"),sourcePath:o,immutable:!0}}async#p(e,t){let{root:s,targetPath:n}=await this.#l(e,t),o=Mp.dirname(n);try{let l=await Nu.promises.realpath(o);AC(l,s)}catch(l){if(!pe(l))throw l}let r;try{r=await Nu.promises.realpath(n)}catch(l){if(pe(l))throw Error(`Vault file not found: ${e.url}`);throw l}AC(r,s);let i=await Nu.promises.stat(r);if(i.isDirectory())return this.#u(e,t);if(!i.isFile())throw Error(`vault:// URL must resolve to a file or directory: ${e.url}`);let a=await Bun.file(r).text();return{url:e.url,content:a,contentType:_Hr(r),size:Buffer.byteLength(a,"utf-8"),sourcePath:r}}async#c(e,t,s){let{root:n,targetPath:o}=await this.#l(e,s);try{let r=await Nu.promises.realpath(o);if(AC(r,n),(await Nu.promises.stat(r)).isDirectory())throw Error(`vault:// URL must resolve to a file: ${e.url}`)}catch(r){if(!pe(r))throw r;let i=Mp.dirname(o),a=await JHr(i,n);AC(a,n),await Nu.promises.mkdir(i,{recursive:!0});let l=await Nu.promises.realpath(i);AC(l,n)}await Bun.write(o,t)}async#d(e,t){let s=ZHr(e),n=[...this.#r(e.ref),...s.args],o=await this.#s(n,t);return wPe(s.opLabel,o),{url:e.url,content:o.stdout,contentType:s.contentType,size:Buffer.byteLength(o.stdout,"utf-8"),immutable:!0}}}var Xgt="/Applications/Obsidian.app/Contents/MacOS/obsidian",b3s=30000,PHr,FHr,QE,xPe,XE,QV,Jgt,GHr="vault:// is disabled. Enable it by setting `vault.enabled = true` (Settings \u2192 Tools \u2192 Obsidian Vault).",MPe;var vPe=S(()=>{B();Gt();ch();J_();PE();IB();PHr={outline:!0,backlinks:!0,links:!0,tags:!0,properties:!0,tasks:!0,wordcount:!0,history:!0,base:!0},FHr={search:!0,daily:!0,"daily-path":!0,tags:!0,tag:!0,tasks:!0,orphans:!0,unresolved:!0,deadends:!0,bases:!0,bookmarks:!0,recents:!0,templates:!0,aliases:!0,properties:!0,property:!0},Jgt=new Map;MPe=class MPe extends Error{constructor(){super(GHr);this.name="VaultDisabledError"}}});function ZV(e){return e.toLowerCase().startsWith("xd://")?e.slice(5):e}function vC(e){let t=e.trim();if(!t.toLowerCase().startsWith("xd://"))return null;let s=t.slice(5);if(s.length===0)return{name:null};if(/[/?#]/.test(s))return null;return{name:s}}function A3s(e){if(e.length<=5)return"xd://".startsWith(e.toLowerCase());return e.toLowerCase().startsWith("xd://")}class eht{scheme="xd";immutable=!0;async resolve(e,t){let s=vC(e.href);if(!s)throw Error(`Invalid xd:// URL: ${e.href}. Use xd:// or xd://<tool>.`);if(!t?.xd)throw Error("xd:// is not mounted in this session.");let n=await t.xd.read(s.name);return{url:e.href,content:n,contentType:"text/plain",size:Buffer.byteLength(n)}}async write(e,t,s){let n=vC(e.href);if(!n)throw Error(`Invalid xd:// URL: ${e.href}. Use xd://<tool>.`);if(!s?.xd)throw Error("xd:// is not mounted in this session.");await s.xd.write(n.name,t)}}var Hl="xd://";class Mi{static#e;#t=new Map;constructor(){this.register(new Igt),this.register(new kdt),this.register(new Edt),this.register(new vgt),this.register(new BT),this.register(new Zgt),this.register(new dft),this.register(new Pgt),this.register(new Fie),this.register(new Bft),this.register(new aft),this.register(new lft),this.register(new Adt),this.register(new Vgt),this.register(new eht)}static instance(){return Mi.#e??=new Mi,Mi.#e}static resetForTests(){Mi.#e=void 0}register(e){this.#t.set(e.scheme.toLowerCase(),e)}unregister(e){return this.#t.delete(e.toLowerCase())}getHandler(e){return this.#t.get(e.toLowerCase())}canHandle(e){let t=e.match(/^([a-z][a-z0-9+.-]*):\/\//i);if(!t)return!1;return this.#t.has(t[1].toLowerCase())}canResolve(e){let t=r0e(e);if(!t)return!1;if(this.#t.has(t))return this.canHandle(e);return this.#s(t)}completionSchemes(){let e=[];for(let[t,s]of this.#t)if(s.complete)e.push(t);return e}async complete(e,t,s){let n=this.#t.get(e.toLowerCase());if(!n?.complete)return null;return n.complete(t,s)}#s(e){return!["file","http","https"].includes(e)&&this.#t.has("mcp")}#n(e,t=!1){let s=Nd(e),n=s.protocol.replace(/:$/,"").toLowerCase(),o=this.#t.get(n)??(t&&this.#s(n)?this.#t.get("mcp"):void 0);if(!o){let r=Array.from(this.#t.keys()).map((i)=>`${i}://`).join(", ");throw Error(`Unknown protocol: ${n}://
|
|
4622
|
-
Supported: ${r||"none"}`)}return{parsed:s,handler:o}}async resolve(e,t){let{parsed:s,handler:n}=this.#n(e,!0),o=await n.resolve(s,t);return{...o,immutable:o.immutable??n.immutable}}async write(e,t,s){let{parsed:n,handler:o}=this.#n(e);if(!o.write){let r=n.protocol.replace(/:$/,"").toLowerCase();throw Error(`${r}:// URLs are read-only for write; use the protocol-specific tool for mutations.`)}await o.write(n,t,s)}}var Hie=S(()=>{Sdt();OIe();vdt();uft();u0e();Wft();sPe();Ogt();PE();Fgt();fPe();IB();Ygt();vPe()});var ru=S(()=>{Sdt();OIe();vdt();uft();u0e();Wft();sPe();Ogt();PE();Hie();Fgt();fPe();IB();Ygt();vPe()});import*as sd from"fs";import*as q3s from"os";import*as un from"path";import*as U3s from"url";import{glob as eBr}from"@oh-my-pi/pi-natives";function aW(e){return un.posix.isAbsolute(e)||un.win32.isAbsolute(e)}function aBr(e){return e.replace(tBr," ")}function lBr(e){return e.replace(/ (AM|PM)\./g,`${iBr}$1.`)}function uBr(e){return e.normalize("NFD")}function P3s(e){return e.replace(/'/g,"\u2019")}function pBr(e){if(!e.includes("\\")||!e.includes("/"))return e;return e.replace(/\\([ \t"'(){}[\]])/g,"$1")}function Bie(e){try{return sd.accessSync(e,sd.constants.F_OK),!0}catch{return!1}}function cBr(e){if(!e.startsWith("@"))return e;let t=e.slice(1);if(t.startsWith("/")||t==="~"||t.startsWith("~/")||un.win32.isAbsolute(t)||t.startsWith("agent://")||t.startsWith("artifact://")||t.startsWith("skill://")||t.startsWith("rule://")||t.startsWith("security://")||t.startsWith("local:")||t.startsWith("mcp://"))return t;return e}function dBr(e){if(!e.toLowerCase().startsWith("file://"))return e;try{return U3s.fileURLToPath(e)}catch{return e}}function Pu(e,t){let s=t??q3s.homedir();if(e==="~")return s;if(e.startsWith("~/")||e.startsWith("~\\"))return s+e.slice(1);if(e.startsWith("~"))return un.join(s,e.slice(1));return e}function IC(e){let t=/^:(?=[/\\~]|\.\.?[/\\]|[A-Za-z]:)/.test(e)?e.slice(1):e,s=dR(dBr(aBr(cBr(t))));return Pu(s)}function F3s(e){if(e.length!==1)return!1;let t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function fBr(e){if(!e.startsWith("/"))return;let t=e.split("/");if(t[0]!=="")return;let s,n=2;if(t.length>=2&&F3s(t[1]??""))s=t[1].toUpperCase();else if(t.length>=3&&(t[1]??"").toLowerCase()==="mnt"&&F3s(t[2]??""))s=t[2].toUpperCase(),n=3;if(!s)return;let o=t.slice(n).filter(Boolean).join("\\");return o?`${s}:\\${o}`:`${s}:\\`}function mBr(e,t=process.platform,s=process.env){if(t==="win32")return fBr(e)??e;if(oT(t,s))return rTe(e)??e;return e}function hBr(e){let t=gBr.exec(e);if(!t)return null;let s=Number.parseInt(t[1],10);if(s<1)throw new X("Line selector 0 is invalid; lines are 1-indexed. Use :1.");let n=t[2]===".."?"-":t[2],o=t[3]?Number.parseInt(t[3],10):void 0,r;if(n==="+"){if(o===void 0||o<1)throw new X(`Invalid range ${s}+${o??0}: count must be >= 1.`);r=s+o-1}else if(n==="-"){if(o!==void 0){if(o<s)throw new X(`Invalid range ${s}-${o}: end must be >= start.`);r=o}}return{startLine:s,endLine:r}}function bh(e){let t=e.split(","),s=[];for(let o of t){let r=hBr(o);if(!r)return null;s.push(r)}if(s.length===0)return null;s.sort((o,r)=>o.startLine-r.startLine);let n=[s[0]];for(let o=1;o<s.length;o++){let r=s[o],i=n[n.length-1];if(i.endLine===void 0)continue;if(r.startLine<=i.endLine+1){if(r.endLine===void 0||r.endLine>i.endLine)n[n.length-1]={startLine:i.startLine,endLine:r.endLine};continue}n.push(r)}return n}function PPe(e){if(!e)return;for(let t of e.split(":")){let s=t.toLowerCase();if(s==="raw"||s==="conflicts")continue;let n=bh(t);if(n)return n}return}function Gie(e,t){for(let s of t){if(e<s.startLine)continue;if(s.endLine===void 0||e<=s.endLine)return!0}return!1}function Ha(e){let t=e.lastIndexOf(":");if(t<=0)return{path:e};let s=e.slice(t+1);if(!sBr.test(s))return{path:e};let n=e.slice(0,t),o=s,r=n.lastIndexOf(":");if(r>0){let i=n.slice(r+1),a=O3s.test(i),l=O3s.test(s),u=I3s.test(i),p=I3s.test(s);if(a&&p||u&&l)o=`${i}:${s}`,n=n.slice(0,r)}return{path:n,sel:o}}async function iD(e,t){let s=lu(e,t);try{return await sd.promises.lstat(s),"exists"}catch(n){if(pe(n)||CP(n)||xl(n,"ENAMETOOLONG"))return"missing";return"unknown"}}async function t6(e,t){let s=Ha(e);if(s.sel===void 0)return s;return await iD(e,t)==="missing"?s:{path:e}}function TBr(e,t){let s=lu(e,t);try{return sd.lstatSync(s),"exists"}catch(n){if(pe(n)||CP(n)||xl(n,"ENAMETOOLONG"))return"missing";return"unknown"}}function B3s(e,t){let s=Ha(e);if(s.sel===void 0)return s;return TBr(e,t)==="missing"?s:{path:e}}function lW(e){let t=e.match(H3s);if(!t)return{path:e};let s=t[1].toLowerCase();if(rBr.has(s))return{path:e};if(!oBr[s])return{path:e};let n=t[0].length;if(s==="ssh"&&e.indexOf("/",n)===-1)return{path:e};let o=e,r=[];while(!0){let i=o.lastIndexOf(":");if(i<n)break;let a=o.slice(i+1);if(!nBr.test(a))break;r.unshift(a),o=o.slice(0,i)}if(r.length===0)return{path:e};return{path:o,sel:r.join(":")}}function W3s(e){let{path:t,sel:s}=lW(e);if(s===void 0)return e;if(/^(?:raw|conflicts)$/i.test(s))return t;throw new X(`write does not accept the trailing selector ":${s}" \u2014 it writes a whole file. `+`Remove ":${s}", or if the filename truly ends with it, percent-encode the ":" as %3A.`)}function yBr(e,t){for(let s of rht)if(e.startsWith(s))throw Error(`Path "${t}" uses internal scheme "${s}" and must be resolved through the proper protocol handler, not as a filesystem path.`)}function Nr(e){return e.replace(/^(local:)\/(?!\/)/,"$1//")}function $d(e){let t=Nr(e),s=Nr(IC(t));for(let n of rht)if(s.startsWith(n))return!0;return!1}function FPe(e){let t=Nr(IC(Nr(e)));if(!rht.some((o)=>t.startsWith(o)))return"write";let s=H3s.exec(t)?.[1]?.toLowerCase();return(s?Mi.instance().getHandler(s):void 0)?.write?"write":"read"}function s6(e){return/ssh:\/\//i.test(e)}function iht(e){return/^ssh:\/\//i.test(e.trim())}function uW(e){return/^https?:\/\/?/i.test(e)||/^www\./i.test(e)}function Cs(e,t){let s=Nr(e),n=mBr(IC(s)),o=Nr(n);if(yBr(o,s),/^\/+$/.test(n))return t;if(un.isAbsolute(n))return n;return un.resolve(t,n)}function G3s(e,t){if(!e||un.isAbsolute(e))return null;if(e.startsWith("~")||$d(e))return null;let s=un.resolve(t),n=un.resolve(s,e);if(!IPe(n,s))return null;let o=tht(s);if(!o)return null;let r=tht(n);if(r)return IPe(r,o)?n:null;if(RBr(n))return null;let i=un.dirname(n),a=[un.basename(n)];for(;;){let l=tht(i);if(l)return IPe(un.join(l,...a.reverse()),o)?n:null;let u=un.dirname(i);if(u===i||!IPe(i,s))return null;a.push(un.basename(i)),i=u}}function IPe(e,t){let s=un.relative(t,e);return!!s&&!s.startsWith("..")&&!un.isAbsolute(s)}function tht(e){try{return sd.realpathSync.native(e)}catch{return null}}function RBr(e){try{return sd.lstatSync(e).isSymbolicLink()}catch{return!1}}async function aht(e,t){let s=un.resolve(e);if(t){let r=await _3s(s);if(r!==null)return r;if(!await L3s(s))return null}let n=[un.basename(s)],o=un.dirname(s);for(;;){let r=await _3s(o);if(r!==null)return un.join(r,...n.reverse());if(!await L3s(o))return null;let i=un.dirname(o);if(i===o)return null;n.push(un.basename(o)),o=i}}async function _3s(e){try{return await sd.promises.realpath(e)}catch{return null}}async function L3s(e){try{return!(await sd.promises.lstat(e)).isSymbolicLink()}catch(t){return pe(t)}}function Ys(e,t,s={}){let n=un.resolve(t),o=Nr(e);if($d(o))return o;let r=IC(o),i=un.isAbsolute(r)?un.resolve(r):un.resolve(t,r),a=un.relative(n,i),l=a===""||!a.startsWith("..")&&!un.isAbsolute(a),u=e6(l?a||".":i);if(s.trailingSlash&&u!=="."&&!u.endsWith("/"))u+="/";return u}function lht(e){return e.startsWith('"')&&e.endsWith('"')&&e.length>1?e.slice(1,-1):e}function uht(e){if($d(e))return e;if(!e.includes("\\"))return e;return e.replace(/\\/g,"/")}function aD(e){return lht(e.trim())}function CBr(e){let t=e.trim();if(!t.startsWith("[")||!t.endsWith("]"))return null;let s;try{s=JSON.parse(t)}catch{return null}if(!Array.isArray(s)||s.some((n)=>typeof n!=="string"))return null;return s}function ay(e){if(typeof e==="string")return CBr(e)??[e];return e??[]}function kS(e){return bBr.some((t)=>e.includes(t))}function kBr(e,t){if(t==="comma")return e===",";if(t==="semicolon")return e===";";if(t==="whitespace")return nht.test(e);return e===","||e===";"||nht.test(e)}function SBr(e){let t=0;for(let s=0;s<e.length;s++){let n=e[s];if(n==="\\"&&s+1<e.length){s++;continue}if(n==="{"){t++;continue}if(n==="}"){if(t>0)t--;continue}if(t===0&&(n===","||n===";"||nht.test(n)))return!0}return!1}function wBr(e,t){let s=[],n=0,o=0;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"&&r+1<e.length){r++;continue}if(i==="{"){n++;continue}if(i==="}"){if(n>0)n--;continue}if(n!==0||!kBr(i,t))continue;s.push(e.slice(o,r)),o=r+1}return s.push(e.slice(o)),s}async function j3s(e,t,s){if($d(e))return!0;let n=Ha(e).path,{basePath:o}=s(n),r=Cs(o,t);try{return await sd.promises.stat(r),!0}catch(i){if(pe(i)||xl(i,"ENAMETOOLONG"))return!1;throw i}}async function Wie(e,t,s,n,o){let r=wBr(e,n);if(r.length<2)return null;let i=r.map(aD).filter((a)=>a.length>0);if(i.length===0)return null;if(i.length<2&&r.length===i.length)return null;if(o!=="none"){let a=await Promise.all(i.map((u)=>j3s(u,t,s)));if(!(o==="all"?a.every(Boolean):a.some(Boolean)))return null}return i}async function pht(e,t,s={}){let n=aD(e);if(!SBr(n))return null;let o=s.splitter??OPe;if(s.routedUrlPredicate?.(n)){let i=await Wie(n,t,o,"semicolon","none");return i?.every(s.routedUrlPredicate)?i:null}if($d(n))return null;if(await iD(n,t)!=="missing")return null;let r=Ha(n).path;if(!kS(r)&&await j3s(n,t,o))return null;return await Wie(n,t,o,"semicolon","none")??await Wie(n,t,o,"comma","some")??await Wie(n,t,o,"whitespace","all")??await Wie(n,t,o,"mixed","all")}async function jie(e,t,s={}){let n=[];for(let o of e){let r=aD(o),i=await pht(r,t,s);if(i)n.push(...i);else n.push(r)}return n}function OPe(e){let t=uht(e),s=t.split("/"),n=-1;for(let o=0;o<s.length;o++)if(kS(s[o])){n=o;break}if(n===-1)return{basePath:t};if(n<=0)return{basePath:".",glob:t};return{basePath:s.slice(0,n).join("/"),glob:s.slice(n).join("/")}}async function $3s(e,t){if(!kS(e)||$d(e))return OPe(e);try{return await sd.promises.stat(Cs(e,t)),{basePath:uht(e)}}catch{return OPe(e)}}function $ie(e){let t=uht(e),s=t.split("/"),n=-1;for(let o=0;o<s.length;o++)if(kS(s[o])){n=o;break}if(n===-1)return{basePath:t,globPattern:"**/*",hasGlob:!1};if(n===0)return{basePath:".",globPattern:!t.startsWith("**/")?`**/${t}`:t,hasGlob:!0};return{basePath:s.slice(0,n).join("/"),globPattern:s.slice(n).join("/"),hasGlob:!0}}function sht(e,t){if(!e)return t;if(!t)return e;let s=e.replace(/\/+$/,""),n=t.replace(/^\/+/,"");return`${s}/${n}`}function e6(e){return e.replace(/\\/g,"/")}function D3s(e,t){if(!e||e===".")return e6(t).replace(/^\/+/,"");let s=e6(e).replace(/\/+$/,""),n=e6(t).replace(/^\/+/,"");return`${s}/${n}`}function xBr(e){let t=[...new Set(e.map((s)=>e6(s).trim()).filter(Boolean))];if(t.length===0)return;if(t.length===1)return t[0];return`{${t.join(",")}}`}function EBr(e){if(e.length===0)return".";let t=un.resolve(e[0]).split(un.sep);for(let n of e.slice(1)){let o=un.resolve(n).split(un.sep),r=0,i=Math.min(t.length,o.length);while(r<i&&t[r]===o[r])r+=1;t=t.slice(0,r)}if(t.length===0)return un.parse(un.resolve(e[0])).root;return t.join(un.sep)||un.parse(un.resolve(e[0])).root}function z3s(e,t){return e.map((s)=>Ys(s,t,{trailingSlash:s.endsWith("/")||s.endsWith("\\")})).join(", ")}async function MBr(e,t,s,n=!1){if(e.length<1)return;let o=await Promise.all(e.map(async(c)=>{let d=await $3s(c,t),f=Cs(d.basePath,t),m=await sd.promises.stat(f);return{raw:c,parsedPath:d,absoluteBasePath:f,stat:m}})),r=!s&&o.every((c)=>!c.parsedPath.glob&&c.stat.isFile()),i=EBr(o.map((c)=>c.absoluteBasePath)),a=o.map((c)=>{let d=e6(un.relative(i,c.absoluteBasePath))||".";if(c.parsedPath.glob){let f=D3s(d,c.parsedPath.glob);return sht(f,s)??f}if(s)return sht(d==="."?void 0:d,s)??s;if(c.stat.isDirectory())return D3s(d,"**/*");return d==="."?un.basename(c.absoluteBasePath):d}),l=o.some((c)=>c.absoluteBasePath===i),u=n&&!r&&o.some((c)=>!c.parsedPath.glob&&c.stat.isFile()),p=o.length>1&&(!l||u)?o.map((c)=>({basePath:c.absoluteBasePath,glob:c.parsedPath.glob?sht(c.parsedPath.glob,s):s})):void 0;return{basePath:i,glob:xBr(a),scopePath:z3s(e,t),exactFilePaths:r?o.map((c)=>c.absoluteBasePath):void 0,targets:p}}async function ABr(e,t,s,n=!1){return MBr([...new Set(e)],t,s,n)}async function vBr(e,t){if(e.length<=1)return;return{targets:e.map((n)=>{let o=$ie(n);return{basePath:Cs(o.basePath,t),globPattern:o.globPattern,hasGlob:o.hasGlob}}),scopePath:z3s(e,t)}}async function K3s(e,t){return vBr([...new Set(e)],t)}async function cht(e,t,s){let n=await Promise.all(e.map(async(i)=>{let{basePath:a}=s(i),l=Cs(a,t);try{return await sd.promises.stat(l),{item:i,exists:!0}}catch(u){if(pe(u))return{item:i,exists:!1};throw u}})),o=[],r=[];for(let i of n)if(i.exists)o.push(i.item);else r.push(i.item);return{valid:o,missing:r}}function lu(e,t){let s=Cs(e,t),n=pBr(s),o=n!==s?[s,n]:[s];for(let r of o)if(Bie(r))return r;for(let r of o){let i=lBr(r);if(i!==r&&Bie(i))return i;let a=uBr(r);if(a!==r&&Bie(a))return a;let l=P3s(r);if(l!==r&&Bie(l))return l;let u=P3s(a);if(u!==r&&Bie(u))return u}return s}function IBr(e){return e.replace(/[*?[{]/g,"[$&]")}async function OBr(e,t,s,n){let o=e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/+$/,"");if(!o)return null;let r=AbortSignal.timeout(N3s),i=s?AbortSignal.any([s,r]):r,a;try{let l=await n({pattern:`**/${IBr(o)}`,path:t,hidden:!0,signal:i,timeoutMs:N3s});if(s?.aborted)throw new Ke;a=l.matches.map((u)=>u.path)}catch{if(s?.aborted)throw new Ke;return null}if(a.length!==1)return null;return{absolutePath:un.resolve(t,a[0]),displayPath:a[0]}}async function _Pe(e,t,s){return OBr(e,t,s,eBr)}async function n6(e){let{rawPaths:t,cwd:s,internalUrlAction:n}=e,o=t.map(aD);if(o.some((y)=>y.length===0))throw new X("Search scope entries must be non-empty paths or globs");let r=await jie(o,s);if(r.some((y)=>y.length===0))throw new X("Search scope entries must be non-empty paths or globs");let i=/^(?:https?|ftp|ws|wss):\/\//i,a=Mi.instance(),l=[],u=new Set;for(let y of r){let R=i.test(y);if(!R&&uW(y)&&!kS(y))try{await sd.promises.stat(Cs(y,s))}catch(b){R=pe(b)||CP(b)}if(R){let b=e.resolveExternalUrl?await e.resolveExternalUrl(y):void 0;if(b){if(l.push(b.sourcePath),e.trackImmutableSources&&b.immutable)u.add(un.resolve(b.sourcePath));continue}throw new X(`Cannot ${n} external URL: ${y}. Use \`read\` to fetch web content, then search the returned text.`)}if(!a.canHandle(y)){l.push(y);continue}if(iht(y))throw new X(`Cannot ${n} a remote ssh:// path (no local file): ${y}. Use \`read ${y}\` to view it, or use \`grep\` on a specific remote file.`);if(kS(y))throw new X(`Glob patterns are not supported for internal URLs: ${y}`);let C=await a.resolve(y,{cwd:s,settings:e.settings,signal:e.signal,sessionFile:e.sessionFile,localProtocolOptions:e.localProtocolOptions,skills:e.skills,pathOnly:!0});if(!C.sourcePath)throw new X(`Cannot ${n} internal URL without a backing file: ${y}`);if(e.trackImmutableSources&&C.immutable)u.add(un.resolve(C.sourcePath));l.push(C.sourcePath)}let p=[],c=l;if(l.length>1){let y=await cht(l,s,OPe);if(y.valid.length===0)throw new X(`Path not found: ${y.missing.join(", ")}`);c=y.valid,p=y.missing}let d,f,m,g,h;if(c.length===1){let y=await $3s(c[0]??".",s);d=Cs(y.basePath,s),m=y.glob,f=Ys(d,s)}else{let y=await ABr(c,s,void 0,e.fanOutFileTargets===!0);if(!y)throw new X("`paths` must contain at least one path or glob");if(d=y.basePath,g=y.targets,e.surfaceExactFilePaths)h=y.exactFilePaths,m=h||g?void 0:y.glob;else m=g?void 0:y.glob;f=y.scopePath}let T;try{T=(await Bun.file(d).stat()).isDirectory()}catch{let y=e.multipathStatHint&&r.length>1?e.multipathStatHint:"";throw new X(`Path not found: ${f}${y}`)}return{searchPath:d,scopePath:f,globFilter:m,isDirectory:T,multiTargets:g,exactFilePaths:h,missingPaths:p,immutableSourcePaths:u}}var tBr,v3s,oht,sBr,I3s,O3s,nBr,oBr,rBr,H3s,iBr="\u202F",rht,gBr,bBr,nht,N3s=5000;var hs=S(()=>{B();ru();Mt();tBr=/[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;v3s=String.raw`L?\d+(?:(?:[-+]|\.\.)L?\d+|-|\.\.)?`,oht=`${v3s}(?:,${v3s})*`,sBr=new RegExp(`^(?:${oht}|raw|conflicts|img)$`,"i"),I3s=new RegExp(`^${oht}$`,"i"),O3s=/^raw$/i,nBr=new RegExp(String.raw`^(?:raw|conflicts|img|${oht}|-\d+(?:[-+]\d+)?)$`,"i"),oBr={agent:!0,artifact:!0,issue:!0,history:!0,local:!0,memory:!0,omp:!0,pr:!0,rule:!0,security:!0,skill:!0,ssh:!0,vault:!0},rBr=new Set(["mcp"]),H3s=/^([a-z][a-z0-9+.-]*):\/\//i,rht=["agent://","artifact://","skill://","rule://","security://","local://","mcp://","ssh://","vault://"];gBr=/^L?(\d+)(?:(\.\.|[-+])L?(\d+)?)?$/i;bBr=["*","?","[","{"];nht=/\s/});var o6;var LPe=S(()=>{o6={type:"module",name:"@oh-my-pi/pi-coding-agent",version:"18.1.0",description:"Coding agent CLI with read, bash, edit, write tools and session management",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Mario Zechner"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/coding-agent"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["coding-agent","ai","llm","cli","tui","agent"],main:"./src/index.ts",types:"./dist/types/index.d.ts",bin:{omp:"dist/cli.js"},scripts:{build:"bun scripts/build-binary.ts",check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun ../../scripts/ci-test-ts.ts coding-agent-heavy --full",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run format-prompts","format-prompts":"bun scripts/format-prompts.ts","gen:tool-views":"bun --cwd=../collab-web run gen:tool-views","gen:bundle":"bun scripts/bundle-dist.ts","gen:native":"bun --cwd=../natives run gen:native","gen:native:reset":"bun --cwd=../natives run gen:native:reset",prepack:"bun run gen:tool-views && bun run gen:bundle","bench:guard":"bun scripts/bench-guard.ts"},dependencies:{"@babel/parser":"catalog:","@oh-my-pi/hashline":"catalog:","@oh-my-pi/omp-stats":"catalog:","@oh-my-pi/omptype":"catalog:","@oh-my-pi/pi-agent-core":"catalog:","@oh-my-pi/pi-ai":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-mnemopi":"catalog:","@oh-my-pi/pi-natives":"catalog:","@oh-my-pi/pi-tui":"catalog:","@oh-my-pi/pi-utils":"catalog:","@oh-my-pi/pi-wire":"catalog:","@oh-my-pi/snapcompact":"catalog:","@opentelemetry/api":"catalog:","@opentelemetry/api-logs":"catalog:","@opentelemetry/context-async-hooks":"catalog:","@opentelemetry/exporter-logs-otlp-proto":"catalog:","@opentelemetry/exporter-metrics-otlp-proto":"catalog:","@opentelemetry/exporter-trace-otlp-proto":"catalog:","@opentelemetry/resources":"catalog:","@opentelemetry/sdk-logs":"catalog:","@opentelemetry/sdk-metrics":"catalog:","@opentelemetry/sdk-trace-base":"catalog:","@opentelemetry/sdk-trace-node":"catalog:","puppeteer-core":"catalog:"},optionalDependencies:{"@huggingface/transformers":"catalog:","sherpa-onnx-node":"1.13.2"},devDependencies:{"@types/bun":"catalog:"},engines:{bun:">=1.3.14"},files:["src","dist/cli.js","dist/docs-index.generated.txt","dist/CHANGELOG-*.md","dist/*.node","dist/template-*.css","dist/template-*.html","dist/template-*.js","dist/tool-views.generated-*.js","scripts","examples","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./async":{types:"./dist/types/async/index.d.ts",import:"./src/async/index.ts"},"./async/*":{types:"./dist/types/async/*.d.ts",import:"./src/async/*.ts"},"./autoresearch":{types:"./dist/types/autoresearch/index.d.ts",import:"./src/autoresearch/index.ts"},"./autoresearch/*":{types:"./dist/types/autoresearch/*.d.ts",import:"./src/autoresearch/*.ts"},"./autoresearch/tools/*":{types:"./dist/types/autoresearch/tools/*.d.ts",import:"./src/autoresearch/tools/*.ts"},"./capability":{types:"./dist/types/capability/index.d.ts",import:"./src/capability/index.ts"},"./capability/*":{types:"./dist/types/capability/*.d.ts",import:"./src/capability/*.ts"},"./cli/*":{types:"./dist/types/cli/*.d.ts",import:"./src/cli/*.ts"},"./cli/gallery-fixtures":{types:"./dist/types/cli/gallery-fixtures/index.d.ts",import:"./src/cli/gallery-fixtures/index.ts"},"./cli/gallery-fixtures/*":{types:"./dist/types/cli/gallery-fixtures/*.d.ts",import:"./src/cli/gallery-fixtures/*.ts"},"./cli/commands/*":{types:"./dist/types/cli/commands/*.d.ts",import:"./src/cli/commands/*.ts"},"./commands/*":{types:"./dist/types/commands/*.d.ts",import:"./src/commands/*.ts"},"./commit":{types:"./dist/types/commit/index.d.ts",import:"./src/commit/index.ts"},"./commit/*":{types:"./dist/types/commit/*.d.ts",import:"./src/commit/*.ts"},"./commit/agentic":{types:"./dist/types/commit/agentic/index.d.ts",import:"./src/commit/agentic/index.ts"},"./commit/agentic/*":{types:"./dist/types/commit/agentic/*.d.ts",import:"./src/commit/agentic/*.ts"},"./commit/agentic/tools":{types:"./dist/types/commit/agentic/tools/index.d.ts",import:"./src/commit/agentic/tools/index.ts"},"./commit/agentic/tools/*":{types:"./dist/types/commit/agentic/tools/*.d.ts",import:"./src/commit/agentic/tools/*.ts"},"./commit/analysis":{types:"./dist/types/commit/analysis/index.d.ts",import:"./src/commit/analysis/index.ts"},"./commit/analysis/*":{types:"./dist/types/commit/analysis/*.d.ts",import:"./src/commit/analysis/*.ts"},"./commit/changelog":{types:"./dist/types/commit/changelog/index.d.ts",import:"./src/commit/changelog/index.ts"},"./commit/changelog/*":{types:"./dist/types/commit/changelog/*.d.ts",import:"./src/commit/changelog/*.ts"},"./commit/conventional":{types:"./dist/types/commit/conventional/index.d.ts",import:"./src/commit/conventional/index.ts"},"./commit/conventional/*":{types:"./dist/types/commit/conventional/*.d.ts",import:"./src/commit/conventional/*.ts"},"./commit/git/*":{types:"./dist/types/commit/git/*.d.ts",import:"./src/commit/git/*.ts"},"./commit/utils/*":{types:"./dist/types/commit/utils/*.d.ts",import:"./src/commit/utils/*.ts"},"./config/*":{types:"./dist/types/config/*.d.ts",import:"./src/config/*.ts"},"./dap":{types:"./dist/types/dap/index.d.ts",import:"./src/dap/index.ts"},"./dap/*":{types:"./dist/types/dap/*.d.ts",import:"./src/dap/*.ts"},"./debug":{types:"./dist/types/debug/index.d.ts",import:"./src/debug/index.ts"},"./debug/*":{types:"./dist/types/debug/*.d.ts",import:"./src/debug/*.ts"},"./discovery":{types:"./dist/types/discovery/index.d.ts",import:"./src/discovery/index.ts"},"./discovery/*":{types:"./dist/types/discovery/*.d.ts",import:"./src/discovery/*.ts"},"./edit":{types:"./dist/types/edit/index.d.ts",import:"./src/edit/index.ts"},"./edit/*":{types:"./dist/types/edit/*.d.ts",import:"./src/edit/*.ts"},"./edit/modes/*":{types:"./dist/types/edit/modes/*.d.ts",import:"./src/edit/modes/*.ts"},"./exa":{types:"./dist/types/exa/index.d.ts",import:"./src/exa/index.ts"},"./exa/*":{types:"./dist/types/exa/*.d.ts",import:"./src/exa/*.ts"},"./exec/*":{types:"./dist/types/exec/*.d.ts",import:"./src/exec/*.ts"},"./export/*":{types:"./dist/types/export/*.d.ts",import:"./src/export/*.ts"},"./export/html":{types:"./dist/types/export/html/index.d.ts",import:"./src/export/html/index.ts"},"./export/html/*":{types:"./dist/types/export/html/*.d.ts",import:"./src/export/html/*.ts"},"./extensibility/*":{types:"./dist/types/extensibility/*.d.ts",import:"./src/extensibility/*.ts"},"./extensibility/custom-commands":{types:"./dist/types/extensibility/custom-commands/index.d.ts",import:"./src/extensibility/custom-commands/index.ts"},"./extensibility/custom-commands/*":{types:"./dist/types/extensibility/custom-commands/*.d.ts",import:"./src/extensibility/custom-commands/*.ts"},"./extensibility/custom-commands/bundled/ci-green":{types:"./dist/types/extensibility/custom-commands/bundled/ci-green/index.d.ts",import:"./src/extensibility/custom-commands/bundled/ci-green/index.ts"},"./extensibility/custom-commands/bundled/review":{types:"./dist/types/extensibility/custom-commands/bundled/review/index.d.ts",import:"./src/extensibility/custom-commands/bundled/review/index.ts"},"./extensibility/custom-tools":{types:"./dist/types/extensibility/custom-tools/index.d.ts",import:"./src/extensibility/custom-tools/index.ts"},"./extensibility/custom-tools/*":{types:"./dist/types/extensibility/custom-tools/*.d.ts",import:"./src/extensibility/custom-tools/*.ts"},"./extensibility/extensions":{types:"./dist/types/extensibility/extensions/index.d.ts",import:"./src/extensibility/extensions/index.ts"},"./extensibility/extensions/*":{types:"./dist/types/extensibility/extensions/*.d.ts",import:"./src/extensibility/extensions/*.ts"},"./extensibility/hooks":{types:"./dist/types/extensibility/hooks/index.d.ts",import:"./src/extensibility/hooks/index.ts"},"./extensibility/hooks/*":{types:"./dist/types/extensibility/hooks/*.d.ts",import:"./src/extensibility/hooks/*.ts"},"./extensibility/plugins":{types:"./dist/types/extensibility/plugins/index.d.ts",import:"./src/extensibility/plugins/index.ts"},"./extensibility/plugins/*":{types:"./dist/types/extensibility/plugins/*.d.ts",import:"./src/extensibility/plugins/*.ts"},"./extensibility/plugins/marketplace":{types:"./dist/types/extensibility/plugins/marketplace/index.d.ts",import:"./src/extensibility/plugins/marketplace/index.ts"},"./extensibility/plugins/marketplace/*":{types:"./dist/types/extensibility/plugins/marketplace/*.d.ts",import:"./src/extensibility/plugins/marketplace/*.ts"},"./internal-urls":{types:"./dist/types/internal-urls/index.d.ts",import:"./src/internal-urls/index.ts"},"./internal-urls/*":{types:"./dist/types/internal-urls/*.d.ts",import:"./src/internal-urls/*.ts"},"./eval":{types:"./dist/types/eval/index.d.ts",import:"./src/eval/index.ts"},"./if-bench":{types:"./dist/types/if-bench/index.d.ts",import:"./src/if-bench/index.ts"},"./if-bench/*":{types:"./dist/types/if-bench/*.d.ts",import:"./src/if-bench/*.ts"},"./eval/js/*":{types:"./dist/types/eval/js/*.d.ts",import:"./src/eval/js/*.ts"},"./eval/py/*":{types:"./dist/types/eval/py/*.d.ts",import:"./src/eval/py/*.ts"},"./lsp":{types:"./dist/types/lsp/index.d.ts",import:"./src/lsp/index.ts"},"./lsp/*":{types:"./dist/types/lsp/*.d.ts",import:"./src/lsp/*.ts"},"./lsp/clients":{types:"./dist/types/lsp/clients/index.d.ts",import:"./src/lsp/clients/index.ts"},"./lsp/clients/*":{types:"./dist/types/lsp/clients/*.d.ts",import:"./src/lsp/clients/*.ts"},"./markit":{types:"./dist/types/markit/index.d.ts",import:"./src/markit/index.ts"},"./markit/*":{types:"./dist/types/markit/*.d.ts",import:"./src/markit/*.ts"},"./mcp":{types:"./dist/types/mcp/index.d.ts",import:"./src/mcp/index.ts"},"./mcp/*":{types:"./dist/types/mcp/*.d.ts",import:"./src/mcp/*.ts"},"./mcp/transports":{types:"./dist/types/mcp/transports/index.d.ts",import:"./src/mcp/transports/index.ts"},"./mcp/transports/*":{types:"./dist/types/mcp/transports/*.d.ts",import:"./src/mcp/transports/*.ts"},"./memories":{types:"./dist/types/memories/index.d.ts",import:"./src/memories/index.ts"},"./memories/*":{types:"./dist/types/memories/*.d.ts",import:"./src/memories/*.ts"},"./memory-backend":{types:"./dist/types/memory-backend/index.d.ts",import:"./src/memory-backend/index.ts"},"./memory-backend/*":{types:"./dist/types/memory-backend/*.d.ts",import:"./src/memory-backend/*.ts"},"./hindsight":{types:"./dist/types/hindsight/index.d.ts",import:"./src/hindsight/index.ts"},"./hindsight/*":{types:"./dist/types/hindsight/*.d.ts",import:"./src/hindsight/*.ts"},"./modes":{types:"./dist/types/modes/index.d.ts",import:"./src/modes/index.ts"},"./modes/*":{types:"./dist/types/modes/*.d.ts",import:"./src/modes/*.ts"},"./modes/acp":{types:"./dist/types/modes/acp/index.d.ts",import:"./src/modes/acp/index.ts"},"./modes/acp/*":{types:"./dist/types/modes/acp/*.d.ts",import:"./src/modes/acp/*.ts"},"./modes/components":{types:"./dist/types/modes/components/index.d.ts",import:"./src/modes/components/index.ts"},"./modes/components/*":{types:"./dist/types/modes/components/*.d.ts",import:"./src/modes/components/*.ts"},"./modes/components/extensions":{types:"./dist/types/modes/components/extensions/index.d.ts",import:"./src/modes/components/extensions/index.ts"},"./modes/components/extensions/*":{types:"./dist/types/modes/components/extensions/*.d.ts",import:"./src/modes/components/extensions/*.ts"},"./modes/components/status-line":{types:"./dist/types/modes/components/status-line/index.d.ts",import:"./src/modes/components/status-line/index.ts"},"./modes/components/status-line/*":{types:"./dist/types/modes/components/status-line/*.d.ts",import:"./src/modes/components/status-line/*.ts"},"./modes/controllers/*":{types:"./dist/types/modes/controllers/*.d.ts",import:"./src/modes/controllers/*.ts"},"./modes/setup-wizard":{types:"./dist/types/modes/setup-wizard/index.d.ts",import:"./src/modes/setup-wizard/index.ts"},"./modes/setup-wizard/*":{types:"./dist/types/modes/setup-wizard/*.d.ts",import:"./src/modes/setup-wizard/*.ts"},"./modes/rpc/*":{types:"./dist/types/modes/rpc/*.d.ts",import:"./src/modes/rpc/*.ts"},"./modes/theme/*":{types:"./dist/types/modes/theme/*.d.ts",import:"./src/modes/theme/*.ts"},"./modes/theme/defaults":{types:"./dist/types/modes/theme/defaults/index.d.ts",import:"./src/modes/theme/defaults/index.ts"},"./modes/utils/*":{types:"./dist/types/modes/utils/*.d.ts",import:"./src/modes/utils/*.ts"},"./plan-mode/*":{types:"./dist/types/plan-mode/*.d.ts",import:"./src/plan-mode/*.ts"},"./prompts/*":"./src/prompts/*.md","./registry/*":{types:"./dist/types/registry/*.d.ts",import:"./src/registry/*.ts"},"./secrets":{types:"./dist/types/secrets/index.d.ts",import:"./src/secrets/index.ts"},"./secrets/*":{types:"./dist/types/secrets/*.d.ts",import:"./src/secrets/*.ts"},"./session/*":{types:"./dist/types/session/*.d.ts",import:"./src/session/*.ts"},"./slash-commands/*":{types:"./dist/types/slash-commands/*.d.ts",import:"./src/slash-commands/*.ts"},"./ssh/*":{types:"./dist/types/ssh/*.d.ts",import:"./src/ssh/*.ts"},"./stt":{types:"./dist/types/stt/index.d.ts",import:"./src/stt/index.ts"},"./stt/*":{types:"./dist/types/stt/*.d.ts",import:"./src/stt/*.ts"},"./task":{types:"./dist/types/task/index.d.ts",import:"./src/task/index.ts"},"./task/*":{types:"./dist/types/task/*.d.ts",import:"./src/task/*.ts"},"./tools":{types:"./dist/types/tools/index.d.ts",import:"./src/tools/index.ts"},"./tools/hub":{types:"./dist/types/tools/hub/index.d.ts",import:"./src/tools/hub/index.ts"},"./tools/hub/*":{types:"./dist/types/tools/hub/*.d.ts",import:"./src/tools/hub/*.ts"},"./tools/*":{types:"./dist/types/tools/*.d.ts",import:"./src/tools/*.ts"},"./tui":{types:"./dist/types/tui/index.d.ts",import:"./src/tui/index.ts"},"./tui/*":{types:"./dist/types/tui/*.d.ts",import:"./src/tui/*.ts"},"./utils/*":{types:"./dist/types/utils/*.d.ts",import:"./src/utils/*.ts"},"./web/*":{types:"./dist/types/web/*.d.ts",import:"./src/web/*.ts"},"./web/scrapers":{types:"./dist/types/web/scrapers/index.d.ts",import:"./src/web/scrapers/index.ts"},"./web/scrapers/*":{types:"./dist/types/web/scrapers/*.d.ts",import:"./src/web/scrapers/*.ts"},"./web/search":{types:"./dist/types/web/search/index.d.ts",import:"./src/web/search/index.ts"},"./web/search/*":{types:"./dist/types/web/search/*.d.ts",import:"./src/web/search/*.ts"},"./web/search/providers/*":{types:"./dist/types/web/search/providers/*.d.ts",import:"./src/web/search/providers/*.ts"},"./*.js":"./src/*.ts"}}});import*as ly from"fs/promises";import*as zie from"path";function Y3s(e,t){let n=(t.trim().toLowerCase().replace(/^\.+/,"")||"bin").replace(/[^a-z0-9]+/g,"_")||"bin",o=o6.version.replace(/[^a-z0-9]+/gi,"_"),r=new Bun.CryptoHasher("sha256").update(e).digest("hex");return`v${DPe}-${o}-${n}-${r}`}function _Br(e){return zie.join(FVe(),`${e}.json`)}function pW(e){return e instanceof Error?e.message:String(e)}function LBr(e){let t=JSON.parse(e);if(typeof t!=="object"||t===null)return null;if(!("version"in t)||t.version!==DPe)return null;if(!("content"in t)||typeof t.content!=="string"||t.content.length===0)return null;return{version:DPe,content:t.content}}async function J3s(e){let t=_Br(e),s;try{s=await Bun.file(t).text()}catch(o){if(!pe(o))v.debug("document conversion cache read failed",{error:pW(o)});return{status:"miss"}}let n;try{n=LBr(s)}catch(o){v.debug("document conversion cache read failed",{error:pW(o)}),n=null}if(!n)return await ly.rm(t,{force:!0}).catch(()=>{return}),{status:"miss"};return{status:"hit",content:n.content}}async function DBr(e){let t;try{t=await ly.readdir(e)}catch(r){if(!pe(r))v.debug("document conversion cache prune failed",{error:pW(r)});return}let s=Date.now(),n=[],o=0;for(let r of t){let i=zie.join(e,r),a;try{a=await ly.stat(i)}catch(l){if(!pe(l))v.debug("document conversion cache prune failed",{error:pW(l)});continue}if(!a.isFile())continue;if(r.endsWith(".tmp")){if(s-a.mtimeMs>FBr)await ly.rm(i,{force:!0}).catch(()=>{return});continue}if(!r.endsWith(".json"))continue;n.push({path:i,size:a.size,mtimeMs:a.mtimeMs}),o+=a.size}if(o<=V3s)return;n.sort((r,i)=>r.mtimeMs-i.mtimeMs);for(let r of n){if(o<=V3s)break;try{await ly.rm(r.path,{force:!0}),o-=r.size}catch(i){if(!pe(i))v.debug("document conversion cache prune failed",{error:pW(i)})}}}async function X3s(e,t){let s=FVe(),n=zie.join(s,`${e}.json`),o=zie.join(s,`${e}.${process.pid}.${Date.now()}.${crypto.randomUUID()}.tmp`),r=JSON.stringify({version:DPe,content:t});try{await ly.mkdir(s,{recursive:!0}),await Bun.write(o,r),await ly.rename(o,n)}catch(i){await ly.rm(o,{force:!0}).catch(()=>{return}),v.debug("document conversion cache write failed",{error:pW(i)});return}DBr(s).catch((i)=>{v.debug("document conversion cache prune failed",{error:pW(i)})})}var DPe=1,V3s=268435456,FBr=300000;var Q3s=S(()=>{B();LPe()});var j;var Ur=S(()=>{j=class j extends Error{constructor(e){super(e);this.name="ArchiveError"}}});function xn(e,t){return e[t]|e[t+1]<<8}function Es(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function ZE(e,t){let s=Es(e,t)+Es(e,t+4)*4294967296;if(!Number.isSafeInteger(s))throw new j("Archive uses offsets or sizes too large to read safely");return s}function Kie(e,t){return e[t]<<8|e[t+1]}function kh(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function nd(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255}function dl(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24&255}function cW(e,t,s){dl(e,t,s>>>0),dl(e,t+4,Math.floor(s/4294967296))}function Ap(e,t,s){if(e.byteLength<t+s.length)return!1;for(let n=0;n<s.length;n++)if(e[t+n]!==s.charCodeAt(n))return!1;return!0}var r6;var Sh=S(()=>{Ur();r6=new TextDecoder});function zd(e){if(!e)return"";let t=e.replace(/\\/g,"/").split("/"),s=[];for(let n of t){if(!n||n===".")continue;if(n==="..")return;s.push(n)}return s.join("/")}function Sr(e){let t=e.replace(/\\/g,"/").split("/"),s=[];for(let n of t){if(!n||n===".")continue;if(n==="..")return;s.push(n)}if(s.length===0)return;return s.join("/")}function ejs(e){return e.endsWith("/")||e.endsWith("\\")}function dr(e){if(Buffer.byteLength(e,"utf-8")<=Z3s)return e;let t=0,s=0;for(let n of e){let o=Buffer.byteLength(n,"utf-8");if(s+o>Z3s-3)break;t+=n.length,s+=o}return`${e.slice(0,t)}...`}function ko(e,t,s){if(e>s)throw new j(`Archive ${t} exceeds ${s} bytes`)}function Kd(e,t,s){ko(Buffer.byteLength(e,"utf-8"),t,s)}var Z3s=256;var Vd=S(()=>{Ur()});function ci(e,t){if(!Number.isSafeInteger(e)||e<0)throw new j("Archive is too large to read safely");if(e>t.maxInMemorySize)throw new j(`Archive is too large to read in memory (${pt(e)} > ${pt(t.maxInMemorySize)} limit)`)}function Hn(e,t,s){if(!Number.isSafeInteger(e)||e<0)throw new j(`Invalid archive: ${s} has an invalid size`);if(e>t.maxIndexSize)throw new j(`Archive ${s} is too large (${pt(e)} > ${pt(t.maxIndexSize)} limit)`)}function Qi(e,t,s){if(!Number.isSafeInteger(e)||e<0)throw new j(`Archive member '${dr(t)}' has an invalid size`);if(e>s.maxMemberSize)throw new j(`Archive member '${dr(t)}' is too large to extract in memory (${pt(e)} > ${pt(s.maxMemberSize)} limit)`)}function or(e,t){if(e>t.maxEntries)throw new j(`Archive has too many entries (> ${t.maxEntries} limit)`)}var Vie;var vp=S(()=>{Ur();Vd();Vie={maxEntries:1e6,maxInMemorySize:268435456,maxIndexSize:67108864,maxMemberSize:67108864,maxPathBytes:4096,maxLinkDepth:40}});function yc(e,t){let s=e.get(t.path);if(!s)return e.set(t.path,t),t;if(s.isDirectory&&!t.isDirectory)return e.set(t.path,t),t;if(!s.isDirectory&&t.isDirectory)return;let n={...t,mtimeMs:t.mtimeMs??s.mtimeMs,mode:t.mode??s.mode,storage:t.storage??s.storage};return e.set(t.path,n),n}function lD(e,t){or(e.size,t);for(let s of Array.from(e.values())){let n=s.path.split("/"),o=n.length-1;for(let r=1;r<=o;r++){let i=n.slice(0,r).join("/");if(!i||e.has(i))continue;e.set(i,{path:i,isDirectory:!0,size:0}),or(e.size,t)}}}function dW(e,t,s){let n=t,o=new Set;for(let r=0;!o.has(n);){o.add(n);let i;for(let a=n.length;a>0;a=n.lastIndexOf("/",a-1)){let l=e.get(n.slice(0,a));if(l?.storage?.type!=="link"||!l.isDirectory&&!l.storage.resolveTarget)continue;let u=n.slice(a+1);i=u?l.storage.targetPath?`${l.storage.targetPath}/${u}`:u:l.storage.targetPath;break}if(i===void 0)return n;if(++r>s)break;n=i}throw new j(`Archive path '${t}' crosses a cyclic symlink`)}var uD=S(()=>{Ur();vp()});function NBr(e,t){throw new j(`Archive symlink '${dr(t)}' cannot be materialized from target '${dr(e)}'`)}class dht{format;limits;#e=new Map;constructor(e,t,s=Vie){this.format=e,this.limits=s;for(let n of t)yc(this.#e,n);lD(this.#e,s)}indexEntries(){return this.#e.values()}getNode(e){let t=zd(e);if(t===void 0)return;if(t==="")return{path:"",isDirectory:!0,size:0};let s=dW(this.#e,t,this.limits.maxLinkDepth);if(s==="")return{path:t,isDirectory:!0,size:0};let n=this.#e.get(s);if(!n)return;return{path:t,isDirectory:n.isDirectory,size:n.size,mtimeMs:n.mtimeMs,mode:n.mode}}listDirectory(e){let t=zd(e);if(t===void 0)throw new j("Archive path cannot contain '..'");let s=t?dW(this.#e,t,this.limits.maxLinkDepth):"";if(t&&s!==""){let r=this.#e.get(s);if(!r)throw new j(`Archive path '${t}' not found`);if(!r.isDirectory)throw new j(`Archive path '${t}' is not a directory`)}let n=s?`${s}/`:"",o=new Map;for(let r of this.#e.values()){if(s){if(!r.path.startsWith(n)||r.path===s)continue}let i=s?r.path.slice(n.length):r.path,a=i.split("/")[0];if(!a)continue;let l=t?`${t}/${a}`:a;if(o.has(l))continue;let u=s?`${s}/${a}`:a,p=dW(this.#e,u,this.limits.maxLinkDepth),c=p?this.#e.get(p):void 0,d=p===""||c?.isDirectory===!0||i.includes("/");o.set(l,{name:a,path:l,isDirectory:d,size:d?0:c?.size??r.size,mtimeMs:c?.mtimeMs??r.mtimeMs,mode:c?.mode??r.mode})}return[...o.values()].sort((r,i)=>r.name.toLowerCase().localeCompare(i.name.toLowerCase()))}async readFile(e){let t=zd(e);if(!t)throw new j("Archive file path is required");let s=dW(this.#e,t,this.limits.maxLinkDepth);if(s==="")throw new j(`Archive path '${t}' is a directory`);let n=this.#e.get(s);if(!n)throw new j(`Archive file '${t}' not found`);if(n.isDirectory)throw new j(`Archive path '${t}' is a directory`);if(!n.storage)throw new j(`Archive file '${t}' has no readable storage`);if(Qi(n.size,t,this.limits),n.storage.type==="link")NBr(n.storage.targetPath,t);let o=await n.storage.source.read(n.size,t);return{path:t,isDirectory:!1,size:n.size,mtimeMs:n.mtimeMs,mode:n.mode,bytes:o}}}var fht=S(()=>{uD();Ur();vp();Vd()});function Wi(e,t=0){return Bun.hash.crc32(e,t)>>>0}function njs(e,t=0n){let s=t^0xffffffffffffffffn,n=Number(s&0xffffffffn)>>>0,o=Number(s>>32n&0xffffffffn)>>>0;for(let r=0;r<e.length;r++){let i=(n^e[r])&255;n=((n>>>8|(o&255)<<24)>>>0^tjs[i])>>>0,o=(o>>>8^sjs[i])>>>0}return(BigInt(o)<<32n|BigInt(n))^0xffffffffffffffffn}function i6(e,t=0){let s=t;for(let n=0;n<e.length;n++)s=(s>>>8^ojs[(s^e[n])&255])&65535;return s}var tjs,sjs,ojs;var m0=S(()=>{tjs=new Uint32Array(256),sjs=new Uint32Array(256);for(let e=0;e<256;e++){let t=e,s=0;for(let n=0;n<8;n++){let o=(t&1)!==0;if(t=(t>>>1|(s&1)<<31)>>>0,s>>>=1,o)t=(t^3615952706)>>>0,s=(s^3379320725)>>>0}tjs[e]=t,sjs[e]=s}ojs=new Uint16Array(256);for(let e=0;e<256;e++){let t=e;for(let s=0;s<8;s++)t=(t&1)!==0?t>>>1^40961:t>>>1;ojs[e]=t}});function rjs(e,t){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<0||t<e)throw new j("Invalid archive range")}function ijs(e,t,s){if(rjs(t,s),s>e.byteLength)throw new j("Invalid archive: truncated data");return e.subarray(t,s)}function NPe(e){return{size:e.byteLength,async read(t,s){return ijs(e,t,s)}}}function mht(e){let t=Bun.file(e),s=t.size;if(!Number.isSafeInteger(s))throw new j("Archive is too large to read safely");return{size:s,async read(n,o){rjs(n,o);let r=await t.slice(n,o).bytes();if(r.byteLength!==o-n)throw new j("Invalid archive: truncated data");return r}}}async function eM(e){return e.read(0,e.size)}var tM=S(()=>{Ur()});class hht{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=t}read(e){if(!Number.isInteger(e)||e<0||e>24||this.#s+e>this.#e.byteLength*8)throw new j(`Invalid ${this.#t} compressed data: truncated bitstream`);let t=0;for(let s=0;s<e;s++){let n=this.#s++;t=t*2+(this.#e[n>>>3]>>>7-(n&7)&1)}return t}assertZeroPadding(){while(this.#s<this.#e.byteLength*8)if(this.read(1)!==0)throw new j(`Invalid ${this.#t} compressed data: non-zero trailing bits`)}}class h0{#e=[-1];#t=[-1];#s=[-1];#n;constructor(e){this.#n=e}static single(e,t,s){if(!Number.isInteger(e)||e<0||e>=t)throw new j(`Invalid ${s} Huffman table: symbol is out of range`);let n=new h0(s);return n.#s[0]=e,n}static build(e,t,s){let n=new Uint32Array(17),o=0;for(let l=0;l<t;l++){let u=e[l];if(u>16)throw new j(`Invalid ${s} Huffman table: code is too long`);if(u!==0)n[u]++,o=Math.max(o,u)}if(o===0)throw new j(`Invalid ${s} Huffman table: no symbols`);let r=new Uint32Array(17),i=0;for(let l=1;l<=16;l++){if(i=(i+n[l-1])*2,i+n[l]>2**l)throw new j(`Invalid ${s} Huffman table: oversubscribed codes`);r[l]=i}if(r[o]+n[o]!==2**o)throw new j(`Invalid ${s} Huffman table: incomplete codes`);let a=new h0(s);for(let l=0;l<t;l++){let u=e[l];if(u===0)continue;let p=r[u];r[u]=p+1;let c=0;for(let d=u-1;d>=0;d--){if(a.#s[c]>=0)throw new j(`Invalid ${s} Huffman table: prefix collision`);let f=p>>>d&1,m=f===0?a.#e[c]:a.#t[c];if(m<0)if(m=a.#s.length,a.#e.push(-1),a.#t.push(-1),a.#s.push(-1),f===0)a.#e[c]=m;else a.#t[c]=m;c=m}if(a.#s[c]>=0||a.#e[c]>=0||a.#t[c]>=0)throw new j(`Invalid ${s} Huffman table: duplicate code`);a.#s[c]=l}return a}decode(e){let t=0;for(let s=0;s<=16;s++){let n=this.#s[t];if(n>=0)return n;if(t=e.read(1)===0?this.#e[t]:this.#t[t],t<0)throw new j(`Invalid ${this.#n} Huffman code`)}throw new j(`Invalid ${this.#n} Huffman code: excessive depth`)}}function cjs(e,t){let s=e.read(3);if(s===7){while(e.read(1)!==0)if(s++,s>16)throw new j(`Invalid ${t} Huffman table: code is too long`)}return s}function HBr(e,t){let n=e.read(5);if(n===0)return h0.single(e.read(5),19,t);if(n>19)throw new j(`Invalid ${t} temporary Huffman table size`);let o=new Uint8Array(19),r=0;while(r<n)if(o[r++]=cjs(e,t),r===3){let i=e.read(2);if(r+i>n)throw new j(`Invalid ${t} temporary Huffman table`);r+=i}return h0.build(o,19,t)}function BBr(e,t,s){let o=e.read(9);if(o===0)return h0.single(e.read(9),510,s);if(o>510)throw new j(`Invalid ${s} command Huffman table size`);let r=new Uint8Array(510),i=0;while(i<o){let a=t.decode(e);if(a<=2){let l=a===0?1:a===1?e.read(4)+3:e.read(9)+20;if(i+l>o)throw new j(`Invalid ${s} command Huffman table`);i+=l}else r[i++]=a-2}return h0.build(r,510,s)}function WBr(e,t,s,n){let o=e.read(t);if(o===0)return h0.single(e.read(t),s,n);if(o>s)throw new j(`Invalid ${n} position Huffman table size`);let r=new Uint8Array(s);for(let i=0;i<o;i++)r[i]=cjs(e,n);return h0.build(r,s,n)}function a6(e,t,s,n,o,r){let i=new hht(e,r),a=new Uint8Array(t),l=0,u=0,p,c;while(l<t){if(u===0){if(u=i.read(16),u===0)throw new j(`Invalid ${r} compressed data: empty block`);let T=HBr(i,r);p=BBr(i,T,r),c=WBr(i,n,o,r)}u--;let d=p.decode(i);if(d<256){a[l++]=d;continue}let f=d-256+3;if(f>t-l)throw new j(`Invalid ${r} compressed data: match exceeds declared size`);let m=c.decode(i),g=m;if(m>1){let T=m-1;g=2**T+i.read(T)}if(g>=s||g>=l)throw new j(`Invalid ${r} compressed data: history distance is out of range`);let h=l-g-1;for(let T=0;T<f;T++)a[l++]=a[h++]}if(u!==0)throw new j(`Invalid ${r} compressed data: block exceeds declared size`);return i.assertZeroPadding(),a}function GBr(e,t){let s=new hht(e,"LZH -lzs-"),n=new Uint8Array(t),o=new Uint8Array(2048);o.fill(32);let r=2031,i=0,a=(l)=>{if(i>=t)throw new j("Invalid LZH -lzs- data: output exceeds declared size");n[i++]=l,o[r]=l,r=r+1&2047};while(i<t)if(s.read(1)!==0)a(s.read(8));else{let l=s.read(11),u=s.read(4)+2;if(u>t-i)throw new j("Invalid LZH -lzs- data: match exceeds declared size");for(let p=0;p<u;p++)a(o[l+p&2047])}return s.assertZeroPadding(),n}function $Br(e,t,s){if(t<0)return i6(e);let n=i6(e.subarray(0,t));return n=i6(jBr.subarray(0,s-t),n),i6(e.subarray(s),n)}function g0(e,t){return e[t]|e[t+1]<<8}function sM(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function ajs(e,t){let s=sM(e,t)+sM(e,t+4)*4294967296;if(!Number.isSafeInteger(s))throw new j("LZH uses sizes too large to read safely");return s}function Yie(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid LZH archive: truncated ${n}`)}function ght(e){let t=e.indexOf(0);if(t<0)t=e.byteLength;return qBr.decode(e.subarray(0,t))}function ljs(e){if((e.byteLength&1)!==0)throw new j("Invalid LZH Unicode path header: odd UTF-16 length");let t=e.byteLength;while(t>=2&&e[t-1]===0&&e[t-2]===0)t-=2;return UBr.decode(e.subarray(0,t))}function zBr(e){if(e===0)return;let t=1980+(e>>>25&127),s=e>>>21&15,n=e>>>16&31,o=e>>>11&31,r=e>>>5&63,i=(e&31)*2;if(s<1||s>12||n<1||n>31||o>23||r>59||i>59)return;return Date.UTC(t,s-1,n,o,r,i)}function ujs(e,t,s,n){switch(e){case 0:if(t.byteLength<2)throw new j("Invalid LZH common extended header");n.commonCrc=g0(t,0),n.commonCrcOffset=s;break;case 1:n.filename=ght(t);break;case 2:n.directory=ght(t).replaceAll("\xFF","/");break;case 57:throw new j("Multi-volume LZH archives are unsupported");case 65:if(t.byteLength>=16){let o=sM(t,8),r=sM(t,12),i=o+r*4294967296;if(Number.isSafeInteger(i))n.mtimeMs=i/1e4-11644473600000}break;case 66:if(t.byteLength<16)throw new j("Invalid LZH 64-bit size extended header");n.packedSize=ajs(t,0),n.size=ajs(t,8);break;case 68:n.unicodeFilename=ljs(t);break;case 69:n.unicodeDirectory=ljs(t).replaceAll("\xFF","/");break;case 80:if(t.byteLength<2)throw new j("Invalid LZH Unix permissions extended header");n.mode=g0(t,0);break;case 84:if(t.byteLength<4)throw new j("Invalid LZH Unix timestamp extended header");n.mtimeMs=sM(t,0)*1000;break}}class djs{#e;#t;#s;#n;#o;constructor(e,t,s,n,o){this.#e=e,this.#t=t,this.#s=s,this.#n=n,this.#o=o}async read(e,t){let s=this.#e.subarray(this.#t,this.#t+this.#s),n;switch(this.#n){case"-lh0-":case"-lz4-":if(s.byteLength!==e)throw new j(`LZH member '${t}' has inconsistent stored size`);n=s.slice();break;case"-lh4-":n=a6(s,e,4096,4,13,"LZH -lh4-");break;case"-lh5-":n=a6(s,e,8192,4,14,"LZH -lh5-");break;case"-lh6-":n=a6(s,e,32768,5,16,"LZH -lh6-");break;case"-lh7-":n=a6(s,e,65536,5,17,"LZH -lh7-");break;case"-lzs-":n=GBr(s,e);break;case"-lh1-":throw new j(`LZH member '${t}' uses unsupported dynamic-Huffman method -lh1-`);default:throw new j(`LZH member '${t}' uses unsupported compression method ${this.#n}`)}if(n.byteLength!==e)throw new j(`LZH member '${t}' extracted to an unexpected size`);if(i6(n)!==this.#o)throw new j(`LZH member '${t}' failed CRC-16 verification`);return n}}function KBr(e,t,s){Yie(e,t,t+22,"header");let n=e[t+20];if(n>2)throw new j(`Unsupported LZH header level ${n}`);let o=String.fromCharCode(...e.subarray(t+2,t+7));if(!pjs.test(o))throw new j(`Invalid LZH compression method '${o}'`);let r=sM(e,t+7),i=sM(e,t+11),a=0,l,u,p=0,c,d={};if(n<2){let T=e[t];if(T<(n===0?22:25))throw new j(`Invalid LZH level-${n} header size`);let R=t+T+2;Yie(e,t,R,"header");let C=0;for(let w=t+2;w<R;w++)C=C+e[w]&255;if(C!==e[t+1])throw new j("Invalid LZH header checksum");let b=e[t+21];if(22+b+2>T+2)throw new j("Invalid LZH filename length");if(ko(b,"member path",s.limits.maxPathBytes),l=ght(e.subarray(t+22,t+22+b)),a=g0(e,t+22+b),u=zBr(sM(e,t+15)),n===0){let w=t+24+b;if(R-w>=12){let E=e.subarray(w,R);if((E[0]===85||E[0]===75)&&E[1]===0)p=E[0],d.mtimeMs=sM(E,2)*1000,d.mode=g0(E,E.byteLength-6)}c=R}else{p=e[t+24+b];let w=g0(e,R-2),E=R,x=0,A=0;while(w!==0){if(w<3)throw new j("Invalid LZH extended header size");if(Yie(e,E,E+w,"extended header"),x+=w,Hn(T+2+x,s.limits,"header metadata"),++A>65535)throw new j("Invalid LZH archive: too many extended headers");let M=e[E],I=E+w-2,O=e.subarray(E+1,I);if(M===1||M===2||M===68||M===69)ko(O.byteLength,"member path",s.limits.maxPathBytes);ujs(M,O,E+1,d);let P=w;w=g0(e,I),E+=P}if(c=R+x,r=d.packedSize??r-x,r<0)throw new j("Invalid LZH level-1 packed size")}}else{let T=g0(e,t);if(T<26)throw new j("Invalid LZH level-2 header size");let y=t+T;Yie(e,t,y,"header"),a=g0(e,t+21),p=e[t+23],u=sM(e,t+15)*1000;let R=t+24,C=0;while(R+2<=y){let b=g0(e,R);if(b===0){R+=2;break}if(b<3||R+b>y)throw new j("Invalid LZH extended header size");if(++C>65535)throw new j("Invalid LZH archive: too many extended headers");let w=e[R+2],E=e.subarray(R+3,R+b);if(w===1||w===2||w===68||w===69)ko(E.byteLength,"member path",s.limits.maxPathBytes);ujs(w,E,R+3,d),R+=b}if(R!==y)throw new j("Invalid LZH level-2 extended header chain");c=y,r=d.packedSize??r}if(n===1&&p===32&&o==="-lh7-")throw new j("LZH uses the incompatible LHARK -lh7- variant");i=d.size??i,u=d.mtimeMs??u;let f=d.mode;if(d.commonCrc!==void 0){let T=d.commonCrcOffset-t;if($Br(e.subarray(t,c),T,T+2)!==d.commonCrc)throw new j("Invalid LZH common header CRC-16")}let m=d.unicodeFilename??d.filename??l??"",g=d.unicodeDirectory??d.directory??"",h=`${g}${g&&!/[\\/]$/.test(g)?"/":""}${m}`;return Kd(h,"member path",s.limits.maxPathBytes),Qi(i,h||"<unnamed>",s.limits),Yie(e,c,c+r,"member data"),{method:o,packedSize:r,size:i,dataStart:c,nextOffset:c+r,crc:a,path:Sr(h),mtimeMs:u,mode:f}}function Tht(e){if(e.byteLength<22||e[2]!==45||e[6]!==45||e[3]!==108)return!1;let t=String.fromCharCode(...e.subarray(2,7));return pjs.test(t)&&e[20]<=2}var qBr,UBr,pjs,jBr,fjs=async(e,t)=>{ci(e.size,t.limits);let s;try{s=await eM(e)}catch(a){if(a instanceof j)throw a;throw new j(`Unable to read LZH archive: ${a instanceof Error?a.message:String(a)}`)}if(s.byteLength!==e.size)throw new j("Invalid LZH archive: truncated data");if(!Tht(s))throw new j("Invalid LZH archive header");let n=[],o=0,r=0,i=0;while(o<s.byteLength&&s[o]!==0){let a=KBr(s,o,t);if(i+=a.dataStart-o,Hn(i,t.limits,"index"),or(++r,t.limits),a.nextOffset<=o)throw new j("Invalid LZH archive: header did not advance");if(o=a.nextOffset,!a.path)continue;let l=a.method==="-lhd-";if(l&&a.mode!==void 0&&(a.mode&61440)===40960){let u=a.path.indexOf("|");if(u<1)throw new j(`Invalid LZH symbolic link '${a.path}'`);let p=Sr(a.path.slice(0,u)),c=Sr(a.path.slice(u+1));if(!p||!c)continue;n.push({path:p,isDirectory:!1,size:0,mtimeMs:a.mtimeMs,mode:a.mode,storage:{type:"link",targetPath:c,resolveTarget:!1}});continue}n.push({path:a.path,isDirectory:l,size:l?0:a.size,mtimeMs:a.mtimeMs,mode:a.mode,storage:l?void 0:{type:"member",source:new djs(s,a.dataStart,a.packedSize,a.method,a.crc)}})}if(n.length===0&&r===0)throw new j("Invalid LZH archive: no members");return n};var yht=S(()=>{m0();Ur();vp();Vd();tM();qBr=new TextDecoder("windows-1252"),UBr=new TextDecoder("utf-16"),pjs=/^-(?:lh[0-7d]|lz[45s])-$/;jBr=new Uint8Array(2)});function qPe(e,t){return e[t]|e[t+1]<<8}function fW(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Jie(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid ARJ archive: truncated ${n}`)}function YBr(e){if(e===0)return;let t=1980+(e>>>25&127),s=e>>>21&15,n=e>>>16&31,o=e>>>11&31,r=e>>>5&63,i=(e&31)*2;if(s<1||s>12||n<1||n>31||o>23||r>59||i>59)return;return Date.UTC(t,s-1,n,o,r,i)}function mjs(e,t,s,n){let o=t;while(o<s&&e[o]!==0)o++;if(o===s)throw new j(`Invalid ARJ ${n}: missing terminator`);return{value:VBr.decode(e.subarray(t,o)),next:o+1}}function gjs(e,t,s){if(Jie(e,t,t+4,"header signature"),e[t]!==hjs||e[t+1]!==Tjs)throw new j("Invalid ARJ header signature");let n=qPe(e,t+2);if(n===0)return{bodyStart:t+4,bodySize:0,nextOffset:t+4,metadataSize:4,isEnd:!0};if(n<30||n>yjs)throw new j("Invalid ARJ basic header size");let o=t+4,r=o+n;if(Jie(e,o,r+4,"basic header"),Wi(e.subarray(o,r))!==fW(e,r))throw new j("Invalid ARJ basic header CRC32");let i=r+4,a=0;for(;;){Jie(e,i,i+2,"extended header size");let l=qPe(e,i);if(i+=2,l===0)break;if(++a>65535)throw new j("Invalid ARJ archive: too many extended headers");if(Jie(e,i,i+l+4,"extended header"),Wi(e.subarray(i,i+l))!==fW(e,i+l))throw new j("Invalid ARJ extended header CRC32");i+=l+4,Hn(i-t,s.limits,"header metadata")}return{bodyStart:o,bodySize:n,nextOffset:i,metadataSize:i-t,isEnd:!1}}class Rjs{#e;#t=0;constructor(e){this.#e=e}read(e){if(!Number.isInteger(e)||e<0||e>24||this.#t+e>this.#e.byteLength*8)throw new j("Invalid ARJ method-4 compressed data: truncated bitstream");let t=0;for(let s=0;s<e;s++){let n=this.#t++;t=t*2+(this.#e[n>>>3]>>>7-(n&7)&1)}return t}assertZeroPadding(){while(this.#t<this.#e.byteLength*8)if(this.read(1)!==0)throw new j("Invalid ARJ method-4 compressed data: non-zero trailing bits")}}function JBr(e,t){let s=new Rjs(e),n=new Uint8Array(t),o=0;while(o<t){let r=0,i=0;for(;i<7;i++){if(s.read(1)===0)break;r+=2**i}if(i!==0)r+=s.read(i);if(r===0){n[o++]=s.read(8);continue}let a=r+2;if(a>t-o)throw new j("Invalid ARJ method-4 compressed data: match exceeds declared size");let l=0,u=9;for(;u<13;u++){if(s.read(1)===0)break;l+=2**u}if(l+=s.read(u),l>=26624||l>=o)throw new j("Invalid ARJ method-4 compressed data: history distance is out of range");let p=o-l-1;for(let c=0;c<a;c++)n[o++]=n[p++]}return s.assertZeroPadding(),n}class Cjs{#e;#t;#s;#n;#o;constructor(e,t,s,n,o){this.#e=e,this.#t=t,this.#s=s,this.#n=n,this.#o=o}async read(e,t){let s=this.#e.subarray(this.#t,this.#t+this.#s),n;switch(this.#n){case 0:if(s.byteLength!==e)throw new j(`ARJ member '${t}' has inconsistent stored size`);n=s.slice();break;case 1:case 2:case 3:n=a6(s,e,26624,5,17,`ARJ method ${this.#n}`);break;case 4:n=JBr(s,e);break;case 8:case 9:if(e!==0||s.byteLength!==0)throw new j(`ARJ member '${t}' has invalid no-data method sizes`);n=new Uint8Array(0);break;default:throw new j(`ARJ member '${t}' uses unsupported compression method ${this.#n}`)}if(n.byteLength!==e)throw new j(`ARJ member '${t}' extracted to an unexpected size`);if(this.#n!==8&&Wi(n)!==this.#o)throw new j(`ARJ member '${t}' failed CRC32 verification`);return n}}function XBr(e,t){let s=e.replaceAll("\\","/");if(t===1)s=s.replaceAll(">","/");else if(t===4)s=s.replaceAll(":","/");return s}function Rht(e){if(e.byteLength<34||e[0]!==hjs||e[1]!==Tjs)return!1;let t=qPe(e,2);if(t<30||t>yjs||e.byteLength<t+8)return!1;let s=e.subarray(4,4+t);return s[0]>=30&&s[0]<=t&&s[6]===2&&Wi(s)===fW(e,4+t)}var hjs=96,Tjs=234,yjs=2600,VBr,bjs=async(e,t)=>{ci(e.size,t.limits);let s;try{s=await eM(e)}catch(p){if(p instanceof j)throw p;throw new j(`Unable to read ARJ archive: ${p instanceof Error?p.message:String(p)}`)}if(s.byteLength!==e.size)throw new j("Invalid ARJ archive: truncated data");if(!Rht(s))throw new j("Invalid ARJ archive header");let n=gjs(s,0,t);if(n.isEnd)throw new j("Invalid ARJ archive: missing main header");let o=s[n.bodyStart];if(o<30||o>n.bodySize||s[n.bodyStart+6]!==2)throw new j("Invalid ARJ main header");let r=s[n.bodyStart+4];if((r&1)!==0)throw new j("Encrypted ARJ archives are unsupported");if((r&4)!==0)throw new j("Multi-volume ARJ archives are unsupported");let i=[],a=n.nextOffset,l=n.metadataSize,u=0;for(;;){let p=gjs(s,a,t);if(l+=p.metadataSize,Hn(l,t.limits,"index"),p.isEnd)break;or(++u,t.limits);let c=s[p.bodyStart];if(c<30||c>p.bodySize)throw new j("Invalid ARJ local header");let d=s[p.bodyStart+3],f=s[p.bodyStart+4],m=s[p.bodyStart+5],g=s[p.bodyStart+6];if((f&1)!==0)throw new j("Encrypted ARJ members are unsupported");if((f&12)!==0)throw new j("Multi-volume ARJ members are unsupported");let h=fW(s,p.bodyStart+12),T=fW(s,p.bodyStart+16),y=fW(s,p.bodyStart+20),R=qPe(s,p.bodyStart+26),C=mjs(s,p.bodyStart+c,p.bodyStart+p.bodySize,"filename");mjs(s,C.next,p.bodyStart+p.bodySize,"comment"),ko(C.next-(p.bodyStart+c)-1,"member path",t.limits.maxPathBytes);let b=XBr(C.value,d);Kd(b,"member path",t.limits.maxPathBytes),Qi(T,b||"<unnamed>",t.limits);let w=p.nextOffset;Jie(s,w,w+h,"member data"),a=w+h;let E=Sr(b);if(!E)continue;let x=g===3,A;if((d===2||d===8)&&R!==0)A=(x?16384:32768)|R&4095;let M=fW(s,p.bodyStart+8),I=d===2||d===8?M===0?void 0:M*1000:YBr(M);i.push({path:E,isDirectory:x,size:x?0:T,mtimeMs:I,mode:A,storage:x?void 0:{type:"member",source:new Cjs(s,w,h,m,y)}})}if(u===0)throw new j("Invalid ARJ archive: no members");return i};var kjs=S(()=>{m0();Ur();vp();yht();Vd();tM();VBr=new TextDecoder("windows-1252")});import*as wjs from"path";function Ai(e){return new j(`Invalid ASAR archive: ${e}`)}function HPe(e){return e instanceof Error&&e.message?e.message:String(e)}function Cht(e){return e+(4-e%4)%4}function Xie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function tWr(e,t,s){if(e===void 0)return;let n=dr(t);if(!Xie(e))throw Ai(`file '${n}' has an invalid integrity record`);if(e.algorithm!=="SHA256")throw Ai(`file '${n}' uses unsupported integrity algorithm '${String(e.algorithm)}'`);if(typeof e.hash!=="string"||!Sjs.test(e.hash))throw Ai(`file '${n}' has an invalid integrity hash`);if(typeof e.blockSize!=="number"||!Number.isSafeInteger(e.blockSize)||e.blockSize<=0)throw Ai(`file '${n}' has an invalid integrity block size`);if(!Array.isArray(e.blocks))throw Ai(`file '${n}' has invalid integrity blocks`);let o=Math.max(1,Math.ceil(s/e.blockSize));if(e.blocks.length!==o)throw Ai(`file '${n}' has an inconsistent integrity block count`);for(let r of e.blocks)if(typeof r!=="string"||!Sjs.test(r))throw Ai(`file '${n}' has an invalid integrity block hash`);return{algorithm:"SHA256",hash:e.hash.toLowerCase()}}function xjs(e,t,s){if(!t)return;if(new Bun.CryptoHasher("sha256").update(e).digest("hex")!==t.hash)throw new j(`ASAR member '${dr(s)}' failed SHA256 integrity verification`)}class Ejs{#e;#t;#s;#n;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}async read(e,t){if(e!==this.#s)throw new j(`ASAR member '${dr(t)}' has an inconsistent size`);let s;try{s=await this.#e.read(this.#t,this.#t+this.#s)}catch(n){if(n instanceof j)throw n;throw new j(`Failed to read ASAR member '${dr(t)}': ${HPe(n)}`)}if(s.byteLength!==this.#s)throw new j(`ASAR member '${dr(t)}' is truncated`);return xjs(s,this.#n,t),s}}class Mjs{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){let s=dr(t);if(e!==this.#t)throw new j(`ASAR member '${s}' has an inconsistent size`);if(!this.#e)throw new j(`Archive file '${s}' is unpacked and requires a filesystem-backed ASAR archive`);let n=Bun.file(this.#e),o=await n.stat().catch(()=>{throw new j(`Unpacked ASAR file '${s}' was not found`)});if(o.isDirectory())throw new j(`Unpacked ASAR file '${s}' is a directory`);if(o.size!==this.#t)throw new j(`Unpacked ASAR file '${s}' size differs from its archive header (${o.size} != ${this.#t} bytes)`);let r;try{r=await n.bytes()}catch(i){throw new j(`Failed to read unpacked ASAR file '${s}': ${HPe(i)}`)}if(r.byteLength!==this.#t)throw new j(`Unpacked ASAR file '${s}' changed while being read`);return xjs(r,this.#s,t),r}}async function sWr(e,t){if(!Number.isSafeInteger(e.size)||e.size<UPe)throw Ai("truncated header");let s=await e.read(0,l6);if(s.byteLength!==l6)throw Ai("truncated size pickle");if(Es(s,0)!==4)throw Ai("invalid size pickle");let n=Es(s,4);if(n<Qie)throw Ai("header is too small");Hn(n,t.limits,"ASAR header");let o=l6+n;if(!Number.isSafeInteger(o)||o>e.size)throw Ai("header extends beyond archive boundary");let r=await e.read(l6,o);if(r.byteLength!==n)throw Ai("truncated header pickle");let i=Es(r,0),a=Es(r,4);if(i+4!==n||i!==4+Cht(a))throw Ai("inconsistent pickle lengths");let l=Qie+a;for(let g=l;g<r.byteLength;g++)if(r[g]!==0)throw Ai("non-zero pickle string padding");let u;try{u=QBr.decode(r.subarray(Qie,l))}catch{throw Ai("header is not valid UTF-8")}let p;try{p=JSON.parse(u)}catch{throw Ai("header is not valid JSON")}if(!Xie(p)||!Xie(p.files))throw Ai("root must contain a files object");let c=[],d=[],f=0,m=(g,h,T)=>{for(let y in g)or(++f,t.limits),d.push({parentPath:h,parentPathBytes:T,name:y,node:g[y]})};m(p.files,"",0);while(d.length>0){let g=d.pop(),h=Buffer.byteLength(g.name,"utf-8");if(ko(h,"entry name",t.limits.maxPathBytes),g.name.length===0||g.name==="."||g.name===".."||g.name.includes("/")||g.name.includes("\\")||g.name.includes("\x00"))throw Ai(`invalid entry name '${dr(g.name)}'`);if(!Xie(g.node))throw Ai(`entry '${dr(g.name)}' must be an object`);let T=g.parentPathBytes+(g.parentPath?1:0)+h;ko(T,"member path",t.limits.maxPathBytes);let y=g.parentPath?`${g.parentPath}/${g.name}`:g.name;if(Sr(y)!==y)throw Ai(`invalid entry path '${dr(y)}'`);let C=dr(y);if(g.node.unpacked!==void 0&&typeof g.node.unpacked!=="boolean")throw Ai(`entry '${C}' has a non-boolean unpacked flag`);if("link"in g.node){if(typeof g.node.link!=="string"||g.node.link.length===0)throw Ai(`entry '${C}' has an invalid link target`);Kd(g.node.link,"link target",t.limits.maxPathBytes);let I=g.node.link.replace(/\\/g,"/"),O=I.startsWith("/")||/^[A-Za-z]:\//.test(I)?void 0:zd(I);if(O===void 0)throw Ai(`entry '${C}' links outside the archive`);c.push({path:y,isDirectory:!1,size:0,storage:{type:"link",targetPath:O,resolveTarget:!0}});continue}if("files"in g.node){if(!Xie(g.node.files))throw Ai(`directory '${C}' must contain a files object`);c.push({path:y,isDirectory:!0,size:0}),m(g.node.files,y,T);continue}let b=g.node.size;if(typeof b!=="number"||!Number.isSafeInteger(b)||b<0)throw Ai(`file '${C}' has an invalid size`);if(Qi(b,y,t.limits),g.node.executable!==void 0&&typeof g.node.executable!=="boolean")throw Ai(`file '${C}' has a non-boolean executable flag`);let w=typeof g.node.executable==="boolean"?eWr|(g.node.executable?493:420):void 0,E=tWr(g.node.integrity,y,b);if(g.node.unpacked===!0){let I=t.archivePath?wjs.join(`${t.archivePath}.unpacked`,...y.split("/")):void 0;c.push({path:y,isDirectory:!1,size:b,mode:w,storage:{type:"member",source:new Mjs(I,b,E)}});continue}if(typeof g.node.offset!=="string"||!/^\d+$/.test(g.node.offset))throw Ai(`file '${C}' has an invalid offset`);let x=Number(g.node.offset),A=o+x,M=A+b;if(!Number.isSafeInteger(x)||!Number.isSafeInteger(A)||!Number.isSafeInteger(M)||M>e.size)throw Ai(`file '${C}' extends beyond archive boundary`);c.push({path:y,isDirectory:!1,size:b,mode:w,storage:{type:"member",source:new Ejs(e,A,b,E)}})}return c}function vjs(e){if(e.byteLength<UPe+1)return!1;let t=Es(e,0),s=Es(e,4),n=Es(e,8),o=Es(e,12);return t===4&&s>=Qie&&s===n+4&&n===4+Cht(o)&&o>0&&e[UPe]===123}function nWr(e){let t=e.replace(/\\/g,"/"),s=Sr(t);if(s===void 0||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.includes("\x00")||t.split("/").some((n)=>!n||n==="."||n===".."))throw new j(`Invalid ASAR member path '${dr(e)}'`);return s}async function Ijs(e){try{let t={files:Object.create(null)},s=[],n=0;for(let d of e){if(!Array.isArray(d)||d.length!==2||typeof d[0]!=="string"||!(d[1]instanceof Uint8Array))throw new j("ASAR members must be [path, Uint8Array] pairs");let f=nWr(d[0]),m=f.split("/"),g=t;for(let T=0;T<m.length-1;T++){let y=m[T],R=g.files[y];if(R&&!("files"in R))throw new j(`ASAR member path '${f}' crosses file '${m.slice(0,T+1).join("/")}'`);if(!R)g.files[y]={files:Object.create(null)};g=g.files[y]}let h=m.at(-1);if(g.files[h])throw new j(`Duplicate or conflicting ASAR member path '${f}'`);if(!Number.isSafeInteger(d[1].byteLength)||!Number.isSafeInteger(n+d[1].byteLength))throw new j("ASAR payload is too large to encode safely");g.files[h]={size:d[1].byteLength,offset:String(n)},s.push(d[1]),n+=d[1].byteLength}let o=ZBr.encode(JSON.stringify(t)),i=4+Cht(o.byteLength),a=4+i;if(o.byteLength>4294967295||a>4294967295)throw new j("ASAR header is too large to encode");let l=l6+a,u=l+n;if(!Number.isSafeInteger(u))throw new j("ASAR archive is too large to encode safely");let p;try{p=new Uint8Array(u)}catch{throw new j("ASAR archive is too large to encode in memory")}dl(p,0,4),dl(p,4,a),dl(p,8,i),dl(p,12,o.byteLength),p.set(o,UPe);let c=l;for(let d of s)p.set(d,c),c+=d.byteLength;return p}catch(t){if(t instanceof j)throw t;throw new j(`Failed to encode ASAR archive: ${HPe(t)}`)}}var QBr,ZBr,l6=8,Qie=8,UPe,eWr=32768,Sjs,Ajs=async(e,t)=>{try{return await sWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(`Failed to read ASAR archive: ${HPe(s)}`)}};var bht=S(()=>{Sh();Ur();vp();Vd();QBr=new TextDecoder("utf-8",{fatal:!0}),ZBr=new TextEncoder,UPe=l6+Qie,Sjs=/^[0-9a-f]{64}$/i});class Fjs{#e;#t=0;#s=0;#n=0;constructor(e){this.#e=e}readBits(e){let t=0,s=e;while(s>0){if(this.#n===0){if(this.#t+2>this.#e.byteLength)throw new j("Invalid CAB archive: truncated LZX bitstream");this.#s=this.#e[this.#t]|this.#e[this.#t+1]<<8,this.#t+=2,this.#n=16}let n=Math.min(s,this.#n);t=t*2**n+(this.#s>>>this.#n-n&2**n-1),this.#n-=n,s-=n}return t}alignWord(){this.#n=0}readByte(){if(this.#n!==0)throw new j("Invalid CAB archive: misaligned LZX byte stream");if(this.#t>=this.#e.byteLength)throw new j("Invalid CAB archive: truncated LZX data");return this.#e[this.#t++]}readUInt32LE(){let e=this.readByte(),t=this.readByte(),s=this.readByte(),n=this.readByte();return(e|t<<8|s<<16|n<<24)>>>0}}class Zie{#e=new Uint32Array(17);#t=new Uint32Array(17);#s=new Uint32Array(17);#n;empty;constructor(e,t=!1){let s=0;for(let i of e){if(i>16)throw new j("Invalid CAB archive: invalid LZX Huffman code length");if(i!==0)this.#e[i]++,s++}if(this.empty=s===0,this.empty&&!t)throw new j("Invalid CAB archive: empty LZX Huffman tree");let n=0,o=0;for(let i=1;i<=16;i++){if(n=(n+this.#e[i-1])*2,n+this.#e[i]>2**i)throw new j("Invalid CAB archive: oversubscribed LZX Huffman tree");this.#t[i]=n,this.#s[i]=o,o+=this.#e[i]}this.#n=new Uint16Array(s);let r=this.#s.slice();for(let i=0;i<e.byteLength;i++){let a=e[i];if(a!==0)this.#n[r[a]]=i;r[a]++}}decode(e){if(this.empty)throw new j("Invalid CAB archive: LZX stream uses an empty Huffman tree");let t=0;for(let s=1;s<=16;s++){t=t*2+e.readBits(1);let n=t-this.#t[s];if(n>=0&&n<this.#e[s])return this.#n[this.#s[s]+n]}throw new j("Invalid CAB archive: invalid LZX Huffman symbol")}}function kht(e,t,s,n){let o=new Uint8Array(20);for(let a=0;a<o.byteLength;a++)o[a]=e.readBits(4);let r=new Zie(o),i=s;while(i<n){let a=r.decode(e);if(a===17||a===18){let l=e.readBits(a===17?4:5)+(a===17?4:20);if(i+l>n)throw new j("Invalid CAB archive: LZX code-length run exceeds its tree");t.fill(0,i,i+l),i+=l;continue}if(a===19){let l=e.readBits(1)+4;if(i+l>n)throw new j("Invalid CAB archive: LZX code-length run exceeds its tree");let u=r.decode(e),p=(t[i]-u+17)%17;t.fill(p,i,i+l),i+=l;continue}t[i]=(t[i]-a+17)%17,i++}}function Pjs(e){return e>2147483647?e-4294967296:e}class Sht{#e;#t;#s;#n;#o=new Uint8Array(iWr);#r;#a;#i;#l=0;#u=0;#p=0;#c=1;#d=1;#m=1;#f=!1;#h=0;#T=!1;#g=0;#y=0;#R=0;#C=!1;constructor(e){if(!Number.isInteger(e)||e<15||e>21)throw new j(`Unsupported CAB LZX window size: ${e} bits (expected 15-21)`);this.#e=new Uint8Array(2**e);let t=aWr[e-15];this.#n=new Uint8Array(256+t*8),this.#s=new Uint8Array(t),this.#t=new Uint32Array(t);for(let s=0;s<t;s++)if(this.#s[s]=s<4?0:Math.min(17,Math.floor(s/2)-1),s>0)this.#t[s]=this.#t[s-1]+2**this.#s[s-1]}decompressFrame(e,t){if(!Number.isInteger(t)||t<0||t>oWr)throw new j(`Invalid CAB archive: LZX frame size ${t} exceeds 32768 bytes`);if(t===0)return new Uint8Array(0);let s=new Fjs(e);if(!this.#f){if(s.readBits(1)!==0){let i=s.readBits(16),a=s.readBits(16);this.#h=Pjs(i*65536+a>>>0)}this.#f=!0}let n=new Uint8Array(t),o=0;while(o<t){if(this.#R===0)this.#k(s);let i=Math.min(this.#R,t-o),a=this.#S(s,n,o,i);if(a!==i)throw new j("Invalid CAB archive: LZX block produced the wrong byte count");o+=a,this.#R-=a}if(this.#R===0&&this.#g===3&&this.#C)s.readByte(),this.#C=!1;s.alignWord();let r=this.#x(n);return this.#p++,r}#k(e){if(this.#g===3&&this.#C)e.readByte();if(this.#C=!1,this.#g=e.readBits(3),this.#y=e.readBits(16)*256+e.readBits(8),this.#y===0)throw new j("Invalid CAB archive: zero-length LZX block");if(this.#R=this.#y,this.#g===1||this.#g===2){if(this.#g===2){let t=new Uint8Array(8);for(let s=0;s<t.byteLength;s++)t[s]=e.readBits(3);this.#i=new Zie(t)}if(kht(e,this.#n,0,256),kht(e,this.#n,256,this.#n.byteLength),this.#r=new Zie(this.#n),this.#n[232]!==0)this.#T=!0;kht(e,this.#o,0,this.#o.byteLength),this.#a=new Zie(this.#o,!0);return}if(this.#g===3){if(this.#T=!0,e.alignWord(),this.#c=e.readUInt32LE(),this.#d=e.readUInt32LE(),this.#m=e.readUInt32LE(),this.#c===0||this.#d===0||this.#m===0)throw new j("Invalid CAB archive: invalid LZX repeated offset");this.#C=(this.#y&1)!==0;return}throw new j(`Invalid CAB archive: unsupported LZX block type ${this.#g}`)}#S(e,t,s,n){if(this.#g===3){for(let r=0;r<n;r++)this.#b(e.readByte(),t,s+r);return n}if(!this.#r||!this.#a)throw new j("Invalid CAB archive: missing LZX decode trees");let o=0;while(o<n){let r=this.#r.decode(e);if(r<256){this.#b(r,t,s+o),o++;continue}let i=r-256,a=i&Ojs;if(a===Ojs)a+=this.#a.decode(e);if(a+=rWr,a>n-o||a>this.#R-o)throw new j("Invalid CAB archive: LZX match crosses a frame or block boundary");let l=i>>>3,u;if(l===0)u=this.#c;else if(l===1)u=this.#d,this.#d=this.#c,this.#c=u;else if(l===2)u=this.#m,this.#m=this.#c,this.#c=u;else{if(l>=this.#t.byteLength)throw new j("Invalid CAB archive: LZX position slot is out of range");let p=this.#s[l];if(u=this.#t[l]-2,this.#g===2&&p>=3){if(p>3)u+=e.readBits(p-3)*8;if(!this.#i)throw new j("Invalid CAB archive: missing LZX aligned tree");u+=this.#i.decode(e)}else if(p!==0)u+=e.readBits(p);this.#m=this.#d,this.#d=this.#c,this.#c=u}if(u<=0||u>Math.min(this.#u,this.#e.byteLength))throw new j("Invalid CAB archive: LZX match offset exceeds available history");for(let p=0;p<a;p++){let c=(this.#l-u+this.#e.byteLength)%this.#e.byteLength;this.#b(this.#e[c],t,s+o+p)}o+=a}return o}#b(e,t,s){t[s]=e,this.#e[this.#l]=e,this.#l=(this.#l+1)%this.#e.byteLength,this.#u++}#x(e){if(!this.#T||this.#h===0||this.#p>=32768||e.byteLength<=10)return e;let t=e.slice(),s=0,n=this.#u-e.byteLength,o=t.byteLength-10;while(s<o){if(t[s++]!==232){n++;continue}let r=Pjs((t[s]|t[s+1]<<8|t[s+2]<<16|t[s+3]<<24)>>>0);if(r>=-n&&r<this.#h){let i=r>=0?r-n:r+this.#h;t[s]=i&255,t[s+1]=i>>>8&255,t[s+2]=i>>>16&255,t[s+3]=i>>>24&255}s+=4,n+=5}return t}}var oWr=32768,rWr=2,Ojs=7,iWr=249,aWr;var _js=S(()=>{Ur();aWr=[30,32,34,36,38,42,50]});import*as Njs from"zlib";async function eae(e,t,s,n=e.size){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>n)throw new j("Invalid CAB archive: metadata range is out of bounds");let o;try{o=await e.read(t,s)}catch(r){if(r instanceof j)throw r;throw new j(`Unable to read CAB archive: ${r instanceof Error?r.message:String(r)}`)}if(o.byteLength!==s-t)throw new j("Invalid CAB archive: truncated data");return o}function qjs(e){return e.byteLength>=4&&e[0]===77&&e[1]===83&&e[2]===67&&e[3]===70}function Djs(e,t=0){let s=t>>>0,n=0;while(n+4<=e.byteLength)s^=Es(e,n),n+=4;let o=e.byteLength-n,r=0;if(o===3)r=e[n]<<16|e[n+1]<<8|e[n+2];else if(o===2)r=e[n]<<8|e[n+1];else if(o===1)r=e[n];return(s^r)>>>0}function gWr(e,t){try{return t?fWr.decode(e):mWr.decode(e)}catch{throw new j("Invalid CAB archive: file name is not valid UTF-8")}}function hWr(e,t){if(e===0&&t===0)return;let s=1980+(e>>>9),n=e>>>5&15,o=e&31,r=t>>>11,i=t>>>5&63,a=(t&31)*2;if(n<1||n>12||o<1||o>31||r>23||i>59||a>59)throw new j("Invalid CAB archive: file has an invalid DOS timestamp");return new Date(s,n-1,o,r,i,a).getTime()}function TWr(e,t){if(t)return 16877;let s=e&uWr?292:420;if(e&cWr)s|=73;return 32768|s}class Ujs{#e;#t;#s;#n;#o;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}readAll(){return this.#o??=this.#r(),this.#o}async#r(){let e=this.#t;if(e.method===2)throw new j(`Unsupported CAB compression method: Quantum (level ${e.parameter})`);if(e.method>3)throw new j(`Unsupported CAB compression method: ${e.method}`);if(e.method===3&&(e.parameter<15||e.parameter>21))throw new j(`Unsupported CAB LZX window size: ${e.parameter} bits (expected 15-21)`);let t=e.dataEnd-e.dataStart;ci(t,this.#n);let s=await eae(this.#e,e.dataStart,e.dataEnd),n=0,o=0;for(let l=0;l<e.blockCount;l++){if(n+wht+this.#s>s.byteLength)throw new j("Invalid CAB archive: truncated CFDATA header");let u=xn(s,n+4),p=xn(s,n+6);if(p===0)throw new j("Unsupported multi-volume CAB archive: split CFDATA block");if(p>Ljs)throw new j(`Invalid CAB archive: CFDATA expands to ${p} bytes (maximum 32768)`);let c=n+wht+this.#s,d=c+u;if(d>s.byteLength)throw new j("Invalid CAB archive: truncated CFDATA payload");let f=Es(s,n);if(f!==0){let m=Djs(s.subarray(c,d));if(Djs(s.subarray(n+4,c),m)!==f)throw new j(`Invalid CAB archive: CFDATA block ${l} checksum mismatch`)}o+=p,ci(o,this.#n),n=d}if(o<e.requiredSize)throw new j("Invalid CAB archive: folder data is shorter than its file table declares");let r=new Uint8Array(o),i=e.method===3?new Sht(e.parameter):void 0;n=0;let a=0;for(let l=0;l<e.blockCount;l++){let u=xn(s,n+4),p=xn(s,n+6),c=n+wht+this.#s,d=c+u,f=s.subarray(c,d),m;if(e.method===0){if(u!==p)throw new j("Invalid CAB archive: uncompressed CFDATA sizes do not match");m=f}else if(e.method===1){if(f.byteLength<2||f[0]!==67||f[1]!==75)throw new j("Invalid CAB archive: MSZIP block is missing its CK signature");try{let g=r.subarray(Math.max(0,a-Ljs),a);m=new Uint8Array(Njs.inflateRawSync(f.subarray(2),{dictionary:g,maxOutputLength:p}))}catch(g){throw new j(`Invalid CAB archive: MSZIP decompression failed${g instanceof Error?`: ${g.message}`:""}`)}}else m=i.decompressFrame(f,p);if(m.byteLength!==p)throw new j(`Invalid CAB archive: CFDATA block ${l} produced ${m.byteLength} bytes, expected ${p}`);r.set(m,a),a+=m.byteLength,n=d}return r}}class Hjs{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){if(e!==this.#s)throw new j(`Invalid CAB archive: size changed while extracting '${t}'`);let s=await this.#e.readAll(),n=this.#t+e;if(!Number.isSafeInteger(n)||this.#t<0||n>s.byteLength)throw new j(`Invalid CAB archive: member '${t}' is outside its folder data`);return s.slice(this.#t,n)}}async function yWr(e,t){if(e.size<mW)throw new j("Invalid CAB archive: truncated CFHEADER");let s=await eae(e,0,mW);if(!qjs(s))throw new j(`Invalid CAB archive: expected ${lWr} signature`);if(Es(s,4)!==0||Es(s,12)!==0||Es(s,20)!==0)throw new j("Invalid CAB archive: reserved CFHEADER fields must be zero");let n=Es(s,8);if(n<mW||n>e.size)throw new j("Invalid CAB archive: declared cabinet size is out of bounds");let o=Es(s,16);if(o<mW||o>n)throw new j("Invalid CAB archive: CFFILE table offset is out of bounds");if(s[24]!==3||s[25]!==1)throw new j(`Unsupported CAB format version ${s[25]}.${s[24]} (expected 1.3)`);let r=xn(s,26),i=xn(s,28),a=xn(s,30);if(a&3)throw new j("Unsupported multi-volume CAB archive (previous/next cabinet link)");if(or(r+i,t.limits),r===0&&i!==0)throw new j("Invalid CAB archive: files exist without a folder");let l=0,u=0,p=0,c=mW;if(a&4){let b=await eae(e,mW,mW+4,n);if(l=xn(b,0),u=b[2],p=b[3],l>60000)throw new j("Invalid CAB archive: CFHEADER reserve area exceeds 60000 bytes");c+=4+l}let d=8+u,f=c+r*d;if(!Number.isSafeInteger(f)||f>n||f>o)throw new j("Invalid CAB archive: CFFOLDER table is out of bounds");Hn(f,t.limits,"CAB header");let m=await eae(e,0,f,n),g=[];for(let b=0;b<r;b++){let w=c+b*d,E=xn(m,w+6);g.push({dataStart:Es(m,w),dataEnd:n,blockCount:xn(m,w+4),method:E&15,parameter:E>>>8,requiredSize:0})}for(let b of g){if(b.dataStart<f||b.dataStart>n)throw new j("Invalid CAB archive: CFFOLDER data offset is out of bounds");for(let w of g)if(w.dataStart>b.dataStart&&w.dataStart<b.dataEnd)b.dataEnd=w.dataStart}let h=g.reduce((b,w)=>Math.min(b,w.dataStart),n);if(o>h)throw new j("Invalid CAB archive: CFFILE table overlaps folder data");Hn(f+(h-o),t.limits,"CAB index");let T=await eae(e,o,h,n),y=g.map((b)=>new Ujs(e,b,p,t.limits)),R=[],C=0;for(let b=0;b<i;b++){if(C+16>T.byteLength)throw new j("Invalid CAB archive: truncated CFFILE entry");let w=Es(T,C),E=Es(T,C+4),x=xn(T,C+8),A=xn(T,C+10),M=xn(T,C+12),I=xn(T,C+14);C+=16;let O=T.indexOf(0,C);if(O<0)throw new j("Invalid CAB archive: unterminated CFFILE name");let P=T.subarray(C,O);if(P.byteLength>256)throw new j("Invalid CAB archive: CFFILE name exceeds 256 bytes");if(ko(P.byteLength,"member path",t.limits.maxPathBytes),C=O+1,x>=65533)throw new j("Unsupported multi-volume CAB archive: continued file");if(x>=y.length)throw new j("Invalid CAB archive: CFFILE references a missing folder");let F=gWr(P,(I&dWr)!==0);Qi(w,F,t.limits);let _=E+w;if(!Number.isSafeInteger(_))throw new j("Invalid CAB archive: CFFILE range is too large");if(_>g[x].requiredSize)g[x].requiredSize=_;let D=Sr(F);if(!D)continue;let L=(I&pWr)!==0;R.push({path:D,isDirectory:L,size:w,mtimeMs:hWr(A,M),mode:TWr(I,L),storage:L?void 0:{type:"member",source:new Hjs(y[x],E,w)}})}for(let b of g)ci(b.requiredSize,t.limits);return R}function Bjs(e){return qjs(e)}var lWr="MSCF",mW=36,wht=8,Ljs=32768,uWr=1,pWr=16,cWr=64,dWr=128,fWr,mWr,Wjs=async(e,t)=>{try{return await yWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(`Invalid CAB archive: ${s instanceof Error?s.message:String(s)}`)}};var Gjs=S(()=>{Sh();_js();Ur();vp();Vd();fWr=new TextDecoder("utf-8",{fatal:!0}),mWr=new TextDecoder("windows-1252")});function xWr(){let e=new Uint32Array(256);for(let t=0;t<e.length;t++){let s=t<<24;for(let n=0;n<8;n++)s=(s&2147483648)!==0?s<<1^79764919:s<<1;e[t]=s>>>0}return e}function jjs(e,t){return(wWr[(e>>>24^t)&255]^e<<8)>>>0}class zjs{#e;#t=0;constructor(e){this.#e=e}get done(){return this.#t===this.#e.byteLength*8}readBit(){if(this.#t>=this.#e.byteLength*8)throw new j("Truncated bzip2 stream");let t=this.#e[this.#t>>>3]>>>7-(this.#t&7)&1;return this.#t++,t}readBits(e){let t=0;for(let s=0;s<e;s++)t=t*2+this.readBit();return t}readUint32(){return this.readBits(16)*65536+this.readBits(16)>>>0}readMarker(){return[this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8)]}alignToByte(){while((this.#t&7)!==0)if(this.readBit()!==0)throw new j("Invalid non-zero bzip2 stream padding")}}class Kjs{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=new Uint8Array(Math.min(e,Math.max(64,Math.min(t*2,65536))))}push(e){this.#n(1),this.#t[this.#s++]=e}pushRepeated(e,t){this.#n(t),this.#t.fill(e,this.#s,this.#s+t),this.#s+=t}finish(){return this.#t.slice(0,this.#s)}#n(e){let t=this.#s+e;if(!Number.isSafeInteger(t)||t>this.#e)throw new j(`Bzip2 output exceeds the ${this.#e}-byte limit`);if(t<=this.#t.byteLength)return;let s=Math.max(t,Math.min(this.#e,Math.max(64,this.#t.byteLength*2)));if(s>this.#e)s=this.#e;let n=new Uint8Array(s);n.set(this.#t.subarray(0,this.#s)),this.#t=n}}class Vjs{#e=new Uint16Array(gW+1);#t=new Uint32Array(gW+1);#s=new Uint16Array(gW+1);#n;constructor(e){for(let o of e){if(o<1||o>gW)throw new j("Invalid bzip2 Huffman code length");this.#e[o]++}let t=0,s=0;for(let o=1;o<=gW;o++){if(t=(t+this.#e[o-1])*2,t+this.#e[o]>2**o)throw new j("Oversubscribed bzip2 Huffman table");this.#t[o]=t,this.#s[o]=s,s+=this.#e[o]}this.#n=new Uint16Array(e.length);let n=new Uint16Array(this.#s);for(let o=0;o<e.length;o++){let r=e[o];this.#n[n[r]]=o,n[r]++}}decode(e){let t=0;for(let s=1;s<=gW;s++){t=t*2+e.readBit();let n=t-this.#t[s];if(n>=0&&n<this.#e[s])return this.#n[this.#s[s]+n]}throw new j("Invalid bzip2 Huffman code")}}function $js(e,t){return e.every((s,n)=>s===t[n])}function EWr(e){if(e.readBits(8)!==66||e.readBits(8)!==90||e.readBits(8)!==104)throw new j("Invalid bzip2 stream header");let t=e.readBits(8)-48;if(t<1||t>9)throw new j("Invalid bzip2 block-size level");return t*1e5}function MWr(e,t){let s=e.readBits(3);if(s<2||s>6)throw new j("Invalid bzip2 Huffman group count");let n=e.readBits(15);if(n<1||n>bWr)throw new j("Invalid bzip2 selector count");let o=new Uint8Array(n),r=new Uint8Array(s);for(let l=0;l<s;l++)r[l]=l;for(let l=0;l<n;l++){let u=0;while(e.readBit()!==0)if(u++,u>=s)throw new j("Invalid bzip2 selector MTF value");let p=r[u];o[l]=p,r.copyWithin(1,0,u),r[0]=p}let i=t.length+2,a=[];for(let l=0;l<s;l++){let u=new Uint8Array(i),p=e.readBits(5);for(let c=0;c<i;c++){while(e.readBit()!==0)if(p+=e.readBit()===0?1:-1,p<1||p>gW)throw new j("Invalid bzip2 Huffman code length");u[c]=p}a.push(new Vjs(u))}return{selectors:o,tables:a}}function AWr(e,t,s,n,o){let r=new Uint8Array(s),i=new Uint8Array(t),a=0,l=0,u=0,p,c=()=>{if(u===0){if(l>=n.length)throw new j("Bzip2 block exhausted its Huffman selectors");p=o[n[l++]],u=kWr}return u--,p.decode(e)},d=(g,h)=>{if(h<0||a+h>t)throw new j("Bzip2 block exceeds its declared block-size level");i.fill(g,a,a+h),a+=h},f=s.length+1,m=c();while(m!==f){if(m===0||m===1){let T=0,y=1;do{if(T+=m===0?y:y*2,T>t||y>t)throw new j("Invalid bzip2 RLE run length");y*=2,m=c()}while(m===0||m===1);if(d(r[0],T),m===f)break}let g=m-1;if(g<0||g>=r.length)throw new j("Invalid bzip2 MTF symbol");let h=r[g];r.copyWithin(1,0,g),r[0]=h,d(h,1),m=c()}return i.slice(0,a)}function vWr(e,t){if(e.length===0||t<0||t>=e.length)throw new j("Invalid bzip2 BWT origin pointer");let s=new Uint32Array(257);for(let a of e)s[a+1]++;for(let a=1;a<s.length;a++)s[a]+=s[a-1];let n=new Uint32Array(s.subarray(0,256)),o=new Uint32Array(e.length);for(let a=0;a<e.length;a++){let l=e[a];o[n[l]]=a,n[l]++}let r=new Uint8Array(e.length),i=o[t];for(let a=0;a<r.length;a++)r[a]=e[i],i=o[i];return r}function IWr(e,t,s){let n=4294967295,o=-1,r=0,i=0,a=0,l=(p)=>{s.push(p),n=jjs(n,p)},u=(p,c)=>{s.pushRepeated(p,c);for(let d=0;d<c;d++)n=jjs(n,p)};for(let p of e){if(t){if(a===0)a=SWr[i],i=i+1&511;if(a--,a===1)p^=1}if(r===4){u(o,p),r=0;continue}if(l(p),p===o)r++;else o=p,r=1}if(r===4)throw new j("Truncated bzip2 RLE run");return(n^4294967295)>>>0}function OWr(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid bzip2 output limit");let s=new zjs(e),n=new Kjs(t,e.byteLength);for(;;){let o=EWr(s),r=0;for(;;){let i=s.readMarker();if($js(i,CWr)){let R=s.readUint32();if(r!==R)throw new j("Bzip2 stream CRC mismatch");s.alignToByte();break}if(!$js(i,RWr))throw new j("Invalid bzip2 block marker");let a=s.readUint32(),l=s.readBit()!==0,u=s.readBits(24),p=s.readBits(16),c=new Uint8Array(256),d=0;for(let R=0;R<16;R++){if((p&32768>>>R)===0)continue;for(let C=0;C<16;C++)if(s.readBit()!==0)c[d++]=R*16+C}if(d===0)throw new j("Bzip2 block has an empty symbol map");let f=c.slice(0,d),{selectors:m,tables:g}=MWr(s,f),h=AWr(s,o,f,m,g),T=vWr(h,u),y=IWr(T,l,n);if(y!==a)throw new j("Bzip2 block CRC mismatch");r=((r<<1|r>>>31)^y)>>>0}if(s.done)return n.finish()}}function BPe(e){return e.byteLength>=4&&e[0]===66&&e[1]===90&&e[2]===104&&e[3]>=49&&e[3]<=57}async function T0(e,t){try{return OWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}}var RWr,CWr,gW=20,bWr=18002,kWr=50,SWr,wWr;var tae=S(()=>{Ur();RWr=[49,65,89,38,83,89],CWr=[23,114,69,56,80,144],SWr=new Uint16Array([619,720,127,481,931,816,813,233,566,247,985,724,205,454,863,491,741,242,949,214,733,859,335,708,621,574,73,654,730,472,419,436,278,496,867,210,399,680,480,51,878,465,811,169,869,675,611,697,867,561,862,687,507,283,482,129,807,591,733,623,150,238,59,379,684,877,625,169,643,105,170,607,520,932,727,476,693,425,174,647,73,122,335,530,442,853,695,249,445,515,909,545,703,919,874,474,882,500,594,612,641,801,220,162,819,984,589,513,495,799,161,604,958,533,221,400,386,867,600,782,382,596,414,171,516,375,682,485,911,276,98,553,163,354,666,933,424,341,533,870,227,730,475,186,263,647,537,686,600,224,469,68,770,919,190,373,294,822,808,206,184,943,795,384,383,461,404,758,839,887,715,67,618,276,204,918,873,777,604,560,951,160,578,722,79,804,96,409,713,940,652,934,970,447,318,353,859,672,112,785,645,863,803,350,139,93,354,99,820,908,609,772,154,274,580,184,79,626,630,742,653,282,762,623,680,81,927,626,789,125,411,521,938,300,821,78,343,175,128,250,170,774,972,275,999,639,495,78,352,126,857,956,358,619,580,124,737,594,701,612,669,112,134,694,363,992,809,743,168,974,944,375,748,52,600,747,642,182,862,81,344,805,988,739,511,655,814,334,249,515,897,955,664,981,649,113,974,459,893,228,433,837,553,268,926,240,102,654,459,51,686,754,806,760,493,403,415,394,687,700,946,670,656,610,738,392,760,799,887,653,978,321,576,617,626,502,894,679,243,440,680,879,194,572,640,724,926,56,204,700,707,151,457,449,797,195,791,558,945,679,297,59,87,824,713,663,412,693,342,606,134,108,571,364,631,212,174,643,304,329,343,97,430,751,497,314,983,374,822,928,140,206,73,263,980,736,876,478,430,305,170,514,364,692,829,82,855,953,676,246,369,970,294,750,807,827,150,790,288,923,804,378,215,828,592,281,565,555,710,82,896,831,547,261,524,462,293,465,502,56,661,821,976,991,658,869,905,758,745,193,768,550,608,933,378,286,215,979,792,961,61,688,793,644,986,403,106,366,905,644,372,567,466,434,645,210,389,550,919,135,780,773,635,389,707,100,626,958,165,504,920,176,193,713,857,265,203,50,668,108,645,990,626,197,510,357,358,850,858,364,936,638]),wWr=xWr()});import{promisify as Yjs}from"util";import*as WPe from"zlib";function GPe(e){return e.byteLength>=2&&e[0]===31&&e[1]===139}async function hW(e,t){try{return await FWr(e,{maxOutputLength:Math.max(t,1)})}catch(s){throw new j(s instanceof Error?s.message:String(s))}}function Jjs(e){return PWr(e)}var PWr,FWr;var sae=S(()=>{Ur();PWr=Yjs(WPe.gzip),FWr=Yjs(WPe.gunzip)});class Zjs{bytes;pos=0;range=4294967295;code=0;constructor(e){if(this.bytes=e,e.byteLength<5||e[0]!==0)throw new j("Invalid LZMA range-coded stream");for(let t=0;t<5;t++)this.code=(this.code<<8|e[this.pos++])>>>0}#e(){if(this.range<_Wr){if(this.pos>=this.bytes.byteLength)throw new j("Invalid LZMA stream: truncated range data");this.range=this.range<<8>>>0,this.code=(this.code<<8|this.bytes[this.pos++])>>>0}}decodeBit(e,t){this.#e();let s=e[t],n=Math.imul(this.range>>>11,s)>>>0;if(this.code<n)return this.range=n,e[t]=s+(zf-s>>>Xjs),0;return this.range=this.range-n>>>0,this.code=this.code-n>>>0,e[t]=s-(s>>>Xjs),1}decodeDirectBits(e){let t=0;for(let s=0;s<e;s++){this.#e(),this.range>>>=1;let n=0;if(this.code>=this.range)this.code=this.code-this.range>>>0,n=1;t=(t<<1|n)>>>0}return t}}function Ym(e){let t=new Uint16Array(e);return t.fill(zf>>>1),t}class Mht{choice=Ym(2);low=Ym($Pe<<3);mid=Ym($Pe<<3);high=Ym(256);reset(){this.choice.fill(zf>>>1),this.low.fill(zf>>>1),this.mid.fill(zf>>>1),this.high.fill(zf>>>1)}decode(e,t){if(e.decodeBit(this.choice,0)===0)return jPe(e,this.low,t<<3,3);if(e.decodeBit(this.choice,1)===0)return 8+jPe(e,this.mid,t<<3,3);return 16+jPe(e,this.high,0,8)}}function jPe(e,t,s,n){let o=1;for(let r=0;r<n;r++)o=o<<1|e.decodeBit(t,s+o);return o-(1<<n)}function Qjs(e,t,s,n){let o=1,r=0;for(let i=0;i<n;i++){let a=e.decodeBit(t,s+o);o=o<<1|a,r|=a<<i}return r>>>0}function e$s(e){if(e.byteLength!==5)throw new j("Invalid LZMA properties: expected 5 bytes");let t=e[0];if(t>=225)throw new j("Invalid LZMA properties");let s=t%9;t=Math.floor(t/9);let n=t%5,o=Math.floor(t/5),r=(e[1]|e[2]<<8|e[3]<<16|e[4]<<24)>>>0;return{lc:s,lp:n,pb:o,dictionarySize:Math.max(r,4096)}}class zPe{#e;#t;#s=0;#n=0;#o=0;#r=0;#a=0;#i=0;#l=0;#u=1;#p=1;#c=1;#d=1;#m=Ym(xht);#f=Ym(u6*$Pe);#h=Ym(u6);#T=Ym(u6);#g=Ym(u6);#y=Ym(u6);#R=Ym(u6*$Pe);#C=Ym(256);#k=Ym(115);#S=Ym(16);#b=new Mht;#x=new Mht;constructor(e,t){this.#e=e,this.#t=t.dictionarySize,this.setProperties(t.lc,t.lp,t.pb),this.resetDictionary()}get outputPos(){return this.#s}setProperties(e,t,s){if(e>8||t>4||s>4||e+t>12)throw new j("Invalid LZMA properties");this.#r=e,this.#a=t,this.#i=s;let n=xht*2**(e+t);if(this.#m.length!==n)this.#m=Ym(n)}resetDictionary(){this.#n=this.#s,this.#o=0,this.resetState()}resetState(){this.#l=0,this.#u=this.#p=this.#c=this.#d=1,this.#m.fill(zf>>>1),this.#f.fill(zf>>>1),this.#h.fill(zf>>>1),this.#T.fill(zf>>>1),this.#g.fill(zf>>>1),this.#y.fill(zf>>>1),this.#R.fill(zf>>>1),this.#C.fill(zf>>>1),this.#k.fill(zf>>>1),this.#S.fill(zf>>>1),this.#b.reset(),this.#x.reset()}appendUncompressed(e,t){if(t)this.resetDictionary();if(e.byteLength>this.#e.byteLength-this.#s)throw new j("LZMA2 output exceeds its limit");this.#e.set(e,this.#s),this.#s+=e.byteLength,this.#o+=e.byteLength}decodeChunk(e,t,s=!1){if(!Number.isSafeInteger(t)||t<0||t>this.#e.byteLength-this.#s)throw new j("LZMA output exceeds its declared size");let n=this.#s+t,o=new Zjs(e),r=(1<<this.#i)-1,i=(1<<this.#a)-1;while(this.#s<n||s){let a=this.#o&r;if(o.decodeBit(this.#f,(this.#l<<4)+a)===0){let u=this.#s===this.#n?0:this.#e[this.#s-1],p=(((this.#o&i)<<this.#r)+(u>>>8-this.#r))*xht,c=1;if(this.#l>=7){this.#E(this.#u);let d=this.#e[this.#s-this.#u];while(c<256){let f=d>>>7&1;d=d<<1&255;let m=o.decodeBit(this.#m,p+(1+f<<8)+c);if(c=c<<1|m,f!==m)break}}while(c<256)c=c<<1|o.decodeBit(this.#m,p+c);if(this.#s>=n)throw new j("LZMA output exceeds its size limit before the end marker");this.#e[this.#s++]=c&255,this.#o++,this.#l=this.#l<4?0:this.#l<10?this.#l-3:this.#l-6;continue}let l;if(o.decodeBit(this.#h,this.#l)===1){if(o.decodeBit(this.#T,this.#l)===0){if(o.decodeBit(this.#R,(this.#l<<4)+a)===0){this.#l=this.#l<7?9:11,this.#w(this.#u,1,n);continue}}else{let u;if(o.decodeBit(this.#g,this.#l)===0)u=this.#p;else{if(o.decodeBit(this.#y,this.#l)===0)u=this.#c;else u=this.#d,this.#d=this.#c;this.#c=this.#p}this.#p=this.#u,this.#u=u}l=this.#x.decode(o,a)+Eht,this.#l=this.#l<7?8:11}else{this.#d=this.#c,this.#c=this.#p,this.#p=this.#u,l=this.#b.decode(o,a)+Eht,this.#l=this.#l<7?7:10;let u=Math.min(l-Eht,3),p=jPe(o,this.#C,u<<6,6),c;if(p<4)c=p;else{let d=(p>>>1)-1;if(c=(2|p&1)<<d>>>0,p<14)c=c+Qjs(o,this.#k,c-p,d)>>>0;else if(c=c+(o.decodeDirectBits(d-4)<<4)>>>0,c=c+Qjs(o,this.#S,0,4)>>>0,c===4294967295){if(s)return!0;throw new j("LZMA stream ended before its declared output size")}}this.#u=c+1>>>0}this.#w(this.#u,l,n)}return!1}#E(e){let t=this.#s-this.#n;if(e<1||e>t||e>this.#t)throw new j(`Invalid LZMA match distance ${e} with ${t} bytes available`)}#w(e,t,s){if(this.#E(e),t>s-this.#s)throw new j("LZMA match exceeds its declared output size");for(let n=0;n<t;n++)this.#e[this.#s]=this.#e[this.#s-e],this.#s++;this.#o+=t}}async function nae(e,t,s){if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid LZMA output size");try{let n=new Uint8Array(s),o=new zPe(n,e$s(e));if(o.decodeChunk(t,s),o.outputPos!==s)throw new j("LZMA output size mismatch");return n}catch(n){if(n instanceof j)throw n;throw new j(`Invalid LZMA stream: ${n instanceof Error?n.message:String(n)}`)}}async function p6(e,t){if(e.byteLength<13)throw new j("Invalid LZMA-alone stream: truncated header");if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid LZMA output limit");let s=e.subarray(0,5),n=!0,o=0;for(let r=0;r<8;r++){let i=e[5+r];if(i!==255)n=!1;o+=i*2**(r*8)}if(!n){if(!Number.isSafeInteger(o)||o>t)throw new j("LZMA-alone output exceeds its size limit");return nae(s,e.subarray(13),o)}try{let r=new Uint8Array(t),i=new zPe(r,e$s(s));if(!i.decodeChunk(e.subarray(13),t,!0))throw new j("LZMA-alone output exceeds its size limit before the end marker");return r.subarray(0,i.outputPos)}catch(r){if(r instanceof j)throw r;throw new j(`Invalid LZMA-alone stream: ${r instanceof Error?r.message:String(r)}`)}}async function KPe(e,t,s){if(!Number.isInteger(e)||e<0||e>40)throw new j("Unsupported LZMA2 dictionary property");if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid LZMA2 output limit");let n=e===40?4294967295:(2|e&1)*2**(Math.floor(e/2)+11),o=new Uint8Array(s),r=new zPe(o,{lc:3,lp:0,pb:2,dictionarySize:n}),i=0,a=!0,l=!1,u=()=>{if(i>=t.byteLength)throw new j("Invalid LZMA2 stream: truncated chunk header");return t[i++]};try{for(;;){let p=u();if(p===0)break;if(p<128){if(p!==1&&p!==2)throw new j(`Invalid LZMA2 control byte 0x${p.toString(16)}`);if(p===2&&a)throw new j("Invalid LZMA2 stream: dictionary was not initialized");let h=(u()<<8)+u()+1;if(h>s-r.outputPos||h>t.byteLength-i)throw new j("Invalid LZMA2 uncompressed chunk size");if(r.appendUncompressed(t.subarray(i,i+h),p===1),i+=h,p===1)a=!1,l=!1;continue}let c=((p&31)<<16)+(u()<<8)+u()+1,d=(u()<<8)+u()+1,f=p>=224,m=p>=160,g=p>=192;if(a&&!f)throw new j("Invalid LZMA2 stream: dictionary was not initialized");if(!l&&!g)throw new j("Invalid LZMA2 stream: properties were not initialized");if(g){let h=u();if(h>=225)throw new j("Invalid LZMA2 properties");let T=h%9;h=Math.floor(h/9);let y=h%5,R=Math.floor(h/5);if(T+y>4)throw new j("Invalid LZMA2 literal properties");r.setProperties(T,y,R),l=!0}if(d>t.byteLength-i||c>s-r.outputPos)throw new j("Invalid LZMA2 chunk size");if(f)r.resetDictionary();else if(m)r.resetState();r.decodeChunk(t.subarray(i,i+d),c),i+=d,a=!1}if(i!==t.byteLength)throw new j("Invalid LZMA2 stream: trailing data");return o.subarray(0,r.outputPos)}catch(p){if(p instanceof j)throw p;throw new j(`Invalid LZMA2 stream: ${p instanceof Error?p.message:String(p)}`)}}var _Wr=16777216,zf=2048,Xjs=5,xht=768,u6=12,$Pe=16,Eht=2;var TW=S(()=>{Ur()});class s$s{#e;#t=0;#s=0;constructor(e){this.#e=e}get remainingBits(){return this.#e.byteLength*8-this.#t}read(e){if(this.remainingBits<e)return;let t=0;for(let s=0;s<e;s++){let n=this.#t+s;t+=(this.#e[n>>>3]>>>(n&7)&1)*2**s}return this.#t+=e,t}alignCodeGroup(e){let t=e*8,s=this.#s+Math.ceil((this.#t-this.#s)/t)*t;if(s>this.#e.byteLength*8)throw new j("Truncated compress (.Z) code group");this.#t=s,this.#s=s}assertFinalPadding(){this.#n(this.#e.byteLength*8)}#n(e){for(let t=this.#t;t<e;t++)if((this.#e[t>>>3]>>>(t&7)&1)!==0)throw new j("Invalid non-zero compress (.Z) padding")}}class n$s{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=new Uint8Array(Math.min(e,Math.max(64,Math.min(t*2,65536))))}appendReversed(e,t){this.#n(t);for(let s=t-1;s>=0;s--)this.#t[this.#s++]=e[s]}finish(){return this.#t.slice(0,this.#s)}#n(e){let t=this.#s+e;if(!Number.isSafeInteger(t)||t>this.#e)throw new j(`Compress (.Z) output exceeds the ${this.#e}-byte limit`);if(t<=this.#t.byteLength)return;let s=Math.max(t,Math.min(this.#e,Math.max(64,this.#t.byteLength*2)));if(s>this.#e)s=this.#e;let n=new Uint8Array(s);n.set(this.#t.subarray(0,this.#s)),this.#t=n}}function NWr(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid compress (.Z) output limit");if(e.byteLength<3)throw new j("Truncated compress (.Z) header");if(e[0]!==31||e[1]!==157)throw new j("Invalid compress (.Z) header");let s=e[2];if((s&96)!==0)throw new j("Unsupported compress (.Z) header flags");let n=s&31;if(n<Aht||n>DWr)throw new j(`Invalid compress (.Z) maximum code width ${n}`);let o=(s&128)!==0,r=2**n,i=new Uint16Array(r),a=new Uint8Array(r),l=new Uint8Array(r),u=new s$s(e.subarray(3)),p=new n$s(t,e.byteLength),c=Aht,d=o?t$s:256,f=!1;for(;;){let m=u.read(c);if(m===void 0)return u.assertFinalPadding(),p.finish();if(m>=d)throw new j(`Corrupt compress (.Z) dictionary code ${m}`);if(o&&m===LWr){u.alignCodeGroup(c),c=Aht,d=t$s,f=!1;continue}let g=m,h=0;while(g>=256){if(g>=d||h>=l.length-1)throw new j("Corrupt compress (.Z) dictionary chain");l[h++]=a[g],g=i[g]}if(l[h++]=g,f){if(a[d-1]=g,m===d-1)l[0]=g}if(p.appendReversed(l,h),d<r){if(f=!0,i[d++]=m,d>2**c&&c<n)u.alignCodeGroup(c),c++}else f=!1}}function o$s(e){return e.byteLength>=2&&e[0]===31&&e[1]===157}async function vht(e,t){try{return NWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}}var LWr=256,t$s=257,Aht=9,DWr=16;var r$s=S(()=>{Ur()});function SS(e,t){if(t<0||t+4>e.byteLength)throw new j("Invalid XZ stream: truncated integer");return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function YPe(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24}function i$s(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function qWr(e,t,s){e[t]=s>>>24,e[t+1]=s>>>16&255,e[t+2]=s>>>8&255,e[t+3]=s&255}function Iht(e,t){if(e.byteLength!==t.byteLength)return!1;for(let s=0;s<e.byteLength;s++)if(e[s]!==t[s])return!1;return!0}function yW(e){let t=0;for(let s=0;s<9;s++){if(e.pos>=e.limit)throw new j("Invalid XZ stream: truncated variable-length integer");let n=e.bytes[e.pos++];if(s>0&&n===0)throw new j("Invalid XZ stream: non-canonical variable-length integer");if(t+=(n&127)*2**(s*7),!Number.isSafeInteger(t))throw new j("XZ stream uses sizes too large to read safely");if((n&128)===0)return t}throw new j("Invalid XZ stream: variable-length integer is too long")}function a$s(e){switch(e){case 0:return 0;case 1:return 4;case 4:return 8;case 10:return 32;default:throw new j(`Unsupported XZ integrity check ID 0x${e.toString(16)}`)}}function UWr(e,t,s){if(s<8||t<0||t+s>e.byteLength)throw new j("Invalid XZ stream: index range is invalid");let n=t+s;if(e[t]!==0)throw new j("Invalid XZ stream: missing index indicator");if(Wi(e.subarray(t,n-4))!==SS(e,n-4))throw new j("Invalid XZ stream: index CRC32 mismatch");let o={bytes:e,pos:t+1,limit:n-4},r=yW(o);if(r>Math.floor(s/2))throw new j("Invalid XZ stream: impossible index record count");let i=[];for(let a=0;a<r;a++){let l=yW(o),u=yW(o);if(l===0)throw new j("Invalid XZ stream: zero unpadded block size");i.push({unpaddedSize:l,uncompressedSize:u})}while(o.pos<o.limit)if(e[o.pos++]!==0)throw new j("Invalid XZ stream: non-zero index padding");return i}function HWr(e){if(e.byteLength===0||(e.byteLength&3)!==0)throw new j("Invalid XZ stream: size is not a multiple of four bytes");let t=[],s=e.byteLength;while(s>0){let n=0;while(s>=4&&e[s-1]===0&&e[s-2]===0&&e[s-3]===0&&e[s-4]===0)s-=4,n+=4;if(s===0)throw new j("Invalid XZ stream: padding without a stream");if(s<24)throw new j("Invalid XZ stream: truncated stream framing");let o=s-12;if(e[o+10]!==89||e[o+11]!==90)throw new j("Invalid XZ stream: footer magic mismatch");if(Wi(e.subarray(o+4,o+10))!==SS(e,o))throw new j("Invalid XZ stream: footer CRC32 mismatch");let r=e[o+8],i=e[o+9];if(r!==0||(i&240)!==0)throw new j("Unsupported XZ stream flags");let a=i&15;a$s(a);let l=(SS(e,o+4)+1)*4;if(!Number.isSafeInteger(l)||l>o)throw new j("Invalid XZ stream: backward index size is invalid");let u=o-l,p=UWr(e,u,l),c=0;for(let f of p)if(c+=Math.ceil(f.unpaddedSize/4)*4,!Number.isSafeInteger(c))throw new j("XZ stream uses sizes too large to read safely");let d=u-c-12;if(d<0||d+12>e.byteLength||!Iht(e.subarray(d,d+6),VPe))throw new j("Invalid XZ stream: header position or magic is invalid");if(e[d+6]!==r||e[d+7]!==i)throw new j("Invalid XZ stream: header and footer flags differ");if(Wi(e.subarray(d+6,d+8))!==SS(e,d+8))throw new j("Invalid XZ stream: header CRC32 mismatch");t.unshift({start:d,indexStart:u,footerStart:o,checkId:a,records:p}),s=d}return t}function BWr(e,t){let s=new Uint8Array(256),n=0;for(let o=0;o<e.byteLength;o++){let r=e[o]+s[t+n&255]&255;s[n]=r,e[o]=r,n=n-1&255}}function WWr(e,t){let s=[0,1,2,2,3],n=0,o=4294967291;if(e.byteLength<5)return;let r=0,i=e.byteLength-5;while(r<=i){let a=e[r];if(a!==232&&a!==233){r++;continue}let l=t+r>>>0,u=l-o>>>0;if(o=l,u>5)n=0;else for(let p=0;p<u;p++)n=(n&119)<<1>>>0;if(a=e[r+4],(a===0||a===255)&&n>>>1<=4&&n>>>1!==3){let p=SS(e,r+1),c=0;for(;;){if(c=p-l-5>>>0,n===0)break;let d=s[n>>>1]*8,f=c>>>24-d&255;if(f!==0&&f!==255)break;let m=d===0?4294967295:2**(32-d)-1;p=(c^m)>>>0}e[r+4]=~((c>>>24&1)-1)&255,e[r+3]=c>>>16,e[r+2]=c>>>8,e[r+1]=c,r+=5,n=0}else if(r++,n|=1,a===0||a===255)n|=16}}function GWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(e[s]>>>2!==18||(e[s+3]&3)!==1)continue;let o=(((e[s]&3)<<24|e[s+1]<<16|e[s+2]<<8|e[s+3]&252)>>>0)-t-s>>>0;e[s]=72|o>>>24&3,e[s+1]=o>>>16,e[s+2]=o>>>8,e[s+3]=e[s+3]&3|o&252}}function jWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(e[s+3]!==235)continue;let o=((e[s+2]<<18|e[s+1]<<10|e[s]<<2)>>>0)-t-s-8>>>2;e[s]=o,e[s+1]=o>>>8,e[s+2]=o>>>16}}function $Wr(e,t){for(let s=0;s+4<=e.byteLength;s+=2){if((e[s+1]&248)!==240||(e[s+3]&248)!==248)continue;let o=(((e[s+1]&7)<<19|e[s]<<11|(e[s+3]&7)<<8|e[s+2])<<1>>>0)-t-s-4>>>1;e[s+1]=240|o>>>19&7,e[s]=o>>>11,e[s+3]=248|o>>>8&7,e[s+2]=o,s+=2}}function zWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(!(e[s]===64&&(e[s+1]&192)===0||e[s]===127&&(e[s+1]&192)===192))continue;let o=(i$s(e,s)<<2>>>0)-t-s>>>2;o=0-(o>>>22&1)<<22&1073741823|o&4194303|1073741824,qWr(e,s,o>>>0)}}function KWr(e,t){let s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,6,6,0,0,7,7,4,4,0,0,4,4,0,0];for(let n=0;n+16<=e.byteLength;n+=16){let o=s[e[n]&31],r=5;for(let i=0;i<3;i++,r+=41){if((o>>>i&1)===0)continue;let a=r>>>3,l=r&7,u=0n;for(let f=0;f<6;f++)u|=BigInt(e[n+a+f])<<BigInt(f*8);let p=u>>BigInt(l);if((p>>37n&15n)!==5n||(p>>9n&7n)!==0n)continue;let c=Number(p>>13n&0xfffffn)|Number(p>>36n&1n)<<20;c=c<<4>>>0;let d=c-t-n>>>4>>>0;p&=~(0x8fffffn<<13n),p|=BigInt(d&1048575)<<13n,p|=BigInt(d&1048576)<<16n,u&=(1n<<BigInt(l))-1n,u|=p<<BigInt(l);for(let f=0;f<6;f++)e[n+a+f]=Number(u>>BigInt(f*8))&255}}}function VWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){let n=t+s>>>0,o=SS(e,s);if(o>>>26===37)o=(2483027968|o-(n>>>2)&67108863)>>>0,YPe(e,s,o);else if((o&2667577344)===2415919104){let r=o>>>29&3|o>>>3&2097148;if((r+131072&1835008)!==0)continue;let i=r-(n>>>12)>>>0;o&=2415919135,o|=(i&3)<<29,o|=(i&262140)<<3,o|=0-(i&131072)&14680064,YPe(e,s,o>>>0)}}}function YWr(e,t){if(e.byteLength<8)return;for(let s=0;s<=e.byteLength-8;s+=2){let n=e[s];if(n===239){let r=e[s+1];if((r&13)!==0)continue;let i=((r&240)<<13|e[s+2]<<9|e[s+3]<<1)-t-s>>>0;e[s+1]=r&15|i>>>8&240,e[s+2]=i>>>16&15|i>>>7&16|i<<4&224,e[s+3]=i>>>4&127|i>>>13&128,s+=2;continue}if((n&127)!==23)continue;n=SS(e,s);let o;if((n&3712)!==0){if(o=SS(e,s+4),(n<<8^o-3&1015811)!==0){s+=4;continue}let r=(n&4294963200)+(o>>>20);n=(279|o<<12)>>>0,o=r>>>0}else{let r=n>>>27;if(n-12567<<18>>>0>=(r&29)){s+=2;continue}let i=i$s(e,s+4)-t-s>>>0;o=(n>>>12|i<<20)>>>0,n=(23|r<<7|i+2048&4294963200)>>>0}YPe(e,s,n),YPe(e,s+4,o),s+=6}}function JWr(e,t){if(t.id===3){if(t.properties.byteLength!==1)throw new j("Invalid XZ Delta filter properties");BWr(e,t.properties[0]+1);return}if(t.properties.byteLength!==0&&t.properties.byteLength!==4)throw new j(`Invalid XZ BCJ filter 0x${t.id.toString(16)} properties`);let s=t.properties.byteLength===4?SS(t.properties,0):0,n=t.id===6?16:t.id===8||t.id===11?2:t.id===4?1:4;if((s&n-1)!==0)throw new j(`Invalid XZ BCJ filter 0x${t.id.toString(16)} start offset`);switch(t.id){case 4:WWr(e,s);break;case 5:GWr(e,s);break;case 6:KWr(e,s);break;case 7:jWr(e,s);break;case 8:$Wr(e,s);break;case 9:zWr(e,s);break;case 10:VWr(e,s);break;case 11:YWr(e,s);break;default:throw new j(`Unsupported XZ filter ID 0x${t.id.toString(16)}`)}}function XWr(e,t,s){if(e===0)return;if(e===1){if(SS(s,0)!==Wi(t))throw new j("Invalid XZ stream: block CRC32 mismatch");return}if(e===4){let o=njs(t),r=0n;for(let i=0;i<8;i++)r|=BigInt(s[i])<<BigInt(i*8);if(o!==r)throw new j("Invalid XZ stream: block CRC64 mismatch");return}let n=new Uint8Array(new Bun.CryptoHasher("sha256").update(t).digest());if(!Iht(n,s))throw new j("Invalid XZ stream: block SHA-256 mismatch")}async function QWr(e,t,s,n){if(t>=e.byteLength||e[t]===0)throw new j("Invalid XZ stream: missing block header");let o=(e[t]+1)*4;if(t+o>e.byteLength||o<8)throw new j("Invalid XZ stream: truncated block header");if(Wi(e.subarray(t,t+o-4))!==SS(e,t+o-4))throw new j("Invalid XZ stream: block header CRC32 mismatch");let r={bytes:e,pos:t+1,limit:t+o-4},i=e[r.pos++];if((i&60)!==0)throw new j("Unsupported XZ block flags");let a=(i&3)+1,l=(i&64)!==0?yW(r):void 0,u=(i&128)!==0?yW(r):void 0,p=[];for(let C=0;C<a;C++){let b=yW(r),w=yW(r);if(w>r.limit-r.pos)throw new j("Invalid XZ stream: truncated filter properties");p.push({id:b,properties:e.slice(r.pos,r.pos+w)}),r.pos+=w}while(r.pos<r.limit)if(e[r.pos++]!==0)throw new j("Invalid XZ stream: non-zero block header padding");let c=a$s(n),d=s.unpaddedSize-o-c;if(!Number.isSafeInteger(d)||d<=0)throw new j("Invalid XZ stream: compressed block size is invalid");if(l!==void 0&&l!==d)throw new j("Invalid XZ stream: block compressed size mismatch");if(u!==void 0&&u!==s.uncompressedSize)throw new j("Invalid XZ stream: block uncompressed size mismatch");let f=t+o,m=f+d,g=4-(o+d&3)&3,h=m+g;if(h+c>e.byteLength)throw new j("Invalid XZ stream: truncated block data");let T=p[p.length-1];if(T.id!==33||T.properties.byteLength!==1)throw new j(`Unsupported XZ terminal filter ID 0x${T.id.toString(16)} (LZMA2 required)`);let y=await KPe(T.properties[0],e.subarray(f,m),s.uncompressedSize);if(y.byteLength!==s.uncompressedSize)throw new j("Invalid XZ stream: decoded block size mismatch");y=y.slice();for(let C=p.length-2;C>=0;C--)JWr(y,p[C]);for(let C=m;C<h;C++)if(e[C]!==0)throw new j("Invalid XZ stream: non-zero block padding");XWr(n,y,e.subarray(h,h+c));let R=t+Math.ceil(s.unpaddedSize/4)*4;if(h+c!==R)throw new j("Invalid XZ stream: block size does not match its index record");return y}function JPe(e){return e.byteLength>=VPe.byteLength&&Iht(e.subarray(0,VPe.byteLength),VPe)}async function y0(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid XZ output limit");try{let s=HWr(e),n=0;for(let i of s)for(let a of i.records)if(n+=a.uncompressedSize,!Number.isSafeInteger(n)||n>t)throw new j("XZ output exceeds its size limit");let o=new Uint8Array(n),r=0;for(let i of s){let a=i.start+12;for(let l of i.records){let u=await QWr(e,a,l,i.checkId);o.set(u,r),r+=u.byteLength,a+=Math.ceil(l.unpaddedSize/4)*4}if(a!==i.indexStart)throw new j("Invalid XZ stream: blocks do not align with index")}return o}catch(s){if(s instanceof j)throw s;throw new j(`Invalid XZ stream: ${s instanceof Error?s.message:String(s)}`)}}var VPe;var oae=S(()=>{m0();Ur();TW();VPe=Uint8Array.of(253,55,122,88,90,0)});import{promisify as l$s}from"util";import*as XPe from"zlib";function QPe(e){return e.byteLength>=4&&e[0]===40&&e[1]===181&&e[2]===47&&e[3]===253}async function R0(e,t){try{return await e2r(e,{maxOutputLength:Math.max(t,1)})}catch(s){throw new j(s instanceof Error?s.message:String(s))}}function u$s(e){return ZWr(e)}var ZWr,e2r;var c6=S(()=>{Ur();ZWr=l$s(XPe.zstdCompress),e2r=l$s(XPe.zstdDecompress)});import*as eFe from"path";class Fht{#e;#t;#s;#n;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}async read(e,t){if(e!==this.#s)throw new j(`CPIO member '${t}' has an inconsistent declared size`);let s=this.#t+this.#s;if(s>this.#e.byteLength)throw new j(`CPIO member '${t}' is truncated`);let n=this.#e.subarray(this.#t,s);if(this.#n!==void 0&&h$s(n)!==this.#n)throw new j(`CPIO member '${t}' has an invalid CRC checksum`);return n}}function h$s(e){let t=0;for(let s of e)t=t+s>>>0;return t}function g$s(e,t){let s=e%t;return s===0?e:e+t-s}function C0(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid CPIO archive: truncated ${n}`)}function ZPe(e,t,s,n,o){C0(e,t,t+s,`${o} field`);let r=0;for(let i=t;i<t+s;i++){let a=e[i],l;if(a>=48&&a<=57)l=a-48;else if(n===16&&a>=65&&a<=70)l=a-65+10;else if(n===16&&a>=97&&a<=102)l=a-97+10;else throw new j(`Invalid CPIO archive: ${o} is not a valid base-${n} number`);if(l>=n)throw new j(`Invalid CPIO archive: ${o} is not a valid base-${n} number`);r=r*n+l}if(!Number.isSafeInteger(r))throw new j(`Invalid CPIO archive: ${o} is too large`);return r}function T$s(e,t){C0(e,t,t+2,"header");let s=e[t],n=e[t+1];if(s===199&&n===113||s===113&&n===199){C0(e,t,t+d$s,"old binary header");let i=s===199?xn:Kie,a=(l)=>i(e,t+l)*65536+i(e,t+l+2);return{headerSize:d$s,alignment:2,devMajor:0,devMinor:i(e,t+2),inode:i(e,t+4),mode:i(e,t+6),nlink:i(e,t+12),mtime:a(16),nameSize:i(e,t+20),fileSize:a(22)}}C0(e,t,t+6,"magic");let o=String.fromCharCode(...e.subarray(t,t+6));if(o==="070701"||o==="070702"){C0(e,t,t+p$s,"new ASCII header");let r=(a,l)=>ZPe(e,t+6+a*8,8,16,l),i=r(12,"checksum");if(o==="070701"&&i!==0)throw new j("Invalid CPIO archive: newc checksum field must be zero");return{headerSize:p$s,alignment:4,inode:r(0,"inode"),mode:r(1,"mode"),nlink:r(4,"link count"),mtime:r(5,"modification time"),fileSize:r(6,"file size"),devMajor:r(7,"device major"),devMinor:r(8,"device minor"),nameSize:r(11,"name size"),checksum:o==="070702"?i:void 0}}if(o==="070707"){C0(e,t,t+c$s,"portable ASCII header");let r=(i,a)=>ZPe(e,t+i,6,8,a);return{headerSize:c$s,alignment:1,devMajor:0,devMinor:r(6,"device"),inode:r(12,"inode"),mode:r(18,"mode"),nlink:r(36,"link count"),mtime:ZPe(e,t+48,11,8,"modification time"),nameSize:r(59,"name size"),fileSize:ZPe(e,t+65,11,8,"file size")}}throw new j(`Invalid CPIO archive: unsupported or corrupt magic at offset ${t}`)}function y$s(e){try{return n2r.decode(e)}catch{return}}function Pht(e,t,s,n){for(let o=t;o<s;o++)if(e[o]!==0)throw new j(`Invalid CPIO archive: non-zero ${n} padding`)}function o2r(e,t,s){ko(t.byteLength,"link target",s);let n=y$s(t);if(n===void 0||n.includes("\x00"))throw new j(`Invalid CPIO archive: symlink '${e}' has an invalid UTF-8 target`);let o=n.replace(/\\/g,"/");if(eFe.posix.isAbsolute(o))return{path:o,resolveTarget:!1};let r=zd(eFe.posix.join(eFe.posix.dirname(e),o));return r===void 0?{path:o,resolveTarget:!1}:{path:r,resolveTarget:!0}}function _ht(e,t){ci(e.byteLength,t.limits);let s=[],n=0,o=0,r=!1;while(n<e.byteLength){let u=T$s(e,n);if(u.mode>65535)throw new j("Invalid CPIO archive: mode exceeds 16 bits");if(u.nameSize<1)throw new j("Invalid CPIO archive: name size must include a NUL terminator");ko(u.nameSize-1,"member path",t.limits.maxPathBytes),Qi(u.fileSize,"(CPIO entry)",t.limits);let p=n+u.headerSize,c=p+u.nameSize,d=g$s(c,u.alignment),f=d+u.fileSize,m=g$s(f,u.alignment);if(C0(e,p,c,"member name"),C0(e,d,f,"member data"),C0(e,f,m,"member padding"),e[c-1]!==0)throw new j("Invalid CPIO archive: member name is not NUL-terminated");for(let y=p;y<c-1;y++)if(e[y]===0)throw new j("Invalid CPIO archive: member name contains an embedded NUL");Pht(e,c,d,"name"),Pht(e,f,m,"data"),o+=d-n,Hn(o,t.limits,"CPIO index");let g=y$s(e.subarray(p,c-1));if(g===t2r){if(u.fileSize!==0)throw new j("Invalid CPIO archive: TRAILER!!! has non-empty data");r=!0,n=m;break}let h=u.mode&Oht;if((h===m$s||h===4096)&&u.fileSize!==0)throw new j("Invalid CPIO archive: directory or FIFO has non-empty data");or(s.length+1,t.limits);let T=g===void 0?void 0:Sr(g);s.push({path:T,mode:u.mode,mtimeMs:u.mtime*1000,nlink:u.nlink,inode:u.inode,devMajor:u.devMajor,devMinor:u.devMinor,fileSize:u.fileSize,dataOffset:d,checksum:u.checksum}),n=m}if(!r)throw new j("Invalid CPIO archive: missing TRAILER!!! terminator");Pht(e,n,e.byteLength,"trailing");let i=new Map,a=new Set,l=new Map;for(let u of s){if((u.mode&Oht)!==f$s||u.nlink<=1)continue;let p=`${u.devMajor}:${u.devMinor}:${u.inode}`,c=l.get(p);if(c)c.push(u);else l.set(p,[u])}for(let u of l.values()){if(u.length<2)continue;for(let f of u)a.add(f);let p=u.filter((f)=>f.path!==void 0);if(p.length===0)continue;let c=u.find((f)=>f.fileSize!==0)??u[0],d=p.find((f)=>f===c)??p[0];for(let f of p){let m={path:f.path,isDirectory:!1,size:c.fileSize,mtimeMs:f.mtimeMs,mode:f.mode,storage:f===d?{type:"member",source:new Fht(e,c.dataOffset,c.fileSize,c.checksum)}:{type:"link",targetPath:d.path,resolveTarget:!1}};yc(i,m)}}for(let u of s){if(a.has(u)||u.path===void 0)continue;let p=u.mode&Oht;if(p===m$s){yc(i,{path:u.path,isDirectory:!0,size:0,mtimeMs:u.mtimeMs,mode:u.mode});continue}if(p===s2r){let c=e.subarray(u.dataOffset,u.dataOffset+u.fileSize);if(u.checksum!==void 0&&h$s(c)!==u.checksum)throw new j(`CPIO symlink '${u.path}' has an invalid CRC checksum`);let d=o2r(u.path,c,t.limits.maxPathBytes);yc(i,{path:u.path,isDirectory:!1,size:0,mtimeMs:u.mtimeMs,mode:u.mode,storage:{type:"link",targetPath:d.path,resolveTarget:d.resolveTarget}});continue}if(p!==f$s)continue;yc(i,{path:u.path,isDirectory:!1,size:u.fileSize,mtimeMs:u.mtimeMs,mode:u.mode,storage:{type:"member",source:new Fht(e,u.dataOffset,u.fileSize,u.checksum)}})}return lD(i,t.limits),[...i.values()]}function rae(e){try{let t=T$s(e,0);if(t.mode>65535||t.nameSize<1)return!1;let s=t.headerSize+t.nameSize;return s<=e.byteLength&&e[s-1]===0}catch{return!1}}var p$s=110,c$s=76,d$s=26,t2r="TRAILER!!!",Oht=61440,f$s=32768,m$s=16384,s2r=40960,n2r,R$s=async(e,t)=>{try{return ci(e.size,t.limits),_ht(await eM(e),t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}};var Lht=S(()=>{Sh();uD();Ur();vp();Vd();tM();n2r=new TextDecoder("utf-8",{fatal:!0})});import*as aae from"path";class q$s{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){if(this.#s)throw new j(`Archive member '${dr(t)}' is a sparse file and cannot be read`);if(e>this.#e.byteLength-this.#t)throw new j(`Archive member '${dr(t)}' is truncated`);let s=this.#e.subarray(this.#t,this.#t+e);if(s.byteLength!==e)throw new j(`Archive member '${dr(t)}' has an invalid size`);return s}}function sFe(e,t,s){let n=Math.min(t+s,e.byteLength),o=t;while(o<n&&e[o]!==0)o++;return uae.decode(e.subarray(t,o))}function RW(e,t){return e.byteLength===t.length&&Ap(e,0,t)}function p2r(e,t){return Ap(e,t+L$s,qht)&&Ap(e,t+D$s,Uht)}function nFe(e,t,s){let n=e.indexOf(0),o=e.subarray(0,n===-1?e.byteLength:n);return ko(o.byteLength,t,s.maxPathBytes),uae.decode(o)}function k$s(e,t,s){return ko(e.byteLength,t,s.maxPathBytes),uae.decode(e)}function oFe(e,t,s){if(t<0||s<=0||t+s>e.byteLength)throw new j("Invalid tar numeric field");let n=e[t],o=0n;if((n&128)!==0){o=BigInt(n&127);for(let r=1;r<s;r++)o=o<<8n|BigInt(e[t+r]);if((n&64)!==0)o-=1n<<BigInt(s*8-1)}else for(let r=0;r<s;r++){let i=e[t+r];if(i>=48&&i<=55)o=o*8n+BigInt(i-48)}return Number(o)}function U$s(e,t){let s=oFe(e,t,O$s);if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid tar member size");return s}function rFe(e){let t=e%wS,s=e+(t===0?0:wS-t);if(!Number.isSafeInteger(s))throw new j("Invalid tar member size");return s}function S$s(e,t){if(!/^\d+$/.test(e))throw new j(`Invalid tar ${t}`);let s=Number(e);if(!Number.isSafeInteger(s)||s<0)throw new j(`Invalid tar ${t}`);return s}function H$s(e,t){for(let s=0;s<wS;s++)if(e[t+s]!==0)return!1;return!0}function B$s(e,t){let s=oFe(e,t+pD,Nht),n=0,o=0;for(let r=0;r<wS;r++){let a=r>=pD&&r<pD+Nht?32:e[t+r]??0;n+=a,o+=a<<24>>24}return s===n||s===o}function w$s(e,t){Hn(e.byteLength,t,"tar PAX metadata");let s=new Map,n=0;while(n<e.byteLength){let o=n;while(o<e.byteLength&&e[o]!==32)o++;if(o===n||o>=e.byteLength||o-n>16)throw new j("Invalid tar PAX record");let r=0;for(let l=n;l<o;l++){let u=e[l];if(u<48||u>57)throw new j("Invalid tar PAX record");if(r=r*10+(u-48),r>e.byteLength-n)throw new j("Invalid tar PAX record")}if(r<=0||n+r>e.byteLength||e[n+r-1]!==10)throw new j("Invalid tar PAX record");let i=e.subarray(o+1,n+r-1),a=i.indexOf(61);if(a>=0){let l=i.subarray(0,a),u=i.subarray(a+1);if(Ap(l,0,Hht)){if(s.set(Hht,u.byteLength===0?"":"1"),RW(l,"GNU.sparse.name"))s.set("GNU.sparse.name",k$s(u,"PAX sparse path",t));else if(RW(l,"GNU.sparse.realsize")||RW(l,"GNU.sparse.size")){if(u.byteLength>C$s)throw new j("Invalid tar sparse real size");s.set("GNU.sparse.realsize",uae.decode(u))}}else if(RW(l,"path")||RW(l,"linkpath")){let p=RW(l,"path")?"PAX path":"PAX link target";s.set(p==="PAX path"?"path":"linkpath",k$s(u,p,t))}else if(RW(l,"size")){if(u.byteLength>C$s)throw new j("Invalid tar member size");s.set("size",uae.decode(u))}}n+=r}return s}function c2r(e,t){for(let[s,n]of t)if(n==="")e.delete(s);else e.set(s,n)}function d6(e,t,s){if(t?.has(s))return t.get(s);return e.get(s)}function d2r(e,t){return d6(e,t,Hht)==="1"}function f2r(e,t,s){for(let n=s;n<=e.byteLength-t.length;n++)if(Ap(e,n,t))return n;return-1}function x$s(e,t,s){let n=e.replace(/\\/g,"/");if(aae.posix.isAbsolute(n))throw new j(`Invalid old-GNU ${t}`);let o=Sr(n);if(!o)throw new j(`Invalid old-GNU ${t}`);return Kd(o,t,s.maxPathBytes),o}function m2r(e,t,s,n,o){let r=[...e.entries()].filter(([i])=>i===s||i.startsWith(`${s}/`));if(r.length===0)return;for(let[i]of r)e.delete(i);for(let[i,a]of r){let l=i.slice(s.length),u=`${n}${l}`;Kd(u,"member path",o.maxPathBytes),a.path=u;let p=e.get(u);if(p)t.delete(p);e.set(u,a)}for(let i of t.values())if(i.kind==="hard link"&&(i.targetPath===s||i.targetPath.startsWith(`${s}/`)))i.targetPath=`${n}${i.targetPath.slice(s.length)}`}function g2r(e,t,s,n){Hn(e.byteLength,n,"old-GNU name metadata");let o=e.indexOf(0),r=o===-1?e.byteLength:o,i=0;while(i<r){let a=e.indexOf(10,i),l=a===-1||a>r?r:a,u=e.subarray(i,l);if(Ap(u,0,"Rename ")){let p=f2r(u," to ",7);if(p===-1)throw new j("Invalid old-GNU name record");let c=nFe(u.subarray(7,p),"old-GNU source path",n),d=u[u.byteLength-1]===47?u.byteLength-1:u.byteLength,f=nFe(u.subarray(p+4,d),"old-GNU target path",n);m2r(t,s,x$s(c,"source path",n),x$s(f,"target path",n),n)}i=l+1}}function h2r(e,t,s){if(t.size===0)return;let n=new Set;for(let l of e.values())for(let u=l.path.lastIndexOf("/");u>0;u=l.path.lastIndexOf("/",u-1)){let p=l.path.slice(0,u);if(n.has(p))break;n.add(p)}let o=new Set(t.keys()),r=new Map,i=(l)=>{for(let u=l.length;u>0;u=l.lastIndexOf("/",u-1)){let p=e.get(l.slice(0,u));if(p&&o.has(p))return p}return null},a=[...o];while(a.length>0){let l=a.pop();if(!o.has(l))continue;let u=t.get(l),p=i(u.targetPath),c=u.targetPath;if(p===null){try{c=dW(e,c,s.maxLinkDepth)}catch(g){if(!(g instanceof j))throw new j("Invalid archive link")}if(c!==u.targetPath)p=i(c)}if(p!==null&&p!==l){let g=r.get(p);if(g)g.push(l);else r.set(p,[l]);continue}o.delete(l);let d=r.get(l);if(d)r.delete(l),a.push(...d);if(p===l){if(u.kind==="hard link")throw new j(`Archive hard link '${dr(l.path)}' has a cyclic target '${dr(u.targetPath)}'`);l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1};continue}let f=e.get(c);if(f?.storage&&!f.isDirectory&&!o.has(f)){l.size=f.size,l.storage=f.storage;continue}if(!(c===""||f?.isDirectory===!0||n.has(c))){if(u.kind==="symlink"){l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1};continue}let g=f?"unreadable member":"missing member";throw new j(`Archive hard link '${dr(l.path)}' targets ${g} '${dr(u.targetPath)}'`)}if(u.kind==="hard link")throw new j(`Archive hard link '${dr(l.path)}' targets directory '${dr(u.targetPath)}'`);l.isDirectory=!0,l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1}}if(o.size>0)throw new j("Archive contains cyclic or unsupported links")}function pae(e,t){let{limits:s}=t;ci(e.byteLength,s);let n=new Map,o=new Map,r=(d,f)=>{let m=n.get(d.path),g=yc(n,d);if(!g)return;if(m)o.delete(m);if(f)o.set(g,f);or(n.size,s)},i=0,a,l,u,p=new Map,c=!1;while(i+wS<=e.byteLength){if(H$s(e,i)){c=!0;break}if(!B$s(e,i))throw new j("Invalid or corrupt tar archive header");let d=i,f=String.fromCharCode(e[d+_$s]||48),m=U$s(e,d+Wht),g=sFe(e,d+Bht,lae);if(p2r(e,d)){let H=sFe(e,d+N$s,Ght);if(H)g=`${H}/${g}`}let h=sFe(e,d+r2r,i2r),T=oFe(e,d+P$s,F$s),y=oFe(e,d+v$s,I$s),R=Number.isSafeInteger(y)&&y>=0?y:void 0;i+=wS;let C=rFe(m);if(C>e.byteLength-i)throw new j("Archive member data is truncated");let b=e.subarray(i,i+m);if(f==="L"){Hn(b.byteLength,s,"GNU long-name metadata"),a=nFe(b,"GNU long path",s),i+=C;continue}if(f==="K"){Hn(b.byteLength,s,"GNU long-link metadata"),l=nFe(b,"GNU long link target",s),i+=C;continue}if(f==="N"){g2r(b,n,o,s),i+=C;continue}if(f==="x"||f==="X"){u=w$s(b,s),i+=C;continue}if(f==="g"){c2r(p,w$s(b,s)),i+=C;continue}if(f==="M")throw new j("GNU multi-volume tar members are not supported");if(a!==void 0)g=a;if(l!==void 0)h=l;let w=d6(p,u,"path");if(w!==void 0)g=w;let E=d6(p,u,"linkpath");if(E!==void 0)h=E;let x=d6(p,u,"size");if(x!==void 0)m=S$s(x,"member size");let A=d6(p,u,"GNU.sparse.name");if(A!==void 0)g=A;let M=m,I=d6(p,u,"GNU.sparse.realsize");if(I!==void 0)M=S$s(I,"sparse real size");let O=f==="S"||d2r(p,u);if(f==="S"&&e[d+a2r]===1){let H=!0;while(H){if(i+wS>e.byteLength)throw new j("Archive sparse metadata is truncated");H=e[i+l2r]===1,i+=wS}}let P=i,F=rFe(m);if(F>e.byteLength-P)throw new j(`Archive member '${dr(g)}' is truncated`);i+=F,a=void 0,l=void 0,u=void 0;let _=f==="5"||g.endsWith("/"),D=Sr(g);if(!D)continue;Kd(D,"member path",s.maxPathBytes);let L=T*1000,N=T!==0&&Number.isSafeInteger(L)?L:void 0;if(_){r({path:D,isDirectory:!0,size:0,mtimeMs:N,mode:R});continue}if(f==="1"||f==="2"){let H=f==="1"?"hard link":"symlink",q=h.replace(/\\/g,"/");Kd(q,"link target",s.maxPathBytes);let z=f==="1"?Sr(q):aae.posix.isAbsolute(q)?void 0:zd(aae.posix.join(aae.posix.dirname(D),q)),J={path:D,isDirectory:!1,size:0,mtimeMs:N,mode:R};if(z===void 0||Buffer.byteLength(z,"utf-8")>s.maxPathBytes){if(H==="hard link")throw new j(`Archive hard link '${dr(D)}' has an invalid target`);J.storage={type:"link",targetPath:q,resolveTarget:!1},r(J);continue}r(J,{kind:H,targetPath:z});continue}if(f!=="0"&&f!=="\x00"&&f!=="7"&&f!=="S")continue;Qi(M,D,s),r({path:D,isDirectory:!1,size:M,mtimeMs:N,mode:R,storage:{type:"member",source:new q$s(e,P,O)}})}if(!c)throw new j("Not a valid tar archive: missing terminating zero block");return h2r(n,o,s),[...n.values()]}function jht(e){if(e.byteLength<wS)return!1;if(H$s(e,0))return!0;try{if(sFe(e,Bht,lae).length===0)return!1;let t=U$s(e,Wht);return Number.isSafeInteger(rFe(t))&&B$s(e,0)}catch{return!1}}function tFe(e,t,s,n){if(n.byteLength>s)throw new j("Tar header field is too long");e.set(n,t)}function iae(e,t,s,n){if(!Number.isSafeInteger(n)||n<0)throw new j("Invalid tar numeric value");let o=n.toString(8);if(o.length>s-1)throw new j("Tar numeric value does not fit its header field");for(let r=t;r<t+s-1-o.length;r++)e[r]=48;for(let r=0;r<o.length;r++)e[t+s-1-o.length+r]=o.charCodeAt(r);e[t+s-1]=0}function T2r(e){if(e.byteLength<=lae)return[e,new Uint8Array(0)];for(let t=e.byteLength-1;t>0;t--){if(e[t]!==47)continue;let s=e.subarray(0,t),n=e.subarray(t+1);if(s.byteLength<=Ght&&n.byteLength>0&&n.byteLength<=lae)return[n,s]}return}function Dht(e,t){let s=cD.encode(`${e}=${t}
|
|
4622
|
+
Supported: ${r||"none"}`)}return{parsed:s,handler:o}}async resolve(e,t){let{parsed:s,handler:n}=this.#n(e,!0),o=await n.resolve(s,t);return{...o,immutable:o.immutable??n.immutable}}async write(e,t,s){let{parsed:n,handler:o}=this.#n(e);if(!o.write){let r=n.protocol.replace(/:$/,"").toLowerCase();throw Error(`${r}:// URLs are read-only for write; use the protocol-specific tool for mutations.`)}await o.write(n,t,s)}}var Hie=S(()=>{Sdt();OIe();vdt();uft();u0e();Wft();sPe();Ogt();PE();Fgt();fPe();IB();Ygt();vPe()});var ru=S(()=>{Sdt();OIe();vdt();uft();u0e();Wft();sPe();Ogt();PE();Hie();Fgt();fPe();IB();Ygt();vPe()});import*as sd from"fs";import*as q3s from"os";import*as un from"path";import*as U3s from"url";import{glob as eBr}from"@oh-my-pi/pi-natives";function aW(e){return un.posix.isAbsolute(e)||un.win32.isAbsolute(e)}function aBr(e){return e.replace(tBr," ")}function lBr(e){return e.replace(/ (AM|PM)\./g,`${iBr}$1.`)}function uBr(e){return e.normalize("NFD")}function P3s(e){return e.replace(/'/g,"\u2019")}function pBr(e){if(!e.includes("\\")||!e.includes("/"))return e;return e.replace(/\\([ \t"'(){}[\]])/g,"$1")}function Bie(e){try{return sd.accessSync(e,sd.constants.F_OK),!0}catch{return!1}}function cBr(e){if(!e.startsWith("@"))return e;let t=e.slice(1);if(t.startsWith("/")||t==="~"||t.startsWith("~/")||un.win32.isAbsolute(t)||t.startsWith("agent://")||t.startsWith("artifact://")||t.startsWith("skill://")||t.startsWith("rule://")||t.startsWith("security://")||t.startsWith("local:")||t.startsWith("mcp://"))return t;return e}function dBr(e){if(!e.toLowerCase().startsWith("file://"))return e;try{return U3s.fileURLToPath(e)}catch{return e}}function Pu(e,t){let s=t??q3s.homedir();if(e==="~")return s;if(e.startsWith("~/")||e.startsWith("~\\"))return s+e.slice(1);if(e.startsWith("~"))return un.join(s,e.slice(1));return e}function IC(e){let t=/^:(?=[/\\~]|\.\.?[/\\]|[A-Za-z]:)/.test(e)?e.slice(1):e,s=dR(dBr(aBr(cBr(t))));return Pu(s)}function F3s(e){if(e.length!==1)return!1;let t=e.charCodeAt(0);return t>=65&&t<=90||t>=97&&t<=122}function fBr(e){if(!e.startsWith("/"))return;let t=e.split("/");if(t[0]!=="")return;let s,n=2;if(t.length>=2&&F3s(t[1]??""))s=t[1].toUpperCase();else if(t.length>=3&&(t[1]??"").toLowerCase()==="mnt"&&F3s(t[2]??""))s=t[2].toUpperCase(),n=3;if(!s)return;let o=t.slice(n).filter(Boolean).join("\\");return o?`${s}:\\${o}`:`${s}:\\`}function mBr(e,t=process.platform,s=process.env){if(t==="win32")return fBr(e)??e;if(oT(t,s))return rTe(e)??e;return e}function hBr(e){let t=gBr.exec(e);if(!t)return null;let s=Number.parseInt(t[1],10);if(s<1)throw new X("Line selector 0 is invalid; lines are 1-indexed. Use :1.");let n=t[2]===".."?"-":t[2],o=t[3]?Number.parseInt(t[3],10):void 0,r;if(n==="+"){if(o===void 0||o<1)throw new X(`Invalid range ${s}+${o??0}: count must be >= 1.`);r=s+o-1}else if(n==="-"){if(o!==void 0){if(o<s)throw new X(`Invalid range ${s}-${o}: end must be >= start.`);r=o}}return{startLine:s,endLine:r}}function bh(e){let t=e.split(","),s=[];for(let o of t){let r=hBr(o);if(!r)return null;s.push(r)}if(s.length===0)return null;s.sort((o,r)=>o.startLine-r.startLine);let n=[s[0]];for(let o=1;o<s.length;o++){let r=s[o],i=n[n.length-1];if(i.endLine===void 0)continue;if(r.startLine<=i.endLine+1){if(r.endLine===void 0||r.endLine>i.endLine)n[n.length-1]={startLine:i.startLine,endLine:r.endLine};continue}n.push(r)}return n}function PPe(e){if(!e)return;for(let t of e.split(":")){let s=t.toLowerCase();if(s==="raw"||s==="conflicts")continue;let n=bh(t);if(n)return n}return}function Gie(e,t){for(let s of t){if(e<s.startLine)continue;if(s.endLine===void 0||e<=s.endLine)return!0}return!1}function Ha(e){let t=e.lastIndexOf(":");if(t<=0)return{path:e};let s=e.slice(t+1);if(!sBr.test(s))return{path:e};let n=e.slice(0,t),o=s,r=n.lastIndexOf(":");if(r>0){let i=n.slice(r+1),a=O3s.test(i),l=O3s.test(s),u=I3s.test(i),p=I3s.test(s);if(a&&p||u&&l)o=`${i}:${s}`,n=n.slice(0,r)}return{path:n,sel:o}}async function iD(e,t){let s=lu(e,t);try{return await sd.promises.lstat(s),"exists"}catch(n){if(pe(n)||CP(n)||xl(n,"ENAMETOOLONG"))return"missing";return"unknown"}}async function t6(e,t){let s=Ha(e);if(s.sel===void 0)return s;return await iD(e,t)==="missing"?s:{path:e}}function TBr(e,t){let s=lu(e,t);try{return sd.lstatSync(s),"exists"}catch(n){if(pe(n)||CP(n)||xl(n,"ENAMETOOLONG"))return"missing";return"unknown"}}function B3s(e,t){let s=Ha(e);if(s.sel===void 0)return s;return TBr(e,t)==="missing"?s:{path:e}}function lW(e){let t=e.match(H3s);if(!t)return{path:e};let s=t[1].toLowerCase();if(rBr.has(s))return{path:e};if(!oBr[s])return{path:e};let n=t[0].length;if(s==="ssh"&&e.indexOf("/",n)===-1)return{path:e};let o=e,r=[];while(!0){let i=o.lastIndexOf(":");if(i<n)break;let a=o.slice(i+1);if(!nBr.test(a))break;r.unshift(a),o=o.slice(0,i)}if(r.length===0)return{path:e};return{path:o,sel:r.join(":")}}function W3s(e){let{path:t,sel:s}=lW(e);if(s===void 0)return e;if(/^(?:raw|conflicts)$/i.test(s))return t;throw new X(`write does not accept the trailing selector ":${s}" \u2014 it writes a whole file. `+`Remove ":${s}", or if the filename truly ends with it, percent-encode the ":" as %3A.`)}function yBr(e,t){for(let s of rht)if(e.startsWith(s))throw Error(`Path "${t}" uses internal scheme "${s}" and must be resolved through the proper protocol handler, not as a filesystem path.`)}function Nr(e){return e.replace(/^(local:)\/(?!\/)/,"$1//")}function $d(e){let t=Nr(e),s=Nr(IC(t));for(let n of rht)if(s.startsWith(n))return!0;return!1}function FPe(e){let t=Nr(IC(Nr(e)));if(!rht.some((o)=>t.startsWith(o)))return"write";let s=H3s.exec(t)?.[1]?.toLowerCase();return(s?Mi.instance().getHandler(s):void 0)?.write?"write":"read"}function s6(e){return/ssh:\/\//i.test(e)}function iht(e){return/^ssh:\/\//i.test(e.trim())}function uW(e){return/^https?:\/\/?/i.test(e)||/^www\./i.test(e)}function Cs(e,t){let s=Nr(e),n=mBr(IC(s)),o=Nr(n);if(yBr(o,s),/^\/+$/.test(n))return t;if(un.isAbsolute(n))return n;return un.resolve(t,n)}function G3s(e,t){if(!e||un.isAbsolute(e))return null;if(e.startsWith("~")||$d(e))return null;let s=un.resolve(t),n=un.resolve(s,e);if(!IPe(n,s))return null;let o=tht(s);if(!o)return null;let r=tht(n);if(r)return IPe(r,o)?n:null;if(RBr(n))return null;let i=un.dirname(n),a=[un.basename(n)];for(;;){let l=tht(i);if(l)return IPe(un.join(l,...a.reverse()),o)?n:null;let u=un.dirname(i);if(u===i||!IPe(i,s))return null;a.push(un.basename(i)),i=u}}function IPe(e,t){let s=un.relative(t,e);return!!s&&!s.startsWith("..")&&!un.isAbsolute(s)}function tht(e){try{return sd.realpathSync.native(e)}catch{return null}}function RBr(e){try{return sd.lstatSync(e).isSymbolicLink()}catch{return!1}}async function aht(e,t){let s=un.resolve(e);if(t){let r=await _3s(s);if(r!==null)return r;if(!await L3s(s))return null}let n=[un.basename(s)],o=un.dirname(s);for(;;){let r=await _3s(o);if(r!==null)return un.join(r,...n.reverse());if(!await L3s(o))return null;let i=un.dirname(o);if(i===o)return null;n.push(un.basename(o)),o=i}}async function _3s(e){try{return await sd.promises.realpath(e)}catch{return null}}async function L3s(e){try{return!(await sd.promises.lstat(e)).isSymbolicLink()}catch(t){return pe(t)}}function Ys(e,t,s={}){let n=un.resolve(t),o=Nr(e);if($d(o))return o;let r=IC(o),i=un.isAbsolute(r)?un.resolve(r):un.resolve(t,r),a=un.relative(n,i),l=a===""||!a.startsWith("..")&&!un.isAbsolute(a),u=e6(l?a||".":i);if(s.trailingSlash&&u!=="."&&!u.endsWith("/"))u+="/";return u}function lht(e){return e.startsWith('"')&&e.endsWith('"')&&e.length>1?e.slice(1,-1):e}function uht(e){if($d(e))return e;if(!e.includes("\\"))return e;return e.replace(/\\/g,"/")}function aD(e){return lht(e.trim())}function CBr(e){let t=e.trim();if(!t.startsWith("[")||!t.endsWith("]"))return null;let s;try{s=JSON.parse(t)}catch{return null}if(!Array.isArray(s)||s.some((n)=>typeof n!=="string"))return null;return s}function ay(e){if(typeof e==="string")return CBr(e)??[e];return e??[]}function kS(e){return bBr.some((t)=>e.includes(t))}function kBr(e,t){if(t==="comma")return e===",";if(t==="semicolon")return e===";";if(t==="whitespace")return nht.test(e);return e===","||e===";"||nht.test(e)}function SBr(e){let t=0;for(let s=0;s<e.length;s++){let n=e[s];if(n==="\\"&&s+1<e.length){s++;continue}if(n==="{"){t++;continue}if(n==="}"){if(t>0)t--;continue}if(t===0&&(n===","||n===";"||nht.test(n)))return!0}return!1}function wBr(e,t){let s=[],n=0,o=0;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"&&r+1<e.length){r++;continue}if(i==="{"){n++;continue}if(i==="}"){if(n>0)n--;continue}if(n!==0||!kBr(i,t))continue;s.push(e.slice(o,r)),o=r+1}return s.push(e.slice(o)),s}async function j3s(e,t,s){if($d(e))return!0;let n=Ha(e).path,{basePath:o}=s(n),r=Cs(o,t);try{return await sd.promises.stat(r),!0}catch(i){if(pe(i)||xl(i,"ENAMETOOLONG"))return!1;throw i}}async function Wie(e,t,s,n,o){let r=wBr(e,n);if(r.length<2)return null;let i=r.map(aD).filter((a)=>a.length>0);if(i.length===0)return null;if(i.length<2&&r.length===i.length)return null;if(o!=="none"){let a=await Promise.all(i.map((u)=>j3s(u,t,s)));if(!(o==="all"?a.every(Boolean):a.some(Boolean)))return null}return i}async function pht(e,t,s={}){let n=aD(e);if(!SBr(n))return null;let o=s.splitter??OPe;if(s.routedUrlPredicate?.(n)){let i=await Wie(n,t,o,"semicolon","none");return i?.every(s.routedUrlPredicate)?i:null}if($d(n))return null;if(await iD(n,t)!=="missing")return null;let r=Ha(n).path;if(!kS(r)&&await j3s(n,t,o))return null;return await Wie(n,t,o,"semicolon","none")??await Wie(n,t,o,"comma","some")??await Wie(n,t,o,"whitespace","all")??await Wie(n,t,o,"mixed","all")}async function jie(e,t,s={}){let n=[];for(let o of e){let r=aD(o),i=await pht(r,t,s);if(i)n.push(...i);else n.push(r)}return n}function OPe(e){let t=uht(e),s=t.split("/"),n=-1;for(let o=0;o<s.length;o++)if(kS(s[o])){n=o;break}if(n===-1)return{basePath:t};if(n<=0)return{basePath:".",glob:t};return{basePath:s.slice(0,n).join("/"),glob:s.slice(n).join("/")}}async function $3s(e,t){if(!kS(e)||$d(e))return OPe(e);try{return await sd.promises.stat(Cs(e,t)),{basePath:uht(e)}}catch{return OPe(e)}}function $ie(e){let t=uht(e),s=t.split("/"),n=-1;for(let o=0;o<s.length;o++)if(kS(s[o])){n=o;break}if(n===-1)return{basePath:t,globPattern:"**/*",hasGlob:!1};if(n===0)return{basePath:".",globPattern:!t.startsWith("**/")?`**/${t}`:t,hasGlob:!0};return{basePath:s.slice(0,n).join("/"),globPattern:s.slice(n).join("/"),hasGlob:!0}}function sht(e,t){if(!e)return t;if(!t)return e;let s=e.replace(/\/+$/,""),n=t.replace(/^\/+/,"");return`${s}/${n}`}function e6(e){return e.replace(/\\/g,"/")}function D3s(e,t){if(!e||e===".")return e6(t).replace(/^\/+/,"");let s=e6(e).replace(/\/+$/,""),n=e6(t).replace(/^\/+/,"");return`${s}/${n}`}function xBr(e){let t=[...new Set(e.map((s)=>e6(s).trim()).filter(Boolean))];if(t.length===0)return;if(t.length===1)return t[0];return`{${t.join(",")}}`}function EBr(e){if(e.length===0)return".";let t=un.resolve(e[0]).split(un.sep);for(let n of e.slice(1)){let o=un.resolve(n).split(un.sep),r=0,i=Math.min(t.length,o.length);while(r<i&&t[r]===o[r])r+=1;t=t.slice(0,r)}if(t.length===0)return un.parse(un.resolve(e[0])).root;return t.join(un.sep)||un.parse(un.resolve(e[0])).root}function z3s(e,t){return e.map((s)=>Ys(s,t,{trailingSlash:s.endsWith("/")||s.endsWith("\\")})).join(", ")}async function MBr(e,t,s,n=!1){if(e.length<1)return;let o=await Promise.all(e.map(async(c)=>{let d=await $3s(c,t),f=Cs(d.basePath,t),m=await sd.promises.stat(f);return{raw:c,parsedPath:d,absoluteBasePath:f,stat:m}})),r=!s&&o.every((c)=>!c.parsedPath.glob&&c.stat.isFile()),i=EBr(o.map((c)=>c.absoluteBasePath)),a=o.map((c)=>{let d=e6(un.relative(i,c.absoluteBasePath))||".";if(c.parsedPath.glob){let f=D3s(d,c.parsedPath.glob);return sht(f,s)??f}if(s)return sht(d==="."?void 0:d,s)??s;if(c.stat.isDirectory())return D3s(d,"**/*");return d==="."?un.basename(c.absoluteBasePath):d}),l=o.some((c)=>c.absoluteBasePath===i),u=n&&!r&&o.some((c)=>!c.parsedPath.glob&&c.stat.isFile()),p=o.length>1&&(!l||u)?o.map((c)=>({basePath:c.absoluteBasePath,glob:c.parsedPath.glob?sht(c.parsedPath.glob,s):s})):void 0;return{basePath:i,glob:xBr(a),scopePath:z3s(e,t),exactFilePaths:r?o.map((c)=>c.absoluteBasePath):void 0,targets:p}}async function ABr(e,t,s,n=!1){return MBr([...new Set(e)],t,s,n)}async function vBr(e,t){if(e.length<=1)return;return{targets:e.map((n)=>{let o=$ie(n);return{basePath:Cs(o.basePath,t),globPattern:o.globPattern,hasGlob:o.hasGlob}}),scopePath:z3s(e,t)}}async function K3s(e,t){return vBr([...new Set(e)],t)}async function cht(e,t,s){let n=await Promise.all(e.map(async(i)=>{let{basePath:a}=s(i),l=Cs(a,t);try{return await sd.promises.stat(l),{item:i,exists:!0}}catch(u){if(pe(u))return{item:i,exists:!1};throw u}})),o=[],r=[];for(let i of n)if(i.exists)o.push(i.item);else r.push(i.item);return{valid:o,missing:r}}function lu(e,t){let s=Cs(e,t),n=pBr(s),o=n!==s?[s,n]:[s];for(let r of o)if(Bie(r))return r;for(let r of o){let i=lBr(r);if(i!==r&&Bie(i))return i;let a=uBr(r);if(a!==r&&Bie(a))return a;let l=P3s(r);if(l!==r&&Bie(l))return l;let u=P3s(a);if(u!==r&&Bie(u))return u}return s}function IBr(e){return e.replace(/[*?[{]/g,"[$&]")}async function OBr(e,t,s,n){let o=e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/+$/,"");if(!o)return null;let r=AbortSignal.timeout(N3s),i=s?AbortSignal.any([s,r]):r,a;try{let l=await n({pattern:`**/${IBr(o)}`,path:t,hidden:!0,signal:i,timeoutMs:N3s});if(s?.aborted)throw new Ke;a=l.matches.map((u)=>u.path)}catch{if(s?.aborted)throw new Ke;return null}if(a.length!==1)return null;return{absolutePath:un.resolve(t,a[0]),displayPath:a[0]}}async function _Pe(e,t,s){return OBr(e,t,s,eBr)}async function n6(e){let{rawPaths:t,cwd:s,internalUrlAction:n}=e,o=t.map(aD);if(o.some((y)=>y.length===0))throw new X("Search scope entries must be non-empty paths or globs");let r=await jie(o,s);if(r.some((y)=>y.length===0))throw new X("Search scope entries must be non-empty paths or globs");let i=/^(?:https?|ftp|ws|wss):\/\//i,a=Mi.instance(),l=[],u=new Set;for(let y of r){let R=i.test(y);if(!R&&uW(y)&&!kS(y))try{await sd.promises.stat(Cs(y,s))}catch(b){R=pe(b)||CP(b)}if(R){let b=e.resolveExternalUrl?await e.resolveExternalUrl(y):void 0;if(b){if(l.push(b.sourcePath),e.trackImmutableSources&&b.immutable)u.add(un.resolve(b.sourcePath));continue}throw new X(`Cannot ${n} external URL: ${y}. Use \`read\` to fetch web content, then search the returned text.`)}if(!a.canHandle(y)){l.push(y);continue}if(iht(y))throw new X(`Cannot ${n} a remote ssh:// path (no local file): ${y}. Use \`read ${y}\` to view it, or use \`grep\` on a specific remote file.`);if(kS(y))throw new X(`Glob patterns are not supported for internal URLs: ${y}`);let C=await a.resolve(y,{cwd:s,settings:e.settings,signal:e.signal,sessionFile:e.sessionFile,localProtocolOptions:e.localProtocolOptions,skills:e.skills,pathOnly:!0});if(!C.sourcePath)throw new X(`Cannot ${n} internal URL without a backing file: ${y}`);if(e.trackImmutableSources&&C.immutable)u.add(un.resolve(C.sourcePath));l.push(C.sourcePath)}let p=[],c=l;if(l.length>1){let y=await cht(l,s,OPe);if(y.valid.length===0)throw new X(`Path not found: ${y.missing.join(", ")}`);c=y.valid,p=y.missing}let d,f,m,g,h;if(c.length===1){let y=await $3s(c[0]??".",s);d=Cs(y.basePath,s),m=y.glob,f=Ys(d,s)}else{let y=await ABr(c,s,void 0,e.fanOutFileTargets===!0);if(!y)throw new X("`paths` must contain at least one path or glob");if(d=y.basePath,g=y.targets,e.surfaceExactFilePaths)h=y.exactFilePaths,m=h||g?void 0:y.glob;else m=g?void 0:y.glob;f=y.scopePath}let T;try{T=(await Bun.file(d).stat()).isDirectory()}catch{let y=e.multipathStatHint&&r.length>1?e.multipathStatHint:"";throw new X(`Path not found: ${f}${y}`)}return{searchPath:d,scopePath:f,globFilter:m,isDirectory:T,multiTargets:g,exactFilePaths:h,missingPaths:p,immutableSourcePaths:u}}var tBr,v3s,oht,sBr,I3s,O3s,nBr,oBr,rBr,H3s,iBr="\u202F",rht,gBr,bBr,nht,N3s=5000;var hs=S(()=>{B();ru();Mt();tBr=/[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;v3s=String.raw`L?\d+(?:(?:[-+]|\.\.)L?\d+|-|\.\.)?`,oht=`${v3s}(?:,${v3s})*`,sBr=new RegExp(`^(?:${oht}|raw|conflicts|img)$`,"i"),I3s=new RegExp(`^${oht}$`,"i"),O3s=/^raw$/i,nBr=new RegExp(String.raw`^(?:raw|conflicts|img|${oht}|-\d+(?:[-+]\d+)?)$`,"i"),oBr={agent:!0,artifact:!0,issue:!0,history:!0,local:!0,memory:!0,omp:!0,pr:!0,rule:!0,security:!0,skill:!0,ssh:!0,vault:!0},rBr=new Set(["mcp"]),H3s=/^([a-z][a-z0-9+.-]*):\/\//i,rht=["agent://","artifact://","skill://","rule://","security://","local://","mcp://","ssh://","vault://"];gBr=/^L?(\d+)(?:(\.\.|[-+])L?(\d+)?)?$/i;bBr=["*","?","[","{"];nht=/\s/});var o6;var LPe=S(()=>{o6={type:"module",name:"@oh-my-pi/pi-coding-agent",version:"18.1.1",description:"Coding agent CLI with read, bash, edit, write tools and session management",homepage:"https://omp.sh",author:"Stencil Labs, Inc.",contributors:["Mario Zechner"],license:"MIT",repository:{type:"git",url:"git+https://github.com/can1357/oh-my-pi.git",directory:"packages/coding-agent"},bugs:{url:"https://github.com/can1357/oh-my-pi/issues"},keywords:["coding-agent","ai","llm","cli","tui","agent"],main:"./src/index.ts",types:"./dist/types/index.d.ts",bin:{omp:"dist/cli.js"},scripts:{build:"bun scripts/build-binary.ts",check:"oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types","check:types":"tsgo -p tsconfig.json --noEmit",lint:"oxlint .",test:"bun ../../scripts/ci-test-ts.ts coding-agent-heavy --full",fix:"oxlint --fix --fix-suggestions . && bun run fmt",fmt:"oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run format-prompts","format-prompts":"bun scripts/format-prompts.ts","gen:tool-views":"bun --cwd=../collab-web run gen:tool-views","gen:bundle":"bun scripts/bundle-dist.ts","gen:native":"bun --cwd=../natives run gen:native","gen:native:reset":"bun --cwd=../natives run gen:native:reset",prepack:"bun run gen:tool-views && bun run gen:bundle","bench:guard":"bun scripts/bench-guard.ts"},dependencies:{"@babel/parser":"catalog:","@oh-my-pi/hashline":"catalog:","@oh-my-pi/omp-stats":"catalog:","@oh-my-pi/omptype":"catalog:","@oh-my-pi/pi-agent-core":"catalog:","@oh-my-pi/pi-ai":"catalog:","@oh-my-pi/pi-catalog":"catalog:","@oh-my-pi/pi-mnemopi":"catalog:","@oh-my-pi/pi-natives":"catalog:","@oh-my-pi/pi-tui":"catalog:","@oh-my-pi/pi-utils":"catalog:","@oh-my-pi/pi-wire":"catalog:","@oh-my-pi/snapcompact":"catalog:","@opentelemetry/api":"catalog:","@opentelemetry/api-logs":"catalog:","@opentelemetry/context-async-hooks":"catalog:","@opentelemetry/exporter-logs-otlp-proto":"catalog:","@opentelemetry/exporter-metrics-otlp-proto":"catalog:","@opentelemetry/exporter-trace-otlp-proto":"catalog:","@opentelemetry/resources":"catalog:","@opentelemetry/sdk-logs":"catalog:","@opentelemetry/sdk-metrics":"catalog:","@opentelemetry/sdk-trace-base":"catalog:","@opentelemetry/sdk-trace-node":"catalog:","puppeteer-core":"catalog:"},optionalDependencies:{"@huggingface/transformers":"catalog:","sherpa-onnx-node":"1.13.2"},devDependencies:{"@types/bun":"catalog:"},engines:{bun:">=1.3.14"},files:["src","dist/cli.js","dist/docs-index.generated.txt","dist/CHANGELOG-*.md","dist/*.node","dist/template-*.css","dist/template-*.html","dist/template-*.js","dist/tool-views.generated-*.js","scripts","examples","README.md","CHANGELOG.md","LICENSE","THIRD-PARTY-NOTICES.txt","dist/types"],exports:{".":{types:"./dist/types/index.d.ts",import:"./src/index.ts"},"./*":{types:"./dist/types/*.d.ts",import:"./src/*.ts"},"./async":{types:"./dist/types/async/index.d.ts",import:"./src/async/index.ts"},"./async/*":{types:"./dist/types/async/*.d.ts",import:"./src/async/*.ts"},"./autoresearch":{types:"./dist/types/autoresearch/index.d.ts",import:"./src/autoresearch/index.ts"},"./autoresearch/*":{types:"./dist/types/autoresearch/*.d.ts",import:"./src/autoresearch/*.ts"},"./autoresearch/tools/*":{types:"./dist/types/autoresearch/tools/*.d.ts",import:"./src/autoresearch/tools/*.ts"},"./capability":{types:"./dist/types/capability/index.d.ts",import:"./src/capability/index.ts"},"./capability/*":{types:"./dist/types/capability/*.d.ts",import:"./src/capability/*.ts"},"./cli/*":{types:"./dist/types/cli/*.d.ts",import:"./src/cli/*.ts"},"./cli/gallery-fixtures":{types:"./dist/types/cli/gallery-fixtures/index.d.ts",import:"./src/cli/gallery-fixtures/index.ts"},"./cli/gallery-fixtures/*":{types:"./dist/types/cli/gallery-fixtures/*.d.ts",import:"./src/cli/gallery-fixtures/*.ts"},"./cli/commands/*":{types:"./dist/types/cli/commands/*.d.ts",import:"./src/cli/commands/*.ts"},"./commands/*":{types:"./dist/types/commands/*.d.ts",import:"./src/commands/*.ts"},"./commit":{types:"./dist/types/commit/index.d.ts",import:"./src/commit/index.ts"},"./commit/*":{types:"./dist/types/commit/*.d.ts",import:"./src/commit/*.ts"},"./commit/agentic":{types:"./dist/types/commit/agentic/index.d.ts",import:"./src/commit/agentic/index.ts"},"./commit/agentic/*":{types:"./dist/types/commit/agentic/*.d.ts",import:"./src/commit/agentic/*.ts"},"./commit/agentic/tools":{types:"./dist/types/commit/agentic/tools/index.d.ts",import:"./src/commit/agentic/tools/index.ts"},"./commit/agentic/tools/*":{types:"./dist/types/commit/agentic/tools/*.d.ts",import:"./src/commit/agentic/tools/*.ts"},"./commit/analysis":{types:"./dist/types/commit/analysis/index.d.ts",import:"./src/commit/analysis/index.ts"},"./commit/analysis/*":{types:"./dist/types/commit/analysis/*.d.ts",import:"./src/commit/analysis/*.ts"},"./commit/changelog":{types:"./dist/types/commit/changelog/index.d.ts",import:"./src/commit/changelog/index.ts"},"./commit/changelog/*":{types:"./dist/types/commit/changelog/*.d.ts",import:"./src/commit/changelog/*.ts"},"./commit/conventional":{types:"./dist/types/commit/conventional/index.d.ts",import:"./src/commit/conventional/index.ts"},"./commit/conventional/*":{types:"./dist/types/commit/conventional/*.d.ts",import:"./src/commit/conventional/*.ts"},"./commit/git/*":{types:"./dist/types/commit/git/*.d.ts",import:"./src/commit/git/*.ts"},"./commit/utils/*":{types:"./dist/types/commit/utils/*.d.ts",import:"./src/commit/utils/*.ts"},"./config/*":{types:"./dist/types/config/*.d.ts",import:"./src/config/*.ts"},"./dap":{types:"./dist/types/dap/index.d.ts",import:"./src/dap/index.ts"},"./dap/*":{types:"./dist/types/dap/*.d.ts",import:"./src/dap/*.ts"},"./debug":{types:"./dist/types/debug/index.d.ts",import:"./src/debug/index.ts"},"./debug/*":{types:"./dist/types/debug/*.d.ts",import:"./src/debug/*.ts"},"./discovery":{types:"./dist/types/discovery/index.d.ts",import:"./src/discovery/index.ts"},"./discovery/*":{types:"./dist/types/discovery/*.d.ts",import:"./src/discovery/*.ts"},"./edit":{types:"./dist/types/edit/index.d.ts",import:"./src/edit/index.ts"},"./edit/*":{types:"./dist/types/edit/*.d.ts",import:"./src/edit/*.ts"},"./edit/modes/*":{types:"./dist/types/edit/modes/*.d.ts",import:"./src/edit/modes/*.ts"},"./exa":{types:"./dist/types/exa/index.d.ts",import:"./src/exa/index.ts"},"./exa/*":{types:"./dist/types/exa/*.d.ts",import:"./src/exa/*.ts"},"./exec/*":{types:"./dist/types/exec/*.d.ts",import:"./src/exec/*.ts"},"./export/*":{types:"./dist/types/export/*.d.ts",import:"./src/export/*.ts"},"./export/html":{types:"./dist/types/export/html/index.d.ts",import:"./src/export/html/index.ts"},"./export/html/*":{types:"./dist/types/export/html/*.d.ts",import:"./src/export/html/*.ts"},"./extensibility/*":{types:"./dist/types/extensibility/*.d.ts",import:"./src/extensibility/*.ts"},"./extensibility/custom-commands":{types:"./dist/types/extensibility/custom-commands/index.d.ts",import:"./src/extensibility/custom-commands/index.ts"},"./extensibility/custom-commands/*":{types:"./dist/types/extensibility/custom-commands/*.d.ts",import:"./src/extensibility/custom-commands/*.ts"},"./extensibility/custom-commands/bundled/ci-green":{types:"./dist/types/extensibility/custom-commands/bundled/ci-green/index.d.ts",import:"./src/extensibility/custom-commands/bundled/ci-green/index.ts"},"./extensibility/custom-commands/bundled/review":{types:"./dist/types/extensibility/custom-commands/bundled/review/index.d.ts",import:"./src/extensibility/custom-commands/bundled/review/index.ts"},"./extensibility/custom-tools":{types:"./dist/types/extensibility/custom-tools/index.d.ts",import:"./src/extensibility/custom-tools/index.ts"},"./extensibility/custom-tools/*":{types:"./dist/types/extensibility/custom-tools/*.d.ts",import:"./src/extensibility/custom-tools/*.ts"},"./extensibility/extensions":{types:"./dist/types/extensibility/extensions/index.d.ts",import:"./src/extensibility/extensions/index.ts"},"./extensibility/extensions/*":{types:"./dist/types/extensibility/extensions/*.d.ts",import:"./src/extensibility/extensions/*.ts"},"./extensibility/hooks":{types:"./dist/types/extensibility/hooks/index.d.ts",import:"./src/extensibility/hooks/index.ts"},"./extensibility/hooks/*":{types:"./dist/types/extensibility/hooks/*.d.ts",import:"./src/extensibility/hooks/*.ts"},"./extensibility/plugins":{types:"./dist/types/extensibility/plugins/index.d.ts",import:"./src/extensibility/plugins/index.ts"},"./extensibility/plugins/*":{types:"./dist/types/extensibility/plugins/*.d.ts",import:"./src/extensibility/plugins/*.ts"},"./extensibility/plugins/marketplace":{types:"./dist/types/extensibility/plugins/marketplace/index.d.ts",import:"./src/extensibility/plugins/marketplace/index.ts"},"./extensibility/plugins/marketplace/*":{types:"./dist/types/extensibility/plugins/marketplace/*.d.ts",import:"./src/extensibility/plugins/marketplace/*.ts"},"./internal-urls":{types:"./dist/types/internal-urls/index.d.ts",import:"./src/internal-urls/index.ts"},"./internal-urls/*":{types:"./dist/types/internal-urls/*.d.ts",import:"./src/internal-urls/*.ts"},"./eval":{types:"./dist/types/eval/index.d.ts",import:"./src/eval/index.ts"},"./if-bench":{types:"./dist/types/if-bench/index.d.ts",import:"./src/if-bench/index.ts"},"./if-bench/*":{types:"./dist/types/if-bench/*.d.ts",import:"./src/if-bench/*.ts"},"./eval/js/*":{types:"./dist/types/eval/js/*.d.ts",import:"./src/eval/js/*.ts"},"./eval/py/*":{types:"./dist/types/eval/py/*.d.ts",import:"./src/eval/py/*.ts"},"./lsp":{types:"./dist/types/lsp/index.d.ts",import:"./src/lsp/index.ts"},"./lsp/*":{types:"./dist/types/lsp/*.d.ts",import:"./src/lsp/*.ts"},"./lsp/clients":{types:"./dist/types/lsp/clients/index.d.ts",import:"./src/lsp/clients/index.ts"},"./lsp/clients/*":{types:"./dist/types/lsp/clients/*.d.ts",import:"./src/lsp/clients/*.ts"},"./markit":{types:"./dist/types/markit/index.d.ts",import:"./src/markit/index.ts"},"./markit/*":{types:"./dist/types/markit/*.d.ts",import:"./src/markit/*.ts"},"./mcp":{types:"./dist/types/mcp/index.d.ts",import:"./src/mcp/index.ts"},"./mcp/*":{types:"./dist/types/mcp/*.d.ts",import:"./src/mcp/*.ts"},"./mcp/transports":{types:"./dist/types/mcp/transports/index.d.ts",import:"./src/mcp/transports/index.ts"},"./mcp/transports/*":{types:"./dist/types/mcp/transports/*.d.ts",import:"./src/mcp/transports/*.ts"},"./memories":{types:"./dist/types/memories/index.d.ts",import:"./src/memories/index.ts"},"./memories/*":{types:"./dist/types/memories/*.d.ts",import:"./src/memories/*.ts"},"./memory-backend":{types:"./dist/types/memory-backend/index.d.ts",import:"./src/memory-backend/index.ts"},"./memory-backend/*":{types:"./dist/types/memory-backend/*.d.ts",import:"./src/memory-backend/*.ts"},"./hindsight":{types:"./dist/types/hindsight/index.d.ts",import:"./src/hindsight/index.ts"},"./hindsight/*":{types:"./dist/types/hindsight/*.d.ts",import:"./src/hindsight/*.ts"},"./modes":{types:"./dist/types/modes/index.d.ts",import:"./src/modes/index.ts"},"./modes/*":{types:"./dist/types/modes/*.d.ts",import:"./src/modes/*.ts"},"./modes/acp":{types:"./dist/types/modes/acp/index.d.ts",import:"./src/modes/acp/index.ts"},"./modes/acp/*":{types:"./dist/types/modes/acp/*.d.ts",import:"./src/modes/acp/*.ts"},"./modes/components":{types:"./dist/types/modes/components/index.d.ts",import:"./src/modes/components/index.ts"},"./modes/components/*":{types:"./dist/types/modes/components/*.d.ts",import:"./src/modes/components/*.ts"},"./modes/components/extensions":{types:"./dist/types/modes/components/extensions/index.d.ts",import:"./src/modes/components/extensions/index.ts"},"./modes/components/extensions/*":{types:"./dist/types/modes/components/extensions/*.d.ts",import:"./src/modes/components/extensions/*.ts"},"./modes/components/status-line":{types:"./dist/types/modes/components/status-line/index.d.ts",import:"./src/modes/components/status-line/index.ts"},"./modes/components/status-line/*":{types:"./dist/types/modes/components/status-line/*.d.ts",import:"./src/modes/components/status-line/*.ts"},"./modes/controllers/*":{types:"./dist/types/modes/controllers/*.d.ts",import:"./src/modes/controllers/*.ts"},"./modes/setup-wizard":{types:"./dist/types/modes/setup-wizard/index.d.ts",import:"./src/modes/setup-wizard/index.ts"},"./modes/setup-wizard/*":{types:"./dist/types/modes/setup-wizard/*.d.ts",import:"./src/modes/setup-wizard/*.ts"},"./modes/rpc/*":{types:"./dist/types/modes/rpc/*.d.ts",import:"./src/modes/rpc/*.ts"},"./modes/theme/*":{types:"./dist/types/modes/theme/*.d.ts",import:"./src/modes/theme/*.ts"},"./modes/theme/defaults":{types:"./dist/types/modes/theme/defaults/index.d.ts",import:"./src/modes/theme/defaults/index.ts"},"./modes/utils/*":{types:"./dist/types/modes/utils/*.d.ts",import:"./src/modes/utils/*.ts"},"./plan-mode/*":{types:"./dist/types/plan-mode/*.d.ts",import:"./src/plan-mode/*.ts"},"./prompts/*":"./src/prompts/*.md","./registry/*":{types:"./dist/types/registry/*.d.ts",import:"./src/registry/*.ts"},"./secrets":{types:"./dist/types/secrets/index.d.ts",import:"./src/secrets/index.ts"},"./secrets/*":{types:"./dist/types/secrets/*.d.ts",import:"./src/secrets/*.ts"},"./session/*":{types:"./dist/types/session/*.d.ts",import:"./src/session/*.ts"},"./slash-commands/*":{types:"./dist/types/slash-commands/*.d.ts",import:"./src/slash-commands/*.ts"},"./ssh/*":{types:"./dist/types/ssh/*.d.ts",import:"./src/ssh/*.ts"},"./stt":{types:"./dist/types/stt/index.d.ts",import:"./src/stt/index.ts"},"./stt/*":{types:"./dist/types/stt/*.d.ts",import:"./src/stt/*.ts"},"./task":{types:"./dist/types/task/index.d.ts",import:"./src/task/index.ts"},"./task/*":{types:"./dist/types/task/*.d.ts",import:"./src/task/*.ts"},"./tools":{types:"./dist/types/tools/index.d.ts",import:"./src/tools/index.ts"},"./tools/hub":{types:"./dist/types/tools/hub/index.d.ts",import:"./src/tools/hub/index.ts"},"./tools/hub/*":{types:"./dist/types/tools/hub/*.d.ts",import:"./src/tools/hub/*.ts"},"./tools/*":{types:"./dist/types/tools/*.d.ts",import:"./src/tools/*.ts"},"./tui":{types:"./dist/types/tui/index.d.ts",import:"./src/tui/index.ts"},"./tui/*":{types:"./dist/types/tui/*.d.ts",import:"./src/tui/*.ts"},"./utils/*":{types:"./dist/types/utils/*.d.ts",import:"./src/utils/*.ts"},"./web/*":{types:"./dist/types/web/*.d.ts",import:"./src/web/*.ts"},"./web/scrapers":{types:"./dist/types/web/scrapers/index.d.ts",import:"./src/web/scrapers/index.ts"},"./web/scrapers/*":{types:"./dist/types/web/scrapers/*.d.ts",import:"./src/web/scrapers/*.ts"},"./web/search":{types:"./dist/types/web/search/index.d.ts",import:"./src/web/search/index.ts"},"./web/search/*":{types:"./dist/types/web/search/*.d.ts",import:"./src/web/search/*.ts"},"./web/search/providers/*":{types:"./dist/types/web/search/providers/*.d.ts",import:"./src/web/search/providers/*.ts"},"./*.js":"./src/*.ts"}}});import*as ly from"fs/promises";import*as zie from"path";function Y3s(e,t){let n=(t.trim().toLowerCase().replace(/^\.+/,"")||"bin").replace(/[^a-z0-9]+/g,"_")||"bin",o=o6.version.replace(/[^a-z0-9]+/gi,"_"),r=new Bun.CryptoHasher("sha256").update(e).digest("hex");return`v${DPe}-${o}-${n}-${r}`}function _Br(e){return zie.join(FVe(),`${e}.json`)}function pW(e){return e instanceof Error?e.message:String(e)}function LBr(e){let t=JSON.parse(e);if(typeof t!=="object"||t===null)return null;if(!("version"in t)||t.version!==DPe)return null;if(!("content"in t)||typeof t.content!=="string"||t.content.length===0)return null;return{version:DPe,content:t.content}}async function J3s(e){let t=_Br(e),s;try{s=await Bun.file(t).text()}catch(o){if(!pe(o))v.debug("document conversion cache read failed",{error:pW(o)});return{status:"miss"}}let n;try{n=LBr(s)}catch(o){v.debug("document conversion cache read failed",{error:pW(o)}),n=null}if(!n)return await ly.rm(t,{force:!0}).catch(()=>{return}),{status:"miss"};return{status:"hit",content:n.content}}async function DBr(e){let t;try{t=await ly.readdir(e)}catch(r){if(!pe(r))v.debug("document conversion cache prune failed",{error:pW(r)});return}let s=Date.now(),n=[],o=0;for(let r of t){let i=zie.join(e,r),a;try{a=await ly.stat(i)}catch(l){if(!pe(l))v.debug("document conversion cache prune failed",{error:pW(l)});continue}if(!a.isFile())continue;if(r.endsWith(".tmp")){if(s-a.mtimeMs>FBr)await ly.rm(i,{force:!0}).catch(()=>{return});continue}if(!r.endsWith(".json"))continue;n.push({path:i,size:a.size,mtimeMs:a.mtimeMs}),o+=a.size}if(o<=V3s)return;n.sort((r,i)=>r.mtimeMs-i.mtimeMs);for(let r of n){if(o<=V3s)break;try{await ly.rm(r.path,{force:!0}),o-=r.size}catch(i){if(!pe(i))v.debug("document conversion cache prune failed",{error:pW(i)})}}}async function X3s(e,t){let s=FVe(),n=zie.join(s,`${e}.json`),o=zie.join(s,`${e}.${process.pid}.${Date.now()}.${crypto.randomUUID()}.tmp`),r=JSON.stringify({version:DPe,content:t});try{await ly.mkdir(s,{recursive:!0}),await Bun.write(o,r),await ly.rename(o,n)}catch(i){await ly.rm(o,{force:!0}).catch(()=>{return}),v.debug("document conversion cache write failed",{error:pW(i)});return}DBr(s).catch((i)=>{v.debug("document conversion cache prune failed",{error:pW(i)})})}var DPe=1,V3s=268435456,FBr=300000;var Q3s=S(()=>{B();LPe()});var j;var Ur=S(()=>{j=class j extends Error{constructor(e){super(e);this.name="ArchiveError"}}});function xn(e,t){return e[t]|e[t+1]<<8}function Es(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function ZE(e,t){let s=Es(e,t)+Es(e,t+4)*4294967296;if(!Number.isSafeInteger(s))throw new j("Archive uses offsets or sizes too large to read safely");return s}function Kie(e,t){return e[t]<<8|e[t+1]}function kh(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function nd(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255}function dl(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24&255}function cW(e,t,s){dl(e,t,s>>>0),dl(e,t+4,Math.floor(s/4294967296))}function Ap(e,t,s){if(e.byteLength<t+s.length)return!1;for(let n=0;n<s.length;n++)if(e[t+n]!==s.charCodeAt(n))return!1;return!0}var r6;var Sh=S(()=>{Ur();r6=new TextDecoder});function zd(e){if(!e)return"";let t=e.replace(/\\/g,"/").split("/"),s=[];for(let n of t){if(!n||n===".")continue;if(n==="..")return;s.push(n)}return s.join("/")}function Sr(e){let t=e.replace(/\\/g,"/").split("/"),s=[];for(let n of t){if(!n||n===".")continue;if(n==="..")return;s.push(n)}if(s.length===0)return;return s.join("/")}function ejs(e){return e.endsWith("/")||e.endsWith("\\")}function dr(e){if(Buffer.byteLength(e,"utf-8")<=Z3s)return e;let t=0,s=0;for(let n of e){let o=Buffer.byteLength(n,"utf-8");if(s+o>Z3s-3)break;t+=n.length,s+=o}return`${e.slice(0,t)}...`}function ko(e,t,s){if(e>s)throw new j(`Archive ${t} exceeds ${s} bytes`)}function Kd(e,t,s){ko(Buffer.byteLength(e,"utf-8"),t,s)}var Z3s=256;var Vd=S(()=>{Ur()});function ci(e,t){if(!Number.isSafeInteger(e)||e<0)throw new j("Archive is too large to read safely");if(e>t.maxInMemorySize)throw new j(`Archive is too large to read in memory (${pt(e)} > ${pt(t.maxInMemorySize)} limit)`)}function Hn(e,t,s){if(!Number.isSafeInteger(e)||e<0)throw new j(`Invalid archive: ${s} has an invalid size`);if(e>t.maxIndexSize)throw new j(`Archive ${s} is too large (${pt(e)} > ${pt(t.maxIndexSize)} limit)`)}function Qi(e,t,s){if(!Number.isSafeInteger(e)||e<0)throw new j(`Archive member '${dr(t)}' has an invalid size`);if(e>s.maxMemberSize)throw new j(`Archive member '${dr(t)}' is too large to extract in memory (${pt(e)} > ${pt(s.maxMemberSize)} limit)`)}function or(e,t){if(e>t.maxEntries)throw new j(`Archive has too many entries (> ${t.maxEntries} limit)`)}var Vie;var vp=S(()=>{Ur();Vd();Vie={maxEntries:1e6,maxInMemorySize:268435456,maxIndexSize:67108864,maxMemberSize:67108864,maxPathBytes:4096,maxLinkDepth:40}});function yc(e,t){let s=e.get(t.path);if(!s)return e.set(t.path,t),t;if(s.isDirectory&&!t.isDirectory)return e.set(t.path,t),t;if(!s.isDirectory&&t.isDirectory)return;let n={...t,mtimeMs:t.mtimeMs??s.mtimeMs,mode:t.mode??s.mode,storage:t.storage??s.storage};return e.set(t.path,n),n}function lD(e,t){or(e.size,t);for(let s of Array.from(e.values())){let n=s.path.split("/"),o=n.length-1;for(let r=1;r<=o;r++){let i=n.slice(0,r).join("/");if(!i||e.has(i))continue;e.set(i,{path:i,isDirectory:!0,size:0}),or(e.size,t)}}}function dW(e,t,s){let n=t,o=new Set;for(let r=0;!o.has(n);){o.add(n);let i;for(let a=n.length;a>0;a=n.lastIndexOf("/",a-1)){let l=e.get(n.slice(0,a));if(l?.storage?.type!=="link"||!l.isDirectory&&!l.storage.resolveTarget)continue;let u=n.slice(a+1);i=u?l.storage.targetPath?`${l.storage.targetPath}/${u}`:u:l.storage.targetPath;break}if(i===void 0)return n;if(++r>s)break;n=i}throw new j(`Archive path '${t}' crosses a cyclic symlink`)}var uD=S(()=>{Ur();vp()});function NBr(e,t){throw new j(`Archive symlink '${dr(t)}' cannot be materialized from target '${dr(e)}'`)}class dht{format;limits;#e=new Map;constructor(e,t,s=Vie){this.format=e,this.limits=s;for(let n of t)yc(this.#e,n);lD(this.#e,s)}indexEntries(){return this.#e.values()}getNode(e){let t=zd(e);if(t===void 0)return;if(t==="")return{path:"",isDirectory:!0,size:0};let s=dW(this.#e,t,this.limits.maxLinkDepth);if(s==="")return{path:t,isDirectory:!0,size:0};let n=this.#e.get(s);if(!n)return;return{path:t,isDirectory:n.isDirectory,size:n.size,mtimeMs:n.mtimeMs,mode:n.mode}}listDirectory(e){let t=zd(e);if(t===void 0)throw new j("Archive path cannot contain '..'");let s=t?dW(this.#e,t,this.limits.maxLinkDepth):"";if(t&&s!==""){let r=this.#e.get(s);if(!r)throw new j(`Archive path '${t}' not found`);if(!r.isDirectory)throw new j(`Archive path '${t}' is not a directory`)}let n=s?`${s}/`:"",o=new Map;for(let r of this.#e.values()){if(s){if(!r.path.startsWith(n)||r.path===s)continue}let i=s?r.path.slice(n.length):r.path,a=i.split("/")[0];if(!a)continue;let l=t?`${t}/${a}`:a;if(o.has(l))continue;let u=s?`${s}/${a}`:a,p=dW(this.#e,u,this.limits.maxLinkDepth),c=p?this.#e.get(p):void 0,d=p===""||c?.isDirectory===!0||i.includes("/");o.set(l,{name:a,path:l,isDirectory:d,size:d?0:c?.size??r.size,mtimeMs:c?.mtimeMs??r.mtimeMs,mode:c?.mode??r.mode})}return[...o.values()].sort((r,i)=>r.name.toLowerCase().localeCompare(i.name.toLowerCase()))}async readFile(e){let t=zd(e);if(!t)throw new j("Archive file path is required");let s=dW(this.#e,t,this.limits.maxLinkDepth);if(s==="")throw new j(`Archive path '${t}' is a directory`);let n=this.#e.get(s);if(!n)throw new j(`Archive file '${t}' not found`);if(n.isDirectory)throw new j(`Archive path '${t}' is a directory`);if(!n.storage)throw new j(`Archive file '${t}' has no readable storage`);if(Qi(n.size,t,this.limits),n.storage.type==="link")NBr(n.storage.targetPath,t);let o=await n.storage.source.read(n.size,t);return{path:t,isDirectory:!1,size:n.size,mtimeMs:n.mtimeMs,mode:n.mode,bytes:o}}}var fht=S(()=>{uD();Ur();vp();Vd()});function Wi(e,t=0){return Bun.hash.crc32(e,t)>>>0}function njs(e,t=0n){let s=t^0xffffffffffffffffn,n=Number(s&0xffffffffn)>>>0,o=Number(s>>32n&0xffffffffn)>>>0;for(let r=0;r<e.length;r++){let i=(n^e[r])&255;n=((n>>>8|(o&255)<<24)>>>0^tjs[i])>>>0,o=(o>>>8^sjs[i])>>>0}return(BigInt(o)<<32n|BigInt(n))^0xffffffffffffffffn}function i6(e,t=0){let s=t;for(let n=0;n<e.length;n++)s=(s>>>8^ojs[(s^e[n])&255])&65535;return s}var tjs,sjs,ojs;var m0=S(()=>{tjs=new Uint32Array(256),sjs=new Uint32Array(256);for(let e=0;e<256;e++){let t=e,s=0;for(let n=0;n<8;n++){let o=(t&1)!==0;if(t=(t>>>1|(s&1)<<31)>>>0,s>>>=1,o)t=(t^3615952706)>>>0,s=(s^3379320725)>>>0}tjs[e]=t,sjs[e]=s}ojs=new Uint16Array(256);for(let e=0;e<256;e++){let t=e;for(let s=0;s<8;s++)t=(t&1)!==0?t>>>1^40961:t>>>1;ojs[e]=t}});function rjs(e,t){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<0||t<e)throw new j("Invalid archive range")}function ijs(e,t,s){if(rjs(t,s),s>e.byteLength)throw new j("Invalid archive: truncated data");return e.subarray(t,s)}function NPe(e){return{size:e.byteLength,async read(t,s){return ijs(e,t,s)}}}function mht(e){let t=Bun.file(e),s=t.size;if(!Number.isSafeInteger(s))throw new j("Archive is too large to read safely");return{size:s,async read(n,o){rjs(n,o);let r=await t.slice(n,o).bytes();if(r.byteLength!==o-n)throw new j("Invalid archive: truncated data");return r}}}async function eM(e){return e.read(0,e.size)}var tM=S(()=>{Ur()});class hht{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=t}read(e){if(!Number.isInteger(e)||e<0||e>24||this.#s+e>this.#e.byteLength*8)throw new j(`Invalid ${this.#t} compressed data: truncated bitstream`);let t=0;for(let s=0;s<e;s++){let n=this.#s++;t=t*2+(this.#e[n>>>3]>>>7-(n&7)&1)}return t}assertZeroPadding(){while(this.#s<this.#e.byteLength*8)if(this.read(1)!==0)throw new j(`Invalid ${this.#t} compressed data: non-zero trailing bits`)}}class h0{#e=[-1];#t=[-1];#s=[-1];#n;constructor(e){this.#n=e}static single(e,t,s){if(!Number.isInteger(e)||e<0||e>=t)throw new j(`Invalid ${s} Huffman table: symbol is out of range`);let n=new h0(s);return n.#s[0]=e,n}static build(e,t,s){let n=new Uint32Array(17),o=0;for(let l=0;l<t;l++){let u=e[l];if(u>16)throw new j(`Invalid ${s} Huffman table: code is too long`);if(u!==0)n[u]++,o=Math.max(o,u)}if(o===0)throw new j(`Invalid ${s} Huffman table: no symbols`);let r=new Uint32Array(17),i=0;for(let l=1;l<=16;l++){if(i=(i+n[l-1])*2,i+n[l]>2**l)throw new j(`Invalid ${s} Huffman table: oversubscribed codes`);r[l]=i}if(r[o]+n[o]!==2**o)throw new j(`Invalid ${s} Huffman table: incomplete codes`);let a=new h0(s);for(let l=0;l<t;l++){let u=e[l];if(u===0)continue;let p=r[u];r[u]=p+1;let c=0;for(let d=u-1;d>=0;d--){if(a.#s[c]>=0)throw new j(`Invalid ${s} Huffman table: prefix collision`);let f=p>>>d&1,m=f===0?a.#e[c]:a.#t[c];if(m<0)if(m=a.#s.length,a.#e.push(-1),a.#t.push(-1),a.#s.push(-1),f===0)a.#e[c]=m;else a.#t[c]=m;c=m}if(a.#s[c]>=0||a.#e[c]>=0||a.#t[c]>=0)throw new j(`Invalid ${s} Huffman table: duplicate code`);a.#s[c]=l}return a}decode(e){let t=0;for(let s=0;s<=16;s++){let n=this.#s[t];if(n>=0)return n;if(t=e.read(1)===0?this.#e[t]:this.#t[t],t<0)throw new j(`Invalid ${this.#n} Huffman code`)}throw new j(`Invalid ${this.#n} Huffman code: excessive depth`)}}function cjs(e,t){let s=e.read(3);if(s===7){while(e.read(1)!==0)if(s++,s>16)throw new j(`Invalid ${t} Huffman table: code is too long`)}return s}function HBr(e,t){let n=e.read(5);if(n===0)return h0.single(e.read(5),19,t);if(n>19)throw new j(`Invalid ${t} temporary Huffman table size`);let o=new Uint8Array(19),r=0;while(r<n)if(o[r++]=cjs(e,t),r===3){let i=e.read(2);if(r+i>n)throw new j(`Invalid ${t} temporary Huffman table`);r+=i}return h0.build(o,19,t)}function BBr(e,t,s){let o=e.read(9);if(o===0)return h0.single(e.read(9),510,s);if(o>510)throw new j(`Invalid ${s} command Huffman table size`);let r=new Uint8Array(510),i=0;while(i<o){let a=t.decode(e);if(a<=2){let l=a===0?1:a===1?e.read(4)+3:e.read(9)+20;if(i+l>o)throw new j(`Invalid ${s} command Huffman table`);i+=l}else r[i++]=a-2}return h0.build(r,510,s)}function WBr(e,t,s,n){let o=e.read(t);if(o===0)return h0.single(e.read(t),s,n);if(o>s)throw new j(`Invalid ${n} position Huffman table size`);let r=new Uint8Array(s);for(let i=0;i<o;i++)r[i]=cjs(e,n);return h0.build(r,s,n)}function a6(e,t,s,n,o,r){let i=new hht(e,r),a=new Uint8Array(t),l=0,u=0,p,c;while(l<t){if(u===0){if(u=i.read(16),u===0)throw new j(`Invalid ${r} compressed data: empty block`);let T=HBr(i,r);p=BBr(i,T,r),c=WBr(i,n,o,r)}u--;let d=p.decode(i);if(d<256){a[l++]=d;continue}let f=d-256+3;if(f>t-l)throw new j(`Invalid ${r} compressed data: match exceeds declared size`);let m=c.decode(i),g=m;if(m>1){let T=m-1;g=2**T+i.read(T)}if(g>=s||g>=l)throw new j(`Invalid ${r} compressed data: history distance is out of range`);let h=l-g-1;for(let T=0;T<f;T++)a[l++]=a[h++]}if(u!==0)throw new j(`Invalid ${r} compressed data: block exceeds declared size`);return i.assertZeroPadding(),a}function GBr(e,t){let s=new hht(e,"LZH -lzs-"),n=new Uint8Array(t),o=new Uint8Array(2048);o.fill(32);let r=2031,i=0,a=(l)=>{if(i>=t)throw new j("Invalid LZH -lzs- data: output exceeds declared size");n[i++]=l,o[r]=l,r=r+1&2047};while(i<t)if(s.read(1)!==0)a(s.read(8));else{let l=s.read(11),u=s.read(4)+2;if(u>t-i)throw new j("Invalid LZH -lzs- data: match exceeds declared size");for(let p=0;p<u;p++)a(o[l+p&2047])}return s.assertZeroPadding(),n}function $Br(e,t,s){if(t<0)return i6(e);let n=i6(e.subarray(0,t));return n=i6(jBr.subarray(0,s-t),n),i6(e.subarray(s),n)}function g0(e,t){return e[t]|e[t+1]<<8}function sM(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function ajs(e,t){let s=sM(e,t)+sM(e,t+4)*4294967296;if(!Number.isSafeInteger(s))throw new j("LZH uses sizes too large to read safely");return s}function Yie(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid LZH archive: truncated ${n}`)}function ght(e){let t=e.indexOf(0);if(t<0)t=e.byteLength;return qBr.decode(e.subarray(0,t))}function ljs(e){if((e.byteLength&1)!==0)throw new j("Invalid LZH Unicode path header: odd UTF-16 length");let t=e.byteLength;while(t>=2&&e[t-1]===0&&e[t-2]===0)t-=2;return UBr.decode(e.subarray(0,t))}function zBr(e){if(e===0)return;let t=1980+(e>>>25&127),s=e>>>21&15,n=e>>>16&31,o=e>>>11&31,r=e>>>5&63,i=(e&31)*2;if(s<1||s>12||n<1||n>31||o>23||r>59||i>59)return;return Date.UTC(t,s-1,n,o,r,i)}function ujs(e,t,s,n){switch(e){case 0:if(t.byteLength<2)throw new j("Invalid LZH common extended header");n.commonCrc=g0(t,0),n.commonCrcOffset=s;break;case 1:n.filename=ght(t);break;case 2:n.directory=ght(t).replaceAll("\xFF","/");break;case 57:throw new j("Multi-volume LZH archives are unsupported");case 65:if(t.byteLength>=16){let o=sM(t,8),r=sM(t,12),i=o+r*4294967296;if(Number.isSafeInteger(i))n.mtimeMs=i/1e4-11644473600000}break;case 66:if(t.byteLength<16)throw new j("Invalid LZH 64-bit size extended header");n.packedSize=ajs(t,0),n.size=ajs(t,8);break;case 68:n.unicodeFilename=ljs(t);break;case 69:n.unicodeDirectory=ljs(t).replaceAll("\xFF","/");break;case 80:if(t.byteLength<2)throw new j("Invalid LZH Unix permissions extended header");n.mode=g0(t,0);break;case 84:if(t.byteLength<4)throw new j("Invalid LZH Unix timestamp extended header");n.mtimeMs=sM(t,0)*1000;break}}class djs{#e;#t;#s;#n;#o;constructor(e,t,s,n,o){this.#e=e,this.#t=t,this.#s=s,this.#n=n,this.#o=o}async read(e,t){let s=this.#e.subarray(this.#t,this.#t+this.#s),n;switch(this.#n){case"-lh0-":case"-lz4-":if(s.byteLength!==e)throw new j(`LZH member '${t}' has inconsistent stored size`);n=s.slice();break;case"-lh4-":n=a6(s,e,4096,4,13,"LZH -lh4-");break;case"-lh5-":n=a6(s,e,8192,4,14,"LZH -lh5-");break;case"-lh6-":n=a6(s,e,32768,5,16,"LZH -lh6-");break;case"-lh7-":n=a6(s,e,65536,5,17,"LZH -lh7-");break;case"-lzs-":n=GBr(s,e);break;case"-lh1-":throw new j(`LZH member '${t}' uses unsupported dynamic-Huffman method -lh1-`);default:throw new j(`LZH member '${t}' uses unsupported compression method ${this.#n}`)}if(n.byteLength!==e)throw new j(`LZH member '${t}' extracted to an unexpected size`);if(i6(n)!==this.#o)throw new j(`LZH member '${t}' failed CRC-16 verification`);return n}}function KBr(e,t,s){Yie(e,t,t+22,"header");let n=e[t+20];if(n>2)throw new j(`Unsupported LZH header level ${n}`);let o=String.fromCharCode(...e.subarray(t+2,t+7));if(!pjs.test(o))throw new j(`Invalid LZH compression method '${o}'`);let r=sM(e,t+7),i=sM(e,t+11),a=0,l,u,p=0,c,d={};if(n<2){let T=e[t];if(T<(n===0?22:25))throw new j(`Invalid LZH level-${n} header size`);let R=t+T+2;Yie(e,t,R,"header");let C=0;for(let w=t+2;w<R;w++)C=C+e[w]&255;if(C!==e[t+1])throw new j("Invalid LZH header checksum");let b=e[t+21];if(22+b+2>T+2)throw new j("Invalid LZH filename length");if(ko(b,"member path",s.limits.maxPathBytes),l=ght(e.subarray(t+22,t+22+b)),a=g0(e,t+22+b),u=zBr(sM(e,t+15)),n===0){let w=t+24+b;if(R-w>=12){let E=e.subarray(w,R);if((E[0]===85||E[0]===75)&&E[1]===0)p=E[0],d.mtimeMs=sM(E,2)*1000,d.mode=g0(E,E.byteLength-6)}c=R}else{p=e[t+24+b];let w=g0(e,R-2),E=R,x=0,A=0;while(w!==0){if(w<3)throw new j("Invalid LZH extended header size");if(Yie(e,E,E+w,"extended header"),x+=w,Hn(T+2+x,s.limits,"header metadata"),++A>65535)throw new j("Invalid LZH archive: too many extended headers");let M=e[E],I=E+w-2,O=e.subarray(E+1,I);if(M===1||M===2||M===68||M===69)ko(O.byteLength,"member path",s.limits.maxPathBytes);ujs(M,O,E+1,d);let P=w;w=g0(e,I),E+=P}if(c=R+x,r=d.packedSize??r-x,r<0)throw new j("Invalid LZH level-1 packed size")}}else{let T=g0(e,t);if(T<26)throw new j("Invalid LZH level-2 header size");let y=t+T;Yie(e,t,y,"header"),a=g0(e,t+21),p=e[t+23],u=sM(e,t+15)*1000;let R=t+24,C=0;while(R+2<=y){let b=g0(e,R);if(b===0){R+=2;break}if(b<3||R+b>y)throw new j("Invalid LZH extended header size");if(++C>65535)throw new j("Invalid LZH archive: too many extended headers");let w=e[R+2],E=e.subarray(R+3,R+b);if(w===1||w===2||w===68||w===69)ko(E.byteLength,"member path",s.limits.maxPathBytes);ujs(w,E,R+3,d),R+=b}if(R!==y)throw new j("Invalid LZH level-2 extended header chain");c=y,r=d.packedSize??r}if(n===1&&p===32&&o==="-lh7-")throw new j("LZH uses the incompatible LHARK -lh7- variant");i=d.size??i,u=d.mtimeMs??u;let f=d.mode;if(d.commonCrc!==void 0){let T=d.commonCrcOffset-t;if($Br(e.subarray(t,c),T,T+2)!==d.commonCrc)throw new j("Invalid LZH common header CRC-16")}let m=d.unicodeFilename??d.filename??l??"",g=d.unicodeDirectory??d.directory??"",h=`${g}${g&&!/[\\/]$/.test(g)?"/":""}${m}`;return Kd(h,"member path",s.limits.maxPathBytes),Qi(i,h||"<unnamed>",s.limits),Yie(e,c,c+r,"member data"),{method:o,packedSize:r,size:i,dataStart:c,nextOffset:c+r,crc:a,path:Sr(h),mtimeMs:u,mode:f}}function Tht(e){if(e.byteLength<22||e[2]!==45||e[6]!==45||e[3]!==108)return!1;let t=String.fromCharCode(...e.subarray(2,7));return pjs.test(t)&&e[20]<=2}var qBr,UBr,pjs,jBr,fjs=async(e,t)=>{ci(e.size,t.limits);let s;try{s=await eM(e)}catch(a){if(a instanceof j)throw a;throw new j(`Unable to read LZH archive: ${a instanceof Error?a.message:String(a)}`)}if(s.byteLength!==e.size)throw new j("Invalid LZH archive: truncated data");if(!Tht(s))throw new j("Invalid LZH archive header");let n=[],o=0,r=0,i=0;while(o<s.byteLength&&s[o]!==0){let a=KBr(s,o,t);if(i+=a.dataStart-o,Hn(i,t.limits,"index"),or(++r,t.limits),a.nextOffset<=o)throw new j("Invalid LZH archive: header did not advance");if(o=a.nextOffset,!a.path)continue;let l=a.method==="-lhd-";if(l&&a.mode!==void 0&&(a.mode&61440)===40960){let u=a.path.indexOf("|");if(u<1)throw new j(`Invalid LZH symbolic link '${a.path}'`);let p=Sr(a.path.slice(0,u)),c=Sr(a.path.slice(u+1));if(!p||!c)continue;n.push({path:p,isDirectory:!1,size:0,mtimeMs:a.mtimeMs,mode:a.mode,storage:{type:"link",targetPath:c,resolveTarget:!1}});continue}n.push({path:a.path,isDirectory:l,size:l?0:a.size,mtimeMs:a.mtimeMs,mode:a.mode,storage:l?void 0:{type:"member",source:new djs(s,a.dataStart,a.packedSize,a.method,a.crc)}})}if(n.length===0&&r===0)throw new j("Invalid LZH archive: no members");return n};var yht=S(()=>{m0();Ur();vp();Vd();tM();qBr=new TextDecoder("windows-1252"),UBr=new TextDecoder("utf-16"),pjs=/^-(?:lh[0-7d]|lz[45s])-$/;jBr=new Uint8Array(2)});function qPe(e,t){return e[t]|e[t+1]<<8}function fW(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Jie(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid ARJ archive: truncated ${n}`)}function YBr(e){if(e===0)return;let t=1980+(e>>>25&127),s=e>>>21&15,n=e>>>16&31,o=e>>>11&31,r=e>>>5&63,i=(e&31)*2;if(s<1||s>12||n<1||n>31||o>23||r>59||i>59)return;return Date.UTC(t,s-1,n,o,r,i)}function mjs(e,t,s,n){let o=t;while(o<s&&e[o]!==0)o++;if(o===s)throw new j(`Invalid ARJ ${n}: missing terminator`);return{value:VBr.decode(e.subarray(t,o)),next:o+1}}function gjs(e,t,s){if(Jie(e,t,t+4,"header signature"),e[t]!==hjs||e[t+1]!==Tjs)throw new j("Invalid ARJ header signature");let n=qPe(e,t+2);if(n===0)return{bodyStart:t+4,bodySize:0,nextOffset:t+4,metadataSize:4,isEnd:!0};if(n<30||n>yjs)throw new j("Invalid ARJ basic header size");let o=t+4,r=o+n;if(Jie(e,o,r+4,"basic header"),Wi(e.subarray(o,r))!==fW(e,r))throw new j("Invalid ARJ basic header CRC32");let i=r+4,a=0;for(;;){Jie(e,i,i+2,"extended header size");let l=qPe(e,i);if(i+=2,l===0)break;if(++a>65535)throw new j("Invalid ARJ archive: too many extended headers");if(Jie(e,i,i+l+4,"extended header"),Wi(e.subarray(i,i+l))!==fW(e,i+l))throw new j("Invalid ARJ extended header CRC32");i+=l+4,Hn(i-t,s.limits,"header metadata")}return{bodyStart:o,bodySize:n,nextOffset:i,metadataSize:i-t,isEnd:!1}}class Rjs{#e;#t=0;constructor(e){this.#e=e}read(e){if(!Number.isInteger(e)||e<0||e>24||this.#t+e>this.#e.byteLength*8)throw new j("Invalid ARJ method-4 compressed data: truncated bitstream");let t=0;for(let s=0;s<e;s++){let n=this.#t++;t=t*2+(this.#e[n>>>3]>>>7-(n&7)&1)}return t}assertZeroPadding(){while(this.#t<this.#e.byteLength*8)if(this.read(1)!==0)throw new j("Invalid ARJ method-4 compressed data: non-zero trailing bits")}}function JBr(e,t){let s=new Rjs(e),n=new Uint8Array(t),o=0;while(o<t){let r=0,i=0;for(;i<7;i++){if(s.read(1)===0)break;r+=2**i}if(i!==0)r+=s.read(i);if(r===0){n[o++]=s.read(8);continue}let a=r+2;if(a>t-o)throw new j("Invalid ARJ method-4 compressed data: match exceeds declared size");let l=0,u=9;for(;u<13;u++){if(s.read(1)===0)break;l+=2**u}if(l+=s.read(u),l>=26624||l>=o)throw new j("Invalid ARJ method-4 compressed data: history distance is out of range");let p=o-l-1;for(let c=0;c<a;c++)n[o++]=n[p++]}return s.assertZeroPadding(),n}class Cjs{#e;#t;#s;#n;#o;constructor(e,t,s,n,o){this.#e=e,this.#t=t,this.#s=s,this.#n=n,this.#o=o}async read(e,t){let s=this.#e.subarray(this.#t,this.#t+this.#s),n;switch(this.#n){case 0:if(s.byteLength!==e)throw new j(`ARJ member '${t}' has inconsistent stored size`);n=s.slice();break;case 1:case 2:case 3:n=a6(s,e,26624,5,17,`ARJ method ${this.#n}`);break;case 4:n=JBr(s,e);break;case 8:case 9:if(e!==0||s.byteLength!==0)throw new j(`ARJ member '${t}' has invalid no-data method sizes`);n=new Uint8Array(0);break;default:throw new j(`ARJ member '${t}' uses unsupported compression method ${this.#n}`)}if(n.byteLength!==e)throw new j(`ARJ member '${t}' extracted to an unexpected size`);if(this.#n!==8&&Wi(n)!==this.#o)throw new j(`ARJ member '${t}' failed CRC32 verification`);return n}}function XBr(e,t){let s=e.replaceAll("\\","/");if(t===1)s=s.replaceAll(">","/");else if(t===4)s=s.replaceAll(":","/");return s}function Rht(e){if(e.byteLength<34||e[0]!==hjs||e[1]!==Tjs)return!1;let t=qPe(e,2);if(t<30||t>yjs||e.byteLength<t+8)return!1;let s=e.subarray(4,4+t);return s[0]>=30&&s[0]<=t&&s[6]===2&&Wi(s)===fW(e,4+t)}var hjs=96,Tjs=234,yjs=2600,VBr,bjs=async(e,t)=>{ci(e.size,t.limits);let s;try{s=await eM(e)}catch(p){if(p instanceof j)throw p;throw new j(`Unable to read ARJ archive: ${p instanceof Error?p.message:String(p)}`)}if(s.byteLength!==e.size)throw new j("Invalid ARJ archive: truncated data");if(!Rht(s))throw new j("Invalid ARJ archive header");let n=gjs(s,0,t);if(n.isEnd)throw new j("Invalid ARJ archive: missing main header");let o=s[n.bodyStart];if(o<30||o>n.bodySize||s[n.bodyStart+6]!==2)throw new j("Invalid ARJ main header");let r=s[n.bodyStart+4];if((r&1)!==0)throw new j("Encrypted ARJ archives are unsupported");if((r&4)!==0)throw new j("Multi-volume ARJ archives are unsupported");let i=[],a=n.nextOffset,l=n.metadataSize,u=0;for(;;){let p=gjs(s,a,t);if(l+=p.metadataSize,Hn(l,t.limits,"index"),p.isEnd)break;or(++u,t.limits);let c=s[p.bodyStart];if(c<30||c>p.bodySize)throw new j("Invalid ARJ local header");let d=s[p.bodyStart+3],f=s[p.bodyStart+4],m=s[p.bodyStart+5],g=s[p.bodyStart+6];if((f&1)!==0)throw new j("Encrypted ARJ members are unsupported");if((f&12)!==0)throw new j("Multi-volume ARJ members are unsupported");let h=fW(s,p.bodyStart+12),T=fW(s,p.bodyStart+16),y=fW(s,p.bodyStart+20),R=qPe(s,p.bodyStart+26),C=mjs(s,p.bodyStart+c,p.bodyStart+p.bodySize,"filename");mjs(s,C.next,p.bodyStart+p.bodySize,"comment"),ko(C.next-(p.bodyStart+c)-1,"member path",t.limits.maxPathBytes);let b=XBr(C.value,d);Kd(b,"member path",t.limits.maxPathBytes),Qi(T,b||"<unnamed>",t.limits);let w=p.nextOffset;Jie(s,w,w+h,"member data"),a=w+h;let E=Sr(b);if(!E)continue;let x=g===3,A;if((d===2||d===8)&&R!==0)A=(x?16384:32768)|R&4095;let M=fW(s,p.bodyStart+8),I=d===2||d===8?M===0?void 0:M*1000:YBr(M);i.push({path:E,isDirectory:x,size:x?0:T,mtimeMs:I,mode:A,storage:x?void 0:{type:"member",source:new Cjs(s,w,h,m,y)}})}if(u===0)throw new j("Invalid ARJ archive: no members");return i};var kjs=S(()=>{m0();Ur();vp();yht();Vd();tM();VBr=new TextDecoder("windows-1252")});import*as wjs from"path";function Ai(e){return new j(`Invalid ASAR archive: ${e}`)}function HPe(e){return e instanceof Error&&e.message?e.message:String(e)}function Cht(e){return e+(4-e%4)%4}function Xie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function tWr(e,t,s){if(e===void 0)return;let n=dr(t);if(!Xie(e))throw Ai(`file '${n}' has an invalid integrity record`);if(e.algorithm!=="SHA256")throw Ai(`file '${n}' uses unsupported integrity algorithm '${String(e.algorithm)}'`);if(typeof e.hash!=="string"||!Sjs.test(e.hash))throw Ai(`file '${n}' has an invalid integrity hash`);if(typeof e.blockSize!=="number"||!Number.isSafeInteger(e.blockSize)||e.blockSize<=0)throw Ai(`file '${n}' has an invalid integrity block size`);if(!Array.isArray(e.blocks))throw Ai(`file '${n}' has invalid integrity blocks`);let o=Math.max(1,Math.ceil(s/e.blockSize));if(e.blocks.length!==o)throw Ai(`file '${n}' has an inconsistent integrity block count`);for(let r of e.blocks)if(typeof r!=="string"||!Sjs.test(r))throw Ai(`file '${n}' has an invalid integrity block hash`);return{algorithm:"SHA256",hash:e.hash.toLowerCase()}}function xjs(e,t,s){if(!t)return;if(new Bun.CryptoHasher("sha256").update(e).digest("hex")!==t.hash)throw new j(`ASAR member '${dr(s)}' failed SHA256 integrity verification`)}class Ejs{#e;#t;#s;#n;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}async read(e,t){if(e!==this.#s)throw new j(`ASAR member '${dr(t)}' has an inconsistent size`);let s;try{s=await this.#e.read(this.#t,this.#t+this.#s)}catch(n){if(n instanceof j)throw n;throw new j(`Failed to read ASAR member '${dr(t)}': ${HPe(n)}`)}if(s.byteLength!==this.#s)throw new j(`ASAR member '${dr(t)}' is truncated`);return xjs(s,this.#n,t),s}}class Mjs{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){let s=dr(t);if(e!==this.#t)throw new j(`ASAR member '${s}' has an inconsistent size`);if(!this.#e)throw new j(`Archive file '${s}' is unpacked and requires a filesystem-backed ASAR archive`);let n=Bun.file(this.#e),o=await n.stat().catch(()=>{throw new j(`Unpacked ASAR file '${s}' was not found`)});if(o.isDirectory())throw new j(`Unpacked ASAR file '${s}' is a directory`);if(o.size!==this.#t)throw new j(`Unpacked ASAR file '${s}' size differs from its archive header (${o.size} != ${this.#t} bytes)`);let r;try{r=await n.bytes()}catch(i){throw new j(`Failed to read unpacked ASAR file '${s}': ${HPe(i)}`)}if(r.byteLength!==this.#t)throw new j(`Unpacked ASAR file '${s}' changed while being read`);return xjs(r,this.#s,t),r}}async function sWr(e,t){if(!Number.isSafeInteger(e.size)||e.size<UPe)throw Ai("truncated header");let s=await e.read(0,l6);if(s.byteLength!==l6)throw Ai("truncated size pickle");if(Es(s,0)!==4)throw Ai("invalid size pickle");let n=Es(s,4);if(n<Qie)throw Ai("header is too small");Hn(n,t.limits,"ASAR header");let o=l6+n;if(!Number.isSafeInteger(o)||o>e.size)throw Ai("header extends beyond archive boundary");let r=await e.read(l6,o);if(r.byteLength!==n)throw Ai("truncated header pickle");let i=Es(r,0),a=Es(r,4);if(i+4!==n||i!==4+Cht(a))throw Ai("inconsistent pickle lengths");let l=Qie+a;for(let g=l;g<r.byteLength;g++)if(r[g]!==0)throw Ai("non-zero pickle string padding");let u;try{u=QBr.decode(r.subarray(Qie,l))}catch{throw Ai("header is not valid UTF-8")}let p;try{p=JSON.parse(u)}catch{throw Ai("header is not valid JSON")}if(!Xie(p)||!Xie(p.files))throw Ai("root must contain a files object");let c=[],d=[],f=0,m=(g,h,T)=>{for(let y in g)or(++f,t.limits),d.push({parentPath:h,parentPathBytes:T,name:y,node:g[y]})};m(p.files,"",0);while(d.length>0){let g=d.pop(),h=Buffer.byteLength(g.name,"utf-8");if(ko(h,"entry name",t.limits.maxPathBytes),g.name.length===0||g.name==="."||g.name===".."||g.name.includes("/")||g.name.includes("\\")||g.name.includes("\x00"))throw Ai(`invalid entry name '${dr(g.name)}'`);if(!Xie(g.node))throw Ai(`entry '${dr(g.name)}' must be an object`);let T=g.parentPathBytes+(g.parentPath?1:0)+h;ko(T,"member path",t.limits.maxPathBytes);let y=g.parentPath?`${g.parentPath}/${g.name}`:g.name;if(Sr(y)!==y)throw Ai(`invalid entry path '${dr(y)}'`);let C=dr(y);if(g.node.unpacked!==void 0&&typeof g.node.unpacked!=="boolean")throw Ai(`entry '${C}' has a non-boolean unpacked flag`);if("link"in g.node){if(typeof g.node.link!=="string"||g.node.link.length===0)throw Ai(`entry '${C}' has an invalid link target`);Kd(g.node.link,"link target",t.limits.maxPathBytes);let I=g.node.link.replace(/\\/g,"/"),O=I.startsWith("/")||/^[A-Za-z]:\//.test(I)?void 0:zd(I);if(O===void 0)throw Ai(`entry '${C}' links outside the archive`);c.push({path:y,isDirectory:!1,size:0,storage:{type:"link",targetPath:O,resolveTarget:!0}});continue}if("files"in g.node){if(!Xie(g.node.files))throw Ai(`directory '${C}' must contain a files object`);c.push({path:y,isDirectory:!0,size:0}),m(g.node.files,y,T);continue}let b=g.node.size;if(typeof b!=="number"||!Number.isSafeInteger(b)||b<0)throw Ai(`file '${C}' has an invalid size`);if(Qi(b,y,t.limits),g.node.executable!==void 0&&typeof g.node.executable!=="boolean")throw Ai(`file '${C}' has a non-boolean executable flag`);let w=typeof g.node.executable==="boolean"?eWr|(g.node.executable?493:420):void 0,E=tWr(g.node.integrity,y,b);if(g.node.unpacked===!0){let I=t.archivePath?wjs.join(`${t.archivePath}.unpacked`,...y.split("/")):void 0;c.push({path:y,isDirectory:!1,size:b,mode:w,storage:{type:"member",source:new Mjs(I,b,E)}});continue}if(typeof g.node.offset!=="string"||!/^\d+$/.test(g.node.offset))throw Ai(`file '${C}' has an invalid offset`);let x=Number(g.node.offset),A=o+x,M=A+b;if(!Number.isSafeInteger(x)||!Number.isSafeInteger(A)||!Number.isSafeInteger(M)||M>e.size)throw Ai(`file '${C}' extends beyond archive boundary`);c.push({path:y,isDirectory:!1,size:b,mode:w,storage:{type:"member",source:new Ejs(e,A,b,E)}})}return c}function vjs(e){if(e.byteLength<UPe+1)return!1;let t=Es(e,0),s=Es(e,4),n=Es(e,8),o=Es(e,12);return t===4&&s>=Qie&&s===n+4&&n===4+Cht(o)&&o>0&&e[UPe]===123}function nWr(e){let t=e.replace(/\\/g,"/"),s=Sr(t);if(s===void 0||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.includes("\x00")||t.split("/").some((n)=>!n||n==="."||n===".."))throw new j(`Invalid ASAR member path '${dr(e)}'`);return s}async function Ijs(e){try{let t={files:Object.create(null)},s=[],n=0;for(let d of e){if(!Array.isArray(d)||d.length!==2||typeof d[0]!=="string"||!(d[1]instanceof Uint8Array))throw new j("ASAR members must be [path, Uint8Array] pairs");let f=nWr(d[0]),m=f.split("/"),g=t;for(let T=0;T<m.length-1;T++){let y=m[T],R=g.files[y];if(R&&!("files"in R))throw new j(`ASAR member path '${f}' crosses file '${m.slice(0,T+1).join("/")}'`);if(!R)g.files[y]={files:Object.create(null)};g=g.files[y]}let h=m.at(-1);if(g.files[h])throw new j(`Duplicate or conflicting ASAR member path '${f}'`);if(!Number.isSafeInteger(d[1].byteLength)||!Number.isSafeInteger(n+d[1].byteLength))throw new j("ASAR payload is too large to encode safely");g.files[h]={size:d[1].byteLength,offset:String(n)},s.push(d[1]),n+=d[1].byteLength}let o=ZBr.encode(JSON.stringify(t)),i=4+Cht(o.byteLength),a=4+i;if(o.byteLength>4294967295||a>4294967295)throw new j("ASAR header is too large to encode");let l=l6+a,u=l+n;if(!Number.isSafeInteger(u))throw new j("ASAR archive is too large to encode safely");let p;try{p=new Uint8Array(u)}catch{throw new j("ASAR archive is too large to encode in memory")}dl(p,0,4),dl(p,4,a),dl(p,8,i),dl(p,12,o.byteLength),p.set(o,UPe);let c=l;for(let d of s)p.set(d,c),c+=d.byteLength;return p}catch(t){if(t instanceof j)throw t;throw new j(`Failed to encode ASAR archive: ${HPe(t)}`)}}var QBr,ZBr,l6=8,Qie=8,UPe,eWr=32768,Sjs,Ajs=async(e,t)=>{try{return await sWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(`Failed to read ASAR archive: ${HPe(s)}`)}};var bht=S(()=>{Sh();Ur();vp();Vd();QBr=new TextDecoder("utf-8",{fatal:!0}),ZBr=new TextEncoder,UPe=l6+Qie,Sjs=/^[0-9a-f]{64}$/i});class Fjs{#e;#t=0;#s=0;#n=0;constructor(e){this.#e=e}readBits(e){let t=0,s=e;while(s>0){if(this.#n===0){if(this.#t+2>this.#e.byteLength)throw new j("Invalid CAB archive: truncated LZX bitstream");this.#s=this.#e[this.#t]|this.#e[this.#t+1]<<8,this.#t+=2,this.#n=16}let n=Math.min(s,this.#n);t=t*2**n+(this.#s>>>this.#n-n&2**n-1),this.#n-=n,s-=n}return t}alignWord(){this.#n=0}readByte(){if(this.#n!==0)throw new j("Invalid CAB archive: misaligned LZX byte stream");if(this.#t>=this.#e.byteLength)throw new j("Invalid CAB archive: truncated LZX data");return this.#e[this.#t++]}readUInt32LE(){let e=this.readByte(),t=this.readByte(),s=this.readByte(),n=this.readByte();return(e|t<<8|s<<16|n<<24)>>>0}}class Zie{#e=new Uint32Array(17);#t=new Uint32Array(17);#s=new Uint32Array(17);#n;empty;constructor(e,t=!1){let s=0;for(let i of e){if(i>16)throw new j("Invalid CAB archive: invalid LZX Huffman code length");if(i!==0)this.#e[i]++,s++}if(this.empty=s===0,this.empty&&!t)throw new j("Invalid CAB archive: empty LZX Huffman tree");let n=0,o=0;for(let i=1;i<=16;i++){if(n=(n+this.#e[i-1])*2,n+this.#e[i]>2**i)throw new j("Invalid CAB archive: oversubscribed LZX Huffman tree");this.#t[i]=n,this.#s[i]=o,o+=this.#e[i]}this.#n=new Uint16Array(s);let r=this.#s.slice();for(let i=0;i<e.byteLength;i++){let a=e[i];if(a!==0)this.#n[r[a]]=i;r[a]++}}decode(e){if(this.empty)throw new j("Invalid CAB archive: LZX stream uses an empty Huffman tree");let t=0;for(let s=1;s<=16;s++){t=t*2+e.readBits(1);let n=t-this.#t[s];if(n>=0&&n<this.#e[s])return this.#n[this.#s[s]+n]}throw new j("Invalid CAB archive: invalid LZX Huffman symbol")}}function kht(e,t,s,n){let o=new Uint8Array(20);for(let a=0;a<o.byteLength;a++)o[a]=e.readBits(4);let r=new Zie(o),i=s;while(i<n){let a=r.decode(e);if(a===17||a===18){let l=e.readBits(a===17?4:5)+(a===17?4:20);if(i+l>n)throw new j("Invalid CAB archive: LZX code-length run exceeds its tree");t.fill(0,i,i+l),i+=l;continue}if(a===19){let l=e.readBits(1)+4;if(i+l>n)throw new j("Invalid CAB archive: LZX code-length run exceeds its tree");let u=r.decode(e),p=(t[i]-u+17)%17;t.fill(p,i,i+l),i+=l;continue}t[i]=(t[i]-a+17)%17,i++}}function Pjs(e){return e>2147483647?e-4294967296:e}class Sht{#e;#t;#s;#n;#o=new Uint8Array(iWr);#r;#a;#i;#l=0;#u=0;#p=0;#c=1;#d=1;#m=1;#f=!1;#h=0;#T=!1;#g=0;#y=0;#R=0;#C=!1;constructor(e){if(!Number.isInteger(e)||e<15||e>21)throw new j(`Unsupported CAB LZX window size: ${e} bits (expected 15-21)`);this.#e=new Uint8Array(2**e);let t=aWr[e-15];this.#n=new Uint8Array(256+t*8),this.#s=new Uint8Array(t),this.#t=new Uint32Array(t);for(let s=0;s<t;s++)if(this.#s[s]=s<4?0:Math.min(17,Math.floor(s/2)-1),s>0)this.#t[s]=this.#t[s-1]+2**this.#s[s-1]}decompressFrame(e,t){if(!Number.isInteger(t)||t<0||t>oWr)throw new j(`Invalid CAB archive: LZX frame size ${t} exceeds 32768 bytes`);if(t===0)return new Uint8Array(0);let s=new Fjs(e);if(!this.#f){if(s.readBits(1)!==0){let i=s.readBits(16),a=s.readBits(16);this.#h=Pjs(i*65536+a>>>0)}this.#f=!0}let n=new Uint8Array(t),o=0;while(o<t){if(this.#R===0)this.#k(s);let i=Math.min(this.#R,t-o),a=this.#S(s,n,o,i);if(a!==i)throw new j("Invalid CAB archive: LZX block produced the wrong byte count");o+=a,this.#R-=a}if(this.#R===0&&this.#g===3&&this.#C)s.readByte(),this.#C=!1;s.alignWord();let r=this.#x(n);return this.#p++,r}#k(e){if(this.#g===3&&this.#C)e.readByte();if(this.#C=!1,this.#g=e.readBits(3),this.#y=e.readBits(16)*256+e.readBits(8),this.#y===0)throw new j("Invalid CAB archive: zero-length LZX block");if(this.#R=this.#y,this.#g===1||this.#g===2){if(this.#g===2){let t=new Uint8Array(8);for(let s=0;s<t.byteLength;s++)t[s]=e.readBits(3);this.#i=new Zie(t)}if(kht(e,this.#n,0,256),kht(e,this.#n,256,this.#n.byteLength),this.#r=new Zie(this.#n),this.#n[232]!==0)this.#T=!0;kht(e,this.#o,0,this.#o.byteLength),this.#a=new Zie(this.#o,!0);return}if(this.#g===3){if(this.#T=!0,e.alignWord(),this.#c=e.readUInt32LE(),this.#d=e.readUInt32LE(),this.#m=e.readUInt32LE(),this.#c===0||this.#d===0||this.#m===0)throw new j("Invalid CAB archive: invalid LZX repeated offset");this.#C=(this.#y&1)!==0;return}throw new j(`Invalid CAB archive: unsupported LZX block type ${this.#g}`)}#S(e,t,s,n){if(this.#g===3){for(let r=0;r<n;r++)this.#b(e.readByte(),t,s+r);return n}if(!this.#r||!this.#a)throw new j("Invalid CAB archive: missing LZX decode trees");let o=0;while(o<n){let r=this.#r.decode(e);if(r<256){this.#b(r,t,s+o),o++;continue}let i=r-256,a=i&Ojs;if(a===Ojs)a+=this.#a.decode(e);if(a+=rWr,a>n-o||a>this.#R-o)throw new j("Invalid CAB archive: LZX match crosses a frame or block boundary");let l=i>>>3,u;if(l===0)u=this.#c;else if(l===1)u=this.#d,this.#d=this.#c,this.#c=u;else if(l===2)u=this.#m,this.#m=this.#c,this.#c=u;else{if(l>=this.#t.byteLength)throw new j("Invalid CAB archive: LZX position slot is out of range");let p=this.#s[l];if(u=this.#t[l]-2,this.#g===2&&p>=3){if(p>3)u+=e.readBits(p-3)*8;if(!this.#i)throw new j("Invalid CAB archive: missing LZX aligned tree");u+=this.#i.decode(e)}else if(p!==0)u+=e.readBits(p);this.#m=this.#d,this.#d=this.#c,this.#c=u}if(u<=0||u>Math.min(this.#u,this.#e.byteLength))throw new j("Invalid CAB archive: LZX match offset exceeds available history");for(let p=0;p<a;p++){let c=(this.#l-u+this.#e.byteLength)%this.#e.byteLength;this.#b(this.#e[c],t,s+o+p)}o+=a}return o}#b(e,t,s){t[s]=e,this.#e[this.#l]=e,this.#l=(this.#l+1)%this.#e.byteLength,this.#u++}#x(e){if(!this.#T||this.#h===0||this.#p>=32768||e.byteLength<=10)return e;let t=e.slice(),s=0,n=this.#u-e.byteLength,o=t.byteLength-10;while(s<o){if(t[s++]!==232){n++;continue}let r=Pjs((t[s]|t[s+1]<<8|t[s+2]<<16|t[s+3]<<24)>>>0);if(r>=-n&&r<this.#h){let i=r>=0?r-n:r+this.#h;t[s]=i&255,t[s+1]=i>>>8&255,t[s+2]=i>>>16&255,t[s+3]=i>>>24&255}s+=4,n+=5}return t}}var oWr=32768,rWr=2,Ojs=7,iWr=249,aWr;var _js=S(()=>{Ur();aWr=[30,32,34,36,38,42,50]});import*as Njs from"zlib";async function eae(e,t,s,n=e.size){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>n)throw new j("Invalid CAB archive: metadata range is out of bounds");let o;try{o=await e.read(t,s)}catch(r){if(r instanceof j)throw r;throw new j(`Unable to read CAB archive: ${r instanceof Error?r.message:String(r)}`)}if(o.byteLength!==s-t)throw new j("Invalid CAB archive: truncated data");return o}function qjs(e){return e.byteLength>=4&&e[0]===77&&e[1]===83&&e[2]===67&&e[3]===70}function Djs(e,t=0){let s=t>>>0,n=0;while(n+4<=e.byteLength)s^=Es(e,n),n+=4;let o=e.byteLength-n,r=0;if(o===3)r=e[n]<<16|e[n+1]<<8|e[n+2];else if(o===2)r=e[n]<<8|e[n+1];else if(o===1)r=e[n];return(s^r)>>>0}function gWr(e,t){try{return t?fWr.decode(e):mWr.decode(e)}catch{throw new j("Invalid CAB archive: file name is not valid UTF-8")}}function hWr(e,t){if(e===0&&t===0)return;let s=1980+(e>>>9),n=e>>>5&15,o=e&31,r=t>>>11,i=t>>>5&63,a=(t&31)*2;if(n<1||n>12||o<1||o>31||r>23||i>59||a>59)throw new j("Invalid CAB archive: file has an invalid DOS timestamp");return new Date(s,n-1,o,r,i,a).getTime()}function TWr(e,t){if(t)return 16877;let s=e&uWr?292:420;if(e&cWr)s|=73;return 32768|s}class Ujs{#e;#t;#s;#n;#o;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}readAll(){return this.#o??=this.#r(),this.#o}async#r(){let e=this.#t;if(e.method===2)throw new j(`Unsupported CAB compression method: Quantum (level ${e.parameter})`);if(e.method>3)throw new j(`Unsupported CAB compression method: ${e.method}`);if(e.method===3&&(e.parameter<15||e.parameter>21))throw new j(`Unsupported CAB LZX window size: ${e.parameter} bits (expected 15-21)`);let t=e.dataEnd-e.dataStart;ci(t,this.#n);let s=await eae(this.#e,e.dataStart,e.dataEnd),n=0,o=0;for(let l=0;l<e.blockCount;l++){if(n+wht+this.#s>s.byteLength)throw new j("Invalid CAB archive: truncated CFDATA header");let u=xn(s,n+4),p=xn(s,n+6);if(p===0)throw new j("Unsupported multi-volume CAB archive: split CFDATA block");if(p>Ljs)throw new j(`Invalid CAB archive: CFDATA expands to ${p} bytes (maximum 32768)`);let c=n+wht+this.#s,d=c+u;if(d>s.byteLength)throw new j("Invalid CAB archive: truncated CFDATA payload");let f=Es(s,n);if(f!==0){let m=Djs(s.subarray(c,d));if(Djs(s.subarray(n+4,c),m)!==f)throw new j(`Invalid CAB archive: CFDATA block ${l} checksum mismatch`)}o+=p,ci(o,this.#n),n=d}if(o<e.requiredSize)throw new j("Invalid CAB archive: folder data is shorter than its file table declares");let r=new Uint8Array(o),i=e.method===3?new Sht(e.parameter):void 0;n=0;let a=0;for(let l=0;l<e.blockCount;l++){let u=xn(s,n+4),p=xn(s,n+6),c=n+wht+this.#s,d=c+u,f=s.subarray(c,d),m;if(e.method===0){if(u!==p)throw new j("Invalid CAB archive: uncompressed CFDATA sizes do not match");m=f}else if(e.method===1){if(f.byteLength<2||f[0]!==67||f[1]!==75)throw new j("Invalid CAB archive: MSZIP block is missing its CK signature");try{let g=r.subarray(Math.max(0,a-Ljs),a);m=new Uint8Array(Njs.inflateRawSync(f.subarray(2),{dictionary:g,maxOutputLength:p}))}catch(g){throw new j(`Invalid CAB archive: MSZIP decompression failed${g instanceof Error?`: ${g.message}`:""}`)}}else m=i.decompressFrame(f,p);if(m.byteLength!==p)throw new j(`Invalid CAB archive: CFDATA block ${l} produced ${m.byteLength} bytes, expected ${p}`);r.set(m,a),a+=m.byteLength,n=d}return r}}class Hjs{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){if(e!==this.#s)throw new j(`Invalid CAB archive: size changed while extracting '${t}'`);let s=await this.#e.readAll(),n=this.#t+e;if(!Number.isSafeInteger(n)||this.#t<0||n>s.byteLength)throw new j(`Invalid CAB archive: member '${t}' is outside its folder data`);return s.slice(this.#t,n)}}async function yWr(e,t){if(e.size<mW)throw new j("Invalid CAB archive: truncated CFHEADER");let s=await eae(e,0,mW);if(!qjs(s))throw new j(`Invalid CAB archive: expected ${lWr} signature`);if(Es(s,4)!==0||Es(s,12)!==0||Es(s,20)!==0)throw new j("Invalid CAB archive: reserved CFHEADER fields must be zero");let n=Es(s,8);if(n<mW||n>e.size)throw new j("Invalid CAB archive: declared cabinet size is out of bounds");let o=Es(s,16);if(o<mW||o>n)throw new j("Invalid CAB archive: CFFILE table offset is out of bounds");if(s[24]!==3||s[25]!==1)throw new j(`Unsupported CAB format version ${s[25]}.${s[24]} (expected 1.3)`);let r=xn(s,26),i=xn(s,28),a=xn(s,30);if(a&3)throw new j("Unsupported multi-volume CAB archive (previous/next cabinet link)");if(or(r+i,t.limits),r===0&&i!==0)throw new j("Invalid CAB archive: files exist without a folder");let l=0,u=0,p=0,c=mW;if(a&4){let b=await eae(e,mW,mW+4,n);if(l=xn(b,0),u=b[2],p=b[3],l>60000)throw new j("Invalid CAB archive: CFHEADER reserve area exceeds 60000 bytes");c+=4+l}let d=8+u,f=c+r*d;if(!Number.isSafeInteger(f)||f>n||f>o)throw new j("Invalid CAB archive: CFFOLDER table is out of bounds");Hn(f,t.limits,"CAB header");let m=await eae(e,0,f,n),g=[];for(let b=0;b<r;b++){let w=c+b*d,E=xn(m,w+6);g.push({dataStart:Es(m,w),dataEnd:n,blockCount:xn(m,w+4),method:E&15,parameter:E>>>8,requiredSize:0})}for(let b of g){if(b.dataStart<f||b.dataStart>n)throw new j("Invalid CAB archive: CFFOLDER data offset is out of bounds");for(let w of g)if(w.dataStart>b.dataStart&&w.dataStart<b.dataEnd)b.dataEnd=w.dataStart}let h=g.reduce((b,w)=>Math.min(b,w.dataStart),n);if(o>h)throw new j("Invalid CAB archive: CFFILE table overlaps folder data");Hn(f+(h-o),t.limits,"CAB index");let T=await eae(e,o,h,n),y=g.map((b)=>new Ujs(e,b,p,t.limits)),R=[],C=0;for(let b=0;b<i;b++){if(C+16>T.byteLength)throw new j("Invalid CAB archive: truncated CFFILE entry");let w=Es(T,C),E=Es(T,C+4),x=xn(T,C+8),A=xn(T,C+10),M=xn(T,C+12),I=xn(T,C+14);C+=16;let O=T.indexOf(0,C);if(O<0)throw new j("Invalid CAB archive: unterminated CFFILE name");let P=T.subarray(C,O);if(P.byteLength>256)throw new j("Invalid CAB archive: CFFILE name exceeds 256 bytes");if(ko(P.byteLength,"member path",t.limits.maxPathBytes),C=O+1,x>=65533)throw new j("Unsupported multi-volume CAB archive: continued file");if(x>=y.length)throw new j("Invalid CAB archive: CFFILE references a missing folder");let F=gWr(P,(I&dWr)!==0);Qi(w,F,t.limits);let _=E+w;if(!Number.isSafeInteger(_))throw new j("Invalid CAB archive: CFFILE range is too large");if(_>g[x].requiredSize)g[x].requiredSize=_;let D=Sr(F);if(!D)continue;let L=(I&pWr)!==0;R.push({path:D,isDirectory:L,size:w,mtimeMs:hWr(A,M),mode:TWr(I,L),storage:L?void 0:{type:"member",source:new Hjs(y[x],E,w)}})}for(let b of g)ci(b.requiredSize,t.limits);return R}function Bjs(e){return qjs(e)}var lWr="MSCF",mW=36,wht=8,Ljs=32768,uWr=1,pWr=16,cWr=64,dWr=128,fWr,mWr,Wjs=async(e,t)=>{try{return await yWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(`Invalid CAB archive: ${s instanceof Error?s.message:String(s)}`)}};var Gjs=S(()=>{Sh();_js();Ur();vp();Vd();fWr=new TextDecoder("utf-8",{fatal:!0}),mWr=new TextDecoder("windows-1252")});function xWr(){let e=new Uint32Array(256);for(let t=0;t<e.length;t++){let s=t<<24;for(let n=0;n<8;n++)s=(s&2147483648)!==0?s<<1^79764919:s<<1;e[t]=s>>>0}return e}function jjs(e,t){return(wWr[(e>>>24^t)&255]^e<<8)>>>0}class zjs{#e;#t=0;constructor(e){this.#e=e}get done(){return this.#t===this.#e.byteLength*8}readBit(){if(this.#t>=this.#e.byteLength*8)throw new j("Truncated bzip2 stream");let t=this.#e[this.#t>>>3]>>>7-(this.#t&7)&1;return this.#t++,t}readBits(e){let t=0;for(let s=0;s<e;s++)t=t*2+this.readBit();return t}readUint32(){return this.readBits(16)*65536+this.readBits(16)>>>0}readMarker(){return[this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8),this.readBits(8)]}alignToByte(){while((this.#t&7)!==0)if(this.readBit()!==0)throw new j("Invalid non-zero bzip2 stream padding")}}class Kjs{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=new Uint8Array(Math.min(e,Math.max(64,Math.min(t*2,65536))))}push(e){this.#n(1),this.#t[this.#s++]=e}pushRepeated(e,t){this.#n(t),this.#t.fill(e,this.#s,this.#s+t),this.#s+=t}finish(){return this.#t.slice(0,this.#s)}#n(e){let t=this.#s+e;if(!Number.isSafeInteger(t)||t>this.#e)throw new j(`Bzip2 output exceeds the ${this.#e}-byte limit`);if(t<=this.#t.byteLength)return;let s=Math.max(t,Math.min(this.#e,Math.max(64,this.#t.byteLength*2)));if(s>this.#e)s=this.#e;let n=new Uint8Array(s);n.set(this.#t.subarray(0,this.#s)),this.#t=n}}class Vjs{#e=new Uint16Array(gW+1);#t=new Uint32Array(gW+1);#s=new Uint16Array(gW+1);#n;constructor(e){for(let o of e){if(o<1||o>gW)throw new j("Invalid bzip2 Huffman code length");this.#e[o]++}let t=0,s=0;for(let o=1;o<=gW;o++){if(t=(t+this.#e[o-1])*2,t+this.#e[o]>2**o)throw new j("Oversubscribed bzip2 Huffman table");this.#t[o]=t,this.#s[o]=s,s+=this.#e[o]}this.#n=new Uint16Array(e.length);let n=new Uint16Array(this.#s);for(let o=0;o<e.length;o++){let r=e[o];this.#n[n[r]]=o,n[r]++}}decode(e){let t=0;for(let s=1;s<=gW;s++){t=t*2+e.readBit();let n=t-this.#t[s];if(n>=0&&n<this.#e[s])return this.#n[this.#s[s]+n]}throw new j("Invalid bzip2 Huffman code")}}function $js(e,t){return e.every((s,n)=>s===t[n])}function EWr(e){if(e.readBits(8)!==66||e.readBits(8)!==90||e.readBits(8)!==104)throw new j("Invalid bzip2 stream header");let t=e.readBits(8)-48;if(t<1||t>9)throw new j("Invalid bzip2 block-size level");return t*1e5}function MWr(e,t){let s=e.readBits(3);if(s<2||s>6)throw new j("Invalid bzip2 Huffman group count");let n=e.readBits(15);if(n<1||n>bWr)throw new j("Invalid bzip2 selector count");let o=new Uint8Array(n),r=new Uint8Array(s);for(let l=0;l<s;l++)r[l]=l;for(let l=0;l<n;l++){let u=0;while(e.readBit()!==0)if(u++,u>=s)throw new j("Invalid bzip2 selector MTF value");let p=r[u];o[l]=p,r.copyWithin(1,0,u),r[0]=p}let i=t.length+2,a=[];for(let l=0;l<s;l++){let u=new Uint8Array(i),p=e.readBits(5);for(let c=0;c<i;c++){while(e.readBit()!==0)if(p+=e.readBit()===0?1:-1,p<1||p>gW)throw new j("Invalid bzip2 Huffman code length");u[c]=p}a.push(new Vjs(u))}return{selectors:o,tables:a}}function AWr(e,t,s,n,o){let r=new Uint8Array(s),i=new Uint8Array(t),a=0,l=0,u=0,p,c=()=>{if(u===0){if(l>=n.length)throw new j("Bzip2 block exhausted its Huffman selectors");p=o[n[l++]],u=kWr}return u--,p.decode(e)},d=(g,h)=>{if(h<0||a+h>t)throw new j("Bzip2 block exceeds its declared block-size level");i.fill(g,a,a+h),a+=h},f=s.length+1,m=c();while(m!==f){if(m===0||m===1){let T=0,y=1;do{if(T+=m===0?y:y*2,T>t||y>t)throw new j("Invalid bzip2 RLE run length");y*=2,m=c()}while(m===0||m===1);if(d(r[0],T),m===f)break}let g=m-1;if(g<0||g>=r.length)throw new j("Invalid bzip2 MTF symbol");let h=r[g];r.copyWithin(1,0,g),r[0]=h,d(h,1),m=c()}return i.slice(0,a)}function vWr(e,t){if(e.length===0||t<0||t>=e.length)throw new j("Invalid bzip2 BWT origin pointer");let s=new Uint32Array(257);for(let a of e)s[a+1]++;for(let a=1;a<s.length;a++)s[a]+=s[a-1];let n=new Uint32Array(s.subarray(0,256)),o=new Uint32Array(e.length);for(let a=0;a<e.length;a++){let l=e[a];o[n[l]]=a,n[l]++}let r=new Uint8Array(e.length),i=o[t];for(let a=0;a<r.length;a++)r[a]=e[i],i=o[i];return r}function IWr(e,t,s){let n=4294967295,o=-1,r=0,i=0,a=0,l=(p)=>{s.push(p),n=jjs(n,p)},u=(p,c)=>{s.pushRepeated(p,c);for(let d=0;d<c;d++)n=jjs(n,p)};for(let p of e){if(t){if(a===0)a=SWr[i],i=i+1&511;if(a--,a===1)p^=1}if(r===4){u(o,p),r=0;continue}if(l(p),p===o)r++;else o=p,r=1}if(r===4)throw new j("Truncated bzip2 RLE run");return(n^4294967295)>>>0}function OWr(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid bzip2 output limit");let s=new zjs(e),n=new Kjs(t,e.byteLength);for(;;){let o=EWr(s),r=0;for(;;){let i=s.readMarker();if($js(i,CWr)){let R=s.readUint32();if(r!==R)throw new j("Bzip2 stream CRC mismatch");s.alignToByte();break}if(!$js(i,RWr))throw new j("Invalid bzip2 block marker");let a=s.readUint32(),l=s.readBit()!==0,u=s.readBits(24),p=s.readBits(16),c=new Uint8Array(256),d=0;for(let R=0;R<16;R++){if((p&32768>>>R)===0)continue;for(let C=0;C<16;C++)if(s.readBit()!==0)c[d++]=R*16+C}if(d===0)throw new j("Bzip2 block has an empty symbol map");let f=c.slice(0,d),{selectors:m,tables:g}=MWr(s,f),h=AWr(s,o,f,m,g),T=vWr(h,u),y=IWr(T,l,n);if(y!==a)throw new j("Bzip2 block CRC mismatch");r=((r<<1|r>>>31)^y)>>>0}if(s.done)return n.finish()}}function BPe(e){return e.byteLength>=4&&e[0]===66&&e[1]===90&&e[2]===104&&e[3]>=49&&e[3]<=57}async function T0(e,t){try{return OWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}}var RWr,CWr,gW=20,bWr=18002,kWr=50,SWr,wWr;var tae=S(()=>{Ur();RWr=[49,65,89,38,83,89],CWr=[23,114,69,56,80,144],SWr=new Uint16Array([619,720,127,481,931,816,813,233,566,247,985,724,205,454,863,491,741,242,949,214,733,859,335,708,621,574,73,654,730,472,419,436,278,496,867,210,399,680,480,51,878,465,811,169,869,675,611,697,867,561,862,687,507,283,482,129,807,591,733,623,150,238,59,379,684,877,625,169,643,105,170,607,520,932,727,476,693,425,174,647,73,122,335,530,442,853,695,249,445,515,909,545,703,919,874,474,882,500,594,612,641,801,220,162,819,984,589,513,495,799,161,604,958,533,221,400,386,867,600,782,382,596,414,171,516,375,682,485,911,276,98,553,163,354,666,933,424,341,533,870,227,730,475,186,263,647,537,686,600,224,469,68,770,919,190,373,294,822,808,206,184,943,795,384,383,461,404,758,839,887,715,67,618,276,204,918,873,777,604,560,951,160,578,722,79,804,96,409,713,940,652,934,970,447,318,353,859,672,112,785,645,863,803,350,139,93,354,99,820,908,609,772,154,274,580,184,79,626,630,742,653,282,762,623,680,81,927,626,789,125,411,521,938,300,821,78,343,175,128,250,170,774,972,275,999,639,495,78,352,126,857,956,358,619,580,124,737,594,701,612,669,112,134,694,363,992,809,743,168,974,944,375,748,52,600,747,642,182,862,81,344,805,988,739,511,655,814,334,249,515,897,955,664,981,649,113,974,459,893,228,433,837,553,268,926,240,102,654,459,51,686,754,806,760,493,403,415,394,687,700,946,670,656,610,738,392,760,799,887,653,978,321,576,617,626,502,894,679,243,440,680,879,194,572,640,724,926,56,204,700,707,151,457,449,797,195,791,558,945,679,297,59,87,824,713,663,412,693,342,606,134,108,571,364,631,212,174,643,304,329,343,97,430,751,497,314,983,374,822,928,140,206,73,263,980,736,876,478,430,305,170,514,364,692,829,82,855,953,676,246,369,970,294,750,807,827,150,790,288,923,804,378,215,828,592,281,565,555,710,82,896,831,547,261,524,462,293,465,502,56,661,821,976,991,658,869,905,758,745,193,768,550,608,933,378,286,215,979,792,961,61,688,793,644,986,403,106,366,905,644,372,567,466,434,645,210,389,550,919,135,780,773,635,389,707,100,626,958,165,504,920,176,193,713,857,265,203,50,668,108,645,990,626,197,510,357,358,850,858,364,936,638]),wWr=xWr()});import{promisify as Yjs}from"util";import*as WPe from"zlib";function GPe(e){return e.byteLength>=2&&e[0]===31&&e[1]===139}async function hW(e,t){try{return await FWr(e,{maxOutputLength:Math.max(t,1)})}catch(s){throw new j(s instanceof Error?s.message:String(s))}}function Jjs(e){return PWr(e)}var PWr,FWr;var sae=S(()=>{Ur();PWr=Yjs(WPe.gzip),FWr=Yjs(WPe.gunzip)});class Zjs{bytes;pos=0;range=4294967295;code=0;constructor(e){if(this.bytes=e,e.byteLength<5||e[0]!==0)throw new j("Invalid LZMA range-coded stream");for(let t=0;t<5;t++)this.code=(this.code<<8|e[this.pos++])>>>0}#e(){if(this.range<_Wr){if(this.pos>=this.bytes.byteLength)throw new j("Invalid LZMA stream: truncated range data");this.range=this.range<<8>>>0,this.code=(this.code<<8|this.bytes[this.pos++])>>>0}}decodeBit(e,t){this.#e();let s=e[t],n=Math.imul(this.range>>>11,s)>>>0;if(this.code<n)return this.range=n,e[t]=s+(zf-s>>>Xjs),0;return this.range=this.range-n>>>0,this.code=this.code-n>>>0,e[t]=s-(s>>>Xjs),1}decodeDirectBits(e){let t=0;for(let s=0;s<e;s++){this.#e(),this.range>>>=1;let n=0;if(this.code>=this.range)this.code=this.code-this.range>>>0,n=1;t=(t<<1|n)>>>0}return t}}function Ym(e){let t=new Uint16Array(e);return t.fill(zf>>>1),t}class Mht{choice=Ym(2);low=Ym($Pe<<3);mid=Ym($Pe<<3);high=Ym(256);reset(){this.choice.fill(zf>>>1),this.low.fill(zf>>>1),this.mid.fill(zf>>>1),this.high.fill(zf>>>1)}decode(e,t){if(e.decodeBit(this.choice,0)===0)return jPe(e,this.low,t<<3,3);if(e.decodeBit(this.choice,1)===0)return 8+jPe(e,this.mid,t<<3,3);return 16+jPe(e,this.high,0,8)}}function jPe(e,t,s,n){let o=1;for(let r=0;r<n;r++)o=o<<1|e.decodeBit(t,s+o);return o-(1<<n)}function Qjs(e,t,s,n){let o=1,r=0;for(let i=0;i<n;i++){let a=e.decodeBit(t,s+o);o=o<<1|a,r|=a<<i}return r>>>0}function e$s(e){if(e.byteLength!==5)throw new j("Invalid LZMA properties: expected 5 bytes");let t=e[0];if(t>=225)throw new j("Invalid LZMA properties");let s=t%9;t=Math.floor(t/9);let n=t%5,o=Math.floor(t/5),r=(e[1]|e[2]<<8|e[3]<<16|e[4]<<24)>>>0;return{lc:s,lp:n,pb:o,dictionarySize:Math.max(r,4096)}}class zPe{#e;#t;#s=0;#n=0;#o=0;#r=0;#a=0;#i=0;#l=0;#u=1;#p=1;#c=1;#d=1;#m=Ym(xht);#f=Ym(u6*$Pe);#h=Ym(u6);#T=Ym(u6);#g=Ym(u6);#y=Ym(u6);#R=Ym(u6*$Pe);#C=Ym(256);#k=Ym(115);#S=Ym(16);#b=new Mht;#x=new Mht;constructor(e,t){this.#e=e,this.#t=t.dictionarySize,this.setProperties(t.lc,t.lp,t.pb),this.resetDictionary()}get outputPos(){return this.#s}setProperties(e,t,s){if(e>8||t>4||s>4||e+t>12)throw new j("Invalid LZMA properties");this.#r=e,this.#a=t,this.#i=s;let n=xht*2**(e+t);if(this.#m.length!==n)this.#m=Ym(n)}resetDictionary(){this.#n=this.#s,this.#o=0,this.resetState()}resetState(){this.#l=0,this.#u=this.#p=this.#c=this.#d=1,this.#m.fill(zf>>>1),this.#f.fill(zf>>>1),this.#h.fill(zf>>>1),this.#T.fill(zf>>>1),this.#g.fill(zf>>>1),this.#y.fill(zf>>>1),this.#R.fill(zf>>>1),this.#C.fill(zf>>>1),this.#k.fill(zf>>>1),this.#S.fill(zf>>>1),this.#b.reset(),this.#x.reset()}appendUncompressed(e,t){if(t)this.resetDictionary();if(e.byteLength>this.#e.byteLength-this.#s)throw new j("LZMA2 output exceeds its limit");this.#e.set(e,this.#s),this.#s+=e.byteLength,this.#o+=e.byteLength}decodeChunk(e,t,s=!1){if(!Number.isSafeInteger(t)||t<0||t>this.#e.byteLength-this.#s)throw new j("LZMA output exceeds its declared size");let n=this.#s+t,o=new Zjs(e),r=(1<<this.#i)-1,i=(1<<this.#a)-1;while(this.#s<n||s){let a=this.#o&r;if(o.decodeBit(this.#f,(this.#l<<4)+a)===0){let u=this.#s===this.#n?0:this.#e[this.#s-1],p=(((this.#o&i)<<this.#r)+(u>>>8-this.#r))*xht,c=1;if(this.#l>=7){this.#E(this.#u);let d=this.#e[this.#s-this.#u];while(c<256){let f=d>>>7&1;d=d<<1&255;let m=o.decodeBit(this.#m,p+(1+f<<8)+c);if(c=c<<1|m,f!==m)break}}while(c<256)c=c<<1|o.decodeBit(this.#m,p+c);if(this.#s>=n)throw new j("LZMA output exceeds its size limit before the end marker");this.#e[this.#s++]=c&255,this.#o++,this.#l=this.#l<4?0:this.#l<10?this.#l-3:this.#l-6;continue}let l;if(o.decodeBit(this.#h,this.#l)===1){if(o.decodeBit(this.#T,this.#l)===0){if(o.decodeBit(this.#R,(this.#l<<4)+a)===0){this.#l=this.#l<7?9:11,this.#w(this.#u,1,n);continue}}else{let u;if(o.decodeBit(this.#g,this.#l)===0)u=this.#p;else{if(o.decodeBit(this.#y,this.#l)===0)u=this.#c;else u=this.#d,this.#d=this.#c;this.#c=this.#p}this.#p=this.#u,this.#u=u}l=this.#x.decode(o,a)+Eht,this.#l=this.#l<7?8:11}else{this.#d=this.#c,this.#c=this.#p,this.#p=this.#u,l=this.#b.decode(o,a)+Eht,this.#l=this.#l<7?7:10;let u=Math.min(l-Eht,3),p=jPe(o,this.#C,u<<6,6),c;if(p<4)c=p;else{let d=(p>>>1)-1;if(c=(2|p&1)<<d>>>0,p<14)c=c+Qjs(o,this.#k,c-p,d)>>>0;else if(c=c+(o.decodeDirectBits(d-4)<<4)>>>0,c=c+Qjs(o,this.#S,0,4)>>>0,c===4294967295){if(s)return!0;throw new j("LZMA stream ended before its declared output size")}}this.#u=c+1>>>0}this.#w(this.#u,l,n)}return!1}#E(e){let t=this.#s-this.#n;if(e<1||e>t||e>this.#t)throw new j(`Invalid LZMA match distance ${e} with ${t} bytes available`)}#w(e,t,s){if(this.#E(e),t>s-this.#s)throw new j("LZMA match exceeds its declared output size");for(let n=0;n<t;n++)this.#e[this.#s]=this.#e[this.#s-e],this.#s++;this.#o+=t}}async function nae(e,t,s){if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid LZMA output size");try{let n=new Uint8Array(s),o=new zPe(n,e$s(e));if(o.decodeChunk(t,s),o.outputPos!==s)throw new j("LZMA output size mismatch");return n}catch(n){if(n instanceof j)throw n;throw new j(`Invalid LZMA stream: ${n instanceof Error?n.message:String(n)}`)}}async function p6(e,t){if(e.byteLength<13)throw new j("Invalid LZMA-alone stream: truncated header");if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid LZMA output limit");let s=e.subarray(0,5),n=!0,o=0;for(let r=0;r<8;r++){let i=e[5+r];if(i!==255)n=!1;o+=i*2**(r*8)}if(!n){if(!Number.isSafeInteger(o)||o>t)throw new j("LZMA-alone output exceeds its size limit");return nae(s,e.subarray(13),o)}try{let r=new Uint8Array(t),i=new zPe(r,e$s(s));if(!i.decodeChunk(e.subarray(13),t,!0))throw new j("LZMA-alone output exceeds its size limit before the end marker");return r.subarray(0,i.outputPos)}catch(r){if(r instanceof j)throw r;throw new j(`Invalid LZMA-alone stream: ${r instanceof Error?r.message:String(r)}`)}}async function KPe(e,t,s){if(!Number.isInteger(e)||e<0||e>40)throw new j("Unsupported LZMA2 dictionary property");if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid LZMA2 output limit");let n=e===40?4294967295:(2|e&1)*2**(Math.floor(e/2)+11),o=new Uint8Array(s),r=new zPe(o,{lc:3,lp:0,pb:2,dictionarySize:n}),i=0,a=!0,l=!1,u=()=>{if(i>=t.byteLength)throw new j("Invalid LZMA2 stream: truncated chunk header");return t[i++]};try{for(;;){let p=u();if(p===0)break;if(p<128){if(p!==1&&p!==2)throw new j(`Invalid LZMA2 control byte 0x${p.toString(16)}`);if(p===2&&a)throw new j("Invalid LZMA2 stream: dictionary was not initialized");let h=(u()<<8)+u()+1;if(h>s-r.outputPos||h>t.byteLength-i)throw new j("Invalid LZMA2 uncompressed chunk size");if(r.appendUncompressed(t.subarray(i,i+h),p===1),i+=h,p===1)a=!1,l=!1;continue}let c=((p&31)<<16)+(u()<<8)+u()+1,d=(u()<<8)+u()+1,f=p>=224,m=p>=160,g=p>=192;if(a&&!f)throw new j("Invalid LZMA2 stream: dictionary was not initialized");if(!l&&!g)throw new j("Invalid LZMA2 stream: properties were not initialized");if(g){let h=u();if(h>=225)throw new j("Invalid LZMA2 properties");let T=h%9;h=Math.floor(h/9);let y=h%5,R=Math.floor(h/5);if(T+y>4)throw new j("Invalid LZMA2 literal properties");r.setProperties(T,y,R),l=!0}if(d>t.byteLength-i||c>s-r.outputPos)throw new j("Invalid LZMA2 chunk size");if(f)r.resetDictionary();else if(m)r.resetState();r.decodeChunk(t.subarray(i,i+d),c),i+=d,a=!1}if(i!==t.byteLength)throw new j("Invalid LZMA2 stream: trailing data");return o.subarray(0,r.outputPos)}catch(p){if(p instanceof j)throw p;throw new j(`Invalid LZMA2 stream: ${p instanceof Error?p.message:String(p)}`)}}var _Wr=16777216,zf=2048,Xjs=5,xht=768,u6=12,$Pe=16,Eht=2;var TW=S(()=>{Ur()});class s$s{#e;#t=0;#s=0;constructor(e){this.#e=e}get remainingBits(){return this.#e.byteLength*8-this.#t}read(e){if(this.remainingBits<e)return;let t=0;for(let s=0;s<e;s++){let n=this.#t+s;t+=(this.#e[n>>>3]>>>(n&7)&1)*2**s}return this.#t+=e,t}alignCodeGroup(e){let t=e*8,s=this.#s+Math.ceil((this.#t-this.#s)/t)*t;if(s>this.#e.byteLength*8)throw new j("Truncated compress (.Z) code group");this.#t=s,this.#s=s}assertFinalPadding(){this.#n(this.#e.byteLength*8)}#n(e){for(let t=this.#t;t<e;t++)if((this.#e[t>>>3]>>>(t&7)&1)!==0)throw new j("Invalid non-zero compress (.Z) padding")}}class n$s{#e;#t;#s=0;constructor(e,t){this.#e=e,this.#t=new Uint8Array(Math.min(e,Math.max(64,Math.min(t*2,65536))))}appendReversed(e,t){this.#n(t);for(let s=t-1;s>=0;s--)this.#t[this.#s++]=e[s]}finish(){return this.#t.slice(0,this.#s)}#n(e){let t=this.#s+e;if(!Number.isSafeInteger(t)||t>this.#e)throw new j(`Compress (.Z) output exceeds the ${this.#e}-byte limit`);if(t<=this.#t.byteLength)return;let s=Math.max(t,Math.min(this.#e,Math.max(64,this.#t.byteLength*2)));if(s>this.#e)s=this.#e;let n=new Uint8Array(s);n.set(this.#t.subarray(0,this.#s)),this.#t=n}}function NWr(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid compress (.Z) output limit");if(e.byteLength<3)throw new j("Truncated compress (.Z) header");if(e[0]!==31||e[1]!==157)throw new j("Invalid compress (.Z) header");let s=e[2];if((s&96)!==0)throw new j("Unsupported compress (.Z) header flags");let n=s&31;if(n<Aht||n>DWr)throw new j(`Invalid compress (.Z) maximum code width ${n}`);let o=(s&128)!==0,r=2**n,i=new Uint16Array(r),a=new Uint8Array(r),l=new Uint8Array(r),u=new s$s(e.subarray(3)),p=new n$s(t,e.byteLength),c=Aht,d=o?t$s:256,f=!1;for(;;){let m=u.read(c);if(m===void 0)return u.assertFinalPadding(),p.finish();if(m>=d)throw new j(`Corrupt compress (.Z) dictionary code ${m}`);if(o&&m===LWr){u.alignCodeGroup(c),c=Aht,d=t$s,f=!1;continue}let g=m,h=0;while(g>=256){if(g>=d||h>=l.length-1)throw new j("Corrupt compress (.Z) dictionary chain");l[h++]=a[g],g=i[g]}if(l[h++]=g,f){if(a[d-1]=g,m===d-1)l[0]=g}if(p.appendReversed(l,h),d<r){if(f=!0,i[d++]=m,d>2**c&&c<n)u.alignCodeGroup(c),c++}else f=!1}}function o$s(e){return e.byteLength>=2&&e[0]===31&&e[1]===157}async function vht(e,t){try{return NWr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}}var LWr=256,t$s=257,Aht=9,DWr=16;var r$s=S(()=>{Ur()});function SS(e,t){if(t<0||t+4>e.byteLength)throw new j("Invalid XZ stream: truncated integer");return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function YPe(e,t,s){e[t]=s&255,e[t+1]=s>>>8&255,e[t+2]=s>>>16&255,e[t+3]=s>>>24}function i$s(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function qWr(e,t,s){e[t]=s>>>24,e[t+1]=s>>>16&255,e[t+2]=s>>>8&255,e[t+3]=s&255}function Iht(e,t){if(e.byteLength!==t.byteLength)return!1;for(let s=0;s<e.byteLength;s++)if(e[s]!==t[s])return!1;return!0}function yW(e){let t=0;for(let s=0;s<9;s++){if(e.pos>=e.limit)throw new j("Invalid XZ stream: truncated variable-length integer");let n=e.bytes[e.pos++];if(s>0&&n===0)throw new j("Invalid XZ stream: non-canonical variable-length integer");if(t+=(n&127)*2**(s*7),!Number.isSafeInteger(t))throw new j("XZ stream uses sizes too large to read safely");if((n&128)===0)return t}throw new j("Invalid XZ stream: variable-length integer is too long")}function a$s(e){switch(e){case 0:return 0;case 1:return 4;case 4:return 8;case 10:return 32;default:throw new j(`Unsupported XZ integrity check ID 0x${e.toString(16)}`)}}function UWr(e,t,s){if(s<8||t<0||t+s>e.byteLength)throw new j("Invalid XZ stream: index range is invalid");let n=t+s;if(e[t]!==0)throw new j("Invalid XZ stream: missing index indicator");if(Wi(e.subarray(t,n-4))!==SS(e,n-4))throw new j("Invalid XZ stream: index CRC32 mismatch");let o={bytes:e,pos:t+1,limit:n-4},r=yW(o);if(r>Math.floor(s/2))throw new j("Invalid XZ stream: impossible index record count");let i=[];for(let a=0;a<r;a++){let l=yW(o),u=yW(o);if(l===0)throw new j("Invalid XZ stream: zero unpadded block size");i.push({unpaddedSize:l,uncompressedSize:u})}while(o.pos<o.limit)if(e[o.pos++]!==0)throw new j("Invalid XZ stream: non-zero index padding");return i}function HWr(e){if(e.byteLength===0||(e.byteLength&3)!==0)throw new j("Invalid XZ stream: size is not a multiple of four bytes");let t=[],s=e.byteLength;while(s>0){let n=0;while(s>=4&&e[s-1]===0&&e[s-2]===0&&e[s-3]===0&&e[s-4]===0)s-=4,n+=4;if(s===0)throw new j("Invalid XZ stream: padding without a stream");if(s<24)throw new j("Invalid XZ stream: truncated stream framing");let o=s-12;if(e[o+10]!==89||e[o+11]!==90)throw new j("Invalid XZ stream: footer magic mismatch");if(Wi(e.subarray(o+4,o+10))!==SS(e,o))throw new j("Invalid XZ stream: footer CRC32 mismatch");let r=e[o+8],i=e[o+9];if(r!==0||(i&240)!==0)throw new j("Unsupported XZ stream flags");let a=i&15;a$s(a);let l=(SS(e,o+4)+1)*4;if(!Number.isSafeInteger(l)||l>o)throw new j("Invalid XZ stream: backward index size is invalid");let u=o-l,p=UWr(e,u,l),c=0;for(let f of p)if(c+=Math.ceil(f.unpaddedSize/4)*4,!Number.isSafeInteger(c))throw new j("XZ stream uses sizes too large to read safely");let d=u-c-12;if(d<0||d+12>e.byteLength||!Iht(e.subarray(d,d+6),VPe))throw new j("Invalid XZ stream: header position or magic is invalid");if(e[d+6]!==r||e[d+7]!==i)throw new j("Invalid XZ stream: header and footer flags differ");if(Wi(e.subarray(d+6,d+8))!==SS(e,d+8))throw new j("Invalid XZ stream: header CRC32 mismatch");t.unshift({start:d,indexStart:u,footerStart:o,checkId:a,records:p}),s=d}return t}function BWr(e,t){let s=new Uint8Array(256),n=0;for(let o=0;o<e.byteLength;o++){let r=e[o]+s[t+n&255]&255;s[n]=r,e[o]=r,n=n-1&255}}function WWr(e,t){let s=[0,1,2,2,3],n=0,o=4294967291;if(e.byteLength<5)return;let r=0,i=e.byteLength-5;while(r<=i){let a=e[r];if(a!==232&&a!==233){r++;continue}let l=t+r>>>0,u=l-o>>>0;if(o=l,u>5)n=0;else for(let p=0;p<u;p++)n=(n&119)<<1>>>0;if(a=e[r+4],(a===0||a===255)&&n>>>1<=4&&n>>>1!==3){let p=SS(e,r+1),c=0;for(;;){if(c=p-l-5>>>0,n===0)break;let d=s[n>>>1]*8,f=c>>>24-d&255;if(f!==0&&f!==255)break;let m=d===0?4294967295:2**(32-d)-1;p=(c^m)>>>0}e[r+4]=~((c>>>24&1)-1)&255,e[r+3]=c>>>16,e[r+2]=c>>>8,e[r+1]=c,r+=5,n=0}else if(r++,n|=1,a===0||a===255)n|=16}}function GWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(e[s]>>>2!==18||(e[s+3]&3)!==1)continue;let o=(((e[s]&3)<<24|e[s+1]<<16|e[s+2]<<8|e[s+3]&252)>>>0)-t-s>>>0;e[s]=72|o>>>24&3,e[s+1]=o>>>16,e[s+2]=o>>>8,e[s+3]=e[s+3]&3|o&252}}function jWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(e[s+3]!==235)continue;let o=((e[s+2]<<18|e[s+1]<<10|e[s]<<2)>>>0)-t-s-8>>>2;e[s]=o,e[s+1]=o>>>8,e[s+2]=o>>>16}}function $Wr(e,t){for(let s=0;s+4<=e.byteLength;s+=2){if((e[s+1]&248)!==240||(e[s+3]&248)!==248)continue;let o=(((e[s+1]&7)<<19|e[s]<<11|(e[s+3]&7)<<8|e[s+2])<<1>>>0)-t-s-4>>>1;e[s+1]=240|o>>>19&7,e[s]=o>>>11,e[s+3]=248|o>>>8&7,e[s+2]=o,s+=2}}function zWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){if(!(e[s]===64&&(e[s+1]&192)===0||e[s]===127&&(e[s+1]&192)===192))continue;let o=(i$s(e,s)<<2>>>0)-t-s>>>2;o=0-(o>>>22&1)<<22&1073741823|o&4194303|1073741824,qWr(e,s,o>>>0)}}function KWr(e,t){let s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,6,6,0,0,7,7,4,4,0,0,4,4,0,0];for(let n=0;n+16<=e.byteLength;n+=16){let o=s[e[n]&31],r=5;for(let i=0;i<3;i++,r+=41){if((o>>>i&1)===0)continue;let a=r>>>3,l=r&7,u=0n;for(let f=0;f<6;f++)u|=BigInt(e[n+a+f])<<BigInt(f*8);let p=u>>BigInt(l);if((p>>37n&15n)!==5n||(p>>9n&7n)!==0n)continue;let c=Number(p>>13n&0xfffffn)|Number(p>>36n&1n)<<20;c=c<<4>>>0;let d=c-t-n>>>4>>>0;p&=~(0x8fffffn<<13n),p|=BigInt(d&1048575)<<13n,p|=BigInt(d&1048576)<<16n,u&=(1n<<BigInt(l))-1n,u|=p<<BigInt(l);for(let f=0;f<6;f++)e[n+a+f]=Number(u>>BigInt(f*8))&255}}}function VWr(e,t){for(let s=0;s+4<=e.byteLength;s+=4){let n=t+s>>>0,o=SS(e,s);if(o>>>26===37)o=(2483027968|o-(n>>>2)&67108863)>>>0,YPe(e,s,o);else if((o&2667577344)===2415919104){let r=o>>>29&3|o>>>3&2097148;if((r+131072&1835008)!==0)continue;let i=r-(n>>>12)>>>0;o&=2415919135,o|=(i&3)<<29,o|=(i&262140)<<3,o|=0-(i&131072)&14680064,YPe(e,s,o>>>0)}}}function YWr(e,t){if(e.byteLength<8)return;for(let s=0;s<=e.byteLength-8;s+=2){let n=e[s];if(n===239){let r=e[s+1];if((r&13)!==0)continue;let i=((r&240)<<13|e[s+2]<<9|e[s+3]<<1)-t-s>>>0;e[s+1]=r&15|i>>>8&240,e[s+2]=i>>>16&15|i>>>7&16|i<<4&224,e[s+3]=i>>>4&127|i>>>13&128,s+=2;continue}if((n&127)!==23)continue;n=SS(e,s);let o;if((n&3712)!==0){if(o=SS(e,s+4),(n<<8^o-3&1015811)!==0){s+=4;continue}let r=(n&4294963200)+(o>>>20);n=(279|o<<12)>>>0,o=r>>>0}else{let r=n>>>27;if(n-12567<<18>>>0>=(r&29)){s+=2;continue}let i=i$s(e,s+4)-t-s>>>0;o=(n>>>12|i<<20)>>>0,n=(23|r<<7|i+2048&4294963200)>>>0}YPe(e,s,n),YPe(e,s+4,o),s+=6}}function JWr(e,t){if(t.id===3){if(t.properties.byteLength!==1)throw new j("Invalid XZ Delta filter properties");BWr(e,t.properties[0]+1);return}if(t.properties.byteLength!==0&&t.properties.byteLength!==4)throw new j(`Invalid XZ BCJ filter 0x${t.id.toString(16)} properties`);let s=t.properties.byteLength===4?SS(t.properties,0):0,n=t.id===6?16:t.id===8||t.id===11?2:t.id===4?1:4;if((s&n-1)!==0)throw new j(`Invalid XZ BCJ filter 0x${t.id.toString(16)} start offset`);switch(t.id){case 4:WWr(e,s);break;case 5:GWr(e,s);break;case 6:KWr(e,s);break;case 7:jWr(e,s);break;case 8:$Wr(e,s);break;case 9:zWr(e,s);break;case 10:VWr(e,s);break;case 11:YWr(e,s);break;default:throw new j(`Unsupported XZ filter ID 0x${t.id.toString(16)}`)}}function XWr(e,t,s){if(e===0)return;if(e===1){if(SS(s,0)!==Wi(t))throw new j("Invalid XZ stream: block CRC32 mismatch");return}if(e===4){let o=njs(t),r=0n;for(let i=0;i<8;i++)r|=BigInt(s[i])<<BigInt(i*8);if(o!==r)throw new j("Invalid XZ stream: block CRC64 mismatch");return}let n=new Uint8Array(new Bun.CryptoHasher("sha256").update(t).digest());if(!Iht(n,s))throw new j("Invalid XZ stream: block SHA-256 mismatch")}async function QWr(e,t,s,n){if(t>=e.byteLength||e[t]===0)throw new j("Invalid XZ stream: missing block header");let o=(e[t]+1)*4;if(t+o>e.byteLength||o<8)throw new j("Invalid XZ stream: truncated block header");if(Wi(e.subarray(t,t+o-4))!==SS(e,t+o-4))throw new j("Invalid XZ stream: block header CRC32 mismatch");let r={bytes:e,pos:t+1,limit:t+o-4},i=e[r.pos++];if((i&60)!==0)throw new j("Unsupported XZ block flags");let a=(i&3)+1,l=(i&64)!==0?yW(r):void 0,u=(i&128)!==0?yW(r):void 0,p=[];for(let C=0;C<a;C++){let b=yW(r),w=yW(r);if(w>r.limit-r.pos)throw new j("Invalid XZ stream: truncated filter properties");p.push({id:b,properties:e.slice(r.pos,r.pos+w)}),r.pos+=w}while(r.pos<r.limit)if(e[r.pos++]!==0)throw new j("Invalid XZ stream: non-zero block header padding");let c=a$s(n),d=s.unpaddedSize-o-c;if(!Number.isSafeInteger(d)||d<=0)throw new j("Invalid XZ stream: compressed block size is invalid");if(l!==void 0&&l!==d)throw new j("Invalid XZ stream: block compressed size mismatch");if(u!==void 0&&u!==s.uncompressedSize)throw new j("Invalid XZ stream: block uncompressed size mismatch");let f=t+o,m=f+d,g=4-(o+d&3)&3,h=m+g;if(h+c>e.byteLength)throw new j("Invalid XZ stream: truncated block data");let T=p[p.length-1];if(T.id!==33||T.properties.byteLength!==1)throw new j(`Unsupported XZ terminal filter ID 0x${T.id.toString(16)} (LZMA2 required)`);let y=await KPe(T.properties[0],e.subarray(f,m),s.uncompressedSize);if(y.byteLength!==s.uncompressedSize)throw new j("Invalid XZ stream: decoded block size mismatch");y=y.slice();for(let C=p.length-2;C>=0;C--)JWr(y,p[C]);for(let C=m;C<h;C++)if(e[C]!==0)throw new j("Invalid XZ stream: non-zero block padding");XWr(n,y,e.subarray(h,h+c));let R=t+Math.ceil(s.unpaddedSize/4)*4;if(h+c!==R)throw new j("Invalid XZ stream: block size does not match its index record");return y}function JPe(e){return e.byteLength>=VPe.byteLength&&Iht(e.subarray(0,VPe.byteLength),VPe)}async function y0(e,t){if(!Number.isSafeInteger(t)||t<0)throw new j("Invalid XZ output limit");try{let s=HWr(e),n=0;for(let i of s)for(let a of i.records)if(n+=a.uncompressedSize,!Number.isSafeInteger(n)||n>t)throw new j("XZ output exceeds its size limit");let o=new Uint8Array(n),r=0;for(let i of s){let a=i.start+12;for(let l of i.records){let u=await QWr(e,a,l,i.checkId);o.set(u,r),r+=u.byteLength,a+=Math.ceil(l.unpaddedSize/4)*4}if(a!==i.indexStart)throw new j("Invalid XZ stream: blocks do not align with index")}return o}catch(s){if(s instanceof j)throw s;throw new j(`Invalid XZ stream: ${s instanceof Error?s.message:String(s)}`)}}var VPe;var oae=S(()=>{m0();Ur();TW();VPe=Uint8Array.of(253,55,122,88,90,0)});import{promisify as l$s}from"util";import*as XPe from"zlib";function QPe(e){return e.byteLength>=4&&e[0]===40&&e[1]===181&&e[2]===47&&e[3]===253}async function R0(e,t){try{return await e2r(e,{maxOutputLength:Math.max(t,1)})}catch(s){throw new j(s instanceof Error?s.message:String(s))}}function u$s(e){return ZWr(e)}var ZWr,e2r;var c6=S(()=>{Ur();ZWr=l$s(XPe.zstdCompress),e2r=l$s(XPe.zstdDecompress)});import*as eFe from"path";class Fht{#e;#t;#s;#n;constructor(e,t,s,n){this.#e=e,this.#t=t,this.#s=s,this.#n=n}async read(e,t){if(e!==this.#s)throw new j(`CPIO member '${t}' has an inconsistent declared size`);let s=this.#t+this.#s;if(s>this.#e.byteLength)throw new j(`CPIO member '${t}' is truncated`);let n=this.#e.subarray(this.#t,s);if(this.#n!==void 0&&h$s(n)!==this.#n)throw new j(`CPIO member '${t}' has an invalid CRC checksum`);return n}}function h$s(e){let t=0;for(let s of e)t=t+s>>>0;return t}function g$s(e,t){let s=e%t;return s===0?e:e+t-s}function C0(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.byteLength)throw new j(`Invalid CPIO archive: truncated ${n}`)}function ZPe(e,t,s,n,o){C0(e,t,t+s,`${o} field`);let r=0;for(let i=t;i<t+s;i++){let a=e[i],l;if(a>=48&&a<=57)l=a-48;else if(n===16&&a>=65&&a<=70)l=a-65+10;else if(n===16&&a>=97&&a<=102)l=a-97+10;else throw new j(`Invalid CPIO archive: ${o} is not a valid base-${n} number`);if(l>=n)throw new j(`Invalid CPIO archive: ${o} is not a valid base-${n} number`);r=r*n+l}if(!Number.isSafeInteger(r))throw new j(`Invalid CPIO archive: ${o} is too large`);return r}function T$s(e,t){C0(e,t,t+2,"header");let s=e[t],n=e[t+1];if(s===199&&n===113||s===113&&n===199){C0(e,t,t+d$s,"old binary header");let i=s===199?xn:Kie,a=(l)=>i(e,t+l)*65536+i(e,t+l+2);return{headerSize:d$s,alignment:2,devMajor:0,devMinor:i(e,t+2),inode:i(e,t+4),mode:i(e,t+6),nlink:i(e,t+12),mtime:a(16),nameSize:i(e,t+20),fileSize:a(22)}}C0(e,t,t+6,"magic");let o=String.fromCharCode(...e.subarray(t,t+6));if(o==="070701"||o==="070702"){C0(e,t,t+p$s,"new ASCII header");let r=(a,l)=>ZPe(e,t+6+a*8,8,16,l),i=r(12,"checksum");if(o==="070701"&&i!==0)throw new j("Invalid CPIO archive: newc checksum field must be zero");return{headerSize:p$s,alignment:4,inode:r(0,"inode"),mode:r(1,"mode"),nlink:r(4,"link count"),mtime:r(5,"modification time"),fileSize:r(6,"file size"),devMajor:r(7,"device major"),devMinor:r(8,"device minor"),nameSize:r(11,"name size"),checksum:o==="070702"?i:void 0}}if(o==="070707"){C0(e,t,t+c$s,"portable ASCII header");let r=(i,a)=>ZPe(e,t+i,6,8,a);return{headerSize:c$s,alignment:1,devMajor:0,devMinor:r(6,"device"),inode:r(12,"inode"),mode:r(18,"mode"),nlink:r(36,"link count"),mtime:ZPe(e,t+48,11,8,"modification time"),nameSize:r(59,"name size"),fileSize:ZPe(e,t+65,11,8,"file size")}}throw new j(`Invalid CPIO archive: unsupported or corrupt magic at offset ${t}`)}function y$s(e){try{return n2r.decode(e)}catch{return}}function Pht(e,t,s,n){for(let o=t;o<s;o++)if(e[o]!==0)throw new j(`Invalid CPIO archive: non-zero ${n} padding`)}function o2r(e,t,s){ko(t.byteLength,"link target",s);let n=y$s(t);if(n===void 0||n.includes("\x00"))throw new j(`Invalid CPIO archive: symlink '${e}' has an invalid UTF-8 target`);let o=n.replace(/\\/g,"/");if(eFe.posix.isAbsolute(o))return{path:o,resolveTarget:!1};let r=zd(eFe.posix.join(eFe.posix.dirname(e),o));return r===void 0?{path:o,resolveTarget:!1}:{path:r,resolveTarget:!0}}function _ht(e,t){ci(e.byteLength,t.limits);let s=[],n=0,o=0,r=!1;while(n<e.byteLength){let u=T$s(e,n);if(u.mode>65535)throw new j("Invalid CPIO archive: mode exceeds 16 bits");if(u.nameSize<1)throw new j("Invalid CPIO archive: name size must include a NUL terminator");ko(u.nameSize-1,"member path",t.limits.maxPathBytes),Qi(u.fileSize,"(CPIO entry)",t.limits);let p=n+u.headerSize,c=p+u.nameSize,d=g$s(c,u.alignment),f=d+u.fileSize,m=g$s(f,u.alignment);if(C0(e,p,c,"member name"),C0(e,d,f,"member data"),C0(e,f,m,"member padding"),e[c-1]!==0)throw new j("Invalid CPIO archive: member name is not NUL-terminated");for(let y=p;y<c-1;y++)if(e[y]===0)throw new j("Invalid CPIO archive: member name contains an embedded NUL");Pht(e,c,d,"name"),Pht(e,f,m,"data"),o+=d-n,Hn(o,t.limits,"CPIO index");let g=y$s(e.subarray(p,c-1));if(g===t2r){if(u.fileSize!==0)throw new j("Invalid CPIO archive: TRAILER!!! has non-empty data");r=!0,n=m;break}let h=u.mode&Oht;if((h===m$s||h===4096)&&u.fileSize!==0)throw new j("Invalid CPIO archive: directory or FIFO has non-empty data");or(s.length+1,t.limits);let T=g===void 0?void 0:Sr(g);s.push({path:T,mode:u.mode,mtimeMs:u.mtime*1000,nlink:u.nlink,inode:u.inode,devMajor:u.devMajor,devMinor:u.devMinor,fileSize:u.fileSize,dataOffset:d,checksum:u.checksum}),n=m}if(!r)throw new j("Invalid CPIO archive: missing TRAILER!!! terminator");Pht(e,n,e.byteLength,"trailing");let i=new Map,a=new Set,l=new Map;for(let u of s){if((u.mode&Oht)!==f$s||u.nlink<=1)continue;let p=`${u.devMajor}:${u.devMinor}:${u.inode}`,c=l.get(p);if(c)c.push(u);else l.set(p,[u])}for(let u of l.values()){if(u.length<2)continue;for(let f of u)a.add(f);let p=u.filter((f)=>f.path!==void 0);if(p.length===0)continue;let c=u.find((f)=>f.fileSize!==0)??u[0],d=p.find((f)=>f===c)??p[0];for(let f of p){let m={path:f.path,isDirectory:!1,size:c.fileSize,mtimeMs:f.mtimeMs,mode:f.mode,storage:f===d?{type:"member",source:new Fht(e,c.dataOffset,c.fileSize,c.checksum)}:{type:"link",targetPath:d.path,resolveTarget:!1}};yc(i,m)}}for(let u of s){if(a.has(u)||u.path===void 0)continue;let p=u.mode&Oht;if(p===m$s){yc(i,{path:u.path,isDirectory:!0,size:0,mtimeMs:u.mtimeMs,mode:u.mode});continue}if(p===s2r){let c=e.subarray(u.dataOffset,u.dataOffset+u.fileSize);if(u.checksum!==void 0&&h$s(c)!==u.checksum)throw new j(`CPIO symlink '${u.path}' has an invalid CRC checksum`);let d=o2r(u.path,c,t.limits.maxPathBytes);yc(i,{path:u.path,isDirectory:!1,size:0,mtimeMs:u.mtimeMs,mode:u.mode,storage:{type:"link",targetPath:d.path,resolveTarget:d.resolveTarget}});continue}if(p!==f$s)continue;yc(i,{path:u.path,isDirectory:!1,size:u.fileSize,mtimeMs:u.mtimeMs,mode:u.mode,storage:{type:"member",source:new Fht(e,u.dataOffset,u.fileSize,u.checksum)}})}return lD(i,t.limits),[...i.values()]}function rae(e){try{let t=T$s(e,0);if(t.mode>65535||t.nameSize<1)return!1;let s=t.headerSize+t.nameSize;return s<=e.byteLength&&e[s-1]===0}catch{return!1}}var p$s=110,c$s=76,d$s=26,t2r="TRAILER!!!",Oht=61440,f$s=32768,m$s=16384,s2r=40960,n2r,R$s=async(e,t)=>{try{return ci(e.size,t.limits),_ht(await eM(e),t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}};var Lht=S(()=>{Sh();uD();Ur();vp();Vd();tM();n2r=new TextDecoder("utf-8",{fatal:!0})});import*as aae from"path";class q$s{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){if(this.#s)throw new j(`Archive member '${dr(t)}' is a sparse file and cannot be read`);if(e>this.#e.byteLength-this.#t)throw new j(`Archive member '${dr(t)}' is truncated`);let s=this.#e.subarray(this.#t,this.#t+e);if(s.byteLength!==e)throw new j(`Archive member '${dr(t)}' has an invalid size`);return s}}function sFe(e,t,s){let n=Math.min(t+s,e.byteLength),o=t;while(o<n&&e[o]!==0)o++;return uae.decode(e.subarray(t,o))}function RW(e,t){return e.byteLength===t.length&&Ap(e,0,t)}function p2r(e,t){return Ap(e,t+L$s,qht)&&Ap(e,t+D$s,Uht)}function nFe(e,t,s){let n=e.indexOf(0),o=e.subarray(0,n===-1?e.byteLength:n);return ko(o.byteLength,t,s.maxPathBytes),uae.decode(o)}function k$s(e,t,s){return ko(e.byteLength,t,s.maxPathBytes),uae.decode(e)}function oFe(e,t,s){if(t<0||s<=0||t+s>e.byteLength)throw new j("Invalid tar numeric field");let n=e[t],o=0n;if((n&128)!==0){o=BigInt(n&127);for(let r=1;r<s;r++)o=o<<8n|BigInt(e[t+r]);if((n&64)!==0)o-=1n<<BigInt(s*8-1)}else for(let r=0;r<s;r++){let i=e[t+r];if(i>=48&&i<=55)o=o*8n+BigInt(i-48)}return Number(o)}function U$s(e,t){let s=oFe(e,t,O$s);if(!Number.isSafeInteger(s)||s<0)throw new j("Invalid tar member size");return s}function rFe(e){let t=e%wS,s=e+(t===0?0:wS-t);if(!Number.isSafeInteger(s))throw new j("Invalid tar member size");return s}function S$s(e,t){if(!/^\d+$/.test(e))throw new j(`Invalid tar ${t}`);let s=Number(e);if(!Number.isSafeInteger(s)||s<0)throw new j(`Invalid tar ${t}`);return s}function H$s(e,t){for(let s=0;s<wS;s++)if(e[t+s]!==0)return!1;return!0}function B$s(e,t){let s=oFe(e,t+pD,Nht),n=0,o=0;for(let r=0;r<wS;r++){let a=r>=pD&&r<pD+Nht?32:e[t+r]??0;n+=a,o+=a<<24>>24}return s===n||s===o}function w$s(e,t){Hn(e.byteLength,t,"tar PAX metadata");let s=new Map,n=0;while(n<e.byteLength){let o=n;while(o<e.byteLength&&e[o]!==32)o++;if(o===n||o>=e.byteLength||o-n>16)throw new j("Invalid tar PAX record");let r=0;for(let l=n;l<o;l++){let u=e[l];if(u<48||u>57)throw new j("Invalid tar PAX record");if(r=r*10+(u-48),r>e.byteLength-n)throw new j("Invalid tar PAX record")}if(r<=0||n+r>e.byteLength||e[n+r-1]!==10)throw new j("Invalid tar PAX record");let i=e.subarray(o+1,n+r-1),a=i.indexOf(61);if(a>=0){let l=i.subarray(0,a),u=i.subarray(a+1);if(Ap(l,0,Hht)){if(s.set(Hht,u.byteLength===0?"":"1"),RW(l,"GNU.sparse.name"))s.set("GNU.sparse.name",k$s(u,"PAX sparse path",t));else if(RW(l,"GNU.sparse.realsize")||RW(l,"GNU.sparse.size")){if(u.byteLength>C$s)throw new j("Invalid tar sparse real size");s.set("GNU.sparse.realsize",uae.decode(u))}}else if(RW(l,"path")||RW(l,"linkpath")){let p=RW(l,"path")?"PAX path":"PAX link target";s.set(p==="PAX path"?"path":"linkpath",k$s(u,p,t))}else if(RW(l,"size")){if(u.byteLength>C$s)throw new j("Invalid tar member size");s.set("size",uae.decode(u))}}n+=r}return s}function c2r(e,t){for(let[s,n]of t)if(n==="")e.delete(s);else e.set(s,n)}function d6(e,t,s){if(t?.has(s))return t.get(s);return e.get(s)}function d2r(e,t){return d6(e,t,Hht)==="1"}function f2r(e,t,s){for(let n=s;n<=e.byteLength-t.length;n++)if(Ap(e,n,t))return n;return-1}function x$s(e,t,s){let n=e.replace(/\\/g,"/");if(aae.posix.isAbsolute(n))throw new j(`Invalid old-GNU ${t}`);let o=Sr(n);if(!o)throw new j(`Invalid old-GNU ${t}`);return Kd(o,t,s.maxPathBytes),o}function m2r(e,t,s,n,o){let r=[...e.entries()].filter(([i])=>i===s||i.startsWith(`${s}/`));if(r.length===0)return;for(let[i]of r)e.delete(i);for(let[i,a]of r){let l=i.slice(s.length),u=`${n}${l}`;Kd(u,"member path",o.maxPathBytes),a.path=u;let p=e.get(u);if(p)t.delete(p);e.set(u,a)}for(let i of t.values())if(i.kind==="hard link"&&(i.targetPath===s||i.targetPath.startsWith(`${s}/`)))i.targetPath=`${n}${i.targetPath.slice(s.length)}`}function g2r(e,t,s,n){Hn(e.byteLength,n,"old-GNU name metadata");let o=e.indexOf(0),r=o===-1?e.byteLength:o,i=0;while(i<r){let a=e.indexOf(10,i),l=a===-1||a>r?r:a,u=e.subarray(i,l);if(Ap(u,0,"Rename ")){let p=f2r(u," to ",7);if(p===-1)throw new j("Invalid old-GNU name record");let c=nFe(u.subarray(7,p),"old-GNU source path",n),d=u[u.byteLength-1]===47?u.byteLength-1:u.byteLength,f=nFe(u.subarray(p+4,d),"old-GNU target path",n);m2r(t,s,x$s(c,"source path",n),x$s(f,"target path",n),n)}i=l+1}}function h2r(e,t,s){if(t.size===0)return;let n=new Set;for(let l of e.values())for(let u=l.path.lastIndexOf("/");u>0;u=l.path.lastIndexOf("/",u-1)){let p=l.path.slice(0,u);if(n.has(p))break;n.add(p)}let o=new Set(t.keys()),r=new Map,i=(l)=>{for(let u=l.length;u>0;u=l.lastIndexOf("/",u-1)){let p=e.get(l.slice(0,u));if(p&&o.has(p))return p}return null},a=[...o];while(a.length>0){let l=a.pop();if(!o.has(l))continue;let u=t.get(l),p=i(u.targetPath),c=u.targetPath;if(p===null){try{c=dW(e,c,s.maxLinkDepth)}catch(g){if(!(g instanceof j))throw new j("Invalid archive link")}if(c!==u.targetPath)p=i(c)}if(p!==null&&p!==l){let g=r.get(p);if(g)g.push(l);else r.set(p,[l]);continue}o.delete(l);let d=r.get(l);if(d)r.delete(l),a.push(...d);if(p===l){if(u.kind==="hard link")throw new j(`Archive hard link '${dr(l.path)}' has a cyclic target '${dr(u.targetPath)}'`);l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1};continue}let f=e.get(c);if(f?.storage&&!f.isDirectory&&!o.has(f)){l.size=f.size,l.storage=f.storage;continue}if(!(c===""||f?.isDirectory===!0||n.has(c))){if(u.kind==="symlink"){l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1};continue}let g=f?"unreadable member":"missing member";throw new j(`Archive hard link '${dr(l.path)}' targets ${g} '${dr(u.targetPath)}'`)}if(u.kind==="hard link")throw new j(`Archive hard link '${dr(l.path)}' targets directory '${dr(u.targetPath)}'`);l.isDirectory=!0,l.storage={type:"link",targetPath:u.targetPath,resolveTarget:!1}}if(o.size>0)throw new j("Archive contains cyclic or unsupported links")}function pae(e,t){let{limits:s}=t;ci(e.byteLength,s);let n=new Map,o=new Map,r=(d,f)=>{let m=n.get(d.path),g=yc(n,d);if(!g)return;if(m)o.delete(m);if(f)o.set(g,f);or(n.size,s)},i=0,a,l,u,p=new Map,c=!1;while(i+wS<=e.byteLength){if(H$s(e,i)){c=!0;break}if(!B$s(e,i))throw new j("Invalid or corrupt tar archive header");let d=i,f=String.fromCharCode(e[d+_$s]||48),m=U$s(e,d+Wht),g=sFe(e,d+Bht,lae);if(p2r(e,d)){let H=sFe(e,d+N$s,Ght);if(H)g=`${H}/${g}`}let h=sFe(e,d+r2r,i2r),T=oFe(e,d+P$s,F$s),y=oFe(e,d+v$s,I$s),R=Number.isSafeInteger(y)&&y>=0?y:void 0;i+=wS;let C=rFe(m);if(C>e.byteLength-i)throw new j("Archive member data is truncated");let b=e.subarray(i,i+m);if(f==="L"){Hn(b.byteLength,s,"GNU long-name metadata"),a=nFe(b,"GNU long path",s),i+=C;continue}if(f==="K"){Hn(b.byteLength,s,"GNU long-link metadata"),l=nFe(b,"GNU long link target",s),i+=C;continue}if(f==="N"){g2r(b,n,o,s),i+=C;continue}if(f==="x"||f==="X"){u=w$s(b,s),i+=C;continue}if(f==="g"){c2r(p,w$s(b,s)),i+=C;continue}if(f==="M")throw new j("GNU multi-volume tar members are not supported");if(a!==void 0)g=a;if(l!==void 0)h=l;let w=d6(p,u,"path");if(w!==void 0)g=w;let E=d6(p,u,"linkpath");if(E!==void 0)h=E;let x=d6(p,u,"size");if(x!==void 0)m=S$s(x,"member size");let A=d6(p,u,"GNU.sparse.name");if(A!==void 0)g=A;let M=m,I=d6(p,u,"GNU.sparse.realsize");if(I!==void 0)M=S$s(I,"sparse real size");let O=f==="S"||d2r(p,u);if(f==="S"&&e[d+a2r]===1){let H=!0;while(H){if(i+wS>e.byteLength)throw new j("Archive sparse metadata is truncated");H=e[i+l2r]===1,i+=wS}}let P=i,F=rFe(m);if(F>e.byteLength-P)throw new j(`Archive member '${dr(g)}' is truncated`);i+=F,a=void 0,l=void 0,u=void 0;let _=f==="5"||g.endsWith("/"),D=Sr(g);if(!D)continue;Kd(D,"member path",s.maxPathBytes);let L=T*1000,N=T!==0&&Number.isSafeInteger(L)?L:void 0;if(_){r({path:D,isDirectory:!0,size:0,mtimeMs:N,mode:R});continue}if(f==="1"||f==="2"){let H=f==="1"?"hard link":"symlink",q=h.replace(/\\/g,"/");Kd(q,"link target",s.maxPathBytes);let z=f==="1"?Sr(q):aae.posix.isAbsolute(q)?void 0:zd(aae.posix.join(aae.posix.dirname(D),q)),J={path:D,isDirectory:!1,size:0,mtimeMs:N,mode:R};if(z===void 0||Buffer.byteLength(z,"utf-8")>s.maxPathBytes){if(H==="hard link")throw new j(`Archive hard link '${dr(D)}' has an invalid target`);J.storage={type:"link",targetPath:q,resolveTarget:!1},r(J);continue}r(J,{kind:H,targetPath:z});continue}if(f!=="0"&&f!=="\x00"&&f!=="7"&&f!=="S")continue;Qi(M,D,s),r({path:D,isDirectory:!1,size:M,mtimeMs:N,mode:R,storage:{type:"member",source:new q$s(e,P,O)}})}if(!c)throw new j("Not a valid tar archive: missing terminating zero block");return h2r(n,o,s),[...n.values()]}function jht(e){if(e.byteLength<wS)return!1;if(H$s(e,0))return!0;try{if(sFe(e,Bht,lae).length===0)return!1;let t=U$s(e,Wht);return Number.isSafeInteger(rFe(t))&&B$s(e,0)}catch{return!1}}function tFe(e,t,s,n){if(n.byteLength>s)throw new j("Tar header field is too long");e.set(n,t)}function iae(e,t,s,n){if(!Number.isSafeInteger(n)||n<0)throw new j("Invalid tar numeric value");let o=n.toString(8);if(o.length>s-1)throw new j("Tar numeric value does not fit its header field");for(let r=t;r<t+s-1-o.length;r++)e[r]=48;for(let r=0;r<o.length;r++)e[t+s-1-o.length+r]=o.charCodeAt(r);e[t+s-1]=0}function T2r(e){if(e.byteLength<=lae)return[e,new Uint8Array(0)];for(let t=e.byteLength-1;t>0;t--){if(e[t]!==47)continue;let s=e.subarray(0,t),n=e.subarray(t+1);if(s.byteLength<=Ght&&n.byteLength>0&&n.byteLength<=lae)return[n,s]}return}function Dht(e,t){let s=cD.encode(`${e}=${t}
|
|
4623
4623
|
`),n=s.byteLength+2;for(;;){let a=String(n).length+1+s.byteLength;if(a===n)break;n=a}let o=cD.encode(`${n} `),r=new Uint8Array(n);return r.set(o),r.set(s,o.byteLength),r}function G$s(e){let t=0;for(let o of e)if(t+=o.byteLength,!Number.isSafeInteger(t))throw new j("Tar archive is too large to encode safely");let s=new Uint8Array(t),n=0;for(let o of e)s.set(o,n),n+=o.byteLength;return s}function E$s(e,t,s,n,o,r){let i=new Uint8Array(wS);tFe(i,Bht,lae,e),iae(i,v$s,I$s,o),iae(i,108,8,0),iae(i,116,8,0),iae(i,Wht,O$s,s),iae(i,P$s,F$s,n),i.fill(32,pD,pD+Nht),i[_$s]=r,tFe(i,L$s,qht.length,cD.encode(qht)),tFe(i,D$s,Uht.length,cD.encode(Uht)),tFe(i,N$s,Ght,t);let a=0;for(let u of i)a+=u;let l=a.toString(8).padStart(6,"0");for(let u=0;u<6;u++)i[pD+u]=l.charCodeAt(u);return i[pD+6]=0,i[pD+7]=32,i}function M$s(e,t){e.push(t);let s=rFe(t.byteLength)-t.byteLength;if(s>0)e.push(new Uint8Array(s))}function A$s(e,t,s,n,o){let r=cD.encode(n?`${t}/`:t),i=T2r(r),a=n?0:s.byteLength,l=0,u=[];if(!i)u.push(Dht("path",n?`${t}/`:t));if(a>b$s)u.push(Dht("size",String(a)));if(0>u2r)u.push(Dht("mtime",String(0)));if(u.length>0){let c=G$s(u),d=cD.encode(`PaxHeaders/${String(o).padStart(8,"0")}`);e.push(E$s(d,new Uint8Array(0),c.byteLength,0,420,120)),M$s(e,c)}let p=i??[cD.encode(`PaxFile/${String(o).padStart(8,"0")}`),new Uint8Array(0)];if(e.push(E$s(p[0],p[1],a<=b$s?a:0,0,n?493:420,n?53:48)),!n)M$s(e,s)}async function iFe(e){let t=[],s=new Map,n=0;for(let[o,r]of e){let i=o.endsWith("/")||o.endsWith("\\"),a=Sr(o);if(!a)throw new j(`Invalid tar member path '${dr(o)}'`);if(cD.encode(a).byteLength===0)throw new j("Invalid empty tar member path");if(i&&r.byteLength!==0)throw new j(`Tar directory '${dr(a)}' cannot contain file data`);let u=a.split("/");for(let c=1;c<u.length;c++){let d=u.slice(0,c).join("/"),f=s.get(d);if(f==="file")throw new j(`Tar member '${dr(d)}' is not a directory`);if(f==="directory")continue;s.set(d,"directory"),A$s(t,d,new Uint8Array(0),!0,n++)}let p=s.get(a);if(p){if(i&&p==="directory")continue;throw new j(`Duplicate tar member path '${dr(a)}'`)}s.set(a,i?"directory":"file"),A$s(t,a,r,i,n++)}return t.push(new Uint8Array(wS*2)),G$s(t)}var wS=512,Bht=0,lae=100,v$s=100,I$s=8,Wht=124,O$s=12,P$s=136,F$s=12,pD=148,Nht=8,_$s=156,r2r=157,i2r=100,L$s=257,qht="ustar\x00",D$s=263,Uht="00",N$s=345,Ght=155,a2r=482,l2r=504,C$s=32,Hht="GNU.sparse.",uae,cD,b$s=8589934591,u2r=8589934591,W$s=async(e,t)=>{ci(e.size,t.limits);let s;try{s=await eM(e)}catch(n){if(n instanceof j)throw n;throw new j(n instanceof Error?n.message:"Failed to read tar archive")}if(s.byteLength!==e.size)throw new j("Invalid archive: truncated data");return pae(s,t)};var aFe=S(()=>{Sh();uD();Ur();vp();Vd();tM();uae=new TextDecoder,cD=new TextEncoder});class $$s{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async read(e,t){try{let s=await this.#e.read(this.#t,this.#t+e);if(s.byteLength!==e)throw new j(`Archive member '${t}' is truncated`);return s}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}}}function f6(e,t,s){let n=t+s;while(n>t&&e[n-1]===32)n--;let o="";for(let r=t;r<n;r++){let i=e[r];if(i<32||i>126)throw new j("Invalid ar archive header field");o+=String.fromCharCode(i)}return o}function cae(e,t,s){if(e===""||e==="-1")return;if(!(t===8?/^[0-7]+$/:/^\d+$/).test(e))throw new j(`Invalid ar archive ${s}`);let o=Number.parseInt(e,t);if(!Number.isSafeInteger(o))throw new j(`Invalid ar archive ${s}`);return o}function b2r(e){let t=cae(e,10,"member size");if(t===void 0)throw new j("Invalid ar archive member size");return t}function k2r(e){if(e.byteLength!==pFe||e[j$s]!==96||e[j$s+1]!==10)throw new j("Invalid ar archive member header");let t=f6(e,0,y2r),s=cae(f6(e,16,12),10,"modification time");cae(f6(e,28,6),10,"user id"),cae(f6(e,34,6),10,"group id");let n=cae(f6(e,40,8),8,"mode"),o=b2r(f6(e,48,10)),r;if(t.startsWith("#1/")){let i=t.slice(3);if(!/^\d+$/.test(i))throw new j("Invalid ar archive BSD extended name length");if(r=Number.parseInt(i,10),!Number.isSafeInteger(r)||r<=0||r>o)throw new j("Invalid ar archive BSD extended name length")}return{rawName:t,physicalSize:o,mtimeSeconds:s,mode:n,bsdNameLength:r}}function z$s(e,t){return ko(e.byteLength,"member path",t.maxPathBytes),r6.decode(e)}function S2r(e,t){let s=e.indexOf(0),n=s>=0?e.subarray(0,s):e;if(n.byteLength===0)throw new j("Invalid ar archive empty BSD extended name");return{name:z$s(n,t),byteLength:n.byteLength}}function w2r(e){if(e==="/"||e==="//"||e==="/SYM64/")return e;return e.endsWith("/")?e.slice(0,-1):e}function x2r(e,t,s){let n=e.slice(1);if(!/^\d+$/.test(n))throw new j(`Invalid ar archive member name '${e}'`);let o=Number.parseInt(n,10);if(!Number.isSafeInteger(o)||o<0||o>=t.byteLength)throw new j(`Invalid ar archive long-name offset '${e}'`);let r=o;while(r<t.byteLength&&t[r]!==0&&t[r]!==10)r++;if(r===t.byteLength)throw new j(`Unterminated ar archive long name at offset ${o}`);let i=r;if(t[r]===10&&i>o&&t[i-1]===47)i--;if(i===o)throw new j(`Empty ar archive long name at offset ${o}`);let a=t.subarray(o,i);return{name:z$s(a,s),byteLength:a.byteLength}}function E2r(e){return e==="/"||e==="//"||e==="/SYM64/"||e==="__.SYMDEF"||e==="__.SYMDEF SORTED"}function M2r(e,t,s,n){let o=new Map;for(let r of e){let{name:i,nameByteLength:a}=r;if(/^\/\d+$/.test(i)){if(!t)throw new j(`Ar archive member '${i}' references a missing long-name table`);let c=x2r(i,t,n.limits);i=c.name,a=c.byteLength}else i=w2r(i);if(E2r(i))continue;ko(a,"member path",n.limits.maxPathBytes),Qi(r.size,i,n.limits);let l=Sr(i);if(!l)continue;let u=r.mode!==void 0&&(r.mode&R2r)===C2r,p={path:l,isDirectory:u,size:u?0:r.size,...r.mtimeSeconds!==void 0?{mtimeMs:r.mtimeSeconds*1000}:{},...r.mode!==void 0?{mode:r.mode}:{},...!u?{storage:{type:"member",source:new $$s(s,r.dataOffset)}}:{}};yc(o,p),or(o.size,n.limits)}return lD(o,n.limits),[...o.values()]}function A2r(e){if(!$ht(e))throw new j("Invalid ar archive signature")}async function lFe(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.size)throw new j(`Invalid ar archive: truncated ${n}`);try{let o=await e.read(t,s);if(o.byteLength!==s-t)throw new j(`Invalid ar archive: truncated ${n}`);return o}catch(o){if(o instanceof j)throw o;throw new j(o instanceof Error?o.message:String(o))}}async function v2r(e,t){if(!Number.isSafeInteger(e.size)||e.size<uFe.length)throw new j("Invalid ar archive signature");A2r(await lFe(e,0,uFe.length,"signature"));let s=[],n,o=0;for(let r=uFe.length;r<e.size;){let i=await lFe(e,r,r+pFe,"member header"),a=k2r(i);o+=pFe,Hn(o,t.limits,"index");let l=r+pFe,u=l+a.physicalSize;if(!Number.isSafeInteger(u)||u>e.size)throw new j("Invalid ar archive: truncated member data");let p=a.rawName,c=Buffer.byteLength(p,"utf-8"),d=l,f=a.physicalSize;if(a.bsdNameLength!==void 0){o+=a.bsdNameLength,Hn(o,t.limits,"index");let m=await lFe(e,l,l+a.bsdNameLength,"BSD member name"),g=S2r(m,t.limits);p=g.name,c=g.byteLength,d+=a.bsdNameLength,f-=a.bsdNameLength}else if(a.rawName==="//")o+=a.physicalSize,Hn(o,t.limits,"index"),n=await lFe(e,l,u,"long-name table");if(s.push({name:p,nameByteLength:c,dataOffset:d,size:f,mtimeSeconds:a.mtimeSeconds,mode:a.mode}),or(s.length,t.limits),r=u+(a.physicalSize&1),r>e.size)throw new j("Invalid ar archive: missing alignment byte")}return M2r(s,n,e,t)}function $ht(e){return Ap(e,0,uFe)}var uFe=`!<arch>
|
|
4624
4624
|
`,pFe=60,y2r=16,j$s=58,R2r=61440,C2r=16384,cFe=async(e,t)=>{try{return await v2r(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}};var zht=S(()=>{Sh();uD();Ur();vp();Vd();tM()});function O2r(e){if(!Ap(e,0,dFe)||e.byteLength<dFe.length+Kht)return;let t=dFe.length;if(e[t+58]!==96||e[t+59]!==10)return;let s=t+I2r;while(s>t&&e[s-1]===32)s--;let n="";for(let o=t;o<s;o++){let r=e[o];if(r<32||r>126)return;n+=String.fromCharCode(r)}if(n.startsWith("#1/")){let o=n.slice(3);if(!/^\d+$/.test(o))return;let r=Number.parseInt(o,10),i=t+Kht;if(!Number.isSafeInteger(r)||r<=0||i+r>e.byteLength)return;let a=e.subarray(i,i+r),l=a.indexOf(0);return r6.decode(l>=0?a.subarray(0,l):a)}return n.endsWith("/")?n.slice(0,-1):n}function P2r(e){let t=/^(control|data)\.tar(?:\.(gz|xz|zst|bz2|lzma))?$/.exec(e);if(!t)return;return{kind:t[1],compression:t[2]??"none"}}async function F2r(e,t,s){let n=s.limits.maxInMemorySize,o;switch(t){case"none":o=e;break;case"gz":o=await hW(e,n);break;case"xz":o=await y0(e,n);break;case"zst":o=await R0(e,n);break;case"bz2":o=await T0(e,n);break;case"lzma":o=await p6(e,n);break}return ci(o.byteLength,s.limits),o}function _2r(e){let t=`control/${e.path}`;if(e.storage?.type!=="link")return{...e,path:t};let s=e.storage.targetPath;if(s!==""&&Sr(s)!==s)return{...e,path:t};return{...e,path:t,storage:{...e.storage,targetPath:s?`control/${s}`:"control"}}}async function L2r(e){if(e.isDirectory||e.storage?.type!=="member")throw new j(`Invalid deb archive member '${e.path}'`);return e.storage.source.read(e.size,e.path)}async function D2r(e,t){let s=Math.min(e.size,dFe.length+Kht+t.limits.maxPathBytes),n;try{n=await e.read(0,s)}catch(i){throw new j(i instanceof Error?i.message:String(i))}if(!Vht(n))throw new j("Invalid deb archive: first member is not debian-binary");let o=await cFe(e,t);if(o[0]?.path!==K$s)throw new j("Invalid deb archive: first member is not debian-binary");let r=new Map;for(let i of o){let a=P2r(i.path);if(!a){if(i.path.startsWith("control.tar.")||i.path.startsWith("data.tar."))throw new j(`Unsupported deb tar compression in '${i.path}'`);yc(r,i);continue}let l=await L2r(i),u=await F2r(l,a.compression,t),p=pae(u,t);for(let c of p)yc(r,a.kind==="control"?_2r(c):c)}return lD(r,t.limits),[...r.values()]}function Vht(e){return O2r(e)===K$s}var dFe=`!<arch>
|
|
4625
4625
|
`,Kht=60,I2r=16,K$s="debian-binary",V$s=async(e,t)=>{try{return await D2r(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}};var Y$s=S(()=>{Sh();tae();sae();TW();oae();c6();uD();Ur();vp();Vd();aFe();zht()});import*as CW from"path";class Q$s{#e=0;#t;constructor(e){this.#t=e}async read(e,t,s,n){Xht(e,t,s,n),this.#e+=s-t,Hn(this.#e,this.#t,"ISO metadata");let o=await e.read(t,s);if(o.byteLength!==s-t)throw To(`truncated ${n}`);return o}}class Z$s{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}async read(e,t){try{let s=new Uint8Array(e),n=0;for(let o of this.#s){if(n+o.size>e)throw To(`invalid multi-extent size for '${t}'`);let r=o.fileUnitSize*this.#t,i=o.interleaveGapSize*this.#t;if(r===0){let u=await J$s(this.#e,o.start,o.size,t);s.set(u,n),n+=u.byteLength;continue}let{size:a,start:l}=o;while(a>0){let u=Math.min(r,a),p=await J$s(this.#e,l,u,t);s.set(p,n),n+=u,a-=u,l=b0(l,r+i,"interleaved file offset")}}if(n!==e)throw To(`member '${t}' produced ${n} bytes, expected ${e}`);return s}catch(s){if(s instanceof j)throw s;throw To(`could not extract member '${t}'`)}}}function To(e){return new j(`Invalid ISO 9660 archive: ${e}`)}function gFe(e,t,s){let n=e*t;if(!Number.isSafeInteger(n)||n<0)throw To(`${s} is too large`);return n}function b0(e,t,s){let n=e+t;if(!Number.isSafeInteger(n)||n<0)throw To(`${s} is too large`);return n}function Xht(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.size)throw To(`truncated or invalid ${n}`)}async function J$s(e,t,s,n){let o=b0(t,s,"member extent");Xht(e,t,o,`extent for '${n}'`);let r=await e.read(t,o);if(r.byteLength!==s)throw To(`truncated extent for '${n}'`);return r}function fFe(e,t,s){let n=xn(e,t);if(n!==Kie(e,t+2))throw To(`${s} has mismatched byte orders`);return n}function dD(e,t,s){let n=Es(e,t);if(n!==kh(e,t+4))throw To(`${s} has mismatched byte orders`);return n}function q2r(e,t){let s=e[t]+1900,n=e[t+1],o=e[t+2],r=e[t+3],i=e[t+4],a=e[t+5],l=e[t+6],u=l>=128?l-256:l;if(n<1||n>12||o<1||o>31||r>23||i>59||a>60||u<-48||u>52)return;let p=Date.UTC(s,n-1,o,r,i,Math.min(a,59));if(!Number.isFinite(p))return;return p-u*15*60000}function ezs(e,t,s,n){if(s<34)throw To(`${n} directory record is too short`);let o=e[t];if(o<34||o>s)throw To(`${n} directory record has an invalid length`);let r=e[t+32],i=r%2===0?1:0,a=33+r+i;if(r===0||a>o)throw To(`${n} directory record has an invalid identifier`);let l=dD(e,t+2,`${n} extent location`),u=dD(e,t+10,`${n} data length`);fFe(e,t+28,`${n} volume sequence number`);let p=e[t+26],c=e[t+27];if(p===0!==(c===0))throw To(`${n} has an invalid interleave configuration`);return{extent:l,size:u,extendedAttributeBlocks:e[t+1],mtimeMs:q2r(e,t+18),flags:e[t+25],fileUnitSize:p,interleaveGapSize:c,identifier:e.subarray(t+33,t+33+r),systemUse:e.subarray(t+a,t+o)}}function X$s(e,t){dD(e,80,"volume space size"),fFe(e,120,"volume set size"),fFe(e,124,"volume sequence number");let s=fFe(e,128,"logical block size");if(dD(e,132,"path table size"),s!==OC)throw new j(`Unsupported ISO 9660 logical block size ${s} (expected 2048)`);let n=ezs(e,156,e.byteLength-156,"root");if((n.flags&2)===0||n.size===0||n.identifier.byteLength!==1||n.identifier[0]!==0)throw To("invalid root directory record");return{blockSize:s,root:n,joliet:t}}async function U2r(e,t,s){if(e.size<Yht+OC)throw To("truncated volume descriptor set");let n=Yht,o=16,r=new Uint8Array(0),i=0,a,l,u=!1,p=!1,c=!1,d=0;while(!c&&n<e.size){let f=gFe(o,OC,"volume descriptor scan"),m=s.maxIndexSize-d;if(m<OC)throw To("volume descriptor set exceeds metadata limit");let g=Math.floor(Math.min(f,m,e.size-n)/OC);if(g<1)throw To("truncated volume descriptor");let h=g*OC;r=await t.read(e,n,n+h,"volume descriptor set"),i=0;while(i+OC<=r.byteLength){let T=r.subarray(i,i+OC),y=T[0];if(Ap(T,1,"CDROM")||Ap(T,9,"CDROM"))p=!0;if(Ap(T,1,"BEA01")||Ap(T,1,"NSR02")||Ap(T,1,"NSR03")||Ap(T,1,"TEA01"))u=!0;if(Ap(T,1,"CD001")){if(T[6]!==1&&T[6]!==2)throw To("unsupported volume descriptor version");if(y===1)a=X$s(T,!1);if(y===2&&T[88]===37&&T[89]===47&&[64,67,69].includes(T[90]))l=X$s(T,!0);if(y===255){c=!0;break}}i+=OC,d+=OC}n+=r.byteLength,o=Math.min(o*2,Math.ceil(s.maxIndexSize/OC))}if(!a&&!l){if(p)throw new j("Unsupported High Sierra CD-ROM filesystem (not ISO 9660)");if(u)throw new j("Unsupported UDF-only image (no ISO 9660 volume descriptor)");throw To("primary volume descriptor not found")}if(!c)throw To("volume descriptor terminator not found");if(l)return{...l,rockRidgeRoot:a?.root};return a}function tzs(e,t){let s;if(t){if(e.byteLength%2!==0)throw To("Joliet identifier has an odd byte length");let n=new Uint16Array(e.byteLength/2);for(let r=0;r<n.length;r++)n[r]=Kie(e,r*2);let o=[];for(let r=0;r<n.length;r+=4096)o.push(String.fromCharCode(...n.subarray(r,r+4096)));s=o.join("")}else s=Jht.decode(e);return s.endsWith(";1")?s.slice(0,-2):s}function szs(e){let t=e.systemUse;for(let s=0;s+7<=t.byteLength;){let n=t[s+2];if(n<4||s+n>t.byteLength)return;if(t[s]===83&&t[s+1]===80&&n===7&&t[s+4]===190&&t[s+5]===239)return t[s+6];s+=n}return}async function nzs(e,t,s,n,o,r){if(t===void 0||t>e.systemUse.byteLength)return{};let i=[e.systemUse.subarray(t)],a=new Set,l=[],u=[],p=!1,c,d;for(let g=0;g<i.length;g++){let h=i[g];for(let T=0;T+4<=h.byteLength;){let y=String.fromCharCode(h[T],h[T+1]),R=h[T+2],C=h[T+3];if(R<4||T+R>h.byteLength)throw To("malformed SUSP record");if(C!==1&&(y==="CE"||y==="NM"||y==="PX"||y==="RE"||y==="CL"||y==="PL"||y==="SL"||y==="ST"))throw To(`unsupported SUSP ${y} version ${C}`);let b=h.subarray(T+4,T+R);if(y==="ST")break;if(y==="CE"){if(b.byteLength<24)throw To("short SUSP CE record");let w=dD(b,0,"SUSP continuation block"),E=dD(b,8,"SUSP continuation offset"),x=dD(b,16,"SUSP continuation length");Hn(x,r,"ISO SUSP continuation");let A=b0(gFe(w,n,"SUSP continuation location"),E,"SUSP continuation location"),M=b0(A,x,"SUSP continuation range"),I=`${A}:${M}`;if(a.has(I))throw To("cyclic SUSP continuation");if(a.size>=N2r)throw To("too many SUSP continuations");a.add(I),i.push(await o.read(s,A,M,"SUSP continuation"))}if(y==="NM"&&b.byteLength>=1){let w=b[0];if((w&6)===0)l.push(Jht.decode(b.subarray(1)));else if(w&2)l.push(".");else if(w&4)l.push("..")}if(y==="PX"&&b.byteLength>=8)c=dD(b,0,"Rock Ridge PX mode");if(y==="RE"||y==="CL"||y==="PL")d=y;if(y==="SL"&&b.byteLength>=1){let w=1;while(w<b.byteLength){if(w+2>b.byteLength)throw To("malformed Rock Ridge SL component");let E=b[w],x=b[w+1];if(w+=2,w+x>b.byteLength)throw To("malformed Rock Ridge SL component");let A;if(E&8)A="";else if(E&4)A="..";else if(E&2)A=".";else A=Jht.decode(b.subarray(w,w+x));if(p&&u.length>0)u[u.length-1]+=A;else u.push(A);p=(E&1)!==0,w+=x}}T+=R}}let f=l.length>0?l.join(""):void 0,m;if(u.length>0)m=u[0]===""?`/${u.slice(1).join("/")}`:u.join("/");return{name:f,mode:c,symlink:m,relocation:d}}function ozs(e,t){for(let s=e;s;s=s.parent)if(s.key===t)return!0;return!1}function H2r(e,t){let s=b0(e.extent,e.extendedAttributeBlocks,"file extent block");return{start:gFe(s,t,"file extent offset"),size:e.size,fileUnitSize:e.fileUnitSize,interleaveGapSize:e.interleaveGapSize}}async function rzs(e,t,s,n,o){let r=gFe(b0(t.extent,t.extendedAttributeBlocks,"directory extent block"),s,"directory extent offset"),i=b0(r,t.size,"directory extent range"),a=await n.read(e,r,i,"directory extent"),l=[];for(let u=0;u<a.byteLength;){let p=s-u%s,c=a[u];if(c===0){u+=p;continue}if(c>p||c>a.byteLength-u)throw To("directory record crosses a logical block");l.push(ezs(a,u,c,"member")),or(l.length,o),u+=c}return l}async function B2r(e,t,s,n,o,r){let i=`${t.extent}:${t.size}`,a=[{record:t,parentPath:"",depth:0,ancestor:{key:i}}],l;while(a.length>0){let u=a.pop();if(u.depth>mFe)throw To(`directory hierarchy exceeds ${mFe} levels`);let p=await rzs(e,u.record,s,n,o);if(u.depth===0&&p.length>0&&p[0].identifier.byteLength===1&&p[0].identifier[0]===0)l=szs(p[0]);for(let c of p){if(c.identifier.byteLength===1&&(c.identifier[0]===0||c.identifier[0]===1))continue;let d=await nzs(c,l,e,s,n,o);if(d.relocation)throw new j(`Unsupported Rock Ridge relocated directory (${d.relocation})`);let f=d.name??tzs(c.identifier,!1);ko(Buffer.byteLength(f,"utf-8"),"member name",o.maxPathBytes);let m=u.parentPath?`${u.parentPath}/${f}`:f,g=Sr(m);if(!g)continue;if(ko(Buffer.byteLength(g,"utf-8"),"member path",o.maxPathBytes),d.symlink!==void 0){ko(Buffer.byteLength(d.symlink,"utf-8"),"link target",o.maxPathBytes);let y=CW.posix.isAbsolute(d.symlink)?void 0:zd(CW.posix.join(CW.posix.dirname(g),d.symlink));yc(r,{path:g,isDirectory:!1,size:0,mtimeMs:c.mtimeMs,mode:d.mode,storage:{type:"link",targetPath:y??d.symlink,resolveTarget:y!==void 0}}),or(r.size,o);continue}let h=r.get(g);if(h&&d.mode!==void 0)r.set(g,{...h,mode:d.mode});if((c.flags&2)===0)continue;let T=`${c.extent}:${c.size}`;if(ozs(u.ancestor,T))throw To(`cyclic directory at '${g}'`);a.push({record:c,parentPath:g,depth:u.depth+1,ancestor:{key:T,parent:u.ancestor}})}}}async function W2r(e,t){if(!Number.isSafeInteger(e.size)||e.size<0)throw To("invalid source size");let s=new Q$s(t.limits),n=await U2r(e,s,t.limits),r={key:`${n.root.extent}:${n.root.size}`},i=[{record:n.root,parentPath:"",depth:0,ancestor:r}],a=new Map,l;while(i.length>0){let u=i.pop();if(u.depth>mFe)throw To(`directory hierarchy exceeds ${mFe} levels`);let p=await rzs(e,u.record,n.blockSize,s,t.limits);if(u.depth===0&&p.length>0&&p[0].identifier.byteLength===1&&p[0].identifier[0]===0)l=szs(p[0]);for(let c=0;c<p.length;){let d=p[c];if(d.identifier.byteLength===1&&(d.identifier[0]===0||d.identifier[0]===1)){c++;continue}let f=[d];if((d.flags&128)!==0){if((d.flags&2)!==0)throw To("multi-extent directory is unsupported");while((f[f.length-1].flags&128)!==0){let b=p[++c];if(!b||b.identifier.byteLength!==d.identifier.byteLength)throw To("unterminated multi-extent file");for(let w=0;w<d.identifier.byteLength;w++)if(b.identifier[w]!==d.identifier[w])throw To("non-contiguous multi-extent file");if((b.flags&-129)!==(d.flags&-129))throw To("inconsistent multi-extent file flags");f.push(b)}}c++;let m=await nzs(d,l,e,n.blockSize,s,t.limits);if(m.relocation)throw new j(`Unsupported Rock Ridge relocated directory (${m.relocation})`);let g=m.name??tzs(d.identifier,n.joliet);ko(Buffer.byteLength(g,"utf-8"),"member name",t.limits.maxPathBytes);let h=u.parentPath?`${u.parentPath}/${g}`:g,T=Sr(h);if(!T)continue;ko(Buffer.byteLength(T,"utf-8"),"member path",t.limits.maxPathBytes);let y=(d.flags&2)!==0;if(m.symlink!==void 0){ko(Buffer.byteLength(m.symlink,"utf-8"),"link target",t.limits.maxPathBytes);let b=CW.posix.isAbsolute(m.symlink)?void 0:zd(CW.posix.join(CW.posix.dirname(T),m.symlink));yc(a,{path:T,isDirectory:!1,size:0,mtimeMs:d.mtimeMs,mode:m.mode,storage:{type:"link",targetPath:b??m.symlink,resolveTarget:b!==void 0}}),or(a.size,t.limits);continue}if(y){yc(a,{path:T,isDirectory:!0,size:0,mtimeMs:d.mtimeMs,mode:m.mode}),or(a.size,t.limits);let b=`${d.extent}:${d.size}`;if(ozs(u.ancestor,b))throw To(`cyclic directory at '${T}'`);i.push({record:d,parentPath:T,depth:u.depth+1,ancestor:{key:b,parent:u.ancestor}});continue}let R=0;for(let b of f)R=b0(R,b.size,"multi-extent member size");Qi(R,T,t.limits);let C=R===0?[]:f.map((b)=>H2r(b,n.blockSize));for(let b of C)Xht(e,b.start,b0(b.start,b.size,"file extent range"),`extent for '${T}'`);yc(a,{path:T,isDirectory:!1,size:R,mtimeMs:d.mtimeMs,mode:m.mode,storage:{type:"member",source:new Z$s(e,n.blockSize,C)}}),or(a.size,t.limits)}}if(n.rockRidgeRoot)await B2r(e,n.rockRidgeRoot,n.blockSize,s,t.limits,a);return[...a.values()]}function izs(e){return Ap(e,Yht+1,"CD001")}var OC=2048,Yht,mFe=256,N2r=32,Jht,azs=async(e,t)=>{try{return await W2r(e,t)}catch(s){if(s instanceof j)throw s;throw To("could not parse image")}};var lzs=S(()=>{Sh();uD();Ur();vp();Vd();Yht=16*OC,Jht=new TextDecoder});class gzs{bytes;pos=0;bit=0;constructor(e){this.bytes=new Uint8Array(e.byteLength+4),this.bytes.set(e)}read(e){if(e===0)return 0;let t=0;for(let s=e;s>0;){if(this.pos>=this.bytes.byteLength-4)fD("truncated compressed data");let n=Math.min(s,8-this.bit);if(t=t*2**n+(this.bytes[this.pos]>>>8-this.bit-n&2**n-1),this.bit+=n,s-=n,this.bit===8)this.bit=0,this.pos++}return t}align(){if(this.bit!==0)this.pos++,this.bit=0}}class m6{#e=new Int32Array(16);#t=new Int32Array(16);#s=new Int32Array(16);#n;#o=!1;constructor(e){this.#n=new Int32Array(e)}build(e,t,s){this.#e.fill(0);for(let i=0;i<s;i++){let a=e[t+i]&15;if(a!==0)this.#e[a]++}let n=0,o=0;for(let i=1;i<=15;i++)n=n+this.#e[i-1]<<1,this.#t[i]=n,this.#s[i]=o,o+=this.#e[i];let r=this.#s.slice();for(let i=0;i<s;i++){let a=e[t+i]&15;if(a!==0)this.#n[r[a]++]=i}this.#o=o!==0}decode(e){if(!this.#o)fD("empty Huffman table");let t=0;for(let s=1;s<=15;s++){t=t<<1|e.read(1);let n=t-this.#t[s];if(n>=0&&n<this.#e[s])return this.#n[this.#s[s]+n]}fD("invalid Huffman symbol")}}class Zht{#e=new Uint8Array(0);#t=[0,0,0,0];#s=0;#n=0;#o=0;#r=0;#a=new Uint8Array(uzs);#i=[];#l=[];#u=0;reset(){this.#e=new Uint8Array(0),this.#t=[0,0,0,0],this.#s=0,this.#n=0,this.#o=0,this.#r=0,this.#a.fill(0),this.#i=[],this.#l=[],this.#u=0}decode(e,t,s,n,o){if(o<29)throw new j(`Unsupported RAR4 compression algorithm version ${o}`);if(!n)this.reset();let r=this.#e.byteLength>s?this.#e.subarray(this.#e.byteLength-s):this.#e,i=new Uint8Array(r.byteLength+t+260);i.set(r);let a=r.byteLength,l=a+t,u=a,p=new gzs(e),c=new m6(hFe),d=new m6(g6),f=new m6(TFe),m=new m6(Qht),g=[],h=()=>{if(p.align(),p.read(1)!==0)throw new j("Unsupported RAR4 PPMd compressed block");let b=p.read(1)!==0;if(this.#o=0,this.#r=0,!b)this.#a.fill(0);let w=V2r(p,this.#a,uzs),E=0;c.build(w,E,hFe),E+=hFe,d.build(w,E,g6),E+=g6,f.build(w,E,TFe),E+=TFe,m.build(w,E,Qht),this.#a.set(w)},T=(b,w)=>{if(b<=0||b>s||b>u)fD("invalid LZ distance");w=Math.min(w,l-u);for(let E=0;E<w;E++)i[u+E]=i[u+E-b];u+=w},y=(b)=>{this.#t[3]=this.#t[2],this.#t[2]=this.#t[1],this.#t[1]=this.#t[0],this.#t[0]=b},R=()=>{let b=p.read(8),w=(b&7)+1;if(w===7)w=p.read(8)+7;else if(w===8)w=p.read(16);let E=new Uint8Array(w);for(let _=0;_<w;_++)E[_]=p.read(8);let x=new hzs(E),A;if((b&128)!==0)if(A=x.readData(),A===0)this.#i=[],this.#l=[];else A--;else A=this.#u;if(A<0||A>this.#i.length)fD("invalid RarVM filter index");this.#u=A;let M=A===this.#i.length,I=x.readData();if((b&64)!==0)I+=258;I+=u-a;let O=(b&32)!==0?x.readData():this.#l[A]??0,P=new Int32Array(7);if(P[3]=245760,P[4]=O,(b&16)!==0){let _=x.read(7);for(let D=0;D<7;D++)if((_&1<<D)!==0)P[D]=x.readData()}let F;if(M){let _=x.readData(),D=new Uint8Array(_);for(let L=0;L<_;L++)D[L]=x.read(8);F=$2r(D),this.#i.push(F),this.#l.push(O)}else F=this.#i[A],this.#l[A]=O;if(F!==1&&F!==2&&F!==6)throw new j(`Unsupported RAR4 RarVM filter type ${F||"unknown"}`);if(I<0||O<0||I+O>t)fD("invalid RarVM filter range");g.push({type:F,start:I,size:O,channels:P[0],fileOffset:P[6]})};h();while(u<l){let b=c.decode(p);if(b<256)i[u++]=b;else if(b>=271){let w=b-271,E=pzs[w]+3+p.read(czs[w]),x=d.decode(p),A=fzs[x]+1,M=mzs[x];if(M!==0)if(x>9){if(M>4)A+=p.read(M-4)*16;if(this.#r>0)this.#r--,A+=this.#o;else{let I=f.decode(p);if(I===16)this.#r=15,A+=this.#o;else A+=I,this.#o=I}}else A+=p.read(M);if(A>=8192)E++;if(A>=262144)E++;y(A),this.#s=A,this.#n=E,T(A,E)}else if(b===256)if(p.read(1)!==0)h();else{if(p.read(1)!==0)h();break}else if(b===257)R();else if(b===258){if(this.#n!==0)T(this.#s,this.#n)}else if(b<263){let w=b-259,E=this.#t[w];for(let M=w;M>0;M--)this.#t[M]=this.#t[M-1];this.#t[0]=E;let x=m.decode(p),A=pzs[x]+2+p.read(czs[x]);this.#s=E,this.#n=A,T(E,A)}else{let w=b-263,E=G2r[w]+1+p.read(j2r[w]);y(E),this.#s=E,this.#n=2,T(E,2)}}if(u!==l)fD(`decompressed size mismatch (${u-a} != ${t})`);let C=i.slice(a,l);return z2r(C,g),this.#e=i.slice(Math.max(0,l-s),l),C}}class hzs{#e;#t=0;constructor(e){this.#e=e}read(e){let t=0;for(let s=e;s>0;){let n=this.#t>>>3;if(n>=this.#e.byteLength)fD("truncated RarVM code");let o=this.#t&7,r=Math.min(s,8-o);t=t*2**r+(this.#e[n]>>>8-o-r&2**r-1),this.#t+=r,s-=r}return t}readData(){let e=this.read(2);if(e===0)return this.read(4);if(e===1){let t=this.read(4);if(t===0)return this.read(8)|4294967040|0;return t*16+this.read(4)}if(e===2)return this.read(16);return this.read(16)*65536+this.read(16)}}function $2r(e){let t=Wi(e);if(e.byteLength===53&&t===2908186759)return 1;if(e.byteLength===57&&t===1020781950)return 2;if(e.byteLength===29&&t===235276157)return 6;if(e.byteLength===120&&t===929663295)return 3;if(e.byteLength===149&&t===472669640)return 4;if(e.byteLength===216&&t===3162892033)return 5;if(e.byteLength===40&&t===1186579808)return 7;return 0}function z2r(e,t){for(let s of t){let n=e.subarray(s.start,s.start+s.size);if(s.type===6){let r=n.slice(),i=0;for(let a=0;a<s.channels;a++){let l=0;for(let u=a;u<n.byteLength;u+=s.channels)l=l-r[i++]&255,n[u]=l}continue}let o=s.type===2?233:232;for(let r=0;r+4<n.byteLength;){let i=n[r++];if(i!==232&&i!==o)continue;let a=r+(s.fileOffset>>>0),l=K2r(n,r);if(l<0){if(l+a>=0)dzs(n,r,l+16777216)}else if(l-16777216<0)dzs(n,r,l-a);r+=4}}}function K2r(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function dzs(e,t,s){e[t]=s,e[t+1]=s>>>8,e[t+2]=s>>>16,e[t+3]=s>>>24}function V2r(e,t,s){let n=new Uint8Array(20);for(let i=0;i<20;i++){let a=e.read(4);if(a===15){let l=e.read(4);if(l!==0){l+=2;while(l-- >0&&i<20)n[i++]=0;i--;continue}}n[i]=a}let o=new m6(20);o.build(n,0,20);let r=new Uint8Array(s);for(let i=0;i<s;){let a=o.decode(e);if(a<16)r[i]=a+t[i]&15,i++;else if(a===16||a===17){let l=e.read(a===16?3:7)+(a===16?3:11),u=i===0?0:r[i-1];while(l-- >0&&i<s)r[i++]=u}else{let l=e.read(a===18?3:7)+(a===18?3:11);while(l-- >0&&i<s)r[i++]=0}}return r}function fD(e){throw new j(`Invalid RAR4 archive: ${e}`)}var hFe=299,g6=60,TFe=17,Qht=28,uzs,pzs,czs,G2r,j2r,fzs,mzs;var Tzs=S(()=>{m0();Ur();uzs=hFe+g6+TFe+Qht,pzs=[0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224],czs=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5],G2r=[0,4,8,16,32,64,128,192],j2r=[2,2,3,4,5,6,6,6],fzs=new Int32Array(g6),mzs=new Uint8Array(g6);{let e=[4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,14,0,12],t=0,s=0;for(let n=0;n<e.length;n++)for(let o=0;o<e[n];o++)fzs[s]=t,mzs[s]=n,t+=2**n,s++}});class bzs{bytes;pos=0;bit=0;blockEnd=0;blockEndBit=0;constructor(e){this.bytes=new Uint8Array(e.byteLength+16),this.bytes.set(e),this.bytes.fill(255,e.byteLength)}read(e){if(e===0)return 0;if(e<0||e>31)od("invalid bit count");let t=0;for(let s=e;s>0;){if(this.pos>=this.bytes.byteLength-16)od("truncated compressed data");let n=Math.min(s,8-this.bit);if(t=t*2**n+(this.bytes[this.pos]>>>8-this.bit-n&2**n-1),this.bit+=n,s-=n,this.bit===8)this.bit=0,this.pos++}return t}peek15(){let e=this.pos,t=this.bit,s=this.read(15);return this.pos=e,this.bit=t,s}align(){if(this.bit!==0)this.pos++,this.bit=0}byte(){if(this.bit!==0)od("unaligned compressed data");if(this.pos>=this.bytes.byteLength-16)od("truncated compressed data");return this.bytes[this.pos++]}atBlockEnd(){return this.pos>this.blockEnd||this.pos===this.blockEnd&&this.bit>=this.blockEndBit}}class oM{#e;#t;#s;#n;#o;#r;#a=!1;constructor(e,t=15){this.#t=e,this.#e=t,this.#s=new Int32Array(t+1),this.#n=new Int32Array(t+1),this.#o=new Int32Array(t+1),this.#r=new Int32Array(e)}build(e,t=0){this.#s.fill(0);for(let r=0;r<this.#t;r++){let i=e[t+r];if(i>this.#e)od("invalid Huffman code length");if(i!==0)this.#s[i]++}let s=0,n=0;for(let r=1;r<=this.#e;r++)s=s+this.#s[r-1]<<1,this.#n[r]=s,this.#o[r]=n,n+=this.#s[r];if(n!==0&&s+this.#s[this.#e]!==1<<this.#e)od("incomplete Huffman table");let o=this.#o.slice();for(let r=0;r<this.#t;r++){let i=e[t+r];if(i!==0)this.#r[o[i]++]=r}this.#a=n!==0}decode(e){if(!this.#a)od("empty Huffman table");let t=0;for(let s=1;s<=this.#e;s++){t=t<<1|e.read(1);let n=t-this.#n[s];if(n>=0&&n<this.#s[s])return this.#r[this.#o[s]+n]}od("invalid Huffman symbol")}}class sTt{#e=new Uint8Array(0);#t=[4294967295,4294967295,4294967295,4294967295];#s=0;#n=new oM(nM);#o=new oM(bW);#r=new oM(dae);#a=new oM(tTt);#i=!1;reset(){this.#e=new Uint8Array(0),this.#t=[4294967295,4294967295,4294967295,4294967295],this.#s=0,this.#n=new oM(nM),this.#o=new oM(bW),this.#r=new oM(dae),this.#a=new oM(tTt),this.#i=!1}decode(e,t,s,n,o){if(o!==0&&o!==1)throw new j(`Unsupported RAR5 compression algorithm version ${o}`);if(!n)this.reset();if(!Number.isSafeInteger(s)||s<131072)od("invalid dictionary size");let r=this.#e.byteLength>s?this.#e.subarray(this.#e.byteLength-s):this.#e,i=new Uint8Array(r.byteLength+t+J2r);i.set(r);let a=r.byteLength,l=a,u=l+t,p=[],c=new bzs(e),d=this.#n,f=this.#o,m=this.#r,g=this.#a,h=!1,T=()=>{c.align();let C=c.byte(),b=C^c.byte(),w=C>>>3&3;if(w===3)od("invalid compressed block header");let E=c.byte();b^=E;for(let F=0;F<w;F++){let _=c.byte();b^=_,E+=_*2**(8*(F+1))}if(b!==90)od("compressed block checksum mismatch");let x=(C&7)+1;if(E+=x>>>3,E===0)od("empty compressed block");if(E--,x&=7,c.blockEnd=c.pos+E,c.blockEndBit=x,h=(C&64)!==0,(C&128)===0)return;let A=new Uint8Array(20);for(let F=0;F<20;){let _=c.read(4);if(_===15){let D=c.read(4);if(D!==0){F=Math.min(20,F+D+2);continue}}A[F++]=_}let M=new oM(20);M.build(A);let I=o===1?eTt:eTt-16,O=new Uint8Array(I);for(let F=0;F<I;){let _=M.decode(c);if(_<16){O[F++]=_;continue}let D=(_-16&1)*4;D+=D+3+c.read(D+3);let L=_<18?F===0?od("invalid Huffman repeat"):O[F-1]:0,N=Math.min(I,F+D);O.fill(L,F,N),F=N}let P=new Uint8Array(eTt);if(o===0)P.set(O.subarray(0,nM+64)),P.set(O.subarray(nM+64),nM+bW);else P.set(O);d.build(P),f.build(P,nM),m.build(P,nM+bW),g.build(P,nM+bW+dae),this.#i=!1;for(let F=0;F<dae;F++)if(P[nM+bW+F]!==4)this.#i=!0};T();while(a<u){if(c.atBlockEnd()){if(c.pos>c.blockEnd||c.pos===c.blockEnd&&c.bit>c.blockEndBit)od("compressed block overread");if(c.align(),h)break;T();continue}let C=d.decode(c);if(C<256){i[a++]=C;continue}if(C===256){let E=(c.read(2)+1)*8,x=0;for(let P=0;P<E;P+=8)x+=c.read(8)*2**P;let A=(c.read(2)+1)*8,M=0;for(let P=0;P<A;P+=8)M+=c.read(8)*2**P;let I=c.read(3),O=I===0?c.read(5)+1:0;if(I>3)throw new j(`Unsupported RAR5 filter type ${I}`);if(M>X2r||a-l+x+M>t)od("invalid filter range");p.push({type:I,channels:O,start:a-l+x,size:M});continue}let b,w=this.#t[0];if(C<262){if(C>=258){let E=C-258;w=this.#t[E];for(let A=E;A>0;A--)this.#t[A]=this.#t[A-1];this.#t[0]=w;let x=g.decode(c);b=x>=8?yzs(c,x):x,b+=2,this.#s=b}else if(b=this.#s,b===0)continue}else{this.#t[3]=this.#t[2],this.#t[2]=this.#t[1],this.#t[1]=this.#t[0];let E=C-262;b=E>=8?yzs(c,E):E,b+=2;let x=f.decode(c);if(x>=4){let A=x-2>>>1;if(x=(2|x&1)*2**A,A<4)x+=c.read(A);else if(b+=Y2r[A]??3,this.#i)x+=c.read(A-4)*16+m.decode(c);else x+=c.read(A)}w=x+1,this.#t[0]=w,this.#s=b}if(w<=0||w>s||w>a)od("invalid LZ distance");if(a+b>i.byteLength)od("invalid LZ match length");for(let E=0;E<b;E++)i[a+E]=i[a+E-w];a+=b}if(a!==u)od(`decompressed size mismatch (${a-l} != ${t})`);let y=i.slice(l,u);Q2r(y,p);let R=Math.max(0,u-s);return this.#e=i.slice(R,u),y}}function yzs(e,t){let s=(t>>>2)-1;return((4|t&3)<<s)+e.read(s)}function Q2r(e,t){for(let s of t){let n=e.subarray(s.start,s.start+s.size);if(s.type===0){let o=n.slice(),r=0;for(let i=0;i<s.channels;i++){let a=0;for(let l=i;l<n.byteLength;l+=s.channels)a=a-o[r++]&255,n[l]=a}}else if(s.type===1||s.type===2)for(let r=0;r+4<n.byteLength;){let i=n[r++];if(i!==232&&(s.type===1||i!==233))continue;let a=s.start+r&16777215,l=Rzs(n,r);if(l>>>0<16777216)l-=a;else if(l>>>0>=-a>>>0)l+=16777216;else{r+=4;continue}Czs(n,r,l),r+=4}else for(let o=0;o+3<n.byteLength;o+=4){if(n[o+3]!==235)continue;let r=Rzs(n,o),i=(r&4278190080|r-(s.start+o>>2)&16777215)>>>0;Czs(n,o,i)}}}function Rzs(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function Czs(e,t,s){e[t]=s,e[t+1]=s>>>8,e[t+2]=s>>>16,e[t+3]=s>>>24}function od(e){throw new j(`Invalid RAR5 archive: ${e}`)}var nM=306,bW=80,dae=16,tTt=44,eTt,Y2r,J2r=4100,X2r=4194304;var kzs=S(()=>{Ur();eTt=nM+bW+dae+tTt,Y2r=[0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]});class Ezs{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async read(e,t){return this.#e.read(this.#t,e,t)}}class Mzs{#e;#t;#s;#n=new Map;#o=Promise.resolve();constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s.limits}member(e){return new Ezs(this,e)}async read(e,t,s){let n=this.#o.then(async()=>{if(!this.#n.has(e))await this.#r(e)});this.#o=n.catch(()=>{return}),await n;let o=this.#n.get(e);if(!o)throw new j(`Failed to extract RAR member '${s}'`);if(o.byteLength!==t)throw new j(`RAR member '${s}' size mismatch (${o.byteLength} != ${t})`);return o.slice()}async#r(e){let t=this.#t[e];if(!t)throw new j("Invalid RAR member index");let s=e;if(t.solid)while(s>0&&this.#t[s].solid&&this.#t[s-1].format===t.format)s--;let n=new Zht,o=new sTt;for(let r=s;r<=e;r++){let i=this.#t[r];if(i.isDirectory)continue;if(Qi(i.unpackedSize,i.path,this.#s),i.method===0&&i.packedSize!==i.unpackedSize)uu("stored member size mismatch");if(i.method>5)throw new j(i.format===4?`Unsupported RAR4 compression method 0x${(i.method+48).toString(16)} for '${i.path}'`:`Unsupported RAR5 compression method ${i.method} for '${i.path}'`);if(i.method!==0)ci(i.packedSize+2*i.unpackedSize+2*i.dictionarySize+8192,this.#s);let a=PC(i.dataStart,i.packedSize,this.#e.size,"member data"),l=await this.#e.read(i.dataStart,a),u;if(i.method===0){if(u=l,i.solid)if(i.format===4)n.reset();else o.reset()}else if(i.format===5)u=o.decode(l,i.unpackedSize,i.dictionarySize,i.solid,i.version);else u=n.decode(l,i.unpackedSize,i.dictionarySize,i.solid,i.version);if(u.byteLength!==i.unpackedSize)uu(`member '${i.path}' size mismatch`);if(i.crc!==void 0&&Wi(u)!==i.crc)throw new j(`RAR member '${i.path}' CRC32 mismatch`);this.#n.set(r,u.slice())}}}function Azs(e){return nTt(e)!==void 0}async function Z2r(e,t){let s=Math.min(e.size,kW.byteLength),n=await e.read(0,s),o=nTt(n);while(!o&&s<Math.min(e.size,1048576+kW.byteLength)){let l=Math.min(e.size,1048576+kW.byteLength,Math.max(65536,s*2));Hn(l,t.limits,"RAR signature scan");let u=await e.read(s,l),p=new Uint8Array(l);p.set(n),p.set(u,s),n=p,s=l,o=nTt(n)}if(!o)throw new j("Invalid RAR archive: signature not found");let r=[{start:0,bytes:n}],i=n.byteLength;Hn(i,t.limits,"RAR metadata");let a=o.offset+(o.version===5?kW.byteLength:oTt.byteLength);while(a<e.size)if(o.version===5){if(a+5>e.size)uu("truncated RAR5 header");let l=await e.read(a,Math.min(e.size,a+16)),u={offset:4},p=Ba(l,u,l.byteLength,"header size");if(p>2097152)uu("RAR5 header exceeds format limit");let c=PC(a,u.offset+p,e.size,"RAR5 header");Hn(i+c-a,t.limits,"RAR metadata");let d=await e.read(a,c);r.push({start:a,bytes:d}),i+=d.byteLength,Hn(i,t.limits,"RAR metadata");let f={offset:u.offset},m=Ba(d,f,d.byteLength,"header type"),g=Ba(d,f,d.byteLength,"header flags");if((g&1)!==0)Ba(d,f,d.byteLength,"extra area size");let h=(g&2)!==0?Ba(d,f,d.byteLength,"data size"):0;if(a=PC(c,h,e.size,"RAR5 data area"),m===4||m===5)break}else{if(a+7>e.size)uu("truncated RAR4 base header");let l=await e.read(a,Math.min(e.size,a+11)),u=l[2],p=xn(l,3),c=xn(l,5);if(c<7)uu("invalid RAR4 header size");let d=PC(a,c,e.size,"RAR4 header");Hn(i+d-a,t.limits,"RAR metadata");let f=await e.read(a,d);r.push({start:a,bytes:f}),i+=f.byteLength,Hn(i,t.limits,"RAR metadata");let m=(p&32768)!==0?Es(f,7):0,g=PC(d,m,e.size,"RAR4 data area");if(u===116&&m<=t.limits.maxPathBytes){let h=(p&32768)!==0?11:7;if(h+21<=f.byteLength){let T=f[h+4],y=Es(f,h+17);if(T===3&&(y&61440)===40960)Hn(i+m,t.limits,"RAR metadata"),r.push({start:d,bytes:await e.read(d,g)}),i+=m,Hn(i,t.limits,"RAR metadata")}}if(a=g,u===123||u===115&&(p&128)!==0)break}return r.sort((l,u)=>l.start-u.start||u.bytes.byteLength-l.bytes.byteLength),{marker:o,segments:r}}function eGr(e,t){let s=(r,i)=>{let a=0,l=t.length;while(a<l){let u=a+l>>>1;if(t[u].start<=r)a=u+1;else l=u}for(let u=a-1;u>=0;u--){let p=t[u];if(r>=p.start&&i<=p.start+p.bytes.byteLength)return p}uu("RAR parser accessed member payload while indexing")},n=Object.create(null);return new Proxy(n,{get(r,i){if(i==="byteLength"||i==="length")return e;if(i==="subarray")return(a,l=e)=>{let u=s(a,l);return u.bytes.subarray(a-u.start,l-u.start)};if(typeof i==="string"){let a=Number(i);if(Number.isSafeInteger(a)&&a>=0){let l=s(a,a+1);return l.bytes[a-l.start]}}return}})}function tGr(e,t,s){let n=[],o=t+kW.byteLength,r=!1;while(o<e.byteLength){if(o+5>e.byteLength)uu("truncated RAR5 header");let i=Es(e,o),a=o+4,l={offset:a},u=Ba(e,l,e.byteLength,"header size");if(u>2097152)uu("RAR5 header exceeds format limit");Hn(u,s.limits,"RAR5 header");let p=l.offset,c=PC(p,u,e.byteLength,"RAR5 header");if(Wi(e.subarray(a,c))!==i)uu("RAR5 header CRC32 mismatch");let d={offset:p},f=Ba(e,d,c,"header type"),m=Ba(e,d,c,"header flags"),g=(m&1)!==0?Ba(e,d,c,"extra area size"):0,h=(m&2)!==0?Ba(e,d,c,"data size"):0;if((m&24)!==0)throw new j("Unsupported multi-volume RAR5 archive");let T=c,y=PC(T,h,e.byteLength,"RAR5 data area");if(g>c-d.offset)uu("invalid RAR5 extra area size");let R=c-g;if(f===4)throw new j("Encrypted RAR5 headers are not supported");if(f===1){let C=Ba(e,d,R,"archive flags");if((C&1)!==0)throw new j("Unsupported multi-volume RAR5 archive");if((C&8)!==0)throw new j("Unsupported RAR5 recovery record");if((C&2)!==0)Ba(e,d,R,"volume number");r=!0}else if(f===2||f===3){let C=Ba(e,d,R,"file flags"),b=Ba(e,d,R,"unpacked size");if((C&8)!==0)throw new j("RAR5 member with unknown unpacked size is not supported");let w=Ba(e,d,R,"file attributes"),E;if((C&2)!==0)Jm(d.offset,4,R,"RAR5 modification time"),E=Es(e,d.offset)*1000,d.offset+=4;let x;if((C&4)!==0)Jm(d.offset,4,R,"RAR5 data CRC32"),x=Es(e,d.offset),d.offset+=4;let A=Ba(e,d,R,"compression information"),M=A&63;if(M===1&&(A&1048576)!==0)M=0;let I=(A&64)!==0,O=A>>>7&7,F=131072*2**(A>>>10&31);if((A&63)===1)F+=F*(A>>>15&31)/32;if(!Number.isSafeInteger(F)||F>s.limits.maxInMemorySize)throw new j(`RAR5 dictionary is too large (${F} bytes)`);let _=Ba(e,d,R,"host OS"),D=Ba(e,d,R,"file name size");ko(D,"member path",s.limits.maxPathBytes),Jm(d.offset,D,R,"RAR5 file name");let L;try{L=Szs.decode(e.subarray(d.offset,d.offset+D))}catch{throw new j("Invalid RAR5 UTF-8 member name")}d.offset+=D;let N;for(let H of nGr(e,R,c)){let q={offset:H.start};if(H.type===1)throw new j(`Encrypted RAR5 member '${L}' is not supported`);if(H.type===3){let z=Ba(e,q,H.end,"time flags");if((z&2)!==0)if((z&1)!==0)Jm(q.offset,4,H.end,"Unix modification time"),E=Es(e,q.offset)*1000;else Jm(q.offset,8,H.end,"Windows modification time"),E=iGr(e,q.offset)}else if(H.type===5){let z=Ba(e,q,H.end,"redirection type");Ba(e,q,H.end,"redirection flags");let J=Ba(e,q,H.end,"link target size");if(ko(J,"link target",s.limits.maxPathBytes),Jm(q.offset,J,H.end,"link target"),z<1||z>5)throw new j(`Unsupported RAR5 redirection type ${z}`);try{N=Szs.decode(e.subarray(q.offset,q.offset+J))}catch{throw new j("Invalid RAR5 UTF-8 link target")}}}if(f===2){Qi(b,L,s.limits);let H=Sr(L);if(H){let q;if(N!==void 0){let J=Izs(H,N);N=J.target,q=J.resolveTarget}let z=(C&1)!==0;n.push({format:5,path:H,dataStart:T,packedSize:h,unpackedSize:b,method:O,version:M,dictionarySize:F,solid:I,crc:x,isDirectory:z,mtimeMs:E,mode:_===1?w:void 0,linkTarget:N,linkResolveTarget:q}),or(n.length,s.limits)}}else if(L==="RR")throw new j("Unsupported RAR5 recovery record")}else if(f===5){if((Ba(e,d,R,"end flags")&1)!==0)throw new j("Unsupported multi-volume RAR5 archive");break}else if((m&4)===0)throw new j(`Unsupported RAR5 header type ${f}`);o=y}if(!r)uu("RAR5 main header is missing");return n}function sGr(e,t,s){let n=[],o=t+oTt.byteLength,r=!1;while(o<e.byteLength){Jm(o,7,e.byteLength,"RAR4 base header");let i=xn(e,o),a=e[o+2],l=xn(e,o+3),u=xn(e,o+5);if(u<7)uu("invalid RAR4 header size");Hn(u,s.limits,"RAR4 header");let p=PC(o,u,e.byteLength,"RAR4 header");if((Wi(e.subarray(o+2,p))&65535)!==i)uu("RAR4 header CRC mismatch");let c=0,d=o+7;if((l&32768)!==0)Jm(d,4,p,"RAR4 additional size"),c=Es(e,d),d+=4;let f=p,m=PC(f,c,e.byteLength,"RAR4 data area");if(a===115){if((l&1)!==0)throw new j("Unsupported multi-volume RAR4 archive");if((l&64)!==0)throw new j("Unsupported RAR4 recovery record");if((l&128)!==0)throw new j("Encrypted RAR4 headers are not supported");r=!0}else if(a===116){Jm(d,21,p,"RAR4 file header");let g=Es(e,d);d+=4;let h=e[d++],T=Es(e,d);d+=4;let y=Es(e,d);d+=4;let R=e[d++],C=e[d++],b=xn(e,d);d+=2;let w=Es(e,d);d+=4;let E=c,x=g;if((l&256)!==0)Jm(d,8,p,"RAR4 high sizes"),E+=Es(e,d)*4294967296,d+=4,x+=Es(e,d)*4294967296,d+=4,m=PC(f,E,e.byteLength,"RAR4 file data");if((l&3)!==0)throw new j("Unsupported multi-volume RAR4 member");if((l&4)!==0)throw new j("Encrypted RAR4 file data is not supported");if(C<48||C>53)throw new j(`Unsupported RAR4 compression method 0x${C.toString(16)}`);ko(b,"member path",s.limits.maxPathBytes),Jm(d,b,p,"RAR4 file name");let A=e.subarray(d,d+b),M=(l&512)!==0?oGr(A):yFe.decode(A);if(d+=b,(l&1024)!==0)Jm(d,8,p,"RAR4 salt"),d+=8;let I=xzs(y);if((l&4096)!==0){Jm(d,2,p,"RAR4 extended time flags");let P=xn(e,d);d+=2;for(let F=0;F<4;F++){let _=P>>>(3-F)*4&15;if((_&8)===0)continue;let D=y;if(F!==0)Jm(d,4,p,"RAR4 extended time"),D=Es(e,d),d+=4;let L=xzs(D)+((_&4)!==0?1000:0),N=0,H=_&3;Jm(d,H,p,"RAR4 extended time precision");for(let q=0;q<H;q++)N|=e[d++]<<(q+3-H)*8;if(L+=N/1e4,F===0)I=L}}Qi(x,M,s.limits);let O=Sr(M);if(O){let P=(l>>>5&7)===7,F=h===3?w:void 0,_,D;if(F!==void 0&&(F&61440)===40960){if(C!==48||E!==x)throw new j(`Unsupported compressed RAR4 symlink '${O}'`);ko(E,"link target",s.limits.maxPathBytes);let L=Izs(O,yFe.decode(e.subarray(f,m)));_=L.target,D=L.resolveTarget}n.push({format:4,path:O,dataStart:f,packedSize:E,unpackedSize:x,method:C-48,version:R,dictionarySize:rGr(l),solid:(l&16)!==0,crc:T,isDirectory:P,mtimeMs:I,mode:F,linkTarget:_,linkResolveTarget:D}),or(n.length,s.limits)}}else if(a===120)throw new j("Unsupported RAR4 recovery record");else if(a===123){if((l&1)!==0)throw new j("Unsupported multi-volume RAR4 archive");break}o=m}if(!r)uu("RAR4 main header is missing");return n}function nGr(e,t,s){let n=[],o={offset:t};while(o.offset<s){let r=Ba(e,o,s,"extra record size"),i=o.offset,a=PC(i,r,s,"extra record"),l=Ba(e,o,a,"extra record type");n.push({type:l,start:o.offset,end:a}),o.offset=a}return n}function Ba(e,t,s,n){let o=0,r=1;for(let i=0;i<10;i++){if(t.offset>=s)uu(`truncated ${n}`);let a=e[t.offset++];if(o+=(a&127)*r,!Number.isSafeInteger(o))uu(`${n} is too large`);if((a&128)===0)return o;r*=128}uu(`${n} vint is too long`)}function nTt(e){let t=Math.min(e.byteLength,1048576+kW.byteLength);for(let s=0;s<t;s++){if(wzs(e,s,kW))return{version:5,offset:s};if(wzs(e,s,oTt))return{version:4,offset:s}}return}function wzs(e,t,s){if(t+s.byteLength>e.byteLength)return!1;for(let n=0;n<s.byteLength;n++)if(e[t+n]!==s[n])return!1;return!0}function oGr(e){let t=e.indexOf(0);if(t<0)return yFe.decode(e);if(++t>=e.byteLength)return yFe.decode(e.subarray(0,t-1));let s=e[t++],n=0,o=0,r=0,i="";while(t<e.byteLength){if(r===0){if(o=e[t++],r=8,t>=e.byteLength)break}let a=o>>>6;if(a===0)i+=String.fromCharCode(e[t++]),n++;else if(a===1)i+=String.fromCharCode(e[t++]+(s<<8)),n++;else if(a===2){if(t+1>=e.byteLength)uu("truncated RAR4 Unicode name");i+=String.fromCharCode(e[t]|e[t+1]<<8),t+=2,n++}else{let l=e[t++];if((l&128)!==0){if(t>=e.byteLength)uu("truncated RAR4 Unicode name correction");let u=e[t++];l=(l&127)+2;for(;l>0&&n<e.byteLength;l--,n++)i+=String.fromCharCode(s<<8|e[n]+u&255)}else{l+=2;for(;l>0&&n<e.byteLength;l--,n++)i+=String.fromCharCode(e[n])}}o=o<<2&255,r-=2}return i}function Izs(e,t){let s=t.replace(/\\/g,"/");if(s.startsWith("/"))return{target:s,resolveTarget:!1};let n=e.split("/");n.pop();for(let o of s.split("/")){if(!o||o===".")continue;if(o===".."){if(n.length===0)return{target:s,resolveTarget:!1};n.pop()}else n.push(o)}return{target:n.join("/"),resolveTarget:!0}}function rGr(e){let t=e>>>5&7;return t===7?4194304:65536*2**t}function xzs(e){let t=(e&31)*2,s=e>>>5&63,n=e>>>11&31,o=e>>>16&31,r=e>>>21&15,i=(e>>>25&127)+1980;return new Date(i,r-1,o,n,s,t).getTime()}function iGr(e,t){return(Es(e,t)+Es(e,t+4)*4294967296)/1e4-11644473600000}function PC(e,t,s,n){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||t<0)uu(`invalid ${n} range`);let o=e+t;if(!Number.isSafeInteger(o)||o<e||o>s)uu(`truncated ${n}`);return o}function Jm(e,t,s,n){PC(e,t,s,n)}function uu(e){throw new j(`Invalid RAR archive: ${e}`)}var oTt,kW,Szs,yFe,vzs=async(e,t)=>{if(!Number.isSafeInteger(e.size)||e.size<0)throw new j("Archive is too large to read safely");let s=await Z2r(e,t),n=eGr(e.size,s.segments),o=s.marker,r=o.version===5?tGr(n,o.offset,t):sGr(n,o.offset,t),i=new Mzs(e,r,t),a=[];for(let l=0;l<r.length;l++){let u=r[l],p={path:u.path,isDirectory:u.isDirectory,size:u.unpackedSize};if(u.mtimeMs!==void 0)p.mtimeMs=u.mtimeMs;if(u.mode!==void 0)p.mode=u.mode;if(u.linkTarget!==void 0)p.storage={type:"link",targetPath:u.linkTarget,resolveTarget:u.linkResolveTarget??!1};else if(!u.isDirectory)p.storage={type:"member",source:i.member(l)};a.push(p)}return a};var Ozs=S(()=>{Sh();m0();Ur();vp();Vd();Tzs();kzs();oTt=Uint8Array.of(82,97,114,33,26,7,0),kW=Uint8Array.of(82,97,114,33,26,7,1,0),Szs=new TextDecoder("utf-8",{fatal:!0}),yFe=new TextDecoder("windows-1252")});function pGr(e,t){let s=e%t;return s===0?e:e+t-s}async function fae(e,t,s,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<t||s>e.size)throw new j(`Invalid RPM package: truncated ${n}`);let o=await e.read(t,s);if(o.byteLength!==s-t)throw new j(`Invalid RPM package: truncated ${n}`);return o}function Nzs(e,t,s){if(e.byteLength!==SW||kh(e,0)!==aGr)throw new j(`Invalid RPM package: corrupt ${s} header magic`);for(let a=4;a<8;a++)if(e[a]!==0)throw new j(`Invalid RPM package: corrupt ${s} header reserved bytes`);let n=kh(e,8),o=kh(e,12);or(n,t.limits);let i=n*mae+o;if(!Number.isSafeInteger(i))throw new j(`Invalid RPM package: ${s} header is too large`);return Hn(SW+i,t.limits,`RPM ${s} header`),{indexCount:n,dataSize:o,bodySize:i,totalSize:SW+i}}function Uzs(e,t,s){let n=t.indexCount*mae;if(e.byteLength!==t.bodySize)throw new j(`Invalid RPM package: truncated ${s} header`);for(let o=0;o<t.indexCount;o++){let r=o*mae,i=kh(e,r),a=kh(e,r+4),l=kh(e,r+8),u=kh(e,r+12);if(l>t.dataSize)throw new j(`Invalid RPM package: tag ${i} points outside header data`);let p=t.dataSize-l,c=0;if(a===1||a===2||a===7)c=1;else if(a===3)c=2;else if(a===4)c=4;else if(a===5)c=8;else if(a===0){if(u!==0)throw new j(`Invalid RPM package: null tag ${i} has values`);continue}else if(a===CFe||a===8||a===9){let d=a===CFe?1:u;if(a===CFe&&u!==1)throw new j(`Invalid RPM package: string tag ${i} has an invalid count`);if(d>p)throw new j(`Invalid RPM package: string tag ${i} exceeds header data`);let f=n+l,m=n+t.dataSize;for(let g=0;g<d;g++){while(f<m&&e[f]!==0)f++;if(f===m)throw new j(`Invalid RPM package: string tag ${i} is not NUL-terminated`);f++}continue}else throw new j(`Invalid RPM package: tag ${i} uses unknown data type ${a}`);if(l%c!==0)throw new j(`Invalid RPM package: tag ${i} data is misaligned`);if(u*c>p)throw new j(`Invalid RPM package: tag ${i} exceeds header data`)}}function cGr(e,t,s,n,o,r,i){if(r!==CFe||o!==1)throw new j(`Invalid RPM package: tag ${i} must contain one string`);let a=t+n,l=t+s,u=a;while(u<l&&e[u]!==0)u++;if(u===l)throw new j(`Invalid RPM package: tag ${i} string is not NUL-terminated`);if(u-a>4096)throw new j(`Invalid RPM package: tag ${i} string is too large`);try{return uGr.decode(e.subarray(a,u))}catch{throw new j(`Invalid RPM package: tag ${i} is not valid UTF-8`)}}function dGr(e,t){Uzs(e,t,"main");let s=t.indexCount*mae;if(e.byteLength!==t.bodySize)throw new j("Invalid RPM package: truncated main header");let n={};for(let o=0;o<t.indexCount;o++){let r=o*mae,i=kh(e,r),a=kh(e,r+4),l=kh(e,r+8),u=kh(e,r+12);if(l>t.dataSize)throw new j(`Invalid RPM package: tag ${i} points outside header data`);if(i!==Pzs&&i!==Fzs&&i!==_zs&&i!==Lzs&&i!==Dzs)continue;let p=cGr(e,s,t.dataSize,l,u,a,i);switch(i){case Pzs:n.name=p;break;case Fzs:n.version=p;break;case _zs:n.payloadFormat=p;break;case Lzs:n.payloadCompressor=p;break;case Dzs:n.payloadFlags=p;break}}return n}function fGr(e,t){if(e.name&&e.version)return`${e.name}-${e.version}`;return e.name??t}function qzs(e){if(e.byteLength<13||e[0]>224)return!1;let t=(e[1]|e[2]<<8|e[3]<<16|e[4]<<24)>>>0;if(t<4096)return!1;let s=2**Math.ceil(Math.log2(t));return t===s||t===s-s/4}async function mGr(e,t,s,n){let r=t.payloadCompressor?.trim().toLowerCase();if(!r||!["gzip","gz","bzip2","bzip","xz","lzma","zstd","zstdio","none"].includes(r))if(GPe(e))r="gzip";else if(BPe(e))r="bzip2";else if(JPe(e))r="xz";else if(QPe(e))r="zstd";else if(qzs(e))r="lzma";else if(rae(e))r="none";else throw new j(`RPM package '${s}' uses unsupported payload compressor '${t.payloadCompressor??"unknown"}'`);switch(r){case"gzip":case"gz":return hW(e,n);case"bzip2":case"bzip":return T0(e,n);case"xz":return y0(e,n);case"zstd":case"zstdio":return R0(e,n);case"lzma":if(!qzs(e))throw new j(`RPM package '${s}' has a malformed LZMA payload`);return p6(e,n);case"none":if(!rae(e))throw new j(`RPM package '${s}' has an invalid uncompressed CPIO payload`);return e;default:throw new j(`RPM package '${s}' uses unsupported payload compressor '${r}'`)}}async function gGr(e,t){let s=await fae(e,0,RFe+SW,"lead and signature header");if(!rTt(s))throw new j("Invalid RPM package: bad lead magic");let n=s[4],o=s[6]<<8|s[7];if(n<3||o>1)throw new j("Unsupported RPM package lead version or type");let r=s[78]<<8|s[79];if(r!==lGr)throw new j(`Unsupported RPM signature type ${r}; only header signatures are supported`);let i=s.subarray(10,76).indexOf(0),a=s.subarray(10,i<0?76:10+i),l="unknown package";try{let E=new TextDecoder("utf-8",{fatal:!0}).decode(a);if(E)l=E}catch{}let u=Nzs(s.subarray(RFe),t,"signature"),p=RFe+u.totalSize,c=pGr(p,8),d=await fae(e,RFe+SW,c,"signature header");if(d.byteLength<u.bodySize)throw new j("Invalid RPM package: truncated signature header");Uzs(d.subarray(0,u.bodySize),u,"signature");for(let E=u.bodySize;E<d.byteLength;E++)if(d[E]!==0)throw new j("Invalid RPM package: non-zero signature alignment padding");let f=await fae(e,c,c+SW,"main header intro"),m=Nzs(f,t,"main");Hn(u.totalSize+m.totalSize,t.limits,"RPM headers");let g=c+SW,h=await fae(e,g,g+m.bodySize,"main header"),T=dGr(h,m),y=fGr(T,l);if(T.payloadFormat&&T.payloadFormat.toLowerCase()!=="cpio")throw new j(`RPM package '${y}' uses unsupported payload format '${T.payloadFormat}'`);let R=c+m.totalSize,C=e.size-R;ci(C,t.limits);let b=await fae(e,R,e.size,"payload"),w=await mGr(b,T,y,t.limits.maxInMemorySize);return ci(w.byteLength,t.limits),_ht(w,t)}function rTt(e){return e.byteLength>=4&&e[0]===237&&e[1]===171&&e[2]===238&&e[3]===219}var RFe=96,SW=16,mae=16,aGr=2393761793,lGr=5,Pzs=1000,Fzs=1001,_zs=1124,Lzs=1125,Dzs=1126,CFe=6,uGr,Hzs=async(e,t)=>{try{return await gGr(e,t)}catch(s){if(s instanceof j)throw s;throw new j(s instanceof Error?s.message:String(s))}};var Bzs=S(()=>{Sh();tae();sae();TW();oae();c6();Lht();Ur();vp();uGr=new TextDecoder("utf-8",{fatal:!0})});function Wzs(e){switch(e){case 0n:return"Copy";case 3n:return"Delta";case 0x21n:return"LZMA2";case 0x30101n:return"LZMA";case 0x30401n:return"PPMd";case 0x3030103n:return"BCJ x86";case 0x303011bn:return"BCJ2";case 0x6f10701n:return"7zAES";case 0x40108n:return"Deflate";case 0x40109n:return"Deflate64";case 0x40202n:return"BZip2";case 0x3030205n:return"BCJ PowerPC";case 0x3030401n:return"BCJ IA64";case 0x3030501n:return"BCJ ARM";case 0x3030701n:return"BCJ ARM Thumb";case 0x3030805n:return"BCJ SPARC";case 0xan:return"BCJ ARM64";case 0xbn:return"BCJ RISC-V";default:return`method 0x${e.toString(16)}`}}function Gzs(e,t){if(t+4>e.byteLength)throw new j("Invalid 7z BCJ properties");return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function hGr(e,t){let s=new Uint8Array(256),n=0;for(let o=0;o<e.byteLength;o++){let r=e[o]+s[t+n&255]&255;s[n]=r,e[o]=r,n=n-1&255}}function TGr(e,t){let s=[0,1,2,2,3],n=0,o=4294967291;if(e.byteLength<5)return;let r=0,i=e.byteLength-5;while(r<=i){let a=e[r];if(a!==232&&a!==233){r++;continue}let l=t+r>>>0,u=l-o>>>0;if(o=l,u>5)n=0;else for(let p=0;p<u;p++)n=(n&119)<<1>>>0;if(a=e[r+4],(a===0||a===255)&&n>>>1<=4&&n>>>1!==3){let p=Gzs(e,r+1),c=0;for(;;){if(c=p-l-5>>>0,n===0)break;let d=s[n>>>1]*8,f=c>>>24-d&255;if(f!==0&&f!==255)break;let m=d===0?4294967295:2**(32-d)-1;p=(c^m)>>>0}e[r+4]=~((c>>>24&1)-1)&255,e[r+3]=c>>>16,e[r+2]=c>>>8,e[r+1]=c,r+=5,n=0}else if(r++,n|=1,a===0||a===255)n|=16}}class bFe{#e;#t;#s;#n;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}read(){return this.#n??=this.#o(),this.#n}async#o(){let e=this.#t;if(e.packedIndices.length!==1||e.packOffsets.length!==1||e.packSizes.length!==1){if(e.coders.find((a)=>a.id===0x303011bn))throw new j("Unsupported 7z coder BCJ2 (multi-input folder)");throw new j("Unsupported 7z folder graph with multiple packed input streams")}let t=e.packOffsets[0],s=e.packSizes[0];if(!Number.isSafeInteger(t)||!Number.isSafeInteger(s)||t<0||s<0||t+s>this.#e.size)throw new j("Invalid 7z packed-stream range");let n=await this.#e.read(t,t+s);if(e.packCrcs[0]!==void 0&&Wi(n)!==e.packCrcs[0])throw new j("Invalid 7z packed-stream CRC32 mismatch");let o=e.packedIndices[0],r=new Set;for(;;){let i=e.coders.findIndex((p)=>o>=p.inputStart&&o<p.inputStart+p.numInputs);if(i<0||r.has(i))throw new j("Invalid 7z folder binding graph");r.add(i);let a=e.coders[i];if(a.numInputs!==1||a.numOutputs!==1)throw new j(`Unsupported 7z coder ${Wzs(a.id)} stream topology`);let l=e.unpackSizes[a.outputStart];if(l===void 0)throw new j("Invalid 7z coder unpack size");switch(ci(l,this.#s),a.id){case 0n:if(a.properties.byteLength!==0||n.byteLength!==l)throw new j("Invalid 7z Copy coder size or properties");break;case 0x30101n:n=await nae(a.properties,n,l);break;case 0x21n:if(a.properties.byteLength!==1)throw new j("Invalid 7z LZMA2 coder properties");if(n=await KPe(a.properties[0],n,l),n.byteLength!==l)throw new j("7z LZMA2 coder output size mismatch");break;case 3n:if(a.properties.byteLength!==1||n.byteLength!==l)throw new j("Invalid 7z Delta coder properties or size");n=n.slice(),hGr(n,a.properties[0]+1);break;case 0x3030103n:{if(a.properties.byteLength!==0&&a.properties.byteLength!==4)throw new j("Invalid 7z BCJ x86 coder properties");if(n.byteLength!==l)throw new j("7z BCJ x86 coder output size mismatch");let p=a.properties.byteLength===4?Gzs(a.properties,0):0;n=n.slice(),TGr(n,p);break}case 0x30401n:throw new j("Unsupported 7z coder PPMd");case 0x6f10701n:throw new j("Encrypted 7z archives use unsupported coder 7zAES");default:throw new j(`Unsupported 7z coder ${Wzs(a.id)}`)}let u=e.bindPairs.find((p)=>p.output===a.outputStart);if(!u)break;o=u.input}if(r.size!==e.coders.length)throw new j("Unsupported 7z folder graph with disconnected coders");if(e.crc!==void 0&&Wi(n)!==e.crc)throw new j("Invalid 7z folder CRC32 mismatch");return n}}var jzs=S(()=>{m0();TW();Ur();vp()});class k0{bytes;pos=0;constructor(e){this.bytes=e}get remaining(){return this.bytes.byteLength-this.pos}readByte(){if(this.pos>=this.bytes.byteLength)throw new j("Invalid 7z header: truncated data");return this.bytes[this.pos++]}readBytes(e){if(!Number.isSafeInteger(e)||e<0||e>this.remaining)throw new j("Invalid 7z header: truncated or invalid-sized data");let t=this.bytes.subarray(this.pos,this.pos+e);return this.pos+=e,t}readUInt32(){let e=this.readBytes(4);return(e[0]|e[1]<<8|e[2]<<16|e[3]<<24)>>>0}readUInt64BigInt(){let e=this.readBytes(8),t=0n;for(let s=0;s<8;s++)t|=BigInt(e[s])<<BigInt(s*8);return t}readNumberBigInt(){let e=this.readByte(),t=0n,s=128;for(let n=0;n<8;n++){if((e&s)===0)return t|BigInt(e&s-1)<<BigInt(n*8);t|=BigInt(this.readByte())<<BigInt(n*8),s>>>=1}return t}readNumber(e="number"){let t=this.readNumberBigInt();if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new j(`7z ${e} is too large to read safely`);return Number(t)}skipSizedProperty(){this.readBytes(this.readNumber("property size"))}}function kFe(e,t){let s=Array(t),n=0,o=0;for(let r=0;r<t;r++){if(o===0)n=e.readByte(),o=128;s[r]=(n&o)!==0,o>>>=1}return s}function pTt(e,t){if(e.readByte()!==0)return Array(t).fill(!0);return kFe(e,t)}function cTt(e,t){let s=pTt(e,t),n=Array(t);for(let o=0;o<t;o++)if(s[o])n[o]=e.readUInt32();return{defined:s,values:n}}function aTt(e,t,s){let n=e.readNumber("property ID");if(n!==t)throw new j(`Invalid 7z header: expected ${s} ID 0x${t.toString(16)}, got 0x${n.toString(16)}`)}function bGr(e,t){let s=e.readNumber("folder coder count");if(s===0||s>t.limits.maxEntries)throw new j("Invalid 7z folder coder count");let n=[],o=0,r=0;for(let d=0;d<s;d++){let f=e.readByte();if((f&192)!==0)throw new j("Unsupported 7z coder alternatives or reserved flags");let m=f&15;if(m===0||m>8)throw new j("Invalid 7z coder method ID size");let g=0n;for(let b of e.readBytes(m))g=g<<8n|BigInt(b);let h=(f&16)!==0,T=h?e.readNumber("coder input count"):1,y=h?e.readNumber("coder output count"):1;if(T===0||y===0||o+T>t.limits.maxEntries||r+y>t.limits.maxEntries)throw new j("Invalid or excessive 7z coder stream count");let R=(f&32)!==0?e.readNumber("coder properties size"):0;Hn(R,t.limits,"coder properties");let C=e.readBytes(R).slice();n.push({id:g,properties:C,inputStart:o,outputStart:r,numInputs:T,numOutputs:y}),o+=T,r+=y}let i=r-1;if(i<0||i>o)throw new j("Invalid 7z folder bind-pair count");let a=[],l=new Set,u=new Set;for(let d=0;d<i;d++){let f=e.readNumber("bind input index"),m=e.readNumber("bind output index");if(f>=o||m>=r||l.has(f)||u.has(m))throw new j("Invalid 7z folder bind pair");l.add(f),u.add(m),a.push({input:f,output:m})}let p=o-i,c=[];if(p===1){for(let d=0;d<o;d++)if(!l.has(d))c.push(d)}else for(let d=0;d<p;d++){let f=e.readNumber("packed stream index");if(f>=o||l.has(f))throw new j("Invalid 7z packed stream index");l.add(f),c.push(f)}if(c.length!==p)throw new j("Invalid 7z folder packed-stream map");return{coders:n,bindPairs:a,packedIndices:c,unpackSizes:[],packOffsets:[],packSizes:[],packCrcs:[]}}function dTt(e){let t=new Set(e.bindPairs.map((o)=>o.output)),n=e.coders.flatMap((o)=>Array.from({length:o.numOutputs},(r,i)=>o.outputStart+i)).filter((o)=>!t.has(o));if(n.length!==1)throw new j("Unsupported 7z folder with multiple final output streams");return n[0]}function kGr(e,t,s){t.packPosition=e.readNumber("pack position");let n=e.readNumber("pack stream count");if(n>s.limits.maxEntries)throw new j("7z has too many packed streams");for(;;){let o=e.readNumber("PackInfo property ID");if(o===0)break;if(o===9){if(t.packSizes.length!==0)throw new j("Invalid duplicate 7z pack sizes");for(let r=0;r<n;r++)t.packSizes.push(e.readNumber("packed stream size"))}else if(o===10){if(t.packCrcs.length!==0)throw new j("Invalid duplicate 7z pack CRCs");t.packCrcs=cTt(e,n).values}else e.skipSizedProperty()}if(t.packSizes.length!==n)throw new j("Invalid 7z PackInfo without complete sizes");if(t.packCrcs.length===0)t.packCrcs=Array(n).fill(void 0)}function SGr(e,t,s){aTt(e,11,"Folder");let n=e.readNumber("folder count");if(n>s.limits.maxEntries)throw new j("7z has too many folders");if(e.readByte()!==0)throw new j("Unsupported 7z external folder definitions");for(let o=0;o<n;o++)t.folders.push(bGr(e,s));aTt(e,12,"CodersUnpackSize");for(let o of t.folders){let r=o.coders.reduce((i,a)=>i+a.numOutputs,0);for(let i=0;i<r;i++)o.unpackSizes.push(e.readNumber("coder unpack size"))}for(;;){let o=e.readNumber("UnpackInfo property ID");if(o===0)break;if(o===10){let r=cTt(e,n);for(let i=0;i<n;i++)t.folders[i].crc=r.values[i]}else e.skipSizedProperty()}}function wGr(e,t){let s=Array(t.folders.length).fill(1),n,o;for(;;){let a=e.readNumber("SubStreamsInfo property ID");if(a===0)break;if(a===13)for(let l=0;l<s.length;l++)s[l]=e.readNumber("folder substream count");else if(a===9){n=[];for(let l=0;l<t.folders.length;l++)for(let u=1;u<s[l];u++)n.push(e.readNumber("substream size"))}else if(a===10){let l=0;for(let u=0;u<s.length;u++)if(s[u]!==1||t.folders[u].crc===void 0)l+=s[u];o=cTt(e,l)}else e.skipSizedProperty()}let r=0,i=0;for(let a=0;a<t.folders.length;a++){let l=t.folders[a],u=s[a],p=0,c=l.unpackSizes[dTt(l)];for(let d=0;d<u;d++){let f=d+1===u?c-p:n?.[r++]??(()=>{throw new j("Invalid 7z SubStreamsInfo without sizes")})();if(f<0||p+f>c)throw new j("Invalid 7z substream size total");let m;if(u===1&&l.crc!==void 0)m=l.crc;else m=o?.values[i++];t.substreams.push({folderIndex:a,offset:p,size:f,crc:m}),p+=f}if(p!==c)throw new j("Invalid 7z substream sizes")}}function xGr(e,t){let s=32+e.packPosition,n=[];for(let r of e.packSizes){if(!Number.isSafeInteger(s)||s<0||r<0||s+r>t)throw new j("Invalid 7z packed-stream range");n.push(s),s+=r}let o=0;for(let r of e.folders)for(let i=0;i<r.packedIndices.length;i++){if(o>=e.packSizes.length)throw new j("Invalid 7z folder-to-pack-stream mapping");r.packOffsets.push(n[o]),r.packSizes.push(e.packSizes[o]),r.packCrcs.push(e.packCrcs[o]),o++}if(o!==e.packSizes.length)throw new j("Invalid unused 7z packed streams")}function lTt(e,t,s){let n={packPosition:0,packSizes:[],packCrcs:[],folders:[],substreams:[]};for(;;){let o=e.readNumber("StreamsInfo property ID");if(o===0)break;if(o===6)kGr(e,n,s);else if(o===7)SGr(e,n,s);else if(o===8)wGr(e,n);else throw new j(`Unsupported 7z StreamsInfo property ID 0x${o.toString(16)}`)}if(n.folders.length>0&&n.substreams.length===0)for(let o=0;o<n.folders.length;o++){let r=n.folders[o];n.substreams.push({folderIndex:o,offset:0,size:r.unpackSizes[dTt(r)],crc:r.crc})}return xGr(n,t),n}async function $zs(e,t,s){let n=[];for(let o of t.folders){let r=o.unpackSizes[dTt(o)];Hn(r,s.limits,"decoded header"),ci(r,s.limits),n.push(await new bFe(e,o,s.limits).read())}return n}function fTt(e,t){let s=e.readByte();if(s===0)return e;if(s!==1)throw new j("Invalid 7z external-property flag");let n=e.readNumber("external property stream index"),o=t[n];if(!o)throw new j("Invalid 7z external property stream index");return new k0(o)}function EGr(e,t,s,n){let o=fTt(e,s),r=[];for(let i=0;i<t;i++){let a=o.pos;while(o.remaining>=2&&(o.bytes[o.pos]!==0||o.bytes[o.pos+1]!==0))o.pos+=2;if(ko(o.pos-a,"encoded member path",n*2),o.remaining<2)throw new j("Invalid 7z UTF-16 file-name table");let l;try{l=yGr.decode(o.bytes.subarray(a,o.pos))}catch{throw new j("Invalid 7z UTF-16 file name")}o.pos+=2,Kd(l,"member path",n),r.push(l)}return r}function MGr(e,t,s){let n=pTt(e,t),o=fTt(e,s),r=Array(t);for(let i=0;i<t;i++)if(n[i]){let a=o.readUInt64BigInt(),l=Number(a/10000n)-CGr;if(Number.isFinite(l))r[i]=l}return r}function AGr(e,t,s){let n=pTt(e,t),o=fTt(e,s),r=Array(t);for(let i=0;i<t;i++)if(n[i])r[i]=o.readUInt32();return r}function vGr(e,t,s){let n=e.readNumber("file count");or(n,s.limits);let o={names:Array(n).fill(""),emptyStreams:Array(n).fill(!1),emptyFiles:[],antiFiles:[],mtimes:Array(n),attributes:Array(n)};for(;;){let r=e.readNumber("FilesInfo property ID");if(r===0)break;let i=e.readNumber("FilesInfo property size");Hn(i,s.limits,"file property");let a=new k0(e.readBytes(i));if(r===14)o.emptyStreams=kFe(a,n);else if(r===15)o.emptyFiles=kFe(a,o.emptyStreams.filter(Boolean).length);else if(r===16)o.antiFiles=kFe(a,o.emptyStreams.filter(Boolean).length);else if(r===17)o.names=EGr(a,n,t,s.limits.maxPathBytes);else if(r===20)o.mtimes=MGr(a,n,t);else if(r===21)o.attributes=AGr(a,n,t);else if(r===25)while(a.remaining>0)if(a.readByte()!==0)throw new j("Invalid non-zero 7z dummy property");else a.pos=a.bytes.byteLength;if(a.remaining!==0)throw new j(`Invalid 7z file property 0x${r.toString(16)} length`)}return o}async function IGr(e,t,s){let n=new k0(t);aTt(n,1,"Header");let o=[],r,i;for(;;){let a=n.readNumber("Header property ID");if(a===0)break;if(a===2)for(;;){if(n.readNumber("archive property ID")===0)break;n.skipSizedProperty()}else if(a===3)o=await $zs(e,lTt(n,e.size,s),s);else if(a===4)r=lTt(n,e.size,s);else if(a===5)i=vGr(n,o,s);else throw new j(`Unsupported 7z header property ID 0x${a.toString(16)}`)}if(n.remaining!==0)throw new j("Invalid 7z trailing header data");if(!r)r={packPosition:0,packSizes:[],packCrcs:[],folders:[],substreams:[]};if(!i)i={names:[],emptyStreams:[],emptyFiles:[],antiFiles:[],mtimes:[],attributes:[]};return{streams:r,files:i}}class uTt{#e;#t;#s;#n;constructor(e,t){this.#e=e,this.#t=t.offset,this.#s=t.size,this.#n=t.crc}async read(e,t){if(e!==this.#s)throw new j(`7z member '${t}' declared size changed during extraction`);let s=await this.#e.read();if(this.#t<0||this.#t+e>s.byteLength)throw new j(`Invalid 7z member '${t}' folder range`);let n=s.subarray(this.#t,this.#t+e);if(this.#n!==void 0&&Wi(n)!==this.#n)throw new j(`Invalid 7z member '${t}' CRC32 mismatch`);return n.slice()}}class zzs{async read(e,t){if(e!==0)throw new j(`Invalid empty 7z member '${t}' size`);return new Uint8Array(0)}}function PGr(e,t){let s=t.replace(/\\/g,"/");if(s.startsWith("/"))return{targetPath:s,resolveTarget:!1};let n=e.split("/");n.pop();for(let o of s.split("/")){if(!o||o===".")continue;if(o===".."){if(n.length===0)return{targetPath:s,resolveTarget:!1};n.pop()}else n.push(o)}return{targetPath:n.join("/"),resolveTarget:!0}}async function FGr(e,t,s,n){let o=t.folders.map((l)=>new bFe(e,l,n.limits)),r=[],i=0,a=0;for(let l=0;l<s.names.length;l++){let u=s.names[l],p=Sr(u),c=s.emptyStreams[l]??!1,d=c?s.emptyFiles[i]??!1:!1,f=c?s.antiFiles[i]??!1:!1;if(c)i++;let m=c?void 0:t.substreams[a++];if(!c&&!m)throw new j("Invalid 7z file-to-substream mapping");if(!p||f)continue;let g=s.attributes[l],h=g!==void 0&&g>>>16!==0?g>>>16:void 0,T=h!==void 0&&(h&61440)===40960,y=c&&!d||g!==void 0&&(g&16)!==0||h!==void 0&&(h&61440)===16384,R=m?.size??0;Qi(R,p,n.limits);let C={path:p,isDirectory:y,size:R,mtimeMs:s.mtimes[l],mode:h};if(T&&m){ko(R,"link target",n.limits.maxPathBytes);let b=new uTt(o[m.folderIndex],m),w;try{w=RGr.decode(await b.read(R,p))}catch(x){if(x instanceof j)throw x;throw new j(`Invalid UTF-8 symlink target in 7z member '${p}'`)}Kd(w,"link target",n.limits.maxPathBytes);let E=PGr(p,w);C.storage={type:"link",targetPath:E.targetPath,resolveTarget:E.resolveTarget}}else if(!y)C.storage=m?{type:"member",source:new uTt(o[m.folderIndex],m)}:{type:"member",source:OGr};r.push(C),or(r.length,n.limits)}if(a!==t.substreams.length)throw new j("Invalid unused 7z substreams");return r}function mTt(e){if(e.byteLength<iTt.byteLength)return!1;for(let t=0;t<iTt.byteLength;t++)if(e[t]!==iTt[t])return!1;return!0}var iTt,yGr,RGr,CGr=11644473600000,OGr,Kzs=async(e,t)=>{try{if(e.size<32)throw new j("Invalid 7z archive: truncated signature header");let s=await e.read(0,32);if(!mTt(s))throw new j("Invalid 7z archive signature");if(s[6]!==0)throw new j(`Unsupported 7z major version ${s[6]}`);if(Wi(s.subarray(12,32))!==new k0(s.subarray(8,12)).readUInt32())throw new j("Invalid 7z start-header CRC32 mismatch");let n=new k0(s.subarray(12)),o=n.readUInt64BigInt(),r=n.readUInt64BigInt(),i=n.readUInt32();if(o>BigInt(Number.MAX_SAFE_INTEGER)||r>BigInt(Number.MAX_SAFE_INTEGER))throw new j("7z header offsets or sizes are too large to read safely");let a=32+Number(o),l=Number(r);if(Hn(l,t.limits,"next header"),!Number.isSafeInteger(a)||a<32||a+l>e.size)throw new j("Invalid 7z next-header range");let u=await e.read(a,a+l);if(Wi(u)!==i)throw new j("Invalid 7z next-header CRC32 mismatch");let p=new k0(u).readNumber("next-header ID");if(p===23){let d=new k0(u);d.readNumber();let f=lTt(d,e.size,t);if(d.remaining!==0)throw new j("Invalid 7z encoded-header trailing data");let m=await $zs(e,f,t);if(m.length!==1)throw new j("Invalid 7z encoded header folder count");if(u=m[0],new k0(u).readNumber("decoded-header ID")!==1)throw new j("Invalid decoded 7z header marker")}else if(p!==1)throw new j(`Unsupported 7z next-header ID 0x${p.toString(16)}`);let c=await IGr(e,u,t);return await FGr(e,c.streams,c.files,t)}catch(s){if(s instanceof j)throw s;throw new j(`Invalid 7z archive: ${s instanceof Error?s.message:String(s)}`)}};var Vzs=S(()=>{m0();Ur();vp();Vd();jzs();iTt=Uint8Array.of(55,122,188,175,39,28),yGr=new TextDecoder("utf-16",{fatal:!0}),RGr=new TextDecoder("utf-8",{fatal:!0});OGr=new zzs});import*as wW from"path";import*as wFe from"zlib";function xFe(e,t){if(e instanceof j)return e;return new j(`${t}: ${e instanceof Error?e.message:String(e)}`)}function SFe(e,t,s,n){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<0||t<0)throw new j(`Invalid ZIP archive: ${n} has an invalid range`);let o=e+t;if(!Number.isSafeInteger(o)||o>s)throw new j(`Invalid ZIP archive: ${n} exceeds archive size`);return o}function $Gr(e){for(let t=e.byteLength-hae;t>=0;t--){if(Es(e,t)!==CTt)continue;if(t+hae+xn(e,t+20)===e.byteLength)return t}throw new j("Invalid ZIP archive: missing end of central directory")}async function zGr(e,t,s,n){let o=n-gae;if(o<0)return;let r=o>=s?t.subarray(o-s,o-s+gae):await e.read(o,n);if(r.byteLength!==gae||Es(r,0)!==Jzs)return;if(Es(r,4)!==0||Es(r,16)!==1)throw new j("Multi-volume ZIP archives are not supported");let i=ZE(r,8),a=[i],l=o-h6;if(l>=0&&l!==i)a.push(l);for(let u of a){if(u<0||u+h6>e.size)continue;let p=await e.read(u,u+h6);if(p.byteLength!==h6||Es(p,0)!==Yzs)continue;let c=ZE(p,4);if(c<44||u+12+c!==o)continue;if(Es(p,16)!==0||Es(p,20)!==0)throw new j("Multi-volume ZIP archives are not supported");let d=ZE(p,24),f=ZE(p,32);if(d!==f)throw new j("Multi-volume ZIP archives are not supported");return{entries:f,size:ZE(p,40),offset:ZE(p,48),physicalEnd:u,archiveOffset:0}}throw new j("Invalid ZIP archive: missing ZIP64 end of central directory")}async function KGr(e,t){if(t.entries===0)return t.offset;let s=[t.offset],n=t.physicalEnd-t.size;if(n!==t.offset)s.push(n);for(let o of s){if(o<0||o+4>e.size||o+t.size>e.size)continue;let r=await e.read(o,o+4);if(r.byteLength===4&&Es(r,0)===RTt)return o}throw new j("Invalid ZIP archive: central directory is out of bounds or malformed")}async function VGr(e,t){if(e.size<hae)throw new j("Invalid ZIP archive: missing end of central directory");let s=Math.min(e.size,hae+LGr),n=e.size-s,o=await e.read(n,e.size);if(o.byteLength!==s)throw new j("Invalid ZIP archive: truncated end of central directory");let r=$Gr(o),i=n+r,a=xn(o,r+4),l=xn(o,r+6),u=xn(o,r+8),p=xn(o,r+10),c=Es(o,r+12),d=Es(o,r+16);if(a!==0||l!==0||u!==S0&&p!==S0&&u!==p)throw new j("Multi-volume ZIP archives are not supported");let f=u===S0||p===S0||c===xS||d===xS,m=await zGr(e,o,n,i),g=i;if(m)({entries:p,size:c,offset:d,physicalEnd:g}=m);else if(f)throw new j("Invalid ZIP archive: missing ZIP64 central-directory metadata");if(or(p,t),Hn(c,t,"ZIP central directory"),p>Math.floor(c/46))throw new j("Invalid ZIP archive: truncated central directory");let h=d,T={entries:p,size:c,offset:d,physicalEnd:g,archiveOffset:0};return T.offset=await KGr(e,T),T.archiveOffset=T.offset-h,SFe(T.offset,T.size,e.size,"central directory"),T}function YGr(e,t){let s=0n;for(let r=7;r>=0;r--)s=s<<8n|BigInt(e[t+r]);let n=s/10000n-HGr,o=Number(n);return Number.isSafeInteger(o)?o:void 0}function JGr(e){if(e.byteLength<4)return;let t=4;while(t+4<=e.byteLength){let s=xn(e,t),n=xn(e,t+2),o=t+4+n;if(o>e.byteLength)throw new j("Invalid ZIP archive: malformed NTFS extra field");if(s===1&&n>=8)return YGr(e,t+4);t=o}return}function XGr(e,t){if(t===0)return;let s=1980+(t>>>9&127),n=(t>>>5&15)-1,o=t&31,r=e>>>11&31,i=e>>>5&63,a=(e&31)*2;if(n<0||n>11||o<1||o>31||r>23||i>59||a>59)return;let l=new Date(s,n,o,r,i,a).getTime();return Number.isFinite(l)?l:void 0}function QGr(e,t){let s={},n=0;while(n<e.byteLength){if(n+4>e.byteLength)throw new j("Invalid ZIP archive: truncated extra-field header");let o=xn(e,n),r=xn(e,n+2),i=n+4,a=i+r;if(a>e.byteLength)throw new j("Invalid ZIP archive: malformed extra field");let l=e.subarray(i,a);if(o===1)s.zip64=l;else if(o===28789){if(l.byteLength<5)throw new j("Invalid ZIP archive: Unicode path extra field is too small");if(l[0]===1&&Es(l,1)===Wi(t))try{s.unicodePath=WGr.decode(l.subarray(5))}catch{}}else if(o===21589){if(l.byteLength<1)throw new j("Invalid ZIP archive: extended timestamp extra field is too small");if((l[0]&1)!==0){if(l.byteLength<5)throw new j("Invalid ZIP archive: extended timestamp extra field is too small");s.mtimeMs=(Es(l,1)|0)*1000}}else if(o===10&&s.mtimeMs===void 0)s.mtimeMs=JGr(l);n=a}return s}function ZGr(e,t,s){if(!(s.uncompressedSize||s.compressedSize||s.localHeaderOffset||s.diskStart))return t;if(!e)throw new j("Invalid ZIP archive: missing ZIP64 extra field");let o=0,r={...t};if(s.uncompressedSize){if(o+8>e.byteLength)throw new j("Invalid ZIP archive: malformed ZIP64 extra field");r.uncompressedSize=ZE(e,o),o+=8}if(s.compressedSize){if(o+8>e.byteLength)throw new j("Invalid ZIP archive: malformed ZIP64 extra field");r.compressedSize=ZE(e,o),o+=8}if(s.localHeaderOffset){if(o+8>e.byteLength)throw new j("Invalid ZIP archive: malformed ZIP64 extra field");r.localHeaderOffset=ZE(e,o),o+=8}if(s.diskStart){if(o+4>e.byteLength)throw new j("Invalid ZIP archive: malformed ZIP64 extra field");r.diskStart=Es(e,o)}return r}async function e3r(e,t,s,n){try{switch(t){case 0:return e;case 8:return wFe.inflateRawSync(e,{maxOutputLength:Math.max(s,1)});case 12:return await T0(e,s);case 14:{if(e.byteLength<9||e[2]!==5||e[3]!==0)throw new j(`Invalid ZIP archive: malformed LZMA properties for '${n}'`);return await nae(e.subarray(4,9),e.subarray(9),s)}case 20:case 93:return await R0(e,s);case 95:return await y0(e,s);default:throw new j(`Unsupported ZIP compression method ${t} for '${n}'`)}}catch(o){throw xFe(o,`Failed to decompress ZIP member '${n}'`)}}class Zzs{#e;#t;#s;#n;#o;#r;#a;constructor(e,t,s,n,o,r,i){this.#e=e,this.#t=t,this.#s=s,this.#n=n,this.#o=o,this.#r=r,this.#a=i}async read(e,t){try{if(Qi(Math.max(e,this.#t),t,this.#a),(this.#n&(hTt|TTt))!==0||this.#s===99)throw new j(`Encrypted ZIP member '${t}' is not supported`);if(BGr[this.#s]!==!0)throw new j(`Unsupported ZIP compression method ${this.#s} for '${t}'`);let s=SFe(this.#r,30,this.#e.size,`local header for '${t}'`),n=await this.#e.read(this.#r,s);if(n.byteLength!==30||Es(n,0)!==yTt)throw new j(`Invalid ZIP archive: malformed local header for '${t}'`);if((xn(n,6)&(hTt|TTt))!==0)throw new j(`Encrypted ZIP member '${t}' is not supported`);if(xn(n,8)!==this.#s)throw new j(`Invalid ZIP archive: local and central compression methods disagree for '${t}'`);let r=this.#r+30+xn(n,26)+xn(n,28),i=SFe(r,this.#t,this.#e.size,`data for '${t}'`);if(this.#s===0&&this.#t!==e)throw new j(`Invalid ZIP archive: size mismatch for '${t}' (expected ${e}, got ${this.#t})`);let a=await this.#e.read(r,i);if(a.byteLength!==this.#t)throw new j(`Invalid ZIP archive: truncated data for '${t}'`);let l=await e3r(a,this.#s,e,t);if(l.byteLength!==e)throw new j(`Invalid ZIP archive: size mismatch for '${t}' (expected ${e}, got ${l.byteLength})`);if(Wi(l)!==this.#o)throw new j(`Invalid ZIP archive: CRC mismatch for '${t}'`);return l}catch(s){throw xFe(s,`Failed to read ZIP member '${t}'`)}}}function t3r(e,t,s,n){let o=[],r=0;for(let i=0;i<s.entries;i++){if(r+46>t.byteLength)throw new j("Invalid ZIP archive: truncated central directory");if(Es(t,r)!==RTt)throw new j("Invalid ZIP archive: malformed central directory");let a=xn(t,r+4),l=xn(t,r+8),u=xn(t,r+10),p=xn(t,r+12),c=xn(t,r+14),d=Es(t,r+16),f=Es(t,r+20),m=Es(t,r+24),g=xn(t,r+28),h=xn(t,r+30),T=xn(t,r+32),y=xn(t,r+34),R=Es(t,r+38),C=Es(t,r+42),b=r+46,w=b+g,E=w+h,x=E+T;if(!Number.isSafeInteger(x)||x>t.byteLength)throw new j("Invalid ZIP archive: truncated central-directory entry");ko(g,"member path",n.limits.maxPathBytes);let A=t.subarray(b,w),M=QGr(t.subarray(w,E),A),I=ZGr(M.zip64,{compressedSize:f,uncompressedSize:m,localHeaderOffset:C,diskStart:y},{compressedSize:f===xS,uncompressedSize:m===xS,localHeaderOffset:C===xS,diskStart:y===S0});if(I.diskStart!==0)throw new j("Multi-volume ZIP archives are not supported");let O=M.unicodePath??((l&gTt)!==0?Qzs:GGr).decode(A);if(Kd(O,"member path",n.limits.maxPathBytes),(l&(hTt|TTt))!==0||u===99)throw new j(`Encrypted ZIP member '${O}' is not supported`);let P=Sr(O);if(P){Qi(Math.max(I.uncompressedSize,I.compressedSize),P,n.limits);let F=a>>>8,_=F===Xzs||F===DGr?R>>>16:void 0,D=_===void 0?0:_&NGr,L=ejs(O)||D===qGr||(R&16)!==0,N=D===UGr&&!L,H=I.localHeaderOffset+s.archiveOffset;SFe(H,30,e.size,`local header for '${P}'`);let q=new Zzs(e,I.compressedSize,u,l,d,H,n.limits),z={path:P,isDirectory:L,size:L?0:I.uncompressedSize,mtimeMs:M.mtimeMs??XGr(p,c),mode:_||void 0,storage:L?void 0:{type:"member",source:q}};o.push({entry:z,isSymlink:N}),or(o.length,n.limits)}r=x}return o}async function s3r(e,t){let s=await VGr(e,t.limits);if(s.size===0)return[];let n=await e.read(s.offset,s.offset+s.size);if(n.byteLength!==s.size)throw new j("Invalid ZIP archive: truncated central directory");let o=t3r(e,n,s,t);for(let r of o){if(!r.isSymlink)continue;if(ko(r.entry.size,"symlink target",t.limits.maxPathBytes),r.entry.storage?.type!=="member")throw new j("Invalid ZIP archive: symlink has no payload");let i=await r.entry.storage.source.read(r.entry.size,r.entry.path),a=Qzs.decode(i);Kd(a,"symlink target",t.limits.maxPathBytes);let l=a.replace(/\\/g,"/"),p=wW.posix.isAbsolute(l)||/^[A-Za-z]:/.test(l)||l.includes("\x00")?void 0:zd(wW.posix.join(wW.posix.dirname(r.entry.path),l));r.entry.size=0,r.entry.storage={type:"link",targetPath:p===void 0?l:p,resolveTarget:p!==void 0}}return o.map((r)=>r.entry)}function t5s(e){if(e.byteLength<4)return!1;let t=Es(e,0);return t===yTt||t===CTt||t===_Gr}async function s5s(e){try{let t=[],s=[],n=0,o=0,r=0;for(let[c,d]of e){let f=c.replace(/\\/g,"/"),m=Sr(f);if(!m||m!==f.replace(/^\.\//,"")||f.startsWith("/")||/^[A-Za-z]:/.test(f)||f.includes("\x00"))throw new j(`Cannot write unsafe ZIP member path '${c}'`);let g=m,h=jGr.encode(g);if(h.byteLength>S0)throw new j(`ZIP member path '${g}' is too long to write`);if(d.byteLength>=xS)throw new j(`ZIP member '${g}' is too large to write`);let T=d.byteLength===0?void 0:wFe.deflateRawSync(d),y=T&&T.byteLength<d.byteLength?T:d,R=y===d?0:8;if(y.byteLength>=xS||n>=xS)throw new j("ZIP archive is too large to write member offsets safely");let C=Wi(d),b=new Uint8Array(30+h.byteLength);dl(b,0,yTt),nd(b,4,20),nd(b,6,gTt),nd(b,8,R),nd(b,10,0),nd(b,12,33),dl(b,14,C),dl(b,18,y.byteLength),dl(b,22,d.byteLength),nd(b,26,h.byteLength),b.set(h,30),t.push(b,y);let w=new Uint8Array(46+h.byteLength);if(dl(w,0,RTt),nd(w,4,Xzs<<8|20),nd(w,6,20),nd(w,8,gTt),nd(w,10,R),nd(w,12,0),nd(w,14,33),dl(w,16,C),dl(w,20,y.byteLength),dl(w,24,d.byteLength),nd(w,28,h.byteLength),dl(w,38,2175008768),dl(w,42,n),w.set(h,46),s.push(w),n+=b.byteLength+y.byteLength,o+=w.byteLength,r++,!Number.isSafeInteger(n+o)||r>xS)throw new j("ZIP archive is too large to write")}if(n>=xS||o>=xS)throw new j("ZIP archive is too large to write member offsets safely");let i=r>=S0,a=hae+(i?h6+gae:0),l=n+o+a;if(!Number.isSafeInteger(l))throw new j("ZIP archive is too large to write");let u=new Uint8Array(l),p=0;for(let c of t)u.set(c,p),p+=c.byteLength;for(let c of s)u.set(c,p),p+=c.byteLength;if(i){let c=p;dl(u,p,Yzs),cW(u,p+4,44),nd(u,p+12,45),nd(u,p+14,45),cW(u,p+24,r),cW(u,p+32,r),cW(u,p+40,o),cW(u,p+48,n),p+=h6,dl(u,p,Jzs),cW(u,p+8,c),dl(u,p+16,1),p+=gae}return dl(u,p,CTt),nd(u,p+8,i?S0:r),nd(u,p+10,i?S0:r),dl(u,p+12,o),dl(u,p+16,n),u}catch(t){throw xFe(t,"Failed to encode ZIP archive")}}var yTt=67324752,RTt=33639248,Yzs=101075792,Jzs=117853008,CTt=101010256,_Gr=134695760,hae=22,h6=56,gae=20,LGr=65535,S0=65535,xS=4294967295,gTt=2048,hTt=1,TTt=64,Xzs=3,DGr=19,NGr=61440,qGr=16384,UGr=40960,HGr=11644473600000n,BGr,Qzs,WGr,GGr,jGr,e5s=async(e,t)=>{try{return await s3r(e,t)}catch(s){throw xFe(s,"Failed to read ZIP archive")}};var bTt=S(()=>{Sh();m0();tae();TW();oae();c6();Ur();vp();Vd();tM();BGr={0:!0,8:!0,12:!0,14:!0,20:!0,93:!0,95:!0},Qzs=new TextDecoder("utf-8"),WGr=new TextDecoder("utf-8",{fatal:!0}),GGr=new TextDecoder("windows-1252"),jGr=new TextEncoder});import*as o5s from"path";function EFe(e){let t=e.toLowerCase();for(let[s,n]of kTt)if(t.endsWith(`.${s}`))return n;return}function o3r(e){if(!e)return"data";let t=o5s.basename(e.replace(/\\/g,"/")),s=t.toLowerCase();for(let[n]of kTt)if(s.length>n.length+1&&s.endsWith(`.${n}`))return t.slice(0,t.length-n.length-1);return t||"data"}class i5s{#e;constructor(e){this.#e=e}async read(){return this.#e}}function ES(e){return async(t,s)=>{ci(t.size,s.limits);let n=await e(await eM(t),s.limits.maxInMemorySize);if(ci(n.byteLength,s.limits),jht(n))return pae(n,s);return[{path:o3r(s.archivePath),isDirectory:!1,size:n.byteLength,storage:{type:"member",source:new i5s(n)}}]}}function a5s(e){return r3r[e]}function l5s(e){for(let[n,o]of i3r)if(o(e))return n;let t=e.byteLength-n5s,s=Math.max(0,e.byteLength-n5s-l3r);for(let n=t;n>=s;n--)if(Es(e,n)===a3r)return"zip";return}var n3r,kTt,r5s,r3r,i3r,a3r=101010256,n5s=22,l3r=65535;var STt=S(()=>{kjs();bht();Sh();Gjs();tae();sae();TW();r$s();oae();c6();Lht();Y$s();lzs();vp();yht();Ozs();Bzs();Vzs();tM();aFe();zht();bTt();n3r={zip:["zip","jar","war","ear","apk","whl","ipa","xpi","vsix","nupkg","cbz"],tar:["tar"],"tar.gz":["tar.gz","tgz"],"tar.bz2":["tar.bz2","tbz2","tbz"],"tar.xz":["tar.xz","txz"],"tar.zst":["tar.zst","tzst"],"tar.Z":["tar.z"],asar:["asar"],rar:["rar","cbr"],"7z":["7z"],iso:["iso"],cab:["cab"],cpio:["cpio"],rpm:["rpm"],ar:["ar","a","lib"],deb:["deb"],lzh:["lzh","lha"],arj:["arj"],gz:["gz"],bz2:["bz2"],xz:["xz"],zst:["zst"],Z:["z"],lzma:["lzma"]},kTt=Object.entries(n3r).flatMap(([e,t])=>t.map((s)=>[s,e])).sort((e,t)=>t[0].length-e[0].length),r5s=kTt.map(([e])=>e.replace(/\./g,"\\.")).join("|");r3r={zip:e5s,tar:W$s,"tar.gz":ES(hW),"tar.bz2":ES(T0),"tar.xz":ES(y0),"tar.zst":ES(R0),"tar.Z":ES(vht),asar:Ajs,rar:vzs,"7z":Kzs,iso:azs,cab:Wjs,cpio:R$s,rpm:Hzs,ar:cFe,deb:V$s,lzh:fjs,arj:bjs,gz:ES(hW),bz2:ES(T0),xz:ES(y0),zst:ES(R0),Z:ES(vht),lzma:ES(p6)};i3r=[["zip",t5s],["rar",Azs],["7z",mTt],["cab",Bjs],["rpm",rTt],["arj",Rht],["lzh",Tht],["cpio",rae],["deb",Vht],["ar",$ht],["asar",vjs],["tar.gz",GPe],["tar.bz2",BPe],["tar.xz",JPe],["tar.zst",QPe],["tar.Z",o$s],["iso",izs],["tar",jht]]});import*as mD from"fs/promises";import*as wh from"path";function p3r(e){if(typeof e!=="string"){if("bytes"in e)return{source:NPe(e.bytes),format:e.format};if("source"in e)return{source:e.source,format:e.format,archivePath:e.path};let s=e.format;return{source:mht(e.path),format:s,archivePath:e.path}}let t=EFe(e);if(!t)throw new j(`Unsupported archive format: ${e}`);return{source:mht(e),format:t,archivePath:e}}async function xW(e,t={}){let{source:s,format:n,archivePath:o}=p3r(e),r={...Vie,...t.limits},i={limits:r,archivePath:o},a=await a5s(n)(s,i);return new dht(n,a,r)}function T6(e){let t=e.replace(/\\/g,"/"),s=new RegExp(`\\.(?:${r5s})(?=(?::|$))`,"gi"),n=new Set,o=[],r;while(!0){if(r=s.exec(t),r===null)break;let i=r.index+r[0].length,a=e.slice(0,i),l=t.slice(i).replace(/^:+/,""),u=`${a}\x00${l}`;if(n.has(u))continue;n.add(u),o.push({archivePath:a,subPath:l})}return o.sort((i,a)=>a.archivePath.length-i.archivePath.length)}function wTt(e){return e.map((t)=>{if(t.isDirectory)return`${t.name}/`;let s=t.size>0?` (${pt(t.size)})`:"";return`${t.name}${s}`})}async function u5s(e,t,s={}){let o=(await xW({bytes:e,format:t})).listDirectory(""),r=s.limit!==void 0&&s.limit>0?o.slice(0,s.limit):o,i=wTt(r);return i.length>0?i.join(`
|
|
@@ -5115,7 +5115,7 @@ ${o}`,v8s))}if(this.#t==="running")this.#i.addChild(this.#n);else{let o=sLe({sta
|
|
|
5115
5115
|
`),u=l.length>0?n.countTokens(l):0,p=s===!0;return{candidate:{id:e,textTokens:u,frames:!p&&u>=Y8s?z5(l,{shape:o}):0,isError:p},text:l}}function e9s(e){let{options:t,model:s}=e;if(!s?.input.includes("image"))return{visionCapable:!1,savedTokens:0};let n=Ux(s,t.shape),o=new vd(s),r=J8s(e.messages),i=$5(s.provider)-r,a=[];if(t.renderToolResults)for(let m of e.messages){if(m.role!=="toolResult"||typeof m.toolCallId!=="string")continue;let g=Z8s(m.toolCallId,m.content,m.isError,o,n);a.push(g.candidate)}let l,u;if(t.renderSystemPrompt!=="none"){if(l=X8s(e.systemPrompt,t.renderSystemPrompt),l)u={textTokens:o.countTokens(l.text),frames:z5(l.text,{shape:n})}}let p=Q8s({options:t,shape:n,budget:i,toolResults:a,systemPrompt:u,hasUserMessage:!0}),c=0,d;if(t.renderSystemPrompt!=="none"){let m=u??{textTokens:0,frames:0},g=p.systemPrompt!==void 0,h=m.frames*n.frameTokenEstimate,T=g?Math.max(0,m.textTokens-h):0,y;if(!g){let R=i-p.toolResults.reduce((C,b)=>C+b.frames,0);if(m.frames===0)y="empty";else if(m.frames>Math.min(R,lLe))y="budget";else y="margin"}d={applied:g,...y?{reason:y}:{},textTokens:m.textTokens,frames:m.frames,imageTokens:h,savedTokens:T,scope:l?.scope??t.renderSystemPrompt},c+=T}let f;if(t.renderToolResults){let m=0,g=0;for(let y of p.toolResults)m+=y.textTokens,g+=y.frames;let h=g*n.frameTokenEstimate,T=Math.max(0,m-h);f={total:a.length,swapped:p.toolResults.length,textTokens:m,frames:g,imageTokens:h,savedTokens:T},c+=T}return{visionCapable:!0,...d?{systemPrompt:d}:{},...f?{toolResults:f}:{},savedTokens:c}}class ZRt{options;onToolResultSavings;frameSink;#e=new Map;#t;constructor(e,t,s){this.options=e;this.onToolResultSavings=t;this.frameSink=s}async transform(e,t){if(!t.input.includes("image"))return e;let s=Ux(t,this.options.shape),n=new vd(t),o=$5(t.provider)-J8s(e.messages);if(o<=0)return e;let r=[...e.messages],i=[],a=new Map,l=new Set;if(this.options.renderToolResults)for(let h=0;h<r.length;h++){let T=r[h];if(T.role!=="toolResult")continue;l.add(T.toolCallId);let y=Z8s(T.toolCallId,T.content,T.isError,n,s);i.push(y.candidate),a.set(T.toolCallId,{index:h,message:T,text:y.text})}let u,p;if(this.options.renderSystemPrompt!=="none"){if(u=X8s(e.systemPrompt,this.options.renderSystemPrompt),u)p={textTokens:n.countTokens(u.text),frames:z5(u.text,{shape:s})}}let c=r.findIndex((h)=>h.role==="user"),d=Q8s({options:this.options,shape:s,budget:o,toolResults:i,systemPrompt:p,hasUserMessage:c>=0}),f=!1,m=[];for(let h of d.toolResults){let T=a.get(h.id);if(!T)continue;let y=await this.#s(this.#e,h.id,T.text,s),R=[{type:"text",text:K8s},...y],C=0;for(let b of T.message.content){if(b.type!=="image")continue;C++,R.push({type:"text",text:`[Original source image ${C}; corresponds to its marker in the compacted text.]`}),R.push(b)}r[T.index]={...T.message,content:R},f=!0,m.push({toolCallId:h.id,savedTokens:Math.max(0,h.textTokens-h.frames*s.frameTokenEstimate)})}if(m.length>0)this.onToolResultSavings?.(m,t);if(this.options.renderToolResults){for(let h of this.#e.keys())if(!l.has(h))this.#e.delete(h)}let g=e.systemPrompt;if(d.systemPrompt&&c>=0&&u){let h=Bun.hash(u.text),T=this.#t;if(!T||T.hash!==h)T={hash:h,frames:await this.frameSink?.framesFor(u.text,s,lLe)??await Q1(u.text,{shape:s,maxFrames:lLe})},this.#t=T;let y=T.frames,R=r[c],C=typeof R.content==="string"?[{type:"text",text:R.content}]:R.content;r[c]={...R,content:[{type:"text",text:u.userNote},...y,...C]},g=u.replacement,f=!0}if(!f)return e;return{...e,systemPrompt:g,messages:r}}async#s(e,t,s,n){let o=Bun.hash(s),r=e.get(t);if(r&&r.hash===o)return r.frames;let i=await this.frameSink?.framesFor(s,n)??await Q1(s,{shape:n});return e.set(t,{hash:o,frames:i}),i}}var lLe=6,Y8s=3000,sVr=0.9,nVr;var eCt=S(()=>{Yr();$R();q8s();H8s();W8s();j8s();z8s();nVr=[/<repo-rules>\n[\s\S]*?\n<\/repo-rules>/g,/## Context\n<instructions>\n[\s\S]*?\n<\/instructions>/g]});function Zae(e){return Math.min(32000,Math.max(8192,Math.floor(e*0.125)))}var tCt=8192;function n9s(e,t,s){if(!(t>0))return null;let n=e.getGroup("compaction"),o=n;if(!n.enabled||o.strategy==="off")return null;let r=Fk(t,o);if(!(r>0)||r>t)return null;let i=n.asyncEnabled!==!1&&noe(s,n)!==void 0,a=Zae(r);return{thresholdPercent:r/t*100,speculationPercent:i?Math.max(0,r-a)/t*100:null}}function aVr(e,t){if(!t.some((s)=>s.name==="read"))return rCt;return e.filter((s)=>s.hide!==!0)}function lVr(e,t){let s=[];for(let n of e)s.push(n.name,n.description??"");return t.countTokens(s)}function fLe(e,t){let s=[];for(let n of e){if(typeof n.name==="string")s.push(n.name);if(typeof n.description==="string")s.push(n.description);try{let o={name:n.name,description:n.description,parameters:n.parameters},r=JSON.stringify(Qn(o)??{});if(typeof r==="string")s.push(r)}catch{}}return t.countTokens(s)}function o9s(e,t){let s=e,n=e.systemPrompt??nCt,o=e.agent?.state?.tools??oCt,r=e.skills??rCt,i=s[t9s];if(i&&i.systemPromptRef===n&&i.toolsRef===o&&i.skillsRef===r&&i.tokenizerRef===t)return i;return i={systemPromptRef:n,toolsRef:o,skillsRef:r,tokenizerRef:t,tokens:void 0,breakdown:void 0},s[t9s]=i,i}function Yf(e,t){let s=o9s(e,t);if(s.tokens!==void 0)return s.tokens;let n=e.systemPrompt??nCt,o=e.agent?.state?.tools??oCt,r=t.countTokens(Array.from(n,(i)=>i??""))+fLe(o,t);return s.tokens=r,r}function iCt(e,t){let s=o9s(e,t);if(s.breakdown)return s.breakdown;let n=e.agent?.state?.tools??oCt,o=lVr(aVr(e.skills??rCt,n),t),r=fLe(n,t),i=e.systemPrompt??nCt,a=t.countTokens(Array.from(i.slice(1),(p)=>p??"")),l=Math.max(0,t.countTokens(i[0]??"")-o),u={skillsTokens:o,toolsTokens:r,systemContextTokens:a,systemPromptTokens:l};return s.breakdown=u,u}function mLe(e,t){let s=e.model,n=e.agent.tokenizer,o=s?.contextWindow??0,r=typeof e.getContextBreakdown==="function"?e.getContextBreakdown():void 0,i=0,a=0,l=0,u=0,p=0,c=0;if(r)i=r.messagesTokens,a=r.skillsTokens,l=r.systemToolsTokens,u=r.systemContextTokens,p=r.systemPromptTokens,c=r.usedTokens;else{i=n.countMessages(e.messages??[]);let h=iCt(e,n);a=h.skillsTokens,l=h.toolsTokens,u=h.systemContextTokens,p=h.systemPromptTokens,c=a+l+u+p+i}let d=[{id:"systemPrompt",label:"System prompt",tokens:p,color:"accent",glyph:uLe},{id:"systemTools",label:"System tools",tokens:l,color:"warning",glyph:uLe},{id:"systemContext",label:"System context",tokens:u,color:"customMessageLabel",glyph:uLe},{id:"skills",label:"Skills",tokens:a,color:"success",glyph:uLe},{id:"messages",label:"Messages",tokens:i,color:"userMessageText",glyph:iVr}],f=0;if(o>0){let h=e.settings.getGroup("compaction");if(h.enabled&&h.strategy!=="off"){let T=Fk(o,h);f=Math.max(0,o-T)}else f=0;if(f===0&&h.enabled)f=nH(o,h)}f=Math.min(f,Math.max(0,o-c));let m=Math.max(0,o-c-f),g;if(t?.snapcompactSavings){let h=e.settings.get("snapcompact.systemPrompt"),T=e.settings.get("snapcompact.toolResults");if(h!=="none"||T)g=e9s({options:{renderSystemPrompt:h,renderToolResults:T,shape:e.settings.get("snapcompact.shape")},model:s,systemPrompt:e.systemPrompt??[],messages:e.messages??[]})}return{model:s,contextWindow:o,categories:d,usedTokens:c,autoCompactBufferTokens:f,freeTokens:m,snapcompact:g}}function uVr(e){let t=[],s=e.contextWindow;if(s<=0){for(let p=0;p<PD;p++)t.push({glyph:dLe,color:"dim"});return t}let n=s/PD,o=(p)=>{if(p<=0)return 0;return Math.max(1,Math.round(p/n))},r=e.categories.map((p)=>({category:p,count:o(p.tokens)})),i=o(e.autoCompactBufferTokens),a=r.reduce((p,c)=>p+c.count,0),l=PD-i;if(a>l){let p=a-l,c=[...r].sort((d,f)=>f.count-d.count);for(let d of c)while(p>0&&d.count>1)d.count-=1,p-=1;if(a=r.reduce((d,f)=>d+f.count,0),a+i>PD)i=Math.max(0,PD-a)}for(let{category:p,count:c}of r)for(let d=0;d<c;d++)t.push({glyph:p.glyph,color:p.color});let u=Math.max(0,PD-t.length-i);for(let p=0;p<u;p++)t.push({glyph:dLe,color:"dim"});for(let p=0;p<i;p++)t.push({glyph:s9s,color:"warning"});while(t.length<PD)t.push({glyph:dLe,color:"dim"});return t.slice(0,PD)}function pLe(e,t,s=1){if(t<=0)return"0%";let n=e/t*100;if(n>0&&n<0.05)return"<0.1%";return`${n.toFixed(s)}%`}function pVr(e,t){let s=[],{model:n,contextWindow:o,categories:r,usedTokens:i,autoCompactBufferTokens:a,freeTokens:l}=e,u=n?.name??n?.id??"no model",p=n?.id??"unknown",c=xe(o).toLowerCase();s.push(t.bold(`${u}`)+t.fg("dim",` (${c} context)`)),s.push(t.fg("muted",`${p}[${c}]`)),s.push(`${t.bold(xe(i))}${t.fg("dim",`/${c} tokens`)}`+t.fg("muted",` (${pLe(i,o)})`)),s.push(""),s.push(t.fg("muted","Estimated usage by category"));for(let m of r){let g=t.fg(m.color,m.glyph),h=m.label,T=xe(m.tokens),y=pLe(m.tokens,o);s.push(`${g} ${h}: ${t.bold(T)} ${t.fg("dim",`tokens (${y})`)}`)}let d=t.fg("dim",dLe);if(s.push(`${d} Free space: ${t.bold(xe(l))} ${t.fg("dim",`(${pLe(l,o)})`)}`),a>0){let m=t.fg("warning",s9s);s.push(`${m} Autocompact buffer: ${t.bold(xe(a))} ${t.fg("dim",`tokens (${pLe(a,o)})`)}`)}let f=e.snapcompact;if(f)if(s.push(""),!f.visionCapable)s.push(t.fg("muted","Snapcompact: inactive (model has no image input)"));else{if(s.push(t.fg("muted","Snapcompact (estimated wire savings)")),f.systemPrompt){let m=f.systemPrompt;if(m.applied)s.push(` System prompt (${m.scope==="agents-md"?"AGENTS.md":"all"}): saves ${t.bold(`~${xe(m.savedTokens)}`)} `+t.fg("dim",`(${xe(m.textTokens)} text \u2192 ${m.frames} frame${m.frames===1?"":"s"} \u2248 ${xe(m.imageTokens)})`));else{let g=m.reason==="budget"?"image budget exhausted":m.reason==="empty"?"nothing to image":"frames would not save tokens";s.push(` System prompt (${m.scope==="agents-md"?"AGENTS.md":"all"}): ${t.fg("dim",`stays text (${g})`)}`)}}if(f.toolResults){let m=f.toolResults;if(m.swapped>0)s.push(` Tool results: saves ${t.bold(`~${xe(m.savedTokens)}`)} `+t.fg("dim",`(${m.swapped}/${m.total} imaged, ${xe(m.textTokens)} text \u2192 ${m.frames} frames \u2248 ${xe(m.imageTokens)})`));else s.push(` Tool results: ${t.fg("dim",`none imaged (${m.total} in history)`)}`)}if(f.savedTokens>0)s.push(` Next request: ${t.bold(`~${xe(Math.max(0,i-f.savedTokens))}`)} ${t.fg("dim","tokens on the wire")}`)}return s}function r9s(e,t){if(e.contextWindow<=0)return t.fg("muted","Context usage is unavailable: no model is selected for this session.");let s=uVr(e),n=pVr(e,t),o=Math.max(sCt,n.length),r=[];for(let i=0;i<o;i++){let a="";if(i<sCt){let p=[];for(let c=0;c<cLe;c++){let d=s[i*cLe+c];p.push(t.fg(d.color,d.glyph))}a=p.join(" ")}else a=" ".repeat(cLe*2-1);let l=n[i]??"",u=l.length>0?`${a}${rVr}${l}`:a;r.push(u)}return r.join(`
|
|
5116
5116
|
`)}var cLe=20,sCt=10,PD,rVr=" ",uLe="\u26C1",iVr="\u26C3",dLe="\u26F6",s9s="\u26DD",nCt,oCt,rCt,t9s;var FD=S(()=>{JR();sl();B();a4();eCt();PD=cLe*sCt;nCt=[],oCt=[],rCt=[];t9s=Symbol("non-message-token-cache")});function Wl(e,t){return e.keybindings.getDisplayString(t)||"Disabled"}function i9s(e){let t=xoe(),s=t==="darwin",n=Eoe("alt",t),o=Eoe("super",t);return["**Navigation**","| Key | Action |","|-----|--------|","| `Arrow keys` | Move cursor / browse history (Up when empty) |",`| \`${n}+Left/Right\` | Move by word |`,s?`| \`Ctrl+A\` / \`Home\` / \`${o}+Left\` | Start of line |`:"| `Ctrl+A` / `Home` | Start of line |",s?`| \`Ctrl+E\` / \`End\` / \`${o}+Right\` | End of line |`:"| `Ctrl+E` / `End` | End of line |","","**Editing**","| Key | Action |","|-----|--------|","| `Enter` | Send message |",`| \`Shift+Enter\` / \`${n}+Enter\` | New line |`,`| \`Ctrl+W\` / \`${n}+Backspace\` | Delete word backwards |`,"| `Ctrl+U` | Delete to start of line |","| `Ctrl+K` | Delete to end of line |",`| \`${Wl(e,"app.clipboard.copyLine")}\` | Copy current line |`,`| \`${Wl(e,"app.clipboard.copyPrompt")}\` | Copy whole prompt |`,"","**Other**","| Key | Action |","|-----|--------|","| `Tab` | Path completion / accept autocomplete |",`| \`${Wl(e,"app.interrupt")}\` | Cancel autocomplete / interrupt active work |`,`| \`${Wl(e,"app.clear")}\` | Clear editor (first) / exit (second) |`,`| \`${Wl(e,"app.exit")}\` | Exit (saves current prompt as draft) |`,`| \`${Wl(e,"app.suspend")}\` | Suspend to background |`,`| \`${Wl(e,"app.display.reset")}\` | Reset terminal display |`,`| \`${Wl(e,"app.thinking.cycle")}\` | Cycle thinking level |`,`| \`${Wl(e,"app.model.cycleForward")}\` | Cycle role models (slow/default/smol) |`,`| \`${Wl(e,"app.model.cycleBackward")}\` | Cycle role models (backward) |`,`| \`${Wl(e,"app.model.selectTemporary")}\` | Select model (temporary) |`,`| \`${Wl(e,"app.model.select")}\` | Select model (set roles) |`,`| \`${Wl(e,"app.plan.toggle")}\` | Toggle plan mode |`,`| \`${Wl(e,"app.history.search")}\` | Search prompt history |`,`| \`${Wl(e,"app.tools.expand")}\` | Toggle tool output expansion |`,`| \`${Wl(e,"app.tools.toggleVisibility")}\` | Toggle tool activity visibility |`,`| \`${Wl(e,"app.thinking.toggle")}\` | Toggle thinking block visibility |`,`| \`${Wl(e,"app.editor.external")}\` | Edit message in external editor |`,`| \`${Wl(e,"app.retry")}\` | Retry last failed assistant turn |`,`| \`${Wl(e,"app.clipboard.pasteImage")}\` | Paste image or text from clipboard |`,"| Hold `Space` | Speech-to-text (push-to-talk): hold to record, release to transcribe |",`| \`${Wl(e,"app.live.toggle")}\` | Start/stop live voice mode (/live) |`,`| \`${Wl(e,"app.agents.hub")}\` / \`${Wl(e,"app.session.observe")}\` / double-tap \`\u2190\` (empty editor) | Open the agent hub |`,"| `#<number>` | GitHub issue/PR reference (e.g. `#3164` \u2192 `pr://`/`issue://`) |","| `#` / `#<text>` | Prompt actions (copy / undo / move cursor) |","| `/` | Slash commands |","| `!` | Run bash command |","| `!!` | Run bash command (excluded from context) |","| `$` | Run Python in shared kernel |","| `$$` | Run Python (excluded from context) |"].join(`
|
|
5117
5117
|
`)}var a9s=S(()=>{mL()});function l9s(e){return e.replace(/\|/g,"\\|").replace(/\r?\n+/g," ").trim()}function u9s(e){if(e.tools.length===0&&!e.xdevTools?.length)return"No tools are currently visible to the agent.";let t=[];for(let s of e.tools){let n=l9s(s.description)||"No description provided.";t.push(`| \`${s.name}\` | ${n} |`)}for(let s of e.xdevTools??[])t.push(`| \`xd://${s.name}\` | ${l9s(s.summary)||"No description provided."} |`);return["| Tool | Description |","|------|-------------|",...t].join(`
|
|
5118
|
-
`)}function gLe(e){if(e.mode==="images"){let s=e.imagesDropped??0;return s===0?"No images found in this session.":`Dropped ${s} image${s===1?"":"s"} from this session.`}if(e.mode==="thinking"){let s=e.thinkingBlocksDropped??0;return s===0?"No thinking blocks found in this session.":`Dropped ${s} thinking block${s===1?"":"s"} from this session.`}let t=[];if(e.toolResultsDropped>0)t.push(`${e.toolResultsDropped} tool result${e.toolResultsDropped===1?"":"s"}`);if(e.blocksDropped>0)t.push(`${e.blocksDropped} block${e.blocksDropped===1?"":"s"}`);if(t.length===0)return"Nothing to shake.";return`Shook ${t.join(" + ")} (~${e.tokensFreed} tokens freed).`}function DS(e){return typeof e==="string"&&e.trim()?e.trim().toLowerCase():void 0}function hLe(e){if(!e)return;let t=e.email||e.accountId||e.projectId;if(!t)return;let s=e.orgName||e.orgId;return s&&s!==t?`${t} (${s})`:t}function s8(e,t,s){if(!s)return!1;let n=e.metadata??{},o=DS(s.accountId),r=DS(s.email),i=DS(s.projectId),a=DS(s.orgId),l=DS(n.orgId);if(a||l){if(a!==l)return!1;if(!o&&!r&&!i)return!0}if(o){if((DS(n.accountId)??DS(n.account_id))===o)return!0;if(DS(t.scope.accountId)===o)return!0}if(r&&DS(n.email)===r)return!0;if(i){if(DS(n.projectId)===i)return!0;if(DS(t.scope.projectId)===i)return!0}return!1}function TLe(e,t){if(!t)return!1;return e.limits.some((s)=>s8(e,s,t))}function aCt(e,t){return typeof t==="string"?e.getFgAnsi(t):t.ansi}function d9s(e,t){let s=t,n=s[c9s];if(n&&s[p9s]===e)return n;let o=aCt(e,t.low),r=aCt(e,t.mid),i=aCt(e,t.high),a=t.bold?`${fVr}${i}`:i,l=t.bold?`${mVr}${yLe}`:yLe,u={low:{open:o,close:yLe},mid:{open:r,close:yLe},high:{open:a,close:l}};return s[p9s]=e,s[c9s]=u,u}function hVr(e,t,s){let n=s+ele*2,o=e/1000*RLe%n,r=Math.abs(t+ele-o);if(r>=CLe)return 0;return 0.5*(1+Math.cos(Math.PI*r/CLe))}function TVr(e,t,s){let n=s-1;if(n<=0)return 1;let o=2*n,r=e/1000*RLe%o,i=r<n,a=i?r:o-r,l=t-a;if((l<0?-l:l)<=YW)return 1;let p=i?-l:l;if(p<=YW)return 0;let c=(p-YW)/lCt;if(c>=1)return 0;let d=1-c;return d*d}function yVr(e){if(e>=cVr)return"high";if(e>=dVr)return"mid";return"low"}function f9s(){if(!rl())return"classic";return ge.get("display.shimmer")}function _D(){return f9s()!=="disabled"}function RVr(e,t){let s=f9s(),n=0,o=[];for(let c of e)n+=bVr(c.text),o.push({text:c.text,palette:c.palette??gVr});if(n===0)return"";if(s==="disabled"){let c="";for(let{text:d,palette:f}of o){let m=d9s(t,f).mid;c+=`${m.open}${d}${m.close}`}return c}let r=Date.now(),i=s==="kitt"?TVr:hVr,{lo:a,hi:l}=CVr(s,r,n),u="",p=0;for(let{text:c,palette:d}of o){let f=d9s(t,d),m=null,g=0,h=0,T=0;while(T<c.length){let y=c.charCodeAt(T),R=1;if(y>=55296&&y<=56319&&T+1<c.length){let b=c.charCodeAt(T+1);if(b>=56320&&b<=57343)R=2}let C=p<a||p>l?"low":yVr(i(r,p,n));if(C!==m){if(m!==null&&h>g){let b=f[m];u+=`${b.open}${c.slice(g,h)}${b.close}`}m=C,g=T}h=T+R,p++,T+=R}if(m!==null&&h>g){let y=f[m];u+=`${y.open}${c.slice(g,h)}${y.close}`}}return u}function CVr(e,t,s){if(e==="classic"){let l=s+ele*2,u=t/1000*RLe%l;return{lo:u-ele-CLe,hi:u-ele+CLe}}let n=s-1;if(n<=0)return{lo:0,hi:s};let o=2*n,r=t/1000*RLe%o,i=r<n,a=i?r:o-r;return i?{lo:a-YW-lCt,hi:a+YW}:{lo:a-YW,hi:a+YW+lCt}}function bVr(e){let t=0,s=0;while(s<e.length){let n=e.charCodeAt(s);if(n>=55296&&n<=56319&&s+1<e.length){let o=e.charCodeAt(s+1);if(o>=56320&&o<=57343){s+=2,t++;continue}}s++,t++}return t}function NS(e,t,s){return RVr([{text:e,palette:s}],t)}var RLe=30,ele=10,CLe=6,YW=0.6,lCt=7,cVr=0.65,dVr=0.22,yLe="\x1B[39m",fVr="\x1B[1m",mVr="\x1B[22m",gVr,p9s,c9s;var tle=S(()=>{Gt();gVr={low:"dim",mid:"muted",high:"accent",bold:!0},p9s=Symbol("shimmer.compiledFor"),c9s=Symbol("shimmer.compiled")});function n8(e){return e.split(/[-_]/g).map((t)=>t?t[0].toUpperCase()+t.slice(1):"").join(" ")}function gy(e){let t=Math.max(0,Math.round(e/1000));if(t<60)return`${t}s`;let s=Math.round(t/60);if(s<60)return`${s}m`;let n=Math.round(s/60);if(n<48)return`${n}h`;return`${Math.round(n/24)}d`}function SVr(e){return e??k??kVr}function o8(e,t=24,s){let n=SVr(s);if(e===void 0)return`[${NS("\xB7".repeat(t),n)}]`;let o=Math.min(Math.max(e,0),1),r=Math.round(o*t),i=Math.round(o*100),a=`${"\u2588".repeat(r)}${"\u2591".repeat(Math.max(0,t-r))}`;return`[${NS(a,n)}] ${i}%`}var kVr;var M0=S(()=>{tle();Le();kVr={fg(e,t){return t},bold(e){return e},getFgAnsi(){return""}}});var uCt="./CHANGELOG-
|
|
5118
|
+
`)}function gLe(e){if(e.mode==="images"){let s=e.imagesDropped??0;return s===0?"No images found in this session.":`Dropped ${s} image${s===1?"":"s"} from this session.`}if(e.mode==="thinking"){let s=e.thinkingBlocksDropped??0;return s===0?"No thinking blocks found in this session.":`Dropped ${s} thinking block${s===1?"":"s"} from this session.`}let t=[];if(e.toolResultsDropped>0)t.push(`${e.toolResultsDropped} tool result${e.toolResultsDropped===1?"":"s"}`);if(e.blocksDropped>0)t.push(`${e.blocksDropped} block${e.blocksDropped===1?"":"s"}`);if(t.length===0)return"Nothing to shake.";return`Shook ${t.join(" + ")} (~${e.tokensFreed} tokens freed).`}function DS(e){return typeof e==="string"&&e.trim()?e.trim().toLowerCase():void 0}function hLe(e){if(!e)return;let t=e.email||e.accountId||e.projectId;if(!t)return;let s=e.orgName||e.orgId;return s&&s!==t?`${t} (${s})`:t}function s8(e,t,s){if(!s)return!1;let n=e.metadata??{},o=DS(s.accountId),r=DS(s.email),i=DS(s.projectId),a=DS(s.orgId),l=DS(n.orgId);if(a||l){if(a!==l)return!1;if(!o&&!r&&!i)return!0}if(o){if((DS(n.accountId)??DS(n.account_id))===o)return!0;if(DS(t.scope.accountId)===o)return!0}if(r&&DS(n.email)===r)return!0;if(i){if(DS(n.projectId)===i)return!0;if(DS(t.scope.projectId)===i)return!0}return!1}function TLe(e,t){if(!t)return!1;return e.limits.some((s)=>s8(e,s,t))}function aCt(e,t){return typeof t==="string"?e.getFgAnsi(t):t.ansi}function d9s(e,t){let s=t,n=s[c9s];if(n&&s[p9s]===e)return n;let o=aCt(e,t.low),r=aCt(e,t.mid),i=aCt(e,t.high),a=t.bold?`${fVr}${i}`:i,l=t.bold?`${mVr}${yLe}`:yLe,u={low:{open:o,close:yLe},mid:{open:r,close:yLe},high:{open:a,close:l}};return s[p9s]=e,s[c9s]=u,u}function hVr(e,t,s){let n=s+ele*2,o=e/1000*RLe%n,r=Math.abs(t+ele-o);if(r>=CLe)return 0;return 0.5*(1+Math.cos(Math.PI*r/CLe))}function TVr(e,t,s){let n=s-1;if(n<=0)return 1;let o=2*n,r=e/1000*RLe%o,i=r<n,a=i?r:o-r,l=t-a;if((l<0?-l:l)<=YW)return 1;let p=i?-l:l;if(p<=YW)return 0;let c=(p-YW)/lCt;if(c>=1)return 0;let d=1-c;return d*d}function yVr(e){if(e>=cVr)return"high";if(e>=dVr)return"mid";return"low"}function f9s(){if(!rl())return"classic";return ge.get("display.shimmer")}function _D(){return f9s()!=="disabled"}function RVr(e,t){let s=f9s(),n=0,o=[];for(let c of e)n+=bVr(c.text),o.push({text:c.text,palette:c.palette??gVr});if(n===0)return"";if(s==="disabled"){let c="";for(let{text:d,palette:f}of o){let m=d9s(t,f).mid;c+=`${m.open}${d}${m.close}`}return c}let r=Date.now(),i=s==="kitt"?TVr:hVr,{lo:a,hi:l}=CVr(s,r,n),u="",p=0;for(let{text:c,palette:d}of o){let f=d9s(t,d),m=null,g=0,h=0,T=0;while(T<c.length){let y=c.charCodeAt(T),R=1;if(y>=55296&&y<=56319&&T+1<c.length){let b=c.charCodeAt(T+1);if(b>=56320&&b<=57343)R=2}let C=p<a||p>l?"low":yVr(i(r,p,n));if(C!==m){if(m!==null&&h>g){let b=f[m];u+=`${b.open}${c.slice(g,h)}${b.close}`}m=C,g=T}h=T+R,p++,T+=R}if(m!==null&&h>g){let y=f[m];u+=`${y.open}${c.slice(g,h)}${y.close}`}}return u}function CVr(e,t,s){if(e==="classic"){let l=s+ele*2,u=t/1000*RLe%l;return{lo:u-ele-CLe,hi:u-ele+CLe}}let n=s-1;if(n<=0)return{lo:0,hi:s};let o=2*n,r=t/1000*RLe%o,i=r<n,a=i?r:o-r;return i?{lo:a-YW-lCt,hi:a+YW}:{lo:a-YW,hi:a+YW+lCt}}function bVr(e){let t=0,s=0;while(s<e.length){let n=e.charCodeAt(s);if(n>=55296&&n<=56319&&s+1<e.length){let o=e.charCodeAt(s+1);if(o>=56320&&o<=57343){s+=2,t++;continue}}s++,t++}return t}function NS(e,t,s){return RVr([{text:e,palette:s}],t)}var RLe=30,ele=10,CLe=6,YW=0.6,lCt=7,cVr=0.65,dVr=0.22,yLe="\x1B[39m",fVr="\x1B[1m",mVr="\x1B[22m",gVr,p9s,c9s;var tle=S(()=>{Gt();gVr={low:"dim",mid:"muted",high:"accent",bold:!0},p9s=Symbol("shimmer.compiledFor"),c9s=Symbol("shimmer.compiled")});function n8(e){return e.split(/[-_]/g).map((t)=>t?t[0].toUpperCase()+t.slice(1):"").join(" ")}function gy(e){let t=Math.max(0,Math.round(e/1000));if(t<60)return`${t}s`;let s=Math.round(t/60);if(s<60)return`${s}m`;let n=Math.round(s/60);if(n<48)return`${n}h`;return`${Math.round(n/24)}d`}function SVr(e){return e??k??kVr}function o8(e,t=24,s){let n=SVr(s);if(e===void 0)return`[${NS("\xB7".repeat(t),n)}]`;let o=Math.min(Math.max(e,0),1),r=Math.round(o*t),i=Math.round(o*100),a=`${"\u2588".repeat(r)}${"\u2591".repeat(Math.max(0,t-r))}`;return`[${NS(a,n)}] ${i}%`}var kVr;var M0=S(()=>{tle();Le();kVr={fg(e,t){return t},bold(e){return e},getFgAnsi(){return""}}});var uCt="./CHANGELOG-ynmfayhn.md";var m9s=()=>{};import*as bLe from"path";function EVr(e){return{markdown:void 0,persistCurrentVersion:e,truncated:!1,selectedEntries:0,totalUnseenEntries:0,latestVersion:void 0,changeCount:0,categoryCounts:{}}}function MVr(e){let t={},s=0;for(let n of e){let o;for(let r of n.content.split(`
|
|
5119
5119
|
`)){let i=r.match(/^###\s+(.+?)\s*$/);if(i){o=i[1];continue}if(!o||!/^-\s+\S/.test(r))continue;t[o]=(t[o]??0)+1,s++}}return{changeCount:s,categoryCounts:t}}function AVr(e,t){if(e==="Breaking Changes")return t===1?"breaking change":"breaking changes";return e.toLowerCase()}function R9s(e){let t=e.latestVersion;if(!t||e.selectedEntries===0)return"Updated omp. Use /changelog for recent changes.";let{selectedEntries:s,changeCount:n}=e,o=s===1?"release":"releases",r=n===1?"change":"changes",i=s===1?`Updated to v${t} \xB7 ${n} ${r} in 1 release`:`Updated to v${t} \xB7 ${n} ${r} across ${s} ${o}`,l=[...g9s.filter((c)=>e.categoryCounts[c]),...Object.keys(e.categoryCounts).filter((c)=>!g9s.includes(c)).sort()].map((c)=>`${e.categoryCounts[c]} ${AVr(c,e.categoryCounts[c])}`).join(" \xB7 "),u=e.totalUnseenEntries-e.selectedEntries,p=u>0?`+${u} earlier ${u===1?"release":"releases"} \xB7 Use /changelog full for history.`:"Use /changelog for details.";return l?`${i}
|
|
5120
5120
|
${l} \xB7 ${p}`:`${i}
|
|
5121
5121
|
${p}`}function C9s(e,t){if(bLe.isAbsolute(e)||bLe.win32.isAbsolute(e))return e;return new URL(e,t)}async function kLe(e){let t;if(e)try{t=await Bun.file(e).text()}catch(s){if(!pe(s))v.error(`Warning: Could not parse changelog: ${s}`)}return t??=await Bun.file(C9s(uCt,import.meta.url)).text(),vVr(t)}function vVr(e){let t=e.split(`
|