@apptoolkit/harness 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- var Xu=Object.defineProperty;var Yu=(e)=>e;function Qu(e,t){this[e]=Yu.bind(null,t)}var ep=(e,t)=>{for(var r in t)Xu(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Qu.bind(t,r)})};import{resolve as tr}from"node:path";import{fileURLToPath as zh}from"node:url";function He(e){let t=Object.values(e).filter((o)=>typeof o==="number");return Object.entries(e).filter(([o,n])=>t.indexOf(+o)===-1).map(([o,n])=>n)}function ir(e,t="|"){return e.map((r)=>ar(r)).join(t)}function Ke(e,t){if(typeof t==="bigint")return t.toString();return t}class Bo{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function Ge(e){return new Bo(e)}function Jo(e){return e===null||e===void 0}function gt(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Vo(e,t){let r=e/t,o=Math.round(r),n=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-o)<n)return 0;return r-o}function Q(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function qe(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function ue(e){return qe(e._zod.def)??e._zod.def.shape}function Ho(e,t,r){Object.defineProperty(e,t,{get(){let o=r();return Q(this,t,o),o},enumerable:!0,configurable:!0})}function Ko(e,t,r){if(t in e)Q(e,t,r);else e[t]=r}function be(e,t,r,o){let n=ue(t);for(let i of r){let s=Object.getOwnPropertyDescriptor(n,i);if(!s.enumerable)continue;if(s.get)Ho(e,i,()=>{let c=t._zod.def.shape[i];return o?o(c,i):c});else Ko(e,i,o?o(s.value,i):s.value)}}function tp(e,t){for(let r of Reflect.ownKeys(t)){let o=Object.getOwnPropertyDescriptor(t,r);if(!o.enumerable)continue;if(o.get)Ho(e,r,()=>t[r]);else Ko(e,r,o.value)}}function W(...e){let t={};for(let r of e){let o=Object.getOwnPropertyDescriptors(r);Object.assign(t,o)}return Object.defineProperties({},t)}function Go(e){return JSON.stringify(e)}function qo(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var sr="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Ce(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var Xo=Ge(()=>{if(B.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Re(e){if(Ce(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(Ce(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function cr(e){if(Re(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var Yo=new Set(["string","number","symbol"]);function ge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e,t,r){let o=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)o._zod.parent=e;return o}function x(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}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function ar(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function Qo(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var yt=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),ur={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function rp(e,t){let r=e._zod.def,o=r.checks;if(o&&o.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let i={};return be(i,e,xt(e,t)),ne(e,W(r,{shape:i,checks:[]}))}function xt(e,t){let r=ue(e),o=[];for(let n of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,n)?.enumerable)throw Error(`Unrecognized key: "${String(n)}"`);if(t[n])o.push(n)}return o}function op(e,t){let r=e._zod.def,o=r.checks;if(o&&o.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let i=new Set(xt(e,t)),s={};return be(s,e,Reflect.ownKeys(ue(e)).filter((c)=>!i.has(c))),ne(e,W(r,{shape:s,checks:[]}))}function np(e,t){if(!Re(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let n=ue(e);for(let i of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,i)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return ne(e,W(e._zod.def,{shape:en(e,t)}))}function en(e,t){let r={};return be(r,e,Reflect.ownKeys(ue(e))),tp(r,t),r}function ip(e,t){if(!Re(t))throw Error("Invalid input to safeExtend: expected a plain object");return ne(e,W(e._zod.def,{shape:en(e,t)}))}function sp(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let r={};be(r,e,Reflect.ownKeys(ue(e))),be(r,t,Reflect.ownKeys(ue(t)));let o=W(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return ne(e,o)}function tn(e,t,r,o="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${o}() cannot be used on object schemas containing refinements`);let c=r?new Set(xt(t,r)):void 0,a={};return be(a,t,Reflect.ownKeys(ue(t)),e&&((u,p)=>c&&!c.has(p)?u:new e({type:"optional",innerType:u}))),ne(t,W(t._zod.def,{shape:a,checks:[]}))}function cp(e,t,r){let o=r?new Set(xt(t,r)):void 0,n={};return be(n,t,Reflect.ownKeys(ue(t)),(i,s)=>o&&!o.has(s)?i:new e({type:"nonoptional",innerType:i})),ne(t,W(t._zod.def,{shape:n}))}function ie(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function rn(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function vt(e,t){return t.map((r)=>{var o;return(o=r).path??(o.path=[]),r.path.unshift(e),r})}function Ve(e){return typeof e==="string"?e:e?.message}function pr(e){let t=[];for(let r of e??[]){let o=r._zod.def;if(!/_(length|size)$|_equals$/.test(o.check))break;let n=o.maximum??o.length??o.size;if(n>=0)t.push([n,r])}return t}function wt(e,t,r){var o;for(let n=t;n<e.length;n++)(o=e[n]).schema??(o.schema=r)}function ye(e,t,r){var o;let n=e.inst?._zod?.traits;if(n?.has("$ZodType"))if(n.has("$ZodCheck"))(o=e).schema??(o.schema=e.inst);else e.schema=e.inst;let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,s=e.message?e.message:Ve(e.inst?._zod.def?.error?.(e))??Ve(i?.(e))??Ve(t?.error?.(e))??Ve(r.customError?.(e))??Ve(r.localeError?.(e))??"Invalid input",c={};for(let a of Object.keys(e)){if(a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__")continue;c[a]=e[a]}if(c.path??(c.path=[]),c.message=s,t?.reportInput)c.input=e.input;return c}var ap=/[\uD800-\uDBFF]/;function _t(e){let t=e.length;if(!ap.test(e))return t;let r=t;for(let o=0;o<t-1;o++)if((e.charCodeAt(o)&64512)===55296&&(e.charCodeAt(o+1)&64512)===56320)r--,o++;return r}function bt(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function on(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function ke(...e){let[t,r,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:o};return{...t}}function nn(e,t){for(let r in t){let o=Object.getOwnPropertyDescriptor(t,r);if(o.get)Object.defineProperty(e,r,{...o,enumerable:!1});else up(e,r,o.value)}}function pe(e,t,r,o=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:o,value:r}),r}function kt(e,t,r){return pe(e,t,r,!1)}function $t(e,t){for(let r in e){let o=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return pe(this,r,o(this))},set(n){pe(this,r,n)}})}return t}function up(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:pe(this,t,r.bind(this))},set(o){pe(this,t,o)}})}function pp(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var nr,me=!1,lp={configurable:!0,get(){me=!0;return}};function b(e,t,r){let o=Object.getPrototypeOf(e._zod);if(t in o&&nr!==e._zod){nr=void 0;return}nr=e._zod,Object.defineProperty(o,t,{configurable:!0,get(){Object.defineProperty(this,t,lp);let n=me;me=!1;try{let i=r(this);if(me)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i});return me=me||n,i}catch(i){throw delete this[t],me=me||n,i}},set(n){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:n})}})}function fp(e,t,r,o){let n=pp(e,t);if(!n)return;Object.defineProperty(n,t,{configurable:!0,get(){let i={configurable:!0,writable:!0,enumerable:o,value:void 0};return Object.defineProperty(this,t,i),i.value=r(this),Object.defineProperty(this,t,i),i.value},set(i){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:o,value:i})}})}var dp="~constantCatch";function sn(e){let t=()=>e;return t[dp]=!0,t}var cn;var lr={value:void 0,enumerable:!1},an="captureStackTrace"in Error?Error:null;function hp(e){let t=an;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return an=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function h(e,t,r,o){let n={};function i(f){this.def=f,this.constr=l,this.traits=new Set}i.prototype=n;let s=r,c=s&&new WeakSet;function a(f,d){if(!f._zod){lr.value=new i(d);try{Object.defineProperty(f,"_zod",lr)}finally{lr.value=void 0}}else if(f._zod.traits.has(e))return;if(f._zod.traits.add(e),t(f,d),c){let m=Object.getPrototypeOf(f),y=f._zod.constr.prototype,v=m;while(v&&v!==y)v=Object.getPrototypeOf(v);let k=v??m;if(!c.has(k))c.add(k),nn(k,s)}let g=l.prototype;for(let m in g){if(!Object.prototype.hasOwnProperty.call(g,m))continue;if(!(m in f))f[m]=g[m].bind(f)}}let u=o?.Parent??Object;class p extends u{}Object.defineProperty(p,"name",{value:e});function l(f){let d=o?.Parent?hp(p):this;a(d,f);let g=d._zod.deferred;if(g){for(let y of g)y();d._zod.deferred=void 0}let m=globalThis.__zod_globalConfig?.postProcessor;if(m)m(d);return d}return Object.defineProperty(l,"init",{value:a}),Object.defineProperty(l,Symbol.hasInstance,{value:(f)=>{if(o?.Parent&&f instanceof o.Parent)return!0;return f?._zod?.traits?.has(e)}}),Object.defineProperty(l,"name",{value:e}),l}class se extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Xe extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(cn=globalThis).__zod_globalConfig??(cn.__zod_globalConfig={});var B=globalThis.__zod_globalConfig;function te(e){if(e)Object.assign(B,e);return B}function mp(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ke,2)),e.message}function gp(e){this._zod.message=e}var yp={get:mp,set:gp,enumerable:!0,configurable:!0},dr={value:void 0,enumerable:!1},un=new WeakSet([Object.prototype,Error.prototype]),pn=(e,t)=>{e.name="$ZodError",dr.value=t,Object.defineProperty(e,"issues",dr),dr.value=void 0,Object.defineProperty(e,"message",yp);let r=Object.getPrototypeOf(e);if(!un.has(r))un.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let o=()=>this.message;return Object.defineProperty(this,"toString",{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,"toString",{value:o,configurable:!0,writable:!0})}})},ln=h("$ZodError",pn),Ih=h("$ZodError",pn,void 0,{Parent:Error});function xp(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function fn(e,t=(r)=>r.message){let r={},o=[];for(let n of e.issues)if(n.path.length>0)xp(r,n.path[0],()=>[]).push(t(n));else o.push(t(n));return{formErrors:o,fieldErrors:r}}function dn(e,t=(r)=>r.message){let r={_errors:[]},o=(n,i=[])=>{for(let s of n.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map((c)=>o({issues:c},[...i,...s.path]));else if(s.code==="invalid_key")o({issues:s.issues},[...i,...s.path]);else if(s.code==="invalid_element")o({issues:s.issues},[...i,...s.path]);else{let c=[...i,...s.path];if(c.length===0)r._errors.push(t(s));else{let a=r,u=0;while(u<c.length){let p=c[u],l=u===c.length-1;if(p==="_errors"){if(l)a._errors.push(t(s));u++;continue}if(!Object.prototype.hasOwnProperty.call(a,p))Object.defineProperty(a,p,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let f=a[p];if(l)f._errors.push(t(s));a=f,u++}}}};return o(e),r}function zt(e,t){return{callee:t?.callee??e,Err:t?.Err}}var St=(e)=>{let t=(r,o,n,i)=>{let s=n?{...n,async:!1}:{async:!1},c=r._zod.run({value:o,issues:[]},s);if(c instanceof Promise)throw new se;if(c.issues.length){let a=new(i?.Err??e)(c.issues.map((u)=>ye(u,s,te())));throw sr(a,i?.callee??t),a}return c.value};return t};var Pt=(e)=>{let t=async(r,o,n,i)=>{let s=n?{...n,async:!0}:{async:!0},c=r._zod.run({value:o,issues:[]},s);if(c instanceof Promise)c=await c;if(c.issues.length){let a=new(i?.Err??e)(c.issues.map((u)=>ye(u,s,te())));throw sr(a,i?.callee??t),a}return c.value};return t};var Et=(e)=>(t,r,o)=>{let n=o?{...o,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},n);if(i instanceof Promise)throw new se;return i.issues.length?hn(e,i.issues,n):{success:!0,data:i.value}};function hn(e,t,r){let o;return{success:!1,get error(){if(!o)o=new e(t.map((n)=>ye(n,r,te()))),t=void 0,r=void 0;return o},set error(n){o=n,t=void 0,r=void 0}}}var Zt=(e)=>async(t,r,o)=>{let n=o?{...o,async:!0}:{async:!0},i=t._zod.run({value:r,issues:[]},n);if(i instanceof Promise)i=await i;return i.issues.length?hn(e,i.issues,n):{success:!0,data:i.value}};var vp=Symbol.for("zod.compile.invalid"),wp=Symbol.for("zod.compile.fallback"),hr=(e,t,r)=>{let o=e._zod.bag.validator;if(o!==void 0){if(o(t)!==vp)return!0;if(o.definite===!0&&r===void 0)return!1}return _p(e,t,r)};function _p(e,t,r){let o=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},n=e._zod.bag.fallbackRun,i;if(n)o[wp]=!0,i=n({value:t,issues:[]},o);else i=e._zod.run({value:t,issues:[]},o);if(i instanceof Promise)throw new se;return i.issues.length===0}var mr=async(e,t,r)=>{let o=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},n=e._zod.run({value:t,issues:[]},o);if(n instanceof Promise)n=await n;return n.issues.length===0},mn=(e)=>{let t=St(e),r=(o,n,i,s)=>{let c=i?{...i,direction:"backward"}:{direction:"backward"};return t(o,n,c,zt(r,s))};return r};var gn=(e)=>{let t=St(e),r=(o,n,i,s)=>t(o,n,i,zt(r,s));return r};var yn=(e)=>{let t=Pt(e),r=async(o,n,i,s)=>{let c=i?{...i,direction:"backward"}:{direction:"backward"};return await t(o,n,c,zt(r,s))};return r};var xn=(e)=>{let t=Pt(e),r=async(o,n,i,s)=>await t(o,n,i,zt(r,s));return r};var vn=(e)=>(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Et(e)(t,r,n)};var wn=(e)=>(t,r,o)=>Et(e)(t,r,o);var _n=(e)=>async(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Zt(e)(t,r,n)};var bn=(e)=>async(t,r,o)=>Zt(e)(t,r,o);var kn=/^[cC][0-9a-z]{6,}$/,$n=/^[0-9a-z]+$/,zn=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Sn=/^[0-9a-vA-V]{20}$/,Pn=/^[A-Za-z0-9]{27}$/,En=/^[a-zA-Z0-9_-]{21}$/;function Zn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var On=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var 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})$/,yr=(e)=>{if(!e)return/^([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)$/;return new 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})$`)};var Rn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var bp="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function In(){return new RegExp(bp,"u")}var An=/^(?:(?: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])$/,Nn=/^(([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}|:))$/;var Tn=/^((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])$/,jn=/^(([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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Dn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Fn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var Ln=/^https?$/,Mn=/^\+[1-9]\d{6,14}$/;var Un="(?:(?:\\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])))";function kp(e){return new RegExp(`^${e}$`)}var Wn=kp(Un);function gr(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function Bn(e){return new RegExp(`^${gr(e)}$`)}function Jn(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${gr({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,o=e.local?`${r}|${gr({precision:e.precision})}`:r;return new RegExp(`^${Un}T(?:${o})$`)}var Vn=/^[\s\S]{0,}$/;var Hn=/^-?\d+n?$/;var xr=/^-?\d+(?:\.\d+)?$/,Kn=/^(?:true|false)$/i;var Gn=/^[^A-Z]*$/,qn=/^[^a-z]*$/;var N=h("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var vr=(e)=>{let t=e.value;return!Jo(t)&&t.length!==void 0},Ot={number:"number",bigint:"bigint",object:"date"},wr=h("$ZodCheckLessThan",(e,t)=>{N.init(e,t);let r=Ot[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value<=t.value:o.value<t.value)return;o.issues.push({origin:Ot[typeof o.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),_r=h("$ZodCheckGreaterThan",(e,t)=>{N.init(e,t);let r=Ot[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value>=t.value:o.value>t.value)return;o.issues.push({origin:Ot[typeof o.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Xn=h("$ZodCheckMultipleOf",(e,t)=>{N.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):Vo(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),Yn=h("$ZodCheckNumberFormat",(e,t)=>{N.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),o=r?"int":"number",[n,i]=yt[t.format];e._zod.check=(s)=>{let c=s.value;if(r){if(!Number.isInteger(c)){s.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)s.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});else s.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});return}}if(c<n)s.issues.push({origin:"number",input:c,code:"too_small",minimum:n,inclusive:!0,inst:e,continue:!t.abort});if(c>i)s.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}});var Qn=h("$ZodCheckMaxLength",(e,t)=>{var r;N.init(e,t),(r=e._zod.def).when??(r.when=vr),e._zod.check=(o)=>{let n=o.value,i=n.length;if((typeof n==="string"&&i>t.maximum?_t(n):i)<=t.maximum)return;let c=bt(n);o.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),ei=h("$ZodCheckMinLength",(e,t)=>{var r;N.init(e,t),(r=e._zod.def).when??(r.when=vr),e._zod.check=(o)=>{let n=o.value,i=n.length;if((typeof n==="string"&&i>=t.minimum&&i<t.minimum*2?_t(n):i)>=t.minimum)return;let c=bt(n);o.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),ti=h("$ZodCheckLengthEquals",(e,t)=>{var r;N.init(e,t),(r=e._zod.def).when??(r.when=vr),e._zod.check=(o)=>{let n=o.value,i=n.length,s=typeof n==="string"&&i>=t.length&&i<=t.length*2?_t(n):i;if(s===t.length)return;let c=bt(n),a=s>t.length;o.issues.push({origin:c,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),Qe=h("$ZodCheckStringFormat",(e,t)=>{var r,o;if(N.init(e,t),t.pattern)(r=e._zod).check??(r.check=(n)=>{if(t.pattern.lastIndex=0,t.pattern.test(n.value))return;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})});else(o=e._zod).check??(o.check=()=>{})}),ri=h("$ZodCheckRegex",(e,t)=>{Qe.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),oi=h("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Gn),Qe.init(e,t)}),ni=h("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=qn),Qe.init(e,t)}),ii=h("$ZodCheckIncludes",(e,t)=>{N.init(e,t);let r=ge(t.includes),o=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=o,e._zod.check=(n)=>{if(n.value.includes(t.includes,t.position))return;n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),si=h("$ZodCheckStartsWith",(e,t)=>{N.init(e,t);let r=new RegExp(`^${ge(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(o)=>{if(o.value.startsWith(t.prefix))return;o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),ci=h("$ZodCheckEndsWith",(e,t)=>{N.init(e,t);let r=new RegExp(`.*${ge(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(o)=>{if(o.value.endsWith(t.suffix))return;o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}});var ai=h("$ZodCheckOverwrite",(e,t)=>{N.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class br{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
3
- `).filter((i)=>i),o=Math.min(...r.map((i)=>i.length-i.trimStart().length)),n=r.map((i)=>i.slice(o)).map((i)=>" ".repeat(this.indent*2)+i);for(let i of n)this.content.push(i)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
2
+ var tp=Object.defineProperty;var rp=(e)=>e;function op(e,t){this[e]=rp.bind(null,t)}var np=(e,t)=>{for(var r in t)tp(e,r,{get:t[r],enumerable:!0,configurable:!0,set:op.bind(t,r)})};import{resolve as sr}from"node:path";import{fileURLToPath as Dh}from"node:url";function Ke(e){let t=Object.values(e).filter((o)=>typeof o==="number");return Object.entries(e).filter(([o,n])=>t.indexOf(+o)===-1).map(([o,n])=>n)}function ur(e,t="|"){return e.map((r)=>fr(r)).join(t)}function Ge(e,t){if(typeof t==="bigint")return t.toString();return t}class Ho{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function qe(e){return new Ho(e)}function Ko(e){return e===null||e===void 0}function vt(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Go(e,t){let r=e/t,o=Math.round(r),n=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-o)<n)return 0;return r-o}function Q(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Xe(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function ue(e){return Xe(e._zod.def)??e._zod.def.shape}function qo(e,t,r){Object.defineProperty(e,t,{get(){let o=r();return Q(this,t,o),o},enumerable:!0,configurable:!0})}function Xo(e,t,r){if(t in e)Q(e,t,r);else e[t]=r}function ke(e,t,r,o){let n=ue(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(n,s);if(!i.enumerable)continue;if(i.get)qo(e,s,()=>{let c=t._zod.def.shape[s];return o?o(c,s):c});else Xo(e,s,o?o(i.value,s):i.value)}}function sp(e,t){for(let r of Reflect.ownKeys(t)){let o=Object.getOwnPropertyDescriptor(t,r);if(!o.enumerable)continue;if(o.get)qo(e,r,()=>t[r]);else Xo(e,r,o.value)}}function B(...e){let t={};for(let r of e){let o=Object.getOwnPropertyDescriptors(r);Object.assign(t,o)}return Object.defineProperties({},t)}function Yo(e){return JSON.stringify(e)}function Qo(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var pr="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Ce(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var en=qe(()=>{if(J.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Ie(e){if(Ce(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(Ce(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function lr(e){if(Ie(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var tn=new Set(["string","number","symbol"]);function ye(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ne(e,t,r){let o=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)o._zod.parent=e;return o}function x(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}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function fr(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function rn(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var wt=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),dr={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function ip(e,t){let r=e._zod.def,o=r.checks;if(o&&o.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s={};return ke(s,e,_t(e,t)),ne(e,B(r,{shape:s,checks:[]}))}function _t(e,t){let r=ue(e),o=[];for(let n of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,n)?.enumerable)throw Error(`Unrecognized key: "${String(n)}"`);if(t[n])o.push(n)}return o}function cp(e,t){let r=e._zod.def,o=r.checks;if(o&&o.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=new Set(_t(e,t)),i={};return ke(i,e,Reflect.ownKeys(ue(e)).filter((c)=>!s.has(c))),ne(e,B(r,{shape:i,checks:[]}))}function ap(e,t){if(!Ie(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let n=ue(e);for(let s of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,s)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return ne(e,B(e._zod.def,{shape:on(e,t)}))}function on(e,t){let r={};return ke(r,e,Reflect.ownKeys(ue(e))),sp(r,t),r}function up(e,t){if(!Ie(t))throw Error("Invalid input to safeExtend: expected a plain object");return ne(e,B(e._zod.def,{shape:on(e,t)}))}function pp(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let r={};ke(r,e,Reflect.ownKeys(ue(e))),ke(r,t,Reflect.ownKeys(ue(t)));let o=B(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return ne(e,o)}function nn(e,t,r,o="partial"){let s=t._zod.def.checks;if(s&&s.length>0)throw Error(`.${o}() cannot be used on object schemas containing refinements`);let c=r?new Set(_t(t,r)):void 0,a={};return ke(a,t,Reflect.ownKeys(ue(t)),e&&((u,p)=>c&&!c.has(p)?u:new e({type:"optional",innerType:u}))),ne(t,B(t._zod.def,{shape:a,checks:[]}))}function lp(e,t,r){let o=r?new Set(_t(t,r)):void 0,n={};return ke(n,t,Reflect.ownKeys(ue(t)),(s,i)=>o&&!o.has(i)?s:new e({type:"nonoptional",innerType:s})),ne(t,B(t._zod.def,{shape:n}))}function se(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function sn(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function bt(e,t){return t.map((r)=>{var o;return(o=r).path??(o.path=[]),r.path.unshift(e),r})}function He(e){return typeof e==="string"?e:e?.message}function hr(e){let t=[];for(let r of e??[]){let o=r._zod.def;if(!/_(length|size)$|_equals$/.test(o.check))break;let n=o.maximum??o.length??o.size;if(n>=0)t.push([n,r])}return t}function kt(e,t,r){var o;for(let n=t;n<e.length;n++)(o=e[n]).schema??(o.schema=r)}function xe(e,t,r){var o;let n=e.inst?._zod?.traits;if(n?.has("$ZodType"))if(n.has("$ZodCheck"))(o=e).schema??(o.schema=e.inst);else e.schema=e.inst;let s=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,i=e.message?e.message:He(e.inst?._zod.def?.error?.(e))??He(s?.(e))??He(t?.error?.(e))??He(r.customError?.(e))??He(r.localeError?.(e))??"Invalid input",c={};for(let a of Object.keys(e)){if(a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__")continue;c[a]=e[a]}if(c.path??(c.path=[]),c.message=i,t?.reportInput)c.input=e.input;return c}var fp=/[\uD800-\uDBFF]/;function $t(e){let t=e.length;if(!fp.test(e))return t;let r=t;for(let o=0;o<t-1;o++)if((e.charCodeAt(o)&64512)===55296&&(e.charCodeAt(o+1)&64512)===56320)r--,o++;return r}function zt(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function cn(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function $e(...e){let[t,r,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:o};return{...t}}function an(e,t){for(let r in t){let o=Object.getOwnPropertyDescriptor(t,r);if(o.get)Object.defineProperty(e,r,{...o,enumerable:!1});else dp(e,r,o.value)}}function pe(e,t,r,o=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:o,value:r}),r}function St(e,t,r){return pe(e,t,r,!1)}function Pt(e,t){for(let r in e){let o=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return pe(this,r,o(this))},set(n){pe(this,r,n)}})}return t}function dp(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:pe(this,t,r.bind(this))},set(o){pe(this,t,o)}})}function hp(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var ar,ge=!1,mp={configurable:!0,get(){ge=!0;return}};function b(e,t,r){let o=Object.getPrototypeOf(e._zod);if(t in o&&ar!==e._zod){ar=void 0;return}ar=e._zod,Object.defineProperty(o,t,{configurable:!0,get(){Object.defineProperty(this,t,mp);let n=ge;ge=!1;try{let s=r(this);if(ge)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return ge=ge||n,s}catch(s){throw delete this[t],ge=ge||n,s}},set(n){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:n})}})}function gp(e,t,r,o){let n=hp(e,t);if(!n)return;Object.defineProperty(n,t,{configurable:!0,get(){let s={configurable:!0,writable:!0,enumerable:o,value:void 0};return Object.defineProperty(this,t,s),s.value=r(this),Object.defineProperty(this,t,s),s.value},set(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:o,value:s})}})}var yp="~constantCatch";function un(e){let t=()=>e;return t[yp]=!0,t}var pn;var mr={value:void 0,enumerable:!1},ln="captureStackTrace"in Error?Error:null;function xp(e){let t=ln;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return ln=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function h(e,t,r,o){let n={};function s(f){this.def=f,this.constr=l,this.traits=new Set}s.prototype=n;let i=r,c=i&&new WeakSet;function a(f,d){if(!f._zod){mr.value=new s(d);try{Object.defineProperty(f,"_zod",mr)}finally{mr.value=void 0}}else if(f._zod.traits.has(e))return;if(f._zod.traits.add(e),t(f,d),c){let g=Object.getPrototypeOf(f),y=f._zod.constr.prototype,v=g;while(v&&v!==y)v=Object.getPrototypeOf(v);let k=v??g;if(!c.has(k))c.add(k),an(k,i)}let m=l.prototype;for(let g in m){if(!Object.prototype.hasOwnProperty.call(m,g))continue;if(!(g in f))f[g]=m[g].bind(f)}}let u=o?.Parent??Object;class p extends u{}Object.defineProperty(p,"name",{value:e});function l(f){let d=o?.Parent?xp(p):this;a(d,f);let m=d._zod.deferred;if(m){for(let y of m)y();d._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;if(g)g(d);return d}return Object.defineProperty(l,"init",{value:a}),Object.defineProperty(l,Symbol.hasInstance,{value:(f)=>{if(o?.Parent&&f instanceof o.Parent)return!0;return f?._zod?.traits?.has(e)}}),Object.defineProperty(l,"name",{value:e}),l}class ie extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ye extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(pn=globalThis).__zod_globalConfig??(pn.__zod_globalConfig={});var J=globalThis.__zod_globalConfig;function te(e){if(e)Object.assign(J,e);return J}function vp(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ge,2)),e.message}function wp(e){this._zod.message=e}var _p={get:vp,set:wp,enumerable:!0,configurable:!0},yr={value:void 0,enumerable:!1},fn=new WeakSet([Object.prototype,Error.prototype]),dn=(e,t)=>{e.name="$ZodError",yr.value=t,Object.defineProperty(e,"issues",yr),yr.value=void 0,Object.defineProperty(e,"message",_p);let r=Object.getPrototypeOf(e);if(!fn.has(r))fn.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let o=()=>this.message;return Object.defineProperty(this,"toString",{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,"toString",{value:o,configurable:!0,writable:!0})}})},hn=h("$ZodError",dn),Vh=h("$ZodError",dn,void 0,{Parent:Error});function bp(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function mn(e,t=(r)=>r.message){let r={},o=[];for(let n of e.issues)if(n.path.length>0)bp(r,n.path[0],()=>[]).push(t(n));else o.push(t(n));return{formErrors:o,fieldErrors:r}}function gn(e,t=(r)=>r.message){let r={_errors:[]},o=(n,s=[])=>{for(let i of n.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map((c)=>o({issues:c},[...s,...i.path]));else if(i.code==="invalid_key")o({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")o({issues:i.issues},[...s,...i.path]);else{let c=[...s,...i.path];if(c.length===0)r._errors.push(t(i));else{let a=r,u=0;while(u<c.length){let p=c[u],l=u===c.length-1;if(p==="_errors"){if(l)a._errors.push(t(i));u++;continue}if(!Object.prototype.hasOwnProperty.call(a,p))Object.defineProperty(a,p,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let f=a[p];if(l)f._errors.push(t(i));a=f,u++}}}};return o(e),r}function Et(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Zt=(e)=>{let t=(r,o,n,s)=>{let i=n?{...n,async:!1}:{async:!1},c=r._zod.run({value:o,issues:[]},i);if(c instanceof Promise)throw new ie;if(c.issues.length){let a=new(s?.Err??e)(c.issues.map((u)=>xe(u,i,te())));throw pr(a,s?.callee??t),a}return c.value};return t};var Ot=(e)=>{let t=async(r,o,n,s)=>{let i=n?{...n,async:!0}:{async:!0},c=r._zod.run({value:o,issues:[]},i);if(c instanceof Promise)c=await c;if(c.issues.length){let a=new(s?.Err??e)(c.issues.map((u)=>xe(u,i,te())));throw pr(a,s?.callee??t),a}return c.value};return t};var Rt=(e)=>(t,r,o)=>{let n=o?{...o,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},n);if(s instanceof Promise)throw new ie;return s.issues.length?yn(e,s.issues,n):{success:!0,data:s.value}};function yn(e,t,r){let o;return{success:!1,get error(){if(!o)o=new e(t.map((n)=>xe(n,r,te()))),t=void 0,r=void 0;return o},set error(n){o=n,t=void 0,r=void 0}}}var Ct=(e)=>async(t,r,o)=>{let n=o?{...o,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},n);if(s instanceof Promise)s=await s;return s.issues.length?yn(e,s.issues,n):{success:!0,data:s.value}};var kp=Symbol.for("zod.compile.invalid"),$p=Symbol.for("zod.compile.fallback"),xr=(e,t,r)=>{let o=e._zod.bag.validator;if(o!==void 0){if(o(t)!==kp)return!0;if(o.definite===!0&&r===void 0)return!1}return zp(e,t,r)};function zp(e,t,r){let o=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},n=e._zod.bag.fallbackRun,s;if(n)o[$p]=!0,s=n({value:t,issues:[]},o);else s=e._zod.run({value:t,issues:[]},o);if(s instanceof Promise)throw new ie;return s.issues.length===0}var vr=async(e,t,r)=>{let o=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},n=e._zod.run({value:t,issues:[]},o);if(n instanceof Promise)n=await n;return n.issues.length===0},xn=(e)=>{let t=Zt(e),r=(o,n,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return t(o,n,c,Et(r,i))};return r};var vn=(e)=>{let t=Zt(e),r=(o,n,s,i)=>t(o,n,s,Et(r,i));return r};var wn=(e)=>{let t=Ot(e),r=async(o,n,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return await t(o,n,c,Et(r,i))};return r};var _n=(e)=>{let t=Ot(e),r=async(o,n,s,i)=>await t(o,n,s,Et(r,i));return r};var bn=(e)=>(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Rt(e)(t,r,n)};var kn=(e)=>(t,r,o)=>Rt(e)(t,r,o);var $n=(e)=>async(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Ct(e)(t,r,n)};var zn=(e)=>async(t,r,o)=>Ct(e)(t,r,o);var Sn=/^[cC][0-9a-z]{6,}$/,Pn=/^[0-9a-z]+$/,En=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Zn=/^[0-9a-vA-V]{20}$/,On=/^[A-Za-z0-9]{27}$/,Rn=/^[a-zA-Z0-9_-]{21}$/;function Cn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var In=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var An=/^([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})$/,_r=(e)=>{if(!e)return/^([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)$/;return new 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})$`)};var Tn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var Sp="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Nn(){return new RegExp(Sp,"u")}var jn=/^(?:(?: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])$/,Dn=/^(([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}|:))$/;var Fn=/^((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])$/,Ln=/^(([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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Mn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Wn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var Un=/^https?$/,Bn=/^\+[1-9]\d{6,14}$/;var Jn="(?:(?:\\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])))";function Pp(e){return new RegExp(`^${e}$`)}var Vn=Pp(Jn);function wr(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function Hn(e){return new RegExp(`^${wr(e)}$`)}function Kn(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${wr({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,o=e.local?`${r}|${wr({precision:e.precision})}`:r;return new RegExp(`^${Jn}T(?:${o})$`)}var Gn=/^[\s\S]{0,}$/;var qn=/^-?\d+n?$/;var br=/^-?\d+(?:\.\d+)?$/,Xn=/^(?:true|false)$/i;var Yn=/^[^A-Z]*$/,Qn=/^[^a-z]*$/;var T=h("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var kr=(e)=>{let t=e.value;return!Ko(t)&&t.length!==void 0},It={number:"number",bigint:"bigint",object:"date"},$r=h("$ZodCheckLessThan",(e,t)=>{T.init(e,t);let r=It[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value<=t.value:o.value<t.value)return;o.issues.push({origin:It[typeof o.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),zr=h("$ZodCheckGreaterThan",(e,t)=>{T.init(e,t);let r=It[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value>=t.value:o.value>t.value)return;o.issues.push({origin:It[typeof o.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:o.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),es=h("$ZodCheckMultipleOf",(e,t)=>{T.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):Go(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),ts=h("$ZodCheckNumberFormat",(e,t)=>{T.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),o=r?"int":"number",[n,s]=wt[t.format];e._zod.check=(i)=>{let c=i.value;if(r){if(!Number.isInteger(c)){i.issues.push({expected:o,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});else i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:o,inclusive:!0,continue:!t.abort});return}}if(c<n)i.issues.push({origin:"number",input:c,code:"too_small",minimum:n,inclusive:!0,inst:e,continue:!t.abort});if(c>s)i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var rs=h("$ZodCheckMaxLength",(e,t)=>{var r;T.init(e,t),(r=e._zod.def).when??(r.when=kr),e._zod.check=(o)=>{let n=o.value,s=n.length;if((typeof n==="string"&&s>t.maximum?$t(n):s)<=t.maximum)return;let c=zt(n);o.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),os=h("$ZodCheckMinLength",(e,t)=>{var r;T.init(e,t),(r=e._zod.def).when??(r.when=kr),e._zod.check=(o)=>{let n=o.value,s=n.length;if((typeof n==="string"&&s>=t.minimum&&s<t.minimum*2?$t(n):s)>=t.minimum)return;let c=zt(n);o.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),ns=h("$ZodCheckLengthEquals",(e,t)=>{var r;T.init(e,t),(r=e._zod.def).when??(r.when=kr),e._zod.check=(o)=>{let n=o.value,s=n.length,i=typeof n==="string"&&s>=t.length&&s<=t.length*2?$t(n):s;if(i===t.length)return;let c=zt(n),a=i>t.length;o.issues.push({origin:c,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),et=h("$ZodCheckStringFormat",(e,t)=>{var r,o;if(T.init(e,t),t.pattern)(r=e._zod).check??(r.check=(n)=>{if(t.pattern.lastIndex=0,t.pattern.test(n.value))return;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})});else(o=e._zod).check??(o.check=()=>{})}),ss=h("$ZodCheckRegex",(e,t)=>{et.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),is=h("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Yn),et.init(e,t)}),cs=h("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Qn),et.init(e,t)}),as=h("$ZodCheckIncludes",(e,t)=>{T.init(e,t);let r=ye(t.includes),o=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=o,e._zod.check=(n)=>{if(n.value.includes(t.includes,t.position))return;n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),us=h("$ZodCheckStartsWith",(e,t)=>{T.init(e,t);let r=new RegExp(`^${ye(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(o)=>{if(o.value.startsWith(t.prefix))return;o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),ps=h("$ZodCheckEndsWith",(e,t)=>{T.init(e,t);let r=new RegExp(`.*${ye(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(o)=>{if(o.value.endsWith(t.suffix))return;o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}});var ls=h("$ZodCheckOverwrite",(e,t)=>{T.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Sr{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
3
+ `).filter((s)=>s),o=Math.min(...r.map((s)=>s.length-s.trimStart().length)),n=r.map((s)=>s.slice(o)).map((s)=>" ".repeat(this.indent*2)+s);for(let s of n)this.content.push(s)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
4
4
  ${t.join(`
5
5
  `)}
6
- };`)(...Object.values(this.closed))}}var pi={major:4,minor:6,patch:7};var E=h("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=pi;let o=e._zod.def.checks,n=e._zod.traits.has("$ZodCheck")?[e,...o??[]]:o?.length?[...o]:[];for(let i of n)for(let s of i._zod.onattach)s(e);if(n.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(c,a,u)=>{if(c.memo)return c;let p=ie(c),l;for(let f of a){if(f._zod.def.when){if(rn(c))continue;if(!f._zod.def.when(c))continue}else if(p)continue;let d=c.issues.length,g=f._zod.check(c);if(g instanceof Promise&&u?.async===!1)throw new se;if(l||g instanceof Promise)l=(l??Promise.resolve()).then(async()=>{if(await g,c.issues.length===d)return;if(wt(c.issues,d,e),!p)p=ie(c,d)});else{if(c.issues.length===d)continue;if(wt(c.issues,d,e),!p)p=ie(c,d)}}if(l)return l.then(()=>c);return c},s=(c,a,u)=>{if(ie(c))return c.aborted=!0,c;let p=i(a,n,u);if(p instanceof Promise){if(u.async===!1)throw new se;return p.then((l)=>e._zod.parse(l,u))}return e._zod.parse(p,u)};e._zod.run=(c,a)=>{if(a.skipChecks)return e._zod.parse(c,a);if(a.direction==="backward"){let p=e._zod.parse({value:c.value,issues:[]},{...a,skipChecks:!0});if(p instanceof Promise)return p.then((l)=>s(l,c,a));return s(p,c,a)}let u=e._zod.parse(c,a);if(u instanceof Promise){if(a.async===!1)throw new se;return u.then((p)=>i(p,n,a))}return i(u,n,a)}}},{get "~standard"(){return kt(this,"~standard",$r(this))},set "~standard"(e){pe(this,"~standard",e)}}),_i=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>ye(r,t,te()))}:{value:e.value};async function zp(e,t){let r={async:!0};return _i(await e._zod.run({value:t,issues:[]},r),r)}function $r(e){return{validate:(t)=>{let r={async:!1};try{let o=e._zod.run({value:t,issues:[]},r);if(!(o instanceof Promise))return _i(o,r)}catch(o){}return zp(e,t)},vendor:"zod",version:1}}var At=h("$ZodString",(e,t)=>{E.init(e,t),e._zod.pattern=t.pattern??Vn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=String(r.value)}catch(n){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),Z=h("$ZodStringFormat",(e,t)=>{Qe.init(e,t),At.init(e,t)}),bi=h("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Cn),Z.init(e,t)}),ki=h("$ZodUUID",(e,t)=>{if(t.version){let o={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(o===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=yr(o))}else t.pattern??(t.pattern=yr());Z.init(e,t)}),$i=h("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Rn),Z.init(e,t)}),zi=1,Rt=2;function Si(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function Sp(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return Si(e)||Rt;return Pp(e,t)}function Pp(e,t){if(!t.normalize&&t.protocol?.source===Ln.source&&!/^https?:\/\//i.test(e))return zi;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Rt}return new URL(e)}catch{return Rt}}var Ep=/[\t\n\r]/g;function li(e){return e.replace(Ep,"")}function Zp(e,t){return t.lastIndex=0,t.test(e.hostname)}function Op(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var Pi=h("$ZodURL",(e,t)=>{Z.init(e,t),e._zod.check=(r)=>{try{let o=r.value.trim(),n=Sp(o,t);if(n===zi){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(n===Rt){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(n===!0){r.value=li(o);return}if(t.hostname&&!Zp(n,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!Op(n,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?n.href:li(o);return}catch(o){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),Ei=h("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=In()),Z.init(e,t)}),Zi=h("$ZodNanoID",(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=t.length===void 0?En:Zn(t.length)),Z.init(e,t)}),Oi=h("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=kn),Z.init(e,t)}),Ci=h("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=$n),Z.init(e,t)}),Ri=h("$ZodULID",(e,t)=>{t.pattern??(t.pattern=zn),Z.init(e,t)}),Ii=h("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Sn),Z.init(e,t)}),Ai=h("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Pn),Z.init(e,t)}),Ni=h("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Jn(t)),Z.init(e,t)}),Ti=h("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Wn),Z.init(e,t)}),ji=h("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Bn(t)),Z.init(e,t)}),Di=h("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=On),Z.init(e,t)}),Fi=h("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=An),Z.init(e,t)}),Cp=/^[0-9a-fA-F:.]+$/;function Li(e){if(!Cp.test(e))return!1;return Si(`http://[${e}]`)}var Mi=h("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Nn),Z.init(e,t),e._zod.check=(r)=>{if(!Li(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var Ui=h("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Tn),Z.init(e,t)});function Rp(e){let t=e.split("/");if(t.length!==2)return!1;let[r,o]=t;if(!o)return!1;let n=Number(o);if(`${n}`!==o)return!1;if(n<0||n>128)return!1;return Li(r)}var Wi=h("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=jn),Z.init(e,t),e._zod.check=(r)=>{if(!Rp(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function Bi(e){if(e==="")return!0;if(/\s/.test(e))return!1;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var zr=/^[0-9a-zA-Z+/]*={0,2}$/,Ji=h("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=zr),Z.init(e,t),e._zod.check=(r)=>{if(Bi(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),Nt=/^[A-Za-z0-9_-]*$/;function Ip(e){if(!Nt.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return Bi(r)}var Vi=h("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Nt),Z.init(e,t),e._zod.check=(r)=>{if(Ip(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),Hi=h("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Mn),Z.init(e,t)});function Ap(e,t=null){try{let r=e.split(".");if(r.length!==3)return!1;let[o]=r;if(!o)return!1;let n=JSON.parse(atob(o));if("typ"in n&&n?.typ!=="JWT")return!1;if(!n.alg)return!1;if(t&&(!("alg"in n)||n.alg!==t))return!1;return!0}catch{return!1}}var Ki=h("$ZodJWT",(e,t)=>{Z.init(e,t),e._zod.check=(r)=>{if(Ap(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var Sr=h("$ZodNumber",(e,t)=>{E.init(e,t),e._zod.pattern=xr,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=Number(r.value)}catch(s){}let n=r.value;if(typeof n==="number"&&!Number.isNaN(n)&&Number.isFinite(n))return r;let i=typeof n==="number"?Number.isNaN(n)?"NaN":!Number.isFinite(n)?String(n):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:n,inst:e,...i?{received:i}:{}}),r}}),Gi=h("$ZodNumberFormat",(e,t)=>{Yn.init(e,t),Sr.init(e,t)}),qi=h("$ZodBoolean",(e,t)=>{E.init(e,t),e._zod.pattern=Kn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(i){}let n=r.value;if(typeof n==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:n,inst:e}),r}}),Xi=h("$ZodBigInt",(e,t)=>{E.init(e,t),e._zod.pattern=Hn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=BigInt(r.value)}catch(n){}if(typeof r.value==="bigint")return r;return r.issues.push({expected:"bigint",code:"invalid_type",input:r.value,inst:e}),r}});var Yi=h("$ZodUnknown",(e,t)=>{E.init(e,t),e._zod.parse=(r)=>r}),Qi=h("$ZodNever",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});var es=h("$ZodDate",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=new Date(r.value)}catch(c){}let n=r.value,i=n instanceof Date;if(i&&!Number.isNaN(n.getTime()))return r;return r.issues.push({expected:"date",code:"invalid_type",input:n,...i?{received:"Invalid Date"}:{},inst:e}),r}});function Np(e,t){let r=pr(e._zod.def.checks);if(!r.length)return;let o=Math.min(...r.map((i)=>i[0])),n=e._zod.parse;e._zod.parse=(i,s)=>{let c=t(i.value);if(c>o&&!s?.skipChecks&&s?.direction!=="backward"){for(let[a,u]of pr(e._zod.def.checks))if(c>a&&u._zod.def.when(i)){let p=i.issues.length;return u._zod.check(i),i.issues[p].continue=!1,wt(i.issues,p,e),i}}return n(i,s)}}var Tp=(e)=>Array.isArray(e)?e.length:-1;function fi(e,t,r){if(e.issues.length)t.issues.push(...vt(r,e.issues));t.value[r]=e.value}var ts=h("$ZodArray",(e,t)=>{E.init(e,t);let r=B.memoizer;r?.attach(e),e._zod.parse=(o,n)=>{let i=o.value;if(!Array.isArray(i))return o.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),o;o.value=r?r.alloc(e,o,Array(i.length),n):Array(i.length);let s=[],c=n?.abortEarly;for(let a=0;a<i.length;a++){let u=i[a],p=t.element._zod.run({value:u,issues:[]},n);if(p instanceof Promise)s.push(p.then((l)=>fi(l,o,a)));else if(fi(p,o,a),c&&p.issues.length!==0&&ie(p))break}if(s.length)return Promise.all(s).then(()=>o);return o},Np(e,Tp)});function It(e,t,r,o,n,i){let s=r in o,c=i==="optional";if(!s&&c&&n==="optional")return;if(e.issues.length){if(n!==void 0&&c&&!s)return;t.issues.push(...vt(r,e.issues))}if(!s&&n===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(s||n==="defaulted"&&!c)t.value[r]=void 0}else t.value[r]=e.value}var jp=[];function rs(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),o=r.length?r:jp,n=o.length?[...t,...o]:t;for(let s of n)if(!e.shape?.[s]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(s)}": expected a Zod schema`);let i=Qo(e.shape);return{...e,allKeys:n,symbolKeys:o,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function os(e,t,r,o,n,i,s){let c=[],a=n.keySet,u=n.catchall._zod,p=u.def.type,{optin:l,optout:f}=u,d=0;for(let g in t){if(s&&r.issues.length!==d){if(ie(r,d))break;d=r.issues.length}if(a.has(g))continue;if(g==="__proto__"){if(p==="never")c.push(g);continue}if(p==="never"){c.push(g);continue}let m=u.run({value:t[g],issues:[]},o);if(m instanceof Promise)e.push(m.then((y)=>It(y,r,g,t,l,f)));else It(m,r,g,t,l,f)}if(c.length)r.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:i,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var Dp=h("$ZodObject",(e,t)=>{E.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),o=r?.get?r.get.raw:t.shape??{};if(o){let u=()=>{let p={...o};return Object.defineProperty(t,"shape",{value:p}),u.raw=p,p};u.raw=o,Object.defineProperty(t,"shape",{get:u})}let n=Ge(()=>rs(t));b(e,"propValues",(u)=>{let p=u.def.shape,l={};for(let f in p){let d=p[f]._zod;if(d.values){if(!Object.prototype.hasOwnProperty.call(l,f))Q(l,f,new Set);for(let g of d.values)l[f].add(g);if(d.optin!==void 0)l[f].add(void 0)}}return l});let i=Ce,s=t.catchall,c,a=B.memoizer;a?.attach(e),e._zod.parse=(u,p)=>{c??(c=n.value);let l=u.value;if(!i(l))return u.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),u;u.value=a?a.alloc(e,u,{},p):{};let f=[],d=c.shape,g=p?.abortEarly,m=u.issues.length;for(let y of c.allKeys){if(g&&u.issues.length!==m){if(ie(u,m))break;m=u.issues.length}if(y==="__proto__")continue;let v=d[y],k=v._zod.optin,G=v._zod.optout,z=v._zod.run({value:l[y],issues:[]},p);if(z instanceof Promise)f.push(z.then((I)=>It(I,u,y,l,k,G)));else It(z,u,y,l,k,G)}if(!s)return f.length?Promise.all(f).then(()=>u):u;return os(f,l,u,p,n.value,e,g===!0)}}),ns=h("$ZodObjectJIT",(e,t)=>{Dp.init(e,t);let r=e._zod.parse,o=Ge(()=>rs(t)),n=B.memoizer,i=(d)=>{let g=o.value,m=g.symbolKeys,y=new br(["payload","ctx"],{shape:d,inst:e,memo:n,syms:m}),v=(I)=>`shape[${I}]._zod.run({ value: input[${I}], issues: [] }, ctx)`,k=(I,S)=>`
6
+ };`)(...Object.values(this.closed))}}var ds={major:4,minor:6,patch:7};var E=h("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=ds;let o=e._zod.def.checks,n=e._zod.traits.has("$ZodCheck")?[e,...o??[]]:o?.length?[...o]:[];for(let s of n)for(let i of s._zod.onattach)i(e);if(n.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let s=(c,a,u)=>{if(c.memo)return c;let p=se(c),l;for(let f of a){if(f._zod.def.when){if(sn(c))continue;if(!f._zod.def.when(c))continue}else if(p)continue;let d=c.issues.length,m=f._zod.check(c);if(m instanceof Promise&&u?.async===!1)throw new ie;if(l||m instanceof Promise)l=(l??Promise.resolve()).then(async()=>{if(await m,c.issues.length===d)return;if(kt(c.issues,d,e),!p)p=se(c,d)});else{if(c.issues.length===d)continue;if(kt(c.issues,d,e),!p)p=se(c,d)}}if(l)return l.then(()=>c);return c},i=(c,a,u)=>{if(se(c))return c.aborted=!0,c;let p=s(a,n,u);if(p instanceof Promise){if(u.async===!1)throw new ie;return p.then((l)=>e._zod.parse(l,u))}return e._zod.parse(p,u)};e._zod.run=(c,a)=>{if(a.skipChecks)return e._zod.parse(c,a);if(a.direction==="backward"){let p=e._zod.parse({value:c.value,issues:[]},{...a,skipChecks:!0});if(p instanceof Promise)return p.then((l)=>i(l,c,a));return i(p,c,a)}let u=e._zod.parse(c,a);if(u instanceof Promise){if(a.async===!1)throw new ie;return u.then((p)=>s(p,n,a))}return s(u,n,a)}}},{get "~standard"(){return St(this,"~standard",Er(this))},set "~standard"(e){pe(this,"~standard",e)}}),$s=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>xe(r,t,te()))}:{value:e.value};async function Zp(e,t){let r={async:!0};return $s(await e._zod.run({value:t,issues:[]},r),r)}function Er(e){return{validate:(t)=>{let r={async:!1};try{let o=e._zod.run({value:t,issues:[]},r);if(!(o instanceof Promise))return $s(o,r)}catch(o){}return Zp(e,t)},vendor:"zod",version:1}}var jt=h("$ZodString",(e,t)=>{E.init(e,t),e._zod.pattern=t.pattern??Gn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=String(r.value)}catch(n){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),Z=h("$ZodStringFormat",(e,t)=>{et.init(e,t),jt.init(e,t)}),zs=h("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=An),Z.init(e,t)}),Ss=h("$ZodUUID",(e,t)=>{if(t.version){let o={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(o===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=_r(o))}else t.pattern??(t.pattern=_r());Z.init(e,t)}),Ps=h("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Tn),Z.init(e,t)}),Es=1,Tt=2;function Zs(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function Op(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return Zs(e)||Tt;return Rp(e,t)}function Rp(e,t){if(!t.normalize&&t.protocol?.source===Un.source&&!/^https?:\/\//i.test(e))return Es;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Tt}return new URL(e)}catch{return Tt}}var Cp=/[\t\n\r]/g;function hs(e){return e.replace(Cp,"")}function Ip(e,t){return t.lastIndex=0,t.test(e.hostname)}function Ap(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var Os=h("$ZodURL",(e,t)=>{Z.init(e,t),e._zod.check=(r)=>{try{let o=r.value.trim(),n=Op(o,t);if(n===Es){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(n===Tt){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(n===!0){r.value=hs(o);return}if(t.hostname&&!Ip(n,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!Ap(n,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?n.href:hs(o);return}catch(o){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),Rs=h("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Nn()),Z.init(e,t)}),Cs=h("$ZodNanoID",(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=t.length===void 0?Rn:Cn(t.length)),Z.init(e,t)}),Is=h("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Sn),Z.init(e,t)}),As=h("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Pn),Z.init(e,t)}),Ts=h("$ZodULID",(e,t)=>{t.pattern??(t.pattern=En),Z.init(e,t)}),Ns=h("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Zn),Z.init(e,t)}),js=h("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=On),Z.init(e,t)}),Ds=h("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Kn(t)),Z.init(e,t)}),Fs=h("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Vn),Z.init(e,t)}),Ls=h("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Hn(t)),Z.init(e,t)}),Ms=h("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=In),Z.init(e,t)}),Ws=h("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=jn),Z.init(e,t)}),Tp=/^[0-9a-fA-F:.]+$/;function Us(e){if(!Tp.test(e))return!1;return Zs(`http://[${e}]`)}var Bs=h("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Dn),Z.init(e,t),e._zod.check=(r)=>{if(!Us(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var Js=h("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Fn),Z.init(e,t)});function Np(e){let t=e.split("/");if(t.length!==2)return!1;let[r,o]=t;if(!o)return!1;let n=Number(o);if(`${n}`!==o)return!1;if(n<0||n>128)return!1;return Us(r)}var Vs=h("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Ln),Z.init(e,t),e._zod.check=(r)=>{if(!Np(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function Hs(e){if(e==="")return!0;if(/\s/.test(e))return!1;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Zr=/^[0-9a-zA-Z+/]*={0,2}$/,Ks=h("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Zr),Z.init(e,t),e._zod.check=(r)=>{if(Hs(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),Dt=/^[A-Za-z0-9_-]*$/;function jp(e){if(!Dt.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return Hs(r)}var Gs=h("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Dt),Z.init(e,t),e._zod.check=(r)=>{if(jp(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),qs=h("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Bn),Z.init(e,t)});function Dp(e,t=null){try{let r=e.split(".");if(r.length!==3)return!1;let[o]=r;if(!o)return!1;let n=JSON.parse(atob(o));if("typ"in n&&n?.typ!=="JWT")return!1;if(!n.alg)return!1;if(t&&(!("alg"in n)||n.alg!==t))return!1;return!0}catch{return!1}}var Xs=h("$ZodJWT",(e,t)=>{Z.init(e,t),e._zod.check=(r)=>{if(Dp(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var Or=h("$ZodNumber",(e,t)=>{E.init(e,t),e._zod.pattern=br,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=Number(r.value)}catch(i){}let n=r.value;if(typeof n==="number"&&!Number.isNaN(n)&&Number.isFinite(n))return r;let s=typeof n==="number"?Number.isNaN(n)?"NaN":!Number.isFinite(n)?String(n):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:n,inst:e,...s?{received:s}:{}}),r}}),Ys=h("$ZodNumberFormat",(e,t)=>{ts.init(e,t),Or.init(e,t)}),Qs=h("$ZodBoolean",(e,t)=>{E.init(e,t),e._zod.pattern=Xn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(s){}let n=r.value;if(typeof n==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:n,inst:e}),r}}),ei=h("$ZodBigInt",(e,t)=>{E.init(e,t),e._zod.pattern=qn,e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=BigInt(r.value)}catch(n){}if(typeof r.value==="bigint")return r;return r.issues.push({expected:"bigint",code:"invalid_type",input:r.value,inst:e}),r}});var ti=h("$ZodUnknown",(e,t)=>{E.init(e,t),e._zod.parse=(r)=>r}),ri=h("$ZodNever",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});var oi=h("$ZodDate",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>{if(t.coerce)try{r.value=new Date(r.value)}catch(c){}let n=r.value,s=n instanceof Date;if(s&&!Number.isNaN(n.getTime()))return r;return r.issues.push({expected:"date",code:"invalid_type",input:n,...s?{received:"Invalid Date"}:{},inst:e}),r}});function Fp(e,t){let r=hr(e._zod.def.checks);if(!r.length)return;let o=Math.min(...r.map((s)=>s[0])),n=e._zod.parse;e._zod.parse=(s,i)=>{let c=t(s.value);if(c>o&&!i?.skipChecks&&i?.direction!=="backward"){for(let[a,u]of hr(e._zod.def.checks))if(c>a&&u._zod.def.when(s)){let p=s.issues.length;return u._zod.check(s),s.issues[p].continue=!1,kt(s.issues,p,e),s}}return n(s,i)}}var Lp=(e)=>Array.isArray(e)?e.length:-1;function ms(e,t,r){if(e.issues.length)t.issues.push(...bt(r,e.issues));t.value[r]=e.value}var ni=h("$ZodArray",(e,t)=>{E.init(e,t);let r=J.memoizer;r?.attach(e),e._zod.parse=(o,n)=>{let s=o.value;if(!Array.isArray(s))return o.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),o;o.value=r?r.alloc(e,o,Array(s.length),n):Array(s.length);let i=[],c=n?.abortEarly;for(let a=0;a<s.length;a++){let u=s[a],p=t.element._zod.run({value:u,issues:[]},n);if(p instanceof Promise)i.push(p.then((l)=>ms(l,o,a)));else if(ms(p,o,a),c&&p.issues.length!==0&&se(p))break}if(i.length)return Promise.all(i).then(()=>o);return o},Fp(e,Lp)});function Nt(e,t,r,o,n,s){let i=r in o,c=s==="optional";if(!i&&c&&n==="optional")return;if(e.issues.length){if(n!==void 0&&c&&!i)return;t.issues.push(...bt(r,e.issues))}if(!i&&n===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(i||n==="defaulted"&&!c)t.value[r]=void 0}else t.value[r]=e.value}var Mp=[];function si(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),o=r.length?r:Mp,n=o.length?[...t,...o]:t;for(let i of n)if(!e.shape?.[i]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(i)}": expected a Zod schema`);let s=rn(e.shape);return{...e,allKeys:n,symbolKeys:o,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(s)}}function ii(e,t,r,o,n,s,i){let c=[],a=n.keySet,u=n.catchall._zod,p=u.def.type,{optin:l,optout:f}=u,d=0;for(let m in t){if(i&&r.issues.length!==d){if(se(r,d))break;d=r.issues.length}if(a.has(m))continue;if(m==="__proto__"){if(p==="never")c.push(m);continue}if(p==="never"){c.push(m);continue}let g=u.run({value:t[m],issues:[]},o);if(g instanceof Promise)e.push(g.then((y)=>Nt(y,r,m,t,l,f)));else Nt(g,r,m,t,l,f)}if(c.length)r.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:s,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var Wp=h("$ZodObject",(e,t)=>{E.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),o=r?.get?r.get.raw:t.shape??{};if(o){let u=()=>{let p={...o};return Object.defineProperty(t,"shape",{value:p}),u.raw=p,p};u.raw=o,Object.defineProperty(t,"shape",{get:u})}let n=qe(()=>si(t));b(e,"propValues",(u)=>{let p=u.def.shape,l={};for(let f in p){let d=p[f]._zod;if(d.values){if(!Object.prototype.hasOwnProperty.call(l,f))Q(l,f,new Set);for(let m of d.values)l[f].add(m);if(d.optin!==void 0)l[f].add(void 0)}}return l});let s=Ce,i=t.catchall,c,a=J.memoizer;a?.attach(e),e._zod.parse=(u,p)=>{c??(c=n.value);let l=u.value;if(!s(l))return u.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),u;u.value=a?a.alloc(e,u,{},p):{};let f=[],d=c.shape,m=p?.abortEarly,g=u.issues.length;for(let y of c.allKeys){if(m&&u.issues.length!==g){if(se(u,g))break;g=u.issues.length}if(y==="__proto__")continue;let v=d[y],k=v._zod.optin,G=v._zod.optout,z=v._zod.run({value:l[y],issues:[]},p);if(z instanceof Promise)f.push(z.then((I)=>Nt(I,u,y,l,k,G)));else Nt(z,u,y,l,k,G)}if(!i)return f.length?Promise.all(f).then(()=>u):u;return ii(f,l,u,p,n.value,e,m===!0)}}),ci=h("$ZodObjectJIT",(e,t)=>{Wp.init(e,t);let r=e._zod.parse,o=qe(()=>si(t)),n=J.memoizer,s=(d)=>{let m=o.value,g=m.symbolKeys,y=new Sr(["payload","ctx"],{shape:d,inst:e,memo:n,syms:g}),v=(I)=>`shape[${I}]._zod.run({ value: input[${I}], issues: [] }, ctx)`,k=(I,S)=>`
7
7
  let ${I}_ab = false;
8
8
  for (let i = 0; i < ${I}.issues.length; i++) {
9
9
  const iss = ${I}.issues[i];
@@ -14,19 +14,19 @@ ${t.join(`
14
14
  if (${I}_ab && ctx && ctx.abortEarly) {
15
15
  payload.value = newResult;
16
16
  return payload;
17
- }`;y.write("const input = payload.value;");let G=Object.create(null),z=0;for(let I of g.allKeys)G[I]=`key_${z++}`;y.write(n?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(let I of g.allKeys){if(I==="__proto__")continue;let S=G[I],q=typeof I==="symbol"?`syms[${m.indexOf(I)}]`:Go(I),rr=`${q} in input`,Uo=d[I],or=Uo?._zod?.optin,Wo=or!==void 0,Gu=Uo?._zod?.optout==="optional";if(y.write(`const ${S} = ${v(q)};`),Wo&&Gu){let qu=or==="optional"?`${S}_present`:`${S}.value !== undefined || ${S}_present`;y.write(`
18
- const ${S}_present = ${rr};
17
+ }`;y.write("const input = payload.value;");let G=Object.create(null),z=0;for(let I of m.allKeys)G[I]=`key_${z++}`;y.write(n?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(let I of m.allKeys){if(I==="__proto__")continue;let S=G[I],q=typeof I==="symbol"?`syms[${g.indexOf(I)}]`:Yo(I),ir=`${q} in input`,Jo=d[I],cr=Jo?._zod?.optin,Vo=cr!==void 0,Qu=Jo?._zod?.optout==="optional";if(y.write(`const ${S} = ${v(q)};`),Vo&&Qu){let ep=cr==="optional"?`${S}_present`:`${S}.value !== undefined || ${S}_present`;y.write(`
18
+ const ${S}_present = ${ir};
19
19
  if (!${S}.issues.length || ${S}_present) {
20
20
  if (${S}.issues.length) {${k(S,q)}
21
21
  }
22
22
 
23
- if (${qu}) {
23
+ if (${ep}) {
24
24
  newResult[${q}] = ${S}.value;
25
25
  }
26
26
  }
27
27
 
28
- `)}else if(!Wo)y.write(`
29
- const ${S}_present = ${rr};
28
+ `)}else if(!Vo)y.write(`
29
+ const ${S}_present = ${ir};
30
30
  if (${S}.issues.length) {${k(S,q)}
31
31
  }
32
32
  if (!${S}_present && !${S}.issues.length) {
@@ -49,32 +49,32 @@ ${t.join(`
49
49
  `);else if(y.write(`
50
50
  if (${S}.issues.length) {${k(S,q)}
51
51
  }
52
- `),or==="defaulted")y.write(`newResult[${q}] = ${S}.value;`);else y.write(`
53
- if (${S}.value !== undefined || ${rr}) {
52
+ `),cr==="defaulted")y.write(`newResult[${q}] = ${S}.value;`);else y.write(`
53
+ if (${S}.value !== undefined || ${ir}) {
54
54
  newResult[${q}] = ${S}.value;
55
55
  }
56
- `)}return y.write("payload.value = newResult;"),y.write("return payload;"),y.compile()},s,c=Ce,a=!B.jitless,p=a&&Xo.value,l=t.catchall,f;e._zod.parse=(d,g)=>{f??(f=o.value);let m=d.value;if(!c(m))return d.issues.push({expected:"object",code:"invalid_type",input:m,inst:e}),d;if(a&&p&&g?.async===!1&&g.jitless!==!0){if(!s)s=i(t.shape);if(d=s(d,g),!l)return d;return os([],m,d,g,f,e,g?.abortEarly===!0)}return r(d,g)}});function di(e,t,r,o){for(let i of e)if(i.issues.length===0)return t.value=i.value,t;let n=e.filter((i)=>!ie(i));if(n.length===1)return t.value=n[0].value,n[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((i)=>i.issues.map((s)=>ye(s,o,te())))}),t}var Pr=h("$ZodUnion",(e,t)=>{E.init(e,t),b(e,"optin",(o)=>o.def.options.some((n)=>n._zod.optin==="defaulted")?"defaulted":o.def.options.some((n)=>n._zod.optin!==void 0)?"optional":void 0),b(e,"optout",(o)=>o.def.options.some((n)=>n._zod.optout==="optional")?"optional":void 0),b(e,"values",(o)=>{if(o.def.options.every((n)=>n._zod.values))return new Set(o.def.options.flatMap((n)=>Array.from(n._zod.values)));return}),b(e,"pattern",(o)=>{if(o.def.options.every((n)=>n._zod.pattern)){let n=o.def.options.map((i)=>i._zod.pattern);return new RegExp(`^(${n.map((i)=>gt(i.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(o,n)=>{if(r)return r(o,n);let i=!1,s=[];for(let c of t.options){let a=c._zod.run({value:o.value,issues:[]},n);if(a instanceof Promise)s.push(a),i=!0;else{if(a.issues.length===0)return a;s.push(a)}}if(!i)return di(s,o,e,n);return Promise.all(s).then((c)=>di(c,o,e,n))}});function Fp(e){let t=new Map;for(let r of e.options){let o=r._zod.propValues?.[e.discriminator];if(!o||o.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);for(let n of o)if(t.has(n)){if(n!==void 0)throw Error(`Duplicate discriminator value "${String(n)}"`);t.set(n,null)}else t.set(n,r)}return t}var is=h("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Pr.init(e,t);let r=e._zod.parse;b(e,"propValues",(n)=>{let i={},s=0;for(let c of n.def.options){let a=c._zod.propValues;if(!a||Object.keys(a).length===0)throw Error(`Invalid discriminated union option at index "${n.def.options.indexOf(c)}"`);if(a[n.def.discriminator]?.has(void 0))s++;for(let[u,p]of Object.entries(a)){if(!Object.prototype.hasOwnProperty.call(i,u))Q(i,u,new Set);for(let l of p)i[u].add(l)}}if(!n.def.unionFallback&&s>1)i[n.def.discriminator]?.delete(void 0);return i}),t.options.forEach((n,i)=>{let s=qe(n._zod.def);if(s&&!Object.prototype.hasOwnProperty.call(s,t.discriminator))throw Error(`Invalid discriminated union option at index "${i}"`)});let o=Ge(()=>Fp(t));e._zod.parse=(n,i)=>{let s=n.value;if(!Ce(s))return n.issues.push({code:"invalid_type",expected:"object",input:s,inst:e}),n;let c=s?.[t.discriminator],a=o.value.get(c);if(a&&(c!==void 0||i.direction!=="backward"))return a._zod.run(n,i);if(t.unionFallback||i.direction==="backward")return r(n,i);return n.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(o.value.keys()).filter((u)=>o.value.get(u)!==null),input:s,path:[t.discriminator],inst:e}),n}}),ss=h("$ZodIntersection",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>{let n=r.value,i=t.left._zod.run({value:n,issues:[]},o),s=t.right._zod.run({value:n,issues:[]},o);if(i instanceof Promise||s instanceof Promise)return Promise.all([i,s]).then(([a,u])=>hi(r,a,u));return hi(r,i,s)}});function kr(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(Re(e)&&Re(t)){let r=Object.keys(t),o=Object.keys(e).filter((i)=>r.indexOf(i)!==-1),n={...e,...t};if(Object.prototype.hasOwnProperty.call(n,"__proto__"))delete n.__proto__;for(let i of o){if(i==="__proto__")continue;let s=kr(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};n[i]=s.data}return{valid:!0,data:n}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let o=0;o<e.length;o++){let n=e[o],i=t[o],s=kr(n,i);if(!s.valid)return{valid:!1,mergeErrorPath:[o,...s.mergeErrorPath]};r.push(s.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function hi(e,t,r){let o=new Map,n,i=new Map,s=(u,p)=>{let l;if(u.code==="unrecognized_keys"&&!u.path?.length)n??(n=u),l=u.keys;else if(u.code==="invalid_key"&&u.origin==="record"&&u.path?.length===1){let f=String(u.path[0]);if(!i.has(f))i.set(f,u);l=[f]}else return!1;for(let f of l){if(!o.has(f))o.set(f,{});o.get(f)[p]=!0}return!0};for(let u of t.issues)if(!s(u,"l"))e.issues.push(u);for(let u of r.issues)if(!s(u,"r"))e.issues.push(u);let c=[...o].filter(([,u])=>u.l&&u.r).map(([u])=>u);if(c.length){let u=n?c.filter((p)=>n.keys.includes(p)):[];if(u.length)e.issues.push({...n,keys:u});for(let p of c)if(!u.includes(p)&&i.has(p))e.issues.push(i.get(p))}let a=kr(t.value,r.value);if(!a.valid){if(ie(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`)}return e.value=a.data,e}var cs=h("$ZodEnum",(e,t)=>{E.init(e,t);let r=He(t.entries),o=new Set(r);e._zod.values=o,b(e,"pattern",(n)=>{let i=He(n.def.entries).filter((s)=>Yo.has(typeof s));return new RegExp(i.length?`^(${i.map((s)=>ge(s.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(n,i)=>{let s=n.value;if(o.has(s))return n;return n.issues.push({code:"invalid_value",values:r,input:s,inst:e}),n}}),as=h("$ZodLiteral",(e,t)=>{E.init(e,t);let r=new Set(t.values);e._zod.values=r,b(e,"pattern",(o)=>{let n=o.def.values;return new RegExp(n.length?`^(${n.map((i)=>typeof i==="string"?ge(i):i?ge(i.toString()):String(i)).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,n)=>{let i=o.value;if(r.has(i))return o;return o.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),o}});var us=h("$ZodTransform",(e,t)=>{E.init(e,t),e._zod.optin="optional",B.memoizer?.guard(e),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Xe(e.constructor.name);let n=t.transform(r.value,r);if(o.async)return(n instanceof Promise?n:Promise.resolve(n)).then((s)=>(r.value=s,r));if(n instanceof Promise)throw new se;return r.value=n,r}});function mi(e,t){return e.value=t.issues.length?void 0:t.value,e}var Er=h("$ZodOptional",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",b(e,"values",(r)=>{let o=r.def.innerType._zod.values;return o?new Set([...o,void 0]):void 0}),b(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${gt(o.source)})?$`):void 0}),e._zod.parse=(r,o)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let n=t.innerType._zod.run({value:r.value,issues:[]},o);if(n instanceof Promise)return n.then((i)=>mi(r,i));return mi(r,n)}return t.innerType._zod.run(r,o)}}),ps=h("$ZodExactOptional",(e,t)=>{Er.init(e,t),b(e,"values",(r)=>r.def.innerType._zod.values),b(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,o)=>t.innerType._zod.run(r,o)}),ls=h("$ZodNullable",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin),b(e,"optout",(r)=>r.def.innerType._zod.optout),b(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${gt(o.source)}|null)$`):void 0}),b(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,o)=>{if(r.value===null)return r;return t.innerType._zod.run(r,o)}}),fs=h("$ZodDefault",(e,t)=>{E.init(e,t),e._zod.optin="defaulted",b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);if(r.value===void 0)return r.value=t.defaultValue,r;let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then((i)=>gi(i,t));return gi(n,t)}});function gi(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var ds=h("$ZodPrefault",(e,t)=>{E.init(e,t),e._zod.optin="defaulted",b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,o)}}),hs=h("$ZodNonOptional",(e,t)=>{E.init(e,t),b(e,"values",(r)=>{let o=r.def.innerType._zod.values;return o?new Set([...o].filter((n)=>n!==void 0)):void 0}),e._zod.parse=(r,o)=>{let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then((i)=>yi(i,e));return yi(n,e)}});function yi(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function xi(e,t,r,o){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((n)=>ye(n,o,te()))},input:e.value}),e}var ms=h("$ZodCatch",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),b(e,"optout",(r)=>r.def.innerType._zod.optout),b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);let n=t.innerType._zod.run({value:r.value,issues:[]},o);if(n instanceof Promise)return n.then((i)=>xi(r,i,t,o));return xi(r,n,t,o)}});var gs=h("$ZodPipe",(e,t)=>{E.init(e,t),b(e,"values",(r)=>r.def.in._zod.values),b(e,"optin",(r)=>r.def.in._zod.optin),b(e,"optout",(r)=>r.def.out._zod.optout),b(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,o)=>{if(o.direction==="backward"){let i=t.out._zod.run(r,o);if(i instanceof Promise)return i.then((s)=>Ct(s,t.in,o));return Ct(i,t.in,o)}let n=t.in._zod.run(r,o);if(n instanceof Promise)return n.then((i)=>Ct(i,t.out,o));return Ct(n,t.out,o)}});function Ct(e,t,r){if(e.issues.some((o)=>o.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var ys=h("$ZodReadonly",(e,t)=>{E.init(e,t),b(e,"propValues",(r)=>r.def.innerType._zod.propValues),b(e,"values",(r)=>r.def.innerType._zod.values),b(e,"optin",(r)=>r.def.innerType?._zod?.optin),b(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then(vi);return vi(n)}});function vi(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var xs=h("$ZodCustom",(e,t)=>{N.init(e,t),E.init(e,t),e._zod.parse=(r,o)=>r,e._zod.check=(r)=>{let o=r.value,n=t.fn(o);if(n instanceof Promise)return n.then((i)=>wi(i,r,o,e));wi(n,r,o,e);return}});function wi(e,t,r,o){if(!e){let n={code:"custom",input:r,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};if(o._zod.def.params)n.params=o._zod.def.params;t.issues.push(ke(n))}}class ws extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var Or="~memo",vs=[];function _s(e){return e!==null&&typeof e==="object"}function Zr(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var bs=new WeakMap,et=0,Dt=1,tt=2;function Ft(e,t,r){let o=bs.get(e);if(o!==void 0)return o?tt:et;if(t.has(e))return tt;t.add(e);let n=et,i=(p)=>{if(n!==tt&&p?._zod){let l=Ft(p,t,r);if(l>n)n=l}},s=(p,l)=>{let f=et;for(let d of Reflect.ownKeys(p)){let g=Object.getOwnPropertyDescriptor(p,d);if(l&&!g.enumerable)continue;let m=g.get?Dt:g.value?._zod?Ft(g.value,t,r):et;if(m>f)f=m}return f},c=(p)=>{if(p>n)n=p},a=e._zod.def,u=a.type;switch(u){case"object":{let p=qe(a);c(p?s(p,!0):Dt),i(a.catchall);break}case"array":i(a.element);break;case"tuple":for(let p of a.items)i(p);i(a.rest);break;case"record":case"map":i(a.keyType),i(a.valueType);break;case"set":i(a.valueType);break;case"union":for(let p of a.options)i(p);break;case"intersection":i(a.left),i(a.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":i(a.innerType);break;case"pipe":i(a.in),i(a.out);break;case"function":i(a.input),i(a.output);break;case"lazy":{let p=a._cachedInner??(r?e._zod.innerType:void 0);c(p?Ft(p,t,!1):Dt);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let p in a){let l=Object.getOwnPropertyDescriptor(a,p);if(!l||l.get)continue;let f=l.value;if(!f||typeof f!=="object")continue;if(f._zod)i(f);else if(Array.isArray(f))for(let d of f)i(d)}}return t.delete(e),Lp(e,n)}function Lp(e,t){if(t!==Dt)bs.set(e,t===tt);return t}function Mp(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var Tt,jt=[],Up={alloc(e,t,r){let o=Tt;if(!o)return r;Tt=void 0;let n={value:r,issues:null};return o.set(t.value,n),jt.push(n),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,o=(n,i)=>{if(i.direction!=="backward"&&Wp(i,n.value))throw new ws;return r(n,i)};if(e._zod.parse=o,e._zod.run===r)e._zod.run=o})},attach(e){var t;let r,o=!1,n,i;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let s=e._zod.parse,c=(a,u)=>{if(r===void 0){let v=Ft(e,new Set,!1);if(v===et){if(e._zod.parse=s,e._zod.run===c)e._zod.run=s;return s(a,u)}if(v===tt||o)r=!0;else o=!0}let p=a.value;if(!_s(p))return s(a,u);let l=u[Or];if(!l)l={buckets:new WeakMap,backEdges:void 0},u[Or]=l;let f;if(n===u)f=i;else f=Mp(l,e),n=u,i=f;let d=f.get(p);if(d){if(a.value=d.value,d.issues){if(d.issues.length)a.issues.push(...Zr(d.issues))}else a.memo=!0,l.backEdges??(l.backEdges=new WeakSet),l.backEdges.add(d.value);return a}Tt=f;let g=jt.length,m=s(a,u);Tt=void 0;let y=jt.length>g?jt.pop():void 0;if(m instanceof Promise)return m.then((v)=>{if(y)y.issues=v.issues.length?Zr(v.issues):vs;return v});if(y)y.issues=m.issues.length?Zr(m.issues):vs;return m};if(e._zod.parse=c,e._zod.run===s)e._zod.run=c})}};function ks(){return Up}function Wp(e,t){let r=e[Or]?.backEdges;return r!==void 0&&_s(t)&&r.has(t)}var Bp=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(i){return e[i]??null}let r={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",currency_code:"currency code",credit_card:"credit card number",iban:"IBAN",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};function n(i,s){if(i==="number"&&typeof s==="number"&&!Number.isFinite(s))return String(s);return o[i]??i}return(i)=>{switch(i.code){case"invalid_type":{let s=n(i.expected),c=on(i.input),a=n(c,i.input);return`Invalid input: expected ${s}, received ${a}`}case"invalid_value":if(i.values.length===1)return`Invalid input: expected ${ar(i.values[0])}`;return`Invalid option: expected one of ${ir(i.values,"|")}`;case"too_big":{let s=i.exact?"exactly ":i.inclusive?"<=":"<",c=t(i.origin);if(c)return`Too big: expected ${i.origin??"value"} to have ${s}${i.maximum.toString()} ${c.unit??"elements"}`;return`Too big: expected ${i.origin??"value"} to be ${s}${i.maximum.toString()}`}case"too_small":{let s=i.exact?"exactly ":i.inclusive?">=":">",c=t(i.origin);if(c)return`Too small: expected ${i.origin} to have ${s}${i.minimum.toString()} ${c.unit}`;return`Too small: expected ${i.origin} to be ${s}${i.minimum.toString()}`}case"invalid_format":{let s=i;if(s.format==="starts_with")return`Invalid string: must start with "${s.prefix}"`;if(s.format==="ends_with")return`Invalid string: must end with "${s.suffix}"`;if(s.format==="includes")return`Invalid string: must include "${s.includes}"`;if(s.format==="regex")return`Invalid string: must match pattern ${s.pattern}`;return`Invalid ${r[s.format]??i.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${i.divisor}`;case"unrecognized_keys":return`Unrecognized key${i.keys.length>1?"s":""}: ${ir(i.keys,", ")}`;case"invalid_key":return`Invalid key in ${i.origin}`;case"invalid_union":if(i.options&&Array.isArray(i.options)&&i.options.length>0)return`Invalid discriminator value. Expected ${i.options.map((c)=>`'${c}'`).join(" | ")}`;if(i.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${i.origin}`;default:return"Invalid input"}}};function Cr(){return{localeError:Bp()}}var $s;class zs{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let o={...r,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function Jp(){return new zs}($s=globalThis).__zod_globalRegistry??($s.__zod_globalRegistry=Jp());var $e=globalThis.__zod_globalRegistry;function Lt(e){if(e.checks)e.checks=[...e.checks];return e}function Ss(e,t){return new e(Lt({type:"string",...x(t)}))}function Ps(e,t){return new e(Lt({type:"string",coerce:!0,...x(t)}))}function Es(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...x(t)})}function Zs(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...x(t)})}function Rr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...x(t)})}function Os(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...x(t)})}function Cs(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...x(t)})}function Rs(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...x(t)})}function Ir(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...x(t)})}function Is(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...x(t)})}function As(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...x(t)})}function Ns(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...x(t)})}function Ts(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...x(t)})}function js(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...x(t)})}function Ds(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...x(t)})}function Fs(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...x(t)})}function Ls(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...x(t)})}function Ms(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...x(t)})}function Us(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...x(t)})}function Ws(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...x(t)})}function Bs(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...x(t)})}function Js(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...x(t)})}function Vs(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...x(t)})}function Hs(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...x(t)})}function Ks(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...x(t)})}function Gs(e,t){return new e({type:"string",format:"date",check:"string_format",...x(t)})}function qs(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...x(t)})}function Xs(e,t){return new e({type:"string",format:"duration",check:"string_format",...x(t)})}function Ys(e,t){return new e(Lt({type:"number",checks:[],...x(t)}))}function Qs(e,t){return new e(Lt({type:"number",coerce:!0,checks:[],...x(t)}))}function ec(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...x(t)})}function tc(e,t){return new e({type:"boolean",...x(t)})}function rc(e,t){return new e({type:"boolean",coerce:!0,...x(t)})}function oc(e,t){return new e({type:"bigint",coerce:!0,...x(t)})}function nc(e){return new e({type:"unknown"})}function ic(e,t){return new e({type:"never",...x(t)})}function sc(e,t){return new e({type:"date",coerce:!0,...x(t)})}function Ie(e,t){return new wr({check:"less_than",...x(t),value:e,inclusive:!1})}function le(e,t){return new wr({check:"less_than",...x(t),value:e,inclusive:!0})}function Ae(e,t){return new _r({check:"greater_than",...x(t),value:e,inclusive:!1})}function fe(e,t){return new _r({check:"greater_than",...x(t),value:e,inclusive:!0})}function rt(e,t){return new Xn({check:"multiple_of",...x(t),value:e})}function Mt(e,t){return new Qn({check:"max_length",...x(t),maximum:e})}function Ne(e,t){return new ei({check:"min_length",...x(t),minimum:e})}function Ut(e,t){return new ti({check:"length_equals",...x(t),length:e})}function Ar(e,t){return new ri({check:"string_format",format:"regex",...x(t),pattern:e})}function Nr(e){return new oi({check:"string_format",format:"lowercase",...x(e)})}function Tr(e){return new ni({check:"string_format",format:"uppercase",...x(e)})}function jr(e,t){return new ii({check:"string_format",format:"includes",...x(t),includes:e})}function Dr(e,t){return new si({check:"string_format",format:"starts_with",...x(t),prefix:e})}function Fr(e,t){return new ci({check:"string_format",format:"ends_with",...x(t),suffix:e})}function xe(e){return new ai({check:"overwrite",tx:e})}function Lr(e){return xe((t)=>t.normalize(e))}function Mr(){return xe((e)=>e.trim())}function Ur(){return xe((e)=>e.toLowerCase())}function Wr(){return xe((e)=>e.toUpperCase())}function Br(){return xe((e)=>qo(e))}function cc(e,t,r){return new e({type:"array",element:t,...x(r)})}function ac(e,t,r){return new e({type:"custom",check:"custom",fn:t,...x(r)})}function uc(e,t){let r=Vp((o)=>(o.addIssue=(n)=>{if(typeof n==="string")o.issues.push(ke(n,o.value,r._zod.def));else{let i=n;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=o.value;i.inst??(i.inst=r),i.continue??(i.continue=!r._zod.def.abort),o.issues.push(ke(i))}},e(o.value,o)),t);return r}function Vp(e,t){let r=new N({check:"custom",...x(t)});return r._zod.check=e,r}function ot(e,...t){for(let r of t)for(let o of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,o))Q(e,o,r[o]);return e}function Vr(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??$e,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??"ref",reused:e?.reused??"inline",intersections:[],deferred:[],external:e?.external??void 0}}function re(e,t,r,o,n){let i=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:o.path,message:n}):t.unrepresentable;if(i==="any")return!1;if(i===void 0||i==="throw")throw Error(n);return Object.assign(r,i),!0}function A(e,t,r={path:[],schemaPath:[]}){var o;let n=e._zod.def,i=t.seen.get(e);if(i){if(i.count++,r.schemaPath.includes(e))i.cycle=r.path;return i.schema}let s={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,s),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let c=e._zod.toJSONSchema?.();if(c)s.schema=c;else{let p={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,p);else{let f=s.schema,d=t.processors[n.type];if(!d)throw Error(`[toJSONSchema]: Non-representable type encountered: ${n.type}`);d(e,t,f,p)}let l=e._zod.parent;if(l){if(!s.ref)s.ref=l;A(l,t,p),t.seen.get(l).isParent=!0}}let a=t.metadataRegistry.get(e);if(a)ot(s.schema,a);if(t.io==="input"&&F(e))delete s.schema.examples,delete s.schema.default;if(t.io==="input"&&"_prefault"in s.schema)(o=s.schema).default??(o.default=s.schema._prefault);return delete s.schema._prefault,t.seen.get(e).schema}function pc(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Hr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let o=new Map;for(let s of e.seen.entries()){let c=e.metadataRegistry.get(s[0])?.id;if(c){let a=o.get(c);if(a&&a!==s[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(c,s[0])}}let n=(s)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let l=e.external.registry.get(s[0])?.id,f=e.external.uri??((g)=>g);if(l)return{ref:f(l)};let d=s[1].defId??s[1].schema.id??`schema${e.counter++}`;return s[1].defId=d,{defId:d,ref:`${f("__shared")}#/${c}/${pc(d)}`}}let a="#",u=`${a}/${c}/`;if(s[1]===r&&!s[1].schema.id)return{ref:a};let p=s[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:u+pc(p)}},i=(s)=>{if(s[1].schema.$ref)return;let c=s[1],{ref:a,defId:u}=n(s);if(c.def={...c.schema},u)c.defId=u;let p=c.schema;for(let l in p)delete p[l];p.$ref=a};if(e.cycles==="throw")for(let s of e.seen.entries()){let c=s[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
56
+ `)}return y.write("payload.value = newResult;"),y.write("return payload;"),y.compile()},i,c=Ce,a=!J.jitless,p=a&&en.value,l=t.catchall,f;e._zod.parse=(d,m)=>{f??(f=o.value);let g=d.value;if(!c(g))return d.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),d;if(a&&p&&m?.async===!1&&m.jitless!==!0){if(!i)i=s(t.shape);if(d=i(d,m),!l)return d;return ii([],g,d,m,f,e,m?.abortEarly===!0)}return r(d,m)}});function gs(e,t,r,o){for(let s of e)if(s.issues.length===0)return t.value=s.value,t;let n=e.filter((s)=>!se(s));if(n.length===1)return t.value=n[0].value,n[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((s)=>s.issues.map((i)=>xe(i,o,te())))}),t}var Rr=h("$ZodUnion",(e,t)=>{E.init(e,t),b(e,"optin",(o)=>o.def.options.some((n)=>n._zod.optin==="defaulted")?"defaulted":o.def.options.some((n)=>n._zod.optin!==void 0)?"optional":void 0),b(e,"optout",(o)=>o.def.options.some((n)=>n._zod.optout==="optional")?"optional":void 0),b(e,"values",(o)=>{if(o.def.options.every((n)=>n._zod.values))return new Set(o.def.options.flatMap((n)=>Array.from(n._zod.values)));return}),b(e,"pattern",(o)=>{if(o.def.options.every((n)=>n._zod.pattern)){let n=o.def.options.map((s)=>s._zod.pattern);return new RegExp(`^(${n.map((s)=>vt(s.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(o,n)=>{if(r)return r(o,n);let s=!1,i=[];for(let c of t.options){let a=c._zod.run({value:o.value,issues:[]},n);if(a instanceof Promise)i.push(a),s=!0;else{if(a.issues.length===0)return a;i.push(a)}}if(!s)return gs(i,o,e,n);return Promise.all(i).then((c)=>gs(c,o,e,n))}});function Up(e){let t=new Map;for(let r of e.options){let o=r._zod.propValues?.[e.discriminator];if(!o||o.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);for(let n of o)if(t.has(n)){if(n!==void 0)throw Error(`Duplicate discriminator value "${String(n)}"`);t.set(n,null)}else t.set(n,r)}return t}var ai=h("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Rr.init(e,t);let r=e._zod.parse;b(e,"propValues",(n)=>{let s={},i=0;for(let c of n.def.options){let a=c._zod.propValues;if(!a||Object.keys(a).length===0)throw Error(`Invalid discriminated union option at index "${n.def.options.indexOf(c)}"`);if(a[n.def.discriminator]?.has(void 0))i++;for(let[u,p]of Object.entries(a)){if(!Object.prototype.hasOwnProperty.call(s,u))Q(s,u,new Set);for(let l of p)s[u].add(l)}}if(!n.def.unionFallback&&i>1)s[n.def.discriminator]?.delete(void 0);return s}),t.options.forEach((n,s)=>{let i=Xe(n._zod.def);if(i&&!Object.prototype.hasOwnProperty.call(i,t.discriminator))throw Error(`Invalid discriminated union option at index "${s}"`)});let o=qe(()=>Up(t));e._zod.parse=(n,s)=>{let i=n.value;if(!Ce(i))return n.issues.push({code:"invalid_type",expected:"object",input:i,inst:e}),n;let c=i?.[t.discriminator],a=o.value.get(c);if(a&&(c!==void 0||s.direction!=="backward"))return a._zod.run(n,s);if(t.unionFallback||s.direction==="backward")return r(n,s);return n.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(o.value.keys()).filter((u)=>o.value.get(u)!==null),input:i,path:[t.discriminator],inst:e}),n}}),ui=h("$ZodIntersection",(e,t)=>{E.init(e,t),e._zod.parse=(r,o)=>{let n=r.value,s=t.left._zod.run({value:n,issues:[]},o),i=t.right._zod.run({value:n,issues:[]},o);if(s instanceof Promise||i instanceof Promise)return Promise.all([s,i]).then(([a,u])=>ys(r,a,u));return ys(r,s,i)}});function Pr(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(Ie(e)&&Ie(t)){let r=Object.keys(t),o=Object.keys(e).filter((s)=>r.indexOf(s)!==-1),n={...e,...t};if(Object.prototype.hasOwnProperty.call(n,"__proto__"))delete n.__proto__;for(let s of o){if(s==="__proto__")continue;let i=Pr(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};n[s]=i.data}return{valid:!0,data:n}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let o=0;o<e.length;o++){let n=e[o],s=t[o],i=Pr(n,s);if(!i.valid)return{valid:!1,mergeErrorPath:[o,...i.mergeErrorPath]};r.push(i.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function ys(e,t,r){let o=new Map,n,s=new Map,i=(u,p)=>{let l;if(u.code==="unrecognized_keys"&&!u.path?.length)n??(n=u),l=u.keys;else if(u.code==="invalid_key"&&u.origin==="record"&&u.path?.length===1){let f=String(u.path[0]);if(!s.has(f))s.set(f,u);l=[f]}else return!1;for(let f of l){if(!o.has(f))o.set(f,{});o.get(f)[p]=!0}return!0};for(let u of t.issues)if(!i(u,"l"))e.issues.push(u);for(let u of r.issues)if(!i(u,"r"))e.issues.push(u);let c=[...o].filter(([,u])=>u.l&&u.r).map(([u])=>u);if(c.length){let u=n?c.filter((p)=>n.keys.includes(p)):[];if(u.length)e.issues.push({...n,keys:u});for(let p of c)if(!u.includes(p)&&s.has(p))e.issues.push(s.get(p))}let a=Pr(t.value,r.value);if(!a.valid){if(se(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`)}return e.value=a.data,e}var pi=h("$ZodEnum",(e,t)=>{E.init(e,t);let r=Ke(t.entries),o=new Set(r);e._zod.values=o,b(e,"pattern",(n)=>{let s=Ke(n.def.entries).filter((i)=>tn.has(typeof i));return new RegExp(s.length?`^(${s.map((i)=>ye(i.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(n,s)=>{let i=n.value;if(o.has(i))return n;return n.issues.push({code:"invalid_value",values:r,input:i,inst:e}),n}}),li=h("$ZodLiteral",(e,t)=>{E.init(e,t);let r=new Set(t.values);e._zod.values=r,b(e,"pattern",(o)=>{let n=o.def.values;return new RegExp(n.length?`^(${n.map((s)=>typeof s==="string"?ye(s):s?ye(s.toString()):String(s)).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,n)=>{let s=o.value;if(r.has(s))return o;return o.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),o}});var fi=h("$ZodTransform",(e,t)=>{E.init(e,t),e._zod.optin="optional",J.memoizer?.guard(e),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Ye(e.constructor.name);let n=t.transform(r.value,r);if(o.async)return(n instanceof Promise?n:Promise.resolve(n)).then((i)=>(r.value=i,r));if(n instanceof Promise)throw new ie;return r.value=n,r}});function xs(e,t){return e.value=t.issues.length?void 0:t.value,e}var Cr=h("$ZodOptional",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",b(e,"values",(r)=>{let o=r.def.innerType._zod.values;return o?new Set([...o,void 0]):void 0}),b(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${vt(o.source)})?$`):void 0}),e._zod.parse=(r,o)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let n=t.innerType._zod.run({value:r.value,issues:[]},o);if(n instanceof Promise)return n.then((s)=>xs(r,s));return xs(r,n)}return t.innerType._zod.run(r,o)}}),di=h("$ZodExactOptional",(e,t)=>{Cr.init(e,t),b(e,"values",(r)=>r.def.innerType._zod.values),b(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,o)=>t.innerType._zod.run(r,o)}),hi=h("$ZodNullable",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin),b(e,"optout",(r)=>r.def.innerType._zod.optout),b(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${vt(o.source)}|null)$`):void 0}),b(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,o)=>{if(r.value===null)return r;return t.innerType._zod.run(r,o)}}),mi=h("$ZodDefault",(e,t)=>{E.init(e,t),e._zod.optin="defaulted",b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);if(r.value===void 0)return r.value=t.defaultValue,r;let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then((s)=>vs(s,t));return vs(n,t)}});function vs(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var gi=h("$ZodPrefault",(e,t)=>{E.init(e,t),e._zod.optin="defaulted",b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,o)}}),yi=h("$ZodNonOptional",(e,t)=>{E.init(e,t),b(e,"values",(r)=>{let o=r.def.innerType._zod.values;return o?new Set([...o].filter((n)=>n!==void 0)):void 0}),e._zod.parse=(r,o)=>{let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then((s)=>ws(s,e));return ws(n,e)}});function ws(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function _s(e,t,r,o){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((n)=>xe(n,o,te()))},input:e.value}),e}var xi=h("$ZodCatch",(e,t)=>{E.init(e,t),b(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),b(e,"optout",(r)=>r.def.innerType._zod.optout),b(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);let n=t.innerType._zod.run({value:r.value,issues:[]},o);if(n instanceof Promise)return n.then((s)=>_s(r,s,t,o));return _s(r,n,t,o)}});var vi=h("$ZodPipe",(e,t)=>{E.init(e,t),b(e,"values",(r)=>r.def.in._zod.values),b(e,"optin",(r)=>r.def.in._zod.optin),b(e,"optout",(r)=>r.def.out._zod.optout),b(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,o)=>{if(o.direction==="backward"){let s=t.out._zod.run(r,o);if(s instanceof Promise)return s.then((i)=>At(i,t.in,o));return At(s,t.in,o)}let n=t.in._zod.run(r,o);if(n instanceof Promise)return n.then((s)=>At(s,t.out,o));return At(n,t.out,o)}});function At(e,t,r){if(e.issues.some((o)=>o.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var wi=h("$ZodReadonly",(e,t)=>{E.init(e,t),b(e,"propValues",(r)=>r.def.innerType._zod.propValues),b(e,"values",(r)=>r.def.innerType._zod.values),b(e,"optin",(r)=>r.def.innerType?._zod?.optin),b(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,o)=>{if(o.direction==="backward")return t.innerType._zod.run(r,o);let n=t.innerType._zod.run(r,o);if(n instanceof Promise)return n.then(bs);return bs(n)}});function bs(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var _i=h("$ZodCustom",(e,t)=>{T.init(e,t),E.init(e,t),e._zod.parse=(r,o)=>r,e._zod.check=(r)=>{let o=r.value,n=t.fn(o);if(n instanceof Promise)return n.then((s)=>ks(s,r,o,e));ks(n,r,o,e);return}});function ks(e,t,r,o){if(!e){let n={code:"custom",input:r,inst:o,path:[...o._zod.def.path??[]],continue:!o._zod.def.abort};if(o._zod.def.params)n.params=o._zod.def.params;t.issues.push($e(n))}}class ki extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var Ar="~memo",bi=[];function $i(e){return e!==null&&typeof e==="object"}function Ir(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var zi=new WeakMap,tt=0,Mt=1,rt=2;function Wt(e,t,r){let o=zi.get(e);if(o!==void 0)return o?rt:tt;if(t.has(e))return rt;t.add(e);let n=tt,s=(p)=>{if(n!==rt&&p?._zod){let l=Wt(p,t,r);if(l>n)n=l}},i=(p,l)=>{let f=tt;for(let d of Reflect.ownKeys(p)){let m=Object.getOwnPropertyDescriptor(p,d);if(l&&!m.enumerable)continue;let g=m.get?Mt:m.value?._zod?Wt(m.value,t,r):tt;if(g>f)f=g}return f},c=(p)=>{if(p>n)n=p},a=e._zod.def,u=a.type;switch(u){case"object":{let p=Xe(a);c(p?i(p,!0):Mt),s(a.catchall);break}case"array":s(a.element);break;case"tuple":for(let p of a.items)s(p);s(a.rest);break;case"record":case"map":s(a.keyType),s(a.valueType);break;case"set":s(a.valueType);break;case"union":for(let p of a.options)s(p);break;case"intersection":s(a.left),s(a.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":s(a.innerType);break;case"pipe":s(a.in),s(a.out);break;case"function":s(a.input),s(a.output);break;case"lazy":{let p=a._cachedInner??(r?e._zod.innerType:void 0);c(p?Wt(p,t,!1):Mt);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let p in a){let l=Object.getOwnPropertyDescriptor(a,p);if(!l||l.get)continue;let f=l.value;if(!f||typeof f!=="object")continue;if(f._zod)s(f);else if(Array.isArray(f))for(let d of f)s(d)}}return t.delete(e),Bp(e,n)}function Bp(e,t){if(t!==Mt)zi.set(e,t===rt);return t}function Jp(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var Ft,Lt=[],Vp={alloc(e,t,r){let o=Ft;if(!o)return r;Ft=void 0;let n={value:r,issues:null};return o.set(t.value,n),Lt.push(n),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,o=(n,s)=>{if(s.direction!=="backward"&&Hp(s,n.value))throw new ki;return r(n,s)};if(e._zod.parse=o,e._zod.run===r)e._zod.run=o})},attach(e){var t;let r,o=!1,n,s;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let i=e._zod.parse,c=(a,u)=>{if(r===void 0){let v=Wt(e,new Set,!1);if(v===tt){if(e._zod.parse=i,e._zod.run===c)e._zod.run=i;return i(a,u)}if(v===rt||o)r=!0;else o=!0}let p=a.value;if(!$i(p))return i(a,u);let l=u[Ar];if(!l)l={buckets:new WeakMap,backEdges:void 0},u[Ar]=l;let f;if(n===u)f=s;else f=Jp(l,e),n=u,s=f;let d=f.get(p);if(d){if(a.value=d.value,d.issues){if(d.issues.length)a.issues.push(...Ir(d.issues))}else a.memo=!0,l.backEdges??(l.backEdges=new WeakSet),l.backEdges.add(d.value);return a}Ft=f;let m=Lt.length,g=i(a,u);Ft=void 0;let y=Lt.length>m?Lt.pop():void 0;if(g instanceof Promise)return g.then((v)=>{if(y)y.issues=v.issues.length?Ir(v.issues):bi;return v});if(y)y.issues=g.issues.length?Ir(g.issues):bi;return g};if(e._zod.parse=c,e._zod.run===i)e._zod.run=c})}};function Si(){return Vp}function Hp(e,t){let r=e[Ar]?.backEdges;return r!==void 0&&$i(t)&&r.has(t)}var Kp=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(s){return e[s]??null}let r={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",currency_code:"currency code",credit_card:"credit card number",iban:"IBAN",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};function n(s,i){if(s==="number"&&typeof i==="number"&&!Number.isFinite(i))return String(i);return o[s]??s}return(s)=>{switch(s.code){case"invalid_type":{let i=n(s.expected),c=cn(s.input),a=n(c,s.input);return`Invalid input: expected ${i}, received ${a}`}case"invalid_value":if(s.values.length===1)return`Invalid input: expected ${fr(s.values[0])}`;return`Invalid option: expected one of ${ur(s.values,"|")}`;case"too_big":{let i=s.exact?"exactly ":s.inclusive?"<=":"<",c=t(s.origin);if(c)return`Too big: expected ${s.origin??"value"} to have ${i}${s.maximum.toString()} ${c.unit??"elements"}`;return`Too big: expected ${s.origin??"value"} to be ${i}${s.maximum.toString()}`}case"too_small":{let i=s.exact?"exactly ":s.inclusive?">=":">",c=t(s.origin);if(c)return`Too small: expected ${s.origin} to have ${i}${s.minimum.toString()} ${c.unit}`;return`Too small: expected ${s.origin} to be ${i}${s.minimum.toString()}`}case"invalid_format":{let i=s;if(i.format==="starts_with")return`Invalid string: must start with "${i.prefix}"`;if(i.format==="ends_with")return`Invalid string: must end with "${i.suffix}"`;if(i.format==="includes")return`Invalid string: must include "${i.includes}"`;if(i.format==="regex")return`Invalid string: must match pattern ${i.pattern}`;return`Invalid ${r[i.format]??s.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${s.divisor}`;case"unrecognized_keys":return`Unrecognized key${s.keys.length>1?"s":""}: ${ur(s.keys,", ")}`;case"invalid_key":return`Invalid key in ${s.origin}`;case"invalid_union":if(s.options&&Array.isArray(s.options)&&s.options.length>0)return`Invalid discriminator value. Expected ${s.options.map((c)=>`'${c}'`).join(" | ")}`;if(s.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${s.origin}`;default:return"Invalid input"}}};function Tr(){return{localeError:Kp()}}var Pi;class Ei{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let o={...r,...this._map.get(e)};return Object.keys(o).length?o:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function Gp(){return new Ei}(Pi=globalThis).__zod_globalRegistry??(Pi.__zod_globalRegistry=Gp());var ze=globalThis.__zod_globalRegistry;function Ut(e){if(e.checks)e.checks=[...e.checks];return e}function Zi(e,t){return new e(Ut({type:"string",...x(t)}))}function Oi(e,t){return new e(Ut({type:"string",coerce:!0,...x(t)}))}function Ri(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...x(t)})}function Ci(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...x(t)})}function Nr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...x(t)})}function Ii(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...x(t)})}function Ai(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...x(t)})}function Ti(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...x(t)})}function jr(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...x(t)})}function Ni(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...x(t)})}function ji(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...x(t)})}function Di(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...x(t)})}function Fi(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...x(t)})}function Li(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...x(t)})}function Mi(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...x(t)})}function Wi(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...x(t)})}function Ui(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...x(t)})}function Bi(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...x(t)})}function Ji(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...x(t)})}function Vi(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...x(t)})}function Hi(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...x(t)})}function Ki(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...x(t)})}function Gi(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...x(t)})}function qi(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...x(t)})}function Xi(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...x(t)})}function Yi(e,t){return new e({type:"string",format:"date",check:"string_format",...x(t)})}function Qi(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...x(t)})}function ec(e,t){return new e({type:"string",format:"duration",check:"string_format",...x(t)})}function tc(e,t){return new e(Ut({type:"number",checks:[],...x(t)}))}function rc(e,t){return new e(Ut({type:"number",coerce:!0,checks:[],...x(t)}))}function oc(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...x(t)})}function nc(e,t){return new e({type:"boolean",...x(t)})}function sc(e,t){return new e({type:"boolean",coerce:!0,...x(t)})}function ic(e,t){return new e({type:"bigint",coerce:!0,...x(t)})}function cc(e){return new e({type:"unknown"})}function ac(e,t){return new e({type:"never",...x(t)})}function uc(e,t){return new e({type:"date",coerce:!0,...x(t)})}function Ae(e,t){return new $r({check:"less_than",...x(t),value:e,inclusive:!1})}function le(e,t){return new $r({check:"less_than",...x(t),value:e,inclusive:!0})}function Te(e,t){return new zr({check:"greater_than",...x(t),value:e,inclusive:!1})}function fe(e,t){return new zr({check:"greater_than",...x(t),value:e,inclusive:!0})}function ot(e,t){return new es({check:"multiple_of",...x(t),value:e})}function Bt(e,t){return new rs({check:"max_length",...x(t),maximum:e})}function Ne(e,t){return new os({check:"min_length",...x(t),minimum:e})}function Jt(e,t){return new ns({check:"length_equals",...x(t),length:e})}function Dr(e,t){return new ss({check:"string_format",format:"regex",...x(t),pattern:e})}function Fr(e){return new is({check:"string_format",format:"lowercase",...x(e)})}function Lr(e){return new cs({check:"string_format",format:"uppercase",...x(e)})}function Mr(e,t){return new as({check:"string_format",format:"includes",...x(t),includes:e})}function Wr(e,t){return new us({check:"string_format",format:"starts_with",...x(t),prefix:e})}function Ur(e,t){return new ps({check:"string_format",format:"ends_with",...x(t),suffix:e})}function ve(e){return new ls({check:"overwrite",tx:e})}function Br(e){return ve((t)=>t.normalize(e))}function Jr(){return ve((e)=>e.trim())}function Vr(){return ve((e)=>e.toLowerCase())}function Hr(){return ve((e)=>e.toUpperCase())}function Kr(){return ve((e)=>Qo(e))}function pc(e,t,r){return new e({type:"array",element:t,...x(r)})}function lc(e,t,r){return new e({type:"custom",check:"custom",fn:t,...x(r)})}function fc(e,t){let r=qp((o)=>(o.addIssue=(n)=>{if(typeof n==="string")o.issues.push($e(n,o.value,r._zod.def));else{let s=n;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=o.value;s.inst??(s.inst=r),s.continue??(s.continue=!r._zod.def.abort),o.issues.push($e(s))}},e(o.value,o)),t);return r}function qp(e,t){let r=new T({check:"custom",...x(t)});return r._zod.check=e,r}function nt(e,...t){for(let r of t)for(let o of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,o))Q(e,o,r[o]);return e}function qr(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??ze,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??"ref",reused:e?.reused??"inline",intersections:[],deferred:[],external:e?.external??void 0}}function re(e,t,r,o,n){let s=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:o.path,message:n}):t.unrepresentable;if(s==="any")return!1;if(s===void 0||s==="throw")throw Error(n);return Object.assign(r,s),!0}function A(e,t,r={path:[],schemaPath:[]}){var o;let n=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,r.schemaPath.includes(e))s.cycle=r.path;return s.schema}let i={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,i),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let c=e._zod.toJSONSchema?.();if(c)i.schema=c;else{let p={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,p);else{let f=i.schema,d=t.processors[n.type];if(!d)throw Error(`[toJSONSchema]: Non-representable type encountered: ${n.type}`);d(e,t,f,p)}let l=e._zod.parent;if(l){if(!i.ref)i.ref=l;A(l,t,p),t.seen.get(l).isParent=!0}}let a=t.metadataRegistry.get(e);if(a)nt(i.schema,a);if(t.io==="input"&&L(e))delete i.schema.examples,delete i.schema.default;if(t.io==="input"&&"_prefault"in i.schema)(o=i.schema).default??(o.default=i.schema._prefault);return delete i.schema._prefault,t.seen.get(e).schema}function dc(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Xr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let o=new Map;for(let i of e.seen.entries()){let c=e.metadataRegistry.get(i[0])?.id;if(c){let a=o.get(c);if(a&&a!==i[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);o.set(c,i[0])}}let n=(i)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let l=e.external.registry.get(i[0])?.id,f=e.external.uri??((m)=>m);if(l)return{ref:f(l)};let d=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=d,{defId:d,ref:`${f("__shared")}#/${c}/${dc(d)}`}}let a="#",u=`${a}/${c}/`;if(i[1]===r&&!i[1].schema.id)return{ref:a};let p=i[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:u+dc(p)}},s=(i)=>{if(i[1].schema.$ref)return;let c=i[1],{ref:a,defId:u}=n(i);if(c.def={...c.schema},u)c.defId=u;let p=c.schema;for(let l in p)delete p[l];p.$ref=a};if(e.cycles==="throw")for(let i of e.seen.entries()){let c=i[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
57
57
 
58
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of e.seen.entries()){let c=s[1];if(t===s[0]){i(s);continue}if(e.external){let u=e.external.registry.get(s[0])?.id;if(t!==s[0]&&u){i(s);continue}}if(e.metadataRegistry.get(s[0])?.id){i(s);continue}if(c.cycle){i(s);continue}if(c.count>1){if(e.reused==="ref")i(s)}}if(e.external)e.sharedDefsExtractedFor=e.external}function dc(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let o of t){if(!o||typeof o!=="object")return;dc(o);let n=Object.keys(o);if(n.length!==1||n[0]!=="type")return;let i=o.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!=="string")return;if(!r.includes(s))r.push(s)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var hc=new Set(["type","properties","required","additionalProperties"]),lc=["oneOf","anyOf"];function fc(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function Jr(e){let t=[];for(let i of e){if(typeof i!=="object"||i.type!=="object")return null;for(let s in i)if(!hc.has(s))return null;t.push(i)}let r={},o=new Set;for(let i of t){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let c=[];for(let u of t){let p=u.properties?.[s]??fc(u);if(p===null||p===void 0)continue;if(!c.some((l)=>JSON.stringify(l)===JSON.stringify(p)))c.push(p)}let a=c.length===1?c[0]:Jr(c)??{allOf:c};Q(r,s,a)}for(let s of i.required??[])o.add(s)}let n={type:"object",properties:r};if(o.size)n.required=[...o];if(t.every((i)=>i.additionalProperties===!1))n.additionalProperties=!1;else{let i=[];for(let s of t){let c=fc(s);if(c&&!i.some((a)=>JSON.stringify(a)===JSON.stringify(c)))i.push(c)}if(i.length===1)n.additionalProperties=i[0];else if(i.length>1)n.additionalProperties={allOf:i}}return n}function Hp(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let n of hc)if(n in e)return;let r=t.filter((n)=>lc.some((i)=>Array.isArray(n[i]))),o=null;if(!r.length)o=Jr(t);else{let n=r[0],i=lc.find((a)=>Array.isArray(n[a]));if(Object.keys(n).length!==1)return;let s=t.filter((a)=>a!==n),c=n[i].map((a)=>Jr([...s,a]));if(c.some((a)=>!a))return;o={[i]:c}}if(!o)return;delete e.allOf,ot(e,o)}function Kr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let o=(c)=>{let a=e.seen.get(c);if(a.ref===null)return;let u=a.def??a.schema,p={...u},l=a.ref;if(a.ref=null,l){o(l);let d=e.seen.get(l),g=d.schema;if(g.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))u.allOf=u.allOf??[],u.allOf.push(g);else ot(u,g);if(ot(u,p),c._zod.parent===l)for(let y in u){if(y==="$ref"||y==="allOf")continue;if(!(y in p))delete u[y]}if(g.$ref&&d.def)for(let y in u){if(y==="$ref"||y==="allOf")continue;if(y in d.def&&JSON.stringify(u[y])===JSON.stringify(d.def[y]))delete u[y]}}let f=c._zod.parent;if(f&&f!==l){o(f);let d=e.seen.get(f);if(d?.schema.$ref){if(u.$ref=d.schema.$ref,d.def)for(let g in u){if(g==="$ref"||g==="allOf")continue;if(g in d.def&&JSON.stringify(u[g])===JSON.stringify(d.def[g]))delete u[g]}}}e.override({zodSchema:c,jsonSchema:u,path:a.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let c of[...e.seen.entries()].reverse())o(c[0]);if(e.target!=="openapi-3.0")for(let c of e.seen.entries())dc(c[1].def??c[1].schema);for(let c of e.deferred)c();if(e.intersections.length){let c=new Map;for(let a of e.seen.values())for(let u of[a.schema,a.def]){let p=u?.allOf;if(!Array.isArray(p))continue;let l=c.get(p);if(l)l.push(u);else c.set(p,[u])}for(let a of e.intersections)for(let u of c.get(a)??[])Hp(u)}}let n={};if(e.target==="draft-2020-12")n.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")n.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")n.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let c=e.external.registry.get(t)?.id;if(!c)throw Error("Schema is missing an `id` property");n.$id=e.external.uri(c)}ot(n,r.defId?r.schema:r.def??r.schema);let i=e.metadataRegistry.get(t)?.id;if(i!==void 0&&n.id===i)delete n.id;let s=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let c of e.seen.entries()){let a=c[1];if(a.def&&a.defId){if(a.def.id===a.defId)delete a.def.id;Q(s,a.defId,a.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")n.$defs=s;else n.definitions=s;try{let c=JSON.parse(JSON.stringify(n));return Object.defineProperty(c,"~standard",{value:{...t["~standard"],jsonSchema:{input:nt(t,"input",e.processors),output:nt(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch(c){throw Error("Error converting schema to JSON.")}}function F(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return F(o.element,r);if(o.type==="set")return F(o.valueType,r);if(o.type==="lazy")return F(o.getter(),r);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return F(o.innerType,r);if(o.type==="intersection")return F(o.left,r)||F(o.right,r);if(o.type==="record"||o.type==="map")return F(o.keyType,r)||F(o.valueType,r);if(o.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return F(o.in,r)||F(o.out,r)}if(o.type==="object"){for(let n in o.shape)if(F(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(F(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(F(n,r))return!0;if(o.rest&&F(o.rest,r))return!0;return!1}return!1}var mc=(e,t={})=>(r)=>{let o=Vr({...r,processors:t});return A(e,o),Hr(o,e),Kr(o,e)},nt=(e,t,r={})=>(o)=>{let{libraryOptions:n,target:i}=o??{},s=Vr({...n??{},target:i,io:t,processors:r});return A(e,s),Hr(s,e),Kr(s,e)};var Te=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},je=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},gc=(e,t)=>{Te(e,"minimum",t),je(e,"maximum",t)},wc=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},_c=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},bc=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},kc=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},yc=(e,t)=>Te(e,"minimum",t.minimum),xc=(e,t)=>je(e,"maximum",t.maximum),vc=(e)=>(t,r)=>{kc(t,r.format);let[o,n]=e[r.format];Te(t,"minimum",o),je(t,"maximum",n)},Kp={greater_than:(e,t)=>Te(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>je(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>wc(e,t.value),number_format:vc(yt),bigint_format:vc(ur),min_length:yc,max_length:xc,length_equals:(e,t)=>gc(e,t.length),min_size:yc,max_size:xc,size_equals:(e,t)=>gc(e,t.size),string_format:(e,t)=>{if(kc(e,t.format),t.pattern)_c(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>bc(e,t.mime)};function j(e){let t={},r=e._zod.def,o=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let i of o)Kp[i._zod.def.check]?.(t,i._zod.def);let n=e._zod.bag;if(n.minimum!==void 0)Te(t,"minimum",n.minimum);if(n.exclusiveMinimum!==void 0)Te(t,"exclusiveMinimum",n.exclusiveMinimum);if(n.maximum!==void 0)je(t,"maximum",n.maximum);if(n.exclusiveMaximum!==void 0)je(t,"exclusiveMaximum",n.exclusiveMaximum);if(n.multipleOf!==void 0)wc(t,n.multipleOf);if(n.format!==void 0){if(t.format??(t.format=n.format),n.format.includes("int"))t.isInt=!0}if(n.mime)bc(t,n.mime);for(let i of n.patterns??[])_c(t,i);return t}var Gp={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},qp=new Map([[zr,Dn],[Nt,Fn]]),Xp=(e)=>qp.get(e)??e,$c=(e,t,r,o)=>{let n=r;n.type="string";let{minimum:i,maximum:s,format:c,patterns:a,contentEncoding:u,laxFormat:p}=j(e);if(typeof i==="number")n.minLength=i;if(typeof s==="number")n.maxLength=s;if(c){if(n.format=Gp[c]??c,n.format==="")delete n.format;if(c==="time"||p)delete n.format}if(u)n.contentEncoding=u;if(a&&a.size>0){let l=[...a].map(Xp);if(l.length===1)n.pattern=l[0].source;else if(l.length>1)n.allOf=[...l.map((f)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))]}},zc=(e,t,r,o)=>{let n=r,{minimum:i,maximum:s,multipleOf:c,exclusiveMaximum:a,exclusiveMinimum:u,isInt:p}=j(e);n.type=p?"integer":"number";let l=typeof u==="number"&&u>=(i??Number.NEGATIVE_INFINITY),f=typeof a==="number"&&a<=(s??Number.POSITIVE_INFINITY),d=t.target==="draft-04"||t.target==="openapi-3.0";if(l)if(d)n.minimum=u,n.exclusiveMinimum=!0;else n.exclusiveMinimum=u;else if(typeof i==="number")n.minimum=i;if(f)if(d)n.maximum=a,n.exclusiveMaximum=!0;else n.exclusiveMaximum=a;else if(typeof s==="number")n.maximum=s;if(c){let g=new Set;for(let v of c)if(Number.isFinite(v)&&v!==0)g.add(Math.abs(v));else re(e,t,n,o,`A multipleOf divisor of ${v} cannot be represented in JSON Schema`);let[m,...y]=g;if(m!==void 0)n.multipleOf=m;if(y.length)n.allOf=[...n.allOf??[],...y.map((v)=>({multipleOf:v}))]}},Sc=(e,t,r,o)=>{r.type="boolean"},Pc=(e,t,r,o)=>{re(e,t,r,o,"BigInt cannot be represented in JSON Schema")};var Ec=(e,t,r,o)=>{r.not={}};var Zc=(e,t,r,o)=>{},Oc=(e,t,r,o)=>{re(e,t,r,o,"Date cannot be represented in JSON Schema")},Cc=(e,t,r,o)=>{let n=e._zod.def,i=He(n.entries);if(i.length===0){r.not={};return}if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";r.enum=i},Rc=(e,t,r,o)=>{let n=e._zod.def;if(n.values.length===0){r.not={};return}let i=[];for(let s of n.values)if(s===void 0){if(re(e,t,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s==="bigint"){if(re(e,t,r,o,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length===0);else if(i.length===1){let s=i[0];if(r.type=s===null?"null":typeof s,t.target==="draft-04"||t.target==="openapi-3.0")r.enum=[s];else r.const=s}else{if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";if(i.every((s)=>typeof s==="boolean"))r.type="boolean";if(i.every((s)=>s===null))r.type="null";r.enum=i}};var Ic=(e,t,r,o)=>{re(e,t,r,o,"Custom types cannot be represented in JSON Schema")};var Ac=(e,t,r,o)=>{re(e,t,r,o,"Transforms cannot be represented in JSON Schema")};var Nc=(e,t,r,o)=>{let n=r,i=e._zod.def,{minimum:s,maximum:c}=j(e);if(typeof s==="number")n.minItems=s;if(typeof c==="number")n.maxItems=c;n.type="array",n.items=A(i.element,t,{...o,path:[...o.path,"items"]})};function Gr(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return Gr(t.out);if(t.type==="catch")return Gr(t.innerType);return e._zod.optin}var Tc=(e,t,r,o)=>{let n=r,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&re(e,t,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in s)Q(n.properties,u,A(s[u],t,{...o,path:[...o.path,"properties",u]}));let a=[];for(let u of Object.keys(s)){let p=i.shape[u];if(t.io==="input"?Gr(p)===void 0:p._zod.optout===void 0)a.push(u)}if(a.length>0)n.required=a;if(i.catchall?._zod.def.type==="never")n.additionalProperties=!1;else if(!i.catchall){if(t.io==="output")n.additionalProperties=!1}else if(i.catchall)n.additionalProperties=A(i.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},jc=(e,t,r,o)=>{let n=e._zod.def,i=n.inclusive===!1,s=n.options.map((c,a)=>A(c,t,{...o,path:[...o.path,i?"oneOf":"anyOf",a]}));if(i)r.oneOf=s;else r.anyOf=s},Dc=(e,t,r,o)=>{let n=e._zod.def,i=A(n.left,t,{...o,path:[...o.path,"allOf",0]}),s=A(n.right,t,{...o,path:[...o.path,"allOf",1]}),c=(u)=>("allOf"in u)&&Object.keys(u).length===1,a=[...c(i)?i.allOf:[i],...c(s)?s.allOf:[s]];r.allOf=a,t.intersections.push(a)};var Fc=(e,t,r,o)=>{let n=e._zod.def,i=A(n.innerType,t,o),s=t.seen.get(e);if(t.target==="openapi-3.0")s.ref=n.innerType,r.nullable=!0;else r.anyOf=[i,{type:"null"}]},Lc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);i.ref=n.innerType},qr=Symbol();function Mc(e,t,r,o,n){let i=!1,s=JSON.stringify(e,(c,a)=>{if(typeof a!=="bigint")return a;return i=!0,null});if(!i)return JSON.parse(s);return re(t,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),qr}var Uc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);i.ref=n.innerType;let s=Mc(n.defaultValue,e,t,r,o);if(s!==qr)r.default=s},Wc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);if(i.ref=n.innerType,t.io!=="input")return;let s=Mc(n.defaultValue,e,t,r,o);if(s!==qr)r._prefault=s},Bc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);i.ref=n.innerType;let s;try{s=n.catchValue(void 0)}catch{re(e,t,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},Jc=(e,t,r,o)=>{let n=e._zod.def,i=n.in._zod.traits.has("$ZodTransform"),s=t.io==="input"?i?n.out:n.in:n.out;A(s,t,o);let c=t.seen.get(e);c.ref=s},Vc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);i.ref=n.innerType,r.readOnly=!0};var Xr=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let i=t.seen.get(e);i.ref=n.innerType};var Hc=new WeakSet([Object.prototype,Error.prototype]);function Wt(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let o=r(this);return Object.defineProperty(this,t,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,t,{value:o,configurable:!0,writable:!0})}})}var sl=(e,t)=>{ln.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(Hc.has(r))return;Hc.add(r),Wt(r,"format",(o)=>(n)=>dn(o,n)),Wt(r,"flatten",(o)=>(n)=>fn(o,n)),Wt(r,"addIssue",(o)=>(n)=>{o.issues.push(n),o.message=JSON.stringify(o.issues,Ke,2)}),Wt(r,"addIssues",(o)=>(n)=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,Ke,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var J=h("ZodError",sl,void 0,{Parent:Error});var Kc=St(J),Gc=Pt(J),qc=Et(J),Xc=Zt(J),Yc=mn(J),Qc=gn(J),ea=yn(J),ta=xn(J),ra=vn(J),oa=wn(J),na=_n(J),ia=bn(J);function al(){if(!B.localeError)te(Cr())}function Qr(){if(!B.memoizer)te({memoizer:ks()})}var O=h("ZodType",(e,t)=>(al(),E.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(W(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ne(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(ef(e,t))},superRefine(e,t){return this.check(tf(e,t))},overwrite(e){return this.check(xe(e))},optional(){return aa(this)},exactOptional(){return Ml(this)},nullable(){return ua(this)},nullish(){return aa(ua(this))},nonoptional(e){return Hl(this,e)},array(){return _(this)},or(e){return oo([this,e])},and(e){return jl(this,e)},transform(e){return pa(this,Ll(e))},default(e){return Bl(this,e)},prefault(e){return Vl(this,e)},catch(e){return Gl(this,e)},pipe(e){return pa(this,e)},readonly(){return Yl(this)},describe(e){let t=this.clone();return $e.add(t,{description:e}),t},meta(...e){if(e.length===0)return $e.get(this);let t=this.clone();return $e.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get "~standard"(){return kt(this,"~standard",{...$r(this),jsonSchema:{input:nt(this,"input"),output:nt(this,"output")}})},set "~standard"(e){pe(this,"~standard",e)},parse:function e(t,r){return Kc(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await Gc(this,t,r,{callee:e})},safeParse(e,t){return qc(this,e,t)},async safeParseAsync(e,t){return Xc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){pe(this,"spa",e)},validate(e,t){return hr(this,e,t)},validateAsync(e,t){return mr(this,e,t)},encode:function e(t,r){return Yc(this,t,r,{callee:e})},decode:function e(t,r){return Qc(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await ea(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await ta(this,t,r,{callee:e})},safeEncode(e,t){return ra(this,e,t)},safeDecode(e,t){return oa(this,e,t)},async safeEncodeAsync(e,t){return na(this,e,t)},async safeDecodeAsync(e,t){return ia(this,e,t)},toJSONSchema(e){return mc(this,{})(e)},get description(){return $e.get(this)?.description},get _def(){return this._zod.def}}),la=h("_ZodString",(e,t)=>{At.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>$c(e,r,o,n)},$t({format:(e)=>j(e).format??null,minLength:(e)=>j(e).minimum??null,maxLength:(e)=>j(e).maximum??null},{regex(...e){return this.check(Ar(...e))},includes(...e){return this.check(jr(...e))},startsWith(...e){return this.check(Dr(...e))},endsWith(...e){return this.check(Fr(...e))},min(...e){return this.check(Ne(...e))},max(...e){return this.check(Mt(...e))},length(...e){return this.check(Ut(...e))},nonempty(...e){return this.check(Ne(1,...e))},lowercase(e){return this.check(Nr(e))},uppercase(e){return this.check(Tr(e))},trim(){return this.check(Mr())},normalize(...e){return this.check(Lr(...e))},toLowerCase(){return this.check(Ur())},toUpperCase(){return this.check(Wr())},slugify(){return this.check(Br())}})),eo=h("ZodString",(e,t)=>{At.init(e,t),la.init(e,t)},{email(e){return this.check(Es(dl,e))},url(e){return this.check(Ir(fa,e))},jwt(e){return this.check(Hs(Ol,e))},emoji(e){return this.check(Is(gl,e))},guid(e){return this.check(Zs(hl,e))},uuid(e){return this.check(Rr(st,e))},uuidv4(e){return this.check(Os(st,e))},uuidv6(e){return this.check(Cs(st,e))},uuidv7(e){return this.check(Rs(st,e))},nanoid(e){return this.check(As(yl,e))},cuid(e){return this.check(Ns(xl,e))},cuid2(e){return this.check(Ts(vl,e))},ulid(e){return this.check(js(wl,e))},base64(e){return this.check(Bs(Pl,e))},base64url(e){return this.check(Js(El,e))},xid(e){return this.check(Ds(_l,e))},ksuid(e){return this.check(Fs(bl,e))},ipv4(e){return this.check(Ls(kl,e))},ipv6(e){return this.check(Ms($l,e))},cidrv4(e){return this.check(Us(zl,e))},cidrv6(e){return this.check(Ws(Sl,e))},e164(e){return this.check(Vs(Zl,e))},datetime(e){return this.check(Ks(ul,e))},date(e){return this.check(Gs(pl,e))},time(e){return this.check(qs(ll,e))},duration(e){return this.check(Xs(fl,e))}});function w(e){return Ss(eo,e)}var C=h("ZodStringFormat",(e,t)=>{Z.init(e,t),la.init(e,t)}),ul=h("ZodISODateTime",(e,t)=>{Ni.init(e,t),C.init(e,t)}),pl=h("ZodISODate",(e,t)=>{Ti.init(e,t),C.init(e,t)}),ll=h("ZodISOTime",(e,t)=>{ji.init(e,t),C.init(e,t)}),fl=h("ZodISODuration",(e,t)=>{Di.init(e,t),C.init(e,t)}),dl=h("ZodEmail",(e,t)=>{$i.init(e,t),C.init(e,t)});var hl=h("ZodGUID",(e,t)=>{bi.init(e,t),C.init(e,t)});var st=h("ZodUUID",(e,t)=>{ki.init(e,t),C.init(e,t)});function to(e){return Rr(st,e)}var fa=h("ZodURL",(e,t)=>{Pi.init(e,t),C.init(e,t)});function ml(e){return Ir(fa,e)}var gl=h("ZodEmoji",(e,t)=>{Ei.init(e,t),C.init(e,t)});var yl=h("ZodNanoID",(e,t)=>{Zi.init(e,t),C.init(e,t)});var xl=h("ZodCUID",(e,t)=>{Oi.init(e,t),C.init(e,t)});var vl=h("ZodCUID2",(e,t)=>{Ci.init(e,t),C.init(e,t)});var wl=h("ZodULID",(e,t)=>{Ri.init(e,t),C.init(e,t)});var _l=h("ZodXID",(e,t)=>{Ii.init(e,t),C.init(e,t)});var bl=h("ZodKSUID",(e,t)=>{Ai.init(e,t),C.init(e,t)});var kl=h("ZodIPv4",(e,t)=>{Fi.init(e,t),C.init(e,t)});var $l=h("ZodIPv6",(e,t)=>{Mi.init(e,t),C.init(e,t)});var zl=h("ZodCIDRv4",(e,t)=>{Ui.init(e,t),C.init(e,t)});var Sl=h("ZodCIDRv6",(e,t)=>{Wi.init(e,t),C.init(e,t)});var Pl=h("ZodBase64",(e,t)=>{Ji.init(e,t),C.init(e,t)});var El=h("ZodBase64URL",(e,t)=>{Vi.init(e,t),C.init(e,t)});var Zl=h("ZodE164",(e,t)=>{Hi.init(e,t),C.init(e,t)});var Ol=h("ZodJWT",(e,t)=>{Ki.init(e,t),C.init(e,t)});var Bt=h("ZodNumber",(e,t)=>{Sr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>zc(e,r,o,n),e.isFinite=!0},$t({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=j(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=j(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=j(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>j(e).format??null},{gt(e,t){return this.check(Ae(e,t))},gte(e,t){return this.check(fe(e,t))},min(e,t){return this.check(fe(e,t))},lt(e,t){return this.check(Ie(e,t))},lte(e,t){return this.check(le(e,t))},max(e,t){return this.check(le(e,t))},int(e){return this.check(sa(e))},safe(e){return this.check(sa(e))},positive(e){return this.check(Ae(0,e))},nonnegative(e){return this.check(fe(0,e))},negative(e){return this.check(Ie(0,e))},nonpositive(e){return this.check(le(0,e))},multipleOf(e,t){return this.check(rt(e,t))},step(e,t){return this.check(rt(e,t))},finite(){return this}}));function da(e){return Ys(Bt,e)}var Cl=h("ZodNumberFormat",(e,t)=>{Gi.init(e,t),Bt.init(e,t)});function sa(e){return ec(Cl,e)}var ro=h("ZodBoolean",(e,t)=>{qi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Sc(e,r,o,n)});function De(e){return tc(ro,e)}var ha=h("ZodBigInt",(e,t)=>{Xi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Pc(e,r,o,n)},$t({minValue:(e)=>j(e).minimum??null,maxValue:(e)=>j(e).maximum??null,format:(e)=>j(e).format??null},{gte(e,t){return this.check(fe(e,t))},min(e,t){return this.check(fe(e,t))},gt(e,t){return this.check(Ae(e,t))},lt(e,t){return this.check(Ie(e,t))},lte(e,t){return this.check(le(e,t))},max(e,t){return this.check(le(e,t))},positive(e){return this.check(Ae(BigInt(0),e))},negative(e){return this.check(Ie(BigInt(0),e))},nonpositive(e){return this.check(le(BigInt(0),e))},nonnegative(e){return this.check(fe(BigInt(0),e))},multipleOf(e,t){return this.check(rt(e,t))}}));var Rl=h("ZodUnknown",(e,t)=>{Yi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Zc(e,r,o,n)});function ca(){return nc(Rl)}var Il=h("ZodNever",(e,t)=>{Qi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Ec(e,r,o,n)});function ma(e){return ic(Il,e)}var ga=h("ZodDate",(e,t)=>{es.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Oc(e,r,o,n),e.min=(r,o)=>e.check(fe(r,o)),e.max=(r,o)=>e.check(le(r,o))},$t({minDate:(e)=>{let{minimum:t}=j(e);return t?new Date(t):null},maxDate:(e)=>{let{maximum:t}=j(e);return t?new Date(t):null}},{}));var Al=h("ZodArray",(e,t)=>{Qr(),ts.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Nc(e,r,o,n),e.element=t.element},{min(e,t){return this.check(Ne(e,t))},nonempty(e){return this.check(Ne(1,e))},max(e,t){return this.check(Mt(e,t))},length(e,t){return this.check(Ut(e,t))},unwrap(){return this.element}});function _(e,t){return cc(Al,e,t)}var ya=h("ZodObject",(e,t)=>{Qr(),ns.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Tc(e,r,o,n),fp(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return X(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(W(this._zod.def,{catchall:e}))},passthrough(){return this.clone(W(this._zod.def,{catchall:ca()}))},loose(){return this.clone(W(this._zod.def,{catchall:ca()}))},strict(){return this.clone(W(this._zod.def,{catchall:ma()}))},strip(){return this.clone(W(this._zod.def,{catchall:void 0}))},extend(e){return np(this,e)},safeExtend(e){return ip(this,e)},merge(e){return sp(this,e)},pick(e){return rp(this,e)},omit(e){return op(this,e)},partial(...e){return tn(va,this,e[0])},exactPartial(...e){return tn(wa,this,e[0],"exactPartial")},required(...e){return cp(_a,this,e[0])}});function ct(e,t){let r={type:"object",shape:e??{},...x(t)};return new ya(r)}function P(e,t){return new ya({type:"object",shape:e,catchall:ma(),...x(t)})}var xa=h("ZodUnion",(e,t)=>{Pr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>jc(e,r,o,n),e.options=t.options});function oo(e,t){return new xa({type:"union",options:e,...x(t)})}var Nl=h("ZodDiscriminatedUnion",(e,t)=>{xa.init(e,t),is.init(e,t)});function no(e,t,r){return new Nl({type:"union",options:t,discriminator:e,...x(r)})}var Tl=h("ZodIntersection",(e,t)=>{ss.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Dc(e,r,o,n)});function jl(e,t){return new Tl({type:"intersection",left:e,right:t})}var Yr=h("ZodEnum",(e,t)=>{cs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(o,n,i)=>Cc(e,o,n,i),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(o,n)=>{let i={};for(let s of o)if(r.has(s))i[s]=t.entries[s];else throw Error(`Key ${s} not found in enum`);return new Yr({...t,checks:[],...x(n),entries:i})},e.exclude=(o,n)=>{let i={...t.entries};for(let s of o)if(r.has(s))delete i[s];else throw Error(`Key ${s} not found in enum`);return new Yr({...t,checks:[],...x(n),entries:i})}});function X(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new Yr({type:"enum",entries:r,...x(t)})}var Dl=h("ZodLiteral",(e,t)=>{as.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Rc(e,r,o,n),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function V(e,t){return new Dl({type:"literal",values:Array.isArray(e)?e:[e],...x(t)})}var Fl=h("ZodTransform",(e,t)=>{Qr(),us.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Ac(e,r,o,n),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Xe(e.constructor.name);r.addIssue=(i)=>{if(typeof i==="string")r.issues.push(ke(i,r.value,t));else{let s=i;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=r.value;s.inst??(s.inst=e),r.issues.push(ke(s))}};let n=t.transform(r.value,r);if(n instanceof Promise)return n.then((i)=>(r.value=i,r));return r.value=n,r}});function Ll(e){return new Fl({type:"transform",transform:e})}var va=h("ZodOptional",(e,t)=>{Er.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Xr(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function aa(e){return new va({type:"optional",innerType:e})}var wa=h("ZodExactOptional",(e,t)=>{ps.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Xr(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Ml(e){return new wa({type:"optional",innerType:e})}var Ul=h("ZodNullable",(e,t)=>{ls.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Fc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function ua(e){return new Ul({type:"nullable",innerType:e})}var Wl=h("ZodDefault",(e,t)=>{fs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Uc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Bl(e,t){return new Wl({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():cr(t)}})}var Jl=h("ZodPrefault",(e,t)=>{ds.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Wc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Vl(e,t){return new Jl({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():cr(t)}})}var _a=h("ZodNonOptional",(e,t)=>{hs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Lc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Hl(e,t){return new _a({type:"nonoptional",innerType:e,...x(t)})}var Kl=h("ZodCatch",(e,t)=>{ms.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Bc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Gl(e,t){return new Kl({type:"catch",innerType:e,catchValue:typeof t==="function"?t:sn(t)})}var ql=h("ZodPipe",(e,t)=>{gs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Jc(e,r,o,n),e.in=t.in,e.out=t.out});function pa(e,t){return new ql({type:"pipe",in:e,out:t})}var Xl=h("ZodReadonly",(e,t)=>{ys.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Vc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Yl(e){return new Xl({type:"readonly",innerType:e})}var Ql=h("ZodCustom",(e,t)=>{xs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Ic(e,r,o,n)});function ef(e,t={}){return ac(Ql,e,t)}function tf(e,t){return uc(e,t)}var io={};ep(io,{bigint:()=>cf,boolean:()=>sf,date:()=>af,number:()=>nf,string:()=>of});function of(e){return Ps(eo,e)}function nf(e){return Qs(Bt,e)}function sf(e){return rc(ro,e)}function cf(e){return oc(ha,e)}function af(e){return sc(ga,e)}var so=X(["codex","claude","opencode"]),uf=w().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),pf="Initialize an AppToolkit workspace, register an existing checkout, or find the approved project workflow.",lf={codex:".agents/skills/apptoolkit/SKILL.md",claude:".claude/skills/apptoolkit/SKILL.md",opencode:".opencode/commands/apptoolkit.md"},ba=["For requests involving this workspace, read `llm/HARNESS.md` and use its workflow index to open the relevant procedure. Follow the established rules for the project and target repository.","","For a request like “Dame mi lista de pendientes”, open W01. For a new feature, use W16 to establish requirements before W18 implementation."].join(`
59
- `);function co(e){let t=new Set(_(so).parse(e)),r=[];if(t.has("codex")||t.has("opencode"))r.push({path:"AGENTS.md",content:ba});if(t.has("claude"))r.push({path:"CLAUDE.md",content:ba});return r}function ff(e,t){let r=["---"];if(e!=="opencode")r.push("name: apptoolkit");if(r.push(`description: ${pf}`),e==="claude")r.push('argument-hint: "[init | add repo <path> | workflow <request>]"');if(r.push("---","",`# AppToolkit Harness ${t}`,""),e!=="codex")r.push("Treat the following as user arguments, never as shell source.","","$ARGUMENTS","");return r.push("Find the installed workspace root using `llm/harness/workspace.json`. Open the session from that root when discovery is ambiguous.","Read `llm/HARNESS.md`, the project settings, and relevant repository instructions before choosing a workflow. Read the indexed workflow by ID instead of loading every workflow.","","Use `rtk proxy bun --no-env-file <workspace>/llm/harness/runtime/harness.mjs` for deterministic operations. If only Node.js is available, replace `bun --no-env-file` with `node`. Substitute absolute paths with individually quoted arguments.","","- For `init`, use `init --root <workspace> --json` to load the configuration template. Ask about budgets and discover approved project rules, tool routes, authority, and documentation conventions. Keep service connections and snapshots opt-in. Save the agreed answers as an explicit JSON input with credential references only. Apply it with `init --root <workspace> --config <input>`.","- For `add repo <path>`, identify the existing checkout and ask whether harness files there may be versioned. Preview `add repo <path> --root <workspace>` with the agreed `--repo-versioned` or `--repo-local` choice. Apply with `--yes` only after the user approves that plan. Keep shared knowledge in the workspace and scope repository-specific instructions to the checkout.","- For feature requests, use W16 to settle the definition before W18 implementation. In existing projects, an authoritative ticket or approved specification may satisfy that gate.","- For other requests, resolve the closest workflow from the index. Obtain separate authority for external writes and Git writes. Do not grant tool access or move credentials into the workspace.",""),r.join(`
60
- `)}function ao(e,t){let r=_(so).parse(e),o=uf.parse(t);return[...new Set(r)].map((n)=>({path:lf[n],content:ff(n,o)}))}import{randomUUID as Jf}from"node:crypto";import{lstatSync as Vf,readFileSync as Hf,realpathSync as Va,renameSync as Kf,rmSync as Gf,writeFileSync as qf}from"node:fs";import{dirname as Xf,join as Be,relative as Yf,resolve as Ha}from"node:path";import{mkdirSync as Ef,readFileSync as Zf,rmSync as Aa,writeFileSync as Of}from"node:fs";import{tmpdir as Cf}from"node:os";import{resolve as lo}from"node:path";import{createHash as df,randomUUID as hf}from"node:crypto";import{chmodSync as mf,linkSync as gf,lstatSync as Jt,mkdirSync as yf,readFileSync as xf,realpathSync as za,renameSync as vf,rmSync as wf,unlinkSync as _f,writeFileSync as bf}from"node:fs";import{dirname as ka,isAbsolute as Sa,relative as Pa,resolve as ut,sep as kf}from"node:path";var $a=16777216;class Vt extends Error{}function Ea(e){return"code"in e&&e.code==="ENOENT"}function de(e){let t=za(ut(e));if(!Jt(t).isDirectory())throw Error(`Expected an existing directory at ${t}.`);return t}function uo(e,t){let r=Pa(e,t);return r!==".."&&!r.startsWith(`..${kf}`)&&!Sa(r)}function ve(e,t){if(!uo(e,t))throw Error(`Path ${t} is outside ${e}.`);return Pa(e,t)||"."}function oe(e){let t=e.split("/");if(Sa(e)||/[\\\u0000-\u001f\u007f]/u.test(e)||t.some((r)=>!r||r==="."||r===".."||r===".git"))throw Error(`Expected a safe relative path. Received ${JSON.stringify(e)}.`)}function Ht(e,t){if(oe(t),za(e)!==e||!Jt(e).isDirectory())throw Error(`The installation base changed. Inspect ${e} before retrying.`);let r=t.split("/"),o=e;for(let[n,i]of r.entries()){o=ut(o,i);let s=Jt(o,{throwIfNoEntry:!1});if(!s)break;let c=n===r.length-1;if(s.isSymbolicLink()||!c&&!s.isDirectory()||c&&!s.isFile())throw new Vt(`Expected a regular file path. Inspect ${o} before retrying.`)}return ut(e,t)}function M(e){return df("sha256").update(e).digest("hex")}function U(e,t=420){let r=Buffer.isBuffer(e)?e:Buffer.from(e);return{bytes:r,hash:M(r),mode:t}}function R(e,t){let r=Ht(e,t),o=Jt(r,{throwIfNoEntry:!1});if(!o)return null;if(o.size>$a)throw Error(`The file at ${r} exceeds the ${$a}-byte installation limit.`);return U(xf(r),o.mode&511)}function ce(e,t){return e?.hash===t?.hash&&e?.mode===t?.mode}function at(e){if(!ce(R(e.base,e.path),e.before))throw Error(`File changed after planning. Replan before applying ${ut(e.base,e.path)}.`)}function Kt(e){at(e);let t=Ht(e.base,e.path);if(!e.after){_f(t);return}yf(ka(t),{recursive:!0}),at(e);let r=ut(ka(t),`.apptoolkit-${hf()}.tmp`),o=e.after;try{if(bf(r,o.bytes,{flag:"wx",mode:o.mode}),mf(r,o.mode),e.before)at(e),vf(r,t);else gf(r,t)}finally{wf(r,{force:!0})}}import{spawnSync as $f}from"node:child_process";import{lstatSync as zf,realpathSync as Za}from"node:fs";import{dirname as Oa,resolve as po}from"node:path";function Sf(){let e={};for(let[t,r]of Object.entries(process.env))if(!t.startsWith("GIT_"))e[t]=r;return{...e,GIT_OPTIONAL_LOCKS:"0",LC_ALL:"C"}}function Fe(e,t,r=[0],o=!1){let i=$f("rtk",["proxy","git",...o?["--literal-pathspecs"]:[],"-C",e,...t],{encoding:"utf8",env:Sf(),maxBuffer:1048576,timeout:1e4});if(i.error)throw Error(`Cannot run Git ${t[0]} in ${e}. Verify RTK and Git are installed.`,{cause:i.error});if(i.status===null||!r.includes(i.status))throw Error(`Git ${t[0]} failed in ${e}: ${i.stderr.trim()||`exit ${i.status}`}`);return{output:i.stdout,status:i.status}}function Ca(e){let t=e;while(!0){let r=zf(po(t,".git"),{throwIfNoEntry:!1});if(r?.isDirectory()||r?.isFile())return t;if(r)throw Error(`Unsupported Git metadata at ${po(t,".git")}. Inspect the repository before retrying.`);let o=Oa(t);if(o===t)return;t=o}}function L(e){if(!Ca(e))return;let t=Za(Fe(e,["rev-parse","--show-toplevel"]).output.trimEnd()),r=Za(Fe(e,["rev-parse","--path-format=absolute","--git-common-dir"]).output.trimEnd()),o=Fe(e,["rev-parse","--path-format=absolute","--git-path","info/exclude"]).output.trimEnd();if(po(r,"info/exclude")!==o)throw Error(`Git returned a local exclude path outside the expected metadata directory for ${e}.`);return{root:t,commonDirectory:r,exclude:"info/exclude"}}function ze(e,t){if(Ca(Oa(e))!==t)throw Error(`The path ${e} belongs to a different Git checkout. Select that checkout explicitly before retrying.`)}function Le(e,t){let r=ve(e.root,t);return Fe(e.root,["ls-files","--cached","-z","--",r],[0],!0).output.split("\x00").includes(r)}function Gt(e,t){let r=Fe(e.git.root,["check-ignore","--quiet","--",`./${e.path}`],[0,1]);if(!t&&r.status!==0)throw Error(`Git did not ignore ${e.path} in ${e.git.root}. Check for an existing tracked file or a higher-priority rule before retrying.`);if(t&&r.status===0)throw Error(`Git ignores ${e.path} in ${e.git.root}. Choose local mode or resolve the existing exclusion before retrying.`)}function Pf(e){if(e.includes("://")){try{let n=new URL(e);if(n.hostname&&n.pathname!=="/")return`${n.host.toLowerCase()}${n.pathname.replace(/\.git\/?$/,"").replace(/\/$/,"")}`}catch(n){throw Error("Git returned an invalid origin URL. Correct the local repository configuration before retrying.",{cause:n})}return}let t=/^(?:[^@/:\s]+@)?([^/:\s]+):([^\s]+)$/.exec(e),r=t?.[1],o=t?.[2];if(r&&o)return`${r.toLowerCase()}/${o.replace(/^\//,"").replace(/\.git\/?$/,"").replace(/\/$/,"")}`;return}function Ra(e){let t=Fe(e,["config","--local","--get","remote.origin.url"],[0,1]);if(t.status===1)return;let r=Pf(t.output.trimEnd());if(!r)return;return M(r)}function qt(e){return`/${e.replace(/[\\[\]*? #!]/gu,"\\$&")}`}var Rf=io.number().int().positive(),Na=new WeakMap;function Ta(e,t){Na.set(e,t)}function If(e){let t=lo(Cf(),`apptoolkit-${M(e).slice(0,24)}.lock`),r=lo(t,"owner");try{Ef(t,{mode:448})}catch(o){if(!(o instanceof Error)||!("code"in o)||o.code!=="EEXIST")throw Error(`Cannot acquire the installation lock ${t}.`,{cause:o});let n;try{n=Rf.parse(Zf(r,"utf8"))}catch(i){throw Error(`An installation lock already exists at ${t}. If no install is running, remove the stale lock directory and retry.`,{cause:i})}try{process.kill(n,0)}catch(i){if(i instanceof Error&&"code"in i&&i.code==="ESRCH")throw Error(`The previous installation stopped. Remove its stale lock at ${t} and rerun the same installation to resume.`,{cause:i});throw Error(`Cannot confirm whether the installation holding ${t} is still running.`,{cause:i})}throw Error(`Another installation is running for ${e} with process ID ${n}. Retry after it finishes.`)}try{Of(r,`${process.pid}
61
- `,{mode:384,flag:"wx"})}catch(o){try{Aa(t,{recursive:!0})}catch(n){throw AggregateError([o,n],`Cannot record or remove the installation lock at ${t}.`)}throw Error(`Cannot record the installation lock owner at ${r}.`,{cause:o})}return t}function Af(e){let t=new Map;for(let r of e){let n=t.get(r.git.root)??L(r.git.root)?.commonDirectory;if(n!==r.git.commonDirectory)throw Error(`Git metadata changed after planning in ${r.git.root}. Replan the installation.`);if(t.set(r.git.root,n),!r.versioned&&Le(r.git,r.absolute))throw Error(`Git started tracking ${r.absolute} after planning. Replan before applying local mode.`)}}function Nf(e,t){let r=[t];for(let o of e.reverse())try{Kt({...o,before:o.after,after:o.before})}catch(n){r.push(Error(`Cannot restore ${lo(o.base,o.path)} after the installation failed.`,{cause:n}))}if(r.length>1)throw AggregateError(r,"Installation stopped and some files could not be restored. Inspect the reported paths and replan.");throw t}function Tf(e){let{exclusions:t,files:r,checks:o}=e,n=[];for(let i of[...e.guards??[],...t,...r])at(i);for(let i of e.boundaries??[])ze(i.absolute,i.gitRoot);Af(o);try{for(let i of t)Kt(i),n.push(i);for(let i of o)Gt(i,i.versioned);for(let i of r)Kt(i),n.push(i)}catch(i){Nf(n,Error("Could not apply the workspace installation. Inspect the cause and replan before retrying.",{cause:i}))}return n.length}function Ia(e){let t=[];for(let r of e.reverse())try{Aa(r,{recursive:!0})}catch(o){if(!(o instanceof Error)||!Ea(o))t.push(Error(`Cannot remove the installation lock at ${r}. Inspect it before retrying.`,{cause:o}))}return t}function ja(e,t){let r=[],o;try{for(let i of[...new Set(e)].sort())r.push(If(i));o=t()}catch(i){let s=Ia(r);if(s.length)throw AggregateError([i,...s],"The installation failed and some locks could not be removed.");throw i}let n=Ia(r);if(n.length)throw AggregateError(n,"The installation completed and some locks could not be removed.");return o}function Da(e,t){return ja([e],t)}function fo(e,t){let r=[e,...t.exclusions.map((o)=>o.base),...t.checks.map((o)=>o.git.commonDirectory)];return ja(r,()=>Tf(t))}function ho(e){let t=Na.get(e);if(!t)throw Error("Apply requires a plan created by this process. Run the workspace planner again.");if(e.conflicts.length)throw Error(`Resolve the workspace conflicts before applying: ${e.conflicts.map((o)=>o.path).join(", ")}.`);return{changed:fo(e.root,t),receipt:e.receipt}}import{resolve as jf}from"node:path";var Fa=X(["codex","claude","opencode"]),La=X(["plane","penpot"]),mo=w().regex(/^[a-f0-9]{64}$/),Ma=P({path:w().min(1),versioned:De(),identity:mo.optional()}),Ua=P({schema:V(1),version:w().min(1),hosts:_(Fa),workspaceVersioned:De(),repositories:_(Ma),services:_(La),installation:w().regex(/^[a-f0-9]{16}$/).optional(),files:_(P({path:w().min(1),hash:mo,versioned:De(),fragment:mo.optional()}))}),Wa=P({root:w().min(1),action:X(["install","update","add-repo"]),version:w().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),contentDirectory:w(),hosts:_(Fa).min(1),workspaceVersioned:De(),repositories:_(Ma),services:_(La),repository:w().min(1).optional()}),H="llm/harness/workspace.json";var Df=new Set([".agents/skills/apptoolkit/SKILL.md",".claude/skills/apptoolkit/SKILL.md",".opencode/commands/apptoolkit.md","AGENTS.md","CLAUDE.md",".claude/rules/apptoolkit.md"]);function go(e,t){if(e.startsWith("llm/harness/")||e.startsWith("llm/author-style/")||Df.has(e))return e!==H&&e!=="llm/harness/project.json";if(e==="llm/HARNESS.md"||e==="llm/README.md")return!0;return t.some((r)=>e===Se(r.path))}function Se(e){if(e===".")return"llm/harness-context.llm.md";return`${e}/llm/harness-context.llm.md`}function Y(e){let t=de(e),r=R(t,H);if(!r)return;try{let o=Ua.parse(JSON.parse(r.bytes.toString("utf8"))),n=new Set,i=new Set;for(let s of o.repositories){if(s.path!==".")oe(s.path);if(n.has(s.path))throw Error(`Repeated repository path ${s.path}.`);n.add(s.path)}for(let s of o.files){if(oe(s.path),!go(s.path,o.repositories)||i.has(s.path))throw Error(`Unexpected managed file ${s.path}.`);i.add(s.path)}return o}catch(o){throw Error(`Cannot read the installation receipt at ${jf(t,H)}. Restore a valid receipt before retrying.`,{cause:o})}}var ae=w().trim().min(1).max(120).regex(/^[\p{L}\p{N}][\p{L}\p{N} ./_:+-]*$/u),Ja=w().regex(/^[A-Z_][A-Z0-9_]*$/).max(120),Me=w().min(1).max(512).refine((e)=>{if(/^[A-Za-z]:|[\\\u0000-\u001f\u007f]/u.test(e))return!1;return e.split("/").every((t)=>t!==""&&t!=="."&&t!==".."&&t!==".git")},"Use a workspace-relative path without traversal."),Ue=oo([V("."),Me]),We=X(["plane","penpot"]),Ff=new Set(["localhost","127.0.0.1","[::1]"]),yo=ml().max(512).pipe(w().refine((e)=>{let t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:"&&Ff.has(t.hostname))&&!t.username&&!t.password&&!t.search&&!t.hash},"Use HTTPS or loopback HTTP without credentials, query, or fragment.")),Ba={baseUrl:yo,tokenEnv:Ja,snapshots:X(["off","versioned"])},Lf=no("provider",[P({...Ba,provider:V("plane"),workspace:w().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,119}$/),projectId:to(),auth:X(["api-key","oauth"]).default("api-key")}),P({...Ba,provider:V("penpot"),fileId:to()})]),Mf=no("mode",[P({mode:V("unlimited")}),P({mode:V("limited"),limits:_(P({category:ae,maximum:da().positive(),unit:ae})).min(1).max(12)})]),Uf=P({category:ae,scope:ae,authority:ae,provider:ae,access:no("method",[P({method:V("local"),path:Me}),P({method:V("cli"),command:ae}),P({method:V("mcp"),server:ae}),P({method:V("api"),baseUrl:yo,tokenEnv:Ja.optional()}),P({method:V("web"),baseUrl:yo})])}),Wf=P({kind:ae,template:Me.optional(),requiredSections:_(ae).max(30),checklist:_(w().trim().min(1).max(200)).max(30),prohibitedText:_(w().trim().min(1).max(120)).max(30)}),Bf=P({path:Ue,budget:Mf,rules:_(Me).max(50),routes:_(Uf).max(50),documentation:_(Wf).max(50),services:_(Lf).max(2)}).superRefine((e,t)=>{let r=new Set;for(let[n,i]of e.routes.entries()){let s=`${i.category.toLowerCase()}
62
- ${i.scope.toLowerCase()}`;if(r.has(s))t.addIssue({code:"custom",path:["routes",n],message:"Choose one authority for this category and scope."});r.add(s)}let o=new Set;for(let[n,i]of e.services.entries()){if(o.has(i.provider))t.addIssue({code:"custom",path:["services",n],message:"Configure each built-in service once per project."});o.add(i.provider)}}),Pe=P({schema:V(1),projects:_(Bf).min(1).max(100)}).superRefine((e,t)=>{let r=new Set;for(let[o,n]of e.projects.entries()){if(r.has(n.path))t.addIssue({code:"custom",path:["projects",o,"path"],message:"Each project must appear once."});r.add(n.path)}});var vo="llm/harness/project.json",Qf=1048576;function he(e){try{return Vf(e)}catch(t){if(t instanceof Error&&"code"in t&&t.code==="ENOENT")return;throw Error(`Inspect ${e}.`,{cause:t})}}function wo(e){let t=he(e);if(!t?.isFile()||t.size>Qf)throw Error(`Expected a regular JSON file of at most 1 MiB at ${e}.`);try{return JSON.parse(Hf(e,"utf8"))}catch(r){throw Error(`Read JSON configuration at ${e}.`,{cause:r})}}function Ka(e){let t=e;for(let r of["llm","harness"])if(t=Be(t,r),!he(t)?.isDirectory())throw Error(`Expected an installed, nonsymlink workspace directory at ${t}.`);return t}function pt(e){let t=Va(Ha(e));Ka(t);let r=Y(t);if(!r)throw Error("Install the harness in the selected workspace before configuring it.");return{root:t,receipt:r}}function Ga(e,t){if(Ka(e),!he(t))return;let r=Pe.safeParse(wo(t));if(!r.success){let o=r.error.issues.map((n)=>`${n.path.join(".")||"settings"} ${n.message}`);throw Error(`Invalid project settings in ${t}. ${o.join(" ")}`)}return r.data}function Ee(e){return Ga(e,Be(e,vo))}function ed(e,t,r){if(r)return r;let o=Be(e,t),n=[];if(he(o)?.isDirectory()&&Va(o)===o){for(let i of["AGENTS.md","CLAUDE.md","CONTRIBUTING.md"])if(he(Be(o,i))?.isFile())n.push(i)}return{path:t,budget:null,rules:n,routes:[],documentation:[],services:[]}}function _o(e){let{root:t,receipt:r}=pt(e),o=Ee(t);return{schema:1,projects:[...new Set([".",...r.repositories.map((i)=>i.path)])].map((i)=>{let s=o?.projects.find((c)=>c.path===i);return ed(t,i,s)})}}function xo(e){return`${JSON.stringify(e,null,2)}
63
- `}function td(e,t){let r=Xf(e),o=Be(r,`.project.${Jf()}.json`);try{qf(o,xo(t),{flag:"wx",mode:384}),Kf(o,e)}catch(n){try{Gf(o,{force:!0})}catch(i){throw AggregateError([n,i],`Write project settings and clean the draft at ${e}.`)}throw Error(`Write project settings at ${e}.`,{cause:n})}}async function bo(e){let{root:t}=pt(e.root),r=Ga(t,Ha(e.configPath));if(!r)throw Error("Provide the approved project settings JSON file.");return Da(t,()=>{let{receipt:o}=pt(t),n=new Set([".",...o.repositories.map((u)=>u.path)]);for(let u of r.projects){if(!n.has(u.path))throw Error(`Register ${u.path} before initializing its settings.`);for(let p of u.services){if(!o.services.includes(p.provider))throw Error(`Select ${p.provider} during workspace installation before connecting it.`);if(p.snapshots==="versioned"&&!o.workspaceVersioned)throw Error("Versioned service snapshots require a versioned workspace harness.")}}let i=Be(t,vo);if(!o.workspaceVersioned){let u=L(t);if(u)Gt({git:u,path:Yf(u.root,i)},!1)}let s=Ee(t),c=new Map(s?.projects.map((u)=>[u.path,u]));for(let u of r.projects)c.set(u.path,u);let a=Pe.parse({schema:1,projects:[...c.values()]});if(s&&xo(s)===xo(a))return{path:i,changed:!1,projects:a.projects.length};return td(i,a),{path:i,changed:!0,projects:a.projects.length}})}var rd=P({root:w().min(1),project:Ue,service:We,verifyHealth:De().optional(),verifyRead:De()}),od=ct({results:_(ct({id:to()})).max(1)}),nd=ct({name:w().min(1)}),id=131072;class we extends Error{}function $o(e){let{root:t,receipt:r}=pt(e.root);if(!r.services.includes(e.service))throw Error(`${e.service} is not selected in the installed workspace.`);if(e.project!=="."&&!r.repositories.some((i)=>i.path===e.project))throw Error(`Register ${e.project} before using its service connections.`);let n=Ee(t)?.projects.find((i)=>i.path===e.project)?.services.find((i)=>i.provider===e.service);if(!n)throw Error(`Initialize the ${e.service} connection for ${e.project} first.`);return{root:t,receipt:r,connection:n}}function ko(e,t){let r=new URL(e);if(!r.pathname.endsWith("/"))r.pathname+="/";return new URL(t,r)}function sd(e){if(e.provider==="plane"){let r=`api/v1/workspaces/${e.workspace}/projects/${e.projectId}/work-items/`,o=ko(e.baseUrl,r);return o.searchParams.set("per_page","1"),o.searchParams.set("fields","id"),o}let t=ko(e.baseUrl,"api/rpc/command/get-file-summary");return t.searchParams.set("id",e.fileId),t}function cd(e,t){let r=new Headers({Accept:"application/json"});if(e.provider==="penpot")r.set("Authorization",`Token ${t}`);else if(e.auth==="oauth")r.set("Authorization",`Bearer ${t}`);else r.set("X-API-Key",t);return r}async function ad(e){if(!e.headers.get("content-type")?.toLowerCase().startsWith("application/json"))throw await e.body?.cancel(),new we("Expected an application/json response from the service.");let r=e.body?.getReader();if(!r)throw new we("The service response has no body.");let o=[],n=0;try{for(;;){let i=await r.read();if(i.done)return Buffer.concat(o,n).toString("utf8");if(n+=i.value.byteLength,n>id)throw await r.cancel(),new we("The service response exceeded the 128 KiB verification limit.");o.push(i.value)}}finally{r.releaseLock()}}async function ud(e,t){let r=await t(ko(e.baseUrl,"./"),{method:"HEAD",redirect:"manual",signal:AbortSignal.timeout(1e4)});return await r.body?.cancel(),r.status}async function pd(e,t,r){let o=await r(sd(e),{method:"GET",headers:cd(e,t),redirect:"error",signal:AbortSignal.timeout(1e4)});if(!o.ok)throw await o.body?.cancel(),new we(`The selected resource returned HTTP ${o.status}. Confirm the target and its read permission.`);let n=await ad(o),i=e.provider==="plane"?od:nd,s=!1;try{s=i.safeParse(JSON.parse(n)).success}catch(c){throw new we("The service returned invalid JSON.",{cause:c})}if(!s)throw new we("The response does not match the expected resource read.");return o.status}async function zo(e,t={}){let r=rd.parse(e),{connection:o}=$o(r),i=(t.environment??process.env)[o.tokenEnv],s=typeof i==="string"&&/^[\x21-\x7e]+$/.test(i),c={provider:o.provider,project:r.project,baseUrl:o.baseUrl,credentialEnv:o.tokenEnv,credentialAvailable:s,snapshots:o.snapshots,connectivity:"unchecked",read:"unchecked"},a=t.fetch??fetch;if(r.verifyRead){if(!s)throw Error(`Provide ${o.tokenEnv} in the process environment before verifying access.`);try{let u=await pd(o,i,a);return{...c,connectivity:"reachable",read:"verified",httpStatus:u}}catch(u){let p=u instanceof we?u.message:"Check the configured host and retry.";throw Error(`Verify ${o.provider} read for ${r.project}. ${p}`,{cause:u})}}if(r.verifyHealth)try{let u=await ud(o,a);return{...c,connectivity:u>=500?"service-error":"reachable",httpStatus:u}}catch(u){throw Error(`Check ${o.provider} connectivity for ${r.project}.`,{cause:u})}return c}import{createHash as ld}from"node:crypto";import{constants as qa,createReadStream as fd,openSync as dd}from"node:fs";import{join as hd,relative as Xa,resolve as md}from"node:path";var Ya=Me.refine((e)=>e.startsWith("harness-snapshots/"),{message:"Keep native service exports in the workspace harness-snapshots directory."}),gd=w().regex(/^[a-f0-9]{64}$/),yd=P({path:Ya,bytes:da().int().positive(),sha256:gd}),xd=P({root:w().min(1),project:Ue,service:We}),Qa=P({schema:V(1),project:Ue,service:We,files:_(yd).min(1).max(30)}).refine((e)=>new Set(e.files.map((t)=>t.path)).size===e.files.length,"Duplicate snapshot paths.");function eu(e,t){let r=md(e,t),o=Ya.parse(Xa(e,r)),n=e,i=o.split("/");for(let[s,c]of i.entries()){n=hd(n,c);let a=he(n);if(!(s===i.length-1?a?.isFile():a?.isDirectory()))throw Error(`Expected a regular nonsymlink snapshot path at ${n}.`)}return r}async function tu(e,t){let r=eu(e,t),o=he(r);if(!o?.isFile()||o.size===0)throw Error(`Expected a nonempty snapshot file at ${r}.`);let n=ld("sha256");try{let s=dd(r,qa.O_RDONLY|qa.O_NOFOLLOW),c=fd(r,{fd:s});for await(let a of c)n.update(a)}catch(s){throw Error(`Read snapshot bytes at ${r}.`,{cause:s})}let i=he(r);if(!i||o.dev!==i.dev||o.ino!==i.ino||o.mtimeMs!==i.mtimeMs||o.size!==i.size)throw Error(`Snapshot changed while reading ${r}. Retry with a stable export.`);return{path:Xa(e,r),bytes:o.size,sha256:n.digest("hex")}}function ru(e){let{root:t,receipt:r,connection:o}=$o(xd.parse(e));if(!r.workspaceVersioned||o.snapshots!=="versioned")throw Error("Enable versioned snapshots for this project and provider before working with a snapshot.");return t}async function So(e){let t=ru({root:e.root,project:e.project,service:e.service}),r=_(w().min(1)).min(1).max(30).parse(e.paths),o=[];for(let n of r)o.push(await tu(t,n));return Qa.parse({schema:1,project:e.project,service:e.service,files:o})}async function Po(e){let t=ru({root:e.root,project:e.project,service:e.service}),r=eu(t,e.manifestPath),o=Qa.parse(wo(r));if(o.project!==e.project||o.service!==e.service)throw Error("The snapshot manifest belongs to a different project or service.");for(let n of o.files){let i=await tu(t,n.path);if(i.bytes!==n.bytes||i.sha256!==n.sha256)throw Error(`Snapshot integrity check failed for ${n.path}.`)}return{manifestPath:r,project:o.project,service:o.service,files:o.files.length}}import{closeSync as ou,constants as Eo,fstatSync as nu,lstatSync as iu,openSync as vd,readSync as wd,realpathSync as _d}from"node:fs";import{isAbsolute as cu,join as bd}from"node:path";var kd=262144,$d=new Set([".aws",".git",".gnupg",".npm",".ssh","credentials","node_modules","passwords","private","processing","raw","secret","secrets"]);function au(e){let t=e.toLowerCase(),r=t.replace(/(?:\.llm)?\.md$/,"");return t.startsWith(".env")||$d.has(r)}function zd(e){if(cu(e)||/[\\:\x00-\x1f\x7f]/.test(e))throw Error("Provide a relative path inside the project root.");let t=e.split("/");for(let r of t){if(r===""||r==="."||r==="..")throw Error("Paths must use explicit project-relative segments.");if(au(r))throw Error(`The path crosses a protected location at "${r}".`)}return t}function su(e,t){if(!cu(e))throw Error("Provide an absolute project root.");if(!iu(e).isDirectory())throw Error("The project root must be a directory.");let r=_d(e);if(r.split("/").filter(Boolean).some((i,s)=>(s!==0||i!=="private")&&au(i)))throw Error("The project root crosses a protected location.");let n;for(let[i,s]of t.entries()){if(r=bd(r,s),n=iu(r),n.isSymbolicLink())throw Error(`Symbolic links are not allowed in the project path at "${s}".`);if(i<t.length-1&&!n.isDirectory())throw Error(`Expected a directory at "${s}".`)}if(!n?.isFile())throw Error("The project path must resolve to a regular file.");return{path:r,info:n}}function Sd(e,t,r,o){let n=nu(e);if(!n.isFile()||n.ino!==t.ino||n.dev!==t.dev)throw Error("The file changed while opening. Retry after checking its path.");if(n.size>r)throw Error(`${o} source exceeds ${r} bytes. Use a narrower input.`);let i=Buffer.alloc(n.size+1),s=0;while(s<i.length){let a=wd(e,i,s,i.length-s,s);if(a===0)break;s+=a}if(s>r)throw Error(`${o} source exceeds ${r} bytes. Use a narrower input.`);let c=nu(e);if(c.size!==s||n.size!==c.size||n.mtimeMs!==c.mtimeMs||n.ctimeMs!==c.ctimeMs)throw Error("The source changed during the read. Retry with a stable file.");return i.subarray(0,s)}function Pd(e,t,r,o){let n;try{n=Sd(e,t,r,o)}catch(i){try{ou(e)}catch(s){throw AggregateError([i,s],"Reading and closing the file both failed.")}throw i}return ou(e),n}function Xt(e,t,r,o){try{let n=zd(t),{path:i,info:s}=su(e,n),c=vd(i,Eo.O_RDONLY|Eo.O_NOFOLLOW|Eo.O_NONBLOCK),a=Pd(c,s,r,o),u=su(e,n);if(u.path!==i||u.info.ino!==s.ino||u.info.dev!==s.dev)throw Error("The file path changed during the read. Retry after verifying the current path.");return new TextDecoder("utf-8",{fatal:!0}).decode(a)}catch(n){let i=n instanceof Error?n.message:String(n);throw Error(`Unable to read ${o} "${t}". ${i}`,{cause:n})}}function lt(e,t){if(!t.toLowerCase().endsWith(".md"))throw Error("Provide a relative Markdown path inside the project root.");return Xt(e,t,kd,"Markdown context")}function uu(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}function pu(e,t,r){let o=e.toLowerCase().replace(/[^\p{L}\p{M}\p{N}_\s-]/gu,"").trim().replace(/\s+/g,"-");return{title:e,level:t,line:r,locator:`line:${r}`,anchor:`#${o}`}}function Ed(e){let t=/^ {0,3}(`{3,}|~{3,})/.exec(e)?.[1];if(t)return{marker:t.charAt(0),length:t.length};return}function Zd(e,t){let r=/^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(e)?.[1];return r!==void 0&&r.startsWith(t.marker)&&r.length>=t.length}function Od(e,t){let r=/^ {0,3}(#{1,6})[ \t]+(.*)$/.exec(e),o=r?.[1],n=r?.[2];if(o&&n){let i=n.replace(/(?:^|[ \t]+)#+[ \t]*$/,"").trim();if(i)return pu(i,o.length,t)}return}function Cd(e){if(!e.trim()||/^(?: {4}|\t)/.test(e))return!1;return!/^ {0,3}(?:[>#<]|[-+*][ \t]|\d+[.)][ \t]|\[[^\]]+\]:|(?:[*_-][ \t]*){3,})/.test(e)}function lu(e){let t=[],r,o,n=!1,i=-1;if(e[0]?.trim()==="---")i=e.findIndex((s,c)=>c>0&&/^(---|\.\.\.)$/.test(s.trim()));for(let[s,c]of e.entries()){if(s<=i)continue;let a=c.replace(/\r?\n$/,""),u=s+1;if(r){if(Zd(a,r))r=void 0;continue}if(n||a.trimStart().startsWith("<!--")){n=!a.includes("-->"),o=void 0;continue}if(r=Ed(a),r){o=void 0;continue}let p=Od(a,u);if(p){t.push(p),o=void 0;continue}let l=/^ {0,3}(=+|-+)[ \t]*$/.exec(a)?.[1];if(l&&o){let f=o.lines.join(" "),d=l.startsWith("=")?1:2;t.push(pu(f,d,o.line)),o=void 0;continue}if(!Cd(a)){o=void 0;continue}if(!o)o={line:u,lines:[]};o.lines.push(a.trim())}return t}var Zo=w().min(1).refine((e)=>!/[\x00-\x1f\x7f]/.test(e),"Control characters are not allowed."),Rd=P({root:Zo.max(4096),file:Zo.max(4096),section:Zo.max(512).optional()}),fu=128,du=16384;function Id(e,t){let r=e.filter((n)=>{if(/^line:[1-9][0-9]*$/.test(t))return n.locator===t;if(t.startsWith("#"))return n.anchor===t;return n.title===t}),[o]=r;if(!o)throw Error(`No heading matches "${t}". List the heading index and use an exact locator.`);if(r.length>1){let n=r.slice(0,8).map((s)=>s.locator),i=r.length>n.length?", or another locator from the index":"";throw Error(`Heading "${t}" is ambiguous. Use one of ${n.join(", ")}${i}.`)}return o}function hu(e,t){if(Buffer.byteLength(e)>du)throw Error(`Context output exceeds ${du} bytes. ${t}`)}function mu(e){let t=Rd.parse(e),r=uu(lt(t.root,t.file)),o=lu(r);if(t.section===void 0){if(o.length>fu)throw Error(`Heading index exceeds ${fu} entries. Request a known section or use a narrower map.`);let u={kind:"index",file:t.file,headings:o};return hu(JSON.stringify(u),"Request a known section or use a narrower map."),u}let n=Id(o,t.section),i=o.find((u)=>u.line>n.line&&u.level<=n.level),s=i?i.line-1:r.length,c=r.slice(n.line-1,s).join(""),a={kind:"section",file:t.file,heading:n,startLine:n.line,endLine:s,text:c};return hu(JSON.stringify(a),"Choose a smaller child section or a narrower map."),a}import{realpathSync as Md}from"node:fs";import{isAbsolute as Ro,normalize as Ud,relative as Wd,resolve as Bd}from"node:path";var yu=X(["lines","functions","branches"]),Ad=X(["LF","LH","FNF","FNH","BRF","BRH"]),Nd={lines:{found:"LF",hit:"LH"},functions:{found:"FNF",hit:"FNH"},branches:{found:"BRF",hit:"BRH"}};function xu(e){return{source:e,summaries:new Map,lines:new Map,branches:new Map,functionNames:new Set,functionHits:new Map,groupIds:new Set,aliasHits:new Map,versionSeen:!1}}function T(e,t){let r=Number(e);if(!/^\d+$/.test(e)||!Number.isSafeInteger(r)||r<t)throw Error("Expected an integer within the supported range.");return r}function ft(e,t,r){if(e.has(t))throw Error("Duplicate coverage entry.");e.set(t,r)}function gu(e,t){if(e.has(t))throw Error("Duplicate coverage identity.");e.add(t)}function Td(e,t){let[r,o,,n,i]=t.split(",");if(!r||!o||i!==void 0)throw Error("Expected a line number and execution count.");let s=T(r,1);if(n!==void 0)T(n,s);ft(e.lines,String(s),T(o,0)>0)}function jd(e,t){let r=/^([^,]+),([ef]?u?\d+(?:\^\d+)?),(.+),([^,]+)$/.exec(t),o=r?.[1],n=r?.[2],i=r?.[3],s=r?.[4];if(!o||!n||!i||!s)throw Error("Expected a branch line, block, identity and hit count.");let[,c,a]=/^[ef]?u?(\d+)(?:\^(\d+))?$/.exec(n)??[];if(!c)throw Error("Expected a numeric branch block.");let u=JSON.stringify([T(o,1),T(c,0),a===void 0?null:T(a,0),/^\d+$/.test(i)?T(i,0):i]);ft(e.branches,u,s!=="-"&&T(s,0)>0)}function Dd(e,t,r){let o=t==="FN"?/^(\d+),(?:(\d+),)?(.+)$/:/^(\d+),(\d+)(?:,(\d+))?$/,[,n,i,s]=o.exec(r)??[];if(n===void 0)throw Error("Malformed function definition.");if(t==="FN"&&s){let c=T(n,1);if(i)T(i,c);gu(e.functionNames,s);return}if(t==="FNL"&&i){let c=T(i,1);if(s)T(s,c);gu(e.groupIds,String(T(n,0)));return}throw Error("Malformed function definition.")}function Fd(e,t,r){if(t==="FNDA"){let[,a,u]=/^(\d+),(.+)$/.exec(r)??[];if(!a||!u)throw Error("Expected a function hit count and name.");ft(e.functionHits,u,T(a,0)>0);return}let[,o,n,i]=/^(\d+),(\d+),(.+)$/.exec(r)??[];if(!o||!n||!i)throw Error("Expected an alias group, hit count and name.");let s=String(T(o,0)),c=e.aliasHits.get(s)??new Map;ft(c,i,T(n,0)>0),e.aliasHits.set(s,c)}function vu(e,t,r){let o=Ad.safeParse(t);if(o.success){ft(e.summaries,o.data,T(r,0));return}switch(t){case"VER":if(e.versionSeen||!r)throw Error("Expected one source version per record.");e.versionSeen=!0;return;case"DA":return Td(e,r);case"BRDA":return jd(e,r);case"FN":case"FNL":return Dd(e,t,r);case"FNDA":case"FNA":return Fd(e,t,r);default:throw Error("Unsupported LCOV field. Export a line, function and branch report.")}}function Oo(e){let t=0;for(let r of e.values())if(r)t+=1;return{found:e.size,hit:t}}function Ld(e){let t=e.functionNames.size>0||e.functionHits.size>0,r=e.groupIds.size>0||e.aliasHits.size>0;if(t&&r)throw Error("Function records mix classic names and alias groups.");if(r){let o=0;if(e.groupIds.size!==e.aliasHits.size)throw Error("Missing function group or alias records.");for(let n of e.groupIds){let i=e.aliasHits.get(n);if(!i?.size)throw Error("Function group is missing execution records.");if(Array.from(i.values()).some(Boolean))o+=1}return{found:e.groupIds.size,hit:o}}if(e.functionNames.size!==e.functionHits.size)throw Error("Missing function names or execution records.");for(let o of e.functionNames)if(!e.functionHits.has(o))throw Error("A function definition has no matching execution record.");return Oo(e.functionHits)}function wu(e,t){let r=Nd[t],o=e.summaries.get(r.found),n=e.summaries.get(r.hit);if(o===void 0||n===void 0)throw Error(`Missing ${r.found} or ${r.hit} summary.`);let i;switch(t){case"lines":i=Oo(e.lines);break;case"functions":i=Ld(e);break;case"branches":i=Oo(e.branches);break}if(i.found!==o||i.hit!==n)throw Error(`Summary ${n}/${o} differs from measured entries ${i.hit}/${i.found}.`);if(n!==o)throw Error(`Only ${n}/${o} were covered. The requirement is 100 percent.`);return i}var Yt=w().min(1).max(4096).refine((e)=>!/[\x00-\x1f\x7f]/.test(e)),Jd=P({root:Yt,file:Yt,config:Yt}),Vd=P({files:_(Yt).min(1).max(1e4),metrics:_(yu).min(1).max(3)});function Co(e){if(Ro(e)||/[\\:\x00-\x1f\x7f]/.test(e)||e.split("/").some((t)=>!t||t==="."||t===".."))throw Error(`Use a project-relative source path in the coverage configuration. Received "${e}".`);return e}function _u(e,t){let r=Wd(e,t);if(!r||r===".."||r.startsWith("../")||Ro(r))return;return r}function Hd(e,t,r){if(!e||/[\\:\x00-\x1f\x7f]/.test(e))throw Error("Expected a valid source path in the LCOV record.");if(Ro(e)){let o=_u(t,e)??_u(r,e);if(o)return Co(o);throw Error("An LCOV source is outside the project root.")}return Co(Ud(e))}function Kd(e,t){for(let[r,o]of t)try{let n=wu(e,r);o.found+=n.found,o.hit+=n.hit}catch(n){let i=n instanceof Error?n.message:String(n);throw Error(`${e.source} ${r}. ${i}`,{cause:n})}}function Gd(e,t,r,o){let n=Md(t),i=new Set,s=new Set,c,a=!1;for(let[p,l]of e.split(/\r?\n/).entries()){if(!l.trim()||l.startsWith("#"))continue;try{if(/[\x00-\x08\x0b-\x1f\x7f]/.test(l))throw Error("Control characters are not allowed in coverage records.");if(l.startsWith("TN:")&&!c&&!a)a=!0;else if((l.startsWith("SF:")||l.startsWith("KF:"))&&!c){let f=l.slice(3),[,d,g]=/^(\d+),(.*)$/.exec(f)??[],m=Hd(g??f,t,n);if(d!==void 0){let y=Number(d);if(!Number.isSafeInteger(y)||s.has(y))throw Error("Expected a distinct safe integer source index.");s.add(y)}if(i.has(m))throw Error(`Duplicate LCOV source "${m}".`);if(!r.has(m))throw Error(`Unexpected LCOV source "${m}".`);c=xu(m),a=!1}else if(l==="end_of_record"&&c)Kd(c,o),i.add(c.source),c=void 0;else if(c){let f=l.indexOf(":");if(f<1)throw Error("Malformed LCOV field.");vu(c,l.slice(0,f),l.slice(f+1))}else throw Error("Expected an LCOV source record.")}catch(f){let d=f instanceof Error?f.message:String(f);throw Error(`LCOV line ${p+1}. ${d}`,{cause:f})}}if(c||a)throw Error("The final LCOV record is incomplete.");let u=Array.from(r).filter((p)=>!i.has(p));if(u.length)throw Error(`LCOV is missing ${u.length} expected source files. First missing path is "${u[0]}".`)}function bu(e){let t=Jd.parse(e),r=Xt(t.root,t.config,262144,"coverage configuration"),o;try{o=Vd.parse(JSON.parse(r))}catch(a){throw Error(`Invalid coverage configuration "${t.config}". Provide JSON arrays for files and metrics.`,{cause:a})}let n=new Set(o.files.map(Co)),i=new Map;for(let a of o.metrics)i.set(a,{found:0,hit:0});if(n.size!==o.files.length||i.size!==o.metrics.length)throw Error("Coverage configuration contains duplicate files or metrics.");let s=Xt(t.root,t.file,16777216,"LCOV report");Gd(s,Bd(t.root),n,i);let c=Array.from(i,([a,u])=>{if(u.found===0)throw Error(`No measurable ${a} were found for the selected scope.`);return{metric:a,...u,percent:100}});return{file:t.file,config:t.config,sources:n.size,metrics:c}}import{lstatSync as Mu}from"node:fs";import{relative as Lu,resolve as _e}from"node:path";import{lstatSync as qd,readdirSync as $u}from"node:fs";import{basename as ku,resolve as dt}from"node:path";var Xd=ct({name:w().optional(),workspaces:oo([_(w()),ct({packages:_(w())})]).optional()}),Yd=new Set(["package.json","pnpm-workspace.yaml","Cargo.toml","go.mod","pyproject.toml","Gemfile","pom.xml","composer.json"]),zu=new Set([".git",".DS_Store",".agents",".claude",".opencode","llm","node_modules","dist","vendor"]);function Qd(e){let t=R(e,"package.json");if(!t)return;try{return Xd.parse(JSON.parse(t.bytes.toString("utf8")))}catch(r){throw Error(`Cannot read ${dt(e,"package.json")}. Correct the manifest and retry.`,{cause:r})}}function Je(e,t){if(t===".")return e;oe(t);let r=de(dt(e,t));if(!uo(e,r)||r!==dt(e,t))throw Error(`Choose a real directory inside ${e}. The repository path resolves through a symbolic link: ${t}.`);if(L(r)?.root!==r)throw Error(`Choose the Git repository root at ${r} before registering it.`);return r}function eh(e){let t=$u(e,{withFileTypes:!0});if(t.length>2048)throw Error(`Workspace discovery is limited to 2048 entries at ${e}. Choose a narrower directory.`);let r=[];for(let o of t.sort((n,i)=>n.name.localeCompare(i.name,"en"))){if(!o.isDirectory()||o.name.startsWith(".")||zu.has(o.name))continue;let n=dt(e,o.name);if(!qd(dt(n,".git"),{throwIfNoEntry:!1}))continue;if(L(n)?.root!==n)throw Error(`The Git metadata in ${n} does not identify that checkout as a repository root.`);oe(o.name),r.push({path:o.name,name:o.name,gitRoot:n})}return r}function Ze(e){let t=de(e),r=L(t),o=eh(t),n=new Set($u(t)),i=Qd(t),s=Boolean(i?.workspaces||n.has("pnpm-workspace.yaml")||n.has("lerna.json")),c=[...Yd].some((l)=>n.has(l)),a=r?{gitRoot:r.root}:{};if(o.length&&!s){let l=[...o];if(c)l.unshift({path:".",name:i?.name??ku(t),...a});return{root:t,kind:"workspace",monorepo:s,repositories:l,...a}}let u=[...n].every((l)=>zu.has(l)),p={path:".",name:i?.name??ku(t),...a};return{root:t,kind:u?"blank":"existing",monorepo:s,repositories:[p],...a}}import{lstatSync as Eu}from"node:fs";import{resolve as ht}from"node:path";function th(e,t,r,o=!1){let n=`# appToolkit harness ${t} begin`,i=`# appToolkit harness ${t} end`,s=e.includes(`\r
58
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let i of e.seen.entries()){let c=i[1];if(t===i[0]){s(i);continue}if(e.external){let u=e.external.registry.get(i[0])?.id;if(t!==i[0]&&u){s(i);continue}}if(e.metadataRegistry.get(i[0])?.id){s(i);continue}if(c.cycle){s(i);continue}if(c.count>1){if(e.reused==="ref")s(i)}}if(e.external)e.sharedDefsExtractedFor=e.external}function gc(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let o of t){if(!o||typeof o!=="object")return;gc(o);let n=Object.keys(o);if(n.length!==1||n[0]!=="type")return;let s=o.type;for(let i of Array.isArray(s)?s:[s]){if(typeof i!=="string")return;if(!r.includes(i))r.push(i)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var yc=new Set(["type","properties","required","additionalProperties"]),hc=["oneOf","anyOf"];function mc(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function Gr(e){let t=[];for(let s of e){if(typeof s!=="object"||s.type!=="object")return null;for(let i in s)if(!yc.has(i))return null;t.push(s)}let r={},o=new Set;for(let s of t){for(let i in s.properties){if(Object.prototype.hasOwnProperty.call(r,i))continue;let c=[];for(let u of t){let p=u.properties?.[i]??mc(u);if(p===null||p===void 0)continue;if(!c.some((l)=>JSON.stringify(l)===JSON.stringify(p)))c.push(p)}let a=c.length===1?c[0]:Gr(c)??{allOf:c};Q(r,i,a)}for(let i of s.required??[])o.add(i)}let n={type:"object",properties:r};if(o.size)n.required=[...o];if(t.every((s)=>s.additionalProperties===!1))n.additionalProperties=!1;else{let s=[];for(let i of t){let c=mc(i);if(c&&!s.some((a)=>JSON.stringify(a)===JSON.stringify(c)))s.push(c)}if(s.length===1)n.additionalProperties=s[0];else if(s.length>1)n.additionalProperties={allOf:s}}return n}function Xp(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let n of yc)if(n in e)return;let r=t.filter((n)=>hc.some((s)=>Array.isArray(n[s]))),o=null;if(!r.length)o=Gr(t);else{let n=r[0],s=hc.find((a)=>Array.isArray(n[a]));if(Object.keys(n).length!==1)return;let i=t.filter((a)=>a!==n),c=n[s].map((a)=>Gr([...i,a]));if(c.some((a)=>!a))return;o={[s]:c}}if(!o)return;delete e.allOf,nt(e,o)}function Yr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let o=(c)=>{let a=e.seen.get(c);if(a.ref===null)return;let u=a.def??a.schema,p={...u},l=a.ref;if(a.ref=null,l){o(l);let d=e.seen.get(l),m=d.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))u.allOf=u.allOf??[],u.allOf.push(m);else nt(u,m);if(nt(u,p),c._zod.parent===l)for(let y in u){if(y==="$ref"||y==="allOf")continue;if(!(y in p))delete u[y]}if(m.$ref&&d.def)for(let y in u){if(y==="$ref"||y==="allOf")continue;if(y in d.def&&JSON.stringify(u[y])===JSON.stringify(d.def[y]))delete u[y]}}let f=c._zod.parent;if(f&&f!==l){o(f);let d=e.seen.get(f);if(d?.schema.$ref){if(u.$ref=d.schema.$ref,d.def)for(let m in u){if(m==="$ref"||m==="allOf")continue;if(m in d.def&&JSON.stringify(u[m])===JSON.stringify(d.def[m]))delete u[m]}}}e.override({zodSchema:c,jsonSchema:u,path:a.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let c of[...e.seen.entries()].reverse())o(c[0]);if(e.target!=="openapi-3.0")for(let c of e.seen.entries())gc(c[1].def??c[1].schema);for(let c of e.deferred)c();if(e.intersections.length){let c=new Map;for(let a of e.seen.values())for(let u of[a.schema,a.def]){let p=u?.allOf;if(!Array.isArray(p))continue;let l=c.get(p);if(l)l.push(u);else c.set(p,[u])}for(let a of e.intersections)for(let u of c.get(a)??[])Xp(u)}}let n={};if(e.target==="draft-2020-12")n.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")n.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")n.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let c=e.external.registry.get(t)?.id;if(!c)throw Error("Schema is missing an `id` property");n.$id=e.external.uri(c)}nt(n,r.defId?r.schema:r.def??r.schema);let s=e.metadataRegistry.get(t)?.id;if(s!==void 0&&n.id===s)delete n.id;let i=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let c of e.seen.entries()){let a=c[1];if(a.def&&a.defId){if(a.def.id===a.defId)delete a.def.id;Q(i,a.defId,a.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(i).length>0)if(e.target==="draft-2020-12")n.$defs=i;else n.definitions=i;try{let c=JSON.parse(JSON.stringify(n));return Object.defineProperty(c,"~standard",{value:{...t["~standard"],jsonSchema:{input:st(t,"input",e.processors),output:st(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch(c){throw Error("Error converting schema to JSON.")}}function L(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let o=e._zod.def;if(o.type==="transform")return!0;if(o.type==="array")return L(o.element,r);if(o.type==="set")return L(o.valueType,r);if(o.type==="lazy")return L(o.getter(),r);if(o.type==="promise"||o.type==="optional"||o.type==="nonoptional"||o.type==="nullable"||o.type==="readonly"||o.type==="default"||o.type==="prefault"||o.type==="catch")return L(o.innerType,r);if(o.type==="intersection")return L(o.left,r)||L(o.right,r);if(o.type==="record"||o.type==="map")return L(o.keyType,r)||L(o.valueType,r);if(o.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return L(o.in,r)||L(o.out,r)}if(o.type==="object"){for(let n in o.shape)if(L(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(L(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(L(n,r))return!0;if(o.rest&&L(o.rest,r))return!0;return!1}return!1}var xc=(e,t={})=>(r)=>{let o=qr({...r,processors:t});return A(e,o),Xr(o,e),Yr(o,e)},st=(e,t,r={})=>(o)=>{let{libraryOptions:n,target:s}=o??{},i=qr({...n??{},target:s,io:t,processors:r});return A(e,i),Xr(i,e),Yr(i,e)};var je=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},De=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},vc=(e,t)=>{je(e,"minimum",t),De(e,"maximum",t)},kc=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},$c=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},zc=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},Sc=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},wc=(e,t)=>je(e,"minimum",t.minimum),_c=(e,t)=>De(e,"maximum",t.maximum),bc=(e)=>(t,r)=>{Sc(t,r.format);let[o,n]=e[r.format];je(t,"minimum",o),De(t,"maximum",n)},Yp={greater_than:(e,t)=>je(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>De(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>kc(e,t.value),number_format:bc(wt),bigint_format:bc(dr),min_length:wc,max_length:_c,length_equals:(e,t)=>vc(e,t.length),min_size:wc,max_size:_c,size_equals:(e,t)=>vc(e,t.size),string_format:(e,t)=>{if(Sc(e,t.format),t.pattern)$c(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>zc(e,t.mime)};function j(e){let t={},r=e._zod.def,o=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let s of o)Yp[s._zod.def.check]?.(t,s._zod.def);let n=e._zod.bag;if(n.minimum!==void 0)je(t,"minimum",n.minimum);if(n.exclusiveMinimum!==void 0)je(t,"exclusiveMinimum",n.exclusiveMinimum);if(n.maximum!==void 0)De(t,"maximum",n.maximum);if(n.exclusiveMaximum!==void 0)De(t,"exclusiveMaximum",n.exclusiveMaximum);if(n.multipleOf!==void 0)kc(t,n.multipleOf);if(n.format!==void 0){if(t.format??(t.format=n.format),n.format.includes("int"))t.isInt=!0}if(n.mime)zc(t,n.mime);for(let s of n.patterns??[])$c(t,s);return t}var Qp={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},el=new Map([[Zr,Mn],[Dt,Wn]]),tl=(e)=>el.get(e)??e,Pc=(e,t,r,o)=>{let n=r;n.type="string";let{minimum:s,maximum:i,format:c,patterns:a,contentEncoding:u,laxFormat:p}=j(e);if(typeof s==="number")n.minLength=s;if(typeof i==="number")n.maxLength=i;if(c){if(n.format=Qp[c]??c,n.format==="")delete n.format;if(c==="time"||p)delete n.format}if(u)n.contentEncoding=u;if(a&&a.size>0){let l=[...a].map(tl);if(l.length===1)n.pattern=l[0].source;else if(l.length>1)n.allOf=[...l.map((f)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))]}},Ec=(e,t,r,o)=>{let n=r,{minimum:s,maximum:i,multipleOf:c,exclusiveMaximum:a,exclusiveMinimum:u,isInt:p}=j(e);n.type=p?"integer":"number";let l=typeof u==="number"&&u>=(s??Number.NEGATIVE_INFINITY),f=typeof a==="number"&&a<=(i??Number.POSITIVE_INFINITY),d=t.target==="draft-04"||t.target==="openapi-3.0";if(l)if(d)n.minimum=u,n.exclusiveMinimum=!0;else n.exclusiveMinimum=u;else if(typeof s==="number")n.minimum=s;if(f)if(d)n.maximum=a,n.exclusiveMaximum=!0;else n.exclusiveMaximum=a;else if(typeof i==="number")n.maximum=i;if(c){let m=new Set;for(let v of c)if(Number.isFinite(v)&&v!==0)m.add(Math.abs(v));else re(e,t,n,o,`A multipleOf divisor of ${v} cannot be represented in JSON Schema`);let[g,...y]=m;if(g!==void 0)n.multipleOf=g;if(y.length)n.allOf=[...n.allOf??[],...y.map((v)=>({multipleOf:v}))]}},Zc=(e,t,r,o)=>{r.type="boolean"},Oc=(e,t,r,o)=>{re(e,t,r,o,"BigInt cannot be represented in JSON Schema")};var Rc=(e,t,r,o)=>{r.not={}};var Cc=(e,t,r,o)=>{},Ic=(e,t,r,o)=>{re(e,t,r,o,"Date cannot be represented in JSON Schema")},Ac=(e,t,r,o)=>{let n=e._zod.def,s=Ke(n.entries);if(s.length===0){r.not={};return}if(s.every((i)=>typeof i==="number"))r.type="number";if(s.every((i)=>typeof i==="string"))r.type="string";r.enum=s},Tc=(e,t,r,o)=>{let n=e._zod.def;if(n.values.length===0){r.not={};return}let s=[];for(let i of n.values)if(i===void 0){if(re(e,t,r,o,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof i==="bigint"){if(re(e,t,r,o,"BigInt literals cannot be represented in JSON Schema"))return;s.push(Number(i))}else s.push(i);if(s.length===0);else if(s.length===1){let i=s[0];if(r.type=i===null?"null":typeof i,t.target==="draft-04"||t.target==="openapi-3.0")r.enum=[i];else r.const=i}else{if(s.every((i)=>typeof i==="number"))r.type="number";if(s.every((i)=>typeof i==="string"))r.type="string";if(s.every((i)=>typeof i==="boolean"))r.type="boolean";if(s.every((i)=>i===null))r.type="null";r.enum=s}};var Nc=(e,t,r,o)=>{re(e,t,r,o,"Custom types cannot be represented in JSON Schema")};var jc=(e,t,r,o)=>{re(e,t,r,o,"Transforms cannot be represented in JSON Schema")};var Dc=(e,t,r,o)=>{let n=r,s=e._zod.def,{minimum:i,maximum:c}=j(e);if(typeof i==="number")n.minItems=i;if(typeof c==="number")n.maxItems=c;n.type="array",n.items=A(s.element,t,{...o,path:[...o.path,"items"]})};function Qr(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return Qr(t.out);if(t.type==="catch")return Qr(t.innerType);return e._zod.optin}var Fc=(e,t,r,o)=>{let n=r,s=e._zod.def,i=s.shape;if(Object.getOwnPropertySymbols(i).length&&re(e,t,n,o,"Symbol keys cannot be represented in JSON Schema"))return;n.type="object",n.properties={};for(let u in i)Q(n.properties,u,A(i[u],t,{...o,path:[...o.path,"properties",u]}));let a=[];for(let u of Object.keys(i)){let p=s.shape[u];if(t.io==="input"?Qr(p)===void 0:p._zod.optout===void 0)a.push(u)}if(a.length>0)n.required=a;if(s.catchall?._zod.def.type==="never")n.additionalProperties=!1;else if(!s.catchall){if(t.io==="output")n.additionalProperties=!1}else if(s.catchall)n.additionalProperties=A(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},Lc=(e,t,r,o)=>{let n=e._zod.def,s=n.inclusive===!1,i=n.options.map((c,a)=>A(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",a]}));if(s)r.oneOf=i;else r.anyOf=i},Mc=(e,t,r,o)=>{let n=e._zod.def,s=A(n.left,t,{...o,path:[...o.path,"allOf",0]}),i=A(n.right,t,{...o,path:[...o.path,"allOf",1]}),c=(u)=>("allOf"in u)&&Object.keys(u).length===1,a=[...c(s)?s.allOf:[s],...c(i)?i.allOf:[i]];r.allOf=a,t.intersections.push(a)};var Wc=(e,t,r,o)=>{let n=e._zod.def,s=A(n.innerType,t,o),i=t.seen.get(e);if(t.target==="openapi-3.0")i.ref=n.innerType,r.nullable=!0;else r.anyOf=[s,{type:"null"}]},Uc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType},eo=Symbol();function Bc(e,t,r,o,n){let s=!1,i=JSON.stringify(e,(c,a)=>{if(typeof a!=="bigint")return a;return s=!0,null});if(!s)return JSON.parse(i);return re(t,r,o,n,"BigInt defaults cannot be represented in JSON Schema"),eo}var Jc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType;let i=Bc(n.defaultValue,e,t,r,o);if(i!==eo)r.default=i},Vc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);if(s.ref=n.innerType,t.io!=="input")return;let i=Bc(n.defaultValue,e,t,r,o);if(i!==eo)r._prefault=i},Hc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType;let i;try{i=n.catchValue(void 0)}catch{re(e,t,r,o,"Dynamic catch values are not supported in JSON Schema");return}r.default=i},Kc=(e,t,r,o)=>{let n=e._zod.def,s=n.in._zod.traits.has("$ZodTransform"),i=t.io==="input"?s?n.out:n.in:n.out;A(i,t,o);let c=t.seen.get(e);c.ref=i},Gc=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType,r.readOnly=!0};var to=(e,t,r,o)=>{let n=e._zod.def;A(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType};var qc=new WeakSet([Object.prototype,Error.prototype]);function Vt(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let o=r(this);return Object.defineProperty(this,t,{value:o,configurable:!0,writable:!0}),o},set(o){Object.defineProperty(this,t,{value:o,configurable:!0,writable:!0})}})}var pl=(e,t)=>{hn.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(qc.has(r))return;qc.add(r),Vt(r,"format",(o)=>(n)=>gn(o,n)),Vt(r,"flatten",(o)=>(n)=>mn(o,n)),Vt(r,"addIssue",(o)=>(n)=>{o.issues.push(n),o.message=JSON.stringify(o.issues,Ge,2)}),Vt(r,"addIssues",(o)=>(n)=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,Ge,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var V=h("ZodError",pl,void 0,{Parent:Error});var Xc=Zt(V),Yc=Ot(V),Qc=Rt(V),ea=Ct(V),ta=xn(V),ra=vn(V),oa=wn(V),na=_n(V),sa=bn(V),ia=kn(V),ca=$n(V),aa=zn(V);function fl(){if(!J.localeError)te(Tr())}function oo(){if(!J.memoizer)te({memoizer:Si()})}var O=h("ZodType",(e,t)=>(fl(),E.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(B(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ne(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(nf(e,t))},superRefine(e,t){return this.check(sf(e,t))},overwrite(e){return this.check(ve(e))},optional(){return la(this)},exactOptional(){return Jl(this)},nullable(){return fa(this)},nullish(){return la(fa(this))},nonoptional(e){return Xl(this,e)},array(){return _(this)},or(e){return co([this,e])},and(e){return Ml(this,e)},transform(e){return da(this,Bl(e))},default(e){return Kl(this,e)},prefault(e){return ql(this,e)},catch(e){return Ql(this,e)},pipe(e){return da(this,e)},readonly(){return rf(this)},describe(e){let t=this.clone();return ze.add(t,{description:e}),t},meta(...e){if(e.length===0)return ze.get(this);let t=this.clone();return ze.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get "~standard"(){return St(this,"~standard",{...Er(this),jsonSchema:{input:st(this,"input"),output:st(this,"output")}})},set "~standard"(e){pe(this,"~standard",e)},parse:function e(t,r){return Xc(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await Yc(this,t,r,{callee:e})},safeParse(e,t){return Qc(this,e,t)},async safeParseAsync(e,t){return ea(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){pe(this,"spa",e)},validate(e,t){return xr(this,e,t)},validateAsync(e,t){return vr(this,e,t)},encode:function e(t,r){return ta(this,t,r,{callee:e})},decode:function e(t,r){return ra(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await oa(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await na(this,t,r,{callee:e})},safeEncode(e,t){return sa(this,e,t)},safeDecode(e,t){return ia(this,e,t)},async safeEncodeAsync(e,t){return ca(this,e,t)},async safeDecodeAsync(e,t){return aa(this,e,t)},toJSONSchema(e){return xc(this,{})(e)},get description(){return ze.get(this)?.description},get _def(){return this._zod.def}}),ha=h("_ZodString",(e,t)=>{jt.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Pc(e,r,o,n)},Pt({format:(e)=>j(e).format??null,minLength:(e)=>j(e).minimum??null,maxLength:(e)=>j(e).maximum??null},{regex(...e){return this.check(Dr(...e))},includes(...e){return this.check(Mr(...e))},startsWith(...e){return this.check(Wr(...e))},endsWith(...e){return this.check(Ur(...e))},min(...e){return this.check(Ne(...e))},max(...e){return this.check(Bt(...e))},length(...e){return this.check(Jt(...e))},nonempty(...e){return this.check(Ne(1,...e))},lowercase(e){return this.check(Fr(e))},uppercase(e){return this.check(Lr(e))},trim(){return this.check(Jr())},normalize(...e){return this.check(Br(...e))},toLowerCase(){return this.check(Vr())},toUpperCase(){return this.check(Hr())},slugify(){return this.check(Kr())}})),no=h("ZodString",(e,t)=>{jt.init(e,t),ha.init(e,t)},{email(e){return this.check(Ri(yl,e))},url(e){return this.check(jr(ma,e))},jwt(e){return this.check(qi(Al,e))},emoji(e){return this.check(Ni(wl,e))},guid(e){return this.check(Ci(xl,e))},uuid(e){return this.check(Nr(ct,e))},uuidv4(e){return this.check(Ii(ct,e))},uuidv6(e){return this.check(Ai(ct,e))},uuidv7(e){return this.check(Ti(ct,e))},nanoid(e){return this.check(ji(_l,e))},cuid(e){return this.check(Di(bl,e))},cuid2(e){return this.check(Fi(kl,e))},ulid(e){return this.check(Li($l,e))},base64(e){return this.check(Hi(Rl,e))},base64url(e){return this.check(Ki(Cl,e))},xid(e){return this.check(Mi(zl,e))},ksuid(e){return this.check(Wi(Sl,e))},ipv4(e){return this.check(Ui(Pl,e))},ipv6(e){return this.check(Bi(El,e))},cidrv4(e){return this.check(Ji(Zl,e))},cidrv6(e){return this.check(Vi(Ol,e))},e164(e){return this.check(Gi(Il,e))},datetime(e){return this.check(Xi(dl,e))},date(e){return this.check(Yi(hl,e))},time(e){return this.check(Qi(ml,e))},duration(e){return this.check(ec(gl,e))}});function w(e){return Zi(no,e)}var R=h("ZodStringFormat",(e,t)=>{Z.init(e,t),ha.init(e,t)}),dl=h("ZodISODateTime",(e,t)=>{Ds.init(e,t),R.init(e,t)}),hl=h("ZodISODate",(e,t)=>{Fs.init(e,t),R.init(e,t)}),ml=h("ZodISOTime",(e,t)=>{Ls.init(e,t),R.init(e,t)}),gl=h("ZodISODuration",(e,t)=>{Ms.init(e,t),R.init(e,t)}),yl=h("ZodEmail",(e,t)=>{Ps.init(e,t),R.init(e,t)});var xl=h("ZodGUID",(e,t)=>{zs.init(e,t),R.init(e,t)});var ct=h("ZodUUID",(e,t)=>{Ss.init(e,t),R.init(e,t)});function so(e){return Nr(ct,e)}var ma=h("ZodURL",(e,t)=>{Os.init(e,t),R.init(e,t)});function vl(e){return jr(ma,e)}var wl=h("ZodEmoji",(e,t)=>{Rs.init(e,t),R.init(e,t)});var _l=h("ZodNanoID",(e,t)=>{Cs.init(e,t),R.init(e,t)});var bl=h("ZodCUID",(e,t)=>{Is.init(e,t),R.init(e,t)});var kl=h("ZodCUID2",(e,t)=>{As.init(e,t),R.init(e,t)});var $l=h("ZodULID",(e,t)=>{Ts.init(e,t),R.init(e,t)});var zl=h("ZodXID",(e,t)=>{Ns.init(e,t),R.init(e,t)});var Sl=h("ZodKSUID",(e,t)=>{js.init(e,t),R.init(e,t)});var Pl=h("ZodIPv4",(e,t)=>{Ws.init(e,t),R.init(e,t)});var El=h("ZodIPv6",(e,t)=>{Bs.init(e,t),R.init(e,t)});var Zl=h("ZodCIDRv4",(e,t)=>{Js.init(e,t),R.init(e,t)});var Ol=h("ZodCIDRv6",(e,t)=>{Vs.init(e,t),R.init(e,t)});var Rl=h("ZodBase64",(e,t)=>{Ks.init(e,t),R.init(e,t)});var Cl=h("ZodBase64URL",(e,t)=>{Gs.init(e,t),R.init(e,t)});var Il=h("ZodE164",(e,t)=>{qs.init(e,t),R.init(e,t)});var Al=h("ZodJWT",(e,t)=>{Xs.init(e,t),R.init(e,t)});var Ht=h("ZodNumber",(e,t)=>{Or.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Ec(e,r,o,n),e.isFinite=!0},Pt({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=j(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=j(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=j(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>j(e).format??null},{gt(e,t){return this.check(Te(e,t))},gte(e,t){return this.check(fe(e,t))},min(e,t){return this.check(fe(e,t))},lt(e,t){return this.check(Ae(e,t))},lte(e,t){return this.check(le(e,t))},max(e,t){return this.check(le(e,t))},int(e){return this.check(ua(e))},safe(e){return this.check(ua(e))},positive(e){return this.check(Te(0,e))},nonnegative(e){return this.check(fe(0,e))},negative(e){return this.check(Ae(0,e))},nonpositive(e){return this.check(le(0,e))},multipleOf(e,t){return this.check(ot(e,t))},step(e,t){return this.check(ot(e,t))},finite(){return this}}));function ga(e){return tc(Ht,e)}var Tl=h("ZodNumberFormat",(e,t)=>{Ys.init(e,t),Ht.init(e,t)});function ua(e){return oc(Tl,e)}var io=h("ZodBoolean",(e,t)=>{Qs.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Zc(e,r,o,n)});function Fe(e){return nc(io,e)}var ya=h("ZodBigInt",(e,t)=>{ei.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Oc(e,r,o,n)},Pt({minValue:(e)=>j(e).minimum??null,maxValue:(e)=>j(e).maximum??null,format:(e)=>j(e).format??null},{gte(e,t){return this.check(fe(e,t))},min(e,t){return this.check(fe(e,t))},gt(e,t){return this.check(Te(e,t))},lt(e,t){return this.check(Ae(e,t))},lte(e,t){return this.check(le(e,t))},max(e,t){return this.check(le(e,t))},positive(e){return this.check(Te(BigInt(0),e))},negative(e){return this.check(Ae(BigInt(0),e))},nonpositive(e){return this.check(le(BigInt(0),e))},nonnegative(e){return this.check(fe(BigInt(0),e))},multipleOf(e,t){return this.check(ot(e,t))}}));var Nl=h("ZodUnknown",(e,t)=>{ti.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Cc(e,r,o,n)});function pa(){return cc(Nl)}var jl=h("ZodNever",(e,t)=>{ri.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Rc(e,r,o,n)});function xa(e){return ac(jl,e)}var va=h("ZodDate",(e,t)=>{oi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Ic(e,r,o,n),e.min=(r,o)=>e.check(fe(r,o)),e.max=(r,o)=>e.check(le(r,o))},Pt({minDate:(e)=>{let{minimum:t}=j(e);return t?new Date(t):null},maxDate:(e)=>{let{maximum:t}=j(e);return t?new Date(t):null}},{}));var Dl=h("ZodArray",(e,t)=>{oo(),ni.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Dc(e,r,o,n),e.element=t.element},{min(e,t){return this.check(Ne(e,t))},nonempty(e){return this.check(Ne(1,e))},max(e,t){return this.check(Bt(e,t))},length(e,t){return this.check(Jt(e,t))},unwrap(){return this.element}});function _(e,t){return pc(Dl,e,t)}var wa=h("ZodObject",(e,t)=>{oo(),ci.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Fc(e,r,o,n),gp(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return X(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(B(this._zod.def,{catchall:e}))},passthrough(){return this.clone(B(this._zod.def,{catchall:pa()}))},loose(){return this.clone(B(this._zod.def,{catchall:pa()}))},strict(){return this.clone(B(this._zod.def,{catchall:xa()}))},strip(){return this.clone(B(this._zod.def,{catchall:void 0}))},extend(e){return ap(this,e)},safeExtend(e){return up(this,e)},merge(e){return pp(this,e)},pick(e){return ip(this,e)},omit(e){return cp(this,e)},partial(...e){return nn(ba,this,e[0])},exactPartial(...e){return nn(ka,this,e[0],"exactPartial")},required(...e){return lp($a,this,e[0])}});function at(e,t){let r={type:"object",shape:e??{},...x(t)};return new wa(r)}function P(e,t){return new wa({type:"object",shape:e,catchall:xa(),...x(t)})}var _a=h("ZodUnion",(e,t)=>{Rr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Lc(e,r,o,n),e.options=t.options});function co(e,t){return new _a({type:"union",options:e,...x(t)})}var Fl=h("ZodDiscriminatedUnion",(e,t)=>{_a.init(e,t),ai.init(e,t)});function ao(e,t,r){return new Fl({type:"union",options:t,discriminator:e,...x(r)})}var Ll=h("ZodIntersection",(e,t)=>{ui.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Mc(e,r,o,n)});function Ml(e,t){return new Ll({type:"intersection",left:e,right:t})}var ro=h("ZodEnum",(e,t)=>{pi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(o,n,s)=>Ac(e,o,n,s),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(o,n)=>{let s={};for(let i of o)if(r.has(i))s[i]=t.entries[i];else throw Error(`Key ${i} not found in enum`);return new ro({...t,checks:[],...x(n),entries:s})},e.exclude=(o,n)=>{let s={...t.entries};for(let i of o)if(r.has(i))delete s[i];else throw Error(`Key ${i} not found in enum`);return new ro({...t,checks:[],...x(n),entries:s})}});function X(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new ro({type:"enum",entries:r,...x(t)})}var Wl=h("ZodLiteral",(e,t)=>{li.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Tc(e,r,o,n),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function H(e,t){return new Wl({type:"literal",values:Array.isArray(e)?e:[e],...x(t)})}var Ul=h("ZodTransform",(e,t)=>{oo(),fi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>jc(e,r,o,n),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new Ye(e.constructor.name);r.addIssue=(s)=>{if(typeof s==="string")r.issues.push($e(s,r.value,t));else{let i=s;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=r.value;i.inst??(i.inst=e),r.issues.push($e(i))}};let n=t.transform(r.value,r);if(n instanceof Promise)return n.then((s)=>(r.value=s,r));return r.value=n,r}});function Bl(e){return new Ul({type:"transform",transform:e})}var ba=h("ZodOptional",(e,t)=>{Cr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>to(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function la(e){return new ba({type:"optional",innerType:e})}var ka=h("ZodExactOptional",(e,t)=>{di.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>to(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Jl(e){return new ka({type:"optional",innerType:e})}var Vl=h("ZodNullable",(e,t)=>{hi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Wc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function fa(e){return new Vl({type:"nullable",innerType:e})}var Hl=h("ZodDefault",(e,t)=>{mi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Jc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Kl(e,t){return new Hl({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():lr(t)}})}var Gl=h("ZodPrefault",(e,t)=>{gi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Vc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function ql(e,t){return new Gl({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():lr(t)}})}var $a=h("ZodNonOptional",(e,t)=>{yi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Uc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Xl(e,t){return new $a({type:"nonoptional",innerType:e,...x(t)})}var Yl=h("ZodCatch",(e,t)=>{xi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Hc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Ql(e,t){return new Yl({type:"catch",innerType:e,catchValue:typeof t==="function"?t:un(t)})}var ef=h("ZodPipe",(e,t)=>{vi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Kc(e,r,o,n),e.in=t.in,e.out=t.out});function da(e,t){return new ef({type:"pipe",in:e,out:t})}var tf=h("ZodReadonly",(e,t)=>{wi.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Gc(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function rf(e){return new tf({type:"readonly",innerType:e})}var of=h("ZodCustom",(e,t)=>{_i.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Nc(e,r,o,n)});function nf(e,t={}){return lc(of,e,t)}function sf(e,t){return fc(e,t)}var uo={};np(uo,{bigint:()=>lf,boolean:()=>pf,date:()=>ff,number:()=>uf,string:()=>af});function af(e){return Oi(no,e)}function uf(e){return rc(Ht,e)}function pf(e){return sc(io,e)}function lf(e){return ic(ya,e)}function ff(e){return uc(va,e)}var po=X(["codex","claude","opencode"]),df=w().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),hf="Initialize an AppToolkit workspace, register an existing checkout, or find the approved project workflow.",mf={codex:".agents/skills/apptoolkit/SKILL.md",claude:".claude/skills/apptoolkit/SKILL.md",opencode:".opencode/commands/apptoolkit.md"},za=["For requests involving this workspace, read `llm/HARNESS.md` and use its workflow index to open the relevant procedure. Follow the established rules for the project and target repository.","","For a request like “Dame mi lista de pendientes”, open W01. For a new feature, use W16 to establish requirements before W18 implementation."].join(`
59
+ `);function lo(e){let t=new Set(_(po).parse(e)),r=[];if(t.has("codex")||t.has("opencode"))r.push({path:"AGENTS.md",content:za});if(t.has("claude"))r.push({path:"CLAUDE.md",content:za});return r}function gf(e,t){let r=["---"];if(e!=="opencode")r.push("name: apptoolkit");if(r.push(`description: ${hf}`),e==="claude")r.push('argument-hint: "[init | add repo <path> | workflow <request>]"');if(r.push("---","",`# AppToolkit Harness ${t}`,""),e!=="codex")r.push("Treat the following as user arguments, never as shell source.","","$ARGUMENTS","");return r.push("Find the installed workspace root using `llm/harness/workspace.json`. Open the session from that root when discovery is ambiguous.","Read `llm/HARNESS.md`, the project settings, and relevant repository instructions before choosing a workflow. Read the indexed workflow by ID instead of loading every workflow.","","Use `rtk proxy bun --no-env-file <workspace>/llm/harness/runtime/harness.mjs` for deterministic operations. If only Node.js is available, replace `bun --no-env-file` with `node`. Substitute absolute paths with individually quoted arguments.","","- For `init`, use `init --root <workspace> --json` to load the configuration template. Ask about budgets and discover approved project rules, tool routes, authority, and documentation conventions. Keep service connections and snapshots opt-in. Save the agreed answers as an explicit JSON input with credential references only. Apply it with `init --root <workspace> --config <input>`.","- For `add repo <path>`, identify the existing checkout and ask whether harness files there may be versioned. Preview `add repo <path> --root <workspace>` with the agreed `--repo-versioned` or `--repo-local` choice. Apply with `--yes` only after the user approves that plan. Keep shared knowledge in the workspace and scope repository-specific instructions to the checkout.","- For feature requests, use W16 to settle the definition before W18 implementation. In existing projects, an authoritative ticket or approved specification may satisfy that gate.","- For other requests, resolve the closest workflow from the index. Obtain separate authority for external writes and Git writes. Do not grant tool access or move credentials into the workspace.",""),r.join(`
60
+ `)}function fo(e,t){let r=_(po).parse(e),o=df.parse(t);return[...new Set(r)].map((n)=>({path:mf[n],content:gf(n,o)}))}import{randomUUID as Gf}from"node:crypto";import{lstatSync as qf,readFileSync as Xf,realpathSync as Ga,renameSync as Yf,rmSync as Qf,writeFileSync as ed}from"node:fs";import{dirname as td,join as Je,relative as rd,resolve as qa}from"node:path";import{mkdirSync as Cf,readFileSync as If,rmSync as ja,writeFileSync as Af}from"node:fs";import{tmpdir as Tf}from"node:os";import{resolve as go}from"node:path";import{createHash as yf,randomUUID as xf}from"node:crypto";import{chmodSync as vf,linkSync as wf,lstatSync as Kt,mkdirSync as _f,readFileSync as bf,realpathSync as Ea,renameSync as kf,rmSync as $f,unlinkSync as zf,writeFileSync as Sf}from"node:fs";import{dirname as Sa,isAbsolute as Za,relative as Oa,resolve as pt,sep as Pf}from"node:path";var Pa=16777216;class Gt extends Error{}function Ra(e){return"code"in e&&e.code==="ENOENT"}function de(e){let t=Ea(pt(e));if(!Kt(t).isDirectory())throw Error(`Expected an existing directory at ${t}.`);return t}function ho(e,t){let r=Oa(e,t);return r!==".."&&!r.startsWith(`..${Pf}`)&&!Za(r)}function we(e,t){if(!ho(e,t))throw Error(`Path ${t} is outside ${e}.`);return Oa(e,t)||"."}function oe(e){let t=e.split("/");if(Za(e)||/[\\\u0000-\u001f\u007f]/u.test(e)||t.some((r)=>!r||r==="."||r===".."||r===".git"))throw Error(`Expected a safe relative path. Received ${JSON.stringify(e)}.`)}function qt(e,t){if(oe(t),Ea(e)!==e||!Kt(e).isDirectory())throw Error(`The installation base changed. Inspect ${e} before retrying.`);let r=t.split("/"),o=e;for(let[n,s]of r.entries()){o=pt(o,s);let i=Kt(o,{throwIfNoEntry:!1});if(!i)break;let c=n===r.length-1;if(i.isSymbolicLink()||!c&&!i.isDirectory()||c&&!i.isFile())throw new Gt(`Expected a regular file path. Inspect ${o} before retrying.`)}return pt(e,t)}function W(e){return yf("sha256").update(e).digest("hex")}function U(e,t=420){let r=Buffer.isBuffer(e)?e:Buffer.from(e);return{bytes:r,hash:W(r),mode:t}}function C(e,t){let r=qt(e,t),o=Kt(r,{throwIfNoEntry:!1});if(!o)return null;if(o.size>Pa)throw Error(`The file at ${r} exceeds the ${Pa}-byte installation limit.`);return U(bf(r),o.mode&511)}function ce(e,t){return e?.hash===t?.hash&&e?.mode===t?.mode}function ut(e){if(!ce(C(e.base,e.path),e.before))throw Error(`File changed after planning. Replan before applying ${pt(e.base,e.path)}.`)}function Xt(e){ut(e);let t=qt(e.base,e.path);if(!e.after){zf(t);return}_f(Sa(t),{recursive:!0}),ut(e);let r=pt(Sa(t),`.apptoolkit-${xf()}.tmp`),o=e.after;try{if(Sf(r,o.bytes,{flag:"wx",mode:o.mode}),vf(r,o.mode),e.before)ut(e),kf(r,t);else wf(r,t)}finally{$f(r,{force:!0})}}import{spawnSync as Ef}from"node:child_process";import{lstatSync as Zf,realpathSync as Ca}from"node:fs";import{dirname as Ia,resolve as mo}from"node:path";function Of(){let e={};for(let[t,r]of Object.entries(process.env))if(!t.startsWith("GIT_"))e[t]=r;return{...e,GIT_OPTIONAL_LOCKS:"0",LC_ALL:"C"}}function Le(e,t,r=[0],o=!1){let s=Ef("rtk",["proxy","git",...o?["--literal-pathspecs"]:[],"-C",e,...t],{encoding:"utf8",env:Of(),maxBuffer:1048576,timeout:1e4});if(s.error)throw Error(`Cannot run Git ${t[0]} in ${e}. Verify RTK and Git are installed.`,{cause:s.error});if(s.status===null||!r.includes(s.status))throw Error(`Git ${t[0]} failed in ${e}: ${s.stderr.trim()||`exit ${s.status}`}`);return{output:s.stdout,status:s.status}}function Aa(e){let t=e;while(!0){let r=Zf(mo(t,".git"),{throwIfNoEntry:!1});if(r?.isDirectory()||r?.isFile())return t;if(r)throw Error(`Unsupported Git metadata at ${mo(t,".git")}. Inspect the repository before retrying.`);let o=Ia(t);if(o===t)return;t=o}}function M(e){if(!Aa(e))return;let t=Ca(Le(e,["rev-parse","--show-toplevel"]).output.trimEnd()),r=Ca(Le(e,["rev-parse","--path-format=absolute","--git-common-dir"]).output.trimEnd()),o=Le(e,["rev-parse","--path-format=absolute","--git-path","info/exclude"]).output.trimEnd();if(mo(r,"info/exclude")!==o)throw Error(`Git returned a local exclude path outside the expected metadata directory for ${e}.`);return{root:t,commonDirectory:r,exclude:"info/exclude"}}function Se(e,t){if(Aa(Ia(e))!==t)throw Error(`The path ${e} belongs to a different Git checkout. Select that checkout explicitly before retrying.`)}function Me(e,t){let r=we(e.root,t);return Le(e.root,["ls-files","--cached","-z","--",r],[0],!0).output.split("\x00").includes(r)}function Yt(e,t){let r=Le(e.git.root,["check-ignore","--quiet","--",`./${e.path}`],[0,1]);if(!t&&r.status!==0)throw Error(`Git did not ignore ${e.path} in ${e.git.root}. Check for an existing tracked file or a higher-priority rule before retrying.`);if(t&&r.status===0)throw Error(`Git ignores ${e.path} in ${e.git.root}. Choose local mode or resolve the existing exclusion before retrying.`)}function Rf(e){if(e.includes("://")){try{let n=new URL(e);if(n.hostname&&n.pathname!=="/")return`${n.host.toLowerCase()}${n.pathname.replace(/\.git\/?$/,"").replace(/\/$/,"")}`}catch(n){throw Error("Git returned an invalid origin URL. Correct the local repository configuration before retrying.",{cause:n})}return}let t=/^(?:[^@/:\s]+@)?([^/:\s]+):([^\s]+)$/.exec(e),r=t?.[1],o=t?.[2];if(r&&o)return`${r.toLowerCase()}/${o.replace(/^\//,"").replace(/\.git\/?$/,"").replace(/\/$/,"")}`;return}function Ta(e){let t=Le(e,["config","--local","--get","remote.origin.url"],[0,1]);if(t.status===1)return;let r=Rf(t.output.trimEnd());if(!r)return;return W(r)}function Qt(e){return`/${e.replace(/[\\[\]*? #!]/gu,"\\$&")}`}var Nf=uo.number().int().positive(),Da=new WeakMap;function Fa(e,t){Da.set(e,t)}function jf(e){let t=go(Tf(),`apptoolkit-${W(e).slice(0,24)}.lock`),r=go(t,"owner");try{Cf(t,{mode:448})}catch(o){if(!(o instanceof Error)||!("code"in o)||o.code!=="EEXIST")throw Error(`Cannot acquire the installation lock ${t}.`,{cause:o});let n;try{n=Nf.parse(If(r,"utf8"))}catch(s){throw Error(`An installation lock already exists at ${t}. If no install is running, remove the stale lock directory and retry.`,{cause:s})}try{process.kill(n,0)}catch(s){if(s instanceof Error&&"code"in s&&s.code==="ESRCH")throw Error(`The previous installation stopped. Remove its stale lock at ${t} and rerun the same installation to resume.`,{cause:s});throw Error(`Cannot confirm whether the installation holding ${t} is still running.`,{cause:s})}throw Error(`Another installation is running for ${e} with process ID ${n}. Retry after it finishes.`)}try{Af(r,`${process.pid}
61
+ `,{mode:384,flag:"wx"})}catch(o){try{ja(t,{recursive:!0})}catch(n){throw AggregateError([o,n],`Cannot record or remove the installation lock at ${t}.`)}throw Error(`Cannot record the installation lock owner at ${r}.`,{cause:o})}return t}function Df(e){let t=new Map;for(let r of e){let n=t.get(r.git.root)??M(r.git.root)?.commonDirectory;if(n!==r.git.commonDirectory)throw Error(`Git metadata changed after planning in ${r.git.root}. Replan the installation.`);if(t.set(r.git.root,n),!r.versioned&&Me(r.git,r.absolute))throw Error(`Git started tracking ${r.absolute} after planning. Replan before applying local mode.`)}}function Ff(e,t){let r=[t];for(let o of e.reverse())try{Xt({...o,before:o.after,after:o.before})}catch(n){r.push(Error(`Cannot restore ${go(o.base,o.path)} after the installation failed.`,{cause:n}))}if(r.length>1)throw AggregateError(r,"Installation stopped and some files could not be restored. Inspect the reported paths and replan.");throw t}function Lf(e){let{exclusions:t,files:r,checks:o}=e,n=[];for(let s of[...e.guards??[],...t,...r])ut(s);for(let s of e.boundaries??[])Se(s.absolute,s.gitRoot);Df(o);try{for(let s of t)Xt(s),n.push(s);for(let s of o)Yt(s,s.versioned);for(let s of r)Xt(s),n.push(s)}catch(s){Ff(n,Error("Could not apply the workspace installation. Inspect the cause and replan before retrying.",{cause:s}))}return n.length}function Na(e){let t=[];for(let r of e.reverse())try{ja(r,{recursive:!0})}catch(o){if(!(o instanceof Error)||!Ra(o))t.push(Error(`Cannot remove the installation lock at ${r}. Inspect it before retrying.`,{cause:o}))}return t}function La(e,t){let r=[],o;try{for(let s of[...new Set(e)].sort())r.push(jf(s));o=t()}catch(s){let i=Na(r);if(i.length)throw AggregateError([s,...i],"The installation failed and some locks could not be removed.");throw s}let n=Na(r);if(n.length)throw AggregateError(n,"The installation completed and some locks could not be removed.");return o}function Ma(e,t){return La([e],t)}function yo(e,t){let r=[e,...t.exclusions.map((o)=>o.base),...t.checks.map((o)=>o.git.commonDirectory)];return La(r,()=>Lf(t))}function xo(e){let t=Da.get(e);if(!t)throw Error("Apply requires a plan created by this process. Run the workspace planner again.");if(e.conflicts.length)throw Error(`Resolve the workspace conflicts before applying: ${e.conflicts.map((o)=>o.path).join(", ")}.`);return{changed:yo(e.root,t),receipt:e.receipt}}import{resolve as Mf}from"node:path";var Wa=X(["codex","claude","opencode"]),Ua=X(["plane","penpot"]),vo=w().regex(/^[a-f0-9]{64}$/),Ba=P({path:w().min(1),versioned:Fe(),identity:vo.optional()}),Ja=P({schema:H(1),version:w().min(1),hosts:_(Wa),workspaceVersioned:Fe(),repositories:_(Ba),services:_(Ua),installation:w().regex(/^[a-f0-9]{16}$/).optional(),files:_(P({path:w().min(1),hash:vo,versioned:Fe(),fragment:vo.optional()}))}),Va=P({root:w().min(1),action:X(["install","update","add-repo"]),version:w().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),contentDirectory:w(),hosts:_(Wa).min(1),workspaceVersioned:Fe(),repositories:_(Ba),services:_(Ua),repository:w().min(1).optional()}),F="llm/harness/workspace.json";var Wf=new Set([".agents/skills/apptoolkit/SKILL.md",".claude/skills/apptoolkit/SKILL.md",".opencode/commands/apptoolkit.md","AGENTS.md","CLAUDE.md",".claude/rules/apptoolkit.md"]);function wo(e,t){if(e.startsWith("llm/harness/")||e.startsWith("llm/author-style/")||Wf.has(e))return e!==F&&e!=="llm/harness/project.json";if(e==="llm/HARNESS.md"||e==="llm/README.md")return!0;return t.some((r)=>e===he(r.path))}function he(e){if(e===".")return"llm/harness-context.llm.md";return`${e}/llm/harness-context.llm.md`}function Y(e){let t=de(e),r=C(t,F);if(!r)return;try{let o=Ja.parse(JSON.parse(r.bytes.toString("utf8"))),n=new Set,s=new Set;for(let i of o.repositories){if(i.path!==".")oe(i.path);if(n.has(i.path))throw Error(`Repeated repository path ${i.path}.`);n.add(i.path)}for(let i of o.files){if(oe(i.path),!wo(i.path,o.repositories)||s.has(i.path))throw Error(`Unexpected managed file ${i.path}.`);s.add(i.path)}return o}catch(o){throw Error(`Cannot read the installation receipt at ${Mf(t,F)}. Restore a valid receipt before retrying.`,{cause:o})}}var ae=w().trim().min(1).max(120).regex(/^[\p{L}\p{N}][\p{L}\p{N} ./_:+-]*$/u),Ka=w().regex(/^[A-Z_][A-Z0-9_]*$/).max(120),We=w().min(1).max(512).refine((e)=>{if(/^[A-Za-z]:|[\\\u0000-\u001f\u007f]/u.test(e))return!1;return e.split("/").every((t)=>t!==""&&t!=="."&&t!==".."&&t!==".git")},"Use a workspace-relative path without traversal."),Ue=co([H("."),We]),Be=X(["plane","penpot"]),Uf=new Set(["localhost","127.0.0.1","[::1]"]),_o=vl().max(512).pipe(w().refine((e)=>{let t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:"&&Uf.has(t.hostname))&&!t.username&&!t.password&&!t.search&&!t.hash},"Use HTTPS or loopback HTTP without credentials, query, or fragment.")),Ha={baseUrl:_o,tokenEnv:Ka,snapshots:X(["off","versioned"])},Bf=ao("provider",[P({...Ha,provider:H("plane"),workspace:w().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,119}$/),projectId:so(),auth:X(["api-key","oauth"]).default("api-key")}),P({...Ha,provider:H("penpot"),fileId:so()})]),Jf=ao("mode",[P({mode:H("unlimited")}),P({mode:H("limited"),limits:_(P({category:ae,maximum:ga().positive(),unit:ae})).min(1).max(12)})]),Vf=P({category:ae,scope:ae,authority:ae,provider:ae,access:ao("method",[P({method:H("local"),path:We}),P({method:H("cli"),command:ae}),P({method:H("mcp"),server:ae}),P({method:H("api"),baseUrl:_o,tokenEnv:Ka.optional()}),P({method:H("web"),baseUrl:_o})])}),Hf=P({kind:ae,template:We.optional(),requiredSections:_(ae).max(30),checklist:_(w().trim().min(1).max(200)).max(30),prohibitedText:_(w().trim().min(1).max(120)).max(30)}),Kf=P({path:Ue,budget:Jf,rules:_(We).max(50),routes:_(Vf).max(50),documentation:_(Hf).max(50),services:_(Bf).max(2)}).superRefine((e,t)=>{let r=new Set;for(let[n,s]of e.routes.entries()){let i=`${s.category.toLowerCase()}
62
+ ${s.scope.toLowerCase()}`;if(r.has(i))t.addIssue({code:"custom",path:["routes",n],message:"Choose one authority for this category and scope."});r.add(i)}let o=new Set;for(let[n,s]of e.services.entries()){if(o.has(s.provider))t.addIssue({code:"custom",path:["services",n],message:"Configure each built-in service once per project."});o.add(s.provider)}}),Pe=P({schema:H(1),projects:_(Kf).min(1).max(100)}).superRefine((e,t)=>{let r=new Set;for(let[o,n]of e.projects.entries()){if(r.has(n.path))t.addIssue({code:"custom",path:["projects",o,"path"],message:"Each project must appear once."});r.add(n.path)}});var ko="llm/harness/project.json",od=1048576;function me(e){try{return qf(e)}catch(t){if(t instanceof Error&&"code"in t&&t.code==="ENOENT")return;throw Error(`Inspect ${e}.`,{cause:t})}}function $o(e){let t=me(e);if(!t?.isFile()||t.size>od)throw Error(`Expected a regular JSON file of at most 1 MiB at ${e}.`);try{return JSON.parse(Xf(e,"utf8"))}catch(r){throw Error(`Read JSON configuration at ${e}.`,{cause:r})}}function Xa(e){let t=e;for(let r of["llm","harness"])if(t=Je(t,r),!me(t)?.isDirectory())throw Error(`Expected an installed, nonsymlink workspace directory at ${t}.`);return t}function lt(e){let t=Ga(qa(e));Xa(t);let r=Y(t);if(!r)throw Error("Install the harness in the selected workspace before configuring it.");return{root:t,receipt:r}}function Ya(e,t){if(Xa(e),!me(t))return;let r=Pe.safeParse($o(t));if(!r.success){let o=r.error.issues.map((n)=>`${n.path.join(".")||"settings"} ${n.message}`);throw Error(`Invalid project settings in ${t}. ${o.join(" ")}`)}return r.data}function Ee(e){return Ya(e,Je(e,ko))}function nd(e,t,r){if(r)return r;let o=Je(e,t),n=[];if(me(o)?.isDirectory()&&Ga(o)===o){for(let s of["AGENTS.md","CLAUDE.md","CONTRIBUTING.md"])if(me(Je(o,s))?.isFile())n.push(s)}return{path:t,budget:null,rules:n,routes:[],documentation:[],services:[]}}function zo(e){let{root:t,receipt:r}=lt(e),o=Ee(t);return{schema:1,projects:[...new Set([".",...r.repositories.map((s)=>s.path)])].map((s)=>{let i=o?.projects.find((c)=>c.path===s);return nd(t,s,i)})}}function bo(e){return`${JSON.stringify(e,null,2)}
63
+ `}function sd(e,t){let r=td(e),o=Je(r,`.project.${Gf()}.json`);try{ed(o,bo(t),{flag:"wx",mode:384}),Yf(o,e)}catch(n){try{Qf(o,{force:!0})}catch(s){throw AggregateError([n,s],`Write project settings and clean the draft at ${e}.`)}throw Error(`Write project settings at ${e}.`,{cause:n})}}async function So(e){let{root:t}=lt(e.root),r=Ya(t,qa(e.configPath));if(!r)throw Error("Provide the approved project settings JSON file.");return Ma(t,()=>{let{receipt:o}=lt(t),n=new Set([".",...o.repositories.map((u)=>u.path)]);for(let u of r.projects){if(!n.has(u.path))throw Error(`Register ${u.path} before initializing its settings.`);for(let p of u.services){if(!o.services.includes(p.provider))throw Error(`Select ${p.provider} during workspace installation before connecting it.`);if(p.snapshots==="versioned"&&!o.workspaceVersioned)throw Error("Versioned service snapshots require a versioned workspace harness.")}}let s=Je(t,ko);if(!o.workspaceVersioned){let u=M(t);if(u)Yt({git:u,path:rd(u.root,s)},!1)}let i=Ee(t),c=new Map(i?.projects.map((u)=>[u.path,u]));for(let u of r.projects)c.set(u.path,u);let a=Pe.parse({schema:1,projects:[...c.values()]});if(i&&bo(i)===bo(a))return{path:s,changed:!1,projects:a.projects.length};return sd(s,a),{path:s,changed:!0,projects:a.projects.length}})}var id=P({root:w().min(1),project:Ue,service:Be,verifyHealth:Fe().optional(),verifyRead:Fe()}),cd=at({results:_(at({id:so()})).max(1)}),ad=at({name:w().min(1)}),ud=131072;class _e extends Error{}function Eo(e){let{root:t,receipt:r}=lt(e.root);if(!r.services.includes(e.service))throw Error(`${e.service} is not selected in the installed workspace.`);if(e.project!=="."&&!r.repositories.some((s)=>s.path===e.project))throw Error(`Register ${e.project} before using its service connections.`);let n=Ee(t)?.projects.find((s)=>s.path===e.project)?.services.find((s)=>s.provider===e.service);if(!n)throw Error(`Initialize the ${e.service} connection for ${e.project} first.`);return{root:t,receipt:r,connection:n}}function Po(e,t){let r=new URL(e);if(!r.pathname.endsWith("/"))r.pathname+="/";return new URL(t,r)}function pd(e){if(e.provider==="plane"){let r=`api/v1/workspaces/${e.workspace}/projects/${e.projectId}/work-items/`,o=Po(e.baseUrl,r);return o.searchParams.set("per_page","1"),o.searchParams.set("fields","id"),o}let t=Po(e.baseUrl,"api/rpc/command/get-file-summary");return t.searchParams.set("id",e.fileId),t}function ld(e,t){let r=new Headers({Accept:"application/json"});if(e.provider==="penpot")r.set("Authorization",`Token ${t}`);else if(e.auth==="oauth")r.set("Authorization",`Bearer ${t}`);else r.set("X-API-Key",t);return r}async function fd(e){if(!e.headers.get("content-type")?.toLowerCase().startsWith("application/json"))throw await e.body?.cancel(),new _e("Expected an application/json response from the service.");let r=e.body?.getReader();if(!r)throw new _e("The service response has no body.");let o=[],n=0;try{for(;;){let s=await r.read();if(s.done)return Buffer.concat(o,n).toString("utf8");if(n+=s.value.byteLength,n>ud)throw await r.cancel(),new _e("The service response exceeded the 128 KiB verification limit.");o.push(s.value)}}finally{r.releaseLock()}}async function dd(e,t){let r=await t(Po(e.baseUrl,"./"),{method:"HEAD",redirect:"manual",signal:AbortSignal.timeout(1e4)});return await r.body?.cancel(),r.status}async function hd(e,t,r){let o=await r(pd(e),{method:"GET",headers:ld(e,t),redirect:"error",signal:AbortSignal.timeout(1e4)});if(!o.ok)throw await o.body?.cancel(),new _e(`The selected resource returned HTTP ${o.status}. Confirm the target and its read permission.`);let n=await fd(o),s=e.provider==="plane"?cd:ad,i=!1;try{i=s.safeParse(JSON.parse(n)).success}catch(c){throw new _e("The service returned invalid JSON.",{cause:c})}if(!i)throw new _e("The response does not match the expected resource read.");return o.status}async function Zo(e,t={}){let r=id.parse(e),{connection:o}=Eo(r),s=(t.environment??process.env)[o.tokenEnv],i=typeof s==="string"&&/^[\x21-\x7e]+$/.test(s),c={provider:o.provider,project:r.project,baseUrl:o.baseUrl,credentialEnv:o.tokenEnv,credentialAvailable:i,snapshots:o.snapshots,connectivity:"unchecked",read:"unchecked"},a=t.fetch??fetch;if(r.verifyRead){if(!i)throw Error(`Provide ${o.tokenEnv} in the process environment before verifying access.`);try{let u=await hd(o,s,a);return{...c,connectivity:"reachable",read:"verified",httpStatus:u}}catch(u){let p=u instanceof _e?u.message:"Check the configured host and retry.";throw Error(`Verify ${o.provider} read for ${r.project}. ${p}`,{cause:u})}}if(r.verifyHealth)try{let u=await dd(o,a);return{...c,connectivity:u>=500?"service-error":"reachable",httpStatus:u}}catch(u){throw Error(`Check ${o.provider} connectivity for ${r.project}.`,{cause:u})}return c}import{createHash as md}from"node:crypto";import{constants as Qa,createReadStream as gd,openSync as yd}from"node:fs";import{join as xd,relative as eu,resolve as vd}from"node:path";var tu=We.refine((e)=>e.startsWith("harness-snapshots/"),{message:"Keep native service exports in the workspace harness-snapshots directory."}),wd=w().regex(/^[a-f0-9]{64}$/),_d=P({path:tu,bytes:ga().int().positive(),sha256:wd}),bd=P({root:w().min(1),project:Ue,service:Be}),ru=P({schema:H(1),project:Ue,service:Be,files:_(_d).min(1).max(30)}).refine((e)=>new Set(e.files.map((t)=>t.path)).size===e.files.length,"Duplicate snapshot paths.");function ou(e,t){let r=vd(e,t),o=tu.parse(eu(e,r)),n=e,s=o.split("/");for(let[i,c]of s.entries()){n=xd(n,c);let a=me(n);if(!(i===s.length-1?a?.isFile():a?.isDirectory()))throw Error(`Expected a regular nonsymlink snapshot path at ${n}.`)}return r}async function nu(e,t){let r=ou(e,t),o=me(r);if(!o?.isFile()||o.size===0)throw Error(`Expected a nonempty snapshot file at ${r}.`);let n=md("sha256");try{let i=yd(r,Qa.O_RDONLY|Qa.O_NOFOLLOW),c=gd(r,{fd:i});for await(let a of c)n.update(a)}catch(i){throw Error(`Read snapshot bytes at ${r}.`,{cause:i})}let s=me(r);if(!s||o.dev!==s.dev||o.ino!==s.ino||o.mtimeMs!==s.mtimeMs||o.size!==s.size)throw Error(`Snapshot changed while reading ${r}. Retry with a stable export.`);return{path:eu(e,r),bytes:o.size,sha256:n.digest("hex")}}function su(e){let{root:t,receipt:r,connection:o}=Eo(bd.parse(e));if(!r.workspaceVersioned||o.snapshots!=="versioned")throw Error("Enable versioned snapshots for this project and provider before working with a snapshot.");return t}async function Oo(e){let t=su({root:e.root,project:e.project,service:e.service}),r=_(w().min(1)).min(1).max(30).parse(e.paths),o=[];for(let n of r)o.push(await nu(t,n));return ru.parse({schema:1,project:e.project,service:e.service,files:o})}async function Ro(e){let t=su({root:e.root,project:e.project,service:e.service}),r=ou(t,e.manifestPath),o=ru.parse($o(r));if(o.project!==e.project||o.service!==e.service)throw Error("The snapshot manifest belongs to a different project or service.");for(let n of o.files){let s=await nu(t,n.path);if(s.bytes!==n.bytes||s.sha256!==n.sha256)throw Error(`Snapshot integrity check failed for ${n.path}.`)}return{manifestPath:r,project:o.project,service:o.service,files:o.files.length}}import{closeSync as iu,constants as Co,fstatSync as cu,lstatSync as au,openSync as kd,readSync as $d,realpathSync as zd}from"node:fs";import{isAbsolute as pu,join as Sd}from"node:path";var Pd=262144,Ed=new Set([".aws",".git",".gnupg",".npm",".ssh","credentials","node_modules","passwords","private","processing","raw","secret","secrets"]);function lu(e){let t=e.toLowerCase(),r=t.replace(/(?:\.llm)?\.md$/,"");return t.startsWith(".env")||Ed.has(r)}function Zd(e){if(pu(e)||/[\\:\x00-\x1f\x7f]/.test(e))throw Error("Provide a relative path inside the project root.");let t=e.split("/");for(let r of t){if(r===""||r==="."||r==="..")throw Error("Paths must use explicit project-relative segments.");if(lu(r))throw Error(`The path crosses a protected location at "${r}".`)}return t}function uu(e,t){if(!pu(e))throw Error("Provide an absolute project root.");if(!au(e).isDirectory())throw Error("The project root must be a directory.");let r=zd(e);if(r.split("/").filter(Boolean).some((s,i)=>(i!==0||s!=="private")&&lu(s)))throw Error("The project root crosses a protected location.");let n;for(let[s,i]of t.entries()){if(r=Sd(r,i),n=au(r),n.isSymbolicLink())throw Error(`Symbolic links are not allowed in the project path at "${i}".`);if(s<t.length-1&&!n.isDirectory())throw Error(`Expected a directory at "${i}".`)}if(!n?.isFile())throw Error("The project path must resolve to a regular file.");return{path:r,info:n}}function Od(e,t,r,o){let n=cu(e);if(!n.isFile()||n.ino!==t.ino||n.dev!==t.dev)throw Error("The file changed while opening. Retry after checking its path.");if(n.size>r)throw Error(`${o} source exceeds ${r} bytes. Use a narrower input.`);let s=Buffer.alloc(n.size+1),i=0;while(i<s.length){let a=$d(e,s,i,s.length-i,i);if(a===0)break;i+=a}if(i>r)throw Error(`${o} source exceeds ${r} bytes. Use a narrower input.`);let c=cu(e);if(c.size!==i||n.size!==c.size||n.mtimeMs!==c.mtimeMs||n.ctimeMs!==c.ctimeMs)throw Error("The source changed during the read. Retry with a stable file.");return s.subarray(0,i)}function Rd(e,t,r,o){let n;try{n=Od(e,t,r,o)}catch(s){try{iu(e)}catch(i){throw AggregateError([s,i],"Reading and closing the file both failed.")}throw s}return iu(e),n}function er(e,t,r,o){try{let n=Zd(t),{path:s,info:i}=uu(e,n),c=kd(s,Co.O_RDONLY|Co.O_NOFOLLOW|Co.O_NONBLOCK),a=Rd(c,i,r,o),u=uu(e,n);if(u.path!==s||u.info.ino!==i.ino||u.info.dev!==i.dev)throw Error("The file path changed during the read. Retry after verifying the current path.");return new TextDecoder("utf-8",{fatal:!0}).decode(a)}catch(n){let s=n instanceof Error?n.message:String(n);throw Error(`Unable to read ${o} "${t}". ${s}`,{cause:n})}}function ft(e,t){if(!t.toLowerCase().endsWith(".md"))throw Error("Provide a relative Markdown path inside the project root.");return er(e,t,Pd,"Markdown context")}function fu(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}function du(e,t,r){let o=e.toLowerCase().replace(/[^\p{L}\p{M}\p{N}_\s-]/gu,"").trim().replace(/\s+/g,"-");return{title:e,level:t,line:r,locator:`line:${r}`,anchor:`#${o}`}}function Cd(e){let t=/^ {0,3}(`{3,}|~{3,})/.exec(e)?.[1];if(t)return{marker:t.charAt(0),length:t.length};return}function Id(e,t){let r=/^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(e)?.[1];return r!==void 0&&r.startsWith(t.marker)&&r.length>=t.length}function Ad(e,t){let r=/^ {0,3}(#{1,6})[ \t]+(.*)$/.exec(e),o=r?.[1],n=r?.[2];if(o&&n){let s=n.replace(/(?:^|[ \t]+)#+[ \t]*$/,"").trim();if(s)return du(s,o.length,t)}return}function Td(e){if(!e.trim()||/^(?: {4}|\t)/.test(e))return!1;return!/^ {0,3}(?:[>#<]|[-+*][ \t]|\d+[.)][ \t]|\[[^\]]+\]:|(?:[*_-][ \t]*){3,})/.test(e)}function hu(e){let t=[],r,o,n=!1,s=-1;if(e[0]?.trim()==="---")s=e.findIndex((i,c)=>c>0&&/^(---|\.\.\.)$/.test(i.trim()));for(let[i,c]of e.entries()){if(i<=s)continue;let a=c.replace(/\r?\n$/,""),u=i+1;if(r){if(Id(a,r))r=void 0;continue}if(n||a.trimStart().startsWith("<!--")){n=!a.includes("-->"),o=void 0;continue}if(r=Cd(a),r){o=void 0;continue}let p=Ad(a,u);if(p){t.push(p),o=void 0;continue}let l=/^ {0,3}(=+|-+)[ \t]*$/.exec(a)?.[1];if(l&&o){let f=o.lines.join(" "),d=l.startsWith("=")?1:2;t.push(du(f,d,o.line)),o=void 0;continue}if(!Td(a)){o=void 0;continue}if(!o)o={line:u,lines:[]};o.lines.push(a.trim())}return t}var Io=w().min(1).refine((e)=>!/[\x00-\x1f\x7f]/.test(e),"Control characters are not allowed."),Nd=P({root:Io.max(4096),file:Io.max(4096),section:Io.max(512).optional()}),mu=128,gu=16384;function jd(e,t){let r=e.filter((n)=>{if(/^line:[1-9][0-9]*$/.test(t))return n.locator===t;if(t.startsWith("#"))return n.anchor===t;return n.title===t}),[o]=r;if(!o)throw Error(`No heading matches "${t}". List the heading index and use an exact locator.`);if(r.length>1){let n=r.slice(0,8).map((i)=>i.locator),s=r.length>n.length?", or another locator from the index":"";throw Error(`Heading "${t}" is ambiguous. Use one of ${n.join(", ")}${s}.`)}return o}function yu(e,t){if(Buffer.byteLength(e)>gu)throw Error(`Context output exceeds ${gu} bytes. ${t}`)}function xu(e){let t=Nd.parse(e),r=fu(ft(t.root,t.file)),o=hu(r);if(t.section===void 0){if(o.length>mu)throw Error(`Heading index exceeds ${mu} entries. Request a known section or use a narrower map.`);let u={kind:"index",file:t.file,headings:o};return yu(JSON.stringify(u),"Request a known section or use a narrower map."),u}let n=jd(o,t.section),s=o.find((u)=>u.line>n.line&&u.level<=n.level),i=s?s.line-1:r.length,c=r.slice(n.line-1,i).join(""),a={kind:"section",file:t.file,heading:n,startLine:n.line,endLine:i,text:c};return yu(JSON.stringify(a),"Choose a smaller child section or a narrower map."),a}import{realpathSync as Jd}from"node:fs";import{isAbsolute as No,normalize as Vd,relative as Hd,resolve as Kd}from"node:path";var wu=X(["lines","functions","branches"]),Dd=X(["LF","LH","FNF","FNH","BRF","BRH"]),Fd={lines:{found:"LF",hit:"LH"},functions:{found:"FNF",hit:"FNH"},branches:{found:"BRF",hit:"BRH"}};function _u(e){return{source:e,summaries:new Map,lines:new Map,branches:new Map,functionNames:new Set,functionHits:new Map,groupIds:new Set,aliasHits:new Map,versionSeen:!1}}function N(e,t){let r=Number(e);if(!/^\d+$/.test(e)||!Number.isSafeInteger(r)||r<t)throw Error("Expected an integer within the supported range.");return r}function dt(e,t,r){if(e.has(t))throw Error("Duplicate coverage entry.");e.set(t,r)}function vu(e,t){if(e.has(t))throw Error("Duplicate coverage identity.");e.add(t)}function Ld(e,t){let[r,o,,n,s]=t.split(",");if(!r||!o||s!==void 0)throw Error("Expected a line number and execution count.");let i=N(r,1);if(n!==void 0)N(n,i);dt(e.lines,String(i),N(o,0)>0)}function Md(e,t){let r=/^([^,]+),([ef]?u?\d+(?:\^\d+)?),(.+),([^,]+)$/.exec(t),o=r?.[1],n=r?.[2],s=r?.[3],i=r?.[4];if(!o||!n||!s||!i)throw Error("Expected a branch line, block, identity and hit count.");let[,c,a]=/^[ef]?u?(\d+)(?:\^(\d+))?$/.exec(n)??[];if(!c)throw Error("Expected a numeric branch block.");let u=JSON.stringify([N(o,1),N(c,0),a===void 0?null:N(a,0),/^\d+$/.test(s)?N(s,0):s]);dt(e.branches,u,i!=="-"&&N(i,0)>0)}function Wd(e,t,r){let o=t==="FN"?/^(\d+),(?:(\d+),)?(.+)$/:/^(\d+),(\d+)(?:,(\d+))?$/,[,n,s,i]=o.exec(r)??[];if(n===void 0)throw Error("Malformed function definition.");if(t==="FN"&&i){let c=N(n,1);if(s)N(s,c);vu(e.functionNames,i);return}if(t==="FNL"&&s){let c=N(s,1);if(i)N(i,c);vu(e.groupIds,String(N(n,0)));return}throw Error("Malformed function definition.")}function Ud(e,t,r){if(t==="FNDA"){let[,a,u]=/^(\d+),(.+)$/.exec(r)??[];if(!a||!u)throw Error("Expected a function hit count and name.");dt(e.functionHits,u,N(a,0)>0);return}let[,o,n,s]=/^(\d+),(\d+),(.+)$/.exec(r)??[];if(!o||!n||!s)throw Error("Expected an alias group, hit count and name.");let i=String(N(o,0)),c=e.aliasHits.get(i)??new Map;dt(c,s,N(n,0)>0),e.aliasHits.set(i,c)}function bu(e,t,r){let o=Dd.safeParse(t);if(o.success){dt(e.summaries,o.data,N(r,0));return}switch(t){case"VER":if(e.versionSeen||!r)throw Error("Expected one source version per record.");e.versionSeen=!0;return;case"DA":return Ld(e,r);case"BRDA":return Md(e,r);case"FN":case"FNL":return Wd(e,t,r);case"FNDA":case"FNA":return Ud(e,t,r);default:throw Error("Unsupported LCOV field. Export a line, function and branch report.")}}function Ao(e){let t=0;for(let r of e.values())if(r)t+=1;return{found:e.size,hit:t}}function Bd(e){let t=e.functionNames.size>0||e.functionHits.size>0,r=e.groupIds.size>0||e.aliasHits.size>0;if(t&&r)throw Error("Function records mix classic names and alias groups.");if(r){let o=0;if(e.groupIds.size!==e.aliasHits.size)throw Error("Missing function group or alias records.");for(let n of e.groupIds){let s=e.aliasHits.get(n);if(!s?.size)throw Error("Function group is missing execution records.");if(Array.from(s.values()).some(Boolean))o+=1}return{found:e.groupIds.size,hit:o}}if(e.functionNames.size!==e.functionHits.size)throw Error("Missing function names or execution records.");for(let o of e.functionNames)if(!e.functionHits.has(o))throw Error("A function definition has no matching execution record.");return Ao(e.functionHits)}function ku(e,t){let r=Fd[t],o=e.summaries.get(r.found),n=e.summaries.get(r.hit);if(o===void 0||n===void 0)throw Error(`Missing ${r.found} or ${r.hit} summary.`);let s;switch(t){case"lines":s=Ao(e.lines);break;case"functions":s=Bd(e);break;case"branches":s=Ao(e.branches);break}if(s.found!==o||s.hit!==n)throw Error(`Summary ${n}/${o} differs from measured entries ${s.hit}/${s.found}.`);if(n!==o)throw Error(`Only ${n}/${o} were covered. The requirement is 100 percent.`);return s}var tr=w().min(1).max(4096).refine((e)=>!/[\x00-\x1f\x7f]/.test(e)),Gd=P({root:tr,file:tr,config:tr}),qd=P({files:_(tr).min(1).max(1e4),metrics:_(wu).min(1).max(3)});function To(e){if(No(e)||/[\\:\x00-\x1f\x7f]/.test(e)||e.split("/").some((t)=>!t||t==="."||t===".."))throw Error(`Use a project-relative source path in the coverage configuration. Received "${e}".`);return e}function $u(e,t){let r=Hd(e,t);if(!r||r===".."||r.startsWith("../")||No(r))return;return r}function Xd(e,t,r){if(!e||/[\\:\x00-\x1f\x7f]/.test(e))throw Error("Expected a valid source path in the LCOV record.");if(No(e)){let o=$u(t,e)??$u(r,e);if(o)return To(o);throw Error("An LCOV source is outside the project root.")}return To(Vd(e))}function Yd(e,t){for(let[r,o]of t)try{let n=ku(e,r);o.found+=n.found,o.hit+=n.hit}catch(n){let s=n instanceof Error?n.message:String(n);throw Error(`${e.source} ${r}. ${s}`,{cause:n})}}function Qd(e,t,r,o){let n=Jd(t),s=new Set,i=new Set,c,a=!1;for(let[p,l]of e.split(/\r?\n/).entries()){if(!l.trim()||l.startsWith("#"))continue;try{if(/[\x00-\x08\x0b-\x1f\x7f]/.test(l))throw Error("Control characters are not allowed in coverage records.");if(l.startsWith("TN:")&&!c&&!a)a=!0;else if((l.startsWith("SF:")||l.startsWith("KF:"))&&!c){let f=l.slice(3),[,d,m]=/^(\d+),(.*)$/.exec(f)??[],g=Xd(m??f,t,n);if(d!==void 0){let y=Number(d);if(!Number.isSafeInteger(y)||i.has(y))throw Error("Expected a distinct safe integer source index.");i.add(y)}if(s.has(g))throw Error(`Duplicate LCOV source "${g}".`);if(!r.has(g))throw Error(`Unexpected LCOV source "${g}".`);c=_u(g),a=!1}else if(l==="end_of_record"&&c)Yd(c,o),s.add(c.source),c=void 0;else if(c){let f=l.indexOf(":");if(f<1)throw Error("Malformed LCOV field.");bu(c,l.slice(0,f),l.slice(f+1))}else throw Error("Expected an LCOV source record.")}catch(f){let d=f instanceof Error?f.message:String(f);throw Error(`LCOV line ${p+1}. ${d}`,{cause:f})}}if(c||a)throw Error("The final LCOV record is incomplete.");let u=Array.from(r).filter((p)=>!s.has(p));if(u.length)throw Error(`LCOV is missing ${u.length} expected source files. First missing path is "${u[0]}".`)}function zu(e){let t=Gd.parse(e),r=er(t.root,t.config,262144,"coverage configuration"),o;try{o=qd.parse(JSON.parse(r))}catch(a){throw Error(`Invalid coverage configuration "${t.config}". Provide JSON arrays for files and metrics.`,{cause:a})}let n=new Set(o.files.map(To)),s=new Map;for(let a of o.metrics)s.set(a,{found:0,hit:0});if(n.size!==o.files.length||s.size!==o.metrics.length)throw Error("Coverage configuration contains duplicate files or metrics.");let i=er(t.root,t.file,16777216,"LCOV report");Qd(i,Kd(t.root),n,s);let c=Array.from(s,([a,u])=>{if(u.found===0)throw Error(`No measurable ${a} were found for the selected scope.`);return{metric:a,...u,percent:100}});return{file:t.file,config:t.config,sources:n.size,metrics:c}}import{lstatSync as Uu}from"node:fs";import{relative as Wu,resolve as be}from"node:path";import{lstatSync as eh,readdirSync as Pu}from"node:fs";import{basename as Su,resolve as ht}from"node:path";var th=at({name:w().optional(),workspaces:co([_(w()),at({packages:_(w())})]).optional()}),rh=new Set(["package.json","pnpm-workspace.yaml","Cargo.toml","go.mod","pyproject.toml","Gemfile","pom.xml","composer.json"]),Eu=new Set([".git",".DS_Store",".agents",".claude",".opencode","llm","node_modules","dist","vendor"]);function oh(e){let t=C(e,"package.json");if(!t)return;try{return th.parse(JSON.parse(t.bytes.toString("utf8")))}catch(r){throw Error(`Cannot read ${ht(e,"package.json")}. Correct the manifest and retry.`,{cause:r})}}function Ve(e,t){if(t===".")return e;oe(t);let r=de(ht(e,t));if(!ho(e,r)||r!==ht(e,t))throw Error(`Choose a real directory inside ${e}. The repository path resolves through a symbolic link: ${t}.`);if(M(r)?.root!==r)throw Error(`Choose the Git repository root at ${r} before registering it.`);return r}function nh(e){let t=Pu(e,{withFileTypes:!0});if(t.length>2048)throw Error(`Workspace discovery is limited to 2048 entries at ${e}. Choose a narrower directory.`);let r=[];for(let o of t.sort((n,s)=>n.name.localeCompare(s.name,"en"))){if(!o.isDirectory()||o.name.startsWith(".")||Eu.has(o.name))continue;let n=ht(e,o.name);if(!eh(ht(n,".git"),{throwIfNoEntry:!1}))continue;if(M(n)?.root!==n)throw Error(`The Git metadata in ${n} does not identify that checkout as a repository root.`);oe(o.name),r.push({path:o.name,name:o.name,gitRoot:n})}return r}function Ze(e){let t=de(e),r=M(t),o=nh(t),n=new Set(Pu(t)),s=oh(t),i=Boolean(s?.workspaces||n.has("pnpm-workspace.yaml")||n.has("lerna.json")),c=[...rh].some((l)=>n.has(l)),a=r?{gitRoot:r.root}:{};if(o.length&&!i){let l=[...o];if(c)l.unshift({path:".",name:s?.name??Su(t),...a});return{root:t,kind:"workspace",monorepo:i,repositories:l,...a}}let u=[...n].every((l)=>Eu.has(l)),p={path:".",name:s?.name??Su(t),...a};return{root:t,kind:u?"blank":"existing",monorepo:i,repositories:[p],...a}}import{lstatSync as Ru}from"node:fs";import{resolve as mt}from"node:path";function sh(e,t,r,o=!1){let n=`# appToolkit harness ${t} begin`,s=`# appToolkit harness ${t} end`,i=e.includes(`\r
64
64
  `)?`\r
65
65
  `:`
66
- `,c=e.split(s),a=c.indexOf(n),u=c.indexOf(i);if(a===-1!==(u===-1)||a!==-1&&u<=a||c.lastIndexOf(n)!==a||c.lastIndexOf(i)!==u)throw Error(`The existing appToolkit local exclusion block ${t} is malformed. Repair it before retrying.`);let p=new Set(r);if(o&&a!==-1)for(let d of c.slice(a+1,u)){if(!d.startsWith("/"))throw Error(`The existing appToolkit local exclusion block ${t} contains an unsupported pattern.`);p.add(d)}let l=p.size?[n,...[...p].sort(),i]:[];if(a!==-1)return c.splice(a,u-a+1,...l),c.join(s);if(!l.length)return e;return`${e&&!e.endsWith(s)?`${e}${s}`:e}${l.join(s)}${s}`}function Io(e,t,r,o=!1){let n=R(e.commonDirectory,e.exclude),i=n?.bytes.toString("utf8")??"";if(n&&!Buffer.from(i).equals(n.bytes))throw Error(`Cannot update the non-UTF-8 local exclusions at ${ht(e.commonDirectory,e.exclude)}.`);let s=th(i,t,r,o),c=s||n?U(s,n?.mode):null;if(ce(n,c))return;return{base:e.commonDirectory,path:e.exclude,before:n,after:c}}function Su(e,t){let r=new Map,o=L(e);if(o)r.set(".",o);for(let n of t){if(n.path===".")continue;let i=ht(e,n.path);if(!Eu(i,{throwIfNoEntry:!1})?.isDirectory())continue;let c=L(i);if(c?.root===i)r.set(n.path,c)}return r}function Pu(e,t){let r=[...t.keys()].filter((n)=>n!=="."&&e.startsWith(`${n}/`));r.sort((n,i)=>i.length-n.length);let o=r[0]??".";return t.get(o)}function Zu(e,t,r,o,n){let i=Su(e,t.repositories),s=new Map,c=[],a=[];if(r){let d=Su(e,r.repositories);for(let g of d.values())s.set(g.commonDirectory,{scope:g,patterns:new Set});for(let g of n){let m=ht(e,g),y=Pu(g,d);ze(m,y?.root),a.push(y?{absolute:m,gitRoot:y.root}:{absolute:m})}}let u=[...t.files,{path:"llm/harness/workspace.json",versioned:t.workspaceVersioned},{path:"llm/harness/project.json",versioned:t.workspaceVersioned}],p=new Set(t.repositories.filter((d)=>!Eu(ht(e,d.path),{throwIfNoEntry:!1})).map((d)=>Se(d.path)));for(let d of u){if(p.has(d.path))continue;let g=Pu(d.path,i),m=ht(e,d.path);if(ze(m,g?.root),a.push(g?{absolute:m,gitRoot:g.root}:{absolute:m}),!g)continue;let y=ve(g.root,m);if(c.push({git:g,path:y,absolute:m,versioned:d.versioned}),d.versioned)continue;if(Le(g,m)){o.push({path:d.path,reason:"Git already tracks this file. Choose versioned mode or separately remove it from the index before retrying."});continue}let v=s.get(g.commonDirectory)??{scope:g,patterns:new Set};v.patterns.add(qt(y)),s.set(g.commonDirectory,v)}let l=[],f=t.installation??M(e).slice(0,16);for(let{scope:d,patterns:g}of s.values()){let m=Io(d,f,g);if(m)l.push(m)}return{operations:l,checks:c,boundaries:a}}import{lstatSync as rh,readdirSync as oh}from"node:fs";import{resolve as Ou}from"node:path";var Cu=4096,nh=67108864,ih=new Set([".git","node_modules","raw","processing",".npmrc"]);function Ru(e){if(!e)throw Error("The release content directory is required for install and update.");let t=de(e),r=new Map,o=["."],n=0;while(o.length){let i=o.pop();if(!i)break;let s=oh(Ou(t,i),{withFileTypes:!0});for(let c of s.sort((a,u)=>a.name.localeCompare(u.name,"en"))){let a=i==="."?c.name:`${i}/${c.name}`;if(oe(a),ih.has(c.name)||/^\.env(?:$|\.(?!example$))/u.test(c.name))throw Error(`The release payload includes an unsupported private path: ${a}.`);if(c.isDirectory()&&!rh(Ou(t,a)).isSymbolicLink()){if(o.length+r.size>=Cu||a.split("/").length>12)throw Error(`Release content exceeds the directory limits at ${a}.`);o.push(a);continue}let u=`llm/${a}`;if(!c.isFile()||!go(u,[]))throw Error(`The release payload includes an unsupported file: ${a}.`);let p=R(t,a);if(!p)throw Error(`The release payload changed while reading ${a}.`);if(n+=p.bytes.length,r.size>=Cu||n>nh)throw Error(`The release payload exceeds the installation limits at ${a}.`);r.set(u,p)}}if(!r.has("llm/HARNESS.md"))throw Error("The release payload is missing the harness index HARNESS.md.");return r}var Qt="llm/harness/project.json";function Iu(e,t,r,o){let n=t.repositories.find((c)=>!r.repositories.some((a)=>a.path===c.path));if(!n)return;let i=r.repositories.find((c)=>c.identity&&c.identity===n.identity);if(!i)return;let s=R(e,Qt);if(!s)return;try{let c=Pe.parse(JSON.parse(s.bytes.toString("utf8")));if(!c.projects.some((p)=>p.path===n.path))return;if(c.projects.some((p)=>p.path===i.path)){o.push({path:Qt,reason:"Both the old and new checkout paths already have project settings. Reconcile them before registering the move."});return}let a=c.projects.map((p)=>{if(p.path===n.path)return{...p,path:i.path};return p}),u=U(`${JSON.stringify(Pe.parse({...c,projects:a}),null,2)}
67
- `,s.mode);return{base:e,path:Qt,before:s,after:u}}catch(c){throw Error(`Cannot reassign the project settings in ${Qt}. Restore a valid settings file before retrying.`,{cause:c})}}import{lstatSync as sh}from"node:fs";import{resolve as ch}from"node:path";var Ao="<!-- apptoolkit-harness:begin -->",er="<!-- apptoolkit-harness:end -->";function Nu(e){return["AGENTS.md","CLAUDE.md",".claude/rules/apptoolkit.md"].includes(e)}function ah(e,t){let r=e.indexOf(Ao),o=e.indexOf(er);if(r===-1&&o===-1)return;if(r<0||o<=r||e.lastIndexOf(Ao)!==r||e.lastIndexOf(er)!==o)throw Error(`The AppToolkit router block in ${t} is malformed. Review its markers before retrying.`);let n=o+er.length;return{prefix:e.slice(0,r),old:e.slice(r,n),suffix:e.slice(n)}}function Au(e,t,r,o,n,i,s){let c;try{c=R(e,t)}catch(m){if(!(m instanceof Vt))throw m;s.push(`Preserved the existing native instructions path ${t}. Use the installed apptoolkit command to open the harness explicitly.`);return}let a=c?.bytes.toString("utf8")??"",u=n?.files.find((m)=>m.path===t)?.fragment,p=a.includes(`\r
66
+ `,c=e.split(i),a=c.indexOf(n),u=c.indexOf(s);if(a===-1!==(u===-1)||a!==-1&&u<=a||c.lastIndexOf(n)!==a||c.lastIndexOf(s)!==u)throw Error(`The existing appToolkit local exclusion block ${t} is malformed. Repair it before retrying.`);let p=new Set(r);if(o&&a!==-1)for(let d of c.slice(a+1,u)){if(!d.startsWith("/"))throw Error(`The existing appToolkit local exclusion block ${t} contains an unsupported pattern.`);p.add(d)}let l=p.size?[n,...[...p].sort(),s]:[];if(a!==-1)return c.splice(a,u-a+1,...l),c.join(i);if(!l.length)return e;return`${e&&!e.endsWith(i)?`${e}${i}`:e}${l.join(i)}${i}`}function jo(e,t,r,o=!1){let n=C(e.commonDirectory,e.exclude),s=n?.bytes.toString("utf8")??"";if(n&&!Buffer.from(s).equals(n.bytes))throw Error(`Cannot update the non-UTF-8 local exclusions at ${mt(e.commonDirectory,e.exclude)}.`);let i=sh(s,t,r,o),c=i||n?U(i,n?.mode):null;if(ce(n,c))return;return{base:e.commonDirectory,path:e.exclude,before:n,after:c}}function Zu(e,t){let r=new Map,o=M(e);if(o)r.set(".",o);for(let n of t){if(n.path===".")continue;let s=mt(e,n.path);if(!Ru(s,{throwIfNoEntry:!1})?.isDirectory())continue;let c=M(s);if(c?.root===s)r.set(n.path,c)}return r}function Ou(e,t){let r=[...t.keys()].filter((n)=>n!=="."&&e.startsWith(`${n}/`));r.sort((n,s)=>s.length-n.length);let o=r[0]??".";return t.get(o)}function Cu(e,t,r,o,n){let s=Zu(e,t.repositories),i=new Map,c=[],a=[];if(r){let d=Zu(e,r.repositories);for(let m of d.values())i.set(m.commonDirectory,{scope:m,patterns:new Set});for(let m of n){let g=mt(e,m),y=Ou(m,d);Se(g,y?.root),a.push(y?{absolute:g,gitRoot:y.root}:{absolute:g})}}let u=[...t.files,{path:"llm/harness/workspace.json",versioned:t.workspaceVersioned},{path:"llm/harness/project.json",versioned:t.workspaceVersioned}],p=new Set(t.repositories.filter((d)=>!Ru(mt(e,d.path),{throwIfNoEntry:!1})).map((d)=>he(d.path)));for(let d of u){if(p.has(d.path))continue;let m=Ou(d.path,s),g=mt(e,d.path);if(Se(g,m?.root),a.push(m?{absolute:g,gitRoot:m.root}:{absolute:g}),!m)continue;let y=we(m.root,g);if(c.push({git:m,path:y,absolute:g,versioned:d.versioned}),d.versioned)continue;if(Me(m,g)){o.push({path:d.path,reason:"Git already tracks this file. Choose versioned mode or separately remove it from the index before retrying."});continue}let v=i.get(m.commonDirectory)??{scope:m,patterns:new Set};v.patterns.add(Qt(y)),i.set(m.commonDirectory,v)}let l=[],f=t.installation??W(e).slice(0,16);for(let{scope:d,patterns:m}of i.values()){let g=jo(d,f,m);if(g)l.push(g)}return{operations:l,checks:c,boundaries:a}}import{lstatSync as ih,readdirSync as ch}from"node:fs";import{resolve as Iu}from"node:path";var Au=4096,ah=67108864,uh=new Set([".git","node_modules","raw","processing",".npmrc"]);function Tu(e){if(!e)throw Error("The release content directory is required for install and update.");let t=de(e),r=new Map,o=["."],n=0;while(o.length){let s=o.pop();if(!s)break;let i=ch(Iu(t,s),{withFileTypes:!0});for(let c of i.sort((a,u)=>a.name.localeCompare(u.name,"en"))){let a=s==="."?c.name:`${s}/${c.name}`;if(oe(a),uh.has(c.name)||/^\.env(?:$|\.(?!example$))/u.test(c.name))throw Error(`The release payload includes an unsupported private path: ${a}.`);if(c.isDirectory()&&!ih(Iu(t,a)).isSymbolicLink()){if(o.length+r.size>=Au||a.split("/").length>12)throw Error(`Release content exceeds the directory limits at ${a}.`);o.push(a);continue}let u=`llm/${a}`;if(!c.isFile()||!wo(u,[]))throw Error(`The release payload includes an unsupported file: ${a}.`);let p=C(t,a);if(!p)throw Error(`The release payload changed while reading ${a}.`);if(n+=p.bytes.length,r.size>=Au||n>ah)throw Error(`The release payload exceeds the installation limits at ${a}.`);r.set(u,p)}}if(!r.has("llm/HARNESS.md"))throw Error("The release payload is missing the harness index HARNESS.md.");return r}var rr="llm/harness/project.json";function Nu(e,t,r,o){let n=t.repositories.find((c)=>!r.repositories.some((a)=>a.path===c.path));if(!n)return;let s=r.repositories.find((c)=>c.identity&&c.identity===n.identity);if(!s)return;let i=C(e,rr);if(!i)return;try{let c=Pe.parse(JSON.parse(i.bytes.toString("utf8")));if(!c.projects.some((p)=>p.path===n.path))return;if(c.projects.some((p)=>p.path===s.path)){o.push({path:rr,reason:"Both the old and new checkout paths already have project settings. Reconcile them before registering the move."});return}let a=c.projects.map((p)=>{if(p.path===n.path)return{...p,path:s.path};return p}),u=U(`${JSON.stringify(Pe.parse({...c,projects:a}),null,2)}
67
+ `,i.mode);return{base:e,path:rr,before:i,after:u}}catch(c){throw Error(`Cannot reassign the project settings in ${rr}. Restore a valid settings file before retrying.`,{cause:c})}}import{lstatSync as ph}from"node:fs";import{resolve as lh}from"node:path";var Do="<!-- apptoolkit-harness:begin -->",or="<!-- apptoolkit-harness:end -->";function nr(e){return["AGENTS.md","CLAUDE.md",".claude/rules/apptoolkit.md"].includes(e)}function fh(e,t){let r=e.indexOf(Do),o=e.indexOf(or);if(r===-1&&o===-1)return;if(r<0||o<=r||e.lastIndexOf(Do)!==r||e.lastIndexOf(or)!==o)throw Error(`The AppToolkit router block in ${t} is malformed. Review its markers before retrying.`);let n=o+or.length;return{prefix:e.slice(0,r),old:e.slice(r,n),suffix:e.slice(n)}}function ju(e,t,r,o,n,s,i){let c;try{c=C(e,t)}catch(g){if(!(g instanceof Gt))throw g;i.push(`Preserved the existing native instructions path ${t}. Use the installed apptoolkit command to open the harness explicitly.`);return}let a=c?.bytes.toString("utf8")??"",u=n?.files.find((g)=>g.path===t)?.fragment,p=a.includes(`\r
68
68
  `)?`\r
69
69
  `:`
70
- `,l=[Ao,r.trimEnd().replaceAll(`
71
- `,p),er].join(p),f=M(l);if(c&&!Buffer.from(a).equals(c.bytes)){i.push({path:t,reason:"The native project instructions are not UTF-8. Open the harness explicitly from the agent instead."});return}let d=ah(a,t);if(u&&!d){i.push({path:t,reason:"The previously installed router block was removed. Restore or reconcile it before updating."});return}if(d){let m=M(d.old);if(m!==u&&m!==f){i.push({path:t,reason:"The existing router block has local edits. Reconcile it before applying the release."});return}if(!u&&!o&&(d.prefix||d.suffix!==p)){s.push(`Preserved the existing ${t}. Use the installed apptoolkit command to open the harness explicitly.`);return}return{content:U(`${d.prefix}${l}${d.suffix}`,c?.mode),versioned:o,fragment:f,observed:c}}if(c&&!o){s.push(`Preserved the existing ${t} in local mode. Use the installed apptoolkit command to open the harness explicitly.`);return}let g=a;if(a&&!a.endsWith(`${p}${p}`))g=a.endsWith(p)?`${a}${p}`:`${a}${p}${p}`;return{content:U(`${g}${l}${p}`,c?.mode),versioned:o,fragment:f,observed:c}}function Tu(e,t,r,o,n){let i=new Map;if(t.hosts.includes("codex")&&sh(ch(e,"AGENTS.override.md"),{throwIfNoEntry:!1}))n.push("Codex may prioritize the existing AGENTS.override.md. Use $apptoolkit explicitly to open the harness.");for(let{path:s,content:c}of co(t.hosts)){let p=s==="CLAUDE.md"&&r?.files.some((d)=>d.path===".claude/rules/apptoolkit.md")?".claude/rules/apptoolkit.md":s,l=[],f=Au(e,p,c,t.workspaceVersioned,r,o,l);if(f)i.set(p,f);else if(p==="CLAUDE.md"&&!t.workspaceVersioned&&l.length){let d=Au(e,".claude/rules/apptoolkit.md",c,!1,r,o,n);if(d)i.set(".claude/rules/apptoolkit.md",d),n.push("Claude uses .claude/rules/apptoolkit.md alongside the preserved CLAUDE.md.");else n.push(...l)}else n.push(...l)}return i}import{lstatSync as uh}from"node:fs";import{basename as ph,resolve as ju}from"node:path";function mt(e,t){return!uh(ju(e,t),{throwIfNoEntry:!1})}function No(e,t){let r=ve(e,ju(e,t));if(r!==".")oe(r);return r}function Du(e,t,r){let o=Je(e,t),n=L(o);if(r&&!n)throw Error(`Cannot version files in ${o} because Git does not manage this directory.`);let i=n&&Ra(n.root);return i?{path:t,versioned:r,identity:i}:{path:t,versioned:r}}function lh(e,t,r){let o=t.repository;if(!o)throw Error("Specify the directory of the Git repository to register.");let n=No(e,o);if(r.repositories.find((p)=>p.path===n)&&!mt(e,n))return Je(e,n),r.repositories;if(mt(e,n)){let p=r.repositories.filter((f)=>ph(f.path)===o),l=p[0];if(l&&p.length===1&&!mt(e,l.path))return Je(e,l.path),r.repositories}if(n===".")throw Error("Select the directory of a Git checkout inside the workspace.");let s=t.repositories.find((p)=>No(e,p.path)===n)?.versioned;if(s===void 0)throw Error(`Choose whether generated files inside ${n} should be versioned before registering it.`);let c=Du(e,n,s),a=r.repositories.filter((p)=>c.identity&&p.identity===c.identity&&mt(e,p.path)),u=a[0];if(a.length>1)throw Error(`More than one missing registration matches ${n}. Resolve the ambiguous repository paths before retrying.`);return[...r.repositories.filter((p)=>p.path!==u?.path),c]}function Fu(e,t,r){let{root:o}=e;if(t.action==="add-repo"){if(!r)throw Error("Install the workspace harness before registering an additional repository.");return lh(o,t,r).sort((c,a)=>c.path.localeCompare(a.path,"en"))}let n=t.workspaceVersioned&&Boolean(e.gitRoot),i=t.repositories;if(!i.length&&r)i=r.repositories;if(!i.length&&e.kind==="workspace")throw Error("Select the repositories to register in this workspace.");if(!i.length)i=[{path:".",versioned:n}];let s=new Map;for(let c of i){let a=No(o,c.path);if(s.has(a))throw Error(`Repository ${a} was selected more than once.`);let u=r?.repositories.find((p)=>p.path===a);if(u&&mt(o,a))s.set(a,{...u,versioned:c.versioned});else s.set(a,Du(o,a,c.versioned))}if(r?.repositories.some((c)=>!s.has(c.path)))throw Error("The new selection omits a registered repository. Keep the existing selection when reinstalling or updating.");return[...s.values()].sort((c,a)=>c.path.localeCompare(a.path,"en"))}import{resolve as fh}from"node:path";var dh=P({root:w().min(1),repository:w().min(1),file:w().endsWith(".llm.md")}),To=new WeakMap;function jo(e){let t=dh.parse(e),r=de(t.root),o=R(r,H),n=Y(r),i=n?.repositories.find((y)=>y.path===t.repository);if(!n||!i)throw Error(`Register repository ${t.repository} in the workspace before excluding generated files.`);if(i.versioned)throw Error(`Repository ${t.repository} is configured to version its generated files.`);let s=Je(r,i.path),c=Ht(s,t.file),a=L(s);ze(c,a?.root);let u={root:r,writes:[],conflicts:[]},p=[{base:r,path:H,before:o,after:o}],l=[a?{absolute:c,gitRoot:a.root}:{absolute:c}];if(!ce(o,R(r,H)))throw Error("The installation receipt changed while planning. Retry the artifact command.");if(!a)return To.set(u,{exclusions:[],files:[],checks:[],guards:p,boundaries:l}),u;if(Le(a,c))u.conflicts.push({path:t.file,reason:"Git already tracks this file. Resolve its index status before choosing local mode."});let f=ve(a.root,c),d=n.installation??M(r).slice(0,16),g=Io(a,`${d} artifacts`,new Set([qt(f)]),!0),m=g?[g]:[];if(g)u.writes.push({path:fh(g.base,g.path),before:g.before?.hash??null,after:g.after?.hash??null});return To.set(u,{exclusions:m,files:[],checks:[{git:a,path:f,absolute:c,versioned:!1}],guards:p,boundaries:l}),u}function Do(e){let t=To.get(e);if(!t||e.conflicts.length)throw Error("Resolve the artifact conflicts and create a new plan in this process before applying.");return{changed:fo(e.root,t)}}function hh(e,t){let r=_e(e,t,"llm"),o=Lu(r,_e(e,"llm/HARNESS.md"));return["# Harness context","",`Start from the workspace folder at \`${Lu(_e(e,t),e)||"."}\` and open the [harness index](${encodeURI(o)}).`,"Read the workspace profile and this repository’s own instructions before changing code.","Use the repository-specific settings for services, documentation conventions and validation.",""].join(`
72
- `)}function mh(e,t,r,o,n,i){let s=new Map;if(t.action!=="add-repo"){for(let[l,f]of Ru(t.contentDirectory))s.set(l,{content:f,versioned:r.workspaceVersioned});for(let l of ao(r.hosts,r.version))s.set(l.path,{content:U(l.content),versioned:r.workspaceVersioned});for(let[l,f]of Tu(e,r,o,n,i))s.set(l,f);let c="llm/README.md",a=R(e,c),u=o?.files.some((l)=>l.path===c),p=U(`# LLM workspace
70
+ `,l=[Do,r.trimEnd().replaceAll(`
71
+ `,p),or].join(p),f=W(l);if(c&&!Buffer.from(a).equals(c.bytes)){s.push({path:t,reason:"The native project instructions are not UTF-8. Open the harness explicitly from the agent instead."});return}let d=fh(a,t);if(u&&!d){s.push({path:t,reason:"The previously installed router block was removed. Restore or reconcile it before updating."});return}if(d){let g=W(d.old);if(g!==u&&g!==f){s.push({path:t,reason:"The existing router block has local edits. Reconcile it before applying the release."});return}if(!u&&!o&&(d.prefix||d.suffix!==p)){i.push(`Preserved the existing ${t}. Use the installed apptoolkit command to open the harness explicitly.`);return}return{content:U(`${d.prefix}${l}${d.suffix}`,c?.mode),versioned:o,fragment:f,observed:c}}if(c&&!o){i.push(`Preserved the existing ${t} in local mode. Use the installed apptoolkit command to open the harness explicitly.`);return}let m=a;if(a&&!a.endsWith(`${p}${p}`))m=a.endsWith(p)?`${a}${p}`:`${a}${p}${p}`;return{content:U(`${m}${l}${p}`,c?.mode),versioned:o,fragment:f,observed:c}}function Du(e,t,r,o,n){let s=new Map;if(t.hosts.includes("codex")&&ph(lh(e,"AGENTS.override.md"),{throwIfNoEntry:!1}))n.push("Codex may prioritize the existing AGENTS.override.md. Use $apptoolkit explicitly to open the harness.");for(let{path:i,content:c}of lo(t.hosts)){let p=i==="CLAUDE.md"&&r?.files.some((d)=>d.path===".claude/rules/apptoolkit.md")?".claude/rules/apptoolkit.md":i,l=[],f=ju(e,p,c,t.workspaceVersioned,r,o,l);if(f)s.set(p,f);else if(p==="CLAUDE.md"&&!t.workspaceVersioned&&l.length){let d=ju(e,".claude/rules/apptoolkit.md",c,!1,r,o,n);if(d)s.set(".claude/rules/apptoolkit.md",d),n.push("Claude uses .claude/rules/apptoolkit.md alongside the preserved CLAUDE.md.");else n.push(...l)}else n.push(...l)}return s}import{lstatSync as dh}from"node:fs";import{basename as hh,resolve as Fu}from"node:path";function gt(e,t){return!dh(Fu(e,t),{throwIfNoEntry:!1})}function Fo(e,t){let r=we(e,Fu(e,t));if(r!==".")oe(r);return r}function Lu(e,t,r){let o=Ve(e,t),n=M(o);if(r&&!n)throw Error(`Cannot version files in ${o} because Git does not manage this directory.`);let s=n&&Ta(n.root);return s?{path:t,versioned:r,identity:s}:{path:t,versioned:r}}function mh(e,t,r){let o=t.repository;if(!o)throw Error("Specify the directory of the Git repository to register.");let n=Fo(e,o);if(r.repositories.find((p)=>p.path===n)&&!gt(e,n))return Ve(e,n),r.repositories;if(gt(e,n)){let p=r.repositories.filter((f)=>hh(f.path)===o),l=p[0];if(l&&p.length===1&&!gt(e,l.path))return Ve(e,l.path),r.repositories}if(n===".")throw Error("Select the directory of a Git checkout inside the workspace.");let i=t.repositories.find((p)=>Fo(e,p.path)===n)?.versioned;if(i===void 0)throw Error(`Choose whether generated files inside ${n} should be versioned before registering it.`);let c=Lu(e,n,i),a=r.repositories.filter((p)=>c.identity&&p.identity===c.identity&&gt(e,p.path)),u=a[0];if(a.length>1)throw Error(`More than one missing registration matches ${n}. Resolve the ambiguous repository paths before retrying.`);return[...r.repositories.filter((p)=>p.path!==u?.path),c]}function Mu(e,t,r){let{root:o}=e;if(t.action==="add-repo"){if(!r)throw Error("Install the workspace harness before registering an additional repository.");return mh(o,t,r).sort((c,a)=>c.path.localeCompare(a.path,"en"))}let n=t.workspaceVersioned&&Boolean(e.gitRoot),s=t.repositories;if(!s.length&&r)s=r.repositories;if(!s.length&&e.kind==="workspace")throw Error("Select the repositories to register in this workspace.");if(!s.length)s=[{path:".",versioned:n}];let i=new Map;for(let c of s){let a=Fo(o,c.path);if(i.has(a))throw Error(`Repository ${a} was selected more than once.`);let u=r?.repositories.find((p)=>p.path===a);if(u&&gt(o,a))i.set(a,{...u,versioned:c.versioned});else i.set(a,Lu(o,a,c.versioned))}if(r?.repositories.some((c)=>!i.has(c.path)))throw Error("The new selection omits a registered repository. Keep the existing selection when reinstalling or updating.");return[...i.values()].sort((c,a)=>c.path.localeCompare(a.path,"en"))}import{resolve as gh}from"node:path";var yh=P({root:w().min(1),repository:w().min(1),file:w().endsWith(".llm.md")}),Lo=new WeakMap;function Mo(e){let t=yh.parse(e),r=de(t.root),o=C(r,F),n=Y(r),s=n?.repositories.find((y)=>y.path===t.repository);if(!n||!s)throw Error(`Register repository ${t.repository} in the workspace before excluding generated files.`);if(s.versioned)throw Error(`Repository ${t.repository} is configured to version its generated files.`);let i=Ve(r,s.path),c=qt(i,t.file),a=M(i);Se(c,a?.root);let u={root:r,writes:[],conflicts:[]},p=[{base:r,path:F,before:o,after:o}],l=[a?{absolute:c,gitRoot:a.root}:{absolute:c}];if(!ce(o,C(r,F)))throw Error("The installation receipt changed while planning. Retry the artifact command.");if(!a)return Lo.set(u,{exclusions:[],files:[],checks:[],guards:p,boundaries:l}),u;if(Me(a,c))u.conflicts.push({path:t.file,reason:"Git already tracks this file. Resolve its index status before choosing local mode."});let f=we(a.root,c),d=n.installation??W(r).slice(0,16),m=jo(a,`${d} artifacts`,new Set([Qt(f)]),!0),g=m?[m]:[];if(m)u.writes.push({path:gh(m.base,m.path),before:m.before?.hash??null,after:m.after?.hash??null});return Lo.set(u,{exclusions:g,files:[],checks:[{git:a,path:f,absolute:c,versioned:!1}],guards:p,boundaries:l}),u}function Wo(e){let t=Lo.get(e);if(!t||e.conflicts.length)throw Error("Resolve the artifact conflicts and create a new plan in this process before applying.");return{changed:yo(e.root,t)}}function xh(e,t){let r=be(e,t,"llm"),o=Wu(r,be(e,"llm/HARNESS.md"));return["# Harness context","",`Start from the workspace folder at \`${Wu(be(e,t),e)||"."}\` and open the [harness index](${encodeURI(o)}).`,"Read the workspace profile and this repository’s own instructions before changing code.","Use the repository-specific settings for services, documentation conventions and validation.",""].join(`
72
+ `)}function vh(e,t,r,o,n,s){let i=new Map;if(t.action!=="add-repo"){for(let[l,f]of Tu(t.contentDirectory))i.set(l,{content:f,versioned:r.workspaceVersioned});for(let l of fo(r.hosts,r.version))i.set(l.path,{content:U(l.content),versioned:r.workspaceVersioned});for(let[l,f]of Du(e,r,o,n,s))i.set(l,f);let c="llm/README.md",a=C(e,c),u=o?.files.some((l)=>l.path===c),p=U(`# LLM workspace
73
73
 
74
74
  Open the [harness index](HARNESS.md) for workspace rules, project routing, workflows and tools.
75
- `);if(!a||u||a.hash===p.hash)s.set(c,{content:p,versioned:r.workspaceVersioned})}for(let c of r.repositories){if(!Mu(_e(e,c.path),{throwIfNoEntry:!1}))continue;let a=Se(c.path);s.set(a,{content:U(hh(e,c.path)),versioned:c.versioned})}return s}function gh(e,t,r,o,n,i){let s=[],c=new Map(o?.files.map((p)=>[p.path,p])),a=new Set(o?.repositories.map((p)=>Se(p.path))),u=new Set(r.repositories.filter((p)=>!Mu(_e(e,p.path),{throwIfNoEntry:!1})).map((p)=>Se(p.path)));for(let[p,{content:l,versioned:f,fragment:d,observed:g}]of t){let m=R(e,p),y=c.get(p),v=U(l.bytes,m?.mode??l.mode);if(g!==void 0&&!ce(m,g))throw Error(`The native router ${p} changed while planning. Retry the workspace command.`);if(!d&&m&&m.hash!==v.hash&&m.hash!==y?.hash)i.push({path:p,reason:"A different local file is present. Review or move it before applying this release."});else if(!ce(m,v))s.push({base:e,path:p,before:m,after:v});r.files.push({path:p,hash:v.hash,versioned:f,...d?{fragment:d}:{}})}for(let p of c.values()){if(t.has(p.path))continue;if(Nu(p.path)||u.has(p.path)||n==="add-repo"&&!a.has(p.path)){r.files.push(p);continue}let l=R(e,p.path);if(!l)continue;if(l.hash!==p.hash){i.push({path:p.path,reason:"The release retires this file, but it has local edits. Preserve the changes before updating."});continue}s.push({base:e,path:p.path,before:l,after:null})}return r.files.sort((p,l)=>p.path.localeCompare(l.path,"en")),s}function Uu(e){let t=Wa.parse(e),r=Ze(t.root),{root:o}=r,n=R(o,H),i=Y(o);if(t.action==="update"&&!i)throw Error("Install the workspace harness before updating it.");if(t.action==="install"&&i&&i.version!==t.version)throw Error(`This workspace already has harness ${i.version}. Use update to select ${t.version}.`);let s=t.action==="add-repo"&&i,c=Fu(r,t,i),a=s?i.workspaceVersioned:t.workspaceVersioned;if(a&&!r.gitRoot)throw Error(`The workspace at ${o} does not have Git. Choose local workspace mode before retrying.`);let u={schema:1,version:s?i.version:t.version,hosts:s?i.hosts:[...new Set(t.hosts)].sort(),workspaceVersioned:a,repositories:c,services:s?i.services:[...new Set(t.services)].sort(),installation:i?.installation??M(o).slice(0,16),files:[]},p=[],l=[],f=mh(o,t,u,i,p,l),d=gh(o,f,u,i,t.action,p);if(s){let z=Iu(o,i,u,p);if(z)d.push(z)}let g=d.filter((z)=>z.after===null).map((z)=>z.path),m=Zu(o,u,i,p,g),y=new Set(m.checks.filter((z)=>!z.versioned&&z.git.commonDirectory!==_e(z.git.root,".git")).map((z)=>z.git.commonDirectory));for(let z of y)l.push(`Local Git exclusions use ${_e(z,"info/exclude")}. Linked worktrees that share this Git directory use the same exclusions.`);let v=U(`${JSON.stringify(u,null,2)}
76
- `,n?.mode);if(!ce(n,R(o,H)))throw Error("The installation receipt changed while planning. Retry the workspace command.");if(!ce(n,v))d.push({base:o,path:H,before:n,after:v});let k=[...m.operations,...d].map((z)=>({path:z.base===o?z.path:_e(z.base,z.path),before:z.before?.hash??null,after:z.after?.hash??null})),G={root:o,action:t.action,writes:k,conflicts:p,notices:l,receipt:u};return Ta(G,{exclusions:m.operations,files:d,checks:m.checks,guards:[{base:o,path:H,before:n,after:n}],boundaries:m.boundaries}),G}import{parseArgs as yh}from"node:util";var Fo=X(["codex","claude","opencode"]),Oe=X(["plane","penpot"]);function Wu(e){let t=yh({args:e,allowPositionals:!0,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},root:{type:"string"},json:{type:"boolean"},yes:{type:"boolean",short:"y"},plan:{type:"boolean"},hosts:{type:"string"},versioned:{type:"boolean"},local:{type:"boolean"},repo:{type:"string",multiple:!0},"repo-mode":{type:"string",multiple:!0},"repo-versioned":{type:"boolean"},"repo-local":{type:"boolean"},"enable-service":{type:"string",multiple:!0},config:{type:"string"},project:{type:"string"},"verify-read":{type:"boolean"},"verify-health":{type:"boolean"},manifest:{type:"string"},file:{type:"string",multiple:!0},section:{type:"string"}}}),{values:r}=t;if(r.versioned&&r.local||r["repo-versioned"]&&r["repo-local"])throw Error("Choose exactly one Git storage mode for each scope.");if(r.plan&&r.yes)throw Error("Choose --plan to preview or --yes to apply.");return t}function K(e,t){return w().min(1,`Supply ${t}.`).parse(e??"")}function Bu(e){let t=new Map;for(let r of e){let o=r.lastIndexOf("="),n=r.slice(0,o),i=r.slice(o+1);if(o<1||i!=="local"&&i!=="versioned"||t.has(n))throw Error(`Invalid or duplicate --repo-mode ${r}. Use <path>=local or <path>=versioned.`);t.set(n,i==="versioned")}return t}import{readFileSync as Ju}from"node:fs";var xh=P({kind:w().min(1),title:w().min(1).optional(),headings:_(w().min(1)).default([]),checkedItems:_(w().min(1)).default([]),requiredText:_(w().min(1)).default([]),forbiddenText:_(w().min(1)).default([])});function vh(e){let t,r=[];for(let o of e.split(/\r?\n/)){let n=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(o),i=n?.[1];if(t){if(i?.startsWith(t)&&!n?.[2]?.trim())t=void 0}else if(i)t=i;else r.push(o)}return r}function Vu(e,t){let r=xh.parse(JSON.parse(Ju(e,"utf8"))),o=Ju(t,"utf8"),n=vh(o),i=n.join(`
77
- `),s=o.toLowerCase(),c=n.flatMap((l)=>{let f=/^ {0,3}#{1,6}[ \t]+(.+?)\s*$/.exec(l);return f?.[1]?[f[1].replace(/[ \t]+#+[ \t]*$/,"")]:[]}),a=new Set(n.flatMap((l)=>{let f=/^\s*[-+*]\s+\[[xX]\]\s+(.+?)\s*$/.exec(l);return f?.[1]?[f[1]]:[]})),u=[],p=-1;if(r.title&&c[0]!==r.title)u.push(`Expected the first heading to be ${r.title}.`);for(let l of r.headings){let f=c.indexOf(l,p+1);if(f<0)u.push(`Missing or out-of-order heading: ${l}.`);else p=f}for(let l of r.checkedItems)if(!a.has(l))u.push(`Checklist item must be checked: ${l}.`);for(let l of r.requiredText)if(!i.includes(l))u.push(`Required text is absent: ${l}.`);for(let[l,f]of r.forbiddenText.entries())if(s.includes(f.toLowerCase()))u.push(`Forbidden text rule ${l+1} matched.`);return{kind:r.kind,valid:u.length===0,issues:u}}import{resolve as Lo}from"node:path";var wh=[{label:"Keep harness files local",value:"local"},{label:"Make harness files available to commit",value:"versioned"}],Hu=[{label:"No",value:"no"},{label:"Yes",value:"yes"}];async function Mo(e,t,r){if(!e)throw Error(`Supply ${r} for a noninteractive run.`);return await e(t,wh)==="versioned"}async function _h(e){let{options:t,select:r}=e;if(t.hosts)return[...new Set(_(Fo).min(1).parse(t.hosts.split(",")))];if(!r)throw Error("Supply --hosts codex,claude,opencode or a subset for a noninteractive install.");let n=await r("Which agent hosts should this workspace support?",[{label:"Codex, Claude Code and OpenCode",value:"codex,claude,opencode"},{label:"Codex",value:"codex"},{label:"Claude Code",value:"claude"},{label:"OpenCode",value:"opencode"},{label:"Codex and Claude Code",value:"codex,claude"},{label:"Codex and OpenCode",value:"codex,opencode"},{label:"Claude Code and OpenCode",value:"claude,opencode"}]);return _(Fo).parse(n.split(","))}async function bh(e,t){let{options:r,select:o}=e,n=Bu(r["repo-mode"]??[]),i=new Set(t.repositories.map(({path:a})=>a)),s=new Set(r.repo??[]),c=[];for(let a of[...s,...n.keys()])if(!i.has(a))throw Error(`No repository was detected at ${a}. Inspect the workspace for accepted relative paths.`);for(let a of t.repositories){if(s.size&&!s.has(a.path))continue;if(t.kind==="workspace"&&o&&!s.size&&!n.has(a.path)){if(await o(`Register ${a.path}?`,[{label:"Register",value:"yes"},{label:"Skip",value:"no"}])==="no")continue}let u=`--repo-mode ${a.path}=local or ${a.path}=versioned`,p=a.gitRoot?n.get(a.path)??await Mo(o,`Version files generated inside ${a.path}?`,u):!1;c.push({path:a.path,versioned:p})}if(t.kind==="workspace"&&c.length===0)throw Error("Select at least one repository for the shared workspace.");return c}async function kh(e){let{root:t,options:r,select:o,emit:n}=e,i=Ze(t);if(!r.json){let p={blank:"an empty project",existing:"an existing project",workspace:"a parent workspace"};n(`Detected ${i.monorepo?"a monorepo":p[i.kind]} at ${i.root}.`)}let s=await _h(e),c=i.gitRoot?r.versioned||!r.local&&await Mo(o,"Version the central harness with this Git repository?","--local or --versioned"):!1;if(r.versioned&&!i.gitRoot)throw Error("The workspace root has no Git repository. Use --local.");let a=await bh(e,i),u=_(Oe).parse(r["enable-service"]??[]);if(o&&!r["enable-service"]){for(let p of Oe.options)if(await o(`Offer ${p==="plane"?"Plane for agent work items":"Penpot for design"} during setup?`,Hu)==="yes")u.push(p)}return{hosts:s,workspaceVersioned:c,repositories:a,services:[...new Set(u)]}}function $h(e){let t=Y(e);if(!t)throw Error(`No harness is registered at ${e}. Run install first.`);return{hosts:t.hosts,workspaceVersioned:t.workspaceVersioned,repositories:t.repositories,services:t.services}}async function Ku(e,t,r){let{root:o,version:n,options:i,emit:s,select:c,contentDirectory:a}=e;if(!a&&t!=="add-repo")throw Error("Run this command from a release package. Use bunx @apptoolkit/harness@latest update for an installed workspace.");let u=Y(o),p=t==="install"&&!u?await kh(e):$h(o),l;if(t==="update"&&i["enable-service"]){let m=_(Oe).parse(i["enable-service"]);p.services=[...new Set([...p.services,...m])]}if(t==="add-repo"){l=K(r,"the checkout path");let m=Lo(o,l),y=p.repositories.find(({path:k})=>Lo(o,k)===m),v=i["repo-versioned"]||(i["repo-local"]?!1:y?.versioned??await Mo(c,`Version files generated inside ${l}?`,"--repo-local or --repo-versioned"));p.repositories=[...p.repositories.filter(({path:k})=>Lo(o,k)!==m),{path:l,versioned:v}]}let f=Uu({root:o,action:t,version:n,contentDirectory:a??"",...p,...l?{repository:l}:{}}),d={action:t,root:f.root,writes:f.writes.map(({path:m,before:y,after:v})=>({path:m,effect:v===null?"remove":y===null?"create":"update",before:y,after:v})),conflicts:f.conflicts,notices:f.notices};if(!i.json){s(`Plan for ${f.root} contains ${d.writes.length} change(s).`);for(let m of d.writes)s(` ${m.effect} ${m.path}`);for(let m of d.conflicts)s(` conflict ${m.path}: ${m.reason}`);for(let m of d.notices)s(` note ${m}`)}if(i.plan||!i.yes&&!c){if(i.json)s(d);return f.conflicts.length?1:0}if(f.conflicts.length){if(i.json)s(d);throw Error("Resolve the reported installation conflicts before applying the plan.")}if(!i.yes&&f.writes.length&&c&&await c("Apply this plan?",Hu)!=="yes")return 0;let g=ho(f);if(i.json)s({...d,changed:g.changed,version:g.receipt.version,hosts:g.receipt.hosts});else if(s(`Applied ${g.changed} change(s) for @apptoolkit/harness ${g.receipt.version}.`),t==="install"){s(`Open ${f.root} in your selected agent host.`);for(let m of g.receipt.hosts)s(` ${m}: ${m==="codex"?"$":"/"}apptoolkit init`)}return 0}var Sh=`@apptoolkit/harness 1.0.1
75
+ `);if(!a||u||a.hash===p.hash)i.set(c,{content:p,versioned:r.workspaceVersioned})}for(let c of r.repositories){if(!Uu(be(e,c.path),{throwIfNoEntry:!1}))continue;let a=he(c.path);i.set(a,{content:U(xh(e,c.path)),versioned:c.versioned})}return i}function wh(e,t,r,o,n,s){let i=[],c=new Map(o?.files.map((p)=>[p.path,p])),a=new Set(o?.repositories.map((p)=>he(p.path))),u=new Set(r.repositories.filter((p)=>!Uu(be(e,p.path),{throwIfNoEntry:!1})).map((p)=>he(p.path)));for(let[p,{content:l,versioned:f,fragment:d,observed:m}]of t){let g=C(e,p),y=c.get(p),v=U(l.bytes,g?.mode??l.mode);if(m!==void 0&&!ce(g,m))throw Error(`The native router ${p} changed while planning. Retry the workspace command.`);if(!d&&g&&g.hash!==v.hash&&g.hash!==y?.hash)s.push({path:p,reason:"A different local file is present. Review or move it before applying this release."});else if(!ce(g,v))i.push({base:e,path:p,before:g,after:v});r.files.push({path:p,hash:v.hash,versioned:f,...d?{fragment:d}:{}})}for(let p of c.values()){if(t.has(p.path))continue;if(nr(p.path)||u.has(p.path)||n==="add-repo"&&!a.has(p.path)){r.files.push(p);continue}let l=C(e,p.path);if(!l)continue;if(l.hash!==p.hash){s.push({path:p.path,reason:"The release retires this file, but it has local edits. Preserve the changes before updating."});continue}i.push({base:e,path:p.path,before:l,after:null})}return r.files.sort((p,l)=>p.path.localeCompare(l.path,"en")),i}function Bu(e){let t=Va.parse(e),r=Ze(t.root),{root:o}=r,n=C(o,F),s=Y(o);if(t.action==="update"&&!s)throw Error("Install the workspace harness before updating it.");if(t.action==="install"&&s&&s.version!==t.version)throw Error(`This workspace already has harness ${s.version}. Use update to select ${t.version}.`);let i=t.action==="add-repo"&&s,c=Mu(r,t,s),a=i?s.workspaceVersioned:t.workspaceVersioned;if(a&&!r.gitRoot)throw Error(`The workspace at ${o} does not have Git. Choose local workspace mode before retrying.`);let u={schema:1,version:i?s.version:t.version,hosts:i?s.hosts:[...new Set(t.hosts)].sort(),workspaceVersioned:a,repositories:c,services:i?s.services:[...new Set(t.services)].sort(),installation:s?.installation??W(o).slice(0,16),files:[]},p=[],l=[],f=vh(o,t,u,s,p,l),d=wh(o,f,u,s,t.action,p);if(i){let z=Nu(o,s,u,p);if(z)d.push(z)}let m=d.filter((z)=>z.after===null).map((z)=>z.path),g=Cu(o,u,s,p,m),y=new Set(g.checks.filter((z)=>!z.versioned&&z.git.commonDirectory!==be(z.git.root,".git")).map((z)=>z.git.commonDirectory));for(let z of y)l.push(`Local Git exclusions use ${be(z,"info/exclude")}. Linked worktrees that share this Git directory use the same exclusions.`);let v=U(`${JSON.stringify(u,null,2)}
76
+ `,n?.mode);if(!ce(n,C(o,F)))throw Error("The installation receipt changed while planning. Retry the workspace command.");if(!ce(n,v))d.push({base:o,path:F,before:n,after:v});let k=[...g.operations,...d].map((z)=>({path:z.base===o?z.path:be(z.base,z.path),before:z.before?.hash??null,after:z.after?.hash??null})),G={root:o,...r.gitRoot?{gitRoot:r.gitRoot}:{},action:t.action,writes:k,conflicts:p,notices:l,receipt:u};return Fa(G,{exclusions:g.operations,files:d,checks:g.checks,guards:[{base:o,path:F,before:n,after:n}],boundaries:g.boundaries}),G}import{parseArgs as _h}from"node:util";var Oe=X(["codex","claude","opencode"]),yt={codex:"Codex",claude:"Claude Code",opencode:"OpenCode"},Re=X(["plane","penpot"]);function Ju(e){let t=_h({args:e,allowPositionals:!0,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},root:{type:"string"},json:{type:"boolean"},yes:{type:"boolean",short:"y"},plan:{type:"boolean"},hosts:{type:"string"},versioned:{type:"boolean"},local:{type:"boolean"},repo:{type:"string",multiple:!0},"repo-mode":{type:"string",multiple:!0},"repo-versioned":{type:"boolean"},"repo-local":{type:"boolean"},"enable-service":{type:"string",multiple:!0},config:{type:"string"},project:{type:"string"},"verify-read":{type:"boolean"},"verify-health":{type:"boolean"},manifest:{type:"string"},file:{type:"string",multiple:!0},section:{type:"string"}}}),{values:r}=t;if(r.versioned&&r.local||r["repo-versioned"]&&r["repo-local"])throw Error("Choose exactly one Git storage mode for each scope.");if(r.plan&&r.yes)throw Error("Choose --plan to preview or --yes to apply.");return t}function K(e,t){return w().min(1,`Supply ${t}.`).parse(e??"")}function Vu(e){let t=new Map;for(let r of e){let o=r.lastIndexOf("="),n=r.slice(0,o),s=r.slice(o+1);if(o<1||s!=="local"&&s!=="versioned"||t.has(n))throw Error(`Invalid or duplicate --repo-mode ${r}. Use <path>=local or <path>=versioned.`);t.set(n,s==="versioned")}return t}import{readFileSync as Hu}from"node:fs";var bh=P({kind:w().min(1),title:w().min(1).optional(),headings:_(w().min(1)).default([]),checkedItems:_(w().min(1)).default([]),requiredText:_(w().min(1)).default([]),forbiddenText:_(w().min(1)).default([])});function kh(e){let t,r=[];for(let o of e.split(/\r?\n/)){let n=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(o),s=n?.[1];if(t){if(s?.startsWith(t)&&!n?.[2]?.trim())t=void 0}else if(s)t=s;else r.push(o)}return r}function Ku(e,t){let r=bh.parse(JSON.parse(Hu(e,"utf8"))),o=Hu(t,"utf8"),n=kh(o),s=n.join(`
77
+ `),i=o.toLowerCase(),c=n.flatMap((l)=>{let f=/^ {0,3}#{1,6}[ \t]+(.+?)\s*$/.exec(l);return f?.[1]?[f[1].replace(/[ \t]+#+[ \t]*$/,"")]:[]}),a=new Set(n.flatMap((l)=>{let f=/^\s*[-+*]\s+\[[xX]\]\s+(.+?)\s*$/.exec(l);return f?.[1]?[f[1]]:[]})),u=[],p=-1;if(r.title&&c[0]!==r.title)u.push(`Expected the first heading to be ${r.title}.`);for(let l of r.headings){let f=c.indexOf(l,p+1);if(f<0)u.push(`Missing or out-of-order heading: ${l}.`);else p=f}for(let l of r.checkedItems)if(!a.has(l))u.push(`Checklist item must be checked: ${l}.`);for(let l of r.requiredText)if(!s.includes(l))u.push(`Required text is absent: ${l}.`);for(let[l,f]of r.forbiddenText.entries())if(i.includes(f.toLowerCase()))u.push(`Forbidden text rule ${l+1} matched.`);return{kind:r.kind,valid:u.length===0,issues:u}}import{resolve as Uo}from"node:path";import{basename as $h,isAbsolute as zh,relative as Sh,resolve as Ph}from"node:path";var xt=new Intl.ListFormat("en"),Gu={plane:"Plane for work items",penpot:"Penpot for design"};function Eh(e,t,r){let o=e.receipt.version;if(e.action==="add-repo"){if(!e.writes.length&&!e.conflicts.length)return`Review the AppToolkit Harness registration for ${r} in ${e.root}.`;return`Register ${r} with the shared AppToolkit Harness in ${e.root}.`}if(e.action==="update"){if(t&&t.version!==o)return`Update AppToolkit Harness from ${t.version} to ${o} in ${e.root}.`;return`Update the AppToolkit Harness ${o} setup in ${e.root}.`}return`Install AppToolkit Harness ${o} in ${e.root}.`}function Zh(e,t){let{workspaceVersioned:r,repositories:o}=e.receipt,n=Boolean(e.gitRoot),i=(o.length===1&&o[0]?.path==="."?o[0]:void 0)?.versioned===r,c=i?"the harness, its settings and generated project guidance":"the shared harness and its settings",a=e.action==="add-repo"?o.filter(({path:p})=>p===t):o,u=[];if(r)u.push(`Make ${c} available to commit in the workspace Git repository.`);else if(n)u.push(`Keep ${c} on this machine using local Git ignore rules.`);else u.push(`Keep ${c} in this folder outside Git.`);for(let p of a){if(i&&p.path===".")continue;let l=p.path==="."?"this project":p.path;if(p.versioned)u.push(`Make the harness files generated for ${l} available to commit.`);else if(p.path!=="."||n)u.push(`Keep the harness files generated for ${l} local using Git ignore rules.`);else u.push(`Keep the harness files generated for ${l} in the project folder outside Git.`)}if(r||a.some(({versioned:p})=>p))u.push("You decide what to stage and commit in Git.");return u}function Oh(e,t){let{services:r}=e.receipt,o=r.filter((i)=>!t?.services.includes(i)),n=r.filter((i)=>t?.services.includes(i)),s=[];if(o.length){let i=xt.format(o.map((c)=>Gu[c]));s.push(`Offer ${i} during agent setup. Each connection is configured separately.`)}if(n.length){let i=xt.format(n.map((c)=>Gu[c]));s.push(`Optional services selected for this workspace are ${i}.`)}if(!r.length)s.push("Skip the optional Plane and Penpot setup.");return s}function Rh(e){let{writes:t}=e,r=t.filter(({after:f})=>f!==null),o=r.filter(({path:f})=>nr(f)),n=o.filter(({before:f})=>f===null).map(({path:f})=>f),s=o.filter(({before:f})=>f!==null).map(({path:f})=>f),i=new Set(e.receipt.repositories.map(({path:f})=>he(f))),c=new Set(["llm/HARNESS.md","llm/README.md"]),a="llm/harness/project.json",u=[],p=r.filter(({path:f})=>{let d=f.startsWith("llm/harness/")&&f!==F&&f!=="llm/harness/project.json";return c.has(f)||f.startsWith("llm/author-style/")||d});if(p.length){let f=p.every(({before:d})=>d===null)?"Add":"Refresh";u.push(`${f} shared workflows, project guidance, and tools for verification and code style in llm/.`)}if(r.some(({path:f})=>f.startsWith(".agents/")||f.startsWith(".claude/skills/")||f.startsWith(".opencode/commands/")))u.push("Set up the shortcuts your selected agents use to open the harness.");if(n.length)u.push(`Create agent guidance in ${xt.format(n)} so your agents can find the harness.`);if(s.length)u.push(`Update the harness section in ${xt.format(s)} and preserve the project guidance.`);if(r.some(({path:f})=>i.has(f)))u.push("Write project context that points agents to the shared harness and the relevant project rules.");if(r.some(({path:f})=>f==="llm/harness/project.json"))u.push("Update the saved project settings for the checkout path.");if(r.some(({path:f})=>zh(f)))u.push("Update the local Git ignore rules for the generated harness files.");if(r.some(({path:f})=>f===F))u.push("Save the harness version and workspace choices.");if(t.some(({after:f})=>f===null))u.push("Remove harness files retired by this plan.");return u}function Ch(e,t,r){let o=e.receipt.repositories.map(({path:i})=>i),n=o.find((i)=>!t?.repositories.some((c)=>c.path===i));if(n)return n;if(!r)return"the checkout";let s=Sh(e.root,Ph(e.root,r))||".";if(o.includes(s))return s;return o.find((i)=>$h(i)===r)??s}function qu(e,t,r){let o=e.action==="add-repo"?Ch(e,t,r):"",n=Oe.options.filter((a)=>e.receipt.hosts.includes(a)),s=xt.format(n.map((a)=>yt[a])),i=e.action==="add-repo"?[]:Oh(e,t),c=[Eh(e,t,o),`The harness will be available in ${s}.`,...Zh(e,o),...i,...Rh(e)];for(let a of e.notices)c.push(a);if(e.conflicts.length){c.push("Resolve these conflicts before applying the plan.");for(let{path:a,reason:u}of e.conflicts)c.push(` ${a}. ${u}`)}else if(!e.writes.length)c.push("The current setup already matches this plan.");return c}var Ih=[{label:"Keep harness files local",value:"local"},{label:"Make harness files available to commit",value:"versioned"}],Xu=[{label:"No",value:"no"},{label:"Yes",value:"yes"}];async function Bo(e,t,r){if(!e)throw Error(`Supply ${r} for a noninteractive run.`);return await e(t,Ih)==="versioned"}async function Ah(e){let{options:t,selectMany:r}=e;if(t.hosts)return[...new Set(_(Oe).min(1).parse(t.hosts.split(",")))];if(!r)throw Error("Supply --hosts codex,claude,opencode or a subset for a noninteractive install.");let o=Oe.options.map((s)=>({label:yt[s],value:s})),n=await r("Which agent hosts should this workspace support?",o,Oe.options);return _(Oe).min(1).parse(n)}async function Th(e,t){let{options:r,select:o}=e,n=Vu(r["repo-mode"]??[]),s=new Set(t.repositories.map(({path:a})=>a)),i=new Set(r.repo??[]),c=[];for(let a of[...i,...n.keys()])if(!s.has(a))throw Error(`No repository was detected at ${a}. Inspect the workspace for accepted relative paths.`);for(let a of t.repositories){if(i.size&&!i.has(a.path))continue;if(t.kind==="workspace"&&o&&!i.size&&!n.has(a.path)){if(await o(`Register ${a.path}?`,[{label:"Register",value:"yes"},{label:"Skip",value:"no"}])==="no")continue}let u=`--repo-mode ${a.path}=local or ${a.path}=versioned`,p=a.gitRoot?n.get(a.path)??await Bo(o,`Version files generated inside ${a.path}?`,u):!1;c.push({path:a.path,versioned:p})}if(t.kind==="workspace"&&c.length===0)throw Error("Select at least one repository for the shared workspace.");return c}async function Nh(e){let{root:t,options:r,select:o,emit:n}=e,s=Ze(t);if(!r.json){let p={blank:"an empty project",existing:"an existing project",workspace:"a parent workspace"};n(`Detected ${s.monorepo?"a monorepo":p[s.kind]} at ${s.root}.`)}let i=await Ah(e),c=s.gitRoot?r.versioned||!r.local&&await Bo(o,"Version the central harness with this Git repository?","--local or --versioned"):!1;if(r.versioned&&!s.gitRoot)throw Error("The workspace root has no Git repository. Use --local.");let a=await Th(e,s),u=_(Re).parse(r["enable-service"]??[]);if(o&&!r["enable-service"]){for(let p of Re.options)if(await o(`Offer ${p==="plane"?"Plane for agent work items":"Penpot for design"} during setup?`,Xu)==="yes")u.push(p)}return{hosts:i,workspaceVersioned:c,repositories:a,services:[...new Set(u)]}}function jh(e){let t=Y(e);if(!t)throw Error(`No harness is registered at ${e}. Run install first.`);return{hosts:t.hosts,workspaceVersioned:t.workspaceVersioned,repositories:t.repositories,services:t.services}}async function Yu(e,t,r){let{root:o,version:n,options:s,emit:i,select:c,contentDirectory:a}=e;if(!a&&t!=="add-repo")throw Error("Run this command from a release package. Use bunx @apptoolkit/harness@latest update for an installed workspace.");let u=Y(o),p=t==="install"&&!u?await Nh(e):jh(o),l;if(t==="update"&&s["enable-service"]){let g=_(Re).parse(s["enable-service"]);p.services=[...new Set([...p.services,...g])]}if(t==="add-repo"){l=K(r,"the checkout path");let g=Uo(o,l),y=p.repositories.find(({path:k})=>Uo(o,k)===g),v=s["repo-versioned"]||(s["repo-local"]?!1:y?.versioned??await Bo(c,`Version files generated inside ${l}?`,"--repo-local or --repo-versioned"));p.repositories=[...p.repositories.filter(({path:k})=>Uo(o,k)!==g),{path:l,versioned:v}]}let f=Bu({root:o,action:t,version:n,contentDirectory:a??"",...p,...l?{repository:l}:{}}),d={action:t,root:f.root,writes:f.writes.map(({path:g,before:y,after:v})=>({path:g,effect:v===null?"remove":y===null?"create":"update",before:y,after:v})),conflicts:f.conflicts,notices:f.notices};if(!s.json)for(let g of qu(f,u,l))i(g);if(s.plan||!s.yes&&!c){if(s.json)i(d);return f.conflicts.length?1:0}if(f.conflicts.length){if(s.json)i(d);throw Error("Resolve the reported installation conflicts before applying the plan.")}if(!s.yes&&f.writes.length&&c&&await c("Apply this plan?",Xu)!=="yes")return 0;let m=xo(f);if(s.json)i({...d,changed:m.changed,version:m.receipt.version,hosts:m.receipt.hosts});else if(i(`Applied ${m.changed} change(s) for @apptoolkit/harness ${m.receipt.version}.`),t==="install"){i(`Open ${f.root} in your selected agent host.`);for(let g of m.receipt.hosts)i(` ${yt[g]}: ${g==="codex"?"$":"/"}apptoolkit init`)}return 0}var Fh=`@apptoolkit/harness 1.0.2
78
78
 
79
79
  install Inspect and prepare a project or workspace
80
80
  inspect Report workspace topology and installation state
@@ -97,8 +97,8 @@ Install options: --hosts codex,claude,opencode --local | --versioned
97
97
  Add options: --repo-local | --repo-versioned
98
98
  Service options: --project <repo> --verify-health --verify-read --manifest <file> | --file <export>
99
99
  Use --plan to preview. Noninteractive workspace changes require --yes and explicit choices.
100
- `;function Ph(e,t){if(t==="list")return lt(e,"llm/harness/WORKFLOWS.md");let r=w().regex(/^W(?:0[1-9]|[12][0-9]|3[0-7])$/,"Choose W01 through W37 or list.").parse(t??""),o=lt(e,`llm/harness/workflows/${r}.md`);if(Buffer.byteLength(o)>32768)throw Error(`Workflow ${r} is larger than 32 KiB. Use context to read a section.`);return o}async function Eh(){let{values:e,positionals:t}=Wu(process.argv.slice(2)),[r,o,n,i]=t;if(e.version)return process.stdout.write(`1.0.1
101
- `),0;if(e.help||!r)return process.stdout.write(Sh),0;let s=tr(e.root??zh(new URL("../../../",import.meta.url))),c=(y)=>{if(typeof y==="string")process.stdout.write(`${y.trimEnd()}
100
+ `;function Lh(e,t){if(t==="list")return ft(e,"llm/harness/WORKFLOWS.md");let r=w().regex(/^W(?:0[1-9]|[12][0-9]|3[0-7])$/,"Choose W01 through W37 or list.").parse(t??""),o=ft(e,`llm/harness/workflows/${r}.md`);if(Buffer.byteLength(o)>32768)throw Error(`Workflow ${r} is larger than 32 KiB. Use context to read a section.`);return o}async function Mh(){let{values:e,positionals:t}=Ju(process.argv.slice(2)),[r,o,n,s]=t;if(e.version)return process.stdout.write(`1.0.2
101
+ `),0;if(e.help||!r)return process.stdout.write(Fh),0;let i=sr(e.root??Dh(new URL("../../../",import.meta.url))),c=(y)=>{if(typeof y==="string")process.stdout.write(`${y.trimEnd()}
102
102
  `);else process.stdout.write(`${JSON.stringify(y,null,2)}
103
- `)};if(r==="inspect"&&!o){let y=Ze(s),v=Y(y.root),G=(v?Ee(y.root):void 0)?.projects.map(({path:z,budget:I,services:S})=>({path:z,budget:I.mode,services:S.map(({provider:q})=>q)}))??[];return c({...y,installation:v??null,configuredProjects:G}),0}if(r==="init"&&!o){if(!e.config)return c(await _o(s)),0;if(e.plan)throw Error("Use init without --config to read the setup template. Applying a configuration requires a separate invocation.");return c(await bo({root:s,configPath:tr(e.config)})),0}if(r==="workflow"&&!n){let y=Ph(s,o);return c(e.json?{id:o,document:y}:y),0}if(r==="context"&&!n){let y=K(o,"the workspace-relative Markdown path");return c(mu({root:s,file:y,...e.section?{section:e.section}:{}})),0}if(r==="verify"&&o==="document"&&!i){let y=tr(K(e.config,"--config <policy.json>")),v=tr(K(n,"the document path")),k=Vu(y,v);return c(k),k.valid?0:1}if(r==="verify"&&o==="coverage"&&!i){let y=K(n,"the workspace-relative LCOV report"),v=K(e.config,"--config <coverage-policy.json>");return c(bu({root:s,file:y,config:v})),0}if(r==="protect"&&!n){let y=K(e.project,"--project <repo>"),v=K(o,"the repository-relative source map path"),k=jo({root:s,repository:y,file:v});if(e.yes&&!k.conflicts.length)c({...k,...Do(k)});else c(k);return k.conflicts.length?1:0}if(r==="service"&&o==="status"&&!i){let y=Oe.parse(n),v=K(e.project,"--project <repo>");return c(await zo({root:s,service:y,project:v,verifyRead:e["verify-read"]??!1,verifyHealth:e["verify-health"]??!1})),0}if(r==="service"&&o==="snapshot"&&!i){let y=Oe.parse(n),v=K(e.project,"--project <repo>"),k=e.file??[];if(k.length&&e.manifest)throw Error("Choose --file to prepare a manifest or --manifest to verify it.");if(k.length)c(await So({root:s,service:y,project:v,paths:k}));else{let G=K(e.manifest,"--manifest <snapshot.json>");c(await Po({root:s,service:y,project:v,manifestPath:G}))}return 0}let a=r==="add"&&o==="repo"&&!i,u=r==="install"&&!o;if(!a&&!u&&!(r==="update"&&!o))throw Error("Unknown command or arguments. Run with --help for usage.");let l=process.stdin.isTTY&&!e.json&&!e.plan&&!e.yes,f=void 0,d={root:s,version:"1.0.1",options:e,emit:c},g={},m=f?{select:f.selectChoice}:{};return Ku({...d,...g,...m},a?"add-repo":u?"install":"update",n)}try{process.exitCode=await Eh()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`apptoolkit: ${t}
103
+ `)};if(r==="inspect"&&!o){let y=Ze(i),v=Y(y.root),G=(v?Ee(y.root):void 0)?.projects.map(({path:z,budget:I,services:S})=>({path:z,budget:I.mode,services:S.map(({provider:q})=>q)}))??[];return c({...y,installation:v??null,configuredProjects:G}),0}if(r==="init"&&!o){if(!e.config)return c(await zo(i)),0;if(e.plan)throw Error("Use init without --config to read the setup template. Applying a configuration requires a separate invocation.");return c(await So({root:i,configPath:sr(e.config)})),0}if(r==="workflow"&&!n){let y=Lh(i,o);return c(e.json?{id:o,document:y}:y),0}if(r==="context"&&!n){let y=K(o,"the workspace-relative Markdown path");return c(xu({root:i,file:y,...e.section?{section:e.section}:{}})),0}if(r==="verify"&&o==="document"&&!s){let y=sr(K(e.config,"--config <policy.json>")),v=sr(K(n,"the document path")),k=Ku(y,v);return c(k),k.valid?0:1}if(r==="verify"&&o==="coverage"&&!s){let y=K(n,"the workspace-relative LCOV report"),v=K(e.config,"--config <coverage-policy.json>");return c(zu({root:i,file:y,config:v})),0}if(r==="protect"&&!n){let y=K(e.project,"--project <repo>"),v=K(o,"the repository-relative source map path"),k=Mo({root:i,repository:y,file:v});if(e.yes&&!k.conflicts.length)c({...k,...Wo(k)});else c(k);return k.conflicts.length?1:0}if(r==="service"&&o==="status"&&!s){let y=Re.parse(n),v=K(e.project,"--project <repo>");return c(await Zo({root:i,service:y,project:v,verifyRead:e["verify-read"]??!1,verifyHealth:e["verify-health"]??!1})),0}if(r==="service"&&o==="snapshot"&&!s){let y=Re.parse(n),v=K(e.project,"--project <repo>"),k=e.file??[];if(k.length&&e.manifest)throw Error("Choose --file to prepare a manifest or --manifest to verify it.");if(k.length)c(await Oo({root:i,service:y,project:v,paths:k}));else{let G=K(e.manifest,"--manifest <snapshot.json>");c(await Ro({root:i,service:y,project:v,manifestPath:G}))}return 0}let a=r==="add"&&o==="repo"&&!s,u=r==="install"&&!o;if(!a&&!u&&!(r==="update"&&!o))throw Error("Unknown command or arguments. Run with --help for usage.");let l=process.stdin.isTTY&&!e.json&&!e.plan&&!e.yes,f=void 0,d={root:i,version:"1.0.2",options:e,emit:c},m={},g=f?{select:f.selectChoice,selectMany:f.selectMany}:{};return Yu({...d,...m,...g},a?"add-repo":u?"install":"update",n)}try{process.exitCode=await Mh()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`apptoolkit: ${t}
104
104
  `),process.exitCode=1}