holycodex 0.16.4 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +5 -0
  2. package/dist/agent.js +54 -38
  3. package/dist/assets/plugin/plugin.json +2 -2
  4. package/dist/assets/plugin/skills/code-review/SKILL.md +10 -23
  5. package/dist/assets/plugin/skills/code-review/agents/openai.yaml +2 -2
  6. package/dist/assets/plugin/skills/commit/SKILL.md +6 -12
  7. package/dist/assets/plugin/skills/commit/agents/openai.yaml +1 -1
  8. package/dist/assets/plugin/skills/compress/SKILL.md +4 -15
  9. package/dist/assets/plugin/skills/compress/agents/openai.yaml +1 -1
  10. package/dist/assets/plugin/skills/context7-cli/SKILL.md +7 -9
  11. package/dist/assets/plugin/skills/context7-cli/agents/openai.yaml +2 -2
  12. package/dist/assets/plugin/skills/debugging/SKILL.md +7 -22
  13. package/dist/assets/plugin/skills/debugging/agents/openai.yaml +2 -2
  14. package/dist/assets/plugin/skills/grill-me/SKILL.md +21 -0
  15. package/dist/assets/plugin/skills/grill-me/agents/openai.yaml +6 -0
  16. package/dist/assets/plugin/skills/handoff/SKILL.md +4 -13
  17. package/dist/assets/plugin/skills/handoff/agents/openai.yaml +1 -1
  18. package/dist/assets/plugin/skills/operations/SKILL.md +11 -26
  19. package/dist/assets/plugin/skills/operations/agents/openai.yaml +1 -1
  20. package/dist/assets/plugin/skills/plan/SKILL.md +9 -20
  21. package/dist/assets/plugin/skills/plan/agents/openai.yaml +2 -2
  22. package/dist/assets/plugin/skills/plan-review/SKILL.md +7 -18
  23. package/dist/assets/plugin/skills/plan-review/agents/openai.yaml +2 -2
  24. package/dist/assets/plugin/skills/programming/SKILL.md +7 -17
  25. package/dist/assets/plugin/skills/programming/agents/openai.yaml +2 -2
  26. package/dist/assets/plugin/skills/refactor/SKILL.md +4 -18
  27. package/dist/assets/plugin/skills/refactor/agents/openai.yaml +1 -1
  28. package/dist/assets/plugin/skills/rules/SKILL.md +7 -14
  29. package/dist/assets/plugin/skills/rules/agents/openai.yaml +2 -2
  30. package/dist/assets/plugin/skills/stop-slop/SKILL.md +5 -42
  31. package/dist/assets/plugin/skills/stop-slop/agents/openai.yaml +1 -1
  32. package/dist/assets/plugin/skills/testing-quality.md +13 -24
  33. package/dist/assets/plugin/skills/writing-for-agents/SKILL-MECHANICS.md +6 -16
  34. package/dist/assets/plugin/skills/writing-for-agents/SKILL.md +29 -55
  35. package/dist/assets/plugin/skills/writing-for-agents/agents/openai.yaml +1 -1
  36. package/dist/index.js +69 -53
  37. package/package.json +2 -2
package/dist/agent.js CHANGED
@@ -1,51 +1,53 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var ju="0.15";function cr(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&&$u(n.value))cr(n.value,t)}Object.freeze(e)}function $u(e){return typeof e==="object"&&e!==null}var Ca={comma:",",tab:"\t",pipe:"|"},kr=Ca.comma;function at(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 Gh(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 Yh(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 La(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 tt(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 rt(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 tk=/^[ \t]*/;function rk(){return{lineNumber:0,blankLines:[]}}function nk(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=tk.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=ik(e.slice(a));if(s===-1&&l[0]==="#")return;let u=ok(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 ok(e,t){return Math.floor(e/t)}function ik(e){let t=e.length;while(t>0&&e[t-1]===" ")t--;return t===e.length?e:e.slice(0,t)}var Zh=Symbol("fetch-line");function sk(e){return{buffer:[],done:!1,lastLine:void 0,scanState:rk(),indentSize:e.indentSize,strict:e.strict}}function*Qh(e){while(e.buffer.length===0&&!e.done){let t=yield Zh;if(t===void 0){e.done=!0;return}let r=nk(t,e.scanState,e.indentSize,e.strict);if(r!==void 0)e.buffer.push(r)}}function*Pt(e){return yield*Qh(e),e.buffer[0]}function*bt(e){yield*Qh(e);let t=e.buffer[0];if(t!==void 0)e.buffer.shift(),e.lastLine=t;return t}function*ak(e,t){let r=e[Symbol.iterator](),n=t.next();while(!n.done)if(n.value===Zh){let o=r.next();n=t.next(o.done?void 0:o.value)}else yield n.value,n=t.next()}var ck=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Xh(e){return e==="true"||e==="false"||e==="null"}function lk(e){if(!e)return!1;if(!ck.test(e))return!1;let t=Number(e);return!Number.isNaN(t)&&Number.isFinite(t)}function Pa(e,t){let r=e.trimStart(),n=-1;if(r.startsWith('"')){let T=La(r,0);if(T===-1)return{kind:"notHeader"};if(!r.slice(T+1).startsWith("["))return{kind:"notHeader"};let A=e.length-r.length+T+1;n=e.indexOf("[",A)}else n=tt(e,"[");if(n===-1)return{kind:"notHeader"};let o=tt(e,":");if(o!==-1&&o<n)return{kind:"notHeader"};let i=tt(e,"]",n);if(i===-1)return{kind:"notHeader"};let s=i+1,a=s,c=tt(e,"{",i);if(c!==-1&&c<tt(e,":",i)){let T=e.slice(i+1,c);if(T!==""){let R=T.trim();return{kind:"invalid",reason:R===""?"Unexpected whitespace between bracket segment and field list":`Unexpected content "${R}" between bracket segment and field list`}}let A=Bu(e,c);if(A!==-1)a=A+1}if(s=tt(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 f;if(n>0){let T=e.slice(0,n);if(T!==T.trimEnd())return{kind:"invalid",reason:"Unexpected whitespace between key and bracket segment"};f=T.startsWith('"')?Fa(T):T}let d=at(e.slice(s+1)),h=e.slice(n+1,i),g;try{g=pk(h,t)}catch(T){return{kind:"invalid",reason:T.message}}let{length:P,delimiter:x,keyed:E}=g,W;if(c!==-1&&c<s){let T=Bu(e,c);if(T!==-1&&T<s){let A=e.slice(c+1,T),R=mk(A,x);if(R!==void 0)return{kind:"invalid",reason:`Header delimiter mismatch: bracket declares "${Bh(x)}" but field list contains unquoted "${Bh(R)}"`};try{W=eg(A,x)}catch(v){return{kind:"invalid",reason:v.message}}}}let F=W?tg(W):void 0,D=F?`Duplicate field name "${F}" in field list`:void 0;if(E&&!W)return{kind:"invalid",reason:"Keyed header requires a field list"};if(W&&d)return{kind:"invalid",reason:D??"Unexpected content after fields-bearing header colon"};return{kind:"header",header:{key:f,length:P,delimiter:x,fields:W,keyed:E},inlineValues:d||void 0,strictError:D}}var uk=/^(?:0|[1-9]\d*)$/;function pk(e,t){let r=e,n=t;if(r.endsWith("\t"))n=Ca.tab,r=r.slice(0,-1);else if(r.endsWith("|"))n=Ca.pipe,r=r.slice(0,-1);let o=!1;if(r.endsWith(":"))o=!0,r=r.slice(0,-1);if(!uk.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 eg(e,t){return fk(e,t).map((r)=>{let n=at(r);if(!n)throw SyntaxError("Empty field name in field list");let o=tt(n,"{");if(o===-1)return{name:Fa(n)};let i=at(n.slice(0,o));if(!i)throw SyntaxError("Missing field name before nested field group");let s=Bu(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=eg(n.slice(o+1,s),t);return{name:Fa(i),children:a}})}function fk(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 Bu(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 tg(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=tg(r.children);if(n!==void 0)return n}}}function zu(e){let t=0;for(let r of e)t+=r.children?zu(r.children):1;return t}var dk=[",","\t","|"];function mk(e,t){for(let r of dk){if(r===t)continue;if(tt(e,r)!==-1)return r}}function Bh(e){if(e==="\t")return"\\t";return e}function Vu(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(at(n)),n="",i++;continue}n+=s,i++}if(n||r.length>0)r.push(at(n));return r}function Ju(e){return e.map((t)=>Da(t))}function Da(e){let t=at(e);if(!t)return"";if(t.startsWith('"'))return Fa(t);if(Xh(t)){if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null}if(lk(t)){let r=Number.parseFloat(t);return Object.is(r,-0)?0:r}return t}function Fa(e){let t=at(e);if(t.startsWith('"')){let r=La(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 Yh(t.slice(1,r))}return t}function hk(e,t){let r=tt(e,":",t);if(r===-1)throw SyntaxError("Missing colon after key");return{key:at(e.slice(t,r)),end:r+1}}function gk(e,t){let r=La(e,t);if(r===-1)throw SyntaxError("Unterminated quoted key");let n=Yh(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 rg(e,t){return e[t]==='"'?gk(e,t):hk(e,t)}function ng(e){return e.trim().startsWith("[")&&tt(e,":")!==-1}function yk(e){return tt(e,":")!==-1}function Wn(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 xk(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 Sk(e,t,r){if(e?.depth===t&&!e.content.startsWith("- ")&&og(e.content,r.delimiter))throw new ke(`Expected ${r.length} tabular rows, but found more`,{line:e.lineNumber,source:e.raw})}function Gu(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 og(e,t){let r=tt(e,":"),n=tt(e,t);if(r===-1)return!0;if(n!==-1&&n<r)return!0;return!1}function bk(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}function _k(e,t){let r=bk(t);return ak(e,wk(sk(r),r))}function*wk(e,t){let r=yield*Pt(e);if(!r){yield{type:"startObject"},yield{type:"endObject"};return}if(at(r.content)==="[]"){yield*bt(e),yield{type:"startArray",length:0},yield{type:"endArray"},yield*Kh(e,t.strict);return}if(ng(r.content)){let i=rt(r,()=>Ma(Pa(r.content,kr),t.strict));if(i){yield*bt(e),yield*Na(i.header,i.inlineValues,e,0,t,r),yield*Kh(e,t.strict);return}}yield*bt(e);let n=yield*Pt(e);if(n===void 0&&!zh(r)){yield{type:"primitive",value:rt(r,()=>Da(r.content))};return}if(!zh(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*ji(r,e,0,t,o);while(!0){let i=yield*Pt(e);if(!i)break;if(i.depth!==0){if(t.strict)throw ig(i,0);sg(i),yield*bt(e);continue}yield*bt(e),yield*ji(i,e,0,t,o)}yield{type:"endObject"}}function Ek(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 ig(e,t){return new ke(`Over-indented line: expected depth ${t}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function sg(e){if(e.content.startsWith("- ")||e.content==="-"||tt(e.content,":")!==-1)return;throw new ke("Unexpected bare token line outside root primitive position",{line:e.lineNumber,source:e.raw})}function ag(e){return new ke("Keyless keyed header is only valid at the document root",{line:e.lineNumber,source:e.raw})}function Ok(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 Tk(e){return new ke("Keyless header with a field list is only valid at the document root",{line:e.lineNumber,source:e.raw})}function*Kh(e,t){if(!t)return;let r=yield*Pt(e);if(r)throw new ke("Unexpected content after the document root",{line:r.lineNumber,source:r.raw})}function Ku(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*ji(e,t,r,n,o){let i=e.content,s=rt(e,()=>Ma(Pa(i,kr),n.strict));if(s&&s.header.key!==void 0){Ku(s.header.key,e,o),yield{type:"key",key:s.header.key},yield*Na(s.header,s.inlineValues,t,r,n,e);return}if(s&&s.header.key===void 0&&n.strict)throw s.header.keyed?ag(e):Ok(e);let{key:a,end:c}=rt(e,()=>rg(i,0)),l=at(i.slice(c));if(Ku(a,e,o),yield{type:"key",key:a},!l){let u=yield*Pt(t);if(u&&u.depth>r){Ek(u,r,n.strict),yield{type:"startObject"},yield*kk(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:rt(e,()=>Da(l))}}function*kk(e,t,r){let n,o=r.strict?new Set:void 0;while(!0){let i=yield*Pt(e);if(!i||i.depth<t)break;if(n===void 0&&i.depth>=t)n=i.depth;if(i.depth===n)yield*bt(e),yield*ji(i,e,n,r,o);else if(n!==void 0&&i.depth>n){if(r.strict)throw ig(i,n);sg(i),yield*bt(e)}else break}}function*Na(e,t,r,n,o,i){if(e.keyed){yield*Ik(e,r,n,o,i);return}if(yield{type:"startArray",length:e.length},t){yield*Ak(e,t,o,i),yield{type:"endArray"};return}if(e.fields&&e.fields.length>0){yield*Rk(e,r,n,o,i),yield{type:"endArray"};return}yield*vk(e,r,n,o,i),yield{type:"endArray"}}function*Ak(e,t,r,n){if(!at(t)){Wn(0,e.length,"inline-form values",r,n);return}let o=rt(n,()=>Vu(t,e.delimiter)),i=rt(n,()=>Ju(o));Wn(i.length,e.length,"inline-form values",r,n);for(let s of i)yield{type:"primitive",value:s}}function*Ik(e,t,r,n,o){let i=r+1,s=zu(e.fields),a=n.strict?new Set:void 0,c=0,l,u,f=o;yield{type:"startObject"};while(!0){let d=yield*Pt(t);if(!d||d.depth<=r)break;if(d.depth>i){if(n.strict)throw new ke("Unexpected indentation inside keyed tabular object",{line:d.lineNumber,source:d.raw});yield*bt(t);continue}if(tt(d.content,":")===-1){if(n.strict)throw new ke("Expected entry row inside keyed tabular object",{line:d.lineNumber,source:d.raw});yield*bt(t);continue}if(yield*bt(t),l===void 0)l=d.lineNumber;u=d.lineNumber,f=d;let{key:h,end:g}=rt(d,()=>rg(d.content,0));Ku(h,d,a),yield{type:"key",key:h};let P=at(d.content.slice(g)),x=P===""?[]:rt(d,()=>Vu(P,e.delimiter));Wn(x.length,s,"keyed entry cells",n,d);let E=rt(d,()=>Ju(x));yield*cg(e.fields,E),c++}if(Wn(c,e.length,"keyed entries",n,f),n.strict&&l!==void 0&&u!==void 0)Gu(l,u,t.scanState.blankLines,n.strict,"keyed tabular object");yield{type:"endObject"}}function*Rk(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*Pt(t);if(!u||u.depth<i)break;if(u.depth===i){if(!og(u.content,e.delimiter))break;if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*bt(t);let f=rt(u,()=>Vu(u.content,e.delimiter));Wn(f.length,zu(e.fields),"tabular row values",n,u);let d=rt(u,()=>Ju(f));yield*cg(e.fields,d),s++}else break}if(Wn(s,e.length,"tabular rows",n,l),n.strict&&a!==void 0&&c!==void 0)Gu(a,c,t.scanState.blankLines,n.strict,"tabular array");if(n.strict)Sk(yield*Pt(t),i,e)}function*vk(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*Pt(t);if(!u||u.depth<i)break;let f=u.content.startsWith("- ")||u.content==="-";if(u.depth===i&&f){if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*Ck(t,i,n);let d=t.lastLine;if(d)c=d.lineNumber,l=d;s++}else break}if(Wn(s,e.length,"list-form items",n,l),n.strict&&a!==void 0&&c!==void 0)Gu(a,c,t.scanState.blankLines,n.strict,"list-form array");if(n.strict)xk(yield*Pt(t),i,e.length)}function*Ck(e,t,r){let n=yield*bt(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(!at(o)){yield{type:"startObject"},yield{type:"endObject"};return}if(at(o)==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}let i={...n,content:o};if(ng(o)){let a=rt(i,()=>Ma(Pa(o,kr),r.strict));if(a)if(a.header.keyed||a.header.fields!==void 0){if(r.strict)throw a.header.keyed?ag(i):Tk(i)}else{yield*Na(a.header,a.inlineValues,e,t,r,i);return}}let s=rt(i,()=>Ma(Pa(o,kr),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*Na(a,s.inlineValues,e,t+1,r,i),yield*Wh(e,t+1,r,c),yield{type:"endObject"};return}if(yk(o)){let a=r.strict?new Set:void 0;yield{type:"startObject"},yield*ji(i,e,t+1,r,a),yield*Wh(e,t+1,r,a),yield{type:"endObject"};return}yield{type:"primitive",value:rt(i,()=>Da(o))}}function*Wh(e,t,r,n){while(!0){let o=yield*Pt(e);if(!o||o.depth<t)break;if(o.depth===t&&!o.content.startsWith("- "))yield*bt(e),yield*ji(o,e,t,r,n);else break}}function zh(e){let t=e.content;if(t.startsWith('"')){let r=La(t,0);if(r===-1)return!1;return t.slice(r+1).includes(":")}else return t.includes(":")}function Ma(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*cg(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 Hi(e,t,r){if(t==="__proto__"){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0});return}e[t]=r}function Pk(e){let t={stack:[],root:void 0};for(let r of e)Fk(t,r);return Nk(t)}function Fk(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");Hi(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");Hi(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");Hi(n.obj,n.currentKey,t.value),n.currentKey=void 0}else if(n.type==="array")n.arr.push(t.value)}break}}function Nk(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 Mk=new RegExp("(?:^\uFEFF?|\\n) *#"),Lk=class{constructor(e){if(Mk.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function Ki(e){return e instanceof Lk}var Dk=/[\uD800-\uDFFF]/;function Kn(e){if(e===null)return null;if(Ki(e))return e;if(typeof e==="object"&&e!==null&&"toJSON"in e&&typeof e.toJSON==="function"){let t=e.toJSON();if(t!==e)return Kn(t)}if(typeof e==="string")return Vh(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(Kn);if(e instanceof Set)return Array.from(e).map(Kn);if(e instanceof Map)return Object.fromEntries(Array.from(e,([t,r])=>[String(t),Kn(r)]));if(Uk(e)){let t={};for(let r in e)if(Object.hasOwn(e,r))Vh(r,"object key"),Hi(t,r,Kn(e[r]));return t}return null}function Vh(e,t){if(!Dk.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 qk(e){return e===null||typeof e==="string"||typeof e==="number"||typeof e==="boolean"}function Vn(e){return qk(e)||Ki(e)}function zn(e){return Array.isArray(e)}function Ar(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&!Ki(e)}function $i(e){return Object.keys(e).length===0}function Uk(e){if(e===null||typeof e!=="object")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function Bi(e){return e.length===0||e.every((t)=>Vn(t))}function Hk(e){return e.length===0||e.every((t)=>zn(t))}function lg(e){return e.length===0||e.every((t)=>Ar(t))}var jk=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function $k(e){if(!Object.values(Ca).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Bk(e){return/^[A-Z_][\w.]*$/i.test(e)}function Kk(e,t=kr){if(!e)return!1;if(/^[ \t]|[ \t]$/.test(e))return!1;if(Xh(e)||Wk(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 Wk(e){return jk.test(e)}function Wi(e,t){if(Ki(e))return e.value;if(e===null)return"null";if(typeof e==="boolean")return String(e);if(typeof e==="number")return String(e);return zk(e,t)}function zk(e,t=kr){if(Kk(e,t))return e;return`"${Gh(e)}"`}function Ho(e){if(Bk(e))return e;return`"${Gh(e)}"`}function Yu(e,t=kr){return e.map((r)=>Wi(r,t)).join(t)}function Tr(e,t){let r=t?.key,n=t?.fields,o=t?.delimiter??",",i="";if(r!=null)i+=Ho(r);if(i+=`[${e}${t?.keyed?":":""}${o!==kr?o:""}]`,n)i+=`{${ug(n,o)}}`;return i+=":",i}function ug(e,t){return e.map((r)=>Ho(r.name)+(r.children?`{${ug(r.children,t)}}`:"")).join(t)}function qa(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=Vk(n,e.map((i)=>i[n]));if(!o)return;r.push(o)}return r}function Zu(e){let t=Object.values(e);if(t.length<2)return;if(!t.every((r)=>Ar(r)&&!$i(r)))return;return qa(t)}function pg(e,t){let r=[];return fg(e,t,r),r}function Vk(e,t){if(t.every((n)=>Vn(n)))return{name:e};if(!t.every((n)=>Ar(n)&&!$i(n)))return;let r=qa(t);if(!r)return;return{name:e,children:r}}function fg(e,t,r){for(let n of t){let o=e[n.name];if(n.children)fg(o,n.children,r);else r.push(o)}}function*Jk(e,t,r){if(Vn(e)){let n=Wi(e,t.delimiter);if(n!=="")yield n;return}if(zn(e))yield*hg(void 0,e,r,t);else if(Ar(e)){let n=Zu(e);if(n){yield*dg(void 0,e,n,r,t);return}yield*Uo(e,r,t)}}function*Uo(e,t,r){for(let[n,o]of Object.entries(e))yield*Gk(n,o,t,r)}function*Gk(e,t,r,n){let o=Ho(e);if(Vn(t))yield Ft(r,`${o}: ${Wi(t,n.delimiter)}`,n.indentSize);else if(zn(t))yield*hg(e,t,r,n);else if(Ar(t)){let i=Zu(t);if(i){yield*dg(e,t,i,r,n);return}if(yield Ft(r,`${o}:`,n.indentSize),!$i(t))yield*Uo(t,r+1,n)}}function*dg(e,t,r,n,o){let i=Object.entries(t);yield Ft(n,Tr(i.length,{key:e,fields:r,delimiter:o.delimiter,keyed:!0}),o.indentSize),yield*mg(i,r,n+1,o)}function*mg(e,t,r,n){for(let[o,i]of e){let s=pg(i,t);yield Ft(r,`${Ho(o)}: ${Yu(s,n.delimiter)}`,n.indentSize)}}function*hg(e,t,r,n){if(t.length===0){yield Ft(r,e!=null?`${Ho(e)}: []`:"[]",n.indentSize);return}if(Bi(t)){yield Ft(r,Ua(t,n.delimiter,e),n.indentSize);return}if(Hk(t)){if(t.every((o)=>Bi(o))){yield*Yk(e,t,r,n);return}}if(lg(t)){let o=qa(t);if(o)yield*Zk(e,t,o,r,n);else yield*Jh(e,t,r,n);return}yield*Jh(e,t,r,n)}function*Yk(e,t,r,n){yield Ft(r,Tr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)if(Bi(o)){let i=Ua(o,n.delimiter);yield Kt(r+1,i,n.indentSize)}}function Ua(e,t,r){let n=Tr(e.length,{key:r,delimiter:t}),o=Yu(e,t);if(e.length===0)return n;return`${n} ${o}`}function*Zk(e,t,r,n,o){yield Ft(n,Tr(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 Ft(r,Yu(pg(o,t),n.delimiter),n.indentSize)}function*Jh(e,t,r,n){yield Ft(r,Tr(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)yield*Qu(o,r+1,n)}function*Qk(e,t,r){if($i(e)){yield Ft(t,"-",r.indentSize);return}let n=Object.entries(e),[o,i]=n[0],s=n.slice(1);if(zn(i)&&lg(i)){let c=qa(i);if(c){if(yield Kt(t,Tr(i.length,{key:o,fields:c,delimiter:r.delimiter}),r.indentSize),yield*gg(i,c,t+2,r),s.length>0)yield*Uo(Object.fromEntries(s),t+1,r);return}}if(Ar(i)){let c=Zu(i);if(c){let l=Object.entries(i);if(yield Kt(t,Tr(l.length,{key:o,fields:c,delimiter:r.delimiter,keyed:!0}),r.indentSize),yield*mg(l,c,t+2,r),s.length>0)yield*Uo(Object.fromEntries(s),t+1,r);return}}let a=Ho(o);if(Vn(i))yield Kt(t,`${a}: ${Wi(i,r.delimiter)}`,r.indentSize);else if(zn(i))if(i.length===0)yield Kt(t,`${a}: []`,r.indentSize);else if(Bi(i))yield Kt(t,`${a}${Ua(i,r.delimiter)}`,r.indentSize);else{yield Kt(t,`${a}${Tr(i.length,{delimiter:r.delimiter})}`,r.indentSize);for(let c of i)yield*Qu(c,t+2,r)}else if(Ar(i)){if(yield Kt(t,`${a}:`,r.indentSize),!$i(i))yield*Uo(i,t+2,r)}if(s.length>0)yield*Uo(Object.fromEntries(s),t+1,r)}function*Qu(e,t,r){if(Vn(e))yield Kt(t,Wi(e,r.delimiter),r.indentSize);else if(zn(e))if(Bi(e))yield Kt(t,Ua(e,r.delimiter),r.indentSize);else{yield Kt(t,Tr(e.length,{delimiter:r.delimiter}),r.indentSize);for(let n of e)yield*Qu(n,t+1,r)}else if(Ar(e))yield*Qk(e,t,r)}function Ft(e,t,r){return" ".repeat(r*e)+t}function Kt(e,t,r){return Ft(e,"- "+t,r)}function Xk(e,t){let r=t("",e,[]);if(r===void 0)return Wu(e,t,[]);return Xu(e,r,t,[])}function Xu(e,t,r,n){if(Ki(t)&&!Vn(e))return Wu(e,r,n);return Wu(Kn(t),r,n)}function Wu(e,t,r){if(Ar(e))return eA(e,t,r);if(zn(e))return tA(e,t,r);return e}function eA(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;Hi(n,o,Xu(i,a,t,s))}return n}function tA(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(Xu(i,a,t,s))}return n}function zi(e,t){return Array.from(rA(e,t)).join(`
5
- `)}function yg(e,t){return nA(e.split(`
6
- `),t)}function rA(e,t){let r=Kn(e),n=oA(t);return Jk(n.replacer?Xk(r,n.replacer):r,n,0)}function nA(e,t){return Pk(_k(e,iA(t)))}function oA(e){let t=e?.delimiter??kr;return $k(t),{indentSize:e?.indentSize??e?.indent??2,delimiter:t,replacer:e?.replacer}}function iA(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}class nt extends Error{code;details;constructor(e,t,r={},n){super(t,n);this.name="CoreError",this.code=e,this.details=r,cr(this.details),Object.freeze(this)}}var ep=(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 Q=(e)=>e;var Vi=(e)=>()=>e,Ji=Vi(!0),an=Vi(!1);var Ha=Vi(void 0),Gi=Ha;function m(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 Zi=(e)=>(t,r)=>t===r||e(t,r),sA=(e,t)=>e===t,aA=()=>sA;var cA=aA();var tp=p(2,(e,t)=>Zi((r,n)=>e(t(r),t(n)))),xg=tp(cA,(e)=>e.getTime());var Sg=(e)=>Zi((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 Qi,N=(e,t)=>{if(!Qi)globalThis["effect/GlobalValue"]??=new Map,Qi=globalThis["effect/GlobalValue"];if(!Qi.has(e))Qi.set(e,t());return Qi.get(e)};var Be=(e)=>typeof e==="string",_t=(e)=>typeof e==="number",Jn=(e)=>typeof e==="boolean",cn=(e)=>typeof e==="bigint",Gn=(e)=>typeof e==="symbol";var ln=ep,bg=(e)=>e===void 0;var _g=(e)=>!1;var Xi=(e)=>typeof e==="object"&&e!==null,ot=(e)=>Xi(e)||ln(e),_=p(2,(e,t)=>ot(e)&&(t in e)),es=p(2,(e,t)=>_(e,"_tag")&&e._tag===t),Yn=(e)=>e===null||e===void 0,wg=(e)=>e!==null&&e!==void 0;var $a=(e)=>e instanceof Date,rp=(e)=>typeof e==="string"||_(e,Symbol.iterator),np=(e)=>Xi(e)&&!Array.isArray(e);var Eg=(e)=>_(e,"then")&&ln(e.then);var Zn=(e)=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`;class $o{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 $o(this.self)}}var lA=335903614,uA=4150755663,pA=1481765933,fA=1284865837,dA=9007199254740992,mA=134217728;class ip{_state;constructor(e,t,r,n){if(Yn(t)&&Yn(e))t=Math.random()*4294967295>>>0,e=0;else if(Yn(t))t=e,e=0;if(Yn(n)&&Yn(r))n=this._state?this._state[3]:uA,r=this._state?this._state[2]:lA;else if(Yn(n))n=r,r=0;return this._state=new Int32Array([0,0,r>>>0,((n||0)|1)>>>0]),this._next(),Og(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*mA+t)/dA}_next(){let e=this._state[0]>>>0,t=this._state[1]>>>0;hA(this._state,e,t,pA,fA),Og(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 hA(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 Og(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 op=Symbol.for("effect/Utils/YieldWrap");class Ir{#e;constructor(e){this.#e=e}[op](){return this.#e}}function sp(e){if(typeof e==="object"&&e!==null&&op in e)return e[op]();throw Error(Zn("yieldWrapGet"))}var ct=N("effect/Utils/isStructuralRegion",()=>({enabled:!1,tester:void 0}));var Tg={effect_internal_function:(e)=>e()},gA={effect_internal_function:(e)=>{try{return e()}finally{}}},yA=Tg.effect_internal_function(()=>Error().stack)?.includes("effect_internal_function")===!0,Ke=yA?Tg.effect_internal_function:gA.effect_internal_function,eL=function*(){}.constructor;var ap=N(Symbol.for("effect/Hash/randomHashCache"),()=>new WeakMap),k=Symbol.for("effect/Hash"),S=(e)=>{if(ct.enabled===!0)return 0;switch(typeof e){case"number":return Ka(e);case"bigint":return ne(e.toString(10));case"boolean":return ne(String(e));case"symbol":return ne(String(e));case"string":return ne(e);case"undefined":return ne("undefined");case"function":case"object":if(e===null)return ne("null");else if(e instanceof Date){if(Number.isNaN(e.getTime()))return ne("Invalid Date");return S(e.toISOString())}else if(e instanceof URL)return S(e.href);else if(SA(e))return e[k]();else return ts(e);default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},ts=(e)=>{if(!ap.has(e))ap.set(e,Ka(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)));return ap.get(e)},H=(e)=>(t)=>t*53^e,Ba=(e)=>e&3221225471|e>>>1&1073741824,SA=(e)=>_(e,k),Ka=(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 Ba(t)},ne=(e)=>{let t=5381,r=e.length;while(r)t=t*33^e.charCodeAt(--r);return Ba(t)},bA=(e,t)=>{let r=12289;for(let n=0;n<t.length;n++)r^=m(ne(t[n]),H(S(e[t[n]])));return Ba(r)},Wa=(e)=>bA(e,Object.keys(e)),wt=(e)=>{let t=6151;for(let r=0;r<e.length;r++)t=m(t,H(S(e[r])));return Ba(t)},Z=function(){if(arguments.length===1){let r=arguments[0];return function(n){return Object.defineProperty(r,k,{value(){return n},enumerable:!1}),n}}let e=arguments[0],t=arguments[1];return Object.defineProperty(e,k,{value(){return t},enumerable:!1}),t};var O=Symbol.for("effect/Equal");function b(){if(arguments.length===1)return(e)=>za(e,arguments[0]);return za(arguments[0],arguments[1])}function za(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(rs(e)&&rs(t))if(S(e)===S(t)&&e[O](t))return!0;else return ct.enabled&&ct.tester?ct.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(ct.enabled){if(e===null||t===null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((n,o)=>za(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)&&za(e[i],t[i])))return ct.tester?ct.tester(e,t):!1;return!0}}return ct.tester?ct.tester(e,t):!1}}return ct.enabled&&ct.tester?ct.tester(e,t):!1}var rs=(e)=>_(e,O),ns=()=>b;var J=Symbol.for("nodejs.util.inspect.custom"),X=(e)=>{try{if(_(e,"toJSON")&&ln(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(X)}catch{return{}}return Ig(e)},cp="[Circular]";function _A(e){try{return e.toISOString()}catch{return"Invalid Date"}}function wA(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}function os(e){return Be(e)?JSON.stringify(e):String(e)}function lr(e,t){let r=t?.space??0,n=new WeakSet,o=!r?"":_t(r)?" ".repeat(r):r,i=(l)=>o.repeat(l),s=(l,u)=>{let f=l?.constructor;return f&&f!==Object.prototype.constructor&&f.name?`${f.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 cp;if(n.add(l),!o||l.length<=1)return`[${l.map((d)=>c(d,u)).join(",")}]`;let f=l.map((d)=>c(d,u+1)).join(`,
3
+ var Wu="0.15";function fr(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&&zu(n.value))fr(n.value,t)}Object.freeze(e)}function zu(e){return typeof e==="object"&&e!==null}var Na={comma:",",tab:"\t",pipe:"|"},Ir=Na.comma;function ft(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 rg(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 ng(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 Ua(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 ot(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 ve=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 it(e,t){try{return t()}catch(r){if(r instanceof ve)throw r;if(r instanceof Error)throw new ve(r.message,{line:e.lineNumber,source:e.raw,cause:r});throw r}}var ak=/^[ \t]*/;function ck(){return{lineNumber:0,blankLines:[]}}function lk(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=ak.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=pk(e.slice(a));if(s===-1&&l[0]==="#")return;let u=uk(a-c,r)+c;if(!l){t.blankLines.push({lineNumber:o,indent:a,depth:u});return}if(n){if(s!==-1)throw new ve("Tabs are not allowed in indentation in strict mode",{line:o,source:e});if(a>0&&a%r!==0)throw new ve(`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 uk(e,t){return Math.floor(e/t)}function pk(e){let t=e.length;while(t>0&&e[t-1]===" ")t--;return t===e.length?e:e.slice(0,t)}var og=Symbol("fetch-line");function fk(e){return{buffer:[],done:!1,lastLine:void 0,scanState:ck(),indentSize:e.indentSize,strict:e.strict}}function*ig(e){while(e.buffer.length===0&&!e.done){let t=yield og;if(t===void 0){e.done=!0;return}let r=lk(t,e.scanState,e.indentSize,e.strict);if(r!==void 0)e.buffer.push(r)}}function*Ft(e){return yield*ig(e),e.buffer[0]}function*Tt(e){yield*ig(e);let t=e.buffer[0];if(t!==void 0)e.buffer.shift(),e.lastLine=t;return t}function*dk(e,t){let r=e[Symbol.iterator](),n=t.next();while(!n.done)if(n.value===og){let o=r.next();n=t.next(o.done?void 0:o.value)}else yield n.value,n=t.next()}var mk=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:e[+-]?\d+)?$/i;function sg(e){return e==="true"||e==="false"||e==="null"}function hk(e){if(!e)return!1;if(!mk.test(e))return!1;let t=Number(e);return!Number.isNaN(t)&&Number.isFinite(t)}function Ma(e,t){let r=e.trimStart(),n=-1;if(r.startsWith('"')){let k=Ua(r,0);if(k===-1)return{kind:"notHeader"};if(!r.slice(k+1).startsWith("["))return{kind:"notHeader"};let I=e.length-r.length+k+1;n=e.indexOf("[",I)}else n=ot(e,"[");if(n===-1)return{kind:"notHeader"};let o=ot(e,":");if(o!==-1&&o<n)return{kind:"notHeader"};let i=ot(e,"]",n);if(i===-1)return{kind:"notHeader"};let s=i+1,a=s,c=ot(e,"{",i);if(c!==-1&&c<ot(e,":",i)){let k=e.slice(i+1,c);if(k!==""){let j=k.trim();return{kind:"invalid",reason:j===""?"Unexpected whitespace between bracket segment and field list":`Unexpected content "${j}" between bracket segment and field list`}}let I=Vu(e,c);if(I!==-1)a=I+1}if(s=ot(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 f;if(n>0){let k=e.slice(0,n);if(k!==k.trimEnd())return{kind:"invalid",reason:"Unexpected whitespace between key and bracket segment"};f=k.startsWith('"')?La(k):k}let d=ft(e.slice(s+1)),g=e.slice(n+1,i),h;try{h=yk(g,t)}catch(k){return{kind:"invalid",reason:k.message}}let{length:P,delimiter:x,keyed:E}=h,G;if(c!==-1&&c<s){let k=Vu(e,c);if(k!==-1&&k<s){let I=e.slice(c+1,k),j=bk(I,x);if(j!==void 0)return{kind:"invalid",reason:`Header delimiter mismatch: bracket declares "${Yh(x)}" but field list contains unquoted "${Yh(j)}"`};try{G=ag(I,x)}catch(v){return{kind:"invalid",reason:v.message}}}}let N=G?cg(G):void 0,q=N?`Duplicate field name "${N}" in field list`:void 0;if(E&&!G)return{kind:"invalid",reason:"Keyed header requires a field list"};if(G&&d)return{kind:"invalid",reason:q??"Unexpected content after fields-bearing header colon"};return{kind:"header",header:{key:f,length:P,delimiter:x,fields:G,keyed:E},inlineValues:d||void 0,strictError:q}}var gk=/^(?:0|[1-9]\d*)$/;function yk(e,t){let r=e,n=t;if(r.endsWith("\t"))n=Na.tab,r=r.slice(0,-1);else if(r.endsWith("|"))n=Na.pipe,r=r.slice(0,-1);let o=!1;if(r.endsWith(":"))o=!0,r=r.slice(0,-1);if(!gk.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 ag(e,t){return xk(e,t).map((r)=>{let n=ft(r);if(!n)throw SyntaxError("Empty field name in field list");let o=ot(n,"{");if(o===-1)return{name:La(n)};let i=ft(n.slice(0,o));if(!i)throw SyntaxError("Missing field name before nested field group");let s=Vu(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=ag(n.slice(o+1,s),t);return{name:La(i),children:a}})}function xk(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 Vu(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 cg(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=cg(r.children);if(n!==void 0)return n}}}function Yu(e){let t=0;for(let r of e)t+=r.children?Yu(r.children):1;return t}var Sk=[",","\t","|"];function bk(e,t){for(let r of Sk){if(r===t)continue;if(ot(e,r)!==-1)return r}}function Yh(e){if(e==="\t")return"\\t";return e}function Zu(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(ft(n)),n="",i++;continue}n+=s,i++}if(n||r.length>0)r.push(ft(n));return r}function Qu(e){return e.map((t)=>Ha(t))}function Ha(e){let t=ft(e);if(!t)return"";if(t.startsWith('"'))return La(t);if(sg(t)){if(t==="true")return!0;if(t==="false")return!1;if(t==="null")return null}if(hk(t)){let r=Number.parseFloat(t);return Object.is(r,-0)?0:r}return t}function La(e){let t=ft(e);if(t.startsWith('"')){let r=Ua(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 ng(t.slice(1,r))}return t}function _k(e,t){let r=ot(e,":",t);if(r===-1)throw SyntaxError("Missing colon after key");return{key:ft(e.slice(t,r)),end:r+1}}function wk(e,t){let r=Ua(e,t);if(r===-1)throw SyntaxError("Unterminated quoted key");let n=ng(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 lg(e,t){return e[t]==='"'?wk(e,t):_k(e,t)}function ug(e){return e.trim().startsWith("[")&&ot(e,":")!==-1}function Ek(e){return ot(e,":")!==-1}function Gn(e,t,r,n,o){if(n.strict&&e!==t)throw new ve(`Expected ${t} ${r}, but got ${e}`,{line:o.lineNumber,source:o.raw})}function Ok(e,t,r){if(e?.depth===t&&e.content.startsWith("- "))throw new ve(`Expected ${r} list-form items, but found more`,{line:e.lineNumber,source:e.raw})}function Tk(e,t,r){if(e?.depth===t&&!e.content.startsWith("- ")&&pg(e.content,r.delimiter))throw new ve(`Expected ${r.length} tabular rows, but found more`,{line:e.lineNumber,source:e.raw})}function Xu(e,t,r,n,o){if(!n)return;let i=r.find((s)=>s.lineNumber>e&&s.lineNumber<t);if(i)throw new ve(`Blank lines inside ${o} are not allowed in strict mode`,{line:i.lineNumber})}function pg(e,t){let r=ot(e,":"),n=ot(e,t);if(r===-1)return!0;if(n!==-1&&n<r)return!0;return!1}function kk(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}function Ak(e,t){let r=kk(t);return dk(e,Ik(fk(r),r))}function*Ik(e,t){let r=yield*Ft(e);if(!r){yield{type:"startObject"},yield{type:"endObject"};return}if(ft(r.content)==="[]"){yield*Tt(e),yield{type:"startArray",length:0},yield{type:"endArray"},yield*Zh(e,t.strict);return}if(ug(r.content)){let i=it(r,()=>qa(Ma(r.content,Ir),t.strict));if(i){yield*Tt(e),yield*Da(i.header,i.inlineValues,e,0,t,r),yield*Zh(e,t.strict);return}}yield*Tt(e);let n=yield*Ft(e);if(n===void 0&&!Xh(r)){yield{type:"primitive",value:it(r,()=>Ha(r.content))};return}if(!Xh(r)&&n?.depth===0)throw new ve("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*Bi(r,e,0,t,o);while(!0){let i=yield*Ft(e);if(!i)break;if(i.depth!==0){if(t.strict)throw fg(i,0);dg(i),yield*Tt(e);continue}yield*Tt(e),yield*Bi(i,e,0,t,o)}yield{type:"endObject"}}function vk(e,t,r){if(r&&e.depth>t+1)throw new ve(`Indentation depth jump: expected depth ${t+1}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function fg(e,t){return new ve(`Over-indented line: expected depth ${t}, but found ${e.depth}`,{line:e.lineNumber,source:e.raw})}function dg(e){if(e.content.startsWith("- ")||e.content==="-"||ot(e.content,":")!==-1)return;throw new ve("Unexpected bare token line outside root primitive position",{line:e.lineNumber,source:e.raw})}function mg(e){return new ve("Keyless keyed header is only valid at the document root",{line:e.lineNumber,source:e.raw})}function Rk(e){return new ve("Keyless array header is only valid at the document root or as a list item",{line:e.lineNumber,source:e.raw})}function Ck(e){return new ve("Keyless header with a field list is only valid at the document root",{line:e.lineNumber,source:e.raw})}function*Zh(e,t){if(!t)return;let r=yield*Ft(e);if(r)throw new ve("Unexpected content after the document root",{line:r.lineNumber,source:r.raw})}function Ju(e,t,r){if(!r)return;if(r.has(e))throw new ve(`Duplicate sibling key "${e}"`,{line:t.lineNumber,source:t.raw});r.add(e)}function*Bi(e,t,r,n,o){let i=e.content,s=it(e,()=>qa(Ma(i,Ir),n.strict));if(s&&s.header.key!==void 0){Ju(s.header.key,e,o),yield{type:"key",key:s.header.key},yield*Da(s.header,s.inlineValues,t,r,n,e);return}if(s&&s.header.key===void 0&&n.strict)throw s.header.keyed?mg(e):Rk(e);let{key:a,end:c}=it(e,()=>lg(i,0)),l=ft(i.slice(c));if(Ju(a,e,o),yield{type:"key",key:a},!l){let u=yield*Ft(t);if(u&&u.depth>r){vk(u,r,n.strict),yield{type:"startObject"},yield*Pk(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:it(e,()=>Ha(l))}}function*Pk(e,t,r){let n,o=r.strict?new Set:void 0;while(!0){let i=yield*Ft(e);if(!i||i.depth<t)break;if(n===void 0&&i.depth>=t)n=i.depth;if(i.depth===n)yield*Tt(e),yield*Bi(i,e,n,r,o);else if(n!==void 0&&i.depth>n){if(r.strict)throw fg(i,n);dg(i),yield*Tt(e)}else break}}function*Da(e,t,r,n,o,i){if(e.keyed){yield*Nk(e,r,n,o,i);return}if(yield{type:"startArray",length:e.length},t){yield*Fk(e,t,o,i),yield{type:"endArray"};return}if(e.fields&&e.fields.length>0){yield*Mk(e,r,n,o,i),yield{type:"endArray"};return}yield*Lk(e,r,n,o,i),yield{type:"endArray"}}function*Fk(e,t,r,n){if(!ft(t)){Gn(0,e.length,"inline-form values",r,n);return}let o=it(n,()=>Zu(t,e.delimiter)),i=it(n,()=>Qu(o));Gn(i.length,e.length,"inline-form values",r,n);for(let s of i)yield{type:"primitive",value:s}}function*Nk(e,t,r,n,o){let i=r+1,s=Yu(e.fields),a=n.strict?new Set:void 0,c=0,l,u,f=o;yield{type:"startObject"};while(!0){let d=yield*Ft(t);if(!d||d.depth<=r)break;if(d.depth>i){if(n.strict)throw new ve("Unexpected indentation inside keyed tabular object",{line:d.lineNumber,source:d.raw});yield*Tt(t);continue}if(ot(d.content,":")===-1){if(n.strict)throw new ve("Expected entry row inside keyed tabular object",{line:d.lineNumber,source:d.raw});yield*Tt(t);continue}if(yield*Tt(t),l===void 0)l=d.lineNumber;u=d.lineNumber,f=d;let{key:g,end:h}=it(d,()=>lg(d.content,0));Ju(g,d,a),yield{type:"key",key:g};let P=ft(d.content.slice(h)),x=P===""?[]:it(d,()=>Zu(P,e.delimiter));Gn(x.length,s,"keyed entry cells",n,d);let E=it(d,()=>Qu(x));yield*hg(e.fields,E),c++}if(Gn(c,e.length,"keyed entries",n,f),n.strict&&l!==void 0&&u!==void 0)Xu(l,u,t.scanState.blankLines,n.strict,"keyed tabular object");yield{type:"endObject"}}function*Mk(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*Ft(t);if(!u||u.depth<i)break;if(u.depth===i){if(!pg(u.content,e.delimiter))break;if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*Tt(t);let f=it(u,()=>Zu(u.content,e.delimiter));Gn(f.length,Yu(e.fields),"tabular row values",n,u);let d=it(u,()=>Qu(f));yield*hg(e.fields,d),s++}else break}if(Gn(s,e.length,"tabular rows",n,l),n.strict&&a!==void 0&&c!==void 0)Xu(a,c,t.scanState.blankLines,n.strict,"tabular array");if(n.strict)Tk(yield*Ft(t),i,e)}function*Lk(e,t,r,n,o){let i=r+1,s=0,a,c,l=o;while(!n.strict||s<e.length){let u=yield*Ft(t);if(!u||u.depth<i)break;let f=u.content.startsWith("- ")||u.content==="-";if(u.depth===i&&f){if(a===void 0)a=u.lineNumber;c=u.lineNumber,l=u,yield*Dk(t,i,n);let d=t.lastLine;if(d)c=d.lineNumber,l=d;s++}else break}if(Gn(s,e.length,"list-form items",n,l),n.strict&&a!==void 0&&c!==void 0)Xu(a,c,t.scanState.blankLines,n.strict,"list-form array");if(n.strict)Ok(yield*Ft(t),i,e.length)}function*Dk(e,t,r){let n=yield*Tt(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 ve('Expected list item to start with "- "',{line:n.lineNumber,source:n.raw});if(!ft(o)){yield{type:"startObject"},yield{type:"endObject"};return}if(ft(o)==="[]"){yield{type:"startArray",length:0},yield{type:"endArray"};return}let i={...n,content:o};if(ug(o)){let a=it(i,()=>qa(Ma(o,Ir),r.strict));if(a)if(a.header.keyed||a.header.fields!==void 0){if(r.strict)throw a.header.keyed?mg(i):Ck(i)}else{yield*Da(a.header,a.inlineValues,e,t,r,i);return}}let s=it(i,()=>qa(Ma(o,Ir),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*Da(a,s.inlineValues,e,t+1,r,i),yield*Qh(e,t+1,r,c),yield{type:"endObject"};return}if(Ek(o)){let a=r.strict?new Set:void 0;yield{type:"startObject"},yield*Bi(i,e,t+1,r,a),yield*Qh(e,t+1,r,a),yield{type:"endObject"};return}yield{type:"primitive",value:it(i,()=>Ha(o))}}function*Qh(e,t,r,n){while(!0){let o=yield*Ft(e);if(!o||o.depth<t)break;if(o.depth===t&&!o.content.startsWith("- "))yield*Tt(e),yield*Bi(o,e,t,r,n);else break}}function Xh(e){let t=e.content;if(t.startsWith('"')){let r=Ua(t,0);if(r===-1)return!1;return t.slice(r+1).includes(":")}else return t.includes(":")}function qa(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 $i(e,t,r){if(t==="__proto__"){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0});return}e[t]=r}function qk(e){let t={stack:[],root:void 0};for(let r of e)Uk(t,r);return Hk(t)}function Uk(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");$i(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");$i(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");$i(n.obj,n.currentKey,t.value),n.currentKey=void 0}else if(n.type==="array")n.arr.push(t.value)}break}}function Hk(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 jk=new RegExp("(?:^\uFEFF?|\\n) *#"),$k=class{constructor(e){if(jk.test(e))throw TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(e)}`);this.value=e}};function zi(e){return e instanceof $k}var Bk=/[\uD800-\uDFFF]/;function Jn(e){if(e===null)return null;if(zi(e))return e;if(typeof e==="object"&&e!==null&&"toJSON"in e&&typeof e.toJSON==="function"){let t=e.toJSON();if(t!==e)return Jn(t)}if(typeof e==="string")return eg(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(Jn);if(e instanceof Set)return Array.from(e).map(Jn);if(e instanceof Map)return Object.fromEntries(Array.from(e,([t,r])=>[String(t),Jn(r)]));if(Wk(e)){let t={};for(let r in e)if(Object.hasOwn(e,r))eg(r,"object key"),$i(t,r,Jn(e[r]));return t}return null}function eg(e,t){if(!Bk.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 Kk(e){return e===null||typeof e==="string"||typeof e==="number"||typeof e==="boolean"}function Zn(e){return Kk(e)||zi(e)}function Yn(e){return Array.isArray(e)}function vr(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)&&!zi(e)}function Ki(e){return Object.keys(e).length===0}function Wk(e){if(e===null||typeof e!=="object")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function Wi(e){return e.length===0||e.every((t)=>Zn(t))}function zk(e){return e.length===0||e.every((t)=>Yn(t))}function gg(e){return e.length===0||e.every((t)=>vr(t))}var Vk=/^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;function Jk(e){if(!Object.values(Na).includes(e))throw TypeError(`Invalid delimiter ${JSON.stringify(e)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`)}function Gk(e){return/^[A-Z_][\w.]*$/i.test(e)}function Yk(e,t=Ir){if(!e)return!1;if(/^[ \t]|[ \t]$/.test(e))return!1;if(sg(e)||Zk(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 Zk(e){return Vk.test(e)}function Vi(e,t){if(zi(e))return e.value;if(e===null)return"null";if(typeof e==="boolean")return String(e);if(typeof e==="number")return String(e);return Qk(e,t)}function Qk(e,t=Ir){if(Yk(e,t))return e;return`"${rg(e)}"`}function Bo(e){if(Gk(e))return e;return`"${rg(e)}"`}function ep(e,t=Ir){return e.map((r)=>Vi(r,t)).join(t)}function Ar(e,t){let r=t?.key,n=t?.fields,o=t?.delimiter??",",i="";if(r!=null)i+=Bo(r);if(i+=`[${e}${t?.keyed?":":""}${o!==Ir?o:""}]`,n)i+=`{${yg(n,o)}}`;return i+=":",i}function yg(e,t){return e.map((r)=>Bo(r.name)+(r.children?`{${yg(r.children,t)}}`:"")).join(t)}function ja(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=Xk(n,e.map((i)=>i[n]));if(!o)return;r.push(o)}return r}function tp(e){let t=Object.values(e);if(t.length<2)return;if(!t.every((r)=>vr(r)&&!Ki(r)))return;return ja(t)}function xg(e,t){let r=[];return Sg(e,t,r),r}function Xk(e,t){if(t.every((n)=>Zn(n)))return{name:e};if(!t.every((n)=>vr(n)&&!Ki(n)))return;let r=ja(t);if(!r)return;return{name:e,children:r}}function Sg(e,t,r){for(let n of t){let o=e[n.name];if(n.children)Sg(o,n.children,r);else r.push(o)}}function*eA(e,t,r){if(Zn(e)){let n=Vi(e,t.delimiter);if(n!=="")yield n;return}if(Yn(e))yield*wg(void 0,e,r,t);else if(vr(e)){let n=tp(e);if(n){yield*bg(void 0,e,n,r,t);return}yield*$o(e,r,t)}}function*$o(e,t,r){for(let[n,o]of Object.entries(e))yield*tA(n,o,t,r)}function*tA(e,t,r,n){let o=Bo(e);if(Zn(t))yield Nt(r,`${o}: ${Vi(t,n.delimiter)}`,n.indentSize);else if(Yn(t))yield*wg(e,t,r,n);else if(vr(t)){let i=tp(t);if(i){yield*bg(e,t,i,r,n);return}if(yield Nt(r,`${o}:`,n.indentSize),!Ki(t))yield*$o(t,r+1,n)}}function*bg(e,t,r,n,o){let i=Object.entries(t);yield Nt(n,Ar(i.length,{key:e,fields:r,delimiter:o.delimiter,keyed:!0}),o.indentSize),yield*_g(i,r,n+1,o)}function*_g(e,t,r,n){for(let[o,i]of e){let s=xg(i,t);yield Nt(r,`${Bo(o)}: ${ep(s,n.delimiter)}`,n.indentSize)}}function*wg(e,t,r,n){if(t.length===0){yield Nt(r,e!=null?`${Bo(e)}: []`:"[]",n.indentSize);return}if(Wi(t)){yield Nt(r,$a(t,n.delimiter,e),n.indentSize);return}if(zk(t)){if(t.every((o)=>Wi(o))){yield*rA(e,t,r,n);return}}if(gg(t)){let o=ja(t);if(o)yield*nA(e,t,o,r,n);else yield*tg(e,t,r,n);return}yield*tg(e,t,r,n)}function*rA(e,t,r,n){yield Nt(r,Ar(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)if(Wi(o)){let i=$a(o,n.delimiter);yield Vt(r+1,i,n.indentSize)}}function $a(e,t,r){let n=Ar(e.length,{key:r,delimiter:t}),o=ep(e,t);if(e.length===0)return n;return`${n} ${o}`}function*nA(e,t,r,n,o){yield Nt(n,Ar(t.length,{key:e,fields:r,delimiter:o.delimiter}),o.indentSize),yield*Eg(t,r,n+1,o)}function*Eg(e,t,r,n){for(let o of e)yield Nt(r,ep(xg(o,t),n.delimiter),n.indentSize)}function*tg(e,t,r,n){yield Nt(r,Ar(t.length,{key:e,delimiter:n.delimiter}),n.indentSize);for(let o of t)yield*rp(o,r+1,n)}function*oA(e,t,r){if(Ki(e)){yield Nt(t,"-",r.indentSize);return}let n=Object.entries(e),[o,i]=n[0],s=n.slice(1);if(Yn(i)&&gg(i)){let c=ja(i);if(c){if(yield Vt(t,Ar(i.length,{key:o,fields:c,delimiter:r.delimiter}),r.indentSize),yield*Eg(i,c,t+2,r),s.length>0)yield*$o(Object.fromEntries(s),t+1,r);return}}if(vr(i)){let c=tp(i);if(c){let l=Object.entries(i);if(yield Vt(t,Ar(l.length,{key:o,fields:c,delimiter:r.delimiter,keyed:!0}),r.indentSize),yield*_g(l,c,t+2,r),s.length>0)yield*$o(Object.fromEntries(s),t+1,r);return}}let a=Bo(o);if(Zn(i))yield Vt(t,`${a}: ${Vi(i,r.delimiter)}`,r.indentSize);else if(Yn(i))if(i.length===0)yield Vt(t,`${a}: []`,r.indentSize);else if(Wi(i))yield Vt(t,`${a}${$a(i,r.delimiter)}`,r.indentSize);else{yield Vt(t,`${a}${Ar(i.length,{delimiter:r.delimiter})}`,r.indentSize);for(let c of i)yield*rp(c,t+2,r)}else if(vr(i)){if(yield Vt(t,`${a}:`,r.indentSize),!Ki(i))yield*$o(i,t+2,r)}if(s.length>0)yield*$o(Object.fromEntries(s),t+1,r)}function*rp(e,t,r){if(Zn(e))yield Vt(t,Vi(e,r.delimiter),r.indentSize);else if(Yn(e))if(Wi(e))yield Vt(t,$a(e,r.delimiter),r.indentSize);else{yield Vt(t,Ar(e.length,{delimiter:r.delimiter}),r.indentSize);for(let n of e)yield*rp(n,t+1,r)}else if(vr(e))yield*oA(e,t,r)}function Nt(e,t,r){return" ".repeat(r*e)+t}function Vt(e,t,r){return Nt(e,"- "+t,r)}function iA(e,t){let r=t("",e,[]);if(r===void 0)return Gu(e,t,[]);return np(e,r,t,[])}function np(e,t,r,n){if(zi(t)&&!Zn(e))return Gu(e,r,n);return Gu(Jn(t),r,n)}function Gu(e,t,r){if(vr(e))return sA(e,t,r);if(Yn(e))return aA(e,t,r);return e}function sA(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;$i(n,o,np(i,a,t,s))}return n}function aA(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(np(i,a,t,s))}return n}function Ji(e,t){return Array.from(cA(e,t)).join(`
5
+ `)}function Og(e,t){return lA(e.split(`
6
+ `),t)}function cA(e,t){let r=Jn(e),n=uA(t);return eA(n.replacer?iA(r,n.replacer):r,n,0)}function lA(e,t){return qk(Ak(e,pA(t)))}function uA(e){let t=e?.delimiter??Ir;return Jk(t),{indentSize:e?.indentSize??e?.indent??2,delimiter:t,replacer:e?.replacer}}function pA(e){return{indentSize:e?.indentSize??e?.indent??2,strict:e?.strict??!0}}class st extends Error{code;details;constructor(e,t,r={},n){super(t,n);this.name="CoreError",this.code=e,this.details=r,fr(this.details),Object.freeze(this)}}var op=(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 Gi=(e)=>()=>e,Yi=Gi(!0),ln=Gi(!1);var Ba=Gi(void 0),Zi=Ba;function m(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 Xi=(e)=>(t,r)=>t===r||e(t,r),fA=(e,t)=>e===t,dA=()=>fA;var mA=dA();var ip=p(2,(e,t)=>Xi((r,n)=>e(t(r),t(n)))),Tg=ip(mA,(e)=>e.getTime());var kg=(e)=>Xi((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 es,M=(e,t)=>{if(!es)globalThis["effect/GlobalValue"]??=new Map,es=globalThis["effect/GlobalValue"];if(!es.has(e))es.set(e,t());return es.get(e)};var Ke=(e)=>typeof e==="string",kt=(e)=>typeof e==="number",Qn=(e)=>typeof e==="boolean",un=(e)=>typeof e==="bigint",Xn=(e)=>typeof e==="symbol";var pn=op,Ag=(e)=>e===void 0;var Ig=(e)=>!1;var ts=(e)=>typeof e==="object"&&e!==null,at=(e)=>ts(e)||pn(e),_=p(2,(e,t)=>at(e)&&(t in e)),rs=p(2,(e,t)=>_(e,"_tag")&&e._tag===t),eo=(e)=>e===null||e===void 0,vg=(e)=>e!==null&&e!==void 0;var Wa=(e)=>e instanceof Date,sp=(e)=>typeof e==="string"||_(e,Symbol.iterator),ap=(e)=>ts(e)&&!Array.isArray(e);var Rg=(e)=>_(e,"then")&&pn(e.then);var to=(e)=>`BUG: ${e} - please report an issue at https://github.com/Effect-TS/effect/issues`;class Wo{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 Wo(this.self)}}var hA=335903614,gA=4150755663,yA=1481765933,xA=1284865837,SA=9007199254740992,bA=134217728;class lp{_state;constructor(e,t,r,n){if(eo(t)&&eo(e))t=Math.random()*4294967295>>>0,e=0;else if(eo(t))t=e,e=0;if(eo(n)&&eo(r))n=this._state?this._state[3]:gA,r=this._state?this._state[2]:hA;else if(eo(n))n=r,r=0;return this._state=new Int32Array([0,0,r>>>0,((n||0)|1)>>>0]),this._next(),Cg(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*bA+t)/SA}_next(){let e=this._state[0]>>>0,t=this._state[1]>>>0;_A(this._state,e,t,yA,xA),Cg(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 _A(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 Cg(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 cp=Symbol.for("effect/Utils/YieldWrap");class Rr{#e;constructor(e){this.#e=e}[cp](){return this.#e}}function up(e){if(typeof e==="object"&&e!==null&&cp in e)return e[cp]();throw Error(to("yieldWrapGet"))}var dt=M("effect/Utils/isStructuralRegion",()=>({enabled:!1,tester:void 0}));var Pg={effect_internal_function:(e)=>e()},wA={effect_internal_function:(e)=>{try{return e()}finally{}}},EA=Pg.effect_internal_function(()=>Error().stack)?.includes("effect_internal_function")===!0,We=EA?Pg.effect_internal_function:wA.effect_internal_function,uL=function*(){}.constructor;var pp=M(Symbol.for("effect/Hash/randomHashCache"),()=>new WeakMap),T=Symbol.for("effect/Hash"),S=(e)=>{if(dt.enabled===!0)return 0;switch(typeof e){case"number":return Va(e);case"bigint":return oe(e.toString(10));case"boolean":return oe(String(e));case"symbol":return oe(String(e));case"string":return oe(e);case"undefined":return oe("undefined");case"function":case"object":if(e===null)return oe("null");else if(e instanceof Date){if(Number.isNaN(e.getTime()))return oe("Invalid Date");return S(e.toISOString())}else if(e instanceof URL)return S(e.href);else if(TA(e))return e[T]();else return ns(e);default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},ns=(e)=>{if(!pp.has(e))pp.set(e,Va(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)));return pp.get(e)},H=(e)=>(t)=>t*53^e,za=(e)=>e&3221225471|e>>>1&1073741824,TA=(e)=>_(e,T),Va=(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 za(t)},oe=(e)=>{let t=5381,r=e.length;while(r)t=t*33^e.charCodeAt(--r);return za(t)},kA=(e,t)=>{let r=12289;for(let n=0;n<t.length;n++)r^=m(oe(t[n]),H(S(e[t[n]])));return za(r)},Ja=(e)=>kA(e,Object.keys(e)),At=(e)=>{let t=6151;for(let r=0;r<e.length;r++)t=m(t,H(S(e[r])));return za(t)},Q=function(){if(arguments.length===1){let r=arguments[0];return function(n){return Object.defineProperty(r,T,{value(){return n},enumerable:!1}),n}}let e=arguments[0],t=arguments[1];return Object.defineProperty(e,T,{value(){return t},enumerable:!1}),t};var O=Symbol.for("effect/Equal");function b(){if(arguments.length===1)return(e)=>Ga(e,arguments[0]);return Ga(arguments[0],arguments[1])}function Ga(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(os(e)&&os(t))if(S(e)===S(t)&&e[O](t))return!0;else return dt.enabled&&dt.tester?dt.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(dt.enabled){if(e===null||t===null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((n,o)=>Ga(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)&&Ga(e[i],t[i])))return dt.tester?dt.tester(e,t):!1;return!0}}return dt.tester?dt.tester(e,t):!1}}return dt.enabled&&dt.tester?dt.tester(e,t):!1}var os=(e)=>_(e,O),is=()=>b;var Z=Symbol.for("nodejs.util.inspect.custom"),re=(e)=>{try{if(_(e,"toJSON")&&pn(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(re)}catch{return{}}return Mg(e)},fp="[Circular]";function AA(e){try{return e.toISOString()}catch{return"Invalid Date"}}function IA(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}function ss(e){return Ke(e)?JSON.stringify(e):String(e)}function dr(e,t){let r=t?.space??0,n=new WeakSet,o=!r?"":kt(r)?" ".repeat(r):r,i=(l)=>o.repeat(l),s=(l,u)=>{let f=l?.constructor;return f&&f!==Object.prototype.constructor&&f.name?`${f.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 fp;if(n.add(l),!o||l.length<=1)return`[${l.map((d)=>c(d,u)).join(",")}]`;let f=l.map((d)=>c(d,u+1)).join(`,
7
7
  `+i(u+1));return`[
8
8
  ${i(u+1)}${f}
9
- ${i(u)}]`}if($a(l))return _A(l);if(!t?.ignoreToString&&_(l,"toString")&&ln(l.toString)&&l.toString!==Object.prototype.toString&&l.toString!==Array.prototype.toString){let f=wA(l);if(l instanceof Error&&l.cause)return`${f} (cause: ${c(l.cause,u)})`;return f}if(Be(l))return JSON.stringify(l);if(_t(l)||l==null||Jn(l)||Gn(l))return String(l);if(cn(l))return String(l)+"n";if(l instanceof Set||l instanceof Map){if(n.has(l))return cp;return n.add(l),`${l.constructor.name}(${c(Array.from(l),u)})`}if(ot(l)){if(n.has(l))return cp;n.add(l);let f=a(l);if(!o||f.length<=1){let h=`{${f.map((g)=>`${os(g)}:${c(l[g],u)}`).join(",")}}`;return s(l,h)}let d=`{
10
- ${f.map((h)=>`${i(u+1)}${os(h)}: ${c(l[h],u+1)}`).join(`,
9
+ ${i(u)}]`}if(Wa(l))return AA(l);if(!t?.ignoreToString&&_(l,"toString")&&pn(l.toString)&&l.toString!==Object.prototype.toString&&l.toString!==Array.prototype.toString){let f=IA(l);if(l instanceof Error&&l.cause)return`${f} (cause: ${c(l.cause,u)})`;return f}if(Ke(l))return JSON.stringify(l);if(kt(l)||l==null||Qn(l)||Xn(l))return String(l);if(un(l))return String(l)+"n";if(l instanceof Set||l instanceof Map){if(n.has(l))return fp;return n.add(l),`${l.constructor.name}(${c(Array.from(l),u)})`}if(at(l)){if(n.has(l))return fp;n.add(l);let f=a(l);if(!o||f.length<=1){let g=`{${f.map((h)=>`${ss(h)}:${c(l[h],u)}`).join(",")}}`;return s(l,g)}let d=`{
10
+ ${f.map((g)=>`${i(u+1)}${ss(g)}: ${c(l[g],u+1)}`).join(`,
11
11
  `)}
12
- ${i(u)}}`;return s(l,d)}return String(l)}return c(e,0)}var oe=(e)=>JSON.stringify(e,null,2),cL={toJSON(){return X(this)},[J](){return this.toJSON()},toString(){return oe(this.toJSON())}};var Rr=(e,t=2)=>{if(typeof e==="string")return e;try{return typeof e==="object"?Va(e,t):String(e)}catch{return String(e)}},Va=(e,t)=>{let r=[],n=JSON.stringify(e,(o,i)=>typeof i==="object"&&i!==null?r.includes(i)?void 0:r.push(i)&&(Qn.fiberRefs!==void 0&&kg(i)?i[lp](Qn.fiberRefs):i):i,t);return r=void 0,n},lp=Symbol.for("effect/Inspectable/Redactable"),kg=(e)=>typeof e==="object"&&e!==null&&(lp in e),Qn=N("effect/Inspectable/redactableState",()=>({fiberRefs:void 0})),Ag=(e,t)=>{let r=Qn.fiberRefs;Qn.fiberRefs=e;try{return t()}finally{Qn.fiberRefs=r}},Ig=(e)=>{if(kg(e)&&Qn.fiberRefs!==void 0)return e[lp](Qn.fiberRefs);return e};var y=(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 eo="Async",to="Commit",lt="Failure",is="OnFailure",Bo="OnSuccess",Ko="OnSuccessAndFailure",ut="Success",Ja="Sync",Rg="Tag",ro="UpdateRuntimeFlags",Wo="While",zo="Iterator",Ga="WithRuntime",Vo="Yield",ss="RevertFlags";var EA="3.22.1",as=()=>EA;var Cg=Symbol.for("effect/Effect"),Pg=Symbol.for("effect/Stream"),Fg=Symbol.for("effect/Sink"),Ng=Symbol.for("effect/Channel"),un={_R:(e)=>e,_E:(e)=>e,_A:(e)=>e,_V:as()},OA={_A:(e)=>e,_In:(e)=>e,_L:(e)=>e,_E:(e)=>e,_R:(e)=>e},TA={_Env:(e)=>e,_InErr:(e)=>e,_InElem:(e)=>e,_InDone:(e)=>e,_OutErr:(e)=>e,_OutElem:(e)=>e,_OutDone:(e)=>e},vr={[Cg]:un,[Pg]:un,[Fg]:OA,[Ng]:TA,[O](e){return this===e},[k](){return Z(this,ts(this))},[Symbol.iterator](){return new $o(new Ir(this))},pipe(){return y(this,arguments)}},cs={[k](){return Z(this,Wa(this))},[O](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)&&b(this[n],e[n])))return!1;return!0}},pn={...vr,_op:to},pp={...pn,...cs},Mg=function(){function e(){}return e.prototype=pn,e}();var Dg=Symbol.for("effect/Option"),qg={...vr,[Dg]:{_A:(e)=>e},[J](){return this.toJSON()},toString(){return oe(this.toJSON())}},kA=Object.assign(Object.create(qg),{_tag:"Some",_op:"Some",[O](e){return fp(e)&&mp(e)&&b(this.value,e.value)},[k](){return Z(this,H(S(this._tag))(S(this.value)))},toJSON(){return{_id:"Option",_tag:this._tag,value:X(this.value)}}}),AA=S("None"),IA=Object.assign(Object.create(qg),{_tag:"None",_op:"None",[O](e){return fp(e)&&dp(e)},[k](){return AA},toJSON(){return{_id:"Option",_tag:this._tag}}}),fp=(e)=>_(e,Dg),dp=(e)=>e._tag==="None",mp=(e)=>e._tag==="Some",Ya=Object.create(IA),ls=(e)=>{let t=Object.create(kA);return t.value=e,t};var hp=Symbol.for("effect/Either"),Hg={...vr,[hp]:{_R:(e)=>e},[J](){return this.toJSON()},toString(){return oe(this.toJSON())}},RA=Object.assign(Object.create(Hg),{_tag:"Right",_op:"Right",[O](e){return Za(e)&&yp(e)&&b(this.right,e.right)},[k](){return H(S(this._tag))(S(this.right))},toJSON(){return{_id:"Either",_tag:this._tag,right:X(this.right)}}}),vA=Object.assign(Object.create(Hg),{_tag:"Left",_op:"Left",[O](e){return Za(e)&&gp(e)&&b(this.left,e.left)},[k](){return H(S(this._tag))(S(this.left))},toJSON(){return{_id:"Either",_tag:this._tag,left:X(this.left)}}}),Za=(e)=>_(e,hp),gp=(e)=>e._tag==="Left",yp=(e)=>e._tag==="Right",jg=(e)=>{let t=Object.create(vA);return t.left=e,t},$g=(e)=>{let t=Object.create(RA);return t.right=e,t};var B=$g;var U=jg;var xp=Za,he=gp,pt=yp;var Qa=p(2,(e,t)=>he(e)?U(t(e.left)):B(e.right)),Bg=p(2,(e,t)=>pt(e)?B(t(e.right)):U(e.left)),us=p(2,(e,{onLeft:t,onRight:r})=>he(e)?t(e.left):r(e.right));var Kg=us({onLeft:Q,onRight:Q});var Sp=p(2,(e,t)=>{if(pt(e))return e.right;throw t(e.left)}),Wg=Sp(()=>Error("getOrThrow called on a Left"));var bp=(e)=>e.length>0;var zg=(e)=>(t,r)=>t===r?0:e(t,r);var Vg=zg((e,t)=>e<t?-1:1);var Xa=p(2,(e,t)=>zg((r,n)=>e(t(r),t(n))));var _p=(e)=>p(2,(t,r)=>e(t,r)===1);var w=()=>Ya,I=ls;var ye=dp,ue=mp,Ee=p(2,(e,{onNone:t,onSome:r})=>ye(e)?t():r(e.value));var ce=p(2,(e,t)=>ye(e)?t():e.value),Wt=p(2,(e,t)=>ye(e)?t():e),Jg=p(2,(e,t)=>ye(e)?I(t()):e);var Pr=(e)=>e==null?w():I(e);var ft=ce(Ha),Gg=(e)=>(...t)=>{try{return I(e(...t))}catch{return w()}};var zt=p(2,(e,t)=>ye(e)?w():I(t(e.value)));var Vt=p(2,(e,t)=>ye(e)?w():t(e.value));var Yg=p(2,(e,t)=>ye(e)?w():Pr(t(e.value)));var NA=(e)=>p(2,(t,r)=>ye(t)?!1:e(t.value,r)),MA=ns(),Zg=NA(MA),Qg=p(2,(e,t)=>ye(e)?!1:t(e.value));var Xg=(...e)=>e;var no=(e)=>Array(e),Ep=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 pe=(e)=>Array.isArray(e)?e:Array.from(e),Op=(e)=>Array.isArray(e)?e:[e];var ey=p(2,(e,{onEmpty:t,onNonEmpty:r})=>se(e)?r(Ie(e),Jt(e)):t());var Jo=p(2,(e,t)=>[t,...e]);var ty=p(2,(e,t)=>[...e,t]),Tp=p(2,(e,t)=>pe(e).concat(pe(t)));var kp=Array.isArray,DA=(e)=>e.length===0,ry=DA,fn=bp,se=bp;var ny=(e,t)=>e<0||e>=t.length,qA=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),UA=p(2,(e,t)=>{let r=Math.floor(t);return ny(r,e)?w():I(e[r])}),Ap=p(2,(e,t)=>{let r=Math.floor(t);if(ny(r,e))throw Error(`Index ${r} out of bounds`);return e[r]});var Fr=UA(0),Ie=Ap(0),oy=(e)=>se(e)?I(Ip(e)):w(),Ip=(e)=>e[e.length-1];var Jt=(e)=>e.slice(1);var HA=(e,t)=>{let r=0;for(let n of e){if(!t(n,r))break;r++}return r},iy=p(2,(e,t)=>$A(e,HA(e,t))),sy=p(2,(e,t)=>{let r=pe(e);return r.slice(qA(t,r),r.length)});var Rp=(e)=>Array.from(e).reverse(),Nr=p(2,(e,t)=>{let r=Array.from(e);return r.sort(t),r});var vp=p(2,(e,t)=>ay(e,t,Xg)),ay=p(3,(e,t,r)=>{let n=pe(e),o=pe(t);if(se(n)&&se(o)){let i=[r(Ie(n),Ie(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 jA=ns();var $A=p(2,(e,t)=>{let r=Array.from(e),n=Math.floor(t);if(se(r)){if(n>=1)return BA(r,n);return[[],r]}return[r,[]]}),BA=p(2,(e,t)=>{let r=Math.max(1,Math.floor(t));return r>=e.length?[Go(e),[]]:[Jo(e.slice(1,r),Ie(e)),e.slice(r)]});var Go=(e)=>e.slice();var KA=p(3,(e,t,r)=>{let n=pe(e),o=pe(t);if(se(n)){if(se(o))return cy(r)(Tp(n,o));return n}return o}),dn=p(2,(e,t)=>KA(e,t,jA));var Mr=()=>[],Ve=(e)=>[e],Gt=p(2,(e,t)=>e.map(t)),ps=p(2,(e,t)=>{if(ry(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}),ec=ps(Q),tc=p(2,(e,t)=>{let r=pe(e),n=[];for(let o=0;o<r.length;o++){let i=t(r[o],o);if(ue(i))n.push(i.value)}return n});var Yo=p(3,(e,t,r)=>pe(e).reduce((n,o,i)=>r(n,o,i),t));var Cp=(e,t)=>{let r=[],n=e,o;while(ue(o=t(n))){let[i,s]=o.value;r.push(i),n=s}return r};var mn=Sg;var cy=p(2,(e,t)=>{let r=pe(e);if(se(r)){let n=[Ie(r)],o=Jt(r);for(let i of o)if(n.every((s)=>!t(i,s)))n.push(i);return n}return[]}),Pp=(e)=>cy(e,ns());var Lr=p(2,(e,t)=>pe(e).join(t));var uy=Symbol.for("effect/Chunk");function JA(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 py=[],GA=(e)=>Zi((t,r)=>t.length===r.length&&Dr(t).every((n,o)=>e(n,Zo(r,o)))),YA=GA(b),ZA={[uy]:{_A:(e)=>e},toString(){return oe(this.toJSON())},toJSON(){return{_id:"Chunk",values:Dr(this).map(X)}},[J](){return this.toJSON()},[O](e){return fy(e)&&YA(this,e)},[k](){return Z(this,wt(Dr(this)))},[Symbol.iterator](){switch(this.backing._tag){case"IArray":return this.backing.array[Symbol.iterator]();case"IEmpty":return py[Symbol.iterator]();default:return Dr(this)[Symbol.iterator]()}},pipe(){return y(this,arguments)}},Pe=(e)=>{let t=Object.create(ZA);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=ur,t.right=ur;break}case"ISingleton":{t.length=1,t.depth=0,t.left=ur,t.right=ur;break}case"ISlice":{t.length=e.length,t.depth=e.chunk.depth+1,t.left=ur,t.right=ur;break}}return t},fy=(e)=>_(e,uy),ur=Pe({_tag:"IEmpty"}),Nt=()=>ur,fs=(...e)=>eI(e),Re=(e)=>Pe({_tag:"ISingleton",a:e}),rc=(e)=>fy(e)?e:ds(pe(e)),Fp=(e,t,r)=>{switch(e.backing._tag){case"IArray":{JA(e.backing.array,0,t,r,e.length);break}case"IConcat":{Fp(e.left,t,r),Fp(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]=Zo(e,n),n+=1,o+=1;break}}};var QA=(e)=>{switch(e.backing._tag){case"IEmpty":return py;case"IArray":return e.backing.array;default:{let t=Array(e.length);return Fp(e,t,0),e.backing={_tag:"IArray",array:t},e.left=ur,e.right=ur,e.depth=0,t}}},Dr=QA,XA=(e)=>{switch(e.backing._tag){case"IEmpty":case"ISingleton":return e;case"IArray":return Pe({_tag:"IArray",array:Rp(e.backing.array)});case"IConcat":return Pe({_tag:"IConcat",left:hn(e.backing.right),right:hn(e.backing.left)});case"ISlice":return ds(Rp(Dr(e)))}},hn=XA;var ds=(e)=>e.length===0?Nt():e.length===1?Re(e[0]):Pe({_tag:"IArray",array:e}),eI=(e)=>ds(e),Zo=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?Zo(e.left,t):Zo(e.right,t-e.left.length);case"ISlice":return Zo(e.backing.chunk,t+e.backing.offset)}}),dy=p(2,(e,t)=>Et(e,Re(t))),Je=p(2,(e,t)=>Et(Re(t),e));var Np=p(2,(e,t)=>{if(t<=0)return e;else if(t>=e.length)return ur;else switch(e.backing._tag){case"ISlice":return Pe({_tag:"ISlice",chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case"IConcat":{if(t>e.left.length)return Np(e.right,t-e.left.length);return Pe({_tag:"IConcat",left:Np(e.left,t),right:e.right})}default:return Pe({_tag:"ISlice",chunk:e,offset:t,length:e.length-t})}});var Et=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 Pe({_tag:"IConcat",left:e,right:t});else if(r<-1)if(e.left.depth>=e.right.depth){let n=Et(e.right,t);return Pe({_tag:"IConcat",left:e.left,right:n})}else{let n=Et(e.right.right,t);if(n.depth===e.depth-3){let o=Pe({_tag:"IConcat",left:e.right.left,right:n});return Pe({_tag:"IConcat",left:e.left,right:o})}else{let o=Pe({_tag:"IConcat",left:e.left,right:e.right.left});return Pe({_tag:"IConcat",left:o,right:n})}}else if(t.right.depth>=t.left.depth){let n=Et(e,t.left);return Pe({_tag:"IConcat",left:n,right:t.right})}else{let n=Et(e,t.left.left);if(n.depth===t.depth-3){let o=Pe({_tag:"IConcat",left:n,right:t.left.right});return Pe({_tag:"IConcat",left:o,right:t.right})}else{let o=Pe({_tag:"IConcat",left:t.left.right,right:t.right});return Pe({_tag:"IConcat",left:n,right:o})}}});var my=(e)=>e.length===0,Yt=(e)=>e.length>0;var Mp=(e)=>Zo(e,0),Zt=Mp;var Qt=(e)=>Np(e,1);var gn=5,Lp=Math.pow(2,5),hy=Lp-1,gy=Lp/2,yy=Lp/4;function tI(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 yn(e,t){return t>>>e&hy}function xn(e){return 1<<e}function nc(e,t){return tI(e&t-1)}var xy=(e,t)=>({value:e,previous:t});function oo(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 Dp(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 Sy(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 Ur{_tag="EmptyNode";modify(e,t,r,n,o,i){let s=r(w());if(ye(s))return new Ur;return++i.value,new io(e,n,o,s)}}function Mt(e){return es(e,"EmptyNode")}function nI(e){return Mt(e)||e._tag==="LeafNode"||e._tag==="CollisionNode"}function oc(e,t){return Mt(e)?!1:t===e.edit}class io{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(b(o,this.key)){let a=r(this.value);if(a===this.value)return this;else if(ye(a))return--i.value,new Ur;if(oc(this,e))return this.value=a,this;return new io(e,n,o,a)}let s=r(w());if(ye(s))return this;return++i.value,by(e,t,this.hash,this,n,new io(e,n,o,s))}}class qp{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=oc(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 qp(e,this.hash,c):c[0]}let s=r(w());if(ye(s))return this;return++i.value,by(e,t,this.hash,this,n,new io(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&&b(i,u.key)){let f=u.value,d=o(f);if(d===f)return n;if(ye(d))return--s.value,Dp(e,l,n);return oo(e,l,new io(t,r,i,d),n)}}let c=o(w());if(ye(c))return n;return++s.value,oo(e,a,new io(t,r,i,c),n)}}class Qo{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=yn(t,n),l=xn(c),u=nc(s,l),f=s&l,d=oc(this,e);if(!f){let E=new Ur().modify(e,t+gn,r,n,o,i);if(!E)return this;return a.length>=gy?iI(e,c,E,s,a):new Qo(e,s|l,Sy(d,u,E,a))}let h=a[u],g=h.modify(e,t+gn,r,n,o,i);if(h===g)return this;let P=s,x;if(Mt(g)){if(P&=~l,!P)return new Ur;if(a.length<=2&&nI(a[u^1]))return a[u^1];x=Dp(d,u,a)}else x=oo(d,u,g,a);if(d)return this.mask=P,this.children=x,this;return new Qo(e,P,x)}}class Up{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=yn(t,n),l=a[c],u=(l||new Ur).modify(e,t+gn,r,n,o,i);if(l===u)return this;let f=oc(this,e),d;if(Mt(l)&&!Mt(u))++s,d=oo(f,c,u,a);else if(!Mt(l)&&Mt(u)){if(--s,s<=yy)return oI(e,s,c,a);d=oo(f,c,new Ur,a)}else d=oo(f,c,u,a);if(f)return this.size=s,this.children=d,this;return new Up(e,s,d)}}function oI(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&&!Mt(l))o[i++]=l,s|=1<<a}return new Qo(e,s,o)}function iI(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 Up(e,a+1,i)}function sI(e,t,r,n,o,i){if(r===o)return new qp(e,r,[i,n]);let s=yn(t,r),a=yn(t,o);if(s===a)return(c)=>new Qo(e,xn(s)|xn(a),[c]);else{let c=s<a?[n,i]:[i,n];return new Qo(e,xn(s)|xn(a),c)}}function by(e,t,r,n,o,i){let s=void 0,a=t;while(!0){let c=sI(e,a,r,n,o,i);if(typeof c==="function")s=xy(c,s),a=a+gn;else{let l=c;while(s!=null)l=s.value(l),s=s.previous;return l}}}var _y="effect/HashMap",ic=Symbol.for(_y),cI={[ic]:ic,[Symbol.iterator](){return new ac(this,(e,t)=>[e,t])},[k](){let e=S(_y);for(let t of this)e^=m(S(t[0]),H(S(t[1])));return Z(this,e)},[O](e){if(Ty(e)){if(e._size!==this._size)return!1;for(let t of this){let r=m(e,cc(t[0],S(t[0])));if(ye(r))return!1;else if(!b(t[1],r.value))return!1}return!0}return!1},toString(){return oe(this.toJSON())},toJSON(){return{_id:"HashMap",values:Array.from(this).map(X)}},[J](){return this.toJSON()},pipe(){return y(this,arguments)}},Hp=(e,t,r,n)=>{let o=Object.create(cI);return o._editable=e,o._edit=t,o._root=r,o._size=n,o};class ac{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=wy(this.map._root,this.f,void 0)}next(){if(ye(this.v))return{done:!0,value:void 0};let e=this.v.value;return this.v=sc(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new ac(this.map,this.f)}}var sc=(e)=>e?Ey(e[0],e[1],e[2],e[3],e[4]):w(),wy=(e,t,r=void 0)=>{switch(e._tag){case"LeafNode":{if(ue(e.value))return I({value:t(e.key,e.value.value),cont:r});return sc(r)}case"CollisionNode":case"ArrayNode":case"IndexedNode":{let n=e.children;return Ey(n.length,n,0,t,r)}default:return sc(r)}},Ey=(e,t,r,n,o)=>{while(r<e){let i=t[r++];if(i&&!Mt(i))return wy(i,n,[e,t,r,n,o])}return sc(o)},lI=Hp(!1,0,new Ur,0),Xo=()=>lI;var Oy=(e)=>{let t=uc(Xo());for(let r of e)so(t,r[0],r[1]);return Iy(t)},Ty=(e)=>_(e,ic),ky=(e)=>e&&Mt(e._root),Ay=p(2,(e,t)=>cc(e,t,S(t))),cc=p(3,(e,t,r)=>{let n=e._root,o=0;while(!0)switch(n._tag){case"LeafNode":return b(t,n.key)?n.value:w();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&&b(t,c.key))return c.value}}return w()}case"IndexedNode":{let i=yn(o,r),s=xn(i);if(n.mask&s){n=n.children[nc(n.mask,s)],o+=gn;break}return w()}case"ArrayNode":{if(n=n.children[yn(o,r)],n){o+=gn;break}return w()}default:return w()}});var jp=p(2,(e,t)=>ue(cc(e,t,S(t))));var so=p(3,(e,t,r)=>pc(e,t,()=>I(r))),uI=p(3,(e,t,r)=>{if(e._editable)return e._root=t,e._size=r,e;return t===e._root?e:Hp(e._editable,e._edit,t,r)}),lc=(e)=>new ac(e,(t)=>t);var ms=(e)=>e._size;var uc=(e)=>Hp(!0,e._edit+1,e._root,e._size),Iy=(e)=>(e._editable=!1,e);var pc=p(3,(e,t,r)=>Ry(e,t,S(t),r)),Ry=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,uI(i,o.value))});var fc=p(2,(e,t)=>pc(e,t,w));var vy=p(2,(e,t)=>ei(e,Xo(),(r,n,o)=>so(r,o,t(n,o))));var $p=p(2,(e,t)=>ei(e,void 0,(r,n,o)=>t(n,o))),ei=p(3,(e,t,r)=>{let n=e._root;if(n._tag==="LeafNode")return ue(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&&!Mt(c))if(c._tag==="LeafNode"){if(ue(c.value))t=r(t,c.value.value,c.key)}else o.push(c.children)}return t});var Py="effect/HashSet",dc=Symbol.for(Py),pI={[dc]:dc,[Symbol.iterator](){return lc(this._keyMap)},[k](){return Z(this,H(S(this._keyMap))(S(Py)))},[O](e){if(Fy(e))return ms(this._keyMap)===ms(e._keyMap)&&b(this._keyMap,e._keyMap);return!1},toString(){return oe(this.toJSON())},toJSON(){return{_id:"HashSet",values:Array.from(this).map(X)}},[J](){return this.toJSON()},pipe(){return y(this,arguments)}},mc=(e)=>{let t=Object.create(pI);return t._keyMap=e,t},Fy=(e)=>_(e,dc),fI=mc(Xo()),hs=()=>fI,Ny=(e)=>{let t=hc(hs());for(let r of e)ti(t,r);return gc(t)},My=(...e)=>{let t=hc(hs());for(let r of e)ti(t,r);return gc(t)},Ly=p(2,(e,t)=>jp(e._keyMap,t));var Dy=(e)=>ms(e._keyMap),hc=(e)=>mc(uc(e._keyMap)),gc=(e)=>(e._keyMap._editable=!1,e),Bp=p(2,(e,t)=>{let r=hc(e);return t(r),gc(r)}),ti=p(2,(e,t)=>e._keyMap._editable?(so(t,!0)(e._keyMap),e):mc(so(t,!0)(e._keyMap))),Kp=p(2,(e,t)=>e._keyMap._editable?(fc(t)(e._keyMap),e):mc(fc(t)(e._keyMap))),qy=p(2,(e,t)=>Bp(e,(r)=>{for(let n of t)Kp(r,n)}));var Uy=p(2,(e,t)=>Bp(hs(),(r)=>{Hy(e,(n)=>ti(r,n));for(let n of t)ti(r,n)}));var Hy=p(2,(e,t)=>$p(e._keyMap,(r,n)=>t(n))),jy=p(3,(e,t,r)=>ei(e._keyMap,t,(n,o,i)=>r(n,i)));var pr=hs,$y=Ny,ao=My,By=Ly;var gs=Dy;var co=ti,Wp=Kp,zp=qy;var Hr=Uy;var lo=jy;var ni="Die",Sn="Empty",bn="Fail",uo="Interrupt",po="Parallel",fo="Sequential";var zy="effect/Cause",Gp=Symbol.for(zy),hI={_E:(e)=>e},oi={[Gp]:hI,[k](){return m(S(zy),H(S(yI(this))),Z(this))},[O](e){return Vy(e)&&gI(this,e)},pipe(){return y(this,arguments)},toJSON(){switch(this._tag){case"Empty":return{_id:"Cause",_tag:this._tag};case"Die":return{_id:"Cause",_tag:this._tag,defect:X(this.defect)};case"Interrupt":return{_id:"Cause",_tag:this._tag,fiberId:this.fiberId.toJSON()};case"Fail":return{_id:"Cause",_tag:this._tag,failure:X(this.error)};case"Sequential":case"Parallel":return{_id:"Cause",_tag:this._tag,left:X(this.left),right:X(this.right)}}},toString(){return er(this)},[J](){return this.toJSON()}},jr=(()=>{let e=Object.create(oi);return e._tag=Sn,e})(),ii=(e)=>{let t=Object.create(oi);return t._tag=bn,t.error=e,t},Ot=(e)=>{let t=Object.create(oi);return t._tag=ni,t.defect=e,t},Xt=(e)=>{let t=Object.create(oi);return t._tag=uo,t.fiberId=e,t},go=(e,t)=>{let r=Object.create(oi);return r._tag=po,r.left=e,r.right=t,r},Ge=(e,t)=>{let r=Object.create(oi);return r._tag=fo,r.left=e,r.right=t,r},Vy=(e)=>_(e,Gp),Yp=(e)=>e._tag===Sn,Jy=(e)=>e._tag===bn;var yc=(e)=>{if(e._tag===Sn)return!0;return mo(e,!0,(t,r)=>{switch(r._tag){case Sn:return I(t);case ni:case bn:case uo:return I(!1);default:return w()}})};var xc=(e)=>ue(Gy(e)),si=(e)=>_c(void 0,SI)(e),Zp=(e)=>hn(mo(e,Nt(),(t,r)=>r._tag===bn?I(m(t,Je(r.error))):w())),Qp=(e)=>hn(mo(e,Nt(),(t,r)=>r._tag===ni?I(m(t,Je(r.defect))):w())),Xp=(e)=>mo(e,pr(),(t,r)=>r._tag===uo?I(m(t,co(r.fiberId))):w()),ef=(e)=>tf(e,(t)=>t._tag===bn?I(t.error):w()),Sc=(e)=>{let t=ef(e);switch(t._tag){case"None":return B(e);case"Some":return U(t.value)}};var Gy=(e)=>tf(e,(t)=>t._tag===uo?I(t.fiberId):w());var bc=(e)=>rf(e,{onEmpty:jr,onFail:()=>jr,onDie:Ot,onInterrupt:Xt,onSequential:Ge,onParallel:go}),Yy=(e)=>rf(e,{onEmpty:jr,onFail:Ot,onDie:Ot,onInterrupt:Xt,onSequential:Ge,onParallel:go});var gI=(e,t)=>{let r=Re(e),n=Re(t);while(Yt(r)&&Yt(n)){let[o,i]=m(Zt(r),mo([pr(),Nt()],([c,l],u)=>{let[f,d]=Vp(u);return I([m(c,Hr(f)),m(l,Et(d))])})),[s,a]=m(Zt(n),mo([pr(),Nt()],([c,l],u)=>{let[f,d]=Vp(u);return I([m(c,Hr(f)),m(l,Et(d))])}));if(!b(o,s))return!1;r=i,n=a}return!0},yI=(e)=>xI(Re(e),Nt()),xI=(e,t)=>{while(!0){let[r,n]=m(e,Yo([pr(),Nt()],([i,s],a)=>{let[c,l]=Vp(a);return[m(i,Hr(c)),m(s,Et(l))]})),o=gs(r)>0?m(t,Je(r)):t;if(my(n))return hn(o);e=n,t=o}throw Error(Zn("Cause.flattenCauseLoop"))},tf=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 fo:case po:{r.push(n.right),r.push(n.left);break}}break}case"Some":return o}}return w()});var Vp=(e)=>{let t=e,r=[],n=pr(),o=Nt();while(t!==void 0)switch(t._tag){case Sn:{if(r.length===0)return[n,o];t=r.pop();break}case bn:{if(n=co(n,fs(t._tag,t.error)),r.length===0)return[n,o];t=r.pop();break}case ni:{if(n=co(n,fs(t._tag,t.defect)),r.length===0)return[n,o];t=r.pop();break}case uo:{if(n=co(n,fs(t._tag,t.fiberId)),r.length===0)return[n,o];t=r.pop();break}case fo:{switch(t.left._tag){case Sn:{t=t.right;break}case fo:{t=Ge(t.left.left,Ge(t.left.right,t.right));break}case po:{t=go(Ge(t.left.left,t.right),Ge(t.left.right,t.right));break}default:{o=Je(o,t.right),t=t.left;break}}break}case po:{r.push(t.right),t=t.left;break}}throw Error(Zn("Cause.evaluateCauseLoop"))};var SI={emptyCase:Ji,failCase:an,dieCase:an,interruptCase:Ji,sequentialCase:(e,t,r)=>t&&r,parallelCase:(e,t,r)=>t&&r};var Ky="SequentialCase",Wy="ParallelCase",rf=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)})),mo=p(3,(e,t,r)=>{let n=t,o=e,i=[];while(o!==void 0){let s=r(n,o);switch(n=ue(s)?s.value:n,o._tag){case fo:{i.push(o.right),o=o.left;break}case po:{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 Sn:{o.push(B(r.emptyCase(t)));break}case bn:{o.push(B(r.failCase(t,s.error)));break}case ni:{o.push(B(r.dieCase(t,s.defect)));break}case uo:{o.push(B(r.interruptCase(t,s.fiberId)));break}case fo:{n.push(s.right),n.push(s.left),o.push(U({_tag:Ky}));break}case po:{n.push(s.right),n.push(s.left),o.push(U({_tag:Wy}));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._tag){case"Left":{switch(s.left._tag){case Ky:{let a=i.pop(),c=i.pop(),l=r.sequentialCase(t,a,c);i.push(l);break}case Wy:{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()}),er=(e,t)=>{if(si(e))return"All fibers interrupted without errors.";return ys(e).map(function(r){if(t?.renderErrorCause!==!0||r.cause===void 0)return r.stack;return`${r.stack} {
13
- ${Zy(r.cause," ")}
12
+ ${i(u)}}`;return s(l,d)}return String(l)}return c(e,0)}var ie=(e)=>JSON.stringify(e,null,2),xL={toJSON(){return re(this)},[Z](){return this.toJSON()},toString(){return ie(this.toJSON())}};var Cr=(e,t=2)=>{if(typeof e==="string")return e;try{return typeof e==="object"?Ya(e,t):String(e)}catch{return String(e)}},Ya=(e,t)=>{let r=[],n=JSON.stringify(e,(o,i)=>typeof i==="object"&&i!==null?r.includes(i)?void 0:r.push(i)&&(ro.fiberRefs!==void 0&&Fg(i)?i[dp](ro.fiberRefs):i):i,t);return r=void 0,n},dp=Symbol.for("effect/Inspectable/Redactable"),Fg=(e)=>typeof e==="object"&&e!==null&&(dp in e),ro=M("effect/Inspectable/redactableState",()=>({fiberRefs:void 0})),Ng=(e,t)=>{let r=ro.fiberRefs;ro.fiberRefs=e;try{return t()}finally{ro.fiberRefs=r}},Mg=(e)=>{if(Fg(e)&&ro.fiberRefs!==void 0)return e[dp](ro.fiberRefs);return e};var y=(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 oo="Async",io="Commit",mt="Failure",as="OnFailure",zo="OnSuccess",Vo="OnSuccessAndFailure",ht="Success",Za="Sync",Lg="Tag",so="UpdateRuntimeFlags",Jo="While",Go="Iterator",Qa="WithRuntime",Yo="Yield",cs="RevertFlags";var vA="3.22.1",ls=()=>vA;var qg=Symbol.for("effect/Effect"),Ug=Symbol.for("effect/Stream"),Hg=Symbol.for("effect/Sink"),jg=Symbol.for("effect/Channel"),fn={_R:(e)=>e,_E:(e)=>e,_A:(e)=>e,_V:ls()},RA={_A:(e)=>e,_In:(e)=>e,_L:(e)=>e,_E:(e)=>e,_R:(e)=>e},CA={_Env:(e)=>e,_InErr:(e)=>e,_InElem:(e)=>e,_InDone:(e)=>e,_OutErr:(e)=>e,_OutElem:(e)=>e,_OutDone:(e)=>e},Pr={[qg]:fn,[Ug]:fn,[Hg]:RA,[jg]:CA,[O](e){return this===e},[T](){return Q(this,ns(this))},[Symbol.iterator](){return new Wo(new Rr(this))},pipe(){return y(this,arguments)}},us={[T](){return Q(this,Ja(this))},[O](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)&&b(this[n],e[n])))return!1;return!0}},dn={...Pr,_op:io},hp={...dn,...us},$g=function(){function e(){}return e.prototype=dn,e}();var Kg=Symbol.for("effect/Option"),Wg={...Pr,[Kg]:{_A:(e)=>e},[Z](){return this.toJSON()},toString(){return ie(this.toJSON())}},PA=Object.assign(Object.create(Wg),{_tag:"Some",_op:"Some",[O](e){return gp(e)&&xp(e)&&b(this.value,e.value)},[T](){return Q(this,H(S(this._tag))(S(this.value)))},toJSON(){return{_id:"Option",_tag:this._tag,value:re(this.value)}}}),FA=S("None"),NA=Object.assign(Object.create(Wg),{_tag:"None",_op:"None",[O](e){return gp(e)&&yp(e)},[T](){return FA},toJSON(){return{_id:"Option",_tag:this._tag}}}),gp=(e)=>_(e,Kg),yp=(e)=>e._tag==="None",xp=(e)=>e._tag==="Some",Xa=Object.create(NA),ps=(e)=>{let t=Object.create(PA);return t.value=e,t};var Sp=Symbol.for("effect/Either"),Vg={...Pr,[Sp]:{_R:(e)=>e},[Z](){return this.toJSON()},toString(){return ie(this.toJSON())}},MA=Object.assign(Object.create(Vg),{_tag:"Right",_op:"Right",[O](e){return ec(e)&&_p(e)&&b(this.right,e.right)},[T](){return H(S(this._tag))(S(this.right))},toJSON(){return{_id:"Either",_tag:this._tag,right:re(this.right)}}}),LA=Object.assign(Object.create(Vg),{_tag:"Left",_op:"Left",[O](e){return ec(e)&&bp(e)&&b(this.left,e.left)},[T](){return H(S(this._tag))(S(this.left))},toJSON(){return{_id:"Either",_tag:this._tag,left:re(this.left)}}}),ec=(e)=>_(e,Sp),bp=(e)=>e._tag==="Left",_p=(e)=>e._tag==="Right",Jg=(e)=>{let t=Object.create(LA);return t.left=e,t},Gg=(e)=>{let t=Object.create(MA);return t.right=e,t};var K=Gg;var U=Jg;var wp=ec,ye=bp,gt=_p;var tc=p(2,(e,t)=>ye(e)?U(t(e.left)):K(e.right)),Yg=p(2,(e,t)=>gt(e)?K(t(e.right)):U(e.left)),fs=p(2,(e,{onLeft:t,onRight:r})=>ye(e)?t(e.left):r(e.right));var Zg=fs({onLeft:te,onRight:te});var Ep=p(2,(e,t)=>{if(gt(e))return e.right;throw t(e.left)}),Qg=Ep(()=>Error("getOrThrow called on a Left"));var Op=(e)=>e.length>0;var Xg=(e)=>(t,r)=>t===r?0:e(t,r);var ey=Xg((e,t)=>e<t?-1:1);var rc=p(2,(e,t)=>Xg((r,n)=>e(t(r),t(n))));var Tp=(e)=>p(2,(t,r)=>e(t,r)===1);var w=()=>Xa,R=ps;var Se=yp,pe=xp,Oe=p(2,(e,{onNone:t,onSome:r})=>Se(e)?t():r(e.value));var ue=p(2,(e,t)=>Se(e)?t():e.value),Jt=p(2,(e,t)=>Se(e)?t():e),ty=p(2,(e,t)=>Se(e)?R(t()):e);var Nr=(e)=>e==null?w():R(e);var yt=ue(Ba),ry=(e)=>(...t)=>{try{return R(e(...t))}catch{return w()}};var Gt=p(2,(e,t)=>Se(e)?w():R(t(e.value)));var Yt=p(2,(e,t)=>Se(e)?w():t(e.value));var ny=p(2,(e,t)=>Se(e)?w():Nr(t(e.value)));var HA=(e)=>p(2,(t,r)=>Se(t)?!1:e(t.value,r)),jA=is(),oy=HA(jA),iy=p(2,(e,t)=>Se(e)?!1:t(e.value));var sy=(...e)=>e;var ao=(e)=>Array(e),Ap=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),Ip=(e)=>Array.isArray(e)?e:[e];var ay=p(2,(e,{onEmpty:t,onNonEmpty:r})=>ae(e)?r(Ce(e),Zt(e)):t());var Zo=p(2,(e,t)=>[t,...e]);var cy=p(2,(e,t)=>[...e,t]),vp=p(2,(e,t)=>fe(e).concat(fe(t)));var Rp=Array.isArray,BA=(e)=>e.length===0,ly=BA,mn=Op,ae=Op;var uy=(e,t)=>e<0||e>=t.length,KA=(e,t)=>Math.floor(Math.min(Math.max(0,e),t.length)),WA=p(2,(e,t)=>{let r=Math.floor(t);return uy(r,e)?w():R(e[r])}),Cp=p(2,(e,t)=>{let r=Math.floor(t);if(uy(r,e))throw Error(`Index ${r} out of bounds`);return e[r]});var Mr=WA(0),Ce=Cp(0),py=(e)=>ae(e)?R(Pp(e)):w(),Pp=(e)=>e[e.length-1];var Zt=(e)=>e.slice(1);var zA=(e,t)=>{let r=0;for(let n of e){if(!t(n,r))break;r++}return r},fy=p(2,(e,t)=>JA(e,zA(e,t))),dy=p(2,(e,t)=>{let r=fe(e);return r.slice(KA(t,r),r.length)});var Fp=(e)=>Array.from(e).reverse(),Lr=p(2,(e,t)=>{let r=Array.from(e);return r.sort(t),r});var Np=p(2,(e,t)=>my(e,t,sy)),my=p(3,(e,t,r)=>{let n=fe(e),o=fe(t);if(ae(n)&&ae(o)){let i=[r(Ce(n),Ce(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 VA=is();var JA=p(2,(e,t)=>{let r=Array.from(e),n=Math.floor(t);if(ae(r)){if(n>=1)return GA(r,n);return[[],r]}return[r,[]]}),GA=p(2,(e,t)=>{let r=Math.max(1,Math.floor(t));return r>=e.length?[Qo(e),[]]:[Zo(e.slice(1,r),Ce(e)),e.slice(r)]});var Qo=(e)=>e.slice();var YA=p(3,(e,t,r)=>{let n=fe(e),o=fe(t);if(ae(n)){if(ae(o))return hy(r)(vp(n,o));return n}return o}),hn=p(2,(e,t)=>YA(e,t,VA));var Dr=()=>[],Je=(e)=>[e],Qt=p(2,(e,t)=>e.map(t)),ds=p(2,(e,t)=>{if(ly(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}),nc=ds(te),oc=p(2,(e,t)=>{let r=fe(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 Xo=p(3,(e,t,r)=>fe(e).reduce((n,o,i)=>r(n,o,i),t));var Mp=(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 gn=kg;var hy=p(2,(e,t)=>{let r=fe(e);if(ae(r)){let n=[Ce(r)],o=Zt(r);for(let i of o)if(n.every((s)=>!t(i,s)))n.push(i);return n}return[]}),Lp=(e)=>hy(e,is());var qr=p(2,(e,t)=>fe(e).join(t));var yy=Symbol.for("effect/Chunk");function eI(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 xy=[],tI=(e)=>Xi((t,r)=>t.length===r.length&&Ur(t).every((n,o)=>e(n,ei(r,o)))),rI=tI(b),nI={[yy]:{_A:(e)=>e},toString(){return ie(this.toJSON())},toJSON(){return{_id:"Chunk",values:Ur(this).map(re)}},[Z](){return this.toJSON()},[O](e){return Sy(e)&&rI(this,e)},[T](){return Q(this,At(Ur(this)))},[Symbol.iterator](){switch(this.backing._tag){case"IArray":return this.backing.array[Symbol.iterator]();case"IEmpty":return xy[Symbol.iterator]();default:return Ur(this)[Symbol.iterator]()}},pipe(){return y(this,arguments)}},Me=(e)=>{let t=Object.create(nI);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=mr,t.right=mr;break}case"ISingleton":{t.length=1,t.depth=0,t.left=mr,t.right=mr;break}case"ISlice":{t.length=e.length,t.depth=e.chunk.depth+1,t.left=mr,t.right=mr;break}}return t},Sy=(e)=>_(e,yy),mr=Me({_tag:"IEmpty"}),Mt=()=>mr,ms=(...e)=>sI(e),Pe=(e)=>Me({_tag:"ISingleton",a:e}),ic=(e)=>Sy(e)?e:hs(fe(e)),Dp=(e,t,r)=>{switch(e.backing._tag){case"IArray":{eI(e.backing.array,0,t,r,e.length);break}case"IConcat":{Dp(e.left,t,r),Dp(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]=ei(e,n),n+=1,o+=1;break}}};var oI=(e)=>{switch(e.backing._tag){case"IEmpty":return xy;case"IArray":return e.backing.array;default:{let t=Array(e.length);return Dp(e,t,0),e.backing={_tag:"IArray",array:t},e.left=mr,e.right=mr,e.depth=0,t}}},Ur=oI,iI=(e)=>{switch(e.backing._tag){case"IEmpty":case"ISingleton":return e;case"IArray":return Me({_tag:"IArray",array:Fp(e.backing.array)});case"IConcat":return Me({_tag:"IConcat",left:yn(e.backing.right),right:yn(e.backing.left)});case"ISlice":return hs(Fp(Ur(e)))}},yn=iI;var hs=(e)=>e.length===0?Mt():e.length===1?Pe(e[0]):Me({_tag:"IArray",array:e}),sI=(e)=>hs(e),ei=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?ei(e.left,t):ei(e.right,t-e.left.length);case"ISlice":return ei(e.backing.chunk,t+e.backing.offset)}}),by=p(2,(e,t)=>It(e,Pe(t))),Ge=p(2,(e,t)=>It(Pe(t),e));var qp=p(2,(e,t)=>{if(t<=0)return e;else if(t>=e.length)return mr;else switch(e.backing._tag){case"ISlice":return Me({_tag:"ISlice",chunk:e.backing.chunk,offset:e.backing.offset+t,length:e.backing.length-t});case"IConcat":{if(t>e.left.length)return qp(e.right,t-e.left.length);return Me({_tag:"IConcat",left:qp(e.left,t),right:e.right})}default:return Me({_tag:"ISlice",chunk:e,offset:t,length:e.length-t})}});var It=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 Me({_tag:"IConcat",left:e,right:t});else if(r<-1)if(e.left.depth>=e.right.depth){let n=It(e.right,t);return Me({_tag:"IConcat",left:e.left,right:n})}else{let n=It(e.right.right,t);if(n.depth===e.depth-3){let o=Me({_tag:"IConcat",left:e.right.left,right:n});return Me({_tag:"IConcat",left:e.left,right:o})}else{let o=Me({_tag:"IConcat",left:e.left,right:e.right.left});return Me({_tag:"IConcat",left:o,right:n})}}else if(t.right.depth>=t.left.depth){let n=It(e,t.left);return Me({_tag:"IConcat",left:n,right:t.right})}else{let n=It(e,t.left.left);if(n.depth===t.depth-3){let o=Me({_tag:"IConcat",left:n,right:t.left.right});return Me({_tag:"IConcat",left:o,right:t.right})}else{let o=Me({_tag:"IConcat",left:t.left.right,right:t.right});return Me({_tag:"IConcat",left:n,right:o})}}});var _y=(e)=>e.length===0,Xt=(e)=>e.length>0;var Up=(e)=>ei(e,0),er=Up;var tr=(e)=>qp(e,1);var xn=5,Hp=Math.pow(2,5),wy=Hp-1,Ey=Hp/2,Oy=Hp/4;function aI(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 Sn(e,t){return t>>>e&wy}function bn(e){return 1<<e}function sc(e,t){return aI(e&t-1)}var Ty=(e,t)=>({value:e,previous:t});function co(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 jp(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 ky(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 jr{_tag="EmptyNode";modify(e,t,r,n,o,i){let s=r(w());if(Se(s))return new jr;return++i.value,new lo(e,n,o,s)}}function Lt(e){return rs(e,"EmptyNode")}function lI(e){return Lt(e)||e._tag==="LeafNode"||e._tag==="CollisionNode"}function ac(e,t){return Lt(e)?!1:t===e.edit}class lo{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(b(o,this.key)){let a=r(this.value);if(a===this.value)return this;else if(Se(a))return--i.value,new jr;if(ac(this,e))return this.value=a,this;return new lo(e,n,o,a)}let s=r(w());if(Se(s))return this;return++i.value,Ay(e,t,this.hash,this,n,new lo(e,n,o,s))}}class $p{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=ac(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 $p(e,this.hash,c):c[0]}let s=r(w());if(Se(s))return this;return++i.value,Ay(e,t,this.hash,this,n,new lo(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&&b(i,u.key)){let f=u.value,d=o(f);if(d===f)return n;if(Se(d))return--s.value,jp(e,l,n);return co(e,l,new lo(t,r,i,d),n)}}let c=o(w());if(Se(c))return n;return++s.value,co(e,a,new lo(t,r,i,c),n)}}class ti{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=Sn(t,n),l=bn(c),u=sc(s,l),f=s&l,d=ac(this,e);if(!f){let E=new jr().modify(e,t+xn,r,n,o,i);if(!E)return this;return a.length>=Ey?pI(e,c,E,s,a):new ti(e,s|l,ky(d,u,E,a))}let g=a[u],h=g.modify(e,t+xn,r,n,o,i);if(g===h)return this;let P=s,x;if(Lt(h)){if(P&=~l,!P)return new jr;if(a.length<=2&&lI(a[u^1]))return a[u^1];x=jp(d,u,a)}else x=co(d,u,h,a);if(d)return this.mask=P,this.children=x,this;return new ti(e,P,x)}}class Bp{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=Sn(t,n),l=a[c],u=(l||new jr).modify(e,t+xn,r,n,o,i);if(l===u)return this;let f=ac(this,e),d;if(Lt(l)&&!Lt(u))++s,d=co(f,c,u,a);else if(!Lt(l)&&Lt(u)){if(--s,s<=Oy)return uI(e,s,c,a);d=co(f,c,new jr,a)}else d=co(f,c,u,a);if(f)return this.size=s,this.children=d,this;return new Bp(e,s,d)}}function uI(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&&!Lt(l))o[i++]=l,s|=1<<a}return new ti(e,s,o)}function pI(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 Bp(e,a+1,i)}function fI(e,t,r,n,o,i){if(r===o)return new $p(e,r,[i,n]);let s=Sn(t,r),a=Sn(t,o);if(s===a)return(c)=>new ti(e,bn(s)|bn(a),[c]);else{let c=s<a?[n,i]:[i,n];return new ti(e,bn(s)|bn(a),c)}}function Ay(e,t,r,n,o,i){let s=void 0,a=t;while(!0){let c=fI(e,a,r,n,o,i);if(typeof c==="function")s=Ty(c,s),a=a+xn;else{let l=c;while(s!=null)l=s.value(l),s=s.previous;return l}}}var Iy="effect/HashMap",cc=Symbol.for(Iy),mI={[cc]:cc,[Symbol.iterator](){return new uc(this,(e,t)=>[e,t])},[T](){let e=S(Iy);for(let t of this)e^=m(S(t[0]),H(S(t[1])));return Q(this,e)},[O](e){if(Py(e)){if(e._size!==this._size)return!1;for(let t of this){let r=m(e,pc(t[0],S(t[0])));if(Se(r))return!1;else if(!b(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)}},[Z](){return this.toJSON()},pipe(){return y(this,arguments)}},Kp=(e,t,r,n)=>{let o=Object.create(mI);return o._editable=e,o._edit=t,o._root=r,o._size=n,o};class uc{map;f;v;constructor(e,t){this.map=e,this.f=t,this.v=vy(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=lc(e.cont),{done:!1,value:e.value}}[Symbol.iterator](){return new uc(this.map,this.f)}}var lc=(e)=>e?Ry(e[0],e[1],e[2],e[3],e[4]):w(),vy=(e,t,r=void 0)=>{switch(e._tag){case"LeafNode":{if(pe(e.value))return R({value:t(e.key,e.value.value),cont:r});return lc(r)}case"CollisionNode":case"ArrayNode":case"IndexedNode":{let n=e.children;return Ry(n.length,n,0,t,r)}default:return lc(r)}},Ry=(e,t,r,n,o)=>{while(r<e){let i=t[r++];if(i&&!Lt(i))return vy(i,n,[e,t,r,n,o])}return lc(o)},hI=Kp(!1,0,new jr,0),ri=()=>hI;var Cy=(e)=>{let t=dc(ri());for(let r of e)uo(t,r[0],r[1]);return My(t)},Py=(e)=>_(e,cc),Fy=(e)=>e&&Lt(e._root),Ny=p(2,(e,t)=>pc(e,t,S(t))),pc=p(3,(e,t,r)=>{let n=e._root,o=0;while(!0)switch(n._tag){case"LeafNode":return b(t,n.key)?n.value:w();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&&b(t,c.key))return c.value}}return w()}case"IndexedNode":{let i=Sn(o,r),s=bn(i);if(n.mask&s){n=n.children[sc(n.mask,s)],o+=xn;break}return w()}case"ArrayNode":{if(n=n.children[Sn(o,r)],n){o+=xn;break}return w()}default:return w()}});var Wp=p(2,(e,t)=>pe(pc(e,t,S(t))));var uo=p(3,(e,t,r)=>mc(e,t,()=>R(r))),gI=p(3,(e,t,r)=>{if(e._editable)return e._root=t,e._size=r,e;return t===e._root?e:Kp(e._editable,e._edit,t,r)}),fc=(e)=>new uc(e,(t)=>t);var gs=(e)=>e._size;var dc=(e)=>Kp(!0,e._edit+1,e._root,e._size),My=(e)=>(e._editable=!1,e);var mc=p(3,(e,t,r)=>Ly(e,t,S(t),r)),Ly=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,gI(i,o.value))});var hc=p(2,(e,t)=>mc(e,t,w));var Dy=p(2,(e,t)=>ni(e,ri(),(r,n,o)=>uo(r,o,t(n,o))));var zp=p(2,(e,t)=>ni(e,void 0,(r,n,o)=>t(n,o))),ni=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&&!Lt(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 Uy="effect/HashSet",gc=Symbol.for(Uy),yI={[gc]:gc,[Symbol.iterator](){return fc(this._keyMap)},[T](){return Q(this,H(S(this._keyMap))(S(Uy)))},[O](e){if(Hy(e))return gs(this._keyMap)===gs(e._keyMap)&&b(this._keyMap,e._keyMap);return!1},toString(){return ie(this.toJSON())},toJSON(){return{_id:"HashSet",values:Array.from(this).map(re)}},[Z](){return this.toJSON()},pipe(){return y(this,arguments)}},yc=(e)=>{let t=Object.create(yI);return t._keyMap=e,t},Hy=(e)=>_(e,gc),xI=yc(ri()),ys=()=>xI,jy=(e)=>{let t=xc(ys());for(let r of e)oi(t,r);return Sc(t)},$y=(...e)=>{let t=xc(ys());for(let r of e)oi(t,r);return Sc(t)},By=p(2,(e,t)=>Wp(e._keyMap,t));var Ky=(e)=>gs(e._keyMap),xc=(e)=>yc(dc(e._keyMap)),Sc=(e)=>(e._keyMap._editable=!1,e),Vp=p(2,(e,t)=>{let r=xc(e);return t(r),Sc(r)}),oi=p(2,(e,t)=>e._keyMap._editable?(uo(t,!0)(e._keyMap),e):yc(uo(t,!0)(e._keyMap))),Jp=p(2,(e,t)=>e._keyMap._editable?(hc(t)(e._keyMap),e):yc(hc(t)(e._keyMap))),Wy=p(2,(e,t)=>Vp(e,(r)=>{for(let n of t)Jp(r,n)}));var zy=p(2,(e,t)=>Vp(ys(),(r)=>{Vy(e,(n)=>oi(r,n));for(let n of t)oi(r,n)}));var Vy=p(2,(e,t)=>zp(e._keyMap,(r,n)=>t(n))),Jy=p(3,(e,t,r)=>ni(e._keyMap,t,(n,o,i)=>r(n,i)));var hr=ys,Gy=jy,po=$y,Yy=By;var xs=Ky;var fo=oi,Gp=Jp,Yp=Wy;var $r=zy;var mo=Jy;var si="Die",_n="Empty",wn="Fail",ho="Interrupt",go="Parallel",yo="Sequential";var Xy="effect/Cause",Xp=Symbol.for(Xy),_I={_E:(e)=>e},ai={[Xp]:_I,[T](){return m(S(Xy),H(S(EI(this))),Q(this))},[O](e){return ex(e)&&wI(this,e)},pipe(){return y(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 nr(this)},[Z](){return this.toJSON()}},Br=(()=>{let e=Object.create(ai);return e._tag=_n,e})(),ci=(e)=>{let t=Object.create(ai);return t._tag=wn,t.error=e,t},vt=(e)=>{let t=Object.create(ai);return t._tag=si,t.defect=e,t},rr=(e)=>{let t=Object.create(ai);return t._tag=ho,t.fiberId=e,t},bo=(e,t)=>{let r=Object.create(ai);return r._tag=go,r.left=e,r.right=t,r},Ye=(e,t)=>{let r=Object.create(ai);return r._tag=yo,r.left=e,r.right=t,r},ex=(e)=>_(e,Xp),ef=(e)=>e._tag===_n,tx=(e)=>e._tag===wn;var bc=(e)=>{if(e._tag===_n)return!0;return xo(e,!0,(t,r)=>{switch(r._tag){case _n:return R(t);case si:case wn:case ho:return R(!1);default:return w()}})};var _c=(e)=>pe(rx(e)),li=(e)=>Oc(void 0,TI)(e),tf=(e)=>yn(xo(e,Mt(),(t,r)=>r._tag===wn?R(m(t,Ge(r.error))):w())),rf=(e)=>yn(xo(e,Mt(),(t,r)=>r._tag===si?R(m(t,Ge(r.defect))):w())),nf=(e)=>xo(e,hr(),(t,r)=>r._tag===ho?R(m(t,fo(r.fiberId))):w()),of=(e)=>sf(e,(t)=>t._tag===wn?R(t.error):w()),wc=(e)=>{let t=of(e);switch(t._tag){case"None":return K(e);case"Some":return U(t.value)}};var rx=(e)=>sf(e,(t)=>t._tag===ho?R(t.fiberId):w());var Ec=(e)=>af(e,{onEmpty:Br,onFail:()=>Br,onDie:vt,onInterrupt:rr,onSequential:Ye,onParallel:bo}),nx=(e)=>af(e,{onEmpty:Br,onFail:vt,onDie:vt,onInterrupt:rr,onSequential:Ye,onParallel:bo});var wI=(e,t)=>{let r=Pe(e),n=Pe(t);while(Xt(r)&&Xt(n)){let[o,i]=m(er(r),xo([hr(),Mt()],([c,l],u)=>{let[f,d]=Zp(u);return R([m(c,$r(f)),m(l,It(d))])})),[s,a]=m(er(n),xo([hr(),Mt()],([c,l],u)=>{let[f,d]=Zp(u);return R([m(c,$r(f)),m(l,It(d))])}));if(!b(o,s))return!1;r=i,n=a}return!0},EI=(e)=>OI(Pe(e),Mt()),OI=(e,t)=>{while(!0){let[r,n]=m(e,Xo([hr(),Mt()],([i,s],a)=>{let[c,l]=Zp(a);return[m(i,$r(c)),m(s,It(l))]})),o=xs(r)>0?m(t,Ge(r)):t;if(_y(n))return yn(o);e=n,t=o}throw Error(to("Cause.flattenCauseLoop"))},sf=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 yo:case go:{r.push(n.right),r.push(n.left);break}}break}case"Some":return o}}return w()});var Zp=(e)=>{let t=e,r=[],n=hr(),o=Mt();while(t!==void 0)switch(t._tag){case _n:{if(r.length===0)return[n,o];t=r.pop();break}case wn:{if(n=fo(n,ms(t._tag,t.error)),r.length===0)return[n,o];t=r.pop();break}case si:{if(n=fo(n,ms(t._tag,t.defect)),r.length===0)return[n,o];t=r.pop();break}case ho:{if(n=fo(n,ms(t._tag,t.fiberId)),r.length===0)return[n,o];t=r.pop();break}case yo:{switch(t.left._tag){case _n:{t=t.right;break}case yo:{t=Ye(t.left.left,Ye(t.left.right,t.right));break}case go:{t=bo(Ye(t.left.left,t.right),Ye(t.left.right,t.right));break}default:{o=Ge(o,t.right),t=t.left;break}}break}case go:{r.push(t.right),t=t.left;break}}throw Error(to("Cause.evaluateCauseLoop"))};var TI={emptyCase:Yi,failCase:ln,dieCase:ln,interruptCase:Yi,sequentialCase:(e,t,r)=>t&&r,parallelCase:(e,t,r)=>t&&r};var Zy="SequentialCase",Qy="ParallelCase",af=p(2,(e,{onDie:t,onEmpty:r,onFail:n,onInterrupt:o,onParallel:i,onSequential:s})=>Oc(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)})),xo=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 yo:{i.push(o.right),o=o.left;break}case go:{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}),Oc=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._tag){case _n:{o.push(K(r.emptyCase(t)));break}case wn:{o.push(K(r.failCase(t,s.error)));break}case si:{o.push(K(r.dieCase(t,s.defect)));break}case ho:{o.push(K(r.interruptCase(t,s.fiberId)));break}case yo:{n.push(s.right),n.push(s.left),o.push(U({_tag:Zy}));break}case go:{n.push(s.right),n.push(s.left),o.push(U({_tag:Qy}));break}}}let i=[];while(o.length>0){let s=o.pop();switch(s._tag){case"Left":{switch(s.left._tag){case Zy:{let a=i.pop(),c=i.pop(),l=r.sequentialCase(t,a,c);i.push(l);break}case Qy:{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()}),nr=(e,t)=>{if(li(e))return"All fibers interrupted without errors.";return Ss(e).map(function(r){if(t?.renderErrorCause!==!0||r.cause===void 0)return r.stack;return`${r.stack} {
13
+ ${ox(r.cause," ")}
14
14
  }`}).join(`
15
- `)},Zy=(e,t)=>{let r=e.stack.split(`
15
+ `)},ox=(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
- ${Zy(e.cause,`${t} `)}
19
- ${t}}`;return n},Jp=(e)=>{let t=typeof e==="object"&&e!==null,r=Error.stackTraceLimit;Error.stackTraceLimit=1;let n=Error(bI(e),t&&"cause"in e&&typeof e.cause<"u"?{cause:Jp(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(ho in e)n.span=e[ho];Object.keys(e).forEach((o)=>{if(!(o in n))n[o]=e[o]})}return n.stack=EI(`${n.name}: ${n.message}`,e instanceof Error&&e.stack?e.stack:"",n.span),n},bI=(e)=>{if(typeof e==="string")return e;if(typeof e==="object"&&e!==null&&e instanceof Error)return e.message;try{if(_(e,"toString")&&ln(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return Va(e)},_I=/\((.*)\)/g,wI=N("effect/Tracer/spanToTrace",()=>new WeakMap),EI=(e,t,r)=>{let n=[e],o=t.startsWith(e)?t.slice(e.length).split(`
18
+ ${ox(e.cause,`${t} `)}
19
+ ${t}}`;return n},Qp=(e)=>{let t=typeof e==="object"&&e!==null,r=Error.stackTraceLimit;Error.stackTraceLimit=1;let n=Error(kI(e),t&&"cause"in e&&typeof e.cause<"u"?{cause:Qp(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(So in e)n.span=e[So];Object.keys(e).forEach((o)=>{if(!(o in n))n[o]=e[o]})}return n.stack=vI(`${n.name}: ${n.message}`,e instanceof Error&&e.stack?e.stack:"",n.span),n},kI=(e)=>{if(typeof e==="string")return e;if(typeof e==="object"&&e!==null&&e instanceof Error)return e.message;try{if(_(e,"toString")&&pn(e.toString)&&e.toString!==Object.prototype.toString&&e.toString!==globalThis.Array.prototype.toString)return e.toString()}catch{}return Ya(e)},AI=/\((.*)\)/g,II=M("effect/Tracer/spanToTrace",()=>new WeakMap),vI=(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=wI.get(i);if(typeof a==="function"){let c=a();if(typeof c==="string"){let l=c.matchAll(_I),u=!1;for(let[,f]of l)u=!0,n.push(` at ${i.name} (${f})`);if(!u)n.push(` at ${i.name} (${c.replace(/^at /,"")})`)}else n.push(` at ${i.name}`)}else n.push(` at ${i.name}`);i=ft(i.parent),s++}}return n.join(`
22
- `)},ho=Symbol.for("effect/SpanAnnotation"),ys=(e)=>_c(e,void 0,{emptyCase:()=>[],dieCase:(t,r)=>[Jp(r)],failCase:(t,r)=>[Jp(r)],interruptCase:()=>[],parallelCase:(t,r,n)=>[...r,...n],sequentialCase:(t,r,n)=>[...r,...n]});var Qy=Symbol.for("effect/Context/Tag"),Ss=Symbol.for("effect/Context/Reference"),OI="effect/STM",TI=Symbol.for(OI),Xy={...vr,_op:"Tag",[TI]:un,[Qy]:{_Service:(e)=>e,_Identifier:(e)=>e},toString(){return oe(this.toJSON())},toJSON(){return{_id:"Tag",key:this.key,stack:this.stack}},[J](){return this.toJSON()},of(e){return e},context(e){return sf(this,e)}},kI={...Xy,[Ss]:Ss},ex=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let r=Error();Error.stackTraceLimit=t;let n=Object.create(Xy);return Object.defineProperty(n,"stack",{get(){return r.stack}}),n.key=e,n};var tx=()=>(e,t)=>{let r=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=r;function o(){}return Object.setPrototypeOf(o,kI),o.key=e,o.defaultValue=t.defaultValue,Object.defineProperty(o,"stack",{get(){return n.stack}}),o},of=Symbol.for("effect/Context"),AI={[of]:{_Services:(e)=>e},[O](e){if(rx(e)){if(this.unsafeMap.size===e.unsafeMap.size){for(let t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!b(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}}return!1},[k](){return Z(this,Ka(this.unsafeMap.size))},pipe(){return y(this,arguments)},toString(){return oe(this.toJSON())},toJSON(){return{_id:"Context",services:Array.from(this.unsafeMap).map(X)}},[J](){return this.toJSON()}},_n=(e)=>{let t=Object.create(AI);return t.unsafeMap=e,t},II=(e)=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(e.stack){let r=e.stack.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=II.get(i);if(typeof a==="function"){let c=a();if(typeof c==="string"){let l=c.matchAll(AI),u=!1;for(let[,f]of l)u=!0,n.push(` at ${i.name} (${f})`);if(!u)n.push(` at ${i.name} (${c.replace(/^at /,"")})`)}else n.push(` at ${i.name}`)}else n.push(` at ${i.name}`);i=yt(i.parent),s++}}return n.join(`
22
+ `)},So=Symbol.for("effect/SpanAnnotation"),Ss=(e)=>Oc(e,void 0,{emptyCase:()=>[],dieCase:(t,r)=>[Qp(r)],failCase:(t,r)=>[Qp(r)],interruptCase:()=>[],parallelCase:(t,r,n)=>[...r,...n],sequentialCase:(t,r,n)=>[...r,...n]});var ix=Symbol.for("effect/Context/Tag"),_s=Symbol.for("effect/Context/Reference"),RI="effect/STM",CI=Symbol.for(RI),sx={...Pr,_op:"Tag",[CI]:fn,[ix]:{_Service:(e)=>e,_Identifier:(e)=>e},toString(){return ie(this.toJSON())},toJSON(){return{_id:"Tag",key:this.key,stack:this.stack}},[Z](){return this.toJSON()},of(e){return e},context(e){return uf(this,e)}},PI={...sx,[_s]:_s},ax=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=2;let r=Error();Error.stackTraceLimit=t;let n=Object.create(sx);return Object.defineProperty(n,"stack",{get(){return r.stack}}),n.key=e,n};var cx=()=>(e,t)=>{let r=Error.stackTraceLimit;Error.stackTraceLimit=2;let n=Error();Error.stackTraceLimit=r;function o(){}return Object.setPrototypeOf(o,PI),o.key=e,o.defaultValue=t.defaultValue,Object.defineProperty(o,"stack",{get(){return n.stack}}),o},lf=Symbol.for("effect/Context"),FI={[lf]:{_Services:(e)=>e},[O](e){if(lx(e)){if(this.unsafeMap.size===e.unsafeMap.size){for(let t of this.unsafeMap.keys())if(!e.unsafeMap.has(t)||!b(this.unsafeMap.get(t),e.unsafeMap.get(t)))return!1;return!0}}return!1},[T](){return Q(this,Va(this.unsafeMap.size))},pipe(){return y(this,arguments)},toString(){return ie(this.toJSON())},toJSON(){return{_id:"Context",services:Array.from(this.unsafeMap).map(re)}},[Z](){return this.toJSON()}},En=(e)=>{let t=Object.create(FI);return t.unsafeMap=e,t},NI=(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},rx=(e)=>_(e,of);var nx=(e)=>_(e,Ss),RI=_n(new Map),ox=()=>RI,sf=(e,t)=>_n(new Map([[e.key,t]])),ix=p(3,(e,t,r)=>{let n=new Map(e.unsafeMap);return n.set(t.key,r),_n(n)}),nf=N("effect/Context/defaultValueCache",()=>new Map),af=(e)=>{if(nf.has(e.key))return nf.get(e.key);let t=e.defaultValue();return nf.set(e.key,t),t},sx=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):af(t),cf=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(Ss in t)return af(t);throw II(t)}return e.unsafeMap.get(t.key)}),ax=cf;var cx=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key))return nx(t)?ls(af(t)):Ya;return ls(e.unsafeMap.get(t.key))}),lx=p(2,(e,t)=>{let r=new Map(e.unsafeMap);for(let[n,o]of t.unsafeMap)r.set(n,o);return _n(r)});var dt=ex;var wn=ox,px=sf,fr=ix,bs=ax;var _s=cf,En=cx,ws=lx;var Es=tx;var uf=Symbol.for("effect/Duration"),gx=BigInt(0),fx=BigInt(24),wc=BigInt(60),pf=BigInt(1000),dx=BigInt(1e6),mx=BigInt(1e9),vI=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,$r=(e)=>{if(yx(e))return e;else if(_t(e))return Ec(e);else if(cn(e))return lf(e);else if(Array.isArray(e)&&e.length===2&&e.every(_t)){if(e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1]))return ff;if(e[0]===1/0||e[1]===1/0)return NI;return lf(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])))}else if(Be(e)){let t=vI.exec(e);if(t){let[r,n,o]=t,i=Number(n);switch(o){case"nano":case"nanos":return lf(BigInt(n));case"micro":case"micros":return MI(BigInt(n));case"milli":case"millis":return Ec(i);case"second":case"seconds":return LI(i);case"minute":case"minutes":return DI(i);case"hour":case"hours":return qI(i);case"day":case"days":return UI(i);case"week":case"weeks":return HI(i)}}}throw Error("Invalid DurationInput")};var hx={_tag:"Millis",millis:0},CI={_tag:"Infinity"},PI={[uf]:uf,[k](){return Z(this,Wa(this.value))},[O](e){return yx(e)&&WI(this,e)},toString(){return`Duration(${VI(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:$I(this)};case"Infinity":return{_id:"Duration",_tag:"Infinity"}}},[J](){return this.toJSON()},pipe(){return y(this,arguments)}},dr=(e)=>{let t=Object.create(PI);if(_t(e))if(isNaN(e)||e<=0)t.value=hx;else if(!Number.isFinite(e))t.value=CI;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=hx;else t.value={_tag:"Nanos",nanos:e};return t},yx=(e)=>_(e,uf);var FI=(e)=>{switch(e.value._tag){case"Millis":return e.value.millis===0;case"Nanos":return e.value.nanos===gx;case"Infinity":return!1}},ff=dr(0),NI=dr(1/0),lf=(e)=>dr(e),MI=(e)=>dr(e*pf),Ec=(e)=>dr(e),LI=(e)=>dr(e*1000),DI=(e)=>dr(e*60000),qI=(e)=>dr(e*3600000),UI=(e)=>dr(e*86400000),HI=(e)=>dr(e*604800000),Oc=(e)=>BI(e,{onMillis:(t)=>t,onNanos:(t)=>Number(t)/1e6});var jI=(e)=>{let t=$r(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))}},$I=(e)=>{let t=$r(e);switch(t.value._tag){case"Infinity":return[1/0,0];case"Nanos":return[Number(t.value.nanos/mx),Number(t.value.nanos%mx)];case"Millis":return[Math.floor(t.value.millis/1000),Math.round(t.value.millis%1000*1e6)]}},BI=p(2,(e,t)=>{let r=$r(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)}}),df=p(3,(e,t,r)=>{let n=$r(e),o=$r(t);if(n.value._tag==="Infinity"||o.value._tag==="Infinity")return r.onMillis(Oc(n),Oc(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 KI=(e,t)=>df(e,t,{onMillis:(r,n)=>r===n,onNanos:(r,n)=>r===n});var xx=p(2,(e,t)=>df(e,t,{onMillis:(r,n)=>r<=n,onNanos:(r,n)=>r<=n}));var Sx=p(2,(e,t)=>df(e,t,{onMillis:(r,n)=>r>=n,onNanos:(r,n)=>r>=n})),WI=p(2,(e,t)=>KI($r(e),$r(t))),zI=(e)=>{let t=$r(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=jI(t),n=r/dx,o=n/pf,i=o/wc,s=i/wc,a=s/fx;return{days:Number(a),hours:Number(s%fx),minutes:Number(i%wc),seconds:Number(o%wc),millis:Number(n%pf),nanos:Number(r%dx)}},VI=(e)=>{let t=$r(e);if(t.value._tag==="Infinity")return"Infinity";if(FI(t))return"0";let r=zI(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 _x=Symbol.for("effect/MutableRef"),JI={[_x]:_x,toString(){return oe(this.toJSON())},toJSON(){return{_id:"MutableRef",current:X(this.current)}},[J](){return this.toJSON()},pipe(){return y(this,arguments)}},Tc=(e)=>{let t=Object.create(JI);return t.current=e,t};var ai=(e)=>e.current;var kc=p(2,(e,t)=>(e.current=t,e));var hf="effect/FiberId",ci=Symbol.for(hf),Ac="None",mf="Runtime",GI="Composite",YI=ne(`${hf}-${Ac}`);class Ox{[ci]=ci;_tag=Ac;id=-1;startTimeMillis=-1;[k](){return YI}[O](e){return gf(e)&&e._tag===Ac}toString(){return oe(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag}}[J](){return this.toJSON()}}class Tx{id;startTimeMillis;[ci]=ci;_tag=mf;constructor(e,t){this.id=e,this.startTimeMillis=t}[k](){return Z(this,ne(`${hf}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[O](e){return gf(e)&&e._tag===mf&&this.id===e.id&&this.startTimeMillis===e.startTimeMillis}toString(){return oe(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag,id:this.id,startTimeMillis:this.startTimeMillis}}[J](){return this.toJSON()}}var kx=new Ox;var gf=(e)=>_(e,ci);var Ic=(e)=>{switch(e._tag){case Ac:return pr();case mf:return ao(e.id);case GI:return m(Ic(e.left),Hr(Ic(e.right)))}},Ex=N(Symbol.for("effect/Fiber/Id/_fiberCounter"),()=>Tc(0));var Rc=(e)=>Array.from(Ic(e)).map((r)=>`#${r}`).join(",");var Ax=()=>{let e=ai(Ex);return m(Ex,kc(e+1)),new Tx(e,Date.now())};var Lt=kx;var Rx=Rc;var vc=Ax;var li=Xo;var vx=Oy,Cx=ky,yf=Ay;var xf=so,Sf=lc;var Px=pc;var Fx=vy;var bf=ei;var Ts=Symbol.for("effect/List"),wf=(e)=>pe(e),ZI=(e)=>tp(mn(e),wf),QI=ZI(b),XI={[Ts]:Ts,_tag:"Cons",toString(){return oe(this.toJSON())},toJSON(){return{_id:"List",_tag:"Cons",values:wf(this).map(X)}},[J](){return this.toJSON()},[O](e){return Mx(e)&&this._tag===e._tag&&QI(this,e)},[k](){return Z(this,wt(wf(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 y(this,arguments)}},Cc=(e,t)=>{let r=Object.create(XI);return r.head=e,r.tail=t,r},eR=ne("Nil"),tR={[Ts]:Ts,_tag:"Nil",toString(){return oe(this.toJSON())},toJSON(){return{_id:"List",_tag:"Nil"}},[J](){return this.toJSON()},[k](){return eR},[O](e){return Mx(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return y(this,arguments)}},Nx=Object.create(tR),Mx=(e)=>_(e,Ts),mr=(e)=>e._tag==="Nil",Ef=(e)=>e._tag==="Cons";var rR=()=>Nx,Br=(e,t)=>Cc(e,t),On=rR,ks=(e)=>Cc(e,Nx);var Lx=p(2,(e,t)=>oR(t,e)),nR=p(2,(e,t)=>Br(t,e)),oR=p(2,(e,t)=>{if(mr(e))return t;else if(mr(t))return e;else{let r=Cc(t.head,e),n=r,o=t.tail;while(!mr(o)){let i=Cc(o.head,e);n.tail=i,n=i,o=o.tail}return r}});var Dx=p(3,(e,t,r)=>{let n=t,o=e;while(!mr(o))n=r(n,o.head),o=o.tail;return n});var qx=(e)=>{let t=On(),r=e;while(!mr(r))t=nR(t,r.head),r=r.tail;return t};var Nq=Object.assign(Object.create(Array.prototype),{[k](){return Z(this,wt(this))},[O](e){if(Array.isArray(e)&&this.length===e.length)return this.every((t,r)=>b(t,e[r]));else return!1}}),ui=function(){function e(t){if(t)Object.assign(this,t)}return e.prototype=cs,e}();var sR=Symbol.for("effect/DifferContextPatch");function Ux(e){return e}var Is={...ui.prototype,[sR]:{_Value:Ux,_Patch:Ux}},aR=Object.assign(Object.create(Is),{_tag:"Empty"}),cR=Object.create(aR),Tf=()=>cR,lR=Object.assign(Object.create(Is),{_tag:"AndThen"}),uR=(e,t)=>{let r=Object.create(lR);return r.first=e,r.second=t,r},pR=Object.assign(Object.create(Is),{_tag:"AddService"}),fR=(e,t)=>{let r=Object.create(pR);return r.key=e,r.service=t,r},dR=Object.assign(Object.create(Is),{_tag:"RemoveService"}),mR=(e)=>{let t=Object.create(dR);return t.key=e,t},hR=Object.assign(Object.create(Is),{_tag:"UpdateService"}),gR=(e,t)=>{let r=Object.create(hR);return r.key=e,r.update=t,r},Hx=(e,t)=>{let r=new Map(e.unsafeMap),n=Tf();for(let[o,i]of t.unsafeMap.entries())if(r.has(o)){let s=r.get(o);if(r.delete(o),!b(s,i))n=As(gR(o,()=>i))(n)}else r.delete(o),n=As(fR(o,i))(n);for(let[o]of r.entries())n=As(mR(o))(n);return n},As=p(2,(e,t)=>uR(e,t)),jx=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=!1,n=Re(e),o=new Map(t.unsafeMap);while(Yt(n)){let s=Zt(n),a=Qt(n);switch(s._tag){case"Empty":{n=a;break}case"AddService":{o.set(s.key,s.service),n=a;break}case"AndThen":{n=Je(Je(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 _n(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 _n(i)});var xR=Symbol.for("effect/DifferHashSetPatch");function kf(e){return e}var Fc={...ui.prototype,[xR]:{_Value:kf,_Key:kf,_Patch:kf}},SR=Object.assign(Object.create(Fc),{_tag:"Empty"}),bR=Object.create(SR),Af=()=>bR,_R=Object.assign(Object.create(Fc),{_tag:"AndThen"}),wR=(e,t)=>{let r=Object.create(_R);return r.first=e,r.second=t,r},ER=Object.assign(Object.create(Fc),{_tag:"Add"}),OR=(e)=>{let t=Object.create(ER);return t.value=e,t},TR=Object.assign(Object.create(Fc),{_tag:"Remove"}),kR=(e)=>{let t=Object.create(TR);return t.value=e,t},$x=(e,t)=>{let[r,n]=lo([e,Af()],([o,i],s)=>{if(By(s)(o))return[Wp(s)(o),i];return[o,Pc(OR(s))(i)]})(t);return lo(n,(o,i)=>Pc(kR(i))(o))(r)},Pc=p(2,(e,t)=>wR(e,t)),Bx=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=t,n=Re(e);while(Yt(n)){let o=Zt(n),i=Qt(n);switch(o._tag){case"Empty":{n=i;break}case"AndThen":{n=Je(o.first)(Je(o.second)(i));break}case"Add":{r=co(o.value)(r),n=i;break}case"Remove":r=Wp(o.value)(r),n=i}}return r});var IR=Symbol.for("effect/DifferReadonlyArrayPatch");function Kx(e){return e}var vs={...ui.prototype,[IR]:{_Value:Kx,_Patch:Kx}},RR=Object.assign(Object.create(vs),{_tag:"Empty"}),vR=Object.create(RR),If=()=>vR,CR=Object.assign(Object.create(vs),{_tag:"AndThen"}),PR=(e,t)=>{let r=Object.create(CR);return r.first=e,r.second=t,r},FR=Object.assign(Object.create(vs),{_tag:"Append"}),NR=(e)=>{let t=Object.create(FR);return t.values=e,t},MR=Object.assign(Object.create(vs),{_tag:"Slice"}),LR=(e,t)=>{let r=Object.create(MR);return r.from=e,r.until=t,r},DR=Object.assign(Object.create(vs),{_tag:"Update"}),qR=(e,t)=>{let r=Object.create(DR);return r.index=e,r.patch=t,r},Wx=(e)=>{let t=0,r=If();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(!b(i,e.differ.empty))r=Rs(r,qR(t,i));t=t+1}if(t<e.oldValue.length)r=Rs(r,LR(0,t));if(t<e.newValue.length)r=Rs(r,NR(sy(t)(e.newValue)));return r},Rs=p(2,(e,t)=>PR(e,t)),zx=p(3,(e,t,r)=>{if(e._tag==="Empty")return t;let n=t.slice(),o=Ve(e);while(fn(o)){let i=Ie(o),s=Jt(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 Vx=Symbol.for("effect/Differ"),HR={[Vx]:{_P:Q,_V:Q},pipe(){return y(this,arguments)}},Tn=(e)=>{let t=Object.create(HR);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},Rf=()=>Tn({empty:Tf(),combine:(e,t)=>As(t)(e),diff:(e,t)=>Hx(e,t),patch:(e,t)=>jx(t)(e)});var vf=()=>Tn({empty:Af(),combine:(e,t)=>Pc(t)(e),diff:(e,t)=>$x(e,t),patch:(e,t)=>Bx(t)(e)});var Cf=(e)=>Tn({empty:If(),combine:(t,r)=>Rs(t,r),diff:(t,r)=>Wx({oldValue:t,newValue:r,differ:e}),patch:(t,r)=>zx(t,r,e)});var Nc=()=>Jx((e,t)=>t),Jx=(e)=>Tn({empty:Q,combine:(t,r)=>{if(t===Q)return r;if(r===Q)return t;return(n)=>r(t(n))},diff:(t,r)=>{if(b(t,r))return Q;return Vi(r)},patch:(t,r)=>e(r,t(r))});var Cs=255,Gx=8,Mc=(e)=>e&Cs,Lc=(e)=>e>>Gx&Cs,yo=(e,t)=>(e&Cs)+((t&e&Cs)<<Gx),Ff=yo(0,0),Yx=(e)=>yo(e,e),Zx=(e)=>yo(e,0);var Qx=p(2,(e,t)=>yo(Mc(e)&~t,Lc(e)));var Nf=p(2,(e,t)=>e|t);var Xx=(e)=>~e>>>0&Cs;var jR=0,Kr=1,tS=2,Mf=4,Dc=16,Lf=32;var rS=(e)=>qc(e,Lf);var Df=p(2,(e,t)=>e|t);var Wr=(e)=>qf(e)&&!$R(e),qf=(e)=>qc(e,Kr);var qc=p(2,(e,t)=>(e&t)!==0),Uf=(...e)=>e.reduce((t,r)=>t|r,0),nS=Uf(jR);var Hf=(e)=>qc(e,Mf);var $R=(e)=>qc(e,Dc);var Ps=p(2,(e,t)=>yo(e^t,t)),Fs=p(2,(e,t)=>e&(Xx(Mc(t))|Lc(t))|Mc(t)&Lc(t));var jf=Tn({empty:Ff,diff:(e,t)=>Ps(e,t),combine:(e,t)=>Nf(t)(e),patch:(e,t)=>Fs(t,e)});var oS=Yx,Bf=Zx;var Kf=Qx;var zf=(e,t)=>({_tag:"Par",left:e,right:t}),Uc=(e,t)=>({_tag:"Seq",left:e,right:t});var sS=(e)=>{let t=ks(e),r=On();while(!0){let[n,o]=Dx(t,[aS(),On()],([i,s],a)=>{let[c,l]=BR(a);return[JR(i,c),Lx(s,l)]});if(r=KR(r,n),mr(o))return qx(r);t=o}throw Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues")},BR=(e)=>{let t=e,r=aS(),n=On(),o=On();while(!0)switch(t._tag){case"Empty":{if(mr(n))return[r,o];t=n.head,n=n.tail;break}case"Par":{n=Br(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=zf(Uc(a,s),Uc(c,s));break}case"Seq":{let{left:a,right:c}=i;t=Uc(a,Uc(c,s));break}case"Single":{t=i,o=Br(s,o);break}}break}case"Single":{if(r=VR(r,t),mr(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")},KR=(e,t)=>{if(mr(e))return ks(Wf(t));if(GR(t))return e;let r=tv(e.head),n=YR(t);if(r.length===1&&n.length===1&&b(r[0],n[0]))return Br(ev(e.head,Wf(t)),e.tail);return Br(Wf(t),e)};var WR=Symbol.for("effect/RequestBlock/RequestBlockParallel"),zR={_R:(e)=>e};class Hc{map;[WR]=zR;constructor(e){this.map=e}}var aS=()=>new Hc(li());var VR=(e,t)=>new Hc(Px(e.map,t.dataSource,(r)=>Jg(zt(r,dy(t.blockedRequest)),()=>Re(t.blockedRequest)))),JR=(e,t)=>new Hc(bf(e.map,t.map,(r,n,o)=>xf(r,o,Ee(yf(r,o),{onNone:()=>n,onSome:(i)=>Et(n,i)})))),GR=(e)=>Cx(e.map),YR=(e)=>Array.from(Sf(e.map)),Wf=(e)=>XR(Fx(e.map,(t)=>Re(t))),ZR=Symbol.for("effect/RequestBlock/RequestBlockSequential"),QR={_R:(e)=>e};class Vf{map;[ZR]=QR;constructor(e){this.map=e}}var XR=(e)=>new Vf(e),ev=(e,t)=>new Vf(bf(t.map,e.map,(r,n,o)=>xf(r,o,Ee(yf(r,o),{onNone:()=>Nt(),onSome:(i)=>Et(i,n)}))));var tv=(e)=>Array.from(Sf(e.map)),cS=(e)=>Array.from(e.map);var pi="Pending",jc="Done";var nv="effect/Deferred",uS=Symbol.for(nv),pS={_E:(e)=>e,_A:(e)=>e},fS=(e)=>({_tag:pi,joiners:e}),dS=(e)=>({_tag:jc,effect:e});class fi{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 fi(this.self)}}var Kc=(e,t)=>{let r=new De("Blocked");return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r},Yf=(e)=>{let t=new De("RunBlocked");return t.effect_instruction_i0=e,t},kn=Symbol.for("effect/Effect");class Zf{patch;op;_op=ss;constructor(e,t){this.patch=e,this.op=t}}class De{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[kn]=un;constructor(e){this._op=e}[O](e){return this===e}[k](){return Z(this,ts(this))}pipe(){return y(this,arguments)}toJSON(){return{_id:"Effect",_op:this._op,effect_instruction_i0:X(this.effect_instruction_i0),effect_instruction_i1:X(this.effect_instruction_i1),effect_instruction_i2:X(this.effect_instruction_i2)}}toString(){return oe(this.toJSON())}[J](){return this.toJSON()}[Symbol.iterator](){return new fi(new Ir(this))}}class Qf{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[kn]=un;constructor(e){this._op=e,this._tag=e}[O](e){return xi(e)&&e._op==="Failure"&&b(this.effect_instruction_i0,e.effect_instruction_i0)}[k](){return m(ne(this._tag),H(S(this.effect_instruction_i0)),Z(this))}get cause(){return this.effect_instruction_i0}pipe(){return y(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,cause:this.cause.toJSON()}}toString(){return oe(this.toJSON())}[J](){return this.toJSON()}[Symbol.iterator](){return new fi(new Ir(this))}}class Xf{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[kn]=un;constructor(e){this._op=e,this._tag=e}[O](e){return xi(e)&&e._op==="Success"&&b(this.effect_instruction_i0,e.effect_instruction_i0)}[k](){return m(ne(this._tag),H(S(this.effect_instruction_i0)),Z(this))}get value(){return this.effect_instruction_i0}pipe(){return y(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,value:X(this.value)}}toString(){return oe(this.toJSON())}[J](){return this.toJSON()}[Symbol.iterator](){return new fi(new Ir(this))}}var di=(e)=>_(e,kn),We=(e)=>{let t=new De(Ga);return t.effect_instruction_i0=e,t},wS=p(3,(e,t,r)=>Rn((n)=>L(e,(o)=>L(In(fe(()=>n(t(o)))),(i)=>fe(()=>r(o,i)).pipe(Dt({onFailure:(s)=>{switch(i._tag){case lt:return Ye(Ge(i.effect_instruction_i0,s));case ut:return Ye(s)}},onSuccess:()=>i})))))),zr=p(2,(e,t)=>L(e,()=>ee(t))),Vr=(e)=>zr(e,void 0),ed=function(){let e=new De(to);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(Zn("you're not supposed to end up here"))}return e},Ns=(e,t=Lt)=>{let r=new De(eo),n=void 0;return r.effect_instruction_i0=(o)=>{n=e(o)},r.effect_instruction_i1=t,qs(r,(o)=>di(n)?n:ve)},ES=(e,t=Lt)=>fe(()=>Ns(e,t)),An=(e,t=Lt)=>ed(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 De(eo);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=Ke(()=>this.effect_instruction_i0(o,a.signal));else s=Ke(()=>this.effect_instruction_i0(o));return s||a?qs(i,(c)=>{if(a)a.abort();return s??ve}):i});var Ms=p(2,(e,t)=>mi(e,{onFailure:t,onSuccess:ee}));var mS=Symbol.for("effect/OriginalAnnotation");var Wc=(e,t)=>{if(ue(t))return new Proxy(e,{has(r,n){return n===ho||n===mS||n in r},get(r,n){if(n===ho)return t.value;if(n===mS)return e;return r[n]}});return e},zc=(e)=>ot(e)&&!(ho in e)?We((t)=>Ye(Ot(Wc(e,cl(t))))):Ye(Ot(e)),td=(e)=>OS(()=>Ot(new fv(e)));var xo=(e)=>mi(e,{onFailure:(t)=>ee(U(t)),onSuccess:(t)=>ee(B(t))}),In=(e)=>TS(e,{onFailure:ae,onSuccess:ge}),qe=(e)=>ot(e)&&!(ho in e)?We((t)=>Ye(ii(Wc(e,cl(t))))):Ye(ii(e)),rd=(e)=>L(C(e),qe),Ye=(e)=>{let t=new Qf(lt);return t.effect_instruction_i0=e,t},OS=(e)=>L(C(e),Ye),nd=We((e)=>ee(e.id())),Ls=(e)=>We((t)=>e(t.id())),L=p(2,(e,t)=>{let r=new De(Bo);return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r});var od=(e)=>{let t=new De("OnStep");return t.effect_instruction_i0=e,t},Ds=(e)=>L(e,Q);var TS=p(2,(e,t)=>Dt(e,{onFailure:(r)=>ee(t.onFailure(r)),onSuccess:(r)=>ee(t.onSuccess(r))})),Dt=p(2,(e,t)=>{let r=new De(Ko);return r.effect_instruction_i0=e,r.effect_instruction_i1=t.onFailure,r.effect_instruction_i2=t.onSuccess,r}),mi=p(2,(e,t)=>Dt(e,{onFailure:(r)=>{if(Qp(r).length>0)return Ye(Yy(r));let o=Zp(r);if(o.length>0)return t.onFailure(Mp(o));return Ye(r)},onSuccess:t.onSuccess})),qt=p(2,(e,t)=>fe(()=>{let r=pe(e),n=no(r.length),o=0;return zr(Us({while:()=>o<r.length,body:()=>t(r[o],o),step:(i)=>{n[o++]=i}}),n)})),So=p(2,(e,t)=>fe(()=>{let r=pe(e),n=0;return Us({while:()=>n<r.length,body:()=>t(r[n],n),step:()=>{n++}})}));var Vc=(e)=>{let t=new De(ro);return t.effect_instruction_i0=oS(Kr),t.effect_instruction_i1=()=>e,t};var we=p(2,(e,t)=>L(e,(r)=>C(()=>t(r)))),Jc=p(2,(e,t)=>mi(e,{onFailure:(r)=>rd(()=>t.onFailure(r)),onSuccess:(r)=>C(()=>t.onSuccess(r))})),bo=p(2,(e,t)=>Dt(e,{onFailure:(r)=>{let n=Sc(r);switch(n._tag){case"Left":return rd(()=>t(n.left));case"Right":return Ye(n.right)}},onSuccess:ee}));var hi=p(2,(e,t)=>Rn((r)=>Dt(r(e),{onFailure:(n)=>{let o=ae(n);return Dt(t(o),{onFailure:(i)=>ae(Ge(n,i)),onSuccess:()=>o})},onSuccess:(n)=>{let o=ge(n);return vn(t(o),o)}}))),qs=p(2,(e,t)=>hi(e,il({onFailure:(r)=>si(r)?Vr(t(Xp(r))):ve,onSuccess:()=>ve})));var ee=(e)=>{let t=new Xf(ut);return t.effect_instruction_i0=e,t},fe=(e)=>{let t=new De(to);return t.commit=e,t},C=(e)=>{let t=new De(Ja);return t.effect_instruction_i0=e,t},Gc=p((e)=>e.length===3||e.length===2&&!(ot(e[1])&&("onlyEffect"in e[1])),(e,t)=>L(e,(r)=>{let n=typeof t==="function"?t(r):t;if(di(n))return zr(n,r);else if(Eg(n))return Ns((o)=>{n.then((i)=>o(ee(r)),(i)=>o(qe(new mv(i,"An unknown error occurred in Effect.tap"))))});return ee(r)})),id=(e)=>We((t)=>{let r=t.getFiberRef(Bc),n=m(r,ce(()=>t.scope()));return e(Cn(Bc,I(n)))});var Yc=(e)=>{let t=new De(ro);return t.effect_instruction_i0=Bf(Kr),t.effect_instruction_i1=()=>e,t},Rn=(e)=>ed(e,function(){let t=new De(ro);return t.effect_instruction_i0=Bf(Kr),t.effect_instruction_i1=(r)=>qf(r)?Ke(()=>this.effect_instruction_i0(Vc)):Ke(()=>this.effect_instruction_i0(Yc)),t}),ve=ee(void 0);var sd=(e)=>{let t=new De(ro);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t};var Us=(e)=>{let t=new De(Wo);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t};var Hs=(e)=>{let t=new De(Vo);return typeof e?.priority<"u"?LS(t,e.priority):t},Zc=p(2,(e,t)=>L(e,(r)=>we(t,(n)=>[r,n])));var Qc=p(2,(e,t)=>L(e,(r)=>zr(t,r))),vn=p(2,(e,t)=>L(e,()=>t));var js=ES(()=>{let e=setInterval(()=>{},2147483647);return C(()=>clearInterval(e))}),kS=(e)=>L(nd,(t)=>m(e,$s(t))),$s=p(2,(e,t)=>L(e.interruptAsFork(t),()=>e.await)),AS={_tag:"All",syslog:0,label:"ALL",ordinal:Number.MIN_SAFE_INTEGER,pipe(){return y(this,arguments)}},IS={_tag:"Fatal",syslog:2,label:"FATAL",ordinal:50000,pipe(){return y(this,arguments)}},RS={_tag:"Error",syslog:3,label:"ERROR",ordinal:40000,pipe(){return y(this,arguments)}},ad={_tag:"Warning",syslog:4,label:"WARN",ordinal:30000,pipe(){return y(this,arguments)}},cd={_tag:"Info",syslog:6,label:"INFO",ordinal:20000,pipe(){return y(this,arguments)}},ld={_tag:"Debug",syslog:7,label:"DEBUG",ordinal:1e4,pipe(){return y(this,arguments)}},vS={_tag:"Trace",syslog:7,label:"TRACE",ordinal:0,pipe(){return y(this,arguments)}},CS={_tag:"None",syslog:7,label:"OFF",ordinal:Number.MAX_SAFE_INTEGER,pipe(){return y(this,arguments)}};var av="effect/FiberRef",cv=Symbol.for(av),lv={_A:(e)=>e},Xc=(e)=>We((t)=>ge(t.getFiberRef(e)));var _o=p(2,(e,t)=>L(Xc(e),t)),Jf=p(2,(e,t)=>uv(e,()=>[void 0,t]));var uv=p(2,(e,t)=>We((r)=>{let[n,o]=t(r.getFiberRef(e));return r.setFiberRef(e,o),ee(n)}));var Cn=p(3,(e,t,r)=>wS(Qc(Xc(t),Jf(t,r)),()=>e,(n)=>Jf(t,n)));var ze=(e,t)=>wo(e,{differ:Nc(),fork:t?.fork??Q,join:t?.join}),PS=(e)=>{let t=vf();return wo(e,{differ:t,fork:t.empty})},pv=(e)=>{let t=Cf(Nc());return wo(e,{differ:t,fork:t.empty})},el=(e)=>{let t=Rf();return wo(e,{differ:t,fork:t.empty})},wo=(e,t)=>({...pn,[cv]:lv,initial:e,commit(){return Xc(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)}),FS=(e)=>wo(e,{differ:jf,fork:jf.empty}),Eo=N(Symbol.for("effect/FiberRef/currentContext"),()=>el(wn())),gi=N(Symbol.for("effect/FiberRef/currentSchedulingPriority"),()=>ze(0)),ud=N(Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"),()=>ze(2048)),NS=N(Symbol.for("effect/FiberRef/currentLogAnnotation"),()=>ze(li())),pd=N(Symbol.for("effect/FiberRef/currentLogLevel"),()=>ze(cd)),MS=N(Symbol.for("effect/FiberRef/currentLogSpan"),()=>ze(On())),LS=p(2,(e,t)=>Cn(e,gi,t));var DS=N(Symbol.for("effect/FiberRef/currentConcurrency"),()=>ze("unbounded")),qS=N(Symbol.for("effect/FiberRef/currentRequestBatching"),()=>ze(!0)),US=N(Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"),()=>ze(I(ld))),HS=N(Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"),()=>ze(I(ad)));var Bs=N(Symbol.for("effect/FiberRef/currentMetricLabels"),()=>pv(Mr()));var Bc=N(Symbol.for("effect/FiberRef/currentForkScopeOverride"),()=>ze(w(),{fork:()=>w(),join:(e,t)=>e})),Ks=N(Symbol.for("effect/FiberRef/currentInterruptedCause"),()=>ze(jr,{fork:()=>jr,join:(e,t)=>e}));var tl=Symbol.for("effect/Scope"),rl=Symbol.for("effect/CloseableScope"),nl=(e,t)=>e.addFinalizer(()=>Vr(t));var fd=(e,t)=>e.close(t),yi=(e,t)=>e.fork(t);var ol=function(){class e extends globalThis.Error{commit(){return qe(this)}toJSON(){let t={...this};if(this.message)t.message=this.message;if(this.cause)t.cause=this.cause;return t}[J](){if(this.toString!==globalThis.Error.prototype.toString)return this.stack?`${this.toString()}
25
+ `)}return t},lx=(e)=>_(e,lf);var ux=(e)=>_(e,_s),MI=En(new Map),px=()=>MI,uf=(e,t)=>En(new Map([[e.key,t]])),fx=p(3,(e,t,r)=>{let n=new Map(e.unsafeMap);return n.set(t.key,r),En(n)}),cf=M("effect/Context/defaultValueCache",()=>new Map),pf=(e)=>{if(cf.has(e.key))return cf.get(e.key);let t=e.defaultValue();return cf.set(e.key,t),t},dx=(e,t)=>e.unsafeMap.has(t.key)?e.unsafeMap.get(t.key):pf(t),ff=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key)){if(_s in t)return pf(t);throw NI(t)}return e.unsafeMap.get(t.key)}),mx=ff;var hx=p(2,(e,t)=>{if(!e.unsafeMap.has(t.key))return ux(t)?ps(pf(t)):Xa;return ps(e.unsafeMap.get(t.key))}),gx=p(2,(e,t)=>{let r=new Map(e.unsafeMap);for(let[n,o]of t.unsafeMap)r.set(n,o);return En(r)});var xt=ax;var On=px,xx=uf,gr=fx,ws=mx;var Es=ff,Tn=hx,Os=gx;var Ts=cx;var mf=Symbol.for("effect/Duration"),Ex=BigInt(0),Sx=BigInt(24),Tc=BigInt(60),hf=BigInt(1000),bx=BigInt(1e6),_x=BigInt(1e9),LI=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,Kr=(e)=>{if(Ox(e))return e;else if(kt(e))return kc(e);else if(un(e))return df(e);else if(Array.isArray(e)&&e.length===2&&e.every(kt)){if(e[0]===-1/0||e[1]===-1/0||Number.isNaN(e[0])||Number.isNaN(e[1]))return gf;if(e[0]===1/0||e[1]===1/0)return HI;return df(BigInt(Math.round(e[0]*1e9))+BigInt(Math.round(e[1])))}else if(Ke(e)){let t=LI.exec(e);if(t){let[r,n,o]=t,i=Number(n);switch(o){case"nano":case"nanos":return df(BigInt(n));case"micro":case"micros":return jI(BigInt(n));case"milli":case"millis":return kc(i);case"second":case"seconds":return $I(i);case"minute":case"minutes":return BI(i);case"hour":case"hours":return KI(i);case"day":case"days":return WI(i);case"week":case"weeks":return zI(i)}}}throw Error("Invalid DurationInput")};var wx={_tag:"Millis",millis:0},DI={_tag:"Infinity"},qI={[mf]:mf,[T](){return Q(this,Ja(this.value))},[O](e){return Ox(e)&&ZI(this,e)},toString(){return`Duration(${XI(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:JI(this)};case"Infinity":return{_id:"Duration",_tag:"Infinity"}}},[Z](){return this.toJSON()},pipe(){return y(this,arguments)}},yr=(e)=>{let t=Object.create(qI);if(kt(e))if(isNaN(e)||e<=0)t.value=wx;else if(!Number.isFinite(e))t.value=DI;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<=Ex)t.value=wx;else t.value={_tag:"Nanos",nanos:e};return t},Ox=(e)=>_(e,mf);var UI=(e)=>{switch(e.value._tag){case"Millis":return e.value.millis===0;case"Nanos":return e.value.nanos===Ex;case"Infinity":return!1}},gf=yr(0),HI=yr(1/0),df=(e)=>yr(e),jI=(e)=>yr(e*hf),kc=(e)=>yr(e),$I=(e)=>yr(e*1000),BI=(e)=>yr(e*60000),KI=(e)=>yr(e*3600000),WI=(e)=>yr(e*86400000),zI=(e)=>yr(e*604800000),Ac=(e)=>GI(e,{onMillis:(t)=>t,onNanos:(t)=>Number(t)/1e6});var VI=(e)=>{let t=Kr(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))}},JI=(e)=>{let t=Kr(e);switch(t.value._tag){case"Infinity":return[1/0,0];case"Nanos":return[Number(t.value.nanos/_x),Number(t.value.nanos%_x)];case"Millis":return[Math.floor(t.value.millis/1000),Math.round(t.value.millis%1000*1e6)]}},GI=p(2,(e,t)=>{let r=Kr(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)}}),yf=p(3,(e,t,r)=>{let n=Kr(e),o=Kr(t);if(n.value._tag==="Infinity"||o.value._tag==="Infinity")return r.onMillis(Ac(n),Ac(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 YI=(e,t)=>yf(e,t,{onMillis:(r,n)=>r===n,onNanos:(r,n)=>r===n});var Tx=p(2,(e,t)=>yf(e,t,{onMillis:(r,n)=>r<=n,onNanos:(r,n)=>r<=n}));var kx=p(2,(e,t)=>yf(e,t,{onMillis:(r,n)=>r>=n,onNanos:(r,n)=>r>=n})),ZI=p(2,(e,t)=>YI(Kr(e),Kr(t))),QI=(e)=>{let t=Kr(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=VI(t),n=r/bx,o=n/hf,i=o/Tc,s=i/Tc,a=s/Sx;return{days:Number(a),hours:Number(s%Sx),minutes:Number(i%Tc),seconds:Number(o%Tc),millis:Number(n%hf),nanos:Number(r%bx)}},XI=(e)=>{let t=Kr(e);if(t.value._tag==="Infinity")return"Infinity";if(UI(t))return"0";let r=QI(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 Ix=Symbol.for("effect/MutableRef"),ev={[Ix]:Ix,toString(){return ie(this.toJSON())},toJSON(){return{_id:"MutableRef",current:re(this.current)}},[Z](){return this.toJSON()},pipe(){return y(this,arguments)}},Ic=(e)=>{let t=Object.create(ev);return t.current=e,t};var ui=(e)=>e.current;var vc=p(2,(e,t)=>(e.current=t,e));var Sf="effect/FiberId",pi=Symbol.for(Sf),Rc="None",xf="Runtime",tv="Composite",rv=oe(`${Sf}-${Rc}`);class Cx{[pi]=pi;_tag=Rc;id=-1;startTimeMillis=-1;[T](){return rv}[O](e){return bf(e)&&e._tag===Rc}toString(){return ie(this.toJSON())}toJSON(){return{_id:"FiberId",_tag:this._tag}}[Z](){return this.toJSON()}}class Px{id;startTimeMillis;[pi]=pi;_tag=xf;constructor(e,t){this.id=e,this.startTimeMillis=t}[T](){return Q(this,oe(`${Sf}-${this._tag}-${this.id}-${this.startTimeMillis}`))}[O](e){return bf(e)&&e._tag===xf&&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}}[Z](){return this.toJSON()}}var Fx=new Cx;var bf=(e)=>_(e,pi);var Cc=(e)=>{switch(e._tag){case Rc:return hr();case xf:return po(e.id);case tv:return m(Cc(e.left),$r(Cc(e.right)))}},Rx=M(Symbol.for("effect/Fiber/Id/_fiberCounter"),()=>Ic(0));var Pc=(e)=>Array.from(Cc(e)).map((r)=>`#${r}`).join(",");var Nx=()=>{let e=ui(Rx);return m(Rx,vc(e+1)),new Px(e,Date.now())};var Dt=Fx;var Lx=Pc;var Fc=Nx;var fi=ri;var Dx=Cy,qx=Fy,_f=Ny;var wf=uo,Ef=fc;var Ux=mc;var Hx=Dy;var Of=ni;var As=Symbol.for("effect/List"),kf=(e)=>fe(e),nv=(e)=>ip(gn(e),kf),ov=nv(b),iv={[As]:As,_tag:"Cons",toString(){return ie(this.toJSON())},toJSON(){return{_id:"List",_tag:"Cons",values:kf(this).map(re)}},[Z](){return this.toJSON()},[O](e){return $x(e)&&this._tag===e._tag&&ov(this,e)},[T](){return Q(this,At(kf(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 y(this,arguments)}},Nc=(e,t)=>{let r=Object.create(iv);return r.head=e,r.tail=t,r},sv=oe("Nil"),av={[As]:As,_tag:"Nil",toString(){return ie(this.toJSON())},toJSON(){return{_id:"List",_tag:"Nil"}},[Z](){return this.toJSON()},[T](){return sv},[O](e){return $x(e)&&this._tag===e._tag},[Symbol.iterator](){return{next(){return{done:!0,value:void 0}}}},pipe(){return y(this,arguments)}},jx=Object.create(av),$x=(e)=>_(e,As),xr=(e)=>e._tag==="Nil",Af=(e)=>e._tag==="Cons";var cv=()=>jx,Wr=(e,t)=>Nc(e,t),kn=cv,Is=(e)=>Nc(e,jx);var Bx=p(2,(e,t)=>uv(t,e)),lv=p(2,(e,t)=>Wr(t,e)),uv=p(2,(e,t)=>{if(xr(e))return t;else if(xr(t))return e;else{let r=Nc(t.head,e),n=r,o=t.tail;while(!xr(o)){let i=Nc(o.head,e);n.tail=i,n=i,o=o.tail}return r}});var Kx=p(3,(e,t,r)=>{let n=t,o=e;while(!xr(o))n=r(n,o.head),o=o.tail;return n});var Wx=(e)=>{let t=kn(),r=e;while(!xr(r))t=lv(t,r.head),r=r.tail;return t};var Kq=Object.assign(Object.create(Array.prototype),{[T](){return Q(this,At(this))},[O](e){if(Array.isArray(e)&&this.length===e.length)return this.every((t,r)=>b(t,e[r]));else return!1}}),di=function(){function e(t){if(t)Object.assign(this,t)}return e.prototype=us,e}();var fv=Symbol.for("effect/DifferContextPatch");function zx(e){return e}var Rs={...di.prototype,[fv]:{_Value:zx,_Patch:zx}},dv=Object.assign(Object.create(Rs),{_tag:"Empty"}),mv=Object.create(dv),vf=()=>mv,hv=Object.assign(Object.create(Rs),{_tag:"AndThen"}),gv=(e,t)=>{let r=Object.create(hv);return r.first=e,r.second=t,r},yv=Object.assign(Object.create(Rs),{_tag:"AddService"}),xv=(e,t)=>{let r=Object.create(yv);return r.key=e,r.service=t,r},Sv=Object.assign(Object.create(Rs),{_tag:"RemoveService"}),bv=(e)=>{let t=Object.create(Sv);return t.key=e,t},_v=Object.assign(Object.create(Rs),{_tag:"UpdateService"}),wv=(e,t)=>{let r=Object.create(_v);return r.key=e,r.update=t,r},Vx=(e,t)=>{let r=new Map(e.unsafeMap),n=vf();for(let[o,i]of t.unsafeMap.entries())if(r.has(o)){let s=r.get(o);if(r.delete(o),!b(s,i))n=vs(wv(o,()=>i))(n)}else r.delete(o),n=vs(xv(o,i))(n);for(let[o]of r.entries())n=vs(bv(o))(n);return n},vs=p(2,(e,t)=>gv(e,t)),Jx=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=!1,n=Pe(e),o=new Map(t.unsafeMap);while(Xt(n)){let s=er(n),a=tr(n);switch(s._tag){case"Empty":{n=a;break}case"AddService":{o.set(s.key,s.service),n=a;break}case"AndThen":{n=Ge(Ge(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 En(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 En(i)});var Ov=Symbol.for("effect/DifferHashSetPatch");function Rf(e){return e}var Lc={...di.prototype,[Ov]:{_Value:Rf,_Key:Rf,_Patch:Rf}},Tv=Object.assign(Object.create(Lc),{_tag:"Empty"}),kv=Object.create(Tv),Cf=()=>kv,Av=Object.assign(Object.create(Lc),{_tag:"AndThen"}),Iv=(e,t)=>{let r=Object.create(Av);return r.first=e,r.second=t,r},vv=Object.assign(Object.create(Lc),{_tag:"Add"}),Rv=(e)=>{let t=Object.create(vv);return t.value=e,t},Cv=Object.assign(Object.create(Lc),{_tag:"Remove"}),Pv=(e)=>{let t=Object.create(Cv);return t.value=e,t},Gx=(e,t)=>{let[r,n]=mo([e,Cf()],([o,i],s)=>{if(Yy(s)(o))return[Gp(s)(o),i];return[o,Mc(Rv(s))(i)]})(t);return mo(n,(o,i)=>Mc(Pv(i))(o))(r)},Mc=p(2,(e,t)=>Iv(e,t)),Yx=p(2,(e,t)=>{if(e._tag==="Empty")return t;let r=t,n=Pe(e);while(Xt(n)){let o=er(n),i=tr(n);switch(o._tag){case"Empty":{n=i;break}case"AndThen":{n=Ge(o.first)(Ge(o.second)(i));break}case"Add":{r=fo(o.value)(r),n=i;break}case"Remove":r=Gp(o.value)(r),n=i}}return r});var Nv=Symbol.for("effect/DifferReadonlyArrayPatch");function Zx(e){return e}var Ps={...di.prototype,[Nv]:{_Value:Zx,_Patch:Zx}},Mv=Object.assign(Object.create(Ps),{_tag:"Empty"}),Lv=Object.create(Mv),Pf=()=>Lv,Dv=Object.assign(Object.create(Ps),{_tag:"AndThen"}),qv=(e,t)=>{let r=Object.create(Dv);return r.first=e,r.second=t,r},Uv=Object.assign(Object.create(Ps),{_tag:"Append"}),Hv=(e)=>{let t=Object.create(Uv);return t.values=e,t},jv=Object.assign(Object.create(Ps),{_tag:"Slice"}),$v=(e,t)=>{let r=Object.create(jv);return r.from=e,r.until=t,r},Bv=Object.assign(Object.create(Ps),{_tag:"Update"}),Kv=(e,t)=>{let r=Object.create(Bv);return r.index=e,r.patch=t,r},Qx=(e)=>{let t=0,r=Pf();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(!b(i,e.differ.empty))r=Cs(r,Kv(t,i));t=t+1}if(t<e.oldValue.length)r=Cs(r,$v(0,t));if(t<e.newValue.length)r=Cs(r,Hv(dy(t)(e.newValue)));return r},Cs=p(2,(e,t)=>qv(e,t)),Xx=p(3,(e,t,r)=>{if(e._tag==="Empty")return t;let n=t.slice(),o=Je(e);while(mn(o)){let i=Ce(o),s=Zt(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 eS=Symbol.for("effect/Differ"),zv={[eS]:{_P:te,_V:te},pipe(){return y(this,arguments)}},An=(e)=>{let t=Object.create(zv);return t.empty=e.empty,t.diff=e.diff,t.combine=e.combine,t.patch=e.patch,t},Ff=()=>An({empty:vf(),combine:(e,t)=>vs(t)(e),diff:(e,t)=>Vx(e,t),patch:(e,t)=>Jx(t)(e)});var Nf=()=>An({empty:Cf(),combine:(e,t)=>Mc(t)(e),diff:(e,t)=>Gx(e,t),patch:(e,t)=>Yx(t)(e)});var Mf=(e)=>An({empty:Pf(),combine:(t,r)=>Cs(t,r),diff:(t,r)=>Qx({oldValue:t,newValue:r,differ:e}),patch:(t,r)=>Xx(t,r,e)});var Dc=()=>tS((e,t)=>t),tS=(e)=>An({empty:te,combine:(t,r)=>{if(t===te)return r;if(r===te)return t;return(n)=>r(t(n))},diff:(t,r)=>{if(b(t,r))return te;return Gi(r)},patch:(t,r)=>e(r,t(r))});var Fs=255,rS=8,qc=(e)=>e&Fs,Uc=(e)=>e>>rS&Fs,_o=(e,t)=>(e&Fs)+((t&e&Fs)<<rS),Df=_o(0,0),nS=(e)=>_o(e,e),oS=(e)=>_o(e,0);var iS=p(2,(e,t)=>_o(qc(e)&~t,Uc(e)));var qf=p(2,(e,t)=>e|t);var sS=(e)=>~e>>>0&Fs;var Vv=0,zr=1,cS=2,Uf=4,Hc=16,Hf=32;var lS=(e)=>jc(e,Hf);var jf=p(2,(e,t)=>e|t);var Vr=(e)=>$f(e)&&!Jv(e),$f=(e)=>jc(e,zr);var jc=p(2,(e,t)=>(e&t)!==0),Bf=(...e)=>e.reduce((t,r)=>t|r,0),uS=Bf(Vv);var Kf=(e)=>jc(e,Uf);var Jv=(e)=>jc(e,Hc);var Ns=p(2,(e,t)=>_o(e^t,t)),Ms=p(2,(e,t)=>e&(sS(qc(t))|Uc(t))|qc(t)&Uc(t));var Wf=An({empty:Df,diff:(e,t)=>Ns(e,t),combine:(e,t)=>qf(t)(e),patch:(e,t)=>Ms(t,e)});var pS=nS,Vf=oS;var Jf=iS;var Yf=(e,t)=>({_tag:"Par",left:e,right:t}),$c=(e,t)=>({_tag:"Seq",left:e,right:t});var dS=(e)=>{let t=Is(e),r=kn();while(!0){let[n,o]=Kx(t,[mS(),kn()],([i,s],a)=>{let[c,l]=Gv(a);return[eR(i,c),Bx(s,l)]});if(r=Yv(r,n),xr(o))return Wx(r);t=o}throw Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues")},Gv=(e)=>{let t=e,r=mS(),n=kn(),o=kn();while(!0)switch(t._tag){case"Empty":{if(xr(n))return[r,o];t=n.head,n=n.tail;break}case"Par":{n=Wr(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($c(a,s),$c(c,s));break}case"Seq":{let{left:a,right:c}=i;t=$c(a,$c(c,s));break}case"Single":{t=i,o=Wr(s,o);break}}break}case"Single":{if(r=Xv(r,t),xr(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")},Yv=(e,t)=>{if(xr(e))return Is(Gf(t));if(tR(t))return e;let r=aR(e.head),n=rR(t);if(r.length===1&&n.length===1&&b(r[0],n[0]))return Wr(sR(e.head,Gf(t)),e.tail);return Wr(Gf(t),e)};var Zv=Symbol.for("effect/RequestBlock/RequestBlockParallel"),Qv={_R:(e)=>e};class Bc{map;[Zv]=Qv;constructor(e){this.map=e}}var mS=()=>new Bc(fi());var Xv=(e,t)=>new Bc(Ux(e.map,t.dataSource,(r)=>ty(Gt(r,by(t.blockedRequest)),()=>Pe(t.blockedRequest)))),eR=(e,t)=>new Bc(Of(e.map,t.map,(r,n,o)=>wf(r,o,Oe(_f(r,o),{onNone:()=>n,onSome:(i)=>It(n,i)})))),tR=(e)=>qx(e.map),rR=(e)=>Array.from(Ef(e.map)),Gf=(e)=>iR(Hx(e.map,(t)=>Pe(t))),nR=Symbol.for("effect/RequestBlock/RequestBlockSequential"),oR={_R:(e)=>e};class Zf{map;[nR]=oR;constructor(e){this.map=e}}var iR=(e)=>new Zf(e),sR=(e,t)=>new Zf(Of(t.map,e.map,(r,n,o)=>wf(r,o,Oe(_f(r,o),{onNone:()=>Mt(),onSome:(i)=>It(i,n)}))));var aR=(e)=>Array.from(Ef(e.map)),hS=(e)=>Array.from(e.map);var mi="Pending",Kc="Done";var lR="effect/Deferred",yS=Symbol.for(lR),xS={_E:(e)=>e,_A:(e)=>e},SS=(e)=>({_tag:mi,joiners:e}),bS=(e)=>({_tag:Kc,effect:e});class hi{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 hi(this.self)}}var Vc=(e,t)=>{let r=new je("Blocked");return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r},ed=(e)=>{let t=new je("RunBlocked");return t.effect_instruction_i0=e,t},In=Symbol.for("effect/Effect");class td{patch;op;_op=cs;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;[In]=fn;constructor(e){this._op=e}[O](e){return this===e}[T](){return Q(this,ns(this))}pipe(){return y(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())}[Z](){return this.toJSON()}[Symbol.iterator](){return new hi(new Rr(this))}}class rd{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[In]=fn;constructor(e){this._op=e,this._tag=e}[O](e){return _i(e)&&e._op==="Failure"&&b(this.effect_instruction_i0,e.effect_instruction_i0)}[T](){return m(oe(this._tag),H(S(this.effect_instruction_i0)),Q(this))}get cause(){return this.effect_instruction_i0}pipe(){return y(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,cause:this.cause.toJSON()}}toString(){return ie(this.toJSON())}[Z](){return this.toJSON()}[Symbol.iterator](){return new hi(new Rr(this))}}class nd{_op;effect_instruction_i0=void 0;effect_instruction_i1=void 0;effect_instruction_i2=void 0;trace=void 0;[In]=fn;constructor(e){this._op=e,this._tag=e}[O](e){return _i(e)&&e._op==="Success"&&b(this.effect_instruction_i0,e.effect_instruction_i0)}[T](){return m(oe(this._tag),H(S(this.effect_instruction_i0)),Q(this))}get value(){return this.effect_instruction_i0}pipe(){return y(this,arguments)}toJSON(){return{_id:"Exit",_tag:this._op,value:re(this.value)}}toString(){return ie(this.toJSON())}[Z](){return this.toJSON()}[Symbol.iterator](){return new hi(new Rr(this))}}var gi=(e)=>_(e,In),ze=(e)=>{let t=new je(Qa);return t.effect_instruction_i0=e,t},vS=p(3,(e,t,r)=>Cn((n)=>L(e,(o)=>L(Rn(de(()=>n(t(o)))),(i)=>de(()=>r(o,i)).pipe(qt({onFailure:(s)=>{switch(i._tag){case mt:return Ze(Ye(i.effect_instruction_i0,s));case ht:return Ze(s)}},onSuccess:()=>i})))))),Jr=p(2,(e,t)=>L(e,()=>ne(t))),Gr=(e)=>Jr(e,void 0),od=function(){let e=new je(io);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(to("you're not supposed to end up here"))}return e},Ls=(e,t=Dt)=>{let r=new je(oo),n=void 0;return r.effect_instruction_i0=(o)=>{n=e(o)},r.effect_instruction_i1=t,Hs(r,(o)=>gi(n)?n:Fe)},RS=(e,t=Dt)=>de(()=>Ls(e,t)),vn=(e,t=Dt)=>od(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(oo);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=We(()=>this.effect_instruction_i0(o,a.signal));else s=We(()=>this.effect_instruction_i0(o));return s||a?Hs(i,(c)=>{if(a)a.abort();return s??Fe}):i});var Ds=p(2,(e,t)=>yi(e,{onFailure:t,onSuccess:ne}));var _S=Symbol.for("effect/OriginalAnnotation");var Jc=(e,t)=>{if(pe(t))return new Proxy(e,{has(r,n){return n===So||n===_S||n in r},get(r,n){if(n===So)return t.value;if(n===_S)return e;return r[n]}});return e},Gc=(e)=>at(e)&&!(So in e)?ze((t)=>Ze(vt(Jc(e,pl(t))))):Ze(vt(e)),id=(e)=>CS(()=>vt(new xR(e)));var wo=(e)=>yi(e,{onFailure:(t)=>ne(U(t)),onSuccess:(t)=>ne(K(t))}),Rn=(e)=>PS(e,{onFailure:ce,onSuccess:xe}),$e=(e)=>at(e)&&!(So in e)?ze((t)=>Ze(ci(Jc(e,pl(t))))):Ze(ci(e)),sd=(e)=>L(F(e),$e),Ze=(e)=>{let t=new rd(mt);return t.effect_instruction_i0=e,t},CS=(e)=>L(F(e),Ze),ad=ze((e)=>ne(e.id())),qs=(e)=>ze((t)=>e(t.id())),L=p(2,(e,t)=>{let r=new je(zo);return r.effect_instruction_i0=e,r.effect_instruction_i1=t,r});var cd=(e)=>{let t=new je("OnStep");return t.effect_instruction_i0=e,t},Us=(e)=>L(e,te);var PS=p(2,(e,t)=>qt(e,{onFailure:(r)=>ne(t.onFailure(r)),onSuccess:(r)=>ne(t.onSuccess(r))})),qt=p(2,(e,t)=>{let r=new je(Vo);return r.effect_instruction_i0=e,r.effect_instruction_i1=t.onFailure,r.effect_instruction_i2=t.onSuccess,r}),yi=p(2,(e,t)=>qt(e,{onFailure:(r)=>{if(rf(r).length>0)return Ze(nx(r));let o=tf(r);if(o.length>0)return t.onFailure(Up(o));return Ze(r)},onSuccess:t.onSuccess})),Ut=p(2,(e,t)=>de(()=>{let r=fe(e),n=ao(r.length),o=0;return Jr(js({while:()=>o<r.length,body:()=>t(r[o],o),step:(i)=>{n[o++]=i}}),n)})),Eo=p(2,(e,t)=>de(()=>{let r=fe(e),n=0;return js({while:()=>n<r.length,body:()=>t(r[n],n),step:()=>{n++}})}));var Yc=(e)=>{let t=new je(so);return t.effect_instruction_i0=pS(zr),t.effect_instruction_i1=()=>e,t};var Ee=p(2,(e,t)=>L(e,(r)=>F(()=>t(r)))),Zc=p(2,(e,t)=>yi(e,{onFailure:(r)=>sd(()=>t.onFailure(r)),onSuccess:(r)=>F(()=>t.onSuccess(r))})),Oo=p(2,(e,t)=>qt(e,{onFailure:(r)=>{let n=wc(r);switch(n._tag){case"Left":return sd(()=>t(n.left));case"Right":return Ze(n.right)}},onSuccess:ne}));var xi=p(2,(e,t)=>Cn((r)=>qt(r(e),{onFailure:(n)=>{let o=ce(n);return qt(t(o),{onFailure:(i)=>ce(Ye(n,i)),onSuccess:()=>o})},onSuccess:(n)=>{let o=xe(n);return Pn(t(o),o)}}))),Hs=p(2,(e,t)=>xi(e,cl({onFailure:(r)=>li(r)?Gr(t(nf(r))):Fe,onSuccess:()=>Fe})));var ne=(e)=>{let t=new nd(ht);return t.effect_instruction_i0=e,t},de=(e)=>{let t=new je(io);return t.commit=e,t},F=(e)=>{let t=new je(Za);return t.effect_instruction_i0=e,t},Qc=p((e)=>e.length===3||e.length===2&&!(at(e[1])&&("onlyEffect"in e[1])),(e,t)=>L(e,(r)=>{let n=typeof t==="function"?t(r):t;if(gi(n))return Jr(n,r);else if(Rg(n))return Ls((o)=>{n.then((i)=>o(ne(r)),(i)=>o($e(new bR(i,"An unknown error occurred in Effect.tap"))))});return ne(r)})),ld=(e)=>ze((t)=>{let r=t.getFiberRef(zc),n=m(r,ue(()=>t.scope()));return e(Fn(zc,R(n)))});var Xc=(e)=>{let t=new je(so);return t.effect_instruction_i0=Vf(zr),t.effect_instruction_i1=()=>e,t},Cn=(e)=>od(e,function(){let t=new je(so);return t.effect_instruction_i0=Vf(zr),t.effect_instruction_i1=(r)=>$f(r)?We(()=>this.effect_instruction_i0(Yc)):We(()=>this.effect_instruction_i0(Xc)),t}),Fe=ne(void 0);var ud=(e)=>{let t=new je(so);return t.effect_instruction_i0=e,t.effect_instruction_i1=void 0,t};var js=(e)=>{let t=new je(Jo);return t.effect_instruction_i0=e.while,t.effect_instruction_i1=e.body,t.effect_instruction_i2=e.step,t};var $s=(e)=>{let t=new je(Yo);return typeof e?.priority<"u"?BS(t,e.priority):t},el=p(2,(e,t)=>L(e,(r)=>Ee(t,(n)=>[r,n])));var tl=p(2,(e,t)=>L(e,(r)=>Jr(t,r))),Pn=p(2,(e,t)=>L(e,()=>t));var Bs=RS(()=>{let e=setInterval(()=>{},2147483647);return F(()=>clearInterval(e))}),FS=(e)=>L(ad,(t)=>m(e,Ks(t))),Ks=p(2,(e,t)=>L(e.interruptAsFork(t),()=>e.await)),NS={_tag:"All",syslog:0,label:"ALL",ordinal:Number.MIN_SAFE_INTEGER,pipe(){return y(this,arguments)}},MS={_tag:"Fatal",syslog:2,label:"FATAL",ordinal:50000,pipe(){return y(this,arguments)}},LS={_tag:"Error",syslog:3,label:"ERROR",ordinal:40000,pipe(){return y(this,arguments)}},pd={_tag:"Warning",syslog:4,label:"WARN",ordinal:30000,pipe(){return y(this,arguments)}},fd={_tag:"Info",syslog:6,label:"INFO",ordinal:20000,pipe(){return y(this,arguments)}},dd={_tag:"Debug",syslog:7,label:"DEBUG",ordinal:1e4,pipe(){return y(this,arguments)}},DS={_tag:"Trace",syslog:7,label:"TRACE",ordinal:0,pipe(){return y(this,arguments)}},qS={_tag:"None",syslog:7,label:"OFF",ordinal:Number.MAX_SAFE_INTEGER,pipe(){return y(this,arguments)}};var dR="effect/FiberRef",mR=Symbol.for(dR),hR={_A:(e)=>e},rl=(e)=>ze((t)=>xe(t.getFiberRef(e)));var To=p(2,(e,t)=>L(rl(e),t)),Qf=p(2,(e,t)=>gR(e,()=>[void 0,t]));var gR=p(2,(e,t)=>ze((r)=>{let[n,o]=t(r.getFiberRef(e));return r.setFiberRef(e,o),ne(n)}));var Fn=p(3,(e,t,r)=>vS(tl(rl(t),Qf(t,r)),()=>e,(n)=>Qf(t,n)));var Ve=(e,t)=>ko(e,{differ:Dc(),fork:t?.fork??te,join:t?.join}),US=(e)=>{let t=Nf();return ko(e,{differ:t,fork:t.empty})},yR=(e)=>{let t=Mf(Dc());return ko(e,{differ:t,fork:t.empty})},nl=(e)=>{let t=Ff();return ko(e,{differ:t,fork:t.empty})},ko=(e,t)=>({...dn,[mR]:hR,initial:e,commit(){return rl(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)}),HS=(e)=>ko(e,{differ:Wf,fork:Wf.empty}),Ao=M(Symbol.for("effect/FiberRef/currentContext"),()=>nl(On())),Si=M(Symbol.for("effect/FiberRef/currentSchedulingPriority"),()=>Ve(0)),md=M(Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"),()=>Ve(2048)),jS=M(Symbol.for("effect/FiberRef/currentLogAnnotation"),()=>Ve(fi())),hd=M(Symbol.for("effect/FiberRef/currentLogLevel"),()=>Ve(fd)),$S=M(Symbol.for("effect/FiberRef/currentLogSpan"),()=>Ve(kn())),BS=p(2,(e,t)=>Fn(e,Si,t));var KS=M(Symbol.for("effect/FiberRef/currentConcurrency"),()=>Ve("unbounded")),WS=M(Symbol.for("effect/FiberRef/currentRequestBatching"),()=>Ve(!0)),zS=M(Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"),()=>Ve(R(dd))),VS=M(Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"),()=>Ve(R(pd)));var Ws=M(Symbol.for("effect/FiberRef/currentMetricLabels"),()=>yR(Dr()));var zc=M(Symbol.for("effect/FiberRef/currentForkScopeOverride"),()=>Ve(w(),{fork:()=>w(),join:(e,t)=>e})),zs=M(Symbol.for("effect/FiberRef/currentInterruptedCause"),()=>Ve(Br,{fork:()=>Br,join:(e,t)=>e}));var ol=Symbol.for("effect/Scope"),il=Symbol.for("effect/CloseableScope"),sl=(e,t)=>e.addFinalizer(()=>Gr(t));var gd=(e,t)=>e.close(t),bi=(e,t)=>e.fork(t);var al=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}[Z](){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 er(ii(this),{renderErrorCause:!0});return this}}return Object.assign(e.prototype,pp),e}(),Oo=(e,t)=>{class r extends ol{_tag=t}return Object.assign(r.prototype,e),r.prototype.name=t,r},hS=Symbol.for("effect/Cause/errors/RuntimeException"),fv=Oo({[hS]:hS},"RuntimeException");var Gf=Symbol.for("effect/Cause/errors/InterruptedException"),p2=Oo({[Gf]:Gf},"InterruptedException"),jS=(e)=>_(e,Gf),gS=Symbol.for("effect/Cause/errors/IllegalArgument"),dv=Oo({[gS]:gS},"IllegalArgumentException");var yS=Symbol.for("effect/Cause/errors/NoSuchElement"),Ws=Oo({[yS]:yS},"NoSuchElementException");var xS=Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"),f2=Oo({[xS]:xS},"InvalidPubSubCapacityException"),SS=Symbol.for("effect/Cause/errors/ExceededCapacityException"),d2=Oo({[SS]:SS},"ExceededCapacityException");var bS=Symbol.for("effect/Cause/errors/Timeout"),m2=Oo({[bS]:bS},"TimeoutException");var _S=Symbol.for("effect/Cause/errors/UnknownException"),mv=function(){class e extends ol{_tag="UnknownException";error;constructor(t,r){super(r??"An unknown error occurred",{cause:t});this.error=t}}return Object.assign(e.prototype,{[_S]:_S,name:"UnknownException"}),e}();var xi=(e)=>di(e)&&("_tag"in e)&&(e._tag==="Success"||e._tag==="Failure");var dd=(e)=>e._tag==="Success";var $S=p(2,(e,t)=>{switch(e._tag){case lt:return ae(e.effect_instruction_i0);case ut:return ge(t)}}),zs=(e)=>$S(e,void 0);var To=(e,t)=>hv(e,t?.parallel?go:Ge),md=(e)=>ae(Ot(e));var Vs=(e)=>ae(ii(e)),ae=(e)=>{let t=new Qf(lt);return t.effect_instruction_i0=e,t};var hd=(e)=>ae(Xt(e)),$c=p(2,(e,t)=>{switch(e._tag){case lt:return ae(e.effect_instruction_i0);case ut:return ge(t(e.effect_instruction_i0))}});var il=p(2,(e,{onFailure:t,onSuccess:r})=>{switch(e._tag){case lt:return t(e.effect_instruction_i0);case ut:return r(e.effect_instruction_i0)}});var ge=(e)=>{let t=new Xf(ut);return t.effect_instruction_i0=e,t},Ut=ge(void 0);var gd=p(3,(e,t,{onFailure:r,onSuccess:n})=>{switch(e._tag){case lt:switch(t._tag){case ut:return ae(e.effect_instruction_i0);case lt:return ae(r(e.effect_instruction_i0,t.effect_instruction_i0))}case ut:switch(t._tag){case ut:return ge(n(e.effect_instruction_i0,t.effect_instruction_i0));case lt:return ae(t.effect_instruction_i0)}}}),hv=(e,t)=>{let r=rc(e);if(!Yt(r))return w();return m(Qt(r),Yo(m(Zt(r),$c(Re)),(n,o)=>m(n,gd(o,{onSuccess:(i,s)=>m(i,Je(s)),onFailure:t}))),$c(hn),$c((n)=>Dr(n)),I)},BS=(e)=>({...pn,[uS]:pS,state:Tc(fS([])),commit(){return sl(this)},blockingOn:e});var sl=(e)=>ES((t)=>{let r=ai(e.state);switch(r._tag){case jc:return t(r.effect);case pi:return r.joiners.push(t),gv(e,t)}},e.blockingOn);var al=(e,t)=>{let r=ai(e.state);if(r._tag===pi){kc(e.state,dS(t));for(let n=0,o=r.joiners.length;n<o;n++)r.joiners[n](t)}},gv=(e,t)=>C(()=>{let r=ai(e.state);if(r._tag===pi){let n=r.joiners.indexOf(t);if(n>=0)r.joiners.splice(n,1)}}),yv=We((e)=>ge(e.currentContext)),KS=()=>yv;var ko=(e)=>L(KS(),e),xv=p(2,(e,t)=>Cn(Eo,t)(e));var yd=p(2,(e,t)=>ko((r)=>xv(e,t(r))));var cl=(e)=>{let t=e.currentSpan;return t!==void 0&&t._tag==="Span"?I(t):w()};var WS=Jy;var zS=er;var ll="And",ul="Or",pl="InvalidData",fl="MissingData",dl="SourceUnavailable",ml="Unsupported";var _v="effect/ConfigError",VS=Symbol.for(_v),Si={_tag:"ConfigError",[VS]:VS},hl=(e,t)=>{let r=Object.create(Si);return r._op=ll,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},gl=(e,t)=>{let r=Object.create(Si);return r._op=ul,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},xd=(e,t,r={pathDelim:"."})=>{let n=Object.create(Si);return n._op=pl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Invalid data at ${m(this.path,Lr(r.pathDelim))}: "${this.message}")`}}),n},hr=(e,t,r={pathDelim:"."})=>{let n=Object.create(Si);return n._op=fl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Missing data at ${m(this.path,Lr(r.pathDelim))}: "${this.message}")`}}),n},Sd=(e,t,r,n={pathDelim:"."})=>{let o=Object.create(Si);return o._op=dl,o.path=e,o.message=t,o.cause=r,Object.defineProperty(o,"toString",{enumerable:!1,value(){return`(Source unavailable at ${m(this.path,Lr(n.pathDelim))}: "${this.message}")`}}),o},bd=(e,t,r={pathDelim:"."})=>{let n=Object.create(Si);return n._op=ml,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${m(this.path,Lr(r.pathDelim))}: "${this.message}")`}}),n};var Pn=p(2,(e,t)=>{switch(e._op){case ll:return hl(Pn(e.left,t),Pn(e.right,t));case ul:return gl(Pn(e.left,t),Pn(e.right,t));case pl:return xd([...t,...e.path],e.message);case fl:return hr([...t,...e.path],e.message);case dl:return Sd([...t,...e.path],e.message,e.cause);case ml:return bd([...t,...e.path],e.message)}});var JS=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._op){case ll:{n.push(s.right),n.push(s.left),o.push(U({_op:"AndCase"}));break}case ul:{n.push(s.right),n.push(s.left),o.push(U({_op:"OrCase"}));break}case pl:{o.push(B(r.invalidDataCase(t,s.path,s.message)));break}case fl:{o.push(B(r.missingDataCase(t,s.path,s.message)));break}case dl:{o.push(B(r.sourceUnavailableCase(t,s.path,s.message,s.cause)));break}case ml:{o.push(B(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 wv="effect/Clock",YS=Symbol.for(wv),Js=dt("effect/Clock"),Ev=2147483647,ZS={unsafeSchedule(e,t){let r=Oc(t);if(r>Ev)return an;let n=!1,o=setTimeout(()=>{n=!0,e()},r);return()=>(clearTimeout(o),!n)}},QS=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))}}(),Ov=function(){let e=typeof process==="object"&&"hrtime"in process&&typeof process.hrtime.bigint==="function"?process.hrtime:void 0;if(!e)return QS;let t=QS()-e.bigint();return()=>t+e.bigint()}();class XS{[YS]=YS;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return Ov()}currentTimeMillis=C(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=C(()=>this.unsafeCurrentTimeNanos());scheduler(){return ee(ZS)}sleep(e){return An((t)=>{let r=ZS.unsafeSchedule(()=>t(ve),e);return Vr(C(r))})}}var eb=()=>new XS;var gr=Vg;var bi=(e)=>e.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&");var nb={_tag:"Empty"};var xl=p(2,(e,t)=>{let r=ks(t),n=e;while(Ef(r)){let o=r.head;switch(o._tag){case"Empty":{r=r.tail;break}case"AndThen":{r=Br(o.first,Br(o.second,r.tail));break}case"MapName":{n=Gt(n,o.f),r=r.tail;break}case"Nested":{n=Jo(n,o.name),r=r.tail;break}case"Unnested":{if(m(Fr(n),Zg(o.name)))n=Jt(n),r=r.tail;else return U(hr(n,`Expected ${o.name} to be in path in ConfigProvider#unnested`));break}}}return B(n)});var ob="Constant",ib="Fail",sb="Fallback",ab="Described",cb="Lazy",lb="MapOrFail",ub="Nested",pb="Primitive",fb="Redacted",db="Sequence",mb="HashMap",hb="ZipWith";var Sl=(e,t)=>[...e,...t],Cv="effect/ConfigProvider",gb=Symbol.for(Cv),xb=dt("effect/ConfigProvider"),Pv="effect/ConfigProviderFlat",yb=Symbol.for(Pv),Fv=(e)=>({[gb]:gb,pipe(){return y(this,arguments)},...e}),Nv=(e)=>({[yb]:yb,patch:e.patch,load:(t,r,n=!0)=>e.load(t,r,n),enumerateChildren:e.enumerateChildren}),Mv=(e)=>Fv({load:(t)=>L(Tt(e,Mr(),t,!1),(r)=>Ee(Fr(r),{onNone:()=>qe(hr(Mr(),`Expected a single value having structure: ${t}`)),onSome:ee})),flattened:e}),Sb=(e)=>{let{pathDelim:t,seqDelim:r}=Object.assign({},{pathDelim:"_",seqDelim:","},e),n=(c)=>m(c,Lr(t)),o=(c)=>c.split(t),i=()=>typeof process<"u"&&("env"in process)&&typeof process.env==="object"?process.env:{};return Mv(Nv({load:(c,l,u=!0)=>{let f=n(c),d=i(),h=f in d?I(d[f]):w();return m(h,bo(()=>hr(c,`Expected ${f} to exist in the process context`)),L((g)=>$v(g,c,l,r,u)))},enumerateChildren:(c)=>C(()=>{let l=i(),d=Object.keys(l).map((h)=>o(h.toUpperCase())).filter((h)=>{for(let g=0;g<c.length;g++){let P=m(c,Ap(g)),x=h[g];if(x===void 0||P!==x)return!1}return!0}).flatMap((h)=>h.slice(c.length,c.length+1));return $y(d)}),patch:nb}))};var Lv=(e,t,r,n)=>{let o=Cp(r.length,(c)=>c>=n.length?w():I([e(c),c+1])),i=Cp(n.length,(c)=>c>=r.length?w():I([t(c),c+1])),s=Sl(r,o),a=Sl(n,i);return[s,a]},Dv=(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},qv={andCase:(e,t,r)=>hl(t,r),orCase:(e,t,r)=>gl(t,r),invalidDataCase:(e,t)=>xd(t,"<redacted>"),missingDataCase:(e,t)=>hr(t,"<redacted>"),sourceUnavailableCase:(e,t,r,n)=>Sd(t,"<redacted>",n),unsupportedCase:(e,t)=>bd(t,"<redacted>")},Uv=(e)=>JS(e,void 0,qv),Tt=(e,t,r,n)=>{let o=r;switch(o._tag){case ob:return ee(Ve(o.value));case ab:return fe(()=>Tt(e,t,o.config,n));case ib:return qe(hr(t,o.message));case sb:return m(fe(()=>Tt(e,t,o.first,n)),Ms((i)=>{if(o.condition(i))return m(Tt(e,t,o.second,n),Ms((s)=>qe(gl(i,s))));return qe(i)}));case cb:return fe(()=>Tt(e,t,o.config(),n));case lb:return fe(()=>m(Tt(e,t,o.original,n),L(qt((i)=>m(o.mapOrFail(i),bo(Pn(Dv(t,o.original))))))));case ub:return fe(()=>Tt(e,Sl(t,Ve(o.name)),o.config,n));case pb:return m(xl(t,e.patch),L((i)=>m(e.load(i,o,n),L((s)=>{if(s.length===0){let a=m(oy(i),ce(()=>"<n/a>"));return qe(hr([],`Expected ${o.description} with name ${a}`))}return ee(s)}))));case fb:return fe(()=>m(Tt(e,t,o.original,n),bo(Uv),we(Gt(o.redact))));case db:return m(xl(t,e.patch),L((i)=>m(e.enumerateChildren(i),L(Kv),L((s)=>{if(s.length===0)return fe(()=>we(Tt(e,t,o.config,!0),Ve));return m(qt(s,(a)=>Tt(e,ty(t,`[${a}]`),o.config,!0)),we((a)=>{let c=ec(a);if(c.length===0)return Ve(Mr());return Ve(c)}))}))));case mb:return fe(()=>m(xl(t,e.patch),L((i)=>m(e.enumerateChildren(i),L((s)=>m(s,qt((a)=>Tt(e,Sl(i,Ve(a)),o.valueConfig,n)),we((a)=>{if(a.length===0)return Ve(li());return m(Bv(a),Gt((c)=>vx(vp(pe(s),c))))})))))));case hb:return fe(()=>m(Tt(e,t,o.left,n),xo,L((i)=>m(Tt(e,t,o.right,n),xo,L((s)=>{if(he(i)&&he(s))return qe(hl(i.left,s.left));if(he(i)&&pt(s))return qe(i.left);if(pt(i)&&he(s))return qe(s.left);if(pt(i)&&pt(s)){let a=m(t,Lr(".")),c=Hv(t,a),[l,u]=Lv(c,c,m(i.right,Gt(B)),m(s.right,Gt(B)));return m(l,vp(u),qt(([f,d])=>m(Zc(f,d),we(([h,g])=>o.zip(h,g)))))}throw Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues")})))))}},Hv=(e,t)=>(r)=>U(hr(e,`The element at index ${r} in a sequence at path "${t}" was missing`));var jv=(e,t)=>e.split(new RegExp(`\\s*${bi(t)}\\s*`)),$v=(e,t,r,n,o)=>{if(!o)return m(r.parse(e),Jc({onFailure:Pn(t),onSuccess:Ve}));return m(jv(e,n),qt((i)=>r.parse(i.trim())),bo(Pn(t)))},Bv=(e)=>Object.keys(e[0]).map((t)=>e.map((r)=>r[t])),Kv=(e)=>m(qt(e,zv),Jc({onFailure:()=>Mr(),onSuccess:Nr(gr)}),xo,we(Kg));var Wv=/^(\[(\d+)\])$/,zv=(e)=>{let t=e.match(Wv);if(t!==null){let r=t[2];return m(r!==void 0&&r.length>0?I(r):w(),Vt(Vv))}return w()};var Vv=(e)=>{let t=Number.parseInt(e);return Number.isNaN(t)?w():I(t)};var bb=Symbol.for("effect/Console"),bl=dt("effect/Console"),_b={[bb]:bb,assert(e,...t){return C(()=>{console.assert(e,...t)})},clear:C(()=>{console.clear()}),count(e){return C(()=>{console.count(e)})},countReset(e){return C(()=>{console.countReset(e)})},debug(...e){return C(()=>{console.debug(...e)})},dir(e,t){return C(()=>{console.dir(e,t)})},dirxml(...e){return C(()=>{console.dirxml(...e)})},error(...e){return C(()=>{console.error(...e)})},group(e){return e?.collapsed?C(()=>console.groupCollapsed(e?.label)):C(()=>console.group(e?.label))},groupEnd:C(()=>{console.groupEnd()}),info(...e){return C(()=>{console.info(...e)})},log(...e){return C(()=>{console.log(...e)})},table(e,t){return C(()=>{console.table(e,t)})},time(e){return C(()=>console.time(e))},timeEnd(e){return C(()=>console.timeEnd(e))},timeLog(e,...t){return C(()=>{console.timeLog(e,...t)})},trace(...e){return C(()=>{console.trace(...e)})},warn(...e){return C(()=>{console.warn(...e)})},unsafe:console};var Yv="effect/Random",wb=Symbol.for(Yv),Eb=dt("effect/Random");class Ob{seed;[wb]=wb;PRNG;constructor(e){this.seed=e,this.PRNG=new ip(e)}get next(){return C(()=>this.PRNG.number())}get nextBoolean(){return we(this.next,(e)=>e>0.5)}get nextInt(){return C(()=>this.PRNG.integer(Number.MAX_SAFE_INTEGER))}nextRange(e,t){return we(this.next,(r)=>(t-e)*r+e)}nextIntBetween(e,t){return C(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return Zv(e,(t)=>this.nextIntBetween(0,t))}}var Zv=(e,t)=>fe(()=>m(C(()=>Array.from(e)),L((r)=>{let n=[];for(let o=r.length;o>=2;o=o-1)n.push(o);return m(n,So((o)=>m(t(o),we((i)=>Qv(r,o-1,i)))),zr(rc(r)))}))),Qv=(e,t,r)=>{let n=e[t];return e[t]=e[r],e[r]=n,e},Tb=(e)=>new Ob(S(e));var kb=Symbol.for("effect/Tracer"),eC=(e)=>({[kb]:kb,...e}),Gs=dt("effect/Tracer"),_l=dt("effect/ParentSpan"),Ab=function(){return function(r){let n="";for(let o=0;o<r;o++)n+="abcdef0123456789".charAt(Math.floor(Math.random()*16));return n}}();class Ib{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:Ab(32),this.spanId=Ab(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 Rb=eC({span:(e,t,r,n,o,i)=>new Ib(e,t,r,n,o,i),context:(e)=>e()});var vb=Es()("effect/Tracer/DisablePropagation",{defaultValue:an});var nC=m(wn(),fr(Js,eb()),fr(bl,_b),fr(Eb,Tb(Math.random())),fr(xb,Sb()),fr(Gs,Rb)),Ys=N(Symbol.for("effect/DefaultServices/currentServices"),()=>el(nC));var iC=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return{BaseEffectError:class extends ol{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}(),Cb=(e)=>{let t={BaseEffectError:class extends iC{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError};var Pb=vr;var sC=Mg;class wd extends sC{}var Nb="Sequential",Mb="Parallel",aC="ParallelN",_i={_tag:Nb},Lb={_tag:Mb},Db=(e)=>({_tag:aC,parallelism:e}),Ed=(e)=>e._tag===Nb,Od=(e)=>e._tag===Mb;var wl=_i,El=Lb,Ol=Db;function qb(e){return new Jr(e)}function Ub(){return qb(new Map)}var kd=Symbol.for("effect/FiberRefs");class Jr{locals;[kd]=kd;constructor(e){this.locals=e}pipe(){return y(this,arguments)}}var lC=(e,t,r,n=!1)=>{let o=e,i=t,s=r,a=n,c=void 0;while(c===void 0)if(se(i)&&se(s)){let l=Ie(i)[0],u=Jt(i),f=Ie(s)[0],d=Ie(s)[1],h=Jt(s);if(l.startTimeMillis<f.startTimeMillis)s=h,a=!0;else if(l.startTimeMillis>f.startTimeMillis)i=u;else if(l.id<f.id)s=h,a=!0;else if(l.id>f.id)i=u;else c=[d,a]}else c=[o.initial,!0];return c},Id=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][O](t)){if(!n.has(i)){if(b(s,i.initial))return;n.set(i,[[t,i.join(i.initial,s)]]);return}let a=n.get(i),[c,l]=lC(i,a,o);if(l){let u=i.diff(c,s),f=a[0][1],d=i.join(f,i.patch(u)(f));if(!b(f,d)){let h,g=a[0][0];if(g[O](t))h=[[g,d],...a.slice(1)];else h=[[t,d],...a];n.set(i,h)}}}}),new Jr(n)}),Rd=p(2,(e,t)=>{let r=new Map;return Hb(e,r,t),new Jr(r)}),Hb=(e,t,r)=>{e.locals.forEach((n,o)=>{let i=n[0][1],s=o.patch(o.fork)(i);if(b(i,s))t.set(o,n);else t.set(o,[[r,s],...n])})};var Zs=p(2,(e,t)=>{let r=new Map(e.locals);return r.delete(t),new Jr(r)}),vd=p(2,(e,t)=>{if(!e.locals.has(t))return w();return I(Ie(e.locals.get(t))[1])}),Fn=p(2,(e,t)=>m(vd(e,t),ce(()=>t.initial))),wi=p(2,(e,{fiberId:t,fiberRef:r,value:n})=>{if(e.locals.size===0)return new Jr(new Map([[r,[[t,n]]]]));let o=new Map(e.locals);return Ad(o,t,r,n),new Jr(o)}),Ad=(e,t,r,n)=>{let o=e.get(r)??[],i;if(se(o)){let[s,a]=Ie(o);if(s[O](t))if(b(a,n))return;else i=[[t,n],...o.slice(1)];else i=[[t,n],...o]}else i=[[t,n]];e.set(r,i)},jb=p(2,(e,{entries:t,forkAs:r})=>{if(e.locals.size===0)return new Jr(new Map(t));let n=new Map(e.locals);if(r!==void 0)Hb(e,n,r);return t.forEach(([o,i])=>{if(i.length===1)Ad(n,i[0][0],o,i[0][1]);else i.forEach(([s,a])=>{Ad(n,s,o,a)})}),new Jr(n)});var $b=Fn;var Bb=jb;var Kb=Ub;var zb="Empty",Vb="Add",Jb="Remove",Gb="Update",Yb="AndThen",Zb={_tag:zb},Qb=(e,t)=>{let r=new Map(e.locals),n=Zb;for(let[o,i]of t.locals.entries()){let s=Ie(i)[1],a=r.get(o);if(a!==void 0){let c=Ie(a)[1];if(!b(c,s))n=Tl({_tag:Gb,fiberRef:o,patch:o.diff(c,s)})(n)}else n=Tl({_tag:Vb,fiberRef:o,value:s})(n);r.delete(o)}for(let[o]of r.entries())n=Tl({_tag:Jb,fiberRef:o})(n);return n},Tl=p(2,(e,t)=>({_tag:Yb,first:e,second:t})),Xb=p(3,(e,t,r)=>{let n=r,o=Ve(e);while(se(o)){let i=Ie(o),s=Jt(o);switch(i._tag){case zb:{o=s;break}case Vb:{n=wi(n,{fiberId:t,fiberRef:i.fiberRef,value:i.value}),o=s;break}case Jb:{n=Zs(n,i.fiberRef),o=s;break}case Gb:{let a=Fn(n,i.fiberRef);n=wi(n,{fiberId:t,fiberRef:i.fiberRef,value:i.fiberRef.patch(i.patch)(a)}),o=s;break}case Yb:{o=Jo(i.first)(Jo(i.second)(s));break}}}return n});var e_=Qb;var t_=Xb;var Al="effect/FiberStatus",Nn=Symbol.for(Al),kl="Done",r_="Running",n_="Suspended",fC=ne(`${Al}-${kl}`);class o_{[Nn]=Nn;_tag=kl;[k](){return fC}[O](e){return Il(e)&&e._tag===kl}}class i_{runtimeFlags;[Nn]=Nn;_tag=r_;constructor(e){this.runtimeFlags=e}[k](){return m(S(Al),H(S(this._tag)),H(S(this.runtimeFlags)),Z(this))}[O](e){return Il(e)&&e._tag===r_&&this.runtimeFlags===e.runtimeFlags}}class s_{runtimeFlags;blockingOn;[Nn]=Nn;_tag=n_;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[k](){return m(S(Al),H(S(this._tag)),H(S(this.runtimeFlags)),H(S(this.blockingOn)),Z(this))}[O](e){return Il(e)&&e._tag===n_&&this.runtimeFlags===e.runtimeFlags&&b(this.blockingOn,e.blockingOn)}}var a_=new o_,c_=(e)=>new i_(e),l_=(e,t)=>new s_(e,t),Il=(e)=>_(e,Nn),u_=(e)=>e._tag===kl;var p_=a_,Pd=c_,f_=l_;var d_=u_;var hC=AS,gC=IS,yC=RS,xC=ad,SC=cd,bC=ld,_C=vS,wC=CS;var EC=m(gr,Xa((e)=>e.ordinal));var m_=_p(EC);var h_=(e)=>{switch(e){case"All":return hC;case"Debug":return bC;case"Error":return yC;case"Fatal":return gC;case"Info":return SC;case"Trace":return _C;case"None":return wC;case"Warning":return xC}};var TC=Symbol.for("effect/Micro"),vl=Symbol.for("effect/Micro/MicroExit");var g_=Symbol.for("effect/Micro/MicroCause");var kC={_E:Q};class Md 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 nr(ci(this),{renderErrorCause:!0});return this}}return Object.assign(e.prototype,hp),e}(),Io=(e,t)=>{class r extends al{_tag=t}return Object.assign(r.prototype,e),r.prototype.name=t,r},wS=Symbol.for("effect/Cause/errors/RuntimeException"),xR=Io({[wS]:wS},"RuntimeException");var Xf=Symbol.for("effect/Cause/errors/InterruptedException"),_2=Io({[Xf]:Xf},"InterruptedException"),JS=(e)=>_(e,Xf),ES=Symbol.for("effect/Cause/errors/IllegalArgument"),SR=Io({[ES]:ES},"IllegalArgumentException");var OS=Symbol.for("effect/Cause/errors/NoSuchElement"),Vs=Io({[OS]:OS},"NoSuchElementException");var TS=Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"),w2=Io({[TS]:TS},"InvalidPubSubCapacityException"),kS=Symbol.for("effect/Cause/errors/ExceededCapacityException"),E2=Io({[kS]:kS},"ExceededCapacityException");var AS=Symbol.for("effect/Cause/errors/Timeout"),O2=Io({[AS]:AS},"TimeoutException");var IS=Symbol.for("effect/Cause/errors/UnknownException"),bR=function(){class e extends al{_tag="UnknownException";error;constructor(t,r){super(r??"An unknown error occurred",{cause:t});this.error=t}}return Object.assign(e.prototype,{[IS]:IS,name:"UnknownException"}),e}();var _i=(e)=>gi(e)&&("_tag"in e)&&(e._tag==="Success"||e._tag==="Failure");var yd=(e)=>e._tag==="Success";var GS=p(2,(e,t)=>{switch(e._tag){case mt:return ce(e.effect_instruction_i0);case ht:return xe(t)}}),Js=(e)=>GS(e,void 0);var vo=(e,t)=>_R(e,t?.parallel?bo:Ye),xd=(e)=>ce(vt(e));var Gs=(e)=>ce(ci(e)),ce=(e)=>{let t=new rd(mt);return t.effect_instruction_i0=e,t};var Sd=(e)=>ce(rr(e)),Wc=p(2,(e,t)=>{switch(e._tag){case mt:return ce(e.effect_instruction_i0);case ht:return xe(t(e.effect_instruction_i0))}});var cl=p(2,(e,{onFailure:t,onSuccess:r})=>{switch(e._tag){case mt:return t(e.effect_instruction_i0);case ht:return r(e.effect_instruction_i0)}});var xe=(e)=>{let t=new nd(ht);return t.effect_instruction_i0=e,t},Ht=xe(void 0);var bd=p(3,(e,t,{onFailure:r,onSuccess:n})=>{switch(e._tag){case mt:switch(t._tag){case ht:return ce(e.effect_instruction_i0);case mt:return ce(r(e.effect_instruction_i0,t.effect_instruction_i0))}case ht:switch(t._tag){case ht:return xe(n(e.effect_instruction_i0,t.effect_instruction_i0));case mt:return ce(t.effect_instruction_i0)}}}),_R=(e,t)=>{let r=ic(e);if(!Xt(r))return w();return m(tr(r),Xo(m(er(r),Wc(Pe)),(n,o)=>m(n,bd(o,{onSuccess:(i,s)=>m(i,Ge(s)),onFailure:t}))),Wc(yn),Wc((n)=>Ur(n)),R)},YS=(e)=>({...dn,[yS]:xS,state:Ic(SS([])),commit(){return ll(this)},blockingOn:e});var ll=(e)=>RS((t)=>{let r=ui(e.state);switch(r._tag){case Kc:return t(r.effect);case mi:return r.joiners.push(t),wR(e,t)}},e.blockingOn);var ul=(e,t)=>{let r=ui(e.state);if(r._tag===mi){vc(e.state,bS(t));for(let n=0,o=r.joiners.length;n<o;n++)r.joiners[n](t)}},wR=(e,t)=>F(()=>{let r=ui(e.state);if(r._tag===mi){let n=r.joiners.indexOf(t);if(n>=0)r.joiners.splice(n,1)}}),ER=ze((e)=>xe(e.currentContext)),ZS=()=>ER;var Ro=(e)=>L(ZS(),e),OR=p(2,(e,t)=>Fn(Ao,t)(e));var _d=p(2,(e,t)=>Ro((r)=>OR(e,t(r))));var pl=(e)=>{let t=e.currentSpan;return t!==void 0&&t._tag==="Span"?R(t):w()};var QS=tx;var XS=nr;var fl="And",dl="Or",ml="InvalidData",hl="MissingData",gl="SourceUnavailable",yl="Unsupported";var AR="effect/ConfigError",eb=Symbol.for(AR),wi={_tag:"ConfigError",[eb]:eb},xl=(e,t)=>{let r=Object.create(wi);return r._op=fl,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},Sl=(e,t)=>{let r=Object.create(wi);return r._op=dl,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},wd=(e,t,r={pathDelim:"."})=>{let n=Object.create(wi);return n._op=ml,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Invalid data at ${m(this.path,qr(r.pathDelim))}: "${this.message}")`}}),n},Sr=(e,t,r={pathDelim:"."})=>{let n=Object.create(wi);return n._op=hl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Missing data at ${m(this.path,qr(r.pathDelim))}: "${this.message}")`}}),n},Ed=(e,t,r,n={pathDelim:"."})=>{let o=Object.create(wi);return o._op=gl,o.path=e,o.message=t,o.cause=r,Object.defineProperty(o,"toString",{enumerable:!1,value(){return`(Source unavailable at ${m(this.path,qr(n.pathDelim))}: "${this.message}")`}}),o},Od=(e,t,r={pathDelim:"."})=>{let n=Object.create(wi);return n._op=yl,n.path=e,n.message=t,Object.defineProperty(n,"toString",{enumerable:!1,value(){return`(Unsupported operation at ${m(this.path,qr(r.pathDelim))}: "${this.message}")`}}),n};var Nn=p(2,(e,t)=>{switch(e._op){case fl:return xl(Nn(e.left,t),Nn(e.right,t));case dl:return Sl(Nn(e.left,t),Nn(e.right,t));case ml:return wd([...t,...e.path],e.message);case hl:return Sr([...t,...e.path],e.message);case gl:return Ed([...t,...e.path],e.message,e.cause);case yl:return Od([...t,...e.path],e.message)}});var tb=p(3,(e,t,r)=>{let n=[e],o=[];while(n.length>0){let s=n.pop();switch(s._op){case fl:{n.push(s.right),n.push(s.left),o.push(U({_op:"AndCase"}));break}case dl:{n.push(s.right),n.push(s.left),o.push(U({_op:"OrCase"}));break}case ml:{o.push(K(r.invalidDataCase(t,s.path,s.message)));break}case hl:{o.push(K(r.missingDataCase(t,s.path,s.message)));break}case gl:{o.push(K(r.sourceUnavailableCase(t,s.path,s.message,s.cause)));break}case yl:{o.push(K(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 IR="effect/Clock",nb=Symbol.for(IR),Ys=xt("effect/Clock"),vR=2147483647,ob={unsafeSchedule(e,t){let r=Ac(t);if(r>vR)return ln;let n=!1,o=setTimeout(()=>{n=!0,e()},r);return()=>(clearTimeout(o),!n)}},ib=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))}}(),RR=function(){let e=typeof process==="object"&&"hrtime"in process&&typeof process.hrtime.bigint==="function"?process.hrtime:void 0;if(!e)return ib;let t=ib()-e.bigint();return()=>t+e.bigint()}();class sb{[nb]=nb;unsafeCurrentTimeMillis(){return Date.now()}unsafeCurrentTimeNanos(){return RR()}currentTimeMillis=F(()=>this.unsafeCurrentTimeMillis());currentTimeNanos=F(()=>this.unsafeCurrentTimeNanos());scheduler(){return ne(ob)}sleep(e){return vn((t)=>{let r=ob.unsafeSchedule(()=>t(Fe),e);return Gr(F(r))})}}var ab=()=>new sb;var br=ey;var Ei=(e)=>e.replace(/[/\\^$*+?.()|[\]{}]/g,"\\$&");var ub={_tag:"Empty"};var _l=p(2,(e,t)=>{let r=Is(t),n=e;while(Af(r)){let o=r.head;switch(o._tag){case"Empty":{r=r.tail;break}case"AndThen":{r=Wr(o.first,Wr(o.second,r.tail));break}case"MapName":{n=Qt(n,o.f),r=r.tail;break}case"Nested":{n=Zo(n,o.name),r=r.tail;break}case"Unnested":{if(m(Mr(n),oy(o.name)))n=Zt(n),r=r.tail;else return U(Sr(n,`Expected ${o.name} to be in path in ConfigProvider#unnested`));break}}}return K(n)});var pb="Constant",fb="Fail",db="Fallback",mb="Described",hb="Lazy",gb="MapOrFail",yb="Nested",xb="Primitive",Sb="Redacted",bb="Sequence",_b="HashMap",wb="ZipWith";var wl=(e,t)=>[...e,...t],DR="effect/ConfigProvider",Eb=Symbol.for(DR),Tb=xt("effect/ConfigProvider"),qR="effect/ConfigProviderFlat",Ob=Symbol.for(qR),UR=(e)=>({[Eb]:Eb,pipe(){return y(this,arguments)},...e}),HR=(e)=>({[Ob]:Ob,patch:e.patch,load:(t,r,n=!0)=>e.load(t,r,n),enumerateChildren:e.enumerateChildren}),jR=(e)=>UR({load:(t)=>L(Rt(e,Dr(),t,!1),(r)=>Oe(Mr(r),{onNone:()=>$e(Sr(Dr(),`Expected a single value having structure: ${t}`)),onSome:ne})),flattened:e}),kb=(e)=>{let{pathDelim:t,seqDelim:r}=Object.assign({},{pathDelim:"_",seqDelim:","},e),n=(c)=>m(c,qr(t)),o=(c)=>c.split(t),i=()=>typeof process<"u"&&("env"in process)&&typeof process.env==="object"?process.env:{};return jR(HR({load:(c,l,u=!0)=>{let f=n(c),d=i(),g=f in d?R(d[f]):w();return m(g,Oo(()=>Sr(c,`Expected ${f} to exist in the process context`)),L((h)=>JR(h,c,l,r,u)))},enumerateChildren:(c)=>F(()=>{let l=i(),d=Object.keys(l).map((g)=>o(g.toUpperCase())).filter((g)=>{for(let h=0;h<c.length;h++){let P=m(c,Cp(h)),x=g[h];if(x===void 0||P!==x)return!1}return!0}).flatMap((g)=>g.slice(c.length,c.length+1));return Gy(d)}),patch:ub}))};var $R=(e,t,r,n)=>{let o=Mp(r.length,(c)=>c>=n.length?w():R([e(c),c+1])),i=Mp(n.length,(c)=>c>=r.length?w():R([t(c),c+1])),s=wl(r,o),a=wl(n,i);return[s,a]},BR=(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},KR={andCase:(e,t,r)=>xl(t,r),orCase:(e,t,r)=>Sl(t,r),invalidDataCase:(e,t)=>wd(t,"<redacted>"),missingDataCase:(e,t)=>Sr(t,"<redacted>"),sourceUnavailableCase:(e,t,r,n)=>Ed(t,"<redacted>",n),unsupportedCase:(e,t)=>Od(t,"<redacted>")},WR=(e)=>tb(e,void 0,KR),Rt=(e,t,r,n)=>{let o=r;switch(o._tag){case pb:return ne(Je(o.value));case mb:return de(()=>Rt(e,t,o.config,n));case fb:return $e(Sr(t,o.message));case db:return m(de(()=>Rt(e,t,o.first,n)),Ds((i)=>{if(o.condition(i))return m(Rt(e,t,o.second,n),Ds((s)=>$e(Sl(i,s))));return $e(i)}));case hb:return de(()=>Rt(e,t,o.config(),n));case gb:return de(()=>m(Rt(e,t,o.original,n),L(Ut((i)=>m(o.mapOrFail(i),Oo(Nn(BR(t,o.original))))))));case yb:return de(()=>Rt(e,wl(t,Je(o.name)),o.config,n));case xb:return m(_l(t,e.patch),L((i)=>m(e.load(i,o,n),L((s)=>{if(s.length===0){let a=m(py(i),ue(()=>"<n/a>"));return $e(Sr([],`Expected ${o.description} with name ${a}`))}return ne(s)}))));case Sb:return de(()=>m(Rt(e,t,o.original,n),Oo(WR),Ee(Qt(o.redact))));case bb:return m(_l(t,e.patch),L((i)=>m(e.enumerateChildren(i),L(YR),L((s)=>{if(s.length===0)return de(()=>Ee(Rt(e,t,o.config,!0),Je));return m(Ut(s,(a)=>Rt(e,cy(t,`[${a}]`),o.config,!0)),Ee((a)=>{let c=nc(a);if(c.length===0)return Je(Dr());return Je(c)}))}))));case _b:return de(()=>m(_l(t,e.patch),L((i)=>m(e.enumerateChildren(i),L((s)=>m(s,Ut((a)=>Rt(e,wl(i,Je(a)),o.valueConfig,n)),Ee((a)=>{if(a.length===0)return Je(fi());return m(GR(a),Qt((c)=>Dx(Np(fe(s),c))))})))))));case wb:return de(()=>m(Rt(e,t,o.left,n),wo,L((i)=>m(Rt(e,t,o.right,n),wo,L((s)=>{if(ye(i)&&ye(s))return $e(xl(i.left,s.left));if(ye(i)&&gt(s))return $e(i.left);if(gt(i)&&ye(s))return $e(s.left);if(gt(i)&&gt(s)){let a=m(t,qr(".")),c=zR(t,a),[l,u]=$R(c,c,m(i.right,Qt(K)),m(s.right,Qt(K)));return m(l,Np(u),Ut(([f,d])=>m(el(f,d),Ee(([g,h])=>o.zip(g,h)))))}throw Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues")})))))}},zR=(e,t)=>(r)=>U(Sr(e,`The element at index ${r} in a sequence at path "${t}" was missing`));var VR=(e,t)=>e.split(new RegExp(`\\s*${Ei(t)}\\s*`)),JR=(e,t,r,n,o)=>{if(!o)return m(r.parse(e),Zc({onFailure:Nn(t),onSuccess:Je}));return m(VR(e,n),Ut((i)=>r.parse(i.trim())),Oo(Nn(t)))},GR=(e)=>Object.keys(e[0]).map((t)=>e.map((r)=>r[t])),YR=(e)=>m(Ut(e,QR),Zc({onFailure:()=>Dr(),onSuccess:Lr(br)}),wo,Ee(Zg));var ZR=/^(\[(\d+)\])$/,QR=(e)=>{let t=e.match(ZR);if(t!==null){let r=t[2];return m(r!==void 0&&r.length>0?R(r):w(),Yt(XR))}return w()};var XR=(e)=>{let t=Number.parseInt(e);return Number.isNaN(t)?w():R(t)};var Ab=Symbol.for("effect/Console"),El=xt("effect/Console"),Ib={[Ab]:Ab,assert(e,...t){return F(()=>{console.assert(e,...t)})},clear:F(()=>{console.clear()}),count(e){return F(()=>{console.count(e)})},countReset(e){return F(()=>{console.countReset(e)})},debug(...e){return F(()=>{console.debug(...e)})},dir(e,t){return F(()=>{console.dir(e,t)})},dirxml(...e){return F(()=>{console.dirxml(...e)})},error(...e){return F(()=>{console.error(...e)})},group(e){return e?.collapsed?F(()=>console.groupCollapsed(e?.label)):F(()=>console.group(e?.label))},groupEnd:F(()=>{console.groupEnd()}),info(...e){return F(()=>{console.info(...e)})},log(...e){return F(()=>{console.log(...e)})},table(e,t){return F(()=>{console.table(e,t)})},time(e){return F(()=>console.time(e))},timeEnd(e){return F(()=>console.timeEnd(e))},timeLog(e,...t){return F(()=>{console.timeLog(e,...t)})},trace(...e){return F(()=>{console.trace(...e)})},warn(...e){return F(()=>{console.warn(...e)})},unsafe:console};var rC="effect/Random",vb=Symbol.for(rC),Rb=xt("effect/Random");class Cb{seed;[vb]=vb;PRNG;constructor(e){this.seed=e,this.PRNG=new lp(e)}get next(){return F(()=>this.PRNG.number())}get nextBoolean(){return Ee(this.next,(e)=>e>0.5)}get nextInt(){return F(()=>this.PRNG.integer(Number.MAX_SAFE_INTEGER))}nextRange(e,t){return Ee(this.next,(r)=>(t-e)*r+e)}nextIntBetween(e,t){return F(()=>this.PRNG.integer(t-e)+e)}shuffle(e){return nC(e,(t)=>this.nextIntBetween(0,t))}}var nC=(e,t)=>de(()=>m(F(()=>Array.from(e)),L((r)=>{let n=[];for(let o=r.length;o>=2;o=o-1)n.push(o);return m(n,Eo((o)=>m(t(o),Ee((i)=>oC(r,o-1,i)))),Jr(ic(r)))}))),oC=(e,t,r)=>{let n=e[t];return e[t]=e[r],e[r]=n,e},Pb=(e)=>new Cb(S(e));var Fb=Symbol.for("effect/Tracer"),sC=(e)=>({[Fb]:Fb,...e}),Zs=xt("effect/Tracer"),Ol=xt("effect/ParentSpan"),Nb=function(){return function(r){let n="";for(let o=0;o<r;o++)n+="abcdef0123456789".charAt(Math.floor(Math.random()*16));return n}}();class Mb{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:Nb(32),this.spanId=Nb(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 Lb=sC({span:(e,t,r,n,o,i)=>new Mb(e,t,r,n,o,i),context:(e)=>e()});var Db=Ts()("effect/Tracer/DisablePropagation",{defaultValue:ln});var lC=m(On(),gr(Ys,ab()),gr(El,Ib),gr(Rb,Pb(Math.random())),gr(Tb,kb()),gr(Zs,Lb)),Qs=M(Symbol.for("effect/DefaultServices/currentServices"),()=>nl(lC));var pC=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return{BaseEffectError:class extends al{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}(),qb=(e)=>{let t={BaseEffectError:class extends pC{_tag=e}};return t.BaseEffectError.prototype.name=e,t.BaseEffectError};var Ub=Pr;var fC=$g;class kd extends fC{}var jb="Sequential",$b="Parallel",dC="ParallelN",Oi={_tag:jb},Bb={_tag:$b},Kb=(e)=>({_tag:dC,parallelism:e}),Ad=(e)=>e._tag===jb,Id=(e)=>e._tag===$b;var Tl=Oi,kl=Bb,Al=Kb;function Wb(e){return new Yr(e)}function zb(){return Wb(new Map)}var Rd=Symbol.for("effect/FiberRefs");class Yr{locals;[Rd]=Rd;constructor(e){this.locals=e}pipe(){return y(this,arguments)}}var hC=(e,t,r,n=!1)=>{let o=e,i=t,s=r,a=n,c=void 0;while(c===void 0)if(ae(i)&&ae(s)){let l=Ce(i)[0],u=Zt(i),f=Ce(s)[0],d=Ce(s)[1],g=Zt(s);if(l.startTimeMillis<f.startTimeMillis)s=g,a=!0;else if(l.startTimeMillis>f.startTimeMillis)i=u;else if(l.id<f.id)s=g,a=!0;else if(l.id>f.id)i=u;else c=[d,a]}else c=[o.initial,!0];return c},Pd=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][O](t)){if(!n.has(i)){if(b(s,i.initial))return;n.set(i,[[t,i.join(i.initial,s)]]);return}let a=n.get(i),[c,l]=hC(i,a,o);if(l){let u=i.diff(c,s),f=a[0][1],d=i.join(f,i.patch(u)(f));if(!b(f,d)){let g,h=a[0][0];if(h[O](t))g=[[h,d],...a.slice(1)];else g=[[t,d],...a];n.set(i,g)}}}}),new Yr(n)}),Fd=p(2,(e,t)=>{let r=new Map;return Vb(e,r,t),new Yr(r)}),Vb=(e,t,r)=>{e.locals.forEach((n,o)=>{let i=n[0][1],s=o.patch(o.fork)(i);if(b(i,s))t.set(o,n);else t.set(o,[[r,s],...n])})};var Xs=p(2,(e,t)=>{let r=new Map(e.locals);return r.delete(t),new Yr(r)}),Nd=p(2,(e,t)=>{if(!e.locals.has(t))return w();return R(Ce(e.locals.get(t))[1])}),Mn=p(2,(e,t)=>m(Nd(e,t),ue(()=>t.initial))),Ti=p(2,(e,{fiberId:t,fiberRef:r,value:n})=>{if(e.locals.size===0)return new Yr(new Map([[r,[[t,n]]]]));let o=new Map(e.locals);return Cd(o,t,r,n),new Yr(o)}),Cd=(e,t,r,n)=>{let o=e.get(r)??[],i;if(ae(o)){let[s,a]=Ce(o);if(s[O](t))if(b(a,n))return;else i=[[t,n],...o.slice(1)];else i=[[t,n],...o]}else i=[[t,n]];e.set(r,i)},Jb=p(2,(e,{entries:t,forkAs:r})=>{if(e.locals.size===0)return new Yr(new Map(t));let n=new Map(e.locals);if(r!==void 0)Vb(e,n,r);return t.forEach(([o,i])=>{if(i.length===1)Cd(n,i[0][0],o,i[0][1]);else i.forEach(([s,a])=>{Cd(n,s,o,a)})}),new Yr(n)});var Gb=Mn;var Yb=Jb;var Zb=zb;var Xb="Empty",e_="Add",t_="Remove",r_="Update",n_="AndThen",o_={_tag:Xb},i_=(e,t)=>{let r=new Map(e.locals),n=o_;for(let[o,i]of t.locals.entries()){let s=Ce(i)[1],a=r.get(o);if(a!==void 0){let c=Ce(a)[1];if(!b(c,s))n=Il({_tag:r_,fiberRef:o,patch:o.diff(c,s)})(n)}else n=Il({_tag:e_,fiberRef:o,value:s})(n);r.delete(o)}for(let[o]of r.entries())n=Il({_tag:t_,fiberRef:o})(n);return n},Il=p(2,(e,t)=>({_tag:n_,first:e,second:t})),s_=p(3,(e,t,r)=>{let n=r,o=Je(e);while(ae(o)){let i=Ce(o),s=Zt(o);switch(i._tag){case Xb:{o=s;break}case e_:{n=Ti(n,{fiberId:t,fiberRef:i.fiberRef,value:i.value}),o=s;break}case t_:{n=Xs(n,i.fiberRef),o=s;break}case r_:{let a=Mn(n,i.fiberRef);n=Ti(n,{fiberId:t,fiberRef:i.fiberRef,value:i.fiberRef.patch(i.patch)(a)}),o=s;break}case n_:{o=Zo(i.first)(Zo(i.second)(s));break}}}return n});var a_=i_;var c_=s_;var Rl="effect/FiberStatus",Ln=Symbol.for(Rl),vl="Done",l_="Running",u_="Suspended",xC=oe(`${Rl}-${vl}`);class p_{[Ln]=Ln;_tag=vl;[T](){return xC}[O](e){return Cl(e)&&e._tag===vl}}class f_{runtimeFlags;[Ln]=Ln;_tag=l_;constructor(e){this.runtimeFlags=e}[T](){return m(S(Rl),H(S(this._tag)),H(S(this.runtimeFlags)),Q(this))}[O](e){return Cl(e)&&e._tag===l_&&this.runtimeFlags===e.runtimeFlags}}class d_{runtimeFlags;blockingOn;[Ln]=Ln;_tag=u_;constructor(e,t){this.runtimeFlags=e,this.blockingOn=t}[T](){return m(S(Rl),H(S(this._tag)),H(S(this.runtimeFlags)),H(S(this.blockingOn)),Q(this))}[O](e){return Cl(e)&&e._tag===u_&&this.runtimeFlags===e.runtimeFlags&&b(this.blockingOn,e.blockingOn)}}var m_=new p_,h_=(e)=>new f_(e),g_=(e,t)=>new d_(e,t),Cl=(e)=>_(e,Ln),y_=(e)=>e._tag===vl;var x_=m_,Ld=h_,S_=g_;var b_=y_;var _C=NS,wC=MS,EC=LS,OC=pd,TC=fd,kC=dd,AC=DS,IC=qS;var vC=m(br,rc((e)=>e.ordinal));var __=Tp(vC);var w_=(e)=>{switch(e){case"All":return _C;case"Debug":return kC;case"Error":return EC;case"Fatal":return wC;case"Info":return TC;case"Trace":return AC;case"None":return IC;case"Warning":return OC}};var CC=Symbol.for("effect/Micro"),Fl=Symbol.for("effect/Micro/MicroExit");var E_=Symbol.for("effect/Micro/MicroCause");var PC={_E:te};class Ud extends globalThis.Error{_tag;traces;[E_];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
- `)}`:`${o}: ${i}`}else o=n,i=Rr(t,0),s=`${o}: ${i}`;if(r.length>0)s+=`
31
+ `)}`:`${o}: ${i}`}else o=n,i=Cr(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_]=kC,this.name=o,this.stack=s}pipe(){return y(this,arguments)}toString(){return this.stack}[J](){return this.stack}}class S_ extends Md{defect;constructor(e,t=[]){super("Die",e,t);this.defect=e}}var AC=(e,t=[])=>new S_(e,t);class b_ extends Md{constructor(e=[]){super("Interrupt","interrupted",e)}}var IC=(e=[])=>new b_(e);var RC=(e)=>e._tag==="Interrupt";var y_=Symbol.for("effect/Micro/MicroFiber"),vC={_A:Q,_E:Q};class __{context;interruptible;[y_];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[y_]=vC}getRef(e){return sx(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),Gi;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(Hd)}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===Rl)return;let r=x_.interruptChildren&&x_.interruptChildren(this);if(r!==void 0)return this.evaluate(Pl(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(Nl).shouldYield(this)){t=!0;let n=r;r=Pl(MC,()=>n)}if(r=r[Fd](this),r===Rl){let n=this._yielded;if(vl in n)return this._yielded=void 0,n;return Rl}}}catch(n){if(!_(r,Fd))return Nd(`MicroFiber.runLoop: Not a valid effect: ${String(r)}`);return Nd(n)}}getCont(e){while(!0){let t=this._stack.pop();if(!t)return;let r=t[Cl]&&t[Cl](this);if(r)return{[e]:r};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,Rl}children(){return this._children??=new Set}}var x_=N("effect/Micro/fiberMiddleware",()=>({interruptChildren:void 0}));var w_=Symbol.for("effect/Micro/identifier"),Fe=Symbol.for("effect/Micro/args"),Fd=Symbol.for("effect/Micro/evaluate"),Oi=Symbol.for("effect/Micro/successCont"),Ei=Symbol.for("effect/Micro/failureCont"),Cl=Symbol.for("effect/Micro/ensureCont"),Rl=Symbol.for("effect/Micro/Yield"),CC={_A:Q,_E:Q,_R:Q},PC={...Pb,_op:"Micro",[TC]:CC,pipe(){return y(this,arguments)},[Symbol.iterator](){return new $o(new Ir(this))},toJSON(){return{_id:"Micro",op:this[w_],...Fe in this?{args:this[Fe]}:void 0}},toString(){return oe(this)},[J](){return oe(this)}};function FC(e){return Nd("Micro.evaluate: Not implemented")}var Fl=(e)=>({...PC,[w_]:e.op,[Fd]:e.eval??FC,[Oi]:e.contA,[Ei]:e.contE,[Cl]:e.ensure}),Ld=(e)=>{let t=Fl(e);return function(){let r=Object.create(t);return r[Fe]=e.single===!1?arguments:arguments[0],r}},E_=(e)=>{let t={...Fl(e),[vl]:vl,_tag:e.op,get[e.prop](){return this[Fe]},toJSON(){return{_id:"MicroExit",_tag:e.op,[e.prop]:this[Fe]}},[O](r){return qC(r)&&r._tag===e.op&&b(this[Fe],r[Fe])},[k](){return Z(this,H(ne(e.op))(S(this[Fe])))}};return function(r){let n=Object.create(t);return n[Fe]=r,n[Oi]=void 0,n[Ei]=void 0,n[Cl]=void 0,n}},Dd=E_({op:"Success",prop:"value",eval(e){let t=e.getCont(Oi);return t?t[Oi](this[Fe],e):e.yieldWith(this)}}),O_=E_({op:"Failure",prop:"cause",eval(e){let t=e.getCont(Ei);while(RC(this[Fe])&&t&&e.interruptible)t=e.getCont(Ei);return t?t[Ei](this[Fe],e):e.yieldWith(this)}});var NC=Ld({op:"Yield",eval(e){let t=!1;return e.getRef(Nl).scheduleTask(()=>{if(t)return;e.evaluate(UC)},this[Fe]??0),e.yieldWith(()=>{t=!0})}}),MC=NC(0);var LC=Dd(void 0);var qd=Ld({op:"WithMicroFiber",eval(e){return this[Fe](e)}});var Pl=p(2,(e,t)=>{let r=Object.create(DC);return r[Fe]=e,r[Oi]=t,r}),DC=Fl({op:"OnSuccess",eval(e){return e._stack.push(this),this[Fe]}});var qC=(e)=>_(e,vl),T_=Dd,Ud=O_,Hd=Ud(IC());var Nd=(e)=>Ud(AC(e));var UC=T_(void 0);var HC="setImmediate"in globalThis?globalThis.setImmediate:(e)=>setTimeout(e,0);class jd{tasks=[];running=!1;scheduleTask(e,t){if(this.tasks.push(e),!this.running)this.running=!0,HC(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(A_)}flush(){while(this.tasks.length>0)this.runTasks()}}var jC=p(2,(e,t)=>qd((r)=>{let n=r.context;return r.context=t(n),KC(e,()=>(r.context=n,LC))}));var k_=p(2,(e,t)=>jC(e,ws(t)));class A_ extends Es()("effect/Micro/currentMaxOpsBeforeYield",{defaultValue:()=>2048}){}class Nl extends Es()("effect/Micro/currentScheduler",{defaultValue:()=>new jd}){}var $C=p(2,(e,t)=>{let r=Object.create(BC);return r[Fe]=e,r[Oi]=t.onSuccess,r[Ei]=t.onFailure,r}),BC=Fl({op:"OnSuccessAndFailure",eval(e){return e._stack.push(this),this[Fe]}});var KC=p(2,(e,t)=>zC((r)=>$C(r(e),{onFailure:(n)=>Pl(t(Ud(n)),()=>O_(n)),onSuccess:(n)=>Pl(t(T_(n)),()=>Dd(n))})));var I_=Ld({op:"SetInterruptible",ensure(e){if(e.interruptible=this[Fe],e._interrupted&&e.interruptible)return()=>Hd}}),WC=(e)=>qd((t)=>{if(t.interruptible)return e;if(t.interruptible=!0,t._stack.push(I_(!1)),t._interrupted)return Hd;return e}),zC=(e)=>qd((t)=>{if(!t.interruptible)return e(Q);return t.interruptible=!1,t._stack.push(I_(!0)),e(WC)});var R_=(e,t)=>{let r=new __(Nl.context(t?.scheduler??new jd));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 Ml{scheduleDrain;running=!1;tasks=new $d;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 Ml(e),r=new WeakMap;return(n)=>{if(n===void 0)return t;let o=r.get(n);if(o===void 0)o=new Ml(e),r.set(n,o);return o}}}class $d{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 v_{maxNextTickBeforeTimer;getRunner=Ml.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(ud)?e.getFiberRef(gi):!1}scheduleTask(e,t,r){this.getRunner(r).scheduleTask(e,t)}}var C_=N(Symbol.for("effect/Scheduler/defaultScheduler"),()=>new v_(2048));class Qs{tasks=new $d;deferred=!1;scheduleTask(e,t,r){if(this.deferred)C_.scheduleTask(e,t,r);else this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(ud)?e.getFiberRef(gi):!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 Ll=N(Symbol.for("effect/FiberRef/currentScheduler"),()=>ze(C_));var Dl=N(Symbol.for("effect/FiberRef/currentRequestMap"),()=>ze(new Map));var Bd=(e,t,r,n)=>{switch(e){case void 0:return t();case"unbounded":return r();case"inherit":return _o(DS,(o)=>o==="unbounded"?r():o>1?n(o):t());default:return e>1?n(e):t()}};var Kd=(e)=>e.replace(/[\s="]/g,"_"),F_=(e)=>(t)=>`${Kd(t.label)}=${e-t.startTime}ms`;var N_="effect/MetricLabel",Wd=Symbol.for(N_);class M_{key;value;[Wd]=Wd;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=ne(N_+this.key+this.value)}[k](){return this._hash}[O](e){return ZC(e)&&this.key===e.key&&this.value===e.value}pipe(){return y(this,arguments)}}var L_=(e,t)=>new M_(e,t),ZC=(e)=>_(e,Wd);var zd=Vt((e)=>bs(e.context,vb)?e._tag==="Span"?zd(e.parent):w():I(e));var D_=dd;var Vd="InterruptSignal",Jd="Stateful",Gd="Resume",Yd="YieldNow",ql=(e)=>({_tag:"InterruptSignal",cause:e}),Ti=(e)=>({_tag:"Stateful",onFiber:e}),Ao=(e)=>({_tag:"Resume",effect:e}),q_=()=>({_tag:"YieldNow"});var nP="effect/FiberScope",Ul=Symbol.for(nP);class H_{[Ul]=Ul;fiberId=Lt;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}}class j_{fiberId;parent;[Ul]=Ul;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell(Ti((r)=>{r.addChild(t),t.addObserver(()=>{r.removeChild(t)})}))}}var $_=(e)=>new j_(e.id(),e),Xs=N(Symbol.for("effect/FiberScope/Global"),()=>new H_);var sP="effect/Fiber",Zd=Symbol.for(sP),Qd={_E:(e)=>e,_A:(e)=>e},aP={[Zd]:Qd,pipe(){return y(this,arguments)}},cP="effect/Fiber",K_=Symbol.for(cP);var Hl=(e)=>Qc(Ds(e.await),e.inheritAll);var GU={...pn,commit(){return Hl(this)},...aP,id:()=>Lt,await:js,children:ee([]),inheritAll:js,poll:ee(w()),interruptAsFork:()=>js};var Mn="effect/FiberCurrent";var uP="effect/Logger",W_=Symbol.for(uP),z_={_Message:(e)=>e,_Output:(e)=>e},jl=(e)=>({[W_]:z_,log:e,pipe(){return y(this,arguments)}});var QU={[W_]:z_,log:Gi,pipe(){return y(this,arguments)}};var pP=/^[^\s"=]*$/,fP=(e,t)=>({annotations:r,cause:n,date:o,fiberId:i,logLevel:s,message:a,spans:c})=>{let l=(g)=>g.match(pP)?g:e(g),u=(g,P)=>`${Kd(g)}=${l(P)}`,f=(g,P)=>" "+u(g,P),d=u("timestamp",o.toISOString());d+=f("level",s.label),d+=f("fiber",Rc(i));let h=Op(a);for(let g=0;g<h.length;g++)d+=f("message",Rr(h[g],t));if(!Yp(n))d+=f("cause",er(n,{renderErrorCause:!0}));for(let g of c)d+=" "+F_(o.getTime())(g);for(let[g,P]of r)d+=f(g,Rr(P,t));return d},dP=(e)=>`"${e.replace(/\\([\s\S])|(")/g,"\\$1$2")}"`,V_=jl(fP(dP));var Io={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},XU={None:[],All:[],Trace:[Io.gray],Debug:[Io.blue],Info:[Io.green],Warning:[Io.yellow],Error:[Io.red],Fatal:[Io.bgBrightRed,Io.black]};var J_=typeof process==="object"&&process!==null&&typeof process.stdout==="object"&&process.stdout!==null,e1=J_&&process.stdout.isTTY===!0,t1=J_||"Deno"in globalThis;var G_="effect/MetricBoundaries",Xd=Symbol.for(G_);class Y_{values;[Xd]=Xd;constructor(e){this.values=e,this._hash=m(ne(G_),H(wt(this.values)))}_hash;[k](){return this._hash}[O](e){return hP(e)&&b(this.values,e.values)}pipe(){return y(this,arguments)}}var hP=(e)=>_(e,Xd),gP=(e)=>{let t=m(e,Tp(Re(Number.POSITIVE_INFINITY)),Pp);return new Y_(t)};var Z_=(e)=>m(Ep(e.count-1,(t)=>e.start*Math.pow(e.factor,t)),ds,gP);var xP="effect/MetricKeyType",Q_=Symbol.for(xP),X_="effect/MetricKeyType/Counter",em=Symbol.for(X_),SP="effect/MetricKeyType/Frequency",bP=Symbol.for(SP),_P="effect/MetricKeyType/Gauge",wP=Symbol.for(_P),ew="effect/MetricKeyType/Histogram",tm=Symbol.for(ew),EP="effect/MetricKeyType/Summary",OP=Symbol.for(EP),tw={_In:(e)=>e,_Out:(e)=>e};class rw{incremental;bigint;[Q_]=tw;[em]=em;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=ne(X_)}_hash;[k](){return this._hash}[O](e){return rm(e)}pipe(){return y(this,arguments)}}class nw{boundaries;[Q_]=tw;[tm]=tm;constructor(e){this.boundaries=e,this._hash=m(ne(ew),H(S(this.boundaries)))}_hash;[k](){return this._hash}[O](e){return nm(e)&&b(this.boundaries,e.boundaries)}pipe(){return y(this,arguments)}}var ow=(e)=>new rw(e?.incremental??!1,e?.bigint??!1);var iw=(e)=>new nw(e);var rm=(e)=>_(e,em),sw=(e)=>_(e,bP),aw=(e)=>_(e,wP),nm=(e)=>_(e,tm),cw=(e)=>_(e,OP);var TP="effect/MetricKey",uw=Symbol.for(TP),kP={_Type:(e)=>e},AP=mn(b);class $l{name;keyType;description;tags;[uw]=kP;constructor(e,t,r,n=[]){this.name=e,this.keyType=t,this.description=r,this.tags=n,this._hash=m(ne(this.name+this.description),H(S(this.keyType)),H(wt(this.tags)))}_hash;[k](){return this._hash}[O](e){return IP(e)&&this.name===e.name&&b(this.keyType,e.keyType)&&b(this.description,e.description)&&AP(this.tags,e.tags)}pipe(){return y(this,arguments)}}var IP=(e)=>_(e,uw),pw=(e,t)=>new $l(e,ow(t),Pr(t?.description));var fw=(e,t,r)=>new $l(e,iw(t),Pr(r));var dw=p(2,(e,t)=>t.length===0?e:new $l(e.name,e.keyType,e.description,dn(e.tags,t)));var mw=Symbol.for("effect/MutableHashMap"),vP={[mw]:mw,[Symbol.iterator](){return new om(this)},toString(){return oe(this.toJSON())},toJSON(){return{_id:"MutableHashMap",values:Array.from(this).map(X)}},[J](){return this.toJSON()},pipe(){return y(this,arguments)}};class om{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 hw(this.self.buckets.values()),this.next();return e}[Symbol.iterator](){return new om(this.self)}}class hw{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(vP);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e};var Ln=p(2,(e,t)=>{if(rs(t)===!1)return e.referential.has(t)?I(e.referential.get(t)):w();let r=t[k](),n=e.buckets.get(r);if(n===void 0)return w();return CP(e,n,t)});var CP=(e,t,r,n=!1)=>{for(let o=0,i=t.length;o<i;o++)if(r[O](t[o][0])){let s=t[o][1];if(n)t.splice(o,1),e.bucketsSize--;return I(s)}return w()},ki=p(2,(e,t)=>ue(Ln(e,t))),Ai=p(3,(e,t,r)=>{if(rs(t)===!1)return e.referential.set(t,r),e;let n=t[k](),o=e.buckets.get(n);if(o===void 0)return e.buckets.set(n,[[t,r]]),e.bucketsSize++,e;return PP(e,o,t),o.push([t,r]),e.bucketsSize++,e}),PP=(e,t,r)=>{for(let n=0,o=t.length;n<o;n++)if(r[O](t[n][0])){t.splice(n,1),e.bucketsSize--;return}};var NP="effect/MetricState",ea=Symbol.for(NP),yw="effect/MetricState/Counter",im=Symbol.for(yw),xw="effect/MetricState/Frequency",sm=Symbol.for(xw),Sw="effect/MetricState/Gauge",am=Symbol.for(Sw),bw="effect/MetricState/Histogram",cm=Symbol.for(bw),_w="effect/MetricState/Summary",lm=Symbol.for(_w),ta={_A:(e)=>e};class ww{count;[ea]=ta;[im]=im;constructor(e){this.count=e}[k](){return m(S(yw),H(S(this.count)),Z(this))}[O](e){return LP(e)&&this.count===e.count}pipe(){return y(this,arguments)}}var MP=mn(b);class Ew{occurrences;[ea]=ta;[sm]=sm;constructor(e){this.occurrences=e}_hash;[k](){return m(ne(xw),H(wt(pe(this.occurrences.entries()))),Z(this))}[O](e){return DP(e)&&MP(pe(this.occurrences.entries()),pe(e.occurrences.entries()))}pipe(){return y(this,arguments)}}class Ow{value;[ea]=ta;[am]=am;constructor(e){this.value=e}[k](){return m(S(Sw),H(S(this.value)),Z(this))}[O](e){return qP(e)&&this.value===e.value}pipe(){return y(this,arguments)}}class Tw{buckets;count;min;max;sum;[ea]=ta;[cm]=cm;constructor(e,t,r,n,o){this.buckets=e,this.count=t,this.min=r,this.max=n,this.sum=o}[k](){return m(S(bw),H(S(this.buckets)),H(S(this.count)),H(S(this.min)),H(S(this.max)),H(S(this.sum)),Z(this))}[O](e){return UP(e)&&b(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return y(this,arguments)}}class kw{error;quantiles;count;min;max;sum;[ea]=ta;[lm]=lm;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}[k](){return m(S(_w),H(S(this.error)),H(S(this.quantiles)),H(S(this.count)),H(S(this.min)),H(S(this.max)),H(S(this.sum)),Z(this))}[O](e){return HP(e)&&this.error===e.error&&b(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return y(this,arguments)}}var Aw=(e)=>new ww(e),Iw=(e)=>new Ew(e),Rw=(e)=>new Ow(e),vw=(e)=>new Tw(e.buckets,e.count,e.min,e.max,e.sum),Cw=(e)=>new kw(e.error,e.quantiles,e.count,e.min,e.max,e.sum);var LP=(e)=>_(e,im),DP=(e)=>_(e,sm),qP=(e)=>_(e,am),UP=(e)=>_(e,cm),HP=(e)=>_(e,lm);var $P="effect/MetricHook",BP=Symbol.for($P),KP={_In:(e)=>e,_Out:(e)=>e},ra=(e)=>({[BP]:KP,pipe(){return y(this,arguments)},...e});var Pw=BigInt(0),Nw=(e)=>{let t=e.keyType.bigint?Pw:0,r=e.keyType.incremental?e.keyType.bigint?(o)=>o>=Pw:(o)=>o>=0:(o)=>!0,n=(o)=>{if(r(o))t=t+o};return ra({get:()=>Aw(t),update:n,modify:n})},Mw=(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 ra({get:()=>Iw(t),update:r,modify:r})},Lw=(e,t)=>{let r=t;return ra({get:()=>Rw(r),update:(n)=>{r=n},modify:(n)=>{r=r+n}})},Dw=(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,Nr(gr),Gt((f,d)=>{o[d]=f}));let l=(f)=>{let d=0,h=r;while(d!==h){let g=Math.floor(d+(h-d)/2),P=o[g];if(f<=P)h=g;else d=g;if(h===d+1)if(f<=o[d])h=d;else d=h}if(n[d]=n[d]+1,i=i+1,s=s+f,f<a)a=f;if(f>c)c=f},u=()=>{let f=no(r),d=0;for(let h=0;h<r;h++){let g=o[h],P=n[h];d=d+P,f[h]=[g,d]}return f};return ra({get:()=>vw({buckets:u(),count:i,min:a,max:c,sum:s}),update:l,modify:l})},qw=(e)=>{let{error:t,maxAge:r,maxSize:n,quantiles:o}=e.keyType,i=m(o,Nr(gr)),s=no(n),a=0,c=0,l=0,u=0,f=0,d=(g)=>{let P=[],x=0;while(x!==n-1){let E=s[x];if(E!=null){let[W,F]=E,D=Ec(g-W);if(Sx(D,ff)&&xx(D,r))P.push(F)}x=x+1}return WP(t,i,Nr(P,gr))},h=(g,P)=>{if(n>0){a=a+1;let x=a%n;s[x]=[P,g]}u=c===0?g:Math.min(u,g),f=c===0?g:Math.max(f,g),c=c+1,l=l+g};return ra({get:()=>Cw({error:t,quantiles:d(Date.now()),count:c,min:u,max:f,sum:l}),update:([g,P])=>h(g,P),modify:([g,P])=>h(g,P)})},WP=(e,t,r)=>{let n=r.length;if(!se(t))return Mr();let o=t[0],i=t.slice(1),s=Fw(e,n,w(),0,o,r),a=Ve(s);return i.forEach((c)=>{a.push(Fw(e,n,s.value,s.consumed,c,s.rest))}),Gt(a,(c)=>[c.quantile,c.value])},Fw=(e,t,r,n,o,i)=>{let s=e,a=t,c=r,l=n,u=o,f=i,d=e,h=t,g=r,P=n,x=o,E=i;while(!0){if(!se(f))return{quantile:u,value:w(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:I(Ip(f)),consumed:l+f.length,rest:[]};let W=Ie(f),F=iy(f,(v)=>v===W),D=u*a,T=s/2*D,A=l+F[0].length,R=Math.abs(A-D);if(A<D-T){d=s,h=a,g=Fr(f),P=A,x=u,E=F[1],s=d,a=h,c=g,l=P,u=x,f=E;continue}if(A>D+T){let v=ye(c)?I(W):c;return{quantile:u,value:v,consumed:l,rest:f}}switch(c._tag){case"None":{d=s,h=a,g=Fr(f),P=A,x=u,E=F[1],s=d,a=h,c=g,l=P,u=x,f=E;continue}case"Some":{let v=Math.abs(D-c.value);if(R<v){d=s,h=a,g=Fr(f),P=A,x=u,E=F[1],s=d,a=h,c=g,l=P,u=x,f=E;continue}return{quantile:u,value:I(c.value),consumed:l,rest:f}}}}throw Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues")};var VP="effect/MetricPair",JP=Symbol.for(VP),GP={_Type:(e)=>e};var Uw=(e,t)=>({[JP]:GP,metricKey:e,metricState:t,pipe(){return y(this,arguments)}});var ZP="effect/MetricRegistry",Hw=Symbol.for(ZP);class jw{[Hw]=Hw;map=gw();snapshot(){let e=[];for(let[t,r]of this.map)e.push(Uw(t,r.get()));return e}get(e){let t=m(this.map,Ln(e),ft);if(t==null){if(rm(e.keyType))return this.getCounter(e);if(aw(e.keyType))return this.getGauge(e);if(sw(e.keyType))return this.getFrequency(e);if(nm(e.keyType))return this.getHistogram(e);if(cw(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,Ln(e),ft);if(t==null){let r=Nw(e);if(!m(this.map,ki(e)))m(this.map,Ai(e,r));t=r}return t}getFrequency(e){let t=m(this.map,Ln(e),ft);if(t==null){let r=Mw(e);if(!m(this.map,ki(e)))m(this.map,Ai(e,r));t=r}return t}getGauge(e){let t=m(this.map,Ln(e),ft);if(t==null){let r=Lw(e,e.keyType.bigint?BigInt(0):0);if(!m(this.map,ki(e)))m(this.map,Ai(e,r));t=r}return t}getHistogram(e){let t=m(this.map,Ln(e),ft);if(t==null){let r=Dw(e);if(!m(this.map,ki(e)))m(this.map,Ai(e,r));t=r}return t}getSummary(e){let t=m(this.map,Ln(e),ft);if(t==null){let r=qw(e);if(!m(this.map,ki(e)))m(this.map,Ai(e,r));t=r}return t}}var $w=()=>new jw;var XP="effect/Metric",e0=Symbol.for(XP),t0={_Type:(e)=>e,_In:(e)=>e,_Out:(e)=>e},Bw=N(Symbol.for("effect/Metric/globalMetricRegistry"),()=>$w()),Kw=function(e,t,r,n){let o=Object.assign((i)=>Gc(i,(s)=>n0(o,s)),{[e0]:t0,keyType:e,unsafeUpdate:t,unsafeValue:r,unsafeModify:n,register(){return this.unsafeValue([]),this},pipe(){return y(this,arguments)}});return o};var na=(e,t)=>Ww(pw(e,t));var Ww=(e)=>{let t,r=new WeakMap,n=(o)=>{if(o.length===0){if(t!==void 0)return t;return t=Bw.get(e),t}let i=r.get(o);if(i!==void 0)return i;return i=Bw.get(dw(e,o)),r.set(o,i),i};return Kw(e.keyType,(o,i)=>n(i).update(o),(o)=>n(o).get(),(o,i)=>n(i).modify(o))};var zw=(e,t,r)=>Ww(fw(e,t,r));var Vw=p(3,(e,t,r)=>r0(e,[L_(t,r)]));var r0=p(2,(e,t)=>Kw(e.keyType,(r,n)=>e.unsafeUpdate(r,dn(t,n)),(r)=>e.unsafeValue(dn(t,r)),(r,n)=>e.unsafeModify(r,dn(t,n))));var n0=p(2,(e,t)=>_o(Bs,(r)=>C(()=>e.unsafeUpdate(t,r))));var i0="effect/Request",s0=Symbol.for(i0),a0={_E:(e)=>e,_A:(e)=>e},P1={...cs,[s0]:a0};var Jw=p(2,(e,t)=>_o(Dl,(r)=>C(()=>{if(r.has(e)){let n=r.get(e);if(!n.state.completed)n.state.completed=!0,al(n.result,t)}})));var c0="effect/Supervisor",Bl=Symbol.for(c0),um={_T:(e)=>e};class Kl{underlying;value0;[Bl]=um;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 Kl(this,m(this.value,we(e)))}zip(e){return new Wl(this,e)}}class Wl{left;right;_tag="Zip";[Bl]=um;constructor(e,t){this.left=e,this.right=t}get value(){return Zc(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 Kl(this,m(this.value,we(e)))}zip(e){return new Wl(this,e)}}var pm=(e)=>_(e,Bl)&&es(e,"Zip");class Gw{effect;[Bl]=um;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 Kl(this,m(this.value,we(e)))}zip(e){return new Wl(this,e)}onRun(e,t){return e()}}var l0=(e)=>new Gw(e),Ro=N("effect/Supervisor/none",()=>l0(ve));var Yw=Tn;var Zw="Empty",Qw="AddSupervisor",Xw="RemoveSupervisor",eE="AndThen",Ii={_tag:Zw},zl=(e,t)=>({_tag:eE,first:e,second:t}),p0=(e,t)=>f0(t,Re(e)),f0=(e,t)=>{let r=e,n=t;while(Yt(n)){let o=Zt(n);switch(o._tag){case Zw:{n=Qt(n);break}case Qw:{r=r.zip(o.supervisor),n=Qt(n);break}case Xw:{r=dm(r,o.supervisor),n=Qt(n);break}case eE:{n=Je(o.first)(Je(o.second)(Qt(n)));break}}}return r},dm=(e,t)=>{if(b(e,t))return Ro;else if(pm(e))return dm(e.left,t).zip(dm(e.right,t));else return e},Vl=(e)=>{if(b(e,Ro))return pr();else if(pm(e))return m(Vl(e.left),Hr(Vl(e.right)));else return ao(e)},d0=(e,t)=>{if(b(e,t))return Ii;let r=Vl(e),n=Vl(t),o=m(n,zp(r),lo(Ii,(s,a)=>zl(s,{_tag:Qw,supervisor:a}))),i=m(r,zp(n),lo(Ii,(s,a)=>zl(s,{_tag:Xw,supervisor:a})));return zl(o,i)},tE=Yw({empty:Ii,patch:p0,combine:zl,diff:d0});var E0=na("effect_fiber_started",{incremental:!0}),rE=na("effect_fiber_active"),O0=na("effect_fiber_successes",{incremental:!0}),T0=na("effect_fiber_failures",{incremental:!0}),k0=Vw(zw("effect_fiber_lifetimes",Z_({start:0.5,factor:2,count:35})),"time_unit","milliseconds"),oa="Continue",A0="Done",nE="Yield",I0={_E:(e)=>e,_A:(e)=>e},Jl=(e)=>{throw Error(`BUG: FiberRuntime - ${Rr(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},Gr=Symbol.for("effect/internal/fiberRuntime/YieldedOp"),Yr=N("effect/internal/fiberRuntime/yieldedOpChannel",()=>({currentOp:null})),ia={[Bo]:(e,t,r)=>Ke(()=>t.effect_instruction_i1(r)),["OnStep"]:(e,t,r)=>ge(ge(r)),[Ko]:(e,t,r)=>Ke(()=>t.effect_instruction_i2(r)),[ss]:(e,t,r)=>{if(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),Wr(e.currentRuntimeFlags)&&e.isInterrupted())return ae(e.getInterruptedCause());else return ge(r)},[Wo]:(e,t,r)=>{if(Ke(()=>t.effect_instruction_i2(r)),Ke(()=>t.effect_instruction_i0()))return e.pushStack(t),Ke(()=>t.effect_instruction_i1());else return ve},[zo]:(e,t,r)=>{while(!0){let n=Ke(()=>t.effect_instruction_i0.next(r));if(n.done)return ge(n.value);let o=sp(n.value);if(!xi(o))return e.pushStack(t),o;else if(o._tag==="Failure")return o;r=o.value}}},R0={[Vd]:(e,t,r,n)=>(e.processNewInterruptSignal(n.cause),Wr(t)?ae(n.cause):r),[Gd]:(e,t,r,n)=>{throw Error("It is illegal to have multiple concurrent run loops in a single fiber")},[Jd]:(e,t,r,n)=>(n.onFiber(e,Pd(t)),r),[Yd]:(e,t,r,n)=>L(Hs(),()=>r)},v0=(e)=>So(sS(e),(t)=>vo(cS(t),([r,n])=>{let o=new Map,i=[];for(let a of n){i.push(Dr(a));for(let c of a)o.set(c.request,c)}let s=i.flat();return Cn(W0(r.runAll(i),s,()=>s.forEach((a)=>{a.listeners.interrupted=!0})),Dl,o)},!1,!1)),C0=as();class Gl extends wd{[Zd]=Qd;[K_]=I0;_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,Hf(r)){let n=this.getFiberRef(Bs);E0.unsafeUpdate(1,n),rE.unsafeUpdate(1,n)}this.refreshRefCache()}commit(){return Hl(this)}id(){return this._fiberId}resume(e){this.tell(Ao(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>{if(d_(t))return e.currentRuntimeFlags;return t.runtimeFlags})}scope(){return $_(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(Ks)}fiberRefs(){return this.ask((e)=>e.getFiberRefs())}ask(e){return fe(()=>{let t=BS(this._fiberId);return this.tell(Ti((r,n)=>{al(t,C(()=>e(r,n)))})),sl(t)})}tell(e){if(this._queue.push(e),!this._running)this._running=!0,this.drainQueueLaterOnExecutor()}get await(){return An((e)=>{let t=(r)=>e(ee(r));if(this._exitValue!==null){t(this._exitValue);return}return this.tell(Ti((r,n)=>{if(r._exitValue!==null)t(this._exitValue);else r.addObserver(t)})),C(()=>this.tell(Ti((r,n)=>{r.removeObserver(t)})))},this.id())}get inheritAll(){return We((e,t)=>{let r=e.id(),n=e.getFiberRefs(),o=t.runtimeFlags,i=this.getFiberRefs(),s=Id(n,r,i);e.setFiberRefs(s);let a=e.getFiberRef(iE),c=m(Ps(o,a),Kf(Kr),Kf(Dc));return sd(c)})}get poll(){return C(()=>Pr(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return C(()=>this.tell(ql(Xt(e))))}unsafeInterruptAsFork(e){this.tell(ql(Xt(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(iE,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=Zs(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=wi(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(Ys),this.currentTracer=this.currentDefaultServices.unsafeMap.get(Gs.key),this.currentSupervisor=this.getFiberRef(K0),this.currentScheduler=this.getFiberRef(Ll),this.currentContext=this.getFiberRef(Eo),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[Mn];globalThis[Mn]=this;try{while(t===oa)t=this._queue.length===0?A0:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[Mn]=r}if(this._queue.length>0&&!this._running)if(this._running=!0,t===nE)this.drainQueueLaterOnExecutor(),e=!1;else e=!0;else e=!1}}drainQueueLaterOnExecutor(){this.currentScheduler.scheduleTask(this.run,this.getFiberRef(gi),this)}drainQueueWhileRunning(e,t){let r=t;while(this._queue.length>0){let n=this._queue.splice(0,1)[0];r=R0[n._tag](this,e,r,n)}return r}isInterrupted(){return!yc(this.getFiberRef(Ks))}addInterruptedCause(e){let t=this.getFiberRef(Ks);this.setFiberRef(Ks,Ge(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(ql(Xt(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return Us({while:()=>!t,body:()=>{let n=e.next();if(!n.done)return Vr(n.value.await);else return C(()=>{t=!0})},step:()=>{}})}return null}reportExitValue(e){if(Hf(this.currentRuntimeFlags)){let t=this.getFiberRef(Bs),r=this.id().startTimeMillis,n=Date.now();switch(k0.unsafeUpdate(n-r,t),rE.unsafeUpdate(-1,t),e._tag){case ut:{O0.unsafeUpdate(1,t);break}case lt:{T0.unsafeUpdate(1,t);break}}}if(e._tag==="Failure"){let t=this.getFiberRef(US);if(!si(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(L0)}log(e,t,r){let n=ue(r)?r.value:this.getFiberRef(pd),o=this.getFiberRef(P0);if(m_(o,n))return;let i=this.getFiberRef(MS),s=this.getFiberRef(NS),a=this.getLoggers(),c=this.getFiberRefs();if(gs(a)>0){let l=bs(this.getFiberRef(Ys),Js),u=new Date(l.unsafeCurrentTimeMillis());Ag(c,()=>{for(let f of a)f.log({fiberId:this.id(),logLevel:n,message:e,cause:t,context:c,spans:i,annotations:s,date:u})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case Yd:return nE;case Vd:{if(this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null)this._asyncInterruptor(ae(e.cause)),this._asyncInterruptor=null;return oa}case Gd:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),oa;case Jd:return e.onFiber(this,this._exitValue!==null?p_:f_(this.currentRuntimeFlags,this._asyncBlockingOn)),oa;default:return Jl(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=Wr(this.currentRuntimeFlags)&&this.isInterrupted()?ae(this.getInterruptedCause()):e;while(t!==null){let r=t,n=this.runLoop(r);if(n===Gr){let o=Yr.currentOp;if(Yr.currentOp=null,o._op===Vo)if(rS(this.currentRuntimeFlags))this.tell(q_()),this.tell(Ao(Ut)),t=null;else t=Ut;else if(o._op===eo)t=null}else{this.currentRuntimeFlags=m(this.currentRuntimeFlags,Df(Dc));let o=this.interruptAllChildren();if(o!==null)t=L(o,()=>n);else{if(this._queue.length===0)this.setExitValue(n);else this.tell(Ao(n));t=null}}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(!this._running){this._running=!0;let t=globalThis[Mn];globalThis[Mn]=this;try{this.evaluateEffect(e)}finally{if(this._running=!1,globalThis[Mn]=t,this._queue.length>0)this.drainQueueLaterOnExecutor()}}else this.tell(Ao(e))}startFork(e){this.tell(Ao(e))}patchRuntimeFlags(e,t){let r=Fs(e,t);return globalThis[Mn]=this,this.currentRuntimeFlags=r,r}initiateAsync(e,t){let r=!1,n=(o)=>{if(!r)r=!0,this.tell(Ao(o))};if(Wr(e))this._asyncInterruptor=n;try{t(n)}catch(o){n(Ye(Ot(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!==is)return e;e=this.popStack()}}getNextFailCont(){let e=this.popStack();while(e){if(e._op!==Bo&&e._op!==Wo&&e._op!==zo)return e;e=this.popStack()}}[Rg](e){return C(()=>_s(this.currentContext,e))}["Left"](e){return qe(e.left)}["None"](e){return qe(new Ws)}["Right"](e){return ge(e.right)}["Some"](e){return ge(e.value)}["Micro"](e){return Ns((t)=>{let r=t,n=R_(k_(e,this.currentContext));return n.addObserver((o)=>{if(o._tag==="Success")return r(ge(o.value));switch(o.cause._tag){case"Interrupt":return r(ae(Xt(Lt)));case"Fail":return r(qe(o.cause.error));case"Die":return r(zc(o.cause.defect))}}),Ns((o)=>{r=(i)=>{o(ve)},n.unsafeInterrupt()})})}[Ja](e){let t=Ke(()=>e.effect_instruction_i0()),r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in ia))Jl(r);return ia[r._op](this,r,t)}else return Yr.currentOp=ge(t),Gr}[ut](e){let t=e,r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in ia))Jl(r);return ia[r._op](this,r,t.effect_instruction_i0)}else return Yr.currentOp=t,Gr}[lt](e){let t=e.effect_instruction_i0,r=this.getNextFailCont();if(r!==void 0)switch(r._op){case is:case Ko:if(!(Wr(this.currentRuntimeFlags)&&this.isInterrupted()))return Ke(()=>r.effect_instruction_i1(t));else return ae(bc(t));case"OnStep":if(!(Wr(this.currentRuntimeFlags)&&this.isInterrupted()))return ge(ae(t));else return ae(bc(t));case ss:if(this.patchRuntimeFlags(this.currentRuntimeFlags,r.patch),Wr(this.currentRuntimeFlags)&&this.isInterrupted())return ae(Ge(t,this.getInterruptedCause()));else return ae(t);default:Jl(r)}else return Yr.currentOp=ae(t),Gr}[Ga](e){return Ke(()=>e.effect_instruction_i0(this,Pd(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=e_(o.refs,t),a=Ps(o.flags,r);return ge(Kc(e.effect_instruction_i0,We((c)=>{while(n.length>0)c.pushStack(n.pop());return c.setFiberRefs(t_(c.id(),c.getFiberRefs())(s)),c.currentRuntimeFlags=Fs(a)(c.currentRuntimeFlags),e.effect_instruction_i1})))}return Rn((n)=>L(ym(Yf(e.effect_instruction_i0)),()=>n(e.effect_instruction_i1)))}["RunBlocked"](e){return v0(e.effect_instruction_i0)}[ro](e){let t=e.effect_instruction_i0,r=this.currentRuntimeFlags,n=Fs(r,t);if(Wr(n)&&this.isInterrupted())return ae(this.getInterruptedCause());else if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let o=Ps(n,r);return this.pushStack(new Zf(o,e)),Ke(()=>e.effect_instruction_i1(r))}else return Ut}[Bo](e){return this.pushStack(e),e.effect_instruction_i0}["OnStep"](e){return this.pushStack(e),e.effect_instruction_i0}[is](e){return this.pushStack(e),e.effect_instruction_i0}[Ko](e){return this.pushStack(e),e.effect_instruction_i0}[eo](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),Yr.currentOp=e,Gr}[Vo](e){return this._isYielding=!1,Yr.currentOp=e,Gr}[Wo](e){let{effect_instruction_i0:t,effect_instruction_i1:r}=e;if(t())return this.pushStack(e),r();else return Ut}[zo](e){return ia[zo](this,e,void 0)}[to](e){return Ke(()=>e.commit())}runLoop(e){let t=e;this.currentOpCount=0;while(!0){if((this.currentRuntimeFlags&tS)!==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=L(Hs({priority:r}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(C0!==t[kn]._V){let r=this.getFiberRef(HS);if(r._tag==="Some"){let n=t[kn]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${as()}, 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`,jr,r)}}return this[t._op](t)},this),t===Gr){let r=Yr.currentOp;if(r._op===Vo||r._op===eo)return Gr;return Yr.currentOp=null,r._op===ut||r._op===lt?r:ae(Ot(r))}}catch(r){if(t!==Gr&&!_(t,"_op")||!(t._op in this))t=td(`Not a valid effect: ${Rr(t)}`);else if(jS(r))t=ae(Ge(Ot(r),Xt(Lt)));else t=zc(r)}}}run=()=>{this.drainQueueOnCurrentThread()}}var P0=N("effect/FiberRef/currentMinimumLogLevel",()=>ze(h_("Info"))),F0=(e)=>jl((t)=>{let r=$b(t.context,Ys);bs(r,bl).unsafe.log(e.log(t))});var N0=N(Symbol.for("effect/Logger/defaultLogger"),()=>F0(V_));var M0=N(Symbol.for("effect/Logger/tracerLogger"),()=>jl(({annotations:e,cause:t,context:r,fiberId:n,logLevel:o,message:i})=>{let s=zd(En(Fn(r,Eo),_l));if(s._tag==="None"||s.value._tag==="ExternalSpan")return;let a=_s(Fn(r,Ys),Js),c={};for(let[l,u]of e)c[l]=u;if(c["effect.fiberId"]=Rx(n),c["effect.logLevel"]=o.label,t!==null&&t._tag!=="Empty")c["effect.cause"]=er(t,{renderErrorCause:!0});s.value.event(Rr(Array.isArray(i)&&i.length===1?i[0]:i),a.unsafeCurrentTimeNanos(),c)}));var L0=N(Symbol.for("effect/FiberRef/currentLoggers"),()=>PS(ao(N0,M0)));var sE=p((e)=>rp(e[0]),(e,t,r)=>We((n)=>{let o=r?.batching===!0||r?.batching==="inherit"&&n.getFiberRef(qS);if(r?.discard)return Bd(r.concurrency,()=>Ri(wl,r?.concurrentFinalizers)((i)=>o?vo(e,(s,a)=>i(t(s,a)),!0,!1,1):So(e,(s,a)=>i(t(s,a)))),()=>Ri(El,r?.concurrentFinalizers)((i)=>vo(e,(s,a)=>i(t(s,a)),o,!1)),(i)=>Ri(Ol(i),r?.concurrentFinalizers)((s)=>vo(e,(a,c)=>s(t(a,c)),o,!1,i)));return Bd(r?.concurrency,()=>Ri(wl,r?.concurrentFinalizers)((i)=>o?mm(e,1,(s,a)=>i(t(s,a)),!0):qt(e,(s,a)=>i(t(s,a)))),()=>Ri(El,r?.concurrentFinalizers)((i)=>aE(e,(s,a)=>i(t(s,a)),o)),(i)=>Ri(Ol(i),r?.concurrentFinalizers)((s)=>mm(e,i,(a,c)=>s(t(a,c)),o)))})),aE=(e,t,r)=>fe(()=>{let n=pe(e),o=Array(n.length);return vn(vo(n,(s,a)=>L(t(s,a),(c)=>C(()=>o[a]=c)),r,!1),ee(o))}),vo=(e,t,r,n,o)=>Rn((i)=>id((s)=>We((a)=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return ve;let u=0,f=!1,d=o?Math.min(c.length,o):c.length,h=new Set,g=[],P=()=>h.forEach((v)=>{v.currentScheduler.scheduleTask(()=>{v.unsafeInterruptAsFork(a.id())},0,v)}),x=[],E=[],W=[],F=()=>{let v=g.filter(({exit:te})=>te._tag==="Failure").sort((te,re)=>te.index<re.index?-1:te.index===re.index?0:1).map(({exit:te})=>te);if(v.length===0)v.push(Ut);return v},D=(v,te=!1)=>{let re=Yc(s(v)),Y=q0(re,a,a.currentRuntimeFlags,Xs);return a.currentScheduler.scheduleTask(()=>{if(te)Y.unsafeInterruptAsFork(a.id());Y.resume(re)},0,Y),Y},T=()=>{if(!n)l-=c.length,c=[];f=!0,P()},A=r?od:In,R=D(An((v)=>{let te=(Y,xe)=>{if(Y._op==="Blocked")W.push(Y);else if(g.push({index:xe,exit:Y}),Y._op==="Failure"&&!f)T()},re=()=>{if(c.length>0){let Y=c.pop(),xe=u++,Rt=()=>{let $e=c.pop();return xe=u++,L(Hs(),()=>L(A(i(t($e,xe))),vt))},vt=($e)=>{if(c.length>0){if(te($e,xe),c.length>0)return Rt()}return ee($e)},Bt=L(A(i(t(Y,xe))),vt),je=D(Bt);if(x.push(je),h.add(je),f)je.currentScheduler.scheduleTask(()=>{je.unsafeInterruptAsFork(a.id())},0,je);je.addObserver(($e)=>{let Ct;if($e._op==="Failure")Ct=$e;else Ct=$e.effect_instruction_i0;if(E.push(je),h.delete(je),te(Ct,xe),g.length===l)v(ee(ce(To(F(),{parallel:!0}),()=>Ut)));else if(W.length+g.length===l){let qo=F(),Hu=W.map((Ui)=>Ui.effect_instruction_i0).reduce(zf);v(ee(Kc(Hu,vo([ce(To(qo,{parallel:!0}),()=>Ut),...W.map((Ui)=>Ui.effect_instruction_i1)],(Ui)=>Ui,r,!0,o))))}else re()})}};for(let Y=0;Y<d;Y++)re()}));return Vr(hi(Ds(i(Hl(R))),il({onFailure:(v)=>{T();let te=W.length+1,re=Math.min(typeof o==="number"?o:W.length,W.length),Y=Array.from(W);return An((xe)=>{let Rt=[],vt=0,Bt=0,je=(Ct,qo)=>(Hu)=>{if(Rt[Ct]=Hu,vt++,vt===te)xe(ge(ae(v)));if(Y.length>0&&qo)$e()},$e=()=>{D(Y.pop(),!0).addObserver(je(Bt,!0)),Bt++};R.addObserver(je(Bt,!1)),Bt++;for(let Ct=0;Ct<re;Ct++)$e()})},onSuccess:()=>qt(E,(v)=>v.inheritAll)})))}))),mm=(e,t,r,n)=>fe(()=>{let o=pe(e),i=Array(o.length);return vn(vo(o,(a,c)=>we(r(a,c),(l)=>i[c]=l),n,!1,t),ee(i))});var ym=(e)=>U0(e,Xs);var D0=(e,t,r,n=null)=>{let o=cE(e,t,r,n);return o.resume(e),o},q0=(e,t,r,n=null)=>cE(e,t,r,n),cE=(e,t,r,n=null)=>{let o=vc(),i=t.getFiberRefs(),s=Rd(i,o),a=new Gl(o,s,r),c=Fn(s,Eo),l=a.currentSupervisor;return l.onStart(c,e,I(t),a),a.addObserver((f)=>l.onEnd(f,a)),(n!==null?n:m(t.getFiberRef(Bc),ce(()=>t.scope()))).add(r,a),a},U0=(e,t)=>We((r,n)=>ee(D0(e,r,n.runtimeFlags,t)));var hm=(e)=>ko((t)=>Ee(En(t,sa),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Parallel":return e;case"Sequential":case"ParallelN":return L(yi(r,El),(n)=>xm(e,n))}}})),oE=(e)=>(t)=>ko((r)=>Ee(En(r,sa),{onNone:()=>t,onSome:(n)=>{if(n.strategy._tag==="ParallelN"&&n.strategy.parallelism===e)return t;return L(yi(n,Ol(e)),(o)=>xm(t,o))}}));var Ri=(e,t)=>(r)=>ko((n)=>Ee(En(n,sa),{onNone:()=>r(Q),onSome:(o)=>{if(t===!0){let i=e._tag==="Parallel"?hm:e._tag==="Sequential"?gm:oE(e.parallelism);switch(o.strategy._tag){case"Parallel":return i(r(hm));case"Sequential":return i(r(gm));case"ParallelN":return i(r(oE(o.strategy.parallelism)))}}else return r(Q)}}));var gm=(e)=>ko((t)=>Ee(En(t,sa),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Sequential":return e;case"Parallel":case"ParallelN":return L(yi(r,wl),(n)=>xm(e,n))}}}));var sa=dt("effect/Scope");var H0=(e,t)=>{if(e.state._tag==="Open")e.state.finalizers.set({},t)},j0={[tl]:tl,[rl]:rl,pipe(){return y(this,arguments)},fork(e){return C(()=>{let t=$0(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),H0(t,(o)=>C(()=>{if(this.state._tag==="Open")this.state.finalizers.delete(r)})),t})},close(e){return fe(()=>{if(this.state._tag==="Closed")return ve;let t=Array.from(this.state.finalizers.values()).reverse();if(this.state={_tag:"Closed",exit:e},t.length===0)return ve;return Ed(this.strategy)?m(qt(t,(r)=>In(r(e))),L((r)=>m(To(r),zt(zs),ce(()=>Ut)))):Od(this.strategy)?m(aE(t,(r)=>In(r(e)),!1),L((r)=>m(To(r,{parallel:!0}),zt(zs),ce(()=>Ut)))):m(mm(t,this.strategy.parallelism,(r)=>In(r(e)),!1),L((r)=>m(To(r,{parallel:!0}),zt(zs),ce(()=>Ut))))})},addFinalizer(e){return fe(()=>{if(this.state._tag==="Closed")return e(this.state.exit);return this.state.finalizers.set({},e),ve})}},$0=(e=_i)=>{let t=Object.create(j0);return t.strategy=e,t.state={_tag:"Open",finalizers:new Map},t};var xm=p(2,(e,t)=>yd(e,ws(px(sa,t))));var B0=(e)=>wo(e,{differ:tE,fork:Ii});var iE=FS(nS),K0=B0(Ro);var lE=p(2,(e,t)=>Rn((r)=>Dt(r(e),{onFailure:(n)=>Dt(t,{onFailure:(o)=>Ye(Ge(n,o)),onSuccess:()=>Ye(n)}),onSuccess:(n)=>zr(t,n)}))),W0=(e,t,r)=>Ls((n)=>lE(L(ym(Vc(e)),(o)=>An((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"&&xi(l.result.state.current.effect)&&l.result.state.current.effect._tag==="Failure"&&xc(l.result.state.current.effect.cause))return!0;else return!1}))c.forEach((l)=>l()),r?.(),i(kS(o))}};o.addObserver((l)=>{c.forEach((u)=>u()),i(l)});let c=t.map((l,u)=>{let f=(d)=>{s[u]=d,a()};return l.listeners.addObserver(f),()=>l.listeners.removeObserver(f)});return a(),C(()=>{c.forEach((l)=>l())})})),fe(()=>{let o=t.flatMap((i)=>{if(!i.state.completed)return[i];return[]});return So(o,(i)=>Jw(i.request,hd(n)))})));var pE=fd;var fE=yi;var bm=(e)=>function(){if(arguments.length===1){let t=arguments[0];return(r,...n)=>e(t,r,...n)}return e.apply(this,arguments)},dE=bm((e,t,r)=>{let n=vc(),o=[[Eo,[[n,e.context]]]];if(r?.scheduler)o.push([Ll,[[n,r.scheduler]]]);let i=Bb(e.fiberRefs,{entries:o,forkAs:n});if(r?.updateRefs)i=r.updateRefs(i,n);let s=new Gl(n,i,e.runtimeFlags),a=t;if(r?.scope)a=L(fE(r.scope,_i),(l)=>vn(nl(l,Ls((u)=>b(u,s.id())?ve:$s(s,u))),hi(t,(u)=>pE(l,u))));let c=s.currentSupervisor;if(c!==Ro)c.onStart(e.context,a,w(),s),s.addObserver((l)=>c.onEnd(l,s));if(Xs.add(e.runtimeFlags,s),r?.immediate===!1)s.resume(a);else s.start(a);return s});var G0=bm((e,t)=>{let r=X0(e)(t);if(r._tag==="Failure")throw Z0(r.effect_instruction_i0);return r.effect_instruction_i0});class mE 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 Y0=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new mE(e);return Error.stackTraceLimit=t,r};var Sm=Symbol.for("effect/Runtime/FiberFailure"),Yl=Symbol.for("effect/Runtime/FiberFailure/Cause");class hE extends Error{[Sm];[Yl];constructor(e){let t=ys(e)[0];super(t?.message||"An error has occurred");if(this[Sm]=Sm,this[Yl]=e,this.name=t?`(FiberFailure) ${t.name}`:"FiberFailure",t?.stack)this.stack=t.stack}toJSON(){return{_id:"FiberFailure",cause:this[Yl].toJSON()}}toString(){return"(FiberFailure) "+er(this[Yl],{renderErrorCause:!0})}[J](){return this.toString()}}var Z0=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new hE(e);return Error.stackTraceLimit=t,r};var Q0=(e)=>{let t=e;switch(t._op){case"Failure":case"Success":return t;case"Left":return Vs(t.left);case"Right":return ge(t.right);case"Some":return ge(t.value);case"None":return Vs(new Ws)}},X0=bm((e,t)=>{let r=Q0(t);if(r)return r;let n=new Qs,o=dE(e)(t,{scheduler:n});n.flush();let i=o.unsafePoll();if(i)return i;return md(Wc(Y0(o),cl(o)))});class gE{context;runtimeFlags;fiberRefs;constructor(e,t,r){this.context=e,this.runtimeFlags=t,this.fiberRefs=r}pipe(){return y(this,arguments)}}var eF=(e)=>new gE(e.context,e.runtimeFlags,e.fiberRefs);var tF=Uf(Kr,Lf,Mf),yE=eF({context:wn(),runtimeFlags:tF,fiberRefs:Kb()});var xE=dE(yE);var SE=G0(yE);var bE=di;var aa=sE;var ca=fe;var kt=ve;var _E=Ms;var Zl=we;var wE=bo;var Co=xo;var rr=L;var EE=xE;var OE=SE;var _m=(e,t)=>{switch(t._tag){case"StringKeyword":case"TemplateLiteral":return Object.keys(e);case"SymbolKeyword":return Object.getOwnPropertySymbols(e);case"Refinement":return _m(e,t.from)}},la=(e)=>{let t=!1,r;return()=>{if(t)return r;return r=e(),t=!0,r}},wm=(e)=>Array.isArray(e),kE=(e)=>!Array.isArray(e),TE=(e)=>`[${os(e)}]`,Ql=(e)=>wm(e)?e.map(TE).join(""):TE(e);var Dn=(e,t,r,n)=>{let o=e;if(r&&se(r))o+=`
34
- at path: ${Ql(r)}`;if(t!==void 0)o+=`
33
+ `)}`;super(i);this._tag=e,this.traces=r,this[E_]=PC,this.name=o,this.stack=s}pipe(){return y(this,arguments)}toString(){return this.stack}[Z](){return this.stack}}class k_ extends Ud{defect;constructor(e,t=[]){super("Die",e,t);this.defect=e}}var FC=(e,t=[])=>new k_(e,t);class A_ extends Ud{constructor(e=[]){super("Interrupt","interrupted",e)}}var NC=(e=[])=>new A_(e);var MC=(e)=>e._tag==="Interrupt";var O_=Symbol.for("effect/Micro/MicroFiber"),LC={_A:te,_E:te};class I_{context;interruptible;[O_];_stack=[];_observers=[];_exit;_children;currentOpCount=0;constructor(e,t=!0){this.context=e,this.interruptible=t,this[O_]=LC}getRef(e){return dx(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),Zi;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(Kd)}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===Pl)return;let r=T_.interruptChildren&&T_.interruptChildren(this);if(r!==void 0)return this.evaluate(Ml(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(Dl).shouldYield(this)){t=!0;let n=r;r=Ml(jC,()=>n)}if(r=r[Dd](this),r===Pl){let n=this._yielded;if(Fl in n)return this._yielded=void 0,n;return Pl}}}catch(n){if(!_(r,Dd))return qd(`MicroFiber.runLoop: Not a valid effect: ${String(r)}`);return qd(n)}}getCont(e){while(!0){let t=this._stack.pop();if(!t)return;let r=t[Nl]&&t[Nl](this);if(r)return{[e]:r};if(t[e])return t}}_yielded=void 0;yieldWith(e){return this._yielded=e,Pl}children(){return this._children??=new Set}}var T_=M("effect/Micro/fiberMiddleware",()=>({interruptChildren:void 0}));var v_=Symbol.for("effect/Micro/identifier"),Le=Symbol.for("effect/Micro/args"),Dd=Symbol.for("effect/Micro/evaluate"),Ai=Symbol.for("effect/Micro/successCont"),ki=Symbol.for("effect/Micro/failureCont"),Nl=Symbol.for("effect/Micro/ensureCont"),Pl=Symbol.for("effect/Micro/Yield"),DC={_A:te,_E:te,_R:te},qC={...Ub,_op:"Micro",[CC]:DC,pipe(){return y(this,arguments)},[Symbol.iterator](){return new Wo(new Rr(this))},toJSON(){return{_id:"Micro",op:this[v_],...Le in this?{args:this[Le]}:void 0}},toString(){return ie(this)},[Z](){return ie(this)}};function UC(e){return qd("Micro.evaluate: Not implemented")}var Ll=(e)=>({...qC,[v_]:e.op,[Dd]:e.eval??UC,[Ai]:e.contA,[ki]:e.contE,[Nl]:e.ensure}),Hd=(e)=>{let t=Ll(e);return function(){let r=Object.create(t);return r[Le]=e.single===!1?arguments:arguments[0],r}},R_=(e)=>{let t={...Ll(e),[Fl]:Fl,_tag:e.op,get[e.prop](){return this[Le]},toJSON(){return{_id:"MicroExit",_tag:e.op,[e.prop]:this[Le]}},[O](r){return KC(r)&&r._tag===e.op&&b(this[Le],r[Le])},[T](){return Q(this,H(oe(e.op))(S(this[Le])))}};return function(r){let n=Object.create(t);return n[Le]=r,n[Ai]=void 0,n[ki]=void 0,n[Nl]=void 0,n}},jd=R_({op:"Success",prop:"value",eval(e){let t=e.getCont(Ai);return t?t[Ai](this[Le],e):e.yieldWith(this)}}),C_=R_({op:"Failure",prop:"cause",eval(e){let t=e.getCont(ki);while(MC(this[Le])&&t&&e.interruptible)t=e.getCont(ki);return t?t[ki](this[Le],e):e.yieldWith(this)}});var HC=Hd({op:"Yield",eval(e){let t=!1;return e.getRef(Dl).scheduleTask(()=>{if(t)return;e.evaluate(WC)},this[Le]??0),e.yieldWith(()=>{t=!0})}}),jC=HC(0);var $C=jd(void 0);var $d=Hd({op:"WithMicroFiber",eval(e){return this[Le](e)}});var Ml=p(2,(e,t)=>{let r=Object.create(BC);return r[Le]=e,r[Ai]=t,r}),BC=Ll({op:"OnSuccess",eval(e){return e._stack.push(this),this[Le]}});var KC=(e)=>_(e,Fl),P_=jd,Bd=C_,Kd=Bd(NC());var qd=(e)=>Bd(FC(e));var WC=P_(void 0);var zC="setImmediate"in globalThis?globalThis.setImmediate:(e)=>setTimeout(e,0);class Wd{tasks=[];running=!1;scheduleTask(e,t){if(this.tasks.push(e),!this.running)this.running=!0,zC(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(N_)}flush(){while(this.tasks.length>0)this.runTasks()}}var VC=p(2,(e,t)=>$d((r)=>{let n=r.context;return r.context=t(n),YC(e,()=>(r.context=n,$C))}));var F_=p(2,(e,t)=>VC(e,Os(t)));class N_ extends Ts()("effect/Micro/currentMaxOpsBeforeYield",{defaultValue:()=>2048}){}class Dl extends Ts()("effect/Micro/currentScheduler",{defaultValue:()=>new Wd}){}var JC=p(2,(e,t)=>{let r=Object.create(GC);return r[Le]=e,r[Ai]=t.onSuccess,r[ki]=t.onFailure,r}),GC=Ll({op:"OnSuccessAndFailure",eval(e){return e._stack.push(this),this[Le]}});var YC=p(2,(e,t)=>QC((r)=>JC(r(e),{onFailure:(n)=>Ml(t(Bd(n)),()=>C_(n)),onSuccess:(n)=>Ml(t(P_(n)),()=>jd(n))})));var M_=Hd({op:"SetInterruptible",ensure(e){if(e.interruptible=this[Le],e._interrupted&&e.interruptible)return()=>Kd}}),ZC=(e)=>$d((t)=>{if(t.interruptible)return e;if(t.interruptible=!0,t._stack.push(M_(!1)),t._interrupted)return Kd;return e}),QC=(e)=>$d((t)=>{if(!t.interruptible)return e(te);return t.interruptible=!1,t._stack.push(M_(!0)),e(ZC)});var L_=(e,t)=>{let r=new I_(Dl.context(t?.scheduler??new Wd));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 ql{scheduleDrain;running=!1;tasks=new zd;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 ql(e),r=new WeakMap;return(n)=>{if(n===void 0)return t;let o=r.get(n);if(o===void 0)o=new ql(e),r.set(n,o);return o}}}class zd{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 D_{maxNextTickBeforeTimer;getRunner=ql.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(md)?e.getFiberRef(Si):!1}scheduleTask(e,t,r){this.getRunner(r).scheduleTask(e,t)}}var q_=M(Symbol.for("effect/Scheduler/defaultScheduler"),()=>new D_(2048));class ea{tasks=new zd;deferred=!1;scheduleTask(e,t,r){if(this.deferred)q_.scheduleTask(e,t,r);else this.tasks.scheduleTask(e,t)}shouldYield(e){return e.currentOpCount>e.getFiberRef(md)?e.getFiberRef(Si):!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 Ul=M(Symbol.for("effect/FiberRef/currentScheduler"),()=>Ve(q_));var Hl=M(Symbol.for("effect/FiberRef/currentRequestMap"),()=>Ve(new Map));var Vd=(e,t,r,n)=>{switch(e){case void 0:return t();case"unbounded":return r();case"inherit":return To(KS,(o)=>o==="unbounded"?r():o>1?n(o):t());default:return e>1?n(e):t()}};var Jd=(e)=>e.replace(/[\s="]/g,"_"),H_=(e)=>(t)=>`${Jd(t.label)}=${e-t.startTime}ms`;var j_="effect/MetricLabel",Gd=Symbol.for(j_);class $_{key;value;[Gd]=Gd;_hash;constructor(e,t){this.key=e,this.value=t,this._hash=oe(j_+this.key+this.value)}[T](){return this._hash}[O](e){return nP(e)&&this.key===e.key&&this.value===e.value}pipe(){return y(this,arguments)}}var B_=(e,t)=>new $_(e,t),nP=(e)=>_(e,Gd);var Yd=Yt((e)=>ws(e.context,Db)?e._tag==="Span"?Yd(e.parent):w():R(e));var K_=yd;var Zd="InterruptSignal",Qd="Stateful",Xd="Resume",em="YieldNow",jl=(e)=>({_tag:"InterruptSignal",cause:e}),Ii=(e)=>({_tag:"Stateful",onFiber:e}),Co=(e)=>({_tag:"Resume",effect:e}),W_=()=>({_tag:"YieldNow"});var lP="effect/FiberScope",$l=Symbol.for(lP);class V_{[$l]=$l;fiberId=Dt;roots=new Set;add(e,t){this.roots.add(t),t.addObserver(()=>{this.roots.delete(t)})}}class J_{fiberId;parent;[$l]=$l;constructor(e,t){this.fiberId=e,this.parent=t}add(e,t){this.parent.tell(Ii((r)=>{r.addChild(t),t.addObserver(()=>{r.removeChild(t)})}))}}var G_=(e)=>new J_(e.id(),e),ta=M(Symbol.for("effect/FiberScope/Global"),()=>new V_);var fP="effect/Fiber",tm=Symbol.for(fP),rm={_E:(e)=>e,_A:(e)=>e},dP={[tm]:rm,pipe(){return y(this,arguments)}},mP="effect/Fiber",Z_=Symbol.for(mP);var Bl=(e)=>tl(Us(e.await),e.inheritAll);var i1={...dn,commit(){return Bl(this)},...dP,id:()=>Dt,await:Bs,children:ne([]),inheritAll:Bs,poll:ne(w()),interruptAsFork:()=>Bs};var Dn="effect/FiberCurrent";var gP="effect/Logger",Q_=Symbol.for(gP),X_={_Message:(e)=>e,_Output:(e)=>e},Kl=(e)=>({[Q_]:X_,log:e,pipe(){return y(this,arguments)}});var c1={[Q_]:X_,log:Zi,pipe(){return y(this,arguments)}};var yP=/^[^\s"=]*$/,xP=(e,t)=>({annotations:r,cause:n,date:o,fiberId:i,logLevel:s,message:a,spans:c})=>{let l=(h)=>h.match(yP)?h:e(h),u=(h,P)=>`${Jd(h)}=${l(P)}`,f=(h,P)=>" "+u(h,P),d=u("timestamp",o.toISOString());d+=f("level",s.label),d+=f("fiber",Pc(i));let g=Ip(a);for(let h=0;h<g.length;h++)d+=f("message",Cr(g[h],t));if(!ef(n))d+=f("cause",nr(n,{renderErrorCause:!0}));for(let h of c)d+=" "+H_(o.getTime())(h);for(let[h,P]of r)d+=f(h,Cr(P,t));return d},SP=(e)=>`"${e.replace(/\\([\s\S])|(")/g,"\\$1$2")}"`,ew=Kl(xP(SP));var Po={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},l1={None:[],All:[],Trace:[Po.gray],Debug:[Po.blue],Info:[Po.green],Warning:[Po.yellow],Error:[Po.red],Fatal:[Po.bgBrightRed,Po.black]};var tw=typeof process==="object"&&process!==null&&typeof process.stdout==="object"&&process.stdout!==null,u1=tw&&process.stdout.isTTY===!0,p1=tw||"Deno"in globalThis;var rw="effect/MetricBoundaries",nm=Symbol.for(rw);class nw{values;[nm]=nm;constructor(e){this.values=e,this._hash=m(oe(rw),H(At(this.values)))}_hash;[T](){return this._hash}[O](e){return _P(e)&&b(this.values,e.values)}pipe(){return y(this,arguments)}}var _P=(e)=>_(e,nm),wP=(e)=>{let t=m(e,vp(Pe(Number.POSITIVE_INFINITY)),Lp);return new nw(t)};var ow=(e)=>m(Ap(e.count-1,(t)=>e.start*Math.pow(e.factor,t)),hs,wP);var OP="effect/MetricKeyType",iw=Symbol.for(OP),sw="effect/MetricKeyType/Counter",om=Symbol.for(sw),TP="effect/MetricKeyType/Frequency",kP=Symbol.for(TP),AP="effect/MetricKeyType/Gauge",IP=Symbol.for(AP),aw="effect/MetricKeyType/Histogram",im=Symbol.for(aw),vP="effect/MetricKeyType/Summary",RP=Symbol.for(vP),cw={_In:(e)=>e,_Out:(e)=>e};class lw{incremental;bigint;[iw]=cw;[om]=om;constructor(e,t){this.incremental=e,this.bigint=t,this._hash=oe(sw)}_hash;[T](){return this._hash}[O](e){return sm(e)}pipe(){return y(this,arguments)}}class uw{boundaries;[iw]=cw;[im]=im;constructor(e){this.boundaries=e,this._hash=m(oe(aw),H(S(this.boundaries)))}_hash;[T](){return this._hash}[O](e){return am(e)&&b(this.boundaries,e.boundaries)}pipe(){return y(this,arguments)}}var pw=(e)=>new lw(e?.incremental??!1,e?.bigint??!1);var fw=(e)=>new uw(e);var sm=(e)=>_(e,om),dw=(e)=>_(e,kP),mw=(e)=>_(e,IP),am=(e)=>_(e,im),hw=(e)=>_(e,RP);var CP="effect/MetricKey",yw=Symbol.for(CP),PP={_Type:(e)=>e},FP=gn(b);class Wl{name;keyType;description;tags;[yw]=PP;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),H(S(this.keyType)),H(At(this.tags)))}_hash;[T](){return this._hash}[O](e){return NP(e)&&this.name===e.name&&b(this.keyType,e.keyType)&&b(this.description,e.description)&&FP(this.tags,e.tags)}pipe(){return y(this,arguments)}}var NP=(e)=>_(e,yw),xw=(e,t)=>new Wl(e,pw(t),Nr(t?.description));var Sw=(e,t,r)=>new Wl(e,fw(t),Nr(r));var bw=p(2,(e,t)=>t.length===0?e:new Wl(e.name,e.keyType,e.description,hn(e.tags,t)));var _w=Symbol.for("effect/MutableHashMap"),LP={[_w]:_w,[Symbol.iterator](){return new cm(this)},toString(){return ie(this.toJSON())},toJSON(){return{_id:"MutableHashMap",values:Array.from(this).map(re)}},[Z](){return this.toJSON()},pipe(){return y(this,arguments)}};class cm{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 ww(this.self.buckets.values()),this.next();return e}[Symbol.iterator](){return new cm(this.self)}}class ww{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 Ew=()=>{let e=Object.create(LP);return e.referential=new Map,e.buckets=new Map,e.bucketsSize=0,e};var qn=p(2,(e,t)=>{if(os(t)===!1)return e.referential.has(t)?R(e.referential.get(t)):w();let r=t[T](),n=e.buckets.get(r);if(n===void 0)return w();return DP(e,n,t)});var DP=(e,t,r,n=!1)=>{for(let o=0,i=t.length;o<i;o++)if(r[O](t[o][0])){let s=t[o][1];if(n)t.splice(o,1),e.bucketsSize--;return R(s)}return w()},vi=p(2,(e,t)=>pe(qn(e,t))),Ri=p(3,(e,t,r)=>{if(os(t)===!1)return e.referential.set(t,r),e;let n=t[T](),o=e.buckets.get(n);if(o===void 0)return e.buckets.set(n,[[t,r]]),e.bucketsSize++,e;return qP(e,o,t),o.push([t,r]),e.bucketsSize++,e}),qP=(e,t,r)=>{for(let n=0,o=t.length;n<o;n++)if(r[O](t[n][0])){t.splice(n,1),e.bucketsSize--;return}};var HP="effect/MetricState",ra=Symbol.for(HP),Ow="effect/MetricState/Counter",lm=Symbol.for(Ow),Tw="effect/MetricState/Frequency",um=Symbol.for(Tw),kw="effect/MetricState/Gauge",pm=Symbol.for(kw),Aw="effect/MetricState/Histogram",fm=Symbol.for(Aw),Iw="effect/MetricState/Summary",dm=Symbol.for(Iw),na={_A:(e)=>e};class vw{count;[ra]=na;[lm]=lm;constructor(e){this.count=e}[T](){return m(S(Ow),H(S(this.count)),Q(this))}[O](e){return $P(e)&&this.count===e.count}pipe(){return y(this,arguments)}}var jP=gn(b);class Rw{occurrences;[ra]=na;[um]=um;constructor(e){this.occurrences=e}_hash;[T](){return m(oe(Tw),H(At(fe(this.occurrences.entries()))),Q(this))}[O](e){return BP(e)&&jP(fe(this.occurrences.entries()),fe(e.occurrences.entries()))}pipe(){return y(this,arguments)}}class Cw{value;[ra]=na;[pm]=pm;constructor(e){this.value=e}[T](){return m(S(kw),H(S(this.value)),Q(this))}[O](e){return KP(e)&&this.value===e.value}pipe(){return y(this,arguments)}}class Pw{buckets;count;min;max;sum;[ra]=na;[fm]=fm;constructor(e,t,r,n,o){this.buckets=e,this.count=t,this.min=r,this.max=n,this.sum=o}[T](){return m(S(Aw),H(S(this.buckets)),H(S(this.count)),H(S(this.min)),H(S(this.max)),H(S(this.sum)),Q(this))}[O](e){return WP(e)&&b(this.buckets,e.buckets)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return y(this,arguments)}}class Fw{error;quantiles;count;min;max;sum;[ra]=na;[dm]=dm;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}[T](){return m(S(Iw),H(S(this.error)),H(S(this.quantiles)),H(S(this.count)),H(S(this.min)),H(S(this.max)),H(S(this.sum)),Q(this))}[O](e){return zP(e)&&this.error===e.error&&b(this.quantiles,e.quantiles)&&this.count===e.count&&this.min===e.min&&this.max===e.max&&this.sum===e.sum}pipe(){return y(this,arguments)}}var Nw=(e)=>new vw(e),Mw=(e)=>new Rw(e),Lw=(e)=>new Cw(e),Dw=(e)=>new Pw(e.buckets,e.count,e.min,e.max,e.sum),qw=(e)=>new Fw(e.error,e.quantiles,e.count,e.min,e.max,e.sum);var $P=(e)=>_(e,lm),BP=(e)=>_(e,um),KP=(e)=>_(e,pm),WP=(e)=>_(e,fm),zP=(e)=>_(e,dm);var JP="effect/MetricHook",GP=Symbol.for(JP),YP={_In:(e)=>e,_Out:(e)=>e},oa=(e)=>({[GP]:YP,pipe(){return y(this,arguments)},...e});var Uw=BigInt(0),jw=(e)=>{let t=e.keyType.bigint?Uw:0,r=e.keyType.incremental?e.keyType.bigint?(o)=>o>=Uw:(o)=>o>=0:(o)=>!0,n=(o)=>{if(r(o))t=t+o};return oa({get:()=>Nw(t),update:n,modify:n})},$w=(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 oa({get:()=>Mw(t),update:r,modify:r})},Bw=(e,t)=>{let r=t;return oa({get:()=>Lw(r),update:(n)=>{r=n},modify:(n)=>{r=r+n}})},Kw=(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,Lr(br),Qt((f,d)=>{o[d]=f}));let l=(f)=>{let d=0,g=r;while(d!==g){let h=Math.floor(d+(g-d)/2),P=o[h];if(f<=P)g=h;else d=h;if(g===d+1)if(f<=o[d])g=d;else d=g}if(n[d]=n[d]+1,i=i+1,s=s+f,f<a)a=f;if(f>c)c=f},u=()=>{let f=ao(r),d=0;for(let g=0;g<r;g++){let h=o[g],P=n[g];d=d+P,f[g]=[h,d]}return f};return oa({get:()=>Dw({buckets:u(),count:i,min:a,max:c,sum:s}),update:l,modify:l})},Ww=(e)=>{let{error:t,maxAge:r,maxSize:n,quantiles:o}=e.keyType,i=m(o,Lr(br)),s=ao(n),a=0,c=0,l=0,u=0,f=0,d=(h)=>{let P=[],x=0;while(x!==n-1){let E=s[x];if(E!=null){let[G,N]=E,q=kc(h-G);if(kx(q,gf)&&Tx(q,r))P.push(N)}x=x+1}return ZP(t,i,Lr(P,br))},g=(h,P)=>{if(n>0){a=a+1;let x=a%n;s[x]=[P,h]}u=c===0?h:Math.min(u,h),f=c===0?h:Math.max(f,h),c=c+1,l=l+h};return oa({get:()=>qw({error:t,quantiles:d(Date.now()),count:c,min:u,max:f,sum:l}),update:([h,P])=>g(h,P),modify:([h,P])=>g(h,P)})},ZP=(e,t,r)=>{let n=r.length;if(!ae(t))return Dr();let o=t[0],i=t.slice(1),s=Hw(e,n,w(),0,o,r),a=Je(s);return i.forEach((c)=>{a.push(Hw(e,n,s.value,s.consumed,c,s.rest))}),Qt(a,(c)=>[c.quantile,c.value])},Hw=(e,t,r,n,o,i)=>{let s=e,a=t,c=r,l=n,u=o,f=i,d=e,g=t,h=r,P=n,x=o,E=i;while(!0){if(!ae(f))return{quantile:u,value:w(),consumed:l,rest:[]};if(u===1)return{quantile:u,value:R(Pp(f)),consumed:l+f.length,rest:[]};let G=Ce(f),N=fy(f,(v)=>v===G),q=u*a,k=s/2*q,I=l+N[0].length,j=Math.abs(I-q);if(I<q-k){d=s,g=a,h=Mr(f),P=I,x=u,E=N[1],s=d,a=g,c=h,l=P,u=x,f=E;continue}if(I>q+k){let v=Se(c)?R(G):c;return{quantile:u,value:v,consumed:l,rest:f}}switch(c._tag){case"None":{d=s,g=a,h=Mr(f),P=I,x=u,E=N[1],s=d,a=g,c=h,l=P,u=x,f=E;continue}case"Some":{let v=Math.abs(q-c.value);if(j<v){d=s,g=a,h=Mr(f),P=I,x=u,E=N[1],s=d,a=g,c=h,l=P,u=x,f=E;continue}return{quantile:u,value:R(c.value),consumed:l,rest:f}}}}throw Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues")};var XP="effect/MetricPair",e0=Symbol.for(XP),t0={_Type:(e)=>e};var zw=(e,t)=>({[e0]:t0,metricKey:e,metricState:t,pipe(){return y(this,arguments)}});var n0="effect/MetricRegistry",Vw=Symbol.for(n0);class Jw{[Vw]=Vw;map=Ew();snapshot(){let e=[];for(let[t,r]of this.map)e.push(zw(t,r.get()));return e}get(e){let t=m(this.map,qn(e),yt);if(t==null){if(sm(e.keyType))return this.getCounter(e);if(mw(e.keyType))return this.getGauge(e);if(dw(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,qn(e),yt);if(t==null){let r=jw(e);if(!m(this.map,vi(e)))m(this.map,Ri(e,r));t=r}return t}getFrequency(e){let t=m(this.map,qn(e),yt);if(t==null){let r=$w(e);if(!m(this.map,vi(e)))m(this.map,Ri(e,r));t=r}return t}getGauge(e){let t=m(this.map,qn(e),yt);if(t==null){let r=Bw(e,e.keyType.bigint?BigInt(0):0);if(!m(this.map,vi(e)))m(this.map,Ri(e,r));t=r}return t}getHistogram(e){let t=m(this.map,qn(e),yt);if(t==null){let r=Kw(e);if(!m(this.map,vi(e)))m(this.map,Ri(e,r));t=r}return t}getSummary(e){let t=m(this.map,qn(e),yt);if(t==null){let r=Ww(e);if(!m(this.map,vi(e)))m(this.map,Ri(e,r));t=r}return t}}var Gw=()=>new Jw;var i0="effect/Metric",s0=Symbol.for(i0),a0={_Type:(e)=>e,_In:(e)=>e,_Out:(e)=>e},Yw=M(Symbol.for("effect/Metric/globalMetricRegistry"),()=>Gw()),Zw=function(e,t,r,n){let o=Object.assign((i)=>Qc(i,(s)=>l0(o,s)),{[s0]:a0,keyType:e,unsafeUpdate:t,unsafeValue:r,unsafeModify:n,register(){return this.unsafeValue([]),this},pipe(){return y(this,arguments)}});return o};var ia=(e,t)=>Qw(xw(e,t));var Qw=(e)=>{let t,r=new WeakMap,n=(o)=>{if(o.length===0){if(t!==void 0)return t;return t=Yw.get(e),t}let i=r.get(o);if(i!==void 0)return i;return i=Yw.get(bw(e,o)),r.set(o,i),i};return Zw(e.keyType,(o,i)=>n(i).update(o),(o)=>n(o).get(),(o,i)=>n(i).modify(o))};var Xw=(e,t,r)=>Qw(Sw(e,t,r));var eE=p(3,(e,t,r)=>c0(e,[B_(t,r)]));var c0=p(2,(e,t)=>Zw(e.keyType,(r,n)=>e.unsafeUpdate(r,hn(t,n)),(r)=>e.unsafeValue(hn(t,r)),(r,n)=>e.unsafeModify(r,hn(t,n))));var l0=p(2,(e,t)=>To(Ws,(r)=>F(()=>e.unsafeUpdate(t,r))));var p0="effect/Request",f0=Symbol.for(p0),d0={_E:(e)=>e,_A:(e)=>e},$1={...us,[f0]:d0};var tE=p(2,(e,t)=>To(Hl,(r)=>F(()=>{if(r.has(e)){let n=r.get(e);if(!n.state.completed)n.state.completed=!0,ul(n.result,t)}})));var m0="effect/Supervisor",zl=Symbol.for(m0),mm={_T:(e)=>e};class Vl{underlying;value0;[zl]=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 Vl(this,m(this.value,Ee(e)))}zip(e){return new Jl(this,e)}}class Jl{left;right;_tag="Zip";[zl]=mm;constructor(e,t){this.left=e,this.right=t}get value(){return el(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 Vl(this,m(this.value,Ee(e)))}zip(e){return new Jl(this,e)}}var hm=(e)=>_(e,zl)&&rs(e,"Zip");class rE{effect;[zl]=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 Vl(this,m(this.value,Ee(e)))}zip(e){return new Jl(this,e)}onRun(e,t){return e()}}var h0=(e)=>new rE(e),Fo=M("effect/Supervisor/none",()=>h0(Fe));var nE=An;var oE="Empty",iE="AddSupervisor",sE="RemoveSupervisor",aE="AndThen",Ci={_tag:oE},Gl=(e,t)=>({_tag:aE,first:e,second:t}),y0=(e,t)=>x0(t,Pe(e)),x0=(e,t)=>{let r=e,n=t;while(Xt(n)){let o=er(n);switch(o._tag){case oE:{n=tr(n);break}case iE:{r=r.zip(o.supervisor),n=tr(n);break}case sE:{r=ym(r,o.supervisor),n=tr(n);break}case aE:{n=Ge(o.first)(Ge(o.second)(tr(n)));break}}}return r},ym=(e,t)=>{if(b(e,t))return Fo;else if(hm(e))return ym(e.left,t).zip(ym(e.right,t));else return e},Yl=(e)=>{if(b(e,Fo))return hr();else if(hm(e))return m(Yl(e.left),$r(Yl(e.right)));else return po(e)},S0=(e,t)=>{if(b(e,t))return Ci;let r=Yl(e),n=Yl(t),o=m(n,Yp(r),mo(Ci,(s,a)=>Gl(s,{_tag:iE,supervisor:a}))),i=m(r,Yp(n),mo(Ci,(s,a)=>Gl(s,{_tag:sE,supervisor:a})));return Gl(o,i)},cE=nE({empty:Ci,patch:y0,combine:Gl,diff:S0});var v0=ia("effect_fiber_started",{incremental:!0}),lE=ia("effect_fiber_active"),R0=ia("effect_fiber_successes",{incremental:!0}),C0=ia("effect_fiber_failures",{incremental:!0}),P0=eE(Xw("effect_fiber_lifetimes",ow({start:0.5,factor:2,count:35})),"time_unit","milliseconds"),sa="Continue",F0="Done",uE="Yield",N0={_E:(e)=>e,_A:(e)=>e},Zl=(e)=>{throw Error(`BUG: FiberRuntime - ${Cr(e)} - please report an issue at https://github.com/Effect-TS/effect/issues`)},Zr=Symbol.for("effect/internal/fiberRuntime/YieldedOp"),Qr=M("effect/internal/fiberRuntime/yieldedOpChannel",()=>({currentOp:null})),aa={[zo]:(e,t,r)=>We(()=>t.effect_instruction_i1(r)),["OnStep"]:(e,t,r)=>xe(xe(r)),[Vo]:(e,t,r)=>We(()=>t.effect_instruction_i2(r)),[cs]:(e,t,r)=>{if(e.patchRuntimeFlags(e.currentRuntimeFlags,t.patch),Vr(e.currentRuntimeFlags)&&e.isInterrupted())return ce(e.getInterruptedCause());else return xe(r)},[Jo]:(e,t,r)=>{if(We(()=>t.effect_instruction_i2(r)),We(()=>t.effect_instruction_i0()))return e.pushStack(t),We(()=>t.effect_instruction_i1());else return Fe},[Go]:(e,t,r)=>{while(!0){let n=We(()=>t.effect_instruction_i0.next(r));if(n.done)return xe(n.value);let o=up(n.value);if(!_i(o))return e.pushStack(t),o;else if(o._tag==="Failure")return o;r=o.value}}},M0={[Zd]:(e,t,r,n)=>(e.processNewInterruptSignal(n.cause),Vr(t)?ce(n.cause):r),[Xd]:(e,t,r,n)=>{throw Error("It is illegal to have multiple concurrent run loops in a single fiber")},[Qd]:(e,t,r,n)=>(n.onFiber(e,Ld(t)),r),[em]:(e,t,r,n)=>L($s(),()=>r)},L0=(e)=>Eo(dS(e),(t)=>No(hS(t),([r,n])=>{let o=new Map,i=[];for(let a of n){i.push(Ur(a));for(let c of a)o.set(c.request,c)}let s=i.flat();return Fn(Z0(r.runAll(i),s,()=>s.forEach((a)=>{a.listeners.interrupted=!0})),Hl,o)},!1,!1)),D0=ls();class Ql extends kd{[tm]=rm;[Z_]=N0;_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,Kf(r)){let n=this.getFiberRef(Ws);v0.unsafeUpdate(1,n),lE.unsafeUpdate(1,n)}this.refreshRefCache()}commit(){return Bl(this)}id(){return this._fiberId}resume(e){this.tell(Co(e))}get status(){return this.ask((e,t)=>t)}get runtimeFlags(){return this.ask((e,t)=>{if(b_(t))return e.currentRuntimeFlags;return t.runtimeFlags})}scope(){return G_(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(zs)}fiberRefs(){return this.ask((e)=>e.getFiberRefs())}ask(e){return de(()=>{let t=YS(this._fiberId);return this.tell(Ii((r,n)=>{ul(t,F(()=>e(r,n)))})),ll(t)})}tell(e){if(this._queue.push(e),!this._running)this._running=!0,this.drainQueueLaterOnExecutor()}get await(){return vn((e)=>{let t=(r)=>e(ne(r));if(this._exitValue!==null){t(this._exitValue);return}return this.tell(Ii((r,n)=>{if(r._exitValue!==null)t(this._exitValue);else r.addObserver(t)})),F(()=>this.tell(Ii((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=Pd(n,r,i);e.setFiberRefs(s);let a=e.getFiberRef(fE),c=m(Ns(o,a),Jf(zr),Jf(Hc));return ud(c)})}get poll(){return F(()=>Nr(this._exitValue))}unsafePoll(){return this._exitValue}interruptAsFork(e){return F(()=>this.tell(jl(rr(e))))}unsafeInterruptAsFork(e){this.tell(jl(rr(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(fE,this.currentRuntimeFlags),this._fiberRefs}unsafeDeleteFiberRef(e){this._fiberRefs=Xs(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=Ti(this._fiberRefs,{fiberId:this._fiberId,fiberRef:e,value:t}),this.refreshRefCache()}refreshRefCache(){this.currentDefaultServices=this.getFiberRef(Qs),this.currentTracer=this.currentDefaultServices.unsafeMap.get(Zs.key),this.currentSupervisor=this.getFiberRef(Y0),this.currentScheduler=this.getFiberRef(Ul),this.currentContext=this.getFiberRef(Ao),this.currentSpan=this.currentContext.unsafeMap.get(Ol.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=sa,r=globalThis[Dn];globalThis[Dn]=this;try{while(t===sa)t=this._queue.length===0?F0:this.evaluateMessageWhileSuspended(this._queue.splice(0,1)[0])}finally{this._running=!1,globalThis[Dn]=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(Si),this)}drainQueueWhileRunning(e,t){let r=t;while(this._queue.length>0){let n=this._queue.splice(0,1)[0];r=M0[n._tag](this,e,r,n)}return r}isInterrupted(){return!bc(this.getFiberRef(zs))}addInterruptedCause(e){let t=this.getFiberRef(zs);this.setFiberRef(zs,Ye(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(jl(rr(this.id()))),e=!0;return e}interruptAllChildren(){if(this.sendInterruptSignalToAllChildren()){let e=this._children.values();this._children=null;let t=!1;return js({while:()=>!t,body:()=>{let n=e.next();if(!n.done)return Gr(n.value.await);else return F(()=>{t=!0})},step:()=>{}})}return null}reportExitValue(e){if(Kf(this.currentRuntimeFlags)){let t=this.getFiberRef(Ws),r=this.id().startTimeMillis,n=Date.now();switch(P0.unsafeUpdate(n-r,t),lE.unsafeUpdate(-1,t),e._tag){case ht:{R0.unsafeUpdate(1,t);break}case mt:{C0.unsafeUpdate(1,t);break}}}if(e._tag==="Failure"){let t=this.getFiberRef(zS);if(!li(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($0)}log(e,t,r){let n=pe(r)?r.value:this.getFiberRef(hd),o=this.getFiberRef(q0);if(__(o,n))return;let i=this.getFiberRef($S),s=this.getFiberRef(jS),a=this.getLoggers(),c=this.getFiberRefs();if(xs(a)>0){let l=ws(this.getFiberRef(Qs),Ys),u=new Date(l.unsafeCurrentTimeMillis());Ng(c,()=>{for(let f of a)f.log({fiberId:this.id(),logLevel:n,message:e,cause:t,context:c,spans:i,annotations:s,date:u})})}}evaluateMessageWhileSuspended(e){switch(e._tag){case em:return uE;case Zd:{if(this.processNewInterruptSignal(e.cause),this._asyncInterruptor!==null)this._asyncInterruptor(ce(e.cause)),this._asyncInterruptor=null;return sa}case Xd:return this._asyncInterruptor=null,this._asyncBlockingOn=null,this.evaluateEffect(e.effect),sa;case Qd:return e.onFiber(this,this._exitValue!==null?x_:S_(this.currentRuntimeFlags,this._asyncBlockingOn)),sa;default:return Zl(e)}}evaluateEffect(e){this.currentSupervisor.onResume(this);try{let t=Vr(this.currentRuntimeFlags)&&this.isInterrupted()?ce(this.getInterruptedCause()):e;while(t!==null){let r=t,n=this.runLoop(r);if(n===Zr){let o=Qr.currentOp;if(Qr.currentOp=null,o._op===Yo)if(lS(this.currentRuntimeFlags))this.tell(W_()),this.tell(Co(Ht)),t=null;else t=Ht;else if(o._op===oo)t=null}else{this.currentRuntimeFlags=m(this.currentRuntimeFlags,jf(Hc));let o=this.interruptAllChildren();if(o!==null)t=L(o,()=>n);else{if(this._queue.length===0)this.setExitValue(n);else this.tell(Co(n));t=null}}}}finally{this.currentSupervisor.onSuspend(this)}}start(e){if(!this._running){this._running=!0;let t=globalThis[Dn];globalThis[Dn]=this;try{this.evaluateEffect(e)}finally{if(this._running=!1,globalThis[Dn]=t,this._queue.length>0)this.drainQueueLaterOnExecutor()}}else this.tell(Co(e))}startFork(e){this.tell(Co(e))}patchRuntimeFlags(e,t){let r=Ms(e,t);return globalThis[Dn]=this,this.currentRuntimeFlags=r,r}initiateAsync(e,t){let r=!1,n=(o)=>{if(!r)r=!0,this.tell(Co(o))};if(Vr(e))this._asyncInterruptor=n;try{t(n)}catch(o){n(Ze(vt(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!==zo&&e._op!==Jo&&e._op!==Go)return e;e=this.popStack()}}[Lg](e){return F(()=>Es(this.currentContext,e))}["Left"](e){return $e(e.left)}["None"](e){return $e(new Vs)}["Right"](e){return xe(e.right)}["Some"](e){return xe(e.value)}["Micro"](e){return Ls((t)=>{let r=t,n=L_(F_(e,this.currentContext));return n.addObserver((o)=>{if(o._tag==="Success")return r(xe(o.value));switch(o.cause._tag){case"Interrupt":return r(ce(rr(Dt)));case"Fail":return r($e(o.cause.error));case"Die":return r(Gc(o.cause.defect))}}),Ls((o)=>{r=(i)=>{o(Fe)},n.unsafeInterrupt()})})}[Za](e){let t=We(()=>e.effect_instruction_i0()),r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in aa))Zl(r);return aa[r._op](this,r,t)}else return Qr.currentOp=xe(t),Zr}[ht](e){let t=e,r=this.getNextSuccessCont();if(r!==void 0){if(!(r._op in aa))Zl(r);return aa[r._op](this,r,t.effect_instruction_i0)}else return Qr.currentOp=t,Zr}[mt](e){let t=e.effect_instruction_i0,r=this.getNextFailCont();if(r!==void 0)switch(r._op){case as:case Vo:if(!(Vr(this.currentRuntimeFlags)&&this.isInterrupted()))return We(()=>r.effect_instruction_i1(t));else return ce(Ec(t));case"OnStep":if(!(Vr(this.currentRuntimeFlags)&&this.isInterrupted()))return xe(ce(t));else return ce(Ec(t));case cs:if(this.patchRuntimeFlags(this.currentRuntimeFlags,r.patch),Vr(this.currentRuntimeFlags)&&this.isInterrupted())return ce(Ye(t,this.getInterruptedCause()));else return ce(t);default:Zl(r)}else return Qr.currentOp=ce(t),Zr}[Qa](e){return We(()=>e.effect_instruction_i0(this,Ld(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=a_(o.refs,t),a=Ns(o.flags,r);return xe(Vc(e.effect_instruction_i0,ze((c)=>{while(n.length>0)c.pushStack(n.pop());return c.setFiberRefs(c_(c.id(),c.getFiberRefs())(s)),c.currentRuntimeFlags=Ms(a)(c.currentRuntimeFlags),e.effect_instruction_i1})))}return Cn((n)=>L(_m(ed(e.effect_instruction_i0)),()=>n(e.effect_instruction_i1)))}["RunBlocked"](e){return L0(e.effect_instruction_i0)}[so](e){let t=e.effect_instruction_i0,r=this.currentRuntimeFlags,n=Ms(r,t);if(Vr(n)&&this.isInterrupted())return ce(this.getInterruptedCause());else if(this.patchRuntimeFlags(this.currentRuntimeFlags,t),e.effect_instruction_i1){let o=Ns(n,r);return this.pushStack(new td(o,e)),We(()=>e.effect_instruction_i1(r))}else return Ht}[zo](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}[Vo](e){return this.pushStack(e),e.effect_instruction_i0}[oo](e){return this._asyncBlockingOn=e.effect_instruction_i1,this.initiateAsync(this.currentRuntimeFlags,e.effect_instruction_i0),Qr.currentOp=e,Zr}[Yo](e){return this._isYielding=!1,Qr.currentOp=e,Zr}[Jo](e){let{effect_instruction_i0:t,effect_instruction_i1:r}=e;if(t())return this.pushStack(e),r();else return Ht}[Go](e){return aa[Go](this,e,void 0)}[io](e){return We(()=>e.commit())}runLoop(e){let t=e;this.currentOpCount=0;while(!0){if((this.currentRuntimeFlags&cS)!==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=L($s({priority:r}),()=>n)}}try{if(t=this.currentTracer.context(()=>{if(D0!==t[In]._V){let r=this.getFiberRef(VS);if(r._tag==="Some"){let n=t[In]._V;this.log(`Executing an Effect versioned ${n} with a Runtime of version ${ls()}, 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`,Br,r)}}return this[t._op](t)},this),t===Zr){let r=Qr.currentOp;if(r._op===Yo||r._op===oo)return Zr;return Qr.currentOp=null,r._op===ht||r._op===mt?r:ce(vt(r))}}catch(r){if(t!==Zr&&!_(t,"_op")||!(t._op in this))t=id(`Not a valid effect: ${Cr(t)}`);else if(JS(r))t=ce(Ye(vt(r),rr(Dt)));else t=Gc(r)}}}run=()=>{this.drainQueueOnCurrentThread()}}var q0=M("effect/FiberRef/currentMinimumLogLevel",()=>Ve(w_("Info"))),U0=(e)=>Kl((t)=>{let r=Gb(t.context,Qs);ws(r,El).unsafe.log(e.log(t))});var H0=M(Symbol.for("effect/Logger/defaultLogger"),()=>U0(ew));var j0=M(Symbol.for("effect/Logger/tracerLogger"),()=>Kl(({annotations:e,cause:t,context:r,fiberId:n,logLevel:o,message:i})=>{let s=Yd(Tn(Mn(r,Ao),Ol));if(s._tag==="None"||s.value._tag==="ExternalSpan")return;let a=Es(Mn(r,Qs),Ys),c={};for(let[l,u]of e)c[l]=u;if(c["effect.fiberId"]=Lx(n),c["effect.logLevel"]=o.label,t!==null&&t._tag!=="Empty")c["effect.cause"]=nr(t,{renderErrorCause:!0});s.value.event(Cr(Array.isArray(i)&&i.length===1?i[0]:i),a.unsafeCurrentTimeNanos(),c)}));var $0=M(Symbol.for("effect/FiberRef/currentLoggers"),()=>US(po(H0,j0)));var dE=p((e)=>sp(e[0]),(e,t,r)=>ze((n)=>{let o=r?.batching===!0||r?.batching==="inherit"&&n.getFiberRef(WS);if(r?.discard)return Vd(r.concurrency,()=>Pi(Tl,r?.concurrentFinalizers)((i)=>o?No(e,(s,a)=>i(t(s,a)),!0,!1,1):Eo(e,(s,a)=>i(t(s,a)))),()=>Pi(kl,r?.concurrentFinalizers)((i)=>No(e,(s,a)=>i(t(s,a)),o,!1)),(i)=>Pi(Al(i),r?.concurrentFinalizers)((s)=>No(e,(a,c)=>s(t(a,c)),o,!1,i)));return Vd(r?.concurrency,()=>Pi(Tl,r?.concurrentFinalizers)((i)=>o?xm(e,1,(s,a)=>i(t(s,a)),!0):Ut(e,(s,a)=>i(t(s,a)))),()=>Pi(kl,r?.concurrentFinalizers)((i)=>mE(e,(s,a)=>i(t(s,a)),o)),(i)=>Pi(Al(i),r?.concurrentFinalizers)((s)=>xm(e,i,(a,c)=>s(t(a,c)),o)))})),mE=(e,t,r)=>de(()=>{let n=fe(e),o=Array(n.length);return Pn(No(n,(s,a)=>L(t(s,a),(c)=>F(()=>o[a]=c)),r,!1),ne(o))}),No=(e,t,r,n,o)=>Cn((i)=>ld((s)=>ze((a)=>{let c=Array.from(e).reverse(),l=c.length;if(l===0)return Fe;let u=0,f=!1,d=o?Math.min(c.length,o):c.length,g=new Set,h=[],P=()=>g.forEach((v)=>{v.currentScheduler.scheduleTask(()=>{v.unsafeInterruptAsFork(a.id())},0,v)}),x=[],E=[],G=[],N=()=>{let v=h.filter(({exit:X})=>X._tag==="Failure").sort((X,ee)=>X.index<ee.index?-1:X.index===ee.index?0:1).map(({exit:X})=>X);if(v.length===0)v.push(Ht);return v},q=(v,X=!1)=>{let ee=Xc(s(v)),V=K0(ee,a,a.currentRuntimeFlags,ta);return a.currentScheduler.scheduleTask(()=>{if(X)V.unsafeInterruptAsFork(a.id());V.resume(ee)},0,V),V},k=()=>{if(!n)l-=c.length,c=[];f=!0,P()},I=r?cd:Rn,j=q(vn((v)=>{let X=(V,me)=>{if(V._op==="Blocked")G.push(V);else if(h.push({index:me,exit:V}),V._op==="Failure"&&!f)k()},ee=()=>{if(c.length>0){let V=c.pop(),me=u++,nt=()=>{let Y=c.pop();return me=u++,L($s(),()=>L(I(i(t(Y,me))),pt))},pt=(Y)=>{if(c.length>0){if(X(Y,me),c.length>0)return nt()}return ne(Y)},Ot=L(I(i(t(V,me))),pt),Ie=q(Ot);if(x.push(Ie),g.add(Ie),f)Ie.currentScheduler.scheduleTask(()=>{Ie.unsafeInterruptAsFork(a.id())},0,Ie);Ie.addObserver((Y)=>{let He;if(Y._op==="Failure")He=Y;else He=Y.effect_instruction_i0;if(E.push(Ie),g.delete(Ie),X(He,me),h.length===l)v(ne(ue(vo(N(),{parallel:!0}),()=>Ht)));else if(G.length+h.length===l){let cn=N(),Ku=G.map((ji)=>ji.effect_instruction_i0).reduce(Yf);v(ne(Vc(Ku,No([ue(vo(cn,{parallel:!0}),()=>Ht),...G.map((ji)=>ji.effect_instruction_i1)],(ji)=>ji,r,!0,o))))}else ee()})}};for(let V=0;V<d;V++)ee()}));return Gr(xi(Us(i(Bl(j))),cl({onFailure:(v)=>{k();let X=G.length+1,ee=Math.min(typeof o==="number"?o:G.length,G.length),V=Array.from(G);return vn((me)=>{let nt=[],pt=0,Ot=0,Ie=(He,cn)=>(Ku)=>{if(nt[He]=Ku,pt++,pt===X)me(xe(ce(v)));if(V.length>0&&cn)Y()},Y=()=>{q(V.pop(),!0).addObserver(Ie(Ot,!0)),Ot++};j.addObserver(Ie(Ot,!1)),Ot++;for(let He=0;He<ee;He++)Y()})},onSuccess:()=>Ut(E,(v)=>v.inheritAll)})))}))),xm=(e,t,r,n)=>de(()=>{let o=fe(e),i=Array(o.length);return Pn(No(o,(a,c)=>Ee(r(a,c),(l)=>i[c]=l),n,!1,t),ne(i))});var _m=(e)=>W0(e,ta);var B0=(e,t,r,n=null)=>{let o=hE(e,t,r,n);return o.resume(e),o},K0=(e,t,r,n=null)=>hE(e,t,r,n),hE=(e,t,r,n=null)=>{let o=Fc(),i=t.getFiberRefs(),s=Fd(i,o),a=new Ql(o,s,r),c=Mn(s,Ao),l=a.currentSupervisor;return l.onStart(c,e,R(t),a),a.addObserver((f)=>l.onEnd(f,a)),(n!==null?n:m(t.getFiberRef(zc),ue(()=>t.scope()))).add(r,a),a},W0=(e,t)=>ze((r,n)=>ne(B0(e,r,n.runtimeFlags,t)));var Sm=(e)=>Ro((t)=>Oe(Tn(t,ca),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Parallel":return e;case"Sequential":case"ParallelN":return L(bi(r,kl),(n)=>wm(e,n))}}})),pE=(e)=>(t)=>Ro((r)=>Oe(Tn(r,ca),{onNone:()=>t,onSome:(n)=>{if(n.strategy._tag==="ParallelN"&&n.strategy.parallelism===e)return t;return L(bi(n,Al(e)),(o)=>wm(t,o))}}));var Pi=(e,t)=>(r)=>Ro((n)=>Oe(Tn(n,ca),{onNone:()=>r(te),onSome:(o)=>{if(t===!0){let i=e._tag==="Parallel"?Sm:e._tag==="Sequential"?bm:pE(e.parallelism);switch(o.strategy._tag){case"Parallel":return i(r(Sm));case"Sequential":return i(r(bm));case"ParallelN":return i(r(pE(o.strategy.parallelism)))}}else return r(te)}}));var bm=(e)=>Ro((t)=>Oe(Tn(t,ca),{onNone:()=>e,onSome:(r)=>{switch(r.strategy._tag){case"Sequential":return e;case"Parallel":case"ParallelN":return L(bi(r,Tl),(n)=>wm(e,n))}}}));var ca=xt("effect/Scope");var z0=(e,t)=>{if(e.state._tag==="Open")e.state.finalizers.set({},t)},V0={[ol]:ol,[il]:il,pipe(){return y(this,arguments)},fork(e){return F(()=>{let t=J0(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),z0(t,(o)=>F(()=>{if(this.state._tag==="Open")this.state.finalizers.delete(r)})),t})},close(e){return de(()=>{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 Ad(this.strategy)?m(Ut(t,(r)=>Rn(r(e))),L((r)=>m(vo(r),Gt(Js),ue(()=>Ht)))):Id(this.strategy)?m(mE(t,(r)=>Rn(r(e)),!1),L((r)=>m(vo(r,{parallel:!0}),Gt(Js),ue(()=>Ht)))):m(xm(t,this.strategy.parallelism,(r)=>Rn(r(e)),!1),L((r)=>m(vo(r,{parallel:!0}),Gt(Js),ue(()=>Ht))))})},addFinalizer(e){return de(()=>{if(this.state._tag==="Closed")return e(this.state.exit);return this.state.finalizers.set({},e),Fe})}},J0=(e=Oi)=>{let t=Object.create(V0);return t.strategy=e,t.state={_tag:"Open",finalizers:new Map},t};var wm=p(2,(e,t)=>_d(e,Os(xx(ca,t))));var G0=(e)=>ko(e,{differ:cE,fork:Ci});var fE=HS(uS),Y0=G0(Fo);var gE=p(2,(e,t)=>Cn((r)=>qt(r(e),{onFailure:(n)=>qt(t,{onFailure:(o)=>Ze(Ye(n,o)),onSuccess:()=>Ze(n)}),onSuccess:(n)=>Jr(t,n)}))),Z0=(e,t,r)=>qs((n)=>gE(L(_m(Yc(e)),(o)=>vn((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"&&_i(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(FS(o))}};o.addObserver((l)=>{c.forEach((u)=>u()),i(l)});let c=t.map((l,u)=>{let f=(d)=>{s[u]=d,a()};return l.listeners.addObserver(f),()=>l.listeners.removeObserver(f)});return a(),F(()=>{c.forEach((l)=>l())})})),de(()=>{let o=t.flatMap((i)=>{if(!i.state.completed)return[i];return[]});return Eo(o,(i)=>tE(i.request,Sd(n)))})));var xE=gd;var SE=bi;var Om=(e)=>function(){if(arguments.length===1){let t=arguments[0];return(r,...n)=>e(t,r,...n)}return e.apply(this,arguments)},bE=Om((e,t,r)=>{let n=Fc(),o=[[Ao,[[n,e.context]]]];if(r?.scheduler)o.push([Ul,[[n,r.scheduler]]]);let i=Yb(e.fiberRefs,{entries:o,forkAs:n});if(r?.updateRefs)i=r.updateRefs(i,n);let s=new Ql(n,i,e.runtimeFlags),a=t;if(r?.scope)a=L(SE(r.scope,Oi),(l)=>Pn(sl(l,qs((u)=>b(u,s.id())?Fe:Ks(s,u))),xi(t,(u)=>xE(l,u))));let c=s.currentSupervisor;if(c!==Fo)c.onStart(e.context,a,w(),s),s.addObserver((l)=>c.onEnd(l,s));if(ta.add(e.runtimeFlags,s),r?.immediate===!1)s.resume(a);else s.start(a);return s});var tF=Om((e,t)=>{let r=iF(e)(t);if(r._tag==="Failure")throw nF(r.effect_instruction_i0);return r.effect_instruction_i0});class _E 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 rF=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new _E(e);return Error.stackTraceLimit=t,r};var Em=Symbol.for("effect/Runtime/FiberFailure"),Xl=Symbol.for("effect/Runtime/FiberFailure/Cause");class wE extends Error{[Em];[Xl];constructor(e){let t=Ss(e)[0];super(t?.message||"An error has occurred");if(this[Em]=Em,this[Xl]=e,this.name=t?`(FiberFailure) ${t.name}`:"FiberFailure",t?.stack)this.stack=t.stack}toJSON(){return{_id:"FiberFailure",cause:this[Xl].toJSON()}}toString(){return"(FiberFailure) "+nr(this[Xl],{renderErrorCause:!0})}[Z](){return this.toString()}}var nF=(e)=>{let t=Error.stackTraceLimit;Error.stackTraceLimit=0;let r=new wE(e);return Error.stackTraceLimit=t,r};var oF=(e)=>{let t=e;switch(t._op){case"Failure":case"Success":return t;case"Left":return Gs(t.left);case"Right":return xe(t.right);case"Some":return xe(t.value);case"None":return Gs(new Vs)}},iF=Om((e,t)=>{let r=oF(t);if(r)return r;let n=new ea,o=bE(e)(t,{scheduler:n});n.flush();let i=o.unsafePoll();if(i)return i;return xd(Jc(rF(o),pl(o)))});class EE{context;runtimeFlags;fiberRefs;constructor(e,t,r){this.context=e,this.runtimeFlags=t,this.fiberRefs=r}pipe(){return y(this,arguments)}}var sF=(e)=>new EE(e.context,e.runtimeFlags,e.fiberRefs);var aF=Bf(zr,Hf,Uf),OE=sF({context:On(),runtimeFlags:aF,fiberRefs:Zb()});var TE=bE(OE);var kE=tF(OE);var AE=gi;var la=dE;var ua=de;var Ct=Fe;var IE=Ds;var eu=Ee;var vE=Oo;var Mo=wo;var ir=L;var RE=TE;var CE=kE;var Tm=(e,t)=>{switch(t._tag){case"StringKeyword":case"TemplateLiteral":return Object.keys(e);case"SymbolKeyword":return Object.getOwnPropertySymbols(e);case"Refinement":return Tm(e,t.from)}},pa=(e)=>{let t=!1,r;return()=>{if(t)return r;return r=e(),t=!0,r}},km=(e)=>Array.isArray(e),FE=(e)=>!Array.isArray(e),PE=(e)=>`[${ss(e)}]`,tu=(e)=>km(e)?e.map(PE).join(""):PE(e);var Un=(e,t,r,n)=>{let o=e;if(r&&ae(r))o+=`
34
+ at path: ${tu(r)}`;if(t!==void 0)o+=`
35
35
  details: ${t}`;if(n)o+=`
36
- schema (${n._tag}): ${n}`;return o},AE=(e)=>Dn("Invalid Argument",e);var IE=(e)=>Dn("Unsupported key schema",void 0,void 0,e),RE=(e)=>Dn("Unsupported literal",`literal value: ${lr(e)}`),Em=(e)=>Dn("Duplicate index signature",`${e} index signature`),vE=Dn("Unsupported index signature parameter","An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),CE=Dn("Invalid element","A required element cannot follow an optional element. ts(1257)"),Om=(e)=>Dn("Duplicate property signature transformation",`Duplicate key ${lr(e)}`);var Tm=(e)=>Dn("Duplicate property signature",`Duplicate key ${lr(e)}`);var FE=Symbol.for("effect/SchemaId/DateFromSelf"),NE=Symbol.for("effect/SchemaId/GreaterThan"),ME=Symbol.for("effect/SchemaId/GreaterThanOrEqualTo");var LE=Symbol.for("effect/SchemaId/Int");var DE=Symbol.for("effect/SchemaId/MinLength");var qE=Symbol.for("effect/SchemaId/MinItems");var HE=Symbol.for("effect/annotation/TypeConstructor"),Im=Symbol.for("effect/annotation/Brand"),jE=Symbol.for("effect/annotation/SchemaId"),Rm=Symbol.for("effect/annotation/Message"),eu=Symbol.for("effect/annotation/MissingMessage"),tu=Symbol.for("effect/annotation/Identifier"),mt=Symbol.for("effect/annotation/Title"),ru=Symbol.for("effect/annotation/AutoTitle"),Zr=Symbol.for("effect/annotation/Description"),vm=Symbol.for("effect/annotation/Examples"),Cm=Symbol.for("effect/annotation/Default"),Pm=Symbol.for("effect/annotation/JSONSchema"),Fm=Symbol.for("effect/annotation/Arbitrary"),Nm=Symbol.for("effect/annotation/Pretty"),Mm=Symbol.for("effect/annotation/Equivalence"),$E=Symbol.for("effect/annotation/Documentation"),Lm=Symbol.for("effect/annotation/Concurrency"),Dm=Symbol.for("effect/annotation/Batching"),qm=Symbol.for("effect/annotation/ParseIssueTitle"),Um=Symbol.for("effect/annotation/ParseOptions"),Hm=Symbol.for("effect/annotation/DecodingFallback"),jm=Symbol.for("effect/annotation/Surrogate"),$m=Symbol.for("effect/annotation/StableFilter"),Ze=p(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?I(e.annotations[t]):w());var Bm=Ze(Im);var BE=Ze(Rm),KE=Ze(eu),Km=Ze(mt),Wm=Ze(ru),ua=Ze(tu),zm=Ze(Zr);var WE=Ze(Lm),zE=Ze(Dm),VE=Ze(qm),JE=Ze(Um),GE=Ze(Hm),Vm=Ze(jm),iF=Ze($m),Jm=(e)=>Qg(iF(e),(t)=>t===!0),Gm=Symbol.for("effect/annotation/JSONIdentifier"),sF=Ze(Gm),aF=(e)=>Wt(sF(e),()=>ua(e));class vi{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 ce(xr(this),()=>"<declaration schema>")}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map((e)=>e.toJSON()),annotations:be(this.annotations)}}}var pa=(e)=>(t)=>t._tag===e;class Po{literal;annotations;_tag="Literal";constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return ce(xr(this),()=>lr(this.literal))}toJSON(){return{_tag:this._tag,literal:cn(this.literal)?String(this.literal):this.literal,annotations:be(this.annotations)}}}var nu=pa("Literal"),YE=new Po(null);class ou{symbol;annotations;_tag="UniqueSymbol";constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return ce(xr(this),()=>lr(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:be(this.annotations)}}}class ZE{annotations;_tag="UndefinedKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var iu=new ZE({[mt]:"undefined"});class QE{annotations;_tag="VoidKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var cF=new QE({[mt]:"void"});class XE{annotations;_tag="NeverKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var su=new XE({[mt]:"never"});class eO{annotations;_tag="UnknownKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var tO=new eO({[mt]:"unknown"});class rO{annotations;_tag="AnyKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var nO=new rO({[mt]:"any"});class oO{annotations;_tag="StringKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var iO=new oO({[mt]:"string",[Zr]:"a string"}),au=pa("StringKeyword");class sO{annotations;_tag="NumberKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var aO=new sO({[mt]:"number",[Zr]:"a number"});class cO{annotations;_tag="BooleanKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var lO=new cO({[mt]:"boolean",[Zr]:"a boolean"});class uO{annotations;_tag="BigIntKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var lF=new uO({[mt]:"bigint",[Zr]:"a bigint"});class pO{annotations;_tag="SymbolKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var uF=new pO({[mt]:"symbol",[Zr]:"a symbol"}),fO=pa("SymbolKeyword");class dO{annotations;_tag="ObjectKeyword";constructor(e={}){this.annotations=e}toString(){return nr(this)}toJSON(){return{_tag:this._tag,annotations:be(this.annotations)}}}var pF=new dO({[mt]:"object",[Zr]:"an object in the TypeScript meaning, i.e. the `object` type"});class Ci{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:be(this.annotations)}}toString(){return String(this.type)}}class qn extends Ci{isOptional;constructor(e,t,r={}){super(e,r);this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:be(this.annotations)}}toString(){return String(this.type)+(this.isOptional?"?":"")}}var mO=(e)=>e.map((t)=>t.type);class fa{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(CE)}toString(){return ce(xr(this),()=>fF(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map((e)=>e.toJSON()),rest:this.rest.map((e)=>e.toJSON()),isReadonly:this.isReadonly,annotations:be(this.annotations)}}}var fF=(e)=>{let t=e.elements.map(String).join(", ");return ey(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 Me extends qn{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:be(this.annotations)}}}var hO=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return!0;case"Refinement":return hO(e.from)}return!1};class Pi{type;isReadonly;parameter;constructor(e,t,r){if(this.type=t,this.isReadonly=r,hO(e))this.parameter=e;else throw Error(vE)}toString(){return(this.isReadonly?"readonly ":"")+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}}class Sr{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(Tm(s));n[s]=null}let o={string:!1,symbol:!1};for(let i=0;i<t.length;i++){let s=rh(t[i].parameter);if(au(s)){if(o.string)throw Error(Em("string"));o.string=!0}else if(fO(s)){if(o.symbol)throw Error(Em("symbol"));o.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return ce(xr(this),()=>dF(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map((e)=>e.toJSON()),indexSignatures:this.indexSignatures.map((e)=>e.toJSON()),annotations:be(this.annotations)}}}var UE=(e)=>e.map(String).join("; "),dF=(e)=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join("; ");if(e.indexSignatures.length>0)return`{ ${t}; ${UE(e.indexSignatures)} }`;else return`{ ${t} }`}else if(e.indexSignatures.length>0)return`{ ${UE(e.indexSignatures)} }`;else return"{}"};var mF=Nr(Xa(gr,(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})),hF={string:"StringKeyword",number:"NumberKeyword",boolean:"BooleanKeyword",bigint:"BigIntKeyword"},gO=(e)=>ps(e,(t)=>Ym(t)?gO(t.types):[t]),gF=(e)=>{let t=mF(e),r=[],n={},o=[];for(let i of t)switch(i._tag){case"NeverKeyword":break;case"AnyKeyword":return[nO];case"UnknownKeyword":return[tO];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=hF[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 it{types;annotations;static make=(e,t)=>cu(e)?new it(e,t):e.length===1?e[0]:su;static unify=(e,t)=>it.make(gF(gO(e)),t);_tag="Union";constructor(e,t={}){this.types=e,this.annotations=t}toString(){return ce(xr(this),()=>this.types.map(String).join(" | "))}toJSON(){return{_tag:this._tag,types:this.types.map((e)=>e.toJSON()),annotations:be(this.annotations)}}}var yO=(e,t)=>e.map(t),cu=(e)=>e.length>1,Ym=pa("Union"),km=N(Symbol.for("effect/Schema/AST/toJSONMemoMap"),()=>new WeakMap);class lu{f;annotations;_tag="Suspend";constructor(e,t={}){this.f=e,this.annotations=t,this.f=la(e)}toString(){return xr(this).pipe(Wt(()=>Vt(Gg(this.f)(),(e)=>xr(e))),ce(()=>"<suspended schema>"))}toJSON(){let e=this.f(),t=km.get(e);if(t)return t;return km.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:be(this.annotations)},km.set(e,t),t}}class da{from;filter;annotations;_tag="Refinement";constructor(e,t,r={}){this.from=e,this.filter=t,this.annotations=r}toString(){return ua(this).pipe(ce(()=>Ee(_O(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:be(this.annotations)}}}var ma=pa("Refinement"),uu={};class Zm{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 ce(xr(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:be(this.annotations)}}}class Qm{from;to;decode;encode;constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}}class Xm{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(Om(o));t[o]=!0;let i=n.to;if(r[i])throw Error(Om(i));r[i]=!0}}}var ha=(e,t)=>{let r=Object.getOwnPropertyDescriptors(e),n={...e.annotations};delete n[tu];let o={...n,...t},i=Vm(e);if(ue(i))o[jm]=ha(i.value,t);return r.annotations.value=o,Object.create(Object.getPrototypeOf(e),r)};var yF="[\\s\\S]*?",xF="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",xO=(e,t)=>{switch(e._tag){case"Literal":return bi(String(e.literal));case"StringKeyword":return yF;case"NumberKeyword":return xF;case"TemplateLiteral":return SO(e,t,!1);case"Union":return e.types.map((r)=>xO(r,t)).join("|")}},SF=(e,t,r,n)=>{if(Ym(e)){if(r&&!n)return`(?:${t})`}else if(!r||!n)return t;return`(${t})`},SO=(e,t,r)=>{let n="";if(e.head!==""){let o=bi(e.head);n+=t&&r?`(${o})`:o}for(let o of e.spans){let i=xO(o.type,t);if(n+=SF(o.type,i,t,r),o.literal!==""){let s=bi(o.literal);n+=t&&r?`(${s})`:s}}return n},bO=(e)=>new RegExp(`^${SO(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 Pi(i,t,!0));break;case"Literal":if(Be(i.literal)||_t(i.literal))r.push(new Me(i.literal,t,!1,!0));else throw Error(RE(i.literal));break;case"Enums":{for(let[s,a]of i.enums)r.push(new Me(a,t,!1,!0));break}case"UniqueSymbol":r.push(new Me(i.symbol,t,!1,!0));break;case"Union":i.types.forEach(o);break;default:throw Error(IE(i))}};return o(e),{propertySignatures:r,indexSignatures:n}};var th=(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 bF=th([vm,Cm,Pm,Fm,Nm,Mm]),Ne=(e)=>{switch(e._tag){case"Declaration":{let t=Ht(e.typeParameters,Ne);return t===e.typeParameters?e:new vi(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case"TupleType":{let t=Ht(e.elements,(o)=>{let i=Ne(o.type);return i===o.type?o:new qn(i,o.isOptional)}),r=mO(e.rest),n=Ht(r,Ne);return t===e.elements&&n===r?e:new fa(t,n.map((o)=>new Ci(o)),e.isReadonly,e.annotations)}case"TypeLiteral":{let t=Ht(e.propertySignatures,(n)=>{let o=Ne(n.type);return o===n.type?n:new Me(n.name,o,n.isOptional,n.isReadonly)}),r=Ht(e.indexSignatures,(n)=>{let o=Ne(n.type);return o===n.type?n:new Pi(n.parameter,o,n.isReadonly)});return t===e.propertySignatures&&r===e.indexSignatures?e:new Sr(t,r,e.annotations)}case"Union":{let t=Ht(e.types,Ne);return t===e.types?e:it.make(t,e.annotations)}case"Suspend":return new lu(()=>Ne(e.f()),e.annotations);case"Refinement":{let t=Ne(e.from);return t===e.from?e:new da(t,e.filter,e.annotations)}case"Transformation":{let t=bF(e);return Ne(t!==void 0?ha(e.to,t):e.to)}}return e};function Ht(e,t){let r=!1,n=no(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 Am=(e)=>{switch(e._tag){case"Transformation":return e.from;case"Refinement":return Am(e.from);case"Suspend":return Am(e.f())}},yr=(e,t)=>{switch(e._tag){case"Declaration":{let r=Ht(e.typeParameters,(n)=>yr(n,t));return r===e.typeParameters?e:new vi(r,e.decodeUnknown,e.encodeUnknown)}case"TupleType":{let r=Ht(e.elements,(i)=>{let s=yr(i.type,t);return s===i.type?i:new qn(s,i.isOptional)}),n=mO(e.rest),o=Ht(n,(i)=>yr(i,t));return r===e.elements&&o===n?e:new fa(r,o.map((i)=>new Ci(i)),e.isReadonly)}case"TypeLiteral":{let r=Ht(e.propertySignatures,(o)=>{let i=yr(o.type,t);return i===o.type?o:new Me(o.name,i,o.isOptional,o.isReadonly)}),n=Ht(e.indexSignatures,(o)=>{let i=yr(o.type,t);return i===o.type?o:new Pi(o.parameter,i,o.isReadonly)});return r===e.propertySignatures&&n===e.indexSignatures?e:new Sr(r,n)}case"Union":{let r=Ht(e.types,(n)=>yr(n,t));return r===e.types?e:it.make(r)}case"Suspend":{let r=void 0,n=aF(e);if(ue(n)){let o=t?"Bound":"";r={[Gm]:`${n.value}Encoded${o}`}}return new lu(()=>yr(e.f(),t),r)}case"Refinement":{let r=yr(e.from,t);if(t){if(r===e.from)return e;if(Am(e.from)===void 0&&Jm(e))return new da(r,e.filter,e.annotations);return r}else return r}case"Transformation":return yr(e.from,t)}return e},pu=(e)=>yr(e,!1);var be=(e)=>{let t={};for(let r of Object.getOwnPropertySymbols(e))t[String(r)]=e[r];return t},rh=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return e;case"Refinement":return rh(e.from)}};var nr=(e)=>ce(xr(e),()=>e._tag);function _F(e){return Ee(Bm(e),{onNone:()=>"",onSome:(t)=>t.map((r)=>` & Brand<${lr(r)}>`).join("")})}var _O=(e)=>Km(e).pipe(Wt(()=>zm(e)),Wt(()=>Wm(e)),zt((t)=>t+_F(e))),xr=(e)=>Wt(ua(e),()=>_O(e));class Le{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 Fi{ast;message;_tag="Missing";actual=void 0;constructor(e,t){this.ast=e,this.message=t}}class _e{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 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 jt{ast;actual;message;_tag="Type";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}class sh{ast;actual;message;_tag="Forbidden";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}var EO=Symbol.for("effect/Schema/ParseErrorTypeId");class kO extends Cb("ParseError"){[EO]=EO;get message(){return this.toString()}toString(){return xa.formatIssueSync(this.issue)}toJSON(){return{_id:"ParseError",message:this.toString()}}[J](){return this.toJSON()}}var ch=(e)=>new kO({issue:e}),AO=B,IO=U;var gt=xp,Qr=p(2,(e,t)=>gt(e)?us(e,{onLeft:U,onRight:t}):rr(e,t)),ir=p(2,(e,t)=>gt(e)?Bg(e,t):Zl(e,t)),hu=p(2,(e,t)=>gt(e)?Qa(e,t):wE(e,t));var RO=p(2,(e,t)=>gt(e)?us(e,{onLeft:t,onRight:B}):_E(e,t)),vO=(e,t)=>{if(t===void 0||_t(t))return e;if(e===void 0)return t;return{...e,...t}},CO=(e,t,r)=>{let n=Qe(e,t);return(o,i)=>n(o,vO(r,i))},wF=(e,t,r)=>{let n=CO(e,t,r);return(o,i)=>Sp(n(o,i),ch)};var PO=(e,t)=>CO(e.ast,!0,t);var gu=(e,t)=>wF(Ne(e.ast),!0,t);var EF=N(Symbol.for("effect/ParseResult/decodeMemoMap"),()=>new WeakMap),OF=N(Symbol.for("effect/ParseResult/encodeMemoMap"),()=>new WeakMap),Qe=(e,t)=>{let r=t?EF:OF,n=r.get(e);if(n)return n;let o=TF(e,t),i=JE(e),s=ue(i)?(l,u)=>o(l,vO(u,i.value)):o,a=GE(e),c=t&&ue(a)?(l,u)=>ya(RO(s(l,u),a.value),e,l,u):s;return r.set(e,c),c},nh=(e)=>ft(WE(e)),oh=(e)=>ft(zE(e)),TF=(e,t)=>{switch(e._tag){case"Refinement":if(t){let r=Qe(e.from,!0);return(n,o)=>{o=o??uu;let i=o?.errors==="all",s=Qr(RO(r(n,o),(a)=>{let c=new du(e,n,"From",a);if(i&&Jm(e)&&DO(a))return Ee(e.filter(n,o,e),{onNone:()=>U(c),onSome:(l)=>U(new _e(e,n,[c,new du(e,n,"Predicate",l)]))});return U(c)}),(a)=>Ee(e.filter(a,o,e),{onNone:()=>B(a),onSome:(c)=>U(new du(e,n,"Predicate",c))}));return ya(s,e,n,o)}}else{let r=Qe(Ne(e),!0),n=Qe(NO(e.from),!1);return(o,i)=>ya(Qr(r(o,i),(s)=>n(s,i)),e,o,i)}case"Transformation":{let r=AF(e.transformation,t),n=t?Qe(e.from,!0):Qe(e.to,!1),o=t?Qe(e.to,!0):Qe(e.from,!1);return(i,s)=>ya(Qr(hu(n(i,s),(a)=>new mu(e,i,t?"Encoded":"Type",a)),(a)=>Qr(hu(r(a,s??uu,e,i),(c)=>new mu(e,i,"Transformation",c)),(c)=>hu(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)=>ya(r(n,o??uu,e),e,n,o)}case"Literal":return ht(e,(r)=>r===e.literal);case"UniqueSymbol":return ht(e,(r)=>r===e.symbol);case"UndefinedKeyword":return ht(e,bg);case"NeverKeyword":return ht(e,_g);case"UnknownKeyword":case"AnyKeyword":case"VoidKeyword":return B;case"StringKeyword":return ht(e,Be);case"NumberKeyword":return ht(e,_t);case"BooleanKeyword":return ht(e,Jn);case"BigIntKeyword":return ht(e,cn);case"SymbolKeyword":return ht(e,Gn);case"ObjectKeyword":return ht(e,ot);case"Enums":return ht(e,(r)=>e.enums.some(([n,o])=>o===r));case"TemplateLiteral":{if(e.spans.every((n)=>au(n.type)))return ht(e,(n)=>{if(!Be(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=bO(e);return ht(e,(n)=>Be(n)&&r.test(n))}case"TupleType":{let r=e.elements.map((l)=>Qe(l.type,t)),n=e.rest.map((l)=>Qe(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=nh(e),c=oh(e);return(l,u)=>{if(!kp(l))return U(new jt(e,l));let f=u?.errors==="all",d=[],h=0,g=[],P=l.length;for(let F=P;F<=i-1;F++){let D=new Le(F,l,new Fi(o[F-P]));if(f){d.push([h++,D]);continue}else return U(new _e(e,l,D,g))}if(e.rest.length===0)for(let F=e.elements.length;F<=P-1;F++){let D=new Le(F,l,new ih(l[F],`is unexpected, expected: ${s}`));if(f){d.push([h++,D]);continue}else return U(new _e(e,l,D,g))}let x=0,E=void 0;for(;x<r.length;x++)if(P<x+1){if(e.elements[x].isOptional)continue}else{let F=r[x],D=F(l[x],u);if(gt(D)){if(he(D)){let T=new Le(x,l,D.left);if(f){d.push([h++,T]);continue}else return U(new _e(e,l,T,or(g)))}g.push([h++,D.right])}else{let T=h++,A=x;if(!E)E=[];E.push(({es:R,output:v})=>rr(Co(D),(te)=>{if(he(te)){let re=new Le(A,l,te.left);if(f)return R.push([T,re]),kt;else return U(new _e(e,l,re,or(v)))}return v.push([T,te.right]),kt}))}}if(se(n)){let[F,...D]=n;for(;x<P-D.length;x++){let T=F(l[x],u);if(gt(T))if(he(T)){let A=new Le(x,l,T.left);if(f){d.push([h++,A]);continue}else return U(new _e(e,l,A,or(g)))}else g.push([h++,T.right]);else{let A=h++,R=x;if(!E)E=[];E.push(({es:v,output:te})=>rr(Co(T),(re)=>{if(he(re)){let Y=new Le(R,l,re.left);if(f)return v.push([A,Y]),kt;else return U(new _e(e,l,Y,or(te)))}else return te.push([A,re.right]),kt}))}}for(let T=0;T<D.length;T++){let A=x+T;if(P<A+1)continue;else{let R=D[T](l[A],u);if(gt(R)){if(he(R)){let v=new Le(A,l,R.left);if(f){d.push([h++,v]);continue}else return U(new _e(e,l,v,or(g)))}g.push([h++,R.right])}else{let v=h++;if(!E)E=[];E.push(({es:te,output:re})=>rr(Co(R),(Y)=>{if(he(Y)){let xe=new Le(A,l,Y.left);if(f)return te.push([v,xe]),kt;else return U(new _e(e,l,xe,or(re)))}return re.push([v,Y.right]),kt}))}}}}let W=({es:F,output:D})=>fn(F)?U(new _e(e,l,or(F),or(D))):B(or(D));if(E&&E.length>0){let F=E;return ca(()=>{let D={es:Go(d),output:Go(g)};return rr(aa(F,(T)=>T(D),{concurrency:a,batching:c,discard:!0}),()=>W(D))})}return W({output:g,es:d})}}case"TypeLiteral":{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return ht(e,wg);let r=[],n={},o=[];for(let u of e.propertySignatures)r.push([Qe(u.type,t),u]),n[u.name]=null,o.push(u.name);let i=e.indexSignatures.map((u)=>[Qe(u.parameter,t),Qe(u.type,t),u.parameter]),s=it.make(e.indexSignatures.map((u)=>u.parameter).concat(o.map((u)=>Gn(u)?new ou(u):new Po(u)))),a=Qe(s,t),c=nh(e),l=oh(e);return(u,f)=>{if(!np(u))return U(new jt(e,u));let d=f?.errors==="all",h=[],g=0,P=f?.onExcessProperty==="error",x=f?.onExcessProperty==="preserve",E={},W;if(P||x){W=Reflect.ownKeys(u);for(let A of W){let R=a(A,f);if(gt(R)&&he(R))if(P){let v=new Le(A,u,new ih(u[A],`is unexpected, expected: ${String(s)}`));if(d){h.push([g++,v]);continue}else return U(new _e(e,u,v,E))}else E[A]=u[A]}}let F=void 0,D=f?.exact===!0;for(let A=0;A<r.length;A++){let R=r[A][1],v=R.name,te=Object.prototype.hasOwnProperty.call(u,v);if(!te){if(R.isOptional)continue;else if(D){let xe=new Le(v,u,new Fi(R));if(d){h.push([g++,xe]);continue}else return U(new _e(e,u,xe,E))}}let re=r[A][0],Y=re(u[v],f);if(gt(Y)){if(he(Y)){let xe=new Le(v,u,te?Y.left:new Fi(R));if(d){h.push([g++,xe]);continue}else return U(new _e(e,u,xe,E))}E[v]=Y.right}else{let xe=g++,Rt=v;if(!F)F=[];F.push(({es:vt,output:Bt})=>rr(Co(Y),(je)=>{if(he(je)){let $e=new Le(Rt,u,te?je.left:new Fi(R));if(d)return vt.push([xe,$e]),kt;else return U(new _e(e,u,$e,Bt))}return Bt[Rt]=je.right,kt}))}}for(let A=0;A<i.length;A++){let R=i[A],v=R[0],te=R[1],re=_m(u,R[2]);for(let Y of re){let xe=v(Y,f);if(gt(xe)&&pt(xe)){let Rt=te(u[Y],f);if(gt(Rt)){if(he(Rt)){let vt=new Le(Y,u,Rt.left);if(d){h.push([g++,vt]);continue}else return U(new _e(e,u,vt,E))}else if(!Object.prototype.hasOwnProperty.call(n,Y))E[Y]=Rt.right}else{let vt=g++,Bt=Y;if(!F)F=[];F.push(({es:je,output:$e})=>rr(Co(Rt),(Ct)=>{if(he(Ct)){let qo=new Le(Bt,u,Ct.left);if(d)return je.push([vt,qo]),kt;else return U(new _e(e,u,qo,$e))}else{if(!Object.prototype.hasOwnProperty.call(n,Y))$e[Y]=Ct.right;return kt}}))}}}}let T=({es:A,output:R})=>{if(fn(A))return U(new _e(e,u,or(A),R));if(f?.propertyOrder==="original"){let v=W||Reflect.ownKeys(u);for(let re of o)if(v.indexOf(re)===-1)v.push(re);let te={};for(let re of v)if(Object.prototype.hasOwnProperty.call(R,re))te[re]=R[re];return B(te)}return B(R)};if(F&&F.length>0){let A=F;return ca(()=>{let R={es:Go(h),output:Object.assign({},E)};return rr(aa(A,(v)=>v(R),{concurrency:c,batching:l,discard:!0}),()=>T(R))})}return T({es:h,output:E})}}case"Union":{let r=FO(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],Qe(e.types[l],t));let a=nh(e)??1,c=oh(e);return(l,u)=>{let f=[],d=0,h=[];if(o>0)if(Xi(l))for(let x=0;x<o;x++){let E=n[x],W=r.keys[E].buckets;if(Object.prototype.hasOwnProperty.call(l,E)){let F=String(l[E]);if(Object.prototype.hasOwnProperty.call(W,F))h=h.concat(W[F]);else{let{candidates:D,literals:T}=r.keys[E],A=it.make(T),R=D.length===i?new Sr([new Me(E,A,!1,!0)],[]):it.make(D);f.push([d++,new _e(R,l,new Le(E,l,new jt(A,l[E])))])}}else{let{candidates:F,literals:D}=r.keys[E],T=new Me(E,it.make(D),!1,!0),A=F.length===i?new Sr([T],[]):it.make(F);f.push([d++,new _e(A,l,new Le(E,l,new Fi(T)))])}}else{let x=r.candidates.length===i?e:it.make(r.candidates);f.push([d++,new jt(x,l)])}if(r.otherwise.length>0)h=h.concat(r.otherwise);let g=void 0;for(let x=0;x<h.length;x++){let E=h[x],W=s.get(E)(l,u);if(gt(W)&&(!g||g.length===0))if(pt(W))return W;else f.push([d++,W.left]);else{let F=d++;if(!g)g=[];g.push((D)=>ca(()=>{if("finalResult"in D)return kt;else return rr(Co(W),(T)=>{if(pt(T))D.finalResult=T;else D.es.push([F,T.left]);return kt})}))}}let P=(x)=>fn(x)?x.length===1&&x[0][1]._tag==="Type"?U(x[0][1]):U(new _e(e,l,or(x))):U(new jt(e,l));if(g&&g.length>0){let x=g;return ca(()=>{let E={es:Go(f)};return rr(aa(x,(W)=>W(E),{concurrency:a,batching:c,discard:!0}),()=>{if("finalResult"in E)return E.finalResult;return P(E.es)})})}return P(f)}}case"Suspend":{let r=la(()=>Qe(e.f(),t));return(n,o)=>r()(n,o)}}},ht=(e,t)=>(r)=>t(r)?B(r):U(new jt(e,r)),ga=(e,t)=>{switch(e._tag){case"Declaration":{let r=Vm(e);if(ue(r))return ga(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):Ne(o.type);if(nu(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):Ne(o.type);if(nu(i)&&!o.isOptional)r.push([n,i])}return r}case"Refinement":return ga(e.from,t);case"Suspend":return ga(e.f(),t);case"Transformation":return ga(t?e.from:e.to,t)}return[]},FO=(e,t)=>{let r={},n=[],o=[];for(let i=0;i<e.length;i++){let s=e[i],a=ga(s,t);if(a.length>0){o.push(s);for(let c=0;c<a.length;c++){let[l,u]=a[c],f=String(u.literal);r[l]=r[l]||{buckets:{},literals:[],candidates:[]};let d=r[l].buckets;if(Object.prototype.hasOwnProperty.call(d,f)){if(c<a.length-1)continue;d[f].push(s),r[l].literals.push(u),r[l].candidates.push(s)}else{d[f]=[s],r[l].literals.push(u),r[l].candidates.push(s);break}}}else n.push(s)}return{keys:r,otherwise:n,candidates:o}},NO=(e)=>ma(e)?NO(e.from):e,ya=(e,t,r,n)=>{if(n?.isEffectAllowed===!0)return e;if(gt(e))return e;let o=new Qs,i=EE(e,{scheduler:o});o.flush();let s=i.unsafePoll();if(s){if(D_(s))return B(s.value);let a=s.cause;if(WS(a))return U(a.error);return U(new sh(t,r,zS(a)))}return U(new sh(t,r,"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"))},kF=([e],[t])=>e>t?1:e<t?-1:0;function or(e){return e.sort(kF).map((t)=>t[1])}var AF=(e,t)=>{switch(e._tag){case"FinalTransformation":return t?e.decode:e.encode;case"ComposeTransformation":return B;case"TypeLiteralTransformation":return(r)=>{let n=B(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=ir(n,(l)=>{let u=a(Object.prototype.hasOwnProperty.call(l,i)?I(l[i]):w());if(delete l[i],ue(u))l[s]=u.value;return l})}return n}}},st=(e,t=[])=>({value:e,forest:t}),xa={formatIssue:(e)=>ir(Ni(e),IF),formatIssueSync:(e)=>{let t=xa.formatIssue(e);return gt(t)?Wg(t):OE(t)},formatError:(e)=>xa.formatIssue(e.issue),formatErrorSync:(e)=>xa.formatIssueSync(e.issue)},IF=(e)=>e.value+MO(`
37
- `,e.forest),MO=(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+=MO(e+(n>1&&!s?"\u2502 ":" "),o.forest)}return r},RF=(e)=>{switch(e){case"Encoded":return"Encoded side transformation failure";case"Transformation":return"Transformation process failure";case"Type":return"Type side transformation failure"}},vF=(e)=>{switch(e){case"From":return"From side refinement failure";case"Predicate":return"Predicate refinement failure"}},LO=(e)=>("ast"in e)?I(e.ast):w(),ah=B(void 0),CF=(e)=>LO(e).pipe(Vt(BE),Ee({onNone:()=>ah,onSome:(t)=>{let r=t(e);if(Be(r))return B({message:r,override:!1});if(bE(r))return Zl(r,(n)=>({message:n,override:!1}));if(Be(r.message))return B({message:r.message,override:r.override});return Zl(r.message,(n)=>({message:n,override:r.override}))}})),lh=(e)=>(t)=>t._tag===e,DO=lh("Composite"),OO=lh("Refinement"),TO=lh("Transformation"),Sa=(e)=>Qr(CF(e),(t)=>{if(t!==void 0)return!t.override&&(DO(e)||OO(e)&&e.kind==="From"||TO(e)&&e.kind!=="Transformation")?TO(e)||OO(e)?Sa(e.issue):ah:B(t.message);return ah}),qO=(e)=>LO(e).pipe(Vt(VE),Yg((t)=>t(e)),ft);function PF(e){return zm(e).pipe(Wt(()=>Km(e)),Wt(()=>Wm(e)),Wt(()=>ua(e)),ce(()=>`{ ${e.from} | filter }`))}function FF(e){if(e.message!==void 0)return e.message;return`Expected ${ma(e.ast)?PF(e.ast):String(e.ast)}, actual ${lr(e.actual)}`}var NF=(e)=>ir(Sa(e),(t)=>t??qO(e)??FF(e)),fu=(e)=>qO(e)??String(e.ast),MF=(e)=>e.message??"is forbidden",LF=(e)=>e.message??"is unexpected",DF=(e)=>{let t=KE(e.ast);if(ue(t)){let r=t.value();return Be(r)?B(r):r}return B(e.message??"is missing")},Ni=(e)=>{switch(e._tag){case"Type":return ir(NF(e),st);case"Forbidden":return B(st(fu(e),[st(MF(e))]));case"Unexpected":return B(st(LF(e)));case"Missing":return ir(DF(e),st);case"Transformation":return Qr(Sa(e),(t)=>{if(t!==void 0)return B(st(t));return ir(Ni(e.issue),(r)=>st(fu(e),[st(RF(e.kind),[r])]))});case"Refinement":return Qr(Sa(e),(t)=>{if(t!==void 0)return B(st(t));return ir(Ni(e.issue),(r)=>st(fu(e),[st(vF(e.kind),[r])]))});case"Pointer":return ir(Ni(e.issue),(t)=>st(Ql(e.path),[t]));case"Composite":return Qr(Sa(e),(t)=>{if(t!==void 0)return B(st(t));let r=fu(e);return wm(e.issues)?ir(aa(e.issues,Ni),(n)=>st(r,n)):ir(Ni(e.issues),(n)=>st(r,[n]))})}};var UO=p((e)=>ot(e[0]),(e,...t)=>{let r={};for(let n of t)if(n in e)r[n]=e[n];return r}),HO=p((e)=>ot(e[0]),(e,...t)=>{let r={...e};for(let n of t)delete r[n];return r});var ba=Symbol.for("effect/Schema");function Xe(e){return class{[ba]=jO;static ast=e;static annotations(r){return Xe(Xr(this.ast,r))}static pipe(){return y(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[ba]=jO}}var jO={_A:(e)=>e,_I:(e)=>e,_R:(e)=>e};var $O={typeConstructor:HE,schemaId:jE,message:Rm,missingMessage:eu,identifier:tu,title:mt,description:Zr,examples:vm,default:Cm,documentation:$E,jsonSchema:Pm,arbitrary:Fm,pretty:Nm,equivalence:Mm,concurrency:Lm,batching:Dm,parseIssueTitle:qm,parseOptions:Um,decodingFallback:Hm},Fo=(e)=>{if(!e)return{};let t={...e};for(let r in $O)if(r in e){let n=$O[r];t[n]=e[r],delete t[r]}return t},Xr=(e,t)=>ha(e,Fo(t));var yu=(e,t)=>{let r=PO(e,t);return(n,o)=>Qa(r(n,o),ch)};var BO=(e)=>_(e,ba)&&ot(e[ba]);function HF(e){return cu(e)?it.make(yO(e,(t)=>new Po(t))):new Po(e[0])}function JO(e,t=HF(e)){return class extends Xe(t){static annotations(n){return JO(this.literals,Xr(this.ast,n))}static literals=[...e]}}function q(...e){return se(e)?JO(e):fh}var jF=(e,t,r)=>ph(e,new vi(e.map((n)=>n.ast),(...n)=>t.decode(...n.map(Xe)),(...n)=>t.encode(...n.map(Xe)),Fo(r))),$F=(e,t)=>{let r=()=>(o,i,s)=>e(o)?AO(o):IO(new jt(s,o));return ph([],new vi([],r,r,Fo(t)))};function ph(e,t){return class extends Xe(t){static annotations(n){return ph(this.typeParameters,Xr(this.ast,n))}static typeParameters=[...e]}}var At=function(){if(Array.isArray(arguments[0])){let r=arguments[0],n=arguments[1],o=arguments[2];return jF(r,n,o)}let e=arguments[0],t=arguments[1];return $F(e,t)};class GO extends Xe(iu){}class en extends Xe(YE){}class fh extends Xe(su){}class le extends Xe(iO){}class xu extends Xe(aO){}class de extends Xe(lO){}var BF=(e)=>it.make(e.map((t)=>t.ast));function YO(e,t=BF(e)){return class extends Xe(t){static annotations(n){return YO(this.members,Xr(this.ast,n))}static members=[...e]}}function yt(...e){return cu(e)?YO(e):se(e)?e[0]:fh}var KF=(e)=>yt(e,GO);var WF=(e,t)=>new fa(e.map((r)=>BO(r)?new qn(r.ast,!1):r.ast),t.map((r)=>BO(r)?new Ci(r.ast):r.ast),!0);function ZO(e,t,r=WF(e,t)){return class extends Xe(r){static annotations(o){return ZO(this.elements,this.rest,Xr(this.ast,o))}static elements=[...e];static rest=[...t]}}function QO(e,t){return class extends ZO([],[e],t){static annotations(n){return QO(this.value,Xr(this.ast,n))}static value=e}}var V=(e)=>QO(e);var uh=(e)=>e?'"?:"':'":"';class dh extends qn{isReadonly;defaultValue;_tag="PropertySignatureDeclaration";constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}toString(){let e=uh(this.isOptional),t=String(this.type);return`PropertySignature<${e}, ${t}, never, ${e}, ${t}>`}}class XO extends qn{isReadonly;defaultValue;constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}}var zF=(e)=>{if(e===void 0)return"never";if(Be(e))return JSON.stringify(e);return String(e)};class eT{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<${uh(this.to.isOptional)}, ${this.to.type}, ${zF(this.from.fromKey)}, ${uh(this.from.isOptional)}, ${this.from.type}>`}}var tT=(e,t)=>{switch(e._tag){case"PropertySignatureDeclaration":return new dh(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case"PropertySignatureTransformation":return new eT(e.from,new XO(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},rT=Symbol.for("effect/PropertySignature"),nT=(e)=>_(e,rT);class mh{ast;[ba];[rT]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return y(this,arguments)}annotations(e){return new mh(tT(this.ast,Fo(e)))}toString(){return String(this.ast)}}class hh extends mh{from;constructor(e,t){super(e);this.from=t}annotations(e){return new hh(tT(this.ast,Fo(e)),this.from)}}var G=(e)=>{let t=e.ast===iu||e.ast===su?iu:KF(e).ast;return new hh(new dh(t,!0,!0,{},void 0),e)};var VF=th([eu]),JF=(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(nT(u)){let f=u.ast;switch(f._tag){case"PropertySignatureDeclaration":{let{type:d,isOptional:h,annotations:g}=f;i.push(new Me(l,d,h,!0,VF(f))),s.push(new Me(l,Ne(d),h,!0,g)),n.push(new Me(l,d,h,!0,g));break}case"PropertySignatureTransformation":{let d=f.from.fromKey??l;i.push(new Me(d,f.from.type,f.from.isOptional,!0,f.from.annotations)),s.push(new Me(l,f.to.type,f.to.isOptional,!0,f.to.annotations)),a.push(new Qm(d,l,f.decode,f.encode));break}}}else i.push(new Me(l,u.ast,!1,!0)),s.push(new Me(l,Ne(u.ast),!1,!0)),n.push(new Me(l,u.ast,!1,!0))}if(se(a)){let c=[],l=[];for(let u of t){let{indexSignatures:f,propertySignatures:d}=eh(u.key.ast,u.value.ast);d.forEach((h)=>{i.push(h),s.push(new Me(h.name,Ne(h.type),h.isOptional,h.isReadonly,h.annotations))}),f.forEach((h)=>{c.push(h),l.push(new Pi(h.parameter,Ne(h.type),h.isReadonly))})}return new Zm(new Sr(i,c,{[ru]:"Struct (Encoded side)"}),new Sr(s,l,{[ru]:"Struct (Type side)"}),new Xm(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 Sr(n,o)},GF=(e,t)=>{let r=Reflect.ownKeys(e);for(let n of r){let o=e[n];if(t[n]===void 0&&nT(o)){let i=o.ast,s=i._tag==="PropertySignatureDeclaration"?i.defaultValue:i.to.defaultValue;if(s!==void 0)t[n]=s()}}return t};function oT(e,t,r=JF(e,t)){return class extends Xe(r){static annotations(o){return oT(this.fields,this.records,Xr(this.ast,o))}static fields={...e};static records=[...t];static make=(o,i)=>{let s=GF(e,{...o});return gh(i)?s:gu(this)(s)};static pick(...o){return z(UO(e,...o))}static omit(...o){return z(HO(e,...o))}}}function z(e,...t){return oT(e,t)}function iT(e,t){return class extends Xe(t){static annotations(n){return iT(this.from,Xr(this.ast,n))}static make=(n,o)=>gh(o)?n:gu(this)(n);static from=e}}var _a=(e,t)=>(r)=>{let n=Ee(Bm(r.ast),{onNone:()=>[e],onSome:(i)=>[...i,e]}),o=ha(r.ast,Fo({[Im]:n,...t}));return iT(r,o)};var YF=Symbol.for("effect/SchemaId/Refine");function sT(e,t,r){return class extends Xe(r){static annotations(o){return sT(this.from,this.filter,Xr(this.ast,o))}static[YF]=e;static from=e;static filter=t;static make=(o,i)=>gh(i)?o:gu(this)(o)}}var KO=(e,t,r)=>{if(Jn(e))return e?w():I(new jt(t,r));if(Be(e))return I(new jt(t,r,e));if(e!==void 0){if("_tag"in e)return I(e);let n=new jt(t,r,e.message);return I(se(e.path)?new Le(e.path,r,n):n)}return w()},ZF=(e,t,r)=>{if(kE(e))return KO(e,t,r);if(se(e)){let n=tc(e,(o)=>KO(o,t,r));if(se(n))return I(n.length===1?n[0]:new _e(t,r,n))}return w()};function br(e,t){return(r)=>{function n(i,s,a){return ZF(e(i,s,a),a,i)}let o=new da(r.ast,n,Fo(t));return sT(r,n,o)}}var QF=DE,aT=(e,t)=>(r)=>r.pipe(br((n)=>n.length>=e,{schemaId:QF,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t}));var WO=Symbol.for("effect/SchemaId/Pattern"),_r=(e,t)=>(r)=>{let n=e.source;return r.pipe(br((o)=>(e.lastIndex=0,e.test(o)),{schemaId:WO,[WO]:{regex:e},description:`a string matching the pattern ${n}`,jsonSchema:{pattern:n},...t}))};var XF=Symbol.for("effect/SchemaId/UUID"),zO=/^[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 eN extends le.pipe(_r(zO,{schemaId:XF,identifier:"UUID",jsonSchema:{format:"uuid",pattern:zO.source},description:"a Universally Unique Identifier",arbitrary:()=>(e)=>e.uuid()})){}var tN=NE,cT=(e,t)=>(r)=>r.pipe(br((n)=>n>e,{schemaId:tN,title:`greaterThan(${e})`,description:e===0?"a positive number":`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),rN=ME,lT=(e,t)=>(r)=>r.pipe(br((n)=>n>=e,{schemaId:rN,title:`greaterThanOrEqualTo(${e})`,description:e===0?"a non-negative number":`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t}));var nN=LE,oN=(e)=>(t)=>t.pipe(br((r)=>Number.isSafeInteger(r),{schemaId:nN,title:"int",description:"an integer",jsonSchema:{type:"integer"},...e}));class Su extends xu.pipe(oN({identifier:"Int"})){}var iN=qE,bu=(e,t)=>(r)=>{let n=Math.floor(e);if(n<1)throw Error(AE(`Expected an integer greater than or equal to 1, actual ${e}`));return r.pipe(br((o)=>o.length>=n,{schemaId:iN,title:`minItems(${n})`,description:`an array of at least ${n} item(s)`,jsonSchema:{minItems:n},[$m]:!0,...t}))};var VO=FE;class sN extends At($a,{typeConstructor:{_tag:"Date"},identifier:"DateFromSelf",schemaId:VO,[VO]:{noInvalidDate:!1},description:"a potentially invalid Date instance",pretty:()=>(e)=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>(e)=>e.date({noInvalidDate:!1}),equivalence:()=>xg}){}function gh(e){return Jn(e)?e:e?.disableValidation??!1}var aN={onExcessProperty:"error"};function tn(e,t){return yu(e,aN)(t)}var yh=q("computer_use","work","frontend","security"),cN=q("computer_use","work","frontend","security"),lN=q("installed","disabled","missing","uncertain"),uN=q("healthy","missing","disabled","uncertain"),pN=Object.freeze(["openai-curated","openai-curated-remote"]),fN=Object.freeze(["build-web-apps","codex-security"]);var rn=Object.freeze({coding:!0,computer_use:!1,work:!1,frontend:!0,security:!0}),dN={work:{name:"work",pluginIds:["documents@openai-primary-runtime","pdf@openai-primary-runtime","presentations@openai-primary-runtime","spreadsheets@openai-primary-runtime","template-creator@openai-primary-runtime"],defaultSelected:rn.work,migrationKey:"work",semanticSkillIds:["documents:documents","pdf:pdf","presentations:Presentations","spreadsheets:Spreadsheets","template-creator:template-creator"],ownership:"shared-preserve"},frontend:{name:"frontend",pluginIds:["build-web-apps@openai-curated"],defaultSelected:rn.frontend,migrationKey:"frontend",semanticSkillIds:["build-web-apps:frontend-app-builder","build-web-apps:frontend-testing-debugging","build-web-apps:react-best-practices"],ownership:"shared-preserve"},security:{name:"security",pluginIds:["codex-security@openai-curated"],defaultSelected:rn.security,migrationKey:"security",semanticSkillIds:["codex-security:security-scan","codex-security:security-diff-scan","codex-security:threat-model"],ownership:"shared-preserve"},computer_use:{name:"computer_use",pluginIds:["computer-use@openai-bundled"],defaultSelected:rn.computer_use,migrationKey:"computer_use",semanticSkillIds:["computer-use:computer-use"],ownership:"shared-preserve"}},mN=Object.freeze(dN),hN=Object.freeze(["computer_use","work","frontend","security"]),gN=Object.freeze({computer_use:rn.computer_use,work:rn.work,frontend:rn.frontend,security:rn.security});var fT=q("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"),yN=z({identifier:fT,label:le,requiresRootApproval:de});function wr(e){return z({identifier:q(e),label:le,requiresRootApproval:de})}var xN=z({localRepositoryEdit:wr("local.repository.edit"),localRepositoryCheck:wr("local.repository.check"),localRepositoryLint:wr("local.repository.lint"),localRepositoryFormat:wr("local.repository.format"),localRepositoryCommit:wr("local.repository.commit"),externalRead:wr("external.read"),specialistDispatch:wr("specialist.dispatch"),versionControlServerMutation:wr("vcs.server.mutation"),versionControlServerCiTrigger:wr("vcs.server.ci-trigger"),unknownEffect:wr("unknown.effect")}),xh={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}};cr(xh);var SN=q("never","root"),dT=Object.values(xh);function uT(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 pT(e){return e.length===0?e:`${e[0]?.toUpperCase()??""}${e.slice(1)}`}var bN=dT.filter((e)=>!e.requiresRootApproval),_N=dT.filter((e)=>e.requiresRootApproval),wN=Object.freeze({noRootApproval:`${pT(uT(bN))} actions do not require Root approval.`,rootApproval:`${pT(uT(_N))} require Root approval.`});var sr=le.pipe(_r(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),Sh=le.pipe(_r(/^[0-9a-f]{64}$/u)),IB=sr.pipe(_a("RunId")),RB=sr.pipe(_a("ProjectId")),vB=sr.pipe(_a("TrustId")),CB=Sh.pipe(_a("Sha256Digest"));var EN=z({run_id:sr,objective_lineage:sr,parent_run_id:G(yt(sr,en))}),ON=z({project_id:sr,trust_id:sr,trust_digest:Sh}),TN=z({project_id:sr,project_digest:Sh}),kN=le.pipe(_r(/^state-[0-9]+\.[0-9]+$/u));var _u=q("low","default","high"),yT=q("go","Go","plus-low","plus","plus-high","pro-5x","pro-20x"),AN=yt(_u,yT);var xT=q("standard","fast","fast-all"),IN=q("low","medium","high","xhigh","max"),ST="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.",nn=[{role:"Explorer",tasks:[{name:"lookup",description:"Use when Root needs one exact repository fact; locate it and return the exact path, symbol, or value.",instruction:"Locate the exact requested repository fact."},{name:"trace",description:"Use when Root needs a complete in-scope execution or reference path; trace every relevant caller and constraint, then return the path and evidence.",instruction:"Trace the complete in-scope execution or reference path."}],capability:"repository-read",authority:"Read only the delegated Assignment repository scope; Git/VCS, lifecycle, and decisions remain Root-only.",evidence:"Return exact paths, symbols, callers, tests, and constraints.",completion:"Account for every in-scope caller and constraint.",permissions:{network:!1,write:!1}},{role:"Librarian",tasks:[{name:"lookup",description:"Use when Root needs one exact current external fact; locate it in the assigned authoritative source and return the citation.",instruction:"Locate the exact requested authoritative external fact."},{name:"research",description:"Use when Root needs a sourced current synthesis; combine the assigned authoritative sources with citations and return the evidence and uncertainty.",instruction:"Synthesize the assigned current sources with citations."}],capability:"current-research",authority:"Research only the delegated Assignment current sources without repository mutation; Git/VCS, lifecycle, and decisions remain Root-only.",evidence:"Return sourced facts, dates, and explicit uncertainty.",completion:"Resolve the assigned external fact or report the exact evidence gap.",permissions:{network:!0,write:!1}},{role:"Worker",tasks:[{name:"mechanical",description:"Use when Root has decided deterministic edits; apply only those edits, verify the result, and return changed paths and evidence.",instruction:"Apply only deterministic, already-decided edits."},{name:"implementation",description:"Use when Root has decided a bounded behavior seam; implement and verify that seam, then return changed paths and evidence.",instruction:"Implement and verify the bounded behavior seam."},{name:"integration",description:"Use when Root has decided seams that must be combined; integrate and verify them together, then return the result and residual risk.",instruction:"Integrate the decided seams and verify them together."},{name:"operations",description:"Use after Root approves an exact ref or SHA; observe required CI and release state to terminal evidence and return it, never treating pending as success.",instruction:"After Root approves an exact ref or SHA, observe required CI and release state through terminal evidence; pending or running state is never success."}],capability:"bounded-write",authority:"Change only the delegated Assignment seam; Intent lifecycle, Git/VCS, 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:!1,write:!0}},{role:"Reviewer",tasks:[{name:"plan",description:"Use when Root needs a complete plan adversarially checked; review it to a fixed point and return findings, proof, and residual risk.",instruction:"Review the complete plan to a fixed point."},{name:"code",description:"Use when Root needs implemented code adversarially checked; review and repair it to a fixed point, returning findings, proof, and residual risk.",instruction:"Review and repair the implemented code to a fixed point."},{name:"artifact",description:"Use when Root needs a produced artifact inspected; review and repair it to a fixed point, returning findings, proof, and residual risk.",instruction:"Review and repair the produced artifact to a fixed point."}],capability:"bounded-review",authority:"Inspect and repair only reviewer-owned defects within the delegated Assignment; Intent lifecycle, Git/VCS, and material choices remain Root-only.",evidence:"Return findings, repaired paths, verification, and residual risk.",completion:"Reach a fixed point or report each reproducible blocker as a compact structured outcome.",permissions:{network:!1,write:!0}}];cr(nn);var bT=new Map(nn.map((e)=>[e.role,e])),RN=new Set(nn.map((e)=>e.role)),bh=nn.flatMap((e)=>e.tasks.map((t)=>`${e.role}:${t.name}`)),vN=new Set(bh),_T=bh.map((e)=>e.replace(":",".")),wT=new Set(_T);function ET(e){return typeof e==="string"&&RN.has(e)}function CN(e){if(typeof e!=="object"||e===null||!("role"in e)||!("task"in e))return!1;let{role:t,task:r}=e;if(!ET(t)||typeof r!=="string")return!1;return bT.get(t)?.tasks.some((n)=>n.name===r)===!0}function wu(e,t){return typeof t==="string"&&bT.get(e)?.tasks.some((r)=>r.name===t)===!0}function OT(e){return typeof e==="string"&&vN.has(e)}var _h=At(ET),PN=At((e)=>wu("Explorer",e)),FN=At((e)=>wu("Librarian",e)),NN=At((e)=>wu("Worker",e)),MN=At((e)=>wu("Reviewer",e)),wa=At(CN),No=Object.freeze(bh.filter((e)=>OT(e))),TT=At(OT),LN=Object.freeze(_T.filter((e)=>wT.has(e))),DN=At((e)=>typeof e==="string"&&wT.has(e));var kT=z({profile:_u,service_tier:G(xT)}),qN=q("git_vcs","computer_use"),UN=Object.freeze({requiresDelegation:!0,trivialWorkRequiresDelegation:!0,directExecutionExceptions:Object.freeze(["git_vcs","computer_use"]),requestUserInputGates:Object.freeze(["plan_approval","installation_profile_approval","remote_origin_server_vcs_mutation","public_publication_or_release","ambiguity_or_missing_material_input"]),surgicalMutationRule:ST,specialistOutcomes:Object.freeze(["completed","blocked","needs_root_input","failed"]),materialDecisionsRemainRootOwned:!0,lifecycleRemainsRootOwned:!0,integrationAndCompletionRemainRootOwned:!0,codeReviewRequiredForImplementation:!0,codeReviewRequiredBeforeVcs:!0,externalVerificationMustBeTerminal:!0,postVcsFlow:"discover_topology_observe_repair_repeat"});function et(e,t){return new nt("invalid_canonical_value",`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function wh(e,t,r){if(e===null)return"null";switch(typeof e){case"string":{let n=JSON.stringify(e);if(n===void 0)throw et(t,"invalid string");return n}case"boolean":return e?"true":"false";case"number":{if(!Number.isFinite(e))throw et(t,"non-finite number");let n=JSON.stringify(e);if(n===void 0)throw et(t,"invalid number");return n}case"undefined":throw et(t,"undefined is not JSON");case"bigint":throw et(t,"bigint is not JSON");case"function":throw et(t,"function is not JSON");case"symbol":throw et(t,"symbol is not JSON");case"object":break}if(r.has(e))throw et(t,"cyclic value");r.add(e);try{if(Array.isArray(e)){for(let a of Object.getOwnPropertySymbols(e))throw et(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 et(`${t}[${a}]`,"sparse or accessor array item");s.push(wh(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 et(t,`non-index array property ${a}`);let l=Object.getOwnPropertyDescriptor(i,a);if(!l||!l.enumerable||!("value"in l))throw et(`${t}[${c}]`,"non-enumerable or accessor array item")}return`[${s.join(",")}]`}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw et(t,"only plain objects are supported");for(let i of Object.getOwnPropertySymbols(e))throw et(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 et(`${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 et(`${t}.${i}`,"accessor property");o.push(`${JSON.stringify(i)}:${wh(s.value,`${t}.${i}`,r)}`)}return`{${o.join(",")}}`}finally{r.delete(e)}}function Eh(e){return wh(e,"$",new Set)}var AT=q("blocked","completed","failed","partial"),IT=yt(q("high","max","xhigh"),en);function RT(e){try{return Eh(e)!==void 0}catch{return!1}}var vT=At((e)=>RT(e)),jN=At((e)=>$u(e)&&!Array.isArray(e)&&RT(e)),$N=z({blocked:de,changed_files:V(le),confidence:xu,context_owner:yt(le,en),material_findings:V(le),needs_more_context:de,needs_root_decision:de,needs_verification:de,relevant_files:V(le),remaining_risk:V(le),reuse_recommended:de,status:AT,suggested_followup:yt(le,en),suggested_luna_effort:IT,suggested_specialist:yt(_h,en),verification:V(le),verification_passed:de}),Oh="holycodex-specialist-outcome-2",xt=le.pipe(aT(1)),Ea={protocol_version:q(Oh),route:wa,evidence:V(xt)},BN=z(Ea),KN=z({...Ea,status:q("completed"),summary:xt}),WN=z({...Ea,status:q("blocked"),reason:xt,needs_root_decision:de}),zN=z({...Ea,status:q("partial"),summary:xt,completed:V(xt),remaining:V(xt),needs_root_decision:de}),VN=z({...Ea,status:q("failed"),error:xt}),JN=yt(KN,WN,zN,VN),Eu={protocol_version:q(Oh),capability:yh,route:yt(wa,en),evidence:V(xt),data:vT},GN=z({...Eu,status:q("completed"),summary:xt}),YN=z({...Eu,status:q("blocked"),reason:xt,needs_root_decision:de}),ZN=z({...Eu,status:q("partial"),summary:xt,completed:V(xt),remaining:V(xt),needs_root_decision:de}),QN=z({...Eu,status:q("failed"),error:xt}),XN=yt(GN,YN,ZN,QN);var CT=V(le),PT=le.pipe(_r(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),FT=q(ju),eM=z({code:sr,message:le,details:jN}),NT=z({schema_version:FT,ok:q(!0),command:PT,data:vT,warnings:CT}),MT=z({schema_version:FT,ok:q(!1),command:PT,error:eM,warnings:CT}),tM=yt(NT,MT);var DT="gpt-5.6-luna";function rM(e,t,r){return{key:`${e}:${t}`,role:e,task:t,model:DT,effort:r}}var nM=new Set(No),LT={low:0,medium:1,high:2,xhigh:3,max:4},kh=[{profile:"low",rationale:"The low profile keeps bounded specialist work economical.",efforts:{"Explorer:lookup":"medium","Explorer:trace":"high","Librarian:lookup":"medium","Librarian:research":"high","Worker:mechanical":"high","Worker:implementation":"high","Worker:integration":"max","Worker:operations":"high","Reviewer:plan":"high","Reviewer:code":"max","Reviewer:artifact":"high"}},{profile:"default",rationale:"The default profile is the recommended balanced route.",efforts:{"Explorer:lookup":"medium","Explorer:trace":"xhigh","Librarian:lookup":"medium","Librarian:research":"xhigh","Worker:mechanical":"high","Worker:implementation":"xhigh","Worker:integration":"max","Worker:operations":"high","Reviewer:plan":"xhigh","Reviewer:code":"max","Reviewer:artifact":"xhigh"}},{profile:"high",rationale:"The high profile maximizes specialist reasoning where specified.",efforts:{"Explorer:lookup":"medium","Explorer:trace":"max","Librarian:lookup":"medium","Librarian:research":"max","Worker:mechanical":"xhigh","Worker:implementation":"max","Worker:integration":"max","Worker:operations":"xhigh","Reviewer:plan":"max","Reviewer:code":"max","Reviewer:artifact":"max"}}];cr(kh);var oM=new Map(kh.map((e)=>[e.profile,e]));function iM(e){let t=oM.get(e);if(t===void 0)throw new nt("catalog_invalid","A profile has no route effort policy.",{profile:e});return nn.flatMap((r)=>r.tasks.map((n)=>{let o=`${r.role}:${n.name}`,i=t.efforts[o];if(i===void 0)throw new nt("catalog_invalid","A route effort policy is incomplete.",{profile:e,route:o});return rM(r.role,n.name,i)}))}function Th(e){return{name:e.name,root:{model:"gpt-6-astra",effort:e.effort},specialistModel:"gpt-5.6-luna",defaultServiceTier:"standard",routes:iM(e.name)}}var Ah=[Th({name:"low",effort:"low"}),Th({name:"default",effort:"medium"}),Th({name:"high",effort:"high"})];function sM(e){let t=["low","default","high"];if(e.length!==t.length)throw new nt("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 nt("catalog_invalid","The profile catalog order is invalid.",{index:r});let i=o==="low"?"low":o==="default"?"medium":"high";if(n.root.model!=="gpt-6-astra"||n.root.effort!==i||n.specialistModel!=="gpt-5.6-luna")throw new nt("catalog_invalid","A profile has an invalid model route.",{profile:n.name});if(n.routes.length!==No.length)throw new nt("catalog_invalid","A profile is incomplete.",{profile:n.name});let s=new Set;for(let a of n.routes){if(s.has(a.key)||!nM.has(a.key)||a.model!=="gpt-5.6-luna"||`${a.role}:${a.task}`!==a.key)throw new nt("catalog_invalid","A profile contains an invalid route.",{profile:n.name});s.add(a.key)}if(s.size!==No.length)throw new nt("catalog_invalid","A profile is missing a specialist route.",{profile:n.name})}for(let r=0;r<No.length;r+=1){let n=-1;for(let o of e){let i=o.routes[r];if(!i||LT[i.effort]<n)throw new nt("catalog_invalid","Profile route effort is not monotonic.",{route:No[r]??"unknown"});n=LT[i.effort]}}}sM(Ah);cr(Ah);var qT=Ah,aM=new Map,cM=new Map;for(let e of qT){aM.set(e.name,e);let t=new Map;for(let r of e.routes)t.set(r.key,r);cM.set(e.name,t)}import{execFile as lM}from"child_process";import{createHash as uM}from"crypto";import{lstat as on,mkdir as Li,open as Pu,readFile as Ch,readdir as Ta,realpath as pM,rename as fM,rm as Aa,stat as dM}from"fs/promises";import{basename as Ih,dirname as jn,isAbsolute as mM,join as M,relative as hM,resolve as vu}from"path";import{promisify as gM}from"util";var Fu="holycodex-intent-1",Ph="holycodex-plan-1",Fh="holycodex-assignment-1",$n="toon-4",K=le.pipe(br((e)=>e.trim().length>0)),ar=le.pipe(_r(/^[a-z0-9][a-z0-9-]{0,95}$/u)),Nh=le.pipe(_r(/^[a-f0-9]{64}$/u)),Ia=Su.pipe(lT(1)),Or=le.pipe(br((e)=>!Number.isNaN(Date.parse(e)))),Te=V(K),yM=z({pid:Su.pipe(cT(0)),token:K}),xM=120000,SM=4294967295,Mh=z({role:q("Explorer","Librarian","Worker","Reviewer"),task:K}).pipe(br((e)=>nn.some((t)=>t.role===e.role&&t.tasks.some((r)=>r.name===e.task)))),Do=z({kind:q("changed_path","check","repository_fact","ci","behavior","uncertainty"),value:K,result:G(q("passed","failed","observed","unknown"))}),Lh=z({root:K,git_common_dir:K,initial_head:K,expected_head:K,expected_changes:Te,expected_status_digest:Nh,updated_at:Or}),qi=q("scoping","ready","executing","verifying","reviewing","blocked","needs_root_input","complete","abandoned"),bM=q("scoping","ready","executing","verifying","reviewing"),UT=z({required:de,status:q("not_required","missing","passed","failed","accepted","rejected"),evidence:V(Do)}),Ra=z({schema_version:q(Fu),toon_compatibility:q($n),id:ar,slug:ar,title:K,goal:K,acceptance_criteria:Te,state:qi,revision:Ia,plan_required:de,active_plan_revision:G(Ia),active_plan_digest:G(Nh),blockers:Te,resume_state:G(bM),verification:UT,review:UT,acceptance_met:de,root_readiness:de,evidence:V(Do),baseline:Lh,created_at:Or,updated_at:Or}),Ru=z({schema_version:q(Ph),toon_compatibility:q($n),intent_id:ar,revision:Ia,predecessor_digest:G(Nh),approach:K,scope:Te,exclusions:Te,assignments:Te,dependencies:Te,architecture:Te,risks:Te,assumptions:Te,open_questions:Te,verification:Te,recovery:Te,updated_at:Or}),Dh=q("completed","blocked","needs_root_input","failed"),zT=q("pending","executing","completed","blocked","needs_root_input","failed"),qh=z({id:ar,outcome:Dh,started_at:Or,finished_at:Or,summary:K,evidence:V(Do),blocker:G(K),remaining_risk:Te}),ka=z({schema_version:q(Fh),toon_compatibility:q($n),intent_id:ar,id:ar,objective:K,owner:Mh,scope:Te,constraints:Te,exclusions:Te,dependencies:Te,acceptance_criteria:Te,status:zT,revision:Ia,invocations:V(qh),evidence:V(Do),blocker:G(K),remaining_risk:Te,created_at:Or,updated_at:Or}),_M=z({schema_version:q("holycodex-intent-0"),id:ar,slug:ar,title:K,goal:K,acceptance_criteria:Te,state:qi,revision:Ia,baseline:Lh,created_at:Or,updated_at:Or});class j extends Error{code;details;constructor(e,t,r={}){super(t);this.name="IntentStoreError",this.code=e,this.details=r}}var Nu=z({title:K,goal:K,acceptanceCriteria:V(K).pipe(bu(1)),planRequired:G(de),verificationRequired:G(de),reviewRequired:G(de)}),Mu=z({approach:K,scope:G(V(K)),exclusions:G(V(K)),assignments:G(V(K)),dependencies:G(V(K)),architecture:G(V(K)),risks:G(V(K)),assumptions:G(V(K)),openQuestions:G(V(K)),verification:G(V(K)),recovery:G(V(K))}),Lu=z({id:G(K),objective:K,owner:Mh,scope:V(K).pipe(bu(1)),constraints:G(V(K)),exclusions:G(V(K)),dependencies:G(V(K)),acceptanceCriteria:V(K).pipe(bu(1))}),Du=z({invocationId:G(K),outcome:Dh,startedAt:G(K),summary:K,evidence:G(V(Do)),blocker:G(K),remainingRisk:G(V(K))}),qu=z({evidence:G(V(Do)),verification:G(q("passed","failed")),review:G(q("accepted","rejected")),acceptanceMet:G(de),rootReadiness:G(de),clearBlockers:G(de)}),Uh=gM(lM);class Uu{repositoryRoot;stateRoot;#e;#i;constructor(e,t={}){this.repositoryRoot=vu(e),this.stateRoot=M(this.repositoryRoot,".holycodex"),this.#e=t.now??(()=>new Date),this.#i=t.repositorySnapshot??(()=>VT(this.repositoryRoot))}async recover(){if(await this.#s(),!await Iu(this.stateRoot))return[];return await Au(M(this.stateRoot,".intent-store"),async()=>this.#c())}async#c(){let e;try{e=await Ta(this.stateRoot,{recursive:!0})}catch(r){if(me(r,"ENOENT"))return[];throw Ce(r)}let t=[];for(let r of e){let n=Ih(r);if(!n.startsWith(".holycodex-write-")||!n.endsWith(".tmp"))continue;let o=M(this.stateRoot,r),i=jn(o);if(i!==this.stateRoot&&await Iu(M(i,".intent-store")))continue;await Di(o),await Aa(o,{force:!0}),t.push(r.replaceAll("\\","/"))}return t.sort()}async#s(){try{let e=await on(this.stateRoot);if(e.isSymbolicLink()||!e.isDirectory())throw new j("schema_invalid","Repository-local work state must be a real directory.",{path:this.stateRoot})}catch(e){if(me(e,"ENOENT"))return;throw Ce(e)}}async createIntent(e){let t=He(Nu,e);if(!t.title.trim()||!t.goal.trim()||t.acceptanceCriteria.length===0)throw Lo("Intent title, goal, and acceptance criteria are required.");return await this.recover(),await Li(this.stateRoot,{recursive:!0}),await Au(M(this.stateRoot,".intent-store"),async()=>{let r=await this.#i(),n=OM(t.title),o=Hn([r.root,t.title.trim(),t.goal.trim()].join("\x00")).slice(0,10),i=`${n}-${o}`,s=1;while(await Iu(M(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=He(Ra,{schema_version:Fu,toon_compatibility:$n,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:Cu(t.verificationRequired??!0),review:Cu(t.reviewRequired??!0),acceptance_met:!1,root_readiness:!1,evidence:[],baseline:HT(r,c),created_at:c,updated_at:c}),u=M(this.stateRoot,i);return await Li(M(u,"assignments"),{recursive:!0}),await It(M(u,"intent.toon"),l),await vh(M(this.stateRoot,"current"),`${i}
38
- `),l})}async listIntents(){await this.#s(),await this.recover();let e;try{e=await Ta(this.stateRoot)}catch(r){if(me(r,"ENOENT"))return[];throw Ce(r)}let t=[];for(let r of e.sort()){let n=M(this.stateRoot,r);if(!await Rh(n))continue;let o=M(n,"intent.toon");if(await Oa(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(M(t,"intent.toon")))}async currentIntent(){await this.#s();try{let t=M(this.stateRoot,"current"),r=await on(t).catch((o)=>{if(me(o,"ENOENT"))return;throw Ce(o)});if(r?.isSymbolicLink()||r&&!r.isFile())throw new j("schema_invalid","The current Intent pointer must be a regular file.");let n=r?(await Ch(t,"utf8")).trim():"";if(n){let o=vu(this.stateRoot,n);if(!CM(this.stateRoot,o))throw new j("schema_invalid","The current Intent pointer escapes repository-local state.",{directory:n});if(!await Rh(o))throw new j("schema_invalid","The current Intent pointer does not select a work-state directory.",{directory:n});return await this.#t(M(o,"intent.toon"))}}catch(t){if(!me(t,"ENOENT"))throw Ce(t)}let e=(await this.listIntents()).filter((t)=>t.state!=="complete"&&t.state!=="abandoned");if(e.length===1)return e[0];throw new j(e.length?"current_ambiguous":"not_found",e.length?"Multiple active Intents require explicit selection.":"No current Intent exists.",{intent_ids:e.map((t)=>t.id)})}async selectCurrent(e){let t=await this.#r(e),r=await this.#t(M(t,"intent.toon"));return await Au(M(this.stateRoot,".intent-store"),async()=>vh(M(this.stateRoot,"current"),`${Ih(t)}
39
- `)),r}async transitionIntent(e,t,r,n){let o=He(qi,t),i=n===void 0?void 0:He(K,n);if(!Number.isSafeInteger(r)||r<1)throw Lo("Intent revision must be a positive integer.");let s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(M(s,"intent.toon"));if(Er(a.revision,r),o==="complete")throw new j("invalid_transition","Use the predicate-checked complete operation.");if(o==="abandoned")return await this.#a(s,a);return await this.#l(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(M(r,"intent.toon"));if(Er(n.revision,t),Mi(n),await this.#o(n),n.active_plan_revision!==void 0)await this.readPlan(e);let o=await this.listAssignments(e),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"))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=Mo(n,this.#e,{state:"complete"});return await It(M(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(M(r,"intent.toon"));return Er(n.revision,t),await this.#a(r,n)})}async recordIntentEvidence(e,t,r){let n=He(qu,r),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(M(o,"intent.toon"));if(Er(i.revision,t),Mi(i),n.verification!==void 0||n.review!==void 0)await this.#o(i);if(n.verification!==void 0&&i.state!=="verifying")throw new j("invalid_transition","Verification evidence is only accepted while the Intent is verifying.",{state:i.state});if(n.review!==void 0&&i.state!=="reviewing")throw new j("invalid_transition","Review evidence is only accepted while the Intent is reviewing.",{state:i.state});let s=[...i.evidence,...n.evidence??[]],a=n.verification===void 0?i.verification:{...i.verification,status:n.verification,evidence:[...i.verification.evidence,...n.evidence??[]]},c=n.review===void 0?i.review:{...i.review,status:n.review,evidence:[...i.review.evidence,...n.evidence??[]]},l=n.review==="rejected"&&i.state==="reviewing"?"executing":i.state,u=Mo(i,this.#e,{state:l,evidence:s,verification:a,review:c,...n.acceptanceMet===void 0?{}:{acceptance_met:n.acceptanceMet},...n.rootReadiness===void 0?{}:{root_readiness:n.rootReadiness},...n.clearBlockers?{blockers:[]}:{}});return await It(M(o,"intent.toon"),u),u})}async readPlan(e){let t=await this.#r(e),r=M(t,"plan.toon");if(!await Oa(r))return;let n=await ku(r,Ru),o=await this.#t(M(t,"intent.toon")),i=Hn(`${zi(n)}
40
- `);if(n.intent_id!==o.id||o.active_plan_revision!==n.revision||o.active_plan_digest!==i)throw new j("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=He(Mu,t);if(!o.approach.trim())throw Lo("Plan approach is required.");let i=await this.#r(e);return await this.#n(i,async()=>{let s=await this.#t(M(i,"intent.toon"));Er(s.revision,r),Mi(s),await this.#o(s);let a=M(i,"plan.toon"),c=await Oa(a)?await ku(a,Ru):void 0;if(c===void 0&&n!==void 0)Er(0,n);if(c!==void 0)Er(c.revision,n);let l,u;if(c){let g=`${zi(c)}
41
- `;u=Hn(g),l=await vM(i),await kM(l,g)}let f=He(Ru,{schema_version:Ph,toon_compatibility:$n,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 It(a,f);let d=Hn(`${zi(f)}
42
- `),h=Mo(s,this.#e,{active_plan_revision:f.revision,active_plan_digest:d,verification:Ou(s.verification),review:Ou(s.review),acceptance_met:!1,root_readiness:!1});return await It(M(i,"intent.toon"),h),{intent:h,plan:f,...l?{archived:Ih(l)}:{}}})}async createAssignment(e,t,r){let n=He(Lu,t);if(!n.objective.trim()||n.scope.length===0||n.acceptanceCriteria.length===0)throw Lo("Assignment objective, scope, and acceptance criteria are required.");let o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(M(o,"intent.toon"));Er(i.revision,r),Mi(i),await this.#o(i);let s=n.id??`assignment-${Hn([i.id,n.objective,...n.scope].join("\x00")).slice(0,10)}`;if(!/^[a-z0-9][a-z0-9-]{0,95}$/u.test(s))throw Lo("Assignment id is invalid.");let a=M(o,"assignments",`${s}.toon`);if(await Iu(a))throw new j("already_exists","Assignment already exists.",{id:s});let c=this.#e().toISOString(),l=He(ka,{schema_version:Fh,toon_compatibility:$n,intent_id:i.id,id:s,objective:n.objective.trim(),owner:n.owner,scope:[...n.scope],constraints:[...n.constraints??[]],exclusions:[...n.exclusions??[]],dependencies:[...n.dependencies??[]],acceptance_criteria:[...n.acceptanceCriteria],status:"pending",revision:1,invocations:[],evidence:[],remaining_risk:[],created_at:c,updated_at:c});return await Li(jn(a),{recursive:!0}),await It(a,l),l})}async readAssignment(e,t){let r=He(ar,t),n=await this.#r(e),o=await this.#t(M(n,"intent.toon")),i=M(n,"assignments");await KT(i,!0);let s=M(i,`${r}.toon`);if(!await Oa(s))throw new j("not_found","Assignment was not found.",{assignment_id:r});let a=await ku(s,ka);return WT(a,o.id,r,s),a}async listAssignments(e){let t=await this.#r(e),r=await this.#t(M(t,"intent.toon")),n=M(t,"assignments");if(!await KT(n,!0))return[];let o;try{o=await Ta(n)}catch(s){if(me(s,"ENOENT"))return[];throw Ce(s)}return await Promise.all(o.filter((s)=>s.endsWith(".toon")).sort().map(async(s)=>{let a=M(n,s),c=await ku(a,ka),l=s.slice(0,-5);return WT(c,r.id,l,a),c}))}async startAssignment(e,t,r){let n=He(ar,t),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(M(o,"intent.toon"));Mi(i),await this.#o(i);let s=await this.readAssignment(e,n);if(Er(s.revision,r),s.status==="completed")throw new j("invalid_transition","A completed Assignment cannot be restarted.");let a=$T(s,this.#e,{status:"executing",blocker:void 0});return await It(M(o,"assignments",`${n}.toon`),a),a})}async recordAssignmentResult(e,t,r,n){let o=He(Du,n),i=He(ar,t),s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(M(s,"intent.toon"));Mi(a);let c=await this.readAssignment(e,i);if(Er(c.revision,r),!["executing","blocked","needs_root_input","failed"].includes(c.status))throw new j("invalid_transition",`Assignment result is invalid from ${c.status}.`);if((o.outcome==="blocked"||o.outcome==="needs_root_input")&&!o.blocker?.trim())throw Lo("Blocked results require a local blocker.");let l=await this.#i(),u=[...o.evidence??[]],f=new Set(u.filter((R)=>R.kind==="changed_path").map((R)=>R.value)),d=[...f].filter((R)=>!c.scope.some((v)=>TM(R,v)));if(d.length)throw new j("repository_drift","Assignment evidence declares paths outside its bounded scope.",{assignment_id:c.id,out_of_scope_paths:d.sort()});let h=new Set([...a.baseline.expected_changes,...f]),g=l.changedPaths.filter((R)=>!h.has(R)),P=l.root!==a.baseline.root||l.gitCommonDir!==a.baseline.git_common_dir,x=jT(l.statusDigest)!==a.baseline.expected_status_digest,E=[...f].some((R)=>l.changedPaths.includes(R));if(P||g.length||x&&!E||l.head!==a.baseline.expected_head&&!E)throw new j("repository_drift","Repository state changed outside the recorded Assignment result.",{expected_head:a.baseline.expected_head,actual_head:l.head,unexpected_paths:g});let W=this.#e().toISOString(),F=o.invocationId??`invocation-${String(c.invocations.length+1).padStart(3,"0")}`;if(c.invocations.some((R)=>R.id===F))throw new j("already_exists","Assignment invocation already exists.",{invocation_id:F});let D=He(qh,{id:F,outcome:o.outcome,started_at:o.startedAt??W,finished_at:W,summary:o.summary,evidence:u,...o.blocker?{blocker:o.blocker}:{},remaining_risk:[...o.remainingRisk??[]]}),T=$T(c,this.#e,{status:o.outcome,invocations:[...c.invocations,D],evidence:[...c.evidence,...u],blocker:o.blocker,remaining_risk:[...o.remainingRisk??[]]});await It(M(s,"assignments",`${i}.toon`),T);let A=Mo(a,this.#e,{baseline:HT(l,W,a.baseline.initial_head),verification:Ou(a.verification),review:Ou(a.review),acceptance_met:!1,root_readiness:!1});return await It(M(s,"intent.toon"),A),{assignment:T,intent:A}})}async#l(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 Tu(o,r);if(!n?.trim())throw Lo("A blocker or required input is required.");let s=Mo(t,this.#e,{state:r,blockers:[n.trim()],resume_state:o});return await It(M(e,"intent.toon"),s),s}if(o==="blocked"||o==="needs_root_input"){if(r!==t.resume_state||t.blockers.length)throw Tu(o,r)}else if(!{scoping:["ready"],ready:["executing"],executing:["verifying"],verifying:["reviewing","executing"],reviewing:["executing"]}[o]?.includes(r))throw Tu(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 j("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 j("invalid_transition","Verification must pass before review.");if(r==="reviewing")await this.#o(t);let i=Mo(t,this.#e,{state:r,resume_state:void 0});return await It(M(e,"intent.toon"),i),i}async#n(e,t){return await Au(M(e,".intent-store"),t)}async#a(e,t){if(t.state==="complete"||t.state==="abandoned")throw Tu(t.state,"abandoned");let r=Mo(t,this.#e,{state:"abandoned",blockers:[]});return await It(M(e,"intent.toon"),r),r}async#o(e){let t=await this.#i(),r=[...e.baseline.expected_changes].sort(),n=[...t.changedPaths].sort();if(t.root!==e.baseline.root||t.gitCommonDir!==e.baseline.git_common_dir||t.head!==e.baseline.expected_head||jT(t.statusDigest)!==e.baseline.expected_status_digest||r.join("\x00")!==n.join("\x00"))throw new j("repository_drift","Repository baseline no longer matches recorded assumptions.",{expected_head:e.baseline.expected_head,actual_head:t.head,expected_changes:r,actual_changes:n})}async#r(e){await this.#s();let t;try{t=await Ta(this.stateRoot)}catch(n){if(me(n,"ENOENT"))throw new j("not_found","Intent was not found.",{reference:e});throw Ce(n)}let r=[];for(let n of t.sort()){let o=M(this.stateRoot,n);if(!await Rh(o))continue;let i=M(o,"intent.toon");if(!await Oa(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 j("current_ambiguous","Intent reference is ambiguous.",{reference:e});throw new j("not_found","Intent was not found.",{reference:e})}async#t(e){let t=await GT(e),r=tn(Ra,t);if(pt(r))return r.right;let n=tn(_M,t);if(he(n))throw new j("schema_invalid","Persisted Intent failed schema validation.",{path:e,error:String(r.left)});let o=EM(n.right);return await It(e,o),o}}async function VT(e){let t=await pM(e),r=async(...a)=>{try{return(await Uh("git",["-C",t,...a],{encoding:"utf8"})).stdout.trim()}catch(c){throw new j("io_failure","Repository identity requires an accessible Git worktree.",{message:c instanceof Error?c.message:String(c)})}},n=await r("rev-parse","--git-common-dir"),o=await wM(t,"rev-parse","--verify","HEAD")??"unborn",i=await r("status","--porcelain=v1","--untracked-files=all"),s=i.split(`
43
- `).filter(Boolean).map((a)=>a.slice(3).split(" -> ").at(-1)).sort();return{root:t,gitCommonDir:vu(t,n),head:o,changedPaths:s,statusDigest:Hn(i)}}async function wM(e,...t){try{return(await Uh("git",["-C",e,...t],{encoding:"utf8"})).stdout.trim()}catch{return}}function EM(e){return He(Ra,{...e,schema_version:Fu,toon_compatibility:$n,plan_required:!1,blockers:[],verification:Cu(!0),review:Cu(!0),acceptance_met:!1,root_readiness:!1,evidence:[]})}function Cu(e){return{required:e,status:e?"missing":"not_required",evidence:[]}}function Ou(e){return{...e,status:e.required?"missing":"not_required"}}function HT(e,t,r=e.head){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:Hn(e.statusDigest),updated_at:t}}function jT(e){return/^[a-f0-9]{64}$/u.test(e)?e:Hn(e)}function Mo(e,t,r){return He(Ra,JT({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function $T(e,t,r){return He(ka,JT({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function JT(e){let t={...e};for(let[r,n]of Object.entries(t))if(n===void 0)delete t[r];return t}function OM(e){return e.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-|-$/gu,"").slice(0,48).replace(/-$/u,"")||"intent"}function TM(e,t){let r=BT(e),n=BT(t).replace(/\/+$/u,"");if(!r||!n||r.startsWith("/")||n.startsWith("/")||/^[a-z]:\//u.test(r)||/^[a-z]:\//u.test(n)||r.split("/").includes("..")||n.split("/").includes(".."))return!1;return n==="."||r===n||r.startsWith(`${n}/`)}function BT(e){return e.trim().replaceAll("\\","/").replace(/^\.\//u,"")}function Hn(e){return uM("sha256").update(e).digest("hex")}function Er(e,t){if(t===void 0||e!==t)throw new j("stale_write","Persisted revision changed before mutation.",{expected_revision:t,actual_revision:e})}function Lo(e){return new j("invalid_input",e)}function Mi(e){if(e.state==="complete"||e.state==="abandoned")throw new j("invalid_transition","Terminal Intents cannot be mutated.",{state:e.state})}function Tu(e,t){return new j("invalid_transition",`Intent cannot transition from ${e} to ${t}.`,{source:e,target:t})}function He(e,t){let r=tn(e,t);if(he(r))throw new j("schema_invalid","Value failed Effect Schema validation.",{error:String(r.left)});return r.right}async function GT(e){let t;try{let r=await on(e);if(r.isSymbolicLink()||!r.isFile())throw new j("schema_invalid","Persistent work state must be a regular file.",{path:e});t=await Ch(e,"utf8")}catch(r){if(me(r,"ENOENT"))throw new j("not_found","Persistent work state was not found.",{path:e});throw Ce(r)}try{return yg(t,{strict:!0})}catch(r){throw new j("malformed_toon","Persistent work state is malformed TOON.",{path:e,message:r instanceof Error?r.message:String(r)})}}async function ku(e,t){return He(t,await GT(e))}async function It(e,t){await vh(e,`${zi(t)}
44
- `)}async function vh(e,t){await Di(e),await Li(jn(e),{recursive:!0}),await Di(e);let r=M(jn(e),`.holycodex-write-${process.pid}-${crypto.randomUUID()}.tmp`);try{let n=await Pu(r,"wx",384);try{await n.writeFile(t,"utf8"),await n.sync()}finally{await n.close()}await fM(r,e),await YT(jn(e))}catch(n){throw await Aa(r,{force:!0}),Ce(n)}}async function kM(e,t){await Di(e);try{let r=await Pu(e,"wx",256);try{await r.writeFile(t,"utf8"),await r.sync()}finally{await r.close()}await YT(jn(e))}catch(r){if(me(r,"EEXIST"))throw new j("archive_conflict","Archived plans are immutable.",{path:e});throw Ce(r)}}async function YT(e){if(process.platform==="win32")return;try{let t=await Pu(e,"r");try{await t.sync()}finally{await t.close()}}catch(t){if(me(t,"EINVAL")||me(t,"ENOSYS")||me(t,"ENOTSUP")||me(t,"EOPNOTSUPP")||me(t,"EISDIR"))return;throw t}}async function Au(e,t){let r=jn(e);await Di(e),await Li(r,{recursive:!0});let n=!1;for(let a=0;a<200;a+=1)try{await Li(e),n=!0;break}catch(c){if(!me(c,"EEXIST"))throw Ce(c);try{let l=await on(e);if(l.isSymbolicLink()||!l.isDirectory())throw new j("schema_invalid","The work-state lock must be a real directory.",{path:e});let u=await ZT(e);if(u.kind==="owned"&&!await AM(u.owner.pid)){await Aa(e,{recursive:!0,force:!0});continue}if(u.kind==="missing"&&Date.now()-l.mtimeMs>xM){await Aa(e,{recursive:!0,force:!0});continue}}catch(l){if(!me(l,"ENOENT"))throw Ce(l)}await new Promise((l)=>setTimeout(l,Math.min(5+a,50)))}if(!n)throw new j("stale_write","Another mutation is still in progress.",{lock:e});let o=M(e,".owner"),i=crypto.randomUUID(),s;try{await Di(o),s=await Pu(o,"wx",384),await s.writeFile(`${JSON.stringify({pid:process.pid,token:i})}
45
- `,"utf8"),await s.sync()}catch(a){if(s!==void 0)try{await s.close()}catch{}if(me(a,"EEXIST"))throw new j("stale_write","Another mutation is still in progress.",{lock:e});throw Ce(a)}if(s===void 0)throw Ce(Error("The work-state lock owner was not opened."));try{return await t()}finally{try{await s.close()}finally{await RM(e,i)}}}async function ZT(e){let t=M(e,".owner");try{let r=await on(t);if(r.isSymbolicLink()||!r.isFile())return{kind:"unknown"};let n=await Ch(t,"utf8"),o;try{o=JSON.parse(n)}catch{return{kind:"unknown"}}let i=tn(yM,o);return pt(i)?{kind:"owned",owner:i.right}:{kind:"unknown"}}catch(r){if(me(r,"ENOENT"))return{kind:"missing"};throw Ce(r)}}async function AM(e){if(e===process.pid)return!0;if(process.platform==="win32")return await IM(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 me(r,"EPERM")}}async function IM(e){if(!Number.isSafeInteger(e)||e>SM)return!1;try{let{stdout:t}=await Uh("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 RM(e,t){let r=await ZT(e);if(r.kind!=="owned"||r.owner.token!==t)return;await Aa(e,{recursive:!0,force:!0})}async function vM(e){let t=(await Ta(e)).map((r)=>/^plan\.old-(\d{3})\.toon$/u.exec(r)?.[1]).filter((r)=>r!==void 0).map(Number);return M(e,`plan.old-${String((t.length?Math.max(...t):0)+1).padStart(3,"0")}.toon`)}async function Iu(e){try{return await dM(e),!0}catch(t){if(me(t,"ENOENT"))return!1;throw Ce(t)}}async function Oa(e){try{let t=await on(e);return t.isFile()&&!t.isSymbolicLink()}catch(t){if(me(t,"ENOENT")||me(t,"ENOTDIR"))return!1;throw Ce(t)}}async function KT(e,t){try{let r=await on(e);if(r.isSymbolicLink()||!r.isDirectory())throw new j("schema_invalid","Persistent work-state directories must be real directories.",{path:e});return!0}catch(r){if(me(r,"ENOENT")&&t)return!1;throw Ce(r)}}async function Rh(e){try{let t=await on(e);return t.isDirectory()&&!t.isSymbolicLink()}catch(t){if(me(t,"ENOENT")||me(t,"ENOTDIR"))return!1;throw Ce(t)}}function WT(e,t,r,n){if(e.intent_id!==t||e.id!==r)throw new j("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 Di(e){let t=vu(e);while(!0){try{if((await on(t)).isSymbolicLink())throw new j("schema_invalid","Persistent work state must not contain symbolic links.",{path:t})}catch(n){if(!me(n,"ENOENT"))throw Ce(n)}let r=jn(t);if(r===t)break;t=r}}function me(e,t){return typeof e==="object"&&e!==null&&"code"in e&&e.code===t}function Ce(e){return e instanceof j?e:new j("io_failure","Persistent work-state I/O failed.",{message:e instanceof Error?e.message:String(e)})}function CM(e,t){let r=hM(e,t);return r===""||!r.startsWith(`..${PM()}`)&&r!==".."&&!mM(r)}function PM(){return process.platform==="win32"?"\\":"/"}var QT={intent:`Usage: holycodex-agent intent <command> [options]
36
+ schema (${n._tag}): ${n}`;return o},NE=(e)=>Un("Invalid Argument",e);var ME=(e)=>Un("Unsupported key schema",void 0,void 0,e),LE=(e)=>Un("Unsupported literal",`literal value: ${dr(e)}`),Am=(e)=>Un("Duplicate index signature",`${e} index signature`),DE=Un("Unsupported index signature parameter","An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"),qE=Un("Invalid element","A required element cannot follow an optional element. ts(1257)"),Im=(e)=>Un("Duplicate property signature transformation",`Duplicate key ${dr(e)}`);var vm=(e)=>Un("Duplicate property signature",`Duplicate key ${dr(e)}`);var HE=Symbol.for("effect/SchemaId/DateFromSelf"),jE=Symbol.for("effect/SchemaId/GreaterThan"),$E=Symbol.for("effect/SchemaId/GreaterThanOrEqualTo");var BE=Symbol.for("effect/SchemaId/Int");var KE=Symbol.for("effect/SchemaId/MinLength");var WE=Symbol.for("effect/SchemaId/MinItems");var VE=Symbol.for("effect/annotation/TypeConstructor"),Pm=Symbol.for("effect/annotation/Brand"),JE=Symbol.for("effect/annotation/SchemaId"),Fm=Symbol.for("effect/annotation/Message"),nu=Symbol.for("effect/annotation/MissingMessage"),ou=Symbol.for("effect/annotation/Identifier"),St=Symbol.for("effect/annotation/Title"),iu=Symbol.for("effect/annotation/AutoTitle"),Xr=Symbol.for("effect/annotation/Description"),Nm=Symbol.for("effect/annotation/Examples"),Mm=Symbol.for("effect/annotation/Default"),Lm=Symbol.for("effect/annotation/JSONSchema"),Dm=Symbol.for("effect/annotation/Arbitrary"),qm=Symbol.for("effect/annotation/Pretty"),Um=Symbol.for("effect/annotation/Equivalence"),GE=Symbol.for("effect/annotation/Documentation"),Hm=Symbol.for("effect/annotation/Concurrency"),jm=Symbol.for("effect/annotation/Batching"),$m=Symbol.for("effect/annotation/ParseIssueTitle"),Bm=Symbol.for("effect/annotation/ParseOptions"),Km=Symbol.for("effect/annotation/DecodingFallback"),Wm=Symbol.for("effect/annotation/Surrogate"),zm=Symbol.for("effect/annotation/StableFilter"),Qe=p(2,(e,t)=>Object.prototype.hasOwnProperty.call(e.annotations,t)?R(e.annotations[t]):w());var Vm=Qe(Pm);var YE=Qe(Fm),ZE=Qe(nu),Jm=Qe(St),Gm=Qe(iu),fa=Qe(ou),Ym=Qe(Xr);var QE=Qe(Hm),XE=Qe(jm),eO=Qe($m),tO=Qe(Bm),rO=Qe(Km),Zm=Qe(Wm),pF=Qe(zm),Qm=(e)=>iy(pF(e),(t)=>t===!0),Xm=Symbol.for("effect/annotation/JSONIdentifier"),fF=Qe(Xm),dF=(e)=>Jt(fF(e),()=>fa(e));class Fi{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(wr(this),()=>"<declaration schema>")}toJSON(){return{_tag:this._tag,typeParameters:this.typeParameters.map((e)=>e.toJSON()),annotations:_e(this.annotations)}}}var da=(e)=>(t)=>t._tag===e;class Lo{literal;annotations;_tag="Literal";constructor(e,t={}){this.literal=e,this.annotations=t}toString(){return ue(wr(this),()=>dr(this.literal))}toJSON(){return{_tag:this._tag,literal:un(this.literal)?String(this.literal):this.literal,annotations:_e(this.annotations)}}}var su=da("Literal"),nO=new Lo(null);class au{symbol;annotations;_tag="UniqueSymbol";constructor(e,t={}){this.symbol=e,this.annotations=t}toString(){return ue(wr(this),()=>dr(this.symbol))}toJSON(){return{_tag:this._tag,symbol:String(this.symbol),annotations:_e(this.annotations)}}}class oO{annotations;_tag="UndefinedKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var cu=new oO({[St]:"undefined"});class iO{annotations;_tag="VoidKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var mF=new iO({[St]:"void"});class sO{annotations;_tag="NeverKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var lu=new sO({[St]:"never"});class aO{annotations;_tag="UnknownKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var cO=new aO({[St]:"unknown"});class lO{annotations;_tag="AnyKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var uO=new lO({[St]:"any"});class pO{annotations;_tag="StringKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var fO=new pO({[St]:"string",[Xr]:"a string"}),uu=da("StringKeyword");class dO{annotations;_tag="NumberKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var mO=new dO({[St]:"number",[Xr]:"a number"});class hO{annotations;_tag="BooleanKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var gO=new hO({[St]:"boolean",[Xr]:"a boolean"});class yO{annotations;_tag="BigIntKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var hF=new yO({[St]:"bigint",[Xr]:"a bigint"});class xO{annotations;_tag="SymbolKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var gF=new xO({[St]:"symbol",[Xr]:"a symbol"}),SO=da("SymbolKeyword");class bO{annotations;_tag="ObjectKeyword";constructor(e={}){this.annotations=e}toString(){return sr(this)}toJSON(){return{_tag:this._tag,annotations:_e(this.annotations)}}}var yF=new bO({[St]:"object",[Xr]:"an object in the TypeScript meaning, i.e. the `object` type"});class Ni{type;annotations;constructor(e,t={}){this.type=e,this.annotations=t}toJSON(){return{type:this.type.toJSON(),annotations:_e(this.annotations)}}toString(){return String(this.type)}}class Hn extends Ni{isOptional;constructor(e,t,r={}){super(e,r);this.isOptional=t}toJSON(){return{type:this.type.toJSON(),isOptional:this.isOptional,annotations:_e(this.annotations)}}toString(){return String(this.type)+(this.isOptional?"?":"")}}var _O=(e)=>e.map((t)=>t.type);class ma{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(qE)}toString(){return ue(wr(this),()=>xF(this))}toJSON(){return{_tag:this._tag,elements:this.elements.map((e)=>e.toJSON()),rest:this.rest.map((e)=>e.toJSON()),isReadonly:this.isReadonly,annotations:_e(this.annotations)}}}var xF=(e)=>{let t=e.elements.map(String).join(", ");return ay(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 qe extends Hn{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:_e(this.annotations)}}}var wO=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return!0;case"Refinement":return wO(e.from)}return!1};class Mi{type;isReadonly;parameter;constructor(e,t,r){if(this.type=t,this.isReadonly=r,wO(e))this.parameter=e;else throw Error(DE)}toString(){return(this.isReadonly?"readonly ":"")+`[x: ${this.parameter}]: ${this.type}`}toJSON(){return{parameter:this.parameter.toJSON(),type:this.type.toJSON(),isReadonly:this.isReadonly}}}class Er{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(vm(s));n[s]=null}let o={string:!1,symbol:!1};for(let i=0;i<t.length;i++){let s=sh(t[i].parameter);if(uu(s)){if(o.string)throw Error(Am("string"));o.string=!0}else if(SO(s)){if(o.symbol)throw Error(Am("symbol"));o.symbol=!0}}this.propertySignatures=e,this.indexSignatures=t}toString(){return ue(wr(this),()=>SF(this))}toJSON(){return{_tag:this._tag,propertySignatures:this.propertySignatures.map((e)=>e.toJSON()),indexSignatures:this.indexSignatures.map((e)=>e.toJSON()),annotations:_e(this.annotations)}}}var zE=(e)=>e.map(String).join("; "),SF=(e)=>{if(e.propertySignatures.length>0){let t=e.propertySignatures.map(String).join("; ");if(e.indexSignatures.length>0)return`{ ${t}; ${zE(e.indexSignatures)} }`;else return`{ ${t} }`}else if(e.indexSignatures.length>0)return`{ ${zE(e.indexSignatures)} }`;else return"{}"};var bF=Lr(rc(br,(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})),_F={string:"StringKeyword",number:"NumberKeyword",boolean:"BooleanKeyword",bigint:"BigIntKeyword"},EO=(e)=>ds(e,(t)=>eh(t)?EO(t.types):[t]),wF=(e)=>{let t=bF(e),r=[],n={},o=[];for(let i of t)switch(i._tag){case"NeverKeyword":break;case"AnyKeyword":return[uO];case"UnknownKeyword":return[cO];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=_F[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 ct{types;annotations;static make=(e,t)=>pu(e)?new ct(e,t):e.length===1?e[0]:lu;static unify=(e,t)=>ct.make(wF(EO(e)),t);_tag="Union";constructor(e,t={}){this.types=e,this.annotations=t}toString(){return ue(wr(this),()=>this.types.map(String).join(" | "))}toJSON(){return{_tag:this._tag,types:this.types.map((e)=>e.toJSON()),annotations:_e(this.annotations)}}}var OO=(e,t)=>e.map(t),pu=(e)=>e.length>1,eh=da("Union"),Rm=M(Symbol.for("effect/Schema/AST/toJSONMemoMap"),()=>new WeakMap);class fu{f;annotations;_tag="Suspend";constructor(e,t={}){this.f=e,this.annotations=t,this.f=pa(e)}toString(){return wr(this).pipe(Jt(()=>Yt(ry(this.f)(),(e)=>wr(e))),ue(()=>"<suspended schema>"))}toJSON(){let e=this.f(),t=Rm.get(e);if(t)return t;return Rm.set(e,{_tag:this._tag}),t={_tag:this._tag,ast:e.toJSON(),annotations:_e(this.annotations)},Rm.set(e,t),t}}class ha{from;filter;annotations;_tag="Refinement";constructor(e,t,r={}){this.from=e,this.filter=t,this.annotations=r}toString(){return fa(this).pipe(ue(()=>Oe(IO(this),{onNone:()=>`{ ${this.from} | filter }`,onSome:(e)=>ga(this.from)?String(this.from)+" & "+e:e})))}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),annotations:_e(this.annotations)}}}var ga=da("Refinement"),du={};class th{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(wr(this),()=>`(${String(this.from)} <-> ${String(this.to)})`)}toJSON(){return{_tag:this._tag,from:this.from.toJSON(),to:this.to.toJSON(),annotations:_e(this.annotations)}}}class rh{from;to;decode;encode;constructor(e,t,r,n){this.from=e,this.to=t,this.decode=r,this.encode=n}}class nh{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(Im(o));t[o]=!0;let i=n.to;if(r[i])throw Error(Im(i));r[i]=!0}}}var ya=(e,t)=>{let r=Object.getOwnPropertyDescriptors(e),n={...e.annotations};delete n[ou];let o={...n,...t},i=Zm(e);if(pe(i))o[Wm]=ya(i.value,t);return r.annotations.value=o,Object.create(Object.getPrototypeOf(e),r)};var EF="[\\s\\S]*?",OF="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?",TO=(e,t)=>{switch(e._tag){case"Literal":return Ei(String(e.literal));case"StringKeyword":return EF;case"NumberKeyword":return OF;case"TemplateLiteral":return kO(e,t,!1);case"Union":return e.types.map((r)=>TO(r,t)).join("|")}},TF=(e,t,r,n)=>{if(eh(e)){if(r&&!n)return`(?:${t})`}else if(!r||!n)return t;return`(${t})`},kO=(e,t,r)=>{let n="";if(e.head!==""){let o=Ei(e.head);n+=t&&r?`(${o})`:o}for(let o of e.spans){let i=TO(o.type,t);if(n+=TF(o.type,i,t,r),o.literal!==""){let s=Ei(o.literal);n+=t&&r?`(${s})`:s}}return n},AO=(e)=>new RegExp(`^${kO(e,!1,!0)}$`);var oh=(e,t)=>{let r=[],n=[],o=(i)=>{switch(i._tag){case"NeverKeyword":break;case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":case"Refinement":n.push(new Mi(i,t,!0));break;case"Literal":if(Ke(i.literal)||kt(i.literal))r.push(new qe(i.literal,t,!1,!0));else throw Error(LE(i.literal));break;case"Enums":{for(let[s,a]of i.enums)r.push(new qe(a,t,!1,!0));break}case"UniqueSymbol":r.push(new qe(i.symbol,t,!1,!0));break;case"Union":i.types.forEach(o);break;default:throw Error(ME(i))}};return o(e),{propertySignatures:r,indexSignatures:n}};var ih=(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 kF=ih([Nm,Mm,Lm,Dm,qm,Um]),De=(e)=>{switch(e._tag){case"Declaration":{let t=jt(e.typeParameters,De);return t===e.typeParameters?e:new Fi(t,e.decodeUnknown,e.encodeUnknown,e.annotations)}case"TupleType":{let t=jt(e.elements,(o)=>{let i=De(o.type);return i===o.type?o:new Hn(i,o.isOptional)}),r=_O(e.rest),n=jt(r,De);return t===e.elements&&n===r?e:new ma(t,n.map((o)=>new Ni(o)),e.isReadonly,e.annotations)}case"TypeLiteral":{let t=jt(e.propertySignatures,(n)=>{let o=De(n.type);return o===n.type?n:new qe(n.name,o,n.isOptional,n.isReadonly)}),r=jt(e.indexSignatures,(n)=>{let o=De(n.type);return o===n.type?n:new Mi(n.parameter,o,n.isReadonly)});return t===e.propertySignatures&&r===e.indexSignatures?e:new Er(t,r,e.annotations)}case"Union":{let t=jt(e.types,De);return t===e.types?e:ct.make(t,e.annotations)}case"Suspend":return new fu(()=>De(e.f()),e.annotations);case"Refinement":{let t=De(e.from);return t===e.from?e:new ha(t,e.filter,e.annotations)}case"Transformation":{let t=kF(e);return De(t!==void 0?ya(e.to,t):e.to)}}return e};function jt(e,t){let r=!1,n=ao(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 Cm=(e)=>{switch(e._tag){case"Transformation":return e.from;case"Refinement":return Cm(e.from);case"Suspend":return Cm(e.f())}},_r=(e,t)=>{switch(e._tag){case"Declaration":{let r=jt(e.typeParameters,(n)=>_r(n,t));return r===e.typeParameters?e:new Fi(r,e.decodeUnknown,e.encodeUnknown)}case"TupleType":{let r=jt(e.elements,(i)=>{let s=_r(i.type,t);return s===i.type?i:new Hn(s,i.isOptional)}),n=_O(e.rest),o=jt(n,(i)=>_r(i,t));return r===e.elements&&o===n?e:new ma(r,o.map((i)=>new Ni(i)),e.isReadonly)}case"TypeLiteral":{let r=jt(e.propertySignatures,(o)=>{let i=_r(o.type,t);return i===o.type?o:new qe(o.name,i,o.isOptional,o.isReadonly)}),n=jt(e.indexSignatures,(o)=>{let i=_r(o.type,t);return i===o.type?o:new Mi(o.parameter,i,o.isReadonly)});return r===e.propertySignatures&&n===e.indexSignatures?e:new Er(r,n)}case"Union":{let r=jt(e.types,(n)=>_r(n,t));return r===e.types?e:ct.make(r)}case"Suspend":{let r=void 0,n=dF(e);if(pe(n)){let o=t?"Bound":"";r={[Xm]:`${n.value}Encoded${o}`}}return new fu(()=>_r(e.f(),t),r)}case"Refinement":{let r=_r(e.from,t);if(t){if(r===e.from)return e;if(Cm(e.from)===void 0&&Qm(e))return new ha(r,e.filter,e.annotations);return r}else return r}case"Transformation":return _r(e.from,t)}return e},mu=(e)=>_r(e,!1);var _e=(e)=>{let t={};for(let r of Object.getOwnPropertySymbols(e))t[String(r)]=e[r];return t},sh=(e)=>{switch(e._tag){case"StringKeyword":case"SymbolKeyword":case"TemplateLiteral":return e;case"Refinement":return sh(e.from)}};var sr=(e)=>ue(wr(e),()=>e._tag);function AF(e){return Oe(Vm(e),{onNone:()=>"",onSome:(t)=>t.map((r)=>` & Brand<${dr(r)}>`).join("")})}var IO=(e)=>Jm(e).pipe(Jt(()=>Ym(e)),Jt(()=>Gm(e)),Gt((t)=>t+AF(e))),wr=(e)=>Jt(fa(e),()=>IO(e));class Ue{path;actual;issue;_tag="Pointer";constructor(e,t,r){this.path=e,this.actual=t,this.issue=r}}class lh{actual;message;_tag="Unexpected";constructor(e,t){this.actual=e,this.message=t}}class Li{ast;message;_tag="Missing";actual=void 0;constructor(e,t){this.ast=e,this.message=t}}class we{ast;actual;issues;output;_tag="Composite";constructor(e,t,r,n){this.ast=e,this.actual=t,this.issues=r,this.output=n}}class gu{ast;actual;kind;issue;_tag="Refinement";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class yu{ast;actual;kind;issue;_tag="Transformation";constructor(e,t,r,n){this.ast=e,this.actual=t,this.kind=r,this.issue=n}}class $t{ast;actual;message;_tag="Type";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}class uh{ast;actual;message;_tag="Forbidden";constructor(e,t,r){this.ast=e,this.actual=t,this.message=r}}var RO=Symbol.for("effect/Schema/ParseErrorTypeId");class FO extends qb("ParseError"){[RO]=RO;get message(){return this.toString()}toString(){return ba.formatIssueSync(this.issue)}toJSON(){return{_id:"ParseError",message:this.toString()}}[Z](){return this.toJSON()}}var fh=(e)=>new FO({issue:e}),NO=K,MO=U;var _t=wp,en=p(2,(e,t)=>_t(e)?fs(e,{onLeft:U,onRight:t}):ir(e,t)),cr=p(2,(e,t)=>_t(e)?Yg(e,t):eu(e,t)),xu=p(2,(e,t)=>_t(e)?tc(e,t):vE(e,t));var LO=p(2,(e,t)=>_t(e)?fs(e,{onLeft:t,onRight:K}):IE(e,t)),DO=(e,t)=>{if(t===void 0||kt(t))return e;if(e===void 0)return t;return{...e,...t}},qO=(e,t,r)=>{let n=Xe(e,t);return(o,i)=>n(o,DO(r,i))},IF=(e,t,r)=>{let n=qO(e,t,r);return(o,i)=>Ep(n(o,i),fh)};var UO=(e,t)=>qO(e.ast,!0,t);var Su=(e,t)=>IF(De(e.ast),!0,t);var vF=M(Symbol.for("effect/ParseResult/decodeMemoMap"),()=>new WeakMap),RF=M(Symbol.for("effect/ParseResult/encodeMemoMap"),()=>new WeakMap),Xe=(e,t)=>{let r=t?vF:RF,n=r.get(e);if(n)return n;let o=CF(e,t),i=tO(e),s=pe(i)?(l,u)=>o(l,DO(u,i.value)):o,a=rO(e),c=t&&pe(a)?(l,u)=>Sa(LO(s(l,u),a.value),e,l,u):s;return r.set(e,c),c},ah=(e)=>yt(QE(e)),ch=(e)=>yt(XE(e)),CF=(e,t)=>{switch(e._tag){case"Refinement":if(t){let r=Xe(e.from,!0);return(n,o)=>{o=o??du;let i=o?.errors==="all",s=en(LO(r(n,o),(a)=>{let c=new gu(e,n,"From",a);if(i&&Qm(e)&&KO(a))return Oe(e.filter(n,o,e),{onNone:()=>U(c),onSome:(l)=>U(new we(e,n,[c,new gu(e,n,"Predicate",l)]))});return U(c)}),(a)=>Oe(e.filter(a,o,e),{onNone:()=>K(a),onSome:(c)=>U(new gu(e,n,"Predicate",c))}));return Sa(s,e,n,o)}}else{let r=Xe(De(e),!0),n=Xe(jO(e.from),!1);return(o,i)=>Sa(en(r(o,i),(s)=>n(s,i)),e,o,i)}case"Transformation":{let r=FF(e.transformation,t),n=t?Xe(e.from,!0):Xe(e.to,!1),o=t?Xe(e.to,!0):Xe(e.from,!1);return(i,s)=>Sa(en(xu(n(i,s),(a)=>new yu(e,i,t?"Encoded":"Type",a)),(a)=>en(xu(r(a,s??du,e,i),(c)=>new yu(e,i,"Transformation",c)),(c)=>xu(o(c,s),(l)=>new yu(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)=>Sa(r(n,o??du,e),e,n,o)}case"Literal":return bt(e,(r)=>r===e.literal);case"UniqueSymbol":return bt(e,(r)=>r===e.symbol);case"UndefinedKeyword":return bt(e,Ag);case"NeverKeyword":return bt(e,Ig);case"UnknownKeyword":case"AnyKeyword":case"VoidKeyword":return K;case"StringKeyword":return bt(e,Ke);case"NumberKeyword":return bt(e,kt);case"BooleanKeyword":return bt(e,Qn);case"BigIntKeyword":return bt(e,un);case"SymbolKeyword":return bt(e,Xn);case"ObjectKeyword":return bt(e,at);case"Enums":return bt(e,(r)=>e.enums.some(([n,o])=>o===r));case"TemplateLiteral":{if(e.spans.every((n)=>uu(n.type)))return bt(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=AO(e);return bt(e,(n)=>Ke(n)&&r.test(n))}case"TupleType":{let r=e.elements.map((l)=>Xe(l.type,t)),n=e.rest.map((l)=>Xe(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=ch(e);return(l,u)=>{if(!Rp(l))return U(new $t(e,l));let f=u?.errors==="all",d=[],g=0,h=[],P=l.length;for(let N=P;N<=i-1;N++){let q=new Ue(N,l,new Li(o[N-P]));if(f){d.push([g++,q]);continue}else return U(new we(e,l,q,h))}if(e.rest.length===0)for(let N=e.elements.length;N<=P-1;N++){let q=new Ue(N,l,new lh(l[N],`is unexpected, expected: ${s}`));if(f){d.push([g++,q]);continue}else return U(new we(e,l,q,h))}let x=0,E=void 0;for(;x<r.length;x++)if(P<x+1){if(e.elements[x].isOptional)continue}else{let N=r[x],q=N(l[x],u);if(_t(q)){if(ye(q)){let k=new Ue(x,l,q.left);if(f){d.push([g++,k]);continue}else return U(new we(e,l,k,ar(h)))}h.push([g++,q.right])}else{let k=g++,I=x;if(!E)E=[];E.push(({es:j,output:v})=>ir(Mo(q),(X)=>{if(ye(X)){let ee=new Ue(I,l,X.left);if(f)return j.push([k,ee]),Ct;else return U(new we(e,l,ee,ar(v)))}return v.push([k,X.right]),Ct}))}}if(ae(n)){let[N,...q]=n;for(;x<P-q.length;x++){let k=N(l[x],u);if(_t(k))if(ye(k)){let I=new Ue(x,l,k.left);if(f){d.push([g++,I]);continue}else return U(new we(e,l,I,ar(h)))}else h.push([g++,k.right]);else{let I=g++,j=x;if(!E)E=[];E.push(({es:v,output:X})=>ir(Mo(k),(ee)=>{if(ye(ee)){let V=new Ue(j,l,ee.left);if(f)return v.push([I,V]),Ct;else return U(new we(e,l,V,ar(X)))}else return X.push([I,ee.right]),Ct}))}}for(let k=0;k<q.length;k++){let I=x+k;if(P<I+1)continue;else{let j=q[k](l[I],u);if(_t(j)){if(ye(j)){let v=new Ue(I,l,j.left);if(f){d.push([g++,v]);continue}else return U(new we(e,l,v,ar(h)))}h.push([g++,j.right])}else{let v=g++;if(!E)E=[];E.push(({es:X,output:ee})=>ir(Mo(j),(V)=>{if(ye(V)){let me=new Ue(I,l,V.left);if(f)return X.push([v,me]),Ct;else return U(new we(e,l,me,ar(ee)))}return ee.push([v,V.right]),Ct}))}}}}let G=({es:N,output:q})=>mn(N)?U(new we(e,l,ar(N),ar(q))):K(ar(q));if(E&&E.length>0){let N=E;return ua(()=>{let q={es:Qo(d),output:Qo(h)};return ir(la(N,(k)=>k(q),{concurrency:a,batching:c,discard:!0}),()=>G(q))})}return G({output:h,es:d})}}case"TypeLiteral":{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return bt(e,vg);let r=[],n={},o=[];for(let u of e.propertySignatures)r.push([Xe(u.type,t),u]),n[u.name]=null,o.push(u.name);let i=e.indexSignatures.map((u)=>[Xe(u.parameter,t),Xe(u.type,t),u.parameter]),s=ct.make(e.indexSignatures.map((u)=>u.parameter).concat(o.map((u)=>Xn(u)?new au(u):new Lo(u)))),a=Xe(s,t),c=ah(e),l=ch(e);return(u,f)=>{if(!ap(u))return U(new $t(e,u));let d=f?.errors==="all",g=[],h=0,P=f?.onExcessProperty==="error",x=f?.onExcessProperty==="preserve",E={},G;if(P||x){G=Reflect.ownKeys(u);for(let I of G){let j=a(I,f);if(_t(j)&&ye(j))if(P){let v=new Ue(I,u,new lh(u[I],`is unexpected, expected: ${String(s)}`));if(d){g.push([h++,v]);continue}else return U(new we(e,u,v,E))}else E[I]=u[I]}}let N=void 0,q=f?.exact===!0;for(let I=0;I<r.length;I++){let j=r[I][1],v=j.name,X=Object.prototype.hasOwnProperty.call(u,v);if(!X){if(j.isOptional)continue;else if(q){let me=new Ue(v,u,new Li(j));if(d){g.push([h++,me]);continue}else return U(new we(e,u,me,E))}}let ee=r[I][0],V=ee(u[v],f);if(_t(V)){if(ye(V)){let me=new Ue(v,u,X?V.left:new Li(j));if(d){g.push([h++,me]);continue}else return U(new we(e,u,me,E))}E[v]=V.right}else{let me=h++,nt=v;if(!N)N=[];N.push(({es:pt,output:Ot})=>ir(Mo(V),(Ie)=>{if(ye(Ie)){let Y=new Ue(nt,u,X?Ie.left:new Li(j));if(d)return pt.push([me,Y]),Ct;else return U(new we(e,u,Y,Ot))}return Ot[nt]=Ie.right,Ct}))}}for(let I=0;I<i.length;I++){let j=i[I],v=j[0],X=j[1],ee=Tm(u,j[2]);for(let V of ee){let me=v(V,f);if(_t(me)&&gt(me)){let nt=X(u[V],f);if(_t(nt)){if(ye(nt)){let pt=new Ue(V,u,nt.left);if(d){g.push([h++,pt]);continue}else return U(new we(e,u,pt,E))}else if(!Object.prototype.hasOwnProperty.call(n,V))E[V]=nt.right}else{let pt=h++,Ot=V;if(!N)N=[];N.push(({es:Ie,output:Y})=>ir(Mo(nt),(He)=>{if(ye(He)){let cn=new Ue(Ot,u,He.left);if(d)return Ie.push([pt,cn]),Ct;else return U(new we(e,u,cn,Y))}else{if(!Object.prototype.hasOwnProperty.call(n,V))Y[V]=He.right;return Ct}}))}}}}let k=({es:I,output:j})=>{if(mn(I))return U(new we(e,u,ar(I),j));if(f?.propertyOrder==="original"){let v=G||Reflect.ownKeys(u);for(let ee of o)if(v.indexOf(ee)===-1)v.push(ee);let X={};for(let ee of v)if(Object.prototype.hasOwnProperty.call(j,ee))X[ee]=j[ee];return K(X)}return K(j)};if(N&&N.length>0){let I=N;return ua(()=>{let j={es:Qo(g),output:Object.assign({},E)};return ir(la(I,(v)=>v(j),{concurrency:c,batching:l,discard:!0}),()=>k(j))})}return k({es:g,output:E})}}case"Union":{let r=HO(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],Xe(e.types[l],t));let a=ah(e)??1,c=ch(e);return(l,u)=>{let f=[],d=0,g=[];if(o>0)if(ts(l))for(let x=0;x<o;x++){let E=n[x],G=r.keys[E].buckets;if(Object.prototype.hasOwnProperty.call(l,E)){let N=String(l[E]);if(Object.prototype.hasOwnProperty.call(G,N))g=g.concat(G[N]);else{let{candidates:q,literals:k}=r.keys[E],I=ct.make(k),j=q.length===i?new Er([new qe(E,I,!1,!0)],[]):ct.make(q);f.push([d++,new we(j,l,new Ue(E,l,new $t(I,l[E])))])}}else{let{candidates:N,literals:q}=r.keys[E],k=new qe(E,ct.make(q),!1,!0),I=N.length===i?new Er([k],[]):ct.make(N);f.push([d++,new we(I,l,new Ue(E,l,new Li(k)))])}}else{let x=r.candidates.length===i?e:ct.make(r.candidates);f.push([d++,new $t(x,l)])}if(r.otherwise.length>0)g=g.concat(r.otherwise);let h=void 0;for(let x=0;x<g.length;x++){let E=g[x],G=s.get(E)(l,u);if(_t(G)&&(!h||h.length===0))if(gt(G))return G;else f.push([d++,G.left]);else{let N=d++;if(!h)h=[];h.push((q)=>ua(()=>{if("finalResult"in q)return Ct;else return ir(Mo(G),(k)=>{if(gt(k))q.finalResult=k;else q.es.push([N,k.left]);return Ct})}))}}let P=(x)=>mn(x)?x.length===1&&x[0][1]._tag==="Type"?U(x[0][1]):U(new we(e,l,ar(x))):U(new $t(e,l));if(h&&h.length>0){let x=h;return ua(()=>{let E={es:Qo(f)};return ir(la(x,(G)=>G(E),{concurrency:a,batching:c,discard:!0}),()=>{if("finalResult"in E)return E.finalResult;return P(E.es)})})}return P(f)}}case"Suspend":{let r=pa(()=>Xe(e.f(),t));return(n,o)=>r()(n,o)}}},bt=(e,t)=>(r)=>t(r)?K(r):U(new $t(e,r)),xa=(e,t)=>{switch(e._tag){case"Declaration":{let r=Zm(e);if(pe(r))return xa(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):De(o.type);if(su(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):De(o.type);if(su(i)&&!o.isOptional)r.push([n,i])}return r}case"Refinement":return xa(e.from,t);case"Suspend":return xa(e.f(),t);case"Transformation":return xa(t?e.from:e.to,t)}return[]},HO=(e,t)=>{let r={},n=[],o=[];for(let i=0;i<e.length;i++){let s=e[i],a=xa(s,t);if(a.length>0){o.push(s);for(let c=0;c<a.length;c++){let[l,u]=a[c],f=String(u.literal);r[l]=r[l]||{buckets:{},literals:[],candidates:[]};let d=r[l].buckets;if(Object.prototype.hasOwnProperty.call(d,f)){if(c<a.length-1)continue;d[f].push(s),r[l].literals.push(u),r[l].candidates.push(s)}else{d[f]=[s],r[l].literals.push(u),r[l].candidates.push(s);break}}}else n.push(s)}return{keys:r,otherwise:n,candidates:o}},jO=(e)=>ga(e)?jO(e.from):e,Sa=(e,t,r,n)=>{if(n?.isEffectAllowed===!0)return e;if(_t(e))return e;let o=new ea,i=RE(e,{scheduler:o});o.flush();let s=i.unsafePoll();if(s){if(K_(s))return K(s.value);let a=s.cause;if(QS(a))return U(a.error);return U(new uh(t,r,XS(a)))}return U(new uh(t,r,"cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work"))},PF=([e],[t])=>e>t?1:e<t?-1:0;function ar(e){return e.sort(PF).map((t)=>t[1])}var FF=(e,t)=>{switch(e._tag){case"FinalTransformation":return t?e.decode:e.encode;case"ComposeTransformation":return K;case"TypeLiteralTransformation":return(r)=>{let n=K(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=cr(n,(l)=>{let u=a(Object.prototype.hasOwnProperty.call(l,i)?R(l[i]):w());if(delete l[i],pe(u))l[s]=u.value;return l})}return n}}},lt=(e,t=[])=>({value:e,forest:t}),ba={formatIssue:(e)=>cr(Di(e),NF),formatIssueSync:(e)=>{let t=ba.formatIssue(e);return _t(t)?Qg(t):CE(t)},formatError:(e)=>ba.formatIssue(e.issue),formatErrorSync:(e)=>ba.formatIssueSync(e.issue)},NF=(e)=>e.value+$O(`
37
+ `,e.forest),$O=(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+=$O(e+(n>1&&!s?"\u2502 ":" "),o.forest)}return r},MF=(e)=>{switch(e){case"Encoded":return"Encoded side transformation failure";case"Transformation":return"Transformation process failure";case"Type":return"Type side transformation failure"}},LF=(e)=>{switch(e){case"From":return"From side refinement failure";case"Predicate":return"Predicate refinement failure"}},BO=(e)=>("ast"in e)?R(e.ast):w(),ph=K(void 0),DF=(e)=>BO(e).pipe(Yt(YE),Oe({onNone:()=>ph,onSome:(t)=>{let r=t(e);if(Ke(r))return K({message:r,override:!1});if(AE(r))return eu(r,(n)=>({message:n,override:!1}));if(Ke(r.message))return K({message:r.message,override:r.override});return eu(r.message,(n)=>({message:n,override:r.override}))}})),dh=(e)=>(t)=>t._tag===e,KO=dh("Composite"),CO=dh("Refinement"),PO=dh("Transformation"),_a=(e)=>en(DF(e),(t)=>{if(t!==void 0)return!t.override&&(KO(e)||CO(e)&&e.kind==="From"||PO(e)&&e.kind!=="Transformation")?PO(e)||CO(e)?_a(e.issue):ph:K(t.message);return ph}),WO=(e)=>BO(e).pipe(Yt(eO),ny((t)=>t(e)),yt);function qF(e){return Ym(e).pipe(Jt(()=>Jm(e)),Jt(()=>Gm(e)),Jt(()=>fa(e)),ue(()=>`{ ${e.from} | filter }`))}function UF(e){if(e.message!==void 0)return e.message;return`Expected ${ga(e.ast)?qF(e.ast):String(e.ast)}, actual ${dr(e.actual)}`}var HF=(e)=>cr(_a(e),(t)=>t??WO(e)??UF(e)),hu=(e)=>WO(e)??String(e.ast),jF=(e)=>e.message??"is forbidden",$F=(e)=>e.message??"is unexpected",BF=(e)=>{let t=ZE(e.ast);if(pe(t)){let r=t.value();return Ke(r)?K(r):r}return K(e.message??"is missing")},Di=(e)=>{switch(e._tag){case"Type":return cr(HF(e),lt);case"Forbidden":return K(lt(hu(e),[lt(jF(e))]));case"Unexpected":return K(lt($F(e)));case"Missing":return cr(BF(e),lt);case"Transformation":return en(_a(e),(t)=>{if(t!==void 0)return K(lt(t));return cr(Di(e.issue),(r)=>lt(hu(e),[lt(MF(e.kind),[r])]))});case"Refinement":return en(_a(e),(t)=>{if(t!==void 0)return K(lt(t));return cr(Di(e.issue),(r)=>lt(hu(e),[lt(LF(e.kind),[r])]))});case"Pointer":return cr(Di(e.issue),(t)=>lt(tu(e.path),[t]));case"Composite":return en(_a(e),(t)=>{if(t!==void 0)return K(lt(t));let r=hu(e);return km(e.issues)?cr(la(e.issues,Di),(n)=>lt(r,n)):cr(Di(e.issues),(n)=>lt(r,[n]))})}};var zO=p((e)=>at(e[0]),(e,...t)=>{let r={};for(let n of t)if(n in e)r[n]=e[n];return r}),VO=p((e)=>at(e[0]),(e,...t)=>{let r={...e};for(let n of t)delete r[n];return r});var wa=Symbol.for("effect/Schema");function et(e){return class{[wa]=JO;static ast=e;static annotations(r){return et(tn(this.ast,r))}static pipe(){return y(this,arguments)}static toString(){return String(e)}static Type;static Encoded;static Context;static[wa]=JO}}var JO={_A:(e)=>e,_I:(e)=>e,_R:(e)=>e};var GO={typeConstructor:VE,schemaId:JE,message:Fm,missingMessage:nu,identifier:ou,title:St,description:Xr,examples:Nm,default:Mm,documentation:GE,jsonSchema:Lm,arbitrary:Dm,pretty:qm,equivalence:Um,concurrency:Hm,batching:jm,parseIssueTitle:$m,parseOptions:Bm,decodingFallback:Km},Do=(e)=>{if(!e)return{};let t={...e};for(let r in GO)if(r in e){let n=GO[r];t[n]=e[r],delete t[r]}return t},tn=(e,t)=>ya(e,Do(t));var bu=(e,t)=>{let r=UO(e,t);return(n,o)=>tc(r(n,o),fh)};var YO=(e)=>_(e,wa)&&at(e[wa]);function zF(e){return pu(e)?ct.make(OO(e,(t)=>new Lo(t))):new Lo(e[0])}function tT(e,t=zF(e)){return class extends et(t){static annotations(n){return tT(this.literals,tn(this.ast,n))}static literals=[...e]}}function D(...e){return ae(e)?tT(e):gh}var VF=(e,t,r)=>hh(e,new Fi(e.map((n)=>n.ast),(...n)=>t.decode(...n.map(et)),(...n)=>t.encode(...n.map(et)),Do(r))),JF=(e,t)=>{let r=()=>(o,i,s)=>e(o)?NO(o):MO(new $t(s,o));return hh([],new Fi([],r,r,Do(t)))};function hh(e,t){return class extends et(t){static annotations(n){return hh(this.typeParameters,tn(this.ast,n))}static typeParameters=[...e]}}var Pt=function(){if(Array.isArray(arguments[0])){let r=arguments[0],n=arguments[1],o=arguments[2];return VF(r,n,o)}let e=arguments[0],t=arguments[1];return JF(e,t)};class rT extends et(cu){}class rn extends et(nO){}class gh extends et(lu){}class le extends et(fO){}class _u extends et(mO){}class he extends et(gO){}var GF=(e)=>ct.make(e.map((t)=>t.ast));function nT(e,t=GF(e)){return class extends et(t){static annotations(n){return nT(this.members,tn(this.ast,n))}static members=[...e]}}function wt(...e){return pu(e)?nT(e):ae(e)?e[0]:gh}var YF=(e)=>wt(e,rT);var ZF=(e,t)=>new ma(e.map((r)=>YO(r)?new Hn(r.ast,!1):r.ast),t.map((r)=>YO(r)?new Ni(r.ast):r.ast),!0);function oT(e,t,r=ZF(e,t)){return class extends et(r){static annotations(o){return oT(this.elements,this.rest,tn(this.ast,o))}static elements=[...e];static rest=[...t]}}function iT(e,t){return class extends oT([],[e],t){static annotations(n){return iT(this.value,tn(this.ast,n))}static value=e}}var J=(e)=>iT(e);var mh=(e)=>e?'"?:"':'":"';class yh extends Hn{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 sT extends Hn{isReadonly;defaultValue;constructor(e,t,r,n,o){super(e,t,n);this.isReadonly=r,this.defaultValue=o}}var QF=(e)=>{if(e===void 0)return"never";if(Ke(e))return JSON.stringify(e);return String(e)};class aT{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}, ${QF(this.from.fromKey)}, ${mh(this.from.isOptional)}, ${this.from.type}>`}}var cT=(e,t)=>{switch(e._tag){case"PropertySignatureDeclaration":return new yh(e.type,e.isOptional,e.isReadonly,{...e.annotations,...t},e.defaultValue);case"PropertySignatureTransformation":return new aT(e.from,new sT(e.to.type,e.to.isOptional,e.to.isReadonly,{...e.to.annotations,...t},e.to.defaultValue),e.decode,e.encode)}},lT=Symbol.for("effect/PropertySignature"),uT=(e)=>_(e,lT);class xh{ast;[wa];[lT]=null;_TypeToken;_Key;_EncodedToken;_HasDefault;constructor(e){this.ast=e}pipe(){return y(this,arguments)}annotations(e){return new xh(cT(this.ast,Do(e)))}toString(){return String(this.ast)}}class Sh extends xh{from;constructor(e,t){super(e);this.from=t}annotations(e){return new Sh(cT(this.ast,Do(e)),this.from)}}var z=(e)=>{let t=e.ast===cu||e.ast===lu?cu:YF(e).ast;return new Sh(new yh(t,!0,!0,{},void 0),e)};var XF=ih([nu]),eN=(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(uT(u)){let f=u.ast;switch(f._tag){case"PropertySignatureDeclaration":{let{type:d,isOptional:g,annotations:h}=f;i.push(new qe(l,d,g,!0,XF(f))),s.push(new qe(l,De(d),g,!0,h)),n.push(new qe(l,d,g,!0,h));break}case"PropertySignatureTransformation":{let d=f.from.fromKey??l;i.push(new qe(d,f.from.type,f.from.isOptional,!0,f.from.annotations)),s.push(new qe(l,f.to.type,f.to.isOptional,!0,f.to.annotations)),a.push(new rh(d,l,f.decode,f.encode));break}}}else i.push(new qe(l,u.ast,!1,!0)),s.push(new qe(l,De(u.ast),!1,!0)),n.push(new qe(l,u.ast,!1,!0))}if(ae(a)){let c=[],l=[];for(let u of t){let{indexSignatures:f,propertySignatures:d}=oh(u.key.ast,u.value.ast);d.forEach((g)=>{i.push(g),s.push(new qe(g.name,De(g.type),g.isOptional,g.isReadonly,g.annotations))}),f.forEach((g)=>{c.push(g),l.push(new Mi(g.parameter,De(g.type),g.isReadonly))})}return new th(new Er(i,c,{[iu]:"Struct (Encoded side)"}),new Er(s,l,{[iu]:"Struct (Type side)"}),new nh(a))}}let o=[];for(let i of t){let{indexSignatures:s,propertySignatures:a}=oh(i.key.ast,i.value.ast);a.forEach((c)=>n.push(c)),s.forEach((c)=>o.push(c))}return new Er(n,o)},tN=(e,t)=>{let r=Reflect.ownKeys(e);for(let n of r){let o=e[n];if(t[n]===void 0&&uT(o)){let i=o.ast,s=i._tag==="PropertySignatureDeclaration"?i.defaultValue:i.to.defaultValue;if(s!==void 0)t[n]=s()}}return t};function pT(e,t,r=eN(e,t)){return class extends et(r){static annotations(o){return pT(this.fields,this.records,tn(this.ast,o))}static fields={...e};static records=[...t];static make=(o,i)=>{let s=tN(e,{...o});return bh(i)?s:Su(this)(s)};static pick(...o){return W(zO(e,...o))}static omit(...o){return W(VO(e,...o))}}}function W(e,...t){return pT(e,t)}function fT(e,t){return class extends et(t){static annotations(n){return fT(this.from,tn(this.ast,n))}static make=(n,o)=>bh(o)?n:Su(this)(n);static from=e}}var Ea=(e,t)=>(r)=>{let n=Oe(Vm(r.ast),{onNone:()=>[e],onSome:(i)=>[...i,e]}),o=ya(r.ast,Do({[Pm]:n,...t}));return fT(r,o)};var rN=Symbol.for("effect/SchemaId/Refine");function dT(e,t,r){return class extends et(r){static annotations(o){return dT(this.from,this.filter,tn(this.ast,o))}static[rN]=e;static from=e;static filter=t;static make=(o,i)=>bh(i)?o:Su(this)(o)}}var ZO=(e,t,r)=>{if(Qn(e))return e?w():R(new $t(t,r));if(Ke(e))return R(new $t(t,r,e));if(e!==void 0){if("_tag"in e)return R(e);let n=new $t(t,r,e.message);return R(ae(e.path)?new Ue(e.path,r,n):n)}return w()},nN=(e,t,r)=>{if(FE(e))return ZO(e,t,r);if(ae(e)){let n=oc(e,(o)=>ZO(o,t,r));if(ae(n))return R(n.length===1?n[0]:new we(t,r,n))}return w()};function Or(e,t){return(r)=>{function n(i,s,a){return nN(e(i,s,a),a,i)}let o=new ha(r.ast,n,Do(t));return dT(r,n,o)}}var oN=KE,mT=(e,t)=>(r)=>r.pipe(Or((n)=>n.length>=e,{schemaId:oN,title:`minLength(${e})`,description:`a string at least ${e} character(s) long`,jsonSchema:{minLength:e},...t}));var QO=Symbol.for("effect/SchemaId/Pattern"),lr=(e,t)=>(r)=>{let n=e.source;return r.pipe(Or((o)=>(e.lastIndex=0,e.test(o)),{schemaId:QO,[QO]:{regex:e},description:`a string matching the pattern ${n}`,jsonSchema:{pattern:n},...t}))};var iN=Symbol.for("effect/SchemaId/UUID"),XO=/^[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 sN extends le.pipe(lr(XO,{schemaId:iN,identifier:"UUID",jsonSchema:{format:"uuid",pattern:XO.source},description:"a Universally Unique Identifier",arbitrary:()=>(e)=>e.uuid()})){}var aN=jE,hT=(e,t)=>(r)=>r.pipe(Or((n)=>n>e,{schemaId:aN,title:`greaterThan(${e})`,description:e===0?"a positive number":`a number greater than ${e}`,jsonSchema:{exclusiveMinimum:e},...t})),cN=$E,gT=(e,t)=>(r)=>r.pipe(Or((n)=>n>=e,{schemaId:cN,title:`greaterThanOrEqualTo(${e})`,description:e===0?"a non-negative number":`a number greater than or equal to ${e}`,jsonSchema:{minimum:e},...t}));var lN=BE,uN=(e)=>(t)=>t.pipe(Or((r)=>Number.isSafeInteger(r),{schemaId:lN,title:"int",description:"an integer",jsonSchema:{type:"integer"},...e}));class wu extends _u.pipe(uN({identifier:"Int"})){}var pN=WE,Oa=(e,t)=>(r)=>{let n=Math.floor(e);if(n<1)throw Error(NE(`Expected an integer greater than or equal to 1, actual ${e}`));return r.pipe(Or((o)=>o.length>=n,{schemaId:pN,title:`minItems(${n})`,description:`an array of at least ${n} item(s)`,jsonSchema:{minItems:n},[zm]:!0,...t}))};var eT=HE;class fN extends Pt(Wa,{typeConstructor:{_tag:"Date"},identifier:"DateFromSelf",schemaId:eT,[eT]:{noInvalidDate:!1},description:"a potentially invalid Date instance",pretty:()=>(e)=>`new Date(${JSON.stringify(e)})`,arbitrary:()=>(e)=>e.date({noInvalidDate:!1}),equivalence:()=>Tg}){}function bh(e){return Qn(e)?e:e?.disableValidation??!1}var dN={onExcessProperty:"error"};function nn(e,t){return bu(e,dN)(t)}var _h=D("computer_use","work","frontend","security"),mN=D("computer_use","work","frontend","security"),hN=D("installed","disabled","missing","uncertain"),gN=D("healthy","missing","disabled","uncertain"),yN=Object.freeze(["openai-curated","openai-curated-remote"]),xN=Object.freeze(["build-web-apps","codex-security"]);var on=Object.freeze({coding:!0,computer_use:!1,work:!1,frontend:!0,security:!0}),SN={work:{name:"work",pluginIds:["documents@openai-primary-runtime","pdf@openai-primary-runtime","presentations@openai-primary-runtime","spreadsheets@openai-primary-runtime","template-creator@openai-primary-runtime"],defaultSelected:on.work,migrationKey:"work",semanticSkillIds:["documents:documents","pdf:pdf","presentations:Presentations","spreadsheets:Spreadsheets","template-creator:template-creator"],ownership:"shared-preserve"},frontend:{name:"frontend",pluginIds:["build-web-apps@openai-curated"],defaultSelected:on.frontend,migrationKey:"frontend",semanticSkillIds:["build-web-apps:frontend-app-builder","build-web-apps:frontend-testing-debugging","build-web-apps:react-best-practices"],ownership:"shared-preserve"},security:{name:"security",pluginIds:["codex-security@openai-curated"],defaultSelected:on.security,migrationKey:"security",semanticSkillIds:["codex-security:security-scan","codex-security:security-diff-scan","codex-security:threat-model"],ownership:"shared-preserve"},computer_use:{name:"computer_use",pluginIds:["computer-use@openai-bundled"],defaultSelected:on.computer_use,migrationKey:"computer_use",semanticSkillIds:["computer-use:computer-use"],ownership:"shared-preserve"}},bN=Object.freeze(SN),_N=Object.freeze(["computer_use","work","frontend","security"]),wN=Object.freeze({computer_use:on.computer_use,work:on.work,frontend:on.frontend,security:on.security});var ST=D("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"),EN=W({identifier:ST,label:le,requiresRootApproval:he});function Tr(e){return W({identifier:D(e),label:le,requiresRootApproval:he})}var ON=W({localRepositoryEdit:Tr("local.repository.edit"),localRepositoryCheck:Tr("local.repository.check"),localRepositoryLint:Tr("local.repository.lint"),localRepositoryFormat:Tr("local.repository.format"),localRepositoryCommit:Tr("local.repository.commit"),externalRead:Tr("external.read"),specialistDispatch:Tr("specialist.dispatch"),versionControlServerMutation:Tr("vcs.server.mutation"),versionControlServerCiTrigger:Tr("vcs.server.ci-trigger"),unknownEffect:Tr("unknown.effect")}),wh={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}};fr(wh);var TN=D("never","root"),bT=Object.values(wh);function yT(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 xT(e){return e.length===0?e:`${e[0]?.toUpperCase()??""}${e.slice(1)}`}var kN=bT.filter((e)=>!e.requiresRootApproval),AN=bT.filter((e)=>e.requiresRootApproval),IN=Object.freeze({noRootApproval:`${xT(yT(kN))} actions do not require Root approval.`,rootApproval:`${xT(yT(AN))} require Root approval.`});var ur=le.pipe(lr(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u)),Eh=le.pipe(lr(/^[0-9a-f]{64}$/u)),qB=ur.pipe(Ea("RunId")),UB=ur.pipe(Ea("ProjectId")),HB=ur.pipe(Ea("TrustId")),jB=Eh.pipe(Ea("Sha256Digest"));var vN=W({run_id:ur,objective_lineage:ur,parent_run_id:z(wt(ur,rn))}),RN=W({project_id:ur,trust_id:ur,trust_digest:Eh}),CN=W({project_id:ur,project_digest:Eh}),PN=le.pipe(lr(/^state-[0-9]+\.[0-9]+$/u));var Eu=D("low","default","high"),OT=D("go","Go","plus-low","plus","plus-high","pro-5x","pro-20x"),FN=wt(Eu,OT);var TT=D("standard","fast","fast-all"),NN=D("low","medium","high","xhigh","max"),kT="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.",$n="Do not modify repository source or the implementation under validation; observation, analysis, and proof artifacts only.",MN=D("read-only","workspace-write"),sn=[{role:"Explorer",tasks:[{name:"lookup",description:"Repository fact lookup specialist.",instruction:`Locate the exact requested repository fact. ${$n}`,permissions:{network:!1,filesystem:"read-only",sourceMutation:!1}},{name:"trace",description:"Repository execution and reference tracing specialist.",instruction:`Trace the complete in-scope execution or reference path. ${$n}`,permissions:{network:!1,filesystem:"read-only",sourceMutation:!1}}],capability:"repository-read",authority:"Read only the delegated Assignment repository scope; Git/VCS, lifecycle, and decisions remain Root-only.",evidence:"Return exact paths, symbols, callers, tests, and constraints.",completion:"Account for every in-scope caller and constraint.",permissions:{network:!1,filesystem:"read-only",sourceMutation:!1}},{role:"Librarian",tasks:[{name:"lookup",description:"Authoritative external fact lookup specialist.",instruction:`Locate the exact requested authoritative external fact. ${$n}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"research",description:"Current authoritative-source research specialist.",instruction:`Synthesize the assigned current sources with citations. ${$n}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}}],capability:"current-research",authority:"Research only the delegated Assignment current sources without repository mutation; Git/VCS, lifecycle, and decisions remain Root-only.",evidence:"Return sourced facts, dates, and explicit uncertainty.",completion:"Resolve the assigned external fact or report the exact evidence gap.",permissions:{network:!1,filesystem:"read-only",sourceMutation:!1}},{role:"Worker",tasks:[{name:"mechanical",description:"Deterministic bounded-edit specialist.",instruction:"Apply only deterministic, already-decided edits.",permissions:{network:!1,filesystem:"workspace-write",sourceMutation:!0}},{name:"implementation",description:"Bounded behavior implementation specialist.",instruction:"Implement and verify the bounded behavior seam.",permissions:{network:!1,filesystem:"workspace-write",sourceMutation:!0}},{name:"integration",description:"Decided seam integration specialist.",instruction:"Integrate the decided seams and verify them together.",permissions:{network:!1,filesystem:"workspace-write",sourceMutation:!0}},{name:"operations",description:"Exact-ref or SHA terminal operations observer.",instruction:`Observe the assigned post-VCS external gate at the supplied exact ref or SHA. ${$n}`,permissions:{network:!0,filesystem:"read-only",sourceMutation:!1}},{name:"validation",description:"Independent local behavioral validation specialist.",instruction:`When independent proof is useful, run the smallest relevant local checks for the delegated seam, classify failures, and report evidence without redesigning the solution or replacing code review. ${$n}`,permissions:{network:!1,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; return material redesigns to Root.",permissions:{network:!1,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, 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:!1,filesystem:"read-only",sourceMutation:!1}},{role:"Reviewer",tasks:[{name:"plan",description:"Adversarial implementation-plan review specialist.",instruction:`Review the complete plan to a fixed point. ${$n}`,permissions:{network:!1,filesystem:"read-only",sourceMutation:!1}},{name:"code",description:"Adversarial implemented-code review specialist.",instruction:"Review and repair the implemented code to a fixed point. 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.",permissions:{network:!1,filesystem:"workspace-write",sourceMutation:!0}},{name:"artifact",description:"Adversarial produced-artifact review specialist.",instruction:"Review and repair the produced artifact to a fixed point.",permissions:{network:!1,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, 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:!1,filesystem:"read-only",sourceMutation:!1}}];fr(sn);var AT=new Map(sn.map((e)=>[e.role,e])),LN=new Set(sn.map((e)=>e.role)),Oh=sn.flatMap((e)=>e.tasks.map((t)=>`${e.role}:${t.name}`)),DN=new Set(Oh),IT=Oh.map((e)=>e.replace(":",".")),vT=new Set(IT);function RT(e){return typeof e==="string"&&LN.has(e)}function qN(e){if(typeof e!=="object"||e===null||!("role"in e)||!("task"in e))return!1;let{role:t,task:r}=e;if(!RT(t)||typeof r!=="string")return!1;return AT.get(t)?.tasks.some((n)=>n.name===r)===!0}function Ou(e,t){return typeof t==="string"&&AT.get(e)?.tasks.some((r)=>r.name===t)===!0}function CT(e){return typeof e==="string"&&DN.has(e)}var Th=Pt(RT),UN=Pt((e)=>Ou("Explorer",e)),HN=Pt((e)=>Ou("Librarian",e)),jN=Pt((e)=>Ou("Worker",e)),$N=Pt((e)=>Ou("Reviewer",e)),Ta=Pt(qN),qo=Object.freeze(Oh.filter((e)=>CT(e))),PT=Pt(CT),BN=Object.freeze(IT.filter((e)=>vT.has(e))),KN=Pt((e)=>typeof e==="string"&&vT.has(e));var FT=W({profile:Eu,service_tier:z(TT)}),WN=D("git_vcs","computer_use"),zN=D("delegated","root_direct","unavailable"),VN=Object.freeze({requiresDelegation:!0,trivialWorkRequiresDelegation:!0,directExecutionExceptions:Object.freeze(["git_vcs","computer_use"]),requestUserInputGates:Object.freeze(["plan_approval","installation_profile_approval","remote_origin_server_vcs_mutation","public_publication_or_release","ambiguity_or_missing_material_input"]),surgicalMutationRule:kT,specialistOutcomes:Object.freeze(["completed","blocked","needs_root_input","failed"]),materialDecisionsRemainRootOwned:!0,lifecycleRemainsRootOwned:!0,integrationAndCompletionRemainRootOwned:!0,codeReviewRequiredForImplementation:!0,codeReviewRequiredBeforeVcs:!0,externalVerificationMustBeTerminal:!0,postVcsFlow:"discover_topology_observe_repair_repeat"});function tt(e,t){return new st("invalid_canonical_value",`Cannot canonicalize ${e}: ${t}.`,{path:e,reason:t})}function kh(e,t,r){if(e===null)return"null";switch(typeof e){case"string":{let n=JSON.stringify(e);if(n===void 0)throw tt(t,"invalid string");return n}case"boolean":return e?"true":"false";case"number":{if(!Number.isFinite(e))throw tt(t,"non-finite number");let n=JSON.stringify(e);if(n===void 0)throw tt(t,"invalid number");return n}case"undefined":throw tt(t,"undefined is not JSON");case"bigint":throw tt(t,"bigint is not JSON");case"function":throw tt(t,"function is not JSON");case"symbol":throw tt(t,"symbol is not JSON");case"object":break}if(r.has(e))throw tt(t,"cyclic value");r.add(e);try{if(Array.isArray(e)){for(let a of Object.getOwnPropertySymbols(e))throw tt(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 tt(`${t}[${a}]`,"sparse or accessor array item");s.push(kh(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 tt(t,`non-index array property ${a}`);let l=Object.getOwnPropertyDescriptor(i,a);if(!l||!l.enumerable||!("value"in l))throw tt(`${t}[${c}]`,"non-enumerable or accessor array item")}return`[${s.join(",")}]`}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw tt(t,"only plain objects are supported");for(let i of Object.getOwnPropertySymbols(e))throw tt(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 tt(`${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 tt(`${t}.${i}`,"accessor property");o.push(`${JSON.stringify(i)}:${kh(s.value,`${t}.${i}`,r)}`)}return`{${o.join(",")}}`}finally{r.delete(e)}}function Ah(e){return kh(e,"$",new Set)}var NT=D("blocked","completed","failed","partial"),MT=wt(D("high","max","xhigh"),rn);function LT(e){try{return Ah(e)!==void 0}catch{return!1}}var DT=Pt((e)=>LT(e)),GN=Pt((e)=>zu(e)&&!Array.isArray(e)&&LT(e)),YN=W({blocked:he,changed_files:J(le),confidence:_u,context_owner:wt(le,rn),material_findings:J(le),needs_more_context:he,needs_root_decision:he,needs_verification:he,relevant_files:J(le),remaining_risk:J(le),reuse_recommended:he,status:NT,suggested_followup:wt(le,rn),suggested_luna_effort:MT,suggested_specialist:wt(Th,rn),verification:J(le),verification_passed:he}),Ih="holycodex-specialist-outcome-2",Et=le.pipe(mT(1)),ka={protocol_version:D(Ih),route:Ta,evidence:J(Et)},ZN=W(ka),QN=W({...ka,status:D("completed"),summary:Et}),XN=W({...ka,status:D("blocked"),reason:Et,needs_root_decision:he}),eM=W({...ka,status:D("partial"),summary:Et,completed:J(Et),remaining:J(Et),needs_root_decision:he}),tM=W({...ka,status:D("failed"),error:Et}),rM=wt(QN,XN,eM,tM),Tu={protocol_version:D(Ih),capability:_h,route:wt(Ta,rn),evidence:J(Et),data:DT},nM=W({...Tu,status:D("completed"),summary:Et}),oM=W({...Tu,status:D("blocked"),reason:Et,needs_root_decision:he}),iM=W({...Tu,status:D("partial"),summary:Et,completed:J(Et),remaining:J(Et),needs_root_decision:he}),sM=W({...Tu,status:D("failed"),error:Et}),aM=wt(nM,oM,iM,sM);var qT=J(le),UT=le.pipe(lr(/^[a-z][a-z0-9-]*(?: [a-z][a-z0-9-]*)*$/u)),HT=D(Wu),cM=W({code:ur,message:le,details:GN}),jT=W({schema_version:HT,ok:D(!0),command:UT,data:DT,warnings:qT}),$T=W({schema_version:HT,ok:D(!1),command:UT,error:cM,warnings:qT}),lM=wt(jT,$T);var KT="gpt-5.6-luna";function uM(e,t,r){return{key:`${e}:${t}`,role:e,task:t,model:KT,effort:r}}var pM=new Set(qo),BT={low:0,medium:1,high:2,xhigh:3,max:4},Rh=[{profile:"low",rationale:"The low profile keeps bounded specialist work economical.",efforts:{"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: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: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"}}];fr(Rh);var fM=new Map(Rh.map((e)=>[e.profile,e]));function dM(e){let t=fM.get(e);if(t===void 0)throw new st("catalog_invalid","A profile has no route effort policy.",{profile:e});return sn.flatMap((r)=>r.tasks.map((n)=>{let o=`${r.role}:${n.name}`,i=t.efforts[o];if(i===void 0)throw new st("catalog_invalid","A route effort policy is incomplete.",{profile:e,route:o});return uM(r.role,n.name,i)}))}function vh(e){return{name:e.name,root:{model:"gpt-6-astra",effort:e.effort},specialistModel:"gpt-5.6-luna",defaultServiceTier:"standard",routes:dM(e.name)}}var Ch=[vh({name:"low",effort:"low"}),vh({name:"default",effort:"medium"}),vh({name:"high",effort:"high"})];function mM(e){let t=["low","default","high"];if(e.length!==t.length)throw new st("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 st("catalog_invalid","The profile catalog order is invalid.",{index:r});let i=o==="low"?"low":o==="default"?"medium":"high";if(n.root.model!=="gpt-6-astra"||n.root.effort!==i||n.specialistModel!=="gpt-5.6-luna")throw new st("catalog_invalid","A profile has an invalid model route.",{profile:n.name});if(n.routes.length!==qo.length)throw new st("catalog_invalid","A profile is incomplete.",{profile:n.name});let s=new Set;for(let a of n.routes){if(s.has(a.key)||!pM.has(a.key)||a.model!=="gpt-5.6-luna"||`${a.role}:${a.task}`!==a.key)throw new st("catalog_invalid","A profile contains an invalid route.",{profile:n.name});s.add(a.key)}if(s.size!==qo.length)throw new st("catalog_invalid","A profile is missing a specialist route.",{profile:n.name})}for(let r=0;r<qo.length;r+=1){let n=-1;for(let o of e){let i=o.routes[r];if(!i||BT[i.effort]<n)throw new st("catalog_invalid","Profile route effort is not monotonic.",{route:qo[r]??"unknown"});n=BT[i.effort]}}}mM(Ch);fr(Ch);var WT=Ch,hM=new Map,gM=new Map;for(let e of WT){hM.set(e.name,e);let t=new Map;for(let r of e.routes)t.set(r.key,r);gM.set(e.name,t)}import{execFile as yM}from"child_process";import{createHash as xM}from"crypto";import{lstat as an,mkdir as qi,open as Nu,readFile as Uh,readdir as Ia,realpath as SM,rename as bM,rm as Ra,stat as _M}from"fs/promises";import{basename as Ph,dirname as zn,isAbsolute as wM,join as C,relative as EM,resolve as Pu}from"path";import{promisify as OM}from"util";var Mu="holycodex-intent-1",Hh="holycodex-plan-1",jh="holycodex-assignment-1",Vn="toon-4",B=le.pipe(Or((e)=>e.trim().length>0)),Kt=le.pipe(lr(/^[a-z0-9][a-z0-9-]{0,95}$/u)),$h=le.pipe(lr(/^[a-f0-9]{64}$/u)),ZT=le.pipe(lr(/^[a-f0-9]{40}$/u)),Ca=wu.pipe(gT(1)),pr=le.pipe(Or((e)=>!Number.isNaN(Date.parse(e)))),Ae=J(B),TM=W({pid:wu.pipe(hT(0)),token:B}),kM=120000,AM=4294967295,Bh=W({role:D("Explorer","Librarian","Worker","Reviewer"),task:B}).pipe(Or((e)=>sn.some((t)=>t.role===e.role&&t.tasks.some((r)=>r.name===e.task)))),Ho=W({kind:D("changed_path","check","repository_fact","ci","behavior","uncertainty"),value:B,result:z(D("passed","failed","observed","unknown"))}),Kh=W({root:B,git_common_dir:B,initial_head:B,expected_head:B,expected_changes:Ae,expected_status_digest:$h,integrated_commit:z(ZT),updated_at:pr}),Hi=D("scoping","ready","executing","verifying","reviewing","blocked","needs_root_input","complete","abandoned"),IM=D("scoping","ready","executing","verifying","reviewing"),zT=W({required:he,status:D("not_required","missing","passed","failed","accepted","rejected"),evidence:J(Ho)}),Pa=W({schema_version:D(Mu),toon_compatibility:D(Vn),id:Kt,slug:Kt,title:B,goal:B,acceptance_criteria:Ae,state:Hi,revision:Ca,plan_required:he,active_plan_revision:z(Ca),active_plan_digest:z($h),blockers:Ae,resume_state:z(IM),verification:zT,review:zT,acceptance_met:he,root_readiness:he,evidence:J(Ho),baseline:Kh,created_at:pr,updated_at:pr}),Cu=W({schema_version:D(Hh),toon_compatibility:D(Vn),intent_id:Kt,revision:Ca,predecessor_digest:z($h),approach:B,scope:Ae,exclusions:Ae,assignments:Ae,dependencies:Ae,architecture:Ae,risks:Ae,assumptions:Ae,open_questions:Ae,verification:Ae,recovery:Ae,updated_at:pr}),Wh=D("completed","blocked","needs_root_input","failed"),QT=D("pending","executing","completed","blocked","needs_root_input","failed"),zh=W({id:Kt,outcome:Wh,started_at:pr,finished_at:pr,summary:B,evidence:J(Ho),blocker:z(B),remaining_risk:Ae}),va=W({schema_version:D(jh),toon_compatibility:D(Vn),intent_id:Kt,id:Kt,objective:B,owner:Bh,scope:Ae,constraints:Ae,exclusions:Ae,dependencies:Ae,acceptance_criteria:Ae,status:QT,revision:Ca,invocations:J(zh),active_invocation_id:z(B),active_started_at:z(pr),evidence:J(Ho),blocker:z(B),remaining_risk:Ae,created_at:pr,updated_at:pr}),vM=W({schema_version:D("holycodex-intent-0"),id:Kt,slug:Kt,title:B,goal:B,acceptance_criteria:Ae,state:Hi,revision:Ca,baseline:Kh,created_at:pr,updated_at:pr});class A extends Error{code;details;constructor(e,t,r={}){super(t);this.name="IntentStoreError",this.code=e,this.details=r}}var Lu=W({title:B,goal:B,acceptanceCriteria:J(B).pipe(Oa(1)),planRequired:z(he),verificationRequired:z(he),reviewRequired:z(he)}),Du=W({approach:B,scope:z(J(B)),exclusions:z(J(B)),assignments:z(J(B)),dependencies:z(J(B)),architecture:z(J(B)),risks:z(J(B)),assumptions:z(J(B)),openQuestions:z(J(B)),verification:z(J(B)),recovery:z(J(B))}),qu=W({id:z(B),objective:B,owner:Bh,scope:J(B).pipe(Oa(1)),constraints:z(J(B)),exclusions:z(J(B)),dependencies:z(J(B)),acceptanceCriteria:J(B).pipe(Oa(1))}),Uu=W({scope:J(B).pipe(Oa(1))}),Hu=W({commit:ZT}),ju=W({invocationId:z(B),outcome:Wh,startedAt:z(B),summary:B,evidence:z(J(Ho)),blocker:z(B),remainingRisk:z(J(B))}),$u=W({evidence:z(J(Ho)),verification:z(D("passed","failed")),review:z(D("accepted","rejected")),acceptanceMet:z(he),rootReadiness:z(he),clearBlockers:z(he)}),Fa=OM(yM);class Bu{repositoryRoot;stateRoot;#e;#i;constructor(e,t={}){this.repositoryRoot=Pu(e),this.stateRoot=C(this.repositoryRoot,".holycodex"),this.#e=t.now??(()=>new Date),this.#i=t.repositorySnapshot??(()=>XT(this.repositoryRoot))}async recover(){if(await this.#s(),!await Ru(this.stateRoot))return[];return await vu(C(this.stateRoot,".intent-store"),async()=>this.#c())}async#c(){let e;try{e=await Ia(this.stateRoot,{recursive:!0})}catch(r){if(ge(r,"ENOENT"))return[];throw Ne(r)}let t=[];for(let r of e){let n=Ph(r);if(!n.startsWith(".holycodex-write-")||!n.endsWith(".tmp"))continue;let o=C(this.stateRoot,r),i=zn(o);if(i!==this.stateRoot&&await Ru(C(i,".intent-store")))continue;await Ui(o),await Ra(o,{force:!0}),t.push(r.replaceAll("\\","/"))}return t.sort()}async#s(){try{let e=await an(this.stateRoot);if(e.isSymbolicLink()||!e.isDirectory())throw new A("schema_invalid","Repository-local work state must be a real directory.",{path:this.stateRoot})}catch(e){if(ge(e,"ENOENT"))return;throw Ne(e)}}async createIntent(e){let t=ke(Lu,e);if(!t.title.trim()||!t.goal.trim()||t.acceptanceCriteria.length===0)throw Uo("Intent title, goal, and acceptance criteria are required.");return await this.recover(),await qi(this.stateRoot,{recursive:!0}),await vu(C(this.stateRoot,".intent-store"),async()=>{let r=await this.#i(),n=MM(t.title),o=Wn([r.root,t.title.trim(),t.goal.trim()].join("\x00")).slice(0,10),i=`${n}-${o}`,s=1;while(await Ru(C(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=ke(Pa,{schema_version:Mu,toon_compatibility:Vn,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:Fu(t.verificationRequired??!0),review:Fu(t.reviewRequired??!0),acceptance_met:!1,root_readiness:!1,evidence:[],baseline:Fh(r,c),created_at:c,updated_at:c}),u=C(this.stateRoot,i);return await qi(C(u,"assignments"),{recursive:!0}),await ut(C(u,"intent.toon"),l),await qh(C(this.stateRoot,"current"),`${i}
38
+ `),l})}async listIntents(){await this.#s(),await this.recover();let e;try{e=await Ia(this.stateRoot)}catch(r){if(ge(r,"ENOENT"))return[];throw Ne(r)}let t=[];for(let r of e.sort()){let n=C(this.stateRoot,r);if(!await Lh(n))continue;let o=C(n,"intent.toon");if(await Aa(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(C(t,"intent.toon")))}async currentIntent(){await this.#s();try{let t=C(this.stateRoot,"current"),r=await an(t).catch((o)=>{if(ge(o,"ENOENT"))return;throw Ne(o)});if(r?.isSymbolicLink()||r&&!r.isFile())throw new A("schema_invalid","The current Intent pointer must be a regular file.");let n=r?(await Uh(t,"utf8")).trim():"";if(n){let o=Pu(this.stateRoot,n);if(!jM(this.stateRoot,o))throw new A("schema_invalid","The current Intent pointer escapes repository-local state.",{directory:n});if(!await Lh(o))throw new A("schema_invalid","The current Intent pointer does not select a work-state directory.",{directory:n});return await this.#t(C(o,"intent.toon"))}}catch(t){if(!ge(t,"ENOENT"))throw Ne(t)}let e=(await this.listIntents()).filter((t)=>t.state!=="complete"&&t.state!=="abandoned");if(e.length===1)return e[0];throw new A(e.length?"current_ambiguous":"not_found",e.length?"Multiple active Intents require explicit selection.":"No current Intent exists.",{intent_ids:e.map((t)=>t.id)})}async selectCurrent(e){let t=await this.#r(e),r=await this.#t(C(t,"intent.toon"));return await vu(C(this.stateRoot,".intent-store"),async()=>qh(C(this.stateRoot,"current"),`${Ph(t)}
39
+ `)),r}async transitionIntent(e,t,r,n){let o=ke(Hi,t),i=n===void 0?void 0:ke(B,n);if(!Number.isSafeInteger(r)||r<1)throw Uo("Intent revision must be a positive integer.");let s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(C(s,"intent.toon"));if(Bt(a.revision,r),o==="complete")throw new A("invalid_transition","Use the predicate-checked complete operation.");if(o==="abandoned")return await this.#a(s,a);return await this.#l(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(C(r,"intent.toon"));if(Bt(n.revision,t),Kn(n),await this.#o(n),n.active_plan_revision!==void 0)await this.readPlan(e);let o=await this.listAssignments(e),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"))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=Bn(n,this.#e,{state:"complete"});return await ut(C(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(C(r,"intent.toon"));return Bt(n.revision,t),await this.#a(r,n)})}async recordIntentEvidence(e,t,r){let n=ke($u,r),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(C(o,"intent.toon"));if(Bt(i.revision,t),Kn(i),n.verification!==void 0||n.review!==void 0)await this.#o(i);if(n.verification!==void 0&&i.state!=="verifying")throw new A("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"&&!NM(s))throw new A("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 A("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,f=Bn(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 ut(C(o,"intent.toon"),f),f})}async recordVcsIntegration(e,t,r){let n=ke(Hu,r),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(C(o,"intent.toon"));if(Bt(i.revision,t),Kn(i),i.state!=="reviewing")throw new A("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 A("not_ready","VCS integration requires accepted review evidence.",{review_status:i.review.status});let s=await this.#i();if(s.root!==i.baseline.root||s.gitCommonDir!==i.baseline.git_common_dir)throw new A("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 A("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 A("repository_drift","VCS integration requires a clean worktree.",{changed_paths:[...s.changedPaths].sort()});let a=await RM(this.repositoryRoot,n.commit);if(a.parents[0]!==i.baseline.expected_head)throw new A("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 CM(this.repositoryRoot,i.baseline.expected_head,n.commit),l=[...new Set(i.baseline.expected_changes)].sort();if(c.join("\x00")!==l.join("\x00"))throw new A("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(),f={kind:"repository_fact",value:`Root VCS integration recorded at ${n.commit}; ${String(c.length)} expected path(s) committed.`,result:"observed"},d=Bn(i,this.#e,{baseline:Fh(s,u,i.baseline.initial_head,n.commit),evidence:[...i.evidence,f]});return await ut(C(o,"intent.toon"),d),d})}async readPlan(e){let t=await this.#r(e),r=C(t,"plan.toon");if(!await Aa(r))return;let n=await Iu(r,Cu),o=await this.#t(C(t,"intent.toon")),i=Wn(`${Ji(n)}
40
+ `);if(n.intent_id!==o.id||o.active_plan_revision!==n.revision||o.active_plan_digest!==i)throw new A("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=ke(Du,t);if(!o.approach.trim())throw Uo("Plan approach is required.");let i=await this.#r(e);return await this.#n(i,async()=>{let s=await this.#t(C(i,"intent.toon"));Bt(s.revision,r),Kn(s),await this.#o(s);let a=C(i,"plan.toon"),c=await Aa(a)?await Iu(a,Cu):void 0;if(c===void 0&&n!==void 0)Bt(0,n);if(c!==void 0)Bt(c.revision,n);let l,u;if(c){let h=`${Ji(c)}
41
+ `;u=Wn(h),l=await HM(i),await LM(l,h)}let f=ke(Cu,{schema_version:Hh,toon_compatibility:Vn,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 ut(a,f);let d=Wn(`${Ji(f)}
42
+ `),g=Bn(s,this.#e,{active_plan_revision:f.revision,active_plan_digest:d,verification:ku(s.verification),review:ku(s.review),acceptance_met:!1,root_readiness:!1});return await ut(C(i,"intent.toon"),g),{intent:g,plan:f,...l?{archived:Ph(l)}:{}}})}async createAssignment(e,t,r){let n=ke(qu,t);if(!n.objective.trim()||n.scope.length===0||n.acceptanceCriteria.length===0)throw Uo("Assignment objective, scope, and acceptance criteria are required.");let o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(C(o,"intent.toon"));if(Bt(i.revision,r),Kn(i),await this.#o(i),n.owner.role==="Worker"&&n.owner.task==="operations"&&i.baseline.integrated_commit!==i.baseline.expected_head)throw new A("not_ready","Worker.operations requires a successfully integrated exact commit.",{expected_head:i.baseline.expected_head});let s=n.id??`assignment-${Wn([i.id,n.objective,...n.scope].join("\x00")).slice(0,10)}`;if(!/^[a-z0-9][a-z0-9-]{0,95}$/u.test(s))throw Uo("Assignment id is invalid.");let a=C(o,"assignments",`${s}.toon`);if(await Ru(a))throw new A("already_exists","Assignment already exists.",{id:s});let c=this.#e().toISOString(),l=ke(va,{schema_version:jh,toon_compatibility:Vn,intent_id:i.id,id:s,objective:n.objective.trim(),owner:n.owner,scope:[...n.scope],constraints:[...n.constraints??[]],exclusions:[...n.exclusions??[]],dependencies:[...n.dependencies??[]],acceptance_criteria:[...n.acceptanceCriteria],status:"pending",revision:1,invocations:[],evidence:[],remaining_risk:[],created_at:c,updated_at:c});return await qi(zn(a),{recursive:!0}),await ut(a,l),l})}async reviseAssignmentScope(e,t,r,n){let o=ke(Uu,r),i=ke(Kt,t),s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(C(s,"intent.toon"));Kn(a);let c=await this.readAssignment(e,i);if(Bt(c.revision,n),c.status==="completed")throw new A("invalid_transition","A completed Assignment cannot have its scope revised.");let l=Nh(c,this.#e,{scope:[...o.scope]});return await ut(C(s,"assignments",`${i}.toon`),l),l})}async readAssignment(e,t){let r=ke(Kt,t),n=await this.#r(e),o=await this.#t(C(n,"intent.toon")),i=C(n,"assignments");await GT(i,!0);let s=C(i,`${r}.toon`);if(!await Aa(s))throw new A("not_found","Assignment was not found.",{assignment_id:r});let a=await Iu(s,va);return YT(a,o.id,r,s),a}async listAssignments(e){let t=await this.#r(e),r=await this.#t(C(t,"intent.toon")),n=C(t,"assignments");if(!await GT(n,!0))return[];let o;try{o=await Ia(n)}catch(s){if(ge(s,"ENOENT"))return[];throw Ne(s)}return await Promise.all(o.filter((s)=>s.endsWith(".toon")).sort().map(async(s)=>{let a=C(n,s),c=await Iu(a,va),l=s.slice(0,-5);return YT(c,r.id,l,a),c}))}async startAssignment(e,t,r){let n=ke(Kt,t),o=await this.#r(e);return await this.#n(o,async()=>{let i=await this.#t(C(o,"intent.toon"));Kn(i),await this.#o(i);let s=await this.readAssignment(e,n);if(Bt(s.revision,r),s.status==="completed")throw new A("invalid_transition","A completed Assignment cannot be restarted.");if(s.status==="executing")throw new A("invalid_transition","Assignment is already executing; record its active invocation result first.",{assignment_id:s.id,...s.active_invocation_id?{invocation_id:s.active_invocation_id}:{}});let a=this.#e().toISOString(),c=JT(s),l=Nh(s,this.#e,{status:"executing",blocker:void 0,active_invocation_id:c,active_started_at:a});return await ut(C(o,"assignments",`${n}.toon`),l),l})}async recordAssignmentResult(e,t,r,n){let o=ke(ju,n),i=ke(Kt,t),s=await this.#r(e);return await this.#n(s,async()=>{let a=await this.#t(C(s,"intent.toon"));Kn(a);let c=await this.readAssignment(e,i);if(Bt(c.revision,r),c.status!=="executing")throw new A("invalid_transition",`Assignment result requires an executing Assignment; current status is ${c.status}.`,{assignment_id:c.id,status:c.status});if(c.active_invocation_id!==void 0&&o.invocationId!==void 0&&c.active_invocation_id!==o.invocationId)throw new A("invalid_transition","Assignment result does not match the active invocation.",{assignment_id:c.id,expected_invocation_id:c.active_invocation_id,actual_invocation_id:o.invocationId});if((o.outcome==="blocked"||o.outcome==="needs_root_input")&&!o.blocker?.trim())throw Uo("Blocked results require a local blocker.");let l=await this.#i(),u=[...o.evidence??[]],f=new Set(u.filter((Y)=>Y.kind==="changed_path").map((Y)=>Y.value)),d=[...f].filter((Y)=>!c.scope.some((He)=>Mh(Y,He)));if(d.length)throw new A("repository_drift","Assignment evidence declares paths outside its bounded scope.",{assignment_id:c.id,out_of_scope_paths:d.sort()});let h=(await this.listAssignments(e)).filter((Y)=>Y.id!==c.id&&Y.status==="executing"),P=l.changedPaths.filter((Y)=>h.some((He)=>He.scope.some((cn)=>Mh(Y,cn)))),x=new Set([...a.baseline.expected_changes,...f,...P]),E=l.changedPaths.filter((Y)=>!x.has(Y)),G=new Set(a.baseline.expected_changes),N=l.changedPaths.filter((Y)=>c.scope.some((He)=>Mh(Y,He))&&!G.has(Y)&&!f.has(Y)),q=l.root!==a.baseline.root||l.gitCommonDir!==a.baseline.git_common_dir,k=VT(l.statusDigest)!==a.baseline.expected_status_digest,I=[...f].some((Y)=>l.changedPaths.includes(Y)),j=P.length>0;if(q||E.length||N.length||k&&!I&&!j||l.head!==a.baseline.expected_head&&!I&&!j)throw new A("repository_drift","Repository state changed outside the recorded Assignment result.",{expected_head:a.baseline.expected_head,actual_head:l.head,unexpected_paths:[...new Set([...E,...N])].sort(),concurrent_assignments:h.map((Y)=>Y.id).sort()});let v=this.#e().toISOString(),X=c.active_invocation_id??o.invocationId??JT(c);if(c.invocations.some((Y)=>Y.id===X))throw new A("already_exists","Assignment invocation already exists.",{invocation_id:X});let ee=ke(zh,{id:X,outcome:o.outcome,started_at:c.active_started_at??o.startedAt??v,finished_at:v,summary:o.summary,evidence:u,...o.blocker?{blocker:o.blocker}:{},remaining_risk:[...o.remainingRisk??[]]}),V=Nh(c,this.#e,{status:o.outcome,invocations:[...c.invocations,ee],active_invocation_id:void 0,active_started_at:void 0,evidence:[...c.evidence,...u],blocker:o.blocker,remaining_risk:[...o.remainingRisk??[]]});await ut(C(s,"assignments",`${i}.toon`),V);let me=c.owner.role==="Worker"&&c.owner.task==="operations",nt=a.baseline.integrated_commit!==void 0&&a.baseline.integrated_commit===a.baseline.expected_head&&l.head===a.baseline.expected_head&&l.changedPaths.length===0,pt=me&&o.outcome==="failed",Ot=me&&o.outcome==="completed"&&nt&&a.state==="reviewing"&&(!a.verification.required||a.verification.status==="passed")&&(!a.review.required||a.review.status==="accepted"),Ie=Bn(a,this.#e,{baseline:Fh(l,v,a.baseline.initial_head,nt?a.baseline.integrated_commit:void 0),...Ot?{}:{state:pt?"executing":a.state,verification:ku(a.verification),review:ku(a.review),acceptance_met:!1,root_readiness:!1}});return await ut(C(s,"intent.toon"),Ie),{assignment:V,intent:Ie}})}async#l(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 Au(o,r);if(!n?.trim())throw Uo("A blocker or required input is required.");let s=Bn(t,this.#e,{state:r,blockers:[n.trim()],resume_state:o});return await ut(C(e,"intent.toon"),s),s}if(o==="blocked"||o==="needs_root_input"){if(r!==t.resume_state||t.blockers.length)throw Au(o,r)}else if(!{scoping:["ready"],ready:["executing"],executing:["verifying"],verifying:["reviewing","executing"],reviewing:["executing"]}[o]?.includes(r))throw Au(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 A("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 A("invalid_transition","Verification must pass before review.");if(r==="reviewing")await this.#o(t);let i=Bn(t,this.#e,{state:r,resume_state:void 0});return await ut(C(e,"intent.toon"),i),i}async#n(e,t){return await vu(C(e,".intent-store"),t)}async#a(e,t){if(t.state==="complete"||t.state==="abandoned")throw Au(t.state,"abandoned");let r=Bn(t,this.#e,{state:"abandoned",blockers:[]});return await ut(C(e,"intent.toon"),r),r}async#o(e){let t=await this.#i(),r=[...e.baseline.expected_changes].sort(),n=[...t.changedPaths].sort();if(t.root!==e.baseline.root||t.gitCommonDir!==e.baseline.git_common_dir||t.head!==e.baseline.expected_head||VT(t.statusDigest)!==e.baseline.expected_status_digest||r.join("\x00")!==n.join("\x00"))throw new A("repository_drift","Repository baseline no longer matches recorded assumptions.",{expected_head:e.baseline.expected_head,actual_head:t.head,expected_changes:r,actual_changes:n})}async#r(e){await this.#s();let t;try{t=await Ia(this.stateRoot)}catch(n){if(ge(n,"ENOENT"))throw new A("not_found","Intent was not found.",{reference:e});throw Ne(n)}let r=[];for(let n of t.sort()){let o=C(this.stateRoot,n);if(!await Lh(o))continue;let i=C(o,"intent.toon");if(!await Aa(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 A("current_ambiguous","Intent reference is ambiguous.",{reference:e});throw new A("not_found","Intent was not found.",{reference:e})}async#t(e){let t=await tk(e),r=nn(Pa,t);if(gt(r))return r.right;let n=nn(vM,t);if(ye(n))throw new A("schema_invalid","Persisted Intent failed schema validation.",{path:e,error:String(r.left)});let o=FM(n.right);return await ut(e,o),o}}async function XT(e){let t=await SM(e),r=async(...a)=>{try{return(await Fa("git",["-C",t,...a],{encoding:"utf8"})).stdout.trimEnd()}catch(c){throw new A("io_failure","Repository identity requires an accessible Git worktree.",{message:c instanceof Error?c.message:String(c)})}},n=await r("rev-parse","--git-common-dir"),o=await PM(t,"rev-parse","--verify","HEAD")??"unborn",i=await r("status","--porcelain=v1","--untracked-files=all"),s=i.split(`
43
+ `).filter(Boolean).map((a)=>a.slice(3).split(" -> ").at(-1)).sort();return{root:t,gitCommonDir:Pu(t,n),head:o,changedPaths:s,statusDigest:Wn(i)}}async function RM(e,t){try{let r=(await Fa("git",["-C",e,"show","-s","--format=%H%n%P",t],{encoding:"utf8"})).stdout.trim(),[n,o=""]=r.split(`
44
+ `);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 A("repository_drift","VCS integration commit could not be inspected.",{commit:t,message:r instanceof Error?r.message:String(r)})}}async function CM(e,t,r){try{let n=(await Fa("git",["-C",e,"diff","--name-only","--no-ext-diff",t,r],{encoding:"utf8"})).stdout.trim();return n?n.split(`
45
+ `).map(Dh).filter(Boolean).sort():[]}catch(n){throw new A("repository_drift","VCS integration commit tree could not be inspected.",{parent:t,commit:r,message:n instanceof Error?n.message:String(n)})}}async function PM(e,...t){try{return(await Fa("git",["-C",e,...t],{encoding:"utf8"})).stdout.trim()}catch{return}}function FM(e){return ke(Pa,{...e,schema_version:Mu,toon_compatibility:Vn,plan_required:!1,blockers:[],verification:Fu(!0),review:Fu(!0),acceptance_met:!1,root_readiness:!1,evidence:[]})}function Fu(e){return{required:e,status:e?"missing":"not_required",evidence:[]}}function ku(e){return{...e,status:e.required?"missing":"not_required"}}function Fh(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:Wn(e.statusDigest),...n===void 0?{}:{integrated_commit:n},updated_at:t}}function VT(e){return/^[a-f0-9]{64}$/u.test(e)?e:Wn(e)}function NM(e){return e.some((t)=>["check","behavior","ci"].includes(t.kind)&&["passed","observed"].includes(t.result??""))}function JT(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 Bn(e,t,r){return ke(Pa,ek({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function Nh(e,t,r){return ke(va,ek({...e,...r,revision:e.revision+1,updated_at:t().toISOString()}))}function ek(e){let t={...e};for(let[r,n]of Object.entries(t))if(n===void 0)delete t[r];return t}function MM(e){return e.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/gu,"-").replace(/^-|-$/gu,"").slice(0,48).replace(/-$/u,"")||"intent"}function Mh(e,t){let r=Dh(e),n=Dh(t).replace(/\/+$/u,"");if(!r||!n||r.startsWith("/")||n.startsWith("/")||/^[a-z]:\//u.test(r)||/^[a-z]:\//u.test(n)||r.split("/").includes("..")||n.split("/").includes(".."))return!1;return n==="."||r===n||r.startsWith(`${n}/`)}function Dh(e){return e.trim().replaceAll("\\","/").replace(/^\.\//u,"")}function Wn(e){return xM("sha256").update(e).digest("hex")}function Bt(e,t){if(t===void 0||e!==t)throw new A("stale_write","Persisted revision changed before mutation.",{expected_revision:t,actual_revision:e})}function Uo(e){return new A("invalid_input",e)}function Kn(e){if(e.state==="complete"||e.state==="abandoned")throw new A("invalid_transition","Terminal Intents cannot be mutated.",{state:e.state})}function Au(e,t){return new A("invalid_transition",`Intent cannot transition from ${e} to ${t}.`,{source:e,target:t})}function ke(e,t){let r=nn(e,t);if(ye(r))throw new A("schema_invalid","Value failed Effect Schema validation.",{error:String(r.left)});return r.right}async function tk(e){let t;try{let r=await an(e);if(r.isSymbolicLink()||!r.isFile())throw new A("schema_invalid","Persistent work state must be a regular file.",{path:e});t=await Uh(e,"utf8")}catch(r){if(ge(r,"ENOENT"))throw new A("not_found","Persistent work state was not found.",{path:e});throw Ne(r)}try{return Og(t,{strict:!0})}catch(r){throw new A("malformed_toon","Persistent work state is malformed TOON.",{path:e,message:r instanceof Error?r.message:String(r)})}}async function Iu(e,t){return ke(t,await tk(e))}async function ut(e,t){await qh(e,`${Ji(t)}
46
+ `)}async function qh(e,t){await Ui(e),await qi(zn(e),{recursive:!0}),await Ui(e);let r=C(zn(e),`.holycodex-write-${process.pid}-${crypto.randomUUID()}.tmp`);try{let n=await Nu(r,"wx",384);try{await n.writeFile(t,"utf8"),await n.sync()}finally{await n.close()}await bM(r,e),await rk(zn(e))}catch(n){throw await Ra(r,{force:!0}),Ne(n)}}async function LM(e,t){await Ui(e);try{let r=await Nu(e,"wx",256);try{await r.writeFile(t,"utf8"),await r.sync()}finally{await r.close()}await rk(zn(e))}catch(r){if(ge(r,"EEXIST"))throw new A("archive_conflict","Archived plans are immutable.",{path:e});throw Ne(r)}}async function rk(e){if(process.platform==="win32")return;try{let t=await Nu(e,"r");try{await t.sync()}finally{await t.close()}}catch(t){if(ge(t,"EINVAL")||ge(t,"ENOSYS")||ge(t,"ENOTSUP")||ge(t,"EOPNOTSUPP")||ge(t,"EISDIR"))return;throw t}}async function vu(e,t){let r=zn(e);await Ui(e),await qi(r,{recursive:!0});let n=!1;for(let a=0;a<200;a+=1)try{await qi(e),n=!0;break}catch(c){if(!ge(c,"EEXIST"))throw Ne(c);try{let l=await an(e);if(l.isSymbolicLink()||!l.isDirectory())throw new A("schema_invalid","The work-state lock must be a real directory.",{path:e});let u=await nk(e);if(u.kind==="owned"&&!await DM(u.owner.pid)){await Ra(e,{recursive:!0,force:!0});continue}if(u.kind==="missing"&&Date.now()-l.mtimeMs>kM){await Ra(e,{recursive:!0,force:!0});continue}}catch(l){if(!ge(l,"ENOENT"))throw Ne(l)}await new Promise((l)=>setTimeout(l,Math.min(5+a,50)))}if(!n)throw new A("stale_write","Another mutation is still in progress.",{lock:e});let o=C(e,".owner"),i=crypto.randomUUID(),s;try{await Ui(o),s=await Nu(o,"wx",384),await s.writeFile(`${JSON.stringify({pid:process.pid,token:i})}
47
+ `,"utf8"),await s.sync()}catch(a){if(s!==void 0)try{await s.close()}catch{}if(ge(a,"EEXIST"))throw new A("stale_write","Another mutation is still in progress.",{lock:e});throw Ne(a)}if(s===void 0)throw Ne(Error("The work-state lock owner was not opened."));try{return await t()}finally{try{await s.close()}finally{await UM(e,i)}}}async function nk(e){let t=C(e,".owner");try{let r=await an(t);if(r.isSymbolicLink()||!r.isFile())return{kind:"unknown"};let n=await Uh(t,"utf8"),o;try{o=JSON.parse(n)}catch{return{kind:"unknown"}}let i=nn(TM,o);return gt(i)?{kind:"owned",owner:i.right}:{kind:"unknown"}}catch(r){if(ge(r,"ENOENT"))return{kind:"missing"};throw Ne(r)}}async function DM(e){if(e===process.pid)return!0;if(process.platform==="win32")return await qM(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 ge(r,"EPERM")}}async function qM(e){if(!Number.isSafeInteger(e)||e>AM)return!1;try{let{stdout:t}=await Fa("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 UM(e,t){let r=await nk(e);if(r.kind!=="owned"||r.owner.token!==t)return;await Ra(e,{recursive:!0,force:!0})}async function HM(e){let t=(await Ia(e)).map((r)=>/^plan\.old-(\d{3})\.toon$/u.exec(r)?.[1]).filter((r)=>r!==void 0).map(Number);return C(e,`plan.old-${String((t.length?Math.max(...t):0)+1).padStart(3,"0")}.toon`)}async function Ru(e){try{return await _M(e),!0}catch(t){if(ge(t,"ENOENT"))return!1;throw Ne(t)}}async function Aa(e){try{let t=await an(e);return t.isFile()&&!t.isSymbolicLink()}catch(t){if(ge(t,"ENOENT")||ge(t,"ENOTDIR"))return!1;throw Ne(t)}}async function GT(e,t){try{let r=await an(e);if(r.isSymbolicLink()||!r.isDirectory())throw new A("schema_invalid","Persistent work-state directories must be real directories.",{path:e});return!0}catch(r){if(ge(r,"ENOENT")&&t)return!1;throw Ne(r)}}async function Lh(e){try{let t=await an(e);return t.isDirectory()&&!t.isSymbolicLink()}catch(t){if(ge(t,"ENOENT")||ge(t,"ENOTDIR"))return!1;throw Ne(t)}}function YT(e,t,r,n){if(e.intent_id!==t||e.id!==r)throw new A("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 Ui(e){let t=Pu(e);while(!0){try{if((await an(t)).isSymbolicLink())throw new A("schema_invalid","Persistent work state must not contain symbolic links.",{path:t})}catch(n){if(!ge(n,"ENOENT"))throw Ne(n)}let r=zn(t);if(r===t)break;t=r}}function ge(e,t){return typeof e==="object"&&e!==null&&"code"in e&&e.code===t}function Ne(e){return e instanceof A?e:new A("io_failure","Persistent work-state I/O failed.",{message:e instanceof Error?e.message:String(e)})}function jM(e,t){let r=EM(e,t);return r===""||!r.startsWith(`..${$M()}`)&&r!==".."&&!wM(r)}function $M(){return process.platform==="win32"?"\\":"/"}var ok={intent:`Usage: holycodex-agent intent <command> [options]
46
48
 
47
49
  Intent owns the durable global goal, lifecycle, baseline, blockers, gates, and readiness.
48
- Commands: create, list, current, read, select, transition, evidence, complete, abandon.
50
+ Commands: create, list, current, read, select, transition, evidence, integrate, complete, abandon.
49
51
  Reads emit validated JSON. Mutations are atomic; stale revisions and invalid transitions fail.
50
52
  `,"intent create":`Usage: holycodex-agent intent create --input <json> [--repo <path>]
51
53
 
@@ -74,6 +76,12 @@ blocked/needs_root_input require --blocker. Use intent complete for completion.
74
76
 
75
77
  Input may record evidence, verification, review, acceptanceMet, rootReadiness, clearBlockers.
76
78
  Effect: atomically updates Root-owned global proof. Review rejection returns to executing.
79
+ `,"intent integrate":`Usage: holycodex-agent intent integrate --intent <ref> --revision <n> --input <json> [--repo <path>]
80
+
81
+ Input: {"commit":40-character commit SHA}. Effect: records Root-owned integration only when
82
+ the reviewed Intent is current at that exact commit, its direct parent is the baseline HEAD,
83
+ its tree matches the expected change set, and the worktree is clean. The baseline then advances
84
+ to the clean commit so a subsequent exact-SHA Assignment can be created.
77
85
  `,"intent complete":`Usage: holycodex-agent intent complete --intent <ref> --revision <n> [--repo <path>]
78
86
 
79
87
  Output: completed Intent or completion_refused with machine-readable reasons.
@@ -92,7 +100,7 @@ Output: current validated Plan or null. No mutation.
92
100
  Input requires approach and may include scope, assignments, dependencies, architecture, risks,
93
101
  assumptions, openQuestions, verification, and recovery. Effect: archives plan.old-NNN.toon
94
102
  immutably before atomic replacement. Fails on stale Intent or Plan revision.
95
- `,assignment:`Usage: holycodex-agent assignment <create|list|read|start|result> [options]
103
+ `,assignment:`Usage: holycodex-agent assignment <create|list|read|revise|start|result> [options]
96
104
 
97
105
  Assignments are bounded specialist contracts. Their results never own global lifecycle state.
98
106
  `,"assignment create":`Usage: holycodex-agent assignment create --intent <ref> --revision <n> --input <json> [--repo <path>]
@@ -105,24 +113,32 @@ Output: validated Assignments sorted by id. No mutation.
105
113
  `,"assignment read":`Usage: holycodex-agent assignment read --intent <ref> --assignment <id> [--repo <path>]
106
114
 
107
115
  Output: one validated Assignment. No mutation.
116
+ `,"assignment revise":`Usage: holycodex-agent assignment revise --intent <ref> --assignment <id> --revision <n> --input <json> [--repo <path>]
117
+
118
+ Input requires a non-empty scope array. Effect: Root-owned reconciliation of an unfinished
119
+ Assignment's bounded repository scope; lifecycle and invocation state are preserved.
108
120
  `,"assignment start":`Usage: holycodex-agent assignment start --intent <ref> --assignment <id> --revision <n> [--repo <path>]
109
121
 
110
- Effect: marks a pending/blocked/failed Assignment executing. Completed work cannot restart.
122
+ Effect: marks a pending/blocked/failed Assignment executing and records its active invocation.
123
+ An already executing Assignment must receive its result before another start.
111
124
  `,"assignment result":`Usage: holycodex-agent assignment result --intent <ref> --assignment <id> --revision <n> --input <json> [--repo <path>]
112
125
 
113
126
  Input requires outcome and summary; supports compact invocation metadata, evidence, blocker,
114
- and remainingRisk. Effect: appends one invocation and accepts only declared repository evolution.
115
- `};function Hh(e){return QT[e.slice(0,2).join(" ")]??QT[e[0]??""]??`Usage: holycodex-agent <intent|plan|assignment> <command> [options]
127
+ and remainingRisk. Result must match the active invocation (legacy executing records may finish
128
+ without metadata). Operations success preserves accepted Intent gates for Root CI/acceptance;
129
+ operations failure returns the Intent to executing for repair. Effect: appends one invocation
130
+ and accepts only declared repository evolution.
131
+ `};function Vh(e){return ok[e.slice(0,2).join(" ")]??ok[e[0]??""]??`Usage: holycodex-agent <intent|plan|assignment> <command> [options]
116
132
 
117
133
  Deterministic model-facing work-state API. JSON responses use holycodex-agent-response-1.
118
134
  All mutations require --revision and are atomic. No command prompts or emits ANSI.
119
135
 
120
136
  Commands:
121
- intent create, list, current, read, select, transition, evidence, complete, abandon
137
+ intent create, list, current, read, select, transition, evidence, integrate, complete, abandon
122
138
  plan read, revise
123
- assignment create, list, read, start, result
139
+ assignment create, list, read, revise, start, result
124
140
 
125
141
  Use -h or --help at any command depth. Failures are classified and exit nonzero.
126
- `}function jh(e){return e.includes("-h")||e.includes("--help")||e.length===0}var XT="holycodex-agent-response-1",FM=V(le);async function NM(e=Bun.argv.slice(2),t={cwd:process.cwd(),writeStdout:(r)=>process.stdout.write(r),writeStderr:(r)=>process.stderr.write(r)}){try{let r=$h(FM,e),n=r.filter((a)=>!a.startsWith("-")).slice(0,2);if(jh(r))return t.writeStdout(Hh(n)),0;let o=LM(r),i=new Uu(o.options.repo??t.cwd??process.cwd()),s=await MM(i,o.command,o.subcommand,o.options);return t.writeStdout(`${JSON.stringify({schema_version:XT,ok:!0,operation:`${o.command}.${o.subcommand}`,data:s})}
127
- `),0}catch(r){let n=UM(r);return t.writeStderr(`${JSON.stringify({schema_version:XT,ok:!1,error:n})}
128
- `),n.code==="invalid_usage"||n.code==="invalid_input"?2:n.code==="completion_refused"?3:1}}async function MM(e,t,r,n){let o=n.intent;if(t==="intent"){if(r==="create")return await e.createIntent(va(Nu,sn(n,"input")));if(r==="list")return await e.listIntents();if(r==="current")return await e.currentIntent();if(r==="read")return await e.readIntent(St(o,"intent"));if(r==="select")return await e.selectCurrent(St(o,"intent"));if(r==="transition")return await e.transitionIntent(St(o,"intent"),$h(qi,sn(n,"state")),Bn(n),n.blocker);if(r==="evidence")return await e.recordIntentEvidence(St(o,"intent"),Bn(n),va(qu,sn(n,"input")));if(r==="abandon")return await e.abandonIntent(St(o,"intent"),Bn(n));if(r==="complete"){let i=await e.completeIntent(St(o,"intent"),Bn(n));if("completed"in i&&!i.completed)throw new $t("completion_refused","Intent completion predicates failed.",{reasons:i.reasons});return i}}if(t==="plan"){if(r==="read")return await e.readPlan(St(o,"intent"))??null;if(r==="revise")return await e.revisePlan(St(o,"intent"),va(Mu,sn(n,"input")),Bn(n),qM(n["plan-revision"]))}if(t==="assignment"){if(r==="create")return await e.createAssignment(St(o,"intent"),va(Lu,sn(n,"input")),Bn(n));if(r==="list")return await e.listAssignments(St(o,"intent"));if(r==="read")return await e.readAssignment(St(o,"intent"),sn(n,"assignment"));if(r==="start")return await e.startAssignment(St(o,"intent"),sn(n,"assignment"),Bn(n));if(r==="result")return await e.recordAssignmentResult(St(o,"intent"),sn(n,"assignment"),Bn(n),va(Du,sn(n,"input")))}throw new $t("invalid_usage","Unknown command. Use --help.")}function LM(e){let t=e[0],r=e[1];if(!t||!r||t.startsWith("-")||r.startsWith("-"))throw new $t("invalid_usage","A command and subcommand are required. Use --help.");let n={},o=DM(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 $t("invalid_usage","Options require --name value pairs.");let c=s.slice(2);if(n[c]!==void 0)throw new $t("invalid_usage",`Duplicate option --${c}.`);if(!o.has(c))throw new $t("invalid_usage",`Unknown option --${c}.`);n[c]=a}return{command:t,subcommand:r,options:n}}function DM(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 complete":["intent","revision"],"intent abandon":["intent","revision"],"plan read":["intent"],"plan revise":["intent","revision","plan-revision","input"],"assignment create":["intent","revision","input"],"assignment list":["intent"],"assignment read":["intent","assignment"],"assignment start":["intent","assignment","revision"],"assignment result":["intent","assignment","revision","input"]};return new Set([...r,...n[`${e} ${t}`]??[]])}class $t extends Error{code;details;constructor(e,t,r={}){super(t);this.code=e,this.details=r}}function va(e,t){let r;try{r=JSON.parse(t)}catch{throw new $t("invalid_input","--input must be valid JSON.")}return $h(e,r)}function $h(e,t){let r=yu(e,{onExcessProperty:"error"})(t);if(he(r))throw new $t("invalid_input","Input failed Effect Schema validation.",{issue:String(r.left)});return r.right}function sn(e,t){return St(e[t],t)}function St(e,t){if(!e)throw new $t("invalid_usage",`Missing --${t}.`);return e}function Bn(e){return ek(e.revision,"revision")}function ek(e,t){let r=Number(e);if(!Number.isSafeInteger(r)||r<1)throw new $t("invalid_input",`--${t} must be a positive integer.`);return r}function qM(e){return e===void 0?void 0:ek(e,"plan-revision")}function UM(e){if(e instanceof j||e instanceof $t)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 NM();export{Hh as agentHelp,jh as agentHelpRequested,NM as runAgentBinary};
142
+ `}function Jh(e){return e.includes("-h")||e.includes("--help")||e.length===0}var ik="holycodex-agent-response-1",BM=J(le);async function KM(e=Bun.argv.slice(2),t={cwd:process.cwd(),writeStdout:(r)=>process.stdout.write(r),writeStderr:(r)=>process.stderr.write(r)}){try{let r=Gh(BM,e),n=r.filter((a)=>!a.startsWith("-")).slice(0,2);if(Jh(r))return t.writeStdout(Vh(n)),0;let o=zM(r),i=new Bu(o.options.repo??t.cwd??process.cwd()),s=await WM(i,o.command,o.subcommand,o.options);return t.writeStdout(`${JSON.stringify({schema_version:ik,ok:!0,operation:`${o.command}.${o.subcommand}`,data:s})}
143
+ `),0}catch(r){let n=GM(r);return t.writeStderr(`${JSON.stringify({schema_version:ik,ok:!1,error:n})}
144
+ `),n.code==="invalid_usage"||n.code==="invalid_input"?2:n.code==="completion_refused"?3:1}}async function WM(e,t,r,n){let o=n.intent;if(t==="intent"){if(r==="create")return await e.createIntent(jo(Lu,Wt(n,"input")));if(r==="list")return await e.listIntents();if(r==="current")return await e.currentIntent();if(r==="read")return await e.readIntent(rt(o,"intent"));if(r==="select")return await e.selectCurrent(rt(o,"intent"));if(r==="transition")return await e.transitionIntent(rt(o,"intent"),Gh(Hi,Wt(n,"state")),kr(n),n.blocker);if(r==="evidence")return await e.recordIntentEvidence(rt(o,"intent"),kr(n),jo($u,Wt(n,"input")));if(r==="integrate")return await e.recordVcsIntegration(rt(o,"intent"),kr(n),jo(Hu,Wt(n,"input")));if(r==="abandon")return await e.abandonIntent(rt(o,"intent"),kr(n));if(r==="complete"){let i=await e.completeIntent(rt(o,"intent"),kr(n));if("completed"in i&&!i.completed)throw new zt("completion_refused","Intent completion predicates failed.",{reasons:i.reasons});return i}}if(t==="plan"){if(r==="read")return await e.readPlan(rt(o,"intent"))??null;if(r==="revise")return await e.revisePlan(rt(o,"intent"),jo(Du,Wt(n,"input")),kr(n),JM(n["plan-revision"]))}if(t==="assignment"){if(r==="create")return await e.createAssignment(rt(o,"intent"),jo(qu,Wt(n,"input")),kr(n));if(r==="revise")return await e.reviseAssignmentScope(rt(o,"intent"),Wt(n,"assignment"),jo(Uu,Wt(n,"input")),kr(n));if(r==="list")return await e.listAssignments(rt(o,"intent"));if(r==="read")return await e.readAssignment(rt(o,"intent"),Wt(n,"assignment"));if(r==="start")return await e.startAssignment(rt(o,"intent"),Wt(n,"assignment"),kr(n));if(r==="result")return await e.recordAssignmentResult(rt(o,"intent"),Wt(n,"assignment"),kr(n),jo(ju,Wt(n,"input")))}throw new zt("invalid_usage","Unknown command. Use --help.")}function zM(e){let t=e[0],r=e[1];if(!t||!r||t.startsWith("-")||r.startsWith("-"))throw new zt("invalid_usage","A command and subcommand are required. Use --help.");let n={},o=VM(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 zt("invalid_usage","Options require --name value pairs.");let c=s.slice(2);if(n[c]!==void 0)throw new zt("invalid_usage",`Duplicate option --${c}.`);if(!o.has(c))throw new zt("invalid_usage",`Unknown option --${c}.`);n[c]=a}return{command:t,subcommand:r,options:n}}function VM(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 list":["intent"],"assignment read":["intent","assignment"],"assignment start":["intent","assignment","revision"],"assignment result":["intent","assignment","revision","input"]};return new Set([...r,...n[`${e} ${t}`]??[]])}class zt extends Error{code;details;constructor(e,t,r={}){super(t);this.code=e,this.details=r}}function jo(e,t){let r;try{r=JSON.parse(t)}catch{throw new zt("invalid_input","--input must be valid JSON.")}return Gh(e,r)}function Gh(e,t){let r=bu(e,{onExcessProperty:"error"})(t);if(ye(r))throw new zt("invalid_input","Input failed Effect Schema validation.",{issue:String(r.left)});return r.right}function Wt(e,t){return rt(e[t],t)}function rt(e,t){if(!e)throw new zt("invalid_usage",`Missing --${t}.`);return e}function kr(e){return sk(e.revision,"revision")}function sk(e,t){let r=Number(e);if(!Number.isSafeInteger(r)||r<1)throw new zt("invalid_input",`--${t} must be a positive integer.`);return r}function JM(e){return e===void 0?void 0:sk(e,"plan-revision")}function GM(e){if(e instanceof A||e instanceof zt)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 KM();export{Vh as agentHelp,Jh as agentHelpRequested,KM as runAgentBinary};