@kaisers-io/refs 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/refs.mjs +54 -88
  2. package/package.json +2 -3
package/bin/refs.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as e}from"node:module";import{access as t,chmod as n,constants as r,copyFile as i,lstat as a,mkdir as o,readFile as s,readdir as c,realpath as l,rename as u,rm as d,rmdir as f,stat as p,writeFile as m}from"node:fs/promises";import h,{basename as g,dirname as _,isAbsolute as v,join as y,relative as ee,resolve as te,sep as ne}from"node:path";import{randomUUID as re}from"node:crypto";import ie,{appendFileSync as ae,createReadStream as oe,createWriteStream as se,existsSync as ce,readFileSync as le,realpathSync as ue,statSync as de,writeFileSync as fe}from"node:fs";import{constants as pe,homedir as me}from"node:os";import{scheduler as he,setImmediate as ge,setTimeout as _e}from"node:timers/promises";import{fileURLToPath as ve}from"node:url";import ye,{ChildProcess as be,execFile as xe,spawn as Se,spawnSync as Ce}from"node:child_process";import{StringDecoder as we}from"node:string_decoder";import{aborted as Te,callbackify as Ee,debuglog as De,inspect as Oe,promisify as ke,stripVTControlCharacters as Ae}from"node:util";import b,{execArgv as je,execPath as Me,hrtime as Ne,platform as Pe}from"node:process";import Fe from"node:tty";import{EventEmitter as Ie,addAbortListener as Le,on as Re,once as x,setMaxListeners as ze}from"node:events";import{serialize as Be}from"node:v8";import{finished as Ve}from"node:stream/promises";import{Duplex as He,PassThrough as Ue,Readable as We,Transform as Ge,Writable as Ke,getDefaultHighWaterMark as qe}from"node:stream";import{Buffer as Je}from"node:buffer";var Ye=Object.create,Xe=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,Qe=Object.getOwnPropertyNames,$e=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty,S=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),tt=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=Qe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!et.call(e,s)&&s!==n&&Xe(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=Ze(t,s))||r.enumerable});return e},nt=(e,t,n)=>(n=e==null?{}:Ye($e(e)),tt(t||!e||!e.__esModule?Xe(n,`default`,{value:e,enumerable:!0}):n,e)),rt=e(import.meta.url);const it={CONFLICT:5,NOT_FOUND:4,OK:0,UNEXPECTED:1,USAGE:2,VALIDATION:3};var at=class extends Error{code;exitCode;constructor(e,t,n,r){super(n,r),this.code=t,this.exitCode=e,this.name=`RefsError`}};const ot=e=>new at(it.CONFLICT,`conflict`,e),C=e=>new at(it.NOT_FOUND,`not_found`,e),w=e=>new at(it.USAGE,`usage`,e),T=e=>new at(it.VALIDATION,`validation`,e),st=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,ct=(e,t)=>e instanceof at?{code:e.code,exitCode:e.exitCode,message:st(e.message,e.stack,t.verbose)}:e instanceof Error?{code:`unexpected`,exitCode:it.UNEXPECTED,message:st(e.message,e.stack,t.verbose)}:{code:`unexpected`,exitCode:it.UNEXPECTED,message:String(e)};var lt;function E(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var ut=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},dt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(lt=globalThis).__zod_globalConfig??(lt.__zod_globalConfig={});const ft=globalThis.__zod_globalConfig;function pt(e){return e&&Object.assign(ft,e),ft}function mt(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function ht(e,t){return typeof t==`bigint`?t.toString():t}function gt(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}throw Error(`cached value already set`)}}}function _t(e){return e==null}function vt(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function yt(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}const bt=Symbol(`evaluating`);function D(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==bt)return r===void 0&&(r=bt,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function xt(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function St(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ct(e){return JSON.stringify(e)}function wt(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Tt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Dt=gt(()=>{if(ft.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Ot(e){if(Et(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Et(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function kt(e){return Ot(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const At=new Set([`string`,`number`,`symbol`]);function jt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Mt(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function O(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Nt(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const Pt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Ft(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return Mt(e,St(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return xt(this,`shape`,e),e},checks:[]}))}function It(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return Mt(e,St(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return xt(this,`shape`,r),r},checks:[]}))}function Lt(e,t){if(!Ot(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Mt(e,St(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return xt(this,`shape`,n),n}}))}function Rt(e,t){if(!Ot(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Mt(e,St(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return xt(this,`shape`,n),n}}))}function zt(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return Mt(e,St(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return xt(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Bt(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return Mt(t,St(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return xt(this,`shape`,i),i},checks:[]}))}function Vt(e,t,n){return Mt(t,St(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return xt(this,`shape`,i),i}}))}function Ht(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Ut(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function Wt(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Gt(e){return typeof e==`string`?e:e?.message}function Kt(e,t,n){let r=e.message?e.message:Gt(e.inst?._zod.def?.error?.(e))??Gt(t?.error?.(e))??Gt(n.customError?.(e))??Gt(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function qt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Jt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Yt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ht,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Xt=E(`$ZodError`,Yt),Zt=E(`$ZodError`,Yt,{Parent:Error});function Qt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function $t(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}function en(e){let t=[],n=e.map(e=>typeof e==`object`?e.key:e);for(let e of n)typeof e==`number`?t.push(`[${e}]`):typeof e==`symbol`?t.push(`[${JSON.stringify(String(e))}]`):/[^\w$]/.test(e)?t.push(`[${JSON.stringify(e)}]`):(t.length&&t.push(`.`),t.push(e));return t.join(``)}function k(e){let t=[],n=[...e.issues].sort((e,t)=>(e.path??[]).length-(t.path??[]).length);for(let e of n)t.push(`✖ ${e.message}`),e.path?.length&&t.push(` → at ${en(e.path)}`);return t.join(`
3
- `)}const tn=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new ut;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Kt(e,a,pt())));throw Tt(t,i?.callee),t}return o.value},nn=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Kt(e,a,pt())));throw Tt(t,i?.callee),t}return o.value},rn=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new ut;return a.issues.length?{success:!1,error:new(e??Xt)(a.issues.map(e=>Kt(e,i,pt())))}:{success:!0,data:a.value}},an=rn(Zt),on=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>Kt(e,i,pt())))}:{success:!0,data:a.value}},sn=on(Zt),cn=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return tn(e)(t,n,i)},ln=e=>(t,n,r)=>tn(e)(t,n,r),un=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return nn(e)(t,n,i)},dn=e=>async(t,n,r)=>nn(e)(t,n,r),fn=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return rn(e)(t,n,i)},pn=e=>(t,n,r)=>rn(e)(t,n,r),mn=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return on(e)(t,n,i)},hn=e=>async(t,n,r)=>on(e)(t,n,r),gn=/^[cC][0-9a-z]{6,}$/,_n=/^[0-9a-z]+$/,vn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,yn=/^[0-9a-vA-V]{20}$/,bn=/^[A-Za-z0-9]{27}$/,xn=/^[a-zA-Z0-9_-]{21}$/,Sn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Cn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,wn=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Tn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function En(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const Dn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,On=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,kn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,An=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,jn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Mn=/^[A-Za-z0-9_-]*$/,Nn=/^https?$/,Pn=/^\+[1-9]\d{6,14}$/,Fn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,In=RegExp(`^${Fn}$`);function Ln(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Rn(e){return RegExp(`^${Ln(e)}$`)}function zn(e){let t=Ln({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Fn}T(?:${r})$`)}const Bn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Vn=/^-?\d+$/,Hn=/^-?\d+(?:\.\d+)?$/,Un=/^[^A-Z]*$/,Wn=/^[^a-z]*$/,A=E(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Gn={number:`number`,bigint:`bigint`,object:`date`},Kn=E(`$ZodCheckLessThan`,(e,t)=>{A.init(e,t);let n=Gn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),qn=E(`$ZodCheckGreaterThan`,(e,t)=>{A.init(e,t);let n=Gn[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Jn=E(`$ZodCheckMultipleOf`,(e,t)=>{A.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):yt(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Yn=E(`$ZodCheckNumberFormat`,(e,t)=>{A.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Pt[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Vn)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Xn=E(`$ZodCheckMaxLength`,(e,t)=>{var n;A.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!_t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=qt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Zn=E(`$ZodCheckMinLength`,(e,t)=>{var n;A.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!_t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=qt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Qn=E(`$ZodCheckLengthEquals`,(e,t)=>{var n;A.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!_t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=qt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),$n=E(`$ZodCheckStringFormat`,(e,t)=>{var n,r;A.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),er=E(`$ZodCheckRegex`,(e,t)=>{$n.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),tr=E(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Un,$n.init(e,t)}),nr=E(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Wn,$n.init(e,t)}),rr=E(`$ZodCheckIncludes`,(e,t)=>{A.init(e,t);let n=jt(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),ir=E(`$ZodCheckStartsWith`,(e,t)=>{A.init(e,t);let n=RegExp(`^${jt(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),ar=E(`$ZodCheckEndsWith`,(e,t)=>{A.init(e,t);let n=RegExp(`.*${jt(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),or=E(`$ZodCheckOverwrite`,(e,t)=>{A.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var sr=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
2
+ import{access as e,chmod as t,constants as n,copyFile as r,lstat as i,mkdir as a,readFile as o,readdir as s,realpath as c,rename as l,rm as u,rmdir as d,stat as f,writeFile as ee}from"node:fs/promises";import p,{basename as te,dirname as ne,isAbsolute as re,join as m,relative as ie,resolve as ae,sep as oe}from"node:path";import{randomUUID as se}from"node:crypto";import ce,{existsSync as le,realpathSync as ue}from"node:fs";import{homedir as de}from"node:os";import{setTimeout as fe}from"node:timers/promises";import{EventEmitter as pe,once as me}from"node:events";import he,{spawn as ge}from"node:child_process";import h from"node:process";import{stripVTControlCharacters as _e}from"node:util";const g={CONFLICT:5,NOT_FOUND:4,OK:0,UNEXPECTED:1,USAGE:2,VALIDATION:3};var _=class extends Error{code;exitCode;constructor(e,t,n,r){super(n,r),this.code=t,this.exitCode=e,this.name=`RefsError`}};const ve=e=>new _(g.CONFLICT,`conflict`,e),v=e=>new _(g.NOT_FOUND,`not_found`,e),y=e=>new _(g.USAGE,`usage`,e),b=e=>new _(g.VALIDATION,`validation`,e),ye=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,be=(e,t)=>e instanceof _?{code:e.code,exitCode:e.exitCode,message:ye(e.message,e.stack,t.verbose)}:e instanceof Error?{code:`unexpected`,exitCode:g.UNEXPECTED,message:ye(e.message,e.stack,t.verbose)}:{code:`unexpected`,exitCode:g.UNEXPECTED,message:String(e)};var xe;function x(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var Se=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Ce=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(xe=globalThis).__zod_globalConfig??(xe.__zod_globalConfig={});const we=globalThis.__zod_globalConfig;function S(e){return e&&Object.assign(we,e),we}function Te(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Ee(e,t){return typeof t==`bigint`?t.toString():t}function De(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}throw Error(`cached value already set`)}}}function Oe(e){return e==null}function ke(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Ae(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}const je=Symbol(`evaluating`);function C(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==je)return r===void 0&&(r=je,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Me(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function w(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ne(e){return JSON.stringify(e)}function Pe(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Fe=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Ie(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Le=De(()=>{if(we.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Re(e){if(Ie(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Ie(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function ze(e){return Re(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Be=new Set([`string`,`number`,`symbol`]);function Ve(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function T(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function E(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function He(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}const Ue={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function We(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return T(e,w(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Me(this,`shape`,e),e},checks:[]}))}function Ge(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return T(e,w(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Me(this,`shape`,r),r},checks:[]}))}function Ke(e,t){if(!Re(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return T(e,w(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Me(this,`shape`,n),n}}))}function qe(e,t){if(!Re(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return T(e,w(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return Me(this,`shape`,n),n}}))}function Je(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return T(e,w(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return Me(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ye(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return T(t,w(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return Me(this,`shape`,i),i},checks:[]}))}function Xe(e,t,n){return T(t,w(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return Me(this,`shape`,i),i}}))}function Ze(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Qe(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function $e(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function et(e){return typeof e==`string`?e:e?.message}function D(e,t,n){let r=e.message?e.message:et(e.inst?._zod.def?.error?.(e))??et(t?.error?.(e))??et(n.customError?.(e))??et(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function tt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function nt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const rt=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Ee,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},it=x(`$ZodError`,rt),at=x(`$ZodError`,rt,{Parent:Error});function ot(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function st(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}function ct(e){let t=[],n=e.map(e=>typeof e==`object`?e.key:e);for(let e of n)typeof e==`number`?t.push(`[${e}]`):typeof e==`symbol`?t.push(`[${JSON.stringify(String(e))}]`):/[^\w$]/.test(e)?t.push(`[${JSON.stringify(e)}]`):(t.length&&t.push(`.`),t.push(e));return t.join(``)}function O(e){let t=[],n=[...e.issues].sort((e,t)=>(e.path??[]).length-(t.path??[]).length);for(let e of n)t.push(`✖ ${e.message}`),e.path?.length&&t.push(` → at ${ct(e.path)}`);return t.join(`
3
+ `)}const lt=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Se;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>D(e,a,S())));throw Fe(t,i?.callee),t}return o.value},ut=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>D(e,a,S())));throw Fe(t,i?.callee),t}return o.value},dt=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Se;return a.issues.length?{success:!1,error:new(e??it)(a.issues.map(e=>D(e,i,S())))}:{success:!0,data:a.value}},ft=dt(at),pt=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>D(e,i,S())))}:{success:!0,data:a.value}},mt=pt(at),ht=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return lt(e)(t,n,i)},gt=e=>(t,n,r)=>lt(e)(t,n,r),_t=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ut(e)(t,n,i)},vt=e=>async(t,n,r)=>ut(e)(t,n,r),yt=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return dt(e)(t,n,i)},bt=e=>(t,n,r)=>dt(e)(t,n,r),xt=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return pt(e)(t,n,i)},St=e=>async(t,n,r)=>pt(e)(t,n,r),Ct=/^[cC][0-9a-z]{6,}$/,wt=/^[0-9a-z]+$/,Tt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Et=/^[0-9a-vA-V]{20}$/,Dt=/^[A-Za-z0-9]{27}$/,Ot=/^[a-zA-Z0-9_-]{21}$/,kt=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,At=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,jt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Mt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function Nt(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const Pt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ft=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,It=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Lt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Rt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,zt=/^[A-Za-z0-9_-]*$/,Bt=/^https?$/,Vt=/^\+[1-9]\d{6,14}$/,Ht=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Ut=RegExp(`^${Ht}$`);function Wt(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Gt(e){return RegExp(`^${Wt(e)}$`)}function Kt(e){let t=Wt({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Ht}T(?:${r})$`)}const qt=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Jt=/^-?\d+$/,Yt=/^-?\d+(?:\.\d+)?$/,Xt=/^[^A-Z]*$/,Zt=/^[^a-z]*$/,k=x(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qt={number:`number`,bigint:`bigint`,object:`date`},$t=x(`$ZodCheckLessThan`,(e,t)=>{k.init(e,t);let n=Qt[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),en=x(`$ZodCheckGreaterThan`,(e,t)=>{k.init(e,t);let n=Qt[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tn=x(`$ZodCheckMultipleOf`,(e,t)=>{k.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):Ae(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nn=x(`$ZodCheckNumberFormat`,(e,t)=>{k.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Ue[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Jt)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),rn=x(`$ZodCheckMaxLength`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=tt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),an=x(`$ZodCheckMinLength`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=tt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),on=x(`$ZodCheckLengthEquals`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=tt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),sn=x(`$ZodCheckStringFormat`,(e,t)=>{var n,r;k.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),cn=x(`$ZodCheckRegex`,(e,t)=>{sn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),ln=x(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Xt,sn.init(e,t)}),un=x(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Zt,sn.init(e,t)}),dn=x(`$ZodCheckIncludes`,(e,t)=>{k.init(e,t);let n=Ve(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),fn=x(`$ZodCheckStartsWith`,(e,t)=>{k.init(e,t);let n=RegExp(`^${Ve(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),pn=x(`$ZodCheckEndsWith`,(e,t)=>{k.init(e,t);let n=RegExp(`.*${Ve(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),mn=x(`$ZodCheckOverwrite`,(e,t)=>{k.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var hn=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
4
4
  `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
5
- `))}};const cr={major:4,minor:4,patch:3},j=E(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=cr;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=Ht(e),i;for(let a of t){if(a._zod.def.when){if(Ut(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new ut;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=Ht(e,t))});else{if(e.issues.length===t)continue;r||=Ht(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(Ht(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new ut;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new ut;return o.then(e=>t(e,r,a))}return t(o,r,a)}}D(e,`~standard`,()=>({validate:t=>{try{let n=an(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return sn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),lr=E(`$ZodString`,(e,t)=>{j.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Bn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),M=E(`$ZodStringFormat`,(e,t)=>{$n.init(e,t),lr.init(e,t)}),ur=E(`$ZodGUID`,(e,t)=>{t.pattern??=Cn,M.init(e,t)}),dr=E(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=wn(e)}else t.pattern??=wn();M.init(e,t)}),fr=E(`$ZodEmail`,(e,t)=>{t.pattern??=Tn,M.init(e,t)}),pr=E(`$ZodURL`,(e,t)=>{M.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===Nn.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),mr=E(`$ZodEmoji`,(e,t)=>{t.pattern??=En(),M.init(e,t)}),hr=E(`$ZodNanoID`,(e,t)=>{t.pattern??=xn,M.init(e,t)}),gr=E(`$ZodCUID`,(e,t)=>{t.pattern??=gn,M.init(e,t)}),_r=E(`$ZodCUID2`,(e,t)=>{t.pattern??=_n,M.init(e,t)}),vr=E(`$ZodULID`,(e,t)=>{t.pattern??=vn,M.init(e,t)}),yr=E(`$ZodXID`,(e,t)=>{t.pattern??=yn,M.init(e,t)}),br=E(`$ZodKSUID`,(e,t)=>{t.pattern??=bn,M.init(e,t)}),xr=E(`$ZodISODateTime`,(e,t)=>{t.pattern??=zn(t),M.init(e,t)}),Sr=E(`$ZodISODate`,(e,t)=>{t.pattern??=In,M.init(e,t)}),Cr=E(`$ZodISOTime`,(e,t)=>{t.pattern??=Rn(t),M.init(e,t)}),wr=E(`$ZodISODuration`,(e,t)=>{t.pattern??=Sn,M.init(e,t)}),Tr=E(`$ZodIPv4`,(e,t)=>{t.pattern??=Dn,M.init(e,t),e._zod.bag.format=`ipv4`}),Er=E(`$ZodIPv6`,(e,t)=>{t.pattern??=On,M.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Dr=E(`$ZodCIDRv4`,(e,t)=>{t.pattern??=kn,M.init(e,t)}),Or=E(`$ZodCIDRv6`,(e,t)=>{t.pattern??=An,M.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function kr(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Ar=E(`$ZodBase64`,(e,t)=>{t.pattern??=jn,M.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{kr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function jr(e){if(!Mn.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return kr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Mr=E(`$ZodBase64URL`,(e,t)=>{t.pattern??=Mn,M.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{jr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Nr=E(`$ZodE164`,(e,t)=>{t.pattern??=Pn,M.init(e,t)});function Pr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Fr=E(`$ZodJWT`,(e,t)=>{M.init(e,t),e._zod.check=n=>{Pr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Ir=E(`$ZodNumber`,(e,t)=>{j.init(e,t),e._zod.pattern=e._zod.bag.pattern??Hn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Lr=E(`$ZodNumberFormat`,(e,t)=>{Yn.init(e,t),Ir.init(e,t)}),Rr=E(`$ZodUnknown`,(e,t)=>{j.init(e,t),e._zod.parse=e=>e}),zr=E(`$ZodNever`,(e,t)=>{j.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Br(e,t,n){e.issues.length&&t.issues.push(...Wt(n,e.issues)),t.value[n]=e.value}const Vr=E(`$ZodArray`,(e,t)=>{j.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Br(t,n,e))):Br(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Hr(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...Wt(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Ur(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=Nt(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Wr(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Hr(e,n,i,t,u,d))):Hr(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const Gr=E(`$ZodObject`,(e,t)=>{if(j.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=gt(()=>Ur(t));D(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=Et,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>Hr(n,t,e,s,r,i))):Hr(a,t,e,s,r,i)}return i?Wr(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Kr=E(`$ZodObjectJIT`,(e,t)=>{Gr.init(e,t);let n=e._zod.parse,r=gt(()=>Ur(t)),i=e=>{let t=new sr([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Ct(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=Ct(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
5
+ `))}};const gn={major:4,minor:4,patch:3},A=x(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=gn;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=Ze(e),i;for(let a of t){if(a._zod.def.when){if(Qe(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new Se;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=Ze(e,t))});else{if(e.issues.length===t)continue;r||=Ze(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(Ze(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new Se;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new Se;return o.then(e=>t(e,r,a))}return t(o,r,a)}}C(e,`~standard`,()=>({validate:t=>{try{let n=ft(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return mt(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),_n=x(`$ZodString`,(e,t)=>{A.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??qt(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),j=x(`$ZodStringFormat`,(e,t)=>{sn.init(e,t),_n.init(e,t)}),vn=x(`$ZodGUID`,(e,t)=>{t.pattern??=At,j.init(e,t)}),yn=x(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=jt(e)}else t.pattern??=jt();j.init(e,t)}),bn=x(`$ZodEmail`,(e,t)=>{t.pattern??=Mt,j.init(e,t)}),xn=x(`$ZodURL`,(e,t)=>{j.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===Bt.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Sn=x(`$ZodEmoji`,(e,t)=>{t.pattern??=Nt(),j.init(e,t)}),Cn=x(`$ZodNanoID`,(e,t)=>{t.pattern??=Ot,j.init(e,t)}),wn=x(`$ZodCUID`,(e,t)=>{t.pattern??=Ct,j.init(e,t)}),Tn=x(`$ZodCUID2`,(e,t)=>{t.pattern??=wt,j.init(e,t)}),En=x(`$ZodULID`,(e,t)=>{t.pattern??=Tt,j.init(e,t)}),Dn=x(`$ZodXID`,(e,t)=>{t.pattern??=Et,j.init(e,t)}),On=x(`$ZodKSUID`,(e,t)=>{t.pattern??=Dt,j.init(e,t)}),kn=x(`$ZodISODateTime`,(e,t)=>{t.pattern??=Kt(t),j.init(e,t)}),An=x(`$ZodISODate`,(e,t)=>{t.pattern??=Ut,j.init(e,t)}),jn=x(`$ZodISOTime`,(e,t)=>{t.pattern??=Gt(t),j.init(e,t)}),Mn=x(`$ZodISODuration`,(e,t)=>{t.pattern??=kt,j.init(e,t)}),Nn=x(`$ZodIPv4`,(e,t)=>{t.pattern??=Pt,j.init(e,t),e._zod.bag.format=`ipv4`}),Pn=x(`$ZodIPv6`,(e,t)=>{t.pattern??=Ft,j.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Fn=x(`$ZodCIDRv4`,(e,t)=>{t.pattern??=It,j.init(e,t)}),In=x(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Lt,j.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Ln(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Rn=x(`$ZodBase64`,(e,t)=>{t.pattern??=Rt,j.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Ln(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function zn(e){if(!zt.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Ln(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Bn=x(`$ZodBase64URL`,(e,t)=>{t.pattern??=zt,j.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{zn(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Vn=x(`$ZodE164`,(e,t)=>{t.pattern??=Vt,j.init(e,t)});function Hn(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Un=x(`$ZodJWT`,(e,t)=>{j.init(e,t),e._zod.check=n=>{Hn(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Wn=x(`$ZodNumber`,(e,t)=>{A.init(e,t),e._zod.pattern=e._zod.bag.pattern??Yt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Gn=x(`$ZodNumberFormat`,(e,t)=>{nn.init(e,t),Wn.init(e,t)}),Kn=x(`$ZodUnknown`,(e,t)=>{A.init(e,t),e._zod.parse=e=>e}),qn=x(`$ZodNever`,(e,t)=>{A.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Jn(e,t,n){e.issues.length&&t.issues.push(...$e(n,e.issues)),t.value[n]=e.value}const Yn=x(`$ZodArray`,(e,t)=>{A.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Jn(t,n,e))):Jn(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function Xn(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...$e(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Zn(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=He(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Qn(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Xn(e,n,i,t,u,d))):Xn(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const $n=x(`$ZodObject`,(e,t)=>{if(A.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=De(()=>Zn(t));C(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=Ie,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>Xn(n,t,e,s,r,i))):Xn(a,t,e,s,r,i)}return i?Qn(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),er=x(`$ZodObjectJIT`,(e,t)=>{$n.init(e,t);let n=e._zod.parse,r=De(()=>Zn(t)),i=e=>{let t=new hn([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=Ne(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=Ne(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
6
6
  if (${n}.issues.length) {
7
7
  if (${o} in input) {
8
8
  payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
@@ -61,9 +61,9 @@ import{createRequire as e}from"node:module";import{access as t,chmod as n,consta
61
61
  }
62
62
  }
63
63
 
64
- `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Et,s=!ft.jitless,c=s&&Dt.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Wr([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function qr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Ht(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Kt(e,r,pt())))}),t)}const Jr=E(`$ZodUnion`,(e,t)=>{j.init(e,t),D(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),D(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),D(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),D(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>vt(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>qr(t,r,e,i)):qr(o,r,e,i)}}),Yr=E(`$ZodIntersection`,(e,t)=>{j.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Zr(e,t,n)):Zr(e,i,a)}});function Xr(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ot(e)&&Ot(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=Xr(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=Xr(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Zr(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Ht(e))return e;let o=Xr(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const Qr=E(`$ZodRecord`,(e,t)=>{j.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Ot(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>Kt(e,r,pt())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...Wt(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...Wt(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Hn.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Kt(e,r,pt())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Wt(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Wt(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),$r=E(`$ZodEnum`,(e,t)=>{j.init(e,t);let n=mt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>At.has(typeof e)).map(e=>typeof e==`string`?jt(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),ei=E(`$ZodTransform`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new dt(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new ut;return n.value=i,n.fallback=!0,n}});function ti(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const ni=E(`$ZodOptional`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,D(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),D(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${vt(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>ti(e,r)):ti(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),ri=E(`$ZodExactOptional`,(e,t)=>{ni.init(e,t),D(e._zod,`values`,()=>t.innerType._zod.values),D(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ii=E(`$ZodNullable`,(e,t)=>{j.init(e,t),D(e._zod,`optin`,()=>t.innerType._zod.optin),D(e._zod,`optout`,()=>t.innerType._zod.optout),D(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${vt(e.source)}|null)$`):void 0}),D(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),ai=E(`$ZodDefault`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,D(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>oi(e,t)):oi(r,t)}});function oi(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const si=E(`$ZodPrefault`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,D(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),ci=E(`$ZodNonOptional`,(e,t)=>{j.init(e,t),D(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>li(t,e)):li(i,e)}});function li(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const ui=E(`$ZodCatch`,(e,t)=>{j.init(e,t),e._zod.optin=`optional`,D(e._zod,`optout`,()=>t.innerType._zod.optout),D(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Kt(e,n,pt()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Kt(e,n,pt()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),di=E(`$ZodPipe`,(e,t)=>{j.init(e,t),D(e._zod,`values`,()=>t.in._zod.values),D(e._zod,`optin`,()=>t.in._zod.optin),D(e._zod,`optout`,()=>t.out._zod.optout),D(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>fi(e,t.in,n)):fi(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>fi(e,t.out,n)):fi(r,t.out,n)}});function fi(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const pi=E(`$ZodPreprocess`,(e,t)=>{di.init(e,t)}),mi=E(`$ZodReadonly`,(e,t)=>{j.init(e,t),D(e._zod,`propValues`,()=>t.innerType._zod.propValues),D(e._zod,`values`,()=>t.innerType._zod.values),D(e._zod,`optin`,()=>t.innerType?._zod?.optin),D(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(hi):hi(r)}});function hi(e){return e.value=Object.freeze(e.value),e}const gi=E(`$ZodCustom`,(e,t)=>{A.init(e,t),j.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>_i(t,n,r,e));_i(i,n,r,e)}});function _i(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Jt(e))}}var vi,yi=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function bi(){return new yi}(vi=globalThis).__zod_globalRegistry??(vi.__zod_globalRegistry=bi());const xi=globalThis.__zod_globalRegistry;function Si(e,t){return new e({type:`string`,...O(t)})}function Ci(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...O(t)})}function wi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...O(t)})}function Ti(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...O(t)})}function Ei(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...O(t)})}function Di(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...O(t)})}function Oi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...O(t)})}function ki(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...O(t)})}function Ai(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...O(t)})}function ji(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...O(t)})}function Mi(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...O(t)})}function Ni(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...O(t)})}function Pi(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...O(t)})}function Fi(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...O(t)})}function Ii(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...O(t)})}function Li(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...O(t)})}function Ri(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...O(t)})}function zi(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...O(t)})}function Bi(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...O(t)})}function Vi(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...O(t)})}function Hi(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...O(t)})}function Ui(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...O(t)})}function Wi(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...O(t)})}function Gi(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...O(t)})}function Ki(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...O(t)})}function qi(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...O(t)})}function Ji(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...O(t)})}function Yi(e,t){return new e({type:`number`,checks:[],...O(t)})}function Xi(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...O(t)})}function Zi(e){return new e({type:`unknown`})}function Qi(e,t){return new e({type:`never`,...O(t)})}function $i(e,t){return new Kn({check:`less_than`,...O(t),value:e,inclusive:!1})}function ea(e,t){return new Kn({check:`less_than`,...O(t),value:e,inclusive:!0})}function ta(e,t){return new qn({check:`greater_than`,...O(t),value:e,inclusive:!1})}function na(e,t){return new qn({check:`greater_than`,...O(t),value:e,inclusive:!0})}function ra(e,t){return new Jn({check:`multiple_of`,...O(t),value:e})}function ia(e,t){return new Xn({check:`max_length`,...O(t),maximum:e})}function aa(e,t){return new Zn({check:`min_length`,...O(t),minimum:e})}function oa(e,t){return new Qn({check:`length_equals`,...O(t),length:e})}function sa(e,t){return new er({check:`string_format`,format:`regex`,...O(t),pattern:e})}function ca(e){return new tr({check:`string_format`,format:`lowercase`,...O(e)})}function la(e){return new nr({check:`string_format`,format:`uppercase`,...O(e)})}function ua(e,t){return new rr({check:`string_format`,format:`includes`,...O(t),includes:e})}function da(e,t){return new ir({check:`string_format`,format:`starts_with`,...O(t),prefix:e})}function fa(e,t){return new ar({check:`string_format`,format:`ends_with`,...O(t),suffix:e})}function pa(e){return new or({check:`overwrite`,tx:e})}function ma(e){return pa(t=>t.normalize(e))}function ha(){return pa(e=>e.trim())}function ga(){return pa(e=>e.toLowerCase())}function _a(){return pa(e=>e.toUpperCase())}function va(){return pa(e=>wt(e))}function ya(e,t,n){return new e({type:`array`,element:t,...O(n)})}function ba(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...O(n)})}function xa(e,t){let n=Sa(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Jt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Jt(r))}},e(t.value,t)),t);return n}function Sa(e,t){let n=new A({check:`custom`,...O(t)});return n._zod.check=e,n}function Ca(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??xi,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function N(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,N(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&P(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function wa(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
64
+ `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Ie,s=!we.jitless,c=s&&Le.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let ee=d.value;return o(ee)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Qn([],ee,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:ee,inst:e}),d)}});function tr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Ze(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>D(e,r,S())))}),t)}const nr=x(`$ZodUnion`,(e,t)=>{A.init(e,t),C(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),C(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),C(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),C(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>ke(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>tr(t,r,e,i)):tr(o,r,e,i)}}),rr=x(`$ZodIntersection`,(e,t)=>{A.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>ar(e,t,n)):ar(e,i,a)}});function ir(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Re(e)&&Re(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=ir(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ir(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function ar(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Ze(e))return e;let o=ir(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const or=x(`$ZodRecord`,(e,t)=>{A.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Re(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>D(e,r,S())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...$e(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...$e(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Yt.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>D(e,r,S())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...$e(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...$e(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),sr=x(`$ZodEnum`,(e,t)=>{A.init(e,t);let n=Te(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Be.has(typeof e)).map(e=>typeof e==`string`?Ve(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),cr=x(`$ZodTransform`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ce(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new Se;return n.value=i,n.fallback=!0,n}});function lr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const ur=x(`$ZodOptional`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),C(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ke(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>lr(e,r)):lr(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),dr=x(`$ZodExactOptional`,(e,t)=>{ur.init(e,t),C(e._zod,`values`,()=>t.innerType._zod.values),C(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),fr=x(`$ZodNullable`,(e,t)=>{A.init(e,t),C(e._zod,`optin`,()=>t.innerType._zod.optin),C(e._zod,`optout`,()=>t.innerType._zod.optout),C(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ke(e.source)}|null)$`):void 0}),C(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),pr=x(`$ZodDefault`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>mr(e,t)):mr(r,t)}});function mr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const hr=x(`$ZodPrefault`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),gr=x(`$ZodNonOptional`,(e,t)=>{A.init(e,t),C(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>_r(t,e)):_r(i,e)}});function _r(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const vr=x(`$ZodCatch`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`optout`,()=>t.innerType._zod.optout),C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>D(e,n,S()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>D(e,n,S()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),yr=x(`$ZodPipe`,(e,t)=>{A.init(e,t),C(e._zod,`values`,()=>t.in._zod.values),C(e._zod,`optin`,()=>t.in._zod.optin),C(e._zod,`optout`,()=>t.out._zod.optout),C(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>br(e,t.in,n)):br(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>br(e,t.out,n)):br(r,t.out,n)}});function br(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const xr=x(`$ZodPreprocess`,(e,t)=>{yr.init(e,t)}),Sr=x(`$ZodReadonly`,(e,t)=>{A.init(e,t),C(e._zod,`propValues`,()=>t.innerType._zod.propValues),C(e._zod,`values`,()=>t.innerType._zod.values),C(e._zod,`optin`,()=>t.innerType?._zod?.optin),C(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Cr):Cr(r)}});function Cr(e){return e.value=Object.freeze(e.value),e}const wr=x(`$ZodCustom`,(e,t)=>{k.init(e,t),A.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Tr(t,n,r,e));Tr(i,n,r,e)}});function Tr(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(nt(e))}}var Er,Dr=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Or(){return new Dr}(Er=globalThis).__zod_globalRegistry??(Er.__zod_globalRegistry=Or());const kr=globalThis.__zod_globalRegistry;function Ar(e,t){return new e({type:`string`,...E(t)})}function jr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...E(t)})}function Mr(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...E(t)})}function Nr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...E(t)})}function Pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...E(t)})}function Fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...E(t)})}function Ir(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...E(t)})}function Lr(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...E(t)})}function Rr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...E(t)})}function zr(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...E(t)})}function Br(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...E(t)})}function Vr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...E(t)})}function Hr(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...E(t)})}function Ur(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...E(t)})}function Wr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...E(t)})}function Gr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...E(t)})}function Kr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...E(t)})}function qr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...E(t)})}function Jr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...E(t)})}function Yr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...E(t)})}function Xr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...E(t)})}function Zr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...E(t)})}function Qr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...E(t)})}function $r(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...E(t)})}function ei(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...E(t)})}function ti(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...E(t)})}function ni(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...E(t)})}function ri(e,t){return new e({type:`number`,checks:[],...E(t)})}function ii(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...E(t)})}function ai(e){return new e({type:`unknown`})}function oi(e,t){return new e({type:`never`,...E(t)})}function si(e,t){return new $t({check:`less_than`,...E(t),value:e,inclusive:!1})}function ci(e,t){return new $t({check:`less_than`,...E(t),value:e,inclusive:!0})}function li(e,t){return new en({check:`greater_than`,...E(t),value:e,inclusive:!1})}function ui(e,t){return new en({check:`greater_than`,...E(t),value:e,inclusive:!0})}function di(e,t){return new tn({check:`multiple_of`,...E(t),value:e})}function fi(e,t){return new rn({check:`max_length`,...E(t),maximum:e})}function pi(e,t){return new an({check:`min_length`,...E(t),minimum:e})}function mi(e,t){return new on({check:`length_equals`,...E(t),length:e})}function hi(e,t){return new cn({check:`string_format`,format:`regex`,...E(t),pattern:e})}function gi(e){return new ln({check:`string_format`,format:`lowercase`,...E(e)})}function _i(e){return new un({check:`string_format`,format:`uppercase`,...E(e)})}function vi(e,t){return new dn({check:`string_format`,format:`includes`,...E(t),includes:e})}function yi(e,t){return new fn({check:`string_format`,format:`starts_with`,...E(t),prefix:e})}function bi(e,t){return new pn({check:`string_format`,format:`ends_with`,...E(t),suffix:e})}function xi(e){return new mn({check:`overwrite`,tx:e})}function Si(e){return xi(t=>t.normalize(e))}function Ci(){return xi(e=>e.trim())}function wi(){return xi(e=>e.toLowerCase())}function Ti(){return xi(e=>e.toUpperCase())}function Ei(){return xi(e=>Pe(e))}function Di(e,t,n){return new e({type:`array`,element:t,...E(n)})}function Oi(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...E(n)})}function ki(e,t){let n=Ai(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(nt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(nt(r))}},e(t.value,t)),t);return n}function Ai(e,t){let n=new k({check:`custom`,...E(t)});return n._zod.check=e,n}function ji(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??kr,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function M(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,M(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&N(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Mi(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
65
65
 
66
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ta(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Da(t,`input`,e.processors),output:Da(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function P(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return P(r.element,n);if(r.type===`set`)return P(r.valueType,n);if(r.type===`lazy`)return P(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return P(r.innerType,n);if(r.type===`intersection`)return P(r.left,n)||P(r.right,n);if(r.type===`record`||r.type===`map`)return P(r.keyType,n)||P(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:P(r.in,n)||P(r.out,n);if(r.type===`object`){for(let e in r.shape)if(P(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(P(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(P(e,n))return!0;return!!(r.rest&&P(r.rest,n))}return!1}const Ea=(e,t={})=>n=>{let r=Ca({...n,processors:t});return N(e,r),wa(r,e),Ta(r,e)},Da=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Ca({...i??{},target:a,io:t,processors:n});return N(e,o),wa(o,e),Ta(o,e)},Oa={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},ka=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Oa[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Aa=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},ja=(e,t,n,r)=>{n.not={}},Ma=(e,t,n,r)=>{let i=e._zod.def,a=mt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Na=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Pa=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Fa=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=N(a.element,t,{...r,path:[...r.path,`items`]})},Ia=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=N(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=N(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},La=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>N(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ra=(e,t,n,r)=>{let i=e._zod.def,a=N(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=N(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},za=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=N(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=N(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=N(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Ba=(e,t,n,r)=>{let i=e._zod.def,a=N(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Va=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ha=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Ua=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Wa=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Ga=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;N(o,t,r);let s=t.seen.get(e);s.ref=o},Ka=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},qa=(e,t,n,r)=>{let i=e._zod.def;N(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ja=E(`ZodISODateTime`,(e,t)=>{xr.init(e,t),R.init(e,t)});function Ya(e){return Gi(Ja,e)}const Xa=E(`ZodISODate`,(e,t)=>{Sr.init(e,t),R.init(e,t)});function Za(e){return Ki(Xa,e)}const Qa=E(`ZodISOTime`,(e,t)=>{Cr.init(e,t),R.init(e,t)});function $a(e){return qi(Qa,e)}const eo=E(`ZodISODuration`,(e,t)=>{wr.init(e,t),R.init(e,t)});function to(e){return Ji(eo,e)}const F=E(`ZodError`,(e,t)=>{Xt.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>$t(e,t)},flatten:{value:t=>Qt(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ht,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ht,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),no=tn(F),ro=nn(F),io=rn(F),ao=on(F),oo=cn(F),so=ln(F),co=un(F),lo=dn(F),uo=fn(F),fo=pn(F),po=mn(F),mo=hn(F),ho=new WeakMap;function go(e,t,n){let r=Object.getPrototypeOf(e),i=ho.get(r);if(i||(i=new Set,ho.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}const I=E(`ZodType`,(e,t)=>(j.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Da(e,`input`),output:Da(e,`output`)}}),e.toJSONSchema=Ea(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>no(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>io(e,t,n),e.parseAsync=async(t,n)=>ro(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ao(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>oo(e,t,n),e.decode=(t,n)=>so(e,t,n),e.encodeAsync=async(t,n)=>co(e,t,n),e.decodeAsync=async(t,n)=>lo(e,t,n),e.safeEncode=(t,n)=>uo(e,t,n),e.safeDecode=(t,n)=>fo(e,t,n),e.safeEncodeAsync=async(t,n)=>po(e,t,n),e.safeDecodeAsync=async(t,n)=>mo(e,t,n),go(e,`ZodType`,{check(...e){let t=this.def;return this.clone(St(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Mt(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ds(e,t))},superRefine(e,t){return this.check(Os(e,t))},overwrite(e){return this.check(pa(e))},optional(){return cs(this)},exactOptional(){return us(this)},nullable(){return fs(this)},nullish(){return cs(fs(this))},nonoptional(e){return vs(this,e)},array(){return qo(this)},or(e){return Qo([this,e])},and(e){return es(this,e)},transform(e){return Ss(this,os(e))},default(e){return ms(this,e)},prefault(e){return gs(this,e)},catch(e){return bs(this,e)},pipe(e){return Ss(this,e)},readonly(){return Ts(this)},describe(e){let t=this.clone();return xi.add(t,{description:e}),t},meta(...e){if(e.length===0)return xi.get(this);let t=this.clone();return xi.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return xi.get(e)?.description},configurable:!0}),e)),_o=E(`_ZodString`,(e,t)=>{lr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ka(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,go(e,`_ZodString`,{regex(...e){return this.check(sa(...e))},includes(...e){return this.check(ua(...e))},startsWith(...e){return this.check(da(...e))},endsWith(...e){return this.check(fa(...e))},min(...e){return this.check(aa(...e))},max(...e){return this.check(ia(...e))},length(...e){return this.check(oa(...e))},nonempty(...e){return this.check(aa(1,...e))},lowercase(e){return this.check(ca(e))},uppercase(e){return this.check(la(e))},trim(){return this.check(ha())},normalize(...e){return this.check(ma(...e))},toLowerCase(){return this.check(ga())},toUpperCase(){return this.check(_a())},slugify(){return this.check(va())}})}),vo=E(`ZodString`,(e,t)=>{lr.init(e,t),_o.init(e,t),e.email=t=>e.check(Ci(yo,t)),e.url=t=>e.check(ki(So,t)),e.jwt=t=>e.check(Wi(Lo,t)),e.emoji=t=>e.check(Ai(Co,t)),e.guid=t=>e.check(wi(bo,t)),e.uuid=t=>e.check(Ti(xo,t)),e.uuidv4=t=>e.check(Ei(xo,t)),e.uuidv6=t=>e.check(Di(xo,t)),e.uuidv7=t=>e.check(Oi(xo,t)),e.nanoid=t=>e.check(ji(wo,t)),e.guid=t=>e.check(wi(bo,t)),e.cuid=t=>e.check(Mi(To,t)),e.cuid2=t=>e.check(Ni(Eo,t)),e.ulid=t=>e.check(Pi(Do,t)),e.base64=t=>e.check(Vi(Po,t)),e.base64url=t=>e.check(Hi(Fo,t)),e.xid=t=>e.check(Fi(Oo,t)),e.ksuid=t=>e.check(Ii(ko,t)),e.ipv4=t=>e.check(Li(Ao,t)),e.ipv6=t=>e.check(Ri(jo,t)),e.cidrv4=t=>e.check(zi(Mo,t)),e.cidrv6=t=>e.check(Bi(No,t)),e.e164=t=>e.check(Ui(Io,t)),e.datetime=t=>e.check(Ya(t)),e.date=t=>e.check(Za(t)),e.time=t=>e.check($a(t)),e.duration=t=>e.check(to(t))});function L(e){return Si(vo,e)}const R=E(`ZodStringFormat`,(e,t)=>{M.init(e,t),_o.init(e,t)}),yo=E(`ZodEmail`,(e,t)=>{fr.init(e,t),R.init(e,t)}),bo=E(`ZodGUID`,(e,t)=>{ur.init(e,t),R.init(e,t)}),xo=E(`ZodUUID`,(e,t)=>{dr.init(e,t),R.init(e,t)}),So=E(`ZodURL`,(e,t)=>{pr.init(e,t),R.init(e,t)}),Co=E(`ZodEmoji`,(e,t)=>{mr.init(e,t),R.init(e,t)}),wo=E(`ZodNanoID`,(e,t)=>{hr.init(e,t),R.init(e,t)}),To=E(`ZodCUID`,(e,t)=>{gr.init(e,t),R.init(e,t)}),Eo=E(`ZodCUID2`,(e,t)=>{_r.init(e,t),R.init(e,t)}),Do=E(`ZodULID`,(e,t)=>{vr.init(e,t),R.init(e,t)}),Oo=E(`ZodXID`,(e,t)=>{yr.init(e,t),R.init(e,t)}),ko=E(`ZodKSUID`,(e,t)=>{br.init(e,t),R.init(e,t)}),Ao=E(`ZodIPv4`,(e,t)=>{Tr.init(e,t),R.init(e,t)}),jo=E(`ZodIPv6`,(e,t)=>{Er.init(e,t),R.init(e,t)}),Mo=E(`ZodCIDRv4`,(e,t)=>{Dr.init(e,t),R.init(e,t)}),No=E(`ZodCIDRv6`,(e,t)=>{Or.init(e,t),R.init(e,t)}),Po=E(`ZodBase64`,(e,t)=>{Ar.init(e,t),R.init(e,t)}),Fo=E(`ZodBase64URL`,(e,t)=>{Mr.init(e,t),R.init(e,t)}),Io=E(`ZodE164`,(e,t)=>{Nr.init(e,t),R.init(e,t)}),Lo=E(`ZodJWT`,(e,t)=>{Fr.init(e,t),R.init(e,t)}),Ro=E(`ZodNumber`,(e,t)=>{Ir.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Aa(e,t,n,r),go(e,`ZodNumber`,{gt(e,t){return this.check(ta(e,t))},gte(e,t){return this.check(na(e,t))},min(e,t){return this.check(na(e,t))},lt(e,t){return this.check($i(e,t))},lte(e,t){return this.check(ea(e,t))},max(e,t){return this.check(ea(e,t))},int(e){return this.check(Vo(e))},safe(e){return this.check(Vo(e))},positive(e){return this.check(ta(0,e))},nonnegative(e){return this.check(na(0,e))},negative(e){return this.check($i(0,e))},nonpositive(e){return this.check(ea(0,e))},multipleOf(e,t){return this.check(ra(e,t))},step(e,t){return this.check(ra(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function zo(e){return Yi(Ro,e)}const Bo=E(`ZodNumberFormat`,(e,t)=>{Lr.init(e,t),Ro.init(e,t)});function Vo(e){return Xi(Bo,e)}const Ho=E(`ZodUnknown`,(e,t)=>{Rr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Uo(){return Zi(Ho)}const Wo=E(`ZodNever`,(e,t)=>{zr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ja(e,t,n,r)});function Go(e){return Qi(Wo,e)}const Ko=E(`ZodArray`,(e,t)=>{Vr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fa(e,t,n,r),e.element=t.element,go(e,`ZodArray`,{min(e,t){return this.check(aa(e,t))},nonempty(e){return this.check(aa(1,e))},max(e,t){return this.check(ia(e,t))},length(e,t){return this.check(oa(e,t))},unwrap(){return this.element}})});function qo(e,t){return ya(Ko,e,t)}const Jo=E(`ZodObject`,(e,t)=>{Kr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ia(e,t,n,r),D(e,`shape`,()=>t.shape),go(e,`ZodObject`,{keyof(){return is(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Uo()})},loose(){return this.clone({...this._zod.def,catchall:Uo()})},strict(){return this.clone({...this._zod.def,catchall:Go()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return Lt(this,e)},safeExtend(e){return Rt(this,e)},merge(e){return zt(this,e)},pick(e){return Ft(this,e)},omit(e){return It(this,e)},partial(...e){return Bt(ss,this,e[0])},required(...e){return Vt(_s,this,e[0])}})});function Yo(e,t){return new Jo({type:`object`,shape:e,catchall:Go(),...O(t)})}function Xo(e,t){return new Jo({type:`object`,shape:e,catchall:Uo(),...O(t)})}const Zo=E(`ZodUnion`,(e,t)=>{Jr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>La(e,t,n,r),e.options=t.options});function Qo(e,t){return new Zo({type:`union`,options:e,...O(t)})}const $o=E(`ZodIntersection`,(e,t)=>{Yr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ra(e,t,n,r)});function es(e,t){return new $o({type:`intersection`,left:e,right:t})}const ts=E(`ZodRecord`,(e,t)=>{Qr.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>za(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function ns(e,t,n){return!t||!t._zod?new ts({type:`record`,keyType:L(),valueType:e,...O(t)}):new ts({type:`record`,keyType:e,valueType:t,...O(n)})}const rs=E(`ZodEnum`,(e,t)=>{$r.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ma(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new rs({...t,checks:[],...O(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new rs({...t,checks:[],...O(r),entries:i})}});function is(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new rs({type:`enum`,entries:n,...O(t)})}const as=E(`ZodTransform`,(e,t)=>{ei.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pa(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new dt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function os(e){return new as({type:`transform`,transform:e})}const ss=E(`ZodOptional`,(e,t)=>{ni.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function cs(e){return new ss({type:`optional`,innerType:e})}const ls=E(`ZodExactOptional`,(e,t)=>{ri.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function us(e){return new ls({type:`optional`,innerType:e})}const ds=E(`ZodNullable`,(e,t)=>{ii.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ba(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fs(e){return new ds({type:`nullable`,innerType:e})}const ps=E(`ZodDefault`,(e,t)=>{ai.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ha(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ms(e,t){return new ps({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():kt(t)}})}const hs=E(`ZodPrefault`,(e,t)=>{si.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ua(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function gs(e,t){return new hs({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():kt(t)}})}const _s=E(`ZodNonOptional`,(e,t)=>{ci.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Va(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function vs(e,t){return new _s({type:`nonoptional`,innerType:e,...O(t)})}const ys=E(`ZodCatch`,(e,t)=>{ui.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wa(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function bs(e,t){return new ys({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const xs=E(`ZodPipe`,(e,t)=>{di.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ga(e,t,n,r),e.in=t.in,e.out=t.out});function Ss(e,t){return new xs({type:`pipe`,in:e,out:t})}const Cs=E(`ZodPreprocess`,(e,t)=>{xs.init(e,t),pi.init(e,t)}),ws=E(`ZodReadonly`,(e,t)=>{mi.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ka(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ts(e){return new ws({type:`readonly`,innerType:e})}const Es=E(`ZodCustom`,(e,t)=>{gi.init(e,t),I.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Na(e,t,n,r)});function Ds(e,t={}){return ba(Es,e,t)}function Os(e,t){return xa(e,t)}function ks(e,t){return new Cs({type:`pipe`,in:os(e),out:t})}const As=new Set([`__proto__`,`constructor`,`prototype`]),js=(e,t,n)=>ks((n,r)=>{if(typeof n==`object`&&n)for(let i of Reflect.ownKeys(n))(typeof i!=`string`||!e(i))&&r.addIssue({code:`custom`,message:t(String(i)),path:[String(i)]});return n},n),Ms=e=>e.length>=1&&!As.has(e),Ns=e=>js(Ms,()=>`package key must be non-empty and not "__proto__", "constructor", or "prototype"`,ns(L().min(1),e)),Ps=[`blobless`,`full`],Fs=[`ssh`,`https`],Is=/^(?!\.{1,2}$)[^/\\%:]+$/u,Ls=/^[a-z0-9][a-z0-9.-]*(?:_[1-9]\d{0,4})?$/u,Rs=/^(?<amount>[1-9]\d{0,3})(?<unit>[mhd])$/u,zs={d:864e5,h:36e5,m:6e4},Bs=e=>e!==``&&/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(e),Vs=e=>{let t=e.groups?.port;if(!t)return!0;let n=Number(t);return n>=1&&n<=65535},Hs=e=>{let t=e.match(/_(?<port>\d+)$/u);if(t&&!Vs(t))return!1;let n=e;return t&&(n=e.slice(0,e.length-t[0].length)),n.split(`.`).every(e=>Bs(e))},Us=L().refine(e=>{let[t,...n]=e.split(`/`);return t===void 0||n.length<2||!Ls.test(t)||!Hs(t)?!1:n.every(e=>Is.test(e))},`ref key must be host/path…/repo with safe, non-empty segments`).brand(),Ws=L().regex(Rs,`duration must be <n>m, <n>h, or <n>d`).brand(),Gs=e=>{let t=Rs.exec(e);if(t===null)throw Error(`invalid duration: ${e}`);let{amount:n,unit:r}=t.groups??{};if(!n||!r)throw Error(`invalid duration: ${e}`);return Number(n)*zs[r]},Ks=is(Ps),qs=is(Fs),Js=L().refine(e=>e.includes(`{version}`),`tag format must contain {version}`),Ys=L().refine(e=>{if(e===`.`)return!0;let t=e.split(`/`);return t.length>0&&t.every(e=>Is.test(e)&&e!==`.`)},`package path must be "." or a normalized relative path without traversal`),Xs={clone_mode:`blobless`,git_transport:`https`,sync_ttl:`1h`},Zs=Yo({clone_mode:Ks.default(Xs.clone_mode),git_transport:qs.default(Xs.git_transport),sync_ttl:Ws.default(Ws.parse(Xs.sync_ttl))}),Qs=Yo((e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.removeDefault().optional()])))(Zs.shape)),$s=Yo({description:L().min(1),path:Ys,tag_format:Js.optional()}),ec=Yo({default_branch:L().min(1),description:L().min(1),packages:Ns($s).optional(),tag_format:Js,url:L().min(1),...Qs.shape}),tc=Yo({meta:Xo({cli_version:L().min(1),schema_version:zo().int().positive()}),refs:js(e=>Us.safeParse(e).success,()=>`ref key must be host/path…/repo with safe, non-empty segments`,ns(L(),ec)).default({}),settings:Zs});
66
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ni(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Fi(t,`input`,e.processors),output:Fi(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function N(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return N(r.element,n);if(r.type===`set`)return N(r.valueType,n);if(r.type===`lazy`)return N(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return N(r.innerType,n);if(r.type===`intersection`)return N(r.left,n)||N(r.right,n);if(r.type===`record`||r.type===`map`)return N(r.keyType,n)||N(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:N(r.in,n)||N(r.out,n);if(r.type===`object`){for(let e in r.shape)if(N(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(N(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(N(e,n))return!0;return!!(r.rest&&N(r.rest,n))}return!1}const Pi=(e,t={})=>n=>{let r=ji({...n,processors:t});return M(e,r),Mi(r,e),Ni(r,e)},Fi=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=ji({...i??{},target:a,io:t,processors:n});return M(e,o),Mi(o,e),Ni(o,e)},Ii={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Li=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ii[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Ri=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),ee=t.target===`draft-04`||t.target===`openapi-3.0`;d?ee?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?ee?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},zi=(e,t,n,r)=>{n.not={}},Bi=(e,t,n,r)=>{let i=e._zod.def,a=Te(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Vi=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Hi=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Ui=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=M(a.element,t,{...r,path:[...r.path,`items`]})},Wi=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=M(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=M(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Gi=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>M(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ki=(e,t,n,r)=>{let i=e._zod.def,a=M(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=M(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},qi=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=M(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=M(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=M(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Ji=(e,t,n,r)=>{let i=e._zod.def,a=M(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Yi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Xi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Zi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Qi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},$i=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;M(o,t,r);let s=t.seen.get(e);s.ref=o},ea=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},ta=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},na=x(`ZodISODateTime`,(e,t)=>{kn.init(e,t),L.init(e,t)});function ra(e){return $r(na,e)}const ia=x(`ZodISODate`,(e,t)=>{An.init(e,t),L.init(e,t)});function aa(e){return ei(ia,e)}const oa=x(`ZodISOTime`,(e,t)=>{jn.init(e,t),L.init(e,t)});function sa(e){return ti(oa,e)}const ca=x(`ZodISODuration`,(e,t)=>{Mn.init(e,t),L.init(e,t)});function la(e){return ni(ca,e)}const P=x(`ZodError`,(e,t)=>{it.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>st(e,t)},flatten:{value:t=>ot(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Ee,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Ee,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),ua=lt(P),da=ut(P),fa=dt(P),pa=pt(P),ma=ht(P),ha=gt(P),ga=_t(P),_a=vt(P),va=yt(P),ya=bt(P),ba=xt(P),xa=St(P),Sa=new WeakMap;function Ca(e,t,n){let r=Object.getPrototypeOf(e),i=Sa.get(r);if(i||(i=new Set,Sa.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}const F=x(`ZodType`,(e,t)=>(A.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Fi(e,`input`),output:Fi(e,`output`)}}),e.toJSONSchema=Pi(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>ua(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>fa(e,t,n),e.parseAsync=async(t,n)=>da(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>pa(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>ma(e,t,n),e.decode=(t,n)=>ha(e,t,n),e.encodeAsync=async(t,n)=>ga(e,t,n),e.decodeAsync=async(t,n)=>_a(e,t,n),e.safeEncode=(t,n)=>va(e,t,n),e.safeDecode=(t,n)=>ya(e,t,n),e.safeEncodeAsync=async(t,n)=>ba(e,t,n),e.safeDecodeAsync=async(t,n)=>xa(e,t,n),Ca(e,`ZodType`,{check(...e){let t=this.def;return this.clone(w(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return T(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Po(e,t))},superRefine(e,t){return this.check(Fo(e,t))},overwrite(e){return this.check(xi(e))},optional(){return ho(this)},exactOptional(){return _o(this)},nullable(){return yo(this)},nullish(){return ho(yo(this))},nonoptional(e){return To(this,e)},array(){return eo(this)},or(e){return io([this,e])},and(e){return oo(this,e)},transform(e){return ko(this,po(e))},default(e){return xo(this,e)},prefault(e){return Co(this,e)},catch(e){return Do(this,e)},pipe(e){return ko(this,e)},readonly(){return Mo(this)},describe(e){let t=this.clone();return kr.add(t,{description:e}),t},meta(...e){if(e.length===0)return kr.get(this);let t=this.clone();return kr.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return kr.get(e)?.description},configurable:!0}),e)),wa=x(`_ZodString`,(e,t)=>{_n.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Li(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Ca(e,`_ZodString`,{regex(...e){return this.check(hi(...e))},includes(...e){return this.check(vi(...e))},startsWith(...e){return this.check(yi(...e))},endsWith(...e){return this.check(bi(...e))},min(...e){return this.check(pi(...e))},max(...e){return this.check(fi(...e))},length(...e){return this.check(mi(...e))},nonempty(...e){return this.check(pi(1,...e))},lowercase(e){return this.check(gi(e))},uppercase(e){return this.check(_i(e))},trim(){return this.check(Ci())},normalize(...e){return this.check(Si(...e))},toLowerCase(){return this.check(wi())},toUpperCase(){return this.check(Ti())},slugify(){return this.check(Ei())}})}),Ta=x(`ZodString`,(e,t)=>{_n.init(e,t),wa.init(e,t),e.email=t=>e.check(jr(Ea,t)),e.url=t=>e.check(Lr(ka,t)),e.jwt=t=>e.check(Qr(Wa,t)),e.emoji=t=>e.check(Rr(Aa,t)),e.guid=t=>e.check(Mr(Da,t)),e.uuid=t=>e.check(Nr(Oa,t)),e.uuidv4=t=>e.check(Pr(Oa,t)),e.uuidv6=t=>e.check(Fr(Oa,t)),e.uuidv7=t=>e.check(Ir(Oa,t)),e.nanoid=t=>e.check(zr(ja,t)),e.guid=t=>e.check(Mr(Da,t)),e.cuid=t=>e.check(Br(Ma,t)),e.cuid2=t=>e.check(Vr(Na,t)),e.ulid=t=>e.check(Hr(Pa,t)),e.base64=t=>e.check(Yr(Va,t)),e.base64url=t=>e.check(Xr(Ha,t)),e.xid=t=>e.check(Ur(Fa,t)),e.ksuid=t=>e.check(Wr(Ia,t)),e.ipv4=t=>e.check(Gr(La,t)),e.ipv6=t=>e.check(Kr(Ra,t)),e.cidrv4=t=>e.check(qr(za,t)),e.cidrv6=t=>e.check(Jr(Ba,t)),e.e164=t=>e.check(Zr(Ua,t)),e.datetime=t=>e.check(ra(t)),e.date=t=>e.check(aa(t)),e.time=t=>e.check(sa(t)),e.duration=t=>e.check(la(t))});function I(e){return Ar(Ta,e)}const L=x(`ZodStringFormat`,(e,t)=>{j.init(e,t),wa.init(e,t)}),Ea=x(`ZodEmail`,(e,t)=>{bn.init(e,t),L.init(e,t)}),Da=x(`ZodGUID`,(e,t)=>{vn.init(e,t),L.init(e,t)}),Oa=x(`ZodUUID`,(e,t)=>{yn.init(e,t),L.init(e,t)}),ka=x(`ZodURL`,(e,t)=>{xn.init(e,t),L.init(e,t)}),Aa=x(`ZodEmoji`,(e,t)=>{Sn.init(e,t),L.init(e,t)}),ja=x(`ZodNanoID`,(e,t)=>{Cn.init(e,t),L.init(e,t)}),Ma=x(`ZodCUID`,(e,t)=>{wn.init(e,t),L.init(e,t)}),Na=x(`ZodCUID2`,(e,t)=>{Tn.init(e,t),L.init(e,t)}),Pa=x(`ZodULID`,(e,t)=>{En.init(e,t),L.init(e,t)}),Fa=x(`ZodXID`,(e,t)=>{Dn.init(e,t),L.init(e,t)}),Ia=x(`ZodKSUID`,(e,t)=>{On.init(e,t),L.init(e,t)}),La=x(`ZodIPv4`,(e,t)=>{Nn.init(e,t),L.init(e,t)}),Ra=x(`ZodIPv6`,(e,t)=>{Pn.init(e,t),L.init(e,t)}),za=x(`ZodCIDRv4`,(e,t)=>{Fn.init(e,t),L.init(e,t)}),Ba=x(`ZodCIDRv6`,(e,t)=>{In.init(e,t),L.init(e,t)}),Va=x(`ZodBase64`,(e,t)=>{Rn.init(e,t),L.init(e,t)}),Ha=x(`ZodBase64URL`,(e,t)=>{Bn.init(e,t),L.init(e,t)}),Ua=x(`ZodE164`,(e,t)=>{Vn.init(e,t),L.init(e,t)}),Wa=x(`ZodJWT`,(e,t)=>{Un.init(e,t),L.init(e,t)}),Ga=x(`ZodNumber`,(e,t)=>{Wn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ri(e,t,n,r),Ca(e,`ZodNumber`,{gt(e,t){return this.check(li(e,t))},gte(e,t){return this.check(ui(e,t))},min(e,t){return this.check(ui(e,t))},lt(e,t){return this.check(si(e,t))},lte(e,t){return this.check(ci(e,t))},max(e,t){return this.check(ci(e,t))},int(e){return this.check(Ja(e))},safe(e){return this.check(Ja(e))},positive(e){return this.check(li(0,e))},nonnegative(e){return this.check(ui(0,e))},negative(e){return this.check(si(0,e))},nonpositive(e){return this.check(ci(0,e))},multipleOf(e,t){return this.check(di(e,t))},step(e,t){return this.check(di(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Ka(e){return ri(Ga,e)}const qa=x(`ZodNumberFormat`,(e,t)=>{Gn.init(e,t),Ga.init(e,t)});function Ja(e){return ii(qa,e)}const Ya=x(`ZodUnknown`,(e,t)=>{Kn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Xa(){return ai(Ya)}const Za=x(`ZodNever`,(e,t)=>{qn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zi(e,t,n,r)});function Qa(e){return oi(Za,e)}const $a=x(`ZodArray`,(e,t)=>{Yn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ui(e,t,n,r),e.element=t.element,Ca(e,`ZodArray`,{min(e,t){return this.check(pi(e,t))},nonempty(e){return this.check(pi(1,e))},max(e,t){return this.check(fi(e,t))},length(e,t){return this.check(mi(e,t))},unwrap(){return this.element}})});function eo(e,t){return Di($a,e,t)}const to=x(`ZodObject`,(e,t)=>{er.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wi(e,t,n,r),C(e,`shape`,()=>t.shape),Ca(e,`ZodObject`,{keyof(){return uo(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Xa()})},loose(){return this.clone({...this._zod.def,catchall:Xa()})},strict(){return this.clone({...this._zod.def,catchall:Qa()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return Ke(this,e)},safeExtend(e){return qe(this,e)},merge(e){return Je(this,e)},pick(e){return We(this,e)},omit(e){return Ge(this,e)},partial(...e){return Ye(mo,this,e[0])},required(...e){return Xe(wo,this,e[0])}})});function R(e,t){return new to({type:`object`,shape:e,catchall:Qa(),...E(t)})}function no(e,t){return new to({type:`object`,shape:e,catchall:Xa(),...E(t)})}const ro=x(`ZodUnion`,(e,t)=>{nr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gi(e,t,n,r),e.options=t.options});function io(e,t){return new ro({type:`union`,options:e,...E(t)})}const ao=x(`ZodIntersection`,(e,t)=>{rr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ki(e,t,n,r)});function oo(e,t){return new ao({type:`intersection`,left:e,right:t})}const so=x(`ZodRecord`,(e,t)=>{or.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qi(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function co(e,t,n){return!t||!t._zod?new so({type:`record`,keyType:I(),valueType:e,...E(t)}):new so({type:`record`,keyType:e,valueType:t,...E(n)})}const lo=x(`ZodEnum`,(e,t)=>{sr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bi(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new lo({...t,checks:[],...E(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new lo({...t,checks:[],...E(r),entries:i})}});function uo(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new lo({type:`enum`,entries:n,...E(t)})}const fo=x(`ZodTransform`,(e,t)=>{cr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hi(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ce(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(nt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(nt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function po(e){return new fo({type:`transform`,transform:e})}const mo=x(`ZodOptional`,(e,t)=>{ur.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ho(e){return new mo({type:`optional`,innerType:e})}const go=x(`ZodExactOptional`,(e,t)=>{dr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _o(e){return new go({type:`optional`,innerType:e})}const vo=x(`ZodNullable`,(e,t)=>{fr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ji(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yo(e){return new vo({type:`nullable`,innerType:e})}const bo=x(`ZodDefault`,(e,t)=>{pr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function xo(e,t){return new bo({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ze(t)}})}const So=x(`ZodPrefault`,(e,t)=>{hr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Co(e,t){return new So({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ze(t)}})}const wo=x(`ZodNonOptional`,(e,t)=>{gr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function To(e,t){return new wo({type:`nonoptional`,innerType:e,...E(t)})}const Eo=x(`ZodCatch`,(e,t)=>{vr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Do(e,t){return new Eo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const Oo=x(`ZodPipe`,(e,t)=>{yr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$i(e,t,n,r),e.in=t.in,e.out=t.out});function ko(e,t){return new Oo({type:`pipe`,in:e,out:t})}const Ao=x(`ZodPreprocess`,(e,t)=>{Oo.init(e,t),xr.init(e,t)}),jo=x(`ZodReadonly`,(e,t)=>{Sr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ea(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mo(e){return new jo({type:`readonly`,innerType:e})}const No=x(`ZodCustom`,(e,t)=>{wr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vi(e,t,n,r)});function Po(e,t={}){return Oi(No,e,t)}function Fo(e,t){return ki(e,t)}function Io(e,t){return new Ao({type:`pipe`,in:po(e),out:t})}const Lo=new Set([`__proto__`,`constructor`,`prototype`]),Ro=(e,t,n)=>Io((n,r)=>{if(typeof n==`object`&&n)for(let i of Reflect.ownKeys(n))(typeof i!=`string`||!e(i))&&r.addIssue({code:`custom`,message:t(String(i)),path:[String(i)]});return n},n),zo=e=>e.length>=1&&!Lo.has(e),Bo=e=>Ro(zo,()=>`package key must be non-empty and not "__proto__", "constructor", or "prototype"`,co(I().min(1),e)),Vo=[`blobless`,`full`],Ho=[`ssh`,`https`],Uo=/^(?!\.{1,2}$)[^/\\%:]+$/u,Wo=/^[a-z0-9][a-z0-9.-]*(?:_[1-9]\d{0,4})?$/u,Go=/^(?<amount>[1-9]\d{0,3})(?<unit>[mhd])$/u,Ko={d:864e5,h:36e5,m:6e4},qo=e=>e!==``&&/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(e),Jo=e=>{let t=e.groups?.port;if(!t)return!0;let n=Number(t);return n>=1&&n<=65535},Yo=e=>{let t=e.match(/_(?<port>\d+)$/u);if(t&&!Jo(t))return!1;let n=e;return t&&(n=e.slice(0,e.length-t[0].length)),n.split(`.`).every(e=>qo(e))},z=I().refine(e=>{let[t,...n]=e.split(`/`);return t===void 0||n.length<2||!Wo.test(t)||!Yo(t)?!1:n.every(e=>Uo.test(e))},`ref key must be host/path…/repo with safe, non-empty segments`).brand(),Xo=I().regex(Go,`duration must be <n>m, <n>h, or <n>d`).brand(),Zo=e=>{let t=Go.exec(e);if(t===null)throw Error(`invalid duration: ${e}`);let{amount:n,unit:r}=t.groups??{};if(!n||!r)throw Error(`invalid duration: ${e}`);return Number(n)*Ko[r]},Qo=uo(Vo),$o=uo(Ho),es=I().refine(e=>e.includes(`{version}`),`tag format must contain {version}`),ts=I().refine(e=>{if(e===`.`)return!0;let t=e.split(`/`);return t.length>0&&t.every(e=>Uo.test(e)&&e!==`.`)},`package path must be "." or a normalized relative path without traversal`),ns={clone_mode:`blobless`,git_transport:`https`,sync_ttl:`1h`},rs=R({clone_mode:Qo.default(ns.clone_mode),git_transport:$o.default(ns.git_transport),sync_ttl:Xo.default(Xo.parse(ns.sync_ttl))}),is=R((e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.removeDefault().optional()])))(rs.shape)),as=R({description:I().min(1),path:ts,tag_format:es.optional()}),os=R({default_branch:I().min(1),description:I().min(1),packages:Bo(as).optional(),tag_format:es,url:I().min(1),...is.shape}),ss=R({meta:no({cli_version:I().min(1),schema_version:Ka().int().positive()}),refs:Ro(e=>z.safeParse(e).success,()=>`ref key must be host/path…/repo with safe, non-empty segments`,co(I(),os)).default({}),settings:rs});
67
67
  /*!
68
68
  * Copyright (c) Squirrel Chat et al., All rights reserved.
69
69
  * SPDX-License-Identifier: BSD-3-Clause
@@ -91,9 +91,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
91
91
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
92
92
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93
93
  */
94
- function nc(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function rc(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
95
- `,e===t&&(i+=` `.repeat(a+n+2),i+=`^
96
- `))}return i}var z=class extends Error{line;column;codeblock;constructor(e,t){let[n,r]=nc(t.toml,t.ptr),i=rc(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}};
94
+ let cs=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;var ls=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e){let t=!0,n=!0,r=`Z`;if(typeof e==`string`){let i=e.match(cs);i?(i[1]||(t=!1,e=`0000-01-01T${e}`),n=!!i[2],n&&e[10]===` `&&(e=e.replace(` `,`T`)),i[2]&&+i[2]>23?e=``:(r=i[3]||null,e=e.toUpperCase(),!r&&n&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=t,this.#t=n,this.#n=r)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}};
97
95
  /*!
98
96
  * Copyright (c) Squirrel Chat et al., All rights reserved.
99
97
  * SPDX-License-Identifier: BSD-3-Clause
@@ -121,14 +119,9 @@ function nc(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop()
121
119
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
122
120
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
123
121
  */
124
- function ic(e,t){let n=0;for(;e[t-++n]===`\\`;);return--n&&n%2}function ac(e,t=0,n=e.length){let r=e.indexOf(`
125
- `,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function oc(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r===`
126
- `)return n;if(r===`\r`&&e[n+1]===`
127
- `)return n+1;if(r<` `&&r!==` `||r===``)throw new z(`control characters are not allowed in comments`,{toml:e,ptr:t})}return e.length}function sc(e,t,n,r){let i;for(;;){for(;(i=e[t])===` `||i===` `||!n&&(i===`
128
- `||i===`\r`&&e[t+1]===`
129
- `);)t++;if(r||i!==`#`)break;t=oc(e,t)}return t}function cc(e,t,n,r,i=!1){if(!r)return t=ac(e,t),t<0?e.length:t;for(let a=t;a<e.length;a++){let t=e[a];if(t===`#`)a=ac(e,a);else if(t===n)return a+1;else if(t===r||i&&(t===`
130
- `||t===`\r`&&e[a+1]===`
131
- `))return a}throw new z(`cannot find end of structure`,{toml:e,ptr:t})}function lc(e,t){let n=e[t],r=n===e[t+1]&&e[t+1]===e[t+2]?e.slice(t,t+3):n;t+=r.length-1;do t=e.indexOf(r,++t);while(t>-1&&n!==`'`&&ic(e,t));return t>-1&&(t+=r.length,r.length>1&&(e[t]===n&&t++,e[t]===n&&t++)),t}
122
+ function us(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function ds(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
123
+ `,e===t&&(i+=` `.repeat(a+n+2),i+=`^
124
+ `))}return i}var B=class extends Error{line;column;codeblock;constructor(e,t){let[n,r]=us(t.toml,t.ptr),i=ds(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}};
132
125
  /*!
133
126
  * Copyright (c) Squirrel Chat et al., All rights reserved.
134
127
  * SPDX-License-Identifier: BSD-3-Clause
@@ -156,7 +149,12 @@ function ic(e,t){let n=0;for(;e[t-++n]===`\\`;);return--n&&n%2}function ac(e,t=0
156
149
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
157
150
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158
151
  */
159
- let uc=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;var dc=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e){let t=!0,n=!0,r=`Z`;if(typeof e==`string`){let i=e.match(uc);i?(i[1]||(t=!1,e=`0000-01-01T${e}`),n=!!i[2],n&&e[10]===` `&&(e=e.replace(` `,`T`)),i[2]&&+i[2]>23?e=``:(r=i[3]||null,e=e.toUpperCase(),!r&&n&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=t,this.#t=n,this.#n=r)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}};
152
+ let fs=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,ps=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,ms=/^[+-]?0[0-9_]/;function hs(e,t){let n=e[t++],r=n,i=n===`'`,a=n===e[t]&&n===e[t+1];a&&(e[t+=2]===`
153
+ `?t++:e[t]===`\r`&&e[t+1]===`
154
+ `&&(t+=2));let o=``,s=t,c=0;for(let l=t;l<e.length;l++)if(n=e[l],a&&(n===`
155
+ `||n===`\r`&&e[l+1]===`
156
+ `))c&&=3;else if(n<` `&&n!==` `||n===``)throw new B(`control characters are not allowed in strings`,{toml:e,ptr:l});else if((!c||c===3)&&n===r&&(!a||e[l+1]===r&&e[l+2]===r))return a&&(e[l+3]===r&&l++,e[l+3]===r&&l++),[c?o:o+e.slice(s,l),l+(a?3:1)];else if(!c)!i&&n===`\\`&&(o+=e.slice(s,s=l),c=1);else if(c===1)if(n===`x`||n===`u`||n===`U`){let t=0,r=n===`x`?2:n===`u`?4:8;for(let n=0;n<r;n++,l++){let n=e.charCodeAt(l+1),r=n>=48&&n<=57?n-48:n>=65&&n<=70?n-65+10:n>=97&&n<=102?n-97+10:-1;if(r<0)throw new B(`invalid non-hex character in unicode escape`,{toml:e,ptr:l+1});t=t<<4|r}if(t<0||t>1114111||t>=55296&&t<=57343)throw new B(`invalid unicode escape`,{toml:e,ptr:l});o+=String.fromCodePoint(t),s=l+1,c=0}else if(n===` `||n===` `)c=2;else{if(n===`b`)o+=`\b`;else if(n===`t`)o+=` `;else if(n===`n`)o+=`
157
+ `;else if(n===`f`)o+=`\f`;else if(n===`r`)o+=`\r`;else if(n===`e`)o+=`\x1B`;else if(n===`"`)o+=`"`;else if(n===`\\`)o+=`\\`;else throw new B(`unrecognized escape sequence`,{toml:e,ptr:l});s=l+1,c=0}else if(n!==` `&&n!==` `){if(c===2)throw new B(`invalid escape: only line-ending whitespace may be escaped`,{toml:e,ptr:s});c=+(!i&&n===`\\`),s=l}throw new B(`unfinished string`,{toml:e,ptr:t})}function gs(e,t,n,r){if(e===`true`)return!0;if(e===`false`)return!1;if(e===`-inf`)return-1/0;if(e===`inf`||e===`+inf`)return 1/0;if(e===`nan`||e===`+nan`||e===`-nan`)return NaN;if(e===`-0`)return r?0n:0;let i=fs.test(e);if(i||ps.test(e)){if(ms.test(e))throw new B(`leading zeroes are not allowed`,{toml:t,ptr:n});e=e.replace(/_/g,``);let a=+e;if(isNaN(a))throw new B(`invalid number`,{toml:t,ptr:n});if(i){if((i=!Number.isSafeInteger(a))&&!r)throw new B(`integer value cannot be represented losslessly`,{toml:t,ptr:n});(i||r===!0)&&(a=BigInt(e))}return a}let a=new ls(e);if(!a.isValid())throw new B(`invalid value`,{toml:t,ptr:n});return a}
160
158
  /*!
161
159
  * Copyright (c) Squirrel Chat et al., All rights reserved.
162
160
  * SPDX-License-Identifier: BSD-3-Clause
@@ -184,13 +182,14 @@ let uc=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]
184
182
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
185
183
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186
184
  */
187
- let fc=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,pc=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,mc=/^[+-]?0[0-9_]/,hc=/^[0-9a-f]{2,8}$/i,gc={b:`\b`,t:` `,n:`
188
- `,f:`\f`,r:`\r`,e:`\x1B`,'"':`"`,"\\":`\\`};function _c(e,t=0,n=e.length){let r=e[t]===`'`,i=e[t++]===e[t]&&e[t]===e[t+1];i&&(n-=2,e[t+=2]===`\r`&&t++,e[t]===`
189
- `&&t++);let a=0,o,s=``,c=t;for(;t<n-1;){let n=e[t++];if(n===`
190
- `||n===`\r`&&e[t]===`
191
- `){if(!i)throw new z(`newlines are not allowed in strings`,{toml:e,ptr:t-1})}else if(n<` `&&n!==` `||n===``)throw new z(`control characters are not allowed in strings`,{toml:e,ptr:t-1});if(o){if(o=!1,n===`x`||n===`u`||n===`U`){let r=e.slice(t,t+=n===`x`?2:n===`u`?4:8);if(!hc.test(r))throw new z(`invalid unicode escape`,{toml:e,ptr:a});try{s+=String.fromCodePoint(parseInt(r,16))}catch{throw new z(`invalid unicode escape`,{toml:e,ptr:a})}}else if(i&&(n===`
192
- `||n===` `||n===` `||n===`\r`)){if(t=sc(e,t-1,!0),e[t]!==`
193
- `&&e[t]!==`\r`)throw new z(`invalid escape: only line-ending whitespace may be escaped`,{toml:e,ptr:a});t=sc(e,t)}else if(n in gc)s+=gc[n];else throw new z(`unrecognized escape sequence`,{toml:e,ptr:a});c=t}else!r&&n===`\\`&&(a=t-1,o=!0,s+=e.slice(c,a))}return s+e.slice(c,n-1)}function vc(e,t,n,r){if(e===`true`)return!0;if(e===`false`)return!1;if(e===`-inf`)return-1/0;if(e===`inf`||e===`+inf`)return 1/0;if(e===`nan`||e===`+nan`||e===`-nan`)return NaN;if(e===`-0`)return r?0n:0;let i=fc.test(e);if(i||pc.test(e)){if(mc.test(e))throw new z(`leading zeroes are not allowed`,{toml:t,ptr:n});e=e.replace(/_/g,``);let a=+e;if(isNaN(a))throw new z(`invalid number`,{toml:t,ptr:n});if(i){if((i=!Number.isSafeInteger(a))&&!r)throw new z(`integer value cannot be represented losslessly`,{toml:t,ptr:n});(i||r===!0)&&(a=BigInt(e))}return a}let a=new dc(e);if(!a.isValid())throw new z(`invalid value`,{toml:t,ptr:n});return a}
185
+ function _s(e,t=0,n=e.length){let r=e.indexOf(`
186
+ `,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function vs(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r===`
187
+ `)return n;if(r===`\r`&&e[n+1]===`
188
+ `)return n+1;if(r<` `&&r!==` `||r===``)throw new B(`control characters are not allowed in comments`,{toml:e,ptr:t})}return e.length}function ys(e,t,n,r){let i;for(;;){for(;(i=e[t])===` `||i===` `||!n&&(i===`
189
+ `||i===`\r`&&e[t+1]===`
190
+ `);)t++;if(r||i!==`#`)break;t=vs(e,t)}return t}function bs(e,t,n,r,i=!1){if(!r)return t=_s(e,t),t<0?e.length:t;for(let a=t;a<e.length;a++){let t=e[a];if(t===`#`)a=_s(e,a);else if(t===n)return a+1;else if(t===r||i&&(t===`
191
+ `||t===`\r`&&e[a+1]===`
192
+ `))return a}throw new B(`cannot find end of structure`,{toml:e,ptr:t})}
194
193
  /*!
195
194
  * Copyright (c) Squirrel Chat et al., All rights reserved.
196
195
  * SPDX-License-Identifier: BSD-3-Clause
@@ -218,8 +217,8 @@ let fc=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,pc=/^[+-]?
218
217
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
219
218
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
220
219
  */
221
- function yc(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(oc(e,i),r=r.slice(0,i)),[r.trimEnd(),i]}function bc(e,t,n,r,i){if(r===0)throw new z(`document contains excessively nested structures. aborting.`,{toml:e,ptr:t});let a=e[t];if(a===`[`||a===`{`){let[o,s]=a===`[`?wc(e,t,r,i):Cc(e,t,r,i);if(n){if(s=sc(e,s),e[s]===`,`)s++;else if(e[s]!==n)throw new z(`expected comma or end of structure`,{toml:e,ptr:s})}return[o,s]}let o;if(a===`"`||a===`'`){o=lc(e,t);let r=_c(e,t,o);if(n){if(o=sc(e,o),e[o]&&e[o]!==`,`&&e[o]!==n&&e[o]!==`
222
- `&&e[o]!==`\r`)throw new z(`unexpected character encountered`,{toml:e,ptr:o});o+=+(e[o]===`,`)}return[r,o]}o=cc(e,t,`,`,n);let s=yc(e,t,o-+(e[o-1]===`,`));if(!s[0])throw new z(`incomplete key-value declaration: no value specified`,{toml:e,ptr:t});return n&&s[1]>-1&&(o=sc(e,t+s[1]),o+=+(e[o]===`,`)),[vc(s[0],e,t,i),o]}
220
+ function xs(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(vs(e,i),r=r.slice(0,i)),[r.trimEnd(),i]}function Ss(e,t,n,r,i){if(r===0)throw new B(`document contains excessively nested structures. aborting.`,{toml:e,ptr:t});let a=e[t];if(a===`[`||a===`{`){let[o,s]=a===`[`?Es(e,t,r,i):Ts(e,t,r,i);if(n){if(s=ys(e,s),e[s]===`,`)s++;else if(e[s]!==n)throw new B(`expected comma or end of structure`,{toml:e,ptr:s})}return[o,s]}if(a===`"`||a===`'`){let[r,i]=hs(e,t);if(n){if(i=ys(e,i),e[i]&&e[i]!==`,`&&e[i]!==n&&e[i]!==`
221
+ `&&e[i]!==`\r`)throw new B(`unexpected character encountered`,{toml:e,ptr:i});e[i]===`,`&&i++}return[r,i]}let o=bs(e,t,`,`,n),s=xs(e,t,o-+(e[o-1]===`,`));if(!s[0])throw new B(`incomplete key-value declaration: no value specified`,{toml:e,ptr:t});return n&&s[1]>-1&&(o=ys(e,t+s[1]),e[o]===`,`&&o++),[gs(s[0],e,t,i),o]}
223
222
  /*!
224
223
  * Copyright (c) Squirrel Chat et al., All rights reserved.
225
224
  * SPDX-License-Identifier: BSD-3-Clause
@@ -247,9 +246,9 @@ function yc(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(oc(e,i),r=r
247
246
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
248
247
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
249
248
  */
250
- let xc=/^[a-zA-Z0-9-_]+[ \t]*$/;function Sc(e,t,n=`=`){let r=t-1,i=[],a=e.indexOf(n,t);if(a<0)throw new z(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});do{let o=e[t=++r];if(o!==` `&&o!==` `)if(o===`"`||o===`'`){if(o===e[t+1]&&o===e[t+2])throw new z(`multiline strings are not allowed in keys`,{toml:e,ptr:t});let s=lc(e,t);if(s<0)throw new z(`unfinished string encountered`,{toml:e,ptr:t});r=e.indexOf(`.`,s);let c=e.slice(s,r<0||r>a?a:r),l=ac(c);if(l>-1)throw new z(`newlines are not allowed in keys`,{toml:e,ptr:t+r+l});if(c.trimStart())throw new z(`found extra tokens after the string part`,{toml:e,ptr:s});if(a<s&&(a=e.indexOf(n,s),a<0))throw new z(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});i.push(_c(e,t,s))}else{r=e.indexOf(`.`,t);let n=e.slice(t,r<0||r>a?a:r);if(!xc.test(n))throw new z(`only letter, numbers, dashes and underscores are allowed in keys`,{toml:e,ptr:t});i.push(n.trimEnd())}}while(r+1&&r<a);return[i,sc(e,a+1,!0,!0)]}function Cc(e,t,n,r){let i={},a=new Set,o;for(t++;(o=e[t++])!==`}`&&o;)if(o===`,`)throw new z(`expected value, found comma`,{toml:e,ptr:t-1});else if(o===`#`)t=oc(e,t);else if(o!==` `&&o!==` `&&o!==`
251
- `&&o!==`\r`){let o,s=i,c=!1,[l,u]=Sc(e,t-1);for(let n=0;n<l.length;n++){if(n&&(s=c?s[o]:s[o]={}),o=l[n],(c=Object.hasOwn(s,o))&&(typeof s[o]!=`object`||a.has(s[o])))throw new z(`trying to redefine an already defined value`,{toml:e,ptr:t});!c&&o===`__proto__`&&Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new z(`trying to redefine an already defined value`,{toml:e,ptr:t});let[d,f]=bc(e,u,`}`,n-1,r);a.add(d),s[o]=d,t=f}if(!o)throw new z(`unfinished table encountered`,{toml:e,ptr:t});return[i,t]}function wc(e,t,n,r){let i=[],a;for(t++;(a=e[t++])!==`]`&&a;)if(a===`,`)throw new z(`expected value, found comma`,{toml:e,ptr:t-1});else if(a===`#`)t=oc(e,t);else if(a!==` `&&a!==` `&&a!==`
252
- `&&a!==`\r`){let a=bc(e,t-1,`]`,n-1,r);i.push(a[0]),t=a[1]}if(!a)throw new z(`unfinished array encountered`,{toml:e,ptr:t});return[i,t]}
249
+ let Cs=/^[a-zA-Z0-9-_]+[ \t]*$/;function ws(e,t,n=`=`){let r=t-1,i=[],a=e.indexOf(n,t);if(a<0)throw new B(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});do{let o=e[t=++r];if(o!==` `&&o!==` `)if(o===`"`||o===`'`){if(o===e[t+1]&&o===e[t+2])throw new B(`multiline strings are not allowed in keys`,{toml:e,ptr:t});let[s,c]=hs(e,t);r=e.indexOf(`.`,c);let l=e.slice(c,r<0||r>a?a:r),u=_s(l);if(u>-1)throw new B(`newlines are not allowed in keys`,{toml:e,ptr:t+r+u});if(l.trimStart())throw new B(`found extra tokens after the string part`,{toml:e,ptr:c});if(a<c&&(a=e.indexOf(n,c),a<0))throw new B(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});i.push(s)}else{r=e.indexOf(`.`,t);let n=e.slice(t,r<0||r>a?a:r);if(!Cs.test(n))throw new B(`only letter, numbers, dashes and underscores are allowed in keys`,{toml:e,ptr:t});i.push(n.trimEnd())}}while(r+1&&r<a);return[i,ys(e,a+1,!0,!0)]}function Ts(e,t,n,r){let i={},a=new Set,o;for(t++;(o=e[t++])!==`}`&&o;)if(o===`,`)throw new B(`expected value, found comma`,{toml:e,ptr:t-1});else if(o===`#`)t=vs(e,t);else if(o!==` `&&o!==` `&&o!==`
250
+ `&&o!==`\r`){let o,s=i,c=!1,[l,u]=ws(e,t-1);for(let n=0;n<l.length;n++){if(n&&(s=c?s[o]:s[o]={}),o=l[n],(c=Object.hasOwn(s,o))&&(typeof s[o]!=`object`||a.has(s[o])))throw new B(`trying to redefine an already defined value`,{toml:e,ptr:t});!c&&o===`__proto__`&&Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new B(`trying to redefine an already defined value`,{toml:e,ptr:t});let[d,f]=Ss(e,u,`}`,n-1,r);a.add(d),s[o]=d,t=f}if(!o)throw new B(`unfinished table encountered`,{toml:e,ptr:t});return[i,t]}function Es(e,t,n,r){let i=[],a;for(t++;(a=e[t++])!==`]`&&a;)if(a===`,`)throw new B(`expected value, found comma`,{toml:e,ptr:t-1});else if(a===`#`)t=vs(e,t);else if(a!==` `&&a!==` `&&a!==`
251
+ `&&a!==`\r`){let a=Ss(e,t-1,`]`,n-1,r);i.push(a[0]),t=a[1]}if(!a)throw new B(`unfinished array encountered`,{toml:e,ptr:t});return[i,t]}
253
252
  /*!
254
253
  * Copyright (c) Squirrel Chat et al., All rights reserved.
255
254
  * SPDX-License-Identifier: BSD-3-Clause
@@ -277,8 +276,8 @@ let xc=/^[a-zA-Z0-9-_]+[ \t]*$/;function Sc(e,t,n=`=`){let r=t-1,i=[],a=e.indexO
277
276
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
278
277
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279
278
  */
280
- function Tc(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i=s?i[o]:i[o]={},a=(c=a[o]).c,r===0&&(c.t===1||c.t===2))return null;if(c.t===2){let e=i.length-1;i=i[e],a=a[e].c}}if(o=e[t],(s=Object.hasOwn(i,o))&&a[o]?.t===0&&a[o]?.d)return null;s||(o===`__proto__`&&(Object.defineProperty(i,o,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(a,o,{enumerable:!0,configurable:!0,writable:!0})),a[o]={t:t<e.length-1&&r===2?3:r,d:!1,i:0,c:{}})}if(c=a[o],c.t!==r&&!(r===1&&c.t===3)||(r===2&&(c.d||(c.d=!0,i[o]=[]),i[o].push(i={}),c.c[c.i++]=c={t:1,d:!1,i:0,c:{}}),c.d))return null;if(c.d=!0,r===1)i=s?i[o]:i[o]={};else if(r===0&&s)return null;return[o,i,c.c]}function Ec(e,{maxDepth:t=1e3,integersAsBigInt:n}={}){let r={},i={},a=r,o=i;for(let s=sc(e,0);s<e.length;){if(e[s]===`[`){let t=e[++s]===`[`,n=Sc(e,s+=+t,`]`);if(t){if(e[n[1]-1]!==`]`)throw new z(`expected end of table declaration`,{toml:e,ptr:n[1]-1});n[1]++}let c=Tc(n[0],r,i,t?2:1);if(!c)throw new z(`trying to redefine an already defined table or value`,{toml:e,ptr:s});o=c[2],a=c[1],s=n[1]}else{let r=Sc(e,s),i=Tc(r[0],a,o,0);if(!i)throw new z(`trying to redefine an already defined table or value`,{toml:e,ptr:s});let c=bc(e,r[1],void 0,t,n);i[1][i[0]]=c[0],s=c[1]}if(s=sc(e,s,!0),e[s]&&e[s]!==`
281
- `&&e[s]!==`\r`)throw new z(`each key-value declaration must be followed by an end-of-line`,{toml:e,ptr:s});s=sc(e,s)}return r}
279
+ function Ds(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i=s?i[o]:i[o]={},a=(c=a[o]).c,r===0&&(c.t===1||c.t===2))return null;if(c.t===2){let e=i.length-1;i=i[e],a=a[e].c}}if(o=e[t],(s=Object.hasOwn(i,o))&&a[o]?.t===0&&a[o]?.d)return null;s||(o===`__proto__`&&(Object.defineProperty(i,o,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(a,o,{enumerable:!0,configurable:!0,writable:!0})),a[o]={t:t<e.length-1&&r===2?3:r,d:!1,i:0,c:{}})}if(c=a[o],c.t!==r&&!(r===1&&c.t===3)||(r===2&&(c.d||(c.d=!0,i[o]=[]),i[o].push(i={}),c.c[c.i++]=c={t:1,d:!1,i:0,c:{}}),c.d))return null;if(c.d=!0,r===1)i=s?i[o]:i[o]={};else if(r===0&&s)return null;return[o,i,c.c]}function Os(e,{maxDepth:t=1e3,integersAsBigInt:n}={}){let r={},i={},a=r,o=i;for(let s=ys(e,0);s<e.length;){if(e[s]===`[`){let t=e[++s]===`[`,n=ws(e,s+=+t,`]`);if(t){if(e[n[1]-1]!==`]`)throw new B(`expected end of table declaration`,{toml:e,ptr:n[1]-1});n[1]++}let c=Ds(n[0],r,i,t?2:1);if(!c)throw new B(`trying to redefine an already defined table or value`,{toml:e,ptr:s});o=c[2],a=c[1],s=n[1]}else{let r=ws(e,s),i=Ds(r[0],a,o,0);if(!i)throw new B(`trying to redefine an already defined table or value`,{toml:e,ptr:s});let c=Ss(e,r[1],void 0,t,n);i[1][i[0]]=c[0],s=c[1]}if(s=ys(e,s,!0),e[s]&&e[s]!==`
280
+ `&&e[s]!==`\r`)throw new B(`each key-value declaration must be followed by an end-of-line`,{toml:e,ptr:s});s=ys(e,s)}return r}
282
281
  /*!
283
282
  * Copyright (c) Squirrel Chat et al., All rights reserved.
284
283
  * SPDX-License-Identifier: BSD-3-Clause
@@ -306,13 +305,13 @@ function Tc(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i
306
305
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
307
306
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
308
307
  */
309
- let Dc=/^[a-z0-9-_]+$/i;function Oc(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`}return t}function kc(e){for(let t=0;t<e.length;t++)if(Oc(e[t])!==`object`)return!1;return e.length!=0}function Ac(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function jc(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);if(t===`number`)return isNaN(e)?`nan`:e===1/0?`inf`:e===-1/0?`-inf`:r&&Number.isInteger(e)?e.toFixed(1):e.toString();if(t===`bigint`||t===`boolean`)return e.toString();if(t===`string`)return Ac(e);if(t===`date`){if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString()}if(t===`object`)return Mc(e,n,r);if(t===`array`)return Nc(e,n,r)}function Mc(e,t,n){let r=Object.keys(e);if(r.length===0)return`{}`;let i=`{ `;for(let a=0;a<r.length;a++){let o=r[a];a&&(i+=`, `),i+=Dc.test(o)?o:Ac(o),i+=` = `,i+=jc(e[o],Oc(e[o]),t-1,n)}return i+` }`}function Nc(e,t,n){if(e.length===0)return`[]`;let r=`[ `;for(let i=0;i<e.length;i++){if(i&&(r+=`, `),e[i]===null||e[i]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);r+=jc(e[i],Oc(e[i]),t-1,n)}return r+` ]`}function Pc(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let i=``;for(let a=0;a<e.length;a++)i+=`${i&&`
310
- `}[[${t}]]\n`,i+=Fc(0,e[a],t,n,r);return i}function Fc(e,t,n,r,i){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``,o=``,s=Object.keys(t);for(let e=0;e<s.length;e++){let c=s[e];if(t[c]!==null&&t[c]!==void 0){let e=Oc(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=Dc.test(c)?c:Ac(c);if(e===`array`&&kc(t[c]))o+=(o&&`
311
- `)+Pc(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
312
- `)+Fc(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=jc(t[c],e,r,i),a+=`
313
- `}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function Ic(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if(Oc(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=Fc(0,e,``,t,n);return r[r.length-1]===`
308
+ let ks=/^[a-z0-9-_]+$/i;function As(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`}return t}function js(e){for(let t=0;t<e.length;t++)if(As(e[t])!==`object`)return!1;return e.length!=0}function Ms(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function Ns(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);if(t===`number`)return isNaN(e)?`nan`:e===1/0?`inf`:e===-1/0?`-inf`:Number.isInteger(e)&&(r||!Number.isSafeInteger(e))?e.toFixed(1):e.toString();if(t===`bigint`||t===`boolean`)return e.toString();if(t===`string`)return Ms(e);if(t===`date`){if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString()}if(t===`object`)return Ps(e,n,r);if(t===`array`)return Fs(e,n,r)}function Ps(e,t,n){let r=Object.keys(e);if(r.length===0)return`{}`;let i=`{ `;for(let a=0;a<r.length;a++){let o=r[a];a&&(i+=`, `),i+=ks.test(o)?o:Ms(o),i+=` = `,i+=Ns(e[o],As(e[o]),t-1,n)}return i+` }`}function Fs(e,t,n){if(e.length===0)return`[]`;let r=`[ `;for(let i=0;i<e.length;i++){if(i&&(r+=`, `),e[i]===null||e[i]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);r+=Ns(e[i],As(e[i]),t-1,n)}return r+` ]`}function Is(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let i=``;for(let a=0;a<e.length;a++)i+=`${i&&`
309
+ `}[[${t}]]\n`,i+=Ls(0,e[a],t,n,r);return i}function Ls(e,t,n,r,i){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``,o=``,s=Object.keys(t);for(let e=0;e<s.length;e++){let c=s[e];if(t[c]!==null&&t[c]!==void 0){let e=As(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=ks.test(c)?c:Ms(c);if(e===`array`&&js(t[c]))o+=(o&&`
310
+ `)+Is(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
311
+ `)+Ls(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=Ns(t[c],e,r,i),a+=`
312
+ `}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function Rs(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if(As(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=Ls(0,e,``,t,n);return r[r.length-1]===`
314
313
  `?r:r+`
315
- `}const Lc=e=>typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`,Rc=async(e,t)=>{await o(_(e),{recursive:!0});let n=`${e}.tmp-${re()}`;await m(n,t,`utf8`),await u(n,e)},B=e=>{let t=te(e.REFS_HOME??y(me(),`.kaisers-io`,`refs`));return{configPath:y(t,`config.toml`),hooksDir:y(t,`hooks`),locksDir:y(t,`locks`),root:t,sourcesDir:y(t,`sources`),statePath:y(t,`state.json`)}},V=(e,t)=>y(e.sourcesDir,...t.split(`/`)),zc=e=>`${e.configPath}.bak`,Bc=e=>{let t=[],n=e;for(;!ce(n);){let e=_(n);if(e===n)break;t.unshift(g(n)),n=e}return{ancestor:n,missing:t}},Vc=e=>{let{ancestor:t,missing:n}=Bc(e),r=ue(t);return n.length===0?r:y(r,...n)},Hc=(e,t)=>{let n=ee(Vc(e.sourcesDir),Vc(t)),r=n===`..`||n.startsWith(`..`+ne);if(!(n!==``&&!r&&!v(n)))throw T(`path escapes sources directory (containment violation): ${t}`)},Uc=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Wc=(e,t)=>Uc(e)?e:t,Gc=async e=>{try{return await s(e.configPath,`utf8`)}catch(e){throw Lc(e)?C(`no config found — run: refs init`):e}},Kc=(e,t)=>{try{return Ec(e)}catch(e){throw e instanceof z?T(`invalid TOML in ${t}: ${e.message}`):e}},qc=e=>typeof e==`number`&&Number.isInteger(e)&&e>=1,Jc=e=>{let{meta:t}=e;if(!Uc(t))return;let n=t.schema_version;if(qc(n))return n},Yc=(e,t)=>{let n=Jc(e);if(n===void 0)throw T(`config schema version is missing or invalid in ${t} — run: refs migrate`);if(n>1)throw T(`config schema ${n} is newer than this CLI supports — upgrade refs`);if(n<1)throw T(`config schema ${n} is older than expected 1 — run: refs migrate`)},H=async e=>{let t=await Gc(e),n=Kc(t,e.configPath);Yc(n,e.configPath);let r=tc.safeParse(n);if(!r.success)throw T(k(r.error));return r.data},Xc=async(e,t)=>{let n=tc.safeParse(t);if(!n.success)throw T(k(n.error));await Rc(e.configPath,Ic(n.data))},Zc=async e=>{try{return await p(e),!0}catch(e){if(Lc(e))return!1;throw e}},Qc=async(e,t)=>await Zc(e.configPath)?`noop`:(await Rc(e.configPath,`# refs configuration
314
+ `}const V=e=>typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`,zs=async(e,t)=>{await a(ne(e),{recursive:!0});let n=`${e}.tmp-${se()}`;await ee(n,t,`utf8`),await l(n,e)},H=e=>{let t=ae(e.REFS_HOME??m(de(),`.kaisers-io`,`refs`));return{configPath:m(t,`config.toml`),hooksDir:m(t,`hooks`),locksDir:m(t,`locks`),root:t,sourcesDir:m(t,`sources`),statePath:m(t,`state.json`)}},U=(e,t)=>m(e.sourcesDir,...t.split(`/`)),Bs=e=>`${e.configPath}.bak`,Vs=e=>{let t=[],n=e;for(;!le(n);){let e=ne(n);if(e===n)break;t.unshift(te(n)),n=e}return{ancestor:n,missing:t}},Hs=e=>{let{ancestor:t,missing:n}=Vs(e),r=ue(t);return n.length===0?r:m(r,...n)},Us=(e,t)=>{let n=ie(Hs(e.sourcesDir),Hs(t)),r=n===`..`||n.startsWith(`..`+oe);if(!(n!==``&&!r&&!re(n)))throw b(`path escapes sources directory (containment violation): ${t}`)},Ws=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gs=(e,t)=>Ws(e)?e:t,Ks=async e=>{try{return await o(e.configPath,`utf8`)}catch(e){throw V(e)?v(`no config found — run: refs init`):e}},qs=(e,t)=>{try{return Os(e)}catch(e){throw e instanceof B?b(`invalid TOML in ${t}: ${e.message}`):e}},Js=e=>typeof e==`number`&&Number.isInteger(e)&&e>=1,Ys=e=>{let{meta:t}=e;if(!Ws(t))return;let n=t.schema_version;if(Js(n))return n},Xs=(e,t)=>{let n=Ys(e);if(n===void 0)throw b(`config schema version is missing or invalid in ${t} — run: refs migrate`);if(n>1)throw b(`config schema ${n} is newer than this CLI supports — upgrade refs`);if(n<1)throw b(`config schema ${n} is older than expected 1 — run: refs migrate`)},W=async e=>{let t=await Ks(e),n=qs(t,e.configPath);Xs(n,e.configPath);let r=ss.safeParse(n);if(!r.success)throw b(O(r.error));return r.data},Zs=async(e,t)=>{let n=ss.safeParse(t);if(!n.success)throw b(O(n.error));await zs(e.configPath,Rs(n.data))},Qs=async e=>{try{return await f(e),!0}catch(e){if(V(e))return!1;throw e}},$s=async(e,t)=>await Qs(e.configPath)?`noop`:(await zs(e.configPath,`# refs configuration
316
315
  #
317
316
  # Every global setting under [settings] can also be set per-ref: add the same
318
317
  # key directly inside a [refs."host/owner/repo"] table to override it just for
@@ -343,62 +342,29 @@ sync_ttl = "1h"
343
342
  # tag_format = "v{version}"
344
343
  # # Per-ref overrides of [settings] go in the same table, e.g.:
345
344
  # # clone_mode = "full"
346
- `.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),$c=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];t===void 0?n[e]=r:Uc(t)&&Uc(r)&&(n[e]=$c(t,r))}return n},el={meta:{},refs:{},settings:{}},tl=async e=>{try{return await Gc(e)}catch(e){if(e instanceof at&&e.code===`not_found`)return;throw e}},nl=e=>{if(e!==void 0&&e>1)throw T(`config schema ${e} is newer than this CLI supports — upgrade refs`)},rl=async(e,t,n)=>{let r=Wc(t.meta,{});if(r.cli_version===n)return;let i={...t,meta:{...r,cli_version:n}};await Rc(e.configPath,Ic(i))},il=async(e,t,n)=>{await i(e.configPath,zc(e));let r=$c(t,el),a=Wc(r.meta,{}),o={...r,meta:{...a,cli_version:n,schema_version:1}},s=tc.safeParse(o);if(!s.success)throw T(`config in ${e.configPath} is malformed beyond automatic migration (backup preserved at ${zc(e)}): ${k(s.error)}`);await Rc(e.configPath,Ic(o))},al=async(e,t)=>(await Qc(e,t),`seeded`),ol=async(e,t,n)=>{let r=Kc(t,e.configPath),i=Jc(r);return nl(i),i===1?(await rl(e,r,n),`noop`):(await il(e,r,n),`migrated`)},sl=async(e,t)=>{let n=await tl(e);return n===void 0?al(e,t):ol(e,n,t)},cl=e=>{let t=e.stderr.trim()||e.stdout.trim()||`exit code ${e.exitCode}`,n=t.split(`
347
- `)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`},ll=(e,t)=>t?`restored`:e.oldSha===e.newSha?`fresh`:`updated`,ul=(e,t)=>{let n=[];if(e&&n.push(`checkout had local changes (managed checkouts are read-only) — discarded and restored to the remote state`),t!==void 0&&n.push(t),n.length!==0)return n.join(` | `)},dl=e=>{let{branchRenamedTo:t,dirty:n,setHeadWarning:r,shas:i}=e,a={...i,status:ll(i,n)};t!==void 0&&(a.branchRenamedTo=t);let o=ul(n,r);return o!==void 0&&(a.warning=o),a},fl=(e,t,n)=>{let r={dirty:t,shas:n};return e.branchRenamedTo!==void 0&&(r.branchRenamedTo=e.branchRenamedTo),e.warning!==void 0&&(r.setHeadWarning=e.warning),r},U=e=>ce(y(e,`.git`)),pl=e=>`refusing to sync ${e}: not a refs-managed checkout`,ml=async(e,t)=>{if(!U(t))throw T(pl(t));let n=await e.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:t});if(n.exitCode!==0||n.stdout.trim()===``)throw T(pl(t))},hl=/filtering not recognized/iu,gl=e=>e===void 0?{}:{cwd:e},_l=(e,t,n)=>({action:e,args:t,cmd:`git`,...gl(n)}),vl=async(e,t)=>{let n=await e.run(t.cmd,t.args,gl(t.cwd));if(n.exitCode===0)return n;let r=n.stderr.trim()||n.stdout.trim()||`exit code ${n.exitCode}`;throw T(`${t.action} failed: ${r}`)},yl=async(e,t)=>{let n=[`clone`,`-q`];t.mode===`blobless`&&n.push(`--filter=blob:none`),n.push(t.cloneUrl,t.dest);let r=await vl(e,_l(`git clone`,n));return await vl(e,_l(`git config core.hooksPath`,[`config`,`core.hooksPath`,t.hooksDir],t.dest)),t.mode===`blobless`&&hl.test(r.stderr)?{effectiveMode:`full`,warning:`server did not honour the partial-clone filter (blob:none); fell back to a full clone`}:{effectiveMode:t.mode}},bl=async(e,t)=>{let n=await e.run(`git`,[`symbolic-ref`,`--short`,`refs/remotes/origin/HEAD`],{cwd:t});if(n.exitCode!==0)return;let r=n.stdout.trim();return r.startsWith(`origin/`)?r.slice(7):r},xl=async(e,t)=>{let n=await bl(e,t);if(n!==void 0)return n;await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t});let r=await bl(e,t);if(r!==void 0)return r;throw T(`could not detect the default branch for checkout: ${t}`)},Sl=async(e,t)=>(await vl(e,_l(`git rev-parse HEAD`,[`rev-parse`,`HEAD`],t))).stdout.trim(),Cl=async(e,t)=>(await vl(e,_l(`git status --porcelain`,[`status`,`--porcelain`],t))).stdout.trim()!==``,wl=async(e,t)=>{await vl(e,_l(`git fetch`,[`fetch`,`--prune`,`--tags`,`origin`],t.dir));let n=await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t.dir}),r=await xl(e,t.dir),i={branch:r};return r!==t.defaultBranch&&(i.branchRenamedTo=r),n.exitCode!==0&&(i.warning=`could not refresh origin/HEAD: ${cl(n)}`),i},Tl=e=>[_l(`git reset --hard HEAD (pre-checkout)`,[`reset`,`--hard`,`HEAD`],e),_l(`git clean -fd`,[`clean`,`-fd`],e)],El=async(e,t)=>{let{branch:n,dir:r,dirty:i}=t,a=[];i&&a.push(...Tl(r)),a.push(_l(`git checkout -B`,[`checkout`,`-B`,n,`origin/${n}`],r),_l(`git reset --hard`,[`reset`,`--hard`,`origin/${n}`],r));for(let t of a)await vl(e,t)},Dl=async(e,t)=>{await ml(e,t.dir);let n=await Sl(e,t.dir),r=await wl(e,t),i=await Cl(e,t.dir);return await El(e,{branch:r.branch,dir:t.dir,dirty:i}),dl(fl(r,i,{newSha:await Sl(e,t.dir),oldSha:n}))},Ol=async(e,t,n=20)=>(await vl(e,_l(`git tag`,[`tag`,`--sort=-version:refname`],t))).stdout.split(`
348
- `).map(e=>e.trim()).filter(e=>e!==``).slice(0,n),kl=async(e,t,n)=>(await e.run(`git`,[`show-ref`,`--verify`,`--`,`refs/tags/${n}`],{cwd:t})).exitCode===0,Al=[`#!/bin/sh`,`echo "refs: this checkout is a managed read-only reference — commits are blocked" >&2`,`exit 1`,``].join(`
349
- `),jl=async e=>{await Promise.all([`pre-commit`,`pre-push`].map(async t=>{let r=y(e.hooksDir,t);await Rc(r,Al),await n(r,493)}))},Ml=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Nl=/\d+\.\d+\.\d+/gu,Pl=e=>Js.safeParse(e).success,Fl=e=>{let t=e.match(Nl);return t!==null&&t.length>1},Il=e=>{let t=Ml.exec(e);if(!t||Fl(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Pl(r))return r},Ll=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Rl=e=>{let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n];if(r===void 0)continue;let i=Il(r);i&&Ll(t,i,n)}return t},zl=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,Bl=e=>{let t=[...e.entries()];if(t.length===0)return null;let n=t[0];if(!n)return null;let[r,i]=n;return t.slice(1).reduce(({format:e,data:t},[n,r])=>zl(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Vl=e=>{let t=Rl(e);return Bl(t)},Hl=(e,t)=>e.replaceAll(`{version}`,()=>t),Ul=async(e,t,n,r)=>{let i=Hl(n,r);if(!await kl(e,t,i))throw C(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},Wl=/^(?<scheme>[a-z][a-z0-9+.-]*:\/\/)?[\s\S]*@/iu,W=e=>{let t=e.replace(Wl,`$<scheme><redacted>@`);return t.length<=200?t:`${t.slice(0,200)}…`},Gl=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,Kl=/^git\+/u,ql={"https:":`443`,"ssh:":`22`},Jl=e=>e.replace(/\.git$/u,``),Yl=e=>e.split(`/`).some(e=>e===`.`||e===`..`),Xl=e=>e.includes(`\\`),Zl=e=>e.includes(`%`),Ql=e=>{let t=Us.safeParse(e);if(!t.success)throw T(`not a supported git url: derived key '${W(e)}' is invalid`);return t.data},$l=({host:e,port:t,protocol:n})=>{let r=ql[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},eu=e=>{let t=Jl(e.path.replace(/^\/+/u,``).replace(/\/+$/u,``));return Ql(`${$l(e)}/${t}`)},tu=e=>{let t=decodeURIComponent(e).split(`/`).filter(e=>e!==``);if(t.length<2)throw T(`not a supported git url: file url path must have at least 2 segments`);let n=t.at(-2)??``,r=t.at(-1)??``;return Ql(`local/${n}/${r}`)},nu=(e,t)=>{try{return new URL(e)}catch{throw T(`not a supported git url: ${W(t)}`)}},ru=e=>{if(e.password!==``)throw T(`not a supported git url: credentials embedded in url`);if(e.protocol===`https:`&&e.username!==``)throw T(`not a supported git url: credentials embedded in https url`)},iu=(e,t)=>{if(e.protocol===`file:`){if(!t)throw T(`not a supported git url: unsupported protocol ${e.protocol}`);return tu(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw T(`not a supported git url: unsupported protocol ${e.protocol}`);return ru(e),eu({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},au=(e,t)=>{if(Zl(e))throw T(`not a supported git url: percent-encoding not supported in ${W(t)}`);if(e.includes(`:`))throw T(`not a supported git url: ambiguous ':' in scp-style path ${W(t)}; use the ssh:// url form instead`);if(e.startsWith(`/`)||e.startsWith(`~`))throw T(`not a supported git url: ambiguous absolute/home-relative scp path in ${W(t)}; use the ssh:// url form instead`)},ou=(e,t)=>{let n=e.groups?.path??``;return au(n,t),eu({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},su=(e,t)=>{if(Xl(e))throw T(`not a supported git url: backslash not allowed in ${W(t)}`)},cu=(e,t)=>{if(Yl(e))throw T(`not a supported git url: path traversal segment in ${W(t)}`)},lu=(e,t,n)=>{if(e.protocol!==`file:`&&Zl(t))throw T(`not a supported git url: percent-encoding not supported in ${W(n)}`)},uu=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace(Kl,``);su(r,e),cu(r,e);let i=Gl.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:ou(i,e)};let a=nu(r,e);return lu(a,r,e),{cloneUrl:r,key:iu(a,n)}},du=`.git`,fu=e=>e.replace(/^\/+/u,``).replace(/\/+$/u,``),pu=e=>e.endsWith(du)?e:`${e}${du}`,mu=(e,t)=>`https://${e.toLowerCase()}/${fu(t)}`,hu=(e,t)=>`git@${e.toLowerCase()}:${pu(fu(t))}`,gu=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw T(`not a supported git url: unsupported protocol ${e}`)},_u=(e,t,n)=>{let r=ql[e.protocol];if(e.port!==``&&e.port!==r)throw T(`cannot apply git_transport=${t} to ${W(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},vu=(e,t)=>t===`https`?mu(e.hostname,e.pathname):hu(e.hostname,e.pathname),yu=(e,t,n)=>{let r=uu(t).key;if(r!==n)throw T(`git_transport transform changed repo identity: '${W(e)}' → '${t}' (key '${n}' → '${r}')`);return t},bu=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return yu(t.cloneUrl,mu(n,r),t.originalKey)},xu=e=>{let t=nu(e.cloneUrl,e.cloneUrl);return gu(t.protocol)===e.transport?e.cloneUrl:(_u(t,e.transport,e.cloneUrl),yu(e.cloneUrl,vu(t,e.transport),e.originalKey))},Su=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:uu(e).key,transport:t},r=Gl.exec(e);return r?.groups===void 0?xu(n):bu(r,n)},Cu=`meta.json`,wu=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},Tu=e=>{try{return process.kill(e,0),!0}catch(e){return wu(e)!==`ESRCH`}},Eu=e=>{try{return JSON.parse(e)}catch{return}},Du=async e=>{try{return await s(e,`utf8`)}catch{return}},Ou=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},ku=e=>{if(typeof e!=`object`||!e)return;let t=e,{pid:n}=t,r=Ou(t.acquired_at);if(!(typeof n!=`number`||r===void 0))return{acquiredAtMs:r,pid:n}},Au=async e=>{let t=await Du(y(e,Cu));if(t!==void 0)return ku(Eu(t))},ju=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},Mu=async e=>{let t=await Du(y(e,Cu));if(t!==void 0)return ju(Eu(t))},Nu=async e=>{try{return(await p(e)).mtimeMs}catch{return}},Pu=async(e,t)=>{let n=y(e,Cu),r=`${n}.tmp-${re()}`;await m(r,t,`utf8`),await u(r,n)},Fu=async(e,t)=>{await Pu(e,JSON.stringify({acquired_at:new Date().toISOString(),pid:process.pid,token:t}))},Iu=/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u,Lu=async e=>{let t=await Au(e);if(t===void 0){let t=await Nu(e);return t===void 0?!1:Date.now()-t>5e3}return Date.now()-t.acquiredAtMs>6e5?!0:!Tu(t.pid)},Ru=async(e,t)=>{try{await Fu(e,t)}catch(e){if(wu(e)===`ENOENT`)return`retry`;throw e}return t},zu=async e=>{try{return await o(e,{recursive:!1}),!0}catch(e){if(wu(e)===`EEXIST`)return!1;throw e}},Bu=async e=>{if(!await zu(e))return;let t=await Ru(e,re());return t===`retry`?Bu(e):t},Vu=e=>y(e.locksDir,`${e.name}.steal-claim`),Hu=e=>y(e.locksDir,`${e.name}.steal.${re()}`),Uu=async e=>{try{return await o(e,{recursive:!1}),!0}catch(e){if(wu(e)===`EEXIST`)return!1;throw e}},Wu=async e=>{let t=await Nu(e);return t!==void 0&&Date.now()-t>2e3},Gu=async e=>await Uu(e)?!0:await Wu(e)?(await d(e,{force:!0,recursive:!0}),Uu(e)):!1,Ku=async e=>{let t=Hu(e);try{await u(e.lockPath,t)}catch(e){if(wu(e)===`ENOENT`)return;throw e}return t},qu=async e=>{if(!await Lu(e.lockPath))return;let t=await Ku(e);t!==void 0&&await d(t,{force:!0,recursive:!0})},Ju=async e=>{let t=Vu(e);if(await Gu(t))try{await qu(e)}finally{await d(t,{force:!0,recursive:!0})}},Yu=async(e,t)=>{if(await Lu(e.lockPath)){await Ju(e);return}if(Date.now()>=t)throw ot(`lock ${e.name} is held — another refs process is running`);await _e(100)},Xu=async(e,t)=>{let n=await Bu(e.lockPath);return n===void 0?(await Yu(e,t),Xu(e,t)):n},Zu=async(e,t)=>{await Mu(e)===t&&await d(e,{force:!0,recursive:!0})},Qu=e=>{if(e===`.`||e===`..`||!Iu.test(e))throw T(`lock name must not contain "/" or other unsafe characters — only letters, digits, and "_.:-" are allowed, and it may not be "." or "..": ${e}`)},G=async(e,t,n,r)=>{Qu(t);let i={lockPath:y(e.locksDir,t),locksDir:e.locksDir,name:t};await o(e.locksDir,{recursive:!0});let a=Date.now()+(r?.timeoutMs??1e4),s=await Xu(i,a);try{return await n()}finally{await Zu(i.lockPath,s)}},$u=Xo({directory:L().optional(),url:L().optional()}),ed=Xo({repository:Qo([L(),$u]).optional()}),td=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,nd=new Set([`node_modules`,`favicon.ico`]),rd=e=>C(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),id=e=>{let t=e.split(`/`);return t.length>=2?t[1]:e},ad=e=>{if(e.length>214)throw w(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!td.test(e))throw w(`invalid package name: '${e}' does not match npm naming rules`);let t=id(e);if(nd.has(t))throw w(`invalid package name: '${e}' uses a reserved name`)},od=e=>e.replace(`/`,`%2F`),sd=e=>typeof e==`string`?e:e?.url,cd=e=>{if(typeof e==`object`&&e?.directory){let t=Ys.safeParse(e.directory);if(t.success)return t.data}},ld=async(e,t)=>{try{return await e.json()}catch{throw T(`invalid npm registry response for '${t}': not parseable JSON`)}},ud=async(e,t)=>{let n=await e(`https://registry.npmjs.org/${od(t)}`);if(n.status===404)throw C(`npm package '${t}' not found`);if(n.status!==200)throw T(`failed to fetch npm package '${t}': status ${n.status}`);let r=await ld(n,t),i=ed.safeParse(r);if(!i.success)throw T(`invalid npm package response for '${t}'`);return i.data},dd=(e,t)=>{try{return uu(e)}catch{throw rd(t)}},fd=async(e,t)=>{ad(t);let n=await ud(e,t),r=sd(n.repository);if(r===void 0||r===``)throw rd(t);let{cloneUrl:i,key:a}=dd(r,t),o=cd(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}};function K(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}const pd=(e,t)=>{let n=gd(md(e));if(typeof n!=`string`)throw TypeError(`${t} must be a string or a file URL: ${n}.`);return n},md=e=>hd(e)?e.toString():e,hd=e=>typeof e!=`string`&&e&&Object.getPrototypeOf(e)===String.prototype,gd=e=>e instanceof URL?ve(e):e,_d=(e,t=[],n={})=>{let r=pd(e,`First argument`),[i,a]=K(t)?[[],t]:[t,n];if(!Array.isArray(i))throw TypeError(`Second argument must be either an array of arguments or an options object: ${i}`);if(i.some(e=>typeof e==`object`&&!!e))throw TypeError(`Second argument must be an array of strings: ${i}`);let o=i.map(String),s=o.find(e=>e.includes(`\0`));if(s!==void 0)throw TypeError(`Arguments cannot contain null bytes ("\\0"): ${s}`);if(!K(a))throw TypeError(`Last argument must be an options object: ${a}`);return[r,o,a]},{toString:vd}=Object.prototype,yd=e=>vd.call(e)===`[object ArrayBuffer]`,q=e=>vd.call(e)===`[object Uint8Array]`,bd=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),xd=new TextEncoder,Sd=e=>xd.encode(e),Cd=new TextDecoder,wd=e=>Cd.decode(e),Td=(e,t)=>Ed(e,t).join(``),Ed=(e,t)=>{if(t===`utf8`&&e.every(e=>typeof e==`string`))return e;let n=new we(t),r=e.map(e=>typeof e==`string`?Sd(e):e).map(e=>n.write(e)),i=n.end();return i===``?r:[...r,i]},Dd=e=>e.length===1&&q(e[0])?e[0]:kd(Od(e)),Od=e=>e.map(e=>typeof e==`string`?Sd(e):e),kd=e=>{let t=new Uint8Array(Ad(e)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t},Ad=e=>{let t=0;for(let n of e)t+=n.length;return t},jd=e=>Array.isArray(e)&&Array.isArray(e.raw),Md=(e,t)=>{let n=[];for(let[r,i]of e.entries())n=Nd({templates:e,expressions:t,tokens:n,index:r,template:i});if(n.length===0)throw TypeError(`Template script must not be empty`);let[r,...i]=n;return[r,i,{}]},Nd=({templates:e,expressions:t,tokens:n,index:r,template:i})=>{if(i===void 0)throw TypeError(`Invalid backslash sequence: ${e.raw[r]}`);let{nextTokens:a,leadingWhitespaces:o,trailingWhitespaces:s}=Pd(i,e.raw[r]),c=Ld(n,a,o);if(r===t.length)return c;let l=t[r],u=Array.isArray(l)?l.map(e=>Rd(e)):[Rd(l)];return Ld(c,u,s)},Pd=(e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};let n=[],r=0,i=Fd.has(t[0]);for(let i=0,a=0;i<e.length;i+=1,a+=1){let o=t[a];if(Fd.has(o))r!==i&&n.push(e.slice(r,i)),r=i+1;else if(o===`\\`){let e=t[a+1];e===`
350
- `?(--i,a+=1):e===`u`&&t[a+2]===`{`?a=t.indexOf(`}`,a+3):a+=Id[e]??1}}let a=r===e.length;return a||n.push(e.slice(r)),{nextTokens:n,leadingWhitespaces:i,trailingWhitespaces:a}},Fd=new Set([` `,` `,`\r`,`
351
- `]),Id={x:3,u:5},Ld=(e,t,n)=>n||e.length===0||t.length===0?[...e,...t]:[...e.slice(0,-1),`${e.at(-1)}${t[0]}`,...t.slice(1)],Rd=e=>{let t=typeof e;if(t===`string`)return e;if(t===`number`)return String(e);if(K(e)&&(`stdout`in e||`isMaxBuffer`in e))return zd(e);throw e instanceof be||Object.prototype.toString.call(e)===`[object Promise]`?TypeError("Unexpected subprocess in template expression. Please use ${await subprocess} instead of ${subprocess}."):TypeError(`Unexpected "${t}" in template expression`)},zd=({stdout:e})=>{if(typeof e==`string`)return e;if(q(e))return wd(e);throw TypeError(e===void 0?`Missing result.stdout in template expression. This is probably due to the previous subprocess' "stdout" option.`:`Unexpected "${typeof e}" stdout in template expression`)},Bd=e=>Vd.includes(e),Vd=[b.stdin,b.stdout,b.stderr],Hd=[`stdin`,`stdout`,`stderr`],Ud=e=>Hd[e]??`stdio[${e}]`,Wd=e=>{let t={...e};for(let n of nf)t[n]=Gd(e,n);return t},Gd=(e,t)=>{let n=Array.from({length:Kd(e)+1}),r=qd(e[t],n,t);return ef(r,t)},Kd=({stdio:e})=>Array.isArray(e)?Math.max(e.length,Hd.length):Hd.length,qd=(e,t,n)=>K(e)?Jd(e,t,n):t.fill(e),Jd=(e,t,n)=>{for(let r of Object.keys(e).sort(Yd))for(let i of Zd(r,n,t))t[i]=e[r];return t},Yd=(e,t)=>Xd(e)<Xd(t)?1:-1,Xd=e=>e===`stdout`||e===`stderr`?0:e===`all`?2:1,Zd=(e,t,n)=>{if(e===`ipc`)return[n.length-1];let r=Qd(e);if(r===void 0||r===0)throw TypeError(`"${t}.${e}" is invalid.
352
- It must be "${t}.stdout", "${t}.stderr", "${t}.all", "${t}.ipc", or "${t}.fd3", "${t}.fd4" (and so on).`);if(r>=n.length)throw TypeError(`"${t}.${e}" is invalid: that file descriptor does not exist.
353
- Please set the "stdio" option to ensure that file descriptor exists.`);return r===`all`?[1,2]:[r]},Qd=e=>{if(e===`all`)return e;if(Hd.includes(e))return Hd.indexOf(e);let t=$d.exec(e);if(t!==null)return Number(t[1])},$d=/^fd(\d+)$/,ef=(e,t)=>e.map(e=>e===void 0?tf[t]:e),tf={lines:!1,buffer:!0,maxBuffer:1e3*1e3*100,verbose:De(`execa`).enabled?`full`:`none`,stripFinalNewline:!0},nf=[`lines`,`buffer`,`maxBuffer`,`verbose`,`stripFinalNewline`],rf=(e,t)=>t===`ipc`?e.at(-1):e[t],af=({verbose:e},t)=>cf(e,t)!==`none`,of=({verbose:e},t)=>![`none`,`short`].includes(cf(e,t)),sf=({verbose:e},t)=>{let n=cf(e,t);return uf(n)?n:void 0},cf=(e,t)=>t===void 0?lf(e):rf(e,t),lf=e=>e.find(e=>uf(e))??df.findLast(t=>e.includes(t)),uf=e=>typeof e==`function`,df=[`none`,`short`,`full`],ff=(e,t)=>{let n=[e,...t];return{command:n.join(` `),escapedCommand:n.map(e=>yf(mf(e))).join(` `)}},pf=e=>Ae(e).split(`
354
- `).map(e=>mf(e)).join(`
355
- `),mf=e=>e.replaceAll(gf,e=>hf(e)),hf=e=>{let t=_f[e];if(t!==void 0)return t;let n=e.codePointAt(0),r=n.toString(16);return n<=vf?`\\u${r.padStart(4,`0`)}`:`\\U${r}`},gf=(()=>{try{return RegExp(`\\p{Separator}|\\p{Other}`,`gu`)}catch{return/[\s\u0000-\u001F\u007F-\u009F\u00AD]/g}})(),_f={" ":` `,"\b":`\\b`,"\f":`\\f`,"\n":`\\n`,"\r":`\\r`," ":`\\t`},vf=65535,yf=e=>bf.test(e)?e:Pe===`win32`?`"${e.replaceAll(`"`,`""`)}"`:`'${e.replaceAll(`'`,`'\\''`)}'`,bf=/^[\w./-]+$/;function xf(){let{env:e}=b,{TERM:t,TERM_PROGRAM:n}=e;return b.platform===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||n===`Terminus-Sublime`||n===`vscode`||t===`xterm-256color`||t===`alacritty`||t===`rxvt-unicode`||t===`rxvt-unicode-256color`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`:t!==`linux`}const Sf={circleQuestionMark:`(?)`,questionMarkPrefix:`(?)`,square:`█`,squareDarkShade:`▓`,squareMediumShade:`▒`,squareLightShade:`░`,squareTop:`▀`,squareBottom:`▄`,squareLeft:`▌`,squareRight:`▐`,squareCenter:`■`,bullet:`●`,dot:`․`,ellipsis:`…`,pointerSmall:`›`,triangleUp:`▲`,triangleUpSmall:`▴`,triangleDown:`▼`,triangleDownSmall:`▾`,triangleLeftSmall:`◂`,triangleRightSmall:`▸`,home:`⌂`,heart:`♥`,musicNote:`♪`,musicNoteBeamed:`♫`,arrowUp:`↑`,arrowDown:`↓`,arrowLeft:`←`,arrowRight:`→`,arrowLeftRight:`↔`,arrowUpDown:`↕`,almostEqual:`≈`,notEqual:`≠`,lessOrEqual:`≤`,greaterOrEqual:`≥`,identical:`≡`,infinity:`∞`,subscriptZero:`₀`,subscriptOne:`₁`,subscriptTwo:`₂`,subscriptThree:`₃`,subscriptFour:`₄`,subscriptFive:`₅`,subscriptSix:`₆`,subscriptSeven:`₇`,subscriptEight:`₈`,subscriptNine:`₉`,oneHalf:`½`,oneThird:`⅓`,oneQuarter:`¼`,oneFifth:`⅕`,oneSixth:`⅙`,oneEighth:`⅛`,twoThirds:`⅔`,twoFifths:`⅖`,threeQuarters:`¾`,threeFifths:`⅗`,threeEighths:`⅜`,fourFifths:`⅘`,fiveSixths:`⅚`,fiveEighths:`⅝`,sevenEighths:`⅞`,line:`─`,lineBold:`━`,lineDouble:`═`,lineDashed0:`┄`,lineDashed1:`┅`,lineDashed2:`┈`,lineDashed3:`┉`,lineDashed4:`╌`,lineDashed5:`╍`,lineDashed6:`╴`,lineDashed7:`╶`,lineDashed8:`╸`,lineDashed9:`╺`,lineDashed10:`╼`,lineDashed11:`╾`,lineDashed12:`−`,lineDashed13:`–`,lineDashed14:`‐`,lineDashed15:`⁃`,lineVertical:`│`,lineVerticalBold:`┃`,lineVerticalDouble:`║`,lineVerticalDashed0:`┆`,lineVerticalDashed1:`┇`,lineVerticalDashed2:`┊`,lineVerticalDashed3:`┋`,lineVerticalDashed4:`╎`,lineVerticalDashed5:`╏`,lineVerticalDashed6:`╵`,lineVerticalDashed7:`╷`,lineVerticalDashed8:`╹`,lineVerticalDashed9:`╻`,lineVerticalDashed10:`╽`,lineVerticalDashed11:`╿`,lineDownLeft:`┐`,lineDownLeftArc:`╮`,lineDownBoldLeftBold:`┓`,lineDownBoldLeft:`┒`,lineDownLeftBold:`┑`,lineDownDoubleLeftDouble:`╗`,lineDownDoubleLeft:`╖`,lineDownLeftDouble:`╕`,lineDownRight:`┌`,lineDownRightArc:`╭`,lineDownBoldRightBold:`┏`,lineDownBoldRight:`┎`,lineDownRightBold:`┍`,lineDownDoubleRightDouble:`╔`,lineDownDoubleRight:`╓`,lineDownRightDouble:`╒`,lineUpLeft:`┘`,lineUpLeftArc:`╯`,lineUpBoldLeftBold:`┛`,lineUpBoldLeft:`┚`,lineUpLeftBold:`┙`,lineUpDoubleLeftDouble:`╝`,lineUpDoubleLeft:`╜`,lineUpLeftDouble:`╛`,lineUpRight:`└`,lineUpRightArc:`╰`,lineUpBoldRightBold:`┗`,lineUpBoldRight:`┖`,lineUpRightBold:`┕`,lineUpDoubleRightDouble:`╚`,lineUpDoubleRight:`╙`,lineUpRightDouble:`╘`,lineUpDownLeft:`┤`,lineUpBoldDownBoldLeftBold:`┫`,lineUpBoldDownBoldLeft:`┨`,lineUpDownLeftBold:`┥`,lineUpBoldDownLeftBold:`┩`,lineUpDownBoldLeftBold:`┪`,lineUpDownBoldLeft:`┧`,lineUpBoldDownLeft:`┦`,lineUpDoubleDownDoubleLeftDouble:`╣`,lineUpDoubleDownDoubleLeft:`╢`,lineUpDownLeftDouble:`╡`,lineUpDownRight:`├`,lineUpBoldDownBoldRightBold:`┣`,lineUpBoldDownBoldRight:`┠`,lineUpDownRightBold:`┝`,lineUpBoldDownRightBold:`┡`,lineUpDownBoldRightBold:`┢`,lineUpDownBoldRight:`┟`,lineUpBoldDownRight:`┞`,lineUpDoubleDownDoubleRightDouble:`╠`,lineUpDoubleDownDoubleRight:`╟`,lineUpDownRightDouble:`╞`,lineDownLeftRight:`┬`,lineDownBoldLeftBoldRightBold:`┳`,lineDownLeftBoldRightBold:`┯`,lineDownBoldLeftRight:`┰`,lineDownBoldLeftBoldRight:`┱`,lineDownBoldLeftRightBold:`┲`,lineDownLeftRightBold:`┮`,lineDownLeftBoldRight:`┭`,lineDownDoubleLeftDoubleRightDouble:`╦`,lineDownDoubleLeftRight:`╥`,lineDownLeftDoubleRightDouble:`╤`,lineUpLeftRight:`┴`,lineUpBoldLeftBoldRightBold:`┻`,lineUpLeftBoldRightBold:`┷`,lineUpBoldLeftRight:`┸`,lineUpBoldLeftBoldRight:`┹`,lineUpBoldLeftRightBold:`┺`,lineUpLeftRightBold:`┶`,lineUpLeftBoldRight:`┵`,lineUpDoubleLeftDoubleRightDouble:`╩`,lineUpDoubleLeftRight:`╨`,lineUpLeftDoubleRightDouble:`╧`,lineUpDownLeftRight:`┼`,lineUpBoldDownBoldLeftBoldRightBold:`╋`,lineUpDownBoldLeftBoldRightBold:`╈`,lineUpBoldDownLeftBoldRightBold:`╇`,lineUpBoldDownBoldLeftRightBold:`╊`,lineUpBoldDownBoldLeftBoldRight:`╉`,lineUpBoldDownLeftRight:`╀`,lineUpDownBoldLeftRight:`╁`,lineUpDownLeftBoldRight:`┽`,lineUpDownLeftRightBold:`┾`,lineUpBoldDownBoldLeftRight:`╂`,lineUpDownLeftBoldRightBold:`┿`,lineUpBoldDownLeftBoldRight:`╃`,lineUpBoldDownLeftRightBold:`╄`,lineUpDownBoldLeftBoldRight:`╅`,lineUpDownBoldLeftRightBold:`╆`,lineUpDoubleDownDoubleLeftDoubleRightDouble:`╬`,lineUpDoubleDownDoubleLeftRight:`╫`,lineUpDownLeftDoubleRightDouble:`╪`,lineCross:`╳`,lineBackslash:`╲`,lineSlash:`╱`},Cf={tick:`✔`,info:`ℹ`,warning:`⚠`,cross:`✘`,squareSmall:`◻`,squareSmallFilled:`◼`,circle:`◯`,circleFilled:`◉`,circleDotted:`◌`,circleDouble:`◎`,circleCircle:`ⓞ`,circleCross:`ⓧ`,circlePipe:`Ⓘ`,radioOn:`◉`,radioOff:`◯`,checkboxOn:`☒`,checkboxOff:`☐`,checkboxCircleOn:`ⓧ`,checkboxCircleOff:`Ⓘ`,pointer:`❯`,triangleUpOutline:`△`,triangleLeft:`◀`,triangleRight:`▶`,lozenge:`◆`,lozengeOutline:`◇`,hamburger:`☰`,smiley:`㋡`,mustache:`෴`,star:`★`,play:`▶`,nodejs:`⬢`,oneSeventh:`⅐`,oneNinth:`⅑`,oneTenth:`⅒`},wf={tick:`√`,info:`i`,warning:`‼`,cross:`×`,squareSmall:`□`,squareSmallFilled:`■`,circle:`( )`,circleFilled:`(*)`,circleDotted:`( )`,circleDouble:`( )`,circleCircle:`(○)`,circleCross:`(×)`,circlePipe:`(│)`,radioOn:`(*)`,radioOff:`( )`,checkboxOn:`[×]`,checkboxOff:`[ ]`,checkboxCircleOn:`(×)`,checkboxCircleOff:`( )`,pointer:`>`,triangleUpOutline:`∆`,triangleLeft:`◄`,triangleRight:`►`,lozenge:`♦`,lozengeOutline:`◊`,hamburger:`≡`,smiley:`☺`,mustache:`┌─┐`,star:`✶`,play:`►`,nodejs:`♦`,oneSeventh:`1/7`,oneNinth:`1/9`,oneTenth:`1/10`},Tf={...Sf,...Cf},Ef={...Sf,...wf},Df=xf()?Tf:Ef;Object.entries(Cf);const Of=Fe?.WriteStream?.prototype?.hasColors?.()??!1,J=(e,t)=>{if(!Of)return e=>e;let n=`\u001B[${e}m`,r=`\u001B[${t}m`;return e=>{let i=e+``,a=i.indexOf(r);if(a===-1)return n+i+r;let o=n,s=0,c=(t===22?r:``)+n;for(;a!==-1;)o+=i.slice(s,a)+c,s=a+r.length,a=i.indexOf(r,s);return o+=i.slice(s)+r,o}};J(0,0);const kf=J(1,22);J(2,22),J(3,23),J(4,24),J(53,55),J(7,27),J(8,28),J(9,29),J(30,39),J(31,39),J(32,39),J(33,39),J(34,39),J(35,39),J(36,39),J(37,39);const Af=J(90,39);J(40,49),J(41,49),J(42,49),J(43,49),J(44,49),J(45,49),J(46,49),J(47,49),J(100,49);const jf=J(91,39);J(92,39);const Mf=J(93,39);J(94,39),J(95,39),J(96,39),J(97,39),J(101,49),J(102,49),J(103,49),J(104,49),J(105,49),J(106,49),J(107,49);const Nf=({type:e,message:t,timestamp:n,piped:r,commandId:i,result:{failed:a=!1}={},options:{reject:o=!0}})=>{let s=Pf(n),c=Lf[e]({failed:a,reject:o,piped:r}),l=zf[e]({reject:o});return`${Af(`[${s}]`)} ${Af(`[${i}]`)} ${l(c)} ${l(t)}`},Pf=e=>`${Ff(e.getHours(),2)}:${Ff(e.getMinutes(),2)}:${Ff(e.getSeconds(),2)}.${Ff(e.getMilliseconds(),3)}`,Ff=(e,t)=>String(e).padStart(t,`0`),If=({failed:e,reject:t})=>e?t?Df.cross:Df.warning:Df.tick,Lf={command:({piped:e})=>e?`|`:`$`,output:()=>` `,ipc:()=>`*`,error:If,duration:If},Rf=e=>e,zf={command:()=>kf,output:()=>Rf,ipc:()=>Rf,error:({reject:e})=>e?jf:Mf,duration:()=>Af},Bf=(e,t,n)=>{let r=sf(t,n);return e.map(({verboseLine:e,verboseObject:t})=>Vf(e,t,r)).filter(e=>e!==void 0).map(e=>Hf(e)).join(``)},Vf=(e,t,n)=>{if(n===void 0)return e;let r=n(e,t);if(typeof r==`string`)return r},Hf=e=>e.endsWith(`
356
- `)?e:`${e}\n`,Uf=({type:e,verboseMessage:t,fdNumber:n,verboseInfo:r,result:i})=>{let a=Wf({type:e,result:i,verboseInfo:r}),o=Bf(Gf(t,a),r,n);o!==``&&console.warn(o.slice(0,-1))},Wf=({type:e,result:t,verboseInfo:{escapedCommand:n,commandId:r,rawOptions:{piped:i=!1,...a}}})=>({type:e,escapedCommand:n,commandId:`${r}`,timestamp:new Date,piped:i,result:t,options:a}),Gf=(e,t)=>e.split(`
357
- `).map(e=>Kf({...t,message:e})),Kf=e=>({verboseLine:Nf(e),verboseObject:e}),qf=e=>pf(typeof e==`string`?e:Oe(e)).replaceAll(` `,` `.repeat(Jf)),Jf=2,Yf=(e,t)=>{af(t)&&Uf({type:`command`,verboseMessage:e,verboseInfo:t})},Xf=(e,t,n)=>($f(e),{verbose:e,escapedCommand:t,commandId:Zf(e),rawOptions:n}),Zf=e=>af({verbose:e})?Qf++:void 0;let Qf=0n;const $f=e=>{for(let t of e){if(t===!1)throw TypeError(`The "verbose: false" option was renamed to "verbose: 'none'".`);if(t===!0)throw TypeError(`The "verbose: true" option was renamed to "verbose: 'short'".`);if(!df.includes(t)&&!uf(t)){let e=df.map(e=>`'${e}'`).join(`, `);throw TypeError(`The "verbose" option must not be ${t}. Allowed values are: ${e} or a function.`)}}},ep=()=>Ne.bigint(),tp=e=>Number(Ne.bigint()-e)/1e6,np=(e,t,n)=>{let r=ep(),{command:i,escapedCommand:a}=ff(e,t),o=Xf(Gd(n,`verbose`),a,{...n});return Yf(a,o),{command:i,escapedCommand:a,startTime:r,verboseInfo:o}};var rp=S(((e,t)=>{t.exports=a,a.sync=o;var n=rt(`fs`);function r(e,t){var n=t.pathExt===void 0?process.env.PATHEXT:t.pathExt;if(!n||(n=n.split(`;`),n.indexOf(``)!==-1))return!0;for(var r=0;r<n.length;r++){var i=n[r].toLowerCase();if(i&&e.substr(-i.length).toLowerCase()===i)return!0}return!1}function i(e,t,n){return!e.isSymbolicLink()&&!e.isFile()?!1:r(t,n)}function a(e,t,r){n.stat(e,function(n,a){r(n,n?!1:i(a,e,t))})}function o(e,t){return i(n.statSync(e),e,t)}})),ip=S(((e,t)=>{t.exports=r,r.sync=i;var n=rt(`fs`);function r(e,t,r){n.stat(e,function(e,n){r(e,e?!1:a(n,t))})}function i(e,t){return a(n.statSync(e),t)}function a(e,t){return e.isFile()&&o(e,t)}function o(e,t){var n=e.mode,r=e.uid,i=e.gid,a=t.uid===void 0?process.getuid&&process.getuid():t.uid,o=t.gid===void 0?process.getgid&&process.getgid():t.gid,s=64,c=8,l=1,u=s|c;return n&l||n&c&&i===o||n&s&&r===a||n&u&&a===0}})),ap=S(((e,t)=>{rt(`fs`);var n=process.platform===`win32`||global.TESTING_WINDOWS?rp():ip();t.exports=r,r.sync=i;function r(e,t,i){if(typeof t==`function`&&(i=t,t={}),!i){if(typeof Promise!=`function`)throw TypeError(`callback not provided`);return new Promise(function(n,i){r(e,t||{},function(e,t){e?i(e):n(t)})})}n(e,t||{},function(e,n){e&&(e.code===`EACCES`||t&&t.ignoreErrors)&&(e=null,n=!1),i(e,n)})}function i(e,t){try{return n.sync(e,t||{})}catch(e){if(t&&t.ignoreErrors||e.code===`EACCES`)return!1;throw e}}})),op=S(((e,t)=>{let n=process.platform===`win32`||process.env.OSTYPE===`cygwin`||process.env.OSTYPE===`msys`,r=rt(`path`),i=n?`;`:`:`,a=ap(),o=e=>Object.assign(Error(`not found: ${e}`),{code:`ENOENT`}),s=(e,t)=>{let r=t.colon||i,a=e.match(/\//)||n&&e.match(/\\/)?[``]:[...n?[process.cwd()]:[],...(t.path||process.env.PATH||``).split(r)],o=n?t.pathExt||process.env.PATHEXT||`.EXE;.CMD;.BAT;.COM`:``,s=n?o.split(r):[``];return n&&e.indexOf(`.`)!==-1&&s[0]!==``&&s.unshift(``),{pathEnv:a,pathExt:s,pathExtExe:o}},c=(e,t,n)=>{typeof t==`function`&&(n=t,t={}),t||={};let{pathEnv:i,pathExt:c,pathExtExe:l}=s(e,t),u=[],d=n=>new Promise((a,s)=>{if(n===i.length)return t.all&&u.length?a(u):s(o(e));let c=i[n],l=/^".*"$/.test(c)?c.slice(1,-1):c,d=r.join(l,e),p=!l&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;a(f(p,n,0))}),f=(e,n,r)=>new Promise((i,o)=>{if(r===c.length)return i(d(n+1));let s=c[r];a(e+s,{pathExt:l},(a,o)=>{if(!a&&o)if(t.all)u.push(e+s);else return i(e+s);return i(f(e,n,r+1))})});return n?d(0).then(e=>n(null,e),n):d(0)};t.exports=c,c.sync=(e,t)=>{t||={};let{pathEnv:n,pathExt:i,pathExtExe:c}=s(e,t),l=[];for(let o=0;o<n.length;o++){let s=n[o],u=/^".*"$/.test(s)?s.slice(1,-1):s,d=r.join(u,e),f=!u&&/^\.[\\\/]/.test(e)?e.slice(0,2)+d:d;for(let e=0;e<i.length;e++){let n=f+i[e];try{if(a.sync(n,{pathExt:c}))if(t.all)l.push(n);else return n}catch{}}}if(t.all&&l.length)return l;if(t.nothrow)return null;throw o(e)}})),sp=S(((e,t)=>{let n=(e={})=>{let t=e.env||process.env;return(e.platform||process.platform)===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`};t.exports=n,t.exports.default=n})),cp=S(((e,t)=>{let n=rt(`path`),r=op(),i=sp();function a(e,t){let a=e.options.env||process.env,o=process.cwd(),s=e.options.cwd!=null,c=s&&process.chdir!==void 0&&!process.chdir.disabled;if(c)try{process.chdir(e.options.cwd)}catch{}let l;try{l=r.sync(e.command,{path:a[i({env:a})],pathExt:t?n.delimiter:void 0})}catch{}finally{c&&process.chdir(o)}return l&&=n.resolve(s?e.options.cwd:``,l),l}function o(e){return a(e)||a(e,!0)}t.exports=o})),lp=S(((e,t)=>{let n=/([()\][%!^"`<>&|;, *?])/g;function r(e){return e=e.replace(n,`^$1`),e}function i(e,t){return e=`${e}`,e=e.replace(/(?=(\\+?)?)\1"/g,`$1$1\\"`),e=e.replace(/(?=(\\+?)?)\1$/,`$1$1`),e=`"${e}"`,e=e.replace(n,`^$1`),t&&(e=e.replace(n,`^$1`)),e}t.exports.command=r,t.exports.argument=i})),up=S(((e,t)=>{t.exports=/^#!(.*)/})),dp=S(((e,t)=>{let n=up();t.exports=(e=``)=>{let t=e.match(n);if(!t)return null;let[r,i]=t[0].replace(/#! ?/,``).split(` `),a=r.split(`/`).pop();return a===`env`?i:i?`${a} ${i}`:a}})),fp=S(((e,t)=>{let n=rt(`fs`),r=dp();function i(e){let t=Buffer.alloc(150),i;try{i=n.openSync(e,`r`),n.readSync(i,t,0,150,0),n.closeSync(i)}catch{}return r(t.toString())}t.exports=i})),pp=S(((e,t)=>{let n=rt(`path`),r=cp(),i=lp(),a=fp(),o=process.platform===`win32`,s=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function l(e){e.file=r(e);let t=e.file&&a(e.file);return t?(e.args.unshift(e.file),e.command=t,r(e)):e.file}function u(e){if(!o)return e;let t=l(e),r=!s.test(t);if(e.options.forceShell||r){let r=c.test(t);e.command=n.normalize(e.command),e.command=i.command(e.command),e.args=e.args.map(e=>i.argument(e,r)),e.args=[`/d`,`/s`,`/c`,`"${[e.command].concat(e.args).join(` `)}"`],e.command=process.env.comspec||`cmd.exe`,e.options.windowsVerbatimArguments=!0}return e}function d(e,t,n){t&&!Array.isArray(t)&&(n=t,t=null),t=t?t.slice(0):[],n=Object.assign({},n);let r={command:e,args:t,options:n,file:void 0,original:{command:e,args:t}};return n.shell?r:u(r)}t.exports=d})),mp=S(((e,t)=>{let n=process.platform===`win32`;function r(e,t){return Object.assign(Error(`${t} ${e.command} ENOENT`),{code:`ENOENT`,errno:`ENOENT`,syscall:`${t} ${e.command}`,path:e.command,spawnargs:e.args})}function i(e,t){if(!n)return;let r=e.emit;e.emit=function(n,i){if(n===`exit`){let n=a(i,t);if(n)return r.call(e,`error`,n)}return r.apply(e,arguments)}}function a(e,t){return n&&e===1&&!t.file?r(t.original,`spawn`):null}function o(e,t){return n&&e===1&&!t.file?r(t.original,`spawnSync`):null}t.exports={hookChildProcess:i,verifyENOENT:a,verifyENOENTSync:o,notFoundError:r}})),hp=nt(S(((e,t)=>{let n=rt(`child_process`),r=pp(),i=mp();function a(e,t,a){let o=r(e,t,a),s=n.spawn(o.command,o.args,o.options);return i.hookChildProcess(s,o),s}function o(e,t,a){let o=r(e,t,a),s=n.spawnSync(o.command,o.args,o.options);return s.error=s.error||i.verifyENOENTSync(s.status,o),s}t.exports=a,t.exports.spawn=a,t.exports.sync=o,t.exports._parse=r,t.exports._enoent=i}))(),1);function gp(e={}){let{env:t=process.env,platform:n=process.platform}=e;return n===`win32`?Object.keys(t).reverse().find(e=>e.toUpperCase()===`PATH`)||`Path`:`PATH`}ke(xe);function _p(e){return e instanceof URL?ve(e):e}function vp(e){return{*[Symbol.iterator](){let t=h.resolve(_p(e)),n;for(;n!==t;)yield t,n=t,t=h.resolve(t,`..`)}}}const yp=({cwd:e=b.cwd(),path:t=b.env[gp()],preferLocal:n=!0,execPath:r=b.execPath,addExecPath:i=!0}={})=>{let a=h.resolve(_p(e)),o=[],s=t.split(h.delimiter);return n&&bp(o,s,a),i&&xp(o,s,r,a),t===``||t===h.delimiter?`${o.join(h.delimiter)}${t}`:[...o,t].join(h.delimiter)},bp=(e,t,n)=>{for(let r of vp(n)){let n=h.join(r,`node_modules/.bin`);t.includes(n)||e.push(n)}},xp=(e,t,n,r)=>{let i=h.resolve(r,_p(n),`..`);t.includes(i)||e.push(i)},Sp=({env:e=b.env,...t}={})=>{e={...e};let n=gp({env:e});return t.path=e[n],e[n]=yp(t),e},Cp=(e,t,n)=>new(n?Ap:kp)(t,e instanceof wp?{}:{cause:e});var wp=class extends Error{};const Tp=(e,t)=>{Object.defineProperty(e.prototype,"name",{value:t,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,Dp,{value:!0,writable:!1,enumerable:!1,configurable:!1})},Ep=e=>Op(e)&&Dp in e,Dp=Symbol(`isExecaError`),Op=e=>Object.prototype.toString.call(e)===`[object Error]`;var kp=class extends Error{};Tp(kp,kp.name);var Ap=class extends Error{};Tp(Ap,Ap.name);const jp=()=>{let e=64-Np+1;return Array.from({length:e},Mp)},Mp=(e,t)=>({name:`SIGRT${t+1}`,number:Np+t,action:`terminate`,description:`Application-specific signal (realtime)`,standard:`posix`}),Np=34,Pp=[{name:`SIGHUP`,number:1,action:`terminate`,description:`Terminal closed`,standard:`posix`},{name:`SIGINT`,number:2,action:`terminate`,description:`User interruption with CTRL-C`,standard:`ansi`},{name:`SIGQUIT`,number:3,action:`core`,description:`User interruption with CTRL-\\`,standard:`posix`},{name:`SIGILL`,number:4,action:`core`,description:`Invalid machine instruction`,standard:`ansi`},{name:`SIGTRAP`,number:5,action:`core`,description:`Debugger breakpoint`,standard:`posix`},{name:`SIGABRT`,number:6,action:`core`,description:`Aborted`,standard:`ansi`},{name:`SIGIOT`,number:6,action:`core`,description:`Aborted`,standard:`bsd`},{name:`SIGBUS`,number:7,action:`core`,description:`Bus error due to misaligned, non-existing address or paging error`,standard:`bsd`},{name:`SIGEMT`,number:7,action:`terminate`,description:`Command should be emulated but is not implemented`,standard:`other`},{name:`SIGFPE`,number:8,action:`core`,description:`Floating point arithmetic error`,standard:`ansi`},{name:`SIGKILL`,number:9,action:`terminate`,description:`Forced termination`,standard:`posix`,forced:!0},{name:`SIGUSR1`,number:10,action:`terminate`,description:`Application-specific signal`,standard:`posix`},{name:`SIGSEGV`,number:11,action:`core`,description:`Segmentation fault`,standard:`ansi`},{name:`SIGUSR2`,number:12,action:`terminate`,description:`Application-specific signal`,standard:`posix`},{name:`SIGPIPE`,number:13,action:`terminate`,description:`Broken pipe or socket`,standard:`posix`},{name:`SIGALRM`,number:14,action:`terminate`,description:`Timeout or timer`,standard:`posix`},{name:`SIGTERM`,number:15,action:`terminate`,description:`Termination`,standard:`ansi`},{name:`SIGSTKFLT`,number:16,action:`terminate`,description:`Stack is empty or overflowed`,standard:`other`},{name:`SIGCHLD`,number:17,action:`ignore`,description:`Child process terminated, paused or unpaused`,standard:`posix`},{name:`SIGCLD`,number:17,action:`ignore`,description:`Child process terminated, paused or unpaused`,standard:`other`},{name:`SIGCONT`,number:18,action:`unpause`,description:`Unpaused`,standard:`posix`,forced:!0},{name:`SIGSTOP`,number:19,action:`pause`,description:`Paused`,standard:`posix`,forced:!0},{name:`SIGTSTP`,number:20,action:`pause`,description:`Paused using CTRL-Z or "suspend"`,standard:`posix`},{name:`SIGTTIN`,number:21,action:`pause`,description:`Background process cannot read terminal input`,standard:`posix`},{name:`SIGBREAK`,number:21,action:`terminate`,description:`User interruption with CTRL-BREAK`,standard:`other`},{name:`SIGTTOU`,number:22,action:`pause`,description:`Background process cannot write to terminal output`,standard:`posix`},{name:`SIGURG`,number:23,action:`ignore`,description:`Socket received out-of-band data`,standard:`bsd`},{name:`SIGXCPU`,number:24,action:`core`,description:`Process timed out`,standard:`bsd`},{name:`SIGXFSZ`,number:25,action:`core`,description:`File too big`,standard:`bsd`},{name:`SIGVTALRM`,number:26,action:`terminate`,description:`Timeout or timer`,standard:`bsd`},{name:`SIGPROF`,number:27,action:`terminate`,description:`Timeout or timer`,standard:`bsd`},{name:`SIGWINCH`,number:28,action:`ignore`,description:`Terminal window size changed`,standard:`bsd`},{name:`SIGIO`,number:29,action:`terminate`,description:`I/O is available`,standard:`other`},{name:`SIGPOLL`,number:29,action:`terminate`,description:`Watched event`,standard:`other`},{name:`SIGINFO`,number:29,action:`ignore`,description:`Request for process information`,standard:`other`},{name:`SIGPWR`,number:30,action:`terminate`,description:`Device running out of power`,standard:`systemv`},{name:`SIGSYS`,number:31,action:`core`,description:`Invalid system call`,standard:`other`},{name:`SIGUNUSED`,number:31,action:`terminate`,description:`Invalid system call`,standard:`other`}],Fp=()=>{let e=jp();return[...Pp,...e].map(Ip)},Ip=({name:e,number:t,description:n,action:r,forced:i=!1,standard:a})=>{let{signals:{[e]:o}}=pe,s=o!==void 0;return{name:e,number:s?o:t,description:n,supported:s,action:r,forced:i,standard:a}},Lp=()=>{let e=Fp();return Object.fromEntries(e.map(Rp))},Rp=({name:e,number:t,description:n,supported:r,action:i,forced:a,standard:o})=>[e,{name:e,number:t,description:n,supported:r,action:i,forced:a,standard:o}],zp=Lp(),Bp=()=>{let e=Fp(),t=Array.from({length:65},(t,n)=>Vp(n,e));return Object.assign({},...t)},Vp=(e,t)=>{let n=Hp(e,t);if(n===void 0)return{};let{name:r,description:i,supported:a,action:o,forced:s,standard:c}=n;return{[e]:{name:r,number:e,description:i,supported:a,action:o,forced:s,standard:c}}},Hp=(e,t)=>{let n=t.find(({name:t})=>pe.signals[t]===e);return n===void 0?t.find(t=>t.number===e):n};Bp();const Up=e=>{let t="option `killSignal`";if(e===0)throw TypeError(`Invalid ${t}: 0 cannot be used.`);return Gp(e,t)},Wp=e=>e===0?e:Gp(e,"`subprocess.kill()`'s argument"),Gp=(e,t)=>{if(Number.isInteger(e))return Kp(e,t);if(typeof e==`string`)return Jp(e,t);throw TypeError(`Invalid ${t} ${String(e)}: it must be a string or an integer.\n${Yp()}`)},Kp=(e,t)=>{if(qp.has(e))return qp.get(e);throw TypeError(`Invalid ${t} ${e}: this signal integer does not exist.\n${Yp()}`)},qp=new Map(Object.entries(pe.signals).reverse().map(([e,t])=>[t,e])),Jp=(e,t)=>{if(e in pe.signals)return e;throw e.toUpperCase()in pe.signals?TypeError(`Invalid ${t} '${e}': please rename it to '${e.toUpperCase()}'.`):TypeError(`Invalid ${t} '${e}': this signal name does not exist.\n${Yp()}`)},Yp=()=>`Available signal names: ${Xp()}.
358
- Available signal numbers: ${Zp()}.`,Xp=()=>Object.keys(pe.signals).sort().map(e=>`'${e}'`).join(`, `),Zp=()=>[...new Set(Object.values(pe.signals).sort((e,t)=>e-t))].join(`, `),Qp=e=>zp[e].description,$p=e=>{if(e===!1)return e;if(e===!0)return em;if(!Number.isFinite(e)||e<0)throw TypeError(`Expected the \`forceKillAfterDelay\` option to be a non-negative integer, got \`${e}\` (${typeof e})`);return e},em=1e3*5,tm=({kill:e,options:{forceKillAfterDelay:t,killSignal:n},onInternalError:r,context:i,controller:a},o,s)=>{let{signal:c,error:l}=nm(o,s,n);rm(l,r);let u=e(c);return im({kill:e,signal:c,forceKillAfterDelay:t,killSignal:n,killResult:u,context:i,controller:a}),u},nm=(e,t,n)=>{let[r=n,i]=Op(e)?[void 0,e]:[e,t];if(typeof r!=`string`&&!Number.isInteger(r))throw TypeError(`The first argument must be an error instance or a signal name string/integer: ${String(r)}`);if(i!==void 0&&!Op(i))throw TypeError(`The second argument is optional. If specified, it must be an error instance: ${i}`);return{signal:Wp(r),error:i}},rm=(e,t)=>{e!==void 0&&t.reject(e)},im=async({kill:e,signal:t,forceKillAfterDelay:n,killSignal:r,killResult:i,context:a,controller:o})=>{t===r&&i&&am({kill:e,forceKillAfterDelay:n,context:a,controllerSignal:o.signal})},am=async({kill:e,forceKillAfterDelay:t,context:n,controllerSignal:r})=>{if(t!==!1)try{await _e(t,void 0,{signal:r}),e(`SIGKILL`)&&(n.isForcefullyTerminated??=!0)}catch{}},om=async(e,t)=>{e.aborted||await x(e,`abort`,{signal:t})},sm=({cancelSignal:e})=>{if(e!==void 0&&Object.prototype.toString.call(e)!==`[object AbortSignal]`)throw Error(`The \`cancelSignal\` option must be an AbortSignal: ${String(e)}`)},cm=({subprocess:e,cancelSignal:t,gracefulCancel:n,context:r,controller:i})=>t===void 0||n?[]:[lm(e,t,r,i)],lm=async(e,t,n,{signal:r})=>{throw await om(t,r),n.terminationReason??=`cancel`,e.kill(),t.reason},um=({methodName:e,isSubprocess:t,ipc:n,isConnected:r})=>{dm(e,t,n),fm(e,t,r)},dm=(e,t,n)=>{if(!n)throw Error(`${Y(e,t)} can only be used if the \`ipc\` option is \`true\`.`)},fm=(e,t,n)=>{if(!n)throw Error(`${Y(e,t)} cannot be used: the ${Em(t)} has already exited or disconnected.`)},pm=e=>{throw Error(`${Y(`getOneMessage`,e)} could not complete: the ${Em(e)} exited or disconnected.`)},mm=e=>{throw Error(`${Y(`sendMessage`,e)} failed: the ${Em(e)} is sending a message too, instead of listening to incoming messages.
359
- This can be fixed by both sending a message and listening to incoming messages at the same time:
360
-
361
- const [receivedMessage] = await Promise.all([
362
- ${Y(`getOneMessage`,e)},
363
- ${Y(`sendMessage`,e,`message, {strict: true}`)},
364
- ]);`)},hm=(e,t)=>Error(`${Y(`sendMessage`,t)} failed when sending an acknowledgment response to the ${Em(t)}.`,{cause:e}),gm=e=>{throw Error(`${Y(`sendMessage`,e)} failed: the ${Em(e)} is not listening to incoming messages.`)},_m=e=>{throw Error(`${Y(`sendMessage`,e)} failed: the ${Em(e)} exited without listening to incoming messages.`)},vm=()=>Error(`\`cancelSignal\` aborted: the ${Em(!0)} disconnected.`),ym=()=>{throw Error("`getCancelSignal()` cannot be used without setting the `cancelSignal` subprocess option.")},bm=({error:e,methodName:t,isSubprocess:n})=>{if(e.code===`EPIPE`)throw Error(`${Y(t,n)} cannot be used: the ${Em(n)} is disconnecting.`,{cause:e})},xm=({error:e,methodName:t,isSubprocess:n,message:r})=>{if(Sm(e))throw Error(`${Y(t,n)}'s argument type is invalid: the message cannot be serialized: ${String(r)}.`,{cause:e})},Sm=({code:e,message:t})=>Cm.has(e)||wm.some(e=>t.includes(e)),Cm=new Set([`ERR_MISSING_ARGS`,`ERR_INVALID_ARG_TYPE`]),wm=[`could not be cloned`,`circular structure`,`call stack size exceeded`],Y=(e,t,n=``)=>e===`cancelSignal`?"`cancelSignal`'s `controller.abort()`":`${Tm(t)}${e}(${n})`,Tm=e=>e?``:`subprocess.`,Em=e=>e?`parent process`:`subprocess`,Dm=e=>{e.connected&&e.disconnect()},Om=()=>{let e={},t=new Promise((t,n)=>{Object.assign(e,{resolve:t,reject:n})});return Object.assign(t,e)},km=(e,t=`stdin`)=>{let{options:n,fileDescriptors:r}=jm.get(e),i=Mm(r,t,!0),a=e.stdio[i];if(a===null)throw TypeError(Fm(i,t,n,!0));return a},Am=(e,t=`stdout`)=>{let{options:n,fileDescriptors:r}=jm.get(e),i=Mm(r,t,!1),a=i===`all`?e.all:e.stdio[i];if(a==null)throw TypeError(Fm(i,t,n,!1));return a},jm=new WeakMap,Mm=(e,t,n)=>{let r=Nm(t,n);return Pm(r,t,n,e),r},Nm=(e,t)=>{let n=Qd(e);if(n!==void 0)return n;let{validOptions:r,defaultValue:i}=t?{validOptions:`"stdin"`,defaultValue:`stdin`}:{validOptions:`"stdout", "stderr", "all"`,defaultValue:`stdout`};throw TypeError(`"${Rm(t)}" must not be "${e}".
365
- It must be ${r} or "fd3", "fd4" (and so on).
366
- It is optional and defaults to "${i}".`)},Pm=(e,t,n,r)=>{let i=r[Lm(e)];if(i===void 0)throw TypeError(`"${Rm(n)}" must not be ${t}. That file descriptor does not exist.
367
- Please set the "stdio" option to ensure that file descriptor exists.`);if(i.direction===`input`&&!n)throw TypeError(`"${Rm(n)}" must not be ${t}. It must be a readable stream, not writable.`);if(i.direction!==`input`&&n)throw TypeError(`"${Rm(n)}" must not be ${t}. It must be a writable stream, not readable.`)},Fm=(e,t,n,r)=>{if(e===`all`&&!n.all)return`The "all" option must be true to use "from: 'all'".`;let{optionName:i,optionValue:a}=Im(e,n);return`The "${i}: ${zm(a)}" option is incompatible with using "${Rm(r)}: ${zm(t)}".
368
- Please set this option with "pipe" instead.`},Im=(e,{stdin:t,stdout:n,stderr:r,stdio:i})=>{let a=Lm(e);return a===0&&t!==void 0?{optionName:`stdin`,optionValue:t}:a===1&&n!==void 0?{optionName:`stdout`,optionValue:n}:a===2&&r!==void 0?{optionName:`stderr`,optionValue:r}:{optionName:`stdio[${a}]`,optionValue:i[a]}},Lm=e=>e===`all`?1:e,Rm=e=>e?`to`:`from`,zm=e=>typeof e==`string`?`'${e}'`:typeof e==`number`?`${e}`:`Stream`,Bm=(e,t,n)=>{let r=e.getMaxListeners();r===0||r===1/0||(e.setMaxListeners(r+t),Le(n,()=>{e.setMaxListeners(e.getMaxListeners()-t)}))},Vm=(e,t)=>{t&&Hm(e)},Hm=e=>{e.refCounted()},Um=(e,t)=>{t&&Wm(e)},Wm=e=>{e.unrefCounted()},Gm=(e,t)=>{t&&(Wm(e),Wm(e))},Km=(e,t)=>{t&&(Hm(e),Hm(e))},qm=async({anyProcess:e,channel:t,isSubprocess:n,ipcEmitter:r},i)=>{if(ih(i)||Th(i))return;Ym.has(e)||Ym.set(e,[]);let a=Ym.get(e);if(a.push(i),!(a.length>1))for(;a.length>0;){await fh(e,r,i),await he.yield();let o=await rh({wrappedMessage:a[0],anyProcess:e,channel:t,isSubprocess:n,ipcEmitter:r});a.shift(),r.emit(`message`,o),r.emit(`message:done`)}},Jm=async({anyProcess:e,channel:t,isSubprocess:n,ipcEmitter:r,boundOnMessage:i})=>{Dh();let a=Ym.get(e);for(;a?.length>0;)await x(r,`message:done`);e.removeListener(`message`,i),Km(t,n),r.connected=!1,r.emit(`disconnect`)},Ym=new WeakMap,Xm=(e,t,n)=>{if(Zm.has(e))return Zm.get(e);let r=new Ie;return r.connected=!0,Zm.set(e,r),Qm({ipcEmitter:r,anyProcess:e,channel:t,isSubprocess:n}),r},Zm=new WeakMap,Qm=({ipcEmitter:e,anyProcess:t,channel:n,isSubprocess:r})=>{let i=qm.bind(void 0,{anyProcess:t,channel:n,isSubprocess:r,ipcEmitter:e});t.on(`message`,i),t.once(`disconnect`,Jm.bind(void 0,{anyProcess:t,channel:n,isSubprocess:r,ipcEmitter:e,boundOnMessage:i})),Gm(n,r)},$m=e=>{let t=Zm.get(e);return t===void 0?e.channel!==null:t.connected},eh=({anyProcess:e,channel:t,isSubprocess:n,message:r,strict:i})=>{if(!i)return r;let a=mh(e,Xm(e,t,n));return{id:th++,type:ch,message:r,hasListeners:a}};let th=0n;const nh=(e,t)=>{if(!(t?.type!==ch||t.hasListeners))for(let{id:t}of e)t!==void 0&&oh[t].resolve({isDeadlock:!0,hasListeners:!1})},rh=async({wrappedMessage:e,anyProcess:t,channel:n,isSubprocess:r,ipcEmitter:i})=>{if(e?.type!==ch||!t.connected)return e;let{id:a,message:o}=e,s={id:a,type:lh,message:mh(t,i)};try{await gh({anyProcess:t,channel:n,isSubprocess:r,ipc:!0},s)}catch(e){i.emit(`strict:error`,e)}return o},ih=e=>{if(e?.type!==lh)return!1;let{id:t,message:n}=e;return oh[t]?.resolve({isDeadlock:!1,hasListeners:n}),!0},ah=async(e,t,n)=>{if(e?.type!==ch)return;let r=Om();oh[e.id]=r;let i=new AbortController;try{let{isDeadlock:e,hasListeners:a}=await Promise.race([r,sh(t,n,i)]);e&&mm(n),a||gm(n)}finally{i.abort(),delete oh[e.id]}},oh={},sh=async(e,t,{signal:n})=>{Bm(e,1,n),await x(e,`disconnect`,{signal:n}),_m(t)},ch=`execa:ipc:request`,lh=`execa:ipc:response`,uh=(e,t,n)=>{ph.has(e)||ph.set(e,new Set);let r=ph.get(e),i={onMessageSent:Om(),id:n?t.id:void 0};return r.add(i),{outgoingMessages:r,outgoingMessage:i}},dh=({outgoingMessages:e,outgoingMessage:t})=>{e.delete(t),t.onMessageSent.resolve()},fh=async(e,t,n)=>{for(;!mh(e,t)&&ph.get(e)?.size>0;){let t=[...ph.get(e)];nh(t,n),await Promise.all(t.map(({onMessageSent:e})=>e))}},ph=new WeakMap,mh=(e,t)=>t.listenerCount(`message`)>hh(e),hh=e=>jm.has(e)&&!rf(jm.get(e).options.buffer,`ipc`)?1:0,gh=({anyProcess:e,channel:t,isSubprocess:n,ipc:r},i,{strict:a=!1}={})=>{let o=`sendMessage`;return um({methodName:o,isSubprocess:n,ipc:r,isConnected:e.connected}),_h({anyProcess:e,channel:t,methodName:o,isSubprocess:n,message:i,strict:a})},_h=async({anyProcess:e,channel:t,methodName:n,isSubprocess:r,message:i,strict:a})=>{let o=eh({anyProcess:e,channel:t,isSubprocess:r,message:i,strict:a}),s=uh(e,o,a);try{await vh({anyProcess:e,methodName:n,isSubprocess:r,wrappedMessage:o,message:i})}catch(t){throw Dm(e),t}finally{dh(s)}},vh=async({anyProcess:e,methodName:t,isSubprocess:n,wrappedMessage:r,message:i})=>{let a=yh(e);try{await Promise.all([ah(r,e,n),a(r)])}catch(e){throw bm({error:e,methodName:t,isSubprocess:n}),xm({error:e,methodName:t,isSubprocess:n,message:i}),e}},yh=e=>{if(bh.has(e))return bh.get(e);let t=ke(e.send.bind(e));return bh.set(e,t),t},bh=new WeakMap,xh=(e,t)=>{let n=`cancelSignal`;return fm(n,!1,e.connected),vh({anyProcess:e,methodName:n,isSubprocess:!1,wrappedMessage:{type:Eh,message:t},message:t})},Sh=async({anyProcess:e,channel:t,isSubprocess:n,ipc:r})=>(await Ch({anyProcess:e,channel:t,isSubprocess:n,ipc:r}),Oh.signal),Ch=async({anyProcess:e,channel:t,isSubprocess:n,ipc:r})=>{if(!wh){if(wh=!0,!r){ym();return}if(t===null){Dh();return}Xm(e,t,n),await he.yield()}};let wh=!1;const Th=e=>e?.type===Eh?(Oh.abort(e.message),!0):!1,Eh=`execa:ipc:cancel`,Dh=()=>{Oh.abort(vm())},Oh=new AbortController,kh=({gracefulCancel:e,cancelSignal:t,ipc:n,serialization:r})=>{if(e){if(t===void 0)throw Error("The `cancelSignal` option must be defined when setting the `gracefulCancel` option.");if(!n)throw Error("The `ipc` option cannot be false when setting the `gracefulCancel` option.");if(r===`json`)throw Error("The `serialization` option cannot be 'json' when setting the `gracefulCancel` option.")}},Ah=({subprocess:e,cancelSignal:t,gracefulCancel:n,forceKillAfterDelay:r,context:i,controller:a})=>n?[jh({subprocess:e,cancelSignal:t,forceKillAfterDelay:r,context:i,controller:a})]:[],jh=async({subprocess:e,cancelSignal:t,forceKillAfterDelay:n,context:r,controller:{signal:i}})=>{throw await om(t,i),await xh(e,Mh(t)),am({kill:e.kill,forceKillAfterDelay:n,context:r,controllerSignal:i}),r.terminationReason??=`gracefulCancel`,t.reason},Mh=({reason:e})=>{if(!(e instanceof DOMException))return e;let t=Error(e.message);return Object.defineProperty(t,"stack",{value:e.stack,enumerable:!1,configurable:!0,writable:!0}),t},Nh=({timeout:e})=>{if(e!==void 0&&(!Number.isFinite(e)||e<0))throw TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${e}\` (${typeof e})`)},Ph=(e,t,n,r)=>t===0||t===void 0?[]:[Fh(e,t,n,r)],Fh=async(e,t,n,{signal:r})=>{throw await _e(t,void 0,{signal:r}),n.terminationReason??=`timeout`,e.kill(),new wp},Ih=({options:e})=>{if(e.node===!1)throw TypeError('The "node" option cannot be false with `execaNode()`.');return{options:{...e,node:!0}}},Lh=(e,t,{node:n=!1,nodePath:r=Me,nodeOptions:i=je.filter(e=>!e.startsWith(`--inspect`)),cwd:a,execPath:o,...s})=>{if(o!==void 0)throw TypeError(`The "execPath" option has been removed. Please use the "nodePath" option instead.`);let c=pd(r,`The "nodePath" option`),l=h.resolve(a,c),u={...s,nodePath:l,node:n,cwd:a};if(!n)return[e,t,u];if(h.basename(e,`.exe`)===`node`)throw TypeError(`When the "node" option is true, the first argument does not need to be "node".`);return[l,[...i,e,...t],{ipc:!0,...u,shell:!1}]},Rh=({ipcInput:e,ipc:t,serialization:n})=>{if(e!==void 0){if(!t)throw Error("The `ipcInput` option cannot be set unless the `ipc` option is `true`.");zh[n](e)}},zh={advanced:e=>{try{Be(e)}catch(e){throw Error("The `ipcInput` option is not serializable with a structured clone.",{cause:e})}},json:e=>{try{JSON.stringify(e)}catch(e){throw Error("The `ipcInput` option is not serializable with JSON.",{cause:e})}}},Bh=async(e,t)=>{t!==void 0&&await e.sendMessage(t)},Vh=({encoding:e})=>{if(Wh.has(e))return;let t=Gh(e);if(t!==void 0)throw TypeError(`Invalid option \`encoding: ${qh(e)}\`.
369
- Please rename it to ${qh(t)}.`);let n=[...Wh].map(e=>qh(e)).join(`, `);throw TypeError(`Invalid option \`encoding: ${qh(e)}\`.
370
- Please rename it to one of: ${n}.`)},Hh=new Set([`utf8`,`utf16le`]),Uh=new Set([`buffer`,`hex`,`base64`,`base64url`,`latin1`,`ascii`]),Wh=new Set([...Hh,...Uh]),Gh=e=>{if(e===null)return`buffer`;if(typeof e!=`string`)return;let t=e.toLowerCase();if(t in Kh)return Kh[t];if(Wh.has(t))return t},Kh={"utf-8":`utf8`,"utf-16le":`utf16le`,"ucs-2":`utf16le`,ucs2:`utf16le`,binary:`latin1`},qh=e=>typeof e==`string`?`"${e}"`:String(e),Jh=(e=Yh())=>{let t=pd(e,`The "cwd" option`);return h.resolve(t)},Yh=()=>{try{return b.cwd()}catch(e){throw e.message=`The current directory does not exist.\n${e.message}`,e}},Xh=(e,t)=>{if(t===Yh())return e;let n;try{n=de(t)}catch(n){return`The "cwd" option is invalid: ${t}.\n${n.message}\n${e}`}return n.isDirectory()?e:`The "cwd" option is not a directory: ${t}.\n${e}`},Zh=(e,t,n)=>{n.cwd=Jh(n.cwd);let[r,i,a]=Lh(e,t,n),{command:o,args:s,options:c}=hp.default._parse(r,i,a),l=Wd(c),u=Qh(l);return Nh(u),Vh(u),Rh(u),sm(u),kh(u),u.shell=gd(u.shell),u.env=$h(u),u.killSignal=Up(u.killSignal),u.forceKillAfterDelay=$p(u.forceKillAfterDelay),u.lines=u.lines.map((e,t)=>e&&!Uh.has(u.encoding)&&u.buffer[t]),b.platform===`win32`&&h.basename(o,`.exe`)===`cmd`&&s.unshift(`/q`),{file:o,commandArguments:s,options:u}},Qh=({extendEnv:e=!0,preferLocal:t=!1,cwd:n,localDir:r=n,encoding:i=`utf8`,reject:a=!0,cleanup:o=!0,all:s=!1,windowsHide:c=!0,killSignal:l=`SIGTERM`,forceKillAfterDelay:u=!0,gracefulCancel:d=!1,ipcInput:f,ipc:p=f!==void 0||d,serialization:m=`advanced`,...h})=>({...h,extendEnv:e,preferLocal:t,cwd:n,localDirectory:r,encoding:i,reject:a,cleanup:o,all:s,windowsHide:c,killSignal:l,forceKillAfterDelay:u,gracefulCancel:d,ipcInput:f,ipc:p,serialization:m}),$h=({env:e,extendEnv:t,preferLocal:n,node:r,localDirectory:i,nodePath:a})=>{let o=t?{...b.env,...e}:e;return n||r?Sp({env:o,cwd:i,execPath:a,preferLocal:n,addExecPath:r}):o},eg=(e,t,n)=>n.shell&&t.length>0?[[e,...t].join(` `),[],n]:[e,t,n];function tg(e){if(typeof e==`string`)return ng(e);if(!(ArrayBuffer.isView(e)&&e.BYTES_PER_ELEMENT===1))throw Error(`Input must be a string or a Uint8Array`);return rg(e)}const ng=e=>e.at(-1)===ig?e.slice(0,e.at(-2)===og?-2:-1):e,rg=e=>e.at(-1)===ag?e.subarray(0,e.at(-2)===sg?-2:-1):e,ig=`
371
- `,ag=`
372
- `.codePointAt(0),og=`\r`,sg=`\r`.codePointAt(0);function cg(e,{checkOpen:t=!0}={}){return typeof e==`object`&&!!e&&(e.writable||e.readable||!t||e.writable===void 0&&e.readable===void 0)&&typeof e.pipe==`function`}function lg(e,{checkOpen:t=!0}={}){return cg(e,{checkOpen:t})&&(e.writable||!t)&&typeof e.write==`function`&&typeof e.end==`function`&&typeof e.writable==`boolean`&&typeof e.writableObjectMode==`boolean`&&typeof e.destroy==`function`&&typeof e.destroyed==`boolean`}function ug(e,{checkOpen:t=!0}={}){return cg(e,{checkOpen:t})&&(e.readable||!t)&&typeof e.read==`function`&&typeof e.readable==`boolean`&&typeof e.readableObjectMode==`boolean`&&typeof e.destroy==`function`&&typeof e.destroyed==`boolean`}function dg(e,t){return lg(e,t)&&ug(e,t)}const fg=Object.getPrototypeOf(Object.getPrototypeOf(async function*(){}).prototype);var pg=class{#e;#t;#n=!1;#r=void 0;constructor(e,t){this.#e=e,this.#t=t}next(){let e=()=>this.#i();return this.#r=this.#r?this.#r.then(e,e):e(),this.#r}return(e){let t=()=>this.#a(e);return this.#r?this.#r.then(t,t):t()}async#i(){if(this.#n)return{done:!0,value:void 0};let e;try{e=await this.#e.read()}catch(e){throw this.#r=void 0,this.#n=!0,this.#e.releaseLock(),e}return e.done&&(this.#r=void 0,this.#n=!0,this.#e.releaseLock()),e}async#a(e){if(this.#n)return{done:!0,value:e};if(this.#n=!0,!this.#t){let t=this.#e.cancel(e);return this.#e.releaseLock(),await t,{done:!0,value:e}}return this.#e.releaseLock(),{done:!0,value:e}}};const mg=Symbol();function hg(){return this[mg].next()}Object.defineProperty(hg,"name",{value:`next`});function gg(e){return this[mg].return(e)}Object.defineProperty(gg,"name",{value:`return`});const _g=Object.create(fg,{next:{enumerable:!0,configurable:!0,writable:!0,value:hg},return:{enumerable:!0,configurable:!0,writable:!0,value:gg}});function vg({preventCancel:e=!1}={}){let t=new pg(this.getReader(),e),n=Object.create(_g);return n[mg]=t,n}const yg=e=>{if(ug(e,{checkOpen:!1})&&Cg.on!==void 0)return xg(e);if(typeof e?.[Symbol.asyncIterator]==`function`)return e;if(bg.call(e)===`[object ReadableStream]`)return vg.call(e);throw TypeError(`The first argument must be a Readable, a ReadableStream, or an async iterable.`)},{toString:bg}=Object.prototype,xg=async function*(e){let t=new AbortController,n={};Sg(e,t,n);try{for await(let[n]of Cg.on(e,`data`,{signal:t.signal}))yield n}catch(e){if(n.error!==void 0)throw n.error;if(!t.signal.aborted)throw e}finally{e.destroy()}},Sg=async(e,t,n)=>{try{await Cg.finished(e,{cleanup:!0,readable:!0,writable:!1,error:!1})}catch(e){n.error=e}finally{t.abort()}},Cg={},wg=async(e,{init:t,convertChunk:n,getSize:r,truncateChunk:i,addChunk:a,getFinalChunk:o,finalize:s},{maxBuffer:c=1/0}={})=>{let l=yg(e),u=t();u.length=0;try{for await(let e of l){let t=n[Og(e)](e,u);Eg({convertedChunk:t,state:u,getSize:r,truncateChunk:i,addChunk:a,maxBuffer:c})}return Tg({state:u,convertChunk:n,getSize:r,truncateChunk:i,addChunk:a,getFinalChunk:o,maxBuffer:c}),s(u)}catch(e){let t=typeof e==`object`&&e?e:Error(e);throw t.bufferedData=s(u),t}},Tg=({state:e,getSize:t,truncateChunk:n,addChunk:r,getFinalChunk:i,maxBuffer:a})=>{let o=i(e);o!==void 0&&Eg({convertedChunk:o,state:e,getSize:t,truncateChunk:n,addChunk:r,maxBuffer:a})},Eg=({convertedChunk:e,state:t,getSize:n,truncateChunk:r,addChunk:i,maxBuffer:a})=>{let o=n(e),s=t.length+o;if(s<=a){Dg(e,t,i,s);return}let c=r(e,a-t.length);throw c!==void 0&&Dg(c,t,i,a),new Ag},Dg=(e,t,n,r)=>{t.contents=n(e,t,r),t.length=r},Og=e=>{let t=typeof e;if(t===`string`)return`string`;if(t!==`object`||e===null)return`others`;if(globalThis.Buffer?.isBuffer(e))return`buffer`;let n=kg.call(e);return n===`[object ArrayBuffer]`?`arrayBuffer`:n===`[object DataView]`?`dataView`:Number.isInteger(e.byteLength)&&Number.isInteger(e.byteOffset)&&kg.call(e.buffer)===`[object ArrayBuffer]`?`typedArray`:`others`},{toString:kg}=Object.prototype;var Ag=class extends Error{name=`MaxBufferError`;constructor(){super(`maxBuffer exceeded`)}};const jg=e=>e,Mg=()=>void 0,Ng=({contents:e})=>e,Pg=e=>{throw Error(`Streams in object mode are not supported: ${String(e)}`)},Fg=e=>e.length;async function Ig(e,t){return wg(e,Lg,t)}const Lg={init:()=>({contents:[]}),convertChunk:{string:jg,buffer:jg,arrayBuffer:jg,dataView:jg,typedArray:jg,others:jg},getSize:()=>1,truncateChunk:Mg,addChunk:(e,{contents:t})=>(t.push(e),t),getFinalChunk:Mg,finalize:Ng};async function Rg(e,t){return wg(e,Qg,t)}const zg=()=>({contents:new ArrayBuffer(0)}),Bg=e=>Vg.encode(e),Vg=new TextEncoder,Hg=e=>new Uint8Array(e),Ug=e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),Wg=(e,t)=>e.slice(0,t),Gg=(e,{contents:t,length:n},r)=>{let i=Zg()?qg(t,r):Kg(t,r);return new Uint8Array(i).set(e,n),i},Kg=(e,t)=>{if(t<=e.byteLength)return e;let n=new ArrayBuffer(Jg(t));return new Uint8Array(n).set(new Uint8Array(e),0),n},qg=(e,t)=>{if(t<=e.maxByteLength)return e.resize(t),e;let n=new ArrayBuffer(t,{maxByteLength:Jg(t)});return new Uint8Array(n).set(new Uint8Array(e),0),n},Jg=e=>Yg**Math.ceil(Math.log(e)/Math.log(Yg)),Yg=2,Xg=({contents:e,length:t})=>Zg()?e:e.slice(0,t),Zg=()=>`resize`in ArrayBuffer.prototype,Qg={init:zg,convertChunk:{string:Bg,buffer:Hg,arrayBuffer:Hg,dataView:Ug,typedArray:Ug,others:Pg},getSize:Fg,truncateChunk:Wg,addChunk:Gg,getFinalChunk:Mg,finalize:Xg};async function $g(e,t){return wg(e,n_,t)}const e_=()=>({contents:``,textDecoder:new TextDecoder}),t_=(e,{textDecoder:t})=>t.decode(e,{stream:!0}),n_={init:e_,convertChunk:{string:jg,buffer:t_,arrayBuffer:t_,dataView:t_,typedArray:t_,others:Pg},getSize:Fg,truncateChunk:(e,t)=>e.slice(0,t),addChunk:(e,{contents:t})=>t+e,getFinalChunk:({textDecoder:e})=>{let t=e.decode();return t===``?void 0:t},finalize:Ng},r_=({error:e,stream:t,readableObjectMode:n,lines:r,encoding:i,fdNumber:a})=>{if(!(e instanceof Ag))throw e;if(a===`all`)return e;throw e.maxBufferInfo={fdNumber:a,unit:i_(n,r,i)},t.destroy(),e},i_=(e,t,n)=>e?`objects`:t?`lines`:n===`buffer`?`bytes`:`characters`,a_=(e,t,n)=>{if(t.length!==n)return;let r=new Ag;throw r.maxBufferInfo={fdNumber:`ipc`},r},o_=(e,t)=>{let{streamName:n,threshold:r,unit:i}=s_(e,t);return`Command's ${n} was larger than ${r} ${i}`},s_=(e,t)=>{if(e?.maxBufferInfo===void 0)return{streamName:`output`,threshold:t[1],unit:`bytes`};let{maxBufferInfo:{fdNumber:n,unit:r}}=e;delete e.maxBufferInfo;let i=rf(t,n);return n===`ipc`?{streamName:`IPC output`,threshold:i,unit:`messages`}:{streamName:Ud(n),threshold:i,unit:r}},c_=(e,t,n)=>e?.code===`ENOBUFS`&&t!==null&&t.some(e=>e!==null&&e.length>u_(n)),l_=(e,t,n)=>{if(!t)return e;let r=u_(n);return e.length>r?e.slice(0,r):e},u_=([,e])=>e,d_=({stdio:e,all:t,ipcOutput:n,originalError:r,signal:i,signalDescription:a,exitCode:o,escapedCommand:s,timedOut:c,isCanceled:l,isGracefullyCanceled:u,isMaxBuffer:d,isForcefullyTerminated:f,forceKillAfterDelay:p,killSignal:m,maxBuffer:h,timeout:g,cwd:_})=>{let v=r?.code,y=f_({originalError:r,timedOut:c,timeout:g,isMaxBuffer:d,maxBuffer:h,errorCode:v,signal:i,signalDescription:a,exitCode:o,isCanceled:l,isGracefullyCanceled:u,isForcefullyTerminated:f,forceKillAfterDelay:p,killSignal:m}),ee=m_(r,_),te=`${y}: ${s}${ee===void 0?``:`\n${ee}`}`;return{originalMessage:ee,shortMessage:te,message:[te,...t===void 0?[e[2],e[1]]:[t],...e.slice(3),n.map(e=>h_(e)).join(`
373
- `)].map(e=>pf(tg(g_(e)))).filter(Boolean).join(`
374
-
375
- `)}},f_=({originalError:e,timedOut:t,timeout:n,isMaxBuffer:r,maxBuffer:i,errorCode:a,signal:o,signalDescription:s,exitCode:c,isCanceled:l,isGracefullyCanceled:u,isForcefullyTerminated:d,forceKillAfterDelay:f,killSignal:p})=>{let m=p_(d,f);return t?`Command timed out after ${n} milliseconds${m}`:u?o===void 0?`Command was gracefully canceled with exit code ${c}`:d?`Command was gracefully canceled${m}`:`Command was gracefully canceled with ${o} (${s})`:l?`Command was canceled${m}`:r?`${o_(e,i)}${m}`:a===void 0?d?`Command was killed with ${p} (${Qp(p)})${m}`:o===void 0?c===void 0?`Command failed`:`Command failed with exit code ${c}`:`Command was killed with ${o} (${s})`:`Command failed with ${a}${m}`},p_=(e,t)=>e?` and was forcefully terminated after ${t} milliseconds`:``,m_=(e,t)=>{if(e instanceof wp)return;let n=pf(Xh(Ep(e)?e.originalMessage:String(e?.message??e),t));return n===``?void 0:n},h_=e=>typeof e==`string`?e:Oe(e),g_=e=>Array.isArray(e)?e.map(e=>tg(__(e))).filter(Boolean).join(`
376
- `):__(e),__=e=>typeof e==`string`?e:q(e)?wd(e):``,v_=({command:e,escapedCommand:t,stdio:n,all:r,ipcOutput:i,options:{cwd:a},startTime:o})=>S_({command:e,escapedCommand:t,cwd:a,durationMs:tp(o),failed:!1,timedOut:!1,isCanceled:!1,isGracefullyCanceled:!1,isTerminated:!1,isMaxBuffer:!1,isForcefullyTerminated:!1,exitCode:0,stdout:n[1],stderr:n[2],all:r,stdio:n,ipcOutput:i,pipedFrom:[]}),y_=({error:e,command:t,escapedCommand:n,fileDescriptors:r,options:i,startTime:a,isSync:o})=>b_({error:e,command:t,escapedCommand:n,startTime:a,timedOut:!1,isCanceled:!1,isGracefullyCanceled:!1,isMaxBuffer:!1,isForcefullyTerminated:!1,stdio:Array.from({length:r.length}),ipcOutput:[],options:i,isSync:o}),b_=({error:e,command:t,escapedCommand:n,startTime:r,timedOut:i,isCanceled:a,isGracefullyCanceled:o,isMaxBuffer:s,isForcefullyTerminated:c,exitCode:l,signal:u,stdio:d,all:f,ipcOutput:p,options:{timeoutDuration:m,timeout:h=m,forceKillAfterDelay:g,killSignal:_,cwd:v,maxBuffer:y},isSync:ee})=>{let{exitCode:te,signal:ne,signalDescription:re}=C_(l,u),{originalMessage:ie,shortMessage:ae,message:oe}=d_({stdio:d,all:f,ipcOutput:p,originalError:e,signal:ne,signalDescription:re,exitCode:te,escapedCommand:n,timedOut:i,isCanceled:a,isGracefullyCanceled:o,isMaxBuffer:s,isForcefullyTerminated:c,forceKillAfterDelay:g,killSignal:_,maxBuffer:y,timeout:h,cwd:v}),se=Cp(e,oe,ee);return Object.assign(se,x_({error:se,command:t,escapedCommand:n,startTime:r,timedOut:i,isCanceled:a,isGracefullyCanceled:o,isMaxBuffer:s,isForcefullyTerminated:c,exitCode:te,signal:ne,signalDescription:re,stdio:d,all:f,ipcOutput:p,cwd:v,originalMessage:ie,shortMessage:ae})),se},x_=({error:e,command:t,escapedCommand:n,startTime:r,timedOut:i,isCanceled:a,isGracefullyCanceled:o,isMaxBuffer:s,isForcefullyTerminated:c,exitCode:l,signal:u,signalDescription:d,stdio:f,all:p,ipcOutput:m,cwd:h,originalMessage:g,shortMessage:_})=>S_({shortMessage:_,originalMessage:g,command:t,escapedCommand:n,cwd:h,durationMs:tp(r),failed:!0,timedOut:i,isCanceled:a,isGracefullyCanceled:o,isTerminated:u!==void 0,isMaxBuffer:s,isForcefullyTerminated:c,exitCode:l,signal:u,signalDescription:d,code:e.cause?.code,stdout:f[1],stderr:f[2],all:p,stdio:f,ipcOutput:m,pipedFrom:[]}),S_=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0)),C_=(e,t)=>{let n=e===null?void 0:e,r=t===null?void 0:t;return{exitCode:n,signal:r,signalDescription:r===void 0?void 0:Qp(t)}},w_=e=>Number.isFinite(e)?e:0;function T_(e){return{days:Math.trunc(e/864e5),hours:Math.trunc(e/36e5%24),minutes:Math.trunc(e/6e4%60),seconds:Math.trunc(e/1e3%60),milliseconds:Math.trunc(e%1e3),microseconds:Math.trunc(w_(e*1e3)%1e3),nanoseconds:Math.trunc(w_(e*1e6)%1e3)}}function E_(e){return{days:e/86400000n,hours:e/3600000n%24n,minutes:e/60000n%60n,seconds:e/1000n%60n,milliseconds:e%1000n,microseconds:0n,nanoseconds:0n}}function D_(e){switch(typeof e){case`number`:if(Number.isFinite(e))return T_(e);break;case`bigint`:return E_(e)}throw TypeError(`Expected a finite number or bigint`)}const O_=e=>e===0||e===0n,k_=(e,t)=>t===1||t===1n?e:`${e}s`,A_=24n*60n*60n*1000n;function j_(e,t){let n=typeof e==`bigint`;if(!n&&!Number.isFinite(e))throw TypeError(`Expected a finite number or bigint`);t={...t};let r=e<0?`-`:``;e=e<0?-e:e,t.colonNotation&&(t.compact=!1,t.formatSubMilliseconds=!1,t.separateMilliseconds=!1,t.verbose=!1),t.compact&&(t.unitCount=1,t.secondsDecimalDigits=0,t.millisecondsDecimalDigits=0);let i=[],a=(e,t)=>{let n=Math.floor(e*10**t+1e-7);return(Math.round(n)/10**t).toFixed(t)},o=(e,n,r,a)=>{if(!((i.length===0||!t.colonNotation)&&O_(e)&&!(t.colonNotation&&r===`m`))){if(a??=String(e),t.colonNotation){let e=a.includes(`.`)?a.split(`.`)[0].length:a.length,t=i.length>0?2:1;a=`0`.repeat(Math.max(0,t-e))+a}else a+=t.verbose?` `+k_(n,e):r;i.push(a)}},s=D_(e),c=BigInt(s.days);if(t.hideYearAndDays?o(BigInt(c)*24n+BigInt(s.hours),`hour`,`h`):(t.hideYear?o(c,`day`,`d`):(o(c/365n,`year`,`y`),o(c%365n,`day`,`d`)),o(Number(s.hours),`hour`,`h`)),o(Number(s.minutes),`minute`,`m`),!t.hideSeconds)if(t.separateMilliseconds||t.formatSubMilliseconds||!t.colonNotation&&e<1e3&&!t.subSecondsAsDecimals){let e=Number(s.seconds),n=Number(s.milliseconds),r=Number(s.microseconds),i=Number(s.nanoseconds);if(o(e,`second`,`s`),t.formatSubMilliseconds)o(n,`millisecond`,`ms`),o(r,`microsecond`,`µs`),o(i,`nanosecond`,`ns`);else{let e=n+r/1e3+i/1e6,a=typeof t.millisecondsDecimalDigits==`number`?t.millisecondsDecimalDigits:0,s=a?e.toFixed(a):e>=1?Math.round(e):Math.ceil(e);o(Number.parseFloat(s),`millisecond`,`ms`,s)}}else{let r=a((n?Number(e%A_):e)/1e3%60,typeof t.secondsDecimalDigits==`number`?t.secondsDecimalDigits:1),i=t.keepDecimalsOnWholeSeconds?r:r.replace(/\.0+$/,``);o(Number.parseFloat(i),`second`,`s`,i)}if(i.length===0)return r+`0`+(t.verbose?` milliseconds`:`ms`);let l=t.colonNotation?`:`:` `;return typeof t.unitCount==`number`&&(i=i.slice(0,Math.max(t.unitCount,1))),r+i.join(l)}const M_=(e,t)=>{e.failed&&Uf({type:`error`,verboseMessage:e.shortMessage,verboseInfo:t,result:e})},N_=(e,t)=>{af(t)&&(M_(e,t),P_(e,t))},P_=(e,t)=>{Uf({type:`duration`,verboseMessage:`(done in ${j_(e.durationMs)})`,verboseInfo:t,result:e})},F_=(e,t,{reject:n})=>{if(N_(e,t),e.failed&&n)throw e;return e},I_=(e,t)=>G_(e)?`asyncGenerator`:K_(e)?`generator`:J_(e)?`fileUrl`:X_(e)?`filePath`:rv(e)?`webStream`:cg(e,{checkOpen:!1})?`native`:q(e)?`uint8Array`:av(e)?`asyncIterable`:ov(e)?`iterable`:iv(e)?z_({transform:e},t):q_(e)?L_(e,t):`native`,L_=(e,t)=>dg(e.transform,{checkOpen:!1})?R_(e,t):iv(e.transform)?z_(e,t):H_(e,t),R_=(e,t)=>(B_(e,t,`Duplex stream`),`duplex`),z_=(e,t)=>(B_(e,t,`web TransformStream`),`webTransform`),B_=({final:e,binary:t,objectMode:n},r,i)=>{V_(e,`${r}.final`,i),V_(t,`${r}.binary`,i),U_(n,`${r}.objectMode`)},V_=(e,t,n)=>{if(e!==void 0)throw TypeError(`The \`${t}\` option can only be defined when using a generator, not a ${n}.`)},H_=({transform:e,final:t,binary:n,objectMode:r},i)=>{if(e!==void 0&&!W_(e))throw TypeError(`The \`${i}.transform\` option must be a generator, a Duplex stream or a web TransformStream.`);if(dg(t,{checkOpen:!1}))throw TypeError(`The \`${i}.final\` option must not be a Duplex stream.`);if(iv(t))throw TypeError(`The \`${i}.final\` option must not be a web TransformStream.`);if(t!==void 0&&!W_(t))throw TypeError(`The \`${i}.final\` option must be a generator.`);return U_(n,`${i}.binary`),U_(r,`${i}.objectMode`),G_(e)||G_(t)?`asyncGenerator`:`generator`},U_=(e,t)=>{if(e!==void 0&&typeof e!=`boolean`)throw TypeError(`The \`${t}\` option must use a boolean.`)},W_=e=>G_(e)||K_(e),G_=e=>Object.prototype.toString.call(e)===`[object AsyncGeneratorFunction]`,K_=e=>Object.prototype.toString.call(e)===`[object GeneratorFunction]`,q_=e=>K(e)&&(e.transform!==void 0||e.final!==void 0),J_=e=>Object.prototype.toString.call(e)===`[object URL]`,Y_=e=>J_(e)&&e.protocol!==`file:`,X_=e=>K(e)&&Object.keys(e).length>0&&Object.keys(e).every(e=>Z_.has(e))&&Q_(e.file),Z_=new Set([`file`,`append`]),Q_=e=>typeof e==`string`,$_=(e,t)=>e===`native`&&typeof t==`string`&&!ev.has(t),ev=new Set([`ipc`,`ignore`,`inherit`,`overlapped`,`pipe`]),tv=e=>Object.prototype.toString.call(e)===`[object ReadableStream]`,nv=e=>Object.prototype.toString.call(e)===`[object WritableStream]`,rv=e=>tv(e)||nv(e),iv=e=>tv(e?.readable)&&nv(e?.writable),av=e=>sv(e)&&typeof e[Symbol.asyncIterator]==`function`,ov=e=>sv(e)&&typeof e[Symbol.iterator]==`function`,sv=e=>typeof e==`object`&&!!e,cv=new Set([`generator`,`asyncGenerator`,`duplex`,`webTransform`]),lv=new Set([`fileUrl`,`filePath`,`fileNumber`]),uv=new Set([`fileUrl`,`filePath`]),dv=new Set([...uv,`webStream`,`nodeStream`]),fv=new Set([`webTransform`,`duplex`]),pv={generator:`a generator`,asyncGenerator:`an async generator`,fileUrl:`a file URL`,filePath:`a file path string`,fileNumber:`a file descriptor number`,webStream:`a web stream`,nodeStream:`a Node.js stream`,webTransform:`a web TransformStream`,duplex:`a Duplex stream`,native:`any value`,iterable:`an iterable`,asyncIterable:`an async iterable`,string:`a string`,uint8Array:`a Uint8Array`},mv=(e,t,n,r)=>r===`output`?hv(e,t,n):gv(e,t,n),hv=(e,t,n)=>{let r=t!==0&&n[t-1].value.readableObjectMode;return{writableObjectMode:r,readableObjectMode:e??r}},gv=(e,t,n)=>{let r=t===0?e===!0:n[t-1].value.readableObjectMode;return{writableObjectMode:r,readableObjectMode:t!==n.length-1&&(e??r)}},_v=(e,t)=>{let n=e.findLast(({type:e})=>cv.has(e));return n===void 0?!1:t===`input`?n.value.writableObjectMode:n.value.readableObjectMode},vv=(e,t,n,r)=>[...e.filter(({type:e})=>!cv.has(e)),...yv(e,t,n,r)],yv=(e,t,n,{encoding:r})=>{let i=e.filter(({type:e})=>cv.has(e)),a=Array.from({length:i.length});for(let[e,o]of Object.entries(i))a[e]=bv({stdioItem:o,index:Number(e),newTransforms:a,optionName:t,direction:n,encoding:r});return wv(a,n)},bv=({stdioItem:e,stdioItem:{type:t},index:n,newTransforms:r,optionName:i,direction:a,encoding:o})=>t===`duplex`?xv({stdioItem:e,optionName:i}):t===`webTransform`?Sv({stdioItem:e,index:n,newTransforms:r,direction:a}):Cv({stdioItem:e,index:n,newTransforms:r,direction:a,encoding:o}),xv=({stdioItem:e,stdioItem:{value:{transform:t,transform:{writableObjectMode:n,readableObjectMode:r},objectMode:i=r}},optionName:a})=>{if(i&&!r)throw TypeError(`The \`${a}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);if(!i&&r)throw TypeError(`The \`${a}.objectMode\` option cannot be \`false\` if \`new Duplex({objectMode: true})\` is used.`);return{...e,value:{transform:t,writableObjectMode:n,readableObjectMode:r}}},Sv=({stdioItem:e,stdioItem:{value:t},index:n,newTransforms:r,direction:i})=>{let{transform:a,objectMode:o}=K(t)?t:{transform:t},{writableObjectMode:s,readableObjectMode:c}=mv(o,n,r,i);return{...e,value:{transform:a,writableObjectMode:s,readableObjectMode:c}}},Cv=({stdioItem:e,stdioItem:{value:t},index:n,newTransforms:r,direction:i,encoding:a})=>{let{transform:o,final:s,binary:c=!1,preserveNewlines:l=!1,objectMode:u}=K(t)?t:{transform:t},d=c||Uh.has(a),{writableObjectMode:f,readableObjectMode:p}=mv(u,n,r,i);return{...e,value:{transform:o,final:s,binary:d,preserveNewlines:l,writableObjectMode:f,readableObjectMode:p}}},wv=(e,t)=>t===`input`?e.reverse():e,Tv=(e,t,n)=>{let r=e.map(e=>Ev(e,t));if(r.includes(`input`)&&r.includes(`output`))throw TypeError(`The \`${n}\` option must not be an array of both readable and writable values.`);return r.find(Boolean)??Mv},Ev=({type:e,value:t},n)=>Dv[n]??Av[e](t),Dv=[`input`,`output`,`output`],Ov=()=>void 0,kv=()=>`input`,Av={generator:Ov,asyncGenerator:Ov,fileUrl:Ov,filePath:Ov,iterable:kv,asyncIterable:kv,uint8Array:kv,webStream:e=>nv(e)?`output`:`input`,nodeStream(e){return ug(e,{checkOpen:!1})?lg(e,{checkOpen:!1})?void 0:`input`:`output`},webTransform:Ov,duplex:Ov,native(e){let t=jv(e);if(t!==void 0)return t;if(cg(e,{checkOpen:!1}))return Av.nodeStream(e)}},jv=e=>{if([0,b.stdin].includes(e))return`input`;if([1,2,b.stdout,b.stderr].includes(e))return`output`},Mv=`output`,Nv=(e,t)=>t&&!e.includes(`ipc`)?[...e,`ipc`]:e,Pv=({stdio:e,ipc:t,buffer:n,...r},i,a)=>{let o=Fv(e,r).map((e,t)=>Lv(e,t));return a?Rv(o,n,i):Nv(o,t)},Fv=(e,t)=>{if(e===void 0)return Hd.map(e=>t[e]);if(Iv(t))throw Error(`It's not possible to provide \`stdio\` in combination with one of ${Hd.map(e=>`\`${e}\``).join(`, `)}`);if(typeof e==`string`)return[e,e,e];if(!Array.isArray(e))throw TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof e}\``);let n=Math.max(e.length,Hd.length);return Array.from({length:n},(t,n)=>e[n])},Iv=e=>Hd.some(t=>e[t]!==void 0),Lv=(e,t)=>Array.isArray(e)?e.map(e=>Lv(e,t)):e??(t>=Hd.length?`ignore`:`pipe`),Rv=(e,t,n)=>e.map((e,r)=>!t[r]&&r!==0&&!of(n,r)&&zv(e)?`ignore`:e),zv=e=>e===`pipe`||Array.isArray(e)&&e.every(e=>e===`pipe`),Bv=({stdioItem:e,stdioItem:{type:t},isStdioArray:n,fdNumber:r,direction:i,isSync:a})=>!n||t!==`native`?e:a?Vv({stdioItem:e,fdNumber:r,direction:i}):Wv({stdioItem:e,fdNumber:r}),Vv=({stdioItem:e,stdioItem:{value:t,optionName:n},fdNumber:r,direction:i})=>{let a=Hv({value:t,optionName:n,fdNumber:r,direction:i});if(a!==void 0)return a;if(cg(t,{checkOpen:!1}))throw TypeError(`The \`${n}: Stream\` option cannot both be an array and include a stream with synchronous methods.`);return e},Hv=({value:e,optionName:t,fdNumber:n,direction:r})=>{let i=Uv(e,n);if(i!==void 0){if(r===`output`)return{type:`fileNumber`,value:i,optionName:t};if(Fe.isatty(i))throw TypeError(`The \`${t}: ${zm(e)}\` option is invalid: it cannot be a TTY with synchronous methods.`);return{type:`uint8Array`,value:bd(le(i)),optionName:t}}},Uv=(e,t)=>{if(e===`inherit`)return t;if(typeof e==`number`)return e;let n=Vd.indexOf(e);if(n!==-1)return n},Wv=({stdioItem:e,stdioItem:{value:t,optionName:n},fdNumber:r})=>t===`inherit`?{type:`nodeStream`,value:Gv(r,t,n),optionName:n}:typeof t==`number`?{type:`nodeStream`,value:Gv(t,t,n),optionName:n}:cg(t,{checkOpen:!1})?{type:`nodeStream`,value:t,optionName:n}:e,Gv=(e,t,n)=>{let r=Vd[e];if(r===void 0)throw TypeError(`The \`${n}: ${t}\` option is invalid: no such standard stream.`);return r},Kv=({input:e,inputFile:t},n)=>n===0?[...qv(e),...Yv(t)]:[],qv=e=>e===void 0?[]:[{type:Jv(e),value:e,optionName:`input`}],Jv=e=>{if(ug(e,{checkOpen:!1}))return`nodeStream`;if(typeof e==`string`)return`string`;if(q(e))return`uint8Array`;throw Error("The `input` option must be a string, a Uint8Array or a Node.js Readable stream.")},Yv=e=>e===void 0?[]:[{...Xv(e),optionName:`inputFile`}],Xv=e=>{if(J_(e))return{type:`fileUrl`,value:e};if(Q_(e))return{type:`filePath`,value:{file:e}};throw Error("The `inputFile` option must be a file path string or a file URL.")},Zv=e=>e.filter((t,n)=>e.every((e,r)=>t.value!==e.value||n>=r||t.type===`generator`||t.type===`asyncGenerator`)),Qv=({stdioItem:{type:e,value:t,optionName:n},direction:r,fileDescriptors:i,isSync:a})=>{let o=$v(i,e);if(o.length!==0){if(a){ey({otherStdioItems:o,type:e,value:t,optionName:n,direction:r});return}if(dv.has(e))return ty({otherStdioItems:o,type:e,value:t,optionName:n,direction:r});fv.has(e)&&ry({otherStdioItems:o,type:e,value:t,optionName:n})}},$v=(e,t)=>e.flatMap(({direction:e,stdioItems:n})=>n.filter(e=>e.type===t).map((t=>({...t,direction:e})))),ey=({otherStdioItems:e,type:t,value:n,optionName:r,direction:i})=>{uv.has(t)&&ty({otherStdioItems:e,type:t,value:n,optionName:r,direction:i})},ty=({otherStdioItems:e,type:t,value:n,optionName:r,direction:i})=>{let a=e.filter(e=>ny(e,n));if(a.length===0)return;let o=a.find(e=>e.direction!==i);return iy(o,r,t),i===`output`?a[0].stream:void 0},ny=({type:e,value:t},n)=>e===`filePath`?t.file===n.file:e===`fileUrl`?t.href===n.href:t===n,ry=({otherStdioItems:e,type:t,value:n,optionName:r})=>{let i=e.find(({value:{transform:e}})=>e===n.transform);iy(i,r,t)},iy=(e,t,n)=>{if(e!==void 0)throw TypeError(`The \`${e.optionName}\` and \`${t}\` options must not target ${pv[n]} that is the same.`)},ay=(e,t,n,r)=>{let i=Pv(t,n,r).map((e,n)=>oy({stdioOption:e,fdNumber:n,options:t,isSync:r})),a=my({initialFileDescriptors:i,addProperties:e,options:t,isSync:r});return t.stdio=a.map(({stdioItems:e})=>vy(e)),a},oy=({stdioOption:e,fdNumber:t,options:n,isSync:r})=>{let i=Ud(t),{stdioItems:a,isStdioArray:o}=sy({stdioOption:e,fdNumber:t,options:n,optionName:i}),s=Tv(a,t,i),c=vv(a.map(e=>Bv({stdioItem:e,isStdioArray:o,fdNumber:t,direction:s,isSync:r})),i,s,n),l=_v(c,s);return py(c,l),{direction:s,objectMode:l,stdioItems:c}},sy=({stdioOption:e,fdNumber:t,options:n,optionName:r})=>{let i=Zv([...(Array.isArray(e)?e:[e]).map(e=>cy(e,r)),...Kv(n,t)]),a=i.length>1;return ly(i,a,r),dy(i),{stdioItems:i,isStdioArray:a}},cy=(e,t)=>({type:I_(e,t),value:e,optionName:t}),ly=(e,t,n)=>{if(e.length===0)throw TypeError(`The \`${n}\` option must not be an empty array.`);if(t){for(let{value:t,optionName:n}of e)if(uy.has(t))throw Error(`The \`${n}\` option must not include \`${t}\`.`)}},uy=new Set([`ignore`,`ipc`]),dy=e=>{for(let t of e)fy(t)},fy=({type:e,value:t,optionName:n})=>{if(Y_(t))throw TypeError(`The \`${n}: URL\` option must use the \`file:\` scheme.
377
- For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);if($_(e,t))throw TypeError(`The \`${n}: { file: '...' }\` option must be used instead of \`${n}: '...'\`.`)},py=(e,t)=>{if(!t)return;let n=e.find(({type:e})=>lv.has(e));if(n!==void 0)throw TypeError(`The \`${n.optionName}\` option cannot use both files and transforms in objectMode.`)},my=({initialFileDescriptors:e,addProperties:t,options:n,isSync:r})=>{let i=[];try{for(let a of e)i.push(hy({fileDescriptor:a,fileDescriptors:i,addProperties:t,options:n,isSync:r}));return i}catch(e){throw _y(i),e}},hy=({fileDescriptor:{direction:e,objectMode:t,stdioItems:n},fileDescriptors:r,addProperties:i,options:a,isSync:o})=>({direction:e,objectMode:t,stdioItems:n.map(t=>gy({stdioItem:t,addProperties:i,direction:e,options:a,fileDescriptors:r,isSync:o}))}),gy=({stdioItem:e,addProperties:t,direction:n,options:r,fileDescriptors:i,isSync:a})=>{let o=Qv({stdioItem:e,direction:n,fileDescriptors:i,isSync:a});return o===void 0?{...e,...t[n][e.type](e,r)}:{...e,stream:o}},_y=e=>{for(let{stdioItems:t}of e)for(let{stream:e}of t)e!==void 0&&!Bd(e)&&e.destroy()},vy=e=>{if(e.length>1)return e.some(({value:e})=>e===`overlapped`)?`overlapped`:`pipe`;let[{type:t,value:n}]=e;return t===`native`?n:`pipe`},yy=(e,t)=>ay(Cy,e,t,!0),X=({type:e,optionName:t})=>{xy(t,pv[e])},by=({optionName:e,value:t})=>((t===`ipc`||t===`overlapped`)&&xy(e,`"${t}"`),{}),xy=(e,t)=>{throw TypeError(`The \`${e}\` option cannot be ${t} with synchronous methods.`)},Sy={generator(){},asyncGenerator:X,webStream:X,nodeStream:X,webTransform:X,duplex:X,asyncIterable:X,native:by},Cy={input:{...Sy,fileUrl:({value:e})=>({contents:[bd(le(e))]}),filePath:({value:{file:e}})=>({contents:[bd(le(e))]}),fileNumber:X,iterable:({value:e})=>({contents:[...e]}),string:({value:e})=>({contents:[e]}),uint8Array:({value:e})=>({contents:[e]})},output:{...Sy,fileUrl:({value:e})=>({path:e}),filePath:({value:{file:e,append:t}})=>({path:e,append:t}),fileNumber:({value:e})=>({path:e}),iterable:X,string:X,uint8Array:X}},wy=(e,{stripFinalNewline:t},n)=>Ty(t,n)&&e!==void 0&&!Array.isArray(e)?tg(e):e,Ty=(e,t)=>t===`all`?e[1]||e[2]:e[t],Ey=(e,t,n,r)=>e||n?void 0:ky(t,r),Dy=(e,t,n)=>n?e.flatMap(e=>Oy(e,t)):Oy(e,t),Oy=(e,t)=>{let{transform:n,final:r}=ky(t,{});return[...n(e),...r()]},ky=(e,t)=>(t.previousChunks=``,{transform:Ay.bind(void 0,t,e),final:My.bind(void 0,t)}),Ay=function*(e,t,n){if(typeof n!=`string`){yield n;return}let{previousChunks:r}=e,i=-1;for(let a=0;a<n.length;a+=1)if(n[a]===`
378
- `){let o=jy(n,a,t,e),s=n.slice(i+1,a+1-o);r.length>0&&(s=Fy(r,s),r=``),yield s,i=a}i!==n.length-1&&(r=Fy(r,n.slice(i+1))),e.previousChunks=r},jy=(e,t,n,r)=>n?0:(r.isWindowsNewline=t!==0&&e[t-1]===`\r`,r.isWindowsNewline?2:1),My=function*({previousChunks:e}){e.length>0&&(yield e)},Ny=({binary:e,preserveNewlines:t,readableObjectMode:n,state:r})=>e||t||n?void 0:{transform:Py.bind(void 0,r)},Py=function*({isWindowsNewline:e=!1},t){let{unixNewline:n,windowsNewline:r,LF:i,concatBytes:a}=typeof t==`string`?Iy:Ly;if(t.at(-1)===i){yield t;return}yield a(t,e?r:n)},Fy=(e,t)=>`${e}${t}`,Iy={windowsNewline:`\r
379
- `,unixNewline:`
380
- `,LF:`
381
- `,concatBytes:Fy},Ly={windowsNewline:new Uint8Array([13,10]),unixNewline:new Uint8Array([10]),LF:10,concatBytes:(e,t)=>{let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}},Ry=(e,t)=>e?void 0:zy.bind(void 0,t),zy=function*(e,t){if(typeof t!=`string`&&!q(t)&&!Je.isBuffer(t))throw TypeError(`The \`${e}\` option's transform must use "objectMode: true" to receive as input: ${typeof t}.`);yield t},By=(e,t)=>e?Vy.bind(void 0,t):Hy.bind(void 0,t),Vy=function*(e,t){Uy(e,t),yield t},Hy=function*(e,t){if(Uy(e,t),typeof t!=`string`&&!q(t))throw TypeError(`The \`${e}\` option's function must yield a string or an Uint8Array, not ${typeof t}.`);yield t},Uy=(e,t)=>{if(t==null)throw TypeError(`The \`${e}\` option's function must not call \`yield ${t}\`.
382
- Instead, \`yield\` should either be called with a value, or not be called at all. For example:
383
- if (condition) { yield value; }`)},Wy=(e,t,n)=>{if(n)return;if(e)return{transform:Gy.bind(void 0,new TextEncoder)};let r=new we(t);return{transform:Ky.bind(void 0,r),final:qy.bind(void 0,r)}},Gy=function*(e,t){Je.isBuffer(t)?yield bd(t):typeof t==`string`?yield e.encode(t):yield t},Ky=function*(e,t){yield q(t)?e.write(t):t},qy=function*(e){let t=e.end();t!==``&&(yield t)},Jy=Ee(async(e,t,n,r)=>{t.currentIterable=e(...n);try{for await(let e of t.currentIterable)r.push(e)}finally{delete t.currentIterable}}),Yy=async function*(e,t,n){if(n===t.length){yield e;return}let{transform:r=$y}=t[n];for await(let i of r(e))yield*Yy(i,t,n+1)},Xy=async function*(e){for(let[t,{final:n}]of Object.entries(e))yield*Zy(n,Number(t),e)},Zy=async function*(e,t,n){if(e!==void 0)for await(let r of e())yield*Yy(r,n,t+1)},Qy=Ee(async({currentIterable:e},t)=>{if(e!==void 0){await(t?e.throw(t):e.return());return}if(t)throw t}),$y=function*(e){yield e},eb=(e,t,n,r)=>{try{for(let r of e(...t))n.push(r);r()}catch(e){r(e)}},tb=(e,t)=>[...t.flatMap(t=>[...nb(t,e,0)]),...rb(e)],nb=function*(e,t,n){if(n===t.length){yield e;return}let{transform:r=ab}=t[n];for(let i of r(e))yield*nb(i,t,n+1)},rb=function*(e){for(let[t,{final:n}]of Object.entries(e))yield*ib(n,Number(t),e)},ib=function*(e,t,n){if(e!==void 0)for(let r of e())yield*nb(r,n,t+1)},ab=function*(e){yield e},ob=({value:e,value:{transform:t,final:n,writableObjectMode:r,readableObjectMode:i},optionName:a},{encoding:o})=>{let s={},c=cb(e,o,a),l=G_(t),u=G_(n),d=l?Jy.bind(void 0,Yy,s):eb.bind(void 0,nb),f=l||u?Jy.bind(void 0,Xy,s):eb.bind(void 0,rb),p=l||u?Qy.bind(void 0,s):void 0;return{stream:new Ge({writableObjectMode:r,writableHighWaterMark:qe(r),readableObjectMode:i,readableHighWaterMark:qe(i),transform(e,t,n){d([e,c,0],this,n)},flush(e){f([c],this,e)},destroy:p})}},sb=(e,t,n,r)=>{let i=t.filter(({type:e})=>e===`generator`),a=r?i.reverse():i;for(let{value:t,optionName:r}of a)e=tb(cb(t,n,r),e);return e},cb=({transform:e,final:t,binary:n,writableObjectMode:r,readableObjectMode:i,preserveNewlines:a},o,s)=>{let c={};return[{transform:Ry(r,s)},Wy(n,o,r),Ey(n,a,r,c),{transform:e,final:t},{transform:By(i,s)},Ny({binary:n,preserveNewlines:a,readableObjectMode:i,state:c})].filter(Boolean)},lb=(e,t)=>{for(let n of ub(e))db(e,n,t)},ub=e=>new Set(Object.entries(e).filter(([,{direction:e}])=>e===`input`).map(([e])=>Number(e))),db=(e,t,n)=>{let{stdioItems:r}=e[t],i=r.filter(({contents:e})=>e!==void 0);if(i.length!==0){if(t!==0){let[{type:e,optionName:t}]=i;throw TypeError(`Only the \`stdin\` option, not \`${t}\`, can be ${pv[e]} with synchronous methods.`)}n.input=Dd(i.map(({contents:e})=>e).map(e=>fb(e,r)))}},fb=(e,t)=>{let n=sb(e,t,`utf8`,!0);return pb(n),Dd(n)},pb=e=>{let t=e.find(e=>typeof e!=`string`&&!q(e));if(t!==void 0)throw TypeError(`The \`stdin\` option is invalid: when passing objects as input, a transform must be used to serialize them to strings or Uint8Arrays: ${t}.`)},mb=({stdioItems:e,encoding:t,verboseInfo:n,fdNumber:r})=>r!==`all`&&of(n,r)&&!Uh.has(t)&&hb(r)&&(e.some(({type:e,value:t})=>e===`native`&&gb.has(t))||e.every(({type:e})=>cv.has(e))),hb=e=>e===1||e===2,gb=new Set([`pipe`,`overlapped`]),_b=async(e,t,n,r)=>{for await(let i of e)yb(t)||bb(i,n,r)},vb=(e,t,n)=>{for(let r of e)bb(r,t,n)},yb=e=>e._readableState.pipes.length>0,bb=(e,t,n)=>{Uf({type:`output`,verboseMessage:qf(e),fdNumber:t,verboseInfo:n})},xb=({fileDescriptors:e,syncResult:{output:t},options:n,isMaxBuffer:r,verboseInfo:i})=>{if(t===null)return{output:Array.from({length:3})};let a={},o=new Set([]);return{output:t.map((t,s)=>Sb({result:t,fileDescriptors:e,fdNumber:s,state:a,outputFiles:o,isMaxBuffer:r,verboseInfo:i},n)),...a}},Sb=({result:e,fileDescriptors:t,fdNumber:n,state:r,outputFiles:i,isMaxBuffer:a,verboseInfo:o},{buffer:s,encoding:c,lines:l,stripFinalNewline:u,maxBuffer:d})=>{if(e===null)return;let f=bd(l_(e,a,d)),{stdioItems:p,objectMode:m}=t[n],h=Cb([f],p,c,r),{serializedResult:g,finalResult:_=g}=wb({chunks:h,objectMode:m,encoding:c,lines:l,stripFinalNewline:u,fdNumber:n});Tb({serializedResult:g,fdNumber:n,state:r,verboseInfo:o,encoding:c,stdioItems:p,objectMode:m});let v=s[n]?_:void 0;try{return r.error===void 0&&Eb(g,p,i),v}catch(e){return r.error=e,v}},Cb=(e,t,n,r)=>{try{return sb(e,t,n,!1)}catch(t){return r.error=t,e}},wb=({chunks:e,objectMode:t,encoding:n,lines:r,stripFinalNewline:i,fdNumber:a})=>{if(t)return{serializedResult:e};if(n===`buffer`)return{serializedResult:Dd(e)};let o=Td(e,n);return r[a]?{serializedResult:o,finalResult:Dy(o,!i[a],t)}:{serializedResult:o}},Tb=({serializedResult:e,fdNumber:t,state:n,verboseInfo:r,encoding:i,stdioItems:a,objectMode:o})=>{if(!mb({stdioItems:a,encoding:i,verboseInfo:r,fdNumber:t}))return;let s=Dy(e,!1,o);try{vb(s,t,r)}catch(e){n.error??=e}},Eb=(e,t,n)=>{for(let{path:r,append:i}of t.filter(({type:e})=>lv.has(e))){let t=typeof r==`string`?r:r.toString();i||n.has(t)?ae(r,e):(n.add(t),fe(r,e))}},Db=([,e,t],n)=>{if(n.all)return e===void 0?t:t===void 0?e:Array.isArray(e)?Array.isArray(t)?[...e,...t]:[...e,wy(t,n,`all`)]:Array.isArray(t)?[wy(e,n,`all`),...t]:q(e)&&q(t)?kd([e,t]):`${e}${t}`},Ob=async(e,t)=>{let[n,r]=await kb(e);return t.isForcefullyTerminated??=!1,[n,r]},kb=async e=>{let[t,n]=await Promise.allSettled([x(e,`spawn`),x(e,`exit`)]);return t.status===`rejected`?[]:n.status===`rejected`?Ab(e):n.value},Ab=async e=>{try{return await x(e,`exit`)}catch{return Ab(e)}},jb=async e=>{let[t,n]=await e;if(!Mb(t,n)&&Nb(t,n))throw new wp;return[t,n]},Mb=(e,t)=>e===void 0&&t===void 0,Nb=(e,t)=>e!==0||t!==null,Pb=({error:e,status:t,signal:n,output:r},{maxBuffer:i})=>{let a=Fb(e,t,n);return{resultError:a,exitCode:t,signal:n,timedOut:a?.code===`ETIMEDOUT`,isMaxBuffer:c_(a,r,i)}},Fb=(e,t,n)=>e===void 0?Nb(t,n)?new wp:void 0:e,Ib=(e,t,n)=>{let{file:r,commandArguments:i,command:a,escapedCommand:o,startTime:s,verboseInfo:c,options:l,fileDescriptors:u}=Lb(e,t,n);return F_(Vb({file:r,commandArguments:i,options:l,command:a,escapedCommand:o,verboseInfo:c,fileDescriptors:u,startTime:s}),c,l)},Lb=(e,t,n)=>{let{command:r,escapedCommand:i,startTime:a,verboseInfo:o}=np(e,t,n),{file:s,commandArguments:c,options:l}=Zh(e,t,Rb(n));return zb(l),{file:s,commandArguments:c,command:r,escapedCommand:i,startTime:a,verboseInfo:o,options:l,fileDescriptors:yy(l,o)}},Rb=e=>e.node&&!e.ipc?{...e,ipc:!1}:e,zb=({ipc:e,ipcInput:t,detached:n,cancelSignal:r})=>{t&&Bb(`ipcInput`),e&&Bb(`ipc: true`),n&&Bb(`detached: true`),r&&Bb(`cancelSignal`)},Bb=e=>{throw TypeError(`The "${e}" option cannot be used with synchronous methods.`)},Vb=({file:e,commandArguments:t,options:n,command:r,escapedCommand:i,verboseInfo:a,fileDescriptors:o,startTime:s})=>{let c=Hb({file:e,commandArguments:t,options:n,command:r,escapedCommand:i,fileDescriptors:o,startTime:s});if(c.failed)return c;let{resultError:l,exitCode:u,signal:d,timedOut:f,isMaxBuffer:p}=Pb(c,n),{output:m,error:h=l}=xb({fileDescriptors:o,syncResult:c,options:n,isMaxBuffer:p,verboseInfo:a}),g=m.map((e,t)=>wy(e,n,t)),_=wy(Db(m,n),n,`all`);return Wb({error:h,exitCode:u,signal:d,timedOut:f,isMaxBuffer:p,stdio:g,all:_,options:n,command:r,escapedCommand:i,startTime:s})},Hb=({file:e,commandArguments:t,options:n,command:r,escapedCommand:i,fileDescriptors:a,startTime:o})=>{try{return lb(a,n),Ce(...eg(e,t,Ub(n)))}catch(e){return y_({error:e,command:r,escapedCommand:i,fileDescriptors:a,options:n,startTime:o,isSync:!0})}},Ub=({encoding:e,maxBuffer:t,...n})=>({...n,encoding:`buffer`,maxBuffer:u_(t)}),Wb=({error:e,exitCode:t,signal:n,timedOut:r,isMaxBuffer:i,stdio:a,all:o,options:s,command:c,escapedCommand:l,startTime:u})=>e===void 0?v_({command:c,escapedCommand:l,stdio:a,all:o,ipcOutput:[],options:s,startTime:u}):b_({error:e,command:c,escapedCommand:l,timedOut:r,isCanceled:!1,isGracefullyCanceled:!1,isMaxBuffer:i,isForcefullyTerminated:!1,exitCode:t,signal:n,stdio:a,all:o,ipcOutput:[],options:s,startTime:u,isSync:!0}),Gb=({anyProcess:e,channel:t,isSubprocess:n,ipc:r},{reference:i=!0,filter:a}={})=>(um({methodName:`getOneMessage`,isSubprocess:n,ipc:r,isConnected:$m(e)}),Kb({anyProcess:e,channel:t,isSubprocess:n,filter:a,reference:i})),Kb=async({anyProcess:e,channel:t,isSubprocess:n,filter:r,reference:i})=>{Vm(t,i);let a=Xm(e,t,n),o=new AbortController;try{return await Promise.race([qb(a,r,o),Jb(a,n,o),Yb(a,n,o)])}catch(t){throw Dm(e),t}finally{o.abort(),Um(t,i)}},qb=async(e,t,{signal:n})=>{if(t===void 0){let[t]=await x(e,`message`,{signal:n});return t}for await(let[r]of Re(e,`message`,{signal:n}))if(t(r))return r},Jb=async(e,t,{signal:n})=>{await x(e,`disconnect`,{signal:n}),pm(t)},Yb=async(e,t,{signal:n})=>{let[r]=await x(e,`strict:error`,{signal:n});throw hm(r,t)},Xb=({anyProcess:e,channel:t,isSubprocess:n,ipc:r},{reference:i=!0}={})=>Zb({anyProcess:e,channel:t,isSubprocess:n,ipc:r,shouldAwait:!n,reference:i}),Zb=({anyProcess:e,channel:t,isSubprocess:n,ipc:r,shouldAwait:i,reference:a})=>{um({methodName:`getEachMessage`,isSubprocess:n,ipc:r,isConnected:$m(e)}),Vm(t,a);let o=Xm(e,t,n),s=new AbortController,c={};return Qb(e,o,s),$b({ipcEmitter:o,isSubprocess:n,controller:s,state:c}),ex({anyProcess:e,channel:t,ipcEmitter:o,isSubprocess:n,shouldAwait:i,controller:s,state:c,reference:a})},Qb=async(e,t,n)=>{try{await x(t,`disconnect`,{signal:n.signal}),n.abort()}catch{}},$b=async({ipcEmitter:e,isSubprocess:t,controller:n,state:r})=>{try{let[i]=await x(e,`strict:error`,{signal:n.signal});r.error=hm(i,t),n.abort()}catch{}},ex=async function*({anyProcess:e,channel:t,ipcEmitter:n,isSubprocess:r,shouldAwait:i,controller:a,state:o,reference:s}){try{for await(let[e]of Re(n,`message`,{signal:a.signal}))tx(o),yield e}catch{tx(o)}finally{a.abort(),Um(t,s),r||Dm(e),i&&await e}},tx=({error:e})=>{if(e)throw e},nx=(e,{ipc:t})=>{Object.assign(e,ix(e,!1,t))},rx=()=>{let e=b,t=b.channel!==void 0;return{...ix(e,!0,t),getCancelSignal:Sh.bind(void 0,{anyProcess:e,channel:e.channel,isSubprocess:!0,ipc:t})}},ix=(e,t,n)=>({sendMessage:gh.bind(void 0,{anyProcess:e,channel:e.channel,isSubprocess:t,ipc:n}),getOneMessage:Gb.bind(void 0,{anyProcess:e,channel:e.channel,isSubprocess:t,ipc:n}),getEachMessage:Xb.bind(void 0,{anyProcess:e,channel:e.channel,isSubprocess:t,ipc:n})}),ax=({error:e,command:t,escapedCommand:n,fileDescriptors:r,options:i,startTime:a,verboseInfo:o})=>{_y(r);let s=new be;ox(s,r),Object.assign(s,{readable:cx,writable:lx,duplex:ux});let c=y_({error:e,command:t,escapedCommand:n,fileDescriptors:r,options:i,startTime:a,isSync:!1});return{subprocess:s,promise:dx(c,o,i)}},ox=(e,t)=>{let n=sx(),r=sx(),i=sx(),a=Array.from({length:t.length-3},sx),o=sx(),s=[n,r,i,...a];Object.assign(e,{stdin:n,stdout:r,stderr:i,all:o,stdio:s})},sx=()=>{let e=new Ue;return e.end(),e},cx=()=>new We({read(){}}),lx=()=>new Ke({write(){}}),ux=()=>new He({read(){},write(){}}),dx=async(e,t,n)=>F_(e,t,n),fx=(e,t)=>ay(hx,e,t,!1),px=({type:e,optionName:t})=>{throw TypeError(`The \`${t}\` option cannot be ${pv[e]}.`)},mx={fileNumber:px,generator:ob,asyncGenerator:ob,nodeStream:({value:e})=>({stream:e}),webTransform({value:{transform:e,writableObjectMode:t,readableObjectMode:n}}){let r=t||n;return{stream:He.fromWeb(e,{objectMode:r})}},duplex:({value:{transform:e}})=>({stream:e}),native(){}},hx={input:{...mx,fileUrl:({value:e})=>({stream:oe(e)}),filePath:({value:{file:e}})=>({stream:oe(e)}),webStream:({value:e})=>({stream:We.fromWeb(e)}),iterable:({value:e})=>({stream:We.from(e)}),asyncIterable:({value:e})=>({stream:We.from(e)}),string:({value:e})=>({stream:We.from(e)}),uint8Array:({value:e})=>({stream:We.from(Je.from(e))})},output:{...mx,fileUrl:({value:e})=>({stream:se(e)}),filePath:({value:{file:e,append:t}})=>({stream:se(e,t?{flags:`a`}:{})}),webStream:({value:e})=>({stream:Ke.fromWeb(e)}),iterable:px,asyncIterable:px,string:px,uint8Array:px}};function gx(e){if(!Array.isArray(e))throw TypeError(`Expected an array, got \`${typeof e}\`.`);for(let t of e)Sx(t);let t=e.some(({readableObjectMode:e})=>e),n=_x(e,t),r=new vx({objectMode:t,writableHighWaterMark:n,readableHighWaterMark:n});for(let t of e)r.add(t);return r}const _x=(e,t)=>{if(e.length===0)return qe(t);let n=e.filter(({readableObjectMode:e})=>e===t).map(({readableHighWaterMark:e})=>e);return Math.max(...n)};var vx=class extends Ue{#e=new Set([]);#t=new Set([]);#n=new Set([]);#r;#i=Symbol(`unpipe`);#a=new WeakMap;add(e){if(Sx(e),this.#e.has(e))return;this.#e.add(e),this.#r??=yx(this,this.#e,this.#i);let t=Cx({passThroughStream:this,stream:e,streams:this.#e,ended:this.#t,aborted:this.#n,onFinished:this.#r,unpipeEvent:this.#i});this.#a.set(e,t),e.pipe(this,{end:!1})}async remove(e){if(Sx(e),!this.#e.has(e))return!1;let t=this.#a.get(e);return t===void 0?!1:(this.#a.delete(e),e.unpipe(this),await t,!0)}};const yx=async(e,t,n)=>{Nx(e,Px);let r=new AbortController;try{await Promise.race([bx(e,r),xx(e,t,n,r)])}finally{r.abort(),Nx(e,-Px)}},bx=async(e,{signal:t})=>{try{await Ve(e,{signal:t,cleanup:!0})}catch(t){throw Ox(e,t),t}},xx=async(e,t,n,{signal:r})=>{for await(let[i]of Re(e,`unpipe`,{signal:r}))t.has(i)&&i.emit(n)},Sx=e=>{if(typeof e?.pipe!=`function`)throw TypeError(`Expected a readable stream, got: \`${typeof e}\`.`)},Cx=async({passThroughStream:e,stream:t,streams:n,ended:r,aborted:i,onFinished:a,unpipeEvent:o})=>{Nx(e,Fx);let s=new AbortController;try{await Promise.race([wx(a,t,s),Tx({passThroughStream:e,stream:t,streams:n,ended:r,aborted:i,controller:s}),Ex({stream:t,streams:n,ended:r,aborted:i,unpipeEvent:o,controller:s})])}finally{s.abort(),Nx(e,-Fx)}n.size>0&&n.size===r.size+i.size&&(r.size===0&&i.size>0?Ax(e):Dx(e))},wx=async(e,t,{signal:n})=>{try{await e,n.aborted||Ax(t)}catch(e){n.aborted||Ox(t,e)}},Tx=async({passThroughStream:e,stream:t,streams:n,ended:r,aborted:i,controller:{signal:a}})=>{try{await Ve(t,{signal:a,cleanup:!0,readable:!0,writable:!1}),n.has(t)&&r.add(t)}catch(r){if(a.aborted||!n.has(t))return;kx(r)?i.add(t):jx(e,r)}},Ex=async({stream:e,streams:t,ended:n,aborted:r,unpipeEvent:i,controller:{signal:a}})=>{if(await x(e,i,{signal:a}),!e.readable)return x(a,`abort`,{signal:a});t.delete(e),n.delete(e),r.delete(e)},Dx=e=>{e.writable&&e.end()},Ox=(e,t)=>{kx(t)?Ax(e):jx(e,t)},kx=e=>e?.code===`ERR_STREAM_PREMATURE_CLOSE`,Ax=e=>{(e.readable||e.writable)&&e.destroy()},jx=(e,t)=>{e.destroyed||(e.once(`error`,Mx),e.destroy(t))},Mx=()=>{},Nx=(e,t)=>{let n=e.getMaxListeners();n!==0&&n!==1/0&&e.setMaxListeners(n+t)},Px=2,Fx=1,Ix=(e,t)=>{e.pipe(t),Lx(e,t),zx(e,t)},Lx=async(e,t)=>{if(!(Bd(e)||Bd(t))){try{await Ve(e,{cleanup:!0,readable:!0,writable:!1})}catch{}Rx(t)}},Rx=e=>{e.writable&&e.end()},zx=async(e,t)=>{if(!(Bd(e)||Bd(t))){try{await Ve(t,{cleanup:!0,readable:!1,writable:!0})}catch{}Bx(e)}},Bx=e=>{e.readable&&e.destroy()},Vx=(e,t,n)=>{let r=new Map;for(let[i,{stdioItems:a,direction:o}]of Object.entries(t)){for(let{stream:t}of a.filter(({type:e})=>cv.has(e)))Hx(e,t,o,i);for(let{stream:t}of a.filter(({type:e})=>!cv.has(e)))Wx({subprocess:e,stream:t,direction:o,fdNumber:i,pipeGroups:r,controller:n})}for(let[e,t]of r.entries())Ix(t.length===1?t[0]:gx(t),e)},Hx=(e,t,n,r)=>{n===`output`?Ix(e.stdio[r],t):Ix(t,e.stdio[r]);let i=Ux[r];i!==void 0&&(e[i]=t),e.stdio[r]=t},Ux=[`stdin`,`stdout`,`stderr`],Wx=({subprocess:e,stream:t,direction:n,fdNumber:r,pipeGroups:i,controller:a})=>{if(t===void 0)return;Gx(t,a);let[o,s]=n===`output`?[t,e.stdio[r]]:[e.stdio[r],t],c=i.get(o)??[];i.set(o,[...c,s])},Gx=(e,{signal:t})=>{Bd(e)&&Bm(e,Kx,t)},Kx=2,qx=[];qx.push(`SIGHUP`,`SIGINT`,`SIGTERM`),process.platform!==`win32`&&qx.push(`SIGALRM`,`SIGABRT`,`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&qx.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`);const Jx=e=>!!e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`,Yx=Symbol.for(`signal-exit emitter`),Xx=globalThis,Zx=Object.defineProperty.bind(Object);var Qx=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(Xx[Yx])return Xx[Yx];Zx(Xx,Yx,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,t){this.listeners[e].push(t)}removeListener(e,t){let n=this.listeners[e],r=n.indexOf(t);r!==-1&&(r===0&&n.length===1?n.length=0:n.splice(r,1))}emit(e,t,n){if(this.emitted[e])return!1;this.emitted[e]=!0;let r=!1;for(let i of this.listeners[e])r=i(t,n)===!0||r;return e===`exit`&&(r=this.emit(`afterExit`,t,n)||r),r}},$x=class{};const eS=e=>({onExit(t,n){return e.onExit(t,n)},load(){return e.load()},unload(){return e.unload()}});var tS=class extends $x{onExit(){return()=>{}}load(){}unload(){}},nS=class extends $x{#e=rS.platform===`win32`?`SIGINT`:`SIGHUP`;#t=new Qx;#n;#r;#i;#a={};#o=!1;constructor(e){super(),this.#n=e,this.#a={};for(let t of qx)this.#a[t]=()=>{let n=this.#n.listeners(t),{count:r}=this.#t,i=e;if(typeof i.__signal_exit_emitter__==`object`&&typeof i.__signal_exit_emitter__.count==`number`&&(r+=i.__signal_exit_emitter__.count),n.length===r){this.unload();let n=this.#t.emit(`exit`,null,t),r=t===`SIGHUP`?this.#e:t;n||e.kill(e.pid,r)}};this.#i=e.reallyExit,this.#r=e.emit}onExit(e,t){if(!Jx(this.#n))return()=>{};this.#o===!1&&this.load();let n=t?.alwaysLast?`afterExit`:`exit`;return this.#t.on(n,e),()=>{this.#t.removeListener(n,e),this.#t.listeners.exit.length===0&&this.#t.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#o){this.#o=!0,this.#t.count+=1;for(let e of qx)try{let t=this.#a[e];t&&this.#n.on(e,t)}catch{}this.#n.emit=(e,...t)=>this.#c(e,...t),this.#n.reallyExit=e=>this.#s(e)}}unload(){this.#o&&(this.#o=!1,qx.forEach(e=>{let t=this.#a[e];if(!t)throw Error(`Listener not defined for signal: `+e);try{this.#n.removeListener(e,t)}catch{}}),this.#n.emit=this.#r,this.#n.reallyExit=this.#i,--this.#t.count)}#s(e){return Jx(this.#n)?(this.#n.exitCode=e||0,this.#t.emit(`exit`,this.#n.exitCode,null),this.#i.call(this.#n,this.#n.exitCode)):0}#c(e,...t){let n=this.#r;if(e===`exit`&&Jx(this.#n)){typeof t[0]==`number`&&(this.#n.exitCode=t[0]);let r=n.call(this.#n,e,...t);return this.#t.emit(`exit`,this.#n.exitCode,null),r}else return n.call(this.#n,e,...t)}};const rS=globalThis.process,{onExit:iS,load:aS,unload:oS}=eS(Jx(rS)?new nS(rS):new tS),sS=(e,{cleanup:t,detached:n},{signal:r})=>{if(!t||n)return;let i=iS(()=>{e.kill()});Le(r,()=>{i()})},cS=({source:e,sourcePromise:t,boundOptions:n,createNested:r},...i)=>{let a=ep(),{destination:o,destinationStream:s,destinationError:c,from:l,unpipeSignal:u}=lS(n,r,i),{sourceStream:d,sourceError:f}=fS(e,l),{options:p,fileDescriptors:m}=jm.get(e);return{sourcePromise:t,sourceStream:d,sourceOptions:p,sourceError:f,destination:o,destinationStream:s,destinationError:c,unpipeSignal:u,fileDescriptors:m,startTime:a}},lS=(e,t,n)=>{try{let{destination:r,pipeOptions:{from:i,to:a,unpipeSignal:o}={}}=uS(e,t,...n);return{destination:r,destinationStream:km(r,a),from:i,unpipeSignal:o}}catch(e){return{destinationError:e}}},uS=(e,t,n,...r)=>{if(Array.isArray(n))return{destination:t(dS,e)(n,...r),pipeOptions:e};if(typeof n==`string`||n instanceof URL||hd(n)){if(Object.keys(e).length>0)throw TypeError(`Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).`);let[i,a,o]=_d(n,...r);return{destination:t(dS)(i,a,o),pipeOptions:o}}if(jm.has(n)){if(Object.keys(e).length>0)throw TypeError("Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).");return{destination:n,pipeOptions:r[0]}}throw TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${n}`)},dS=({options:e})=>({options:{...e,stdin:`pipe`,piped:!0}}),fS=(e,t)=>{try{return{sourceStream:Am(e,t)}}catch(e){return{sourceError:e}}},pS=({sourceStream:e,sourceError:t,destinationStream:n,destinationError:r,fileDescriptors:i,sourceOptions:a,startTime:o})=>{let s=mS({sourceStream:e,sourceError:t,destinationStream:n,destinationError:r});if(s!==void 0)throw hS({error:s,fileDescriptors:i,sourceOptions:a,startTime:o})},mS=({sourceStream:e,sourceError:t,destinationStream:n,destinationError:r})=>{if(t!==void 0&&r!==void 0)return r;if(r!==void 0)return Bx(e),r;if(t!==void 0)return Rx(n),t},hS=({error:e,fileDescriptors:t,sourceOptions:n,startTime:r})=>y_({error:e,command:gS,escapedCommand:gS,fileDescriptors:t,options:n,startTime:r,isSync:!1}),gS=`source.pipe(destination)`,_S=async e=>{let[{status:t,reason:n,value:r=n},{status:i,reason:a,value:o=a}]=await e;if(o.pipedFrom.includes(r)||o.pipedFrom.push(r),i===`rejected`)throw o;if(t===`rejected`)throw r;return o},vS=(e,t,n)=>{let r=SS.has(t)?bS(e,t):yS(e,t);return Bm(e,CS,n.signal),Bm(t,wS,n.signal),xS(t),r},yS=(e,t)=>{let n=gx([e]);return Ix(n,t),SS.set(t,n),n},bS=(e,t)=>{let n=SS.get(t);return n.add(e),n},xS=async e=>{try{await Ve(e,{cleanup:!0,readable:!1,writable:!0})}catch{}SS.delete(e)},SS=new WeakMap,CS=2,wS=1,TS=(e,t)=>e===void 0?[]:[ES(e,t)],ES=async(e,{sourceStream:t,mergedStream:n,fileDescriptors:r,sourceOptions:i,startTime:a})=>{throw await Te(e,t),await n.remove(t),hS({error:Error("Pipe canceled by `unpipeSignal` option."),fileDescriptors:r,sourceOptions:i,startTime:a})},DS=(e,...t)=>{if(K(t[0]))return DS.bind(void 0,{...e,boundOptions:{...e.boundOptions,...t[0]}});let{destination:n,...r}=cS(e,...t),i=OS({...r,destination:n});return i.pipe=DS.bind(void 0,{...e,source:n,sourcePromise:i,boundOptions:{}}),i},OS=async({sourcePromise:e,sourceStream:t,sourceOptions:n,sourceError:r,destination:i,destinationStream:a,destinationError:o,unpipeSignal:s,fileDescriptors:c,startTime:l})=>{let u=kS(e,i);pS({sourceStream:t,sourceError:r,destinationStream:a,destinationError:o,fileDescriptors:c,sourceOptions:n,startTime:l});let d=new AbortController;try{let e=vS(t,a,d);return await Promise.race([_S(u),...TS(s,{sourceStream:t,mergedStream:e,sourceOptions:n,fileDescriptors:c,startTime:l})])}finally{d.abort()}},kS=(e,t)=>Promise.allSettled([e,t]),AS=({subprocessStdout:e,subprocess:t,binary:n,shouldEncode:r,encoding:i,preserveNewlines:a})=>{let o=new AbortController;return jS(t,o),PS({stream:e,controller:o,binary:n,shouldEncode:!e.readableObjectMode&&r,encoding:i,shouldSplit:!e.readableObjectMode,preserveNewlines:a})},jS=async(e,t)=>{try{await e}catch{}finally{t.abort()}},MS=({stream:e,onStreamEnd:t,lines:n,encoding:r,stripFinalNewline:i,allMixed:a})=>{let o=new AbortController;NS(t,o,e);let s=e.readableObjectMode&&!a;return PS({stream:e,controller:o,binary:r===`buffer`,shouldEncode:!s,encoding:r,shouldSplit:!s&&n,preserveNewlines:!i})},NS=async(e,t,n)=>{try{await e}catch{n.destroy()}finally{t.abort()}},PS=({stream:e,controller:t,binary:n,shouldEncode:r,encoding:i,shouldSplit:a,preserveNewlines:o})=>{let s=Re(e,`data`,{signal:t.signal,highWaterMark:IS,highWatermark:IS});return LS({onStdoutChunk:s,controller:t,binary:n,shouldEncode:r,encoding:i,shouldSplit:a,preserveNewlines:o})},FS=qe(!0),IS=FS,LS=async function*({onStdoutChunk:e,controller:t,binary:n,shouldEncode:r,encoding:i,shouldSplit:a,preserveNewlines:o}){let s=RS({binary:n,shouldEncode:r,encoding:i,shouldSplit:a,preserveNewlines:o});try{for await(let[t]of e)yield*nb(t,s,0)}catch(e){if(!t.signal.aborted)throw e}finally{yield*rb(s)}},RS=({binary:e,shouldEncode:t,encoding:n,shouldSplit:r,preserveNewlines:i})=>[Wy(e,n,!t),Ey(e,i,!r,{})].filter(Boolean),zS=async({stream:e,onStreamEnd:t,fdNumber:n,encoding:r,buffer:i,maxBuffer:a,lines:o,allMixed:s,stripFinalNewline:c,verboseInfo:l,streamInfo:u})=>{let d=BS({stream:e,onStreamEnd:t,fdNumber:n,encoding:r,allMixed:s,verboseInfo:l,streamInfo:u});if(!i){await Promise.all([VS(e),d]);return}let f=MS({stream:e,onStreamEnd:t,lines:o,encoding:r,stripFinalNewline:Ty(c,n),allMixed:s}),[p]=await Promise.all([HS({stream:e,iterable:f,fdNumber:n,encoding:r,maxBuffer:a,lines:o}),d]);return p},BS=async({stream:e,onStreamEnd:t,fdNumber:n,encoding:r,allMixed:i,verboseInfo:a,streamInfo:{fileDescriptors:o}})=>{mb({stdioItems:o[n]?.stdioItems,encoding:r,verboseInfo:a,fdNumber:n})&&await _b(MS({stream:e,onStreamEnd:t,lines:!0,encoding:r,stripFinalNewline:!0,allMixed:i}),e,n,a)},VS=async e=>{await ge(),e.readableFlowing===null&&e.resume()},HS=async({stream:e,stream:{readableObjectMode:t},iterable:n,fdNumber:r,encoding:i,maxBuffer:a,lines:o})=>{try{return t||o?await Ig(n,{maxBuffer:a}):i===`buffer`?new Uint8Array(await Rg(n,{maxBuffer:a})):await $g(n,{maxBuffer:a})}catch(n){return WS(r_({error:n,stream:e,readableObjectMode:t,lines:o,encoding:i,fdNumber:r}))}},US=async e=>{try{return await e}catch(e){return WS(e)}},WS=({bufferedData:e})=>yd(e)?new Uint8Array(e):e,GS=async(e,t,n,{isSameDirection:r,stopOnExit:i=!1}={})=>{let a=KS(e,n),o=new AbortController;try{await Promise.race([...i?[n.exitPromise]:[],Ve(e,{cleanup:!0,signal:o.signal})])}catch(e){a.stdinCleanedUp||YS(e,t,n,r)}finally{o.abort()}},KS=(e,{originalStreams:[t],subprocess:n})=>{let r={stdinCleanedUp:!1};return e===t&&qS(e,n,r),r},qS=(e,t,n)=>{let{_destroy:r}=e;e._destroy=(...i)=>{JS(t,n),r.call(e,...i)}},JS=({exitCode:e,signalCode:t},n)=>{(e!==null||t!==null)&&(n.stdinCleanedUp=!0)},YS=(e,t,n,r)=>{if(!XS(e,t,n,r))throw e},XS=(e,t,n,r=!0)=>n.propagating?$S(e)||QS(e):(n.propagating=!0,ZS(n,t)===r?$S(e):QS(e)),ZS=({fileDescriptors:e},t)=>t!==`all`&&e[t].direction===`input`,QS=e=>e?.code===`ERR_STREAM_PREMATURE_CLOSE`,$S=e=>e?.code===`EPIPE`,eC=({subprocess:e,encoding:t,buffer:n,maxBuffer:r,lines:i,stripFinalNewline:a,verboseInfo:o,streamInfo:s})=>e.stdio.map((e,c)=>tC({stream:e,fdNumber:c,encoding:t,buffer:n[c],maxBuffer:r[c],lines:i[c],allMixed:!1,stripFinalNewline:a,verboseInfo:o,streamInfo:s})),tC=async({stream:e,fdNumber:t,encoding:n,buffer:r,maxBuffer:i,lines:a,allMixed:o,stripFinalNewline:s,verboseInfo:c,streamInfo:l})=>{if(!e)return;let u=GS(e,t,l);if(ZS(l,t)){await u;return}let[d]=await Promise.all([zS({stream:e,onStreamEnd:u,fdNumber:t,encoding:n,buffer:r,maxBuffer:i,lines:a,allMixed:o,stripFinalNewline:s,verboseInfo:c,streamInfo:l}),u]);return d},nC=({stdout:e,stderr:t},{all:n})=>n&&(e||t)?gx([e,t].filter(Boolean)):void 0,rC=({subprocess:e,encoding:t,buffer:n,maxBuffer:r,lines:i,stripFinalNewline:a,verboseInfo:o,streamInfo:s})=>tC({...iC(e,n),fdNumber:`all`,encoding:t,maxBuffer:r[1]+r[2],lines:i[1]||i[2],allMixed:aC(e),stripFinalNewline:a,verboseInfo:o,streamInfo:s}),iC=({stdout:e,stderr:t,all:n},[,r,i])=>{let a=r||i;return a?r?i?{stream:n,buffer:a}:{stream:e,buffer:a}:{stream:t,buffer:a}:{stream:n,buffer:a}},aC=({all:e,stdout:t,stderr:n})=>e&&t&&n&&t.readableObjectMode!==n.readableObjectMode,oC=e=>of(e,`ipc`),sC=(e,t)=>{Uf({type:`ipc`,verboseMessage:qf(e),fdNumber:`ipc`,verboseInfo:t})},cC=async({subprocess:e,buffer:t,maxBuffer:n,ipc:r,ipcOutput:i,verboseInfo:a})=>{if(!r)return i;let o=oC(a),s=rf(t,`ipc`),c=rf(n,`ipc`);for await(let t of Zb({anyProcess:e,channel:e.channel,isSubprocess:!1,ipc:r,shouldAwait:!1,reference:!0}))s&&(a_(e,i,c),i.push(t)),o&&sC(t,a);return i},lC=async(e,t)=>(await Promise.allSettled([e]),t),uC=async({subprocess:e,options:{encoding:t,buffer:n,maxBuffer:r,lines:i,timeoutDuration:a,cancelSignal:o,gracefulCancel:s,forceKillAfterDelay:c,stripFinalNewline:l,ipc:u,ipcInput:d},context:f,verboseInfo:p,fileDescriptors:m,originalStreams:h,onInternalError:g,controller:_})=>{let v=Ob(e,f),y={originalStreams:h,fileDescriptors:m,subprocess:e,exitPromise:v,propagating:!1},ee=eC({subprocess:e,encoding:t,buffer:n,maxBuffer:r,lines:i,stripFinalNewline:l,verboseInfo:p,streamInfo:y}),te=rC({subprocess:e,encoding:t,buffer:n,maxBuffer:r,lines:i,stripFinalNewline:l,verboseInfo:p,streamInfo:y}),ne=[],re=cC({subprocess:e,buffer:n,maxBuffer:r,ipc:u,ipcOutput:ne,verboseInfo:p}),ie=dC(h,e,y),ae=fC(m,y);try{return await Promise.race([Promise.all([{},jb(v),Promise.all(ee),te,re,Bh(e,d),...ie,...ae]),g,pC(e,_),...Ph(e,a,f,_),...cm({subprocess:e,cancelSignal:o,gracefulCancel:s,context:f,controller:_}),...Ah({subprocess:e,cancelSignal:o,gracefulCancel:s,forceKillAfterDelay:c,context:f,controller:_})])}catch(e){return f.terminationReason??=`other`,Promise.all([{error:e},v,Promise.all(ee.map(e=>US(e))),US(te),lC(re,ne),Promise.allSettled(ie),Promise.allSettled(ae)])}},dC=(e,t,n)=>e.map((e,r)=>e===t.stdio[r]?void 0:GS(e,r,n)),fC=(e,t)=>e.flatMap(({stdioItems:e},n)=>e.filter(({value:e,stream:t=e})=>cg(t,{checkOpen:!1})&&!Bd(t)).map(({type:e,value:r,stream:i=r})=>GS(i,n,t,{isSameDirection:cv.has(e),stopOnExit:e===`native`}))),pC=async(e,{signal:t})=>{let[n]=await x(e,`error`,{signal:t});throw n},mC=()=>({readableDestroy:new WeakMap,writableFinal:new WeakMap,writableDestroy:new WeakMap}),hC=(e,t,n)=>{let r=e[n];r.has(t)||r.set(t,[]);let i=r.get(t),a=Om();return i.push(a),{resolve:a.resolve.bind(a),promises:i}},gC=async({resolve:e,promises:t},n)=>{e();let[r]=await Promise.race([Promise.allSettled([!0,n]),Promise.all([!1,...t])]);return!r},_C=async e=>{if(e!==void 0)try{await yC(e)}catch{}},vC=async e=>{if(e!==void 0)try{await bC(e)}catch{}},yC=async e=>{await Ve(e,{cleanup:!0,readable:!1,writable:!0})},bC=async e=>{await Ve(e,{cleanup:!0,readable:!0,writable:!1})},xC=async(e,t)=>{if(await e,t)throw t},SC=(e,t,n)=>{n&&!QS(n)?e.destroy(n):t&&e.destroy()},CC=({subprocess:e,concurrentStreams:t,encoding:n},{from:r,binary:i=!0,preserveNewlines:a=!0}={})=>{let o=i||Uh.has(n),{subprocessStdout:s,waitReadableDestroy:c}=wC(e,r,t),{readableEncoding:l,readableObjectMode:u,readableHighWaterMark:d}=TC(s,o),{read:f,onStdoutDataDone:p}=EC({subprocessStdout:s,subprocess:e,binary:o,encoding:n,preserveNewlines:a}),m=new We({read:f,destroy:Ee(kC.bind(void 0,{subprocessStdout:s,subprocess:e,waitReadableDestroy:c})),highWaterMark:d,objectMode:u,encoding:l});return OC({subprocessStdout:s,onStdoutDataDone:p,readable:m,subprocess:e}),m},wC=(e,t,n)=>{let r=Am(e,t);return{subprocessStdout:r,waitReadableDestroy:hC(n,r,`readableDestroy`)}},TC=({readableEncoding:e,readableObjectMode:t,readableHighWaterMark:n},r)=>r?{readableEncoding:e,readableObjectMode:t,readableHighWaterMark:n}:{readableEncoding:e,readableObjectMode:!0,readableHighWaterMark:FS},EC=({subprocessStdout:e,subprocess:t,binary:n,encoding:r,preserveNewlines:i})=>{let a=Om(),o=AS({subprocessStdout:e,subprocess:t,binary:n,shouldEncode:!n,encoding:r,preserveNewlines:i});return{read(){DC(this,o,a)},onStdoutDataDone:a}},DC=async(e,t,n)=>{try{let{value:r,done:i}=await t.next();i?n.resolve():e.push(r)}catch{}},OC=async({subprocessStdout:e,onStdoutDataDone:t,readable:n,subprocess:r,subprocessStdin:i})=>{try{await bC(e),await r,await _C(i),await t,n.readable&&n.push(null)}catch(e){await _C(i),AC(n,e)}},kC=async({subprocessStdout:e,subprocess:t,waitReadableDestroy:n},r)=>{await gC(n,t)&&(AC(e,r),await xC(t,r))},AC=(e,t)=>{SC(e,e.readable,t)},jC=({subprocess:e,concurrentStreams:t},{to:n}={})=>{let{subprocessStdin:r,waitWritableFinal:i,waitWritableDestroy:a}=MC(e,n,t),o=new Ke({...NC(r,e,i),destroy:Ee(LC.bind(void 0,{subprocessStdin:r,subprocess:e,waitWritableFinal:i,waitWritableDestroy:a})),highWaterMark:r.writableHighWaterMark,objectMode:r.writableObjectMode});return IC(r,o),o},MC=(e,t,n)=>{let r=km(e,t);return{subprocessStdin:r,waitWritableFinal:hC(n,r,`writableFinal`),waitWritableDestroy:hC(n,r,`writableDestroy`)}},NC=(e,t,n)=>({write:PC.bind(void 0,e),final:Ee(FC.bind(void 0,e,t,n))}),PC=(e,t,n,r)=>{e.write(t,n)?r():e.once(`drain`,r)},FC=async(e,t,n)=>{await gC(n,t)&&(e.writable&&e.end(),await t)},IC=async(e,t,n)=>{try{await yC(e),t.writable&&t.end()}catch(e){await vC(n),RC(t,e)}},LC=async({subprocessStdin:e,subprocess:t,waitWritableFinal:n,waitWritableDestroy:r},i)=>{await gC(n,t),await gC(r,t)&&(RC(e,i),await xC(t,i))},RC=(e,t)=>{SC(e,e.writable,t)},zC=({subprocess:e,concurrentStreams:t,encoding:n},{from:r,to:i,binary:a=!0,preserveNewlines:o=!0}={})=>{let s=a||Uh.has(n),{subprocessStdout:c,waitReadableDestroy:l}=wC(e,r,t),{subprocessStdin:u,waitWritableFinal:d,waitWritableDestroy:f}=MC(e,i,t),{readableEncoding:p,readableObjectMode:m,readableHighWaterMark:h}=TC(c,s),{read:g,onStdoutDataDone:_}=EC({subprocessStdout:c,subprocess:e,binary:s,encoding:n,preserveNewlines:o}),v=new He({read:g,...NC(u,e,d),destroy:Ee(BC.bind(void 0,{subprocessStdout:c,subprocessStdin:u,subprocess:e,waitReadableDestroy:l,waitWritableFinal:d,waitWritableDestroy:f})),readableHighWaterMark:h,writableHighWaterMark:u.writableHighWaterMark,readableObjectMode:m,writableObjectMode:u.writableObjectMode,encoding:p});return OC({subprocessStdout:c,onStdoutDataDone:_,readable:v,subprocess:e,subprocessStdin:u}),IC(u,v,c),v},BC=async({subprocessStdout:e,subprocessStdin:t,subprocess:n,waitReadableDestroy:r,waitWritableFinal:i,waitWritableDestroy:a},o)=>{await Promise.all([kC({subprocessStdout:e,subprocess:n,waitReadableDestroy:r},o),LC({subprocessStdin:t,subprocess:n,waitWritableFinal:i,waitWritableDestroy:a},o)])},VC=(e,t,{from:n,binary:r=!1,preserveNewlines:i=!1}={})=>{let a=r||Uh.has(t),o=Am(e,n),s=AS({subprocessStdout:o,subprocess:e,binary:a,shouldEncode:!0,encoding:t,preserveNewlines:i});return HC(s,o,e)},HC=async function*(e,t,n){try{yield*e}finally{t.readable&&t.destroy(),await n}},UC=(e,{encoding:t})=>{let n=mC();e.readable=CC.bind(void 0,{subprocess:e,concurrentStreams:n,encoding:t}),e.writable=jC.bind(void 0,{subprocess:e,concurrentStreams:n}),e.duplex=zC.bind(void 0,{subprocess:e,concurrentStreams:n,encoding:t}),e.iterable=VC.bind(void 0,e,t),e[Symbol.asyncIterator]=VC.bind(void 0,e,t,{})},WC=(e,t)=>{for(let[n,r]of KC){let i=r.value.bind(t);Reflect.defineProperty(e,n,{...r,value:i})}},GC=(async()=>{})().constructor.prototype,KC=[`then`,`catch`,`finally`].map(e=>[e,Reflect.getOwnPropertyDescriptor(GC,e)]),qC=(e,t,n,r)=>{let{file:i,commandArguments:a,command:o,escapedCommand:s,startTime:c,verboseInfo:l,options:u,fileDescriptors:d}=JC(e,t,n),{subprocess:f,promise:p}=XC({file:i,commandArguments:a,options:u,startTime:c,verboseInfo:l,command:o,escapedCommand:s,fileDescriptors:d});return f.pipe=DS.bind(void 0,{source:f,sourcePromise:p,boundOptions:{},createNested:r}),WC(f,p),jm.set(f,{options:u,fileDescriptors:d}),f},JC=(e,t,n)=>{let{command:r,escapedCommand:i,startTime:a,verboseInfo:o}=np(e,t,n),{file:s,commandArguments:c,options:l}=Zh(e,t,n),u=YC(l);return{file:s,commandArguments:c,command:r,escapedCommand:i,startTime:a,verboseInfo:o,options:u,fileDescriptors:fx(u,o)}},YC=({timeout:e,signal:t,...n})=>{if(t!==void 0)throw TypeError(`The "signal" option has been renamed to "cancelSignal" instead.`);return{...n,timeoutDuration:e}},XC=({file:e,commandArguments:t,options:n,startTime:r,verboseInfo:i,command:a,escapedCommand:o,fileDescriptors:s})=>{let c;try{c=Se(...eg(e,t,n))}catch(e){return ax({error:e,command:a,escapedCommand:o,fileDescriptors:s,options:n,startTime:r,verboseInfo:i})}let l=new AbortController;ze(1/0,l.signal);let u=[...c.stdio];Vx(c,s,l),sS(c,n,l);let d={},f=Om();c.kill=tm.bind(void 0,{kill:c.kill.bind(c),options:n,onInternalError:f,context:d,controller:l}),c.all=nC(c,n),UC(c,n),nx(c,n);let p=ZC({subprocess:c,options:n,startTime:r,verboseInfo:i,fileDescriptors:s,originalStreams:u,command:a,escapedCommand:o,context:d,onInternalError:f,controller:l});return{subprocess:c,promise:p}},ZC=async({subprocess:e,options:t,startTime:n,verboseInfo:r,fileDescriptors:i,originalStreams:a,command:o,escapedCommand:s,context:c,onInternalError:l,controller:u})=>{let[d,[f,p],m,h,g]=await uC({subprocess:e,options:t,context:c,verboseInfo:r,fileDescriptors:i,originalStreams:a,onInternalError:l,controller:u});u.abort(),l.resolve();let _=m.map((e,n)=>wy(e,t,n)),v=wy(h,t,`all`);return F_(QC({errorInfo:d,exitCode:f,signal:p,stdio:_,all:v,ipcOutput:g,context:c,options:t,command:o,escapedCommand:s,startTime:n}),r,t)},QC=({errorInfo:e,exitCode:t,signal:n,stdio:r,all:i,ipcOutput:a,context:o,options:s,command:c,escapedCommand:l,startTime:u})=>`error`in e?b_({error:e.error,command:c,escapedCommand:l,timedOut:o.terminationReason===`timeout`,isCanceled:o.terminationReason===`cancel`||o.terminationReason===`gracefulCancel`,isGracefullyCanceled:o.terminationReason===`gracefulCancel`,isMaxBuffer:e.error instanceof Ag,isForcefullyTerminated:o.isForcefullyTerminated,exitCode:t,signal:n,stdio:r,all:i,ipcOutput:a,options:s,startTime:u,isSync:!1}):v_({command:c,escapedCommand:l,stdio:r,all:i,ipcOutput:a,options:s,startTime:u}),$C=(e,t)=>{let n=Object.fromEntries(Object.entries(t).map(([t,n])=>[t,ew(t,e[t],n)]));return{...e,...n}},ew=(e,t,n)=>tw.has(e)&&K(t)&&K(n)?{...t,...n}:n,tw=new Set([`env`,...nf]),nw=(e,t,n,r)=>{let i=(e,t,r)=>nw(e,t,n,r),a=(...a)=>rw({mapArguments:e,deepOptions:n,boundOptions:t,setBoundExeca:r,createNested:i},...a);return r!==void 0&&r(a,i,t),a},rw=({mapArguments:e,deepOptions:t={},boundOptions:n={},setBoundExeca:r,createNested:i},a,...o)=>{if(K(a))return i(e,$C(n,a),r);let{file:s,commandArguments:c,options:l,isSync:u}=iw({mapArguments:e,firstArgument:a,nextArguments:o,deepOptions:t,boundOptions:n});return u?Ib(s,c,l):qC(s,c,l,i)},iw=({mapArguments:e,firstArgument:t,nextArguments:n,deepOptions:r,boundOptions:i})=>{let[a,o,s]=_d(...jd(t)?Md(t,n):[t,...n]),c=$C($C(r,i),s),{file:l=a,commandArguments:u=o,options:d=c,isSync:f=!1}=e({file:a,commandArguments:o,options:c});return{file:l,commandArguments:u,options:d,isSync:f}},aw=({file:e,commandArguments:t})=>sw(e,t),ow=({file:e,commandArguments:t})=>({...sw(e,t),isSync:!0}),sw=(e,t)=>{if(t.length>0)throw TypeError(`The command and its arguments must be passed as a single string: ${e} ${t}.`);let[n,...r]=cw(e);return{file:n,commandArguments:r}},cw=e=>{if(typeof e!=`string`)throw TypeError(`The command must be a string: ${String(e)}.`);let t=e.trim();if(t===``)return[];let n=[];for(let e of t.split(lw)){let t=n.at(-1);t&&t.endsWith(`\\`)?n[n.length-1]=`${t.slice(0,-1)} ${e}`:n.push(e)}return n},lw=/ +/g,uw=(e,t,n)=>{e.sync=t(fw,n),e.s=e.sync},dw=({options:e})=>pw(e),fw=({options:e})=>({...pw(e),isSync:!0}),pw=e=>({options:{...mw(e),...e}}),mw=({input:e,inputFile:t,stdio:n})=>e===void 0&&t===void 0&&n===void 0?{stdin:`inherit`}:{},hw={preferLocal:!0},gw=nw(()=>({}));nw(()=>({isSync:!0})),nw(aw),nw(ow),nw(Ih),nw(dw,{},hw,uw);const{sendMessage:_w,getOneMessage:vw,getEachMessage:yw,getCancelSignal:bw}=rx(),xw=e=>e===void 0?{}:{cwd:e},Sw=e=>e===void 0?{}:{timeout:e},Cw=(e,t)=>[e,`refs: command timed out after ${String(t)}ms`].filter(e=>e!==``).join(`
384
- `),ww=(e,t)=>({exitCode:124,stderr:Cw(e,t),stdout:``,timedOut:!0});var Tw=class{async run(e,t,n){let r=await gw(e,t,{...xw(n?.cwd),...Sw(n?.timeoutMs),reject:!1});return r.timedOut?ww(r.stderr,n?.timeoutMs):{exitCode:r.exitCode??1,stderr:r.stderr,stdout:r.stdout}}};const Ew=$s.partial({description:!0}),Dw=Yo({default_branch:L().min(1),key:Us,tag_format_candidate:Js.nullable(),url:L().min(1)});Dw.extend({description:L().default(``),packages:Ns(Ew)});const Ow=Dw.extend({description:L().min(1),packages:Ns($s)}),kw=Yo({effective_clone_mode:Ks.optional(),head_sha:L().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:L().optional(),last_fetched_at:Ya().optional(),pending_proposal_at:Ya().optional()}),Aw=Yo({refs:js(e=>e.length>=1&&!As.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,ns(L(),kw)).default({})}),jw=(e,t,n)=>t?.[e]??n[e],Mw=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(Lc(e))return;throw e}},Nw=e=>{try{return JSON.parse(e)}catch{return}},Z=async e=>{let t=await Mw(e);if(t===void 0)return Aw.parse({});let n=Nw(t);if(n===void 0)return Aw.parse({});let r=Aw.safeParse(n);return r.success?r.data:Aw.parse({})},Pw=async(e,t)=>{let n=Aw.safeParse(t);if(!n.success)throw T(k(n.error));await Rc(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},Fw=/^\s*-\s+["']?(?<pattern>[^"'#]+)["']?/u,Iw=/^packages:\s*(?:#.*)?$/u,Lw=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Rw=e=>{if(Array.isArray(e))return e.filter(e=>typeof e==`string`);if(!Lw(e))return[];let{packages:t}=e;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]},zw=e=>{let t=[],n=!1;for(let r of e){let e=r.trim();if(Iw.test(r)){n=!0;continue}if(!n)continue;if(e&&!e.startsWith(`-`)&&e.includes(`:`))break;if(!e.startsWith(`-`))continue;let i=Fw.exec(r)?.groups?.pattern?.trim();i&&i!==``&&t.push(i)}return t},Bw=e=>{let{name:t}=e;if(typeof t==`string`)return t},Vw=e=>{let{description:t}=e;if(typeof t==`string`)return t},Hw=/[/\\]/u,Uw=e=>v(e)?!1:e.split(Hw).every(e=>e!==`.`&&e!==`..`),Ww=async(e,t,n=!1)=>{try{let r=ee(await l(e),await l(t));if(n&&r===``)return!0;let i=r===`..`||r.startsWith(`..`+ne);return r!==``&&!i&&!v(r)}catch{return!1}},Gw=async(e,t)=>{try{let n=y(t,`package.json`);return await Ww(e,n)?(await s(n,`utf8`),!0):!1}catch{return!1}},Kw=async(e,t)=>{try{let n=y(e,t);if(!await Ww(e,n,t===`.`))return[];let r=(await c(n,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(async r=>{if(await Gw(e,y(n,r.name)))return y(t,r.name)});return(await Promise.all(r)).filter(e=>e!==void 0)}catch{return[]}},qw=async(e,t)=>{if(!Uw(t)||t.startsWith(`!`)||t.includes(`**`)||(t.match(/\*/gu)??[]).length>1)return[];if(t.endsWith(`/*`)){let n=t.slice(0,-2);return Kw(e,n)}if(t===`*`)return Kw(e,`.`);if(!t.includes(`*`)){let n=y(e,t);if(await Ww(e,n)&&await Gw(e,n))return[t]}return[]},Jw=async(e,t)=>{try{let n=y(t,`package.json`);if(!await Ww(e,n))return;let r=await s(n,`utf8`),i=JSON.parse(r);return{description:Vw(i),name:Bw(i)}}catch{return}},Yw=e=>{let t=e.map(e=>[e.path,e]),n=[...new Map(t).values()];return n.sort((e,t)=>e.path.localeCompare(t.path)),n},Xw=async(e,t)=>{let n=new Set;try{if(!await Ww(e,t))return n;let r=await s(t,`utf8`);Rw(JSON.parse(r).workspaces).forEach(e=>n.add(e))}catch{}return n},Zw=async(e,t)=>{let n=new Set;try{if(!await Ww(e,t))return n;zw((await s(t,`utf8`)).split(`
385
- `)).forEach(e=>n.add(e))}catch{}return n},Qw=async(e,t)=>{let n=new Set,r=[...t].map(t=>qw(e,t));return(await Promise.all(r)).forEach(e=>{e.forEach(e=>n.add(e))}),n},$w=async(e,t)=>{let n=y(e,t);if(!await Ww(e,n))return;let r=await Jw(e,n);if(r?.name)return{description:r.description,name:r.name,path:t}},eT=async(e,t)=>{let n=[...t].map(t=>$w(e,t));return(await Promise.all(n)).filter(e=>e!==void 0)},tT=async e=>{let t=y(e,`package.json`),n=y(e,`pnpm-workspace.yaml`),r=await Xw(e,t),i=await Zw(e,n),a=new Set;if(r.forEach(e=>a.add(e)),i.forEach(e=>a.add(e)),a.size===0)return[];let o=await Qw(e,a),s=await eT(e,o);return Yw(s)},nT=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},rT=()=>({env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:e=>fetch(e),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:nT,runner:new Tw});var iT=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},aT=class extends iT{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},oT=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new aT(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function sT(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var cT=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>sT(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
386
- `)}displayWidth(e){return Ae(e).length}styleTitle(e){return e}styleUsage(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e===`[command]`?this.styleSubcommandText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleCommandText(e)).join(` `)}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleSubcommandText(e)).join(` `)}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,r){let i=` `.repeat(2);if(!n)return i+e;let a=e.padEnd(t+e.length-r.displayWidth(e)),o=(this.helpWidth??80)-t-2-2,s;return s=o<this.minWidthToWrap||r.preformatted(n)?n:r.boxWrap(n,o).replace(/\n/g,`
345
+ `.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),ec=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];t===void 0?n[e]=r:Ws(t)&&Ws(r)&&(n[e]=ec(t,r))}return n},tc={meta:{},refs:{},settings:{}},nc=async e=>{try{return await Ks(e)}catch(e){if(e instanceof _&&e.code===`not_found`)return;throw e}},rc=e=>{if(e!==void 0&&e>1)throw b(`config schema ${e} is newer than this CLI supports — upgrade refs`)},ic=async(e,t,n)=>{let r=Gs(t.meta,{});if(r.cli_version===n)return;let i={...t,meta:{...r,cli_version:n}};await zs(e.configPath,Rs(i))},ac=async(e,t,n)=>{await r(e.configPath,Bs(e));let i=ec(t,tc),a=Gs(i.meta,{}),o={...i,meta:{...a,cli_version:n,schema_version:1}},s=ss.safeParse(o);if(!s.success)throw b(`config in ${e.configPath} is malformed beyond automatic migration (backup preserved at ${Bs(e)}): ${O(s.error)}`);await zs(e.configPath,Rs(o))},oc=async(e,t)=>(await $s(e,t),`seeded`),sc=async(e,t,n)=>{let r=qs(t,e.configPath),i=Ys(r);return rc(i),i===1?(await ic(e,r,n),`noop`):(await ac(e,r,n),`migrated`)},cc=async(e,t)=>{let n=await nc(e);return n===void 0?oc(e,t):sc(e,n,t)},lc=e=>{let t=e.stderr.trim()||e.stdout.trim()||`exit code ${e.exitCode}`,n=t.split(`
346
+ `)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`},uc=(e,t)=>t?`restored`:e.oldSha===e.newSha?`fresh`:`updated`,dc=(e,t)=>{let n=[];if(e&&n.push(`checkout had local changes (managed checkouts are read-only) — discarded and restored to the remote state`),t!==void 0&&n.push(t),n.length!==0)return n.join(` | `)},fc=e=>{let{branchRenamedTo:t,dirty:n,setHeadWarning:r,shas:i}=e,a={...i,status:uc(i,n)};t!==void 0&&(a.branchRenamedTo=t);let o=dc(n,r);return o!==void 0&&(a.warning=o),a},pc=(e,t,n)=>{let r={dirty:t,shas:n};return e.branchRenamedTo!==void 0&&(r.branchRenamedTo=e.branchRenamedTo),e.warning!==void 0&&(r.setHeadWarning=e.warning),r},G=e=>le(m(e,`.git`)),mc=e=>`refusing to sync ${e}: not a refs-managed checkout`,hc=async(e,t)=>{if(!G(t))throw b(mc(t));let n=await e.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:t});if(n.exitCode!==0||n.stdout.trim()===``)throw b(mc(t))},gc=/filtering not recognized/iu,_c=e=>e===void 0?{}:{cwd:e},K=(e,t,n)=>({action:e,args:t,cmd:`git`,..._c(n)}),vc=async(e,t)=>{let n=await e.run(t.cmd,t.args,_c(t.cwd));if(n.exitCode===0)return n;let r=n.stderr.trim()||n.stdout.trim()||`exit code ${n.exitCode}`;throw b(`${t.action} failed: ${r}`)},yc=async(e,t)=>{let n=[`clone`,`-q`];t.mode===`blobless`&&n.push(`--filter=blob:none`),n.push(t.cloneUrl,t.dest);let r=await vc(e,K(`git clone`,n));return await vc(e,K(`git config core.hooksPath`,[`config`,`core.hooksPath`,t.hooksDir],t.dest)),t.mode===`blobless`&&gc.test(r.stderr)?{effectiveMode:`full`,warning:`server did not honour the partial-clone filter (blob:none); fell back to a full clone`}:{effectiveMode:t.mode}},bc=async(e,t)=>{let n=await e.run(`git`,[`symbolic-ref`,`--short`,`refs/remotes/origin/HEAD`],{cwd:t});if(n.exitCode!==0)return;let r=n.stdout.trim();return r.startsWith(`origin/`)?r.slice(7):r},xc=async(e,t)=>{let n=await bc(e,t);if(n!==void 0)return n;await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t});let r=await bc(e,t);if(r!==void 0)return r;throw b(`could not detect the default branch for checkout: ${t}`)},Sc=async(e,t)=>(await vc(e,K(`git rev-parse HEAD`,[`rev-parse`,`HEAD`],t))).stdout.trim(),Cc=async(e,t)=>(await vc(e,K(`git status --porcelain`,[`status`,`--porcelain`],t))).stdout.trim()!==``,wc=async(e,t)=>{await vc(e,K(`git fetch`,[`fetch`,`--prune`,`--tags`,`origin`],t.dir));let n=await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t.dir}),r=await xc(e,t.dir),i={branch:r};return r!==t.defaultBranch&&(i.branchRenamedTo=r),n.exitCode!==0&&(i.warning=`could not refresh origin/HEAD: ${lc(n)}`),i},Tc=e=>[K(`git reset --hard HEAD (pre-checkout)`,[`reset`,`--hard`,`HEAD`],e),K(`git clean -fd`,[`clean`,`-fd`],e)],Ec=async(e,t)=>{let{branch:n,dir:r,dirty:i}=t,a=[];i&&a.push(...Tc(r)),a.push(K(`git checkout -B`,[`checkout`,`-B`,n,`origin/${n}`],r),K(`git reset --hard`,[`reset`,`--hard`,`origin/${n}`],r));for(let t of a)await vc(e,t)},Dc=async(e,t)=>{await hc(e,t.dir);let n=await Sc(e,t.dir),r=await wc(e,t),i=await Cc(e,t.dir);return await Ec(e,{branch:r.branch,dir:t.dir,dirty:i}),fc(pc(r,i,{newSha:await Sc(e,t.dir),oldSha:n}))},Oc=async(e,t,n=20)=>(await vc(e,K(`git tag`,[`tag`,`--sort=-version:refname`],t))).stdout.split(`
347
+ `).map(e=>e.trim()).filter(e=>e!==``).slice(0,n),kc=async(e,t,n)=>(await e.run(`git`,[`show-ref`,`--verify`,`--`,`refs/tags/${n}`],{cwd:t})).exitCode===0,Ac=[`#!/bin/sh`,`echo "refs: this checkout is a managed read-only reference — commits are blocked" >&2`,`exit 1`,``].join(`
348
+ `),jc=async e=>{await Promise.all([`pre-commit`,`pre-push`].map(async n=>{let r=m(e.hooksDir,n);await zs(r,Ac),await t(r,493)}))},Mc=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Nc=/\d+\.\d+\.\d+/gu,Pc=e=>es.safeParse(e).success,Fc=e=>{let t=e.match(Nc);return t!==null&&t.length>1},Ic=e=>{let t=Mc.exec(e);if(!t||Fc(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Pc(r))return r},Lc=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Rc=e=>{let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n];if(r===void 0)continue;let i=Ic(r);i&&Lc(t,i,n)}return t},zc=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,Bc=e=>{let t=[...e.entries()];if(t.length===0)return null;let n=t[0];if(!n)return null;let[r,i]=n;return t.slice(1).reduce(({format:e,data:t},[n,r])=>zc(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Vc=e=>{let t=Rc(e);return Bc(t)},Hc=(e,t)=>e.replaceAll(`{version}`,()=>t),Uc=async(e,t,n,r)=>{let i=Hc(n,r);if(!await kc(e,t,i))throw v(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},Wc=/^(?<scheme>[a-z][a-z0-9+.-]*:\/\/)?[\s\S]*@/iu,q=e=>{let t=e.replace(Wc,`$<scheme><redacted>@`);return t.length<=200?t:`${t.slice(0,200)}…`},Gc=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,Kc=/^git\+/u,qc={"https:":`443`,"ssh:":`22`},Jc=e=>e.replace(/\.git$/u,``),Yc=e=>e.split(`/`).some(e=>e===`.`||e===`..`),Xc=e=>e.includes(`\\`),Zc=e=>e.includes(`%`),Qc=e=>{let t=z.safeParse(e);if(!t.success)throw b(`not a supported git url: derived key '${q(e)}' is invalid`);return t.data},$c=({host:e,port:t,protocol:n})=>{let r=qc[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},el=e=>{let t=Jc(e.path.replace(/^\/+/u,``).replace(/\/+$/u,``));return Qc(`${$c(e)}/${t}`)},tl=e=>{let t=decodeURIComponent(e).split(`/`).filter(e=>e!==``);if(t.length<2)throw b(`not a supported git url: file url path must have at least 2 segments`);let n=t.at(-2)??``,r=t.at(-1)??``;return Qc(`local/${n}/${r}`)},nl=(e,t)=>{try{return new URL(e)}catch{throw b(`not a supported git url: ${q(t)}`)}},rl=e=>{if(e.password!==``)throw b(`not a supported git url: credentials embedded in url`);if(e.protocol===`https:`&&e.username!==``)throw b(`not a supported git url: credentials embedded in https url`)},il=(e,t)=>{if(e.protocol===`file:`){if(!t)throw b(`not a supported git url: unsupported protocol ${e.protocol}`);return tl(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw b(`not a supported git url: unsupported protocol ${e.protocol}`);return rl(e),el({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},al=(e,t)=>{if(Zc(e))throw b(`not a supported git url: percent-encoding not supported in ${q(t)}`);if(e.includes(`:`))throw b(`not a supported git url: ambiguous ':' in scp-style path ${q(t)}; use the ssh:// url form instead`);if(e.startsWith(`/`)||e.startsWith(`~`))throw b(`not a supported git url: ambiguous absolute/home-relative scp path in ${q(t)}; use the ssh:// url form instead`)},ol=(e,t)=>{let n=e.groups?.path??``;return al(n,t),el({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},sl=(e,t)=>{if(Xc(e))throw b(`not a supported git url: backslash not allowed in ${q(t)}`)},cl=(e,t)=>{if(Yc(e))throw b(`not a supported git url: path traversal segment in ${q(t)}`)},ll=(e,t,n)=>{if(e.protocol!==`file:`&&Zc(t))throw b(`not a supported git url: percent-encoding not supported in ${q(n)}`)},J=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace(Kc,``);sl(r,e),cl(r,e);let i=Gc.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:ol(i,e)};let a=nl(r,e);return ll(a,r,e),{cloneUrl:r,key:il(a,n)}},ul=`.git`,dl=e=>e.replace(/^\/+/u,``).replace(/\/+$/u,``),fl=e=>e.endsWith(ul)?e:`${e}${ul}`,pl=(e,t)=>`https://${e.toLowerCase()}/${dl(t)}`,ml=(e,t)=>`git@${e.toLowerCase()}:${fl(dl(t))}`,hl=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw b(`not a supported git url: unsupported protocol ${e}`)},gl=(e,t,n)=>{let r=qc[e.protocol];if(e.port!==``&&e.port!==r)throw b(`cannot apply git_transport=${t} to ${q(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},_l=(e,t)=>t===`https`?pl(e.hostname,e.pathname):ml(e.hostname,e.pathname),vl=(e,t,n)=>{let r=J(t).key;if(r!==n)throw b(`git_transport transform changed repo identity: '${q(e)}' → '${t}' (key '${n}' → '${r}')`);return t},yl=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return vl(t.cloneUrl,pl(n,r),t.originalKey)},bl=e=>{let t=nl(e.cloneUrl,e.cloneUrl);return hl(t.protocol)===e.transport?e.cloneUrl:(gl(t,e.transport,e.cloneUrl),vl(e.cloneUrl,_l(t,e.transport),e.originalKey))},xl=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:J(e).key,transport:t},r=Gc.exec(e);return r?.groups===void 0?bl(n):yl(r,n)},Sl=`meta.json`,Cl=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},wl=e=>{try{return process.kill(e,0),!0}catch(e){return Cl(e)!==`ESRCH`}},Tl=e=>{try{return JSON.parse(e)}catch{return}},El=async e=>{try{return await o(e,`utf8`)}catch{return}},Dl=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},Ol=e=>{if(typeof e!=`object`||!e)return;let t=e,{pid:n}=t,r=Dl(t.acquired_at);if(!(typeof n!=`number`||r===void 0))return{acquiredAtMs:r,pid:n}},kl=async e=>{let t=await El(m(e,Sl));if(t!==void 0)return Ol(Tl(t))},Al=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},jl=async e=>{let t=await El(m(e,Sl));if(t!==void 0)return Al(Tl(t))},Ml=async e=>{try{return(await f(e)).mtimeMs}catch{return}},Nl=async(e,t)=>{let n=m(e,Sl),r=`${n}.tmp-${se()}`;await ee(r,t,`utf8`),await l(r,n)},Pl=async(e,t)=>{await Nl(e,JSON.stringify({acquired_at:new Date().toISOString(),pid:process.pid,token:t}))},Fl=/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u,Il=async e=>{let t=await kl(e);if(t===void 0){let t=await Ml(e);return t===void 0?!1:Date.now()-t>5e3}return Date.now()-t.acquiredAtMs>6e5?!0:!wl(t.pid)},Ll=async(e,t)=>{try{await Pl(e,t)}catch(e){if(Cl(e)===`ENOENT`)return`retry`;throw e}return t},Rl=async e=>{try{return await a(e,{recursive:!1}),!0}catch(e){if(Cl(e)===`EEXIST`)return!1;throw e}},zl=async e=>{if(!await Rl(e))return;let t=await Ll(e,se());return t===`retry`?zl(e):t},Bl=e=>m(e.locksDir,`${e.name}.steal-claim`),Vl=e=>m(e.locksDir,`${e.name}.steal.${se()}`),Hl=async e=>{try{return await a(e,{recursive:!1}),!0}catch(e){if(Cl(e)===`EEXIST`)return!1;throw e}},Ul=async e=>{let t=await Ml(e);return t!==void 0&&Date.now()-t>2e3},Wl=async e=>await Hl(e)?!0:await Ul(e)?(await u(e,{force:!0,recursive:!0}),Hl(e)):!1,Gl=async e=>{let t=Vl(e);try{await l(e.lockPath,t)}catch(e){if(Cl(e)===`ENOENT`)return;throw e}return t},Kl=async e=>{if(!await Il(e.lockPath))return;let t=await Gl(e);t!==void 0&&await u(t,{force:!0,recursive:!0})},ql=async e=>{let t=Bl(e);if(await Wl(t))try{await Kl(e)}finally{await u(t,{force:!0,recursive:!0})}},Jl=async(e,t)=>{if(await Il(e.lockPath)){await ql(e);return}if(Date.now()>=t)throw ve(`lock ${e.name} is held — another refs process is running`);await fe(100)},Yl=async(e,t)=>{let n=await zl(e.lockPath);return n===void 0?(await Jl(e,t),Yl(e,t)):n},Xl=async(e,t)=>{await jl(e)===t&&await u(e,{force:!0,recursive:!0})},Zl=e=>{if(e===`.`||e===`..`||!Fl.test(e))throw b(`lock name must not contain "/" or other unsafe characters — only letters, digits, and "_.:-" are allowed, and it may not be "." or "..": ${e}`)},Y=async(e,t,n,r)=>{Zl(t);let i={lockPath:m(e.locksDir,t),locksDir:e.locksDir,name:t};await a(e.locksDir,{recursive:!0});let o=Date.now()+(r?.timeoutMs??1e4),s=await Yl(i,o);try{return await n()}finally{await Xl(i.lockPath,s)}},Ql=no({directory:I().optional(),url:I().optional()}),$l=no({repository:io([I(),Ql]).optional()}),eu=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,tu=new Set([`node_modules`,`favicon.ico`]),nu=e=>v(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),ru=e=>{let t=e.split(`/`);return t.length>=2?t[1]:e},iu=e=>{if(e.length>214)throw y(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!eu.test(e))throw y(`invalid package name: '${e}' does not match npm naming rules`);let t=ru(e);if(tu.has(t))throw y(`invalid package name: '${e}' uses a reserved name`)},au=e=>e.replace(`/`,`%2F`),ou=e=>typeof e==`string`?e:e?.url,su=e=>{if(typeof e==`object`&&e?.directory){let t=ts.safeParse(e.directory);if(t.success)return t.data}},cu=async(e,t)=>{try{return await e.json()}catch{throw b(`invalid npm registry response for '${t}': not parseable JSON`)}},lu=async(e,t)=>{let n=await e(`https://registry.npmjs.org/${au(t)}`);if(n.status===404)throw v(`npm package '${t}' not found`);if(n.status!==200)throw b(`failed to fetch npm package '${t}': status ${n.status}`);let r=await cu(n,t),i=$l.safeParse(r);if(!i.success)throw b(`invalid npm package response for '${t}'`);return i.data},uu=(e,t)=>{try{return J(e)}catch{throw nu(t)}},du=async(e,t)=>{iu(t);let n=await lu(e,t),r=ou(n.repository);if(r===void 0||r===``)throw nu(t);let{cloneUrl:i,key:a}=uu(r,t),o=su(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}},fu=new Set;let pu=!1;const mu=()=>{for(let e of fu)try{e.kill(`SIGKILL`)}catch{}},hu=[`SIGINT`,`SIGTERM`,`SIGHUP`],gu=e=>{let t=()=>{mu(),process.removeListener(e,t),process.kill(process.pid,e)};process.on(e,t)},_u=()=>{pu||(pu=!0,hu.forEach(e=>{gu(e)}),process.on(`exit`,mu))},vu=()=>{let e=[],t=0,n=!1;return{finish:()=>({text:Buffer.concat(e).toString(`utf8`),truncated:n}),push:r=>{if(n)return;let i=67108864-t;if(r.length<=i){e.push(r),t+=r.length;return}i>0&&e.push(r.subarray(0,i)),n=!0}}},yu=(e,t)=>[e.replace(/\r?\n$/u,``),t].filter(e=>e!==``).join(`
349
+ `),bu=(e,t,n)=>{let r=e;return t.truncated&&(r=yu(r,`refs: stdout exceeded 67108864 bytes, truncated`)),n.truncated&&(r=yu(r,`refs: stderr exceeded 67108864 bytes, truncated`)),r},xu={clear:()=>{},markedTimedOut:()=>!1},Su=(e,t)=>{if(t===void 0)return xu;let n=!1,r,i=setTimeout(()=>{n=!0,e.kill(`SIGTERM`),r=setTimeout(()=>{e.kill(`SIGKILL`)},2e3)},t);return{clear:()=>{clearTimeout(i),r!==void 0&&clearTimeout(r)},markedTimedOut:()=>n}},Cu=e=>e===void 0?{}:{cwd:e},wu=(e,t)=>yu(e,`refs: command timed out after ${String(t)}ms`),Tu=(e,t)=>({exitCode:124,stderr:wu(e,t),stdout:``,timedOut:!0}),Eu=(e,t,n)=>{let r=ge(e,t,{...Cu(n?.cwd),stdio:[`ignore`,`pipe`,`pipe`]});fu.add(r);let i=vu(),a=vu();return r.stdout.on(`data`,e=>{i.push(e)}),r.stderr.on(`data`,e=>{a.push(e)}),{child:r,stderrCollector:a,stdoutCollector:i,timeout:Su(r,n?.timeoutMs)}},Du=(e,t,n)=>{try{return Eu(e,t,n)}catch(e){return{exitCode:127,stderr:ku(e),stdout:``}}},Ou=e=>!(`child`in e),ku=e=>e instanceof Error?e.message:String(e),Au=async e=>{try{let[t]=await me(e,`close`);return{code:t}}catch(e){return{code:null,errorMessage:ku(e)}}},ju=e=>e===null?1:e,Mu=e=>e.timedOut?Tu(e.stderr.text,e.timeoutMs):e.errorMessage===void 0?{exitCode:ju(e.code),stderr:bu(e.stderr.text,e.stdout,e.stderr),stdout:e.stdout.text}:{exitCode:127,stderr:yu(e.stderr.text,e.errorMessage),stdout:e.stdout.text};var Nu=class{async run(e,t,n){_u();let r=Du(e,t,n);if(Ou(r))return r;let i=await Au(r.child);return fu.delete(r.child),r.timeout.clear(),Mu({code:i.code,errorMessage:i.errorMessage,stderr:r.stderrCollector.finish(),stdout:r.stdoutCollector.finish(),timedOut:r.timeout.markedTimedOut(),timeoutMs:n?.timeoutMs})}};const Pu=as.partial({description:!0}),Fu=R({default_branch:I().min(1),key:z,tag_format_candidate:es.nullable(),url:I().min(1)});Fu.extend({description:I().default(``),packages:Bo(Pu)});const Iu=Fu.extend({description:I().min(1),packages:Bo(as)}),Lu=R({effective_clone_mode:Qo.optional(),head_sha:I().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:I().optional(),last_fetched_at:ra().optional(),pending_proposal_at:ra().optional()}),Ru=R({refs:Ro(e=>e.length>=1&&!Lo.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,co(I(),Lu)).default({})}),X=(e,t,n)=>t?.[e]??n[e],zu=async e=>{try{return await o(e.statePath,`utf8`)}catch(e){if(V(e))return;throw e}},Bu=e=>{try{return JSON.parse(e)}catch{return}},Z=async e=>{let t=await zu(e);if(t===void 0)return Ru.parse({});let n=Bu(t);if(n===void 0)return Ru.parse({});let r=Ru.safeParse(n);return r.success?r.data:Ru.parse({})},Vu=async(e,t)=>{let n=Ru.safeParse(t);if(!n.success)throw b(O(n.error));await zs(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},Hu=/^\s*-\s+["']?(?<pattern>[^"'#]+)["']?/u,Uu=/^packages:\s*(?:#.*)?$/u,Wu=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gu=e=>{if(Array.isArray(e))return e.filter(e=>typeof e==`string`);if(!Wu(e))return[];let{packages:t}=e;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]},Ku=e=>{let t=[],n=!1;for(let r of e){let e=r.trim();if(Uu.test(r)){n=!0;continue}if(!n)continue;if(e&&!e.startsWith(`-`)&&e.includes(`:`))break;if(!e.startsWith(`-`))continue;let i=Hu.exec(r)?.groups?.pattern?.trim();i&&i!==``&&t.push(i)}return t},qu=e=>{let{name:t}=e;if(typeof t==`string`)return t},Ju=e=>{let{description:t}=e;if(typeof t==`string`)return t},Yu=/[/\\]/u,Xu=e=>re(e)?!1:e.split(Yu).every(e=>e!==`.`&&e!==`..`),Zu=async(e,t,n=!1)=>{try{let r=ie(await c(e),await c(t));if(n&&r===``)return!0;let i=r===`..`||r.startsWith(`..`+oe);return r!==``&&!i&&!re(r)}catch{return!1}},Qu=async(e,t)=>{try{let n=m(t,`package.json`);return await Zu(e,n)?(await o(n,`utf8`),!0):!1}catch{return!1}},$u=async(e,t)=>{try{let n=m(e,t);if(!await Zu(e,n,t===`.`))return[];let r=(await s(n,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(async r=>{if(await Qu(e,m(n,r.name)))return m(t,r.name)});return(await Promise.all(r)).filter(e=>e!==void 0)}catch{return[]}},ed=async(e,t)=>{if(!Xu(t)||t.startsWith(`!`)||t.includes(`**`)||(t.match(/\*/gu)??[]).length>1)return[];if(t.endsWith(`/*`)){let n=t.slice(0,-2);return $u(e,n)}if(t===`*`)return $u(e,`.`);if(!t.includes(`*`)){let n=m(e,t);if(await Zu(e,n)&&await Qu(e,n))return[t]}return[]},td=async(e,t)=>{try{let n=m(t,`package.json`);if(!await Zu(e,n))return;let r=await o(n,`utf8`),i=JSON.parse(r);return{description:Ju(i),name:qu(i)}}catch{return}},nd=e=>{let t=e.map(e=>[e.path,e]),n=[...new Map(t).values()];return n.sort((e,t)=>e.path.localeCompare(t.path)),n},rd=async(e,t)=>{let n=new Set;try{if(!await Zu(e,t))return n;let r=await o(t,`utf8`);Gu(JSON.parse(r).workspaces).forEach(e=>n.add(e))}catch{}return n},id=async(e,t)=>{let n=new Set;try{if(!await Zu(e,t))return n;Ku((await o(t,`utf8`)).split(`
350
+ `)).forEach(e=>n.add(e))}catch{}return n},ad=async(e,t)=>{let n=new Set,r=[...t].map(t=>ed(e,t));return(await Promise.all(r)).forEach(e=>{e.forEach(e=>n.add(e))}),n},od=async(e,t)=>{let n=m(e,t);if(!await Zu(e,n))return;let r=await td(e,n);if(r?.name)return{description:r.description,name:r.name,path:t}},sd=async(e,t)=>{let n=[...t].map(t=>od(e,t));return(await Promise.all(n)).filter(e=>e!==void 0)},cd=async e=>{let t=m(e,`package.json`),n=m(e,`pnpm-workspace.yaml`),r=await rd(e,t),i=await id(e,n),a=new Set;if(r.forEach(e=>a.add(e)),i.forEach(e=>a.add(e)),a.size===0)return[];let o=await ad(e,a),s=await sd(e,o);return nd(s)},ld=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},ud=()=>({env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:e=>fetch(e),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:ld,runner:new Nu});var dd=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},fd=class extends dd{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},pd=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new fd(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function md(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var hd=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>md(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
351
+ `)}displayWidth(e){return _e(e).length}styleTitle(e){return e}styleUsage(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e===`[command]`?this.styleSubcommandText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleCommandText(e)).join(` `)}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleSubcommandText(e)).join(` `)}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,r){let i=` `.repeat(2);if(!n)return i+e;let a=e.padEnd(t+e.length-r.displayWidth(e)),o=(this.helpWidth??80)-t-2-2,s;return s=o<this.minWidthToWrap||r.preformatted(n)?n:r.boxWrap(n,o).replace(/\n/g,`
387
352
  `+` `.repeat(t+2)),i+a+` `.repeat(2)+s.replace(/\n/g,`\n${i}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),r=/[\s]*[^\s]+/g,i=[];return n.forEach(e=>{let n=e.match(r);if(n===null){i.push(``);return}let a=[n.shift()],o=this.displayWidth(a[0]);n.forEach(e=>{let n=this.displayWidth(e);if(o+n<=t){a.push(e),o+=n;return}i.push(a.join(``));let r=e.trimStart();a=[r],o=this.displayWidth(r)}),i.push(a.join(``))}),i.join(`
388
- `)}},lT=class{constructor(e,t){this.flags=e,this.description=t||``,this.required=e.includes(`<`),this.optional=e.includes(`[`),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=fT(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith(`--no-`)),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e==`string`&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new aT(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}name(){return this.long?this.long.replace(/^--/,``):this.short.replace(/^-/,``)}attributeName(){return this.negate?dT(this.name().replace(/^no-/,``)):dT(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},uT=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let r=this.negativeOptions.get(n).presetArg,i=r===void 0?!1:r;return t.negate===(i===e)}};function dT(e){return e.split(`-`).reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function fT(e){let t,n,r=/^-[^-]$/,i=/^--[^-]/,a=e.split(/[ |,]+/).concat(`guard`);if(r.test(a[0])&&(t=a.shift()),i.test(a[0])&&(n=a.shift()),!t&&r.test(a[0])&&(t=a.shift()),!t&&i.test(a[0])&&(t=n,n=a.shift()),a[0].startsWith(`-`)){let t=a[0],n=`option creation failed due to '${t}' in option flags '${e}'`;throw/^-[^-][^-]/.test(t)?Error(`${n}
353
+ `)}},gd=class{constructor(e,t){this.flags=e,this.description=t||``,this.required=e.includes(`<`),this.optional=e.includes(`[`),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=yd(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith(`--no-`)),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e==`string`&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new fd(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}name(){return this.long?this.long.replace(/^--/,``):this.short.replace(/^-/,``)}attributeName(){return this.negate?vd(this.name().replace(/^no-/,``)):vd(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},_d=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let r=this.negativeOptions.get(n).presetArg,i=r===void 0?!1:r;return t.negate===(i===e)}};function vd(e){return e.split(`-`).reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function yd(e){let t,n,r=/^-[^-]$/,i=/^--[^-]/,a=e.split(/[ |,]+/).concat(`guard`);if(r.test(a[0])&&(t=a.shift()),i.test(a[0])&&(n=a.shift()),!t&&r.test(a[0])&&(t=a.shift()),!t&&i.test(a[0])&&(t=n,n=a.shift()),a[0].startsWith(`-`)){let t=a[0],n=`option creation failed due to '${t}' in option flags '${e}'`;throw/^-[^-][^-]/.test(t)?Error(`${n}
389
354
  - a short flag is a single dash and a single character
390
355
  - either use a single dash and a single character (for a short flag)
391
356
  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):r.test(t)?Error(`${n}
392
357
  - too many short flags`):i.test(t)?Error(`${n}
393
358
  - too many long flags`):Error(`${n}
394
- - unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function pT(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=t.length;r++)for(let i=1;i<=e.length;i++){let a;a=e[i-1]===t[r-1]?0:1,n[i][r]=Math.min(n[i-1][r]+1,n[i][r-1]+1,n[i-1][r-1]+a),i>1&&r>1&&e[i-1]===t[r-2]&&e[i-2]===t[r-1]&&(n[i][r]=Math.min(n[i][r],n[i-2][r-2]+1))}return n[e.length][t.length]}function mT(e,t){if(!t||t.length===0)return``;t=Array.from(new Set(t));let n=e.startsWith(`--`);n&&(e=e.slice(2),t=t.map(e=>e.slice(2)));let r=[],i=3;return t.forEach(t=>{if(t.length<=1)return;let n=pT(e,t),a=Math.max(e.length,t.length);(a-n)/a>.4&&(n<i?(i=n,r=[t]):n===i&&r.push(t))}),r.sort((e,t)=>e.localeCompare(t)),n&&(r=r.map(e=>`--${e}`)),r.length>1?`\n(Did you mean one of ${r.join(`, `)}?)`:r.length===1?`\n(Did you mean ${r[0]}?)`:``}var hT=class e extends Ie{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||``,this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description=``,this._summary=``,this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:e=>b.stdout.write(e),writeErr:e=>b.stderr.write(e),outputError:(e,t)=>t(e),getOutHelpWidth:()=>b.stdout.isTTY?b.stdout.columns:void 0,getErrHelpWidth:()=>b.stderr.isTTY?b.stderr.columns:void 0,getOutHasColors:()=>_T()??(b.stdout.isTTY&&b.stdout.hasColors?.()),getErrHasColors:()=>_T()??(b.stderr.isTTY&&b.stderr.hasColors?.()),stripColor:e=>Ae(e)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let r=t,i=n;typeof r==`object`&&r&&(i=r,r=null),i||={};let[,a,o]=e.match(/([^ ]+) *(.*)/),s=this.createCommand(a);return r&&(s.description(r),s._executableHandler=!0),i.isDefault&&(this._defaultCommandName=s._name),s._hidden=!!(i.noHelp||i.hidden),s._executableFile=i.executableFile||null,o&&s.arguments(o),this._registerCommand(s),s.parent=this,s.copyInheritedSettings(this),r?this:s}createCommand(t){return new e(t)}createHelp(){return Object.assign(new cT,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!=`string`&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
395
- - specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new oT(e,t)}argument(e,t,n,r){let i=this.createArgument(e,t);return typeof n==`function`?i.default(r).argParser(n):i.default(n),this.addArgument(i),this}arguments(e){return e.trim().split(/ +/).forEach(e=>{this.argument(e)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e==`boolean`)return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let[,n,r]=(e??`help [command]`).match(/([^ ]+) *(.*)/),i=t??`display help for command`,a=this.createCommand(n);return a.helpOption(!1),r&&a.arguments(r),i&&a.description(i),this._addImplicitHelpCommand=!0,this._helpCommand=a,(e||t)&&this._initCommandGroup(a),this}addHelpCommand(e,t){return typeof e==`object`?(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this):(this.helpCommand(e,t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand(`help`))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=[`preSubcommand`,`preAction`,`postAction`];if(!n.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
396
- Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new iT(e,t,n)),b.exit(e)}action(e){let t=t=>{let n=this.registeredArguments.length,r=t.slice(0,n);return this._storeOptionsAsProperties?r[n]=this:r[n]=this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new lT(e,t)}_callParseArg(e,t,n,r){try{return e.parseArg(t,n)}catch(e){if(e.code===`commander.invalidArgument`){let t=`${r} ${e.message}`;this.error(t,{exitCode:e.exitCode,code:e.code})}throw e}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
397
- - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof lT)throw Error(`To add an Option object use addOption() instead of option() or requiredOption()`);let a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof r==`function`)a.default(i).argParser(r);else if(r instanceof RegExp){let e=r;r=(t,n)=>{let r=e.exec(t);return r?r[0]:n},a.default(i).argParser(r)}else a.default(r);return this.addOption(a)}option(e,t,n,r){return this._optionEx({},e,t,n,r)}requiredOption(e,t,n,r){return this._optionEx({mandatory:!0},e,t,n,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error(`call .storeOptionsAsProperties() before adding options`);if(Object.keys(this._optionValues).length)throw Error(`call .storeOptionsAsProperties() before setting option values`);return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw Error(`first parameter to parse must be array or undefined`);if(t||={},e===void 0&&t.from===void 0){b.versions?.electron&&(t.from=`electron`);let e=b.execArgv??[];(e.includes(`-e`)||e.includes(`--eval`)||e.includes(`-p`)||e.includes(`--print`))&&(t.from=`eval`)}e===void 0&&(e=b.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case`node`:this._scriptPath=e[1],n=e.slice(2);break;case`electron`:b.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case`user`:n=e.slice(0);break;case`eval`:n=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||`program`,n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,`--`);this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,`default`)}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
398
- - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(ie.existsSync(e))return;let r=`'${e}' does not exist
359
+ - unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function bd(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=t.length;r++)for(let i=1;i<=e.length;i++){let a;a=e[i-1]===t[r-1]?0:1,n[i][r]=Math.min(n[i-1][r]+1,n[i][r-1]+1,n[i-1][r-1]+a),i>1&&r>1&&e[i-1]===t[r-2]&&e[i-2]===t[r-1]&&(n[i][r]=Math.min(n[i][r],n[i-2][r-2]+1))}return n[e.length][t.length]}function xd(e,t){if(!t||t.length===0)return``;t=Array.from(new Set(t));let n=e.startsWith(`--`);n&&(e=e.slice(2),t=t.map(e=>e.slice(2)));let r=[],i=3;return t.forEach(t=>{if(t.length<=1)return;let n=bd(e,t),a=Math.max(e.length,t.length);(a-n)/a>.4&&(n<i?(i=n,r=[t]):n===i&&r.push(t))}),r.sort((e,t)=>e.localeCompare(t)),n&&(r=r.map(e=>`--${e}`)),r.length>1?`\n(Did you mean one of ${r.join(`, `)}?)`:r.length===1?`\n(Did you mean ${r[0]}?)`:``}var Sd=class e extends pe{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||``,this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description=``,this._summary=``,this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:e=>h.stdout.write(e),writeErr:e=>h.stderr.write(e),outputError:(e,t)=>t(e),getOutHelpWidth:()=>h.stdout.isTTY?h.stdout.columns:void 0,getErrHelpWidth:()=>h.stderr.isTTY?h.stderr.columns:void 0,getOutHasColors:()=>wd()??(h.stdout.isTTY&&h.stdout.hasColors?.()),getErrHasColors:()=>wd()??(h.stderr.isTTY&&h.stderr.hasColors?.()),stripColor:e=>_e(e)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let r=t,i=n;typeof r==`object`&&r&&(i=r,r=null),i||={};let[,a,o]=e.match(/([^ ]+) *(.*)/),s=this.createCommand(a);return r&&(s.description(r),s._executableHandler=!0),i.isDefault&&(this._defaultCommandName=s._name),s._hidden=!!(i.noHelp||i.hidden),s._executableFile=i.executableFile||null,o&&s.arguments(o),this._registerCommand(s),s.parent=this,s.copyInheritedSettings(this),r?this:s}createCommand(t){return new e(t)}createHelp(){return Object.assign(new hd,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!=`string`&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
360
+ - specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new pd(e,t)}argument(e,t,n,r){let i=this.createArgument(e,t);return typeof n==`function`?i.default(r).argParser(n):i.default(n),this.addArgument(i),this}arguments(e){return e.trim().split(/ +/).forEach(e=>{this.argument(e)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e==`boolean`)return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let[,n,r]=(e??`help [command]`).match(/([^ ]+) *(.*)/),i=t??`display help for command`,a=this.createCommand(n);return a.helpOption(!1),r&&a.arguments(r),i&&a.description(i),this._addImplicitHelpCommand=!0,this._helpCommand=a,(e||t)&&this._initCommandGroup(a),this}addHelpCommand(e,t){return typeof e==`object`?(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this):(this.helpCommand(e,t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand(`help`))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=[`preSubcommand`,`preAction`,`postAction`];if(!n.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
361
+ Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new dd(e,t,n)),h.exit(e)}action(e){let t=t=>{let n=this.registeredArguments.length,r=t.slice(0,n);return this._storeOptionsAsProperties?r[n]=this:r[n]=this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new gd(e,t)}_callParseArg(e,t,n,r){try{return e.parseArg(t,n)}catch(e){if(e.code===`commander.invalidArgument`){let t=`${r} ${e.message}`;this.error(t,{exitCode:e.exitCode,code:e.code})}throw e}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
362
+ - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof gd)throw Error(`To add an Option object use addOption() instead of option() or requiredOption()`);let a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof r==`function`)a.default(i).argParser(r);else if(r instanceof RegExp){let e=r;r=(t,n)=>{let r=e.exec(t);return r?r[0]:n},a.default(i).argParser(r)}else a.default(r);return this.addOption(a)}option(e,t,n,r){return this._optionEx({},e,t,n,r)}requiredOption(e,t,n,r){return this._optionEx({mandatory:!0},e,t,n,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error(`call .storeOptionsAsProperties() before adding options`);if(Object.keys(this._optionValues).length)throw Error(`call .storeOptionsAsProperties() before setting option values`);return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw Error(`first parameter to parse must be array or undefined`);if(t||={},e===void 0&&t.from===void 0){h.versions?.electron&&(t.from=`electron`);let e=h.execArgv??[];(e.includes(`-e`)||e.includes(`--eval`)||e.includes(`-p`)||e.includes(`--print`))&&(t.from=`eval`)}e===void 0&&(e=h.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case`node`:this._scriptPath=e[1],n=e.slice(2);break;case`electron`:h.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case`user`:n=e.slice(0);break;case`eval`:n=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||`program`,n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,`--`);this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,`default`)}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
363
+ - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(ce.existsSync(e))return;let r=`'${e}' does not exist
399
364
  - if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
400
365
  - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
401
- - ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=h.resolve(e,t);if(ie.existsSync(r))return r;if(n.includes(h.extname(t)))return;let i=n.find(e=>ie.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=ie.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=h.resolve(h.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=h.basename(this._scriptPath,h.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(h.extname(i)),s;b.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=gT(b.execArgv).concat(t),s=ye.spawn(b.execPath,t,{stdio:`inherit`})):o?(t.unshift(i),t=gT(b.execArgv).concat(t),s=ye.spawn(b.argv[0],t,{stdio:`inherit`})):s=ye.spawn(i,t,{stdio:`inherit`}),s.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{b.on(e,()=>{s.killed===!1&&s.exitCode===null&&s.kill(e)})});let c=this._exitCallback;s.on(`close`,e=>{e??=1,c?c(new iT(e,`commander.executeSubCommandAsync`,`(close)`)):b.exit(e)}),s.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(i,a,e._name);else if(t.code===`EACCES`)throw Error(`'${i}' not executable`);if(!c)b.exit(1);else{let e=new iT(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,c(e)}}),this.runningCommand=s}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)===void 0?!1:this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l))){this.emit(`option:${o.name()}`,l);continue}if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}else if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
402
- `),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in b.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,b.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new uT(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=mT(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=mT(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>sT(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=h.basename(e,h.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(b.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
403
- Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function gT(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function _T(){if(b.env.NO_COLOR||b.env.FORCE_COLOR===`0`||b.env.FORCE_COLOR===`false`)return!1;if(b.env.FORCE_COLOR||b.env.CLICOLOR_FORCE!==void 0)return!0}new hT;const vT=[],yT=e=>Array.isArray(e)?e:[e],Q=(e,t,n,r,i)=>{if(t.json){let t={data:r,ok:!0,warnings:i??vT};e.out(JSON.stringify(t));return}for(let t of yT(n))e.out(t);for(let t of i??vT)e.errLine(`refs: warning: ${t}`)},bT=(e,t,n)=>{if(t.json){let t={error:{code:n.code,message:n.message},ok:!1};e.out(JSON.stringify(t));return}e.errLine(`refs: ${n.message}`)},$=(e,t,n)=>async()=>{try{await n()}catch(n){let r=ct(n,{verbose:t.verbose});bT(e,t,r),process.exitCode=r.exitCode}};var xT=`0.1.1`;const ST=async e=>{let t=await e.runner.run(`git`,[`--version`]);return t.exitCode===0?{detail:t.stdout.trim(),name:`git`,status:`ok`}:{detail:t.stderr.trim()||`git --version exited with code ${t.exitCode}`,name:`git`,status:`fail`}},CT=/^v(?<major>\d+)\.(?<minor>\d+)/u,wT=e=>{let t=CT.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(!(n===void 0||r===void 0))return{major:Number(n),minor:Number(r)}},TT=e=>e===void 0?!1:e.major===24&&e.minor>=12,ET=e=>{let{nodeVersion:t}=e;return TT(wT(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.12 <25`,name:`node`,status:`fail`}},DT=e=>e instanceof Error?e.message:String(e),OT=()=>tc.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),kT=async e=>{try{return{config:await H(e)}}catch(e){return{config:OT(),errorMessage:DT(e)}}},AT=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},jT=[`.claude`,`skills`,`refs`,`SKILL.md`],MT=[`.codex`,`skills`,`refs`,`SKILL.md`],NT=e=>e===void 0?[]:[y(e,...jT),y(e,...MT)],PT=async e=>{try{return await t(e),!0}catch{return!1}},FT=async e=>{let t=NT(e.env.HOME);return(await Promise.all(t.map(e=>PT(e)))).some(Boolean)?{detail:`the refs skill is installed`,name:`skill`,status:`ok`}:{detail:`refs skill not found — install it: npx skills add kaisers-io/refs`,name:`skill`,status:`warn`}},IT=(e,t)=>Object.keys(t.refs).map(t=>({dest:V(e,Us.parse(t)),key:t})).filter(e=>U(e.dest)),LT=[`pre-commit`,`pre-push`],RT=async(e,n)=>{try{return await t(y(e.hooksDir,n),r.X_OK),!0}catch{return!1}},zT=async e=>{let t=await Promise.all(LT.map(t=>RT(e,t)));return LT.filter((e,n)=>!t[n])},BT=async(e,t,n)=>{let r=await e.runner.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:n});return r.exitCode===0&&r.stdout.trim()===t.hooksDir},VT=e=>e.missingHooks.length>0?{detail:`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`,name:`hooks-guard`,status:`fail`}:e.badKeys.length>0?{detail:`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`,name:`hooks-guard`,status:`fail`}:{detail:`${LT.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`},HT=async(e,t,n)=>{let r=IT(t,n),[i,a]=await Promise.all([zT(t),Promise.all(r.map(n=>BT(e,t,n.dest)))]),o=r.filter((e,t)=>!a[t]).map(e=>e.key);return VT({badKeys:o,checkoutCount:r.length,missingHooks:i})},UT=async(e,t)=>{let n=await e.runner.run(`git`,[`status`,`--porcelain`],{cwd:t.dest});return n.exitCode===0?{broken:!1,detail:``,dirty:n.stdout.trim()!==``,key:t.key}:{broken:!0,detail:n.stderr.trim(),dirty:!1,key:t.key}},WT=e=>{let t=e.filter(e=>e.broken);if(t.length>0)return{detail:t.map(e=>`${e.key}: git status failed — ${e.detail}`).join(`; `),name:`dirty-checkouts`,status:`fail`};let n=e.filter(e=>e.dirty).map(e=>e.key);return n.length===0?{detail:`no local changes in any checkout`,name:`dirty-checkouts`,status:`ok`}:{detail:`local changes will be discarded on next sync: ${n.join(`, `)}`,name:`dirty-checkouts`,status:`warn`}},GT=async(e,t,n)=>{let r=IT(t,n),i=await Promise.all(r.map(t=>UT(e,t)));return WT(i)},KT=async e=>{try{return await Z(e)}catch{return Aw.parse({})}},qT=async e=>{try{return(await c(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(Lc(e))return[];throw e}},JT=async(e,t)=>{if(U(e))return[[...t]];let n=await qT(e);return(await Promise.all(n.map(n=>JT(y(e,n),[...t,n])))).flat()},YT=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r===void 0?!1:n-Date.parse(r)<864e5},XT=(e,t,n)=>YT(t,e.key,n)?`${e.key}: pending add`:`${e.key}: orphan — remove with: rm -rf ${e.dest}`,ZT=(e,t)=>({dest:y(e.sourcesDir,...t),key:t.join(`/`)}),QT=async(e,t,n)=>{let r=(await JT(e.sourcesDir,[])).map(t=>ZT(e,t)).filter(e=>!Object.hasOwn(t.refs,e.key));if(r.length===0)return{detail:`no orphaned checkouts under sources/`,name:`orphans`,status:`ok`};let i=Date.now();return{detail:r.map(e=>XT(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},$T=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,eE=e=>e===``?{}:{user:e},tE=e=>e===``?{}:{port:e},nE=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...eE(t.username),...tE(t.port)}:void 0}catch{return}},rE=e=>{let t=$T.exec(e),n=t?.groups?.host;return n===void 0?nE(e):{host:n,user:t?.groups?.user??`git`}},iE=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,aE=e=>e.user===void 0?iE(e):`${e.user}@${iE(e)}`,oE=e=>{let t=Object.values(e.refs).map(e=>rE(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(aE(e),e);return[...n.values()].toSorted((e,t)=>aE(e).localeCompare(aE(t)))},sE=/Permission denied/u,cE=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],lE=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,uE=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=lE(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},dE=async(e,t,n)=>{let r=aE(t),i=await e.runner.run(`ssh`,uE(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:sE.test(i.stderr)?{host:r,outcome:`denied`}:cE.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},fE=(e,t)=>{let n=e.filter(e=>e.outcome===`timeout`).map(e=>e.host);if(n.length!==0)return{detail:`ssh probe timed out after ${t/1e3}s: ${n.join(`, `)}`,name:`ssh-auth`,status:`fail`}},pE=e=>{let t=e.filter(e=>e.outcome===`denied`).map(e=>e.host);if(t.length!==0)return{detail:`ssh permission denied for: ${t.join(`, `)}`,name:`ssh-auth`,status:`fail`}},mE=e=>{let t=e.filter(e=>e.outcome===`connection-warn`);if(t.length!==0)return{detail:`ssh connection issue, treated as warn: ${t.map(e=>`${e.host} (${e.detail??``})`).join(`; `)}`,name:`ssh-auth`,status:`warn`}},hE=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),gE=(e,t)=>fE(e,t)??pE(e)??mE(e)??hE(e),_E=async(e,t,n)=>{let r=oE(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>dE(e,t,i)));return gE(a,i)},vE=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${DT(t)}`,name:e.name,status:`fail`}}},yE=async e=>{let[t,...n]=e;if(t===void 0)return[];let r=await vE(t),i=await yE(n);return r===void 0?i:[r,...i]},bE=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>ST(n)},{name:`node`,run:()=>Promise.resolve(ET(n))},{name:`config`,run:()=>Promise.resolve(AT(t.errorMessage))},{name:`hooks-guard`,run:()=>HT(n,r,t.config)},{name:`dirty-checkouts`,run:()=>GT(n,r,t.config)},{name:`orphans`,run:()=>QT(r,t.config,i)},{name:`skill`,run:()=>FT(n)},{name:`ssh-auth`,run:()=>_E(n,t.config)}]},xE=async e=>{let t=B(e.env),n=await kT(t),r=await KT(t);return yE(bE({configLoad:n,ctx:e,home:t,state:r}))},SE={fail:`FAIL`,ok:`OK`,warn:`WARN`},CE=e=>e.map(e=>`[${SE[e.status]}] ${e.name}: ${e.detail}`),wE=e=>e.some(e=>e.status===`fail`),TE=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, ssh).`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await xE(t);Q(t,i,CE(e),{checks:e}),wE(e)&&(process.exitCode=it.UNEXPECTED)})()})},EE=async e=>{let t=B(e.env),n=await G(t,`home`,()=>sl(t,xT));return n===`migrated`?{backup:zc(t),result:n}:{backup:null,result:n}},DE=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${g(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,OE=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await EE(t);Q(t,i,DE(e),e)})()})},kE=(e,t,n)=>e===void 0?!0:n-Date.parse(e)>t,AE=(e,t,n)=>{let r=e.state.refs[t],i=Gs(jw(`sync_ttl`,n,e.settings));return{clone_mode:jw(`clone_mode`,n,e.settings),description:n.description,key:t,missing:!U(V(e.home,Us.parse(t))),packages:Object.keys(n.packages??{}).toSorted(),stale:kE(r?.last_fetched_at,i,e.now)}},jE=e=>{let t={home:e.home,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>AE(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},ME=async e=>{let t=B(e.env),n=await H(t),r=await Z(t);return jE({config:n,home:t,now:Date.now(),state:r})},NE=e=>{let t=[];return e.stale&&t.push(`[stale]`),e.missing&&t.push(`[missing]`),t.length===0?``:` ${t.join(` `)}`},PE=e=>e.length===0?[`no refs configured — run: refs add <source>`]:e.map(e=>`${e.key} ${e.description}${NE(e)}`),FE=e=>e.split(`/`),IE=(e,t)=>{let n=FE(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},LE=(e,t)=>{if(Object.hasOwn(e.refs,t))return Us.parse(t);let n=FE(t),r=Object.keys(e.refs).filter(e=>IE(e,n)).toSorted(),[i]=r;if(i===void 0)throw C(`no ref matches '${t}'`);if(r.length>1)throw w(`'${t}' matches more than one ref: ${r.join(`, `)}`);return Us.parse(i)},RE=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await ME(t);Q(t,i,PE(e),e)})()})},zE=e=>`ref:${e.replaceAll(`/`,`_`)}`,BE=e=>e.REFS_ALLOW_FILE_URLS===`1`,VE=(e,t)=>{let n=uu(t,{allowFileUrls:BE(e.env)});return{cloneUrl:n.cloneUrl,key:n.key}},HE=async(e,t)=>{if(t===``)throw w(`refs add npm: requires a package name, e.g. npm:left-pad`);let n=await fd(e.fetcher,t),r={cloneUrl:n.cloneUrl,key:n.key,npmPkgName:t};return n.directory!==void 0&&(r.npmDirectory=n.directory),r},UE=(e,t)=>t.startsWith(`npm:`)?HE(e,t.slice(4)):Promise.resolve(VE(e,t)),WE=(e,t)=>{if(e.npmPkgName===void 0)return e;let n=jw(`git_transport`,void 0,t);return{...e,cloneUrl:Su(e.cloneUrl,n)}},GE=e=>`ref '${e}' already exists — use refs edit or refs remove`,KE=(e,t)=>{if(e.refs[t]!==void 0)throw ot(GE(t))},qE=async e=>{try{return await c(e,{withFileTypes:!0})}catch(e){if(Lc(e))return;throw e}},JE=e=>e.filter(e=>e.isDirectory()).map(e=>e.name),YE=async(e,t)=>{let n=await qE(e);if(n===void 0)return{kind:`stop`};let r=JE(n);if(r.includes(t))return{kind:`continue`,nextDir:y(e,t)};let i=r.find(e=>e.toLowerCase()===t.toLowerCase());return i===void 0?{kind:`stop`}:{kind:`collision`,name:i}},XE=async(e,t,n)=>{let[r,...i]=t;if(r===void 0)return;let a=await YE(e,r);if(a.kind!==`stop`)return a.kind===`collision`?[...n,a.name].join(`/`):XE(a.nextDir,i,[...n,r])},ZE=[],QE=async(e,t)=>{let n=await XE(e.sourcesDir,t.split(`/`),ZE);if(n!==void 0)throw ot(`checkout path for '${t}' collides case-insensitively with existing '${n}'`)},$E=[],eD=e=>e===void 0?$E:[e],tD=async e=>{try{return await a(e),!0}catch(e){if(Lc(e))return!1;throw e}},nD=async e=>{try{return await c(e)}catch(e){if(Lc(e))return;throw e}},rD=async e=>{try{return(await a(e)).isDirectory()}catch(e){if(Lc(e))return;throw e}},iD=async e=>{let t=await nD(e);if(t===void 0)return!0;if(t.length!==0)return!1;try{await f(e)}catch(e){if(!Lc(e))throw e}return!0},aD=async e=>{let t=await rD(e);return t===void 0?!0:t?iD(e):!1},oD=async(e,t)=>{t!==e.sourcesDir&&await aD(t)&&await oD(e,_(t))},sD=async(e,t)=>await tD(t)?(Hc(e,t),await d(t,{force:!0,recursive:!0}),await oD(e,_(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},cD=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),lD=async(e,t)=>{let n=await H(e);await Xc(e,{...n,refs:cD(n.refs,t)});let r=await Z(e);await Pw(e,{...r,refs:cD(r.refs,t)})},uD=async(e,t)=>{let n=B(e.env),r=LE(await H(n),t),i=V(n,r),{removedCheckout:a,warning:o}=await G(n,zE(r),()=>sD(n,i));return await G(n,`home`,()=>lD(n,r)),{data:{key:r,removed_checkout:a},warnings:eD(o)}},dD=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],fD=(e,t)=>{e.command(`remove`).description(`Remove a configured ref: its config/state entry AND its checkout directory.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await uD(t,e);Q(t,a,dD(n),n,r)})()})},pD=e=>`no ref matches '${e}' — run refs list, or add it: refs add <url>`,mD=/^[a-z][a-z0-9+.-]*:\/\//iu,hD=/^git@[^:/\s]+:[^\s]+$/u,gD=e=>mD.test(e)||hD.test(e),_D=(e,t)=>{try{return uu(e,t)}catch{if(gD(e))throw T(`query looks like a git url but is not a supported form — check the url (credentials are never accepted) or run: refs resolve <package|ref-suffix>`);return}},vD=(e,t,n)=>{let r=_D(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw C(pD(t))}},yD=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages?.[t];i!==void 0&&n.push({entry:i,key:Us.parse(r)})}return n},bD=(e,t)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — use the full ref key`,xD=(e,t)=>{let n=yD(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw w(bD(t,n.map(e=>e.key)));return r}},SD=(e,t)=>{let n=t.split(`/`);for(let t=n.length-1;t>=1;--t){let r=n.slice(0,t).join(`/`),i=xD(e,r);if(i!==void 0)return{...i,name:r}}},CD=(e,t)=>{try{return LE(e,t)}catch(e){throw e instanceof at&&e.code===`not_found`?C(pD(t)):e}},wD=(e,t,n)=>{let r=vD(e,t,n);if(r!==void 0)return r;let i=xD(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=SD(e,t);return a===void 0?{key:CD(e,t)}:{key:a.key,packageMatch:a}},TD=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: resolved ref key '${t}' is missing from config.refs`);return n},ED=(e,t)=>{if(e.packageMatch===void 0)return null;let{entry:n,name:r}=e.packageMatch;return{local_path:y(t,n.path),name:r,path:n.path}},DD=async(e,t)=>{let n=B(e.env),r=await H(n),i=wD(r,t,{allowFileUrls:BE(e.env)}),a=TD(r,i.key),o=await Z(n),s=V(n,i.key),c=Gs(jw(`sync_ttl`,a,r.settings));return{key:i.key,local_path:s,missing:!U(s),package:ED(i,s),stale:kE(o.refs[i.key]?.last_fetched_at,c,Date.now())}},OD=e=>{let t=[e.key,`local_path: ${e.local_path}`];return e.package!==null&&t.push(`package: ${e.package.name}`,`local_path: ${e.package.local_path}`),t},kD=(e,t)=>{e.command(`resolve`).description(`Resolve a git url, npm package name, import path, or ref-key suffix to its ref/package.`).argument(`<query>`,`git url, npm package name, import path, or unique ref-key suffix`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let n=await DD(t,e);Q(t,a,OD(n),n)})()})},AD={},jD=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},MD=e=>e instanceof Error?e.message:String(e),ND=async(e,t)=>{if(!U(t))return{tags:[]};try{return{tags:await Ol(e.runner,t,5)}}catch(e){return{tags:[],warning:`could not list tags: ${MD(e)}`}}},PD=[],FD=e=>e===void 0?PD:[e],ID=async(e,t)=>{let n=B(e.env),r=await H(n),i=LE(r,t),a=jD(r,i),o=await Z(n),s=V(n,i),{tags:c,warning:l}=await ND(e,s);return{data:{...a,key:i,local_path:s,sample_tags:c,state:o.refs[i]??AD},warnings:FD(l)}},LD=e=>{let t=[`${e.key} ${e.description}`,`url: ${e.url}`,`local_path: ${e.local_path}`];return e.sample_tags.length>0&&t.push(`tags: ${e.sample_tags.join(`, `)}`),t},RD=(e,t)=>{e.command(`show`).description(`Show a configured ref: full entry, state, local path, and sample tags.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await ID(t,e);Q(t,a,LD(n),n,r)})()})},zD=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:new Date().toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},BD=async(e,t,n)=>{let r=await H(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await Xc(e,r))},VD=(e,t,n)=>G(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await BD(e,t,n.branchRenamedTo);let r=await Z(e);r.refs[t]=zD(r.refs[t],n),await Pw(e,r)}),HD=async(e,t,n)=>{try{await G(e,`home`,async()=>{let r=await Z(e);r.refs[t]={...r.refs[t],last_error:n},await Pw(e,r)})}catch{}},UD=e=>{let t=0,n=[];return{acquire:()=>{if(t<e)return t+=1,Promise.resolve();let{promise:r,resolve:i}=Promise.withResolvers();return n.push(()=>{t+=1,i()}),r},release:()=>{--t;let e=n.shift();e!==void 0&&e()}}},WD=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},GD=(e,t,n)=>`checkout at ${e} points at '${W(t)}' — expected '${W(n)}'; remove the checkout directory or run refs remove before retrying`,KD=e=>e.exitCode===0?e.stdout.trim():`(no origin remote)`,qD=(e,t)=>{try{return uu(e,{allowFileUrls:t}).key}catch{return}},JD=async(e,t)=>{let n=await e.run(`git`,[`remote`,`get-url`,`origin`],{cwd:t.dest}),r=KD(n),i=qD(t.expectedUrl,t.allowFileUrls),a=qD(r,t.allowFileUrls);if(!(i!==void 0&&a===i))throw ot(GD(t.dest,r,t.expectedUrl))},YD=e=>`checkout at ${e} exists but is not refs-managed — remove it (rm -rf ${e}) and retry`,XD=async(e,t)=>{let n=await e.run(`git`,[`config`,`--local`,`core.hooksPath`],{cwd:t.dest});if(n.exitCode!==0||n.stdout.trim()!==t.hooksDir)throw ot(YD(t.dest))},ZD=async(e,t)=>{if(Hc(t.home,t.dest),U(t.dest))return await JD(e,{allowFileUrls:t.allowFileUrls,dest:t.dest,expectedUrl:t.cloneUrl}),await XD(e,{dest:t.dest,hooksDir:t.hooksDir}),{};await o(_(t.dest),{recursive:!0});let n=await yl(e,t);return n.warning===void 0?{effectiveMode:n.effectiveMode}:{effectiveMode:n.effectiveMode,warning:n.warning}},QD=(e,t)=>`checkout for '${e}' at ${t} is missing or corrupt (git rev-parse HEAD failed) — run: refs remove ${e}, then refs add <source> --dry-run again`,$D=(e,t,n)=>`checkout for '${e}' at ${t} has a HEAD sha refs cannot store yet (${n.length} hex chars, expected 40) — only SHA-1 repositories are supported for now; \`--object-format=sha256\` repositories are not yet supported`,eO=async(e,t)=>{await JD(e,t),await XD(e,{dest:t.dest,hooksDir:t.hooksDir});let n=await e.run(`git`,[`rev-parse`,`HEAD`],{cwd:t.dest});if(n.exitCode!==0)throw T(QD(t.key,t.dest));let r=n.stdout.trim();if(!kw.shape.head_sha.safeParse(r).success)throw T($D(t.key,t.dest,r));return r},tO=(e,t,n)=>`sync produced a HEAD sha for '${e}' at ${t} that refs cannot store yet (${n.length} hex chars) — only SHA-1 repositories are supported for now`,nO=(e,t,n)=>{if(!kw.shape.head_sha.safeParse(n).success)throw T(tO(e,t,n));return n},rO=(e,t,n)=>{let r={effectiveCloneMode:t.effectiveMode,headSha:n.headSha,status:`cloned`};return n.actualBranch!==e.ref.default_branch&&(r.branchRenamedTo=n.actualBranch),t.warning!==void 0&&(r.warning=t.warning),r},iO=async(e,t,n)=>{await o(_(n),{recursive:!0});let r=jw(`clone_mode`,t.ref,t.settings),i=await yl(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),a=await xl(e.runner,n),s=await eO(e.runner,{allowFileUrls:BE(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return rO(t,i,{actualBranch:a,headSha:s})},aO=async(e,t,n)=>{await XD(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await JD(e.runner,{allowFileUrls:BE(e.env),dest:n,expectedUrl:t.ref.url});let r=await Dl(e.runner,{defaultBranch:t.ref.default_branch,dir:n}),i={headSha:nO(t.key,n,r.newSha),status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},oO=(e,t)=>G(t.home,zE(t.key),()=>{let n=V(t.home,t.key);return Hc(t.home,n),U(n)?aO(e,t,n):iO(e,t,n)}),sO=e=>e instanceof Error?e.message:String(e),cO=e=>{let t=[];e.branchRenamedTo!==void 0&&t.push(`default branch renamed to ${e.branchRenamedTo}`),e.warning!==void 0&&t.push(e.warning);let[n]=t;if(n!==void 0)return t.join(` | `)},lO=(e,t)=>{let n={key:e,status:t.status},r=cO(t);return r!==void 0&&(n.warning=r),n},uO=async(e,t)=>{try{let n=await oO(e,t);return await VD(t.home,t.key,n),lO(t.key,n)}catch(e){let n=sO(e);return await HD(t.home,t.key,n),{error:n,key:t.key,status:`failed`}}},dO=(e,t)=>e.status===`fulfilled`?e.value:{error:sO(e.reason),key:t,status:`failed`},fO=async(e,t)=>{let n=UD(4);return(await Promise.allSettled(t.map(t=>WD(n,()=>uO(e,t))))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return dO(e,r.key)})},pO=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},mO=(e,t,n)=>({home:e,key:n,ref:pO(t,n),settings:t.settings}),hO=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>mO(e,t,Us.parse(n))):n.map(n=>mO(e,t,LE(t,n))),gO=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=Gs(jw(`sync_ttl`,t.ref,t.settings)),a=kE(n.refs[t.key]?.last_fetched_at,i,r),o=!U(V(e,t.key));return a||o})},_O=async(e,t,n)=>{if(!n)return t;let r=await Z(e);return gO(e,t,r)},vO=async(e,t)=>{let n=B(e.env),r=await H(n),i=hO(n,r,t.refs),a=await fO(e,await _O(n,i,t.staleOnly));return{failedCount:a.filter(e=>e.status===`failed`).length,results:a}},yO=[`updated`,`fresh`,`cloned`,`restored`,`failed`],bO={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},xO=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},SO=e=>e.status===`failed`?` ${e.key}: ${e.error??`unknown error`}`:e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`,CO=e=>{let t=xO(e),n=[yO.map(e=>`${bO[e]} (${t[e].length})`).join(` / `)];for(let e of yO)for(let r of t[e])n.push(SO(r));return n},wO=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),TO=(e,t)=>{e.command(`sync`).description(`Fetch (or re-clone, if the checkout is missing) configured refs — all by default.`).argument(`[refs...]`,`ref keys or unique suffixes to sync (default: every configured ref)`).option(`--stale-only`,`skip refs whose last sync is still within their ref's sync_ttl`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let r=await vO(t,wO(e,n));Q(t,a,CO(r.results),{results:r.results}),r.failedCount>0&&(process.exitCode=it.UNEXPECTED)})()})},EO=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},DO=(e,t,n)=>{if(n===void 0)return e.tag_format;let r=e.packages?.[n];if(r===void 0)throw C(`no package '${n}' registered on ref '${t}'`);return r.tag_format??e.tag_format},OO=(e,t)=>{if(!U(e))throw C(`checkout for '${t}' is missing — run: refs sync ${t}`)},kO=async(e,t)=>{let n=B(e.env),r=await H(n),i=LE(r,t.query),a=EO(r,i),o=DO(a,i,t.opts.packageName),s=V(n,i);OO(s,i);let c=await Ul(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},AO=e=>[`${e.key}@${e.version} -> ${e.tag}`],jO=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},MO=[TE,OE,fD,kD,RD,TO,(e,t)=>{e.command(`tag`).description(`Resolve a version to its git tag, via the ref's (or a package's) tag_format.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).argument(`<version>`,`version to resolve, e.g. 15.3.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=i.optsWithGlobals(),o={json:a.json===!0,verbose:a.verbose===!0};return $(t,o,async()=>{let i=await kO(t,{opts:jO(r),query:e,version:n});Q(t,o,AO(i),i)})()})}],NO=e=>e.description===void 0?{path:e.path}:{description:e.description,path:e.path},PO=(e,t,n)=>e.length>0?Object.fromEntries(e.map(e=>[e.name,NO(e)])):n===void 0?{}:{[n]:{path:t??`.`}},FO=(e,t)=>{let n=e.description??t;return e.tag_format===void 0?{description:n,path:e.path}:{description:n,path:e.path,tag_format:e.tag_format}},IO=(e,t)=>{let n=Object.entries(e);if(n.length!==0)return Object.fromEntries(n.map(([e,n])=>[e,FO(n,t)]))},LO=e=>{if(Object.keys(e).length!==0)return e},RO=e=>{if(e===null)throw T(`tag_format_candidate must be set to a valid tag format (containing '{version}') before finalizing — edit the proposal and provide one, or add the ref manually`);return e},zO=e=>e.packages===void 0?{default_branch:e.default_branch,description:e.description,tag_format:e.tag_format,url:e.url}:{default_branch:e.default_branch,description:e.description,packages:e.packages,tag_format:e.tag_format,url:e.url},BO=[],VO=e=>e===void 0?[...BO]:[e],HO=async(e,t,n)=>{let r=await xl(e,t),i=Vl(await Ol(e,t));return{defaultBranch:r,packages:PO(await tT(t),n.npmDirectory,n.npmPkgName),tagFormatCandidate:i}},UO=(e,t)=>G(t.home,zE(t.resolved.key),async()=>{let n=await ZD(e.runner,{allowFileUrls:BE(e.env),cloneUrl:t.resolved.cloneUrl,dest:t.dest,home:t.home,hooksDir:t.home.hooksDir,mode:t.cloneMode}),r={fields:await HO(e.runner,t.dest,t.resolved)};return n.effectiveMode!==void 0&&(r.effectiveMode=n.effectiveMode),n.warning!==void 0&&(r.warning=n.warning),r}),WO=e=>{let t={default_branch:e.cloneResult.fields.defaultBranch,description:``,key:e.resolved.key,packages:e.cloneResult.fields.packages,tag_format_candidate:e.cloneResult.fields.tagFormatCandidate,url:e.resolved.cloneUrl},n={dest:e.dest,proposal:t};return e.cloneResult.effectiveMode!==void 0&&(n.effectiveCloneMode=e.cloneResult.effectiveMode),e.cloneResult.warning!==void 0&&(n.warning=e.cloneResult.warning),n},GO=async(e,t)=>{let n=B(e.env),r=await H(n),i=WE(await UE(e,t),r.settings);KE(r,i.key),await QE(n,i.key);let a=V(n,i.key),o=jw(`clone_mode`,void 0,r.settings),s=await UO(e,{cloneMode:o,dest:a,home:n,resolved:i});return WO({cloneResult:s,dest:a,resolved:i})},KO=(e,t,n)=>G(e,`home`,async()=>{KE(await H(e),t);let r=await Z(e),i=r.refs[t],a=n??i?.effective_clone_mode,o={...i,pending_proposal_at:new Date().toISOString()};a!==void 0&&(o.effective_clone_mode=a),r.refs[t]=o,await Pw(e,r)}),qO=(e,t)=>{let n=tc.safeParse(e);if(!n.success)throw T(k(n.error));let r=Aw.safeParse(t);if(!r.success)throw T(k(r.error));return{config:n.data,state:r.data}},JO=async(e,t)=>{let n=await H(e.home);KE(n,e.ref.key);let r=zO(e.ref);n.refs[e.ref.key]=r;let i=await Z(e.home);return i.refs[e.ref.key]={effective_clone_mode:e.effectiveCloneMode??i.refs[e.ref.key]?.effective_clone_mode??jw(`clone_mode`,void 0,n.settings),head_sha:t,last_fetched_at:new Date().toISOString()},{...qO(n,i),entry:r}},YO=async(e,t)=>{let n=BE(e.env),r=await G(t.home,zE(t.ref.key),()=>(Hc(t.home,t.dest),eO(e.runner,{allowFileUrls:n,dest:t.dest,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.ref.key})));return G(t.home,`home`,async()=>{let{config:e,entry:n,state:i}=await JO(t,r);return await Pw(t.home,i),await Xc(t.home,e),{entry:n,key:t.ref.key}})},XO=(e,t)=>t===`-`?e.readStdin():s(t,`utf8`),ZO=e=>e instanceof Error?e.message:String(e),QO=e=>{try{return JSON.parse(e)}catch(e){throw T(`invalid JSON in proposal: ${ZO(e)}`)}},$O=e=>{let t=Ow.safeParse(e);if(!t.success)throw T(k(t.error));return t.data},ek=async(e,t)=>{let n=await XO(e,t);return $O(QO(n))},tk=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],nk=async(e,t)=>{let n=await GO(e,t);await KO(B(e.env),n.proposal.key,n.effectiveCloneMode);let r=VO(n.warning);return{data:n.proposal,human:tk(n.proposal.key,n.dest),warnings:r}},rk=e=>[`refs add: '${e}' added to config`],ik=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,tag_format:RO(e.tag_format_candidate),url:e.url},n=LO(e.packages);return n!==void 0&&(t.packages=n),t},ak=async(e,t)=>{let n=await ek(e,t),r=B(e.env),i=V(r,n.key);if(!U(i))throw C(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let{entry:a,key:o}=await YO(e,{dest:i,home:r,ref:ik(n)});return{data:{entry:a,key:o},human:rk(o),warnings:[]}},ok=(e,t)=>{let n={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,tag_format:RO(e.proposal.tag_format_candidate),url:e.proposal.url},r=IO(e.proposal.packages,t);return r!==void 0&&(n.packages=r),n},sk=async(e,t,n)=>{let r=await GO(e,t),i=B(e.env),a=ok(r,n),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await YO(e,o),l=VO(r.warning);return{data:{entry:s,key:c},human:rk(c),warnings:l}},ck=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw w(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw w(`refs add needs --dry-run, --proposal, or --description`)},lk=e=>{if(e===void 0||e===``)throw w(`refs add requires <source> (a git url or npm:<package>)`);return e},uk=(e,t)=>(ck(t),t.proposal===void 0?t.description===void 0?nk(e,lk(t.source)):sk(e,lk(t.source),t.description):ak(e,t.proposal)),dk=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},fk=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let r=await uk(t,dk(e,n));Q(t,a,r.human,r.data,r.warnings)})()})},pk=e=>e===void 0?null:e,mk=()=>Object.keys($s.shape).toSorted().join(`, `),hk=e=>`unknown package field '${e}' — valid fields: ${mk()}`,gk=e=>Object.hasOwn($s.shape,e),_k=(e,t,n)=>{let r=e.packages?.[n];if(r===void 0)throw C(`no package '${n}' registered on ref '${t}'`);return r},vk=(e,t,n)=>{if(!gk(t))throw w(hk(t));let r=e[t],i=$s.safeParse({...e,[t]:n});if(!i.success)throw T(k(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},yk=async e=>{let t=_k(e.entry,e.key,e.packageName),n=vk(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await Xc(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:pk(n.newValue),old:pk(n.oldValue)}},bk=`packages`,xk=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Sk=()=>Object.keys(ec.shape).filter(e=>e!==bk).toSorted().join(`, `),Ck=e=>`unknown ref field '${e}' — valid fields: ${Sk()}`,wk=e=>Object.hasOwn(ec.shape,e),Tk=(e,t,n)=>`failed to rewrite git remote at ${e} to '${W(t)}': ${n.trim()}`,Ek=async(e,t)=>{if(Hc(t.home,t.dest),!U(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw T(Tk(t.dest,t.cloneUrl,n.stderr))},Dk=async(e,t)=>{let n=uu(t.value,{allowFileUrls:BE(e.env)});if(n.key!==t.key)throw T(`new url derives a different key — remove and re-add instead`);let r=V(t.home,t.key);return await Ek(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},Ok=(e,t,n)=>{let r={...e,[t]:n},i=ec.safeParse(r);if(!i.success)throw T(k(i.error));return i.data},kk=(e,t)=>t.field===`url`?Dk(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(Ok(t.entry,t.field,t.value)),Ak=async(e,t)=>{let{field:n}=t;if(n===bk)throw w(`use --package <name> <field> <value>`);if(!wk(n))throw w(Ck(n));let r=t.entry[n],i=await kk(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},jk=(e,t)=>{let n=B(e.env),{field:r,opts:i,query:a,value:o}=t;return G(n,`home`,async()=>{let t=await H(n),s=LE(t,a),c=xk(t,s);if(i.packageName!==void 0)return yk({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await Ak(e,{entry:c,field:r,home:n,key:s,value:o});return await Xc(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:pk(l.new),old:pk(l.old)}})},Mk=`settings`,Nk=[],Pk=()=>Object.keys(Zs.shape).toSorted().join(`, `),Fk=e=>`unknown setting '${e}' — valid settings: ${Pk()}`,Ik=e=>Object.hasOwn(Zs.shape,e),Lk=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,Rk=e=>{try{let t=LE(e,Mk);return[Lk(`ref '${t}'`)]}catch(e){if(e instanceof at&&e.code===`usage`)return[Lk("one of several matching refs — see `refs list`")];if(e instanceof at&&e.code===`not_found`)return Nk;throw e}},zk=e=>({data:{field:e.key,key:Mk,new:pk(e.parsed[e.key]),old:pk(e.old)},warnings:Rk(e.config)}),Bk=(e,t)=>{let n=B(e.env);return G(n,`home`,async()=>{let e=await H(n);if(!Ik(t.key))throw w(Fk(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=Zs.safeParse(i);if(!a.success)throw T(k(a.error));return await Xc(n,{...e,settings:a.data}),zk({config:e,key:t.key,old:r,parsed:a.data})})},Vk=[],Hk=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},Uk=async(e,t)=>{if(t.first===`settings`){if(t.opts.packageName!==void 0)throw w(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return Bk(e,{key:t.second,value:t.value})}return{data:await jk(e,{field:t.second,opts:t.opts,query:t.first,value:t.value}),warnings:Vk}},Wk=e=>e==null?`(unset)`:String(e),Gk=e=>[`${e.key}: ${e.field} '${Wk(e.old)}' -> '${Wk(e.new)}'`],Kk=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`<field-or-key>`,`field to edit (or, in settings mode, the setting key)`).argument(`<value>`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).action((e,n,r,i,a)=>{let o=a.optsWithGlobals(),s={json:o.json===!0,verbose:o.verbose===!0};return $(t,s,async()=>{let{data:a,warnings:o}=await Uk(t,{first:e,opts:Hk(i),second:n,value:r});Q(t,s,Gk(a),a,o)})()})},qk=`Install the agent skill: npx skills add kaisers-io/refs (private phase: npx skills add <path-to-this-repo> --skill refs)`,Jk=async e=>{await o(e.root,{recursive:!0}),await o(e.sourcesDir,{recursive:!0}),await o(e.locksDir,{recursive:!0}),await o(e.hooksDir,{recursive:!0})},Yk=async e=>{let t=B(e.env);return await Jk(t),{config:await G(t,`home`,async()=>{let e=await sl(t,xT);return await jl(t),e}),home:t.root,skill_hint:qk}},Xk=[(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Yk(t);Q(t,i,[`refs home: ${e.home} (${e.config})`,qk],e)})()})},fk,Kk,RE,...MO],Zk=(e,t)=>{for(let n of Xk)n(e,t)},Qk=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve next/navigation --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
404
- `),$k=new Set([`commander.help`,`commander.helpDisplayed`,`commander.version`]),eA=`--json`,tA=`--verbose`,nA=/\n$/u,rA=/^error: /u,iA=e=>e.replace(rA,``),aA=(e,t)=>{for(let n of e){if(n===`--`)return!1;if(n===t)return!0}return!1},oA=e=>aA(e,eA),sA=e=>aA(e,tA),cA=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,lA=e=>{let t=new hT().name(`refs`).description(`Manage git-based reference checkouts shared across a workspace.`).version(xT).option(eA,`emit machine-readable JSON on stdout instead of human-readable text`).option(tA,`include stack traces in error output`).allowExcessArguments(!1).exitOverride().configureOutput({outputError:()=>{},writeErr:t=>{e.errLine(t.replace(nA,``))},writeOut:t=>{e.out(t.replace(nA,``))}});return t.addHelpText(`after`,Qk),Zk(t,e),t},uA=()=>{process.exitCode=it.OK},dA=(e,t,n)=>{bT(e,t,{code:`usage`,message:cA(iA(n.message),n.stack,t.verbose)}),process.exitCode=it.USAGE},fA=(e,t,n)=>{if($k.has(n.code)){uA();return}dA(e,t,n)},pA=(e,t,n)=>{let r=ct(n,{verbose:t.verbose});bT(e,t,r),process.exitCode=r.exitCode},mA=async(e,t,n)=>{let r={json:oA(n),verbose:sA(n)};try{await t.parseAsync(n)}catch(t){if(t instanceof iT){fA(e,r,t);return}pA(e,r,t)}},hA=(e,t)=>mA(e,lA(e),t);import.meta.main&&await hA(rT(),process.argv);export{lA as buildProgram,Q as emit,bT as emitError,rT as realContext,Zk as registerCommands,hA as run,mA as runProgram,$ as wrapAction};
366
+ - ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=p.resolve(e,t);if(ce.existsSync(r))return r;if(n.includes(p.extname(t)))return;let i=n.find(e=>ce.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=ce.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=p.resolve(p.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=p.basename(this._scriptPath,p.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(p.extname(i)),s;h.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=Cd(h.execArgv).concat(t),s=he.spawn(h.execPath,t,{stdio:`inherit`})):o?(t.unshift(i),t=Cd(h.execArgv).concat(t),s=he.spawn(h.argv[0],t,{stdio:`inherit`})):s=he.spawn(i,t,{stdio:`inherit`}),s.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{h.on(e,()=>{s.killed===!1&&s.exitCode===null&&s.kill(e)})});let c=this._exitCallback;s.on(`close`,e=>{e??=1,c?c(new dd(e,`commander.executeSubCommandAsync`,`(close)`)):h.exit(e)}),s.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(i,a,e._name);else if(t.code===`EACCES`)throw Error(`'${i}' not executable`);if(!c)h.exit(1);else{let e=new dd(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,c(e)}}),this.runningCommand=s}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)===void 0?!1:this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l))){this.emit(`option:${o.name()}`,l);continue}if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}else if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
367
+ `),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in h.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,h.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new _d(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=xd(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=xd(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>md(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=p.basename(e,p.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(h.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
368
+ Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function Cd(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function wd(){if(h.env.NO_COLOR||h.env.FORCE_COLOR===`0`||h.env.FORCE_COLOR===`false`)return!1;if(h.env.FORCE_COLOR||h.env.CLICOLOR_FORCE!==void 0)return!0}new Sd;const Td=[],Ed=e=>Array.isArray(e)?e:[e],Q=(e,t,n,r,i)=>{if(t.json){let t={data:r,ok:!0,warnings:i??Td};e.out(JSON.stringify(t));return}for(let t of Ed(n))e.out(t);for(let t of i??Td)e.errLine(`refs: warning: ${t}`)},Dd=(e,t,n)=>{if(t.json){let t={error:{code:n.code,message:n.message},ok:!1};e.out(JSON.stringify(t));return}e.errLine(`refs: ${n.message}`)},Od=(e,t)=>{e.errLine(`refs: ${t}`)},$=(e,t,n)=>async()=>{try{await n()}catch(n){let r=be(n,{verbose:t.verbose});Dd(e,t,r),process.exitCode=r.exitCode}};var kd=`0.1.3`;const Ad=async e=>{let t=await e.runner.run(`git`,[`--version`]);return t.exitCode===0?{detail:t.stdout.trim(),name:`git`,status:`ok`}:{detail:t.stderr.trim()||`git --version exited with code ${t.exitCode}`,name:`git`,status:`fail`}},jd=/^v(?<major>\d+)\.(?<minor>\d+)/u,Md=e=>{let t=jd.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(!(n===void 0||r===void 0))return{major:Number(n),minor:Number(r)}},Nd=e=>e===void 0?!1:e.major===24&&e.minor>=12,Pd=e=>{let{nodeVersion:t}=e;return Nd(Md(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.12 <25`,name:`node`,status:`fail`}},Fd=e=>e instanceof Error?e.message:String(e),Id=()=>ss.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),Ld=async e=>{try{return{config:await W(e)}}catch(e){return{config:Id(),errorMessage:Fd(e)}}},Rd=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},zd=[`.claude`,`skills`,`refs`,`SKILL.md`],Bd=[`.codex`,`skills`,`refs`,`SKILL.md`],Vd=e=>e===void 0?[]:[m(e,...zd),m(e,...Bd)],Hd=async t=>{try{return await e(t),!0}catch{return!1}},Ud=async e=>{let t=Vd(e.env.HOME);return(await Promise.all(t.map(e=>Hd(e)))).some(Boolean)?{detail:`the refs skill is installed`,name:`skill`,status:`ok`}:{detail:`refs skill not found — install it: npx skills add kaisers-io/refs`,name:`skill`,status:`warn`}},Wd=(e,t)=>Object.keys(t.refs).map(t=>({dest:U(e,z.parse(t)),key:t})).filter(e=>G(e.dest)),Gd=[`pre-commit`,`pre-push`],Kd=async(t,r)=>{try{return await e(m(t.hooksDir,r),n.X_OK),!0}catch{return!1}},qd=async e=>{let t=await Promise.all(Gd.map(t=>Kd(e,t)));return Gd.filter((e,n)=>!t[n])},Jd=async(e,t,n)=>{let r=await e.runner.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:n});return r.exitCode===0&&r.stdout.trim()===t.hooksDir},Yd=e=>e.missingHooks.length>0?{detail:`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`,name:`hooks-guard`,status:`fail`}:e.badKeys.length>0?{detail:`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`,name:`hooks-guard`,status:`fail`}:{detail:`${Gd.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`},Xd=async(e,t,n)=>{let r=Wd(t,n),[i,a]=await Promise.all([qd(t),Promise.all(r.map(n=>Jd(e,t,n.dest)))]),o=r.filter((e,t)=>!a[t]).map(e=>e.key);return Yd({badKeys:o,checkoutCount:r.length,missingHooks:i})},Zd=async(e,t)=>{let n=await e.runner.run(`git`,[`status`,`--porcelain`],{cwd:t.dest});return n.exitCode===0?{broken:!1,detail:``,dirty:n.stdout.trim()!==``,key:t.key}:{broken:!0,detail:n.stderr.trim(),dirty:!1,key:t.key}},Qd=e=>{let t=e.filter(e=>e.broken);if(t.length>0)return{detail:t.map(e=>`${e.key}: git status failed — ${e.detail}`).join(`; `),name:`dirty-checkouts`,status:`fail`};let n=e.filter(e=>e.dirty).map(e=>e.key);return n.length===0?{detail:`no local changes in any checkout`,name:`dirty-checkouts`,status:`ok`}:{detail:`local changes will be discarded on next sync: ${n.join(`, `)}`,name:`dirty-checkouts`,status:`warn`}},$d=async(e,t,n)=>{let r=Wd(t,n),i=await Promise.all(r.map(t=>Zd(e,t)));return Qd(i)},ef=async e=>{try{return await Z(e)}catch{return Ru.parse({})}},tf=async e=>{try{return(await s(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(V(e))return[];throw e}},nf=async(e,t)=>{if(G(e))return[[...t]];let n=await tf(e);return(await Promise.all(n.map(n=>nf(m(e,n),[...t,n])))).flat()},rf=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r===void 0?!1:n-Date.parse(r)<864e5},af=(e,t,n)=>rf(t,e.key,n)?`${e.key}: pending add`:`${e.key}: orphan — remove with: rm -rf ${e.dest}`,of=(e,t)=>({dest:m(e.sourcesDir,...t),key:t.join(`/`)}),sf=async(e,t,n)=>{let r=(await nf(e.sourcesDir,[])).map(t=>of(e,t)).filter(e=>!Object.hasOwn(t.refs,e.key));if(r.length===0)return{detail:`no orphaned checkouts under sources/`,name:`orphans`,status:`ok`};let i=Date.now();return{detail:r.map(e=>af(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},cf=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,lf=e=>e===``?{}:{user:e},uf=e=>e===``?{}:{port:e},df=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...lf(t.username),...uf(t.port)}:void 0}catch{return}},ff=e=>{let t=cf.exec(e),n=t?.groups?.host;return n===void 0?df(e):{host:n,user:t?.groups?.user??`git`}},pf=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,mf=e=>e.user===void 0?pf(e):`${e.user}@${pf(e)}`,hf=e=>{let t=Object.values(e.refs).map(e=>ff(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(mf(e),e);return[...n.values()].toSorted((e,t)=>mf(e).localeCompare(mf(t)))},gf=/Permission denied/u,_f=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],vf=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,yf=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=vf(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},bf=async(e,t,n)=>{let r=mf(t),i=await e.runner.run(`ssh`,yf(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:gf.test(i.stderr)?{host:r,outcome:`denied`}:_f.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},xf=(e,t)=>{let n=e.filter(e=>e.outcome===`timeout`).map(e=>e.host);if(n.length!==0)return{detail:`ssh probe timed out after ${t/1e3}s: ${n.join(`, `)}`,name:`ssh-auth`,status:`fail`}},Sf=e=>{let t=e.filter(e=>e.outcome===`denied`).map(e=>e.host);if(t.length!==0)return{detail:`ssh permission denied for: ${t.join(`, `)}`,name:`ssh-auth`,status:`fail`}},Cf=e=>{let t=e.filter(e=>e.outcome===`connection-warn`);if(t.length!==0)return{detail:`ssh connection issue, treated as warn: ${t.map(e=>`${e.host} (${e.detail??``})`).join(`; `)}`,name:`ssh-auth`,status:`warn`}},wf=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),Tf=(e,t)=>xf(e,t)??Sf(e)??Cf(e)??wf(e),Ef=async(e,t,n)=>{let r=hf(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>bf(e,t,i)));return Tf(a,i)},Df=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Fd(t)}`,name:e.name,status:`fail`}}},Of=async e=>{let[t,...n]=e;if(t===void 0)return[];let r=await Df(t),i=await Of(n);return r===void 0?i:[r,...i]},kf=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>Ad(n)},{name:`node`,run:()=>Promise.resolve(Pd(n))},{name:`config`,run:()=>Promise.resolve(Rd(t.errorMessage))},{name:`hooks-guard`,run:()=>Xd(n,r,t.config)},{name:`dirty-checkouts`,run:()=>$d(n,r,t.config)},{name:`orphans`,run:()=>sf(r,t.config,i)},{name:`skill`,run:()=>Ud(n)},{name:`ssh-auth`,run:()=>Ef(n,t.config)}]},Af=async e=>{let t=H(e.env),n=await Ld(t),r=await ef(t);return Of(kf({configLoad:n,ctx:e,home:t,state:r}))},jf={fail:`FAIL`,ok:`OK`,warn:`WARN`},Mf=e=>e.map(e=>`[${jf[e.status]}] ${e.name}: ${e.detail}`),Nf=e=>e.some(e=>e.status===`fail`),Pf=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, ssh).`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Af(t);Q(t,i,Mf(e),{checks:e}),Nf(e)&&(process.exitCode=g.UNEXPECTED)})()})},Ff=async e=>{let t=H(e.env),n=await Y(t,`home`,()=>cc(t,kd));return n===`migrated`?{backup:Bs(t),result:n}:{backup:null,result:n}},If=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${te(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,Lf=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Ff(t);Q(t,i,If(e),e)})()})},Rf=(e,t,n)=>e===void 0?!0:n-Date.parse(e)>t,zf=(e,t,n)=>{let r=e.state.refs[t],i=Zo(X(`sync_ttl`,n,e.settings));return{clone_mode:X(`clone_mode`,n,e.settings),description:n.description,key:t,missing:!G(U(e.home,z.parse(t))),packages:Object.keys(n.packages??{}).toSorted(),stale:Rf(r?.last_fetched_at,i,e.now)}},Bf=e=>{let t={home:e.home,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>zf(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},Vf=async e=>{let t=H(e.env),n=await W(t),r=await Z(t);return Bf({config:n,home:t,now:Date.now(),state:r})},Hf=e=>{let t=[];return e.stale&&t.push(`[stale]`),e.missing&&t.push(`[missing]`),t.length===0?``:` ${t.join(` `)}`},Uf=e=>e.length===0?[`no refs configured — run: refs add <source>`]:e.map(e=>`${e.key} ${e.description}${Hf(e)}`),Wf=e=>e.split(`/`),Gf=(e,t)=>{let n=Wf(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},Kf=(e,t)=>{if(Object.hasOwn(e.refs,t))return z.parse(t);let n=Wf(t),r=Object.keys(e.refs).filter(e=>Gf(e,n)).toSorted(),[i]=r;if(i===void 0)throw v(`no ref matches '${t}'`);if(r.length>1)throw y(`'${t}' matches more than one ref: ${r.join(`, `)}`);return z.parse(i)},qf=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Vf(t);Q(t,i,Uf(e),e)})()})},Jf=e=>`ref:${e.replaceAll(`/`,`_`)}`,Yf=e=>e.REFS_ALLOW_FILE_URLS===`1`,Xf=(e,t)=>{let n=J(t,{allowFileUrls:Yf(e.env)});return{cloneUrl:n.cloneUrl,key:n.key}},Zf=async(e,t)=>{if(t===``)throw y(`refs add npm: requires a package name, e.g. npm:left-pad`);Od(e,`resolving npm package '${t}'…`);let n=await du(e.fetcher,t),r={cloneUrl:n.cloneUrl,key:n.key,npmPkgName:t};return n.directory!==void 0&&(r.npmDirectory=n.directory),r},Qf=(e,t)=>t.startsWith(`npm:`)?Zf(e,t.slice(4)):Promise.resolve(Xf(e,t)),$f=(e,t)=>{if(e.npmPkgName===void 0)return e;let n=X(`git_transport`,void 0,t);return{...e,cloneUrl:xl(e.cloneUrl,n)}},ep=e=>`ref '${e}' already exists — use refs edit or refs remove`,tp=(e,t)=>{if(e.refs[t]!==void 0)throw ve(ep(t))},np=async e=>{try{return await s(e,{withFileTypes:!0})}catch(e){if(V(e))return;throw e}},rp=e=>e.filter(e=>e.isDirectory()).map(e=>e.name),ip=async(e,t)=>{let n=await np(e);if(n===void 0)return{kind:`stop`};let r=rp(n);if(r.includes(t))return{kind:`continue`,nextDir:m(e,t)};let i=r.find(e=>e.toLowerCase()===t.toLowerCase());return i===void 0?{kind:`stop`}:{kind:`collision`,name:i}},ap=async(e,t,n)=>{let[r,...i]=t;if(r===void 0)return;let a=await ip(e,r);if(a.kind!==`stop`)return a.kind===`collision`?[...n,a.name].join(`/`):ap(a.nextDir,i,[...n,r])},op=[],sp=async(e,t)=>{let n=await ap(e.sourcesDir,t.split(`/`),op);if(n!==void 0)throw ve(`checkout path for '${t}' collides case-insensitively with existing '${n}'`)},cp=[],lp=e=>e===void 0?cp:[e],up=async e=>{try{return await i(e),!0}catch(e){if(V(e))return!1;throw e}},dp=async e=>{try{return await s(e)}catch(e){if(V(e))return;throw e}},fp=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(V(e))return;throw e}},pp=async e=>{let t=await dp(e);if(t===void 0)return!0;if(t.length!==0)return!1;try{await d(e)}catch(e){if(!V(e))throw e}return!0},mp=async e=>{let t=await fp(e);return t===void 0?!0:t?pp(e):!1},hp=async(e,t)=>{t!==e.sourcesDir&&await mp(t)&&await hp(e,ne(t))},gp=async(e,t)=>await up(t)?(Us(e,t),await u(t,{force:!0,recursive:!0}),await hp(e,ne(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},_p=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),vp=async(e,t)=>{let n=await W(e);await Zs(e,{...n,refs:_p(n.refs,t)});let r=await Z(e);await Vu(e,{...r,refs:_p(r.refs,t)})},yp=async(e,t)=>{let n=H(e.env),r=Kf(await W(n),t),i=U(n,r),{removedCheckout:a,warning:o}=await Y(n,Jf(r),()=>gp(n,i));return await Y(n,`home`,()=>vp(n,r)),{data:{key:r,removed_checkout:a},warnings:lp(o)}},bp=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],xp=(e,t)=>{e.command(`remove`).description(`Remove a configured ref: its config/state entry AND its checkout directory.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await yp(t,e);Q(t,a,bp(n),n,r)})()})},Sp=e=>`no ref matches '${e}' — run refs list, or add it: refs add <url>`,Cp=/^[a-z][a-z0-9+.-]*:\/\//iu,wp=/^git@[^:/\s]+:[^\s]+$/u,Tp=e=>Cp.test(e)||wp.test(e),Ep=(e,t)=>{try{return J(e,t)}catch{if(Tp(e))throw b(`query looks like a git url but is not a supported form — check the url (credentials are never accepted) or run: refs resolve <package|ref-suffix>`);return}},Dp=(e,t,n)=>{let r=Ep(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw v(Sp(t))}},Op=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages?.[t];i!==void 0&&n.push({entry:i,key:z.parse(r)})}return n},kp=(e,t)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — use the full ref key`,Ap=(e,t)=>{let n=Op(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw y(kp(t,n.map(e=>e.key)));return r}},jp=(e,t)=>{let n=t.split(`/`);for(let t=n.length-1;t>=1;--t){let r=n.slice(0,t).join(`/`),i=Ap(e,r);if(i!==void 0)return{...i,name:r}}},Mp=(e,t)=>{try{return Kf(e,t)}catch(e){throw e instanceof _&&e.code===`not_found`?v(Sp(t)):e}},Np=(e,t,n)=>{let r=Dp(e,t,n);if(r!==void 0)return r;let i=Ap(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=jp(e,t);return a===void 0?{key:Mp(e,t)}:{key:a.key,packageMatch:a}},Pp=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: resolved ref key '${t}' is missing from config.refs`);return n},Fp=(e,t)=>{if(e.packageMatch===void 0)return null;let{entry:n,name:r}=e.packageMatch;return{local_path:m(t,n.path),name:r,path:n.path}},Ip=async(e,t)=>{let n=H(e.env),r=await W(n),i=Np(r,t,{allowFileUrls:Yf(e.env)}),a=Pp(r,i.key),o=await Z(n),s=U(n,i.key),c=Zo(X(`sync_ttl`,a,r.settings));return{key:i.key,local_path:s,missing:!G(s),package:Fp(i,s),stale:Rf(o.refs[i.key]?.last_fetched_at,c,Date.now())}},Lp=e=>{let t=[e.key,`local_path: ${e.local_path}`];return e.package!==null&&t.push(`package: ${e.package.name}`,`local_path: ${e.package.local_path}`),t},Rp=(e,t)=>{e.command(`resolve`).description(`Resolve a git url, npm package name, import path, or ref-key suffix to its ref/package.`).argument(`<query>`,`git url, npm package name, import path, or unique ref-key suffix`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let n=await Ip(t,e);Q(t,a,Lp(n),n)})()})},zp={},Bp=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Vp=e=>e instanceof Error?e.message:String(e),Hp=async(e,t)=>{if(!G(t))return{tags:[]};try{return{tags:await Oc(e.runner,t,5)}}catch(e){return{tags:[],warning:`could not list tags: ${Vp(e)}`}}},Up=[],Wp=e=>e===void 0?Up:[e],Gp=async(e,t)=>{let n=H(e.env),r=await W(n),i=Kf(r,t),a=Bp(r,i),o=await Z(n),s=U(n,i),{tags:c,warning:l}=await Hp(e,s);return{data:{...a,key:i,local_path:s,sample_tags:c,state:o.refs[i]??zp},warnings:Wp(l)}},Kp=e=>{let t=[`${e.key} ${e.description}`,`url: ${e.url}`,`local_path: ${e.local_path}`];return e.sample_tags.length>0&&t.push(`tags: ${e.sample_tags.join(`, `)}`),t},qp=(e,t)=>{e.command(`show`).description(`Show a configured ref: full entry, state, local path, and sample tags.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await Gp(t,e);Q(t,a,Kp(n),n,r)})()})},Jp=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:new Date().toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},Yp=async(e,t,n)=>{let r=await W(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await Zs(e,r))},Xp=(e,t,n)=>Y(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await Yp(e,t,n.branchRenamedTo);let r=await Z(e);r.refs[t]=Jp(r.refs[t],n),await Vu(e,r)}),Zp=async(e,t,n)=>{try{await Y(e,`home`,async()=>{let r=await Z(e);r.refs[t]={...r.refs[t],last_error:n},await Vu(e,r)})}catch{}},Qp=e=>{let t=0,n=[];return{acquire:()=>{if(t<e)return t+=1,Promise.resolve();let{promise:r,resolve:i}=Promise.withResolvers();return n.push(()=>{t+=1,i()}),r},release:()=>{--t;let e=n.shift();e!==void 0&&e()}}},$p=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},em=(e,t,n)=>`checkout at ${e} points at '${q(t)}' — expected '${q(n)}'; remove the checkout directory or run refs remove before retrying`,tm=e=>e.exitCode===0?e.stdout.trim():`(no origin remote)`,nm=(e,t)=>{try{return J(e,{allowFileUrls:t}).key}catch{return}},rm=async(e,t)=>{let n=await e.run(`git`,[`remote`,`get-url`,`origin`],{cwd:t.dest}),r=tm(n),i=nm(t.expectedUrl,t.allowFileUrls),a=nm(r,t.allowFileUrls);if(!(i!==void 0&&a===i))throw ve(em(t.dest,r,t.expectedUrl))},im=e=>`checkout at ${e} exists but is not refs-managed — remove it (rm -rf ${e}) and retry`,am=async(e,t)=>{let n=await e.run(`git`,[`config`,`--local`,`core.hooksPath`],{cwd:t.dest});if(n.exitCode!==0||n.stdout.trim()!==t.hooksDir)throw ve(im(t.dest))},om=async(e,t)=>{await a(ne(t.dest),{recursive:!0}),Od(e,`cloning ${q(t.cloneUrl)} into ${t.dest}…`);let n=await yc(e.runner,t);return n.warning===void 0?{effectiveMode:n.effectiveMode}:{effectiveMode:n.effectiveMode,warning:n.warning}},sm=async(e,t)=>(Us(t.home,t.dest),G(t.dest)?(await rm(e.runner,{allowFileUrls:t.allowFileUrls,dest:t.dest,expectedUrl:t.cloneUrl}),await am(e.runner,{dest:t.dest,hooksDir:t.hooksDir}),{}):om(e,t)),cm=(e,t)=>`checkout for '${e}' at ${t} is missing or corrupt (git rev-parse HEAD failed) — run: refs remove ${e}, then refs add <source> --dry-run again`,lm=(e,t,n)=>`checkout for '${e}' at ${t} has a HEAD sha refs cannot store yet (${n.length} hex chars, expected 40) — only SHA-1 repositories are supported for now; \`--object-format=sha256\` repositories are not yet supported`,um=async(e,t)=>{await rm(e,t),await am(e,{dest:t.dest,hooksDir:t.hooksDir});let n=await e.run(`git`,[`rev-parse`,`HEAD`],{cwd:t.dest});if(n.exitCode!==0)throw b(cm(t.key,t.dest));let r=n.stdout.trim();if(!Lu.shape.head_sha.safeParse(r).success)throw b(lm(t.key,t.dest,r));return r},dm=(e,t,n)=>`sync produced a HEAD sha for '${e}' at ${t} that refs cannot store yet (${n.length} hex chars) — only SHA-1 repositories are supported for now`,fm=(e,t,n)=>{if(!Lu.shape.head_sha.safeParse(n).success)throw b(dm(e,t,n));return n},pm=(e,t,n)=>{let r={effectiveCloneMode:t.effectiveMode,headSha:n.headSha,status:`cloned`};return n.actualBranch!==e.ref.default_branch&&(r.branchRenamedTo=n.actualBranch),t.warning!==void 0&&(r.warning=t.warning),r},mm=async(e,t,n)=>{await a(ne(n),{recursive:!0});let r=X(`clone_mode`,t.ref,t.settings),i=await yc(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await xc(e.runner,n),s=await um(e.runner,{allowFileUrls:Yf(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return pm(t,i,{actualBranch:o,headSha:s})},hm=async(e,t,n)=>{await am(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await rm(e.runner,{allowFileUrls:Yf(e.env),dest:n,expectedUrl:t.ref.url});let r=await Dc(e.runner,{defaultBranch:t.ref.default_branch,dir:n}),i={headSha:fm(t.key,n,r.newSha),status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},gm=(e,t)=>Y(t.home,Jf(t.key),()=>{let n=U(t.home,t.key);return Us(t.home,n),G(n)?hm(e,t,n):mm(e,t,n)}),_m=e=>e instanceof Error?e.message:String(e),vm=e=>{let t=[];e.branchRenamedTo!==void 0&&t.push(`default branch renamed to ${e.branchRenamedTo}`),e.warning!==void 0&&t.push(e.warning);let[n]=t;if(n!==void 0)return t.join(` | `)},ym=(e,t)=>{let n={key:e,status:t.status},r=vm(t);return r!==void 0&&(n.warning=r),n},bm=async(e,t)=>{try{let n=await gm(e,t);return await Xp(t.home,t.key,n),ym(t.key,n)}catch(e){let n=_m(e);return await Zp(t.home,t.key,n),{error:n,key:t.key,status:`failed`}}},xm=(e,t)=>e.status===`fulfilled`?e.value:{error:_m(e.reason),key:t,status:`failed`},Sm=async(e,t)=>{let n=Qp(4);return(await Promise.allSettled(t.map(t=>$p(n,()=>bm(e,t))))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return xm(e,r.key)})},Cm=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},wm=(e,t,n)=>({home:e,key:n,ref:Cm(t,n),settings:t.settings}),Tm=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>wm(e,t,z.parse(n))):n.map(n=>wm(e,t,Kf(t,n))),Em=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=Zo(X(`sync_ttl`,t.ref,t.settings)),a=Rf(n.refs[t.key]?.last_fetched_at,i,r),o=!G(U(e,t.key));return a||o})},Dm=async(e,t,n)=>{if(!n)return t;let r=await Z(e);return Em(e,t,r)},Om=async(e,t)=>{let n=H(e.env),r=await W(n),i=Tm(n,r,t.refs),a=await Sm(e,await Dm(n,i,t.staleOnly));return{failedCount:a.filter(e=>e.status===`failed`).length,results:a}},km=[`updated`,`fresh`,`cloned`,`restored`,`failed`],Am={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},jm=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},Mm=e=>e.status===`failed`?` ${e.key}: ${e.error??`unknown error`}`:e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`,Nm=e=>{let t=jm(e),n=[km.map(e=>`${Am[e]} (${t[e].length})`).join(` / `)];for(let e of km)for(let r of t[e])n.push(Mm(r));return n},Pm=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),Fm=(e,t)=>{e.command(`sync`).description(`Fetch (or re-clone, if the checkout is missing) configured refs — all by default.`).argument(`[refs...]`,`ref keys or unique suffixes to sync (default: every configured ref)`).option(`--stale-only`,`skip refs whose last sync is still within their ref's sync_ttl`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let r=await Om(t,Pm(e,n));Q(t,a,Nm(r.results),{results:r.results}),r.failedCount>0&&(process.exitCode=g.UNEXPECTED)})()})},Im=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Lm=(e,t,n)=>{if(n===void 0)return e.tag_format;let r=e.packages?.[n];if(r===void 0)throw v(`no package '${n}' registered on ref '${t}'`);return r.tag_format??e.tag_format},Rm=(e,t)=>{if(!G(e))throw v(`checkout for '${t}' is missing — run: refs sync ${t}`)},zm=async(e,t)=>{let n=H(e.env),r=await W(n),i=Kf(r,t.query),a=Im(r,i),o=Lm(a,i,t.opts.packageName),s=U(n,i);Rm(s,i);let c=await Uc(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},Bm=e=>[`${e.key}@${e.version} -> ${e.tag}`],Vm=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},Hm=[Pf,Lf,xp,Rp,qp,Fm,(e,t)=>{e.command(`tag`).description(`Resolve a version to its git tag, via the ref's (or a package's) tag_format.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).argument(`<version>`,`version to resolve, e.g. 15.3.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=i.optsWithGlobals(),o={json:a.json===!0,verbose:a.verbose===!0};return $(t,o,async()=>{let i=await zm(t,{opts:Vm(r),query:e,version:n});Q(t,o,Bm(i),i)})()})}],Um=e=>e.description===void 0?{path:e.path}:{description:e.description,path:e.path},Wm=(e,t,n)=>e.length>0?Object.fromEntries(e.map(e=>[e.name,Um(e)])):n===void 0?{}:{[n]:{path:t??`.`}},Gm=e=>{let t=e.description??``;return e.tag_format===void 0?{description:t,path:e.path}:{description:t,path:e.path,tag_format:e.tag_format}},Km=e=>{let t=Object.entries(e);if(t.length!==0)return Object.fromEntries(t.map(([e,t])=>[e,Gm(t)]))},qm=e=>e.description===void 0||e.description===``,Jm=e=>Object.entries(e).filter(([,e])=>qm(e)).map(([e])=>e).toSorted(),Ym=e=>{let t=Jm(e);if(t.length!==0)throw b(`packages without a detected description: ${t.join(`, `)} — run the two-phase flow instead: refs add <source> --dry-run --json > proposal.json, fill in the package descriptions, then refs add --proposal proposal.json`)},Xm=e=>{if(Object.keys(e).length!==0)return e},Zm=e=>{if(e===null)throw b(`tag_format_candidate must be set to a valid tag format (containing '{version}') before finalizing — edit the proposal and provide one, or add the ref manually`);return e},Qm=e=>e.packages===void 0?{default_branch:e.default_branch,description:e.description,tag_format:e.tag_format,url:e.url}:{default_branch:e.default_branch,description:e.description,packages:e.packages,tag_format:e.tag_format,url:e.url},$m=[],eh=e=>e===void 0?[...$m]:[e],th=async(e,t,n)=>{let r=await xc(e.runner,t),i=Vc(await Oc(e.runner,t));return Od(e,`detecting workspace packages…`),{defaultBranch:r,packages:Wm(await cd(t),n.npmDirectory,n.npmPkgName),tagFormatCandidate:i}},nh=(e,t)=>Y(t.home,Jf(t.resolved.key),async()=>{let n=await sm(e,{allowFileUrls:Yf(e.env),cloneUrl:t.resolved.cloneUrl,dest:t.dest,home:t.home,hooksDir:t.home.hooksDir,mode:t.cloneMode}),r={fields:await th(e,t.dest,t.resolved)};return n.effectiveMode!==void 0&&(r.effectiveMode=n.effectiveMode),n.warning!==void 0&&(r.warning=n.warning),r}),rh=e=>{let t={default_branch:e.cloneResult.fields.defaultBranch,description:``,key:e.resolved.key,packages:e.cloneResult.fields.packages,tag_format_candidate:e.cloneResult.fields.tagFormatCandidate,url:e.resolved.cloneUrl},n={dest:e.dest,proposal:t};return e.cloneResult.effectiveMode!==void 0&&(n.effectiveCloneMode=e.cloneResult.effectiveMode),e.cloneResult.warning!==void 0&&(n.warning=e.cloneResult.warning),n},ih=async(e,t)=>{let n=H(e.env),r=await W(n),i=$f(await Qf(e,t),r.settings);tp(r,i.key),await sp(n,i.key);let a=U(n,i.key),o=X(`clone_mode`,void 0,r.settings),s=await nh(e,{cloneMode:o,dest:a,home:n,resolved:i});return rh({cloneResult:s,dest:a,resolved:i})},ah=(e,t,n)=>Y(e,`home`,async()=>{tp(await W(e),t);let r=await Z(e),i=r.refs[t],a=n??i?.effective_clone_mode,o={...i,pending_proposal_at:new Date().toISOString()};a!==void 0&&(o.effective_clone_mode=a),r.refs[t]=o,await Vu(e,r)}),oh=(e,t)=>{let n=ss.safeParse(e);if(!n.success)throw b(O(n.error));let r=Ru.safeParse(t);if(!r.success)throw b(O(r.error));return{config:n.data,state:r.data}},sh=async(e,t)=>{let n=await W(e.home);tp(n,e.ref.key);let r=Qm(e.ref);n.refs[e.ref.key]=r;let i=await Z(e.home);return i.refs[e.ref.key]={effective_clone_mode:e.effectiveCloneMode??i.refs[e.ref.key]?.effective_clone_mode??X(`clone_mode`,void 0,n.settings),head_sha:t,last_fetched_at:new Date().toISOString()},{...oh(n,i),entry:r}},ch=async(e,t)=>{let n=Yf(e.env),r=await Y(t.home,Jf(t.ref.key),()=>(Us(t.home,t.dest),um(e.runner,{allowFileUrls:n,dest:t.dest,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.ref.key})));return Y(t.home,`home`,async()=>{let{config:e,entry:n,state:i}=await sh(t,r);return await Vu(t.home,i),await Zs(t.home,e),{entry:n,key:t.ref.key}})},lh=(e,t)=>t===`-`?e.readStdin():o(t,`utf8`),uh=e=>e instanceof Error?e.message:String(e),dh=e=>{try{return JSON.parse(e)}catch(e){throw b(`invalid JSON in proposal: ${uh(e)}`)}},fh=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ph=e=>fh(e)&&`ok`in e&&!(`key`in e),mh=e=>{if(!ph(e))return e;if(e.ok===!1)throw b(`proposal file contains a failed refs envelope (ok is false) — re-run the dry-run`);if(fh(e.data))return e.data;throw b(`proposal file is a refs envelope without a usable data object — re-run the dry-run`)},hh=e=>e.code===`unrecognized_keys`,gh=e=>e.path.length===0,_h=(e,t)=>{let n=t.toSorted().map(e=>`"${e}"`).join(`, `);return e===``?`✖ unrecognized key(s) in proposal: ${n}`:`✖ unrecognized key(s) in proposal at ${e}: ${n}`},vh=e=>{let t=new Map;for(let n of e){let e=ct(n.path);t.set(e,[...t.get(e)??[],...n.keys])}return[...t.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>_h(e,t))},yh=e=>`✖ invalid proposal: ${e.message}`,bh=e=>{let t=e.issues.filter(e=>hh(e)),n=e.issues.filter(e=>!hh(e)),r=n.filter(e=>gh(e));if(t.length===0&&r.length===0)return O(e);let i=n.filter(e=>!gh(e)),a=[...vh(t),...r.map(e=>yh(e))];return i.length>0&&a.push(O({issues:i})),a.join(`
369
+ `)},xh=e=>{let t=Iu.safeParse(e);if(!t.success)throw b(bh(t.error));return t.data},Sh=async(e,t)=>{let n=await lh(e,t);return xh(mh(dh(n)))},Ch=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],wh=async(e,t)=>{let n=await ih(e,t);await ah(H(e.env),n.proposal.key,n.effectiveCloneMode);let r=eh(n.warning);return{data:n.proposal,human:Ch(n.proposal.key,n.dest),warnings:r}},Th=e=>[`refs add: '${e}' added to config`],Eh=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,tag_format:Zm(e.tag_format_candidate),url:e.url},n=Xm(e.packages);return n!==void 0&&(t.packages=n),t},Dh=async(e,t)=>{let n=await Sh(e,t),r=H(e.env),i=U(r,n.key);if(!G(i))throw v(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let{entry:a,key:o}=await ch(e,{dest:i,home:r,ref:Eh(n)});return{data:{entry:a,key:o},human:Th(o),warnings:[]}},Oh=(e,t)=>{Ym(e.proposal.packages);let n={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,tag_format:Zm(e.proposal.tag_format_candidate),url:e.proposal.url},r=Km(e.proposal.packages);return r!==void 0&&(n.packages=r),n},kh=async(e,t,n)=>{let r=await ih(e,t),i=H(e.env),a=Oh(r,n),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await ch(e,o),l=eh(r.warning);return{data:{entry:s,key:c},human:Th(c),warnings:l}},Ah=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw y(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw y(`refs add needs --dry-run, --proposal, or --description`)},jh=e=>{if(e===void 0||e===``)throw y(`refs add requires <source> (a git url or npm:<package>)`);return e},Mh=(e,t)=>(Ah(t),t.proposal===void 0?t.description===void 0?wh(e,jh(t.source)):kh(e,jh(t.source),t.description):Dh(e,t.proposal)),Nh=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},Ph=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let r=await Mh(t,Nh(e,n));Q(t,a,r.human,r.data,r.warnings)})()})},Fh=e=>e===void 0?null:e,Ih=()=>Object.keys(as.shape).toSorted().join(`, `),Lh=e=>`unknown package field '${e}' — valid fields: ${Ih()}`,Rh=e=>Object.hasOwn(as.shape,e),zh=(e,t,n)=>{let r=e.packages?.[n];if(r===void 0)throw v(`no package '${n}' registered on ref '${t}'`);return r},Bh=(e,t,n)=>{if(!Rh(t))throw y(Lh(t));let r=e[t],i=as.safeParse({...e,[t]:n});if(!i.success)throw b(O(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},Vh=async e=>{let t=zh(e.entry,e.key,e.packageName),n=Bh(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await Zs(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:Fh(n.newValue),old:Fh(n.oldValue)}},Hh=`packages`,Uh=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Wh=()=>Object.keys(os.shape).filter(e=>e!==Hh).toSorted().join(`, `),Gh=e=>`unknown ref field '${e}' — valid fields: ${Wh()}`,Kh=e=>Object.hasOwn(os.shape,e),qh=(e,t,n)=>`failed to rewrite git remote at ${e} to '${q(t)}': ${n.trim()}`,Jh=async(e,t)=>{if(Us(t.home,t.dest),!G(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw b(qh(t.dest,t.cloneUrl,n.stderr))},Yh=async(e,t)=>{let n=J(t.value,{allowFileUrls:Yf(e.env)});if(n.key!==t.key)throw b(`new url derives a different key — remove and re-add instead`);let r=U(t.home,t.key);return await Jh(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},Xh=(e,t,n)=>{let r={...e,[t]:n},i=os.safeParse(r);if(!i.success)throw b(O(i.error));return i.data},Zh=(e,t)=>t.field===`url`?Yh(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(Xh(t.entry,t.field,t.value)),Qh=async(e,t)=>{let{field:n}=t;if(n===Hh)throw y(`use --package <name> <field> <value>`);if(!Kh(n))throw y(Gh(n));let r=t.entry[n],i=await Zh(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},$h=(e,t)=>{let n=H(e.env),{field:r,opts:i,query:a,value:o}=t;return Y(n,`home`,async()=>{let t=await W(n),s=Kf(t,a),c=Uh(t,s);if(i.packageName!==void 0)return Vh({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await Qh(e,{entry:c,field:r,home:n,key:s,value:o});return await Zs(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:Fh(l.new),old:Fh(l.old)}})},eg=`settings`,tg=[],ng=()=>Object.keys(rs.shape).toSorted().join(`, `),rg=e=>`unknown setting '${e}' — valid settings: ${ng()}`,ig=e=>Object.hasOwn(rs.shape,e),ag=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,og=e=>{try{let t=Kf(e,eg);return[ag(`ref '${t}'`)]}catch(e){if(e instanceof _&&e.code===`usage`)return[ag("one of several matching refs — see `refs list`")];if(e instanceof _&&e.code===`not_found`)return tg;throw e}},sg=e=>({data:{field:e.key,key:eg,new:Fh(e.parsed[e.key]),old:Fh(e.old)},warnings:og(e.config)}),cg=(e,t)=>{let n=H(e.env);return Y(n,`home`,async()=>{let e=await W(n);if(!ig(t.key))throw y(rg(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=rs.safeParse(i);if(!a.success)throw b(O(a.error));return await Zs(n,{...e,settings:a.data}),sg({config:e,key:t.key,old:r,parsed:a.data})})},lg=[],ug=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},dg=async(e,t)=>{if(t.first===`settings`){if(t.opts.packageName!==void 0)throw y(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return cg(e,{key:t.second,value:t.value})}return{data:await $h(e,{field:t.second,opts:t.opts,query:t.first,value:t.value}),warnings:lg}},fg=e=>e==null?`(unset)`:String(e),pg=e=>[`${e.key}: ${e.field} '${fg(e.old)}' -> '${fg(e.new)}'`],mg=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`<field-or-key>`,`field to edit (or, in settings mode, the setting key)`).argument(`<value>`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).action((e,n,r,i,a)=>{let o=a.optsWithGlobals(),s={json:o.json===!0,verbose:o.verbose===!0};return $(t,s,async()=>{let{data:a,warnings:o}=await dg(t,{first:e,opts:ug(i),second:n,value:r});Q(t,s,pg(a),a,o)})()})},hg=`Install the agent skill: npx skills add kaisers-io/refs (private phase: npx skills add <path-to-this-repo> --skill refs)`,gg=async e=>{await a(e.root,{recursive:!0}),await a(e.sourcesDir,{recursive:!0}),await a(e.locksDir,{recursive:!0}),await a(e.hooksDir,{recursive:!0})},_g=async e=>{let t=H(e.env);return await gg(t),{config:await Y(t,`home`,async()=>{let e=await cc(t,kd);return await jc(t),e}),home:t.root,skill_hint:hg}},vg=[(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await _g(t);Q(t,i,[`refs home: ${e.home} (${e.config})`,hg],e)})()})},Ph,mg,qf,...Hm],yg=(e,t)=>{for(let n of vg)n(e,t)},bg=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve next/navigation --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
370
+ `),xg=new Set([`commander.help`,`commander.helpDisplayed`,`commander.version`]),Sg=`--json`,Cg=`--verbose`,wg=/\n$/u,Tg=/^error: /u,Eg=e=>e.replace(Tg,``),Dg=(e,t)=>{for(let n of e){if(n===`--`)return!1;if(n===t)return!0}return!1},Og=e=>Dg(e,Sg),kg=e=>Dg(e,Cg),Ag=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,jg=e=>{let t=new Sd().name(`refs`).description(`Manage git-based reference checkouts shared across a workspace.`).version(kd).option(Sg,`emit machine-readable JSON on stdout instead of human-readable text`).option(Cg,`include stack traces in error output`).allowExcessArguments(!1).exitOverride().configureOutput({outputError:()=>{},writeErr:t=>{e.errLine(t.replace(wg,``))},writeOut:t=>{e.out(t.replace(wg,``))}});return t.addHelpText(`after`,bg),yg(t,e),t},Mg=()=>{process.exitCode=g.OK},Ng=(e,t,n)=>{Dd(e,t,{code:`usage`,message:Ag(Eg(n.message),n.stack,t.verbose)}),process.exitCode=g.USAGE},Pg=(e,t,n)=>{if(xg.has(n.code)){Mg();return}Ng(e,t,n)},Fg=(e,t,n)=>{let r=be(n,{verbose:t.verbose});Dd(e,t,r),process.exitCode=r.exitCode},Ig=async(e,t,n)=>{let r={json:Og(n),verbose:kg(n)};try{await t.parseAsync(n)}catch(t){if(t instanceof dd){Pg(e,r,t);return}Fg(e,r,t)}},Lg=(e,t)=>Ig(e,jg(e),t);import.meta.main&&await Lg(ud(),process.argv);export{jg as buildProgram,Q as emit,Dd as emitError,Od as progress,ud as realContext,yg as registerCommands,Lg as run,Ig as runProgram,$ as wrapAction};