holycodex 0.16.8-dev.92.1 → 0.16.9-dev.103.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/README.md +9 -3
- package/dist/agent.js +50 -41
- package/dist/assets/plugin/plugin.json +1 -1
- package/dist/assets/plugin/skills/babysit-ci/SKILL.md +15 -35
- package/dist/assets/plugin/skills/code-review/SKILL.md +0 -7
- package/dist/assets/plugin/skills/codebase-onboarding/SKILL.md +11 -0
- package/dist/assets/plugin/skills/codebase-onboarding/agents/openai.yaml +6 -0
- package/dist/assets/plugin/skills/commit/SKILL.md +5 -15
- package/dist/assets/plugin/skills/commit/agents/openai.yaml +1 -1
- package/dist/assets/plugin/skills/context7-cli/SKILL.md +1 -3
- package/dist/assets/plugin/skills/continue-work/SKILL.md +15 -0
- package/dist/assets/plugin/skills/continue-work/agents/openai.yaml +6 -0
- package/dist/assets/plugin/skills/debugging/SKILL.md +7 -4
- package/dist/assets/plugin/skills/debugging/agents/openai.yaml +1 -1
- package/dist/assets/plugin/skills/handoff/SKILL.md +1 -3
- package/dist/assets/plugin/skills/programming/SKILL.md +2 -3
- package/dist/assets/plugin/skills/testing-quality.md +0 -4
- package/dist/assets/plugin/skills/web-visualize/SKILL.md +17 -0
- package/dist/assets/plugin/skills/web-visualize/agents/openai.yaml +6 -0
- package/dist/assets/plugin/skills/writing-instructions/SKILL.md +7 -9
- package/dist/assets/plugin/skills/writing-instructions/agents/openai.yaml +1 -1
- package/dist/index.js +51 -53
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -1,58 +1,66 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`,r+=2;continue}if(n==="t"){t+="\t",r+=2;continue}if(n==="r"){t+="\r",r+=2;continue}if(n==="\\"){t+="\\",r+=2;continue}if(n==='"'){t+='"',r+=2;continue}if(n==="u"){if(r+6>e.length)throw SyntaxError(`Invalid escape sequence: truncated \\u escape at "${e.slice(r,r+6)}"`);let o=e.slice(r+2,r+6);if(!/^[0-9a-f]{4}$/i.test(o))throw SyntaxError(`Invalid escape sequence: \\u must be followed by 4 hex digits, got "${o}"`);let i=Number.parseInt(o,16);if(i>=55296&&i<=57343)throw SyntaxError(`Invalid escape sequence: \\u${o} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`);t+=String.fromCodePoint(i),r+=6;continue}throw SyntaxError(`Invalid escape sequence: \\${n}`)}t+=e[r],r++}return t}function nc(e,t){let r=t+1;while(r<e.length){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==='"')return r;r++}return-1}function dt(e,t,r=0){let n=!1,o=r;while(o<e.length){if(e[o]==="\\"&&o+1<e.length&&n){o+=2;continue}if(e[o]==='"'){n=!n,o++;continue}if(e[o]===t&&!n)return o;o++}return-1}var Re=class extends SyntaxError{constructor(e,t){let r=t?.line!==void 0?`Line ${t.line}: `:"";super(r+e,t?.cause!==void 0?{cause:t.cause}:void 0);this.name="ToonDecodeError",this.line=t?.line,this.source=t?.source}};function ft(e,t){try{return t()}catch(r){if(r instanceof Re)throw r;if(r instanceof Error)throw new Re(r.message,{line:e.lineNumber,source:e.raw,cause:r});throw r}}var GA=/^[ \t]*/;function JA(){return{lineNumber:0,blankLines:[]}}function YA(e,t,r,n){t.lineNumber++;let o=t.lineNumber;if(o===1&&e[0]==="\uFEFF")e=e.slice(1);if(e[e.length-1]==="\r")e=e.slice(0,-1);let i=GA.exec(e)[0],s=i.indexOf("\t"),a=n&&s!==-1?s:i.length,c=n||s===-1?0:i.split("\t").length-1,l=QA(e.slice(a));if(s===-1&&l[0]==="#")return;let u=ZA(a-c,r)+c;if(!l){t.blankLines.push({lineNumber:o,indent:a,depth:u});return}if(n){if(s!==-1)throw new Re("Tabs are not allowed in indentation in strict mode",{line:o,source:e});if(a>0&&a%r!==0)throw new Re(`Indentation must be exact multiple of ${r}, but found ${a} spaces`,{line:o,source:e})}return{raw:e,indent:a,content:l,depth:u,lineNumber:o}}function ZA(e,t){return Math.floor(e/t)}function QA(e){let t=e.length;while(t>0&&e[t-1]===" ")t--;return t===e.length?e:e.slice(0,t)}var kg=Symbol("fetch-line");function XA(e){return{buffer:[],done:!1,lastLine:void 0,scanState:JA(),indentSize:e.indentSize,strict:e.strict}}function*Rg(e){while(e.buffer.length===0&&!e.done){let t=yield kg;if(t===void 0){e.done=!0;return}let r=YA(t,e.scanState,e.indentSize,e.strict);if(r!==void 0)e.buffer.push(r)}}function*$t(e){return yield*Rg(e),e.buffer[0]}function*Pt(e){yield*Rg(e);let t=e.buffer[0];if(t!==void 0)e.buffer.shift(),e.lastLine=t;return t}function*eT(e,t){let r=e[Symbol.iterator](),n=t.next();while(!n.done)if(n.value===kg){let o=r.next();n=t.next(o.done?void 0:o.value)}else yield n.value,n=t.next()}var tT=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Cg(e){return e==="true"||e==="false"||e==="null"}function rT(e){if(!e)return!1;if(!tT.test(e))return!1;let t=Number(e);return!Number.isNaN(t)&&Number.isFinite(t)}function Xa(e,t){let r=e.trimStart(),n=-1;if(r.startsWith('"')){let k=nc(r,0);if(k===-1)return{kind:"notHeader"};if(!r.slice(k+1).startsWith("["))return{kind:"notHeader"};let C=e.length-r.length+k+1;n=e.indexOf("[",C)}else n=dt(e,"[");if(n===-1)return{kind:"notHeader"};let o=dt(e,":");if(o!==-1&&o<n)return{kind:"notHeader"};let i=dt(e,"]",n);if(i===-1)return{kind:"notHeader"};let s=i+1,a=s,c=dt(e,"{",i);if(c!==-1&&c<dt(e,":",i)){let k=e.slice(i+1,c);if(k!==""){let V=k.trim();return{kind:"invalid",reason:V===""?"Unexpected whitespace between bracket segment and field list":`Unexpected content "${V}" between bracket segment and field list`}}let C=dp(e,c);if(C!==-1)a=C+1}if(s=dt(e,":",Math.max(i,a)),s===-1)return{kind:"notHeader"};let l=Math.max(i+1,a),u=e.slice(l,s);if(u!==""){let k=u.trim();return{kind:"invalid",reason:k===""?"Unexpected whitespace between bracket segment and colon":`Unexpected content "${k}" between bracket segment and colon`}}let d;if(n>0){let k=e.slice(0,n);if(k!==k.trimEnd())return{kind:"invalid",reason:"Unexpected whitespace between key and bracket segment"};d=k.startsWith('"')?ec(k):k}let f=bt(e.slice(s+1)),h=e.slice(n+1,i),g;try{g=oT(h,t)}catch(k){return{kind:"invalid",reason:k.message}}let{length:O,delimiter:S,keyed:v}=g,G;if(c!==-1&&c<s){let k=dp(e,c);if(k!==-1&&k<s){let C=e.slice(c+1,k),V=aT(C,S);if(V!==void 0)return{kind:"invalid",reason:`Header delimiter mismatch: bracket declares "${_g(S)}" but field list contains unquoted "${_g(V)}"`};try{G=Pg(C,S)}catch(F){return{kind:"invalid",reason:F.message}}}}let q=G?Fg(G):void 0,j=q?`Duplicate field name "${q}" in field list`:void 0;if(v&&!G)return{kind:"invalid",reason:"Keyed header requires a field list"};if(G&&f)return{kind:"invalid",reason:j??"Unexpected content after fields-bearing header colon"};return{kind:"header",header:{key:d,length:O,delimiter:S,fields:G,keyed:v},inlineValues:f||void 0,strictError:j}}var nT=/^(?:0|[1-9]\d*)$/;function oT(e,t){let r=e,n=t;if(r.endsWith("\t"))n=Qa.tab,r=r.slice(0,-1);else if(r.endsWith("|"))n=Qa.pipe,r=r.slice(0,-1);let o=!1;if(r.endsWith(":"))o=!0,r=r.slice(0,-1);if(!nT.test(r))throw SyntaxError(`Invalid array length: "${e}" (expected non-negative integer with no leading zeros)`);return{length:Number.parseInt(r,10),delimiter:n,keyed:o}}function Pg(e,t){return iT(e,t).map((r)=>{let n=bt(r);if(!n)throw SyntaxError("Empty field name in field list");let o=dt(n,"{");if(o===-1)return{name:ec(n)};let i=bt(n.slice(0,o));if(!i)throw SyntaxError("Missing field name before nested field group");let s=dp(n,o);if(s===-1)throw SyntaxError("Unmatched brace in field list");if(s!==n.length-1)throw SyntaxError("Unexpected content after nested field group");let a=Pg(n.slice(o+1,s),t);return{name:ec(i),children:a}})}function iT(e,t){let r=[],n="",o=!1,i=0,s=0;while(s<e.length){let a=e[s];if(a==="\\"&&s+1<e.length&&o){n+=a+e[s+1],s+=2;continue}if(a==='"'){o=!o,n+=a,s++;continue}if(!o){if(a==="{")i++;else if(a==="}")i--;else if(a===t&&i===0){r.push(n),n="",s++;continue}}n+=a,s++}return r.push(n),r}function dp(e,t){let r=!1,n=0,o=t;while(o<e.length){let i=e[o];if(i==="\\"&&o+1<e.length&&r){o+=2;continue}if(i==='"'){r=!r,o++;continue}if(!r){if(i==="{")n++;else if(i==="}"){if(n--,n===0)return o}}o++}return-1}function Fg(e){let t=new Set;for(let r of e){if(t.has(r.name))return r.name;if(t.add(r.name),r.children){let n=Fg(r.children);if(n!==void 0)return n}}}function hp(e){let t=0;for(let r of e)t+=r.children?hp(r.children):1;return t}var sT=[",","\t","|"];function aT(e,t){for(let r of sT){if(r===t)continue;if(dt(e,r)!==-1)return r}}function _g(e){if(e==="\t")return"\\t";return e}function gp(e,t){let r=[],n="",o=!1,i=0;while(i<e.length){let s=e[i];if(s==="\\"&&i+1<e.length&&o){n+=s+e[i+1],i+=2;continue}if(s==='"'){o=!o,n+=s,i++;continue}if(s===t&&!o){r.push(bt(n)),n="",i++;continue}n+=s,i++}if(n||r.length>0)r.push(bt(n));return r}function yp(e){return e.map((t)=>oc(t))}function oc(e){let t=bt(e);if(!t)return"";if(t.startsWith('"'))return ec(t);if(Cg(t)){if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null}if(rT(t)){let r=Number.parseFloat(t);return Object.is(r,-0)?0:r}return t}function ec(e){let t=bt(e);if(t.startsWith('"')){let r=nc(t,0);if(r===-1)throw SyntaxError("Unterminated string: missing closing quote");if(r!==t.length-1)throw SyntaxError("Unexpected characters after closing quote");return Ig(t.slice(1,r))}return t}function cT(e,t){let r=dt(e,":",t);if(r===-1)throw SyntaxError("Missing colon after key");return{key:bt(e.slice(t,r)),end:r+1}}function lT(e,t){let r=nc(e,t);if(r===-1)throw SyntaxError("Unterminated quoted key");let n=Ig(e.slice(t+1,r)),o=r+1;if(o>=e.length||e[o]!==":")throw SyntaxError("Missing colon after key");return o++,{key:n,end:o}}function Ng(e,t){return e[t]==='"'?lT(e,t):cT(e,t)}function Mg(e){return e.trim().startsWith("[")&&dt(e,":")!==-1}function uT(e){return dt(e,":")!==-1}function no(e,t,r,n,o){if(n.strict&&e!==t)throw new Re(`Expected ${t} ${r}, but got ${e}`,{line:o.lineNumber,source:o.raw})}function pT(e,t,r){if(e?.depth===t&&e.content.startsWith("- "))throw new Re(`Expected ${r} list-form items, but found more`,{line:e.lineNumber,source:e.raw})}function dT(e,t,r){if(e?.depth===t&&!e.content.startsWith("- ")&&Lg(e.content,r.delimiter))throw new Re(`Expected ${r.length} tabular rows, but found more`,{line:e.lineNumber,source:e.raw})}function xp(e,t,r,n,o){if(!n)return;let i=r.find((s)=>s.lineNumber>e&&s.lineNumber<t);if(i)throw new Re(`Blank lines inside ${o} are not allowed in strict mode`,{line:i.lineNumber})}function Lg(e,t){let r=dt(e,":"),n=dt(e,t);if(r===-1)return!0;if(n!==-1&&n<r)return!0;return!1}function fT(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}function mT(e,t){let r=fT(t);return eT(e,hT(XA(r),r))}function*hT(e,t){let r=yield*$t(e);if(!r){yield{type:"startObject"},yield{type:"endObject"};return}if(bt(r.content)==="[]"){yield*Pt(e),yield{type:"startArray",length:0},yield{type:"endArray"},yield*wg(e,t.strict);return}if(Mg(r.content)){let i=ft(r,()=>rc(Xa(r.content,qr),t.strict));if(i){yield*Pt(e),yield*tc(i.header,i.inlineValues,e,0,t,r),yield*wg(e,t.strict);return}}yield*Pt(e);let n=yield*$t(e);if(n===void 0&&!Og(r)){yield{type:"primitive",value:ft(r,()=>oc(r.content))};return}if(!Og(r)&&n?.depth===0)throw new Re("Top-level document must start with a key-value or array-header line",{line:r.lineNumber,source:r.raw});let o=t.strict?new Set:void 0;yield{type:"startObject"},yield*cs(r,e,0,t,o);while(!0){let i=yield*$t(e);if(!i)break;if(i.depth!==0){if(t.strict)throw Dg(i,0);qg(i),yield*Pt(e);continue}yield*Pt(e),yield*cs(i,e,0,t,o)}yield{type:"endObject"}}function gT(e,t,r){if(r&&e.depth>t+1)throw new Re(`Indentation depth jump: expected depth ${t+1}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function Dg(e,t){return new Re(`Over-indented line: expected depth ${t}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function qg(e){if(e.content.startsWith("- ")||e.content==="-"||dt(e.content,":")!==-1)return;throw new Re("Unexpected bare token line outside root primitive position",{line:e.lineNumber,source:e.raw})}function Ug(e){return new Re("Keyless keyed header is only valid at the document root",{line:e.lineNumber,source:e.raw})}function yT(e){return new Re("Keyless array header is only valid at the document root or as a list item",{line:e.lineNumber,source:e.raw})}function xT(e){return new Re("Keyless header with a field list is only valid at the document root",{line:e.lineNumber,source:e.raw})}function*wg(e,t){if(!t)return;let r=yield*$t(e);if(r)throw new Re("Unexpected content after the document root",{line:r.lineNumber,source:r.raw})}function fp(e,t,r){if(!r)return;if(r.has(e))throw new Re(`Duplicate sibling key "${e}"`,{line:t.lineNumber,source:t.raw});r.add(e)}function*cs(e,t,r,n,o){let i=e.content,s=ft(e,()=>rc(Xa(i,qr),n.strict));if(s&&s.header.key!==void 0){fp(s.header.key,e,o),yield{type:"key",key:s.header.key},yield*tc(s.header,s.inlineValues,t,r,n,e);return}if(s&&s.header.key===void 0&&n.strict)throw s.header.keyed?Ug(e):yT(e);let{key:a,end:c}=ft(e,()=>Ng(i,0)),l=bt(i.slice(c));if(fp(a,e,o),yield{type:"key",key:a},!l){let u=yield*$t(t);if(u&&u.depth>r){gT(u,r,n.strict),yield{type:"startObject"},yield*ST(t,r+1,n),yield{type:"endObject"};return}yield{type:"startObject"},yield{type:"endObject"};return}if(l==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}yield{type:"primitive",value:ft(e,()=>oc(l))}}function*ST(e,t,r){let n,o=r.strict?new Set:void 0;while(!0){let i=yield*$t(e);if(!i||i.depth<t)break;if(n===void 0&&i.depth>=t)n=i.depth;if(i.depth===n)yield*Pt(e),yield*cs(i,e,n,r,o);else if(n!==void 0&&i.depth>n){if(r.strict)throw Dg(i,n);qg(i),yield*Pt(e)}else break}}function*tc(e,t,r,n,o,i){if(e.keyed){yield*_T(e,r,n,o,i);return}if(yield{type:"startArray",length:e.length},t){yield*bT(e,t,o,i),yield{type:"endArray"};return}if(e.fields&&e.fields.length>0){yield*wT(e,r,n,o,i),yield{type:"endArray"};return}yield*ET(e,r,n,o,i),yield{type:"endArray"}}function*bT(e,t,r,n){if(!bt(t)){no(0,e.length,"inline-form values",r,n);return}let o=ft(n,()=>gp(t,e.delimiter)),i=ft(n,()=>yp(o));no(i.length,e.length,"inline-form values",r,n);for(let s of i)yield{type:"primitive",value:s}}function*_T(e,t,r,n,o){let i=r+1,s=hp(e.fields),a=n.strict?new Set:void 0,c=0,l,u,d=o;yield{type:"startObject"};while(!0){let f=yield*$t(t);if(!f||f.depth<=r)break;if(f.depth>i){if(n.strict)throw new Re("Unexpected indentation inside keyed tabular object",{line:f.lineNumber,source:f.raw});yield*Pt(t);continue}if(dt(f.content,":")===-1){if(n.strict)throw new Re("Expected entry row inside keyed tabular object",{line:f.lineNumber,source:f.raw});yield*Pt(t);continue}if(yield*Pt(t),l===void 0)l=f.lineNumber;u=f.lineNumber,d=f;let{key:h,end:g}=ft(f,()=>Ng(f.content,0));fp(h,f,a),yield{type:"key",key:h};let O=bt(f.content.slice(g)),S=O===""?[]:ft(f,()=>gp(O,e.delimiter));no(S.length,s,"keyed entry cells",n,f);let v=ft(f,()=>yp(S));yield*Hg(e.fields,v),c++}if(no(c,e.length,"keyed entries",n,d),n.strict&&l!==void 0&&u!==void 0)xp(l,u,t.scanState.blankLines,n.strict,"keyed tabular object");yield{type:"endObject"}}function*wT(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*$t(t);if(!u||u.depth<i)break;if(u.depth===i){if(!Lg(u.content,e.delimiter))break;if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*Pt(t);let d=ft(u,()=>gp(u.content,e.delimiter));no(d.length,hp(e.fields),"tabular row values",n,u);let f=ft(u,()=>yp(d));yield*Hg(e.fields,f),s++}else break}if(no(s,e.length,"tabular rows",n,l),n.strict&&a!==void 0&&c!==void 0)xp(a,c,t.scanState.blankLines,n.strict,"tabular array");if(n.strict)dT(yield*$t(t),i,e)}function*ET(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*$t(t);if(!u||u.depth<i)break;let d=u.content.startsWith("- ")||u.content==="-";if(u.depth===i&&d){if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*OT(t,i,n);let f=t.lastLine;if(f)c=f.lineNumber,l=f;s++}else break}if(no(s,e.length,"list-form items",n,l),n.strict&&a!==void 0&&c!==void 0)xp(a,c,t.scanState.blankLines,n.strict,"list-form array");if(n.strict)pT(yield*$t(t),i,e.length)}function*OT(e,t,r){let n=yield*Pt(e);if(!n)throw ReferenceError("Expected list item");let o;if(n.content==="-"){yield{type:"startObject"},yield{type:"endObject"};return}else if(n.content.startsWith("- "))o=n.content.slice(2);else throw new Re('Expected list item to start with "- "',{line:n.lineNumber,source:n.raw});if(!bt(o)){yield{type:"startObject"},yield{type:"endObject"};return}if(bt(o)==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}let i={...n,content:o};if(Mg(o)){let a=ft(i,()=>rc(Xa(o,qr),r.strict));if(a)if(a.header.keyed||a.header.fields!==void 0){if(r.strict)throw a.header.keyed?Ug(i):xT(i)}else{yield*tc(a.header,a.inlineValues,e,t,r,i);return}}let s=ft(i,()=>rc(Xa(o,qr),r.strict));if(s&&s.header.key!==void 0&&s.header.fields!==void 0){let a=s.header,c=r.strict?new Set([a.key]):void 0;yield{type:"startObject"},yield{type:"key",key:a.key},yield*tc(a,s.inlineValues,e,t+1,r,i),yield*Eg(e,t+1,r,c),yield{type:"endObject"};return}if(uT(o)){let a=r.strict?new Set:void 0;yield{type:"startObject"},yield*cs(i,e,t+1,r,a),yield*Eg(e,t+1,r,a),yield{type:"endObject"};return}yield{type:"primitive",value:ft(i,()=>oc(o))}}function*Eg(e,t,r,n){while(!0){let o=yield*$t(e);if(!o||o.depth<t)break;if(o.depth===t&&!o.content.startsWith("- "))yield*Pt(e),yield*cs(o,e,t,r,n);else break}}function Og(e){let t=e.content;if(t.startsWith('"')){let r=nc(t,0);if(r===-1)return!1;return t.slice(r+1).includes(":")}else return t.includes(":")}function rc(e,t){if(e.kind==="notHeader")return;if(e.kind==="invalid"){if(t)throw SyntaxError(e.reason);return}if(t&&e.strictError!==void 0)throw SyntaxError(e.strictError);return{header:e.header,inlineValues:e.inlineValues}}function*Hg(e,t){let r=0;function*n(o){yield{type:"startObject"};for(let i of o){if(!i.children&&r>=t.length)continue;if(yield{type:"key",key:i.name},i.children)yield*n(i.children);else yield{type:"primitive",value:t[r++]}}yield{type:"endObject"}}yield*n(e)}function as(e,t,r){if(t==="__proto__"){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0});return}e[t]=r}function vT(e){let t={stack:[],root:void 0};for(let r of e)AT(t,r);return TT(t)}function AT(e,t){let{stack:r}=e;switch(t.type){case"startObject":{let n={};if(r.length===0)r.push({type:"object",obj:n});else{let o=r[r.length-1];if(o.type==="object"){if(o.currentKey===void 0)throw Error("Object startObject event without preceding key");as(o.obj,o.currentKey,n),o.currentKey=void 0}else if(o.type==="array")o.arr.push(n);r.push({type:"object",obj:n})}break}case"endObject":{if(r.length===0)throw Error("Unexpected endObject event");let n=r.pop();if(n.type!=="object")throw Error("Mismatched endObject event");if(r.length===0)e.root=n.obj;break}case"startArray":{let n=[];if(r.length===0)r.push({type:"array",arr:n});else{let o=r[r.length-1];if(o.type==="object"){if(o.currentKey===void 0)throw Error("Array startArray event without preceding key");as(o.obj,o.currentKey,n),o.currentKey=void 0}else if(o.type==="array")o.arr.push(n);r.push({type:"array",arr:n})}break}case"endArray":{if(r.length===0)throw Error("Unexpected endArray event");let n=r.pop();if(n.type!=="array")throw Error("Mismatched endArray event");if(r.length===0)e.root=n.arr;break}case"key":{if(r.length===0)throw Error("Key event outside of object context");let n=r[r.length-1];if(n.type!=="object")throw Error("Key event outside of object context");n.currentKey=t.key;break}case"primitive":if(r.length===0)e.root=t.value;else{let n=r[r.length-1];if(n.type==="object"){if(n.currentKey===void 0)throw Error("Primitive event without preceding key in object");as(n.obj,n.currentKey,t.value),n.currentKey=void 0}else if(n.type==="array")n.arr.push(t.value)}break}}function TT(e){if(e.stack.length!==0)throw Error("Incomplete event stream: unclosed objects or arrays");if(e.root===void 0)throw Error("No root value built from events");return e.root}var IT=new RegExp("(?:^\uFEFF?|\\n) *#"),kT=class{constructor(e){if(IT.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function ps(e){return e instanceof kT}var RT=/[\uD800-\uDFFF]/;function ro(e){if(e===null)return null;if(ps(e))return e;if(typeof e==="object"&&e!==null&&"toJSON"in e&&typeof e.toJSON==="function"){let t=e.toJSON();if(t!==e)return ro(t)}if(typeof e==="string")return vg(e,"string value"),e;if(typeof e==="boolean")return e;if(typeof e==="number"){if(Object.is(e,-0))return 0;if(!Number.isFinite(e))return null;return e}if(typeof e==="bigint"){if(e>=Number.MIN_SAFE_INTEGER&&e<=Number.MAX_SAFE_INTEGER)return Number(e);return e.toString()}if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(ro);if(e instanceof Set)return Array.from(e).map(ro);if(e instanceof Map)return Object.fromEntries(Array.from(e,([t,r])=>[String(t),ro(r)]));if(PT(e)){let t={};for(let r in e)if(Object.hasOwn(e,r))vg(r,"object key"),as(t,r,ro(e[r]));return t}return null}function vg(e,t){if(!RT.test(e))return;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n<55296||n>57343)continue;let o=n<=56319,i=e.charCodeAt(r+1);if(o&&i>=56320&&i<=57343){r++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${n.toString(16).toUpperCase()} at index ${r}`)}}function CT(e){return e===null||typeof e==="string"||typeof e==="number"||typeof e==="boolean"}function io(e){return CT(e)||ps(e)}function oo(e){return Array.isArray(e)}function Ur(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&!ps(e)}function ls(e){return Object.keys(e).length===0}function PT(e){if(e===null||typeof e!=="object")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function us(e){return e.length===0||e.every((t)=>io(t))}function FT(e){return e.length===0||e.every((t)=>oo(t))}function jg(e){return e.length===0||e.every((t)=>Ur(t))}var NT=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function MT(e){if(!Object.values(Qa).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function LT(e){return/^[A-Z_][\w.]*$/i.test(e)}function DT(e,t=qr){if(!e)return!1;if(/^[ \t]|[ \t]$/.test(e))return!1;if(Cg(e)||qT(e))return!1;if(e.includes(":"))return!1;if(e.includes('"')||e.includes("\\"))return!1;if(/[[\]{}]/.test(e))return!1;if(/[\u0000-\u001F]/.test(e))return!1;if(e.includes(t))return!1;if(e.startsWith("-"))return!1;if(e.startsWith("#"))return!1;return!0}function qT(e){return NT.test(e)}function ds(e,t){if(ps(e))return e.value;if(e===null)return"null";if(typeof e==="boolean")return String(e);if(typeof e==="number")return String(e);return UT(e,t)}function UT(e,t=qr){if(DT(e,t))return e;return`"${Tg(e)}"`}function ti(e){if(LT(e))return e;return`"${Tg(e)}"`}function Sp(e,t=qr){return e.map((r)=>ds(r,t)).join(t)}function Dr(e,t){let r=t?.key,n=t?.fields,o=t?.delimiter??",",i="";if(r!=null)i+=ti(r);if(i+=`[${e}${t?.keyed?":":""}${o!==qr?o:""}]`,n)i+=`{${$g(n,o)}}`;return i+=":",i}function $g(e,t){return e.map((r)=>ti(r.name)+(r.children?`{${$g(r.children,t)}}`:"")).join(t)}function ic(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let o of t)if(!Object.hasOwn(n,o))return}let r=[];for(let n of t){let o=HT(n,e.map((i)=>i[n]));if(!o)return;r.push(o)}return r}function bp(e){let t=Object.values(e);if(t.length<2)return;if(!t.every((r)=>Ur(r)&&!ls(r)))return;return ic(t)}function Bg(e,t){let r=[];return Kg(e,t,r),r}function HT(e,t){if(t.every((n)=>io(n)))return{name:e};if(!t.every((n)=>Ur(n)&&!ls(n)))return;let r=ic(t);if(!r)return;return{name:e,children:r}}function Kg(e,t,r){for(let n of t){let o=e[n.name];if(n.children)Kg(o,n.children,r);else r.push(o)}}function*jT(e,t,r){if(io(e)){let n=ds(e,t.delimiter);if(n!=="")yield n;return}if(oo(e))yield*zg(void 0,e,r,t);else if(Ur(e)){let n=bp(e);if(n){yield*Wg(void 0,e,n,r,t);return}yield*ei(e,r,t)}}function*ei(e,t,r){for(let[n,o]of Object.entries(e))yield*$T(n,o,t,r)}function*$T(e,t,r,n){let o=ti(e);if(io(t))yield Bt(r,`${o}: ${ds(t,n.delimiter)}`,n.indentSize);else if(oo(t))yield*zg(e,t,r,n);else if(Ur(t)){let i=bp(t);if(i){yield*Wg(e,t,i,r,n);return}if(yield Bt(r,`${o}:`,n.indentSize),!ls(t))yield*ei(t,r+1,n)}}function*Wg(e,t,r,n,o){let i=Object.entries(t);yield Bt(n,Dr(i.length,{key:e,fields:r,delimiter:o.delimiter,keyed:!0}),o.indentSize),yield*Vg(i,r,n+1,o)}function*Vg(e,t,r,n){for(let[o,i]of e){let s=Bg(i,t);yield Bt(r,`${ti(o)}: ${Sp(s,n.delimiter)}`,n.indentSize)}}function*zg(e,t,r,n){if(t.length===0){yield Bt(r,e!=null?`${ti(e)}: []`:"[]",n.indentSize);return}if(us(t)){yield Bt(r,sc(t,n.delimiter,e),n.indentSize);return}if(FT(t)){if(t.every((o)=>us(o))){yield*BT(e,t,r,n);return}}if(jg(t)){let o=ic(t);if(o)yield*KT(e,t,o,r,n);else yield*Ag(e,t,r,n);return}yield*Ag(e,t,r,n)}function*BT(e,t,r,n){yield Bt(r,Dr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)if(us(o)){let i=sc(o,n.delimiter);yield tr(r+1,i,n.indentSize)}}function sc(e,t,r){let n=Dr(e.length,{key:r,delimiter:t}),o=Sp(e,t);if(e.length===0)return n;return`${n} ${o}`}function*KT(e,t,r,n,o){yield Bt(n,Dr(t.length,{key:e,fields:r,delimiter:o.delimiter}),o.indentSize),yield*Gg(t,r,n+1,o)}function*Gg(e,t,r,n){for(let o of e)yield Bt(r,Sp(Bg(o,t),n.delimiter),n.indentSize)}function*Ag(e,t,r,n){yield Bt(r,Dr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)yield*_p(o,r+1,n)}function*WT(e,t,r){if(ls(e)){yield Bt(t,"-",r.indentSize);return}let n=Object.entries(e),[o,i]=n[0],s=n.slice(1);if(oo(i)&&jg(i)){let c=ic(i);if(c){if(yield tr(t,Dr(i.length,{key:o,fields:c,delimiter:r.delimiter}),r.indentSize),yield*Gg(i,c,t+2,r),s.length>0)yield*ei(Object.fromEntries(s),t+1,r);return}}if(Ur(i)){let c=bp(i);if(c){let l=Object.entries(i);if(yield tr(t,Dr(l.length,{key:o,fields:c,delimiter:r.delimiter,keyed:!0}),r.indentSize),yield*Vg(l,c,t+2,r),s.length>0)yield*ei(Object.fromEntries(s),t+1,r);return}}let a=ti(o);if(io(i))yield tr(t,`${a}: ${ds(i,r.delimiter)}`,r.indentSize);else if(oo(i))if(i.length===0)yield tr(t,`${a}: []`,r.indentSize);else if(us(i))yield tr(t,`${a}${sc(i,r.delimiter)}`,r.indentSize);else{yield tr(t,`${a}${Dr(i.length,{delimiter:r.delimiter})}`,r.indentSize);for(let c of i)yield*_p(c,t+2,r)}else if(Ur(i)){if(yield tr(t,`${a}:`,r.indentSize),!ls(i))yield*ei(i,t+2,r)}if(s.length>0)yield*ei(Object.fromEntries(s),t+1,r)}function*_p(e,t,r){if(io(e))yield tr(t,ds(e,r.delimiter),r.indentSize);else if(oo(e))if(us(e))yield tr(t,sc(e,r.delimiter),r.indentSize);else{yield tr(t,Dr(e.length,{delimiter:r.delimiter}),r.indentSize);for(let n of e)yield*_p(n,t+1,r)}else if(Ur(e))yield*WT(e,t,r)}function Bt(e,t,r){return" ".repeat(r*e)+t}function tr(e,t,r){return Bt(e,"- "+t,r)}function VT(e,t){let r=t("",e,[]);if(r===void 0)return mp(e,t,[]);return wp(e,r,t,[])}function wp(e,t,r,n){if(ps(t)&&!io(e))return mp(e,r,n);return mp(ro(t),r,n)}function mp(e,t,r){if(Ur(e))return zT(e,t,r);if(oo(e))return GT(e,t,r);return e}function zT(e,t,r){let n={};for(let[o,i]of Object.entries(e)){let s=[...r,o],a=t(o,i,s);if(a===void 0)continue;as(n,o,wp(i,a,t,s))}return n}function GT(e,t,r){let n=[];for(let o=0;o<e.length;o++){let i=e[o],s=[...r,o],a=t(String(o),i,s);if(a===void 0)continue;n.push(wp(i,a,t,s))}return n}function mt(e,t){return Array.from(JT(e,t)).join(`
|
|
5
|
-
`)}function
|
|
6
|
-
`),t)}function
|
|
3
|
+
var dp="0.15";function br(e,t=new WeakSet){if(t.has(e))return;t.add(e);for(let r of Reflect.ownKeys(e)){let n=Object.getOwnPropertyDescriptor(e,r);if(n&&"value"in n&&fp(n.value))br(n.value,t)}Object.freeze(e)}function fp(e){return typeof e==="object"&&e!==null}var tc={comma:",",tab:"\t",pipe:"|"},qr=tc.comma;function bt(e){let t=0,r=e.length;while(t<r&&e[t]===" ")t++;while(r>t&&e[r-1]===" ")r--;return t===0&&r===e.length?e:e.slice(t,r)}function Cg(e){return e.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/[\u0000-\u001F]/g,(t)=>`\\u${t.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Pg(e){let t="",r=0;while(r<e.length){if(e[r]==="\\"){if(r+1>=e.length)throw SyntaxError("Invalid escape sequence: backslash at end of string");let n=e[r+1];if(n==="n"){t+=`
|
|
4
|
+
`,r+=2;continue}if(n==="t"){t+="\t",r+=2;continue}if(n==="r"){t+="\r",r+=2;continue}if(n==="\\"){t+="\\",r+=2;continue}if(n==='"'){t+='"',r+=2;continue}if(n==="u"){if(r+6>e.length)throw SyntaxError(`Invalid escape sequence: truncated \\u escape at "${e.slice(r,r+6)}"`);let o=e.slice(r+2,r+6);if(!/^[0-9a-f]{4}$/i.test(o))throw SyntaxError(`Invalid escape sequence: \\u must be followed by 4 hex digits, got "${o}"`);let i=Number.parseInt(o,16);if(i>=55296&&i<=57343)throw SyntaxError(`Invalid escape sequence: \\u${o} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`);t+=String.fromCodePoint(i),r+=6;continue}throw SyntaxError(`Invalid escape sequence: \\${n}`)}t+=e[r],r++}return t}function sc(e,t){let r=t+1;while(r<e.length){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==='"')return r;r++}return-1}function ft(e,t,r=0){let n=!1,o=r;while(o<e.length){if(e[o]==="\\"&&o+1<e.length&&n){o+=2;continue}if(e[o]==='"'){n=!n,o++;continue}if(e[o]===t&&!n)return o;o++}return-1}var ke=class extends SyntaxError{constructor(e,t){let r=t?.line!==void 0?`Line ${t.line}: `:"";super(r+e,t?.cause!==void 0?{cause:t.cause}:void 0);this.name="ToonDecodeError",this.line=t?.line,this.source=t?.source}};function mt(e,t){try{return t()}catch(r){if(r instanceof ke)throw r;if(r instanceof Error)throw new ke(r.message,{line:e.lineNumber,source:e.raw,cause:r});throw r}}var XA=/^[ \t]*/;function eT(){return{lineNumber:0,blankLines:[]}}function tT(e,t,r,n){t.lineNumber++;let o=t.lineNumber;if(o===1&&e[0]==="\uFEFF")e=e.slice(1);if(e[e.length-1]==="\r")e=e.slice(0,-1);let i=XA.exec(e)[0],s=i.indexOf("\t"),a=n&&s!==-1?s:i.length,c=n||s===-1?0:i.split("\t").length-1,l=nT(e.slice(a));if(s===-1&&l[0]==="#")return;let u=rT(a-c,r)+c;if(!l){t.blankLines.push({lineNumber:o,indent:a,depth:u});return}if(n){if(s!==-1)throw new ke("Tabs are not allowed in indentation in strict mode",{line:o,source:e});if(a>0&&a%r!==0)throw new ke(`Indentation must be exact multiple of ${r}, but found ${a} spaces`,{line:o,source:e})}return{raw:e,indent:a,content:l,depth:u,lineNumber:o}}function rT(e,t){return Math.floor(e/t)}function nT(e){let t=e.length;while(t>0&&e[t-1]===" ")t--;return t===e.length?e:e.slice(0,t)}var Ng=Symbol("fetch-line");function oT(e){return{buffer:[],done:!1,lastLine:void 0,scanState:eT(),indentSize:e.indentSize,strict:e.strict}}function*Fg(e){while(e.buffer.length===0&&!e.done){let t=yield Ng;if(t===void 0){e.done=!0;return}let r=tT(t,e.scanState,e.indentSize,e.strict);if(r!==void 0)e.buffer.push(r)}}function*jt(e){return yield*Fg(e),e.buffer[0]}function*Ct(e){yield*Fg(e);let t=e.buffer[0];if(t!==void 0)e.buffer.shift(),e.lastLine=t;return t}function*iT(e,t){let r=e[Symbol.iterator](),n=t.next();while(!n.done)if(n.value===Ng){let o=r.next();n=t.next(o.done?void 0:o.value)}else yield n.value,n=t.next()}var sT=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Mg(e){return e==="true"||e==="false"||e==="null"}function aT(e){if(!e)return!1;if(!sT.test(e))return!1;let t=Number(e);return!Number.isNaN(t)&&Number.isFinite(t)}function rc(e,t){let r=e.trimStart(),n=-1;if(r.startsWith('"')){let T=sc(r,0);if(T===-1)return{kind:"notHeader"};if(!r.slice(T+1).startsWith("["))return{kind:"notHeader"};let I=e.length-r.length+T+1;n=e.indexOf("[",I)}else n=ft(e,"[");if(n===-1)return{kind:"notHeader"};let o=ft(e,":");if(o!==-1&&o<n)return{kind:"notHeader"};let i=ft(e,"]",n);if(i===-1)return{kind:"notHeader"};let s=i+1,a=s,c=ft(e,"{",i);if(c!==-1&&c<ft(e,":",i)){let T=e.slice(i+1,c);if(T!==""){let C=T.trim();return{kind:"invalid",reason:C===""?"Unexpected whitespace between bracket segment and field list":`Unexpected content "${C}" between bracket segment and field list`}}let I=mp(e,c);if(I!==-1)a=I+1}if(s=ft(e,":",Math.max(i,a)),s===-1)return{kind:"notHeader"};let l=Math.max(i+1,a),u=e.slice(l,s);if(u!==""){let T=u.trim();return{kind:"invalid",reason:T===""?"Unexpected whitespace between bracket segment and colon":`Unexpected content "${T}" between bracket segment and colon`}}let d;if(n>0){let T=e.slice(0,n);if(T!==T.trimEnd())return{kind:"invalid",reason:"Unexpected whitespace between key and bracket segment"};d=T.startsWith('"')?nc(T):T}let f=bt(e.slice(s+1)),g=e.slice(n+1,i),y;try{y=lT(g,t)}catch(T){return{kind:"invalid",reason:T.message}}let{length:O,delimiter:m,keyed:x}=y,D;if(c!==-1&&c<s){let T=mp(e,c);if(T!==-1&&T<s){let I=e.slice(c+1,T),C=dT(I,m);if(C!==void 0)return{kind:"invalid",reason:`Header delimiter mismatch: bracket declares "${vg(m)}" but field list contains unquoted "${vg(C)}"`};try{D=Lg(I,m)}catch(M){return{kind:"invalid",reason:M.message}}}}let k=D?Dg(D):void 0,j=k?`Duplicate field name "${k}" in field list`:void 0;if(x&&!D)return{kind:"invalid",reason:"Keyed header requires a field list"};if(D&&f)return{kind:"invalid",reason:j??"Unexpected content after fields-bearing header colon"};return{kind:"header",header:{key:d,length:O,delimiter:m,fields:D,keyed:x},inlineValues:f||void 0,strictError:j}}var cT=/^(?:0|[1-9]\d*)$/;function lT(e,t){let r=e,n=t;if(r.endsWith("\t"))n=tc.tab,r=r.slice(0,-1);else if(r.endsWith("|"))n=tc.pipe,r=r.slice(0,-1);let o=!1;if(r.endsWith(":"))o=!0,r=r.slice(0,-1);if(!cT.test(r))throw SyntaxError(`Invalid array length: "${e}" (expected non-negative integer with no leading zeros)`);return{length:Number.parseInt(r,10),delimiter:n,keyed:o}}function Lg(e,t){return uT(e,t).map((r)=>{let n=bt(r);if(!n)throw SyntaxError("Empty field name in field list");let o=ft(n,"{");if(o===-1)return{name:nc(n)};let i=bt(n.slice(0,o));if(!i)throw SyntaxError("Missing field name before nested field group");let s=mp(n,o);if(s===-1)throw SyntaxError("Unmatched brace in field list");if(s!==n.length-1)throw SyntaxError("Unexpected content after nested field group");let a=Lg(n.slice(o+1,s),t);return{name:nc(i),children:a}})}function uT(e,t){let r=[],n="",o=!1,i=0,s=0;while(s<e.length){let a=e[s];if(a==="\\"&&s+1<e.length&&o){n+=a+e[s+1],s+=2;continue}if(a==='"'){o=!o,n+=a,s++;continue}if(!o){if(a==="{")i++;else if(a==="}")i--;else if(a===t&&i===0){r.push(n),n="",s++;continue}}n+=a,s++}return r.push(n),r}function mp(e,t){let r=!1,n=0,o=t;while(o<e.length){let i=e[o];if(i==="\\"&&o+1<e.length&&r){o+=2;continue}if(i==='"'){r=!r,o++;continue}if(!r){if(i==="{")n++;else if(i==="}"){if(n--,n===0)return o}}o++}return-1}function Dg(e){let t=new Set;for(let r of e){if(t.has(r.name))return r.name;if(t.add(r.name),r.children){let n=Dg(r.children);if(n!==void 0)return n}}}function yp(e){let t=0;for(let r of e)t+=r.children?yp(r.children):1;return t}var pT=[",","\t","|"];function dT(e,t){for(let r of pT){if(r===t)continue;if(ft(e,r)!==-1)return r}}function vg(e){if(e==="\t")return"\\t";return e}function xp(e,t){let r=[],n="",o=!1,i=0;while(i<e.length){let s=e[i];if(s==="\\"&&i+1<e.length&&o){n+=s+e[i+1],i+=2;continue}if(s==='"'){o=!o,n+=s,i++;continue}if(s===t&&!o){r.push(bt(n)),n="",i++;continue}n+=s,i++}if(n||r.length>0)r.push(bt(n));return r}function Sp(e){return e.map((t)=>ac(t))}function ac(e){let t=bt(e);if(!t)return"";if(t.startsWith('"'))return nc(t);if(Mg(t)){if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null}if(aT(t)){let r=Number.parseFloat(t);return Object.is(r,-0)?0:r}return t}function nc(e){let t=bt(e);if(t.startsWith('"')){let r=sc(t,0);if(r===-1)throw SyntaxError("Unterminated string: missing closing quote");if(r!==t.length-1)throw SyntaxError("Unexpected characters after closing quote");return Pg(t.slice(1,r))}return t}function fT(e,t){let r=ft(e,":",t);if(r===-1)throw SyntaxError("Missing colon after key");return{key:bt(e.slice(t,r)),end:r+1}}function mT(e,t){let r=sc(e,t);if(r===-1)throw SyntaxError("Unterminated quoted key");let n=Pg(e.slice(t+1,r)),o=r+1;if(o>=e.length||e[o]!==":")throw SyntaxError("Missing colon after key");return o++,{key:n,end:o}}function qg(e,t){return e[t]==='"'?mT(e,t):fT(e,t)}function Ug(e){return e.trim().startsWith("[")&&ft(e,":")!==-1}function hT(e){return ft(e,":")!==-1}function io(e,t,r,n,o){if(n.strict&&e!==t)throw new ke(`Expected ${t} ${r}, but got ${e}`,{line:o.lineNumber,source:o.raw})}function gT(e,t,r){if(e?.depth===t&&e.content.startsWith("- "))throw new ke(`Expected ${r} list-form items, but found more`,{line:e.lineNumber,source:e.raw})}function yT(e,t,r){if(e?.depth===t&&!e.content.startsWith("- ")&&Hg(e.content,r.delimiter))throw new ke(`Expected ${r.length} tabular rows, but found more`,{line:e.lineNumber,source:e.raw})}function bp(e,t,r,n,o){if(!n)return;let i=r.find((s)=>s.lineNumber>e&&s.lineNumber<t);if(i)throw new ke(`Blank lines inside ${o} are not allowed in strict mode`,{line:i.lineNumber})}function Hg(e,t){let r=ft(e,":"),n=ft(e,t);if(r===-1)return!0;if(n!==-1&&n<r)return!0;return!1}function xT(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}function ST(e,t){let r=xT(t);return iT(e,bT(oT(r),r))}function*bT(e,t){let r=yield*jt(e);if(!r){yield{type:"startObject"},yield{type:"endObject"};return}if(bt(r.content)==="[]"){yield*Ct(e),yield{type:"startArray",length:0},yield{type:"endArray"},yield*Ag(e,t.strict);return}if(Ug(r.content)){let i=mt(r,()=>ic(rc(r.content,qr),t.strict));if(i){yield*Ct(e),yield*oc(i.header,i.inlineValues,e,0,t,r),yield*Ag(e,t.strict);return}}yield*Ct(e);let n=yield*jt(e);if(n===void 0&&!Ig(r)){yield{type:"primitive",value:mt(r,()=>ac(r.content))};return}if(!Ig(r)&&n?.depth===0)throw new ke("Top-level document must start with a key-value or array-header line",{line:r.lineNumber,source:r.raw});let o=t.strict?new Set:void 0;yield{type:"startObject"},yield*ls(r,e,0,t,o);while(!0){let i=yield*jt(e);if(!i)break;if(i.depth!==0){if(t.strict)throw jg(i,0);$g(i),yield*Ct(e);continue}yield*Ct(e),yield*ls(i,e,0,t,o)}yield{type:"endObject"}}function _T(e,t,r){if(r&&e.depth>t+1)throw new ke(`Indentation depth jump: expected depth ${t+1}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function jg(e,t){return new ke(`Over-indented line: expected depth ${t}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function $g(e){if(e.content.startsWith("- ")||e.content==="-"||ft(e.content,":")!==-1)return;throw new ke("Unexpected bare token line outside root primitive position",{line:e.lineNumber,source:e.raw})}function Bg(e){return new ke("Keyless keyed header is only valid at the document root",{line:e.lineNumber,source:e.raw})}function wT(e){return new ke("Keyless array header is only valid at the document root or as a list item",{line:e.lineNumber,source:e.raw})}function ET(e){return new ke("Keyless header with a field list is only valid at the document root",{line:e.lineNumber,source:e.raw})}function*Ag(e,t){if(!t)return;let r=yield*jt(e);if(r)throw new ke("Unexpected content after the document root",{line:r.lineNumber,source:r.raw})}function hp(e,t,r){if(!r)return;if(r.has(e))throw new ke(`Duplicate sibling key "${e}"`,{line:t.lineNumber,source:t.raw});r.add(e)}function*ls(e,t,r,n,o){let i=e.content,s=mt(e,()=>ic(rc(i,qr),n.strict));if(s&&s.header.key!==void 0){hp(s.header.key,e,o),yield{type:"key",key:s.header.key},yield*oc(s.header,s.inlineValues,t,r,n,e);return}if(s&&s.header.key===void 0&&n.strict)throw s.header.keyed?Bg(e):wT(e);let{key:a,end:c}=mt(e,()=>qg(i,0)),l=bt(i.slice(c));if(hp(a,e,o),yield{type:"key",key:a},!l){let u=yield*jt(t);if(u&&u.depth>r){_T(u,r,n.strict),yield{type:"startObject"},yield*OT(t,r+1,n),yield{type:"endObject"};return}yield{type:"startObject"},yield{type:"endObject"};return}if(l==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}yield{type:"primitive",value:mt(e,()=>ac(l))}}function*OT(e,t,r){let n,o=r.strict?new Set:void 0;while(!0){let i=yield*jt(e);if(!i||i.depth<t)break;if(n===void 0&&i.depth>=t)n=i.depth;if(i.depth===n)yield*Ct(e),yield*ls(i,e,n,r,o);else if(n!==void 0&&i.depth>n){if(r.strict)throw jg(i,n);$g(i),yield*Ct(e)}else break}}function*oc(e,t,r,n,o,i){if(e.keyed){yield*AT(e,r,n,o,i);return}if(yield{type:"startArray",length:e.length},t){yield*vT(e,t,o,i),yield{type:"endArray"};return}if(e.fields&&e.fields.length>0){yield*TT(e,r,n,o,i),yield{type:"endArray"};return}yield*IT(e,r,n,o,i),yield{type:"endArray"}}function*vT(e,t,r,n){if(!bt(t)){io(0,e.length,"inline-form values",r,n);return}let o=mt(n,()=>xp(t,e.delimiter)),i=mt(n,()=>Sp(o));io(i.length,e.length,"inline-form values",r,n);for(let s of i)yield{type:"primitive",value:s}}function*AT(e,t,r,n,o){let i=r+1,s=yp(e.fields),a=n.strict?new Set:void 0,c=0,l,u,d=o;yield{type:"startObject"};while(!0){let f=yield*jt(t);if(!f||f.depth<=r)break;if(f.depth>i){if(n.strict)throw new ke("Unexpected indentation inside keyed tabular object",{line:f.lineNumber,source:f.raw});yield*Ct(t);continue}if(ft(f.content,":")===-1){if(n.strict)throw new ke("Expected entry row inside keyed tabular object",{line:f.lineNumber,source:f.raw});yield*Ct(t);continue}if(yield*Ct(t),l===void 0)l=f.lineNumber;u=f.lineNumber,d=f;let{key:g,end:y}=mt(f,()=>qg(f.content,0));hp(g,f,a),yield{type:"key",key:g};let O=bt(f.content.slice(y)),m=O===""?[]:mt(f,()=>xp(O,e.delimiter));io(m.length,s,"keyed entry cells",n,f);let x=mt(f,()=>Sp(m));yield*Wg(e.fields,x),c++}if(io(c,e.length,"keyed entries",n,d),n.strict&&l!==void 0&&u!==void 0)bp(l,u,t.scanState.blankLines,n.strict,"keyed tabular object");yield{type:"endObject"}}function*TT(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*jt(t);if(!u||u.depth<i)break;if(u.depth===i){if(!Hg(u.content,e.delimiter))break;if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*Ct(t);let d=mt(u,()=>xp(u.content,e.delimiter));io(d.length,yp(e.fields),"tabular row values",n,u);let f=mt(u,()=>Sp(d));yield*Wg(e.fields,f),s++}else break}if(io(s,e.length,"tabular rows",n,l),n.strict&&a!==void 0&&c!==void 0)bp(a,c,t.scanState.blankLines,n.strict,"tabular array");if(n.strict)yT(yield*jt(t),i,e)}function*IT(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*jt(t);if(!u||u.depth<i)break;let d=u.content.startsWith("- ")||u.content==="-";if(u.depth===i&&d){if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*RT(t,i,n);let f=t.lastLine;if(f)c=f.lineNumber,l=f;s++}else break}if(io(s,e.length,"list-form items",n,l),n.strict&&a!==void 0&&c!==void 0)bp(a,c,t.scanState.blankLines,n.strict,"list-form array");if(n.strict)gT(yield*jt(t),i,e.length)}function*RT(e,t,r){let n=yield*Ct(e);if(!n)throw ReferenceError("Expected list item");let o;if(n.content==="-"){yield{type:"startObject"},yield{type:"endObject"};return}else if(n.content.startsWith("- "))o=n.content.slice(2);else throw new ke('Expected list item to start with "- "',{line:n.lineNumber,source:n.raw});if(!bt(o)){yield{type:"startObject"},yield{type:"endObject"};return}if(bt(o)==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}let i={...n,content:o};if(Ug(o)){let a=mt(i,()=>ic(rc(o,qr),r.strict));if(a)if(a.header.keyed||a.header.fields!==void 0){if(r.strict)throw a.header.keyed?Bg(i):ET(i)}else{yield*oc(a.header,a.inlineValues,e,t,r,i);return}}let s=mt(i,()=>ic(rc(o,qr),r.strict));if(s&&s.header.key!==void 0&&s.header.fields!==void 0){let a=s.header,c=r.strict?new Set([a.key]):void 0;yield{type:"startObject"},yield{type:"key",key:a.key},yield*oc(a,s.inlineValues,e,t+1,r,i),yield*Tg(e,t+1,r,c),yield{type:"endObject"};return}if(hT(o)){let a=r.strict?new Set:void 0;yield{type:"startObject"},yield*ls(i,e,t+1,r,a),yield*Tg(e,t+1,r,a),yield{type:"endObject"};return}yield{type:"primitive",value:mt(i,()=>ac(o))}}function*Tg(e,t,r,n){while(!0){let o=yield*jt(e);if(!o||o.depth<t)break;if(o.depth===t&&!o.content.startsWith("- "))yield*Ct(e),yield*ls(o,e,t,r,n);else break}}function Ig(e){let t=e.content;if(t.startsWith('"')){let r=sc(t,0);if(r===-1)return!1;return t.slice(r+1).includes(":")}else return t.includes(":")}function ic(e,t){if(e.kind==="notHeader")return;if(e.kind==="invalid"){if(t)throw SyntaxError(e.reason);return}if(t&&e.strictError!==void 0)throw SyntaxError(e.strictError);return{header:e.header,inlineValues:e.inlineValues}}function*Wg(e,t){let r=0;function*n(o){yield{type:"startObject"};for(let i of o){if(!i.children&&r>=t.length)continue;if(yield{type:"key",key:i.name},i.children)yield*n(i.children);else yield{type:"primitive",value:t[r++]}}yield{type:"endObject"}}yield*n(e)}function cs(e,t,r){if(t==="__proto__"){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0});return}e[t]=r}function kT(e){let t={stack:[],root:void 0};for(let r of e)CT(t,r);return PT(t)}function CT(e,t){let{stack:r}=e;switch(t.type){case"startObject":{let n={};if(r.length===0)r.push({type:"object",obj:n});else{let o=r[r.length-1];if(o.type==="object"){if(o.currentKey===void 0)throw Error("Object startObject event without preceding key");cs(o.obj,o.currentKey,n),o.currentKey=void 0}else if(o.type==="array")o.arr.push(n);r.push({type:"object",obj:n})}break}case"endObject":{if(r.length===0)throw Error("Unexpected endObject event");let n=r.pop();if(n.type!=="object")throw Error("Mismatched endObject event");if(r.length===0)e.root=n.obj;break}case"startArray":{let n=[];if(r.length===0)r.push({type:"array",arr:n});else{let o=r[r.length-1];if(o.type==="object"){if(o.currentKey===void 0)throw Error("Array startArray event without preceding key");cs(o.obj,o.currentKey,n),o.currentKey=void 0}else if(o.type==="array")o.arr.push(n);r.push({type:"array",arr:n})}break}case"endArray":{if(r.length===0)throw Error("Unexpected endArray event");let n=r.pop();if(n.type!=="array")throw Error("Mismatched endArray event");if(r.length===0)e.root=n.arr;break}case"key":{if(r.length===0)throw Error("Key event outside of object context");let n=r[r.length-1];if(n.type!=="object")throw Error("Key event outside of object context");n.currentKey=t.key;break}case"primitive":if(r.length===0)e.root=t.value;else{let n=r[r.length-1];if(n.type==="object"){if(n.currentKey===void 0)throw Error("Primitive event without preceding key in object");cs(n.obj,n.currentKey,t.value),n.currentKey=void 0}else if(n.type==="array")n.arr.push(t.value)}break}}function PT(e){if(e.stack.length!==0)throw Error("Incomplete event stream: unclosed objects or arrays");if(e.root===void 0)throw Error("No root value built from events");return e.root}var NT=new RegExp("(?:^\uFEFF?|\\n) *#"),FT=class{constructor(e){if(NT.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function ds(e){return e instanceof FT}var MT=/[\uD800-\uDFFF]/;function oo(e){if(e===null)return null;if(ds(e))return e;if(typeof e==="object"&&e!==null&&"toJSON"in e&&typeof e.toJSON==="function"){let t=e.toJSON();if(t!==e)return oo(t)}if(typeof e==="string")return Rg(e,"string value"),e;if(typeof e==="boolean")return e;if(typeof e==="number"){if(Object.is(e,-0))return 0;if(!Number.isFinite(e))return null;return e}if(typeof e==="bigint"){if(e>=Number.MIN_SAFE_INTEGER&&e<=Number.MAX_SAFE_INTEGER)return Number(e);return e.toString()}if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(oo);if(e instanceof Set)return Array.from(e).map(oo);if(e instanceof Map)return Object.fromEntries(Array.from(e,([t,r])=>[String(t),oo(r)]));if(DT(e)){let t={};for(let r in e)if(Object.hasOwn(e,r))Rg(r,"object key"),cs(t,r,oo(e[r]));return t}return null}function Rg(e,t){if(!MT.test(e))return;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n<55296||n>57343)continue;let o=n<=56319,i=e.charCodeAt(r+1);if(o&&i>=56320&&i<=57343){r++;continue}throw TypeError(`Cannot encode ${t} containing an unpaired surrogate U+${n.toString(16).toUpperCase()} at index ${r}`)}}function LT(e){return e===null||typeof e==="string"||typeof e==="number"||typeof e==="boolean"}function ao(e){return LT(e)||ds(e)}function so(e){return Array.isArray(e)}function Ur(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&!ds(e)}function us(e){return Object.keys(e).length===0}function DT(e){if(e===null||typeof e!=="object")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function ps(e){return e.length===0||e.every((t)=>ao(t))}function qT(e){return e.length===0||e.every((t)=>so(t))}function Kg(e){return e.length===0||e.every((t)=>Ur(t))}var UT=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function HT(e){if(!Object.values(tc).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function jT(e){return/^[A-Z_][\w.]*$/i.test(e)}function $T(e,t=qr){if(!e)return!1;if(/^[ \t]|[ \t]$/.test(e))return!1;if(Mg(e)||BT(e))return!1;if(e.includes(":"))return!1;if(e.includes('"')||e.includes("\\"))return!1;if(/[[\]{}]/.test(e))return!1;if(/[\u0000-\u001F]/.test(e))return!1;if(e.includes(t))return!1;if(e.startsWith("-"))return!1;if(e.startsWith("#"))return!1;return!0}function BT(e){return UT.test(e)}function fs(e,t){if(ds(e))return e.value;if(e===null)return"null";if(typeof e==="boolean")return String(e);if(typeof e==="number")return String(e);return WT(e,t)}function WT(e,t=qr){if($T(e,t))return e;return`"${Cg(e)}"`}function ni(e){if(jT(e))return e;return`"${Cg(e)}"`}function _p(e,t=qr){return e.map((r)=>fs(r,t)).join(t)}function Dr(e,t){let r=t?.key,n=t?.fields,o=t?.delimiter??",",i="";if(r!=null)i+=ni(r);if(i+=`[${e}${t?.keyed?":":""}${o!==qr?o:""}]`,n)i+=`{${Vg(n,o)}}`;return i+=":",i}function Vg(e,t){return e.map((r)=>ni(r.name)+(r.children?`{${Vg(r.children,t)}}`:"")).join(t)}function cc(e){if(e.length===0)return;let t=Object.keys(e[0]);if(t.length===0)return;for(let n of e){if(Object.keys(n).length!==t.length)return;for(let o of t)if(!Object.hasOwn(n,o))return}let r=[];for(let n of t){let o=KT(n,e.map((i)=>i[n]));if(!o)return;r.push(o)}return r}function wp(e){let t=Object.values(e);if(t.length<2)return;if(!t.every((r)=>Ur(r)&&!us(r)))return;return cc(t)}function zg(e,t){let r=[];return Gg(e,t,r),r}function KT(e,t){if(t.every((n)=>ao(n)))return{name:e};if(!t.every((n)=>Ur(n)&&!us(n)))return;let r=cc(t);if(!r)return;return{name:e,children:r}}function Gg(e,t,r){for(let n of t){let o=e[n.name];if(n.children)Gg(o,n.children,r);else r.push(o)}}function*VT(e,t,r){if(ao(e)){let n=fs(e,t.delimiter);if(n!=="")yield n;return}if(so(e))yield*Zg(void 0,e,r,t);else if(Ur(e)){let n=wp(e);if(n){yield*Jg(void 0,e,n,r,t);return}yield*ri(e,r,t)}}function*ri(e,t,r){for(let[n,o]of Object.entries(e))yield*zT(n,o,t,r)}function*zT(e,t,r,n){let o=ni(e);if(ao(t))yield $t(r,`${o}: ${fs(t,n.delimiter)}`,n.indentSize);else if(so(t))yield*Zg(e,t,r,n);else if(Ur(t)){let i=wp(t);if(i){yield*Jg(e,t,i,r,n);return}if(yield $t(r,`${o}:`,n.indentSize),!us(t))yield*ri(t,r+1,n)}}function*Jg(e,t,r,n,o){let i=Object.entries(t);yield $t(n,Dr(i.length,{key:e,fields:r,delimiter:o.delimiter,keyed:!0}),o.indentSize),yield*Yg(i,r,n+1,o)}function*Yg(e,t,r,n){for(let[o,i]of e){let s=zg(i,t);yield $t(r,`${ni(o)}: ${_p(s,n.delimiter)}`,n.indentSize)}}function*Zg(e,t,r,n){if(t.length===0){yield $t(r,e!=null?`${ni(e)}: []`:"[]",n.indentSize);return}if(ps(t)){yield $t(r,lc(t,n.delimiter,e),n.indentSize);return}if(qT(t)){if(t.every((o)=>ps(o))){yield*GT(e,t,r,n);return}}if(Kg(t)){let o=cc(t);if(o)yield*JT(e,t,o,r,n);else yield*kg(e,t,r,n);return}yield*kg(e,t,r,n)}function*GT(e,t,r,n){yield $t(r,Dr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)if(ps(o)){let i=lc(o,n.delimiter);yield tr(r+1,i,n.indentSize)}}function lc(e,t,r){let n=Dr(e.length,{key:r,delimiter:t}),o=_p(e,t);if(e.length===0)return n;return`${n} ${o}`}function*JT(e,t,r,n,o){yield $t(n,Dr(t.length,{key:e,fields:r,delimiter:o.delimiter}),o.indentSize),yield*Qg(t,r,n+1,o)}function*Qg(e,t,r,n){for(let o of e)yield $t(r,_p(zg(o,t),n.delimiter),n.indentSize)}function*kg(e,t,r,n){yield $t(r,Dr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)yield*Ep(o,r+1,n)}function*YT(e,t,r){if(us(e)){yield $t(t,"-",r.indentSize);return}let n=Object.entries(e),[o,i]=n[0],s=n.slice(1);if(so(i)&&Kg(i)){let c=cc(i);if(c){if(yield tr(t,Dr(i.length,{key:o,fields:c,delimiter:r.delimiter}),r.indentSize),yield*Qg(i,c,t+2,r),s.length>0)yield*ri(Object.fromEntries(s),t+1,r);return}}if(Ur(i)){let c=wp(i);if(c){let l=Object.entries(i);if(yield tr(t,Dr(l.length,{key:o,fields:c,delimiter:r.delimiter,keyed:!0}),r.indentSize),yield*Yg(l,c,t+2,r),s.length>0)yield*ri(Object.fromEntries(s),t+1,r);return}}let a=ni(o);if(ao(i))yield tr(t,`${a}: ${fs(i,r.delimiter)}`,r.indentSize);else if(so(i))if(i.length===0)yield tr(t,`${a}: []`,r.indentSize);else if(ps(i))yield tr(t,`${a}${lc(i,r.delimiter)}`,r.indentSize);else{yield tr(t,`${a}${Dr(i.length,{delimiter:r.delimiter})}`,r.indentSize);for(let c of i)yield*Ep(c,t+2,r)}else if(Ur(i)){if(yield tr(t,`${a}:`,r.indentSize),!us(i))yield*ri(i,t+2,r)}if(s.length>0)yield*ri(Object.fromEntries(s),t+1,r)}function*Ep(e,t,r){if(ao(e))yield tr(t,fs(e,r.delimiter),r.indentSize);else if(so(e))if(ps(e))yield tr(t,lc(e,r.delimiter),r.indentSize);else{yield tr(t,Dr(e.length,{delimiter:r.delimiter}),r.indentSize);for(let n of e)yield*Ep(n,t+1,r)}else if(Ur(e))yield*YT(e,t,r)}function $t(e,t,r){return" ".repeat(r*e)+t}function tr(e,t,r){return $t(e,"- "+t,r)}function ZT(e,t){let r=t("",e,[]);if(r===void 0)return gp(e,t,[]);return Op(e,r,t,[])}function Op(e,t,r,n){if(ds(t)&&!ao(e))return gp(e,r,n);return gp(oo(t),r,n)}function gp(e,t,r){if(Ur(e))return QT(e,t,r);if(so(e))return XT(e,t,r);return e}function QT(e,t,r){let n={};for(let[o,i]of Object.entries(e)){let s=[...r,o],a=t(o,i,s);if(a===void 0)continue;cs(n,o,Op(i,a,t,s))}return n}function XT(e,t,r){let n=[];for(let o=0;o<e.length;o++){let i=e[o],s=[...r,o],a=t(String(o),i,s);if(a===void 0)continue;n.push(Op(i,a,t,s))}return n}function Xe(e,t){return Array.from(eI(e,t)).join(`
|
|
5
|
+
`)}function Xg(e,t){return tI(e.split(`
|
|
6
|
+
`),t)}function eI(e,t){let r=oo(e),n=rI(t);return VT(n.replacer?ZT(r,n.replacer):r,n,0)}function tI(e,t){return kT(ST(e,nI(t)))}function rI(e){let t=e?.delimiter??qr;return HT(t),{indentSize:e?.indentSize??e?.indent??2,delimiter:t,replacer:e?.replacer}}function nI(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}class ht extends Error{code;details;constructor(e,t,r={},n){super(t,n);this.name="CoreError",this.code=e,this.details=r,br(this.details),Object.freeze(this)}}var vp=(e)=>typeof e==="function",p=function(e,t){if(typeof e==="function")return function(){if(e(arguments))return t.apply(this,arguments);return(r)=>t(r,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(r,n){if(arguments.length>=2)return t(r,n);return function(o){return t(o,r)}};case 3:return function(r,n,o){if(arguments.length>=3)return t(r,n,o);return function(i){return t(i,r,n)}};case 4:return function(r,n,o,i){if(arguments.length>=4)return t(r,n,o,i);return function(s){return t(s,r,n,o)}};case 5:return function(r,n,o,i,s){if(arguments.length>=5)return t(r,n,o,i,s);return function(a){return t(a,r,n,o,i)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let r=arguments;return function(n){return t(n,...r)}}}};var te=(e)=>e;var ms=(e)=>()=>e,hs=ms(!0),bn=ms(!1);var uc=ms(void 0),gs=uc;function h(e,t,r,n,o,i,s,a,c){switch(arguments.length){case 1:return e;case 2:return t(e);case 3:return r(t(e));case 4:return n(r(t(e)));case 5:return o(n(r(t(e))));case 6:return i(o(n(r(t(e)))));case 7:return s(i(o(n(r(t(e))))));case 8:return a(s(i(o(n(r(t(e)))))));case 9:return c(a(s(i(o(n(r(t(e))))))));default:{let l=arguments[0];for(let u=1;u<arguments.length;u++)l=arguments[u](l);return l}}}var xs=(e)=>(t,r)=>t===r||e(t,r),oI=(e,t)=>e===t,iI=()=>oI;var sI=iI();var Ap=p(2,(e,t)=>xs((r,n)=>e(t(r),t(n)))),ey=Ap(sI,(e)=>e.getTime());var ty=(e)=>xs((t,r)=>{if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(!e(t[n],r[n]))return!1;return!0});var Ss,B=(e,t)=>{if(!Ss)globalThis["effect/GlobalValue"]??=new Map,Ss=globalThis["effect/GlobalValue"];if(!Ss.has(e))Ss.set(e,t());return Ss.get(e)};var Ke=(e)=>typeof e==="string",Pt=(e)=>typeof e==="number",co=(e)=>typeof e==="boolean",_n=(e)=>typeof e==="bigint",lo=(e)=>typeof e==="symbol";var wn=vp,ry=(e)=>e===void 0;var ny=(e)=>!1;var bs=(e)=>typeof e==="object"&&e!==null,gt=(e)=>bs(e)||wn(e),v=p(2,(e,t)=>gt(e)&&(t in e)),_s=p(2,(e,t)=>v(e,"_tag")&&e._tag===t),uo=(e)=>e===null||e===void 0,oy=(e)=>e!==null&&e!==void 0;var dc=(e)=>e instanceof Date,Tp=(e)=>typeof e==="string"||v(e,Symbol.iterator),Ip=(e)=>bs(e)&&!Array.isArray(e);var iy=(e)=>v(e,"then")&&wn(e.then);var po=(e)=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`;class ii{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 ii(this.self)}}var aI=335903614,cI=4150755663,lI=1481765933,uI=1284865837,pI=9007199254740992,dI=134217728;class kp{_state;constructor(e,t,r,n){if(uo(t)&&uo(e))t=Math.random()*4294967295>>>0,e=0;else if(uo(t))t=e,e=0;if(uo(n)&&uo(r))n=this._state?this._state[3]:cI,r=this._state?this._state[2]:aI;else if(uo(n))n=r,r=0;return this._state=new Int32Array([0,0,r>>>0,((n||0)|1)>>>0]),this._next(),sy(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()*Number.MAX_SAFE_INTEGER)%e}number(){let e=(this._next()&67108863)*1,t=(this._next()&134217727)*1;return(e*dI+t)/pI}_next(){let e=this._state[0]>>>0,t=this._state[1]>>>0;fI(this._state,e,t,lI,uI),sy(this._state,this._state[0],this._state[1],this._state[2],this._state[3]);let r=e>>>18,n=(t>>>18|e<<14)>>>0;r=(r^e)>>>0,n=(n^t)>>>0;let o=(n>>>27|r<<5)>>>0,i=e>>>27,s=(-i>>>0&31)>>>0;return(o>>>i|o<<s)>>>0}}function fI(e,t,r,n,o){let i=(r>>>16)*(o&65535)>>>0,s=(r&65535)*(o>>>16)>>>0,a=(r&65535)*(o&65535)>>>0,c=(r>>>16)*(o>>>16)+((s>>>16)+(i>>>16))>>>0;if(s=s<<16>>>0,a=a+s>>>0,a>>>0<s>>>0)c=c+1>>>0;if(i=i<<16>>>0,a=a+i>>>0,a>>>0<i>>>0)c=c+1>>>0;c=c+Math.imul(r,n)>>>0,c=c+Math.imul(t,o)>>>0,e[0]=c,e[1]=a}function sy(e,t,r,n,o){let i=t+n>>>0,s=r+o>>>0;if(s>>>0<r>>>0)i=i+1|0;e[0]=i,e[1]=s}var Rp=Symbol.for("effect/Utils/YieldWrap");class Hr{#e;constructor(e){this.#e=e}[Rp](){return this.#e}}function Cp(e){if(typeof e==="object"&&e!==null&&Rp in e)return e[Rp]();throw Error(po("yieldWrapGet"))}var _t=B("effect/Utils/isStructuralRegion",()=>({enabled:!1,tester:void 0}));var ay={effect_internal_function:(e)=>e()},mI={effect_internal_function:(e)=>{try{return e()}finally{}}},hI=ay.effect_internal_function(()=>Error().stack)?.includes("effect_internal_function")===!0,Ve=hI?ay.effect_internal_function:mI.effect_internal_function,ED=function*(){}.constructor;var Pp=B(Symbol.for("effect/Hash/randomHashCache"),()=>new WeakMap),P=Symbol.for("effect/Hash"),w=(e)=>{if(_t.enabled===!0)return 0;switch(typeof e){case"number":return mc(e);case"bigint":return ie(e.toString(10));case"boolean":return ie(String(e));case"symbol":return ie(String(e));case"string":return ie(e);case"undefined":return ie("undefined");case"function":case"object":if(e===null)return ie("null");else if(e instanceof Date){if(Number.isNaN(e.getTime()))return ie("Invalid Date");return w(e.toISOString())}else if(e instanceof URL)return w(e.href);else if(yI(e))return e[P]();else return ws(e);default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},ws=(e)=>{if(!Pp.has(e))Pp.set(e,mc(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)));return Pp.get(e)},V=(e)=>(t)=>t*53^e,fc=(e)=>e&3221225471|e>>>1&1073741824,yI=(e)=>v(e,P),mc=(e)=>{if(e!==e||e===1/0)return 0;let t=e|0;if(t!==e)t^=e*4294967295;while(e>4294967295)t^=e/=4294967295;return fc(t)},ie=(e)=>{let t=5381,r=e.length;while(r)t=t*33^e.charCodeAt(--r);return fc(t)},xI=(e,t)=>{let r=12289;for(let n=0;n<t.length;n++)r^=h(ie(t[n]),V(w(e[t[n]])));return fc(r)},hc=(e)=>xI(e,Object.keys(e)),Nt=(e)=>{let t=6151;for(let r=0;r<e.length;r++)t=h(t,V(w(e[r])));return fc(t)},Z=function(){if(arguments.length===1){let r=arguments[0];return function(n){return Object.defineProperty(r,P,{value(){return n},enumerable:!1}),n}}let e=arguments[0],t=arguments[1];return Object.defineProperty(e,P,{value(){return t},enumerable:!1}),t};var R=Symbol.for("effect/Equal");function E(){if(arguments.length===1)return(e)=>gc(e,arguments[0]);return gc(arguments[0],arguments[1])}function gc(e,t){if(e===t)return!0;let r=typeof e;if(r!==typeof t)return!1;if(r==="object"||r==="function"){if(e!==null&&t!==null){if(Es(e)&&Es(t))if(w(e)===w(t)&&e[R](t))return!0;else return _t.enabled&&_t.tester?_t.tester(e,t):!1;else if(e instanceof Date&&t instanceof Date){let n=e.getTime(),o=t.getTime();return n===o||Number.isNaN(n)&&Number.isNaN(o)}else 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((n,o)=>gc(n,t[o]));if(Object.getPrototypeOf(e)===Object.prototype&&Object.getPrototypeOf(t)===Object.prototype){let n=Object.keys(e),o=Object.keys(t);if(n.length===o.length){for(let i of n)if(!((i in t)&&gc(e[i],t[i])))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 Es=(e)=>v(e,R),Os=()=>E;var Y=Symbol.for("nodejs.util.inspect.custom"),re=(e)=>{try{if(v(e,"toJSON")&&wn(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(re)}catch{return{}}return uy(e)},Np="[Circular]";function SI(e){try{return e.toISOString()}catch{return"Invalid Date"}}function bI(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}function vs(e){return Ke(e)?JSON.stringify(e):String(e)}function _r(e,t){let r=t?.space??0,n=new WeakSet,o=!r?"":Pt(r)?" ".repeat(r):r,i=(l)=>o.repeat(l),s=(l,u)=>{let d=l?.constructor;return d&&d!==Object.prototype.constructor&&d.name?`${d.name}(${u})`:u},a=(l)=>{try{return Reflect.ownKeys(l)}catch{return["[ownKeys threw]"]}};function c(l,u=0){if(Array.isArray(l)){if(n.has(l))return Np;if(n.add(l),!o||l.length<=1)return`[${l.map((f)=>c(f,u)).join(",")}]`;let d=l.map((f)=>c(f,u+1)).join(`,
|
|
7
7
|
`+i(u+1));return`[
|
|
8
8
|
${i(u+1)}${d}
|
|
9
|
-
${i(u)}]`}if(
|
|
10
|
-
${d.map((
|
|
9
|
+
${i(u)}]`}if(dc(l))return SI(l);if(!t?.ignoreToString&&v(l,"toString")&&wn(l.toString)&&l.toString!==Object.prototype.toString&&l.toString!==Array.prototype.toString){let d=bI(l);if(l instanceof Error&&l.cause)return`${d} (cause: ${c(l.cause,u)})`;return d}if(Ke(l))return JSON.stringify(l);if(Pt(l)||l==null||co(l)||lo(l))return String(l);if(_n(l))return String(l)+"n";if(l instanceof Set||l instanceof Map){if(n.has(l))return Np;return n.add(l),`${l.constructor.name}(${c(Array.from(l),u)})`}if(gt(l)){if(n.has(l))return Np;n.add(l);let d=a(l);if(!o||d.length<=1){let g=`{${d.map((y)=>`${vs(y)}:${c(l[y],u)}`).join(",")}}`;return s(l,g)}let f=`{
|
|
10
|
+
${d.map((g)=>`${i(u+1)}${vs(g)}: ${c(l[g],u+1)}`).join(`,
|
|
11
11
|
`)}
|
|
12
|
-
${i(u)}}`;return s(l,f)}return String(l)}return c(e,0)}var ie=(e)=>JSON.stringify(e,null,2),ED={toJSON(){return re(this)},[Y](){return this.toJSON()},toString(){return ie(this.toJSON())}};var jr=(e,t=2)=>{if(typeof e==="string")return e;try{return typeof e==="object"?mc(e,t):String(e)}catch{return String(e)}},mc=(e,t)=>{let r=[],n=JSON.stringify(e,(o,i)=>typeof i==="object"&&i!==null?r.includes(i)?void 0:r.push(i)&&(uo.fiberRefs!==void 0&&oy(i)?i[Pp](uo.fiberRefs):i):i,t);return r=void 0,n},Pp=Symbol.for("effect/Inspectable/Redactable"),oy=(e)=>typeof e==="object"&&e!==null&&(Pp in e),uo=U("effect/Inspectable/redactableState",()=>({fiberRefs:void 0})),iy=(e,t)=>{let r=uo.fiberRefs;uo.fiberRefs=e;try{return t()}finally{uo.fiberRefs=r}},sy=(e)=>{if(oy(e)&&uo.fiberRefs!==void 0)return e[Pp](uo.fiberRefs);return e};var x=(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 r=e;for(let n=0,o=t.length;n<o;n++)r=t[n](r);return r}}};var fo="Async",mo="Commit",wt="Failure",vs="OnFailure",oi="OnSuccess",ii="OnSuccessAndFailure",Et="Success",hc="Sync",ay="Tag",ho="UpdateRuntimeFlags",si="While",ai="Iterator",gc="WithRuntime",ci="Yield",As="RevertFlags";var gI="3.22.2",Ts=()=>gI;var ly=Symbol.for("effect/Effect"),uy=Symbol.for("effect/Stream"),py=Symbol.for("effect/Sink"),dy=Symbol.for("effect/Channel"),wn={_R:(e)=>e,_E:(e)=>e,_A:(e)=>e,_V:Ts()},yI={_A:(e)=>e,_In:(e)=>e,_L:(e)=>e,_E:(e)=>e,_R:(e)=>e},xI={_Env:(e)=>e,_InErr:(e)=>e,_InElem:(e)=>e,_InDone:(e)=>e,_OutErr:(e)=>e,_OutElem:(e)=>e,_OutDone:(e)=>e},$r={[ly]:wn,[uy]:wn,[py]:yI,[dy]:xI,[A](e){return this===e},[I](){return Z(this,_s(this))},[Symbol.iterator](){return new ni(new Hr(this))},pipe(){return x(this,arguments)}},Is={[I](){return Z(this,dc(this))},[A](e){let t=Object.keys(this),r=Object.keys(e);if(t.length!==r.length)return!1;for(let n of t)if(!((n in e)&&_(this[n],e[n])))return!1;return!0}},En={...$r,_op:mo},Np={...En,...Is},fy=function(){function e(){}return e.prototype=En,e}();var hy=Symbol.for("effect/Option"),gy={...$r,[hy]:{_A:(e)=>e},[Y](){return this.toJSON()},toString(){return ie(this.toJSON())}},SI=Object.assign(Object.create(gy),{_tag:"Some",_op:"Some",[A](e){return Mp(e)&&Dp(e)&&_(this.value,e.value)},[I](){return Z(this,K(b(this._tag))(b(this.value)))},toJSON(){return{_id:"Option",_tag:this._tag,value:re(this.value)}}}),bI=b("None"),_I=Object.assign(Object.create(gy),{_tag:"None",_op:"None",[A](e){return Mp(e)&&Lp(e)},[I](){return bI},toJSON(){return{_id:"Option",_tag:this._tag}}}),Mp=(e)=>w(e,hy),Lp=(e)=>e._tag==="None",Dp=(e)=>e._tag==="Some",yc=Object.create(_I),ks=(e)=>{let t=Object.create(SI);return t.value=e,t};var qp=Symbol.for("effect/Either"),xy={...$r,[qp]:{_R:(e)=>e},[Y](){return this.toJSON()},toString(){return ie(this.toJSON())}},wI=Object.assign(Object.create(xy),{_tag:"Right",_op:"Right",[A](e){return xc(e)&&Hp(e)&&_(this.right,e.right)},[I](){return K(b(this._tag))(b(this.right))},toJSON(){return{_id:"Either",_tag:this._tag,right:re(this.right)}}}),EI=Object.assign(Object.create(xy),{_tag:"Left",_op:"Left",[A](e){return xc(e)&&Up(e)&&_(this.left,e.left)},[I](){return K(b(this._tag))(b(this.left))},toJSON(){return{_id:"Either",_tag:this._tag,left:re(this.left)}}}),xc=(e)=>w(e,qp),Up=(e)=>e._tag==="Left",Hp=(e)=>e._tag==="Right",Sy=(e)=>{let t=Object.create(EI);return t.left=e,t},by=(e)=>{let t=Object.create(wI);return t.right=e,t};var z=by;var B=Sy;var jp=xc,ye=Up,Qe=Hp;var Sc=p(2,(e,t)=>ye(e)?B(t(e.left)):z(e.right)),_y=p(2,(e,t)=>Qe(e)?z(t(e.right)):B(e.left)),Rs=p(2,(e,{onLeft:t,onRight:r})=>ye(e)?t(e.left):r(e.right));var wy=Rs({onLeft:te,onRight:te});var $p=p(2,(e,t)=>{if(Qe(e))return e.right;throw t(e.left)}),Ey=$p(()=>Error("getOrThrow called on a Left"));var Bp=(e)=>e.length>0;var Oy=(e)=>(t,r)=>t===r?0:e(t,r);var vy=Oy((e,t)=>e<t?-1:1);var bc=p(2,(e,t)=>Oy((r,n)=>e(t(r),t(n))));var Kp=(e)=>p(2,(t,r)=>e(t,r)===1);var E=()=>yc,P=ks;var Se=Lp,pe=Dp,Ae=p(2,(e,{onNone:t,onSome:r})=>Se(e)?t():r(e.value));var ue=p(2,(e,t)=>Se(e)?t():e.value),rr=p(2,(e,t)=>Se(e)?t():e),Ay=p(2,(e,t)=>Se(e)?P(t()):e);var Br=(e)=>e==null?E():P(e);var Ot=ue(ac),Ty=(e)=>(...t)=>{try{return P(e(...t))}catch{return E()}};var nr=p(2,(e,t)=>Se(e)?E():P(t(e.value)));var or=p(2,(e,t)=>Se(e)?E():t(e.value));var Iy=p(2,(e,t)=>Se(e)?E():Br(t(e.value)));var TI=(e)=>p(2,(t,r)=>Se(t)?!1:e(t.value,r)),II=Es(),ky=TI(II),Ry=p(2,(e,t)=>Se(e)?!1:t(e.value));var Cy=(...e)=>e;var go=(e)=>Array(e),Vp=p(2,(e,t)=>{let r=Math.max(1,Math.floor(e)),n=Array(r);for(let o=0;o<r;o++)n[o]=t(o);return n});var de=(e)=>Array.isArray(e)?e:Array.from(e),zp=(e)=>Array.isArray(e)?e:[e];var Py=p(2,(e,{onEmpty:t,onNonEmpty:r})=>ce(e)?r(Pe(e),ir(e)):t());var li=p(2,(e,t)=>[t,...e]);var Fy=p(2,(e,t)=>[...e,t]),Gp=p(2,(e,t)=>de(e).concat(de(t)));var Jp=Array.isArray,RI=(e)=>e.length===0,Ny=RI,On=Bp,ce=Bp;var My=(e,t)=>e<0||e>=t.length,CI=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),PI=p(2,(e,t)=>{let r=Math.floor(t);return My(r,e)?E():P(e[r])}),Yp=p(2,(e,t)=>{let r=Math.floor(t);if(My(r,e))throw Error(`Index ${r} out of bounds`);return e[r]});var Kr=PI(0),Pe=Yp(0),Ly=(e)=>ce(e)?P(Zp(e)):E(),Zp=(e)=>e[e.length-1];var ir=(e)=>e.slice(1);var FI=(e,t)=>{let r=0;for(let n of e){if(!t(n,r))break;r++}return r},Dy=p(2,(e,t)=>MI(e,FI(e,t))),qy=p(2,(e,t)=>{let r=de(e);return r.slice(CI(t,r),r.length)});var Qp=(e)=>Array.from(e).reverse(),Wr=p(2,(e,t)=>{let r=Array.from(e);return r.sort(t),r});var Xp=p(2,(e,t)=>Uy(e,t,Cy)),Uy=p(3,(e,t,r)=>{let n=de(e),o=de(t);if(ce(n)&&ce(o)){let i=[r(Pe(n),Pe(o))],s=Math.min(n.length,o.length);for(let a=1;a<s;a++)i[a]=r(n[a],o[a]);return i}return[]});var NI=Es();var MI=p(2,(e,t)=>{let r=Array.from(e),n=Math.floor(t);if(ce(r)){if(n>=1)return LI(r,n);return[[],r]}return[r,[]]}),LI=p(2,(e,t)=>{let r=Math.max(1,Math.floor(t));return r>=e.length?[ui(e),[]]:[li(e.slice(1,r),Pe(e)),e.slice(r)]});var ui=(e)=>e.slice();var DI=p(3,(e,t,r)=>{let n=de(e),o=de(t);if(ce(n)){if(ce(o))return Hy(r)(Gp(n,o));return n}return o}),vn=p(2,(e,t)=>DI(e,t,NI));var Vr=()=>[],Xe=(e)=>[e],sr=p(2,(e,t)=>e.map(t)),Cs=p(2,(e,t)=>{if(Ny(e))return[];let r=[];for(let n=0;n<e.length;n++){let o=t(e[n],n);for(let i=0;i<o.length;i++)r.push(o[i])}return r}),_c=Cs(te),wc=p(2,(e,t)=>{let r=de(e),n=[];for(let o=0;o<r.length;o++){let i=t(r[o],o);if(pe(i))n.push(i.value)}return n});var pi=p(3,(e,t,r)=>de(e).reduce((n,o,i)=>r(n,o,i),t));var ed=(e,t)=>{let r=[],n=e,o;while(pe(o=t(n))){let[i,s]=o.value;r.push(i),n=s}return r};var An=Zg;var Hy=p(2,(e,t)=>{let r=de(e);if(ce(r)){let n=[Pe(r)],o=ir(r);for(let i of o)if(n.every((s)=>!t(i,s)))n.push(i);return n}return[]}),td=(e)=>Hy(e,Es());var zr=p(2,(e,t)=>de(e).join(t));var $y=Symbol.for("effect/Chunk");function jI(e,t,r,n,o){for(let i=t;i<Math.min(e.length,t+o);i++)r[n+i-t]=e[i];return r}var By=[],$I=(e)=>ys((t,r)=>t.length===r.length&&Gr(t).every((n,o)=>e(n,di(r,o)))),BI=$I(_),KI={[$y]:{_A:(e)=>e},toString(){return ie(this.toJSON())},toJSON(){return{_id:"Chunk",values:Gr(this).map(re)}},[Y](){return this.toJSON()},[A](e){return Ky(e)&&BI(this,e)},[I](){return Z(this,Nt(Gr(this)))},[Symbol.iterator](){switch(this.backing._tag){case"IArray":return this.backing.array[Symbol.iterator]();case"IEmpty":return By[Symbol.iterator]();default:return Gr(this)[Symbol.iterator]()}},pipe(){return x(this,arguments)}},Le=(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=_r,t.right=_r;break}case"ISingleton":{t.length=1,t.depth=0,t.left=_r,t.right=_r;break}case"ISlice":{t.length=e.length,t.depth=e.chunk.depth+1,t.left=_r,t.right=_r;break}}return t},Ky=(e)=>w(e,$y),_r=Le({_tag:"IEmpty"}),Kt=()=>_r,Ps=(...e)=>zI(e),Fe=(e)=>Le({_tag:"ISingleton",a:e}),Ec=(e)=>Ky(e)?e:Fs(de(e)),rd=(e,t,r)=>{switch(e.backing._tag){case"IArray":{jI(e.backing.array,0,t,r,e.length);break}case"IConcat":{rd(e.left,t,r),rd(e.right,t,r+e.left.length);break}case"ISingleton":{t[r]=e.backing.a;break}case"ISlice":{let n=0,o=r;while(n<e.length)t[o]=di(e,n),n+=1,o+=1;break}}};var WI=(e)=>{switch(e.backing._tag){case"IEmpty":return By;case"IArray":return e.backing.array;default:{let t=Array(e.length);return rd(e,t,0),e.backing={_tag:"IArray",array:t},e.left=_r,e.right=_r,e.depth=0,t}}},Gr=WI,VI=(e)=>{switch(e.backing._tag){case"IEmpty":case"ISingleton":return e;case"IArray":return Le({_tag:"IArray",array:Qp(e.backing.array)});case"IConcat":return Le({_tag:"IConcat",left:Tn(e.backing.right),right:Tn(e.backing.left)});case"ISlice":return Fs(Qp(Gr(e)))}},Tn=VI;var Fs=(e)=>e.length===0?Kt():e.length===1?Fe(e[0]):Le({_tag:"IArray",array:e}),zI=(e)=>Fs(e),di=p(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?di(e.left,t):di(e.right,t-e.left.length);case"ISlice":return di(e.backing.chunk,t+e.backing.offset)}}),Wy=p(2,(e,t)=>Mt(e,Fe(t))),et=p(2,(e,t)=>Mt(Fe(t),e));var nd=p(2,(e,t)=>{if(t<=0)return e;else if(t>=e.length)return _r;else switch(e.backing._tag){case"ISlice":return Le({_tag:"ISlice",chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case"IConcat":{if(t>e.left.length)return nd(e.right,t-e.left.length);return Le({_tag:"IConcat",left:nd(e.left,t),right:e.right})}default:return Le({_tag:"ISlice",chunk:e,offset:t,length:e.length-t})}});var Mt=p(2,(e,t)=>{if(e.backing._tag==="IEmpty")return t;if(t.backing._tag==="IEmpty")return e;let r=t.depth-e.depth;if(Math.abs(r)<=1)return Le({_tag:"IConcat",left:e,right:t});else if(r<-1)if(e.left.depth>=e.right.depth){let n=Mt(e.right,t);return Le({_tag:"IConcat",left:e.left,right:n})}else{let n=Mt(e.right.right,t);if(n.depth===e.depth-3){let o=Le({_tag:"IConcat",left:e.right.left,right:n});return Le({_tag:"IConcat",left:e.left,right:o})}else{let o=Le({_tag:"IConcat",left:e.left,right:e.right.left});return Le({_tag:"IConcat",left:o,right:n})}}else if(t.right.depth>=t.left.depth){let n=Mt(e,t.left);return Le({_tag:"IConcat",left:n,right:t.right})}else{let n=Mt(e,t.left.left);if(n.depth===t.depth-3){let o=Le({_tag:"IConcat",left:n,right:t.left.right});return Le({_tag:"IConcat",left:o,right:t.right})}else{let o=Le({_tag:"IConcat",left:t.left.right,right:t.right});return Le({_tag:"IConcat",left:n,right:o})}}});var Vy=(e)=>e.length===0,ar=(e)=>e.length>0;var od=(e)=>di(e,0),cr=od;var lr=(e)=>nd(e,1);var In=5,id=Math.pow(2,5),zy=id-1,Gy=id/2,Jy=id/4;function GI(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 kn(e,t){return t>>>e&zy}function Rn(e){return 1<<e}function Oc(e,t){return GI(e&t-1)}var Yy=(e,t)=>({value:e,previous:t});function yo(e,t,r,n){let o=n;if(!e){let i=n.length;o=Array(i);for(let s=0;s<i;++s)o[s]=n[s]}return o[t]=r,o}function sd(e,t,r){let n=r.length-1,o=0,i=0,s=r;if(e)o=i=t;else{s=Array(n);while(o<t)s[i++]=r[o++]}++o;while(o<=n)s[i++]=r[o++];if(e)s.length=n;return s}function Zy(e,t,r,n){let o=n.length;if(e){let c=o;while(c>=t)n[c--]=n[c];return n[t]=r,n}let i=0,s=0,a=Array(o+1);while(i<t)a[s++]=n[i++];a[t]=r;while(i<o)a[++s]=n[i++];return a}class Yr{_tag="EmptyNode";modify(e,t,r,n,o,i){let s=r(E());if(Se(s))return new Yr;return++i.value,new xo(e,n,o,s)}}function Wt(e){return bs(e,"EmptyNode")}function YI(e){return Wt(e)||e._tag==="LeafNode"||e._tag==="CollisionNode"}function vc(e,t){return Wt(e)?!1:t===e.edit}class xo{edit;hash;key;value;_tag="LeafNode";constructor(e,t,r,n){this.edit=e,this.hash=t,this.key=r,this.value=n}modify(e,t,r,n,o,i){if(_(o,this.key)){let a=r(this.value);if(a===this.value)return this;else if(Se(a))return--i.value,new Yr;if(vc(this,e))return this.value=a,this;return new xo(e,n,o,a)}let s=r(E());if(Se(s))return this;return++i.value,Qy(e,t,this.hash,this,n,new xo(e,n,o,s))}}class ad{edit;hash;children;_tag="CollisionNode";constructor(e,t,r){this.edit=e,this.hash=t,this.children=r}modify(e,t,r,n,o,i){if(n===this.hash){let a=vc(this,e),c=this.updateCollisionList(a,e,this.hash,this.children,r,o,i);if(c===this.children)return this;return c.length>1?new ad(e,this.hash,c):c[0]}let s=r(E());if(Se(s))return this;return++i.value,Qy(e,t,this.hash,this,n,new xo(e,n,o,s))}updateCollisionList(e,t,r,n,o,i,s){let a=n.length;for(let l=0;l<a;++l){let u=n[l];if("key"in u&&_(i,u.key)){let d=u.value,f=o(d);if(f===d)return n;if(Se(f))return--s.value,sd(e,l,n);return yo(e,l,new xo(t,r,i,f),n)}}let c=o(E());if(Se(c))return n;return++s.value,yo(e,a,new xo(t,r,i,c),n)}}class fi{edit;mask;children;_tag="IndexedNode";constructor(e,t,r){this.edit=e,this.mask=t,this.children=r}modify(e,t,r,n,o,i){let s=this.mask,a=this.children,c=kn(t,n),l=Rn(c),u=Oc(s,l),d=s&l,f=vc(this,e);if(!d){let v=new Yr().modify(e,t+In,r,n,o,i);if(!v)return this;return a.length>=Gy?QI(e,c,v,s,a):new fi(e,s|l,Zy(f,u,v,a))}let h=a[u],g=h.modify(e,t+In,r,n,o,i);if(h===g)return this;let O=s,S;if(Wt(g)){if(O&=~l,!O)return new Yr;if(a.length<=2&&YI(a[u^1]))return a[u^1];S=sd(f,u,a)}else S=yo(f,u,g,a);if(f)return this.mask=O,this.children=S,this;return new fi(e,O,S)}}class cd{edit;size;children;_tag="ArrayNode";constructor(e,t,r){this.edit=e,this.size=t,this.children=r}modify(e,t,r,n,o,i){let s=this.size,a=this.children,c=kn(t,n),l=a[c],u=(l||new Yr).modify(e,t+In,r,n,o,i);if(l===u)return this;let d=vc(this,e),f;if(Wt(l)&&!Wt(u))++s,f=yo(d,c,u,a);else if(!Wt(l)&&Wt(u)){if(--s,s<=Jy)return ZI(e,s,c,a);f=yo(d,c,new Yr,a)}else f=yo(d,c,u,a);if(d)return this.size=s,this.children=f,this;return new cd(e,s,f)}}function ZI(e,t,r,n){let o=Array(t-1),i=0,s=0;for(let a=0,c=n.length;a<c;++a)if(a!==r){let l=n[a];if(l&&!Wt(l))o[i++]=l,s|=1<<a}return new fi(e,s,o)}function QI(e,t,r,n,o){let i=[],s=n,a=0;for(let c=0;s;++c){if(s&1)i[c]=o[a++];s>>>=1}return i[t]=r,new cd(e,a+1,i)}function XI(e,t,r,n,o,i){if(r===o)return new ad(e,r,[i,n]);let s=kn(t,r),a=kn(t,o);if(s===a)return(c)=>new fi(e,Rn(s)|Rn(a),[c]);else{let c=s<a?[n,i]:[i,n];return new fi(e,Rn(s)|Rn(a),c)}}function Qy(e,t,r,n,o,i){let s=void 0,a=t;while(!0){let c=XI(e,a,r,n,o,i);if(typeof c==="function")s=Yy(c,s),a=a+In;else{let l=c;while(s!=null)l=s.value(l),s=s.previous;return l}}}var Xy="effect/HashMap",Ac=Symbol.for(Xy),tk={[Ac]:Ac,[Symbol.iterator](){return new Ic(this,(e,t)=>[e,t])},[I](){let e=b(Xy);for(let t of this)e^=m(b(t[0]),K(b(t[1])));return Z(this,e)},[A](e){if(nx(e)){if(e._size!==this._size)return!1;for(let t of this){let r=m(e,kc(t[0],b(t[0])));if(Se(r))return!1;else if(!_(t[1],r.value))return!1}return!0}return!1},toString(){return ie(this.toJSON())},toJSON(){return{_id:"HashMap",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return x(this,arguments)}},ld=(e,t,r,n)=>{let o=Object.create(tk);return o._editable=e,o._edit=t,o._root=r,o._size=n,o};class Ic{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=ex(this.map._root,this.f,void 0)}next(){if(Se(this.v))return{done:!0,value:void 0};let e=this.v.value;return this.v=Tc(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new Ic(this.map,this.f)}}var Tc=(e)=>e?tx(e[0],e[1],e[2],e[3],e[4]):E(),ex=(e,t,r=void 0)=>{switch(e._tag){case"LeafNode":{if(pe(e.value))return P({value:t(e.key,e.value.value),cont:r});return Tc(r)}case"CollisionNode":case"ArrayNode":case"IndexedNode":{let n=e.children;return tx(n.length,n,0,t,r)}default:return Tc(r)}},tx=(e,t,r,n,o)=>{while(r<e){let i=t[r++];if(i&&!Wt(i))return ex(i,n,[e,t,r,n,o])}return Tc(o)},rk=ld(!1,0,new Yr,0),mi=()=>rk;var rx=(e)=>{let t=Cc(mi());for(let r of e)So(t,r[0],r[1]);return sx(t)},nx=(e)=>w(e,Ac),ox=(e)=>e&&Wt(e._root),ix=p(2,(e,t)=>kc(e,t,b(t))),kc=p(3,(e,t,r)=>{let n=e._root,o=0;while(!0)switch(n._tag){case"LeafNode":return _(t,n.key)?n.value:E();case"CollisionNode":{if(r===n.hash){let i=n.children;for(let s=0,a=i.length;s<a;++s){let c=i[s];if("key"in c&&_(t,c.key))return c.value}}return E()}case"IndexedNode":{let i=kn(o,r),s=Rn(i);if(n.mask&s){n=n.children[Oc(n.mask,s)],o+=In;break}return E()}case"ArrayNode":{if(n=n.children[kn(o,r)],n){o+=In;break}return E()}default:return E()}});var ud=p(2,(e,t)=>pe(kc(e,t,b(t))));var So=p(3,(e,t,r)=>Pc(e,t,()=>P(r))),nk=p(3,(e,t,r)=>{if(e._editable)return e._root=t,e._size=r,e;return t===e._root?e:ld(e._editable,e._edit,t,r)}),Rc=(e)=>new Ic(e,(t)=>t);var Ns=(e)=>e._size;var Cc=(e)=>ld(!0,e._edit+1,e._root,e._size),sx=(e)=>(e._editable=!1,e);var Pc=p(3,(e,t,r)=>ax(e,t,b(t),r)),ax=p(4,(e,t,r,n)=>{let o={value:e._size},i=e._root.modify(e._editable?e._edit:NaN,0,n,r,t,o);return m(e,nk(i,o.value))});var Fc=p(2,(e,t)=>Pc(e,t,E));var cx=p(2,(e,t)=>hi(e,mi(),(r,n,o)=>So(r,o,t(n,o))));var pd=p(2,(e,t)=>hi(e,void 0,(r,n,o)=>t(n,o))),hi=p(3,(e,t,r)=>{let n=e._root;if(n._tag==="LeafNode")return pe(n.value)?r(t,n.value.value,n.key):t;if(n._tag==="EmptyNode")return t;let o=[n.children],i;while(i=o.pop())for(let s=0,a=i.length;s<a;){let c=i[s++];if(c&&!Wt(c))if(c._tag==="LeafNode"){if(pe(c.value))t=r(t,c.value.value,c.key)}else o.push(c.children)}return t});var ux="effect/HashSet",Nc=Symbol.for(ux),ok={[Nc]:Nc,[Symbol.iterator](){return Rc(this._keyMap)},[I](){return Z(this,K(b(this._keyMap))(b(ux)))},[A](e){if(px(e))return Ns(this._keyMap)===Ns(e._keyMap)&&_(this._keyMap,e._keyMap);return!1},toString(){return ie(this.toJSON())},toJSON(){return{_id:"HashSet",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return x(this,arguments)}},Mc=(e)=>{let t=Object.create(ok);return t._keyMap=e,t},px=(e)=>w(e,Nc),ik=Mc(mi()),Ms=()=>ik,dx=(e)=>{let t=Lc(Ms());for(let r of e)gi(t,r);return Dc(t)},fx=(...e)=>{let t=Lc(Ms());for(let r of e)gi(t,r);return Dc(t)},mx=p(2,(e,t)=>ud(e._keyMap,t));var hx=(e)=>Ns(e._keyMap),Lc=(e)=>Mc(Cc(e._keyMap)),Dc=(e)=>(e._keyMap._editable=!1,e),dd=p(2,(e,t)=>{let r=Lc(e);return t(r),Dc(r)}),gi=p(2,(e,t)=>e._keyMap._editable?(So(t,!0)(e._keyMap),e):Mc(So(t,!0)(e._keyMap))),fd=p(2,(e,t)=>e._keyMap._editable?(Fc(t)(e._keyMap),e):Mc(Fc(t)(e._keyMap))),gx=p(2,(e,t)=>dd(e,(r)=>{for(let n of t)fd(r,n)}));var yx=p(2,(e,t)=>dd(Ms(),(r)=>{xx(e,(n)=>gi(r,n));for(let n of t)gi(r,n)}));var xx=p(2,(e,t)=>pd(e._keyMap,(r,n)=>t(n))),Sx=p(3,(e,t,r)=>hi(e._keyMap,t,(n,o,i)=>r(n,i)));var wr=Ms,bx=dx,bo=fx,_x=mx;var Ls=hx;var _o=gi,md=fd,hd=gx;var Zr=yx;var wo=Sx;var xi="Die",Cn="Empty",Pn="Fail",Eo="Interrupt",Oo="Parallel",vo="Sequential";var Ox="effect/Cause",xd=Symbol.for(Ox),ck={_E:(e)=>e},Si={[xd]:ck,[I](){return m(b(Ox),K(b(uk(this))),Z(this))},[A](e){return vx(e)&&lk(this,e)},pipe(){return x(this,arguments)},toJSON(){switch(this._tag){case"Empty":return{_id:"Cause",_tag:this._tag};case"Die":return{_id:"Cause",_tag:this._tag,defect:re(this.defect)};case"Interrupt":return{_id:"Cause",_tag:this._tag,fiberId:this.fiberId.toJSON()};case"Fail":return{_id:"Cause",_tag:this._tag,failure:re(this.error)};case"Sequential":case"Parallel":return{_id:"Cause",_tag:this._tag,left:re(this.left),right:re(this.right)}}},toString(){return pr(this)},[Y](){return this.toJSON()}},Qr=(()=>{let e=Object.create(Si);return e._tag=Cn,e})(),bi=(e)=>{let t=Object.create(Si);return t._tag=Pn,t.error=e,t},Lt=(e)=>{let t=Object.create(Si);return t._tag=xi,t.defect=e,t},ur=(e)=>{let t=Object.create(Si);return t._tag=Eo,t.fiberId=e,t},Io=(e,t)=>{let r=Object.create(Si);return r._tag=Oo,r.left=e,r.right=t,r},tt=(e,t)=>{let r=Object.create(Si);return r._tag=vo,r.left=e,r.right=t,r},vx=(e)=>w(e,xd),Sd=(e)=>e._tag===Cn,Ax=(e)=>e._tag===Pn;var qc=(e)=>{if(e._tag===Cn)return!0;return Ao(e,!0,(t,r)=>{switch(r._tag){case Cn:return P(t);case xi:case Pn:case Eo:return P(!1);default:return E()}})};var Uc=(e)=>pe(Tx(e)),_i=(e)=>$c(void 0,dk)(e),bd=(e)=>Tn(Ao(e,Kt(),(t,r)=>r._tag===Pn?P(m(t,et(r.error))):E())),_d=(e)=>Tn(Ao(e,Kt(),(t,r)=>r._tag===xi?P(m(t,et(r.defect))):E())),wd=(e)=>Ao(e,wr(),(t,r)=>r._tag===Eo?P(m(t,_o(r.fiberId))):E()),Ed=(e)=>Od(e,(t)=>t._tag===Pn?P(t.error):E()),Hc=(e)=>{let t=Ed(e);switch(t._tag){case"None":return z(e);case"Some":return B(t.value)}};var Tx=(e)=>Od(e,(t)=>t._tag===Eo?P(t.fiberId):E());var jc=(e)=>vd(e,{onEmpty:Qr,onFail:()=>Qr,onDie:Lt,onInterrupt:ur,onSequential:tt,onParallel:Io}),Ix=(e)=>vd(e,{onEmpty:Qr,onFail:Lt,onDie:Lt,onInterrupt:ur,onSequential:tt,onParallel:Io});var lk=(e,t)=>{let r=Fe(e),n=Fe(t);while(ar(r)&&ar(n)){let[o,i]=m(cr(r),Ao([wr(),Kt()],([c,l],u)=>{let[d,f]=gd(u);return P([m(c,Zr(d)),m(l,Mt(f))])})),[s,a]=m(cr(n),Ao([wr(),Kt()],([c,l],u)=>{let[d,f]=gd(u);return P([m(c,Zr(d)),m(l,Mt(f))])}));if(!_(o,s))return!1;r=i,n=a}return!0},uk=(e)=>pk(Fe(e),Kt()),pk=(e,t)=>{while(!0){let[r,n]=m(e,pi([wr(),Kt()],([i,s],a)=>{let[c,l]=gd(a);return[m(i,Zr(c)),m(s,Mt(l))]})),o=Ls(r)>0?m(t,et(r)):t;if(Vy(n))return Tn(o);e=n,t=o}throw Error(lo("Cause.flattenCauseLoop"))},Od=p(2,(e,t)=>{let r=[e];while(r.length>0){let n=r.pop(),o=t(n);switch(o._tag){case"None":{switch(n._tag){case vo:case Oo:{r.push(n.right),r.push(n.left);break}}break}case"Some":return o}}return E()});var gd=(e)=>{let t=e,r=[],n=wr(),o=Kt();while(t!==void 0)switch(t._tag){case Cn:{if(r.length===0)return[n,o];t=r.pop();break}case Pn:{if(n=_o(n,Ps(t._tag,t.error)),r.length===0)return[n,o];t=r.pop();break}case xi:{if(n=_o(n,Ps(t._tag,t.defect)),r.length===0)return[n,o];t=r.pop();break}case Eo:{if(n=_o(n,Ps(t._tag,t.fiberId)),r.length===0)return[n,o];t=r.pop();break}case vo:{switch(t.left._tag){case Cn:{t=t.right;break}case vo:{t=tt(t.left.left,tt(t.left.right,t.right));break}case Oo:{t=Io(tt(t.left.left,t.right),tt(t.left.right,t.right));break}default:{o=et(o,t.right),t=t.left;break}}break}case Oo:{r.push(t.right),t=t.left;break}}throw Error(lo("Cause.evaluateCauseLoop"))};var dk={emptyCase:ms,failCase:Sn,dieCase:Sn,interruptCase:ms,sequentialCase:(e,t,r)=>t&&r,parallelCase:(e,t,r)=>t&&r};var wx="SequentialCase",Ex="ParallelCase",vd=p(2,(e,{onDie:t,onEmpty:r,onFail:n,onInterrupt:o,onParallel:i,onSequential:s})=>$c(e,void 0,{emptyCase:()=>r,failCase:(a,c)=>n(c),dieCase:(a,c)=>t(c),interruptCase:(a,c)=>o(c),sequentialCase:(a,c,l)=>s(c,l),parallelCase:(a,c,l)=>i(c,l)})),Ao=p(3,(e,t,r)=>{let n=t,o=e,i=[];while(o!==void 0){let s=r(n,o);switch(n=pe(s)?s.value:n,o._tag){case vo:{i.push(o.right),o=o.left;break}case Oo:{i.push(o.right),o=o.left;break}default:{o=void 0;break}}if(o===void 0&&i.length>0)o=i.pop()}return n}),$c=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._tag){case Cn:{o.push(z(r.emptyCase(t)));break}case Pn:{o.push(z(r.failCase(t,s.error)));break}case xi:{o.push(z(r.dieCase(t,s.defect)));break}case Eo:{o.push(z(r.interruptCase(t,s.fiberId)));break}case vo:{n.push(s.right),n.push(s.left),o.push(B({_tag:wx}));break}case Oo:{n.push(s.right),n.push(s.left),o.push(B({_tag:Ex}));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._tag){case"Left":{switch(s.left._tag){case wx:{let a=i.pop(),c=i.pop(),l=r.sequentialCase(t,a,c);i.push(l);break}case Ex:{let a=i.pop(),c=i.pop(),l=r.parallelCase(t,a,c);i.push(l);break}}break}case"Right":{i.push(s.right);break}}}if(i.length===0)throw Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");return i.pop()}),pr=(e,t)=>{if(_i(e))return"All fibers interrupted without errors.";return Ds(e).map(function(r){if(t?.renderErrorCause!==!0||r.cause===void 0)return r.stack;return`${r.stack} {
|
|
13
|
-
${
|
|
12
|
+
${i(u)}}`;return s(l,f)}return String(l)}return c(e,0)}var se=(e)=>JSON.stringify(e,null,2),CD={toJSON(){return re(this)},[Y](){return this.toJSON()},toString(){return se(this.toJSON())}};var jr=(e,t=2)=>{if(typeof e==="string")return e;try{return typeof e==="object"?yc(e,t):String(e)}catch{return String(e)}},yc=(e,t)=>{let r=[],n=JSON.stringify(e,(o,i)=>typeof i==="object"&&i!==null?r.includes(i)?void 0:r.push(i)&&(fo.fiberRefs!==void 0&&cy(i)?i[Fp](fo.fiberRefs):i):i,t);return r=void 0,n},Fp=Symbol.for("effect/Inspectable/Redactable"),cy=(e)=>typeof e==="object"&&e!==null&&(Fp in e),fo=B("effect/Inspectable/redactableState",()=>({fiberRefs:void 0})),ly=(e,t)=>{let r=fo.fiberRefs;fo.fiberRefs=e;try{return t()}finally{fo.fiberRefs=r}},uy=(e)=>{if(cy(e)&&fo.fiberRefs!==void 0)return e[Fp](fo.fiberRefs);return e};var b=(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 r=e;for(let n=0,o=t.length;n<o;n++)r=t[n](r);return r}}};var ho="Async",go="Commit",wt="Failure",As="OnFailure",si="OnSuccess",ai="OnSuccessAndFailure",Et="Success",xc="Sync",py="Tag",yo="UpdateRuntimeFlags",ci="While",li="Iterator",Sc="WithRuntime",ui="Yield",Ts="RevertFlags";var _I="3.22.2",Is=()=>_I;var fy=Symbol.for("effect/Effect"),my=Symbol.for("effect/Stream"),hy=Symbol.for("effect/Sink"),gy=Symbol.for("effect/Channel"),En={_R:(e)=>e,_E:(e)=>e,_A:(e)=>e,_V:Is()},wI={_A:(e)=>e,_In:(e)=>e,_L:(e)=>e,_E:(e)=>e,_R:(e)=>e},EI={_Env:(e)=>e,_InErr:(e)=>e,_InElem:(e)=>e,_InDone:(e)=>e,_OutErr:(e)=>e,_OutElem:(e)=>e,_OutDone:(e)=>e},$r={[fy]:En,[my]:En,[hy]:wI,[gy]:EI,[R](e){return this===e},[P](){return Z(this,ws(this))},[Symbol.iterator](){return new ii(new Hr(this))},pipe(){return b(this,arguments)}},Rs={[P](){return Z(this,hc(this))},[R](e){let t=Object.keys(this),r=Object.keys(e);if(t.length!==r.length)return!1;for(let n of t)if(!((n in e)&&E(this[n],e[n])))return!1;return!0}},On={...$r,_op:go},Lp={...On,...Rs},yy=function(){function e(){}return e.prototype=On,e}();var Sy=Symbol.for("effect/Option"),by={...$r,[Sy]:{_A:(e)=>e},[Y](){return this.toJSON()},toString(){return se(this.toJSON())}},OI=Object.assign(Object.create(by),{_tag:"Some",_op:"Some",[R](e){return Dp(e)&&Up(e)&&E(this.value,e.value)},[P](){return Z(this,V(w(this._tag))(w(this.value)))},toJSON(){return{_id:"Option",_tag:this._tag,value:re(this.value)}}}),vI=w("None"),AI=Object.assign(Object.create(by),{_tag:"None",_op:"None",[R](e){return Dp(e)&&qp(e)},[P](){return vI},toJSON(){return{_id:"Option",_tag:this._tag}}}),Dp=(e)=>v(e,Sy),qp=(e)=>e._tag==="None",Up=(e)=>e._tag==="Some",bc=Object.create(AI),ks=(e)=>{let t=Object.create(OI);return t.value=e,t};var Hp=Symbol.for("effect/Either"),wy={...$r,[Hp]:{_R:(e)=>e},[Y](){return this.toJSON()},toString(){return se(this.toJSON())}},TI=Object.assign(Object.create(wy),{_tag:"Right",_op:"Right",[R](e){return _c(e)&&$p(e)&&E(this.right,e.right)},[P](){return V(w(this._tag))(w(this.right))},toJSON(){return{_id:"Either",_tag:this._tag,right:re(this.right)}}}),II=Object.assign(Object.create(wy),{_tag:"Left",_op:"Left",[R](e){return _c(e)&&jp(e)&&E(this.left,e.left)},[P](){return V(w(this._tag))(w(this.left))},toJSON(){return{_id:"Either",_tag:this._tag,left:re(this.left)}}}),_c=(e)=>v(e,Hp),jp=(e)=>e._tag==="Left",$p=(e)=>e._tag==="Right",Ey=(e)=>{let t=Object.create(II);return t.left=e,t},Oy=(e)=>{let t=Object.create(TI);return t.right=e,t};var G=Oy;var K=Ey;var Bp=_c,ge=jp,ze=$p;var wc=p(2,(e,t)=>ge(e)?K(t(e.left)):G(e.right)),vy=p(2,(e,t)=>ze(e)?G(t(e.right)):K(e.left)),Cs=p(2,(e,{onLeft:t,onRight:r})=>ge(e)?t(e.left):r(e.right));var Ay=Cs({onLeft:te,onRight:te});var Wp=p(2,(e,t)=>{if(ze(e))return e.right;throw t(e.left)}),Ty=Wp(()=>Error("getOrThrow called on a Left"));var Kp=(e)=>e.length>0;var Iy=(e)=>(t,r)=>t===r?0:e(t,r);var Ry=Iy((e,t)=>e<t?-1:1);var Ec=p(2,(e,t)=>Iy((r,n)=>e(t(r),t(n))));var Vp=(e)=>p(2,(t,r)=>e(t,r)===1);var A=()=>bc,F=ks;var be=qp,de=Up,Ae=p(2,(e,{onNone:t,onSome:r})=>be(e)?t():r(e.value));var pe=p(2,(e,t)=>be(e)?t():e.value),rr=p(2,(e,t)=>be(e)?t():e),ky=p(2,(e,t)=>be(e)?F(t()):e);var Br=(e)=>e==null?A():F(e);var Ot=pe(uc),Cy=(e)=>(...t)=>{try{return F(e(...t))}catch{return A()}};var nr=p(2,(e,t)=>be(e)?A():F(t(e.value)));var or=p(2,(e,t)=>be(e)?A():t(e.value));var Py=p(2,(e,t)=>be(e)?A():Br(t(e.value)));var PI=(e)=>p(2,(t,r)=>be(t)?!1:e(t.value,r)),NI=Os(),Ny=PI(NI),Fy=p(2,(e,t)=>be(e)?!1:t(e.value));var My=(...e)=>e;var xo=(e)=>Array(e),Gp=p(2,(e,t)=>{let r=Math.max(1,Math.floor(e)),n=Array(r);for(let o=0;o<r;o++)n[o]=t(o);return n});var fe=(e)=>Array.isArray(e)?e:Array.from(e),Jp=(e)=>Array.isArray(e)?e:[e];var Ly=p(2,(e,{onEmpty:t,onNonEmpty:r})=>le(e)?r(Pe(e),ir(e)):t());var pi=p(2,(e,t)=>[t,...e]);var Dy=p(2,(e,t)=>[...e,t]),Yp=p(2,(e,t)=>fe(e).concat(fe(t)));var Zp=Array.isArray,MI=(e)=>e.length===0,qy=MI,vn=Kp,le=Kp;var Uy=(e,t)=>e<0||e>=t.length,LI=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),DI=p(2,(e,t)=>{let r=Math.floor(t);return Uy(r,e)?A():F(e[r])}),Qp=p(2,(e,t)=>{let r=Math.floor(t);if(Uy(r,e))throw Error(`Index ${r} out of bounds`);return e[r]});var Wr=DI(0),Pe=Qp(0),Hy=(e)=>le(e)?F(Xp(e)):A(),Xp=(e)=>e[e.length-1];var ir=(e)=>e.slice(1);var qI=(e,t)=>{let r=0;for(let n of e){if(!t(n,r))break;r++}return r},jy=p(2,(e,t)=>HI(e,qI(e,t))),$y=p(2,(e,t)=>{let r=fe(e);return r.slice(LI(t,r),r.length)});var ed=(e)=>Array.from(e).reverse(),Kr=p(2,(e,t)=>{let r=Array.from(e);return r.sort(t),r});var td=p(2,(e,t)=>By(e,t,My)),By=p(3,(e,t,r)=>{let n=fe(e),o=fe(t);if(le(n)&&le(o)){let i=[r(Pe(n),Pe(o))],s=Math.min(n.length,o.length);for(let a=1;a<s;a++)i[a]=r(n[a],o[a]);return i}return[]});var UI=Os();var HI=p(2,(e,t)=>{let r=Array.from(e),n=Math.floor(t);if(le(r)){if(n>=1)return jI(r,n);return[[],r]}return[r,[]]}),jI=p(2,(e,t)=>{let r=Math.max(1,Math.floor(t));return r>=e.length?[di(e),[]]:[pi(e.slice(1,r),Pe(e)),e.slice(r)]});var di=(e)=>e.slice();var $I=p(3,(e,t,r)=>{let n=fe(e),o=fe(t);if(le(n)){if(le(o))return Wy(r)(Yp(n,o));return n}return o}),An=p(2,(e,t)=>$I(e,t,UI));var Vr=()=>[],et=(e)=>[e],sr=p(2,(e,t)=>e.map(t)),Ps=p(2,(e,t)=>{if(qy(e))return[];let r=[];for(let n=0;n<e.length;n++){let o=t(e[n],n);for(let i=0;i<o.length;i++)r.push(o[i])}return r}),Oc=Ps(te),vc=p(2,(e,t)=>{let r=fe(e),n=[];for(let o=0;o<r.length;o++){let i=t(r[o],o);if(de(i))n.push(i.value)}return n});var fi=p(3,(e,t,r)=>fe(e).reduce((n,o,i)=>r(n,o,i),t));var rd=(e,t)=>{let r=[],n=e,o;while(de(o=t(n))){let[i,s]=o.value;r.push(i),n=s}return r};var Tn=ty;var Wy=p(2,(e,t)=>{let r=fe(e);if(le(r)){let n=[Pe(r)],o=ir(r);for(let i of o)if(n.every((s)=>!t(i,s)))n.push(i);return n}return[]}),nd=(e)=>Wy(e,Os());var zr=p(2,(e,t)=>fe(e).join(t));var Vy=Symbol.for("effect/Chunk");function VI(e,t,r,n,o){for(let i=t;i<Math.min(e.length,t+o);i++)r[n+i-t]=e[i];return r}var zy=[],zI=(e)=>xs((t,r)=>t.length===r.length&&Gr(t).every((n,o)=>e(n,mi(r,o)))),GI=zI(E),JI={[Vy]:{_A:(e)=>e},toString(){return se(this.toJSON())},toJSON(){return{_id:"Chunk",values:Gr(this).map(re)}},[Y](){return this.toJSON()},[R](e){return Gy(e)&&GI(this,e)},[P](){return Z(this,Nt(Gr(this)))},[Symbol.iterator](){switch(this.backing._tag){case"IArray":return this.backing.array[Symbol.iterator]();case"IEmpty":return zy[Symbol.iterator]();default:return Gr(this)[Symbol.iterator]()}},pipe(){return b(this,arguments)}},Le=(e)=>{let t=Object.create(JI);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=Er,t.right=Er;break}case"ISingleton":{t.length=1,t.depth=0,t.left=Er,t.right=Er;break}case"ISlice":{t.length=e.length,t.depth=e.chunk.depth+1,t.left=Er,t.right=Er;break}}return t},Gy=(e)=>v(e,Vy),Er=Le({_tag:"IEmpty"}),Bt=()=>Er,Ns=(...e)=>QI(e),Ne=(e)=>Le({_tag:"ISingleton",a:e}),Ac=(e)=>Gy(e)?e:Fs(fe(e)),od=(e,t,r)=>{switch(e.backing._tag){case"IArray":{VI(e.backing.array,0,t,r,e.length);break}case"IConcat":{od(e.left,t,r),od(e.right,t,r+e.left.length);break}case"ISingleton":{t[r]=e.backing.a;break}case"ISlice":{let n=0,o=r;while(n<e.length)t[o]=mi(e,n),n+=1,o+=1;break}}};var YI=(e)=>{switch(e.backing._tag){case"IEmpty":return zy;case"IArray":return e.backing.array;default:{let t=Array(e.length);return od(e,t,0),e.backing={_tag:"IArray",array:t},e.left=Er,e.right=Er,e.depth=0,t}}},Gr=YI,ZI=(e)=>{switch(e.backing._tag){case"IEmpty":case"ISingleton":return e;case"IArray":return Le({_tag:"IArray",array:ed(e.backing.array)});case"IConcat":return Le({_tag:"IConcat",left:In(e.backing.right),right:In(e.backing.left)});case"ISlice":return Fs(ed(Gr(e)))}},In=ZI;var Fs=(e)=>e.length===0?Bt():e.length===1?Ne(e[0]):Le({_tag:"IArray",array:e}),QI=(e)=>Fs(e),mi=p(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?mi(e.left,t):mi(e.right,t-e.left.length);case"ISlice":return mi(e.backing.chunk,t+e.backing.offset)}}),Jy=p(2,(e,t)=>Ft(e,Ne(t))),tt=p(2,(e,t)=>Ft(Ne(t),e));var id=p(2,(e,t)=>{if(t<=0)return e;else if(t>=e.length)return Er;else switch(e.backing._tag){case"ISlice":return Le({_tag:"ISlice",chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case"IConcat":{if(t>e.left.length)return id(e.right,t-e.left.length);return Le({_tag:"IConcat",left:id(e.left,t),right:e.right})}default:return Le({_tag:"ISlice",chunk:e,offset:t,length:e.length-t})}});var Ft=p(2,(e,t)=>{if(e.backing._tag==="IEmpty")return t;if(t.backing._tag==="IEmpty")return e;let r=t.depth-e.depth;if(Math.abs(r)<=1)return Le({_tag:"IConcat",left:e,right:t});else if(r<-1)if(e.left.depth>=e.right.depth){let n=Ft(e.right,t);return Le({_tag:"IConcat",left:e.left,right:n})}else{let n=Ft(e.right.right,t);if(n.depth===e.depth-3){let o=Le({_tag:"IConcat",left:e.right.left,right:n});return Le({_tag:"IConcat",left:e.left,right:o})}else{let o=Le({_tag:"IConcat",left:e.left,right:e.right.left});return Le({_tag:"IConcat",left:o,right:n})}}else if(t.right.depth>=t.left.depth){let n=Ft(e,t.left);return Le({_tag:"IConcat",left:n,right:t.right})}else{let n=Ft(e,t.left.left);if(n.depth===t.depth-3){let o=Le({_tag:"IConcat",left:n,right:t.left.right});return Le({_tag:"IConcat",left:o,right:t.right})}else{let o=Le({_tag:"IConcat",left:t.left.right,right:t.right});return Le({_tag:"IConcat",left:n,right:o})}}});var Yy=(e)=>e.length===0,ar=(e)=>e.length>0;var sd=(e)=>mi(e,0),cr=sd;var lr=(e)=>id(e,1);var Rn=5,ad=Math.pow(2,5),Zy=ad-1,Qy=ad/2,Xy=ad/4;function XI(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 kn(e,t){return t>>>e&Zy}function Cn(e){return 1<<e}function Tc(e,t){return XI(e&t-1)}var ex=(e,t)=>({value:e,previous:t});function So(e,t,r,n){let o=n;if(!e){let i=n.length;o=Array(i);for(let s=0;s<i;++s)o[s]=n[s]}return o[t]=r,o}function cd(e,t,r){let n=r.length-1,o=0,i=0,s=r;if(e)o=i=t;else{s=Array(n);while(o<t)s[i++]=r[o++]}++o;while(o<=n)s[i++]=r[o++];if(e)s.length=n;return s}function tx(e,t,r,n){let o=n.length;if(e){let c=o;while(c>=t)n[c--]=n[c];return n[t]=r,n}let i=0,s=0,a=Array(o+1);while(i<t)a[s++]=n[i++];a[t]=r;while(i<o)a[++s]=n[i++];return a}class Yr{_tag="EmptyNode";modify(e,t,r,n,o,i){let s=r(A());if(be(s))return new Yr;return++i.value,new bo(e,n,o,s)}}function Wt(e){return _s(e,"EmptyNode")}function tR(e){return Wt(e)||e._tag==="LeafNode"||e._tag==="CollisionNode"}function Ic(e,t){return Wt(e)?!1:t===e.edit}class bo{edit;hash;key;value;_tag="LeafNode";constructor(e,t,r,n){this.edit=e,this.hash=t,this.key=r,this.value=n}modify(e,t,r,n,o,i){if(E(o,this.key)){let a=r(this.value);if(a===this.value)return this;else if(be(a))return--i.value,new Yr;if(Ic(this,e))return this.value=a,this;return new bo(e,n,o,a)}let s=r(A());if(be(s))return this;return++i.value,rx(e,t,this.hash,this,n,new bo(e,n,o,s))}}class ld{edit;hash;children;_tag="CollisionNode";constructor(e,t,r){this.edit=e,this.hash=t,this.children=r}modify(e,t,r,n,o,i){if(n===this.hash){let a=Ic(this,e),c=this.updateCollisionList(a,e,this.hash,this.children,r,o,i);if(c===this.children)return this;return c.length>1?new ld(e,this.hash,c):c[0]}let s=r(A());if(be(s))return this;return++i.value,rx(e,t,this.hash,this,n,new bo(e,n,o,s))}updateCollisionList(e,t,r,n,o,i,s){let a=n.length;for(let l=0;l<a;++l){let u=n[l];if("key"in u&&E(i,u.key)){let d=u.value,f=o(d);if(f===d)return n;if(be(f))return--s.value,cd(e,l,n);return So(e,l,new bo(t,r,i,f),n)}}let c=o(A());if(be(c))return n;return++s.value,So(e,a,new bo(t,r,i,c),n)}}class hi{edit;mask;children;_tag="IndexedNode";constructor(e,t,r){this.edit=e,this.mask=t,this.children=r}modify(e,t,r,n,o,i){let s=this.mask,a=this.children,c=kn(t,n),l=Cn(c),u=Tc(s,l),d=s&l,f=Ic(this,e);if(!d){let x=new Yr().modify(e,t+Rn,r,n,o,i);if(!x)return this;return a.length>=Qy?nR(e,c,x,s,a):new hi(e,s|l,tx(f,u,x,a))}let g=a[u],y=g.modify(e,t+Rn,r,n,o,i);if(g===y)return this;let O=s,m;if(Wt(y)){if(O&=~l,!O)return new Yr;if(a.length<=2&&tR(a[u^1]))return a[u^1];m=cd(f,u,a)}else m=So(f,u,y,a);if(f)return this.mask=O,this.children=m,this;return new hi(e,O,m)}}class ud{edit;size;children;_tag="ArrayNode";constructor(e,t,r){this.edit=e,this.size=t,this.children=r}modify(e,t,r,n,o,i){let s=this.size,a=this.children,c=kn(t,n),l=a[c],u=(l||new Yr).modify(e,t+Rn,r,n,o,i);if(l===u)return this;let d=Ic(this,e),f;if(Wt(l)&&!Wt(u))++s,f=So(d,c,u,a);else if(!Wt(l)&&Wt(u)){if(--s,s<=Xy)return rR(e,s,c,a);f=So(d,c,new Yr,a)}else f=So(d,c,u,a);if(d)return this.size=s,this.children=f,this;return new ud(e,s,f)}}function rR(e,t,r,n){let o=Array(t-1),i=0,s=0;for(let a=0,c=n.length;a<c;++a)if(a!==r){let l=n[a];if(l&&!Wt(l))o[i++]=l,s|=1<<a}return new hi(e,s,o)}function nR(e,t,r,n,o){let i=[],s=n,a=0;for(let c=0;s;++c){if(s&1)i[c]=o[a++];s>>>=1}return i[t]=r,new ud(e,a+1,i)}function oR(e,t,r,n,o,i){if(r===o)return new ld(e,r,[i,n]);let s=kn(t,r),a=kn(t,o);if(s===a)return(c)=>new hi(e,Cn(s)|Cn(a),[c]);else{let c=s<a?[n,i]:[i,n];return new hi(e,Cn(s)|Cn(a),c)}}function rx(e,t,r,n,o,i){let s=void 0,a=t;while(!0){let c=oR(e,a,r,n,o,i);if(typeof c==="function")s=ex(c,s),a=a+Rn;else{let l=c;while(s!=null)l=s.value(l),s=s.previous;return l}}}var nx="effect/HashMap",Rc=Symbol.for(nx),sR={[Rc]:Rc,[Symbol.iterator](){return new Cc(this,(e,t)=>[e,t])},[P](){let e=w(nx);for(let t of this)e^=h(w(t[0]),V(w(t[1])));return Z(this,e)},[R](e){if(ax(e)){if(e._size!==this._size)return!1;for(let t of this){let r=h(e,Pc(t[0],w(t[0])));if(be(r))return!1;else if(!E(t[1],r.value))return!1}return!0}return!1},toString(){return se(this.toJSON())},toJSON(){return{_id:"HashMap",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return b(this,arguments)}},pd=(e,t,r,n)=>{let o=Object.create(sR);return o._editable=e,o._edit=t,o._root=r,o._size=n,o};class Cc{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=ox(this.map._root,this.f,void 0)}next(){if(be(this.v))return{done:!0,value:void 0};let e=this.v.value;return this.v=kc(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new Cc(this.map,this.f)}}var kc=(e)=>e?ix(e[0],e[1],e[2],e[3],e[4]):A(),ox=(e,t,r=void 0)=>{switch(e._tag){case"LeafNode":{if(de(e.value))return F({value:t(e.key,e.value.value),cont:r});return kc(r)}case"CollisionNode":case"ArrayNode":case"IndexedNode":{let n=e.children;return ix(n.length,n,0,t,r)}default:return kc(r)}},ix=(e,t,r,n,o)=>{while(r<e){let i=t[r++];if(i&&!Wt(i))return ox(i,n,[e,t,r,n,o])}return kc(o)},aR=pd(!1,0,new Yr,0),gi=()=>aR;var sx=(e)=>{let t=Fc(gi());for(let r of e)_o(t,r[0],r[1]);return ux(t)},ax=(e)=>v(e,Rc),cx=(e)=>e&&Wt(e._root),lx=p(2,(e,t)=>Pc(e,t,w(t))),Pc=p(3,(e,t,r)=>{let n=e._root,o=0;while(!0)switch(n._tag){case"LeafNode":return E(t,n.key)?n.value:A();case"CollisionNode":{if(r===n.hash){let i=n.children;for(let s=0,a=i.length;s<a;++s){let c=i[s];if("key"in c&&E(t,c.key))return c.value}}return A()}case"IndexedNode":{let i=kn(o,r),s=Cn(i);if(n.mask&s){n=n.children[Tc(n.mask,s)],o+=Rn;break}return A()}case"ArrayNode":{if(n=n.children[kn(o,r)],n){o+=Rn;break}return A()}default:return A()}});var dd=p(2,(e,t)=>de(Pc(e,t,w(t))));var _o=p(3,(e,t,r)=>Mc(e,t,()=>F(r))),cR=p(3,(e,t,r)=>{if(e._editable)return e._root=t,e._size=r,e;return t===e._root?e:pd(e._editable,e._edit,t,r)}),Nc=(e)=>new Cc(e,(t)=>t);var Ms=(e)=>e._size;var Fc=(e)=>pd(!0,e._edit+1,e._root,e._size),ux=(e)=>(e._editable=!1,e);var Mc=p(3,(e,t,r)=>px(e,t,w(t),r)),px=p(4,(e,t,r,n)=>{let o={value:e._size},i=e._root.modify(e._editable?e._edit:NaN,0,n,r,t,o);return h(e,cR(i,o.value))});var Lc=p(2,(e,t)=>Mc(e,t,A));var dx=p(2,(e,t)=>yi(e,gi(),(r,n,o)=>_o(r,o,t(n,o))));var fd=p(2,(e,t)=>yi(e,void 0,(r,n,o)=>t(n,o))),yi=p(3,(e,t,r)=>{let n=e._root;if(n._tag==="LeafNode")return de(n.value)?r(t,n.value.value,n.key):t;if(n._tag==="EmptyNode")return t;let o=[n.children],i;while(i=o.pop())for(let s=0,a=i.length;s<a;){let c=i[s++];if(c&&!Wt(c))if(c._tag==="LeafNode"){if(de(c.value))t=r(t,c.value.value,c.key)}else o.push(c.children)}return t});var mx="effect/HashSet",Dc=Symbol.for(mx),lR={[Dc]:Dc,[Symbol.iterator](){return Nc(this._keyMap)},[P](){return Z(this,V(w(this._keyMap))(w(mx)))},[R](e){if(hx(e))return Ms(this._keyMap)===Ms(e._keyMap)&&E(this._keyMap,e._keyMap);return!1},toString(){return se(this.toJSON())},toJSON(){return{_id:"HashSet",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return b(this,arguments)}},qc=(e)=>{let t=Object.create(lR);return t._keyMap=e,t},hx=(e)=>v(e,Dc),uR=qc(gi()),Ls=()=>uR,gx=(e)=>{let t=Uc(Ls());for(let r of e)xi(t,r);return Hc(t)},yx=(...e)=>{let t=Uc(Ls());for(let r of e)xi(t,r);return Hc(t)},xx=p(2,(e,t)=>dd(e._keyMap,t));var Sx=(e)=>Ms(e._keyMap),Uc=(e)=>qc(Fc(e._keyMap)),Hc=(e)=>(e._keyMap._editable=!1,e),md=p(2,(e,t)=>{let r=Uc(e);return t(r),Hc(r)}),xi=p(2,(e,t)=>e._keyMap._editable?(_o(t,!0)(e._keyMap),e):qc(_o(t,!0)(e._keyMap))),hd=p(2,(e,t)=>e._keyMap._editable?(Lc(t)(e._keyMap),e):qc(Lc(t)(e._keyMap))),bx=p(2,(e,t)=>md(e,(r)=>{for(let n of t)hd(r,n)}));var _x=p(2,(e,t)=>md(Ls(),(r)=>{wx(e,(n)=>xi(r,n));for(let n of t)xi(r,n)}));var wx=p(2,(e,t)=>fd(e._keyMap,(r,n)=>t(n))),Ex=p(3,(e,t,r)=>yi(e._keyMap,t,(n,o,i)=>r(n,i)));var Or=Ls,Ox=gx,wo=yx,vx=xx;var Ds=Sx;var Eo=xi,gd=hd,yd=bx;var Zr=_x;var Oo=Ex;var bi="Die",Pn="Empty",Nn="Fail",vo="Interrupt",Ao="Parallel",To="Sequential";var Ix="effect/Cause",bd=Symbol.for(Ix),fR={_E:(e)=>e},_i={[bd]:fR,[P](){return h(w(Ix),V(w(hR(this))),Z(this))},[R](e){return Rx(e)&&mR(this,e)},pipe(){return b(this,arguments)},toJSON(){switch(this._tag){case"Empty":return{_id:"Cause",_tag:this._tag};case"Die":return{_id:"Cause",_tag:this._tag,defect:re(this.defect)};case"Interrupt":return{_id:"Cause",_tag:this._tag,fiberId:this.fiberId.toJSON()};case"Fail":return{_id:"Cause",_tag:this._tag,failure:re(this.error)};case"Sequential":case"Parallel":return{_id:"Cause",_tag:this._tag,left:re(this.left),right:re(this.right)}}},toString(){return pr(this)},[Y](){return this.toJSON()}},Qr=(()=>{let e=Object.create(_i);return e._tag=Pn,e})(),wi=(e)=>{let t=Object.create(_i);return t._tag=Nn,t.error=e,t},Mt=(e)=>{let t=Object.create(_i);return t._tag=bi,t.defect=e,t},ur=(e)=>{let t=Object.create(_i);return t._tag=vo,t.fiberId=e,t},ko=(e,t)=>{let r=Object.create(_i);return r._tag=Ao,r.left=e,r.right=t,r},rt=(e,t)=>{let r=Object.create(_i);return r._tag=To,r.left=e,r.right=t,r},Rx=(e)=>v(e,bd),_d=(e)=>e._tag===Pn,kx=(e)=>e._tag===Nn;var jc=(e)=>{if(e._tag===Pn)return!0;return Io(e,!0,(t,r)=>{switch(r._tag){case Pn:return F(t);case bi:case Nn:case vo:return F(!1);default:return A()}})};var $c=(e)=>de(Cx(e)),Ei=(e)=>Kc(void 0,yR)(e),wd=(e)=>In(Io(e,Bt(),(t,r)=>r._tag===Nn?F(h(t,tt(r.error))):A())),Ed=(e)=>In(Io(e,Bt(),(t,r)=>r._tag===bi?F(h(t,tt(r.defect))):A())),Od=(e)=>Io(e,Or(),(t,r)=>r._tag===vo?F(h(t,Eo(r.fiberId))):A()),vd=(e)=>Ad(e,(t)=>t._tag===Nn?F(t.error):A()),Bc=(e)=>{let t=vd(e);switch(t._tag){case"None":return G(e);case"Some":return K(t.value)}};var Cx=(e)=>Ad(e,(t)=>t._tag===vo?F(t.fiberId):A());var Wc=(e)=>Td(e,{onEmpty:Qr,onFail:()=>Qr,onDie:Mt,onInterrupt:ur,onSequential:rt,onParallel:ko}),Px=(e)=>Td(e,{onEmpty:Qr,onFail:Mt,onDie:Mt,onInterrupt:ur,onSequential:rt,onParallel:ko});var mR=(e,t)=>{let r=Ne(e),n=Ne(t);while(ar(r)&&ar(n)){let[o,i]=h(cr(r),Io([Or(),Bt()],([c,l],u)=>{let[d,f]=xd(u);return F([h(c,Zr(d)),h(l,Ft(f))])})),[s,a]=h(cr(n),Io([Or(),Bt()],([c,l],u)=>{let[d,f]=xd(u);return F([h(c,Zr(d)),h(l,Ft(f))])}));if(!E(o,s))return!1;r=i,n=a}return!0},hR=(e)=>gR(Ne(e),Bt()),gR=(e,t)=>{while(!0){let[r,n]=h(e,fi([Or(),Bt()],([i,s],a)=>{let[c,l]=xd(a);return[h(i,Zr(c)),h(s,Ft(l))]})),o=Ds(r)>0?h(t,tt(r)):t;if(Yy(n))return In(o);e=n,t=o}throw Error(po("Cause.flattenCauseLoop"))},Ad=p(2,(e,t)=>{let r=[e];while(r.length>0){let n=r.pop(),o=t(n);switch(o._tag){case"None":{switch(n._tag){case To:case Ao:{r.push(n.right),r.push(n.left);break}}break}case"Some":return o}}return A()});var xd=(e)=>{let t=e,r=[],n=Or(),o=Bt();while(t!==void 0)switch(t._tag){case Pn:{if(r.length===0)return[n,o];t=r.pop();break}case Nn:{if(n=Eo(n,Ns(t._tag,t.error)),r.length===0)return[n,o];t=r.pop();break}case bi:{if(n=Eo(n,Ns(t._tag,t.defect)),r.length===0)return[n,o];t=r.pop();break}case vo:{if(n=Eo(n,Ns(t._tag,t.fiberId)),r.length===0)return[n,o];t=r.pop();break}case To:{switch(t.left._tag){case Pn:{t=t.right;break}case To:{t=rt(t.left.left,rt(t.left.right,t.right));break}case Ao:{t=ko(rt(t.left.left,t.right),rt(t.left.right,t.right));break}default:{o=tt(o,t.right),t=t.left;break}}break}case Ao:{r.push(t.right),t=t.left;break}}throw Error(po("Cause.evaluateCauseLoop"))};var yR={emptyCase:hs,failCase:bn,dieCase:bn,interruptCase:hs,sequentialCase:(e,t,r)=>t&&r,parallelCase:(e,t,r)=>t&&r};var Ax="SequentialCase",Tx="ParallelCase",Td=p(2,(e,{onDie:t,onEmpty:r,onFail:n,onInterrupt:o,onParallel:i,onSequential:s})=>Kc(e,void 0,{emptyCase:()=>r,failCase:(a,c)=>n(c),dieCase:(a,c)=>t(c),interruptCase:(a,c)=>o(c),sequentialCase:(a,c,l)=>s(c,l),parallelCase:(a,c,l)=>i(c,l)})),Io=p(3,(e,t,r)=>{let n=t,o=e,i=[];while(o!==void 0){let s=r(n,o);switch(n=de(s)?s.value:n,o._tag){case To:{i.push(o.right),o=o.left;break}case Ao:{i.push(o.right),o=o.left;break}default:{o=void 0;break}}if(o===void 0&&i.length>0)o=i.pop()}return n}),Kc=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._tag){case Pn:{o.push(G(r.emptyCase(t)));break}case Nn:{o.push(G(r.failCase(t,s.error)));break}case bi:{o.push(G(r.dieCase(t,s.defect)));break}case vo:{o.push(G(r.interruptCase(t,s.fiberId)));break}case To:{n.push(s.right),n.push(s.left),o.push(K({_tag:Ax}));break}case Ao:{n.push(s.right),n.push(s.left),o.push(K({_tag:Tx}));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._tag){case"Left":{switch(s.left._tag){case Ax:{let a=i.pop(),c=i.pop(),l=r.sequentialCase(t,a,c);i.push(l);break}case Tx:{let a=i.pop(),c=i.pop(),l=r.parallelCase(t,a,c);i.push(l);break}}break}case"Right":{i.push(s.right);break}}}if(i.length===0)throw Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");return i.pop()}),pr=(e,t)=>{if(Ei(e))return"All fibers interrupted without errors.";return qs(e).map(function(r){if(t?.renderErrorCause!==!0||r.cause===void 0)return r.stack;return`${r.stack} {
|
|
13
|
+
${Nx(r.cause," ")}
|
|
14
14
|
}`}).join(`
|
|
15
|
-
`)},
|
|
15
|
+
`)},Nx=(e,t)=>{let r=e.stack.split(`
|
|
16
16
|
`),n=`${t}[cause]: ${r[0]}`;for(let o=1,i=r.length;o<i;o++)n+=`
|
|
17
17
|
${t}${r[o]}`;if(e.cause)n+=` {
|
|
18
|
-
${
|
|
19
|
-
${t}}`;return n},
|
|
18
|
+
${Nx(e.cause,`${t} `)}
|
|
19
|
+
${t}}`;return n},Sd=(e)=>{let t=typeof e==="object"&&e!==null,r=Error.stackTraceLimit;Error.stackTraceLimit=1;let n=Error(xR(e),t&&"cause"in e&&typeof e.cause<"u"?{cause:Sd(e.cause)}:void 0);if(Error.stackTraceLimit=r,n.message==="")n.message="An error has occurred";if(Error.stackTraceLimit=r,n.name=e instanceof Error?e.name:"Error",t){if(Ro in e)n.span=e[Ro];Object.keys(e).forEach((o)=>{if(!(o in n))n[o]=e[o]})}return n.stack=_R(`${n.name}: ${n.message}`,e instanceof Error&&e.stack?e.stack:"",n.span),n},xR=(e)=>{if(typeof e==="string")return e;if(typeof e==="object"&&e!==null&&e instanceof Error)return e.message;try{if(v(e,"toString")&&wn(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return yc(e)},SR=/\((.*)\)/g,bR=B("effect/Tracer/spanToTrace",()=>new WeakMap),_R=(e,t,r)=>{let n=[e],o=t.startsWith(e)?t.slice(e.length).split(`
|
|
20
20
|
`):t.split(`
|
|
21
|
-
`);for(let i=1;i<o.length;i++){if(o[i].includes(" at new BaseEffectError")||o[i].includes(" at new YieldableError")){i++;continue}if(o[i].includes("Generator.next"))break;if(o[i].includes("effect_internal_function"))break;n.push(o[i].replace(/at .*effect_instruction_i.*\((.*)\)/,"at $1").replace(/EffectPrimitive\.\w+/,"<anonymous>"))}if(r){let i=r,s=0;while(i&&i._tag==="Span"&&s<10){let a=
|
|
22
|
-
`)},
|
|
21
|
+
`);for(let i=1;i<o.length;i++){if(o[i].includes(" at new BaseEffectError")||o[i].includes(" at new YieldableError")){i++;continue}if(o[i].includes("Generator.next"))break;if(o[i].includes("effect_internal_function"))break;n.push(o[i].replace(/at .*effect_instruction_i.*\((.*)\)/,"at $1").replace(/EffectPrimitive\.\w+/,"<anonymous>"))}if(r){let i=r,s=0;while(i&&i._tag==="Span"&&s<10){let a=bR.get(i);if(typeof a==="function"){let c=a();if(typeof c==="string"){let l=c.matchAll(SR),u=!1;for(let[,d]of l)u=!0,n.push(` at ${i.name} (${d})`);if(!u)n.push(` at ${i.name} (${c.replace(/^at /,"")})`)}else n.push(` at ${i.name}`)}else n.push(` at ${i.name}`);i=Ot(i.parent),s++}}return n.join(`
|
|
22
|
+
`)},Ro=Symbol.for("effect/SpanAnnotation"),qs=(e)=>Kc(e,void 0,{emptyCase:()=>[],dieCase:(t,r)=>[Sd(r)],failCase:(t,r)=>[Sd(r)],interruptCase:()=>[],parallelCase:(t,r,n)=>[...r,...n],sequentialCase:(t,r,n)=>[...r,...n]});var Fx=Symbol.for("effect/Context/Tag"),Hs=Symbol.for("effect/Context/Reference"),wR="effect/STM",ER=Symbol.for(wR),Mx={...$r,_op:"Tag",[ER]:En,[Fx]:{_Service:(e)=>e,_Identifier:(e)=>e},toString(){return se(this.toJSON())},toJSON(){return{_id:"Tag",key:this.key,stack:this.stack}},[Y](){return this.toJSON()},of(e){return e},context(e){return kd(this,e)}},OR={...Mx,[Hs]:Hs},Lx=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let r=Error();Error.stackTraceLimit=t;let n=Object.create(Mx);return Object.defineProperty(n,"stack",{get(){return r.stack}}),n.key=e,n};var Dx=()=>(e,t)=>{let r=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=r;function o(){}return Object.setPrototypeOf(o,OR),o.key=e,o.defaultValue=t.defaultValue,Object.defineProperty(o,"stack",{get(){return n.stack}}),o},Rd=Symbol.for("effect/Context"),vR={[Rd]:{_Services:(e)=>e},[R](e){if(qx(e)){if(this.unsafeMap.size===e.unsafeMap.size){for(let t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!E(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}}return!1},[P](){return Z(this,mc(this.unsafeMap.size))},pipe(){return b(this,arguments)},toString(){return se(this.toJSON())},toJSON(){return{_id:"Context",services:Array.from(this.unsafeMap).map(re)}},[Y](){return this.toJSON()}},Fn=(e)=>{let t=Object.create(vR);return t.unsafeMap=e,t},AR=(e)=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(e.stack){let r=e.stack.split(`
|
|
23
23
|
`);if(r.length>2){let n=r[2].match(/at (.*)/);if(n)t.message=t.message+` (defined at ${n[1]})`}}if(t.stack){let r=t.stack.split(`
|
|
24
24
|
`);r.splice(1,3),t.stack=r.join(`
|
|
25
|
-
`)}return t},Nx=(e)=>w(e,Td);var Mx=(e)=>w(e,Us),wk=Fn(new Map),Lx=()=>wk,Id=(e,t)=>Fn(new Map([[e.key,t]])),Dx=p(3,(e,t,r)=>{let n=new Map(e.unsafeMap);return n.set(t.key,r),Fn(n)}),Ad=U("effect/Context/defaultValueCache",()=>new Map),kd=(e)=>{if(Ad.has(e.key))return Ad.get(e.key);let t=e.defaultValue();return Ad.set(e.key,t),t},qx=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):kd(t),Rd=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(Us in t)return kd(t);throw _k(t)}return e.unsafeMap.get(t.key)}),Ux=Rd;var Hx=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key))return Mx(t)?ks(kd(t)):yc;return ks(e.unsafeMap.get(t.key))}),jx=p(2,(e,t)=>{let r=new Map(e.unsafeMap);for(let[n,o]of t.unsafeMap)r.set(n,o);return Fn(r)});var vt=Px;var Nn=Lx,Bx=Id,Er=Dx,Hs=Ux;var js=Rd,Mn=Hx,$s=jx;var Bs=Fx;var Pd=Symbol.for("effect/Duration"),Gx=BigInt(0),Kx=BigInt(24),Bc=BigInt(60),Fd=BigInt(1000),Wx=BigInt(1e6),Vx=BigInt(1e9),Ek=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,Xr=(e)=>{if(Jx(e))return e;else if(Ft(e))return Kc(e);else if(bn(e))return Cd(e);else if(Array.isArray(e)&&e.length===2&&e.every(Ft)){if(e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1]))return Nd;if(e[0]===1/0||e[1]===1/0)return Tk;return Cd(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])))}else if(We(e)){let t=Ek.exec(e);if(t){let[r,n,o]=t,i=Number(n);switch(o){case"nano":case"nanos":return Cd(BigInt(n));case"micro":case"micros":return Ik(BigInt(n));case"milli":case"millis":return Kc(i);case"second":case"seconds":return kk(i);case"minute":case"minutes":return Rk(i);case"hour":case"hours":return Ck(i);case"day":case"days":return Pk(i);case"week":case"weeks":return Fk(i)}}}throw Error("Invalid DurationInput")};var zx={_tag:"Millis",millis:0},Ok={_tag:"Infinity"},vk={[Pd]:Pd,[I](){return Z(this,dc(this.value))},[A](e){return Jx(e)&&qk(this,e)},toString(){return`Duration(${Hk(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:Mk(this)};case"Infinity":return{_id:"Duration",_tag:"Infinity"}}},[Y](){return this.toJSON()},pipe(){return x(this,arguments)}},Or=(e)=>{let t=Object.create(vk);if(Ft(e))if(isNaN(e)||e<=0)t.value=zx;else if(!Number.isFinite(e))t.value=Ok;else if(!Number.isInteger(e))t.value={_tag:"Nanos",nanos:BigInt(Math.round(e*1e6))};else t.value={_tag:"Millis",millis:e};else if(e<=Gx)t.value=zx;else t.value={_tag:"Nanos",nanos:e};return t},Jx=(e)=>w(e,Pd);var Ak=(e)=>{switch(e.value._tag){case"Millis":return e.value.millis===0;case"Nanos":return e.value.nanos===Gx;case"Infinity":return!1}},Nd=Or(0),Tk=Or(1/0),Cd=(e)=>Or(e),Ik=(e)=>Or(e*Fd),Kc=(e)=>Or(e),kk=(e)=>Or(e*1000),Rk=(e)=>Or(e*60000),Ck=(e)=>Or(e*3600000),Pk=(e)=>Or(e*86400000),Fk=(e)=>Or(e*604800000),Wc=(e)=>Lk(e,{onMillis:(t)=>t,onNanos:(t)=>Number(t)/1e6});var Nk=(e)=>{let t=Xr(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))}},Mk=(e)=>{let t=Xr(e);switch(t.value._tag){case"Infinity":return[1/0,0];case"Nanos":return[Number(t.value.nanos/Vx),Number(t.value.nanos%Vx)];case"Millis":return[Math.floor(t.value.millis/1000),Math.round(t.value.millis%1000*1e6)]}},Lk=p(2,(e,t)=>{let r=Xr(e);switch(r.value._tag){case"Nanos":return t.onNanos(r.value.nanos);case"Infinity":return t.onMillis(1/0);case"Millis":return t.onMillis(r.value.millis)}}),Md=p(3,(e,t,r)=>{let n=Xr(e),o=Xr(t);if(n.value._tag==="Infinity"||o.value._tag==="Infinity")return r.onMillis(Wc(n),Wc(o));else if(n.value._tag==="Nanos"||o.value._tag==="Nanos"){let i=n.value._tag==="Nanos"?n.value.nanos:BigInt(Math.round(n.value.millis*1e6)),s=o.value._tag==="Nanos"?o.value.nanos:BigInt(Math.round(o.value.millis*1e6));return r.onNanos(i,s)}return r.onMillis(n.value.millis,o.value.millis)});var Dk=(e,t)=>Md(e,t,{onMillis:(r,n)=>r===n,onNanos:(r,n)=>r===n});var Yx=p(2,(e,t)=>Md(e,t,{onMillis:(r,n)=>r<=n,onNanos:(r,n)=>r<=n}));var Zx=p(2,(e,t)=>Md(e,t,{onMillis:(r,n)=>r>=n,onNanos:(r,n)=>r>=n})),qk=p(2,(e,t)=>Dk(Xr(e),Xr(t))),Uk=(e)=>{let t=Xr(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 r=Nk(t),n=r/Wx,o=n/Fd,i=o/Bc,s=i/Bc,a=s/Kx;return{days:Number(a),hours:Number(s%Kx),minutes:Number(i%Bc),seconds:Number(o%Bc),millis:Number(n%Fd),nanos:Number(r%Wx)}},Hk=(e)=>{let t=Xr(e);if(t.value._tag==="Infinity")return"Infinity";if(Ak(t))return"0";let r=Uk(t),n=[];if(r.days!==0)n.push(`${r.days}d`);if(r.hours!==0)n.push(`${r.hours}h`);if(r.minutes!==0)n.push(`${r.minutes}m`);if(r.seconds!==0)n.push(`${r.seconds}s`);if(r.millis!==0)n.push(`${r.millis}ms`);if(r.nanos!==0)n.push(`${r.nanos}ns`);return n.join(" ")};var Xx=Symbol.for("effect/MutableRef"),jk={[Xx]:Xx,toString(){return ie(this.toJSON())},toJSON(){return{_id:"MutableRef",current:re(this.current)}},[Y](){return this.toJSON()},pipe(){return x(this,arguments)}},Vc=(e)=>{let t=Object.create(jk);return t.current=e,t};var wi=(e)=>e.current;var zc=p(2,(e,t)=>(e.current=t,e));var Dd="effect/FiberId",Ei=Symbol.for(Dd),Gc="None",Ld="Runtime",$k="Composite",Bk=oe(`${Dd}-${Gc}`);class rS{[Ei]=Ei;_tag=Gc;id=-1;startTimeMillis=-1;[I](){return Bk}[A](e){return qd(e)&&e._tag===Gc}toString(){return ie(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag}}[Y](){return this.toJSON()}}class nS{id;startTimeMillis;[Ei]=Ei;_tag=Ld;constructor(e,t){this.id=e,this.startTimeMillis=t}[I](){return Z(this,oe(`${Dd}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[A](e){return qd(e)&&e._tag===Ld&&this.id===e.id&&this.startTimeMillis===e.startTimeMillis}toString(){return ie(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag,id:this.id,startTimeMillis:this.startTimeMillis}}[Y](){return this.toJSON()}}var oS=new rS;var qd=(e)=>w(e,Ei);var Jc=(e)=>{switch(e._tag){case Gc:return wr();case Ld:return bo(e.id);case $k:return m(Jc(e.left),Zr(Jc(e.right)))}},tS=U(Symbol.for("effect/Fiber/Id/_fiberCounter"),()=>Vc(0));var Yc=(e)=>Array.from(Jc(e)).map((r)=>`#${r}`).join(",");var iS=()=>{let e=wi(tS);return m(tS,zc(e+1)),new nS(e,Date.now())};var Vt=oS;var aS=Yc;var Zc=iS;var Oi=mi;var cS=rx,lS=ox,Ud=ix;var Hd=So,jd=Rc;var uS=Pc;var pS=cx;var $d=hi;var Ws=Symbol.for("effect/List"),Kd=(e)=>de(e),Kk=(e)=>Op(An(e),Kd),Wk=Kk(_),Vk={[Ws]:Ws,_tag:"Cons",toString(){return ie(this.toJSON())},toJSON(){return{_id:"List",_tag:"Cons",values:Kd(this).map(re)}},[Y](){return this.toJSON()},[A](e){return fS(e)&&this._tag===e._tag&&Wk(this,e)},[I](){return Z(this,Nt(Kd(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 r=t.head;return t=t.tail,{done:e,value:r}},return(r){if(!e)e=!0;return{done:!0,value:r}}}},pipe(){return x(this,arguments)}},Qc=(e,t)=>{let r=Object.create(Vk);return r.head=e,r.tail=t,r},zk=oe("Nil"),Gk={[Ws]:Ws,_tag:"Nil",toString(){return ie(this.toJSON())},toJSON(){return{_id:"List",_tag:"Nil"}},[Y](){return this.toJSON()},[I](){return zk},[A](e){return fS(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return x(this,arguments)}},dS=Object.create(Gk),fS=(e)=>w(e,Ws),vr=(e)=>e._tag==="Nil",Wd=(e)=>e._tag==="Cons";var Jk=()=>dS,en=(e,t)=>Qc(e,t),Ln=Jk,Vs=(e)=>Qc(e,dS);var mS=p(2,(e,t)=>Zk(t,e)),Yk=p(2,(e,t)=>en(t,e)),Zk=p(2,(e,t)=>{if(vr(e))return t;else if(vr(t))return e;else{let r=Qc(t.head,e),n=r,o=t.tail;while(!vr(o)){let i=Qc(o.head,e);n.tail=i,n=i,o=o.tail}return r}});var hS=p(3,(e,t,r)=>{let n=t,o=e;while(!vr(o))n=r(n,o.head),o=o.tail;return n});var gS=(e)=>{let t=Ln(),r=e;while(!vr(r))t=Yk(t,r.head),r=r.tail;return t};var JU=Object.assign(Object.create(Array.prototype),{[I](){return Z(this,Nt(this))},[A](e){if(Array.isArray(e)&&this.length===e.length)return this.every((t,r)=>_(t,e[r]));else return!1}}),vi=function(){function e(t){if(t)Object.assign(this,t)}return e.prototype=Is,e}();var Xk=Symbol.for("effect/DifferContextPatch");function yS(e){return e}var Gs={...vi.prototype,[Xk]:{_Value:yS,_Patch:yS}},eR=Object.assign(Object.create(Gs),{_tag:"Empty"}),tR=Object.create(eR),zd=()=>tR,rR=Object.assign(Object.create(Gs),{_tag:"AndThen"}),nR=(e,t)=>{let r=Object.create(rR);return r.first=e,r.second=t,r},oR=Object.assign(Object.create(Gs),{_tag:"AddService"}),iR=(e,t)=>{let r=Object.create(oR);return r.key=e,r.service=t,r},sR=Object.assign(Object.create(Gs),{_tag:"RemoveService"}),aR=(e)=>{let t=Object.create(sR);return t.key=e,t},cR=Object.assign(Object.create(Gs),{_tag:"UpdateService"}),lR=(e,t)=>{let r=Object.create(cR);return r.key=e,r.update=t,r},xS=(e,t)=>{let r=new Map(e.unsafeMap),n=zd();for(let[o,i]of t.unsafeMap.entries())if(r.has(o)){let s=r.get(o);if(r.delete(o),!_(s,i))n=zs(lR(o,()=>i))(n)}else r.delete(o),n=zs(iR(o,i))(n);for(let[o]of r.entries())n=zs(aR(o))(n);return n},zs=p(2,(e,t)=>nR(e,t)),SS=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=!1,n=Fe(e),o=new Map(t.unsafeMap);while(ar(n)){let s=cr(n),a=lr(n);switch(s._tag){case"Empty":{n=a;break}case"AddService":{o.set(s.key,s.service),n=a;break}case"AndThen":{n=et(et(a,s.second),s.first);break}case"RemoveService":{o.delete(s.key),n=a;break}case"UpdateService":{o.set(s.key,s.update(o.get(s.key))),r=!0,n=a;break}}}if(!r)return Fn(o);let i=new Map;for(let[s]of t.unsafeMap)if(o.has(s))i.set(s,o.get(s)),o.delete(s);for(let[s,a]of o)i.set(s,a);return Fn(i)});var pR=Symbol.for("effect/DifferHashSetPatch");function Gd(e){return e}var el={...vi.prototype,[pR]:{_Value:Gd,_Key:Gd,_Patch:Gd}},dR=Object.assign(Object.create(el),{_tag:"Empty"}),fR=Object.create(dR),Jd=()=>fR,mR=Object.assign(Object.create(el),{_tag:"AndThen"}),hR=(e,t)=>{let r=Object.create(mR);return r.first=e,r.second=t,r},gR=Object.assign(Object.create(el),{_tag:"Add"}),yR=(e)=>{let t=Object.create(gR);return t.value=e,t},xR=Object.assign(Object.create(el),{_tag:"Remove"}),SR=(e)=>{let t=Object.create(xR);return t.value=e,t},bS=(e,t)=>{let[r,n]=wo([e,Jd()],([o,i],s)=>{if(_x(s)(o))return[md(s)(o),i];return[o,Xc(yR(s))(i)]})(t);return wo(n,(o,i)=>Xc(SR(i))(o))(r)},Xc=p(2,(e,t)=>hR(e,t)),_S=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=t,n=Fe(e);while(ar(n)){let o=cr(n),i=lr(n);switch(o._tag){case"Empty":{n=i;break}case"AndThen":{n=et(o.first)(et(o.second)(i));break}case"Add":{r=_o(o.value)(r),n=i;break}case"Remove":r=md(o.value)(r),n=i}}return r});var _R=Symbol.for("effect/DifferReadonlyArrayPatch");function wS(e){return e}var Ys={...vi.prototype,[_R]:{_Value:wS,_Patch:wS}},wR=Object.assign(Object.create(Ys),{_tag:"Empty"}),ER=Object.create(wR),Yd=()=>ER,OR=Object.assign(Object.create(Ys),{_tag:"AndThen"}),vR=(e,t)=>{let r=Object.create(OR);return r.first=e,r.second=t,r},AR=Object.assign(Object.create(Ys),{_tag:"Append"}),TR=(e)=>{let t=Object.create(AR);return t.values=e,t},IR=Object.assign(Object.create(Ys),{_tag:"Slice"}),kR=(e,t)=>{let r=Object.create(IR);return r.from=e,r.until=t,r},RR=Object.assign(Object.create(Ys),{_tag:"Update"}),CR=(e,t)=>{let r=Object.create(RR);return r.index=e,r.patch=t,r},ES=(e)=>{let t=0,r=Yd();while(t<e.oldValue.length&&t<e.newValue.length){let n=e.oldValue[t],o=e.newValue[t],i=e.differ.diff(n,o);if(!_(i,e.differ.empty))r=Js(r,CR(t,i));t=t+1}if(t<e.oldValue.length)r=Js(r,kR(0,t));if(t<e.newValue.length)r=Js(r,TR(qy(t)(e.newValue)));return r},Js=p(2,(e,t)=>vR(e,t)),OS=p(3,(e,t,r)=>{if(e._tag==="Empty")return t;let n=t.slice(),o=Xe(e);while(On(o)){let i=Pe(o),s=ir(o);switch(i._tag){case"Empty":{o=s;break}case"AndThen":{s.unshift(i.first,i.second),o=s;break}case"Append":{for(let a of i.values)n.push(a);o=s;break}case"Slice":{n=n.slice(i.from,i.until),o=s;break}case"Update":{n[i.index]=r.patch(i.patch,n[i.index]),o=s;break}}}return n});var vS=Symbol.for("effect/Differ"),FR={[vS]:{_P:te,_V:te},pipe(){return x(this,arguments)}},Dn=(e)=>{let t=Object.create(FR);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},Zd=()=>Dn({empty:zd(),combine:(e,t)=>zs(t)(e),diff:(e,t)=>xS(e,t),patch:(e,t)=>SS(t)(e)});var Qd=()=>Dn({empty:Jd(),combine:(e,t)=>Xc(t)(e),diff:(e,t)=>bS(e,t),patch:(e,t)=>_S(t)(e)});var Xd=(e)=>Dn({empty:Yd(),combine:(t,r)=>Js(t,r),diff:(t,r)=>ES({oldValue:t,newValue:r,differ:e}),patch:(t,r)=>OS(t,r,e)});var tl=()=>AS((e,t)=>t),AS=(e)=>Dn({empty:te,combine:(t,r)=>{if(t===te)return r;if(r===te)return t;return(n)=>r(t(n))},diff:(t,r)=>{if(_(t,r))return te;return fs(r)},patch:(t,r)=>e(r,t(r))});var Zs=255,TS=8,rl=(e)=>e&Zs,nl=(e)=>e>>TS&Zs,ko=(e,t)=>(e&Zs)+((t&e&Zs)<<TS),tf=ko(0,0),IS=(e)=>ko(e,e),kS=(e)=>ko(e,0);var RS=p(2,(e,t)=>ko(rl(e)&~t,nl(e)));var rf=p(2,(e,t)=>e|t);var CS=(e)=>~e>>>0&Zs;var NR=0,tn=1,FS=2,nf=4,ol=16,of=32;var NS=(e)=>il(e,of);var sf=p(2,(e,t)=>e|t);var rn=(e)=>af(e)&&!MR(e),af=(e)=>il(e,tn);var il=p(2,(e,t)=>(e&t)!==0),cf=(...e)=>e.reduce((t,r)=>t|r,0),MS=cf(NR);var lf=(e)=>il(e,nf);var MR=(e)=>il(e,ol);var Qs=p(2,(e,t)=>ko(e^t,t)),Xs=p(2,(e,t)=>e&(CS(rl(t))|nl(t))|rl(t)&nl(t));var uf=Dn({empty:tf,diff:(e,t)=>Qs(e,t),combine:(e,t)=>rf(t)(e),patch:(e,t)=>Xs(t,e)});var LS=IS,df=kS;var ff=RS;var hf=(e,t)=>({_tag:"Par",left:e,right:t}),sl=(e,t)=>({_tag:"Seq",left:e,right:t});var qS=(e)=>{let t=Vs(e),r=Ln();while(!0){let[n,o]=hS(t,[US(),Ln()],([i,s],a)=>{let[c,l]=LR(a);return[jR(i,c),mS(s,l)]});if(r=DR(r,n),vr(o))return gS(r);t=o}throw Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues")},LR=(e)=>{let t=e,r=US(),n=Ln(),o=Ln();while(!0)switch(t._tag){case"Empty":{if(vr(n))return[r,o];t=n.head,n=n.tail;break}case"Par":{n=en(t.right,n),t=t.left;break}case"Seq":{let i=t.left,s=t.right;switch(i._tag){case"Empty":{t=s;break}case"Par":{let{left:a,right:c}=i;t=hf(sl(a,s),sl(c,s));break}case"Seq":{let{left:a,right:c}=i;t=sl(a,sl(c,s));break}case"Single":{t=i,o=en(s,o);break}}break}case"Single":{if(r=HR(r,t),vr(n))return[r,o];t=n.head,n=n.tail;break}}throw Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues")},DR=(e,t)=>{if(vr(e))return Vs(mf(t));if($R(t))return e;let r=GR(e.head),n=BR(t);if(r.length===1&&n.length===1&&_(r[0],n[0]))return en(zR(e.head,mf(t)),e.tail);return en(mf(t),e)};var qR=Symbol.for("effect/RequestBlock/RequestBlockParallel"),UR={_R:(e)=>e};class al{map;[qR]=UR;constructor(e){this.map=e}}var US=()=>new al(Oi());var HR=(e,t)=>new al(uS(e.map,t.dataSource,(r)=>Ay(nr(r,Wy(t.blockedRequest)),()=>Fe(t.blockedRequest)))),jR=(e,t)=>new al($d(e.map,t.map,(r,n,o)=>Hd(r,o,Ae(Ud(r,o),{onNone:()=>n,onSome:(i)=>Mt(n,i)})))),$R=(e)=>lS(e.map),BR=(e)=>Array.from(jd(e.map)),mf=(e)=>VR(pS(e.map,(t)=>Fe(t))),KR=Symbol.for("effect/RequestBlock/RequestBlockSequential"),WR={_R:(e)=>e};class gf{map;[KR]=WR;constructor(e){this.map=e}}var VR=(e)=>new gf(e),zR=(e,t)=>new gf($d(t.map,e.map,(r,n,o)=>Hd(r,o,Ae(Ud(r,o),{onNone:()=>Kt(),onSome:(i)=>Mt(i,n)}))));var GR=(e)=>Array.from(jd(e.map)),HS=(e)=>Array.from(e.map);var Ai="Pending",cl="Done";var YR="effect/Deferred",$S=Symbol.for(YR),BS={_E:(e)=>e,_A:(e)=>e},KS=(e)=>({_tag:Ai,joiners:e}),WS=(e)=>({_tag:cl,effect:e});class Ti{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 Ti(this.self)}}var pl=(e,t)=>{let r=new je("Blocked");return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r},Sf=(e)=>{let t=new je("RunBlocked");return t.effect_instruction_i0=e,t},qn=Symbol.for("effect/Effect");class bf{patch;op;_op=As;constructor(e,t){this.patch=e,this.op=t}}class je{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[qn]=wn;constructor(e){this._op=e}[A](e){return this===e}[I](){return Z(this,_s(this))}pipe(){return x(this,arguments)}toJSON(){return{_id:"Effect",_op:this._op,effect_instruction_i0:re(this.effect_instruction_i0),effect_instruction_i1:re(this.effect_instruction_i1),effect_instruction_i2:re(this.effect_instruction_i2)}}toString(){return ie(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ti(new Hr(this))}}class _f{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[qn]=wn;constructor(e){this._op=e,this._tag=e}[A](e){return Fi(e)&&e._op==="Failure"&&_(this.effect_instruction_i0,e.effect_instruction_i0)}[I](){return m(oe(this._tag),K(b(this.effect_instruction_i0)),Z(this))}get cause(){return this.effect_instruction_i0}pipe(){return x(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,cause:this.cause.toJSON()}}toString(){return ie(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ti(new Hr(this))}}class wf{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[qn]=wn;constructor(e){this._op=e,this._tag=e}[A](e){return Fi(e)&&e._op==="Success"&&_(this.effect_instruction_i0,e.effect_instruction_i0)}[I](){return m(oe(this._tag),K(b(this.effect_instruction_i0)),Z(this))}get value(){return this.effect_instruction_i0}pipe(){return x(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,value:re(this.value)}}toString(){return ie(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ti(new Hr(this))}}var Ii=(e)=>w(e,qn),ze=(e)=>{let t=new je(gc);return t.effect_instruction_i0=e,t},eb=p(3,(e,t,r)=>jn((n)=>H(e,(o)=>H(Hn(fe(()=>n(t(o)))),(i)=>fe(()=>r(o,i)).pipe(zt({onFailure:(s)=>{switch(i._tag){case wt:return rt(tt(i.effect_instruction_i0,s));case Et:return rt(s)}},onSuccess:()=>i})))))),nn=p(2,(e,t)=>H(e,()=>ne(t))),on=(e)=>nn(e,void 0),Ef=function(){let e=new je(mo);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(lo("you're not supposed to end up here"))}return e},ea=(e,t=Vt)=>{let r=new je(fo),n=void 0;return r.effect_instruction_i0=(o)=>{n=e(o)},r.effect_instruction_i1=t,oa(r,(o)=>Ii(n)?n:Ne)},tb=(e,t=Vt)=>fe(()=>ea(e,t)),Un=(e,t=Vt)=>Ef(e,function(){let r=void 0,n=void 0;function o(c){if(r)r(c);else if(n===void 0)n=c}let i=new je(fo);i.effect_instruction_i0=(c)=>{if(r=c,n)c(n)},i.effect_instruction_i1=t;let s=void 0,a=void 0;if(this.effect_instruction_i0.length!==1)a=new AbortController,s=Ve(()=>this.effect_instruction_i0(o,a.signal));else s=Ve(()=>this.effect_instruction_i0(o));return s||a?oa(i,(c)=>{if(a)a.abort();return s??Ne}):i});var ta=p(2,(e,t)=>ki(e,{onFailure:t,onSuccess:ne}));var VS=Symbol.for("effect/OriginalAnnotation");var dl=(e,t)=>{if(pe(t))return new Proxy(e,{has(r,n){return n===To||n===VS||n in r},get(r,n){if(n===To)return t.value;if(n===VS)return e;return r[n]}});return e},fl=(e)=>gt(e)&&!(To in e)?ze((t)=>rt(Lt(dl(e,kl(t))))):rt(Lt(e)),Of=(e)=>rb(()=>Lt(new iC(e)));var Ro=(e)=>ki(e,{onFailure:(t)=>ne(B(t)),onSuccess:(t)=>ne(z(t))}),Hn=(e)=>nb(e,{onFailure:le,onSuccess:xe}),$e=(e)=>gt(e)&&!(To in e)?ze((t)=>rt(bi(dl(e,kl(t))))):rt(bi(e)),vf=(e)=>H(M(e),$e),rt=(e)=>{let t=new _f(wt);return t.effect_instruction_i0=e,t},rb=(e)=>H(M(e),rt),Af=ze((e)=>ne(e.id())),ra=(e)=>ze((t)=>e(t.id())),H=p(2,(e,t)=>{let r=new je(oi);return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r});var Tf=(e)=>{let t=new je("OnStep");return t.effect_instruction_i0=e,t},na=(e)=>H(e,te);var nb=p(2,(e,t)=>zt(e,{onFailure:(r)=>ne(t.onFailure(r)),onSuccess:(r)=>ne(t.onSuccess(r))})),zt=p(2,(e,t)=>{let r=new je(ii);return r.effect_instruction_i0=e,r.effect_instruction_i1=t.onFailure,r.effect_instruction_i2=t.onSuccess,r}),ki=p(2,(e,t)=>zt(e,{onFailure:(r)=>{if(_d(r).length>0)return rt(Ix(r));let o=bd(r);if(o.length>0)return t.onFailure(od(o));return rt(r)},onSuccess:t.onSuccess})),Gt=p(2,(e,t)=>fe(()=>{let r=de(e),n=go(r.length),o=0;return nn(ia({while:()=>o<r.length,body:()=>t(r[o],o),step:(i)=>{n[o++]=i}}),n)})),Co=p(2,(e,t)=>fe(()=>{let r=de(e),n=0;return ia({while:()=>n<r.length,body:()=>t(r[n],n),step:()=>{n++}})}));var ml=(e)=>{let t=new je(ho);return t.effect_instruction_i0=LS(tn),t.effect_instruction_i1=()=>e,t};var Oe=p(2,(e,t)=>H(e,(r)=>M(()=>t(r)))),hl=p(2,(e,t)=>ki(e,{onFailure:(r)=>vf(()=>t.onFailure(r)),onSuccess:(r)=>M(()=>t.onSuccess(r))})),Po=p(2,(e,t)=>zt(e,{onFailure:(r)=>{let n=Hc(r);switch(n._tag){case"Left":return vf(()=>t(n.left));case"Right":return rt(n.right)}},onSuccess:ne}));var Ri=p(2,(e,t)=>jn((r)=>zt(r(e),{onFailure:(n)=>{let o=le(n);return zt(t(o),{onFailure:(i)=>le(tt(n,i)),onSuccess:()=>o})},onSuccess:(n)=>{let o=xe(n);return $n(t(o),o)}}))),oa=p(2,(e,t)=>Ri(e,Al({onFailure:(r)=>_i(r)?on(t(wd(r))):Ne,onSuccess:()=>Ne})));var ne=(e)=>{let t=new wf(Et);return t.effect_instruction_i0=e,t},fe=(e)=>{let t=new je(mo);return t.commit=e,t},M=(e)=>{let t=new je(hc);return t.effect_instruction_i0=e,t},gl=p((e)=>e.length===3||e.length===2&&!(gt(e[1])&&("onlyEffect"in e[1])),(e,t)=>H(e,(r)=>{let n=typeof t==="function"?t(r):t;if(Ii(n))return nn(n,r);else if(ty(n))return ea((o)=>{n.then((i)=>o(ne(r)),(i)=>o($e(new aC(i,"An unknown error occurred in Effect.tap"))))});return ne(r)})),If=(e)=>ze((t)=>{let r=t.getFiberRef(ul),n=m(r,ue(()=>t.scope()));return e(Bn(ul,P(n)))});var yl=(e)=>{let t=new je(ho);return t.effect_instruction_i0=df(tn),t.effect_instruction_i1=()=>e,t},jn=(e)=>Ef(e,function(){let t=new je(ho);return t.effect_instruction_i0=df(tn),t.effect_instruction_i1=(r)=>af(r)?Ve(()=>this.effect_instruction_i0(ml)):Ve(()=>this.effect_instruction_i0(yl)),t}),Ne=ne(void 0);var kf=(e)=>{let t=new je(ho);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t};var ia=(e)=>{let t=new je(si);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t};var sa=(e)=>{let t=new je(ci);return typeof e?.priority<"u"?mb(t,e.priority):t},xl=p(2,(e,t)=>H(e,(r)=>Oe(t,(n)=>[r,n])));var Sl=p(2,(e,t)=>H(e,(r)=>nn(t,r))),$n=p(2,(e,t)=>H(e,()=>t));var aa=tb(()=>{let e=setInterval(()=>{},2147483647);return M(()=>clearInterval(e))}),ob=(e)=>H(Af,(t)=>m(e,ca(t))),ca=p(2,(e,t)=>H(e.interruptAsFork(t),()=>e.await)),ib={_tag:"All",syslog:0,label:"ALL",ordinal:Number.MIN_SAFE_INTEGER,pipe(){return x(this,arguments)}},sb={_tag:"Fatal",syslog:2,label:"FATAL",ordinal:50000,pipe(){return x(this,arguments)}},ab={_tag:"Error",syslog:3,label:"ERROR",ordinal:40000,pipe(){return x(this,arguments)}},Rf={_tag:"Warning",syslog:4,label:"WARN",ordinal:30000,pipe(){return x(this,arguments)}},Cf={_tag:"Info",syslog:6,label:"INFO",ordinal:20000,pipe(){return x(this,arguments)}},Pf={_tag:"Debug",syslog:7,label:"DEBUG",ordinal:1e4,pipe(){return x(this,arguments)}},cb={_tag:"Trace",syslog:7,label:"TRACE",ordinal:0,pipe(){return x(this,arguments)}},lb={_tag:"None",syslog:7,label:"OFF",ordinal:Number.MAX_SAFE_INTEGER,pipe(){return x(this,arguments)}};var eC="effect/FiberRef",tC=Symbol.for(eC),rC={_A:(e)=>e},bl=(e)=>ze((t)=>xe(t.getFiberRef(e)));var Fo=p(2,(e,t)=>H(bl(e),t)),yf=p(2,(e,t)=>nC(e,()=>[void 0,t]));var nC=p(2,(e,t)=>ze((r)=>{let[n,o]=t(r.getFiberRef(e));return r.setFiberRef(e,o),ne(n)}));var Bn=p(3,(e,t,r)=>eb(Sl(bl(t),yf(t,r)),()=>e,(n)=>yf(t,n)));var Ge=(e,t)=>No(e,{differ:tl(),fork:t?.fork??te,join:t?.join}),ub=(e)=>{let t=Qd();return No(e,{differ:t,fork:t.empty})},oC=(e)=>{let t=Xd(tl());return No(e,{differ:t,fork:t.empty})},_l=(e)=>{let t=Zd();return No(e,{differ:t,fork:t.empty})},No=(e,t)=>({...En,[tC]:rC,initial:e,commit(){return bl(this)},diff:(n,o)=>t.differ.diff(n,o),combine:(n,o)=>t.differ.combine(n,o),patch:(n)=>(o)=>t.differ.patch(n,o),fork:t.fork,join:t.join??((n,o)=>o)}),pb=(e)=>No(e,{differ:uf,fork:uf.empty}),Mo=U(Symbol.for("effect/FiberRef/currentContext"),()=>_l(Nn())),Ci=U(Symbol.for("effect/FiberRef/currentSchedulingPriority"),()=>Ge(0)),Ff=U(Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"),()=>Ge(2048)),db=U(Symbol.for("effect/FiberRef/currentLogAnnotation"),()=>Ge(Oi())),Nf=U(Symbol.for("effect/FiberRef/currentLogLevel"),()=>Ge(Cf)),fb=U(Symbol.for("effect/FiberRef/currentLogSpan"),()=>Ge(Ln())),mb=p(2,(e,t)=>Bn(e,Ci,t));var hb=U(Symbol.for("effect/FiberRef/currentConcurrency"),()=>Ge("unbounded")),gb=U(Symbol.for("effect/FiberRef/currentRequestBatching"),()=>Ge(!0)),yb=U(Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"),()=>Ge(P(Pf))),xb=U(Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"),()=>Ge(P(Rf)));var la=U(Symbol.for("effect/FiberRef/currentMetricLabels"),()=>oC(Vr()));var ul=U(Symbol.for("effect/FiberRef/currentForkScopeOverride"),()=>Ge(E(),{fork:()=>E(),join:(e,t)=>e})),ua=U(Symbol.for("effect/FiberRef/currentInterruptedCause"),()=>Ge(Qr,{fork:()=>Qr,join:(e,t)=>e}));var wl=Symbol.for("effect/Scope"),El=Symbol.for("effect/CloseableScope"),Ol=(e,t)=>e.addFinalizer(()=>on(t));var Mf=(e,t)=>e.close(t),Pi=(e,t)=>e.fork(t);var vl=function(){class e extends globalThis.Error{commit(){return $e(this)}toJSON(){let t={...this};if(this.message)t.message=this.message;if(this.cause)t.cause=this.cause;return t}[Y](){if(this.toString!==globalThis.Error.prototype.toString)return this.stack?`${this.toString()}
|
|
25
|
+
`)}return t},qx=(e)=>v(e,Rd);var Ux=(e)=>v(e,Hs),TR=Fn(new Map),Hx=()=>TR,kd=(e,t)=>Fn(new Map([[e.key,t]])),jx=p(3,(e,t,r)=>{let n=new Map(e.unsafeMap);return n.set(t.key,r),Fn(n)}),Id=B("effect/Context/defaultValueCache",()=>new Map),Cd=(e)=>{if(Id.has(e.key))return Id.get(e.key);let t=e.defaultValue();return Id.set(e.key,t),t},$x=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):Cd(t),Pd=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(Hs in t)return Cd(t);throw AR(t)}return e.unsafeMap.get(t.key)}),Bx=Pd;var Wx=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key))return Ux(t)?ks(Cd(t)):bc;return ks(e.unsafeMap.get(t.key))}),Kx=p(2,(e,t)=>{let r=new Map(e.unsafeMap);for(let[n,o]of t.unsafeMap)r.set(n,o);return Fn(r)});var vt=Lx;var Mn=Hx,zx=kd,vr=jx,js=Bx;var $s=Pd,Ln=Wx,Bs=Kx;var Ws=Dx;var Fd=Symbol.for("effect/Duration"),Qx=BigInt(0),Gx=BigInt(24),Vc=BigInt(60),Md=BigInt(1000),Jx=BigInt(1e6),Yx=BigInt(1e9),IR=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,Xr=(e)=>{if(Xx(e))return e;else if(Pt(e))return zc(e);else if(_n(e))return Nd(e);else if(Array.isArray(e)&&e.length===2&&e.every(Pt)){if(e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1]))return Ld;if(e[0]===1/0||e[1]===1/0)return PR;return Nd(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])))}else if(Ke(e)){let t=IR.exec(e);if(t){let[r,n,o]=t,i=Number(n);switch(o){case"nano":case"nanos":return Nd(BigInt(n));case"micro":case"micros":return NR(BigInt(n));case"milli":case"millis":return zc(i);case"second":case"seconds":return FR(i);case"minute":case"minutes":return MR(i);case"hour":case"hours":return LR(i);case"day":case"days":return DR(i);case"week":case"weeks":return qR(i)}}}throw Error("Invalid DurationInput")};var Zx={_tag:"Millis",millis:0},RR={_tag:"Infinity"},kR={[Fd]:Fd,[P](){return Z(this,hc(this.value))},[R](e){return Xx(e)&&BR(this,e)},toString(){return`Duration(${KR(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:HR(this)};case"Infinity":return{_id:"Duration",_tag:"Infinity"}}},[Y](){return this.toJSON()},pipe(){return b(this,arguments)}},Ar=(e)=>{let t=Object.create(kR);if(Pt(e))if(isNaN(e)||e<=0)t.value=Zx;else if(!Number.isFinite(e))t.value=RR;else if(!Number.isInteger(e))t.value={_tag:"Nanos",nanos:BigInt(Math.round(e*1e6))};else t.value={_tag:"Millis",millis:e};else if(e<=Qx)t.value=Zx;else t.value={_tag:"Nanos",nanos:e};return t},Xx=(e)=>v(e,Fd);var CR=(e)=>{switch(e.value._tag){case"Millis":return e.value.millis===0;case"Nanos":return e.value.nanos===Qx;case"Infinity":return!1}},Ld=Ar(0),PR=Ar(1/0),Nd=(e)=>Ar(e),NR=(e)=>Ar(e*Md),zc=(e)=>Ar(e),FR=(e)=>Ar(e*1000),MR=(e)=>Ar(e*60000),LR=(e)=>Ar(e*3600000),DR=(e)=>Ar(e*86400000),qR=(e)=>Ar(e*604800000),Gc=(e)=>jR(e,{onMillis:(t)=>t,onNanos:(t)=>Number(t)/1e6});var UR=(e)=>{let t=Xr(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))}},HR=(e)=>{let t=Xr(e);switch(t.value._tag){case"Infinity":return[1/0,0];case"Nanos":return[Number(t.value.nanos/Yx),Number(t.value.nanos%Yx)];case"Millis":return[Math.floor(t.value.millis/1000),Math.round(t.value.millis%1000*1e6)]}},jR=p(2,(e,t)=>{let r=Xr(e);switch(r.value._tag){case"Nanos":return t.onNanos(r.value.nanos);case"Infinity":return t.onMillis(1/0);case"Millis":return t.onMillis(r.value.millis)}}),Dd=p(3,(e,t,r)=>{let n=Xr(e),o=Xr(t);if(n.value._tag==="Infinity"||o.value._tag==="Infinity")return r.onMillis(Gc(n),Gc(o));else if(n.value._tag==="Nanos"||o.value._tag==="Nanos"){let i=n.value._tag==="Nanos"?n.value.nanos:BigInt(Math.round(n.value.millis*1e6)),s=o.value._tag==="Nanos"?o.value.nanos:BigInt(Math.round(o.value.millis*1e6));return r.onNanos(i,s)}return r.onMillis(n.value.millis,o.value.millis)});var $R=(e,t)=>Dd(e,t,{onMillis:(r,n)=>r===n,onNanos:(r,n)=>r===n});var eS=p(2,(e,t)=>Dd(e,t,{onMillis:(r,n)=>r<=n,onNanos:(r,n)=>r<=n}));var tS=p(2,(e,t)=>Dd(e,t,{onMillis:(r,n)=>r>=n,onNanos:(r,n)=>r>=n})),BR=p(2,(e,t)=>$R(Xr(e),Xr(t))),WR=(e)=>{let t=Xr(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 r=UR(t),n=r/Jx,o=n/Md,i=o/Vc,s=i/Vc,a=s/Gx;return{days:Number(a),hours:Number(s%Gx),minutes:Number(i%Vc),seconds:Number(o%Vc),millis:Number(n%Md),nanos:Number(r%Jx)}},KR=(e)=>{let t=Xr(e);if(t.value._tag==="Infinity")return"Infinity";if(CR(t))return"0";let r=WR(t),n=[];if(r.days!==0)n.push(`${r.days}d`);if(r.hours!==0)n.push(`${r.hours}h`);if(r.minutes!==0)n.push(`${r.minutes}m`);if(r.seconds!==0)n.push(`${r.seconds}s`);if(r.millis!==0)n.push(`${r.millis}ms`);if(r.nanos!==0)n.push(`${r.nanos}ns`);return n.join(" ")};var nS=Symbol.for("effect/MutableRef"),VR={[nS]:nS,toString(){return se(this.toJSON())},toJSON(){return{_id:"MutableRef",current:re(this.current)}},[Y](){return this.toJSON()},pipe(){return b(this,arguments)}},Jc=(e)=>{let t=Object.create(VR);return t.current=e,t};var Oi=(e)=>e.current;var Yc=p(2,(e,t)=>(e.current=t,e));var Ud="effect/FiberId",vi=Symbol.for(Ud),Zc="None",qd="Runtime",zR="Composite",GR=ie(`${Ud}-${Zc}`);class sS{[vi]=vi;_tag=Zc;id=-1;startTimeMillis=-1;[P](){return GR}[R](e){return Hd(e)&&e._tag===Zc}toString(){return se(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag}}[Y](){return this.toJSON()}}class aS{id;startTimeMillis;[vi]=vi;_tag=qd;constructor(e,t){this.id=e,this.startTimeMillis=t}[P](){return Z(this,ie(`${Ud}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[R](e){return Hd(e)&&e._tag===qd&&this.id===e.id&&this.startTimeMillis===e.startTimeMillis}toString(){return se(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag,id:this.id,startTimeMillis:this.startTimeMillis}}[Y](){return this.toJSON()}}var cS=new sS;var Hd=(e)=>v(e,vi);var Qc=(e)=>{switch(e._tag){case Zc:return Or();case qd:return wo(e.id);case zR:return h(Qc(e.left),Zr(Qc(e.right)))}},iS=B(Symbol.for("effect/Fiber/Id/_fiberCounter"),()=>Jc(0));var Xc=(e)=>Array.from(Qc(e)).map((r)=>`#${r}`).join(",");var lS=()=>{let e=Oi(iS);return h(iS,Yc(e+1)),new aS(e,Date.now())};var Kt=cS;var pS=Xc;var el=lS;var Ai=gi;var dS=sx,fS=cx,jd=lx;var $d=_o,Bd=Nc;var mS=Mc;var hS=dx;var Wd=yi;var Vs=Symbol.for("effect/List"),Vd=(e)=>fe(e),JR=(e)=>Ap(Tn(e),Vd),YR=JR(E),ZR={[Vs]:Vs,_tag:"Cons",toString(){return se(this.toJSON())},toJSON(){return{_id:"List",_tag:"Cons",values:Vd(this).map(re)}},[Y](){return this.toJSON()},[R](e){return yS(e)&&this._tag===e._tag&&YR(this,e)},[P](){return Z(this,Nt(Vd(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 r=t.head;return t=t.tail,{done:e,value:r}},return(r){if(!e)e=!0;return{done:!0,value:r}}}},pipe(){return b(this,arguments)}},tl=(e,t)=>{let r=Object.create(ZR);return r.head=e,r.tail=t,r},QR=ie("Nil"),XR={[Vs]:Vs,_tag:"Nil",toString(){return se(this.toJSON())},toJSON(){return{_id:"List",_tag:"Nil"}},[Y](){return this.toJSON()},[P](){return QR},[R](e){return yS(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return b(this,arguments)}},gS=Object.create(XR),yS=(e)=>v(e,Vs),Tr=(e)=>e._tag==="Nil",zd=(e)=>e._tag==="Cons";var ek=()=>gS,en=(e,t)=>tl(e,t),Dn=ek,zs=(e)=>tl(e,gS);var xS=p(2,(e,t)=>rk(t,e)),tk=p(2,(e,t)=>en(t,e)),rk=p(2,(e,t)=>{if(Tr(e))return t;else if(Tr(t))return e;else{let r=tl(t.head,e),n=r,o=t.tail;while(!Tr(o)){let i=tl(o.head,e);n.tail=i,n=i,o=o.tail}return r}});var SS=p(3,(e,t,r)=>{let n=t,o=e;while(!Tr(o))n=r(n,o.head),o=o.tail;return n});var bS=(e)=>{let t=Dn(),r=e;while(!Tr(r))t=tk(t,r.head),r=r.tail;return t};var n2=Object.assign(Object.create(Array.prototype),{[P](){return Z(this,Nt(this))},[R](e){if(Array.isArray(e)&&this.length===e.length)return this.every((t,r)=>E(t,e[r]));else return!1}}),Ti=function(){function e(t){if(t)Object.assign(this,t)}return e.prototype=Rs,e}();var ok=Symbol.for("effect/DifferContextPatch");function _S(e){return e}var Js={...Ti.prototype,[ok]:{_Value:_S,_Patch:_S}},ik=Object.assign(Object.create(Js),{_tag:"Empty"}),sk=Object.create(ik),Jd=()=>sk,ak=Object.assign(Object.create(Js),{_tag:"AndThen"}),ck=(e,t)=>{let r=Object.create(ak);return r.first=e,r.second=t,r},lk=Object.assign(Object.create(Js),{_tag:"AddService"}),uk=(e,t)=>{let r=Object.create(lk);return r.key=e,r.service=t,r},pk=Object.assign(Object.create(Js),{_tag:"RemoveService"}),dk=(e)=>{let t=Object.create(pk);return t.key=e,t},fk=Object.assign(Object.create(Js),{_tag:"UpdateService"}),mk=(e,t)=>{let r=Object.create(fk);return r.key=e,r.update=t,r},wS=(e,t)=>{let r=new Map(e.unsafeMap),n=Jd();for(let[o,i]of t.unsafeMap.entries())if(r.has(o)){let s=r.get(o);if(r.delete(o),!E(s,i))n=Gs(mk(o,()=>i))(n)}else r.delete(o),n=Gs(uk(o,i))(n);for(let[o]of r.entries())n=Gs(dk(o))(n);return n},Gs=p(2,(e,t)=>ck(e,t)),ES=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=!1,n=Ne(e),o=new Map(t.unsafeMap);while(ar(n)){let s=cr(n),a=lr(n);switch(s._tag){case"Empty":{n=a;break}case"AddService":{o.set(s.key,s.service),n=a;break}case"AndThen":{n=tt(tt(a,s.second),s.first);break}case"RemoveService":{o.delete(s.key),n=a;break}case"UpdateService":{o.set(s.key,s.update(o.get(s.key))),r=!0,n=a;break}}}if(!r)return Fn(o);let i=new Map;for(let[s]of t.unsafeMap)if(o.has(s))i.set(s,o.get(s)),o.delete(s);for(let[s,a]of o)i.set(s,a);return Fn(i)});var gk=Symbol.for("effect/DifferHashSetPatch");function Yd(e){return e}var nl={...Ti.prototype,[gk]:{_Value:Yd,_Key:Yd,_Patch:Yd}},yk=Object.assign(Object.create(nl),{_tag:"Empty"}),xk=Object.create(yk),Zd=()=>xk,Sk=Object.assign(Object.create(nl),{_tag:"AndThen"}),bk=(e,t)=>{let r=Object.create(Sk);return r.first=e,r.second=t,r},_k=Object.assign(Object.create(nl),{_tag:"Add"}),wk=(e)=>{let t=Object.create(_k);return t.value=e,t},Ek=Object.assign(Object.create(nl),{_tag:"Remove"}),Ok=(e)=>{let t=Object.create(Ek);return t.value=e,t},OS=(e,t)=>{let[r,n]=Oo([e,Zd()],([o,i],s)=>{if(vx(s)(o))return[gd(s)(o),i];return[o,rl(wk(s))(i)]})(t);return Oo(n,(o,i)=>rl(Ok(i))(o))(r)},rl=p(2,(e,t)=>bk(e,t)),vS=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=t,n=Ne(e);while(ar(n)){let o=cr(n),i=lr(n);switch(o._tag){case"Empty":{n=i;break}case"AndThen":{n=tt(o.first)(tt(o.second)(i));break}case"Add":{r=Eo(o.value)(r),n=i;break}case"Remove":r=gd(o.value)(r),n=i}}return r});var Ak=Symbol.for("effect/DifferReadonlyArrayPatch");function AS(e){return e}var Zs={...Ti.prototype,[Ak]:{_Value:AS,_Patch:AS}},Tk=Object.assign(Object.create(Zs),{_tag:"Empty"}),Ik=Object.create(Tk),Qd=()=>Ik,Rk=Object.assign(Object.create(Zs),{_tag:"AndThen"}),kk=(e,t)=>{let r=Object.create(Rk);return r.first=e,r.second=t,r},Ck=Object.assign(Object.create(Zs),{_tag:"Append"}),Pk=(e)=>{let t=Object.create(Ck);return t.values=e,t},Nk=Object.assign(Object.create(Zs),{_tag:"Slice"}),Fk=(e,t)=>{let r=Object.create(Nk);return r.from=e,r.until=t,r},Mk=Object.assign(Object.create(Zs),{_tag:"Update"}),Lk=(e,t)=>{let r=Object.create(Mk);return r.index=e,r.patch=t,r},TS=(e)=>{let t=0,r=Qd();while(t<e.oldValue.length&&t<e.newValue.length){let n=e.oldValue[t],o=e.newValue[t],i=e.differ.diff(n,o);if(!E(i,e.differ.empty))r=Ys(r,Lk(t,i));t=t+1}if(t<e.oldValue.length)r=Ys(r,Fk(0,t));if(t<e.newValue.length)r=Ys(r,Pk($y(t)(e.newValue)));return r},Ys=p(2,(e,t)=>kk(e,t)),IS=p(3,(e,t,r)=>{if(e._tag==="Empty")return t;let n=t.slice(),o=et(e);while(vn(o)){let i=Pe(o),s=ir(o);switch(i._tag){case"Empty":{o=s;break}case"AndThen":{s.unshift(i.first,i.second),o=s;break}case"Append":{for(let a of i.values)n.push(a);o=s;break}case"Slice":{n=n.slice(i.from,i.until),o=s;break}case"Update":{n[i.index]=r.patch(i.patch,n[i.index]),o=s;break}}}return n});var RS=Symbol.for("effect/Differ"),qk={[RS]:{_P:te,_V:te},pipe(){return b(this,arguments)}},qn=(e)=>{let t=Object.create(qk);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},Xd=()=>qn({empty:Jd(),combine:(e,t)=>Gs(t)(e),diff:(e,t)=>wS(e,t),patch:(e,t)=>ES(t)(e)});var ef=()=>qn({empty:Zd(),combine:(e,t)=>rl(t)(e),diff:(e,t)=>OS(e,t),patch:(e,t)=>vS(t)(e)});var tf=(e)=>qn({empty:Qd(),combine:(t,r)=>Ys(t,r),diff:(t,r)=>TS({oldValue:t,newValue:r,differ:e}),patch:(t,r)=>IS(t,r,e)});var ol=()=>kS((e,t)=>t),kS=(e)=>qn({empty:te,combine:(t,r)=>{if(t===te)return r;if(r===te)return t;return(n)=>r(t(n))},diff:(t,r)=>{if(E(t,r))return te;return ms(r)},patch:(t,r)=>e(r,t(r))});var Qs=255,CS=8,il=(e)=>e&Qs,sl=(e)=>e>>CS&Qs,Co=(e,t)=>(e&Qs)+((t&e&Qs)<<CS),nf=Co(0,0),PS=(e)=>Co(e,e),NS=(e)=>Co(e,0);var FS=p(2,(e,t)=>Co(il(e)&~t,sl(e)));var of=p(2,(e,t)=>e|t);var MS=(e)=>~e>>>0&Qs;var Uk=0,tn=1,DS=2,sf=4,al=16,af=32;var qS=(e)=>cl(e,af);var cf=p(2,(e,t)=>e|t);var rn=(e)=>lf(e)&&!Hk(e),lf=(e)=>cl(e,tn);var cl=p(2,(e,t)=>(e&t)!==0),uf=(...e)=>e.reduce((t,r)=>t|r,0),US=uf(Uk);var pf=(e)=>cl(e,sf);var Hk=(e)=>cl(e,al);var Xs=p(2,(e,t)=>Co(e^t,t)),ea=p(2,(e,t)=>e&(MS(il(t))|sl(t))|il(t)&sl(t));var df=qn({empty:nf,diff:(e,t)=>Xs(e,t),combine:(e,t)=>of(t)(e),patch:(e,t)=>ea(t,e)});var HS=PS,mf=NS;var hf=FS;var yf=(e,t)=>({_tag:"Par",left:e,right:t}),ll=(e,t)=>({_tag:"Seq",left:e,right:t});var $S=(e)=>{let t=zs(e),r=Dn();while(!0){let[n,o]=SS(t,[BS(),Dn()],([i,s],a)=>{let[c,l]=jk(a);return[Vk(i,c),xS(s,l)]});if(r=$k(r,n),Tr(o))return bS(r);t=o}throw Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues")},jk=(e)=>{let t=e,r=BS(),n=Dn(),o=Dn();while(!0)switch(t._tag){case"Empty":{if(Tr(n))return[r,o];t=n.head,n=n.tail;break}case"Par":{n=en(t.right,n),t=t.left;break}case"Seq":{let i=t.left,s=t.right;switch(i._tag){case"Empty":{t=s;break}case"Par":{let{left:a,right:c}=i;t=yf(ll(a,s),ll(c,s));break}case"Seq":{let{left:a,right:c}=i;t=ll(a,ll(c,s));break}case"Single":{t=i,o=en(s,o);break}}break}case"Single":{if(r=Kk(r,t),Tr(n))return[r,o];t=n.head,n=n.tail;break}}throw Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues")},$k=(e,t)=>{if(Tr(e))return zs(gf(t));if(zk(t))return e;let r=Xk(e.head),n=Gk(t);if(r.length===1&&n.length===1&&E(r[0],n[0]))return en(Qk(e.head,gf(t)),e.tail);return en(gf(t),e)};var Bk=Symbol.for("effect/RequestBlock/RequestBlockParallel"),Wk={_R:(e)=>e};class ul{map;[Bk]=Wk;constructor(e){this.map=e}}var BS=()=>new ul(Ai());var Kk=(e,t)=>new ul(mS(e.map,t.dataSource,(r)=>ky(nr(r,Jy(t.blockedRequest)),()=>Ne(t.blockedRequest)))),Vk=(e,t)=>new ul(Wd(e.map,t.map,(r,n,o)=>$d(r,o,Ae(jd(r,o),{onNone:()=>n,onSome:(i)=>Ft(n,i)})))),zk=(e)=>fS(e.map),Gk=(e)=>Array.from(Bd(e.map)),gf=(e)=>Zk(hS(e.map,(t)=>Ne(t))),Jk=Symbol.for("effect/RequestBlock/RequestBlockSequential"),Yk={_R:(e)=>e};class xf{map;[Jk]=Yk;constructor(e){this.map=e}}var Zk=(e)=>new xf(e),Qk=(e,t)=>new xf(Wd(t.map,e.map,(r,n,o)=>$d(r,o,Ae(jd(r,o),{onNone:()=>Bt(),onSome:(i)=>Ft(i,n)}))));var Xk=(e)=>Array.from(Bd(e.map)),WS=(e)=>Array.from(e.map);var Ii="Pending",pl="Done";var tC="effect/Deferred",VS=Symbol.for(tC),zS={_E:(e)=>e,_A:(e)=>e},GS=(e)=>({_tag:Ii,joiners:e}),JS=(e)=>({_tag:pl,effect:e});class Ri{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 Ri(this.self)}}var ml=(e,t)=>{let r=new $e("Blocked");return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r},_f=(e)=>{let t=new $e("RunBlocked");return t.effect_instruction_i0=e,t},Un=Symbol.for("effect/Effect");class wf{patch;op;_op=Ts;constructor(e,t){this.patch=e,this.op=t}}class $e{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[Un]=En;constructor(e){this._op=e}[R](e){return this===e}[P](){return Z(this,ws(this))}pipe(){return b(this,arguments)}toJSON(){return{_id:"Effect",_op:this._op,effect_instruction_i0:re(this.effect_instruction_i0),effect_instruction_i1:re(this.effect_instruction_i1),effect_instruction_i2:re(this.effect_instruction_i2)}}toString(){return se(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ri(new Hr(this))}}class Ef{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[Un]=En;constructor(e){this._op=e,this._tag=e}[R](e){return Mi(e)&&e._op==="Failure"&&E(this.effect_instruction_i0,e.effect_instruction_i0)}[P](){return h(ie(this._tag),V(w(this.effect_instruction_i0)),Z(this))}get cause(){return this.effect_instruction_i0}pipe(){return b(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,cause:this.cause.toJSON()}}toString(){return se(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ri(new Hr(this))}}class Of{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[Un]=En;constructor(e){this._op=e,this._tag=e}[R](e){return Mi(e)&&e._op==="Success"&&E(this.effect_instruction_i0,e.effect_instruction_i0)}[P](){return h(ie(this._tag),V(w(this.effect_instruction_i0)),Z(this))}get value(){return this.effect_instruction_i0}pipe(){return b(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,value:re(this.value)}}toString(){return se(this.toJSON())}[Y](){return this.toJSON()}[Symbol.iterator](){return new Ri(new Hr(this))}}var ki=(e)=>v(e,Un),Ge=(e)=>{let t=new $e(Sc);return t.effect_instruction_i0=e,t},ob=p(3,(e,t,r)=>$n((n)=>W(e,(o)=>W(jn(me(()=>n(t(o)))),(i)=>me(()=>r(o,i)).pipe(Vt({onFailure:(s)=>{switch(i._tag){case wt:return nt(rt(i.effect_instruction_i0,s));case Et:return nt(s)}},onSuccess:()=>i})))))),nn=p(2,(e,t)=>W(e,()=>ne(t))),on=(e)=>nn(e,void 0),vf=function(){let e=new $e(go);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(po("you're not supposed to end up here"))}return e},ta=(e,t=Kt)=>{let r=new $e(ho),n=void 0;return r.effect_instruction_i0=(o)=>{n=e(o)},r.effect_instruction_i1=t,ia(r,(o)=>ki(n)?n:Fe)},ib=(e,t=Kt)=>me(()=>ta(e,t)),Hn=(e,t=Kt)=>vf(e,function(){let r=void 0,n=void 0;function o(c){if(r)r(c);else if(n===void 0)n=c}let i=new $e(ho);i.effect_instruction_i0=(c)=>{if(r=c,n)c(n)},i.effect_instruction_i1=t;let s=void 0,a=void 0;if(this.effect_instruction_i0.length!==1)a=new AbortController,s=Ve(()=>this.effect_instruction_i0(o,a.signal));else s=Ve(()=>this.effect_instruction_i0(o));return s||a?ia(i,(c)=>{if(a)a.abort();return s??Fe}):i});var ra=p(2,(e,t)=>Ci(e,{onFailure:t,onSuccess:ne}));var YS=Symbol.for("effect/OriginalAnnotation");var hl=(e,t)=>{if(de(t))return new Proxy(e,{has(r,n){return n===Ro||n===YS||n in r},get(r,n){if(n===Ro)return t.value;if(n===YS)return e;return r[n]}});return e},gl=(e)=>gt(e)&&!(Ro in e)?Ge((t)=>nt(Mt(hl(e,Pl(t))))):nt(Mt(e)),Af=(e)=>sb(()=>Mt(new uC(e)));var Po=(e)=>Ci(e,{onFailure:(t)=>ne(K(t)),onSuccess:(t)=>ne(G(t))}),jn=(e)=>ab(e,{onFailure:ue,onSuccess:xe}),Be=(e)=>gt(e)&&!(Ro in e)?Ge((t)=>nt(wi(hl(e,Pl(t))))):nt(wi(e)),Tf=(e)=>W(q(e),Be),nt=(e)=>{let t=new Ef(wt);return t.effect_instruction_i0=e,t},sb=(e)=>W(q(e),nt),If=Ge((e)=>ne(e.id())),na=(e)=>Ge((t)=>e(t.id())),W=p(2,(e,t)=>{let r=new $e(si);return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r});var Rf=(e)=>{let t=new $e("OnStep");return t.effect_instruction_i0=e,t},oa=(e)=>W(e,te);var ab=p(2,(e,t)=>Vt(e,{onFailure:(r)=>ne(t.onFailure(r)),onSuccess:(r)=>ne(t.onSuccess(r))})),Vt=p(2,(e,t)=>{let r=new $e(ai);return r.effect_instruction_i0=e,r.effect_instruction_i1=t.onFailure,r.effect_instruction_i2=t.onSuccess,r}),Ci=p(2,(e,t)=>Vt(e,{onFailure:(r)=>{if(Ed(r).length>0)return nt(Px(r));let o=wd(r);if(o.length>0)return t.onFailure(sd(o));return nt(r)},onSuccess:t.onSuccess})),zt=p(2,(e,t)=>me(()=>{let r=fe(e),n=xo(r.length),o=0;return nn(sa({while:()=>o<r.length,body:()=>t(r[o],o),step:(i)=>{n[o++]=i}}),n)})),No=p(2,(e,t)=>me(()=>{let r=fe(e),n=0;return sa({while:()=>n<r.length,body:()=>t(r[n],n),step:()=>{n++}})}));var yl=(e)=>{let t=new $e(yo);return t.effect_instruction_i0=HS(tn),t.effect_instruction_i1=()=>e,t};var ve=p(2,(e,t)=>W(e,(r)=>q(()=>t(r)))),xl=p(2,(e,t)=>Ci(e,{onFailure:(r)=>Tf(()=>t.onFailure(r)),onSuccess:(r)=>q(()=>t.onSuccess(r))})),Fo=p(2,(e,t)=>Vt(e,{onFailure:(r)=>{let n=Bc(r);switch(n._tag){case"Left":return Tf(()=>t(n.left));case"Right":return nt(n.right)}},onSuccess:ne}));var Pi=p(2,(e,t)=>$n((r)=>Vt(r(e),{onFailure:(n)=>{let o=ue(n);return Vt(t(o),{onFailure:(i)=>ue(rt(n,i)),onSuccess:()=>o})},onSuccess:(n)=>{let o=xe(n);return Bn(t(o),o)}}))),ia=p(2,(e,t)=>Pi(e,Rl({onFailure:(r)=>Ei(r)?on(t(Od(r))):Fe,onSuccess:()=>Fe})));var ne=(e)=>{let t=new Of(Et);return t.effect_instruction_i0=e,t},me=(e)=>{let t=new $e(go);return t.commit=e,t},q=(e)=>{let t=new $e(xc);return t.effect_instruction_i0=e,t},Sl=p((e)=>e.length===3||e.length===2&&!(gt(e[1])&&("onlyEffect"in e[1])),(e,t)=>W(e,(r)=>{let n=typeof t==="function"?t(r):t;if(ki(n))return nn(n,r);else if(iy(n))return ta((o)=>{n.then((i)=>o(ne(r)),(i)=>o(Be(new dC(i,"An unknown error occurred in Effect.tap"))))});return ne(r)})),kf=(e)=>Ge((t)=>{let r=t.getFiberRef(fl),n=h(r,pe(()=>t.scope()));return e(Wn(fl,F(n)))});var bl=(e)=>{let t=new $e(yo);return t.effect_instruction_i0=mf(tn),t.effect_instruction_i1=()=>e,t},$n=(e)=>vf(e,function(){let t=new $e(yo);return t.effect_instruction_i0=mf(tn),t.effect_instruction_i1=(r)=>lf(r)?Ve(()=>this.effect_instruction_i0(yl)):Ve(()=>this.effect_instruction_i0(bl)),t}),Fe=ne(void 0);var Cf=(e)=>{let t=new $e(yo);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t};var sa=(e)=>{let t=new $e(ci);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t};var aa=(e)=>{let t=new $e(ui);return typeof e?.priority<"u"?xb(t,e.priority):t},_l=p(2,(e,t)=>W(e,(r)=>ve(t,(n)=>[r,n])));var wl=p(2,(e,t)=>W(e,(r)=>nn(t,r))),Bn=p(2,(e,t)=>W(e,()=>t));var ca=ib(()=>{let e=setInterval(()=>{},2147483647);return q(()=>clearInterval(e))}),cb=(e)=>W(If,(t)=>h(e,la(t))),la=p(2,(e,t)=>W(e.interruptAsFork(t),()=>e.await)),lb={_tag:"All",syslog:0,label:"ALL",ordinal:Number.MIN_SAFE_INTEGER,pipe(){return b(this,arguments)}},ub={_tag:"Fatal",syslog:2,label:"FATAL",ordinal:50000,pipe(){return b(this,arguments)}},pb={_tag:"Error",syslog:3,label:"ERROR",ordinal:40000,pipe(){return b(this,arguments)}},Pf={_tag:"Warning",syslog:4,label:"WARN",ordinal:30000,pipe(){return b(this,arguments)}},Nf={_tag:"Info",syslog:6,label:"INFO",ordinal:20000,pipe(){return b(this,arguments)}},Ff={_tag:"Debug",syslog:7,label:"DEBUG",ordinal:1e4,pipe(){return b(this,arguments)}},db={_tag:"Trace",syslog:7,label:"TRACE",ordinal:0,pipe(){return b(this,arguments)}},fb={_tag:"None",syslog:7,label:"OFF",ordinal:Number.MAX_SAFE_INTEGER,pipe(){return b(this,arguments)}};var iC="effect/FiberRef",sC=Symbol.for(iC),aC={_A:(e)=>e},El=(e)=>Ge((t)=>xe(t.getFiberRef(e)));var Mo=p(2,(e,t)=>W(El(e),t)),Sf=p(2,(e,t)=>cC(e,()=>[void 0,t]));var cC=p(2,(e,t)=>Ge((r)=>{let[n,o]=t(r.getFiberRef(e));return r.setFiberRef(e,o),ne(n)}));var Wn=p(3,(e,t,r)=>ob(wl(El(t),Sf(t,r)),()=>e,(n)=>Sf(t,n)));var Je=(e,t)=>Lo(e,{differ:ol(),fork:t?.fork??te,join:t?.join}),mb=(e)=>{let t=ef();return Lo(e,{differ:t,fork:t.empty})},lC=(e)=>{let t=tf(ol());return Lo(e,{differ:t,fork:t.empty})},Ol=(e)=>{let t=Xd();return Lo(e,{differ:t,fork:t.empty})},Lo=(e,t)=>({...On,[sC]:aC,initial:e,commit(){return El(this)},diff:(n,o)=>t.differ.diff(n,o),combine:(n,o)=>t.differ.combine(n,o),patch:(n)=>(o)=>t.differ.patch(n,o),fork:t.fork,join:t.join??((n,o)=>o)}),hb=(e)=>Lo(e,{differ:df,fork:df.empty}),Do=B(Symbol.for("effect/FiberRef/currentContext"),()=>Ol(Mn())),Ni=B(Symbol.for("effect/FiberRef/currentSchedulingPriority"),()=>Je(0)),Mf=B(Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"),()=>Je(2048)),gb=B(Symbol.for("effect/FiberRef/currentLogAnnotation"),()=>Je(Ai())),Lf=B(Symbol.for("effect/FiberRef/currentLogLevel"),()=>Je(Nf)),yb=B(Symbol.for("effect/FiberRef/currentLogSpan"),()=>Je(Dn())),xb=p(2,(e,t)=>Wn(e,Ni,t));var Sb=B(Symbol.for("effect/FiberRef/currentConcurrency"),()=>Je("unbounded")),bb=B(Symbol.for("effect/FiberRef/currentRequestBatching"),()=>Je(!0)),_b=B(Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"),()=>Je(F(Ff))),wb=B(Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"),()=>Je(F(Pf)));var ua=B(Symbol.for("effect/FiberRef/currentMetricLabels"),()=>lC(Vr()));var fl=B(Symbol.for("effect/FiberRef/currentForkScopeOverride"),()=>Je(A(),{fork:()=>A(),join:(e,t)=>e})),pa=B(Symbol.for("effect/FiberRef/currentInterruptedCause"),()=>Je(Qr,{fork:()=>Qr,join:(e,t)=>e}));var vl=Symbol.for("effect/Scope"),Al=Symbol.for("effect/CloseableScope"),Tl=(e,t)=>e.addFinalizer(()=>on(t));var Df=(e,t)=>e.close(t),Fi=(e,t)=>e.fork(t);var Il=function(){class e extends globalThis.Error{commit(){return Be(this)}toJSON(){let t={...this};if(this.message)t.message=this.message;if(this.cause)t.cause=this.cause;return t}[Y](){if(this.toString!==globalThis.Error.prototype.toString)return this.stack?`${this.toString()}
|
|
26
26
|
${this.stack.split(`
|
|
27
27
|
`).slice(1).join(`
|
|
28
|
-
`)}`:this.toString();else if("Bun"in globalThis)return pr(bi(this),{renderErrorCause:!0});return this}}return Object.assign(e.prototype,Np),e}(),Lo=(e,t)=>{class r extends vl{_tag=t}return Object.assign(r.prototype,e),r.prototype.name=t,r},zS=Symbol.for("effect/Cause/errors/RuntimeException"),iC=Lo({[zS]:zS},"RuntimeException");var xf=Symbol.for("effect/Cause/errors/InterruptedException"),A2=Lo({[xf]:xf},"InterruptedException"),Sb=(e)=>w(e,xf),GS=Symbol.for("effect/Cause/errors/IllegalArgument"),sC=Lo({[GS]:GS},"IllegalArgumentException");var JS=Symbol.for("effect/Cause/errors/NoSuchElement"),pa=Lo({[JS]:JS},"NoSuchElementException");var YS=Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"),T2=Lo({[YS]:YS},"InvalidPubSubCapacityException"),ZS=Symbol.for("effect/Cause/errors/ExceededCapacityException"),I2=Lo({[ZS]:ZS},"ExceededCapacityException");var QS=Symbol.for("effect/Cause/errors/Timeout"),k2=Lo({[QS]:QS},"TimeoutException");var XS=Symbol.for("effect/Cause/errors/UnknownException"),aC=function(){class e extends vl{_tag="UnknownException";error;constructor(t,r){super(r??"An unknown error occurred",{cause:t});this.error=t}}return Object.assign(e.prototype,{[XS]:XS,name:"UnknownException"}),e}();var Fi=(e)=>Ii(e)&&("_tag"in e)&&(e._tag==="Success"||e._tag==="Failure");var Lf=(e)=>e._tag==="Success";var bb=p(2,(e,t)=>{switch(e._tag){case wt:return le(e.effect_instruction_i0);case Et:return xe(t)}}),da=(e)=>bb(e,void 0);var Do=(e,t)=>cC(e,t?.parallel?Io:tt),Df=(e)=>le(Lt(e));var fa=(e)=>le(bi(e)),le=(e)=>{let t=new _f(wt);return t.effect_instruction_i0=e,t};var qf=(e)=>le(ur(e)),ll=p(2,(e,t)=>{switch(e._tag){case wt:return le(e.effect_instruction_i0);case Et:return xe(t(e.effect_instruction_i0))}});var Al=p(2,(e,{onFailure:t,onSuccess:r})=>{switch(e._tag){case wt:return t(e.effect_instruction_i0);case Et:return r(e.effect_instruction_i0)}});var xe=(e)=>{let t=new wf(Et);return t.effect_instruction_i0=e,t},Jt=xe(void 0);var Uf=p(3,(e,t,{onFailure:r,onSuccess:n})=>{switch(e._tag){case wt:switch(t._tag){case Et:return le(e.effect_instruction_i0);case wt:return le(r(e.effect_instruction_i0,t.effect_instruction_i0))}case Et:switch(t._tag){case Et:return xe(n(e.effect_instruction_i0,t.effect_instruction_i0));case wt:return le(t.effect_instruction_i0)}}}),cC=(e,t)=>{let r=Ec(e);if(!ar(r))return E();return m(lr(r),pi(m(cr(r),ll(Fe)),(n,o)=>m(n,Uf(o,{onSuccess:(i,s)=>m(i,et(s)),onFailure:t}))),ll(Tn),ll((n)=>Gr(n)),P)},_b=(e)=>({...En,[$S]:BS,state:Vc(KS([])),commit(){return Tl(this)},blockingOn:e});var Tl=(e)=>tb((t)=>{let r=wi(e.state);switch(r._tag){case cl:return t(r.effect);case Ai:return r.joiners.push(t),lC(e,t)}},e.blockingOn);var Il=(e,t)=>{let r=wi(e.state);if(r._tag===Ai){zc(e.state,WS(t));for(let n=0,o=r.joiners.length;n<o;n++)r.joiners[n](t)}},lC=(e,t)=>M(()=>{let r=wi(e.state);if(r._tag===Ai){let n=r.joiners.indexOf(t);if(n>=0)r.joiners.splice(n,1)}}),uC=ze((e)=>xe(e.currentContext)),wb=()=>uC;var qo=(e)=>H(wb(),e),pC=p(2,(e,t)=>Bn(Mo,t)(e));var Hf=p(2,(e,t)=>qo((r)=>pC(e,t(r))));var kl=(e)=>{let t=e.currentSpan;return t!==void 0&&t._tag==="Span"?P(t):E()};var Eb=Ax;var Ob=pr;var Rl="And",Cl="Or",Pl="InvalidData",Fl="MissingData",Nl="SourceUnavailable",Ml="Unsupported";var mC="effect/ConfigError",vb=Symbol.for(mC),Ni={_tag:"ConfigError",[vb]:vb},Ll=(e,t)=>{let r=Object.create(Ni);return r._op=Rl,r.left=e,r.right=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`${this.left} and ${this.right}`}}),Object.defineProperty(r,"message",{enumerable:!1,get(){return this.toString()}}),r},Dl=(e,t)=>{let r=Object.create(Ni);return r._op=Cl,r.left=e,r.right=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`${this.left} or ${this.right}`}}),Object.defineProperty(r,"message",{enumerable:!1,get(){return this.toString()}}),r},jf=(e,t,r={pathDelim:"."})=>{let n=Object.create(Ni);return n._op=Pl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Invalid data at ${m(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n},Ar=(e,t,r={pathDelim:"."})=>{let n=Object.create(Ni);return n._op=Fl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Missing data at ${m(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n},$f=(e,t,r,n={pathDelim:"."})=>{let o=Object.create(Ni);return o._op=Nl,o.path=e,o.message=t,o.cause=r,Object.defineProperty(o,"toString",{enumerable:!1,value(){return`(Source unavailable at ${m(this.path,zr(n.pathDelim))}: "${this.message}")`}}),o},Bf=(e,t,r={pathDelim:"."})=>{let n=Object.create(Ni);return n._op=Ml,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${m(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n};var Kn=p(2,(e,t)=>{switch(e._op){case Rl:return Ll(Kn(e.left,t),Kn(e.right,t));case Cl:return Dl(Kn(e.left,t),Kn(e.right,t));case Pl:return jf([...t,...e.path],e.message);case Fl:return Ar([...t,...e.path],e.message);case Nl:return $f([...t,...e.path],e.message,e.cause);case Ml:return Bf([...t,...e.path],e.message)}});var Ab=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._op){case Rl:{n.push(s.right),n.push(s.left),o.push(B({_op:"AndCase"}));break}case Cl:{n.push(s.right),n.push(s.left),o.push(B({_op:"OrCase"}));break}case Pl:{o.push(z(r.invalidDataCase(t,s.path,s.message)));break}case Fl:{o.push(z(r.missingDataCase(t,s.path,s.message)));break}case Nl:{o.push(z(r.sourceUnavailableCase(t,s.path,s.message,s.cause)));break}case Ml:{o.push(z(r.unsupportedCase(t,s.path,s.message)));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._op){case"Left":{switch(s.left._op){case"AndCase":{let a=i.pop(),c=i.pop(),l=r.andCase(t,a,c);i.push(l);break}case"OrCase":{let a=i.pop(),c=i.pop(),l=r.orCase(t,a,c);i.push(l);break}}break}case"Right":{i.push(s.right);break}}}if(i.length===0)throw Error("BUG: ConfigError.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");return i.pop()});var hC="effect/Clock",Ib=Symbol.for(hC),ma=vt("effect/Clock"),gC=2147483647,kb={unsafeSchedule(e,t){let r=Wc(t);if(r>gC)return Sn;let n=!1,o=setTimeout(()=>{n=!0,e()},r);return()=>(clearTimeout(o),!n)}},Rb=function(){let e=BigInt(1e6);if(typeof performance>"u"||typeof performance.now!=="function")return()=>BigInt(Date.now())*e;let t;return()=>{if(t===void 0)t=BigInt(Date.now())*e-BigInt(Math.round(performance.now()*1e6));return t+BigInt(Math.round(performance.now()*1e6))}}(),yC=function(){let e=typeof process==="object"&&"hrtime"in process&&typeof process.hrtime.bigint==="function"?process.hrtime:void 0;if(!e)return Rb;let t=Rb()-e.bigint();return()=>t+e.bigint()}();class Cb{[Ib]=Ib;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return yC()}currentTimeMillis=M(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=M(()=>this.unsafeCurrentTimeNanos());scheduler(){return ne(kb)}sleep(e){return Un((t)=>{let r=kb.unsafeSchedule(()=>t(Ne),e);return on(M(r))})}}var Pb=()=>new Cb;var Tr=vy;var Mi=(e)=>e.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&");var Mb={_tag:"Empty"};var Ul=p(2,(e,t)=>{let r=Vs(t),n=e;while(Wd(r)){let o=r.head;switch(o._tag){case"Empty":{r=r.tail;break}case"AndThen":{r=en(o.first,en(o.second,r.tail));break}case"MapName":{n=sr(n,o.f),r=r.tail;break}case"Nested":{n=li(n,o.name),r=r.tail;break}case"Unnested":{if(m(Kr(n),ky(o.name)))n=ir(n),r=r.tail;else return B(Ar(n,`Expected ${o.name} to be in path in ConfigProvider#unnested`));break}}}return z(n)});var Lb="Constant",Db="Fail",qb="Fallback",Ub="Described",Hb="Lazy",jb="MapOrFail",$b="Nested",Bb="Primitive",Kb="Redacted",Wb="Sequence",Vb="HashMap",zb="ZipWith";var Hl=(e,t)=>[...e,...t],OC="effect/ConfigProvider",Gb=Symbol.for(OC),Yb=vt("effect/ConfigProvider"),vC="effect/ConfigProviderFlat",Jb=Symbol.for(vC),AC=(e)=>({[Gb]:Gb,pipe(){return x(this,arguments)},...e}),TC=(e)=>({[Jb]:Jb,patch:e.patch,load:(t,r,n=!0)=>e.load(t,r,n),enumerateChildren:e.enumerateChildren}),IC=(e)=>AC({load:(t)=>H(Dt(e,Vr(),t,!1),(r)=>Ae(Kr(r),{onNone:()=>$e(Ar(Vr(),`Expected a single value having structure: ${t}`)),onSome:ne})),flattened:e}),Zb=(e)=>{let{pathDelim:t,seqDelim:r}=Object.assign({},{pathDelim:"_",seqDelim:","},e),n=(c)=>m(c,zr(t)),o=(c)=>c.split(t),i=()=>typeof process<"u"&&("env"in process)&&typeof process.env==="object"?process.env:{};return IC(TC({load:(c,l,u=!0)=>{let d=n(c),f=i(),h=d in f?P(f[d]):E();return m(h,Po(()=>Ar(c,`Expected ${d} to exist in the process context`)),H((g)=>MC(g,c,l,r,u)))},enumerateChildren:(c)=>M(()=>{let l=i(),f=Object.keys(l).map((h)=>o(h.toUpperCase())).filter((h)=>{for(let g=0;g<c.length;g++){let O=m(c,Yp(g)),S=h[g];if(S===void 0||O!==S)return!1}return!0}).flatMap((h)=>h.slice(c.length,c.length+1));return bx(f)}),patch:Mb}))};var kC=(e,t,r,n)=>{let o=ed(r.length,(c)=>c>=n.length?E():P([e(c),c+1])),i=ed(n.length,(c)=>c>=r.length?E():P([t(c),c+1])),s=Hl(r,o),a=Hl(n,i);return[s,a]},RC=(e,t)=>{let r=t;if(r._tag==="Nested"){let n=e.slice();while(r._tag==="Nested")n.push(r.name),r=r.config;return n}return e},CC={andCase:(e,t,r)=>Ll(t,r),orCase:(e,t,r)=>Dl(t,r),invalidDataCase:(e,t)=>jf(t,"<redacted>"),missingDataCase:(e,t)=>Ar(t,"<redacted>"),sourceUnavailableCase:(e,t,r,n)=>$f(t,"<redacted>",n),unsupportedCase:(e,t)=>Bf(t,"<redacted>")},PC=(e)=>Ab(e,void 0,CC),Dt=(e,t,r,n)=>{let o=r;switch(o._tag){case Lb:return ne(Xe(o.value));case Ub:return fe(()=>Dt(e,t,o.config,n));case Db:return $e(Ar(t,o.message));case qb:return m(fe(()=>Dt(e,t,o.first,n)),ta((i)=>{if(o.condition(i))return m(Dt(e,t,o.second,n),ta((s)=>$e(Dl(i,s))));return $e(i)}));case Hb:return fe(()=>Dt(e,t,o.config(),n));case jb:return fe(()=>m(Dt(e,t,o.original,n),H(Gt((i)=>m(o.mapOrFail(i),Po(Kn(RC(t,o.original))))))));case $b:return fe(()=>Dt(e,Hl(t,Xe(o.name)),o.config,n));case Bb:return m(Ul(t,e.patch),H((i)=>m(e.load(i,o,n),H((s)=>{if(s.length===0){let a=m(Ly(i),ue(()=>"<n/a>"));return $e(Ar([],`Expected ${o.description} with name ${a}`))}return ne(s)}))));case Kb:return fe(()=>m(Dt(e,t,o.original,n),Po(PC),Oe(sr(o.redact))));case Wb:return m(Ul(t,e.patch),H((i)=>m(e.enumerateChildren(i),H(DC),H((s)=>{if(s.length===0)return fe(()=>Oe(Dt(e,t,o.config,!0),Xe));return m(Gt(s,(a)=>Dt(e,Fy(t,`[${a}]`),o.config,!0)),Oe((a)=>{let c=_c(a);if(c.length===0)return Xe(Vr());return Xe(c)}))}))));case Vb:return fe(()=>m(Ul(t,e.patch),H((i)=>m(e.enumerateChildren(i),H((s)=>m(s,Gt((a)=>Dt(e,Hl(i,Xe(a)),o.valueConfig,n)),Oe((a)=>{if(a.length===0)return Xe(Oi());return m(LC(a),sr((c)=>cS(Xp(de(s),c))))})))))));case zb:return fe(()=>m(Dt(e,t,o.left,n),Ro,H((i)=>m(Dt(e,t,o.right,n),Ro,H((s)=>{if(ye(i)&&ye(s))return $e(Ll(i.left,s.left));if(ye(i)&&Qe(s))return $e(i.left);if(Qe(i)&&ye(s))return $e(s.left);if(Qe(i)&&Qe(s)){let a=m(t,zr(".")),c=FC(t,a),[l,u]=kC(c,c,m(i.right,sr(z)),m(s.right,sr(z)));return m(l,Xp(u),Gt(([d,f])=>m(xl(d,f),Oe(([h,g])=>o.zip(h,g)))))}throw Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues")})))))}},FC=(e,t)=>(r)=>B(Ar(e,`The element at index ${r} in a sequence at path "${t}" was missing`));var NC=(e,t)=>e.split(new RegExp(`\\s*${Mi(t)}\\s*`)),MC=(e,t,r,n,o)=>{if(!o)return m(r.parse(e),hl({onFailure:Kn(t),onSuccess:Xe}));return m(NC(e,n),Gt((i)=>r.parse(i.trim())),Po(Kn(t)))},LC=(e)=>Object.keys(e[0]).map((t)=>e.map((r)=>r[t])),DC=(e)=>m(Gt(e,UC),hl({onFailure:()=>Vr(),onSuccess:Wr(Tr)}),Ro,Oe(wy));var qC=/^(\[(\d+)\])$/,UC=(e)=>{let t=e.match(qC);if(t!==null){let r=t[2];return m(r!==void 0&&r.length>0?P(r):E(),or(HC))}return E()};var HC=(e)=>{let t=Number.parseInt(e);return Number.isNaN(t)?E():P(t)};var Qb=Symbol.for("effect/Console"),jl=vt("effect/Console"),Xb={[Qb]:Qb,assert(e,...t){return M(()=>{console.assert(e,...t)})},clear:M(()=>{console.clear()}),count(e){return M(()=>{console.count(e)})},countReset(e){return M(()=>{console.countReset(e)})},debug(...e){return M(()=>{console.debug(...e)})},dir(e,t){return M(()=>{console.dir(e,t)})},dirxml(...e){return M(()=>{console.dirxml(...e)})},error(...e){return M(()=>{console.error(...e)})},group(e){return e?.collapsed?M(()=>console.groupCollapsed(e?.label)):M(()=>console.group(e?.label))},groupEnd:M(()=>{console.groupEnd()}),info(...e){return M(()=>{console.info(...e)})},log(...e){return M(()=>{console.log(...e)})},table(e,t){return M(()=>{console.table(e,t)})},time(e){return M(()=>console.time(e))},timeEnd(e){return M(()=>console.timeEnd(e))},timeLog(e,...t){return M(()=>{console.timeLog(e,...t)})},trace(...e){return M(()=>{console.trace(...e)})},warn(...e){return M(()=>{console.warn(...e)})},unsafe:console};var BC="effect/Random",e_=Symbol.for(BC),t_=vt("effect/Random");class r_{seed;[e_]=e_;PRNG;constructor(e){this.seed=e,this.PRNG=new Ip(e)}get next(){return M(()=>this.PRNG.number())}get nextBoolean(){return Oe(this.next,(e)=>e>0.5)}get nextInt(){return M(()=>this.PRNG.integer(Number.MAX_SAFE_INTEGER))}nextRange(e,t){return Oe(this.next,(r)=>(t-e)*r+e)}nextIntBetween(e,t){return M(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return KC(e,(t)=>this.nextIntBetween(0,t))}}var KC=(e,t)=>fe(()=>m(M(()=>Array.from(e)),H((r)=>{let n=[];for(let o=r.length;o>=2;o=o-1)n.push(o);return m(n,Co((o)=>m(t(o),Oe((i)=>WC(r,o-1,i)))),nn(Ec(r)))}))),WC=(e,t,r)=>{let n=e[t];return e[t]=e[r],e[r]=n,e},n_=(e)=>new r_(b(e));var o_=Symbol.for("effect/Tracer"),zC=(e)=>({[o_]:o_,...e}),ha=vt("effect/Tracer"),$l=vt("effect/ParentSpan"),i_=function(){return function(r){let n="";for(let o=0;o<r;o++)n+="abcdef0123456789".charAt(Math.floor(Math.random()*16));return n}}();class s_{name;parent;context;startTime;kind;_tag="Span";spanId;traceId="native";sampled=!0;status;attributes;events=[];links;constructor(e,t,r,n,o,i){this.name=e,this.parent=t,this.context=r,this.startTime=o,this.kind=i,this.status={_tag:"Started",startTime:o},this.attributes=new Map,this.traceId=t._tag==="Some"?t.value.traceId:i_(32),this.spanId=i_(16),this.links=Array.from(n)}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,r){this.events.push([e,t,r??{}])}addLinks(e){this.links.push(...e)}}var a_=zC({span:(e,t,r,n,o,i)=>new s_(e,t,r,n,o,i),context:(e)=>e()});var c_=Bs()("effect/Tracer/DisablePropagation",{defaultValue:Sn});var YC=m(Nn(),Er(ma,Pb()),Er(jl,Xb),Er(t_,n_(Math.random())),Er(Yb,Zb()),Er(ha,a_)),ga=U(Symbol.for("effect/DefaultServices/currentServices"),()=>_l(YC));var QC=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return{BaseEffectError:class extends vl{constructor(r){super(r?.message,r?.cause?{cause:r.cause}:void 0);if(r)Object.assign(this,r),Object.defineProperty(this,e,{value:r,enumerable:!1})}toJSON(){return{...this[e],...this}}}}.BaseEffectError}(),l_=(e)=>{let t={BaseEffectError:class extends QC{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError};var u_=$r;var XC=fy;class Wf extends XC{}var d_="Sequential",f_="Parallel",eP="ParallelN",Li={_tag:d_},m_={_tag:f_},h_=(e)=>({_tag:eP,parallelism:e}),Vf=(e)=>e._tag===d_,zf=(e)=>e._tag===f_;var Bl=Li,Kl=m_,Wl=h_;function g_(e){return new sn(e)}function y_(){return g_(new Map)}var Jf=Symbol.for("effect/FiberRefs");class sn{locals;[Jf]=Jf;constructor(e){this.locals=e}pipe(){return x(this,arguments)}}var rP=(e,t,r,n=!1)=>{let o=e,i=t,s=r,a=n,c=void 0;while(c===void 0)if(ce(i)&&ce(s)){let l=Pe(i)[0],u=ir(i),d=Pe(s)[0],f=Pe(s)[1],h=ir(s);if(l.startTimeMillis<d.startTimeMillis)s=h,a=!0;else if(l.startTimeMillis>d.startTimeMillis)i=u;else if(l.id<d.id)s=h,a=!0;else if(l.id>d.id)i=u;else c=[f,a]}else c=[o.initial,!0];return c},Zf=p(3,(e,t,r)=>{let n=new Map(e.locals);return r.locals.forEach((o,i)=>{let s=o[0][1];if(!o[0][0][A](t)){if(!n.has(i)){if(_(s,i.initial))return;n.set(i,[[t,i.join(i.initial,s)]]);return}let a=n.get(i),[c,l]=rP(i,a,o);if(l){let u=i.diff(c,s),d=a[0][1],f=i.join(d,i.patch(u)(d));if(!_(d,f)){let h,g=a[0][0];if(g[A](t))h=[[g,f],...a.slice(1)];else h=[[t,f],...a];n.set(i,h)}}}}),new sn(n)}),Qf=p(2,(e,t)=>{let r=new Map;return x_(e,r,t),new sn(r)}),x_=(e,t,r)=>{e.locals.forEach((n,o)=>{let i=n[0][1],s=o.patch(o.fork)(i);if(_(i,s))t.set(o,n);else t.set(o,[[r,s],...n])})};var ya=p(2,(e,t)=>{let r=new Map(e.locals);return r.delete(t),new sn(r)}),Xf=p(2,(e,t)=>{if(!e.locals.has(t))return E();return P(Pe(e.locals.get(t))[1])}),Wn=p(2,(e,t)=>m(Xf(e,t),ue(()=>t.initial))),Di=p(2,(e,{fiberId:t,fiberRef:r,value:n})=>{if(e.locals.size===0)return new sn(new Map([[r,[[t,n]]]]));let o=new Map(e.locals);return Yf(o,t,r,n),new sn(o)}),Yf=(e,t,r,n)=>{let o=e.get(r)??[],i;if(ce(o)){let[s,a]=Pe(o);if(s[A](t))if(_(a,n))return;else i=[[t,n],...o.slice(1)];else i=[[t,n],...o]}else i=[[t,n]];e.set(r,i)},S_=p(2,(e,{entries:t,forkAs:r})=>{if(e.locals.size===0)return new sn(new Map(t));let n=new Map(e.locals);if(r!==void 0)x_(e,n,r);return t.forEach(([o,i])=>{if(i.length===1)Yf(n,i[0][0],o,i[0][1]);else i.forEach(([s,a])=>{Yf(n,s,o,a)})}),new sn(n)});var b_=Wn;var __=S_;var w_=y_;var O_="Empty",v_="Add",A_="Remove",T_="Update",I_="AndThen",k_={_tag:O_},R_=(e,t)=>{let r=new Map(e.locals),n=k_;for(let[o,i]of t.locals.entries()){let s=Pe(i)[1],a=r.get(o);if(a!==void 0){let c=Pe(a)[1];if(!_(c,s))n=Vl({_tag:T_,fiberRef:o,patch:o.diff(c,s)})(n)}else n=Vl({_tag:v_,fiberRef:o,value:s})(n);r.delete(o)}for(let[o]of r.entries())n=Vl({_tag:A_,fiberRef:o})(n);return n},Vl=p(2,(e,t)=>({_tag:I_,first:e,second:t})),C_=p(3,(e,t,r)=>{let n=r,o=Xe(e);while(ce(o)){let i=Pe(o),s=ir(o);switch(i._tag){case O_:{o=s;break}case v_:{n=Di(n,{fiberId:t,fiberRef:i.fiberRef,value:i.value}),o=s;break}case A_:{n=ya(n,i.fiberRef),o=s;break}case T_:{let a=Wn(n,i.fiberRef);n=Di(n,{fiberId:t,fiberRef:i.fiberRef,value:i.fiberRef.patch(i.patch)(a)}),o=s;break}case I_:{o=li(i.first)(li(i.second)(s));break}}}return n});var P_=R_;var F_=C_;var Gl="effect/FiberStatus",Vn=Symbol.for(Gl),zl="Done",N_="Running",M_="Suspended",iP=oe(`${Gl}-${zl}`);class L_{[Vn]=Vn;_tag=zl;[I](){return iP}[A](e){return Jl(e)&&e._tag===zl}}class D_{runtimeFlags;[Vn]=Vn;_tag=N_;constructor(e){this.runtimeFlags=e}[I](){return m(b(Gl),K(b(this._tag)),K(b(this.runtimeFlags)),Z(this))}[A](e){return Jl(e)&&e._tag===N_&&this.runtimeFlags===e.runtimeFlags}}class q_{runtimeFlags;blockingOn;[Vn]=Vn;_tag=M_;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[I](){return m(b(Gl),K(b(this._tag)),K(b(this.runtimeFlags)),K(b(this.blockingOn)),Z(this))}[A](e){return Jl(e)&&e._tag===M_&&this.runtimeFlags===e.runtimeFlags&&_(this.blockingOn,e.blockingOn)}}var U_=new L_,H_=(e)=>new D_(e),j_=(e,t)=>new q_(e,t),Jl=(e)=>w(e,Vn),$_=(e)=>e._tag===zl;var B_=U_,tm=H_,K_=j_;var W_=$_;var cP=ib,lP=sb,uP=ab,pP=Rf,dP=Cf,fP=Pf,mP=cb,hP=lb;var gP=m(Tr,bc((e)=>e.ordinal));var V_=Kp(gP);var z_=(e)=>{switch(e){case"All":return cP;case"Debug":return fP;case"Error":return uP;case"Fatal":return lP;case"Info":return dP;case"Trace":return mP;case"None":return hP;case"Warning":return pP}};var xP=Symbol.for("effect/Micro"),Zl=Symbol.for("effect/Micro/MicroExit");var G_=Symbol.for("effect/Micro/MicroCause");var SP={_E:te};class om extends globalThis.Error{_tag;traces;[G_];constructor(e,t,r){let n=`MicroCause.${e}`,o,i,s;if(t instanceof globalThis.Error){o=`(${n}) ${t.name}`,i=t.message;let a=i.split(`
|
|
28
|
+
`)}`:this.toString();else if("Bun"in globalThis)return pr(wi(this),{renderErrorCause:!0});return this}}return Object.assign(e.prototype,Lp),e}(),qo=(e,t)=>{class r extends Il{_tag=t}return Object.assign(r.prototype,e),r.prototype.name=t,r},ZS=Symbol.for("effect/Cause/errors/RuntimeException"),uC=qo({[ZS]:ZS},"RuntimeException");var bf=Symbol.for("effect/Cause/errors/InterruptedException"),F2=qo({[bf]:bf},"InterruptedException"),Eb=(e)=>v(e,bf),QS=Symbol.for("effect/Cause/errors/IllegalArgument"),pC=qo({[QS]:QS},"IllegalArgumentException");var XS=Symbol.for("effect/Cause/errors/NoSuchElement"),da=qo({[XS]:XS},"NoSuchElementException");var eb=Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"),M2=qo({[eb]:eb},"InvalidPubSubCapacityException"),tb=Symbol.for("effect/Cause/errors/ExceededCapacityException"),L2=qo({[tb]:tb},"ExceededCapacityException");var rb=Symbol.for("effect/Cause/errors/Timeout"),D2=qo({[rb]:rb},"TimeoutException");var nb=Symbol.for("effect/Cause/errors/UnknownException"),dC=function(){class e extends Il{_tag="UnknownException";error;constructor(t,r){super(r??"An unknown error occurred",{cause:t});this.error=t}}return Object.assign(e.prototype,{[nb]:nb,name:"UnknownException"}),e}();var Mi=(e)=>ki(e)&&("_tag"in e)&&(e._tag==="Success"||e._tag==="Failure");var qf=(e)=>e._tag==="Success";var Ob=p(2,(e,t)=>{switch(e._tag){case wt:return ue(e.effect_instruction_i0);case Et:return xe(t)}}),fa=(e)=>Ob(e,void 0);var Uo=(e,t)=>fC(e,t?.parallel?ko:rt),Uf=(e)=>ue(Mt(e));var ma=(e)=>ue(wi(e)),ue=(e)=>{let t=new Ef(wt);return t.effect_instruction_i0=e,t};var Hf=(e)=>ue(ur(e)),dl=p(2,(e,t)=>{switch(e._tag){case wt:return ue(e.effect_instruction_i0);case Et:return xe(t(e.effect_instruction_i0))}});var Rl=p(2,(e,{onFailure:t,onSuccess:r})=>{switch(e._tag){case wt:return t(e.effect_instruction_i0);case Et:return r(e.effect_instruction_i0)}});var xe=(e)=>{let t=new Of(Et);return t.effect_instruction_i0=e,t},Gt=xe(void 0);var jf=p(3,(e,t,{onFailure:r,onSuccess:n})=>{switch(e._tag){case wt:switch(t._tag){case Et:return ue(e.effect_instruction_i0);case wt:return ue(r(e.effect_instruction_i0,t.effect_instruction_i0))}case Et:switch(t._tag){case Et:return xe(n(e.effect_instruction_i0,t.effect_instruction_i0));case wt:return ue(t.effect_instruction_i0)}}}),fC=(e,t)=>{let r=Ac(e);if(!ar(r))return A();return h(lr(r),fi(h(cr(r),dl(Ne)),(n,o)=>h(n,jf(o,{onSuccess:(i,s)=>h(i,tt(s)),onFailure:t}))),dl(In),dl((n)=>Gr(n)),F)},vb=(e)=>({...On,[VS]:zS,state:Jc(GS([])),commit(){return kl(this)},blockingOn:e});var kl=(e)=>ib((t)=>{let r=Oi(e.state);switch(r._tag){case pl:return t(r.effect);case Ii:return r.joiners.push(t),mC(e,t)}},e.blockingOn);var Cl=(e,t)=>{let r=Oi(e.state);if(r._tag===Ii){Yc(e.state,JS(t));for(let n=0,o=r.joiners.length;n<o;n++)r.joiners[n](t)}},mC=(e,t)=>q(()=>{let r=Oi(e.state);if(r._tag===Ii){let n=r.joiners.indexOf(t);if(n>=0)r.joiners.splice(n,1)}}),hC=Ge((e)=>xe(e.currentContext)),Ab=()=>hC;var Ho=(e)=>W(Ab(),e),gC=p(2,(e,t)=>Wn(Do,t)(e));var $f=p(2,(e,t)=>Ho((r)=>gC(e,t(r))));var Pl=(e)=>{let t=e.currentSpan;return t!==void 0&&t._tag==="Span"?F(t):A()};var Tb=kx;var Ib=pr;var Nl="And",Fl="Or",Ml="InvalidData",Ll="MissingData",Dl="SourceUnavailable",ql="Unsupported";var SC="effect/ConfigError",Rb=Symbol.for(SC),Li={_tag:"ConfigError",[Rb]:Rb},Ul=(e,t)=>{let r=Object.create(Li);return r._op=Nl,r.left=e,r.right=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`${this.left} and ${this.right}`}}),Object.defineProperty(r,"message",{enumerable:!1,get(){return this.toString()}}),r},Hl=(e,t)=>{let r=Object.create(Li);return r._op=Fl,r.left=e,r.right=t,Object.defineProperty(r,"toString",{enumerable:!1,value(){return`${this.left} or ${this.right}`}}),Object.defineProperty(r,"message",{enumerable:!1,get(){return this.toString()}}),r},Bf=(e,t,r={pathDelim:"."})=>{let n=Object.create(Li);return n._op=Ml,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Invalid data at ${h(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n},Ir=(e,t,r={pathDelim:"."})=>{let n=Object.create(Li);return n._op=Ll,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Missing data at ${h(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n},Wf=(e,t,r,n={pathDelim:"."})=>{let o=Object.create(Li);return o._op=Dl,o.path=e,o.message=t,o.cause=r,Object.defineProperty(o,"toString",{enumerable:!1,value(){return`(Source unavailable at ${h(this.path,zr(n.pathDelim))}: "${this.message}")`}}),o},Kf=(e,t,r={pathDelim:"."})=>{let n=Object.create(Li);return n._op=ql,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${h(this.path,zr(r.pathDelim))}: "${this.message}")`}}),n};var Kn=p(2,(e,t)=>{switch(e._op){case Nl:return Ul(Kn(e.left,t),Kn(e.right,t));case Fl:return Hl(Kn(e.left,t),Kn(e.right,t));case Ml:return Bf([...t,...e.path],e.message);case Ll:return Ir([...t,...e.path],e.message);case Dl:return Wf([...t,...e.path],e.message,e.cause);case ql:return Kf([...t,...e.path],e.message)}});var kb=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._op){case Nl:{n.push(s.right),n.push(s.left),o.push(K({_op:"AndCase"}));break}case Fl:{n.push(s.right),n.push(s.left),o.push(K({_op:"OrCase"}));break}case Ml:{o.push(G(r.invalidDataCase(t,s.path,s.message)));break}case Ll:{o.push(G(r.missingDataCase(t,s.path,s.message)));break}case Dl:{o.push(G(r.sourceUnavailableCase(t,s.path,s.message,s.cause)));break}case ql:{o.push(G(r.unsupportedCase(t,s.path,s.message)));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._op){case"Left":{switch(s.left._op){case"AndCase":{let a=i.pop(),c=i.pop(),l=r.andCase(t,a,c);i.push(l);break}case"OrCase":{let a=i.pop(),c=i.pop(),l=r.orCase(t,a,c);i.push(l);break}}break}case"Right":{i.push(s.right);break}}}if(i.length===0)throw Error("BUG: ConfigError.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues");return i.pop()});var bC="effect/Clock",Pb=Symbol.for(bC),ha=vt("effect/Clock"),_C=2147483647,Nb={unsafeSchedule(e,t){let r=Gc(t);if(r>_C)return bn;let n=!1,o=setTimeout(()=>{n=!0,e()},r);return()=>(clearTimeout(o),!n)}},Fb=function(){let e=BigInt(1e6);if(typeof performance>"u"||typeof performance.now!=="function")return()=>BigInt(Date.now())*e;let t;return()=>{if(t===void 0)t=BigInt(Date.now())*e-BigInt(Math.round(performance.now()*1e6));return t+BigInt(Math.round(performance.now()*1e6))}}(),wC=function(){let e=typeof process==="object"&&"hrtime"in process&&typeof process.hrtime.bigint==="function"?process.hrtime:void 0;if(!e)return Fb;let t=Fb()-e.bigint();return()=>t+e.bigint()}();class Mb{[Pb]=Pb;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return wC()}currentTimeMillis=q(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=q(()=>this.unsafeCurrentTimeNanos());scheduler(){return ne(Nb)}sleep(e){return Hn((t)=>{let r=Nb.unsafeSchedule(()=>t(Fe),e);return on(q(r))})}}var Lb=()=>new Mb;var Rr=Ry;var Di=(e)=>e.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&");var Ub={_tag:"Empty"};var $l=p(2,(e,t)=>{let r=zs(t),n=e;while(zd(r)){let o=r.head;switch(o._tag){case"Empty":{r=r.tail;break}case"AndThen":{r=en(o.first,en(o.second,r.tail));break}case"MapName":{n=sr(n,o.f),r=r.tail;break}case"Nested":{n=pi(n,o.name),r=r.tail;break}case"Unnested":{if(h(Wr(n),Ny(o.name)))n=ir(n),r=r.tail;else return K(Ir(n,`Expected ${o.name} to be in path in ConfigProvider#unnested`));break}}}return G(n)});var Hb="Constant",jb="Fail",$b="Fallback",Bb="Described",Wb="Lazy",Kb="MapOrFail",Vb="Nested",zb="Primitive",Gb="Redacted",Jb="Sequence",Yb="HashMap",Zb="ZipWith";var Bl=(e,t)=>[...e,...t],RC="effect/ConfigProvider",Qb=Symbol.for(RC),e_=vt("effect/ConfigProvider"),kC="effect/ConfigProviderFlat",Xb=Symbol.for(kC),CC=(e)=>({[Qb]:Qb,pipe(){return b(this,arguments)},...e}),PC=(e)=>({[Xb]:Xb,patch:e.patch,load:(t,r,n=!0)=>e.load(t,r,n),enumerateChildren:e.enumerateChildren}),NC=(e)=>CC({load:(t)=>W(Lt(e,Vr(),t,!1),(r)=>Ae(Wr(r),{onNone:()=>Be(Ir(Vr(),`Expected a single value having structure: ${t}`)),onSome:ne})),flattened:e}),t_=(e)=>{let{pathDelim:t,seqDelim:r}=Object.assign({},{pathDelim:"_",seqDelim:","},e),n=(c)=>h(c,zr(t)),o=(c)=>c.split(t),i=()=>typeof process<"u"&&("env"in process)&&typeof process.env==="object"?process.env:{};return NC(PC({load:(c,l,u=!0)=>{let d=n(c),f=i(),g=d in f?F(f[d]):A();return h(g,Fo(()=>Ir(c,`Expected ${d} to exist in the process context`)),W((y)=>HC(y,c,l,r,u)))},enumerateChildren:(c)=>q(()=>{let l=i(),f=Object.keys(l).map((g)=>o(g.toUpperCase())).filter((g)=>{for(let y=0;y<c.length;y++){let O=h(c,Qp(y)),m=g[y];if(m===void 0||O!==m)return!1}return!0}).flatMap((g)=>g.slice(c.length,c.length+1));return Ox(f)}),patch:Ub}))};var FC=(e,t,r,n)=>{let o=rd(r.length,(c)=>c>=n.length?A():F([e(c),c+1])),i=rd(n.length,(c)=>c>=r.length?A():F([t(c),c+1])),s=Bl(r,o),a=Bl(n,i);return[s,a]},MC=(e,t)=>{let r=t;if(r._tag==="Nested"){let n=e.slice();while(r._tag==="Nested")n.push(r.name),r=r.config;return n}return e},LC={andCase:(e,t,r)=>Ul(t,r),orCase:(e,t,r)=>Hl(t,r),invalidDataCase:(e,t)=>Bf(t,"<redacted>"),missingDataCase:(e,t)=>Ir(t,"<redacted>"),sourceUnavailableCase:(e,t,r,n)=>Wf(t,"<redacted>",n),unsupportedCase:(e,t)=>Kf(t,"<redacted>")},DC=(e)=>kb(e,void 0,LC),Lt=(e,t,r,n)=>{let o=r;switch(o._tag){case Hb:return ne(et(o.value));case Bb:return me(()=>Lt(e,t,o.config,n));case jb:return Be(Ir(t,o.message));case $b:return h(me(()=>Lt(e,t,o.first,n)),ra((i)=>{if(o.condition(i))return h(Lt(e,t,o.second,n),ra((s)=>Be(Hl(i,s))));return Be(i)}));case Wb:return me(()=>Lt(e,t,o.config(),n));case Kb:return me(()=>h(Lt(e,t,o.original,n),W(zt((i)=>h(o.mapOrFail(i),Fo(Kn(MC(t,o.original))))))));case Vb:return me(()=>Lt(e,Bl(t,et(o.name)),o.config,n));case zb:return h($l(t,e.patch),W((i)=>h(e.load(i,o,n),W((s)=>{if(s.length===0){let a=h(Hy(i),pe(()=>"<n/a>"));return Be(Ir([],`Expected ${o.description} with name ${a}`))}return ne(s)}))));case Gb:return me(()=>h(Lt(e,t,o.original,n),Fo(DC),ve(sr(o.redact))));case Jb:return h($l(t,e.patch),W((i)=>h(e.enumerateChildren(i),W($C),W((s)=>{if(s.length===0)return me(()=>ve(Lt(e,t,o.config,!0),et));return h(zt(s,(a)=>Lt(e,Dy(t,`[${a}]`),o.config,!0)),ve((a)=>{let c=Oc(a);if(c.length===0)return et(Vr());return et(c)}))}))));case Yb:return me(()=>h($l(t,e.patch),W((i)=>h(e.enumerateChildren(i),W((s)=>h(s,zt((a)=>Lt(e,Bl(i,et(a)),o.valueConfig,n)),ve((a)=>{if(a.length===0)return et(Ai());return h(jC(a),sr((c)=>dS(td(fe(s),c))))})))))));case Zb:return me(()=>h(Lt(e,t,o.left,n),Po,W((i)=>h(Lt(e,t,o.right,n),Po,W((s)=>{if(ge(i)&&ge(s))return Be(Ul(i.left,s.left));if(ge(i)&&ze(s))return Be(i.left);if(ze(i)&&ge(s))return Be(s.left);if(ze(i)&&ze(s)){let a=h(t,zr(".")),c=qC(t,a),[l,u]=FC(c,c,h(i.right,sr(G)),h(s.right,sr(G)));return h(l,td(u),zt(([d,f])=>h(_l(d,f),ve(([g,y])=>o.zip(g,y)))))}throw Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues")})))))}},qC=(e,t)=>(r)=>K(Ir(e,`The element at index ${r} in a sequence at path "${t}" was missing`));var UC=(e,t)=>e.split(new RegExp(`\\s*${Di(t)}\\s*`)),HC=(e,t,r,n,o)=>{if(!o)return h(r.parse(e),xl({onFailure:Kn(t),onSuccess:et}));return h(UC(e,n),zt((i)=>r.parse(i.trim())),Fo(Kn(t)))},jC=(e)=>Object.keys(e[0]).map((t)=>e.map((r)=>r[t])),$C=(e)=>h(zt(e,WC),xl({onFailure:()=>Vr(),onSuccess:Kr(Rr)}),Po,ve(Ay));var BC=/^(\[(\d+)\])$/,WC=(e)=>{let t=e.match(BC);if(t!==null){let r=t[2];return h(r!==void 0&&r.length>0?F(r):A(),or(KC))}return A()};var KC=(e)=>{let t=Number.parseInt(e);return Number.isNaN(t)?A():F(t)};var r_=Symbol.for("effect/Console"),Wl=vt("effect/Console"),n_={[r_]:r_,assert(e,...t){return q(()=>{console.assert(e,...t)})},clear:q(()=>{console.clear()}),count(e){return q(()=>{console.count(e)})},countReset(e){return q(()=>{console.countReset(e)})},debug(...e){return q(()=>{console.debug(...e)})},dir(e,t){return q(()=>{console.dir(e,t)})},dirxml(...e){return q(()=>{console.dirxml(...e)})},error(...e){return q(()=>{console.error(...e)})},group(e){return e?.collapsed?q(()=>console.groupCollapsed(e?.label)):q(()=>console.group(e?.label))},groupEnd:q(()=>{console.groupEnd()}),info(...e){return q(()=>{console.info(...e)})},log(...e){return q(()=>{console.log(...e)})},table(e,t){return q(()=>{console.table(e,t)})},time(e){return q(()=>console.time(e))},timeEnd(e){return q(()=>console.timeEnd(e))},timeLog(e,...t){return q(()=>{console.timeLog(e,...t)})},trace(...e){return q(()=>{console.trace(...e)})},warn(...e){return q(()=>{console.warn(...e)})},unsafe:console};var GC="effect/Random",o_=Symbol.for(GC),i_=vt("effect/Random");class s_{seed;[o_]=o_;PRNG;constructor(e){this.seed=e,this.PRNG=new kp(e)}get next(){return q(()=>this.PRNG.number())}get nextBoolean(){return ve(this.next,(e)=>e>0.5)}get nextInt(){return q(()=>this.PRNG.integer(Number.MAX_SAFE_INTEGER))}nextRange(e,t){return ve(this.next,(r)=>(t-e)*r+e)}nextIntBetween(e,t){return q(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return JC(e,(t)=>this.nextIntBetween(0,t))}}var JC=(e,t)=>me(()=>h(q(()=>Array.from(e)),W((r)=>{let n=[];for(let o=r.length;o>=2;o=o-1)n.push(o);return h(n,No((o)=>h(t(o),ve((i)=>YC(r,o-1,i)))),nn(Ac(r)))}))),YC=(e,t,r)=>{let n=e[t];return e[t]=e[r],e[r]=n,e},a_=(e)=>new s_(w(e));var c_=Symbol.for("effect/Tracer"),QC=(e)=>({[c_]:c_,...e}),ga=vt("effect/Tracer"),Kl=vt("effect/ParentSpan"),l_=function(){return function(r){let n="";for(let o=0;o<r;o++)n+="abcdef0123456789".charAt(Math.floor(Math.random()*16));return n}}();class u_{name;parent;context;startTime;kind;_tag="Span";spanId;traceId="native";sampled=!0;status;attributes;events=[];links;constructor(e,t,r,n,o,i){this.name=e,this.parent=t,this.context=r,this.startTime=o,this.kind=i,this.status={_tag:"Started",startTime:o},this.attributes=new Map,this.traceId=t._tag==="Some"?t.value.traceId:l_(32),this.spanId=l_(16),this.links=Array.from(n)}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,r){this.events.push([e,t,r??{}])}addLinks(e){this.links.push(...e)}}var p_=QC({span:(e,t,r,n,o,i)=>new u_(e,t,r,n,o,i),context:(e)=>e()});var d_=Ws()("effect/Tracer/DisablePropagation",{defaultValue:bn});var tP=h(Mn(),vr(ha,Lb()),vr(Wl,n_),vr(i_,a_(Math.random())),vr(e_,t_()),vr(ga,p_)),ya=B(Symbol.for("effect/DefaultServices/currentServices"),()=>Ol(tP));var nP=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return{BaseEffectError:class extends Il{constructor(r){super(r?.message,r?.cause?{cause:r.cause}:void 0);if(r)Object.assign(this,r),Object.defineProperty(this,e,{value:r,enumerable:!1})}toJSON(){return{...this[e],...this}}}}.BaseEffectError}(),f_=(e)=>{let t={BaseEffectError:class extends nP{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError};var m_=$r;var oP=yy;class zf extends oP{}var g_="Sequential",y_="Parallel",iP="ParallelN",qi={_tag:g_},x_={_tag:y_},S_=(e)=>({_tag:iP,parallelism:e}),Gf=(e)=>e._tag===g_,Jf=(e)=>e._tag===y_;var Vl=qi,zl=x_,Gl=S_;function b_(e){return new sn(e)}function __(){return b_(new Map)}var Zf=Symbol.for("effect/FiberRefs");class sn{locals;[Zf]=Zf;constructor(e){this.locals=e}pipe(){return b(this,arguments)}}var aP=(e,t,r,n=!1)=>{let o=e,i=t,s=r,a=n,c=void 0;while(c===void 0)if(le(i)&&le(s)){let l=Pe(i)[0],u=ir(i),d=Pe(s)[0],f=Pe(s)[1],g=ir(s);if(l.startTimeMillis<d.startTimeMillis)s=g,a=!0;else if(l.startTimeMillis>d.startTimeMillis)i=u;else if(l.id<d.id)s=g,a=!0;else if(l.id>d.id)i=u;else c=[f,a]}else c=[o.initial,!0];return c},Xf=p(3,(e,t,r)=>{let n=new Map(e.locals);return r.locals.forEach((o,i)=>{let s=o[0][1];if(!o[0][0][R](t)){if(!n.has(i)){if(E(s,i.initial))return;n.set(i,[[t,i.join(i.initial,s)]]);return}let a=n.get(i),[c,l]=aP(i,a,o);if(l){let u=i.diff(c,s),d=a[0][1],f=i.join(d,i.patch(u)(d));if(!E(d,f)){let g,y=a[0][0];if(y[R](t))g=[[y,f],...a.slice(1)];else g=[[t,f],...a];n.set(i,g)}}}}),new sn(n)}),em=p(2,(e,t)=>{let r=new Map;return w_(e,r,t),new sn(r)}),w_=(e,t,r)=>{e.locals.forEach((n,o)=>{let i=n[0][1],s=o.patch(o.fork)(i);if(E(i,s))t.set(o,n);else t.set(o,[[r,s],...n])})};var xa=p(2,(e,t)=>{let r=new Map(e.locals);return r.delete(t),new sn(r)}),tm=p(2,(e,t)=>{if(!e.locals.has(t))return A();return F(Pe(e.locals.get(t))[1])}),Vn=p(2,(e,t)=>h(tm(e,t),pe(()=>t.initial))),Ui=p(2,(e,{fiberId:t,fiberRef:r,value:n})=>{if(e.locals.size===0)return new sn(new Map([[r,[[t,n]]]]));let o=new Map(e.locals);return Qf(o,t,r,n),new sn(o)}),Qf=(e,t,r,n)=>{let o=e.get(r)??[],i;if(le(o)){let[s,a]=Pe(o);if(s[R](t))if(E(a,n))return;else i=[[t,n],...o.slice(1)];else i=[[t,n],...o]}else i=[[t,n]];e.set(r,i)},E_=p(2,(e,{entries:t,forkAs:r})=>{if(e.locals.size===0)return new sn(new Map(t));let n=new Map(e.locals);if(r!==void 0)w_(e,n,r);return t.forEach(([o,i])=>{if(i.length===1)Qf(n,i[0][0],o,i[0][1]);else i.forEach(([s,a])=>{Qf(n,s,o,a)})}),new sn(n)});var O_=Vn;var v_=E_;var A_=__;var I_="Empty",R_="Add",k_="Remove",C_="Update",P_="AndThen",N_={_tag:I_},F_=(e,t)=>{let r=new Map(e.locals),n=N_;for(let[o,i]of t.locals.entries()){let s=Pe(i)[1],a=r.get(o);if(a!==void 0){let c=Pe(a)[1];if(!E(c,s))n=Jl({_tag:C_,fiberRef:o,patch:o.diff(c,s)})(n)}else n=Jl({_tag:R_,fiberRef:o,value:s})(n);r.delete(o)}for(let[o]of r.entries())n=Jl({_tag:k_,fiberRef:o})(n);return n},Jl=p(2,(e,t)=>({_tag:P_,first:e,second:t})),M_=p(3,(e,t,r)=>{let n=r,o=et(e);while(le(o)){let i=Pe(o),s=ir(o);switch(i._tag){case I_:{o=s;break}case R_:{n=Ui(n,{fiberId:t,fiberRef:i.fiberRef,value:i.value}),o=s;break}case k_:{n=xa(n,i.fiberRef),o=s;break}case C_:{let a=Vn(n,i.fiberRef);n=Ui(n,{fiberId:t,fiberRef:i.fiberRef,value:i.fiberRef.patch(i.patch)(a)}),o=s;break}case P_:{o=pi(i.first)(pi(i.second)(s));break}}}return n});var L_=F_;var D_=M_;var Zl="effect/FiberStatus",zn=Symbol.for(Zl),Yl="Done",q_="Running",U_="Suspended",uP=ie(`${Zl}-${Yl}`);class H_{[zn]=zn;_tag=Yl;[P](){return uP}[R](e){return Ql(e)&&e._tag===Yl}}class j_{runtimeFlags;[zn]=zn;_tag=q_;constructor(e){this.runtimeFlags=e}[P](){return h(w(Zl),V(w(this._tag)),V(w(this.runtimeFlags)),Z(this))}[R](e){return Ql(e)&&e._tag===q_&&this.runtimeFlags===e.runtimeFlags}}class $_{runtimeFlags;blockingOn;[zn]=zn;_tag=U_;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[P](){return h(w(Zl),V(w(this._tag)),V(w(this.runtimeFlags)),V(w(this.blockingOn)),Z(this))}[R](e){return Ql(e)&&e._tag===U_&&this.runtimeFlags===e.runtimeFlags&&E(this.blockingOn,e.blockingOn)}}var B_=new H_,W_=(e)=>new j_(e),K_=(e,t)=>new $_(e,t),Ql=(e)=>v(e,zn),V_=(e)=>e._tag===Yl;var z_=B_,nm=W_,G_=K_;var J_=V_;var fP=lb,mP=ub,hP=pb,gP=Pf,yP=Nf,xP=Ff,SP=db,bP=fb;var _P=h(Rr,Ec((e)=>e.ordinal));var Y_=Vp(_P);var Z_=(e)=>{switch(e){case"All":return fP;case"Debug":return xP;case"Error":return hP;case"Fatal":return mP;case"Info":return yP;case"Trace":return SP;case"None":return bP;case"Warning":return gP}};var EP=Symbol.for("effect/Micro"),eu=Symbol.for("effect/Micro/MicroExit");var Q_=Symbol.for("effect/Micro/MicroCause");var OP={_E:te};class sm extends globalThis.Error{_tag;traces;[Q_];constructor(e,t,r){let n=`MicroCause.${e}`,o,i,s;if(t instanceof globalThis.Error){o=`(${n}) ${t.name}`,i=t.message;let a=i.split(`
|
|
29
29
|
`).length;s=t.stack?`(${n}) ${t.stack.split(`
|
|
30
30
|
`).slice(0,a+3).join(`
|
|
31
31
|
`)}`:`${o}: ${i}`}else o=n,i=jr(t,0),s=`${o}: ${i}`;if(r.length>0)s+=`
|
|
32
32
|
${r.join(`
|
|
33
|
-
`)}`;super(i);this._tag=e,this.traces=r,this[G_]=SP,this.name=o,this.stack=s}pipe(){return x(this,arguments)}toString(){return this.stack}[Y](){return this.stack}}class Z_ extends om{defect;constructor(e,t=[]){super("Die",e,t);this.defect=e}}var bP=(e,t=[])=>new Z_(e,t);class Q_ extends om{constructor(e=[]){super("Interrupt","interrupted",e)}}var _P=(e=[])=>new Q_(e);var wP=(e)=>e._tag==="Interrupt";var J_=Symbol.for("effect/Micro/MicroFiber"),EP={_A:te,_E:te};class X_{context;interruptible;[J_];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[J_]=EP}getRef(e){return qx(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),hs;return this._observers.push(e),()=>{let t=this._observers.indexOf(e);if(t>=0)this._observers.splice(t,1)}}_interrupted=!1;unsafeInterrupt(){if(this._exit)return;if(this._interrupted=!0,this.interruptible)this.evaluate(lm)}unsafePoll(){return this._exit}evaluate(e){if(this._exit)return;else if(this._yielded!==void 0){let n=this._yielded;this._yielded=void 0,n()}let t=this.runLoop(e);if(t===Yl)return;let r=Y_.interruptChildren&&Y_.interruptChildren(this);if(r!==void 0)return this.evaluate(Xl(r,()=>t));this._exit=t;for(let n=0;n<this._observers.length;n++)this._observers[n](t);this._observers.length=0}runLoop(e){let t=!1,r=e;this.currentOpCount=0;try{while(!0){if(this.currentOpCount++,!t&&this.getRef(tu).shouldYield(this)){t=!0;let n=r;r=Xl(IP,()=>n)}if(r=r[rm](this),r===Yl){let n=this._yielded;if(Zl in n)return this._yielded=void 0,n;return Yl}}}catch(n){if(!w(r,rm))return nm(`MicroFiber.runLoop: Not a valid effect: ${String(r)}`);return nm(n)}}getCont(e){while(!0){let t=this._stack.pop();if(!t)return;let r=t[Ql]&&t[Ql](this);if(r)return{[e]:r};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,Yl}children(){return this._children??=new Set}}var Y_=U("effect/Micro/fiberMiddleware",()=>({interruptChildren:void 0}));var ew=Symbol.for("effect/Micro/identifier"),De=Symbol.for("effect/Micro/args"),rm=Symbol.for("effect/Micro/evaluate"),Ui=Symbol.for("effect/Micro/successCont"),qi=Symbol.for("effect/Micro/failureCont"),Ql=Symbol.for("effect/Micro/ensureCont"),Yl=Symbol.for("effect/Micro/Yield"),OP={_A:te,_E:te,_R:te},vP={...u_,_op:"Micro",[xP]:OP,pipe(){return x(this,arguments)},[Symbol.iterator](){return new ni(new Hr(this))},toJSON(){return{_id:"Micro",op:this[ew],...De in this?{args:this[De]}:void 0}},toString(){return ie(this)},[Y](){return ie(this)}};function AP(e){return nm("Micro.evaluate: Not implemented")}var eu=(e)=>({...vP,[ew]:e.op,[rm]:e.eval??AP,[Ui]:e.contA,[qi]:e.contE,[Ql]:e.ensure}),im=(e)=>{let t=eu(e);return function(){let r=Object.create(t);return r[De]=e.single===!1?arguments:arguments[0],r}},tw=(e)=>{let t={...eu(e),[Zl]:Zl,_tag:e.op,get[e.prop](){return this[De]},toJSON(){return{_id:"MicroExit",_tag:e.op,[e.prop]:this[De]}},[A](r){return CP(r)&&r._tag===e.op&&_(this[De],r[De])},[I](){return Z(this,K(oe(e.op))(b(this[De])))}};return function(r){let n=Object.create(t);return n[De]=r,n[Ui]=void 0,n[qi]=void 0,n[Ql]=void 0,n}},sm=tw({op:"Success",prop:"value",eval(e){let t=e.getCont(Ui);return t?t[Ui](this[De],e):e.yieldWith(this)}}),rw=tw({op:"Failure",prop:"cause",eval(e){let t=e.getCont(qi);while(wP(this[De])&&t&&e.interruptible)t=e.getCont(qi);return t?t[qi](this[De],e):e.yieldWith(this)}});var TP=im({op:"Yield",eval(e){let t=!1;return e.getRef(tu).scheduleTask(()=>{if(t)return;e.evaluate(PP)},this[De]??0),e.yieldWith(()=>{t=!0})}}),IP=TP(0);var kP=sm(void 0);var am=im({op:"WithMicroFiber",eval(e){return this[De](e)}});var Xl=p(2,(e,t)=>{let r=Object.create(RP);return r[De]=e,r[Ui]=t,r}),RP=eu({op:"OnSuccess",eval(e){return e._stack.push(this),this[De]}});var CP=(e)=>w(e,Zl),nw=sm,cm=rw,lm=cm(_P());var nm=(e)=>cm(bP(e));var PP=nw(void 0);var FP="setImmediate"in globalThis?globalThis.setImmediate:(e)=>setTimeout(e,0);class um{tasks=[];running=!1;scheduleTask(e,t){if(this.tasks.push(e),!this.running)this.running=!0,FP(this.afterScheduled)}afterScheduled=()=>{this.running=!1,this.runTasks()};runTasks(){let e=this.tasks;this.tasks=[];for(let t=0,r=e.length;t<r;t++)e[t]()}shouldYield(e){return e.currentOpCount>=e.getRef(iw)}flush(){while(this.tasks.length>0)this.runTasks()}}var NP=p(2,(e,t)=>am((r)=>{let n=r.context;return r.context=t(n),DP(e,()=>(r.context=n,kP))}));var ow=p(2,(e,t)=>NP(e,$s(t)));class iw extends Bs()("effect/Micro/currentMaxOpsBeforeYield",{defaultValue:()=>2048}){}class tu extends Bs()("effect/Micro/currentScheduler",{defaultValue:()=>new um}){}var MP=p(2,(e,t)=>{let r=Object.create(LP);return r[De]=e,r[Ui]=t.onSuccess,r[qi]=t.onFailure,r}),LP=eu({op:"OnSuccessAndFailure",eval(e){return e._stack.push(this),this[De]}});var DP=p(2,(e,t)=>UP((r)=>MP(r(e),{onFailure:(n)=>Xl(t(cm(n)),()=>rw(n)),onSuccess:(n)=>Xl(t(nw(n)),()=>sm(n))})));var sw=im({op:"SetInterruptible",ensure(e){if(e.interruptible=this[De],e._interrupted&&e.interruptible)return()=>lm}}),qP=(e)=>am((t)=>{if(t.interruptible)return e;if(t.interruptible=!0,t._stack.push(sw(!1)),t._interrupted)return lm;return e}),UP=(e)=>am((t)=>{if(!t.interruptible)return e(te);return t.interruptible=!1,t._stack.push(sw(!0)),e(qP)});var aw=(e,t)=>{let r=new X_(tu.context(t?.scheduler??new um));if(r.evaluate(e),t?.signal)if(t.signal.aborted)r.unsafeInterrupt();else{let n=()=>r.unsafeInterrupt();t.signal.addEventListener("abort",n,{once:!0}),r.addObserver(()=>t.signal.removeEventListener("abort",n))}return r};class ru{scheduleDrain;running=!1;tasks=new pm;constructor(e){this.scheduleDrain=e}starveInternal=(e)=>{let t=this.tasks.buckets;this.tasks.buckets=[];for(let[r,n]of t)for(let o=0;o<n.length;o++)n[o]();if(this.tasks.buckets.length===0)this.running=!1;else this.starve(e)};starve(e=0){this.scheduleDrain(e,this.starveInternal)}scheduleTask(e,t){if(this.tasks.scheduleTask(e,t),!this.running)this.running=!0,this.starve()}static cached(e){let t=new ru(e),r=new WeakMap;return(n)=>{if(n===void 0)return t;let o=r.get(n);if(o===void 0)o=new ru(e),r.set(n,o);return o}}}class pm{buckets=[];scheduleTask(e,t){let r=this.buckets.length,n=void 0,o=0;for(;o<r;o++)if(this.buckets[o][0]<=t)n=this.buckets[o];else break;if(n&&n[0]===t)n[1].push(e);else if(o===r)this.buckets.push([t,[e]]);else this.buckets.splice(o,0,[t,[e]])}}class cw{maxNextTickBeforeTimer;getRunner=ru.cached((e,t)=>{if(e>=this.maxNextTickBeforeTimer)setTimeout(()=>t(0),0);else Promise.resolve(void 0).then(()=>t(e+1))});constructor(e){this.maxNextTickBeforeTimer=e}shouldYield(e){return e.currentOpCount>e.getFiberRef(Ff)?e.getFiberRef(Ci):!1}scheduleTask(e,t,r){this.getRunner(r).scheduleTask(e,t)}}var lw=U(Symbol.for("effect/Scheduler/defaultScheduler"),()=>new cw(2048));class xa{tasks=new pm;deferred=!1;scheduleTask(e,t,r){if(this.deferred)lw.scheduleTask(e,t,r);else this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(Ff)?e.getFiberRef(Ci):!1}flush(){while(this.tasks.buckets.length>0){let e=this.tasks.buckets;this.tasks.buckets=[];for(let[t,r]of e)for(let n=0;n<r.length;n++)r[n]()}this.deferred=!0}}var nu=U(Symbol.for("effect/FiberRef/currentScheduler"),()=>Ge(lw));var ou=U(Symbol.for("effect/FiberRef/currentRequestMap"),()=>Ge(new Map));var dm=(e,t,r,n)=>{switch(e){case void 0:return t();case"unbounded":return r();case"inherit":return Fo(hb,(o)=>o==="unbounded"?r():o>1?n(o):t());default:return e>1?n(e):t()}};var fm=(e)=>e.replace(/[\s="]/g,"_"),pw=(e)=>(t)=>`${fm(t.label)}=${e-t.startTime}ms`;var dw="effect/MetricLabel",mm=Symbol.for(dw);class fw{key;value;[mm]=mm;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=oe(dw+this.key+this.value)}[I](){return this._hash}[A](e){return KP(e)&&this.key===e.key&&this.value===e.value}pipe(){return x(this,arguments)}}var mw=(e,t)=>new fw(e,t),KP=(e)=>w(e,mm);var hm=or((e)=>Hs(e.context,c_)?e._tag==="Span"?hm(e.parent):E():P(e));var hw=Lf;var gm="InterruptSignal",ym="Stateful",xm="Resume",Sm="YieldNow",iu=(e)=>({_tag:"InterruptSignal",cause:e}),Hi=(e)=>({_tag:"Stateful",onFiber:e}),Uo=(e)=>({_tag:"Resume",effect:e}),gw=()=>({_tag:"YieldNow"});var YP="effect/FiberScope",su=Symbol.for(YP);class xw{[su]=su;fiberId=Vt;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}}class Sw{fiberId;parent;[su]=su;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell(Hi((r)=>{r.addChild(t),t.addObserver(()=>{r.removeChild(t)})}))}}var bw=(e)=>new Sw(e.id(),e),Sa=U(Symbol.for("effect/FiberScope/Global"),()=>new xw);var XP="effect/Fiber",bm=Symbol.for(XP),_m={_E:(e)=>e,_A:(e)=>e},e0={[bm]:_m,pipe(){return x(this,arguments)}},t0="effect/Fiber",ww=Symbol.for(t0);var au=(e)=>Sl(na(e.await),e.inheritAll);var uH={...En,commit(){return au(this)},...e0,id:()=>Vt,await:aa,children:ne([]),inheritAll:aa,poll:ne(E()),interruptAsFork:()=>aa};var zn="effect/FiberCurrent";var n0="effect/Logger",Ew=Symbol.for(n0),Ow={_Message:(e)=>e,_Output:(e)=>e},cu=(e)=>({[Ew]:Ow,log:e,pipe(){return x(this,arguments)}});var fH={[Ew]:Ow,log:hs,pipe(){return x(this,arguments)}};var o0=/^[^\s"=]*$/,i0=(e,t)=>({annotations:r,cause:n,date:o,fiberId:i,logLevel:s,message:a,spans:c})=>{let l=(g)=>g.match(o0)?g:e(g),u=(g,O)=>`${fm(g)}=${l(O)}`,d=(g,O)=>" "+u(g,O),f=u("timestamp",o.toISOString());f+=d("level",s.label),f+=d("fiber",Yc(i));let h=zp(a);for(let g=0;g<h.length;g++)f+=d("message",jr(h[g],t));if(!Sd(n))f+=d("cause",pr(n,{renderErrorCause:!0}));for(let g of c)f+=" "+pw(o.getTime())(g);for(let[g,O]of r)f+=d(g,jr(O,t));return f},s0=(e)=>`"${e.replace(/\\([\s\S])|(")/g,"\\$1$2")}"`,vw=cu(i0(s0));var Ho={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},mH={None:[],All:[],Trace:[Ho.gray],Debug:[Ho.blue],Info:[Ho.green],Warning:[Ho.yellow],Error:[Ho.red],Fatal:[Ho.bgBrightRed,Ho.black]};var Aw=typeof process==="object"&&process!==null&&typeof process.stdout==="object"&&process.stdout!==null,hH=Aw&&process.stdout.isTTY===!0,gH=Aw||"Deno"in globalThis;var Tw="effect/MetricBoundaries",wm=Symbol.for(Tw);class Iw{values;[wm]=wm;constructor(e){this.values=e,this._hash=m(oe(Tw),K(Nt(this.values)))}_hash;[I](){return this._hash}[A](e){return c0(e)&&_(this.values,e.values)}pipe(){return x(this,arguments)}}var c0=(e)=>w(e,wm),l0=(e)=>{let t=m(e,Gp(Fe(Number.POSITIVE_INFINITY)),td);return new Iw(t)};var kw=(e)=>m(Vp(e.count-1,(t)=>e.start*Math.pow(e.factor,t)),Fs,l0);var p0="effect/MetricKeyType",Rw=Symbol.for(p0),Cw="effect/MetricKeyType/Counter",Em=Symbol.for(Cw),d0="effect/MetricKeyType/Frequency",f0=Symbol.for(d0),m0="effect/MetricKeyType/Gauge",h0=Symbol.for(m0),Pw="effect/MetricKeyType/Histogram",Om=Symbol.for(Pw),g0="effect/MetricKeyType/Summary",y0=Symbol.for(g0),Fw={_In:(e)=>e,_Out:(e)=>e};class Nw{incremental;bigint;[Rw]=Fw;[Em]=Em;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=oe(Cw)}_hash;[I](){return this._hash}[A](e){return vm(e)}pipe(){return x(this,arguments)}}class Mw{boundaries;[Rw]=Fw;[Om]=Om;constructor(e){this.boundaries=e,this._hash=m(oe(Pw),K(b(this.boundaries)))}_hash;[I](){return this._hash}[A](e){return Am(e)&&_(this.boundaries,e.boundaries)}pipe(){return x(this,arguments)}}var Lw=(e)=>new Nw(e?.incremental??!1,e?.bigint??!1);var Dw=(e)=>new Mw(e);var vm=(e)=>w(e,Em),qw=(e)=>w(e,f0),Uw=(e)=>w(e,h0),Am=(e)=>w(e,Om),Hw=(e)=>w(e,y0);var x0="effect/MetricKey",$w=Symbol.for(x0),S0={_Type:(e)=>e},b0=An(_);class lu{name;keyType;description;tags;[$w]=S0;constructor(e,t,r,n=[]){this.name=e,this.keyType=t,this.description=r,this.tags=n,this._hash=m(oe(this.name+this.description),K(b(this.keyType)),K(Nt(this.tags)))}_hash;[I](){return this._hash}[A](e){return _0(e)&&this.name===e.name&&_(this.keyType,e.keyType)&&_(this.description,e.description)&&b0(this.tags,e.tags)}pipe(){return x(this,arguments)}}var _0=(e)=>w(e,$w),Bw=(e,t)=>new lu(e,Lw(t),Br(t?.description));var Kw=(e,t,r)=>new lu(e,Dw(t),Br(r));var Ww=p(2,(e,t)=>t.length===0?e:new lu(e.name,e.keyType,e.description,vn(e.tags,t)));var Vw=Symbol.for("effect/MutableHashMap"),E0={[Vw]:Vw,[Symbol.iterator](){return new Tm(this)},toString(){return ie(this.toJSON())},toJSON(){return{_id:"MutableHashMap",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return x(this,arguments)}};class Tm{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();if(e.done)return this.bucketIterator=new zw(this.self.buckets.values()),this.next();return e}[Symbol.iterator](){return new Tm(this.self)}}class zw{backing;constructor(e){this.backing=e}currentBucket;next(){if(this.currentBucket===void 0){let t=this.backing.next();if(t.done)return t;this.currentBucket=t.value[Symbol.iterator]()}let e=this.currentBucket.next();if(e.done)return this.currentBucket=void 0,this.next();return e}}var Gw=()=>{let e=Object.create(E0);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e};var Gn=p(2,(e,t)=>{if(ws(t)===!1)return e.referential.has(t)?P(e.referential.get(t)):E();let r=t[I](),n=e.buckets.get(r);if(n===void 0)return E();return O0(e,n,t)});var O0=(e,t,r,n=!1)=>{for(let o=0,i=t.length;o<i;o++)if(r[A](t[o][0])){let s=t[o][1];if(n)t.splice(o,1),e.bucketsSize--;return P(s)}return E()},ji=p(2,(e,t)=>pe(Gn(e,t))),$i=p(3,(e,t,r)=>{if(ws(t)===!1)return e.referential.set(t,r),e;let n=t[I](),o=e.buckets.get(n);if(o===void 0)return e.buckets.set(n,[[t,r]]),e.bucketsSize++,e;return v0(e,o,t),o.push([t,r]),e.bucketsSize++,e}),v0=(e,t,r)=>{for(let n=0,o=t.length;n<o;n++)if(r[A](t[n][0])){t.splice(n,1),e.bucketsSize--;return}};var T0="effect/MetricState",ba=Symbol.for(T0),Jw="effect/MetricState/Counter",Im=Symbol.for(Jw),Yw="effect/MetricState/Frequency",km=Symbol.for(Yw),Zw="effect/MetricState/Gauge",Rm=Symbol.for(Zw),Qw="effect/MetricState/Histogram",Cm=Symbol.for(Qw),Xw="effect/MetricState/Summary",Pm=Symbol.for(Xw),_a={_A:(e)=>e};class eE{count;[ba]=_a;[Im]=Im;constructor(e){this.count=e}[I](){return m(b(Jw),K(b(this.count)),Z(this))}[A](e){return k0(e)&&this.count===e.count}pipe(){return x(this,arguments)}}var I0=An(_);class tE{occurrences;[ba]=_a;[km]=km;constructor(e){this.occurrences=e}_hash;[I](){return m(oe(Yw),K(Nt(de(this.occurrences.entries()))),Z(this))}[A](e){return R0(e)&&I0(de(this.occurrences.entries()),de(e.occurrences.entries()))}pipe(){return x(this,arguments)}}class rE{value;[ba]=_a;[Rm]=Rm;constructor(e){this.value=e}[I](){return m(b(Zw),K(b(this.value)),Z(this))}[A](e){return C0(e)&&this.value===e.value}pipe(){return x(this,arguments)}}class nE{buckets;count;min;max;sum;[ba]=_a;[Cm]=Cm;constructor(e,t,r,n,o){this.buckets=e,this.count=t,this.min=r,this.max=n,this.sum=o}[I](){return m(b(Qw),K(b(this.buckets)),K(b(this.count)),K(b(this.min)),K(b(this.max)),K(b(this.sum)),Z(this))}[A](e){return P0(e)&&_(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return x(this,arguments)}}class oE{error;quantiles;count;min;max;sum;[ba]=_a;[Pm]=Pm;constructor(e,t,r,n,o,i){this.error=e,this.quantiles=t,this.count=r,this.min=n,this.max=o,this.sum=i}[I](){return m(b(Xw),K(b(this.error)),K(b(this.quantiles)),K(b(this.count)),K(b(this.min)),K(b(this.max)),K(b(this.sum)),Z(this))}[A](e){return F0(e)&&this.error===e.error&&_(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return x(this,arguments)}}var iE=(e)=>new eE(e),sE=(e)=>new tE(e),aE=(e)=>new rE(e),cE=(e)=>new nE(e.buckets,e.count,e.min,e.max,e.sum),lE=(e)=>new oE(e.error,e.quantiles,e.count,e.min,e.max,e.sum);var k0=(e)=>w(e,Im),R0=(e)=>w(e,km),C0=(e)=>w(e,Rm),P0=(e)=>w(e,Cm),F0=(e)=>w(e,Pm);var M0="effect/MetricHook",L0=Symbol.for(M0),D0={_In:(e)=>e,_Out:(e)=>e},wa=(e)=>({[L0]:D0,pipe(){return x(this,arguments)},...e});var uE=BigInt(0),dE=(e)=>{let t=e.keyType.bigint?uE:0,r=e.keyType.incremental?e.keyType.bigint?(o)=>o>=uE:(o)=>o>=0:(o)=>!0,n=(o)=>{if(r(o))t=t+o};return wa({get:()=>iE(t),update:n,modify:n})},fE=(e)=>{let t=new Map;for(let n of e.keyType.preregisteredWords)t.set(n,0);let r=(n)=>{let o=t.get(n)??0;t.set(n,o+1)};return wa({get:()=>sE(t),update:r,modify:r})},mE=(e,t)=>{let r=t;return wa({get:()=>aE(r),update:(n)=>{r=n},modify:(n)=>{r=r+n}})},hE=(e)=>{let t=e.keyType.boundaries.values,r=t.length,n=new Uint32Array(r+1),o=new Float64Array(r),i=0,s=0,{MAX_VALUE:a,MIN_VALUE:c}=Number;m(t,Wr(Tr),sr((d,f)=>{o[f]=d}));let l=(d)=>{let f=0,h=r;while(f!==h){let g=Math.floor(f+(h-f)/2),O=o[g];if(d<=O)h=g;else f=g;if(h===f+1)if(d<=o[f])h=f;else f=h}if(n[f]=n[f]+1,i=i+1,s=s+d,d<a)a=d;if(d>c)c=d},u=()=>{let d=go(r),f=0;for(let h=0;h<r;h++){let g=o[h],O=n[h];f=f+O,d[h]=[g,f]}return d};return wa({get:()=>cE({buckets:u(),count:i,min:a,max:c,sum:s}),update:l,modify:l})},gE=(e)=>{let{error:t,maxAge:r,maxSize:n,quantiles:o}=e.keyType,i=m(o,Wr(Tr)),s=go(n),a=0,c=0,l=0,u=0,d=0,f=(g)=>{let O=[],S=0;while(S!==n-1){let v=s[S];if(v!=null){let[G,q]=v,j=Kc(g-G);if(Zx(j,Nd)&&Yx(j,r))O.push(q)}S=S+1}return q0(t,i,Wr(O,Tr))},h=(g,O)=>{if(n>0){a=a+1;let S=a%n;s[S]=[O,g]}u=c===0?g:Math.min(u,g),d=c===0?g:Math.max(d,g),c=c+1,l=l+g};return wa({get:()=>lE({error:t,quantiles:f(Date.now()),count:c,min:u,max:d,sum:l}),update:([g,O])=>h(g,O),modify:([g,O])=>h(g,O)})},q0=(e,t,r)=>{let n=r.length;if(!ce(t))return Vr();let o=t[0],i=t.slice(1),s=pE(e,n,E(),0,o,r),a=Xe(s);return i.forEach((c)=>{a.push(pE(e,n,s.value,s.consumed,c,s.rest))}),sr(a,(c)=>[c.quantile,c.value])},pE=(e,t,r,n,o,i)=>{let s=e,a=t,c=r,l=n,u=o,d=i,f=e,h=t,g=r,O=n,S=o,v=i;while(!0){if(!ce(d))return{quantile:u,value:E(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:P(Zp(d)),consumed:l+d.length,rest:[]};let G=Pe(d),q=Dy(d,(F)=>F===G),j=u*a,k=s/2*j,C=l+q[0].length,V=Math.abs(C-j);if(C<j-k){f=s,h=a,g=Kr(d),O=C,S=u,v=q[1],s=f,a=h,c=g,l=O,u=S,d=v;continue}if(C>j+k){let F=Se(c)?P(G):c;return{quantile:u,value:F,consumed:l,rest:d}}switch(c._tag){case"None":{f=s,h=a,g=Kr(d),O=C,S=u,v=q[1],s=f,a=h,c=g,l=O,u=S,d=v;continue}case"Some":{let F=Math.abs(j-c.value);if(V<F){f=s,h=a,g=Kr(d),O=C,S=u,v=q[1],s=f,a=h,c=g,l=O,u=S,d=v;continue}return{quantile:u,value:P(c.value),consumed:l,rest:d}}}}throw Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues")};var H0="effect/MetricPair",j0=Symbol.for(H0),$0={_Type:(e)=>e};var yE=(e,t)=>({[j0]:$0,metricKey:e,metricState:t,pipe(){return x(this,arguments)}});var K0="effect/MetricRegistry",xE=Symbol.for(K0);class SE{[xE]=xE;map=Gw();snapshot(){let e=[];for(let[t,r]of this.map)e.push(yE(t,r.get()));return e}get(e){let t=m(this.map,Gn(e),Ot);if(t==null){if(vm(e.keyType))return this.getCounter(e);if(Uw(e.keyType))return this.getGauge(e);if(qw(e.keyType))return this.getFrequency(e);if(Am(e.keyType))return this.getHistogram(e);if(Hw(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")}else return t}getCounter(e){let t=m(this.map,Gn(e),Ot);if(t==null){let r=dE(e);if(!m(this.map,ji(e)))m(this.map,$i(e,r));t=r}return t}getFrequency(e){let t=m(this.map,Gn(e),Ot);if(t==null){let r=fE(e);if(!m(this.map,ji(e)))m(this.map,$i(e,r));t=r}return t}getGauge(e){let t=m(this.map,Gn(e),Ot);if(t==null){let r=mE(e,e.keyType.bigint?BigInt(0):0);if(!m(this.map,ji(e)))m(this.map,$i(e,r));t=r}return t}getHistogram(e){let t=m(this.map,Gn(e),Ot);if(t==null){let r=hE(e);if(!m(this.map,ji(e)))m(this.map,$i(e,r));t=r}return t}getSummary(e){let t=m(this.map,Gn(e),Ot);if(t==null){let r=gE(e);if(!m(this.map,ji(e)))m(this.map,$i(e,r));t=r}return t}}var bE=()=>new SE;var V0="effect/Metric",z0=Symbol.for(V0),G0={_Type:(e)=>e,_In:(e)=>e,_Out:(e)=>e},_E=U(Symbol.for("effect/Metric/globalMetricRegistry"),()=>bE()),wE=function(e,t,r,n){let o=Object.assign((i)=>gl(i,(s)=>Y0(o,s)),{[z0]:G0,keyType:e,unsafeUpdate:t,unsafeValue:r,unsafeModify:n,register(){return this.unsafeValue([]),this},pipe(){return x(this,arguments)}});return o};var Ea=(e,t)=>EE(Bw(e,t));var EE=(e)=>{let t,r=new WeakMap,n=(o)=>{if(o.length===0){if(t!==void 0)return t;return t=_E.get(e),t}let i=r.get(o);if(i!==void 0)return i;return i=_E.get(Ww(e,o)),r.set(o,i),i};return wE(e.keyType,(o,i)=>n(i).update(o),(o)=>n(o).get(),(o,i)=>n(i).modify(o))};var OE=(e,t,r)=>EE(Kw(e,t,r));var vE=p(3,(e,t,r)=>J0(e,[mw(t,r)]));var J0=p(2,(e,t)=>wE(e.keyType,(r,n)=>e.unsafeUpdate(r,vn(t,n)),(r)=>e.unsafeValue(vn(t,r)),(r,n)=>e.unsafeModify(r,vn(t,n))));var Y0=p(2,(e,t)=>Fo(la,(r)=>M(()=>e.unsafeUpdate(t,r))));var Q0="effect/Request",X0=Symbol.for(Q0),eF={_E:(e)=>e,_A:(e)=>e},zH={...Is,[X0]:eF};var AE=p(2,(e,t)=>Fo(ou,(r)=>M(()=>{if(r.has(e)){let n=r.get(e);if(!n.state.completed)n.state.completed=!0,Il(n.result,t)}})));var tF="effect/Supervisor",uu=Symbol.for(tF),Fm={_T:(e)=>e};class pu{underlying;value0;[uu]=Fm;constructor(e,t){this.underlying=e,this.value0=t}get value(){return this.value0}onStart(e,t,r,n){this.underlying.onStart(e,t,r,n)}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(e){return new pu(this,m(this.value,Oe(e)))}zip(e){return new du(this,e)}}class du{left;right;_tag="Zip";[uu]=Fm;constructor(e,t){this.left=e,this.right=t}get value(){return xl(this.left.value,this.right.value)}onStart(e,t,r,n){this.left.onStart(e,t,r,n),this.right.onStart(e,t,r,n)}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 pu(this,m(this.value,Oe(e)))}zip(e){return new du(this,e)}}var Nm=(e)=>w(e,uu)&&bs(e,"Zip");class TE{effect;[uu]=Fm;constructor(e){this.effect=e}get value(){return this.effect}onStart(e,t,r,n){}onEnd(e,t){}onEffect(e,t){}onSuspend(e){}onResume(e){}map(e){return new pu(this,m(this.value,Oe(e)))}zip(e){return new du(this,e)}onRun(e,t){return e()}}var rF=(e)=>new TE(e),jo=U("effect/Supervisor/none",()=>rF(Ne));var IE=Dn;var kE="Empty",RE="AddSupervisor",CE="RemoveSupervisor",PE="AndThen",Bi={_tag:kE},fu=(e,t)=>({_tag:PE,first:e,second:t}),oF=(e,t)=>iF(t,Fe(e)),iF=(e,t)=>{let r=e,n=t;while(ar(n)){let o=cr(n);switch(o._tag){case kE:{n=lr(n);break}case RE:{r=r.zip(o.supervisor),n=lr(n);break}case CE:{r=Lm(r,o.supervisor),n=lr(n);break}case PE:{n=et(o.first)(et(o.second)(lr(n)));break}}}return r},Lm=(e,t)=>{if(_(e,t))return jo;else if(Nm(e))return Lm(e.left,t).zip(Lm(e.right,t));else return e},mu=(e)=>{if(_(e,jo))return wr();else if(Nm(e))return m(mu(e.left),Zr(mu(e.right)));else return bo(e)},sF=(e,t)=>{if(_(e,t))return Bi;let r=mu(e),n=mu(t),o=m(n,hd(r),wo(Bi,(s,a)=>fu(s,{_tag:RE,supervisor:a}))),i=m(r,hd(n),wo(Bi,(s,a)=>fu(s,{_tag:CE,supervisor:a})));return fu(o,i)},FE=IE({empty:Bi,patch:oF,combine:fu,diff:sF});var gF=Ea("effect_fiber_started",{incremental:!0}),NE=Ea("effect_fiber_active"),yF=Ea("effect_fiber_successes",{incremental:!0}),xF=Ea("effect_fiber_failures",{incremental:!0}),SF=vE(OE("effect_fiber_lifetimes",kw({start:0.5,factor:2,count:35})),"time_unit","milliseconds"),Oa="Continue",bF="Done",ME="Yield",_F={_E:(e)=>e,_A:(e)=>e},hu=(e)=>{throw Error(`BUG: FiberRuntime - ${jr(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},an=Symbol.for("effect/internal/fiberRuntime/YieldedOp"),cn=U("effect/internal/fiberRuntime/yieldedOpChannel",()=>({currentOp:null})),va={[oi]:(e,t,r)=>Ve(()=>t.effect_instruction_i1(r)),["OnStep"]:(e,t,r)=>xe(xe(r)),[ii]:(e,t,r)=>Ve(()=>t.effect_instruction_i2(r)),[As]:(e,t,r)=>{if(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),rn(e.currentRuntimeFlags)&&e.isInterrupted())return le(e.getInterruptedCause());else return xe(r)},[si]:(e,t,r)=>{if(Ve(()=>t.effect_instruction_i2(r)),Ve(()=>t.effect_instruction_i0()))return e.pushStack(t),Ve(()=>t.effect_instruction_i1());else return Ne},[ai]:(e,t,r)=>{while(!0){let n=Ve(()=>t.effect_instruction_i0.next(r));if(n.done)return xe(n.value);let o=kp(n.value);if(!Fi(o))return e.pushStack(t),o;else if(o._tag==="Failure")return o;r=o.value}}},wF={[gm]:(e,t,r,n)=>(e.processNewInterruptSignal(n.cause),rn(t)?le(n.cause):r),[xm]:(e,t,r,n)=>{throw Error("It is illegal to have multiple concurrent run loops in a single fiber")},[ym]:(e,t,r,n)=>(n.onFiber(e,tm(t)),r),[Sm]:(e,t,r,n)=>H(sa(),()=>r)},EF=(e)=>Co(qS(e),(t)=>$o(HS(t),([r,n])=>{let o=new Map,i=[];for(let a of n){i.push(Gr(a));for(let c of a)o.set(c.request,c)}let s=i.flat();return Bn(qF(r.runAll(i),s,()=>s.forEach((a)=>{a.listeners.interrupted=!0})),ou,o)},!1,!1)),OF=Ts();class gu extends Wf{[bm]=_m;[ww]=_F;_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,r){super();if(this.currentRuntimeFlags=r,this._fiberId=e,this._fiberRefs=t,lf(r)){let n=this.getFiberRef(la);gF.unsafeUpdate(1,n),NE.unsafeUpdate(1,n)}this.refreshRefCache()}commit(){return au(this)}id(){return this._fiberId}resume(e){this.tell(Uo(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>{if(W_(t))return e.currentRuntimeFlags;return t.runtimeFlags})}scope(){return bw(this)}get children(){return this.ask((e)=>Array.from(e.getChildren()))}getChildren(){if(this._children===null)this._children=new Set;return this._children}getInterruptedCause(){return this.getFiberRef(ua)}fiberRefs(){return this.ask((e)=>e.getFiberRefs())}ask(e){return fe(()=>{let t=_b(this._fiberId);return this.tell(Hi((r,n)=>{Il(t,M(()=>e(r,n)))})),Tl(t)})}tell(e){if(this._queue.push(e),!this._running)this._running=!0,this.drainQueueLaterOnExecutor()}get await(){return Un((e)=>{let t=(r)=>e(ne(r));if(this._exitValue!==null){t(this._exitValue);return}return this.tell(Hi((r,n)=>{if(r._exitValue!==null)t(this._exitValue);else r.addObserver(t)})),M(()=>this.tell(Hi((r,n)=>{r.removeObserver(t)})))},this.id())}get inheritAll(){return ze((e,t)=>{let r=e.id(),n=e.getFiberRefs(),o=t.runtimeFlags,i=this.getFiberRefs(),s=Zf(n,r,i);e.setFiberRefs(s);let a=e.getFiberRef(DE),c=m(Qs(o,a),ff(tn),ff(ol));return kf(c)})}get poll(){return M(()=>Br(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return M(()=>this.tell(iu(ur(e))))}unsafeInterruptAsFork(e){this.tell(iu(ur(e)))}addObserver(e){if(this._exitValue!==null)e(this._exitValue);else this._observers.push(e)}removeObserver(e){this._observers=this._observers.filter((t)=>t!==e)}getFiberRefs(){return this.setFiberRef(DE,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=ya(this._fiberRefs,e)}getFiberRef(e){if(this._fiberRefs.locals.has(e))return this._fiberRefs.locals.get(e)[0][1];return e.initial}setFiberRef(e,t){this._fiberRefs=Di(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(ga),this.currentTracer=this.currentDefaultServices.unsafeMap.get(ha.key),this.currentSupervisor=this.getFiberRef(DF),this.currentScheduler=this.getFiberRef(nu),this.currentContext=this.getFiberRef(Mo),this.currentSpan=this.currentContext.unsafeMap.get($l.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 r of t)if(r._exitValue===null)e.add(this.currentRuntimeFlags,r)}}drainQueueOnCurrentThread(){let e=!0;while(e){let t=Oa,r=globalThis[zn];globalThis[zn]=this;try{while(t===Oa)t=this._queue.length===0?bF:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[zn]=r}if(this._queue.length>0&&!this._running)if(this._running=!0,t===ME)this.drainQueueLaterOnExecutor(),e=!1;else e=!0;else e=!1}}drainQueueLaterOnExecutor(){this.currentScheduler.scheduleTask(this.run,this.getFiberRef(Ci),this)}drainQueueWhileRunning(e,t){let r=t;while(this._queue.length>0){let n=this._queue.splice(0,1)[0];r=wF[n._tag](this,e,r,n)}return r}isInterrupted(){return!qc(this.getFiberRef(ua))}addInterruptedCause(e){let t=this.getFiberRef(ua);this.setFiberRef(ua,tt(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(iu(ur(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return ia({while:()=>!t,body:()=>{let n=e.next();if(!n.done)return on(n.value.await);else return M(()=>{t=!0})},step:()=>{}})}return null}reportExitValue(e){if(lf(this.currentRuntimeFlags)){let t=this.getFiberRef(la),r=this.id().startTimeMillis,n=Date.now();switch(SF.unsafeUpdate(n-r,t),NE.unsafeUpdate(-1,t),e._tag){case Et:{yF.unsafeUpdate(1,t);break}case wt:{xF.unsafeUpdate(1,t);break}}}if(e._tag==="Failure"){let t=this.getFiberRef(yb);if(!_i(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(kF)}log(e,t,r){let n=pe(r)?r.value:this.getFiberRef(Nf),o=this.getFiberRef(vF);if(V_(o,n))return;let i=this.getFiberRef(fb),s=this.getFiberRef(db),a=this.getLoggers(),c=this.getFiberRefs();if(Ls(a)>0){let l=Hs(this.getFiberRef(ga),ma),u=new Date(l.unsafeCurrentTimeMillis());iy(c,()=>{for(let d of a)d.log({fiberId:this.id(),logLevel:n,message:e,cause:t,context:c,spans:i,annotations:s,date:u})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case Sm:return ME;case gm:{if(this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null)this._asyncInterruptor(le(e.cause)),this._asyncInterruptor=null;return Oa}case xm:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),Oa;case ym:return e.onFiber(this,this._exitValue!==null?B_:K_(this.currentRuntimeFlags,this._asyncBlockingOn)),Oa;default:return hu(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=rn(this.currentRuntimeFlags)&&this.isInterrupted()?le(this.getInterruptedCause()):e;while(t!==null){let r=t,n=this.runLoop(r);if(n===an){let o=cn.currentOp;if(cn.currentOp=null,o._op===ci)if(NS(this.currentRuntimeFlags))this.tell(gw()),this.tell(Uo(Jt)),t=null;else t=Jt;else if(o._op===fo)t=null}else{this.currentRuntimeFlags=m(this.currentRuntimeFlags,sf(ol));let o=this.interruptAllChildren();if(o!==null)t=H(o,()=>n);else{if(this._queue.length===0)this.setExitValue(n);else this.tell(Uo(n));t=null}}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(!this._running){this._running=!0;let t=globalThis[zn];globalThis[zn]=this;try{this.evaluateEffect(e)}finally{if(this._running=!1,globalThis[zn]=t,this._queue.length>0)this.drainQueueLaterOnExecutor()}}else this.tell(Uo(e))}startFork(e){this.tell(Uo(e))}patchRuntimeFlags(e,t){let r=Xs(e,t);return globalThis[zn]=this,this.currentRuntimeFlags=r,r}initiateAsync(e,t){let r=!1,n=(o)=>{if(!r)r=!0,this.tell(Uo(o))};if(rn(e))this._asyncInterruptor=n;try{t(n)}catch(o){n(rt(Lt(o)))}}pushStack(e){if(this._stack.push(e),e._op==="OnStep")this._steps.push({refs:this.getFiberRefs(),flags:this.currentRuntimeFlags})}popStack(){let e=this._stack.pop();if(e){if(e._op==="OnStep")this._steps.pop();return e}return}getNextSuccessCont(){let e=this.popStack();while(e){if(e._op!==vs)return e;e=this.popStack()}}getNextFailCont(){let e=this.popStack();while(e){if(e._op!==oi&&e._op!==si&&e._op!==ai)return e;e=this.popStack()}}[ay](e){return M(()=>js(this.currentContext,e))}["Left"](e){return $e(e.left)}["None"](e){return $e(new pa)}["Right"](e){return xe(e.right)}["Some"](e){return xe(e.value)}["Micro"](e){return ea((t)=>{let r=t,n=aw(ow(e,this.currentContext));return n.addObserver((o)=>{if(o._tag==="Success")return r(xe(o.value));switch(o.cause._tag){case"Interrupt":return r(le(ur(Vt)));case"Fail":return r($e(o.cause.error));case"Die":return r(fl(o.cause.defect))}}),ea((o)=>{r=(i)=>{o(Ne)},n.unsafeInterrupt()})})}[hc](e){let t=Ve(()=>e.effect_instruction_i0()),r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in va))hu(r);return va[r._op](this,r,t)}else return cn.currentOp=xe(t),an}[Et](e){let t=e,r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in va))hu(r);return va[r._op](this,r,t.effect_instruction_i0)}else return cn.currentOp=t,an}[wt](e){let t=e.effect_instruction_i0,r=this.getNextFailCont();if(r!==void 0)switch(r._op){case vs:case ii:if(!(rn(this.currentRuntimeFlags)&&this.isInterrupted()))return Ve(()=>r.effect_instruction_i1(t));else return le(jc(t));case"OnStep":if(!(rn(this.currentRuntimeFlags)&&this.isInterrupted()))return xe(le(t));else return le(jc(t));case As:if(this.patchRuntimeFlags(this.currentRuntimeFlags,r.patch),rn(this.currentRuntimeFlags)&&this.isInterrupted())return le(tt(t,this.getInterruptedCause()));else return le(t);default:hu(r)}else return cn.currentOp=le(t),an}[gc](e){return Ve(()=>e.effect_instruction_i0(this,tm(this.currentRuntimeFlags)))}["Blocked"](e){let t=this.getFiberRefs(),r=this.currentRuntimeFlags;if(this._steps.length>0){let n=[],o=this._steps[this._steps.length-1],i=this.popStack();while(i&&i._op!=="OnStep")n.push(i),i=this.popStack();this.setFiberRefs(o.refs),this.currentRuntimeFlags=o.flags;let s=P_(o.refs,t),a=Qs(o.flags,r);return xe(pl(e.effect_instruction_i0,ze((c)=>{while(n.length>0)c.pushStack(n.pop());return c.setFiberRefs(F_(c.id(),c.getFiberRefs())(s)),c.currentRuntimeFlags=Xs(a)(c.currentRuntimeFlags),e.effect_instruction_i1})))}return jn((n)=>H(Hm(Sf(e.effect_instruction_i0)),()=>n(e.effect_instruction_i1)))}["RunBlocked"](e){return EF(e.effect_instruction_i0)}[ho](e){let t=e.effect_instruction_i0,r=this.currentRuntimeFlags,n=Xs(r,t);if(rn(n)&&this.isInterrupted())return le(this.getInterruptedCause());else if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let o=Qs(n,r);return this.pushStack(new bf(o,e)),Ve(()=>e.effect_instruction_i1(r))}else return Jt}[oi](e){return this.pushStack(e),e.effect_instruction_i0}["OnStep"](e){return this.pushStack(e),e.effect_instruction_i0}[vs](e){return this.pushStack(e),e.effect_instruction_i0}[ii](e){return this.pushStack(e),e.effect_instruction_i0}[fo](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),cn.currentOp=e,an}[ci](e){return this._isYielding=!1,cn.currentOp=e,an}[si](e){let{effect_instruction_i0:t,effect_instruction_i1:r}=e;if(t())return this.pushStack(e),r();else return Jt}[ai](e){return va[ai](this,e,void 0)}[mo](e){return Ve(()=>e.commit())}runLoop(e){let t=e;this.currentOpCount=0;while(!0){if((this.currentRuntimeFlags&FS)!==0)this.currentSupervisor.onEffect(this,t);if(this._queue.length>0)t=this.drainQueueWhileRunning(this.currentRuntimeFlags,t);if(!this._isYielding){this.currentOpCount+=1;let r=this.currentScheduler.shouldYield(this);if(r!==!1){this._isYielding=!0,this.currentOpCount=0;let n=t;t=H(sa({priority:r}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(OF!==t[qn]._V){let r=this.getFiberRef(xb);if(r._tag==="Some"){let n=t[qn]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${Ts()}, 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`,Qr,r)}}return this[t._op](t)},this),t===an){let r=cn.currentOp;if(r._op===ci||r._op===fo)return an;return cn.currentOp=null,r._op===Et||r._op===wt?r:le(Lt(r))}}catch(r){if(t!==an&&!w(t,"_op")||!(t._op in this))t=Of(`Not a valid effect: ${jr(t)}`);else if(Sb(r))t=le(tt(Lt(r),ur(Vt)));else t=fl(r)}}}run=()=>{this.drainQueueOnCurrentThread()}}var vF=U("effect/FiberRef/currentMinimumLogLevel",()=>Ge(z_("Info"))),AF=(e)=>cu((t)=>{let r=b_(t.context,ga);Hs(r,jl).unsafe.log(e.log(t))});var TF=U(Symbol.for("effect/Logger/defaultLogger"),()=>AF(vw));var IF=U(Symbol.for("effect/Logger/tracerLogger"),()=>cu(({annotations:e,cause:t,context:r,fiberId:n,logLevel:o,message:i})=>{let s=hm(Mn(Wn(r,Mo),$l));if(s._tag==="None"||s.value._tag==="ExternalSpan")return;let a=js(Wn(r,ga),ma),c={};for(let[l,u]of e)c[l]=u;if(c["effect.fiberId"]=aS(n),c["effect.logLevel"]=o.label,t!==null&&t._tag!=="Empty")c["effect.cause"]=pr(t,{renderErrorCause:!0});s.value.event(jr(Array.isArray(i)&&i.length===1?i[0]:i),a.unsafeCurrentTimeNanos(),c)}));var kF=U(Symbol.for("effect/FiberRef/currentLoggers"),()=>ub(bo(TF,IF)));var qE=p((e)=>vp(e[0]),(e,t,r)=>ze((n)=>{let o=r?.batching===!0||r?.batching==="inherit"&&n.getFiberRef(gb);if(r?.discard)return dm(r.concurrency,()=>Ki(Bl,r?.concurrentFinalizers)((i)=>o?$o(e,(s,a)=>i(t(s,a)),!0,!1,1):Co(e,(s,a)=>i(t(s,a)))),()=>Ki(Kl,r?.concurrentFinalizers)((i)=>$o(e,(s,a)=>i(t(s,a)),o,!1)),(i)=>Ki(Wl(i),r?.concurrentFinalizers)((s)=>$o(e,(a,c)=>s(t(a,c)),o,!1,i)));return dm(r?.concurrency,()=>Ki(Bl,r?.concurrentFinalizers)((i)=>o?Dm(e,1,(s,a)=>i(t(s,a)),!0):Gt(e,(s,a)=>i(t(s,a)))),()=>Ki(Kl,r?.concurrentFinalizers)((i)=>UE(e,(s,a)=>i(t(s,a)),o)),(i)=>Ki(Wl(i),r?.concurrentFinalizers)((s)=>Dm(e,i,(a,c)=>s(t(a,c)),o)))})),UE=(e,t,r)=>fe(()=>{let n=de(e),o=Array(n.length);return $n($o(n,(s,a)=>H(t(s,a),(c)=>M(()=>o[a]=c)),r,!1),ne(o))}),$o=(e,t,r,n,o)=>jn((i)=>If((s)=>ze((a)=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return Ne;let u=0,d=!1,f=o?Math.min(c.length,o):c.length,h=new Set,g=[],O=()=>h.forEach((F)=>{F.currentScheduler.scheduleTask(()=>{F.unsafeInterruptAsFork(a.id())},0,F)}),S=[],v=[],G=[],q=()=>{let F=g.filter(({exit:ee})=>ee._tag==="Failure").sort((ee,X)=>ee.index<X.index?-1:ee.index===X.index?0:1).map(({exit:ee})=>ee);if(F.length===0)F.push(Jt);return F},j=(F,ee=!1)=>{let X=yl(s(F)),J=CF(X,a,a.currentRuntimeFlags,Sa);return a.currentScheduler.scheduleTask(()=>{if(ee)J.unsafeInterruptAsFork(a.id());J.resume(X)},0,J),J},k=()=>{if(!n)l-=c.length,c=[];d=!0,O()},C=r?Tf:Hn,V=j(Un((F)=>{let ee=(J,he)=>{if(J._op==="Blocked")G.push(J);else if(g.push({index:he,exit:J}),J._op==="Failure"&&!d)k()},X=()=>{if(c.length>0){let J=c.pop(),he=u++,lt=()=>{let ke=c.pop();return he=u++,H(sa(),()=>H(C(i(t(ke,he))),Ze))},Ze=(ke)=>{if(c.length>0){if(ee(ke,he),c.length>0)return lt()}return ne(ke)},ut=H(C(i(t(J,he))),Ze),Me=j(ut);if(S.push(Me),h.add(Me),d)Me.currentScheduler.scheduleTask(()=>{Me.unsafeInterruptAsFork(a.id())},0,Me);Me.addObserver((ke)=>{let pt;if(ke._op==="Failure")pt=ke;else pt=ke.effect_instruction_i0;if(v.push(Me),h.delete(Me),ee(pt,he),g.length===l)F(ne(ue(Do(q(),{parallel:!0}),()=>Jt)));else if(G.length+g.length===l){let Lr=q(),is=G.map((to)=>to.effect_instruction_i0).reduce(hf);F(ne(pl(is,$o([ue(Do(Lr,{parallel:!0}),()=>Jt),...G.map((to)=>to.effect_instruction_i1)],(to)=>to,r,!0,o))))}else X()})}};for(let J=0;J<f;J++)X()}));return on(Ri(na(i(au(V))),Al({onFailure:(F)=>{k();let ee=G.length+1,X=Math.min(typeof o==="number"?o:G.length,G.length),J=Array.from(G);return Un((he)=>{let lt=[],Ze=0,ut=0,Me=(pt,Lr)=>(is)=>{if(lt[pt]=is,Ze++,Ze===ee)he(xe(le(F)));if(J.length>0&&Lr)ke()},ke=()=>{j(J.pop(),!0).addObserver(Me(ut,!0)),ut++};V.addObserver(Me(ut,!1)),ut++;for(let pt=0;pt<X;pt++)ke()})},onSuccess:()=>Gt(v,(F)=>F.inheritAll)})))}))),Dm=(e,t,r,n)=>fe(()=>{let o=de(e),i=Array(o.length);return $n($o(o,(a,c)=>Oe(r(a,c),(l)=>i[c]=l),n,!1,t),ne(i))});var Hm=(e)=>PF(e,Sa);var RF=(e,t,r,n=null)=>{let o=HE(e,t,r,n);return o.resume(e),o},CF=(e,t,r,n=null)=>HE(e,t,r,n),HE=(e,t,r,n=null)=>{let o=Zc(),i=t.getFiberRefs(),s=Qf(i,o),a=new gu(o,s,r),c=Wn(s,Mo),l=a.currentSupervisor;return l.onStart(c,e,P(t),a),a.addObserver((d)=>l.onEnd(d,a)),(n!==null?n:m(t.getFiberRef(ul),ue(()=>t.scope()))).add(r,a),a},PF=(e,t)=>ze((r,n)=>ne(RF(e,r,n.runtimeFlags,t)));var qm=(e)=>qo((t)=>Ae(Mn(t,Aa),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Parallel":return e;case"Sequential":case"ParallelN":return H(Pi(r,Kl),(n)=>jm(e,n))}}})),LE=(e)=>(t)=>qo((r)=>Ae(Mn(r,Aa),{onNone:()=>t,onSome:(n)=>{if(n.strategy._tag==="ParallelN"&&n.strategy.parallelism===e)return t;return H(Pi(n,Wl(e)),(o)=>jm(t,o))}}));var Ki=(e,t)=>(r)=>qo((n)=>Ae(Mn(n,Aa),{onNone:()=>r(te),onSome:(o)=>{if(t===!0){let i=e._tag==="Parallel"?qm:e._tag==="Sequential"?Um:LE(e.parallelism);switch(o.strategy._tag){case"Parallel":return i(r(qm));case"Sequential":return i(r(Um));case"ParallelN":return i(r(LE(o.strategy.parallelism)))}}else return r(te)}}));var Um=(e)=>qo((t)=>Ae(Mn(t,Aa),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Sequential":return e;case"Parallel":case"ParallelN":return H(Pi(r,Bl),(n)=>jm(e,n))}}}));var Aa=vt("effect/Scope");var FF=(e,t)=>{if(e.state._tag==="Open")e.state.finalizers.set({},t)},NF={[wl]:wl,[El]:El,pipe(){return x(this,arguments)},fork(e){return M(()=>{let t=MF(e);if(this.state._tag==="Closed")return t.state=this.state,t;let r={},n=(o)=>t.close(o);return this.state.finalizers.set(r,n),FF(t,(o)=>M(()=>{if(this.state._tag==="Open")this.state.finalizers.delete(r)})),t})},close(e){return fe(()=>{if(this.state._tag==="Closed")return Ne;let t=Array.from(this.state.finalizers.values()).reverse();if(this.state={_tag:"Closed",exit:e},t.length===0)return Ne;return Vf(this.strategy)?m(Gt(t,(r)=>Hn(r(e))),H((r)=>m(Do(r),nr(da),ue(()=>Jt)))):zf(this.strategy)?m(UE(t,(r)=>Hn(r(e)),!1),H((r)=>m(Do(r,{parallel:!0}),nr(da),ue(()=>Jt)))):m(Dm(t,this.strategy.parallelism,(r)=>Hn(r(e)),!1),H((r)=>m(Do(r,{parallel:!0}),nr(da),ue(()=>Jt))))})},addFinalizer(e){return fe(()=>{if(this.state._tag==="Closed")return e(this.state.exit);return this.state.finalizers.set({},e),Ne})}},MF=(e=Li)=>{let t=Object.create(NF);return t.strategy=e,t.state={_tag:"Open",finalizers:new Map},t};var jm=p(2,(e,t)=>Hf(e,$s(Bx(Aa,t))));var LF=(e)=>No(e,{differ:FE,fork:Bi});var DE=pb(MS),DF=LF(jo);var jE=p(2,(e,t)=>jn((r)=>zt(r(e),{onFailure:(n)=>zt(t,{onFailure:(o)=>rt(tt(n,o)),onSuccess:()=>rt(n)}),onSuccess:(n)=>nn(t,n)}))),qF=(e,t,r)=>ra((n)=>jE(H(Hm(ml(e)),(o)=>Un((i)=>{let s=t.map((l)=>l.listeners.count),a=()=>{if(s.every((l)=>l===0)){if(t.every((l)=>{if(l.result.state.current._tag==="Pending")return!0;else if(l.result.state.current._tag==="Done"&&Fi(l.result.state.current.effect)&&l.result.state.current.effect._tag==="Failure"&&Uc(l.result.state.current.effect.cause))return!0;else return!1}))c.forEach((l)=>l()),r?.(),i(ob(o))}};o.addObserver((l)=>{c.forEach((u)=>u()),i(l)});let c=t.map((l,u)=>{let d=(f)=>{s[u]=f,a()};return l.listeners.addObserver(d),()=>l.listeners.removeObserver(d)});return a(),M(()=>{c.forEach((l)=>l())})})),fe(()=>{let o=t.flatMap((i)=>{if(!i.state.completed)return[i];return[]});return Co(o,(i)=>AE(i.request,qf(n)))})));var BE=Mf;var KE=Pi;var Bm=(e)=>function(){if(arguments.length===1){let t=arguments[0];return(r,...n)=>e(t,r,...n)}return e.apply(this,arguments)},WE=Bm((e,t,r)=>{let n=Zc(),o=[[Mo,[[n,e.context]]]];if(r?.scheduler)o.push([nu,[[n,r.scheduler]]]);let i=__(e.fiberRefs,{entries:o,forkAs:n});if(r?.updateRefs)i=r.updateRefs(i,n);let s=new gu(n,i,e.runtimeFlags),a=t;if(r?.scope)a=H(KE(r.scope,Li),(l)=>$n(Ol(l,ra((u)=>_(u,s.id())?Ne:ca(s,u))),Ri(t,(u)=>BE(l,u))));let c=s.currentSupervisor;if(c!==jo)c.onStart(e.context,a,E(),s),s.addObserver((l)=>c.onEnd(l,s));if(Sa.add(e.runtimeFlags,s),r?.immediate===!1)s.resume(a);else s.start(a);return s});var $F=Bm((e,t)=>{let r=VF(e)(t);if(r._tag==="Failure")throw KF(r.effect_instruction_i0);return r.effect_instruction_i0});class VE 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}}var BF=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new VE(e);return Error.stackTraceLimit=t,r};var $m=Symbol.for("effect/Runtime/FiberFailure"),yu=Symbol.for("effect/Runtime/FiberFailure/Cause");class zE extends Error{[$m];[yu];constructor(e){let t=Ds(e)[0];super(t?.message||"An error has occurred");if(this[$m]=$m,this[yu]=e,this.name=t?`(FiberFailure) ${t.name}`:"FiberFailure",t?.stack)this.stack=t.stack}toJSON(){return{_id:"FiberFailure",cause:this[yu].toJSON()}}toString(){return"(FiberFailure) "+pr(this[yu],{renderErrorCause:!0})}[Y](){return this.toString()}}var KF=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new zE(e);return Error.stackTraceLimit=t,r};var WF=(e)=>{let t=e;switch(t._op){case"Failure":case"Success":return t;case"Left":return fa(t.left);case"Right":return xe(t.right);case"Some":return xe(t.value);case"None":return fa(new pa)}},VF=Bm((e,t)=>{let r=WF(t);if(r)return r;let n=new xa,o=WE(e)(t,{scheduler:n});n.flush();let i=o.unsafePoll();if(i)return i;return Df(dl(BF(o),kl(o)))});class GE{context;runtimeFlags;fiberRefs;constructor(e,t,r){this.context=e,this.runtimeFlags=t,this.fiberRefs=r}pipe(){return x(this,arguments)}}var zF=(e)=>new GE(e.context,e.runtimeFlags,e.fiberRefs);var GF=cf(tn,of,nf),JE=zF({context:Nn(),runtimeFlags:GF,fiberRefs:w_()});var YE=WE(JE);var ZE=$F(JE);var QE=Ii;var Ta=qE;var Ia=fe;var qt=Ne;var XE=ta;var xu=Oe;var eO=Po;var Bo=Ro;var fr=H;var tO=YE;var rO=ZE;var Km=(e,t)=>{switch(t._tag){case"StringKeyword":case"TemplateLiteral":return Object.keys(e);case"SymbolKeyword":return Object.getOwnPropertySymbols(e);case"Refinement":return Km(e,t.from)}},ka=(e)=>{let t=!1,r;return()=>{if(t)return r;return r=e(),t=!0,r}},Wm=(e)=>Array.isArray(e),oO=(e)=>!Array.isArray(e),nO=(e)=>`[${Os(e)}]`,Su=(e)=>Wm(e)?e.map(nO).join(""):nO(e);var Jn=(e,t,r,n)=>{let o=e;if(r&&ce(r))o+=`
|
|
34
|
-
at path: ${
|
|
33
|
+
`)}`;super(i);this._tag=e,this.traces=r,this[Q_]=OP,this.name=o,this.stack=s}pipe(){return b(this,arguments)}toString(){return this.stack}[Y](){return this.stack}}class tw extends sm{defect;constructor(e,t=[]){super("Die",e,t);this.defect=e}}var vP=(e,t=[])=>new tw(e,t);class rw extends sm{constructor(e=[]){super("Interrupt","interrupted",e)}}var AP=(e=[])=>new rw(e);var TP=(e)=>e._tag==="Interrupt";var X_=Symbol.for("effect/Micro/MicroFiber"),IP={_A:te,_E:te};class nw{context;interruptible;[X_];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[X_]=IP}getRef(e){return $x(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),gs;return this._observers.push(e),()=>{let t=this._observers.indexOf(e);if(t>=0)this._observers.splice(t,1)}}_interrupted=!1;unsafeInterrupt(){if(this._exit)return;if(this._interrupted=!0,this.interruptible)this.evaluate(pm)}unsafePoll(){return this._exit}evaluate(e){if(this._exit)return;else if(this._yielded!==void 0){let n=this._yielded;this._yielded=void 0,n()}let t=this.runLoop(e);if(t===Xl)return;let r=ew.interruptChildren&&ew.interruptChildren(this);if(r!==void 0)return this.evaluate(ru(r,()=>t));this._exit=t;for(let n=0;n<this._observers.length;n++)this._observers[n](t);this._observers.length=0}runLoop(e){let t=!1,r=e;this.currentOpCount=0;try{while(!0){if(this.currentOpCount++,!t&&this.getRef(ou).shouldYield(this)){t=!0;let n=r;r=ru(NP,()=>n)}if(r=r[om](this),r===Xl){let n=this._yielded;if(eu in n)return this._yielded=void 0,n;return Xl}}}catch(n){if(!v(r,om))return im(`MicroFiber.runLoop: Not a valid effect: ${String(r)}`);return im(n)}}getCont(e){while(!0){let t=this._stack.pop();if(!t)return;let r=t[tu]&&t[tu](this);if(r)return{[e]:r};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,Xl}children(){return this._children??=new Set}}var ew=B("effect/Micro/fiberMiddleware",()=>({interruptChildren:void 0}));var ow=Symbol.for("effect/Micro/identifier"),De=Symbol.for("effect/Micro/args"),om=Symbol.for("effect/Micro/evaluate"),ji=Symbol.for("effect/Micro/successCont"),Hi=Symbol.for("effect/Micro/failureCont"),tu=Symbol.for("effect/Micro/ensureCont"),Xl=Symbol.for("effect/Micro/Yield"),RP={_A:te,_E:te,_R:te},kP={...m_,_op:"Micro",[EP]:RP,pipe(){return b(this,arguments)},[Symbol.iterator](){return new ii(new Hr(this))},toJSON(){return{_id:"Micro",op:this[ow],...De in this?{args:this[De]}:void 0}},toString(){return se(this)},[Y](){return se(this)}};function CP(e){return im("Micro.evaluate: Not implemented")}var nu=(e)=>({...kP,[ow]:e.op,[om]:e.eval??CP,[ji]:e.contA,[Hi]:e.contE,[tu]:e.ensure}),am=(e)=>{let t=nu(e);return function(){let r=Object.create(t);return r[De]=e.single===!1?arguments:arguments[0],r}},iw=(e)=>{let t={...nu(e),[eu]:eu,_tag:e.op,get[e.prop](){return this[De]},toJSON(){return{_id:"MicroExit",_tag:e.op,[e.prop]:this[De]}},[R](r){return LP(r)&&r._tag===e.op&&E(this[De],r[De])},[P](){return Z(this,V(ie(e.op))(w(this[De])))}};return function(r){let n=Object.create(t);return n[De]=r,n[ji]=void 0,n[Hi]=void 0,n[tu]=void 0,n}},cm=iw({op:"Success",prop:"value",eval(e){let t=e.getCont(ji);return t?t[ji](this[De],e):e.yieldWith(this)}}),sw=iw({op:"Failure",prop:"cause",eval(e){let t=e.getCont(Hi);while(TP(this[De])&&t&&e.interruptible)t=e.getCont(Hi);return t?t[Hi](this[De],e):e.yieldWith(this)}});var PP=am({op:"Yield",eval(e){let t=!1;return e.getRef(ou).scheduleTask(()=>{if(t)return;e.evaluate(DP)},this[De]??0),e.yieldWith(()=>{t=!0})}}),NP=PP(0);var FP=cm(void 0);var lm=am({op:"WithMicroFiber",eval(e){return this[De](e)}});var ru=p(2,(e,t)=>{let r=Object.create(MP);return r[De]=e,r[ji]=t,r}),MP=nu({op:"OnSuccess",eval(e){return e._stack.push(this),this[De]}});var LP=(e)=>v(e,eu),aw=cm,um=sw,pm=um(AP());var im=(e)=>um(vP(e));var DP=aw(void 0);var qP="setImmediate"in globalThis?globalThis.setImmediate:(e)=>setTimeout(e,0);class dm{tasks=[];running=!1;scheduleTask(e,t){if(this.tasks.push(e),!this.running)this.running=!0,qP(this.afterScheduled)}afterScheduled=()=>{this.running=!1,this.runTasks()};runTasks(){let e=this.tasks;this.tasks=[];for(let t=0,r=e.length;t<r;t++)e[t]()}shouldYield(e){return e.currentOpCount>=e.getRef(lw)}flush(){while(this.tasks.length>0)this.runTasks()}}var UP=p(2,(e,t)=>lm((r)=>{let n=r.context;return r.context=t(n),$P(e,()=>(r.context=n,FP))}));var cw=p(2,(e,t)=>UP(e,Bs(t)));class lw extends Ws()("effect/Micro/currentMaxOpsBeforeYield",{defaultValue:()=>2048}){}class ou extends Ws()("effect/Micro/currentScheduler",{defaultValue:()=>new dm}){}var HP=p(2,(e,t)=>{let r=Object.create(jP);return r[De]=e,r[ji]=t.onSuccess,r[Hi]=t.onFailure,r}),jP=nu({op:"OnSuccessAndFailure",eval(e){return e._stack.push(this),this[De]}});var $P=p(2,(e,t)=>WP((r)=>HP(r(e),{onFailure:(n)=>ru(t(um(n)),()=>sw(n)),onSuccess:(n)=>ru(t(aw(n)),()=>cm(n))})));var uw=am({op:"SetInterruptible",ensure(e){if(e.interruptible=this[De],e._interrupted&&e.interruptible)return()=>pm}}),BP=(e)=>lm((t)=>{if(t.interruptible)return e;if(t.interruptible=!0,t._stack.push(uw(!1)),t._interrupted)return pm;return e}),WP=(e)=>lm((t)=>{if(!t.interruptible)return e(te);return t.interruptible=!1,t._stack.push(uw(!0)),e(BP)});var pw=(e,t)=>{let r=new nw(ou.context(t?.scheduler??new dm));if(r.evaluate(e),t?.signal)if(t.signal.aborted)r.unsafeInterrupt();else{let n=()=>r.unsafeInterrupt();t.signal.addEventListener("abort",n,{once:!0}),r.addObserver(()=>t.signal.removeEventListener("abort",n))}return r};class iu{scheduleDrain;running=!1;tasks=new fm;constructor(e){this.scheduleDrain=e}starveInternal=(e)=>{let t=this.tasks.buckets;this.tasks.buckets=[];for(let[r,n]of t)for(let o=0;o<n.length;o++)n[o]();if(this.tasks.buckets.length===0)this.running=!1;else this.starve(e)};starve(e=0){this.scheduleDrain(e,this.starveInternal)}scheduleTask(e,t){if(this.tasks.scheduleTask(e,t),!this.running)this.running=!0,this.starve()}static cached(e){let t=new iu(e),r=new WeakMap;return(n)=>{if(n===void 0)return t;let o=r.get(n);if(o===void 0)o=new iu(e),r.set(n,o);return o}}}class fm{buckets=[];scheduleTask(e,t){let r=this.buckets.length,n=void 0,o=0;for(;o<r;o++)if(this.buckets[o][0]<=t)n=this.buckets[o];else break;if(n&&n[0]===t)n[1].push(e);else if(o===r)this.buckets.push([t,[e]]);else this.buckets.splice(o,0,[t,[e]])}}class dw{maxNextTickBeforeTimer;getRunner=iu.cached((e,t)=>{if(e>=this.maxNextTickBeforeTimer)setTimeout(()=>t(0),0);else Promise.resolve(void 0).then(()=>t(e+1))});constructor(e){this.maxNextTickBeforeTimer=e}shouldYield(e){return e.currentOpCount>e.getFiberRef(Mf)?e.getFiberRef(Ni):!1}scheduleTask(e,t,r){this.getRunner(r).scheduleTask(e,t)}}var fw=B(Symbol.for("effect/Scheduler/defaultScheduler"),()=>new dw(2048));class Sa{tasks=new fm;deferred=!1;scheduleTask(e,t,r){if(this.deferred)fw.scheduleTask(e,t,r);else this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(Mf)?e.getFiberRef(Ni):!1}flush(){while(this.tasks.buckets.length>0){let e=this.tasks.buckets;this.tasks.buckets=[];for(let[t,r]of e)for(let n=0;n<r.length;n++)r[n]()}this.deferred=!0}}var su=B(Symbol.for("effect/FiberRef/currentScheduler"),()=>Je(fw));var au=B(Symbol.for("effect/FiberRef/currentRequestMap"),()=>Je(new Map));var mm=(e,t,r,n)=>{switch(e){case void 0:return t();case"unbounded":return r();case"inherit":return Mo(Sb,(o)=>o==="unbounded"?r():o>1?n(o):t());default:return e>1?n(e):t()}};var hm=(e)=>e.replace(/[\s="]/g,"_"),hw=(e)=>(t)=>`${hm(t.label)}=${e-t.startTime}ms`;var gw="effect/MetricLabel",gm=Symbol.for(gw);class yw{key;value;[gm]=gm;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=ie(gw+this.key+this.value)}[P](){return this._hash}[R](e){return JP(e)&&this.key===e.key&&this.value===e.value}pipe(){return b(this,arguments)}}var xw=(e,t)=>new yw(e,t),JP=(e)=>v(e,gm);var ym=or((e)=>js(e.context,d_)?e._tag==="Span"?ym(e.parent):A():F(e));var Sw=qf;var xm="InterruptSignal",Sm="Stateful",bm="Resume",_m="YieldNow",cu=(e)=>({_tag:"InterruptSignal",cause:e}),$i=(e)=>({_tag:"Stateful",onFiber:e}),jo=(e)=>({_tag:"Resume",effect:e}),bw=()=>({_tag:"YieldNow"});var t0="effect/FiberScope",lu=Symbol.for(t0);class ww{[lu]=lu;fiberId=Kt;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}}class Ew{fiberId;parent;[lu]=lu;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell($i((r)=>{r.addChild(t),t.addObserver(()=>{r.removeChild(t)})}))}}var Ow=(e)=>new Ew(e.id(),e),ba=B(Symbol.for("effect/FiberScope/Global"),()=>new ww);var o0="effect/Fiber",wm=Symbol.for(o0),Em={_E:(e)=>e,_A:(e)=>e},i0={[wm]:Em,pipe(){return b(this,arguments)}},s0="effect/Fiber",Aw=Symbol.for(s0);var uu=(e)=>wl(oa(e.await),e.inheritAll);var xH={...On,commit(){return uu(this)},...i0,id:()=>Kt,await:ca,children:ne([]),inheritAll:ca,poll:ne(A()),interruptAsFork:()=>ca};var Gn="effect/FiberCurrent";var c0="effect/Logger",Tw=Symbol.for(c0),Iw={_Message:(e)=>e,_Output:(e)=>e},pu=(e)=>({[Tw]:Iw,log:e,pipe(){return b(this,arguments)}});var _H={[Tw]:Iw,log:gs,pipe(){return b(this,arguments)}};var l0=/^[^\s"=]*$/,u0=(e,t)=>({annotations:r,cause:n,date:o,fiberId:i,logLevel:s,message:a,spans:c})=>{let l=(y)=>y.match(l0)?y:e(y),u=(y,O)=>`${hm(y)}=${l(O)}`,d=(y,O)=>" "+u(y,O),f=u("timestamp",o.toISOString());f+=d("level",s.label),f+=d("fiber",Xc(i));let g=Jp(a);for(let y=0;y<g.length;y++)f+=d("message",jr(g[y],t));if(!_d(n))f+=d("cause",pr(n,{renderErrorCause:!0}));for(let y of c)f+=" "+hw(o.getTime())(y);for(let[y,O]of r)f+=d(y,jr(O,t));return f},p0=(e)=>`"${e.replace(/\\([\s\S])|(")/g,"\\$1$2")}"`,Rw=pu(u0(p0));var $o={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},wH={None:[],All:[],Trace:[$o.gray],Debug:[$o.blue],Info:[$o.green],Warning:[$o.yellow],Error:[$o.red],Fatal:[$o.bgBrightRed,$o.black]};var kw=typeof process==="object"&&process!==null&&typeof process.stdout==="object"&&process.stdout!==null,EH=kw&&process.stdout.isTTY===!0,OH=kw||"Deno"in globalThis;var Cw="effect/MetricBoundaries",Om=Symbol.for(Cw);class Pw{values;[Om]=Om;constructor(e){this.values=e,this._hash=h(ie(Cw),V(Nt(this.values)))}_hash;[P](){return this._hash}[R](e){return f0(e)&&E(this.values,e.values)}pipe(){return b(this,arguments)}}var f0=(e)=>v(e,Om),m0=(e)=>{let t=h(e,Yp(Ne(Number.POSITIVE_INFINITY)),nd);return new Pw(t)};var Nw=(e)=>h(Gp(e.count-1,(t)=>e.start*Math.pow(e.factor,t)),Fs,m0);var g0="effect/MetricKeyType",Fw=Symbol.for(g0),Mw="effect/MetricKeyType/Counter",vm=Symbol.for(Mw),y0="effect/MetricKeyType/Frequency",x0=Symbol.for(y0),S0="effect/MetricKeyType/Gauge",b0=Symbol.for(S0),Lw="effect/MetricKeyType/Histogram",Am=Symbol.for(Lw),_0="effect/MetricKeyType/Summary",w0=Symbol.for(_0),Dw={_In:(e)=>e,_Out:(e)=>e};class qw{incremental;bigint;[Fw]=Dw;[vm]=vm;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=ie(Mw)}_hash;[P](){return this._hash}[R](e){return Tm(e)}pipe(){return b(this,arguments)}}class Uw{boundaries;[Fw]=Dw;[Am]=Am;constructor(e){this.boundaries=e,this._hash=h(ie(Lw),V(w(this.boundaries)))}_hash;[P](){return this._hash}[R](e){return Im(e)&&E(this.boundaries,e.boundaries)}pipe(){return b(this,arguments)}}var Hw=(e)=>new qw(e?.incremental??!1,e?.bigint??!1);var jw=(e)=>new Uw(e);var Tm=(e)=>v(e,vm),$w=(e)=>v(e,x0),Bw=(e)=>v(e,b0),Im=(e)=>v(e,Am),Ww=(e)=>v(e,w0);var E0="effect/MetricKey",Vw=Symbol.for(E0),O0={_Type:(e)=>e},v0=Tn(E);class du{name;keyType;description;tags;[Vw]=O0;constructor(e,t,r,n=[]){this.name=e,this.keyType=t,this.description=r,this.tags=n,this._hash=h(ie(this.name+this.description),V(w(this.keyType)),V(Nt(this.tags)))}_hash;[P](){return this._hash}[R](e){return A0(e)&&this.name===e.name&&E(this.keyType,e.keyType)&&E(this.description,e.description)&&v0(this.tags,e.tags)}pipe(){return b(this,arguments)}}var A0=(e)=>v(e,Vw),zw=(e,t)=>new du(e,Hw(t),Br(t?.description));var Gw=(e,t,r)=>new du(e,jw(t),Br(r));var Jw=p(2,(e,t)=>t.length===0?e:new du(e.name,e.keyType,e.description,An(e.tags,t)));var Yw=Symbol.for("effect/MutableHashMap"),I0={[Yw]:Yw,[Symbol.iterator](){return new Rm(this)},toString(){return se(this.toJSON())},toJSON(){return{_id:"MutableHashMap",values:Array.from(this).map(re)}},[Y](){return this.toJSON()},pipe(){return b(this,arguments)}};class Rm{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();if(e.done)return this.bucketIterator=new Zw(this.self.buckets.values()),this.next();return e}[Symbol.iterator](){return new Rm(this.self)}}class Zw{backing;constructor(e){this.backing=e}currentBucket;next(){if(this.currentBucket===void 0){let t=this.backing.next();if(t.done)return t;this.currentBucket=t.value[Symbol.iterator]()}let e=this.currentBucket.next();if(e.done)return this.currentBucket=void 0,this.next();return e}}var Qw=()=>{let e=Object.create(I0);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e};var Jn=p(2,(e,t)=>{if(Es(t)===!1)return e.referential.has(t)?F(e.referential.get(t)):A();let r=t[P](),n=e.buckets.get(r);if(n===void 0)return A();return R0(e,n,t)});var R0=(e,t,r,n=!1)=>{for(let o=0,i=t.length;o<i;o++)if(r[R](t[o][0])){let s=t[o][1];if(n)t.splice(o,1),e.bucketsSize--;return F(s)}return A()},Bi=p(2,(e,t)=>de(Jn(e,t))),Wi=p(3,(e,t,r)=>{if(Es(t)===!1)return e.referential.set(t,r),e;let n=t[P](),o=e.buckets.get(n);if(o===void 0)return e.buckets.set(n,[[t,r]]),e.bucketsSize++,e;return k0(e,o,t),o.push([t,r]),e.bucketsSize++,e}),k0=(e,t,r)=>{for(let n=0,o=t.length;n<o;n++)if(r[R](t[n][0])){t.splice(n,1),e.bucketsSize--;return}};var P0="effect/MetricState",_a=Symbol.for(P0),Xw="effect/MetricState/Counter",km=Symbol.for(Xw),eE="effect/MetricState/Frequency",Cm=Symbol.for(eE),tE="effect/MetricState/Gauge",Pm=Symbol.for(tE),rE="effect/MetricState/Histogram",Nm=Symbol.for(rE),nE="effect/MetricState/Summary",Fm=Symbol.for(nE),wa={_A:(e)=>e};class oE{count;[_a]=wa;[km]=km;constructor(e){this.count=e}[P](){return h(w(Xw),V(w(this.count)),Z(this))}[R](e){return F0(e)&&this.count===e.count}pipe(){return b(this,arguments)}}var N0=Tn(E);class iE{occurrences;[_a]=wa;[Cm]=Cm;constructor(e){this.occurrences=e}_hash;[P](){return h(ie(eE),V(Nt(fe(this.occurrences.entries()))),Z(this))}[R](e){return M0(e)&&N0(fe(this.occurrences.entries()),fe(e.occurrences.entries()))}pipe(){return b(this,arguments)}}class sE{value;[_a]=wa;[Pm]=Pm;constructor(e){this.value=e}[P](){return h(w(tE),V(w(this.value)),Z(this))}[R](e){return L0(e)&&this.value===e.value}pipe(){return b(this,arguments)}}class aE{buckets;count;min;max;sum;[_a]=wa;[Nm]=Nm;constructor(e,t,r,n,o){this.buckets=e,this.count=t,this.min=r,this.max=n,this.sum=o}[P](){return h(w(rE),V(w(this.buckets)),V(w(this.count)),V(w(this.min)),V(w(this.max)),V(w(this.sum)),Z(this))}[R](e){return D0(e)&&E(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return b(this,arguments)}}class cE{error;quantiles;count;min;max;sum;[_a]=wa;[Fm]=Fm;constructor(e,t,r,n,o,i){this.error=e,this.quantiles=t,this.count=r,this.min=n,this.max=o,this.sum=i}[P](){return h(w(nE),V(w(this.error)),V(w(this.quantiles)),V(w(this.count)),V(w(this.min)),V(w(this.max)),V(w(this.sum)),Z(this))}[R](e){return q0(e)&&this.error===e.error&&E(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return b(this,arguments)}}var lE=(e)=>new oE(e),uE=(e)=>new iE(e),pE=(e)=>new sE(e),dE=(e)=>new aE(e.buckets,e.count,e.min,e.max,e.sum),fE=(e)=>new cE(e.error,e.quantiles,e.count,e.min,e.max,e.sum);var F0=(e)=>v(e,km),M0=(e)=>v(e,Cm),L0=(e)=>v(e,Pm),D0=(e)=>v(e,Nm),q0=(e)=>v(e,Fm);var H0="effect/MetricHook",j0=Symbol.for(H0),$0={_In:(e)=>e,_Out:(e)=>e},Ea=(e)=>({[j0]:$0,pipe(){return b(this,arguments)},...e});var mE=BigInt(0),gE=(e)=>{let t=e.keyType.bigint?mE:0,r=e.keyType.incremental?e.keyType.bigint?(o)=>o>=mE:(o)=>o>=0:(o)=>!0,n=(o)=>{if(r(o))t=t+o};return Ea({get:()=>lE(t),update:n,modify:n})},yE=(e)=>{let t=new Map;for(let n of e.keyType.preregisteredWords)t.set(n,0);let r=(n)=>{let o=t.get(n)??0;t.set(n,o+1)};return Ea({get:()=>uE(t),update:r,modify:r})},xE=(e,t)=>{let r=t;return Ea({get:()=>pE(r),update:(n)=>{r=n},modify:(n)=>{r=r+n}})},SE=(e)=>{let t=e.keyType.boundaries.values,r=t.length,n=new Uint32Array(r+1),o=new Float64Array(r),i=0,s=0,{MAX_VALUE:a,MIN_VALUE:c}=Number;h(t,Kr(Rr),sr((d,f)=>{o[f]=d}));let l=(d)=>{let f=0,g=r;while(f!==g){let y=Math.floor(f+(g-f)/2),O=o[y];if(d<=O)g=y;else f=y;if(g===f+1)if(d<=o[f])g=f;else f=g}if(n[f]=n[f]+1,i=i+1,s=s+d,d<a)a=d;if(d>c)c=d},u=()=>{let d=xo(r),f=0;for(let g=0;g<r;g++){let y=o[g],O=n[g];f=f+O,d[g]=[y,f]}return d};return Ea({get:()=>dE({buckets:u(),count:i,min:a,max:c,sum:s}),update:l,modify:l})},bE=(e)=>{let{error:t,maxAge:r,maxSize:n,quantiles:o}=e.keyType,i=h(o,Kr(Rr)),s=xo(n),a=0,c=0,l=0,u=0,d=0,f=(y)=>{let O=[],m=0;while(m!==n-1){let x=s[m];if(x!=null){let[D,k]=x,j=zc(y-D);if(tS(j,Ld)&&eS(j,r))O.push(k)}m=m+1}return B0(t,i,Kr(O,Rr))},g=(y,O)=>{if(n>0){a=a+1;let m=a%n;s[m]=[O,y]}u=c===0?y:Math.min(u,y),d=c===0?y:Math.max(d,y),c=c+1,l=l+y};return Ea({get:()=>fE({error:t,quantiles:f(Date.now()),count:c,min:u,max:d,sum:l}),update:([y,O])=>g(y,O),modify:([y,O])=>g(y,O)})},B0=(e,t,r)=>{let n=r.length;if(!le(t))return Vr();let o=t[0],i=t.slice(1),s=hE(e,n,A(),0,o,r),a=et(s);return i.forEach((c)=>{a.push(hE(e,n,s.value,s.consumed,c,s.rest))}),sr(a,(c)=>[c.quantile,c.value])},hE=(e,t,r,n,o,i)=>{let s=e,a=t,c=r,l=n,u=o,d=i,f=e,g=t,y=r,O=n,m=o,x=i;while(!0){if(!le(d))return{quantile:u,value:A(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:F(Xp(d)),consumed:l+d.length,rest:[]};let D=Pe(d),k=jy(d,(M)=>M===D),j=u*a,T=s/2*j,I=l+k[0].length,C=Math.abs(I-j);if(I<j-T){f=s,g=a,y=Wr(d),O=I,m=u,x=k[1],s=f,a=g,c=y,l=O,u=m,d=x;continue}if(I>j+T){let M=be(c)?F(D):c;return{quantile:u,value:M,consumed:l,rest:d}}switch(c._tag){case"None":{f=s,g=a,y=Wr(d),O=I,m=u,x=k[1],s=f,a=g,c=y,l=O,u=m,d=x;continue}case"Some":{let M=Math.abs(j-c.value);if(C<M){f=s,g=a,y=Wr(d),O=I,m=u,x=k[1],s=f,a=g,c=y,l=O,u=m,d=x;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")};var K0="effect/MetricPair",V0=Symbol.for(K0),z0={_Type:(e)=>e};var _E=(e,t)=>({[V0]:z0,metricKey:e,metricState:t,pipe(){return b(this,arguments)}});var J0="effect/MetricRegistry",wE=Symbol.for(J0);class EE{[wE]=wE;map=Qw();snapshot(){let e=[];for(let[t,r]of this.map)e.push(_E(t,r.get()));return e}get(e){let t=h(this.map,Jn(e),Ot);if(t==null){if(Tm(e.keyType))return this.getCounter(e);if(Bw(e.keyType))return this.getGauge(e);if($w(e.keyType))return this.getFrequency(e);if(Im(e.keyType))return this.getHistogram(e);if(Ww(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")}else return t}getCounter(e){let t=h(this.map,Jn(e),Ot);if(t==null){let r=gE(e);if(!h(this.map,Bi(e)))h(this.map,Wi(e,r));t=r}return t}getFrequency(e){let t=h(this.map,Jn(e),Ot);if(t==null){let r=yE(e);if(!h(this.map,Bi(e)))h(this.map,Wi(e,r));t=r}return t}getGauge(e){let t=h(this.map,Jn(e),Ot);if(t==null){let r=xE(e,e.keyType.bigint?BigInt(0):0);if(!h(this.map,Bi(e)))h(this.map,Wi(e,r));t=r}return t}getHistogram(e){let t=h(this.map,Jn(e),Ot);if(t==null){let r=SE(e);if(!h(this.map,Bi(e)))h(this.map,Wi(e,r));t=r}return t}getSummary(e){let t=h(this.map,Jn(e),Ot);if(t==null){let r=bE(e);if(!h(this.map,Bi(e)))h(this.map,Wi(e,r));t=r}return t}}var OE=()=>new EE;var Z0="effect/Metric",Q0=Symbol.for(Z0),X0={_Type:(e)=>e,_In:(e)=>e,_Out:(e)=>e},vE=B(Symbol.for("effect/Metric/globalMetricRegistry"),()=>OE()),AE=function(e,t,r,n){let o=Object.assign((i)=>Sl(i,(s)=>tN(o,s)),{[Q0]:X0,keyType:e,unsafeUpdate:t,unsafeValue:r,unsafeModify:n,register(){return this.unsafeValue([]),this},pipe(){return b(this,arguments)}});return o};var Oa=(e,t)=>TE(zw(e,t));var TE=(e)=>{let t,r=new WeakMap,n=(o)=>{if(o.length===0){if(t!==void 0)return t;return t=vE.get(e),t}let i=r.get(o);if(i!==void 0)return i;return i=vE.get(Jw(e,o)),r.set(o,i),i};return AE(e.keyType,(o,i)=>n(i).update(o),(o)=>n(o).get(),(o,i)=>n(i).modify(o))};var IE=(e,t,r)=>TE(Gw(e,t,r));var RE=p(3,(e,t,r)=>eN(e,[xw(t,r)]));var eN=p(2,(e,t)=>AE(e.keyType,(r,n)=>e.unsafeUpdate(r,An(t,n)),(r)=>e.unsafeValue(An(t,r)),(r,n)=>e.unsafeModify(r,An(t,n))));var tN=p(2,(e,t)=>Mo(ua,(r)=>q(()=>e.unsafeUpdate(t,r))));var nN="effect/Request",oN=Symbol.for(nN),iN={_E:(e)=>e,_A:(e)=>e},tj={...Rs,[oN]:iN};var kE=p(2,(e,t)=>Mo(au,(r)=>q(()=>{if(r.has(e)){let n=r.get(e);if(!n.state.completed)n.state.completed=!0,Cl(n.result,t)}})));var sN="effect/Supervisor",fu=Symbol.for(sN),Mm={_T:(e)=>e};class mu{underlying;value0;[fu]=Mm;constructor(e,t){this.underlying=e,this.value0=t}get value(){return this.value0}onStart(e,t,r,n){this.underlying.onStart(e,t,r,n)}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(e){return new mu(this,h(this.value,ve(e)))}zip(e){return new hu(this,e)}}class hu{left;right;_tag="Zip";[fu]=Mm;constructor(e,t){this.left=e,this.right=t}get value(){return _l(this.left.value,this.right.value)}onStart(e,t,r,n){this.left.onStart(e,t,r,n),this.right.onStart(e,t,r,n)}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 mu(this,h(this.value,ve(e)))}zip(e){return new hu(this,e)}}var Lm=(e)=>v(e,fu)&&_s(e,"Zip");class CE{effect;[fu]=Mm;constructor(e){this.effect=e}get value(){return this.effect}onStart(e,t,r,n){}onEnd(e,t){}onEffect(e,t){}onSuspend(e){}onResume(e){}map(e){return new mu(this,h(this.value,ve(e)))}zip(e){return new hu(this,e)}onRun(e,t){return e()}}var aN=(e)=>new CE(e),Bo=B("effect/Supervisor/none",()=>aN(Fe));var PE=qn;var NE="Empty",FE="AddSupervisor",ME="RemoveSupervisor",LE="AndThen",Ki={_tag:NE},gu=(e,t)=>({_tag:LE,first:e,second:t}),lN=(e,t)=>uN(t,Ne(e)),uN=(e,t)=>{let r=e,n=t;while(ar(n)){let o=cr(n);switch(o._tag){case NE:{n=lr(n);break}case FE:{r=r.zip(o.supervisor),n=lr(n);break}case ME:{r=qm(r,o.supervisor),n=lr(n);break}case LE:{n=tt(o.first)(tt(o.second)(lr(n)));break}}}return r},qm=(e,t)=>{if(E(e,t))return Bo;else if(Lm(e))return qm(e.left,t).zip(qm(e.right,t));else return e},yu=(e)=>{if(E(e,Bo))return Or();else if(Lm(e))return h(yu(e.left),Zr(yu(e.right)));else return wo(e)},pN=(e,t)=>{if(E(e,t))return Ki;let r=yu(e),n=yu(t),o=h(n,yd(r),Oo(Ki,(s,a)=>gu(s,{_tag:FE,supervisor:a}))),i=h(r,yd(n),Oo(Ki,(s,a)=>gu(s,{_tag:ME,supervisor:a})));return gu(o,i)},DE=PE({empty:Ki,patch:lN,combine:gu,diff:pN});var _N=Oa("effect_fiber_started",{incremental:!0}),qE=Oa("effect_fiber_active"),wN=Oa("effect_fiber_successes",{incremental:!0}),EN=Oa("effect_fiber_failures",{incremental:!0}),ON=RE(IE("effect_fiber_lifetimes",Nw({start:0.5,factor:2,count:35})),"time_unit","milliseconds"),va="Continue",vN="Done",UE="Yield",AN={_E:(e)=>e,_A:(e)=>e},xu=(e)=>{throw Error(`BUG: FiberRuntime - ${jr(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},an=Symbol.for("effect/internal/fiberRuntime/YieldedOp"),cn=B("effect/internal/fiberRuntime/yieldedOpChannel",()=>({currentOp:null})),Aa={[si]:(e,t,r)=>Ve(()=>t.effect_instruction_i1(r)),["OnStep"]:(e,t,r)=>xe(xe(r)),[ai]:(e,t,r)=>Ve(()=>t.effect_instruction_i2(r)),[Ts]:(e,t,r)=>{if(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),rn(e.currentRuntimeFlags)&&e.isInterrupted())return ue(e.getInterruptedCause());else return xe(r)},[ci]:(e,t,r)=>{if(Ve(()=>t.effect_instruction_i2(r)),Ve(()=>t.effect_instruction_i0()))return e.pushStack(t),Ve(()=>t.effect_instruction_i1());else return Fe},[li]:(e,t,r)=>{while(!0){let n=Ve(()=>t.effect_instruction_i0.next(r));if(n.done)return xe(n.value);let o=Cp(n.value);if(!Mi(o))return e.pushStack(t),o;else if(o._tag==="Failure")return o;r=o.value}}},TN={[xm]:(e,t,r,n)=>(e.processNewInterruptSignal(n.cause),rn(t)?ue(n.cause):r),[bm]:(e,t,r,n)=>{throw Error("It is illegal to have multiple concurrent run loops in a single fiber")},[Sm]:(e,t,r,n)=>(n.onFiber(e,nm(t)),r),[_m]:(e,t,r,n)=>W(aa(),()=>r)},IN=(e)=>No($S(e),(t)=>Wo(WS(t),([r,n])=>{let o=new Map,i=[];for(let a of n){i.push(Gr(a));for(let c of a)o.set(c.request,c)}let s=i.flat();return Wn(BN(r.runAll(i),s,()=>s.forEach((a)=>{a.listeners.interrupted=!0})),au,o)},!1,!1)),RN=Is();class Su extends zf{[wm]=Em;[Aw]=AN;_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,r){super();if(this.currentRuntimeFlags=r,this._fiberId=e,this._fiberRefs=t,pf(r)){let n=this.getFiberRef(ua);_N.unsafeUpdate(1,n),qE.unsafeUpdate(1,n)}this.refreshRefCache()}commit(){return uu(this)}id(){return this._fiberId}resume(e){this.tell(jo(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>{if(J_(t))return e.currentRuntimeFlags;return t.runtimeFlags})}scope(){return Ow(this)}get children(){return this.ask((e)=>Array.from(e.getChildren()))}getChildren(){if(this._children===null)this._children=new Set;return this._children}getInterruptedCause(){return this.getFiberRef(pa)}fiberRefs(){return this.ask((e)=>e.getFiberRefs())}ask(e){return me(()=>{let t=vb(this._fiberId);return this.tell($i((r,n)=>{Cl(t,q(()=>e(r,n)))})),kl(t)})}tell(e){if(this._queue.push(e),!this._running)this._running=!0,this.drainQueueLaterOnExecutor()}get await(){return Hn((e)=>{let t=(r)=>e(ne(r));if(this._exitValue!==null){t(this._exitValue);return}return this.tell($i((r,n)=>{if(r._exitValue!==null)t(this._exitValue);else r.addObserver(t)})),q(()=>this.tell($i((r,n)=>{r.removeObserver(t)})))},this.id())}get inheritAll(){return Ge((e,t)=>{let r=e.id(),n=e.getFiberRefs(),o=t.runtimeFlags,i=this.getFiberRefs(),s=Xf(n,r,i);e.setFiberRefs(s);let a=e.getFiberRef(jE),c=h(Xs(o,a),hf(tn),hf(al));return Cf(c)})}get poll(){return q(()=>Br(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return q(()=>this.tell(cu(ur(e))))}unsafeInterruptAsFork(e){this.tell(cu(ur(e)))}addObserver(e){if(this._exitValue!==null)e(this._exitValue);else this._observers.push(e)}removeObserver(e){this._observers=this._observers.filter((t)=>t!==e)}getFiberRefs(){return this.setFiberRef(jE,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=xa(this._fiberRefs,e)}getFiberRef(e){if(this._fiberRefs.locals.has(e))return this._fiberRefs.locals.get(e)[0][1];return e.initial}setFiberRef(e,t){this._fiberRefs=Ui(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(ya),this.currentTracer=this.currentDefaultServices.unsafeMap.get(ga.key),this.currentSupervisor=this.getFiberRef($N),this.currentScheduler=this.getFiberRef(su),this.currentContext=this.getFiberRef(Do),this.currentSpan=this.currentContext.unsafeMap.get(Kl.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 r of t)if(r._exitValue===null)e.add(this.currentRuntimeFlags,r)}}drainQueueOnCurrentThread(){let e=!0;while(e){let t=va,r=globalThis[Gn];globalThis[Gn]=this;try{while(t===va)t=this._queue.length===0?vN:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[Gn]=r}if(this._queue.length>0&&!this._running)if(this._running=!0,t===UE)this.drainQueueLaterOnExecutor(),e=!1;else e=!0;else e=!1}}drainQueueLaterOnExecutor(){this.currentScheduler.scheduleTask(this.run,this.getFiberRef(Ni),this)}drainQueueWhileRunning(e,t){let r=t;while(this._queue.length>0){let n=this._queue.splice(0,1)[0];r=TN[n._tag](this,e,r,n)}return r}isInterrupted(){return!jc(this.getFiberRef(pa))}addInterruptedCause(e){let t=this.getFiberRef(pa);this.setFiberRef(pa,rt(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(cu(ur(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return sa({while:()=>!t,body:()=>{let n=e.next();if(!n.done)return on(n.value.await);else return q(()=>{t=!0})},step:()=>{}})}return null}reportExitValue(e){if(pf(this.currentRuntimeFlags)){let t=this.getFiberRef(ua),r=this.id().startTimeMillis,n=Date.now();switch(ON.unsafeUpdate(n-r,t),qE.unsafeUpdate(-1,t),e._tag){case Et:{wN.unsafeUpdate(1,t);break}case wt:{EN.unsafeUpdate(1,t);break}}}if(e._tag==="Failure"){let t=this.getFiberRef(_b);if(!Ei(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(FN)}log(e,t,r){let n=de(r)?r.value:this.getFiberRef(Lf),o=this.getFiberRef(kN);if(Y_(o,n))return;let i=this.getFiberRef(yb),s=this.getFiberRef(gb),a=this.getLoggers(),c=this.getFiberRefs();if(Ds(a)>0){let l=js(this.getFiberRef(ya),ha),u=new Date(l.unsafeCurrentTimeMillis());ly(c,()=>{for(let d of a)d.log({fiberId:this.id(),logLevel:n,message:e,cause:t,context:c,spans:i,annotations:s,date:u})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case _m:return UE;case xm:{if(this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null)this._asyncInterruptor(ue(e.cause)),this._asyncInterruptor=null;return va}case bm:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),va;case Sm:return e.onFiber(this,this._exitValue!==null?z_:G_(this.currentRuntimeFlags,this._asyncBlockingOn)),va;default:return xu(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=rn(this.currentRuntimeFlags)&&this.isInterrupted()?ue(this.getInterruptedCause()):e;while(t!==null){let r=t,n=this.runLoop(r);if(n===an){let o=cn.currentOp;if(cn.currentOp=null,o._op===ui)if(qS(this.currentRuntimeFlags))this.tell(bw()),this.tell(jo(Gt)),t=null;else t=Gt;else if(o._op===ho)t=null}else{this.currentRuntimeFlags=h(this.currentRuntimeFlags,cf(al));let o=this.interruptAllChildren();if(o!==null)t=W(o,()=>n);else{if(this._queue.length===0)this.setExitValue(n);else this.tell(jo(n));t=null}}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(!this._running){this._running=!0;let t=globalThis[Gn];globalThis[Gn]=this;try{this.evaluateEffect(e)}finally{if(this._running=!1,globalThis[Gn]=t,this._queue.length>0)this.drainQueueLaterOnExecutor()}}else this.tell(jo(e))}startFork(e){this.tell(jo(e))}patchRuntimeFlags(e,t){let r=ea(e,t);return globalThis[Gn]=this,this.currentRuntimeFlags=r,r}initiateAsync(e,t){let r=!1,n=(o)=>{if(!r)r=!0,this.tell(jo(o))};if(rn(e))this._asyncInterruptor=n;try{t(n)}catch(o){n(nt(Mt(o)))}}pushStack(e){if(this._stack.push(e),e._op==="OnStep")this._steps.push({refs:this.getFiberRefs(),flags:this.currentRuntimeFlags})}popStack(){let e=this._stack.pop();if(e){if(e._op==="OnStep")this._steps.pop();return e}return}getNextSuccessCont(){let e=this.popStack();while(e){if(e._op!==As)return e;e=this.popStack()}}getNextFailCont(){let e=this.popStack();while(e){if(e._op!==si&&e._op!==ci&&e._op!==li)return e;e=this.popStack()}}[py](e){return q(()=>$s(this.currentContext,e))}["Left"](e){return Be(e.left)}["None"](e){return Be(new da)}["Right"](e){return xe(e.right)}["Some"](e){return xe(e.value)}["Micro"](e){return ta((t)=>{let r=t,n=pw(cw(e,this.currentContext));return n.addObserver((o)=>{if(o._tag==="Success")return r(xe(o.value));switch(o.cause._tag){case"Interrupt":return r(ue(ur(Kt)));case"Fail":return r(Be(o.cause.error));case"Die":return r(gl(o.cause.defect))}}),ta((o)=>{r=(i)=>{o(Fe)},n.unsafeInterrupt()})})}[xc](e){let t=Ve(()=>e.effect_instruction_i0()),r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in Aa))xu(r);return Aa[r._op](this,r,t)}else return cn.currentOp=xe(t),an}[Et](e){let t=e,r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in Aa))xu(r);return Aa[r._op](this,r,t.effect_instruction_i0)}else return cn.currentOp=t,an}[wt](e){let t=e.effect_instruction_i0,r=this.getNextFailCont();if(r!==void 0)switch(r._op){case As:case ai:if(!(rn(this.currentRuntimeFlags)&&this.isInterrupted()))return Ve(()=>r.effect_instruction_i1(t));else return ue(Wc(t));case"OnStep":if(!(rn(this.currentRuntimeFlags)&&this.isInterrupted()))return xe(ue(t));else return ue(Wc(t));case Ts:if(this.patchRuntimeFlags(this.currentRuntimeFlags,r.patch),rn(this.currentRuntimeFlags)&&this.isInterrupted())return ue(rt(t,this.getInterruptedCause()));else return ue(t);default:xu(r)}else return cn.currentOp=ue(t),an}[Sc](e){return Ve(()=>e.effect_instruction_i0(this,nm(this.currentRuntimeFlags)))}["Blocked"](e){let t=this.getFiberRefs(),r=this.currentRuntimeFlags;if(this._steps.length>0){let n=[],o=this._steps[this._steps.length-1],i=this.popStack();while(i&&i._op!=="OnStep")n.push(i),i=this.popStack();this.setFiberRefs(o.refs),this.currentRuntimeFlags=o.flags;let s=L_(o.refs,t),a=Xs(o.flags,r);return xe(ml(e.effect_instruction_i0,Ge((c)=>{while(n.length>0)c.pushStack(n.pop());return c.setFiberRefs(D_(c.id(),c.getFiberRefs())(s)),c.currentRuntimeFlags=ea(a)(c.currentRuntimeFlags),e.effect_instruction_i1})))}return $n((n)=>W($m(_f(e.effect_instruction_i0)),()=>n(e.effect_instruction_i1)))}["RunBlocked"](e){return IN(e.effect_instruction_i0)}[yo](e){let t=e.effect_instruction_i0,r=this.currentRuntimeFlags,n=ea(r,t);if(rn(n)&&this.isInterrupted())return ue(this.getInterruptedCause());else if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let o=Xs(n,r);return this.pushStack(new wf(o,e)),Ve(()=>e.effect_instruction_i1(r))}else return Gt}[si](e){return this.pushStack(e),e.effect_instruction_i0}["OnStep"](e){return this.pushStack(e),e.effect_instruction_i0}[As](e){return this.pushStack(e),e.effect_instruction_i0}[ai](e){return this.pushStack(e),e.effect_instruction_i0}[ho](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),cn.currentOp=e,an}[ui](e){return this._isYielding=!1,cn.currentOp=e,an}[ci](e){let{effect_instruction_i0:t,effect_instruction_i1:r}=e;if(t())return this.pushStack(e),r();else return Gt}[li](e){return Aa[li](this,e,void 0)}[go](e){return Ve(()=>e.commit())}runLoop(e){let t=e;this.currentOpCount=0;while(!0){if((this.currentRuntimeFlags&DS)!==0)this.currentSupervisor.onEffect(this,t);if(this._queue.length>0)t=this.drainQueueWhileRunning(this.currentRuntimeFlags,t);if(!this._isYielding){this.currentOpCount+=1;let r=this.currentScheduler.shouldYield(this);if(r!==!1){this._isYielding=!0,this.currentOpCount=0;let n=t;t=W(aa({priority:r}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(RN!==t[Un]._V){let r=this.getFiberRef(wb);if(r._tag==="Some"){let n=t[Un]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${Is()}, 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`,Qr,r)}}return this[t._op](t)},this),t===an){let r=cn.currentOp;if(r._op===ui||r._op===ho)return an;return cn.currentOp=null,r._op===Et||r._op===wt?r:ue(Mt(r))}}catch(r){if(t!==an&&!v(t,"_op")||!(t._op in this))t=Af(`Not a valid effect: ${jr(t)}`);else if(Eb(r))t=ue(rt(Mt(r),ur(Kt)));else t=gl(r)}}}run=()=>{this.drainQueueOnCurrentThread()}}var kN=B("effect/FiberRef/currentMinimumLogLevel",()=>Je(Z_("Info"))),CN=(e)=>pu((t)=>{let r=O_(t.context,ya);js(r,Wl).unsafe.log(e.log(t))});var PN=B(Symbol.for("effect/Logger/defaultLogger"),()=>CN(Rw));var NN=B(Symbol.for("effect/Logger/tracerLogger"),()=>pu(({annotations:e,cause:t,context:r,fiberId:n,logLevel:o,message:i})=>{let s=ym(Ln(Vn(r,Do),Kl));if(s._tag==="None"||s.value._tag==="ExternalSpan")return;let a=$s(Vn(r,ya),ha),c={};for(let[l,u]of e)c[l]=u;if(c["effect.fiberId"]=pS(n),c["effect.logLevel"]=o.label,t!==null&&t._tag!=="Empty")c["effect.cause"]=pr(t,{renderErrorCause:!0});s.value.event(jr(Array.isArray(i)&&i.length===1?i[0]:i),a.unsafeCurrentTimeNanos(),c)}));var FN=B(Symbol.for("effect/FiberRef/currentLoggers"),()=>mb(wo(PN,NN)));var $E=p((e)=>Tp(e[0]),(e,t,r)=>Ge((n)=>{let o=r?.batching===!0||r?.batching==="inherit"&&n.getFiberRef(bb);if(r?.discard)return mm(r.concurrency,()=>Vi(Vl,r?.concurrentFinalizers)((i)=>o?Wo(e,(s,a)=>i(t(s,a)),!0,!1,1):No(e,(s,a)=>i(t(s,a)))),()=>Vi(zl,r?.concurrentFinalizers)((i)=>Wo(e,(s,a)=>i(t(s,a)),o,!1)),(i)=>Vi(Gl(i),r?.concurrentFinalizers)((s)=>Wo(e,(a,c)=>s(t(a,c)),o,!1,i)));return mm(r?.concurrency,()=>Vi(Vl,r?.concurrentFinalizers)((i)=>o?Um(e,1,(s,a)=>i(t(s,a)),!0):zt(e,(s,a)=>i(t(s,a)))),()=>Vi(zl,r?.concurrentFinalizers)((i)=>BE(e,(s,a)=>i(t(s,a)),o)),(i)=>Vi(Gl(i),r?.concurrentFinalizers)((s)=>Um(e,i,(a,c)=>s(t(a,c)),o)))})),BE=(e,t,r)=>me(()=>{let n=fe(e),o=Array(n.length);return Bn(Wo(n,(s,a)=>W(t(s,a),(c)=>q(()=>o[a]=c)),r,!1),ne(o))}),Wo=(e,t,r,n,o)=>$n((i)=>kf((s)=>Ge((a)=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return Fe;let u=0,d=!1,f=o?Math.min(c.length,o):c.length,g=new Set,y=[],O=()=>g.forEach((M)=>{M.currentScheduler.scheduleTask(()=>{M.unsafeInterruptAsFork(a.id())},0,M)}),m=[],x=[],D=[],k=()=>{let M=y.filter(({exit:ee})=>ee._tag==="Failure").sort((ee,X)=>ee.index<X.index?-1:ee.index===X.index?0:1).map(({exit:ee})=>ee);if(M.length===0)M.push(Gt);return M},j=(M,ee=!1)=>{let X=bl(s(M)),J=LN(X,a,a.currentRuntimeFlags,ba);return a.currentScheduler.scheduleTask(()=>{if(ee)J.unsafeInterruptAsFork(a.id());J.resume(X)},0,J),J},T=()=>{if(!n)l-=c.length,c=[];d=!0,O()},I=r?Rf:jn,C=j(Hn((M)=>{let ee=(J,he)=>{if(J._op==="Blocked")D.push(J);else if(y.push({index:he,exit:J}),J._op==="Failure"&&!d)T()},X=()=>{if(c.length>0){let J=c.pop(),he=u++,ut=()=>{let Re=c.pop();return he=u++,W(aa(),()=>W(I(i(t(Re,he))),Qe))},Qe=(Re)=>{if(c.length>0){if(ee(Re,he),c.length>0)return ut()}return ne(Re)},pt=W(I(i(t(J,he))),Qe),Me=j(pt);if(m.push(Me),g.add(Me),d)Me.currentScheduler.scheduleTask(()=>{Me.unsafeInterruptAsFork(a.id())},0,Me);Me.addObserver((Re)=>{let dt;if(Re._op==="Failure")dt=Re;else dt=Re.effect_instruction_i0;if(x.push(Me),g.delete(Me),ee(dt,he),y.length===l)M(ne(pe(Uo(k(),{parallel:!0}),()=>Gt)));else if(D.length+y.length===l){let Lr=k(),ss=D.map((no)=>no.effect_instruction_i0).reduce(yf);M(ne(ml(ss,Wo([pe(Uo(Lr,{parallel:!0}),()=>Gt),...D.map((no)=>no.effect_instruction_i1)],(no)=>no,r,!0,o))))}else X()})}};for(let J=0;J<f;J++)X()}));return on(Pi(oa(i(uu(C))),Rl({onFailure:(M)=>{T();let ee=D.length+1,X=Math.min(typeof o==="number"?o:D.length,D.length),J=Array.from(D);return Hn((he)=>{let ut=[],Qe=0,pt=0,Me=(dt,Lr)=>(ss)=>{if(ut[dt]=ss,Qe++,Qe===ee)he(xe(ue(M)));if(J.length>0&&Lr)Re()},Re=()=>{j(J.pop(),!0).addObserver(Me(pt,!0)),pt++};C.addObserver(Me(pt,!1)),pt++;for(let dt=0;dt<X;dt++)Re()})},onSuccess:()=>zt(x,(M)=>M.inheritAll)})))}))),Um=(e,t,r,n)=>me(()=>{let o=fe(e),i=Array(o.length);return Bn(Wo(o,(a,c)=>ve(r(a,c),(l)=>i[c]=l),n,!1,t),ne(i))});var $m=(e)=>DN(e,ba);var MN=(e,t,r,n=null)=>{let o=WE(e,t,r,n);return o.resume(e),o},LN=(e,t,r,n=null)=>WE(e,t,r,n),WE=(e,t,r,n=null)=>{let o=el(),i=t.getFiberRefs(),s=em(i,o),a=new Su(o,s,r),c=Vn(s,Do),l=a.currentSupervisor;return l.onStart(c,e,F(t),a),a.addObserver((d)=>l.onEnd(d,a)),(n!==null?n:h(t.getFiberRef(fl),pe(()=>t.scope()))).add(r,a),a},DN=(e,t)=>Ge((r,n)=>ne(MN(e,r,n.runtimeFlags,t)));var Hm=(e)=>Ho((t)=>Ae(Ln(t,Ta),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Parallel":return e;case"Sequential":case"ParallelN":return W(Fi(r,zl),(n)=>Bm(e,n))}}})),HE=(e)=>(t)=>Ho((r)=>Ae(Ln(r,Ta),{onNone:()=>t,onSome:(n)=>{if(n.strategy._tag==="ParallelN"&&n.strategy.parallelism===e)return t;return W(Fi(n,Gl(e)),(o)=>Bm(t,o))}}));var Vi=(e,t)=>(r)=>Ho((n)=>Ae(Ln(n,Ta),{onNone:()=>r(te),onSome:(o)=>{if(t===!0){let i=e._tag==="Parallel"?Hm:e._tag==="Sequential"?jm:HE(e.parallelism);switch(o.strategy._tag){case"Parallel":return i(r(Hm));case"Sequential":return i(r(jm));case"ParallelN":return i(r(HE(o.strategy.parallelism)))}}else return r(te)}}));var jm=(e)=>Ho((t)=>Ae(Ln(t,Ta),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Sequential":return e;case"Parallel":case"ParallelN":return W(Fi(r,Vl),(n)=>Bm(e,n))}}}));var Ta=vt("effect/Scope");var qN=(e,t)=>{if(e.state._tag==="Open")e.state.finalizers.set({},t)},UN={[vl]:vl,[Al]:Al,pipe(){return b(this,arguments)},fork(e){return q(()=>{let t=HN(e);if(this.state._tag==="Closed")return t.state=this.state,t;let r={},n=(o)=>t.close(o);return this.state.finalizers.set(r,n),qN(t,(o)=>q(()=>{if(this.state._tag==="Open")this.state.finalizers.delete(r)})),t})},close(e){return me(()=>{if(this.state._tag==="Closed")return Fe;let t=Array.from(this.state.finalizers.values()).reverse();if(this.state={_tag:"Closed",exit:e},t.length===0)return Fe;return Gf(this.strategy)?h(zt(t,(r)=>jn(r(e))),W((r)=>h(Uo(r),nr(fa),pe(()=>Gt)))):Jf(this.strategy)?h(BE(t,(r)=>jn(r(e)),!1),W((r)=>h(Uo(r,{parallel:!0}),nr(fa),pe(()=>Gt)))):h(Um(t,this.strategy.parallelism,(r)=>jn(r(e)),!1),W((r)=>h(Uo(r,{parallel:!0}),nr(fa),pe(()=>Gt))))})},addFinalizer(e){return me(()=>{if(this.state._tag==="Closed")return e(this.state.exit);return this.state.finalizers.set({},e),Fe})}},HN=(e=qi)=>{let t=Object.create(UN);return t.strategy=e,t.state={_tag:"Open",finalizers:new Map},t};var Bm=p(2,(e,t)=>$f(e,Bs(zx(Ta,t))));var jN=(e)=>Lo(e,{differ:DE,fork:Ki});var jE=hb(US),$N=jN(Bo);var KE=p(2,(e,t)=>$n((r)=>Vt(r(e),{onFailure:(n)=>Vt(t,{onFailure:(o)=>nt(rt(n,o)),onSuccess:()=>nt(n)}),onSuccess:(n)=>nn(t,n)}))),BN=(e,t,r)=>na((n)=>KE(W($m(yl(e)),(o)=>Hn((i)=>{let s=t.map((l)=>l.listeners.count),a=()=>{if(s.every((l)=>l===0)){if(t.every((l)=>{if(l.result.state.current._tag==="Pending")return!0;else if(l.result.state.current._tag==="Done"&&Mi(l.result.state.current.effect)&&l.result.state.current.effect._tag==="Failure"&&$c(l.result.state.current.effect.cause))return!0;else return!1}))c.forEach((l)=>l()),r?.(),i(cb(o))}};o.addObserver((l)=>{c.forEach((u)=>u()),i(l)});let c=t.map((l,u)=>{let d=(f)=>{s[u]=f,a()};return l.listeners.addObserver(d),()=>l.listeners.removeObserver(d)});return a(),q(()=>{c.forEach((l)=>l())})})),me(()=>{let o=t.flatMap((i)=>{if(!i.state.completed)return[i];return[]});return No(o,(i)=>kE(i.request,Hf(n)))})));var zE=Df;var GE=Fi;var Km=(e)=>function(){if(arguments.length===1){let t=arguments[0];return(r,...n)=>e(t,r,...n)}return e.apply(this,arguments)},JE=Km((e,t,r)=>{let n=el(),o=[[Do,[[n,e.context]]]];if(r?.scheduler)o.push([su,[[n,r.scheduler]]]);let i=v_(e.fiberRefs,{entries:o,forkAs:n});if(r?.updateRefs)i=r.updateRefs(i,n);let s=new Su(n,i,e.runtimeFlags),a=t;if(r?.scope)a=W(GE(r.scope,qi),(l)=>Bn(Tl(l,na((u)=>E(u,s.id())?Fe:la(s,u))),Pi(t,(u)=>zE(l,u))));let c=s.currentSupervisor;if(c!==Bo)c.onStart(e.context,a,A(),s),s.addObserver((l)=>c.onEnd(l,s));if(ba.add(e.runtimeFlags,s),r?.immediate===!1)s.resume(a);else s.start(a);return s});var zN=Km((e,t)=>{let r=ZN(e)(t);if(r._tag==="Failure")throw JN(r.effect_instruction_i0);return r.effect_instruction_i0});class YE 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}}var GN=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new YE(e);return Error.stackTraceLimit=t,r};var Wm=Symbol.for("effect/Runtime/FiberFailure"),bu=Symbol.for("effect/Runtime/FiberFailure/Cause");class ZE extends Error{[Wm];[bu];constructor(e){let t=qs(e)[0];super(t?.message||"An error has occurred");if(this[Wm]=Wm,this[bu]=e,this.name=t?`(FiberFailure) ${t.name}`:"FiberFailure",t?.stack)this.stack=t.stack}toJSON(){return{_id:"FiberFailure",cause:this[bu].toJSON()}}toString(){return"(FiberFailure) "+pr(this[bu],{renderErrorCause:!0})}[Y](){return this.toString()}}var JN=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new ZE(e);return Error.stackTraceLimit=t,r};var YN=(e)=>{let t=e;switch(t._op){case"Failure":case"Success":return t;case"Left":return ma(t.left);case"Right":return xe(t.right);case"Some":return xe(t.value);case"None":return ma(new da)}},ZN=Km((e,t)=>{let r=YN(t);if(r)return r;let n=new Sa,o=JE(e)(t,{scheduler:n});n.flush();let i=o.unsafePoll();if(i)return i;return Uf(hl(GN(o),Pl(o)))});class QE{context;runtimeFlags;fiberRefs;constructor(e,t,r){this.context=e,this.runtimeFlags=t,this.fiberRefs=r}pipe(){return b(this,arguments)}}var QN=(e)=>new QE(e.context,e.runtimeFlags,e.fiberRefs);var XN=uf(tn,af,sf),XE=QN({context:Mn(),runtimeFlags:XN,fiberRefs:A_()});var eO=JE(XE);var tO=zN(XE);var rO=ki;var Ia=$E;var Ra=me;var Dt=Fe;var nO=ra;var _u=ve;var oO=Fo;var Ko=Po;var fr=W;var iO=eO;var sO=tO;var Vm=(e,t)=>{switch(t._tag){case"StringKeyword":case"TemplateLiteral":return Object.keys(e);case"SymbolKeyword":return Object.getOwnPropertySymbols(e);case"Refinement":return Vm(e,t.from)}},ka=(e)=>{let t=!1,r;return()=>{if(t)return r;return r=e(),t=!0,r}},zm=(e)=>Array.isArray(e),cO=(e)=>!Array.isArray(e),aO=(e)=>`[${vs(e)}]`,wu=(e)=>zm(e)?e.map(aO).join(""):aO(e);var Yn=(e,t,r,n)=>{let o=e;if(r&&le(r))o+=`
|
|
34
|
+
at path: ${wu(r)}`;if(t!==void 0)o+=`
|
|
35
35
|
details: ${t}`;if(n)o+=`
|
|
36
|
-
schema (${n._tag}): ${n}`;return o},iO=(e)=>Jn("Invalid Argument",e);var sO=(e)=>Jn("Unsupported key schema",void 0,void 0,e),aO=(e)=>Jn("Unsupported literal",`literal value: ${Sr(e)}`),Vm=(e)=>Jn("Duplicate index signature",`${e} index signature`),cO=Jn("Unsupported index signature parameter","An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),lO=Jn("Invalid element","A required element cannot follow an optional element. ts(1257)"),zm=(e)=>Jn("Duplicate property signature transformation",`Duplicate key ${Sr(e)}`);var Gm=(e)=>Jn("Duplicate property signature",`Duplicate key ${Sr(e)}`);var pO=Symbol.for("effect/SchemaId/DateFromSelf"),dO=Symbol.for("effect/SchemaId/GreaterThan"),fO=Symbol.for("effect/SchemaId/GreaterThanOrEqualTo");var mO=Symbol.for("effect/SchemaId/Int");var hO=Symbol.for("effect/SchemaId/MinLength");var gO=Symbol.for("effect/SchemaId/MinItems");var xO=Symbol.for("effect/annotation/TypeConstructor"),Zm=Symbol.for("effect/annotation/Brand"),SO=Symbol.for("effect/annotation/SchemaId"),Qm=Symbol.for("effect/annotation/Message"),_u=Symbol.for("effect/annotation/MissingMessage"),wu=Symbol.for("effect/annotation/Identifier"),At=Symbol.for("effect/annotation/Title"),Eu=Symbol.for("effect/annotation/AutoTitle"),ln=Symbol.for("effect/annotation/Description"),Xm=Symbol.for("effect/annotation/Examples"),eh=Symbol.for("effect/annotation/Default"),th=Symbol.for("effect/annotation/JSONSchema"),rh=Symbol.for("effect/annotation/Arbitrary"),nh=Symbol.for("effect/annotation/Pretty"),oh=Symbol.for("effect/annotation/Equivalence"),bO=Symbol.for("effect/annotation/Documentation"),ih=Symbol.for("effect/annotation/Concurrency"),sh=Symbol.for("effect/annotation/Batching"),ah=Symbol.for("effect/annotation/ParseIssueTitle"),ch=Symbol.for("effect/annotation/ParseOptions"),lh=Symbol.for("effect/annotation/DecodingFallback"),uh=Symbol.for("effect/annotation/Surrogate"),ph=Symbol.for("effect/annotation/StableFilter"),nt=p(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?P(e.annotations[t]):E());var dh=nt(Zm);var _O=nt(Qm),wO=nt(_u),fh=nt(At),mh=nt(Eu),Ra=nt(wu),hh=nt(ln);var EO=nt(ih),OO=nt(sh),vO=nt(ah),AO=nt(ch),TO=nt(lh),gh=nt(uh),QF=nt(ph),yh=(e)=>Ry(QF(e),(t)=>t===!0),xh=Symbol.for("effect/annotation/JSONIdentifier"),XF=nt(xh),eN=(e)=>rr(XF(e),()=>Ra(e));class Wi{typeParameters;decodeUnknown;encodeUnknown;annotations;_tag="Declaration";constructor(e,t,r,n={}){this.typeParameters=e,this.decodeUnknown=t,this.encodeUnknown=r,this.annotations=n}toString(){return ue(kr(this),()=>"<declaration schema>")}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map((e)=>e.toJSON()),annotations:we(this.annotations)}}}var Ca=(e)=>(t)=>t._tag===e;class Ko{literal;annotations;_tag="Literal";constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return ue(kr(this),()=>Sr(this.literal))}toJSON(){return{_tag:this._tag,literal:bn(this.literal)?String(this.literal):this.literal,annotations:we(this.annotations)}}}var Ou=Ca("Literal"),IO=new Ko(null);class vu{symbol;annotations;_tag="UniqueSymbol";constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return ue(kr(this),()=>Sr(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:we(this.annotations)}}}class kO{annotations;_tag="UndefinedKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var Au=new kO({[At]:"undefined"});class RO{annotations;_tag="VoidKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var tN=new RO({[At]:"void"});class CO{annotations;_tag="NeverKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var Tu=new CO({[At]:"never"});class PO{annotations;_tag="UnknownKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var FO=new PO({[At]:"unknown"});class NO{annotations;_tag="AnyKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var MO=new NO({[At]:"any"});class LO{annotations;_tag="StringKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var DO=new LO({[At]:"string",[ln]:"a string"}),Iu=Ca("StringKeyword");class qO{annotations;_tag="NumberKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var UO=new qO({[At]:"number",[ln]:"a number"});class HO{annotations;_tag="BooleanKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var jO=new HO({[At]:"boolean",[ln]:"a boolean"});class $O{annotations;_tag="BigIntKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var rN=new $O({[At]:"bigint",[ln]:"a bigint"});class BO{annotations;_tag="SymbolKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var nN=new BO({[At]:"symbol",[ln]:"a symbol"}),KO=Ca("SymbolKeyword");class WO{annotations;_tag="ObjectKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:we(this.annotations)}}}var oN=new WO({[At]:"object",[ln]:"an object in the TypeScript meaning, i.e. the `object` type"});class Vi{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:we(this.annotations)}}toString(){return String(this.type)}}class Yn extends Vi{isOptional;constructor(e,t,r={}){super(e,r);this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:we(this.annotations)}}toString(){return String(this.type)+(this.isOptional?"?":"")}}var VO=(e)=>e.map((t)=>t.type);class Pa{elements;rest;isReadonly;annotations;_tag="TupleType";constructor(e,t,r,n={}){this.elements=e,this.rest=t,this.isReadonly=r,this.annotations=n;let o=!1,i=!1;for(let s of e)if(s.isOptional)o=!0;else if(o){i=!0;break}if(i||o&&t.length>1)throw Error(lO)}toString(){return ue(kr(this),()=>iN(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map((e)=>e.toJSON()),rest:this.rest.map((e)=>e.toJSON()),isReadonly:this.isReadonly,annotations:we(this.annotations)}}}var iN=(e)=>{let t=e.elements.map(String).join(", ");return Py(e.rest,{onEmpty:()=>`readonly [${t}]`,onNonEmpty:(r,n)=>{let o=String(r),i=o.includes(" | ")?`(${o})`:o;if(n.length>0){let s=n.map(String).join(", ");if(e.elements.length>0)return`readonly [${t}, ...${i}[], ${s}]`;else return`readonly [...${i}[], ${s}]`}else if(e.elements.length>0)return`readonly [${t}, ...${i}[]]`;else return`ReadonlyArray<${o}>`}})};class Ue extends Yn{name;isReadonly;constructor(e,t,r,n,o){super(t,r,o);this.name=e,this.isReadonly=n}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:we(this.annotations)}}}var zO=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return!0;case"Refinement":return zO(e.from)}return!1};class zi{type;isReadonly;parameter;constructor(e,t,r){if(this.type=t,this.isReadonly=r,zO(e))this.parameter=e;else throw Error(cO)}toString(){return(this.isReadonly?"readonly ":"")+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}}class Rr{annotations;_tag="TypeLiteral";propertySignatures;indexSignatures;constructor(e,t,r={}){this.annotations=r;let n={};for(let i=0;i<e.length;i++){let s=e[i].name;if(Object.prototype.hasOwnProperty.call(n,s))throw Error(Gm(s));n[s]=null}let o={string:!1,symbol:!1};for(let i=0;i<t.length;i++){let s=vh(t[i].parameter);if(Iu(s)){if(o.string)throw Error(Vm("string"));o.string=!0}else if(KO(s)){if(o.symbol)throw Error(Vm("symbol"));o.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return ue(kr(this),()=>sN(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map((e)=>e.toJSON()),indexSignatures:this.indexSignatures.map((e)=>e.toJSON()),annotations:we(this.annotations)}}}var yO=(e)=>e.map(String).join("; "),sN=(e)=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join("; ");if(e.indexSignatures.length>0)return`{ ${t}; ${yO(e.indexSignatures)} }`;else return`{ ${t} }`}else if(e.indexSignatures.length>0)return`{ ${yO(e.indexSignatures)} }`;else return"{}"};var aN=Wr(bc(Tr,(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})),cN={string:"StringKeyword",number:"NumberKeyword",boolean:"BooleanKeyword",bigint:"BigIntKeyword"},GO=(e)=>Cs(e,(t)=>Sh(t)?GO(t.types):[t]),lN=(e)=>{let t=aN(e),r=[],n={},o=[];for(let i of t)switch(i._tag){case"NeverKeyword":break;case"AnyKeyword":return[MO];case"UnknownKeyword":return[FO];case"ObjectKeyword":case"UndefinedKeyword":case"VoidKeyword":case"StringKeyword":case"NumberKeyword":case"BooleanKeyword":case"BigIntKeyword":case"SymbolKeyword":{if(!n[i._tag])n[i._tag]=i,r.push(i);break}case"Literal":{let s=typeof i.literal;switch(s){case"string":case"number":case"bigint":case"boolean":{let a=cN[s];if(!n[a]&&!o.includes(i.literal))o.push(i.literal),r.push(i);break}case"object":{if(!o.includes(i.literal))o.push(i.literal),r.push(i);break}}break}case"UniqueSymbol":{if(!n.SymbolKeyword&&!o.includes(i.symbol))o.push(i.symbol),r.push(i);break}case"TupleType":{if(!n.ObjectKeyword)r.push(i);break}case"TypeLiteral":{if(i.propertySignatures.length===0&&i.indexSignatures.length===0){if(!n["{}"])n["{}"]=i,r.push(i)}else if(!n.ObjectKeyword)r.push(i);break}default:r.push(i)}return r};class yt{types;annotations;static make=(e,t)=>ku(e)?new yt(e,t):e.length===1?e[0]:Tu;static unify=(e,t)=>yt.make(lN(GO(e)),t);_tag="Union";constructor(e,t={}){this.types=e,this.annotations=t}toString(){return ue(kr(this),()=>this.types.map(String).join(" | "))}toJSON(){return{_tag:this._tag,types:this.types.map((e)=>e.toJSON()),annotations:we(this.annotations)}}}var JO=(e,t)=>e.map(t),ku=(e)=>e.length>1,Sh=Ca("Union"),Jm=U(Symbol.for("effect/Schema/AST/toJSONMemoMap"),()=>new WeakMap);class Ru{f;annotations;_tag="Suspend";constructor(e,t={}){this.f=e,this.annotations=t,this.f=ka(e)}toString(){return kr(this).pipe(rr(()=>or(Ty(this.f)(),(e)=>kr(e))),ue(()=>"<suspended schema>"))}toJSON(){let e=this.f(),t=Jm.get(e);if(t)return t;return Jm.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:we(this.annotations)},Jm.set(e,t),t}}class Fa{from;filter;annotations;_tag="Refinement";constructor(e,t,r={}){this.from=e,this.filter=t,this.annotations=r}toString(){return Ra(this).pipe(ue(()=>Ae(XO(this),{onNone:()=>`{ ${this.from} | filter }`,onSome:(e)=>Na(this.from)?String(this.from)+" & "+e:e})))}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),annotations:we(this.annotations)}}}var Na=Ca("Refinement"),Cu={};class bh{from;to;transformation;annotations;_tag="Transformation";constructor(e,t,r,n={}){this.from=e,this.to=t,this.transformation=r,this.annotations=n}toString(){return ue(kr(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:we(this.annotations)}}}class _h{from;to;decode;encode;constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}}class wh{propertySignatureTransformations;_tag="TypeLiteralTransformation";constructor(e){this.propertySignatureTransformations=e;let t={},r={};for(let n of e){let o=n.from;if(t[o])throw Error(zm(o));t[o]=!0;let i=n.to;if(r[i])throw Error(zm(i));r[i]=!0}}}var Ma=(e,t)=>{let r=Object.getOwnPropertyDescriptors(e),n={...e.annotations};delete n[wu];let o={...n,...t},i=gh(e);if(pe(i))o[uh]=Ma(i.value,t);return r.annotations.value=o,Object.create(Object.getPrototypeOf(e),r)};var uN="[\\s\\S]*?",pN="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",YO=(e,t)=>{switch(e._tag){case"Literal":return Mi(String(e.literal));case"StringKeyword":return uN;case"NumberKeyword":return pN;case"TemplateLiteral":return ZO(e,t,!1);case"Union":return e.types.map((r)=>YO(r,t)).join("|")}},dN=(e,t,r,n)=>{if(Sh(e)){if(r&&!n)return`(?:${t})`}else if(!r||!n)return t;return`(${t})`},ZO=(e,t,r)=>{let n="";if(e.head!==""){let o=Mi(e.head);n+=t&&r?`(${o})`:o}for(let o of e.spans){let i=YO(o.type,t);if(n+=dN(o.type,i,t,r),o.literal!==""){let s=Mi(o.literal);n+=t&&r?`(${s})`:s}}return n},QO=(e)=>new RegExp(`^${ZO(e,!1,!0)}$`);var Eh=(e,t)=>{let r=[],n=[],o=(i)=>{switch(i._tag){case"NeverKeyword":break;case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":case"Refinement":n.push(new zi(i,t,!0));break;case"Literal":if(We(i.literal)||Ft(i.literal))r.push(new Ue(i.literal,t,!1,!0));else throw Error(aO(i.literal));break;case"Enums":{for(let[s,a]of i.enums)r.push(new Ue(a,t,!1,!0));break}case"UniqueSymbol":r.push(new Ue(i.symbol,t,!1,!0));break;case"Union":i.types.forEach(o);break;default:throw Error(sO(i))}};return o(e),{propertySignatures:r,indexSignatures:n}};var Oh=(e)=>(t)=>{let r=void 0;for(let n of e)if(Object.prototype.hasOwnProperty.call(t.annotations,n)){if(r===void 0)r={};r[n]=t.annotations[n]}return r};var fN=Oh([Xm,eh,th,rh,nh,oh]),qe=(e)=>{switch(e._tag){case"Declaration":{let t=Yt(e.typeParameters,qe);return t===e.typeParameters?e:new Wi(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case"TupleType":{let t=Yt(e.elements,(o)=>{let i=qe(o.type);return i===o.type?o:new Yn(i,o.isOptional)}),r=VO(e.rest),n=Yt(r,qe);return t===e.elements&&n===r?e:new Pa(t,n.map((o)=>new Vi(o)),e.isReadonly,e.annotations)}case"TypeLiteral":{let t=Yt(e.propertySignatures,(n)=>{let o=qe(n.type);return o===n.type?n:new Ue(n.name,o,n.isOptional,n.isReadonly)}),r=Yt(e.indexSignatures,(n)=>{let o=qe(n.type);return o===n.type?n:new zi(n.parameter,o,n.isReadonly)});return t===e.propertySignatures&&r===e.indexSignatures?e:new Rr(t,r,e.annotations)}case"Union":{let t=Yt(e.types,qe);return t===e.types?e:yt.make(t,e.annotations)}case"Suspend":return new Ru(()=>qe(e.f()),e.annotations);case"Refinement":{let t=qe(e.from);return t===e.from?e:new Fa(t,e.filter,e.annotations)}case"Transformation":{let t=fN(e);return qe(t!==void 0?Ma(e.to,t):e.to)}}return e};function Yt(e,t){let r=!1,n=go(e.length);for(let o=0;o<e.length;o++){let i=e[o],s=t(i);if(s!==i)r=!0;n[o]=s}return r?n:e}var Ym=(e)=>{switch(e._tag){case"Transformation":return e.from;case"Refinement":return Ym(e.from);case"Suspend":return Ym(e.f())}},Ir=(e,t)=>{switch(e._tag){case"Declaration":{let r=Yt(e.typeParameters,(n)=>Ir(n,t));return r===e.typeParameters?e:new Wi(r,e.decodeUnknown,e.encodeUnknown)}case"TupleType":{let r=Yt(e.elements,(i)=>{let s=Ir(i.type,t);return s===i.type?i:new Yn(s,i.isOptional)}),n=VO(e.rest),o=Yt(n,(i)=>Ir(i,t));return r===e.elements&&o===n?e:new Pa(r,o.map((i)=>new Vi(i)),e.isReadonly)}case"TypeLiteral":{let r=Yt(e.propertySignatures,(o)=>{let i=Ir(o.type,t);return i===o.type?o:new Ue(o.name,i,o.isOptional,o.isReadonly)}),n=Yt(e.indexSignatures,(o)=>{let i=Ir(o.type,t);return i===o.type?o:new zi(o.parameter,i,o.isReadonly)});return r===e.propertySignatures&&n===e.indexSignatures?e:new Rr(r,n)}case"Union":{let r=Yt(e.types,(n)=>Ir(n,t));return r===e.types?e:yt.make(r)}case"Suspend":{let r=void 0,n=eN(e);if(pe(n)){let o=t?"Bound":"";r={[xh]:`${n.value}Encoded${o}`}}return new Ru(()=>Ir(e.f(),t),r)}case"Refinement":{let r=Ir(e.from,t);if(t){if(r===e.from)return e;if(Ym(e.from)===void 0&&yh(e))return new Fa(r,e.filter,e.annotations);return r}else return r}case"Transformation":return Ir(e.from,t)}return e},Pu=(e)=>Ir(e,!1);var we=(e)=>{let t={};for(let r of Object.getOwnPropertySymbols(e))t[String(r)]=e[r];return t},vh=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return e;case"Refinement":return vh(e.from)}};var mr=(e)=>ue(kr(e),()=>e._tag);function mN(e){return Ae(dh(e),{onNone:()=>"",onSome:(t)=>t.map((r)=>` & Brand<${Sr(r)}>`).join("")})}var XO=(e)=>fh(e).pipe(rr(()=>hh(e)),rr(()=>mh(e)),nr((t)=>t+mN(e))),kr=(e)=>rr(Ra(e),()=>XO(e));class He{path;actual;issue;_tag="Pointer";constructor(e,t,r){this.path=e,this.actual=t,this.issue=r}}class Ih{actual;message;_tag="Unexpected";constructor(e,t){this.actual=e,this.message=t}}class Gi{ast;message;_tag="Missing";actual=void 0;constructor(e,t){this.ast=e,this.message=t}}class Ee{ast;actual;issues;output;_tag="Composite";constructor(e,t,r,n){this.ast=e,this.actual=t,this.issues=r,this.output=n}}class Nu{ast;actual;kind;issue;_tag="Refinement";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class Mu{ast;actual;kind;issue;_tag="Transformation";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class Zt{ast;actual;message;_tag="Type";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}class kh{ast;actual;message;_tag="Forbidden";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}var tv=Symbol.for("effect/Schema/ParseErrorTypeId");class ov extends l_("ParseError"){[tv]=tv;get message(){return this.toString()}toString(){return qa.formatIssueSync(this.issue)}toJSON(){return{_id:"ParseError",message:this.toString()}}[Y](){return this.toJSON()}}var Ch=(e)=>new ov({issue:e}),iv=z,sv=B;var It=jp,un=p(2,(e,t)=>It(e)?Rs(e,{onLeft:B,onRight:t}):fr(e,t)),gr=p(2,(e,t)=>It(e)?_y(e,t):xu(e,t)),Lu=p(2,(e,t)=>It(e)?Sc(e,t):eO(e,t));var av=p(2,(e,t)=>It(e)?Rs(e,{onLeft:t,onRight:z}):XE(e,t)),cv=(e,t)=>{if(t===void 0||Ft(t))return e;if(e===void 0)return t;return{...e,...t}},lv=(e,t,r)=>{let n=ot(e,t);return(o,i)=>n(o,cv(r,i))},hN=(e,t,r)=>{let n=lv(e,t,r);return(o,i)=>$p(n(o,i),Ch)};var uv=(e,t)=>lv(e.ast,!0,t);var Du=(e,t)=>hN(qe(e.ast),!0,t);var gN=U(Symbol.for("effect/ParseResult/decodeMemoMap"),()=>new WeakMap),yN=U(Symbol.for("effect/ParseResult/encodeMemoMap"),()=>new WeakMap),ot=(e,t)=>{let r=t?gN:yN,n=r.get(e);if(n)return n;let o=xN(e,t),i=AO(e),s=pe(i)?(l,u)=>o(l,cv(u,i.value)):o,a=TO(e),c=t&&pe(a)?(l,u)=>Da(av(s(l,u),a.value),e,l,u):s;return r.set(e,c),c},Ah=(e)=>Ot(EO(e)),Th=(e)=>Ot(OO(e)),xN=(e,t)=>{switch(e._tag){case"Refinement":if(t){let r=ot(e.from,!0);return(n,o)=>{o=o??Cu;let i=o?.errors==="all",s=un(av(r(n,o),(a)=>{let c=new Nu(e,n,"From",a);if(i&&yh(e)&&hv(a))return Ae(e.filter(n,o,e),{onNone:()=>B(c),onSome:(l)=>B(new Ee(e,n,[c,new Nu(e,n,"Predicate",l)]))});return B(c)}),(a)=>Ae(e.filter(a,o,e),{onNone:()=>z(a),onSome:(c)=>B(new Nu(e,n,"Predicate",c))}));return Da(s,e,n,o)}}else{let r=ot(qe(e),!0),n=ot(dv(e.from),!1);return(o,i)=>Da(un(r(o,i),(s)=>n(s,i)),e,o,i)}case"Transformation":{let r=bN(e.transformation,t),n=t?ot(e.from,!0):ot(e.to,!1),o=t?ot(e.to,!0):ot(e.from,!1);return(i,s)=>Da(un(Lu(n(i,s),(a)=>new Mu(e,i,t?"Encoded":"Type",a)),(a)=>un(Lu(r(a,s??Cu,e,i),(c)=>new Mu(e,i,"Transformation",c)),(c)=>Lu(o(c,s),(l)=>new Mu(e,i,t?"Type":"Encoded",l)))),e,i,s)}case"Declaration":{let r=t?e.decodeUnknown(...e.typeParameters):e.encodeUnknown(...e.typeParameters);return(n,o)=>Da(r(n,o??Cu,e),e,n,o)}case"Literal":return Tt(e,(r)=>r===e.literal);case"UniqueSymbol":return Tt(e,(r)=>r===e.symbol);case"UndefinedKeyword":return Tt(e,Qg);case"NeverKeyword":return Tt(e,Xg);case"UnknownKeyword":case"AnyKeyword":case"VoidKeyword":return z;case"StringKeyword":return Tt(e,We);case"NumberKeyword":return Tt(e,Ft);case"BooleanKeyword":return Tt(e,so);case"BigIntKeyword":return Tt(e,bn);case"SymbolKeyword":return Tt(e,ao);case"ObjectKeyword":return Tt(e,gt);case"Enums":return Tt(e,(r)=>e.enums.some(([n,o])=>o===r));case"TemplateLiteral":{if(e.spans.every((n)=>Iu(n.type)))return Tt(e,(n)=>{if(!We(n)||!n.startsWith(e.head))return!1;let o=e.head.length;for(let s=0;s<e.spans.length-1;s++){let a=e.spans[s].literal,c=n.indexOf(a,o);if(c===-1)return!1;o=c+a.length}let i=e.spans[e.spans.length-1].literal;return n.endsWith(i)&&n.length-i.length>=o});let r=QO(e);return Tt(e,(n)=>We(n)&&r.test(n))}case"TupleType":{let r=e.elements.map((l)=>ot(l.type,t)),n=e.rest.map((l)=>ot(l.type,t)),o=e.elements.filter((l)=>!l.isOptional);if(e.rest.length>0)o=o.concat(e.rest.slice(1));let i=o.length,s=e.elements.length>0?e.elements.map((l,u)=>u).join(" | "):"never",a=Ah(e),c=Th(e);return(l,u)=>{if(!Jp(l))return B(new Zt(e,l));let d=u?.errors==="all",f=[],h=0,g=[],O=l.length;for(let q=O;q<=i-1;q++){let j=new He(q,l,new Gi(o[q-O]));if(d){f.push([h++,j]);continue}else return B(new Ee(e,l,j,g))}if(e.rest.length===0)for(let q=e.elements.length;q<=O-1;q++){let j=new He(q,l,new Ih(l[q],`is unexpected, expected: ${s}`));if(d){f.push([h++,j]);continue}else return B(new Ee(e,l,j,g))}let S=0,v=void 0;for(;S<r.length;S++)if(O<S+1){if(e.elements[S].isOptional)continue}else{let q=r[S],j=q(l[S],u);if(It(j)){if(ye(j)){let k=new He(S,l,j.left);if(d){f.push([h++,k]);continue}else return B(new Ee(e,l,k,hr(g)))}g.push([h++,j.right])}else{let k=h++,C=S;if(!v)v=[];v.push(({es:V,output:F})=>fr(Bo(j),(ee)=>{if(ye(ee)){let X=new He(C,l,ee.left);if(d)return V.push([k,X]),qt;else return B(new Ee(e,l,X,hr(F)))}return F.push([k,ee.right]),qt}))}}if(ce(n)){let[q,...j]=n;for(;S<O-j.length;S++){let k=q(l[S],u);if(It(k))if(ye(k)){let C=new He(S,l,k.left);if(d){f.push([h++,C]);continue}else return B(new Ee(e,l,C,hr(g)))}else g.push([h++,k.right]);else{let C=h++,V=S;if(!v)v=[];v.push(({es:F,output:ee})=>fr(Bo(k),(X)=>{if(ye(X)){let J=new He(V,l,X.left);if(d)return F.push([C,J]),qt;else return B(new Ee(e,l,J,hr(ee)))}else return ee.push([C,X.right]),qt}))}}for(let k=0;k<j.length;k++){let C=S+k;if(O<C+1)continue;else{let V=j[k](l[C],u);if(It(V)){if(ye(V)){let F=new He(C,l,V.left);if(d){f.push([h++,F]);continue}else return B(new Ee(e,l,F,hr(g)))}g.push([h++,V.right])}else{let F=h++;if(!v)v=[];v.push(({es:ee,output:X})=>fr(Bo(V),(J)=>{if(ye(J)){let he=new He(C,l,J.left);if(d)return ee.push([F,he]),qt;else return B(new Ee(e,l,he,hr(X)))}return X.push([F,J.right]),qt}))}}}}let G=({es:q,output:j})=>On(q)?B(new Ee(e,l,hr(q),hr(j))):z(hr(j));if(v&&v.length>0){let q=v;return Ia(()=>{let j={es:ui(f),output:ui(g)};return fr(Ta(q,(k)=>k(j),{concurrency:a,batching:c,discard:!0}),()=>G(j))})}return G({output:g,es:f})}}case"TypeLiteral":{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return Tt(e,ey);let r=[],n={},o=[];for(let u of e.propertySignatures)r.push([ot(u.type,t),u]),n[u.name]=null,o.push(u.name);let i=e.indexSignatures.map((u)=>[ot(u.parameter,t),ot(u.type,t),u.parameter]),s=yt.make(e.indexSignatures.map((u)=>u.parameter).concat(o.map((u)=>ao(u)?new vu(u):new Ko(u)))),a=ot(s,t),c=Ah(e),l=Th(e);return(u,d)=>{if(!Ap(u))return B(new Zt(e,u));let f=d?.errors==="all",h=[],g=0,O=d?.onExcessProperty==="error",S=d?.onExcessProperty==="preserve",v={},G;if(O||S){G=Reflect.ownKeys(u);for(let C of G){let V=a(C,d);if(It(V)&&ye(V))if(O){let F=new He(C,u,new Ih(u[C],`is unexpected, expected: ${String(s)}`));if(f){h.push([g++,F]);continue}else return B(new Ee(e,u,F,v))}else v[C]=u[C]}}let q=void 0,j=d?.exact===!0;for(let C=0;C<r.length;C++){let V=r[C][1],F=V.name,ee=Object.prototype.hasOwnProperty.call(u,F);if(!ee){if(V.isOptional)continue;else if(j){let he=new He(F,u,new Gi(V));if(f){h.push([g++,he]);continue}else return B(new Ee(e,u,he,v))}}let X=r[C][0],J=X(u[F],d);if(It(J)){if(ye(J)){let he=new He(F,u,ee?J.left:new Gi(V));if(f){h.push([g++,he]);continue}else return B(new Ee(e,u,he,v))}v[F]=J.right}else{let he=g++,lt=F;if(!q)q=[];q.push(({es:Ze,output:ut})=>fr(Bo(J),(Me)=>{if(ye(Me)){let ke=new He(lt,u,ee?Me.left:new Gi(V));if(f)return Ze.push([he,ke]),qt;else return B(new Ee(e,u,ke,ut))}return ut[lt]=Me.right,qt}))}}for(let C=0;C<i.length;C++){let V=i[C],F=V[0],ee=V[1],X=Km(u,V[2]);for(let J of X){let he=F(J,d);if(It(he)&&Qe(he)){let lt=ee(u[J],d);if(It(lt)){if(ye(lt)){let Ze=new He(J,u,lt.left);if(f){h.push([g++,Ze]);continue}else return B(new Ee(e,u,Ze,v))}else if(!Object.prototype.hasOwnProperty.call(n,J))v[J]=lt.right}else{let Ze=g++,ut=J;if(!q)q=[];q.push(({es:Me,output:ke})=>fr(Bo(lt),(pt)=>{if(ye(pt)){let Lr=new He(ut,u,pt.left);if(f)return Me.push([Ze,Lr]),qt;else return B(new Ee(e,u,Lr,ke))}else{if(!Object.prototype.hasOwnProperty.call(n,J))ke[J]=pt.right;return qt}}))}}}}let k=({es:C,output:V})=>{if(On(C))return B(new Ee(e,u,hr(C),V));if(d?.propertyOrder==="original"){let F=G||Reflect.ownKeys(u);for(let X of o)if(F.indexOf(X)===-1)F.push(X);let ee={};for(let X of F)if(Object.prototype.hasOwnProperty.call(V,X))ee[X]=V[X];return z(ee)}return z(V)};if(q&&q.length>0){let C=q;return Ia(()=>{let V={es:ui(h),output:Object.assign({},v)};return fr(Ta(C,(F)=>F(V),{concurrency:c,batching:l,discard:!0}),()=>k(V))})}return k({es:h,output:v})}}case"Union":{let r=pv(e.types,t),n=Reflect.ownKeys(r.keys),o=n.length,i=e.types.length,s=new Map;for(let l=0;l<i;l++)s.set(e.types[l],ot(e.types[l],t));let a=Ah(e)??1,c=Th(e);return(l,u)=>{let d=[],f=0,h=[];if(o>0)if(Ss(l))for(let S=0;S<o;S++){let v=n[S],G=r.keys[v].buckets;if(Object.prototype.hasOwnProperty.call(l,v)){let q=String(l[v]);if(Object.prototype.hasOwnProperty.call(G,q))h=h.concat(G[q]);else{let{candidates:j,literals:k}=r.keys[v],C=yt.make(k),V=j.length===i?new Rr([new Ue(v,C,!1,!0)],[]):yt.make(j);d.push([f++,new Ee(V,l,new He(v,l,new Zt(C,l[v])))])}}else{let{candidates:q,literals:j}=r.keys[v],k=new Ue(v,yt.make(j),!1,!0),C=q.length===i?new Rr([k],[]):yt.make(q);d.push([f++,new Ee(C,l,new He(v,l,new Gi(k)))])}}else{let S=r.candidates.length===i?e:yt.make(r.candidates);d.push([f++,new Zt(S,l)])}if(r.otherwise.length>0)h=h.concat(r.otherwise);let g=void 0;for(let S=0;S<h.length;S++){let v=h[S],G=s.get(v)(l,u);if(It(G)&&(!g||g.length===0))if(Qe(G))return G;else d.push([f++,G.left]);else{let q=f++;if(!g)g=[];g.push((j)=>Ia(()=>{if("finalResult"in j)return qt;else return fr(Bo(G),(k)=>{if(Qe(k))j.finalResult=k;else j.es.push([q,k.left]);return qt})}))}}let O=(S)=>On(S)?S.length===1&&S[0][1]._tag==="Type"?B(S[0][1]):B(new Ee(e,l,hr(S))):B(new Zt(e,l));if(g&&g.length>0){let S=g;return Ia(()=>{let v={es:ui(d)};return fr(Ta(S,(G)=>G(v),{concurrency:a,batching:c,discard:!0}),()=>{if("finalResult"in v)return v.finalResult;return O(v.es)})})}return O(d)}}case"Suspend":{let r=ka(()=>ot(e.f(),t));return(n,o)=>r()(n,o)}}},Tt=(e,t)=>(r)=>t(r)?z(r):B(new Zt(e,r)),La=(e,t)=>{switch(e._tag){case"Declaration":{let r=gh(e);if(pe(r))return La(r.value,t);break}case"TypeLiteral":{let r=[];for(let n=0;n<e.propertySignatures.length;n++){let o=e.propertySignatures[n],i=t?Pu(o.type):qe(o.type);if(Ou(i)&&!o.isOptional)r.push([o.name,i])}return r}case"TupleType":{let r=[];for(let n=0;n<e.elements.length;n++){let o=e.elements[n],i=t?Pu(o.type):qe(o.type);if(Ou(i)&&!o.isOptional)r.push([n,i])}return r}case"Refinement":return La(e.from,t);case"Suspend":return La(e.f(),t);case"Transformation":return La(t?e.from:e.to,t)}return[]},pv=(e,t)=>{let r={},n=[],o=[];for(let i=0;i<e.length;i++){let s=e[i],a=La(s,t);if(a.length>0){o.push(s);for(let c=0;c<a.length;c++){let[l,u]=a[c],d=String(u.literal);r[l]=r[l]||{buckets:{},literals:[],candidates:[]};let f=r[l].buckets;if(Object.prototype.hasOwnProperty.call(f,d)){if(c<a.length-1)continue;f[d].push(s),r[l].literals.push(u),r[l].candidates.push(s)}else{f[d]=[s],r[l].literals.push(u),r[l].candidates.push(s);break}}}else n.push(s)}return{keys:r,otherwise:n,candidates:o}},dv=(e)=>Na(e)?dv(e.from):e,Da=(e,t,r,n)=>{if(n?.isEffectAllowed===!0)return e;if(It(e))return e;let o=new xa,i=tO(e,{scheduler:o});o.flush();let s=i.unsafePoll();if(s){if(hw(s))return z(s.value);let a=s.cause;if(Eb(a))return B(a.error);return B(new kh(t,r,Ob(a)))}return B(new kh(t,r,"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"))},SN=([e],[t])=>e>t?1:e<t?-1:0;function hr(e){return e.sort(SN).map((t)=>t[1])}var bN=(e,t)=>{switch(e._tag){case"FinalTransformation":return t?e.decode:e.encode;case"ComposeTransformation":return z;case"TypeLiteralTransformation":return(r)=>{let n=z(r);for(let o of e.propertySignatureTransformations){let[i,s]=t?[o.from,o.to]:[o.to,o.from],a=t?o.decode:o.encode;n=gr(n,(l)=>{let u=a(Object.prototype.hasOwnProperty.call(l,i)?P(l[i]):E());if(delete l[i],pe(u))l[s]=u.value;return l})}return n}}},xt=(e,t=[])=>({value:e,forest:t}),qa={formatIssue:(e)=>gr(Ji(e),_N),formatIssueSync:(e)=>{let t=qa.formatIssue(e);return It(t)?Ey(t):rO(t)},formatError:(e)=>qa.formatIssue(e.issue),formatErrorSync:(e)=>qa.formatIssueSync(e.issue)},_N=(e)=>e.value+fv(`
|
|
37
|
-
`,e.forest),fv=(e,t)=>{let r="",n=t.length,o;for(let i=0;i<n;i++){o=t[i];let s=i===n-1;r+=e+(s?"\u2514":"\u251C")+"\u2500 "+o.value,r+=fv(e+(n>1&&!s?"\u2502 ":" "),o.forest)}return r},wN=(e)=>{switch(e){case"Encoded":return"Encoded side transformation failure";case"Transformation":return"Transformation process failure";case"Type":return"Type side transformation failure"}},EN=(e)=>{switch(e){case"From":return"From side refinement failure";case"Predicate":return"Predicate refinement failure"}},mv=(e)=>("ast"in e)?P(e.ast):E(),Rh=z(void 0),ON=(e)=>mv(e).pipe(or(_O),Ae({onNone:()=>Rh,onSome:(t)=>{let r=t(e);if(We(r))return z({message:r,override:!1});if(QE(r))return xu(r,(n)=>({message:n,override:!1}));if(We(r.message))return z({message:r.message,override:r.override});return xu(r.message,(n)=>({message:n,override:r.override}))}})),Ph=(e)=>(t)=>t._tag===e,hv=Ph("Composite"),rv=Ph("Refinement"),nv=Ph("Transformation"),Ua=(e)=>un(ON(e),(t)=>{if(t!==void 0)return!t.override&&(hv(e)||rv(e)&&e.kind==="From"||nv(e)&&e.kind!=="Transformation")?nv(e)||rv(e)?Ua(e.issue):Rh:z(t.message);return Rh}),gv=(e)=>mv(e).pipe(or(vO),Iy((t)=>t(e)),Ot);function vN(e){return hh(e).pipe(rr(()=>fh(e)),rr(()=>mh(e)),rr(()=>Ra(e)),ue(()=>`{ ${e.from} | filter }`))}function AN(e){if(e.message!==void 0)return e.message;return`Expected ${Na(e.ast)?vN(e.ast):String(e.ast)}, actual ${Sr(e.actual)}`}var TN=(e)=>gr(Ua(e),(t)=>t??gv(e)??AN(e)),Fu=(e)=>gv(e)??String(e.ast),IN=(e)=>e.message??"is forbidden",kN=(e)=>e.message??"is unexpected",RN=(e)=>{let t=wO(e.ast);if(pe(t)){let r=t.value();return We(r)?z(r):r}return z(e.message??"is missing")},Ji=(e)=>{switch(e._tag){case"Type":return gr(TN(e),xt);case"Forbidden":return z(xt(Fu(e),[xt(IN(e))]));case"Unexpected":return z(xt(kN(e)));case"Missing":return gr(RN(e),xt);case"Transformation":return un(Ua(e),(t)=>{if(t!==void 0)return z(xt(t));return gr(Ji(e.issue),(r)=>xt(Fu(e),[xt(wN(e.kind),[r])]))});case"Refinement":return un(Ua(e),(t)=>{if(t!==void 0)return z(xt(t));return gr(Ji(e.issue),(r)=>xt(Fu(e),[xt(EN(e.kind),[r])]))});case"Pointer":return gr(Ji(e.issue),(t)=>xt(Su(e.path),[t]));case"Composite":return un(Ua(e),(t)=>{if(t!==void 0)return z(xt(t));let r=Fu(e);return Wm(e.issues)?gr(Ta(e.issues,Ji),(n)=>xt(r,n)):gr(Ji(e.issues),(n)=>xt(r,[n]))})}};var yv=p((e)=>gt(e[0]),(e,...t)=>{let r={};for(let n of t)if(n in e)r[n]=e[n];return r}),xv=p((e)=>gt(e[0]),(e,...t)=>{let r={...e};for(let n of t)delete r[n];return r});var Ha=Symbol.for("effect/Schema");function it(e){return class{[Ha]=Sv;static ast=e;static annotations(r){return it(pn(this.ast,r))}static pipe(){return x(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[Ha]=Sv}}var Sv={_A:(e)=>e,_I:(e)=>e,_R:(e)=>e};var bv={typeConstructor:xO,schemaId:SO,message:Qm,missingMessage:_u,identifier:wu,title:At,description:ln,examples:Xm,default:eh,documentation:bO,jsonSchema:th,arbitrary:rh,pretty:nh,equivalence:oh,concurrency:ih,batching:sh,parseIssueTitle:ah,parseOptions:ch,decodingFallback:lh},Wo=(e)=>{if(!e)return{};let t={...e};for(let r in bv)if(r in e){let n=bv[r];t[n]=e[r],delete t[r]}return t},pn=(e,t)=>Ma(e,Wo(t));var Yi=(e,t)=>{let r=uv(e,t);return(n,o)=>Sc(r(n,o),Ch)};var _v=(e)=>w(e,Ha)&>(e[Ha]);function FN(e){return ku(e)?yt.make(JO(e,(t)=>new Ko(t))):new Ko(e[0])}function Av(e,t=FN(e)){return class extends it(t){static annotations(n){return Av(this.literals,pn(this.ast,n))}static literals=[...e]}}function N(...e){return ce(e)?Av(e):Mh}var NN=(e,t,r)=>Nh(e,new Wi(e.map((n)=>n.ast),(...n)=>t.decode(...n.map(it)),(...n)=>t.encode(...n.map(it)),Wo(r))),MN=(e,t)=>{let r=()=>(o,i,s)=>e(o)?iv(o):sv(new Zt(s,o));return Nh([],new Wi([],r,r,Wo(t)))};function Nh(e,t){return class extends it(t){static annotations(n){return Nh(this.typeParameters,pn(this.ast,n))}static typeParameters=[...e]}}var Ut=function(){if(Array.isArray(arguments[0])){let r=arguments[0],n=arguments[1],o=arguments[2];return NN(r,n,o)}let e=arguments[0],t=arguments[1];return MN(e,t)};class Tv extends it(Au){}class dn extends it(IO){}class Mh extends it(Tu){}class Q extends it(DO){}class qu extends it(UO){}class ge extends it(jO){}var LN=(e)=>yt.make(e.map((t)=>t.ast));function Iv(e,t=LN(e)){return class extends it(t){static annotations(n){return Iv(this.members,pn(this.ast,n))}static members=[...e]}}function st(...e){return ku(e)?Iv(e):ce(e)?e[0]:Mh}var DN=(e)=>st(e,Tv);var qN=(e,t)=>new Pa(e.map((r)=>_v(r)?new Yn(r.ast,!1):r.ast),t.map((r)=>_v(r)?new Vi(r.ast):r.ast),!0);function kv(e,t,r=qN(e,t)){return class extends it(r){static annotations(o){return kv(this.elements,this.rest,pn(this.ast,o))}static elements=[...e];static rest=[...t]}}function Rv(e,t){return class extends kv([],[e],t){static annotations(n){return Rv(this.value,pn(this.ast,n))}static value=e}}var W=(e)=>Rv(e);var Fh=(e)=>e?'"?:"':'":"';class Lh extends Yn{isReadonly;defaultValue;_tag="PropertySignatureDeclaration";constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}toString(){let e=Fh(this.isOptional),t=String(this.type);return`PropertySignature<${e}, ${t}, never, ${e}, ${t}>`}}class Cv extends Yn{isReadonly;defaultValue;constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}}var UN=(e)=>{if(e===void 0)return"never";if(We(e))return JSON.stringify(e);return String(e)};class Pv{from;to;decode;encode;_tag="PropertySignatureTransformation";constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}toString(){return`PropertySignature<${Fh(this.to.isOptional)}, ${this.to.type}, ${UN(this.from.fromKey)}, ${Fh(this.from.isOptional)}, ${this.from.type}>`}}var Fv=(e,t)=>{switch(e._tag){case"PropertySignatureDeclaration":return new Lh(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case"PropertySignatureTransformation":return new Pv(e.from,new Cv(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},Nv=Symbol.for("effect/PropertySignature"),Mv=(e)=>w(e,Nv);class Dh{ast;[Ha];[Nv]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return x(this,arguments)}annotations(e){return new Dh(Fv(this.ast,Wo(e)))}toString(){return String(this.ast)}}class qh extends Dh{from;constructor(e,t){super(e);this.from=t}annotations(e){return new qh(Fv(this.ast,Wo(e)),this.from)}}var R=(e)=>{let t=e.ast===Au||e.ast===Tu?Au:DN(e).ast;return new qh(new Lh(t,!0,!0,{},void 0),e)};var HN=Oh([_u]),jN=(e,t)=>{let r=Reflect.ownKeys(e),n=[];if(r.length>0){let i=[],s=[],a=[];for(let c=0;c<r.length;c++){let l=r[c],u=e[l];if(Mv(u)){let d=u.ast;switch(d._tag){case"PropertySignatureDeclaration":{let{type:f,isOptional:h,annotations:g}=d;i.push(new Ue(l,f,h,!0,HN(d))),s.push(new Ue(l,qe(f),h,!0,g)),n.push(new Ue(l,f,h,!0,g));break}case"PropertySignatureTransformation":{let f=d.from.fromKey??l;i.push(new Ue(f,d.from.type,d.from.isOptional,!0,d.from.annotations)),s.push(new Ue(l,d.to.type,d.to.isOptional,!0,d.to.annotations)),a.push(new _h(f,l,d.decode,d.encode));break}}}else i.push(new Ue(l,u.ast,!1,!0)),s.push(new Ue(l,qe(u.ast),!1,!0)),n.push(new Ue(l,u.ast,!1,!0))}if(ce(a)){let c=[],l=[];for(let u of t){let{indexSignatures:d,propertySignatures:f}=Eh(u.key.ast,u.value.ast);f.forEach((h)=>{i.push(h),s.push(new Ue(h.name,qe(h.type),h.isOptional,h.isReadonly,h.annotations))}),d.forEach((h)=>{c.push(h),l.push(new zi(h.parameter,qe(h.type),h.isReadonly))})}return new bh(new Rr(i,c,{[Eu]:"Struct (Encoded side)"}),new Rr(s,l,{[Eu]:"Struct (Type side)"}),new wh(a))}}let o=[];for(let i of t){let{indexSignatures:s,propertySignatures:a}=Eh(i.key.ast,i.value.ast);a.forEach((c)=>n.push(c)),s.forEach((c)=>o.push(c))}return new Rr(n,o)},$N=(e,t)=>{let r=Reflect.ownKeys(e);for(let n of r){let o=e[n];if(t[n]===void 0&&Mv(o)){let i=o.ast,s=i._tag==="PropertySignatureDeclaration"?i.defaultValue:i.to.defaultValue;if(s!==void 0)t[n]=s()}}return t};function Lv(e,t,r=jN(e,t)){return class extends it(r){static annotations(o){return Lv(this.fields,this.records,pn(this.ast,o))}static fields={...e};static records=[...t];static make=(o,i)=>{let s=$N(e,{...o});return Uh(i)?s:Du(this)(s)};static pick(...o){return D(yv(e,...o))}static omit(...o){return D(xv(e,...o))}}}function D(e,...t){return Lv(e,t)}function Dv(e,t){return class extends it(t){static annotations(n){return Dv(this.from,pn(this.ast,n))}static make=(n,o)=>Uh(o)?n:Du(this)(n);static from=e}}var ja=(e,t)=>(r)=>{let n=Ae(dh(r.ast),{onNone:()=>[e],onSome:(i)=>[...i,e]}),o=Ma(r.ast,Wo({[Zm]:n,...t}));return Dv(r,o)};var BN=Symbol.for("effect/SchemaId/Refine");function qv(e,t,r){return class extends it(r){static annotations(o){return qv(this.from,this.filter,pn(this.ast,o))}static[BN]=e;static from=e;static filter=t;static make=(o,i)=>Uh(i)?o:Du(this)(o)}}var wv=(e,t,r)=>{if(so(e))return e?E():P(new Zt(t,r));if(We(e))return P(new Zt(t,r,e));if(e!==void 0){if("_tag"in e)return P(e);let n=new Zt(t,r,e.message);return P(ce(e.path)?new He(e.path,r,n):n)}return E()},KN=(e,t,r)=>{if(oO(e))return wv(e,t,r);if(ce(e)){let n=wc(e,(o)=>wv(o,t,r));if(ce(n))return P(n.length===1?n[0]:new Ee(t,r,n))}return E()};function Ht(e,t){return(r)=>{function n(i,s,a){return KN(e(i,s,a),a,i)}let o=new Fa(r.ast,n,Wo(t));return qv(r,n,o)}}var WN=hO,Uv=(e,t)=>(r)=>r.pipe(Ht((n)=>n.length>=e,{schemaId:WN,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t}));var Ev=Symbol.for("effect/SchemaId/Pattern"),jt=(e,t)=>(r)=>{let n=e.source;return r.pipe(Ht((o)=>(e.lastIndex=0,e.test(o)),{schemaId:Ev,[Ev]:{regex:e},description:`a string matching the pattern ${n}`,jsonSchema:{pattern:n},...t}))};var VN=Symbol.for("effect/SchemaId/UUID"),Ov=/^[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;class zN extends Q.pipe(jt(Ov,{schemaId:VN,identifier:"UUID",jsonSchema:{format:"uuid",pattern:Ov.source},description:"a Universally Unique Identifier",arbitrary:()=>(e)=>e.uuid()})){}var GN=dO,Hv=(e,t)=>(r)=>r.pipe(Ht((n)=>n>e,{schemaId:GN,title:`greaterThan(${e})`,description:e===0?"a positive number":`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),JN=fO,jv=(e,t)=>(r)=>r.pipe(Ht((n)=>n>=e,{schemaId:JN,title:`greaterThanOrEqualTo(${e})`,description:e===0?"a non-negative number":`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t}));var YN=mO,ZN=(e)=>(t)=>t.pipe(Ht((r)=>Number.isSafeInteger(r),{schemaId:YN,title:"int",description:"an integer",jsonSchema:{type:"integer"},...e}));class Uu extends qu.pipe(ZN({identifier:"Int"})){}var QN=gO,Cr=(e,t)=>(r)=>{let n=Math.floor(e);if(n<1)throw Error(iO(`Expected an integer greater than or equal to 1, actual ${e}`));return r.pipe(Ht((o)=>o.length>=n,{schemaId:QN,title:`minItems(${n})`,description:`an array of at least ${n} item(s)`,jsonSchema:{minItems:n},[ph]:!0,...t}))};var vv=pO;class XN extends Ut(lc,{typeConstructor:{_tag:"Date"},identifier:"DateFromSelf",schemaId:vv,[vv]:{noInvalidDate:!1},description:"a potentially invalid Date instance",pretty:()=>(e)=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>(e)=>e.date({noInvalidDate:!1}),equivalence:()=>Yg}){}function Uh(e){return so(e)?e:e?.disableValidation??!1}var eM={onExcessProperty:"error"};function mn(e,t){return Yi(e,eM)(t)}var Bv=/^0\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*))?$/u,Hh=Q.pipe(jt(Bv));function tM(e){let t=Yi(Hh)(e);return Qe(t)?t.right:void 0}function Kv(e){return tM(e)!==void 0}function Wv(e){return Kv(e)&&!e.includes("-")}var rM=Q.pipe(Ht(Wv));function $v(e){if(e===void 0||e.length===0||e[0]==="0")return!1;for(let t of e)if(t<"0"||t>"9")return!1;return!0}function nM(e){let[t,r,n]=e.split("-");if(t===void 0||r===void 0||n!==void 0)return!1;if(!Wv(t))return!1;let[o,i,s,a]=r.split(".");return o==="dev"&&a===void 0&&$v(i)&&$v(s)}var Vv=Q.pipe(Ht(nM)),oM=st(Hh,Vv);var jh=N("computer_use","frontend","security"),iM=N("computer_use","frontend","security"),sM=N("installed","disabled","missing","uncertain"),aM=N("healthy","missing","disabled","uncertain"),cM=Object.freeze(["openai-curated","openai-curated-remote"]),lM=Object.freeze(["build-web-apps","codex-security"]);var Vo=Object.freeze({coding:!0,computer_use:!1,frontend:!0,security:!0}),Zi=Object.freeze({frontend:Object.freeze([{skillId:"build-web-apps:frontend-app-builder",appliesWhen:"a new visually-driven UI or meaningful redesign"},{skillId:"build-web-apps:frontend-testing-debugging",appliesWhen:"a rendered UI or interaction defect"},{skillId:"build-web-apps:react-best-practices",appliesWhen:"a relevant React or Next implementation or review"}]),security:Object.freeze([]),computer_use:Object.freeze([])}),uM=Zi.frontend,pM={frontend:{name:"frontend",pluginIds:["build-web-apps@openai-curated"],defaultSelected:Vo.frontend,migrationKey:"frontend",semanticSkillIds:Object.freeze(Zi.frontend.map(({skillId:e})=>e)),applicability:Zi.frontend,ownership:"shared-preserve"},security:{name:"security",pluginIds:["codex-security@openai-curated"],defaultSelected:Vo.security,migrationKey:"security",semanticSkillIds:["codex-security:security-scan","codex-security:security-diff-scan","codex-security:threat-model"],applicability:Zi.security,ownership:"shared-preserve"},computer_use:{name:"computer_use",pluginIds:["computer-use@openai-bundled"],defaultSelected:Vo.computer_use,migrationKey:"computer_use",semanticSkillIds:["computer-use:computer-use"],applicability:Zi.computer_use,ownership:"shared-preserve"}},dM=Object.freeze(pM),fM=Object.freeze(["computer_use","frontend","security"]),mM=Object.freeze(["writing-instructions","babysit-ci"]),hM=Object.freeze({computer_use:Vo.computer_use,frontend:Vo.frontend,security:Vo.security});var Jv=N("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"),gM=D({identifier:Jv,label:Q,requiresRootApproval:ge});function Pr(e){return D({identifier:N(e),label:Q,requiresRootApproval:ge})}var yM=D({localRepositoryEdit:Pr("local.repository.edit"),localRepositoryCheck:Pr("local.repository.check"),localRepositoryLint:Pr("local.repository.lint"),localRepositoryFormat:Pr("local.repository.format"),localRepositoryCommit:Pr("local.repository.commit"),externalRead:Pr("external.read"),specialistDispatch:Pr("specialist.dispatch"),versionControlServerMutation:Pr("vcs.server.mutation"),versionControlServerCiTrigger:Pr("vcs.server.ci-trigger"),unknownEffect:Pr("unknown.effect")}),$h={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}};xr($h);var xM=N("never","root"),Yv=Object.values($h);function zv(e){let t=e.map((n)=>n.label),r=t.at(-1);if(r===void 0)return"";if(t.length===1)return r;return`${t.slice(0,-1).join(", ")}, and ${r}`}function Gv(e){return e.length===0?e:`${e[0]?.toUpperCase()??""}${e.slice(1)}`}var SM=Yv.filter((e)=>!e.requiresRootApproval),bM=Yv.filter((e)=>e.requiresRootApproval),_M=Object.freeze({noRootApproval:`${Gv(zv(SM))} actions do not require Root approval.`,rootApproval:`${Gv(zv(bM))} require Root approval.`});var yr=Q.pipe(jt(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),Bh=Q.pipe(jt(/^[0-9a-f]{64}$/u)),KK=yr.pipe(ja("RunId")),WK=yr.pipe(ja("ProjectId")),VK=yr.pipe(ja("TrustId")),zK=Bh.pipe(ja("Sha256Digest"));var wM=D({run_id:yr,objective_lineage:yr,parent_run_id:R(st(yr,dn))}),EM=D({project_id:yr,trust_id:yr,trust_digest:Bh}),OM=D({project_id:yr,project_digest:Bh}),vM=Q.pipe(jt(/^state-[0-9]+\.[0-9]+$/u));var ju=N("low","default","high"),eA=N("go","Go","plus-low","plus","plus-high","pro-5x","pro-20x"),AM=st(ju,eA);var tA=N("standard","fast","fast-all"),TM=N("low","medium","high","xhigh","max"),rA="Make the smallest complete edit set within the authorized boundary, touch no unrelated paths, avoid speculative refactors or formatting churn, and perform no redundant writes or operations; preserve unrelated work and stop for Root input before expanding scope.",hn="Do not modify repository source or the implementation under validation; observation, analysis, and proof artifacts only.",kt="Send no mid-task messages to Root or peers. Return only a terminal result, including any material blocker.",IM=N("none"),nA=Object.freeze(["implementation","review","validation","integration","vcs"]),kM=N("read-only","workspace-write"),gn=[{role:"Explorer",tasks:[{name:"map",description:"Bounded repository structure mapping specialist.",instruction:`Map the assigned repository area: locate its relevant packages, entry points, ownership boundaries, and nearby tests or docs. Return a compact path map and identify where a follow-up lookup or trace should start; do not trace runtime behavior or resolve an unrelated fact. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"lookup",description:"Repository fact lookup specialist.",instruction:`Find the specific requested repository fact and cite its exact path or symbol; keep the search narrower than a structure map or execution trace. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"trace",description:"Repository execution and reference tracing specialist.",instruction:`Follow the assigned execution or reference path across callers, boundaries, and tests; explain the evidence-backed flow and stop at the assigned boundary. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}],capability:"repository-read",authority:"Read only the delegated Assignment repository scope; Git/VCS writes, Intent lifecycle, and material decisions remain Root-only.",evidence:"Return exact paths, symbols, callers, tests, and constraints.",completion:"Account for every in-scope caller and constraint.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{role:"Librarian",tasks:[{name:"lookup",description:"Authoritative external fact lookup specialist.",instruction:`Answer the specific external fact with its current authoritative source; do not broaden into a multi-source synthesis. For current library, framework, SDK, API, CLI, or cloud-service facts, resolve the library identity and query Context7 narrowly before model memory or generic web sources. Return a typed Context7 evidence state in the context7 field with supporting version/source evidence. Use web search only when Context7 is unavailable, has no coverage or relevant results, fails for authentication or quota, the required version is missing, or a conflict remains unresolved after checking authoritative first-party documentation; successful Context7 evidence alone never justifies fallback. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"research",description:"Current authoritative-source research specialist.",instruction:`Compare and synthesize the assigned current sources with citations, noting conflicts and uncertainty rather than returning one isolated fact. For current library, framework, SDK, API, CLI, or cloud-service facts, resolve the library identity and query Context7 narrowly before model memory or generic web sources. Return a typed Context7 evidence state in the context7 field with supporting version/source evidence. Use web search only when Context7 is unavailable, has no coverage or relevant results, fails for authentication or quota, the required version is missing, or a conflict remains unresolved after checking authoritative first-party documentation; successful Context7 evidence alone never justifies fallback. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}],capability:"current-research",authority:"Research only the delegated Assignment current sources without repository mutation; Git/VCS writes, Intent lifecycle, and material 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,filesystem:"read-only",sourceMutation:!1}},{role:"Worker",tasks:[{name:"mechanical",description:"Deterministic bounded-edit specialist.",instruction:`Apply the exact already-decided transformation within the assigned files and verify it. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"implementation",description:"Bounded behavior implementation specialist.",instruction:`Design and implement the assigned behavior within its bounded seam, then verify the changed behavior. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"integration",description:"Decided seam integration specialist.",instruction:`Connect already-decided component seams, resolve interface mismatches within the assigned boundary, and verify their combined behavior. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"operations",description:"Exact-ref or SHA terminal operations observer.",instruction:`Observe the assigned CI or release gate for the Root-supplied exact ref or SHA until it reaches a terminal state; report the matching result and failure evidence. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"validation",description:"Independent local behavioral validation specialist.",instruction:`Independently exercise the assigned local behavior with the smallest relevant checks, classify failures, and report reproducible evidence; generated proof state is allowed, but do not repair the implementation or substitute for code review. ${hn} ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!1}},{name:"debugging",description:"Reproducible bounded defect-repair specialist.",instruction:`Establish the failure reproducibly, identify the evidence-backed root cause, make the narrow bounded repair, and prove the regression is gone. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}}],capability:"task-scoped-assignment",authority:"Concrete task permissions govern observation, proof writes, or source repair within the delegated Assignment; no role-level source-mutation authority is granted. Intent lifecycle, Git/VCS writes, and material choices remain Root-only.",evidence:"Return changed files, verification results, and remaining risk.",completion:"Finish the delegated Assignment with proportional proof or an exact blocker and return a compact structured outcome.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{role:"Reviewer",tasks:[{name:"plan",description:"Adversarial implementation-plan review specialist.",instruction:`Adversarially inspect the assigned implementation plan for missing requirements, invalid assumptions, unsafe ordering, unowned seams, and inadequate proof. Return actionable plan findings or a fixed-point verdict; do not implement the plan. ${hn} ${kt}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"code",description:"Adversarial implemented-code review specialist.",instruction:`Review and repair the implemented code to a fixed point. Use one batched evidence sweep, reason over it, make targeted follow-ups only, and batch related repairs and verification. The acceptance contract covers correctness, safety, compatibility, mergeability, clarity, simplicity, cohesion, idiomaticity, appropriate abstraction, accidental complexity, duplication, unnecessary files or file splitting, speculative abstraction, test quality, and generated-artifact hygiene. Prefer simple cohesive code over clever or over-engineered code. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"artifact",description:"Adversarial produced-artifact review specialist.",instruction:`Inspect the assigned produced artifact against its requested content, usability, and delivery constraints; repair concrete defects within the artifact boundary and repeat inspection until no actionable findings remain. ${kt}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}}],capability:"task-scoped-review",authority:"Concrete task permissions govern observational review or bounded repair within the delegated Assignment; no role-level source-mutation authority is granted. Intent lifecycle, Git/VCS writes, 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 as a compact structured outcome.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}];xr(gn);var oA=new Map(gn.map((e)=>[e.role,e])),RM=new Set(gn.map((e)=>e.role)),Kh=gn.flatMap((e)=>e.tasks.map((t)=>`${e.role}:${t.name}`)),CM=new Set(Kh),iA=Kh.map((e)=>e.replace(":",".")),sA=new Set(iA);function aA(e){return typeof e==="string"&&RM.has(e)}function PM(e){if(typeof e!=="object"||e===null||!("role"in e)||!("task"in e))return!1;let{role:t,task:r}=e;if(!aA(t)||typeof r!=="string")return!1;return oA.get(t)?.tasks.some((n)=>n.name===r)===!0}function $u(e,t){return typeof t==="string"&&oA.get(e)?.tasks.some((r)=>r.name===t)===!0}function cA(e){return typeof e==="string"&&CM.has(e)}var Wh=Ut(aA),FM=Ut((e)=>$u("Explorer",e)),NM=Ut((e)=>$u("Librarian",e)),MM=Ut((e)=>$u("Worker",e)),LM=Ut((e)=>$u("Reviewer",e)),$a=Ut(PM),zo=Object.freeze(Kh.filter((e)=>cA(e))),lA=Ut(cA),uA=Object.freeze(iA.filter((e)=>sA.has(e))),DM=Ut((e)=>typeof e==="string"&&sA.has(e)),pA=Object.freeze(["worker","explorer","reviewer","librarian"]);var dA=D({profile:ju,service_tier:R(tA)}),Hu=Object.freeze(["user_interaction","intent","material_decisions","orchestration_lifecycle","integration_acceptance","completion","git_vcs","external_effects","gui_browser","computer_use"]),qM=N(...Hu),UM=N("delegated","root_direct","unavailable"),HM=N(...Hu),Vh=N("used","no_coverage","unavailable","auth_or_quota_failure","source_conflict"),fA=Object.freeze({rule:"Run meaningful proof appropriate to changed behavior plus repository-required checks.",avoidImplementationMirrorTestsForLowImpactReversibleChanges:!0,broadenOrRepeatOnlyAfter:Object.freeze(["source_change","proof_failure","unresolved_material_concern"]),mandatoryRepositoryGatesRemainRequired:!0,reviewerCodeRemainsRequired:!0}),jM=Object.freeze({requiredFor:Object.freeze(["library","framework","sdk","api","cli","cloud_service"]),resolveIdentityBeforeQuery:!0,queryNarrowly:!0,evidenceStates:Object.freeze(["used","no_coverage","unavailable","auth_or_quota_failure","source_conflict"]),webFallbackEvidenceStates:Object.freeze(["no_coverage","unavailable","auth_or_quota_failure"]),missingRequiredVersionAllowsFallback:!0,successfulEvidenceAloneAllowsFallback:!1,checkFirstPartyDocsBeforeFallbackForConflict:!0,unresolvedConflictAfterFirstPartyAllowsFallback:!0,materialDecisionsRemainRootOwned:!0}),$M=/\b(?:libraries?|frameworks?|sdks?|apis?|clis?|cloud[ _-]?services?|packages?|dependencies?|technical|documentation|docs?|context7)\b/iu,BM=/\b(?:historical|history|legacy|archived?|past)\b/iu;function zh(e){if(e.role!=="Librarian"||e.task!=="lookup"&&e.task!=="research")return!1;let t=[e.objective,...e.scope,...e.constraints,...e.exclusions,...e.dependencies,...e.acceptanceCriteria].join(" ");return $M.test(t)&&!BM.test(t)}var KM=Object.freeze({repositoryAndUserRequirementsPrecedePluginDefaults:!0,specialistsOwnInspectionImplementationAndRepair:!0,rootOwnsLiveVisualAndInteractionAcceptance:!0,sourceChangesInvalidateRenderEvidence:!0,specialistReportsCannotSubstituteForRootAcceptance:!0,logicOnlyChangesRequireVisualAcceptance:!1,fixedPoint:Object.freeze(["specialist_implements","root_renders_opens_and_interacts","root_judges_current_result","root_delegates_discrepancies","specialist_repairs","root_rerenders_and_retests"])}),WM=Object.freeze({interactiveCapabilitiesRemainRootOwned:!0,credentialEntryAndSubmissionRemainUserOwned:!0,useDefaultBrowserWithComputerUse:!0,agentsMustNeverHandleCredentials:!0,authenticationSequence:Object.freeze(["root_navigates_to_authentication","root_hands_control_to_user","user_enters_and_submits_credentials","root_waits_for_completion","root_resumes_authenticated_session"]),missingAuthorizedPathIsCapabilityBlocker:!0}),VM=Object.freeze({threatModelForMaterialTrustBoundaryChanges:!0,securityDiffScanRequiredForSecuritySensitiveDiffs:!0,fullScanOnlyForAuditNewExposedSurfaceOrSystemicConcern:!0,validateSupportedFindingsBeforeBlocking:!0,introducedOrWorsenedValidatedVulnerabilityBlocksVcs:!0,preExistingUnrelatedFindingsDoNotExpandScope:!0,securityEditsInvalidateCodeReview:!0,securitySensitiveCodeReviewEditsInvalidateSecurityReview:!0,materialDecisionsRemainRootOwned:!0}),zM=Object.freeze({requiresDelegation:!0,assignmentStartAndDispatchPrecedeDelegableExecution:!0,trivialWorkRequiresDelegation:!0,preparatoryAndExploratoryWorkRequiresDelegation:!0,genericDirectWorkFallback:!1,concreteSpecialistDispatchRequired:!0,registeredSpecialistAgentTypes:uA,roleFamiliesAreLabelsOnly:!0,forbiddenGenericAgentTypes:pA,missingConcreteRouteIsBlocker:!0,delegableActions:Object.freeze(["repository_discovery","file_source_test_doc_inspection","fact_finding","research","implementation","debugging","testing","validation","frontend_work","security_work","review","ci_release_observation"]),directExecutionExceptions:Hu,rootOwnedAuthority:Hu,requestUserInputGates:Object.freeze(["plan_approval","installation_profile_approval","remote_origin_server_vcs_mutation","public_publication_or_release","ambiguity_or_missing_material_input"]),surgicalMutationRule:rA,phaseOrder:nA,phaseGates:Object.freeze({implementationLeavesTerminalBeforeReviewerCode:!0,reviewerCodeFixedPointBeforeWorkerValidation:!0,workerValidationBeforeRootIntegration:!0,rootIntegrationBeforeVcs:!0}),initialDispatch:Object.freeze({independentAssignments:!0,substantiveIndependentConcurrency:!0,routinePostdispatchSteering:!1,collectiveWaits:!0,evidenceReusedAcrossPhases:!0}),atomicLifecycleTransitions:Object.freeze({relatedAssignmentAndIntentWrites:!0,oneLockOneCommit:!0,staleRevisionChecksRetained:!0,repositoryDriftChecksRetained:!0}),supersession:Object.freeze({explicitOnly:!0,unfinishedPredecessorOnly:!0,validatedRelatedReplacement:!0,reasonAndProvenanceRequired:!0,supersededExcludedFromCompletionBlockers:!0}),specialistTerminalResultPersistence:Object.freeze({ownActiveInvocationCapabilityRequired:!0,ownAssignmentOnly:!0,terminalOutcomeOnly:!0,rootOwnedIntentLifecycle:!0,rootOwnedAcceptanceReviewAndCiGates:!0,rootOwnedVcsAndExternalEffects:!0,sharedRuntimeCallerIdentityUnavailable:!0,legacyResultCompatibilityPreserved:!0}),normalSpawnForkTurns:"none",normalSpawnRequiresExplicitForkTurns:!0,normalSpawnUsesConcreteRegisteredAgentType:!0,assignmentContextIsTaskSpecificOnly:!0,configuredRouteModelAndEffortPreserved:!0,normalProgressMessages:!1,normalHeartbeatMessages:!1,normalIntermediateEvidence:!1,userUpdatesUsefulOrImportantOnly:!0,routinePerToolOrSubagentNarrationForbidden:!0,routineStatusOnlyChatterForbidden:!0,fixedCadenceUserUpdatesForbidden:!0,materialUserUpdateKinds:Object.freeze(["significant_findings_or_decisions","consequential_blockers_or_input_needs","release_milestones"]),outOfBoundaryRequiresNewAssignment:!0,routineWaitTool:"collaboration.wait_agent",routineWaitMaximumTimeoutMs:1200000,routineWaitUsesMaximumRuntimeTimeout:!0,earlySpecialistCompletionWakesWait:!0,collectiveMailboxIncludesRelevantAgents:!0,idleTimeoutRepeatsMaximumWait:!0,shortRoutineWaitsForbidden:!0,longestPracticalEventWait:!0,busyPollingForbidden:!0,statusOnlyCoordinationLoopsForbidden:!0,batchIndependentLifecycleActions:!0,releaseLeavesAfterAcceptedOutcome:!0,specialistOutcomes:Object.freeze(["completed","blocked","needs_root_input","failed"]),evidenceFirstConciseStructuredReports:!0,specialistReportFields:Object.freeze(["changed paths","checks","observable evidence","blockers","Root decisions needed","remaining risk"]),rootLargeReadsOnlyFor:Object.freeze(["material decisions","conflicts","failures","findings"]),stableFactsReused:!0,duplicatePolicyForbidden:!0,stableBoundedComponentScopesAreCanonical:!0,lifecycleWorkerOwnsDeterministicApi:!0,materialDecisionsRemainRootOwned:!0,lifecycleRemainsRootOwned:!0,integrationAndCompletionRemainRootOwned:!0,routineSafeReversibleInScopeDecisionsProceedAutonomously:!0,userInstructionsOverrideSkillGuidelinesExceptHardInvariants:!0,authorizedWorkContinuesThroughRequestedTerminalState:!0,testingPolicy:fA,codeReviewRequiredForImplementation:!0,codeReviewRequiredBeforeVcs:!0,externalVerificationMustBeTerminal:!0,postVcsFlow:"discover_topology_observe_repair_repeat"});function at(e,t){return new ht("invalid_canonical_value",`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function Gh(e,t,r){if(e===null)return"null";switch(typeof e){case"string":{let n=JSON.stringify(e);if(n===void 0)throw at(t,"invalid string");return n}case"boolean":return e?"true":"false";case"number":{if(!Number.isFinite(e))throw at(t,"non-finite number");let n=JSON.stringify(e);if(n===void 0)throw at(t,"invalid number");return n}case"undefined":throw at(t,"undefined is not JSON");case"bigint":throw at(t,"bigint is not JSON");case"function":throw at(t,"function is not JSON");case"symbol":throw at(t,"symbol is not JSON");case"object":break}if(r.has(e))throw at(t,"cyclic value");r.add(e);try{if(Array.isArray(e)){for(let a of Object.getOwnPropertySymbols(e))throw at(t,`symbol property ${String(a)}`);let i=e,s=[];for(let a=0;a<i.length;a+=1){let c=Object.getOwnPropertyDescriptor(i,String(a));if(!c||!c.enumerable||!("value"in c))throw at(`${t}[${a}]`,"sparse or accessor array item");s.push(Gh(c.value,`${t}[${a}]`,r))}for(let a of Object.getOwnPropertyNames(i)){if(a==="length")continue;let c=Number(a);if(!Number.isInteger(c)||c<0||c>=i.length||String(c)!==a)throw at(t,`non-index array property ${a}`);let l=Object.getOwnPropertyDescriptor(i,a);if(!l||!l.enumerable||!("value"in l))throw at(`${t}[${c}]`,"non-enumerable or accessor array item")}return`[${s.join(",")}]`}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw at(t,"only plain objects are supported");for(let i of Object.getOwnPropertySymbols(e))throw at(t,`symbol property ${String(i)}`);for(let i of Object.getOwnPropertyNames(e)){let s=Object.getOwnPropertyDescriptor(e,i);if(!s||!s.enumerable||!("value"in s))throw at(`${t}.${i}`,"non-enumerable or accessor property")}let o=[];for(let i of Object.keys(e).sort()){let s=Object.getOwnPropertyDescriptor(e,i);if(!s||!("value"in s))throw at(`${t}.${i}`,"accessor property");o.push(`${JSON.stringify(i)}:${Gh(s.value,`${t}.${i}`,r)}`)}return`{${o.join(",")}}`}finally{r.delete(e)}}function Jh(e){return Gh(e,"$",new Set)}var mA=N("blocked","completed","failed","partial"),hA=st(N("high","max","xhigh"),dn);function gA(e){try{return Jh(e)!==void 0}catch{return!1}}var yA=Ut((e)=>gA(e)),JM=Ut((e)=>pp(e)&&!Array.isArray(e)&&gA(e)),YM=D({blocked:ge,changed_files:W(Q),confidence:qu,context_owner:st(Q,dn),material_findings:W(Q),needs_more_context:ge,needs_root_decision:ge,needs_verification:ge,relevant_files:W(Q),remaining_risk:W(Q),reuse_recommended:ge,status:mA,suggested_followup:st(Q,dn),suggested_luna_effort:hA,suggested_specialist:st(Wh,dn),verification:W(Q),verification_passed:ge}),Yh="holycodex-specialist-outcome-2",Je=Q.pipe(Uv(1)),Qi=D({state:Vh,evidence:W(Je).pipe(Cr(1)),library:R(Je),version:R(Je)}),Ba={protocol_version:N(Yh),route:$a,evidence:W(Je),context7:R(Qi)},ZM=D(Ba),QM=D({...Ba,status:N("completed"),summary:Je}),XM=D({...Ba,status:N("blocked"),reason:Je,needs_root_decision:ge}),eL=D({...Ba,status:N("partial"),summary:Je,completed:W(Je),remaining:W(Je),needs_root_decision:ge}),tL=D({...Ba,status:N("failed"),error:Je}),rL=st(QM,XM,eL,tL),Bu={protocol_version:N(Yh),capability:jh,route:st($a,dn),evidence:W(Je),context7:R(Qi),data:yA},nL=D({...Bu,status:N("completed"),summary:Je}),oL=D({...Bu,status:N("blocked"),reason:Je,needs_root_decision:ge}),iL=D({...Bu,status:N("partial"),summary:Je,completed:W(Je),remaining:W(Je),needs_root_decision:ge}),sL=D({...Bu,status:N("failed"),error:Je}),aL=st(nL,oL,iL,sL);var xA=W(Q),SA=Q.pipe(jt(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),bA=N(up),cL=D({code:yr,message:Q,details:JM}),_A=D({schema_version:bA,ok:N(!0),command:SA,data:yA,warnings:xA}),wA=D({schema_version:bA,ok:N(!1),command:SA,error:cL,warnings:xA}),lL=st(_A,wA);var Xh="gpt-6-astra",Qh="gpt-6-sol",Ka="gpt-6-luna";function uL(e,t,r){return{key:`${e}:${t}`,role:e,task:t,model:Ka,effort:r}}var pL=new Set(zo),EA={low:0,medium:1,high:2,xhigh:3,max:4},eg=[{profile:"low",rationale:"The low profile keeps bounded specialist work economical.",efforts:{"Explorer:map":"medium","Explorer:lookup":"medium","Explorer:trace":"high","Librarian:lookup":"medium","Librarian:research":"high","Worker:mechanical":"high","Worker:implementation":"high","Worker:integration":"max","Worker:operations":"high","Worker:validation":"medium","Worker:debugging":"high","Reviewer:plan":"high","Reviewer:code":"max","Reviewer:artifact":"high"}},{profile:"default",rationale:"The default profile is the recommended balanced route.",efforts:{"Explorer:map":"high","Explorer:lookup":"medium","Explorer:trace":"xhigh","Librarian:lookup":"medium","Librarian:research":"xhigh","Worker:mechanical":"high","Worker:implementation":"xhigh","Worker:integration":"max","Worker:operations":"high","Worker:validation":"high","Worker:debugging":"xhigh","Reviewer:plan":"xhigh","Reviewer:code":"max","Reviewer:artifact":"xhigh"}},{profile:"high",rationale:"The high profile maximizes specialist reasoning where specified.",efforts:{"Explorer:map":"high","Explorer:lookup":"medium","Explorer:trace":"max","Librarian:lookup":"medium","Librarian:research":"max","Worker:mechanical":"xhigh","Worker:implementation":"max","Worker:integration":"max","Worker:operations":"xhigh","Worker:validation":"xhigh","Worker:debugging":"max","Reviewer:plan":"max","Reviewer:code":"max","Reviewer:artifact":"max"}}];xr(eg);var dL=new Map(eg.map((e)=>[e.profile,e]));function fL(e){let t=dL.get(e);if(t===void 0)throw new ht("catalog_invalid","A profile has no route effort policy.",{profile:e});return gn.flatMap((r)=>r.tasks.map((n)=>{let o=`${r.role}:${n.name}`,i=t.efforts[o];if(i===void 0)throw new ht("catalog_invalid","A route effort policy is incomplete.",{profile:e,route:o});return uL(r.role,n.name,i)}))}function Zh(e){return{name:e.name,root:{model:e.rootModel,effort:e.rootEffort},specialistModel:Ka,defaultServiceTier:"standard",routes:fL(e.name)}}var tg=[Zh({name:"low",rootModel:Qh,rootEffort:"medium"}),Zh({name:"default",rootModel:Qh,rootEffort:"high"}),Zh({name:"high",rootModel:Xh,rootEffort:"high"})];function mL(e){let t=["low","default","high"];if(e.length!==t.length)throw new ht("catalog_invalid","The profile catalog has an invalid size.");for(let r=0;r<t.length;r+=1){let n=e[r],o=t[r];if(!n||n.name!==o)throw new ht("catalog_invalid","The profile catalog order is invalid.",{index:r});let i=o==="high"?Xh:Qh,s=o==="low"?"medium":"high";if(n.root.model!==i||n.root.effort!==s||n.specialistModel!==Ka)throw new ht("catalog_invalid","A profile has an invalid model route.",{profile:n.name});if(n.routes.length!==zo.length)throw new ht("catalog_invalid","A profile is incomplete.",{profile:n.name});let a=new Set;for(let c of n.routes){if(a.has(c.key)||!pL.has(c.key)||c.model!==Ka||`${c.role}:${c.task}`!==c.key)throw new ht("catalog_invalid","A profile contains an invalid route.",{profile:n.name});a.add(c.key)}if(a.size!==zo.length)throw new ht("catalog_invalid","A profile is missing a specialist route.",{profile:n.name})}for(let r=0;r<zo.length;r+=1){let n=-1;for(let o of e){let i=o.routes[r];if(!i||EA[i.effort]<n)throw new ht("catalog_invalid","Profile route effort is not monotonic.",{route:zo[r]??"unknown"});n=EA[i.effort]}}}mL(tg);xr(tg);var OA=tg,hL=new Map,gL=new Map;for(let e of OA){hL.set(e.name,e);let t=new Map;for(let r of e.routes)t.set(r.key,r);gL.set(e.name,t)}import{execFile as yL}from"child_process";import{createHash as xL,randomBytes as SL}from"crypto";import{lstat as Nr,mkdir as es,open as Qu,readFile as cg,readdir as Yo,realpath as bL,rename as _L,rm as Zo,stat as wL}from"fs/promises";import{basename as rg,dirname as Qo,isAbsolute as EL,join as T,relative as ag,resolve as rs}from"path";import{promisify as OL}from"util";var Xu="holycodex-intent-1",lg="holycodex-plan-1",ug="holycodex-assignment-1",Qn="toon-4",L=Q.pipe(Ht((e)=>e.trim().length>0)),Ye=Q.pipe(jt(/^[a-z0-9][a-z0-9-]{0,95}$/u)),ep=Q.pipe(jt(/^[a-f0-9]{64}$/u)),FA=Q.pipe(jt(/^[a-f0-9]{40}$/u)),ns=Uu.pipe(jv(1)),Qt=Q.pipe(Ht((e)=>!Number.isNaN(Date.parse(e)))),Ie=W(L),vL=D({pid:Uu.pipe(Hv(0)),token:L}),AL=120000,TL=4294967295,pg=D({role:N("Explorer","Librarian","Worker","Reviewer"),task:L}).pipe(Ht((e)=>gn.some((t)=>t.role===e.role&&t.tasks.some((r)=>r.name===e.task)))),Xo=D({kind:N("changed_path","check","repository_fact","ci","behavior","uncertainty"),value:L,result:R(N("passed","failed","observed","unknown"))}),dg=D({root:L,git_common_dir:L,initial_head:L,expected_head:L,expected_changes:Ie,expected_status_digest:ep,integrated_commit:R(FA),updated_at:Qt}),os=N("scoping","ready","executing","verifying","reviewing","blocked","needs_root_input","complete","abandoned"),IL=N("scoping","ready","executing","verifying","reviewing"),vA=D({required:ge,status:N("not_required","missing","passed","failed","accepted","rejected"),evidence:W(Xo)}),ts=D({schema_version:N(Xu),toon_compatibility:N(Qn),id:Ye,slug:Ye,title:L,goal:L,acceptance_criteria:Ie,state:os,revision:ns,plan_required:ge,active_plan_revision:R(ns),active_plan_digest:R(ep),blockers:Ie,resume_state:R(IL),verification:vA,review:vA,acceptance_met:ge,root_readiness:ge,evidence:W(Xo),baseline:dg,created_at:Qt,updated_at:Qt}),zu=D({schema_version:N(lg),toon_compatibility:N(Qn),intent_id:Ye,revision:ns,predecessor_digest:R(ep),approach:L,scope:Ie,exclusions:Ie,assignments:Ie,dependencies:Ie,architecture:Ie,risks:Ie,assumptions:Ie,open_questions:Ie,verification:Ie,recovery:Ie,updated_at:Qt}),fg=N("completed","blocked","needs_root_input","failed"),NA=N("pending","executing","completed","blocked","needs_root_input","failed","superseded"),mg=D({id:Ye,outcome:fg,started_at:Qt,finished_at:Qt,summary:L,evidence:W(Xo),context7:R(Qi),blocker:R(L),remaining_risk:Ie}),Ja=ep,hg={schema_version:N(ug),toon_compatibility:N(Qn),intent_id:Ye,id:Ye,objective:L,owner:pg,scope:Ie,constraints:Ie,exclusions:Ie,dependencies:Ie,acceptance_criteria:Ie,status:NA,revision:ns,invocations:W(mg),active_invocation_id:R(L),active_started_at:R(Qt),supersedes:R(Ye),superseded_by:R(Ye),supersession_reason:R(L),supersession_provenance:R(L),evidence:W(Xo),blocker:R(L),remaining_risk:Ie,created_at:Qt,updated_at:Qt},gg=D(hg),MA=D({...hg,capability:Ja}),Gu=D({...hg,active_invocation_capability_verifier:R(Ja),active_invocation_capability:R(Ja)}),ng=".holycodex-transaction.toon",LA="holycodex-work-state-transaction-1",AA=D({schema_version:N(LA),state:N("prepared","committed"),files:W(D({path:L,previous:Q,next:Q})).pipe(Cr(1))}),kL=D({schema_version:N("holycodex-intent-0"),id:Ye,slug:Ye,title:L,goal:L,acceptance_criteria:Ie,state:os,revision:ns,baseline:dg,created_at:Qt,updated_at:Qt});class y extends Error{code;details;constructor(e,t,r={}){super(t);this.name="IntentStoreError",this.code=e,this.details=r}}var tp=D({title:L,goal:L,acceptanceCriteria:W(L).pipe(Cr(1)),planRequired:R(ge),verificationRequired:R(ge),reviewRequired:R(ge)}),rp=D({approach:L,scope:R(W(L)),exclusions:R(W(L)),assignments:R(W(L)),dependencies:R(W(L)),architecture:R(W(L)),risks:R(W(L)),assumptions:R(W(L)),openQuestions:R(W(L)),verification:R(W(L)),recovery:R(W(L))}),np=D({id:R(L),objective:L,owner:pg,scope:W(L).pipe(Cr(1)),constraints:R(W(L)),exclusions:R(W(L)),dependencies:R(W(L)),acceptanceCriteria:W(L).pipe(Cr(1))}),op=D({scope:W(L).pipe(Cr(1))}),ip=D({scope:R(W(L).pipe(Cr(1)))}),sp=D({replacementId:Ye,replacementRevision:R(ns),reason:L,provenance:L}),ap=D({commit:FA}),Ya=D({invocationId:R(L),capability:R(Ja),outcome:fg,startedAt:R(L),summary:L,scope:R(W(L).pipe(Cr(1))),evidence:R(W(Xo)),context7:R(Qi),blocker:R(L),remainingRisk:R(W(L))}),RL=D({invocationId:L,startedAt:Qt,interruptionReason:L}),cp=D({evidence:R(W(Xo)),verification:R(N("passed","failed")),review:R(N("accepted","rejected")),acceptanceMet:R(ge),rootReadiness:R(ge),clearBlockers:R(ge)}),Za=OL(yL);class lp{repositoryRoot;stateRoot;#e;#s;constructor(e,t={}){this.repositoryRoot=rs(e),this.stateRoot=T(this.repositoryRoot,".holycodex"),this.#e=t.now??(()=>new Date),this.#s=t.repositorySnapshot??(()=>DA(this.repositoryRoot))}async recover(){if(await this.#a(),!await Wu(this.stateRoot))return[];return await Jo(T(this.stateRoot,".intent-store"),async()=>{let e=await this.#l(this.stateRoot),t=await this.#h();return[...e,...t].sort()})}async#l(e,t=!1){let r;try{r=t?await Yo(e,{recursive:!0}):await Yo(e)}catch(o){if(me(o,"ENOENT"))return[];throw ve(o)}let n=[];for(let o of r){let i=rg(o);if(!i.startsWith(".holycodex-write-")||!i.endsWith(".tmp"))continue;let s=T(e,o);await eo(s),await Zo(s,{force:!0}),n.push(ag(this.stateRoot,s).replaceAll("\\","/"))}return n.sort()}async#h(){let e;try{e=await Yo(this.stateRoot)}catch(r){if(me(r,"ENOENT"))return[];throw ve(r)}let t=[];for(let r of e){if(r===".intent-store")continue;let n=T(this.stateRoot,r);if(!await Vu(n))continue;await Jo(T(n,".intent-store"),async()=>{t.push(...await this.#u(n))})}return t.sort()}async#u(e){let t=[],r=T(e,ng);if(await this.#d(e))t.push(ag(this.stateRoot,r).replaceAll("\\","/"));return t.push(...await this.#l(e,!0)),t}async#d(e){let t=T(e,ng);await eo(t);let r;try{r=await Nr(t)}catch(l){if(me(l,"ENOENT"))return!1;throw ve(l)}if(r.isSymbolicLink()||!r.isFile())throw new y("schema_invalid","The work-state transaction journal must be a regular file.",{path:t});let n=await Va(t,AA),o=n.files.filter((l)=>Xn(l.path)==="intent.toon"),i=n.files.filter((l)=>{let u=Xn(l.path);return u!==void 0&&/^assignments\/[a-z0-9][a-z0-9-]{0,95}\.toon$/u.test(u)});if(n.files.length<2||o.length!==1||i.length<1||o.length+i.length!==n.files.length)throw new y("schema_invalid","The work-state transaction must pair one or more Assignments with their Intent.",{path:t});let s=new Set,a=n.files.map((l)=>{let u=Xn(l.path);if(u===void 0)throw new y("schema_invalid","The work-state transaction contains an invalid target path.",{path:t,target:l.path});let d=RA(e,l.path);if(s.has(d))throw new y("schema_invalid","The work-state transaction has duplicate targets.",{path:t,target:l.path});s.add(d);let f=n.state==="committed"?l.next:l.previous,h=u==="intent.toon"?CA(f,ts,d):CA(f,Gu,d);return{canonical:u,target:d,contents:f,record:h}}),c=a.find((l)=>l.canonical==="intent.toon")?.record?.id;if(c===void 0)throw new y("schema_invalid","The work-state transaction has no Intent.",{path:t});for(let l of a)if(await eo(l.target),l.canonical!=="intent.toon"){let u=l.canonical.slice(12,-5);sg(l.record,c,u,l.target)}for(let l of a)await Ga(l.target,l.contents);return await Zo(t,{force:!0}),await Zu(e),!0}async#a(){try{let e=await Nr(this.stateRoot);if(e.isSymbolicLink()||!e.isDirectory())throw new y("schema_invalid","Repository-local work state must be a real directory.",{path:this.stateRoot})}catch(e){if(me(e,"ENOENT"))return;throw ve(e)}}async createIntent(e){let t=se(tp,e);if(!t.title.trim()||!t.goal.trim()||t.acceptanceCriteria.length===0)throw Ct("Intent title, goal, and acceptance criteria are required.");return await this.recover(),await es(this.stateRoot,{recursive:!0}),await Jo(T(this.stateRoot,".intent-store"),async()=>{let r=await this.#s(),n=DL(t.title),o=Fr([r.root,t.title.trim(),t.goal.trim()].join("\x00")).slice(0,10),i=`${n}-${o}`,s=1;while(await Wu(T(this.stateRoot,i)))s+=1,i=`${n}-${o}-${String(s).padStart(2,"0")}`;let a=`intent-${o}${s===1?"":`-${String(s).padStart(2,"0")}`}`,c=this.#e().toISOString(),l=se(ts,{schema_version:Xu,toon_compatibility:Qn,id:a,slug:n,title:t.title.trim(),goal:t.goal.trim(),acceptance_criteria:[...t.acceptanceCriteria],state:"scoping",revision:1,plan_required:t.planRequired??!1,blockers:[],verification:Ju(t.verificationRequired??!0),review:Ju(t.reviewRequired??!0),acceptance_met:!1,root_readiness:!1,evidence:[],baseline:og(r,c),created_at:c,updated_at:c}),u=T(this.stateRoot,i);return await es(T(u,"assignments"),{recursive:!0}),await St(T(u,"intent.toon"),l),await Ga(T(this.stateRoot,"current"),`${i}
|
|
38
|
-
`),l})}async listIntents(){if(await this.#a(),!await Wu(this.stateRoot))return[];return await Jo(T(this.stateRoot,".intent-store"),async()=>{await this.#l(this.stateRoot);let e;try{e=await Yo(this.stateRoot)}catch(r){if(me(r,"ENOENT"))return[];throw ve(r)}let t=[];for(let r of e.sort()){if(r===".intent-store")continue;let n=T(this.stateRoot,r);if(!await Vu(n))continue;await Jo(T(n,".intent-store"),async()=>{await this.#u(n);let o=T(n,"intent.toon");if(await za(o))t.push(await this.#t(o))})}return t.sort((r,n)=>r.id.localeCompare(n.id))})}async readIntent(e){let t=await this.#r(e);return await this.#n(t,async()=>this.#t(T(t,"intent.toon")))}async currentIntent(){await this.#a(),await this.recover();let e=T(this.stateRoot,"current"),t=await Nr(e).catch((o)=>{if(me(o,"ENOENT"))return;throw ve(o)});if(t?.isSymbolicLink()||t&&!t.isFile())throw new y("schema_invalid","The current Intent pointer must be a regular file.");let r=t?(await cg(e,"utf8")).trim():"";if(t&&!r)throw new y("schema_invalid","The current Intent pointer must select a work-state directory.");if(r){let o=rs(this.stateRoot,r);if(!$A(this.stateRoot,o))throw new y("schema_invalid","The current Intent pointer escapes repository-local state.",{directory:r});if(!await Vu(o))throw new y("schema_invalid","The current Intent pointer does not select a work-state directory.",{directory:r});return await this.#n(o,async()=>this.#t(T(o,"intent.toon")))}let n=(await this.listIntents()).filter((o)=>o.state!=="complete"&&o.state!=="abandoned");if(n.length===1)return n[0];throw new y(n.length?"current_ambiguous":"not_found",n.length?"Multiple active Intents require explicit selection.":"No current Intent exists.",{intent_ids:n.map((o)=>o.id)})}async selectCurrent(e){let t=await this.#r(e),r=await this.#t(T(t,"intent.toon"));return await Jo(T(this.stateRoot,".intent-store"),async()=>Ga(T(this.stateRoot,"current"),`${rg(t)}
|
|
39
|
-
`)
|
|
40
|
-
`);if(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`,
|
|
44
|
-
|
|
45
|
-
`,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
`
|
|
54
|
-
`)}async function
|
|
55
|
-
|
|
36
|
+
schema (${n._tag}): ${n}`;return o},lO=(e)=>Yn("Invalid Argument",e);var uO=(e)=>Yn("Unsupported key schema",void 0,void 0,e),pO=(e)=>Yn("Unsupported literal",`literal value: ${_r(e)}`),Gm=(e)=>Yn("Duplicate index signature",`${e} index signature`),dO=Yn("Unsupported index signature parameter","An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),fO=Yn("Invalid element","A required element cannot follow an optional element. ts(1257)"),Jm=(e)=>Yn("Duplicate property signature transformation",`Duplicate key ${_r(e)}`);var Ym=(e)=>Yn("Duplicate property signature",`Duplicate key ${_r(e)}`);var hO=Symbol.for("effect/SchemaId/DateFromSelf"),gO=Symbol.for("effect/SchemaId/GreaterThan"),yO=Symbol.for("effect/SchemaId/GreaterThanOrEqualTo");var xO=Symbol.for("effect/SchemaId/Int");var SO=Symbol.for("effect/SchemaId/MinLength");var bO=Symbol.for("effect/SchemaId/MinItems");var wO=Symbol.for("effect/annotation/TypeConstructor"),Xm=Symbol.for("effect/annotation/Brand"),EO=Symbol.for("effect/annotation/SchemaId"),eh=Symbol.for("effect/annotation/Message"),Ou=Symbol.for("effect/annotation/MissingMessage"),vu=Symbol.for("effect/annotation/Identifier"),At=Symbol.for("effect/annotation/Title"),Au=Symbol.for("effect/annotation/AutoTitle"),ln=Symbol.for("effect/annotation/Description"),th=Symbol.for("effect/annotation/Examples"),rh=Symbol.for("effect/annotation/Default"),nh=Symbol.for("effect/annotation/JSONSchema"),oh=Symbol.for("effect/annotation/Arbitrary"),ih=Symbol.for("effect/annotation/Pretty"),sh=Symbol.for("effect/annotation/Equivalence"),OO=Symbol.for("effect/annotation/Documentation"),ah=Symbol.for("effect/annotation/Concurrency"),ch=Symbol.for("effect/annotation/Batching"),lh=Symbol.for("effect/annotation/ParseIssueTitle"),uh=Symbol.for("effect/annotation/ParseOptions"),ph=Symbol.for("effect/annotation/DecodingFallback"),dh=Symbol.for("effect/annotation/Surrogate"),fh=Symbol.for("effect/annotation/StableFilter"),ot=p(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?F(e.annotations[t]):A());var mh=ot(Xm);var vO=ot(eh),AO=ot(Ou),hh=ot(At),gh=ot(Au),Ca=ot(vu),yh=ot(ln);var TO=ot(ah),IO=ot(ch),RO=ot(lh),kO=ot(uh),CO=ot(ph),xh=ot(dh),nF=ot(fh),Sh=(e)=>Fy(nF(e),(t)=>t===!0),bh=Symbol.for("effect/annotation/JSONIdentifier"),oF=ot(bh),iF=(e)=>rr(oF(e),()=>Ca(e));class zi{typeParameters;decodeUnknown;encodeUnknown;annotations;_tag="Declaration";constructor(e,t,r,n={}){this.typeParameters=e,this.decodeUnknown=t,this.encodeUnknown=r,this.annotations=n}toString(){return pe(Cr(this),()=>"<declaration schema>")}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map((e)=>e.toJSON()),annotations:Ee(this.annotations)}}}var Pa=(e)=>(t)=>t._tag===e;class Vo{literal;annotations;_tag="Literal";constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return pe(Cr(this),()=>_r(this.literal))}toJSON(){return{_tag:this._tag,literal:_n(this.literal)?String(this.literal):this.literal,annotations:Ee(this.annotations)}}}var Tu=Pa("Literal"),PO=new Vo(null);class Iu{symbol;annotations;_tag="UniqueSymbol";constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return pe(Cr(this),()=>_r(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:Ee(this.annotations)}}}class NO{annotations;_tag="UndefinedKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var Ru=new NO({[At]:"undefined"});class FO{annotations;_tag="VoidKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var sF=new FO({[At]:"void"});class MO{annotations;_tag="NeverKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var ku=new MO({[At]:"never"});class LO{annotations;_tag="UnknownKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var DO=new LO({[At]:"unknown"});class qO{annotations;_tag="AnyKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var UO=new qO({[At]:"any"});class HO{annotations;_tag="StringKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var jO=new HO({[At]:"string",[ln]:"a string"}),Cu=Pa("StringKeyword");class $O{annotations;_tag="NumberKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var BO=new $O({[At]:"number",[ln]:"a number"});class WO{annotations;_tag="BooleanKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var KO=new WO({[At]:"boolean",[ln]:"a boolean"});class VO{annotations;_tag="BigIntKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var aF=new VO({[At]:"bigint",[ln]:"a bigint"});class zO{annotations;_tag="SymbolKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var cF=new zO({[At]:"symbol",[ln]:"a symbol"}),GO=Pa("SymbolKeyword");class JO{annotations;_tag="ObjectKeyword";constructor(e={}){this.annotations=e}toString(){return mr(this)}toJSON(){return{_tag:this._tag,annotations:Ee(this.annotations)}}}var lF=new JO({[At]:"object",[ln]:"an object in the TypeScript meaning, i.e. the `object` type"});class Gi{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:Ee(this.annotations)}}toString(){return String(this.type)}}class Zn extends Gi{isOptional;constructor(e,t,r={}){super(e,r);this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:Ee(this.annotations)}}toString(){return String(this.type)+(this.isOptional?"?":"")}}var YO=(e)=>e.map((t)=>t.type);class Na{elements;rest;isReadonly;annotations;_tag="TupleType";constructor(e,t,r,n={}){this.elements=e,this.rest=t,this.isReadonly=r,this.annotations=n;let o=!1,i=!1;for(let s of e)if(s.isOptional)o=!0;else if(o){i=!0;break}if(i||o&&t.length>1)throw Error(fO)}toString(){return pe(Cr(this),()=>uF(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map((e)=>e.toJSON()),rest:this.rest.map((e)=>e.toJSON()),isReadonly:this.isReadonly,annotations:Ee(this.annotations)}}}var uF=(e)=>{let t=e.elements.map(String).join(", ");return Ly(e.rest,{onEmpty:()=>`readonly [${t}]`,onNonEmpty:(r,n)=>{let o=String(r),i=o.includes(" | ")?`(${o})`:o;if(n.length>0){let s=n.map(String).join(", ");if(e.elements.length>0)return`readonly [${t}, ...${i}[], ${s}]`;else return`readonly [...${i}[], ${s}]`}else if(e.elements.length>0)return`readonly [${t}, ...${i}[]]`;else return`ReadonlyArray<${o}>`}})};class Ue extends Zn{name;isReadonly;constructor(e,t,r,n,o){super(t,r,o);this.name=e,this.isReadonly=n}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:Ee(this.annotations)}}}var ZO=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return!0;case"Refinement":return ZO(e.from)}return!1};class Ji{type;isReadonly;parameter;constructor(e,t,r){if(this.type=t,this.isReadonly=r,ZO(e))this.parameter=e;else throw Error(dO)}toString(){return(this.isReadonly?"readonly ":"")+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}}class Pr{annotations;_tag="TypeLiteral";propertySignatures;indexSignatures;constructor(e,t,r={}){this.annotations=r;let n={};for(let i=0;i<e.length;i++){let s=e[i].name;if(Object.prototype.hasOwnProperty.call(n,s))throw Error(Ym(s));n[s]=null}let o={string:!1,symbol:!1};for(let i=0;i<t.length;i++){let s=Th(t[i].parameter);if(Cu(s)){if(o.string)throw Error(Gm("string"));o.string=!0}else if(GO(s)){if(o.symbol)throw Error(Gm("symbol"));o.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return pe(Cr(this),()=>pF(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map((e)=>e.toJSON()),indexSignatures:this.indexSignatures.map((e)=>e.toJSON()),annotations:Ee(this.annotations)}}}var _O=(e)=>e.map(String).join("; "),pF=(e)=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join("; ");if(e.indexSignatures.length>0)return`{ ${t}; ${_O(e.indexSignatures)} }`;else return`{ ${t} }`}else if(e.indexSignatures.length>0)return`{ ${_O(e.indexSignatures)} }`;else return"{}"};var dF=Kr(Ec(Rr,(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})),fF={string:"StringKeyword",number:"NumberKeyword",boolean:"BooleanKeyword",bigint:"BigIntKeyword"},QO=(e)=>Ps(e,(t)=>_h(t)?QO(t.types):[t]),mF=(e)=>{let t=dF(e),r=[],n={},o=[];for(let i of t)switch(i._tag){case"NeverKeyword":break;case"AnyKeyword":return[UO];case"UnknownKeyword":return[DO];case"ObjectKeyword":case"UndefinedKeyword":case"VoidKeyword":case"StringKeyword":case"NumberKeyword":case"BooleanKeyword":case"BigIntKeyword":case"SymbolKeyword":{if(!n[i._tag])n[i._tag]=i,r.push(i);break}case"Literal":{let s=typeof i.literal;switch(s){case"string":case"number":case"bigint":case"boolean":{let a=fF[s];if(!n[a]&&!o.includes(i.literal))o.push(i.literal),r.push(i);break}case"object":{if(!o.includes(i.literal))o.push(i.literal),r.push(i);break}}break}case"UniqueSymbol":{if(!n.SymbolKeyword&&!o.includes(i.symbol))o.push(i.symbol),r.push(i);break}case"TupleType":{if(!n.ObjectKeyword)r.push(i);break}case"TypeLiteral":{if(i.propertySignatures.length===0&&i.indexSignatures.length===0){if(!n["{}"])n["{}"]=i,r.push(i)}else if(!n.ObjectKeyword)r.push(i);break}default:r.push(i)}return r};class yt{types;annotations;static make=(e,t)=>Pu(e)?new yt(e,t):e.length===1?e[0]:ku;static unify=(e,t)=>yt.make(mF(QO(e)),t);_tag="Union";constructor(e,t={}){this.types=e,this.annotations=t}toString(){return pe(Cr(this),()=>this.types.map(String).join(" | "))}toJSON(){return{_tag:this._tag,types:this.types.map((e)=>e.toJSON()),annotations:Ee(this.annotations)}}}var XO=(e,t)=>e.map(t),Pu=(e)=>e.length>1,_h=Pa("Union"),Zm=B(Symbol.for("effect/Schema/AST/toJSONMemoMap"),()=>new WeakMap);class Nu{f;annotations;_tag="Suspend";constructor(e,t={}){this.f=e,this.annotations=t,this.f=ka(e)}toString(){return Cr(this).pipe(rr(()=>or(Cy(this.f)(),(e)=>Cr(e))),pe(()=>"<suspended schema>"))}toJSON(){let e=this.f(),t=Zm.get(e);if(t)return t;return Zm.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:Ee(this.annotations)},Zm.set(e,t),t}}class Fa{from;filter;annotations;_tag="Refinement";constructor(e,t,r={}){this.from=e,this.filter=t,this.annotations=r}toString(){return Ca(this).pipe(pe(()=>Ae(nv(this),{onNone:()=>`{ ${this.from} | filter }`,onSome:(e)=>Ma(this.from)?String(this.from)+" & "+e:e})))}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),annotations:Ee(this.annotations)}}}var Ma=Pa("Refinement"),Fu={};class wh{from;to;transformation;annotations;_tag="Transformation";constructor(e,t,r,n={}){this.from=e,this.to=t,this.transformation=r,this.annotations=n}toString(){return pe(Cr(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:Ee(this.annotations)}}}class Eh{from;to;decode;encode;constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}}class Oh{propertySignatureTransformations;_tag="TypeLiteralTransformation";constructor(e){this.propertySignatureTransformations=e;let t={},r={};for(let n of e){let o=n.from;if(t[o])throw Error(Jm(o));t[o]=!0;let i=n.to;if(r[i])throw Error(Jm(i));r[i]=!0}}}var La=(e,t)=>{let r=Object.getOwnPropertyDescriptors(e),n={...e.annotations};delete n[vu];let o={...n,...t},i=xh(e);if(de(i))o[dh]=La(i.value,t);return r.annotations.value=o,Object.create(Object.getPrototypeOf(e),r)};var hF="[\\s\\S]*?",gF="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",ev=(e,t)=>{switch(e._tag){case"Literal":return Di(String(e.literal));case"StringKeyword":return hF;case"NumberKeyword":return gF;case"TemplateLiteral":return tv(e,t,!1);case"Union":return e.types.map((r)=>ev(r,t)).join("|")}},yF=(e,t,r,n)=>{if(_h(e)){if(r&&!n)return`(?:${t})`}else if(!r||!n)return t;return`(${t})`},tv=(e,t,r)=>{let n="";if(e.head!==""){let o=Di(e.head);n+=t&&r?`(${o})`:o}for(let o of e.spans){let i=ev(o.type,t);if(n+=yF(o.type,i,t,r),o.literal!==""){let s=Di(o.literal);n+=t&&r?`(${s})`:s}}return n},rv=(e)=>new RegExp(`^${tv(e,!1,!0)}$`);var vh=(e,t)=>{let r=[],n=[],o=(i)=>{switch(i._tag){case"NeverKeyword":break;case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":case"Refinement":n.push(new Ji(i,t,!0));break;case"Literal":if(Ke(i.literal)||Pt(i.literal))r.push(new Ue(i.literal,t,!1,!0));else throw Error(pO(i.literal));break;case"Enums":{for(let[s,a]of i.enums)r.push(new Ue(a,t,!1,!0));break}case"UniqueSymbol":r.push(new Ue(i.symbol,t,!1,!0));break;case"Union":i.types.forEach(o);break;default:throw Error(uO(i))}};return o(e),{propertySignatures:r,indexSignatures:n}};var Ah=(e)=>(t)=>{let r=void 0;for(let n of e)if(Object.prototype.hasOwnProperty.call(t.annotations,n)){if(r===void 0)r={};r[n]=t.annotations[n]}return r};var xF=Ah([th,rh,nh,oh,ih,sh]),qe=(e)=>{switch(e._tag){case"Declaration":{let t=Jt(e.typeParameters,qe);return t===e.typeParameters?e:new zi(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case"TupleType":{let t=Jt(e.elements,(o)=>{let i=qe(o.type);return i===o.type?o:new Zn(i,o.isOptional)}),r=YO(e.rest),n=Jt(r,qe);return t===e.elements&&n===r?e:new Na(t,n.map((o)=>new Gi(o)),e.isReadonly,e.annotations)}case"TypeLiteral":{let t=Jt(e.propertySignatures,(n)=>{let o=qe(n.type);return o===n.type?n:new Ue(n.name,o,n.isOptional,n.isReadonly)}),r=Jt(e.indexSignatures,(n)=>{let o=qe(n.type);return o===n.type?n:new Ji(n.parameter,o,n.isReadonly)});return t===e.propertySignatures&&r===e.indexSignatures?e:new Pr(t,r,e.annotations)}case"Union":{let t=Jt(e.types,qe);return t===e.types?e:yt.make(t,e.annotations)}case"Suspend":return new Nu(()=>qe(e.f()),e.annotations);case"Refinement":{let t=qe(e.from);return t===e.from?e:new Fa(t,e.filter,e.annotations)}case"Transformation":{let t=xF(e);return qe(t!==void 0?La(e.to,t):e.to)}}return e};function Jt(e,t){let r=!1,n=xo(e.length);for(let o=0;o<e.length;o++){let i=e[o],s=t(i);if(s!==i)r=!0;n[o]=s}return r?n:e}var Qm=(e)=>{switch(e._tag){case"Transformation":return e.from;case"Refinement":return Qm(e.from);case"Suspend":return Qm(e.f())}},kr=(e,t)=>{switch(e._tag){case"Declaration":{let r=Jt(e.typeParameters,(n)=>kr(n,t));return r===e.typeParameters?e:new zi(r,e.decodeUnknown,e.encodeUnknown)}case"TupleType":{let r=Jt(e.elements,(i)=>{let s=kr(i.type,t);return s===i.type?i:new Zn(s,i.isOptional)}),n=YO(e.rest),o=Jt(n,(i)=>kr(i,t));return r===e.elements&&o===n?e:new Na(r,o.map((i)=>new Gi(i)),e.isReadonly)}case"TypeLiteral":{let r=Jt(e.propertySignatures,(o)=>{let i=kr(o.type,t);return i===o.type?o:new Ue(o.name,i,o.isOptional,o.isReadonly)}),n=Jt(e.indexSignatures,(o)=>{let i=kr(o.type,t);return i===o.type?o:new Ji(o.parameter,i,o.isReadonly)});return r===e.propertySignatures&&n===e.indexSignatures?e:new Pr(r,n)}case"Union":{let r=Jt(e.types,(n)=>kr(n,t));return r===e.types?e:yt.make(r)}case"Suspend":{let r=void 0,n=iF(e);if(de(n)){let o=t?"Bound":"";r={[bh]:`${n.value}Encoded${o}`}}return new Nu(()=>kr(e.f(),t),r)}case"Refinement":{let r=kr(e.from,t);if(t){if(r===e.from)return e;if(Qm(e.from)===void 0&&Sh(e))return new Fa(r,e.filter,e.annotations);return r}else return r}case"Transformation":return kr(e.from,t)}return e},Mu=(e)=>kr(e,!1);var Ee=(e)=>{let t={};for(let r of Object.getOwnPropertySymbols(e))t[String(r)]=e[r];return t},Th=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return e;case"Refinement":return Th(e.from)}};var mr=(e)=>pe(Cr(e),()=>e._tag);function SF(e){return Ae(mh(e),{onNone:()=>"",onSome:(t)=>t.map((r)=>` & Brand<${_r(r)}>`).join("")})}var nv=(e)=>hh(e).pipe(rr(()=>yh(e)),rr(()=>gh(e)),nr((t)=>t+SF(e))),Cr=(e)=>rr(Ca(e),()=>nv(e));class He{path;actual;issue;_tag="Pointer";constructor(e,t,r){this.path=e,this.actual=t,this.issue=r}}class kh{actual;message;_tag="Unexpected";constructor(e,t){this.actual=e,this.message=t}}class Yi{ast;message;_tag="Missing";actual=void 0;constructor(e,t){this.ast=e,this.message=t}}class Oe{ast;actual;issues;output;_tag="Composite";constructor(e,t,r,n){this.ast=e,this.actual=t,this.issues=r,this.output=n}}class Du{ast;actual;kind;issue;_tag="Refinement";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class qu{ast;actual;kind;issue;_tag="Transformation";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class Yt{ast;actual;message;_tag="Type";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}class Ch{ast;actual;message;_tag="Forbidden";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}var iv=Symbol.for("effect/Schema/ParseErrorTypeId");class cv extends f_("ParseError"){[iv]=iv;get message(){return this.toString()}toString(){return Ua.formatIssueSync(this.issue)}toJSON(){return{_id:"ParseError",message:this.toString()}}[Y](){return this.toJSON()}}var Nh=(e)=>new cv({issue:e}),lv=G,uv=K;var It=Bp,un=p(2,(e,t)=>It(e)?Cs(e,{onLeft:K,onRight:t}):fr(e,t)),gr=p(2,(e,t)=>It(e)?vy(e,t):_u(e,t)),Uu=p(2,(e,t)=>It(e)?wc(e,t):oO(e,t));var pv=p(2,(e,t)=>It(e)?Cs(e,{onLeft:t,onRight:G}):nO(e,t)),dv=(e,t)=>{if(t===void 0||Pt(t))return e;if(e===void 0)return t;return{...e,...t}},fv=(e,t,r)=>{let n=it(e,t);return(o,i)=>n(o,dv(r,i))},bF=(e,t,r)=>{let n=fv(e,t,r);return(o,i)=>Wp(n(o,i),Nh)};var mv=(e,t)=>fv(e.ast,!0,t);var Hu=(e,t)=>bF(qe(e.ast),!0,t);var _F=B(Symbol.for("effect/ParseResult/decodeMemoMap"),()=>new WeakMap),wF=B(Symbol.for("effect/ParseResult/encodeMemoMap"),()=>new WeakMap),it=(e,t)=>{let r=t?_F:wF,n=r.get(e);if(n)return n;let o=EF(e,t),i=kO(e),s=de(i)?(l,u)=>o(l,dv(u,i.value)):o,a=CO(e),c=t&&de(a)?(l,u)=>qa(pv(s(l,u),a.value),e,l,u):s;return r.set(e,c),c},Ih=(e)=>Ot(TO(e)),Rh=(e)=>Ot(IO(e)),EF=(e,t)=>{switch(e._tag){case"Refinement":if(t){let r=it(e.from,!0);return(n,o)=>{o=o??Fu;let i=o?.errors==="all",s=un(pv(r(n,o),(a)=>{let c=new Du(e,n,"From",a);if(i&&Sh(e)&&Sv(a))return Ae(e.filter(n,o,e),{onNone:()=>K(c),onSome:(l)=>K(new Oe(e,n,[c,new Du(e,n,"Predicate",l)]))});return K(c)}),(a)=>Ae(e.filter(a,o,e),{onNone:()=>G(a),onSome:(c)=>K(new Du(e,n,"Predicate",c))}));return qa(s,e,n,o)}}else{let r=it(qe(e),!0),n=it(gv(e.from),!1);return(o,i)=>qa(un(r(o,i),(s)=>n(s,i)),e,o,i)}case"Transformation":{let r=vF(e.transformation,t),n=t?it(e.from,!0):it(e.to,!1),o=t?it(e.to,!0):it(e.from,!1);return(i,s)=>qa(un(Uu(n(i,s),(a)=>new qu(e,i,t?"Encoded":"Type",a)),(a)=>un(Uu(r(a,s??Fu,e,i),(c)=>new qu(e,i,"Transformation",c)),(c)=>Uu(o(c,s),(l)=>new qu(e,i,t?"Type":"Encoded",l)))),e,i,s)}case"Declaration":{let r=t?e.decodeUnknown(...e.typeParameters):e.encodeUnknown(...e.typeParameters);return(n,o)=>qa(r(n,o??Fu,e),e,n,o)}case"Literal":return Tt(e,(r)=>r===e.literal);case"UniqueSymbol":return Tt(e,(r)=>r===e.symbol);case"UndefinedKeyword":return Tt(e,ry);case"NeverKeyword":return Tt(e,ny);case"UnknownKeyword":case"AnyKeyword":case"VoidKeyword":return G;case"StringKeyword":return Tt(e,Ke);case"NumberKeyword":return Tt(e,Pt);case"BooleanKeyword":return Tt(e,co);case"BigIntKeyword":return Tt(e,_n);case"SymbolKeyword":return Tt(e,lo);case"ObjectKeyword":return Tt(e,gt);case"Enums":return Tt(e,(r)=>e.enums.some(([n,o])=>o===r));case"TemplateLiteral":{if(e.spans.every((n)=>Cu(n.type)))return Tt(e,(n)=>{if(!Ke(n)||!n.startsWith(e.head))return!1;let o=e.head.length;for(let s=0;s<e.spans.length-1;s++){let a=e.spans[s].literal,c=n.indexOf(a,o);if(c===-1)return!1;o=c+a.length}let i=e.spans[e.spans.length-1].literal;return n.endsWith(i)&&n.length-i.length>=o});let r=rv(e);return Tt(e,(n)=>Ke(n)&&r.test(n))}case"TupleType":{let r=e.elements.map((l)=>it(l.type,t)),n=e.rest.map((l)=>it(l.type,t)),o=e.elements.filter((l)=>!l.isOptional);if(e.rest.length>0)o=o.concat(e.rest.slice(1));let i=o.length,s=e.elements.length>0?e.elements.map((l,u)=>u).join(" | "):"never",a=Ih(e),c=Rh(e);return(l,u)=>{if(!Zp(l))return K(new Yt(e,l));let d=u?.errors==="all",f=[],g=0,y=[],O=l.length;for(let k=O;k<=i-1;k++){let j=new He(k,l,new Yi(o[k-O]));if(d){f.push([g++,j]);continue}else return K(new Oe(e,l,j,y))}if(e.rest.length===0)for(let k=e.elements.length;k<=O-1;k++){let j=new He(k,l,new kh(l[k],`is unexpected, expected: ${s}`));if(d){f.push([g++,j]);continue}else return K(new Oe(e,l,j,y))}let m=0,x=void 0;for(;m<r.length;m++)if(O<m+1){if(e.elements[m].isOptional)continue}else{let k=r[m],j=k(l[m],u);if(It(j)){if(ge(j)){let T=new He(m,l,j.left);if(d){f.push([g++,T]);continue}else return K(new Oe(e,l,T,hr(y)))}y.push([g++,j.right])}else{let T=g++,I=m;if(!x)x=[];x.push(({es:C,output:M})=>fr(Ko(j),(ee)=>{if(ge(ee)){let X=new He(I,l,ee.left);if(d)return C.push([T,X]),Dt;else return K(new Oe(e,l,X,hr(M)))}return M.push([T,ee.right]),Dt}))}}if(le(n)){let[k,...j]=n;for(;m<O-j.length;m++){let T=k(l[m],u);if(It(T))if(ge(T)){let I=new He(m,l,T.left);if(d){f.push([g++,I]);continue}else return K(new Oe(e,l,I,hr(y)))}else y.push([g++,T.right]);else{let I=g++,C=m;if(!x)x=[];x.push(({es:M,output:ee})=>fr(Ko(T),(X)=>{if(ge(X)){let J=new He(C,l,X.left);if(d)return M.push([I,J]),Dt;else return K(new Oe(e,l,J,hr(ee)))}else return ee.push([I,X.right]),Dt}))}}for(let T=0;T<j.length;T++){let I=m+T;if(O<I+1)continue;else{let C=j[T](l[I],u);if(It(C)){if(ge(C)){let M=new He(I,l,C.left);if(d){f.push([g++,M]);continue}else return K(new Oe(e,l,M,hr(y)))}y.push([g++,C.right])}else{let M=g++;if(!x)x=[];x.push(({es:ee,output:X})=>fr(Ko(C),(J)=>{if(ge(J)){let he=new He(I,l,J.left);if(d)return ee.push([M,he]),Dt;else return K(new Oe(e,l,he,hr(X)))}return X.push([M,J.right]),Dt}))}}}}let D=({es:k,output:j})=>vn(k)?K(new Oe(e,l,hr(k),hr(j))):G(hr(j));if(x&&x.length>0){let k=x;return Ra(()=>{let j={es:di(f),output:di(y)};return fr(Ia(k,(T)=>T(j),{concurrency:a,batching:c,discard:!0}),()=>D(j))})}return D({output:y,es:f})}}case"TypeLiteral":{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return Tt(e,oy);let r=[],n={},o=[];for(let u of e.propertySignatures)r.push([it(u.type,t),u]),n[u.name]=null,o.push(u.name);let i=e.indexSignatures.map((u)=>[it(u.parameter,t),it(u.type,t),u.parameter]),s=yt.make(e.indexSignatures.map((u)=>u.parameter).concat(o.map((u)=>lo(u)?new Iu(u):new Vo(u)))),a=it(s,t),c=Ih(e),l=Rh(e);return(u,d)=>{if(!Ip(u))return K(new Yt(e,u));let f=d?.errors==="all",g=[],y=0,O=d?.onExcessProperty==="error",m=d?.onExcessProperty==="preserve",x={},D;if(O||m){D=Reflect.ownKeys(u);for(let I of D){let C=a(I,d);if(It(C)&&ge(C))if(O){let M=new He(I,u,new kh(u[I],`is unexpected, expected: ${String(s)}`));if(f){g.push([y++,M]);continue}else return K(new Oe(e,u,M,x))}else x[I]=u[I]}}let k=void 0,j=d?.exact===!0;for(let I=0;I<r.length;I++){let C=r[I][1],M=C.name,ee=Object.prototype.hasOwnProperty.call(u,M);if(!ee){if(C.isOptional)continue;else if(j){let he=new He(M,u,new Yi(C));if(f){g.push([y++,he]);continue}else return K(new Oe(e,u,he,x))}}let X=r[I][0],J=X(u[M],d);if(It(J)){if(ge(J)){let he=new He(M,u,ee?J.left:new Yi(C));if(f){g.push([y++,he]);continue}else return K(new Oe(e,u,he,x))}x[M]=J.right}else{let he=y++,ut=M;if(!k)k=[];k.push(({es:Qe,output:pt})=>fr(Ko(J),(Me)=>{if(ge(Me)){let Re=new He(ut,u,ee?Me.left:new Yi(C));if(f)return Qe.push([he,Re]),Dt;else return K(new Oe(e,u,Re,pt))}return pt[ut]=Me.right,Dt}))}}for(let I=0;I<i.length;I++){let C=i[I],M=C[0],ee=C[1],X=Vm(u,C[2]);for(let J of X){let he=M(J,d);if(It(he)&&ze(he)){let ut=ee(u[J],d);if(It(ut)){if(ge(ut)){let Qe=new He(J,u,ut.left);if(f){g.push([y++,Qe]);continue}else return K(new Oe(e,u,Qe,x))}else if(!Object.prototype.hasOwnProperty.call(n,J))x[J]=ut.right}else{let Qe=y++,pt=J;if(!k)k=[];k.push(({es:Me,output:Re})=>fr(Ko(ut),(dt)=>{if(ge(dt)){let Lr=new He(pt,u,dt.left);if(f)return Me.push([Qe,Lr]),Dt;else return K(new Oe(e,u,Lr,Re))}else{if(!Object.prototype.hasOwnProperty.call(n,J))Re[J]=dt.right;return Dt}}))}}}}let T=({es:I,output:C})=>{if(vn(I))return K(new Oe(e,u,hr(I),C));if(d?.propertyOrder==="original"){let M=D||Reflect.ownKeys(u);for(let X of o)if(M.indexOf(X)===-1)M.push(X);let ee={};for(let X of M)if(Object.prototype.hasOwnProperty.call(C,X))ee[X]=C[X];return G(ee)}return G(C)};if(k&&k.length>0){let I=k;return Ra(()=>{let C={es:di(g),output:Object.assign({},x)};return fr(Ia(I,(M)=>M(C),{concurrency:c,batching:l,discard:!0}),()=>T(C))})}return T({es:g,output:x})}}case"Union":{let r=hv(e.types,t),n=Reflect.ownKeys(r.keys),o=n.length,i=e.types.length,s=new Map;for(let l=0;l<i;l++)s.set(e.types[l],it(e.types[l],t));let a=Ih(e)??1,c=Rh(e);return(l,u)=>{let d=[],f=0,g=[];if(o>0)if(bs(l))for(let m=0;m<o;m++){let x=n[m],D=r.keys[x].buckets;if(Object.prototype.hasOwnProperty.call(l,x)){let k=String(l[x]);if(Object.prototype.hasOwnProperty.call(D,k))g=g.concat(D[k]);else{let{candidates:j,literals:T}=r.keys[x],I=yt.make(T),C=j.length===i?new Pr([new Ue(x,I,!1,!0)],[]):yt.make(j);d.push([f++,new Oe(C,l,new He(x,l,new Yt(I,l[x])))])}}else{let{candidates:k,literals:j}=r.keys[x],T=new Ue(x,yt.make(j),!1,!0),I=k.length===i?new Pr([T],[]):yt.make(k);d.push([f++,new Oe(I,l,new He(x,l,new Yi(T)))])}}else{let m=r.candidates.length===i?e:yt.make(r.candidates);d.push([f++,new Yt(m,l)])}if(r.otherwise.length>0)g=g.concat(r.otherwise);let y=void 0;for(let m=0;m<g.length;m++){let x=g[m],D=s.get(x)(l,u);if(It(D)&&(!y||y.length===0))if(ze(D))return D;else d.push([f++,D.left]);else{let k=f++;if(!y)y=[];y.push((j)=>Ra(()=>{if("finalResult"in j)return Dt;else return fr(Ko(D),(T)=>{if(ze(T))j.finalResult=T;else j.es.push([k,T.left]);return Dt})}))}}let O=(m)=>vn(m)?m.length===1&&m[0][1]._tag==="Type"?K(m[0][1]):K(new Oe(e,l,hr(m))):K(new Yt(e,l));if(y&&y.length>0){let m=y;return Ra(()=>{let x={es:di(d)};return fr(Ia(m,(D)=>D(x),{concurrency:a,batching:c,discard:!0}),()=>{if("finalResult"in x)return x.finalResult;return O(x.es)})})}return O(d)}}case"Suspend":{let r=ka(()=>it(e.f(),t));return(n,o)=>r()(n,o)}}},Tt=(e,t)=>(r)=>t(r)?G(r):K(new Yt(e,r)),Da=(e,t)=>{switch(e._tag){case"Declaration":{let r=xh(e);if(de(r))return Da(r.value,t);break}case"TypeLiteral":{let r=[];for(let n=0;n<e.propertySignatures.length;n++){let o=e.propertySignatures[n],i=t?Mu(o.type):qe(o.type);if(Tu(i)&&!o.isOptional)r.push([o.name,i])}return r}case"TupleType":{let r=[];for(let n=0;n<e.elements.length;n++){let o=e.elements[n],i=t?Mu(o.type):qe(o.type);if(Tu(i)&&!o.isOptional)r.push([n,i])}return r}case"Refinement":return Da(e.from,t);case"Suspend":return Da(e.f(),t);case"Transformation":return Da(t?e.from:e.to,t)}return[]},hv=(e,t)=>{let r={},n=[],o=[];for(let i=0;i<e.length;i++){let s=e[i],a=Da(s,t);if(a.length>0){o.push(s);for(let c=0;c<a.length;c++){let[l,u]=a[c],d=String(u.literal);r[l]=r[l]||{buckets:{},literals:[],candidates:[]};let f=r[l].buckets;if(Object.prototype.hasOwnProperty.call(f,d)){if(c<a.length-1)continue;f[d].push(s),r[l].literals.push(u),r[l].candidates.push(s)}else{f[d]=[s],r[l].literals.push(u),r[l].candidates.push(s);break}}}else n.push(s)}return{keys:r,otherwise:n,candidates:o}},gv=(e)=>Ma(e)?gv(e.from):e,qa=(e,t,r,n)=>{if(n?.isEffectAllowed===!0)return e;if(It(e))return e;let o=new Sa,i=iO(e,{scheduler:o});o.flush();let s=i.unsafePoll();if(s){if(Sw(s))return G(s.value);let a=s.cause;if(Tb(a))return K(a.error);return K(new Ch(t,r,Ib(a)))}return K(new Ch(t,r,"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"))},OF=([e],[t])=>e>t?1:e<t?-1:0;function hr(e){return e.sort(OF).map((t)=>t[1])}var vF=(e,t)=>{switch(e._tag){case"FinalTransformation":return t?e.decode:e.encode;case"ComposeTransformation":return G;case"TypeLiteralTransformation":return(r)=>{let n=G(r);for(let o of e.propertySignatureTransformations){let[i,s]=t?[o.from,o.to]:[o.to,o.from],a=t?o.decode:o.encode;n=gr(n,(l)=>{let u=a(Object.prototype.hasOwnProperty.call(l,i)?F(l[i]):A());if(delete l[i],de(u))l[s]=u.value;return l})}return n}}},xt=(e,t=[])=>({value:e,forest:t}),Ua={formatIssue:(e)=>gr(Zi(e),AF),formatIssueSync:(e)=>{let t=Ua.formatIssue(e);return It(t)?Ty(t):sO(t)},formatError:(e)=>Ua.formatIssue(e.issue),formatErrorSync:(e)=>Ua.formatIssueSync(e.issue)},AF=(e)=>e.value+yv(`
|
|
37
|
+
`,e.forest),yv=(e,t)=>{let r="",n=t.length,o;for(let i=0;i<n;i++){o=t[i];let s=i===n-1;r+=e+(s?"\u2514":"\u251C")+"\u2500 "+o.value,r+=yv(e+(n>1&&!s?"\u2502 ":" "),o.forest)}return r},TF=(e)=>{switch(e){case"Encoded":return"Encoded side transformation failure";case"Transformation":return"Transformation process failure";case"Type":return"Type side transformation failure"}},IF=(e)=>{switch(e){case"From":return"From side refinement failure";case"Predicate":return"Predicate refinement failure"}},xv=(e)=>("ast"in e)?F(e.ast):A(),Ph=G(void 0),RF=(e)=>xv(e).pipe(or(vO),Ae({onNone:()=>Ph,onSome:(t)=>{let r=t(e);if(Ke(r))return G({message:r,override:!1});if(rO(r))return _u(r,(n)=>({message:n,override:!1}));if(Ke(r.message))return G({message:r.message,override:r.override});return _u(r.message,(n)=>({message:n,override:r.override}))}})),Fh=(e)=>(t)=>t._tag===e,Sv=Fh("Composite"),sv=Fh("Refinement"),av=Fh("Transformation"),Ha=(e)=>un(RF(e),(t)=>{if(t!==void 0)return!t.override&&(Sv(e)||sv(e)&&e.kind==="From"||av(e)&&e.kind!=="Transformation")?av(e)||sv(e)?Ha(e.issue):Ph:G(t.message);return Ph}),bv=(e)=>xv(e).pipe(or(RO),Py((t)=>t(e)),Ot);function kF(e){return yh(e).pipe(rr(()=>hh(e)),rr(()=>gh(e)),rr(()=>Ca(e)),pe(()=>`{ ${e.from} | filter }`))}function CF(e){if(e.message!==void 0)return e.message;return`Expected ${Ma(e.ast)?kF(e.ast):String(e.ast)}, actual ${_r(e.actual)}`}var PF=(e)=>gr(Ha(e),(t)=>t??bv(e)??CF(e)),Lu=(e)=>bv(e)??String(e.ast),NF=(e)=>e.message??"is forbidden",FF=(e)=>e.message??"is unexpected",MF=(e)=>{let t=AO(e.ast);if(de(t)){let r=t.value();return Ke(r)?G(r):r}return G(e.message??"is missing")},Zi=(e)=>{switch(e._tag){case"Type":return gr(PF(e),xt);case"Forbidden":return G(xt(Lu(e),[xt(NF(e))]));case"Unexpected":return G(xt(FF(e)));case"Missing":return gr(MF(e),xt);case"Transformation":return un(Ha(e),(t)=>{if(t!==void 0)return G(xt(t));return gr(Zi(e.issue),(r)=>xt(Lu(e),[xt(TF(e.kind),[r])]))});case"Refinement":return un(Ha(e),(t)=>{if(t!==void 0)return G(xt(t));return gr(Zi(e.issue),(r)=>xt(Lu(e),[xt(IF(e.kind),[r])]))});case"Pointer":return gr(Zi(e.issue),(t)=>xt(wu(e.path),[t]));case"Composite":return un(Ha(e),(t)=>{if(t!==void 0)return G(xt(t));let r=Lu(e);return zm(e.issues)?gr(Ia(e.issues,Zi),(n)=>xt(r,n)):gr(Zi(e.issues),(n)=>xt(r,[n]))})}};var _v=p((e)=>gt(e[0]),(e,...t)=>{let r={};for(let n of t)if(n in e)r[n]=e[n];return r}),wv=p((e)=>gt(e[0]),(e,...t)=>{let r={...e};for(let n of t)delete r[n];return r});var ja=Symbol.for("effect/Schema");function st(e){return class{[ja]=Ev;static ast=e;static annotations(r){return st(pn(this.ast,r))}static pipe(){return b(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[ja]=Ev}}var Ev={_A:(e)=>e,_I:(e)=>e,_R:(e)=>e};var Ov={typeConstructor:wO,schemaId:EO,message:eh,missingMessage:Ou,identifier:vu,title:At,description:ln,examples:th,default:rh,documentation:OO,jsonSchema:nh,arbitrary:oh,pretty:ih,equivalence:sh,concurrency:ah,batching:ch,parseIssueTitle:lh,parseOptions:uh,decodingFallback:ph},zo=(e)=>{if(!e)return{};let t={...e};for(let r in Ov)if(r in e){let n=Ov[r];t[n]=e[r],delete t[r]}return t},pn=(e,t)=>La(e,zo(t));var Qi=(e,t)=>{let r=mv(e,t);return(n,o)=>wc(r(n,o),Nh)};var vv=(e)=>v(e,ja)&>(e[ja]);function qF(e){return Pu(e)?yt.make(XO(e,(t)=>new Vo(t))):new Vo(e[0])}function kv(e,t=qF(e)){return class extends st(t){static annotations(n){return kv(this.literals,pn(this.ast,n))}static literals=[...e]}}function L(...e){return le(e)?kv(e):Dh}var UF=(e,t,r)=>Lh(e,new zi(e.map((n)=>n.ast),(...n)=>t.decode(...n.map(st)),(...n)=>t.encode(...n.map(st)),zo(r))),HF=(e,t)=>{let r=()=>(o,i,s)=>e(o)?lv(o):uv(new Yt(s,o));return Lh([],new zi([],r,r,zo(t)))};function Lh(e,t){return class extends st(t){static annotations(n){return Lh(this.typeParameters,pn(this.ast,n))}static typeParameters=[...e]}}var qt=function(){if(Array.isArray(arguments[0])){let r=arguments[0],n=arguments[1],o=arguments[2];return UF(r,n,o)}let e=arguments[0],t=arguments[1];return HF(e,t)};class Cv extends st(Ru){}class dn extends st(PO){}class Dh extends st(ku){}class Q extends st(jO){}class ju extends st(BO){}class ye extends st(KO){}var jF=(e)=>yt.make(e.map((t)=>t.ast));function Pv(e,t=jF(e)){return class extends st(t){static annotations(n){return Pv(this.members,pn(this.ast,n))}static members=[...e]}}function at(...e){return Pu(e)?Pv(e):le(e)?e[0]:Dh}var $F=(e)=>at(e,Cv);var BF=(e,t)=>new Na(e.map((r)=>vv(r)?new Zn(r.ast,!1):r.ast),t.map((r)=>vv(r)?new Gi(r.ast):r.ast),!0);function Nv(e,t,r=BF(e,t)){return class extends st(r){static annotations(o){return Nv(this.elements,this.rest,pn(this.ast,o))}static elements=[...e];static rest=[...t]}}function Fv(e,t){return class extends Nv([],[e],t){static annotations(n){return Fv(this.value,pn(this.ast,n))}static value=e}}var z=(e)=>Fv(e);var Mh=(e)=>e?'"?:"':'":"';class qh extends Zn{isReadonly;defaultValue;_tag="PropertySignatureDeclaration";constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}toString(){let e=Mh(this.isOptional),t=String(this.type);return`PropertySignature<${e}, ${t}, never, ${e}, ${t}>`}}class Mv extends Zn{isReadonly;defaultValue;constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}}var WF=(e)=>{if(e===void 0)return"never";if(Ke(e))return JSON.stringify(e);return String(e)};class Lv{from;to;decode;encode;_tag="PropertySignatureTransformation";constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}toString(){return`PropertySignature<${Mh(this.to.isOptional)}, ${this.to.type}, ${WF(this.from.fromKey)}, ${Mh(this.from.isOptional)}, ${this.from.type}>`}}var Dv=(e,t)=>{switch(e._tag){case"PropertySignatureDeclaration":return new qh(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case"PropertySignatureTransformation":return new Lv(e.from,new Mv(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},qv=Symbol.for("effect/PropertySignature"),Uv=(e)=>v(e,qv);class Uh{ast;[ja];[qv]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return b(this,arguments)}annotations(e){return new Uh(Dv(this.ast,zo(e)))}toString(){return String(this.ast)}}class Hh extends Uh{from;constructor(e,t){super(e);this.from=t}annotations(e){return new Hh(Dv(this.ast,zo(e)),this.from)}}var N=(e)=>{let t=e.ast===Ru||e.ast===ku?Ru:$F(e).ast;return new Hh(new qh(t,!0,!0,{},void 0),e)};var KF=Ah([Ou]),VF=(e,t)=>{let r=Reflect.ownKeys(e),n=[];if(r.length>0){let i=[],s=[],a=[];for(let c=0;c<r.length;c++){let l=r[c],u=e[l];if(Uv(u)){let d=u.ast;switch(d._tag){case"PropertySignatureDeclaration":{let{type:f,isOptional:g,annotations:y}=d;i.push(new Ue(l,f,g,!0,KF(d))),s.push(new Ue(l,qe(f),g,!0,y)),n.push(new Ue(l,f,g,!0,y));break}case"PropertySignatureTransformation":{let f=d.from.fromKey??l;i.push(new Ue(f,d.from.type,d.from.isOptional,!0,d.from.annotations)),s.push(new Ue(l,d.to.type,d.to.isOptional,!0,d.to.annotations)),a.push(new Eh(f,l,d.decode,d.encode));break}}}else i.push(new Ue(l,u.ast,!1,!0)),s.push(new Ue(l,qe(u.ast),!1,!0)),n.push(new Ue(l,u.ast,!1,!0))}if(le(a)){let c=[],l=[];for(let u of t){let{indexSignatures:d,propertySignatures:f}=vh(u.key.ast,u.value.ast);f.forEach((g)=>{i.push(g),s.push(new Ue(g.name,qe(g.type),g.isOptional,g.isReadonly,g.annotations))}),d.forEach((g)=>{c.push(g),l.push(new Ji(g.parameter,qe(g.type),g.isReadonly))})}return new wh(new Pr(i,c,{[Au]:"Struct (Encoded side)"}),new Pr(s,l,{[Au]:"Struct (Type side)"}),new Oh(a))}}let o=[];for(let i of t){let{indexSignatures:s,propertySignatures:a}=vh(i.key.ast,i.value.ast);a.forEach((c)=>n.push(c)),s.forEach((c)=>o.push(c))}return new Pr(n,o)},zF=(e,t)=>{let r=Reflect.ownKeys(e);for(let n of r){let o=e[n];if(t[n]===void 0&&Uv(o)){let i=o.ast,s=i._tag==="PropertySignatureDeclaration"?i.defaultValue:i.to.defaultValue;if(s!==void 0)t[n]=s()}}return t};function Hv(e,t,r=VF(e,t)){return class extends st(r){static annotations(o){return Hv(this.fields,this.records,pn(this.ast,o))}static fields={...e};static records=[...t];static make=(o,i)=>{let s=zF(e,{...o});return jh(i)?s:Hu(this)(s)};static pick(...o){return H(_v(e,...o))}static omit(...o){return H(wv(e,...o))}}}function H(e,...t){return Hv(e,t)}function jv(e,t){return class extends st(t){static annotations(n){return jv(this.from,pn(this.ast,n))}static make=(n,o)=>jh(o)?n:Hu(this)(n);static from=e}}var $a=(e,t)=>(r)=>{let n=Ae(mh(r.ast),{onNone:()=>[e],onSome:(i)=>[...i,e]}),o=La(r.ast,zo({[Xm]:n,...t}));return jv(r,o)};var GF=Symbol.for("effect/SchemaId/Refine");function $v(e,t,r){return class extends st(r){static annotations(o){return $v(this.from,this.filter,pn(this.ast,o))}static[GF]=e;static from=e;static filter=t;static make=(o,i)=>jh(i)?o:Hu(this)(o)}}var Av=(e,t,r)=>{if(co(e))return e?A():F(new Yt(t,r));if(Ke(e))return F(new Yt(t,r,e));if(e!==void 0){if("_tag"in e)return F(e);let n=new Yt(t,r,e.message);return F(le(e.path)?new He(e.path,r,n):n)}return A()},JF=(e,t,r)=>{if(cO(e))return Av(e,t,r);if(le(e)){let n=vc(e,(o)=>Av(o,t,r));if(le(n))return F(n.length===1?n[0]:new Oe(t,r,n))}return A()};function Ut(e,t){return(r)=>{function n(i,s,a){return JF(e(i,s,a),a,i)}let o=new Fa(r.ast,n,zo(t));return $v(r,n,o)}}var YF=SO,Bv=(e,t)=>(r)=>r.pipe(Ut((n)=>n.length>=e,{schemaId:YF,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t}));var Tv=Symbol.for("effect/SchemaId/Pattern"),Ht=(e,t)=>(r)=>{let n=e.source;return r.pipe(Ut((o)=>(e.lastIndex=0,e.test(o)),{schemaId:Tv,[Tv]:{regex:e},description:`a string matching the pattern ${n}`,jsonSchema:{pattern:n},...t}))};var ZF=Symbol.for("effect/SchemaId/UUID"),Iv=/^[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;class QF extends Q.pipe(Ht(Iv,{schemaId:ZF,identifier:"UUID",jsonSchema:{format:"uuid",pattern:Iv.source},description:"a Universally Unique Identifier",arbitrary:()=>(e)=>e.uuid()})){}var XF=gO,Wv=(e,t)=>(r)=>r.pipe(Ut((n)=>n>e,{schemaId:XF,title:`greaterThan(${e})`,description:e===0?"a positive number":`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),eM=yO,Kv=(e,t)=>(r)=>r.pipe(Ut((n)=>n>=e,{schemaId:eM,title:`greaterThanOrEqualTo(${e})`,description:e===0?"a non-negative number":`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t}));var tM=xO,rM=(e)=>(t)=>t.pipe(Ut((r)=>Number.isSafeInteger(r),{schemaId:tM,title:"int",description:"an integer",jsonSchema:{type:"integer"},...e}));class $u extends ju.pipe(rM({identifier:"Int"})){}var nM=bO,Nr=(e,t)=>(r)=>{let n=Math.floor(e);if(n<1)throw Error(lO(`Expected an integer greater than or equal to 1, actual ${e}`));return r.pipe(Ut((o)=>o.length>=n,{schemaId:nM,title:`minItems(${n})`,description:`an array of at least ${n} item(s)`,jsonSchema:{minItems:n},[fh]:!0,...t}))};var Rv=hO;class oM extends qt(dc,{typeConstructor:{_tag:"Date"},identifier:"DateFromSelf",schemaId:Rv,[Rv]:{noInvalidDate:!1},description:"a potentially invalid Date instance",pretty:()=>(e)=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>(e)=>e.date({noInvalidDate:!1}),equivalence:()=>ey}){}function jh(e){return co(e)?e:e?.disableValidation??!1}var iM={onExcessProperty:"error"};function yr(e,t){return Qi(e,iM)(t)}var zv=/^0\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*))?$/u,$h=Q.pipe(Ht(zv));function sM(e){let t=Qi($h)(e);return ze(t)?t.right:void 0}function Gv(e){return sM(e)!==void 0}function Jv(e){return Gv(e)&&!e.includes("-")}var aM=Q.pipe(Ut(Jv));function Vv(e){if(e===void 0||e.length===0||e[0]==="0")return!1;for(let t of e)if(t<"0"||t>"9")return!1;return!0}function cM(e){let[t,r,n]=e.split("-");if(t===void 0||r===void 0||n!==void 0)return!1;if(!Jv(t))return!1;let[o,i,s,a]=r.split(".");return o==="dev"&&a===void 0&&Vv(i)&&Vv(s)}var Yv=Q.pipe(Ut(cM)),lM=at($h,Yv);var Wh=L("browser_use","computer_use","frontend","security","sites"),uM=L("browser_use","computer_use","sites"),pM=L("installed","disabled","missing","uncertain"),dM=L("healthy","missing","disabled","uncertain"),fM=Object.freeze(["openai-curated","openai-curated-remote"]),mM=Object.freeze(["build-web-apps","codex-security"]),hM=Object.freeze(["browser","computer-use","sites"]);var mn=Object.freeze({coding:!0,computer_use:!1,browser_use:!0,sites:!0,frontend:!0,security:!0}),Qn=Object.freeze({frontend:Object.freeze([{skillId:"build-web-apps:frontend-app-builder",appliesWhen:"a new visually-driven UI or meaningful redesign"},{skillId:"build-web-apps:frontend-testing-debugging",appliesWhen:"a rendered UI or interaction defect"},{skillId:"build-web-apps:react-best-practices",appliesWhen:"a relevant React or Next implementation or review"}]),security:Object.freeze([]),computer_use:Object.freeze([]),browser_use:Object.freeze([]),sites:Object.freeze([])}),gM=Qn.frontend,yM={frontend:{name:"frontend",pluginIds:["build-web-apps@openai-curated"],defaultSelected:mn.frontend,semanticSkillIds:Object.freeze(Qn.frontend.map(({skillId:e})=>e)),applicability:Qn.frontend,ownership:"shared-preserve"},security:{name:"security",pluginIds:["codex-security@openai-curated"],defaultSelected:mn.security,semanticSkillIds:["codex-security:security-scan","codex-security:security-diff-scan","codex-security:threat-model"],applicability:Qn.security,ownership:"shared-preserve"},computer_use:{name:"computer_use",pluginIds:["computer-use@openai-bundled"],defaultSelected:mn.computer_use,migrationKey:"computer_use",semanticSkillIds:["computer-use:computer-use"],applicability:Qn.computer_use,ownership:"shared-preserve"},browser_use:{name:"browser_use",pluginIds:["browser@openai-bundled"],defaultSelected:mn.browser_use,migrationKey:"browser_use",semanticSkillIds:[],applicability:Qn.browser_use,ownership:"shared-preserve"},sites:{name:"sites",pluginIds:["sites@openai-bundled"],defaultSelected:mn.sites,migrationKey:"sites",semanticSkillIds:[],applicability:Qn.sites,ownership:"shared-preserve"}},Bh=Object.freeze(yM),xM=Object.freeze(["browser_use","computer_use","sites"]),SM=Object.freeze(["frontend","security"]),bM=Object.freeze([...Bh.frontend.pluginIds,...Bh.security.pluginIds]),_M=Object.freeze(["writing-instructions","babysit-ci"]),wM=Object.freeze({browser_use:mn.browser_use,computer_use:mn.computer_use,sites:mn.sites});var Xv=L("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"),EM=H({identifier:Xv,label:Q,requiresRootApproval:ye});function Fr(e){return H({identifier:L(e),label:Q,requiresRootApproval:ye})}var OM=H({localRepositoryEdit:Fr("local.repository.edit"),localRepositoryCheck:Fr("local.repository.check"),localRepositoryLint:Fr("local.repository.lint"),localRepositoryFormat:Fr("local.repository.format"),localRepositoryCommit:Fr("local.repository.commit"),externalRead:Fr("external.read"),specialistDispatch:Fr("specialist.dispatch"),versionControlServerMutation:Fr("vcs.server.mutation"),versionControlServerCiTrigger:Fr("vcs.server.ci-trigger"),unknownEffect:Fr("unknown.effect")}),Kh={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}};br(Kh);var vM=L("never","root"),eA=Object.values(Kh);function Zv(e){let t=e.map((n)=>n.label),r=t.at(-1);if(r===void 0)return"";if(t.length===1)return r;return`${t.slice(0,-1).join(", ")}, and ${r}`}function Qv(e){return e.length===0?e:`${e[0]?.toUpperCase()??""}${e.slice(1)}`}var AM=eA.filter((e)=>!e.requiresRootApproval),TM=eA.filter((e)=>e.requiresRootApproval),IM=Object.freeze({noRootApproval:`${Qv(Zv(AM))} actions do not require Root approval.`,rootApproval:`${Qv(Zv(TM))} require Root approval.`});var xr=Q.pipe(Ht(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),Vh=Q.pipe(Ht(/^[0-9a-f]{64}$/u)),QW=xr.pipe($a("RunId")),XW=xr.pipe($a("ProjectId")),eK=xr.pipe($a("TrustId")),tK=Vh.pipe($a("Sha256Digest"));var RM=H({run_id:xr,objective_lineage:xr,parent_run_id:N(at(xr,dn))}),kM=H({project_id:xr,trust_id:xr,trust_digest:Vh}),CM=H({project_id:xr,project_digest:Vh}),PM=Q.pipe(Ht(/^state-[0-9]+\.[0-9]+$/u));var Wu=L("low","default","high"),oA=L("go","Go","plus-low","plus","plus-high","pro-5x","pro-20x"),NM=at(Wu,oA);var iA=L("standard","fast","fast-all"),FM=L("low","medium","high","xhigh","max"),sA="Satisfy the complete requested outcome correctly, elegantly, and mergeably; never weaken or reinterpret it to shrink the patch. Then make the smallest coherent patch within the authorized boundary. Prefer simple, cohesive, idiomatic solutions with appropriate abstraction and minimal accidental complexity. Avoid unrelated code, prose, configuration, documentation, instructions, tests, restructuring, formatting churn, files, and operations. Preserve unrelated work; return material scope expansion to Root.",hn="Do not modify repository source or the implementation under validation; observation, analysis, and proof artifacts only.";var MM=L("none"),aA=Object.freeze(["implementation","review","validation","integration","vcs"]),LM=L("read-only","workspace-write"),gn=[{role:"Explorer",tasks:[{name:"map",description:"Bounded repository structure mapping specialist.",instruction:`Map the assigned repository area: locate its relevant packages, entry points, ownership boundaries, and nearby tests or docs. Return a compact path map and identify where a follow-up lookup or trace should start; do not trace runtime behavior or resolve an unrelated fact. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"lookup",description:"Repository fact lookup specialist.",instruction:`Find the specific requested repository fact and cite its exact path or symbol; keep the search narrower than a structure map or execution trace. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"trace",description:"Repository execution and reference tracing specialist.",instruction:`Follow the assigned execution or reference path across callers, boundaries, and tests; explain the evidence-backed flow and stop at the assigned boundary. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}],capability:"repository-read",authority:"Read only the delegated Assignment repository scope; Git/VCS writes, Intent lifecycle, and material decisions remain Root-only.",evidence:"Return exact paths, symbols, callers, tests, and constraints.",completion:"Account for every in-scope caller and constraint.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{role:"Librarian",tasks:[{name:"lookup",description:"Authoritative external fact lookup specialist.",instruction:`Answer the specific external fact with its current authoritative source. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"research",description:"Current authoritative-source research specialist.",instruction:`Compare and synthesize the assigned current sources with citations, noting conflicts and uncertainty. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}],capability:"current-research",authority:"Research only the delegated Assignment current sources without repository mutation; Git/VCS writes, Intent lifecycle, and material 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,filesystem:"read-only",sourceMutation:!1}},{role:"Worker",tasks:[{name:"mechanical",description:"Deterministic bounded-edit specialist.",instruction:"Apply the exact already-decided transformation within the assigned files and verify it.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"implementation",description:"Bounded behavior implementation specialist.",instruction:"Design and implement the assigned behavior within its bounded seam, then verify the changed behavior.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"integration",description:"Decided seam integration specialist.",instruction:"Connect already-decided component seams, resolve interface mismatches within the assigned boundary, and verify their combined behavior.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"operations",description:"Exact-ref or SHA terminal operations observer.",instruction:`Observe the assigned CI or release gate for the Root-supplied exact ref or SHA until it reaches a terminal state; report the matching result and failure evidence. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"validation",description:"Independent local behavioral validation specialist.",instruction:`Independently exercise the assigned local behavior with the smallest relevant checks, classify failures, and report reproducible evidence; generated proof state is allowed, but do not repair the implementation or substitute for code review. ${hn}`,permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!1}},{name:"debugging",description:"Reproducible bounded defect-repair specialist.",instruction:"Use the debugging skill to repair the assigned defect within its bounded seam.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}}],capability:"task-scoped-assignment",authority:"Concrete task permissions govern observation, proof writes, or source repair within the delegated Assignment; no role-level source-mutation authority is granted. Intent lifecycle, Git/VCS writes, and material choices remain Root-only.",evidence:"Return changed files, verification results, and remaining risk.",completion:"Finish the delegated Assignment with proportional proof or an exact blocker and return a compact structured outcome.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{role:"Reviewer",tasks:[{name:"plan",description:"Adversarial implementation-plan review specialist.",instruction:`Adversarially inspect the assigned implementation plan for missing requirements, invalid assumptions, unsafe ordering, unowned seams, and inadequate proof. Return actionable plan findings or a fixed-point verdict; do not implement the plan. ${hn}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"code",description:"Adversarial implemented-code review specialist.",instruction:"Review and repair the implemented code to a fixed point. Batch relevant evidence, then follow up on concrete uncertainty. Check correctness, safety, compatibility, test quality, generated-artifact hygiene, and the canonical patch-quality rule.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}},{name:"artifact",description:"Adversarial produced-artifact review specialist.",instruction:"Inspect the assigned produced artifact against its requested content, usability, and delivery constraints; repair concrete defects within the artifact boundary and repeat inspection until no actionable findings remain.",permissions:{network:!0,filesystem:"workspace-write",sourceMutation:!0}}],capability:"task-scoped-review",authority:"Concrete task permissions govern observational review or bounded repair within the delegated Assignment; no role-level source-mutation authority is granted. Intent lifecycle, Git/VCS writes, 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 as a compact structured outcome.",permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}];br(gn);var cA=new Map(gn.map((e)=>[e.role,e])),DM=new Set(gn.map((e)=>e.role)),zh=gn.flatMap((e)=>e.tasks.map((t)=>`${e.role}:${t.name}`)),qM=new Set(zh),lA=zh.map((e)=>e.replace(":",".")),uA=new Set(lA);function pA(e){return typeof e==="string"&&DM.has(e)}function UM(e){if(typeof e!=="object"||e===null||!("role"in e)||!("task"in e))return!1;let{role:t,task:r}=e;if(!pA(t)||typeof r!=="string")return!1;return cA.get(t)?.tasks.some((n)=>n.name===r)===!0}function Ku(e,t){return typeof t==="string"&&cA.get(e)?.tasks.some((r)=>r.name===t)===!0}function dA(e){return typeof e==="string"&&qM.has(e)}var Gh=qt(pA),HM=qt((e)=>Ku("Explorer",e)),jM=qt((e)=>Ku("Librarian",e)),$M=qt((e)=>Ku("Worker",e)),BM=qt((e)=>Ku("Reviewer",e)),Ba=qt(UM),Go=Object.freeze(zh.filter((e)=>dA(e))),fA=qt(dA),mA=Object.freeze(lA.filter((e)=>uA.has(e))),WM=qt((e)=>typeof e==="string"&&uA.has(e)),hA=Object.freeze(["worker","explorer","reviewer","librarian"]);var gA=H({profile:Wu,service_tier:N(iA)}),Bu=Object.freeze(["user_interaction","intent","material_decisions","orchestration_lifecycle","integration_acceptance","completion","git_vcs","external_effects"]),KM=L(...Bu),VM=L("delegated","root_direct","unavailable"),zM=L(...Bu),Jh=L("used","no_coverage","unavailable","auth_or_quota_failure","source_conflict"),yA=Object.freeze({rule:"Use the smallest meaningful proof proportionate to changed behavior, scope, and risk, plus repository-required gates. Avoid redundant equivalent checks and speculative edge-case tests.",avoidImplementationMirrorTestsForLowImpactReversibleChanges:!0,broadenOrRepeatOnlyAfter:Object.freeze(["source_change","proof_failure","unresolved_material_concern","change_breadth_or_risk"]),mandatoryRepositoryGatesRemainRequired:!0,reviewerCodeRemainsRequired:!0}),GM=Object.freeze({requiredFor:Object.freeze(["library","framework","sdk","api","cli","cloud_service"]),resolveIdentityBeforeQuery:!0,queryNarrowly:!0,evidenceStates:Object.freeze(["used","no_coverage","unavailable","auth_or_quota_failure","source_conflict"]),webFallbackEvidenceStates:Object.freeze(["no_coverage","unavailable","auth_or_quota_failure"]),missingRequiredVersionAllowsFallback:!0,successfulEvidenceAloneAllowsFallback:!1,checkFirstPartyDocsBeforeFallbackForConflict:!0,unresolvedConflictAfterFirstPartyAllowsFallback:!0,materialDecisionsRemainRootOwned:!0}),JM=/\b(?:libraries?|frameworks?|sdks?|apis?|clis?|cloud[ _-]?services?|packages?|dependencies?|technical|documentation|docs?|context7)\b/iu,YM=/\b(?:historical|history|legacy|archived?|past)\b/iu;function Yh(e){if(e.role!=="Librarian"||e.task!=="lookup"&&e.task!=="research")return!1;let t=[e.objective,...e.scope,...e.constraints,...e.exclusions,...e.dependencies,...e.acceptanceCriteria].join(" ");return JM.test(t)&&!YM.test(t)}var ZM=Object.freeze({repositoryAndUserRequirementsPrecedePluginDefaults:!0,specialistsOwnInspectionImplementationAndRenderedAcceptance:!0,rootAcceptsTerminalVisualEvidence:!0,sourceChangesInvalidateRenderEvidence:!0,specialistReportsIncludeObservableRenderedEvidence:!0,logicOnlyChangesRequireVisualAcceptance:!1,fixedPoint:Object.freeze(["specialist_implements","specialist_renders_and_interacts","specialist_judges_current_result","root_accepts_terminal_evidence","root_assigns_discrepancies","specialist_repairs","root_rerenders_and_retests"])}),QM=Object.freeze({interactiveCapabilitiesRemainSpecialistOwned:!0,credentialEntryAndSubmissionRemainUserOwned:!0,specialistsMustNeverHandleCredentials:!0,missingAuthorizedPathIsCapabilityBlocker:!0}),XM=Object.freeze({threatModelForMaterialTrustBoundaryChanges:!0,securityDiffScanRequiredForSecuritySensitiveDiffs:!0,fullScanOnlyForAuditNewExposedSurfaceOrSystemicConcern:!0,validateSupportedFindingsBeforeBlocking:!0,introducedOrWorsenedValidatedVulnerabilityBlocksVcs:!0,preExistingUnrelatedFindingsDoNotExpandScope:!0,securityEditsInvalidateCodeReview:!0,securitySensitiveCodeReviewEditsInvalidateSecurityReview:!0,materialDecisionsRemainRootOwned:!0}),eL=Object.freeze({requiresDelegation:!0,assignmentStartAndDispatchPrecedeDelegableExecution:!0,trivialWorkRequiresDelegation:!0,preparatoryAndExploratoryWorkRequiresDelegation:!0,genericDirectWorkFallback:!1,concreteSpecialistDispatchRequired:!0,registeredSpecialistAgentTypes:mA,roleFamiliesAreLabelsOnly:!0,forbiddenGenericAgentTypes:hA,missingConcreteRouteIsBlocker:!0,delegableActions:Object.freeze(["repository_discovery","file_source_test_doc_inspection","fact_finding","research","implementation","debugging","testing","validation","frontend_work","security_work","browser_use","computer_use","review","ci_release_observation"]),directExecutionExceptions:Bu,rootOwnedAuthority:Bu,requestUserInputGates:Object.freeze(["plan_approval","installation_profile_approval","remote_origin_server_vcs_mutation","public_publication_or_release","ambiguity_or_missing_material_input"]),surgicalMutationRule:sA,phaseOrder:aA,phaseGates:Object.freeze({implementationLeavesTerminalBeforeReviewerCode:!0,reviewerCodeFixedPointBeforeWorkerValidation:!0,workerValidationBeforeRootIntegration:!0,rootIntegrationBeforeVcs:!0}),initialDispatch:Object.freeze({independentAssignments:!0,substantiveIndependentConcurrency:!0,routinePostdispatchSteering:!1,collectiveWaits:!0,evidenceReusedAcrossPhases:!0}),atomicLifecycleTransitions:Object.freeze({relatedAssignmentAndIntentWrites:!0,oneLockOneCommit:!0,staleRevisionChecksRetained:!0,repositoryDriftChecksRetained:!0}),supersession:Object.freeze({explicitOnly:!0,unfinishedPredecessorOnly:!0,validatedRelatedReplacement:!0,reasonAndProvenanceRequired:!0,supersededExcludedFromCompletionBlockers:!0}),specialistTerminalResultPersistence:Object.freeze({ownActiveInvocationCapabilityRequired:!0,ownAssignmentOnly:!0,terminalOutcomeOnly:!0,rootOwnedIntentLifecycle:!0,rootOwnedAcceptanceReviewAndCiGates:!0,rootOwnedVcsAndExternalEffects:!0,sharedRuntimeCallerIdentityUnavailable:!0,legacyResultCompatibilityPreserved:!0}),normalSpawnForkTurns:"none",normalSpawnRequiresExplicitForkTurns:!0,normalSpawnUsesConcreteRegisteredAgentType:!0,assignmentContextIsTaskSpecificOnly:!0,configuredRouteModelAndEffortPreserved:!0,normalProgressMessages:!1,normalHeartbeatMessages:!1,normalIntermediateEvidence:!1,userUpdatesUsefulOrImportantOnly:!0,routinePerToolOrSubagentNarrationForbidden:!0,routineStatusOnlyChatterForbidden:!0,fixedCadenceUserUpdatesForbidden:!0,materialUserUpdateKinds:Object.freeze(["significant_findings_or_decisions","consequential_blockers_or_input_needs","release_milestones"]),outOfBoundaryRequiresNewAssignment:!0,routineWaitTool:"collaboration.wait_agent",routineWaitMaximumTimeoutMs:1200000,routineWaitUsesMaximumRuntimeTimeout:!0,earlySpecialistCompletionWakesWait:!0,collectiveMailboxIncludesRelevantAgents:!0,idleTimeoutRepeatsMaximumWait:!0,shortRoutineWaitsForbidden:!0,longestPracticalEventWait:!0,busyPollingForbidden:!0,statusOnlyCoordinationLoopsForbidden:!0,batchIndependentLifecycleActions:!0,releaseLeavesAfterAcceptedOutcome:!0,specialistOutcomes:Object.freeze(["completed","blocked","needs_root_input","failed"]),evidenceFirstConciseStructuredReports:!0,specialistReportFields:Object.freeze(["changed paths","checks","observable evidence","blockers","Root decisions needed","remaining risk"]),rootLargeReadsOnlyFor:Object.freeze(["material decisions","conflicts","failures","findings"]),stableFactsReused:!0,duplicatePolicyForbidden:!0,stableBoundedComponentScopesAreCanonical:!0,lifecycleWorkerOwnsDeterministicApi:!0,materialDecisionsRemainRootOwned:!0,lifecycleRemainsRootOwned:!0,integrationAndCompletionRemainRootOwned:!0,routineSafeReversibleInScopeDecisionsProceedAutonomously:!0,userInstructionsOverrideSkillGuidelinesExceptHardInvariants:!0,authorizedWorkContinuesThroughRequestedTerminalState:!0,testingPolicy:yA,codeReviewRequiredForImplementation:!0,codeReviewRequiredBeforeVcs:!0,externalVerificationMustBeTerminal:!0,postVcsFlow:"discover_topology_observe_repair_repeat"});function ct(e,t){return new ht("invalid_canonical_value",`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function Zh(e,t,r){if(e===null)return"null";switch(typeof e){case"string":{let n=JSON.stringify(e);if(n===void 0)throw ct(t,"invalid string");return n}case"boolean":return e?"true":"false";case"number":{if(!Number.isFinite(e))throw ct(t,"non-finite number");let n=JSON.stringify(e);if(n===void 0)throw ct(t,"invalid number");return n}case"undefined":throw ct(t,"undefined is not JSON");case"bigint":throw ct(t,"bigint is not JSON");case"function":throw ct(t,"function is not JSON");case"symbol":throw ct(t,"symbol is not JSON");case"object":break}if(r.has(e))throw ct(t,"cyclic value");r.add(e);try{if(Array.isArray(e)){for(let a of Object.getOwnPropertySymbols(e))throw ct(t,`symbol property ${String(a)}`);let i=e,s=[];for(let a=0;a<i.length;a+=1){let c=Object.getOwnPropertyDescriptor(i,String(a));if(!c||!c.enumerable||!("value"in c))throw ct(`${t}[${a}]`,"sparse or accessor array item");s.push(Zh(c.value,`${t}[${a}]`,r))}for(let a of Object.getOwnPropertyNames(i)){if(a==="length")continue;let c=Number(a);if(!Number.isInteger(c)||c<0||c>=i.length||String(c)!==a)throw ct(t,`non-index array property ${a}`);let l=Object.getOwnPropertyDescriptor(i,a);if(!l||!l.enumerable||!("value"in l))throw ct(`${t}[${c}]`,"non-enumerable or accessor array item")}return`[${s.join(",")}]`}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw ct(t,"only plain objects are supported");for(let i of Object.getOwnPropertySymbols(e))throw ct(t,`symbol property ${String(i)}`);for(let i of Object.getOwnPropertyNames(e)){let s=Object.getOwnPropertyDescriptor(e,i);if(!s||!s.enumerable||!("value"in s))throw ct(`${t}.${i}`,"non-enumerable or accessor property")}let o=[];for(let i of Object.keys(e).sort()){let s=Object.getOwnPropertyDescriptor(e,i);if(!s||!("value"in s))throw ct(`${t}.${i}`,"accessor property");o.push(`${JSON.stringify(i)}:${Zh(s.value,`${t}.${i}`,r)}`)}return`{${o.join(",")}}`}finally{r.delete(e)}}function Qh(e){return Zh(e,"$",new Set)}var xA=L("blocked","completed","failed","partial"),SA=at(L("high","max","xhigh"),dn);function bA(e){try{return Qh(e)!==void 0}catch{return!1}}var _A=qt((e)=>bA(e)),rL=qt((e)=>fp(e)&&!Array.isArray(e)&&bA(e)),nL=H({blocked:ye,changed_files:z(Q),confidence:ju,context_owner:at(Q,dn),material_findings:z(Q),needs_more_context:ye,needs_root_decision:ye,needs_verification:ye,relevant_files:z(Q),remaining_risk:z(Q),reuse_recommended:ye,status:xA,suggested_followup:at(Q,dn),suggested_luna_effort:SA,suggested_specialist:at(Gh,dn),verification:z(Q),verification_passed:ye}),Xh="holycodex-specialist-outcome-2",Ye=Q.pipe(Bv(1)),Xi=H({state:Jh,evidence:z(Ye).pipe(Nr(1)),library:N(Ye),version:N(Ye)}),Wa={protocol_version:L(Xh),route:Ba,evidence:z(Ye),context7:N(Xi)},oL=H(Wa),iL=H({...Wa,status:L("completed"),summary:Ye}),sL=H({...Wa,status:L("blocked"),reason:Ye,needs_root_decision:ye}),aL=H({...Wa,status:L("partial"),summary:Ye,completed:z(Ye),remaining:z(Ye),needs_root_decision:ye}),cL=H({...Wa,status:L("failed"),error:Ye}),lL=at(iL,sL,aL,cL),Vu={protocol_version:L(Xh),capability:Wh,route:at(Ba,dn),evidence:z(Ye),context7:N(Xi),data:_A},uL=H({...Vu,status:L("completed"),summary:Ye}),pL=H({...Vu,status:L("blocked"),reason:Ye,needs_root_decision:ye}),dL=H({...Vu,status:L("partial"),summary:Ye,completed:z(Ye),remaining:z(Ye),needs_root_decision:ye}),fL=H({...Vu,status:L("failed"),error:Ye}),mL=at(uL,pL,dL,fL);var wA=z(Q),EA=Q.pipe(Ht(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),OA=L(dp),hL=H({code:xr,message:Q,details:rL}),vA=H({schema_version:OA,ok:L(!0),command:EA,data:_A,warnings:wA}),AA=H({schema_version:OA,ok:L(!1),command:EA,error:hL,warnings:wA}),gL=at(vA,AA);var rg="gpt-6-astra",tg="gpt-6-sol",Ka="gpt-6-luna";function yL(e,t,r){return{key:`${e}:${t}`,role:e,task:t,model:Ka,effort:r}}var xL=new Set(Go),TA={low:0,medium:1,high:2,xhigh:3,max:4},ng=[{profile:"low",rationale:"The low profile keeps bounded specialist work economical.",efforts:{"Explorer:map":"medium","Explorer:lookup":"medium","Explorer:trace":"high","Librarian:lookup":"medium","Librarian:research":"high","Worker:mechanical":"high","Worker:implementation":"high","Worker:integration":"max","Worker:operations":"high","Worker:validation":"medium","Worker:debugging":"high","Reviewer:plan":"high","Reviewer:code":"max","Reviewer:artifact":"high"}},{profile:"default",rationale:"The default profile is the recommended balanced route.",efforts:{"Explorer:map":"high","Explorer:lookup":"medium","Explorer:trace":"xhigh","Librarian:lookup":"medium","Librarian:research":"xhigh","Worker:mechanical":"high","Worker:implementation":"xhigh","Worker:integration":"max","Worker:operations":"high","Worker:validation":"high","Worker:debugging":"xhigh","Reviewer:plan":"xhigh","Reviewer:code":"max","Reviewer:artifact":"xhigh"}},{profile:"high",rationale:"The high profile maximizes specialist reasoning where specified.",efforts:{"Explorer:map":"high","Explorer:lookup":"medium","Explorer:trace":"max","Librarian:lookup":"medium","Librarian:research":"max","Worker:mechanical":"xhigh","Worker:implementation":"max","Worker:integration":"max","Worker:operations":"xhigh","Worker:validation":"xhigh","Worker:debugging":"max","Reviewer:plan":"max","Reviewer:code":"max","Reviewer:artifact":"max"}}];br(ng);var SL=new Map(ng.map((e)=>[e.profile,e]));function bL(e){let t=SL.get(e);if(t===void 0)throw new ht("catalog_invalid","A profile has no route effort policy.",{profile:e});return gn.flatMap((r)=>r.tasks.map((n)=>{let o=`${r.role}:${n.name}`,i=t.efforts[o];if(i===void 0)throw new ht("catalog_invalid","A route effort policy is incomplete.",{profile:e,route:o});return yL(r.role,n.name,i)}))}function eg(e){return{name:e.name,root:{model:e.rootModel,effort:e.rootEffort},specialistModel:Ka,defaultServiceTier:"standard",routes:bL(e.name)}}var og=[eg({name:"low",rootModel:tg,rootEffort:"medium"}),eg({name:"default",rootModel:tg,rootEffort:"high"}),eg({name:"high",rootModel:rg,rootEffort:"high"})];function _L(e){let t=["low","default","high"];if(e.length!==t.length)throw new ht("catalog_invalid","The profile catalog has an invalid size.");for(let r=0;r<t.length;r+=1){let n=e[r],o=t[r];if(!n||n.name!==o)throw new ht("catalog_invalid","The profile catalog order is invalid.",{index:r});let i=o==="high"?rg:tg,s=o==="low"?"medium":"high";if(n.root.model!==i||n.root.effort!==s||n.specialistModel!==Ka)throw new ht("catalog_invalid","A profile has an invalid model route.",{profile:n.name});if(n.routes.length!==Go.length)throw new ht("catalog_invalid","A profile is incomplete.",{profile:n.name});let a=new Set;for(let c of n.routes){if(a.has(c.key)||!xL.has(c.key)||c.model!==Ka||`${c.role}:${c.task}`!==c.key)throw new ht("catalog_invalid","A profile contains an invalid route.",{profile:n.name});a.add(c.key)}if(a.size!==Go.length)throw new ht("catalog_invalid","A profile is missing a specialist route.",{profile:n.name})}for(let r=0;r<Go.length;r+=1){let n=-1;for(let o of e){let i=o.routes[r];if(!i||TA[i.effort]<n)throw new ht("catalog_invalid","Profile route effort is not monotonic.",{route:Go[r]??"unknown"});n=TA[i.effort]}}}_L(og);br(og);var IA=og,wL=new Map,EL=new Map;for(let e of IA){wL.set(e.name,e);let t=new Map;for(let r of e.routes)t.set(r.key,r);EL.set(e.name,t)}import{execFile as OL}from"child_process";import{createHash as vL,randomBytes as AL}from"crypto";import{lstat as Zt,mkdir as rs,open as Xu,readFile as dg,readdir as Sn,realpath as TL,rename as IL,rm as Qo,stat as RL}from"fs/promises";import{basename as ig,dirname as Xo,isAbsolute as kL,join as _,relative as pg,resolve as ns}from"path";import{promisify as CL}from"util";var ep="holycodex-intent-1",fg="holycodex-plan-1",mg="holycodex-assignment-1",eo="toon-4",U=Q.pipe(Ut((e)=>e.trim().length>0)),Ze=Q.pipe(Ht(/^[a-z0-9][a-z0-9-]{0,95}$/u)),tp=Q.pipe(Ht(/^[a-f0-9]{64}$/u)),DA=Q.pipe(Ht(/^[a-f0-9]{40}$/u)),os=$u.pipe(Kv(1)),Qt=Q.pipe(Ut((e)=>!Number.isNaN(Date.parse(e)))),Ie=z(U),PL=H({pid:$u.pipe(Wv(0)),token:U}),NL=120000,FL=4294967295,hg=H({role:L("Explorer","Librarian","Worker","Reviewer"),task:U}).pipe(Ut((e)=>gn.some((t)=>t.role===e.role&&t.tasks.some((r)=>r.name===e.task)))),ti=H({kind:L("changed_path","check","repository_fact","ci","behavior","uncertainty"),value:U,result:N(L("passed","failed","observed","unknown"))}),gg=H({root:U,git_common_dir:U,initial_head:U,expected_head:U,expected_changes:Ie,expected_status_digest:tp,integrated_commit:N(DA),updated_at:Qt}),is=L("scoping","ready","executing","verifying","reviewing","blocked","needs_root_input","complete","abandoned"),ML=L("scoping","ready","executing","verifying","reviewing"),RA=H({required:ye,status:L("not_required","missing","passed","failed","accepted","rejected"),evidence:z(ti)}),ei=H({schema_version:L(ep),toon_compatibility:L(eo),id:Ze,slug:Ze,title:U,goal:U,acceptance_criteria:Ie,state:is,revision:os,plan_required:ye,active_plan_revision:N(os),active_plan_digest:N(tp),blockers:Ie,resume_state:N(ML),verification:RA,review:RA,acceptance_met:ye,root_readiness:ye,evidence:z(ti),baseline:gg,created_at:Qt,updated_at:Qt}),Ga=H({schema_version:L(fg),toon_compatibility:L(eo),intent_id:Ze,revision:os,predecessor_digest:N(tp),approach:U,scope:Ie,exclusions:Ie,assignments:Ie,dependencies:Ie,architecture:Ie,risks:Ie,assumptions:Ie,open_questions:Ie,verification:Ie,recovery:Ie,updated_at:Qt}),yg=L("completed","blocked","needs_root_input","failed"),qA=L("pending","executing","completed","blocked","needs_root_input","failed","superseded"),xg=H({id:Ze,outcome:yg,started_at:Qt,finished_at:Qt,summary:U,evidence:z(ti),context7:N(Xi),blocker:N(U),remaining_risk:Ie}),Qa=tp,Sg={schema_version:L(mg),toon_compatibility:L(eo),intent_id:Ze,id:Ze,objective:U,owner:hg,scope:Ie,constraints:Ie,exclusions:Ie,dependencies:Ie,acceptance_criteria:Ie,status:qA,revision:os,invocations:z(xg),active_invocation_id:N(U),active_started_at:N(Qt),supersedes:N(Ze),superseded_by:N(Ze),supersession_reason:N(U),supersession_provenance:N(U),evidence:z(ti),blocker:N(U),remaining_risk:Ie,created_at:Qt,updated_at:Qt},bg=H(Sg),UA=H({...Sg,capability:Qa}),Ja=H({...Sg,active_invocation_capability_verifier:N(Qa),active_invocation_capability:N(Qa)}),zu=".holycodex-transaction.toon",HA="holycodex-work-state-transaction-1",kA=H({schema_version:L(HA),state:L("prepared","committed"),files:z(H({path:U,previous:Q,next:Q})).pipe(Nr(1))}),jA=H({schema_version:L("holycodex-intent-0"),id:Ze,slug:Ze,title:U,goal:U,acceptance_criteria:Ie,state:is,revision:os,baseline:gg,created_at:Qt,updated_at:Qt});class S extends Error{code;details;constructor(e,t,r={}){super(t);this.name="IntentStoreError",this.code=e,this.details=r}}var rp=H({title:U,goal:U,acceptanceCriteria:z(U).pipe(Nr(1)),planRequired:N(ye),verificationRequired:N(ye),reviewRequired:N(ye)}),np=H({approach:U,scope:N(z(U)),exclusions:N(z(U)),assignments:N(z(U)),dependencies:N(z(U)),architecture:N(z(U)),risks:N(z(U)),assumptions:N(z(U)),openQuestions:N(z(U)),verification:N(z(U)),recovery:N(z(U))}),op=H({id:N(U),objective:U,owner:hg,scope:z(U).pipe(Nr(1)),constraints:N(z(U)),exclusions:N(z(U)),dependencies:N(z(U)),acceptanceCriteria:z(U).pipe(Nr(1))}),ip=H({scope:z(U).pipe(Nr(1))}),sp=H({scope:N(z(U).pipe(Nr(1)))}),ap=H({replacementId:Ze,replacementRevision:N(os),reason:U,provenance:U}),cp=H({commit:DA}),Xa=H({invocationId:N(U),capability:N(Qa),outcome:yg,startedAt:N(U),summary:U,scope:N(z(U).pipe(Nr(1))),evidence:N(z(ti)),context7:N(Xi),blocker:N(U),remainingRisk:N(z(U))}),LL=H({invocationId:U,startedAt:Qt,interruptionReason:U}),lp=H({evidence:N(z(ti)),verification:N(L("passed","failed")),review:N(L("accepted","rejected")),acceptanceMet:N(ye),rootReadiness:N(ye),clearBlockers:N(ye)}),ec=CL(OL);class up{repositoryRoot;stateRoot;#e;async diagnose(e){await this.#a();let t=await Sn(this.stateRoot).catch((m)=>{if(oe(m,"ENOENT"))throw new S("not_found","Intent was not found.",{reference:e});throw Se(m)}),r=[];for(let m of t.sort()){let x=_(this.stateRoot,m);if(!await za(x)||!await ts(_(x,"intent.toon")))continue;let D;try{D=await VL(_(x,"intent.toon"))}catch(k){if(Ya(k)){if(m===e||k.code!=="not_found"&&await zL(_(x,"intent.toon"),e))throw k;continue}throw k}if([D.id,D.slug,m].includes(e))r.push({directory:x,intent:D})}if(r.length!==1)throw new S(r.length?"current_ambiguous":"not_found",r.length?"Intent reference is ambiguous.":"Intent was not found.",{reference:e});let{directory:n,intent:o}=r[0],i=[],s=(m,x,D)=>{i.push({code:m,subject:x,repair:D})},a=_(n,zu);try{let m=await Zt(a);if(m.isSymbolicLink()||!m.isFile())s("transaction_journal_invalid","intent","Restore the transaction journal as a regular repository-local file.");else s("pending_transaction","intent","Recover the interrupted work-state transaction before relying on this diagnosis.")}catch(m){if(!oe(m,"ENOENT")&&!oe(m,"ENOTDIR"))throw Se(m)}let c=_(n,"plan.toon"),l,u=!1;try{l=await KL(c,Ga)}catch(m){if(!Ya(m))throw m;u=!0,s("plan_unreadable","plan","Repair the canonical Plan record before continuing.")}if(!u&&o.plan_required&&l===void 0)s("required_plan_missing","plan","Create the required Plan before continuing.");if(l!==void 0){let m=Sr(`${Xe(l)}
|
|
38
|
+
`);if(l.intent_id!==o.id||o.active_plan_revision!==l.revision||o.active_plan_digest!==m)s("plan_provenance_mismatch","plan","Reconcile the canonical Plan and Intent provenance.")}else if(!u&&(o.active_plan_revision!==void 0||o.active_plan_digest!==void 0))s("stale_plan_reference","intent","Restore or reconcile the referenced Plan.");let d=_(n,"assignments"),f=[];try{if(await lg(d,!0))f=(await Sn(d)).filter((m)=>m.endsWith(".toon")).sort()}catch(m){if(!Ya(m))throw m;s("assignment_directory_invalid","assignments","Restore the Assignments directory as a real repository-local directory.")}let g=[];for(let m of f){let x;try{x=await Zo(_(d,m),Ja)}catch(D){if(!Ya(D))throw D;s("assignment_unreadable",m,"Repair this Assignment record before continuing.");continue}if(x.intent_id!==o.id||m!==`${x.id}.toon`){s("assignment_identity_mismatch",m,"Reconcile the Assignment identity and path.");continue}g.push(x)}let y=new Map(g.map((m)=>[m.id,m]));for(let m of g){let x=`assignment:${m.id}`,D=m.active_invocation_id,k=D!==void 0,j=k||m.active_started_at!==void 0||m.active_invocation_capability!==void 0||m.active_invocation_capability_verifier!==void 0;if(m.status==="executing"&&!k)s("missing_active_invocation",x,"Reconcile the executing Assignment's invocation.");if(m.status!=="executing"&&j)s("orphaned_active_invocation",x,"Reconcile the active invocation and Assignment status.");if(k&&m.active_started_at===void 0)s("missing_invocation_start",x,"Reconcile the active invocation start time.");let T=new Set;for(let C of m.invocations){if(T.has(C.id))s("duplicate_invocation_id",x,"Reconcile duplicate invocation records.");T.add(C.id)}if(D!==void 0&&T.has(D))s("active_invocation_reused",x,"Reconcile the active invocation identity.");if(m.status==="superseded"&&m.superseded_by===void 0)s("missing_replacement",x,"Record or reconcile the replacement Assignment.");if(m.superseded_by!==void 0){let C=y.get(m.superseded_by);if(m.superseded_by===m.id||C?.supersedes!==m.id||m.status!=="superseded")s("stale_supersession",x,"Reconcile both ends of the supersession relation.");else if(m.supersession_reason===void 0||m.supersession_provenance===void 0||C.supersession_reason===void 0||C.supersession_provenance===void 0)s("supersession_metadata_missing",x,"Record the reason and provenance on both Assignments.");else if(m.supersession_reason!==C.supersession_reason||m.supersession_provenance!==C.supersession_provenance)s("supersession_metadata_mismatch",x,"Reconcile the reason and provenance on both Assignments.")}if(m.supersedes!==void 0&&(m.supersedes===m.id||y.get(m.supersedes)?.superseded_by!==m.id))s("stale_predecessor",x,"Reconcile the predecessor Assignment reference.");for(let C of m.dependencies)if(C===m.id)s("self_dependency",x,"Remove the Assignment's dependency on itself.");else if(C.startsWith("assignment-")&&!y.has(C))s("stale_dependency",x,`Reconcile missing dependency ${C}.`);else if(y.get(C)?.status==="superseded")s("superseded_dependency",x,`Reconcile dependency ${C} with its replacement Assignment.`);let I=m.invocations.at(-1);if(m.status==="completed"){if(I?.outcome!=="completed"||I.evidence.length===0&&I.context7===void 0)s("completion_evidence_missing",x,"Reconcile the completed invocation result and its evidence.")}else if(["blocked","needs_root_input","failed"].includes(m.status)&&I?.outcome!==m.status)s("assignment_result_mismatch",x,"Reconcile the status with its latest result.");if(["blocked","needs_root_input"].includes(m.status)&&m.blocker===void 0)s("assignment_blocker_missing",x,"Record the Assignment's current blocker.");if(m.status==="pending"&&m.invocations.length>0)s("pending_assignment_has_history",x,"Reconcile pending status with its results.");if(!["completed","superseded"].includes(m.status))s("assignment_unresolved",x,o.state==="abandoned"?"Treat as intentionally unfinished; create a new Intent if work resumes.":"Resume, repair, or explicitly supersede this Assignment.")}if(l!==void 0){for(let m of l.assignments)if(m.startsWith("assignment-")&&!y.has(m))s("stale_plan_assignment","plan",`Reconcile missing Assignment ${m}.`);else if(y.get(m)?.status==="superseded")s("superseded_plan_assignment","plan",`Reconcile Plan reference ${m} with its replacement Assignment.`)}let O=GL(g);for(let m of O)s("dependency_cycle",`assignment:${m}`,"Remove the cyclic Assignment dependency before continuing.");if(o.state==="complete"&&g.some((m)=>!["completed","superseded"].includes(m.status)))s("terminal_intent_with_unresolved_work","intent","Reconcile terminal state and unfinished Assignments.");if(o.state==="complete"&&g.length===0)s("assignment_required","intent","Reconcile the required Assignment record.");if(["complete","abandoned"].includes(o.state)&&o.blockers.length>0)s("terminal_intent_with_blockers","intent","Reconcile terminal state and blockers.");if(["blocked","needs_root_input"].includes(o.state)){if(o.blockers.length===0)s("blocked_without_reason","intent","Record the blocker or resume the previous state.");if(o.resume_state===void 0)s("resume_state_missing","intent","Record the state to resume after the blocker clears.")}else if(o.resume_state!==void 0)s("stale_resume_state","intent","Clear the stale blocked-state resume target.");if(o.state==="complete"){if(o.verification.required&&(o.verification.status!=="passed"||!PA(o.verification.evidence)))s("verification_evidence_missing","intent","Reconcile required verification evidence.");if(o.review.required&&(o.review.status!=="accepted"||o.review.evidence.length===0))s("review_evidence_missing","intent","Reconcile required review evidence.");if(!o.acceptance_met||!o.root_readiness||o.evidence.length===0)s("completion_evidence_missing","intent","Reconcile acceptance and Root readiness evidence.")}try{await this.#o(o,g.filter((m)=>m.status==="executing").flatMap((m)=>m.scope))}catch(m){if(!(m instanceof S)||m.code!=="repository_drift")throw m;s("repository_drift","repository","Reconcile the recorded baseline with the current repository state.")}return i.sort((m,x)=>cg(m.subject,x.subject)||cg(m.code,x.code)||cg(m.repair,x.repair)),{intent_id:o.id,issues:i}}#s;constructor(e,t={}){this.repositoryRoot=ns(e),this.stateRoot=_(this.repositoryRoot,".holycodex"),this.#e=t.now??(()=>new Date),this.#s=t.repositorySnapshot??(()=>$A(this.repositoryRoot))}async recover(){if(await this.#a(),!await Ju(this.stateRoot))return[];return await Yo(_(this.stateRoot,".intent-store"),async()=>{let e=await this.#l(this.stateRoot),t=await this.#h();return[...e,...t].sort()})}async#l(e,t=!1){let r;try{r=t?await Sn(e,{recursive:!0}):await Sn(e)}catch(o){if(oe(o,"ENOENT"))return[];throw Se(o)}let n=[];for(let o of r){let i=ig(o);if(!i.startsWith(".holycodex-write-")||!i.endsWith(".tmp"))continue;let s=_(e,o);await ro(s),await Qo(s,{force:!0}),n.push(pg(this.stateRoot,s).replaceAll("\\","/"))}return n.sort()}async#h(){let e;try{e=await Sn(this.stateRoot)}catch(r){if(oe(r,"ENOENT"))return[];throw Se(r)}let t=[];for(let r of e){if(r===".intent-store")continue;let n=_(this.stateRoot,r);if(!await za(n))continue;await Yo(_(n,".intent-store"),async()=>{t.push(...await this.#u(n))})}return t.sort()}async#u(e){let t=[],r=_(e,zu);if(await this.#d(e))t.push(pg(this.stateRoot,r).replaceAll("\\","/"));return t.push(...await this.#l(e,!0)),t}async#d(e){let t=_(e,zu);await ro(t);let r;try{r=await Zt(t)}catch(l){if(oe(l,"ENOENT"))return!1;throw Se(l)}if(r.isSymbolicLink()||!r.isFile())throw new S("schema_invalid","The work-state transaction journal must be a regular file.",{path:t});let n=await Zo(t,kA),o=n.files.filter((l)=>to(l.path)==="intent.toon"),i=n.files.filter((l)=>{let u=to(l.path);return u!==void 0&&/^assignments\/[a-z0-9][a-z0-9-]{0,95}\.toon$/u.test(u)});if(n.files.length<2||o.length!==1||i.length<1||o.length+i.length!==n.files.length)throw new S("schema_invalid","The work-state transaction must pair one or more Assignments with their Intent.",{path:t});let s=new Set,a=n.files.map((l)=>{let u=to(l.path);if(u===void 0)throw new S("schema_invalid","The work-state transaction contains an invalid target path.",{path:t,target:l.path});let d=MA(e,l.path);if(s.has(d))throw new S("schema_invalid","The work-state transaction has duplicate targets.",{path:t,target:l.path});s.add(d);let f=n.state==="committed"?l.next:l.previous,g=u==="intent.toon"?LA(f,ei,d):LA(f,Ja,d);return{canonical:u,target:d,contents:f,record:g}}),c=a.find((l)=>l.canonical==="intent.toon")?.record?.id;if(c===void 0)throw new S("schema_invalid","The work-state transaction has no Intent.",{path:t});for(let l of a)if(await ro(l.target),l.canonical!=="intent.toon"){let u=l.canonical.slice(12,-5);ug(l.record,c,u,l.target)}for(let l of a)await Za(l.target,l.contents);return await Qo(t,{force:!0}),await Qu(e),!0}async#a(){try{let e=await Zt(this.stateRoot);if(e.isSymbolicLink()||!e.isDirectory())throw new S("schema_invalid","Repository-local work state must be a real directory.",{path:this.stateRoot})}catch(e){if(oe(e,"ENOENT"))return;throw Se(e)}}async createIntent(e){let t=ae(rp,e);if(!t.title.trim()||!t.goal.trim()||t.acceptanceCriteria.length===0)throw kt("Intent title, goal, and acceptance criteria are required.");return await this.recover(),await rs(this.stateRoot,{recursive:!0}),await Yo(_(this.stateRoot,".intent-store"),async()=>{let r=await this.#s(),n=jL(t.title),o=Sr([r.root,t.title.trim(),t.goal.trim()].join("\x00")).slice(0,10),i=`${n}-${o}`,s=1;while(await Ju(_(this.stateRoot,i)))s+=1,i=`${n}-${o}-${String(s).padStart(2,"0")}`;let a=`intent-${o}${s===1?"":`-${String(s).padStart(2,"0")}`}`,c=this.#e().toISOString(),l=ae(ei,{schema_version:ep,toon_compatibility:eo,id:a,slug:n,title:t.title.trim(),goal:t.goal.trim(),acceptance_criteria:[...t.acceptanceCriteria],state:"scoping",revision:1,plan_required:t.planRequired??!1,blockers:[],verification:Yu(t.verificationRequired??!0),review:Yu(t.reviewRequired??!0),acceptance_met:!1,root_readiness:!1,evidence:[],baseline:sg(r,c),created_at:c,updated_at:c}),u=_(this.stateRoot,i);return await rs(_(u,"assignments"),{recursive:!0}),await St(_(u,"intent.toon"),l),await Za(_(this.stateRoot,"current"),`${i}
|
|
39
|
+
`),l})}async listIntents(){if(await this.#a(),!await Ju(this.stateRoot))return[];return await Yo(_(this.stateRoot,".intent-store"),async()=>{await this.#l(this.stateRoot);let e;try{e=await Sn(this.stateRoot)}catch(r){if(oe(r,"ENOENT"))return[];throw Se(r)}let t=[];for(let r of e.sort()){if(r===".intent-store")continue;let n=_(this.stateRoot,r);if(!await za(n))continue;await Yo(_(n,".intent-store"),async()=>{await this.#u(n);let o=_(n,"intent.toon");if(await ts(o))t.push(await this.#t(o))})}return t.sort((r,n)=>r.id.localeCompare(n.id))})}async readIntent(e){let t=await this.#r(e);return await this.#n(t,async()=>this.#t(_(t,"intent.toon")))}async currentIntent(){await this.#a(),await this.recover();let e=_(this.stateRoot,"current"),t=await Zt(e).catch((o)=>{if(oe(o,"ENOENT"))return;throw Se(o)});if(t?.isSymbolicLink()||t&&!t.isFile())throw new S("schema_invalid","The current Intent pointer must be a regular file.");let r=t?(await dg(e,"utf8")).trim():"";if(t&&!r)throw new S("schema_invalid","The current Intent pointer must select a work-state directory.");if(r){let o=ns(this.stateRoot,r);if(!zA(this.stateRoot,o))throw new S("schema_invalid","The current Intent pointer escapes repository-local state.",{directory:r});if(!await za(o))throw new S("schema_invalid","The current Intent pointer does not select a work-state directory.",{directory:r});return await this.#n(o,async()=>this.#t(_(o,"intent.toon")))}let n=(await this.listIntents()).filter((o)=>o.state!=="complete"&&o.state!=="abandoned");if(n.length===1)return n[0];throw new S(n.length?"current_ambiguous":"not_found",n.length?"Multiple active Intents require explicit selection.":"No current Intent exists.",{intent_ids:n.map((o)=>o.id)})}async selectCurrent(e){let t=await this.#r(e),r=await this.#t(_(t,"intent.toon"));return await Yo(_(this.stateRoot,".intent-store"),async()=>Za(_(this.stateRoot,"current"),`${ig(t)}
|
|
40
|
+
`)),r}async transitionIntent(e,t,r,n){let o=ae(is,t),i=n===void 0?void 0:ae(U,n);if(!Number.isSafeInteger(r)||r<1)throw kt("Intent revision must be a positive integer.");let s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(_(s,"intent.toon"));if(Rt(a.revision,r),o==="complete")throw new S("invalid_transition","Use the predicate-checked complete operation.");if(o==="abandoned")return await this.#m(s,a);return await this.#g(s,a,o,i)})}async completeIntent(e,t){let r=await this.#r(e);return await this.#n(r,async()=>{let n=await this.#t(_(r,"intent.toon"));if(Rt(n.revision,t),xn(n),await this.#o(n),n.active_plan_revision!==void 0)await this.readPlan(e);let o=await this.#c(r,n),i=[];if(n.state!=="reviewing")i.push("intent_not_reviewing");if(n.plan_required&&n.active_plan_revision===void 0)i.push("required_plan_missing");if(n.blockers.length)i.push("global_blockers_unresolved");if(o.length===0)i.push("assignment_required");if(o.some((a)=>a.status!=="completed"&&a.status!=="superseded"))i.push("assignments_unresolved");if(n.verification.required&&n.verification.status!=="passed")i.push("verification_unresolved");if(n.review.required&&n.review.status!=="accepted")i.push("review_unresolved");if(!n.acceptance_met)i.push("acceptance_criteria_unmet");if(!n.root_readiness)i.push("root_readiness_missing");if(i.length)return{completed:!1,reasons:i};let s=yn(n,this.#e,{state:"complete"});return await St(_(r,"intent.toon"),s),s})}async abandonIntent(e,t){let r=await this.#r(e);return await this.#n(r,async()=>{let n=await this.#t(_(r,"intent.toon"));return Rt(n.revision,t),await this.#m(r,n)})}async recordIntentEvidence(e,t,r){let n=ae(lp,r),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(_(o,"intent.toon"));if(Rt(i.revision,t),xn(i),n.verification!==void 0||n.review!==void 0)await this.#o(i);if(n.verification!==void 0&&i.state!=="verifying")throw new S("invalid_transition","Verification evidence is only accepted while the Intent is verifying.",{state:i.state});let s=[...i.verification.evidence,...n.evidence??[]];if(n.verification==="passed"&&!PA(s))throw new S("invalid_input","Verification cannot pass without meaningful successful check or behavioral evidence.",{required_evidence:["check","behavior","ci"]});if(n.review!==void 0&&i.state!=="reviewing")throw new S("invalid_transition","Review evidence is only accepted while the Intent is reviewing.",{state:i.state});let a=[...i.evidence,...n.evidence??[]],c=n.verification===void 0?i.verification:{...i.verification,status:n.verification,evidence:[...i.verification.evidence,...n.evidence??[]]},l=n.review===void 0?i.review:{...i.review,status:n.review,evidence:[...i.review.evidence,...n.evidence??[]]},u=n.review==="rejected"&&i.state==="reviewing"?"executing":i.state,d=yn(i,this.#e,{state:u,evidence:a,verification:c,review:l,...n.acceptanceMet===void 0?{}:{acceptance_met:n.acceptanceMet},...n.rootReadiness===void 0?{}:{root_readiness:n.rootReadiness},...n.clearBlockers?{blockers:[]}:{}});return await St(_(o,"intent.toon"),d),d})}async recordVcsIntegration(e,t,r){let n=ae(cp,r),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(_(o,"intent.toon"));if(Rt(i.revision,t),xn(i),i.state!=="reviewing")throw new S("invalid_transition","VCS integration is only accepted after review while the Intent is reviewing.",{state:i.state});if(i.review.required&&i.review.status!=="accepted")throw new S("not_ready","VCS integration requires accepted review evidence.",{review_status:i.review.status});let s=await this.#s();if(s.root!==i.baseline.root||s.gitCommonDir!==i.baseline.git_common_dir)throw new S("repository_drift","VCS integration repository identity does not match the Intent baseline.",{expected_root:i.baseline.root,actual_root:s.root});if(s.head!==n.commit)throw new S("repository_drift","VCS integration requires the requested commit to be the current HEAD.",{expected_head:n.commit,actual_head:s.head});if(s.changedPaths.length)throw new S("repository_drift","VCS integration requires a clean worktree.",{changed_paths:[...s.changedPaths].sort()});let a=await DL(this.repositoryRoot,n.commit);if(a.parents[0]!==i.baseline.expected_head)throw new S("repository_drift","VCS integration commit parent does not match the recorded baseline HEAD.",{expected_parent:i.baseline.expected_head,actual_parents:a.parents});let c=await qL(this.repositoryRoot,i.baseline.expected_head,n.commit),l=[...new Set(ag(i.baseline.expected_changes,c))].sort();if(c.join("\x00")!==l.join("\x00"))throw new S("repository_drift","VCS integration commit tree does not match the recorded expected change set.",{expected_changes:l,actual_changes:c});let u=this.#e().toISOString(),d={kind:"repository_fact",value:`Root VCS integration recorded at ${n.commit}; ${String(c.length)} expected path(s) committed.`,result:"observed"},f=yn(i,this.#e,{baseline:sg(s,u,i.baseline.initial_head,n.commit),evidence:[...i.evidence,d]});return await St(_(o,"intent.toon"),f),f})}async readPlan(e){let t=await this.#r(e),r=_(t,"plan.toon");if(!await ts(r))return;let n=await Zo(r,Ga),o=await this.#t(_(t,"intent.toon")),i=Sr(`${Xe(n)}
|
|
41
|
+
`);if(n.intent_id!==o.id||o.active_plan_revision!==n.revision||o.active_plan_digest!==i)throw new S("schema_invalid","Canonical Plan provenance does not match its Intent.",{intent_id:o.id,plan_revision:n.revision});return n}async revisePlan(e,t,r,n){let o=ae(np,t);if(!o.approach.trim())throw kt("Plan approach is required.");let i=await this.#r(e);return await this.#n(i,async()=>{let s=await this.#t(_(i,"intent.toon"));Rt(s.revision,r),xn(s),await this.#o(s);let a=_(i,"plan.toon"),c=await ts(a)?await Zo(a,Ga):void 0;if(c===void 0&&n!==void 0)Rt(0,n);if(c!==void 0)Rt(c.revision,n);let l,u;if(c){let y=`${Xe(c)}
|
|
42
|
+
`;u=Sr(y),l=await XL(i),await JL(l,y)}let d=ae(Ga,{schema_version:fg,toon_compatibility:eo,intent_id:s.id,revision:(c?.revision??0)+1,...u?{predecessor_digest:u}:{},approach:o.approach.trim(),scope:[...o.scope??[]],exclusions:[...o.exclusions??[]],assignments:[...o.assignments??[]],dependencies:[...o.dependencies??[]],architecture:[...o.architecture??[]],risks:[...o.risks??[]],assumptions:[...o.assumptions??[]],open_questions:[...o.openQuestions??[]],verification:[...o.verification??[]],recovery:[...o.recovery??[]],updated_at:this.#e().toISOString()});await St(a,d);let f=Sr(`${Xe(d)}
|
|
43
|
+
`),g=yn(s,this.#e,{active_plan_revision:d.revision,active_plan_digest:f,verification:es(s.verification),review:es(s.review),acceptance_met:!1,root_readiness:!1});return await St(_(i,"intent.toon"),g),{intent:g,plan:d,...l?{archived:ig(l)}:{}}})}async createAssignment(e,t,r){let n=ae(op,t);if(!n.objective.trim()||n.scope.length===0||n.acceptanceCriteria.length===0)throw kt("Assignment objective, scope, and acceptance criteria are required.");let o=Zu(n.scope),i=await this.#r(e);return await this.#n(i,async()=>{let s=await this.#t(_(i,"intent.toon"));if(Rt(s.revision,r),xn(s),await this.#o(s,o),n.owner.role==="Worker"&&n.owner.task==="operations"&&s.baseline.integrated_commit!==s.baseline.expected_head)throw new S("not_ready","Worker.operations requires a successfully integrated exact commit.",{expected_head:s.baseline.expected_head});let a=n.id??`assignment-${Sr([s.id,n.objective,...o].join("\x00")).slice(0,10)}`;if(!/^[a-z0-9][a-z0-9-]{0,95}$/u.test(a))throw kt("Assignment id is invalid.");let c=_(i,"assignments",`${a}.toon`);if(await Ju(c))throw new S("already_exists","Assignment already exists.",{id:a});let l=this.#e().toISOString(),u=ae(bg,{schema_version:mg,toon_compatibility:eo,intent_id:s.id,id:a,objective:n.objective.trim(),owner:n.owner,scope:o,constraints:[...n.constraints??[]],exclusions:[...n.exclusions??[]],dependencies:[...n.dependencies??[]],acceptance_criteria:[...n.acceptanceCriteria],status:"pending",revision:1,invocations:[],evidence:[],remaining_risk:[],created_at:l,updated_at:l});return await rs(Xo(c),{recursive:!0}),await St(c,u),u})}async reviseAssignmentScope(e,t,r,n){let o=ae(ip,r),i=Zu(o.scope),s=ae(Ze,t),a=await this.#r(e);return await this.#n(a,async()=>{let c=await this.#t(_(a,"intent.toon"));xn(c);let l=await this.#i(a,c,s);if(Rt(l.revision,n),l.status==="completed"||l.status==="superseded")throw new S("invalid_transition","A completed or superseded Assignment cannot have its scope revised.");let u=Va(l,this.#e,{scope:i});return await St(_(a,"assignments",`${s}.toon`),u),Jo(u)})}async supersedeAssignment(e,t,r,n){let o=ae(ap,n),i=ae(Ze,t),s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(_(s,"intent.toon"));if(xn(a),a.acceptance_met||a.root_readiness||a.review.status==="accepted")throw new S("invalid_transition","Accepted Intent evidence cannot be superseded.",{intent_id:a.id});let c=await this.#i(s,a,i);Rt(c.revision,r);let l=await this.#i(s,a,o.replacementId);if(o.replacementRevision!==void 0)Rt(l.revision,o.replacementRevision);if(l.id===c.id)throw kt("An Assignment cannot supersede itself.");if(c.status==="completed"||c.status==="superseded")throw new S("invalid_transition","Only unfinished, non-superseded Assignments may be replaced.",{assignment_id:c.id,status:c.status});if(c.status==="executing")throw new S("invalid_transition","An executing Assignment must record its active invocation before supersession.",{assignment_id:c.id});if(c.superseded_by!==void 0)throw new S("invalid_transition","An Assignment with an existing replacement cannot be superseded again.",{assignment_id:c.id,replacement_id:c.superseded_by});if(l.status==="completed"||l.status==="executing"||l.status==="superseded")throw new S("invalid_transition","A supersession replacement must be unfinished and inactive.",{assignment_id:l.id,status:l.status});if(l.supersedes!==void 0||l.superseded_by!==void 0)throw new S("invalid_transition","An Assignment already participating in a supersession cannot be reused.",{assignment_id:l.id});if(!c.scope.some((O)=>l.scope.some((m)=>Xn(O,m)||Xn(m,O))))throw kt("A supersession replacement must overlap the predecessor bounded scope.");let d=await this.#c(s,a);await this.#o(a,[...c.scope,...l.scope,...d.filter((O)=>O.status==="executing").flatMap((O)=>O.scope)]);let f=Va(c,this.#e,{status:"superseded",blocker:void 0,active_invocation_id:void 0,active_started_at:void 0,active_invocation_capability_verifier:void 0,active_invocation_capability:void 0,superseded_by:l.id,supersession_reason:o.reason.trim(),supersession_provenance:o.provenance.trim()}),g=Va(l,this.#e,{supersedes:c.id,supersession_reason:o.reason.trim(),supersession_provenance:o.provenance.trim()}),y=yn(a,this.#e,{state:a.blockers.length===0&&["blocked","needs_root_input","verifying","reviewing"].includes(a.state)?"executing":a.state,blockers:[...a.blockers],...a.blockers.length===0?{resume_state:void 0}:{},verification:es(a.verification),review:es(a.review),acceptance_met:!1,root_readiness:!1,evidence:[...a.evidence,{kind:"behavior",value:`Assignment ${c.id} superseded by ${l.id}: ${o.reason.trim()} (${o.provenance.trim()})`,result:"observed"}]});return await this.#f(s,[{path:`assignments/${c.id}.toon`,previous:`${Xe(c)}
|
|
44
|
+
`,next:`${Xe(f)}
|
|
45
|
+
`},{path:`assignments/${l.id}.toon`,previous:`${Xe(l)}
|
|
46
|
+
`,next:`${Xe(g)}
|
|
47
|
+
`},{path:"intent.toon",previous:`${Xe(a)}
|
|
48
|
+
`,next:`${Xe(y)}
|
|
49
|
+
`}]),{assignment:Jo(f),replacement:Jo(g),intent:y}})}async readAssignment(e,t){let r=ae(Ze,t),n=await this.#r(e);return await this.#n(n,async()=>{let o=await this.#t(_(n,"intent.toon"));return Jo(await this.#i(n,o,r))})}async isLegacyExecutingAssignment(e,t){let r=ae(Ze,t),n=await this.#r(e);return await this.#n(n,async()=>{let o=await this.#t(_(n,"intent.toon")),i=await this.#i(n,o,r);return i.status==="executing"&&i.active_invocation_capability_verifier===void 0&&i.active_invocation_capability===void 0})}async#i(e,t,r){let n=_(e,"assignments");await lg(n,!0);let o=_(n,`${r}.toon`);if(!await ts(o))throw new S("not_found","Assignment was not found.",{assignment_id:r});let i=await Zo(o,Ja);return ug(i,t.id,r,o),i}async listAssignments(e){let t=await this.#r(e);return await this.#n(t,async()=>(await this.#c(t,await this.#t(_(t,"intent.toon")))).map(Jo))}async#c(e,t){let r=_(e,"assignments");if(!await lg(r,!0))return[];let n;try{n=await Sn(r)}catch(i){if(oe(i,"ENOENT"))return[];throw Se(i)}return await Promise.all(n.filter((i)=>i.endsWith(".toon")).sort().map(async(i)=>{let s=_(r,i),a=await Zo(s,Ja),c=i.slice(0,-5);return ug(a,t.id,c,s),a}))}async startAssignment(e,t,r,n={}){let o=ae(sp,n),i=ae(Ze,t),s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(_(s,"intent.toon"));xn(a);let c=await this.#i(s,a,i);Rt(c.revision,r);let l=FA(c.scope,o.scope);if(await this.#o(a,l),c.status==="completed")throw new S("invalid_transition","A completed Assignment cannot be restarted.");if(c.status==="superseded")throw new S("invalid_transition","A superseded Assignment cannot be restarted.",{assignment_id:c.id});if(c.status==="executing")throw new S("invalid_transition","Assignment is already executing; record its active invocation result first.",{assignment_id:c.id,...c.active_invocation_id?{invocation_id:c.active_invocation_id}:{}});let u=this.#e().toISOString(),d=NA(c),f=HL(),g=Va(c,this.#e,{status:"executing",scope:l,blocker:void 0,active_invocation_id:d,active_started_at:u,active_invocation_capability_verifier:Sr(f),active_invocation_capability:void 0});return await St(_(s,"assignments",`${i}.toon`),g),ae(UA,{...Jo(g),capability:f})})}async recordAssignmentResult(e,t,r,n){return await this.#p(e,t,r,n,!1)}async recordSpecialistAssignmentResult(e,t,r,n){if(ae(Xa,n).capability===void 0)throw kt("Specialist Assignment results require an active invocation capability.");return await this.#p(e,t,r,n,!0)}async recoverInterruptedAssignment(e,t,r,n){let o=ae(LL,n),i=o.interruptionReason.trim(),s={kind:"behavior",value:`Interrupted invocation ${o.invocationId} started at ${o.startedAt} recovered as failed: ${i}`,result:"failed"};return await this.#p(e,t,r,{invocationId:o.invocationId,outcome:"failed",startedAt:o.startedAt,summary:`Interrupted invocation recovered as failed: ${i}`,evidence:[s]},!1,{invocationId:o.invocationId,startedAt:o.startedAt})}async#p(e,t,r,n,o,i){let s=ae(Xa,n),a=ae(Ze,t),c=await this.#r(e);return await this.#n(c,async()=>{let l=await this.#t(_(c,"intent.toon"));if(xn(l),i!==void 0&&e!==l.id)throw kt("Interruption recovery requires the exact Intent ID reference.");let u=await this.#i(c,l,a);if(Rt(u.revision,r),u.status!=="executing")throw new S("invalid_transition",`Assignment result requires an executing Assignment; current status is ${u.status}.`,{assignment_id:u.id,status:u.status});if(i===void 0&&!o&&s.capability===void 0&&(u.active_invocation_capability_verifier!==void 0||u.active_invocation_capability!==void 0))throw new S("invalid_transition","This Assignment invocation requires its active capability to record a result.",{assignment_id:u.id});if(i!==void 0){if(u.active_invocation_id!==i.invocationId||u.active_started_at!==i.startedAt)throw new S("invalid_transition","Interruption recovery does not match the active invocation identity and start time.",{assignment_id:u.id,expected_invocation_id:u.active_invocation_id,expected_started_at:u.active_started_at})}if(u.active_invocation_id!==void 0&&s.invocationId!==void 0&&u.active_invocation_id!==s.invocationId)throw new S("invalid_transition","Assignment result does not match the active invocation.",{assignment_id:u.id,expected_invocation_id:u.active_invocation_id,actual_invocation_id:s.invocationId});if(o&&(u.active_invocation_id===void 0||s.invocationId===void 0))throw new S("invalid_transition","Specialist Assignment results require the active invocation identity.",{assignment_id:u.id});if(o&&u.active_invocation_capability_verifier===void 0&&u.active_invocation_capability===void 0)throw new S("invalid_transition","The active Assignment invocation has no capability to authorize a specialist result.",{assignment_id:u.id});if(s.capability!==void 0&&(u.active_invocation_capability_verifier!==void 0?Sr(s.capability)!==u.active_invocation_capability_verifier:u.active_invocation_capability!==s.capability))throw new S("invalid_transition","Assignment result capability does not match the active invocation.",{assignment_id:u.id});if((s.outcome==="blocked"||s.outcome==="needs_root_input")&&!s.blocker?.trim())throw kt("Blocked results require a local blocker.");if(i===void 0&&Yh({role:u.owner.role,task:u.owner.task,objective:u.objective,scope:u.scope,constraints:u.constraints,exclusions:u.exclusions,dependencies:u.dependencies,acceptanceCriteria:u.acceptance_criteria})&&s.context7===void 0)throw new S("invalid_input","This Librarian Assignment result requires typed Context7 evidence.",{assignment_id:u.id,required_evidence:"context7"});let d=FA(u.scope,s.scope),f=await this.#s(),g=ag(l.baseline.expected_changes,f.changedPaths),y=[...s.evidence??[]],O=new Set(y.filter((_e)=>_e.kind==="changed_path").map((_e)=>_e.value)),m=[...O].filter((_e)=>!d.some((as)=>Xn(_e,as)));if(m.length)throw new S("repository_drift","Assignment evidence declares paths outside its bounded scope.",{assignment_id:u.id,out_of_scope_paths:m.sort()});let D=(await this.#c(c,l)).filter((_e)=>_e.id!==u.id&&_e.status==="executing"),k=f.changedPaths.filter((_e)=>D.some((as)=>as.scope.some((QA)=>Xn(_e,QA)))),j=new Set(k),T=new Set([...g,...O,...k]),I=f.changedPaths.filter((_e)=>!T.has(_e)),C=new Set(g),M=f.changedPaths.filter((_e)=>d.some((as)=>Xn(_e,as))&&!C.has(_e)&&!O.has(_e)&&!j.has(_e)),ee=f.root!==l.baseline.root||f.gitCommonDir!==l.baseline.git_common_dir,X=CA(f.statusDigest)!==l.baseline.expected_status_digest,J=f.head!==l.baseline.expected_head||X||[...new Set(g)].sort().join("\x00")!==[...new Set(f.changedPaths)].sort().join("\x00"),he=[...O].some((_e)=>f.changedPaths.includes(_e)),ut=k.length>0;if(i===void 0&&(ee||I.length||M.length||X&&!he&&!ut||f.head!==l.baseline.expected_head&&!he&&!ut))throw new S("repository_drift","Repository state changed outside the recorded Assignment result.",{expected_head:l.baseline.expected_head,actual_head:f.head,unexpected_paths:[...new Set([...I,...M])].sort(),concurrent_assignments:D.map((_e)=>_e.id).sort()});let Qe=this.#e().toISOString(),pt=u.active_invocation_id??s.invocationId??NA(u);if(u.invocations.some((_e)=>_e.id===pt))throw new S("already_exists","Assignment invocation already exists.",{invocation_id:pt});let Me=ae(xg,{id:pt,outcome:s.outcome,started_at:u.active_started_at??s.startedAt??Qe,finished_at:Qe,summary:s.summary,evidence:y,...s.context7===void 0?{}:{context7:s.context7},...s.blocker?{blocker:s.blocker}:{},remaining_risk:[...s.remainingRisk??[]]}),Re=Va(u,this.#e,{status:s.outcome,scope:d,invocations:[...u.invocations,Me],active_invocation_id:void 0,active_started_at:void 0,active_invocation_capability_verifier:void 0,active_invocation_capability:void 0,evidence:[...u.evidence,...y],blocker:s.blocker,remaining_risk:[...s.remainingRisk??[]]}),dt=u.owner.role==="Worker"&&u.owner.task==="operations",Lr=l.baseline.integrated_commit!==void 0&&l.baseline.integrated_commit===l.baseline.expected_head&&f.head===l.baseline.expected_head&&f.changedPaths.length===0,ss=dt&&s.outcome==="failed",no=dt&&s.outcome==="completed"&&Lr&&l.state==="reviewing"&&(!l.verification.required||l.verification.status==="passed")&&(!l.review.required||l.review.status==="accepted"),ZA=J||s.outcome==="failed",Og=yn(l,this.#e,{baseline:i===void 0?sg(f,Qe,l.baseline.initial_head,Lr?l.baseline.integrated_commit:void 0):l.baseline,...no||!ZA?{}:{state:ss?"executing":l.state,verification:es(l.verification),review:es(l.review),acceptance_met:!1,root_readiness:!1}});return await this.#y(c,a,u,Re,l,Og),{assignment:Jo(Re),intent:Og}})}async#g(e,t,r,n){let o=t.state;if(r==="blocked"||r==="needs_root_input"){if(["complete","abandoned","blocked","needs_root_input"].includes(o))throw Gu(o,r);if(!n?.trim())throw kt("A blocker or required input is required.");let s=yn(t,this.#e,{state:r,blockers:[n.trim()],resume_state:o});return await St(_(e,"intent.toon"),s),s}if(o==="blocked"||o==="needs_root_input"){if(r!==t.resume_state||t.blockers.length)throw Gu(o,r)}else if(!{scoping:["ready"],ready:["executing"],executing:["verifying"],verifying:["reviewing","executing"],reviewing:["executing"]}[o]?.includes(r))throw Gu(o,r);if(r==="ready"){let s=[];if(!t.goal.trim())s.push("goal_missing");if(!t.acceptance_criteria.length)s.push("acceptance_criteria_missing");if(t.plan_required&&t.active_plan_revision===void 0)s.push("required_plan_missing");if((t.active_plan_revision===void 0?void 0:await this.readPlan(t.id))?.open_questions.length)s.push("material_open_questions");if(s.length)throw new S("not_ready","Intent readiness predicates failed.",{reasons:s})}if(r==="executing"&&o==="ready")await this.#o(t);if(r==="reviewing"&&t.verification.required&&t.verification.status!=="passed")throw new S("invalid_transition","Verification must pass before review.");if(r==="reviewing")await this.#o(t);let i=yn(t,this.#e,{state:r,resume_state:void 0});return await St(_(e,"intent.toon"),i),i}async#n(e,t){return await Yo(_(e,".intent-store"),async()=>(await this.#u(e),await t()))}async#y(e,t,r,n,o,i){await this.#f(e,[{path:`assignments/${t}.toon`,previous:`${Xe(r)}
|
|
50
|
+
`,next:`${Xe(n)}
|
|
51
|
+
`},{path:"intent.toon",previous:`${Xe(o)}
|
|
52
|
+
`,next:`${Xe(i)}
|
|
53
|
+
`}])}async#f(e,t){let r=_(e,zu),n=ae(kA,{schema_version:HA,state:"prepared",files:t.map((i)=>({...i}))}),o=n.files.map((i)=>MA(e,i.path));await St(r,n);try{for(let[i,s]of o.entries())await Za(s,n.files[i].next);await St(r,{...n,state:"committed"})}catch(i){try{await this.#d(e)}catch(s){throw Se(s)}throw i}await Qo(r,{force:!0}),await Qu(e)}async#m(e,t){if(t.state==="complete"||t.state==="abandoned")throw Gu(t.state,"abandoned");let r=yn(t,this.#e,{state:"abandoned",blockers:[]});return await St(_(e,"intent.toon"),r),r}async#o(e,t){let r=await this.#s(),n=[...ag(e.baseline.expected_changes,r.changedPaths)].sort(),o=[...r.changedPaths].sort(),i=new Set(t===void 0?[]:o.filter((a)=>t.some((c)=>Xn(a,c)))),s=[...new Set([...n,...i])].sort();if(r.root!==e.baseline.root||r.gitCommonDir!==e.baseline.git_common_dir||r.head!==e.baseline.expected_head||s.join("\x00")!==o.join("\x00")||CA(r.statusDigest)!==e.baseline.expected_status_digest&&i.size===0)throw new S("repository_drift","Repository baseline no longer matches recorded assumptions.",{expected_head:e.baseline.expected_head,actual_head:r.head,expected_changes:s,actual_changes:o})}async#r(e){await this.#a();let t;try{t=await Sn(this.stateRoot)}catch(n){if(oe(n,"ENOENT"))throw new S("not_found","Intent was not found.",{reference:e});throw Se(n)}let r=[];for(let n of t.sort()){let o=_(this.stateRoot,n);if(!await za(o))continue;let i=_(o,"intent.toon");if(!await ts(i))continue;let s=await this.#t(i);if(s.id===e||s.slug===e||n===e)r.push(o)}if(r.length===1)return r[0];if(r.length>1)throw new S("current_ambiguous","Intent reference is ambiguous.",{reference:e});throw new S("not_found","Intent was not found.",{reference:e})}async#t(e){let t=await pp(e),r=yr(ei,t);if(ze(r))return r.right;let n=yr(jA,t);if(ge(n))throw new S("schema_invalid","Persisted Intent failed schema validation.",{path:e,error:String(r.left)});let o=BA(n.right);return await St(e,o),o}}async function $A(e){let t=await TL(e),r=async(...l)=>{try{return(await ec("git",["-C",t,...l],{encoding:"utf8"})).stdout.trimEnd()}catch(u){throw new S("io_failure","Repository identity requires an accessible Git worktree.",{message:u instanceof Error?u.message:String(u)})}},n=await r("rev-parse","--git-common-dir"),o=await UL(t,"rev-parse","--verify","HEAD")??"unborn",i=await r("status","--porcelain=v1","-z","--untracked-files=all"),s=await r("status","--porcelain=v1","--untracked-files=all"),a=i.split("\x00"),c=[];for(let l=0;l<a.length;l+=1){let u=a[l];if(!u)continue;if(c.push(u.slice(3)),u.slice(0,2).includes("R")||u.slice(0,2).includes("C"))l+=1}return c.sort(),{root:t,gitCommonDir:ns(t,n),head:o,changedPaths:c,statusDigest:Sr(s)}}async function DL(e,t){try{let r=(await ec("git",["-C",e,"show","-s","--format=%H%n%P",t],{encoding:"utf8"})).stdout.trim(),[n,o=""]=r.split(`
|
|
54
|
+
`);if(n!==t)throw Error(`Resolved commit ${n??""} does not match requested ${t}.`);return{hash:n,parents:o?o.split(/\s+/u):[]}}catch(r){throw new S("repository_drift","VCS integration commit could not be inspected.",{commit:t,message:r instanceof Error?r.message:String(r)})}}async function qL(e,t,r){try{return(await ec("git",["-C",e,"diff","--name-only","-z","--no-ext-diff",t,r],{encoding:"utf8"})).stdout.split("\x00").filter(Boolean).sort()}catch(n){throw new S("repository_drift","VCS integration commit tree could not be inspected.",{parent:t,commit:r,message:n instanceof Error?n.message:String(n)})}}async function UL(e,...t){try{return(await ec("git",["-C",e,...t],{encoding:"utf8"})).stdout.trim()}catch{return}}function BA(e){return ae(ei,{...e,schema_version:ep,toon_compatibility:eo,plan_required:!1,blockers:[],verification:Yu(!0),review:Yu(!0),acceptance_met:!1,root_readiness:!1,evidence:[]})}function Yu(e){return{required:e,status:e?"missing":"not_required",evidence:[]}}function es(e){return{...e,status:e.required?"missing":"not_required"}}function sg(e,t,r=e.head,n){return{root:e.root,git_common_dir:e.gitCommonDir,initial_head:r,expected_head:e.head,expected_changes:[...e.changedPaths].sort(),expected_status_digest:/^[a-f0-9]{64}$/u.test(e.statusDigest)?e.statusDigest:Sr(e.statusDigest),...n===void 0?{}:{integrated_commit:n},updated_at:t}}function CA(e){return/^[a-f0-9]{64}$/u.test(e)?e:Sr(e)}function PA(e){return e.some((t)=>["check","behavior","ci"].includes(t.kind)&&["passed","observed"].includes(t.result??""))}function HL(){return AL(32).toString("hex")}function NA(e){let t=e.invocations.length+1,r=`invocation-${String(t).padStart(3,"0")}`;while(e.invocations.some((n)=>n.id===r))t+=1,r=`invocation-${String(t).padStart(3,"0")}`;return r}function yn(e,t,r){return ae(ei,WA({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function Va(e,t,r){return ae(Ja,WA({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function Jo(e){let{active_invocation_capability_verifier:t,active_invocation_capability:r,...n}=e;return ae(bg,n)}function WA(e){let t={...e};for(let[r,n]of Object.entries(t))if(n===void 0)delete t[r];return t}function jL(e){return e.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-|-$/gu,"").slice(0,48).replace(/-$/u,"")||"intent"}function Zu(e){let t=e.map((r)=>{let n=to(r);if(n===void 0)throw kt("Assignment scope must contain canonical repository-relative paths.");return n});return[...new Set(t)].sort()}function FA(e,t){let r=Zu(e);if(t===void 0)return r;let n=Zu(t);if(r.some((i)=>!n.includes(i)))throw kt("Assignment scope expansion must preserve the existing scope.");if(n.filter((i)=>!r.some((s)=>$L(i,s))).length)throw kt("Assignment scope expansion exceeds the declared component authority.");return n}function $L(e,t){if(Xn(e,t))return!0;let r=to(t);if(r===void 0||r===".")return!1;let n=r.split("/"),o=n.at(-1);if(o===void 0||!o.includes("."))return!1;let i=n.slice(0,-1).join("/")||".";return e!==i&&Xn(e,i)}function Xn(e,t){let r=to(e),n=to(t);if(r===void 0||n===void 0)return!1;return n==="."||r===n||r.startsWith(`${n}/`)}function to(e){let t=e.replaceAll("\\","/");if(!t||t.startsWith("/")||/^[a-z]:/iu.test(t))return;let r=t.split("/");if(r.some((o)=>o===".."))return;let n=r.filter((o)=>o!==""&&o!==".");return n.length===0?".":n.join("/")}function MA(e,t){let r=to(t);if(r===void 0||r!=="intent.toon"&&!/^assignments\/[a-z0-9][a-z0-9-]{0,95}\.toon$/u.test(r))throw new S("schema_invalid","The work-state transaction target is outside the supported Intent records.",{path:t});let n=ns(e,r);if(!zA(ns(e),n))throw new S("schema_invalid","The work-state transaction target escapes the Intent directory.",{path:t});return n}function ag(e,t){let r=new Set(t);return e.map((n)=>{if(r.has(n))return n;let o=WL(n);return o!==void 0&&r.has(o)?o:n})}var BL={a:7,b:8,t:9,n:10,v:11,f:12,r:13,"\\":92,'"':34};function WL(e){if(e.length<2||e[0]!=='"'||e[e.length-1]!=='"')return;let t=[],r=new TextEncoder,n=e.slice(1,-1);for(let o=0;o<n.length;){let i=n.codePointAt(o);if(i===void 0)return;if(i!==92){if(i===34||i<32||i===127)return;let l=String.fromCodePoint(i);t.push(...r.encode(l)),o+=l.length;continue}let s=n[o+1];if(s===void 0)return;let a=BL[s];if(a!==void 0){t.push(a),o+=2;continue}if(s<"0"||s>"7")return;let c=o+2;while(c<n.length&&c<o+4&&n[c]>="0"&&n[c]<="7")c+=1;t.push(Number.parseInt(n.slice(o+1,c),8)),o=c}try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(Uint8Array.from(t))}catch{return}}function Sr(e){return vL("sha256").update(e).digest("hex")}function Rt(e,t){if(t===void 0||e!==t)throw new S("stale_write","Persisted revision changed before mutation.",{expected_revision:t,actual_revision:e})}function kt(e){return new S("invalid_input",e)}function xn(e){if(e.state==="complete"||e.state==="abandoned")throw new S("invalid_transition","Terminal Intents cannot be mutated.",{state:e.state})}function Gu(e,t){return new S("invalid_transition",`Intent cannot transition from ${e} to ${t}.`,{source:e,target:t})}function ae(e,t){let r=yr(e,t);if(ge(r))throw new S("schema_invalid","Value failed Effect Schema validation.",{error:String(r.left)});return r.right}async function pp(e){let t;try{let r=await Zt(e);if(r.isSymbolicLink()||!r.isFile())throw new S("schema_invalid","Persistent work state must be a regular file.",{path:e});t=await dg(e,"utf8")}catch(r){if(oe(r,"ENOENT"))throw new S("not_found","Persistent work state was not found.",{path:e});throw Se(r)}return KA(t,e)}async function Zo(e,t){return ae(t,await pp(e))}async function KL(e,t){let r;try{r=await Zt(e)}catch(n){if(oe(n,"ENOENT")||oe(n,"ENOTDIR"))return;throw Se(n)}if(r.isSymbolicLink()||!r.isFile())throw new S("schema_invalid","Persistent work state must be a regular file.",{path:e});return await Zo(e,t)}async function VL(e){let t=await pp(e),r=yr(ei,t);if(ze(r))return r.right;let n=yr(jA,t);if(ge(n))throw new S("schema_invalid","Persisted Intent failed schema validation.",{path:e,error:String(r.left)});return BA(n.right)}async function zL(e,t){let r;try{r=await pp(e)}catch(o){if(Ya(o))return!1;throw o}if(typeof r!=="object"||r===null||Array.isArray(r))return!1;let n=r;return n.id===t||n.slug===t}function Ya(e){return e instanceof S&&["malformed_toon","schema_invalid","not_found"].includes(e.code)}function GL(e){let t=new Map(e.map((s)=>[s.id,s])),r=new Set,n=[],o=new Set,i=(s)=>{let a=n.indexOf(s);if(a>=0){for(let c of n.slice(a))o.add(c);return}if(r.has(s))return;n.push(s);for(let c of t.get(s)?.dependencies??[])if(c!==s&&t.has(c))i(c);n.pop(),r.add(s)};for(let s of[...t.keys()].sort())i(s);return[...o].sort()}function cg(e,t){return e<t?-1:e>t?1:0}function LA(e,t,r){return ae(t,KA(e,r))}function KA(e,t){try{return Xg(e,{strict:!0})}catch(r){throw new S("malformed_toon","Persistent work state is malformed TOON.",{path:t,message:r instanceof Error?r.message:String(r)})}}async function St(e,t){await Za(e,`${Xe(t)}
|
|
55
|
+
`)}async function Za(e,t){await ro(e),await rs(Xo(e),{recursive:!0}),await ro(e);let r=_(Xo(e),`.holycodex-write-${process.pid}-${crypto.randomUUID()}.tmp`);try{let n=await Xu(r,"wx",384);try{await n.writeFile(t,"utf8"),await n.sync()}finally{await n.close()}await IL(r,e),await Qu(Xo(e))}catch(n){throw await Qo(r,{force:!0}),Se(n)}}async function JL(e,t){await ro(e);try{let r=await Xu(e,"wx",256);try{await r.writeFile(t,"utf8"),await r.sync()}finally{await r.close()}await Qu(Xo(e))}catch(r){if(oe(r,"EEXIST"))throw new S("archive_conflict","Archived plans are immutable.",{path:e});throw Se(r)}}async function Qu(e){if(process.platform==="win32")return;try{let t=await Xu(e,"r");try{await t.sync()}finally{await t.close()}}catch(t){if(oe(t,"EINVAL")||oe(t,"ENOSYS")||oe(t,"ENOTSUP")||oe(t,"EOPNOTSUPP")||oe(t,"EISDIR"))return;throw t}}async function Yo(e,t){let r=Xo(e);await ro(e),await rs(r,{recursive:!0});let n=!1;for(let a=0;a<200;a+=1)try{await rs(e),n=!0;break}catch(c){if(!oe(c,"EEXIST"))throw Se(c);try{let l=await Zt(e);if(l.isSymbolicLink()||!l.isDirectory())throw new S("schema_invalid","The work-state lock must be a real directory.",{path:e});let u=await VA(e);if(u.kind==="owned"&&!await YL(u.owner.pid)){await Qo(e,{recursive:!0,force:!0});continue}if(u.kind==="missing"&&Date.now()-l.mtimeMs>NL){await Qo(e,{recursive:!0,force:!0});continue}}catch(l){if(!oe(l,"ENOENT"))throw Se(l)}await new Promise((l)=>setTimeout(l,Math.min(5+a,50)))}if(!n)throw new S("stale_write","Another mutation is still in progress.",{lock:e});let o=_(e,".owner"),i=crypto.randomUUID(),s;try{await ro(o),s=await Xu(o,"wx",384),await s.writeFile(`${JSON.stringify({pid:process.pid,token:i})}
|
|
56
|
+
`,"utf8"),await s.sync()}catch(a){if(s!==void 0)try{await s.close()}catch{}if(oe(a,"EEXIST"))throw new S("stale_write","Another mutation is still in progress.",{lock:e});throw Se(a)}if(s===void 0)throw Se(Error("The work-state lock owner was not opened."));try{return await t()}finally{try{await s.close()}finally{await QL(e,i)}}}async function VA(e){let t=_(e,".owner");try{let r=await Zt(t);if(r.isSymbolicLink()||!r.isFile())return{kind:"unknown"};let n=await dg(t,"utf8"),o;try{o=JSON.parse(n)}catch{return{kind:"unknown"}}let i=yr(PL,o);return ze(i)?{kind:"owned",owner:i.right}:{kind:"unknown"}}catch(r){if(oe(r,"ENOENT"))return{kind:"missing"};throw Se(r)}}async function YL(e){if(e===process.pid)return!0;if(process.platform==="win32")return await ZL(e);if(!["aix","android","darwin","freebsd","haiku","linux","openbsd","sunos","win32"].includes(process.platform))return!0;try{return process.kill(e,0),!0}catch(r){return oe(r,"EPERM")}}async function ZL(e){if(!Number.isSafeInteger(e)||e>FL)return!1;try{let{stdout:t}=await ec("tasklist.exe",["/FI",`PID eq ${e}`,"/FO","CSV","/NH"],{encoding:"utf8",windowsHide:!0});return t.split(/\r?\n/u).some((r)=>/^"[^"]*","(\d+)",/u.exec(r)?.[1]===String(e))}catch{return!0}}async function QL(e,t){let r=await VA(e);if(r.kind!=="owned"||r.owner.token!==t)return;await Qo(e,{recursive:!0,force:!0})}async function XL(e){let t=(await Sn(e)).map((r)=>/^plan\.old-(\d{3})\.toon$/u.exec(r)?.[1]).filter((r)=>r!==void 0).map(Number);return _(e,`plan.old-${String((t.length?Math.max(...t):0)+1).padStart(3,"0")}.toon`)}async function Ju(e){try{return await RL(e),!0}catch(t){if(oe(t,"ENOENT"))return!1;throw Se(t)}}async function ts(e){try{let t=await Zt(e);return t.isFile()&&!t.isSymbolicLink()}catch(t){if(oe(t,"ENOENT")||oe(t,"ENOTDIR"))return!1;throw Se(t)}}async function lg(e,t){try{let r=await Zt(e);if(r.isSymbolicLink()||!r.isDirectory())throw new S("schema_invalid","Persistent work-state directories must be real directories.",{path:e});return!0}catch(r){if(oe(r,"ENOENT")&&t)return!1;throw Se(r)}}async function za(e){try{let t=await Zt(e);return t.isDirectory()&&!t.isSymbolicLink()}catch(t){if(oe(t,"ENOENT")||oe(t,"ENOTDIR"))return!1;throw Se(t)}}function ug(e,t,r,n){if(e.intent_id!==t||e.id!==r)throw new S("schema_invalid","Assignment provenance does not match its Intent or file name.",{path:n,expected_intent_id:t,actual_intent_id:e.intent_id,expected_assignment_id:r,actual_assignment_id:e.id})}async function ro(e){let t=ns(e);while(!0){try{if((await Zt(t)).isSymbolicLink())throw new S("schema_invalid","Persistent work state must not contain symbolic links.",{path:t})}catch(n){if(!oe(n,"ENOENT"))throw Se(n)}let r=Xo(t);if(r===t)break;t=r}}function oe(e,t){return typeof e==="object"&&e!==null&&"code"in e&&e.code===t}function Se(e){return e instanceof S?e:new S("io_failure","Persistent work-state I/O failed.",{message:e instanceof Error?e.message:String(e)})}function zA(e,t){let r=pg(e,t);return r===""||!r.startsWith(`..${eD()}`)&&r!==".."&&!kL(r)}function eD(){return process.platform==="win32"?"\\":"/"}var GA={state:`Usage: holycodex-agent state diagnose --intent <ref> [--repo <path>]
|
|
57
|
+
|
|
58
|
+
Read-only diagnosis of one Intent, its active Plan, Assignments, and repository baseline.
|
|
59
|
+
`,"state diagnose":`Usage: holycodex-agent state diagnose --intent <ref> [--repo <path>]
|
|
60
|
+
|
|
61
|
+
Output: intent_id and deterministic issues with code, subject, and repair guidance.
|
|
62
|
+
Does not recover transactions, acquire locks, or change persisted records.
|
|
63
|
+
`,intent:`Usage: holycodex-agent intent <command> [options]
|
|
56
64
|
|
|
57
65
|
Intent owns the durable global goal, lifecycle, baseline, blockers, gates, and readiness.
|
|
58
66
|
Commands: create, list, current, read, select, transition, evidence, integrate, complete, abandon.
|
|
@@ -154,7 +162,7 @@ for legacy executing records with neither a persisted verifier nor a raw capabil
|
|
|
154
162
|
The operation atomically persists the Assignment and Intent revisions and returns both current
|
|
155
163
|
records. Worker evidence
|
|
156
164
|
cannot set Root gates; actual repository evolution or failure invalidates prior gates.
|
|
157
|
-
`};function
|
|
165
|
+
`};function _g(e){return GA[e.slice(0,2).join(" ")]??GA[e[0]??""]??`Usage: holycodex-agent <intent|plan|assignment|state> <command> [options]
|
|
158
166
|
|
|
159
167
|
Deterministic model-facing work-state API. JSON responses use holycodex-agent-response-1.
|
|
160
168
|
All mutations require --revision and are atomic. No command prompts or emits ANSI.
|
|
@@ -163,8 +171,9 @@ Commands:
|
|
|
163
171
|
intent create, list, current, read, select, transition, evidence, integrate, complete, abandon
|
|
164
172
|
plan read, revise
|
|
165
173
|
assignment create, list, read, revise, supersede, start, recover, result
|
|
174
|
+
state diagnose
|
|
166
175
|
|
|
167
176
|
Use -h or --help at any command depth. Failures are classified and exit nonzero.
|
|
168
|
-
`}function
|
|
169
|
-
`),0}catch(r){let n=
|
|
170
|
-
`),n.code==="invalid_usage"||n.code==="invalid_input"?2:n.code==="completion_refused"?3:1}}async function
|
|
177
|
+
`}function wg(e){return e.includes("-h")||e.includes("--help")||e.length===0}var JA="holycodex-agent-response-1",tD=z(Q),rD=H({invocationId:Q,startedAt:Q,interruptionReason:Q});async function nD(e=Bun.argv.slice(2),t={cwd:process.cwd(),writeStdout:(r)=>process.stdout.write(r),writeStderr:(r)=>process.stderr.write(r)}){try{let r=Eg(tD,e),n=r.filter((a)=>!a.startsWith("-")).slice(0,2);if(wg(r))return t.writeStdout(_g(n)),0;let o=iD(r),i=new up(o.options.repo??t.cwd??process.cwd()),s=await oD(i,o.command,o.subcommand,o.options);return t.writeStdout(`${JSON.stringify({schema_version:JA,ok:!0,operation:`${o.command}.${o.subcommand}`,data:s})}
|
|
178
|
+
`),0}catch(r){let n=cD(r);return t.writeStderr(`${JSON.stringify({schema_version:JA,ok:!1,error:n})}
|
|
179
|
+
`),n.code==="invalid_usage"||n.code==="invalid_input"?2:n.code==="completion_refused"?3:1}}async function oD(e,t,r,n){let o=n.intent;if(t==="intent"){if(r==="create")return await e.createIntent(Mr(rp,lt(n,"input")));if(r==="list")return await e.listIntents();if(r==="current")return await e.currentIntent();if(r==="read")return await e.readIntent(je(o,"intent"));if(r==="select")return await e.selectCurrent(je(o,"intent"));if(r==="transition")return await e.transitionIntent(je(o,"intent"),Eg(is,lt(n,"state")),Xt(n),n.blocker);if(r==="evidence")return await e.recordIntentEvidence(je(o,"intent"),Xt(n),Mr(lp,lt(n,"input")));if(r==="integrate")return await e.recordVcsIntegration(je(o,"intent"),Xt(n),Mr(cp,lt(n,"input")));if(r==="abandon")return await e.abandonIntent(je(o,"intent"),Xt(n));if(r==="complete"){let i=await e.completeIntent(je(o,"intent"),Xt(n));if("completed"in i&&!i.completed)throw new er("completion_refused","Intent completion predicates failed.",{reasons:i.reasons});return i}}if(t==="plan"){if(r==="read")return await e.readPlan(je(o,"intent"))??null;if(r==="revise")return await e.revisePlan(je(o,"intent"),Mr(np,lt(n,"input")),Xt(n),aD(n["plan-revision"]))}if(t==="assignment"){if(r==="create")return await e.createAssignment(je(o,"intent"),Mr(op,lt(n,"input")),Xt(n));if(r==="revise")return await e.reviseAssignmentScope(je(o,"intent"),lt(n,"assignment"),Mr(ip,lt(n,"input")),Xt(n));if(r==="supersede")return await e.supersedeAssignment(je(o,"intent"),lt(n,"assignment"),Xt(n),Mr(ap,lt(n,"input")));if(r==="list")return await e.listAssignments(je(o,"intent"));if(r==="read")return await e.readAssignment(je(o,"intent"),lt(n,"assignment"));if(r==="start")return await e.startAssignment(je(o,"intent"),lt(n,"assignment"),Xt(n),n.input===void 0?{}:Mr(sp,n.input));if(r==="recover")return await e.recoverInterruptedAssignment(je(o,"intent"),lt(n,"assignment"),Xt(n),Mr(rD,lt(n,"input")));if(r==="result"){let i=Mr(Xa,lt(n,"input")),s=je(o,"intent"),a=lt(n,"assignment"),c=Xt(n);if(i.capability===void 0&&await e.isLegacyExecutingAssignment(s,a))return await e.recordAssignmentResult(s,a,c,i);return await e.recordSpecialistAssignmentResult(s,a,c,i)}}if(t==="state"&&r==="diagnose")return await e.diagnose(je(o,"intent"));throw new er("invalid_usage","Unknown command. Use --help.")}function iD(e){let t=e[0],r=e[1];if(!t||!r||t.startsWith("-")||r.startsWith("-"))throw new er("invalid_usage","A command and subcommand are required. Use --help.");let n={},o=sD(t,r);for(let i=2;i<e.length;i+=2){let s=e[i],a=e[i+1];if(!s?.startsWith("--")||a===void 0||a.startsWith("--"))throw new er("invalid_usage","Options require --name value pairs.");let c=s.slice(2);if(n[c]!==void 0)throw new er("invalid_usage",`Duplicate option --${c}.`);if(!o.has(c))throw new er("invalid_usage",`Unknown option --${c}.`);n[c]=a}return{command:t,subcommand:r,options:n}}function sD(e,t){let r=["repo"],n={"intent create":["input"],"intent list":[],"intent current":[],"intent read":["intent"],"intent select":["intent"],"intent transition":["intent","revision","state","blocker"],"intent evidence":["intent","revision","input"],"intent integrate":["intent","revision","input"],"intent complete":["intent","revision"],"intent abandon":["intent","revision"],"plan read":["intent"],"plan revise":["intent","revision","plan-revision","input"],"assignment create":["intent","revision","input"],"assignment revise":["intent","assignment","revision","input"],"assignment supersede":["intent","assignment","revision","input"],"assignment list":["intent"],"assignment read":["intent","assignment"],"assignment start":["intent","assignment","revision","input"],"assignment recover":["intent","assignment","revision","input"],"assignment result":["intent","assignment","revision","input"],"state diagnose":["intent"]};return new Set([...r,...n[`${e} ${t}`]??[]])}class er extends Error{code;details;constructor(e,t,r={}){super(t);this.code=e,this.details=r}}function Mr(e,t){let r;try{r=JSON.parse(t)}catch{throw new er("invalid_input","--input must be valid JSON.")}return Eg(e,r)}function Eg(e,t){let r=Qi(e,{onExcessProperty:"error"})(t);if(ge(r))throw new er("invalid_input","Input failed Effect Schema validation.",{issue:String(r.left)});return r.right}function lt(e,t){return je(e[t],t)}function je(e,t){if(!e)throw new er("invalid_usage",`Missing --${t}.`);return e}function Xt(e){return YA(e.revision,"revision")}function YA(e,t){let r=Number(e);if(!Number.isSafeInteger(r)||r<1)throw new er("invalid_input",`--${t} must be a positive integer.`);return r}function aD(e){return e===void 0?void 0:YA(e,"plan-revision")}function cD(e){if(e instanceof S||e instanceof er)return{code:e.code,message:e.message,details:e.details};return{code:"internal_error",message:e instanceof Error?e.message:"Agent CLI failed.",details:{}}}if(import.meta.main)process.exitCode=await nD();export{_g as agentHelp,wg as agentHelpRequested,nD as runAgentBinary};
|