holycodex 0.16.2-dev.64.1 → 0.16.3-dev.66.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
1
  #!/usr/bin/env bun
2
- import{createInterface as e}from"node:readline/promises";import{lstat as t,mkdir as n,mkdtemp as r,open as i,readFile as a,readdir as o,realpath as s,rename as c,rm as l,rmdir as u,stat as d,unlink as f,writeFile as p}from"node:fs/promises";import{delimiter as m,dirname as h,isAbsolute as g,join as _,posix as ee,relative as te,resolve as ne,sep as re,win32 as ie}from"node:path";import{spawn as ae}from"node:child_process";import{fileURLToPath as oe}from"node:url";import{homedir as se}from"node:os";const ce=`0.15`,le=`state-0.16`;function ue(e,t=new WeakSet){if(!t.has(e)){t.add(e);for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&`value`in r&&de(r.value)&&ue(r.value,t)}Object.freeze(e)}}function de(e){return typeof e==`object`&&!!e}var fe=class extends Error{code;details;constructor(e,t,n={},r){super(t,r),this.name=`CoreError`,this.code=e,this.details=n,ue(this.details),Object.freeze(this)}};function pe(e){return{ok:!0,value:e}}function me(e){return{ok:!1,error:e}}function he(e,t){return new fe(`invalid_input`,`Invalid ${e}.`,{field:e},t===void 0?void 0:{cause:t})}const ge=e=>typeof e==`function`,v=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};case 4:return function(e,n,r,i){return arguments.length>=4?t(e,n,r,i):function(i){return t(i,e,n,r)}};case 5:return function(e,n,r,i,a){return arguments.length>=5?t(e,n,r,i,a):function(a){return t(a,e,n,r,i)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},y=e=>e,_e=e=>()=>e,ve=_e(!0),ye=_e(!1),be=_e(void 0),xe=be;function b(e,t,n,r,i,a,o,s,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return n(t(e));case 4:return r(n(t(e)));case 5:return i(r(n(t(e))));case 6:return a(i(r(n(t(e)))));case 7:return o(a(i(r(n(t(e))))));case 8:return s(o(a(i(r(n(t(e)))))));case 9:return c(s(o(a(i(r(n(t(e))))))));default:{let e=arguments[0];for(let t=1;t<arguments.length;t++)e=arguments[t](e);return e}}}const Se=e=>(t,n)=>t===n||e(t,n),Ce=(e,t)=>e===t,we=v(2,(e,t)=>Se((n,r)=>e(t(n),t(r)))),Te=we(Ce,e=>e.getTime()),Ee=e=>Se((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e(t[r],n[r]))return!1;return!0}),De=`effect/GlobalValue`;let Oe;const x=(e,t)=>(Oe||=(globalThis[De]??=new Map,globalThis[De]),Oe.has(e)||Oe.set(e,t()),Oe.get(e)),ke=e=>!!e,Ae=e=>typeof e==`string`,je=e=>typeof e==`number`,Me=e=>typeof e==`boolean`,Ne=e=>typeof e==`bigint`,Pe=e=>typeof e==`symbol`,Fe=ge,Ie=e=>e===void 0,Le=e=>!1,Re=e=>typeof e==`object`&&!!e,ze=e=>Re(e)||Fe(e),S=v(2,(e,t)=>ze(e)&&t in e),Be=v(2,(e,t)=>S(e,`_tag`)&&e._tag===t),Ve=e=>e==null,He=e=>e!=null,Ue=e=>e instanceof Uint8Array,We=e=>e instanceof Date,Ge=e=>typeof e==`string`||S(e,Symbol.iterator),Ke=e=>Re(e)&&!Array.isArray(e),qe=e=>S(e,`then`)&&Fe(e.then),Je=e=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`;var Ye=class e{self;called=!1;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(e){return{value:e,done:!0}}throw(e){throw e}[Symbol.iterator](){return new e(this.self)}},Xe=class{_state;constructor(e,t,n,r){return Ve(t)&&Ve(e)?(t=Math.random()*4294967295>>>0,e=0):Ve(t)&&(t=e,e=0),Ve(r)&&Ve(n)?(r=this._state?this._state[3]:4150755663,n=this._state?this._state[2]:335903614):Ve(r)&&(r=n,n=0),this._state=new Int32Array([0,0,n>>>0,((r||0)|1)>>>0]),this._next(),Qe(this._state,this._state[0],this._state[1],e>>>0,t>>>0),this._next(),this}getState(){return[this._state[0],this._state[1],this._state[2],this._state[3]]}setState(e){this._state[0]=e[0],this._state[1]=e[1],this._state[2]=e[2],this._state[3]=e[3]|1}integer(e){return Math.round(this.number()*(2**53-1))%e}number(){let e=(this._next()&67108863)*1,t=(this._next()&134217727)*1;return(e*134217728+t)/9007199254740992}_next(){let e=this._state[0]>>>0,t=this._state[1]>>>0;Ze(this._state,e,t,1481765933,1284865837),Qe(this._state,this._state[0],this._state[1],this._state[2],this._state[3]);let n=e>>>18,r=(t>>>18|e<<14)>>>0;n=(n^e)>>>0,r=(r^t)>>>0;let i=(r>>>27|n<<5)>>>0,a=e>>>27,o=(-a>>>0&31)>>>0;return(i>>>a|i<<o)>>>0}};function Ze(e,t,n,r,i){let a=(n>>>16)*(i&65535)>>>0,o=(n&65535)*(i>>>16)>>>0,s=(n&65535)*(i&65535)>>>0,c=(n>>>16)*(i>>>16)+((o>>>16)+(a>>>16))>>>0;o=o<<16>>>0,s=s+o>>>0,s>>>0<o>>>0&&(c=c+1>>>0),a=a<<16>>>0,s=s+a>>>0,s>>>0<a>>>0&&(c=c+1>>>0),c=c+Math.imul(n,r)>>>0,c=c+Math.imul(t,i)>>>0,e[0]=c,e[1]=s}function Qe(e,t,n,r,i){let a=t+r>>>0,o=n+i>>>0;o>>>0<n>>>0&&(a=a+1|0),e[0]=a,e[1]=o}const $e=Symbol.for(`effect/Utils/YieldWrap`);var et=class{#e;constructor(e){this.#e=e}[$e](){return this.#e}};function tt(e){if(typeof e==`object`&&e&&$e in e)return e[$e]();throw Error(Je(`yieldWrapGet`))}const nt=x(`effect/Utils/isStructuralRegion`,()=>({enabled:!1,tester:void 0})),rt={effect_internal_function:e=>e()},it=rt.effect_internal_function(()=>Error().stack)?.includes(`effect_internal_function`)===!0?rt.effect_internal_function:{effect_internal_function:e=>{try{return e()}finally{}}}.effect_internal_function;(function*(){}).constructor;const at=x(Symbol.for(`effect/Hash/randomHashCache`),()=>new WeakMap),C=Symbol.for(`effect/Hash`),w=e=>{if(nt.enabled===!0)return 0;switch(typeof e){case`number`:return lt(e);case`bigint`:return E(e.toString(10));case`boolean`:return E(String(e));case`symbol`:return E(String(e));case`string`:return E(e);case`undefined`:return E(`undefined`);case`function`:case`object`:return e===null?E(`null`):e instanceof Date?Number.isNaN(e.getTime())?E(`Invalid Date`):w(e.toISOString()):e instanceof URL?w(e.href):ct(e)?e[C]():ot(e);default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},ot=e=>(at.has(e)||at.set(e,lt(Math.floor(Math.random()*(2**53-1)))),at.get(e)),T=e=>t=>t*53^e,st=e=>e&3221225471|e>>>1&1073741824,ct=e=>S(e,C),lt=e=>{if(e!==e||e===1/0)return 0;let t=e|0;for(t!==e&&(t^=e*4294967295);e>4294967295;)t^=e/=4294967295;return st(t)},E=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return st(t)},ut=(e,t)=>{let n=12289;for(let r=0;r<t.length;r++)n^=b(E(t[r]),T(w(e[t[r]])));return st(n)},dt=e=>ut(e,Object.keys(e)),ft=e=>{let t=6151;for(let n=0;n<e.length;n++)t=b(t,T(w(e[n])));return st(t)},D=function(){if(arguments.length===1){let e=arguments[0];return function(t){return Object.defineProperty(e,C,{value(){return t},enumerable:!1}),t}}let e=arguments[0],t=arguments[1];return Object.defineProperty(e,C,{value(){return t},enumerable:!1}),t},O=Symbol.for(`effect/Equal`);function k(){return arguments.length===1?e=>pt(e,arguments[0]):pt(arguments[0],arguments[1])}function pt(e,t){if(e===t)return!0;let n=typeof e;if(n!==typeof t)return!1;if(n===`object`||n===`function`){if(e!==null&&t!==null){if(mt(e)&&mt(t))return w(e)===w(t)&&e[O](t)?!0:nt.enabled&&nt.tester?nt.tester(e,t):!1;if(e instanceof Date&&t instanceof Date){let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof URL&&t instanceof URL)return e.href===t.href}if(nt.enabled){if(e===null||t===null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>pt(e,t[n]));if(Object.getPrototypeOf(e)===Object.prototype&&Object.getPrototypeOf(t)===Object.prototype){let n=Object.keys(e),r=Object.keys(t);if(n.length===r.length){for(let r of n)if(!(r in t&&pt(e[r],t[r])))return nt.tester?nt.tester(e,t):!1;return!0}}return nt.tester?nt.tester(e,t):!1}}return nt.enabled&&nt.tester?nt.tester(e,t):!1}const mt=e=>S(e,O),ht=()=>k,A=Symbol.for(`nodejs.util.inspect.custom`),gt=e=>{try{if(S(e,`toJSON`)&&Fe(e.toJSON)&&e.toJSON.length===0)return e.toJSON();if(Array.isArray(e))return e.map(gt)}catch{return{}}return kt(e)},_t=`[Circular]`;function vt(e){try{return e.toISOString()}catch{return`Invalid Date`}}function yt(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function bt(e){return Ae(e)?JSON.stringify(e):String(e)}function xt(e,t){let n=t?.space??0,r=new WeakSet,i=n?je(n)?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,n=0){if(Array.isArray(e)){if(r.has(e))return _t;if(r.add(e),!i||e.length<=1)return`[${e.map(e=>c(e,n)).join(`,`)}]`;let t=e.map(e=>c(e,n+1)).join(`,
3
- `+a(n+1));return`[\n${a(n+1)}${t}\n${a(n)}]`}if(We(e))return vt(e);if(!t?.ignoreToString&&S(e,`toString`)&&Fe(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=yt(e);return e instanceof Error&&e.cause?`${t} (cause: ${c(e.cause,n)})`:t}if(Ae(e))return JSON.stringify(e);if(je(e)||e==null||Me(e)||Pe(e))return String(e);if(Ne(e))return String(e)+`n`;if(e instanceof Set||e instanceof Map)return r.has(e)?_t:(r.add(e),`${e.constructor.name}(${c(Array.from(e),n)})`);if(ze(e)){if(r.has(e))return _t;r.add(e);let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${bt(t)}:${c(e[t],n)}`).join(`,`)}}`;return o(e,r)}let l=`{\n${t.map(t=>`${a(n+1)}${bt(t)}: ${c(e[t],n+1)}`).join(`,
4
- `)}\n${a(n)}}`;return o(e,l)}return String(e)}return c(e,0)}const St=e=>JSON.stringify(e,null,2),Ct=(e,t=2)=>{if(typeof e==`string`)return e;try{return typeof e==`object`?wt(e,t):String(e)}catch{return String(e)}},wt=(e,t)=>{let n=[],r=JSON.stringify(e,(e,t)=>typeof t==`object`&&t?n.includes(t)?void 0:n.push(t)&&(Dt.fiberRefs!==void 0&&Et(t)?t[Tt](Dt.fiberRefs):t):t,t);return n=void 0,r},Tt=Symbol.for(`effect/Inspectable/Redactable`),Et=e=>typeof e==`object`&&!!e&&Tt in e,Dt=x(`effect/Inspectable/redactableState`,()=>({fiberRefs:void 0})),Ot=(e,t)=>{let n=Dt.fiberRefs;Dt.fiberRefs=e;try{return t()}finally{Dt.fiberRefs=n}},kt=e=>Et(e)&&Dt.fiberRefs!==void 0?e[Tt](Dt.fiberRefs):e,j=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}},At=`Async`,jt=`Commit`,Mt=`Failure`,Nt=`OnFailure`,Pt=`OnSuccess`,Ft=`OnSuccessAndFailure`,It=`Success`,Lt=`Sync`,Rt=`UpdateRuntimeFlags`,zt=`While`,Bt=`Iterator`,Vt=`WithRuntime`,Ht=`Yield`,Ut=`RevertFlags`,Wt=()=>`3.22.1`,Gt=Symbol.for(`effect/Effect`),Kt=Symbol.for(`effect/Stream`),qt=Symbol.for(`effect/Sink`),Jt=Symbol.for(`effect/Channel`),Yt={_R:e=>e,_E:e=>e,_A:e=>e,_V:Wt()},Xt={_A:e=>e,_In:e=>e,_L:e=>e,_E:e=>e,_R:e=>e},Zt={_Env:e=>e,_InErr:e=>e,_InElem:e=>e,_InDone:e=>e,_OutErr:e=>e,_OutElem:e=>e,_OutDone:e=>e},Qt={[Gt]:Yt,[Kt]:Yt,[qt]:Xt,[Jt]:Zt,[O](e){return this===e},[C](){return D(this,ot(this))},[Symbol.iterator](){return new Ye(new et(this))},pipe(){return j(this,arguments)}},$t={[C](){return D(this,dt(this))},[O](e){let t=Object.keys(this),n=Object.keys(e);if(t.length!==n.length)return!1;for(let n of t)if(!(n in e&&k(this[n],e[n])))return!1;return!0}},en={...Qt,_op:jt},tn={...en,...$t},nn=function(){function e(){}return e.prototype=en,e}(),rn=Symbol.for(`effect/Option`),an={...Qt,[rn]:{_A:e=>e},[A](){return this.toJSON()},toString(){return St(this.toJSON())}},on=Object.assign(Object.create(an),{_tag:`Some`,_op:`Some`,[O](e){return ln(e)&&dn(e)&&k(this.value,e.value)},[C](){return D(this,T(w(this._tag))(w(this.value)))},toJSON(){return{_id:`Option`,_tag:this._tag,value:gt(this.value)}}}),sn=w(`None`),cn=Object.assign(Object.create(an),{_tag:`None`,_op:`None`,[O](e){return ln(e)&&un(e)},[C](){return sn},toJSON(){return{_id:`Option`,_tag:this._tag}}}),ln=e=>S(e,rn),un=e=>e._tag===`None`,dn=e=>e._tag===`Some`,fn=Object.create(cn),pn=e=>{let t=Object.create(on);return t.value=e,t},mn=Symbol.for(`effect/Either`),hn={...Qt,[mn]:{_R:e=>e},[A](){return this.toJSON()},toString(){return St(this.toJSON())}},gn=Object.assign(Object.create(hn),{_tag:`Right`,_op:`Right`,[O](e){return vn(e)&&bn(e)&&k(this.right,e.right)},[C](){return T(w(this._tag))(w(this.right))},toJSON(){return{_id:`Either`,_tag:this._tag,right:gt(this.right)}}}),_n=Object.assign(Object.create(hn),{_tag:`Left`,_op:`Left`,[O](e){return vn(e)&&yn(e)&&k(this.left,e.left)},[C](){return T(w(this._tag))(w(this.left))},toJSON(){return{_id:`Either`,_tag:this._tag,left:gt(this.left)}}}),vn=e=>S(e,mn),yn=e=>e._tag===`Left`,bn=e=>e._tag===`Right`,xn=e=>{let t=Object.create(_n);return t.left=e,t},Sn=e=>{let t=Object.create(gn);return t.right=e,t},Cn=v(2,(e,t)=>un(e)?xn(t()):Sn(e.value)),M=Sn,N=xn,wn=Cn,Tn=e=>{if(Fe(e))try{return M(e())}catch(e){return N(e)}try{return M(e.try())}catch(t){return N(e.catch(t))}},En=vn,Dn=yn,On=bn,kn=v(2,(e,{onLeft:t,onRight:n})=>Dn(e)?N(t(e.left)):M(n(e.right))),An=v(2,(e,t)=>Dn(e)?N(t(e.left)):M(e.right)),jn=v(2,(e,t)=>On(e)?M(t(e.right)):N(e.left)),Mn=v(2,(e,{onLeft:t,onRight:n})=>Dn(e)?t(e.left):n(e.right)),Nn=Mn({onLeft:y,onRight:y}),Pn=v(2,(e,t)=>{if(On(e))return e.right;throw t(e.left)}),Fn=Pn(()=>Error(`getOrThrow called on a Left`)),In=e=>e.length>0,Ln=e=>(t,n)=>t===n?0:e(t,n),Rn=Ln((e,t)=>e<t?-1:1),zn=v(2,(e,t)=>Ln((n,r)=>e(t(n),t(r)))),Bn=e=>v(2,(t,n)=>e(t,n)===1),P=()=>fn,F=pn,Vn=ln,Hn=un,Un=dn,Wn=v(2,(e,{onNone:t,onSome:n})=>Hn(e)?t():n(e.value)),Gn=v(2,(e,t)=>Hn(e)?t():e.value),Kn=v(2,(e,t)=>Hn(e)?t():e),qn=v(2,(e,t)=>Hn(e)?F(t()):e),Jn=e=>e==null?P():F(e),Yn=Gn(be),Xn=e=>(...t)=>{try{return F(e(...t))}catch{return P()}},Zn=v(2,(e,t)=>{if(Un(e))return e.value;throw t()}),Qn=v(2,(e,t)=>Hn(e)?P():F(t(e.value))),$n=v(2,(e,t)=>Hn(e)?P():t(e.value)),er=v(2,(e,t)=>Hn(e)?P():Jn(t(e.value))),tr=$n,nr=v(2,(e,t)=>tr(e,e=>t(e)?pn(e):fn)),rr=e=>Se((t,n)=>Hn(t)?Hn(n):!Hn(n)&&e(t.value,n.value)),ir=(e=>v(2,(t,n)=>!Hn(t)&&e(t.value,n)))(ht()),ar=v(2,(e,t)=>!Hn(e)&&t(e.value)),or=(...e)=>e,sr=e=>Array(e),cr=v(2,(e,t)=>{let n=Math.max(1,Math.floor(e)),r=Array(n);for(let e=0;e<n;e++)r[e]=t(e);return r}),lr=e=>Array.isArray(e)?e:Array.from(e),ur=e=>Array.isArray(e)?e:[e],dr=v(2,(e,{onEmpty:t,onNonEmpty:n})=>vr(e)?n(wr(e),Dr(e)):t()),fr=v(2,(e,t)=>[t,...e]),pr=v(2,(e,t)=>[...e,t]),mr=v(2,(e,t)=>lr(e).concat(lr(t))),hr=Array.isArray,gr=e=>e.length===0,_r=In,vr=In,yr=(e,t)=>e<0||e>=t.length,br=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),xr=v(2,(e,t)=>{let n=Math.floor(t);return yr(n,e)?P():F(e[n])}),Sr=v(2,(e,t)=>{let n=Math.floor(t);if(yr(n,e))throw Error(`Index ${n} out of bounds`);return e[n]}),Cr=xr(0),wr=Sr(0),Tr=e=>vr(e)?F(Er(e)):P(),Er=e=>e[e.length-1],Dr=e=>e.slice(1),Or=(e,t)=>{let n=0;for(let r of e){if(!t(r,n))break;n++}return n},kr=v(2,(e,t)=>Ir(e,Or(e,t))),Ar=v(2,(e,t)=>{let n=lr(e);return n.slice(br(t,n),n.length)}),jr=e=>Array.from(e).reverse(),Mr=v(2,(e,t)=>{let n=Array.from(e);return n.sort(t),n}),Nr=v(2,(e,t)=>Pr(e,t,or)),Pr=v(3,(e,t,n)=>{let r=lr(e),i=lr(t);if(vr(r)&&vr(i)){let e=[n(wr(r),wr(i))],t=Math.min(r.length,i.length);for(let a=1;a<t;a++)e[a]=n(r[a],i[a]);return e}return[]}),Fr=ht(),Ir=v(2,(e,t)=>{let n=Array.from(e),r=Math.floor(t);return vr(n)?r>=1?Lr(n,r):[[],n]:[n,[]]}),Lr=v(2,(e,t)=>{let n=Math.max(1,Math.floor(t));return n>=e.length?[Rr(e),[]]:[fr(e.slice(1,n),wr(e)),e.slice(n)]}),Rr=e=>e.slice(),zr=v(3,(e,t,n)=>{let r=lr(e),i=lr(t);return vr(r)?vr(i)?Xr(n)(mr(r,i)):r:i}),Br=v(2,(e,t)=>zr(e,t,Fr)),Vr=()=>[],Hr=e=>[e],Ur=v(2,(e,t)=>e.map(t)),Wr=v(2,(e,t)=>{if(gr(e))return[];let n=[];for(let r=0;r<e.length;r++){let i=t(e[r],r);for(let e=0;e<i.length;e++)n.push(i[e])}return n}),Gr=Wr(y),Kr=v(2,(e,t)=>{let n=lr(e),r=[];for(let e=0;e<n.length;e++){let i=t(n[e],e);Un(i)&&r.push(i.value)}return r}),qr=v(3,(e,t,n)=>lr(e).reduce((e,t,r)=>n(e,t,r),t)),Jr=(e,t)=>{let n=[],r=e,i;for(;Un(i=t(r));){let[e,t]=i.value;n.push(e),r=t}return n},Yr=Ee,Xr=v(2,(e,t)=>{let n=lr(e);if(vr(n)){let e=[wr(n)],r=Dr(n);for(let n of r)e.every(e=>!t(n,e))&&e.push(n);return e}return[]}),Zr=e=>Xr(e,ht()),Qr=v(2,(e,t)=>lr(e).join(t)),$r=/^[+-]?\d+$/,ei=Symbol.for(`effect/BigDecimal`),ti={[ei]:ei,[C](){let e=ci(this);return b(w(e.value),T(lt(e.scale)),D(this))},[O](e){return ni(e)&&fi(this,e)},toString(){return`BigDecimal(${gi(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}},ni=e=>S(e,ei),ri=(e,t)=>{let n=Object.create(ti);return n.value=e,n.scale=t,n},ii=(e,t)=>{if(e!==ai&&e%oi===ai)throw RangeError(`Value must be normalized`);let n=ri(e,t);return n.normalized=n,n},ai=BigInt(0),oi=BigInt(10),si=ii(ai,0),ci=e=>{if(e.normalized===void 0){if(e.value===ai)e.normalized=si;else{let t=`${e.value}`,n=0;for(let e=t.length-1;e>=0&&t[e]===`0`;e--)n++;n===0&&(e.normalized=e);let r=BigInt(t.substring(0,t.length-n)),i=e.scale-n;e.normalized=ii(r,i)}}return e.normalized},li=v(2,(e,t)=>t>e.scale?ri(e.value*oi**BigInt(t-e.scale),t):t<e.scale?ri(e.value/oi**BigInt(e.scale-t),t):e),ui=e=>e.value<ai?ri(-e.value,e.scale):e,di=Se((e,t)=>e.scale>t.scale?li(t,e.scale).value===e.value:e.scale<t.scale?li(e,t.scale).value===t.value:e.value===t.value),fi=v(2,(e,t)=>di(e,t)),pi=e=>Zn(mi(e),()=>RangeError(`Number must be finite, got ${e}`)),mi=e=>{if(!Number.isFinite(e))return P();let t=`${e}`;if(t.includes(`e`))return hi(t);let[n,r=``]=t.split(`.`);return F(ri(BigInt(`${n}${r}`),r.length))},hi=e=>{if(e===``)return F(si);let t,n,r=e.search(/[eE]/);if(r!==-1){let i=e.slice(r+1);if(t=e.slice(0,r),n=Number(i),t===``||!Number.isSafeInteger(n)||!$r.test(i))return P()}else t=e,n=0;let i,a,o=t.search(/\./);if(o!==-1){let e=t.slice(0,o),n=t.slice(o+1);i=`${e}${n}`,a=n.length}else i=t,a=0;if(!$r.test(i))return P();let s=a-n;return Number.isSafeInteger(s)?F(ri(BigInt(i),s)):P()},gi=e=>{let t=ci(e);if(Math.abs(t.scale)>=16)return _i(t);let n=t.value<ai,r=n?`${t.value}`.substring(1):`${t.value}`,i,a;if(t.scale>=r.length)i=`0`,a=`0`.repeat(t.scale-r.length)+r;else{let e=r.length-t.scale;if(e>r.length){let t=e-r.length;i=`${r}${`0`.repeat(t)}`,a=``}else a=r.slice(e),i=r.slice(0,e)}let o=a===``?i:`${i}.${a}`;return n?`-${o}`:o},_i=e=>{if(yi(e))return`0e+0`;let t=ci(e),n=`${ui(t).value}`,r=n.slice(0,1),i=n.slice(1),a=`${bi(t)?`-`:``}${r}`;i!==``&&(a+=`.${i}`);let o=i.length-t.scale;return`${a}e${o>=0?`+`:``}${o}`},vi=e=>Number(gi(e)),yi=e=>e.value===ai,bi=e=>e.value<ai,xi=e=>e>BigInt(2**53-1)||e<BigInt(-(2**53-1))?P():F(Number(e)),Si=e=>{try{return e.trim()===``?P():F(BigInt(e))}catch{return P()}},Ci=e=>{if(e>2**53-1||e<-(2**53-1))return P();try{return F(BigInt(e))}catch{return P()}},wi=e=>!e,Ti=Symbol.for(`effect/Chunk`);function Ei(e,t,n,r,i){for(let a=t;a<Math.min(e.length,t+i);a++)n[r+a-t]=e[a];return n}const Di=[],Oi=(e=>Se((t,n)=>t.length===n.length&&Ri(t).every((t,r)=>e(t,Hi(n,r)))))(k),ki={[Ti]:{_A:e=>e},toString(){return St(this.toJSON())},toJSON(){return{_id:`Chunk`,values:Ri(this).map(gt)}},[A](){return this.toJSON()},[O](e){return ji(e)&&Oi(this,e)},[C](){return D(this,ft(Ri(this)))},[Symbol.iterator](){switch(this.backing._tag){case`IArray`:return this.backing.array[Symbol.iterator]();case`IEmpty`:return Di[Symbol.iterator]();default:return Ri(this)[Symbol.iterator]()}},pipe(){return j(this,arguments)}},Ai=e=>{let t=Object.create(ki);switch(t.backing=e,e._tag){case`IEmpty`:t.length=0,t.depth=0,t.left=t,t.right=t;break;case`IConcat`:t.length=e.left.length+e.right.length,t.depth=1+Math.max(e.left.depth,e.right.depth),t.left=e.left,t.right=e.right;break;case`IArray`:t.length=e.array.length,t.depth=0,t.left=Mi,t.right=Mi;break;case`ISingleton`:t.length=1,t.depth=0,t.left=Mi,t.right=Mi;break;case`ISlice`:t.length=e.length,t.depth=e.chunk.depth+1,t.left=Mi,t.right=Mi}return t},ji=e=>S(e,Ti),Mi=Ai({_tag:`IEmpty`}),Ni=()=>Mi,Pi=(...e)=>Vi(e),Fi=e=>Ai({_tag:`ISingleton`,a:e}),Ii=e=>ji(e)?e:Bi(lr(e)),Li=(e,t,n)=>{switch(e.backing._tag){case`IArray`:Ei(e.backing.array,0,t,n,e.length);break;case`IConcat`:Li(e.left,t,n),Li(e.right,t,n+e.left.length);break;case`ISingleton`:t[n]=e.backing.a;break;case`ISlice`:{let r=0,i=n;for(;r<e.length;)t[i]=Hi(e,r),r+=1,i+=1;break}}},Ri=e=>{switch(e.backing._tag){case`IEmpty`:return Di;case`IArray`:return e.backing.array;default:{let t=Array(e.length);return Li(e,t,0),e.backing={_tag:`IArray`,array:t},e.left=Mi,e.right=Mi,e.depth=0,t}}},zi=e=>{switch(e.backing._tag){case`IEmpty`:case`ISingleton`:return e;case`IArray`:return Ai({_tag:`IArray`,array:jr(e.backing.array)});case`IConcat`:return Ai({_tag:`IConcat`,left:zi(e.backing.right),right:zi(e.backing.left)});case`ISlice`:return Bi(jr(Ri(e)))}},Bi=e=>e.length===0?Ni():e.length===1?Fi(e[0]):Ai({_tag:`IArray`,array:e}),Vi=e=>Bi(e),Hi=v(2,(e,t)=>{switch(e.backing._tag){case`IEmpty`:throw Error(`Index out of bounds`);case`ISingleton`:if(t!==0)throw Error(`Index out of bounds`);return e.backing.a;case`IArray`:if(t>=e.length||t<0)throw Error(`Index out of bounds`);return e.backing.array[t];case`IConcat`:return t<e.left.length?Hi(e.left,t):Hi(e.right,t-e.left.length);case`ISlice`:return Hi(e.backing.chunk,t+e.backing.offset)}}),Ui=v(2,(e,t)=>Ki(e,Fi(t))),Wi=v(2,(e,t)=>Ki(Fi(t),e)),Gi=v(2,(e,t)=>{if(t<=0)return e;if(t>=e.length)return Mi;switch(e.backing._tag){case`ISlice`:return Ai({_tag:`ISlice`,chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case`IConcat`:return t>e.left.length?Gi(e.right,t-e.left.length):Ai({_tag:`IConcat`,left:Gi(e.left,t),right:e.right});default:return Ai({_tag:`ISlice`,chunk:e,offset:t,length:e.length-t})}}),Ki=v(2,(e,t)=>{if(e.backing._tag===`IEmpty`)return t;if(t.backing._tag===`IEmpty`)return e;let n=t.depth-e.depth;if(Math.abs(n)<=1)return Ai({_tag:`IConcat`,left:e,right:t});if(n<-1){if(e.left.depth>=e.right.depth){let n=Ki(e.right,t);return Ai({_tag:`IConcat`,left:e.left,right:n})}{let n=Ki(e.right.right,t);if(n.depth===e.depth-3){let t=Ai({_tag:`IConcat`,left:e.right.left,right:n});return Ai({_tag:`IConcat`,left:e.left,right:t})}{let t=Ai({_tag:`IConcat`,left:e.left,right:e.right.left});return Ai({_tag:`IConcat`,left:t,right:n})}}}if(t.right.depth>=t.left.depth){let n=Ki(e,t.left);return Ai({_tag:`IConcat`,left:n,right:t.right})}{let n=Ki(e,t.left.left);if(n.depth===t.depth-3){let e=Ai({_tag:`IConcat`,left:n,right:t.left.right});return Ai({_tag:`IConcat`,left:e,right:t.right})}{let e=Ai({_tag:`IConcat`,left:t.left.right,right:t.right});return Ai({_tag:`IConcat`,left:n,right:e})}}}),qi=e=>e.length===0,Ji=e=>e.length>0,Yi=e=>Hi(e,0),Xi=Yi,Zi=e=>Gi(e,1);function Qi(e){return e-=e>>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function $i(e,t){return t>>>e&31}function ea(e){return 1<<e}function ta(e,t){return Qi(e&t-1)}const na=(e,t)=>({value:e,previous:t});function ra(e,t,n,r){let i=r;if(!e){let e=r.length;i=Array(e);for(let t=0;t<e;++t)i[t]=r[t]}return i[t]=n,i}function ia(e,t,n){let r=n.length-1,i=0,a=0,o=n;if(e)i=a=t;else for(o=Array(r);i<t;)o[a++]=n[i++];for(++i;i<=r;)o[a++]=n[i++];return e&&(o.length=r),o}function aa(e,t,n,r){let i=r.length;if(e){let e=i;for(;e>=t;)r[e--]=r[e];return r[t]=n,r}let a=0,o=0,s=Array(i+1);for(;a<t;)s[o++]=r[a++];for(s[t]=n;a<i;)s[++o]=r[a++];return s}var oa=class e{_tag=`EmptyNode`;modify(t,n,r,i,a,o){let s=r(P());return Hn(s)?new e:(++o.value,new ua(t,i,a,s))}};function sa(e){return Be(e,`EmptyNode`)}function ca(e){return sa(e)||e._tag===`LeafNode`||e._tag===`CollisionNode`}function la(e,t){return!sa(e)&&t===e.edit}var ua=class e{edit;hash;key;value;_tag=`LeafNode`;constructor(e,t,n,r){this.edit=e,this.hash=t,this.key=n,this.value=r}modify(t,n,r,i,a,o){if(k(a,this.key)){let n=r(this.value);return n===this.value?this:Hn(n)?(--o.value,new oa):la(this,t)?(this.value=n,this):new e(t,i,a,n)}let s=r(P());return Hn(s)?this:(++o.value,_a(t,n,this.hash,this,i,new e(t,i,a,s)))}},da=class e{edit;hash;children;_tag=`CollisionNode`;constructor(e,t,n){this.edit=e,this.hash=t,this.children=n}modify(t,n,r,i,a,o){if(i===this.hash){let n=la(this,t),i=this.updateCollisionList(n,t,this.hash,this.children,r,a,o);return i===this.children?this:i.length>1?new e(t,this.hash,i):i[0]}let s=r(P());return Hn(s)?this:(++o.value,_a(t,n,this.hash,this,i,new ua(t,i,a,s)))}updateCollisionList(e,t,n,r,i,a,o){let s=r.length;for(let c=0;c<s;++c){let s=r[c];if(`key`in s&&k(a,s.key)){let l=s.value,u=i(l);return u===l?r:Hn(u)?(--o.value,ia(e,c,r)):ra(e,c,new ua(t,n,a,u),r)}}let c=i(P());return Hn(c)?r:(++o.value,ra(e,s,new ua(t,n,a,c),r))}},fa=class e{edit;mask;children;_tag=`IndexedNode`;constructor(e,t,n){this.edit=e,this.mask=t,this.children=n}modify(t,n,r,i,a,o){let s=this.mask,c=this.children,l=$i(n,i),u=ea(l),d=ta(s,u),f=s&u,p=la(this,t);if(!f){let f=new oa().modify(t,n+5,r,i,a,o);return f?c.length>=16?ha(t,l,f,s,c):new e(t,s|u,aa(p,d,f,c)):this}let m=c[d],h=m.modify(t,n+5,r,i,a,o);if(m===h)return this;let g=s,_;if(sa(h)){if(g&=~u,!g)return new oa;if(c.length<=2&&ca(c[d^1]))return c[d^1];_=ia(p,d,c)}else _=ra(p,d,h,c);return p?(this.mask=g,this.children=_,this):new e(t,g,_)}},pa=class e{edit;size;children;_tag=`ArrayNode`;constructor(e,t,n){this.edit=e,this.size=t,this.children=n}modify(t,n,r,i,a,o){let s=this.size,c=this.children,l=$i(n,i),u=c[l],d=(u||new oa).modify(t,n+5,r,i,a,o);if(u===d)return this;let f=la(this,t),p;if(sa(u)&&!sa(d))++s,p=ra(f,l,d,c);else if(!sa(u)&&sa(d)){if(--s,s<=8)return ma(t,s,l,c);p=ra(f,l,new oa,c)}else p=ra(f,l,d,c);return f?(this.size=s,this.children=p,this):new e(t,s,p)}};function ma(e,t,n,r){let i=Array(t-1),a=0,o=0;for(let e=0,t=r.length;e<t;++e)if(e!==n){let t=r[e];t&&!sa(t)&&(i[a++]=t,o|=1<<e)}return new fa(e,o,i)}function ha(e,t,n,r,i){let a=[],o=r,s=0;for(let e=0;o;++e)o&1&&(a[e]=i[s++]),o>>>=1;return a[t]=n,new pa(e,s+1,a)}function ga(e,t,n,r,i,a){if(n===i)return new da(e,n,[a,r]);let o=$i(t,n),s=$i(t,i);if(o===s)return t=>new fa(e,ea(o)|ea(s),[t]);{let t=o<s?[r,a]:[a,r];return new fa(e,ea(o)|ea(s),t)}}function _a(e,t,n,r,i,a){let o,s=t;for(;;){let t=ga(e,s,n,r,i,a);if(typeof t==`function`)o=na(t,o),s+=5;else{let e=t;for(;o!=null;)e=o.value(e),o=o.previous;return e}}}const va=`effect/HashMap`,ya=Symbol.for(va),ba={[ya]:ya,[Symbol.iterator](){return new Sa(this,(e,t)=>[e,t])},[C](){let e=w(va);for(let t of this)e^=b(w(t[0]),T(w(t[1])));return D(this,e)},[O](e){if(ka(e)){if(e._size!==this._size)return!1;for(let t of this){let n=b(e,Ma(t[0],w(t[0])));if(Hn(n)||!k(t[1],n.value))return!1}return!0}return!1},toString(){return St(this.toJSON())},toJSON(){return{_id:`HashMap`,values:Array.from(this).map(gt)}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}},xa=(e,t,n,r)=>{let i=Object.create(ba);return i._editable=e,i._edit=t,i._root=n,i._size=r,i};var Sa=class e{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=wa(this.map._root,this.f,void 0)}next(){if(Hn(this.v))return{done:!0,value:void 0};let e=this.v.value;return this.v=Ca(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new e(this.map,this.f)}};const Ca=e=>e?Ta(e[0],e[1],e[2],e[3],e[4]):P(),wa=(e,t,n=void 0)=>{switch(e._tag){case`LeafNode`:return Un(e.value)?F({value:t(e.key,e.value.value),cont:n}):Ca(n);case`CollisionNode`:case`ArrayNode`:case`IndexedNode`:{let r=e.children;return Ta(r.length,r,0,t,n)}default:return Ca(n)}},Ta=(e,t,n,r,i)=>{for(;n<e;){let a=t[n++];if(a&&!sa(a))return wa(a,r,[e,t,n,r,i])}return Ca(i)},Ea=xa(!1,0,new oa,0),Da=()=>Ea,Oa=e=>{let t=Ra(Da());for(let n of e)Pa(t,n[0],n[1]);return za(t)},ka=e=>S(e,ya),Aa=e=>e&&sa(e._root),ja=v(2,(e,t)=>Ma(e,t,w(t))),Ma=v(3,(e,t,n)=>{let r=e._root,i=0;for(;;)switch(r._tag){case`LeafNode`:return k(t,r.key)?r.value:P();case`CollisionNode`:if(n===r.hash){let e=r.children;for(let n=0,r=e.length;n<r;++n){let r=e[n];if(`key`in r&&k(t,r.key))return r.value}}return P();case`IndexedNode`:{let e=ea($i(i,n));if(r.mask&e){r=r.children[ta(r.mask,e)],i+=5;break}return P()}case`ArrayNode`:if(r=r.children[$i(i,n)],r){i+=5;break}return P();default:return P()}}),Na=v(2,(e,t)=>Un(Ma(e,t,w(t)))),Pa=v(3,(e,t,n)=>Ba(e,t,()=>F(n))),Fa=v(3,(e,t,n)=>e._editable?(e._root=t,e._size=n,e):t===e._root?e:xa(e._editable,e._edit,t,n)),Ia=e=>new Sa(e,e=>e),La=e=>e._size,Ra=e=>xa(!0,e._edit+1,e._root,e._size),za=e=>(e._editable=!1,e),Ba=v(3,(e,t,n)=>Va(e,t,w(t),n)),Va=v(4,(e,t,n,r)=>{let i={value:e._size},a=e._root.modify(e._editable?e._edit:NaN,0,r,n,t,i);return b(e,Fa(a,i.value))}),Ha=v(2,(e,t)=>Ba(e,t,P)),Ua=v(2,(e,t)=>Ga(e,Da(),(e,n,r)=>Pa(e,r,t(n,r)))),Wa=v(2,(e,t)=>Ga(e,void 0,(e,n,r)=>t(n,r))),Ga=v(3,(e,t,n)=>{let r=e._root;if(r._tag===`LeafNode`)return Un(r.value)?n(t,r.value.value,r.key):t;if(r._tag===`EmptyNode`)return t;let i=[r.children],a;for(;a=i.pop();)for(let e=0,r=a.length;e<r;){let r=a[e++];r&&!sa(r)&&(r._tag===`LeafNode`?Un(r.value)&&(t=n(t,r.value.value,r.key)):i.push(r.children))}return t}),Ka=`effect/HashSet`,qa=Symbol.for(Ka),Ja={[qa]:qa,[Symbol.iterator](){return Ia(this._keyMap)},[C](){return D(this,T(w(this._keyMap))(w(Ka)))},[O](e){return Xa(e)?La(this._keyMap)===La(e._keyMap)&&k(this._keyMap,e._keyMap):!1},toString(){return St(this.toJSON())},toJSON(){return{_id:`HashSet`,values:Array.from(this).map(gt)}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}},Ya=e=>{let t=Object.create(Ja);return t._keyMap=e,t},Xa=e=>S(e,qa),Za=Ya(Da()),Qa=()=>Za,$a=e=>{let t=ro(Qa());for(let n of e)oo(t,n);return io(t)},eo=(...e)=>{let t=ro(Qa());for(let n of e)oo(t,n);return io(t)},to=v(2,(e,t)=>Na(e._keyMap,t)),no=e=>La(e._keyMap),ro=e=>Ya(Ra(e._keyMap)),io=e=>(e._keyMap._editable=!1,e),ao=v(2,(e,t)=>{let n=ro(e);return t(n),io(n)}),oo=v(2,(e,t)=>e._keyMap._editable?(Pa(t,!0)(e._keyMap),e):Ya(Pa(t,!0)(e._keyMap))),so=v(2,(e,t)=>e._keyMap._editable?(Ha(t)(e._keyMap),e):Ya(Ha(t)(e._keyMap))),co=v(2,(e,t)=>ao(e,e=>{for(let n of t)so(e,n)})),lo=v(2,(e,t)=>ao(Qa(),n=>{uo(e,e=>oo(n,e));for(let e of t)oo(n,e)})),uo=v(2,(e,t)=>Wa(e._keyMap,(e,n)=>t(n))),fo=v(3,(e,t,n)=>Ga(e._keyMap,t,(e,t,r)=>n(e,r))),po=Qa,mo=$a,ho=eo,go=to,_o=no,vo=oo,yo=so,bo=co,xo=lo,So=fo,Co=`Empty`,wo=`Fail`,To=`Interrupt`,Eo=`Parallel`,Do=`Sequential`,Oo=`effect/Cause`,ko=Symbol.for(Oo),Ao={_E:e=>e},jo={[ko]:Ao,[C](){return b(w(Oo),T(w($o(this))),D(this))},[O](e){return Ro(e)&&Qo(this,e)},pipe(){return j(this,arguments)},toJSON(){switch(this._tag){case`Empty`:return{_id:`Cause`,_tag:this._tag};case`Die`:return{_id:`Cause`,_tag:this._tag,defect:gt(this.defect)};case`Interrupt`:return{_id:`Cause`,_tag:this._tag,fiberId:this.fiberId.toJSON()};case`Fail`:return{_id:`Cause`,_tag:this._tag,failure:gt(this.error)};case`Sequential`:case`Parallel`:return{_id:`Cause`,_tag:this._tag,left:gt(this.left),right:gt(this.right)}}},toString(){return ls(this)},[A](){return this.toJSON()}},Mo=(()=>{let e=Object.create(jo);return e._tag=Co,e})(),No=e=>{let t=Object.create(jo);return t._tag=wo,t.error=e,t},Po=e=>{let t=Object.create(jo);return t._tag=`Die`,t.defect=e,t},Fo=e=>{let t=Object.create(jo);return t._tag=To,t.fiberId=e,t},Io=(e,t)=>{let n=Object.create(jo);return n._tag=Eo,n.left=e,n.right=t,n},Lo=(e,t)=>{let n=Object.create(jo);return n._tag=Do,n.left=e,n.right=t,n},Ro=e=>S(e,ko),zo=e=>e._tag===Co,Bo=e=>e._tag===wo,Vo=e=>e._tag===`Empty`||ss(e,!0,(e,t)=>{switch(t._tag){case Co:return F(e);case`Die`:case wo:case To:return F(!1);default:return P()}}),Ho=e=>Un(Yo(e)),Uo=e=>cs(void 0,rs)(e),Wo=e=>zi(ss(e,Ni(),(e,t)=>t._tag===`Fail`?F(b(e,Wi(t.error))):P())),Go=e=>zi(ss(e,Ni(),(e,t)=>t._tag===`Die`?F(b(e,Wi(t.defect))):P())),Ko=e=>ss(e,po(),(e,t)=>t._tag===`Interrupt`?F(b(e,vo(t.fiberId))):P()),qo=e=>ts(e,e=>e._tag===`Fail`?F(e.error):P()),Jo=e=>{let t=qo(e);switch(t._tag){case`None`:return M(e);case`Some`:return N(t.value)}},Yo=e=>ts(e,e=>e._tag===`Interrupt`?F(e.fiberId):P()),Xo=e=>os(e,{onEmpty:Mo,onFail:()=>Mo,onDie:Po,onInterrupt:Fo,onSequential:Lo,onParallel:Io}),Zo=e=>os(e,{onEmpty:Mo,onFail:Po,onDie:Po,onInterrupt:Fo,onSequential:Lo,onParallel:Io}),Qo=(e,t)=>{let n=Fi(e),r=Fi(t);for(;Ji(n)&&Ji(r);){let[e,t]=b(Xi(n),ss([po(),Ni()],([e,t],n)=>{let[r,i]=ns(n);return F([b(e,xo(r)),b(t,Ki(i))])})),[i,a]=b(Xi(r),ss([po(),Ni()],([e,t],n)=>{let[r,i]=ns(n);return F([b(e,xo(r)),b(t,Ki(i))])}));if(!k(e,i))return!1;n=t,r=a}return!0},$o=e=>es(Fi(e),Ni()),es=(e,t)=>{for(;;){let[n,r]=b(e,qr([po(),Ni()],([e,t],n)=>{let[r,i]=ns(n);return[b(e,xo(r)),b(t,Ki(i))]})),i=_o(n)>0?b(t,Wi(n)):t;if(qi(r))return zi(i);e=r,t=i}throw Error(Je(`Cause.flattenCauseLoop`))},ts=v(2,(e,t)=>{let n=[e];for(;n.length>0;){let e=n.pop(),r=t(e);switch(r._tag){case`None`:switch(e._tag){case Do:case Eo:n.push(e.right),n.push(e.left)}break;case`Some`:return r}}return P()}),ns=e=>{let t=e,n=[],r=po(),i=Ni();for(;t!==void 0;)switch(t._tag){case Co:if(n.length===0)return[r,i];t=n.pop();break;case wo:if(r=vo(r,Pi(t._tag,t.error)),n.length===0)return[r,i];t=n.pop();break;case`Die`:if(r=vo(r,Pi(t._tag,t.defect)),n.length===0)return[r,i];t=n.pop();break;case To:if(r=vo(r,Pi(t._tag,t.fiberId)),n.length===0)return[r,i];t=n.pop();break;case Do:switch(t.left._tag){case Co:t=t.right;break;case Do:t=Lo(t.left.left,Lo(t.left.right,t.right));break;case Eo:t=Io(Lo(t.left.left,t.right),Lo(t.left.right,t.right));break;default:i=Wi(i,t.right),t=t.left}break;case Eo:n.push(t.right),t=t.left}throw Error(Je(`Cause.evaluateCauseLoop`))},rs={emptyCase:ve,failCase:ye,dieCase:ye,interruptCase:ve,sequentialCase:(e,t,n)=>t&&n,parallelCase:(e,t,n)=>t&&n},is=`SequentialCase`,as=`ParallelCase`,os=v(2,(e,{onDie:t,onEmpty:n,onFail:r,onInterrupt:i,onParallel:a,onSequential:o})=>cs(e,void 0,{emptyCase:()=>n,failCase:(e,t)=>r(t),dieCase:(e,n)=>t(n),interruptCase:(e,t)=>i(t),sequentialCase:(e,t,n)=>o(t,n),parallelCase:(e,t,n)=>a(t,n)})),ss=v(3,(e,t,n)=>{let r=t,i=e,a=[];for(;i!==void 0;){let e=n(r,i);switch(r=Un(e)?e.value:r,i._tag){case Do:a.push(i.right),i=i.left;break;case Eo:a.push(i.right),i=i.left;break;default:i=void 0}i===void 0&&a.length>0&&(i=a.pop())}return r}),cs=v(3,(e,t,n)=>{let r=[e],i=[];for(;r.length>0;){let e=r.pop();switch(e._tag){case Co:i.push(M(n.emptyCase(t)));break;case wo:i.push(M(n.failCase(t,e.error)));break;case`Die`:i.push(M(n.dieCase(t,e.defect)));break;case To:i.push(M(n.interruptCase(t,e.fiberId)));break;case Do:r.push(e.right),r.push(e.left),i.push(N({_tag:is}));break;case Eo:r.push(e.right),r.push(e.left),i.push(N({_tag:as}))}}let a=[];for(;i.length>0;){let e=i.pop();switch(e._tag){case`Left`:switch(e.left._tag){case is:{let e=a.pop(),r=a.pop(),i=n.sequentialCase(t,e,r);a.push(i);break}case as:{let e=a.pop(),r=a.pop(),i=n.parallelCase(t,e,r);a.push(i);break}}break;case`Right`:a.push(e.right)}}if(a.length===0)throw Error(`BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues`);return a.pop()}),ls=(e,t)=>Uo(e)?`All fibers interrupted without errors.`:_s(e).map(function(e){return t?.renderErrorCause!==!0||e.cause===void 0?e.stack:`${e.stack} {\n${us(e.cause,` `)}\n}`}).join(`
5
- `),us=(e,t)=>{let n=e.stack.split(`
6
- `),r=`${t}[cause]: ${n[0]}`;for(let e=1,i=n.length;e<i;e++)r+=`\n${t}${n[e]}`;return e.cause&&(r+=` {\n${us(e.cause,`${t} `)}\n${t}}`),r},ds=e=>{let t=typeof e==`object`&&!!e,n=Error.stackTraceLimit;Error.stackTraceLimit=1;let r=Error(fs(e),t&&`cause`in e&&e.cause!==void 0?{cause:ds(e.cause)}:void 0);return Error.stackTraceLimit=n,r.message===``&&(r.message=`An error has occurred`),Error.stackTraceLimit=n,r.name=e instanceof Error?e.name:`Error`,t&&(gs in e&&(r.span=e[gs]),Object.keys(e).forEach(t=>{t in r||(r[t]=e[t])})),r.stack=hs(`${r.name}: ${r.message}`,e instanceof Error&&e.stack?e.stack:``,r.span),r},fs=e=>{if(typeof e==`string`)return e;if(typeof e==`object`&&e&&e instanceof Error)return e.message;try{if(S(e,`toString`)&&Fe(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return wt(e)},ps=/\((.*)\)/g,ms=x(`effect/Tracer/spanToTrace`,()=>new WeakMap),hs=(e,t,n)=>{let r=[e],i=t.startsWith(e)?t.slice(e.length).split(`
2
+ import{createInterface as e}from"node:readline/promises";import{lstat as t,mkdir as n,mkdtemp as r,open as i,readFile as a,readdir as o,realpath as s,rename as c,rm as l,rmdir as u,stat as d,unlink as f,writeFile as p}from"node:fs/promises";import{delimiter as m,dirname as h,isAbsolute as g,join as _,posix as ee,relative as te,resolve as ne,sep as re,win32 as ie}from"node:path";import{spawn as ae}from"node:child_process";import{fileURLToPath as oe}from"node:url";import{homedir as se}from"node:os";var ce=Object.defineProperty,v=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},le=(e,t)=>{let n={};for(var r in e)ce(n,r,{get:e[r],enumerable:!0});return t||ce(n,Symbol.toStringTag,{value:`Module`}),n};function ue(e,t=new WeakSet){if(!t.has(e)){t.add(e);for(let n of Reflect.ownKeys(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&`value`in r&&de(r.value)&&ue(r.value,t)}Object.freeze(e)}}function de(e){return typeof e==`object`&&!!e}var fe,pe,me=v((()=>{fe=`0.15`,pe=`state-0.16`}));function he(e){return{ok:!0,value:e}}function ge(e){return{ok:!1,error:e}}function _e(e,t){return new y(`invalid_input`,`Invalid ${e}.`,{field:e},t===void 0?void 0:{cause:t})}var y,ve=v((()=>{me(),y=class extends Error{code;details;constructor(e,t,n={},r){super(t,r),this.name=`CoreError`,this.code=e,this.details=n,ue(this.details),Object.freeze(this)}}}));function b(e,t,n,r,i,a,o,s,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return n(t(e));case 4:return r(n(t(e)));case 5:return i(r(n(t(e))));case 6:return a(i(r(n(t(e)))));case 7:return o(a(i(r(n(t(e))))));case 8:return s(o(a(i(r(n(t(e)))))));case 9:return c(s(o(a(i(r(n(t(e))))))));default:{let e=arguments[0];for(let t=1;t<arguments.length;t++)e=arguments[t](e);return e}}}var ye,x,be,xe,Se,Ce,we,Te,S=v((()=>{ye=e=>typeof e==`function`,x=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};case 4:return function(e,n,r,i){return arguments.length>=4?t(e,n,r,i):function(i){return t(i,e,n,r)}};case 5:return function(e,n,r,i,a){return arguments.length>=5?t(e,n,r,i,a):function(a){return t(a,e,n,r,i)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},be=e=>e,xe=e=>()=>e,Se=xe(!0),Ce=xe(!1),we=xe(void 0),Te=we})),Ee,De,Oe,ke,Ae,je,Me,Ne=v((()=>{S(),Ee=e=>(t,n)=>t===n||e(t,n),De=(e,t)=>e===t,Oe=()=>De,ke=Oe(),Ae=x(2,(e,t)=>Ee((n,r)=>e(t(n),t(r)))),je=Ae(ke,e=>e.getTime()),Me=e=>Ee((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e(t[r],n[r]))return!1;return!0})})),Pe,Fe,C,Ie=v((()=>{Pe=`effect/GlobalValue`,C=(e,t)=>(Fe||=(globalThis[Pe]??=new Map,globalThis[Pe]),Fe.has(e)||Fe.set(e,t()),Fe.get(e))})),Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,w,Je,Ye,Xe,Ze,Qe,$e,et,tt,T=v((()=>{S(),Le=e=>!!e,Re=e=>typeof e==`string`,ze=e=>typeof e==`number`,Be=e=>typeof e==`boolean`,Ve=e=>typeof e==`bigint`,He=e=>typeof e==`symbol`,Ue=ye,We=e=>e===void 0,Ge=e=>!1,Ke=e=>typeof e==`object`&&!!e,qe=e=>Ke(e)||Ue(e),w=x(2,(e,t)=>qe(e)&&t in e),Je=x(2,(e,t)=>w(e,`_tag`)&&e._tag===t),Ye=e=>e==null,Xe=e=>e!=null,Ze=e=>e instanceof Uint8Array,Qe=e=>e instanceof Date,$e=e=>typeof e==`string`||w(e,Symbol.iterator),et=e=>Ke(e)&&!Array.isArray(e),tt=e=>w(e,`then`)&&Ue(e.then)})),nt,rt=v((()=>{nt=e=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`}));function it(e,t,n,r,i){let a=(n>>>16)*(i&65535)>>>0,o=(n&65535)*(i>>>16)>>>0,s=(n&65535)*(i&65535)>>>0,c=(n>>>16)*(i>>>16)+((o>>>16)+(a>>>16))>>>0;o=o<<16>>>0,s=s+o>>>0,s>>>0<o>>>0&&(c=c+1>>>0),a=a<<16>>>0,s=s+a>>>0,s>>>0<a>>>0&&(c=c+1>>>0),c=c+Math.imul(n,r)>>>0,c=c+Math.imul(t,i)>>>0,e[0]=c,e[1]=s}function at(e,t,n,r,i){let a=t+r>>>0,o=n+i>>>0;o>>>0<n>>>0&&(a=a+1|0),e[0]=a,e[1]=o}function ot(e){if(typeof e==`object`&&e&&ht in e)return e[ht]();throw Error(nt(`yieldWrapGet`))}var st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St=v((()=>{Ie(),rt(),T(),st=class e{self;called=!1;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(e){return{value:e,done:!0}}throw(e){throw e}[Symbol.iterator](){return new e(this.self)}},ct=335903614,lt=4150755663,ut=1481765933,dt=1284865837,ft=9007199254740992,pt=134217728,mt=class{_state;constructor(e,t,n,r){return Ye(t)&&Ye(e)?(t=Math.random()*4294967295>>>0,e=0):Ye(t)&&(t=e,e=0),Ye(r)&&Ye(n)?(r=this._state?this._state[3]:lt,n=this._state?this._state[2]:ct):Ye(r)&&(r=n,n=0),this._state=new Int32Array([0,0,n>>>0,((r||0)|1)>>>0]),this._next(),at(this._state,this._state[0],this._state[1],e>>>0,t>>>0),this._next(),this}getState(){return[this._state[0],this._state[1],this._state[2],this._state[3]]}setState(e){this._state[0]=e[0],this._state[1]=e[1],this._state[2]=e[2],this._state[3]=e[3]|1}integer(e){return Math.round(this.number()*(2**53-1))%e}number(){let e=(this._next()&67108863)*1,t=(this._next()&134217727)*1;return(e*pt+t)/ft}_next(){let e=this._state[0]>>>0,t=this._state[1]>>>0;it(this._state,e,t,ut,dt),at(this._state,this._state[0],this._state[1],this._state[2],this._state[3]);let n=e>>>18,r=(t>>>18|e<<14)>>>0;n=(n^e)>>>0,r=(r^t)>>>0;let i=(r>>>27|n<<5)>>>0,a=e>>>27,o=(-a>>>0&31)>>>0;return(i>>>a|i<<o)>>>0}},ht=Symbol.for(`effect/Utils/YieldWrap`),gt=class{#e;constructor(e){this.#e=e}[ht](){return this.#e}},_t=C(`effect/Utils/isStructuralRegion`,()=>({enabled:!1,tester:void 0})),vt={effect_internal_function:e=>e()},yt={effect_internal_function:e=>{try{return e()}finally{}}},bt=vt.effect_internal_function(()=>Error().stack)?.includes(`effect_internal_function`)===!0,xt=bt?vt.effect_internal_function:yt.effect_internal_function,function*(){}.constructor})),Ct,E,D,wt,O,Tt,Et,Dt,Ot,kt,At,jt,k,Mt=v((()=>{S(),Ie(),T(),St(),Ct=C(Symbol.for(`effect/Hash/randomHashCache`),()=>new WeakMap),E=Symbol.for(`effect/Hash`),D=e=>{if(_t.enabled===!0)return 0;switch(typeof e){case`number`:return Dt(e);case`bigint`:return Ot(e.toString(10));case`boolean`:return Ot(String(e));case`symbol`:return Ot(String(e));case`string`:return Ot(e);case`undefined`:return Ot(`undefined`);case`function`:case`object`:return e===null?Ot(`null`):e instanceof Date?Number.isNaN(e.getTime())?Ot(`Invalid Date`):D(e.toISOString()):e instanceof URL?D(e.href):Et(e)?e[E]():wt(e);default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},wt=e=>(Ct.has(e)||Ct.set(e,Dt(Math.floor(Math.random()*(2**53-1)))),Ct.get(e)),O=e=>t=>t*53^e,Tt=e=>e&3221225471|e>>>1&1073741824,Et=e=>w(e,E),Dt=e=>{if(e!==e||e===1/0)return 0;let t=e|0;for(t!==e&&(t^=e*4294967295);e>4294967295;)t^=e/=4294967295;return Tt(t)},Ot=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return Tt(t)},kt=(e,t)=>{let n=12289;for(let r=0;r<t.length;r++)n^=b(Ot(t[r]),O(D(e[t[r]])));return Tt(n)},At=e=>kt(e,Object.keys(e)),jt=e=>{let t=6151;for(let n=0;n<e.length;n++)t=b(t,O(D(e[n])));return Tt(t)},k=function(){if(arguments.length===1){let e=arguments[0];return function(t){return Object.defineProperty(e,E,{value(){return t},enumerable:!1}),t}}let e=arguments[0],t=arguments[1];return Object.defineProperty(e,E,{value(){return t},enumerable:!1}),t}}));function A(){return arguments.length===1?e=>Nt(e,arguments[0]):Nt(arguments[0],arguments[1])}function Nt(e,t){if(e===t)return!0;let n=typeof e;if(n!==typeof t)return!1;if(n===`object`||n===`function`){if(e!==null&&t!==null){if(Pt(e)&&Pt(t))return D(e)===D(t)&&e[j](t)?!0:_t.enabled&&_t.tester?_t.tester(e,t):!1;if(e instanceof Date&&t instanceof Date){let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof URL&&t instanceof URL)return e.href===t.href}if(_t.enabled){if(e===null||t===null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((e,n)=>Nt(e,t[n]));if(Object.getPrototypeOf(e)===Object.prototype&&Object.getPrototypeOf(t)===Object.prototype){let n=Object.keys(e),r=Object.keys(t);if(n.length===r.length){for(let r of n)if(!(r in t&&Nt(e[r],t[r])))return _t.tester?_t.tester(e,t):!1;return!0}}return _t.tester?_t.tester(e,t):!1}}return _t.enabled&&_t.tester?_t.tester(e,t):!1}var j,Pt,Ft,M=v((()=>{Mt(),T(),St(),j=Symbol.for(`effect/Equal`),Pt=e=>w(e,j),Ft=()=>A}));function It(e){try{return e.toISOString()}catch{return`Invalid Date`}}function Lt(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function Rt(e){return Re(e)?JSON.stringify(e):String(e)}function zt(e,t){let n=t?.space??0,r=new WeakSet,i=n?ze(n)?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,n=0){if(Array.isArray(e)){if(r.has(e))return Vt;if(r.add(e),!i||e.length<=1)return`[${e.map(e=>c(e,n)).join(`,`)}]`;let t=e.map(e=>c(e,n+1)).join(`,
3
+ `+a(n+1));return`[\n${a(n+1)}${t}\n${a(n)}]`}if(Qe(e))return It(e);if(!t?.ignoreToString&&w(e,`toString`)&&Ue(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=Lt(e);return e instanceof Error&&e.cause?`${t} (cause: ${c(e.cause,n)})`:t}if(Re(e))return JSON.stringify(e);if(ze(e)||e==null||Be(e)||He(e))return String(e);if(Ve(e))return String(e)+`n`;if(e instanceof Set||e instanceof Map)return r.has(e)?Vt:(r.add(e),`${e.constructor.name}(${c(Array.from(e),n)})`);if(qe(e)){if(r.has(e))return Vt;r.add(e);let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${Rt(t)}:${c(e[t],n)}`).join(`,`)}}`;return o(e,r)}let l=`{\n${t.map(t=>`${a(n+1)}${Rt(t)}: ${c(e[t],n+1)}`).join(`,
4
+ `)}\n${a(n)}}`;return o(e,l)}return String(e)}return c(e,0)}var N,Bt,Vt,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt=v((()=>{Ie(),T(),N=Symbol.for(`nodejs.util.inspect.custom`),Bt=e=>{try{if(w(e,`toJSON`)&&Ue(e.toJSON)&&e.toJSON.length===0)return e.toJSON();if(Array.isArray(e))return e.map(Bt)}catch{return{}}return Yt(e)},Vt=`[Circular]`,Ht=e=>JSON.stringify(e,null,2),Ut=(e,t=2)=>{if(typeof e==`string`)return e;try{return typeof e==`object`?Wt(e,t):String(e)}catch{return String(e)}},Wt=(e,t)=>{let n=[],r=JSON.stringify(e,(e,t)=>typeof t==`object`&&t?n.includes(t)?void 0:n.push(t)&&(qt.fiberRefs!==void 0&&Kt(t)?t[Gt](qt.fiberRefs):t):t,t);return n=void 0,r},Gt=Symbol.for(`effect/Inspectable/Redactable`),Kt=e=>typeof e==`object`&&!!e&&Gt in e,qt=C(`effect/Inspectable/redactableState`,()=>({fiberRefs:void 0})),Jt=(e,t)=>{let n=qt.fiberRefs;qt.fiberRefs=e;try{return t()}finally{qt.fiberRefs=n}},Yt=e=>Kt(e)&&qt.fiberRefs!==void 0?e[Gt](qt.fiberRefs):e})),P,F=v((()=>{P=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}}})),Zt,Qt,$t,en,tn,nn,rn,an,on,sn,cn,ln,un,dn,fn=v((()=>{Zt=`Async`,Qt=`Commit`,$t=`Failure`,en=`OnFailure`,tn=`OnSuccess`,nn=`OnSuccessAndFailure`,rn=`Success`,an=`Sync`,on=`UpdateRuntimeFlags`,sn=`While`,cn=`Iterator`,ln=`WithRuntime`,un=`Yield`,dn=`RevertFlags`})),pn,mn,hn=v((()=>{pn=`3.22.1`,mn=()=>pn})),gn,_n,vn,yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On=v((()=>{M(),Mt(),F(),St(),fn(),hn(),gn=Symbol.for(`effect/Effect`),_n=Symbol.for(`effect/Stream`),vn=Symbol.for(`effect/Sink`),yn=Symbol.for(`effect/Channel`),bn={_R:e=>e,_E:e=>e,_A:e=>e,_V:mn()},xn={_A:e=>e,_In:e=>e,_L:e=>e,_E:e=>e,_R:e=>e},Sn={_Env:e=>e,_InErr:e=>e,_InElem:e=>e,_InDone:e=>e,_OutErr:e=>e,_OutElem:e=>e,_OutDone:e=>e},Cn={[gn]:bn,[_n]:bn,[vn]:xn,[yn]:Sn,[j](e){return this===e},[E](){return k(this,wt(this))},[Symbol.iterator](){return new st(new gt(this))},pipe(){return P(this,arguments)}},wn={[E](){return k(this,At(this))},[j](e){let t=Object.keys(this),n=Object.keys(e);if(t.length!==n.length)return!1;for(let n of t)if(!(n in e&&A(this[n],e[n])))return!1;return!0}},Tn={...Cn,_op:Qt},En={...Tn,...wn},Dn=function(){function e(){}return e.prototype=Tn,e}()})),kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn=v((()=>{M(),Mt(),Xt(),T(),On(),kn=Symbol.for(`effect/Option`),An={...Cn,[kn]:{_A:e=>e},[N](){return this.toJSON()},toString(){return Ht(this.toJSON())}},jn=Object.assign(Object.create(An),{_tag:`Some`,_op:`Some`,[j](e){return Pn(e)&&In(e)&&A(this.value,e.value)},[E](){return k(this,O(D(this._tag))(D(this.value)))},toJSON(){return{_id:`Option`,_tag:this._tag,value:Bt(this.value)}}}),Mn=D(`None`),Nn=Object.assign(Object.create(An),{_tag:`None`,_op:`None`,[j](e){return Pn(e)&&Fn(e)},[E](){return Mn},toJSON(){return{_id:`Option`,_tag:this._tag}}}),Pn=e=>w(e,kn),Fn=e=>e._tag===`None`,In=e=>e._tag===`Some`,Ln=Object.create(Nn),Rn=e=>{let t=Object.create(jn);return t.value=e,t}})),Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn=v((()=>{M(),S(),Mt(),Xt(),T(),On(),zn(),Bn=Symbol.for(`effect/Either`),Vn={...Cn,[Bn]:{_R:e=>e},[N](){return this.toJSON()},toString(){return Ht(this.toJSON())}},Hn=Object.assign(Object.create(Vn),{_tag:`Right`,_op:`Right`,[j](e){return Wn(e)&&Kn(e)&&A(this.right,e.right)},[E](){return O(D(this._tag))(D(this.right))},toJSON(){return{_id:`Either`,_tag:this._tag,right:Bt(this.right)}}}),Un=Object.assign(Object.create(Vn),{_tag:`Left`,_op:`Left`,[j](e){return Wn(e)&&Gn(e)&&A(this.left,e.left)},[E](){return O(D(this._tag))(D(this.left))},toJSON(){return{_id:`Either`,_tag:this._tag,left:Bt(this.left)}}}),Wn=e=>w(e,Bn),Gn=e=>e._tag===`Left`,Kn=e=>e._tag===`Right`,qn=e=>{let t=Object.create(Un);return t.left=e,t},Jn=e=>{let t=Object.create(Hn);return t.right=e,t},Yn=x(2,(e,t)=>Fn(e)?qn(t()):Jn(e.value))})),I,L,Zn,Qn,$n,er,tr,nr,rr,ir,ar,or,sr,cr,lr=v((()=>{S(),Xn(),T(),I=Jn,L=qn,Zn=Yn,Qn=e=>{if(Ue(e))try{return I(e())}catch(e){return L(e)}try{return I(e.try())}catch(t){return L(e.catch(t))}},$n=Wn,er=Gn,tr=Kn,nr=x(2,(e,{onLeft:t,onRight:n})=>er(e)?L(t(e.left)):I(n(e.right))),rr=x(2,(e,t)=>er(e)?L(t(e.left)):I(e.right)),ir=x(2,(e,t)=>tr(e)?I(t(e.right)):L(e.left)),ar=x(2,(e,{onLeft:t,onRight:n})=>er(e)?t(e.left):n(e.right)),or=ar({onLeft:be,onRight:be}),sr=x(2,(e,t)=>{if(tr(e))return e.right;throw t(e.left)}),cr=sr(()=>Error(`getOrThrow called on a Left`))})),ur,dr=v((()=>{ur=e=>e.length>0})),fr,pr,mr,hr,gr=v((()=>{S(),fr=e=>(t,n)=>t===n?0:e(t,n),pr=fr((e,t)=>e<t?-1:1),mr=x(2,(e,t)=>fr((n,r)=>e(t(n),t(r)))),hr=e=>x(2,(t,n)=>e(t,n)===1)})),R,z,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr=v((()=>{M(),Ne(),S(),zn(),R=()=>Ln,z=Rn,_r=Pn,vr=Fn,yr=In,br=x(2,(e,{onNone:t,onSome:n})=>vr(e)?t():n(e.value)),xr=x(2,(e,t)=>vr(e)?t():e.value),Sr=x(2,(e,t)=>vr(e)?t():e),Cr=x(2,(e,t)=>vr(e)?z(t()):e),wr=e=>e==null?R():z(e),Tr=xr(we),Er=e=>(...t)=>{try{return z(e(...t))}catch{return R()}},Dr=x(2,(e,t)=>{if(yr(e))return e.value;throw t()}),Or=x(2,(e,t)=>vr(e)?R():z(t(e.value))),kr=x(2,(e,t)=>vr(e)?R():t(e.value)),Ar=x(2,(e,t)=>vr(e)?R():wr(t(e.value))),jr=kr,Mr=x(2,(e,t)=>jr(e,e=>t(e)?Rn(e):Ln)),Nr=e=>Ee((t,n)=>vr(t)?vr(n):!vr(n)&&e(t.value,n.value)),Pr=e=>x(2,(t,n)=>!vr(t)&&e(t.value,n)),Fr=Ft(),Ir=Pr(Fr),Lr=x(2,(e,t)=>!vr(e)&&t(e.value))})),zr,Br=v((()=>{T(),zr=(...e)=>e})),Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi=v((()=>{M(),Ne(),S(),dr(),Rr(),Br(),Vr=e=>Array(e),Hr=x(2,(e,t)=>{let n=Math.max(1,Math.floor(e)),r=Array(n);for(let e=0;e<n;e++)r[e]=t(e);return r}),Ur=e=>Array.isArray(e)?e:Array.from(e),Wr=e=>Array.isArray(e)?e:[e],Gr=x(2,(e,{onEmpty:t,onNonEmpty:n})=>$r(e)?n(ai(e),ci(e)):t()),Kr=x(2,(e,t)=>[t,...e]),qr=x(2,(e,t)=>[...e,t]),Jr=x(2,(e,t)=>Ur(e).concat(Ur(t))),Yr=Array.isArray,Xr=e=>e.length===0,Zr=Xr,Qr=ur,$r=ur,ei=(e,t)=>e<0||e>=t.length,ti=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),ni=x(2,(e,t)=>{let n=Math.floor(t);return ei(n,e)?R():z(e[n])}),ri=x(2,(e,t)=>{let n=Math.floor(t);if(ei(n,e))throw Error(`Index ${n} out of bounds`);return e[n]}),ii=ni(0),ai=ri(0),oi=e=>$r(e)?z(si(e)):R(),si=e=>e[e.length-1],ci=e=>e.slice(1),li=(e,t)=>{let n=0;for(let r of e){if(!t(r,n))break;n++}return n},ui=x(2,(e,t)=>_i(e,li(e,t))),di=x(2,(e,t)=>{let n=Ur(e);return n.slice(ti(t,n),n.length)}),fi=e=>Array.from(e).reverse(),pi=x(2,(e,t)=>{let n=Array.from(e);return n.sort(t),n}),mi=x(2,(e,t)=>hi(e,t,zr)),hi=x(3,(e,t,n)=>{let r=Ur(e),i=Ur(t);if($r(r)&&$r(i)){let e=[n(ai(r),ai(i))],t=Math.min(r.length,i.length);for(let a=1;a<t;a++)e[a]=n(r[a],i[a]);return e}return[]}),gi=Ft(),_i=x(2,(e,t)=>{let n=Array.from(e),r=Math.floor(t);return $r(n)?r>=1?vi(n,r):[[],n]:[n,[]]}),vi=x(2,(e,t)=>{let n=Math.max(1,Math.floor(t));return n>=e.length?[yi(e),[]]:[Kr(e.slice(1,n),ai(e)),e.slice(n)]}),yi=e=>e.slice(),bi=x(3,(e,t,n)=>{let r=Ur(e),i=Ur(t);return $r(r)?$r(i)?ji(n)(Jr(r,i)):r:i}),xi=x(2,(e,t)=>bi(e,t,gi)),Si=()=>[],Ci=e=>[e],wi=x(2,(e,t)=>e.map(t)),Ti=x(2,(e,t)=>{if(Zr(e))return[];let n=[];for(let r=0;r<e.length;r++){let i=t(e[r],r);for(let e=0;e<i.length;e++)n.push(i[e])}return n}),Ei=Ti(be),Di=x(2,(e,t)=>{let n=Ur(e),r=[];for(let e=0;e<n.length;e++){let i=t(n[e],e);yr(i)&&r.push(i.value)}return r}),Oi=x(3,(e,t,n)=>Ur(e).reduce((e,t,r)=>n(e,t,r),t)),ki=(e,t)=>{let n=[],r=e,i;for(;yr(i=t(r));){let[e,t]=i.value;n.push(e),r=t}return n},Ai=Me,ji=x(2,(e,t)=>{let n=Ur(e);if($r(n)){let e=[ai(n)],r=ci(n);for(let n of r)e.every(e=>!t(n,e))&&e.push(n);return e}return[]}),Mi=e=>ji(e,Ft()),Ni=x(2,(e,t)=>Ur(e).join(t))})),Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra=v((()=>{M(),Ne(),S(),Mt(),Xt(),Rr(),F(),T(),Fi=/^[+-]?\d+$/,Ii=Symbol.for(`effect/BigDecimal`),Li={[Ii]:Ii,[E](){let e=Wi(this);return b(D(e.value),O(Dt(e.scale)),k(this))},[j](e){return Ri(e)&&Ji(this,e)},toString(){return`BigDecimal(${Qi(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},Ri=e=>w(e,Ii),zi=(e,t)=>{let n=Object.create(Li);return n.value=e,n.scale=t,n},Bi=(e,t)=>{if(e!==Vi&&e%Hi===Vi)throw RangeError(`Value must be normalized`);let n=zi(e,t);return n.normalized=n,n},Vi=BigInt(0),Hi=BigInt(10),Ui=Bi(Vi,0),Wi=e=>{if(e.normalized===void 0){if(e.value===Vi)e.normalized=Ui;else{let t=`${e.value}`,n=0;for(let e=t.length-1;e>=0&&t[e]===`0`;e--)n++;n===0&&(e.normalized=e);let r=BigInt(t.substring(0,t.length-n)),i=e.scale-n;e.normalized=Bi(r,i)}}return e.normalized},Gi=x(2,(e,t)=>t>e.scale?zi(e.value*Hi**BigInt(t-e.scale),t):t<e.scale?zi(e.value/Hi**BigInt(e.scale-t),t):e),Ki=e=>e.value<Vi?zi(-e.value,e.scale):e,qi=Ee((e,t)=>e.scale>t.scale?Gi(t,e.scale).value===e.value:e.scale<t.scale?Gi(e,t.scale).value===t.value:e.value===t.value),Ji=x(2,(e,t)=>qi(e,t)),Yi=e=>Dr(Xi(e),()=>RangeError(`Number must be finite, got ${e}`)),Xi=e=>{if(!Number.isFinite(e))return R();let t=`${e}`;if(t.includes(`e`))return Zi(t);let[n,r=``]=t.split(`.`);return z(zi(BigInt(`${n}${r}`),r.length))},Zi=e=>{if(e===``)return z(Ui);let t,n,r=e.search(/[eE]/);if(r!==-1){let i=e.slice(r+1);if(t=e.slice(0,r),n=Number(i),t===``||!Number.isSafeInteger(n)||!Fi.test(i))return R()}else t=e,n=0;let i,a,o=t.search(/\./);if(o!==-1){let e=t.slice(0,o),n=t.slice(o+1);i=`${e}${n}`,a=n.length}else i=t,a=0;if(!Fi.test(i))return R();let s=a-n;return Number.isSafeInteger(s)?z(zi(BigInt(i),s)):R()},Qi=e=>{let t=Wi(e);if(Math.abs(t.scale)>=16)return $i(t);let n=t.value<Vi,r=n?`${t.value}`.substring(1):`${t.value}`,i,a;if(t.scale>=r.length)i=`0`,a=`0`.repeat(t.scale-r.length)+r;else{let e=r.length-t.scale;if(e>r.length){let t=e-r.length;i=`${r}${`0`.repeat(t)}`,a=``}else a=r.slice(e),i=r.slice(0,e)}let o=a===``?i:`${i}.${a}`;return n?`-${o}`:o},$i=e=>{if(ta(e))return`0e+0`;let t=Wi(e),n=`${Ki(t).value}`,r=n.slice(0,1),i=n.slice(1),a=`${na(t)?`-`:``}${r}`;i!==``&&(a+=`.${i}`);let o=i.length-t.scale;return`${a}e${o>=0?`+`:``}${o}`},ea=e=>Number(Qi(e)),ta=e=>e.value===Vi,na=e=>e.value<Vi})),ia,aa,oa,sa=v((()=>{Rr(),ia=e=>e>BigInt(2**53-1)||e<BigInt(-(2**53-1))?R():z(Number(e)),aa=e=>{try{return e.trim()===``?R():z(BigInt(e))}catch{return R()}},oa=e=>{if(e>2**53-1||e<-(2**53-1))return R();try{return z(BigInt(e))}catch{return R()}}})),ca,la=v((()=>{ca=e=>!e}));function ua(e,t,n,r,i){for(let a=t;a<Math.min(e.length,t+i);a++)n[r+a-t]=e[a];return n}var da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba=v((()=>{Pi(),M(),Ne(),S(),Mt(),Xt(),F(),T(),da=Symbol.for(`effect/Chunk`),fa=[],pa=e=>Ee((t,n)=>t.length===n.length&&Ta(t).every((t,r)=>e(t,Aa(n,r)))),ma=pa(A),ha={[da]:{_A:e=>e},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`Chunk`,values:Ta(this).map(Bt)}},[N](){return this.toJSON()},[j](e){return _a(e)&&ma(this,e)},[E](){return k(this,jt(Ta(this)))},[Symbol.iterator](){switch(this.backing._tag){case`IArray`:return this.backing.array[Symbol.iterator]();case`IEmpty`:return fa[Symbol.iterator]();default:return Ta(this)[Symbol.iterator]()}},pipe(){return P(this,arguments)}},ga=e=>{let t=Object.create(ha);switch(t.backing=e,e._tag){case`IEmpty`:t.length=0,t.depth=0,t.left=t,t.right=t;break;case`IConcat`:t.length=e.left.length+e.right.length,t.depth=1+Math.max(e.left.depth,e.right.depth),t.left=e.left,t.right=e.right;break;case`IArray`:t.length=e.array.length,t.depth=0,t.left=va,t.right=va;break;case`ISingleton`:t.length=1,t.depth=0,t.left=va,t.right=va;break;case`ISlice`:t.length=e.length,t.depth=e.chunk.depth+1,t.left=va,t.right=va}return t},_a=e=>w(e,da),va=ga({_tag:`IEmpty`}),ya=()=>va,ba=(...e)=>ka(e),xa=e=>ga({_tag:`ISingleton`,a:e}),Sa=e=>_a(e)?e:Oa(Ur(e)),Ca=(e,t,n)=>{switch(e.backing._tag){case`IArray`:ua(e.backing.array,0,t,n,e.length);break;case`IConcat`:Ca(e.left,t,n),Ca(e.right,t,n+e.left.length);break;case`ISingleton`:t[n]=e.backing.a;break;case`ISlice`:{let r=0,i=n;for(;r<e.length;)t[i]=Aa(e,r),r+=1,i+=1;break}}},wa=e=>{switch(e.backing._tag){case`IEmpty`:return fa;case`IArray`:return e.backing.array;default:{let t=Array(e.length);return Ca(e,t,0),e.backing={_tag:`IArray`,array:t},e.left=va,e.right=va,e.depth=0,t}}},Ta=wa,Ea=e=>{switch(e.backing._tag){case`IEmpty`:case`ISingleton`:return e;case`IArray`:return ga({_tag:`IArray`,array:fi(e.backing.array)});case`IConcat`:return ga({_tag:`IConcat`,left:Da(e.backing.right),right:Da(e.backing.left)});case`ISlice`:return Oa(fi(Ta(e)))}},Da=Ea,Oa=e=>e.length===0?ya():e.length===1?xa(e[0]):ga({_tag:`IArray`,array:e}),ka=e=>Oa(e),Aa=x(2,(e,t)=>{switch(e.backing._tag){case`IEmpty`:throw Error(`Index out of bounds`);case`ISingleton`:if(t!==0)throw Error(`Index out of bounds`);return e.backing.a;case`IArray`:if(t>=e.length||t<0)throw Error(`Index out of bounds`);return e.backing.array[t];case`IConcat`:return t<e.left.length?Aa(e.left,t):Aa(e.right,t-e.left.length);case`ISlice`:return Aa(e.backing.chunk,t+e.backing.offset)}}),ja=x(2,(e,t)=>Pa(e,xa(t))),Ma=x(2,(e,t)=>Pa(xa(t),e)),Na=x(2,(e,t)=>{if(t<=0)return e;if(t>=e.length)return va;switch(e.backing._tag){case`ISlice`:return ga({_tag:`ISlice`,chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case`IConcat`:return t>e.left.length?Na(e.right,t-e.left.length):ga({_tag:`IConcat`,left:Na(e.left,t),right:e.right});default:return ga({_tag:`ISlice`,chunk:e,offset:t,length:e.length-t})}}),Pa=x(2,(e,t)=>{if(e.backing._tag===`IEmpty`)return t;if(t.backing._tag===`IEmpty`)return e;let n=t.depth-e.depth;if(Math.abs(n)<=1)return ga({_tag:`IConcat`,left:e,right:t});if(n<-1){if(e.left.depth>=e.right.depth){let n=Pa(e.right,t);return ga({_tag:`IConcat`,left:e.left,right:n})}{let n=Pa(e.right.right,t);if(n.depth===e.depth-3){let t=ga({_tag:`IConcat`,left:e.right.left,right:n});return ga({_tag:`IConcat`,left:e.left,right:t})}{let t=ga({_tag:`IConcat`,left:e.left,right:e.right.left});return ga({_tag:`IConcat`,left:t,right:n})}}}if(t.right.depth>=t.left.depth){let n=Pa(e,t.left);return ga({_tag:`IConcat`,left:n,right:t.right})}{let n=Pa(e,t.left.left);if(n.depth===t.depth-3){let e=ga({_tag:`IConcat`,left:n,right:t.left.right});return ga({_tag:`IConcat`,left:e,right:t.right})}{let e=ga({_tag:`IConcat`,left:t.left.right,right:t.right});return ga({_tag:`IConcat`,left:n,right:e})}}}),Fa=e=>e.length===0,Ia=e=>e.length>0,La=e=>Aa(e,0),Ra=La,za=e=>Na(e,1)})),Va,Ha,Ua,Wa,Ga=v((()=>{Va=32,Ha=Va-1,Ua=Va/2,Wa=Va/4}));function Ka(e){return e-=e>>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function qa(e,t){return t>>>e&Ha}function Ja(e){return 1<<e}function Ya(e,t){return Ka(e&t-1)}var Xa=v((()=>{Ga()})),Za,Qa=v((()=>{Za=(e,t)=>({value:e,previous:t})}));function $a(e,t,n,r){let i=r;if(!e){let e=r.length;i=Array(e);for(let t=0;t<e;++t)i[t]=r[t]}return i[t]=n,i}function eo(e,t,n){let r=n.length-1,i=0,a=0,o=n;if(e)i=a=t;else for(o=Array(r);i<t;)o[a++]=n[i++];for(++i;i<=r;)o[a++]=n[i++];return e&&(o.length=r),o}function to(e,t,n,r){let i=r.length;if(e){let e=i;for(;e>=t;)r[e--]=r[e];return r[t]=n,r}let a=0,o=0,s=Array(i+1);for(;a<t;)s[o++]=r[a++];for(s[t]=n;a<i;)s[++o]=r[a++];return s}var no=v((()=>{}));function ro(e){return Je(e,`EmptyNode`)}function io(e){return ro(e)||e._tag===`LeafNode`||e._tag===`CollisionNode`}function ao(e,t){return!ro(e)&&t===e.edit}function oo(e,t,n,r){let i=Array(t-1),a=0,o=0;for(let e=0,t=r.length;e<t;++e)if(e!==n){let t=r[e];t&&!ro(t)&&(i[a++]=t,o|=1<<e)}return new mo(e,o,i)}function so(e,t,n,r,i){let a=[],o=r,s=0;for(let e=0;o;++e)o&1&&(a[e]=i[s++]),o>>>=1;return a[t]=n,new ho(e,s+1,a)}function co(e,t,n,r,i,a){if(n===i)return new po(e,n,[a,r]);let o=qa(t,n),s=qa(t,i);if(o===s)return t=>new mo(e,Ja(o)|Ja(s),[t]);{let t=o<s?[r,a]:[a,r];return new mo(e,Ja(o)|Ja(s),t)}}function lo(e,t,n,r,i,a){let o,s=t;for(;;){let t=co(e,s,n,r,i,a);if(typeof t==`function`)o=Za(t,o),s+=5;else{let e=t;for(;o!=null;)e=o.value(e),o=o.previous;return e}}}var uo,fo,po,mo,ho,go=v((()=>{M(),Rr(),T(),Qa(),no(),Xa(),Ga(),uo=class e{_tag=`EmptyNode`;modify(t,n,r,i,a,o){let s=r(R());return vr(s)?new e:(++o.value,new fo(t,i,a,s))}},fo=class e{edit;hash;key;value;_tag=`LeafNode`;constructor(e,t,n,r){this.edit=e,this.hash=t,this.key=n,this.value=r}modify(t,n,r,i,a,o){if(A(a,this.key)){let n=r(this.value);return n===this.value?this:vr(n)?(--o.value,new uo):ao(this,t)?(this.value=n,this):new e(t,i,a,n)}let s=r(R());return vr(s)?this:(++o.value,lo(t,n,this.hash,this,i,new e(t,i,a,s)))}},po=class e{edit;hash;children;_tag=`CollisionNode`;constructor(e,t,n){this.edit=e,this.hash=t,this.children=n}modify(t,n,r,i,a,o){if(i===this.hash){let n=ao(this,t),i=this.updateCollisionList(n,t,this.hash,this.children,r,a,o);return i===this.children?this:i.length>1?new e(t,this.hash,i):i[0]}let s=r(R());return vr(s)?this:(++o.value,lo(t,n,this.hash,this,i,new fo(t,i,a,s)))}updateCollisionList(e,t,n,r,i,a,o){let s=r.length;for(let c=0;c<s;++c){let s=r[c];if(`key`in s&&A(a,s.key)){let l=s.value,u=i(l);return u===l?r:vr(u)?(--o.value,eo(e,c,r)):$a(e,c,new fo(t,n,a,u),r)}}let c=i(R());return vr(c)?r:(++o.value,$a(e,s,new fo(t,n,a,c),r))}},mo=class e{edit;mask;children;_tag=`IndexedNode`;constructor(e,t,n){this.edit=e,this.mask=t,this.children=n}modify(t,n,r,i,a,o){let s=this.mask,c=this.children,l=qa(n,i),u=Ja(l),d=Ya(s,u),f=s&u,p=ao(this,t);if(!f){let f=new uo().modify(t,n+5,r,i,a,o);return f?c.length>=Ua?so(t,l,f,s,c):new e(t,s|u,to(p,d,f,c)):this}let m=c[d],h=m.modify(t,n+5,r,i,a,o);if(m===h)return this;let g=s,_;if(ro(h)){if(g&=~u,!g)return new uo;if(c.length<=2&&io(c[d^1]))return c[d^1];_=eo(p,d,c)}else _=$a(p,d,h,c);return p?(this.mask=g,this.children=_,this):new e(t,g,_)}},ho=class e{edit;size;children;_tag=`ArrayNode`;constructor(e,t,n){this.edit=e,this.size=t,this.children=n}modify(t,n,r,i,a,o){let s=this.size,c=this.children,l=qa(n,i),u=c[l],d=(u||new uo).modify(t,n+5,r,i,a,o);if(u===d)return this;let f=ao(this,t),p;if(ro(u)&&!ro(d))++s,p=$a(f,l,d,c);else if(!ro(u)&&ro(d)){if(--s,s<=Wa)return oo(t,s,l,c);p=$a(f,l,new uo,c)}else p=$a(f,l,d,c);return f?(this.size=s,this.children=p,this):new e(t,s,p)}}})),_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go=v((()=>{M(),S(),Mt(),Xt(),Rr(),F(),T(),Xa(),Ga(),go(),_o=`effect/HashMap`,vo=Symbol.for(_o),yo={[vo]:vo,[Symbol.iterator](){return new xo(this,(e,t)=>[e,t])},[E](){let e=D(_o);for(let t of this)e^=b(D(t[0]),O(D(t[1])));return k(this,e)},[j](e){if(Oo(e)){if(e._size!==this._size)return!1;for(let t of this){let n=b(e,jo(t[0],D(t[0])));if(vr(n)||!A(t[1],n.value))return!1}return!0}return!1},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`HashMap`,values:Array.from(this).map(Bt)}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},bo=(e,t,n,r)=>{let i=Object.create(yo);return i._editable=e,i._edit=t,i._root=n,i._size=r,i},xo=class e{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=Co(this.map._root,this.f,void 0)}next(){if(vr(this.v))return{done:!0,value:void 0};let e=this.v.value;return this.v=So(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new e(this.map,this.f)}},So=e=>e?wo(e[0],e[1],e[2],e[3],e[4]):R(),Co=(e,t,n=void 0)=>{switch(e._tag){case`LeafNode`:return yr(e.value)?z({value:t(e.key,e.value.value),cont:n}):So(n);case`CollisionNode`:case`ArrayNode`:case`IndexedNode`:{let r=e.children;return wo(r.length,r,0,t,n)}default:return So(n)}},wo=(e,t,n,r,i)=>{for(;n<e;){let a=t[n++];if(a&&!ro(a))return Co(a,r,[e,t,n,r,i])}return So(i)},To=bo(!1,0,new uo,0),Eo=()=>To,Do=e=>{let t=Lo(Eo());for(let n of e)No(t,n[0],n[1]);return Ro(t)},Oo=e=>w(e,vo),ko=e=>e&&ro(e._root),Ao=x(2,(e,t)=>jo(e,t,D(t))),jo=x(3,(e,t,n)=>{let r=e._root,i=0;for(;;)switch(r._tag){case`LeafNode`:return A(t,r.key)?r.value:R();case`CollisionNode`:if(n===r.hash){let e=r.children;for(let n=0,r=e.length;n<r;++n){let r=e[n];if(`key`in r&&A(t,r.key))return r.value}}return R();case`IndexedNode`:{let e=Ja(qa(i,n));if(r.mask&e){r=r.children[Ya(r.mask,e)],i+=5;break}return R()}case`ArrayNode`:if(r=r.children[qa(i,n)],r){i+=5;break}return R();default:return R()}}),Mo=x(2,(e,t)=>yr(jo(e,t,D(t)))),No=x(3,(e,t,n)=>zo(e,t,()=>z(n))),Po=x(3,(e,t,n)=>e._editable?(e._root=t,e._size=n,e):t===e._root?e:bo(e._editable,e._edit,t,n)),Fo=e=>new xo(e,e=>e),Io=e=>e._size,Lo=e=>bo(!0,e._edit+1,e._root,e._size),Ro=e=>(e._editable=!1,e),zo=x(3,(e,t,n)=>Bo(e,t,D(t),n)),Bo=x(4,(e,t,n,r)=>{let i={value:e._size},a=e._root.modify(e._editable?e._edit:NaN,0,r,n,t,i);return b(e,Po(a,i.value))}),Vo=x(2,(e,t)=>zo(e,t,R)),Ho=x(2,(e,t)=>Wo(e,Eo(),(e,n,r)=>No(e,r,t(n,r)))),Uo=x(2,(e,t)=>Wo(e,void 0,(e,n,r)=>t(n,r))),Wo=x(3,(e,t,n)=>{let r=e._root;if(r._tag===`LeafNode`)return yr(r.value)?n(t,r.value.value,r.key):t;if(r._tag===`EmptyNode`)return t;let i=[r.children],a;for(;a=i.pop();)for(let e=0,r=a.length;e<r;){let r=a[e++];r&&!ro(r)&&(r._tag===`LeafNode`?yr(r.value)&&(t=n(t,r.value.value,r.key)):i.push(r.children))}return t})})),Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,ls,us,ds,fs=v((()=>{M(),S(),Mt(),Xt(),F(),T(),Go(),Ko=`effect/HashSet`,qo=Symbol.for(Ko),Jo={[qo]:qo,[Symbol.iterator](){return Fo(this._keyMap)},[E](){return k(this,O(D(this._keyMap))(D(Ko)))},[j](e){return Xo(e)?Io(this._keyMap)===Io(e._keyMap)&&A(this._keyMap,e._keyMap):!1},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`HashSet`,values:Array.from(this).map(Bt)}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},Yo=e=>{let t=Object.create(Jo);return t._keyMap=e,t},Xo=e=>w(e,qo),Zo=Yo(Eo()),Qo=()=>Zo,$o=e=>{let t=rs(Qo());for(let n of e)os(t,n);return is(t)},es=(...e)=>{let t=rs(Qo());for(let n of e)os(t,n);return is(t)},ts=x(2,(e,t)=>Mo(e._keyMap,t)),ns=e=>Io(e._keyMap),rs=e=>Yo(Lo(e._keyMap)),is=e=>(e._keyMap._editable=!1,e),as=x(2,(e,t)=>{let n=rs(e);return t(n),is(n)}),os=x(2,(e,t)=>e._keyMap._editable?(No(t,!0)(e._keyMap),e):Yo(No(t,!0)(e._keyMap))),ss=x(2,(e,t)=>e._keyMap._editable?(Vo(t)(e._keyMap),e):Yo(Vo(t)(e._keyMap))),cs=x(2,(e,t)=>as(e,e=>{for(let n of t)ss(e,n)})),ls=x(2,(e,t)=>as(Qo(),n=>{us(e,e=>os(n,e));for(let e of t)os(n,e)})),us=x(2,(e,t)=>Uo(e._keyMap,(e,n)=>t(n))),ds=x(3,(e,t,n)=>Wo(e._keyMap,t,(e,t,r)=>n(e,r)))})),ps,ms,hs,gs,_s,vs,ys,bs,xs,Ss,Cs=v((()=>{fs(),ps=Qo,ms=$o,hs=es,gs=ts,_s=ns,vs=os,ys=ss,bs=cs,xs=ls,Ss=ds})),ws,Ts,Es,Ds,Os,ks=v((()=>{ws=`Empty`,Ts=`Fail`,Es=`Interrupt`,Ds=`Parallel`,Os=`Sequential`})),As,js,Ms,Ns,Ps,Fs,Is,Ls,Rs,zs,Bs,Vs,Hs,Us,Ws,Gs,Ks,qs,Js,Ys,Xs,Zs,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc=v((()=>{Pi(),Ba(),lr(),M(),S(),Ie(),Mt(),Cs(),Xt(),Rr(),F(),T(),rt(),ks(),As=`effect/Cause`,js=Symbol.for(As),Ms={_E:e=>e},Ns={[js]:Ms,[E](){return b(D(As),O(D(tc(this))),k(this))},[j](e){return Bs(e)&&ec(this,e)},pipe(){return P(this,arguments)},toJSON(){switch(this._tag){case`Empty`:return{_id:`Cause`,_tag:this._tag};case`Die`:return{_id:`Cause`,_tag:this._tag,defect:Bt(this.defect)};case`Interrupt`:return{_id:`Cause`,_tag:this._tag,fiberId:this.fiberId.toJSON()};case`Fail`:return{_id:`Cause`,_tag:this._tag,failure:Bt(this.error)};case`Sequential`:case`Parallel`:return{_id:`Cause`,_tag:this._tag,left:Bt(this.left),right:Bt(this.right)}}},toString(){return dc(this)},[N](){return this.toJSON()}},Ps=(()=>{let e=Object.create(Ns);return e._tag=ws,e})(),Fs=e=>{let t=Object.create(Ns);return t._tag=Ts,t.error=e,t},Is=e=>{let t=Object.create(Ns);return t._tag=`Die`,t.defect=e,t},Ls=e=>{let t=Object.create(Ns);return t._tag=Es,t.fiberId=e,t},Rs=(e,t)=>{let n=Object.create(Ns);return n._tag=Ds,n.left=e,n.right=t,n},zs=(e,t)=>{let n=Object.create(Ns);return n._tag=Os,n.left=e,n.right=t,n},Bs=e=>w(e,js),Vs=e=>e._tag===ws,Hs=e=>e._tag===Ts,Us=e=>e._tag===`Empty`||lc(e,!0,(e,t)=>{switch(t._tag){case ws:return z(e);case`Die`:case Ts:case Es:return z(!1);default:return R()}}),Ws=e=>yr(Zs(e)),Gs=e=>uc(void 0,ac)(e),Ks=e=>Da(lc(e,ya(),(e,t)=>t._tag===`Fail`?z(b(e,Ma(t.error))):R())),qs=e=>Da(lc(e,ya(),(e,t)=>t._tag===`Die`?z(b(e,Ma(t.defect))):R())),Js=e=>lc(e,ps(),(e,t)=>t._tag===`Interrupt`?z(b(e,vs(t.fiberId))):R()),Ys=e=>rc(e,e=>e._tag===`Fail`?z(e.error):R()),Xs=e=>{let t=Ys(e);switch(t._tag){case`None`:return I(e);case`Some`:return L(t.value)}},Zs=e=>rc(e,e=>e._tag===`Interrupt`?z(e.fiberId):R()),Qs=e=>cc(e,{onEmpty:Ps,onFail:()=>Ps,onDie:Is,onInterrupt:Ls,onSequential:zs,onParallel:Rs}),$s=e=>cc(e,{onEmpty:Ps,onFail:Is,onDie:Is,onInterrupt:Ls,onSequential:zs,onParallel:Rs}),ec=(e,t)=>{let n=xa(e),r=xa(t);for(;Ia(n)&&Ia(r);){let[e,t]=b(Ra(n),lc([ps(),ya()],([e,t],n)=>{let[r,i]=ic(n);return z([b(e,xs(r)),b(t,Pa(i))])})),[i,a]=b(Ra(r),lc([ps(),ya()],([e,t],n)=>{let[r,i]=ic(n);return z([b(e,xs(r)),b(t,Pa(i))])}));if(!A(e,i))return!1;n=t,r=a}return!0},tc=e=>nc(xa(e),ya()),nc=(e,t)=>{for(;;){let[n,r]=b(e,Oi([ps(),ya()],([e,t],n)=>{let[r,i]=ic(n);return[b(e,xs(r)),b(t,Pa(i))]})),i=_s(n)>0?b(t,Ma(n)):t;if(Fa(r))return Da(i);e=r,t=i}throw Error(nt(`Cause.flattenCauseLoop`))},rc=x(2,(e,t)=>{let n=[e];for(;n.length>0;){let e=n.pop(),r=t(e);switch(r._tag){case`None`:switch(e._tag){case Os:case Ds:n.push(e.right),n.push(e.left)}break;case`Some`:return r}}return R()}),ic=e=>{let t=e,n=[],r=ps(),i=ya();for(;t!==void 0;)switch(t._tag){case ws:if(n.length===0)return[r,i];t=n.pop();break;case Ts:if(r=vs(r,ba(t._tag,t.error)),n.length===0)return[r,i];t=n.pop();break;case`Die`:if(r=vs(r,ba(t._tag,t.defect)),n.length===0)return[r,i];t=n.pop();break;case Es:if(r=vs(r,ba(t._tag,t.fiberId)),n.length===0)return[r,i];t=n.pop();break;case Os:switch(t.left._tag){case ws:t=t.right;break;case Os:t=zs(t.left.left,zs(t.left.right,t.right));break;case Ds:t=Rs(zs(t.left.left,t.right),zs(t.left.right,t.right));break;default:i=Ma(i,t.right),t=t.left}break;case Ds:n.push(t.right),t=t.left}throw Error(nt(`Cause.evaluateCauseLoop`))},ac={emptyCase:Se,failCase:Ce,dieCase:Ce,interruptCase:Se,sequentialCase:(e,t,n)=>t&&n,parallelCase:(e,t,n)=>t&&n},oc=`SequentialCase`,sc=`ParallelCase`,cc=x(2,(e,{onDie:t,onEmpty:n,onFail:r,onInterrupt:i,onParallel:a,onSequential:o})=>uc(e,void 0,{emptyCase:()=>n,failCase:(e,t)=>r(t),dieCase:(e,n)=>t(n),interruptCase:(e,t)=>i(t),sequentialCase:(e,t,n)=>o(t,n),parallelCase:(e,t,n)=>a(t,n)})),lc=x(3,(e,t,n)=>{let r=t,i=e,a=[];for(;i!==void 0;){let e=n(r,i);switch(r=yr(e)?e.value:r,i._tag){case Os:a.push(i.right),i=i.left;break;case Ds:a.push(i.right),i=i.left;break;default:i=void 0}i===void 0&&a.length>0&&(i=a.pop())}return r}),uc=x(3,(e,t,n)=>{let r=[e],i=[];for(;r.length>0;){let e=r.pop();switch(e._tag){case ws:i.push(I(n.emptyCase(t)));break;case Ts:i.push(I(n.failCase(t,e.error)));break;case`Die`:i.push(I(n.dieCase(t,e.defect)));break;case Es:i.push(I(n.interruptCase(t,e.fiberId)));break;case Os:r.push(e.right),r.push(e.left),i.push(L({_tag:oc}));break;case Ds:r.push(e.right),r.push(e.left),i.push(L({_tag:sc}))}}let a=[];for(;i.length>0;){let e=i.pop();switch(e._tag){case`Left`:switch(e.left._tag){case oc:{let e=a.pop(),r=a.pop(),i=n.sequentialCase(t,e,r);a.push(i);break}case sc:{let e=a.pop(),r=a.pop(),i=n.parallelCase(t,e,r);a.push(i);break}}break;case`Right`:a.push(e.right)}}if(a.length===0)throw Error(`BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues`);return a.pop()}),dc=(e,t)=>Gs(e)?`All fibers interrupted without errors.`:yc(e).map(function(e){return t?.renderErrorCause!==!0||e.cause===void 0?e.stack:`${e.stack} {\n${fc(e.cause,` `)}\n}`}).join(`
5
+ `),fc=(e,t)=>{let n=e.stack.split(`
6
+ `),r=`${t}[cause]: ${n[0]}`;for(let e=1,i=n.length;e<i;e++)r+=`\n${t}${n[e]}`;return e.cause&&(r+=` {\n${fc(e.cause,`${t} `)}\n${t}}`),r},pc=e=>{let t=typeof e==`object`&&!!e,n=Error.stackTraceLimit;Error.stackTraceLimit=1;let r=Error(mc(e),t&&`cause`in e&&e.cause!==void 0?{cause:pc(e.cause)}:void 0);return Error.stackTraceLimit=n,r.message===``&&(r.message=`An error has occurred`),Error.stackTraceLimit=n,r.name=e instanceof Error?e.name:`Error`,t&&(vc in e&&(r.span=e[vc]),Object.keys(e).forEach(t=>{t in r||(r[t]=e[t])})),r.stack=_c(`${r.name}: ${r.message}`,e instanceof Error&&e.stack?e.stack:``,r.span),r},mc=e=>{if(typeof e==`string`)return e;if(typeof e==`object`&&e&&e instanceof Error)return e.message;try{if(w(e,`toString`)&&Ue(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return Wt(e)},hc=/\((.*)\)/g,gc=C(`effect/Tracer/spanToTrace`,()=>new WeakMap),_c=(e,t,n)=>{let r=[e],i=t.startsWith(e)?t.slice(e.length).split(`
7
7
  `):t.split(`
8
- `);for(let e=1;e<i.length;e++){if(i[e].includes(` at new BaseEffectError`)||i[e].includes(` at new YieldableError`)){e++;continue}if(i[e].includes(`Generator.next`)||i[e].includes(`effect_internal_function`))break;r.push(i[e].replace(/at .*effect_instruction_i.*\((.*)\)/,`at $1`).replace(/EffectPrimitive\.\w+/,`<anonymous>`))}if(n){let e=n,t=0;for(;e&&e._tag===`Span`&&t<10;){let n=ms.get(e);if(typeof n==`function`){let t=n();if(typeof t==`string`){let n=t.matchAll(ps),i=!1;for(let[,t]of n)i=!0,r.push(` at ${e.name} (${t})`);i||r.push(` at ${e.name} (${t.replace(/^at /,``)})`)}else r.push(` at ${e.name}`)}else r.push(` at ${e.name}`);e=Yn(e.parent),t++}}return r.join(`
9
- `)},gs=Symbol.for(`effect/SpanAnnotation`),_s=e=>cs(e,void 0,{emptyCase:()=>[],dieCase:(e,t)=>[ds(t)],failCase:(e,t)=>[ds(t)],interruptCase:()=>[],parallelCase:(e,t,n)=>[...t,...n],sequentialCase:(e,t,n)=>[...t,...n]}),vs=Symbol.for(`effect/Context/Tag`),ys=Symbol.for(`effect/Context/Reference`),bs=Symbol.for(`effect/STM`),xs={...Qt,_op:`Tag`,[bs]:Yt,[vs]:{_Service:e=>e,_Identifier:e=>e},toString(){return St(this.toJSON())},toJSON(){return{_id:`Tag`,key:this.key,stack:this.stack}},[A](){return this.toJSON()},of(e){return e},context(e){return Ps(this,e)}},Ss={...xs,[ys]:ys},Cs=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=t;let r=Object.create(xs);return Object.defineProperty(r,"stack",{get(){return n.stack}}),r.key=e,r},ws=e=>()=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=t;function r(){}return Object.setPrototypeOf(r,xs),r.key=e,Object.defineProperty(r,"stack",{get(){return n.stack}}),r},Ts=()=>(e,t)=>{let n=Error.stackTraceLimit;Error.stackTraceLimit=2;let r=Error();Error.stackTraceLimit=n;function i(){}return Object.setPrototypeOf(i,Ss),i.key=e,i.defaultValue=t.defaultValue,Object.defineProperty(i,"stack",{get(){return r.stack}}),i},Es=Symbol.for(`effect/Context`),Ds={[Es]:{_Services:e=>e},[O](e){if(As(e)&&this.unsafeMap.size===e.unsafeMap.size){for(let t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!k(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}return!1},[C](){return D(this,lt(this.unsafeMap.size))},pipe(){return j(this,arguments)},toString(){return St(this.toJSON())},toJSON(){return{_id:`Context`,services:Array.from(this.unsafeMap).map(gt)}},[A](){return this.toJSON()}},Os=e=>{let t=Object.create(Ds);return t.unsafeMap=e,t},ks=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(e.stack){let n=e.stack.split(`
8
+ `);for(let e=1;e<i.length;e++){if(i[e].includes(` at new BaseEffectError`)||i[e].includes(` at new YieldableError`)){e++;continue}if(i[e].includes(`Generator.next`)||i[e].includes(`effect_internal_function`))break;r.push(i[e].replace(/at .*effect_instruction_i.*\((.*)\)/,`at $1`).replace(/EffectPrimitive\.\w+/,`<anonymous>`))}if(n){let e=n,t=0;for(;e&&e._tag===`Span`&&t<10;){let n=gc.get(e);if(typeof n==`function`){let t=n();if(typeof t==`string`){let n=t.matchAll(hc),i=!1;for(let[,t]of n)i=!0,r.push(` at ${e.name} (${t})`);i||r.push(` at ${e.name} (${t.replace(/^at /,``)})`)}else r.push(` at ${e.name}`)}else r.push(` at ${e.name}`);e=Tr(e.parent),t++}}return r.join(`
9
+ `)},vc=Symbol.for(`effect/SpanAnnotation`),yc=e=>uc(e,void 0,{emptyCase:()=>[],dieCase:(e,t)=>[pc(t)],failCase:(e,t)=>[pc(t)],interruptCase:()=>[],parallelCase:(e,t,n)=>[...t,...n],sequentialCase:(e,t,n)=>[...t,...n]})})),xc,Sc,Cc,wc,Tc,Ec,Dc,Oc,kc,Ac,jc,Mc,Nc,Pc,Fc,Ic,Lc,Rc,zc,Bc,Vc,Hc,Uc,Wc,Gc,Kc,qc=v((()=>{M(),S(),Ie(),Mt(),Xt(),F(),T(),On(),zn(),xc=Symbol.for(`effect/Context/Tag`),Sc=Symbol.for(`effect/Context/Reference`),Cc=`effect/STM`,wc=Symbol.for(Cc),Tc={...Cn,_op:`Tag`,[wc]:bn,[xc]:{_Service:e=>e,_Identifier:e=>e},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`Tag`,key:this.key,stack:this.stack}},[N](){return this.toJSON()},of(e){return e},context(e){return Rc(this,e)}},Ec={...Tc,[Sc]:Sc},Dc=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=t;let r=Object.create(Tc);return Object.defineProperty(r,"stack",{get(){return n.stack}}),r.key=e,r},Oc=e=>()=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=t;function r(){}return Object.setPrototypeOf(r,Tc),r.key=e,Object.defineProperty(r,"stack",{get(){return n.stack}}),r},kc=()=>(e,t)=>{let n=Error.stackTraceLimit;Error.stackTraceLimit=2;let r=Error();Error.stackTraceLimit=n;function i(){}return Object.setPrototypeOf(i,Ec),i.key=e,i.defaultValue=t.defaultValue,Object.defineProperty(i,"stack",{get(){return r.stack}}),i},Ac=Symbol.for(`effect/Context`),jc={[Ac]:{_Services:e=>e},[j](e){if(Pc(e)&&this.unsafeMap.size===e.unsafeMap.size){for(let t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!A(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}return!1},[E](){return k(this,Dt(this.unsafeMap.size))},pipe(){return P(this,arguments)},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`Context`,services:Array.from(this.unsafeMap).map(Bt)}},[N](){return this.toJSON()}},Mc=e=>{let t=Object.create(jc);return t.unsafeMap=e,t},Nc=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(e.stack){let n=e.stack.split(`
10
10
  `);if(n.length>2){let e=n[2].match(/at (.*)/);e&&(t.message+=` (defined at ${e[1]})`)}}if(t.stack){let e=t.stack.split(`
11
11
  `);e.splice(1,3),t.stack=e.join(`
12
- `)}return t},As=e=>S(e,Es),js=e=>S(e,ys),Ms=Os(new Map),Ns=()=>Ms,Ps=(e,t)=>Os(new Map([[e.key,t]])),Fs=v(3,(e,t,n)=>{let r=new Map(e.unsafeMap);return r.set(t.key,n),Os(r)}),Is=x(`effect/Context/defaultValueCache`,()=>new Map),Ls=e=>{if(Is.has(e.key))return Is.get(e.key);let t=e.defaultValue();return Is.set(e.key,t),t},Rs=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):Ls(t),zs=v(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(ys in t)return Ls(t);throw ks(t)}return e.unsafeMap.get(t.key)}),Bs=zs,Vs=v(2,(e,t)=>e.unsafeMap.has(t.key)?pn(e.unsafeMap.get(t.key)):js(t)?pn(Ls(t)):fn),Hs=v(2,(e,t)=>{let n=new Map(e.unsafeMap);for(let[e,r]of t.unsafeMap)n.set(e,r);return Os(n)}),Us=Cs,Ws=Ns,Gs=Ps,Ks=Fs,qs=Bs,Js=zs,Ys=Vs,Xs=Hs,Zs=ws,Qs=Ts,$s=Symbol.for(`effect/Duration`),ec=BigInt(0),tc=BigInt(24),nc=BigInt(60),rc=BigInt(1e3),ic=BigInt(1e6),ac=BigInt(1e9),oc=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,sc=e=>{if(fc(e))return e;if(je(e))return yc(e);if(Ne(e))return _c(e);if(Array.isArray(e)&&e.length===2&&e.every(je))return e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1])?hc:e[0]===1/0||e[1]===1/0?gc:_c(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])));if(Ae(e)){let t=oc.exec(e);if(t){let[e,n,r]=t,i=Number(n);switch(r){case`nano`:case`nanos`:return _c(BigInt(n));case`micro`:case`micros`:return vc(BigInt(n));case`milli`:case`millis`:return yc(i);case`second`:case`seconds`:return bc(i);case`minute`:case`minutes`:return xc(i);case`hour`:case`hours`:return Sc(i);case`day`:case`days`:return Cc(i);case`week`:case`weeks`:return wc(i)}}}throw Error(`Invalid DurationInput`)},cc={_tag:`Millis`,millis:0},lc={_tag:`Infinity`},uc={[$s]:$s,[C](){return D(this,dt(this.value))},[O](e){return fc(e)&&Pc(this,e)},toString(){return`Duration(${Ic(this)})`},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,hrtime:Oc(this)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`}}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}},dc=e=>{let t=Object.create(uc);return t.value=je(e)?isNaN(e)||e<=0?cc:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:BigInt(Math.round(e*1e6))}:lc:e<=ec?cc:{_tag:`Nanos`,nanos:e},t},fc=e=>S(e,$s),pc=e=>e.value._tag!==`Infinity`,mc=e=>{switch(e.value._tag){case`Millis`:return e.value.millis===0;case`Nanos`:return e.value.nanos===ec;case`Infinity`:return!1}},hc=dc(0),gc=dc(1/0),_c=e=>dc(e),vc=e=>dc(e*rc),yc=e=>dc(e),bc=e=>dc(e*1e3),xc=e=>dc(e*6e4),Sc=e=>dc(e*36e5),Cc=e=>dc(e*864e5),wc=e=>dc(e*6048e5),Tc=e=>kc(e,{onMillis:e=>e,onNanos:e=>Number(e)/1e6}),Ec=e=>{let t=sc(e);switch(t.value._tag){case`Infinity`:return P();case`Nanos`:return F(t.value.nanos);case`Millis`:return F(BigInt(Math.round(t.value.millis*1e6)))}},Dc=e=>{let t=sc(e);switch(t.value._tag){case`Infinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return BigInt(Math.round(t.value.millis*1e6))}},Oc=e=>{let t=sc(e);switch(t.value._tag){case`Infinity`:return[1/0,0];case`Nanos`:return[Number(t.value.nanos/ac),Number(t.value.nanos%ac)];case`Millis`:return[Math.floor(t.value.millis/1e3),Math.round(t.value.millis%1e3*1e6)]}},kc=v(2,(e,t)=>{let n=sc(e);switch(n.value._tag){case`Nanos`:return t.onNanos(n.value.nanos);case`Infinity`:return t.onMillis(1/0);case`Millis`:return t.onMillis(n.value.millis)}}),Ac=v(3,(e,t,n)=>{let r=sc(e),i=sc(t);if(r.value._tag===`Infinity`||i.value._tag===`Infinity`)return n.onMillis(Tc(r),Tc(i));if(r.value._tag===`Nanos`||i.value._tag===`Nanos`){let e=r.value._tag===`Nanos`?r.value.nanos:BigInt(Math.round(r.value.millis*1e6)),t=i.value._tag===`Nanos`?i.value.nanos:BigInt(Math.round(i.value.millis*1e6));return n.onNanos(e,t)}return n.onMillis(r.value.millis,i.value.millis)}),jc=(e,t)=>Ac(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t}),Mc=v(2,(e,t)=>Ac(e,t,{onMillis:(e,t)=>e<=t,onNanos:(e,t)=>e<=t})),Nc=v(2,(e,t)=>Ac(e,t,{onMillis:(e,t)=>e>=t,onNanos:(e,t)=>e>=t})),Pc=v(2,(e,t)=>jc(sc(e),sc(t))),Fc=e=>{let t=sc(e);if(t.value._tag===`Infinity`)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};let n=Dc(t),r=n/ic,i=r/rc,a=i/nc,o=a/nc,s=o/tc;return{days:Number(s),hours:Number(o%tc),minutes:Number(a%nc),seconds:Number(i%nc),millis:Number(r%rc),nanos:Number(n%ic)}},Ic=e=>{let t=sc(e);if(t.value._tag===`Infinity`)return`Infinity`;if(mc(t))return`0`;let n=Fc(t),r=[];return n.days!==0&&r.push(`${n.days}d`),n.hours!==0&&r.push(`${n.hours}h`),n.minutes!==0&&r.push(`${n.minutes}m`),n.seconds!==0&&r.push(`${n.seconds}s`),n.millis!==0&&r.push(`${n.millis}ms`),n.nanos!==0&&r.push(`${n.nanos}ns`),r.join(` `)},Lc=Symbol.for(`effect/MutableRef`),Rc={[Lc]:Lc,toString(){return St(this.toJSON())},toJSON(){return{_id:`MutableRef`,current:gt(this.current)}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}},zc=e=>{let t=Object.create(Rc);return t.current=e,t},Bc=e=>e.current,Vc=v(2,(e,t)=>(e.current=t,e)),Hc=`effect/FiberId`,Uc=Symbol.for(Hc),Wc=`None`,Gc=`Runtime`,Kc=`Composite`,qc=E(`${Hc}-${Wc}`);var Jc=class{[Uc]=Uc;_tag=Wc;id=-1;startTimeMillis=-1;[C](){return qc}[O](e){return el(e)&&e._tag===Wc}toString(){return St(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag}}[A](){return this.toJSON()}},Yc=class{id;startTimeMillis;[Uc]=Uc;_tag=Gc;constructor(e,t){this.id=e,this.startTimeMillis=t}[C](){return D(this,E(`${Hc}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[O](e){return el(e)&&e._tag===Gc&&this.id===e.id&&this.startTimeMillis===e.startTimeMillis}toString(){return St(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag,id:this.id,startTimeMillis:this.startTimeMillis}}[A](){return this.toJSON()}},Xc=class{left;right;[Uc]=Uc;_tag=Kc;constructor(e,t){this.left=e,this.right=t}_hash;[C](){return b(E(`${Hc}-${this._tag}`),T(w(this.left)),T(w(this.right)),D(this))}[O](e){return el(e)&&e._tag===Kc&&k(this.left,e.left)&&k(this.right,e.right)}toString(){return St(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag,left:gt(this.left),right:gt(this.right)}}[A](){return this.toJSON()}};const Zc=new Jc,Qc=(e,t)=>new Yc(e,t),$c=(e,t)=>new Xc(e,t),el=e=>S(e,Uc),tl=e=>{switch(e._tag){case Wc:return po();case Gc:return ho(e.id);case Kc:return b(tl(e.left),xo(tl(e.right)))}},nl=x(Symbol.for(`effect/Fiber/Id/_fiberCounter`),()=>zc(0)),rl=e=>Array.from(tl(e)).map(e=>`#${e}`).join(`,`),il=()=>{let e=Bc(nl);return b(nl,Vc(e+1)),new Yc(e,Date.now())},al=Zc,ol=Qc,sl=$c,cl=el,ll=rl,ul=il,dl=Da,fl=Oa,pl=Aa,ml=ja,hl=Pa,gl=Ia,_l=Ba,vl=Ua,yl=Ga,bl=Symbol.for(`effect/List`),xl=e=>lr(e),Sl=(e=>we(Yr(e),xl))(k),Cl={[bl]:bl,_tag:`Cons`,toString(){return St(this.toJSON())},toJSON(){return{_id:`List`,_tag:`Cons`,values:xl(this).map(gt)}},[A](){return this.toJSON()},[O](e){return Dl(e)&&this._tag===e._tag&&Sl(this,e)},[C](){return D(this,ft(xl(this)))},[Symbol.iterator](){let e=!1,t=this;return{next(){if(e)return this.return();if(t._tag===`Nil`)return e=!0,this.return();let n=t.head;return t=t.tail,{done:e,value:n}},return(t){return e||=!0,{done:!0,value:t}}}},pipe(){return j(this,arguments)}},wl=(e,t)=>{let n=Object.create(Cl);return n.head=e,n.tail=t,n},Tl=E(`Nil`),El=Object.create({[bl]:bl,_tag:`Nil`,toString(){return St(this.toJSON())},toJSON(){return{_id:`List`,_tag:`Nil`}},[A](){return this.toJSON()},[C](){return Tl},[O](e){return Dl(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return j(this,arguments)}}),Dl=e=>S(e,bl),Ol=e=>e._tag===`Nil`,kl=e=>e._tag===`Cons`,Al=()=>El,jl=(e,t)=>wl(e,t),Ml=Al,Nl=e=>wl(e,El),Pl=v(2,(e,t)=>Il(t,e)),Fl=v(2,(e,t)=>jl(t,e)),Il=v(2,(e,t)=>{if(Ol(e))return t;if(Ol(t))return e;{let n=wl(t.head,e),r=n,i=t.tail;for(;!Ol(i);){let t=wl(i.head,e);r.tail=t,r=t,i=i.tail}return n}}),Ll=v(3,(e,t,n)=>{let r=t,i=e;for(;!Ol(i);)r=n(r,i.head),i=i.tail;return r}),Rl=e=>{let t=Ml(),n=e;for(;!Ol(n);)t=Fl(t,n.head),n=n.tail;return t};Array.prototype;const zl=function(){function e(e){e&&Object.assign(this,e)}return e.prototype=$t,e}(),Bl=Symbol.for(`effect/DifferContextPatch`);function Vl(e){return e}const Hl={...zl.prototype,[Bl]:{_Value:Vl,_Patch:Vl}},Ul=Object.create(Object.assign(Object.create(Hl),{_tag:`Empty`})),Wl=()=>Ul,Gl=Object.assign(Object.create(Hl),{_tag:`AndThen`}),Kl=(e,t)=>{let n=Object.create(Gl);return n.first=e,n.second=t,n},ql=Object.assign(Object.create(Hl),{_tag:`AddService`}),Jl=(e,t)=>{let n=Object.create(ql);return n.key=e,n.service=t,n},Yl=Object.assign(Object.create(Hl),{_tag:`RemoveService`}),Xl=e=>{let t=Object.create(Yl);return t.key=e,t},Zl=Object.assign(Object.create(Hl),{_tag:`UpdateService`}),Ql=(e,t)=>{let n=Object.create(Zl);return n.key=e,n.update=t,n},$l=(e,t)=>{let n=new Map(e.unsafeMap),r=Wl();for(let[e,i]of t.unsafeMap.entries())if(n.has(e)){let t=n.get(e);n.delete(e),k(t,i)||(r=eu(Ql(e,()=>i))(r))}else n.delete(e),r=eu(Jl(e,i))(r);for(let[e]of n.entries())r=eu(Xl(e))(r);return r},eu=v(2,(e,t)=>Kl(e,t)),tu=v(2,(e,t)=>{if(e._tag===`Empty`)return t;let n=!1,r=Fi(e),i=new Map(t.unsafeMap);for(;Ji(r);){let e=Xi(r),t=Zi(r);switch(e._tag){case`Empty`:r=t;break;case`AddService`:i.set(e.key,e.service),r=t;break;case`AndThen`:r=Wi(Wi(t,e.second),e.first);break;case`RemoveService`:i.delete(e.key),r=t;break;case`UpdateService`:i.set(e.key,e.update(i.get(e.key))),n=!0,r=t}}if(!n)return Os(i);let a=new Map;for(let[e]of t.unsafeMap)i.has(e)&&(a.set(e,i.get(e)),i.delete(e));for(let[e,t]of i)a.set(e,t);return Os(a)}),nu=Symbol.for(`effect/DifferHashSetPatch`);function ru(e){return e}const iu={...zl.prototype,[nu]:{_Value:ru,_Key:ru,_Patch:ru}},au=Object.create(Object.assign(Object.create(iu),{_tag:`Empty`})),ou=()=>au,su=Object.assign(Object.create(iu),{_tag:`AndThen`}),cu=(e,t)=>{let n=Object.create(su);return n.first=e,n.second=t,n},lu=Object.assign(Object.create(iu),{_tag:`Add`}),uu=e=>{let t=Object.create(lu);return t.value=e,t},du=Object.assign(Object.create(iu),{_tag:`Remove`}),fu=e=>{let t=Object.create(du);return t.value=e,t},pu=(e,t)=>{let[n,r]=So([e,ou()],([e,t],n)=>go(n)(e)?[yo(n)(e),t]:[e,mu(uu(n))(t)])(t);return So(r,(e,t)=>mu(fu(t))(e))(n)},mu=v(2,(e,t)=>cu(e,t)),hu=v(2,(e,t)=>{if(e._tag===`Empty`)return t;let n=t,r=Fi(e);for(;Ji(r);){let e=Xi(r),t=Zi(r);switch(e._tag){case`Empty`:r=t;break;case`AndThen`:r=Wi(e.first)(Wi(e.second)(t));break;case`Add`:n=vo(e.value)(n),r=t;break;case`Remove`:n=yo(e.value)(n),r=t}}return n}),gu=Symbol.for(`effect/DifferReadonlyArrayPatch`);function _u(e){return e}const vu={...zl.prototype,[gu]:{_Value:_u,_Patch:_u}},yu=Object.create(Object.assign(Object.create(vu),{_tag:`Empty`})),bu=()=>yu,xu=Object.assign(Object.create(vu),{_tag:`AndThen`}),Su=(e,t)=>{let n=Object.create(xu);return n.first=e,n.second=t,n},Cu=Object.assign(Object.create(vu),{_tag:`Append`}),wu=e=>{let t=Object.create(Cu);return t.values=e,t},Tu=Object.assign(Object.create(vu),{_tag:`Slice`}),Eu=(e,t)=>{let n=Object.create(Tu);return n.from=e,n.until=t,n},Du=Object.assign(Object.create(vu),{_tag:`Update`}),Ou=(e,t)=>{let n=Object.create(Du);return n.index=e,n.patch=t,n},ku=e=>{let t=0,n=bu();for(;t<e.oldValue.length&&t<e.newValue.length;){let r=e.oldValue[t],i=e.newValue[t],a=e.differ.diff(r,i);k(a,e.differ.empty)||(n=Au(n,Ou(t,a))),t+=1}return t<e.oldValue.length&&(n=Au(n,Eu(0,t))),t<e.newValue.length&&(n=Au(n,wu(Ar(t)(e.newValue)))),n},Au=v(2,(e,t)=>Su(e,t)),ju=v(3,(e,t,n)=>{if(e._tag===`Empty`)return t;let r=t.slice(),i=Hr(e);for(;_r(i);){let e=wr(i),t=Dr(i);switch(e._tag){case`Empty`:i=t;break;case`AndThen`:t.unshift(e.first,e.second),i=t;break;case`Append`:for(let t of e.values)r.push(t);i=t;break;case`Slice`:r=r.slice(e.from,e.until),i=t;break;case`Update`:r[e.index]=n.patch(e.patch,r[e.index]),i=t}}return r}),Mu={[Symbol.for(`effect/Differ`)]:{_P:y,_V:y},pipe(){return j(this,arguments)}},Nu=e=>{let t=Object.create(Mu);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},Pu=()=>Nu({empty:Wl(),combine:(e,t)=>eu(t)(e),diff:(e,t)=>$l(e,t),patch:(e,t)=>tu(t)(e)}),Fu=()=>Nu({empty:ou(),combine:(e,t)=>mu(t)(e),diff:(e,t)=>pu(e,t),patch:(e,t)=>hu(t)(e)}),Iu=e=>Nu({empty:bu(),combine:(e,t)=>Au(e,t),diff:(t,n)=>ku({oldValue:t,newValue:n,differ:e}),patch:(t,n)=>ju(t,n,e)}),Lu=()=>Ru((e,t)=>t),Ru=e=>Nu({empty:y,combine:(e,t)=>e===y?t:t===y?e:n=>t(e(n)),diff:(e,t)=>k(e,t)?y:_e(t),patch:(t,n)=>e(n,t(n))}),zu=e=>e&255,Bu=e=>e>>8&255,Vu=(e,t)=>(e&255)+((t&e&255)<<8),Hu=Vu(0,0),Uu=e=>Vu(e,e),Wu=e=>Vu(e,0),Gu=v(2,(e,t)=>Vu(zu(e)&~t,Bu(e))),Ku=v(2,(e,t)=>e|t),qu=e=>~e>>>0&255,Ju=e=>Qu(e,32),Yu=v(2,(e,t)=>e|t),Xu=e=>Zu(e)&&!nd(e),Zu=e=>Qu(e,1),Qu=v(2,(e,t)=>(e&t)!==0),$u=(...e)=>e.reduce((e,t)=>e|t,0),ed=$u(0),td=e=>Qu(e,4),nd=e=>Qu(e,16),rd=v(2,(e,t)=>Vu(e^t,t)),id=v(2,(e,t)=>e&(qu(zu(t))|Bu(t))|zu(t)&Bu(t)),ad=Nu({empty:Hu,diff:(e,t)=>rd(e,t),combine:(e,t)=>Ku(t)(e),patch:(e,t)=>id(t,e)}),od=Uu,sd=Wu,cd=Gu,ld=(e,t)=>({_tag:`Par`,left:e,right:t}),ud=(e,t)=>({_tag:`Seq`,left:e,right:t}),dd=e=>{let t=Nl(e),n=Ml();for(;;){let[e,r]=Ll(t,[_d(),Ml()],([e,t],n)=>{let[r,i]=fd(n);return[yd(e,r),Pl(t,i)]});if(n=pd(n,e),Ol(r))return Rl(n);t=r}throw Error(`BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues`)},fd=e=>{let t=e,n=_d(),r=Ml(),i=Ml();for(;;)switch(t._tag){case`Empty`:if(Ol(r))return[n,i];t=r.head,r=r.tail;break;case`Par`:r=jl(t.right,r),t=t.left;break;case`Seq`:{let e=t.left,n=t.right;switch(e._tag){case`Empty`:t=n;break;case`Par`:{let r=e.left,i=e.right;t=ld(ud(r,n),ud(i,n));break}case`Seq`:{let r=e.left,i=e.right;t=ud(r,ud(i,n));break}case`Single`:t=e,i=jl(n,i)}break}case`Single`:if(n=vd(n,t),Ol(r))return[n,i];t=r.head,r=r.tail}throw Error(`BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues`)},pd=(e,t)=>{if(Ol(e))return Nl(Sd(t));if(bd(t))return e;let n=Od(e.head),r=xd(t);return n.length===1&&r.length===1&&k(n[0],r[0])?jl(Dd(e.head,Sd(t)),e.tail):jl(Sd(t),e)},md=Symbol.for(`effect/RequestBlock/RequestBlockParallel`),hd={_R:e=>e};var gd=class{map;[md]=hd;constructor(e){this.map=e}};const _d=()=>new gd(dl()),vd=(e,t)=>new gd(_l(e.map,t.dataSource,e=>qn(Qn(e,Ui(t.blockedRequest)),()=>Fi(t.blockedRequest)))),yd=(e,t)=>new gd(yl(e.map,t.map,(e,t,n)=>hl(e,n,Wn(ml(e,n),{onNone:()=>t,onSome:e=>Ki(t,e)})))),bd=e=>pl(e.map),xd=e=>Array.from(gl(e.map)),Sd=e=>Ed(vl(e.map,e=>Fi(e))),Cd=Symbol.for(`effect/RequestBlock/RequestBlockSequential`),wd={_R:e=>e};var Td=class{map;[Cd]=wd;constructor(e){this.map=e}};const Ed=e=>new Td(e),Dd=(e,t)=>new Td(yl(t.map,e.map,(e,t,n)=>hl(e,n,Wn(ml(e,n),{onNone:()=>Ni(),onSome:e=>Ki(e,t)})))),Od=e=>Array.from(gl(e.map)),kd=e=>Array.from(e.map),Ad=`Pending`,jd=`Done`,Md=Symbol.for(`effect/Deferred`),Nd={_E:e=>e,_A:e=>e},Pd=e=>({_tag:Ad,joiners:e}),Fd=e=>({_tag:jd,effect:e});var Id=class e{self;called=!1;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(e){return{value:e,done:!0}}throw(e){throw e}[Symbol.iterator](){return new e(this.self)}};const Ld=(e,t)=>{let n=new Vd(`Blocked`);return n.effect_instruction_i0=e,n.effect_instruction_i1=t,n},Rd=e=>{let t=new Vd(`RunBlocked`);return t.effect_instruction_i0=e,t},zd=Symbol.for(`effect/Effect`);var Bd=class{patch;op;_op=Ut;constructor(e,t){this.patch=e,this.op=t}},Vd=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[zd]=Yt;constructor(e){this._op=e}[O](e){return this===e}[C](){return D(this,ot(this))}pipe(){return j(this,arguments)}toJSON(){return{_id:`Effect`,_op:this._op,effect_instruction_i0:gt(this.effect_instruction_i0),effect_instruction_i1:gt(this.effect_instruction_i1),effect_instruction_i2:gt(this.effect_instruction_i2)}}toString(){return St(this.toJSON())}[A](){return this.toJSON()}[Symbol.iterator](){return new Id(new et(this))}},Hd=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[zd]=Yt;constructor(e){this._op=e,this._tag=e}[O](e){return zp(e)&&e._op===`Failure`&&k(this.effect_instruction_i0,e.effect_instruction_i0)}[C](){return b(E(this._tag),T(w(this.effect_instruction_i0)),D(this))}get cause(){return this.effect_instruction_i0}pipe(){return j(this,arguments)}toJSON(){return{_id:`Exit`,_tag:this._op,cause:this.cause.toJSON()}}toString(){return St(this.toJSON())}[A](){return this.toJSON()}[Symbol.iterator](){return new Id(new et(this))}},Ud=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[zd]=Yt;constructor(e){this._op=e,this._tag=e}[O](e){return zp(e)&&e._op===`Success`&&k(this.effect_instruction_i0,e.effect_instruction_i0)}[C](){return b(E(this._tag),T(w(this.effect_instruction_i0)),D(this))}get value(){return this.effect_instruction_i0}pipe(){return j(this,arguments)}toJSON(){return{_id:`Exit`,_tag:this._op,value:gt(this.value)}}toString(){return St(this.toJSON())}[A](){return this.toJSON()}[Symbol.iterator](){return new Id(new et(this))}};const Wd=e=>S(e,zd),Gd=e=>{let t=new Vd(Vt);return t.effect_instruction_i0=e,t},Kd=v(3,(e,t,n)=>jf(r=>I(e,e=>I(of(Df(()=>r(t(e)))),t=>Df(()=>n(e,t)).pipe(gf({onFailure:e=>{switch(t._tag){case Mt:return lf(Lo(t.effect_instruction_i0,e));case It:return lf(e)}},onSuccess:()=>t})))))),qd=v(2,(e,t)=>I(e,()=>Ef(t))),Jd=e=>qd(e,void 0),Yd=function(){let e=new Vd(jt);switch(arguments.length){case 2:e.effect_instruction_i0=arguments[0],e.commit=arguments[1];break;case 3:e.effect_instruction_i0=arguments[0],e.effect_instruction_i1=arguments[1],e.commit=arguments[2];break;case 4:e.effect_instruction_i0=arguments[0],e.effect_instruction_i1=arguments[1],e.effect_instruction_i2=arguments[2],e.commit=arguments[3];break;default:throw Error(Je(`you're not supposed to end up here`))}return e},Xd=(e,t=al)=>{let n=new Vd(At),r;return n.effect_instruction_i0=t=>{r=e(t)},n.effect_instruction_i1=t,Tf(n,e=>Wd(r)?r:Mf)},Zd=(e,t=al)=>Df(()=>Xd(e,t)),Qd=(e,t=al)=>Yd(e,function(){let e,n;function r(t){e?e(t):n===void 0&&(n=t)}let i=new Vd(At);i.effect_instruction_i0=t=>{e=t,n&&t(n)},i.effect_instruction_i1=t;let a,o;return this.effect_instruction_i0.length===1?a=it(()=>this.effect_instruction_i0(r)):(o=new AbortController,a=it(()=>this.effect_instruction_i0(r,o.signal))),a||o?Tf(i,e=>(o&&o.abort(),a??Mf)):i}),$d=v(2,(e,t)=>_f(e,{onFailure:t,onSuccess:Ef})),ef=Symbol.for(`effect/OriginalAnnotation`),tf=(e,t)=>Un(t)?new Proxy(e,{has(e,t){return t===gs||t===ef||t in e},get(n,r){return r===gs?t.value:r===ef?e:n[r]}}):e,nf=e=>ze(e)&&!(gs in e)?Gd(t=>lf(Po(tf(e,cm(t))))):lf(Po(e)),rf=e=>uf(()=>Po(new Ap(e))),af=e=>_f(e,{onFailure:e=>Ef(N(e)),onSuccess:e=>Ef(M(e))}),of=e=>hf(e,{onFailure:R,onSuccess:Yp}),sf=e=>ze(e)&&!(gs in e)?Gd(t=>lf(No(tf(e,cm(t))))):lf(No(e)),cf=e=>I(L(e),sf),lf=e=>{let t=new Hd(Mt);return t.effect_instruction_i0=e,t},uf=e=>I(L(e),lf),df=Gd(e=>Ef(e.id())),ff=e=>Gd(t=>e(t.id())),I=v(2,(e,t)=>{let n=new Vd(Pt);return n.effect_instruction_i0=e,n.effect_instruction_i1=t,n}),pf=e=>{let t=new Vd(`OnStep`);return t.effect_instruction_i0=e,t},mf=e=>I(e,y),hf=v(2,(e,t)=>gf(e,{onFailure:e=>Ef(t.onFailure(e)),onSuccess:e=>Ef(t.onSuccess(e))})),gf=v(2,(e,t)=>{let n=new Vd(Ft);return n.effect_instruction_i0=e,n.effect_instruction_i1=t.onFailure,n.effect_instruction_i2=t.onSuccess,n}),_f=v(2,(e,t)=>gf(e,{onFailure:e=>{if(Go(e).length>0)return lf(Zo(e));let n=Wo(e);return n.length>0?t.onFailure(Yi(n)):lf(e)},onSuccess:t.onSuccess})),vf=v(2,(e,t)=>Df(()=>{let n=lr(e),r=sr(n.length),i=0;return qd(Pf({while:()=>i<n.length,body:()=>t(n[i],i),step:e=>{r[i++]=e}}),r)})),yf=v(2,(e,t)=>Df(()=>{let n=lr(e),r=0;return Pf({while:()=>r<n.length,body:()=>t(n[r],r),step:()=>{r++}})})),bf=e=>{let t=new Vd(Rt);return t.effect_instruction_i0=od(1),t.effect_instruction_i1=()=>e,t},xf=v(2,(e,t)=>I(e,e=>L(()=>t(e)))),Sf=v(2,(e,t)=>_f(e,{onFailure:e=>cf(()=>t.onFailure(e)),onSuccess:e=>L(()=>t.onSuccess(e))})),Cf=v(2,(e,t)=>gf(e,{onFailure:e=>{let n=Jo(e);switch(n._tag){case`Left`:return cf(()=>t(n.left));case`Right`:return lf(n.right)}},onSuccess:Ef})),wf=v(2,(e,t)=>jf(n=>gf(n(e),{onFailure:e=>{let n=R(e);return gf(t(n),{onFailure:t=>R(Lo(e,t)),onSuccess:()=>n})},onSuccess:e=>{let n=Yp(e);return Rf(t(n),n)}}))),Tf=v(2,(e,t)=>wf(e,Jp({onFailure:e=>Uo(e)?Jd(t(Ko(e))):Mf,onSuccess:()=>Mf}))),Ef=e=>{let t=new Ud(It);return t.effect_instruction_i0=e,t},Df=e=>{let t=new Vd(jt);return t.commit=e,t},L=e=>{let t=new Vd(Lt);return t.effect_instruction_i0=e,t},Of=v(e=>e.length===3||e.length===2&&!(ze(e[1])&&`onlyEffect`in e[1]),(e,t)=>I(e,e=>{let n=typeof t==`function`?t(e):t;return Wd(n)?qd(n,e):qe(n)?Xd(t=>{n.then(n=>t(Ef(e)),e=>t(sf(new Rp(e,`An unknown error occurred in Effect.tap`))))}):Ef(e)})),kf=e=>Gd(t=>{let n=b(t.getFiberRef(bp),Gn(()=>t.scope()));return e(tp(bp,F(n)))}),Af=e=>{let t=new Vd(Rt);return t.effect_instruction_i0=sd(1),t.effect_instruction_i1=()=>e,t},jf=e=>Yd(e,function(){let e=new Vd(Rt);return e.effect_instruction_i0=sd(1),e.effect_instruction_i1=e=>Zu(e)?it(()=>this.effect_instruction_i0(bf)):it(()=>this.effect_instruction_i0(Af)),e}),Mf=Ef(void 0),Nf=e=>{let t=new Vd(Rt);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t},Pf=e=>{let t=new Vd(zt);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t},Ff=e=>{let t=new Vd(Ht);return e?.priority===void 0?t:mp(t,e.priority)},If=v(2,(e,t)=>I(e,e=>xf(t,t=>[e,t]))),Lf=v(2,(e,t)=>I(e,e=>qd(t,e))),Rf=v(2,(e,t)=>I(e,()=>t)),zf=e=>I(df,t=>b(e,Bf(t))),Bf=v(2,(e,t)=>I(e.interruptAsFork(t),()=>e.await)),Vf={_tag:`All`,syslog:0,label:`ALL`,ordinal:-(2**53-1),pipe(){return j(this,arguments)}},Hf={_tag:`Fatal`,syslog:2,label:`FATAL`,ordinal:5e4,pipe(){return j(this,arguments)}},Uf={_tag:`Error`,syslog:3,label:`ERROR`,ordinal:4e4,pipe(){return j(this,arguments)}},Wf={_tag:`Warning`,syslog:4,label:`WARN`,ordinal:3e4,pipe(){return j(this,arguments)}},Gf={_tag:`Info`,syslog:6,label:`INFO`,ordinal:2e4,pipe(){return j(this,arguments)}},Kf={_tag:`Debug`,syslog:7,label:`DEBUG`,ordinal:1e4,pipe(){return j(this,arguments)}},qf={_tag:`Trace`,syslog:7,label:`TRACE`,ordinal:0,pipe(){return j(this,arguments)}},Jf={_tag:`None`,syslog:7,label:`OFF`,ordinal:2**53-1,pipe(){return j(this,arguments)}},Yf=Symbol.for(`effect/FiberRef`),Xf={_A:e=>e},Zf=e=>Gd(t=>Yp(t.getFiberRef(e))),Qf=v(2,(e,t)=>I(Zf(e),t)),$f=v(2,(e,t)=>ep(e,()=>[void 0,t])),ep=v(2,(e,t)=>Gd(n=>{let[r,i]=t(n.getFiberRef(e));return n.setFiberRef(e,i),Ef(r)})),tp=v(3,(e,t,n)=>Kd(Lf(Zf(t),$f(t,n)),()=>e,e=>$f(t,e))),np=(e,t)=>op(e,{differ:Lu(),fork:t?.fork??y,join:t?.join}),rp=e=>{let t=Fu();return op(e,{differ:t,fork:t.empty})},ip=e=>{let t=Iu(Lu());return op(e,{differ:t,fork:t.empty})},ap=e=>{let t=Pu();return op(e,{differ:t,fork:t.empty})},op=(e,t)=>({...en,[Yf]:Xf,initial:e,commit(){return Zf(this)},diff:(e,n)=>t.differ.diff(e,n),combine:(e,n)=>t.differ.combine(e,n),patch:e=>n=>t.differ.patch(e,n),fork:t.fork,join:t.join??((e,t)=>t)}),sp=e=>op(e,{differ:ad,fork:ad.empty}),cp=x(Symbol.for(`effect/FiberRef/currentContext`),()=>ap(Ws())),lp=x(Symbol.for(`effect/FiberRef/currentSchedulingPriority`),()=>np(0)),up=x(Symbol.for(`effect/FiberRef/currentMaxOpsBeforeYield`),()=>np(2048)),dp=x(Symbol.for(`effect/FiberRef/currentLogAnnotation`),()=>np(dl())),fp=x(Symbol.for(`effect/FiberRef/currentLogLevel`),()=>np(Gf)),pp=x(Symbol.for(`effect/FiberRef/currentLogSpan`),()=>np(Ml())),mp=v(2,(e,t)=>tp(e,lp,t)),hp=x(Symbol.for(`effect/FiberRef/currentConcurrency`),()=>np(`unbounded`)),gp=x(Symbol.for(`effect/FiberRef/currentRequestBatching`),()=>np(!0)),_p=x(Symbol.for(`effect/FiberRef/currentUnhandledErrorLogLevel`),()=>np(F(Kf))),vp=x(Symbol.for(`effect/FiberRef/versionMismatchErrorLogLevel`),()=>np(F(Wf))),yp=x(Symbol.for(`effect/FiberRef/currentMetricLabels`),()=>ip(Vr())),bp=x(Symbol.for(`effect/FiberRef/currentForkScopeOverride`),()=>np(P(),{fork:()=>P(),join:(e,t)=>e})),xp=x(Symbol.for(`effect/FiberRef/currentInterruptedCause`),()=>np(Mo,{fork:()=>Mo,join:(e,t)=>e})),Sp=Symbol.for(`effect/Scope`),Cp=Symbol.for(`effect/CloseableScope`),wp=(e,t)=>e.addFinalizer(()=>Jd(t)),Tp=(e,t)=>e.close(t),Ep=(e,t)=>e.fork(t),Dp=function(){class e extends globalThis.Error{commit(){return sf(this)}toJSON(){let e={...this};return this.message&&(e.message=this.message),this.cause&&(e.cause=this.cause),e}[A](){return this.toString===globalThis.Error.prototype.toString?`Bun`in globalThis?ls(No(this),{renderErrorCause:!0}):this:this.stack?`${this.toString()}\n${this.stack.split(`
12
+ `)}return t},Pc=e=>w(e,Ac),Fc=e=>w(e,Sc),Ic=Mc(new Map),Lc=()=>Ic,Rc=(e,t)=>Mc(new Map([[e.key,t]])),zc=x(3,(e,t,n)=>{let r=new Map(e.unsafeMap);return r.set(t.key,n),Mc(r)}),Bc=C(`effect/Context/defaultValueCache`,()=>new Map),Vc=e=>{if(Bc.has(e.key))return Bc.get(e.key);let t=e.defaultValue();return Bc.set(e.key,t),t},Hc=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):Vc(t),Uc=x(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(Sc in t)return Vc(t);throw Nc(t)}return e.unsafeMap.get(t.key)}),Wc=Uc,Gc=x(2,(e,t)=>e.unsafeMap.has(t.key)?Rn(e.unsafeMap.get(t.key)):Fc(t)?Rn(Vc(t)):Ln),Kc=x(2,(e,t)=>{let n=new Map(e.unsafeMap);for(let[e,r]of t.unsafeMap)n.set(e,r);return Mc(n)})})),Jc,Yc,Xc,Zc,Qc,$c,el,tl,nl,rl,il=v((()=>{qc(),Jc=Dc,Yc=Lc,Xc=Rc,Zc=zc,Qc=Wc,$c=Uc,el=Gc,tl=Kc,nl=Oc,rl=kc})),al,ol,sl,cl,ll,ul,dl,fl,pl,ml,hl,gl,_l,vl,yl,bl,xl,Sl,Cl,wl,Tl,El,Dl,Ol,kl,Al,jl,Ml,Nl,Pl,Fl,Il,Ll,Rl,zl,Bl,Vl,Hl,Ul=v((()=>{M(),S(),Mt(),Xt(),Rr(),F(),T(),al=Symbol.for(`effect/Duration`),ol=BigInt(0),sl=BigInt(24),cl=BigInt(60),ll=BigInt(1e3),ul=BigInt(1e6),dl=BigInt(1e9),fl=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,pl=e=>{if(vl(e))return e;if(ze(e))return Tl(e);if(Ve(e))return Cl(e);if(Array.isArray(e)&&e.length===2&&e.every(ze))return e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1])?xl:e[0]===1/0||e[1]===1/0?Sl:Cl(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])));if(Re(e)){let t=fl.exec(e);if(t){let[e,n,r]=t,i=Number(n);switch(r){case`nano`:case`nanos`:return Cl(BigInt(n));case`micro`:case`micros`:return wl(BigInt(n));case`milli`:case`millis`:return Tl(i);case`second`:case`seconds`:return El(i);case`minute`:case`minutes`:return Dl(i);case`hour`:case`hours`:return Ol(i);case`day`:case`days`:return kl(i);case`week`:case`weeks`:return Al(i)}}}throw Error(`Invalid DurationInput`)},ml={_tag:`Millis`,millis:0},hl={_tag:`Infinity`},gl={[al]:al,[E](){return k(this,At(this.value))},[j](e){return vl(e)&&Bl(this,e)},toString(){return`Duration(${Hl(this)})`},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,hrtime:Pl(this)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`}}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},_l=e=>{let t=Object.create(gl);return t.value=ze(e)?isNaN(e)||e<=0?ml:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:BigInt(Math.round(e*1e6))}:hl:e<=ol?ml:{_tag:`Nanos`,nanos:e},t},vl=e=>w(e,al),yl=e=>e.value._tag!==`Infinity`,bl=e=>{switch(e.value._tag){case`Millis`:return e.value.millis===0;case`Nanos`:return e.value.nanos===ol;case`Infinity`:return!1}},xl=_l(0),Sl=_l(1/0),Cl=e=>_l(e),wl=e=>_l(e*ll),Tl=e=>_l(e),El=e=>_l(e*1e3),Dl=e=>_l(e*6e4),Ol=e=>_l(e*36e5),kl=e=>_l(e*864e5),Al=e=>_l(e*6048e5),jl=e=>Fl(e,{onMillis:e=>e,onNanos:e=>Number(e)/1e6}),Ml=e=>{let t=pl(e);switch(t.value._tag){case`Infinity`:return R();case`Nanos`:return z(t.value.nanos);case`Millis`:return z(BigInt(Math.round(t.value.millis*1e6)))}},Nl=e=>{let t=pl(e);switch(t.value._tag){case`Infinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return BigInt(Math.round(t.value.millis*1e6))}},Pl=e=>{let t=pl(e);switch(t.value._tag){case`Infinity`:return[1/0,0];case`Nanos`:return[Number(t.value.nanos/dl),Number(t.value.nanos%dl)];case`Millis`:return[Math.floor(t.value.millis/1e3),Math.round(t.value.millis%1e3*1e6)]}},Fl=x(2,(e,t)=>{let n=pl(e);switch(n.value._tag){case`Nanos`:return t.onNanos(n.value.nanos);case`Infinity`:return t.onMillis(1/0);case`Millis`:return t.onMillis(n.value.millis)}}),Il=x(3,(e,t,n)=>{let r=pl(e),i=pl(t);if(r.value._tag===`Infinity`||i.value._tag===`Infinity`)return n.onMillis(jl(r),jl(i));if(r.value._tag===`Nanos`||i.value._tag===`Nanos`){let e=r.value._tag===`Nanos`?r.value.nanos:BigInt(Math.round(r.value.millis*1e6)),t=i.value._tag===`Nanos`?i.value.nanos:BigInt(Math.round(i.value.millis*1e6));return n.onNanos(e,t)}return n.onMillis(r.value.millis,i.value.millis)}),Ll=(e,t)=>Il(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t}),Rl=x(2,(e,t)=>Il(e,t,{onMillis:(e,t)=>e<=t,onNanos:(e,t)=>e<=t})),zl=x(2,(e,t)=>Il(e,t,{onMillis:(e,t)=>e>=t,onNanos:(e,t)=>e>=t})),Bl=x(2,(e,t)=>Ll(pl(e),pl(t))),Vl=e=>{let t=pl(e);if(t.value._tag===`Infinity`)return{days:1/0,hours:1/0,minutes:1/0,seconds:1/0,millis:1/0,nanos:1/0};let n=Nl(t),r=n/ul,i=r/ll,a=i/cl,o=a/cl,s=o/sl;return{days:Number(s),hours:Number(o%sl),minutes:Number(a%cl),seconds:Number(i%cl),millis:Number(r%ll),nanos:Number(n%ul)}},Hl=e=>{let t=pl(e);if(t.value._tag===`Infinity`)return`Infinity`;if(bl(t))return`0`;let n=Vl(t),r=[];return n.days!==0&&r.push(`${n.days}d`),n.hours!==0&&r.push(`${n.hours}h`),n.minutes!==0&&r.push(`${n.minutes}m`),n.seconds!==0&&r.push(`${n.seconds}s`),n.millis!==0&&r.push(`${n.millis}ms`),n.nanos!==0&&r.push(`${n.nanos}ns`),r.join(` `)}})),Wl,Gl,Kl,ql,Jl,Yl=v((()=>{S(),Xt(),F(),Wl=Symbol.for(`effect/MutableRef`),Gl={[Wl]:Wl,toString(){return Ht(this.toJSON())},toJSON(){return{_id:`MutableRef`,current:Bt(this.current)}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},Kl=e=>{let t=Object.create(Gl);return t.current=e,t},ql=e=>e.current,Jl=x(2,(e,t)=>(e.current=t,e))})),Xl,Zl,Ql,$l,eu,tu,nu,ru,iu,au,ou,su,cu,lu,uu,du,fu,pu=v((()=>{M(),S(),Ie(),Mt(),Cs(),Xt(),Yl(),T(),Xl=`effect/FiberId`,Zl=Symbol.for(Xl),Ql=`None`,$l=`Runtime`,eu=`Composite`,tu=Ot(`${Xl}-${Ql}`),nu=class{[Zl]=Zl;_tag=Ql;id=-1;startTimeMillis=-1;[E](){return tu}[j](e){return cu(e)&&e._tag===Ql}toString(){return Ht(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag}}[N](){return this.toJSON()}},ru=class{id;startTimeMillis;[Zl]=Zl;_tag=$l;constructor(e,t){this.id=e,this.startTimeMillis=t}[E](){return k(this,Ot(`${Xl}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[j](e){return cu(e)&&e._tag===$l&&this.id===e.id&&this.startTimeMillis===e.startTimeMillis}toString(){return Ht(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag,id:this.id,startTimeMillis:this.startTimeMillis}}[N](){return this.toJSON()}},iu=class{left;right;[Zl]=Zl;_tag=eu;constructor(e,t){this.left=e,this.right=t}_hash;[E](){return b(Ot(`${Xl}-${this._tag}`),O(D(this.left)),O(D(this.right)),k(this))}[j](e){return cu(e)&&e._tag===eu&&A(this.left,e.left)&&A(this.right,e.right)}toString(){return Ht(this.toJSON())}toJSON(){return{_id:`FiberId`,_tag:this._tag,left:Bt(this.left),right:Bt(this.right)}}[N](){return this.toJSON()}},au=new nu,ou=(e,t)=>new ru(e,t),su=(e,t)=>new iu(e,t),cu=e=>w(e,Zl),lu=e=>{switch(e._tag){case Ql:return ps();case $l:return hs(e.id);case eu:return b(lu(e.left),xs(lu(e.right)))}},uu=C(Symbol.for(`effect/Fiber/Id/_fiberCounter`),()=>Kl(0)),du=e=>Array.from(lu(e)).map(e=>`#${e}`).join(`,`),fu=()=>{let e=ql(uu);return b(uu,Jl(e+1)),new ru(e,Date.now())}})),mu,hu,gu,_u,vu,yu,bu=v((()=>{pu(),mu=au,hu=ou,gu=su,_u=cu,vu=du,yu=fu})),xu,Su,Cu,wu,Tu,Eu,Du,Ou,ku,Au=v((()=>{Go(),xu=Eo,Su=Do,Cu=ko,wu=Ao,Tu=No,Eu=Fo,Du=zo,Ou=Ho,ku=Wo})),ju,Mu,Nu,Pu,Fu,Iu,Lu,Ru,zu,Bu,Vu,Hu,Uu,Wu,Gu,Ku,qu,Ju,Yu,Xu,Zu,Qu=v((()=>{Pi(),M(),Ne(),S(),Mt(),Xt(),F(),T(),ju=Symbol.for(`effect/List`),Mu=e=>Ur(e),Nu=e=>Ae(Ai(e),Mu),Pu=Nu(A),Fu={[ju]:ju,_tag:`Cons`,toString(){return Ht(this.toJSON())},toJSON(){return{_id:`List`,_tag:`Cons`,values:Mu(this).map(Bt)}},[N](){return this.toJSON()},[j](e){return Bu(e)&&this._tag===e._tag&&Pu(this,e)},[E](){return k(this,jt(Mu(this)))},[Symbol.iterator](){let e=!1,t=this;return{next(){if(e)return this.return();if(t._tag===`Nil`)return e=!0,this.return();let n=t.head;return t=t.tail,{done:e,value:n}},return(t){return e||=!0,{done:!0,value:t}}}},pipe(){return P(this,arguments)}},Iu=(e,t)=>{let n=Object.create(Fu);return n.head=e,n.tail=t,n},Lu=Ot(`Nil`),Ru={[ju]:ju,_tag:`Nil`,toString(){return Ht(this.toJSON())},toJSON(){return{_id:`List`,_tag:`Nil`}},[N](){return this.toJSON()},[E](){return Lu},[j](e){return Bu(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return P(this,arguments)}},zu=Object.create(Ru),Bu=e=>w(e,ju),Vu=e=>e._tag===`Nil`,Hu=e=>e._tag===`Cons`,Uu=()=>zu,Wu=(e,t)=>Iu(e,t),Gu=Uu,Ku=e=>Iu(e,zu),qu=x(2,(e,t)=>Yu(t,e)),Ju=x(2,(e,t)=>Wu(t,e)),Yu=x(2,(e,t)=>{if(Vu(e))return t;if(Vu(t))return e;{let n=Iu(t.head,e),r=n,i=t.tail;for(;!Vu(i);){let t=Iu(i.head,e);r.tail=t,r=t,i=i.tail}return n}}),Xu=x(3,(e,t,n)=>{let r=t,i=e;for(;!Vu(i);)r=n(r,i.head),i=i.tail;return r}),Zu=e=>{let t=Gu(),n=e;for(;!Vu(n);)t=Ju(t,n.head),n=n.tail;return t}})),$u,ed=v((()=>{M(),Mt(),On(),Array.prototype,$u=function(){function e(e){e&&Object.assign(this,e)}return e.prototype=wn,e}()}));function td(e){return e}var nd,rd,id,ad,od,sd,cd,ld,ud,dd,fd,pd,md,hd,gd,_d=v((()=>{Ba(),M(),S(),qc(),ed(),nd=Symbol.for(`effect/DifferContextPatch`),rd={...$u.prototype,[nd]:{_Value:td,_Patch:td}},id=Object.create(Object.assign(Object.create(rd),{_tag:`Empty`})),ad=()=>id,od=Object.assign(Object.create(rd),{_tag:`AndThen`}),sd=(e,t)=>{let n=Object.create(od);return n.first=e,n.second=t,n},cd=Object.assign(Object.create(rd),{_tag:`AddService`}),ld=(e,t)=>{let n=Object.create(cd);return n.key=e,n.service=t,n},ud=Object.assign(Object.create(rd),{_tag:`RemoveService`}),dd=e=>{let t=Object.create(ud);return t.key=e,t},fd=Object.assign(Object.create(rd),{_tag:`UpdateService`}),pd=(e,t)=>{let n=Object.create(fd);return n.key=e,n.update=t,n},md=(e,t)=>{let n=new Map(e.unsafeMap),r=ad();for(let[e,i]of t.unsafeMap.entries())if(n.has(e)){let t=n.get(e);n.delete(e),A(t,i)||(r=hd(pd(e,()=>i))(r))}else n.delete(e),r=hd(ld(e,i))(r);for(let[e]of n.entries())r=hd(dd(e))(r);return r},hd=x(2,(e,t)=>sd(e,t)),gd=x(2,(e,t)=>{if(e._tag===`Empty`)return t;let n=!1,r=xa(e),i=new Map(t.unsafeMap);for(;Ia(r);){let e=Ra(r),t=za(r);switch(e._tag){case`Empty`:r=t;break;case`AddService`:i.set(e.key,e.service),r=t;break;case`AndThen`:r=Ma(Ma(t,e.second),e.first);break;case`RemoveService`:i.delete(e.key),r=t;break;case`UpdateService`:i.set(e.key,e.update(i.get(e.key))),n=!0,r=t}}if(!n)return Mc(i);let a=new Map;for(let[e]of t.unsafeMap)i.has(e)&&(a.set(e,i.get(e)),i.delete(e));for(let[e,t]of i)a.set(e,t);return Mc(a)})}));function vd(e){return e}var yd,bd,xd,Sd,Cd,wd,Td,Ed,Dd,Od,kd,Ad,jd,Md=v((()=>{Ba(),S(),Cs(),ed(),yd=Symbol.for(`effect/DifferHashSetPatch`),bd={...$u.prototype,[yd]:{_Value:vd,_Key:vd,_Patch:vd}},xd=Object.create(Object.assign(Object.create(bd),{_tag:`Empty`})),Sd=()=>xd,Cd=Object.assign(Object.create(bd),{_tag:`AndThen`}),wd=(e,t)=>{let n=Object.create(Cd);return n.first=e,n.second=t,n},Td=Object.assign(Object.create(bd),{_tag:`Add`}),Ed=e=>{let t=Object.create(Td);return t.value=e,t},Dd=Object.assign(Object.create(bd),{_tag:`Remove`}),Od=e=>{let t=Object.create(Dd);return t.value=e,t},kd=(e,t)=>{let[n,r]=Ss([e,Sd()],([e,t],n)=>gs(n)(e)?[ys(n)(e),t]:[e,Ad(Ed(n))(t)])(t);return Ss(r,(e,t)=>Ad(Od(t))(e))(n)},Ad=x(2,(e,t)=>wd(e,t)),jd=x(2,(e,t)=>{if(e._tag===`Empty`)return t;let n=t,r=xa(e);for(;Ia(r);){let e=Ra(r),t=za(r);switch(e._tag){case`Empty`:r=t;break;case`AndThen`:r=Ma(e.first)(Ma(e.second)(t));break;case`Add`:n=vs(e.value)(n),r=t;break;case`Remove`:n=ys(e.value)(n),r=t}}return n})}));function Nd(e){return e}var Pd,Fd,Id,Ld,Rd,zd,Bd,Vd,Hd,Ud,Wd,Gd,Kd,qd,Jd,Yd=v((()=>{Pi(),M(),S(),ed(),Pd=Symbol.for(`effect/DifferReadonlyArrayPatch`),Fd={...$u.prototype,[Pd]:{_Value:Nd,_Patch:Nd}},Id=Object.create(Object.assign(Object.create(Fd),{_tag:`Empty`})),Ld=()=>Id,Rd=Object.assign(Object.create(Fd),{_tag:`AndThen`}),zd=(e,t)=>{let n=Object.create(Rd);return n.first=e,n.second=t,n},Bd=Object.assign(Object.create(Fd),{_tag:`Append`}),Vd=e=>{let t=Object.create(Bd);return t.values=e,t},Hd=Object.assign(Object.create(Fd),{_tag:`Slice`}),Ud=(e,t)=>{let n=Object.create(Hd);return n.from=e,n.until=t,n},Wd=Object.assign(Object.create(Fd),{_tag:`Update`}),Gd=(e,t)=>{let n=Object.create(Wd);return n.index=e,n.patch=t,n},Kd=e=>{let t=0,n=Ld();for(;t<e.oldValue.length&&t<e.newValue.length;){let r=e.oldValue[t],i=e.newValue[t],a=e.differ.diff(r,i);A(a,e.differ.empty)||(n=qd(n,Gd(t,a))),t+=1}return t<e.oldValue.length&&(n=qd(n,Ud(0,t))),t<e.newValue.length&&(n=qd(n,Vd(di(t)(e.newValue)))),n},qd=x(2,(e,t)=>zd(e,t)),Jd=x(3,(e,t,n)=>{if(e._tag===`Empty`)return t;let r=t.slice(),i=Ci(e);for(;Qr(i);){let e=ai(i),t=ci(i);switch(e._tag){case`Empty`:i=t;break;case`AndThen`:t.unshift(e.first,e.second),i=t;break;case`Append`:for(let t of e.values)r.push(t);i=t;break;case`Slice`:r=r.slice(e.from,e.until),i=t;break;case`Update`:r[e.index]=n.patch(e.patch,r[e.index]),i=t}}return r})})),Xd,Zd,Qd,$d,ef,tf,nf,rf,af=v((()=>{M(),S(),F(),_d(),Md(),Yd(),Xd=Symbol.for(`effect/Differ`),Zd={[Xd]:{_P:be,_V:be},pipe(){return P(this,arguments)}},Qd=e=>{let t=Object.create(Zd);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},$d=()=>Qd({empty:ad(),combine:(e,t)=>hd(t)(e),diff:(e,t)=>md(e,t),patch:(e,t)=>gd(t)(e)}),ef=()=>Qd({empty:Sd(),combine:(e,t)=>Ad(t)(e),diff:(e,t)=>kd(e,t),patch:(e,t)=>jd(t)(e)}),tf=e=>Qd({empty:Ld(),combine:(e,t)=>qd(e,t),diff:(t,n)=>Kd({oldValue:t,newValue:n,differ:e}),patch:(t,n)=>Jd(t,n,e)}),nf=()=>rf((e,t)=>t),rf=e=>Qd({empty:be,combine:(e,t)=>e===be?t:t===be?e:n=>t(e(n)),diff:(e,t)=>A(e,t)?be:xe(t),patch:(t,n)=>e(n,t(n))})})),of,sf,cf,lf,uf,df,ff,pf,mf,hf,gf,_f=v((()=>{S(),of=255,sf=8,cf=e=>e&of,lf=e=>e>>sf&of,uf=(e,t)=>(e&of)+((t&e&of)<<sf),df=uf(0,0),ff=e=>uf(e,e),pf=e=>uf(e,0),mf=x(2,(e,t)=>uf(cf(e)&~t,lf(e))),hf=x(2,(e,t)=>e|t),gf=e=>~e>>>0&of})),vf,yf,bf,xf,Sf,Cf,wf,Tf,Ef,Df,Of,kf,Af=v((()=>{S(),af(),_f(),vf=e=>Sf(e,32),yf=x(2,(e,t)=>e|t),bf=e=>xf(e)&&!Ef(e),xf=e=>Sf(e,1),Sf=x(2,(e,t)=>(e&t)!==0),Cf=(...e)=>e.reduce((e,t)=>e|t,0),wf=Cf(0),Tf=e=>Sf(e,4),Ef=e=>Sf(e,16),Df=x(2,(e,t)=>uf(e^t,t)),Of=x(2,(e,t)=>e&(gf(cf(t))|lf(t))|cf(t)&lf(t)),kf=Qd({empty:df,diff:(e,t)=>Df(e,t),combine:(e,t)=>hf(t)(e),patch:(e,t)=>Of(t,e)})})),jf,Mf,Nf,Pf=v((()=>{_f(),jf=ff,Mf=pf,Nf=mf})),Ff,If,Lf,Rf,zf,Bf,Vf,Hf,Uf,Wf,Gf,Kf,qf,Jf,Yf,Xf,Zf,Qf,$f,ep,tp,np=v((()=>{Ba(),M(),Au(),Qu(),Rr(),Ff=(e,t)=>({_tag:`Par`,left:e,right:t}),If=(e,t)=>({_tag:`Seq`,left:e,right:t}),Lf=e=>{let t=Ku(e),n=Gu();for(;;){let[e,r]=Xu(t,[Uf(),Gu()],([e,t],n)=>{let[r,i]=Rf(n);return[Gf(e,r),qu(t,i)]});if(n=zf(n,e),Vu(r))return Zu(n);t=r}throw Error(`BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues`)},Rf=e=>{let t=e,n=Uf(),r=Gu(),i=Gu();for(;;)switch(t._tag){case`Empty`:if(Vu(r))return[n,i];t=r.head,r=r.tail;break;case`Par`:r=Wu(t.right,r),t=t.left;break;case`Seq`:{let e=t.left,n=t.right;switch(e._tag){case`Empty`:t=n;break;case`Par`:{let r=e.left,i=e.right;t=Ff(If(r,n),If(i,n));break}case`Seq`:{let r=e.left,i=e.right;t=If(r,If(i,n));break}case`Single`:t=e,i=Wu(n,i)}break}case`Single`:if(n=Wf(n,t),Vu(r))return[n,i];t=r.head,r=r.tail}throw Error(`BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues`)},zf=(e,t)=>{if(Vu(e))return Ku(Jf(t));if(Kf(t))return e;let n=ep(e.head),r=qf(t);return n.length===1&&r.length===1&&A(n[0],r[0])?Wu($f(e.head,Jf(t)),e.tail):Wu(Jf(t),e)},Bf=Symbol.for(`effect/RequestBlock/RequestBlockParallel`),Vf={_R:e=>e},Hf=class{map;[Bf]=Vf;constructor(e){this.map=e}},Uf=()=>new Hf(xu()),Wf=(e,t)=>new Hf(Du(e.map,t.dataSource,e=>Cr(Or(e,ja(t.blockedRequest)),()=>xa(t.blockedRequest)))),Gf=(e,t)=>new Hf(ku(e.map,t.map,(e,t,n)=>Tu(e,n,br(wu(e,n),{onNone:()=>t,onSome:e=>Pa(t,e)})))),Kf=e=>Cu(e.map),qf=e=>Array.from(Eu(e.map)),Jf=e=>Qf(Ou(e.map,e=>xa(e))),Yf=Symbol.for(`effect/RequestBlock/RequestBlockSequential`),Xf={_R:e=>e},Zf=class{map;[Yf]=Xf;constructor(e){this.map=e}},Qf=e=>new Zf(e),$f=(e,t)=>new Zf(ku(t.map,e.map,(e,t,n)=>Tu(e,n,br(wu(e,n),{onNone:()=>ya(),onSome:e=>Pa(e,t)})))),ep=e=>Array.from(Eu(e.map)),tp=e=>Array.from(e.map)})),rp,ip,ap=v((()=>{rp=`Pending`,ip=`Done`})),op,sp,cp,lp,up,dp=v((()=>{ap(),op=`effect/Deferred`,sp=Symbol.for(op),cp={_E:e=>e,_A:e=>e},lp=e=>({_tag:rp,joiners:e}),up=e=>({_tag:ip,effect:e})})),fp,pp=v((()=>{fp=class e{self;called=!1;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}return(e){return{value:e,done:!0}}throw(e){throw e}[Symbol.iterator](){return new e(this.self)}}})),mp,hp,gp,_p,vp,yp,bp,xp,Sp,Cp,wp,Tp,Ep,Dp,Op,kp,Ap,jp,Mp,Np,Pp,Fp,Ip,Lp,Rp,zp,Bp,Vp,Hp,B,Up,Wp,Gp,Kp,qp,Jp,Yp,Xp,Zp,Qp,$p,em,tm,nm,rm,V,im,am,om,sm,cm,lm,um,dm,fm,pm,mm,hm,gm,_m,vm,ym,bm,xm,Sm,Cm,wm,Tm,Em,Dm,Om,km,Am,jm,Mm,Nm,Pm,Fm,Im,Lm,Rm,zm,Bm,Vm,Hm,Um,Wm,Gm,Km,qm,Jm,Ym,Xm,Zm,Qm,$m,eh,th,nh,rh,ih,ah,oh,sh,ch,lh,uh,dh,fh,ph,mh,hh,gh,_h,vh,yh,bh,xh,Sh,Ch,wh,Th,Eh,Dh,Oh,kh,Ah,jh,Mh,Nh,Ph,Fh,Ih,Lh,Rh,zh,Bh,Vh=v((()=>{Pi(),Ba(),il(),lr(),M(),bu(),S(),Ie(),Mt(),Au(),Xt(),Qu(),Yl(),Rr(),F(),T(),Pf(),St(),bc(),dp(),af(),On(),rt(),ap(),fn(),Af(),pp(),mp=(e,t)=>{let n=new vp(`Blocked`);return n.effect_instruction_i0=e,n.effect_instruction_i1=t,n},hp=e=>{let t=new vp(`RunBlocked`);return t.effect_instruction_i0=e,t},gp=Symbol.for(`effect/Effect`),_p=class{patch;op;_op=dn;constructor(e,t){this.patch=e,this.op=t}},vp=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[gp]=bn;constructor(e){this._op=e}[j](e){return this===e}[E](){return k(this,wt(this))}pipe(){return P(this,arguments)}toJSON(){return{_id:`Effect`,_op:this._op,effect_instruction_i0:Bt(this.effect_instruction_i0),effect_instruction_i1:Bt(this.effect_instruction_i1),effect_instruction_i2:Bt(this.effect_instruction_i2)}}toString(){return Ht(this.toJSON())}[N](){return this.toJSON()}[Symbol.iterator](){return new fp(new gt(this))}},yp=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[gp]=bn;constructor(e){this._op=e,this._tag=e}[j](e){return gh(e)&&e._op===`Failure`&&A(this.effect_instruction_i0,e.effect_instruction_i0)}[E](){return b(Ot(this._tag),O(D(this.effect_instruction_i0)),k(this))}get cause(){return this.effect_instruction_i0}pipe(){return P(this,arguments)}toJSON(){return{_id:`Exit`,_tag:this._op,cause:this.cause.toJSON()}}toString(){return Ht(this.toJSON())}[N](){return this.toJSON()}[Symbol.iterator](){return new fp(new gt(this))}},bp=class{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[gp]=bn;constructor(e){this._op=e,this._tag=e}[j](e){return gh(e)&&e._op===`Success`&&A(this.effect_instruction_i0,e.effect_instruction_i0)}[E](){return b(Ot(this._tag),O(D(this.effect_instruction_i0)),k(this))}get value(){return this.effect_instruction_i0}pipe(){return P(this,arguments)}toJSON(){return{_id:`Exit`,_tag:this._op,value:Bt(this.value)}}toString(){return Ht(this.toJSON())}[N](){return this.toJSON()}[Symbol.iterator](){return new fp(new gt(this))}},xp=e=>w(e,gp),Sp=e=>{let t=new vp(ln);return t.effect_instruction_i0=e,t},Cp=x(3,(e,t,n)=>sm(r=>B(e,e=>B(Ip(rm(()=>r(t(e)))),t=>rm(()=>n(e,t)).pipe(Kp({onFailure:e=>{switch(t._tag){case $t:return zp(zs(t.effect_instruction_i0,e));case rn:return zp(e)}},onSuccess:()=>t})))))),wp=x(2,(e,t)=>B(e,()=>nm(t))),Tp=e=>wp(e,void 0),Ep=function(){let e=new vp(Qt);switch(arguments.length){case 2:e.effect_instruction_i0=arguments[0],e.commit=arguments[1];break;case 3:e.effect_instruction_i0=arguments[0],e.effect_instruction_i1=arguments[1],e.commit=arguments[2];break;case 4:e.effect_instruction_i0=arguments[0],e.effect_instruction_i1=arguments[1],e.effect_instruction_i2=arguments[2],e.commit=arguments[3];break;default:throw Error(nt(`you're not supposed to end up here`))}return e},Dp=(e,t=mu)=>{let n=new vp(Zt),r;return n.effect_instruction_i0=t=>{r=e(t)},n.effect_instruction_i1=t,tm(n,e=>xp(r)?r:cm)},Op=(e,t=mu)=>rm(()=>Dp(e,t)),kp=(e,t=mu)=>Ep(e,function(){let e,n;function r(t){e?e(t):n===void 0&&(n=t)}let i=new vp(Zt);i.effect_instruction_i0=t=>{e=t,n&&t(n)},i.effect_instruction_i1=t;let a,o;return this.effect_instruction_i0.length===1?a=xt(()=>this.effect_instruction_i0(r)):(o=new AbortController,a=xt(()=>this.effect_instruction_i0(r,o.signal))),a||o?tm(i,e=>(o&&o.abort(),a??cm)):i}),Ap=x(2,(e,t)=>qp(e,{onFailure:t,onSuccess:nm})),jp=Symbol.for(`effect/OriginalAnnotation`),Mp=(e,t)=>yr(t)?new Proxy(e,{has(e,t){return t===vc||t===jp||t in e},get(n,r){return r===vc?t.value:r===jp?e:n[r]}}):e,Np=e=>qe(e)&&!(vc in e)?Sp(t=>zp(Is(Mp(e,Bh(t))))):zp(Is(e)),Pp=e=>Bp(()=>Is(new sh(e))),Fp=e=>qp(e,{onFailure:e=>nm(L(e)),onSuccess:e=>nm(I(e))}),Ip=e=>Gp(e,{onFailure:Ch,onSuccess:Dh}),Lp=e=>qe(e)&&!(vc in e)?Sp(t=>zp(Fs(Mp(e,Bh(t))))):zp(Fs(e)),Rp=e=>B(V(e),Lp),zp=e=>{let t=new yp($t);return t.effect_instruction_i0=e,t},Bp=e=>B(V(e),zp),Vp=Sp(e=>nm(e.id())),Hp=e=>Sp(t=>e(t.id())),B=x(2,(e,t)=>{let n=new vp(tn);return n.effect_instruction_i0=e,n.effect_instruction_i1=t,n}),Up=e=>{let t=new vp(`OnStep`);return t.effect_instruction_i0=e,t},Wp=e=>B(e,be),Gp=x(2,(e,t)=>Kp(e,{onFailure:e=>nm(t.onFailure(e)),onSuccess:e=>nm(t.onSuccess(e))})),Kp=x(2,(e,t)=>{let n=new vp(nn);return n.effect_instruction_i0=e,n.effect_instruction_i1=t.onFailure,n.effect_instruction_i2=t.onSuccess,n}),qp=x(2,(e,t)=>Kp(e,{onFailure:e=>{if(qs(e).length>0)return zp($s(e));let n=Ks(e);return n.length>0?t.onFailure(La(n)):zp(e)},onSuccess:t.onSuccess})),Jp=x(2,(e,t)=>rm(()=>{let n=Ur(e),r=Vr(n.length),i=0;return wp(um({while:()=>i<n.length,body:()=>t(n[i],i),step:e=>{r[i++]=e}}),r)})),Yp=x(2,(e,t)=>rm(()=>{let n=Ur(e),r=0;return um({while:()=>r<n.length,body:()=>t(n[r],r),step:()=>{r++}})})),Xp=e=>{let t=new vp(on);return t.effect_instruction_i0=jf(1),t.effect_instruction_i1=()=>e,t},Zp=x(2,(e,t)=>B(e,e=>V(()=>t(e)))),Qp=x(2,(e,t)=>qp(e,{onFailure:e=>Rp(()=>t.onFailure(e)),onSuccess:e=>V(()=>t.onSuccess(e))})),$p=x(2,(e,t)=>Kp(e,{onFailure:e=>{let n=Xs(e);switch(n._tag){case`Left`:return Rp(()=>t(n.left));case`Right`:return zp(n.right)}},onSuccess:nm})),em=x(2,(e,t)=>sm(n=>Kp(n(e),{onFailure:e=>{let n=Ch(e);return Kp(t(n),{onFailure:t=>Ch(zs(e,t)),onSuccess:()=>n})},onSuccess:e=>{let n=Dh(e);return mm(t(n),n)}}))),tm=x(2,(e,t)=>em(e,Eh({onFailure:e=>Gs(e)?Tp(t(Js(e))):cm,onSuccess:()=>cm}))),nm=e=>{let t=new bp(rn);return t.effect_instruction_i0=e,t},rm=e=>{let t=new vp(Qt);return t.commit=e,t},V=e=>{let t=new vp(an);return t.effect_instruction_i0=e,t},im=x(e=>e.length===3||e.length===2&&!(qe(e[1])&&`onlyEffect`in e[1]),(e,t)=>B(e,e=>{let n=typeof t==`function`?t(e):t;return xp(n)?wp(n,e):tt(n)?Dp(t=>{n.then(n=>t(nm(e)),e=>t(Lp(new hh(e,`An unknown error occurred in Effect.tap`))))}):nm(e)})),am=e=>Sp(t=>{let n=b(t.getFiberRef(Zm),xr(()=>t.scope()));return e(Mm(Zm,z(n)))}),om=e=>{let t=new vp(on);return t.effect_instruction_i0=Mf(1),t.effect_instruction_i1=()=>e,t},sm=e=>Ep(e,function(){let e=new vp(on);return e.effect_instruction_i0=Mf(1),e.effect_instruction_i1=e=>xf(e)?xt(()=>this.effect_instruction_i0(Xp)):xt(()=>this.effect_instruction_i0(om)),e}),cm=nm(void 0),lm=e=>{let t=new vp(on);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t},um=e=>{let t=new vp(sn);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t},dm=e=>{let t=new vp(un);return e?.priority===void 0?t:Gm(t,e.priority)},fm=x(2,(e,t)=>B(e,e=>Zp(t,t=>[e,t]))),pm=x(2,(e,t)=>B(e,e=>wp(t,e))),mm=x(2,(e,t)=>B(e,()=>t)),hm=e=>B(Vp,t=>b(e,gm(t))),gm=x(2,(e,t)=>B(e.interruptAsFork(t),()=>e.await)),_m={_tag:`All`,syslog:0,label:`ALL`,ordinal:-(2**53-1),pipe(){return P(this,arguments)}},vm={_tag:`Fatal`,syslog:2,label:`FATAL`,ordinal:5e4,pipe(){return P(this,arguments)}},ym={_tag:`Error`,syslog:3,label:`ERROR`,ordinal:4e4,pipe(){return P(this,arguments)}},bm={_tag:`Warning`,syslog:4,label:`WARN`,ordinal:3e4,pipe(){return P(this,arguments)}},xm={_tag:`Info`,syslog:6,label:`INFO`,ordinal:2e4,pipe(){return P(this,arguments)}},Sm={_tag:`Debug`,syslog:7,label:`DEBUG`,ordinal:1e4,pipe(){return P(this,arguments)}},Cm={_tag:`Trace`,syslog:7,label:`TRACE`,ordinal:0,pipe(){return P(this,arguments)}},wm={_tag:`None`,syslog:7,label:`OFF`,ordinal:2**53-1,pipe(){return P(this,arguments)}},Tm=`effect/FiberRef`,Em=Symbol.for(Tm),Dm={_A:e=>e},Om=e=>Sp(t=>Dh(t.getFiberRef(e))),km=x(2,(e,t)=>B(Om(e),t)),Am=x(2,(e,t)=>jm(e,()=>[void 0,t])),jm=x(2,(e,t)=>Sp(n=>{let[r,i]=t(n.getFiberRef(e));return n.setFiberRef(e,i),nm(r)})),Mm=x(3,(e,t,n)=>Cp(pm(Om(t),Am(t,n)),()=>e,e=>Am(t,e))),Nm=(e,t)=>Lm(e,{differ:nf(),fork:t?.fork??be,join:t?.join}),Pm=e=>{let t=ef();return Lm(e,{differ:t,fork:t.empty})},Fm=e=>{let t=tf(nf());return Lm(e,{differ:t,fork:t.empty})},Im=e=>{let t=$d();return Lm(e,{differ:t,fork:t.empty})},Lm=(e,t)=>({...Tn,[Em]:Dm,initial:e,commit(){return Om(this)},diff:(e,n)=>t.differ.diff(e,n),combine:(e,n)=>t.differ.combine(e,n),patch:e=>n=>t.differ.patch(e,n),fork:t.fork,join:t.join??((e,t)=>t)}),Rm=e=>Lm(e,{differ:kf,fork:kf.empty}),zm=C(Symbol.for(`effect/FiberRef/currentContext`),()=>Im(Yc())),Bm=C(Symbol.for(`effect/FiberRef/currentSchedulingPriority`),()=>Nm(0)),Vm=C(Symbol.for(`effect/FiberRef/currentMaxOpsBeforeYield`),()=>Nm(2048)),Hm=C(Symbol.for(`effect/FiberRef/currentLogAnnotation`),()=>Nm(xu())),Um=C(Symbol.for(`effect/FiberRef/currentLogLevel`),()=>Nm(xm)),Wm=C(Symbol.for(`effect/FiberRef/currentLogSpan`),()=>Nm(Gu())),Gm=x(2,(e,t)=>Mm(e,Bm,t)),Km=C(Symbol.for(`effect/FiberRef/currentConcurrency`),()=>Nm(`unbounded`)),qm=C(Symbol.for(`effect/FiberRef/currentRequestBatching`),()=>Nm(!0)),Jm=C(Symbol.for(`effect/FiberRef/currentUnhandledErrorLogLevel`),()=>Nm(z(Sm))),Ym=C(Symbol.for(`effect/FiberRef/versionMismatchErrorLogLevel`),()=>Nm(z(bm))),Xm=C(Symbol.for(`effect/FiberRef/currentMetricLabels`),()=>Fm(Si())),Zm=C(Symbol.for(`effect/FiberRef/currentForkScopeOverride`),()=>Nm(R(),{fork:()=>R(),join:(e,t)=>e})),Qm=C(Symbol.for(`effect/FiberRef/currentInterruptedCause`),()=>Nm(Ps,{fork:()=>Ps,join:(e,t)=>e})),$m=Symbol.for(`effect/Scope`),eh=Symbol.for(`effect/CloseableScope`),th=(e,t)=>e.addFinalizer(()=>Tp(t)),nh=(e,t)=>e.close(t),rh=(e,t)=>e.fork(t),ih=function(){class e extends globalThis.Error{commit(){return Lp(this)}toJSON(){let e={...this};return this.message&&(e.message=this.message),this.cause&&(e.cause=this.cause),e}[N](){return this.toString===globalThis.Error.prototype.toString?`Bun`in globalThis?dc(Fs(this),{renderErrorCause:!0}):this:this.stack?`${this.toString()}\n${this.stack.split(`
13
13
  `).slice(1).join(`
14
- `)}`:this.toString()}}return Object.assign(e.prototype,tn),e}(),Op=(e,t)=>{class n extends Dp{_tag=t}return Object.assign(n.prototype,e),n.prototype.name=t,n},kp=Symbol.for(`effect/Cause/errors/RuntimeException`),Ap=Op({[kp]:kp},`RuntimeException`),jp=Symbol.for(`effect/Cause/errors/InterruptedException`),Mp=e=>S(e,jp),Np=Symbol.for(`effect/Cause/errors/IllegalArgument`),Pp=Op({[Np]:Np},`IllegalArgumentException`),Fp=Symbol.for(`effect/Cause/errors/NoSuchElement`),Ip=Op({[Fp]:Fp},`NoSuchElementException`),Lp=Symbol.for(`effect/Cause/errors/UnknownException`),Rp=function(){class e extends Dp{_tag=`UnknownException`;error;constructor(e,t){super(t??`An unknown error occurred`,{cause:e}),this.error=e}}return Object.assign(e.prototype,{[Lp]:Lp,name:`UnknownException`}),e}(),zp=e=>Wd(e)&&`_tag`in e&&(e._tag===`Success`||e._tag===`Failure`),Bp=e=>e._tag===`Success`,Vp=v(2,(e,t)=>{switch(e._tag){case Mt:return R(e.effect_instruction_i0);case It:return Yp(t)}}),Hp=e=>Vp(e,void 0),Up=(e,t)=>Qp(e,t?.parallel?Io:Lo),Wp=e=>R(Po(e)),Gp=e=>R(No(e)),R=e=>{let t=new Hd(Mt);return t.effect_instruction_i0=e,t},Kp=e=>R(Fo(e)),qp=v(2,(e,t)=>{switch(e._tag){case Mt:return R(e.effect_instruction_i0);case It:return Yp(t(e.effect_instruction_i0))}}),Jp=v(2,(e,{onFailure:t,onSuccess:n})=>{switch(e._tag){case Mt:return t(e.effect_instruction_i0);case It:return n(e.effect_instruction_i0)}}),Yp=e=>{let t=new Ud(It);return t.effect_instruction_i0=e,t},Xp=Yp(void 0),Zp=v(3,(e,t,{onFailure:n,onSuccess:r})=>{switch(e._tag){case Mt:switch(t._tag){case It:return R(e.effect_instruction_i0);case Mt:return R(n(e.effect_instruction_i0,t.effect_instruction_i0))}case It:switch(t._tag){case It:return Yp(r(e.effect_instruction_i0,t.effect_instruction_i0));case Mt:return R(t.effect_instruction_i0)}}}),Qp=(e,t)=>{let n=Ii(e);return Ji(n)?b(Zi(n),qr(b(Xi(n),qp(Fi)),(e,n)=>b(e,Zp(n,{onSuccess:(e,t)=>b(e,Wi(t)),onFailure:t}))),qp(zi),qp(e=>Ri(e)),F):P()},$p=e=>({...en,[Md]:Nd,state:zc(Pd([])),commit(){return em(this)},blockingOn:e}),em=e=>Zd(t=>{let n=Bc(e.state);switch(n._tag){case jd:return t(n.effect);case Ad:return n.joiners.push(t),nm(e,t)}},e.blockingOn),tm=(e,t)=>{let n=Bc(e.state);if(n._tag===`Pending`){Vc(e.state,Fd(t));for(let e=0,r=n.joiners.length;e<r;e++)n.joiners[e](t)}},nm=(e,t)=>L(()=>{let n=Bc(e.state);if(n._tag===`Pending`){let e=n.joiners.indexOf(t);e>=0&&n.joiners.splice(e,1)}}),rm=Gd(e=>Yp(e.currentContext)),im=()=>rm,am=e=>I(im(),e),om=v(2,(e,t)=>tp(cp,t)(e)),sm=v(2,(e,t)=>am(n=>om(e,t(n)))),cm=e=>{let t=e.currentSpan;return t!==void 0&&t._tag===`Span`?F(t):P()},lm=Bo,um=Pp,dm=ls,fm=`InvalidData`,pm=`MissingData`,mm=`SourceUnavailable`,hm=`Unsupported`,gm=Symbol.for(`effect/ConfigError`),_m={_tag:`ConfigError`,[gm]:gm},vm=(e,t)=>{let n=Object.create(_m);return n._op=`And`,n.left=e,n.right=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`${this.left} and ${this.right}`}}),Object.defineProperty(n,"message",{enumerable:!1,get(){return this.toString()}}),n},ym=(e,t)=>{let n=Object.create(_m);return n._op=`Or`,n.left=e,n.right=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`${this.left} or ${this.right}`}}),Object.defineProperty(n,"message",{enumerable:!1,get(){return this.toString()}}),n},bm=(e,t,n={pathDelim:`.`})=>{let r=Object.create(_m);return r._op=fm,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Invalid data at ${b(this.path,Qr(n.pathDelim))}: "${this.message}")`}}),r},xm=(e,t,n={pathDelim:`.`})=>{let r=Object.create(_m);return r._op=pm,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Missing data at ${b(this.path,Qr(n.pathDelim))}: "${this.message}")`}}),r},Sm=(e,t,n,r={pathDelim:`.`})=>{let i=Object.create(_m);return i._op=mm,i.path=e,i.message=t,i.cause=n,Object.defineProperty(i,"toString",{enumerable:!1,value(){return`(Source unavailable at ${b(this.path,Qr(r.pathDelim))}: "${this.message}")`}}),i},Cm=(e,t,n={pathDelim:`.`})=>{let r=Object.create(_m);return r._op=hm,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${b(this.path,Qr(n.pathDelim))}: "${this.message}")`}}),r},wm=v(2,(e,t)=>{switch(e._op){case`And`:return vm(wm(e.left,t),wm(e.right,t));case`Or`:return ym(wm(e.left,t),wm(e.right,t));case fm:return bm([...t,...e.path],e.message);case pm:return xm([...t,...e.path],e.message);case mm:return Sm([...t,...e.path],e.message,e.cause);case hm:return Cm([...t,...e.path],e.message)}}),Tm=v(3,(e,t,n)=>{let r=[e],i=[];for(;r.length>0;){let e=r.pop();switch(e._op){case`And`:r.push(e.right),r.push(e.left),i.push(N({_op:`AndCase`}));break;case`Or`:r.push(e.right),r.push(e.left),i.push(N({_op:`OrCase`}));break;case fm:i.push(M(n.invalidDataCase(t,e.path,e.message)));break;case pm:i.push(M(n.missingDataCase(t,e.path,e.message)));break;case mm:i.push(M(n.sourceUnavailableCase(t,e.path,e.message,e.cause)));break;case hm:i.push(M(n.unsupportedCase(t,e.path,e.message)))}}let a=[];for(;i.length>0;){let e=i.pop();switch(e._op){case`Left`:switch(e.left._op){case`AndCase`:{let e=a.pop(),r=a.pop(),i=n.andCase(t,e,r);a.push(i);break}case`OrCase`:{let e=a.pop(),r=a.pop(),i=n.orCase(t,e,r);a.push(i);break}}break;case`Right`:a.push(e.right)}}if(a.length===0)throw Error(`BUG: ConfigError.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues`);return a.pop()}),Em=Symbol.for(`effect/Clock`),Dm=Us(`effect/Clock`),Om=2**31-1,km={unsafeSchedule(e,t){let n=Tc(t);if(n>Om)return ye;let r=!1,i=setTimeout(()=>{r=!0,e()},n);return()=>(clearTimeout(i),!r)}},Am=function(){let e=BigInt(1e6);if(typeof performance>`u`||typeof performance.now!=`function`)return()=>BigInt(Date.now())*e;let t;return()=>(t===void 0&&(t=BigInt(Date.now())*e-BigInt(Math.round(performance.now()*1e6))),t+BigInt(Math.round(performance.now()*1e6)))}(),jm=function(){let e=typeof process==`object`&&`hrtime`in process&&typeof process.hrtime.bigint==`function`?process.hrtime:void 0;if(!e)return Am;let t=Am()-e.bigint();return()=>t+e.bigint()}();var Mm=class{[Em]=Em;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return jm()}currentTimeMillis=L(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=L(()=>this.unsafeCurrentTimeNanos());scheduler(){return Ef(km)}sleep(e){return Qd(t=>{let n=km.unsafeSchedule(()=>t(Mf),e);return Jd(L(n))})}};const Nm=()=>new Mm,Pm=Rn,Fm=e=>{if(e===`NaN`)return pn(NaN);if(e===`Infinity`)return pn(1/0);if(e===`-Infinity`)return pn(-1/0);if(e.trim()===``)return fn;let t=Number(e);return Number.isNaN(t)?fn:pn(t)},Im=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`),Lm={_tag:`Empty`},Rm=v(2,(e,t)=>{let n=Nl(t),r=e;for(;kl(n);){let e=n.head;switch(e._tag){case`Empty`:n=n.tail;break;case`AndThen`:n=jl(e.first,jl(e.second,n.tail));break;case`MapName`:r=Ur(r,e.f),n=n.tail;break;case`Nested`:r=fr(r,e.name),n=n.tail;break;case`Unnested`:if(b(Cr(r),ir(e.name)))r=Dr(r),n=n.tail;else return N(xm(r,`Expected ${e.name} to be in path in ConfigProvider#unnested`))}}return M(r)}),zm=(e,t)=>[...e,...t],Bm=Symbol.for(`effect/ConfigProvider`),Vm=Us(`effect/ConfigProvider`),Hm=Symbol.for(`effect/ConfigProviderFlat`),Um=e=>({[Bm]:Bm,pipe(){return j(this,arguments)},...e}),Wm=e=>({[Hm]:Hm,patch:e.patch,load:(t,n,r=!0)=>e.load(t,n,r),enumerateChildren:e.enumerateChildren}),Gm=e=>Um({load:t=>I(Zm(e,Vr(),t,!1),e=>Wn(Cr(e),{onNone:()=>sf(xm(Vr(),`Expected a single value having structure: ${t}`)),onSome:Ef})),flattened:e}),Km=e=>{let{pathDelim:t,seqDelim:n}=Object.assign({},{pathDelim:`_`,seqDelim:`,`},e),r=e=>b(e,Qr(t)),i=e=>e.split(t),a=()=>typeof process<`u`&&`env`in process&&typeof process.env==`object`?process.env:{};return Gm(Wm({load:(e,t,i=!0)=>{let o=r(e),s=a();return b(o in s?F(s[o]):P(),Cf(()=>xm(e,`Expected ${o} to exist in the process context`)),I(r=>eh(r,e,t,n,i)))},enumerateChildren:e=>L(()=>{let t=a(),n=Object.keys(t).map(e=>i(e.toUpperCase())).filter(t=>{for(let n=0;n<e.length;n++){let r=b(e,Sr(n)),i=t[n];if(i===void 0||r!==i)return!1}return!0}).flatMap(t=>t.slice(e.length,e.length+1));return mo(n)}),patch:Lm}))},qm=(e,t,n,r)=>{let i=Jr(n.length,t=>t>=r.length?P():F([e(t),t+1])),a=Jr(r.length,e=>e>=n.length?P():F([t(e),e+1]));return[zm(n,i),zm(r,a)]},Jm=(e,t)=>{let n=t;if(n._tag===`Nested`){let t=e.slice();for(;n._tag===`Nested`;)t.push(n.name),n=n.config;return t}return e},Ym={andCase:(e,t,n)=>vm(t,n),orCase:(e,t,n)=>ym(t,n),invalidDataCase:(e,t)=>bm(t,`<redacted>`),missingDataCase:(e,t)=>xm(t,`<redacted>`),sourceUnavailableCase:(e,t,n,r)=>Sm(t,`<redacted>`,r),unsupportedCase:(e,t)=>Cm(t,`<redacted>`)},Xm=e=>Tm(e,void 0,Ym),Zm=(e,t,n,r)=>{let i=n;switch(i._tag){case`Constant`:return Ef(Hr(i.value));case`Described`:return Df(()=>Zm(e,t,i.config,r));case`Fail`:return sf(xm(t,i.message));case`Fallback`:return b(Df(()=>Zm(e,t,i.first,r)),$d(n=>i.condition(n)?b(Zm(e,t,i.second,r),$d(e=>sf(ym(n,e)))):sf(n)));case`Lazy`:return Df(()=>Zm(e,t,i.config(),r));case`MapOrFail`:return Df(()=>b(Zm(e,t,i.original,r),I(vf(e=>b(i.mapOrFail(e),Cf(wm(Jm(t,i.original))))))));case`Nested`:return Df(()=>Zm(e,zm(t,Hr(i.name)),i.config,r));case`Primitive`:return b(Rm(t,e.patch),I(t=>b(e.load(t,i,r),I(e=>{if(e.length===0){let e=b(Tr(t),Gn(()=>`<n/a>`));return sf(xm([],`Expected ${i.description} with name ${e}`))}return Ef(e)}))));case`Redacted`:return Df(()=>b(Zm(e,t,i.original,r),Cf(Xm),xf(Ur(i.redact))));case`Sequence`:return b(Rm(t,e.patch),I(n=>b(e.enumerateChildren(n),I(nh),I(n=>n.length===0?Df(()=>xf(Zm(e,t,i.config,!0),Hr)):b(vf(n,n=>Zm(e,pr(t,`[${n}]`),i.config,!0)),xf(e=>{let t=Gr(e);return t.length===0?Hr(Vr()):Hr(t)}))))));case`HashMap`:return Df(()=>b(Rm(t,e.patch),I(t=>b(e.enumerateChildren(t),I(n=>b(n,vf(n=>Zm(e,zm(t,Hr(n)),i.valueConfig,r)),xf(e=>e.length===0?Hr(dl()):b(th(e),Ur(e=>fl(Nr(lr(n),e)))))))))));case`ZipWith`:return Df(()=>b(Zm(e,t,i.left,r),af,I(n=>b(Zm(e,t,i.right,r),af,I(e=>{if(Dn(n)&&Dn(e))return sf(vm(n.left,e.left));if(Dn(n)&&On(e))return sf(n.left);if(On(n)&&Dn(e))return sf(e.left);if(On(n)&&On(e)){let r=b(t,Qr(`.`)),a=Qm(t,r),[o,s]=qm(a,a,b(n.right,Ur(M)),b(e.right,Ur(M)));return b(o,Nr(s),vf(([e,t])=>b(If(e,t),xf(([e,t])=>i.zip(e,t)))))}throw Error(`BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues`)})))))}},Qm=(e,t)=>n=>N(xm(e,`The element at index ${n} in a sequence at path "${t}" was missing`)),$m=(e,t)=>e.split(RegExp(`\\s*${Im(t)}\\s*`)),eh=(e,t,n,r,i)=>i?b($m(e,r),vf(e=>n.parse(e.trim())),Cf(wm(t))):b(n.parse(e),Sf({onFailure:wm(t),onSuccess:Hr})),th=e=>Object.keys(e[0]).map(t=>e.map(e=>e[t])),nh=e=>b(vf(e,ih),Sf({onFailure:()=>Vr(),onSuccess:Mr(Pm)}),af,xf(Nn)),rh=/^(\[(\d+)\])$/,ih=e=>{let t=e.match(rh);if(t!==null){let e=t[2];return b(e!==void 0&&e.length>0?F(e):P(),$n(ah))}return P()},ah=e=>{let t=Number.parseInt(e);return Number.isNaN(t)?P():F(t)},oh=Symbol.for(`effect/Console`),sh=Us(`effect/Console`),ch={[oh]:oh,assert(e,...t){return L(()=>{console.assert(e,...t)})},clear:L(()=>{console.clear()}),count(e){return L(()=>{console.count(e)})},countReset(e){return L(()=>{console.countReset(e)})},debug(...e){return L(()=>{console.debug(...e)})},dir(e,t){return L(()=>{console.dir(e,t)})},dirxml(...e){return L(()=>{console.dirxml(...e)})},error(...e){return L(()=>{console.error(...e)})},group(e){return e?.collapsed?L(()=>console.groupCollapsed(e?.label)):L(()=>console.group(e?.label))},groupEnd:L(()=>{console.groupEnd()}),info(...e){return L(()=>{console.info(...e)})},log(...e){return L(()=>{console.log(...e)})},table(e,t){return L(()=>{console.table(e,t)})},time(e){return L(()=>console.time(e))},timeEnd(e){return L(()=>console.timeEnd(e))},timeLog(e,...t){return L(()=>{console.timeLog(e,...t)})},trace(...e){return L(()=>{console.trace(...e)})},warn(...e){return L(()=>{console.warn(...e)})},unsafe:console},lh=Symbol.for(`effect/Random`),uh=Us(`effect/Random`);var dh=class{seed;[lh]=lh;PRNG;constructor(e){this.seed=e,this.PRNG=new Xe(e)}get next(){return L(()=>this.PRNG.number())}get nextBoolean(){return xf(this.next,e=>e>.5)}get nextInt(){return L(()=>this.PRNG.integer(2**53-1))}nextRange(e,t){return xf(this.next,n=>(t-e)*n+e)}nextIntBetween(e,t){return L(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return fh(e,e=>this.nextIntBetween(0,e))}};const fh=(e,t)=>Df(()=>b(L(()=>Array.from(e)),I(e=>{let n=[];for(let t=e.length;t>=2;--t)n.push(t);return b(n,yf(n=>b(t(n),xf(t=>ph(e,n-1,t)))),qd(Ii(e)))}))),ph=(e,t,n)=>{let r=e[t];return e[t]=e[n],e[n]=r,e},mh=e=>new dh(w(e)),hh=Symbol.for(`effect/Tracer`),gh=e=>({[hh]:hh,...e}),_h=Us(`effect/Tracer`),vh=Us(`effect/ParentSpan`),yh=function(){return function(e){let t=``;for(let n=0;n<e;n++)t+=`abcdef0123456789`.charAt(Math.floor(Math.random()*16));return t}}();var bh=class{name;parent;context;startTime;kind;_tag=`Span`;spanId;traceId=`native`;sampled=!0;status;attributes;events=[];links;constructor(e,t,n,r,i,a){this.name=e,this.parent=t,this.context=n,this.startTime=i,this.kind=a,this.status={_tag:`Started`,startTime:i},this.attributes=new Map,this.traceId=t._tag===`Some`?t.value.traceId:yh(32),this.spanId=yh(16),this.links=Array.from(r)}end(e,t){this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime}}attribute(e,t){this.attributes.set(e,t)}event(e,t,n){this.events.push([e,t,n??{}])}addLinks(e){this.links.push(...e)}};const xh=gh({span:(e,t,n,r,i,a)=>new bh(e,t,n,r,i,a),context:e=>e()}),Sh=Qs()(`effect/Tracer/DisablePropagation`,{defaultValue:ye}),Ch=b(Ws(),Ks(Dm,Nm()),Ks(sh,ch),Ks(uh,mh(Math.random())),Ks(Vm,Km()),Ks(_h,xh)),wh=x(Symbol.for(`effect/DefaultServices/currentServices`),()=>ap(Ch)),Th=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return{BaseEffectError:class extends Dp{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Object.assign(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}.BaseEffectError}(),Eh=e=>{let t={BaseEffectError:class extends Th{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError},Dh=Qt,Oh=nn;var kh=class extends Oh{};const Ah=`Sequential`,jh=`Parallel`,Mh={_tag:Ah},Nh={_tag:jh},Ph=e=>({_tag:`ParallelN`,parallelism:e}),Fh=e=>e._tag===Ah,Ih=e=>e._tag===jh,Lh=Mh,Rh=Nh,zh=Ph;function Bh(e){return new Uh(e)}function Vh(){return Bh(new Map)}const Hh=Symbol.for(`effect/FiberRefs`);var Uh=class{locals;[Hh]=Hh;constructor(e){this.locals=e}pipe(){return j(this,arguments)}};const Wh=(e,t,n,r=!1)=>{let i=e,a=t,o=n,s=r,c;for(;c===void 0;)if(vr(a)&&vr(o)){let e=wr(a)[0],t=Dr(a),n=wr(o)[0],r=wr(o)[1],i=Dr(o);e.startTimeMillis<n.startTimeMillis?(o=i,s=!0):e.startTimeMillis>n.startTimeMillis?a=t:e.id<n.id?(o=i,s=!0):e.id>n.id?a=t:c=[r,s]}else c=[i.initial,!0];return c},Gh=v(3,(e,t,n)=>{let r=new Map(e.locals);return n.locals.forEach((e,n)=>{let i=e[0][1];if(!e[0][0][O](t)){if(!r.has(n)){if(k(i,n.initial))return;r.set(n,[[t,n.join(n.initial,i)]]);return}let a=r.get(n),[o,s]=Wh(n,a,e);if(s){let e=n.diff(o,i),s=a[0][1],c=n.join(s,n.patch(e)(s));if(!k(s,c)){let e,i=a[0][0];e=i[O](t)?[[i,c],...a.slice(1)]:[[t,c],...a],r.set(n,e)}}}}),new Uh(r)}),Kh=v(2,(e,t)=>{let n=new Map;return qh(e,n,t),new Uh(n)}),qh=(e,t,n)=>{e.locals.forEach((e,r)=>{let i=e[0][1],a=r.patch(r.fork)(i);k(i,a)?t.set(r,e):t.set(r,[[n,a],...e])})},Jh=v(2,(e,t)=>{let n=new Map(e.locals);return n.delete(t),new Uh(n)}),Yh=v(2,(e,t)=>e.locals.has(t)?F(wr(e.locals.get(t))[1]):P()),Xh=v(2,(e,t)=>b(Yh(e,t),Gn(()=>t.initial))),Zh=v(2,(e,{fiberId:t,fiberRef:n,value:r})=>{if(e.locals.size===0)return new Uh(new Map([[n,[[t,r]]]]));let i=new Map(e.locals);return Qh(i,t,n,r),new Uh(i)}),Qh=(e,t,n,r)=>{let i=e.get(n)??[],a;if(vr(i)){let[e,n]=wr(i);if(e[O](t)){if(k(n,r))return;a=[[t,r],...i.slice(1)]}else a=[[t,r],...i]}else a=[[t,r]];e.set(n,a)},$h=v(2,(e,{entries:t,forkAs:n})=>{if(e.locals.size===0)return new Uh(new Map(t));let r=new Map(e.locals);return n!==void 0&&qh(e,r,n),t.forEach(([e,t])=>{t.length===1?Qh(r,t[0][0],e,t[0][1]):t.forEach(([t,n])=>{Qh(r,t,e,n)})}),new Uh(r)}),eg=Xh,tg=$h,ng=Vh,rg=`Empty`,ig=`Remove`,ag=`Update`,og=`AndThen`,sg={_tag:rg},cg=(e,t)=>{let n=new Map(e.locals),r=sg;for(let[e,i]of t.locals.entries()){let t=wr(i)[1],a=n.get(e);if(a!==void 0){let n=wr(a)[1];k(n,t)||(r=lg({_tag:ag,fiberRef:e,patch:e.diff(n,t)})(r))}else r=lg({_tag:`Add`,fiberRef:e,value:t})(r);n.delete(e)}for(let[e]of n.entries())r=lg({_tag:ig,fiberRef:e})(r);return r},lg=v(2,(e,t)=>({_tag:og,first:e,second:t})),ug=v(3,(e,t,n)=>{let r=n,i=Hr(e);for(;vr(i);){let e=wr(i),n=Dr(i);switch(e._tag){case rg:i=n;break;case`Add`:r=Zh(r,{fiberId:t,fiberRef:e.fiberRef,value:e.value}),i=n;break;case ig:r=Jh(r,e.fiberRef),i=n;break;case ag:{let a=Xh(r,e.fiberRef);r=Zh(r,{fiberId:t,fiberRef:e.fiberRef,value:e.fiberRef.patch(e.patch)(a)}),i=n;break}case og:i=fr(e.first)(fr(e.second)(n))}}return r}),dg=cg,fg=ug,pg=`effect/FiberStatus`,mg=Symbol.for(pg),hg=`Done`,gg=E(`${pg}-${hg}`);var _g=class{[mg]=mg;_tag=hg;[C](){return gg}[O](e){return Cg(e)&&e._tag===`Done`}},vg=class{runtimeFlags;[mg]=mg;_tag=`Running`;constructor(e){this.runtimeFlags=e}[C](){return b(w(pg),T(w(this._tag)),T(w(this.runtimeFlags)),D(this))}[O](e){return Cg(e)&&e._tag===`Running`&&this.runtimeFlags===e.runtimeFlags}},yg=class{runtimeFlags;blockingOn;[mg]=mg;_tag=`Suspended`;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[C](){return b(w(pg),T(w(this._tag)),T(w(this.runtimeFlags)),T(w(this.blockingOn)),D(this))}[O](e){return Cg(e)&&e._tag===`Suspended`&&this.runtimeFlags===e.runtimeFlags&&k(this.blockingOn,e.blockingOn)}};const bg=new _g,xg=e=>new vg(e),Sg=(e,t)=>new yg(e,t),Cg=e=>S(e,mg),wg=e=>e._tag===hg,Tg=bg,Eg=xg,Dg=Sg,Og=wg,kg=Vf,Ag=Hf,jg=Uf,Mg=Wf,Ng=Gf,Pg=Kf,Fg=qf,Ig=Jf,Lg=Bn(b(Pm,zn(e=>e.ordinal))),Rg=e=>{switch(e){case`All`:return kg;case`Debug`:return Pg;case`Error`:return jg;case`Fatal`:return Ag;case`Info`:return Ng;case`Trace`:return Fg;case`None`:return Ig;case`Warning`:return Mg}},zg=Symbol.for(`effect/Micro`),Bg=Symbol.for(`effect/Micro/MicroExit`),Vg=Symbol.for(`effect/Micro/MicroCause`),Hg={_E:y};var Ug=class extends globalThis.Error{_tag;traces;[Vg];constructor(e,t,n){let r=`MicroCause.${e}`,i,a,o;if(t instanceof globalThis.Error){i=`(${r}) ${t.name}`,a=t.message;let e=a.split(`
14
+ `)}`:this.toString()}}return Object.assign(e.prototype,En),e}(),ah=(e,t)=>{class n extends ih{_tag=t}return Object.assign(n.prototype,e),n.prototype.name=t,n},oh=Symbol.for(`effect/Cause/errors/RuntimeException`),sh=ah({[oh]:oh},`RuntimeException`),ch=Symbol.for(`effect/Cause/errors/InterruptedException`),lh=e=>w(e,ch),uh=Symbol.for(`effect/Cause/errors/IllegalArgument`),dh=ah({[uh]:uh},`IllegalArgumentException`),fh=Symbol.for(`effect/Cause/errors/NoSuchElement`),ph=ah({[fh]:fh},`NoSuchElementException`),mh=Symbol.for(`effect/Cause/errors/UnknownException`),hh=function(){class e extends ih{_tag=`UnknownException`;error;constructor(e,t){super(t??`An unknown error occurred`,{cause:e}),this.error=e}}return Object.assign(e.prototype,{[mh]:mh,name:`UnknownException`}),e}(),gh=e=>xp(e)&&`_tag`in e&&(e._tag===`Success`||e._tag===`Failure`),_h=e=>e._tag===`Success`,vh=x(2,(e,t)=>{switch(e._tag){case $t:return Ch(e.effect_instruction_i0);case rn:return Dh(t)}}),yh=e=>vh(e,void 0),bh=(e,t)=>Ah(e,t?.parallel?Rs:zs),xh=e=>Ch(Is(e)),Sh=e=>Ch(Fs(e)),Ch=e=>{let t=new yp($t);return t.effect_instruction_i0=e,t},wh=e=>Ch(Ls(e)),Th=x(2,(e,t)=>{switch(e._tag){case $t:return Ch(e.effect_instruction_i0);case rn:return Dh(t(e.effect_instruction_i0))}}),Eh=x(2,(e,{onFailure:t,onSuccess:n})=>{switch(e._tag){case $t:return t(e.effect_instruction_i0);case rn:return n(e.effect_instruction_i0)}}),Dh=e=>{let t=new bp(rn);return t.effect_instruction_i0=e,t},Oh=Dh(void 0),kh=x(3,(e,t,{onFailure:n,onSuccess:r})=>{switch(e._tag){case $t:switch(t._tag){case rn:return Ch(e.effect_instruction_i0);case $t:return Ch(n(e.effect_instruction_i0,t.effect_instruction_i0))}case rn:switch(t._tag){case rn:return Dh(r(e.effect_instruction_i0,t.effect_instruction_i0));case $t:return Ch(t.effect_instruction_i0)}}}),Ah=(e,t)=>{let n=Sa(e);return Ia(n)?b(za(n),Oi(b(Ra(n),Th(xa)),(e,n)=>b(e,kh(n,{onSuccess:(e,t)=>b(e,Ma(t)),onFailure:t}))),Th(Da),Th(e=>Ta(e)),z):R()},jh=e=>({...Tn,[sp]:cp,state:Kl(lp([])),commit(){return Mh(this)},blockingOn:e}),Mh=e=>Op(t=>{let n=ql(e.state);switch(n._tag){case ip:return t(n.effect);case rp:return n.joiners.push(t),Ph(e,t)}},e.blockingOn),Nh=(e,t)=>{let n=ql(e.state);if(n._tag===`Pending`){Jl(e.state,up(t));for(let e=0,r=n.joiners.length;e<r;e++)n.joiners[e](t)}},Ph=(e,t)=>V(()=>{let n=ql(e.state);if(n._tag===`Pending`){let e=n.joiners.indexOf(t);e>=0&&n.joiners.splice(e,1)}}),Fh=Sp(e=>Dh(e.currentContext)),Ih=()=>Fh,Lh=e=>B(Ih(),e),Rh=x(2,(e,t)=>Mm(zm,t)(e)),zh=x(2,(e,t)=>Lh(n=>Rh(e,t(n)))),Bh=e=>{let t=e.currentSpan;return t!==void 0&&t._tag===`Span`?z(t):R()}})),Hh,Uh,Wh,Gh=v((()=>{bc(),Vh(),Hh=Hs,Uh=dh,Wh=dc})),Kh,qh,Jh,Yh,Xh=v((()=>{Kh=`InvalidData`,qh=`MissingData`,Jh=`SourceUnavailable`,Yh=`Unsupported`})),Zh,Qh,$h,eg,tg,ng,rg,ig,ag,og,sg,cg=v((()=>{Pi(),lr(),S(),Xh(),Zh=`effect/ConfigError`,Qh=Symbol.for(Zh),$h={_tag:`ConfigError`,[Qh]:Qh},eg=(e,t)=>{let n=Object.create($h);return n._op=`And`,n.left=e,n.right=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`${this.left} and ${this.right}`}}),Object.defineProperty(n,"message",{enumerable:!1,get(){return this.toString()}}),n},tg=(e,t)=>{let n=Object.create($h);return n._op=`Or`,n.left=e,n.right=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`${this.left} or ${this.right}`}}),Object.defineProperty(n,"message",{enumerable:!1,get(){return this.toString()}}),n},ng=(e,t,n={pathDelim:`.`})=>{let r=Object.create($h);return r._op=Kh,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Invalid data at ${b(this.path,Ni(n.pathDelim))}: "${this.message}")`}}),r},rg=(e,t,n={pathDelim:`.`})=>{let r=Object.create($h);return r._op=qh,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Missing data at ${b(this.path,Ni(n.pathDelim))}: "${this.message}")`}}),r},ig=(e,t,n,r={pathDelim:`.`})=>{let i=Object.create($h);return i._op=Jh,i.path=e,i.message=t,i.cause=n,Object.defineProperty(i,"toString",{enumerable:!1,value(){return`(Source unavailable at ${b(this.path,Ni(r.pathDelim))}: "${this.message}")`}}),i},ag=(e,t,n={pathDelim:`.`})=>{let r=Object.create($h);return r._op=Yh,r.path=e,r.message=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${b(this.path,Ni(n.pathDelim))}: "${this.message}")`}}),r},og=x(2,(e,t)=>{switch(e._op){case`And`:return eg(og(e.left,t),og(e.right,t));case`Or`:return tg(og(e.left,t),og(e.right,t));case Kh:return ng([...t,...e.path],e.message);case qh:return rg([...t,...e.path],e.message);case Jh:return ig([...t,...e.path],e.message,e.cause);case Yh:return ag([...t,...e.path],e.message)}}),sg=x(3,(e,t,n)=>{let r=[e],i=[];for(;r.length>0;){let e=r.pop();switch(e._op){case`And`:r.push(e.right),r.push(e.left),i.push(L({_op:`AndCase`}));break;case`Or`:r.push(e.right),r.push(e.left),i.push(L({_op:`OrCase`}));break;case Kh:i.push(I(n.invalidDataCase(t,e.path,e.message)));break;case qh:i.push(I(n.missingDataCase(t,e.path,e.message)));break;case Jh:i.push(I(n.sourceUnavailableCase(t,e.path,e.message,e.cause)));break;case Yh:i.push(I(n.unsupportedCase(t,e.path,e.message)))}}let a=[];for(;i.length>0;){let e=i.pop();switch(e._op){case`Left`:switch(e.left._op){case`AndCase`:{let e=a.pop(),r=a.pop(),i=n.andCase(t,e,r);a.push(i);break}case`OrCase`:{let e=a.pop(),r=a.pop(),i=n.orCase(t,e,r);a.push(i);break}}break;case`Right`:a.push(e.right)}}if(a.length===0)throw Error(`BUG: ConfigError.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues`);return a.pop()})})),lg,ug,dg,fg,pg,mg,hg,gg,_g,vg=v((()=>{il(),Ul(),S(),Vh(),lg=`effect/Clock`,ug=Symbol.for(lg),dg=Jc(`effect/Clock`),fg=2**31-1,pg={unsafeSchedule(e,t){let n=jl(t);if(n>fg)return Ce;let r=!1,i=setTimeout(()=>{r=!0,e()},n);return()=>(clearTimeout(i),!r)}},mg=function(){let e=BigInt(1e6);if(typeof performance>`u`||typeof performance.now!=`function`)return()=>BigInt(Date.now())*e;let t;return()=>(t===void 0&&(t=BigInt(Date.now())*e-BigInt(Math.round(performance.now()*1e6))),t+BigInt(Math.round(performance.now()*1e6)))}(),hg=function(){let e=typeof process==`object`&&`hrtime`in process&&typeof process.hrtime.bigint==`function`?process.hrtime:void 0;if(!e)return mg;let t=mg()-e.bigint();return()=>t+e.bigint()}(),gg=class{[ug]=ug;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return hg()}currentTimeMillis=V(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=V(()=>this.unsafeCurrentTimeNanos());scheduler(){return nm(pg)}sleep(e){return kp(t=>{let n=pg.unsafeSchedule(()=>t(cm),e);return Tp(V(n))})}},_g=()=>new gg})),yg,bg,xg=v((()=>{zn(),gr(),yg=pr,bg=e=>{if(e===`NaN`)return Rn(NaN);if(e===`Infinity`)return Rn(1/0);if(e===`-Infinity`)return Rn(-1/0);if(e.trim()===``)return Ln;let t=Number(e);return Number.isNaN(t)?Ln:Rn(t)}})),Sg,Cg=v((()=>{Sg=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`)})),wg,Tg,Eg=v((()=>{Pi(),lr(),S(),Qu(),Rr(),cg(),wg={_tag:`Empty`},Tg=x(2,(e,t)=>{let n=Ku(t),r=e;for(;Hu(n);){let e=n.head;switch(e._tag){case`Empty`:n=n.tail;break;case`AndThen`:n=Wu(e.first,Wu(e.second,n.tail));break;case`MapName`:r=wi(r,e.f),n=n.tail;break;case`Nested`:r=Kr(r,e.name),n=n.tail;break;case`Unnested`:if(b(ii(r),Ir(e.name)))r=ci(r),n=n.tail;else return L(rg(r,`Expected ${e.name} to be in path in ConfigProvider#unnested`))}}return I(r)})})),Dg,Og,kg,Ag,jg,Mg,Ng,Pg,Fg,Ig,Lg,Rg,zg=v((()=>{Dg=`Constant`,Og=`Fail`,kg=`Fallback`,Ag=`Described`,jg=`Lazy`,Mg=`MapOrFail`,Ng=`Nested`,Pg=`Primitive`,Fg=`Redacted`,Ig=`Sequence`,Lg=`HashMap`,Rg=`ZipWith`})),Bg,Vg,Hg,Ug,Wg,Gg,Kg,qg,Jg,Yg,Xg,Zg,Qg,$g,e_,t_,n_,r_,i_,a_,o_,s_,c_,l_=v((()=>{Pi(),il(),lr(),S(),Au(),Cs(),xg(),Rr(),F(),Cg(),cg(),Eg(),Vh(),zg(),Bg=(e,t)=>[...e,...t],Vg=`effect/ConfigProvider`,Hg=Symbol.for(Vg),Ug=Jc(`effect/ConfigProvider`),Wg=`effect/ConfigProviderFlat`,Gg=Symbol.for(Wg),Kg=e=>({[Hg]:Hg,pipe(){return P(this,arguments)},...e}),qg=e=>({[Gg]:Gg,patch:e.patch,load:(t,n,r=!0)=>e.load(t,n,r),enumerateChildren:e.enumerateChildren}),Jg=e=>Kg({load:t=>B(e_(e,Si(),t,!1),e=>br(ii(e),{onNone:()=>Lp(rg(Si(),`Expected a single value having structure: ${t}`)),onSome:nm})),flattened:e}),Yg=e=>{let{pathDelim:t,seqDelim:n}=Object.assign({},{pathDelim:`_`,seqDelim:`,`},e),r=e=>b(e,Ni(t)),i=e=>e.split(t),a=()=>typeof process<`u`&&`env`in process&&typeof process.env==`object`?process.env:{};return Jg(qg({load:(e,t,i=!0)=>{let o=r(e),s=a();return b(o in s?z(s[o]):R(),$p(()=>rg(e,`Expected ${o} to exist in the process context`)),B(r=>r_(r,e,t,n,i)))},enumerateChildren:e=>V(()=>{let t=a(),n=Object.keys(t).map(e=>i(e.toUpperCase())).filter(t=>{for(let n=0;n<e.length;n++){let r=b(e,ri(n)),i=t[n];if(i===void 0||r!==i)return!1}return!0}).flatMap(t=>t.slice(e.length,e.length+1));return ms(n)}),patch:wg}))},Xg=(e,t,n,r)=>{let i=ki(n.length,t=>t>=r.length?R():z([e(t),t+1])),a=ki(r.length,e=>e>=n.length?R():z([t(e),e+1]));return[Bg(n,i),Bg(r,a)]},Zg=(e,t)=>{let n=t;if(n._tag===`Nested`){let t=e.slice();for(;n._tag===`Nested`;)t.push(n.name),n=n.config;return t}return e},Qg={andCase:(e,t,n)=>eg(t,n),orCase:(e,t,n)=>tg(t,n),invalidDataCase:(e,t)=>ng(t,`<redacted>`),missingDataCase:(e,t)=>rg(t,`<redacted>`),sourceUnavailableCase:(e,t,n,r)=>ig(t,`<redacted>`,r),unsupportedCase:(e,t)=>ag(t,`<redacted>`)},$g=e=>sg(e,void 0,Qg),e_=(e,t,n,r)=>{let i=n;switch(i._tag){case Dg:return nm(Ci(i.value));case Ag:return rm(()=>e_(e,t,i.config,r));case Og:return Lp(rg(t,i.message));case kg:return b(rm(()=>e_(e,t,i.first,r)),Ap(n=>i.condition(n)?b(e_(e,t,i.second,r),Ap(e=>Lp(tg(n,e)))):Lp(n)));case jg:return rm(()=>e_(e,t,i.config(),r));case Mg:return rm(()=>b(e_(e,t,i.original,r),B(Jp(e=>b(i.mapOrFail(e),$p(og(Zg(t,i.original))))))));case Ng:return rm(()=>e_(e,Bg(t,Ci(i.name)),i.config,r));case Pg:return b(Tg(t,e.patch),B(t=>b(e.load(t,i,r),B(e=>{if(e.length===0){let e=b(oi(t),xr(()=>`<n/a>`));return Lp(rg([],`Expected ${i.description} with name ${e}`))}return nm(e)}))));case Fg:return rm(()=>b(e_(e,t,i.original,r),$p($g),Zp(wi(i.redact))));case Ig:return b(Tg(t,e.patch),B(n=>b(e.enumerateChildren(n),B(a_),B(n=>n.length===0?rm(()=>Zp(e_(e,t,i.config,!0),Ci)):b(Jp(n,n=>e_(e,qr(t,`[${n}]`),i.config,!0)),Zp(e=>{let t=Ei(e);return t.length===0?Ci(Si()):Ci(t)}))))));case Lg:return rm(()=>b(Tg(t,e.patch),B(t=>b(e.enumerateChildren(t),B(n=>b(n,Jp(n=>e_(e,Bg(t,Ci(n)),i.valueConfig,r)),Zp(e=>e.length===0?Ci(xu()):b(i_(e),wi(e=>Su(mi(Ur(n),e)))))))))));case Rg:return rm(()=>b(e_(e,t,i.left,r),Fp,B(n=>b(e_(e,t,i.right,r),Fp,B(e=>{if(er(n)&&er(e))return Lp(eg(n.left,e.left));if(er(n)&&tr(e))return Lp(n.left);if(tr(n)&&er(e))return Lp(e.left);if(tr(n)&&tr(e)){let r=b(t,Ni(`.`)),a=t_(t,r),[o,s]=Xg(a,a,b(n.right,wi(I)),b(e.right,wi(I)));return b(o,mi(s),Jp(([e,t])=>b(fm(e,t),Zp(([e,t])=>i.zip(e,t)))))}throw Error(`BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues`)})))))}},t_=(e,t)=>n=>L(rg(e,`The element at index ${n} in a sequence at path "${t}" was missing`)),n_=(e,t)=>e.split(RegExp(`\\s*${Sg(t)}\\s*`)),r_=(e,t,n,r,i)=>i?b(n_(e,r),Jp(e=>n.parse(e.trim())),$p(og(t))):b(n.parse(e),Qp({onFailure:og(t),onSuccess:Ci})),i_=e=>Object.keys(e[0]).map(t=>e.map(e=>e[t])),a_=e=>b(Jp(e,s_),Qp({onFailure:()=>Si(),onSuccess:pi(yg)}),Fp,Zp(or)),o_=/^(\[(\d+)\])$/,s_=e=>{let t=e.match(o_);if(t!==null){let e=t[2];return b(e!==void 0&&e.length>0?z(e):R(),kr(c_))}return R()},c_=e=>{let t=Number.parseInt(e);return Number.isNaN(t)?R():z(t)}})),u_,d_,f_,p_=v((()=>{il(),Vh(),u_=Symbol.for(`effect/Console`),d_=Jc(`effect/Console`),f_={[u_]:u_,assert(e,...t){return V(()=>{console.assert(e,...t)})},clear:V(()=>{console.clear()}),count(e){return V(()=>{console.count(e)})},countReset(e){return V(()=>{console.countReset(e)})},debug(...e){return V(()=>{console.debug(...e)})},dir(e,t){return V(()=>{console.dir(e,t)})},dirxml(...e){return V(()=>{console.dirxml(...e)})},error(...e){return V(()=>{console.error(...e)})},group(e){return e?.collapsed?V(()=>console.groupCollapsed(e?.label)):V(()=>console.group(e?.label))},groupEnd:V(()=>{console.groupEnd()}),info(...e){return V(()=>{console.info(...e)})},log(...e){return V(()=>{console.log(...e)})},table(e,t){return V(()=>{console.table(e,t)})},time(e){return V(()=>console.time(e))},timeEnd(e){return V(()=>console.timeEnd(e))},timeLog(e,...t){return V(()=>{console.timeLog(e,...t)})},trace(...e){return V(()=>{console.trace(...e)})},warn(...e){return V(()=>{console.warn(...e)})},unsafe:console}})),m_,h_,g_,__,v_,y_,b_,x_=v((()=>{Ba(),il(),S(),Mt(),St(),Vh(),m_=`effect/Random`,h_=Symbol.for(m_),g_=Jc(`effect/Random`),__=class{seed;[h_]=h_;PRNG;constructor(e){this.seed=e,this.PRNG=new mt(e)}get next(){return V(()=>this.PRNG.number())}get nextBoolean(){return Zp(this.next,e=>e>.5)}get nextInt(){return V(()=>this.PRNG.integer(2**53-1))}nextRange(e,t){return Zp(this.next,n=>(t-e)*n+e)}nextIntBetween(e,t){return V(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return v_(e,e=>this.nextIntBetween(0,e))}},v_=(e,t)=>rm(()=>b(V(()=>Array.from(e)),B(e=>{let n=[];for(let t=e.length;t>=2;--t)n.push(t);return b(n,Yp(n=>b(t(n),Zp(t=>y_(e,n-1,t)))),wp(Sa(e)))}))),y_=(e,t,n)=>{let r=e[t];return e[t]=e[n],e[n]=r,e},b_=e=>new __(D(e))})),S_,C_,w_,T_,E_,D_,O_,k_,A_=v((()=>{il(),S(),S_=Symbol.for(`effect/Tracer`),C_=e=>({[S_]:S_,...e}),w_=Jc(`effect/Tracer`),T_=Jc(`effect/ParentSpan`),E_=function(){return function(e){let t=``;for(let n=0;n<e;n++)t+=`abcdef0123456789`.charAt(Math.floor(Math.random()*16));return t}}(),D_=class{name;parent;context;startTime;kind;_tag=`Span`;spanId;traceId=`native`;sampled=!0;status;attributes;events=[];links;constructor(e,t,n,r,i,a){this.name=e,this.parent=t,this.context=n,this.startTime=i,this.kind=a,this.status={_tag:`Started`,startTime:i},this.attributes=new Map,this.traceId=t._tag===`Some`?t.value.traceId:E_(32),this.spanId=E_(16),this.links=Array.from(r)}end(e,t){this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime}}attribute(e,t){this.attributes.set(e,t)}event(e,t,n){this.events.push([e,t,n??{}])}addLinks(e){this.links.push(...e)}},O_=C_({span:(e,t,n,r,i,a)=>new D_(e,t,n,r,i,a),context:e=>e()}),k_=rl()(`effect/Tracer/DisablePropagation`,{defaultValue:Ce})})),j_,M_,N_=v((()=>{il(),S(),Ie(),vg(),l_(),Vh(),p_(),x_(),A_(),j_=b(Yc(),Zc(dg,_g()),Zc(d_,f_),Zc(g_,b_(Math.random())),Zc(Ug,Yg()),Zc(w_,O_)),M_=C(Symbol.for(`effect/DefaultServices/currentServices`),()=>Im(j_))})),P_,F_,I_=v((()=>{Vh(),P_=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return{BaseEffectError:class extends ih{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Object.assign(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}.BaseEffectError}(),F_=e=>{let t={BaseEffectError:class extends P_{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError}})),L_,R_,z_,B_=v((()=>{On(),L_=Cn,R_=Dn,z_=class extends R_{}})),V_,H_,U_,W_,G_,K_,q_,J_,Y_=v((()=>{V_=`Sequential`,H_=`Parallel`,U_=`ParallelN`,W_={_tag:V_},G_={_tag:H_},K_=e=>({_tag:U_,parallelism:e}),q_=e=>e._tag===V_,J_=e=>e._tag===H_})),X_,Z_,Q_,$_=v((()=>{Y_(),X_=W_,Z_=G_,Q_=K_}));function ev(e){return new rv(e)}function tv(){return ev(new Map)}var nv,rv,iv,av,ov,sv,cv,lv,uv,dv,fv,pv,mv=v((()=>{Pi(),M(),S(),Rr(),F(),nv=Symbol.for(`effect/FiberRefs`),rv=class{locals;[nv]=nv;constructor(e){this.locals=e}pipe(){return P(this,arguments)}},iv=(e,t,n,r=!1)=>{let i=e,a=t,o=n,s=r,c;for(;c===void 0;)if($r(a)&&$r(o)){let e=ai(a)[0],t=ci(a),n=ai(o)[0],r=ai(o)[1],i=ci(o);e.startTimeMillis<n.startTimeMillis?(o=i,s=!0):e.startTimeMillis>n.startTimeMillis?a=t:e.id<n.id?(o=i,s=!0):e.id>n.id?a=t:c=[r,s]}else c=[i.initial,!0];return c},av=x(3,(e,t,n)=>{let r=new Map(e.locals);return n.locals.forEach((e,n)=>{let i=e[0][1];if(!e[0][0][j](t)){if(!r.has(n)){if(A(i,n.initial))return;r.set(n,[[t,n.join(n.initial,i)]]);return}let a=r.get(n),[o,s]=iv(n,a,e);if(s){let e=n.diff(o,i),s=a[0][1],c=n.join(s,n.patch(e)(s));if(!A(s,c)){let e,i=a[0][0];e=i[j](t)?[[i,c],...a.slice(1)]:[[t,c],...a],r.set(n,e)}}}}),new rv(r)}),ov=x(2,(e,t)=>{let n=new Map;return sv(e,n,t),new rv(n)}),sv=(e,t,n)=>{e.locals.forEach((e,r)=>{let i=e[0][1],a=r.patch(r.fork)(i);A(i,a)?t.set(r,e):t.set(r,[[n,a],...e])})},cv=x(2,(e,t)=>{let n=new Map(e.locals);return n.delete(t),new rv(n)}),lv=x(2,(e,t)=>e.locals.has(t)?z(ai(e.locals.get(t))[1]):R()),uv=x(2,(e,t)=>b(lv(e,t),xr(()=>t.initial))),dv=x(2,(e,{fiberId:t,fiberRef:n,value:r})=>{if(e.locals.size===0)return new rv(new Map([[n,[[t,r]]]]));let i=new Map(e.locals);return fv(i,t,n,r),new rv(i)}),fv=(e,t,n,r)=>{let i=e.get(n)??[],a;if($r(i)){let[e,n]=ai(i);if(e[j](t)){if(A(n,r))return;a=[[t,r],...i.slice(1)]}else a=[[t,r],...i]}else a=[[t,r]];e.set(n,a)},pv=x(2,(e,{entries:t,forkAs:n})=>{if(e.locals.size===0)return new rv(new Map(t));let r=new Map(e.locals);return n!==void 0&&sv(e,r,n),t.forEach(([e,t])=>{t.length===1?fv(r,t[0][0],e,t[0][1]):t.forEach(([t,n])=>{fv(r,t,e,n)})}),new rv(r)})})),hv,gv,_v,vv=v((()=>{mv(),hv=uv,gv=pv,_v=tv})),yv,bv,xv,Sv,Cv,wv,Tv,Ev,Dv=v((()=>{Pi(),M(),S(),mv(),yv=`Empty`,bv=`Remove`,xv=`Update`,Sv=`AndThen`,Cv={_tag:yv},wv=(e,t)=>{let n=new Map(e.locals),r=Cv;for(let[e,i]of t.locals.entries()){let t=ai(i)[1],a=n.get(e);if(a!==void 0){let n=ai(a)[1];A(n,t)||(r=Tv({_tag:xv,fiberRef:e,patch:e.diff(n,t)})(r))}else r=Tv({_tag:`Add`,fiberRef:e,value:t})(r);n.delete(e)}for(let[e]of n.entries())r=Tv({_tag:bv,fiberRef:e})(r);return r},Tv=x(2,(e,t)=>({_tag:Sv,first:e,second:t})),Ev=x(3,(e,t,n)=>{let r=n,i=Ci(e);for(;$r(i);){let e=ai(i),n=ci(i);switch(e._tag){case yv:i=n;break;case`Add`:r=dv(r,{fiberId:t,fiberRef:e.fiberRef,value:e.value}),i=n;break;case bv:r=cv(r,e.fiberRef),i=n;break;case xv:{let a=uv(r,e.fiberRef);r=dv(r,{fiberId:t,fiberRef:e.fiberRef,value:e.fiberRef.patch(e.patch)(a)}),i=n;break}case Sv:i=Kr(e.first)(Kr(e.second)(n))}}return r})})),Ov,kv,Av=v((()=>{Dv(),Ov=wv,kv=Ev})),jv,Mv,Nv,Pv,Fv,Iv,Lv,Rv,zv,Bv,Vv,Hv,Uv,Wv,Gv=v((()=>{M(),S(),Mt(),T(),jv=`effect/FiberStatus`,Mv=Symbol.for(jv),Nv=`Done`,Pv=`Running`,Fv=`Suspended`,Iv=Ot(`${jv}-${Nv}`),Lv=class{[Mv]=Mv;_tag=Nv;[E](){return Iv}[j](e){return Uv(e)&&e._tag===`Done`}},Rv=class{runtimeFlags;[Mv]=Mv;_tag=Pv;constructor(e){this.runtimeFlags=e}[E](){return b(D(jv),O(D(this._tag)),O(D(this.runtimeFlags)),k(this))}[j](e){return Uv(e)&&e._tag===`Running`&&this.runtimeFlags===e.runtimeFlags}},zv=class{runtimeFlags;blockingOn;[Mv]=Mv;_tag=Fv;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[E](){return b(D(jv),O(D(this._tag)),O(D(this.runtimeFlags)),O(D(this.blockingOn)),k(this))}[j](e){return Uv(e)&&e._tag===`Suspended`&&this.runtimeFlags===e.runtimeFlags&&A(this.blockingOn,e.blockingOn)}},Bv=new Lv,Vv=e=>new Rv(e),Hv=(e,t)=>new zv(e,t),Uv=e=>w(e,Mv),Wv=e=>e._tag===Nv})),Kv,qv,Jv,Yv,Xv=v((()=>{Gv(),Kv=Bv,qv=Vv,Jv=Hv,Yv=Wv})),Zv,Qv,$v,ey,ty,ny,ry,iy,ay,oy,sy,cy=v((()=>{S(),Vh(),xg(),gr(),Zv=_m,Qv=vm,$v=ym,ey=bm,ty=xm,ny=Sm,ry=Cm,iy=wm,ay=b(yg,mr(e=>e.ordinal)),oy=hr(ay),sy=e=>{switch(e){case`All`:return Zv;case`Debug`:return ny;case`Error`:return $v;case`Fatal`:return Qv;case`Info`:return ty;case`Trace`:return ry;case`None`:return iy;case`Warning`:return ey}}}));function ly(e){return Zy(`Micro.evaluate: Not implemented`)}var uy,dy,fy,py,my,hy,gy,_y,vy,yy,by,xy,Sy,Cy,wy,Ty,Ey,Dy,Oy,ky,Ay,jy,My,Ny,Py,Fy,Iy,Ly,Ry,zy,By,Vy,Hy,Uy,Wy,Gy,Ky,qy,Jy,Yy,Xy,Zy,Qy,$y,eb,tb,nb,rb,ib,ab,ob,sb,cb,lb,ub,db,fb,pb,mb,hb=v((()=>{il(),B_(),M(),S(),Ie(),Mt(),Xt(),qc(),On(),F(),T(),St(),uy=Symbol.for(`effect/Micro`),dy=Symbol.for(`effect/Micro/MicroExit`),fy=Symbol.for(`effect/Micro/MicroCause`),py={_E:be},my=class extends globalThis.Error{_tag;traces;[fy];constructor(e,t,n){let r=`MicroCause.${e}`,i,a,o;if(t instanceof globalThis.Error){i=`(${r}) ${t.name}`,a=t.message;let e=a.split(`
15
15
  `).length;o=t.stack?`(${r}) ${t.stack.split(`
16
16
  `).slice(0,e+3).join(`
17
- `)}`:`${i}: ${a}`}else i=r,a=Ct(t,0),o=`${i}: ${a}`;n.length>0&&(o+=`\n ${n.join(`
18
- `)}`),super(a),this._tag=e,this.traces=n,this[Vg]=Hg,this.name=i,this.stack=o}pipe(){return j(this,arguments)}toString(){return this.stack}[A](){return this.stack}},Wg=class extends Ug{error;constructor(e,t=[]){super(`Fail`,e,t),this.error=e}};const Gg=(e,t=[])=>new Wg(e,t);var Kg=class extends Ug{defect;constructor(e,t=[]){super(`Die`,e,t),this.defect=e}};const qg=(e,t=[])=>new Kg(e,t);var Jg=class extends Ug{constructor(e=[]){super(`Interrupt`,`interrupted`,e)}};const Yg=(e=[])=>new Jg(e),Xg=e=>e._tag===`Interrupt`,Zg=Symbol.for(`effect/Micro/MicroFiber`),Qg={_A:y,_E:y};var $g=class{context;interruptible;[Zg];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[Zg]=Qg}getRef(e){return Rs(this.context,e)}addObserver(e){return this._exit?(e(this._exit),xe):(this._observers.push(e),()=>{let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)})}_interrupted=!1;unsafeInterrupt(){this._exit||(this._interrupted=!0,this.interruptible&&this.evaluate(T_))}unsafePoll(){return this._exit}evaluate(e){if(this._exit)return;if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===s_)return;let n=e_.interruptChildren&&e_.interruptChildren(this);if(n!==void 0)return this.evaluate(b_(n,()=>t));this._exit=t;for(let e=0;e<this._observers.length;e++)this._observers[e](t);this._observers.length=0}runLoop(e){let t=!1,n=e;this.currentOpCount=0;try{for(;;){if(this.currentOpCount++,!t&&this.getRef(N_).shouldYield(this)){t=!0;let e=n;n=b_(__,()=>e)}if(n=n[r_](this),n===s_){let e=this._yielded;return Bg in e?(this._yielded=void 0,e):s_}}}catch(e){return S(n,r_)?E_(e):E_(`MicroFiber.runLoop: Not a valid effect: ${String(n)}`)}}getCont(e){for(;;){let t=this._stack.pop();if(!t)return;let n=t[o_]&&t[o_](this);if(n)return{[e]:n};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,s_}children(){return this._children??=new Set}};const e_=x(`effect/Micro/fiberMiddleware`,()=>({interruptChildren:void 0})),t_=Symbol.for(`effect/Micro/identifier`),n_=Symbol.for(`effect/Micro/args`),r_=Symbol.for(`effect/Micro/evaluate`),i_=Symbol.for(`effect/Micro/successCont`),a_=Symbol.for(`effect/Micro/failureCont`),o_=Symbol.for(`effect/Micro/ensureCont`),s_=Symbol.for(`effect/Micro/Yield`),c_={_A:y,_E:y,_R:y},l_={...Dh,_op:`Micro`,[zg]:c_,pipe(){return j(this,arguments)},[Symbol.iterator](){return new Ye(new et(this))},toJSON(){return{_id:`Micro`,op:this[t_],...n_ in this?{args:this[n_]}:void 0}},toString(){return St(this)},[A](){return St(this)}};function u_(e){return E_(`Micro.evaluate: Not implemented`)}const d_=e=>({...l_,[t_]:e.op,[r_]:e.eval??u_,[i_]:e.contA,[a_]:e.contE,[o_]:e.ensure}),f_=e=>{let t=d_(e);return function(){let n=Object.create(t);return n[n_]=e.single===!1?arguments:arguments[0],n}},p_=e=>{let t={...d_(e),[Bg]:Bg,_tag:e.op,get[e.prop](){return this[n_]},toJSON(){return{_id:`MicroExit`,_tag:e.op,[e.prop]:this[n_]}},[O](t){return S_(t)&&t._tag===e.op&&k(this[n_],t[n_])},[C](){return D(this,T(E(e.op))(w(this[n_])))}};return function(e){let n=Object.create(t);return n[n_]=e,n[i_]=void 0,n[a_]=void 0,n[o_]=void 0,n}},m_=p_({op:`Success`,prop:`value`,eval(e){let t=e.getCont(i_);return t?t[i_](this[n_],e):e.yieldWith(this)}}),h_=p_({op:`Failure`,prop:`cause`,eval(e){let t=e.getCont(a_);for(;Xg(this[n_])&&t&&e.interruptible;)t=e.getCont(a_);return t?t[a_](this[n_],e):e.yieldWith(this)}}),g_=e=>h_(Gg(e)),__=f_({op:`Yield`,eval(e){let t=!1;return e.getRef(N_).scheduleTask(()=>{t||e.evaluate(D_)},this[n_]??0),e.yieldWith(()=>{t=!0})}})(0),v_=m_(void 0),y_=f_({op:`WithMicroFiber`,eval(e){return this[n_](e)}}),b_=v(2,(e,t)=>{let n=Object.create(x_);return n[n_]=e,n[i_]=t,n}),x_=d_({op:`OnSuccess`,eval(e){return e._stack.push(this),this[n_]}}),S_=e=>S(e,Bg),C_=m_,w_=h_,T_=w_(Yg()),E_=e=>w_(qg(e)),D_=C_(void 0),O_=`setImmediate`in globalThis?globalThis.setImmediate:e=>setTimeout(e,0);var k_=class{tasks=[];running=!1;scheduleTask(e,t){this.tasks.push(e),this.running||(this.running=!0,O_(this.afterScheduled))}afterScheduled=()=>{this.running=!1,this.runTasks()};runTasks(){let e=this.tasks;this.tasks=[];for(let t=0,n=e.length;t<n;t++)e[t]()}shouldYield(e){return e.currentOpCount>=e.getRef(M_)}flush(){for(;this.tasks.length>0;)this.runTasks()}};const A_=v(2,(e,t)=>y_(n=>{let r=n.context;return n.context=t(r),I_(e,()=>(n.context=r,v_))})),j_=v(2,(e,t)=>A_(e,Xs(t)));var M_=class extends Qs()(`effect/Micro/currentMaxOpsBeforeYield`,{defaultValue:()=>2048}){};Qs()(`effect/Micro/currentConcurrency`,{defaultValue:()=>`unbounded`});var N_=class extends Qs()(`effect/Micro/currentScheduler`,{defaultValue:()=>new k_}){};const P_=v(2,(e,t)=>{let n=Object.create(F_);return n[n_]=e,n[i_]=t.onSuccess,n[a_]=t.onFailure,n}),F_=d_({op:`OnSuccessAndFailure`,eval(e){return e._stack.push(this),this[n_]}}),I_=v(2,(e,t)=>z_(n=>P_(n(e),{onFailure:e=>b_(t(w_(e)),()=>h_(e)),onSuccess:e=>b_(t(C_(e)),()=>m_(e))}))),L_=f_({op:`SetInterruptible`,ensure(e){if(e.interruptible=this[n_],e._interrupted&&e.interruptible)return()=>T_}}),R_=e=>y_(t=>t.interruptible?e:(t.interruptible=!0,t._stack.push(L_(!1)),t._interrupted?T_:e)),z_=e=>y_(t=>t.interruptible?(t.interruptible=!1,t._stack.push(L_(!0)),e(R_)):e(y)),B_=(e,t)=>{let n=new $g(N_.context(t?.scheduler??new k_));if(n.evaluate(e),t?.signal){if(t.signal.aborted)n.unsafeInterrupt();else{let e=()=>n.unsafeInterrupt();t.signal.addEventListener(`abort`,e,{once:!0}),n.addObserver(()=>t.signal.removeEventListener(`abort`,e))}}return n},V_=function(){class e extends globalThis.Error{}return Object.assign(e.prototype,l_,$t,{[t_]:`Failure`,[r_](){return g_(this)},toString(){return this.message?`${this.name}: ${this.message}`:this.name},toJSON(){return{...this}},[A](){let e=this.stack;return e?`${this.toString()}\n${e.split(`
17
+ `)}`:`${i}: ${a}`}else i=r,a=Ut(t,0),o=`${i}: ${a}`;n.length>0&&(o+=`\n ${n.join(`
18
+ `)}`),super(a),this._tag=e,this.traces=n,this[fy]=py,this.name=i,this.stack=o}pipe(){return P(this,arguments)}toString(){return this.stack}[N](){return this.stack}},hy=class extends my{error;constructor(e,t=[]){super(`Fail`,e,t),this.error=e}},gy=(e,t=[])=>new hy(e,t),_y=class extends my{defect;constructor(e,t=[]){super(`Die`,e,t),this.defect=e}},vy=(e,t=[])=>new _y(e,t),yy=class extends my{constructor(e=[]){super(`Interrupt`,`interrupted`,e)}},by=(e=[])=>new yy(e),xy=e=>e._tag===`Interrupt`,Sy=Symbol.for(`effect/Micro/MicroFiber`),Cy={_A:be,_E:be},wy=class{context;interruptible;[Sy];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[Sy]=Cy}getRef(e){return Hc(this.context,e)}addObserver(e){return this._exit?(e(this._exit),Te):(this._observers.push(e),()=>{let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)})}_interrupted=!1;unsafeInterrupt(){this._exit||(this._interrupted=!0,this.interruptible&&this.evaluate(Xy))}unsafePoll(){return this._exit}evaluate(e){if(this._exit)return;if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===My)return;let n=Ty.interruptChildren&&Ty.interruptChildren(this);if(n!==void 0)return this.evaluate(Gy(n,()=>t));this._exit=t;for(let e=0;e<this._observers.length;e++)this._observers[e](t);this._observers.length=0}runLoop(e){let t=!1,n=e;this.currentOpCount=0;try{for(;;){if(this.currentOpCount++,!t&&this.getRef(ib).shouldYield(this)){t=!0;let e=n;n=Gy(Hy,()=>e)}if(n=n[Oy](this),n===My){let e=this._yielded;return dy in e?(this._yielded=void 0,e):My}}}catch(e){return w(n,Oy)?Zy(e):Zy(`MicroFiber.runLoop: Not a valid effect: ${String(n)}`)}}getCont(e){for(;;){let t=this._stack.pop();if(!t)return;let n=t[jy]&&t[jy](this);if(n)return{[e]:n};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,My}children(){return this._children??=new Set}},Ty=C(`effect/Micro/fiberMiddleware`,()=>({interruptChildren:void 0})),Ey=Symbol.for(`effect/Micro/identifier`),Dy=Symbol.for(`effect/Micro/args`),Oy=Symbol.for(`effect/Micro/evaluate`),ky=Symbol.for(`effect/Micro/successCont`),Ay=Symbol.for(`effect/Micro/failureCont`),jy=Symbol.for(`effect/Micro/ensureCont`),My=Symbol.for(`effect/Micro/Yield`),Ny={_A:be,_E:be,_R:be},Py={...L_,_op:`Micro`,[uy]:Ny,pipe(){return P(this,arguments)},[Symbol.iterator](){return new st(new gt(this))},toJSON(){return{_id:`Micro`,op:this[Ey],...Dy in this?{args:this[Dy]}:void 0}},toString(){return Ht(this)},[N](){return Ht(this)}},Fy=e=>({...Py,[Ey]:e.op,[Oy]:e.eval??ly,[ky]:e.contA,[Ay]:e.contE,[jy]:e.ensure}),Iy=e=>{let t=Fy(e);return function(){let n=Object.create(t);return n[Dy]=e.single===!1?arguments:arguments[0],n}},Ly=e=>{let t={...Fy(e),[dy]:dy,_tag:e.op,get[e.prop](){return this[Dy]},toJSON(){return{_id:`MicroExit`,_tag:e.op,[e.prop]:this[Dy]}},[j](t){return qy(t)&&t._tag===e.op&&A(this[Dy],t[Dy])},[E](){return k(this,O(Ot(e.op))(D(this[Dy])))}};return function(e){let n=Object.create(t);return n[Dy]=e,n[ky]=void 0,n[Ay]=void 0,n[jy]=void 0,n}},Ry=Ly({op:`Success`,prop:`value`,eval(e){let t=e.getCont(ky);return t?t[ky](this[Dy],e):e.yieldWith(this)}}),zy=Ly({op:`Failure`,prop:`cause`,eval(e){let t=e.getCont(Ay);for(;xy(this[Dy])&&t&&e.interruptible;)t=e.getCont(Ay);return t?t[Ay](this[Dy],e):e.yieldWith(this)}}),By=e=>zy(gy(e)),Vy=Iy({op:`Yield`,eval(e){let t=!1;return e.getRef(ib).scheduleTask(()=>{t||e.evaluate(Qy)},this[Dy]??0),e.yieldWith(()=>{t=!0})}}),Hy=Vy(0),Uy=Ry(void 0),Wy=Iy({op:`WithMicroFiber`,eval(e){return this[Dy](e)}}),Gy=x(2,(e,t)=>{let n=Object.create(Ky);return n[Dy]=e,n[ky]=t,n}),Ky=Fy({op:`OnSuccess`,eval(e){return e._stack.push(this),this[Dy]}}),qy=e=>w(e,dy),Jy=Ry,Yy=zy,Xy=Yy(by()),Zy=e=>Yy(vy(e)),Qy=Jy(void 0),$y=`setImmediate`in globalThis?globalThis.setImmediate:e=>setTimeout(e,0),eb=class{tasks=[];running=!1;scheduleTask(e,t){this.tasks.push(e),this.running||(this.running=!0,$y(this.afterScheduled))}afterScheduled=()=>{this.running=!1,this.runTasks()};runTasks(){let e=this.tasks;this.tasks=[];for(let t=0,n=e.length;t<n;t++)e[t]()}shouldYield(e){return e.currentOpCount>=e.getRef(rb)}flush(){for(;this.tasks.length>0;)this.runTasks()}},tb=x(2,(e,t)=>Wy(n=>{let r=n.context;return n.context=t(r),sb(e,()=>(n.context=r,Uy))})),nb=x(2,(e,t)=>tb(e,tl(t))),rb=class extends rl()(`effect/Micro/currentMaxOpsBeforeYield`,{defaultValue:()=>2048}){},rl()(`effect/Micro/currentConcurrency`,{defaultValue:()=>`unbounded`}),ib=class extends rl()(`effect/Micro/currentScheduler`,{defaultValue:()=>new eb}){},ab=x(2,(e,t)=>{let n=Object.create(ob);return n[Dy]=e,n[ky]=t.onSuccess,n[Ay]=t.onFailure,n}),ob=Fy({op:`OnSuccessAndFailure`,eval(e){return e._stack.push(this),this[Dy]}}),sb=x(2,(e,t)=>ub(n=>ab(n(e),{onFailure:e=>Gy(t(Yy(e)),()=>zy(e)),onSuccess:e=>Gy(t(Jy(e)),()=>Ry(e))}))),cb=Iy({op:`SetInterruptible`,ensure(e){if(e.interruptible=this[Dy],e._interrupted&&e.interruptible)return()=>Xy}}),lb=e=>Wy(t=>t.interruptible?e:(t.interruptible=!0,t._stack.push(cb(!1)),t._interrupted?Xy:e)),ub=e=>Wy(t=>t.interruptible?(t.interruptible=!1,t._stack.push(cb(!0)),e(lb)):e(be)),db=(e,t)=>{let n=new wy(ib.context(t?.scheduler??new eb));if(n.evaluate(e),t?.signal){if(t.signal.aborted)n.unsafeInterrupt();else{let e=()=>n.unsafeInterrupt();t.signal.addEventListener(`abort`,e,{once:!0}),n.addObserver(()=>t.signal.removeEventListener(`abort`,e))}}return n},fb=function(){class e extends globalThis.Error{}return Object.assign(e.prototype,Py,wn,{[Ey]:`Failure`,[Oy](){return By(this)},toString(){return this.message?`${this.name}: ${this.message}`:this.name},toJSON(){return{...this}},[N](){let e=this.stack;return e?`${this.toString()}\n${e.split(`
19
19
  `).slice(1).join(`
20
- `)}`:this.toString()}}),e}(),H_=function(){return class extends V_{constructor(e){super(),e&&Object.assign(this,e)}}}(),U_=e=>{class t extends H_{_tag=e}return t.prototype.name=e,t};U_(`NoSuchElementException`),U_(`TimeoutException`);var W_=class e{scheduleDrain;running=!1;tasks=new G_;constructor(e){this.scheduleDrain=e}starveInternal=e=>{let t=this.tasks.buckets;this.tasks.buckets=[];for(let[e,n]of t)for(let e=0;e<n.length;e++)n[e]();this.tasks.buckets.length===0?this.running=!1:this.starve(e)};starve(e=0){this.scheduleDrain(e,this.starveInternal)}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running||(this.running=!0,this.starve())}static cached(t){let n=new e(t),r=new WeakMap;return i=>{if(i===void 0)return n;let a=r.get(i);return a===void 0&&(a=new e(t),r.set(i,a)),a}}},G_=class{buckets=[];scheduleTask(e,t){let n=this.buckets.length,r,i=0;for(;i<n&&this.buckets[i][0]<=t;i++)r=this.buckets[i];r&&r[0]===t?r[1].push(e):i===n?this.buckets.push([t,[e]]):this.buckets.splice(i,0,[t,[e]])}},K_=class{maxNextTickBeforeTimer;getRunner=W_.cached((e,t)=>{e>=this.maxNextTickBeforeTimer?setTimeout(()=>t(0),0):Promise.resolve(void 0).then(()=>t(e+1))});constructor(e){this.maxNextTickBeforeTimer=e}shouldYield(e){return e.currentOpCount>e.getFiberRef(up)&&e.getFiberRef(lp)}scheduleTask(e,t,n){this.getRunner(n).scheduleTask(e,t)}};const q_=x(Symbol.for(`effect/Scheduler/defaultScheduler`),()=>new K_(2048));var J_=class{tasks=new G_;deferred=!1;scheduleTask(e,t,n){this.deferred?q_.scheduleTask(e,t,n):this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(up)&&e.getFiberRef(lp)}flush(){for(;this.tasks.buckets.length>0;){let e=this.tasks.buckets;this.tasks.buckets=[];for(let[t,n]of e)for(let e=0;e<n.length;e++)n[e]()}this.deferred=!0}};const Y_=x(Symbol.for(`effect/FiberRef/currentScheduler`),()=>np(q_)),X_=x(Symbol.for(`effect/FiberRef/currentRequestMap`),()=>np(new Map)),Z_=(e,t,n,r)=>{switch(e){case void 0:return t();case`unbounded`:return n();case`inherit`:return Qf(hp,e=>e===`unbounded`?n():e>1?r(e):t());default:return e>1?r(e):t()}},Q_=e=>e.replace(/[\s="]/g,`_`),$_=e=>t=>`${Q_(t.label)}=${e-t.startTime}ms`,ev=`effect/MetricLabel`,tv=Symbol.for(ev);var nv=class{key;value;[tv]=tv;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=E(ev+this.key+this.value)}[C](){return this._hash}[O](e){return iv(e)&&this.key===e.key&&this.value===e.value}pipe(){return j(this,arguments)}};const rv=(e,t)=>new nv(e,t),iv=e=>S(e,tv),av=$n(e=>qs(e.context,Sh)?e._tag===`Span`?av(e.parent):P():F(e)),ov=Bp,sv=`InterruptSignal`,cv=`Stateful`,lv=`Resume`,uv=`YieldNow`,dv=e=>({_tag:sv,cause:e}),fv=e=>({_tag:cv,onFiber:e}),pv=e=>({_tag:lv,effect:e}),mv=()=>({_tag:uv}),hv=Symbol.for(`effect/FiberScope`);var gv=class{[hv]=hv;fiberId=al;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}},_v=class{fiberId;parent;[hv]=hv;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell(fv(e=>{e.addChild(t),t.addObserver(()=>{e.removeChild(t)})}))}};const vv=e=>new _v(e.id(),e),yv=x(Symbol.for(`effect/FiberScope/Global`),()=>new gv),bv=Symbol.for(`effect/Fiber`),xv={_E:e=>e,_A:e=>e},Sv={[bv]:xv,pipe(){return j(this,arguments)}},Cv=Symbol.for(`effect/Fiber`),wv=e=>Lf(mf(e.await),e.inheritAll);({...en}),{...Sv};const Tv=`effect/FiberCurrent`,Ev=Symbol.for(`effect/Logger`),Dv={_Message:e=>e,_Output:e=>e},Ov=e=>({[Ev]:Dv,log:e,pipe(){return j(this,arguments)}}),kv=/^[^\s"=]*$/,Av=Ov(((e,t)=>({annotations:n,cause:r,date:i,fiberId:a,logLevel:o,message:s,spans:c})=>{let l=t=>t.match(kv)?t:e(t),u=(e,t)=>`${Q_(e)}=${l(t)}`,d=(e,t)=>` `+u(e,t),f=u(`timestamp`,i.toISOString());f+=d(`level`,o.label),f+=d(`fiber`,rl(a));let p=ur(s);for(let e=0;e<p.length;e++)f+=d(`message`,Ct(p[e],t));zo(r)||(f+=d(`cause`,ls(r,{renderErrorCause:!0})));for(let e of c)f+=` `+$_(i.getTime())(e);for(let[e,r]of n)f+=d(e,Ct(r,t));return f})(e=>`"${e.replace(/\\([\s\S])|(")/g,`\\$1$2`)}"`)),jv={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};jv.gray,jv.blue,jv.green,jv.yellow,jv.red,jv.bgBrightRed,jv.black;const Mv=typeof process==`object`&&process!==null&&typeof process.stdout==`object`&&process.stdout!==null;Mv&&process.stdout.isTTY,Mv||`Deno`in globalThis;const Nv=`effect/MetricBoundaries`,Pv=Symbol.for(Nv);var Fv=class{values;[Pv]=Pv;constructor(e){this.values=e,this._hash=b(E(Nv),T(ft(this.values)))}_hash;[C](){return this._hash}[O](e){return Iv(e)&&k(this.values,e.values)}pipe(){return j(this,arguments)}};const Iv=e=>S(e,Pv),Lv=e=>new Fv(b(e,mr(Fi(1/0)),Zr)),Rv=e=>b(cr(e.count-1,t=>e.start*e.factor**+t),Bi,Lv),zv=Symbol.for(`effect/MetricKeyType`),Bv=`effect/MetricKeyType/Counter`,Vv=Symbol.for(Bv),Hv=Symbol.for(`effect/MetricKeyType/Frequency`),Uv=Symbol.for(`effect/MetricKeyType/Gauge`),Wv=`effect/MetricKeyType/Histogram`,Gv=Symbol.for(Wv),Kv=Symbol.for(`effect/MetricKeyType/Summary`),qv={_In:e=>e,_Out:e=>e};var Jv=class{incremental;bigint;[zv]=qv;[Vv]=Vv;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=E(Bv)}_hash;[C](){return this._hash}[O](e){return Qv(e)}pipe(){return j(this,arguments)}},Yv=class{boundaries;[zv]=qv;[Gv]=Gv;constructor(e){this.boundaries=e,this._hash=b(E(Wv),T(w(this.boundaries)))}_hash;[C](){return this._hash}[O](e){return ty(e)&&k(this.boundaries,e.boundaries)}pipe(){return j(this,arguments)}};const Xv=e=>new Jv(e?.incremental??!1,e?.bigint??!1),Zv=e=>new Yv(e),Qv=e=>S(e,Vv),$v=e=>S(e,Hv),ey=e=>S(e,Uv),ty=e=>S(e,Gv),ny=e=>S(e,Kv),ry=Symbol.for(`effect/MetricKey`),iy={_Type:e=>e},ay=Yr(k);var oy=class{name;keyType;description;tags;[ry]=iy;constructor(e,t,n,r=[]){this.name=e,this.keyType=t,this.description=n,this.tags=r,this._hash=b(E(this.name+this.description),T(w(this.keyType)),T(ft(this.tags)))}_hash;[C](){return this._hash}[O](e){return sy(e)&&this.name===e.name&&k(this.keyType,e.keyType)&&k(this.description,e.description)&&ay(this.tags,e.tags)}pipe(){return j(this,arguments)}};const sy=e=>S(e,ry),cy=(e,t)=>new oy(e,Xv(t),Jn(t?.description)),ly=(e,t,n)=>new oy(e,Zv(t),Jn(n)),uy=v(2,(e,t)=>t.length===0?e:new oy(e.name,e.keyType,e.description,Br(e.tags,t))),dy=Symbol.for(`effect/MutableHashMap`),fy={[dy]:dy,[Symbol.iterator](){return new py(this)},toString(){return St(this.toJSON())},toJSON(){return{_id:`MutableHashMap`,values:Array.from(this).map(gt)}},[A](){return this.toJSON()},pipe(){return j(this,arguments)}};var py=class e{self;referentialIterator;bucketIterator;constructor(e){this.self=e,this.referentialIterator=e.referential[Symbol.iterator]()}next(){if(this.bucketIterator!==void 0)return this.bucketIterator.next();let e=this.referentialIterator.next();return e.done?(this.bucketIterator=new my(this.self.buckets.values()),this.next()):e}[Symbol.iterator](){return new e(this.self)}},my=class{backing;constructor(e){this.backing=e}currentBucket;next(){if(this.currentBucket===void 0){let e=this.backing.next();if(e.done)return e;this.currentBucket=e.value[Symbol.iterator]()}let e=this.currentBucket.next();return e.done?(this.currentBucket=void 0,this.next()):e}};const hy=()=>{let e=Object.create(fy);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e},gy=v(2,(e,t)=>{if(mt(t)===!1)return e.referential.has(t)?F(e.referential.get(t)):P();let n=t[C](),r=e.buckets.get(n);return r===void 0?P():_y(e,r,t)}),_y=(e,t,n,r=!1)=>{for(let i=0,a=t.length;i<a;i++)if(n[O](t[i][0])){let n=t[i][1];return r&&(t.splice(i,1),e.bucketsSize--),F(n)}return P()},vy=v(2,(e,t)=>Un(gy(e,t))),yy=v(3,(e,t,n)=>{if(mt(t)===!1)return e.referential.set(t,n),e;let r=t[C](),i=e.buckets.get(r);return i===void 0?(e.buckets.set(r,[[t,n]]),e.bucketsSize++,e):(by(e,i,t),i.push([t,n]),e.bucketsSize++,e)}),by=(e,t,n)=>{for(let r=0,i=t.length;r<i;r++)if(n[O](t[r][0])){t.splice(r,1),e.bucketsSize--;return}},xy=Symbol.for(`effect/MetricState`),Sy=`effect/MetricState/Counter`,Cy=Symbol.for(Sy),wy=`effect/MetricState/Frequency`,Ty=Symbol.for(wy),Ey=`effect/MetricState/Gauge`,Dy=Symbol.for(Ey),Oy=`effect/MetricState/Histogram`,ky=Symbol.for(Oy),Ay=`effect/MetricState/Summary`,jy=Symbol.for(Ay),My={_A:e=>e};var Ny=class{count;[xy]=My;[Cy]=Cy;constructor(e){this.count=e}[C](){return b(w(Sy),T(w(this.count)),D(this))}[O](e){return Wy(e)&&this.count===e.count}pipe(){return j(this,arguments)}};const Py=Yr(k);var Fy=class{occurrences;[xy]=My;[Ty]=Ty;constructor(e){this.occurrences=e}_hash;[C](){return b(E(wy),T(ft(lr(this.occurrences.entries()))),D(this))}[O](e){return Gy(e)&&Py(lr(this.occurrences.entries()),lr(e.occurrences.entries()))}pipe(){return j(this,arguments)}},Iy=class{value;[xy]=My;[Dy]=Dy;constructor(e){this.value=e}[C](){return b(w(Ey),T(w(this.value)),D(this))}[O](e){return Ky(e)&&this.value===e.value}pipe(){return j(this,arguments)}},Ly=class{buckets;count;min;max;sum;[xy]=My;[ky]=ky;constructor(e,t,n,r,i){this.buckets=e,this.count=t,this.min=n,this.max=r,this.sum=i}[C](){return b(w(Oy),T(w(this.buckets)),T(w(this.count)),T(w(this.min)),T(w(this.max)),T(w(this.sum)),D(this))}[O](e){return qy(e)&&k(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return j(this,arguments)}},Ry=class{error;quantiles;count;min;max;sum;[xy]=My;[jy]=jy;constructor(e,t,n,r,i,a){this.error=e,this.quantiles=t,this.count=n,this.min=r,this.max=i,this.sum=a}[C](){return b(w(Ay),T(w(this.error)),T(w(this.quantiles)),T(w(this.count)),T(w(this.min)),T(w(this.max)),T(w(this.sum)),D(this))}[O](e){return Jy(e)&&this.error===e.error&&k(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return j(this,arguments)}};const zy=e=>new Ny(e),By=e=>new Fy(e),Vy=e=>new Iy(e),Hy=e=>new Ly(e.buckets,e.count,e.min,e.max,e.sum),Uy=e=>new Ry(e.error,e.quantiles,e.count,e.min,e.max,e.sum),Wy=e=>S(e,Cy),Gy=e=>S(e,Ty),Ky=e=>S(e,Dy),qy=e=>S(e,ky),Jy=e=>S(e,jy),Yy=Symbol.for(`effect/MetricHook`),Xy={_In:e=>e,_Out:e=>e},Zy=e=>({[Yy]:Xy,pipe(){return j(this,arguments)},...e}),Qy=BigInt(0),$y=e=>{let t=e.keyType.bigint?Qy:0,n=e.keyType.incremental?e.keyType.bigint?e=>e>=Qy:e=>e>=0:e=>!0,r=e=>{n(e)&&(t+=e)};return Zy({get:()=>zy(t),update:r,modify:r})},eb=e=>{let t=new Map;for(let n of e.keyType.preregisteredWords)t.set(n,0);let n=e=>{let n=t.get(e)??0;t.set(e,n+1)};return Zy({get:()=>By(t),update:n,modify:n})},tb=(e,t)=>{let n=t;return Zy({get:()=>Vy(n),update:e=>{n=e},modify:e=>{n+=e}})},nb=e=>{let t=e.keyType.boundaries.values,n=t.length,r=new Uint32Array(n+1),i=new Float64Array(n),a=0,o=0,s=Number.MAX_VALUE,c=Number.MIN_VALUE;b(t,Mr(Pm),Ur((e,t)=>{i[t]=e}));let l=e=>{let t=0,l=n;for(;t!==l;){let n=Math.floor(t+(l-t)/2);e<=i[n]?l=n:t=n,l===t+1&&(e<=i[t]?l=t:t=l)}r[t]=r[t]+1,a+=1,o+=e,e<s&&(s=e),e>c&&(c=e)},u=()=>{let e=sr(n),t=0;for(let a=0;a<n;a++){let n=i[a],o=r[a];t+=o,e[a]=[n,t]}return e};return Zy({get:()=>Hy({buckets:u(),count:a,min:s,max:c,sum:o}),update:l,modify:l})},rb=e=>{let{error:t,maxAge:n,maxSize:r,quantiles:i}=e.keyType,a=b(i,Mr(Pm)),o=sr(r),s=0,c=0,l=0,u=0,d=0,f=e=>{let i=[],s=0;for(;s!==r-1;){let t=o[s];if(t!=null){let[r,a]=t,o=yc(e-r);Nc(o,hc)&&Mc(o,n)&&i.push(a)}s+=1}return ib(t,a,Mr(i,Pm))},p=(e,t)=>{if(r>0){s+=1;let n=s%r;o[n]=[t,e]}u=c===0?e:Math.min(u,e),d=c===0?e:Math.max(d,e),c+=1,l+=e};return Zy({get:()=>Uy({error:t,quantiles:f(Date.now()),count:c,min:u,max:d,sum:l}),update:([e,t])=>p(e,t),modify:([e,t])=>p(e,t)})},ib=(e,t,n)=>{let r=n.length;if(!vr(t))return Vr();let i=t[0],a=t.slice(1),o=ab(e,r,P(),0,i,n),s=Hr(o);return a.forEach(t=>{s.push(ab(e,r,o.value,o.consumed,t,o.rest))}),Ur(s,e=>[e.quantile,e.value])},ab=(e,t,n,r,i,a)=>{let o=e,s=t,c=n,l=r,u=i,d=a,f=e,p=t,m=n,h=r,g=i,_=a;for(;;){if(!vr(d))return{quantile:u,value:P(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:F(Er(d)),consumed:l+d.length,rest:[]};let e=wr(d),t=kr(d,t=>t===e),n=u*s,r=o/2*n,i=l+t[0].length,a=Math.abs(i-n);if(i<n-r){f=o,p=s,m=Cr(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue}if(i>n+r){let t=Hn(c)?F(e):c;return{quantile:u,value:t,consumed:l,rest:d}}switch(c._tag){case`None`:f=o,p=s,m=Cr(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue;case`Some`:if(a<Math.abs(n-c.value)){f=o,p=s,m=Cr(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue}return{quantile:u,value:F(c.value),consumed:l,rest:d}}}throw Error(`BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues`)},ob=Symbol.for(`effect/MetricPair`),sb={_Type:e=>e},cb=(e,t)=>({[ob]:sb,metricKey:e,metricState:t,pipe(){return j(this,arguments)}}),lb=Symbol.for(`effect/MetricRegistry`);var ub=class{[lb]=lb;map=hy();snapshot(){let e=[];for(let[t,n]of this.map)e.push(cb(t,n.get()));return e}get(e){let t=b(this.map,gy(e),Yn);if(t==null){if(Qv(e.keyType))return this.getCounter(e);if(ey(e.keyType))return this.getGauge(e);if($v(e.keyType))return this.getFrequency(e);if(ty(e.keyType))return this.getHistogram(e);if(ny(e.keyType))return this.getSummary(e);throw Error(`BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues`)}return t}getCounter(e){let t=b(this.map,gy(e),Yn);if(t==null){let n=$y(e);b(this.map,vy(e))||b(this.map,yy(e,n)),t=n}return t}getFrequency(e){let t=b(this.map,gy(e),Yn);if(t==null){let n=eb(e);b(this.map,vy(e))||b(this.map,yy(e,n)),t=n}return t}getGauge(e){let t=b(this.map,gy(e),Yn);if(t==null){let n=tb(e,e.keyType.bigint?BigInt(0):0);b(this.map,vy(e))||b(this.map,yy(e,n)),t=n}return t}getHistogram(e){let t=b(this.map,gy(e),Yn);if(t==null){let n=nb(e);b(this.map,vy(e))||b(this.map,yy(e,n)),t=n}return t}getSummary(e){let t=b(this.map,gy(e),Yn);if(t==null){let n=rb(e);b(this.map,vy(e))||b(this.map,yy(e,n)),t=n}return t}};const db=()=>new ub,fb=Symbol.for(`effect/Metric`),pb={_Type:e=>e,_In:e=>e,_Out:e=>e},mb=x(Symbol.for(`effect/Metric/globalMetricRegistry`),()=>db()),hb=function(e,t,n,r){let i=Object.assign(e=>Of(e,e=>xb(i,e)),{[fb]:pb,keyType:e,unsafeUpdate:t,unsafeValue:n,unsafeModify:r,register(){return this.unsafeValue([]),this},pipe(){return j(this,arguments)}});return i},gb=(e,t)=>_b(cy(e,t)),_b=e=>{let t,n=new WeakMap,r=r=>{if(r.length===0)return t===void 0&&(t=mb.get(e)),t;let i=n.get(r);return i===void 0?(i=mb.get(uy(e,r)),n.set(r,i),i):i};return hb(e.keyType,(e,t)=>r(t).update(e),e=>r(e).get(),(e,t)=>r(t).modify(e))},vb=(e,t,n)=>_b(ly(e,t,n)),yb=v(3,(e,t,n)=>bb(e,[rv(t,n)])),bb=v(2,(e,t)=>hb(e.keyType,(n,r)=>e.unsafeUpdate(n,Br(t,r)),n=>e.unsafeValue(Br(t,n)),(n,r)=>e.unsafeModify(n,Br(t,r)))),xb=v(2,(e,t)=>Qf(yp,n=>L(()=>e.unsafeUpdate(t,n))));({...$t});const Sb=v(2,(e,t)=>Qf(X_,n=>L(()=>{if(n.has(e)){let r=n.get(e);r.state.completed||(r.state.completed=!0,tm(r.result,t))}}))),Cb=Symbol.for(`effect/Supervisor`),wb={_T:e=>e};var Tb=class e{underlying;value0;[Cb]=wb;constructor(e,t){this.underlying=e,this.value0=t}get value(){return this.value0}onStart(e,t,n,r){this.underlying.onStart(e,t,n,r)}onEnd(e,t){this.underlying.onEnd(e,t)}onEffect(e,t){this.underlying.onEffect(e,t)}onSuspend(e){this.underlying.onSuspend(e)}onResume(e){this.underlying.onResume(e)}map(t){return new e(this,b(this.value,xf(t)))}zip(e){return new Eb(this,e)}},Eb=class e{left;right;_tag=`Zip`;[Cb]=wb;constructor(e,t){this.left=e,this.right=t}get value(){return If(this.left.value,this.right.value)}onStart(e,t,n,r){this.left.onStart(e,t,n,r),this.right.onStart(e,t,n,r)}onEnd(e,t){this.left.onEnd(e,t),this.right.onEnd(e,t)}onEffect(e,t){this.left.onEffect(e,t),this.right.onEffect(e,t)}onSuspend(e){this.left.onSuspend(e),this.right.onSuspend(e)}onResume(e){this.left.onResume(e),this.right.onResume(e)}map(e){return new Tb(this,b(this.value,xf(e)))}zip(t){return new e(this,t)}};const Db=e=>S(e,Cb)&&Be(e,`Zip`);var Ob=class{effect;[Cb]=wb;constructor(e){this.effect=e}get value(){return this.effect}onStart(e,t,n,r){}onEnd(e,t){}onEffect(e,t){}onSuspend(e){}onResume(e){}map(e){return new Tb(this,b(this.value,xf(e)))}zip(e){return new Eb(this,e)}onRun(e,t){return e()}};const kb=e=>new Ob(e),Ab=x(`effect/Supervisor/none`,()=>kb(Mf)),jb=Nu,Mb=`Empty`,Nb=`AddSupervisor`,Pb=`RemoveSupervisor`,Fb=`AndThen`,Ib={_tag:Mb},Lb=(e,t)=>({_tag:Fb,first:e,second:t}),Rb=(e,t)=>zb(t,Fi(e)),zb=(e,t)=>{let n=e,r=t;for(;Ji(r);){let e=Xi(r);switch(e._tag){case Mb:r=Zi(r);break;case Nb:n=n.zip(e.supervisor),r=Zi(r);break;case Pb:n=Bb(n,e.supervisor),r=Zi(r);break;case Fb:r=Wi(e.first)(Wi(e.second)(Zi(r)))}}return n},Bb=(e,t)=>k(e,t)?Ab:Db(e)?Bb(e.left,t).zip(Bb(e.right,t)):e,Vb=e=>k(e,Ab)?po():Db(e)?b(Vb(e.left),xo(Vb(e.right))):ho(e),Hb=jb({empty:Ib,patch:Rb,combine:Lb,diff:(e,t)=>{if(k(e,t))return Ib;let n=Vb(e),r=Vb(t),i=b(r,bo(n),So(Ib,(e,t)=>Lb(e,{_tag:Nb,supervisor:t}))),a=b(n,bo(r),So(Ib,(e,t)=>Lb(e,{_tag:Pb,supervisor:t})));return Lb(i,a)}}),Ub=gb(`effect_fiber_started`,{incremental:!0}),Wb=gb(`effect_fiber_active`),Gb=gb(`effect_fiber_successes`,{incremental:!0}),Kb=gb(`effect_fiber_failures`,{incremental:!0}),qb=yb(vb(`effect_fiber_lifetimes`,Rv({start:.5,factor:2,count:35})),`time_unit`,`milliseconds`),Jb=`Continue`,Yb=`Yield`,Xb={_E:e=>e,_A:e=>e},Zb=e=>{throw Error(`BUG: FiberRuntime - ${Ct(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},Qb=Symbol.for(`effect/internal/fiberRuntime/YieldedOp`),$b=x(`effect/internal/fiberRuntime/yieldedOpChannel`,()=>({currentOp:null})),ex={[Pt]:(e,t,n)=>it(()=>t.effect_instruction_i1(n)),OnStep:(e,t,n)=>Yp(Yp(n)),[Ft]:(e,t,n)=>it(()=>t.effect_instruction_i2(n)),[Ut]:(e,t,n)=>(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),Xu(e.currentRuntimeFlags)&&e.isInterrupted()?R(e.getInterruptedCause()):Yp(n)),[zt]:(e,t,n)=>(it(()=>t.effect_instruction_i2(n)),it(()=>t.effect_instruction_i0())?(e.pushStack(t),it(()=>t.effect_instruction_i1())):Mf),[Bt]:(e,t,n)=>{for(;;){let r=it(()=>t.effect_instruction_i0.next(n));if(r.done)return Yp(r.value);let i=tt(r.value);if(!zp(i))return e.pushStack(t),i;if(i._tag===`Failure`)return i;n=i.value}}},tx={[sv]:(e,t,n,r)=>(e.processNewInterruptSignal(r.cause),Xu(t)?R(r.cause):n),[lv]:(e,t,n,r)=>{throw Error(`It is illegal to have multiple concurrent run loops in a single fiber`)},[cv]:(e,t,n,r)=>(r.onFiber(e,Eg(t)),n),[uv]:(e,t,n,r)=>I(Ff(),()=>n)},nx=e=>yf(dd(e),e=>fx(kd(e),([e,t])=>{let n=new Map,r=[];for(let e of t){r.push(Ri(e));for(let t of e)n.set(t.request,t)}let i=r.flat();return tp(Mx(e.runAll(r),i,()=>i.forEach(e=>{e.listeners.interrupted=!0})),X_,n)},!1,!1)),rx=Wt();var ix=class extends kh{[bv]=xv;[Cv]=Xb;_fiberRefs;_fiberId;_queue=[];_children=null;_observers=[];_running=!1;_stack=[];_asyncInterruptor=null;_asyncBlockingOn=null;_exitValue=null;_steps=[];_isYielding=!1;currentRuntimeFlags;currentOpCount=0;currentSupervisor;currentScheduler;currentTracer;currentSpan;currentContext;currentDefaultServices;constructor(e,t,n){if(super(),this.currentRuntimeFlags=n,this._fiberId=e,this._fiberRefs=t,td(n)){let e=this.getFiberRef(yp);Ub.unsafeUpdate(1,e),Wb.unsafeUpdate(1,e)}this.refreshRefCache()}commit(){return wv(this)}id(){return this._fiberId}resume(e){this.tell(pv(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>Og(t)?e.currentRuntimeFlags:t.runtimeFlags)}scope(){return vv(this)}get children(){return this.ask(e=>Array.from(e.getChildren()))}getChildren(){return this._children===null&&(this._children=new Set),this._children}getInterruptedCause(){return this.getFiberRef(xp)}fiberRefs(){return this.ask(e=>e.getFiberRefs())}ask(e){return Df(()=>{let t=$p(this._fiberId);return this.tell(fv((n,r)=>{tm(t,L(()=>e(n,r)))})),em(t)})}tell(e){this._queue.push(e),this._running||(this._running=!0,this.drainQueueLaterOnExecutor())}get await(){return Qd(e=>{let t=t=>e(Ef(t));if(this._exitValue!==null){t(this._exitValue);return}return this.tell(fv((e,n)=>{e._exitValue===null?e.addObserver(t):t(this._exitValue)})),L(()=>this.tell(fv((e,n)=>{e.removeObserver(t)})))},this.id())}get inheritAll(){return Gd((e,t)=>{let n=e.id(),r=e.getFiberRefs(),i=t.runtimeFlags,a=this.getFiberRefs(),o=Gh(r,n,a);e.setFiberRefs(o);let s=e.getFiberRef(kx),c=b(rd(i,s),cd(1),cd(16));return Nf(c)})}get poll(){return L(()=>Jn(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return L(()=>this.tell(dv(Fo(e))))}unsafeInterruptAsFork(e){this.tell(dv(Fo(e)))}addObserver(e){this._exitValue===null?this._observers.push(e):e(this._exitValue)}removeObserver(e){this._observers=this._observers.filter(t=>t!==e)}getFiberRefs(){return this.setFiberRef(kx,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=Jh(this._fiberRefs,e)}getFiberRef(e){return this._fiberRefs.locals.has(e)?this._fiberRefs.locals.get(e)[0][1]:e.initial}setFiberRef(e,t){this._fiberRefs=Zh(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(wh),this.currentTracer=this.currentDefaultServices.unsafeMap.get(_h.key),this.currentSupervisor=this.getFiberRef(Ax),this.currentScheduler=this.getFiberRef(Y_),this.currentContext=this.getFiberRef(cp),this.currentSpan=this.currentContext.unsafeMap.get(vh.key)}setFiberRefs(e){this._fiberRefs=e,this.refreshRefCache()}addChild(e){this.getChildren().add(e)}removeChild(e){this.getChildren().delete(e)}transferChildren(e){let t=this._children;if(this._children=null,t!==null&&t.size>0)for(let n of t)n._exitValue===null&&e.add(this.currentRuntimeFlags,n)}drainQueueOnCurrentThread(){let e=!0;for(;e;){let t=Jb,n=globalThis[Tv];globalThis[Tv]=this;try{for(;t===Jb;)t=this._queue.length===0?`Done`:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[Tv]=n}this._queue.length>0&&!this._running?(this._running=!0,t===Yb?(this.drainQueueLaterOnExecutor(),e=!1):e=!0):e=!1}}drainQueueLaterOnExecutor(){this.currentScheduler.scheduleTask(this.run,this.getFiberRef(lp),this)}drainQueueWhileRunning(e,t){let n=t;for(;this._queue.length>0;){let t=this._queue.splice(0,1)[0];n=tx[t._tag](this,e,n,t)}return n}isInterrupted(){return!Vo(this.getFiberRef(xp))}addInterruptedCause(e){let t=this.getFiberRef(xp);this.setFiberRef(xp,Lo(t,e))}processNewInterruptSignal(e){this.addInterruptedCause(e),this.sendInterruptSignalToAllChildren()}sendInterruptSignalToAllChildren(){if(this._children===null||this._children.size===0)return!1;let e=!1;for(let t of this._children)t.tell(dv(Fo(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return Pf({while:()=>!t,body:()=>{let n=e.next();return n.done?L(()=>{t=!0}):Jd(n.value.await)},step:()=>{}})}return null}reportExitValue(e){if(td(this.currentRuntimeFlags)){let t=this.getFiberRef(yp),n=this.id().startTimeMillis,r=Date.now();switch(qb.unsafeUpdate(r-n,t),Wb.unsafeUpdate(-1,t),e._tag){case It:Gb.unsafeUpdate(1,t);break;case Mt:Kb.unsafeUpdate(1,t)}}if(e._tag===`Failure`){let t=this.getFiberRef(_p);!Uo(e.cause)&&t._tag===`Some`&&this.log(`Fiber terminated with an unhandled error`,e.cause,t)}}setExitValue(e){this._exitValue=e,this.reportExitValue(e);for(let t=this._observers.length-1;t>=0;t--)this._observers[t](e);this._observers=[]}getLoggers(){return this.getFiberRef(lx)}log(e,t,n){let r=Un(n)?n.value:this.getFiberRef(fp),i=this.getFiberRef(ax);if(Lg(i,r))return;let a=this.getFiberRef(pp),o=this.getFiberRef(dp),s=this.getLoggers(),c=this.getFiberRefs();if(_o(s)>0){let n=qs(this.getFiberRef(wh),Dm),i=new Date(n.unsafeCurrentTimeMillis());Ot(c,()=>{for(let n of s)n.log({fiberId:this.id(),logLevel:r,message:e,cause:t,context:c,spans:a,annotations:o,date:i})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case uv:return Yb;case sv:return this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null&&(this._asyncInterruptor(R(e.cause)),this._asyncInterruptor=null),Jb;case lv:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),Jb;case cv:return e.onFiber(this,this._exitValue===null?Dg(this.currentRuntimeFlags,this._asyncBlockingOn):Tg),Jb;default:return Zb(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=Xu(this.currentRuntimeFlags)&&this.isInterrupted()?R(this.getInterruptedCause()):e;for(;t!==null;){let e=t,n=this.runLoop(e);if(n===Qb){let e=$b.currentOp;$b.currentOp=null,e._op===`Yield`?Ju(this.currentRuntimeFlags)?(this.tell(mv()),this.tell(pv(Xp)),t=null):t=Xp:e._op===`Async`&&(t=null)}else{this.currentRuntimeFlags=b(this.currentRuntimeFlags,Yu(16));let e=this.interruptAllChildren();e===null?(this._queue.length===0?this.setExitValue(n):this.tell(pv(n)),t=null):t=I(e,()=>n)}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(this._running)this.tell(pv(e));else{this._running=!0;let t=globalThis[Tv];globalThis[Tv]=this;try{this.evaluateEffect(e)}finally{this._running=!1,globalThis[Tv]=t,this._queue.length>0&&this.drainQueueLaterOnExecutor()}}}startFork(e){this.tell(pv(e))}patchRuntimeFlags(e,t){let n=id(e,t);return globalThis[Tv]=this,this.currentRuntimeFlags=n,n}initiateAsync(e,t){let n=!1,r=e=>{n||(n=!0,this.tell(pv(e)))};Xu(e)&&(this._asyncInterruptor=r);try{t(r)}catch(e){r(lf(Po(e)))}}pushStack(e){this._stack.push(e),e._op===`OnStep`&&this._steps.push({refs:this.getFiberRefs(),flags:this.currentRuntimeFlags})}popStack(){let e=this._stack.pop();if(e)return e._op===`OnStep`&&this._steps.pop(),e}getNextSuccessCont(){let e=this.popStack();for(;e;){if(e._op!==`OnFailure`)return e;e=this.popStack()}}getNextFailCont(){let e=this.popStack();for(;e;){if(e._op!==`OnSuccess`&&e._op!==`While`&&e._op!==`Iterator`)return e;e=this.popStack()}}Tag(e){return L(()=>Js(this.currentContext,e))}Left(e){return sf(e.left)}None(e){return sf(new Ip)}Right(e){return Yp(e.right)}Some(e){return Yp(e.value)}Micro(e){return Xd(t=>{let n=t,r=B_(j_(e,this.currentContext));return r.addObserver(e=>{if(e._tag===`Success`)return n(Yp(e.value));switch(e.cause._tag){case`Interrupt`:return n(R(Fo(al)));case`Fail`:return n(sf(e.cause.error));case`Die`:return n(nf(e.cause.defect))}}),Xd(e=>{n=t=>{e(Mf)},r.unsafeInterrupt()})})}[Lt](e){let t=it(()=>e.effect_instruction_i0()),n=this.getNextSuccessCont();return n===void 0?($b.currentOp=Yp(t),Qb):(n._op in ex||Zb(n),ex[n._op](this,n,t))}[It](e){let t=e,n=this.getNextSuccessCont();return n===void 0?($b.currentOp=t,Qb):(n._op in ex||Zb(n),ex[n._op](this,n,t.effect_instruction_i0))}[Mt](e){let t=e.effect_instruction_i0,n=this.getNextFailCont();if(n!==void 0)switch(n._op){case Nt:case Ft:return Xu(this.currentRuntimeFlags)&&this.isInterrupted()?R(Xo(t)):it(()=>n.effect_instruction_i1(t));case`OnStep`:return Xu(this.currentRuntimeFlags)&&this.isInterrupted()?R(Xo(t)):Yp(R(t));case Ut:return this.patchRuntimeFlags(this.currentRuntimeFlags,n.patch),Xu(this.currentRuntimeFlags)&&this.isInterrupted()?R(Lo(t,this.getInterruptedCause())):R(t);default:Zb(n)}else return $b.currentOp=R(t),Qb}[Vt](e){return it(()=>e.effect_instruction_i0(this,Eg(this.currentRuntimeFlags)))}Blocked(e){let t=this.getFiberRefs(),n=this.currentRuntimeFlags;if(this._steps.length>0){let r=[],i=this._steps[this._steps.length-1],a=this.popStack();for(;a&&a._op!==`OnStep`;)r.push(a),a=this.popStack();this.setFiberRefs(i.refs),this.currentRuntimeFlags=i.flags;let o=dg(i.refs,t),s=rd(i.flags,n);return Yp(Ld(e.effect_instruction_i0,Gd(t=>{for(;r.length>0;)t.pushStack(r.pop());return t.setFiberRefs(fg(t.id(),t.getFiberRefs())(o)),t.currentRuntimeFlags=id(s)(t.currentRuntimeFlags),e.effect_instruction_i1})))}return jf(t=>I(mx(Rd(e.effect_instruction_i0)),()=>t(e.effect_instruction_i1)))}RunBlocked(e){return nx(e.effect_instruction_i0)}[Rt](e){let t=e.effect_instruction_i0,n=this.currentRuntimeFlags,r=id(n,t);if(Xu(r)&&this.isInterrupted())return R(this.getInterruptedCause());if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let t=rd(r,n);return this.pushStack(new Bd(t,e)),it(()=>e.effect_instruction_i1(n))}return Xp}[Pt](e){return this.pushStack(e),e.effect_instruction_i0}OnStep(e){return this.pushStack(e),e.effect_instruction_i0}[Nt](e){return this.pushStack(e),e.effect_instruction_i0}[Ft](e){return this.pushStack(e),e.effect_instruction_i0}[At](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),$b.currentOp=e,Qb}[Ht](e){return this._isYielding=!1,$b.currentOp=e,Qb}[zt](e){let t=e.effect_instruction_i0,n=e.effect_instruction_i1;return t()?(this.pushStack(e),n()):Xp}[Bt](e){return ex[Bt](this,e,void 0)}[jt](e){return it(()=>e.commit())}runLoop(e){let t=e;for(this.currentOpCount=0;;){if(this.currentRuntimeFlags&2&&this.currentSupervisor.onEffect(this,t),this._queue.length>0&&(t=this.drainQueueWhileRunning(this.currentRuntimeFlags,t)),!this._isYielding){this.currentOpCount+=1;let e=this.currentScheduler.shouldYield(this);if(e!==!1){this._isYielding=!0,this.currentOpCount=0;let n=t;t=I(Ff({priority:e}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(rx!==t[zd]._V){let e=this.getFiberRef(vp);if(e._tag===`Some`){let n=t[zd]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${Wt()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`,Mo,e)}}return this[t._op](t)},this),t===Qb){let e=$b.currentOp;return e._op===`Yield`||e._op===`Async`?Qb:($b.currentOp=null,e._op===`Success`||e._op===`Failure`?e:R(Po(e)))}}catch(e){t=t!==Qb&&!S(t,`_op`)||!(t._op in this)?rf(`Not a valid effect: ${Ct(t)}`):Mp(e)?R(Lo(Po(e),Fo(al))):nf(e)}}}run=()=>{this.drainQueueOnCurrentThread()}};const ax=x(`effect/FiberRef/currentMinimumLogLevel`,()=>np(Rg(`Info`))),ox=e=>Ov(t=>{let n=eg(t.context,wh);qs(n,sh).unsafe.log(e.log(t))}),sx=x(Symbol.for(`effect/Logger/defaultLogger`),()=>ox(Av)),cx=x(Symbol.for(`effect/Logger/tracerLogger`),()=>Ov(({annotations:e,cause:t,context:n,fiberId:r,logLevel:i,message:a})=>{let o=av(Ys(Xh(n,cp),vh));if(o._tag===`None`||o.value._tag===`ExternalSpan`)return;let s=Js(Xh(n,wh),Dm),c={};for(let[t,n]of e)c[t]=n;c[`effect.fiberId`]=ll(r),c[`effect.logLevel`]=i.label,t!==null&&t._tag!==`Empty`&&(c[`effect.cause`]=ls(t,{renderErrorCause:!0})),o.value.event(Ct(Array.isArray(a)&&a.length===1?a[0]:a),s.unsafeCurrentTimeNanos(),c)})),lx=x(Symbol.for(`effect/FiberRef/currentLoggers`),()=>rp(ho(sx,cx))),ux=v(e=>Ge(e[0]),(e,t,n)=>Gd(r=>{let i=n?.batching===!0||n?.batching===`inherit`&&r.getFiberRef(gp);return n?.discard?Z_(n.concurrency,()=>xx(Lh,n?.concurrentFinalizers)(n=>i?fx(e,(e,r)=>n(t(e,r)),!0,!1,1):yf(e,(e,r)=>n(t(e,r)))),()=>xx(Rh,n?.concurrentFinalizers)(n=>fx(e,(e,r)=>n(t(e,r)),i,!1)),r=>xx(zh(r),n?.concurrentFinalizers)(n=>fx(e,(e,r)=>n(t(e,r)),i,!1,r))):Z_(n?.concurrency,()=>xx(Lh,n?.concurrentFinalizers)(n=>i?px(e,1,(e,r)=>n(t(e,r)),!0):vf(e,(e,r)=>n(t(e,r)))),()=>xx(Rh,n?.concurrentFinalizers)(n=>dx(e,(e,r)=>n(t(e,r)),i)),r=>xx(zh(r),n?.concurrentFinalizers)(n=>px(e,r,(e,r)=>n(t(e,r)),i)))})),dx=(e,t,n)=>Df(()=>{let r=lr(e),i=Array(r.length);return Rf(fx(r,(e,n)=>I(t(e,n),e=>L(()=>i[n]=e)),n,!1),Ef(i))}),fx=(e,t,n,r,i)=>jf(a=>kf(o=>Gd(s=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return Mf;let u=0,d=!1,f=i?Math.min(c.length,i):c.length,p=new Set,m=[],h=()=>p.forEach(e=>{e.currentScheduler.scheduleTask(()=>{e.unsafeInterruptAsFork(s.id())},0,e)}),g=[],_=[],ee=[],te=()=>{let e=m.filter(({exit:e})=>e._tag===`Failure`).sort((e,t)=>e.index<t.index?-1:e.index===t.index?0:1).map(({exit:e})=>e);return e.length===0&&e.push(Xp),e},ne=(e,t=!1)=>{let n=Af(o(e)),r=gx(n,s,s.currentRuntimeFlags,yv);return s.currentScheduler.scheduleTask(()=>{t&&r.unsafeInterruptAsFork(s.id()),r.resume(n)},0,r),r},re=()=>{r||(l-=c.length,c=[]),d=!0,h()},ie=n?pf:of,ae=ne(Qd(e=>{let r=(e,t)=>{e._op===`Blocked`?ee.push(e):(m.push({index:t,exit:e}),e._op===`Failure`&&!d&&re())},o=()=>{if(c.length>0){let f=c.pop(),h=u++,re=()=>{let e=c.pop();return h=u++,I(Ff(),()=>I(ie(a(t(e,h))),ae))},ae=e=>c.length>0&&(r(e,h),c.length>0)?re():Ef(e),oe=I(ie(a(t(f,h))),ae),se=ne(oe);g.push(se),p.add(se),d&&se.currentScheduler.scheduleTask(()=>{se.unsafeInterruptAsFork(s.id())},0,se),se.addObserver(t=>{let a;if(a=t._op===`Failure`?t:t.effect_instruction_i0,_.push(se),p.delete(se),r(a,h),m.length===l)e(Ef(Gn(Up(te(),{parallel:!0}),()=>Xp)));else if(ee.length+m.length===l){let t=te(),r=ee.map(e=>e.effect_instruction_i0).reduce(ld);e(Ef(Ld(r,fx([Gn(Up(t,{parallel:!0}),()=>Xp),...ee.map(e=>e.effect_instruction_i1)],e=>e,n,!0,i))))}else o()})}};for(let e=0;e<f;e++)o()}));return Jd(wf(mf(a(wv(ae))),Jp({onFailure:e=>{re();let t=ee.length+1,n=Math.min(typeof i==`number`?i:ee.length,ee.length),r=Array.from(ee);return Qd(i=>{let a=[],o=0,s=0,c=(n,s)=>c=>{a[n]=c,o++,o===t&&i(Yp(R(e))),r.length>0&&s&&l()},l=()=>{ne(r.pop(),!0).addObserver(c(s,!0)),s++};ae.addObserver(c(s,!1)),s++;for(let e=0;e<n;e++)l()})},onSuccess:()=>vf(_,e=>e.inheritAll)})))}))),px=(e,t,n,r)=>Df(()=>{let i=lr(e),a=Array(i.length);return Rf(fx(i,(e,t)=>xf(n(e,t),e=>a[t]=e),r,!1,t),Ef(a))}),mx=e=>vx(e,yv),hx=(e,t,n,r=null)=>{let i=_x(e,t,n,r);return i.resume(e),i},gx=(e,t,n,r=null)=>_x(e,t,n,r),_x=(e,t,n,r=null)=>{let i=ul(),a=t.getFiberRefs(),o=Kh(a,i),s=new ix(i,o,n),c=Xh(o,cp),l=s.currentSupervisor;return l.onStart(c,e,F(t),s),s.addObserver(e=>l.onEnd(e,s)),(r===null?b(t.getFiberRef(bp),Gn(()=>t.scope())):r).add(n,s),s},vx=(e,t)=>Gd((n,r)=>Ef(hx(e,n,r.runtimeFlags,t))),yx=e=>am(t=>Wn(Ys(t,Cx),{onNone:()=>e,onSome:t=>{switch(t.strategy._tag){case`Parallel`:return e;case`Sequential`:case`ParallelN`:return I(Ep(t,Rh),t=>Dx(e,t))}}})),bx=e=>t=>am(n=>Wn(Ys(n,Cx),{onNone:()=>t,onSome:n=>n.strategy._tag===`ParallelN`&&n.strategy.parallelism===e?t:I(Ep(n,zh(e)),e=>Dx(t,e))})),xx=(e,t)=>n=>am(r=>Wn(Ys(r,Cx),{onNone:()=>n(y),onSome:r=>{if(t===!0){let t=e._tag===`Parallel`?yx:e._tag===`Sequential`?Sx:bx(e.parallelism);switch(r.strategy._tag){case`Parallel`:return t(n(yx));case`Sequential`:return t(n(Sx));case`ParallelN`:return t(n(bx(r.strategy.parallelism)))}}else return n(y)}})),Sx=e=>am(t=>Wn(Ys(t,Cx),{onNone:()=>e,onSome:t=>{switch(t.strategy._tag){case`Sequential`:return e;case`Parallel`:case`ParallelN`:return I(Ep(t,Lh),t=>Dx(e,t))}}})),Cx=Us(`effect/Scope`),wx=(e,t)=>{e.state._tag===`Open`&&e.state.finalizers.set({},t)},Tx={[Sp]:Sp,[Cp]:Cp,pipe(){return j(this,arguments)},fork(e){return L(()=>{let t=Ex(e);if(this.state._tag===`Closed`)return t.state=this.state,t;let n={};return this.state.finalizers.set(n,e=>t.close(e)),wx(t,e=>L(()=>{this.state._tag===`Open`&&this.state.finalizers.delete(n)})),t})},close(e){return Df(()=>{if(this.state._tag===`Closed`)return Mf;let t=Array.from(this.state.finalizers.values()).reverse();return this.state={_tag:`Closed`,exit:e},t.length===0?Mf:Fh(this.strategy)?b(vf(t,t=>of(t(e))),I(e=>b(Up(e),Qn(Hp),Gn(()=>Xp)))):Ih(this.strategy)?b(dx(t,t=>of(t(e)),!1),I(e=>b(Up(e,{parallel:!0}),Qn(Hp),Gn(()=>Xp)))):b(px(t,this.strategy.parallelism,t=>of(t(e)),!1),I(e=>b(Up(e,{parallel:!0}),Qn(Hp),Gn(()=>Xp))))})},addFinalizer(e){return Df(()=>this.state._tag===`Closed`?e(this.state.exit):(this.state.finalizers.set({},e),Mf))}},Ex=(e=Mh)=>{let t=Object.create(Tx);return t.strategy=e,t.state={_tag:`Open`,finalizers:new Map},t},Dx=v(2,(e,t)=>sm(e,Xs(Gs(Cx,t)))),Ox=e=>op(e,{differ:Hb,fork:Ib}),kx=sp(ed),Ax=Ox(Ab),jx=v(2,(e,t)=>jf(n=>gf(n(e),{onFailure:e=>gf(t,{onFailure:t=>lf(Lo(e,t)),onSuccess:()=>lf(e)}),onSuccess:e=>qd(t,e)}))),Mx=(e,t,n)=>ff(r=>jx(I(mx(bf(e)),e=>Qd(r=>{let i=t.map(e=>e.listeners.count),a=()=>{i.every(e=>e===0)&&t.every(e=>e.result.state.current._tag===`Pending`||!!(e.result.state.current._tag===`Done`&&zp(e.result.state.current.effect)&&e.result.state.current.effect._tag===`Failure`&&Ho(e.result.state.current.effect.cause)))&&(o.forEach(e=>e()),n?.(),r(zf(e)))};e.addObserver(e=>{o.forEach(e=>e()),r(e)});let o=t.map((e,t)=>{let n=e=>{i[t]=e,a()};return e.listeners.addObserver(n),()=>e.listeners.removeObserver(n)});return a(),L(()=>{o.forEach(e=>e())})})),Df(()=>{let e=t.flatMap(e=>e.state.completed?[]:[e]);return yf(e,e=>Sb(e.request,Kp(r)))}))),Nx=Tp,Px=Ep,Fx=e=>function(){if(arguments.length===1){let t=arguments[0];return(n,...r)=>e(t,n,...r)}return e.apply(this,arguments)},Ix=Fx((e,t,n)=>{let r=ul(),i=[[cp,[[r,e.context]]]];n?.scheduler&&i.push([Y_,[[r,n.scheduler]]]);let a=tg(e.fiberRefs,{entries:i,forkAs:r});n?.updateRefs&&(a=n.updateRefs(a,r));let o=new ix(r,a,e.runtimeFlags),s=t;n?.scope&&(s=I(Px(n.scope,Mh),e=>Rf(wp(e,ff(e=>k(e,o.id())?Mf:Bf(o,e))),wf(t,t=>Nx(e,t)))));let c=o.currentSupervisor;return c!==Ab&&(c.onStart(e.context,s,P(),o),o.addObserver(e=>c.onEnd(e,o))),yv.add(e.runtimeFlags,o),n?.immediate===!1?o.resume(s):o.start(s),o}),Lx=Fx((e,t)=>{let n=Gx(e)(t);if(n._tag===`Failure`)throw Ux(n.effect_instruction_i0);return n.effect_instruction_i0});var Rx=class extends Error{fiber;_tag=`AsyncFiberException`;constructor(e){super(`Fiber #${e.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`),this.fiber=e,this.name=this._tag,this.stack=this.message}};const zx=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let n=new Rx(e);return Error.stackTraceLimit=t,n},Bx=Symbol.for(`effect/Runtime/FiberFailure`),Vx=Symbol.for(`effect/Runtime/FiberFailure/Cause`);var Hx=class extends Error{[Bx];[Vx];constructor(e){let t=_s(e)[0];super(t?.message||`An error has occurred`),this[Bx]=Bx,this[Vx]=e,this.name=t?`(FiberFailure) ${t.name}`:`FiberFailure`,t?.stack&&(this.stack=t.stack)}toJSON(){return{_id:`FiberFailure`,cause:this[Vx].toJSON()}}toString(){return`(FiberFailure) `+ls(this[Vx],{renderErrorCause:!0})}[A](){return this.toString()}};const Ux=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let n=new Hx(e);return Error.stackTraceLimit=t,n},Wx=e=>{let t=e;switch(t._op){case`Failure`:case`Success`:return t;case`Left`:return Gp(t.left);case`Right`:return Yp(t.right);case`Some`:return Yp(t.value);case`None`:return Gp(new Ip)}},Gx=Fx((e,t)=>{let n=Wx(t);if(n)return n;let r=new J_,i=Ix(e)(t,{scheduler:r});return r.flush(),i.unsafePoll()||Wp(tf(zx(i),cm(i)))});var Kx=class{context;runtimeFlags;fiberRefs;constructor(e,t,n){this.context=e,this.runtimeFlags=t,this.fiberRefs=n}pipe(){return j(this,arguments)}};const qx=(e=>new Kx(e.context,e.runtimeFlags,e.fiberRefs))({context:Ws(),runtimeFlags:$u(1,32,4),fiberRefs:ng()}),Jx=Ix(qx),Yx=Lx(qx),Xx=Symbol.for(`effect/DateTime`),Zx=Symbol.for(`effect/DateTime/TimeZone`),Qx={[Xx]:Xx,pipe(){return j(this,arguments)},[A](){return this.toString()},toJSON(){return kS(this).toJSON()}},$x={...Qx,_tag:`Utc`,[C](){return D(this,lt(this.epochMillis))},[O](e){return aS(e)&&e._tag===`Utc`&&this.epochMillis===e.epochMillis},toString(){return`DateTime.Utc(${kS(this).toJSON()})`}},eS={...Qx,_tag:`Zoned`,[C](){return b(lt(this.epochMillis),T(w(this.zone)),D(this))},[O](e){return aS(e)&&e._tag===`Zoned`&&this.epochMillis===e.epochMillis&&k(this.zone,e.zone)},toString(){return`DateTime.Zoned(${US(this)})`}},tS={[Zx]:Zx,[A](){return this.toString()}},nS={...tS,_tag:`Named`,[C](){return D(this,E(`Named:${this.id}`))},[O](e){return oS(e)&&e._tag===`Named`&&this.id===e.id},toString(){return`TimeZone.Named(${this.id})`},toJSON(){return{_id:`TimeZone`,_tag:`Named`,id:this.id}}},rS={...tS,_tag:`Offset`,[C](){return D(this,E(`Offset:${this.offset}`))},[O](e){return oS(e)&&e._tag===`Offset`&&this.offset===e.offset},toString(){return`TimeZone.Offset(${MS(this.offset)})`},toJSON(){return{_id:`TimeZone`,_tag:`Offset`,offset:this.offset}}},iS=(e,t,n)=>{let r=Object.create(eS);return r.epochMillis=e,r.zone=t,Object.defineProperty(r,"partsUtc",{value:n,enumerable:!1,writable:!0}),Object.defineProperty(r,"adjustedEpochMillis",{value:void 0,enumerable:!1,writable:!0}),Object.defineProperty(r,"partsAdjusted",{value:void 0,enumerable:!1,writable:!0}),r},aS=e=>S(e,Xx),oS=e=>S(e,Zx),sS=e=>oS(e)&&e._tag===`Offset`,cS=e=>oS(e)&&e._tag===`Named`,lS=e=>e._tag===`Utc`,uS=e=>e._tag===`Zoned`,dS=Se((e,t)=>e.epochMillis===t.epochMillis),fS=e=>{let t=Object.create($x);return t.epochMillis=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},pS=e=>{let t=e.getTime();if(Number.isNaN(t))throw new um(`Invalid date`);return fS(t)},mS=e=>{if(aS(e))return e;if(e instanceof Date)return pS(e);if(typeof e==`object`){let t=new Date(0);return FS(t,e),pS(t)}return typeof e==`string`&&!hS(e)?pS(new Date(e+`Z`)):pS(new Date(e))},hS=e=>/Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e);-864e13+432e5;const gS=(e,t)=>{if(t?.timeZone===void 0&&aS(e)&&uS(e))return e;let n=mS(e);if(n.epochMillis<-86399999568e5||n.epochMillis>86399999496e5)throw RangeError(`Epoch millis out of range: ${n.epochMillis}`);let r;if(t?.timeZone===void 0){let e=new Date(n.epochMillis).getTimezoneOffset()*-60*1e3;r=wS(e)}else if(oS(t?.timeZone))r=t.timeZone;else if(typeof t?.timeZone==`number`)r=wS(t.timeZone);else{let e=DS(t.timeZone);if(Hn(e))throw new um(`Invalid time zone: ${t.timeZone}`);r=e.value}return t?.adjustForTimeZone===!0?LS(n.epochMillis,r,t?.disambiguation??`compatible`):iS(n.epochMillis,r,n.partsUtc)},_S=Xn(gS),vS=/^(.{17,35})\[(.+)\]$/,yS=e=>{let t=vS.exec(e);if(t===null){let t=zS(e);return t===null?P():_S(e,{timeZone:t})}let[,n,r]=t;return _S(n,{timeZone:r})},bS=x(`effect/DateTime/validZoneCache`,()=>new Map),xS={day:`numeric`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`,timeZoneName:`longOffset`,fractionalSecondDigits:3,hourCycle:`h23`},SS=e=>{let t=e.resolvedOptions().timeZone;if(bS.has(t))return bS.get(t);let n=Object.create(nS);return n.id=t,n.format=e,bS.set(t,n),n},CS=e=>{if(bS.has(e))return bS.get(e);try{return SS(new Intl.DateTimeFormat(`en-US`,{...xS,timeZone:e}))}catch{throw new um(`Invalid time zone: ${e}`)}},wS=e=>{let t=Object.create(rS);return t.offset=e,t},TS=Xn(CS),ES=/^(?:GMT|[+-])/,DS=e=>{if(ES.test(e)){let t=zS(e);return t===null?P():F(wS(t))}return TS(e)},OS=e=>e._tag===`Offset`?MS(e.offset):e.id,kS=e=>new Date(e.epochMillis),AS=e=>{if(e._tag===`Utc`)return new Date(e.epochMillis);if(e.zone._tag===`Offset`)return new Date(e.epochMillis+e.zone.offset);if(e.adjustedEpochMillis!==void 0)return new Date(e.adjustedEpochMillis);let t=e.zone.format.formatToParts(e.epochMillis).filter(e=>e.type!==`literal`),n=new Date(0);return n.setUTCFullYear(Number(t[2].value),Number(t[0].value)-1,Number(t[1].value)),n.setUTCHours(Number(t[3].value),Number(t[4].value),Number(t[5].value),Number(t[6].value)),e.adjustedEpochMillis=n.getTime(),n},jS=e=>AS(e).getTime()-PS(e),MS=e=>{let t=Math.abs(e),n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r===60&&(n+=1,r=0),`${e<0?`-`:`+`}${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`},NS=e=>MS(jS(e)),PS=e=>e.epochMillis,FS=(e,t)=>{if(t.year!==void 0&&e.setUTCFullYear(t.year),t.month!==void 0&&e.setUTCMonth(t.month-1),t.day!==void 0&&e.setUTCDate(t.day),t.weekDay!==void 0){let n=t.weekDay-e.getUTCDay();e.setUTCDate(e.getUTCDate()+n)}t.hours!==void 0&&e.setUTCHours(t.hours),t.minutes!==void 0&&e.setUTCMinutes(t.minutes),t.seconds!==void 0&&e.setUTCSeconds(t.seconds),t.millis!==void 0&&e.setUTCMilliseconds(t.millis)},IS=864e5,LS=(e,t,n)=>{if(t._tag===`Offset`)return iS(e-t.offset,t);let r=BS(e-IS,e,t),i=BS(e+IS,e,t);if(r===i)return iS(e-r,t);let a=r<i,o=r-i;if(a){if(BS(e-i,e,t)===i)return iS(e-i,t);let a=iS(e-r,t);if(e!==AS(a).getTime())switch(n){case`reject`:{let n=new Date(e).toISOString();throw RangeError(`Gap time: ${n} does not exist in time zone ${t.id}`)}case`earlier`:return iS(e-i,t);case`compatible`:case`later`:return a}return a}if(BS(e-r,e,t)===r){if(n===`earlier`||n===`compatible`||BS(e-r+o,e+o,t)===r)return iS(e-r,t);if(n===`reject`){let n=new Date(e).toISOString();throw RangeError(`Ambiguous time: ${n} occurs twice in time zone ${t.id}`)}}return iS(e-i,t)},RS=/([+-])(\d{2}):(\d{2})$/,zS=e=>{let t=RS.exec(e);if(t===null)return null;let[,n,r,i]=t;return(n===`+`?1:-1)*(Number(r)*60+Number(i))*60*1e3},BS=(e,t,n)=>{let r=n.format.formatToParts(e).find(e=>e.type===`timeZoneName`)?.value??``;if(r===`GMT`)return 0;let i=zS(r);return i===null?jS(iS(t,n)):i},VS=e=>kS(e).toISOString(),HS=e=>{let t=AS(e);return e._tag===`Utc`?t.toISOString():`${t.toISOString().slice(0,-1)}${NS(e)}`},US=e=>e.zone._tag===`Offset`?HS(e):`${HS(e)}[${e.zone.id}]`,WS=e=>e.toUpperCase(),GS=e=>e.toLowerCase(),KS=e=>e.length===0?e:WS(e[0])+e.slice(1),qS=e=>e.length===0?e:GS(e[0])+e.slice(1),JS=e=>e.length>0,YS=Wd,XS=ux,ZS=Df,QS=Mf,$S=$d,eC=xf,tC=Sf,nC=Cf,rC=af,iC=I,aC=Jx,oC=Yx,sC=aS,cC=sS,lC=cS,uC=lS,dC=uS,fC=dS,pC=pS,mC=mS,hC=gS,gC=yS,_C=CS,vC=wS,yC=DS,bC=OS,xC=kS,SC=PS;Zs(`effect/DateTime/CurrentTimeZone`)();const CC=VS,wC=US,TC=(e,t)=>{switch(t._tag){case`StringKeyword`:case`TemplateLiteral`:return Object.keys(e);case`SymbolKeyword`:return Object.getOwnPropertySymbols(e);case`Refinement`:return TC(e,t.from)}},EC=e=>{let t=!1,n;return()=>t?n:(n=e(),t=!0,n)},DC=e=>Array.isArray(e),OC=e=>!Array.isArray(e),kC=e=>`[${bt(e)}]`,AC=e=>DC(e)?e.map(kC).join(``):kC(e),jC=(e,t,n,r)=>{let i=e;return n&&vr(n)&&(i+=`\nat path: ${AC(n)}`),t!==void 0&&(i+=`\ndetails: ${t}`),r&&(i+=`\nschema (${r._tag}): ${r}`),i},MC=e=>jC(`Unsupported key schema`,void 0,void 0,e),NC=e=>jC(`Unsupported literal`,`literal value: ${xt(e)}`),PC=e=>jC(`Duplicate index signature`,`${e} index signature`),FC=jC(`Unsupported index signature parameter`,"An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),IC=jC(`Invalid element`,`A required element cannot follow an optional element. ts(1257)`),LC=e=>jC(`Duplicate property signature transformation`,`Duplicate key ${xt(e)}`),RC=e=>jC(`Duplicate property signature`,`Duplicate key ${xt(e)}`),zC=Symbol.for(`effect/SchemaId/DateFromSelf`),BC=Symbol.for(`effect/SchemaId/GreaterThan`),VC=Symbol.for(`effect/SchemaId/GreaterThanOrEqualTo`),HC=Symbol.for(`effect/SchemaId/LessThan`),UC=Symbol.for(`effect/SchemaId/LessThanOrEqualTo`),WC=Symbol.for(`effect/SchemaId/Int`),GC=Symbol.for(`effect/SchemaId/NonNaN`),KC=Symbol.for(`effect/SchemaId/Finite`),qC=Symbol.for(`effect/SchemaId/JsonNumber`),JC=Symbol.for(`effect/SchemaId/Between`),YC=Symbol.for(`effect/SchemaId/GreaterThanOrEqualToBigint`),XC=Symbol.for(`effect/SchemaId/BetweenBigint`),ZC=Symbol.for(`effect/SchemaId/MinLength`),QC=Symbol.for(`effect/SchemaId/MaxLength`),$C=Symbol.for(`effect/SchemaId/Length`),ew=Symbol.for(`effect/annotation/TypeConstructor`),tw=Symbol.for(`effect/annotation/Brand`),nw=Symbol.for(`effect/annotation/SchemaId`),rw=Symbol.for(`effect/annotation/Message`),iw=Symbol.for(`effect/annotation/MissingMessage`),aw=Symbol.for(`effect/annotation/Identifier`),ow=Symbol.for(`effect/annotation/Title`),sw=Symbol.for(`effect/annotation/AutoTitle`),cw=Symbol.for(`effect/annotation/Description`),lw=Symbol.for(`effect/annotation/Examples`),uw=Symbol.for(`effect/annotation/Default`),dw=Symbol.for(`effect/annotation/JSONSchema`),fw=Symbol.for(`effect/annotation/Arbitrary`),pw=Symbol.for(`effect/annotation/Pretty`),mw=Symbol.for(`effect/annotation/Equivalence`),hw=Symbol.for(`effect/annotation/Documentation`),gw=Symbol.for(`effect/annotation/Concurrency`),_w=Symbol.for(`effect/annotation/Batching`),vw=Symbol.for(`effect/annotation/ParseIssueTitle`),yw=Symbol.for(`effect/annotation/ParseOptions`),bw=Symbol.for(`effect/annotation/DecodingFallback`),xw=Symbol.for(`effect/annotation/Surrogate`),Sw=Symbol.for(`effect/annotation/StableFilter`),Cw=v(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?F(e.annotations[t]):P()),ww=Cw(tw),Tw=Cw(rw),Ew=Cw(iw),Dw=Cw(ow),Ow=Cw(sw),kw=Cw(aw),Aw=Cw(cw),jw=Cw(gw),Mw=Cw(_w),Nw=Cw(vw),Pw=Cw(yw),Fw=Cw(bw),Iw=Cw(xw),Lw=Cw(Sw),Rw=e=>ar(Lw(e),e=>e===!0),zw=Symbol.for(`effect/annotation/JSONIdentifier`),Bw=Cw(zw),Vw=e=>Kn(Bw(e),()=>kw(e));var Hw=class{typeParameters;decodeUnknown;encodeUnknown;annotations;_tag=`Declaration`;constructor(e,t,n,r={}){this.typeParameters=e,this.decodeUnknown=t,this.encodeUnknown=n,this.annotations=r}toString(){return Gn(ZT(this),()=>`<declaration schema>`)}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map(e=>e.toJSON()),annotations:KT(this.annotations)}}};const Uw=e=>t=>t._tag===e;var Ww=class{literal;annotations;_tag=`Literal`;constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return Gn(ZT(this),()=>xt(this.literal))}toJSON(){return{_tag:this._tag,literal:Ne(this.literal)?String(this.literal):this.literal,annotations:KT(this.annotations)}}};const Gw=Uw(`Literal`),Kw=new Ww(null);var qw=class{symbol;annotations;_tag=`UniqueSymbol`;constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return Gn(ZT(this),()=>xt(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:KT(this.annotations)}}};const Jw=new class{annotations;_tag=`UndefinedKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`undefined`}),Yw=new class{annotations;_tag=`NeverKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`never`}),Xw=new class{annotations;_tag=`UnknownKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`unknown`}),Zw=new class{annotations;_tag=`AnyKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`any`}),Qw=new class{annotations;_tag=`StringKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`string`,[cw]:`a string`}),$w=Uw(`StringKeyword`),eT=new class{annotations;_tag=`NumberKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`number`,[cw]:`a number`}),tT=new class{annotations;_tag=`BooleanKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`boolean`,[cw]:`a boolean`}),nT=new class{annotations;_tag=`BigIntKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`bigint`,[cw]:`a bigint`}),rT=new class{annotations;_tag=`SymbolKeyword`;constructor(e={}){this.annotations=e}toString(){return JT(this)}toJSON(){return{_tag:this._tag,annotations:KT(this.annotations)}}}({[ow]:`symbol`,[cw]:`a symbol`}),iT=Uw(`SymbolKeyword`);var aT=class{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:KT(this.annotations)}}toString(){return String(this.type)}},oT=class extends aT{isOptional;constructor(e,t,n={}){super(e,n),this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:KT(this.annotations)}}toString(){return String(this.type)+(this.isOptional?`?`:``)}};const sT=e=>e.map(e=>e.type);var cT=class{elements;rest;isReadonly;annotations;_tag=`TupleType`;constructor(e,t,n,r={}){this.elements=e,this.rest=t,this.isReadonly=n,this.annotations=r;let i=!1,a=!1;for(let t of e)if(t.isOptional)i=!0;else if(i){a=!0;break}if(a||i&&t.length>1)throw Error(IC)}toString(){return Gn(ZT(this),()=>lT(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map(e=>e.toJSON()),rest:this.rest.map(e=>e.toJSON()),isReadonly:this.isReadonly,annotations:KT(this.annotations)}}};const lT=e=>{let t=e.elements.map(String).join(`, `);return dr(e.rest,{onEmpty:()=>`readonly [${t}]`,onNonEmpty:(n,r)=>{let i=String(n),a=i.includes(` | `)?`(${i})`:i;if(r.length>0){let n=r.map(String).join(`, `);return e.elements.length>0?`readonly [${t}, ...${a}[], ${n}]`:`readonly [...${a}[], ${n}]`}return e.elements.length>0?`readonly [${t}, ...${a}[]]`:`ReadonlyArray<${i}>`}})};var uT=class extends oT{name;isReadonly;constructor(e,t,n,r,i){super(t,n,i),this.name=e,this.isReadonly=r}toString(){return(this.isReadonly?`readonly `:``)+String(this.name)+(this.isOptional?`?`:``)+`: `+this.type}toJSON(){return{name:String(this.name),type:this.type.toJSON(),isOptional:this.isOptional,isReadonly:this.isReadonly,annotations:KT(this.annotations)}}};const dT=e=>{switch(e._tag){case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:return!0;case`Refinement`:return dT(e.from)}return!1};var fT=class{type;isReadonly;parameter;constructor(e,t,n){if(this.type=t,this.isReadonly=n,dT(e))this.parameter=e;else throw Error(FC)}toString(){return(this.isReadonly?`readonly `:``)+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}},pT=class{annotations;_tag=`TypeLiteral`;propertySignatures;indexSignatures;constructor(e,t,n={}){this.annotations=n;let r={};for(let t=0;t<e.length;t++){let n=e[t].name;if(Object.prototype.hasOwnProperty.call(r,n))throw Error(RC(n));r[n]=null}let i={string:!1,symbol:!1};for(let e=0;e<t.length;e++){let n=qT(t[e].parameter);if($w(n)){if(i.string)throw Error(PC(`string`));i.string=!0}else if(iT(n)){if(i.symbol)throw Error(PC(`symbol`));i.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return Gn(ZT(this),()=>hT(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map(e=>e.toJSON()),indexSignatures:this.indexSignatures.map(e=>e.toJSON()),annotations:KT(this.annotations)}}};const mT=e=>e.map(String).join(`; `),hT=e=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join(`; `);return e.indexSignatures.length>0?`{ ${t}; ${mT(e.indexSignatures)} }`:`{ ${t} }`}return e.indexSignatures.length>0?`{ ${mT(e.indexSignatures)} }`:`{}`},gT=Mr(zn(Pm,e=>{switch(e._tag){case`AnyKeyword`:return 0;case`UnknownKeyword`:return 1;case`ObjectKeyword`:return 2;case`StringKeyword`:case`NumberKeyword`:case`BooleanKeyword`:case`BigIntKeyword`:case`SymbolKeyword`:return 3}return 4})),_T={string:`StringKeyword`,number:`NumberKeyword`,boolean:`BooleanKeyword`,bigint:`BigIntKeyword`},vT=e=>Wr(e,e=>CT(e)?vT(e.types):[e]),yT=e=>{let t=gT(e),n=[],r={},i=[];for(let e of t)switch(e._tag){case`NeverKeyword`:break;case`AnyKeyword`:return[Zw];case`UnknownKeyword`:return[Xw];case`ObjectKeyword`:case`UndefinedKeyword`:case`VoidKeyword`:case`StringKeyword`:case`NumberKeyword`:case`BooleanKeyword`:case`BigIntKeyword`:case`SymbolKeyword`:r[e._tag]||(r[e._tag]=e,n.push(e));break;case`Literal`:{let t=typeof e.literal;switch(t){case`string`:case`number`:case`bigint`:case`boolean`:!r[_T[t]]&&!i.includes(e.literal)&&(i.push(e.literal),n.push(e));break;case`object`:i.includes(e.literal)||(i.push(e.literal),n.push(e))}break}case`UniqueSymbol`:!r.SymbolKeyword&&!i.includes(e.symbol)&&(i.push(e.symbol),n.push(e));break;case`TupleType`:r.ObjectKeyword||n.push(e);break;case`TypeLiteral`:e.propertySignatures.length===0&&e.indexSignatures.length===0?r[`{}`]||(r[`{}`]=e,n.push(e)):r.ObjectKeyword||n.push(e);break;default:n.push(e)}return n};var bT=class e{types;annotations;static make=(t,n)=>ST(t)?new e(t,n):t.length===1?t[0]:Yw;static unify=(t,n)=>e.make(yT(vT(t)),n);_tag=`Union`;constructor(e,t={}){this.types=e,this.annotations=t}toString(){return Gn(ZT(this),()=>this.types.map(String).join(` | `))}toJSON(){return{_tag:this._tag,types:this.types.map(e=>e.toJSON()),annotations:KT(this.annotations)}}};const xT=(e,t)=>e.map(t),ST=e=>e.length>1,CT=Uw(`Union`),wT=x(Symbol.for(`effect/Schema/AST/toJSONMemoMap`),()=>new WeakMap);var TT=class{f;annotations;_tag=`Suspend`;constructor(e,t={}){this.f=e,this.annotations=t,this.f=EC(e)}toString(){return ZT(this).pipe(Kn(()=>$n(Xn(this.f)(),e=>ZT(e))),Gn(()=>`<suspended schema>`))}toJSON(){let e=this.f(),t=wT.get(e);return t||(wT.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:KT(this.annotations)},wT.set(e,t),t)}},ET=class{from;filter;annotations;_tag=`Refinement`;constructor(e,t,n={}){this.from=e,this.filter=t,this.annotations=n}toString(){return kw(this).pipe(Gn(()=>Wn(XT(this),{onNone:()=>`{ ${this.from} | filter }`,onSome:e=>DT(this.from)?String(this.from)+` & `+e:e})))}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),annotations:KT(this.annotations)}}};const DT=Uw(`Refinement`),OT={};var kT=class{from;to;transformation;annotations;_tag=`Transformation`;constructor(e,t,n,r={}){this.from=e,this.to=t,this.transformation=n,this.annotations=r}toString(){return Gn(ZT(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:KT(this.annotations)}}},AT=class{decode;encode;_tag=`FinalTransformation`;constructor(e,t){this.decode=e,this.encode=t}},jT=class{from;to;decode;encode;constructor(e,t,n,r){this.from=e,this.to=t,this.decode=n,this.encode=r}},MT=class{propertySignatureTransformations;_tag=`TypeLiteralTransformation`;constructor(e){this.propertySignatureTransformations=e;let t={},n={};for(let r of e){let e=r.from;if(t[e])throw Error(LC(e));t[e]=!0;let i=r.to;if(n[i])throw Error(LC(i));n[i]=!0}}};const NT=(e,t)=>{let n=Object.getOwnPropertyDescriptors(e),r={...e.annotations};delete r[aw];let i={...r,...t},a=Iw(e);return Un(a)&&(i[xw]=NT(a.value,t)),n.annotations.value=i,Object.create(Object.getPrototypeOf(e),n)},PT=(e,t)=>{switch(e._tag){case`Literal`:return Im(String(e.literal));case`StringKeyword`:return`[\\s\\S]*?`;case`NumberKeyword`:return`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;case`TemplateLiteral`:return IT(e,t,!1);case`Union`:return e.types.map(e=>PT(e,t)).join(`|`)}},FT=(e,t,n,r)=>{if(CT(e)){if(n&&!r)return`(?:${t})`}else if(!n||!r)return t;return`(${t})`},IT=(e,t,n)=>{let r=``;if(e.head!==``){let i=Im(e.head);r+=t&&n?`(${i})`:i}for(let i of e.spans){let e=PT(i.type,t);if(r+=FT(i.type,e,t,n),i.literal!==``){let e=Im(i.literal);r+=t&&n?`(${e})`:e}}return r},LT=e=>RegExp(`^${IT(e,!1,!0)}$`),RT=(e,t)=>{let n=[],r=[],i=e=>{switch(e._tag){case`NeverKeyword`:break;case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:case`Refinement`:r.push(new fT(e,t,!0));break;case`Literal`:if(Ae(e.literal)||je(e.literal))n.push(new uT(e.literal,t,!1,!0));else throw Error(NC(e.literal));break;case`Enums`:for(let[r,i]of e.enums)n.push(new uT(i,t,!1,!0));break;case`UniqueSymbol`:n.push(new uT(e.symbol,t,!1,!0));break;case`Union`:e.types.forEach(i);break;default:throw Error(MC(e))}};return i(e),{propertySignatures:n,indexSignatures:r}},zT=e=>t=>{let n;for(let r of e)Object.prototype.hasOwnProperty.call(t.annotations,r)&&(n===void 0&&(n={}),n[r]=t.annotations[r]);return n},BT=zT([lw,uw,dw,fw,pw,mw]),VT=e=>{switch(e._tag){case`Declaration`:{let t=HT(e.typeParameters,VT);return t===e.typeParameters?e:new Hw(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case`TupleType`:{let t=HT(e.elements,e=>{let t=VT(e.type);return t===e.type?e:new oT(t,e.isOptional)}),n=sT(e.rest),r=HT(n,VT);return t===e.elements&&r===n?e:new cT(t,r.map(e=>new aT(e)),e.isReadonly,e.annotations)}case`TypeLiteral`:{let t=HT(e.propertySignatures,e=>{let t=VT(e.type);return t===e.type?e:new uT(e.name,t,e.isOptional,e.isReadonly)}),n=HT(e.indexSignatures,e=>{let t=VT(e.type);return t===e.type?e:new fT(e.parameter,t,e.isReadonly)});return t===e.propertySignatures&&n===e.indexSignatures?e:new pT(t,n,e.annotations)}case`Union`:{let t=HT(e.types,VT);return t===e.types?e:bT.make(t,e.annotations)}case`Suspend`:return new TT(()=>VT(e.f()),e.annotations);case`Refinement`:{let t=VT(e.from);return t===e.from?e:new ET(t,e.filter,e.annotations)}case`Transformation`:{let t=BT(e);return VT(t===void 0?e.to:NT(e.to,t))}}return e};function HT(e,t){let n=!1,r=sr(e.length);for(let i=0;i<e.length;i++){let a=e[i],o=t(a);o!==a&&(n=!0),r[i]=o}return n?r:e}const UT=e=>{switch(e._tag){case`Transformation`:return e.from;case`Refinement`:return UT(e.from);case`Suspend`:return UT(e.f())}},WT=(e,t)=>{switch(e._tag){case`Declaration`:{let n=HT(e.typeParameters,e=>WT(e,t));return n===e.typeParameters?e:new Hw(n,e.decodeUnknown,e.encodeUnknown)}case`TupleType`:{let n=HT(e.elements,e=>{let n=WT(e.type,t);return n===e.type?e:new oT(n,e.isOptional)}),r=sT(e.rest),i=HT(r,e=>WT(e,t));return n===e.elements&&i===r?e:new cT(n,i.map(e=>new aT(e)),e.isReadonly)}case`TypeLiteral`:{let n=HT(e.propertySignatures,e=>{let n=WT(e.type,t);return n===e.type?e:new uT(e.name,n,e.isOptional,e.isReadonly)}),r=HT(e.indexSignatures,e=>{let n=WT(e.type,t);return n===e.type?e:new fT(e.parameter,n,e.isReadonly)});return n===e.propertySignatures&&r===e.indexSignatures?e:new pT(n,r)}case`Union`:{let n=HT(e.types,e=>WT(e,t));return n===e.types?e:bT.make(n)}case`Suspend`:{let n,r=Vw(e);if(Un(r)){let e=t?`Bound`:``;n={[zw]:`${r.value}Encoded${e}`}}return new TT(()=>WT(e.f(),t),n)}case`Refinement`:{let n=WT(e.from,t);return t?n===e.from?e:UT(e.from)===void 0&&Rw(e)?new ET(n,e.filter,e.annotations):n:n}case`Transformation`:return WT(e.from,t)}return e},GT=e=>WT(e,!1),KT=e=>{let t={};for(let n of Object.getOwnPropertySymbols(e))t[String(n)]=e[n];return t},qT=e=>{switch(e._tag){case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:return e;case`Refinement`:return qT(e.from)}},JT=e=>Gn(ZT(e),()=>e._tag);function YT(e){return Wn(ww(e),{onNone:()=>``,onSome:e=>e.map(e=>` & Brand<${xt(e)}>`).join(``)})}const XT=e=>Dw(e).pipe(Kn(()=>Aw(e)),Kn(()=>Ow(e)),Qn(t=>t+YT(e))),ZT=e=>Kn(kw(e),()=>XT(e));var QT=class{path;actual;issue;_tag=`Pointer`;constructor(e,t,n){this.path=e,this.actual=t,this.issue=n}},$T=class{actual;message;_tag=`Unexpected`;constructor(e,t){this.actual=e,this.message=t}},eE=class{ast;message;_tag=`Missing`;actual=void 0;constructor(e,t){this.ast=e,this.message=t}},tE=class{ast;actual;issues;output;_tag=`Composite`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.issues=n,this.output=r}},nE=class{ast;actual;kind;issue;_tag=`Refinement`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.kind=n,this.issue=r}},rE=class{ast;actual;kind;issue;_tag=`Transformation`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.kind=n,this.issue=r}},iE=class{ast;actual;message;_tag=`Type`;constructor(e,t,n){this.ast=e,this.actual=t,this.message=n}},aE=class{ast;actual;message;_tag=`Forbidden`;constructor(e,t,n){this.ast=e,this.actual=t,this.message=n}};const oE=Symbol.for(`effect/Schema/ParseErrorTypeId`);var sE=class extends Eh(`ParseError`){[oE]=oE;get message(){return this.toString()}toString(){return HE.formatIssueSync(this.issue)}toJSON(){return{_id:`ParseError`,message:this.toString()}}[A](){return this.toJSON()}};const cE=e=>new sE({issue:e}),lE=M,uE=N,dE=Tn,fE=wn,pE=En,mE=v(2,(e,t)=>pE(e)?Mn(e,{onLeft:N,onRight:t}):iC(e,t)),hE=v(2,(e,t)=>pE(e)?jn(e,t):eC(e,t)),gE=v(2,(e,t)=>pE(e)?An(e,t):nC(e,t)),_E=v(2,(e,t)=>pE(e)?kn(e,{onLeft:t.onFailure,onRight:t.onSuccess}):tC(e,t)),vE=v(2,(e,t)=>pE(e)?Mn(e,{onLeft:t,onRight:M}):$S(e,t)),yE=(e,t)=>t===void 0||je(t)?e:e===void 0?t:{...e,...t},bE=(e,t,n)=>{let r=kE(e,t);return(e,t)=>r(e,yE(n,t))},xE=(e,t,n)=>{let r=bE(e,t,n);return(e,t)=>Pn(r(e,t),cE)},SE=(e,t,n)=>{let r=kE(e,t);return(e,t)=>r(e,{...yE(n,t),isEffectAllowed:!0})},CE=(e,t)=>bE(e.ast,!0,t),wE=(e,t)=>SE(e.ast,!0,t),TE=(e,t)=>SE(e.ast,!1,t),EE=(e,t)=>xE(VT(e.ast),!0,t),DE=x(Symbol.for(`effect/ParseResult/decodeMemoMap`),()=>new WeakMap),OE=x(Symbol.for(`effect/ParseResult/encodeMemoMap`),()=>new WeakMap),kE=(e,t)=>{let n=t?DE:OE,r=n.get(e);if(r)return r;let i=ME(e,t),a=Pw(e),o=Un(a)?(e,t)=>i(e,yE(t,a.value)):i,s=Fw(e),c=t&&Un(s)?(t,n)=>LE(vE(o(t,n),s.value),e,t,n):o;return n.set(e,c),c},AE=e=>Yn(jw(e)),jE=e=>Yn(Mw(e)),ME=(e,t)=>{switch(e._tag){case`Refinement`:if(t){let t=kE(e.from,!0);return(n,r)=>{r??=OT;let i=r?.errors===`all`,a=mE(vE(t(n,r),t=>{let a=new nE(e,n,`From`,t);return i&&Rw(e)&&ZE(t)?Wn(e.filter(n,r,e),{onNone:()=>N(a),onSome:t=>N(new tE(e,n,[a,new nE(e,n,`Predicate`,t)]))}):N(a)}),t=>Wn(e.filter(t,r,e),{onNone:()=>M(t),onSome:t=>N(new nE(e,n,`Predicate`,t))}));return LE(a,e,n,r)}}{let t=kE(VT(e),!0),n=kE(IE(e.from),!1);return(r,i)=>LE(mE(t(r,i),e=>n(e,i)),e,r,i)}case`Transformation`:{let n=BE(e.transformation,t),r=t?kE(e.from,!0):kE(e.to,!1),i=t?kE(e.to,!0):kE(e.from,!1);return(a,o)=>LE(mE(gE(r(a,o),n=>new rE(e,a,t?`Encoded`:`Type`,n)),r=>mE(gE(n(r,o??OT,e,a),t=>new rE(e,a,`Transformation`,t)),n=>gE(i(n,o),n=>new rE(e,a,t?`Type`:`Encoded`,n)))),e,a,o)}case`Declaration`:{let n=t?e.decodeUnknown(...e.typeParameters):e.encodeUnknown(...e.typeParameters);return(t,r)=>LE(n(t,r??OT,e),e,t,r)}case`Literal`:return NE(e,t=>t===e.literal);case`UniqueSymbol`:return NE(e,t=>t===e.symbol);case`UndefinedKeyword`:return NE(e,Ie);case`NeverKeyword`:return NE(e,Le);case`UnknownKeyword`:case`AnyKeyword`:case`VoidKeyword`:return M;case`StringKeyword`:return NE(e,Ae);case`NumberKeyword`:return NE(e,je);case`BooleanKeyword`:return NE(e,Me);case`BigIntKeyword`:return NE(e,Ne);case`SymbolKeyword`:return NE(e,Pe);case`ObjectKeyword`:return NE(e,ze);case`Enums`:return NE(e,t=>e.enums.some(([e,n])=>n===t));case`TemplateLiteral`:{if(e.spans.every(e=>$w(e.type)))return NE(e,t=>{if(!Ae(t)||!t.startsWith(e.head))return!1;let n=e.head.length;for(let r=0;r<e.spans.length-1;r++){let i=e.spans[r].literal,a=t.indexOf(i,n);if(a===-1)return!1;n=a+i.length}let r=e.spans[e.spans.length-1].literal;return t.endsWith(r)&&t.length-r.length>=n});let t=LT(e);return NE(e,e=>Ae(e)&&t.test(e))}case`TupleType`:{let n=e.elements.map(e=>kE(e.type,t)),r=e.rest.map(e=>kE(e.type,t)),i=e.elements.filter(e=>!e.isOptional);e.rest.length>0&&(i=i.concat(e.rest.slice(1)));let a=i.length,o=e.elements.length>0?e.elements.map((e,t)=>t).join(` | `):`never`,s=AE(e),c=jE(e);return(t,l)=>{if(!hr(t))return N(new iE(e,t));let u=l?.errors===`all`,d=[],f=0,p=[],m=t.length;for(let n=m;n<=a-1;n++){let r=new QT(n,t,new eE(i[n-m]));if(u){d.push([f++,r]);continue}return N(new tE(e,t,r,p))}if(e.rest.length===0)for(let n=e.elements.length;n<=m-1;n++){let r=new QT(n,t,new $T(t[n],`is unexpected, expected: ${o}`));if(u){d.push([f++,r]);continue}return N(new tE(e,t,r,p))}let h=0,g;for(;h<n.length;h++)if(m<h+1){if(e.elements[h].isOptional)continue}else{let r=n[h],i=r(t[h],l);if(pE(i)){if(Dn(i)){let n=new QT(h,t,i.left);if(u){d.push([f++,n]);continue}return N(new tE(e,t,n,zE(p)))}p.push([f++,i.right])}else{let n=f++,r=h;g||=[],g.push(({es:a,output:o})=>iC(rC(i),i=>{if(Dn(i)){let s=new QT(r,t,i.left);return u?(a.push([n,s]),QS):N(new tE(e,t,s,zE(o)))}return o.push([n,i.right]),QS}))}}if(vr(r)){let[n,...i]=r;for(;h<m-i.length;h++){let r=n(t[h],l);if(pE(r)){if(Dn(r)){let n=new QT(h,t,r.left);if(u){d.push([f++,n]);continue}return N(new tE(e,t,n,zE(p)))}p.push([f++,r.right])}else{let n=f++,i=h;g||=[],g.push(({es:a,output:o})=>iC(rC(r),r=>{if(Dn(r)){let s=new QT(i,t,r.left);return u?(a.push([n,s]),QS):N(new tE(e,t,s,zE(o)))}return o.push([n,r.right]),QS}))}}for(let n=0;n<i.length;n++){let r=h+n;if(!(m<r+1)){let a=i[n](t[r],l);if(pE(a)){if(Dn(a)){let n=new QT(r,t,a.left);if(u){d.push([f++,n]);continue}return N(new tE(e,t,n,zE(p)))}p.push([f++,a.right])}else{let n=f++;g||=[],g.push(({es:i,output:o})=>iC(rC(a),a=>{if(Dn(a)){let s=new QT(r,t,a.left);return u?(i.push([n,s]),QS):N(new tE(e,t,s,zE(o)))}return o.push([n,a.right]),QS}))}}}}let _=({es:n,output:r})=>_r(n)?N(new tE(e,t,zE(n),zE(r))):M(zE(r));if(g&&g.length>0){let e=g;return ZS(()=>{let t={es:Rr(d),output:Rr(p)};return iC(XS(e,e=>e(t),{concurrency:s,batching:c,discard:!0}),()=>_(t))})}return _({output:p,es:d})}}case`TypeLiteral`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return NE(e,He);let n=[],r={},i=[];for(let a of e.propertySignatures)n.push([kE(a.type,t),a]),r[a.name]=null,i.push(a.name);let a=e.indexSignatures.map(e=>[kE(e.parameter,t),kE(e.type,t),e.parameter]),o=bT.make(e.indexSignatures.map(e=>e.parameter).concat(i.map(e=>Pe(e)?new qw(e):new Ww(e)))),s=kE(o,t),c=AE(e),l=jE(e);return(t,u)=>{if(!Ke(t))return N(new iE(e,t));let d=u?.errors===`all`,f=[],p=0,m=u?.onExcessProperty===`error`,h=u?.onExcessProperty===`preserve`,g={},_;if(m||h){_=Reflect.ownKeys(t);for(let n of _){let r=s(n,u);if(pE(r)&&Dn(r)){if(m){let r=new QT(n,t,new $T(t[n],`is unexpected, expected: ${String(o)}`));if(d){f.push([p++,r]);continue}return N(new tE(e,t,r,g))}g[n]=t[n]}}}let ee,te=u?.exact===!0;for(let r=0;r<n.length;r++){let i=n[r][1],a=i.name,o=Object.prototype.hasOwnProperty.call(t,a);if(!o){if(i.isOptional)continue;if(te){let n=new QT(a,t,new eE(i));if(d){f.push([p++,n]);continue}return N(new tE(e,t,n,g))}}let s=n[r][0],c=s(t[a],u);if(pE(c)){if(Dn(c)){let n=new QT(a,t,o?c.left:new eE(i));if(d){f.push([p++,n]);continue}return N(new tE(e,t,n,g))}g[a]=c.right}else{let n=p++,r=a;ee||=[],ee.push(({es:a,output:s})=>iC(rC(c),c=>{if(Dn(c)){let l=new QT(r,t,o?c.left:new eE(i));return d?(a.push([n,l]),QS):N(new tE(e,t,l,s))}return s[r]=c.right,QS}))}}for(let n=0;n<a.length;n++){let i=a[n],o=i[0],s=i[1],c=TC(t,i[2]);for(let n of c){let i=o(n,u);if(pE(i)&&On(i)){let i=s(t[n],u);if(pE(i)){if(Dn(i)){let r=new QT(n,t,i.left);if(d){f.push([p++,r]);continue}return N(new tE(e,t,r,g))}Object.prototype.hasOwnProperty.call(r,n)||(g[n]=i.right)}else{let a=p++,o=n;ee||=[],ee.push(({es:s,output:c})=>iC(rC(i),i=>{if(Dn(i)){let n=new QT(o,t,i.left);return d?(s.push([a,n]),QS):N(new tE(e,t,n,c))}return Object.prototype.hasOwnProperty.call(r,n)||(c[n]=i.right),QS}))}}}}let ne=({es:n,output:r})=>{if(_r(n))return N(new tE(e,t,zE(n),r));if(u?.propertyOrder===`original`){let e=_||Reflect.ownKeys(t);for(let t of i)e.indexOf(t)===-1&&e.push(t);let n={};for(let t of e)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t]);return M(n)}return M(r)};if(ee&&ee.length>0){let e=ee;return ZS(()=>{let t={es:Rr(f),output:Object.assign({},g)};return iC(XS(e,e=>e(t),{concurrency:c,batching:l,discard:!0}),()=>ne(t))})}return ne({es:f,output:g})}}case`Union`:{let n=FE(e.types,t),r=Reflect.ownKeys(n.keys),i=r.length,a=e.types.length,o=new Map;for(let n=0;n<a;n++)o.set(e.types[n],kE(e.types[n],t));let s=AE(e)??1,c=jE(e);return(t,l)=>{let u=[],d=0,f=[];if(i>0){if(Re(t))for(let e=0;e<i;e++){let i=r[e],o=n.keys[i].buckets;if(Object.prototype.hasOwnProperty.call(t,i)){let e=String(t[i]);if(Object.prototype.hasOwnProperty.call(o,e))f=f.concat(o[e]);else{let{candidates:e,literals:r}=n.keys[i],o=bT.make(r),s=e.length===a?new pT([new uT(i,o,!1,!0)],[]):bT.make(e);u.push([d++,new tE(s,t,new QT(i,t,new iE(o,t[i])))])}}else{let{candidates:e,literals:r}=n.keys[i],o=new uT(i,bT.make(r),!1,!0),s=e.length===a?new pT([o],[]):bT.make(e);u.push([d++,new tE(s,t,new QT(i,t,new eE(o)))])}}else{let r=n.candidates.length===a?e:bT.make(n.candidates);u.push([d++,new iE(r,t)])}}n.otherwise.length>0&&(f=f.concat(n.otherwise));let p;for(let e=0;e<f.length;e++){let n=f[e],r=o.get(n)(t,l);if(pE(r)&&(!p||p.length===0)){if(On(r))return r;u.push([d++,r.left])}else{let e=d++;p||=[],p.push(t=>ZS(()=>`finalResult`in t?QS:iC(rC(r),n=>(On(n)?t.finalResult=n:t.es.push([e,n.left]),QS))))}}let m=n=>_r(n)?n.length===1&&n[0][1]._tag===`Type`?N(n[0][1]):N(new tE(e,t,zE(n))):N(new iE(e,t));if(p&&p.length>0){let e=p;return ZS(()=>{let t={es:Rr(u)};return iC(XS(e,e=>e(t),{concurrency:s,batching:c,discard:!0}),()=>`finalResult`in t?t.finalResult:m(t.es))})}return m(u)}}case`Suspend`:{let n=EC(()=>kE(e.f(),t));return(e,t)=>n()(e,t)}}},NE=(e,t)=>n=>t(n)?M(n):N(new iE(e,n)),PE=(e,t)=>{switch(e._tag){case`Declaration`:{let n=Iw(e);if(Un(n))return PE(n.value,t);break}case`TypeLiteral`:{let n=[];for(let r=0;r<e.propertySignatures.length;r++){let i=e.propertySignatures[r],a=t?GT(i.type):VT(i.type);Gw(a)&&!i.isOptional&&n.push([i.name,a])}return n}case`TupleType`:{let n=[];for(let r=0;r<e.elements.length;r++){let i=e.elements[r],a=t?GT(i.type):VT(i.type);Gw(a)&&!i.isOptional&&n.push([r,a])}return n}case`Refinement`:return PE(e.from,t);case`Suspend`:return PE(e.f(),t);case`Transformation`:return PE(t?e.from:e.to,t)}return[]},FE=(e,t)=>{let n={},r=[],i=[];for(let a=0;a<e.length;a++){let o=e[a],s=PE(o,t);if(s.length>0){i.push(o);for(let e=0;e<s.length;e++){let[t,r]=s[e],i=String(r.literal);n[t]=n[t]||{buckets:{},literals:[],candidates:[]};let a=n[t].buckets;if(Object.prototype.hasOwnProperty.call(a,i)){if(e<s.length-1)continue;a[i].push(o),n[t].literals.push(r),n[t].candidates.push(o)}else{a[i]=[o],n[t].literals.push(r),n[t].candidates.push(o);break}}}else r.push(o)}return{keys:n,otherwise:r,candidates:i}},IE=e=>DT(e)?IE(e.from):e,LE=(e,t,n,r)=>{if(r?.isEffectAllowed===!0||pE(e))return e;let i=new J_,a=aC(e,{scheduler:i});i.flush();let o=a.unsafePoll();if(o){if(ov(o))return M(o.value);let e=o.cause;return lm(e)?N(e.error):N(new aE(t,n,dm(e)))}return N(new aE(t,n,`cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`))},RE=([e],[t])=>e>t?1:e<t?-1:0;function zE(e){return e.sort(RE).map(e=>e[1])}const BE=(e,t)=>{switch(e._tag){case`FinalTransformation`:return t?e.decode:e.encode;case`ComposeTransformation`:return M;case`TypeLiteralTransformation`:return n=>{let r=M(n);for(let n of e.propertySignatureTransformations){let[e,i]=t?[n.from,n.to]:[n.to,n.from],a=t?n.decode:n.encode;r=hE(r,t=>{let n=a(Object.prototype.hasOwnProperty.call(t,e)?F(t[e]):P());return delete t[e],Un(n)&&(t[i]=n.value),t})}return r}}},VE=(e,t=[])=>({value:e,forest:t}),HE={formatIssue:e=>hE(lD(e),UE),formatIssueSync:e=>{let t=HE.formatIssue(e);return pE(t)?Fn(t):oC(t)},formatError:e=>HE.formatIssue(e.issue),formatErrorSync:e=>HE.formatIssueSync(e.issue)},UE=e=>e.value+WE(`
21
- `,e.forest),WE=(e,t)=>{let n=``,r=t.length,i;for(let a=0;a<r;a++){i=t[a];let o=a===r-1;n+=e+(o?`└`:`├`)+`─ `+i.value,n+=WE(e+(r>1&&!o?`│ `:` `),i.forest)}return n},GE=e=>{switch(e){case`Encoded`:return`Encoded side transformation failure`;case`Transformation`:return`Transformation process failure`;case`Type`:return`Type side transformation failure`}},KE=e=>{switch(e){case`From`:return`From side refinement failure`;case`Predicate`:return`Predicate refinement failure`}},qE=e=>`ast`in e?F(e.ast):P(),JE=M(void 0),YE=e=>qE(e).pipe($n(Tw),Wn({onNone:()=>JE,onSome:t=>{let n=t(e);return Ae(n)?M({message:n,override:!1}):YS(n)?eC(n,e=>({message:e,override:!1})):Ae(n.message)?M({message:n.message,override:n.override}):eC(n.message,e=>({message:e,override:n.override}))}})),XE=e=>t=>t._tag===e,ZE=XE(`Composite`),QE=XE(`Refinement`),$E=XE(`Transformation`),eD=e=>mE(YE(e),t=>t===void 0?JE:!t.override&&(ZE(e)||QE(e)&&e.kind===`From`||$E(e)&&e.kind!==`Transformation`)?$E(e)||QE(e)?eD(e.issue):JE:M(t.message)),tD=e=>qE(e).pipe($n(Nw),er(t=>t(e)),Yn);function nD(e){return Aw(e).pipe(Kn(()=>Dw(e)),Kn(()=>Ow(e)),Kn(()=>kw(e)),Gn(()=>`{ ${e.from} | filter }`))}function rD(e){return e.message===void 0?`Expected ${DT(e.ast)?nD(e.ast):String(e.ast)}, actual ${xt(e.actual)}`:e.message}const iD=e=>hE(eD(e),t=>t??tD(e)??rD(e)),aD=e=>tD(e)??String(e.ast),oD=e=>e.message??`is forbidden`,sD=e=>e.message??`is unexpected`,cD=e=>{let t=Ew(e.ast);if(Un(t)){let e=t.value();return Ae(e)?M(e):e}return M(e.message??`is missing`)},lD=e=>{switch(e._tag){case`Type`:return hE(iD(e),VE);case`Forbidden`:return M(VE(aD(e),[VE(oD(e))]));case`Unexpected`:return M(VE(sD(e)));case`Missing`:return hE(cD(e),VE);case`Transformation`:return mE(eD(e),t=>t===void 0?hE(lD(e.issue),t=>VE(aD(e),[VE(GE(e.kind),[t])])):M(VE(t)));case`Refinement`:return mE(eD(e),t=>t===void 0?hE(lD(e.issue),t=>VE(aD(e),[VE(KE(e.kind),[t])])):M(VE(t)));case`Pointer`:return hE(lD(e.issue),t=>VE(AC(e.path),[t]));case`Composite`:return mE(eD(e),t=>{if(t!==void 0)return M(VE(t));let n=aD(e);return DC(e.issues)?hE(XS(e.issues,lD),e=>VE(n,e)):hE(lD(e.issues),e=>VE(n,[e]))})}},uD=v(e=>ze(e[0]),(e,...t)=>{let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}),dD=v(e=>ze(e[0]),(e,...t)=>{let n={...e};for(let e of t)delete n[e];return n}),fD=Symbol.for(`effect/Schema`);function pD(e){return class{[fD]=mD;static ast=e;static annotations(e){return pD(_D(this.ast,e))}static pipe(){return j(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[fD]=mD}}const mD={_A:e=>e,_I:e=>e,_R:e=>e},hD={typeConstructor:ew,schemaId:nw,message:rw,missingMessage:iw,identifier:aw,title:ow,description:cw,examples:lw,default:uw,documentation:hw,jsonSchema:dw,arbitrary:fw,pretty:pw,equivalence:mw,concurrency:gw,batching:_w,parseIssueTitle:vw,parseOptions:yw,decodingFallback:bw},gD=e=>{if(!e)return{};let t={...e};for(let n in hD)if(n in e){let r=hD[n];t[r]=e[n],delete t[n]}return t},_D=(e,t)=>NT(e,gD(t)),vD=e=>String(e.ast),yD=(e,t)=>{let n=CE(e,t);return(e,t)=>An(n(e,t),cE)},bD=e=>S(e,fD)&&ze(e[fD]);function xD(e){return ST(e)?bT.make(xT(e,e=>new Ww(e))):new Ww(e[0])}function SD(e,t=xD(e)){return class extends pD(t){static annotations(e){return SD(this.literals,_D(this.ast,e))}static literals=[...e]}}function z(...e){return vr(e)?SD(e):AD}const CD=(e,t,n)=>TD(e,new Hw(e.map(e=>e.ast),(...e)=>t.decode(...e.map(pD)),(...e)=>t.encode(...e.map(pD)),gD(n))),wD=(e,t)=>{let n=()=>(t,n,r)=>e(t)?lE(t):uE(new iE(r,t));return TD([],new Hw([],n,n,gD(t)))};function TD(e,t){return class extends pD(t){static annotations(e){return TD(this.typeParameters,_D(this.ast,e))}static typeParameters=[...e]}}const B=function(){if(Array.isArray(arguments[0])){let e=arguments[0],t=arguments[1],n=arguments[2];return CD(e,t,n)}let e=arguments[0],t=arguments[1];return wD(e,t)},ED=Symbol.for(`effect/SchemaId/InstanceOf`),DD=(e,t)=>B(t=>t instanceof e,{title:e.name,description:`an instance of ${e.name}`,pretty:()=>String,schemaId:ED,[ED]:{constructor:e},...t});var OD=class extends pD(Jw){},kD=class extends pD(Kw){},AD=class extends pD(Yw){},jD=class extends pD(Xw){},MD=class extends pD(nT){},ND=class extends pD(rT){},V=class extends pD(Qw){},PD=class extends pD(eT){},H=class extends pD(tT){};const FD=e=>bT.make(e.map(e=>e.ast));function ID(e,t=FD(e)){return class extends pD(t){static annotations(e){return ID(this.members,_D(this.ast,e))}static members=[...e]}}function U(...e){return ST(e)?ID(e):vr(e)?e[0]:AD}const LD=e=>U(e,OD),RD=e=>new zD(new oT(e.ast,!1),e);var zD=class e{ast;from;[fD];_Token;constructor(e,t){this.ast=e,this.from=t}annotations(t){return new e(new oT(this.ast.type,this.ast.isOptional,{...this.ast.annotations,...gD(t)}),this.from)}toString(){return`${this.ast.type}${this.ast.isOptional?`?`:``}`}};const BD=(e,t)=>new cT(e.map(e=>bD(e)?new oT(e.ast,!1):e.ast),t.map(e=>bD(e)?new aT(e.ast):e.ast),!0);function VD(e,t,n=BD(e,t)){return class extends pD(n){static annotations(e){return VD(this.elements,this.rest,_D(this.ast,e))}static elements=[...e];static rest=[...t]}}function HD(...e){return Array.isArray(e[0])?VD(e[0],e.slice(1)):VD(e,[])}function UD(e,t){return class extends VD([],[e],t){static annotations(e){return UD(this.value,_D(this.ast,e))}static value=e}}const W=e=>UD(e),WD=e=>e?`"?:"`:`":"`;var GD=class extends oT{isReadonly;defaultValue;_tag=`PropertySignatureDeclaration`;constructor(e,t,n,r,i){super(e,t,r),this.isReadonly=n,this.defaultValue=i}toString(){let e=WD(this.isOptional),t=String(this.type);return`PropertySignature<${e}, ${t}, never, ${e}, ${t}>`}},KD=class extends oT{isReadonly;defaultValue;constructor(e,t,n,r,i){super(e,t,r),this.isReadonly=n,this.defaultValue=i}};const qD=e=>e===void 0?`never`:Ae(e)?JSON.stringify(e):String(e);var JD=class{from;to;decode;encode;_tag=`PropertySignatureTransformation`;constructor(e,t,n,r){this.from=e,this.to=t,this.decode=n,this.encode=r}toString(){return`PropertySignature<${WD(this.to.isOptional)}, ${this.to.type}, ${qD(this.from.fromKey)}, ${WD(this.from.isOptional)}, ${this.from.type}>`}};const YD=(e,t)=>{switch(e._tag){case`PropertySignatureDeclaration`:return new GD(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case`PropertySignatureTransformation`:return new JD(e.from,new KD(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},XD=Symbol.for(`effect/PropertySignature`),ZD=e=>S(e,XD);var QD=class e{ast;[fD];[XD]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return j(this,arguments)}annotations(t){return new e(YD(this.ast,gD(t)))}toString(){return String(this.ast)}};const $D=e=>new QD(e);var eO=class e extends QD{from;constructor(e,t){super(e),this.from=t}annotations(t){return new e(YD(this.ast,gD(t)),this.from)}};const tO=e=>new eO(new GD(e.ast,!1,!0,{},void 0),e),nO=v(2,(e,t)=>{let n=e.ast;switch(n._tag){case`PropertySignatureDeclaration`:return $D(new GD(n.type,n.isOptional,n.isReadonly,n.annotations,t));case`PropertySignatureTransformation`:return $D(new JD(n.from,new KD(n.to.type,n.to.isOptional,n.to.isReadonly,n.to.annotations,t),n.decode,n.encode))}}),G=e=>new eO(new GD(e.ast===Jw||e.ast===Yw?Jw:LD(e).ast,!0,!0,{},void 0),e),rO=zT([iw]),iO=(e,t)=>{let n=Reflect.ownKeys(e),r=[];if(n.length>0){let i=[],a=[],o=[];for(let t=0;t<n.length;t++){let s=n[t],c=e[s];if(ZD(c)){let e=c.ast;switch(e._tag){case`PropertySignatureDeclaration`:{let t=e.type,n=e.isOptional,o=e.annotations;i.push(new uT(s,t,n,!0,rO(e))),a.push(new uT(s,VT(t),n,!0,o)),r.push(new uT(s,t,n,!0,o));break}case`PropertySignatureTransformation`:{let t=e.from.fromKey??s;i.push(new uT(t,e.from.type,e.from.isOptional,!0,e.from.annotations)),a.push(new uT(s,e.to.type,e.to.isOptional,!0,e.to.annotations)),o.push(new jT(t,s,e.decode,e.encode));break}}}else i.push(new uT(s,c.ast,!1,!0)),a.push(new uT(s,VT(c.ast),!1,!0)),r.push(new uT(s,c.ast,!1,!0))}if(vr(o)){let e=[],n=[];for(let r of t){let{indexSignatures:t,propertySignatures:o}=RT(r.key.ast,r.value.ast);o.forEach(e=>{i.push(e),a.push(new uT(e.name,VT(e.type),e.isOptional,e.isReadonly,e.annotations))}),t.forEach(t=>{e.push(t),n.push(new fT(t.parameter,VT(t.type),t.isReadonly))})}return new kT(new pT(i,e,{[sw]:`Struct (Encoded side)`}),new pT(a,n,{[sw]:`Struct (Type side)`}),new MT(o))}}let i=[];for(let e of t){let{indexSignatures:t,propertySignatures:n}=RT(e.key.ast,e.value.ast);n.forEach(e=>r.push(e)),t.forEach(e=>i.push(e))}return new pT(r,i)},aO=(e,t)=>{let n=Reflect.ownKeys(e);for(let r of n){let n=e[r];if(t[r]===void 0&&ZD(n)){let e=n.ast,i=e._tag===`PropertySignatureDeclaration`?e.defaultValue:e.to.defaultValue;i!==void 0&&(t[r]=i())}}return t};function oO(e,t,n=iO(e,t)){return class extends pD(n){static annotations(e){return oO(this.fields,this.records,_D(this.ast,e))}static fields={...e};static records=[...t];static make=(t,n)=>{let r=aO(e,{...t});return cA(n)?r:EE(this)(r)};static pick(...t){return K(uD(e,...t))}static omit(...t){return K(dD(e,...t))}}}function K(e,...t){return oO(e,t)}const sO=e=>z(e).pipe(tO,nO(()=>e)),cO=(e,t)=>K({_tag:sO(e),...t});function lO(e,t,n){return class extends oO({},[{key:e,value:t}],n){static annotations(n){return lO(e,t,_D(this.ast,n))}static key=e;static value=t}}const uO=e=>lO(e.key,e.value);function dO(e,t){return class extends pD(t){static annotations(e){return dO(this.from,_D(this.ast,e))}static make=(e,t)=>cA(t)?e:EE(this)(e);static from=e}}const fO=(e,t)=>n=>{let r=Wn(ww(n.ast),{onNone:()=>[e],onSome:t=>[...t,e]});return dO(n,NT(n.ast,gD({[tw]:r,...t})))},pO=e=>pD(new TT(()=>e().ast)),mO=Symbol.for(`effect/SchemaId/Refine`);function hO(e,t,n){return class extends pD(n){static annotations(e){return hO(this.from,this.filter,_D(this.ast,e))}static[mO]=e;static from=e;static filter=t;static make=(e,t)=>cA(t)?e:EE(this)(e)}}const gO=(e,t,n)=>{if(Me(e))return e?P():F(new iE(t,n));if(Ae(e))return F(new iE(t,n,e));if(e!==void 0){if(`_tag`in e)return F(e);let r=new iE(t,n,e.message);return F(vr(e.path)?new QT(e.path,n,r):r)}return P()},_O=(e,t,n)=>{if(OC(e))return gO(e,t,n);if(vr(e)){let r=Kr(e,e=>gO(e,t,n));if(vr(r))return F(r.length===1?r[0]:new tE(t,n,r))}return P()};function q(e,t){return n=>{function r(t,n,r){return _O(e(t,n,r),r,t)}return hO(n,r,new ET(n.ast,r,gD(t)))}}function vO(e,t,n){return class extends pD(n){static annotations(e){return vO(this.from,this.to,_D(this.ast,e))}static from=e;static to=t}}const yO=v(e=>bD(e[0])&&bD(e[1]),(e,t,n)=>vO(e,t,new kT(e.ast,t.ast,new AT(n.decode,n.encode)))),bO=v(e=>bD(e[0])&&bD(e[1]),(e,t,n)=>yO(e,t,{strict:!0,decode:(e,t,r,i)=>lE(n.decode(e,i)),encode:(e,t,r,i)=>lE(n.encode(e,i))})),xO=Symbol.for(`effect/SchemaId/Trimmed`),SO=e=>t=>t.pipe(q(e=>e===e.trim(),{schemaId:xO,title:`trimmed`,description:`a string with no leading or trailing whitespace`,jsonSchema:{pattern:`^\\S[\\s\\S]*\\S$|^\\S$|^$`},...e})),CO=QC,wO=(e,t)=>n=>n.pipe(q(t=>t.length<=e,{schemaId:CO,title:`maxLength(${e})`,description:`a string at most ${e} character(s) long`,jsonSchema:{maxLength:e},...t})),TO=ZC,EO=(e,t)=>n=>n.pipe(q(t=>t.length>=e,{schemaId:TO,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t})),DO=$C,OO=(e,t)=>n=>{let r=ze(e)?Math.max(0,Math.floor(e.min)):Math.max(0,Math.floor(e)),i=ze(e)?Math.max(r,Math.floor(e.max)):r;return r===i?n.pipe(q(e=>e.length===r,{schemaId:DO,title:`length(${r})`,description:r===1?`a single character`:`a string ${r} character(s) long`,jsonSchema:{minLength:r,maxLength:r},...t})):n.pipe(q(e=>e.length>=r&&e.length<=i,{schemaId:DO,title:`length({ min: ${r}, max: ${i})`,description:`a string at least ${r} character(s) and at most ${i} character(s) long`,jsonSchema:{minLength:r,maxLength:i},...t}))},kO=Symbol.for(`effect/SchemaId/Pattern`),AO=(e,t)=>n=>{let r=e.source;return n.pipe(q(t=>(e.lastIndex=0,e.test(t)),{schemaId:kO,[kO]:{regex:e},description:`a string matching the pattern ${r}`,jsonSchema:{pattern:r},...t}))},jO=Symbol.for(`effect/SchemaId/Lowercased`),MO=e=>t=>t.pipe(q(e=>e===e.toLowerCase(),{schemaId:jO,title:`lowercased`,description:`a lowercase string`,jsonSchema:{pattern:`^[^A-Z]*$`},...e}));var NO=class extends V.pipe(MO({identifier:`Lowercased`})){};const PO=Symbol.for(`effect/SchemaId/Uppercased`),FO=e=>t=>t.pipe(q(e=>e===e.toUpperCase(),{schemaId:PO,title:`uppercased`,description:`an uppercase string`,jsonSchema:{pattern:`^[^a-z]*$`},...e}));var IO=class extends V.pipe(FO({identifier:`Uppercased`})){};const LO=Symbol.for(`effect/SchemaId/Capitalized`),RO=e=>t=>t.pipe(q(e=>e[0]?.toUpperCase()===e[0],{schemaId:LO,title:`capitalized`,description:`a capitalized string`,jsonSchema:{pattern:`^[^a-z]?.*$`},...e}));var zO=class extends V.pipe(RO({identifier:`Capitalized`})){};const BO=Symbol.for(`effect/SchemaId/Uncapitalized`),VO=e=>t=>t.pipe(q(e=>e[0]?.toLowerCase()===e[0],{schemaId:BO,title:`uncapitalized`,description:`a uncapitalized string`,jsonSchema:{pattern:`^[^A-Z]?.*$`},...e}));var HO=class extends V.pipe(VO({identifier:`Uncapitalized`})){};V.pipe(OO(1,{identifier:`Char`}));const UO=e=>EO(1,{title:`nonEmptyString`,description:`a non empty string`,...e});bO(V.annotations({description:`a string that will be converted to lowercase`}),NO,{strict:!0,decode:e=>e.toLowerCase(),encode:y}).annotations({identifier:`Lowercase`}),bO(V.annotations({description:`a string that will be converted to uppercase`}),IO,{strict:!0,decode:e=>e.toUpperCase(),encode:y}).annotations({identifier:`Uppercase`}),bO(V.annotations({description:`a string that will be converted to a capitalized format`}),zO,{strict:!0,decode:e=>KS(e),encode:y}).annotations({identifier:`Capitalize`}),bO(V.annotations({description:`a string that will be converted to an uncapitalized format`}),HO,{strict:!0,decode:e=>qS(e),encode:y}).annotations({identifier:`Uncapitalize`});var WO=class extends V.pipe(SO({identifier:`Trimmed`})){},GO=class extends WO.pipe(UO({identifier:`NonEmptyTrimmedString`})){};bO(V.annotations({description:`a string that will be trimmed`}),WO,{strict:!0,decode:e=>e.trim(),encode:y}).annotations({identifier:`Trim`});const KO=e=>e instanceof Error?e.message:String(e);V.pipe(UO({identifier:`NonEmptyString`}));const qO=Symbol.for(`effect/SchemaId/UUID`),JO=/^[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}$/i;V.pipe(AO(JO,{schemaId:qO,identifier:`UUID`,jsonSchema:{format:`uuid`,pattern:JO.source},description:`a Universally Unique Identifier`,arbitrary:()=>e=>e.uuid()}));const YO=Symbol.for(`effect/SchemaId/ULID`);V.pipe(AO(/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i,{schemaId:YO,identifier:`ULID`,description:`a Universally Unique Lexicographically Sortable Identifier`,arbitrary:()=>e=>e.ulid()}));var XO=class extends DD(URL,{typeConstructor:{_tag:`URL`},identifier:`URLFromSelf`,arbitrary:()=>e=>e.webUrl().map(e=>new URL(e)),pretty:()=>e=>e.toString()}){};yO(V.annotations({description:`a string to be decoded into a URL`}),XO,{strict:!0,decode:(e,t,n)=>dE({try:()=>new URL(e),catch:t=>new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a URL. ${KO(t)}`)}),encode:e=>lE(e.toString())}).annotations({identifier:`URL`,pretty:()=>e=>e.toString()});const ZO=KC,QO=e=>t=>t.pipe(q(Number.isFinite,{schemaId:ZO,title:`finite`,description:`a finite number`,jsonSchema:{},...e})),$O=BC,ek=(e,t)=>n=>n.pipe(q(t=>t>e,{schemaId:$O,title:`greaterThan(${e})`,description:e===0?`a positive number`:`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),tk=VC,nk=(e,t)=>n=>n.pipe(q(t=>t>=e,{schemaId:tk,title:`greaterThanOrEqualTo(${e})`,description:e===0?`a non-negative number`:`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t})),rk=WC,ik=e=>t=>t.pipe(q(e=>Number.isSafeInteger(e),{schemaId:rk,title:`int`,description:`an integer`,jsonSchema:{type:`integer`},...e})),ak=HC,ok=(e,t)=>n=>n.pipe(q(t=>t<e,{schemaId:ak,title:`lessThan(${e})`,description:e===0?`a negative number`:`a number less than ${e}`,jsonSchema:{exclusiveMaximum:e},...t})),sk=UC,ck=(e,t)=>n=>n.pipe(q(t=>t<=e,{schemaId:sk,title:`lessThanOrEqualTo(${e})`,description:e===0?`a non-positive number`:`a number less than or equal to ${e}`,jsonSchema:{maximum:e},...t})),lk=JC,uk=(e,t,n)=>r=>r.pipe(q(n=>n>=e&&n<=t,{schemaId:lk,title:`between(${e}, ${t})`,description:`a number between ${e} and ${t}`,jsonSchema:{minimum:e,maximum:t},...n})),dk=GC,fk=e=>t=>t.pipe(q(e=>!Number.isNaN(e),{schemaId:dk,title:`nonNaN`,description:`a number excluding NaN`,...e})),pk=e=>ek(0,{title:`positive`,...e}),mk=e=>ok(0,{title:`negative`,...e}),hk=e=>ck(0,{title:`nonPositive`,...e}),gk=e=>nk(0,{title:`nonNegative`,...e});function _k(e){return yO(e,PD,{strict:!1,decode:(e,t,n)=>fE(Fm(e),()=>new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a number`)),encode:e=>lE(String(e))})}_k(V.annotations({description:`a string to be decoded into a number`})).annotations({identifier:`NumberFromString`}),PD.pipe(QO({identifier:`Finite`}));var vk=class extends PD.pipe(ik({identifier:`Int`})){};PD.pipe(fk({identifier:`NonNaN`})),PD.pipe(pk({identifier:`Positive`})),PD.pipe(mk({identifier:`Negative`})),PD.pipe(hk({identifier:`NonPositive`}));var yk=class extends PD.pipe(gk({identifier:`NonNegative`})){};const bk=qC;PD.pipe(QO({schemaId:bk,identifier:`JsonNumber`})),bO(H.annotations({description:`a boolean that will be negated`}),H,{strict:!0,decode:e=>wi(e),encode:e=>wi(e)});const xk=(e,t)=>{let n=Symbol.keyFor(e);return n===void 0?uE(new iE(t,e,`Unable to encode a unique symbol ${String(e)} into a string`)):lE(n)},Sk=e=>lE(Symbol.for(e));yO(V.annotations({description:`a string to be decoded into a globally shared symbol`}),ND,{strict:!1,decode:e=>Sk(e),encode:(e,t,n)=>xk(e,n)}).annotations({identifier:`Symbol`});const Ck=YC,wk=(e,t)=>n=>n.pipe(q(t=>t>=e,{schemaId:Ck,[Ck]:{min:e},title:`greaterThanOrEqualToBigInt(${e})`,description:e===0n?`a non-negative bigint`:`a bigint greater than or equal to ${e}n`,...t})),Tk=XC,Ek=(e,t,n)=>r=>r.pipe(q(n=>n>=e&&n<=t,{schemaId:Tk,[Tk]:{min:e,max:t},title:`betweenBigInt(${e}, ${t})`,description:`a bigint between ${e}n and ${t}n`,...n})),Dk=e=>wk(0n,{title:`nonNegativeBigInt`,...e});var Ok=class extends yO(V.annotations({description:`a string to be decoded into a bigint`}),MD,{strict:!0,decode:(e,t,n)=>fE(Si(e),()=>new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a bigint`)),encode:e=>lE(String(e))}).annotations({identifier:`BigInt`}){};const kk=MD.pipe(Dk({identifier:`NonNegativeBigintFromSelf`}));yO(PD.annotations({description:`a number to be decoded into a bigint`}),MD.pipe(Ek(BigInt(-(2**53-1)),BigInt(2**53-1))),{strict:!0,decode:(e,t,n)=>fE(Ci(e),()=>new iE(n,e,`Unable to decode ${e} into a bigint`)),encode:(e,t,n)=>fE(xi(e),()=>new iE(n,e,`Unable to encode ${e}n into a number`))}).annotations({identifier:`BigIntFromNumber`});const Ak=(e,t,n,r)=>_E(e,{onFailure:e=>new tE(n,r,e),onSuccess:t});var jk=class extends B(fc,{typeConstructor:{_tag:`effect/Duration`},identifier:`DurationFromSelf`,pretty:()=>String,arbitrary:()=>e=>e.oneof(e.constant(gc),e.bigInt({min:0n}).map(e=>_c(e)),e.maxSafeNat().map(e=>yc(e))),equivalence:()=>jc}){};yO(kk.annotations({description:`a bigint to be decoded into a Duration`}),jk.pipe(q(e=>pc(e),{description:`a finite duration`})),{strict:!0,decode:e=>lE(_c(e)),encode:(e,t,n)=>Wn(Ec(e),{onNone:()=>uE(new iE(n,e,`Unable to encode ${e} into a bigint`)),onSome:e=>lE(e)})}).annotations({identifier:`DurationFromNanos`});const Mk=yk.pipe(ik()).annotations({identifier:`NonNegativeInt`});bO(yk.annotations({description:`a non-negative number to be decoded into a Duration`}),jk,{strict:!0,decode:e=>yc(e),encode:e=>Tc(e)}).annotations({identifier:`DurationFromMillis`});const Nk=cO(`Millis`,{millis:Mk}),Pk=cO(`Nanos`,{nanos:Ok}),Fk=cO(`Infinity`,{}),Ik=Fk.make({}),Lk=U(Nk,Pk,Fk).annotations({identifier:`DurationValue`,description:`an JSON-compatible tagged union to be decoded into a Duration`}),Rk=U(HD(RD(Mk).annotations({title:`seconds`}),RD(Mk).annotations({title:`nanos`})).annotations({identifier:`FiniteHRTime`}),HD(z(-1),z(0)).annotations({identifier:`InfiniteHRTime`})).annotations({identifier:`HRTime`,description:`a tuple of seconds and nanos to be decoded into a Duration`}),zk=e=>typeof e==`object`;bO(U(Lk,Rk),jk,{strict:!0,decode:e=>{if(zk(e))switch(e._tag){case`Millis`:return yc(e.millis);case`Nanos`:return _c(e.nanos);case`Infinity`:return gc}let[t,n]=e;return t===-1?gc:_c(BigInt(t)*BigInt(1e9)+BigInt(n))},encode:e=>{switch(e.value._tag){case`Millis`:return Nk.make({millis:e.value.millis});case`Nanos`:return Pk.make({nanos:e.value.nanos});case`Infinity`:return Ik}}}).annotations({identifier:`Duration`});var Bk=class extends B(Ue,{typeConstructor:{_tag:`Uint8Array`},identifier:`Uint8ArrayFromSelf`,pretty:()=>e=>`new Uint8Array(${JSON.stringify(Array.from(e))})`,arbitrary:()=>e=>e.uint8Array(),equivalence:()=>Yr(k)}){};bO(W(class extends PD.pipe(uk(0,255,{identifier:`Uint8`,description:`a 8-bit unsigned integer`})){}).annotations({description:`an array of 8-bit unsigned integers to be decoded into a Uint8Array`}),Bk,{strict:!0,decode:e=>Uint8Array.from(e),encode:e=>Array.from(e)}).annotations({identifier:`Uint8Array`});const Vk=Symbol.for(`effect/SchemaId/ValidDate`),Hk=e=>t=>t.pipe(q(e=>!Number.isNaN(e.getTime()),{schemaId:Vk,[Vk]:{noInvalidDate:!0},title:`validDate`,description:`a valid Date`,...e})),Uk=zC;var Wk=class extends B(We,{typeConstructor:{_tag:`Date`},identifier:`DateFromSelf`,schemaId:Uk,[Uk]:{noInvalidDate:!1},description:`a potentially invalid Date instance`,pretty:()=>e=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>e=>e.date({noInvalidDate:!1}),equivalence:()=>Te}){};Wk.pipe(Hk({identifier:`ValidDateFromSelf`,description:`a valid Date instance`})),class extends bO(V.annotations({description:`a string to be decoded into a Date`}),Wk,{strict:!0,decode:e=>new Date(e),encode:e=>vt(e)}).annotations({identifier:`DateFromString`}){}.pipe(Hk({identifier:`Date`})),bO(PD.annotations({description:`a number to be decoded into a Date`}),Wk,{strict:!0,decode:e=>new Date(e),encode:e=>e.getTime()}).annotations({identifier:`DateFromNumber`});var Gk=class extends B(e=>sC(e)&&uC(e),{typeConstructor:{_tag:`effect/DateTime.Utc`},identifier:`DateTimeUtcFromSelf`,description:`a DateTime.Utc instance`,pretty:()=>e=>e.toString(),arbitrary:()=>e=>e.date({noInvalidDate:!0}).map(e=>pC(e)),equivalence:()=>fC}){};const Kk=(e,t)=>dE({try:()=>mC(e),catch:()=>new iE(t,e,`Unable to decode ${xt(e)} into a DateTime.Utc`)});yO(PD.annotations({description:`a number to be decoded into a DateTime.Utc`}),Gk,{strict:!0,decode:(e,t,n)=>Kk(e,n),encode:e=>lE(SC(e))}).annotations({identifier:`DateTimeUtcFromNumber`}),yO(Wk.annotations({description:`a Date to be decoded into a DateTime.Utc`}),Gk,{strict:!0,decode:(e,t,n)=>Kk(e,n),encode:e=>lE(xC(e))}).annotations({identifier:`DateTimeUtcFromDate`}),yO(V.annotations({description:`a string to be decoded into a DateTime.Utc`}),Gk,{strict:!0,decode:(e,t,n)=>Kk(e,n),encode:e=>lE(CC(e))}).annotations({identifier:`DateTimeUtc`});const qk=()=>e=>e.integer({min:-432e5,max:504e5}).map(vC);var Jk=class extends B(cC,{typeConstructor:{_tag:`effect/DateTime.TimeZone.Offset`},identifier:`TimeZoneOffsetFromSelf`,description:`a TimeZone.Offset instance`,pretty:()=>e=>e.toString(),arbitrary:qk}){};bO(PD.annotations({description:`a number to be decoded into a TimeZone.Offset`}),Jk,{strict:!0,decode:e=>vC(e),encode:e=>e.offset}).annotations({identifier:`TimeZoneOffset`});const Yk=()=>e=>e.constantFrom(...Intl.supportedValuesOf(`timeZone`)).map(_C);var Xk=class extends B(lC,{typeConstructor:{_tag:`effect/DateTime.TimeZone.Named`},identifier:`TimeZoneNamedFromSelf`,description:`a TimeZone.Named instance`,pretty:()=>e=>e.toString(),arbitrary:Yk}){};yO(V.annotations({description:`a string to be decoded into a TimeZone.Named`}),Xk,{strict:!0,decode:(e,t,n)=>dE({try:()=>_C(e),catch:()=>new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a TimeZone.Named`)}),encode:e=>lE(e.id)}).annotations({identifier:`TimeZoneNamed`});var Zk=class extends U(Jk,Xk){};yO(V.annotations({description:`a string to be decoded into a TimeZone`}),Zk,{strict:!0,decode:(e,t,n)=>Wn(yC(e),{onNone:()=>uE(new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a TimeZone`)),onSome:lE}),encode:e=>lE(bC(e))}).annotations({identifier:`TimeZone`});const Qk=e=>e.oneof(qk()(e),Yk()(e));var $k=class extends B(e=>sC(e)&&dC(e),{typeConstructor:{_tag:`effect/DateTime.Zoned`},identifier:`DateTimeZonedFromSelf`,description:`a DateTime.Zoned instance`,pretty:()=>e=>e.toString(),arbitrary:()=>e=>e.tuple(e.integer({min:-31536e9,max:31536e9}),Qk(e)).map(([e,t])=>hC(e,{timeZone:t})),equivalence:()=>fC}){};yO(V.annotations({description:`a string to be decoded into a DateTime.Zoned`}),$k,{strict:!0,decode:(e,t,n)=>Wn(gC(e),{onNone:()=>uE(new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a DateTime.Zoned`)),onSome:lE}),encode:e=>lE(wC(e))}).annotations({identifier:`DateTimeZoned`});const eA=e=>e._tag===`None`?P():F(e.value),tA=(e,t)=>n=>n.oneof(t,n.record({_tag:n.constant(`None`)}),n.record({_tag:n.constant(`Some`),value:e(n)})).map(eA),nA=e=>Wn({onNone:()=>`none()`,onSome:t=>`some(${e(t)})`}),rA=e=>(t,n,r)=>Vn(t)?Hn(t)?lE(P()):Ak(e(t.value,n),F,r,t):uE(new iE(r,t)),iA=e=>B([e],{decode:e=>rA(wE(e)),encode:e=>rA(TE(e))},{typeConstructor:{_tag:`effect/Option`},pretty:nA,arbitrary:tA,equivalence:rr});bO(V,(e=>iA(e).annotations({description:`Option<${vD(e)}>`}))(GO),{strict:!0,decode:e=>nr(F(e.trim()),JS),encode:e=>Gn(e,()=>``)});const aA=()=>e=>`BigDecimal(${gi(ci(e))})`,oA=()=>e=>e.tuple(e.bigInt(),e.integer({min:-18,max:18})).map(([e,t])=>ri(e,t));var sA=class extends B(ni,{typeConstructor:{_tag:`effect/BigDecimal`},identifier:`BigDecimalFromSelf`,pretty:aA,arbitrary:oA,equivalence:()=>di}){};yO(V.annotations({description:`a string to be decoded into a BigDecimal`}),sA,{strict:!0,decode:(e,t,n)=>hi(e).pipe(Wn({onNone:()=>uE(new iE(n,e,`Unable to decode ${JSON.stringify(e)} into a BigDecimal`)),onSome:e=>lE(ci(e))})),encode:e=>lE(gi(ci(e)))}).annotations({identifier:`BigDecimal`}),bO(PD.annotations({description:`a number to be decoded into a BigDecimal`}),sA,{strict:!0,decode:e=>pi(e),encode:e=>vi(e)}).annotations({identifier:`BigDecimalFromNumber`});function cA(e){return Me(e)?e:e?.disableValidation??!1}const lA=U(K({_tag:z(`None`)}).annotations({identifier:`FiberIdNoneEncoded`}),K({_tag:z(`Runtime`),id:vk,startTimeMillis:vk}).annotations({identifier:`FiberIdRuntimeEncoded`}),K({_tag:z(`Composite`),left:pO(()=>lA),right:pO(()=>lA)}).annotations({identifier:`FiberIdCompositeEncoded`})).annotations({identifier:`FiberIdEncoded`}),uA=e=>e.letrec(t=>({None:e.record({_tag:e.constant(`None`)}),Runtime:e.record({_tag:e.constant(`Runtime`),id:e.integer(),startTimeMillis:e.integer()}),Composite:e.record({_tag:e.constant(`Composite`),left:t(`FiberId`),right:t(`FiberId`)}),FiberId:e.oneof(t(`None`),t(`Runtime`),t(`Composite`))})).FiberId.map(pA),dA=e=>{switch(e._tag){case`None`:return`FiberId.none`;case`Runtime`:return`FiberId.runtime(${e.id}, ${e.startTimeMillis})`;case`Composite`:return`FiberId.composite(${dA(e.right)}, ${dA(e.left)})`}};var fA=class extends B(cl,{typeConstructor:{_tag:`effect/FiberId`},identifier:`FiberIdFromSelf`,pretty:()=>dA,arbitrary:()=>uA}){};const pA=e=>{switch(e._tag){case`None`:return al;case`Runtime`:return ol(e.id,e.startTimeMillis);case`Composite`:return sl(pA(e.left),pA(e.right))}},mA=e=>{switch(e._tag){case`None`:return{_tag:`None`};case`Runtime`:return{_tag:`Runtime`,id:e.id,startTimeMillis:e.startTimeMillis};case`Composite`:return{_tag:`Composite`,left:mA(e.left),right:mA(e.right)}}};bO(lA,fA,{strict:!0,decode:e=>pA(e),encode:e=>mA(e)}).annotations({identifier:`FiberId`}),bO(jD,jD,{strict:!0,decode:e=>{if(ze(e)&&`message`in e&&typeof e.message==`string`){let t=Error(e.message,{cause:e});return`name`in e&&typeof e.name==`string`&&(t.name=e.name),t.stack=`stack`in e&&typeof e.stack==`string`?e.stack:``,t}return fs(e)},encode:e=>e instanceof Error?{name:e.name,message:e.message}:fs(e)}).annotations({identifier:`Defect`}),bO(jD,H,{strict:!0,decode:e=>ke(e),encode:y}).annotations({identifier:`BooleanFromUnknown`}),bO(z(`true`,`false`).annotations({description:`a string to be decoded into a boolean`}),H,{strict:!0,decode:e=>e===`true`,encode:e=>e?`true`:`false`}).annotations({identifier:`BooleanFromString`});const hA=cO(`symbol`,{key:V}).annotations({description:`an object to be decoded into a globally shared symbol`}),gA=yO(hA,ND,{strict:!0,decode:e=>Sk(e.key),encode:(e,t,n)=>hE(xk(e,n),e=>hA.make({key:e}))});var _A=class extends U(V,PD,gA).annotations({identifier:`PropertyKey`}){};K({_tag:tO(z(`Pointer`,`Unexpected`,`Missing`,`Composite`,`Refinement`,`Transformation`,`Type`,`Forbidden`)).annotations({description:`The tag identifying the type of parse issue`}),path:tO(W(_A)).annotations({description:`The path to the property where the issue occurred`}),message:tO(V).annotations({description:`A descriptive message explaining the issue`})}).annotations({identifier:`ArrayFormatterIssue`,description:`Represents an issue returned by the ArrayFormatter formatter`});const vA={onExcessProperty:`error`};function yA(e,t){return yD(e,vA)(t)}const bA=z(`computer_use`,`work`,`frontend`,`security`);z(`computer_use`,`work`,`frontend`,`security`),z(`installed`,`disabled`,`missing`,`uncertain`),z(`healthy`,`missing`,`disabled`,`uncertain`);const xA=Object.freeze({coding:!0,computer_use:!1,work:!1,frontend:!0,security:!0}),SA={work:{name:`work`,pluginIds:[`documents@openai-primary-runtime`,`pdf@openai-primary-runtime`,`presentations@openai-primary-runtime`,`spreadsheets@openai-primary-runtime`,`template-creator@openai-primary-runtime`],defaultSelected:xA.work,migrationKey:`work`,semanticSkillIds:[`documents:documents`,`pdf:pdf`,`presentations:Presentations`,`spreadsheets:Spreadsheets`,`template-creator:template-creator`],ownership:`shared-preserve`},frontend:{name:`frontend`,pluginIds:[`build-web-apps@openai-curated`],defaultSelected:xA.frontend,migrationKey:`frontend`,semanticSkillIds:[`build-web-apps:frontend-app-builder`,`build-web-apps:frontend-testing-debugging`,`build-web-apps:react-best-practices`],ownership:`shared-preserve`},security:{name:`security`,pluginIds:[`codex-security@openai-curated`],defaultSelected:xA.security,migrationKey:`security`,semanticSkillIds:[`codex-security:security-scan`,`codex-security:security-diff-scan`,`codex-security:threat-model`],ownership:`shared-preserve`},computer_use:{name:`computer_use`,pluginIds:[`computer-use@openai-bundled`],defaultSelected:xA.computer_use,migrationKey:`computer_use`,semanticSkillIds:[`computer-use:computer-use`],ownership:`shared-preserve`}},CA=Object.freeze(SA),wA=Object.freeze([`computer_use`,`work`,`frontend`,`security`]),TA=Object.freeze({computer_use:xA.computer_use,work:xA.work,frontend:xA.frontend,security:xA.security});function EA(e,t){let n=t??TA;return{computer_use:e?.computer_use??n.computer_use,work:e?.work??n.work,frontend:e?.frontend??n.frontend,security:e?.security??n.security}}function DA(e,t=[]){let n=[],r=new Set;for(let t of wA)if(e[t])for(let e of CA[t].pluginIds)r.has(e)||(r.add(e),n.push(e));for(let e of t)r.has(e)||(r.add(e),n.push(e));return n}K({identifier:z(`local.repository.edit`,`local.repository.check`,`local.repository.lint`,`local.repository.format`,`local.repository.commit`,`external.read`,`specialist.dispatch`,`vcs.server.mutation`,`vcs.server.ci-trigger`,`unknown.effect`),label:V,requiresRootApproval:H});function OA(e){return K({identifier:z(e),label:V,requiresRootApproval:H})}K({localRepositoryEdit:OA(`local.repository.edit`),localRepositoryCheck:OA(`local.repository.check`),localRepositoryLint:OA(`local.repository.lint`),localRepositoryFormat:OA(`local.repository.format`),localRepositoryCommit:OA(`local.repository.commit`),externalRead:OA(`external.read`),specialistDispatch:OA(`specialist.dispatch`),versionControlServerMutation:OA(`vcs.server.mutation`),versionControlServerCiTrigger:OA(`vcs.server.ci-trigger`),unknownEffect:OA(`unknown.effect`)});const kA={localRepositoryEdit:{identifier:`local.repository.edit`,label:`local repository edit`,requiresRootApproval:!1},localRepositoryCheck:{identifier:`local.repository.check`,label:`local repository check`,requiresRootApproval:!1},localRepositoryLint:{identifier:`local.repository.lint`,label:`local repository lint`,requiresRootApproval:!1},localRepositoryFormat:{identifier:`local.repository.format`,label:`local repository format`,requiresRootApproval:!1},localRepositoryCommit:{identifier:`local.repository.commit`,label:`local repository commit`,requiresRootApproval:!1},externalRead:{identifier:`external.read`,label:`external read`,requiresRootApproval:!1},specialistDispatch:{identifier:`specialist.dispatch`,label:`specialist dispatch`,requiresRootApproval:!1},versionControlServerMutation:{identifier:`vcs.server.mutation`,label:`version-control-server mutation`,requiresRootApproval:!0},versionControlServerCiTrigger:{identifier:`vcs.server.ci-trigger`,label:`version-control-server CI triggering`,requiresRootApproval:!0},unknownEffect:{identifier:`unknown.effect`,label:`unclassified effect`,requiresRootApproval:!0}};ue(kA),z(`never`,`root`);const AA=Object.values(kA);function jA(e){let t=e.map(e=>e.label),n=t.at(-1);return n===void 0?``:t.length===1?n:`${t.slice(0,-1).join(`, `)}, and ${n}`}function MA(e){return e.length===0?e:`${e[0]?.toUpperCase()??``}${e.slice(1)}`}const NA=AA.filter(e=>!e.requiresRootApproval),PA=AA.filter(e=>e.requiresRootApproval);Object.freeze({noRootApproval:`${MA(jA(NA))} actions do not require Root approval.`,rootApproval:`${MA(jA(PA))} require Root approval.`});const FA=V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),IA=V.pipe(AO(/^[0-9a-f]{64}$/u));FA.pipe(fO(`RunId`)),FA.pipe(fO(`ProjectId`)),FA.pipe(fO(`TrustId`));const LA=IA.pipe(fO(`Sha256Digest`));function RA(e){let t=yA(LA,e);return Dn(t)?me(he(`sha256 digest`,t.left)):pe(t.right)}K({run_id:FA,objective_lineage:FA,parent_run_id:G(U(FA,kD))}),K({project_id:FA,trust_id:FA,trust_digest:IA}),K({project_id:FA,project_digest:IA}),V.pipe(AO(/^state-[0-9]+\.[0-9]+$/u));const zA=z(`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`);U(zA,z(`Go`));function BA(e){return e===`Go`?`go`:e}const VA=z(`standard`,`fast`,`fast-all`);z(`low`,`medium`,`high`,`xhigh`,`max`);const HA=[{role:`Explorer`,tasks:[{name:`lookup`,description:`Use when Root needs one exact repository fact; locate it and return the exact path, symbol, or value.`,instruction:`Locate the exact requested repository fact.`},{name:`trace`,description:`Use when Root needs a complete in-scope execution or reference path; trace every relevant caller and constraint, then return the path and evidence.`,instruction:`Trace the complete in-scope execution or reference path.`}],capability:`repository-read`,authority:`Read only the assigned repository scope; Root owns decisions.`,evidence:`Return exact paths, symbols, callers, tests, and constraints.`,completion:`Account for every in-scope caller and constraint.`,permissions:{network:!1,write:!1,execute:!1}},{role:`Librarian`,tasks:[{name:`lookup`,description:`Use when Root needs one exact current external fact; locate it in the assigned authoritative source and return the citation.`,instruction:`Locate the exact requested authoritative external fact.`},{name:`research`,description:`Use when Root needs a sourced current synthesis; combine the assigned authoritative sources with citations and return the evidence and uncertainty.`,instruction:`Synthesize the assigned current sources with citations.`}],capability:`current-research`,authority:`Research only the assigned current sources; Root owns decisions.`,evidence:`Return sourced facts, dates, and explicit uncertainty.`,completion:`Resolve the assigned external fact or report the exact evidence gap.`,permissions:{network:!0,write:!1,execute:!1}},{role:`Worker`,tasks:[{name:`mechanical`,description:`Use when Root has decided deterministic edits; apply only those edits, verify the result, and return changed paths and evidence.`,instruction:`Apply only deterministic, already-decided edits.`},{name:`implementation`,description:`Use when Root has decided a bounded behavior seam; implement and verify that seam, then return changed paths and evidence.`,instruction:`Implement and verify the bounded behavior seam.`},{name:`integration`,description:`Use when Root has decided seams that must be combined; integrate and verify them together, then return the result and residual risk.`,instruction:`Integrate the decided seams and verify them together.`},{name:`operations`,description:`Use after Root approves an exact ref or SHA; observe required CI and release state to terminal evidence and return it, never treating pending as success.`,instruction:`After Root approves an exact ref or SHA, observe required CI and release state through terminal evidence; pending or running state is never success.`}],capability:`bounded-write`,authority:`Change only the assigned seam; Root owns material choices.`,evidence:`Return changed files, verification results, and remaining risk.`,completion:`Finish the assigned seam with proportional proof or an exact blocker.`,permissions:{network:!1,write:!0,execute:!0}},{role:`Reviewer`,tasks:[{name:`plan`,description:`Use when Root needs a complete plan adversarially checked; review it to a fixed point and return findings, proof, and residual risk.`,instruction:`Review the complete plan to a fixed point.`},{name:`code`,description:`Use when Root needs implemented code adversarially checked; review and repair it to a fixed point, returning findings, proof, and residual risk.`,instruction:`Review and repair the implemented code to a fixed point.`},{name:`artifact`,description:`Use when Root needs a produced artifact inspected; review and repair it to a fixed point, returning findings, proof, and residual risk.`,instruction:`Review and repair the produced artifact to a fixed point.`}],capability:`bounded-review`,authority:`Inspect and repair only reviewer-owned defects; Root owns material choices.`,evidence:`Return findings, repaired paths, verification, and residual risk.`,completion:`Reach a fixed point or report each reproducible blocker.`,permissions:{network:!1,write:!0,execute:!0}}];ue(HA);const UA=new Map(HA.map(e=>[e.role,e])),WA=new Set(HA.map(e=>e.role)),GA=HA.flatMap(e=>e.tasks.map(t=>`${e.role}:${t.name}`)),KA=new Set(GA),qA=GA.map(e=>e.replace(`:`,`.`)),JA=new Set(qA);function YA(e){return typeof e==`string`&&WA.has(e)}function XA(e){if(typeof e!=`object`||!e||!(`role`in e)||!(`task`in e))return!1;let t=e.role,n=e.task;return!YA(t)||typeof n!=`string`?!1:UA.get(t)?.tasks.some(e=>e.name===n)===!0}function ZA(e,t){return typeof t==`string`&&UA.get(e)?.tasks.some(e=>e.name===t)===!0}function QA(e){return typeof e==`string`&&KA.has(e)}const $A=B(YA);B(e=>ZA(`Explorer`,e)),B(e=>ZA(`Librarian`,e)),B(e=>ZA(`Worker`,e)),B(e=>ZA(`Reviewer`,e));const ej=B(XA),tj=Object.freeze(GA.filter(e=>QA(e)));B(QA),Object.freeze(qA.filter(e=>JA.has(e))),B(e=>typeof e==`string`&&JA.has(e));function nj(e){let t=`${e.role}.${e.task}`;if(!JA.has(t))throw Error(`Unknown native specialist agent type.`);return t}function rj(e){let t=UA.get(e.role)?.tasks.find(t=>t.name===e.task);if(t===void 0)throw Error(`Unknown specialist task policy.`);return t.instruction}function ij(e){let t=UA.get(e.role)?.tasks.find(t=>t.name===e.task);if(t===void 0)throw Error(`Unknown specialist task policy.`);return t.description}K({plan:zA,service_tier:G(VA)});function aj(e,t){return new fe(`invalid_canonical_value`,`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function oj(e,t,n){if(e===null)return`null`;switch(typeof e){case`string`:{let n=JSON.stringify(e);if(n===void 0)throw aj(t,`invalid string`);return n}case`boolean`:return e?`true`:`false`;case`number`:{if(!Number.isFinite(e))throw aj(t,`non-finite number`);let n=JSON.stringify(e);if(n===void 0)throw aj(t,`invalid number`);return n}case`undefined`:throw aj(t,`undefined is not JSON`);case`bigint`:throw aj(t,`bigint is not JSON`);case`function`:throw aj(t,`function is not JSON`);case`symbol`:throw aj(t,`symbol is not JSON`)}if(n.has(e))throw aj(t,`cyclic value`);n.add(e);try{if(Array.isArray(e)){for(let n of Object.getOwnPropertySymbols(e))throw aj(t,`symbol property ${String(n)}`);let r=e,i=[];for(let e=0;e<r.length;e+=1){let a=Object.getOwnPropertyDescriptor(r,String(e));if(!a||!a.enumerable||!(`value`in a))throw aj(`${t}[${e}]`,`sparse or accessor array item`);i.push(oj(a.value,`${t}[${e}]`,n))}for(let e of Object.getOwnPropertyNames(r)){if(e===`length`)continue;let n=Number(e);if(!Number.isInteger(n)||n<0||n>=r.length||String(n)!==e)throw aj(t,`non-index array property ${e}`);let i=Object.getOwnPropertyDescriptor(r,e);if(!i||!i.enumerable||!(`value`in i))throw aj(`${t}[${n}]`,`non-enumerable or accessor array item`)}return`[${i.join(`,`)}]`}let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw aj(t,`only plain objects are supported`);for(let n of Object.getOwnPropertySymbols(e))throw aj(t,`symbol property ${String(n)}`);for(let n of Object.getOwnPropertyNames(e)){let r=Object.getOwnPropertyDescriptor(e,n);if(!r||!r.enumerable||!(`value`in r))throw aj(`${t}.${n}`,`non-enumerable or accessor property`)}let i=[];for(let r of Object.keys(e).sort()){let a=Object.getOwnPropertyDescriptor(e,r);if(!a||!(`value`in a))throw aj(`${t}.${r}`,`accessor property`);i.push(`${JSON.stringify(r)}:${oj(a.value,`${t}.${r}`,n)}`)}return`{${i.join(`,`)}}`}finally{n.delete(e)}}function sj(e){return oj(e,`$`,new Set)}function cj(e){return new TextEncoder().encode(sj(e))}function lj(e,t){if(e.length===0||e.includes(`\0`))throw new fe(`invalid_digest_domain`,`Digest domains must be non-empty and NUL-free.`,{field:`domain`});let n=new TextEncoder().encode(`holycodex-sha256\0`),r=new TextEncoder().encode(e),i=n.byteLength+8+r.byteLength;for(let e of t){if(e.byteLength>4294967295||i>4294967291-e.byteLength)throw new fe(`invalid_digest_domain`,`Digest input is too large.`);i+=4+e.byteLength}let a=new Uint8Array(i),o=new DataView(a.buffer);a.set(n,0);let s=n.byteLength;o.setUint32(s,r.byteLength,!1),s+=4,a.set(r,s),s+=r.byteLength,o.setUint32(s,t.length,!1),s+=4;for(let e of t)o.setUint32(s,e.byteLength,!1),s+=4,a.set(e,s),s+=e.byteLength;return a}function uj(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function dj(e,t){let n=globalThis.crypto?.subtle;if(!n)throw new fe(`crypto_unavailable`,`The standards-based crypto API is unavailable.`);let r=await n.digest(`SHA-256`,fj(lj(e,t)));return uj(new Uint8Array(r))}function fj(e){let t=new Uint8Array(e.byteLength);return t.set(e),t}const pj=z(`blocked`,`completed`,`failed`,`partial`),mj=U(z(`high`,`max`,`xhigh`),kD);function hj(e){try{return sj(e)!==void 0}catch{return!1}}const gj=B(e=>hj(e)),_j=B(e=>de(e)&&!Array.isArray(e)&&hj(e));K({blocked:H,changed_files:W(V),confidence:PD,context_owner:U(V,kD),material_findings:W(V),needs_more_context:H,needs_root_decision:H,needs_verification:H,relevant_files:W(V),remaining_risk:W(V),reuse_recommended:H,status:pj,suggested_followup:U(V,kD),suggested_luna_effort:mj,suggested_specialist:U($A,kD),verification:W(V),verification_passed:H});const vj=`holycodex-specialist-outcome-2`,yj=V.pipe(EO(1)),bj={protocol_version:z(vj),route:ej,evidence:W(yj)};K(bj),U(K({...bj,status:z(`completed`),summary:yj}),K({...bj,status:z(`blocked`),reason:yj,needs_root_decision:H}),K({...bj,status:z(`partial`),summary:yj,completed:W(yj),remaining:W(yj),needs_root_decision:H}),K({...bj,status:z(`failed`),error:yj}));const xj={protocol_version:z(vj),capability:bA,route:U(ej,kD),evidence:W(yj),data:gj};U(K({...xj,status:z(`completed`),summary:yj}),K({...xj,status:z(`blocked`),reason:yj,needs_root_decision:H}),K({...xj,status:z(`partial`),summary:yj,completed:W(yj),remaining:W(yj),needs_root_decision:H}),K({...xj,status:z(`failed`),error:yj}));const Sj=W(V),Cj=V.pipe(AO(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),wj=z(ce),Tj=K({code:FA,message:V,details:_j}),Ej=U(K({schema_version:wj,ok:z(!0),command:Cj,data:gj,warnings:Sj}),K({schema_version:wj,ok:z(!1),command:Cj,error:Tj,warnings:Sj}));function Dj(e){let t=yA(Ej,e);return Dn(t)?me(he(`CLI envelope`,t.left)):pe(t.right)}function Oj(e,t,n){return{key:`${e}:${t}`,role:e,task:t,model:`Luna`,effort:n}}const kj=new Set(tj),Aj={low:0,medium:1,high:2,xhigh:3,max:4},jj=[{plan:`plus-low`,rationale:`Preserve the approved plus-low route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`high`,"Librarian:lookup":`medium`,"Librarian:research":`high`,"Worker:mechanical":`high`,"Worker:implementation":`high`,"Worker:integration":`xhigh`,"Worker:operations":`high`,"Reviewer:plan":`high`,"Reviewer:code":`xhigh`,"Reviewer:artifact":`high`}},{plan:`plus`,rationale:`Preserve the approved plus route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`high`,"Librarian:lookup":`medium`,"Librarian:research":`high`,"Worker:mechanical":`high`,"Worker:implementation":`xhigh`,"Worker:integration":`xhigh`,"Worker:operations":`high`,"Reviewer:plan":`high`,"Reviewer:code":`xhigh`,"Reviewer:artifact":`high`}},{plan:`plus-high`,rationale:`Preserve the approved plus-high route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`xhigh`,"Librarian:lookup":`medium`,"Librarian:research":`xhigh`,"Worker:mechanical":`high`,"Worker:implementation":`xhigh`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`xhigh`,"Reviewer:code":`max`,"Reviewer:artifact":`xhigh`}},{plan:`pro-5x`,rationale:`Preserve the approved pro-5x route effort policy.`,efforts:{"Explorer:lookup":`high`,"Explorer:trace":`xhigh`,"Librarian:lookup":`high`,"Librarian:research":`xhigh`,"Worker:mechanical":`high`,"Worker:implementation":`max`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`xhigh`,"Reviewer:code":`max`,"Reviewer:artifact":`xhigh`}},{plan:`pro-20x`,rationale:`Preserve the approved pro-20x route effort policy.`,efforts:{"Explorer:lookup":`high`,"Explorer:trace":`xhigh`,"Librarian:lookup":`high`,"Librarian:research":`max`,"Worker:mechanical":`xhigh`,"Worker:implementation":`max`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`max`,"Reviewer:code":`max`,"Reviewer:artifact":`max`}}];ue(jj);const Mj=new Map(jj.map(e=>[e.plan,e]));function Nj(e){let t=Mj.get(e);if(t===void 0)throw new fe(`catalog_invalid`,`A specialist plan has no route effort policy.`,{plan:e});return HA.flatMap(n=>n.tasks.map(r=>{let i=`${n.role}:${r.name}`,a=t.efforts[i];if(a===void 0)throw new fe(`catalog_invalid`,`A route effort policy is incomplete.`,{plan:e,route:i});return Oj(n.role,r.name,a)}))}function Pj(e){return{...e,specialistModel:`Luna`,defaultServiceTier:`standard`,routes:Nj(e.name)}}const Fj=[{name:`go`,root:{model:`Terra`,effort:`high`},specialistModel:`Luna`,defaultServiceTier:`standard`,routes:Nj(`plus-low`)},Pj({name:`plus-low`,root:{model:`Sol`,effort:`low`}}),Pj({name:`plus`,root:{model:`Sol`,effort:`medium`}}),Pj({name:`plus-high`,root:{model:`Sol`,effort:`high`}}),Pj({name:`pro-5x`,root:{model:`Sol`,effort:`high`}}),Pj({name:`pro-20x`,root:{model:`Sol`,effort:`xhigh`}})];function Ij(e){let t=[`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`];if(e.length!==t.length)throw new fe(`catalog_invalid`,`The plan catalog has an invalid size.`);for(let n=0;n<t.length;n+=1){let r=e[n],i=t[n];if(!r||r.name!==i)throw new fe(`catalog_invalid`,`The plan catalog order is invalid.`,{index:n});let a=r.name===`go`?{model:`Terra`,effort:`high`}:r.name===`plus-low`?{model:`Sol`,effort:`low`}:r.name===`plus`?{model:`Sol`,effort:`medium`}:r.name===`pro-20x`?{model:`Sol`,effort:`xhigh`}:{model:`Sol`,effort:`high`};if(r.root.model!==a.model||r.root.effort!==a.effort)throw new fe(`catalog_invalid`,`A plan has an invalid Root route.`,{plan:r.name});if(r.specialistModel!==`Luna`||r.defaultServiceTier!==`standard`)throw new fe(`catalog_invalid`,`A plan has an invalid specialist policy.`,{plan:r.name});if(r.routes.length!==tj.length)throw new fe(`catalog_invalid`,`A specialist plan is incomplete.`,{plan:r.name});let o=new Set;for(let e of r.routes){if(o.has(e.key)||!kj.has(e.key)||e.model!==`Luna`||`${e.role}:${e.task}`!==e.key)throw new fe(`catalog_invalid`,`A plan contains an invalid route.`,{plan:r.name});o.add(e.key)}if(o.size!==tj.length)throw new fe(`catalog_invalid`,`A plan is missing a specialist route.`,{plan:r.name})}let n=e[0]?.routes,r=e[1]?.routes;if(!n||!r||n.length!==r.length||n.some((e,t)=>e.key!==r[t]?.key||e.model!==r[t]?.model||e.effort!==r[t]?.effort))throw new fe(`catalog_invalid`,`go must use the plus-low specialist route matrix.`);let i=e;for(let e=0;e<tj.length;e+=1){let t=-1;for(let n of i){let r=n.routes[e];if(!r||Aj[r.effort]<t)throw new fe(`catalog_invalid`,`Plan route effort is not monotonic.`,{route:tj[e]??`unknown`});t=Aj[r.effort]}}}Ij(Fj),ue(Fj);const Lj=Fj,Rj=new Map,zj=new Map;for(let e of Lj){Rj.set(e.name,e);let t=new Map;for(let n of e.routes)t.set(n.key,n);zj.set(e.name,t)}function Bj(e){let t=yA(zA,e);if(Dn(t))return me(new fe(`invalid_plan`,`Unknown plan selection.`,{field:`plan`},{cause:t.left}));let n=Rj.get(t.right);return n?pe(n):me(new fe(`invalid_plan`,`Unknown plan selection.`,{plan:t.right}))}const Vj=Object.freeze([{name:`yes`,kind:`boolean`,usage:`--yes`,description:`Confirm installation.`},{name:`plan`,kind:`value`,usage:`--plan <go|plus-low|plus|plus-high|pro-5x|pro-20x>`,description:`Select routing (default: plus).`},{name:`tier`,kind:`value`,usage:`--tier <standard|fast|fast-all>`,description:`Select service handling (default: standard).`},{name:`work`,kind:`boolean`,usage:`--work / --no-work`,description:`Work plugins (default: false).`},{name:`frontend`,kind:`boolean`,usage:`--frontend / --no-frontend`,description:`Frontend plugins via build-web-apps (default: true).`},{name:`security`,kind:`boolean`,usage:`--security / --no-security`,description:`Security plugins (default: true).`},{name:`computer-use`,kind:`boolean`,usage:`--computer-use / --no-computer-use`,description:`Computer Use plugins (default: false).`},{name:`add-plugin`,kind:`value`,usage:`--add-plugin <id>`,description:`Add a Codex plugin; repeatable.`},{name:`json`,kind:`boolean`,usage:`--json`,description:`Emit one JSON envelope.`}]),Hj=new Set([`codex-home`,`plan`,`tier`,`add-plugin`]),Uj=new Set([`yes`,`json`,`verbose`,`dry-run`,`computer-use`,`no-computer-use`,`work`,`no-work`,`frontend`,`no-frontend`,`security`,`no-security`]);var Wj=class extends Error{code;details;constructor(e,t,n={}){super(t),this.name=`ArgumentError`,this.code=e,this.details=n}};function Gj(e){if(e.length===0)throw new Wj(`unknown_command`,`A command is required.`);if(e.includes(`-h`)||e.includes(`--help`)||e.includes(`--help=true`))return{command:`help`,positionals:[],options:{}};if(e[0]===`help`)return{command:`help`,positionals:e.slice(1),options:{}};if(e[0]===`-v`||e[0]===`--version`||e[0]===`--version=true`)return Gj([`version`,...e.slice(1)]);let t=e[0];if(t!==`install`&&t!==`doctor`&&t!==`remove`&&t!==`version`)throw new Wj(`unknown_command`,`Unknown command.`,{command:t??``});let n=[],r={};for(let t=1;t<e.length;t+=1){let i=e[t];if(i===void 0)continue;if(i===`-`||!i.startsWith(`-`)){n.push(i);continue}if(!i.startsWith(`--`)||i===`--`)throw new Wj(`invalid_argument`,`Short options are not supported.`,{option:i});let a=i.slice(2),o=a.indexOf(`=`),s=o>=0?a.slice(0,o):a,c=o>=0?a.slice(o+1):void 0,l=s.replaceAll(`_`,`-`);if(!Hj.has(l)&&!Uj.has(l))throw new Wj(`invalid_argument`,`Unknown option.`,{option:`--${s}`});if(Hj.has(l)){let n=c??e[t+1];if(n===void 0||n.length===0||n.startsWith(`-`))throw new Wj(`invalid_argument`,`Option --${s} requires a value.`,{option:`--${s}`});if(c===void 0&&(t+=1),l===`add-plugin`){let e=r[l];r[l]=Array.isArray(e)?[...e,n]:[n]}else{if(r[l]!==void 0)throw new Wj(`invalid_argument`,`Option --${s} may only be supplied once.`,{option:`--${s}`});r[l]=n}continue}if(c!==void 0&&c!==`true`&&c!==`false`)throw new Wj(`invalid_argument`,`Option --${s} is boolean.`,{option:`--${s}`});if(r[l]!==void 0)throw new Wj(`invalid_argument`,`Option --${s} may only be supplied once.`,{option:`--${s}`});r[l]=c!==`false`}return Kj(t,n,r),{command:t,positionals:n,options:r}}function Kj(e,t,n){let r=qj(e);for(let t of Object.keys(n))if(!r.has(t))throw new Wj(`invalid_argument`,`Option --${t} is not valid for ${e}.`,{option:`--${t}`});let i=e===`version`?{min:0,max:1}:{min:0,max:0};if(t.length<i.min||t.length>i.max)throw new Wj(`invalid_argument`,`Invalid positional arguments for ${e}.`);let a=n.plan;if(typeof a==`string`&&!Bj(a).ok)throw new Wj(`invalid_argument`,`The plan is not supported.`,{plan:a});let o=n.tier;if(typeof o==`string`&&o!==`standard`&&o!==`fast`&&o!==`fast-all`)throw new Wj(`invalid_argument`,`The tier is not supported.`,{tier:o});for(let[e,t]of[[`computer-use`,`no-computer-use`],[`work`,`no-work`],[`frontend`,`no-frontend`],[`security`,`no-security`]])if(n[e]!==void 0&&n[t]!==void 0)throw new Wj(`invalid_argument`,`Conflicting --${e} and --${t} options.`);if(e===`install`&&n.yes===!1)throw new Wj(`invalid_argument`,`--yes cannot be false.`);if(e!==`install`&&Object.keys(n).some(e=>[`plan`,`tier`,`work`,`no-work`,`frontend`,`no-frontend`,`security`,`no-security`,`computer-use`,`no-computer-use`,`add-plugin`].includes(e)))throw new Wj(`invalid_argument`,`Installation options are not valid for ${e}.`)}function qj(e){switch(e){case`install`:return new Set([...Vj.map(e=>e.name),`no-work`,`no-frontend`,`no-security`,`no-computer-use`,`codex-home`,`verbose`]);case`doctor`:return new Set([`json`,`verbose`,`codex-home`]);case`remove`:return new Set([`yes`,`json`,`verbose`,`codex-home`]);case`version`:return new Set([`json`,`verbose`,`dry-run`]);default:return new Set}}const Jj=`Install HolyCodex through Codex native plugin management.
20
+ `)}`:this.toString()}}),e}(),pb=function(){return class extends fb{constructor(e){super(),e&&Object.assign(this,e)}}}(),mb=e=>{class t extends pb{_tag=e}return t.prototype.name=e,t},mb(`NoSuchElementException`),mb(`TimeoutException`)})),gb,_b,vb,yb,bb,xb,Sb=v((()=>{Ie(),Vh(),gb=class e{scheduleDrain;running=!1;tasks=new _b;constructor(e){this.scheduleDrain=e}starveInternal=e=>{let t=this.tasks.buckets;this.tasks.buckets=[];for(let[e,n]of t)for(let e=0;e<n.length;e++)n[e]();this.tasks.buckets.length===0?this.running=!1:this.starve(e)};starve(e=0){this.scheduleDrain(e,this.starveInternal)}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running||(this.running=!0,this.starve())}static cached(t){let n=new e(t),r=new WeakMap;return i=>{if(i===void 0)return n;let a=r.get(i);return a===void 0&&(a=new e(t),r.set(i,a)),a}}},_b=class{buckets=[];scheduleTask(e,t){let n=this.buckets.length,r,i=0;for(;i<n&&this.buckets[i][0]<=t;i++)r=this.buckets[i];r&&r[0]===t?r[1].push(e):i===n?this.buckets.push([t,[e]]):this.buckets.splice(i,0,[t,[e]])}},vb=class{maxNextTickBeforeTimer;getRunner=gb.cached((e,t)=>{e>=this.maxNextTickBeforeTimer?setTimeout(()=>t(0),0):Promise.resolve(void 0).then(()=>t(e+1))});constructor(e){this.maxNextTickBeforeTimer=e}shouldYield(e){return e.currentOpCount>e.getFiberRef(Vm)&&e.getFiberRef(Bm)}scheduleTask(e,t,n){this.getRunner(n).scheduleTask(e,t)}},yb=C(Symbol.for(`effect/Scheduler/defaultScheduler`),()=>new vb(2048)),bb=class{tasks=new _b;deferred=!1;scheduleTask(e,t,n){this.deferred?yb.scheduleTask(e,t,n):this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(Vm)&&e.getFiberRef(Bm)}flush(){for(;this.tasks.buckets.length>0;){let e=this.tasks.buckets;this.tasks.buckets=[];for(let[t,n]of e)for(let e=0;e<n.length;e++)n[e]()}this.deferred=!0}},xb=C(Symbol.for(`effect/FiberRef/currentScheduler`),()=>Nm(yb))})),Cb,wb=v((()=>{Ie(),Vh(),Cb=C(Symbol.for(`effect/FiberRef/currentRequestMap`),()=>Nm(new Map))})),Tb,Eb=v((()=>{Vh(),Tb=(e,t,n,r)=>{switch(e){case void 0:return t();case`unbounded`:return n();case`inherit`:return km(Km,e=>e===`unbounded`?n():e>1?r(e):t());default:return e>1?r(e):t()}}})),Db,Ob,kb=v((()=>{Db=e=>e.replace(/[\s="]/g,`_`),Ob=e=>t=>`${Db(t.label)}=${e-t.startTime}ms`})),Ab,jb,Mb,Nb,Pb,Fb=v((()=>{M(),Mt(),F(),T(),Ab=`effect/MetricLabel`,jb=Symbol.for(Ab),Mb=class{key;value;[jb]=jb;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=Ot(Ab+this.key+this.value)}[E](){return this._hash}[j](e){return Pb(e)&&this.key===e.key&&this.value===e.value}pipe(){return P(this,arguments)}},Nb=(e,t)=>new Mb(e,t),Pb=e=>w(e,jb)})),Ib,Lb=v((()=>{il(),Rr(),A_(),Ib=kr(e=>Qc(e.context,k_)?e._tag===`Span`?Ib(e.parent):R():z(e))})),Rb,zb=v((()=>{Vh(),Rb=_h})),Bb,Vb,Hb,Ub,Wb,Gb,Kb,qb,Jb=v((()=>{Bb=`InterruptSignal`,Vb=`Stateful`,Hb=`Resume`,Ub=`YieldNow`,Wb=e=>({_tag:Bb,cause:e}),Gb=e=>({_tag:Vb,onFiber:e}),Kb=e=>({_tag:Hb,effect:e}),qb=()=>({_tag:Ub})})),Yb,Xb,Zb,Qb,$b,ex,tx=v((()=>{bu(),Ie(),Jb(),Yb=`effect/FiberScope`,Xb=Symbol.for(Yb),Zb=class{[Xb]=Xb;fiberId=mu;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}},Qb=class{fiberId;parent;[Xb]=Xb;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell(Gb(e=>{e.addChild(t),t.addObserver(()=>{e.removeChild(t)})}))}},$b=e=>new Qb(e.id(),e),ex=C(Symbol.for(`effect/FiberScope/Global`),()=>new Zb)})),nx,rx,ix,ax,ox,sx,cx,lx,ux=v((()=>{bu(),Rr(),F(),Vh(),On(),nx=`effect/Fiber`,rx=Symbol.for(nx),ix={_E:e=>e,_A:e=>e},ax={[rx]:ix,pipe(){return P(this,arguments)}},ox=`effect/Fiber`,sx=Symbol.for(ox),cx=e=>pm(Wp(e.await),e.inheritAll),{...Tn},{...ax},lx=`effect/FiberCurrent`})),dx,fx,px,mx,hx,gx,_x,vx,yx,bx,xx=v((()=>{Pi(),Xt(),F(),bc(),pu(),kb(),dx=`effect/Logger`,fx=Symbol.for(dx),px={_Message:e=>e,_Output:e=>e},mx=e=>({[fx]:px,log:e,pipe(){return P(this,arguments)}}),hx=/^[^\s"=]*$/,gx=(e,t)=>({annotations:n,cause:r,date:i,fiberId:a,logLevel:o,message:s,spans:c})=>{let l=t=>t.match(hx)?t:e(t),u=(e,t)=>`${Db(e)}=${l(t)}`,d=(e,t)=>` `+u(e,t),f=u(`timestamp`,i.toISOString());f+=d(`level`,o.label),f+=d(`fiber`,du(a));let p=Wr(s);for(let e=0;e<p.length;e++)f+=d(`message`,Ut(p[e],t));Vs(r)||(f+=d(`cause`,dc(r,{renderErrorCause:!0})));for(let e of c)f+=` `+Ob(i.getTime())(e);for(let[e,r]of n)f+=d(e,Ut(r,t));return f},_x=e=>`"${e.replace(/\\([\s\S])|(")/g,`\\$1$2`)}"`,vx=mx(gx(_x)),yx={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`},yx.gray,yx.blue,yx.green,yx.yellow,yx.red,yx.bgBrightRed,yx.black,bx=typeof process==`object`&&process!==null&&typeof process.stdout==`object`&&process.stdout!==null,bx&&process.stdout.isTTY,bx||`Deno`in globalThis})),Sx,Cx,wx,Tx,Ex,Dx,Ox=v((()=>{Pi(),Ba(),M(),S(),Mt(),F(),T(),Sx=`effect/MetricBoundaries`,Cx=Symbol.for(Sx),wx=class{values;[Cx]=Cx;constructor(e){this.values=e,this._hash=b(Ot(Sx),O(jt(this.values)))}_hash;[E](){return this._hash}[j](e){return Tx(e)&&A(this.values,e.values)}pipe(){return P(this,arguments)}},Tx=e=>w(e,Cx),Ex=e=>{let t=b(e,Jr(xa(1/0)),Mi);return new wx(t)},Dx=e=>b(Hr(e.count-1,t=>e.start*e.factor**+t),Oa,Ex)})),kx,Ax,jx,Mx,Nx,Px,Fx,Ix,Lx,Rx,zx,Bx,Vx,Hx,Ux,Wx,Gx,Kx,qx,Jx,Yx,Xx,Zx=v((()=>{M(),S(),Mt(),F(),T(),kx=`effect/MetricKeyType`,Ax=Symbol.for(kx),jx=`effect/MetricKeyType/Counter`,Mx=Symbol.for(jx),Nx=`effect/MetricKeyType/Frequency`,Px=Symbol.for(Nx),Fx=`effect/MetricKeyType/Gauge`,Ix=Symbol.for(Fx),Lx=`effect/MetricKeyType/Histogram`,Rx=Symbol.for(Lx),zx=`effect/MetricKeyType/Summary`,Bx=Symbol.for(zx),Vx={_In:e=>e,_Out:e=>e},Hx=class{incremental;bigint;[Ax]=Vx;[Mx]=Mx;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=Ot(jx)}_hash;[E](){return this._hash}[j](e){return Kx(e)}pipe(){return P(this,arguments)}},Ux=class{boundaries;[Ax]=Vx;[Rx]=Rx;constructor(e){this.boundaries=e,this._hash=b(Ot(Lx),O(D(this.boundaries)))}_hash;[E](){return this._hash}[j](e){return Yx(e)&&A(this.boundaries,e.boundaries)}pipe(){return P(this,arguments)}},Wx=e=>new Hx(e?.incremental??!1,e?.bigint??!1),Gx=e=>new Ux(e),Kx=e=>w(e,Mx),qx=e=>w(e,Px),Jx=e=>w(e,Ix),Yx=e=>w(e,Rx),Xx=e=>w(e,Bx)})),Qx,$x,eS,tS,nS,rS,iS,aS,oS,sS=v((()=>{Pi(),M(),S(),Mt(),Rr(),F(),T(),Zx(),Qx=`effect/MetricKey`,$x=Symbol.for(Qx),eS={_Type:e=>e},tS=Ai(A),nS=class{name;keyType;description;tags;[$x]=eS;constructor(e,t,n,r=[]){this.name=e,this.keyType=t,this.description=n,this.tags=r,this._hash=b(Ot(this.name+this.description),O(D(this.keyType)),O(jt(this.tags)))}_hash;[E](){return this._hash}[j](e){return rS(e)&&this.name===e.name&&A(this.keyType,e.keyType)&&A(this.description,e.description)&&tS(this.tags,e.tags)}pipe(){return P(this,arguments)}},rS=e=>w(e,$x),iS=(e,t)=>new nS(e,Wx(t),wr(t?.description)),aS=(e,t,n)=>new nS(e,Gx(t),wr(n)),oS=x(2,(e,t)=>t.length===0?e:new nS(e.name,e.keyType,e.description,xi(e.tags,t)))})),cS,lS,uS,dS,fS,pS,mS,hS,gS,_S,vS=v((()=>{M(),S(),Mt(),Xt(),Rr(),F(),cS=Symbol.for(`effect/MutableHashMap`),lS={[cS]:cS,[Symbol.iterator](){return new uS(this)},toString(){return Ht(this.toJSON())},toJSON(){return{_id:`MutableHashMap`,values:Array.from(this).map(Bt)}},[N](){return this.toJSON()},pipe(){return P(this,arguments)}},uS=class e{self;referentialIterator;bucketIterator;constructor(e){this.self=e,this.referentialIterator=e.referential[Symbol.iterator]()}next(){if(this.bucketIterator!==void 0)return this.bucketIterator.next();let e=this.referentialIterator.next();return e.done?(this.bucketIterator=new dS(this.self.buckets.values()),this.next()):e}[Symbol.iterator](){return new e(this.self)}},dS=class{backing;constructor(e){this.backing=e}currentBucket;next(){if(this.currentBucket===void 0){let e=this.backing.next();if(e.done)return e;this.currentBucket=e.value[Symbol.iterator]()}let e=this.currentBucket.next();return e.done?(this.currentBucket=void 0,this.next()):e}},fS=()=>{let e=Object.create(lS);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e},pS=x(2,(e,t)=>{if(Pt(t)===!1)return e.referential.has(t)?z(e.referential.get(t)):R();let n=t[E](),r=e.buckets.get(n);return r===void 0?R():mS(e,r,t)}),mS=(e,t,n,r=!1)=>{for(let i=0,a=t.length;i<a;i++)if(n[j](t[i][0])){let n=t[i][1];return r&&(t.splice(i,1),e.bucketsSize--),z(n)}return R()},hS=x(2,(e,t)=>yr(pS(e,t))),gS=x(3,(e,t,n)=>{if(Pt(t)===!1)return e.referential.set(t,n),e;let r=t[E](),i=e.buckets.get(r);return i===void 0?(e.buckets.set(r,[[t,n]]),e.bucketsSize++,e):(_S(e,i,t),i.push([t,n]),e.bucketsSize++,e)}),_S=(e,t,n)=>{for(let r=0,i=t.length;r<i;r++)if(n[j](t[r][0])){t.splice(r,1),e.bucketsSize--;return}}})),yS,bS,xS,SS,CS,wS,TS,ES,DS,OS,kS,AS,jS,MS,NS,PS,FS,IS,LS,RS,zS,BS,VS,HS,US,WS,GS,KS,qS,JS=v((()=>{Pi(),M(),S(),Mt(),F(),T(),yS=`effect/MetricState`,bS=Symbol.for(yS),xS=`effect/MetricState/Counter`,SS=Symbol.for(xS),CS=`effect/MetricState/Frequency`,wS=Symbol.for(CS),TS=`effect/MetricState/Gauge`,ES=Symbol.for(TS),DS=`effect/MetricState/Histogram`,OS=Symbol.for(DS),kS=`effect/MetricState/Summary`,AS=Symbol.for(kS),jS={_A:e=>e},MS=class{count;[bS]=jS;[SS]=SS;constructor(e){this.count=e}[E](){return b(D(xS),O(D(this.count)),k(this))}[j](e){return US(e)&&this.count===e.count}pipe(){return P(this,arguments)}},NS=Ai(A),PS=class{occurrences;[bS]=jS;[wS]=wS;constructor(e){this.occurrences=e}_hash;[E](){return b(Ot(CS),O(jt(Ur(this.occurrences.entries()))),k(this))}[j](e){return WS(e)&&NS(Ur(this.occurrences.entries()),Ur(e.occurrences.entries()))}pipe(){return P(this,arguments)}},FS=class{value;[bS]=jS;[ES]=ES;constructor(e){this.value=e}[E](){return b(D(TS),O(D(this.value)),k(this))}[j](e){return GS(e)&&this.value===e.value}pipe(){return P(this,arguments)}},IS=class{buckets;count;min;max;sum;[bS]=jS;[OS]=OS;constructor(e,t,n,r,i){this.buckets=e,this.count=t,this.min=n,this.max=r,this.sum=i}[E](){return b(D(DS),O(D(this.buckets)),O(D(this.count)),O(D(this.min)),O(D(this.max)),O(D(this.sum)),k(this))}[j](e){return KS(e)&&A(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return P(this,arguments)}},LS=class{error;quantiles;count;min;max;sum;[bS]=jS;[AS]=AS;constructor(e,t,n,r,i,a){this.error=e,this.quantiles=t,this.count=n,this.min=r,this.max=i,this.sum=a}[E](){return b(D(kS),O(D(this.error)),O(D(this.quantiles)),O(D(this.count)),O(D(this.min)),O(D(this.max)),O(D(this.sum)),k(this))}[j](e){return qS(e)&&this.error===e.error&&A(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return P(this,arguments)}},RS=e=>new MS(e),zS=e=>new PS(e),BS=e=>new FS(e),VS=e=>new IS(e.buckets,e.count,e.min,e.max,e.sum),HS=e=>new LS(e.error,e.quantiles,e.count,e.min,e.max,e.sum),US=e=>w(e,SS),WS=e=>w(e,wS),GS=e=>w(e,ES),KS=e=>w(e,OS),qS=e=>w(e,AS)})),YS,XS,ZS,QS,$S,eC,tC,nC,rC,iC,aC,oC,sC=v((()=>{Pi(),Ul(),S(),xg(),Rr(),F(),JS(),YS=`effect/MetricHook`,XS=Symbol.for(YS),ZS={_In:e=>e,_Out:e=>e},QS=e=>({[XS]:ZS,pipe(){return P(this,arguments)},...e}),$S=BigInt(0),eC=e=>{let t=e.keyType.bigint?$S:0,n=e.keyType.incremental?e.keyType.bigint?e=>e>=$S:e=>e>=0:e=>!0,r=e=>{n(e)&&(t+=e)};return QS({get:()=>RS(t),update:r,modify:r})},tC=e=>{let t=new Map;for(let n of e.keyType.preregisteredWords)t.set(n,0);let n=e=>{let n=t.get(e)??0;t.set(e,n+1)};return QS({get:()=>zS(t),update:n,modify:n})},nC=(e,t)=>{let n=t;return QS({get:()=>BS(n),update:e=>{n=e},modify:e=>{n+=e}})},rC=e=>{let t=e.keyType.boundaries.values,n=t.length,r=new Uint32Array(n+1),i=new Float64Array(n),a=0,o=0,s=Number.MAX_VALUE,c=Number.MIN_VALUE;b(t,pi(yg),wi((e,t)=>{i[t]=e}));let l=e=>{let t=0,l=n;for(;t!==l;){let n=Math.floor(t+(l-t)/2);e<=i[n]?l=n:t=n,l===t+1&&(e<=i[t]?l=t:t=l)}r[t]=r[t]+1,a+=1,o+=e,e<s&&(s=e),e>c&&(c=e)},u=()=>{let e=Vr(n),t=0;for(let a=0;a<n;a++){let n=i[a],o=r[a];t+=o,e[a]=[n,t]}return e};return QS({get:()=>VS({buckets:u(),count:a,min:s,max:c,sum:o}),update:l,modify:l})},iC=e=>{let{error:t,maxAge:n,maxSize:r,quantiles:i}=e.keyType,a=b(i,pi(yg)),o=Vr(r),s=0,c=0,l=0,u=0,d=0,f=e=>{let i=[],s=0;for(;s!==r-1;){let t=o[s];if(t!=null){let[r,a]=t,o=Tl(e-r);zl(o,xl)&&Rl(o,n)&&i.push(a)}s+=1}return aC(t,a,pi(i,yg))},p=(e,t)=>{if(r>0){s+=1;let n=s%r;o[n]=[t,e]}u=c===0?e:Math.min(u,e),d=c===0?e:Math.max(d,e),c+=1,l+=e};return QS({get:()=>HS({error:t,quantiles:f(Date.now()),count:c,min:u,max:d,sum:l}),update:([e,t])=>p(e,t),modify:([e,t])=>p(e,t)})},aC=(e,t,n)=>{let r=n.length;if(!$r(t))return Si();let i=t[0],a=t.slice(1),o=oC(e,r,R(),0,i,n),s=Ci(o);return a.forEach(t=>{s.push(oC(e,r,o.value,o.consumed,t,o.rest))}),wi(s,e=>[e.quantile,e.value])},oC=(e,t,n,r,i,a)=>{let o=e,s=t,c=n,l=r,u=i,d=a,f=e,p=t,m=n,h=r,g=i,_=a;for(;;){if(!$r(d))return{quantile:u,value:R(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:z(si(d)),consumed:l+d.length,rest:[]};let e=ai(d),t=ui(d,t=>t===e),n=u*s,r=o/2*n,i=l+t[0].length,a=Math.abs(i-n);if(i<n-r){f=o,p=s,m=ii(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue}if(i>n+r){let t=vr(c)?z(e):c;return{quantile:u,value:t,consumed:l,rest:d}}switch(c._tag){case`None`:f=o,p=s,m=ii(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue;case`Some`:if(a<Math.abs(n-c.value)){f=o,p=s,m=ii(d),h=i,g=u,_=t[1],o=f,s=p,c=m,l=h,u=g,d=_;continue}return{quantile:u,value:z(c.value),consumed:l,rest:d}}}throw Error(`BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues`)}})),cC,lC,uC,dC,fC=v((()=>{F(),cC=`effect/MetricPair`,lC=Symbol.for(cC),uC={_Type:e=>e},dC=(e,t)=>({[lC]:uC,metricKey:e,metricState:t,pipe(){return P(this,arguments)}})})),pC,mC,hC,gC,_C=v((()=>{S(),vS(),Rr(),sC(),Zx(),fC(),pC=`effect/MetricRegistry`,mC=Symbol.for(pC),hC=class{[mC]=mC;map=fS();snapshot(){let e=[];for(let[t,n]of this.map)e.push(dC(t,n.get()));return e}get(e){let t=b(this.map,pS(e),Tr);if(t==null){if(Kx(e.keyType))return this.getCounter(e);if(Jx(e.keyType))return this.getGauge(e);if(qx(e.keyType))return this.getFrequency(e);if(Yx(e.keyType))return this.getHistogram(e);if(Xx(e.keyType))return this.getSummary(e);throw Error(`BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues`)}return t}getCounter(e){let t=b(this.map,pS(e),Tr);if(t==null){let n=eC(e);b(this.map,hS(e))||b(this.map,gS(e,n)),t=n}return t}getFrequency(e){let t=b(this.map,pS(e),Tr);if(t==null){let n=tC(e);b(this.map,hS(e))||b(this.map,gS(e,n)),t=n}return t}getGauge(e){let t=b(this.map,pS(e),Tr);if(t==null){let n=nC(e,e.keyType.bigint?BigInt(0):0);b(this.map,hS(e))||b(this.map,gS(e,n)),t=n}return t}getHistogram(e){let t=b(this.map,pS(e),Tr);if(t==null){let n=rC(e);b(this.map,hS(e))||b(this.map,gS(e,n)),t=n}return t}getSummary(e){let t=b(this.map,pS(e),Tr);if(t==null){let n=iC(e);b(this.map,hS(e))||b(this.map,gS(e,n)),t=n}return t}},gC=()=>new hC})),vC,yC,bC,xC,SC,CC,wC,TC,EC,DC,OC,kC=v((()=>{Pi(),S(),Ie(),F(),Vh(),sS(),Fb(),_C(),vC=`effect/Metric`,yC=Symbol.for(vC),bC={_Type:e=>e,_In:e=>e,_Out:e=>e},xC=C(Symbol.for(`effect/Metric/globalMetricRegistry`),()=>gC()),SC=function(e,t,n,r){let i=Object.assign(e=>im(e,e=>OC(i,e)),{[yC]:bC,keyType:e,unsafeUpdate:t,unsafeValue:n,unsafeModify:r,register(){return this.unsafeValue([]),this},pipe(){return P(this,arguments)}});return i},CC=(e,t)=>wC(iS(e,t)),wC=e=>{let t,n=new WeakMap,r=r=>{if(r.length===0)return t===void 0&&(t=xC.get(e)),t;let i=n.get(r);return i===void 0?(i=xC.get(oS(e,r)),n.set(r,i),i):i};return SC(e.keyType,(e,t)=>r(t).update(e),e=>r(e).get(),(e,t)=>r(t).modify(e))},TC=(e,t,n)=>wC(aS(e,t,n)),EC=x(3,(e,t,n)=>DC(e,[Nb(t,n)])),DC=x(2,(e,t)=>SC(e.keyType,(n,r)=>e.unsafeUpdate(n,xi(t,r)),n=>e.unsafeValue(xi(t,n)),(n,r)=>e.unsafeModify(n,xi(t,r)))),OC=x(2,(e,t)=>km(Xm,n=>V(()=>e.unsafeUpdate(t,n))))})),AC,jC=v((()=>{S(),wb(),Vh(),On(),{...wn},AC=x(2,(e,t)=>km(Cb,n=>V(()=>{if(n.has(e)){let r=n.get(e);r.state.completed||(r.state.completed=!0,Nh(r.result,t))}})))})),MC,NC,PC,FC,IC,LC,RC,zC,BC,VC=v((()=>{S(),Ie(),T(),Vh(),MC=`effect/Supervisor`,NC=Symbol.for(MC),PC={_T:e=>e},FC=class e{underlying;value0;[NC]=PC;constructor(e,t){this.underlying=e,this.value0=t}get value(){return this.value0}onStart(e,t,n,r){this.underlying.onStart(e,t,n,r)}onEnd(e,t){this.underlying.onEnd(e,t)}onEffect(e,t){this.underlying.onEffect(e,t)}onSuspend(e){this.underlying.onSuspend(e)}onResume(e){this.underlying.onResume(e)}map(t){return new e(this,b(this.value,Zp(t)))}zip(e){return new IC(this,e)}},IC=class e{left;right;_tag=`Zip`;[NC]=PC;constructor(e,t){this.left=e,this.right=t}get value(){return fm(this.left.value,this.right.value)}onStart(e,t,n,r){this.left.onStart(e,t,n,r),this.right.onStart(e,t,n,r)}onEnd(e,t){this.left.onEnd(e,t),this.right.onEnd(e,t)}onEffect(e,t){this.left.onEffect(e,t),this.right.onEffect(e,t)}onSuspend(e){this.left.onSuspend(e),this.right.onSuspend(e)}onResume(e){this.left.onResume(e),this.right.onResume(e)}map(e){return new FC(this,b(this.value,Zp(e)))}zip(t){return new e(this,t)}},LC=e=>w(e,NC)&&Je(e,`Zip`),RC=class{effect;[NC]=PC;constructor(e){this.effect=e}get value(){return this.effect}onStart(e,t,n,r){}onEnd(e,t){}onEffect(e,t){}onSuspend(e){}onResume(e){}map(e){return new FC(this,b(this.value,Zp(e)))}zip(e){return new IC(this,e)}onRun(e,t){return e()}},zC=e=>new RC(e),BC=C(`effect/Supervisor/none`,()=>zC(cm))})),HC,UC=v((()=>{af(),HC=Qd})),WC,GC,KC,qC,JC,YC,XC,ZC,QC,$C,ew,tw,nw=v((()=>{Ba(),UC(),M(),S(),Cs(),VC(),WC=`Empty`,GC=`AddSupervisor`,KC=`RemoveSupervisor`,qC=`AndThen`,JC={_tag:WC},YC=(e,t)=>({_tag:qC,first:e,second:t}),XC=(e,t)=>ZC(t,xa(e)),ZC=(e,t)=>{let n=e,r=t;for(;Ia(r);){let e=Ra(r);switch(e._tag){case WC:r=za(r);break;case GC:n=n.zip(e.supervisor),r=za(r);break;case KC:n=QC(n,e.supervisor),r=za(r);break;case qC:r=Ma(e.first)(Ma(e.second)(za(r)))}}return n},QC=(e,t)=>A(e,t)?BC:LC(e)?QC(e.left,t).zip(QC(e.right,t)):e,$C=e=>A(e,BC)?ps():LC(e)?b($C(e.left),xs($C(e.right))):hs(e),ew=(e,t)=>{if(A(e,t))return JC;let n=$C(e),r=$C(t),i=b(r,bs(n),Ss(JC,(e,t)=>YC(e,{_tag:GC,supervisor:t}))),a=b(n,bs(r),Ss(JC,(e,t)=>YC(e,{_tag:KC,supervisor:t})));return YC(i,a)},tw=HC({empty:JC,patch:XC,combine:YC,diff:ew})})),rw,iw,aw,ow,sw,cw,lw,uw,dw,fw,pw,mw,hw,gw,_w,vw,yw,bw,xw,Sw,Cw,ww,Tw,Ew,Dw,Ow,kw,Aw,jw,Mw,Nw,Pw,Fw,Iw,Lw,Rw,zw,Bw,Vw,Hw,Uw,Ww,Gw,Kw,qw,Jw=v((()=>{Pi(),Ba(),il(),B_(),$_(),bu(),vv(),Av(),Xv(),S(),Ie(),Cs(),Xt(),cy(),hb(),Rr(),F(),T(),Pf(),Sb(),St(),np(),bc(),vg(),wb(),Eb(),Lb(),Vh(),N_(),p_(),Y_(),ux(),Jb(),mv(),tx(),xx(),kC(),Ox(),fn(),jC(),Af(),VC(),nw(),A_(),hn(),rw=CC(`effect_fiber_started`,{incremental:!0}),iw=CC(`effect_fiber_active`),aw=CC(`effect_fiber_successes`,{incremental:!0}),ow=CC(`effect_fiber_failures`,{incremental:!0}),sw=EC(TC(`effect_fiber_lifetimes`,Dx({start:.5,factor:2,count:35})),`time_unit`,`milliseconds`),cw=`Continue`,lw=`Done`,uw=`Yield`,dw={_E:e=>e,_A:e=>e},fw=e=>{throw Error(`BUG: FiberRuntime - ${Ut(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},pw=Symbol.for(`effect/internal/fiberRuntime/YieldedOp`),mw=C(`effect/internal/fiberRuntime/yieldedOpChannel`,()=>({currentOp:null})),hw={[tn]:(e,t,n)=>xt(()=>t.effect_instruction_i1(n)),OnStep:(e,t,n)=>Dh(Dh(n)),[nn]:(e,t,n)=>xt(()=>t.effect_instruction_i2(n)),[dn]:(e,t,n)=>(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),bf(e.currentRuntimeFlags)&&e.isInterrupted()?Ch(e.getInterruptedCause()):Dh(n)),[sn]:(e,t,n)=>(xt(()=>t.effect_instruction_i2(n)),xt(()=>t.effect_instruction_i0())?(e.pushStack(t),xt(()=>t.effect_instruction_i1())):cm),[cn]:(e,t,n)=>{for(;;){let r=xt(()=>t.effect_instruction_i0.next(n));if(r.done)return Dh(r.value);let i=ot(r.value);if(!gh(i))return e.pushStack(t),i;if(i._tag===`Failure`)return i;n=i.value}}},gw={[Bb]:(e,t,n,r)=>(e.processNewInterruptSignal(r.cause),bf(t)?Ch(r.cause):n),[Hb]:(e,t,n,r)=>{throw Error(`It is illegal to have multiple concurrent run loops in a single fiber`)},[Vb]:(e,t,n,r)=>(r.onFiber(e,qv(t)),n),[Ub]:(e,t,n,r)=>B(dm(),()=>n)},_w=e=>Yp(Lf(e),e=>Dw(tp(e),([e,t])=>{let n=new Map,r=[];for(let e of t){r.push(Ta(e));for(let t of e)n.set(t.request,t)}let i=r.flat();return Mm(qw(e.runAll(r),i,()=>i.forEach(e=>{e.listeners.interrupted=!0})),Cb,n)},!1,!1)),vw=mn(),yw=class extends z_{[rx]=ix;[sx]=dw;_fiberRefs;_fiberId;_queue=[];_children=null;_observers=[];_running=!1;_stack=[];_asyncInterruptor=null;_asyncBlockingOn=null;_exitValue=null;_steps=[];_isYielding=!1;currentRuntimeFlags;currentOpCount=0;currentSupervisor;currentScheduler;currentTracer;currentSpan;currentContext;currentDefaultServices;constructor(e,t,n){if(super(),this.currentRuntimeFlags=n,this._fiberId=e,this._fiberRefs=t,Tf(n)){let e=this.getFiberRef(Xm);rw.unsafeUpdate(1,e),iw.unsafeUpdate(1,e)}this.refreshRefCache()}commit(){return cx(this)}id(){return this._fiberId}resume(e){this.tell(Kb(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>Yv(t)?e.currentRuntimeFlags:t.runtimeFlags)}scope(){return $b(this)}get children(){return this.ask(e=>Array.from(e.getChildren()))}getChildren(){return this._children===null&&(this._children=new Set),this._children}getInterruptedCause(){return this.getFiberRef(Qm)}fiberRefs(){return this.ask(e=>e.getFiberRefs())}ask(e){return rm(()=>{let t=jh(this._fiberId);return this.tell(Gb((n,r)=>{Nh(t,V(()=>e(n,r)))})),Mh(t)})}tell(e){this._queue.push(e),this._running||(this._running=!0,this.drainQueueLaterOnExecutor())}get await(){return kp(e=>{let t=t=>e(nm(t));if(this._exitValue!==null){t(this._exitValue);return}return this.tell(Gb((e,n)=>{e._exitValue===null?e.addObserver(t):t(this._exitValue)})),V(()=>this.tell(Gb((e,n)=>{e.removeObserver(t)})))},this.id())}get inheritAll(){return Sp((e,t)=>{let n=e.id(),r=e.getFiberRefs(),i=t.runtimeFlags,a=this.getFiberRefs(),o=av(r,n,a);e.setFiberRefs(o);let s=e.getFiberRef(Ww),c=b(Df(i,s),Nf(1),Nf(16));return lm(c)})}get poll(){return V(()=>wr(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return V(()=>this.tell(Wb(Ls(e))))}unsafeInterruptAsFork(e){this.tell(Wb(Ls(e)))}addObserver(e){this._exitValue===null?this._observers.push(e):e(this._exitValue)}removeObserver(e){this._observers=this._observers.filter(t=>t!==e)}getFiberRefs(){return this.setFiberRef(Ww,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=cv(this._fiberRefs,e)}getFiberRef(e){return this._fiberRefs.locals.has(e)?this._fiberRefs.locals.get(e)[0][1]:e.initial}setFiberRef(e,t){this._fiberRefs=dv(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(M_),this.currentTracer=this.currentDefaultServices.unsafeMap.get(w_.key),this.currentSupervisor=this.getFiberRef(Gw),this.currentScheduler=this.getFiberRef(xb),this.currentContext=this.getFiberRef(zm),this.currentSpan=this.currentContext.unsafeMap.get(T_.key)}setFiberRefs(e){this._fiberRefs=e,this.refreshRefCache()}addChild(e){this.getChildren().add(e)}removeChild(e){this.getChildren().delete(e)}transferChildren(e){let t=this._children;if(this._children=null,t!==null&&t.size>0)for(let n of t)n._exitValue===null&&e.add(this.currentRuntimeFlags,n)}drainQueueOnCurrentThread(){let e=!0;for(;e;){let t=cw,n=globalThis[lx];globalThis[lx]=this;try{for(;t===cw;)t=this._queue.length===0?lw:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[lx]=n}this._queue.length>0&&!this._running?(this._running=!0,t===uw?(this.drainQueueLaterOnExecutor(),e=!1):e=!0):e=!1}}drainQueueLaterOnExecutor(){this.currentScheduler.scheduleTask(this.run,this.getFiberRef(Bm),this)}drainQueueWhileRunning(e,t){let n=t;for(;this._queue.length>0;){let t=this._queue.splice(0,1)[0];n=gw[t._tag](this,e,n,t)}return n}isInterrupted(){return!Us(this.getFiberRef(Qm))}addInterruptedCause(e){let t=this.getFiberRef(Qm);this.setFiberRef(Qm,zs(t,e))}processNewInterruptSignal(e){this.addInterruptedCause(e),this.sendInterruptSignalToAllChildren()}sendInterruptSignalToAllChildren(){if(this._children===null||this._children.size===0)return!1;let e=!1;for(let t of this._children)t.tell(Wb(Ls(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return um({while:()=>!t,body:()=>{let n=e.next();return n.done?V(()=>{t=!0}):Tp(n.value.await)},step:()=>{}})}return null}reportExitValue(e){if(Tf(this.currentRuntimeFlags)){let t=this.getFiberRef(Xm),n=this.id().startTimeMillis,r=Date.now();switch(sw.unsafeUpdate(r-n,t),iw.unsafeUpdate(-1,t),e._tag){case rn:aw.unsafeUpdate(1,t);break;case $t:ow.unsafeUpdate(1,t)}}if(e._tag===`Failure`){let t=this.getFiberRef(Jm);!Gs(e.cause)&&t._tag===`Some`&&this.log(`Fiber terminated with an unhandled error`,e.cause,t)}}setExitValue(e){this._exitValue=e,this.reportExitValue(e);for(let t=this._observers.length-1;t>=0;t--)this._observers[t](e);this._observers=[]}getLoggers(){return this.getFiberRef(ww)}log(e,t,n){let r=yr(n)?n.value:this.getFiberRef(Um),i=this.getFiberRef(bw);if(oy(i,r))return;let a=this.getFiberRef(Wm),o=this.getFiberRef(Hm),s=this.getLoggers(),c=this.getFiberRefs();if(_s(s)>0){let n=Qc(this.getFiberRef(M_),dg),i=new Date(n.unsafeCurrentTimeMillis());Jt(c,()=>{for(let n of s)n.log({fiberId:this.id(),logLevel:r,message:e,cause:t,context:c,spans:a,annotations:o,date:i})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case Ub:return uw;case Bb:return this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null&&(this._asyncInterruptor(Ch(e.cause)),this._asyncInterruptor=null),cw;case Hb:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),cw;case Vb:return e.onFiber(this,this._exitValue===null?Jv(this.currentRuntimeFlags,this._asyncBlockingOn):Kv),cw;default:return fw(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=bf(this.currentRuntimeFlags)&&this.isInterrupted()?Ch(this.getInterruptedCause()):e;for(;t!==null;){let e=t,n=this.runLoop(e);if(n===pw){let e=mw.currentOp;mw.currentOp=null,e._op===`Yield`?vf(this.currentRuntimeFlags)?(this.tell(qb()),this.tell(Kb(Oh)),t=null):t=Oh:e._op===`Async`&&(t=null)}else{this.currentRuntimeFlags=b(this.currentRuntimeFlags,yf(16));let e=this.interruptAllChildren();e===null?(this._queue.length===0?this.setExitValue(n):this.tell(Kb(n)),t=null):t=B(e,()=>n)}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(this._running)this.tell(Kb(e));else{this._running=!0;let t=globalThis[lx];globalThis[lx]=this;try{this.evaluateEffect(e)}finally{this._running=!1,globalThis[lx]=t,this._queue.length>0&&this.drainQueueLaterOnExecutor()}}}startFork(e){this.tell(Kb(e))}patchRuntimeFlags(e,t){let n=Of(e,t);return globalThis[lx]=this,this.currentRuntimeFlags=n,n}initiateAsync(e,t){let n=!1,r=e=>{n||(n=!0,this.tell(Kb(e)))};bf(e)&&(this._asyncInterruptor=r);try{t(r)}catch(e){r(zp(Is(e)))}}pushStack(e){this._stack.push(e),e._op===`OnStep`&&this._steps.push({refs:this.getFiberRefs(),flags:this.currentRuntimeFlags})}popStack(){let e=this._stack.pop();if(e)return e._op===`OnStep`&&this._steps.pop(),e}getNextSuccessCont(){let e=this.popStack();for(;e;){if(e._op!==`OnFailure`)return e;e=this.popStack()}}getNextFailCont(){let e=this.popStack();for(;e;){if(e._op!==`OnSuccess`&&e._op!==`While`&&e._op!==`Iterator`)return e;e=this.popStack()}}Tag(e){return V(()=>$c(this.currentContext,e))}Left(e){return Lp(e.left)}None(e){return Lp(new ph)}Right(e){return Dh(e.right)}Some(e){return Dh(e.value)}Micro(e){return Dp(t=>{let n=t,r=db(nb(e,this.currentContext));return r.addObserver(e=>{if(e._tag===`Success`)return n(Dh(e.value));switch(e.cause._tag){case`Interrupt`:return n(Ch(Ls(mu)));case`Fail`:return n(Lp(e.cause.error));case`Die`:return n(Np(e.cause.defect))}}),Dp(e=>{n=t=>{e(cm)},r.unsafeInterrupt()})})}[an](e){let t=xt(()=>e.effect_instruction_i0()),n=this.getNextSuccessCont();return n===void 0?(mw.currentOp=Dh(t),pw):(n._op in hw||fw(n),hw[n._op](this,n,t))}[rn](e){let t=e,n=this.getNextSuccessCont();return n===void 0?(mw.currentOp=t,pw):(n._op in hw||fw(n),hw[n._op](this,n,t.effect_instruction_i0))}[$t](e){let t=e.effect_instruction_i0,n=this.getNextFailCont();if(n!==void 0)switch(n._op){case en:case nn:return bf(this.currentRuntimeFlags)&&this.isInterrupted()?Ch(Qs(t)):xt(()=>n.effect_instruction_i1(t));case`OnStep`:return bf(this.currentRuntimeFlags)&&this.isInterrupted()?Ch(Qs(t)):Dh(Ch(t));case dn:return this.patchRuntimeFlags(this.currentRuntimeFlags,n.patch),bf(this.currentRuntimeFlags)&&this.isInterrupted()?Ch(zs(t,this.getInterruptedCause())):Ch(t);default:fw(n)}else return mw.currentOp=Ch(t),pw}[ln](e){return xt(()=>e.effect_instruction_i0(this,qv(this.currentRuntimeFlags)))}Blocked(e){let t=this.getFiberRefs(),n=this.currentRuntimeFlags;if(this._steps.length>0){let r=[],i=this._steps[this._steps.length-1],a=this.popStack();for(;a&&a._op!==`OnStep`;)r.push(a),a=this.popStack();this.setFiberRefs(i.refs),this.currentRuntimeFlags=i.flags;let o=Ov(i.refs,t),s=Df(i.flags,n);return Dh(mp(e.effect_instruction_i0,Sp(t=>{for(;r.length>0;)t.pushStack(r.pop());return t.setFiberRefs(kv(t.id(),t.getFiberRefs())(o)),t.currentRuntimeFlags=Of(s)(t.currentRuntimeFlags),e.effect_instruction_i1})))}return sm(t=>B(kw(hp(e.effect_instruction_i0)),()=>t(e.effect_instruction_i1)))}RunBlocked(e){return _w(e.effect_instruction_i0)}[on](e){let t=e.effect_instruction_i0,n=this.currentRuntimeFlags,r=Of(n,t);if(bf(r)&&this.isInterrupted())return Ch(this.getInterruptedCause());if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let t=Df(r,n);return this.pushStack(new _p(t,e)),xt(()=>e.effect_instruction_i1(n))}return Oh}[tn](e){return this.pushStack(e),e.effect_instruction_i0}OnStep(e){return this.pushStack(e),e.effect_instruction_i0}[en](e){return this.pushStack(e),e.effect_instruction_i0}[nn](e){return this.pushStack(e),e.effect_instruction_i0}[Zt](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),mw.currentOp=e,pw}[un](e){return this._isYielding=!1,mw.currentOp=e,pw}[sn](e){let t=e.effect_instruction_i0,n=e.effect_instruction_i1;return t()?(this.pushStack(e),n()):Oh}[cn](e){return hw[cn](this,e,void 0)}[Qt](e){return xt(()=>e.commit())}runLoop(e){let t=e;for(this.currentOpCount=0;;){if(this.currentRuntimeFlags&2&&this.currentSupervisor.onEffect(this,t),this._queue.length>0&&(t=this.drainQueueWhileRunning(this.currentRuntimeFlags,t)),!this._isYielding){this.currentOpCount+=1;let e=this.currentScheduler.shouldYield(this);if(e!==!1){this._isYielding=!0,this.currentOpCount=0;let n=t;t=B(dm({priority:e}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(vw!==t[gp]._V){let e=this.getFiberRef(Ym);if(e._tag===`Some`){let n=t[gp]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${mn()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`,Ps,e)}}return this[t._op](t)},this),t===pw){let e=mw.currentOp;return e._op===`Yield`||e._op===`Async`?pw:(mw.currentOp=null,e._op===`Success`||e._op===`Failure`?e:Ch(Is(e)))}}catch(e){t=t!==pw&&!w(t,`_op`)||!(t._op in this)?Pp(`Not a valid effect: ${Ut(t)}`):lh(e)?Ch(zs(Is(e),Ls(mu))):Np(e)}}}run=()=>{this.drainQueueOnCurrentThread()}},bw=C(`effect/FiberRef/currentMinimumLogLevel`,()=>Nm(sy(`Info`))),xw=e=>mx(t=>{let n=hv(t.context,M_);Qc(n,d_).unsafe.log(e.log(t))}),Sw=C(Symbol.for(`effect/Logger/defaultLogger`),()=>xw(vx)),Cw=C(Symbol.for(`effect/Logger/tracerLogger`),()=>mx(({annotations:e,cause:t,context:n,fiberId:r,logLevel:i,message:a})=>{let o=Ib(el(uv(n,zm),T_));if(o._tag===`None`||o.value._tag===`ExternalSpan`)return;let s=$c(uv(n,M_),dg),c={};for(let[t,n]of e)c[t]=n;c[`effect.fiberId`]=vu(r),c[`effect.logLevel`]=i.label,t!==null&&t._tag!==`Empty`&&(c[`effect.cause`]=dc(t,{renderErrorCause:!0})),o.value.event(Ut(Array.isArray(a)&&a.length===1?a[0]:a),s.unsafeCurrentTimeNanos(),c)})),ww=C(Symbol.for(`effect/FiberRef/currentLoggers`),()=>Pm(hs(Sw,Cw))),Tw=x(e=>$e(e[0]),(e,t,n)=>Sp(r=>{let i=n?.batching===!0||n?.batching===`inherit`&&r.getFiberRef(qm);return n?.discard?Tb(n.concurrency,()=>Iw(X_,n?.concurrentFinalizers)(n=>i?Dw(e,(e,r)=>n(t(e,r)),!0,!1,1):Yp(e,(e,r)=>n(t(e,r)))),()=>Iw(Z_,n?.concurrentFinalizers)(n=>Dw(e,(e,r)=>n(t(e,r)),i,!1)),r=>Iw(Q_(r),n?.concurrentFinalizers)(n=>Dw(e,(e,r)=>n(t(e,r)),i,!1,r))):Tb(n?.concurrency,()=>Iw(X_,n?.concurrentFinalizers)(n=>i?Ow(e,1,(e,r)=>n(t(e,r)),!0):Jp(e,(e,r)=>n(t(e,r)))),()=>Iw(Z_,n?.concurrentFinalizers)(n=>Ew(e,(e,r)=>n(t(e,r)),i)),r=>Iw(Q_(r),n?.concurrentFinalizers)(n=>Ow(e,r,(e,r)=>n(t(e,r)),i)))})),Ew=(e,t,n)=>rm(()=>{let r=Ur(e),i=Array(r.length);return mm(Dw(r,(e,n)=>B(t(e,n),e=>V(()=>i[n]=e)),n,!1),nm(i))}),Dw=(e,t,n,r,i)=>sm(a=>am(o=>Sp(s=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return cm;let u=0,d=!1,f=i?Math.min(c.length,i):c.length,p=new Set,m=[],h=()=>p.forEach(e=>{e.currentScheduler.scheduleTask(()=>{e.unsafeInterruptAsFork(s.id())},0,e)}),g=[],_=[],ee=[],te=()=>{let e=m.filter(({exit:e})=>e._tag===`Failure`).sort((e,t)=>e.index<t.index?-1:e.index===t.index?0:1).map(({exit:e})=>e);return e.length===0&&e.push(Oh),e},ne=(e,t=!1)=>{let n=om(o(e)),r=jw(n,s,s.currentRuntimeFlags,ex);return s.currentScheduler.scheduleTask(()=>{t&&r.unsafeInterruptAsFork(s.id()),r.resume(n)},0,r),r},re=()=>{r||(l-=c.length,c=[]),d=!0,h()},ie=n?Up:Ip,ae=ne(kp(e=>{let r=(e,t)=>{e._op===`Blocked`?ee.push(e):(m.push({index:t,exit:e}),e._op===`Failure`&&!d&&re())},o=()=>{if(c.length>0){let f=c.pop(),h=u++,re=()=>{let e=c.pop();return h=u++,B(dm(),()=>B(ie(a(t(e,h))),ae))},ae=e=>c.length>0&&(r(e,h),c.length>0)?re():nm(e),oe=B(ie(a(t(f,h))),ae),se=ne(oe);g.push(se),p.add(se),d&&se.currentScheduler.scheduleTask(()=>{se.unsafeInterruptAsFork(s.id())},0,se),se.addObserver(t=>{let a;if(a=t._op===`Failure`?t:t.effect_instruction_i0,_.push(se),p.delete(se),r(a,h),m.length===l)e(nm(xr(bh(te(),{parallel:!0}),()=>Oh)));else if(ee.length+m.length===l){let t=te(),r=ee.map(e=>e.effect_instruction_i0).reduce(Ff);e(nm(mp(r,Dw([xr(bh(t,{parallel:!0}),()=>Oh),...ee.map(e=>e.effect_instruction_i1)],e=>e,n,!0,i))))}else o()})}};for(let e=0;e<f;e++)o()}));return Tp(em(Wp(a(cx(ae))),Eh({onFailure:e=>{re();let t=ee.length+1,n=Math.min(typeof i==`number`?i:ee.length,ee.length),r=Array.from(ee);return kp(i=>{let a=[],o=0,s=0,c=(n,s)=>c=>{a[n]=c,o++,o===t&&i(Dh(Ch(e))),r.length>0&&s&&l()},l=()=>{ne(r.pop(),!0).addObserver(c(s,!0)),s++};ae.addObserver(c(s,!1)),s++;for(let e=0;e<n;e++)l()})},onSuccess:()=>Jp(_,e=>e.inheritAll)})))}))),Ow=(e,t,n,r)=>rm(()=>{let i=Ur(e),a=Array(i.length);return mm(Dw(i,(e,t)=>Zp(n(e,t),e=>a[t]=e),r,!1,t),nm(a))}),kw=e=>Nw(e,ex),Aw=(e,t,n,r=null)=>{let i=Mw(e,t,n,r);return i.resume(e),i},jw=(e,t,n,r=null)=>Mw(e,t,n,r),Mw=(e,t,n,r=null)=>{let i=yu(),a=t.getFiberRefs(),o=ov(a,i),s=new yw(i,o,n),c=uv(o,zm),l=s.currentSupervisor;return l.onStart(c,e,z(t),s),s.addObserver(e=>l.onEnd(e,s)),(r===null?b(t.getFiberRef(Zm),xr(()=>t.scope())):r).add(n,s),s},Nw=(e,t)=>Sp((n,r)=>nm(Aw(e,n,r.runtimeFlags,t))),Pw=e=>Lh(t=>br(el(t,Rw),{onNone:()=>e,onSome:t=>{switch(t.strategy._tag){case`Parallel`:return e;case`Sequential`:case`ParallelN`:return B(rh(t,Z_),t=>Hw(e,t))}}})),Fw=e=>t=>Lh(n=>br(el(n,Rw),{onNone:()=>t,onSome:n=>n.strategy._tag===`ParallelN`&&n.strategy.parallelism===e?t:B(rh(n,Q_(e)),e=>Hw(t,e))})),Iw=(e,t)=>n=>Lh(r=>br(el(r,Rw),{onNone:()=>n(be),onSome:r=>{if(t===!0){let t=e._tag===`Parallel`?Pw:e._tag===`Sequential`?Lw:Fw(e.parallelism);switch(r.strategy._tag){case`Parallel`:return t(n(Pw));case`Sequential`:return t(n(Lw));case`ParallelN`:return t(n(Fw(r.strategy.parallelism)))}}else return n(be)}})),Lw=e=>Lh(t=>br(el(t,Rw),{onNone:()=>e,onSome:t=>{switch(t.strategy._tag){case`Sequential`:return e;case`Parallel`:case`ParallelN`:return B(rh(t,X_),t=>Hw(e,t))}}})),Rw=Jc(`effect/Scope`),zw=(e,t)=>{e.state._tag===`Open`&&e.state.finalizers.set({},t)},Bw={[$m]:$m,[eh]:eh,pipe(){return P(this,arguments)},fork(e){return V(()=>{let t=Vw(e);if(this.state._tag===`Closed`)return t.state=this.state,t;let n={};return this.state.finalizers.set(n,e=>t.close(e)),zw(t,e=>V(()=>{this.state._tag===`Open`&&this.state.finalizers.delete(n)})),t})},close(e){return rm(()=>{if(this.state._tag===`Closed`)return cm;let t=Array.from(this.state.finalizers.values()).reverse();return this.state={_tag:`Closed`,exit:e},t.length===0?cm:q_(this.strategy)?b(Jp(t,t=>Ip(t(e))),B(e=>b(bh(e),Or(yh),xr(()=>Oh)))):J_(this.strategy)?b(Ew(t,t=>Ip(t(e)),!1),B(e=>b(bh(e,{parallel:!0}),Or(yh),xr(()=>Oh)))):b(Ow(t,this.strategy.parallelism,t=>Ip(t(e)),!1),B(e=>b(bh(e,{parallel:!0}),Or(yh),xr(()=>Oh))))})},addFinalizer(e){return rm(()=>this.state._tag===`Closed`?e(this.state.exit):(this.state.finalizers.set({},e),cm))}},Vw=(e=W_)=>{let t=Object.create(Bw);return t.strategy=e,t.state={_tag:`Open`,finalizers:new Map},t},Hw=x(2,(e,t)=>zh(e,tl(Xc(Rw,t)))),Uw=e=>Lm(e,{differ:tw,fork:JC}),Ww=Rm(wf),Gw=Uw(BC),Kw=x(2,(e,t)=>sm(n=>Kp(n(e),{onFailure:e=>Kp(t,{onFailure:t=>zp(zs(e,t)),onSuccess:()=>zp(e)}),onSuccess:e=>wp(t,e)}))),qw=(e,t,n)=>Hp(r=>Kw(B(kw(Xp(e)),e=>kp(r=>{let i=t.map(e=>e.listeners.count),a=()=>{i.every(e=>e===0)&&t.every(e=>e.result.state.current._tag===`Pending`||!!(e.result.state.current._tag===`Done`&&gh(e.result.state.current.effect)&&e.result.state.current.effect._tag===`Failure`&&Ws(e.result.state.current.effect.cause)))&&(o.forEach(e=>e()),n?.(),r(hm(e)))};e.addObserver(e=>{o.forEach(e=>e()),r(e)});let o=t.map((e,t)=>{let n=e=>{i[t]=e,a()};return e.listeners.addObserver(n),()=>e.listeners.removeObserver(n)});return a(),V(()=>{o.forEach(e=>e())})})),rm(()=>{let e=t.flatMap(e=>e.state.completed?[]:[e]);return Yp(e,e=>AC(e.request,wh(r)))})))})),Yw,Xw,Zw=v((()=>{Vh(),Yw=nh,Xw=rh})),Qw,$w,eT,tT,nT,rT,iT,aT,oT,sT,cT,lT,uT,dT,fT,pT,mT,hT=v((()=>{il(),M(),bu(),vv(),Xt(),Rr(),F(),Sb(),Zw(),bc(),Vh(),Y_(),Jw(),tx(),Af(),VC(),Qw=e=>function(){if(arguments.length===1){let t=arguments[0];return(n,...r)=>e(t,n,...r)}return e.apply(this,arguments)},$w=Qw((e,t,n)=>{let r=yu(),i=[[zm,[[r,e.context]]]];n?.scheduler&&i.push([xb,[[r,n.scheduler]]]);let a=gv(e.fiberRefs,{entries:i,forkAs:r});n?.updateRefs&&(a=n.updateRefs(a,r));let o=new yw(r,a,e.runtimeFlags),s=t;n?.scope&&(s=B(Xw(n.scope,W_),e=>mm(th(e,Hp(e=>A(e,o.id())?cm:gm(o,e))),em(t,t=>Yw(e,t)))));let c=o.currentSupervisor;return c!==BC&&(c.onStart(e.context,s,R(),o),o.addObserver(e=>c.onEnd(e,o))),ex.add(e.runtimeFlags,o),n?.immediate===!1?o.resume(s):o.start(s),o}),eT=Qw((e,t)=>{let n=cT(e)(t);if(n._tag===`Failure`)throw oT(n.effect_instruction_i0);return n.effect_instruction_i0}),tT=class extends Error{fiber;_tag=`AsyncFiberException`;constructor(e){super(`Fiber #${e.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`),this.fiber=e,this.name=this._tag,this.stack=this.message}},nT=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let n=new tT(e);return Error.stackTraceLimit=t,n},rT=Symbol.for(`effect/Runtime/FiberFailure`),iT=Symbol.for(`effect/Runtime/FiberFailure/Cause`),aT=class extends Error{[rT];[iT];constructor(e){let t=yc(e)[0];super(t?.message||`An error has occurred`),this[rT]=rT,this[iT]=e,this.name=t?`(FiberFailure) ${t.name}`:`FiberFailure`,t?.stack&&(this.stack=t.stack)}toJSON(){return{_id:`FiberFailure`,cause:this[iT].toJSON()}}toString(){return`(FiberFailure) `+dc(this[iT],{renderErrorCause:!0})}[N](){return this.toString()}},oT=e=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let n=new aT(e);return Error.stackTraceLimit=t,n},sT=e=>{let t=e;switch(t._op){case`Failure`:case`Success`:return t;case`Left`:return Sh(t.left);case`Right`:return Dh(t.right);case`Some`:return Dh(t.value);case`None`:return Sh(new ph)}},cT=Qw((e,t)=>{let n=sT(t);if(n)return n;let r=new bb,i=$w(e)(t,{scheduler:r});return r.flush(),i.unsafePoll()||xh(Mp(nT(i),Bh(i)))}),lT=class{context;runtimeFlags;fiberRefs;constructor(e,t,n){this.context=e,this.runtimeFlags=t,this.fiberRefs=n}pipe(){return P(this,arguments)}},uT=e=>new lT(e.context,e.runtimeFlags,e.fiberRefs),dT=Cf(1,32,4),fT=uT({context:Yc(),runtimeFlags:dT,fiberRefs:_v()}),pT=$w(fT),mT=eT(fT)})),gT,_T,vT,yT,bT,xT,ST,CT,wT,TT,ET,DT,OT,kT,AT,jT,MT,NT,PT,FT,IT,LT,RT,zT,BT,VT,HT,UT,WT,GT,KT,qT,JT,YT,XT,ZT,QT,$T,eE,tE,nE,rE,iE,aE,oE,sE,cE,lE,uE,dE,fE=v((()=>{Gh(),M(),Ne(),S(),Ie(),Mt(),Xt(),Rr(),F(),T(),gT=Symbol.for(`effect/DateTime`),_T=Symbol.for(`effect/DateTime/TimeZone`),vT={[gT]:gT,pipe(){return P(this,arguments)},[N](){return this.toString()},toJSON(){return ZT(this).toJSON()}},yT={...vT,_tag:`Utc`,[E](){return k(this,Dt(this.epochMillis))},[j](e){return TT(e)&&e._tag===`Utc`&&this.epochMillis===e.epochMillis},toString(){return`DateTime.Utc(${ZT(this).toJSON()})`}},bT={...vT,_tag:`Zoned`,[E](){return b(Dt(this.epochMillis),O(D(this.zone)),k(this))},[j](e){return TT(e)&&e._tag===`Zoned`&&this.epochMillis===e.epochMillis&&A(this.zone,e.zone)},toString(){return`DateTime.Zoned(${dE(this)})`}},xT={[_T]:_T,[N](){return this.toString()}},ST={...xT,_tag:`Named`,[E](){return k(this,Ot(`Named:${this.id}`))},[j](e){return ET(e)&&e._tag===`Named`&&this.id===e.id},toString(){return`TimeZone.Named(${this.id})`},toJSON(){return{_id:`TimeZone`,_tag:`Named`,id:this.id}}},CT={...xT,_tag:`Offset`,[E](){return k(this,Ot(`Offset:${this.offset}`))},[j](e){return ET(e)&&e._tag===`Offset`&&this.offset===e.offset},toString(){return`TimeZone.Offset(${eE(this.offset)})`},toJSON(){return{_id:`TimeZone`,_tag:`Offset`,offset:this.offset}}},wT=(e,t,n)=>{let r=Object.create(bT);return r.epochMillis=e,r.zone=t,Object.defineProperty(r,"partsUtc",{value:n,enumerable:!1,writable:!0}),Object.defineProperty(r,"adjustedEpochMillis",{value:void 0,enumerable:!1,writable:!0}),Object.defineProperty(r,"partsAdjusted",{value:void 0,enumerable:!1,writable:!0}),r},TT=e=>w(e,gT),ET=e=>w(e,_T),DT=e=>ET(e)&&e._tag===`Offset`,OT=e=>ET(e)&&e._tag===`Named`,kT=e=>e._tag===`Utc`,AT=e=>e._tag===`Zoned`,jT=Ee((e,t)=>e.epochMillis===t.epochMillis),MT=e=>{let t=Object.create(yT);return t.epochMillis=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},NT=e=>{let t=e.getTime();if(Number.isNaN(t))throw new Uh(`Invalid date`);return MT(t)},PT=e=>{if(TT(e))return e;if(e instanceof Date)return NT(e);if(typeof e==`object`){let t=new Date(0);return rE(t,e),NT(t)}return typeof e==`string`&&!FT(e)?NT(new Date(e+`Z`)):NT(new Date(e))},FT=e=>/Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e),IT=-864e13+432e5,LT=864e13-504e5,RT=(e,t)=>{if(t?.timeZone===void 0&&TT(e)&&AT(e))return e;let n=PT(e);if(n.epochMillis<IT||n.epochMillis>LT)throw RangeError(`Epoch millis out of range: ${n.epochMillis}`);let r;if(t?.timeZone===void 0){let e=new Date(n.epochMillis).getTimezoneOffset()*-60*1e3;r=KT(e)}else if(ET(t?.timeZone))r=t.timeZone;else if(typeof t?.timeZone==`number`)r=KT(t.timeZone);else{let e=YT(t.timeZone);if(vr(e))throw new Uh(`Invalid time zone: ${t.timeZone}`);r=e.value}return t?.adjustForTimeZone===!0?aE(n.epochMillis,r,t?.disambiguation??`compatible`):wT(n.epochMillis,r,n.partsUtc)},zT=Er(RT),BT=/^(.{17,35})\[(.+)\]$/,VT=e=>{let t=BT.exec(e);if(t===null){let t=sE(e);return t===null?R():zT(e,{timeZone:t})}let[,n,r]=t;return zT(n,{timeZone:r})},HT=C(`effect/DateTime/validZoneCache`,()=>new Map),UT={day:`numeric`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`numeric`,second:`numeric`,timeZoneName:`longOffset`,fractionalSecondDigits:3,hourCycle:`h23`},WT=e=>{let t=e.resolvedOptions().timeZone;if(HT.has(t))return HT.get(t);let n=Object.create(ST);return n.id=t,n.format=e,HT.set(t,n),n},GT=e=>{if(HT.has(e))return HT.get(e);try{return WT(new Intl.DateTimeFormat(`en-US`,{...UT,timeZone:e}))}catch{throw new Uh(`Invalid time zone: ${e}`)}},KT=e=>{let t=Object.create(CT);return t.offset=e,t},qT=Er(GT),JT=/^(?:GMT|[+-])/,YT=e=>{if(JT.test(e)){let t=sE(e);return t===null?R():z(KT(t))}return qT(e)},XT=e=>e._tag===`Offset`?eE(e.offset):e.id,ZT=e=>new Date(e.epochMillis),QT=e=>{if(e._tag===`Utc`)return new Date(e.epochMillis);if(e.zone._tag===`Offset`)return new Date(e.epochMillis+e.zone.offset);if(e.adjustedEpochMillis!==void 0)return new Date(e.adjustedEpochMillis);let t=e.zone.format.formatToParts(e.epochMillis).filter(e=>e.type!==`literal`),n=new Date(0);return n.setUTCFullYear(Number(t[2].value),Number(t[0].value)-1,Number(t[1].value)),n.setUTCHours(Number(t[3].value),Number(t[4].value),Number(t[5].value),Number(t[6].value)),e.adjustedEpochMillis=n.getTime(),n},$T=e=>QT(e).getTime()-nE(e),eE=e=>{let t=Math.abs(e),n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r===60&&(n+=1,r=0),`${e<0?`-`:`+`}${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`},tE=e=>eE($T(e)),nE=e=>e.epochMillis,rE=(e,t)=>{if(t.year!==void 0&&e.setUTCFullYear(t.year),t.month!==void 0&&e.setUTCMonth(t.month-1),t.day!==void 0&&e.setUTCDate(t.day),t.weekDay!==void 0){let n=t.weekDay-e.getUTCDay();e.setUTCDate(e.getUTCDate()+n)}t.hours!==void 0&&e.setUTCHours(t.hours),t.minutes!==void 0&&e.setUTCMinutes(t.minutes),t.seconds!==void 0&&e.setUTCSeconds(t.seconds),t.millis!==void 0&&e.setUTCMilliseconds(t.millis)},iE=864e5,aE=(e,t,n)=>{if(t._tag===`Offset`)return wT(e-t.offset,t);let r=cE(e-iE,e,t),i=cE(e+iE,e,t);if(r===i)return wT(e-r,t);let a=r<i,o=r-i;if(a){if(cE(e-i,e,t)===i)return wT(e-i,t);let a=wT(e-r,t);if(e!==QT(a).getTime())switch(n){case`reject`:{let n=new Date(e).toISOString();throw RangeError(`Gap time: ${n} does not exist in time zone ${t.id}`)}case`earlier`:return wT(e-i,t);case`compatible`:case`later`:return a}return a}if(cE(e-r,e,t)===r){if(n===`earlier`||n===`compatible`||cE(e-r+o,e+o,t)===r)return wT(e-r,t);if(n===`reject`){let n=new Date(e).toISOString();throw RangeError(`Ambiguous time: ${n} occurs twice in time zone ${t.id}`)}}return wT(e-i,t)},oE=/([+-])(\d{2}):(\d{2})$/,sE=e=>{let t=oE.exec(e);if(t===null)return null;let[,n,r,i]=t;return(n===`+`?1:-1)*(Number(r)*60+Number(i))*60*1e3},cE=(e,t,n)=>{let r=n.format.formatToParts(e).find(e=>e.type===`timeZoneName`)?.value??``;if(r===`GMT`)return 0;let i=sE(r);return i===null?$T(wT(t,n)):i},lE=e=>ZT(e).toISOString(),uE=e=>{let t=QT(e);return e._tag===`Utc`?t.toISOString():`${t.toISOString().slice(0,-1)}${tE(e)}`},dE=e=>e.zone._tag===`Offset`?uE(e):`${uE(e)}[${e.zone.id}]`})),pE,mE,hE,gE,_E,vE=v((()=>{pE=e=>e.toUpperCase(),mE=e=>e.toLowerCase(),hE=e=>e.length===0?e:pE(e[0])+e.slice(1),gE=e=>e.length===0?e:mE(e[0])+e.slice(1),_E=e=>e.length>0})),yE,bE,xE,SE,CE,wE,TE,EE,DE,OE,kE,AE,jE=v((()=>{Vh(),Jw(),hT(),yE=xp,bE=Tw,xE=rm,SE=cm,CE=Ap,wE=Zp,TE=Qp,EE=$p,DE=Fp,OE=B,kE=pT,AE=mT})),ME,NE,PE,FE,IE,LE,RE,zE,BE,VE,HE,UE,WE,GE,KE,qE,JE,YE,XE=v((()=>{il(),fE(),ME=TT,NE=DT,PE=OT,FE=kT,IE=AT,LE=jT,RE=NT,zE=PT,BE=RT,VE=VT,HE=GT,UE=KT,WE=YT,GE=XT,KE=ZT,qE=nE,nl(`effect/DateTime/CurrentTimeZone`)(),JE=lE,YE=dE})),ZE,QE,$E,eD,tD,nD,rD=v((()=>{Xt(),ZE=(e,t)=>{switch(t._tag){case`StringKeyword`:case`TemplateLiteral`:return Object.keys(e);case`SymbolKeyword`:return Object.getOwnPropertySymbols(e);case`Refinement`:return ZE(e,t.from)}},QE=e=>{let t=!1,n;return()=>t?n:(n=e(),t=!0,n)},$E=e=>Array.isArray(e),eD=e=>!Array.isArray(e),tD=e=>`[${Rt(e)}]`,nD=e=>$E(e)?e.map(tD).join(``):tD(e)})),iD,aD,oD,sD,cD,lD,uD,dD,fD=v((()=>{Pi(),Xt(),rD(),iD=(e,t,n,r)=>{let i=e;return n&&$r(n)&&(i+=`\nat path: ${nD(n)}`),t!==void 0&&(i+=`\ndetails: ${t}`),r&&(i+=`\nschema (${r._tag}): ${r}`),i},aD=e=>iD(`Unsupported key schema`,void 0,void 0,e),oD=e=>iD(`Unsupported literal`,`literal value: ${zt(e)}`),sD=e=>iD(`Duplicate index signature`,`${e} index signature`),cD=iD(`Unsupported index signature parameter`,"An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),lD=iD(`Invalid element`,`A required element cannot follow an optional element. ts(1257)`),uD=e=>iD(`Duplicate property signature transformation`,`Duplicate key ${zt(e)}`),dD=e=>iD(`Duplicate property signature`,`Duplicate key ${zt(e)}`)})),pD,mD,hD,gD,_D,vD,yD,bD,xD,SD,CD,wD,TD,ED,DD,OD=v((()=>{pD=Symbol.for(`effect/SchemaId/DateFromSelf`),mD=Symbol.for(`effect/SchemaId/GreaterThan`),hD=Symbol.for(`effect/SchemaId/GreaterThanOrEqualTo`),gD=Symbol.for(`effect/SchemaId/LessThan`),_D=Symbol.for(`effect/SchemaId/LessThanOrEqualTo`),vD=Symbol.for(`effect/SchemaId/Int`),yD=Symbol.for(`effect/SchemaId/NonNaN`),bD=Symbol.for(`effect/SchemaId/Finite`),xD=Symbol.for(`effect/SchemaId/JsonNumber`),SD=Symbol.for(`effect/SchemaId/Between`),CD=Symbol.for(`effect/SchemaId/GreaterThanOrEqualToBigint`),wD=Symbol.for(`effect/SchemaId/BetweenBigint`),TD=Symbol.for(`effect/SchemaId/MinLength`),ED=Symbol.for(`effect/SchemaId/MaxLength`),DD=Symbol.for(`effect/SchemaId/Length`)}));function kD(e,t){let n=!1,r=Vr(e.length);for(let i=0;i<e.length;i++){let a=e[i],o=t(a);o!==a&&(n=!0),r[i]=o}return n?r:e}function AD(e){return br(tO(e),{onNone:()=>``,onSome:e=>e.map(e=>` & Brand<${zt(e)}>`).join(``)})}var jD,MD,ND,PD,FD,ID,LD,RD,zD,BD,VD,HD,UD,WD,GD,KD,qD,JD,YD,XD,ZD,QD,$D,eO,tO,nO,rO,iO,aO,oO,sO,cO,lO,uO,dO,fO,pO,mO,hO,gO,_O,vO,yO,bO,xO,SO,CO,wO,TO,EO,DO,OO,kO,AO,jO,MO,NO,PO,FO,IO,LO,RO,zO,BO,VO,HO,UO,WO,GO,KO,qO,JO,YO,XO,ZO,QO,$O,ek,tk,nk,rk,ik,ak,ok,sk,ck,lk,uk,dk,fk,pk,mk,hk,gk,_k,vk,yk,bk,xk,Sk,Ck,wk,Tk,Ek,Dk,Ok,kk,Ak,jk,Mk,Nk,Pk,Fk,Ik,Lk,Rk=v((()=>{Pi(),S(),Ie(),Xt(),fD(),rD(),xg(),Rr(),gr(),T(),Cg(),jD=Symbol.for(`effect/annotation/TypeConstructor`),MD=Symbol.for(`effect/annotation/Brand`),ND=Symbol.for(`effect/annotation/SchemaId`),PD=Symbol.for(`effect/annotation/Message`),FD=Symbol.for(`effect/annotation/MissingMessage`),ID=Symbol.for(`effect/annotation/Identifier`),LD=Symbol.for(`effect/annotation/Title`),RD=Symbol.for(`effect/annotation/AutoTitle`),zD=Symbol.for(`effect/annotation/Description`),BD=Symbol.for(`effect/annotation/Examples`),VD=Symbol.for(`effect/annotation/Default`),HD=Symbol.for(`effect/annotation/JSONSchema`),UD=Symbol.for(`effect/annotation/Arbitrary`),WD=Symbol.for(`effect/annotation/Pretty`),GD=Symbol.for(`effect/annotation/Equivalence`),KD=Symbol.for(`effect/annotation/Documentation`),qD=Symbol.for(`effect/annotation/Concurrency`),JD=Symbol.for(`effect/annotation/Batching`),YD=Symbol.for(`effect/annotation/ParseIssueTitle`),XD=Symbol.for(`effect/annotation/ParseOptions`),ZD=Symbol.for(`effect/annotation/DecodingFallback`),QD=Symbol.for(`effect/annotation/Surrogate`),$D=Symbol.for(`effect/annotation/StableFilter`),eO=x(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?z(e.annotations[t]):R()),tO=eO(MD),nO=eO(PD),rO=eO(FD),iO=eO(LD),aO=eO(RD),oO=eO(ID),sO=eO(zD),cO=eO(qD),lO=eO(JD),uO=eO(YD),dO=eO(XD),fO=eO(ZD),pO=eO(QD),mO=eO($D),hO=e=>Lr(mO(e),e=>e===!0),gO=Symbol.for(`effect/annotation/JSONIdentifier`),_O=eO(gO),vO=e=>Sr(_O(e),()=>oO(e)),yO=class{typeParameters;decodeUnknown;encodeUnknown;annotations;_tag=`Declaration`;constructor(e,t,n,r={}){this.typeParameters=e,this.decodeUnknown=t,this.encodeUnknown=n,this.annotations=r}toString(){return xr(Lk(this),()=>`<declaration schema>`)}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map(e=>e.toJSON()),annotations:Nk(this.annotations)}}},bO=e=>t=>t._tag===e,xO=class{literal;annotations;_tag=`Literal`;constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return xr(Lk(this),()=>zt(this.literal))}toJSON(){return{_tag:this._tag,literal:Ve(this.literal)?String(this.literal):this.literal,annotations:Nk(this.annotations)}}},SO=bO(`Literal`),CO=new xO(null),wO=class{symbol;annotations;_tag=`UniqueSymbol`;constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return xr(Lk(this),()=>zt(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:Nk(this.annotations)}}},TO=class{annotations;_tag=`UndefinedKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},EO=new TO({[LD]:`undefined`}),DO=class{annotations;_tag=`NeverKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},OO=new DO({[LD]:`never`}),kO=class{annotations;_tag=`UnknownKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},AO=new kO({[LD]:`unknown`}),jO=class{annotations;_tag=`AnyKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},MO=new jO({[LD]:`any`}),NO=class{annotations;_tag=`StringKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},PO=new NO({[LD]:`string`,[zD]:`a string`}),FO=bO(`StringKeyword`),IO=class{annotations;_tag=`NumberKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},LO=new IO({[LD]:`number`,[zD]:`a number`}),RO=class{annotations;_tag=`BooleanKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},zO=new RO({[LD]:`boolean`,[zD]:`a boolean`}),BO=class{annotations;_tag=`BigIntKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},VO=new BO({[LD]:`bigint`,[zD]:`a bigint`}),HO=class{annotations;_tag=`SymbolKeyword`;constructor(e={}){this.annotations=e}toString(){return Fk(this)}toJSON(){return{_tag:this._tag,annotations:Nk(this.annotations)}}},UO=new HO({[LD]:`symbol`,[zD]:`a symbol`}),WO=bO(`SymbolKeyword`),GO=class{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:Nk(this.annotations)}}toString(){return String(this.type)}},KO=class extends GO{isOptional;constructor(e,t,n={}){super(e,n),this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:Nk(this.annotations)}}toString(){return String(this.type)+(this.isOptional?`?`:``)}},qO=e=>e.map(e=>e.type),JO=class{elements;rest;isReadonly;annotations;_tag=`TupleType`;constructor(e,t,n,r={}){this.elements=e,this.rest=t,this.isReadonly=n,this.annotations=r;let i=!1,a=!1;for(let t of e)if(t.isOptional)i=!0;else if(i){a=!0;break}if(a||i&&t.length>1)throw Error(lD)}toString(){return xr(Lk(this),()=>YO(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map(e=>e.toJSON()),rest:this.rest.map(e=>e.toJSON()),isReadonly:this.isReadonly,annotations:Nk(this.annotations)}}},YO=e=>{let t=e.elements.map(String).join(`, `);return Gr(e.rest,{onEmpty:()=>`readonly [${t}]`,onNonEmpty:(n,r)=>{let i=String(n),a=i.includes(` | `)?`(${i})`:i;if(r.length>0){let n=r.map(String).join(`, `);return e.elements.length>0?`readonly [${t}, ...${a}[], ${n}]`:`readonly [...${a}[], ${n}]`}return e.elements.length>0?`readonly [${t}, ...${a}[]]`:`ReadonlyArray<${i}>`}})},XO=class extends KO{name;isReadonly;constructor(e,t,n,r,i){super(t,n,i),this.name=e,this.isReadonly=r}toString(){return(this.isReadonly?`readonly `:``)+String(this.name)+(this.isOptional?`?`:``)+`: `+this.type}toJSON(){return{name:String(this.name),type:this.type.toJSON(),isOptional:this.isOptional,isReadonly:this.isReadonly,annotations:Nk(this.annotations)}}},ZO=e=>{switch(e._tag){case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:return!0;case`Refinement`:return ZO(e.from)}return!1},QO=class{type;isReadonly;parameter;constructor(e,t,n){if(this.type=t,this.isReadonly=n,ZO(e))this.parameter=e;else throw Error(cD)}toString(){return(this.isReadonly?`readonly `:``)+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}},$O=class{annotations;_tag=`TypeLiteral`;propertySignatures;indexSignatures;constructor(e,t,n={}){this.annotations=n;let r={};for(let t=0;t<e.length;t++){let n=e[t].name;if(Object.prototype.hasOwnProperty.call(r,n))throw Error(dD(n));r[n]=null}let i={string:!1,symbol:!1};for(let e=0;e<t.length;e++){let n=Pk(t[e].parameter);if(FO(n)){if(i.string)throw Error(sD(`string`));i.string=!0}else if(WO(n)){if(i.symbol)throw Error(sD(`symbol`));i.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return xr(Lk(this),()=>tk(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map(e=>e.toJSON()),indexSignatures:this.indexSignatures.map(e=>e.toJSON()),annotations:Nk(this.annotations)}}},ek=e=>e.map(String).join(`; `),tk=e=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join(`; `);return e.indexSignatures.length>0?`{ ${t}; ${ek(e.indexSignatures)} }`:`{ ${t} }`}return e.indexSignatures.length>0?`{ ${ek(e.indexSignatures)} }`:`{}`},nk=pi(mr(yg,e=>{switch(e._tag){case`AnyKeyword`:return 0;case`UnknownKeyword`:return 1;case`ObjectKeyword`:return 2;case`StringKeyword`:case`NumberKeyword`:case`BooleanKeyword`:case`BigIntKeyword`:case`SymbolKeyword`:return 3}return 4})),rk={string:`StringKeyword`,number:`NumberKeyword`,boolean:`BooleanKeyword`,bigint:`BigIntKeyword`},ik=e=>Ti(e,e=>lk(e)?ik(e.types):[e]),ak=e=>{let t=nk(e),n=[],r={},i=[];for(let e of t)switch(e._tag){case`NeverKeyword`:break;case`AnyKeyword`:return[MO];case`UnknownKeyword`:return[AO];case`ObjectKeyword`:case`UndefinedKeyword`:case`VoidKeyword`:case`StringKeyword`:case`NumberKeyword`:case`BooleanKeyword`:case`BigIntKeyword`:case`SymbolKeyword`:r[e._tag]||(r[e._tag]=e,n.push(e));break;case`Literal`:{let t=typeof e.literal;switch(t){case`string`:case`number`:case`bigint`:case`boolean`:!r[rk[t]]&&!i.includes(e.literal)&&(i.push(e.literal),n.push(e));break;case`object`:i.includes(e.literal)||(i.push(e.literal),n.push(e))}break}case`UniqueSymbol`:!r.SymbolKeyword&&!i.includes(e.symbol)&&(i.push(e.symbol),n.push(e));break;case`TupleType`:r.ObjectKeyword||n.push(e);break;case`TypeLiteral`:e.propertySignatures.length===0&&e.indexSignatures.length===0?r[`{}`]||(r[`{}`]=e,n.push(e)):r.ObjectKeyword||n.push(e);break;default:n.push(e)}return n},ok=class e{types;annotations;static make=(t,n)=>ck(t)?new e(t,n):t.length===1?t[0]:OO;static unify=(t,n)=>e.make(ak(ik(t)),n);_tag=`Union`;constructor(e,t={}){this.types=e,this.annotations=t}toString(){return xr(Lk(this),()=>this.types.map(String).join(` | `))}toJSON(){return{_tag:this._tag,types:this.types.map(e=>e.toJSON()),annotations:Nk(this.annotations)}}},sk=(e,t)=>e.map(t),ck=e=>e.length>1,lk=bO(`Union`),uk=C(Symbol.for(`effect/Schema/AST/toJSONMemoMap`),()=>new WeakMap),dk=class{f;annotations;_tag=`Suspend`;constructor(e,t={}){this.f=e,this.annotations=t,this.f=QE(e)}toString(){return Lk(this).pipe(Sr(()=>kr(Er(this.f)(),e=>Lk(e))),xr(()=>`<suspended schema>`))}toJSON(){let e=this.f(),t=uk.get(e);return t||(uk.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:Nk(this.annotations)},uk.set(e,t),t)}},fk=class{from;filter;annotations;_tag=`Refinement`;constructor(e,t,n={}){this.from=e,this.filter=t,this.annotations=n}toString(){return oO(this).pipe(xr(()=>br(Ik(this),{onNone:()=>`{ ${this.from} | filter }`,onSome:e=>pk(this.from)?String(this.from)+` & `+e:e})))}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),annotations:Nk(this.annotations)}}},pk=bO(`Refinement`),mk={},hk=class{from;to;transformation;annotations;_tag=`Transformation`;constructor(e,t,n,r={}){this.from=e,this.to=t,this.transformation=n,this.annotations=r}toString(){return xr(Lk(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:Nk(this.annotations)}}},gk=class{decode;encode;_tag=`FinalTransformation`;constructor(e,t){this.decode=e,this.encode=t}},_k=class{from;to;decode;encode;constructor(e,t,n,r){this.from=e,this.to=t,this.decode=n,this.encode=r}},vk=class{propertySignatureTransformations;_tag=`TypeLiteralTransformation`;constructor(e){this.propertySignatureTransformations=e;let t={},n={};for(let r of e){let e=r.from;if(t[e])throw Error(uD(e));t[e]=!0;let i=r.to;if(n[i])throw Error(uD(i));n[i]=!0}}},yk=(e,t)=>{let n=Object.getOwnPropertyDescriptors(e),r={...e.annotations};delete r[ID];let i={...r,...t},a=pO(e);return yr(a)&&(i[QD]=yk(a.value,t)),n.annotations.value=i,Object.create(Object.getPrototypeOf(e),n)},bk=`[\\s\\S]*?`,xk=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`,Sk=(e,t)=>{switch(e._tag){case`Literal`:return Sg(String(e.literal));case`StringKeyword`:return bk;case`NumberKeyword`:return xk;case`TemplateLiteral`:return wk(e,t,!1);case`Union`:return e.types.map(e=>Sk(e,t)).join(`|`)}},Ck=(e,t,n,r)=>{if(lk(e)){if(n&&!r)return`(?:${t})`}else if(!n||!r)return t;return`(${t})`},wk=(e,t,n)=>{let r=``;if(e.head!==``){let i=Sg(e.head);r+=t&&n?`(${i})`:i}for(let i of e.spans){let e=Sk(i.type,t);if(r+=Ck(i.type,e,t,n),i.literal!==``){let e=Sg(i.literal);r+=t&&n?`(${e})`:e}}return r},Tk=e=>RegExp(`^${wk(e,!1,!0)}$`),Ek=(e,t)=>{let n=[],r=[],i=e=>{switch(e._tag){case`NeverKeyword`:break;case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:case`Refinement`:r.push(new QO(e,t,!0));break;case`Literal`:if(Re(e.literal)||ze(e.literal))n.push(new XO(e.literal,t,!1,!0));else throw Error(oD(e.literal));break;case`Enums`:for(let[r,i]of e.enums)n.push(new XO(i,t,!1,!0));break;case`UniqueSymbol`:n.push(new XO(e.symbol,t,!1,!0));break;case`Union`:e.types.forEach(i);break;default:throw Error(aD(e))}};return i(e),{propertySignatures:n,indexSignatures:r}},Dk=e=>t=>{let n;for(let r of e)Object.prototype.hasOwnProperty.call(t.annotations,r)&&(n===void 0&&(n={}),n[r]=t.annotations[r]);return n},Ok=Dk([BD,VD,HD,UD,WD,GD]),kk=e=>{switch(e._tag){case`Declaration`:{let t=kD(e.typeParameters,kk);return t===e.typeParameters?e:new yO(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case`TupleType`:{let t=kD(e.elements,e=>{let t=kk(e.type);return t===e.type?e:new KO(t,e.isOptional)}),n=qO(e.rest),r=kD(n,kk);return t===e.elements&&r===n?e:new JO(t,r.map(e=>new GO(e)),e.isReadonly,e.annotations)}case`TypeLiteral`:{let t=kD(e.propertySignatures,e=>{let t=kk(e.type);return t===e.type?e:new XO(e.name,t,e.isOptional,e.isReadonly)}),n=kD(e.indexSignatures,e=>{let t=kk(e.type);return t===e.type?e:new QO(e.parameter,t,e.isReadonly)});return t===e.propertySignatures&&n===e.indexSignatures?e:new $O(t,n,e.annotations)}case`Union`:{let t=kD(e.types,kk);return t===e.types?e:ok.make(t,e.annotations)}case`Suspend`:return new dk(()=>kk(e.f()),e.annotations);case`Refinement`:{let t=kk(e.from);return t===e.from?e:new fk(t,e.filter,e.annotations)}case`Transformation`:{let t=Ok(e);return kk(t===void 0?e.to:yk(e.to,t))}}return e},Ak=e=>{switch(e._tag){case`Transformation`:return e.from;case`Refinement`:return Ak(e.from);case`Suspend`:return Ak(e.f())}},jk=(e,t)=>{switch(e._tag){case`Declaration`:{let n=kD(e.typeParameters,e=>jk(e,t));return n===e.typeParameters?e:new yO(n,e.decodeUnknown,e.encodeUnknown)}case`TupleType`:{let n=kD(e.elements,e=>{let n=jk(e.type,t);return n===e.type?e:new KO(n,e.isOptional)}),r=qO(e.rest),i=kD(r,e=>jk(e,t));return n===e.elements&&i===r?e:new JO(n,i.map(e=>new GO(e)),e.isReadonly)}case`TypeLiteral`:{let n=kD(e.propertySignatures,e=>{let n=jk(e.type,t);return n===e.type?e:new XO(e.name,n,e.isOptional,e.isReadonly)}),r=kD(e.indexSignatures,e=>{let n=jk(e.type,t);return n===e.type?e:new QO(e.parameter,n,e.isReadonly)});return n===e.propertySignatures&&r===e.indexSignatures?e:new $O(n,r)}case`Union`:{let n=kD(e.types,e=>jk(e,t));return n===e.types?e:ok.make(n)}case`Suspend`:{let n,r=vO(e);if(yr(r)){let e=t?`Bound`:``;n={[gO]:`${r.value}Encoded${e}`}}return new dk(()=>jk(e.f(),t),n)}case`Refinement`:{let n=jk(e.from,t);return t?n===e.from?e:Ak(e.from)===void 0&&hO(e)?new fk(n,e.filter,e.annotations):n:n}case`Transformation`:return jk(e.from,t)}return e},Mk=e=>jk(e,!1),Nk=e=>{let t={};for(let n of Object.getOwnPropertySymbols(e))t[String(n)]=e[n];return t},Pk=e=>{switch(e._tag){case`StringKeyword`:case`SymbolKeyword`:case`TemplateLiteral`:return e;case`Refinement`:return Pk(e.from)}},Fk=e=>xr(Lk(e),()=>e._tag),Ik=e=>iO(e).pipe(Sr(()=>sO(e)),Sr(()=>aO(e)),Or(t=>t+AD(e))),Lk=e=>Sr(oO(e),()=>Ik(e))}));function zk(e){return e.sort(OA).map(e=>e[1])}function Bk(e){return sO(e).pipe(Sr(()=>iO(e)),Sr(()=>aO(e)),Sr(()=>oO(e)),xr(()=>`{ ${e.from} | filter }`))}function Vk(e){return e.message===void 0?`Expected ${pk(e.ast)?Bk(e.ast):String(e.ast)}, actual ${zt(e.actual)}`:e.message}var Hk,Uk,Wk,Gk,Kk,qk,Jk,Yk,Xk,Zk,Qk,$k,eA,tA,nA,rA,iA,aA,oA,sA,cA,lA,uA,dA,fA,pA,mA,hA,gA,_A,vA,yA,bA,xA,SA,CA,wA,TA,EA,DA,OA,kA,AA,jA,MA,NA,PA,FA,IA,LA,RA,zA,BA,VA,HA,UA,WA,GA,KA,qA,JA,YA,XA,ZA=v((()=>{Pi(),Gh(),I_(),jE(),lr(),zb(),S(),Ie(),Xt(),rD(),Rr(),T(),Sb(),Rk(),Hk=class{path;actual;issue;_tag=`Pointer`;constructor(e,t,n){this.path=e,this.actual=t,this.issue=n}},Uk=class{actual;message;_tag=`Unexpected`;constructor(e,t){this.actual=e,this.message=t}},Wk=class{ast;message;_tag=`Missing`;actual=void 0;constructor(e,t){this.ast=e,this.message=t}},Gk=class{ast;actual;issues;output;_tag=`Composite`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.issues=n,this.output=r}},Kk=class{ast;actual;kind;issue;_tag=`Refinement`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.kind=n,this.issue=r}},qk=class{ast;actual;kind;issue;_tag=`Transformation`;constructor(e,t,n,r){this.ast=e,this.actual=t,this.kind=n,this.issue=r}},Jk=class{ast;actual;message;_tag=`Type`;constructor(e,t,n){this.ast=e,this.actual=t,this.message=n}},Yk=class{ast;actual;message;_tag=`Forbidden`;constructor(e,t,n){this.ast=e,this.actual=t,this.message=n}},Xk=Symbol.for(`effect/Schema/ParseErrorTypeId`),Zk=class extends F_(`ParseError`){[Xk]=Xk;get message(){return this.toString()}toString(){return jA.formatIssueSync(this.issue)}toJSON(){return{_id:`ParseError`,message:this.toString()}}[N](){return this.toJSON()}},Qk=e=>new Zk({issue:e}),$k=I,eA=L,tA=Qn,nA=Zn,rA=$n,iA=x(2,(e,t)=>rA(e)?ar(e,{onLeft:L,onRight:t}):OE(e,t)),aA=x(2,(e,t)=>rA(e)?ir(e,t):wE(e,t)),oA=x(2,(e,t)=>rA(e)?rr(e,t):EE(e,t)),sA=x(2,(e,t)=>rA(e)?nr(e,{onLeft:t.onFailure,onRight:t.onSuccess}):TE(e,t)),cA=x(2,(e,t)=>rA(e)?ar(e,{onLeft:t,onRight:I}):CE(e,t)),lA=(e,t)=>t===void 0||ze(t)?e:e===void 0?t:{...e,...t},uA=(e,t,n)=>{let r=yA(e,t);return(e,t)=>r(e,lA(n,t))},dA=(e,t,n)=>{let r=uA(e,t,n);return(e,t)=>sr(r(e,t),Qk)},fA=(e,t,n)=>{let r=yA(e,t);return(e,t)=>r(e,{...lA(n,t),isEffectAllowed:!0})},pA=(e,t)=>uA(e.ast,!0,t),mA=(e,t)=>fA(e.ast,!0,t),hA=(e,t)=>fA(e.ast,!1,t),gA=(e,t)=>dA(kk(e.ast),!0,t),_A=C(Symbol.for(`effect/ParseResult/decodeMemoMap`),()=>new WeakMap),vA=C(Symbol.for(`effect/ParseResult/encodeMemoMap`),()=>new WeakMap),yA=(e,t)=>{let n=t?_A:vA,r=n.get(e);if(r)return r;let i=SA(e,t),a=dO(e),o=yr(a)?(e,t)=>i(e,lA(t,a.value)):i,s=fO(e),c=t&&yr(s)?(t,n)=>DA(cA(o(t,n),s.value),e,t,n):o;return n.set(e,c),c},bA=e=>Tr(cO(e)),xA=e=>Tr(lO(e)),SA=(e,t)=>{switch(e._tag){case`Refinement`:if(t){let t=yA(e.from,!0);return(n,r)=>{r??=mk;let i=r?.errors===`all`,a=iA(cA(t(n,r),t=>{let a=new Kk(e,n,`From`,t);return i&&hO(e)&&BA(t)?br(e.filter(n,r,e),{onNone:()=>L(a),onSome:t=>L(new Gk(e,n,[a,new Kk(e,n,`Predicate`,t)]))}):L(a)}),t=>br(e.filter(t,r,e),{onNone:()=>I(t),onSome:t=>L(new Kk(e,n,`Predicate`,t))}));return DA(a,e,n,r)}}{let t=yA(kk(e),!0),n=yA(EA(e.from),!1);return(r,i)=>DA(iA(t(r,i),e=>n(e,i)),e,r,i)}case`Transformation`:{let n=kA(e.transformation,t),r=t?yA(e.from,!0):yA(e.to,!1),i=t?yA(e.to,!0):yA(e.from,!1);return(a,o)=>DA(iA(oA(r(a,o),n=>new qk(e,a,t?`Encoded`:`Type`,n)),r=>iA(oA(n(r,o??mk,e,a),t=>new qk(e,a,`Transformation`,t)),n=>oA(i(n,o),n=>new qk(e,a,t?`Type`:`Encoded`,n)))),e,a,o)}case`Declaration`:{let n=t?e.decodeUnknown(...e.typeParameters):e.encodeUnknown(...e.typeParameters);return(t,r)=>DA(n(t,r??mk,e),e,t,r)}case`Literal`:return CA(e,t=>t===e.literal);case`UniqueSymbol`:return CA(e,t=>t===e.symbol);case`UndefinedKeyword`:return CA(e,We);case`NeverKeyword`:return CA(e,Ge);case`UnknownKeyword`:case`AnyKeyword`:case`VoidKeyword`:return I;case`StringKeyword`:return CA(e,Re);case`NumberKeyword`:return CA(e,ze);case`BooleanKeyword`:return CA(e,Be);case`BigIntKeyword`:return CA(e,Ve);case`SymbolKeyword`:return CA(e,He);case`ObjectKeyword`:return CA(e,qe);case`Enums`:return CA(e,t=>e.enums.some(([e,n])=>n===t));case`TemplateLiteral`:{if(e.spans.every(e=>FO(e.type)))return CA(e,t=>{if(!Re(t)||!t.startsWith(e.head))return!1;let n=e.head.length;for(let r=0;r<e.spans.length-1;r++){let i=e.spans[r].literal,a=t.indexOf(i,n);if(a===-1)return!1;n=a+i.length}let r=e.spans[e.spans.length-1].literal;return t.endsWith(r)&&t.length-r.length>=n});let t=Tk(e);return CA(e,e=>Re(e)&&t.test(e))}case`TupleType`:{let n=e.elements.map(e=>yA(e.type,t)),r=e.rest.map(e=>yA(e.type,t)),i=e.elements.filter(e=>!e.isOptional);e.rest.length>0&&(i=i.concat(e.rest.slice(1)));let a=i.length,o=e.elements.length>0?e.elements.map((e,t)=>t).join(` | `):`never`,s=bA(e),c=xA(e);return(t,l)=>{if(!Yr(t))return L(new Jk(e,t));let u=l?.errors===`all`,d=[],f=0,p=[],m=t.length;for(let n=m;n<=a-1;n++){let r=new Hk(n,t,new Wk(i[n-m]));if(u){d.push([f++,r]);continue}return L(new Gk(e,t,r,p))}if(e.rest.length===0)for(let n=e.elements.length;n<=m-1;n++){let r=new Hk(n,t,new Uk(t[n],`is unexpected, expected: ${o}`));if(u){d.push([f++,r]);continue}return L(new Gk(e,t,r,p))}let h=0,g;for(;h<n.length;h++)if(m<h+1){if(e.elements[h].isOptional)continue}else{let r=n[h],i=r(t[h],l);if(rA(i)){if(er(i)){let n=new Hk(h,t,i.left);if(u){d.push([f++,n]);continue}return L(new Gk(e,t,n,zk(p)))}p.push([f++,i.right])}else{let n=f++,r=h;g||=[],g.push(({es:a,output:o})=>OE(DE(i),i=>{if(er(i)){let s=new Hk(r,t,i.left);return u?(a.push([n,s]),SE):L(new Gk(e,t,s,zk(o)))}return o.push([n,i.right]),SE}))}}if($r(r)){let[n,...i]=r;for(;h<m-i.length;h++){let r=n(t[h],l);if(rA(r)){if(er(r)){let n=new Hk(h,t,r.left);if(u){d.push([f++,n]);continue}return L(new Gk(e,t,n,zk(p)))}p.push([f++,r.right])}else{let n=f++,i=h;g||=[],g.push(({es:a,output:o})=>OE(DE(r),r=>{if(er(r)){let s=new Hk(i,t,r.left);return u?(a.push([n,s]),SE):L(new Gk(e,t,s,zk(o)))}return o.push([n,r.right]),SE}))}}for(let n=0;n<i.length;n++){let r=h+n;if(!(m<r+1)){let a=i[n](t[r],l);if(rA(a)){if(er(a)){let n=new Hk(r,t,a.left);if(u){d.push([f++,n]);continue}return L(new Gk(e,t,n,zk(p)))}p.push([f++,a.right])}else{let n=f++;g||=[],g.push(({es:i,output:o})=>OE(DE(a),a=>{if(er(a)){let s=new Hk(r,t,a.left);return u?(i.push([n,s]),SE):L(new Gk(e,t,s,zk(o)))}return o.push([n,a.right]),SE}))}}}}let _=({es:n,output:r})=>Qr(n)?L(new Gk(e,t,zk(n),zk(r))):I(zk(r));if(g&&g.length>0){let e=g;return xE(()=>{let t={es:yi(d),output:yi(p)};return OE(bE(e,e=>e(t),{concurrency:s,batching:c,discard:!0}),()=>_(t))})}return _({output:p,es:d})}}case`TypeLiteral`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return CA(e,Xe);let n=[],r={},i=[];for(let a of e.propertySignatures)n.push([yA(a.type,t),a]),r[a.name]=null,i.push(a.name);let a=e.indexSignatures.map(e=>[yA(e.parameter,t),yA(e.type,t),e.parameter]),o=ok.make(e.indexSignatures.map(e=>e.parameter).concat(i.map(e=>He(e)?new wO(e):new xO(e)))),s=yA(o,t),c=bA(e),l=xA(e);return(t,u)=>{if(!et(t))return L(new Jk(e,t));let d=u?.errors===`all`,f=[],p=0,m=u?.onExcessProperty===`error`,h=u?.onExcessProperty===`preserve`,g={},_;if(m||h){_=Reflect.ownKeys(t);for(let n of _){let r=s(n,u);if(rA(r)&&er(r)){if(m){let r=new Hk(n,t,new Uk(t[n],`is unexpected, expected: ${String(o)}`));if(d){f.push([p++,r]);continue}return L(new Gk(e,t,r,g))}g[n]=t[n]}}}let ee,te=u?.exact===!0;for(let r=0;r<n.length;r++){let i=n[r][1],a=i.name,o=Object.prototype.hasOwnProperty.call(t,a);if(!o){if(i.isOptional)continue;if(te){let n=new Hk(a,t,new Wk(i));if(d){f.push([p++,n]);continue}return L(new Gk(e,t,n,g))}}let s=n[r][0],c=s(t[a],u);if(rA(c)){if(er(c)){let n=new Hk(a,t,o?c.left:new Wk(i));if(d){f.push([p++,n]);continue}return L(new Gk(e,t,n,g))}g[a]=c.right}else{let n=p++,r=a;ee||=[],ee.push(({es:a,output:s})=>OE(DE(c),c=>{if(er(c)){let l=new Hk(r,t,o?c.left:new Wk(i));return d?(a.push([n,l]),SE):L(new Gk(e,t,l,s))}return s[r]=c.right,SE}))}}for(let n=0;n<a.length;n++){let i=a[n],o=i[0],s=i[1],c=ZE(t,i[2]);for(let n of c){let i=o(n,u);if(rA(i)&&tr(i)){let i=s(t[n],u);if(rA(i)){if(er(i)){let r=new Hk(n,t,i.left);if(d){f.push([p++,r]);continue}return L(new Gk(e,t,r,g))}Object.prototype.hasOwnProperty.call(r,n)||(g[n]=i.right)}else{let a=p++,o=n;ee||=[],ee.push(({es:s,output:c})=>OE(DE(i),i=>{if(er(i)){let n=new Hk(o,t,i.left);return d?(s.push([a,n]),SE):L(new Gk(e,t,n,c))}return Object.prototype.hasOwnProperty.call(r,n)||(c[n]=i.right),SE}))}}}}let ne=({es:n,output:r})=>{if(Qr(n))return L(new Gk(e,t,zk(n),r));if(u?.propertyOrder===`original`){let e=_||Reflect.ownKeys(t);for(let t of i)e.indexOf(t)===-1&&e.push(t);let n={};for(let t of e)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t]);return I(n)}return I(r)};if(ee&&ee.length>0){let e=ee;return xE(()=>{let t={es:yi(f),output:Object.assign({},g)};return OE(bE(e,e=>e(t),{concurrency:c,batching:l,discard:!0}),()=>ne(t))})}return ne({es:f,output:g})}}case`Union`:{let n=TA(e.types,t),r=Reflect.ownKeys(n.keys),i=r.length,a=e.types.length,o=new Map;for(let n=0;n<a;n++)o.set(e.types[n],yA(e.types[n],t));let s=bA(e)??1,c=xA(e);return(t,l)=>{let u=[],d=0,f=[];if(i>0){if(Ke(t))for(let e=0;e<i;e++){let i=r[e],o=n.keys[i].buckets;if(Object.prototype.hasOwnProperty.call(t,i)){let e=String(t[i]);if(Object.prototype.hasOwnProperty.call(o,e))f=f.concat(o[e]);else{let{candidates:e,literals:r}=n.keys[i],o=ok.make(r),s=e.length===a?new $O([new XO(i,o,!1,!0)],[]):ok.make(e);u.push([d++,new Gk(s,t,new Hk(i,t,new Jk(o,t[i])))])}}else{let{candidates:e,literals:r}=n.keys[i],o=new XO(i,ok.make(r),!1,!0),s=e.length===a?new $O([o],[]):ok.make(e);u.push([d++,new Gk(s,t,new Hk(i,t,new Wk(o)))])}}else{let r=n.candidates.length===a?e:ok.make(n.candidates);u.push([d++,new Jk(r,t)])}}n.otherwise.length>0&&(f=f.concat(n.otherwise));let p;for(let e=0;e<f.length;e++){let n=f[e],r=o.get(n)(t,l);if(rA(r)&&(!p||p.length===0)){if(tr(r))return r;u.push([d++,r.left])}else{let e=d++;p||=[],p.push(t=>xE(()=>`finalResult`in t?SE:OE(DE(r),n=>(tr(n)?t.finalResult=n:t.es.push([e,n.left]),SE))))}}let m=n=>Qr(n)?n.length===1&&n[0][1]._tag===`Type`?L(n[0][1]):L(new Gk(e,t,zk(n))):L(new Jk(e,t));if(p&&p.length>0){let e=p;return xE(()=>{let t={es:yi(u)};return OE(bE(e,e=>e(t),{concurrency:s,batching:c,discard:!0}),()=>`finalResult`in t?t.finalResult:m(t.es))})}return m(u)}}case`Suspend`:{let n=QE(()=>yA(e.f(),t));return(e,t)=>n()(e,t)}}},CA=(e,t)=>n=>t(n)?I(n):L(new Jk(e,n)),wA=(e,t)=>{switch(e._tag){case`Declaration`:{let n=pO(e);if(yr(n))return wA(n.value,t);break}case`TypeLiteral`:{let n=[];for(let r=0;r<e.propertySignatures.length;r++){let i=e.propertySignatures[r],a=t?Mk(i.type):kk(i.type);SO(a)&&!i.isOptional&&n.push([i.name,a])}return n}case`TupleType`:{let n=[];for(let r=0;r<e.elements.length;r++){let i=e.elements[r],a=t?Mk(i.type):kk(i.type);SO(a)&&!i.isOptional&&n.push([r,a])}return n}case`Refinement`:return wA(e.from,t);case`Suspend`:return wA(e.f(),t);case`Transformation`:return wA(t?e.from:e.to,t)}return[]},TA=(e,t)=>{let n={},r=[],i=[];for(let a=0;a<e.length;a++){let o=e[a],s=wA(o,t);if(s.length>0){i.push(o);for(let e=0;e<s.length;e++){let[t,r]=s[e],i=String(r.literal);n[t]=n[t]||{buckets:{},literals:[],candidates:[]};let a=n[t].buckets;if(Object.prototype.hasOwnProperty.call(a,i)){if(e<s.length-1)continue;a[i].push(o),n[t].literals.push(r),n[t].candidates.push(o)}else{a[i]=[o],n[t].literals.push(r),n[t].candidates.push(o);break}}}else r.push(o)}return{keys:n,otherwise:r,candidates:i}},EA=e=>pk(e)?EA(e.from):e,DA=(e,t,n,r)=>{if(r?.isEffectAllowed===!0||rA(e))return e;let i=new bb,a=kE(e,{scheduler:i});i.flush();let o=a.unsafePoll();if(o){if(Rb(o))return I(o.value);let e=o.cause;return Hh(e)?L(e.error):L(new Yk(t,n,Wh(e)))}return L(new Yk(t,n,`cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work`))},OA=([e],[t])=>e>t?1:e<t?-1:0,kA=(e,t)=>{switch(e._tag){case`FinalTransformation`:return t?e.decode:e.encode;case`ComposeTransformation`:return I;case`TypeLiteralTransformation`:return n=>{let r=I(n);for(let n of e.propertySignatureTransformations){let[e,i]=t?[n.from,n.to]:[n.to,n.from],a=t?n.decode:n.encode;r=aA(r,t=>{let n=a(Object.prototype.hasOwnProperty.call(t,e)?z(t[e]):R());return delete t[e],yr(n)&&(t[i]=n.value),t})}return r}}},AA=(e,t=[])=>({value:e,forest:t}),jA={formatIssue:e=>aA(XA(e),MA),formatIssueSync:e=>{let t=jA.formatIssue(e);return rA(t)?cr(t):AE(t)},formatError:e=>jA.formatIssue(e.issue),formatErrorSync:e=>jA.formatIssueSync(e.issue)},MA=e=>e.value+NA(`
21
+ `,e.forest),NA=(e,t)=>{let n=``,r=t.length,i;for(let a=0;a<r;a++){i=t[a];let o=a===r-1;n+=e+(o?`└`:`├`)+`─ `+i.value,n+=NA(e+(r>1&&!o?`│ `:` `),i.forest)}return n},PA=e=>{switch(e){case`Encoded`:return`Encoded side transformation failure`;case`Transformation`:return`Transformation process failure`;case`Type`:return`Type side transformation failure`}},FA=e=>{switch(e){case`From`:return`From side refinement failure`;case`Predicate`:return`Predicate refinement failure`}},IA=e=>`ast`in e?z(e.ast):R(),LA=I(void 0),RA=e=>IA(e).pipe(kr(nO),br({onNone:()=>LA,onSome:t=>{let n=t(e);return Re(n)?I({message:n,override:!1}):yE(n)?wE(n,e=>({message:e,override:!1})):Re(n.message)?I({message:n.message,override:n.override}):wE(n.message,e=>({message:e,override:n.override}))}})),zA=e=>t=>t._tag===e,BA=zA(`Composite`),VA=zA(`Refinement`),HA=zA(`Transformation`),UA=e=>iA(RA(e),t=>t===void 0?LA:!t.override&&(BA(e)||VA(e)&&e.kind===`From`||HA(e)&&e.kind!==`Transformation`)?HA(e)||VA(e)?UA(e.issue):LA:I(t.message)),WA=e=>IA(e).pipe(kr(uO),Ar(t=>t(e)),Tr),GA=e=>aA(UA(e),t=>t??WA(e)??Vk(e)),KA=e=>WA(e)??String(e.ast),qA=e=>e.message??`is forbidden`,JA=e=>e.message??`is unexpected`,YA=e=>{let t=rO(e.ast);if(yr(t)){let e=t.value();return Re(e)?I(e):e}return I(e.message??`is missing`)},XA=e=>{switch(e._tag){case`Type`:return aA(GA(e),AA);case`Forbidden`:return I(AA(KA(e),[AA(qA(e))]));case`Unexpected`:return I(AA(JA(e)));case`Missing`:return aA(YA(e),AA);case`Transformation`:return iA(UA(e),t=>t===void 0?aA(XA(e.issue),t=>AA(KA(e),[AA(PA(e.kind),[t])])):I(AA(t)));case`Refinement`:return iA(UA(e),t=>t===void 0?aA(XA(e.issue),t=>AA(KA(e),[AA(FA(e.kind),[t])])):I(AA(t)));case`Pointer`:return aA(XA(e.issue),t=>AA(nD(e.path),[t]));case`Composite`:return iA(UA(e),t=>{if(t!==void 0)return I(AA(t));let n=KA(e);return $E(e.issues)?aA(bE(e.issues,XA),e=>AA(n,e)):aA(XA(e.issues),e=>AA(n,[e]))})}}})),QA,$A,ej=v((()=>{S(),T(),QA=x(e=>qe(e[0]),(e,...t)=>{let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}),$A=x(e=>qe(e[0]),(e,...t)=>{let n={...e};for(let e of t)delete n[e];return n})}));function tj(e){return class{[_j]=vj;static ast=e;static annotations(e){return tj(xj(this.ast,e))}static pipe(){return P(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[_j]=vj}}function nj(e){return ck(e)?ok.make(sk(e,e=>new xO(e))):new xO(e[0])}function rj(e,t=nj(e)){return class extends tj(t){static annotations(e){return rj(this.literals,xj(this.ast,e))}static literals=[...e]}}function H(...e){return $r(e)?rj(e):jj}function ij(e,t){return class extends tj(t){static annotations(e){return ij(this.typeParameters,xj(this.ast,e))}static typeParameters=[...e]}}function aj(e,t=Ij(e)){return class extends tj(t){static annotations(e){return aj(this.members,xj(this.ast,e))}static members=[...e]}}function U(...e){return ck(e)?aj(e):$r(e)?e[0]:jj}function oj(e,t,n=Bj(e,t)){return class extends tj(n){static annotations(e){return oj(this.elements,this.rest,xj(this.ast,e))}static elements=[...e];static rest=[...t]}}function sj(...e){return Array.isArray(e[0])?oj(e[0],e.slice(1)):oj(e,[])}function cj(e,t){return class extends oj([],[e],t){static annotations(e){return cj(this.value,xj(this.ast,e))}static value=e}}function lj(e,t,n=nM(e,t)){return class extends tj(n){static annotations(e){return lj(this.fields,this.records,xj(this.ast,e))}static fields={...e};static records=[...t];static make=(t,n)=>{let r=rM(e,{...t});return gj(n)?r:gA(this)(r)};static pick(...t){return W(QA(e,...t))}static omit(...t){return W($A(e,...t))}}}function W(e,...t){return lj(e,t)}function uj(e,t,n){return class extends lj({},[{key:e,value:t}],n){static annotations(n){return uj(e,t,xj(this.ast,n))}static key=e;static value=t}}function dj(e,t){return class extends tj(t){static annotations(e){return dj(this.from,xj(this.ast,e))}static make=(e,t)=>gj(t)?e:gA(this)(e);static from=e}}function fj(e,t,n){return class extends tj(n){static annotations(e){return fj(this.from,this.filter,xj(this.ast,e))}static[lM]=e;static from=e;static filter=t;static make=(e,t)=>gj(t)?e:gA(this)(e)}}function pj(e,t){return n=>{function r(t,n,r){return dM(e(t,n,r),r,t)}return fj(n,r,new fk(n.ast,r,bj(t)))}}function mj(e,t,n){return class extends tj(n){static annotations(e){return mj(this.from,this.to,xj(this.ast,e))}static from=e;static to=t}}function hj(e){return fM(e,Fj,{strict:!1,decode:(e,t,n)=>nA(bg(e),()=>new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a number`)),encode:e=>$k(String(e))})}function gj(e){return Be(e)?e:e?.disableValidation??!1}var _j,vj,yj,bj,xj,Sj,Cj,wj,Tj,Ej,G,Dj,Oj,kj,Aj,jj,Mj,Nj,Pj,K,Fj,q,Ij,Lj,Rj,zj,Bj,Vj,Hj,Uj,Wj,Gj,Kj,qj,Jj,Yj,Xj,Zj,Qj,$j,eM,J,tM,nM,rM,iM,aM,oM,sM,cM,lM,uM,dM,fM,pM,mM,hM,gM,_M,vM,yM,bM,xM,SM,CM,wM,TM,EM,DM,OM,kM,AM,jM,MM,NM,PM,FM,IM,LM,RM,zM,BM,VM,HM,UM,WM,GM,KM,qM,JM,YM,XM,ZM,QM,$M,eN,tN,nN,rN,iN,aN,oN,sN,cN,lN,uN,dN,fN,pN,mN,hN,gN,_N,vN,yN,bN,xN,SN,CN,wN,TN,EN,DN,ON,kN,AN,jN,MN,NN,PN,FN,IN,LN,RN,zN,BN,VN,HN,UN,WN,GN,KN,qN,JN,YN,XN,ZN,QN,$N,eP,tP,nP,rP,iP,aP,oP,sP,cP,lP,uP,dP,fP,pP=v((()=>{Pi(),ra(),sa(),la(),XE(),Ul(),lr(),M(),Ne(),bu(),S(),Xt(),bc(),OD(),rD(),xg(),Rr(),ZA(),F(),T(),Rk(),vE(),ej(),_j=Symbol.for(`effect/Schema`),vj={_A:e=>e,_I:e=>e,_R:e=>e},yj={typeConstructor:jD,schemaId:ND,message:PD,missingMessage:FD,identifier:ID,title:LD,description:zD,examples:BD,default:VD,documentation:KD,jsonSchema:HD,arbitrary:UD,pretty:WD,equivalence:GD,concurrency:qD,batching:JD,parseIssueTitle:YD,parseOptions:XD,decodingFallback:ZD},bj=e=>{if(!e)return{};let t={...e};for(let n in yj)if(n in e){let r=yj[n];t[r]=e[n],delete t[n]}return t},xj=(e,t)=>yk(e,bj(t)),Sj=e=>String(e.ast),Cj=(e,t)=>{let n=pA(e,t);return(e,t)=>rr(n(e,t),Qk)},wj=e=>w(e,_j)&&qe(e[_j]),Tj=(e,t,n)=>ij(e,new yO(e.map(e=>e.ast),(...e)=>t.decode(...e.map(tj)),(...e)=>t.encode(...e.map(tj)),bj(n))),Ej=(e,t)=>{let n=()=>(t,n,r)=>e(t)?$k(t):eA(new Jk(r,t));return ij([],new yO([],n,n,bj(t)))},G=function(){if(Array.isArray(arguments[0])){let e=arguments[0],t=arguments[1],n=arguments[2];return Tj(e,t,n)}let e=arguments[0],t=arguments[1];return Ej(e,t)},Dj=Symbol.for(`effect/SchemaId/InstanceOf`),Oj=(e,t)=>G(t=>t instanceof e,{title:e.name,description:`an instance of ${e.name}`,pretty:()=>String,schemaId:Dj,[Dj]:{constructor:e},...t}),kj=class extends tj(EO){},Aj=class extends tj(CO){},jj=class extends tj(OO){},Mj=class extends tj(AO){},Nj=class extends tj(VO){},Pj=class extends tj(UO){},K=class extends tj(PO){},Fj=class extends tj(LO){},q=class extends tj(zO){},Ij=e=>ok.make(e.map(e=>e.ast)),Lj=e=>U(e,kj),Rj=e=>new zj(new KO(e.ast,!1),e),zj=class e{ast;from;[_j];_Token;constructor(e,t){this.ast=e,this.from=t}annotations(t){return new e(new KO(this.ast.type,this.ast.isOptional,{...this.ast.annotations,...bj(t)}),this.from)}toString(){return`${this.ast.type}${this.ast.isOptional?`?`:``}`}},Bj=(e,t)=>new JO(e.map(e=>wj(e)?new KO(e.ast,!1):e.ast),t.map(e=>wj(e)?new GO(e.ast):e.ast),!0),Vj=e=>cj(e),Hj=e=>e?`"?:"`:`":"`,Uj=class extends KO{isReadonly;defaultValue;_tag=`PropertySignatureDeclaration`;constructor(e,t,n,r,i){super(e,t,r),this.isReadonly=n,this.defaultValue=i}toString(){let e=Hj(this.isOptional),t=String(this.type);return`PropertySignature<${e}, ${t}, never, ${e}, ${t}>`}},Wj=class extends KO{isReadonly;defaultValue;constructor(e,t,n,r,i){super(e,t,r),this.isReadonly=n,this.defaultValue=i}},Gj=e=>e===void 0?`never`:Re(e)?JSON.stringify(e):String(e),Kj=class{from;to;decode;encode;_tag=`PropertySignatureTransformation`;constructor(e,t,n,r){this.from=e,this.to=t,this.decode=n,this.encode=r}toString(){return`PropertySignature<${Hj(this.to.isOptional)}, ${this.to.type}, ${Gj(this.from.fromKey)}, ${Hj(this.from.isOptional)}, ${this.from.type}>`}},qj=(e,t)=>{switch(e._tag){case`PropertySignatureDeclaration`:return new Uj(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case`PropertySignatureTransformation`:return new Kj(e.from,new Wj(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},Jj=Symbol.for(`effect/PropertySignature`),Yj=e=>w(e,Jj),Xj=class e{ast;[_j];[Jj]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return P(this,arguments)}annotations(t){return new e(qj(this.ast,bj(t)))}toString(){return String(this.ast)}},Zj=e=>new Xj(e),Qj=class e extends Xj{from;constructor(e,t){super(e),this.from=t}annotations(t){return new e(qj(this.ast,bj(t)),this.from)}},$j=e=>new Qj(new Uj(e.ast,!1,!0,{},void 0),e),eM=x(2,(e,t)=>{let n=e.ast;switch(n._tag){case`PropertySignatureDeclaration`:return Zj(new Uj(n.type,n.isOptional,n.isReadonly,n.annotations,t));case`PropertySignatureTransformation`:return Zj(new Kj(n.from,new Wj(n.to.type,n.to.isOptional,n.to.isReadonly,n.to.annotations,t),n.decode,n.encode))}}),J=e=>{let t=e.ast===EO||e.ast===OO?EO:Lj(e).ast;return new Qj(new Uj(t,!0,!0,{},void 0),e)},tM=Dk([FD]),nM=(e,t)=>{let n=Reflect.ownKeys(e),r=[];if(n.length>0){let i=[],a=[],o=[];for(let t=0;t<n.length;t++){let s=n[t],c=e[s];if(Yj(c)){let e=c.ast;switch(e._tag){case`PropertySignatureDeclaration`:{let t=e.type,n=e.isOptional,o=e.annotations;i.push(new XO(s,t,n,!0,tM(e))),a.push(new XO(s,kk(t),n,!0,o)),r.push(new XO(s,t,n,!0,o));break}case`PropertySignatureTransformation`:{let t=e.from.fromKey??s;i.push(new XO(t,e.from.type,e.from.isOptional,!0,e.from.annotations)),a.push(new XO(s,e.to.type,e.to.isOptional,!0,e.to.annotations)),o.push(new _k(t,s,e.decode,e.encode));break}}}else i.push(new XO(s,c.ast,!1,!0)),a.push(new XO(s,kk(c.ast),!1,!0)),r.push(new XO(s,c.ast,!1,!0))}if($r(o)){let e=[],n=[];for(let r of t){let{indexSignatures:t,propertySignatures:o}=Ek(r.key.ast,r.value.ast);o.forEach(e=>{i.push(e),a.push(new XO(e.name,kk(e.type),e.isOptional,e.isReadonly,e.annotations))}),t.forEach(t=>{e.push(t),n.push(new QO(t.parameter,kk(t.type),t.isReadonly))})}return new hk(new $O(i,e,{[RD]:`Struct (Encoded side)`}),new $O(a,n,{[RD]:`Struct (Type side)`}),new vk(o))}}let i=[];for(let e of t){let{indexSignatures:t,propertySignatures:n}=Ek(e.key.ast,e.value.ast);n.forEach(e=>r.push(e)),t.forEach(e=>i.push(e))}return new $O(r,i)},rM=(e,t)=>{let n=Reflect.ownKeys(e);for(let r of n){let n=e[r];if(t[r]===void 0&&Yj(n)){let e=n.ast,i=e._tag===`PropertySignatureDeclaration`?e.defaultValue:e.to.defaultValue;i!==void 0&&(t[r]=i())}}return t},iM=e=>H(e).pipe($j,eM(()=>e)),aM=(e,t)=>W({_tag:iM(e),...t}),oM=e=>uj(e.key,e.value),sM=(e,t)=>n=>{let r=br(tO(n.ast),{onNone:()=>[e],onSome:t=>[...t,e]});return dj(n,yk(n.ast,bj({[MD]:r,...t})))},cM=e=>tj(new dk(()=>e().ast)),lM=Symbol.for(`effect/SchemaId/Refine`),uM=(e,t,n)=>{if(Be(e))return e?R():z(new Jk(t,n));if(Re(e))return z(new Jk(t,n,e));if(e!==void 0){if(`_tag`in e)return z(e);let r=new Jk(t,n,e.message);return z($r(e.path)?new Hk(e.path,n,r):r)}return R()},dM=(e,t,n)=>{if(eD(e))return uM(e,t,n);if($r(e)){let r=Di(e,e=>uM(e,t,n));if($r(r))return z(r.length===1?r[0]:new Gk(t,n,r))}return R()},fM=x(e=>wj(e[0])&&wj(e[1]),(e,t,n)=>mj(e,t,new hk(e.ast,t.ast,new gk(n.decode,n.encode)))),pM=x(e=>wj(e[0])&&wj(e[1]),(e,t,n)=>fM(e,t,{strict:!0,decode:(e,t,r,i)=>$k(n.decode(e,i)),encode:(e,t,r,i)=>$k(n.encode(e,i))})),mM=Symbol.for(`effect/SchemaId/Trimmed`),hM=e=>t=>t.pipe(pj(e=>e===e.trim(),{schemaId:mM,title:`trimmed`,description:`a string with no leading or trailing whitespace`,jsonSchema:{pattern:`^\\S[\\s\\S]*\\S$|^\\S$|^$`},...e})),gM=ED,_M=(e,t)=>n=>n.pipe(pj(t=>t.length<=e,{schemaId:gM,title:`maxLength(${e})`,description:`a string at most ${e} character(s) long`,jsonSchema:{maxLength:e},...t})),vM=TD,yM=(e,t)=>n=>n.pipe(pj(t=>t.length>=e,{schemaId:vM,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t})),bM=DD,xM=(e,t)=>n=>{let r=qe(e)?Math.max(0,Math.floor(e.min)):Math.max(0,Math.floor(e)),i=qe(e)?Math.max(r,Math.floor(e.max)):r;return r===i?n.pipe(pj(e=>e.length===r,{schemaId:bM,title:`length(${r})`,description:r===1?`a single character`:`a string ${r} character(s) long`,jsonSchema:{minLength:r,maxLength:r},...t})):n.pipe(pj(e=>e.length>=r&&e.length<=i,{schemaId:bM,title:`length({ min: ${r}, max: ${i})`,description:`a string at least ${r} character(s) and at most ${i} character(s) long`,jsonSchema:{minLength:r,maxLength:i},...t}))},SM=Symbol.for(`effect/SchemaId/Pattern`),CM=(e,t)=>n=>{let r=e.source;return n.pipe(pj(t=>(e.lastIndex=0,e.test(t)),{schemaId:SM,[SM]:{regex:e},description:`a string matching the pattern ${r}`,jsonSchema:{pattern:r},...t}))},wM=Symbol.for(`effect/SchemaId/Lowercased`),TM=e=>t=>t.pipe(pj(e=>e===e.toLowerCase(),{schemaId:wM,title:`lowercased`,description:`a lowercase string`,jsonSchema:{pattern:`^[^A-Z]*$`},...e})),EM=class extends K.pipe(TM({identifier:`Lowercased`})){},DM=Symbol.for(`effect/SchemaId/Uppercased`),OM=e=>t=>t.pipe(pj(e=>e===e.toUpperCase(),{schemaId:DM,title:`uppercased`,description:`an uppercase string`,jsonSchema:{pattern:`^[^a-z]*$`},...e})),kM=class extends K.pipe(OM({identifier:`Uppercased`})){},AM=Symbol.for(`effect/SchemaId/Capitalized`),jM=e=>t=>t.pipe(pj(e=>e[0]?.toUpperCase()===e[0],{schemaId:AM,title:`capitalized`,description:`a capitalized string`,jsonSchema:{pattern:`^[^a-z]?.*$`},...e})),MM=class extends K.pipe(jM({identifier:`Capitalized`})){},NM=Symbol.for(`effect/SchemaId/Uncapitalized`),PM=e=>t=>t.pipe(pj(e=>e[0]?.toLowerCase()===e[0],{schemaId:NM,title:`uncapitalized`,description:`a uncapitalized string`,jsonSchema:{pattern:`^[^A-Z]?.*$`},...e})),FM=class extends K.pipe(PM({identifier:`Uncapitalized`})){},K.pipe(xM(1,{identifier:`Char`})),IM=e=>yM(1,{title:`nonEmptyString`,description:`a non empty string`,...e}),pM(K.annotations({description:`a string that will be converted to lowercase`}),EM,{strict:!0,decode:e=>e.toLowerCase(),encode:be}).annotations({identifier:`Lowercase`}),pM(K.annotations({description:`a string that will be converted to uppercase`}),kM,{strict:!0,decode:e=>e.toUpperCase(),encode:be}).annotations({identifier:`Uppercase`}),pM(K.annotations({description:`a string that will be converted to a capitalized format`}),MM,{strict:!0,decode:e=>hE(e),encode:be}).annotations({identifier:`Capitalize`}),pM(K.annotations({description:`a string that will be converted to an uncapitalized format`}),FM,{strict:!0,decode:e=>gE(e),encode:be}).annotations({identifier:`Uncapitalize`}),LM=class extends K.pipe(hM({identifier:`Trimmed`})){},RM=class extends LM.pipe(IM({identifier:`NonEmptyTrimmedString`})){},pM(K.annotations({description:`a string that will be trimmed`}),LM,{strict:!0,decode:e=>e.trim(),encode:be}).annotations({identifier:`Trim`}),zM=e=>e instanceof Error?e.message:String(e),K.pipe(IM({identifier:`NonEmptyString`})),BM=Symbol.for(`effect/SchemaId/UUID`),VM=/^[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}$/i,K.pipe(CM(VM,{schemaId:BM,identifier:`UUID`,jsonSchema:{format:`uuid`,pattern:VM.source},description:`a Universally Unique Identifier`,arbitrary:()=>e=>e.uuid()})),HM=Symbol.for(`effect/SchemaId/ULID`),UM=/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i,K.pipe(CM(UM,{schemaId:HM,identifier:`ULID`,description:`a Universally Unique Lexicographically Sortable Identifier`,arbitrary:()=>e=>e.ulid()})),WM=class extends Oj(URL,{typeConstructor:{_tag:`URL`},identifier:`URLFromSelf`,arbitrary:()=>e=>e.webUrl().map(e=>new URL(e)),pretty:()=>e=>e.toString()}){},fM(K.annotations({description:`a string to be decoded into a URL`}),WM,{strict:!0,decode:(e,t,n)=>tA({try:()=>new URL(e),catch:t=>new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a URL. ${zM(t)}`)}),encode:e=>$k(e.toString())}).annotations({identifier:`URL`,pretty:()=>e=>e.toString()}),GM=bD,KM=e=>t=>t.pipe(pj(Number.isFinite,{schemaId:GM,title:`finite`,description:`a finite number`,jsonSchema:{},...e})),qM=mD,JM=(e,t)=>n=>n.pipe(pj(t=>t>e,{schemaId:qM,title:`greaterThan(${e})`,description:e===0?`a positive number`:`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),YM=hD,XM=(e,t)=>n=>n.pipe(pj(t=>t>=e,{schemaId:YM,title:`greaterThanOrEqualTo(${e})`,description:e===0?`a non-negative number`:`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t})),ZM=vD,QM=e=>t=>t.pipe(pj(e=>Number.isSafeInteger(e),{schemaId:ZM,title:`int`,description:`an integer`,jsonSchema:{type:`integer`},...e})),$M=gD,eN=(e,t)=>n=>n.pipe(pj(t=>t<e,{schemaId:$M,title:`lessThan(${e})`,description:e===0?`a negative number`:`a number less than ${e}`,jsonSchema:{exclusiveMaximum:e},...t})),tN=_D,nN=(e,t)=>n=>n.pipe(pj(t=>t<=e,{schemaId:tN,title:`lessThanOrEqualTo(${e})`,description:e===0?`a non-positive number`:`a number less than or equal to ${e}`,jsonSchema:{maximum:e},...t})),rN=SD,iN=(e,t,n)=>r=>r.pipe(pj(n=>n>=e&&n<=t,{schemaId:rN,title:`between(${e}, ${t})`,description:`a number between ${e} and ${t}`,jsonSchema:{minimum:e,maximum:t},...n})),aN=yD,oN=e=>t=>t.pipe(pj(e=>!Number.isNaN(e),{schemaId:aN,title:`nonNaN`,description:`a number excluding NaN`,...e})),sN=e=>JM(0,{title:`positive`,...e}),cN=e=>eN(0,{title:`negative`,...e}),lN=e=>nN(0,{title:`nonPositive`,...e}),uN=e=>XM(0,{title:`nonNegative`,...e}),hj(K.annotations({description:`a string to be decoded into a number`})).annotations({identifier:`NumberFromString`}),Fj.pipe(KM({identifier:`Finite`})),dN=class extends Fj.pipe(QM({identifier:`Int`})){},Fj.pipe(oN({identifier:`NonNaN`})),Fj.pipe(sN({identifier:`Positive`})),Fj.pipe(cN({identifier:`Negative`})),Fj.pipe(lN({identifier:`NonPositive`})),fN=class extends Fj.pipe(uN({identifier:`NonNegative`})){},pN=xD,Fj.pipe(KM({schemaId:pN,identifier:`JsonNumber`})),pM(q.annotations({description:`a boolean that will be negated`}),q,{strict:!0,decode:e=>ca(e),encode:e=>ca(e)}),mN=(e,t)=>{let n=Symbol.keyFor(e);return n===void 0?eA(new Jk(t,e,`Unable to encode a unique symbol ${String(e)} into a string`)):$k(n)},hN=e=>$k(Symbol.for(e)),fM(K.annotations({description:`a string to be decoded into a globally shared symbol`}),Pj,{strict:!1,decode:e=>hN(e),encode:(e,t,n)=>mN(e,n)}).annotations({identifier:`Symbol`}),gN=CD,_N=(e,t)=>n=>n.pipe(pj(t=>t>=e,{schemaId:gN,[gN]:{min:e},title:`greaterThanOrEqualToBigInt(${e})`,description:e===0n?`a non-negative bigint`:`a bigint greater than or equal to ${e}n`,...t})),vN=wD,yN=(e,t,n)=>r=>r.pipe(pj(n=>n>=e&&n<=t,{schemaId:vN,[vN]:{min:e,max:t},title:`betweenBigInt(${e}, ${t})`,description:`a bigint between ${e}n and ${t}n`,...n})),bN=e=>_N(0n,{title:`nonNegativeBigInt`,...e}),xN=class extends fM(K.annotations({description:`a string to be decoded into a bigint`}),Nj,{strict:!0,decode:(e,t,n)=>nA(aa(e),()=>new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a bigint`)),encode:e=>$k(String(e))}).annotations({identifier:`BigInt`}){},SN=Nj.pipe(bN({identifier:`NonNegativeBigintFromSelf`})),fM(Fj.annotations({description:`a number to be decoded into a bigint`}),Nj.pipe(yN(BigInt(-(2**53-1)),BigInt(2**53-1))),{strict:!0,decode:(e,t,n)=>nA(oa(e),()=>new Jk(n,e,`Unable to decode ${e} into a bigint`)),encode:(e,t,n)=>nA(ia(e),()=>new Jk(n,e,`Unable to encode ${e}n into a number`))}).annotations({identifier:`BigIntFromNumber`}),CN=(e,t,n,r)=>sA(e,{onFailure:e=>new Gk(n,r,e),onSuccess:t}),wN=class extends G(vl,{typeConstructor:{_tag:`effect/Duration`},identifier:`DurationFromSelf`,pretty:()=>String,arbitrary:()=>e=>e.oneof(e.constant(Sl),e.bigInt({min:0n}).map(e=>Cl(e)),e.maxSafeNat().map(e=>Tl(e))),equivalence:()=>Ll}){},fM(SN.annotations({description:`a bigint to be decoded into a Duration`}),wN.pipe(pj(e=>yl(e),{description:`a finite duration`})),{strict:!0,decode:e=>$k(Cl(e)),encode:(e,t,n)=>br(Ml(e),{onNone:()=>eA(new Jk(n,e,`Unable to encode ${e} into a bigint`)),onSome:e=>$k(e)})}).annotations({identifier:`DurationFromNanos`}),TN=fN.pipe(QM()).annotations({identifier:`NonNegativeInt`}),pM(fN.annotations({description:`a non-negative number to be decoded into a Duration`}),wN,{strict:!0,decode:e=>Tl(e),encode:e=>jl(e)}).annotations({identifier:`DurationFromMillis`}),EN=aM(`Millis`,{millis:TN}),DN=aM(`Nanos`,{nanos:xN}),ON=aM(`Infinity`,{}),kN=ON.make({}),AN=U(EN,DN,ON).annotations({identifier:`DurationValue`,description:`an JSON-compatible tagged union to be decoded into a Duration`}),jN=U(sj(Rj(TN).annotations({title:`seconds`}),Rj(TN).annotations({title:`nanos`})).annotations({identifier:`FiniteHRTime`}),sj(H(-1),H(0)).annotations({identifier:`InfiniteHRTime`})).annotations({identifier:`HRTime`,description:`a tuple of seconds and nanos to be decoded into a Duration`}),MN=e=>typeof e==`object`,pM(U(AN,jN),wN,{strict:!0,decode:e=>{if(MN(e))switch(e._tag){case`Millis`:return Tl(e.millis);case`Nanos`:return Cl(e.nanos);case`Infinity`:return Sl}let[t,n]=e;return t===-1?Sl:Cl(BigInt(t)*BigInt(1e9)+BigInt(n))},encode:e=>{switch(e.value._tag){case`Millis`:return EN.make({millis:e.value.millis});case`Nanos`:return DN.make({nanos:e.value.nanos});case`Infinity`:return kN}}}).annotations({identifier:`Duration`}),NN=class extends G(Ze,{typeConstructor:{_tag:`Uint8Array`},identifier:`Uint8ArrayFromSelf`,pretty:()=>e=>`new Uint8Array(${JSON.stringify(Array.from(e))})`,arbitrary:()=>e=>e.uint8Array(),equivalence:()=>Ai(A)}){},PN=class extends Fj.pipe(iN(0,255,{identifier:`Uint8`,description:`a 8-bit unsigned integer`})){},pM(Vj(PN).annotations({description:`an array of 8-bit unsigned integers to be decoded into a Uint8Array`}),NN,{strict:!0,decode:e=>Uint8Array.from(e),encode:e=>Array.from(e)}).annotations({identifier:`Uint8Array`}),FN=Symbol.for(`effect/SchemaId/ValidDate`),IN=e=>t=>t.pipe(pj(e=>!Number.isNaN(e.getTime()),{schemaId:FN,[FN]:{noInvalidDate:!0},title:`validDate`,description:`a valid Date`,...e})),LN=pD,RN=class extends G(Qe,{typeConstructor:{_tag:`Date`},identifier:`DateFromSelf`,schemaId:LN,[LN]:{noInvalidDate:!1},description:`a potentially invalid Date instance`,pretty:()=>e=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>e=>e.date({noInvalidDate:!1}),equivalence:()=>je}){},RN.pipe(IN({identifier:`ValidDateFromSelf`,description:`a valid Date instance`})),zN=class extends pM(K.annotations({description:`a string to be decoded into a Date`}),RN,{strict:!0,decode:e=>new Date(e),encode:e=>It(e)}).annotations({identifier:`DateFromString`}){},zN.pipe(IN({identifier:`Date`})),pM(Fj.annotations({description:`a number to be decoded into a Date`}),RN,{strict:!0,decode:e=>new Date(e),encode:e=>e.getTime()}).annotations({identifier:`DateFromNumber`}),BN=class extends G(e=>ME(e)&&FE(e),{typeConstructor:{_tag:`effect/DateTime.Utc`},identifier:`DateTimeUtcFromSelf`,description:`a DateTime.Utc instance`,pretty:()=>e=>e.toString(),arbitrary:()=>e=>e.date({noInvalidDate:!0}).map(e=>RE(e)),equivalence:()=>LE}){},VN=(e,t)=>tA({try:()=>zE(e),catch:()=>new Jk(t,e,`Unable to decode ${zt(e)} into a DateTime.Utc`)}),fM(Fj.annotations({description:`a number to be decoded into a DateTime.Utc`}),BN,{strict:!0,decode:(e,t,n)=>VN(e,n),encode:e=>$k(qE(e))}).annotations({identifier:`DateTimeUtcFromNumber`}),fM(RN.annotations({description:`a Date to be decoded into a DateTime.Utc`}),BN,{strict:!0,decode:(e,t,n)=>VN(e,n),encode:e=>$k(KE(e))}).annotations({identifier:`DateTimeUtcFromDate`}),fM(K.annotations({description:`a string to be decoded into a DateTime.Utc`}),BN,{strict:!0,decode:(e,t,n)=>VN(e,n),encode:e=>$k(JE(e))}).annotations({identifier:`DateTimeUtc`}),HN=()=>e=>e.integer({min:-432e5,max:504e5}).map(UE),UN=class extends G(NE,{typeConstructor:{_tag:`effect/DateTime.TimeZone.Offset`},identifier:`TimeZoneOffsetFromSelf`,description:`a TimeZone.Offset instance`,pretty:()=>e=>e.toString(),arbitrary:HN}){},pM(Fj.annotations({description:`a number to be decoded into a TimeZone.Offset`}),UN,{strict:!0,decode:e=>UE(e),encode:e=>e.offset}).annotations({identifier:`TimeZoneOffset`}),WN=()=>e=>e.constantFrom(...Intl.supportedValuesOf(`timeZone`)).map(HE),GN=class extends G(PE,{typeConstructor:{_tag:`effect/DateTime.TimeZone.Named`},identifier:`TimeZoneNamedFromSelf`,description:`a TimeZone.Named instance`,pretty:()=>e=>e.toString(),arbitrary:WN}){},fM(K.annotations({description:`a string to be decoded into a TimeZone.Named`}),GN,{strict:!0,decode:(e,t,n)=>tA({try:()=>HE(e),catch:()=>new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a TimeZone.Named`)}),encode:e=>$k(e.id)}).annotations({identifier:`TimeZoneNamed`}),KN=class extends U(UN,GN){},fM(K.annotations({description:`a string to be decoded into a TimeZone`}),KN,{strict:!0,decode:(e,t,n)=>br(WE(e),{onNone:()=>eA(new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a TimeZone`)),onSome:$k}),encode:e=>$k(GE(e))}).annotations({identifier:`TimeZone`}),qN=e=>e.oneof(HN()(e),WN()(e)),JN=class extends G(e=>ME(e)&&IE(e),{typeConstructor:{_tag:`effect/DateTime.Zoned`},identifier:`DateTimeZonedFromSelf`,description:`a DateTime.Zoned instance`,pretty:()=>e=>e.toString(),arbitrary:()=>e=>e.tuple(e.integer({min:-31536e9,max:31536e9}),qN(e)).map(([e,t])=>BE(e,{timeZone:t})),equivalence:()=>LE}){},fM(K.annotations({description:`a string to be decoded into a DateTime.Zoned`}),JN,{strict:!0,decode:(e,t,n)=>br(VE(e),{onNone:()=>eA(new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a DateTime.Zoned`)),onSome:$k}),encode:e=>$k(YE(e))}).annotations({identifier:`DateTimeZoned`}),YN=e=>e._tag===`None`?R():z(e.value),XN=(e,t)=>n=>n.oneof(t,n.record({_tag:n.constant(`None`)}),n.record({_tag:n.constant(`Some`),value:e(n)})).map(YN),ZN=e=>br({onNone:()=>`none()`,onSome:t=>`some(${e(t)})`}),QN=e=>(t,n,r)=>_r(t)?vr(t)?$k(R()):CN(e(t.value,n),z,r,t):eA(new Jk(r,t)),$N=e=>G([e],{decode:e=>QN(mA(e)),encode:e=>QN(hA(e))},{typeConstructor:{_tag:`effect/Option`},pretty:ZN,arbitrary:XN,equivalence:Nr}),eP=e=>$N(e).annotations({description:`Option<${Sj(e)}>`}),pM(K,eP(RM),{strict:!0,decode:e=>Mr(z(e.trim()),_E),encode:e=>xr(e,()=>``)}),tP=()=>e=>`BigDecimal(${Qi(Wi(e))})`,nP=()=>e=>e.tuple(e.bigInt(),e.integer({min:-18,max:18})).map(([e,t])=>zi(e,t)),rP=class extends G(Ri,{typeConstructor:{_tag:`effect/BigDecimal`},identifier:`BigDecimalFromSelf`,pretty:tP,arbitrary:nP,equivalence:()=>qi}){},fM(K.annotations({description:`a string to be decoded into a BigDecimal`}),rP,{strict:!0,decode:(e,t,n)=>Zi(e).pipe(br({onNone:()=>eA(new Jk(n,e,`Unable to decode ${JSON.stringify(e)} into a BigDecimal`)),onSome:e=>$k(Wi(e))})),encode:e=>$k(Qi(Wi(e)))}).annotations({identifier:`BigDecimal`}),pM(Fj.annotations({description:`a number to be decoded into a BigDecimal`}),rP,{strict:!0,decode:e=>Yi(e),encode:e=>ea(e)}).annotations({identifier:`BigDecimalFromNumber`}),iP=U(W({_tag:H(`None`)}).annotations({identifier:`FiberIdNoneEncoded`}),W({_tag:H(`Runtime`),id:dN,startTimeMillis:dN}).annotations({identifier:`FiberIdRuntimeEncoded`}),W({_tag:H(`Composite`),left:cM(()=>iP),right:cM(()=>iP)}).annotations({identifier:`FiberIdCompositeEncoded`})).annotations({identifier:`FiberIdEncoded`}),aP=e=>e.letrec(t=>({None:e.record({_tag:e.constant(`None`)}),Runtime:e.record({_tag:e.constant(`Runtime`),id:e.integer(),startTimeMillis:e.integer()}),Composite:e.record({_tag:e.constant(`Composite`),left:t(`FiberId`),right:t(`FiberId`)}),FiberId:e.oneof(t(`None`),t(`Runtime`),t(`Composite`))})).FiberId.map(cP),oP=e=>{switch(e._tag){case`None`:return`FiberId.none`;case`Runtime`:return`FiberId.runtime(${e.id}, ${e.startTimeMillis})`;case`Composite`:return`FiberId.composite(${oP(e.right)}, ${oP(e.left)})`}},sP=class extends G(_u,{typeConstructor:{_tag:`effect/FiberId`},identifier:`FiberIdFromSelf`,pretty:()=>oP,arbitrary:()=>aP}){},cP=e=>{switch(e._tag){case`None`:return mu;case`Runtime`:return hu(e.id,e.startTimeMillis);case`Composite`:return gu(cP(e.left),cP(e.right))}},lP=e=>{switch(e._tag){case`None`:return{_tag:`None`};case`Runtime`:return{_tag:`Runtime`,id:e.id,startTimeMillis:e.startTimeMillis};case`Composite`:return{_tag:`Composite`,left:lP(e.left),right:lP(e.right)}}},pM(iP,sP,{strict:!0,decode:e=>cP(e),encode:e=>lP(e)}).annotations({identifier:`FiberId`}),pM(Mj,Mj,{strict:!0,decode:e=>{if(qe(e)&&`message`in e&&typeof e.message==`string`){let t=Error(e.message,{cause:e});return`name`in e&&typeof e.name==`string`&&(t.name=e.name),t.stack=`stack`in e&&typeof e.stack==`string`?e.stack:``,t}return mc(e)},encode:e=>e instanceof Error?{name:e.name,message:e.message}:mc(e)}).annotations({identifier:`Defect`}),pM(Mj,q,{strict:!0,decode:e=>Le(e),encode:be}).annotations({identifier:`BooleanFromUnknown`}),pM(H(`true`,`false`).annotations({description:`a string to be decoded into a boolean`}),q,{strict:!0,decode:e=>e===`true`,encode:e=>e?`true`:`false`}).annotations({identifier:`BooleanFromString`}),uP=aM(`symbol`,{key:K}).annotations({description:`an object to be decoded into a globally shared symbol`}),dP=fM(uP,Pj,{strict:!0,decode:e=>hN(e.key),encode:(e,t,n)=>aA(mN(e,n),e=>uP.make({key:e}))}),fP=class extends U(K,Fj,dP).annotations({identifier:`PropertyKey`}){},W({_tag:$j(H(`Pointer`,`Unexpected`,`Missing`,`Composite`,`Refinement`,`Transformation`,`Type`,`Forbidden`)).annotations({description:`The tag identifying the type of parse issue`}),path:$j(Vj(fP)).annotations({description:`The path to the property where the issue occurred`}),message:$j(K).annotations({description:`A descriptive message explaining the issue`})}).annotations({identifier:`ArrayFormatterIssue`,description:`Represents an issue returned by the ArrayFormatter formatter`})}));function mP(e,t){return Cj(e,hP)(t)}var hP,gP=v((()=>{pP(),hP={onExcessProperty:`error`}}));function _P(e,t){if(typeof t!=`string`)return;let n=e.lastIndexOf(`@`);if(n<=0)return;let r=e.slice(0,n),i=e.slice(n+1);if(!(!bP(r)||!yP(i)||t!==i))return{pluginName:r,marketplaceName:i,canonicalPluginId:`${r}@openai-curated`}}function vP(e){let t=e.lastIndexOf(`@`);if(t<=0)return;let n=e.slice(0,t),r=e.slice(t+1);return bP(n)&&yP(r)?`${n}@openai-curated`:void 0}function yP(e){return wP.includes(e)}function bP(e){return TP.includes(e)}function xP(e,t){let n=t??AP;return{computer_use:e?.computer_use??n.computer_use,work:e?.work??n.work,frontend:e?.frontend??n.frontend,security:e?.security??n.security}}function SP(e,t=[]){let n=[],r=new Set;for(let t of kP)if(e[t])for(let e of OP[t].pluginIds)r.has(e)||(r.add(e),n.push(e));for(let e of t)r.has(e)||(r.add(e),n.push(e));return n}var CP,wP,TP,EP,DP,OP,kP,AP,jP=v((()=>{pP(),CP=H(`computer_use`,`work`,`frontend`,`security`),H(`computer_use`,`work`,`frontend`,`security`),H(`installed`,`disabled`,`missing`,`uncertain`),H(`healthy`,`missing`,`disabled`,`uncertain`),wP=Object.freeze([`openai-curated`,`openai-curated-remote`]),TP=Object.freeze([`build-web-apps`,`codex-security`]),EP=Object.freeze({coding:!0,computer_use:!1,work:!1,frontend:!0,security:!0}),DP={work:{name:`work`,pluginIds:[`documents@openai-primary-runtime`,`pdf@openai-primary-runtime`,`presentations@openai-primary-runtime`,`spreadsheets@openai-primary-runtime`,`template-creator@openai-primary-runtime`],defaultSelected:EP.work,migrationKey:`work`,semanticSkillIds:[`documents:documents`,`pdf:pdf`,`presentations:Presentations`,`spreadsheets:Spreadsheets`,`template-creator:template-creator`],ownership:`shared-preserve`},frontend:{name:`frontend`,pluginIds:[`build-web-apps@openai-curated`],defaultSelected:EP.frontend,migrationKey:`frontend`,semanticSkillIds:[`build-web-apps:frontend-app-builder`,`build-web-apps:frontend-testing-debugging`,`build-web-apps:react-best-practices`],ownership:`shared-preserve`},security:{name:`security`,pluginIds:[`codex-security@openai-curated`],defaultSelected:EP.security,migrationKey:`security`,semanticSkillIds:[`codex-security:security-scan`,`codex-security:security-diff-scan`,`codex-security:threat-model`],ownership:`shared-preserve`},computer_use:{name:`computer_use`,pluginIds:[`computer-use@openai-bundled`],defaultSelected:EP.computer_use,migrationKey:`computer_use`,semanticSkillIds:[`computer-use:computer-use`],ownership:`shared-preserve`}},OP=Object.freeze(DP),kP=Object.freeze([`computer_use`,`work`,`frontend`,`security`]),AP=Object.freeze({computer_use:EP.computer_use,work:EP.work,frontend:EP.frontend,security:EP.security})}));function MP(e){return W({identifier:H(e),label:K,requiresRootApproval:q})}function NP(e){let t=e.map(e=>e.label),n=t.at(-1);return n===void 0?``:t.length===1?n:`${t.slice(0,-1).join(`, `)}, and ${n}`}function PP(e){return e.length===0?e:`${e[0]?.toUpperCase()??``}${e.slice(1)}`}var FP,IP,LP,RP,zP,BP=v((()=>{pP(),me(),FP=H(`local.repository.edit`,`local.repository.check`,`local.repository.lint`,`local.repository.format`,`local.repository.commit`,`external.read`,`specialist.dispatch`,`vcs.server.mutation`,`vcs.server.ci-trigger`,`unknown.effect`),W({identifier:FP,label:K,requiresRootApproval:q}),W({localRepositoryEdit:MP(`local.repository.edit`),localRepositoryCheck:MP(`local.repository.check`),localRepositoryLint:MP(`local.repository.lint`),localRepositoryFormat:MP(`local.repository.format`),localRepositoryCommit:MP(`local.repository.commit`),externalRead:MP(`external.read`),specialistDispatch:MP(`specialist.dispatch`),versionControlServerMutation:MP(`vcs.server.mutation`),versionControlServerCiTrigger:MP(`vcs.server.ci-trigger`),unknownEffect:MP(`unknown.effect`)}),IP={localRepositoryEdit:{identifier:`local.repository.edit`,label:`local repository edit`,requiresRootApproval:!1},localRepositoryCheck:{identifier:`local.repository.check`,label:`local repository check`,requiresRootApproval:!1},localRepositoryLint:{identifier:`local.repository.lint`,label:`local repository lint`,requiresRootApproval:!1},localRepositoryFormat:{identifier:`local.repository.format`,label:`local repository format`,requiresRootApproval:!1},localRepositoryCommit:{identifier:`local.repository.commit`,label:`local repository commit`,requiresRootApproval:!1},externalRead:{identifier:`external.read`,label:`external read`,requiresRootApproval:!1},specialistDispatch:{identifier:`specialist.dispatch`,label:`specialist dispatch`,requiresRootApproval:!1},versionControlServerMutation:{identifier:`vcs.server.mutation`,label:`version-control-server mutation`,requiresRootApproval:!0},versionControlServerCiTrigger:{identifier:`vcs.server.ci-trigger`,label:`version-control-server CI triggering`,requiresRootApproval:!0},unknownEffect:{identifier:`unknown.effect`,label:`unclassified effect`,requiresRootApproval:!0}},ue(IP),H(`never`,`root`),LP=Object.values(IP),RP=LP.filter(e=>!e.requiresRootApproval),zP=LP.filter(e=>e.requiresRootApproval),Object.freeze({noRootApproval:`${PP(NP(RP))} actions do not require Root approval.`,rootApproval:`${PP(NP(zP))} require Root approval.`})}));function VP(e){let t=mP(WP,e);return er(t)?ge(_e(`sha256 digest`,t.left)):he(t.right)}var HP,UP,WP,GP=v((()=>{lr(),pP(),ve(),gP(),HP=K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),UP=K.pipe(CM(/^[0-9a-f]{64}$/u)),HP.pipe(sM(`RunId`)),HP.pipe(sM(`ProjectId`)),HP.pipe(sM(`TrustId`)),WP=UP.pipe(sM(`Sha256Digest`)),W({run_id:HP,objective_lineage:HP,parent_run_id:J(U(HP,Aj))}),W({project_id:HP,trust_id:HP,trust_digest:UP}),W({project_id:HP,project_digest:UP}),K.pipe(CM(/^state-[0-9]+\.[0-9]+$/u))}));function KP(e){return e===`Go`?`go`:e}function qP(e){return typeof e==`string`&&aF.has(e)}function JP(e){if(typeof e!=`object`||!e||!(`role`in e)||!(`task`in e))return!1;let t=e.role,n=e.task;return!qP(t)||typeof n!=`string`?!1:iF.get(t)?.tasks.some(e=>e.name===n)===!0}function YP(e,t){return typeof t==`string`&&iF.get(e)?.tasks.some(e=>e.name===t)===!0}function XP(e){return typeof e==`string`&&sF.has(e)}function ZP(e){let t=`${e.role}.${e.task}`;if(!lF.has(t))throw Error(`Unknown native specialist agent type.`);return t}function QP(e){let t=iF.get(e.role)?.tasks.find(t=>t.name===e.task);if(t===void 0)throw Error(`Unknown specialist task policy.`);return t.instruction}function $P(e){let t=iF.get(e.role)?.tasks.find(t=>t.name===e.task);if(t===void 0)throw Error(`Unknown specialist task policy.`);return t.description}var eF,tF,nF,rF,iF,aF,oF,sF,cF,lF,uF,dF,fF,pF,mF=v((()=>{pP(),me(),eF=H(`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`),tF=H(`Go`),U(eF,tF),nF=H(`standard`,`fast`,`fast-all`),H(`low`,`medium`,`high`,`xhigh`,`max`),rF=[{role:`Explorer`,tasks:[{name:`lookup`,description:`Use when Root needs one exact repository fact; locate it and return the exact path, symbol, or value.`,instruction:`Locate the exact requested repository fact.`},{name:`trace`,description:`Use when Root needs a complete in-scope execution or reference path; trace every relevant caller and constraint, then return the path and evidence.`,instruction:`Trace the complete in-scope execution or reference path.`}],capability:`repository-read`,authority:`Read only the assigned repository scope; Git/VCS and decisions remain Root-only.`,evidence:`Return exact paths, symbols, callers, tests, and constraints.`,completion:`Account for every in-scope caller and constraint.`,permissions:{network:!1,write:!1}},{role:`Librarian`,tasks:[{name:`lookup`,description:`Use when Root needs one exact current external fact; locate it in the assigned authoritative source and return the citation.`,instruction:`Locate the exact requested authoritative external fact.`},{name:`research`,description:`Use when Root needs a sourced current synthesis; combine the assigned authoritative sources with citations and return the evidence and uncertainty.`,instruction:`Synthesize the assigned current sources with citations.`}],capability:`current-research`,authority:`Research only the assigned current sources without repository mutation; Git/VCS and decisions remain Root-only.`,evidence:`Return sourced facts, dates, and explicit uncertainty.`,completion:`Resolve the assigned external fact or report the exact evidence gap.`,permissions:{network:!0,write:!1}},{role:`Worker`,tasks:[{name:`mechanical`,description:`Use when Root has decided deterministic edits; apply only those edits, verify the result, and return changed paths and evidence.`,instruction:`Apply only deterministic, already-decided edits.`},{name:`implementation`,description:`Use when Root has decided a bounded behavior seam; implement and verify that seam, then return changed paths and evidence.`,instruction:`Implement and verify the bounded behavior seam.`},{name:`integration`,description:`Use when Root has decided seams that must be combined; integrate and verify them together, then return the result and residual risk.`,instruction:`Integrate the decided seams and verify them together.`},{name:`operations`,description:`Use after Root approves an exact ref or SHA; observe required CI and release state to terminal evidence and return it, never treating pending as success.`,instruction:`After Root approves an exact ref or SHA, observe required CI and release state through terminal evidence; pending or running state is never success.`}],capability:`bounded-write`,authority:`Change only the assigned seam; Git/VCS and material choices remain Root-only.`,evidence:`Return changed files, verification results, and remaining risk.`,completion:`Finish the assigned seam with proportional proof or an exact blocker.`,permissions:{network:!1,write:!0}},{role:`Reviewer`,tasks:[{name:`plan`,description:`Use when Root needs a complete plan adversarially checked; review it to a fixed point and return findings, proof, and residual risk.`,instruction:`Review the complete plan to a fixed point.`},{name:`code`,description:`Use when Root needs implemented code adversarially checked; review and repair it to a fixed point, returning findings, proof, and residual risk.`,instruction:`Review and repair the implemented code to a fixed point.`},{name:`artifact`,description:`Use when Root needs a produced artifact inspected; review and repair it to a fixed point, returning findings, proof, and residual risk.`,instruction:`Review and repair the produced artifact to a fixed point.`}],capability:`bounded-review`,authority:`Inspect and repair only reviewer-owned defects; Git/VCS and material choices remain Root-only.`,evidence:`Return findings, repaired paths, verification, and residual risk.`,completion:`Reach a fixed point or report each reproducible blocker.`,permissions:{network:!1,write:!0}}],ue(rF),iF=new Map(rF.map(e=>[e.role,e])),aF=new Set(rF.map(e=>e.role)),oF=rF.flatMap(e=>e.tasks.map(t=>`${e.role}:${t.name}`)),sF=new Set(oF),cF=oF.map(e=>e.replace(`:`,`.`)),lF=new Set(cF),uF=G(qP),G(e=>YP(`Explorer`,e)),G(e=>YP(`Librarian`,e)),G(e=>YP(`Worker`,e)),G(e=>YP(`Reviewer`,e)),dF=G(JP),fF=Object.freeze(oF.filter(e=>XP(e))),G(XP),pF=Object.freeze(cF.filter(e=>lF.has(e))),G(e=>typeof e==`string`&&lF.has(e)),W({plan:eF,service_tier:J(nF)})}));function hF(e,t){return new y(`invalid_canonical_value`,`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function gF(e,t,n){if(e===null)return`null`;switch(typeof e){case`string`:{let n=JSON.stringify(e);if(n===void 0)throw hF(t,`invalid string`);return n}case`boolean`:return e?`true`:`false`;case`number`:{if(!Number.isFinite(e))throw hF(t,`non-finite number`);let n=JSON.stringify(e);if(n===void 0)throw hF(t,`invalid number`);return n}case`undefined`:throw hF(t,`undefined is not JSON`);case`bigint`:throw hF(t,`bigint is not JSON`);case`function`:throw hF(t,`function is not JSON`);case`symbol`:throw hF(t,`symbol is not JSON`)}if(n.has(e))throw hF(t,`cyclic value`);n.add(e);try{if(Array.isArray(e)){for(let n of Object.getOwnPropertySymbols(e))throw hF(t,`symbol property ${String(n)}`);let r=e,i=[];for(let e=0;e<r.length;e+=1){let a=Object.getOwnPropertyDescriptor(r,String(e));if(!a||!a.enumerable||!(`value`in a))throw hF(`${t}[${e}]`,`sparse or accessor array item`);i.push(gF(a.value,`${t}[${e}]`,n))}for(let e of Object.getOwnPropertyNames(r)){if(e===`length`)continue;let n=Number(e);if(!Number.isInteger(n)||n<0||n>=r.length||String(n)!==e)throw hF(t,`non-index array property ${e}`);let i=Object.getOwnPropertyDescriptor(r,e);if(!i||!i.enumerable||!(`value`in i))throw hF(`${t}[${n}]`,`non-enumerable or accessor array item`)}return`[${i.join(`,`)}]`}let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw hF(t,`only plain objects are supported`);for(let n of Object.getOwnPropertySymbols(e))throw hF(t,`symbol property ${String(n)}`);for(let n of Object.getOwnPropertyNames(e)){let r=Object.getOwnPropertyDescriptor(e,n);if(!r||!r.enumerable||!(`value`in r))throw hF(`${t}.${n}`,`non-enumerable or accessor property`)}let i=[];for(let r of Object.keys(e).sort()){let a=Object.getOwnPropertyDescriptor(e,r);if(!a||!(`value`in a))throw hF(`${t}.${r}`,`accessor property`);i.push(`${JSON.stringify(r)}:${gF(a.value,`${t}.${r}`,n)}`)}return`{${i.join(`,`)}}`}finally{n.delete(e)}}function _F(e){return gF(e,`$`,new Set)}function vF(e){return new TextEncoder().encode(_F(e))}function yF(e,t){if(e.length===0||e.includes(`\0`))throw new y(`invalid_digest_domain`,`Digest domains must be non-empty and NUL-free.`,{field:`domain`});let n=new TextEncoder().encode(`holycodex-sha256\0`),r=new TextEncoder().encode(e),i=n.byteLength+8+r.byteLength;for(let e of t){if(e.byteLength>4294967295||i>4294967291-e.byteLength)throw new y(`invalid_digest_domain`,`Digest input is too large.`);i+=4+e.byteLength}let a=new Uint8Array(i),o=new DataView(a.buffer);a.set(n,0);let s=n.byteLength;o.setUint32(s,r.byteLength,!1),s+=4,a.set(r,s),s+=r.byteLength,o.setUint32(s,t.length,!1),s+=4;for(let e of t)o.setUint32(s,e.byteLength,!1),s+=4,a.set(e,s),s+=e.byteLength;return a}function bF(e){let t=``;for(let n of e)t+=n.toString(16).padStart(2,`0`);return t}async function xF(e,t){let n=globalThis.crypto?.subtle;if(!n)throw new y(`crypto_unavailable`,`The standards-based crypto API is unavailable.`);let r=await n.digest(`SHA-256`,SF(yF(e,t)));return bF(new Uint8Array(r))}function SF(e){let t=new Uint8Array(e.byteLength);return t.set(e),t}var CF=v((()=>{ve(),GP()}));function wF(e){try{return _F(e)!==void 0}catch{return!1}}function TF(e){let t=mP(JF,e);return er(t)?ge(_e(`CLI envelope`,t.left)):he(t.right)}var EF,DF,OF,kF,AF,jF,MF,NF,PF,FF,IF,LF,RF,zF,BF,VF,HF,UF,WF,GF,KF,qF,JF,YF=v((()=>{lr(),pP(),CF(),jP(),me(),ve(),GP(),mF(),gP(),EF=H(`blocked`,`completed`,`failed`,`partial`),DF=U(H(`high`,`max`,`xhigh`),Aj),OF=G(e=>wF(e)),kF=G(e=>de(e)&&!Array.isArray(e)&&wF(e)),W({blocked:q,changed_files:Vj(K),confidence:Fj,context_owner:U(K,Aj),material_findings:Vj(K),needs_more_context:q,needs_root_decision:q,needs_verification:q,relevant_files:Vj(K),remaining_risk:Vj(K),reuse_recommended:q,status:EF,suggested_followup:U(K,Aj),suggested_luna_effort:DF,suggested_specialist:U(uF,Aj),verification:Vj(K),verification_passed:q}),AF=`holycodex-specialist-outcome-2`,jF=K.pipe(yM(1)),MF={protocol_version:H(AF),route:dF,evidence:Vj(jF)},W(MF),NF=W({...MF,status:H(`completed`),summary:jF}),PF=W({...MF,status:H(`blocked`),reason:jF,needs_root_decision:q}),FF=W({...MF,status:H(`partial`),summary:jF,completed:Vj(jF),remaining:Vj(jF),needs_root_decision:q}),IF=W({...MF,status:H(`failed`),error:jF}),U(NF,PF,FF,IF),LF={protocol_version:H(AF),capability:CP,route:U(dF,Aj),evidence:Vj(jF),data:OF},RF=W({...LF,status:H(`completed`),summary:jF}),zF=W({...LF,status:H(`blocked`),reason:jF,needs_root_decision:q}),BF=W({...LF,status:H(`partial`),summary:jF,completed:Vj(jF),remaining:Vj(jF),needs_root_decision:q}),VF=W({...LF,status:H(`failed`),error:jF}),U(RF,zF,BF,VF),HF=Vj(K),UF=K.pipe(CM(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),WF=H(fe),GF=W({code:HP,message:K,details:kF}),KF=W({schema_version:WF,ok:H(!0),command:UF,data:OF,warnings:HF}),qF=W({schema_version:WF,ok:H(!1),command:UF,error:GF,warnings:HF}),JF=U(KF,qF)}));function XF(e,t,n){return{key:`${e}:${t}`,role:e,task:t,model:`Luna`,effort:n}}function ZF(e){let t=iI.get(e);if(t===void 0)throw new y(`catalog_invalid`,`A specialist plan has no route effort policy.`,{plan:e});return rF.flatMap(n=>n.tasks.map(r=>{let i=`${n.role}:${r.name}`,a=t.efforts[i];if(a===void 0)throw new y(`catalog_invalid`,`A route effort policy is incomplete.`,{plan:e,route:i});return XF(n.role,r.name,a)}))}function QF(e){return{...e,specialistModel:`Luna`,defaultServiceTier:`standard`,routes:ZF(e.name)}}function $F(e){let t=[`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`];if(e.length!==t.length)throw new y(`catalog_invalid`,`The plan catalog has an invalid size.`);for(let n=0;n<t.length;n+=1){let r=e[n],i=t[n];if(!r||r.name!==i)throw new y(`catalog_invalid`,`The plan catalog order is invalid.`,{index:n});let a=r.name===`go`?{model:`Terra`,effort:`high`}:r.name===`plus-low`?{model:`Sol`,effort:`low`}:r.name===`plus`?{model:`Sol`,effort:`medium`}:r.name===`pro-20x`?{model:`Sol`,effort:`xhigh`}:{model:`Sol`,effort:`high`};if(r.root.model!==a.model||r.root.effort!==a.effort)throw new y(`catalog_invalid`,`A plan has an invalid Root route.`,{plan:r.name});if(r.specialistModel!==`Luna`||r.defaultServiceTier!==`standard`)throw new y(`catalog_invalid`,`A plan has an invalid specialist policy.`,{plan:r.name});if(r.routes.length!==fF.length)throw new y(`catalog_invalid`,`A specialist plan is incomplete.`,{plan:r.name});let o=new Set;for(let e of r.routes){if(o.has(e.key)||!tI.has(e.key)||e.model!==`Luna`||`${e.role}:${e.task}`!==e.key)throw new y(`catalog_invalid`,`A plan contains an invalid route.`,{plan:r.name});o.add(e.key)}if(o.size!==fF.length)throw new y(`catalog_invalid`,`A plan is missing a specialist route.`,{plan:r.name})}let n=e[0]?.routes,r=e[1]?.routes;if(!n||!r||n.length!==r.length||n.some((e,t)=>e.key!==r[t]?.key||e.model!==r[t]?.model||e.effort!==r[t]?.effort))throw new y(`catalog_invalid`,`go must use the plus-low specialist route matrix.`);let i=e;for(let e=0;e<fF.length;e+=1){let t=-1;for(let n of i){let r=n.routes[e];if(!r||nI[r.effort]<t)throw new y(`catalog_invalid`,`Plan route effort is not monotonic.`,{route:fF[e]??`unknown`});t=nI[r.effort]}}}function eI(e){let t=mP(eF,e);if(er(t))return ge(new y(`invalid_plan`,`Unknown plan selection.`,{field:`plan`},{cause:t.left}));let n=sI.get(t.right);return n?he(n):ge(new y(`invalid_plan`,`Unknown plan selection.`,{plan:t.right}))}var tI,nI,rI,iI,aI,oI,sI,cI,lI=v((()=>{lr(),me(),ve(),mF(),gP(),tI=new Set(fF),nI={low:0,medium:1,high:2,xhigh:3,max:4},rI=[{plan:`plus-low`,rationale:`Preserve the approved plus-low route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`high`,"Librarian:lookup":`medium`,"Librarian:research":`high`,"Worker:mechanical":`high`,"Worker:implementation":`high`,"Worker:integration":`xhigh`,"Worker:operations":`high`,"Reviewer:plan":`high`,"Reviewer:code":`xhigh`,"Reviewer:artifact":`high`}},{plan:`plus`,rationale:`Preserve the approved plus route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`high`,"Librarian:lookup":`medium`,"Librarian:research":`high`,"Worker:mechanical":`high`,"Worker:implementation":`xhigh`,"Worker:integration":`xhigh`,"Worker:operations":`high`,"Reviewer:plan":`high`,"Reviewer:code":`xhigh`,"Reviewer:artifact":`high`}},{plan:`plus-high`,rationale:`Preserve the approved plus-high route effort policy.`,efforts:{"Explorer:lookup":`medium`,"Explorer:trace":`xhigh`,"Librarian:lookup":`medium`,"Librarian:research":`xhigh`,"Worker:mechanical":`high`,"Worker:implementation":`xhigh`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`xhigh`,"Reviewer:code":`max`,"Reviewer:artifact":`xhigh`}},{plan:`pro-5x`,rationale:`Preserve the approved pro-5x route effort policy.`,efforts:{"Explorer:lookup":`high`,"Explorer:trace":`xhigh`,"Librarian:lookup":`high`,"Librarian:research":`xhigh`,"Worker:mechanical":`high`,"Worker:implementation":`max`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`xhigh`,"Reviewer:code":`max`,"Reviewer:artifact":`xhigh`}},{plan:`pro-20x`,rationale:`Preserve the approved pro-20x route effort policy.`,efforts:{"Explorer:lookup":`high`,"Explorer:trace":`xhigh`,"Librarian:lookup":`high`,"Librarian:research":`max`,"Worker:mechanical":`xhigh`,"Worker:implementation":`max`,"Worker:integration":`max`,"Worker:operations":`xhigh`,"Reviewer:plan":`max`,"Reviewer:code":`max`,"Reviewer:artifact":`max`}}],ue(rI),iI=new Map(rI.map(e=>[e.plan,e])),aI=[{name:`go`,root:{model:`Terra`,effort:`high`},specialistModel:`Luna`,defaultServiceTier:`standard`,routes:ZF(`plus-low`)},QF({name:`plus-low`,root:{model:`Sol`,effort:`low`}}),QF({name:`plus`,root:{model:`Sol`,effort:`medium`}}),QF({name:`plus-high`,root:{model:`Sol`,effort:`high`}}),QF({name:`pro-5x`,root:{model:`Sol`,effort:`high`}}),QF({name:`pro-20x`,root:{model:`Sol`,effort:`xhigh`}})],$F(aI),ue(aI),oI=aI,sI=new Map,cI=new Map;for(let e of oI){sI.set(e.name,e);let t=new Map;for(let n of e.routes)t.set(n.key,n);cI.set(e.name,t)}})),uI=v((()=>{me(),ve(),gP(),jP(),BP(),GP(),mF(),YF(),lI(),CF()}));uI();const dI=Object.freeze([{name:`yes`,kind:`boolean`,usage:`--yes`,description:`Confirm installation.`},{name:`plan`,kind:`value`,usage:`--plan <go|plus-low|plus|plus-high|pro-5x|pro-20x>`,description:`Select routing (default: plus).`},{name:`tier`,kind:`value`,usage:`--tier <standard|fast|fast-all>`,description:`Select service handling (default: standard).`},{name:`work`,kind:`boolean`,usage:`--work / --no-work`,description:`Work plugins (default: false).`},{name:`frontend`,kind:`boolean`,usage:`--frontend / --no-frontend`,description:`Frontend plugins via build-web-apps (default: true).`},{name:`security`,kind:`boolean`,usage:`--security / --no-security`,description:`Security plugins (default: true).`},{name:`computer-use`,kind:`boolean`,usage:`--computer-use / --no-computer-use`,description:`Computer Use plugins (default: false).`},{name:`add-plugin`,kind:`value`,usage:`--add-plugin <id>`,description:`Add a Codex plugin; repeatable.`},{name:`json`,kind:`boolean`,usage:`--json`,description:`Emit one JSON envelope.`}]),fI=new Set([`codex-home`,`plan`,`tier`,`add-plugin`]),pI=new Set([`yes`,`json`,`verbose`,`dry-run`,`computer-use`,`no-computer-use`,`work`,`no-work`,`frontend`,`no-frontend`,`security`,`no-security`]);var mI=class extends Error{code;details;constructor(e,t,n={}){super(t),this.name=`ArgumentError`,this.code=e,this.details=n}};function hI(e){if(e.length===0)throw new mI(`unknown_command`,`A command is required.`);if(e.includes(`-h`)||e.includes(`--help`)||e.includes(`--help=true`))return{command:`help`,positionals:[],options:{}};if(e[0]===`help`)return{command:`help`,positionals:e.slice(1),options:{}};if(e[0]===`-v`||e[0]===`--version`||e[0]===`--version=true`)return hI([`version`,...e.slice(1)]);let t=e[0];if(t!==`install`&&t!==`doctor`&&t!==`remove`&&t!==`version`)throw new mI(`unknown_command`,`Unknown command.`,{command:t??``});let n=[],r={};for(let t=1;t<e.length;t+=1){let i=e[t];if(i===void 0)continue;if(i===`-`||!i.startsWith(`-`)){n.push(i);continue}if(!i.startsWith(`--`)||i===`--`)throw new mI(`invalid_argument`,`Short options are not supported.`,{option:i});let a=i.slice(2),o=a.indexOf(`=`),s=o>=0?a.slice(0,o):a,c=o>=0?a.slice(o+1):void 0,l=s.replaceAll(`_`,`-`);if(!fI.has(l)&&!pI.has(l))throw new mI(`invalid_argument`,`Unknown option.`,{option:`--${s}`});if(fI.has(l)){let n=c??e[t+1];if(n===void 0||n.length===0||n.startsWith(`-`))throw new mI(`invalid_argument`,`Option --${s} requires a value.`,{option:`--${s}`});if(c===void 0&&(t+=1),l===`add-plugin`){let e=r[l];r[l]=Array.isArray(e)?[...e,n]:[n]}else{if(r[l]!==void 0)throw new mI(`invalid_argument`,`Option --${s} may only be supplied once.`,{option:`--${s}`});r[l]=n}continue}if(c!==void 0&&c!==`true`&&c!==`false`)throw new mI(`invalid_argument`,`Option --${s} is boolean.`,{option:`--${s}`});if(r[l]!==void 0)throw new mI(`invalid_argument`,`Option --${s} may only be supplied once.`,{option:`--${s}`});r[l]=c!==`false`}return gI(t,n,r),{command:t,positionals:n,options:r}}function gI(e,t,n){let r=_I(e);for(let t of Object.keys(n))if(!r.has(t))throw new mI(`invalid_argument`,`Option --${t} is not valid for ${e}.`,{option:`--${t}`});let i=e===`version`?{min:0,max:1}:{min:0,max:0};if(t.length<i.min||t.length>i.max)throw new mI(`invalid_argument`,`Invalid positional arguments for ${e}.`);let a=n.plan;if(typeof a==`string`&&!eI(a).ok)throw new mI(`invalid_argument`,`The plan is not supported.`,{plan:a});let o=n.tier;if(typeof o==`string`&&o!==`standard`&&o!==`fast`&&o!==`fast-all`)throw new mI(`invalid_argument`,`The tier is not supported.`,{tier:o});for(let[e,t]of[[`computer-use`,`no-computer-use`],[`work`,`no-work`],[`frontend`,`no-frontend`],[`security`,`no-security`]])if(n[e]!==void 0&&n[t]!==void 0)throw new mI(`invalid_argument`,`Conflicting --${e} and --${t} options.`);if(e===`install`&&n.yes===!1)throw new mI(`invalid_argument`,`--yes cannot be false.`);if(e!==`install`&&Object.keys(n).some(e=>[`plan`,`tier`,`work`,`no-work`,`frontend`,`no-frontend`,`security`,`no-security`,`computer-use`,`no-computer-use`,`add-plugin`].includes(e)))throw new mI(`invalid_argument`,`Installation options are not valid for ${e}.`)}function _I(e){switch(e){case`install`:return new Set([...dI.map(e=>e.name),`no-work`,`no-frontend`,`no-security`,`no-computer-use`,`codex-home`,`verbose`]);case`doctor`:return new Set([`json`,`verbose`,`codex-home`]);case`remove`:return new Set([`yes`,`json`,`verbose`,`codex-home`]);case`version`:return new Set([`json`,`verbose`,`dry-run`]);default:return new Set}}const vI=`Install HolyCodex through Codex native plugin management.
22
22
 
23
23
  Usage:
24
24
  holycodex install [options]
@@ -37,7 +37,7 @@ Tier is independent service handling (CLI values are lowercase only):
37
37
  fast-all Fast service handling for Root and leaves.
38
38
 
39
39
  Options:
40
- ${Vj.map(e=>` ${e.usage.padEnd(48)} ${e.description}`).join(`
40
+ ${dI.map(e=>` ${e.usage.padEnd(48)} ${e.description}`).join(`
41
41
  `)}
42
42
  --no-work / --no-frontend / --no-security /
43
43
  --no-computer-use Disable the corresponding plugin.
@@ -45,7 +45,7 @@ ${Vj.map(e=>` ${e.usage.padEnd(48)} ${e.description}`).join(`
45
45
 
46
46
  Capability defaults: Work false, Frontend true (mapped to build-web-apps),
47
47
  Security true, and Computer Use false. --add-plugin may be repeated.
48
- `;function Yj(e){switch(e){case`install`:return Jj;case`remove`:return`Remove HolyCodex-owned state through Codex native plugin management.
48
+ `;function yI(e){switch(e){case`install`:return vI;case`remove`:return`Remove HolyCodex-owned state through Codex native plugin management.
49
49
 
50
50
  Usage:
51
51
  holycodex remove [--yes] [--json] [--codex-home <absolute-path>]
@@ -76,19 +76,17 @@ Options:
76
76
  --json Emit one validated JSON envelope.
77
77
 
78
78
  Use --json for scripts. Install and remove use native Codex plugin management.
79
- `}}function Xj(e,t={}){let n=$j({...t,stream:`stdout`});return Yj(e).split(`
80
- `).map(e=>e===`HolyCodex`||/^(?:Usage|Options|Plans control routing only|Tier is independent service handling|Capability defaults).*:$/u.test(e)?eM(e,`heading`,n):e.replace(/--[a-z][a-z0-9-]*/gu,e=>eM(e,`option`,n)).replace(/<[^>]+>/gu,e=>eM(e,`argument`,n))).join(`
81
- `)}function Zj(e){return e.some(e=>e===`-h`||e===`--help`||e===`--help=true`)}function Qj(e){let t=e.filter(e=>!e.startsWith(`-`));return t[0]===`help`?t[1]:t[0]===`--version`||t[0]===`version`||t[0]===`-v`?`version`:t[0]}function $j(e){let t=e.env??{};return t.NO_COLOR!==void 0||t.TERM===`dumb`?!1:t.FORCE_COLOR!==void 0&&t.FORCE_COLOR!==`0`?!0:t.CI!==void 0&&t.CI!==`false`?!1:(e.stream===`stderr`?e.stderrIsTTY:e.stdoutIsTTY)===!0}function eM(e,t,n){return n?`\u001b[${{heading:`1`,option:`36`,argument:`2`}[t]}m${e}\u001b[0m`:e}function J(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function tM(e){try{return sj(e),!0}catch{return!1}}const nM=B(e=>tM(e)),rM=B(e=>J(e)&&tM(e));V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u));const iM=V.pipe(q(e=>e.length>0&&e.length<=4096));PD.pipe(q(e=>Number.isFinite(e)&&e>=0));function aM(e){switch(e){case`invalid_external_data`:case`manifest_invalid`:case`empty_output_directory`:return`validation`;case`discovery_failed`:return`identity`;case`protocol_mismatch`:case`method_unsupported`:case`server_request_unsupported`:case`unexpected_response`:return`protocol`;case`invalid_transport_line`:case`transport_closed`:case`transport_failure`:return`transport`;case`approval_required`:case`permission_denied`:return`approval`;case`cancellation`:return`interruption`;case`timeout`:return`timeout`;case`turn_failed`:return`turn`;case`closed`:return`closed`;case`server_error`:return`server`}}var Y=class extends Error{code;kind;details;retryable;constructor(e,t,n={},r){super(t,r?.cause===void 0?void 0:{cause:r.cause}),this.name=`CodexError`,this.code=e,this.kind=aM(e),this.details=n,this.retryable=r?.retryable??!1,Object.freeze(this.details),Object.freeze(this)}};function oM(e){return{ok:!1,error:e}}function sM(e){return{ok:!0,value:e}}function cM(e,t=512){let n=``;for(let t of e){let e=t.codePointAt(0)??0;n+=e<=8||e===11||e===12||e>=14&&e<=31||e===127?` `:t}return n.replace(/\s+/gu,` `).trim().slice(0,t)}function lM(e,t=0){if(t>3)return`[truncated]`;if(e===null||typeof e==`boolean`)return e;if(typeof e==`string`)return cM(e,256);if(typeof e==`number`)return Number.isFinite(e)?e:null;if(Array.isArray(e))return e.slice(0,32).map(e=>lM(e,t+1));if(J(e)){let n={};for(let[r,i]of Object.entries(e).slice(0,32)){let e=cM(r,96);e.length>0&&(n[e]=lM(i,t+1))}return n}return`[redacted]`}function uM(e){let t=lM(e);return J(t)?t:{value:t}}function dM(e,t,n){return new Y(`invalid_external_data`,`Invalid ${e}.`,{field:e,received:lM(t)},n===void 0?void 0:{cause:n})}function fM(e,t,n){let r=yA(e,t);if(Dn(r))throw dM(n,t,String(r.left));return r.right}function pM(e,t){try{return fM(e,t,`value`),!0}catch{return!1}}const mM=[`initialize`,`thread/start`,`thread/resume`,`thread/read`,`thread/list`,`thread/fork`,`thread/unsubscribe`,`turn/start`,`turn/steer`,`turn/interrupt`,`model/list`,`modelProvider/capabilities/read`,`config/read`,`permissionProfile/list`],hM=[`item/commandExecution/requestApproval`,`item/fileChange/requestApproval`,`applyPatchApproval`,`execCommandApproval`],gM=[`item/permissions/requestApproval`],_M=[`mcpServer/elicitation/request`],vM=[`item/tool/call`],yM={method:`initialized`};function bM(e,t=new Set){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;t.add(e);try{return Array.isArray(e)?e.every(e=>bM(e,t)):J(e)&&Object.values(e).every(e=>bM(e,t))}finally{t.delete(e)}}function xM(e){return J(e)&&bM(e)}B(e=>bM(e));const SM=B(e=>xM(e));function CM(e){if(!/^[A-Za-z][A-Za-z0-9_-]*(?:\.[A-Za-z][A-Za-z0-9_-]*)*$/u.test(e))throw dM(`TOML key path`,e);let t=e.split(`.`);if(t.some(e=>e===`__proto__`||e===`constructor`||e===`prototype`))throw dM(`TOML key path`,e);return t}function wM(e,t){if(!xM(e))throw dM(`TOML document`,e);let n=e;for(let e of CM(t)){if(!xM(n)||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}function TM(e){return Array.isArray(e)?e.map(TM):J(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,TM(t)])):e}function EM(e){return TM(e)}function DM(e,t,n){if(!xM(e)||!bM(n))throw dM(`TOML write`,{keyPath:t});let r=CM(t),i={...EM(e)},a=i;for(let e of r.slice(0,-1)){let n=a[e];if(n!==void 0&&!xM(n))throw dM(`TOML table path`,t);let r=n===void 0?{}:{...n};a[e]=r,a=r}return a[r.at(-1)]=TM(n),i}function OM(e,t){if(!xM(e))throw dM(`TOML document`,e);let n=CM(t),r={...EM(e)},i=[],a=r;for(let e of n.slice(0,-1)){let t=a[e];if(!xM(t))return r;let n={...t};i.push({table:a,key:e}),a[e]=n,a=n}let o=n.at(-1);if(!Object.prototype.hasOwnProperty.call(a,o))return r;delete a[o];for(let e=i.length-1;e>=0;--e){let t=i[e],n=t.table[t.key];if(xM(n)&&Object.keys(n).length===0)delete t.table[t.key];else break}return r}const kM=[`model`,`model_reasoning_effort`,`service_tier`,`model_verbosity`,`developer_instructions`,`suppress_unstable_features_warning`,`features.default_mode_request_user_input`,`features.multi_agent_v2`,`features.context_management.experimental_mode`];B(e=>AM(e));function AM(e){return typeof e==`string`?kM.includes(e)?!0:/^agents\.(?:explorer|librarian|worker|reviewer)\.config_file$/u.test(e):!1}B(e=>LM(e)),B(e=>zM(e)),B(e=>BM(e));const jM=B(e=>VM(e)),MM=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;function NM(e){return typeof e==`string`&&MM.test(e)}function PM(e){return e===`gpt-5.6-terra`||e===`gpt-5.6-sol`||e===`gpt-5.6-luna`||e===`low`||e===`medium`||e===`high`||e===`xhigh`||e===`max`||e==="default"||e===`fast`}function FM(e){return typeof e==`string`&&/^[a-f0-9]{64}$/u.test(e)}function IM(e,t){let n=new Set(t);return Object.keys(e).every(e=>n.has(e))}function LM(e){if(!J(e)||!IM(e,[`kind`,`value`])||typeof e.kind!=`string`)return!1;switch(e.kind){case`enum`:return PM(e.value);case`boolean`:return typeof e.value==`boolean`;case`relative_path`:return typeof e.value==`string`&&UM(e.value);case`digest`:return FM(e.value);default:return!1}}function RM(e,t){switch(KM(e)){case`boolean`:return t.kind===`boolean`;case`relative_path`:return t.kind===`relative_path`;case`digest`:return t.kind===`digest`;case`enum`:return t.kind===`enum`?e===`model`?t.value===`gpt-5.6-terra`||t.value===`gpt-5.6-sol`||t.value===`gpt-5.6-luna`:e===`model_reasoning_effort`?t.value===`low`||t.value===`medium`||t.value===`high`||t.value===`xhigh`||t.value===`max`:e===`service_tier`?t.value==="default"||t.value===`fast`:t.value===`low`||t.value===`medium`||t.value===`high`:!1}}function zM(e){return J(e)&&e.kind===`absent`?Object.keys(e).length===1:LM(e)}function BM(e){return J(e)&&IM(e,[`owner`,`schema`,`installId`,`keyPath`,`originalValue`,`lastManagedValue`])&&e.owner===`holycodex`&&typeof e.schema==`string`&&NM(e.schema)&&NM(e.installId)&&AM(e.keyPath)&&zM(e.originalValue)&&LM(e.lastManagedValue)&&RM(e.keyPath,e.lastManagedValue)&&(e.originalValue.kind===`absent`||RM(e.keyPath,e.originalValue))}function VM(e){return!J(e)||!IM(e,[`owner`,`schema`,`installId`,`managed`])||e.owner!==`holycodex`||!NM(e.schema)||!NM(e.installId)||!J(e.managed)?!1:Object.entries(e.managed).every(([e,t])=>AM(e)&&BM(t)&&t.keyPath===e)}function HM(e){if(!NM(e.schema)||!NM(e.installId))throw dM(`managed runtime config metadata`,{schema:e.schema});return{owner:`holycodex`,schema:e.schema,installId:e.installId,managed:{}}}function UM(e){if(e.length===0||e.includes(`\0`)||/^[\\/]|^[A-Za-z]:[\\/]/u.test(e))return!1;let t=e.replaceAll(`\\`,`/`).split(`/`);return t.some(e=>e!==`.`)&&t.every(e=>e.length>0&&e!==`..`)}function WM(e){if(!UM(e))throw dM(`relative config path`,`[redacted]`);return e.replaceAll(`\\`,`/`).split(`/`).filter(e=>e!==`.`).join(`/`)}function GM(e,t){let n=WM(t),r=e.replaceAll(`\\`,`/`).split(`/`);r.pop();let i=[...r,...n.split(`/`)].join(`/`),a=[];for(let e of i.split(`/`))e.length!==0&&e!==`.`&&(e===`..`?a.pop():a.push(e));let o=e.replaceAll(`\\`,`/`);return`${o.startsWith(`//`)?`//`:o.startsWith(`/`)?`/`:``}${a.join(`/`)}`}function KM(e){return e===`developer_instructions`?`digest`:e.endsWith(`.config_file`)?`relative_path`:e===`suppress_unstable_features_warning`||e===`features.default_mode_request_user_input`||e===`features.multi_agent_v2`||e===`features.context_management.experimental_mode`?`boolean`:`enum`}function qM(e,t){let n=KM(e);return n===`boolean`?typeof t==`boolean`:n===`relative_path`?typeof t==`string`&&UM(t):n===`digest`?typeof t==`string`:typeof t==`string`&&PM(t)}async function JM(e,t){if(!AM(e)||!bM(t))throw dM(`managed config value`,{keyPath:e});let n=KM(e);return n===`boolean`&&typeof t==`boolean`?{kind:n,value:t}:n===`relative_path`&&typeof t==`string`&&UM(t)?{kind:n,value:WM(t)}:n===`enum`&&typeof t==`string`&&PM(t)?{kind:n,value:t}:{kind:`digest`,value:await dj(`holycodex-managed-config-value`,[cj({keyPath:e,value:t})])}}function YM(e){if(e.kind===`enum`||e.kind===`boolean`||e.kind===`relative_path`)return e.value}async function XM(e,t,n,r){if(!xM(e)||!VM(t)||!NM(r.schema)||!NM(r.installId))throw dM(`managed runtime config`,{});let i={...t.managed},a=EM(e),o=[];for(let[e,s]of Object.entries(n)){if(!AM(e)||typeof s!=`string`&&typeof s!=`boolean`)throw dM(`managed config key`,e);let n=e,c=t.managed[n],l=wM(a,n);if(c&&(c.schema!==r.schema||c.installId!==r.installId)){o.push(n);continue}if(c&&c.owner===`holycodex`){let e=l===void 0?void 0:await JM(n,l);if(e===void 0||JSON.stringify(e)!==JSON.stringify(c.lastManagedValue)){o.push(n);continue}}let u=c?.originalValue??(l===void 0?{kind:`absent`}:await JM(n,l));if(!qM(n,s))throw dM(`managed config value`,{keyPath:n});a=DM(a,n,s),i[n]={owner:`holycodex`,schema:r.schema,installId:r.installId,keyPath:n,originalValue:u,lastManagedValue:await JM(n,s)}}let s={owner:`holycodex`,schema:r.schema,installId:r.installId,managed:i};if(!VM(s))throw dM(`managed runtime config state`,{});return{document:a,state:s,driftedKeys:o}}async function ZM(e,t,n){if(!xM(e)||!VM(t))throw dM(`managed runtime config`,{});let r=EM(e),i={...t.managed},a=[],o=[],s=[];for(let[e,c]of Object.entries(t.managed)){if(!AM(e))throw dM(`managed config key`,e);let t=e;if(c.owner!==`holycodex`||c.schema!==n.schema||c.installId!==n.installId)continue;let l=wM(r,t);if(l===void 0||JSON.stringify(await JM(t,l))!==JSON.stringify(c.lastManagedValue)){o.push(t);continue}if(c.originalValue.kind===`absent`)r=OM(r,t),a.push(t),delete i[t];else{let e=YM(c.originalValue);if(e===void 0){s.push(t),o.push(t);continue}r=DM(r,t,e),a.push(t),delete i[t]}}return{document:r,state:{...t,managed:i},restoredKeys:a,preservedKeys:o,unresolvedKeys:s}}async function QM(e,t,n){if(!AM(n)||!VM(t))throw dM(`managed config key`,n);let r=t.managed[n],i=wM(e,n),a=i===void 0?void 0:await JM(n,i);return r?{keyPath:n,status:a!==void 0&&JSON.stringify(a)===JSON.stringify(r.lastManagedValue)?`unchanged`:`drifted`,expected:r.lastManagedValue,...a===void 0?{}:{current:a}}:a===void 0?{keyPath:n,status:`unmanaged`}:{keyPath:n,status:`unmanaged`,current:a}}const $M=V.pipe(AO(/^[A-Za-z][A-Za-z0-9_./:-]{0,127}$/u)),eN=U(V.pipe(EO(1)),PD.pipe(q(e=>Number.isSafeInteger(e)))),tN=K({code:PD.pipe(q(e=>Number.isSafeInteger(e))),message:V,data:G(nM)}),nN=U(K({id:eN,result:nM}),K({id:eN,error:tN}));K({id:eN,error:tN});const rN=K({method:$M,params:G(nM)}),iN=K({id:eN,method:$M,params:G(nM),trace:G(nM)});function aN(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function oN(e,t,n){let r=new Set([...t,n]),i=Object.keys(e);return!Object.keys(e).some(e=>!r.has(e))&&i.length>0&&i.every(t=>aN(e[t]))}function sN(e){return!J(e)||!tM(e)?!1:oN(e,[`inputTokens`,`cachedInputTokens`,`outputTokens`,`reasoningOutputTokens`],`totalTokens`)||oN(e,[`input_tokens`,`cached_input_tokens`,`output_tokens`,`reasoning_output_tokens`],`total_tokens`)}B(sN);const cN=K({clientInfo:K({name:iM,version:iM,title:U(iM,kD)}),capabilities:U(K({experimentalApi:H,requestAttestation:H,mcpServerOpenaiFormElicitation:G(H),optOutNotificationMethods:G(U(W(V),kD)),extensions:G(rM)}),kD)}),lN=B(e=>J(e)&&tM(e)&&typeof e.userAgent==`string`&&typeof e.codexHome==`string`&&typeof e.platformFamily==`string`&&typeof e.platformOs==`string`),uN=K({method:z(`initialized`)});function dN(e){return J(e)&&tM(e)&&typeof e.id==`string`&&/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(e.id)}B(dN);function fN(e){return J(e)&&tM(e)&&dN(e.thread)}function pN(e){return J(e)&&tM(e)&&typeof e.id==`string`}const mN=B(e=>fN(e)||pN(e)),hN=mN,gN=mN,_N=B(SN),vN=B(e=>J(e)&&tM(e)&&(e.status===`notLoaded`||e.status===`notSubscribed`||e.status===`unsubscribed`)),yN=B(e=>fN(e)),bN=B(e=>{if(!J(e)||!tM(e))return!1;let t=Array.isArray(e.data)&&e.data.every(e=>dN(e)),n=Array.isArray(e.threads)&&e.threads.every(e=>dN(e));return t&&e.threads===void 0||n&&e.data===void 0}),xN=B(e=>J(e)&&tM(e));function SN(e){return J(e)&&tM(e)&&typeof e.threadId==`string`&&e.threadId.length>0}const CN=B(SN),wN=B(SN),TN=B(SN),EN=B(e=>J(e)&&tM(e));function DN(e){return J(e)&&tM(e)&&typeof e.id==`string`&&e.id.length>0&&(e.usage===void 0||sN(e.usage))}const ON=B(e=>SN(e)&&(Array.isArray(e.input)&&e.input.every(e=>tM(e))||typeof e.prompt==`string`&&e.prompt.length>0)),kN=B(e=>SN(e)&&typeof e.expectedTurnId==`string`&&Array.isArray(e.input)&&e.input.every(e=>tM(e))),AN=B(e=>J(e)&&tM(e)&&(e.turn!==void 0&&DN(e.turn)||typeof e.turnId==`string`&&e.turnId.length>0||typeof e.id==`string`&&e.id.length>0)),jN=B(e=>J(e)&&tM(e)&&typeof e.turnId==`string`&&e.turnId.length>0),MN=B(e=>SN(e)&&typeof e.turnId==`string`&&e.turnId.length>0),NN=B(e=>J(e)&&tM(e)),PN=B(e=>SN(e)&&(e.turn!==void 0&&DN(e.turn)||typeof e.turnId==`string`&&e.turnId.length>0)),FN=B(e=>J(e)&&tM(e));function IN(e){return J(e)&&tM(e)&&typeof e.id==`string`&&typeof e.model==`string`&&(e.supportedReasoningEfforts===void 0||Array.isArray(e.supportedReasoningEfforts)&&e.supportedReasoningEfforts.every(e=>J(e)&&typeof e.reasoningEffort==`string`))&&(e.serviceTiers===void 0||Array.isArray(e.serviceTiers)&&e.serviceTiers.every(e=>J(e)&&typeof e.id==`string`))&&(e.defaultServiceTier===void 0||e.defaultServiceTier===null||typeof e.defaultServiceTier==`string`)&&(e.multiAgentVersion===void 0||e.multiAgentVersion===null||e.multiAgentVersion===`disabled`||e.multiAgentVersion===`v1`||e.multiAgentVersion===`v2`)}const LN=B(e=>J(e)&&tM(e)&&Array.isArray(e.data)&&e.data.every(e=>IN(e))),RN=rM,zN=rM,BN=K({includeLayers:G(H),cwd:G(U(V,kD))}),VN=K({config:SM,origins:rM,layers:U(W(rM),kD)}),HN=rM,UN=rM,WN=B(e=>J(e)&&tM(e)&&(typeof e.id==`string`||typeof e.id==`number`&&Number.isSafeInteger(e.id))&&typeof e.method==`string`&&J(e.params)&&(e.category===`approval`||e.category===`dynamic_tool`||e.category===`elicitation`||e.category===`other`||e.category===`permissions`)),GN=nM;B(e=>J(e)&&tM(e)&&typeof e.kind==`string`&&typeof e.method==`string`);function KN(e){return gM.some(t=>t===e)?`permissions`:hM.some(t=>t===e)?`approval`:_M.some(t=>t===e)?`elicitation`:vM.some(t=>t===e)?`dynamic_tool`:`other`}uO({key:V,value:U(z(`stable`,`experimental`,`disabled`),H)});const qN={clientInfo:{name:`holycodex`,title:null,version:`0.15`},capabilities:null},JN=new Set(mM);var YN=class{transport;maxLineBytes;requestTimeoutMs;signal;notificationListeners=new Set;serverRequestHandlers=new Set;pending=new Map;serverRequestWork=new Set;serverRequestTasks=new Set;nextRequestId=1;readerPromise;initializePromise;transportClosePromise;initializeAttempted=!1;initialized=!1;closed=!1;constructor(e,t={}){if(this.transport=e,this.maxLineBytes=t.maxLineBytes??1048576,this.requestTimeoutMs=t.requestTimeoutMs,this.signal=t.signal,!Number.isSafeInteger(this.maxLineBytes)||this.maxLineBytes<1)throw new Y(`invalid_external_data`,`The maximum line size is invalid.`);if(this.requestTimeoutMs!==void 0&&(!Number.isSafeInteger(this.requestTimeoutMs)||this.requestTimeoutMs<1))throw new Y(`invalid_external_data`,`The request timeout is invalid.`);t.onNotification&&this.notificationListeners.add(t.onNotification),t.onServerRequest&&this.serverRequestHandlers.add(t.onServerRequest),this.signal?.aborted?this.close():this.signal&&this.signal.addEventListener(`abort`,()=>void this.close(),{once:!0})}get isInitialized(){return this.initialized}onNotification(e){return this.notificationListeners.add(e),()=>this.notificationListeners.delete(e)}onServerRequest(e){return this.serverRequestHandlers.add(e),()=>this.serverRequestHandlers.delete(e)}async initialize(e=qN){if(this.initializePromise)return this.initializePromise;if(this.initializeAttempted)throw new Y(`invalid_external_data`,`The App Server initialize handshake was already attempted.`);this.ensureOpen();let t=fM(cN,e,`initialize parameters`);return this.initializeAttempted=!0,this.initializePromise=this.performInitialize(t),this.initializePromise}async startThread(e={}){return this.action(`thread/start`,xN,e,mN)}async resumeThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/resume`,CN,t,hN)}async readThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/read`,wN,t,yN)}async listThreads(e={}){return this.action(`thread/list`,EN,e,bN)}async forkThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/fork`,TN,t,gN)}async unsubscribeThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/unsubscribe`,_N,t,vN)}async startTurn(e){return this.action(`turn/start`,ON,e,AN)}async steerTurn(e){return this.action(`turn/steer`,kN,e,jN)}async interruptTurn(e,t){let n=typeof e==`string`?{threadId:e,turnId:t??``}:e;return this.action(`turn/interrupt`,MN,n,NN)}async listModels(e={}){return this.action(`model/list`,FN,e,LN)}async readModelProviderCapabilities(e={}){return this.action(`modelProvider/capabilities/read`,RN,e,zN)}async readConfig(e={}){return this.action(`config/read`,BN,e,VN)}async listPermissionProfiles(e={}){return this.action(`permissionProfile/list`,HN,e,UN)}async call(e,t={}){if(e===`initialize`){let e=await this.initialize(fM(cN,t,`initialize parameters`));return fM(nM,e,`initialize result`)}let n=fM(iN,{id:1,method:e,params:t},`App Server method`);if(!JN.has(n.method))throw new Y(`method_unsupported`,`Unsupported App Server method: ${e}.`,{method:e});return this.request(n.method,n.params===void 0?{}:n.params)}async close(){await this.closeWithError(new Y(`closed`,`The App Server client is closed.`))}async performInitialize(e){try{let t=await this.request(`initialize`,fM(nM,e,`initialize parameters`)),n=fM(lN,t,`initialize result`),r=fM(uN,yM,`initialized notification`);return await this.transport.writeLine(JSON.stringify(r)),this.initialized=!0,n}catch(e){let t=e instanceof Y?e:new Y(`transport_failure`,`The initialize handshake failed.`,{},{cause:e});throw await this.closeWithError(t),t}}async action(e,t,n,r){let i=fM(t,n,`${e} parameters`),a=fM(nM,i,`${e} parameters`);return fM(r,await this.request(e,a),`${e} result`)}async request(e,t){if(this.ensureOpen(),e!==`initialize`&&!this.initialized)throw new Y(`invalid_external_data`,`The ${e} action requires an initialized App Server client.`);this.startReader();let n=this.nextRequestId;this.nextRequestId+=1;let r=fM(iN,{id:n,method:e,params:t},`${e} request`);return new Promise((t,i)=>{let a=!1,o,s,c=e=>{a||(a=!0,this.pending.delete(n),o!==void 0&&clearTimeout(o),s?.(),i(e))};if(this.requestTimeoutMs!==void 0&&(o=setTimeout(()=>c(new Y(`timeout`,`The ${e} request timed out.`,{method:e})),this.requestTimeoutMs)),this.signal){let t=()=>c(new Y(`cancellation`,`The ${e} request was cancelled.`,{method:e}));this.signal.addEventListener(`abort`,t,{once:!0}),s=()=>this.signal?.removeEventListener(`abort`,t)}let l={method:e,resolve:e=>{a||(a=!0,o!==void 0&&clearTimeout(o),s?.(),t(e))},reject:c,...o===void 0?{}:{timer:o},...s===void 0?{}:{removeAbortListener:s}};this.pending.set(n,l),this.transport.writeLine(JSON.stringify(r)).catch(e=>{c(e instanceof Y?e:new Y(`transport_failure`,`The App Server request could not be written.`,{},{cause:e}))})})}startReader(){this.readerPromise||=this.readLoop().catch(e=>this.handleReaderFailure(e)).catch(()=>void 0)}async readLoop(){for(;!this.closed;){let e=await this.transport.readLine();if(e===null){if(!this.closed)throw new Y(`transport_closed`,`The App Server transport closed.`);return}if(new TextEncoder().encode(e).byteLength>this.maxLineBytes)throw new Y(`invalid_transport_line`,`An App Server line exceeded the limit.`);this.handleLine(e)}}async handleReaderFailure(e){let t=e instanceof Y?e:new Y(`transport_failure`,`The App Server transport failed.`,{},{cause:e});await this.closeWithError(t)}handleLine(e){let t;try{t=JSON.parse(e)}catch(e){throw new Y(`invalid_transport_line`,`The App Server emitted invalid JSON.`,{},{cause:e})}let n=this.tryDecode(nN,t);if(n!==void 0){this.handleResponse(n);return}let r=this.tryDecode(iN,t);if(r!==void 0){this.handleServerRequest(r);return}let i=this.tryDecode(rN,t);if(i!==void 0){this.handleNotification(i);return}throw dM(`JSON-RPC message`,t)}tryDecode(e,t){try{return fM(e,t,`JSON-RPC message`)}catch{return}}handleResponse(e){let t=this.pending.get(e.id);if(!t)throw new Y(`unexpected_response`,`The App Server returned an unknown request id.`,{id:e.id});if(this.pending.delete(e.id),`error`in e){let n=e.error.code===-32001,r=ZN(t.method);t.reject(new Y(r,`The App Server rejected ${t.method}: ${cM(e.error.message)}.`,{method:t.method,serverCode:e.error.code,retryable:n,...e.error.data===void 0?{}:{data:lM(e.error.data)}},{retryable:n}));return}t.resolve(e.result)}handleServerRequest(e){let t=e.params??{},n=fM(WN,{...e,params:t,category:KN(e.method)},`server request`);this.emitNotification({kind:`server_request`,method:e.method,params:t});let r=[...this.serverRequestHandlers];if(r.length===0){this.trackServerRequestTask(this.writeServerError(e.id,-32601,`No handler for ${e.method}.`));return}let i=r[0];if(i===void 0){this.trackServerRequestTask(this.writeServerError(e.id,-32601,`No handler for ${e.method}.`));return}let a={active:!0};this.serverRequestWork.add(a);let o;try{o=i(n)}catch(t){this.completeServerRequest(a,()=>this.writeServerError(e.id,-32e3,cM(String(t))));return}if(o instanceof Promise){this.trackServerRequestTask(o.then(t=>this.completeServerRequest(a,()=>this.writeValidatedServerResult(e.id,t)),t=>this.completeServerRequest(a,()=>this.writeServerError(e.id,-32e3,cM(String(t))))));return}this.completeServerRequest(a,()=>this.writeValidatedServerResult(e.id,o))}writeValidatedServerResult(e,t){try{let n=fM(GN,t,`server response`);return this.writeServerResult(e,n)}catch(t){return this.writeServerError(e,-32e3,cM(String(t)))}}completeServerRequest(e,t){if(e.active){e.active=!1,this.serverRequestWork.delete(e);try{this.trackServerRequestTask(t())}catch{}}}trackServerRequestTask(e){let t=e.catch(()=>void 0);this.serverRequestTasks.add(t),t.then(()=>this.serverRequestTasks.delete(t),()=>this.serverRequestTasks.delete(t))}async writeServerResult(e,t){let n=fM(nN,{id:e,result:t},`server response`);await this.transport.writeLine(JSON.stringify(n))}async writeServerError(e,t,n){let r=fM(nN,{id:e,error:{code:t,message:XN(n)}},`server error response`);await this.transport.writeLine(JSON.stringify(r))}handleNotification(e){let t=e.params;if(e.method===`turn/completed`){let n=fM(PN,t,`turn/completed notification`);this.emitNotification({kind:`turn_completed`,method:e.method,params:n});return}if(e.method.includes(`agent`)||e.method.includes(`subagent`)){this.emitNotification({kind:`multi_agent`,method:e.method,...t===void 0?{}:{params:t}});return}this.emitNotification({kind:`unknown`,method:e.method,metadata:uM({params:lM(t)})})}emitNotification(e){for(let t of this.notificationListeners)try{t(e)}catch{}}rejectPending(e){for(let t of this.pending.values())t.reject(e);this.pending.clear()}async closeWithError(e){if(this.transportClosePromise!==void 0){await this.transportClosePromise;return}this.closed=!0,this.rejectPending(e);for(let e of this.serverRequestWork)e.active=!1;this.serverRequestWork.clear(),this.serverRequestTasks.clear(),this.transportClosePromise=Promise.resolve().then(()=>this.transport.close()).catch(()=>void 0),await this.transportClosePromise}ensureOpen(){if(this.closed)throw new Y(`closed`,`The App Server client is closed.`)}};function XN(e){let t=cM(e);return t.length>0?t:`server request failed`}function ZN(e){return gM.some(t=>t===e)?`permission_denied`:hM.some(t=>t===e)?`approval_required`:e===`turn/interrupt`?`cancellation`:e.startsWith(`turn/`)?`turn_failed`:`server_error`}function QN(e=process.env){let t=[`PATH`,`HOME`,`USER`,`CODEX_HOME`,`TMPDIR`,`TEMP`,`TMP`,`LANG`,`LC_ALL`],n={};for(let r of t){let t=e[r];t!==void 0&&t.length>0&&(n[r]=t)}return n}function $N(e=process.env){return Object.freeze(QN(e))}async function eP(e,t){let n=e.getReader(),r=[],i=0;try{for(;;){let e=await n.read();if(e.done)break;if(i+=e.value.byteLength,i>t)throw new Y(`invalid_transport_line`,`A subprocess stream exceeded its limit.`);r.push(e.value)}}finally{n.releaseLock()}let a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.byteLength;return a}function tP(e,t){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch(e){throw new Y(`invalid_transport_line`,`Invalid UTF-8 in ${t}.`,{},{cause:e})}}function nP(e){return cM(e.replace(/Bearer\s+[^\s]+/giu,`Bearer [redacted]`).replace(/((?:api[_-]?key|authorization|cookie|password|secret|token)\s*[:=]\s*)[^\s,;]+/giu,`$1[redacted]`),512)}var rP=class{process;stdin;stdoutReader;stderrStream;maxLineBytes;maxDiagnosticBytes;lineDecoder=new TextDecoder(`utf-8`,{fatal:!0});stderrDiagnostics=[];stdoutBuffer=new Uint8Array;stderrPromise;closed=!1;constructor(e){if(!g(e.executablePath))throw new Y(`discovery_failed`,`The Codex executable path must be absolute.`);if(this.maxLineBytes=e.maxLineBytes??1048576,this.maxDiagnosticBytes=e.maxDiagnosticBytes??65536,this.maxLineBytes<1||this.maxDiagnosticBytes<1)throw new Y(`invalid_external_data`,`The transport bounds are invalid.`);if(this.process=Bun.spawn([e.executablePath,`app-server`],{...e.cwd===void 0?{}:{cwd:e.cwd},env:QN(e.environment),stdin:`pipe`,stdout:`pipe`,stderr:`pipe`}),!(this.process.stdout instanceof ReadableStream)||!(this.process.stderr instanceof ReadableStream))throw new Y(`transport_failure`,`The Codex App Server did not expose stdio pipes.`);if(typeof this.process.stdin==`number`||this.process.stdin===void 0)throw new Y(`transport_failure`,`The Codex App Server did not expose stdin.`);this.stdin=this.process.stdin,this.stdoutReader=this.process.stdout,this.stderrStream=this.process.stderr,this.stderrPromise=this.collectStderr(),e.signal&&(e.signal.aborted?this.close():e.signal.addEventListener(`abort`,()=>void this.close(),{once:!0}))}get diagnostics(){return[...this.stderrDiagnostics]}async readLine(){if(this.closed&&this.stdoutBuffer.byteLength===0)return null;let e=this.stdoutReader.getReader();try{for(;;){let t=this.stdoutBuffer.indexOf(10);if(t>=0){if(t>this.maxLineBytes)throw await this.close(),new Y(`invalid_transport_line`,`The App Server emitted an overlong line.`);let e=this.stdoutBuffer.slice(0,t);this.stdoutBuffer=this.stdoutBuffer.slice(t+1);let n=e.at(-1)===13?e.slice(0,-1):e;return this.lineDecoder.decode(n)}if(this.stdoutBuffer.byteLength>this.maxLineBytes)throw await this.close(),new Y(`invalid_transport_line`,`The App Server emitted an overlong line.`);let n=await e.read();if(n.done){if(this.stdoutBuffer.byteLength===0)return null;if(this.stdoutBuffer.byteLength>this.maxLineBytes)throw await this.close(),new Y(`invalid_transport_line`,`The App Server emitted an overlong line.`);let e=this.stdoutBuffer;return this.stdoutBuffer=new Uint8Array,this.lineDecoder.decode(e)}let r=new Uint8Array(this.stdoutBuffer.byteLength+n.value.byteLength);r.set(this.stdoutBuffer,0),r.set(n.value,this.stdoutBuffer.byteLength),this.stdoutBuffer=r}}catch(e){throw e instanceof Y?e:new Y(`transport_failure`,`The App Server stdout could not be read.`,{},{cause:e})}finally{e.releaseLock()}}async writeLine(e){if(this.closed)throw new Y(`closed`,`The App Server transport is closed.`);if(new TextEncoder().encode(e).byteLength>this.maxLineBytes)throw new Y(`invalid_transport_line`,`The App Server request exceeded the line limit.`);try{await this.stdin.write(`${e}\n`),await this.stdin.flush()}catch(e){throw new Y(`transport_failure`,`The App Server stdin could not be written.`,{},{cause:e})}}async close(){if(!this.closed){this.closed=!0;try{await Promise.resolve(this.stdin.end())}catch{}try{this.process.kill()}catch{}await Promise.race([this.process.exited,new Promise(e=>setTimeout(()=>e(-1),1e3))]),await this.stderrPromise.catch(()=>void 0)}}async collectStderr(){try{let e=tP(await eP(this.stderrStream,this.maxDiagnosticBytes),`Codex stderr`);for(let t of e.split(/\r?\n/u).slice(0,128)){let e=nP(t);e.length>0&&this.stderrDiagnostics.push(e)}}catch{this.stderrDiagnostics.push(`[stderr unavailable]`)}}};async function iP(e){let t=[];if(e.executablePath!==void 0)t.push(ne(e.cwd??process.cwd(),e.executablePath));else{let n=e.pathValue??process.env.PATH??``,r=process.platform===`win32`?[`codex.exe`,`codex.cmd`,`codex`]:[`codex`];for(let e of n.split(m).filter(e=>e.length>0))for(let n of r)t.push(ne(e,n))}for(let n of t)try{let e=await d(n);if(!e.isFile()||process.platform!==`win32`&&!(e.mode&73))continue;return await s(n)}catch{if(e.executablePath!==void 0)throw new Y(`discovery_failed`,`The explicit Codex executable was not found.`,{path:n})}throw new Y(`discovery_failed`,`No Codex executable was found on the allowlisted PATH.`)}async function aP(e,t){let n=Bun.spawn([e,`--version`],{env:t,stdin:`ignore`,stdout:`pipe`,stderr:`pipe`});if(!(n.stdout instanceof ReadableStream)||!(n.stderr instanceof ReadableStream))throw new Y(`discovery_failed`,`The Codex version command did not expose output pipes.`);try{let[e,t,r]=await cP(Promise.all([eP(n.stdout,16384),eP(n.stderr,16384),n.exited]),()=>n.kill(),`The Codex version command timed out.`),i=cM(tP(e,`Codex version output`));if(r!==0||i.length===0)throw new Y(`discovery_failed`,`The Codex executable did not provide a version.`,{exitCode:r,diagnostics:nP(tP(t,`Codex version diagnostics`))});return i}catch(e){try{n.kill()}catch{}throw e instanceof Y?e:new Y(`discovery_failed`,`The Codex version command failed.`,{},{cause:e})}}async function oP(e){let t=await a(e),n=await crypto.subtle.digest(`SHA-256`,t),r=RA([...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``));if(!r.ok)throw new Y(`discovery_failed`,`The Codex executable digest was invalid.`);return r.value}async function sP(e={}){let t=await iP(e),n=QN(e.environment),r=e.versionRunner?cM(await e.versionRunner(t,n)):await aP(t,n);if(r.length===0)throw new Y(`discovery_failed`,`The Codex version output was empty.`);return{path:t,version:r,sha256:await oP(t)}}K({exitCode:PD.pipe(q(e=>Number.isSafeInteger(e))),stdout:V.pipe(wO(1048576)),stderr:V.pipe(wO(1048576))});async function cP(e,t,n){let r;try{return await Promise.race([e,new Promise((e,i)=>{r=setTimeout(()=>{try{t()}catch{}i(new Y(`timeout`,n))},3e4)})])}finally{r!==void 0&&clearTimeout(r)}}const lP=/^codex-cli \d+\.\d+\.\d+$/u,uP=/^codex-app-server-\d+\.\d+\.\d+$/u,dP=V.pipe(AO(/^[a-f0-9]{64}$/u));K({schema_version:z(`holycodex-generated-v2`),artifact_root:z(`packages/codex/generated`),codex_cli_version:V.pipe(AO(lP)),codex_cli_digest:dP,protocol_epoch:V.pipe(AO(uP)),generator:K({command:HD(z(`app-server`),z(`generate-ts`)),supported_surface:z(`codex app-server generators`)}),typescript_root:z(`typescript`),files:K({count:PD.pipe(ik(),pk()),digest:dP})}),K({path:V.pipe(EO(1)),size:PD.pipe(ik(),pk()),sha256:dP}),K({owner:z(`holycodex`),schema:V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),installId:V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u))});const fP=`https://github.com/openai/plugins.git`,pP=[`plugins`,`openai-plugins`],mP=3e4,hP=V.pipe(AO(/^[a-z][a-z0-9._-]{1,63}$/u)),gP=V.pipe(AO(/^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$/u)),_P=W(V),vP=V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u));K({name:hP,version:gP,description:iM,author:G(nM),license:G(iM),homepage:G(iM),repository:G(iM),keywords:G(_P),skills:G(_P),commands:G(_P),hooks:G(_P),assets:G(_P),official:G(H)});async function yP(e){let t=NP(e.selectedPluginIds);if(t.length===0)return;if(IP(e.timeoutMs,e.pollIntervalMs),e.signal?.aborted)throw new Z(`cancelled`,`Official Codex marketplace bootstrap was cancelled.`);let n=e.readSnapshot??DP,r=await n(e.codexHome);if(r!==void 0&&PP(r,t))return r;let i=e.initializeRuntime??(()=>FP(e)),a,o;try{a=await i()}catch(e){o=X(`marketplace_unavailable`,`Codex runtime initialization could not start the official marketplace sync. Check that Codex is available and its network/policy settings permit the official marketplace.`,e)}if(o===void 0)try{let r=e.timeoutMs??mP,i=e.pollIntervalMs??100,a=Date.now();for(;Date.now()-a<=r;){if(e.signal?.aborted)throw new Z(`cancelled`,`Official Codex marketplace bootstrap was cancelled.`);let o=await n(e.codexHome);if(o!==void 0&&PP(o,t))return o;let s=r-(Date.now()-a);if(s<=0)break;await(e.sleep??zP)(Math.min(i,s))}o=X(`marketplace_timeout`,`The official Codex marketplace did not become ready before the bounded wait expired. Check network access and Codex marketplace policy, then retry.`)}catch(e){if(e instanceof Z&&e.code===`cancelled`)throw e;o=e instanceof Z?e:X(`marketplace_unavailable`,`The official Codex marketplace sync failed before its bounded wait completed.`,e)}finally{await a?.()}if(e.gitFallback!==!1)try{return await bP({codexHome:e.codexHome,selectedPluginIds:e.selectedPluginIds,...e.environment===void 0?{}:{environment:e.environment},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.signal===void 0?{}:{signal:e.signal},...e.gitFallback===void 0?{}:e.gitFallback})}catch(e){throw e instanceof Z?e:X(`marketplace_unavailable`,`The official marketplace could not be populated after runtime startup (${o?.code??`unavailable`}). Check network access and retry.`,e)}throw o??X(`marketplace_timeout`,`The official Codex marketplace did not become ready before the bounded wait expired.`)}async function bP(e){let n=NP(e.selectedPluginIds);if(n.length===0)throw X(`marketplace_invalid`,`The official marketplace fallback requires at least one selected provider plugin.`);if(IP(e.timeoutMs,void 0),!g(e.codexHome))throw X(`marketplace_invalid`,`The Codex home for official marketplace fallback must be absolute.`);if(e.signal?.aborted)throw new Z(`cancelled`,`Official Codex marketplace fallback was cancelled.`);let i=QN(e.environment),a=e.gitRunner??GP(`git`,{environment:i,...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}),o=e.timeoutMs??mP,s;try{s=await xP(a,o,e.signal)}catch(e){throw e instanceof Z?e:X(`marketplace_unavailable`,`The official Codex marketplace remote HEAD could not be resolved. Check network access and retry.`,e)}let u=_(e.codexHome,`plugins`),d=_(u,pP[1]);if(await CP(u,e.codexHome),await t(d).catch(e=>{if(!RP(e))throw X(`marketplace_invalid`,`The reserved official marketplace path could not be inspected safely.`,e)})!==void 0)throw X(`marketplace_invalid`,`The reserved official marketplace path appeared during bootstrap; refusing to overwrite it.`);let f=await r(_(u,`.openai-plugins-stage-`));try{if(await LP(e.codexHome,f),e.cloneSnapshot!==void 0)await e.cloneSnapshot(fP,f);else{let t=await a.run([`clone`,`--depth=1`,`--no-tags`,fP,f],{...e.signal===void 0?{}:{signal:e.signal},timeoutMs:o});if(t.exitCode!==0)throw X(`marketplace_unavailable`,`The official Codex marketplace could not be downloaded. Check network access and retry.`,t.stderr)}await EP(f);let r=await OP(f,e.codexHome);if(r===void 0||!PP(r,n))throw X(`marketplace_invalid`,`The downloaded official marketplace is missing the selected plugin entries or manifest.`);if(await SP(a,f,o,e.signal)!==s)throw X(`marketplace_invalid`,`The downloaded official marketplace did not match the verified remote HEAD.`);if(await t(d).catch(e=>{if(!RP(e))throw X(`marketplace_invalid`,`The reserved official marketplace path could not be checked before publication.`,e)})!==void 0)throw X(`marketplace_invalid`,`The reserved official marketplace path appeared during staging; refusing to overwrite it.`);await c(f,d);let i=await DP(e.codexHome);if(i===void 0||!PP(i,n))throw X(`marketplace_invalid`,`The published official marketplace failed validation.`);return i}catch(e){throw e instanceof Z?e:X(`marketplace_unavailable`,`The official Codex marketplace fallback failed safely. Check network access and retry.`,e)}finally{await l(f,{recursive:!0,force:!0}).catch(()=>void 0)}}async function xP(e,t,n){let r=await e.run([`ls-remote`,fP,`HEAD`],{...n===void 0?{}:{signal:n},timeoutMs:t});if(r.exitCode!==0)throw X(`marketplace_unavailable`,`The official Codex marketplace remote HEAD could not be resolved. Check network access and retry.`,r.stderr);let i=r.stdout.trim().split(/\r?\n/u).map(e=>e.trim()).filter(e=>e.length>0),a=i.length===1?/^([0-9a-f]{40}|[0-9a-f]{64})\s+HEAD$/iu.exec(i[0]??``):null;if(a?.[1]===void 0)throw X(`marketplace_invalid`,`The official Codex marketplace remote HEAD response was malformed.`);return a[1].toLowerCase()}async function SP(e,t,n,r){let i=await e.run([`rev-parse`,`HEAD`],{timeoutMs:n,cwd:t,...r===void 0?{}:{signal:r}}),a=i.stdout.trim().toLowerCase();if(i.exitCode!==0||!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(a))throw X(`marketplace_invalid`,`The downloaded official marketplace checkout did not expose a valid HEAD.`,i.stderr);return a}async function CP(e,t){await wP(t,e),await n(e,{recursive:!0}),await wP(t,e)}async function wP(e,n){let r=ne(e),i=ne(n);for(;;){if((await t(i).catch(e=>{if(!RP(e))throw e}))?.isSymbolicLink())throw X(`marketplace_invalid`,`The official marketplace path cannot contain symlinks.`);if(i===r)return;let e=h(i);if(e===i||e!==r&&!TP(r,e))throw X(`marketplace_invalid`,`The official marketplace path escaped CODEX_HOME.`);i=e}}function TP(e,t){let n=te(e,t);return n.length>0&&n!==`..`&&!n.startsWith(`..${re}`)&&!g(n)}async function EP(e){let n=await t(e);if(n.isSymbolicLink())throw X(`marketplace_invalid`,`The official marketplace snapshot cannot contain symlinks.`);if(!n.isDirectory())throw X(`marketplace_invalid`,`The official marketplace snapshot is not a directory.`);let r=await o(e,{withFileTypes:!0});for(let n of r){let r=_(e,n.name),i=await t(r);if(i.isSymbolicLink())throw X(`marketplace_invalid`,`The official marketplace snapshot cannot contain symlinks.`);i.isDirectory()&&await EP(r)}}async function DP(e){return await OP(_(e,...pP),e)}async function OP(e,n){n!==void 0&&await wP(n,e);let r=await t(e).catch(e=>{if(!RP(e))throw X(`marketplace_invalid`,`The reserved openai-curated marketplace path could not be read safely.`,e)});if(r===void 0)return;if(r.isSymbolicLink()||!r.isDirectory())throw X(`marketplace_invalid`,`The reserved openai-curated marketplace path is not a real directory.`);n===void 0?await EP(e):await LP(n,e),n!==void 0&&await EP(e);let i=await s(e),o=[_(i,`.agents`,`plugins`,`marketplace.json`),_(i,`.codex-plugin`,`marketplace.json`),_(i,`marketplace.json`)],c,l;for(let e of o){let n=await t(e).catch(e=>{if(!RP(e))throw X(`marketplace_invalid`,`The official marketplace manifest could not be read safely.`,e)});if(n!==void 0){if(n.isSymbolicLink()||!n.isFile())throw X(`marketplace_invalid`,`The official marketplace manifest is not a regular file.`);if(await LP(i,e),c!==void 0)throw X(`marketplace_invalid`,`The reserved official marketplace contains more than one manifest.`);c=e;try{l=new TextDecoder(`utf-8`,{fatal:!0}).decode(await a(e))}catch(e){throw X(`marketplace_invalid`,`The official marketplace manifest is not valid UTF-8.`,e)}}}if(c===void 0||l===void 0)return;let u;try{u=JSON.parse(l)}catch(e){throw X(`marketplace_invalid`,`The official marketplace manifest is not valid JSON.`,e)}return kP(u,i,c)}function kP(e,t=`${pP.join(`/`)}`,n=`${t}/marketplace.json`){if(!J(e)||e.name!==`openai-curated`)throw X(`marketplace_invalid`,`The reserved official marketplace manifest has an unexpected name.`);AP(e);let r=e.plugins;if(!Array.isArray(r)||r.length===0)throw X(`marketplace_invalid`,`The official marketplace manifest has no plugin entries.`);let i=[],a=new Set;for(let e of r){if(!J(e)||typeof e.name!=`string`)throw X(`marketplace_invalid`,`The official marketplace contains a malformed plugin entry.`);let t=e.name;if(!/^[a-z][a-z0-9._-]{1,63}$/u.test(t)||a.has(t))throw X(`marketplace_invalid`,`The official marketplace contains a duplicate or invalid plugin name.`);let n=jP(e);if(!MP(n))throw X(`marketplace_invalid`,`The official marketplace source for ${t} is unsafe.`);a.add(t),i.push({name:t,source:n})}return{name:`openai-curated`,source:fP,rootPath:t,manifestPath:n,plugins:i}}function AP(e){for(let t of[`source`,`repository`,`repo`,`url`]){let n=e[t];if(n!==void 0&&(typeof n==`string`?n:J(n)&&typeof n.url==`string`?n.url:void 0)!==`https://github.com/openai/plugins.git`)throw X(`marketplace_invalid`,`The reserved official marketplace source is not the approved OpenAI repository.`)}}function jP(e){let t=e.source;if(typeof t==`string`)return t;if(J(t)&&typeof t.path==`string`)return t.path;if(typeof e.path==`string`)return e.path}function MP(e){if(e===void 0||e.length===0||g(e)||/^[A-Za-z]:[\\/]/u.test(e))return!1;let t=e.replaceAll(`\\`,`/`);return t.startsWith(`/`)||/^[A-Za-z][A-Za-z0-9+.-]*:/u.test(t)?!1:t.split(`/`).every(e=>e.length===0||e===`.`||e!==`..`)}function NP(e){let t=[],n=new Set;for(let r of e){let e=r.lastIndexOf(`@`);if(e<1||r.slice(e+1)!==`openai-curated`)continue;let i=r.slice(0,e);if(!/^[a-z][a-z0-9._-]{1,63}$/u.test(i))throw X(`marketplace_invalid`,`A selected official marketplace plugin id is invalid.`);n.has(i)||(n.add(i),t.push(i))}return t}function PP(e,t){return t.every(t=>{let n=e.plugins.find(e=>e.name===t);return n!==void 0&&n.source.replaceAll(`\\`,`/`).replace(/\/+$/u,``).split(`/`).at(-1)===t})}async function FP(e){let t=QN(e.environment),n;try{n=new rP({executablePath:e.executablePath,environment:t,...e.signal===void 0?{}:{signal:e.signal}});let r=new YN(n,{requestTimeoutMs:Math.min(e.timeoutMs??mP,1e4),...e.signal===void 0?{}:{signal:e.signal}});return await r.initialize(),async()=>{await r.close()}}catch(e){throw await n?.close().catch(()=>void 0),e}}function IP(e,t){if(e!==void 0&&(!Number.isSafeInteger(e)||e<1||e>3e5))throw X(`marketplace_invalid`,`The official marketplace timeout is invalid.`);if(t!==void 0&&(!Number.isSafeInteger(t)||t<0||t>6e4))throw X(`marketplace_invalid`,`The official marketplace poll interval is invalid.`)}async function LP(e,n){let r=await s(e),i=await s(n),a=te(r,i);if(a===``||a===`..`||a.startsWith(`..${re}`))throw X(`marketplace_invalid`,`The reserved official marketplace is outside CODEX_HOME.`);let o=ne(e),c=ne(n);for(;;){if((await t(c)).isSymbolicLink())throw X(`marketplace_invalid`,`The reserved official marketplace path cannot contain symlinks.`);if(c===o)break;let e=h(c);if(e===c)throw X(`marketplace_invalid`,`The reserved official marketplace path is outside CODEX_HOME.`);c=e}}function RP(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}async function zP(e){await new Promise(t=>setTimeout(t,e))}function X(e,t,n){return new Z(e,t,n instanceof Error?{cause:nP(n.message)}:{})}K({id:hP,selected:z(!0)});const BP=K({pluginId:vP,installed:H,enabled:H,name:G(U(V,kD)),marketplaceName:G(U(V,kD)),version:G(U(V,kD))},uO({key:V,value:jD})),VP=K({installed:W(BP),available:W(BP)});function HP(e){return pM(VP,e)?sM(fM(VP,e,`live official plugin list`)):oM(dM(`live official plugin list`,e))}var Z=class extends Error{code;details;constructor(e,t,n={}){super(t),this.name=`OfficialPluginAdapterError`,this.code=e,this.details=n}};function UP(e){let t=e.runner??GP(e.executable,{environment:e.environment??QN(),...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.stdoutLimit===void 0?{}:{stdoutLimit:e.stdoutLimit},...e.stderrLimit===void 0?{}:{stderrLimit:e.stderrLimit}}),n=async()=>{let e=await t.run([`plugin`,`list`,`--json`]);if(e.exitCode!==0)throw WP(`list`,e);let n;try{n=JSON.parse(e.stdout)}catch{throw new Z(`command_failed`,`Codex returned invalid plugin data.`)}let r=HP(n);if(!r.ok)throw new Z(`command_failed`,`Codex returned an invalid official plugin list.`);return r.value};return{list:n,ensureOfficialMarketplace:async t=>{if(e.codexHome===void 0)throw new Z(`marketplace_unavailable`,`Codex home is unavailable; the official marketplace cannot be bootstrapped safely.`);await yP({codexHome:e.codexHome,executablePath:e.executable,selectedPluginIds:t,...e.environment===void 0?{}:{environment:e.environment},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.officialMarketplaceFallback===void 0?{}:{gitFallback:e.officialMarketplaceFallback}})},addMarketplace:async(e,n)=>{let r=fM(vP,e,`plugin marketplace source`);if(r===`openai-curated`||r===`https://github.com/openai/plugins.git`)throw new Z(`marketplace_invalid`,`The reserved openai-curated marketplace must be populated by Codex runtime startup; it cannot be added manually.`);let i=await t.run([`plugin`,`marketplace`,`add`,r],n===void 0?void 0:{signal:n});if(i.exitCode!==0&&!/already (?:exists|added)/iu.test(i.stderr))throw WP(`marketplace add`,i,r)},add:async(e,r)=>{let i=fM(vP,e,`official plugin id`),a=await t.run([`plugin`,`add`,i,`--json`],r===void 0?void 0:{signal:r});if(a.exitCode!==0)throw WP(`add`,a,i);let o=await n(),s=[...o.installed,...o.available].filter(e=>e.pluginId===i),c=s.find(e=>e.installed)??s[0];if(!c)throw new Z(`readback_mismatch`,`Codex did not report ${i} after installation.`,{plugin_id:i});if(!c.installed)throw new Z(`plugin_missing`,`Codex reported ${i} as unavailable after installation.`,{plugin_id:i});if(!c.enabled)throw new Z(`plugin_disabled`,`Codex installed ${i} but it is disabled; enable it in Codex and retry.`,{plugin_id:i})},remove:async(e,r)=>{let i=fM(vP,e,`official plugin id`),a=await t.run([`plugin`,`remove`,i,`--json`],r===void 0?void 0:{signal:r});if(a.exitCode!==0&&!/not (?:installed|found)|missing/iu.test(a.stderr))throw WP(`remove`,a,i);let o=await n();if([...o.installed,...o.available].find(e=>e.pluginId===i&&e.installed)!==void 0)throw new Z(`readback_mismatch`,`Codex still reports ${i} after removal.`,{plugin_id:i})}}}function WP(e,t,n){let r=nP(t.stderr).trim().slice(0,512),i=r.length>0?`: ${r}`:``;return new Z(`command_failed`,`Codex plugin ${e} failed${n===void 0?``:` for ${n}`}${i}`,{exit_code:t.exitCode})}function GP(e,t){let n=t.timeoutMs??3e4,r=t.stdoutLimit??131072,i=t.stderrLimit??16384;return{run:(a,o)=>KP(e,a,{...t.environment===void 0?{}:{environment:t.environment},timeoutMs:o?.timeoutMs??n,stdoutLimit:r,stderrLimit:i,...o?.cwd===void 0?{}:{cwd:o.cwd},...o?.signal===void 0?{}:{signal:o.signal}})}}async function KP(e,t,n){if(n.signal?.aborted)throw new Z(`cancelled`,`The Codex plugin command was cancelled.`);let r=ae(e,[...t],{env:n.environment===void 0?void 0:{...n.environment},...n.cwd===void 0?{}:{cwd:n.cwd},stdio:[`ignore`,`pipe`,`pipe`],windowsHide:!0}),i=qP(r.stdout,n.stdoutLimit),a=qP(r.stderr,n.stderrLimit),o=new Promise((e,t)=>{r.once(`error`,t),r.once(`close`,t=>e(t??-1))}),s,c,l=new Promise((e,t)=>{c=()=>{try{r.kill()}catch{}t(new Z(`cancelled`,`The Codex plugin command was cancelled.`))},n.signal?.addEventListener(`abort`,c,{once:!0})}),u=new Promise((e,t)=>{s=setTimeout(()=>{try{r.kill()}catch{}t(new Z(`timeout`,`The Codex plugin command timed out.`))},n.timeoutMs)});try{let[e,t,n]=await Promise.race([Promise.all([i,a,o]),l,u]);return{stdout:e,stderr:t,exitCode:n}}catch(e){try{r.kill()}catch{}throw e instanceof Z?e:new Z(`command_failed`,`The Codex plugin command failed.`)}finally{s!==void 0&&clearTimeout(s),c!==void 0&&n.signal?.removeEventListener(`abort`,c)}}function qP(e,t){return e===null?Promise.reject(new Z(`command_failed`,`Codex plugin command output is unavailable.`)):new Promise((n,r)=>{let i=[],a=0;e.on(`data`,e=>{let n=typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:void 0;if(n===void 0){r(new Z(`command_failed`,`Codex plugin output was invalid.`));return}if(a+=n.byteLength,a>t){r(new Z(`output_limit`,`Codex plugin output exceeded its limit.`));return}i.push(n)}),e.once(`end`,()=>{let e=new Uint8Array(a),t=0;for(let n of i)e.set(n,t),t+=n.byteLength;try{n(new TextDecoder(`utf-8`,{fatal:!0}).decode(e))}catch(e){r(e)}}),e.once(`error`,e=>r(e))})}function JP(e){if(!YP(e))throw Error(`The value is not JSON serializable.`);return sj(e),e}function YP(e,t=new Set){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;t.add(e);try{return Array.isArray(e)?e.every(e=>YP(e,t)):Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>YP(e,t))}finally{t.delete(e)}}const XP=B(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&YP(e));B(YP);const ZP=V.pipe(AO(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/u)),QP=V.pipe(AO(/^[0-9a-f]{64}$/u)),$P=V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),eF=V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u)),tF=V.pipe(q(e=>!Number.isNaN(Date.parse(e)))),nF=K({path:V.pipe(AO(/^[A-Za-z0-9][A-Za-z0-9._/-]{0,255}$/u)),digest:QP}),rF=K({computer_use:H,work:H,frontend:H,security:H,coding:z(!0)}),iF=K({computer_use:G(H),work:G(H),frontend:G(H),security:G(H)}),aF=K({plan:G(zA),tier:G(VA),optional:G(iF),officialPlugins:G(W(eF))}),oF=K({selected:H,status:z(`disabled`,`pending`,`healthy`,`missing`,`provider_disabled`,`uncertain`,`unavailable`),plugin_ids:W(eF),reason:G(V)}),sF=K({computer_use:oF,work:oF,frontend:oF,security:oF}),cF=K({presence:z(`absent`,`present`),digest:QP,safe_value:G(U(K({kind:z(`boolean`),value:H}),K({kind:z(`marketplace`),source_type:z(`git`),source:z(`https://github.com/davidbasilefilho/holycodex.git`)})))}),lF=K({plugin_id:z(`holycodex@holycodex`),before:K({preference:cF,marketplace:cF}),after:K({preference:cF,marketplace:cF})}),uF=K({presence:z(`absent`,`present`),digest:QP,safe_value:G(K({kind:z(`boolean`),value:H}))}),dF=K({plugin_id:eF,before:uF,after:uF}),fF={owner:z(`holycodex`),schema_epoch:z(le),install_id:$P,version:ZP,digest:QP,plan:zA,tier:VA,optional_selections:rF,explicit_optional_selections:iF,official_plugins:G(W(eF)),capability_state:G(sF),managed_artifacts:W(nF),installed_at:tF,status:G(z(`active`)),step:G(z(`active`)),managed_config:G(jM),plugin_snapshot:G(W(K({plugin_id:eF,status:z(`installed`,`available`,`missing`,`disabled`,`uncertain`,`unknown`)}))),plugin_config:G(lF),provider_config:G(W(dF)),owned_plugins:G(W(eF))},pF=K(fF),mF=K({...fF,plan:U(zA,z(`Go`))}),hF=z(`preparing`,`conflicted`),gF=z(`validated`,`plugins_snapshotted`,`roles_prepared`,`plugins_installed`,`config_published`,`verified`,`conflicted`),_F=K({...pF.fields,status:hF,step:gF});function vF(e,t){let n=yA(e,t);return On(n)?n.right:void 0}function yF(e){return vF(XP,e)!==void 0}const bF=le;function xF(e={},t=process.env){let n=se(),r=CF(e.paths?.codexHome??t.CODEX_HOME??_(n,`.codex`),`CODEX_HOME`),i=_(r,`holycodex`);return{codexHome:r,stateRoot:i,activeRecord:_(i,`active.json`),preparingRecord:_(i,`preparing.json`),conflictedRecord:_(i,`conflicted.json`),roleRoot:_(i,`agents`),configFile:_(r,`config.toml`)}}var SF=class extends Error{code;constructor(e,t){super(t),this.name=`PathBoundaryError`,this.code=e}};function CF(e,t,n=process.platform===`win32`?`win32`:`posix`){if(typeof e!=`string`||wF(e))throw new SF(`invalid_path`,`${t} contains invalid characters.`);let r=n===`win32`?ie:ee,i=kF(e,n);if(typeof i!=`string`||i.length===0||!r.isAbsolute(i))throw new SF(`invalid_path`,`${t} must be an absolute path.`);let a=r.normalize(i);if(a.split(n===`win32`?`\\`:re).filter(e=>e.length>0).length===0||a===r.dirname(a))throw new SF(`broad_path`,`${t} is too broad.`);if(i.split(/[\\/]/u).some(e=>e===`..`))throw new SF(`invalid_path`,`${t} cannot contain traversal.`);return r.resolve(a)}function wF(e){for(let t of e){let e=t.codePointAt(0)??0;if(e<=31||e===127)return!0}return!1}async function TF(e){CF(e,`owned path`),await EF(e),await n(e,{recursive:!0}),await EF(e)}async function EF(e){let n=ne(e);for(;;){try{if((await t(n)).isSymbolicLink())throw new SF(`path_symlink`,`A managed path cannot contain a symlink.`)}catch(e){if(e instanceof SF||!AF(e,`ENOENT`))throw e}let e=h(n);if(e===n)break;n=e}}async function DF(e){await EF(e)}function OF(e,t,n=process.platform===`win32`?`win32`:`posix`){let r=n===`win32`?ie:ee,i=r.resolve(kF(e,n)),a=r.resolve(kF(t,n)),o=r.relative(i,a);return o.length>0&&!o.startsWith(`..${n===`win32`?`\\`:re}`)&&o!==`..`&&!r.isAbsolute(o)}function kF(e,t){return t===`win32`&&/^\/[A-Za-z](?:\/|$)/u.test(e)?`${e[1]?.toUpperCase()??``}:${e.slice(2).replaceAll(`/`,`\\`)}`:e}function AF(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}const jF=new Set([`EBADF`,`EINVAL`,`ENOSYS`,`ENOTSUP`,`EISDIR`]);async function MF(e){let t;try{t=await i(e,`r`),await t.sync()}catch(e){if(!BF(e))throw e}finally{await t?.close().catch(()=>void 0)}}async function NF(e){await MF(e).catch(e=>{if(!BF(e))throw e})}async function PF(e,t){await FF(e,`${sj(t)}\n`)}async function FF(e,t){let n=h(e);await TF(n),await EF(e);let r=`${e}.tmp-${process.pid}-${crypto.randomUUID()}`;try{await p(r,t,{encoding:`utf8`,mode:384}),await MF(r),await c(r,e),await NF(n)}catch(e){throw await f(r).catch(()=>void 0),e}}async function IF(e,n){let r=await t(e);if(!r.isFile()||r.isSymbolicLink())throw new zF(`state_corrupt`,`A persisted file is not a regular file.`);let i;try{i=JSON.parse(await a(e,`utf8`))}catch(e){throw new zF(`state_corrupt`,`A persisted file is not valid JSON.`,e)}let o=vF(n,i);if(o===void 0)throw new zF(`state_corrupt`,`A persisted file failed schema validation.`);return o}async function LF(e){try{let n=await t(e);if(!n.isFile()||n.isSymbolicLink())throw new zF(`state_corrupt`,`A persisted file is not a regular file.`);return await a(e,`utf8`)}catch(e){if(AF(e,`ENOENT`))return;throw e}}async function RF(e,t){try{return await IF(e,t)}catch(e){if(AF(e,`ENOENT`))return;throw e}}var zF=class extends Error{code;causeValue;constructor(e,t,n){super(t),this.name=`StorageError`,this.code=e,this.causeValue=n}};function BF(e){return typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?jF.has(e.code)||process.platform===`win32`&&e.code===`EPERM`:!1}const VF=V.pipe(AO(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-dev\.[1-9]\d*\.[1-9]\d*)?$/u)),HF=B(e=>yF(e)&&e.name===`holycodex`&&vF(VF,e.version)!==void 0),UF=ne(h(oe(import.meta.url)),`../package.json`);async function WF(e=UF){let t=JSON.parse(await a(e,`utf8`)),n=vF(HF,t);if(n===void 0)throw new YF(`manifest_invalid`,`The public package manifest is invalid.`);return n}async function GF(e=UF){return(await WF(e)).version}async function KF(e=UF){return(await GF(e)).split(`-`,1)[0]??``}async function qF(e,t,n=UF){let r=await WF(n),i=await KF(n),a=JF(e,i);return t||await PF(n,{...r,version:a}),{previous:i,next:a}}function JF(e,t){if(e!==`patch`&&e!==`minor`){if(vF(ZP,e)===void 0)throw new YF(`version_invalid`,`The version target is invalid.`);return e}let n=t.split(`.`),r=Number(n[1]),i=Number(n[2]);return e===`minor`?`0.${r+1}.0`:`0.${r}.${i+1}`}var YF=class extends Error{code;constructor(e,t){super(t),this.name=`ManifestError`,this.code=e}};function XF(e,t=`standard`){let n=Bj(e);return n.ok?n.value.routes.map(e=>{let n={role:e.role,task:e.task};return{name:nj(n),rolePolicy:HA.find(t=>t.role===e.role),description:ij(n),taskInstruction:rj(n),model:`gpt-5.6-luna`,effort:e.effort,serviceTier:t===`standard`?`default`:`fast`}}):[]}function ZF(e,t=`standard`){let n=Bj(e);if(!n.ok)throw Error(`Unknown plan.`);return{name:`root`,description:`Root-directed HolyCodex control agent.`,model:n.value.root.model===`Terra`?`gpt-5.6-terra`:`gpt-5.6-sol`,effort:n.value.root.effort,serviceTier:t===`fast-all`?`fast`:`default`}}function QF(){return[`You are the HolyCodex Root orchestrator.`,`Own user intent, scope, architecture, product and policy choices, material risk, integration, external state, and final readiness.`,`Delegate every substantive non-VCS operation to one named native Explorer, Librarian, Worker, or Reviewer with an exact bounded scope and observable completion criterion.`,`Before delegation, ensure writing-for-agents is fully loaded and applied in the active context. For any applicable skill, fully load it on first use in the active context, reuse it while its complete instructions remain available, and reload only after compaction, a new context, or an incomplete or unavailable load.`,`Inspect and integrate returned evidence; do not blindly accept conclusions. Keep Git/VCS inspection and mutation Root-only.`,`Use request_user_input whenever user information or approval is required and available; do not replace it with a prose question.`,`Keep changes minimal, mergeable, and within the assigned seam. Preserve unrelated user state and fail closed on ambiguity or conflict.`].join(`
82
- `)}async function $F(e,t,n=[],r=`standard`){let i=_(e,`holycodex`,`agents`),a=[],o=nI(t,r).map(e=>({path:_(i,`${e.role}.toml`),contents:rI(e)})),s=new Map(n.map(t=>[_(e,t.path),t])),c=new Map;for(let e of o){let t=await uI(e.path);c.set(e.path,t);let n=s.get(e.path);if(t!==void 0&&n===void 0&&t!==e.contents)throw Error(`A pre-existing HolyCodex role file is not owned by this installation: ${e.path}`)}let l=[];for(let t of o){let n=c.get(t.path),r=s.get(t.path);if(n!==void 0&&r!==void 0&&await fI(n)!==r.digest&&n!==t.contents){a.push(t.path),l.push({path:te(e,t.path).replaceAll(`\\`,`/`),digest:r.digest});continue}(n===void 0||n!==t.contents)&&await FF(t.path,t.contents),l.push({path:te(e,t.path).replaceAll(`\\`,`/`),digest:await fI(t.contents)})}let u=_(e,`agents`,`root.toml`);await lI(u)===`preserved`&&a.push(u);for(let t of n){let n=_(e,t.path);if(!o.some(e=>e.path===n)){if(!cI(e,n,t.path)){a.push(n);continue}await dI(n,t.digest)===`preserved`&&a.push(n)}}for(let t of n){let n=_(e,t.path);a.includes(n)&&!l.some(t=>_(e,t.path)===n)&&l.push(t)}return{managed_artifacts:l,preserved:a}}async function eI(e,n){let r=[],i=[],o=_(e,`agents`),s=_(e,`holycodex`,`agents`);for(let c of n){let n=_(e,c.path);if(!OF(e,n)||!OF(o,n)&&!OF(s,n)&&n!==_(e,`config.toml`)){i.push(n);continue}try{await EF(n);let e=await t(n);if(e.isSymbolicLink()||!e.isFile()){i.push(n);continue}if(await fI(await a(n))!==c.digest){i.push(n);continue}await l(n,{force:!1}),r.push(n)}catch(e){AF(e,`ENOENT`)?r.push(n):i.push(n)}}let c=_(e,`agents`,`root.toml`),u=await lI(c);return u===`removed`&&r.push(c),u===`preserved`&&i.push(c),{removed:r,preserved:i}}function tI(e){let t=e.rolePolicy,n=[`${t.role} shared policy: ${t.authority}`,t.evidence,t.completion,e.taskInstruction].join(`
83
- `);return[`name = ${JSON.stringify(e.name)}`,`description = ${JSON.stringify(e.description)}`,`model = ${JSON.stringify(e.model)}`,`model_reasoning_effort = ${JSON.stringify(e.effort)}`,`service_tier = ${JSON.stringify(e.serviceTier)}`,`model_reasoning_summary = "none"`,`model_verbosity = "low"`,`tool_output_token_limit = 12000`,`developer_instructions = ${JSON.stringify(`${n}\nExecute only the assigned scope, escalate material decisions to Root, and return evidence/results to Root.`)}`,``,`[agents]`,`enabled = false`,`interrupt_message = false`,``,`[features]`,`multi_agent_v2 = false`,`multi_agent = false`,``].join(`
84
- `)}function nI(e,t){let n=XF(e,t);return[`explorer`,`librarian`,`worker`,`reviewer`].map(e=>{let t=n.filter(t=>t.name.toLowerCase().startsWith(`${e}.`)),r=t[0];if(!r)throw Error(`Plan does not define the ${e} role.`);let i=t.reduce((e,t)=>sI(e,t.effort),r.effort),a=t.map(e=>e.description).join(` `),o=r.rolePolicy;return{role:e,description:`${o.role}: ${a}`,model:r.model,effort:i,serviceTier:r.serviceTier,instructions:[`${o.role} shared policy: ${o.authority}`,o.evidence,o.completion,...t.map(e=>e.taskInstruction)].join(`
85
- `)}})}function rI(e){return[`name = ${JSON.stringify(e.role)}`,`description = ${JSON.stringify(e.description)}`,`model = ${JSON.stringify(e.model)}`,`model_reasoning_effort = ${JSON.stringify(e.effort)}`,`service_tier = ${JSON.stringify(e.serviceTier)}`,`model_reasoning_summary = "none"`,`model_verbosity = "low"`,`tool_output_token_limit = 12000`,`developer_instructions = ${JSON.stringify(`${e.instructions}\nExecute only the assigned scope, escalate material decisions to Root, and return evidence/results to Root.`)}`,``,`[agents]`,`enabled = false`,`interrupt_message = false`,``,`[features]`,`multi_agent_v2 = false`,`multi_agent = false`,``].join(`
86
- `)}function iI(e){return[`name = ${JSON.stringify(e.name)}`,`description = ${JSON.stringify(e.description)}`,`model = ${JSON.stringify(e.model)}`,`model_reasoning_effort = ${JSON.stringify(e.effort)}`,`service_tier = ${JSON.stringify(e.serviceTier)}`,`model_verbosity = "low"`,``].join(`
87
- `)}const aI=new Set([`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`].flatMap(e=>[`standard`,`fast`,`fast-all`].map(t=>iI(ZF(e,t)))));function oI(e){return aI.has(e)}function sI(e,t){let n={low:0,medium:1,high:2,xhigh:3,max:4};return(n[t]??0)>(n[e]??0)?t:e}function cI(e,t,n){return n===`agents/root.toml`||OF(_(e,`agents`),t)&&/^(?:Explorer|Librarian|Worker|Reviewer)\.(?:lookup|trace|research|mechanical|implementation|integration|operations|plan|code|artifact)\.toml$/u.test(n.slice(7))}async function lI(e){try{await EF(e);let n=await t(e);return!n.isFile()||n.isSymbolicLink()||!oI(await a(e,`utf8`))?`preserved`:(await l(e,{force:!1}),`removed`)}catch(e){if(AF(e,`ENOENT`))return`absent`;throw e}}async function uI(e){try{await EF(e);let n=await t(e);if(n.isSymbolicLink()||!n.isFile())throw Error(`Invalid managed path: ${e}`);return new TextDecoder(`utf-8`,{fatal:!0}).decode(await a(e))}catch(e){if(AF(e,`ENOENT`))return;throw e}}async function dI(e,n){try{await EF(e);let r=await t(e);return r.isSymbolicLink()||!r.isFile()?`preserved`:await fI(await a(e))===n?(await l(e,{force:!1}),`removed`):`preserved`}catch(e){if(AF(e,`ENOENT`))return`removed`;throw e}}async function fI(e){let t=typeof e==`string`?new TextEncoder().encode(e):e,n=await crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}var pI=class e{adapter;constructor(e){if(`run`in e){let t=UP({executable:`codex`,runner:e});this.adapter=t}else this.adapter=e}static async discover(t=process.env){let n=UP({executable:(await sP({environment:t})).path,environment:$N(t),...t.CODEX_HOME===void 0?{}:{codexHome:t.CODEX_HOME}});return new e(n)}async list(){try{return await this.adapter.list()}catch(e){throw mI(`list`,e)}}async add(e){try{await this.adapter.add(e)}catch(t){throw mI(`add`,t,e)}}async ensureOfficialMarketplace(e){if(this.adapter.ensureOfficialMarketplace!==void 0)try{await this.adapter.ensureOfficialMarketplace(e)}catch(e){throw mI(`bootstrap`,e)}}async remove(e){try{await this.adapter.remove(e)}catch(t){throw mI(`remove`,t,e)}}async addMarketplace(e){try{await this.adapter.addMarketplace(e)}catch(t){throw mI(`add`,t,e)}}async status(e){let t=await this.list(),n=new Map;for(let e of[...t.installed,...t.available])(!n.has(e.pluginId)||e.installed)&&n.set(e.pluginId,e);return Object.fromEntries(e.map(e=>{let t=n.get(e);return[e,t===void 0?`missing`:t.installed&&t.enabled?`installed`:t.installed?`disabled`:`missing`]}))}};function mI(e,t,n){if(t instanceof hI)return t;let r=(t instanceof Z?t:void 0)?.code;return new hI(r===`timeout`||r===`output_limit`||r===`cancelled`||r===`readback_mismatch`||r===`plugin_disabled`||r===`plugin_missing`||r===`marketplace_invalid`||r===`marketplace_timeout`||r===`marketplace_unavailable`?r:r===`command_failed`?e===`list`?`list_failed`:e===`remove`?`remove_failed`:e===`bootstrap`?`marketplace_unavailable`:`add_failed`:e===`list`?`list_failed`:e===`bootstrap`?`marketplace_unavailable`:`add_failed`,t instanceof Error?t.message:e===`list`?`Codex could not list official plugins.`:e===`remove`?`Codex could not remove ${n??`the selected official plugin`}.`:e===`bootstrap`?`Codex could not initialize the official marketplace.`:`Codex could not add ${n??`the selected official plugin`}.`,t,n===void 0?{}:{plugin_id:n})}var hI=class extends Error{code;causeValue;details;constructor(e,t,n,r={}){super(t),this.name=`OfficialPluginManagerError`,this.code=e,this.causeValue=n,this.details=r}};function gI(e){let t={},n=[];for(let r of e.split(/\r?\n/u)){let e=TI(r).trim();if(e.length===0)continue;if(e.startsWith(`[[`)||e.endsWith(`]]`))throw Error(`Array-of-tables are not supported by the validated fallback.`);if(e.startsWith(`[`)&&e.endsWith(`]`)){n=bI(e.slice(1,-1).trim()),SI(t,n);continue}let i=wI(e);if(i<1)throw Error(`TOML assignment is invalid.`);let a=bI(e.slice(0,i).trim()),o=yI(e.slice(i+1).trim());xI(t,[...n,...a],o)}return t}function _I(e){let t=[];return vI(e,[],t),t.join(`
88
- `)}function vI(e,t,n){let r=[],i=[];for(let[t,n]of Object.entries(e))EI(n)?i.push([t,n]):r.push([t,n]);t.length>0&&(n.length>0&&n.push(``),n.push(`[${t.map(DI).join(`.`)}]`));for(let[e,t]of r)n.push(`${DI(e)} = ${OI(t)}`);for(let[e,r]of i)vI(r,[...t,e],n)}function yI(e){if(e.length===0)throw Error(`TOML value is missing.`);if(e.startsWith(`"`)){let t=JSON.parse(e);if(typeof t!=`string`)throw Error(`TOML string is invalid.`);return t}if(e.startsWith(`'`)){if(!e.endsWith(`'`)||e.length<2)throw Error(`TOML string is invalid.`);return e.slice(1,-1)}if(e===`true`)return!0;if(e===`false`)return!1;if(e.startsWith(`[`)){if(!e.endsWith(`]`))throw Error(`TOML array is invalid.`);let t=e.slice(1,-1).trim();return t.length===0?[]:CI(t,`,`).map(yI)}if(e.startsWith(`{`)){if(!e.endsWith(`}`))throw Error(`TOML inline table is invalid.`);let t=e.slice(1,-1).trim(),n={};if(t.length===0)return n;for(let e of CI(t,`,`)){let t=wI(e);if(t<1)throw Error(`TOML inline table entry is invalid.`);xI(n,bI(e.slice(0,t).trim()),yI(e.slice(t+1).trim()))}return n}if(/^[+-]?(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(e)){let t=Number(e);if(Number.isFinite(t))return t}throw Error(`TOML value is unsupported.`)}function bI(e){let t=CI(e,`.`).map(e=>e.trim());if(t.length===0||t.some(e=>!/^(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(e)||e===`__proto__`||e===`constructor`||e===`prototype`))throw Error(`TOML key is invalid.`);return t.map(e=>e.startsWith(`"`)||e.startsWith(`'`)?yI(e):e)}function xI(e,t,n){if(t.length===0)throw Error(`TOML key is missing.`);let r=e;for(let e of t.slice(0,-1)){let t=r[e];if(t===void 0){let t={};r[e]=t,r=t}else if(EI(t))r=t;else throw Error(`TOML key conflicts with a scalar.`)}let i=t.at(-1);if(Object.prototype.hasOwnProperty.call(r,i))throw Error(`TOML key is duplicated.`);r[i]=n}function SI(e,t){let n=e;for(let e of t){let t=n[e];if(t===void 0){let t={};n[e]=t,n=t}else if(EI(t))n=t;else throw Error(`TOML table conflicts with a scalar.`)}}function CI(e,t){let n=[],r=0,i=0,a,o=!1;for(let s=0;s<e.length;s+=1){let c=e[s];if(a!==void 0){a===`"`&&o?o=!1:a===`"`&&c===`\\`?o=!0:c===a&&(a=void 0);continue}c===`"`||c===`'`?a=c:c===`[`||c===`{`?i+=1:c===`]`||c===`}`?--i:c===t&&i===0&&(n.push(e.slice(r,s)),r=s+1)}if(a!==void 0||i!==0)throw Error(`TOML value is unbalanced.`);return n.push(e.slice(r)),n}function wI(e){let t,n=!1,r=0;for(let i=0;i<e.length;i+=1){let a=e[i];if(t!==void 0)t===`"`&&n?n=!1:t===`"`&&a===`\\`?n=!0:a===t&&(t=void 0);else if(a===`"`||a===`'`)t=a;else if(a===`[`||a===`{`)r+=1;else if(a===`]`||a===`}`)--r;else if(a===`=`&&r===0)return i}return-1}function TI(e){let t,n=!1;for(let r=0;r<e.length;r+=1){let i=e[r];if(t!==void 0)t===`"`&&n?n=!1:t===`"`&&i===`\\`?n=!0:i===t&&(t=void 0);else if(i===`"`||i===`'`)t=i;else if(i===`#`)return e.slice(0,r)}return e}function EI(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function DI(e){return/^[A-Za-z0-9_-]+$/u.test(e)?e:JSON.stringify(e)}function OI(e){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`boolean`||typeof e==`number`){if(typeof e==`number`&&!Number.isFinite(e))throw Error(`TOML number is invalid.`);return String(e)}if(Array.isArray(e))return`[${e.map(OI).join(`, `)}]`;throw Error(e===null?`TOML null is not serializable.`:`TOML nested values must be tables.`)}const kI=`holycodex@holycodex`,AI=`https://github.com/davidbasilefilho/holycodex.git`,jI=`holycodex@holycodex`,MI=`holycodex`;async function NI(e={},t={},n=process.env){if(vF(aF,e)===void 0)throw new Q(`install_failed`,`The installation options are invalid.`);let r=xF(t,n);if(await TF(r.stateRoot),await RF(r.preparingRecord,_F)!==void 0)throw new Q(`state_corrupt`,`A previous HolyCodex operation is still preparing and must converge before reinstalling.`,void 0,{path:r.preparingRecord});if(await RF(r.conflictedRecord,_F)!==void 0)throw new Q(`state_corrupt`,`A previous HolyCodex operation is conflicted and must converge before reinstalling.`,void 0,{path:r.conflictedRecord});let i=await PI(r);if(i!==void 0&&!await _L(i))throw new Q(`state_corrupt`,`The existing HolyCodex configuration has changed and cannot be replaced.`,void 0,{path:r.activeRecord});let a=fL(e.plan,i?.plan),o=pL(e.tier,i?.tier),s=mL(e.optional,i?.optional_selections),c=aL(i?.explicit_optional_selections,e.optional),l=e.officialPlugins??sL(i),u=DA(FI(s),l),d;try{d=t.officialPluginManager??await pI.discover({...n,CODEX_HOME:r.codexHome})}catch(e){throw new Q(`capability_denied`,`Native Codex plugin installation is unavailable.`,e,{recovery:`Install or expose Codex, then retry.`})}if(!d.addMarketplace||!d.add||!d.list)throw new Q(`install_failed`,`Native Codex plugin installation and verification are unavailable.`);if(d.ensureOfficialMarketplace!==void 0)try{await d.ensureOfficialMarketplace(u)}catch(e){throw new Q(`capability_denied`,`The selected official Codex provider marketplace is unavailable: ${yL(e)}`,e,{recovery:`Check Codex network and marketplace policy, then retry.`})}let f=i?.install_id??crypto.randomUUID().replaceAll(`-`,``),p=await KF(),m=(t.now?.()??new Date).toISOString(),h=await LF(r.configFile),g=II(h),_=i?.plugin_config?.before??await RI(g),ee=[...new Set([...u,...(i?.provider_config??[]).map(e=>e.plugin_id),...i?.owned_plugins??[]])].filter(e=>e!==kI),te=(await zI(g,ee)).map(e=>{let t=i?.provider_config?.find(t=>t.plugin_id===e.plugin_id);return t===void 0?e:{plugin_id:e.plugin_id,before:t.before,after:t.before}}),ne=ZI(g,i),re=i?.managed_config??HM({schema:`state-0.16`,installId:f});QI(ne,re);let ie=YI(a,o),ae=await XM(ne,re,ie,{schema:le,installId:f});if(ae.driftedKeys.length>0)throw new Q(`state_corrupt`,`HolyCodex-owned Codex settings changed and cannot be replaced safely.`,void 0,{keys:ae.driftedKeys.join(`,`)});let oe;try{oe=await $I({list:()=>d.list()},[...new Set([kI,...u,...i?.owned_plugins??[]])])}catch(e){throw new Q(`capability_denied`,`Native Codex plugin state could not be read safely.`,e)}let se={owner:`holycodex`,schema_epoch:le,install_id:f,version:p,digest:i?.digest??`0`.repeat(64),plan:a,tier:o,optional_selections:s,explicit_optional_selections:c,official_plugins:u,capability_state:hL(s),managed_artifacts:i?.managed_artifacts??[],installed_at:m,status:`preparing`,step:`validated`,managed_config:ae.state,plugin_snapshot:oe,plugin_config:{plugin_id:kI,before:_,after:_},provider_config:te,owned_plugins:[...new Set(i?.owned_plugins??[])]};await eL(r.preparingRecord,se);let ce,ue=!1,de=new Set,fe=new Set(i?.owned_plugins??[]),pe=new Set,me=se,he=!1,ge=!1,v=h,y=ae.state;try{await TF(r.roleRoot),ce=await $F(r.codexHome,a,i?.managed_artifacts,o),me={...se,step:`roles_prepared`,managed_artifacts:ce.managed_artifacts},await eL(r.preparingRecord,me),he=!0,await d.addMarketplace(`davidbasilefilho/holycodex`),await cL({list:()=>d.list(),add:e=>d.add(e)},[kI,...u],(e,t)=>{t===`new`?(de.add(e),fe.add(e),me={...me,owned_plugins:[...fe]}):pe.add(e)}),me={...me,step:`plugins_installed`},await eL(r.preparingRecord,me);let e=await LF(r.configFile);v=e;let t=II(e),n=await RI(t),l=(await zI(t,ee)).map(e=>({plugin_id:e.plugin_id,before:te.find(t=>t.plugin_id===e.plugin_id)?.before??e.before,after:e.before}));await XI(t,ne,re,ie);let h=await XM(t,re,ie,{schema:le,installId:f});if(h.driftedKeys.length>0)throw new Q(`state_corrupt`,`HolyCodex-owned Codex settings changed during native plugin setup.`,void 0,{keys:h.driftedKeys.join(`,`)});ge=!0,y=h.state,me={...me,managed_config:y,plugin_config:{plugin_id:kI,before:_,after:n},provider_config:l},await FF(r.configFile,LI(h.document)),ue=!0,me={...me,step:`config_published`},await eL(r.preparingRecord,me),await rL(r,a,o,y,ce.preserved);let g=hL(s),ae=await gL({owner:`holycodex`,install_id:f,version:p,plan:a,tier:o,optional_selections:s,explicit_optional_selections:c,official_plugins:u,capability_state:g,managed_artifacts:ce.managed_artifacts,managed_config:y,plugin_config:{plugin_id:kI,before:_,after:n},provider_config:l,plugin_snapshot:oe,owned_plugins:[...fe]}),_e={owner:`holycodex`,schema_epoch:le,install_id:f,version:p,digest:ae,plan:a,tier:o,optional_selections:s,explicit_optional_selections:c,official_plugins:u,capability_state:g,managed_artifacts:ce.managed_artifacts,installed_at:m,status:`active`,step:`active`,managed_config:y,plugin_snapshot:oe,plugin_config:{plugin_id:kI,before:_,after:n},provider_config:l,owned_plugins:[...fe]};if(vF(pF,_e)===void 0)throw new Q(`state_corrupt`,`The HolyCodex configuration is invalid.`);return await PF(r.activeRecord,JP(_e)),await tL(r.preparingRecord),await tL(r.conflictedRecord),{record:_e,optional_plugins:u,preserved:ce.preserved,warnings:ce.preserved.length===0?[]:[`modified managed files were preserved`]}}catch(e){let t=[];if(ue)try{await nL(r.configFile,v)}catch{t.push(`config`)}if(he&&!ge&&t.push(`config`),ce!==void 0){let e=new Set((i?.managed_artifacts??[]).map(e=>e.path));try{await eI(r.codexHome,ce.managed_artifacts.filter(t=>!e.has(t.path)))}catch{t.push(`roles`)}}pe.size>0&&t.push(...[...pe].map(e=>`plugin:${e}`));for(let e of de)try{await d.remove?.(e)}catch{t.push(`plugin:${e}`)}throw t.length>0?await eL(r.conflictedRecord,{...me,step:`conflicted`,status:`conflicted`}).catch(()=>void 0):await tL(r.preparingRecord).catch(()=>void 0),e instanceof SF||e instanceof Q?e:new Q(e instanceof hI||e instanceof uL?`capability_denied`:`install_failed`,yL(e),e,t.length>0?{recovery:`Resolve conflicted state before retrying.`}:{})}}async function PI(e){let t=await RF(e.activeRecord,XP);if(t===void 0)return;let n=vF(pF,t);if(n!==void 0)return n;let r=vF(mF,t);if(r===void 0)throw new Q(`state_corrupt`,`The HolyCodex configuration is invalid.`);if(!await vL(r))throw new Q(`state_corrupt`,`The existing HolyCodex configuration has an invalid digest.`,void 0,{path:e.activeRecord});let i=BA(r.plan);return{...r,plan:i,digest:await gL({owner:r.owner,install_id:r.install_id,version:r.version,plan:i,tier:r.tier,optional_selections:r.optional_selections,explicit_optional_selections:r.explicit_optional_selections,official_plugins:r.official_plugins??[],capability_state:r.capability_state??null,managed_artifacts:r.managed_artifacts,...r.managed_config===void 0?{}:{managed_config:r.managed_config},...r.plugin_config===void 0?{}:{plugin_config:r.plugin_config},...r.provider_config===void 0?{}:{provider_config:r.provider_config},...r.plugin_snapshot===void 0?{}:{plugin_snapshot:r.plugin_snapshot},...r.owned_plugins===void 0?{}:{owned_plugins:r.owned_plugins}})}}function FI(e){return{computer_use:e.computer_use,work:e.work,frontend:e.frontend,security:e.security}}function II(e){if(e===void 0||e.trim().length===0)return{};try{let t=globalThis.Bun,n=t?.TOML?.parse?t.TOML.parse(e):gI(e),r=vF(SM,n);if(r===void 0)throw Error(`TOML document contains unsupported values.`);return r}catch(e){throw new Q(`state_corrupt`,`The Codex config.toml is not valid TOML.`,e)}}function LI(e){try{let t=globalThis.Bun;return`${(t?.TOML?.stringify?t.TOML.stringify(e):_I(e)).trimEnd()}\n`}catch(e){throw new Q(`install_failed`,`The merged Codex configuration is not writable.`,e)}}async function RI(e){return{preference:await HI(e,`plugins`,jI),marketplace:await HI(e,`marketplaces`,MI)}}async function zI(e,t){return await Promise.all(t.map(async t=>{let n=await HI(e,`plugins`,t),r={presence:n.presence,digest:n.digest,...n.safe_value?.kind===`boolean`?{safe_value:n.safe_value}:{}};return{plugin_id:t,before:r,after:r}}))}async function BI(e,t,n={}){let r=e,i=[],a=[],o=[];for(let[s,c,l]of[[`preference`,`plugins`,jI],[`marketplace`,`marketplaces`,MI]]){let u=t.before[s],d=t.after[s],f=await HI(e,c,l);if(n.allowBeforeState!==!0||f.digest!==u.digest){if(f.digest!==d.digest){o.push(s);continue}if(u.presence===`absent`){f.presence===`present`&&(r=qI(r,c,l),a.push(s));continue}if(u.safe_value===void 0){o.push(s);continue}r=KI(r,c,l,GI(u.safe_value)),i.push(s)}}return{document:r,restored:i,removed:a,preserved:o}}async function VI(e,t,n,r={}){let i=e,a=[],o=[],s=[];for(let c of t){if(!n.has(c.plugin_id))continue;let t=c.before,l=c.after,u=await HI(e,`plugins`,c.plugin_id);if(r.allowBeforeState!==!0||u.digest!==t.digest){if(u.digest!==l.digest){s.push(c.plugin_id);continue}if(t.presence===`absent`){u.presence===`present`&&(i=qI(i,`plugins`,c.plugin_id),o.push(c.plugin_id));continue}if(t.safe_value===void 0){s.push(c.plugin_id);continue}i=KI(i,`plugins`,c.plugin_id,{enabled:t.safe_value.value}),a.push(c.plugin_id)}}return{document:i,restored:a,removed:o,preserved:s}}async function HI(e,t,n){let r=UI(e,t,n),i=await dj(`holycodex-plugin-config`,[cj(JP({key:`${t}.${n}`,value:r===void 0?{presence:`absent`}:r}))]),a=WI(t,r);return{presence:r===void 0?`absent`:`present`,digest:i,...a===void 0?{}:{safe_value:a}}}function UI(e,t,n){let r=e[t];if(JI(r))return r[n]}function WI(e,t){if(!JI(t))return;let n=Object.keys(t);if(e===`plugins`)return n.length!==1||n[0]!==`enabled`||typeof t.enabled!=`boolean`?void 0:{kind:`boolean`,value:t.enabled};if(!(n.length!==2||!n.includes(`source_type`)||!n.includes(`source`)||t.source_type!==`git`||t.source!==AI))return{kind:`marketplace`,source_type:`git`,source:AI}}function GI(e){return e.kind===`boolean`?{enabled:e.value}:{source_type:e.source_type,source:e.source}}function KI(e,t,n,r){let i={...e},a=i[t];if(a!==void 0&&!JI(a))throw new Q(`state_corrupt`,`The ${t} Codex config table is invalid.`);return i[t]={...a,[n]:r},i}function qI(e,t,n){let r=e[t];if(!JI(r)||!Object.prototype.hasOwnProperty.call(r,n))return e;let i={...e},a={...r};return delete a[n],Object.keys(a).length===0?delete i[t]:i[t]=a,i}function JI(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function YI(e,t){let n=ZF(e,t);return{model:n.model,model_reasoning_effort:n.effort,service_tier:n.serviceTier,model_verbosity:`low`,developer_instructions:QF(),suppress_unstable_features_warning:!0,"features.default_mode_request_user_input":!0,"features.multi_agent_v2":!0,"features.context_management.experimental_mode":!0,"agents.explorer.config_file":`holycodex/agents/explorer.toml`,"agents.librarian.config_file":`holycodex/agents/librarian.toml`,"agents.worker.config_file":`holycodex/agents/worker.toml`,"agents.reviewer.config_file":`holycodex/agents/reviewer.toml`}}async function XI(e,t,n,r){let i=[];for(let a of Object.keys(r)){let r=a;if(n.managed[r]!==void 0){(await QM(e,n,r)).status===`drifted`&&i.push(r);continue}wM(t,r)!==wM(e,r)&&i.push(r)}if(i.length>0)throw new Q(`state_corrupt`,`Codex settings changed during native plugin setup.`,void 0,{keys:i.join(`,`)})}function ZI(e,t){if(!t)return e;let n=t.managed_artifacts.map(e=>e.path),r=e;for(let e of[`explorer`,`librarian`,`worker`,`reviewer`]){if(!n.some(t=>t.startsWith(`agents/${e[0]?.toUpperCase()}${e.slice(1)}.`)))continue;let t=`agents.${e}.config_file`,i=wM(r,t);typeof i==`string`&&i.replaceAll(`\\`,`/`).replace(/^\.\//u,``)===`agents/${e}.toml`&&(r=OM(r,t))}return r}function QI(e,t){if(wM(e,`developer_instructions`)!==void 0&&t.managed.developer_instructions===void 0)throw new Q(`state_corrupt`,`Existing developer_instructions cannot be displaced safely; remove it or converge managed state first.`)}async function $I(e,t){let n=await e.list();return t.map(e=>{let t=dL(n,e);return{plugin_id:e,status:t===void 0?`missing`:t.installed&&t.enabled?`installed`:t.installed?`disabled`:`available`}})}async function eL(e,t){if(vF(_F,t)===void 0)throw new Q(`state_corrupt`,`The HolyCodex transaction state is invalid.`);await PF(e,JP(t))}async function tL(e){await l(e,{force:!1}).catch(e=>{if(!AF(e,`ENOENT`))throw e})}async function nL(e,t){if(t===void 0){await l(e,{force:!1}).catch(e=>{if(!AF(e,`ENOENT`))throw e});return}await FF(e,t)}async function rL(e,t,n,r,i=[]){let a=II(await LF(e.configFile)),o=YI(t,n);for(let[e,t]of Object.entries(o)){let n=wM(a,e);if(e===`developer_instructions`){if(typeof n!=`string`||await iL(e,n)!==r.managed[e]?.lastManagedValue.value)throw new Q(`install_failed`,`The effective Root instructions did not converge.`)}else if(n!==t)throw new Q(`install_failed`,`The effective Codex setting ${e} did not converge.`)}for(let t of[`explorer`,`librarian`,`worker`,`reviewer`]){let n=wM(a,`agents.${t}.config_file`);if(typeof n!=`string`)throw new Q(`install_failed`,`The ${t} role registration is missing.`);let r=_(e.roleRoot,`${t}.toml`),o=r.replaceAll(`\\`,`/`);if(GM(e.configFile,n).replaceAll(`\\`,`/`)!==o)throw new Q(`install_failed`,`The ${t} role registration is stale.`);let s=await LF(r);if(s===void 0)throw new Q(`install_failed`,`The ${t} role file is missing.`);if(i.includes(r))continue;let c=II(s);if(c.name!==t||typeof c.description!=`string`||typeof c.model!=`string`||typeof c.model_reasoning_effort!=`string`||typeof c.service_tier!=`string`||typeof c.developer_instructions!=`string`||wM(c,`agents.enabled`)!==!1||wM(c,`features.multi_agent_v2`)!==!1||wM(c,`features.multi_agent`)!==!1)throw new Q(`install_failed`,`The ${t} role file is malformed.`)}let s=await LF(`${e.codexHome}/agents/root.toml`);if(s!==void 0&&oI(s))throw new Q(`install_failed`,`A stale HolyCodex Root role remains installed.`)}async function iL(e,t){return await dj(`holycodex-managed-config-value`,[cj({keyPath:e,value:t})])}function aL(e,t){let n={};for(let r of[`computer_use`,`work`,`frontend`,`security`]){let i=t?.[r]??e?.[r];i!==void 0&&(n[r]=i)}return n}function oL(e){return[`computer_use`,`work`,`frontend`,`security`].find(t=>CA[t].pluginIds.includes(e))}function sL(e){return(e?.official_plugins??[]).filter(t=>{let n=oL(t);return n===void 0||e?.optional_selections[n]!==!0})}async function cL(e,t,n){for(let r of t){let t;try{t=dL(await e.list(),r)}catch(e){throw lL(`list`,e,r)}if(t?.installed&&!t.enabled)throw new uL(`uncertain`,`${r} is disabled`);let i=!(t?.installed&&t.enabled);if(!(t?.installed&&t.enabled))try{await e.add(r)}catch(e){throw n?.(r,`uncertain`),lL(`add`,e,r)}let a;try{a=dL(await e.list(),r)}catch(e){throw i&&n?.(r,`uncertain`),lL(`list`,e,r)}if(!a?.installed)throw i&&n?.(r,`uncertain`),new uL(`missing`,`${r} is not installed after add`);if(i&&a.enabled&&n?.(r,`new`),!a.enabled)throw i&&n?.(r,`new`),new uL(`uncertain`,`${r} is disabled after add`)}}function lL(e,t,n){return t instanceof hI?t:new hI(e===`list`?`list_failed`:`add_failed`,e===`list`?`Codex could not read the status of ${n}.`:`Codex could not add ${n}.`,t,{plugin_id:n})}var uL=class extends Error{status;constructor(e,t){super(t),this.name=`PluginVerificationError`,this.status=e}};function dL(e,t){return[...e.installed,...e.available].find(e=>e.pluginId===t)}function fL(e,t){let n=e??t??`plus`;if(!Bj(n).ok)throw new Q(`install_failed`,`Unknown plan.`);return n}function pL(e,t){let n=e??t??`standard`;if(vF(VA,n)===void 0)throw new Q(`install_failed`,`The tier is not supported.`);return n}function mL(e,t){let n=EA(e,t?FI(t):TA);return{computer_use:n.computer_use,work:n.work,frontend:n.frontend,security:n.security,coding:!0}}function hL(e,t=new Map){return Object.fromEntries([`computer_use`,`work`,`frontend`,`security`].map(n=>{let r=e[n];return[n,{selected:r,status:r?t.get(n)??`healthy`:`disabled`,plugin_ids:[...CA[n].pluginIds]}]}))}async function gL(e){return await dj(`install-record`,[cj(JP(e))])}async function _L(e){return await vL(e)}async function vL(e){return await gL({owner:e.owner,install_id:e.install_id,version:e.version,plan:e.plan,tier:e.tier,optional_selections:e.optional_selections,explicit_optional_selections:e.explicit_optional_selections,official_plugins:e.official_plugins??[],capability_state:e.capability_state??null,managed_artifacts:e.managed_artifacts,...e.managed_config===void 0?{}:{managed_config:e.managed_config},...e.plugin_config===void 0?{}:{plugin_config:e.plugin_config},...e.provider_config===void 0?{}:{provider_config:e.provider_config},...e.plugin_snapshot===void 0?{}:{plugin_snapshot:e.plugin_snapshot},...e.owned_plugins===void 0?{}:{owned_plugins:e.owned_plugins}})===e.digest}function yL(e){return e instanceof Error?e.message.slice(0,256):`operation failed`}var Q=class extends Error{code;causeValue;details;constructor(e,t,n,r={}){super(t),this.name=`InstallerError`,this.code=e,this.causeValue=n,this.details=r}};async function bL(e={},t=process.env){let n=xF(e,t),r={};try{await DF(n.codexHome),await DF(n.stateRoot),r.paths=DL({state_root:n.stateRoot})}catch(e){r.paths=OL([`path_symlink`],{error:AL(e)})}let[i,a,o]=await Promise.all([PI(n).catch(e=>{r.configuration=OL([`state_corrupt`],{error:AL(e)})}),RF(n.preparingRecord,_F).catch(e=>{r.transaction=OL([`state_corrupt`],{path:n.preparingRecord,error:AL(e)})}),RF(n.conflictedRecord,_F).catch(e=>{r.transaction=OL([`state_corrupt`],{path:n.conflictedRecord,error:AL(e)})})]);if(a!==void 0&&r.transaction?.status!==`failed`&&(r.transaction=OL([`incomplete_install_state`])),o!==void 0&&r.transaction?.status!==`failed`&&(r.transaction=OL([`conflicted_state`])),r.configuration||=i?await _L(i)?DL({plan:i.plan,tier:i.tier,install_id:i.install_id}):OL([`configuration_changed`],{path:n.activeRecord}):OL([`configuration_missing`]),i){r.runtime_config=await SL(n,i),r.native_roles=await CL(n,i.tier);let e=Object.entries(i.capability_state??{}).find(([,e])=>e.selected&&e.status!==`healthy`);e&&(r.capabilities=OL([`selected_capability_not_healthy`],{capability:e[0],status:e[1].status}))}try{let e=await LF(`${n.codexHome}/agents/root.toml`);if(e!==void 0&&oI(e)){let e=r.native_roles;r.native_roles={status:`failed`,reasons:[...e?.reasons??[],`stale_legacy_root`],details:{...e?.details,path:`${n.codexHome}/agents/root.toml`}}}}catch(e){r.native_roles=OL([`native_role_invalid`],{error:AL(e)})}let s=e.officialPluginManager??await pI.discover({...t,CODEX_HOME:n.codexHome}).catch(()=>void 0);if(i&&s?.status){let e=[...new Set([kI,...DA({computer_use:i.optional_selections.computer_use,work:i.optional_selections.work,frontend:i.optional_selections.frontend,security:i.optional_selections.security},i.official_plugins),...i.owned_plugins??[]])];try{let t=await s.status(e),n=Object.entries(t).filter(([,e])=>e!==`installed`).map(([e])=>e);r.native_plugins=n.length===0?DL({status:t}):OL([`native_plugin_disagreement`],{missing:n,status:t})}catch(e){r.native_plugins=OL([`native_plugin_status_failed`],{error:AL(e)})}}else r.native_plugins={status:`unsupported`,reasons:[`native_plugin_manager_unavailable`],details:{}};let c=Object.values(r).flatMap(e=>e.reasons);return{healthy:Object.values(r).every(e=>e.status!==`failed`),checks:r,reasons:[...new Set(c)]}}async function xL(e={},t=process.env){let n=xF(e,t);await DF(n.codexHome),await DF(n.stateRoot);let r=await PI(n),[i,a]=await Promise.all([RF(n.preparingRecord,_F),RF(n.conflictedRecord,_F)]),o=a??i??r,s=new Set(EL(o)),c=[],d=[],f=[];if(r&&!await _L(r))return d.push(n.activeRecord),f.push(`configuration_changed`),{removed:c,preserved:d,reasons:f};let p=await LF(n.configFile),m=II(p);if(o?.managed_config){let e=await ZM(m,o.managed_config,{schema:o.managed_config.schema,installId:o.managed_config.installId});if(e.preservedKeys.length>0||e.unresolvedKeys.length>0)return d.push(n.configFile),f.push(`managed_config_changed`),await wL(n,o),{removed:c,preserved:d,reasons:f}}if(o?.plugin_config&&(await BI(m,o.plugin_config)).preserved.length>0)return d.push(n.configFile),f.push(`plugin_config_changed`),await wL(n,o),{removed:c,preserved:d,reasons:f};if(o?.provider_config&&(await VI(m,o.provider_config,s)).preserved.length>0)return d.push(n.configFile),f.push(`provider_config_changed`),await wL(n,o),{removed:c,preserved:d,reasons:f};let h;try{h=e.officialPluginManager??await pI.discover({...t,CODEX_HOME:n.codexHome})}catch(e){throw new Q(`capability_denied`,`Native Codex plugin removal is unavailable.`,e,{recovery:`Install or expose Codex, then retry.`})}if(h===void 0||!h.remove||!h.list)throw new Q(`capability_denied`,`Native Codex plugin removal and readback are unavailable.`);let g=await eI(n.codexHome,o?.managed_artifacts??[]);c.push(...g.removed),d.push(...g.preserved),g.preserved.length>0&&f.push(`managed_artifact_changed`);for(let e of s)try{await h.remove(e);let t=await h.list();if([...t.installed,...t.available].find(t=>t.pluginId===e&&t.installed)!==void 0)throw new Q(`capability_denied`,`Codex still reports ${e} after removal.`);c.push(e)}catch(t){throw f.push(`native_plugin_remove_failed`),await wL(n,o??TL()),new Q(`capability_denied`,`Codex native plugin removal did not converge for ${e}: ${AL(t)}`,t)}if(g.preserved.length>0)return await wL(n,o??TL()),{removed:c,preserved:d,reasons:f};let _;try{let e=II(await LF(n.configFile)),t=o?.managed_config;if(t){let r=await ZM(e,t,{schema:t.schema,installId:t.installId});if(r.preservedKeys.length>0||r.unresolvedKeys.length>0)return d.push(n.configFile),f.push(`managed_config_changed`),await wL(n,o??TL()),{removed:c,preserved:d,reasons:f};e=r.document,t=r.state}if(o?.plugin_config){let t=await BI(e,o.plugin_config,{allowBeforeState:!0});if(t.preserved.length>0)return d.push(n.configFile),f.push(`plugin_config_changed`),await wL(n,o),{removed:c,preserved:d,reasons:f};e=t.document}if(o?.provider_config){let t=await VI(e,o.provider_config,s,{allowBeforeState:!0});if(t.preserved.length>0)return d.push(n.configFile),f.push(`provider_config_changed`),await wL(n,o),{removed:c,preserved:d,reasons:f};e=t.document}(o?.managed_config||o?.plugin_config||o?.provider_config)&&(_=t===void 0?{document:e}:{document:e,state:t}),_!==void 0&&(Object.keys(_.document).length===0&&p===void 0?await l(n.configFile,{force:!1}):await FF(n.configFile,LI(_.document)))}catch(e){if(e instanceof Q)throw await wL(n,o??TL()),e;return d.push(n.configFile),f.push(`managed_config_write_failed`),await wL(n,o??TL()),{removed:c,preserved:d,reasons:f}}if(r)try{await l(n.activeRecord,{force:!1}),c.push(n.activeRecord)}catch(e){if(AF(e,`ENOENT`))c.push(n.activeRecord);else return d.push(n.activeRecord),f.push(`state_remove_failed`),await wL(n,o??r),{removed:c,preserved:d,reasons:f}}if(d.length===0){for(let[e,t]of[[n.preparingRecord,i!==void 0],[n.conflictedRecord,a!==void 0]])if(t)try{await kL(e),c.push(e)}catch{d.push(e),f.push(`state_remove_failed`)}}if(d.length===0)try{await u(n.roleRoot),c.push(n.roleRoot)}catch(e){AF(e,`ENOENT`)||(d.push(n.roleRoot),f.push(`role_directory_not_empty`))}if(d.length===0)try{await u(n.stateRoot),c.push(n.stateRoot)}catch(e){AF(e,`ENOENT`)?c.push(n.stateRoot):(d.push(n.stateRoot),f.push(`state_directory_not_empty`))}return{removed:c,preserved:d,reasons:f}}async function SL(e,t){if(!t.managed_config)return OL([`incomplete_install_state`]);try{let n=II(await LF(e.configFile)),r=YI(t.plan,t.tier),i=[];for(let[e,a]of Object.entries(r))((await QM(n,t.managed_config,e)).status!==`unchanged`||e!==`developer_instructions`&&wM(n,e)!==a)&&i.push(e);return i.length===0?DL({managed_keys:Object.keys(r).length}):OL([`changed_holycodex_config`],{keys:i})}catch(e){return OL([`config_unreadable`],{error:AL(e)})}}async function CL(e,t){try{let n=II(await LF(e.configFile)),r=[];for(let i of[`explorer`,`librarian`,`worker`,`reviewer`]){let a=wM(n,`agents.${i}.config_file`),o=`${e.roleRoot}/${i}.toml`.replaceAll(`\\`,`/`);if(typeof a!=`string`||GM(e.configFile,a).replaceAll(`\\`,`/`)!==o){r.push(`${i}:registration`);continue}let s=await LF(`${e.roleRoot}/${i}.toml`);if(s===void 0){r.push(`${i}:missing`);continue}let c=II(s);(c.name!==i||typeof c.description!=`string`||typeof c.developer_instructions!=`string`||c.model!==`gpt-5.6-luna`||c.model_reasoning_summary!==`none`||c.model_verbosity!==`low`||c.tool_output_token_limit!==12e3||c.service_tier!==(t===`standard`?`default`:`fast`)||wM(c,`agents.enabled`)!==!1||wM(c,`features.multi_agent_v2`)!==!1||wM(c,`features.multi_agent`)!==!1)&&r.push(`${i}:malformed`)}let i=await LF(`${e.codexHome}/agents/root.toml`);return i!==void 0&&oI(i)&&r.push(`root:stale`),r.length===0?DL({role_root:e.roleRoot}):OL([`native_role_disagreement`],{roles:r})}catch(e){return OL([`native_role_invalid`],{error:AL(e)})}}async function wL(e,t){let n={...t,status:`conflicted`,step:`conflicted`,managed_config:t.managed_config??{owner:`holycodex`,schema:t.schema_epoch,installId:t.install_id,managed:{}},plugin_snapshot:t.plugin_snapshot??[],owned_plugins:t.owned_plugins??[]};vF(_F,n)!==void 0&&await PF(e.conflictedRecord,JP(n))}function TL(){return{owner:`holycodex`,schema_epoch:`state-0.16`,install_id:`remove-conflict`,version:`0.0.0`,digest:`0`.repeat(64),plan:`plus`,tier:`standard`,optional_selections:{computer_use:!1,work:!1,frontend:!1,security:!1,coding:!0},explicit_optional_selections:{},managed_artifacts:[],installed_at:new Date(0).toISOString()}}function EL(e){if(e?.owned_plugins!==void 0)return[...new Set(e.owned_plugins)];let t=(e?.plugin_snapshot??[]).filter(e=>e.plugin_id!==`holycodex@holycodex`&&e.status!==`installed`).map(e=>e.plugin_id);return[...new Set([kI,...t])]}function DL(e){return{status:`healthy`,reasons:[],details:e}}function OL(e,t={}){return{status:`failed`,reasons:e,details:t}}async function kL(e){await l(e,{force:!1}).catch(e=>{if(!AF(e,`ENOENT`))throw e})}function AL(e){return e instanceof Error?e.message.slice(0,256):`operation failed`}async function jL(e,t={}){if(Zj(e)||e[0]===`help`){let t=e[0]===`help`?e.slice(1).filter(e=>!e.startsWith(`-`))[0]:Qj(e);return{envelope:UL(t===void 0?`help`:`${t} help`,{help:Yj(t)}),exitCode:0}}let n;try{n=Gj(e);let r=await ML(n,t);return{envelope:UL(n.command,r),exitCode:GL(n.command,r)}}catch(t){return WL(n?.command??qL(e),t)}}async function ML(e,t){switch(e.command){case`install`:return JP(await NL(e,t));case`doctor`:return JP(await bL(HL(e,t),t.env));case`remove`:return JP(await PL(e,t));case`version`:return JP(await FL(e,t));case`help`:return{help:Yj(e.positionals[0])};default:throw new fR(`invalid_argument`,`Unknown command.`)}}async function NL(e,t){let n=e.options.json===!0;if(!await IL(e,t,`Install HolyCodex into the selected Codex home?`))throw new fR(`non_tty_confirmation_required`,`Install requires --yes in non-interactive mode.`);XL(t,n,`Validating Codex target`),XL(t,n,`Installing HolyCodex`),XL(t,n,`Installing selected capabilities`),XL(t,n,`Configuring Root`),XL(t,n,`Installing subagent roles`);let r=await NI({...zL(e)===void 0?{}:{plan:zL(e)},...BL(e)===void 0?{}:{tier:BL(e)},...RL(e)===void 0?{}:{optional:RL(e)},...VL(e,`add-plugin`).length===0?{}:{officialPlugins:VL(e,`add-plugin`)}},HL(e,t),t.env);return XL(t,n,`Verifying installation`),XL(t,n,`HolyCodex installation complete`),r}async function PL(e,t){let n=e.options.json===!0;if(!await IL(e,t,`Remove HolyCodex-owned Codex state?`))throw new fR(`non_tty_confirmation_required`,`Remove requires --yes in non-interactive mode.`);XL(t,n,`Validating HolyCodex ownership`);let r=await xL(HL(e,t),t.env);return XL(t,n,`Removing HolyCodex-owned state`),XL(t,n,`HolyCodex removal complete`),r}async function FL(e,t){let n=e.positionals[0];return n?await qF(n,e.options[`dry-run`]===!0):{version:await GF()}}async function IL(e,t,n){return e.options.yes===!0?!0:e.options.json===!0||t.io?.stdoutIsTTY!==!0?!1:await LL(t,n)}async function LL(e,t){return e.io?.confirm?await e.io.confirm(t):!1}function RL(e){let t={};for(let n of[`computer_use`,`work`,`frontend`,`security`]){let r=n.replaceAll(`_`,`-`);e.options[r]===!0?t[n]=!0:(e.options[r]===!1||e.options[`no-${r}`]===!0)&&(t[n]=!1)}return Object.keys(t).length===0?void 0:t}function zL(e){let t=e.options.plan;if(typeof t!=`string`)return;let n=Bj(t);return n.ok?n.value.name:void 0}function BL(e){let t=e.options.tier;return t===`standard`||t===`fast`||t===`fast-all`?t:void 0}function VL(e,t){let n=e.options[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function HL(e,t){let n=t.installer??{},r=e.options[`codex-home`];return typeof r==`string`?{...n,paths:{...n.paths,codexHome:r},...t.now?{now:t.now}:{}}:{...n,...t.now?{now:t.now}:{}}}function UL(e,t){let n=Dj({schema_version:ce,ok:!0,command:e,data:t,warnings:[]});if(!n.ok)throw new fR(`internal_error`,`The success envelope failed validation.`);return n.value}function WL(e,t){let n=KL(t),r=Dj({schema_version:ce,ok:!1,command:e,error:{code:n.code,message:n.message,details:n.details},warnings:[]});return r.ok?{envelope:r.value,exitCode:n.exitCode}:{envelope:{schema_version:ce,ok:!1,command:`internal-error`,error:{code:`internal_error`,message:`The CLI failure envelope was invalid.`,details:{}},warnings:[]},exitCode:5}}function GL(e,t){return e===`doctor`&&YL(t)&&t.healthy===!1?4:0}function KL(e){if(e instanceof Wj)return{code:e.code,message:JL(e.message),details:e.details,exitCode:1};if(e instanceof fR)return{code:e.code,message:JL(e.message),details:{},exitCode:e.code===`internal_error`?5:1};if(e instanceof SF)return{code:`trust_boundary_failed`,message:JL(e.message),details:{},exitCode:4};if(e instanceof Q){let t=e.code===`capability_denied`?2:e.code===`state_corrupt`?4:3;return{code:e.code,message:JL(e.message),details:e.details,exitCode:t}}if(e instanceof hI){let t=[`timeout`,`output_limit`,`cancelled`,`readback_mismatch`].includes(e.code),n=e.code===`plugin_disabled`||e.code===`plugin_missing`||e.code===`command_failed`;return{code:t?`effect_uncertain`:n?`capability_denied`:`install_failed`,message:JL(e.message),details:e.details,exitCode:t?4:n?2:3}}return e instanceof zF?{code:e.code,message:JL(e.message),details:{},exitCode:4}:e instanceof YF?{code:e.code,message:JL(e.message),details:{},exitCode:1}:(e instanceof Error,{code:`internal_error`,message:`The command failed unexpectedly.`,details:{},exitCode:5})}function qL(e){return e.find(e=>!e.startsWith(`-`))??`unknown`}function JL(e){return Array.from(e).map(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127?` `:e}).join(``).replace(/\s+/gu,` `).trim().slice(0,512)}function YL(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function XL(e,t,n){t||e.io?.stderrIsTTY===!1||e.io?.writeStderr?.(`${QL(n,{stderrIsTTY:e.io?.stderrIsTTY,env:e.env})}\n`)}function ZL(e,t={}){let n=$j(t);if(e.envelope.ok)return e.envelope.command===`version`?$L(e.envelope.data):e.envelope.command===`install`?eR(e.envelope.data,n):e.envelope.command===`remove`?tR(e.envelope.data,n):e.envelope.command===`doctor`?nR(e.envelope.data,n):`${$(`✔`,`green`,n)} ${$(e.envelope.command,`heading`,n)}\n${cR(e.envelope.data,n)}`;let r=e.envelope.error,i=dR(r.code,e.envelope.command);return[`${$(`✖`,`red`,n)} ${$(e.envelope.command,`heading`,n)}`,` ${$(r.code,`red`,n)}: ${r.message}`,...lR(r.details,n),...i===void 0?[]:[` hint: ${i}`],``].join(`
89
- `)}function QL(e,t={}){return`${$(`•`,`cyan`,$j({...t,stream:`stderr`}))} ${e}`}function $L(e){if(YL(e)&&typeof e.version==`string`)return`holycodex ${e.version}\n`;if(YL(e)&&typeof e.next==`string`){let t=typeof e.previous==`string`?` (from ${e.previous})`:``;return`holycodex version updated to ${e.next}${t}\n`}return`holycodex version completed
90
- `}function eR(e,t){let n=rR(e,`record`),r=aR(n,`version`)??`unknown`,i=aR(n,`plan`)??`unknown`,a=aR(n,`tier`)??`unknown`,o=rR(n,`optional_selections`),s=rR(n,`capability_state`),c=[`frontend`,`security`,`work`,`computer_use`].filter(e=>o?.[e]===!0).map(e=>{let t=aR(rR(s,e),`status`);return t===void 0||t===`healthy`?e:`${e} (${t})`}),l=oR(e,`preserved`),u=oR(e,`warnings`),d=c.length===0?`none`:c.join(`, `),f=l.length===0?`none`:`${l.length} managed item${l.length===1?``:`s`} (review before retrying)`;return`${[`${$(`✔`,`green`,t)} ${$(`install`,`heading`,t)}`,` ${$(`version`,`option`,t)}: ${r}`,` ${$(`plan`,`option`,t)}: ${i}`,` ${$(`tier`,`option`,t)}: ${a}`,` ${$(`capabilities`,`option`,t)}: ${d}`,` ${$(`preserved`,`option`,t)}: ${f}`,...u.map(e=>` ${$(`warning`,`red`,t)}: ${sR(e)}`)].join(`
91
- `)}\n`}function tR(e,t){let n=oR(e,`removed`),r=oR(e,`preserved`),i=oR(e,`reasons`),a=r.length===0?`none`:`${r.length} item${r.length===1?``:`s`} (review before retrying)`;return`${[`${$(`✔`,`green`,t)} ${$(`remove`,`heading`,t)}`,` ${$(`removed`,`option`,t)}: ${n.length} owned item${n.length===1?``:`s`}`,` ${$(`preserved`,`option`,t)}: ${a}`,...i.map(e=>` ${$(`reason`,`option`,t)}: ${sR(e)}`)].join(`
92
- `)}\n`}function nR(e,t){let n=iR(e,`healthy`)===!0,r=rR(e,`checks`),i=r===void 0?[]:Object.entries(r),a=i.flatMap(([e,n])=>{let r=YL(n)?n:void 0,i=aR(r,`status`);if(i===void 0||i===`healthy`)return[];let a=oR(r,`reasons`);return[` ${$(e,`option`,t)}: ${a.length===0?i:a.map(sR).join(`, `)}`]});return`${[`${n?$(`✔`,`green`,t):$(`✖`,`red`,t)} ${$(`doctor`,`heading`,t)}`,` ${$(`status`,`option`,t)}: ${n?`healthy`:`needs attention`}`,` ${$(`checks`,`option`,t)}: ${i.length}`,...a.length===0?[]:[` ${$(`issues`,`option`,t)}:`,...a]].join(`
93
- `)}\n`}function rR(e,t){if(YL(e))return YL(e[t])?e[t]:void 0}function iR(e,t){return YL(e)?e[t]:void 0}function aR(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function oR(e,t){return!YL(e)||!Array.isArray(e[t])?[]:e[t]}function sR(e){return typeof e==`string`?e.replaceAll(`_`,` `):`operation requires review`}function cR(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return` ${$(uR(e),`dim`,t)}\n`;let n=Object.entries(e);if(n.length===0)return``;let r=Math.max(...n.map(([e])=>e.length));return`${n.map(([e,n])=>` ${$(e.padEnd(r),`option`,t)}: ${uR(n)}`).join(`
94
- `)}\n`}function lR(e,t){return Object.entries(e).map(([e,n])=>` ${$(e,`option`,t)}: ${$(uR(n),`dim`,t)}`)}function uR(e){return typeof e==`string`?e:e===null||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dR(e,t){if(e===`invalid_argument`||e===`unknown_command`)return`holycodex ${t} --help`;if(e===`non_tty_confirmation_required`)return`rerun with --yes or use an interactive terminal`;if(e===`capability_denied`)return"run `holycodex doctor` to inspect capability availability"}function $(e,t,n){return n?`\u001b[${{red:`31`,green:`32`,cyan:`36`,dim:`2`,heading:`1`,option:`36`}[t]}m${e}\u001b[0m`:e}var fR=class extends Error{code;constructor(e,t){super(t),this.name=`CliCommandError`,this.code=e}};async function pR(e=Bun.argv.slice(2),t=mR()){let n={env:process.env,cwd:process.cwd(),io:{stdin:t.stdin??gR(),stdoutIsTTY:t.stdoutIsTTY??process.stdout.isTTY===!0,stderrIsTTY:t.stderrIsTTY??process.stderr.isTTY===!0,...t.confirm===void 0?{}:{confirm:t.confirm},writeStdout:t.writeStdout,writeStderr:t.writeStderr}},r=await jL(e,n);return(Zj(e)||e[0]===`help`)&&!hR(e)?n.io?.writeStdout?.(Xj(Qj(e),{stdoutIsTTY:n.io?.stdoutIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stdout`})):hR(e)?n.io?.writeStdout?.(`${JSON.stringify(r.envelope)}\n`):r.envelope.ok?n.io?.writeStdout?.(ZL(r,{stdoutIsTTY:n.io?.stdoutIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stdout`})):n.io?.writeStderr?.(ZL(r,{stdoutIsTTY:n.io?.stderrIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stderr`})),r.exitCode}function mR(){return{stdoutIsTTY:process.stdout.isTTY===!0,stderrIsTTY:process.stderr.isTTY===!0,writeStdout:e=>process.stdout.write(e),writeStderr:e=>process.stderr.write(e),confirm:async t=>{let n=e({input:process.stdin,output:process.stderr});try{let e=await n.question(`${t} [y/N] `);return/^(?:y|yes)$/iu.test(e.trim())}finally{n.close()}}}}function hR(e){let t=!1;for(let n of e)n===`--json`||n===`--json=true`?t=!0:n===`--json=false`&&(t=!1);return t}async function*gR(){let e=new TextDecoder;for await(let t of process.stdin)typeof t==`string`?yield t:yield e.decode(t,{stream:!0});let t=e.decode();t.length>0&&(yield t)}const _R=`holycodex`;import.meta.main&&(process.exitCode=await pR());export{Wj as ArgumentError,oF as CapabilityInstallStateSchema,sF as CapabilityStateRecordSchema,pI as CodexOfficialPluginManager,pF as InstallRecordSchema,aF as InstallRequestSchema,Q as InstallerError,hI as OfficialPluginManagerError,SF as PathBoundaryError,bF as STATE_SCHEMA,CF as assertRootText,bL as doctorHolyCodex,ML as executeCommand,Zj as helpRequested,Yj as helpText,Qj as helpTopic,NI as installHolyCodex,$F as installNativeAgents,gL as installRecordDigest,_R as packageName,Gj as parseArgv,OF as pathWithin,XF as projectNativeAgents,ZF as projectRootAgent,UF as publicManifestPath,PI as readActiveInstallRecord,KF as readCanonicalBaseVersion,GF as readCanonicalVersion,xL as removeHolyCodex,eI as removeManagedNativeAgents,Xj as renderHelp,ZL as renderHuman,tI as renderNativeAgent,QL as renderProgress,xF as resolveInstallerPaths,pR as runBinary,jL as runCli,qF as updateCanonicalVersion};
79
+ `}}function bI(e,t={}){let n=CI({...t,stream:`stdout`});return yI(e).split(`
80
+ `).map(e=>e===`HolyCodex`||/^(?:Usage|Options|Plans control routing only|Tier is independent service handling|Capability defaults).*:$/u.test(e)?wI(e,`heading`,n):e.replace(/--[a-z][a-z0-9-]*/gu,e=>wI(e,`option`,n)).replace(/<[^>]+>/gu,e=>wI(e,`argument`,n))).join(`
81
+ `)}function xI(e){return e.some(e=>e===`-h`||e===`--help`||e===`--help=true`)}function SI(e){let t=e.filter(e=>!e.startsWith(`-`));return t[0]===`help`?t[1]:t[0]===`--version`||t[0]===`version`||t[0]===`-v`?`version`:t[0]}function CI(e){let t=e.env??{};return t.NO_COLOR!==void 0||t.TERM===`dumb`?!1:t.FORCE_COLOR!==void 0&&t.FORCE_COLOR!==`0`?!0:t.CI!==void 0&&t.CI!==`false`?!1:(e.stream===`stderr`?e.stderrIsTTY:e.stdoutIsTTY)===!0}function wI(e,t,n){return n?`\u001b[${{heading:`1`,option:`36`,argument:`2`}[t]}m${e}\u001b[0m`:e}function Y(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function TI(e){try{return _F(e),!0}catch{return!1}}function EI(e){switch(e){case`invalid_external_data`:case`manifest_invalid`:case`empty_output_directory`:return`validation`;case`discovery_failed`:return`identity`;case`protocol_mismatch`:case`method_unsupported`:case`server_request_unsupported`:case`unexpected_response`:return`protocol`;case`invalid_transport_line`:case`transport_closed`:case`transport_failure`:return`transport`;case`approval_required`:case`permission_denied`:return`approval`;case`cancellation`:return`interruption`;case`timeout`:return`timeout`;case`turn_failed`:return`turn`;case`closed`:return`closed`;case`server_error`:return`server`}}function DI(e){return{ok:!1,error:e}}function OI(e){return{ok:!0,value:e}}function kI(e,t=512){let n=``;for(let t of e){let e=t.codePointAt(0)??0;n+=e<=8||e===11||e===12||e>=14&&e<=31||e===127?` `:t}return n.replace(/\s+/gu,` `).trim().slice(0,t)}function AI(e,t=0){if(t>3)return`[truncated]`;if(e===null||typeof e==`boolean`)return e;if(typeof e==`string`)return kI(e,256);if(typeof e==`number`)return Number.isFinite(e)?e:null;if(Array.isArray(e))return e.slice(0,32).map(e=>AI(e,t+1));if(Y(e)){let n={};for(let[r,i]of Object.entries(e).slice(0,32)){let e=kI(r,96);e.length>0&&(n[e]=AI(i,t+1))}return n}return`[redacted]`}function jI(e){let t=AI(e);return Y(t)?t:{value:t}}function MI(e,t,n){return new X(`invalid_external_data`,`Invalid ${e}.`,{field:e,received:AI(t)},n===void 0?void 0:{cause:n})}function NI(e,t,n){let r=mP(e,t);if(er(r))throw MI(n,t,String(r.left));return r.right}function PI(e,t){try{return NI(e,t,`value`),!0}catch{return!1}}var FI,II,LI,RI,X,zI=v((()=>{uI(),lr(),pP(),FI=fe,II=G(e=>TI(e)),LI=G(e=>Y(e)&&TI(e)),K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),RI=K.pipe(pj(e=>e.length>0&&e.length<=4096)),Fj.pipe(pj(e=>Number.isFinite(e)&&e>=0)),X=class extends Error{code;kind;details;retryable;constructor(e,t,n={},r){super(t,r?.cause===void 0?void 0:{cause:r.cause}),this.name=`CodexError`,this.code=e,this.kind=EI(e),this.details=n,this.retryable=r?.retryable??!1,Object.freeze(this.details),Object.freeze(this)}}})),BI,VI,HI,UI,WI,GI,KI=v((()=>{BI=[`initialize`,`thread/start`,`thread/resume`,`thread/read`,`thread/list`,`thread/fork`,`thread/unsubscribe`,`turn/start`,`turn/steer`,`turn/interrupt`,`model/list`,`modelProvider/capabilities/read`,`config/read`,`permissionProfile/list`],VI=[`item/commandExecution/requestApproval`,`item/fileChange/requestApproval`,`applyPatchApproval`,`execCommandApproval`],HI=[`item/permissions/requestApproval`],UI=[`mcpServer/elicitation/request`],WI=[`item/tool/call`],GI={method:`initialized`}}));function qI(e,t=new Set){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;t.add(e);try{return Array.isArray(e)?e.every(e=>qI(e,t)):Y(e)&&Object.values(e).every(e=>qI(e,t))}finally{t.delete(e)}}function JI(e){return Y(e)&&qI(e)}function YI(e){let t=[],n=0,r=!1,i=!1;for(let a=0;a<=e.length;a+=1){let o=e[a];if(a===e.length||o===`.`&&!r){let r=e.slice(n,a),i=r.startsWith(`"`)?XI(r):r;if(!/^[A-Za-z][A-Za-z0-9_-]*$/u.test(i)&&!pF.includes(i))throw MI(`TOML key path`,e);t.push(i),n=a+1;continue}r?i?i=!1:o===`\\`?i=!0:o===`"`&&(r=!1):o===`"`&&(r=!0)}if(r||i||t.length===0||t.some(e=>e===`__proto__`||e===`constructor`||e===`prototype`))throw MI(`TOML key path`,e);return t}function XI(e){try{let t=JSON.parse(e);if(typeof t==`string`)return t}catch{}throw MI(`TOML quoted key`,e)}function ZI(e,t){if(!JI(e))throw MI(`TOML document`,e);let n=e;for(let e of YI(t)){if(!JI(n)||!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}function QI(e){return Array.isArray(e)?e.map(QI):Y(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,QI(t)])):e}function $I(e){return QI(e)}function eL(e,t,n){if(!JI(e)||!qI(n))throw MI(`TOML write`,{keyPath:t});let r=YI(t),i={...$I(e)},a=i;for(let e of r.slice(0,-1)){let n=a[e];if(n!==void 0&&!JI(n))throw MI(`TOML table path`,t);let r=n===void 0?{}:{...n};a[e]=r,a=r}return a[r.at(-1)]=QI(n),i}function tL(e,t){if(!JI(e))throw MI(`TOML document`,e);let n=YI(t),r={...$I(e)},i=[],a=r;for(let e of n.slice(0,-1)){let t=a[e];if(!JI(t))return r;let n={...t};i.push({table:a,key:e}),a[e]=n,a=n}let o=n.at(-1);if(!Object.prototype.hasOwnProperty.call(a,o))return r;delete a[o];for(let e=i.length-1;e>=0;--e){let t=i[e],n=t.table[t.key];if(JI(n)&&Object.keys(n).length===0)delete t.table[t.key];else break}return r}function nL(e){return typeof e==`string`?wL.includes(e)||/^agents\.(?:explorer|librarian|worker|reviewer)\.config_file$/u.test(e)?!0:pF.some(t=>e===`agents."${t}".config_file`):!1}function rL(e){return typeof e==`string`&&EL.test(e)}function iL(e){return e===`gpt-5.6-terra`||e===`gpt-5.6-sol`||e===`gpt-5.6-luna`||e===`low`||e===`medium`||e===`high`||e===`xhigh`||e===`max`||e==="default"||e===`fast`}function aL(e){return typeof e==`string`&&/^[a-f0-9]{64}$/u.test(e)}function oL(e,t){let n=new Set(t);return Object.keys(e).every(e=>n.has(e))}function sL(e){if(!Y(e)||!oL(e,[`kind`,`value`])||typeof e.kind!=`string`)return!1;switch(e.kind){case`enum`:return iL(e.value);case`boolean`:return typeof e.value==`boolean`;case`relative_path`:return typeof e.value==`string`&&pL(e.value);case`digest`:return aL(e.value);default:return!1}}function cL(e,t){switch(gL(e)){case`boolean`:return t.kind===`boolean`;case`relative_path`:return t.kind===`relative_path`;case`digest`:return t.kind===`digest`;case`enum`:return t.kind===`enum`?e===`model`?t.value===`gpt-5.6-terra`||t.value===`gpt-5.6-sol`||t.value===`gpt-5.6-luna`:e===`model_reasoning_effort`?t.value===`low`||t.value===`medium`||t.value===`high`||t.value===`xhigh`||t.value===`max`:e===`service_tier`?t.value==="default"||t.value===`fast`:t.value===`low`||t.value===`medium`||t.value===`high`:!1}}function lL(e){return Y(e)&&e.kind===`absent`?Object.keys(e).length===1:sL(e)}function uL(e){return Y(e)&&oL(e,[`owner`,`schema`,`installId`,`keyPath`,`originalValue`,`lastManagedValue`])&&e.owner===`holycodex`&&typeof e.schema==`string`&&rL(e.schema)&&rL(e.installId)&&nL(e.keyPath)&&lL(e.originalValue)&&sL(e.lastManagedValue)&&cL(e.keyPath,e.lastManagedValue)&&(e.originalValue.kind===`absent`||cL(e.keyPath,e.originalValue))}function dL(e){return!Y(e)||!oL(e,[`owner`,`schema`,`installId`,`managed`])||e.owner!==`holycodex`||!rL(e.schema)||!rL(e.installId)||!Y(e.managed)?!1:Object.entries(e.managed).every(([e,t])=>nL(e)&&uL(t)&&t.keyPath===e)}function fL(e){if(!rL(e.schema)||!rL(e.installId))throw MI(`managed runtime config metadata`,{schema:e.schema});return{owner:`holycodex`,schema:e.schema,installId:e.installId,managed:{}}}function pL(e){if(e.length===0||e.includes(`\0`)||/^[\\/]|^[A-Za-z]:[\\/]/u.test(e))return!1;let t=e.replaceAll(`\\`,`/`).split(`/`);return t.some(e=>e!==`.`)&&t.every(e=>e.length>0&&e!==`..`)}function mL(e){if(!pL(e))throw MI(`relative config path`,`[redacted]`);return e.replaceAll(`\\`,`/`).split(`/`).filter(e=>e!==`.`).join(`/`)}function hL(e,t){let n=mL(t),r=e.replaceAll(`\\`,`/`).split(`/`);r.pop();let i=[...r,...n.split(`/`)].join(`/`),a=[];for(let e of i.split(`/`))e.length!==0&&e!==`.`&&(e===`..`?a.pop():a.push(e));let o=e.replaceAll(`\\`,`/`);return`${o.startsWith(`//`)?`//`:o.startsWith(`/`)?`/`:``}${a.join(`/`)}`}function gL(e){return e===`developer_instructions`?`digest`:e.endsWith(`.config_file`)?`relative_path`:e===`suppress_unstable_features_warning`||e===`features.default_mode_request_user_input`||e===`features.multi_agent_v2`||e===`features.context_management.experimental_mode`?`boolean`:`enum`}function _L(e,t){let n=gL(e);return n===`boolean`?typeof t==`boolean`:n===`relative_path`?typeof t==`string`&&pL(t):n===`digest`?typeof t==`string`:typeof t==`string`&&iL(t)}async function vL(e,t){if(!nL(e)||!qI(t))throw MI(`managed config value`,{keyPath:e});let n=gL(e);return n===`boolean`&&typeof t==`boolean`?{kind:n,value:t}:n===`relative_path`&&typeof t==`string`&&pL(t)?{kind:n,value:mL(t)}:n===`enum`&&typeof t==`string`&&iL(t)?{kind:n,value:t}:{kind:`digest`,value:await xF(`holycodex-managed-config-value`,[vF({keyPath:e,value:t})])}}function yL(e){if(e.kind===`enum`||e.kind===`boolean`||e.kind===`relative_path`)return e.value}async function bL(e,t,n,r){if(!JI(e)||!dL(t)||!rL(r.schema)||!rL(r.installId))throw MI(`managed runtime config`,{});let i={...t.managed},a=$I(e),o=[];for(let[e,s]of Object.entries(n)){if(!nL(e)||typeof s!=`string`&&typeof s!=`boolean`)throw MI(`managed config key`,e);let n=e,c=t.managed[n],l=ZI(a,n);if(c&&(c.schema!==r.schema||c.installId!==r.installId)){o.push(n);continue}if(c&&c.owner===`holycodex`){let e=l===void 0?void 0:await vL(n,l);if(e===void 0||JSON.stringify(e)!==JSON.stringify(c.lastManagedValue)){o.push(n);continue}}let u=c?.originalValue??(l===void 0?{kind:`absent`}:await vL(n,l));if(!_L(n,s))throw MI(`managed config value`,{keyPath:n});a=eL(a,n,s),i[n]={owner:`holycodex`,schema:r.schema,installId:r.installId,keyPath:n,originalValue:u,lastManagedValue:await vL(n,s)}}let s={owner:`holycodex`,schema:r.schema,installId:r.installId,managed:i};if(!dL(s))throw MI(`managed runtime config state`,{});return{document:a,state:s,driftedKeys:o}}async function xL(e,t,n){if(!JI(e)||!dL(t))throw MI(`managed runtime config`,{});let r=$I(e),i={...t.managed},a=[],o=[],s=[];for(let[e,c]of Object.entries(t.managed)){if(!nL(e))throw MI(`managed config key`,e);let t=e;if(c.owner!==`holycodex`||c.schema!==n.schema||c.installId!==n.installId)continue;let l=ZI(r,t);if(l===void 0||JSON.stringify(await vL(t,l))!==JSON.stringify(c.lastManagedValue)){o.push(t);continue}if(c.originalValue.kind===`absent`)r=tL(r,t),a.push(t),delete i[t];else{let e=yL(c.originalValue);if(e===void 0){s.push(t),o.push(t);continue}r=eL(r,t,e),a.push(t),delete i[t]}}return{document:r,state:{...t,managed:i},restoredKeys:a,preservedKeys:o,unresolvedKeys:s}}async function SL(e,t,n){if(!nL(n)||!dL(t))throw MI(`managed config key`,n);let r=t.managed[n],i=ZI(e,n),a=i===void 0?void 0:await vL(n,i);return r?{keyPath:n,status:a!==void 0&&JSON.stringify(a)===JSON.stringify(r.lastManagedValue)?`unchanged`:`drifted`,expected:r.lastManagedValue,...a===void 0?{}:{current:a}}:a===void 0?{keyPath:n,status:`unmanaged`}:{keyPath:n,status:`unmanaged`,current:a}}var CL,wL,TL,EL,DL=v((()=>{uI(),pP(),zI(),G(e=>qI(e)),CL=G(e=>JI(e)),wL=[`model`,`model_reasoning_effort`,`service_tier`,`model_verbosity`,`developer_instructions`,`suppress_unstable_features_warning`,`features.default_mode_request_user_input`,`features.multi_agent_v2`,`features.context_management.experimental_mode`],G(e=>nL(e)),G(e=>sL(e)),G(e=>lL(e)),G(e=>uL(e)),TL=G(e=>dL(e)),EL=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u}));function OL(e){return typeof e==`number`&&Number.isFinite(e)&&e>=0}function kL(e,t,n){let r=new Set([...t,n]),i=Object.keys(e);return!Object.keys(e).some(e=>!r.has(e))&&i.length>0&&i.every(t=>OL(e[t]))}function AL(e){return!Y(e)||!TI(e)?!1:kL(e,[`inputTokens`,`cachedInputTokens`,`outputTokens`,`reasoningOutputTokens`],`totalTokens`)||kL(e,[`input_tokens`,`cached_input_tokens`,`output_tokens`,`reasoning_output_tokens`],`total_tokens`)}function jL(e){return Y(e)&&TI(e)&&typeof e.id==`string`&&/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(e.id)}function ML(e){return Y(e)&&TI(e)&&jL(e.thread)}function NL(e){return Y(e)&&TI(e)&&typeof e.id==`string`}function PL(e){return Y(e)&&TI(e)&&typeof e.threadId==`string`&&e.threadId.length>0}function FL(e){return Y(e)&&TI(e)&&typeof e.id==`string`&&e.id.length>0&&(e.usage===void 0||AL(e.usage))}function IL(e){return Y(e)&&TI(e)&&typeof e.id==`string`&&typeof e.model==`string`&&(e.supportedReasoningEfforts===void 0||Array.isArray(e.supportedReasoningEfforts)&&e.supportedReasoningEfforts.every(e=>Y(e)&&typeof e.reasoningEffort==`string`))&&(e.serviceTiers===void 0||Array.isArray(e.serviceTiers)&&e.serviceTiers.every(e=>Y(e)&&typeof e.id==`string`))&&(e.defaultServiceTier===void 0||e.defaultServiceTier===null||typeof e.defaultServiceTier==`string`)&&(e.multiAgentVersion===void 0||e.multiAgentVersion===null||e.multiAgentVersion===`disabled`||e.multiAgentVersion===`v1`||e.multiAgentVersion===`v2`)}function LL(e){return HI.some(t=>t===e)?`permissions`:VI.some(t=>t===e)?`approval`:UI.some(t=>t===e)?`elicitation`:WI.some(t=>t===e)?`dynamic_tool`:`other`}var RL,zL,BL,VL,HL,UL,WL,GL,KL,qL,JL,YL,XL,ZL,QL,$L,eR,tR,nR,rR,iR,aR,oR,sR,cR,lR,uR,dR,fR,pR,mR,hR,gR,_R,vR,yR,bR,xR,SR,CR=v((()=>{pP(),zI(),KI(),DL(),RL=K.pipe(CM(/^[A-Za-z][A-Za-z0-9_./:-]{0,127}$/u)),zL=U(K.pipe(yM(1)),Fj.pipe(pj(e=>Number.isSafeInteger(e)))),BL=W({code:Fj.pipe(pj(e=>Number.isSafeInteger(e))),message:K,data:J(II)}),VL=U(W({id:zL,result:II}),W({id:zL,error:BL})),W({id:zL,error:BL}),HL=W({method:RL,params:J(II)}),UL=W({id:zL,method:RL,params:J(II),trace:J(II)}),G(AL),WL=W({clientInfo:W({name:RI,version:RI,title:U(RI,Aj)}),capabilities:U(W({experimentalApi:q,requestAttestation:q,mcpServerOpenaiFormElicitation:J(q),optOutNotificationMethods:J(U(Vj(K),Aj)),extensions:J(LI)}),Aj)}),GL=G(e=>Y(e)&&TI(e)&&typeof e.userAgent==`string`&&typeof e.codexHome==`string`&&typeof e.platformFamily==`string`&&typeof e.platformOs==`string`),KL=W({method:H(`initialized`)}),G(jL),qL=G(e=>ML(e)||NL(e)),JL=qL,YL=qL,XL=G(PL),ZL=G(e=>Y(e)&&TI(e)&&(e.status===`notLoaded`||e.status===`notSubscribed`||e.status===`unsubscribed`)),QL=G(e=>ML(e)),$L=G(e=>{if(!Y(e)||!TI(e))return!1;let t=Array.isArray(e.data)&&e.data.every(e=>jL(e)),n=Array.isArray(e.threads)&&e.threads.every(e=>jL(e));return t&&e.threads===void 0||n&&e.data===void 0}),eR=G(e=>Y(e)&&TI(e)),tR=G(PL),nR=G(PL),rR=G(PL),iR=G(e=>Y(e)&&TI(e)),aR=G(e=>PL(e)&&(Array.isArray(e.input)&&e.input.every(e=>TI(e))||typeof e.prompt==`string`&&e.prompt.length>0)),oR=G(e=>PL(e)&&typeof e.expectedTurnId==`string`&&Array.isArray(e.input)&&e.input.every(e=>TI(e))),sR=G(e=>Y(e)&&TI(e)&&(e.turn!==void 0&&FL(e.turn)||typeof e.turnId==`string`&&e.turnId.length>0||typeof e.id==`string`&&e.id.length>0)),cR=G(e=>Y(e)&&TI(e)&&typeof e.turnId==`string`&&e.turnId.length>0),lR=G(e=>PL(e)&&typeof e.turnId==`string`&&e.turnId.length>0),uR=G(e=>Y(e)&&TI(e)),dR=G(e=>PL(e)&&(e.turn!==void 0&&FL(e.turn)||typeof e.turnId==`string`&&e.turnId.length>0)),fR=G(e=>Y(e)&&TI(e)),pR=G(e=>Y(e)&&TI(e)&&Array.isArray(e.data)&&e.data.every(e=>IL(e))),mR=LI,hR=LI,gR=W({includeLayers:J(q),cwd:J(U(K,Aj))}),_R=W({config:CL,origins:LI,layers:U(Vj(LI),Aj)}),vR=LI,yR=LI,bR=G(e=>Y(e)&&TI(e)&&(typeof e.id==`string`||typeof e.id==`number`&&Number.isSafeInteger(e.id))&&typeof e.method==`string`&&Y(e.params)&&(e.category===`approval`||e.category===`dynamic_tool`||e.category===`elicitation`||e.category===`other`||e.category===`permissions`)),xR=II,G(e=>Y(e)&&TI(e)&&typeof e.kind==`string`&&typeof e.method==`string`),SR=U(H(`stable`,`experimental`,`disabled`),q),oM({key:K,value:SR})}));function wR(e){let t=kI(e);return t.length>0?t:`server request failed`}function TR(e){return HI.some(t=>t===e)?`permission_denied`:VI.some(t=>t===e)?`approval_required`:e===`turn/interrupt`?`cancellation`:e.startsWith(`turn/`)?`turn_failed`:`server_error`}var ER,DR,OR,kR=v((()=>{zI(),KI(),CR(),ER={clientInfo:{name:`holycodex`,title:null,version:FI},capabilities:null},DR=new Set(BI),OR=class{transport;maxLineBytes;requestTimeoutMs;signal;notificationListeners=new Set;serverRequestHandlers=new Set;pending=new Map;serverRequestWork=new Set;serverRequestTasks=new Set;nextRequestId=1;readerPromise;initializePromise;transportClosePromise;initializeAttempted=!1;initialized=!1;closed=!1;constructor(e,t={}){if(this.transport=e,this.maxLineBytes=t.maxLineBytes??1048576,this.requestTimeoutMs=t.requestTimeoutMs,this.signal=t.signal,!Number.isSafeInteger(this.maxLineBytes)||this.maxLineBytes<1)throw new X(`invalid_external_data`,`The maximum line size is invalid.`);if(this.requestTimeoutMs!==void 0&&(!Number.isSafeInteger(this.requestTimeoutMs)||this.requestTimeoutMs<1))throw new X(`invalid_external_data`,`The request timeout is invalid.`);t.onNotification&&this.notificationListeners.add(t.onNotification),t.onServerRequest&&this.serverRequestHandlers.add(t.onServerRequest),this.signal?.aborted?this.close():this.signal&&this.signal.addEventListener(`abort`,()=>void this.close(),{once:!0})}get isInitialized(){return this.initialized}onNotification(e){return this.notificationListeners.add(e),()=>this.notificationListeners.delete(e)}onServerRequest(e){return this.serverRequestHandlers.add(e),()=>this.serverRequestHandlers.delete(e)}async initialize(e=ER){if(this.initializePromise)return this.initializePromise;if(this.initializeAttempted)throw new X(`invalid_external_data`,`The App Server initialize handshake was already attempted.`);this.ensureOpen();let t=NI(WL,e,`initialize parameters`);return this.initializeAttempted=!0,this.initializePromise=this.performInitialize(t),this.initializePromise}async startThread(e={}){return this.action(`thread/start`,eR,e,qL)}async resumeThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/resume`,tR,t,JL)}async readThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/read`,nR,t,QL)}async listThreads(e={}){return this.action(`thread/list`,iR,e,$L)}async forkThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/fork`,rR,t,YL)}async unsubscribeThread(e){let t=typeof e==`string`?{threadId:e}:e;return this.action(`thread/unsubscribe`,XL,t,ZL)}async startTurn(e){return this.action(`turn/start`,aR,e,sR)}async steerTurn(e){return this.action(`turn/steer`,oR,e,cR)}async interruptTurn(e,t){let n=typeof e==`string`?{threadId:e,turnId:t??``}:e;return this.action(`turn/interrupt`,lR,n,uR)}async listModels(e={}){return this.action(`model/list`,fR,e,pR)}async readModelProviderCapabilities(e={}){return this.action(`modelProvider/capabilities/read`,mR,e,hR)}async readConfig(e={}){return this.action(`config/read`,gR,e,_R)}async listPermissionProfiles(e={}){return this.action(`permissionProfile/list`,vR,e,yR)}async call(e,t={}){if(e===`initialize`){let e=await this.initialize(NI(WL,t,`initialize parameters`));return NI(II,e,`initialize result`)}let n=NI(UL,{id:1,method:e,params:t},`App Server method`);if(!DR.has(n.method))throw new X(`method_unsupported`,`Unsupported App Server method: ${e}.`,{method:e});return this.request(n.method,n.params===void 0?{}:n.params)}async close(){await this.closeWithError(new X(`closed`,`The App Server client is closed.`))}async performInitialize(e){try{let t=await this.request(`initialize`,NI(II,e,`initialize parameters`)),n=NI(GL,t,`initialize result`),r=NI(KL,GI,`initialized notification`);return await this.transport.writeLine(JSON.stringify(r)),this.initialized=!0,n}catch(e){let t=e instanceof X?e:new X(`transport_failure`,`The initialize handshake failed.`,{},{cause:e});throw await this.closeWithError(t),t}}async action(e,t,n,r){let i=NI(t,n,`${e} parameters`),a=NI(II,i,`${e} parameters`);return NI(r,await this.request(e,a),`${e} result`)}async request(e,t){if(this.ensureOpen(),e!==`initialize`&&!this.initialized)throw new X(`invalid_external_data`,`The ${e} action requires an initialized App Server client.`);this.startReader();let n=this.nextRequestId;this.nextRequestId+=1;let r=NI(UL,{id:n,method:e,params:t},`${e} request`);return new Promise((t,i)=>{let a=!1,o,s,c=e=>{a||(a=!0,this.pending.delete(n),o!==void 0&&clearTimeout(o),s?.(),i(e))};if(this.requestTimeoutMs!==void 0&&(o=setTimeout(()=>c(new X(`timeout`,`The ${e} request timed out.`,{method:e})),this.requestTimeoutMs)),this.signal){let t=()=>c(new X(`cancellation`,`The ${e} request was cancelled.`,{method:e}));this.signal.addEventListener(`abort`,t,{once:!0}),s=()=>this.signal?.removeEventListener(`abort`,t)}let l={method:e,resolve:e=>{a||(a=!0,o!==void 0&&clearTimeout(o),s?.(),t(e))},reject:c,...o===void 0?{}:{timer:o},...s===void 0?{}:{removeAbortListener:s}};this.pending.set(n,l),this.transport.writeLine(JSON.stringify(r)).catch(e=>{c(e instanceof X?e:new X(`transport_failure`,`The App Server request could not be written.`,{},{cause:e}))})})}startReader(){this.readerPromise||=this.readLoop().catch(e=>this.handleReaderFailure(e)).catch(()=>void 0)}async readLoop(){for(;!this.closed;){let e=await this.transport.readLine();if(e===null){if(!this.closed)throw new X(`transport_closed`,`The App Server transport closed.`);return}if(new TextEncoder().encode(e).byteLength>this.maxLineBytes)throw new X(`invalid_transport_line`,`An App Server line exceeded the limit.`);this.handleLine(e)}}async handleReaderFailure(e){let t=e instanceof X?e:new X(`transport_failure`,`The App Server transport failed.`,{},{cause:e});await this.closeWithError(t)}handleLine(e){let t;try{t=JSON.parse(e)}catch(e){throw new X(`invalid_transport_line`,`The App Server emitted invalid JSON.`,{},{cause:e})}let n=this.tryDecode(VL,t);if(n!==void 0){this.handleResponse(n);return}let r=this.tryDecode(UL,t);if(r!==void 0){this.handleServerRequest(r);return}let i=this.tryDecode(HL,t);if(i!==void 0){this.handleNotification(i);return}throw MI(`JSON-RPC message`,t)}tryDecode(e,t){try{return NI(e,t,`JSON-RPC message`)}catch{return}}handleResponse(e){let t=this.pending.get(e.id);if(!t)throw new X(`unexpected_response`,`The App Server returned an unknown request id.`,{id:e.id});if(this.pending.delete(e.id),`error`in e){let n=e.error.code===-32001,r=TR(t.method);t.reject(new X(r,`The App Server rejected ${t.method}: ${kI(e.error.message)}.`,{method:t.method,serverCode:e.error.code,retryable:n,...e.error.data===void 0?{}:{data:AI(e.error.data)}},{retryable:n}));return}t.resolve(e.result)}handleServerRequest(e){let t=e.params??{},n=NI(bR,{...e,params:t,category:LL(e.method)},`server request`);this.emitNotification({kind:`server_request`,method:e.method,params:t});let r=[...this.serverRequestHandlers];if(r.length===0){this.trackServerRequestTask(this.writeServerError(e.id,-32601,`No handler for ${e.method}.`));return}let i=r[0];if(i===void 0){this.trackServerRequestTask(this.writeServerError(e.id,-32601,`No handler for ${e.method}.`));return}let a={active:!0};this.serverRequestWork.add(a);let o;try{o=i(n)}catch(t){this.completeServerRequest(a,()=>this.writeServerError(e.id,-32e3,kI(String(t))));return}if(o instanceof Promise){this.trackServerRequestTask(o.then(t=>this.completeServerRequest(a,()=>this.writeValidatedServerResult(e.id,t)),t=>this.completeServerRequest(a,()=>this.writeServerError(e.id,-32e3,kI(String(t))))));return}this.completeServerRequest(a,()=>this.writeValidatedServerResult(e.id,o))}writeValidatedServerResult(e,t){try{let n=NI(xR,t,`server response`);return this.writeServerResult(e,n)}catch(t){return this.writeServerError(e,-32e3,kI(String(t)))}}completeServerRequest(e,t){if(e.active){e.active=!1,this.serverRequestWork.delete(e);try{this.trackServerRequestTask(t())}catch{}}}trackServerRequestTask(e){let t=e.catch(()=>void 0);this.serverRequestTasks.add(t),t.then(()=>this.serverRequestTasks.delete(t),()=>this.serverRequestTasks.delete(t))}async writeServerResult(e,t){let n=NI(VL,{id:e,result:t},`server response`);await this.transport.writeLine(JSON.stringify(n))}async writeServerError(e,t,n){let r=NI(VL,{id:e,error:{code:t,message:wR(n)}},`server error response`);await this.transport.writeLine(JSON.stringify(r))}handleNotification(e){let t=e.params;if(e.method===`turn/completed`){let n=NI(dR,t,`turn/completed notification`);this.emitNotification({kind:`turn_completed`,method:e.method,params:n});return}if(e.method.includes(`agent`)||e.method.includes(`subagent`)){this.emitNotification({kind:`multi_agent`,method:e.method,...t===void 0?{}:{params:t}});return}this.emitNotification({kind:`unknown`,method:e.method,metadata:jI({params:AI(t)})})}emitNotification(e){for(let t of this.notificationListeners)try{t(e)}catch{}}rejectPending(e){for(let t of this.pending.values())t.reject(e);this.pending.clear()}async closeWithError(e){if(this.transportClosePromise!==void 0){await this.transportClosePromise;return}this.closed=!0,this.rejectPending(e);for(let e of this.serverRequestWork)e.active=!1;this.serverRequestWork.clear(),this.serverRequestTasks.clear(),this.transportClosePromise=Promise.resolve().then(()=>this.transport.close()).catch(()=>void 0),await this.transportClosePromise}ensureOpen(){if(this.closed)throw new X(`closed`,`The App Server client is closed.`)}}}));function AR(e=process.env){let t=[`PATH`,`HOME`,`USER`,`CODEX_HOME`,`TMPDIR`,`TEMP`,`TMP`,`LANG`,`LC_ALL`],n={};for(let r of t){let t=e[r];t!==void 0&&t.length>0&&(n[r]=t)}return n}function jR(e=process.env){return Object.freeze(AR(e))}async function MR(e,t){let n=e.getReader(),r=[],i=0;try{for(;;){let e=await n.read();if(e.done)break;if(i+=e.value.byteLength,i>t)throw new X(`invalid_transport_line`,`A subprocess stream exceeded its limit.`);r.push(e.value)}}finally{n.releaseLock()}let a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.byteLength;return a}function NR(e,t){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch(e){throw new X(`invalid_transport_line`,`Invalid UTF-8 in ${t}.`,{},{cause:e})}}function PR(e){return kI(e.replace(/Bearer\s+[^\s]+/giu,`Bearer [redacted]`).replace(/((?:api[_-]?key|authorization|cookie|password|secret|token)\s*[:=]\s*)[^\s,;]+/giu,`$1[redacted]`),512)}var FR,IR=v((()=>{zI(),FR=class{process;stdin;stdoutReader;stderrStream;maxLineBytes;maxDiagnosticBytes;lineDecoder=new TextDecoder(`utf-8`,{fatal:!0});stderrDiagnostics=[];stdoutBuffer=new Uint8Array;stderrPromise;closed=!1;constructor(e){if(!g(e.executablePath))throw new X(`discovery_failed`,`The Codex executable path must be absolute.`);if(this.maxLineBytes=e.maxLineBytes??1048576,this.maxDiagnosticBytes=e.maxDiagnosticBytes??65536,this.maxLineBytes<1||this.maxDiagnosticBytes<1)throw new X(`invalid_external_data`,`The transport bounds are invalid.`);if(this.process=Bun.spawn([e.executablePath,`app-server`],{...e.cwd===void 0?{}:{cwd:e.cwd},env:AR(e.environment),stdin:`pipe`,stdout:`pipe`,stderr:`pipe`}),!(this.process.stdout instanceof ReadableStream)||!(this.process.stderr instanceof ReadableStream))throw new X(`transport_failure`,`The Codex App Server did not expose stdio pipes.`);if(typeof this.process.stdin==`number`||this.process.stdin===void 0)throw new X(`transport_failure`,`The Codex App Server did not expose stdin.`);this.stdin=this.process.stdin,this.stdoutReader=this.process.stdout,this.stderrStream=this.process.stderr,this.stderrPromise=this.collectStderr(),e.signal&&(e.signal.aborted?this.close():e.signal.addEventListener(`abort`,()=>void this.close(),{once:!0}))}get diagnostics(){return[...this.stderrDiagnostics]}async readLine(){if(this.closed&&this.stdoutBuffer.byteLength===0)return null;let e=this.stdoutReader.getReader();try{for(;;){let t=this.stdoutBuffer.indexOf(10);if(t>=0){if(t>this.maxLineBytes)throw await this.close(),new X(`invalid_transport_line`,`The App Server emitted an overlong line.`);let e=this.stdoutBuffer.slice(0,t);this.stdoutBuffer=this.stdoutBuffer.slice(t+1);let n=e.at(-1)===13?e.slice(0,-1):e;return this.lineDecoder.decode(n)}if(this.stdoutBuffer.byteLength>this.maxLineBytes)throw await this.close(),new X(`invalid_transport_line`,`The App Server emitted an overlong line.`);let n=await e.read();if(n.done){if(this.stdoutBuffer.byteLength===0)return null;if(this.stdoutBuffer.byteLength>this.maxLineBytes)throw await this.close(),new X(`invalid_transport_line`,`The App Server emitted an overlong line.`);let e=this.stdoutBuffer;return this.stdoutBuffer=new Uint8Array,this.lineDecoder.decode(e)}let r=new Uint8Array(this.stdoutBuffer.byteLength+n.value.byteLength);r.set(this.stdoutBuffer,0),r.set(n.value,this.stdoutBuffer.byteLength),this.stdoutBuffer=r}}catch(e){throw e instanceof X?e:new X(`transport_failure`,`The App Server stdout could not be read.`,{},{cause:e})}finally{e.releaseLock()}}async writeLine(e){if(this.closed)throw new X(`closed`,`The App Server transport is closed.`);if(new TextEncoder().encode(e).byteLength>this.maxLineBytes)throw new X(`invalid_transport_line`,`The App Server request exceeded the line limit.`);try{await this.stdin.write(`${e}\n`),await this.stdin.flush()}catch(e){throw new X(`transport_failure`,`The App Server stdin could not be written.`,{},{cause:e})}}async close(){if(!this.closed){this.closed=!0;try{await Promise.resolve(this.stdin.end())}catch{}try{this.process.kill()}catch{}await Promise.race([this.process.exited,new Promise(e=>setTimeout(()=>e(-1),1e3))]),await this.stderrPromise.catch(()=>void 0)}}async collectStderr(){try{let e=NR(await MR(this.stderrStream,this.maxDiagnosticBytes),`Codex stderr`);for(let t of e.split(/\r?\n/u).slice(0,128)){let e=PR(t);e.length>0&&this.stderrDiagnostics.push(e)}}catch{this.stderrDiagnostics.push(`[stderr unavailable]`)}}}}));async function LR(e){let t=[];if(e.executablePath!==void 0)t.push(ne(e.cwd??process.cwd(),e.executablePath));else{let n=e.pathValue??process.env.PATH??``,r=process.platform===`win32`?[`codex.exe`,`codex.cmd`,`codex`]:[`codex`];for(let e of n.split(m).filter(e=>e.length>0))for(let n of r)t.push(ne(e,n))}for(let n of t)try{let e=await d(n);if(!e.isFile()||process.platform!==`win32`&&!(e.mode&73))continue;return await s(n)}catch{if(e.executablePath!==void 0)throw new X(`discovery_failed`,`The explicit Codex executable was not found.`,{path:n})}throw new X(`discovery_failed`,`No Codex executable was found on the allowlisted PATH.`)}async function RR(e,t){let n=Bun.spawn([e,`--version`],{env:t,stdin:`ignore`,stdout:`pipe`,stderr:`pipe`});if(!(n.stdout instanceof ReadableStream)||!(n.stderr instanceof ReadableStream))throw new X(`discovery_failed`,`The Codex version command did not expose output pipes.`);try{let[e,t,r]=await VR(Promise.all([MR(n.stdout,16384),MR(n.stderr,16384),n.exited]),()=>n.kill(),`The Codex version command timed out.`),i=kI(NR(e,`Codex version output`));if(r!==0||i.length===0){let e=PR(NR(t,`Codex version diagnostics`));throw new X(`discovery_failed`,`The Codex executable did not provide a version.`,{exitCode:r,diagnostics:e})}return i}catch(e){try{n.kill()}catch{}throw e instanceof X?e:new X(`discovery_failed`,`The Codex version command failed.`,{},{cause:e})}}async function zR(e){let t=await a(e),n=await crypto.subtle.digest(`SHA-256`,t),r=VP([...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``));if(!r.ok)throw new X(`discovery_failed`,`The Codex executable digest was invalid.`);return r.value}async function BR(e={}){let t=await LR(e),n=AR(e.environment),r=e.versionRunner?kI(await e.versionRunner(t,n)):await RR(t,n);if(r.length===0)throw new X(`discovery_failed`,`The Codex version output was empty.`);return{path:t,version:r,sha256:await zR(t)}}async function VR(e,t,n){let r;try{return await Promise.race([e,new Promise((e,i)=>{r=setTimeout(()=>{try{t()}catch{}i(new X(`timeout`,n))},HR)})])}finally{r!==void 0&&clearTimeout(r)}}var HR,UR=v((()=>{uI(),pP(),zI(),IR(),HR=3e4,W({exitCode:Fj.pipe(pj(e=>Number.isSafeInteger(e))),stdout:K.pipe(_M(1048576)),stderr:K.pipe(_M(1048576))})})),WR,GR,KR,qR,JR=v((()=>{uI(),pP(),zI(),WR=`packages/codex/generated`,GR=/^codex-cli \d+\.\d+\.\d+$/u,KR=/^codex-app-server-\d+\.\d+\.\d+$/u,qR=K.pipe(CM(/^[a-f0-9]{64}$/u)),W({schema_version:H(`holycodex-generated-v2`),artifact_root:H(WR),codex_cli_version:K.pipe(CM(GR)),codex_cli_digest:qR,protocol_epoch:K.pipe(CM(KR)),generator:W({command:sj(H(`app-server`),H(`generate-ts`)),supported_surface:H(`codex app-server generators`)}),typescript_root:H(`typescript`),files:W({count:Fj.pipe(QM(),sN()),digest:qR})}),W({path:K.pipe(yM(1)),size:Fj.pipe(QM(),sN()),sha256:qR})})),YR=v((()=>{pP(),DL(),W({owner:H(`holycodex`),schema:K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),installId:K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u))})}));async function XR(e){let t=uz(e.selectedPluginIds);if(t.length===0)return;if(pz(e.timeoutMs,e.pollIntervalMs),e.signal?.aborted)throw new Lz(`cancelled`,`Official Codex marketplace bootstrap was cancelled.`);let n=e.readSnapshot??(t=>iz(t,e.selectedPluginIds)),r=await n(e.codexHome);if(r!==void 0&&dz(r,t))return r;let i=e.initializeRuntime??(()=>fz(e)),a,o;try{a=await i()}catch(e){o=Z(`marketplace_unavailable`,`Codex runtime initialization could not start the official marketplace sync. Check that Codex is available and its network/policy settings permit the official marketplace.`,e)}if(o===void 0)try{let r=e.timeoutMs??kz,i=e.pollIntervalMs??Az,a=Date.now();for(;Date.now()-a<=r;){if(e.signal?.aborted)throw new Lz(`cancelled`,`Official Codex marketplace bootstrap was cancelled.`);let o=await n(e.codexHome);if(o!==void 0&&dz(o,t))return o;let s=r-(Date.now()-a);if(s<=0)break;await(e.sleep??_z)(Math.min(i,s))}o=Z(`marketplace_timeout`,`The official Codex marketplace did not become ready before the bounded wait expired. Check network access and Codex marketplace policy, then retry.`)}catch(e){if(e instanceof Lz&&e.code===`cancelled`)throw e;o=e instanceof Lz?e:Z(`marketplace_unavailable`,`The official Codex marketplace sync failed before its bounded wait completed.`,e)}finally{await a?.()}if(e.gitFallback!==!1)try{return await ZR({codexHome:e.codexHome,selectedPluginIds:e.selectedPluginIds,...e.environment===void 0?{}:{environment:e.environment},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.signal===void 0?{}:{signal:e.signal},...e.gitFallback===void 0?{}:e.gitFallback})}catch(e){throw e instanceof Lz?e:Z(`marketplace_unavailable`,`The official marketplace could not be populated after runtime startup (${o?.code??`unavailable`}). Check network access and retry.`,e)}throw o??Z(`marketplace_timeout`,`The official Codex marketplace did not become ready before the bounded wait expired.`)}async function ZR(e){let n=uz(e.selectedPluginIds);if(n.length===0)throw Z(`marketplace_invalid`,`The official marketplace fallback requires at least one selected provider plugin.`);if(pz(e.timeoutMs,void 0),!g(e.codexHome))throw Z(`marketplace_invalid`,`The Codex home for official marketplace fallback must be absolute.`);if(e.signal?.aborted)throw new Lz(`cancelled`,`Official Codex marketplace fallback was cancelled.`);let i=AR(e.environment),a=e.gitRunner??Cz(`git`,{environment:i,...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}),o=e.timeoutMs??kz,s;try{s=await QR(a,o,e.signal)}catch(e){throw e instanceof Lz?e:Z(`marketplace_unavailable`,`The official Codex marketplace remote HEAD could not be resolved. Check network access and retry.`,e)}let u=_(e.codexHome,`plugins`),d=_(u,Oz[1]);if(await ez(u,e.codexHome),await t(d).catch(e=>{if(!hz(e))throw Z(`marketplace_invalid`,`The reserved official marketplace path could not be inspected safely.`,e)})!==void 0)throw Z(`marketplace_invalid`,`The reserved official marketplace path appeared during bootstrap; refusing to overwrite it.`);let f=await r(_(u,`.openai-plugins-stage-`));try{if(await mz(e.codexHome,f),e.cloneSnapshot!==void 0)try{await e.cloneSnapshot(Dz,f)}catch(e){throw gz(e)?Z(`marketplace_invalid`,`The staged official marketplace could not be created as a safe file tree.`,e):e}else{let t=await a.run([`clone`,`--depth=1`,`--no-tags`,Dz,f],{...e.signal===void 0?{}:{signal:e.signal},timeoutMs:o});if(t.exitCode!==0)throw Z(`marketplace_unavailable`,`The official Codex marketplace could not be downloaded. Check network access and retry.`,t.stderr)}await rz(f);let r=await az(f,e.codexHome,n);if(r===void 0||!dz(r,n))throw Z(`marketplace_invalid`,`The downloaded official marketplace is missing the selected plugin entries or manifest.`);if(await $R(a,f,o,e.signal)!==s)throw Z(`marketplace_invalid`,`The downloaded official marketplace did not match the verified remote HEAD.`);if(await t(d).catch(e=>{if(!hz(e))throw Z(`marketplace_invalid`,`The reserved official marketplace path could not be checked before publication.`,e)})!==void 0)throw Z(`marketplace_invalid`,`The reserved official marketplace path appeared during staging; refusing to overwrite it.`);await c(f,d);let i=await iz(e.codexHome,e.selectedPluginIds);if(i===void 0||!dz(i,n))throw Z(`marketplace_invalid`,`The published official marketplace failed validation.`);return i}catch(e){throw e instanceof Lz?e:Z(`marketplace_unavailable`,`The official Codex marketplace fallback failed safely. Check network access and retry.`,e)}finally{await l(f,{recursive:!0,force:!0}).catch(()=>void 0)}}async function QR(e,t,n){let r=await e.run([`ls-remote`,Dz,`HEAD`],{...n===void 0?{}:{signal:n},timeoutMs:t});if(r.exitCode!==0)throw Z(`marketplace_unavailable`,`The official Codex marketplace remote HEAD could not be resolved. Check network access and retry.`,r.stderr);let i=r.stdout.trim().split(/\r?\n/u).map(e=>e.trim()).filter(e=>e.length>0),a=i.length===1?/^([0-9a-f]{40}|[0-9a-f]{64})\s+HEAD$/iu.exec(i[0]??``):null;if(a?.[1]===void 0)throw Z(`marketplace_invalid`,`The official Codex marketplace remote HEAD response was malformed.`);return a[1].toLowerCase()}async function $R(e,t,n,r){let i=await e.run([`rev-parse`,`HEAD`],{timeoutMs:n,cwd:t,...r===void 0?{}:{signal:r}}),a=i.stdout.trim().toLowerCase();if(i.exitCode!==0||!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(a))throw Z(`marketplace_invalid`,`The downloaded official marketplace checkout did not expose a valid HEAD.`,i.stderr);return a}async function ez(e,t){await tz(t,e),await n(e,{recursive:!0}),await tz(t,e)}async function tz(e,n){let r=ne(e),i=ne(n);for(;;){if((await t(i).catch(e=>{if(!hz(e))throw e}))?.isSymbolicLink())throw Z(`marketplace_invalid`,`The official marketplace path cannot contain symlinks.`);if(i===r)return;let e=h(i);if(e===i||e!==r&&!nz(r,e))throw Z(`marketplace_invalid`,`The official marketplace path escaped CODEX_HOME.`);i=e}}function nz(e,t){let n=te(e,t);return n.length>0&&n!==`..`&&!n.startsWith(`..${re}`)&&!g(n)}async function rz(e){let n=await t(e);if(n.isSymbolicLink())throw Z(`marketplace_invalid`,`The official marketplace snapshot cannot contain symlinks.`);if(!n.isDirectory())throw Z(`marketplace_invalid`,`The official marketplace snapshot is not a directory.`);let r=await o(e,{withFileTypes:!0});for(let n of r){let r=_(e,n.name),i=await t(r);if(i.isSymbolicLink())throw Z(`marketplace_invalid`,`The official marketplace snapshot cannot contain symlinks.`);i.isDirectory()&&await rz(r)}}async function iz(e,t=[]){return await az(_(e,...Oz),e,uz(t))}async function az(e,n,r=[]){n!==void 0&&await tz(n,e);let i=await t(e).catch(e=>{if(!hz(e))throw Z(`marketplace_invalid`,`The reserved openai-curated marketplace path could not be read safely.`,e)});if(i===void 0)return;if(i.isSymbolicLink()||!i.isDirectory())throw Z(`marketplace_invalid`,`The reserved openai-curated marketplace path is not a real directory.`);n===void 0?await rz(e):await mz(n,e),n!==void 0&&await rz(e);let o=await s(e),c=[_(o,`.agents`,`plugins`,`marketplace.json`),_(o,`.codex-plugin`,`marketplace.json`),_(o,`marketplace.json`)],l,u;for(let e of c){let n=await t(e).catch(e=>{if(!hz(e))throw Z(`marketplace_invalid`,`The official marketplace manifest could not be read safely.`,e)});if(n!==void 0){if(n.isSymbolicLink()||!n.isFile())throw Z(`marketplace_invalid`,`The official marketplace manifest is not a regular file.`);if(await mz(o,e),l!==void 0)throw Z(`marketplace_invalid`,`The reserved official marketplace contains more than one manifest.`);l=e;try{u=new TextDecoder(`utf-8`,{fatal:!0}).decode(await a(e))}catch(e){throw Z(`marketplace_invalid`,`The official marketplace manifest is not valid UTF-8.`,e)}}}if(l===void 0||u===void 0)return;let d;try{d=JSON.parse(u)}catch(e){throw Z(`marketplace_invalid`,`The official marketplace manifest is not valid JSON.`,e)}return oz(d,o,l,r)}function oz(e,t=`${Oz.join(`/`)}`,n=`${t}/marketplace.json`,r=[]){if(!Y(e)||e.name!==`openai-curated`)throw Z(`marketplace_invalid`,`The reserved official marketplace manifest has an unexpected name.`);sz(e);let i=e.plugins;if(!Array.isArray(i)||i.length===0)throw Z(`marketplace_invalid`,`The official marketplace manifest has no plugin entries.`);let a=[],o=new Set;for(let e of i){if(!Y(e)||typeof e.name!=`string`){if(r.length>0)continue;throw Z(`marketplace_invalid`,`The official marketplace contains a malformed plugin entry.`)}let t=e.name;if(!/^[a-z][a-z0-9._-]{1,63}$/u.test(t)){if(r.length>0)continue;throw Z(`marketplace_invalid`,`The official marketplace contains an invalid plugin name.`)}if(o.has(t)){if(r.length>0&&!r.includes(t))continue;throw Z(`marketplace_invalid`,`The official marketplace contains a duplicate plugin name.`)}if(o.add(t),r.length>0&&!r.includes(t))continue;let n=cz(e);if(!lz(n))throw Z(`marketplace_invalid`,`The official marketplace source for ${t} is unsafe.`);a.push({name:t,source:n})}if(r.some(e=>!a.some(t=>t.name===e)))throw Z(`marketplace_invalid`,`The official marketplace is missing a selected plugin entry.`);return{name:Ez,source:Dz,rootPath:t,manifestPath:n,plugins:a}}function sz(e){for(let t of[`source`,`repository`,`repo`,`url`]){let n=e[t];if(n!==void 0&&(typeof n==`string`?n:Y(n)&&typeof n.url==`string`?n.url:void 0)!==`https://github.com/openai/plugins.git`)throw Z(`marketplace_invalid`,`The reserved official marketplace source is not the approved OpenAI repository.`)}}function cz(e){let t=e.source;if(typeof t==`string`)return t;if(Y(t)&&typeof t.path==`string`)return t.path;if(typeof e.path==`string`)return e.path}function lz(e){if(e===void 0||e.length===0||g(e)||/^[A-Za-z]:[\\/]/u.test(e))return!1;let t=e.replaceAll(`\\`,`/`);return t.startsWith(`/`)||/^[A-Za-z][A-Za-z0-9+.-]*:/u.test(t)?!1:t.split(`/`).every(e=>e.length===0||e===`.`||e!==`..`)}function uz(e){let t=[],n=new Set;for(let r of e){let e=r.lastIndexOf(`@`);if(e<1)continue;let i=r.slice(e+1);if(i!==`openai-curated`&&i!==`openai-curated-remote`)continue;let a=r.slice(0,e);if(!/^[a-z][a-z0-9._-]{1,63}$/u.test(a))throw Z(`marketplace_invalid`,`A selected official marketplace plugin id is invalid.`);yz(a)&&(n.has(a)||(n.add(a),t.push(a)))}return t}function dz(e,t){return t.every(t=>{let n=e.plugins.find(e=>e.name===t);return n!==void 0&&n.source.replaceAll(`\\`,`/`).replace(/\/+$/u,``).split(`/`).at(-1)===t})}async function fz(e){let t=AR(e.environment),n;try{n=new FR({executablePath:e.executablePath,environment:t,...e.signal===void 0?{}:{signal:e.signal}});let r=new OR(n,{requestTimeoutMs:Math.min(e.timeoutMs??kz,1e4),...e.signal===void 0?{}:{signal:e.signal}});return await r.initialize(),async()=>{await r.close()}}catch(e){throw await n?.close().catch(()=>void 0),e}}function pz(e,t){if(e!==void 0&&(!Number.isSafeInteger(e)||e<1||e>3e5))throw Z(`marketplace_invalid`,`The official marketplace timeout is invalid.`);if(t!==void 0&&(!Number.isSafeInteger(t)||t<0||t>6e4))throw Z(`marketplace_invalid`,`The official marketplace poll interval is invalid.`)}async function mz(e,n){let r=await s(e),i=await s(n),a=te(r,i);if(a===``||a===`..`||a.startsWith(`..${re}`))throw Z(`marketplace_invalid`,`The reserved official marketplace is outside CODEX_HOME.`);let o=ne(e),c=ne(n);for(;;){if((await t(c)).isSymbolicLink())throw Z(`marketplace_invalid`,`The reserved official marketplace path cannot contain symlinks.`);if(c===o)break;let e=h(c);if(e===c)throw Z(`marketplace_invalid`,`The reserved official marketplace path is outside CODEX_HOME.`);c=e}}function hz(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}function gz(e){return typeof e==`object`&&!!e&&`code`in e&&(e.code===`EPERM`||e.code===`EACCES`)}async function _z(e){await new Promise(t=>setTimeout(t,e))}function Z(e,t,n){return new Lz(e,t,n instanceof Error?{cause:PR(n.message)}:{})}function vz(e,t){let n=vP(t);if(n===void 0||n!==t)return;let r=[...e.installed,...e.available].flatMap(e=>{let t=_P(e.pluginId,e.marketplaceName);return t?.canonicalPluginId===n?[{identity:t,entry:e}]:[]});return r.find(e=>e.entry.pluginId===n&&e.entry.installed)??r.find(e=>e.entry.installed)??r.find(e=>e.entry.pluginId===n)??r[0]}function yz(e){return TP.includes(e)}function bz(e){return PI(Iz,e)?OI(NI(Iz,e,`live official plugin list`)):DI(MI(`live official plugin list`,e))}function xz(e){let t=e.runner??Cz(e.executable,{environment:e.environment??AR(),...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.stdoutLimit===void 0?{}:{stdoutLimit:e.stdoutLimit},...e.stderrLimit===void 0?{}:{stderrLimit:e.stderrLimit}}),n=async()=>{let e=await t.run([`plugin`,`list`,`--json`]);if(e.exitCode!==0)throw Sz(`list`,e);let n;try{n=JSON.parse(e.stdout)}catch{throw new Lz(`command_failed`,`Codex returned invalid plugin data.`)}let r=bz(n);if(!r.ok)throw new Lz(`command_failed`,`Codex returned an invalid official plugin list.`);return r.value};return{list:n,ensureOfficialMarketplace:async t=>{if(e.codexHome===void 0)throw new Lz(`marketplace_unavailable`,`Codex home is unavailable; the official marketplace cannot be bootstrapped safely.`);await XR({codexHome:e.codexHome,executablePath:e.executable,selectedPluginIds:t,...e.environment===void 0?{}:{environment:e.environment},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.officialMarketplaceFallback===void 0?{}:{gitFallback:e.officialMarketplaceFallback}})},addMarketplace:async(e,n)=>{let r=NI(Pz,e,`plugin marketplace source`);if(r===`openai-curated`||r===`https://github.com/openai/plugins.git`)throw new Lz(`marketplace_invalid`,`The reserved openai-curated marketplace must be populated by Codex runtime startup; it cannot be added manually.`);let i=await t.run([`plugin`,`marketplace`,`add`,r],n===void 0?void 0:{signal:n});if(i.exitCode!==0&&!/already (?:exists|added)/iu.test(i.stderr))throw Sz(`marketplace add`,i,r)},add:async(e,r)=>{let i=NI(Pz,e,`official plugin id`),a=await t.run([`plugin`,`add`,i,`--json`],r===void 0?void 0:{signal:r});if(a.exitCode!==0)throw Sz(`add`,a,i);let o=await n(),s=vz(o,i),c=vP(i),l=[...o.installed,...o.available].filter(e=>e.pluginId===i&&(c===void 0||e.marketplaceName==null)),u=s?.entry??l.find(e=>e.installed)??l[0];if(!u)throw new Lz(`readback_mismatch`,`Codex did not report ${i} after installation.`,{plugin_id:i});if(!u.installed)throw new Lz(`plugin_missing`,`Codex reported ${i} as unavailable after installation.`,{plugin_id:i});if(!u.enabled)throw new Lz(`plugin_disabled`,`Codex installed ${i} but it is disabled; enable it in Codex and retry.`,{plugin_id:i})},remove:async(e,r)=>{let i=NI(Pz,e,`official plugin id`),a=i;if(vP(i)===i){let e=vz(await n(),i);e?.entry.installed&&(a=e.entry.pluginId)}let o=await t.run([`plugin`,`remove`,a,`--json`],r===void 0?void 0:{signal:r});if(o.exitCode!==0&&!/not (?:installed|found)|missing/iu.test(o.stderr))throw Sz(`remove`,o,a);let s=await n(),c=[...s.installed,...s.available].find(e=>e.pluginId===a);if(c?.installed)throw new Lz(`readback_mismatch`,`Codex still reports ${i} after removal.`,{plugin_id:i,observed_plugin_id:c.pluginId})}}}function Sz(e,t,n){let r=PR(t.stderr).trim().slice(0,512),i=r.length>0?`: ${r}`:``;return new Lz(`command_failed`,`Codex plugin ${e} failed${n===void 0?``:` for ${n}`}${i}`,{exit_code:t.exitCode})}function Cz(e,t){let n=t.timeoutMs??3e4,r=t.stdoutLimit??131072,i=t.stderrLimit??16384;return{run:(a,o)=>wz(e,a,{...t.environment===void 0?{}:{environment:t.environment},timeoutMs:o?.timeoutMs??n,stdoutLimit:r,stderrLimit:i,...o?.cwd===void 0?{}:{cwd:o.cwd},...o?.signal===void 0?{}:{signal:o.signal}})}}async function wz(e,t,n){if(n.signal?.aborted)throw new Lz(`cancelled`,`The Codex plugin command was cancelled.`);let r=ae(e,[...t],{env:n.environment===void 0?void 0:{...n.environment},...n.cwd===void 0?{}:{cwd:n.cwd},stdio:[`ignore`,`pipe`,`pipe`],windowsHide:!0}),i=Tz(r.stdout,n.stdoutLimit),a=Tz(r.stderr,n.stderrLimit),o=new Promise((e,t)=>{r.once(`error`,t),r.once(`close`,t=>e(t??-1))}),s,c,l=new Promise((e,t)=>{c=()=>{try{r.kill()}catch{}t(new Lz(`cancelled`,`The Codex plugin command was cancelled.`))},n.signal?.addEventListener(`abort`,c,{once:!0})}),u=new Promise((e,t)=>{s=setTimeout(()=>{try{r.kill()}catch{}t(new Lz(`timeout`,`The Codex plugin command timed out.`))},n.timeoutMs)});try{let[e,t,n]=await Promise.race([Promise.all([i,a,o]),l,u]);return{stdout:e,stderr:t,exitCode:n}}catch(e){try{r.kill()}catch{}throw e instanceof Lz?e:new Lz(`command_failed`,`The Codex plugin command failed.`)}finally{s!==void 0&&clearTimeout(s),c!==void 0&&n.signal?.removeEventListener(`abort`,c)}}function Tz(e,t){return e===null?Promise.reject(new Lz(`command_failed`,`Codex plugin command output is unavailable.`)):new Promise((n,r)=>{let i=[],a=0;e.on(`data`,e=>{let n=typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:void 0;if(n===void 0){r(new Lz(`command_failed`,`Codex plugin output was invalid.`));return}if(a+=n.byteLength,a>t){r(new Lz(`output_limit`,`Codex plugin output exceeded its limit.`));return}i.push(n)}),e.once(`end`,()=>{let e=new Uint8Array(a),t=0;for(let n of i)e.set(n,t),t+=n.byteLength;try{n(new TextDecoder(`utf-8`,{fatal:!0}).decode(e))}catch(e){r(e)}}),e.once(`error`,e=>r(e))})}var Ez,Dz,Oz,kz,Az,jz,Mz,Nz,Pz,Fz,Iz,Lz,Rz=v((()=>{uI(),pP(),kR(),zI(),IR(),Ez=`openai-curated`,Dz=`https://github.com/openai/plugins.git`,Oz=[`plugins`,`openai-plugins`],kz=3e4,Az=100,jz=K.pipe(CM(/^[a-z][a-z0-9._-]{1,63}$/u)),Mz=K.pipe(CM(/^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$/u)),Nz=Vj(K),Pz=K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u)),W({name:jz,version:Mz,description:RI,author:J(II),license:J(RI),homepage:J(RI),repository:J(RI),keywords:J(Nz),skills:J(Nz),commands:J(Nz),hooks:J(Nz),assets:J(Nz),official:J(q)}),W({id:jz,selected:H(!0)}),Fz=W({pluginId:Pz,installed:q,enabled:q,name:J(U(K,Aj)),marketplaceName:J(U(K,Aj)),version:J(U(K,Aj))},oM({key:K,value:Mj})),Iz=W({installed:Vj(Fz),available:Vj(Fz)}),Lz=class extends Error{code;details;constructor(e,t,n={}){super(t),this.name=`OfficialPluginAdapterError`,this.code=e,this.details=n}}})),zz=v((()=>{zI(),KI(),CR(),kR(),IR(),UR(),JR(),YR(),DL(),Rz()}));function Bz(e){if(!Vz(e))throw Error(`The value is not JSON serializable.`);return _F(e),e}function Vz(e,t=new Set){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;t.add(e);try{return Array.isArray(e)?e.every(e=>Vz(e,t)):Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>Vz(e,t))}finally{t.delete(e)}}var Hz=v((()=>{uI()}));function Uz(e,t){let n=mP(e,t);return tr(n)?n.right:void 0}function Wz(e){return Uz(Gz,e)!==void 0}var Gz,Kz,qz,Jz,Yz,Xz,Zz,Qz,$z,eB,tB,nB,rB,iB,aB,oB,sB,cB,lB,uB,dB,fB,pB=v((()=>{zz(),uI(),lr(),pP(),Hz(),Gz=G(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Vz(e)),G(Vz),Kz=K.pipe(CM(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/u)),qz=K.pipe(CM(/^[0-9a-f]{64}$/u)),Jz=K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),Yz=K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,255}$/u)),Xz=K.pipe(pj(e=>!Number.isNaN(Date.parse(e)))),Zz=W({path:K.pipe(CM(/^[A-Za-z0-9][A-Za-z0-9._/-]{0,255}$/u)),digest:qz}),Qz=W({computer_use:q,work:q,frontend:q,security:q,coding:H(!0)}),$z=W({computer_use:J(q),work:J(q),frontend:J(q),security:J(q)}),eB=W({plan:J(eF),tier:J(nF),optional:J($z),officialPlugins:J(Vj(Yz))}),tB=W({selected:q,status:H(`disabled`,`pending`,`healthy`,`missing`,`provider_disabled`,`uncertain`,`unavailable`),plugin_ids:Vj(Yz),reason:J(K)}),nB=W({computer_use:tB,work:tB,frontend:tB,security:tB}),rB=W({presence:H(`absent`,`present`),digest:qz,safe_value:J(U(W({kind:H(`boolean`),value:q}),W({kind:H(`marketplace`),source_type:H(`git`),source:H(`https://github.com/davidbasilefilho/holycodex.git`)})))}),iB=W({plugin_id:H(`holycodex@holycodex`),before:W({preference:rB,marketplace:rB}),after:W({preference:rB,marketplace:rB})}),aB=W({presence:H(`absent`,`present`),digest:qz,safe_value:J(W({kind:H(`boolean`),value:q}))}),oB=W({plugin_id:Yz,before:aB,after:aB}),sB={owner:H(`holycodex`),schema_epoch:H(pe),install_id:Jz,version:Kz,digest:qz,plan:eF,tier:nF,optional_selections:Qz,explicit_optional_selections:$z,official_plugins:J(Vj(Yz)),capability_state:J(nB),managed_artifacts:Vj(Zz),installed_at:Xz,status:J(H(`active`)),step:J(H(`active`)),managed_config:J(TL),plugin_snapshot:J(Vj(W({plugin_id:Yz,status:H(`installed`,`available`,`missing`,`disabled`,`uncertain`,`unknown`)}))),plugin_config:J(iB),provider_config:J(Vj(oB)),owned_plugins:J(Vj(Yz))},cB=W(sB),lB=W({...sB,plan:U(eF,H(`Go`))}),uB=H(`preparing`,`conflicted`),dB=H(`validated`,`plugins_snapshotted`,`roles_prepared`,`plugins_installed`,`config_published`,`verified`,`conflicted`),fB=W({...cB.fields,status:uB,step:dB})}));function mB(e={},t=process.env){let n=se(),r=hB(e.paths?.codexHome??t.CODEX_HOME??_(n,`.codex`),`CODEX_HOME`),i=_(r,CB);return{codexHome:r,stateRoot:i,activeRecord:_(i,wB),preparingRecord:_(i,TB),conflictedRecord:_(i,EB),roleRoot:_(i,`agents`),configFile:_(r,`config.toml`)}}function hB(e,t,n=process.platform===`win32`?`win32`:`posix`){if(typeof e!=`string`||gB(e))throw new OB(`invalid_path`,`${t} contains invalid characters.`);let r=n===`win32`?ie:ee,i=xB(e,n);if(typeof i!=`string`||i.length===0||!r.isAbsolute(i))throw new OB(`invalid_path`,`${t} must be an absolute path.`);let a=r.normalize(i);if(a.split(n===`win32`?`\\`:re).filter(e=>e.length>0).length===0||a===r.dirname(a))throw new OB(`broad_path`,`${t} is too broad.`);if(i.split(/[\\/]/u).some(e=>e===`..`))throw new OB(`invalid_path`,`${t} cannot contain traversal.`);return r.resolve(a)}function gB(e){for(let t of e){let e=t.codePointAt(0)??0;if(e<=31||e===127)return!0}return!1}async function _B(e){hB(e,`owned path`),await vB(e),await n(e,{recursive:!0}),await vB(e)}async function vB(e){let n=ne(e);for(;;){try{if((await t(n)).isSymbolicLink())throw new OB(`path_symlink`,`A managed path cannot contain a symlink.`)}catch(e){if(e instanceof OB||!SB(e,`ENOENT`))throw e}let e=h(n);if(e===n)break;n=e}}async function yB(e){await vB(e)}function bB(e,t,n=process.platform===`win32`?`win32`:`posix`){let r=n===`win32`?ie:ee,i=r.resolve(xB(e,n)),a=r.resolve(xB(t,n)),o=r.relative(i,a);return o.length>0&&!o.startsWith(`..${n===`win32`?`\\`:re}`)&&o!==`..`&&!r.isAbsolute(o)}function xB(e,t){return t===`win32`&&/^\/[A-Za-z](?:\/|$)/u.test(e)?`${e[1]?.toUpperCase()??``}:${e.slice(2).replaceAll(`/`,`\\`)}`:e}function SB(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}var CB,wB,TB,EB,DB,OB,kB=v((()=>{uI(),CB=`holycodex`,wB=`active.json`,TB=`preparing.json`,EB=`conflicted.json`,DB=pe,OB=class extends Error{code;constructor(e,t){super(t),this.name=`PathBoundaryError`,this.code=e}}}));async function AB(e){let t;try{t=await i(e,`r`),await t.sync()}catch(e){if(!LB(e))throw e}finally{await t?.close().catch(()=>void 0)}}async function jB(e){await AB(e).catch(e=>{if(!LB(e))throw e})}async function MB(e,t){await NB(e,`${_F(t)}\n`)}async function NB(e,t){let n=h(e);await _B(n),await vB(e);let r=`${e}.tmp-${process.pid}-${crypto.randomUUID()}`;try{await p(r,t,{encoding:`utf8`,mode:384}),await AB(r),await c(r,e),await jB(n)}catch(e){throw await f(r).catch(()=>void 0),e}}async function PB(e,n){let r=await t(e);if(!r.isFile()||r.isSymbolicLink())throw new zB(`state_corrupt`,`A persisted file is not a regular file.`);let i;try{i=JSON.parse(await a(e,`utf8`))}catch(e){throw new zB(`state_corrupt`,`A persisted file is not valid JSON.`,e)}let o=Uz(n,i);if(o===void 0)throw new zB(`state_corrupt`,`A persisted file failed schema validation.`);return o}async function FB(e){try{let n=await t(e);if(!n.isFile()||n.isSymbolicLink())throw new zB(`state_corrupt`,`A persisted file is not a regular file.`);return await a(e,`utf8`)}catch(e){if(SB(e,`ENOENT`))return;throw e}}async function IB(e,t){try{return await PB(e,t)}catch(e){if(SB(e,`ENOENT`))return;throw e}}function LB(e){return typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?RB.has(e.code)||process.platform===`win32`&&e.code===`EPERM`:!1}var RB,zB,BB=v((()=>{uI(),kB(),pB(),RB=new Set([`EBADF`,`EINVAL`,`ENOSYS`,`ENOTSUP`,`EISDIR`]),zB=class extends Error{code;causeValue;constructor(e,t,n){super(t),this.name=`StorageError`,this.code=e,this.causeValue=n}}}));async function VB(e=JB){let t=JSON.parse(await a(e,`utf8`)),n=Uz(qB,t);if(n===void 0)throw new YB(`manifest_invalid`,`The public package manifest is invalid.`);return n}async function HB(e=JB){return(await VB(e)).version}async function UB(e=JB){return(await HB(e)).split(`-`,1)[0]??``}async function WB(e,t,n=JB){let r=await VB(n),i=await UB(n),a=GB(e,i);return t||await MB(n,{...r,version:a}),{previous:i,next:a}}function GB(e,t){if(e!==`patch`&&e!==`minor`){if(Uz(Kz,e)===void 0)throw new YB(`version_invalid`,`The version target is invalid.`);return e}let n=t.split(`.`),r=Number(n[1]),i=Number(n[2]);return e===`minor`?`0.${r+1}.0`:`0.${r}.${i+1}`}var KB,qB,JB,YB,XB=v((()=>{pP(),pB(),BB(),KB=K.pipe(CM(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-dev\.[1-9]\d*\.[1-9]\d*)?$/u)),qB=G(e=>Wz(e)&&e.name===`holycodex`&&Uz(KB,e.version)!==void 0),JB=ne(h(oe(import.meta.url)),`../package.json`),YB=class extends Error{code;constructor(e,t){super(t),this.name=`ManifestError`,this.code=e}}}));function ZB(e,t=`standard`){let n=eI(e);return n.ok?n.value.routes.map(e=>{let n={role:e.role,task:e.task};return{name:ZP(n),rolePolicy:rF.find(t=>t.role===e.role),description:$P(n),taskInstruction:QP(n),model:`gpt-5.6-luna`,effort:e.effort,serviceTier:t===`standard`?`default`:`fast`}}):[]}function QB(e,t=`standard`){let n=eI(e);if(!n.ok)throw Error(`Unknown plan.`);return{name:`root`,description:`Root-directed HolyCodex control agent.`,model:n.value.root.model===`Terra`?`gpt-5.6-terra`:`gpt-5.6-sol`,effort:n.value.root.effort,serviceTier:t===`fast-all`?`fast`:`default`}}function $B(e=!1){let t=[`You are the HolyCodex Root orchestrator.`,`Own user intent and scope; architecture, product, policy, and material choices; integration; external state and effects; Git/VCS; contradictory-evidence resolution; and final readiness.`,`Proceed autonomously with safe local inspection, implementation, and proportional verification inside approved scope. Use request_user_input for genuinely required information or approval, including material scope or product choices and destructive, remote, or externally consequential effects.`,`Delegate substantive specialist work when it has a bounded scope and observable completion. Apply writing-for-agents before dispatch; keep routine Root-owned inspection, synthesis, and coordination local.`,`Inspect returned evidence before integration. Use planning and review gates when architecture, scope, coordination, risk, or material choices justify them, including an adversarial Reviewer.code fixed-point gate for substantive implementation where appropriate.`];return e&&t.push(`Interactive GUI, browser, and Computer Use execution is Root-only and must not be delegated.`),t.join(`
82
+ `)}async function eV(e,t,n=[],r=`standard`){let i=_(e,`holycodex`,`agents`),a=[],o=[],s=ZB(t,r).map(e=>({path:_(i,`${e.name}.toml`),contents:rV(e)})),c=new Map(n.map(t=>[_(e,t.path),t])),l=new Map;for(let e of s){let t=await cV(e.path);l.set(e.path,t);let n=c.get(e.path);if(t!==void 0&&n===void 0&&t!==e.contents)throw Error(`A pre-existing HolyCodex role file is not owned by this installation: ${e.path}`)}let u=[];try{for(let t of s){let n=l.get(t.path),r=c.get(t.path);if(n!==void 0&&r!==void 0&&await uV(n)!==r.digest&&n!==t.contents){a.push(t.path),u.push({path:te(e,t.path).replaceAll(`\\`,`/`),digest:r.digest});continue}(n===void 0||n!==t.contents)&&(await NB(t.path,t.contents),o.push({path:t.path,previous:n,installedDigest:await uV(t.contents)})),u.push({path:te(e,t.path).replaceAll(`\\`,`/`),digest:await uV(t.contents)})}let t=_(e,`agents`,`root.toml`),r=await cV(t),i=await sV(t);i===`preserved`&&a.push(t),i===`removed`&&r!==void 0&&o.push({path:t,previous:r,installedDigest:void 0});for(let t of n){let n=_(e,t.path);if(!s.some(e=>e.path===n)){if(!oV(e,n,t.path)){a.push(n);continue}let r=await lV(n,t.digest);r.status===`preserved`?a.push(n):r.previous!==void 0&&o.push({path:n,previous:r.previous,installedDigest:void 0})}}for(let t of n){let n=_(e,t.path);a.includes(n)&&!u.some(t=>_(e,t.path)===n)&&u.push(t)}return{managed_artifacts:u,preserved:a,rollback:o}}catch(e){throw await tV(o).catch(()=>void 0),e}}async function tV(e){let t=[],n=[];for(let r of[...e].reverse()){let e=await cV(r.path);if(!(r.installedDigest===void 0?e===void 0:e!==void 0&&await uV(e)===r.installedDigest)){n.push(r.path);continue}r.previous===void 0?(await l(r.path,{force:!1}).catch(e=>{if(!SB(e,`ENOENT`))throw e}),t.push(r.path)):await NB(r.path,r.previous)}return{removed:t,preserved:n}}async function nV(e,n){let r=[],i=[],o=_(e,`agents`),s=_(e,`holycodex`,`agents`);for(let c of n){let n=_(e,c.path);if(!bB(e,n)||!bB(o,n)&&!bB(s,n)&&n!==_(e,`config.toml`)){i.push(n);continue}try{await vB(n);let e=await t(n);if(e.isSymbolicLink()||!e.isFile()){i.push(n);continue}if(await uV(await a(n))!==c.digest){i.push(n);continue}await l(n,{force:!1}),r.push(n)}catch(e){SB(e,`ENOENT`)?r.push(n):i.push(n)}}let c=_(e,`agents`,`root.toml`),u=await sV(c);return u===`removed`&&r.push(c),u===`preserved`&&i.push(c),{removed:r,preserved:i}}function rV(e){let t=e.rolePolicy,n=[`${t.role} shared policy: ${t.authority}`,t.evidence,t.completion,e.taskInstruction].join(`
83
+ `);return[`name = ${JSON.stringify(e.name)}`,`description = ${JSON.stringify(e.description)}`,`model = ${JSON.stringify(e.model)}`,`model_reasoning_effort = ${JSON.stringify(e.effort)}`,`service_tier = ${JSON.stringify(e.serviceTier)}`,`model_reasoning_summary = "none"`,`model_verbosity = "low"`,`sandbox_mode = ${JSON.stringify(t.permissions.write?`workspace-write`:`read-only`)}`,`approval_policy = "never"`,`web_search = ${JSON.stringify(t.permissions.network?`live`:`disabled`)}`,`developer_instructions = ${JSON.stringify(n)}`,``,`[agents]`,`enabled = false`,`interrupt_message = false`,``,`[features]`,`multi_agent_v2 = false`,`multi_agent = false`,`computer_use = false`,`browser_use = false`,`in_app_browser = false`,``].join(`
84
+ `)}function iV(e){return[`name = ${JSON.stringify(e.name)}`,`description = ${JSON.stringify(e.description)}`,`model = ${JSON.stringify(e.model)}`,`model_reasoning_effort = ${JSON.stringify(e.effort)}`,`service_tier = ${JSON.stringify(e.serviceTier)}`,`model_verbosity = "low"`,``].join(`
85
+ `)}function aV(e){return dV.has(e)}function oV(e,t,n){return n===`agents/root.toml`||/^holycodex\/agents\/(?:explorer|librarian|worker|reviewer)\.toml$/u.test(n)?!0:bB(_(e,`agents`),t)&&/^(?:Explorer|Librarian|Worker|Reviewer)\.(?:lookup|trace|research|mechanical|implementation|integration|operations|plan|code|artifact)\.toml$/u.test(n.slice(7))}async function sV(e){try{await vB(e);let n=await t(e);return!n.isFile()||n.isSymbolicLink()||!aV(await a(e,`utf8`))?`preserved`:(await l(e,{force:!1}),`removed`)}catch(e){if(SB(e,`ENOENT`))return`absent`;throw e}}async function cV(e){try{await vB(e);let n=await t(e);if(n.isSymbolicLink()||!n.isFile())throw Error(`Invalid managed path: ${e}`);return new TextDecoder(`utf-8`,{fatal:!0}).decode(await a(e))}catch(e){if(SB(e,`ENOENT`))return;throw e}}async function lV(e,n){try{await vB(e);let r=await t(e);if(r.isSymbolicLink()||!r.isFile())return{status:`preserved`};let i=new TextDecoder(`utf-8`,{fatal:!0}).decode(await a(e));return await uV(i)===n?(await l(e,{force:!1}),{status:`removed`,previous:i}):{status:`preserved`}}catch(e){if(SB(e,`ENOENT`))return{status:`removed`};throw e}}async function uV(e){let t=typeof e==`string`?new TextEncoder().encode(e):e,n=await crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}var dV,fV=v((()=>{uI(),kB(),BB(),dV=new Set([`go`,`plus-low`,`plus`,`plus-high`,`pro-5x`,`pro-20x`].flatMap(e=>[`standard`,`fast`,`fast-all`].map(t=>iV(QB(e,t)))))}));function pV(e,t,n){if(t instanceof hV)return t;let r=(t instanceof Lz?t:void 0)?.code,i=r===`timeout`||r===`output_limit`||r===`cancelled`||r===`readback_mismatch`||r===`plugin_disabled`||r===`plugin_missing`||r===`marketplace_invalid`||r===`marketplace_timeout`||r===`marketplace_unavailable`?r:r===`command_failed`?e===`list`?`list_failed`:e===`remove`?`remove_failed`:e===`bootstrap`?`marketplace_unavailable`:`add_failed`:e===`list`?`list_failed`:e===`bootstrap`?`marketplace_unavailable`:`add_failed`,a=t instanceof Error?t.message:e===`list`?`Codex could not list official plugins.`:e===`remove`?`Codex could not remove ${n??`the selected official plugin`}.`:e===`bootstrap`?`Codex could not initialize the official marketplace.`:`Codex could not add ${n??`the selected official plugin`}.`;return new hV(i,a,t,n===void 0?{}:{plugin_id:n})}var mV,hV,gV=v((()=>{zz(),uI(),mV=class e{adapter;observedIdentities={};constructor(e){if(`run`in e){let t=xz({executable:`codex`,runner:e});this.adapter=t}else this.adapter=e}static async discover(t=process.env){let n=xz({executable:(await BR({environment:t})).path,environment:jR(t),...t.CODEX_HOME===void 0?{}:{codexHome:t.CODEX_HOME}});return new e(n)}async list(){try{return await this.adapter.list()}catch(e){throw pV(`list`,e)}}async add(e){try{await this.adapter.add(e)}catch(t){throw pV(`add`,t,e)}}async ensureOfficialMarketplace(e){if(this.adapter.ensureOfficialMarketplace!==void 0)try{await this.adapter.ensureOfficialMarketplace(e)}catch(e){throw pV(`bootstrap`,e)}}async remove(e){try{await this.adapter.remove(e)}catch(t){throw pV(`remove`,t,e)}}async addMarketplace(e){try{await this.adapter.addMarketplace(e)}catch(t){throw pV(`add`,t,e)}}async status(e){let t=await this.list(),n={},r=new Map;for(let e of[...t.installed,...t.available])(!r.has(e.pluginId)||e.installed)&&r.set(e.pluginId,e);let i=Object.fromEntries(e.map(e=>{let i=vz(t,e),a=vP(e),o=r.get(e),s=i?.entry??(a===void 0||o?.marketplaceName==null?o:void 0);return s!==void 0&&(n[e]=i?.entry.pluginId??s.pluginId),[e,s===void 0?`missing`:s.installed&&s.enabled?`installed`:s.installed?`disabled`:`missing`]}));return this.observedIdentities=Object.freeze(n),i}getObservedIdentities(){return this.observedIdentities}},hV=class extends Error{code;causeValue;details;constructor(e,t,n,r={}){super(t),this.name=`OfficialPluginManagerError`,this.code=e,this.causeValue=n,this.details=r}}}));function _V(e){let t={},n=[];for(let r of e.split(/\r?\n/u)){let e=EV(r).trim();if(e.length===0)continue;if(e.startsWith(`[[`)||e.endsWith(`]]`))throw Error(`Array-of-tables are not supported by the validated fallback.`);if(e.startsWith(`[`)&&e.endsWith(`]`)){n=xV(e.slice(1,-1).trim()),CV(t,n);continue}let i=TV(e);if(i<1)throw Error(`TOML assignment is invalid.`);let a=xV(e.slice(0,i).trim()),o=bV(e.slice(i+1).trim());SV(t,[...n,...a],o)}return t}function vV(e){let t=[];return yV(e,[],t),t.join(`
86
+ `)}function yV(e,t,n){let r=[],i=[];for(let[t,n]of Object.entries(e))DV(n)?i.push([t,n]):r.push([t,n]);t.length>0&&(n.length>0&&n.push(``),n.push(`[${t.map(OV).join(`.`)}]`));for(let[e,t]of r)n.push(`${OV(e)} = ${kV(t)}`);for(let[e,r]of i)yV(r,[...t,e],n)}function bV(e){if(e.length===0)throw Error(`TOML value is missing.`);if(e.startsWith(`"`)){let t=JSON.parse(e);if(typeof t!=`string`)throw Error(`TOML string is invalid.`);return t}if(e.startsWith(`'`)){if(!e.endsWith(`'`)||e.length<2)throw Error(`TOML string is invalid.`);return e.slice(1,-1)}if(e===`true`)return!0;if(e===`false`)return!1;if(e.startsWith(`[`)){if(!e.endsWith(`]`))throw Error(`TOML array is invalid.`);let t=e.slice(1,-1).trim();return t.length===0?[]:wV(t,`,`).map(bV)}if(e.startsWith(`{`)){if(!e.endsWith(`}`))throw Error(`TOML inline table is invalid.`);let t=e.slice(1,-1).trim(),n={};if(t.length===0)return n;for(let e of wV(t,`,`)){let t=TV(e);if(t<1)throw Error(`TOML inline table entry is invalid.`);SV(n,xV(e.slice(0,t).trim()),bV(e.slice(t+1).trim()))}return n}if(/^[+-]?(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(e)){let t=Number(e);if(Number.isFinite(t))return t}throw Error(`TOML value is unsupported.`)}function xV(e){let t=wV(e,`.`).map(e=>e.trim());if(t.length===0||t.some(e=>!/^(?:[A-Za-z0-9_-]+|"(?:[^"\\]|\\.)*"|'[^']*')$/u.test(e)||e===`__proto__`||e===`constructor`||e===`prototype`))throw Error(`TOML key is invalid.`);return t.map(e=>e.startsWith(`"`)||e.startsWith(`'`)?bV(e):e)}function SV(e,t,n){if(t.length===0)throw Error(`TOML key is missing.`);let r=e;for(let e of t.slice(0,-1)){let t=r[e];if(t===void 0){let t={};r[e]=t,r=t}else if(DV(t))r=t;else throw Error(`TOML key conflicts with a scalar.`)}let i=t.at(-1);if(Object.prototype.hasOwnProperty.call(r,i))throw Error(`TOML key is duplicated.`);r[i]=n}function CV(e,t){let n=e;for(let e of t){let t=n[e];if(t===void 0){let t={};n[e]=t,n=t}else if(DV(t))n=t;else throw Error(`TOML table conflicts with a scalar.`)}}function wV(e,t){let n=[],r=0,i=0,a,o=!1;for(let s=0;s<e.length;s+=1){let c=e[s];if(a!==void 0){a===`"`&&o?o=!1:a===`"`&&c===`\\`?o=!0:c===a&&(a=void 0);continue}c===`"`||c===`'`?a=c:c===`[`||c===`{`?i+=1:c===`]`||c===`}`?--i:c===t&&i===0&&(n.push(e.slice(r,s)),r=s+1)}if(a!==void 0||i!==0)throw Error(`TOML value is unbalanced.`);return n.push(e.slice(r)),n}function TV(e){let t,n=!1,r=0;for(let i=0;i<e.length;i+=1){let a=e[i];if(t!==void 0)t===`"`&&n?n=!1:t===`"`&&a===`\\`?n=!0:a===t&&(t=void 0);else if(a===`"`||a===`'`)t=a;else if(a===`[`||a===`{`)r+=1;else if(a===`]`||a===`}`)--r;else if(a===`=`&&r===0)return i}return-1}function EV(e){let t,n=!1;for(let r=0;r<e.length;r+=1){let i=e[r];if(t!==void 0)t===`"`&&n?n=!1:t===`"`&&i===`\\`?n=!0:i===t&&(t=void 0);else if(i===`"`||i===`'`)t=i;else if(i===`#`)return e.slice(0,r)}return e}function DV(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function OV(e){return/^[A-Za-z0-9_-]+$/u.test(e)?e:JSON.stringify(e)}function kV(e){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`boolean`||typeof e==`number`){if(typeof e==`number`&&!Number.isFinite(e))throw Error(`TOML number is invalid.`);return String(e)}if(Array.isArray(e))return`[${e.map(kV).join(`, `)}]`;throw Error(e===null?`TOML null is not serializable.`:`TOML nested values must be tables.`)}var AV=v((()=>{})),jV=le({doctorHolyCodex:()=>MV,removeHolyCodex:()=>NV});async function MV(e={},t=process.env){let n=mB(e,t),r={};try{await yB(n.codexHome),await yB(n.stateRoot),r.paths=zV({state_root:n.stateRoot})}catch(e){r.paths=BV([`path_symlink`],{error:HV(e)})}let[i,a,o]=await Promise.all([GV(n).catch(e=>{r.configuration=BV([`state_corrupt`],{error:HV(e)})}),IB(n.preparingRecord,fB).catch(e=>{r.transaction=BV([`state_corrupt`],{path:n.preparingRecord,error:HV(e)})}),IB(n.conflictedRecord,fB).catch(e=>{r.transaction=BV([`state_corrupt`],{path:n.conflictedRecord,error:HV(e)})})]);if(a!==void 0&&r.transaction?.status!==`failed`&&(r.transaction=BV([`incomplete_install_state`])),o!==void 0&&r.transaction?.status!==`failed`&&(r.transaction=BV([`conflicted_state`])),r.configuration||=i?await OH(i)?zV({plan:i.plan,tier:i.tier,install_id:i.install_id}):BV([`configuration_changed`],{path:n.activeRecord}):BV([`configuration_missing`]),i){r.runtime_config=await PV(n,i),r.native_roles=await FV(n,i.plan,i.tier);let e=Object.entries(i.capability_state??{}).find(([,e])=>e.selected&&e.status!==`healthy`);e&&(r.capabilities=BV([`selected_capability_not_healthy`],{capability:e[0],status:e[1].status}))}try{let e=await FB(`${n.codexHome}/agents/root.toml`);if(e!==void 0&&aV(e)){let e=r.native_roles;r.native_roles={status:`failed`,reasons:[...e?.reasons??[],`stale_legacy_root`],details:{...e?.details,path:`${n.codexHome}/agents/root.toml`}}}}catch(e){r.native_roles=BV([`native_role_invalid`],{error:HV(e)})}let s=e.officialPluginManager??await mV.discover({...t,CODEX_HOME:n.codexHome}).catch(()=>void 0);if(i&&s?.status){let e=[...new Set([MH,...SP({computer_use:i.optional_selections.computer_use,work:i.optional_selections.work,frontend:i.optional_selections.frontend,security:i.optional_selections.security},i.official_plugins),...i.owned_plugins??[]])];try{let t=await s.status(e),n=Object.entries(t).filter(([,e])=>e!==`installed`).map(([e])=>e),i=s.getObservedIdentities?.()??{};r.native_plugins=n.length===0?zV({status:t,observed_identities:i}):BV([`native_plugin_disagreement`],{missing:n,status:t,observed_identities:i})}catch(e){r.native_plugins=BV([`native_plugin_status_failed`],{error:HV(e)})}}else r.native_plugins={status:`unsupported`,reasons:[`native_plugin_manager_unavailable`],details:{}};let c=Object.values(r).flatMap(e=>e.reasons);return{healthy:Object.values(r).every(e=>e.status!==`failed`),checks:r,reasons:[...new Set(c)]}}async function NV(e={},t=process.env){let n=mB(e,t);await yB(n.codexHome),await yB(n.stateRoot);let r=await GV(n),[i,a]=await Promise.all([IB(n.preparingRecord,fB),IB(n.conflictedRecord,fB)]),o=a??i??r,s=new Set(RV(o)),c=[],d=[],f=[];if(r&&!await OH(r))return d.push(n.activeRecord),f.push(`configuration_changed`),{removed:c,preserved:d,reasons:f};let p=await FB(n.configFile),m=qV(p);if(o?.managed_config){let e=await xL(m,o.managed_config,{schema:o.managed_config.schema,installId:o.managed_config.installId});if(e.preservedKeys.length>0||e.unresolvedKeys.length>0)return d.push(n.configFile),f.push(`managed_config_changed`),await IV(n,o),{removed:c,preserved:d,reasons:f}}if(o?.plugin_config&&(await ZV(m,o.plugin_config)).preserved.length>0)return d.push(n.configFile),f.push(`plugin_config_changed`),await IV(n,o),{removed:c,preserved:d,reasons:f};if(o?.provider_config&&(await QV(m,o.provider_config,s)).preserved.length>0)return d.push(n.configFile),f.push(`provider_config_changed`),await IV(n,o),{removed:c,preserved:d,reasons:f};let h;try{h=e.officialPluginManager??await mV.discover({...t,CODEX_HOME:n.codexHome})}catch(e){throw new Q(`capability_denied`,`Native Codex plugin removal is unavailable.`,e,{recovery:`Install or expose Codex, then retry.`})}if(h===void 0||!h.remove||!h.list)throw new Q(`capability_denied`,`Native Codex plugin removal and readback are unavailable.`);let g=await nV(n.codexHome,o?.managed_artifacts??[]);c.push(...g.removed),d.push(...g.preserved),g.preserved.length>0&&f.push(`managed_artifact_changed`);for(let e of s)try{let t=vz(await h.list(),e),n=t?.entry.installed?t.entry.pluginId:e;await h.remove(n);let r=await h.list();if(vz(r,e)?.entry?.installed===!0||[...r.installed,...r.available].some(t=>t.pluginId===e&&t.installed))throw new Q(`capability_denied`,`Codex still reports ${e} after removal.`);c.push(e)}catch(t){throw f.push(`native_plugin_remove_failed`),await IV(n,o??LV()),new Q(`capability_denied`,`Codex native plugin removal did not converge for ${e}: ${HV(t)}`,t)}if(g.preserved.length>0)return await IV(n,o??LV()),{removed:c,preserved:d,reasons:f};let _;try{let e=qV(await FB(n.configFile)),t=o?.managed_config;if(t){let r=await xL(e,t,{schema:t.schema,installId:t.installId});if(r.preservedKeys.length>0||r.unresolvedKeys.length>0)return d.push(n.configFile),f.push(`managed_config_changed`),await IV(n,o??LV()),{removed:c,preserved:d,reasons:f};e=r.document,t=r.state}if(o?.plugin_config){let t=await ZV(e,o.plugin_config,{allowBeforeState:!0});if(t.preserved.length>0)return d.push(n.configFile),f.push(`plugin_config_changed`),await IV(n,o),{removed:c,preserved:d,reasons:f};e=t.document}if(o?.provider_config){let t=await QV(e,o.provider_config,s,{allowBeforeState:!0});if(t.preserved.length>0)return d.push(n.configFile),f.push(`provider_config_changed`),await IV(n,o),{removed:c,preserved:d,reasons:f};e=t.document}(o?.managed_config||o?.plugin_config||o?.provider_config)&&(_=t===void 0?{document:e}:{document:e,state:t}),_!==void 0&&(Object.keys(_.document).length===0&&p===void 0?await l(n.configFile,{force:!1}):await NB(n.configFile,JV(_.document)))}catch(e){if(e instanceof Q)throw await IV(n,o??LV()),e;return d.push(n.configFile),f.push(`managed_config_write_failed`),await IV(n,o??LV()),{removed:c,preserved:d,reasons:f}}if(r)try{await l(n.activeRecord,{force:!1}),c.push(n.activeRecord)}catch(e){if(SB(e,`ENOENT`))c.push(n.activeRecord);else return d.push(n.activeRecord),f.push(`state_remove_failed`),await IV(n,o??r),{removed:c,preserved:d,reasons:f}}if(d.length===0){for(let[e,t]of[[n.preparingRecord,i!==void 0],[n.conflictedRecord,a!==void 0]])if(t)try{await VV(e),c.push(e)}catch{d.push(e),f.push(`state_remove_failed`)}}if(d.length===0)try{await u(n.roleRoot),c.push(n.roleRoot)}catch(e){SB(e,`ENOENT`)||(d.push(n.roleRoot),f.push(`role_directory_not_empty`))}if(d.length===0)try{await u(n.stateRoot),c.push(n.stateRoot)}catch(e){SB(e,`ENOENT`)?c.push(n.stateRoot):(d.push(n.stateRoot),f.push(`state_directory_not_empty`))}return{removed:c,preserved:d,reasons:f}}async function PV(e,t){if(!t.managed_config)return BV([`incomplete_install_state`]);try{let n=qV(await FB(e.configFile)),r=oH(t.plan,t.tier,t.optional_selections.computer_use),i=[];for(let[e,a]of Object.entries(r))((await SL(n,t.managed_config,e)).status!==`unchanged`||e!==`developer_instructions`&&ZI(n,e)!==a)&&i.push(e);return i.length===0?zV({managed_keys:Object.keys(r).length}):BV([`changed_holycodex_config`],{keys:i})}catch(e){return BV([`config_unreadable`],{error:HV(e)})}}async function FV(e,t,n){try{let r=qV(await FB(e.configFile)),i=[];for(let a of ZB(t,n)){let t=ZI(r,`agents."${a.name}".config_file`),o=`${e.roleRoot}/${a.name}.toml`.replaceAll(`\\`,`/`);if(typeof t!=`string`||hL(e.configFile,t).replaceAll(`\\`,`/`)!==o){i.push(`${a.name}:registration`);continue}let s=await FB(`${e.roleRoot}/${a.name}.toml`);if(s===void 0){i.push(`${a.name}:missing`);continue}if(s!==rV(a)){i.push(`${a.name}:changed`);continue}let c=qV(s);(c.name!==a.name||typeof c.description!=`string`||typeof c.developer_instructions!=`string`||c.model!==`gpt-5.6-luna`||c.model_reasoning_summary!==`none`||c.model_verbosity!==`low`||c.tool_output_token_limit!==void 0||c.service_tier!==(n===`standard`?`default`:`fast`)||c.sandbox_mode!==(a.rolePolicy.permissions.write?`workspace-write`:`read-only`)||c.approval_policy!==`never`||c.web_search!==(a.rolePolicy.permissions.network?`live`:`disabled`)||ZI(c,`agents.enabled`)!==!1||ZI(c,`features.multi_agent_v2`)!==!1||ZI(c,`features.multi_agent`)!==!1||ZI(c,`features.computer_use`)!==!1||ZI(c,`features.browser_use`)!==!1||ZI(c,`features.in_app_browser`)!==!1)&&i.push(`${a.name}:malformed`)}let a=await FB(`${e.codexHome}/agents/root.toml`);return a!==void 0&&aV(a)&&i.push(`root:stale`),i.length===0?zV({role_root:e.roleRoot,agent_types:ZB(t,n).map(e=>e.name)}):BV([`native_role_disagreement`],{roles:i})}catch(e){return BV([`native_role_invalid`],{error:HV(e)})}}async function IV(e,t){let n={...t,status:`conflicted`,step:`conflicted`,managed_config:t.managed_config??{owner:`holycodex`,schema:t.schema_epoch,installId:t.install_id,managed:{}},plugin_snapshot:t.plugin_snapshot??[],owned_plugins:t.owned_plugins??[]};Uz(fB,n)!==void 0&&await MB(e.conflictedRecord,Bz(n))}function LV(){return{owner:`holycodex`,schema_epoch:`state-0.16`,install_id:`remove-conflict`,version:`0.0.0`,digest:`0`.repeat(64),plan:`plus`,tier:`standard`,optional_selections:{computer_use:!1,work:!1,frontend:!1,security:!1,coding:!0},explicit_optional_selections:{},managed_artifacts:[],installed_at:new Date(0).toISOString()}}function RV(e){if(e?.owned_plugins!==void 0)return[...new Set(e.owned_plugins)];let t=(e?.plugin_snapshot??[]).filter(e=>e.plugin_id!==`holycodex@holycodex`&&e.status!==`installed`).map(e=>e.plugin_id);return[...new Set([MH,...t])]}function zV(e){return{status:`healthy`,reasons:[],details:e}}function BV(e,t={}){return{status:`failed`,reasons:e,details:t}}async function VV(e){await l(e,{force:!1}).catch(e=>{if(!SB(e,`ENOENT`))throw e})}function HV(e){return e instanceof Error?e.message.slice(0,256):`operation failed`}var UV=v((()=>{zz(),uI(),LH(),Hz(),fV(),gV(),kB(),pB(),BB()}));async function WV(e={},t={},n=process.env){if(Uz(eB,e)===void 0)throw new Q(`install_failed`,`The installation options are invalid.`);let r=mB(t,n);await _B(r.stateRoot);let i=await IB(r.preparingRecord,fB),a=await IB(r.conflictedRecord,fB)??i;if(a!==void 0){let{removeHolyCodex:r}=await Promise.resolve().then(()=>(UV(),jV)),i=await r(t,n);if(i.preserved.length>0||i.reasons.length>0)throw new Q(`state_corrupt`,`The interrupted HolyCodex installation could not be reconciled safely.`,void 0,{preserved:i.preserved.join(`,`),reasons:i.reasons.join(`,`)});return await WV({plan:e.plan??a.plan,tier:e.tier??a.tier,optional:{computer_use:e.optional?.computer_use??a.optional_selections.computer_use,work:e.optional?.work??a.optional_selections.work,frontend:e.optional?.frontend??a.optional_selections.frontend,security:e.optional?.security??a.optional_selections.security},officialPlugins:e.officialPlugins??vH(a)},t,n)}let o=await GV(r);if(o!==void 0&&!await OH(o))throw new Q(`state_corrupt`,`The existing HolyCodex configuration has changed and cannot be replaced.`,void 0,{path:r.activeRecord});let s=CH(e.plan,o?.plan),c=wH(e.tier,o?.tier),l=TH(e.optional,o?.optional_selections),u=gH(o?.explicit_optional_selections,e.optional),d=e.officialPlugins??vH(o),f=[...new Set(SP(KV(l),d).map(e=>vP(e)??e))],p;try{p=t.officialPluginManager??await mV.discover({...n,CODEX_HOME:r.codexHome})}catch(e){throw new Q(`capability_denied`,`Native Codex plugin installation is unavailable.`,e,{recovery:`Install or expose Codex, then retry.`})}if(!p.addMarketplace||!p.add||!p.list)throw new Q(`install_failed`,`Native Codex plugin installation and verification are unavailable.`);let m;try{m=await p.list()}catch(e){throw new Q(`capability_denied`,`Native Codex plugin state could not be read safely.`,e)}let h=f.filter(e=>{if(vP(e)!==e)return!1;let t=SH(m,e);return!(t?.installed&&t.enabled)});if(p.ensureOfficialMarketplace!==void 0&&h.length>0)try{await p.ensureOfficialMarketplace(h)}catch(e){throw new Q(`capability_denied`,`The selected official Codex provider marketplace is unavailable: ${AH(e)}`,e,{recovery:`Check Codex network and marketplace policy, then retry.`})}let g=o?.install_id??crypto.randomUUID().replaceAll(`-`,``),_=await UB(),ee=(t.now?.()??new Date).toISOString(),te=await FB(r.configFile),ne=qV(te),re=o?.plugin_config?.before??await YV(ne),ie=[...new Set([...f,...(o?.provider_config??[]).map(e=>e.plugin_id),...o?.owned_plugins??[]])].filter(e=>e!==MH),ae=(await XV(ne,ie)).map(e=>{let t=o?.provider_config?.find(t=>t.plugin_id===e.plugin_id);return t===void 0?e:{plugin_id:e.plugin_id,before:t.before,after:t.before}}),oe=await cH(ne,o?.managed_config??fL({schema:`state-0.16`,installId:g}),o),se=oe.document,ce=oe.state;lH(se,ce);let v=oH(s,c,l.computer_use),le=await bL(se,ce,v,{schema:pe,installId:g});if(le.driftedKeys.length>0)throw new Q(`state_corrupt`,`HolyCodex-owned Codex settings changed and cannot be replaced safely.`,void 0,{keys:le.driftedKeys.join(`,`)});let ue;try{ue=await uH({list:()=>p.list()},[...new Set([MH,...f,...o?.owned_plugins??[]])])}catch(e){throw new Q(`capability_denied`,`Native Codex plugin state could not be read safely.`,e)}let de={owner:`holycodex`,schema_epoch:pe,install_id:g,version:_,digest:o?.digest??`0`.repeat(64),plan:s,tier:c,optional_selections:l,explicit_optional_selections:u,official_plugins:f,capability_state:EH(l),managed_artifacts:o?.managed_artifacts??[],installed_at:ee,status:`preparing`,step:`validated`,managed_config:le.state,plugin_snapshot:ue,plugin_config:{plugin_id:MH,before:re,after:re},provider_config:ae,owned_plugins:[...new Set(o?.owned_plugins??[])]};await dH(r.preparingRecord,de);let fe,me=!1,he=new Set,ge=new Set(o?.owned_plugins??[]),_e=new Set,y=de,ve=!1,b=!1,ye=te,x=le.state;try{await _B(r.roleRoot),fe=await eV(r.codexHome,s,o?.managed_artifacts,c),y={...de,step:`roles_prepared`,managed_artifacts:fe.managed_artifacts},await dH(r.preparingRecord,y),ve=!0,await p.addMarketplace(jH),await yH({list:()=>p.list(),add:e=>p.add(e)},[MH,...f],(e,t)=>{t===`new`?(he.add(e),ge.add(e),y={...y,owned_plugins:[...ge]}):(_e.add(e),ge.add(e),y={...y,owned_plugins:[...ge]})}),y={...y,step:`plugins_installed`},await dH(r.preparingRecord,y);let e=await FB(r.configFile);ye=e;let t=qV(e),n=await YV(t),i=(await XV(t,ie)).map(e=>({plugin_id:e.plugin_id,before:ae.find(t=>t.plugin_id===e.plugin_id)?.before??e.before,after:e.before}));await sH(t,se,ce,v);let a=await bL(t,ce,v,{schema:pe,installId:g});if(a.driftedKeys.length>0)throw new Q(`state_corrupt`,`HolyCodex-owned Codex settings changed during native plugin setup.`,void 0,{keys:a.driftedKeys.join(`,`)});b=!0,x=a.state,y={...y,managed_config:x,plugin_config:{plugin_id:MH,before:re,after:n},provider_config:i},await NB(r.configFile,JV(a.document)),me=!0,y={...y,step:`config_published`},await dH(r.preparingRecord,y),await mH(r,s,c,l.computer_use,x,fe.preserved);let d=EH(l),m=await DH({owner:`holycodex`,install_id:g,version:_,plan:s,tier:c,optional_selections:l,explicit_optional_selections:u,official_plugins:f,capability_state:d,managed_artifacts:fe.managed_artifacts,managed_config:x,plugin_config:{plugin_id:MH,before:re,after:n},provider_config:i,plugin_snapshot:ue,owned_plugins:[...ge]}),h={owner:`holycodex`,schema_epoch:pe,install_id:g,version:_,digest:m,plan:s,tier:c,optional_selections:l,explicit_optional_selections:u,official_plugins:f,capability_state:d,managed_artifacts:fe.managed_artifacts,installed_at:ee,status:`active`,step:`active`,managed_config:x,plugin_snapshot:ue,plugin_config:{plugin_id:MH,before:re,after:n},provider_config:i,owned_plugins:[...ge]};if(Uz(cB,h)===void 0)throw new Q(`state_corrupt`,`The HolyCodex configuration is invalid.`);return await MB(r.activeRecord,Bz(h)),await fH(r.preparingRecord),await fH(r.conflictedRecord),{record:h,optional_plugins:f,preserved:fe.preserved,warnings:fe.preserved.length===0?[]:[`modified managed files were preserved`]}}catch(e){let t=[];if(me)try{await pH(r.configFile,ye)}catch{t.push(`config`)}if(ve&&!b&&await FB(r.configFile).catch(()=>void 0)!==ye&&t.push(`config`),fe!==void 0)try{(await tV(fe.rollback)).preserved.length>0&&t.push(`roles`)}catch{t.push(`roles`)}_e.size>0&&t.push(...[..._e].map(e=>`plugin:${e}`));for(let e of he)try{await p.remove?.(e)}catch{t.push(`plugin:${e}`)}throw t.length>0?await dH(r.conflictedRecord,{...y,step:`conflicted`,status:`conflicted`}).catch(()=>void 0):await fH(r.preparingRecord).catch(()=>void 0),e instanceof OB||e instanceof Q?e:new Q(e instanceof hV||e instanceof IH?`capability_denied`:`install_failed`,AH(e),e,t.length>0?{recovery:`Resolve conflicted state before retrying.`}:{})}}async function GV(e){let t=await IB(e.activeRecord,Gz);if(t===void 0)return;let n=Uz(cB,t);if(n!==void 0)return n;let r=Uz(lB,t);if(r===void 0)throw new Q(`state_corrupt`,`The HolyCodex configuration is invalid.`);if(!await kH(r))throw new Q(`state_corrupt`,`The existing HolyCodex configuration has an invalid digest.`,void 0,{path:e.activeRecord});let i=KP(r.plan);return{...r,plan:i,digest:await DH({owner:r.owner,install_id:r.install_id,version:r.version,plan:i,tier:r.tier,optional_selections:r.optional_selections,explicit_optional_selections:r.explicit_optional_selections,official_plugins:r.official_plugins??[],capability_state:r.capability_state??null,managed_artifacts:r.managed_artifacts,...r.managed_config===void 0?{}:{managed_config:r.managed_config},...r.plugin_config===void 0?{}:{plugin_config:r.plugin_config},...r.provider_config===void 0?{}:{provider_config:r.provider_config},...r.plugin_snapshot===void 0?{}:{plugin_snapshot:r.plugin_snapshot},...r.owned_plugins===void 0?{}:{owned_plugins:r.owned_plugins}})}}function KV(e){return{computer_use:e.computer_use,work:e.work,frontend:e.frontend,security:e.security}}function qV(e){if(e===void 0||e.trim().length===0)return{};try{let t=globalThis.Bun,n=t?.TOML?.parse?t.TOML.parse(e):_V(e),r=Uz(CL,n);if(r===void 0)throw Error(`TOML document contains unsupported values.`);return r}catch(e){throw new Q(`state_corrupt`,`The Codex config.toml is not valid TOML.`,e)}}function JV(e){try{let t=globalThis.Bun;return`${(t?.TOML?.stringify?t.TOML.stringify(e):vV(e)).trimEnd()}\n`}catch(e){throw new Q(`install_failed`,`The merged Codex configuration is not writable.`,e)}}async function YV(e){return{preference:await $V(e,`plugins`,PH),marketplace:await $V(e,`marketplaces`,FH)}}async function XV(e,t){return await Promise.all(t.map(async t=>{let n=await $V(e,`plugins`,t),r={presence:n.presence,digest:n.digest,...n.safe_value?.kind===`boolean`?{safe_value:n.safe_value}:{}};return{plugin_id:t,before:r,after:r}}))}async function ZV(e,t,n={}){let r=e,i=[],a=[],o=[];for(let[s,c,l]of[[`preference`,`plugins`,PH],[`marketplace`,`marketplaces`,FH]]){let u=t.before[s],d=t.after[s],f=await $V(e,c,l);if(n.allowBeforeState!==!0||f.digest!==u.digest){if(f.digest!==d.digest){o.push(s);continue}if(u.presence===`absent`){f.presence===`present`&&(r=iH(r,c,l),a.push(s));continue}if(u.safe_value===void 0){o.push(s);continue}r=rH(r,c,l,nH(u.safe_value)),i.push(s)}}return{document:r,restored:i,removed:a,preserved:o}}async function QV(e,t,n,r={}){let i=e,a=[],o=[],s=[];for(let c of t){if(!n.has(c.plugin_id))continue;let t=c.before,l=c.after,u=await $V(e,`plugins`,c.plugin_id);if(r.allowBeforeState!==!0||u.digest!==t.digest){if(u.digest!==l.digest){s.push(c.plugin_id);continue}if(t.presence===`absent`){u.presence===`present`&&(i=iH(i,`plugins`,c.plugin_id),o.push(c.plugin_id));continue}if(t.safe_value===void 0){s.push(c.plugin_id);continue}i=rH(i,`plugins`,c.plugin_id,{enabled:t.safe_value.value}),a.push(c.plugin_id)}}return{document:i,restored:a,removed:o,preserved:s}}async function $V(e,t,n){let r=eH(e,t,n),i=await xF(`holycodex-plugin-config`,[vF(Bz({key:`${t}.${n}`,value:r===void 0?{presence:`absent`}:r}))]),a=tH(t,r);return{presence:r===void 0?`absent`:`present`,digest:i,...a===void 0?{}:{safe_value:a}}}function eH(e,t,n){let r=e[t];if(aH(r))return r[n]}function tH(e,t){if(!aH(t))return;let n=Object.keys(t);if(e===`plugins`)return n.length!==1||n[0]!==`enabled`||typeof t.enabled!=`boolean`?void 0:{kind:`boolean`,value:t.enabled};if(!(n.length!==2||!n.includes(`source_type`)||!n.includes(`source`)||t.source_type!==`git`||t.source!==NH))return{kind:`marketplace`,source_type:`git`,source:NH}}function nH(e){return e.kind===`boolean`?{enabled:e.value}:{source_type:e.source_type,source:e.source}}function rH(e,t,n,r){let i={...e},a=i[t];if(a!==void 0&&!aH(a))throw new Q(`state_corrupt`,`The ${t} Codex config table is invalid.`);return i[t]={...a,[n]:r},i}function iH(e,t,n){let r=e[t];if(!aH(r)||!Object.prototype.hasOwnProperty.call(r,n))return e;let i={...e},a={...r};return delete a[n],Object.keys(a).length===0?delete i[t]:i[t]=a,i}function aH(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function oH(e,t,n=!1){let r=QB(e,t),i={model:r.model,model_reasoning_effort:r.effort,service_tier:r.serviceTier,model_verbosity:`low`,developer_instructions:$B(n),suppress_unstable_features_warning:!0,"features.default_mode_request_user_input":!0,"features.multi_agent_v2":!0,"features.context_management.experimental_mode":!0};for(let e of pF)i[`agents."${e}".config_file`]=`holycodex/agents/${e}.toml`;return i}async function sH(e,t,n,r){let i=[];for(let a of Object.keys(r)){let r=a;if(n.managed[r]!==void 0){(await SL(e,n,r)).status===`drifted`&&i.push(r);continue}ZI(t,r)!==ZI(e,r)&&i.push(r)}if(i.length>0)throw new Q(`state_corrupt`,`Codex settings changed during native plugin setup.`,void 0,{keys:i.join(`,`)})}async function cH(e,t,n){let r=[`agents.explorer.config_file`,`agents.librarian.config_file`,`agents.worker.config_file`,`agents.reviewer.config_file`],i=Object.fromEntries(r.flatMap(e=>{let n=t.managed[e];return n===void 0?[]:[[e,n]]})),a=e,o=t;if(Object.keys(i).length>0){let n=await xL(e,{...t,managed:i},{schema:t.schema,installId:t.installId});if(n.preservedKeys.length>0||n.unresolvedKeys.length>0)throw new Q(`state_corrupt`,`Legacy HolyCodex agent registrations changed and cannot be migrated safely.`,void 0,{keys:[...new Set([...n.preservedKeys,...n.unresolvedKeys])].join(`,`)});a=n.document,o={...t,managed:Object.fromEntries(Object.entries(t.managed).filter(([e])=>!r.includes(e)))}}if(!n)return{document:a,state:o};let s=n.managed_artifacts.map(e=>e.path);for(let e of[`explorer`,`librarian`,`worker`,`reviewer`]){if(!s.some(t=>t.startsWith(`agents/${e[0]?.toUpperCase()}${e.slice(1)}.`)||t===`holycodex/agents/${e}.toml`))continue;let t=`agents.${e}.config_file`,n=ZI(a,t);if(typeof n!=`string`)continue;let r=n.replaceAll(`\\`,`/`).replace(/^\.\//u,``);(r===`agents/${e}.toml`||r===`holycodex/agents/${e}.toml`)&&(a=tL(a,t))}return{document:a,state:o}}function lH(e,t){if(ZI(e,`developer_instructions`)!==void 0&&t.managed.developer_instructions===void 0)throw new Q(`state_corrupt`,`Existing developer_instructions cannot be displaced safely; remove it or converge managed state first.`)}async function uH(e,t){let n=await e.list();return t.map(e=>{let t=SH(n,e);return{plugin_id:e,status:t===void 0?`missing`:t.installed&&t.enabled?`installed`:t.installed?`disabled`:`available`}})}async function dH(e,t){if(Uz(fB,t)===void 0)throw new Q(`state_corrupt`,`The HolyCodex transaction state is invalid.`);await MB(e,Bz(t))}async function fH(e){await l(e,{force:!1}).catch(e=>{if(!SB(e,`ENOENT`))throw e})}async function pH(e,t){if(t===void 0){await l(e,{force:!1}).catch(e=>{if(!SB(e,`ENOENT`))throw e});return}await NB(e,t)}async function mH(e,t,n,r,i,a=[]){let o=qV(await FB(e.configFile)),s=oH(t,n,r);for(let[e,t]of Object.entries(s)){let n=ZI(o,e);if(e===`developer_instructions`){if(typeof n!=`string`||await hH(e,n)!==i.managed[e]?.lastManagedValue.value)throw new Q(`install_failed`,`The effective Root instructions did not converge.`)}else if(n!==t)throw new Q(`install_failed`,`The effective Codex setting ${e} did not converge.`)}let c=ZB(t,n);for(let t of c){let n=ZI(o,`agents."${t.name}".config_file`);if(typeof n!=`string`)throw new Q(`install_failed`,`The ${t.name} registration is missing.`);let r=_(e.roleRoot,`${t.name}.toml`),i=r.replaceAll(`\\`,`/`);if(hL(e.configFile,n).replaceAll(`\\`,`/`)!==i)throw new Q(`install_failed`,`The ${t.name} registration is stale.`);let s=await FB(r);if(s===void 0)throw new Q(`install_failed`,`The ${t.name} role file is missing.`);if(a.includes(r))continue;let c=qV(s);if(c.name!==t.name||typeof c.description!=`string`||typeof c.model!=`string`||typeof c.model_reasoning_effort!=`string`||typeof c.service_tier!=`string`||typeof c.developer_instructions!=`string`||c.sandbox_mode!==(t.rolePolicy.permissions.write?`workspace-write`:`read-only`)||c.approval_policy!==`never`||c.web_search!==(t.rolePolicy.permissions.network?`live`:`disabled`)||c.tool_output_token_limit!==void 0||ZI(c,`agents.enabled`)!==!1||ZI(c,`features.multi_agent_v2`)!==!1||ZI(c,`features.multi_agent`)!==!1||ZI(c,`features.computer_use`)!==!1||ZI(c,`features.browser_use`)!==!1||ZI(c,`features.in_app_browser`)!==!1)throw new Q(`install_failed`,`The ${t.name} role file is malformed.`)}let l=await FB(`${e.codexHome}/agents/root.toml`);if(l!==void 0&&aV(l))throw new Q(`install_failed`,`A stale HolyCodex Root role remains installed.`)}async function hH(e,t){return await xF(`holycodex-managed-config-value`,[vF({keyPath:e,value:t})])}function gH(e,t){let n={};for(let r of[`computer_use`,`work`,`frontend`,`security`]){let i=t?.[r]??e?.[r];i!==void 0&&(n[r]=i)}return n}function _H(e){return[`computer_use`,`work`,`frontend`,`security`].find(t=>OP[t].pluginIds.includes(e))}function vH(e){return(e?.official_plugins??[]).filter(t=>{let n=_H(t);return n===void 0||e?.optional_selections[n]!==!0})}async function yH(e,t,n){for(let r of t){let t;try{t=SH(await e.list(),r)}catch(e){throw xH(`list`,e,r)}if(t?.installed&&!t.enabled)throw new IH(`uncertain`,`${r} is disabled`);let i=!(t?.installed&&t.enabled);if(!(t?.installed&&t.enabled))try{await e.add(r)}catch(i){try{let i=SH(await e.list(),r);bH(t,i)||n?.(r,`uncertain`)}catch{n?.(r,`uncertain`)}throw xH(`add`,i,r)}let a;try{a=SH(await e.list(),r)}catch(e){throw i&&n?.(r,`uncertain`),xH(`list`,e,r)}if(!a?.installed)throw i&&!bH(t,a)&&n?.(r,`uncertain`),new IH(`missing`,`${r} is not installed after add`);if(i&&a.enabled&&n?.(r,`new`),!a.enabled)throw i&&n?.(r,`new`),new IH(`uncertain`,`${r} is disabled after add`)}}function bH(e,t){return e?.pluginId===t?.pluginId&&e?.installed===t?.installed&&e?.enabled===t?.enabled&&e?.marketplaceName===t?.marketplaceName}function xH(e,t,n){return t instanceof hV?t:new hV(e===`list`?`list_failed`:`add_failed`,e===`list`?`Codex could not read the status of ${n}.`:`Codex could not add ${n}.`,t,{plugin_id:n})}function SH(e,t){let n=vz(e,t);if(n!==void 0)return n.entry;let r=vP(t);return[...e.installed,...e.available].find(e=>e.pluginId===t&&(r===void 0||e.marketplaceName==null))}function CH(e,t){let n=e??t??`plus`;if(!eI(n).ok)throw new Q(`install_failed`,`Unknown plan.`);return n}function wH(e,t){let n=e??t??`standard`;if(Uz(nF,n)===void 0)throw new Q(`install_failed`,`The tier is not supported.`);return n}function TH(e,t){let n=xP(e,t?KV(t):AP);return{computer_use:n.computer_use,work:n.work,frontend:n.frontend,security:n.security,coding:!0}}function EH(e,t=new Map){return Object.fromEntries([`computer_use`,`work`,`frontend`,`security`].map(n=>{let r=e[n];return[n,{selected:r,status:r?t.get(n)??`healthy`:`disabled`,plugin_ids:[...OP[n].pluginIds]}]}))}async function DH(e){return await xF(`install-record`,[vF(Bz(e))])}async function OH(e){return await kH(e)}async function kH(e){return await DH({owner:e.owner,install_id:e.install_id,version:e.version,plan:e.plan,tier:e.tier,optional_selections:e.optional_selections,explicit_optional_selections:e.explicit_optional_selections,official_plugins:e.official_plugins??[],capability_state:e.capability_state??null,managed_artifacts:e.managed_artifacts,...e.managed_config===void 0?{}:{managed_config:e.managed_config},...e.plugin_config===void 0?{}:{plugin_config:e.plugin_config},...e.provider_config===void 0?{}:{provider_config:e.provider_config},...e.plugin_snapshot===void 0?{}:{plugin_snapshot:e.plugin_snapshot},...e.owned_plugins===void 0?{}:{owned_plugins:e.owned_plugins}})===e.digest}function AH(e){return e instanceof Error?e.message.slice(0,256):`operation failed`}var jH,MH,NH,PH,FH,IH,Q,LH=v((()=>{zz(),uI(),Hz(),XB(),fV(),gV(),kB(),pB(),BB(),AV(),jH=`davidbasilefilho/holycodex`,MH=`holycodex@holycodex`,NH=`https://github.com/davidbasilefilho/holycodex.git`,PH=`holycodex@holycodex`,FH=`holycodex`,IH=class extends Error{status;constructor(e,t){super(t),this.name=`PluginVerificationError`,this.status=e}},Q=class extends Error{code;causeValue;details;constructor(e,t,n,r={}){super(t),this.name=`InstallerError`,this.code=e,this.causeValue=n,this.details=r}}}));uI(),LH(),Hz(),UV(),XB(),gV(),kB(),BB();async function RH(e,t={}){if(xI(e)||e[0]===`help`){let t=e[0]===`help`?e.slice(1).filter(e=>!e.startsWith(`-`))[0]:SI(e);return{envelope:XH(t===void 0?`help`:`${t} help`,{help:yI(t)}),exitCode:0}}let n;try{n=hI(e);let r=await zH(n,t);return{envelope:XH(n.command,r),exitCode:QH(n.command,r)}}catch(t){return ZH(n?.command??eU(e),t)}}async function zH(e,t){switch(e.command){case`install`:return Bz(await BH(e,t));case`doctor`:return Bz(await MV(YH(e,t),t.env));case`remove`:return Bz(await VH(e,t));case`version`:return Bz(await HH(e,t));case`help`:return{help:yI(e.positionals[0])};default:throw new yU(`invalid_argument`,`Unknown command.`)}}async function BH(e,t){let n=e.options.json===!0;if(!await UH(e,t,`Install HolyCodex into the selected Codex home?`))throw new yU(`non_tty_confirmation_required`,`Install requires --yes in non-interactive mode.`);rU(t,n,`Validating Codex target`),rU(t,n,`Installing HolyCodex`),rU(t,n,`Installing selected capabilities`),rU(t,n,`Configuring Root`),rU(t,n,`Installing subagent roles`);let r=await WV({...KH(e)===void 0?{}:{plan:KH(e)},...qH(e)===void 0?{}:{tier:qH(e)},...GH(e)===void 0?{}:{optional:GH(e)},...JH(e,`add-plugin`).length===0?{}:{officialPlugins:JH(e,`add-plugin`)}},YH(e,t),t.env);return rU(t,n,`Verifying installation`),rU(t,n,`HolyCodex installation complete`),r}async function VH(e,t){let n=e.options.json===!0;if(!await UH(e,t,`Remove HolyCodex-owned Codex state?`))throw new yU(`non_tty_confirmation_required`,`Remove requires --yes in non-interactive mode.`);rU(t,n,`Validating HolyCodex ownership`);let r=await NV(YH(e,t),t.env);return rU(t,n,`Removing HolyCodex-owned state`),rU(t,n,`HolyCodex removal complete`),r}async function HH(e,t){let n=e.positionals[0];return n?await WB(n,e.options[`dry-run`]===!0):{version:await HB()}}async function UH(e,t,n){return e.options.yes===!0?!0:e.options.json===!0||t.io?.stdoutIsTTY!==!0?!1:await WH(t,n)}async function WH(e,t){return e.io?.confirm?await e.io.confirm(t):!1}function GH(e){let t={};for(let n of[`computer_use`,`work`,`frontend`,`security`]){let r=n.replaceAll(`_`,`-`);e.options[r]===!0?t[n]=!0:(e.options[r]===!1||e.options[`no-${r}`]===!0)&&(t[n]=!1)}return Object.keys(t).length===0?void 0:t}function KH(e){let t=e.options.plan;if(typeof t!=`string`)return;let n=eI(t);return n.ok?n.value.name:void 0}function qH(e){let t=e.options.tier;return t===`standard`||t===`fast`||t===`fast-all`?t:void 0}function JH(e,t){let n=e.options[t];return Array.isArray(n)?n.filter(e=>typeof e==`string`):[]}function YH(e,t){let n=t.installer??{},r=e.options[`codex-home`];return typeof r==`string`?{...n,paths:{...n.paths,codexHome:r},...t.now?{now:t.now}:{}}:{...n,...t.now?{now:t.now}:{}}}function XH(e,t){let n=TF({schema_version:fe,ok:!0,command:e,data:t,warnings:[]});if(!n.ok)throw new yU(`internal_error`,`The success envelope failed validation.`);return n.value}function ZH(e,t){let n=$H(t),r=TF({schema_version:fe,ok:!1,command:e,error:{code:n.code,message:n.message,details:n.details},warnings:[]});return r.ok?{envelope:r.value,exitCode:n.exitCode}:{envelope:{schema_version:fe,ok:!1,command:`internal-error`,error:{code:`internal_error`,message:`The CLI failure envelope was invalid.`,details:{}},warnings:[]},exitCode:5}}function QH(e,t){return e===`doctor`&&nU(t)&&t.healthy===!1?4:0}function $H(e){if(e instanceof mI)return{code:e.code,message:tU(e.message),details:e.details,exitCode:1};if(e instanceof yU)return{code:e.code,message:tU(e.message),details:{},exitCode:e.code===`internal_error`?5:1};if(e instanceof OB)return{code:`trust_boundary_failed`,message:tU(e.message),details:{},exitCode:4};if(e instanceof Q){let t=e.code===`capability_denied`?2:e.code===`state_corrupt`?4:3;return{code:e.code,message:tU(e.message),details:e.details,exitCode:t}}if(e instanceof hV){let t=[`timeout`,`output_limit`,`cancelled`,`readback_mismatch`].includes(e.code),n=e.code===`plugin_disabled`||e.code===`plugin_missing`||e.code===`command_failed`;return{code:t?`effect_uncertain`:n?`capability_denied`:`install_failed`,message:tU(e.message),details:e.details,exitCode:t?4:n?2:3}}return e instanceof zB?{code:e.code,message:tU(e.message),details:{},exitCode:4}:e instanceof YB?{code:e.code,message:tU(e.message),details:{},exitCode:1}:(e instanceof Error,{code:`internal_error`,message:`The command failed unexpectedly.`,details:{},exitCode:5})}function eU(e){return e.find(e=>!e.startsWith(`-`))??`unknown`}function tU(e){return Array.from(e).map(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127?` `:e}).join(``).replace(/\s+/gu,` `).trim().slice(0,512)}function nU(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rU(e,t,n){t||e.io?.stderrIsTTY===!1||e.io?.writeStderr?.(`${aU(n,{stderrIsTTY:e.io?.stderrIsTTY,env:e.env})}\n`)}function iU(e,t={}){let n=CI(t);if(e.envelope.ok)return e.envelope.command===`version`?oU(e.envelope.data):e.envelope.command===`install`?sU(e.envelope.data,n):e.envelope.command===`remove`?cU(e.envelope.data,n):e.envelope.command===`doctor`?lU(e.envelope.data,n):`${$(`✔`,`green`,n)} ${$(e.envelope.command,`heading`,n)}\n${hU(e.envelope.data,n)}`;let r=e.envelope.error,i=vU(r.code,e.envelope.command);return[`${$(`✖`,`red`,n)} ${$(e.envelope.command,`heading`,n)}`,` ${$(r.code,`red`,n)}: ${r.message}`,...gU(r.details,n),...i===void 0?[]:[` hint: ${i}`],``].join(`
87
+ `)}function aU(e,t={}){return`${$(`•`,`cyan`,CI({...t,stream:`stderr`}))} ${e}`}function oU(e){if(nU(e)&&typeof e.version==`string`)return`holycodex ${e.version}\n`;if(nU(e)&&typeof e.next==`string`){let t=typeof e.previous==`string`?` (from ${e.previous})`:``;return`holycodex version updated to ${e.next}${t}\n`}return`holycodex version completed
88
+ `}function sU(e,t){let n=uU(e,`record`),r=fU(n,`version`)??`unknown`,i=fU(n,`plan`)??`unknown`,a=fU(n,`tier`)??`unknown`,o=uU(n,`optional_selections`),s=uU(n,`capability_state`),c=[`frontend`,`security`,`work`,`computer_use`].filter(e=>o?.[e]===!0).map(e=>{let t=fU(uU(s,e),`status`);return t===void 0||t===`healthy`?e:`${e} (${t})`}),l=pU(e,`preserved`),u=pU(e,`warnings`),d=c.length===0?`none`:c.join(`, `),f=l.length===0?`none`:`${l.length} managed item${l.length===1?``:`s`} (review before retrying)`;return`${[`${$(`✔`,`green`,t)} ${$(`install`,`heading`,t)}`,` ${$(`version`,`option`,t)}: ${r}`,` ${$(`plan`,`option`,t)}: ${i}`,` ${$(`tier`,`option`,t)}: ${a}`,` ${$(`capabilities`,`option`,t)}: ${d}`,` ${$(`preserved`,`option`,t)}: ${f}`,...u.map(e=>` ${$(`warning`,`red`,t)}: ${mU(e)}`)].join(`
89
+ `)}\n`}function cU(e,t){let n=pU(e,`removed`),r=pU(e,`preserved`),i=pU(e,`reasons`),a=r.length===0?`none`:`${r.length} item${r.length===1?``:`s`} (review before retrying)`;return`${[`${$(`✔`,`green`,t)} ${$(`remove`,`heading`,t)}`,` ${$(`removed`,`option`,t)}: ${n.length} owned item${n.length===1?``:`s`}`,` ${$(`preserved`,`option`,t)}: ${a}`,...i.map(e=>` ${$(`reason`,`option`,t)}: ${mU(e)}`)].join(`
90
+ `)}\n`}function lU(e,t){let n=dU(e,`healthy`)===!0,r=uU(e,`checks`),i=r===void 0?[]:Object.entries(r),a=i.flatMap(([e,n])=>{let r=nU(n)?n:void 0,i=fU(r,`status`);if(i===void 0||i===`healthy`)return[];let a=pU(r,`reasons`);return[` ${$(e,`option`,t)}: ${a.length===0?i:a.map(mU).join(`, `)}`]});return`${[`${n?$(`✔`,`green`,t):$(`✖`,`red`,t)} ${$(`doctor`,`heading`,t)}`,` ${$(`status`,`option`,t)}: ${n?`healthy`:`needs attention`}`,` ${$(`checks`,`option`,t)}: ${i.length}`,...a.length===0?[]:[` ${$(`issues`,`option`,t)}:`,...a]].join(`
91
+ `)}\n`}function uU(e,t){if(nU(e))return nU(e[t])?e[t]:void 0}function dU(e,t){return nU(e)?e[t]:void 0}function fU(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function pU(e,t){return!nU(e)||!Array.isArray(e[t])?[]:e[t]}function mU(e){return typeof e==`string`?e.replaceAll(`_`,` `):`operation requires review`}function hU(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return` ${$(_U(e),`dim`,t)}\n`;let n=Object.entries(e);if(n.length===0)return``;let r=Math.max(...n.map(([e])=>e.length));return`${n.map(([e,n])=>` ${$(e.padEnd(r),`option`,t)}: ${_U(n)}`).join(`
92
+ `)}\n`}function gU(e,t){return Object.entries(e).map(([e,n])=>` ${$(e,`option`,t)}: ${$(_U(n),`dim`,t)}`)}function _U(e){return typeof e==`string`?e:e===null||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function vU(e,t){if(e===`invalid_argument`||e===`unknown_command`)return`holycodex ${t} --help`;if(e===`non_tty_confirmation_required`)return`rerun with --yes or use an interactive terminal`;if(e===`capability_denied`)return"run `holycodex doctor` to inspect capability availability"}function $(e,t,n){return n?`\u001b[${{red:`31`,green:`32`,cyan:`36`,dim:`2`,heading:`1`,option:`36`}[t]}m${e}\u001b[0m`:e}var yU=class extends Error{code;constructor(e,t){super(t),this.name=`CliCommandError`,this.code=e}};async function bU(e=Bun.argv.slice(2),t=xU()){let n={env:process.env,cwd:process.cwd(),io:{stdin:t.stdin??CU(),stdoutIsTTY:t.stdoutIsTTY??process.stdout.isTTY===!0,stderrIsTTY:t.stderrIsTTY??process.stderr.isTTY===!0,...t.confirm===void 0?{}:{confirm:t.confirm},writeStdout:t.writeStdout,writeStderr:t.writeStderr}},r=await RH(e,n);return(xI(e)||e[0]===`help`)&&!SU(e)?n.io?.writeStdout?.(bI(SI(e),{stdoutIsTTY:n.io?.stdoutIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stdout`})):SU(e)?n.io?.writeStdout?.(`${JSON.stringify(r.envelope)}\n`):r.envelope.ok?n.io?.writeStdout?.(iU(r,{stdoutIsTTY:n.io?.stdoutIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stdout`})):n.io?.writeStderr?.(iU(r,{stdoutIsTTY:n.io?.stderrIsTTY,stderrIsTTY:n.io?.stderrIsTTY,env:n.env,stream:`stderr`})),r.exitCode}function xU(){return{stdoutIsTTY:process.stdout.isTTY===!0,stderrIsTTY:process.stderr.isTTY===!0,writeStdout:e=>process.stdout.write(e),writeStderr:e=>process.stderr.write(e),confirm:async t=>{let n=e({input:process.stdin,output:process.stderr});try{let e=await n.question(`${t} [y/N] `);return/^(?:y|yes)$/iu.test(e.trim())}finally{n.close()}}}}function SU(e){let t=!1;for(let n of e)n===`--json`||n===`--json=true`?t=!0:n===`--json=false`&&(t=!1);return t}async function*CU(){let e=new TextDecoder;for await(let t of process.stdin)typeof t==`string`?yield t:yield e.decode(t,{stream:!0});let t=e.decode();t.length>0&&(yield t)}LH(),UV(),XB(),kB(),gV(),fV(),pB();const wU=`holycodex`;import.meta.main&&(process.exitCode=await bU());export{mI as ArgumentError,tB as CapabilityInstallStateSchema,nB as CapabilityStateRecordSchema,mV as CodexOfficialPluginManager,cB as InstallRecordSchema,eB as InstallRequestSchema,Q as InstallerError,hV as OfficialPluginManagerError,OB as PathBoundaryError,DB as STATE_SCHEMA,hB as assertRootText,MV as doctorHolyCodex,zH as executeCommand,xI as helpRequested,yI as helpText,SI as helpTopic,WV as installHolyCodex,eV as installNativeAgents,DH as installRecordDigest,wU as packageName,hI as parseArgv,bB as pathWithin,ZB as projectNativeAgents,QB as projectRootAgent,JB as publicManifestPath,GV as readActiveInstallRecord,UB as readCanonicalBaseVersion,HB as readCanonicalVersion,NV as removeHolyCodex,nV as removeManagedNativeAgents,bI as renderHelp,iU as renderHuman,rV as renderNativeAgent,aU as renderProgress,mB as resolveInstallerPaths,tV as rollbackNativeAgentInstall,bU as runBinary,RH as runCli,WB as updateCanonicalVersion};