@apptoolkit/harness 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -47
  3. package/harness.js +123 -0
  4. package/package.json +85 -24
  5. package/payload/HARNESS.md +28 -0
  6. package/payload/author-style/README.md +58 -0
  7. package/payload/author-style/biome-core.json +57 -0
  8. package/payload/author-style/biome-react.json +9 -0
  9. package/payload/author-style/biome-sql.json +9 -0
  10. package/payload/author-style/bun.lock +37 -0
  11. package/payload/author-style/check.llm.md +17 -0
  12. package/payload/author-style/check.test.llm.md +17 -0
  13. package/payload/author-style/check.test.ts +264 -0
  14. package/payload/author-style/check.ts +200 -0
  15. package/payload/author-style/member-spacing.test.ts +172 -0
  16. package/payload/author-style/member-spacing.ts +106 -0
  17. package/payload/author-style/package.json +18 -0
  18. package/payload/author-style/plugins/class-member-order.grit +133 -0
  19. package/payload/author-style/plugins/event-handler-names.grit +110 -0
  20. package/payload/author-style/plugins/explicit-arrow-body.grit +15 -0
  21. package/payload/author-style/plugins/explicit-source-constructs.grit +10 -0
  22. package/payload/author-style/plugins/react-arrow-body.grit +85 -0
  23. package/payload/author-style/plugins/sql-style.grit +125 -0
  24. package/payload/author-style/react-module.llm.md +17 -0
  25. package/payload/author-style/react-module.test.ts +150 -0
  26. package/payload/author-style/react-module.ts +255 -0
  27. package/payload/author-style/source-policy.llm.md +17 -0
  28. package/payload/author-style/source-policy.test.ts +82 -0
  29. package/payload/author-style/source-policy.ts +238 -0
  30. package/payload/author-style/spacing.llm.md +17 -0
  31. package/payload/author-style/spacing.test.ts +174 -0
  32. package/payload/author-style/spacing.ts +211 -0
  33. package/payload/harness/LEARNING.md +18 -0
  34. package/payload/harness/POLICY.md +35 -0
  35. package/payload/harness/PROJECT.md +26 -0
  36. package/payload/harness/REVIEW.md +17 -0
  37. package/payload/harness/TEMPLATES.md +20 -0
  38. package/payload/harness/WORKFLOWS.md +65 -0
  39. package/payload/harness/runtime/ZOD-LICENSE +21 -0
  40. package/payload/harness/runtime/harness.mjs +123 -0
  41. package/payload/harness/services/README.md +26 -0
  42. package/payload/harness/services/penpot.json +7 -0
  43. package/payload/harness/services/plane.json +9 -0
  44. package/payload/harness/workflows/W01.md +13 -0
  45. package/payload/harness/workflows/W02.md +13 -0
  46. package/payload/harness/workflows/W03.md +13 -0
  47. package/payload/harness/workflows/W04.md +13 -0
  48. package/payload/harness/workflows/W05.md +13 -0
  49. package/payload/harness/workflows/W06.md +13 -0
  50. package/payload/harness/workflows/W07.md +13 -0
  51. package/payload/harness/workflows/W08.md +13 -0
  52. package/payload/harness/workflows/W09.md +13 -0
  53. package/payload/harness/workflows/W10.md +13 -0
  54. package/payload/harness/workflows/W11.md +13 -0
  55. package/payload/harness/workflows/W12.md +13 -0
  56. package/payload/harness/workflows/W13.md +13 -0
  57. package/payload/harness/workflows/W14.md +13 -0
  58. package/payload/harness/workflows/W15.md +13 -0
  59. package/payload/harness/workflows/W16.md +13 -0
  60. package/payload/harness/workflows/W17.md +13 -0
  61. package/payload/harness/workflows/W18.md +13 -0
  62. package/payload/harness/workflows/W19.md +13 -0
  63. package/payload/harness/workflows/W20.md +27 -0
  64. package/payload/harness/workflows/W21.md +19 -0
  65. package/payload/harness/workflows/W22.md +13 -0
  66. package/payload/harness/workflows/W23.md +21 -0
  67. package/payload/harness/workflows/W24.md +13 -0
  68. package/payload/harness/workflows/W25.md +13 -0
  69. package/payload/harness/workflows/W26.md +13 -0
  70. package/payload/harness/workflows/W27.md +13 -0
  71. package/payload/harness/workflows/W28.md +13 -0
  72. package/payload/harness/workflows/W29.md +13 -0
  73. package/payload/harness/workflows/W30.md +13 -0
  74. package/payload/harness/workflows/W31.md +13 -0
  75. package/payload/harness/workflows/W32.md +13 -0
  76. package/payload/harness/workflows/W33.md +13 -0
  77. package/payload/harness/workflows/W34.md +13 -0
  78. package/payload/harness/workflows/W35.md +13 -0
  79. package/payload/harness/workflows/W36.md +13 -0
  80. package/payload/harness/workflows/W37.md +13 -0
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ var _p=Object.defineProperty;var kp=(e)=>e;function $p(e,t){this[e]=kp.bind(null,t)}var Sp=(e,t)=>{for(var r in t)_p(e,r,{get:t[r],enumerable:!0,configurable:!0,set:$p.bind(t,r)})};import{resolve as wr}from"node:path";import{fileURLToPath as vm}from"node:url";function it(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 _r(e,t="|"){return e.map((r)=>Sr(r)).join(t)}function ct(e,t){if(typeof t==="bigint")return t.toString();return t}class nn{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 at(e){return new nn(e)}function sn(e){return e===null||e===void 0}function Rt(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function cn(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}var on=Symbol("evaluating");function an(e,t,r){let o=void 0;Object.defineProperty(e,t,{get(){if(o===on)return;if(o===void 0)o=on,o=r();return o},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Q(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function ut(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function le(e){return ut(e._zod.def)??e._zod.def.shape}function un(e,t,r){Object.defineProperty(e,t,{get(){let o=r();return Q(this,t,o),o},enumerable:!0,configurable:!0})}function pn(e,t,r){if(t in e)Q(e,t,r);else e[t]=r}function Oe(e,t,r,o){let n=le(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(n,s);if(!i.enumerable)continue;if(i.get)un(e,s,()=>{let c=t._zod.def.shape[s];return o?o(c,s):c});else pn(e,s,o?o(i.value,s):i.value)}}function zp(e,t){for(let r of Reflect.ownKeys(t)){let o=Object.getOwnPropertyDescriptor(t,r);if(!o.enumerable)continue;if(o.get)un(e,r,()=>t[r]);else pn(e,r,o.value)}}function q(...e){let t={};for(let r of e){let o=Object.getOwnPropertyDescriptors(r);Object.assign(t,o)}return Object.defineProperties({},t)}function ln(e){return JSON.stringify(e)}function fn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var kr="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Ve(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var dn=at(()=>{if(H.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Ze(e){if(Ve(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(Ve(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function $r(e){if(Ze(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 hn=new Set(["string","number","symbol"]);function _e(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 v(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 Sr(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function mn(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Ct=(()=>({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]}))(),zr={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Pp(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 Oe(s,e,At(e,t)),ne(e,q(r,{shape:s,checks:[]}))}function At(e,t){let r=le(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 Ep(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(At(e,t)),i={};return Oe(i,e,Reflect.ownKeys(le(e)).filter((c)=>!s.has(c))),ne(e,q(r,{shape:i,checks:[]}))}function Op(e,t){if(!Ze(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let n=le(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,q(e._zod.def,{shape:gn(e,t)}))}function gn(e,t){let r={};return Oe(r,e,Reflect.ownKeys(le(e))),zp(r,t),r}function Zp(e,t){if(!Ze(t))throw Error("Invalid input to safeExtend: expected a plain object");return ne(e,q(e._zod.def,{shape:gn(e,t)}))}function Rp(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={};Oe(r,e,Reflect.ownKeys(le(e))),Oe(r,t,Reflect.ownKeys(le(t)));let o=q(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return ne(e,o)}function yn(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(At(t,r)):void 0,a={};return Oe(a,t,Reflect.ownKeys(le(t)),e&&((u,p)=>c&&!c.has(p)?u:new e({type:"optional",innerType:u}))),ne(t,q(t._zod.def,{shape:a,checks:[]}))}function Cp(e,t,r){let o=r?new Set(At(t,r)):void 0,n={};return Oe(n,t,Reflect.ownKeys(le(t)),(s,i)=>o&&!o.has(i)?s:new e({type:"nonoptional",innerType:s})),ne(t,q(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 xn(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 ke(e,t){return t.map((r)=>{var o;return(o=r).path??(o.path=[]),r.path.unshift(e),r})}function st(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 It(e,t,r){var o;for(let n=t;n<e.length;n++)(o=e[n]).schema??(o.schema=r)}function ie(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:st(e.inst?._zod.def?.error?.(e))??st(s?.(e))??st(t?.error?.(e))??st(r.customError?.(e))??st(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 Ap=/[\uD800-\uDBFF]/;function jt(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 Nt(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function vn(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 Re(...e){let[t,r,o]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:o};return{...t}}function wn(e,t){for(let r in t){let o=Object.getOwnPropertyDescriptor(t,r);if(o.get)Object.defineProperty(e,r,{...o,enumerable:!1});else Ip(e,r,o.value)}}function fe(e,t,r,o=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:o,value:r}),r}function Tt(e,t,r){return fe(e,t,r,!1)}function Dt(e,t){for(let r in e){let o=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return fe(this,r,o(this))},set(n){fe(this,r,n)}})}return t}function Ip(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:fe(this,t,r.bind(this))},set(o){fe(this,t,o)}})}function jp(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var br,be=!1,Np={configurable:!0,get(){be=!0;return}};function E(e,t,r){let o=Object.getPrototypeOf(e._zod);if(t in o&&br!==e._zod){br=void 0;return}br=e._zod,Object.defineProperty(o,t,{configurable:!0,get(){Object.defineProperty(this,t,Np);let n=be;be=!1;try{let s=r(this);if(be)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return be=be||n,s}catch(s){throw delete this[t],be=be||n,s}},set(n){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:n})}})}function Tp(e,t,r,o){let n=jp(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 Dp="~constantCatch";function bn(e){let t=()=>e;return t[Dp]=!0,t}var _n;var Er={value:void 0,enumerable:!1},kn="captureStackTrace"in Error?Error:null;function Fp(e){let t=kn;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return kn=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function m(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,h){if(!f._zod){Er.value=new s(h);try{Object.defineProperty(f,"_zod",Er)}finally{Er.value=void 0}}else if(f._zod.traits.has(e))return;if(f._zod.traits.add(e),t(f,h),c){let g=Object.getPrototypeOf(f),y=f._zod.constr.prototype,x=g;while(x&&x!==y)x=Object.getPrototypeOf(x);let w=x??g;if(!c.has(w))c.add(w),wn(w,i)}let d=l.prototype;for(let g in d){if(!Object.prototype.hasOwnProperty.call(d,g))continue;if(!(g in f))f[g]=d[g].bind(f)}}let u=o?.Parent??Object;class p extends u{}Object.defineProperty(p,"name",{value:e});function l(f){let h=o?.Parent?Fp(p):this;a(h,f);let d=h._zod.deferred;if(d){for(let y of d)y();h._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;if(g)g(h);return h}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 ce extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class pt extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(_n=globalThis).__zod_globalConfig??(_n.__zod_globalConfig={});var H=globalThis.__zod_globalConfig;function X(e){if(e)Object.assign(H,e);return H}function Lp(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,ct,2)),e.message}function Mp(e){this._zod.message=e}var Wp={get:Lp,set:Mp,enumerable:!0,configurable:!0},Zr={value:void 0,enumerable:!1},$n=new WeakSet([Object.prototype,Error.prototype]),Sn=(e,t)=>{e.name="$ZodError",Zr.value=t,Object.defineProperty(e,"issues",Zr),Zr.value=void 0,Object.defineProperty(e,"message",Wp);let r=Object.getPrototypeOf(e);if(!$n.has(r))$n.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})}})},zn=m("$ZodError",Sn),Pm=m("$ZodError",Sn,void 0,{Parent:Error});function Up(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 Pn(e,t=(r)=>r.message){let r={},o=[];for(let n of e.issues)if(n.path.length>0)Up(r,n.path[0],()=>[]).push(t(n));else o.push(t(n));return{formErrors:o,fieldErrors:r}}function En(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 Ft(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Lt=(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 ce;if(c.issues.length){let a=new(s?.Err??e)(c.issues.map((u)=>ie(u,i,X())));throw kr(a,s?.callee??t),a}return c.value};return t};var Mt=(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)=>ie(u,i,X())));throw kr(a,s?.callee??t),a}return c.value};return t};var Wt=(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 ce;return s.issues.length?On(e,s.issues,n):{success:!0,data:s.value}};function On(e,t,r){let o;return{success:!1,get error(){if(!o)o=new e(t.map((n)=>ie(n,r,X()))),t=void 0,r=void 0;return o},set error(n){o=n,t=void 0,r=void 0}}}var Ut=(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?On(e,s.issues,n):{success:!0,data:s.value}};var Bp=Symbol.for("zod.compile.invalid"),Vp=Symbol.for("zod.compile.fallback"),Rr=(e,t,r)=>{let o=e._zod.bag.validator;if(o!==void 0){if(o(t)!==Bp)return!0;if(o.definite===!0&&r===void 0)return!1}return Jp(e,t,r)};function Jp(e,t,r){let o=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},n=e._zod.bag.fallbackRun,s;if(n)o[Vp]=!0,s=n({value:t,issues:[]},o);else s=e._zod.run({value:t,issues:[]},o);if(s instanceof Promise)throw new ce;return s.issues.length===0}var Cr=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},Zn=(e)=>{let t=Lt(e),r=(o,n,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return t(o,n,c,Ft(r,i))};return r};var Rn=(e)=>{let t=Lt(e),r=(o,n,s,i)=>t(o,n,s,Ft(r,i));return r};var Cn=(e)=>{let t=Mt(e),r=async(o,n,s,i)=>{let c=s?{...s,direction:"backward"}:{direction:"backward"};return await t(o,n,c,Ft(r,i))};return r};var An=(e)=>{let t=Mt(e),r=async(o,n,s,i)=>await t(o,n,s,Ft(r,i));return r};var In=(e)=>(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Wt(e)(t,r,n)};var jn=(e)=>(t,r,o)=>Wt(e)(t,r,o);var Nn=(e)=>async(t,r,o)=>{let n=o?{...o,direction:"backward"}:{direction:"backward"};return Ut(e)(t,r,n)};var Tn=(e)=>async(t,r,o)=>Ut(e)(t,r,o);var Dn=/^[cC][0-9a-z]{6,}$/,Fn=/^[0-9a-z]+$/,Ln=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Mn=/^[0-9a-vA-V]{20}$/,Wn=/^[A-Za-z0-9]{27}$/,Un=/^[a-zA-Z0-9_-]{21}$/;function Bn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var Vn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Jn=/^([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})$/,Ir=(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 Hn=/^(?:[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 Hp="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Kn(){return new RegExp(Hp,"u")}var Gn=/^(?:(?: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])$/,qn=/^(([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 Xn=/^((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])$/,Yn=/^(([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])$/,Qn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,es=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var ts=/^https?$/,rs=/^\+[1-9]\d{6,14}$/;var os="(?:(?:\\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 ns=Kp(os);function Ar(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 ss(e){return new RegExp(`^${Ar(e)}$`)}function is(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Ar({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,o=e.local?`${r}|${Ar({precision:e.precision})}`:r;return new RegExp(`^${os}T(?:${o})$`)}var cs=/^[\s\S]{0,}$/;var as=/^-?\d+n?$/,jr=/^-?\d+$/,lt=/^-?\d+(?:\.\d+)?$/,us=/^(?:true|false)$/i,ps=/^null$/i;var ls=/^[^A-Z]*$/,fs=/^[^a-z]*$/;var F=m("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Nr=(e)=>{let t=e.value;return!sn(t)&&t.length!==void 0},Bt={number:"number",bigint:"bigint",object:"date"},Tr=m("$ZodCheckLessThan",(e,t)=>{F.init(e,t);let r=Bt[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value<=t.value:o.value<t.value)return;o.issues.push({origin:Bt[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})}}),Dr=m("$ZodCheckGreaterThan",(e,t)=>{F.init(e,t);let r=Bt[typeof t.value];e._zod.check=(o)=>{if(t.inclusive?o.value>=t.value:o.value>t.value)return;o.issues.push({origin:Bt[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})}}),ds=m("$ZodCheckMultipleOf",(e,t)=>{F.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):cn(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})}}),hs=m("$ZodCheckNumberFormat",(e,t)=>{F.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),o=r?"int":"number",[n,s]=Ct[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 ms=m("$ZodCheckMaxLength",(e,t)=>{var r;F.init(e,t),(r=e._zod.def).when??(r.when=Nr),e._zod.check=(o)=>{let n=o.value,s=n.length;if((typeof n==="string"&&s>t.maximum?jt(n):s)<=t.maximum)return;let c=Nt(n);o.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),gs=m("$ZodCheckMinLength",(e,t)=>{var r;F.init(e,t),(r=e._zod.def).when??(r.when=Nr),e._zod.check=(o)=>{let n=o.value,s=n.length;if((typeof n==="string"&&s>=t.minimum&&s<t.minimum*2?jt(n):s)>=t.minimum)return;let c=Nt(n);o.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:n,inst:e,continue:!t.abort})}}),ys=m("$ZodCheckLengthEquals",(e,t)=>{var r;F.init(e,t),(r=e._zod.def).when??(r.when=Nr),e._zod.check=(o)=>{let n=o.value,s=n.length,i=typeof n==="string"&&s>=t.length&&s<=t.length*2?jt(n):s;if(i===t.length)return;let c=Nt(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})}}),dt=m("$ZodCheckStringFormat",(e,t)=>{var r,o;if(F.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=()=>{})}),xs=m("$ZodCheckRegex",(e,t)=>{dt.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})}}),vs=m("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ls),dt.init(e,t)}),ws=m("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=fs),dt.init(e,t)}),bs=m("$ZodCheckIncludes",(e,t)=>{F.init(e,t);let r=_e(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})}}),_s=m("$ZodCheckStartsWith",(e,t)=>{F.init(e,t);let r=new RegExp(`^${_e(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})}}),ks=m("$ZodCheckEndsWith",(e,t)=>{F.init(e,t);let r=new RegExp(`.*${_e(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 $s=m("$ZodCheckOverwrite",(e,t)=>{F.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Fr{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
+ ${t.join(`
5
+ `)}
6
+ };`)(...Object.values(this.closed))}}var zs={major:4,minor:6,patch:7};var Z=m("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=zs;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(xn(c))continue;if(!f._zod.def.when(c))continue}else if(p)continue;let h=c.issues.length,d=f._zod.check(c);if(d instanceof Promise&&u?.async===!1)throw new ce;if(l||d instanceof Promise)l=(l??Promise.resolve()).then(async()=>{if(await d,c.issues.length===h)return;if(It(c.issues,h,e),!p)p=se(c,h)});else{if(c.issues.length===h)continue;if(It(c.issues,h,e),!p)p=se(c,h)}}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 ce;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 ce;return u.then((p)=>s(p,n,a))}return s(u,n,a)}}},{get "~standard"(){return Tt(this,"~standard",Mr(this))},set "~standard"(e){fe(this,"~standard",e)}}),Ts=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>ie(r,t,X()))}:{value:e.value};async function Gp(e,t){let r={async:!0};return Ts(await e._zod.run({value:t,issues:[]},r),r)}function Mr(e){return{validate:(t)=>{let r={async:!1};try{let o=e._zod.run({value:t,issues:[]},r);if(!(o instanceof Promise))return Ts(o,r)}catch(o){}return Gp(e,t)},vendor:"zod",version:1}}var Kt=m("$ZodString",(e,t)=>{Z.init(e,t),e._zod.pattern=t.pattern??cs,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}}),A=m("$ZodStringFormat",(e,t)=>{dt.init(e,t),Kt.init(e,t)}),Ds=m("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Jn),A.init(e,t)}),Fs=m("$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=Ir(o))}else t.pattern??(t.pattern=Ir());A.init(e,t)}),Ls=m("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Hn),A.init(e,t)}),Ms=1,Jt=2;function Ws(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function qp(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return Ws(e)||Jt;return Xp(e,t)}function Xp(e,t){if(!t.normalize&&t.protocol?.source===ts.source&&!/^https?:\/\//i.test(e))return Ms;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Jt}return new URL(e)}catch{return Jt}}var Yp=/[\t\n\r]/g;function Ps(e){return e.replace(Yp,"")}function Qp(e,t){return t.lastIndex=0,t.test(e.hostname)}function el(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var Us=m("$ZodURL",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{try{let o=r.value.trim(),n=qp(o,t);if(n===Ms){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(n===Jt){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(n===!0){r.value=Ps(o);return}if(t.hostname&&!Qp(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&&!el(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:Ps(o);return}catch(o){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),Bs=m("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Kn()),A.init(e,t)}),Vs=m("$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?Un:Bn(t.length)),A.init(e,t)}),Js=m("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Dn),A.init(e,t)}),Hs=m("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Fn),A.init(e,t)}),Ks=m("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Ln),A.init(e,t)}),Gs=m("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Mn),A.init(e,t)}),qs=m("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Wn),A.init(e,t)}),Xs=m("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=is(t)),A.init(e,t)}),Ys=m("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=ns),A.init(e,t)}),Qs=m("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=ss(t)),A.init(e,t)}),ei=m("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Vn),A.init(e,t)}),ti=m("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Gn),A.init(e,t)}),tl=/^[0-9a-fA-F:.]+$/;function ri(e){if(!tl.test(e))return!1;return Ws(`http://[${e}]`)}var oi=m("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=qn),A.init(e,t),e._zod.check=(r)=>{if(!ri(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var ni=m("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Xn),A.init(e,t)});function rl(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 ri(r)}var si=m("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Yn),A.init(e,t),e._zod.check=(r)=>{if(!rl(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function ii(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 Wr=/^[0-9a-zA-Z+/]*={0,2}$/,ci=m("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Wr),A.init(e,t),e._zod.check=(r)=>{if(ii(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),Gt=/^[A-Za-z0-9_-]*$/;function ol(e){if(!Gt.test(e))return!1;let t=e.replace(/[-_]/g,(o)=>o==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return ii(r)}var ai=m("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Gt),A.init(e,t),e._zod.check=(r)=>{if(ol(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),ui=m("$ZodE164",(e,t)=>{t.pattern??(t.pattern=rs),A.init(e,t)});function nl(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 pi=m("$ZodJWT",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{if(nl(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var Ur=m("$ZodNumber",(e,t)=>{Z.init(e,t),e._zod.pattern=lt,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}}),li=m("$ZodNumberFormat",(e,t)=>{hs.init(e,t),Ur.init(e,t)}),fi=m("$ZodBoolean",(e,t)=>{Z.init(e,t),e._zod.pattern=us,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}}),di=m("$ZodBigInt",(e,t)=>{Z.init(e,t),e._zod.pattern=as,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 hi=m("$ZodNull",(e,t)=>{Z.init(e,t),e._zod.pattern=ps,e._zod.values=new Set([null]),e._zod.parse=(r,o)=>{let n=r.value;if(n===null)return r;return r.issues.push({expected:"null",code:"invalid_type",input:n,inst:e}),r}});var mi=m("$ZodUnknown",(e,t)=>{Z.init(e,t),e._zod.parse=(r)=>r}),gi=m("$ZodNever",(e,t)=>{Z.init(e,t),e._zod.parse=(r,o)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});var yi=m("$ZodDate",(e,t)=>{Z.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 sl(e,t){let r=Pr(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 Pr(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,It(s.issues,p,e),s}}return n(s,i)}}var il=(e)=>Array.isArray(e)?e.length:-1;function Es(e,t,r){if(e.issues.length)t.issues.push(...ke(r,e.issues));t.value[r]=e.value}var xi=m("$ZodArray",(e,t)=>{Z.init(e,t);let r=H.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)=>Es(l,o,a)));else if(Es(p,o,a),c&&p.issues.length!==0&&se(p))break}if(i.length)return Promise.all(i).then(()=>o);return o},sl(e,il)});function Ht(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(...ke(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 cl=[];function vi(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),o=r.length?r:cl,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=mn(e.shape);return{...e,allKeys:n,symbolKeys:o,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(s)}}function wi(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,h=0;for(let d in t){if(i&&r.issues.length!==h){if(se(r,h))break;h=r.issues.length}if(a.has(d))continue;if(d==="__proto__"){if(p==="never")c.push(d);continue}if(p==="never"){c.push(d);continue}let g=u.run({value:t[d],issues:[]},o);if(g instanceof Promise)e.push(g.then((y)=>Ht(y,r,d,t,l,f)));else Ht(g,r,d,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 al=m("$ZodObject",(e,t)=>{Z.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=at(()=>vi(t));E(e,"propValues",(u)=>{let p=u.def.shape,l={};for(let f in p){let h=p[f]._zod;if(h.values){if(!Object.prototype.hasOwnProperty.call(l,f))Q(l,f,new Set);for(let d of h.values)l[f].add(d);if(h.optin!==void 0)l[f].add(void 0)}}return l});let s=Ve,i=t.catchall,c,a=H.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=[],h=c.shape,d=p?.abortEarly,g=u.issues.length;for(let y of c.allKeys){if(d&&u.issues.length!==g){if(se(u,g))break;g=u.issues.length}if(y==="__proto__")continue;let x=h[y],w=x._zod.optin,S=x._zod.optout,I=x._zod.run({value:l[y],issues:[]},p);if(I instanceof Promise)f.push(I.then((b)=>Ht(b,u,y,l,w,S)));else Ht(I,u,y,l,w,S)}if(!i)return f.length?Promise.all(f).then(()=>u):u;return wi(f,l,u,p,n.value,e,d===!0)}}),bi=m("$ZodObjectJIT",(e,t)=>{al.init(e,t);let r=e._zod.parse,o=at(()=>vi(t)),n=H.memoizer,s=(h)=>{let d=o.value,g=d.symbolKeys,y=new Fr(["payload","ctx"],{shape:h,inst:e,memo:n,syms:g}),x=(b)=>`shape[${b}]._zod.run({ value: input[${b}], issues: [] }, ctx)`,w=(b,z)=>`
7
+ let ${b}_ab = false;
8
+ for (let i = 0; i < ${b}.issues.length; i++) {
9
+ const iss = ${b}.issues[i];
10
+ iss.path = iss.path ? [${z}, ...iss.path] : [${z}];
11
+ payload.issues.push(iss);
12
+ if (iss.continue !== true) ${b}_ab = true;
13
+ }
14
+ if (${b}_ab && ctx && ctx.abortEarly) {
15
+ payload.value = newResult;
16
+ return payload;
17
+ }`;y.write("const input = payload.value;");let S=Object.create(null),I=0;for(let b of d.allKeys)S[b]=`key_${I++}`;y.write(n?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(let b of d.allKeys){if(b==="__proto__")continue;let z=S[b],_=typeof b==="symbol"?`syms[${g.indexOf(b)}]`:ln(b),Ue=`${_} in input`,pe=h[b],Be=pe?._zod?.optin,rn=Be!==void 0,wp=pe?._zod?.optout==="optional";if(y.write(`const ${z} = ${x(_)};`),rn&&wp){let bp=Be==="optional"?`${z}_present`:`${z}.value !== undefined || ${z}_present`;y.write(`
18
+ const ${z}_present = ${Ue};
19
+ if (!${z}.issues.length || ${z}_present) {
20
+ if (${z}.issues.length) {${w(z,_)}
21
+ }
22
+
23
+ if (${bp}) {
24
+ newResult[${_}] = ${z}.value;
25
+ }
26
+ }
27
+
28
+ `)}else if(!rn)y.write(`
29
+ const ${z}_present = ${Ue};
30
+ if (${z}.issues.length) {${w(z,_)}
31
+ }
32
+ if (!${z}_present && !${z}.issues.length) {
33
+ payload.issues.push({
34
+ code: "invalid_type",
35
+ expected: "nonoptional",
36
+ input: undefined,
37
+ path: [${_}]
38
+ });
39
+ if (ctx && ctx.abortEarly) {
40
+ payload.value = newResult;
41
+ return payload;
42
+ }
43
+ }
44
+
45
+ if (${z}_present) {
46
+ newResult[${_}] = ${z}.value;
47
+ }
48
+
49
+ `);else if(y.write(`
50
+ if (${z}.issues.length) {${w(z,_)}
51
+ }
52
+ `),Be==="defaulted")y.write(`newResult[${_}] = ${z}.value;`);else y.write(`
53
+ if (${z}.value !== undefined || ${Ue}) {
54
+ newResult[${_}] = ${z}.value;
55
+ }
56
+ `)}return y.write("payload.value = newResult;"),y.write("return payload;"),y.compile()},i,c=Ve,a=!H.jitless,p=a&&dn.value,l=t.catchall,f;e._zod.parse=(h,d)=>{f??(f=o.value);let g=h.value;if(!c(g))return h.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),h;if(a&&p&&d?.async===!1&&d.jitless!==!0){if(!i)i=s(t.shape);if(h=i(h,d),!l)return h;return wi([],g,h,d,f,e,d?.abortEarly===!0)}return r(h,d)}});function Os(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)=>ie(i,o,X())))}),t}var Br=m("$ZodUnion",(e,t)=>{Z.init(e,t),E(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),E(e,"optout",(o)=>o.def.options.some((n)=>n._zod.optout==="optional")?"optional":void 0),E(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}),E(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)=>Rt(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 Os(i,o,e,n);return Promise.all(i).then((c)=>Os(c,o,e,n))}});function ul(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 _i=m("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Br.init(e,t);let r=e._zod.parse;E(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=ut(n._zod.def);if(i&&!Object.prototype.hasOwnProperty.call(i,t.discriminator))throw Error(`Invalid discriminated union option at index "${s}"`)});let o=at(()=>ul(t));e._zod.parse=(n,s)=>{let i=n.value;if(!Ve(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}}),ki=m("$ZodIntersection",(e,t)=>{Z.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])=>Zs(r,a,u));return Zs(r,s,i)}});function Lr(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(Ze(e)&&Ze(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=Lr(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=Lr(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 Zs(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=Lr(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 $i=m("$ZodRecord",(e,t)=>{Z.init(e,t);let r=H.memoizer;r?.attach(e),e._zod.parse=(o,n)=>{let s=o.value;if(!Ze(s))return o.issues.push({expected:"record",code:"invalid_type",input:s,inst:e}),o;let i=[],c=t.keyType._zod.values;if(c&&!t.partial){o.value=r?r.alloc(e,o,{},n):{};let a=new Set;for(let p of c)if(typeof p==="string"||typeof p==="number"||typeof p==="symbol"){if(a.add(typeof p==="number"?p.toString():p),p==="__proto__")continue;let l=t.keyType._zod.run({value:p,issues:[]},n);if(l instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(l.issues.length){o.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map((d)=>ie(d,n,X())),input:p,path:[p],inst:e});continue}let f=l.value;if(f==="__proto__")continue;let h=t.valueType._zod.run({value:s[p],issues:[]},n);if(h instanceof Promise)i.push(h.then((d)=>{if(d.issues.length)o.issues.push(...ke(p,d.issues));o.value[f]=d.value}));else{if(h.issues.length)o.issues.push(...ke(p,h.issues));o.value[f]=h.value}}let u;for(let p in s)if(!a.has(p))if(t.mode==="loose"){if(p==="__proto__")continue;o.value[p]=s[p]}else u=u??[],u.push(p);if(u&&u.length>0)o.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:u,continue:!0})}else{o.value=r?r.alloc(e,o,{},n):{};let a;for(let u of Reflect.ownKeys(s)){if(u==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(s,u))continue;let p=t.keyType._zod.run({value:u,issues:[]},n);if(p instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof u==="string"&&lt.test(u)&&p.issues.length){let d=t.keyType._zod.run({value:Number(u),issues:[]},n);if(d instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(d.issues.length===0)p=d}if(p.issues.length){if(t.mode==="loose")o.value[u]=s[u];else if(c)a=a??[],a.push(u);else o.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map((d)=>ie(d,n,X())),input:u,path:[u],inst:e});continue}let f=p.value;if(f==="__proto__")continue;let h=t.valueType._zod.run({value:s[u],issues:[]},n);if(h instanceof Promise)i.push(h.then((d)=>{if(d.issues.length)o.issues.push(...ke(u,d.issues));o.value[f]=d.value}));else{if(h.issues.length)o.issues.push(...ke(u,h.issues));o.value[f]=h.value}}if(a&&a.length>0)o.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:a,continue:!0})}if(i.length)return Promise.all(i).then(()=>o);return o}});var Si=m("$ZodEnum",(e,t)=>{Z.init(e,t);let r=it(t.entries),o=new Set(r);e._zod.values=o,E(e,"pattern",(n)=>{let s=it(n.def.entries).filter((i)=>hn.has(typeof i));return new RegExp(s.length?`^(${s.map((i)=>_e(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}}),zi=m("$ZodLiteral",(e,t)=>{Z.init(e,t);let r=new Set(t.values);e._zod.values=r,E(e,"pattern",(o)=>{let n=o.def.values;return new RegExp(n.length?`^(${n.map((s)=>typeof s==="string"?_e(s):s?_e(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 Pi=m("$ZodTransform",(e,t)=>{Z.init(e,t),e._zod.optin="optional",H.memoizer?.guard(e),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new pt(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 ce;return r.value=n,r}});function Rs(e,t){return e.value=t.issues.length?void 0:t.value,e}var Vr=m("$ZodOptional",(e,t)=>{Z.init(e,t),E(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",E(e,"values",(r)=>{let o=r.def.innerType._zod.values;return o?new Set([...o,void 0]):void 0}),E(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${Rt(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)=>Rs(r,s));return Rs(r,n)}return t.innerType._zod.run(r,o)}}),Ei=m("$ZodExactOptional",(e,t)=>{Vr.init(e,t),E(e,"values",(r)=>r.def.innerType._zod.values),E(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,o)=>t.innerType._zod.run(r,o)}),Oi=m("$ZodNullable",(e,t)=>{Z.init(e,t),E(e,"optin",(r)=>r.def.innerType._zod.optin),E(e,"optout",(r)=>r.def.innerType._zod.optout),E(e,"pattern",(r)=>{let o=r.def.innerType._zod.pattern;return o?new RegExp(`^(${Rt(o.source)}|null)$`):void 0}),E(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)}}),Zi=m("$ZodDefault",(e,t)=>{Z.init(e,t),e._zod.optin="defaulted",E(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)=>Cs(s,t));return Cs(n,t)}});function Cs(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var Ri=m("$ZodPrefault",(e,t)=>{Z.init(e,t),e._zod.optin="defaulted",E(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)}}),Ci=m("$ZodNonOptional",(e,t)=>{Z.init(e,t),E(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)=>As(s,e));return As(n,e)}});function As(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 Is(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)=>ie(n,o,X()))},input:e.value}),e}var Ai=m("$ZodCatch",(e,t)=>{Z.init(e,t),E(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),E(e,"optout",(r)=>r.def.innerType._zod.optout),E(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)=>Is(r,s,t,o));return Is(r,n,t,o)}});var Ii=m("$ZodPipe",(e,t)=>{Z.init(e,t),E(e,"values",(r)=>r.def.in._zod.values),E(e,"optin",(r)=>r.def.in._zod.optin),E(e,"optout",(r)=>r.def.out._zod.optout),E(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)=>Vt(i,t.in,o));return Vt(s,t.in,o)}let n=t.in._zod.run(r,o);if(n instanceof Promise)return n.then((s)=>Vt(s,t.out,o));return Vt(n,t.out,o)}});function Vt(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 ji=m("$ZodReadonly",(e,t)=>{Z.init(e,t),E(e,"propValues",(r)=>r.def.innerType._zod.propValues),E(e,"values",(r)=>r.def.innerType._zod.values),E(e,"optin",(r)=>r.def.innerType?._zod?.optin),E(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(js);return js(n)}});function js(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var Ni=m("$ZodLazy",(e,t)=>{Z.init(e,t),an(e._zod,"innerType",()=>{let r=t;if(!r._cachedInner)r._cachedInner=t.getter();return r._cachedInner}),E(e,"pattern",(r)=>r.innerType?._zod?.pattern),E(e,"propValues",(r)=>r.innerType?._zod?.propValues),E(e,"optin",(r)=>r.innerType?._zod?.optin??void 0),E(e,"optout",(r)=>r.innerType?._zod?.optout??void 0),e._zod.parse=(r,o)=>e._zod.innerType._zod.run(r,o)}),Ti=m("$ZodCustom",(e,t)=>{F.init(e,t),Z.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)=>Ns(s,r,o,e));Ns(n,r,o,e);return}});function Ns(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(Re(n))}}class Fi extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var Hr="~memo",Di=[];function Li(e){return e!==null&&typeof e==="object"}function Jr(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var Mi=new WeakMap,ht=0,Yt=1,mt=2;function Qt(e,t,r){let o=Mi.get(e);if(o!==void 0)return o?mt:ht;if(t.has(e))return mt;t.add(e);let n=ht,s=(p)=>{if(n!==mt&&p?._zod){let l=Qt(p,t,r);if(l>n)n=l}},i=(p,l)=>{let f=ht;for(let h of Reflect.ownKeys(p)){let d=Object.getOwnPropertyDescriptor(p,h);if(l&&!d.enumerable)continue;let g=d.get?Yt:d.value?._zod?Qt(d.value,t,r):ht;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=ut(a);c(p?i(p,!0):Yt),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?Qt(p,t,!1):Yt);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 h of f)s(h)}}return t.delete(e),pl(e,n)}function pl(e,t){if(t!==Yt)Mi.set(e,t===mt);return t}function ll(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var qt,Xt=[],fl={alloc(e,t,r){let o=qt;if(!o)return r;qt=void 0;let n={value:r,issues:null};return o.set(t.value,n),Xt.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"&&dl(s,n.value))throw new Fi;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 x=Qt(e,new Set,!1);if(x===ht){if(e._zod.parse=i,e._zod.run===c)e._zod.run=i;return i(a,u)}if(x===mt||o)r=!0;else o=!0}let p=a.value;if(!Li(p))return i(a,u);let l=u[Hr];if(!l)l={buckets:new WeakMap,backEdges:void 0},u[Hr]=l;let f;if(n===u)f=s;else f=ll(l,e),n=u,s=f;let h=f.get(p);if(h){if(a.value=h.value,h.issues){if(h.issues.length)a.issues.push(...Jr(h.issues))}else a.memo=!0,l.backEdges??(l.backEdges=new WeakSet),l.backEdges.add(h.value);return a}qt=f;let d=Xt.length,g=i(a,u);qt=void 0;let y=Xt.length>d?Xt.pop():void 0;if(g instanceof Promise)return g.then((x)=>{if(y)y.issues=x.issues.length?Jr(x.issues):Di;return x});if(y)y.issues=g.issues.length?Jr(g.issues):Di;return g};if(e._zod.parse=c,e._zod.run===i)e._zod.run=c})}};function Wi(){return fl}function dl(e,t){let r=e[Hr]?.backEdges;return r!==void 0&&Li(t)&&r.has(t)}var hl=()=>{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=vn(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 ${Sr(s.values[0])}`;return`Invalid option: expected one of ${_r(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":""}: ${_r(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 Kr(){return{localeError:hl()}}var Ui;class Bi{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 ml(){return new Bi}(Ui=globalThis).__zod_globalRegistry??(Ui.__zod_globalRegistry=ml());var Ce=globalThis.__zod_globalRegistry;function er(e){if(e.checks)e.checks=[...e.checks];return e}function Vi(e,t){return new e(er({type:"string",...v(t)}))}function Ji(e,t){return new e(er({type:"string",coerce:!0,...v(t)}))}function Hi(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...v(t)})}function Ki(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...v(t)})}function Gr(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...v(t)})}function Gi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...v(t)})}function qi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...v(t)})}function Xi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...v(t)})}function qr(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...v(t)})}function Yi(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...v(t)})}function Qi(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...v(t)})}function ec(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...v(t)})}function tc(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...v(t)})}function rc(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...v(t)})}function oc(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...v(t)})}function nc(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...v(t)})}function sc(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...v(t)})}function ic(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...v(t)})}function cc(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...v(t)})}function ac(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...v(t)})}function uc(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...v(t)})}function pc(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...v(t)})}function lc(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...v(t)})}function fc(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...v(t)})}function dc(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...v(t)})}function hc(e,t){return new e({type:"string",format:"date",check:"string_format",...v(t)})}function mc(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...v(t)})}function gc(e,t){return new e({type:"string",format:"duration",check:"string_format",...v(t)})}function yc(e,t){return new e(er({type:"number",checks:[],...v(t)}))}function xc(e,t){return new e(er({type:"number",coerce:!0,checks:[],...v(t)}))}function vc(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...v(t)})}function wc(e,t){return new e({type:"boolean",...v(t)})}function bc(e,t){return new e({type:"boolean",coerce:!0,...v(t)})}function _c(e,t){return new e({type:"bigint",coerce:!0,...v(t)})}function kc(e,t){return new e({type:"null",...v(t)})}function $c(e){return new e({type:"unknown"})}function Sc(e,t){return new e({type:"never",...v(t)})}function zc(e,t){return new e({type:"date",coerce:!0,...v(t)})}function Je(e,t){return new Tr({check:"less_than",...v(t),value:e,inclusive:!1})}function de(e,t){return new Tr({check:"less_than",...v(t),value:e,inclusive:!0})}function He(e,t){return new Dr({check:"greater_than",...v(t),value:e,inclusive:!1})}function he(e,t){return new Dr({check:"greater_than",...v(t),value:e,inclusive:!0})}function gt(e,t){return new ds({check:"multiple_of",...v(t),value:e})}function tr(e,t){return new ms({check:"max_length",...v(t),maximum:e})}function Ke(e,t){return new gs({check:"min_length",...v(t),minimum:e})}function rr(e,t){return new ys({check:"length_equals",...v(t),length:e})}function Xr(e,t){return new xs({check:"string_format",format:"regex",...v(t),pattern:e})}function Yr(e){return new vs({check:"string_format",format:"lowercase",...v(e)})}function Qr(e){return new ws({check:"string_format",format:"uppercase",...v(e)})}function eo(e,t){return new bs({check:"string_format",format:"includes",...v(t),includes:e})}function to(e,t){return new _s({check:"string_format",format:"starts_with",...v(t),prefix:e})}function ro(e,t){return new ks({check:"string_format",format:"ends_with",...v(t),suffix:e})}function $e(e){return new $s({check:"overwrite",tx:e})}function oo(e){return $e((t)=>t.normalize(e))}function no(){return $e((e)=>e.trim())}function so(){return $e((e)=>e.toLowerCase())}function io(){return $e((e)=>e.toUpperCase())}function co(){return $e((e)=>fn(e))}function Pc(e,t,r){return new e({type:"array",element:t,...v(r)})}function Ec(e,t,r){return new e({type:"custom",check:"custom",fn:t,...v(r)})}function Oc(e,t){let r=gl((o)=>(o.addIssue=(n)=>{if(typeof n==="string")o.issues.push(Re(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(Re(s))}},e(o.value,o)),t);return r}function gl(e,t){let r=new F({check:"custom",...v(t)});return r._zod.check=e,r}function yt(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 uo(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??Ce,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 N(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,h=t.processors[n.type];if(!h)throw Error(`[toJSONSchema]: Non-representable type encountered: ${n.type}`);h(e,t,f,p)}let l=e._zod.parent;if(l){if(!i.ref)i.ref=l;N(l,t,p),t.seen.get(l).isParent=!0}}let a=t.metadataRegistry.get(e);if(a)yt(i.schema,a);if(t.io==="input"&&U(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 Zc(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function po(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??((d)=>d);if(l)return{ref:f(l)};let h=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=h,{defId:h,ref:`${f("__shared")}#/${c}/${Zc(h)}`}}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+Zc(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
+
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 Ac(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;Ac(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 Ic=new Set(["type","properties","required","additionalProperties"]),Rc=["oneOf","anyOf"];function Cc(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 ao(e){let t=[];for(let s of e){if(typeof s!=="object"||s.type!=="object")return null;for(let i in s)if(!Ic.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]??Cc(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]:ao(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=Cc(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 yl(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let n of Ic)if(n in e)return;let r=t.filter((n)=>Rc.some((s)=>Array.isArray(n[s]))),o=null;if(!r.length)o=ao(t);else{let n=r[0],s=Rc.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)=>ao([...i,a]));if(c.some((a)=>!a))return;o={[s]:c}}if(!o)return;delete e.allOf,yt(e,o)}function lo(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 h=e.seen.get(l),d=h.schema;if(d.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))u.allOf=u.allOf??[],u.allOf.push(d);else yt(u,d);if(yt(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(d.$ref&&h.def)for(let y in u){if(y==="$ref"||y==="allOf")continue;if(y in h.def&&JSON.stringify(u[y])===JSON.stringify(h.def[y]))delete u[y]}}let f=c._zod.parent;if(f&&f!==l){o(f);let h=e.seen.get(f);if(h?.schema.$ref){if(u.$ref=h.schema.$ref,h.def)for(let d in u){if(d==="$ref"||d==="allOf")continue;if(d in h.def&&JSON.stringify(u[d])===JSON.stringify(h.def[d]))delete u[d]}}}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())Ac(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)??[])yl(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)}yt(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:xt(t,"input",e.processors),output:xt(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch(c){throw Error("Error converting schema to JSON.")}}function U(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 U(o.element,r);if(o.type==="set")return U(o.valueType,r);if(o.type==="lazy")return U(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 U(o.innerType,r);if(o.type==="intersection")return U(o.left,r)||U(o.right,r);if(o.type==="record"||o.type==="map")return U(o.keyType,r)||U(o.valueType,r);if(o.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return U(o.in,r)||U(o.out,r)}if(o.type==="object"){for(let n in o.shape)if(U(o.shape[n],r))return!0;return!1}if(o.type==="union"){for(let n of o.options)if(U(n,r))return!0;return!1}if(o.type==="tuple"){for(let n of o.items)if(U(n,r))return!0;if(o.rest&&U(o.rest,r))return!0;return!1}return!1}var jc=(e,t={})=>(r)=>{let o=uo({...r,processors:t});return N(e,o),po(o,e),lo(o,e)},xt=(e,t,r={})=>(o)=>{let{libraryOptions:n,target:s}=o??{},i=uo({...n??{},target:s,io:t,processors:r});return N(e,i),po(i,e),lo(i,e)};var Ge=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},qe=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},Nc=(e,t)=>{Ge(e,"minimum",t),qe(e,"maximum",t)},Lc=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},Mc=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},Wc=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},Uc=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},Tc=(e,t)=>Ge(e,"minimum",t.minimum),Dc=(e,t)=>qe(e,"maximum",t.maximum),Fc=(e)=>(t,r)=>{Uc(t,r.format);let[o,n]=e[r.format];Ge(t,"minimum",o),qe(t,"maximum",n)},xl={greater_than:(e,t)=>Ge(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>qe(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>Lc(e,t.value),number_format:Fc(Ct),bigint_format:Fc(zr),min_length:Tc,max_length:Dc,length_equals:(e,t)=>Nc(e,t.length),min_size:Tc,max_size:Dc,size_equals:(e,t)=>Nc(e,t.size),string_format:(e,t)=>{if(Uc(e,t.format),t.pattern)Mc(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)=>Wc(e,t.mime)};function L(e){let t={},r=e._zod.def,o=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let s of o)xl[s._zod.def.check]?.(t,s._zod.def);let n=e._zod.bag;if(n.minimum!==void 0)Ge(t,"minimum",n.minimum);if(n.exclusiveMinimum!==void 0)Ge(t,"exclusiveMinimum",n.exclusiveMinimum);if(n.maximum!==void 0)qe(t,"maximum",n.maximum);if(n.exclusiveMaximum!==void 0)qe(t,"exclusiveMaximum",n.exclusiveMaximum);if(n.multipleOf!==void 0)Lc(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)Wc(t,n.mime);for(let s of n.patterns??[])Mc(t,s);return t}var vl={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},wl=new Map([[Wr,Qn],[Gt,es]]),Bc=(e)=>wl.get(e)??e,Vc=(e,t,r,o)=>{let n=r;n.type="string";let{minimum:s,maximum:i,format:c,patterns:a,contentEncoding:u,laxFormat:p}=L(e);if(typeof s==="number")n.minLength=s;if(typeof i==="number")n.maxLength=i;if(c){if(n.format=vl[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(Bc);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}))]}},Jc=(e,t,r,o)=>{let n=r,{minimum:s,maximum:i,multipleOf:c,exclusiveMaximum:a,exclusiveMinimum:u,isInt:p}=L(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),h=t.target==="draft-04"||t.target==="openapi-3.0";if(l)if(h)n.minimum=u,n.exclusiveMinimum=!0;else n.exclusiveMinimum=u;else if(typeof s==="number")n.minimum=s;if(f)if(h)n.maximum=a,n.exclusiveMaximum=!0;else n.exclusiveMaximum=a;else if(typeof i==="number")n.maximum=i;if(c){let d=new Set;for(let x of c)if(Number.isFinite(x)&&x!==0)d.add(Math.abs(x));else re(e,t,n,o,`A multipleOf divisor of ${x} cannot be represented in JSON Schema`);let[g,...y]=d;if(g!==void 0)n.multipleOf=g;if(y.length)n.allOf=[...n.allOf??[],...y.map((x)=>({multipleOf:x}))]}},Hc=(e,t,r,o)=>{r.type="boolean"},Kc=(e,t,r,o)=>{re(e,t,r,o,"BigInt cannot be represented in JSON Schema")};var Gc=(e,t,r,o)=>{if(t.target==="openapi-3.0")r.type="string",r.nullable=!0,r.enum=[null];else r.type="null"};var qc=(e,t,r,o)=>{r.not={}};var Xc=(e,t,r,o)=>{},Yc=(e,t,r,o)=>{re(e,t,r,o,"Date cannot be represented in JSON Schema")},Qc=(e,t,r,o)=>{let n=e._zod.def,s=it(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},ea=(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 ta=(e,t,r,o)=>{re(e,t,r,o,"Custom types cannot be represented in JSON Schema")};var ra=(e,t,r,o)=>{re(e,t,r,o,"Transforms cannot be represented in JSON Schema")};var oa=(e,t,r,o)=>{let n=r,s=e._zod.def,{minimum:i,maximum:c}=L(e);if(typeof i==="number")n.minItems=i;if(typeof c==="number")n.maxItems=c;n.type="array",n.items=N(s.element,t,{...o,path:[...o.path,"items"]})};function or(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return or(t.out);if(t.type==="catch")return or(t.innerType);return e._zod.optin}var na=(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,N(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"?or(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=N(s.catchall,t,{...o,path:[...o.path,"additionalProperties"]})},sa=(e,t,r,o)=>{let n=e._zod.def,s=n.inclusive===!1,i=n.options.map((c,a)=>N(c,t,{...o,path:[...o.path,s?"oneOf":"anyOf",a]}));if(s)r.oneOf=i;else r.anyOf=i},ia=(e,t,r,o)=>{let n=e._zod.def,s=N(n.left,t,{...o,path:[...o.path,"allOf",0]}),i=N(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)};function fo(e,t,r){if(t.$ref){if(r.has(t))return t;r.add(t);let d=e.get(t)?.def;if(!d)return t;let g=fo(e,d,r);return g===d?t:g}for(let d of["anyOf","oneOf"]){let g=t[d];if(!Array.isArray(g))continue;let y=g.map((x)=>fo(e,x,r));if(y.some((x,w)=>x!==g[w]))t={...t,[d]:y}}let o=Array.isArray(t.type)?t.type:[t.type],n=!o.includes("string")&&o.some((d)=>d==="number"||d==="integer"),s=t.enum??(t.const!==void 0?[t.const]:void 0);if(!n&&!s?.some((d)=>typeof d==="number"))return t;let{minimum:i,maximum:c,exclusiveMinimum:a,exclusiveMaximum:u,multipleOf:p,format:l,id:f,...h}=t;if(h.enum)h.enum=h.enum.map((d)=>typeof d==="number"?String(d):d);else if(typeof h.const==="number")h.const=String(h.const);if(!n)return h;if(h.type="string",!s)h.pattern=(o.includes("number")?lt:jr).source;return h}var ho=new WeakMap;function bl(e){let t=new Map;for(let o of e.seen.values())if(o.def&&!t.has(o.schema))t.set(o.schema,o);let r=new Map;for(let o of ho.get(e)??[]){let n=e.seen.get(o),s=(n?.def??n?.schema)?.propertyNames;if(!s||s===!0||r.has(s))continue;let i=fo(t,s,new Set);if(i!==s)r.set(s,i)}if(!r.size)return;for(let o of e.seen.values())for(let n of[o.schema,o.def]){let s=n&&r.get(n.propertyNames);if(s)n.propertyNames=s}}var ca=(e,t,r,o)=>{let n=r,s=e._zod.def;n.type="object";let i=s.keyType,c=L(i).patterns;if(s.mode==="loose"&&c&&c.size>0){let p=N(s.valueType,t,{...o,path:[...o.path,"patternProperties","*"]});n.patternProperties={};for(let l of c)Q(n.patternProperties,Bc(l).source,p)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){n.propertyNames=N(s.keyType,t,{...o,path:[...o.path,"propertyNames"]});let p=ho.get(t);if(!p)p=[],ho.set(t,p),t.deferred.push(()=>bl(t));p.push(e)}n.additionalProperties=N(s.valueType,t,{...o,path:[...o.path,"additionalProperties"]})}let a=i._zod.values,u=t.io==="input"&&or(s.valueType)!==void 0;if(a&&!s.partial&&!u){let p=[...a].filter((l)=>typeof l==="string"||typeof l==="number");if(p.length>0)n.required=p.map(String)}},aa=(e,t,r,o)=>{let n=e._zod.def,s=N(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"}]},ua=(e,t,r,o)=>{let n=e._zod.def;N(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType},mo=Symbol();function pa(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"),mo}var la=(e,t,r,o)=>{let n=e._zod.def;N(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType;let i=pa(n.defaultValue,e,t,r,o);if(i!==mo)r.default=i},fa=(e,t,r,o)=>{let n=e._zod.def;N(n.innerType,t,o);let s=t.seen.get(e);if(s.ref=n.innerType,t.io!=="input")return;let i=pa(n.defaultValue,e,t,r,o);if(i!==mo)r._prefault=i},da=(e,t,r,o)=>{let n=e._zod.def;N(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},ha=(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;N(i,t,o);let c=t.seen.get(e);c.ref=i},ma=(e,t,r,o)=>{let n=e._zod.def;N(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType,r.readOnly=!0};var go=(e,t,r,o)=>{let n=e._zod.def;N(n.innerType,t,o);let s=t.seen.get(e);s.ref=n.innerType},ga=(e,t,r,o)=>{let n=e._zod.innerType;N(n,t,o);let s=t.seen.get(e);s.ref=n};var ya=new WeakSet([Object.prototype,Error.prototype]);function nr(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 Zl=(e,t)=>{zn.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(ya.has(r))return;ya.add(r),nr(r,"format",(o)=>(n)=>En(o,n)),nr(r,"flatten",(o)=>(n)=>Pn(o,n)),nr(r,"addIssue",(o)=>(n)=>{o.issues.push(n),o.message=JSON.stringify(o.issues,ct,2)}),nr(r,"addIssues",(o)=>(n)=>{o.issues.push(...n),o.message=JSON.stringify(o.issues,ct,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var Y=m("ZodError",Zl,void 0,{Parent:Error});var xa=Lt(Y),va=Mt(Y),wa=Wt(Y),ba=Ut(Y),_a=Zn(Y),ka=Rn(Y),$a=Cn(Y),Sa=An(Y),za=In(Y),Pa=jn(Y),Ea=Nn(Y),Oa=Tn(Y);function Cl(){if(!H.localeError)X(Kr())}function sr(){if(!H.memoizer)X({memoizer:Wi()})}var C=m("ZodType",(e,t)=>(Cl(),Z.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(q(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(Of(e,t))},superRefine(e,t){return this.check(Zf(e,t))},overwrite(e){return this.check($e(e))},optional(){return Aa(this)},exactOptional(){return hf(this)},nullable(){return Ia(this)},nullish(){return Aa(Ia(this))},nonoptional(e){return wf(this,e)},array(){return P(this)},or(e){return ar([this,e])},and(e){return pf(this,e)},transform(e){return ja(this,df(e))},default(e){return yf(this,e)},prefault(e){return vf(this,e)},catch(e){return _f(this,e)},pipe(e){return ja(this,e)},readonly(){return Sf(this)},describe(e){let t=this.clone();return Ce.add(t,{description:e}),t},meta(...e){if(e.length===0)return Ce.get(this);let t=this.clone();return Ce.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 Tt(this,"~standard",{...Mr(this),jsonSchema:{input:xt(this,"input"),output:xt(this,"output")}})},set "~standard"(e){fe(this,"~standard",e)},parse:function e(t,r){return xa(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await va(this,t,r,{callee:e})},safeParse(e,t){return wa(this,e,t)},async safeParseAsync(e,t){return ba(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){fe(this,"spa",e)},validate(e,t){return Rr(this,e,t)},validateAsync(e,t){return Cr(this,e,t)},encode:function e(t,r){return _a(this,t,r,{callee:e})},decode:function e(t,r){return ka(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await $a(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await Sa(this,t,r,{callee:e})},safeEncode(e,t){return za(this,e,t)},safeDecode(e,t){return Pa(this,e,t)},async safeEncodeAsync(e,t){return Ea(this,e,t)},async safeDecodeAsync(e,t){return Oa(this,e,t)},toJSONSchema(e){return jc(this,{})(e)},get description(){return Ce.get(this)?.description},get _def(){return this._zod.def}}),Na=m("_ZodString",(e,t)=>{Kt.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Vc(e,r,o,n)},Dt({format:(e)=>L(e).format??null,minLength:(e)=>L(e).minimum??null,maxLength:(e)=>L(e).maximum??null},{regex(...e){return this.check(Xr(...e))},includes(...e){return this.check(eo(...e))},startsWith(...e){return this.check(to(...e))},endsWith(...e){return this.check(ro(...e))},min(...e){return this.check(Ke(...e))},max(...e){return this.check(tr(...e))},length(...e){return this.check(rr(...e))},nonempty(...e){return this.check(Ke(1,...e))},lowercase(e){return this.check(Yr(e))},uppercase(e){return this.check(Qr(e))},trim(){return this.check(no())},normalize(...e){return this.check(oo(...e))},toLowerCase(){return this.check(so())},toUpperCase(){return this.check(io())},slugify(){return this.check(co())}})),xo=m("ZodString",(e,t)=>{Kt.init(e,t),Na.init(e,t)},{email(e){return this.check(Hi(Tl,e))},url(e){return this.check(qr(Ta,e))},jwt(e){return this.check(fc(ef,e))},emoji(e){return this.check(Yi(Ll,e))},guid(e){return this.check(Ki(Dl,e))},uuid(e){return this.check(Gr(wt,e))},uuidv4(e){return this.check(Gi(wt,e))},uuidv6(e){return this.check(qi(wt,e))},uuidv7(e){return this.check(Xi(wt,e))},nanoid(e){return this.check(Qi(Ml,e))},cuid(e){return this.check(ec(Wl,e))},cuid2(e){return this.check(tc(Ul,e))},ulid(e){return this.check(rc(Bl,e))},base64(e){return this.check(uc(Xl,e))},base64url(e){return this.check(pc(Yl,e))},xid(e){return this.check(oc(Vl,e))},ksuid(e){return this.check(nc(Jl,e))},ipv4(e){return this.check(sc(Hl,e))},ipv6(e){return this.check(ic(Kl,e))},cidrv4(e){return this.check(cc(Gl,e))},cidrv6(e){return this.check(ac(ql,e))},e164(e){return this.check(lc(Ql,e))},datetime(e){return this.check(dc(Al,e))},date(e){return this.check(hc(Il,e))},time(e){return this.check(mc(jl,e))},duration(e){return this.check(gc(Nl,e))}});function k(e){return Vi(xo,e)}var j=m("ZodStringFormat",(e,t)=>{A.init(e,t),Na.init(e,t)}),Al=m("ZodISODateTime",(e,t)=>{Xs.init(e,t),j.init(e,t)}),Il=m("ZodISODate",(e,t)=>{Ys.init(e,t),j.init(e,t)}),jl=m("ZodISOTime",(e,t)=>{Qs.init(e,t),j.init(e,t)}),Nl=m("ZodISODuration",(e,t)=>{ei.init(e,t),j.init(e,t)}),Tl=m("ZodEmail",(e,t)=>{Ls.init(e,t),j.init(e,t)});var Dl=m("ZodGUID",(e,t)=>{Ds.init(e,t),j.init(e,t)});var wt=m("ZodUUID",(e,t)=>{Fs.init(e,t),j.init(e,t)});function vo(e){return Gr(wt,e)}var Ta=m("ZodURL",(e,t)=>{Us.init(e,t),j.init(e,t)});function Fl(e){return qr(Ta,e)}var Ll=m("ZodEmoji",(e,t)=>{Bs.init(e,t),j.init(e,t)});var Ml=m("ZodNanoID",(e,t)=>{Vs.init(e,t),j.init(e,t)});var Wl=m("ZodCUID",(e,t)=>{Js.init(e,t),j.init(e,t)});var Ul=m("ZodCUID2",(e,t)=>{Hs.init(e,t),j.init(e,t)});var Bl=m("ZodULID",(e,t)=>{Ks.init(e,t),j.init(e,t)});var Vl=m("ZodXID",(e,t)=>{Gs.init(e,t),j.init(e,t)});var Jl=m("ZodKSUID",(e,t)=>{qs.init(e,t),j.init(e,t)});var Hl=m("ZodIPv4",(e,t)=>{ti.init(e,t),j.init(e,t)});var Kl=m("ZodIPv6",(e,t)=>{oi.init(e,t),j.init(e,t)});var Gl=m("ZodCIDRv4",(e,t)=>{ni.init(e,t),j.init(e,t)});var ql=m("ZodCIDRv6",(e,t)=>{si.init(e,t),j.init(e,t)});var Xl=m("ZodBase64",(e,t)=>{ci.init(e,t),j.init(e,t)});var Yl=m("ZodBase64URL",(e,t)=>{ai.init(e,t),j.init(e,t)});var Ql=m("ZodE164",(e,t)=>{ui.init(e,t),j.init(e,t)});var ef=m("ZodJWT",(e,t)=>{pi.init(e,t),j.init(e,t)});var ir=m("ZodNumber",(e,t)=>{Ur.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Jc(e,r,o,n),e.isFinite=!0},Dt({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=L(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=L(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=L(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>L(e).format??null},{gt(e,t){return this.check(He(e,t))},gte(e,t){return this.check(he(e,t))},min(e,t){return this.check(he(e,t))},lt(e,t){return this.check(Je(e,t))},lte(e,t){return this.check(de(e,t))},max(e,t){return this.check(de(e,t))},int(e){return this.check(Za(e))},safe(e){return this.check(Za(e))},positive(e){return this.check(He(0,e))},nonnegative(e){return this.check(he(0,e))},negative(e){return this.check(Je(0,e))},nonpositive(e){return this.check(de(0,e))},multipleOf(e,t){return this.check(gt(e,t))},step(e,t){return this.check(gt(e,t))},finite(){return this}}));function cr(e){return yc(ir,e)}var tf=m("ZodNumberFormat",(e,t)=>{li.init(e,t),ir.init(e,t)});function Za(e){return vc(tf,e)}var wo=m("ZodBoolean",(e,t)=>{fi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Hc(e,r,o,n)});function Ae(e){return wc(wo,e)}var Da=m("ZodBigInt",(e,t)=>{di.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Kc(e,r,o,n)},Dt({minValue:(e)=>L(e).minimum??null,maxValue:(e)=>L(e).maximum??null,format:(e)=>L(e).format??null},{gte(e,t){return this.check(he(e,t))},min(e,t){return this.check(he(e,t))},gt(e,t){return this.check(He(e,t))},lt(e,t){return this.check(Je(e,t))},lte(e,t){return this.check(de(e,t))},max(e,t){return this.check(de(e,t))},positive(e){return this.check(He(BigInt(0),e))},negative(e){return this.check(Je(BigInt(0),e))},nonpositive(e){return this.check(de(BigInt(0),e))},nonnegative(e){return this.check(he(BigInt(0),e))},multipleOf(e,t){return this.check(gt(e,t))}}));var rf=m("ZodNull",(e,t)=>{hi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Gc(e,r,o,n)});function of(e){return kc(rf,e)}var nf=m("ZodUnknown",(e,t)=>{mi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Xc(e,r,o,n)});function Ra(){return $c(nf)}var sf=m("ZodNever",(e,t)=>{gi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>qc(e,r,o,n)});function Fa(e){return Sc(sf,e)}var La=m("ZodDate",(e,t)=>{yi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>Yc(e,r,o,n),e.min=(r,o)=>e.check(he(r,o)),e.max=(r,o)=>e.check(de(r,o))},Dt({minDate:(e)=>{let{minimum:t}=L(e);return t?new Date(t):null},maxDate:(e)=>{let{maximum:t}=L(e);return t?new Date(t):null}},{}));var cf=m("ZodArray",(e,t)=>{sr(),xi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>oa(e,r,o,n),e.element=t.element},{min(e,t){return this.check(Ke(e,t))},nonempty(e){return this.check(Ke(1,e))},max(e,t){return this.check(tr(e,t))},length(e,t){return this.check(rr(e,t))},unwrap(){return this.element}});function P(e,t){return Pc(cf,e,t)}var Ma=m("ZodObject",(e,t)=>{sr(),bi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>na(e,r,o,n),Tp(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return B(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(q(this._zod.def,{catchall:e}))},passthrough(){return this.clone(q(this._zod.def,{catchall:Ra()}))},loose(){return this.clone(q(this._zod.def,{catchall:Ra()}))},strict(){return this.clone(q(this._zod.def,{catchall:Fa()}))},strip(){return this.clone(q(this._zod.def,{catchall:void 0}))},extend(e){return Op(this,e)},safeExtend(e){return Zp(this,e)},merge(e){return Rp(this,e)},pick(e){return Pp(this,e)},omit(e){return Ep(this,e)},partial(...e){return yn(Ua,this,e[0])},exactPartial(...e){return yn(Ba,this,e[0],"exactPartial")},required(...e){return Cp(Va,this,e[0])}});function me(e,t){let r={type:"object",shape:e??{},...v(t)};return new Ma(r)}function O(e,t){return new Ma({type:"object",shape:e,catchall:Fa(),...v(t)})}var Wa=m("ZodUnion",(e,t)=>{Br.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>sa(e,r,o,n),e.options=t.options});function ar(e,t){return new Wa({type:"union",options:e,...v(t)})}var af=m("ZodDiscriminatedUnion",(e,t)=>{Wa.init(e,t),_i.init(e,t)});function bo(e,t,r){return new af({type:"union",options:t,discriminator:e,...v(r)})}var uf=m("ZodIntersection",(e,t)=>{ki.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ia(e,r,o,n)});function pf(e,t){return new uf({type:"intersection",left:e,right:t})}var Ca=m("ZodRecord",(e,t)=>{sr(),$i.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ca(e,r,o,n),e.keyType=t.keyType,e.valueType=t.valueType});function bt(e,t,r){if(!t||!t._zod)return new Ca({type:"record",keyType:k(),valueType:e,...v(t)});return new Ca({type:"record",keyType:e,valueType:t,...v(r)})}var yo=m("ZodEnum",(e,t)=>{Si.init(e,t),C.init(e,t),e._zod.processJSONSchema=(o,n,s)=>Qc(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 yo({...t,checks:[],...v(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 yo({...t,checks:[],...v(n),entries:s})}});function B(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((o)=>[o,o])):e;return new yo({type:"enum",entries:r,...v(t)})}var lf=m("ZodLiteral",(e,t)=>{zi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ea(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 K(e,t){return new lf({type:"literal",values:Array.isArray(e)?e:[e],...v(t)})}var ff=m("ZodTransform",(e,t)=>{sr(),Pi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ra(e,r,o,n),e._zod.parse=(r,o)=>{if(o.direction==="backward")throw new pt(e.constructor.name);r.addIssue=(s)=>{if(typeof s==="string")r.issues.push(Re(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(Re(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 df(e){return new ff({type:"transform",transform:e})}var Ua=m("ZodOptional",(e,t)=>{Vr.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>go(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Aa(e){return new Ua({type:"optional",innerType:e})}var Ba=m("ZodExactOptional",(e,t)=>{Ei.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>go(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function hf(e){return new Ba({type:"optional",innerType:e})}var mf=m("ZodNullable",(e,t)=>{Oi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>aa(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Ia(e){return new mf({type:"nullable",innerType:e})}var gf=m("ZodDefault",(e,t)=>{Zi.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>la(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function yf(e,t){return new gf({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():$r(t)}})}var xf=m("ZodPrefault",(e,t)=>{Ri.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>fa(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function vf(e,t){return new xf({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():$r(t)}})}var Va=m("ZodNonOptional",(e,t)=>{Ci.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ua(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function wf(e,t){return new Va({type:"nonoptional",innerType:e,...v(t)})}var bf=m("ZodCatch",(e,t)=>{Ai.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>da(e,r,o,n),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function _f(e,t){return new bf({type:"catch",innerType:e,catchValue:typeof t==="function"?t:bn(t)})}var kf=m("ZodPipe",(e,t)=>{Ii.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ha(e,r,o,n),e.in=t.in,e.out=t.out});function ja(e,t){return new kf({type:"pipe",in:e,out:t})}var $f=m("ZodReadonly",(e,t)=>{ji.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ma(e,r,o,n),e.unwrap=()=>e._zod.def.innerType});function Sf(e){return new $f({type:"readonly",innerType:e})}var zf=m("ZodLazy",(e,t)=>{Ni.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ga(e,r,o,n),e.unwrap=()=>e._zod.def.getter()});function Pf(e){return new zf({type:"lazy",getter:e})}var Ef=m("ZodCustom",(e,t)=>{Ti.init(e,t),C.init(e,t),e._zod.processJSONSchema=(r,o,n)=>ta(e,r,o,n)});function Of(e,t={}){return Ec(Ef,e,t)}function Zf(e,t){return Oc(e,t)}function ur(e){let t=Pf(()=>ar([k(e),cr(),Ae(),of(),P(t),bt(k(),t)]));return t}var _o={};Sp(_o,{bigint:()=>jf,boolean:()=>If,date:()=>Nf,number:()=>Af,string:()=>Cf});function Cf(e){return Ji(xo,e)}function Af(e){return xc(ir,e)}function If(e){return bc(wo,e)}function jf(e){return _c(Da,e)}function Nf(e){return zc(La,e)}var ko=B(["codex","claude","opencode"]),Tf=k().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),Df="Run AppToolkit Harness init or update when explicitly requested.",Ff={codex:".agents/skills/apptoolkit/SKILL.md",claude:".claude/skills/apptoolkit/SKILL.md",opencode:".opencode/commands/apptoolkit.md"};function $o(e,t="llm/HARNESS.md"){let r=new Set(P(ko).parse(e)),o=[],n=[`At the start of work, resolve \`${t}\` from the project or workspace root that owns this bootstrap. Open it for scoped rules, tools, prior findings and the workflow index. Follow the established rules for the project. Use W01 for pending work and W16 then W18 for feature work.`,"Prefer reliable deterministic tools for mechanical work. Reuse the project runner and tool catalog. When work repeats or stdout is hard to use, improve or build the smallest tested utility and index it.","Capture durable decisions, human and PR feedback, and verified research in the project knowledge index as you work. Retrieve relevant prior findings first. Create and maintain applicable sibling .llm.md source maps. Apply and verify authorized local improvements to rules, checks and workflows before handoff."].join(`
59
+ `);if(r.has("codex")||r.has("opencode"))o.push({path:"AGENTS.md",content:n});if(r.has("claude"))o.push({path:"CLAUDE.md",content:n});return o}function Lf(e,t){let r=["---"];if(e!=="opencode")r.push("name: apptoolkit");if(r.push(`description: ${Df}`),e==="claude")r.push('argument-hint: "[init | update]"',"disable-model-invocation: true");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.","Use this entry point for init and update. For ordinary work, follow the native project instructions and `llm/HARNESS.md` directly.","","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`, read W20 from the installed index. Use the installed runtime with `init --root <workspace> --json`. Ask the user about budgets, Biome scope and any blocked automatic bootstrap paths. Apply the authorized project choices and verify discovery with the steps in W20.","- For `update`, use `rtk proxy bunx --bun @apptoolkit/harness@latest update --root <workspace> --plan --json` (or `rtk proxy npx --yes @apptoolkit/harness@latest update --root <workspace> --plan --json`). Use the exact reported version for subsequent commands. Follow W20 to compare changed guidance with project rules. For any conflict, show the scoped alternatives and ask which prevails. Apply a clean plan with `--yes --json` and verify the result.",""),r.join(`
60
+ `)}function So(e,t){let r=P(ko).parse(e),o=Tf.parse(t),n=[...new Set(r)].map((s)=>({path:Ff[s],content:Lf(s,o)}));if(r.includes("codex"))n.push({path:".agents/skills/apptoolkit/agents/openai.yaml",content:`policy:
61
+ allow_implicit_invocation: false
62
+ `});return n}import{randomUUID as vd}from"node:crypto";import{lstatSync as wd,readFileSync as bd,realpathSync as mu,renameSync as _d,rmSync as kd,writeFileSync as $d}from"node:fs";import{dirname as Sd,join as rt,relative as zd,resolve as gu}from"node:path";import{mkdirSync as rd,readFileSync as od,rmSync as ou,writeFileSync as nd}from"node:fs";import{tmpdir as sd}from"node:os";import{resolve as Eo}from"node:path";import{createHash as Mf,randomUUID as Wf}from"node:crypto";import{chmodSync as Uf,linkSync as Bf,lstatSync as pr,mkdirSync as Vf,readFileSync as Jf,realpathSync as Ka,renameSync as Hf,rmSync as Kf,unlinkSync as Gf,writeFileSync as qf}from"node:fs";import{dirname as Ja,isAbsolute as Ga,relative as qa,resolve as _t,sep as Xf}from"node:path";var Ha=16777216;class lr extends Error{}function Xa(e){return"code"in e&&e.code==="ENOENT"}function ge(e){let t=Ka(_t(e));if(!pr(t).isDirectory())throw Error(`Expected an existing directory at ${t}.`);return t}function zo(e,t){let r=qa(e,t);return r!==".."&&!r.startsWith(`..${Xf}`)&&!Ga(r)}function ye(e,t){if(!zo(e,t))throw Error(`Path ${t} is outside ${e}.`);return qa(e,t)||"."}function oe(e){let t=e.split("/");if(Ga(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 fr(e,t){if(oe(t),Ka(e)!==e||!pr(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=_t(o,s);let i=pr(o,{throwIfNoEntry:!1});if(!i)break;let c=n===r.length-1;if(i.isSymbolicLink()||!c&&!i.isDirectory()||c&&!i.isFile())throw new lr(`Expected a regular file path. Inspect ${o} before retrying.`)}return _t(e,t)}function V(e){return Mf("sha256").update(e).digest("hex")}function T(e,t=420){let r=Buffer.isBuffer(e)?e:Buffer.from(e);return{bytes:r,hash:V(r),mode:t}}function R(e,t){let r=fr(e,t),o=pr(r,{throwIfNoEntry:!1});if(!o)return null;if(o.size>Ha)throw Error(`The file at ${r} exceeds the ${Ha}-byte installation limit.`);return T(Jf(r),o.mode&511)}function ae(e,t){return e?.hash===t?.hash&&e?.mode===t?.mode}function Ie(e){if(!ae(R(e.base,e.path),e.before))throw Error(`File changed after planning. Replan before applying ${_t(e.base,e.path)}.`)}function kt(e){Ie(e);let t=fr(e.base,e.path);if(!e.after){Gf(t);return}Vf(Ja(t),{recursive:!0}),Ie(e);let r=_t(Ja(t),`.apptoolkit-${Wf()}.tmp`),o=e.after;try{if(qf(r,o.bytes,{flag:"wx",mode:o.mode}),Uf(r,o.mode),e.before)Ie(e),Hf(r,t);else Bf(r,t)}finally{Kf(r,{force:!0})}}import{spawnSync as Yf}from"node:child_process";import{lstatSync as Qf,realpathSync as Ya}from"node:fs";import{dirname as Qa,resolve as Po}from"node:path";function ed(){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 Xe(e,t,r=[0],o=!1){let s=Yf("rtk",["proxy","git",...o?["--literal-pathspecs"]:[],"-C",e,...t],{encoding:"utf8",env:ed(),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 eu(e){let t=e;while(!0){let r=Qf(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=Qa(t);if(o===t)return;t=o}}function J(e){if(!eu(e))return;let t=Ya(Xe(e,["rev-parse","--show-toplevel"]).output.trimEnd()),r=Ya(Xe(e,["rev-parse","--path-format=absolute","--git-common-dir"]).output.trimEnd()),o=Xe(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 je(e,t){if(eu(Qa(e))!==t)throw Error(`The path ${e} belongs to a different Git checkout. Select that checkout explicitly before retrying.`)}function Ye(e,t){let r=ye(e.root,t);return Xe(e.root,["ls-files","--cached","-z","--",r],[0],!0).output.split("\x00").includes(r)}function dr(e,t){let r=Xe(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 td(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 tu(e){let t=Xe(e,["config","--local","--get","remote.origin.url"],[0,1]);if(t.status===1)return;let r=td(t.output.trimEnd());if(!r)return;return V(r)}function $t(e){return`/${e.replace(/[\\[\]*? #!]/gu,"\\$&")}`}var id=_o.number().int().positive(),nu=new WeakMap;function su(e,t){nu.set(e,t)}function cd(e){let t=Eo(sd(),`apptoolkit-${V(e).slice(0,24)}.lock`),r=Eo(t,"owner");try{rd(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=id.parse(od(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{nd(r,`${process.pid}
63
+ `,{mode:384,flag:"wx"})}catch(o){try{ou(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 ad(e){let t=new Map;for(let r of e){let n=t.get(r.git.root)??J(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&&Ye(r.git,r.absolute))throw Error(`Git started tracking ${r.absolute} after planning. Replan before applying local mode.`)}}function ud(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 ${Eo(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 pd(e){let{exclusions:t,files:r,checks:o,guards:n=[],receipt:s}=e,i=[];for(let c of[...n,...t,...r])Ie(c);for(let c of e.boundaries??[])je(c.absolute,c.gitRoot);ad(o);try{for(let c of t)kt(c),i.push(c);for(let c of o)dr(c,c.versioned);for(let c of r)kt(c),i.push(c);if(s){for(let c of n)Ie(c);for(let c of r)Ie({...c,before:c.after});kt(s),i.push(s)}}catch(c){ud(i,Error("Could not apply the workspace installation. Inspect the cause and replan before retrying.",{cause:c}))}return i.length}function ru(e){let t=[];for(let r of e.reverse())try{ou(r,{recursive:!0})}catch(o){if(!(o instanceof Error)||!Xa(o))t.push(Error(`Cannot remove the installation lock at ${r}. Inspect it before retrying.`,{cause:o}))}return t}function iu(e,t){let r=[],o;try{for(let s of[...new Set(e)].sort())r.push(cd(s));o=t()}catch(s){let i=ru(r);if(i.length)throw AggregateError([s,...i],"The installation failed and some locks could not be removed.");throw s}let n=ru(r);if(n.length)throw AggregateError(n,"The installation completed and some locks could not be removed.");return o}function cu(e,t){return iu([e],t)}function Oo(e,t){let r=[e,...t.exclusions.map((o)=>o.base),...t.checks.map((o)=>o.git.commonDirectory)];return iu(r,()=>pd(t))}function Zo(e){let t=nu.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:Oo(e.root,t),receipt:e.receipt}}import{resolve as ld}from"node:path";var au=B(["codex","claude","opencode"]),uu=B(["plane","penpot"]),Qe=k().regex(/^[a-f0-9]{64}$/),pu=O({path:k().min(1),versioned:Ae(),identity:Qe.optional()}),lu=O({schema:K(1),version:k().min(1),hosts:P(au),workspaceVersioned:Ae(),repositories:P(pu),services:P(uu),bootstrapNotices:P(k()).optional(),installation:k().regex(/^[a-f0-9]{16}$/).optional(),files:P(O({path:k().min(1),hash:Qe,versioned:Ae(),fragment:Qe.optional(),retainedAgainst:Qe.nullable().optional()}))}),hr=O({root:k().min(1),action:B(["install","update","add-repo"]),version:k().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/),contentDirectory:k(),hosts:P(au).min(1),workspaceVersioned:Ae(),repositories:P(pu),services:P(uu),repository:k().min(1).optional(),resolutions:P(O({path:k().min(1),local:Qe.nullable(),incoming:Qe.nullable(),choice:B(["local","release"])})).optional()}),W="llm/harness/workspace.json";var fu=new Set([".agents/skills/apptoolkit/SKILL.md",".agents/skills/apptoolkit/agents/openai.yaml",".claude/skills/apptoolkit/SKILL.md",".opencode/commands/apptoolkit.md",".opencode/opencode.json",".opencode/opencode.jsonc","AGENTS.md","AGENTS.override.md","CLAUDE.md",".claude/rules/apptoolkit.md","opencode.json","opencode.jsonc","llm/harness-local/opencode-instructions.md"]);function Ro(e,t){if(e.startsWith("llm/harness/")||e.startsWith("llm/author-style/")||fu.has(e))return e!==W&&e!=="llm/harness/project.json";if(e==="llm/HARNESS.md"||e==="llm/README.md")return!0;return t.some((r)=>e===et(r.path)||r.path!=="."&&[...fu].some((o)=>e===`${r.path}/${o}`))}function et(e){if(e===".")return"llm/harness-context.llm.md";return`${e}/llm/harness-context.llm.md`}function ee(e){let t=ge(e),r=R(t,W);if(!r)return;try{let o=lu.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),!Ro(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 ${ld(t,W)}. Restore a valid receipt before retrying.`,{cause:o})}}var ue=k().trim().min(1).max(120).regex(/^[\p{L}\p{N}][\p{L}\p{N} ./_:+-]*$/u),hu=k().regex(/^[A-Z_][A-Z0-9_]*$/).max(120),xe=k().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."),Se=ar([K("."),xe]),tt=B(["plane","penpot"]),fd=new Set(["localhost","127.0.0.1","[::1]"]),Co=Fl().max(512).pipe(k().refine((e)=>{let t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:"&&fd.has(t.hostname))&&!t.username&&!t.password&&!t.search&&!t.hash},"Use HTTPS or loopback HTTP without credentials, query, or fragment.")),du={baseUrl:Co,tokenEnv:hu,snapshots:B(["off","versioned"])},dd=bo("provider",[O({...du,provider:K("plane"),workspace:k().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,119}$/),projectId:vo(),auth:B(["api-key","oauth"]).default("api-key")}),O({...du,provider:K("penpot"),fileId:vo()})]),hd=B(["project","agent-only"]),md=bo("mode",[O({mode:K("unlimited")}),O({mode:K("limited"),limits:P(O({category:ue,maximum:cr().positive(),unit:ue})).min(1).max(12)})]),gd=O({category:ue,scope:ue,authority:ue,provider:ue,access:bo("method",[O({method:K("local"),path:xe}),O({method:K("cli"),command:ue}),O({method:K("mcp"),server:ue}),O({method:K("api"),baseUrl:Co,tokenEnv:hu.optional()}),O({method:K("web"),baseUrl:Co})])}),yd=O({kind:ue,template:xe.optional(),requiredSections:P(ue).max(30),checklist:P(k().trim().min(1).max(200)).max(30),prohibitedText:P(k().trim().min(1).max(120)).max(30)}),xd=O({path:Se,budget:md,biome:hd.optional(),rules:P(xe).max(50),routes:P(gd).max(50),documentation:P(yd).max(50),services:P(dd).max(2)}).superRefine((e,t)=>{let r=new Set;for(let[n,s]of e.routes.entries()){let i=`${s.category.toLowerCase()}
64
+ ${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)}}),Ne=O({schema:K(1),projects:P(xd).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 Io="llm/harness/project.json",Pd=1048576;function ve(e){try{return wd(e)}catch(t){if(t instanceof Error&&"code"in t&&t.code==="ENOENT")return;throw Error(`Inspect ${e}.`,{cause:t})}}function we(e){let t=ve(e);if(!t?.isFile()||t.size>Pd)throw Error(`Expected a regular JSON file of at most 1 MiB at ${e}.`);try{return JSON.parse(bd(e,"utf8"))}catch(r){throw Error(`Read JSON configuration at ${e}.`,{cause:r})}}function yu(e){let t=e;for(let r of["llm","harness"])if(t=rt(t,r),!ve(t)?.isDirectory())throw Error(`Expected an installed, nonsymlink workspace directory at ${t}.`);return t}function Te(e){let t=mu(gu(e));yu(t);let r=ee(t);if(!r)throw Error("Install the harness in the selected workspace before configuring it.");return{root:t,receipt:r}}function xu(e,t){if(yu(e),!ve(t))return;let r=Ne.safeParse(we(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 De(e){return xu(e,rt(e,Io))}function Ed(e,t,r){if(r)return{...r,biome:r.biome??null};let o=rt(e,t),n=[];if(ve(o)?.isDirectory()&&mu(o)===o){for(let s of["AGENTS.md","CLAUDE.md","CONTRIBUTING.md"])if(ve(rt(o,s))?.isFile())n.push(s)}return{path:t,budget:null,biome:null,rules:n,routes:[],documentation:[],services:[]}}function jo(e){let{root:t,receipt:r}=Te(e),o=De(t),n=new Set([".",...r.repositories.map((s)=>s.path)]);return{schema:1,...r.bootstrapNotices?.length?{bootstrapNotices:r.bootstrapNotices}:{},projects:[...n].map((s)=>{let i=o?.projects.find((c)=>c.path===s);return Ed(t,s,i)})}}function Ao(e){return`${JSON.stringify(e,null,2)}
65
+ `}function Od(e,t){let r=Sd(e),o=rt(r,`.project.${vd()}.json`);try{$d(o,Ao(t),{flag:"wx",mode:384}),_d(o,e)}catch(n){try{kd(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 No(e){let{root:t}=Te(e.root),r=xu(t,gu(e.configPath));if(!r)throw Error("Provide the approved project settings JSON file.");return cu(t,()=>{let{receipt:o}=Te(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.`);if(!u.biome)throw Error(`Choose project or agent-only Biome scope for project "${u.path}".`);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=rt(t,Io);if(!o.workspaceVersioned){let u=J(t);if(u)dr({git:u,path:zd(u.root,s)},!1)}let i=De(t),c=new Map(i?.projects.map((u)=>[u.path,u]));for(let u of r.projects)c.set(u.path,u);let a=Ne.parse({schema:1,projects:[...c.values()]});if(i&&Ao(i)===Ao(a))return{path:s,changed:!1,projects:a.projects.length};return Od(s,a),{path:s,changed:!0,projects:a.projects.length}})}var Zd=O({root:k().min(1),project:Se,service:tt,verifyHealth:Ae().optional(),verifyRead:Ae()}),Rd=me({results:P(me({id:vo()})).max(1)}),Cd=me({name:k().min(1)}),Ad=131072;class ze extends Error{}function Do(e){let{root:t,receipt:r}=Te(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=De(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 To(e,t){let r=new URL(e);if(!r.pathname.endsWith("/"))r.pathname+="/";return new URL(t,r)}function Id(e){if(e.provider==="plane"){let r=`api/v1/workspaces/${e.workspace}/projects/${e.projectId}/work-items/`,o=To(e.baseUrl,r);return o.searchParams.set("per_page","1"),o.searchParams.set("fields","id"),o}let t=To(e.baseUrl,"api/rpc/command/get-file-summary");return t.searchParams.set("id",e.fileId),t}function jd(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 Nd(e){if(!e.headers.get("content-type")?.toLowerCase().startsWith("application/json"))throw await e.body?.cancel(),new ze("Expected an application/json response from the service.");let r=e.body?.getReader();if(!r)throw new ze("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>Ad)throw await r.cancel(),new ze("The service response exceeded the 128 KiB verification limit.");o.push(s.value)}}finally{r.releaseLock()}}async function Td(e,t){let r=await t(To(e.baseUrl,"./"),{method:"HEAD",redirect:"manual",signal:AbortSignal.timeout(1e4)});return await r.body?.cancel(),r.status}async function Dd(e,t,r){let o=await r(Id(e),{method:"GET",headers:jd(e,t),redirect:"error",signal:AbortSignal.timeout(1e4)});if(!o.ok)throw await o.body?.cancel(),new ze(`The selected resource returned HTTP ${o.status}. Confirm the target and its read permission.`);let n=await Nd(o),s=e.provider==="plane"?Rd:Cd,i=!1;try{i=s.safeParse(JSON.parse(n)).success}catch(c){throw new ze("The service returned invalid JSON.",{cause:c})}if(!i)throw new ze("The response does not match the expected resource read.");return o.status}async function Fo(e,t={}){let r=Zd.parse(e),{connection:o}=Do(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 Dd(o,s,a);return{...c,connectivity:"reachable",read:"verified",httpStatus:u}}catch(u){let p=u instanceof ze?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 Td(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 Fd}from"node:crypto";import{constants as vu,createReadStream as Ld,openSync as Md}from"node:fs";import{join as Wd,relative as wu,resolve as Ud}from"node:path";var bu=xe.refine((e)=>e.startsWith("harness-snapshots/"),{message:"Keep native service exports in the workspace harness-snapshots directory."}),Bd=k().regex(/^[a-f0-9]{64}$/),Vd=O({path:bu,bytes:cr().int().positive(),sha256:Bd}),Jd=O({root:k().min(1),project:Se,service:tt}),_u=O({schema:K(1),project:Se,service:tt,files:P(Vd).min(1).max(30)}).refine((e)=>new Set(e.files.map((t)=>t.path)).size===e.files.length,"Duplicate snapshot paths.");function ku(e,t){let r=Ud(e,t),o=bu.parse(wu(e,r)),n=e,s=o.split("/");for(let[i,c]of s.entries()){n=Wd(n,c);let a=ve(n);if(!(i===s.length-1?a?.isFile():a?.isDirectory()))throw Error(`Expected a regular nonsymlink snapshot path at ${n}.`)}return r}async function $u(e,t){let r=ku(e,t),o=ve(r);if(!o?.isFile()||o.size===0)throw Error(`Expected a nonempty snapshot file at ${r}.`);let n=Fd("sha256");try{let i=Md(r,vu.O_RDONLY|vu.O_NOFOLLOW),c=Ld(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=ve(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:wu(e,r),bytes:o.size,sha256:n.digest("hex")}}function Su(e){let{root:t,receipt:r,connection:o}=Do(Jd.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 Lo(e){let t=Su({root:e.root,project:e.project,service:e.service}),r=P(k().min(1)).min(1).max(30).parse(e.paths),o=[];for(let n of r)o.push(await $u(t,n));return _u.parse({schema:1,project:e.project,service:e.service,files:o})}async function Mo(e){let t=Su({root:e.root,project:e.project,service:e.service}),r=ku(t,e.manifestPath),o=_u.parse(we(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 $u(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{resolve as Wo}from"node:path";import{lstatSync as Hd,readdirSync as Pu}from"node:fs";import{basename as zu,resolve as St}from"node:path";var Kd=me({name:k().optional(),workspaces:ar([P(k()),me({packages:P(k())})]).optional()}),Gd=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 qd(e){let t=R(e,"package.json");if(!t)return;try{return Kd.parse(JSON.parse(t.bytes.toString("utf8")))}catch(r){throw Error(`Cannot read ${St(e,"package.json")}. Correct the manifest and retry.`,{cause:r})}}function Pe(e,t){if(t===".")return e;oe(t);let r=ge(St(e,t));if(!zo(e,r)||r!==St(e,t))throw Error(`Choose a real directory inside ${e}. The repository path resolves through a symbolic link: ${t}.`);if(J(r)?.root!==r)throw Error(`Choose the Git repository root at ${r} before registering it.`);return r}function Xd(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=St(e,o.name);if(!Hd(St(n,".git"),{throwIfNoEntry:!1}))continue;if(J(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 Fe(e){let t=ge(e),r=J(t),o=Xd(t),n=new Set(Pu(t)),s=qd(t),i=Boolean(s?.workspaces||n.has("pnpm-workspace.yaml")||n.has("lerna.json")),c=[...Gd].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??zu(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??zu(t),...a};return{root:t,kind:u?"blank":"existing",monorepo:i,repositories:[p],...a}}var Yd=B(["bun","npm","pnpm","yarn"]),Qd=/^(bun|npm|pnpm|yarn)@[^\s]+$/u,eh=me({packageManager:k().regex(Qd).optional()}),th=me({devDependencies:me({"@biomejs/biome":k().regex(/^\d+\.\d+\.\d+$/u)})}),rh=me({root:K(!0),formatter:bt(k(),ur()),javascript:bt(k(),ur()),assist:bt(k(),ur()),linter:bt(k(),ur())}),oh=[{manager:"bun",names:["bun.lock","bun.lockb"]},{manager:"npm",names:["package-lock.json","npm-shrinkwrap.json"]},{manager:"pnpm",names:["pnpm-lock.yaml"]},{manager:"yarn",names:["yarn.lock"]}];function Ou(e,t){let r=Se.parse(t),{root:o,receipt:n}=Te(e);if(r!=="."&&!n.repositories.some(({path:x})=>x===r))throw Error(`Register ${r} before planning its Biome setup.`);let s=Pe(o,r),i=["biome.json","biome.jsonc"].filter((x)=>Boolean(R(s,x))),c=i[0];if(i.length>1)throw Error(`Choose the authoritative Biome configuration in ${s} before adopting changes.`);if(c)return{directory:s,existing:c};if(!R(s,"package.json"))throw Error(`Expected package.json in ${s}. Select the applicable code project or its isolated check.`);let{packageManager:a}=eh.parse(we(Wo(s,"package.json"))),u=oh.filter(({names:x})=>x.some((w)=>Boolean(R(s,w)))),p=a?.split("@")[0],l=p??u[0]?.manager??"bun";if(u.length>1||p&&u.length&&u[0]?.manager!==p)throw Error(`Confirm the project's package manager in ${s}. Declare it in package.json or use its existing lockfile.`);let f=Yd.parse(l),h=th.parse(we(Wo(o,"llm/author-style/package.json"))).devDependencies["@biomejs/biome"],d=rh.parse(we(Wo(o,"llm/author-style/biome-core.json"))),g=`@biomejs/biome@${h}`;return{directory:s,install:f==="npm"?["npm","install","--save-dev","--save-exact",g]:[f,"add","--dev","--exact",g],path:"biome.json",config:d}}import{closeSync as Zu,constants as Uo,fstatSync as Ru,lstatSync as Cu,openSync as nh,readSync as sh,realpathSync as ih}from"node:fs";import{isAbsolute as Iu,join as ch}from"node:path";var ah=262144,uh=new Set([".aws",".git",".gnupg",".npm",".ssh","credentials","node_modules","passwords","private","processing","raw","secret","secrets"]);function ju(e){let t=e.toLowerCase(),r=t.replace(/(?:\.llm)?\.md$/,"");return t.startsWith(".env")||uh.has(r)}function ph(e){if(Iu(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(ju(r))throw Error(`The path crosses a protected location at "${r}".`)}return t}function Au(e,t){if(!Iu(e))throw Error("Provide an absolute project root.");if(!Cu(e).isDirectory())throw Error("The project root must be a directory.");let r=ih(e);if(r.split("/").filter(Boolean).some((s,i)=>(i!==0||s!=="private")&&ju(s)))throw Error("The project root crosses a protected location.");let n;for(let[s,i]of t.entries()){if(r=ch(r,i),n=Cu(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 lh(e,t,r,o){let n=Ru(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=sh(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=Ru(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 fh(e,t,r,o){let n;try{n=lh(e,t,r,o)}catch(s){try{Zu(e)}catch(i){throw AggregateError([s,i],"Reading and closing the file both failed.")}throw s}return Zu(e),n}function ot(e,t,r,o){try{let n=ph(t),{path:s,info:i}=Au(e,n),c=nh(s,Uo.O_RDONLY|Uo.O_NOFOLLOW|Uo.O_NONBLOCK),a=fh(c,i,r,o),u=Au(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 Le(e,t){if(!t.toLowerCase().endsWith(".md"))throw Error("Provide a relative Markdown path inside the project root.");return ot(e,t,ah,"Markdown context")}function Nu(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}function Tu(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 dh(e){let t=/^ {0,3}(`{3,}|~{3,})/.exec(e)?.[1];if(t)return{marker:t.charAt(0),length:t.length};return}function hh(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 mh(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 Tu(s,o.length,t)}return}function gh(e){if(!e.trim()||/^(?: {4}|\t)/.test(e))return!1;return!/^ {0,3}(?:[>#<]|[-+*][ \t]|\d+[.)][ \t]|\[[^\]]+\]:|(?:[*_-][ \t]*){3,})/.test(e)}function Du(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(hh(a,r))r=void 0;continue}if(n||a.trimStart().startsWith("<!--")){n=!a.includes("-->"),o=void 0;continue}if(r=dh(a),r){o=void 0;continue}let p=mh(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(" "),h=l.startsWith("=")?1:2;t.push(Tu(f,h,o.line)),o=void 0;continue}if(!gh(a)){o=void 0;continue}if(!o)o={line:u,lines:[]};o.lines.push(a.trim())}return t}var Bo=k().min(1).refine((e)=>!/[\x00-\x1f\x7f]/.test(e),"Control characters are not allowed."),yh=O({root:Bo.max(4096),file:Bo.max(4096),section:Bo.max(512).optional()}),Fu=128,Lu=16384;function xh(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 Mu(e,t){if(Buffer.byteLength(e)>Lu)throw Error(`Context output exceeds ${Lu} bytes. ${t}`)}function Wu(e){let t=yh.parse(e),r=Nu(Le(t.root,t.file)),o=Du(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 Mu(JSON.stringify(u),"Request a known section or use a narrower map."),u}let n=xh(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 Mu(JSON.stringify(a),"Choose a smaller child section or a narrower map."),a}import{realpathSync as zh}from"node:fs";import{isAbsolute as Ho,normalize as Ph,relative as Eh,resolve as Oh}from"node:path";var Bu=B(["lines","functions","branches"]),vh=B(["LF","LH","FNF","FNH","BRF","BRH"]),wh={lines:{found:"LF",hit:"LH"},functions:{found:"FNF",hit:"FNH"},branches:{found:"BRF",hit:"BRH"}};function Vu(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 M(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 zt(e,t,r){if(e.has(t))throw Error("Duplicate coverage entry.");e.set(t,r)}function Uu(e,t){if(e.has(t))throw Error("Duplicate coverage identity.");e.add(t)}function bh(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=M(r,1);if(n!==void 0)M(n,i);zt(e.lines,String(i),M(o,0)>0)}function _h(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([M(o,1),M(c,0),a===void 0?null:M(a,0),/^\d+$/.test(s)?M(s,0):s]);zt(e.branches,u,i!=="-"&&M(i,0)>0)}function kh(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=M(n,1);if(s)M(s,c);Uu(e.functionNames,i);return}if(t==="FNL"&&s){let c=M(s,1);if(i)M(i,c);Uu(e.groupIds,String(M(n,0)));return}throw Error("Malformed function definition.")}function $h(e,t,r){if(t==="FNDA"){let[,a,u]=/^(\d+),(.+)$/.exec(r)??[];if(!a||!u)throw Error("Expected a function hit count and name.");zt(e.functionHits,u,M(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(M(o,0)),c=e.aliasHits.get(i)??new Map;zt(c,s,M(n,0)>0),e.aliasHits.set(i,c)}function Ju(e,t,r){let o=vh.safeParse(t);if(o.success){zt(e.summaries,o.data,M(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 bh(e,r);case"BRDA":return _h(e,r);case"FN":case"FNL":return kh(e,t,r);case"FNDA":case"FNA":return $h(e,t,r);default:throw Error("Unsupported LCOV field. Export a line, function and branch report.")}}function Vo(e){let t=0;for(let r of e.values())if(r)t+=1;return{found:e.size,hit:t}}function Sh(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 Vo(e.functionHits)}function Hu(e,t){let r=wh[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=Vo(e.lines);break;case"functions":s=Sh(e);break;case"branches":s=Vo(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 mr=k().min(1).max(4096).refine((e)=>!/[\x00-\x1f\x7f]/.test(e)),Zh=O({root:mr,file:mr,config:mr}),Rh=O({files:P(mr).min(1).max(1e4),metrics:P(Bu).min(1).max(3)});function Jo(e){if(Ho(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 Ku(e,t){let r=Eh(e,t);if(!r||r===".."||r.startsWith("../")||Ho(r))return;return r}function Ch(e,t,r){if(!e||/[\\:\x00-\x1f\x7f]/.test(e))throw Error("Expected a valid source path in the LCOV record.");if(Ho(e)){let o=Ku(t,e)??Ku(r,e);if(o)return Jo(o);throw Error("An LCOV source is outside the project root.")}return Jo(Ph(e))}function Ah(e,t){for(let[r,o]of t)try{let n=Hu(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 Ih(e,t,r,o){let n=zh(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),[,h,d]=/^(\d+),(.*)$/.exec(f)??[],g=Ch(d??f,t,n);if(h!==void 0){let y=Number(h);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=Vu(g),a=!1}else if(l==="end_of_record"&&c)Ah(c,o),s.add(c.source),c=void 0;else if(c){let f=l.indexOf(":");if(f<1)throw Error("Malformed LCOV field.");Ju(c,l.slice(0,f),l.slice(f+1))}else throw Error("Expected an LCOV source record.")}catch(f){let h=f instanceof Error?f.message:String(f);throw Error(`LCOV line ${p+1}. ${h}`,{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 Gu(e){let t=Zh.parse(e),r=ot(t.root,t.config,262144,"coverage configuration"),o;try{o=Rh.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(Jo)),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=ot(t.root,t.file,16777216,"LCOV report");Ih(i,Oh(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 jh}from"node:fs";import{resolve as Nh}from"node:path";var Th=O({root:k().min(1),threshold:cr().int().nonnegative(),files:P(xe).max(200),important:P(xe).max(200)});function qu(e){let{root:t,threshold:r,files:o,important:n}=Th.parse(e),s=new Set(n),i=[...new Set([...o,...n])].sort();if(!i.length)throw Error("Supply a changed implementation with --file or --important.");return i.map((c)=>{let a=ot(t,c,1048576,"authored implementation"),u=a.length?a.replace(/(?:\r\n|\r|\n)$/u,"").split(/\r\n|\r|\n/u).length:0,p=`${c}.llm.md`,l=jh(Nh(t,p),{throwIfNoEntry:!1});if(l)Le(t,p);return{file:c,lines:u,map:p,exists:Boolean(l),required:s.has(c)||u>r}})}import{lstatSync as pp}from"node:fs";import{relative as up,resolve as Ee}from"node:path";import{lstatSync as Qu}from"node:fs";import{resolve as nt}from"node:path";function Dh(e,t,r,o=!1){let n=`# appToolkit harness ${t} begin`,s=`# appToolkit harness ${t} end`,i=e.includes(`\r
66
+ `)?`\r
67
+ `:`
68
+ `,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 h of c.slice(a+1,u)){if(!h.startsWith("/"))throw Error(`The existing appToolkit local exclusion block ${t} contains an unsupported pattern.`);p.add(h)}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 Ko(e,t,r,o=!1){let n=R(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 ${nt(e.commonDirectory,e.exclude)}.`);let i=Dh(s,t,r,o),c=i||n?T(i,n?.mode):null;if(ae(n,c))return;return{base:e.commonDirectory,path:e.exclude,before:n,after:c}}function Xu(e,t){let r=new Map,o=J(e);if(o)r.set(".",o);for(let n of t){if(n.path===".")continue;let s=nt(e,n.path);if(!Qu(s,{throwIfNoEntry:!1})?.isDirectory())continue;let c=J(s);if(c?.root===s)r.set(n.path,c)}return r}function Yu(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 ep(e,t,r,o,n,s){let i=Xu(e,t.repositories),c=new Map,a=[],u=[];if(r){let g=Xu(e,r.repositories);for(let y of g.values())c.set(y.commonDirectory,{scope:y,patterns:new Set});for(let y of n){let x=nt(e,y),w=Yu(y,g);je(x,w?.root),u.push(w?{absolute:x,gitRoot:w.root}:{absolute:x})}}let p=[...t.files,...s.map((g)=>({path:g,versioned:!1})),{path:"llm/harness/workspace.json",versioned:t.workspaceVersioned},{path:"llm/harness/project.json",versioned:t.workspaceVersioned}];if(!t.workspaceVersioned)for(let g of["KNOWLEDGE.md","TOOLS.md","IMPROVEMENTS.md"])p.push({path:`llm/harness-local/${g}`,versioned:!1});let l=t.repositories.filter(({path:g})=>!Qu(nt(e,g),{throwIfNoEntry:!1}));for(let g of p){if(l.some(({path:I})=>g.path.startsWith(`${I}/`)))continue;let y=Yu(g.path,i),x=nt(e,g.path);if(je(x,y?.root),u.push(y?{absolute:x,gitRoot:y.root}:{absolute:x}),!y)continue;let w=ye(y.root,x);if(a.push({git:y,path:w,absolute:x,versioned:g.versioned}),g.versioned)continue;if(Ye(y,x)){o.push({path:g.path,reason:"Git already tracks this file. Choose versioned mode or separately remove it from the index before retrying."});continue}let S=c.get(y.commonDirectory)??{scope:y,patterns:new Set};S.patterns.add($t(w)),c.set(y.commonDirectory,S)}let f=i.get(".");if(f){let g=t.workspaceVersioned?"llm/harness-local/update-history":"llm/harness-local",y=ye(f.root,nt(e,g)),x=c.get(f.commonDirectory)??{scope:f,patterns:new Set};x.patterns.add(`${$t(y)}/`),c.set(f.commonDirectory,x)}let h=[],d=t.installation??V(e).slice(0,16);for(let{scope:g,patterns:y}of c.values()){let x=Ko(g,d,y);if(x)h.push(x)}return{operations:h,checks:a,boundaries:u}}import{lstatSync as Fh,readdirSync as Lh}from"node:fs";import{resolve as tp}from"node:path";var rp=4096,Mh=67108864,Wh=new Set([".git","node_modules","raw","processing",".npmrc"]);function op(e){if(!e)throw Error("The release content directory is required for install and update.");let t=ge(e),r=new Map,o=["."],n=0;while(o.length){let s=o.pop();if(!s)break;let i=Lh(tp(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),Wh.has(c.name)||/^\.env(?:$|\.(?!example$))/u.test(c.name))throw Error(`The release payload includes an unsupported private path: ${a}.`);if(c.isDirectory()&&!Fh(tp(t,a)).isSymbolicLink()){if(o.length+r.size>=rp||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()||u.startsWith("llm/harness-local/")||!Ro(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>=rp||n>Mh)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 gr="llm/harness/project.json";function np(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=R(e,gr);if(!i)return;try{let c=Ne.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:gr,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=T(`${JSON.stringify(Ne.parse({...c,projects:a}),null,2)}
69
+ `,i.mode);return{base:e,path:gr,before:i,after:u}}catch(c){throw Error(`Cannot reassign the project settings in ${gr}. Restore a valid settings file before retrying.`,{cause:c})}}import{lstatSync as Go}from"node:fs";import{basename as Uh,relative as Bh,resolve as Pt}from"node:path";var qo="<!-- apptoolkit-harness:begin -->",yr="<!-- apptoolkit-harness:end -->";function xr(e){return["AGENTS.md","AGENTS.override.md","CLAUDE.md","opencode.json","opencode.jsonc","opencode-instructions.md"].includes(Uh(e))||e===".claude/rules/apptoolkit.md"||e.endsWith("/.claude/rules/apptoolkit.md")}function Vh(e,t){let r=e.indexOf(qo),o=e.indexOf(yr);if(r===-1&&o===-1)return;if(r<0||o<=r||e.lastIndexOf(qo)!==r||e.lastIndexOf(yr)!==o)throw Error(`The AppToolkit router block in ${t} is malformed. Review its markers before retrying.`);let n=o+yr.length;return{prefix:e.slice(0,r),old:e.slice(r,n),suffix:e.slice(n)}}function Jh(e,t,r,o,n,s,i,c){let a;try{a=R(e,t)}catch(S){if(!(S instanceof lr))throw S;i.push(`Automatic discovery needs a regular native instructions file at ${t}. Preserved the existing path.`);return}let u=a?.bytes.toString("utf8")??"",p=n?.files.find((S)=>S.path===t)?.fragment,l=u.includes(`\r
70
+ `)?`\r
71
+ `:`
72
+ `,f=[qo,r.trimEnd().replaceAll(`
73
+ `,l),yr].join(l),h=V(f);if(a&&!Buffer.from(u).equals(a.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=Vh(u,t),g=d?V(d.old):null,y=c?.find((S)=>S.path===t&&S.local===g&&S.incoming===h),x=n?.files.find((S)=>S.path===t)?.retainedAgainst;if(!d&&a&&(x===h||y?.choice==="local"))return{content:a,versioned:o,observed:a,retainedAgainst:h};if((p||x)&&!d&&y?.choice!=="release"){s.push({path:t,reason:"The previously installed router block was removed. Restore or reconcile it before updating.",local:g,incoming:h});return}if(d){let S=g!==h&&(g!==p||x!==void 0&&x!==h);if(y?.choice==="local"&&g)return{content:T(u,a?.mode),versioned:o,fragment:g,observed:a,retainedAgainst:h};if(g&&g===p&&x===h)return{content:T(u,a?.mode),versioned:o,fragment:g,observed:a,retainedAgainst:h};if(S&&y?.choice!=="release"){s.push({path:t,reason:"The existing router block has local edits. Reconcile it before applying the release.",local:g,incoming:h});return}if(!p&&!o&&!y&&(d.prefix||d.suffix!==l)){i.push(`Preserved the existing ${t}. Review its local bootstrap before relying on automatic discovery.`);return}return{content:T(`${d.prefix}${f}${d.suffix}`,a?.mode),versioned:o,fragment:h,observed:a,replaced:S}}if(a&&!o&&y?.choice!=="release"){i.push(`Preserved the existing ${t} in local mode.`);return}let w=u;if(u&&!u.endsWith(`${l}${l}`))w=u.endsWith(l)?`${u}${l}`:`${u}${l}${l}`;return{content:T(`${w}${f}${l}`,a?.mode),versioned:o,fragment:h,observed:a,replaced:y?.choice==="release"}}function sp(e,t,r,o,n,s){let i=new Map,c=new Map([[".",t.workspaceVersioned]]);for(let a of t.repositories)if(a.path!=="."&&Go(Pt(e,a.path),{throwIfNoEntry:!1}))c.set(a.path,t.workspaceVersioned&&a.versioned);for(let[a,u]of c){let p=(h)=>a==="."?h:`${a}/${h}`,l=Bh(Pt(e,a),Pt(e,"llm/HARNESS.md")),f=(h,d,g=u,y=n)=>{let x=Jh(e,h,d,g,r,o,y,s);if(x)i.set(h,x);return Boolean(x)};for(let{path:h,content:d}of $o(t.hosts,l)){let g=p(h);if(h==="CLAUDE.md"){let S=p(".claude/rules/apptoolkit.md"),I=r?.files.some((z)=>z.path===S),b=[];if(I||!u&&!f(g,d,u,b))if(f(S,d,!1))n.push(`Claude loads ${S} alongside the preserved project guidance.`);else n.push(...b);else if(u)f(g,d);continue}let y=f(g,d),x=p("AGENTS.override.md"),w=Go(Pt(e,x),{throwIfNoEntry:!1});if(t.hosts.includes("codex")&&(w||!y&&!u)){let S=`Before acting, read the sibling AGENTS.md if present. It contains the project's existing instructions.
74
+
75
+ ${d}`;if(!f(x,S,!1)&&w)n.push(`Codex prioritizes ${x}. Confirm a bootstrap there before relying on automatic discovery.`)}if(!y&&!u&&t.hosts.includes("opencode")){let S=[".opencode/opencode.json",".opencode/opencode.jsonc","opencode.json","opencode.jsonc"].map(p),b=S.find((z)=>r?.files.some((_)=>_.path===z))??S.find((z)=>!Go(Pt(e,z),{throwIfNoEntry:!1}));if(b){let _=`${JSON.stringify({instructions:["llm/harness-local/opencode-instructions.md"]},null,2)}
76
+ `;i.set(b,{content:T(_),versioned:!1}),i.set(p("llm/harness-local/opencode-instructions.md"),{content:T(`${d}
77
+ `),versioned:!1})}else n.push(`All native OpenCode configuration paths are occupied for ${a}. Keep tracked configuration intact and confirm a local route during init.`)}}}return i}import{lstatSync as Hh}from"node:fs";import{basename as Kh,resolve as ip}from"node:path";function Et(e,t){return!Hh(ip(e,t),{throwIfNoEntry:!1})}function Xo(e,t){let r=ye(e,ip(e,t));if(r!==".")oe(r);return r}function cp(e,t,r){let o=Pe(e,t),n=J(o);if(r&&!n)throw Error(`Cannot version files in ${o} because Git does not manage this directory.`);let s=n&&tu(n.root);return s?{path:t,versioned:r,identity:s}:{path:t,versioned:r}}function Gh(e,t,r){let o=t.repository;if(!o)throw Error("Specify the directory of the Git repository to register.");let n=Xo(e,o);if(r.repositories.find((p)=>p.path===n)&&!Et(e,n))return Pe(e,n),r.repositories;if(Et(e,n)){let p=r.repositories.filter((f)=>Kh(f.path)===o),l=p[0];if(l&&p.length===1&&!Et(e,l.path))return Pe(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)=>Xo(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=cp(e,n,i),a=r.repositories.filter((p)=>c.identity&&p.identity===c.identity&&Et(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 ap(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 Gh(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=Xo(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&&Et(o,a))i.set(a,{...u,versioned:c.versioned});else i.set(a,cp(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 qh}from"node:path";var Xh=O({root:k().min(1),repository:k().min(1),file:k().endsWith(".llm.md")}),Yo=new WeakMap;function Qo(e){let t=Xh.parse(e),r=ge(t.root),o=R(r,W),n=ee(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=Pe(r,s.path),c=fr(i,t.file),a=J(i);je(c,a?.root);let u={root:r,writes:[],conflicts:[]},p=[{base:r,path:W,before:o,after:o}],l=[a?{absolute:c,gitRoot:a.root}:{absolute:c}];if(!ae(o,R(r,W)))throw Error("The installation receipt changed while planning. Retry the artifact command.");if(!a)return Yo.set(u,{exclusions:[],files:[],checks:[],guards:p,boundaries:l}),u;if(Ye(a,c))u.conflicts.push({path:t.file,reason:"Git already tracks this file. Resolve its index status before choosing local mode."});let f=ye(a.root,c),h=n.installation??V(r).slice(0,16),d=Ko(a,`${h} artifacts`,new Set([$t(f)]),!0),g=d?[d]:[];if(d)u.writes.push({path:qh(d.base,d.path),before:d.before?.hash??null,after:d.after?.hash??null});return Yo.set(u,{exclusions:g,files:[],checks:[{git:a,path:f,absolute:c,versioned:!1}],guards:p,boundaries:l}),u}function en(e){let t=Yo.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:Oo(e.root,t)}}function Yh(e,t){let r=Ee(e,t,"llm"),o=up(r,Ee(e,"llm/HARNESS.md"));return["# Harness context","",`Start from the workspace folder at \`${up(Ee(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.","Prefer deterministic tools and improve repeatable work and noisy command output.","Retrieve and maintain indexed project knowledge and sibling .llm.md source maps as you work.",""].join(`
78
+ `)}function Qh(e){let t=[["llm/harness-local/KNOWLEDGE.md",`# Project knowledge
79
+
80
+ Index durable findings by topic and repository. Link to the smallest useful record and include search terms, status and revalidation triggers.
81
+ `],["llm/harness-local/TOOLS.md",`# Project tools
82
+
83
+ Index project runners, deterministic utilities and output filters. Record invocation, inputs, outputs, effects, tests and recovery.
84
+ `],["llm/harness-local/IMPROVEMENTS.md",`# Project improvements
85
+
86
+ Index verified harness changes and pending decisions. Record the trigger, evidence, scope, outcome, checks and rollback route.
87
+ `]],r=[];for(let[o,n]of t)if(o&&n&&!R(e,o))r.push({base:e,path:o,before:null,after:T(n)});return r}function em(e,t,r,o,n,s){let i=new Map;if(t.action!=="add-repo"){for(let[l,f]of op(t.contentDirectory))i.set(l,{content:f,versioned:r.workspaceVersioned});for(let l of So(r.hosts,r.version))i.set(l.path,{content:T(l.content),versioned:r.workspaceVersioned});let c="llm/README.md",a=R(e,c),u=o?.files.some((l)=>l.path===c),p=T(`# LLM workspace
88
+
89
+ Open the [harness index](HARNESS.md) for workspace rules, project routing, workflows and tools.
90
+ `);if(!a||u||a.hash===p.hash)i.set(c,{content:p,versioned:r.workspaceVersioned})}for(let[c,a]of sp(e,r,o,n,s,t.resolutions))i.set(c,a);for(let c of r.repositories){if(!pp(Ee(e,c.path),{throwIfNoEntry:!1}))continue;let a=et(c.path),p=o?.files.find((l)=>l.path===a)?.versioned??(r.workspaceVersioned&&c.versioned);if(p&&!r.workspaceVersioned)s.push(`The existing versioned context map ${a} points to a local harness. Review its Git scope during init if it should become private.`);i.set(a,{content:T(Yh(e,c.path)),versioned:p})}return i}function tm(e,t,r,o,n,s){let i=[],c=[],a=new Map(n.resolutions?.map((d)=>[d.path,d])),u=new Map,p=new Map(o?.files.map((d)=>[d.path,d])),l=new Set(o?.repositories.map((d)=>et(d.path))),f=[...new Set([...r.repositories,...o?.repositories??[]].map(({path:d})=>d))].filter((d)=>!pp(Ee(e,d),{throwIfNoEntry:!1}));function h(d,g){let y=`llm/harness-local/update-history/${V(d)}/${g.hash}`,x=`${JSON.stringify({path:d,sha256:g.hash},null,2)}
91
+ `,w=new Map([[`${y}.bak`,T(g.bytes,384)],[`${y}.json`,T(x,384)]]);for(let[S,I]of w){let b=R(e,S);if(b&&b.hash!==I.hash)throw Error(`Update history differs from its expected hash at ${S}. Restore it before retrying.`);let z={base:e,path:S,before:b,after:I};if(b)c.push({...z,after:b});else u.set(S,z)}}for(let[d,{content:g,versioned:y,fragment:x,observed:w,replaced:S,retainedAgainst:I}]of t){let b=R(e,d),z=p.get(d),_=T(g.bytes,b?.mode??g.mode);if(w!==void 0&&!ae(b,w))throw Error(`The native router ${d} changed while planning. Retry the workspace command.`);let Ue=!x&&I===void 0&&b&&b.hash!==_.hash&&(b.hash!==z?.hash||z.retainedAgainst!==void 0&&z.retainedAgainst!==_.hash),pe=a.get(d);if(!x&&I===void 0&&b&&(Ue||z?.retainedAgainst===_.hash)&&(pe?.choice==="local"&&pe.local===b.hash&&pe.incoming===_.hash||b.hash===z?.hash&&z.retainedAgainst===_.hash)){r.files.push({path:d,hash:b.hash,versioned:y,retainedAgainst:_.hash}),c.push({base:e,path:d,before:b,after:b});continue}let Be=b&&pe?.choice==="release"&&pe.local===b.hash&&pe.incoming===_.hash;if(Ue&&!Be)s.push({path:d,reason:"Local changes differ from this release. Compare the files and select the applicable version.",local:b.hash,incoming:_.hash});else if(!ae(b,_)){if(b&&(Be||S))h(d,b);i.push({base:e,path:d,before:b,after:_})}else c.push({base:e,path:d,before:b,after:b});r.files.push({path:d,hash:_.hash,versioned:y,...x?{fragment:x}:{},...I?{retainedAgainst:I}:{}})}for(let d of p.values()){if(t.has(d.path))continue;if(f.some((w)=>d.path.startsWith(`${w}/`))){if(r.repositories.some(({path:w})=>d.path.startsWith(`${w}/`)))r.files.push(d);continue}if(xr(d.path)||n.action==="add-repo"&&!l.has(d.path)){r.files.push(d);continue}let g=R(e,d.path);if(!g)continue;let y=a.get(d.path),x=y?.local===g.hash&&y.incoming===null;if(x&&y.choice==="local"||g.hash===d.hash&&d.retainedAgainst===null){r.files.push({...d,hash:g.hash,retainedAgainst:null}),c.push({base:e,path:d.path,before:g,after:g});continue}if((g.hash!==d.hash||d.retainedAgainst!==void 0)&&!x){s.push({path:d.path,reason:"The release retires this file, but it has local edits. Preserve the changes before updating.",local:g.hash,incoming:null});continue}if(x)h(d.path,g);i.push({base:e,path:d.path,before:g,after:null})}return r.files.sort((d,g)=>d.path.localeCompare(g.path,"en")),{files:[...u.values(),...i],guards:c}}function lp(e){let t=hr.parse(e);if(t.resolutions?.length&&t.action!=="update")throw Error("Conflict decisions apply only to an update.");let r=Fe(t.root),{root:o}=r,n=R(o,W),s=ee(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=ap(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??V(o).slice(0,16),files:[]},p=[],l=[],f=em(o,t,u,s,p,l);if(l.length)u.bootstrapNotices=[...l];let{files:h,guards:d}=tm(o,f,u,s,t,p);if(h.push(...Qh(o)),i){let _=np(o,s,u,p);if(_)h.push(_)}let g=h.filter((_)=>_.after===null).map((_)=>_.path),y=[...h,...d].filter(({path:_})=>_.startsWith("llm/harness-local/update-history/")).map(({path:_})=>_),x=ep(o,u,s,p,g,y),w=new Set(x.checks.filter((_)=>!_.versioned&&_.git.commonDirectory!==Ee(_.git.root,".git")).map((_)=>_.git.commonDirectory));for(let _ of w)l.push(`Local Git exclusions use ${Ee(_,"info/exclude")}. Linked worktrees that share this Git directory use the same exclusions.`);let S=T(`${JSON.stringify(u,null,2)}
92
+ `,n?.mode);if(!ae(n,R(o,W)))throw Error("The installation receipt changed while planning. Retry the workspace command.");let I=ae(n,S)?[]:[{base:o,path:W,before:n,after:S}],b=[...x.operations,...h,...I].map((_)=>({path:_.base===o?_.path:Ee(_.base,_.path),before:_.before?.hash??null,after:_.after?.hash??null})),z={root:o,...r.gitRoot?{gitRoot:r.gitRoot}:{},action:t.action,writes:b,conflicts:p,notices:l,receipt:u};return su(z,{exclusions:x.operations,files:h,checks:x.checks,guards:[{base:o,path:W,before:n,after:n},...d],...I[0]?{receipt:I[0]}:{},boundaries:x.boundaries}),z}import{parseArgs as rm}from"node:util";var Me=B(["codex","claude","opencode"]),Ot={codex:"Codex",claude:"Claude Code",opencode:"OpenCode"},We=B(["plane","penpot"]);function fp(e){let t=rm({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"},resolutions:{type:"string"},threshold:{type:"string"},important:{type:"string",multiple:!0},"verify-maps":{type:"boolean"}}}),{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 G(e,t){return k().min(1,`Supply ${t}.`).parse(e??"")}function dp(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 hp}from"node:fs";var om=O({kind:k().min(1),title:k().min(1).optional(),headings:P(k().min(1)).default([]),checkedItems:P(k().min(1)).default([]),requiredText:P(k().min(1)).default([]),forbiddenText:P(k().min(1)).default([])});function nm(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 mp(e,t){let r=om.parse(JSON.parse(hp(e,"utf8"))),o=hp(t,"utf8"),n=nm(o),s=n.join(`
93
+ `),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 vr}from"node:path";import{basename as sm,isAbsolute as im,relative as cm,resolve as am}from"node:path";var Zt=new Intl.ListFormat("en"),gp={plane:"Plane for work items",penpot:"Penpot for design"};function um(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 pm(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 lm(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=Zt.format(o.map((c)=>gp[c]));s.push(`Offer ${i} during agent setup. Each connection is configured separately.`)}if(n.length){let i=Zt.format(n.map((c)=>gp[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 fm(e){let{writes:t}=e,r=t.filter(({after:f})=>f!==null),o=r.filter(({path:f})=>xr(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})=>et(f))),c=new Set(["llm/HARNESS.md","llm/README.md"]),a="llm/harness/project.json",u=[],p=r.filter(({path:f})=>{let h=f.startsWith("llm/harness/")&&f!==W&&f!=="llm/harness/project.json";return c.has(f)||f.startsWith("llm/author-style/")||h});if(p.length){let f=p.every(({before:h})=>h===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 ${Zt.format(n)} so your agents can find the harness.`);if(s.length)u.push(`Update the harness section in ${Zt.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})=>im(f)))u.push("Update the local Git ignore rules for the generated harness files.");if(r.some(({path:f})=>f===W))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 dm(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=cm(e.root,am(e.root,r))||".";if(o.includes(s))return s;return o.find((i)=>sm(i)===r)??s}function yp(e,t,r){let o=e.action==="add-repo"?dm(e,t,r):"",n=Me.options.filter((a)=>e.receipt.hosts.includes(a)),s=Zt.format(n.map((a)=>Ot[a])),i=e.action==="add-repo"?[]:lm(e,t),c=[um(e,t,o),`The harness will be available in ${s}.`,...pm(e,o),...i,...fm(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 hm=[{label:"Keep harness files local",value:"local"},{label:"Make harness files available to commit",value:"versioned"}],xp=[{label:"No",value:"no"},{label:"Yes",value:"yes"}];async function tn(e,t,r){if(!e)throw Error(`Supply ${r} for a noninteractive run.`);return await e(t,hm)==="versioned"}async function mm(e){let{options:t,selectMany:r}=e;if(t.hosts)return[...new Set(P(Me).min(1).parse(t.hosts.split(",")))];if(!r)throw Error("Supply --hosts codex,claude,opencode or a subset for a noninteractive install.");let o=Me.options.map((s)=>({label:Ot[s],value:s})),n=await r("Which agent hosts should this workspace support?",o,Me.options);return P(Me).min(1).parse(n)}async function gm(e,t){let{options:r,select:o}=e,n=dp(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 tn(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 ym(e){let{root:t,options:r,select:o,emit:n}=e,s=Fe(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 mm(e),c=s.gitRoot?r.versioned||!r.local&&await tn(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 gm(e,s),u=P(We).parse(r["enable-service"]??[]);if(o&&!r["enable-service"]){for(let p of We.options)if(await o(`Offer ${p==="plane"?"Plane for agent work items":"Penpot for design"} during setup?`,xp)==="yes")u.push(p)}return{hosts:i,workspaceVersioned:c,repositories:a,services:[...new Set(u)]}}function xm(e){let t=ee(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 vp(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=ee(o),p=t==="install"&&!u?await ym(e):xm(o),l;if(t==="update"&&s["enable-service"]){let g=P(We).parse(s["enable-service"]);p.services=[...new Set([...p.services,...g])]}if(t==="add-repo"){l=G(r,"the checkout path");let g=vr(o,l),y=p.repositories.find(({path:w})=>vr(o,w)===g),x=s["repo-versioned"]||(s["repo-local"]?!1:y?.versioned??await tn(c,`Version files generated inside ${l}?`,"--repo-local or --repo-versioned"));p.repositories=[...p.repositories.filter(({path:w})=>vr(o,w)!==g),{path:l,versioned:x}]}let f=lp({root:o,action:t,version:n,contentDirectory:a??"",...p,...s.resolutions?{resolutions:hr.shape.resolutions.unwrap().parse(we(vr(s.resolutions)))}:{},...l?{repository:l}:{}}),h={action:t,root:f.root,version:f.receipt.version,writes:f.writes.map(({path:g,before:y,after:x})=>({path:g,effect:x===null?"remove":y===null?"create":"update",before:y,after:x})),conflicts:f.conflicts,notices:f.notices};if(!s.json)for(let g of yp(f,u,l))i(g);if(s.plan||!s.yes&&!c){if(s.json)i(h);return f.conflicts.length?1:0}if(f.conflicts.length){if(s.json)i(h);throw Error("Resolve the reported installation conflicts before applying the plan.")}if(!s.yes&&f.writes.length&&c&&await c("Apply this plan?",xp)!=="yes")return 0;let d=Zo(f);if(s.json)i({...h,changed:d.changed,version:d.receipt.version,hosts:d.receipt.hosts});else if(i(`Applied ${d.changed} change(s) for @apptoolkit/harness ${d.receipt.version}.`),t==="install"){i(`Open ${f.root} in your selected agent host.`);for(let g of d.receipt.hosts)i(` ${Ot[g]}: ${g==="codex"?"$":"/"}apptoolkit init`)}return 0}var wm=`@apptoolkit/harness 1.0.5
94
+
95
+ install Inspect and prepare a project or workspace
96
+ inspect Report workspace topology and installation state
97
+ init --json Print the project setup template for the agent
98
+ init --config <file> Apply validated project choices
99
+ biome-plan Inspect project-wide setup for --project <repo>
100
+ add repo <path> Register a related checkout
101
+ protect <file> Preview or apply a local exclusion for a source map
102
+ update Reconcile this package version with the workspace
103
+ workflow <W01-W37|list> Read a single workflow or the index
104
+ context <file> List headings or read an exact --section
105
+ source-maps Inspect explicit --file and --important paths, use --verify-maps to enforce
106
+ verify document <file> Check a document against a local --config policy
107
+ verify coverage <lcov> Require 100% measured coverage for the configured source scope
108
+ service status <name> Inspect opt-in Plane or Penpot access
109
+ service snapshot <name> Prepare or verify an opt-in snapshot manifest
110
+
111
+ Shared options: --root <path> --json --plan --yes
112
+ Install options: --hosts codex,claude,opencode --local | --versioned
113
+ --repo <path> --repo-mode <path>=local|versioned
114
+ --enable-service plane|penpot
115
+ Add options: --repo-local | --repo-versioned
116
+ Service options: --project <repo> --verify-health --verify-read --manifest <file> | --file <export>
117
+ Use --plan to preview. Noninteractive workspace changes require --yes and explicit choices.
118
+ `;function bm(e,t){if(t==="list")return Le(e,"llm/harness/WORKFLOWS.md");let r=k().regex(/^W(?:0[1-9]|[12][0-9]|3[0-7])$/,"Choose W01 through W37 or list.").parse(t??""),o=Le(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 _m(){let{values:e,positionals:t}=fp(process.argv.slice(2)),[r,o,n,s]=t;if(e.version)return process.stdout.write(`1.0.5
119
+ `),0;if(e.help||!r)return process.stdout.write(wm),0;let i=wr(e.root??vm(new URL("../../../",import.meta.url))),c=(y)=>{if(typeof y==="string")process.stdout.write(`${y.trimEnd()}
120
+ `);else process.stdout.write(`${JSON.stringify(y,null,2)}
121
+ `)};if(r==="inspect"&&!o){let y=Fe(i),x=ee(y.root),S=(x?De(y.root):void 0)?.projects.map(({path:I,budget:b,services:z})=>({path:I,budget:b.mode,services:z.map(({provider:_})=>_)}))??[];return c({...y,installation:x??null,configuredProjects:S}),0}if(r==="init"&&!o){if(!e.config)return c(await jo(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 No({root:i,configPath:wr(e.config)})),0}if(r==="biome-plan"&&!o)return c(Ou(i,G(e.project,"--project <repo>"))),0;if(r==="workflow"&&!n){let y=bm(i,o);return c(e.json?{id:o,document:y}:y),0}if(r==="context"&&!n){let y=G(o,"the workspace-relative Markdown path");return c(Wu({root:i,file:y,...e.section?{section:e.section}:{}})),0}if(r==="source-maps"&&!o){let y=k().regex(/^\d+$/u).transform(Number).parse(e.threshold??"200"),x=qu({root:i,threshold:y,files:e.file??[],important:e.important??[]});if(c(x),e["verify-maps"]&&x.some(({required:w,exists:S})=>w&&!S))return process.stderr.write(`Required sibling source maps are missing. Create the reported maps and verify again.
122
+ `),1;return 0}if(r==="verify"&&o==="document"&&!s){let y=wr(G(e.config,"--config <policy.json>")),x=wr(G(n,"the document path")),w=mp(y,x);return c(w),w.valid?0:1}if(r==="verify"&&o==="coverage"&&!s){let y=G(n,"the workspace-relative LCOV report"),x=G(e.config,"--config <coverage-policy.json>");return c(Gu({root:i,file:y,config:x})),0}if(r==="protect"&&!n){let y=G(e.project,"--project <repo>"),x=G(o,"the repository-relative source map path"),w=Qo({root:i,repository:y,file:x});if(e.yes&&!w.conflicts.length)c({...w,...en(w)});else c(w);return w.conflicts.length?1:0}if(r==="service"&&o==="status"&&!s){let y=We.parse(n),x=G(e.project,"--project <repo>");return c(await Fo({root:i,service:y,project:x,verifyRead:e["verify-read"]??!1,verifyHealth:e["verify-health"]??!1})),0}if(r==="service"&&o==="snapshot"&&!s){let y=We.parse(n),x=G(e.project,"--project <repo>"),w=e.file??[];if(w.length&&e.manifest)throw Error("Choose --file to prepare a manifest or --manifest to verify it.");if(w.length)c(await Lo({root:i,service:y,project:x,paths:w}));else{let S=G(e.manifest,"--manifest <snapshot.json>");c(await Mo({root:i,service:y,project:x,manifestPath:S}))}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,h={root:i,version:"1.0.5",options:e,emit:c},d={},g=f?{select:f.selectChoice,selectMany:f.selectMany}:{};return vp({...h,...d,...g},a?"add-repo":u?"install":"update",n)}try{process.exitCode=await _m()}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`apptoolkit: ${t}
123
+ `),process.exitCode=1}
@@ -0,0 +1,26 @@
1
+ # Optional Plane and Penpot connections
2
+
3
+ Select either provider when installing. The project profile stores each selected connection separately. A workspace can use both providers or use different services for individual repositories. Use the project service map to resolve which provider owns an operation before contacting it.
4
+
5
+ ## Connect an existing instance
6
+
7
+ Use the [Plane configuration example](plane.json) or the [Penpot configuration example](penpot.json) in the selected project's `services` array. Replace the example URL and resource IDs with the approved instance and project or file. The `tokenEnv` field identifies an environment variable. Populate it using the authorized credential store at execution time. Keep tokens and environment files outside `llm/` and outside Git.
8
+
9
+ Use `rtk proxy bun --no-env-file llm/harness/runtime/harness.mjs service status plane --project .` to inspect the selected Plane route without opening a connection. Use `penpot` for the design route or set `--project` to the registered relative repository path. Add `--verify-health` to send an unauthenticated HEAD request or `--verify-read` to check the exact resource with the configured credential. The read checks make one bounded request. The Plane check lists at most one work item ID. The Penpot check reads the selected file summary. The report contains status and credential availability, without credentials or resource data. Successful reads establish only the verified scope.
10
+
11
+ - Plane accepts an API key or OAuth token. Use the appropriate `auth` value and grant read access to the intended workspace and project. [Plane API](https://developers.plane.so/api-reference/issue/list-issues)
12
+ - Penpot accepts a personal access token for its internal API. Select the file ID from the authorized file link. [Penpot access tokens](https://help.penpot.app/technical-guide/integration/) · [File summary endpoint](https://github.com/penpot/penpot/blob/develop/backend/src/app/rpc/commands/files.clj)
13
+
14
+ Use the approved service tools or official MCP integration when the task needs an operation beyond these checks. Resolve the exact target and permissions first. A configuration record is not a publication grant.
15
+
16
+ ## Set up a local instance
17
+
18
+ Use the provider's documented self-hosted distribution with a pinned release. Set up and operate it separately from the project application. Keep deployment credentials, databases, attachments, and container volumes in approved private storage. Bind the service to loopback for a local-only workspace. After setup, create the approved access credential and use the same project configuration and verification steps as for an existing instance. [Plane Docker Compose guide](https://developers.plane.so/self-hosting/methods/docker-compose) · [Penpot Docker guide](https://help.penpot.app/technical-guide/getting-started/docker/)
19
+
20
+ ## Recover approved snapshots after cloning
21
+
22
+ Versioning the harness preserves connection references. Configure `snapshots` to `versioned` separately for each approved project and provider in a versioned workspace. With `off`, use the provider's separately approved private recovery process. A local or unversioned harness refuses to prepare or verify a versioned snapshot.
23
+
24
+ Create the native export using the authorized service. Keep only explicitly approved export files under `harness-snapshots/` and keep credentials outside the export. For Plane, preserve compatible database and attachment exports together if the approved recovery requires both. For Penpot, use the native file export or the chosen deployment's documented backup procedure. Run `rtk proxy bun --no-env-file llm/harness/runtime/harness.mjs service snapshot penpot --project . --file harness-snapshots/design.penpot` and save the resulting JSON as the manifest. Pass `--file` once for each payload. The manifest records the project, service, file paths, byte lengths, and SHA-256 digests.
25
+
26
+ After cloning the versioned workspace, use `rtk proxy bun --no-env-file llm/harness/runtime/harness.mjs service snapshot penpot --project . --manifest harness-snapshots/design.json`. Use `plane` for the ticket route. The command verifies the selected manifest, scope, byte lengths, and digests. Restore through the provider's documented procedure into an explicitly approved destination. Verify the resulting project or file with `service status --verify-read` using the recovered configuration. Native restoration is a separate write operation.