@seanmozeik/tripwire 0.7.2 → 0.9.0

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 (46) hide show
  1. package/README.md +20 -2
  2. package/dist/index.js +22 -27
  3. package/dist/tripwire-cli.js +1 -1
  4. package/dist/tripwire-hook.js +1 -1
  5. package/dist/tripwire-pi.js +16 -6
  6. package/dist/tripwire.js +109 -121
  7. package/dist/types/dispatch.d.ts +4 -2
  8. package/dist/types/index.d.ts +1 -1
  9. package/dist/types/lib/bash/analyze.d.ts +3 -0
  10. package/dist/types/lib/bash/carriers.d.ts +11 -0
  11. package/dist/types/lib/bash/config.d.ts +17 -0
  12. package/dist/types/lib/bash/execution-types.d.ts +13 -0
  13. package/dist/types/lib/bash/execution.d.ts +13 -0
  14. package/dist/types/lib/bash/index.d.ts +8 -0
  15. package/dist/types/lib/bash/pipeline-inputs.d.ts +10 -0
  16. package/dist/types/lib/bash/static-command.d.ts +9 -0
  17. package/dist/types/lib/bash/types.d.ts +64 -0
  18. package/dist/types/lib/bash/values.d.ts +25 -0
  19. package/dist/types/lib/bash/wrappers.d.ts +21 -0
  20. package/dist/types/lib/code/analyze.d.ts +3 -0
  21. package/dist/types/lib/code/calls.d.ts +8 -0
  22. package/dist/types/lib/code/carriers.d.ts +18 -0
  23. package/dist/types/lib/code/containers.d.ts +4 -0
  24. package/dist/types/lib/code/control.d.ts +13 -0
  25. package/dist/types/lib/code/data.d.ts +9 -0
  26. package/dist/types/lib/code/imports.d.ts +5 -0
  27. package/dist/types/lib/code/members.d.ts +4 -0
  28. package/dist/types/lib/code/syntax.d.ts +10 -0
  29. package/dist/types/lib/code/types.d.ts +51 -0
  30. package/dist/types/lib/code/uv.d.ts +13 -0
  31. package/dist/types/lib/code/values.d.ts +9 -0
  32. package/dist/types/lib/config.d.ts +32 -0
  33. package/dist/types/lib/event.d.ts +7 -1
  34. package/dist/types/lib/rule-actions.d.ts +27 -0
  35. package/dist/types/rules/bash-bypass.d.ts +5 -0
  36. package/dist/types/rules/bash-deny.d.ts +4 -4
  37. package/dist/types/rules/bash-git.d.ts +2 -2
  38. package/dist/types/rules/bash-network-install.d.ts +2 -2
  39. package/dist/types/rules/bash-redirect.d.ts +2 -2
  40. package/dist/types/rules/bash-scoped-rm.d.ts +2 -2
  41. package/dist/types/rules/bash-tar-explosion.d.ts +2 -2
  42. package/dist/types/rules/config-custom.d.ts +3 -3
  43. package/dist/types/rules/embedded-code.d.ts +15 -0
  44. package/dist/types/rules/tool-policy.d.ts +2 -2
  45. package/package.json +11 -8
  46. package/dist/types/lib/bash.d.ts +0 -27
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var a=(e)=>{let n=e?.trim();return n===void 0||n.length===0?void 0:n},c=()=>({bunExecutable:a(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:a(process.env.TRIPWIRE_PACKAGE_DIST)}),s=(e)=>({...process.env,TRIPWIRE_PACKAGE_DIST:e});import{accessSync as p,constants as f,realpathSync as u}from"fs";import{createRequire as g}from"module";import m from"path";import{fileURLToPath as b}from"url";var v=["@seanmozeik","tripwire-darwin-arm64"].join("/"),R=(e)=>{try{return p(e,f.X_OK),u(e)}catch{return}},E=(e,n)=>{try{let r=n?.()??g(e).resolve(v);return R(r)}catch{return}},h=(e)=>{let n=b(e),r=n;try{r=u(n)}catch{}return m.join(m.dirname(r),"tripwire.js")},l=(e={})=>{let n=e.moduleUrl??import.meta.url,r=e.platform??process.platform,i=e.architecture??process.arch,t=c();if(!t.forcePortable&&r==="darwin"&&i==="arm64"){let o=E(n,e.nativeResolver);if(o!==void 0)return{arguments:[],executable:o,kind:"native"}}return{arguments:[e.portableExecutable??h(n)],executable:e.bunExecutable??t.bunExecutable??"bun",kind:"portable"}};var d=(e)=>{let n=l({moduleUrl:import.meta.url}),r=e==="hook"?"--tripwire-hook":"--tripwire-force-cli",i=import.meta.dirname,t=Bun.spawnSync([n.executable,...n.arguments,r,...process.argv.slice(2)],{stderr:"inherit",env:s(i),stdin:"inherit",stdout:"inherit"});process.exit(t.exitCode)};d("cli");
3
+ var a=(e)=>{let n=e?.trim();return n===void 0||n.length===0?void 0:n},s=()=>({bunExecutable:a(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:a(process.env.TRIPWIRE_PACKAGE_DIST)}),c=(e)=>({...process.env,TRIPWIRE_PACKAGE_DIST:e});import{accessSync as p,constants as f,realpathSync as u}from"fs";import{createRequire as g}from"module";import m from"path";import{fileURLToPath as b}from"url";var v=["@seanmozeik","tripwire-darwin-arm64"].join("/"),R=(e)=>{try{return p(e,f.X_OK),u(e)}catch{return}},E=(e,n)=>{try{let r=n?.()??g(e).resolve(v);return R(r)}catch{return}},h=(e)=>{let n=b(e),r=n;try{r=u(n)}catch{}return m.join(m.dirname(r),"tripwire.js")},d=(e={})=>{let n=e.moduleUrl??import.meta.url,r=e.platform??process.platform,i=e.architecture??process.arch,t=s();if(!t.forcePortable&&r==="darwin"&&i==="arm64"){let o=E(n,e.nativeResolver);if(o!==void 0)return{arguments:[],executable:o,kind:"native"}}return{arguments:[e.portableExecutable??h(n)],executable:e.bunExecutable??t.bunExecutable??"bun",kind:"portable"}};var l=(e)=>{let n=d({moduleUrl:import.meta.url}),r=e==="hook"?"--tripwire-hook":"--tripwire-force-cli",i=import.meta.dirname,t=Bun.spawnSync([n.executable,...n.arguments,r,...process.argv.slice(2)],{stderr:"inherit",env:c(i),stdin:"inherit",stdout:"inherit"});process.exit(t.exitCode)};l("cli");
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var a=(e)=>{let n=e?.trim();return n===void 0||n.length===0?void 0:n},s=()=>({bunExecutable:a(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:a(process.env.TRIPWIRE_PACKAGE_DIST)}),c=(e)=>({...process.env,TRIPWIRE_PACKAGE_DIST:e});import{accessSync as p,constants as f,realpathSync as u}from"fs";import{createRequire as g}from"module";import m from"path";import{fileURLToPath as b}from"url";var v=["@seanmozeik","tripwire-darwin-arm64"].join("/"),R=(e)=>{try{return p(e,f.X_OK),u(e)}catch{return}},h=(e,n)=>{try{let r=n?.()??g(e).resolve(v);return R(r)}catch{return}},E=(e)=>{let n=b(e),r=n;try{r=u(n)}catch{}return m.join(m.dirname(r),"tripwire.js")},d=(e={})=>{let n=e.moduleUrl??import.meta.url,r=e.platform??process.platform,o=e.architecture??process.arch,t=s();if(!t.forcePortable&&r==="darwin"&&o==="arm64"){let i=h(n,e.nativeResolver);if(i!==void 0)return{arguments:[],executable:i,kind:"native"}}return{arguments:[e.portableExecutable??E(n)],executable:e.bunExecutable??t.bunExecutable??"bun",kind:"portable"}};var l=(e)=>{let n=d({moduleUrl:import.meta.url}),r=e==="hook"?"--tripwire-hook":"--tripwire-force-cli",o=import.meta.dirname,t=Bun.spawnSync([n.executable,...n.arguments,r,...process.argv.slice(2)],{stderr:"inherit",env:c(o),stdin:"inherit",stdout:"inherit"});process.exit(t.exitCode)};l("hook");
3
+ var a=(e)=>{let n=e?.trim();return n===void 0||n.length===0?void 0:n},s=()=>({bunExecutable:a(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:a(process.env.TRIPWIRE_PACKAGE_DIST)}),c=(e)=>({...process.env,TRIPWIRE_PACKAGE_DIST:e});import{accessSync as p,constants as f,realpathSync as u}from"fs";import{createRequire as g}from"module";import m from"path";import{fileURLToPath as b}from"url";var v=["@seanmozeik","tripwire-darwin-arm64"].join("/"),R=(e)=>{try{return p(e,f.X_OK),u(e)}catch{return}},E=(e,n)=>{try{let r=n?.()??g(e).resolve(v);return R(r)}catch{return}},h=(e)=>{let n=b(e),r=n;try{r=u(n)}catch{}return m.join(m.dirname(r),"tripwire.js")},d=(e={})=>{let n=e.moduleUrl??import.meta.url,r=e.platform??process.platform,o=e.architecture??process.arch,t=s();if(!t.forcePortable&&r==="darwin"&&o==="arm64"){let i=E(n,e.nativeResolver);if(i!==void 0)return{arguments:[],executable:i,kind:"native"}}return{arguments:[e.portableExecutable??h(n)],executable:e.bunExecutable??t.bunExecutable??"bun",kind:"portable"}};var l=(e)=>{let n=d({moduleUrl:import.meta.url}),r=e==="hook"?"--tripwire-hook":"--tripwire-force-cli",o=import.meta.dirname,t=Bun.spawnSync([n.executable,...n.arguments,r,...process.argv.slice(2)],{stderr:"inherit",env:c(o),stdin:"inherit",stdout:"inherit"});process.exit(t.exitCode)};l("hook");
@@ -1,6 +1,16 @@
1
- import{spawn as F}from"node:child_process";import{once as H}from"node:events";import{realpathSync as z}from"node:fs";import{fileURLToPath as W,pathToFileURL as K}from"node:url";import{accessSync as A,constants as L,realpathSync as E}from"node:fs";import{createRequire as U}from"node:module";import T from"node:path";import{fileURLToPath as O}from"node:url";var R=(e)=>{let n=e?.trim();return n===void 0||n.length===0?void 0:n},P=()=>({bunExecutable:R(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:R(process.env.TRIPWIRE_PACKAGE_DIST)});var N=["@seanmozeik","tripwire-darwin-arm64"].join("/"),D=(e)=>{try{return A(e,L.X_OK),E(e)}catch{return}},M=(e,n)=>{try{let t=n?.()??U(e).resolve(N);return D(t)}catch{return}},j=(e)=>{let n=O(e),t=n;try{t=E(n)}catch{}return T.join(T.dirname(t),"tripwire.js")},x=(e={})=>{let n=e.moduleUrl??import.meta.url,t=e.platform??process.platform,o=e.architecture??process.arch,r=P();if(!r.forcePortable&&t==="darwin"&&o==="arm64"){let s=M(n,e.nativeResolver);if(s!==void 0)return{arguments:[],executable:s,kind:"native"}}return{arguments:[e.portableExecutable??j(n)],executable:e.bunExecutable??r.bunExecutable??"bun",kind:"portable"}};var b=60000,B=(e=import.meta.url)=>{let n=W(e),t=n;try{t=z(n)}catch{}return x({moduleUrl:K(t)})},J=B(),m=(e,n,t)=>{for(let o of n){let r=e[o];if(typeof r==="string")return r}throw Error(`Pi ${t} is missing`)},G=(e,n)=>{let t=e[n];return Array.isArray(t)?t.filter((o)=>typeof o==="string"):[]},q=(e)=>{let{edits:n}=e;if(Array.isArray(n)){let t=[],o=[];for(let r of n){if(!f(r))continue;let s=a(r,"oldText")??a(r,"old_string"),i=a(r,"newText")??a(r,"new_string");if(s!==void 0)t.push(s);if(i!==void 0)o.push(i)}return{old_string:t.join(`
2
- `),new_string:o.join(`
3
- `)}}return{old_string:a(e,"oldText")??a(e,"old_string")??"",new_string:a(e,"newText")??a(e,"new_string")??a(e,"input")??a(e,"_input")??""}},V=(e)=>{let n=/^\*{3}\s+(?:Add|Update|Delete)\s+File\s*:\s*(?<path>\S.*?)\s*$/,t=/^\*{3}\s+Move\s+to\s*:\s*(?<path>\S.*?)\s*$/,o=new Map,r=[],s="*** Begin Patch",i="*** End Patch",l=e.split(/\r?\n/),u=l.findIndex((d)=>d.trim()===s);if(u===-1)return[];let c=l.slice(u+1),C=[...c,i].findIndex((d)=>d.trim()===i),I=c.slice(0,C),w=(d)=>{if(r.push(d),!o.has(d))o.set(d,{newLines:[],oldLines:[]})};for(let d of I){let h=n.exec(d)?.groups?.path?.trim();if(h!==void 0&&h.length>0){r=[],w(h);continue}if(r.length===0)continue;let y=t.exec(d)?.groups?.path?.trim();if(y!==void 0&&y.length>0){w(y);continue}let p;if(d.startsWith("+"))p="newLines";else if(d.startsWith("-"))p="oldLines";if(p!==void 0)for(let S of r)o.get(S)?.[p].push(d.slice(1))}return[...o].map(([d,g])=>({file_path:d,new_string:g.newLines.join(`
4
- `),old_string:g.oldLines.join(`
5
- `)}))},X=(e)=>{let{input:n,toolName:t}=e;if(t==="bash"||t==="powershell")return[{command:m(n,["command"],`${t} command`)}];if(t==="read")return[{file_path:m(n,["path","file_path"],"read path")}];if(t==="write")return[{content:m(n,["content"],"write content"),file_path:m(n,["path","file_path"],"write path")}];if(t==="edit"){let o=V(a(n,"input")??"");if(o.length>0)return o;let r=a(n,"path")??a(n,"file_path"),i=G(n,"paths");if(i.length===0&&r!==void 0)i=[r];if(i.length===0)throw Error("Pi edit path is missing");let l=q(n),u=[];for(let c of i)u.push({file_path:c,...l});return u}return[n]},Q=(e)=>{if(typeof e==="string")return e;if(!Array.isArray(e))return"";let n=[];for(let t of e)if(f(t)&&t.type==="text"&&typeof t.text==="string")n.push(t.text);return n.join(`
6
- `)},Y=(e)=>{let n=Q(e.content);if(e.toolName==="bash"||e.toolName==="powershell")return{stdout:n,stderr:e.isError?n:"",interrupted:e.isError};if(e.toolName==="read")return{content:n};return{content:n,details:e.details,isError:e.isError}},k=(e,n,t)=>{let o={cwd:t,hook_event_name:n,tool_name:e.toolName,tool_use_id:e.toolCallId};if("content"in e)return[{...o,tool_input:e.input,tool_response:Y(e)}];let r=[];for(let s of X(e))r.push({...o,tool_input:s});return r},v=async(e)=>{e.setEncoding("utf8");let n="";for await(let t of e)n+=String(t);return n},Z=async(e,n)=>{let t=F(e.executable,[...e.arguments,"--tripwire-hook"],{stdio:["pipe","pipe","pipe"]}),o={timedOut:!1},r=setTimeout(()=>{o.timedOut=!0,t.kill("SIGKILL")},b);t.stdin.end(JSON.stringify(n));try{let[s,i,l]=await Promise.all([H(t,"close"),v(t.stdout),v(t.stderr)]);if(o.timedOut)throw Error(`Tripwire exceeded its ${b}ms timeout`);return{exitCode:typeof s[0]==="number"?s[0]:1,stderr:l,stdout:i}}finally{clearTimeout(r)}},f=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),a=(e,n)=>{let t=e[n];return typeof t==="string"?t:void 0},_=(e)=>{if(e.exitCode!==0)return e.stderr.trim()||`Tripwire exited ${e.exitCode}`;if(e.stdout.trim().length===0)return"Tripwire returned no decision";try{let n=JSON.parse(e.stdout);if(!f(n))return"Tripwire returned invalid JSON";let t=f(n.hookSpecificOutput)?n.hookSpecificOutput:void 0,o=(t===void 0?void 0:a(t,"permissionDecision"))??a(n,"permissionDecision")??a(n,"permission"),r=(t===void 0?void 0:a(t,"permissionDecisionReason"))??a(n,"permissionDecisionReason")??a(n,"reason")??"Blocked by Tripwire";if(o==="deny"||o==="ask")return r;if(a(n,"decision")==="block"||n.continue===!1)return r;return n.continue===!0||o==="allow"?void 0:"Tripwire returned an unrecognized response"}catch{return"Tripwire returned invalid JSON"}},ee=(e,n=Z)=>{let t=typeof e==="string"?{arguments:[],executable:e,kind:"native"}:e;return(o)=>{o.on("tool_call",async(r,s)=>{try{let i=k(r,"PreToolUse",s.cwd),l=i.length===1?i[0]:i;if(l===void 0)throw Error("Tripwire could not normalize the Pi tool call");let u=_(await n(t,l));if(u!==void 0)return{block:!0,reason:u};return{}}catch(i){return{block:!0,reason:`Tripwire failed closed: ${i instanceof Error?i.message:String(i)}`}}}),o.on("tool_result",async(r,s)=>{try{let[i]=k(r,"PostToolUse",s.cwd);if(i===void 0)throw Error("Tripwire could not normalize the Pi tool result");let l=_(await n(t,i));if(l!==void 0)s.ui.notify(`Tripwire stopped the session: ${l}`,"error"),s.abort()}catch(i){s.ui.notify(`Tripwire failed closed after tool use: ${i instanceof Error?i.message:String(i)}`,"error"),s.abort()}})}},fe=ee(J);export{ee as createTripwirePiExtension,fe as default,k as hookInputs,B as resolveShippedHookCommand,_ as tripwirePiDenialReason};
1
+ import{spawn as Yl}from"node:child_process";import{once as Xl}from"node:events";import{realpathSync as Ql}from"node:fs";import{fileURLToPath as ef,pathToFileURL as tf}from"node:url";var se=(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}}},dc={pipe(){return se(this,arguments)}},Et=function(){function e(){}return e.prototype=dc,e}();var b=function(e,t){if(typeof e==="function")return function(){return e(arguments)?t.apply(this,arguments):(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(s){return t(s,r,n)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let r=arguments;return function(n){return t(n,...r)}}}};var V=(e)=>e;var zo=(e)=>()=>e;var Qe=zo(void 0),Go=Qe;function Re(e){let t=new WeakMap;return(r)=>{let n=t.get(r);if(n!==void 0)return n;let o=e(r);return t.set(r,o),o}}function bt(e){let t=new WeakMap;return(r)=>{let n=t.get(r);if(n!==void 0)return n;let o=e(r);return t.set(r,o),t.set(o,o),o}}var wt=(e)=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;if(e instanceof Error)t.delete("stack");let r=Object.getPrototypeOf(e),n=r;while(n!==null&&n!==Object.prototype){let o=Reflect.ownKeys(n);for(let s=0;s<o.length;s++)t.add(o[s]);n=Object.getPrototypeOf(n)}if(t.has("constructor")&&typeof e.constructor==="function"&&r===e.constructor.prototype)t.delete("constructor");return t},It=new WeakSet;function vt(e){return typeof e==="string"}function cn(e){return typeof e==="number"}function Ho(e){return typeof e==="boolean"}function Wo(e){return typeof e==="symbol"}function Vo(e){return vt(e)||cn(e)||Wo(e)}function Ot(e){return typeof e==="function"}function un(e){return e!==void 0}function Zo(e){return e!=null}function Yo(e){return!0}function ur(e){return typeof e==="object"&&e!==null||Ot(e)}var O=b(2,(e,t)=>ur(e)&&(t in e));var J="~effect/interfaces/Hash",k=(e)=>{switch(typeof e){case"number":return dr(e);case"bigint":return M(e.toString(10));case"boolean":return M(String(e));case"symbol":return M(String(e));case"string":return M(e);case"undefined":return M("undefined");case"function":case"object":if(e===null)return M("null");else if(e instanceof Date){if(Number.isNaN(e.getTime()))return M("Invalid Date");return M(e.toISOString())}else if(e instanceof RegExp)return M(e.toString());else{if(It.has(e))return lr(e);if(fn.has(e))return fn.get(e);let t=Sc(e,()=>{if(mc(e))return e[J]();else if(typeof e==="function")return lr(e);else if(e instanceof DataView)return fr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e)||ArrayBuffer.isView(e))return fr(e);else if(e instanceof Map)return xc(e);else if(e instanceof Set)return gc(e);return hc(e)});return fn.set(e,t),t}default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},lr=(e)=>{if(!ln.has(e))ln.set(e,dr(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)));return ln.get(e)},Z=b(2,(e,t)=>e*53^t),pr=(e)=>e&3221225471|e>>>1&1073741824,mc=(e)=>O(e,J),dr=(e)=>{if(e!==e)return M("NaN");if(e===1/0)return M("Infinity");if(e===-1/0)return M("-Infinity");let t=e|0;if(t!==e)t^=e*4294967295;while(e>4294967295)t^=e/=4294967295;return pr(t)},M=(e)=>{let t=5381,r=e.length;while(r)t=t*33^e.charCodeAt(--r);return pr(t)},dn=(e,t)=>{let r=12289;for(let n of t)r^=Z(k(n),k(e[n]));return pr(r)},hc=(e)=>dn(e,wt(e)),mn=(e,t)=>(r)=>{let n=e;for(let o of r)n^=t(o);return pr(n)},fr=mn(6151,k),xc=mn(M("Map"),([e,t])=>Z(k(e),k(t))),gc=mn(M("Set"),k),ln=new WeakMap,fn=new WeakMap,pn=new WeakSet;function Sc(e,t){if(pn.has(e))return M("[Circular]");pn.add(e);let r=t();return pn.delete(e),r}var K="~effect/interfaces/Equal";function q(){if(arguments.length===1)return(e)=>$e(e,arguments[0]);return $e(arguments[0],arguments[1])}function $e(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let r=typeof e;if(r!==typeof t)return!1;if(r==="number"&&e!==e&&t!==t)return!0;if(r!=="object"&&r!=="function")return!1;if(It.has(e)||It.has(t))return!1;return Ec(e,t,Tc)}function yc(e,t,r){let n=hn.has(e),o=xn.has(t);if(n&&o)return!0;if(n||o)return!1;hn.add(e),xn.add(t);let s=r();return hn.delete(e),xn.delete(t),s}var hn=new WeakSet,xn=new WeakSet;function Tc(e,t){if(k(e)!==k(t))return!1;else if(e instanceof Date){if(!(t instanceof Date))return!1;let s=e.getTime(),a=t.getTime();return s===a||Number.isNaN(s)&&Number.isNaN(a)}else if(e instanceof RegExp){if(!(t instanceof RegExp))return!1;return e.toString()===t.toString()}let r=Qo(e),n=Qo(t);if(r!==n)return!1;let o=r&&n;if(typeof e==="function"&&!o)return!1;return yc(e,t,()=>{if(o)return e[K](t);else if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;return bc(e,t)}else if(ArrayBuffer.isView(e)){let s=e instanceof DataView;if(!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||s!==t instanceof DataView)return!1;if(s){let a=t;return Xo(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(a.buffer,a.byteOffset,a.byteLength))}return Xo(e,t)}else if(e instanceof Map){if(!(t instanceof Map)||e.size!==t.size)return!1;return vc(e,t)}else if(e instanceof Set){if(!(t instanceof Set)||e.size!==t.size)return!1;return kc(e,t)}return wc(e,t)})}function Ec(e,t,r){let n=mr.get(e);if(!n)n=new WeakMap,mr.set(e,n);else if(n.has(t))return n.get(t);let o=r(e,t);n.set(t,o);let s=mr.get(t);if(!s)s=new WeakMap,mr.set(t,s);return s.set(e,o),o}var mr=new WeakMap;function bc(e,t){for(let r=0;r<e.length;r++)if(!$e(e[r],t[r]))return!1;return!0}function Xo(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function wc(e,t){let r=wt(e),n=wt(t);if(r.size!==n.size)return!1;for(let o of r)if(!n.has(o)||!$e(e[o],t[o]))return!1;return!0}function Ic(e,t){return function(n,o){let s=Array.from(o);for(let[a,c]of n){let l=!1;for(let i=0;i<s.length;i++){let[h,x]=s[i];if(e(a,h)&&t(c,x)){s[i]=s[s.length-1],s.pop(),l=!0;break}}if(!l)return!1}return!0}}var vc=Ic($e,$e);function Oc(e){return function(r,n){let o=Array.from(n);for(let s of r){let a=!1;for(let c=0;c<o.length;c++){let l=o[c];if(e(s,l)){o[c]=o[o.length-1],o.pop(),a=!0;break}}if(!a)return!1}return!0}}var kc=Oc($e),Qo=(e)=>O(e,K);var hr=Symbol.for("~effect/Redactable"),Cc=(e)=>O(e,hr);function xr(e){if(Cc(e))return gn(e);return e}function gn(e){return e[hr](globalThis[tt]?.context??Rc)}var tt="~effect/Fiber/currentFiber",es=new Map,Rc={"~effect/Context":{},base:es,depth:0,mapUnsafe:es,pipe(){return se(this,arguments)}};function F(e,t){let r=t?.space??0,n=new WeakSet,o=!r?"":typeof r==="number"?" ".repeat(r):r,s=(i)=>o.repeat(i),a=(i,h)=>{let x=i?.constructor;return x&&x!==Object.prototype.constructor&&x.name?`${x.name}(${h})`:h},c=(i)=>{try{return Reflect.ownKeys(i)}catch{return["[ownKeys threw]"]}};function l(i,h=0){if(typeof i==="string")return JSON.stringify(i);if(typeof i==="number"||i==null||typeof i==="boolean"||typeof i==="symbol")return String(i);if(typeof i==="bigint")return String(i)+"n";if(typeof i==="object"||typeof i==="function"){if(n.has(i))return _c;n.add(i);let x;if(hr in i)x=l(gn(i),h);else if(Array.isArray(i))x=!o||i.length<=1?`[${i.map((m)=>l(m,h)).join(",")}]`:`[
2
+ ${s(h+1)}${i.map((m)=>l(m,h+1)).join(`,
3
+ `+s(h+1))}
4
+ ${s(h)}]`;else if(i instanceof Date)x=Ac(i);else if(!t?.ignoreToString&&O(i,"toString")&&typeof i.toString==="function"&&i.toString!==Object.prototype.toString&&i.toString!==Array.prototype.toString){let m=Fc(i);x=i instanceof Error&&i.cause?`${m} (cause: ${l(i.cause,h)})`:m}else if(Symbol.iterator in i)x=`${i.constructor.name}(${l(Array.from(i),h)})`;else{let m=c(i);if(!o||m.length<=1){let p=`{${m.map((d)=>`${rt(d)}:${l(i[d],h)}`).join(",")}}`;x=a(i,p)}else{let p=`{
5
+ ${m.map((d)=>`${s(h+1)}${rt(d)}: ${l(i[d],h+1)}`).join(`,
6
+ `)}
7
+ ${s(h)}}`;x=a(i,p)}}return n.delete(i),x}return String(i)}return l(e,0)}var _c="[Circular]";function rt(e){return typeof e==="string"?JSON.stringify(e):String(e)}function ts(e){return e.map((t)=>`[${rt(t)}]`).join("")}function Ac(e){try{return e.toISOString()}catch{return"Invalid Date"}}function Fc(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}var Ct=Symbol.for("nodejs.util.inspect.custom"),Be=(e)=>{try{if(e=xr(e),O(e,"toJSON")&&Ot(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(Be);return e}catch{return"[toJSON threw]"}};var Pf={toJSON(){return Be(this)},[Ct](){return this.toJSON()},toString(){return F(this.toJSON())}};class _e{called=!1;self;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}[Symbol.iterator](){return new _e(this.self)}}var Pc=()=>{let t={["~effect/Utils/internal"]:(o)=>o()},r={["~effect/Utils/internal"]:(o)=>{try{return o()}finally{}}};return t["~effect/Utils/internal"](()=>Error().stack)?.includes("~effect/Utils/internal")===!0?t["~effect/Utils/internal"]:r["~effect/Utils/internal"]},he=Pc();function Ae(e,t,r){if(t==="__proto__")Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0});else e[t]=r}function rs(e,t){for(let r of Reflect.ownKeys(t))if(Object.prototype.propertyIsEnumerable.call(t,r))Ae(e,r,t[r])}var qe="~effect/Effect",je="~effect/Exit",Dc={_A:V,_E:V,_R:V},ss=`${qe}/identifier`,S=`${qe}/args`,P=`${qe}/evaluate`,X=`${qe}/successCont`,ue=`${qe}/failureCont`,Fe=`${qe}/ensureCont`,Je=Symbol.for("effect/Effect/Yield"),Ke={pipe(){return se(this,arguments)},toJSON(){return{...this}},toString(){return F(this.toJSON(),{ignoreToString:!0,space:2})},[Ct](){return this.toJSON()}},qf={[J](){return dn(this,Object.keys(this))},[K](e){let t=Object.keys(this),r=Object.keys(e);if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==r[n]||!q(this[t[n]],e[t[n]]))return!1;return!0}},Uc={[qe]:Dc,...Ke,[Symbol.iterator](){return new _e(this)},toJSON(){return{_id:"Effect",op:this[ss],...S in this?{args:this[S]}:void 0}}};var as=(e)=>O(e,je),Rt="~effect/Cause",gr="~effect/Cause/Reason",Sr=(e)=>O(e,Rt);class Pe{[Rt];reasons;constructor(e){this[Rt]=Rt,this.reasons=e}pipe(){return se(this,arguments)}toJSON(){return{_id:"Cause",failures:this.reasons.map((e)=>e.toJSON())}}toString(){return`Cause(${F(this.reasons)})`}[Ct](){return this.toJSON()}[K](e){return Sr(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,r)=>q(t,e.reasons[r]))}[J](){return fr(this.reasons)}}var os=new WeakMap;class _t{[gr];annotations;_tag;constructor(e,t,r){if(this[gr]=gr,this._tag=e,t!==At&&typeof r==="object"&&r!==null&&t.size>0){let n=os.get(r);if(n)t=new Map([...n,...t]);os.set(r,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let r=new Map(this.annotations);e.mapUnsafe.forEach((o,s)=>{if(t?.overwrite!==!0&&r.has(s))return;r.set(s,o)});let n=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return n.annotations=r,n}pipe(){return se(this,arguments)}toString(){return F(this)}[Ct](){return this.toString()}}var At=new Map;class Ft extends _t{error;constructor(e,t=At){super("Fail",t,e);this.error=e}toString(){return`Fail(${F(this.error)})`}toJSON(){return{_tag:"Fail",error:this.error}}[K](e){return Ut(e)&&q(this.error,e.error)&&q(this.annotations,e.annotations)}[J](){return Z(M(this._tag))(Z(k(this.error))(k(this.annotations)))}}var Pt=(e)=>new Pe(e);var is=(e)=>new Pe([new Ft(e)]);class yn extends _t{defect;constructor(e,t=At){super("Die",t,e);this.defect=e}toString(){return`Die(${F(this.defect)})`}toJSON(){return{_tag:"Die",defect:this.defect}}[K](e){return Tn(e)&&q(this.defect,e.defect)&&q(this.annotations,e.annotations)}[J](){return Z(M(this._tag))(Z(k(this.defect))(k(this.annotations)))}}var cs=(e)=>new Pe([new yn(e)]),Dt=b((e)=>Sr(e[0]),(e,t,r)=>{if(t.mapUnsafe.size===0)return e;return new Pe(e.reasons.map((n)=>n.annotate(t,r)))}),Ut=(e)=>e._tag==="Fail",Tn=(e)=>e._tag==="Die",yr=(e)=>e._tag==="Interrupt";function Mc(e){return De("Effect.evaluate: Not implemented")}var Te=(e)=>({...Uc,[ss]:e.op,[P]:e[P]??Mc,[X]:e[X],[ue]:e[ue],[Fe]:e[Fe]}),ae=(e)=>{let t=Te(e);return function(){let r=Object.create(t);return r[S]=e.single===!1?arguments:arguments[0],r}},us=(e)=>{let t={[je]:je,_tag:e.op,get[e.prop](){return this[S]},...Te(e),toString(){return`${e.op}(${F(this[S])})`},toJSON(){return{_id:"Exit",_tag:e.op,[e.prop]:this[S]}},[K](r){return as(r)&&r._tag===this._tag&&q(this[S],r[S])},[J](){return Z(M(e.op),k(this[S]))}};return function(r){let n=Object.create(t);return n[S]=r,n}},te=us({op:"Success",prop:"value",[P](e){let t=e.getCont(X);return t?t[X](this[S],e,this):e.yieldWith(this)}}),En={key:"effect/Cause/StackTrace"},ls={key:"effect/Cause/InterruptorStackTrace"},le=us({op:"Failure",prop:"cause",[P](e){let t=this[S],r=!1;if(e.currentStackFrame)t=Dt(t,{mapUnsafe:new Map([[En.key,e.currentStackFrame]])}),r=!0;let n=e.getCont(ue);while(e.interruptible&&e._interruptedCause&&n)n=e.getCont(ue);return n?n[ue](t,e,r?void 0:this):e.yieldWith(r?le(t):this)}}),nt=(e)=>le(is(e)),De=(e)=>le(cs(e)),ot=ae({op:"WithFiber",[P](e){return this[S](e)}}),Nc=function(){class e extends globalThis.Error{}let t=Te({op:"YieldableError",[P](){return nt(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),fs=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return class extends Nc{constructor(r){super(r?.message,r?.cause?{cause:r.cause}:void 0);if(r)rs(this,r),Object.defineProperty(this,e,{value:r,enumerable:!1})}toJSON(){return{...this[e],...this}}}}(),Mt=(e)=>{class t extends fs{_tag=e}return t.prototype.name=e,t};var Sn="~effect/Cause/Done";var Jf={[Sn]:Sn,_tag:"Done",value:void 0};var ps="~effect/data/Option",ds={[ps]:{_A:(e)=>e},...Ke,[Symbol.iterator](){return new _e(this)}},Lc=Object.defineProperty(Object.assign(Object.create(ds),{_tag:"Some",_op:"Some",[K](e){return wn(e)&&vn(e)&&q(this.value,e.value)},[J](){return Z(k(this._tag))(k(this.value))},toString(){return`some(${F(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:Be(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),$c=k("None"),Bc=Object.assign(Object.create(ds),{_tag:"None",_op:"None",valueOrUndefined:void 0,[K](e){return wn(e)&&In(e)},[J](){return $c},toString(){return"none()"},toJSON(){return{_id:"Option",_tag:this._tag}}}),wn=(e)=>O(e,ps),In=(e)=>e._tag==="None",vn=(e)=>e._tag==="Some",ms=Object.create(Bc),hs=(e)=>{let t=Object.create(Lc);return t.value=e,t};var xs="~effect/data/Result",gs={[xs]:{_A:(e)=>e,_E:(e)=>e},...Ke,[Symbol.iterator](){return new _e(this)}},qc=Object.assign(Object.create(gs),{_tag:"Success",_op:"Success",[K](e){return On(e)&&Ss(e)&&q(this.success,e.success)},[J](){return Z(k(this._tag))(k(this.success))},toString(){return`success(${F(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:Be(this.success)}}}),Jc=Object.assign(Object.create(gs),{_tag:"Failure",_op:"Failure",[K](e){return On(e)&&kn(e)&&q(this.failure,e.failure)},[J](){return Z(k(this._tag))(k(this.failure))},toString(){return`failure(${F(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:Be(this.failure)}}}),On=(e)=>O(e,xs),kn=(e)=>e._tag==="Failure",Ss=(e)=>e._tag==="Success",ys=(e)=>{let t=Object.create(Jc);return t.failure=e,t},Ts=(e)=>{let t=Object.create(qc);return t.success=e,t};var ze=Ts,xe=ys;var st=kn;var Es=b(2,(e,t)=>st(e)?xe(t(e.failure)):e);var Tr=b(2,(e,{onFailure:t,onSuccess:r})=>st(e)?t(e.failure):r(e.success));var Cn=(e)=>e.length>0;var Ee=()=>ms,ge=hs;var Nt=In,Rn=vn;var _n=b(2,(e,t)=>Nt(e)?Ee():ge(t(e.value)));var bs=b(2,(e,t)=>Nt(e)?Ee():t(e.value)?ge(e.value):Ee());var An=globalThis.Array;var it=(e)=>An.isArray(e)?e:An.from(e);var Fn=b(2,(e,t)=>[...e,t]),Hc=b(2,(e,t)=>it(e).concat(it(t)));var ip=An.isArray;var Pn=Cn,br=Cn;var Wc=(e,t)=>{let r=k(t),n=e.get(r);if(n===void 0)return e.set(r,[t]),!0;for(let o of n)if(q(o,t))return!1;return n.push(t),!0};var ws=b(2,(e,t)=>{let r=it(e),n=it(t);if(br(r))return br(n)?Vc(Hc(r,n)):r;return n});var wr=()=>[];var Is=b(2,(e,t)=>e.map(t));var Vc=(e)=>{let t=it(e);if(t.length<2)return[...t];let r=new Map,n=[];for(let o of t)if(Wc(r,o))n.push(o);return n};var vs=(e)=>Te({op:e.label,[P]:e.evaluate});var Os="~effect/Context/Service",ks=function(){function e(){}let t=e;Object.setPrototypeOf(t,Yc);let r=(n,o)=>{if(t.key=n,o?.defaultValue)t[Mn]=Mn,t.defaultValue=o.defaultValue;if(o?.make)t.make=o.make;if(o?.fiberCached)Cs.add(n);return t};return arguments.length>0?r(arguments[0],arguments[1]):r},Yc={[Os]:Os,...vs({label:"Service",evaluate(e){return te(Lt(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of(e){return e},context(e){return Bn(this,e)},use(e){return ot((t)=>e(Lt(t.context,this)))},useSync(e){return ot((t)=>te(e(Lt(t.context,this))))}},Cs=new Set,Mn="~effect/Context/Reference",Rs="~effect/Context",Xc=8,Qc=8,Nn=(e,t,r,n)=>{let o=Object.create(eu);return o.cacheRoot=e??o,o.base=t,o.overlay=r,o.depth=n,o._flat=void 0,o.baseHits=0,o},_s=(e,t)=>{if(!t)return;_s(e,t.parent),e.set(t.key,t.value)},As=(e)=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return _s(t,e.overlay),e._flat=t};var Ln=Symbol(),Fs=(e,t)=>{let r=e;for(let o=r.overlay;o;o=o.parent)if(o.key===t)return o.value;let n=r.base.get(t);if(n===void 0&&!r.base.has(t))return Ln;if(r.overlay&&++r.baseHits>=Qc)r.base=As(r),r.overlay=void 0,r.depth=0;return n},Ir=(e)=>Nn(void 0,e,void 0,0),eu={get mapUnsafe(){return As(this)},...Ke,[Rs]:{_Services:(e)=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[K](e){if(!tu(e))return!1;let t=this.mapUnsafe,r=e.mapUnsafe;if(t.size!==r.size)return!1;for(let[n,o]of t)if(!r.has(n)||!q(o,r.get(n)))return!1;return!0},[J](){return dr(this.mapUnsafe.size)}},Ps=(e,t)=>e.cacheRoot===t.cacheRoot,tu=(e)=>O(e,Rs);var ru=(e)=>!!e[Mn],$n=()=>nu,nu=Ir(new Map),Bn=(e,t)=>Ir(new Map([[e.key,t]])),Ds=b(3,(e,t,r)=>ou(e,t.key,r)),ou=(e,t,r)=>{let n=e,o=Cs.has(t)?void 0:n.cacheRoot;if(n.depth>=Xc){let s=new Map(n.mapUnsafe);return s.set(t,r),Nn(o,s,void 0,0)}return Nn(o,n.base,{key:t,value:r,parent:n.overlay},n.depth+1)};var vr=(e,t)=>{let r=Fs(e,t);return r===Ln?void 0:r},Us=b(2,(e,t)=>{let r=Fs(e,t.key);if(r===Ln){if(ru(t))return su(t);throw au(t)}return r}),Lt=Us,Un="~effect/Context/defaultValue",su=(e)=>{if(Un in e)return e[Un];return e[Un]=e.defaultValue()},au=(e)=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:""}`);if(t.stack){let r=t.stack.split(`
8
+ `);r.splice(1,3),t.stack=r.join(`
9
+ `)}return t};var be=ks;var qn=be("effect/Scheduler",{fiberCached:!0,defaultValue:()=>new Or}),Ms="setImmediate"in globalThis?(e)=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:(e)=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},iu=(e)=>{let t=!1;return Promise.resolve().then(()=>{if(!t)e()}),()=>{t=!0}};class Ns{buckets=[];scheduleTask(e,t){let r=this.buckets,n=r.length,o,s=0;for(;s<n;s++){if(r[s][0]>t)break;o=r[s]}if(o&&o[0]===t)o[1].push(e);else if(s===n)r.push([t,[e]]);else r.splice(s,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}}class Or{executionMode;setImmediate;constructor(e="async",t){this.executionMode=e,this.setImmediate=t??(e==="sync"?iu:Ms)}shouldYield(e){return e.currentOpCount>=e.maxOpsBeforeYield}makeDispatcher(){return new Ls(this.setImmediate)}}class Ls{tasks=new Ns;running=void 0;setImmediate;constructor(e=Ms){this.setImmediate=e}scheduleTask(e,t){if(this.tasks.scheduleTask(e,t),this.running===void 0)this.running=this.setImmediate(this.afterScheduled)}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let r=e[t][1];for(let n=0;n<r.length;n++)r[n]()}}flush(){while(this.tasks.buckets.length>0){if(this.running!==void 0)this.running(),this.running=void 0;this.runTasks()}}}var $s=be("effect/Scheduler/MaxOpsBeforeYield",{fiberCached:!0,defaultValue:()=>2048}),Bs=be("effect/Scheduler/PreventSchedulerYield",{fiberCached:!0,defaultValue:()=>!1});var kr=Mt;var qs="~effect/encoding/EncodingError";class Rr extends kr("EncodingError"){[qs]=qs}var _r=(e)=>typeof e==="string"?Js(uu.encode(e)):Js(e),Ar=(e)=>{let t=lu(e),r=t.length;if(r%4!==0)return xe(new Rr({kind:"Decode",module:"Base64",input:t,message:`Length must be a multiple of 4, but is ${r}`}));let n=t.indexOf("=");if(n!==-1&&(n<r-2||n===r-2&&t[r-1]!=="="))return xe(new Rr({kind:"Decode",module:"Base64",input:t,message:"Found a '=' character, but it is not at the end"}));try{let o=t.endsWith("==")?2:t.endsWith("=")?1:0,s=new Uint8Array(3*(r/4)-o);for(let a=0,c=0;a<r;a+=4,c+=3){let l=Cr(t.charCodeAt(a))<<18|Cr(t.charCodeAt(a+1))<<12|Cr(t.charCodeAt(a+2))<<6|Cr(t.charCodeAt(a+3));s[c]=l>>16,s[c+1]=l>>8&255,s[c+2]=l&255}return ze(s)}catch(o){return xe(new Rr({kind:"Decode",module:"Base64",input:t,message:o instanceof Error?o.message:"Invalid input"}))}};var uu=new TextEncoder;var lu=(e)=>e.replace(/[\n\r]/g,""),Js=(e)=>{let t=e.length,r="",n;for(n=2;n<t;n+=3)r+=we[e[n-2]>>2],r+=we[(e[n-2]&3)<<4|e[n-1]>>4],r+=we[(e[n-1]&15)<<2|e[n]>>6],r+=we[e[n]&63];if(n===t+1)r+=we[e[n-2]>>2],r+=we[(e[n-2]&3)<<4],r+="==";if(n===t)r+=we[e[n-2]>>2],r+=we[(e[n-2]&3)<<4|e[n-1]>>4],r+=we[(e[n-1]&15)<<2],r+="=";return r};function Cr(e){if(e>=Ks.length)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);let t=Ks[e];if(t===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return t}var we=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"],Ks=[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,62,255,255,255,63,52,53,54,55,56,57,58,59,60,61,255,255,255,0,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255,255,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51];var fu=[];for(let e=0;e<256;e++)fu.push(e.toString(16).padStart(2,"0"));var Gs="effect/Tracer/ParentSpan";var Hs="effect/Tracer";var Ws="effect/observability/Metric/FiberRuntimeMetricsKey";var Vs=be("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:Qe});var Zs=be("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),Ys=be("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"});var hu=()=>{let e=Object.getOwnPropertyDescriptor(Error,"stackTraceLimit");if(e===void 0)return Object.isExtensible(Error);return Object.hasOwn(e,"writable")?e.writable===!0:e.set!==void 0},xu=hu(),Xs=()=>Error.stackTraceLimit,Jn=(e)=>{if(xu)Error.stackTraceLimit=e};class oa extends _t{fiberId;constructor(e,t=At){super("Interrupt",t,"Interrupted");this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:"Interrupt",fiberId:this.fiberId}}[K](e){return yr(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[J](){return Z(M(`${this._tag}:${this.fiberId}`))(lr(this.annotations))}}var sa=(e)=>new Pe([new oa(e)]);var Gn=(e)=>{for(let t=0;t<e.reasons.length;t++){let r=e.reasons[t];if(r._tag==="Fail")return ze(r.error)}return xe(e)};var aa=(e)=>e.reasons.some(yr);var Hn=b(2,(e,t)=>{if(e.reasons.length===0)return t;else if(t.reasons.length===0)return e;let r=new Pe(ws(e.reasons,t.reasons));return q(e,r)?e:r}),ia=b(2,(e,t)=>{let r=!1,n=e.reasons.map((o)=>{if(Ut(o))return r=!0,new Ft(t(o.error),o.annotations);return o});return r?Pt(n):e});var Qs="~effect/Fiber",Eu={_A:V,_E:V},bu={id:0},wu=()=>globalThis[tt];class Wn{constructor(e,t=!0){this[Qs]=Eu,this.setContext(e),this.id=++bu.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=[],this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._running=!1,this._deferredInterrupt=!1,this.runtimeMetrics?.recordFiberStart(this.context)}[Qs];id;interruptible;currentOpCount;_stack;_observers;_exit;_children;_interruptedCause;_yielded;_running;_deferredInterrupt;context;currentScheduler;currentTracerContext;currentSpan;currentLogLevel;minimumLogLevel;currentStackFrame;runtimeMetrics;maxOpsBeforeYield;currentPreventYield;_dispatcher=void 0;get currentDispatcher(){return this._dispatcher??=this.currentScheduler.makeDispatcher()}getRef(e){return Lt(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),Go;return this._observers.push(e),()=>{if(this._exit)return;let t=this._observers.indexOf(e);if(t>=0)this._observers.splice(t,1)}}interruptUnsafe(e,t){if(this._exit)return;let r=sa(e);if(this.currentStackFrame)r=Dt(r,Bn(En,this.currentStackFrame));if(t)r=Dt(r,t);if(this._interruptedCause=this._interruptedCause?Hn(this._interruptedCause,r):r,this.interruptible)if(this._running)this._deferredInterrupt=!0;else this.evaluate(fe(this._interruptedCause))}pollUnsafe(){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===Je)return;let r=ea.interruptChildren&&ea.interruptChildren(this);if(r!==void 0)return this.evaluate(ne(r,()=>t));this._exit=t,this.runtimeMetrics?.recordFiberEnd(this.context,this._exit);for(let n=0;n<this._observers.length;n++)this._observers[n](t);this._observers.length=0,this._stack.length=0,this._children=void 0,this.context=$n()}runLoop(e){let t=globalThis[tt];globalThis[tt]=this;let r=this._running;this._running=!0;let n=!1,o=e;this.currentOpCount=0;try{while(!0){if(this._deferredInterrupt)this._deferredInterrupt=!1,o=fe(this._interruptedCause);if(this.currentOpCount++,!n&&!this.currentPreventYield&&this.currentScheduler.shouldYield(this)){n=!0;let s=o;o=ne(pa,()=>s)}if(o=this.currentTracerContext?this.currentTracerContext(o,this):o[P](this),o===Je){let s=this._yielded;if(je in s)return this._deferredInterrupt=!1,this._yielded=void 0,s;else if(this._deferredInterrupt){this._yielded=void 0,s();continue}return Je}}}catch(s){if(!O(o,P))return De(`Fiber.runLoop: Not a valid effect: ${String(o)}`);return this.runLoop(De(s))}finally{this._running=r,globalThis[tt]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,Iu;while(!0){let t=this._stack.pop();if(!t)return;let r=t[Fe]&&t[Fe](this);if(r)return r[e]=r,r;if(t[e])return t}}yieldWith(e){return this._yielded=e,Je}children(){return this._children??=new Set}pipe(){return se(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Ps(t,e))return;let r=this.getRef(qn);if(r!==this.currentScheduler)this.currentScheduler=r,this._dispatcher=void 0;this.currentSpan=vr(e,Gs),this.currentLogLevel=this.getRef(Zs),this.minimumLogLevel=this.getRef(Ys),this.currentStackFrame=this.getRef(Vs),this.maxOpsBeforeYield=this.getRef($s),this.currentPreventYield=this.getRef(Bs),this.runtimeMetrics=vr(e,Ws);let n=vr(e,Hs);this.currentTracerContext=n?n.context:void 0}get currentSpanLocal(){return this.currentSpan?._tag==="Span"?this.currentSpan:void 0}}var Iu={[X](e,t){return fe(t._interruptedCause)},[ue](e,t){return fe(t._interruptedCause)}},ea={interruptChildren:void 0},ca=(e)=>{if(!e.currentStackFrame)return;let t=new Map;return t.set(ls.key,e.currentStackFrame),Ir(t)};var vu=(e)=>Vn((t)=>{let r=e[Symbol.iterator](),n=[],o=void 0;function s(){let a=r.next();while(!a.done){if(a.value._exit){n.push(a.value._exit),a=r.next();continue}o=a.value.addObserver((c)=>{n.push(c),s()});return}t(re(n))}return s(),ua(()=>o?.())});var ta=(e)=>ot((t)=>{let r=ca(t),n=wr();for(let o of e)o.interruptUnsafe(t.id,r),n.push(o);return Ta(vu(n))});var re=te,fe=le,ct=nt,ua=ae({op:"Sync",[P](e){let t=this[S](),r=e.getCont(X);return r?r[X](t,e):e.yieldWith(te(t))}}),He=ae({op:"Suspend",[P](e){return this[S]()}});var la=Tr({onFailure:ct,onSuccess:re});var fa=ae({op:"Yield",[P](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{if(t)return;e.evaluate(Ie)},this[S]??0),e.yieldWith(()=>{t=!0})}}),pa=fa(0);var da=re(Ee());var ma=(e)=>He(()=>fe(he(e))),Fr=(e)=>De(e),ha=(e)=>He(()=>ct(he(e))),$t=re(void 0);var xa=(e)=>{let t=typeof e==="function"?e:e.try,r=typeof e==="function"?(n)=>new Dr(n,"An error occurred in Effect.try"):e.catch;return He(()=>{try{return re(he(t))}catch(n){return ct(he(()=>r(n)))}})};var ga=(e)=>{let t=typeof e==="function"?e:e.try,r=typeof e==="function"?(n)=>new Dr(n,"An error occurred in Effect.tryPromise"):e.catch;return Sa(function(n,o){let s=(a)=>{try{n(ct(he(()=>r(a))))}catch(c){n(Fr(c))}};try{he(()=>t(o)).then((a)=>n(re(a)),s)}catch(a){s(a)}},t.length!==0)};var Sa=ae({op:"Async",single:!1,[P](e){let t=he(()=>this[S][0].bind(e.currentScheduler)),r=!1,n=!1,o=this[S][1]?new AbortController:void 0,s=t((a)=>{if(r)return;if(r=!0,n)e.evaluate(a);else n=a},o?.signal);if(n!==!1)return n;if(n=!0,e._yielded=()=>{r=!0},o===void 0&&s===void 0)return Je;return e._stack.push(Ou(()=>(r=!0,o?.abort(),s??Ie))),Je}}),Ou=ae({op:"AsyncFinalizer",[Fe](e){if(e.interruptible)e.interruptible=!1,e._stack.push(Xn)},[ue](e,t){return aa(e)?ne(this[S](),()=>fe(e)):fe(e)}}),Vn=(e)=>Sa(e,e.length>=2);var ku=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0});var ya=(e,...t)=>ku(e.length,t.length===0?function(){return ra(()=>e.apply(this,arguments))}:function(){let r=ra(()=>e.apply(this,arguments));for(let n of t)r=n(r);return r}),ra=(e)=>{try{let t=e(),r=void 0;while(!0){let n=t.next(r);if(n.done)return re(n.value);let o=n.value;if(o&&o._tag==="Success"){r=o.value;continue}else if(o&&o._tag==="Failure")return n.value;else{let s=!0;return He(()=>{if(s)return s=!1,ne(n.value,(a)=>na(t,a));else return He(()=>na(e()))})}}}catch(t){return Fr(t)}},na=ae({op:"Iterator",single:!1,[X](e,t){let r=this[S][0];while(!0){let n=r.next(e);if(n.done)return re(n.value);if(!N(n.value))return t._stack.push(this),n.value;else if(n.value._tag==="Failure")return n.value;e=n.value.value}},[P](e){return this[X](this[S][1],e)}});var Ta=(e)=>ne(e,(t)=>Ie);var ne=b(2,(e,t)=>{let r=Object.create(Cu);return r[S]=e,r[X]=t.length!==1?(n)=>t(n):t,r}),Cu=Te({op:"OnSuccess",[P](e){return e._stack.push(this),this[S]}});var N=(e)=>(je in e),Ea=b(2,(e,t)=>{if(N(e))return e._tag==="Success"?t(e.value):e;return ne(e,t)});var ba=b(2,(e,t)=>ne(e,(r)=>re(he(()=>t(r))))),wa=b(2,(e,t)=>N(e)?va(e,t):ba(e,t)),Ia=b(2,(e,t)=>N(e)?Oa(e,t):Ra(e,t));var Zn=(e)=>e._tag==="Success";var Ie=te(void 0),va=b(2,(e,t)=>e._tag==="Success"?te(t(e.value)):e),Oa=b(2,(e,t)=>{if(e._tag==="Success")return e;let r=Gn(e.cause);if(st(r))return e;return nt(t(r.success))});var Pr=b(2,(e,t)=>{let r=Object.create(Ru);return r[S]=e,r[ue]=t.length!==1?(n)=>t(n):t,r}),Ru=Te({op:"OnFailure",[P](e){return e._stack.push(this),this[S]}});var ka=b(3,(e,t,r)=>Pr(e,(n)=>{let o=t(n);return st(o)?fe(o.failure):he(()=>r(o.success,n))})),Ca=b(2,(e,t)=>ka(e,Gn,(r)=>t(r)));var Ra=b(2,(e,t)=>Ca(e,(r)=>ha(()=>t(r))));var Kp=Te({op:"OnSuccessAndFailure",[P](e){return e._stack.push(this),this[S]}});var Yn=(e)=>N(e)?te(e):_u(e),_u=ae({op:"Exit",[P](e){return e._stack.push(this),this[S]},[X](e,t,r){return re(r??te(e))},[ue](e,t,r){return re(r??le(e))}});var Au=(e,t)=>Zn(e)?t:Pr(t,(r)=>fe(Hn(e.cause,r)));var Fu=ae({op:"OnExit",single:!1,[P](e){return e._stack.push(this),this[S][0]},[Fe](e){if(e.interruptible&&this[S][2]!==!0)e._stack.push(Xn),e.interruptible=!1},[X](e,t,r){r??=te(e);let n=this[S][1](r);return n?ne(n,(o)=>r):r},[ue](e,t,r){r??=le(e);let n=this[S][1](r);return n?ne(Au(r,n),(o)=>r):r}});var _a=(e)=>ot((t)=>{if(!t.interruptible)return e;return t.interruptible=!1,t._stack.push(Xn),e}),Pu=ae({op:"SetInterruptible",[Fe](e){if(e.interruptible=this[S],e._interruptedCause&&e.interruptible)return()=>fe(e._interruptedCause)}}),Xn=Pu(!0);var Du=ae({op:"While",[X](e,t){if(this[S].step(e),this[S].while())return t._stack.push(this),this[S].body();return Ie},[P](e){if(this[S].while())return e._stack.push(this),this[S].body();return Ie}});var Uu=(e)=>{let{onItem:t,step:r}=e,n=(o,s,a,c)=>{for(;a<c;a++){let l=s[a],i=t(o,l,a);if(!N(i))return ne(Yn(i),(x)=>r(o,l,x,a)??n(o,s,a+1,c)??$t);let h=r(o,l,i,a);if(h)return h._tag==="Failure"?h:void 0}};return(o,s,a)=>{let c=0,l=a?.end??s.length,i=a?.concurrency??1;if(i===1)return n(o,s,0,l);let h=a?.orderedStep===!0,x=!1,m,p,d,E=!1,u,f,g=c,y=h?Array(l):void 0,T=(U)=>{let C=De(U);return u=C,x=!0,E=!0,p&&p.size>0?ne(_a(ta(Array.from(p))),()=>C):C},B=(U,C,H)=>{if(!h)return r(o,U,C,H);if(u)return u;y[H]=C;while(g<l){let I=y[g];if(I===void 0)return;y[g]=void 0;let v=g++,_=r(o,s[v],I,v);if(_)return _}},D=()=>{let U=!1;for(;!u&&c<l;c++){let C=s[c],H=f??t(o,C,c);if(N(H)){if(u=B(C,H,c),u)break}else if(!m)return Vn((I)=>{m=wu(),p=new Set,f=H,d=I;let v;try{v=D()}catch(_){return I(T(_))}if(v)return I(v);return He(()=>(u=Ie,E=!0,p?ta(p):$t))});else{f=void 0;let I=Mu(m,H,!0,!0,"inherit");if(I._exit){if(u=B(C,I._exit,c),u)break;continue}p.add(I);let v=c;if(I.addObserver((_)=>{p.delete(I);try{if(u){if(!E&&_._tag==="Failure")for(let A of _.cause.reasons)if(A._tag==="Interrupt")continue;else if(u._tag==="Failure")u.cause.reasons.push(A);else u=le(Pt([A]))}else{let A=B(C,_,v);if(A)u=A._tag==="Failure"?le(Pt(A.cause.reasons.slice())):A,D()}if(U){let A=D();if(A)d(A)}else if(x&&p.size===0)d(u??$t)}catch(A){d(T(A))}}),p.size<i)continue;U=!0,c++;return}}if(x=!0,u){if(p&&p.size>0){let C=ca(m);p.forEach((H)=>H.interruptUnsafe(m.id,C));return}if(d||u._tag==="Failure")return u}else if(d){if(!p)return Ie;else if(p.size===0)d($t)}};return D()}},Bt=()=>Uu;var Mu=(e,t,r=!1,n=!1,o=!1)=>{let s=e,a=o==="inherit"?s.interruptible:!o,c=new Wn(s.context,a);if(r)c.evaluate(t);else s.currentDispatcher.scheduleTask(()=>c.evaluate(t),0);if(!n&&!c._exit)s.children().add(c),c.addObserver(()=>s._children.delete(c));return c};var Aa=(e)=>(t,r)=>{let n=new Wn(r?.scheduler?Ds(e,qn,r.scheduler):e,r?.uninterruptible!==!0);if(n.evaluate(t),n._exit)return n;if(r?.signal)if(r.signal.aborted)n.interruptUnsafe();else{let o=()=>n.interruptUnsafe();r.signal.addEventListener("abort",o,{once:!0}),n.addObserver(()=>r.signal.removeEventListener("abort",o))}if(r?.onFiberStart)r.onFiberStart(n);return n};var Fa=(e)=>{let t=Aa(e);return(r)=>{if(N(r))return r;let n=new Or("sync"),o=t(r,{scheduler:n});return o._dispatcher?.flush(),o._exit??De(new Qn(o))}},Pa=Fa($n());var Kn="~effect/Cause/AsyncFiberError";class Qn extends Mt("AsyncFiberError"){[Kn]=Kn;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}var zn="~effect/Cause/UnknownError";class Dr extends Mt("UnknownError"){[zn]=zn;constructor(e,t){super({message:t,cause:e})}}var Nu="~effect/Logger",zp={[Nu]:{_Message:V,_Output:V},pipe(){return se(this,arguments)}};var Ge={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},Gp={None:[],All:[],Trace:[Ge.gray],Debug:[Ge.blue],Info:[Ge.green],Warn:[Ge.yellow],Error:[Ge.red],Fatal:[Ge.bgBrightRed,Ge.black]};var Da=Ut;var Ur=ia;var Ua=te,ro=le,ut=nt;var lt=Ie;var Mr=Zn;var Ma=ga,L=re,oo=da;var R=ct;var so=ma,Na=Fr,ao=xa;var La=la;var ve=ne;var jt=Yn;var qt=Pr;var Jt=Pa;var ft=wa,io=Ia;var ie=Ea;var co=ya;function $a(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}var Ba="~structural";var ja="~sentinels",qa="~constructor";var Nr=Re((e)=>{let t=$a(e)?.identifier;if(typeof t==="string")return t;return e.getExpected(Nr)});var w=Symbol();var pe=Ua,Oe=pe(w),z=pe(w),Lr=(e)=>e===w?Ee():ge(e),uo=(e)=>e._tag==="None"?Oe:pe(e.value);var Gt="~effect/SchemaIssue/Issue";function po(e){return O(e,Gt)&&e[Gt]===Gt}function Lu(e){return Object.hasOwn(e,"input")}class de{[Gt]=Gt;constructor(e,t){if(t?.reportInput===!0&&e!==w)this.input=e}}class mo extends de{_tag="Filter";filter;issue;constructor(e,t,r,n){super(r,n);this.filter=e,this.issue=t}}class ho extends de{_tag="Encoding";ast;issue;constructor(e,t,r,n){super(r,n);this.ast=e,this.issue=t}}class Se extends de{_tag="Pointer";path;issue;constructor(e,t){super();this.path=e,this.issue=t}}class Vt extends de{_tag="MissingKey";annotations;constructor(e){super();this.annotations=e}}class Br extends de{_tag="UnexpectedKey";ast;constructor(e,t,r){super(t,r);this.ast=e}}class G extends de{_tag="Composite";ast;issues;constructor(e,t,r,n){super(r,n);this.ast=e,this.issues=t}}class ke extends de{_tag="InvalidType";ast;constructor(e,t,r){super(t,r);this.ast=e}}class Y extends de{_tag="InvalidValue";annotations;constructor(e,t,r){super(t,r);this.annotations=e}}class Zt extends de{_tag="AnyOf";ast;issues;constructor(e,t,r,n){super(r,n);this.ast=e,this.issues=t}}class xo extends de{_tag="OneOf";ast;successes;constructor(e,t,r,n){super(r,n);this.ast=e,this.successes=t}}function fo(e,t,r){if(po(e))return e;if(typeof e==="string")return new Y({message:e},t,r);let n=typeof e.issue==="string"?new Y({message:e.issue},t,r):e.issue;return new Se(e.path,n)}function Ka(e,t,r){if(e===void 0)return;if(typeof e==="boolean")return e?void 0:new Y(void 0,t,r);return fo(e,t,r)}function za(e,t,r,n){if(Array.isArray(t)){if(!br(t))return;return t.length===1?fo(t[0],r,n):new G(e,Is(t,(o)=>fo(o,r,n)),r,n)}return Ka(t,r,n)}var $u=(e)=>{let t=Wt(e);if(t!==void 0)return t;switch(e._tag){case"InvalidType":return Ht(Nr(e.ast),e);case"InvalidValue":{let r=Ga(e);if(r!==void 0)return Ht(r,e);let n=$r(e);return n===void 0?"Expected a valid value":`Invalid data ${n}`}case"MissingKey":return"Missing key";case"UnexpectedKey":{let r=$r(e);return r===void 0?"Expected no excess property":`Unexpected key with value ${r}`}case"Forbidden":return"Forbidden operation";case"OneOf":{let r=$r(e);return r===void 0?"Expected exactly one member to match":`Expected exactly one member to match the input ${r}`}}},Bu=(e)=>Wt(e.issue)??Wt(e);function $r(e){return Lu(e)?F(e.input):void 0}function Ga(e){let t=e.annotations?.expected;return typeof t==="string"?t:void 0}function Ht(e,t){let r=$r(t);return r===void 0?`Expected ${e}`:`Expected ${e}, got ${r}`}function Ha(e){let t=e.annotations?.expected;if(typeof t==="string")return t;switch(e._tag){case"Filter":return"<filter>";case"FilterGroup":return e.checks.map((r)=>Ha(r)).join(" & ")}}function ju(){return(e)=>zt(e,"")}var Wa=ju();function zt(e,t){let r;switch(e._tag){case"Filter":{let n=Bu(e);if(n!==void 0)r=n;else{if(e.issue._tag!=="InvalidValue")return zt(e.issue,t);let o=Ga(e.issue);r=o===void 0?Ht(Ha(e.filter),e):Ht(o,e.issue)}break}case"Encoding":return zt(e.issue,t);case"Pointer":return zt(e.issue,t+ts(e.path));case"Composite":case"AnyOf":{if(e._tag==="Composite"||e.issues.length>0)return e.issues.map((n)=>zt(n,t)).join(`
10
+ `);r=Wt(e)??Ht(Nr(e.ast),e);break}default:r=$u(e);break}return t?`${r}
11
+ at ${t}`:r}function Wt(e){if(e._tag==="Pointer")return;if(e._tag==="Encoding")return Wt(e.issue);let r=(e._tag==="Filter"?e.filter.annotations:("annotations"in e)?e.annotations:e.ast.annotations)?.[e._tag==="MissingKey"?"messageMissingKey":e._tag==="UnexpectedKey"?"messageUnexpectedKey":"message"];if(typeof r==="string")return r}function Yt(e){let t;for(let r of e.reasons){if(!Da(r)||!po(r.error))return;t??=r.error}return t}function jr(e,t){let r=Yt(e);if(r===void 0)throw Error(t,{cause:e});return r}class We extends Et{run;constructor(e){super();this.run=e}map(e){return new We((t,r)=>this.run(t,r).pipe(ft(_n(e))))}compose(e){if(Za(this))return e;if(Za(e))return this;return new We((t,r)=>this.run(t,r).pipe(ie((n)=>e.run(n,r))))}}var Ya=new We(L);function Za(e){return e.run===Ya.run}function dt(){return Ya}function Ju(e){return new We((t,r)=>Nt(t)?oo:e(t.value,r))}function oe(e){return Xa(_n(e))}function Xt(e){return Ju((t,r)=>e(t,r).pipe(ft(ge)))}function Xa(e){return new We((t)=>L(e(t)))}function go(e){return new We((t)=>{let r=bs(t,un);return Rn(r)?L(r):ft(e,ge)})}function qr(){return oe(globalThis.String)}function Jr(){return oe(globalThis.Number)}function Qa(){return oe(_r)}function ei(){return Xt((e,t)=>io(La(Ar(e)),()=>new Y({expected:"a valid Base64 string"},e,t)))}var Qt="~effect/SchemaTransformation/Transformation";class Q{[Qt]=Qt;_tag="Transformation";decode;encode;constructor(e,t){this.decode=e,this.encode=t}flip(){return new Q(this.encode,this.decode)}compose(e){return new Q(this.decode.compose(e.decode),e.encode.compose(this.encode))}}function Gu(e){return O(e,Qt)&&e[Qt]===Qt}var yo=(e)=>{if(Gu(e))return e;return new Q(e.decode,e.encode)};function er(e){return new Q(Xt(e.decode),Xt(e.encode))}function ti(e){return new Q(oe(e.decode),oe(e.encode))}var Hu=new Q(dt(),dt());function To(){return Hu}var Kr=new Q(Jr(),qr());var ri=er({decode:(e,t)=>URL.canParse(e)?L(new URL(e)):R(new Y({expected:"a valid URL string"},e,t)),encode:(e)=>L(e.href)});var ni=new Q(ei(),Qa());function Ze(e){return(t)=>t._tag===e}var ko=Ze("Declaration");var Zu=Ze("Never");var mt=Ze("Literal"),Eo=Ze("UniqueSymbol");var pi=Ze("Arrays"),Yu=Ze("Objects");var Xu=Ze("Suspend");class ce{to;transformation;constructor(e,t){this.to=e,this.transformation=t}}var Co={};class ht{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,r=void 0,n=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=r,this.annotations=n}}var si="~effect/Schema";class ye{[si]=si;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,r=void 0,n=void 0){this.annotations=e,this.checks=t,this.encoding=r,this.context=n}toString(){return`<${this._tag}>`}}class Wr extends ye{_tag="Declaration";typeParameters;run;encodingChecks;encodingRun;constructor(e,t,r,n,o,s,a,c){super(r,n,o,s);this.typeParameters=e,this.run=t,this.encodingChecks=a,this.encodingRun=c}getParser(){let e;return(t,r)=>{if(t===w)return Oe;return(e??=this.run(this.typeParameters))(t,this,r)}}_rebuild(e,t,r,n,o){let s=xt(this.typeParameters,e);return s===this.typeParameters&&t===this.checks&&r===this.encodingChecks&&n===this.run&&o===this.encodingRun?this:new Wr(s,n,this.annotations,t,void 0,this.context,r,o)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;if(typeof e==="string")return e;return"<Declaration>"}}class di extends ye{_tag="Unknown";getParser(){return cr(this,Yo)}getExpected(){return"unknown"}}var rr=new di;class Ve extends ye{_tag="Literal";literal;constructor(e,t,r,n,o){super(t,r,n,o);if(typeof e==="number"&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${F(e)}`);this.literal=e}getParser(){return fl(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==="bigint"?ai(this):this}toCodecStringTree(){return typeof this.literal==="string"?this:ai(this)}getExpected(){return typeof this.literal==="string"?JSON.stringify(this.literal):globalThis.String(this.literal)}}function ai(e){let t=globalThis.String(e.literal);return me(e,[new ce(new Ve(t),new Q(oe(()=>e.literal),oe(()=>t)))])}class mi extends ye{_tag="String";getParser(){return cr(this,vt)}matchPart(e,t){let r=this.checks;return r&&!t.disableChecks&&Ne(r,e,void 0,this,t)?void 0:e}getExpected(){return"string"}}var nr=new mi;class hi extends ye{_tag="Number";getParser(){return cr(this,cn)}matchKey(e,t){return this._match(pl,e,t)}matchPart(e,t){return this._match(Oo,e,t)}_match(e,t,r){if(!e.test(t))return;let n=globalThis.Number(t);if(r.disableChecks||!this.checks)return n;return Ne(this.checks,n,void 0,this,r)?void 0:n}toCodecJson(){if(this.checks&&(bo(this.checks,"effect/schema/isFinite")||bo(this.checks,"effect/schema/isInt")))return this;return me(this,[ol])}toCodecStringTree(){if(this.toCodecJson()===this)return me(this,[dl]);return me(this,[ml])}getExpected(){return"number"}}function bo(e,t){return e.some((r)=>r.annotations?.representation?.id===t||r._tag==="FilterGroup"&&bo(r.checks,t))}var Ro=new hi;class xi extends ye{_tag="Boolean";getParser(){return cr(this,Ho)}getExpected(){return"boolean"}}var gi=new xi;class sr extends ye{_tag="Arrays";isMutable;elements;rest;encodingChecks;constructor(e,t,r,n,o,s,a,c){super(n,o,s,a);this.isMutable=e,this.elements=t,this.rest=r,this.encodingChecks=c;let l=!1;for(let i=0;i<t.length;i++)if(Me(t[i]))l=!0;else if(l)throw Error("A required element cannot follow an optional element. ts(1257)");if(l&&r.length>1)throw Error("A required element cannot follow an optional element. ts(1257)");for(let i=1;i<r.length;i++)if(Me(r[i]))throw Error("An optional element cannot follow a rest element. ts(1266)")}getParser(e,t=e){let r=this,n,o,s=r.elements.length,a=Math.max(0,r.rest.length-1);function c(l,i){if(i<s)return n[i];else if(i>=l)return o[i-l+1];return o[0]}return co(function*(l,i){if(l===w)return w;if(!Array.isArray(l))return yield*R(new ke(r,l,i));if(!n)n=r.elements.map((d)=>({ast:d,parser:t(d)})),o=r.rest.map((d)=>({ast:d,parser:t(d)}));let h=l.length,x={ast:r,getParser:c,input:l,len:h,tailThreshold:Math.max(s,h-a),output:new globalThis.Array(h),issues:void 0,options:i},m=_o(i?.concurrency),p=Qu(x,l,{concurrency:m?.concurrency,end:r.rest.length===0?s:Math.max(h,s+a)});if(p)yield*p;if(r.rest.length===0&&h>s)for(let d=s;d<=h-1;d++){let E=new Br(r,l[d],i),u=new Se([d],E);if(i.errors==="all")if(x.issues)x.issues.push(u);else x.issues=[u];else return yield*R(new G(r,[u],l,i))}if(x.issues)return yield*R(new G(r,x.issues,l,i));return x.output})}_rebuild(e,t,r){let n=xt(this.elements,e),o=xt(this.rest,e);return n===this.elements&&o===this.rest&&t===this.checks&&r===this.encodingChecks?this:new sr(this.isMutable,n,o,this.annotations,t,void 0,this.context,r)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return"array"}}var Qu=Bt()({onItem(e,t,r){let n=r<e.len?t:w;return e.getParser(e.tailThreshold,r).parser(n,e.options)},step(e,t,r,n){if(r._tag==="Failure")return zr(e,e.ast,n,r);let o=r===z?t:r[S];if(o!==w)e.output[n]=o;else{let s=e.getParser(e.tailThreshold,n);if(Me(s.ast))return;let a=new Se([n],new Vt(s.ast.context?.annotations));if(e.options.errors==="all")if(e.issues)e.issues.push(a);else e.issues=[a];else return ut(new G(e.ast,[a],e.input,e.options))}}}),_o=(e)=>(e=e==="unbounded"?1/0:e??1,e>1?{concurrency:e}:void 0),zr=(e,t,r,n)=>{if(n.cause.reasons.length===0)return n;let o=Yt(n.cause);if(o===void 0)return ro(Ur(n.cause,(a)=>new G(t,[new Se([r],a)],e.input,e.options)));let s=new Se([r],o);if(e.options.errors==="all")if(e.issues)e.issues.push(s);else e.issues=[s];else return ut(new G(t,[s],e.input,e.options))},Si="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";function wo(e,t,r=Co){let n,o;function s(a){switch(a._tag){case"String":case"TemplateLiteral":return(n??=Object.keys(e)).filter((c)=>a.matchPart(c,r)!==void 0);case"Number":return(n??=Object.keys(e)).filter((c)=>a.matchKey(c,r)!==void 0);case"Symbol":return(o??=Object.getOwnPropertySymbols(e)).filter((c)=>a.matchKey(c,r)!==void 0);case"Union":return[...new Set(a.types.flatMap(s))];default:return[]}}return s($o(Qr(t)))}class Vr{name;type;constructor(e,t){this.name=e,this.type=t}}function Io(e){switch(e._tag){case"String":case"Number":case"Symbol":case"TemplateLiteral":return!0;case"Union":return e.types.every(Io);default:return!1}}function el(e){return Io(e)&&Io(Qr(e))}class Ao{parameter;type;constructor(e,t){if(!el(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Me(t)&&!Di(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}}class Zr extends ye{_tag="Objects";propertySignatures;indexSignatures;encodingChecks;constructor(e,t,r,n,o,s,a){super(r,n,o,s);this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=a;let c=e.map((l)=>l.name).filter((l,i,h)=>h.indexOf(l)!==i);if(c.length>0)throw Error(`Duplicate identifiers: ${JSON.stringify(c)}. ts(2300)`)}getParser(e,t=e){let r=this,n=[];for(let u of r.propertySignatures)n.push(u.name);let o=n.length,s=r.indexSignatures.length,a=o&&s?new Set(n):void 0;if(!o&&!s)return cr(r,Zo);let c,l,i=(u,f,g,y,T)=>{if(T._tag==="Failure")return zr(u,r,f,T)??lt;let B=T===z?y:T[S];if(g!==w&&B!==w){if(o&&(a.has(f)||a.has(g)))return lt;Ae(u.out,g,B)}return lt},h=(u,f,g,y)=>{if(!y){let U=g.parserKey(f,u.options);if(!N(U))return ve(jt(U),(C)=>h(u,f,g,C));y=U}if(y._tag==="Failure")return zr(u,r,f,y)??lt;let T=y===z?f:y[S],B=u.input[f],D=g.parserValue(B,u.options);return N(D)?i(u,f,T,B,D):ve(jt(D),(U)=>i(u,f,T,B,U))},x=(u,f,g)=>{let y=u.input[f],T=g.parserValue(y,u.options);return N(T)?i(u,f,f,y,T):ve(jt(T),(B)=>i(u,f,f,y,B))},m=s?Bt()({onItem:(u,[f,g])=>h(u,f,g),step:(u,f,g)=>g._tag==="Failure"?g:void 0}):void 0,p=()=>{if(!c)c=r.propertySignatures.map((u)=>({parser:t(u.type),name:u.name,type:u.type})),l=s?r.indexSignatures.map((u)=>({is:u,parserKey:e($o(u.parameter)),parserValue:t(u.type)})):void 0;return c},d=co(function*(u,f){if(u===w)return w;if(!(typeof u==="object"&&u!==null&&!Array.isArray(u)))return yield*R(new ke(r,u,f));p();let g=u,y={},T={ast:r,input:g,out:y,issues:void 0,options:f},B=f.errors==="all",D=f.onExcessProperty==="error",U=f.onExcessProperty==="preserve",C;if(!s&&(D||U)){a??=new Set(n),C=Reflect.ownKeys(g);for(let I=0;I<C.length;I++){let v=C[I];if(!a.has(v))if(D){let _=new Br(r,g[v],f),A=new Se([v],_);if(B){if(T.issues)T.issues.push(A);else T.issues=[A];continue}else return yield*R(new G(r,[A],u,f))}else Ae(y,v,g[v])}}let H=_o(f?.concurrency);if(o){let I=ii(T,c,H);if(I)yield*I}if(s&&!H)for(let I=0;I<s;I++){let v=l[I],_=v.is.parameter===nr?x:h,A=v.is.parameter===nr?Object.keys(g):wo(g,v.is.parameter,f);for(let Xe=0;Xe<A.length;Xe++){let Ce=_(T,A[Xe],v);if(!N(Ce))yield*Ce;else if(Ce._tag==="Failure")return yield*Ce}}else if(m){let I=wr();for(let _=0;_<s;_++){let A=l[_],Xe=wo(g,A.is.parameter,f);for(let Ce=0;Ce<Xe.length;Ce++)I.push([Xe[Ce],A])}let v=m(T,I,H);if(v)yield*v}if(T.issues)return yield*R(new G(r,T.issues,u,f));if(f.propertyOrder==="original"){let I=(C??Reflect.ownKeys(g)).concat(n),v={};for(let _ of I)if(Object.hasOwn(y,_))Ae(v,_,y[_]);return v}return y});if(s)return d;let E=(u,f,g)=>{let y=c[f];return ve(jt(g),(T)=>{let B=vo(u,y,T);if(B)return B;let D=()=>pe(u.out),U=ii(u,c.slice(f+1));return U?ie(U,D):D()})};return(u,f)=>{if(u===w)return Oe;if(f.errors==="all"||f.onExcessProperty!==void 0||f.propertyOrder==="original"||f.concurrency!==void 0)return d(u,f);if(!(typeof u==="object"&&u!==null&&!Array.isArray(u)))return R(new ke(r,u,f));let g=p(),y=u,T={},B={ast:r,input:y,out:T,issues:void 0,options:f};try{for(let D=0;D<g.length;D++){let U=g[D],C=U.name,H=Object.hasOwn(y,C),I=H?y[C]:w,v=U.parser(I,f);if(!N(v))return E(B,D,v);if(v===z){if(H)Ae(T,C,I);continue}let _=vo(B,U,v);if(_)return _}}catch(D){return Na(D)}return pe(T)}}_rebuild(e,t,r,n){let o=xt(this.propertySignatures,(a)=>{let c=e(a.type);return c===a.type?a:new Vr(a.name,c)}),s=xt(this.indexSignatures,(a)=>{let c=t(a.parameter),l=e(a.type);return c===a.parameter&&l===a.type?a:new Ao(c,l)});return o===this.propertySignatures&&s===this.indexSignatures&&r===this.checks&&n===this.encodingChecks?this:new Zr(o,s,this.annotations,r,void 0,this.context,n)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){if(this.propertySignatures.length===0&&this.indexSignatures.length===0)return"object | array";return"object"}}function vo(e,t,r){if(r._tag==="Failure")return zr(e,e.ast,t.name,r);if(r===z)return;let n=r[S];if(n!==w){Ae(e.out,t.name,n);return}if(delete e.out[t.name],!Me(t.type)){let o=new Se([t.name],new Vt(t.type.context?.annotations));if(e.options.errors==="all"){if(e.issues)e.issues.push(o);else e.issues=[o];return}else return ut(new G(e.ast,[o],e.input,e.options))}}var ii=Bt()({onItem(e,t){if(!Object.hasOwn(e.input,t.name))return t.parser(w,e.options);let r=e.input[t.name];return Ae(e.out,t.name,r),t.parser(r,e.options)},step:vo});function yi(e,t){if(!e)return t;if(!t)return e;return[...e,...t]}function Fo(e,t,r){return new Zr(Reflect.ownKeys(e).map((n)=>new Vr(n,e[n].ast)),[],r,t)}function Po(e){return e.ast}function Do(e,t=void 0){return new sr(!1,e.map((r)=>r.ast),[],void 0,t)}function Uo(e,t,r){return new Ye(e.map(Po),t,void 0,r)}var Yr=bt((e)=>{while(!0){if(Xu(e))return rr;let t=e.encoding;if(!t)return e.recur?.(Yr,V)??e;if(t.some((r)=>r.transformation._tag==="Middleware"&&r.transformation.decode!==V))return rr;e=t[t.length-1].to}});function Ti(e){switch(e._tag){case"Null":return["null"];case"Undefined":return["undefined"];case"String":case"TemplateLiteral":return["string"];case"Number":return["number"];case"Boolean":return["boolean"];case"Symbol":case"UniqueSymbol":return["symbol"];case"BigInt":return["bigint"];case"Arrays":return["array"];case"ObjectKeyword":return["object","array","function"];case"Objects":return e.propertySignatures.length||e.indexSignatures.length?["object"]:["string","number","boolean","symbol","bigint","object","array","function"];case"Enum":return Array.from(new Set(e.enums.map(([,t])=>typeof t)));case"Literal":return[typeof e.literal];case"Union":return Array.from(new Set(e.types.flatMap(Ti)));default:return["null","undefined","string","number","boolean","symbol","bigint","object","array","function"]}}function Gr(e){switch(e._tag){default:return[];case"Declaration":{let t=e.annotations?.[ja];return Array.isArray(t)?t:[]}case"Objects":return e.propertySignatures.flatMap((t)=>{let r=t.type;if(!Me(r)){if(mt(r))return[{key:t.name,literal:r.literal}];if(Eo(r))return[{key:t.name,literal:r.symbol}]}return[]});case"Arrays":return e.elements.flatMap((t,r)=>{if(!Me(t)){if(mt(t))return[{key:r,literal:t.literal}];if(Eo(t))return[{key:r,literal:t.symbol}]}return[]});case"Union":{if(e.types.length===0)return[];let t=e.types.map((r)=>Gr(Yr(r)));return t[0].filter((r)=>t.every((n)=>n.some((o)=>o.key===r.key&&o.literal===r.literal)))}case"Suspend":return Gr(e.thunk())}}var ci=new WeakMap,tr=Object.freeze([]);function tl(e){let t=ci.get(e);if(t)return t;let r,n=0,o,s,a=!0;for(let c=0;c<e.length;c++){let l=e[c],i=Yr(l);if(Zu(i))continue;if(a)if(mt(i)||Eo(i)){s??=new Map;let x=mt(i)?i.literal:i.symbol,m=s.get(x);if(!m)s.set(x,m=[]);m.push(l)}else a=!1;let h=Gr(i);if(h.length){r??=new Map,n++;for(let{key:x,literal:m}of h){let p=r.get(x);if(!p)r.set(x,p=[new Map,new Set]);p[1].add(c);let d=p[0].get(m);if(!d)p[0].set(m,d=new Set);d.add(c)}}else{o??={};let x=Ti(i);for(let m of x)(o[m]??=[]).push(c)}}if(a&&s)s.forEach(Object.freeze),t=(c)=>s.get(c)??tr;else if(r?.size===1&&!o){let[c,[l]]=r.entries().next().value,i=l;for(let[h,x]of l)i.set(h,Object.freeze(Array.from(x,(m)=>e[m])));t=(h,x)=>{if(ur(h)){let m=Object.hasOwn(h,c)?h[c]:void 0;if(m!==void 0)return i.get(m)??tr;if(x)return e}return tr}}else if(r){let c;for(let l of r)if((!c||l[1][0].size>c[1][0].size)&&l[1][1].size===n)c=l;t=(l,i)=>{let h=l===null?"null":Array.isArray(l)?"array":typeof l,x=o?.[h]??tr;if(!ur(l))return x.map((d)=>e[d]);let m=new Set(x),p;if(c){let[d,[E]]=c,u=Object.hasOwn(l,d),f=u?l[d]:void 0;if(u&&(!i||f!==void 0)){let g=E.get(f);if(!g)return x.map((y)=>e[y]);for(let y of g)m.add(y);p=d}}if(p===void 0)for(let[d,[E,u]]of r){let f=Object.hasOwn(l,d),g=f?l[d]:void 0;if(f&&(!i||g!==void 0)){let y=E.get(g);if(y)for(let T of y)m.add(T)}else if(i)for(let y of u)m.add(y)}for(let[d,[E,u]]of r){if(d===p)continue;let f=Object.hasOwn(l,d),g=f?l[d]:void 0;if(f&&(!i||g!==void 0)){let y=E.get(g);for(let T of m)if(u.has(T)&&!y?.has(T))m.delete(T)}}return Array.from(m).sort((d,E)=>d-E).map((d)=>e[d])}}else t=(c)=>{let l=c===null?"null":Array.isArray(c)?"array":typeof c;return(o?.[l]??tr).map((i)=>e[i]).filter(rl(c))};return ci.set(e,t),t}function rl(e){return(t)=>{let r=Yr(t);return r._tag==="Literal"?r.literal===e:r._tag==="UniqueSymbol"?r.symbol===e:!0}}function Ei(e,t,r=!1){return tl(t)(e,r)}class Ye extends ye{_tag="Union";types;mode;encodingChecks;constructor(e,t,r,n,o,s,a){super(r,n,o,s);this.types=e,this.mode=t,this.encodingChecks=a}getParser(e,t){let r=this;return(n,o)=>{if(n===w)return Oe;let s=Ei(n,r.types,t!==void 0);if(s.length===1){let i=e(s[0])(n,o);if(i._tag==="Success")return i;return N(i)?ui(r,i.cause,n,o):qt(i,(h)=>ui(r,h,n,o))}let a={ast:r,compile:e,input:n,out:void 0,successes:r.mode==="oneOf"?[]:void 0,issues:void 0,options:o},c=_o(o?.concurrency),l=nl(a,s,c?{...c,orderedStep:!0}:void 0);if(!l){if(a.out)return a.out;return R(new Zt(r,a.issues??[],n,o))}return ie(l,(i)=>{if(a.out===z)return L(n);if(a.out)return a.out;return R(new Zt(r,a.issues??[],n,o))})}}_rebuild(e,t,r){let n=xt(this.types,e);return n===this.types&&t===this.checks&&r===this.encodingChecks?this:new Ye(n,this.mode,this.annotations,t,void 0,this.context,r)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let r of this.types){let n=r.matchPart(e,t);if(n!==void 0)return n}return}getExpected(e){let t=this.annotations?.expected;if(typeof t==="string")return t;if(this.types.length===0)return"never";let r=this.types.map((n)=>{let o=Qr(n);switch(o._tag){case"Arrays":{let s=o.elements.filter(mt);if(s.length>0)return`${li(o.isMutable)}[ ${s.map((a)=>e(a)+fi(a.context?.isOptional)).join(", ")}, ... ]`;break}case"Objects":{let s=o.propertySignatures.filter((a)=>mt(a.type));if(s.length>0)return`{ ${s.map((a)=>`${li(a.type.context?.isMutable)}${rt(a.name)}${fi(a.type.context?.isOptional)}: ${e(a.type)}`).join(", ")}, ... }`;break}}return e(o)});return Array.from(new Set(r)).join(" | ")}}function ui(e,t,r,n){let o=Yt(t);if(!o)return ro(t);return ut(new Zt(e,[o],r,n))}var nl=Bt()({onItem(e,t){return e.compile(t)(e.input,e.options)},step(e,t,r){if(r._tag==="Failure"){let n=Yt(r.cause);if(n===void 0)return r;if(e.issues)e.issues.push(n);else e.issues=[n]}else{if(e.out&&e.successes)return e.successes.push(t),ut(new xo(e.ast,e.successes,e.input,e.options));if(e.out=r,e.successes)e.successes.push(t);else return lt}}}),bi=new Ye([new Ve("Infinity"),new Ve("-Infinity"),new Ve("NaN")],"anyOf");function li(e){return e?"":"readonly "}function fi(e){return e?"?":""}class Hr extends Et{_tag="Filter";run;annotations;aborted;constructor(e,t=void 0,r=!1){super();this.run=e,this.annotations=t,this.aborted=r}annotate(e){return new Hr(this.run,{...this.annotations,...e},this.aborted)}abort(){return new Hr(this.run,this.annotations,!0)}and(e,t){return new or([this,e],t)}}class or extends Et{_tag="FilterGroup";checks;annotations;constructor(e,t=void 0){super();this.checks=e,this.annotations=t}annotate(e){return new or(this.checks,{...this.annotations,...e})}and(e,t){return new or([this,e],t)}}function Xr(e,t,r=!1){return new Hr((n,o,s)=>za(o,e(n,o,s),n,s),t,r)}function wi(e){return Xr((t)=>globalThis.Number.isFinite(t),{expected:"a finite number",representation:{id:"effect/schema/isFinite",payload:null},toJsonSchema:()=>({type:"number"}),toCode:()=>({runtime:"Schema.isFinite()"}),arbitrary:{constraint:{noInfinity:!0,noNaN:!0}},...e})}var Ii=ir(Ro,[wi()]),ol=new ce(new Ye([Ii,bi],"anyOf"),new Q(Jr(),oe((e)=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function Mo(e,t){let r=e.source,n=new globalThis.RegExp(r,e.flags);return Xr((o)=>(n.lastIndex=0,n.test(o)),{expected:`a string matching the RegExp ${r}`,representation:{id:"effect/schema/isPattern",payload:{source:r,flags:e.flags}},toJsonSchema:()=>({pattern:r}),arbitrary:{constraint:{patterns:[e.source]}},...t})}function ar(e,t){let r=Object.getOwnPropertyDescriptors(e);return t(r),Object.create(Object.getPrototypeOf(e),r)}var vi=new WeakMap;function sl(e){return vi.get(e)??e}function me(e,t){if(e.encoding===t)return e;return ar(e,(r)=>{r.encoding.value=t})}function Oi(e,t){if(e.context===t)return e;let r=sl(e);if(r.context===t)return r;let n=ar(e,(o)=>{o.context.value=t});return vi.set(n,r),n}function No(e,t){if(e.checks){let r=e.checks[e.checks.length-1];return ki(e,Fn(e.checks.slice(0,-1),r.annotate(t)))}return ar(e,(r)=>{r.annotations.value={...r.annotations.value,...t}})}function ki(e,t){if(e._tag==="Suspend"&&t)throw Error("Cannot add checks to Suspend");if(e.checks===t)return e;return ar(e,(r)=>{r.checks.value=t})}function ir(e,t){return ki(e,yi(e.checks,t))}function Ci(e,t){let r=t(e.to);return r===e.to?e:new ce(r,e.transformation)}function al(e,t){let r=e,n=r[r.length-1],o=Ci(n,t);return o===n?e:Fn(e.slice(0,e.length-1),o)}function Ri(e,t){function r(n){if(n.encoding){let o=n.encoding[n.encoding.length-1];return t?.stopAt?.(o)?n:me(n,al(n.encoding,r))}return e(n)}return bt(r)}function il(e,t,r){let n=new ce(e,t);return me(r,r.encoding?[...r.encoding,n]:[n])}function xt(e,t){let r=!1,n=Array(e.length);for(let o=0;o<e.length;o++){let s=e[o],a=t(s);if(a!==s)r=!0;n[o]=a}return r?n:e}function Lo(e,t){let r=e.context?new ht(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new ht(!1,!1,void 0,t);return Oi(e,r)}function _i(e,t){let r=new Q(go(t),dt()),n=new ce(rr,r),o=e.context?new ht(e.context.isOptional,e.context.isMutable,n,e.context.annotations):new ht(!1,!1,n);return Oi(e,o)}function Ai(e,t,r){return il(e,r,t)}function cl(e){let t=[],r=[];function n(o){switch(o._tag){case"Literal":if(Vo(o.literal))t.push(o.literal);return;case"UniqueSymbol":t.push(o.symbol);return;case"Never":return;case"Union":for(let s=0;s<o.types.length;s++)n(o.types[s]);return;default:r.push(o)}}return n(e),{literals:t,parameters:r}}function Fi(e,t){let{literals:r,parameters:n}=cl(e);return new Zr(r.map((o)=>new Vr(o,t)),n.map((o)=>new Ao(o,t)))}function Me(e){return e.context?.isOptional??!1}function Pi(e){return e.annotations?.[Ba]===!0||e._tag==="FilterGroup"&&e.checks.every(Pi)}function ul(e){function t(n){if(Pi(n))return[n];return n._tag==="FilterGroup"?n.checks.flatMap(t):[]}let r=e.flatMap(t);return Pn(r)?r:void 0}var gt=bt((e)=>{if(e.encoding)return gt(me(e,void 0));let t=e,r=t.recur?.(gt)??t,n=r.encodingChecks;if(n){let o=r===e?n:pi(r)||Yu(r)||ko(r)&&r.typeParameters.length>0?ul(n):void 0;return ar(r,(s)=>{s.encodingChecks.value=void 0,s.checks.value=yi(r.checks,o)})}return r}),Qr=bt((e)=>gt(Ue(e)));function ll(e,t){let r=t,n=r.length,o=r[n-1],s=[new ce(Ue(me(e,void 0)),r[0].transformation.flip())];for(let c=1;c<n;c++)s.unshift(new ce(Ue(r[c-1].to),r[c].transformation.flip()));let a=Ue(o.to);if(a.encoding)return me(a,[...a.encoding,...s]);else return me(a,s)}var Ue=Re((e)=>{if(e.encoding)return ll(e,e.encoding);let t=e;return t.flip?.(Ue)??t.recur?.(Ue)??t});function Di(e){switch(e._tag){case"Undefined":return!0;case"Union":return e.types.some(Di);default:return!1}}function fl(e,t){let r=pe(t);return(n,o)=>{if(n===w)return Oe;if(n===t)return r;return R(new ke(e,n,o))}}function cr(e,t){return(r,n)=>{if(r===w)return Oe;if(t(r))return z;return R(new ke(e,r,n))}}var $o=Ri((e)=>{switch(e._tag){default:return e;case"Number":return e.toCodecStringTree();case"Union":return e.recur($o)}});var Oo=new globalThis.RegExp(`^${Si}$`),pl=new globalThis.RegExp(`^(?:${Si}|Infinity|-Infinity|NaN)$`);function Ui(e){return Mo(Oo,{expected:"a string representing a finite number",representation:{id:"effect/schema/isStringFinite",payload:null},toJsonSchema:()=>({pattern:Oo.source}),...e})}var Mi=ir(nr,[Ui()]),dl=new ce(Mi,Kr),ml=new ce(new Ye([Mi,bi],"anyOf"),Kr),hl="-?\\d+",Ug=new globalThis.RegExp(`^${hl}$`);var xl="Symbol\\((.*)\\)",Mg=new globalThis.RegExp(`^${xl}$`);function Ne(e,t,r,n,o){for(let s=0;s<e.length;s++){let a=e[s];if(a._tag==="FilterGroup"){if(r=Ne(a.checks,t,r,n,o),r&&(o.errors!=="all"||r[r.length-1].filter.aborted))return r}else{let c=a.run(t,n,o);if(c){let l=new mo(a,c,t,o);if(r)r.push(l);else r=[l];if(o.errors!=="all"||a.aborted)return r}}}return r}function Ni(e){if(!ko(e))return;let t=e.annotations?.[qa];return Ot(t)?t(e.typeParameters):void 0}function tn(e){let t=qi(rn,gt(e.ast));return(r,n)=>t(r,n?.disableChecks?n?.parseOptions?{...n.parseOptions,disableChecks:!0}:{disableChecks:!0}:n?.parseOptions)}function jo(e){let t=tn(e);return(r,n)=>{let o=Jt(t(r,n));if(Mr(o))return ge(o.value);return jr(o.cause,"Option adapter can only return none for schema issues"),Ee()}}function $i(e){let t=tn(e);return(r,n)=>{let o=Jt(t(r,n));if(Mr(o))return o.value;let s=jr(o.cause,"Constructor adapter can only throw schema issues");throw Error("Schema validation failed",{cause:s})}}function Bi(e,t){let r=Sl(e.ast);return t===void 0?r:(n,o)=>r(n,en(t,o))}function ji(e,t){return Tl(Bi(e,t))}var en=(e,t)=>t?{...e,...t}:e,Li=(e)=>{if(e===w)return R(new Y);return L(e)};function Sl(e){return qi(Ji,e)}function qi(e,t){let r;return(n,o)=>{let s=(r??=e(t))(n,o??Co);if(s===z)return L(n);if(!N(s))return ie(s,Li);return s[S]===w?Li(w):s}}function yl(e){return(t,r)=>Jt(e(t,r))}function Tl(e){let t=yl(e);return(r,n)=>{let o=t(r,n);if(Mr(o))return ze(o.value);return xe(jr(o.cause,"Result adapter can only return schema issues"))}}var Ji=Re((e)=>qo(e,Ji)),rn=Re((e)=>qo(e,rn,Ki)),El=Re((e)=>qo(e,rn,Ki,e.context?.constructorDefault));function Ki(e){return e.context?.constructorDefault?El(e):rn(e)}function zi(e,t,r,n){let o;if(N(e)&&e._tag==="Success"){let s=Lr(e===z?t:e[S]);o=r._tag==="Transformation"?r.decode.run(s,n):r.decode(pe(s),n)}else if(r._tag==="Transformation")o=ie(e,(s)=>r.decode.run(Lr(s),n));else o=r.decode(ft(e,Lr),n);return N(o)&&o._tag==="Success"?uo(o[S]):ie(o,uo)}function bl(e,t){let r;return(n,o)=>{if(n===w)return Oe;if(e.isConstructed(n))return z;let s=(r??=t(e.link.to))(n,o);return zi(s,n,e.link.transformation,o)}}function qo(e,t,r,n){let o=r?Ni(e):void 0,s=o?bl(o,t):e.getParser(t,r),a=e.checks,c=n?e.encoding?[...e.encoding,n]:[n]:e.encoding,l=e.encodingChecks,i=(a?a[a.length-1].annotations:e.annotations)?.parseOptions;if(!c&&!a&&!l){if(!i)return s;return(m,p)=>s(m,en(p,i))}let h,x=(m,p)=>{let d=s(m,p);if(l&&!p.disableChecks)if(N(d)){if(d._tag==="Success"){let E=d===z?m:d[S];if(m!==w&&E!==w){let u=Ne(l,m,void 0,e,p);if(u)d=R(new G(e,u,m,p))}}}else d=ve(d,(E)=>{if(m!==w&&E!==w){let u=Ne(l,m,void 0,e,p);if(u)return R(new G(e,u,m,p))}return L(E)});if(a&&!p.disableChecks)if(N(d)){if(d._tag==="Success"){let E=d===z?m:d[S];if(E===w)return d;let u=Ne(a,E,void 0,e,p);if(u)d=R(new G(e,u,E,p))}}else d=ve(d,(E)=>{if(E!==w){let u=Ne(a,E,void 0,e,p);if(u)return R(new G(e,u,E,p))}return L(E)});return d};if(!c)return i?(m,p)=>x(m,en(p,i)):x;return(m,p)=>{if(i)p=en(p,i);let d=h??=c.map((f)=>t(f.to)),E=m,u=d[d.length-1](m,p);for(let f=c.length-1;f>=0;f--)if(u=zi(u,E,c[f].transformation,p),f!==0){let g=d[f-1];if(u._tag==="Success")E=u[S],u=g(E,p);else u=ie(u,(y)=>{let T=g(y,p);return T===z?pe(y):T})}if(u._tag==="Success"){let f=u[S],g=x(f,p);return g===z?u:g}return u=qt(u,(f)=>so(()=>Ur(f,(g)=>new ho(e,g,m,p)))),ie(u,(f)=>{let g=x(f,p);return g===z?pe(f):g})}}var Jo="~effect/Schema/Schema";var wl={[Jo]:Jo,pipe(){return se(this,arguments)},annotate(e){return this.rebuild(No(this.ast,e))},annotateKey(e){return this.rebuild(Lo(this.ast,e))},check(...e){return this.rebuild(ir(this.ast,e))}};function Ko(e,t){function r(){}let n=Object.defineProperties(Object.setPrototypeOf(r,wl),Object.getOwnPropertyDescriptors({...t}));return n.ast=e,n.rebuild=(o)=>Ko(o,t),n.makeEffect=tn(n),n.make=$i(n),n.makeOption=jo(n),n}var Hi=(e)=>e;function Ol(){return(e,t,r)=>ee(new Wr(e.map(Po),(n)=>t(n.map((o)=>ee(o))),r))}function kl(e,t){return Ol()([],()=>(r,n,o)=>e(r)?L(r):R(new ke(n,r,o)),t)}var Wi="~effect/SchemaError/SchemaError";class Zi extends kr("SchemaError"){[Wi]=Wi;constructor(e){let t=Xs();Jn(0);try{super({issue:e})}finally{Jn(t)}}get message(){return Wa(this.issue)}toString(){return`SchemaError(${this.message})`}}function Cl(e,t){let r=ji(e,t);return(n,o)=>Es(r(n,o),(s)=>new Zi(s))}var ee=Ko;function Yi(e){let t=ee(new Ve(e),{literal:e,transform(r){return t.pipe(Pl(Yi(r),{decode:oe(()=>r),encode:oe(()=>e)}))}});return t}var nn=ee(rr);var W=ee(nr),Rl=ee(Ro),_l=ee(gi);function Xi(e,t){return ee(e,{fields:t,mapFields(r,n){let o=r(this.fields);return Xi(Fo(o,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function St(e){return Xi(Fo(e,void 0),e)}function Qi(e,t){return ee(Fi(e.ast,t.ast),{key:e,value:t})}function ec(e,t){return ee(e,{elements:t,mapElements(r,n){let o=r(this.elements);return ec(Do(o,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function Al(e){return ec(Do(e),e)}var Fl=Hi((e)=>ee(new sr(!1,[],[e.ast]),{value:e}));function tc(e,t){return ee(e,{members:t,mapMembers(r,n){let o=r(this.members);return tc(Uo(o,this.ast.mode,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function rc(e,t){return tc(Uo(e,t?.mode??"anyOf",void 0),e)}function Pl(e,t){return(r)=>ee(Ai(r.ast,e.ast,t?yo(t):To()),{from:r,to:e})}function Dl(e){return(t)=>ee(_i(t.ast,e),{schema:t})}function Vi(e){return Yi(e).pipe(Dl(L(e)))}function yt(e,t){return kl((r)=>r instanceof e,t)}function Tt(){return(e,t)=>new ce(e.ast,yo(t))}var Ul=Xr;function Ml(e,t){let{source:r,flags:n}=e,o=n===""?`new RegExp(${F(r)})`:`new RegExp(${F(r)}, ${F(n)})`;return Mo(e,{toCode:()=>({runtime:`Schema.isPattern(${o})`}),...t})}function Nl(e){let t=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;return Ml(t,{expected:"a base64 encoded string",representation:{id:"effect/schema/isBase64",payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:"Schema.isBase64()"}),...e})}function Ll(e){return Ul((t)=>globalThis.Number.isSafeInteger(t),{expected:"an integer",representation:{id:"effect/schema/isInt",payload:null},toJsonSchema:()=>({type:"integer"}),toCode:()=>({runtime:"Schema.isInt()"}),arbitrary:{constraint:{integer:!0}},...e})}var $l=Rl.check(Ll());var _y=yt(globalThis.RegExp,{representation:{id:"effect/schema/RegExp",payload:null},toCode:()=>({runtime:"Schema.RegExp",Type:"globalThis.RegExp"}),expected:"RegExp",toCodecJson:()=>Tt()(St({source:W,flags:W}),er({decode:(e,t)=>ao({try:()=>new globalThis.RegExp(e.source,e.flags),catch:()=>new Y({expected:"valid RegExp source and flags"},e,t)}),encode:(e)=>L({source:e.source,flags:e.flags})})),toArbitrary:()=>(e)=>e.tuple(e.constantFrom(".",".*","\\d+","\\w+","[a-z]+","[A-Z]+","[0-9]+","^[a-zA-Z0-9]+$","^\\d{4}-\\d{2}-\\d{2}$"),e.uniqueArray(e.constantFrom("g","i","m","s","u","y"),{minLength:0,maxLength:6}).map((t)=>t.join(""))).map(([t,r])=>new globalThis.RegExp(t,r)),toEquivalence:()=>(e,t)=>e.source===t.source&&e.flags===t.flags});var Bl=W.annotate({expected:"a string that will be decoded as a URL"}),Ay=yt(globalThis.URL,{representation:{id:"effect/schema/URL",payload:null},toCode:()=>({runtime:"Schema.URL",Type:"globalThis.URL"}),expected:"URL",toCodecJson:()=>Tt()(Bl,ri),toArbitrary:()=>(e)=>e.webUrl().map((t)=>new globalThis.URL(t)),toEquivalence:()=>(e,t)=>e.toString()===t.toString()});var jl=yt(globalThis.File,{representation:{id:"effect/schema/File",payload:null},toCode:()=>({runtime:"Schema.File",Type:"globalThis.File"}),expected:"File",toCodecJson:()=>Tt()(St({data:W.check(Nl()),type:W,name:W,lastModified:$l}),er({decode:(e,t)=>Tr(Ar(e.data),{onFailure:()=>R(new Y({expected:"a valid Base64 string"},e.data,t)),onSuccess:(r)=>{let n=new globalThis.Uint8Array(r);return L(new globalThis.File([n],e.name,{type:e.type,lastModified:e.lastModified}))}}),encode:(e,t)=>Ma({try:async()=>{let r=new globalThis.Uint8Array(await e.arrayBuffer());return{data:_r(r),type:e.type,name:e.name,lastModified:e.lastModified}},catch:()=>new Y({expected:"a readable File"},e,t)})}))});var Fy=yt(globalThis.FormData,{representation:{id:"effect/schema/FormData",payload:null},toCode:()=>({runtime:"Schema.FormData",Type:"globalThis.FormData"}),expected:"FormData",toCodecJson:()=>Tt()(Fl(Al([W,rc([St({_tag:Vi("String"),value:W}),St({_tag:Vi("File"),value:jl})])])),er({decode:(e)=>{let t=new globalThis.FormData;for(let[r,n]of e)t.append(r,n.value);return L(t)},encode:(e)=>L(globalThis.Array.from(e.entries()).map(([t,r])=>{if(typeof r==="string")return[t,{_tag:"String",value:r}];else return[t,{_tag:"File",value:r}]}))}))});var Py=yt(globalThis.URLSearchParams,{representation:{id:"effect/schema/URLSearchParams",payload:null},toCode:()=>({runtime:"Schema.URLSearchParams",Type:"globalThis.URLSearchParams"}),expected:"URLSearchParams",toCodecJson:()=>Tt()(W.annotate({expected:"a query string that will be decoded as URLSearchParams"}),ti({decode:(e)=>new globalThis.URLSearchParams(e),encode:(e)=>e.toString()}))});var ql=W.annotate({expected:"a base64 encoded string that will be decoded as Uint8Array",format:"byte",contentEncoding:"base64"}),Dy=yt(globalThis.Uint8Array,{representation:{id:"effect/schema/Uint8Array",payload:null},toCode:()=>({runtime:"Schema.Uint8Array",Type:"globalThis.Uint8Array"}),expected:"Uint8Array",toCodecJson:()=>Tt()(ql,ni),toArbitrary:()=>(e)=>e.uint8Array()});import{accessSync as Jl,constants as Kl,realpathSync as ic}from"node:fs";import{createRequire as zl}from"node:module";import ac from"node:path";import{fileURLToPath as Gl}from"node:url";var oc=(e)=>{let t=e?.trim();return t===void 0||t.length===0?void 0:t},sc=()=>({bunExecutable:oc(process.env.TRIPWIRE_BUN),forcePortable:process.env.TRIPWIRE_FORCE_PORTABLE==="1",packageDist:oc(process.env.TRIPWIRE_PACKAGE_DIST)});var Hl=["@seanmozeik","tripwire-darwin-arm64"].join("/"),Wl=(e)=>{try{return Jl(e,Kl.X_OK),ic(e)}catch{return}},Vl=(e,t)=>{try{let r=t?.()??zl(e).resolve(Hl);return Wl(r)}catch{return}},Zl=(e)=>{let t=Gl(e),r=t;try{r=ic(t)}catch{}return ac.join(ac.dirname(r),"tripwire.js")},cc=(e={})=>{let t=e.moduleUrl??import.meta.url,r=e.platform??process.platform,n=e.architecture??process.arch,o=sc();if(!o.forcePortable&&r==="darwin"&&n==="arm64"){let s=Vl(t,e.nativeResolver);if(s!==void 0)return{arguments:[],executable:s,kind:"native"}}return{arguments:[e.portableExecutable??Zl(t)],executable:e.bunExecutable??o.bunExecutable??"bun",kind:"portable"}};var rf=St({input:Qi(W,nn),toolCallId:W,toolName:W}),nf=St({input:Qi(W,nn),toolCallId:W,toolName:W,content:nn,details:nn,isError:_l}),of=rc([nf,rf]),uc=60000,sf=(e=import.meta.url)=>{let t=ef(e),r=t;try{r=Ql(t)}catch{}return cc({moduleUrl:tf(r)})},af=sf(),on=(e,t,r)=>{for(let n of t){let o=e[n];if(typeof o==="string")return o}throw Error(`Pi ${r} is missing`)},cf=(e,t)=>{let r=e[t];return Array.isArray(r)?r.filter((n)=>typeof n==="string"):[]},uf=(e)=>{let{edits:t}=e;if(Array.isArray(t)){let r=[],n=[];for(let o of t)if(sn(o)){let s=j(o,"oldText")??j(o,"old_string"),a=j(o,"newText")??j(o,"new_string");if(s!==void 0)r.push(s);if(a!==void 0)n.push(a)}return{old_string:r.join(`
12
+ `),new_string:n.join(`
13
+ `)}}return{old_string:j(e,"oldText")??j(e,"old_string")??"",new_string:j(e,"newText")??j(e,"new_string")??j(e,"input")??j(e,"_input")??""}},lf=(e,t,r)=>{let n;if(e.startsWith("+"))n="newLines";else if(e.startsWith("-"))n="oldLines";if(n!==void 0)for(let o of t)r.get(o)?.[n].push(e.slice(1))},ff=(e)=>{let t=/^\*{3}\s+(?:Add|Update|Delete)\s+File\s*:\s*(?<path>\S.*?)\s*$/u,r=/^\*{3}\s+Move\s+to\s*:\s*(?<path>\S.*?)\s*$/u,n=new Map,o=[],s="*** Begin Patch",a="*** End Patch",c=e.split(/\r?\n/u),l=c.findIndex((p)=>p.trim()===s);if(l===-1)return[];let i=c.slice(l+1),h=[...i,a].findIndex((p)=>p.trim()===a),x=i.slice(0,h),m=(p)=>{if(o.push(p),!n.has(p))n.set(p,{newLines:[],oldLines:[]})};for(let p of x){let E=t.exec(p)?.groups?.path?.trim();if(E!==void 0&&E.length>0)o=[],m(E);else if(o.length>0){let f=r.exec(p)?.groups?.path?.trim();if(f!==void 0&&f.length>0)m(f);else lf(p,o,n)}}return[...n].map(([p,d])=>({file_path:p,new_string:d.newLines.join(`
14
+ `),old_string:d.oldLines.join(`
15
+ `)}))},pf=(e)=>{let{input:t,toolName:r}=e;if(r==="bash"||r==="powershell")return[{command:on(t,["command"],`${r} command`)}];if(r==="read")return[{file_path:on(t,["path","file_path"],"read path")}];if(r==="write")return[{content:on(t,["content"],"write content"),file_path:on(t,["path","file_path"],"write path")}];if(r==="edit"){let n=ff(j(t,"input")??"");if(n.length>0)return n;let o=j(t,"path")??j(t,"file_path"),a=cf(t,"paths");if(a.length===0&&o!==void 0)a=[o];if(a.length===0)throw Error("Pi edit path is missing");let c=uf(t),l=[];for(let i of a)l.push({file_path:i,...c});return l}return[t]},df=(e)=>{if(typeof e==="string")return e;if(!Array.isArray(e))return"";let t=[];for(let r of e)if(sn(r)&&r.type==="text"&&typeof r.text==="string")t.push(r.text);return t.join(`
16
+ `)},mf=(e)=>{let t=df(e.content);if(e.toolName==="bash"||e.toolName==="powershell")return{stdout:t,stderr:e.isError?t:"",interrupted:e.isError};if(e.toolName==="read")return{content:t};return{content:t,details:e.details,isError:e.isError}},lc=(e,t,r)=>{let n=Cl(of)(e);if(st(n))throw Error("Pi sent an invalid tool event");let o=n.success,s={cwd:r,hook_event_name:t,tool_name:o.toolName,tool_use_id:o.toolCallId};if("content"in o)return[{...s,tool_input:o.input,tool_response:mf(o)}];let a=[];for(let c of pf(o))a.push({...s,tool_input:c});return a},fc=async(e)=>{e.setEncoding("utf8");let t="";for await(let r of e)t+=String(r);return t},hf=async(e,t)=>{let r=Yl(e.executable,[...e.arguments,"--tripwire-hook"],{stdio:["pipe","pipe","pipe"]}),n={timedOut:!1},o=setTimeout(()=>{n.timedOut=!0,r.kill("SIGKILL")},uc);r.stdin.end(JSON.stringify(t));try{let[s,a,c]=await Promise.all([Xl(r,"close"),fc(r.stdout),fc(r.stderr)]);if(n.timedOut)throw Error(`Tripwire exceeded its ${uc}ms timeout`);return{exitCode:typeof s[0]==="number"?s[0]:1,stderr:c,stdout:a}}finally{clearTimeout(o)}},sn=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),j=(e,t)=>{let r=e[t];return typeof r==="string"?r:void 0},pc=(e)=>{if(e.exitCode!==0)return e.stderr.trim()||`Tripwire exited ${e.exitCode}`;if(e.stdout.trim().length===0)return"Tripwire returned no decision";try{let t=JSON.parse(e.stdout);if(!sn(t))return"Tripwire returned invalid JSON";let r=sn(t.hookSpecificOutput)?t.hookSpecificOutput:void 0,n=(r===void 0?void 0:j(r,"permissionDecision"))??j(t,"permissionDecision")??j(t,"permission"),o=(r===void 0?void 0:j(r,"permissionDecisionReason"))??j(t,"permissionDecisionReason")??j(t,"reason")??"Blocked by Tripwire";if(n==="deny"||n==="ask")return o;if(j(t,"decision")==="block"||t.continue===!1)return o;return t.continue===!0||n==="allow"?void 0:"Tripwire returned an unrecognized response"}catch{return"Tripwire returned invalid JSON"}},xf=(e,t=hf)=>{let r=typeof e==="string"?{arguments:[],executable:e,kind:"native"}:e;return(n)=>{n.on("tool_call",async(o,s)=>{try{let a=lc(o,"PreToolUse",s.cwd),c=a.length===1?a[0]:a;if(c===void 0)throw Error("Tripwire could not normalize the Pi tool call");let l=pc(await t(r,c));if(l!==void 0)return{block:!0,reason:l};return{}}catch(a){return{block:!0,reason:`Tripwire failed closed: ${a instanceof Error?a.message:String(a)}`}}}),n.on("tool_result",async(o,s)=>{try{let[a]=lc(o,"PostToolUse",s.cwd);if(a===void 0)throw Error("Tripwire could not normalize the Pi tool result");let c=pc(await t(r,a));if(c!==void 0)s.ui.notify(`Tripwire stopped the session: ${c}`,"error"),s.abort()}catch(a){s.ui.notify(`Tripwire failed closed after tool use: ${a instanceof Error?a.message:String(a)}`,"error"),s.abort()}})}},Rb=xf(af);export{xf as createTripwirePiExtension,Rb as default,lc as hookInputs,sf as resolveShippedHookCommand,pc as tripwirePiDenialReason};