cc-safety-net 2.4.2 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/amp/cc-safety-net/index.ts +2 -2
- package/dist/api.js +1 -1
- package/dist/bin/hook.js +1 -1
- package/dist/chunks/index-26getn55.js +45 -0
- package/dist/chunks/{index-409cdnva.js → index-p4h81vth.js} +2 -2
- package/dist/chunks/{index-jfmgn339.js → index-sp43p448.js} +4 -4
- package/dist/cli.js +113 -113
- package/dist/index.d.ts +5 -0
- package/dist/index.js +11 -1
- package/dist/openclaw/cc-safety-net/index.js +2 -2
- package/dist/openclaw/cc-safety-net/openclaw.plugin.json +1 -1
- package/dist/openclaw/cc-safety-net/package.json +1 -1
- package/dist/opencode-v2.d.ts +3 -0
- package/dist/pi/index.js +2 -2
- package/package.json +16 -4
- package/dist/chunks/index-pmd634p1.js +0 -45
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{ye,A,ve,l,be,f,ae,te,le,u,p}from"./chunks/index-pmd634p1.js";import{X}from"./chunks/index-409cdnva.js";import{he,O}from"./chunks/index-jfmgn339.js";import{resolve as h}from"node:path";function y(){return{"cc-safety-net":{description:"Operate CC Safety Net: explain blocks, rules, integrations, diagnostics",template:X.slice(X.indexOf("# CC Safety Net"))}}}var I=new Set(["powershell","pwsh"]),R=new Set(["bash","dash","ksh","sh","zsh"]);function E(e={}){return async({directory:t,homeDir:i})=>{let o=h(t),a;return{config:async(r)=>{a=r;let c=y(),s=r.command??{};r.command={...c,...s}},"tool.execute.before":async(r,c)=>{let s=i===void 0?l():{...l(),home:i},d=(n,S,D=o)=>{he(s,n,()=>r.sessionID,{agent:"opencode",toolName:S,cwd:D}),v(n)};if(typeof r.tool!=="string"||r.tool.trim()==="")d(A());let m=c.args,g;try{g=te(m)}catch(n){if(!(n instanceof f))throw n;d(A({toolName:r.tool}),r.tool)}let x=N(a?.shell),T=b(r.tool,x),C=L(o,m);if(!le(o)||!C)return d(A({command:g,toolName:r.tool}),r.tool);let P={configCwd:o,executionCwd:C},k=u(r.tool,m,T,P,g??null);try{let n=O(s,k,{guard:{auditAllowed:be(s.env),dependencies:e},audit:{agent:"opencode",getSessionId:()=>r.sessionID}});w(n)}catch(n){if(!(n instanceof p))throw n;if(n.stage==="policy-protection"||n.stage==="config-load"||n.stage==="secret-protection")throw n.cause;w(n.evaluation);return}}}}}function N(e,t=process.platform,i=process.env.SHELL){if(typeof e!=="string"&&t==="win32")return"powershell";let o=typeof e==="string"?e:i;if(typeof o!=="string")return"auto";let a=o.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(!a)return"auto";if(I.has(a))return"powershell";if(R.has(a))return"posix";return"auto"}function b(e,t){if(e==="bash")return{kind:"command",shell:t};return{kind:ae(e)}}function L(e,t){if(!t||typeof t!=="object"||Array.isArray(t))return e;if(!Object.hasOwn(t,"workdir"))return e;let i=t.workdir;if(typeof i!=="string"||i.trim()==="")return null;let o=process.platform==="win32"?_(i):i,a=h(e,o);return le(a)?a:null}function _(e){return e.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(i,o)=>`${o.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(i,o)=>`${o.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(i,o)=>`${o.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(i,o)=>`${o.toUpperCase()}:/`)}function w(e){let t=ye(e,{includeEvidence:!0});if(t)v(t)}function v(e){throw Error(ve(e))}var V=E();export{V as CCSafetyNetPlugin};
|
|
1
|
+
import{ye,P,be,c,xe,f,V,ne,ce,d,p}from"./chunks/index-26getn55.js";import{Q}from"./chunks/index-p4h81vth.js";import{he,D}from"./chunks/index-sp43p448.js";import{resolve as Os}from"node:path";function Ir(){return{"cc-safety-net":{description:"Operate CC Safety Net: explain blocks, rules, integrations, diagnostics",template:Q.slice(Q.indexOf("# CC Safety Net"))}}}var $c=new Set(["powershell","pwsh"]),Bc=new Set(["bash","dash","ksh","sh","zsh"]);function ks(e={}){return async({directory:t,homeDir:r})=>{let n=Os(t),o;return{config:async(s)=>{o=s;let a=Ir(),u=s.command??{};s.command={...a,...u}},"tool.execute.before":async(s,a)=>{Rn({configCwd:n,homeDir:r,tool:s.tool,sessionID:s.sessionID,toolInput:a.args,route:jc(s.tool,_n(o?.shell)),guardDependencies:e})}}}}function Rn({configCwd:e,homeDir:t,tool:r,sessionID:n,toolInput:o,route:s,guardDependencies:a={}}){let u=t===void 0?c():{...c(),home:t},l=(h,g,I=e)=>{he(u,h,()=>n,{agent:"opencode",toolName:g,cwd:I}),Rs(h)};if(typeof r!=="string"||r.trim()==="")l(P());let i;try{i=ne(o)}catch(h){if(!(h instanceof f))throw h;l(P({toolName:r}),r)}let x=qc(e,o);if(!ce(e)||!x){l(P({command:i,toolName:r}),r);return}let S=d(r,o,s,{configCwd:e,executionCwd:x},i??null);try{let h=D(u,S,{guard:{auditAllowed:xe(u.env),dependencies:a},audit:{agent:"opencode",getSessionId:()=>n}});Cs(h)}catch(h){if(!(h instanceof p))throw h;if(h.stage==="policy-protection"||h.stage==="config-load"||h.stage==="secret-protection")throw h.cause;Cs(h.evaluation);return}}function _n(e,t=process.platform,r=process.env.SHELL){if(typeof e!=="string"&&t==="win32")return"powershell";let n=typeof e==="string"?e:r;if(typeof n!=="string")return"auto";let o=n.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(!o)return"auto";if($c.has(o))return"powershell";if(Bc.has(o))return"posix";return"auto"}function jc(e,t){if(e==="bash")return{kind:"command",shell:t};return{kind:V(e)}}function qc(e,t){if(!t||typeof t!=="object"||Array.isArray(t))return e;if(!Object.hasOwn(t,"workdir"))return e;let r=t.workdir;if(typeof r!=="string"||r.trim()==="")return null;let n=process.platform==="win32"?Jc(r):r,o=Os(e,n);return ce(o)?o:null}function Jc(e){return e.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(r,n)=>`${n.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(r,n)=>`${n.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(r,n)=>`${n.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(r,n)=>`${n.toUpperCase()}:/`)}function Cs(e){let t=ye(e,{includeEvidence:!0});if(t)Rs(t)}function Rs(e){throw Error(be(e))}var fe=(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}}},Gc={pipe(){return fe(this,arguments)}},Bt=function(){function e(){}return e.prototype=Gc,e}();var C=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 ie=(e)=>e;var _s=(e)=>()=>e;var St=_s(void 0),As=St;function rt(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 yt(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 jt=(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},qt=new WeakSet;function Jt(e){return typeof e==="string"}function An(e){return typeof e==="number"}function Fs(e){return typeof e==="symbol"}function Cr(e){return Jt(e)||An(e)||Fs(e)}function Tt(e){return typeof e==="function"}function Fn(e){return e!==void 0}function Pn(e){return e!=null}function Ps(e){return!0}function Dn(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Or(e){return typeof e==="object"&&e!==null||Tt(e)}var _=C(2,(e,t)=>Or(e)&&(t in e));function Ds(e){return e instanceof Error}var Y="~effect/interfaces/Hash",F=(e)=>{switch(typeof e){case"number":return Ar(e);case"bigint":return G(e.toString(10));case"boolean":return G(String(e));case"symbol":return G(String(e));case"string":return G(e);case"undefined":return G("undefined");case"function":case"object":if(e===null)return G("null");else if(e instanceof Date){if(Number.isNaN(e.getTime()))return G("Invalid Date");return G(e.toISOString())}else if(e instanceof RegExp)return G(e.toString());else{if(qt.has(e))return kr(e);if(Nn.has(e))return Nn.get(e);let t=Wc(e,()=>{if(Kc(e))return e[Y]();else if(typeof e==="function")return kr(e);else if(e instanceof DataView)return Rr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e)||ArrayBuffer.isView(e))return Rr(e);else if(e instanceof Map)return Vc(e);else if(e instanceof Set)return Hc(e);return zc(e)});return Nn.set(e,t),t}default:throw Error(`BUG: unhandled typeof ${typeof e} - please report an issue at https://github.com/Effect-TS/effect/issues`)}},kr=(e)=>{if(!Un.has(e))Un.set(e,Ar(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)));return Un.get(e)},ue=C(2,(e,t)=>e*53^t),_r=(e)=>e&3221225471|e>>>1&1073741824,Kc=(e)=>_(e,Y),Ar=(e)=>{if(e!==e)return G("NaN");if(e===1/0)return G("Infinity");if(e===-1/0)return G("-Infinity");let t=e|0;if(t!==e)t^=e*4294967295;while(e>4294967295)t^=e/=4294967295;return _r(t)},G=(e)=>{let t=5381,r=e.length;while(r)t=t*33^e.charCodeAt(--r);return _r(t)},Ln=(e,t)=>{let r=12289;for(let n of t)r^=ue(F(n),F(e[n]));return _r(r)},zc=(e)=>Ln(e,jt(e)),$n=(e,t)=>(r)=>{let n=e;for(let o of r)n^=t(o);return _r(n)},Rr=$n(6151,F),Vc=$n(G("Map"),([e,t])=>ue(F(e),F(t))),Hc=$n(G("Set"),F),Un=new WeakMap,Nn=new WeakMap,Mn=new WeakSet;function Wc(e,t){if(Mn.has(e))return G("[Circular]");Mn.add(e);let r=t();return Mn.delete(e),r}var X="~effect/interfaces/Equal";function H(){if(arguments.length===1)return(e)=>ot(e,arguments[0]);return ot(arguments[0],arguments[1])}function ot(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(qt.has(e)||qt.has(t))return!1;return Xc(e,t,Yc)}function Zc(e,t,r){let n=Bn.has(e),o=jn.has(t);if(n&&o)return!0;if(n||o)return!1;Bn.add(e),jn.add(t);let s=r();return Bn.delete(e),jn.delete(t),s}var Bn=new WeakSet,jn=new WeakSet;function Yc(e,t){if(F(e)!==F(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=Ns(e),n=Ns(t);if(r!==n)return!1;let o=r&&n;if(typeof e==="function"&&!o)return!1;return Zc(e,t,()=>{if(o)return e[X](t);else if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;return Qc(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 Us(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(a.buffer,a.byteOffset,a.byteLength))}return Us(e,t)}else if(e instanceof Map){if(!(t instanceof Map)||e.size!==t.size)return!1;return ru(e,t)}else if(e instanceof Set){if(!(t instanceof Set)||e.size!==t.size)return!1;return ou(e,t)}return eu(e,t)})}function Xc(e,t,r){let n=Fr.get(e);if(!n)n=new WeakMap,Fr.set(e,n);else if(n.has(t))return n.get(t);let o=r(e,t);n.set(t,o);let s=Fr.get(t);if(!s)s=new WeakMap,Fr.set(t,s);return s.set(e,o),o}var Fr=new WeakMap;function Qc(e,t){for(let r=0;r<e.length;r++)if(!ot(e[r],t[r]))return!1;return!0}function Us(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 eu(e,t){let r=jt(e),n=jt(t);if(r.size!==n.size)return!1;for(let o of r)if(!n.has(o)||!ot(e[o],t[o]))return!1;return!0}function tu(e,t){return function(n,o){let s=Array.from(o);for(let[a,u]of n){let l=!1;for(let i=0;i<s.length;i++){let[x,T]=s[i];if(e(a,x)&&t(u,T)){s[i]=s[s.length-1],s.pop(),l=!0;break}}if(!l)return!1}return!0}}var ru=tu(ot,ot);function nu(e){return function(r,n){let o=Array.from(n);for(let s of r){let a=!1;for(let u=0;u<o.length;u++){let l=o[u];if(e(s,l)){o[u]=o[o.length-1],o.pop(),a=!0;break}}if(!a)return!1}return!0}}var ou=nu(ot),Ns=(e)=>_(e,X);var Gt=Symbol.for("~effect/Redactable"),su=(e)=>_(e,Gt);function wt(e){if(su(e))return qn(e);return e}function qn(e){return e[Gt](globalThis[It]?.context??au)}var It="~effect/Fiber/currentFiber",Ms=new Map,au={"~effect/Context":{},base:Ms,depth:0,mapUnsafe:Ms,pipe(){return fe(this,arguments)}};function N(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,x)=>{let T=i?.constructor;return T&&T!==Object.prototype.constructor&&T.name?`${T.name}(${x})`:x},u=(i)=>{try{return Reflect.ownKeys(i)}catch{return["[ownKeys threw]"]}};function l(i,x=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 iu;n.add(i);let T;if(Gt in i)T=l(qn(i),x);else if(Array.isArray(i))T=!o||i.length<=1?`[${i.map((S)=>l(S,x)).join(",")}]`:`[
|
|
2
|
+
${s(x+1)}${i.map((S)=>l(S,x+1)).join(`,
|
|
3
|
+
`+s(x+1))}
|
|
4
|
+
${s(x)}]`;else if(i instanceof Date)T=Ls(i);else if(!t?.ignoreToString&&_(i,"toString")&&typeof i.toString==="function"&&i.toString!==Object.prototype.toString&&i.toString!==Array.prototype.toString){let S=cu(i);T=i instanceof Error&&i.cause?`${S} (cause: ${l(i.cause,x)})`:S}else if(Symbol.iterator in i)T=`${i.constructor.name}(${l(Array.from(i),x)})`;else{let S=u(i);if(!o||S.length<=1){let h=`{${S.map((g)=>`${Kt(g)}:${l(i[g],x)}`).join(",")}}`;T=a(i,h)}else{let h=`{
|
|
5
|
+
${S.map((g)=>`${s(x+1)}${Kt(g)}: ${l(i[g],x+1)}`).join(`,
|
|
6
|
+
`)}
|
|
7
|
+
${s(x)}}`;T=a(i,h)}}return n.delete(i),T}return String(i)}return l(e,0)}var iu="[Circular]";function Kt(e){return typeof e==="string"?JSON.stringify(e):String(e)}function Ls(e){try{return e.toISOString()}catch{return"Invalid Date"}}function cu(e){try{let t=e.toString();return typeof t==="string"?t:String(t)}catch{return"[toString threw]"}}function Jn(e,t){let r=[];return JSON.stringify(e,function(n,o){let s=Object.getOwnPropertyDescriptor(this,n)?.value,a=_(s,Gt)?wt(s):wt(o);if(typeof a==="bigint")return N(a);if(typeof a!=="object"||a===null)return a;while(r.length>0&&r[r.length-1]!==this)r.pop();if(r.includes(a))return;return r.push(a),a},t?.space)??"null"}var zt=Symbol.for("nodejs.util.inspect.custom"),st=(e)=>{try{if(e=wt(e),_(e,"toJSON")&&Tt(e.toJSON)&&e.toJSON.length===0)return e.toJSON();else if(Array.isArray(e))return e.map(st);return e}catch{return"[toJSON threw]"}};var Ip={toJSON(){return st(this)},[zt](){return this.toJSON()},toString(){return N(this.toJSON())}};class Je{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 Je(this.self)}}var uu=()=>{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"]},Ae=uu();function Ie(e,t,r){if(t==="__proto__")Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0});else e[t]=r}function $s(e,t){for(let r of Reflect.ownKeys(t))if(Object.prototype.propertyIsEnumerable.call(t,r))Ie(e,r,t[r])}var it="~effect/Effect",at="~effect/Exit",lu={_A:ie,_E:ie,_R:ie},js=`${it}/identifier`,b=`${it}/args`,B=`${it}/evaluate`,pe=`${it}/successCont`,ve=`${it}/failureCont`,Ge=`${it}/ensureCont`,ct=Symbol.for("effect/Effect/Yield"),ut={pipe(){return fe(this,arguments)},toJSON(){return{...this}},toString(){return N(this.toJSON(),{ignoreToString:!0,space:2})},[zt](){return this.toJSON()}},Pp={[Y](){return Ln(this,Object.keys(this))},[X](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]||!H(this[t[n]],e[t[n]]))return!1;return!0}},fu={[it]:lu,...ut,[Symbol.iterator](){return new Je(this)},toJSON(){return{_id:"Effect",op:this[js],...b in this?{args:this[b]}:void 0}}};var qs=(e)=>_(e,at),Vt="~effect/Cause",Pr="~effect/Cause/Reason",Dr=(e)=>_(e,Vt);class Ke{[Vt];reasons;constructor(e){this[Vt]=Vt,this.reasons=e}pipe(){return fe(this,arguments)}toJSON(){return{_id:"Cause",failures:this.reasons.map((e)=>e.toJSON())}}toString(){return`Cause(${N(this.reasons)})`}[zt](){return this.toJSON()}[X](e){return Dr(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,r)=>H(t,e.reasons[r]))}[Y](){return Rr(this.reasons)}}var Bs=new WeakMap;class Ht{[Pr];annotations;_tag;constructor(e,t,r){if(this[Pr]=Pr,this._tag=e,t!==Wt&&typeof r==="object"&&r!==null&&t.size>0){let n=Bs.get(r);if(n)t=new Map([...n,...t]);Bs.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 fe(this,arguments)}toString(){return N(this)}[zt](){return this.toString()}}var Wt=new Map;class Zt extends Ht{error;constructor(e,t=Wt){super("Fail",t,e);this.error=e}toString(){return`Fail(${N(this.error)})`}toJSON(){return{_tag:"Fail",error:this.error}}[X](e){return Qt(e)&&H(this.error,e.error)&&H(this.annotations,e.annotations)}[Y](){return ue(G(this._tag))(ue(F(this.error))(F(this.annotations)))}}var Yt=(e)=>new Ke(e);var Js=(e)=>new Ke([new Zt(e)]);class zn extends Ht{defect;constructor(e,t=Wt){super("Die",t,e);this.defect=e}toString(){return`Die(${N(this.defect)})`}toJSON(){return{_tag:"Die",defect:this.defect}}[X](e){return Vn(e)&&H(this.defect,e.defect)&&H(this.annotations,e.annotations)}[Y](){return ue(G(this._tag))(ue(F(this.defect))(F(this.annotations)))}}var Gs=(e)=>new Ke([new zn(e)]),Xt=C((e)=>Dr(e[0]),(e,t,r)=>{if(t.mapUnsafe.size===0)return e;return new Ke(e.reasons.map((n)=>n.annotate(t,r)))}),Qt=(e)=>e._tag==="Fail",Vn=(e)=>e._tag==="Die",Ur=(e)=>e._tag==="Interrupt";function pu(e){return ze("Effect.evaluate: Not implemented")}var De=(e)=>({...fu,[js]:e.op,[B]:e[B]??pu,[pe]:e[pe],[ve]:e[ve],[Ge]:e[Ge]}),Te=(e)=>{let t=De(e);return function(){let r=Object.create(t);return r[b]=e.single===!1?arguments:arguments[0],r}},Ks=(e)=>{let t={[at]:at,_tag:e.op,get[e.prop](){return this[b]},...De(e),toString(){return`${e.op}(${N(this[b])})`},toJSON(){return{_id:"Exit",_tag:e.op,[e.prop]:this[b]}},[X](r){return qs(r)&&r._tag===this._tag&&H(this[b],r[b])},[Y](){return ue(G(e.op),F(this[b]))}};return function(r){let n=Object.create(t);return n[b]=r,n}},me=Ks({op:"Success",prop:"value",[B](e){let t=e.getCont(pe);return t?t[pe](this[b],e,this):e.yieldWith(this)}}),Hn={key:"effect/Cause/StackTrace"},zs={key:"effect/Cause/InterruptorStackTrace"},Ce=Ks({op:"Failure",prop:"cause",[B](e){let t=this[b],r=!1;if(e.currentStackFrame)t=Xt(t,{mapUnsafe:new Map([[Hn.key,e.currentStackFrame]])}),r=!0;let n=e.getCont(ve);while(e.interruptible&&e._interruptedCause&&n)n=e.getCont(ve);return n?n[ve](t,e,r?void 0:this):e.yieldWith(r?Ce(t):this)}}),vt=(e)=>Ce(Js(e)),ze=(e)=>Ce(Gs(e)),Ct=Te({op:"WithFiber",[B](e){return this[b](e)}}),mu=function(){class e extends globalThis.Error{}let t=De({op:"YieldableError",[B](){return vt(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),Nr=function(){let e=Symbol.for("effect/Data/Error/plainArgs");return class extends mu{constructor(r){super(r?.message,r?.cause?{cause:r.cause}:void 0);if(r)$s(this,r),Object.defineProperty(this,e,{value:r,enumerable:!1})}toJSON(){return{...this[e],...this}}}}(),er=(e)=>{class t extends Nr{_tag=e}return t.prototype.name=e,t};var Kn="~effect/Cause/Done";var Dp={[Kn]:Kn,_tag:"Done",value:void 0};var Vs=(e)=>De({op:e.label,[B]:e.evaluate});var Hs="~effect/data/Option",Ws={[Hs]:{_A:(e)=>e},...ut,[Symbol.iterator](){return new Je(this)}},hu=Object.defineProperty(Object.assign(Object.create(Ws),{_tag:"Some",_op:"Some",[X](e){return Wn(e)&&Yn(e)&&H(this.value,e.value)},[Y](){return ue(F(this._tag))(F(this.value))},toString(){return`some(${N(this.value)})`},toJSON(){return{_id:"Option",_tag:this._tag,value:st(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),xu=F("None"),gu=Object.assign(Object.create(Ws),{_tag:"None",_op:"None",valueOrUndefined:void 0,[X](e){return Wn(e)&&Zn(e)},[Y](){return xu},toString(){return"none()"},toJSON(){return{_id:"Option",_tag:this._tag}}}),Wn=(e)=>_(e,Hs),Zn=(e)=>e._tag==="None",Yn=(e)=>e._tag==="Some",Zs=Object.create(gu),Ys=(e)=>{let t=Object.create(hu);return t.value=e,t};var Xs="~effect/data/Result",Qs={[Xs]:{_A:(e)=>e,_E:(e)=>e},...ut,[Symbol.iterator](){return new Je(this)}},yu=Object.assign(Object.create(Qs),{_tag:"Success",_op:"Success",[X](e){return Xn(e)&&ea(e)&&H(this.success,e.success)},[Y](){return ue(F(this._tag))(F(this.success))},toString(){return`success(${N(this.success)})`},toJSON(){return{_id:"Result",_tag:this._tag,value:st(this.success)}}}),Tu=Object.assign(Object.create(Qs),{_tag:"Failure",_op:"Failure",[X](e){return Xn(e)&&Qn(e)&&H(this.failure,e.failure)},[Y](){return ue(F(this._tag))(F(this.failure))},toString(){return`failure(${N(this.failure)})`},toJSON(){return{_id:"Result",_tag:this._tag,failure:st(this.failure)}}}),Xn=(e)=>_(e,Xs),Qn=(e)=>e._tag==="Failure",ea=(e)=>e._tag==="Success",ta=(e)=>{let t=Object.create(Tu);return t.failure=e,t},ra=(e)=>{let t=Object.create(yu);return t.success=e,t};var Ue=()=>Zs,Fe=Ys;var tr=Zn,eo=Yn;var to=C(2,(e,t)=>tr(e)?Ue():Fe(t(e.value)));var na=C(2,(e,t)=>tr(e)?Ue():t(e.value)?Fe(e.value):Ue());var oa="~effect/Context/Service",sa=function(){function e(){}let t=e;Object.setPrototypeOf(t,wu);let r=(n,o)=>{if(t.key=n,o?.defaultValue)t[no]=no,t.defaultValue=o.defaultValue;if(o?.make)t.make=o.make;if(o?.fiberCached)aa.add(n);return t};return arguments.length>0?r(arguments[0],arguments[1]):r},wu={[oa]:oa,...Vs({label:"Service",evaluate(e){return me(rr(e.context,this))}}),toJSON(){return{_id:"Service",key:this.key}},of(e){return e},context(e){return io(this,e)},use(e){return Ct((t)=>e(rr(t.context,this)))},useSync(e){return Ct((t)=>me(e(rr(t.context,this))))}},aa=new Set,no="~effect/Context/Reference",ia="~effect/Context",Iu=8,vu=8,oo=(e,t,r,n)=>{let o=Object.create(Cu);return o.cacheRoot=e??o,o.base=t,o.overlay=r,o.depth=n,o._flat=void 0,o.baseHits=0,o},ca=(e,t)=>{if(!t)return;ca(e,t.parent),e.set(t.key,t.value)},ua=(e)=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return ca(t,e.overlay),e._flat=t};var so=Symbol(),la=(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 so;if(r.overlay&&++r.baseHits>=vu)r.base=ua(r),r.overlay=void 0,r.depth=0;return n},$r=(e)=>oo(void 0,e,void 0,0),Cu={get mapUnsafe(){return ua(this)},...ut,[ia]:{_Services:(e)=>e},toJSON(){return{_id:"Context",services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[X](e){if(!Ou(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)||!H(o,r.get(n)))return!1;return!0},[Y](){return Ar(this.mapUnsafe.size)}},fa=(e,t)=>e.cacheRoot===t.cacheRoot,Ou=(e)=>_(e,ia);var ku=(e)=>!!e[no],ao=()=>Ru,Ru=$r(new Map),io=(e,t)=>$r(new Map([[e.key,t]])),pa=C(3,(e,t,r)=>_u(e,t.key,r)),_u=(e,t,r)=>{let n=e,o=aa.has(t)?void 0:n.cacheRoot;if(n.depth>=Iu){let s=new Map(n.mapUnsafe);return s.set(t,r),oo(o,s,void 0,0)}return oo(o,n.base,{key:t,value:r,parent:n.overlay},n.depth+1)};var Br=(e,t)=>{let r=la(e,t);return r===so?void 0:r},ma=C(2,(e,t)=>{let r=la(e,t.key);if(r===so){if(ku(t))return Au(t);throw Fu(t)}return r}),rr=ma,ro="~effect/Context/defaultValue",Au=(e)=>{if(ro in e)return e[ro];return e[ro]=e.defaultValue()},Fu=(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 Ne=sa;var uo=(e)=>e.length>0;var nr=ra,lt=ta;var jr=Qn;var qr=C(2,(e,{onFailure:t,onSuccess:r})=>jr(e)?t(e.failure):r(e.success));var fo=globalThis.Array;var Ot=(e)=>fo.isArray(e)?e:fo.from(e);var po=C(2,(e,t)=>[...e,t]),Du=C(2,(e,t)=>Ot(e).concat(Ot(t)));var rm=fo.isArray;var mo=uo,Jr=uo;var Uu=(e,t)=>{let r=F(t),n=e.get(r);if(n===void 0)return e.set(r,[t]),!0;for(let o of n)if(H(o,t))return!1;return n.push(t),!0};var da=C(2,(e,t)=>{let r=Ot(e),n=Ot(t);if(Jr(r))return Jr(n)?Nu(Du(r,n)):r;return n});var Gr=()=>[];var ha=C(2,(e,t)=>e.map(t));var Nu=(e)=>{let t=Ot(e);if(t.length<2)return[...t];let r=new Map,n=[];for(let o of t)if(Uu(r,o))n.push(o);return n};var xo=Ne("effect/Scheduler",{fiberCached:!0,defaultValue:()=>new Kr}),xa="setImmediate"in globalThis?(e)=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:(e)=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},Mu=(e)=>{let t=!1;return Promise.resolve().then(()=>{if(!t)e()}),()=>{t=!0}};class ga{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 Kr{executionMode;setImmediate;constructor(e="async",t){this.executionMode=e,this.setImmediate=t??(e==="sync"?Mu:xa)}shouldYield(e){return e.currentOpCount>=e.maxOpsBeforeYield}makeDispatcher(){return new Sa(this.setImmediate)}}class Sa{tasks=new ga;running=void 0;setImmediate;constructor(e=xa){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 ya=Ne("effect/Scheduler/MaxOpsBeforeYield",{fiberCached:!0,defaultValue:()=>2048}),Ta=Ne("effect/Scheduler/PreventSchedulerYield",{fiberCached:!0,defaultValue:()=>!1});var Ea=er;var ba="~effect/encoding/EncodingError";class Vr extends Ea("EncodingError"){[ba]=ba}var Hr=(e)=>typeof e==="string"?wa(Bu.encode(e)):wa(e),Wr=(e)=>{let t=ju(e),r=t.length;if(r%4!==0)return lt(new Vr({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 lt(new Vr({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,u=0;a<r;a+=4,u+=3){let l=zr(t.charCodeAt(a))<<18|zr(t.charCodeAt(a+1))<<12|zr(t.charCodeAt(a+2))<<6|zr(t.charCodeAt(a+3));s[u]=l>>16,s[u+1]=l>>8&255,s[u+2]=l&255}return nr(s)}catch(o){return lt(new Vr({kind:"Decode",module:"Base64",input:t,message:o instanceof Error?o.message:"Invalid input"}))}};var Bu=new TextEncoder;var ju=(e)=>e.replace(/[\n\r]/g,""),wa=(e)=>{let t=e.length,r="",n;for(n=2;n<t;n+=3)r+=Me[e[n-2]>>2],r+=Me[(e[n-2]&3)<<4|e[n-1]>>4],r+=Me[(e[n-1]&15)<<2|e[n]>>6],r+=Me[e[n]&63];if(n===t+1)r+=Me[e[n-2]>>2],r+=Me[(e[n-2]&3)<<4],r+="==";if(n===t)r+=Me[e[n-2]>>2],r+=Me[(e[n-2]&3)<<4|e[n-1]>>4],r+=Me[(e[n-1]&15)<<2],r+="=";return r};function zr(e){if(e>=Ia.length)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);let t=Ia[e];if(t===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return t}var Me=["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","+","/"],Ia=[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 qu=[];for(let e=0;e<256;e++)qu.push(e.toString(16).padStart(2,"0"));var Ca="effect/Tracer/ParentSpan";var Oa="effect/Tracer";var ka="effect/observability/Metric/FiberRuntimeMetricsKey";var Ra=Ne("effect/References/CurrentStackFrame",{fiberCached:!0,defaultValue:St});var _a=Ne("effect/References/CurrentLogLevel",{fiberCached:!0,defaultValue:()=>"Info"}),Aa=Ne("effect/References/MinimumLogLevel",{fiberCached:!0,defaultValue:()=>"Info"});class Na extends Ht{fiberId;constructor(e,t=Wt){super("Interrupt",t,"Interrupted");this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:"Interrupt",fiberId:this.fiberId}}[X](e){return Ur(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[Y](){return ue(G(`${this._tag}:${this.fiberId}`))(kr(this.annotations))}}var Ma=(e)=>new Ke([new Na(e)]);var To=(e)=>{for(let t=0;t<e.reasons.length;t++){let r=e.reasons[t];if(r._tag==="Fail")return nr(r.error)}return lt(e)};var La=(e)=>e.reasons.some(Ur);var Eo=C(2,(e,t)=>{if(e.reasons.length===0)return t;else if(t.reasons.length===0)return e;let r=new Ke(da(e.reasons,t.reasons));return H(e,r)?e:r}),$a=C(2,(e,t)=>{let r=!1,n=e.reasons.map((o)=>{if(Qt(o))return r=!0,new Zt(t(o.error),o.annotations);return o});return r?Yt(n):e});var Fa="~effect/Fiber",Zu={_A:ie,_E:ie},Yu={id:0},Xu=()=>globalThis[It];class bo{constructor(e,t=!0){this[Fa]=Zu,this.setContext(e),this.id=++Yu.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)}[Fa];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 rr(this.context,e)}addObserver(e){if(this._exit)return e(this._exit),As;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=Ma(e);if(this.currentStackFrame)r=Xt(r,io(Hn,this.currentStackFrame));if(t)r=Xt(r,t);if(this._interruptedCause=this._interruptedCause?Eo(this._interruptedCause,r):r,this.interruptible)if(this._running)this._deferredInterrupt=!0;else this.evaluate(Oe(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===ct)return;let r=Pa.interruptChildren&&Pa.interruptChildren(this);if(r!==void 0)return this.evaluate(ge(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=ao()}runLoop(e){let t=globalThis[It];globalThis[It]=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=Oe(this._interruptedCause);if(this.currentOpCount++,!n&&!this.currentPreventYield&&this.currentScheduler.shouldYield(this)){n=!0;let s=o;o=ge(Ga,()=>s)}if(o=this.currentTracerContext?this.currentTracerContext(o,this):o[B](this),o===ct){let s=this._yielded;if(at in s)return this._deferredInterrupt=!1,this._yielded=void 0,s;else if(this._deferredInterrupt){this._yielded=void 0,s();continue}return ct}}}catch(s){if(!_(o,B))return ze(`Fiber.runLoop: Not a valid effect: ${String(o)}`);return this.runLoop(ze(s))}finally{this._running=r,globalThis[It]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,Qu;while(!0){let t=this._stack.pop();if(!t)return;let r=t[Ge]&&t[Ge](this);if(r)return r[e]=r,r;if(t[e])return t}}yieldWith(e){return this._yielded=e,ct}children(){return this._children??=new Set}pipe(){return fe(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&fa(t,e))return;let r=this.getRef(xo);if(r!==this.currentScheduler)this.currentScheduler=r,this._dispatcher=void 0;this.currentSpan=Br(e,Ca),this.currentLogLevel=this.getRef(_a),this.minimumLogLevel=this.getRef(Aa),this.currentStackFrame=this.getRef(Ra),this.maxOpsBeforeYield=this.getRef(ya),this.currentPreventYield=this.getRef(Ta),this.runtimeMetrics=Br(e,ka);let n=Br(e,Oa);this.currentTracerContext=n?n.context:void 0}get currentSpanLocal(){return this.currentSpan?._tag==="Span"?this.currentSpan:void 0}}var Qu={[pe](e,t){return Oe(t._interruptedCause)},[ve](e,t){return Oe(t._interruptedCause)}},Pa={interruptChildren:void 0},Ba=(e)=>{if(!e.currentStackFrame)return;let t=new Map;return t.set(zs.key,e.currentStackFrame),$r(t)};var el=(e)=>wo((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((u)=>{n.push(u),s()});return}t(de(n))}return s(),ja(()=>o?.())});var Da=(e)=>Ct((t)=>{let r=Ba(t),n=Gr();for(let o of e)o.interruptUnsafe(t.id,r),n.push(o);return Io(el(n))});var de=me,Oe=Ce,Rt=vt,ja=Te({op:"Sync",[B](e){let t=this[b](),r=e.getCont(pe);return r?r[pe](t,e):e.yieldWith(me(t))}}),Ve=Te({op:"Suspend",[B](e){return this[b]()}});var qa=qr({onFailure:Rt,onSuccess:de});var Ja=Te({op:"Yield",[B](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{if(t)return;e.evaluate(Le)},this[b]??0),e.yieldWith(()=>{t=!0})}}),Ga=Ja(0);var Ka=de(Ue());var za=(e)=>Ve(()=>Oe(Ae(e))),or=(e)=>ze(e),Va=(e)=>Ve(()=>Rt(Ae(e))),kt=de(void 0);var Ha=(e)=>{let t=typeof e==="function"?e:e.try,r=typeof e==="function"?(n)=>new Yr(n,"An error occurred in Effect.try"):e.catch;return Ve(()=>{try{return de(Ae(t))}catch(n){return Rt(Ae(()=>r(n)))}})};var Wa=(e)=>{let t=typeof e==="function"?e:e.try,r=typeof e==="function"?(n)=>new Yr(n,"An error occurred in Effect.tryPromise"):e.catch;return Za(function(n,o){let s=(a)=>{try{n(Rt(Ae(()=>r(a))))}catch(u){n(or(u))}};try{Ae(()=>t(o)).then((a)=>n(de(a)),s)}catch(a){s(a)}},t.length!==0)};var Za=Te({op:"Async",single:!1,[B](e){let t=Ae(()=>this[b][0].bind(e.currentScheduler)),r=!1,n=!1,o=this[b][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 ct;return e._stack.push(tl(()=>(r=!0,o?.abort(),s??Le))),ct}}),tl=Te({op:"AsyncFinalizer",[Ge](e){if(e.interruptible)e.interruptible=!1,e._stack.push(ko)},[ve](e,t){return La(e)?ge(this[b](),()=>Oe(e)):Oe(e)}}),wo=(e)=>Za(e,e.length>=2);var Ya=(...e)=>Ve(()=>go(e.length===1?e[0]():e[1].call(e[0].self)));var rl=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0});var Xa=(e,...t)=>rl(e.length,t.length===0?function(){return Ua(()=>e.apply(this,arguments))}:function(){let r=Ua(()=>e.apply(this,arguments));for(let n of t)r=n(r);return r}),Ua=(e)=>{try{let t=e(),r=void 0;while(!0){let n=t.next(r);if(n.done)return de(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 Ve(()=>{if(s)return s=!1,ge(n.value,(a)=>go(t,a));else return Ve(()=>go(e()))})}}}catch(t){return or(t)}},go=Te({op:"Iterator",single:!1,[pe](e,t){let r=this[b][0];while(!0){let n=r.next(e);if(n.done)return de(n.value);if(!K(n.value))return t._stack.push(this),n.value;else if(n.value._tag==="Failure")return n.value;e=n.value.value}},[B](e){return this[pe](this[b][1],e)}});var Io=(e)=>ge(e,(t)=>Le);var ge=C(2,(e,t)=>{let r=Object.create(nl);return r[b]=e,r[pe]=t.length!==1?(n)=>t(n):t,r}),nl=De({op:"OnSuccess",[B](e){return e._stack.push(this),this[b]}});var K=(e)=>(at in e),Qa=C(2,(e,t)=>{if(K(e))return e._tag==="Success"?t(e.value):e;return ge(e,t)});var ei=C(2,(e,t)=>ge(e,(r)=>de(Ae(()=>t(r))))),ti=C(2,(e,t)=>K(e)?ni(e,t):ei(e,t)),ri=C(2,(e,t)=>K(e)?oi(e,t):ai(e,t));var vo=(e)=>e._tag==="Success";var Le=me(void 0),ni=C(2,(e,t)=>e._tag==="Success"?me(t(e.value)):e),oi=C(2,(e,t)=>{if(e._tag==="Success")return e;let r=To(e.cause);if(jr(r))return e;return vt(t(r.success))});var Zr=C(2,(e,t)=>{let r=Object.create(ol);return r[b]=e,r[ve]=t.length!==1?(n)=>t(n):t,r}),ol=De({op:"OnFailure",[B](e){return e._stack.push(this),this[b]}});var si=C(3,(e,t,r)=>Zr(e,(n)=>{let o=t(n);return jr(o)?Oe(o.failure):Ae(()=>r(o.success,n))})),Co=C(2,(e,t)=>si(e,To,(r)=>t(r)));var ai=C(2,(e,t)=>Co(e,(r)=>Va(()=>t(r))));var ii=(e)=>Co(e,or);var Dm=De({op:"OnSuccessAndFailure",[B](e){return e._stack.push(this),this[b]}});var Oo=(e)=>K(e)?me(e):sl(e),sl=Te({op:"Exit",[B](e){return e._stack.push(this),this[b]},[pe](e,t,r){return de(r??me(e))},[ve](e,t,r){return de(r??Ce(e))}});var al=(e,t)=>vo(e)?t:Zr(t,(r)=>Oe(Eo(e.cause,r)));var il=Te({op:"OnExit",single:!1,[B](e){return e._stack.push(this),this[b][0]},[Ge](e){if(e.interruptible&&this[b][2]!==!0)e._stack.push(ko),e.interruptible=!1},[pe](e,t,r){r??=me(e);let n=this[b][1](r);return n?ge(n,(o)=>r):r},[ve](e,t,r){r??=Ce(e);let n=this[b][1](r);return n?ge(al(r,n),(o)=>r):r}});var ci=(e)=>Ct((t)=>{if(!t.interruptible)return e;return t.interruptible=!1,t._stack.push(ko),e}),cl=Te({op:"SetInterruptible",[Ge](e){if(e.interruptible=this[b],e._interruptedCause&&e.interruptible)return()=>Oe(e._interruptedCause)}}),ko=cl(!0);var ul=Te({op:"While",[pe](e,t){if(this[b].step(e),this[b].while())return t._stack.push(this),this[b].body();return Le},[B](e){if(this[b].while())return e._stack.push(this),this[b].body();return Le}});var ll=(e)=>{let{onItem:t,step:r}=e,n=(o,s,a,u)=>{for(;a<u;a++){let l=s[a],i=t(o,l,a);if(!K(i))return ge(Oo(i),(T)=>r(o,l,T,a)??n(o,s,a+1,u)??kt);let x=r(o,l,i,a);if(x)return x._tag==="Failure"?x:void 0}};return(o,s,a)=>{let u=0,l=a?.end??s.length,i=a?.concurrency??1;if(i===1)return n(o,s,0,l);let x=a?.orderedStep===!0,T=!1,S,h,g,I=!1,m,y,E=u,w=x?Array(l):void 0,v=(J)=>{let U=ze(J);return m=U,T=!0,I=!0,h&&h.size>0?ge(ci(Da(Array.from(h))),()=>U):U},z=(J,U,re)=>{if(!x)return r(o,J,U,re);if(m)return m;w[re]=U;while(E<l){let k=w[E];if(k===void 0)return;w[E]=void 0;let R=E++,M=r(o,s[R],k,R);if(M)return M}},q=()=>{let J=!1;for(;!m&&u<l;u++){let U=s[u],re=y??t(o,U,u);if(K(re)){if(m=z(U,re,u),m)break}else if(!S)return wo((k)=>{S=Xu(),h=new Set,y=re,g=k;let R;try{R=q()}catch(M){return k(v(M))}if(R)return k(R);return Ve(()=>(m=Le,I=!0,h?Da(h):kt))});else{y=void 0;let k=fl(S,re,!0,!0,"inherit");if(k._exit){if(m=z(U,k._exit,u),m)break;continue}h.add(k);let R=u;if(k.addObserver((M)=>{h.delete(k);try{if(m){if(!I&&M._tag==="Failure")for(let L of M.cause.reasons)if(L._tag==="Interrupt")continue;else if(m._tag==="Failure")m.cause.reasons.push(L);else m=Ce(Yt([L]))}else{let L=z(U,M,R);if(L)m=L._tag==="Failure"?Ce(Yt(L.cause.reasons.slice())):L,q()}if(J){let L=q();if(L)g(L)}else if(T&&h.size===0)g(m??kt)}catch(L){g(v(L))}}),h.size<i)continue;J=!0,u++;return}}if(T=!0,m){if(h&&h.size>0){let U=Ba(S);h.forEach((re)=>re.interruptUnsafe(S.id,U));return}if(g||m._tag==="Failure")return m}else if(g){if(!h)return Le;else if(h.size===0)g(kt)}};return q()}},sr=()=>ll;var fl=(e,t,r=!1,n=!1,o=!1)=>{let s=e,a=o==="inherit"?s.interruptible:!o,u=new bo(s.context,a);if(r)u.evaluate(t);else s.currentDispatcher.scheduleTask(()=>u.evaluate(t),0);if(!n&&!u._exit)s.children().add(u),u.addObserver(()=>s._children.delete(u));return u};var ui=(e)=>(t,r)=>{let n=new bo(r?.scheduler?pa(e,xo,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 li=(e)=>{let t=ui(e);return(r)=>{if(K(r))return r;let n=new Kr("sync"),o=t(r,{scheduler:n});return o._dispatcher?.flush(),o._exit??ze(new Ro(o))}},fi=li(ao());var So="~effect/Cause/AsyncFiberError";class Ro extends er("AsyncFiberError"){[So]=So;constructor(e){super({message:"An asynchronous Effect was executed with Effect.runSync",fiber:e})}}var yo="~effect/Cause/UnknownError";class Yr extends er("UnknownError"){[yo]=yo;constructor(e,t){super({message:t,cause:e})}}var pl="~effect/Logger",Um={[pl]:{_Message:ie,_Output:ie},pipe(){return fe(this,arguments)}};var ft={bold:"1",red:"31",green:"32",yellow:"33",blue:"34",cyan:"36",white:"37",gray:"90",black:"30",bgBrightRed:"101"},Nm={None:[],All:[],Trace:[ft.gray],Debug:[ft.blue],Info:[ft.green],Warn:[ft.yellow],Error:[ft.red],Fatal:[ft.bgBrightRed,ft.black]};var pi=me,Ao=Ce,_t=vt;var At=Le;var Xr=vo;var mi=Qt;var Qr=$a;var di=Wa,j=de,Do=Ka;var hi=kt;var ml=Ya,A=Rt;var Uo=za,en=or,tn=Ha;var xi=qa;var $e=ge;var ar=Oo;var dl=Io;var ir=Zr;var hl=ii;var cr=fi;var Ft=ti,No=ri;var Ee=Qa;var Mo=Xa;function Lo(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function gi(e){return(t)=>Lo(t)?.[e]}var $o="~structural";var rn="~sentinels",nn="~constructor";var Si=gi("brands");var O=Symbol();var ke=pi,Be=ke(O),W=ke(O),on=(e)=>e===O?Ue():Fe(e),Bo=(e)=>e._tag==="None"?Be:ke(e.value);var ur="~effect/SchemaIssue/Issue";function Jo(e){return _(e,ur)&&e[ur]===ur}class Re{[ur]=ur;constructor(e,t){if(t?.reportInput===!0&&e!==O)this.input=e}}class Go extends Re{_tag="Filter";filter;issue;constructor(e,t,r,n){super(r,n);this.filter=e,this.issue=t}}class Ko extends Re{_tag="Encoding";ast;issue;constructor(e,t,r,n){super(r,n);this.ast=e,this.issue=t}}class Pe extends Re{_tag="Pointer";path;issue;constructor(e,t){super();this.path=e,this.issue=t}}class lr extends Re{_tag="MissingKey";annotations;constructor(e){super();this.annotations=e}}class sn extends Re{_tag="UnexpectedKey";ast;constructor(e,t,r){super(t,r);this.ast=e}}class ee extends Re{_tag="Composite";ast;issues;constructor(e,t,r,n){super(r,n);this.ast=e,this.issues=t}}class we extends Re{_tag="InvalidType";ast;constructor(e,t,r){super(t,r);this.ast=e}}class le extends Re{_tag="InvalidValue";annotations;constructor(e,t,r){super(t,r);this.annotations=e}}class fr extends Re{_tag="AnyOf";ast;issues;constructor(e,t,r,n){super(r,n);this.ast=e,this.issues=t}}class zo extends Re{_tag="OneOf";ast;successes;constructor(e,t,r,n){super(r,n);this.ast=e,this.successes=t}}function qo(e,t,r){if(Jo(e))return e;if(typeof e==="string")return new le({message:e},t,r);let n=typeof e.issue==="string"?new le({message:e.issue},t,r):e.issue;return new Pe(e.path,n)}function Ti(e,t,r){if(e===void 0)return;if(typeof e==="boolean")return e?void 0:new le(void 0,t,r);return qo(e,t,r)}function Ei(e,t,r,n){if(Array.isArray(t)){if(!Jr(t))return;return t.length===1?qo(t[0],r,n):new ee(e,ha(t,(o)=>qo(o,r,n)),r,n)}return Ti(t,r,n)}function pr(e){let t;for(let r of e.reasons){if(!mi(r)||!Jo(r.error))return;t??=r.error}return t}function an(e,t){let r=pr(e);if(r===void 0)throw Error(t,{cause:e});return r}class pt extends Bt{run;constructor(e){super();this.run=e}map(e){return new pt((t,r)=>this.run(t,r).pipe(Ft(to(e))))}compose(e){if(wi(this))return e;if(wi(e))return this;return new pt((t,r)=>this.run(t,r).pipe(Ee((n)=>e.run(n,r))))}}var Ii=new pt(j);function wi(e){return e.run===Ii.run}function mt(){return Ii}function gl(e){return new pt((t,r)=>tr(t)?Do:e(t.value,r))}function oe(e){return vi(to(e))}function mr(e){return gl((t,r)=>e(t,r).pipe(Ft(Fe)))}function vi(e){return new pt((t)=>j(e(t)))}function Vo(e){return new pt((t)=>{let r=na(t,Fn);return eo(r)?j(r):Ft(e,Fe)})}function cn(){return oe(globalThis.String)}function un(){return oe(globalThis.Number)}function Ci(){return oe(Hr)}function Oi(){return mr((e,t)=>No(xi(Wr(e)),()=>new le({expected:"a valid Base64 string"},e,t)))}var dr="~effect/SchemaTransformation/Transformation";class se{[dr]=dr;_tag="Transformation";decode;encode;constructor(e,t){this.decode=e,this.encode=t}flip(){return new se(this.encode,this.decode)}compose(e){return new se(this.decode.compose(e.decode),e.encode.compose(this.encode))}}function Tl(e){return _(e,dr)&&e[dr]===dr}var Wo=(e)=>{if(Tl(e))return e;return new se(e.decode,e.encode)};function hr(e){return new se(mr(e.decode),mr(e.encode))}function Zo(e){return new se(oe(e.decode),oe(e.encode))}var El=new se(mt(),mt());function ln(){return El}var fn=new se(un(),cn());var bl=(e)=>Dn(e)&&typeof e.message==="string",wl=(e)=>{let r=Object.hasOwn(e,"cause")?Error(e.message,{cause:ki(e.cause)}):Error(e.message);if(typeof e.name==="string"&&e.name!=="Error")r.name=e.name;if(typeof e.stack==="string")r.stack=e.stack;return r},Il=(e)=>{try{let t=Jn(e);return t===void 0?N(e):JSON.parse(t)}catch{return N(e)}},vl=(e,t,r)=>{let n={name:e.name,message:typeof e.message==="string"?e.message:""};if(t?.includeStack&&typeof e.stack==="string")n.stack=e.stack;if(!t?.excludeCause&&e.cause!==void 0)n.cause=r(e.cause);return n},Cl=(e)=>{let t=new WeakSet,r=(n)=>{if(Ds(n)){if(t.has(n))return"[Circular]";t.add(n);let o=vl(n,e,r);return t.delete(n),o}return Il(n)};return r},ki=(e)=>bl(e)?wl(e):e;var Ri=(e)=>Zo({decode:ki,encode:Cl(e)});var _i=hr({decode:(e,t)=>URL.canParse(e)?j(new URL(e)):A(new le({expected:"a valid URL string"},e,t)),encode:(e)=>j(e.href)});var Ai=new se(Oi(),Ci());function Qe(e){return(t)=>t._tag===e}var ns=Qe("Declaration");var Al=Qe("Never");var Dt=Qe("Literal"),Yo=Qe("UniqueSymbol");var Bi=Qe("Arrays"),Fl=Qe("Objects"),ji=Qe("Union"),Pl=Qe("Suspend");class ae{to;transformation;constructor(e,t){this.to=e,this.transformation=t}}var dn={};class Ze{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 Pi="~effect/Schema";class _e{[Pi]=Pi;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 ht extends _e{_tag="Declaration";typeParameters;run;encodingChecks;encodingRun;constructor(e,t,r,n,o,s,a,u){super(r,n,o,s);this.typeParameters=e,this.run=t,this.encodingChecks=a,this.encodingRun=u}getParser(){let e;return(t,r)=>{if(t===O)return Be;return(e??=this.run(this.typeParameters))(t,this,r)}}_rebuild(e,t,r,n,o){let s=Nt(this.typeParameters,e);return s===this.typeParameters&&t===this.checks&&r===this.encodingChecks&&n===this.run&&o===this.encodingRun?this:new ht(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 qi extends _e{_tag="Null";getParser(){return ds(this,null)}getExpected(){return"null"}}var Ji=new qi;class Gi extends _e{_tag="Undefined";getParser(){return ds(this,void 0)}toCodecJson(){return Se(this,[Dl])}getExpected(){return"undefined"}}var Dl=new ae(Ji,new se(oe(()=>{return}),oe(()=>null))),os=new Gi;class Ki extends _e{_tag="Unknown";getParser(){return bn(this,Ps)}getExpected(){return"unknown"}}var gr=new Ki;class dt extends _e{_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 ${N(e)}`);this.literal=e}getParser(){return ds(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==="bigint"?Di(this):this}toCodecStringTree(){return typeof this.literal==="string"?this:Di(this)}getExpected(){return typeof this.literal==="string"?JSON.stringify(this.literal):globalThis.String(this.literal)}}function Di(e){let t=globalThis.String(e.literal);return Se(e,[new ae(new dt(t),new se(oe(()=>e.literal),oe(()=>t)))])}class zi extends _e{_tag="String";getParser(){return bn(this,Jt)}matchPart(e,t){let r=this.checks;return r&&!t.disableChecks&&tt(r,e,void 0,this,t)?void 0:e}getExpected(){return"string"}}var Sr=new zi;class Vi extends _e{_tag="Number";getParser(){return bn(this,An)}matchKey(e,t){return this._match(Hl,e,t)}matchPart(e,t){return this._match(rs,e,t)}_match(e,t,r){if(!e.test(t))return;let n=globalThis.Number(t);if(r.disableChecks||!this.checks)return n;return tt(this.checks,n,void 0,this,r)?void 0:n}toCodecJson(){if(this.checks&&(Xo(this.checks,"effect/schema/isFinite")||Xo(this.checks,"effect/schema/isInt")))return this;return Se(this,[Bl])}toCodecStringTree(){if(this.toCodecJson()===this)return Se(this,[Wl]);return Se(this,[Zl])}getExpected(){return"number"}}function Xo(e,t){return e.some((r)=>r.annotations?.representation?.id===t||r._tag==="FilterGroup"&&Xo(r.checks,t))}var ss=new Vi;class Tr extends _e{_tag="Arrays";isMutable;elements;rest;encodingChecks;constructor(e,t,r,n,o,s,a,u){super(n,o,s,a);this.isMutable=e,this.elements=t,this.rest=r,this.encodingChecks=u;let l=!1;for(let i=0;i<t.length;i++)if(Ye(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(Ye(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 u(l,i){if(i<s)return n[i];else if(i>=l)return o[i-l+1];return o[0]}return Mo(function*(l,i){if(l===O)return O;if(!Array.isArray(l))return yield*A(new we(r,l,i));if(!n)n=r.elements.map((g)=>({ast:g,parser:t(g)})),o=r.rest.map((g)=>({ast:g,parser:t(g)}));let x=l.length,T={ast:r,getParser:u,input:l,len:x,tailThreshold:Math.max(s,x-a),output:new globalThis.Array(x),issues:void 0,options:i},S=as(i?.concurrency),h=Ul(T,l,{concurrency:S?.concurrency,end:r.rest.length===0?s:Math.max(x,s+a)});if(h)yield*h;if(r.rest.length===0&&x>s)for(let g=s;g<=x-1;g++){let I=new sn(r,l[g],i),m=new Pe([g],I);if(i.errors==="all")if(T.issues)T.issues.push(m);else T.issues=[m];else return yield*A(new ee(r,[m],l,i))}if(T.issues)return yield*A(new ee(r,T.issues,l,i));return T.output})}_rebuild(e,t,r){let n=Nt(this.elements,e),o=Nt(this.rest,e);return n===this.elements&&o===this.rest&&t===this.checks&&r===this.encodingChecks?this:new Tr(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 Ul=sr()({onItem(e,t,r){let n=r<e.len?t:O;return e.getParser(e.tailThreshold,r).parser(n,e.options)},step(e,t,r,n){if(r._tag==="Failure")return pn(e,e.ast,n,r);let o=r===W?t:r[b];if(o!==O)e.output[n]=o;else{let s=e.getParser(e.tailThreshold,n);if(Ye(s.ast))return;let a=new Pe([n],new lr(s.ast.context?.annotations));if(e.options.errors==="all")if(e.issues)e.issues.push(a);else e.issues=[a];else return _t(new ee(e.ast,[a],e.input,e.options))}}}),as=(e)=>(e=e==="unbounded"?1/0:e??1,e>1?{concurrency:e}:void 0),pn=(e,t,r,n)=>{if(n.cause.reasons.length===0)return n;let o=pr(n.cause);if(o===void 0)return Ao(Qr(n.cause,(a)=>new ee(t,[new Pe([r],a)],e.input,e.options)));let s=new Pe([r],o);if(e.options.errors==="all")if(e.issues)e.issues.push(s);else e.issues=[s];else return _t(new ee(t,[s],e.input,e.options))},Hi="[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";function Qo(e,t,r=dn){let n,o;function s(a){switch(a._tag){case"String":case"TemplateLiteral":return(n??=Object.keys(e)).filter((u)=>a.matchPart(u,r)!==void 0);case"Number":return(n??=Object.keys(e)).filter((u)=>a.matchKey(u,r)!==void 0);case"Symbol":return(o??=Object.getOwnPropertySymbols(e)).filter((u)=>a.matchKey(u,r)!==void 0);case"Union":return[...new Set(a.types.flatMap(s))];default:return[]}}return s(hs(En(t)))}class hn{name;type;constructor(e,t){this.name=e,this.type=t}}function es(e){switch(e._tag){case"String":case"Number":case"Symbol":case"TemplateLiteral":return!0;case"Union":return e.types.every(es);default:return!1}}function Nl(e){return es(e)&&es(En(e))}class is{parameter;type;constructor(e,t){if(!Nl(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Ye(t)&&!pc(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}}class xn extends _e{_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 u=e.map((l)=>l.name).filter((l,i,x)=>x.indexOf(l)!==i);if(u.length>0)throw Error(`Duplicate identifiers: ${JSON.stringify(u)}. ts(2300)`)}getParser(e,t=e){let r=this,n=[];for(let m of r.propertySignatures)n.push(m.name);let o=n.length,s=r.indexSignatures.length,a=o&&s?new Set(n):void 0;if(!o&&!s)return bn(r,Pn);let u,l,i=(m,y,E,w,v)=>{if(v._tag==="Failure")return pn(m,r,y,v)??At;let z=v===W?w:v[b];if(E!==O&&z!==O){if(o&&(a.has(y)||a.has(E)))return At;Ie(m.out,E,z)}return At},x=(m,y,E,w)=>{if(!w){let J=E.parserKey(y,m.options);if(!K(J))return $e(ar(J),(U)=>x(m,y,E,U));w=J}if(w._tag==="Failure")return pn(m,r,y,w)??At;let v=w===W?y:w[b],z=m.input[y],q=E.parserValue(z,m.options);return K(q)?i(m,y,v,z,q):$e(ar(q),(J)=>i(m,y,v,z,J))},T=(m,y,E)=>{let w=m.input[y],v=E.parserValue(w,m.options);return K(v)?i(m,y,y,w,v):$e(ar(v),(z)=>i(m,y,y,w,z))},S=s?sr()({onItem:(m,[y,E])=>x(m,y,E),step:(m,y,E)=>E._tag==="Failure"?E:void 0}):void 0,h=()=>{if(!u)u=r.propertySignatures.map((m)=>({parser:t(m.type),name:m.name,type:m.type})),l=s?r.indexSignatures.map((m)=>({is:m,parserKey:e(hs(m.parameter)),parserValue:t(m.type)})):void 0;return u},g=Mo(function*(m,y){if(m===O)return O;if(!(typeof m==="object"&&m!==null&&!Array.isArray(m)))return yield*A(new we(r,m,y));h();let E=m,w={},v={ast:r,input:E,out:w,issues:void 0,options:y},z=y.errors==="all",q=y.onExcessProperty==="error",J=y.onExcessProperty==="preserve",U;if(!s&&(q||J)){a??=new Set(n),U=Reflect.ownKeys(E);for(let k=0;k<U.length;k++){let R=U[k];if(!a.has(R))if(q){let M=new sn(r,E[R],y),L=new Pe([R],M);if(z){if(v.issues)v.issues.push(L);else v.issues=[L];continue}else return yield*A(new ee(r,[L],m,y))}else Ie(w,R,E[R])}}let re=as(y?.concurrency);if(o){let k=Ui(v,u,re);if(k)yield*k}if(s&&!re)for(let k=0;k<s;k++){let R=l[k],M=R.is.parameter===Sr?T:x,L=R.is.parameter===Sr?Object.keys(E):Qo(E,R.is.parameter,y);for(let gt=0;gt<L.length;gt++){let qe=M(v,L[gt],R);if(!K(qe))yield*qe;else if(qe._tag==="Failure")return yield*qe}}else if(S){let k=Gr();for(let M=0;M<s;M++){let L=l[M],gt=Qo(E,L.is.parameter,y);for(let qe=0;qe<gt.length;qe++)k.push([gt[qe],L])}let R=S(v,k,re);if(R)yield*R}if(v.issues)return yield*A(new ee(r,v.issues,m,y));if(y.propertyOrder==="original"){let k=(U??Reflect.ownKeys(E)).concat(n),R={};for(let M of k)if(Object.hasOwn(w,M))Ie(R,M,w[M]);return R}return w});if(s)return g;let I=(m,y,E)=>{let w=u[y];return $e(ar(E),(v)=>{let z=ts(m,w,v);if(z)return z;let q=()=>ke(m.out),J=Ui(m,u.slice(y+1));return J?Ee(J,q):q()})};return(m,y)=>{if(m===O)return Be;if(y.errors==="all"||y.onExcessProperty!==void 0||y.propertyOrder==="original"||y.concurrency!==void 0)return g(m,y);if(!(typeof m==="object"&&m!==null&&!Array.isArray(m)))return A(new we(r,m,y));let E=h(),w=m,v={},z={ast:r,input:w,out:v,issues:void 0,options:y};try{for(let q=0;q<E.length;q++){let J=E[q],U=J.name,re=Object.hasOwn(w,U),k=re?w[U]:O,R=J.parser(k,y);if(!K(R))return I(z,q,R);if(R===W){if(re)Ie(v,U,k);continue}let M=ts(z,J,R);if(M)return M}}catch(q){return en(q)}return ke(v)}}_rebuild(e,t,r,n){let o=Nt(this.propertySignatures,(a)=>{let u=e(a.type);return u===a.type?a:new hn(a.name,u)}),s=Nt(this.indexSignatures,(a)=>{let u=t(a.parameter),l=e(a.type);return u===a.parameter&&l===a.type?a:new is(u,l)});return o===this.propertySignatures&&s===this.indexSignatures&&r===this.checks&&n===this.encodingChecks?this:new xn(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 ts(e,t,r){if(r._tag==="Failure")return pn(e,e.ast,t.name,r);if(r===W)return;let n=r[b];if(n!==O){Ie(e.out,t.name,n);return}if(delete e.out[t.name],!Ye(t.type)){let o=new Pe([t.name],new lr(t.type.context?.annotations));if(e.options.errors==="all"){if(e.issues)e.issues.push(o);else e.issues=[o];return}else return _t(new ee(e.ast,[o],e.input,e.options))}}var Ui=sr()({onItem(e,t){if(!Object.hasOwn(e.input,t.name))return t.parser(O,e.options);let r=e.input[t.name];return Ie(e.out,t.name,r),t.parser(r,e.options)},step:ts});function Wi(e,t){if(!e)return t;if(!t)return e;return[...e,...t]}function gn(e,t,r){return new xn(Reflect.ownKeys(e).map((n)=>new hn(n,e[n].ast)),[],r,t)}function cs(e){return e.ast}function us(e,t=void 0){return new Tr(!1,e.map((r)=>r.ast),[],void 0,t)}function ls(e,t,r){return new et(e.map(cs),t,void 0,r)}var Sn=yt((e)=>{while(!0){if(Pl(e))return gr;let t=e.encoding;if(!t)return e.recur?.(Sn,ie)??e;if(t.some((r)=>r.transformation._tag==="Middleware"&&r.transformation.decode!==ie))return gr;e=t[t.length-1].to}});function Zi(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(Zi)));default:return["null","undefined","string","number","boolean","symbol","bigint","object","array","function"]}}function Ut(e){switch(e._tag){default:return[];case"Declaration":{let t=e.annotations?.[rn];return Array.isArray(t)?t:[]}case"Objects":return e.propertySignatures.flatMap((t)=>{let r=t.type;if(!Ye(r)){if(Dt(r))return[{key:t.name,literal:r.literal}];if(Yo(r))return[{key:t.name,literal:r.symbol}]}return[]});case"Arrays":return e.elements.flatMap((t,r)=>{if(!Ye(t)){if(Dt(t))return[{key:r,literal:t.literal}];if(Yo(t))return[{key:r,literal:t.symbol}]}return[]});case"Union":{if(e.types.length===0)return[];let t=e.types.map((r)=>Ut(Sn(r)));return t[0].filter((r)=>t.every((n)=>n.some((o)=>o.key===r.key&&o.literal===r.literal)))}case"Suspend":return Ut(e.thunk())}}var Ni=new WeakMap,xr=Object.freeze([]);function Ml(e){let t=Ni.get(e);if(t)return t;let r,n=0,o,s,a=!0;for(let u=0;u<e.length;u++){let l=e[u],i=Sn(l);if(Al(i))continue;if(a)if(Dt(i)||Yo(i)){s??=new Map;let T=Dt(i)?i.literal:i.symbol,S=s.get(T);if(!S)s.set(T,S=[]);S.push(l)}else a=!1;let x=Ut(i);if(x.length){r??=new Map,n++;for(let{key:T,literal:S}of x){let h=r.get(T);if(!h)r.set(T,h=[new Map,new Set]);h[1].add(u);let g=h[0].get(S);if(!g)h[0].set(S,g=new Set);g.add(u)}}else{o??={};let T=Zi(i);for(let S of T)(o[S]??=[]).push(u)}}if(a&&s)s.forEach(Object.freeze),t=(u)=>s.get(u)??xr;else if(r?.size===1&&!o){let[u,[l]]=r.entries().next().value,i=l;for(let[x,T]of l)i.set(x,Object.freeze(Array.from(T,(S)=>e[S])));t=(x,T)=>{if(Or(x)){let S=Object.hasOwn(x,u)?x[u]:void 0;if(S!==void 0)return i.get(S)??xr;if(T)return e}return xr}}else if(r){let u;for(let l of r)if((!u||l[1][0].size>u[1][0].size)&&l[1][1].size===n)u=l;t=(l,i)=>{let x=l===null?"null":Array.isArray(l)?"array":typeof l,T=o?.[x]??xr;if(!Or(l))return T.map((g)=>e[g]);let S=new Set(T),h;if(u){let[g,[I]]=u,m=Object.hasOwn(l,g),y=m?l[g]:void 0;if(m&&(!i||y!==void 0)){let E=I.get(y);if(!E)return T.map((w)=>e[w]);for(let w of E)S.add(w);h=g}}if(h===void 0)for(let[g,[I,m]]of r){let y=Object.hasOwn(l,g),E=y?l[g]:void 0;if(y&&(!i||E!==void 0)){let w=I.get(E);if(w)for(let v of w)S.add(v)}else if(i)for(let w of m)S.add(w)}for(let[g,[I,m]]of r){if(g===h)continue;let y=Object.hasOwn(l,g),E=y?l[g]:void 0;if(y&&(!i||E!==void 0)){let w=I.get(E);for(let v of S)if(m.has(v)&&!w?.has(v))S.delete(v)}}return Array.from(S).sort((g,I)=>g-I).map((g)=>e[g])}}else t=(u)=>{let l=u===null?"null":Array.isArray(u)?"array":typeof u;return(o?.[l]??xr).map((i)=>e[i]).filter(Ll(u))};return Ni.set(e,t),t}function Ll(e){return(t)=>{let r=Sn(t);return r._tag==="Literal"?r.literal===e:r._tag==="UniqueSymbol"?r.symbol===e:!0}}function Yi(e,t,r=!1){return Ml(t)(e,r)}class et extends _e{_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===O)return Be;let s=Yi(n,r.types,t!==void 0);if(s.length===1){let i=e(s[0])(n,o);if(i._tag==="Success")return i;return K(i)?Mi(r,i.cause,n,o):ir(i,(x)=>Mi(r,x,n,o))}let a={ast:r,compile:e,input:n,out:void 0,successes:r.mode==="oneOf"?[]:void 0,issues:void 0,options:o},u=as(o?.concurrency),l=$l(a,s,u?{...u,orderedStep:!0}:void 0);if(!l){if(a.out)return a.out;return A(new fr(r,a.issues??[],n,o))}return Ee(l,(i)=>{if(a.out===W)return j(n);if(a.out)return a.out;return A(new fr(r,a.issues??[],n,o))})}}_rebuild(e,t,r){let n=Nt(this.types,e);return n===this.types&&t===this.checks&&r===this.encodingChecks?this:new et(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=En(n);switch(o._tag){case"Arrays":{let s=o.elements.filter(Dt);if(s.length>0)return`${Li(o.isMutable)}[ ${s.map((a)=>e(a)+$i(a.context?.isOptional)).join(", ")}, ... ]`;break}case"Objects":{let s=o.propertySignatures.filter((a)=>Dt(a.type));if(s.length>0)return`{ ${s.map((a)=>`${Li(a.type.context?.isMutable)}${Kt(a.name)}${$i(a.type.context?.isOptional)}: ${e(a.type)}`).join(", ")}, ... }`;break}}return e(o)});return Array.from(new Set(r)).join(" | ")}}function Mi(e,t,r,n){let o=pr(t);if(!o)return Ao(t);return _t(new fr(e,[o],r,n))}var $l=sr()({onItem(e,t){return e.compile(t)(e.input,e.options)},step(e,t,r){if(r._tag==="Failure"){let n=pr(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),_t(new zo(e.ast,e.successes,e.input,e.options));if(e.out=r,e.successes)e.successes.push(t);else return At}}}),Xi=new et([new dt("Infinity"),new dt("-Infinity"),new dt("NaN")],"anyOf");function Li(e){return e?"":"readonly "}function $i(e){return e?"?":""}class mn extends Bt{_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 mn(this.run,{...this.annotations,...e},this.aborted)}abort(){return new mn(this.run,this.annotations,!0)}and(e,t){return new yr([this,e],t)}}class yr extends Bt{_tag="FilterGroup";checks;annotations;constructor(e,t=void 0){super();this.checks=e,this.annotations=t}annotate(e){return new yr(this.checks,{...this.annotations,...e})}and(e,t){return new yr([this,e],t)}}function yn(e,t,r=!1){return new mn((n,o,s)=>Ei(o,e(n,o,s),n,s),t,r)}function Qi(e){return yn((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 ec=xt(ss,[Qi()]),Bl=new ae(new et([ec,Xi],"anyOf"),new se(un(),oe((e)=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function fs(e,t){let r=e.source,n=new globalThis.RegExp(r,e.flags);return yn((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 Er(e,t){let r=Object.getOwnPropertyDescriptors(e);return t(r),Object.create(Object.getPrototypeOf(e),r)}var tc=new WeakMap;function jl(e){return tc.get(e)??e}function Se(e,t){if(e.encoding===t)return e;return Er(e,(r)=>{r.encoding.value=t})}function ps(e,t){if(e.context===t)return e;let r=jl(e);if(r.context===t)return r;let n=Er(e,(o)=>{o.context.value=t});return tc.set(n,r),n}function Mt(e,t){if(e.checks){let r=e.checks[e.checks.length-1];return rc(e,po(e.checks.slice(0,-1),r.annotate(t)))}return Er(e,(r)=>{r.annotations.value={...r.annotations.value,...t}})}function rc(e,t){if(e._tag==="Suspend"&&t)throw Error("Cannot add checks to Suspend");if(e.checks===t)return e;return Er(e,(r)=>{r.checks.value=t})}function xt(e,t){return rc(e,Wi(e.checks,t))}function nc(e,t){let r=t(e.to);return r===e.to?e:new ae(r,e.transformation)}function oc(e,t){let r=e,n=r[r.length-1],o=nc(n,t);return o===n?e:po(e.slice(0,e.length-1),o)}function ql(e){return(t)=>t.encoding?Se(t,oc(t.encoding,e)):t}function sc(e,t){function r(n){if(n.encoding){let o=n.encoding[n.encoding.length-1];return t?.stopAt?.(o)?n:Se(n,oc(n.encoding,r))}return e(n)}return yt(r)}function Jl(e,t,r){let n=new ae(e,t);return Se(r,r.encoding?[...r.encoding,n]:[n])}function ac(e,t){let r=Si(e),n=r?[...r,t]:[t];return Mt(e,{brands:n})}function Nt(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 Tn(e,t){let r=e.context?new Ze(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new Ze(!1,!1,void 0,t);return ps(e,r)}var ms=yt((e)=>{let t=e.context?e.context.isOptional===!1?new Ze(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new Ze(!0,!1);return Gl(ps(e,t))}),Gl=ql(ms),ic=rt((e)=>ms(new et([e,os],"anyOf")));function cc(e,t){let r=new se(Vo(t),mt()),n=new ae(gr,r),o=e.context?new Ze(e.context.isOptional,e.context.isMutable,n,e.context.annotations):new Ze(!1,!1,n);return ps(e,o)}function uc(e,t,r){return Jl(e,r,t)}function Kl(e){let t=[],r=[];function n(o){switch(o._tag){case"Literal":if(Cr(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 lc(e,t){let{literals:r,parameters:n}=Kl(e);return new xn(r.map((o)=>new hn(o,t)),n.map((o)=>new is(o,t)))}function Ye(e){return e.context?.isOptional??!1}function fc(e){return e.annotations?.[$o]===!0||e._tag==="FilterGroup"&&e.checks.every(fc)}function zl(e){function t(n){if(fc(n))return[n];return n._tag==="FilterGroup"?n.checks.flatMap(t):[]}let r=e.flatMap(t);return mo(r)?r:void 0}var Xe=yt((e)=>{if(e.encoding)return Xe(Se(e,void 0));let t=e,r=t.recur?.(Xe)??t,n=r.encodingChecks;if(n){let o=r===e?n:Bi(r)||Fl(r)||ns(r)&&r.typeParameters.length>0?zl(n):void 0;return Er(r,(s)=>{s.encodingChecks.value=void 0,s.checks.value=Wi(r.checks,o)})}return r}),En=yt((e)=>Xe(We(e)));function Vl(e,t){let r=t,n=r.length,o=r[n-1],s=[new ae(We(Se(e,void 0)),r[0].transformation.flip())];for(let u=1;u<n;u++)s.unshift(new ae(We(r[u-1].to),r[u].transformation.flip()));let a=We(o.to);if(a.encoding)return Se(a,[...a.encoding,...s]);else return Se(a,s)}var We=rt((e)=>{if(e.encoding)return Vl(e,e.encoding);let t=e;return t.flip?.(We)??t.recur?.(We)??t});function pc(e){switch(e._tag){case"Undefined":return!0;case"Union":return e.types.some(pc);default:return!1}}function ds(e,t){let r=ke(t);return(n,o)=>{if(n===O)return Be;if(n===t)return r;return A(new we(e,n,o))}}function bn(e,t){return(r,n)=>{if(r===O)return Be;if(t(r))return W;return A(new we(e,r,n))}}var hs=sc((e)=>{switch(e._tag){default:return e;case"Number":return e.toCodecStringTree();case"Union":return e.recur(hs)}});var rs=new globalThis.RegExp(`^${Hi}$`),Hl=new globalThis.RegExp(`^(?:${Hi}|Infinity|-Infinity|NaN)$`);function mc(e){return fs(rs,{expected:"a string representing a finite number",representation:{id:"effect/schema/isStringFinite",payload:null},toJsonSchema:()=>({pattern:rs.source}),...e})}var dc=xt(Sr,[mc()]),Wl=new ae(dc,fn),Zl=new ae(new et([dc,Xi],"anyOf"),fn),Yl="-?\\d+",gS=new globalThis.RegExp(`^${Yl}$`);var Xl="Symbol\\((.*)\\)",SS=new globalThis.RegExp(`^${Xl}$`);function tt(e,t,r,n,o){for(let s=0;s<e.length;s++){let a=e[s];if(a._tag==="FilterGroup"){if(r=tt(a.checks,t,r,n,o),r&&(o.errors!=="all"||r[r.length-1].filter.aborted))return r}else{let u=a.run(t,n,o);if(u){let l=new Go(a,u,t,o);if(r)r.push(l);else r=[l];if(o.errors!=="all"||a.aborted)return r}}}return r}function hc(e){if(!ns(e))return;let t=e.annotations?.[nn];return Tt(t)?t(e.typeParameters):void 0}function Ql(e){return e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&globalThis.Number.isFinite(e)}function ef(e){return e===void 0||typeof e==="string"}function xc(e,t){let r=new WeakMap,n=[];e:while(!0){if(typeof e!=="object"||e===null){if(!t(e))return!1}else{let o=e,s=r.get(o);if(s===!1)return!1;if(s===void 0){let a=Array.isArray(o);if(!a){let u=Object.getPrototypeOf(o);if(u!==null&&u!==Object.prototype&&Object.getPrototypeOf(u)!==null)return!1}r.set(o,!1),n.push({value:o,keys:a?o.length:Object.keys(o),index:0})}}while(n.length>0){let o=n[n.length-1],s=o.keys;if(typeof s==="number"){if(o.index<s){e=o.value[o.index++];continue e}}else if(o.index<s.length){e=o.value[s[o.index++]];continue e}r.set(o.value,!0),n.pop()}return!0}}function tf(e){return xc(e,Ql)}var gc=new ht([],()=>(e,t,r)=>tf(e)?W:A(new we(t,e,r)),{representation:{id:"effect/schema/Json",payload:null},expected:"JSON value",toCodecJson:()=>{return},toCodecStringTree:()=>Sc,toArbitrary:()=>(e)=>e.jsonValue()});function rf(e){return xc(e,ef)}var nf=new ht([],()=>(e,t,r)=>rf(e)?W:A(new we(t,e,r)),{expected:"StringTree",toCodecStringTree:()=>{return}}),Sc=new ae(nf,ln());function wn(e){let t=wc(vn,Xe(e.ast));return(r,n)=>t(r,n?.disableChecks?n?.parseOptions?{...n.parseOptions,disableChecks:!0}:{disableChecks:!0}:n?.parseOptions)}function In(e){let t=wn(e);return(r,n)=>{let o=cr(t(r,n));if(Xr(o))return Fe(o.value);return an(o.cause,"Option adapter can only return none for schema issues"),Ue()}}function Tc(e){let t=wn(e);return(r,n)=>{let o=cr(t(r,n));if(Xr(o))return o.value;let s=an(o.cause,"Constructor adapter can only throw schema issues");throw Error("Schema validation failed",{cause:s})}}function Ec(e){return bc(e.ast)}function bc(e){let t=af(sf(Xe(e)));return(r)=>{let n=t(r,dn);if(Xr(n))return!0;return an(n.cause,"Type guard adapter can only return false for schema issues"),!1}}var gs=(e,t)=>t?{...e,...t}:e,yc=(e)=>{if(e===O)return A(new le);return j(e)};function sf(e){return wc(Ic,e)}function wc(e,t){let r;return(n,o)=>{let s=(r??=e(t))(n,o??dn);if(s===W)return j(n);if(!K(s))return Ee(s,yc);return s[b]===O?yc(O):s}}function af(e){return(t,r)=>cr(e(t,r))}var Ic=rt((e)=>Ss(e,Ic)),vn=rt((e)=>Ss(e,vn,vc)),cf=rt((e)=>Ss(e,vn,vc,e.context?.constructorDefault));function vc(e){return e.context?.constructorDefault?cf(e):vn(e)}function Cc(e,t,r,n){let o;if(K(e)&&e._tag==="Success"){let s=on(e===W?t:e[b]);o=r._tag==="Transformation"?r.decode.run(s,n):r.decode(ke(s),n)}else if(r._tag==="Transformation")o=Ee(e,(s)=>r.decode.run(on(s),n));else o=r.decode(Ft(e,on),n);return K(o)&&o._tag==="Success"?Bo(o[b]):Ee(o,Bo)}function uf(e,t){let r;return(n,o)=>{if(n===O)return Be;if(e.isConstructed(n))return W;let s=(r??=t(e.link.to))(n,o);return Cc(s,n,e.link.transformation,o)}}function Ss(e,t,r,n){let o=r?hc(e):void 0,s=o?uf(o,t):e.getParser(t,r),a=e.checks,u=n?e.encoding?[...e.encoding,n]:[n]:e.encoding,l=e.encodingChecks,i=(a?a[a.length-1].annotations:e.annotations)?.parseOptions;if(!u&&!a&&!l){if(!i)return s;return(S,h)=>s(S,gs(h,i))}let x,T=(S,h)=>{let g=s(S,h);if(l&&!h.disableChecks)if(K(g)){if(g._tag==="Success"){let I=g===W?S:g[b];if(S!==O&&I!==O){let m=tt(l,S,void 0,e,h);if(m)g=A(new ee(e,m,S,h))}}}else g=$e(g,(I)=>{if(S!==O&&I!==O){let m=tt(l,S,void 0,e,h);if(m)return A(new ee(e,m,S,h))}return j(I)});if(a&&!h.disableChecks)if(K(g)){if(g._tag==="Success"){let I=g===W?S:g[b];if(I===O)return g;let m=tt(a,I,void 0,e,h);if(m)g=A(new ee(e,m,I,h))}}else g=$e(g,(I)=>{if(I!==O){let m=tt(a,I,void 0,e,h);if(m)return A(new ee(e,m,I,h))}return j(I)});return g};if(!u)return i?(S,h)=>T(S,gs(h,i)):T;return(S,h)=>{if(i)h=gs(h,i);let g=x??=u.map((y)=>t(y.to)),I=S,m=g[g.length-1](S,h);for(let y=u.length-1;y>=0;y--)if(m=Cc(m,I,u[y].transformation,h),y!==0){let E=g[y-1];if(m._tag==="Success")I=m[b],m=E(I,h);else m=Ee(m,(w)=>{let v=E(w,h);return v===W?ke(w):v})}if(m._tag==="Success"){let y=m[b],E=T(y,h);return E===W?m:E}return m=ir(m,(y)=>Uo(()=>Qr(y,(E)=>new Ko(e,E,S,h)))),Ee(m,(y)=>{let E=T(y,h);return E===W?ke(y):E})}}var Cn="~effect/Schema/Schema";var lf={[Cn]:Cn,pipe(){return fe(this,arguments)},annotate(e){return this.rebuild(Mt(this.ast,e))},annotateKey(e){return this.rebuild(Tn(this.ast,e))},check(...e){return this.rebuild(xt(this.ast,e))}};function ys(e,t){function r(){}let n=Object.defineProperties(Object.setPrototypeOf(r,lf),Object.getOwnPropertyDescriptors({...t}));return n.ast=e,n.rebuild=(o)=>ys(o,t),n.makeEffect=wn(n),n.make=Tc(n),n.makeOption=In(n),n}var br=(e)=>e;var wr=Cn;function mf(){return(e,t,r)=>Z(new ht(e.map(cs),(n)=>t(n.map((o)=>Z(o))),r))}function df(e,t){return mf()([],()=>(r,n,o)=>e(r)?j(r):A(new we(n,r,o)),t)}var hf=Ec;var Z=ys;function Rc(e){return _(e,wr)&&e[wr]===wr}var Es=br((e)=>{let t=bf(e);return Z(ic(e.ast),{schema:t})});var xf=br((e)=>Z(Xe(e.ast),{schema:e}));function kn(e){let t=Z(new dt(e),{literal:e,transform(r){return t.pipe(Is(kn(r),{decode:oe(()=>r),encode:oe(()=>e)}))}});return t}var _c=Z(gr);var gf=Z(os),te=Z(Sr),Sf=Z(ss);function bs(e,t){return Z(e,{fields:t,mapFields(r,n){let o=r(this.fields);return bs(gn(o,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function je(e){return bs(gn(e,void 0),e)}function yf(e,t){return Z(lc(e.ast,t.ast),{key:e,value:t})}function Ac(e,t){return Z(e,{elements:t,mapElements(r,n){let o=r(this.elements);return Ac(us(o,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function Tf(e){return Ac(us(e),e)}var Ef=br((e)=>Z(new Tr(!1,[],[e.ast]),{value:e}));function Fc(e,t){return Z(e,{members:t,mapMembers(r,n){let o=r(this.members);return Fc(ls(o,this.ast.mode,n?.unsafePreserveChecks?this.ast.checks:void 0),o)}})}function ws(e,t){return Fc(ls(e,t?.mode??"anyOf",void 0),e)}var bf=br((e)=>ws([e,gf]));function wf(e){return(t)=>Z(ac(t.ast,e),{schema:t,identifier:e})}function Is(e,t){return(r)=>Z(uc(r.ast,e.ast,t?Wo(t):ln()),{from:r,to:e})}function If(e){return(t)=>Z(cc(t.ast,e),{schema:t})}function On(e){return kn(e).pipe(If(j(e)))}function vf(e,t){return je({_tag:On(e),...t})}function Cf(e){return(t)=>{let r={},n=[],o=new Set,s={},a=(x)=>(T)=>x.includes(T[e]);return u(t),Object.assign(t,{cases:r,discriminants:n,isAnyOf:a,guards:s,match:l,matchOrElse:i});function u(x){let T=x.ast;if(ji(T)&&"members"in x&&globalThis.Array.isArray(x.members)&&x.members.every(Rc))return x.members.forEach(u);let S=Ut(T);if(S.length>0){let h=S.find((g)=>g.key===e)?.literal;if(Cr(h)){let g=typeof h==="number"?globalThis.String(h):h;if(o.has(g))throw new globalThis.Error(`Duplicate discriminant: ${globalThis.String(h)}`);o.add(g),n.push(h),Ie(r,h,x),Ie(s,h,hf(xf(x)));return}}throw new globalThis.Error("No literal or unique symbol found")}function l(){if(arguments.length===1){let g=arguments[0];return function(I){let m=I[e];return(Object.hasOwn(g,m)?g[m]:void 0)(I)}}let x=arguments[0],T=arguments[1],S=x[e];return(Object.hasOwn(T,S)?T[S]:void 0)(x)}function i(){if(arguments.length===2){let I=arguments[0],m=arguments[1];return function(y){let E=y[e];return(Object.hasOwn(I,E)?I[E]??m:m)(y)}}let x=arguments[0],T=arguments[1],S=arguments[2],h=x[e];return(Object.hasOwn(T,h)?T[h]??S:S)(x)}}}function Lt(e,t){return df((r)=>r instanceof e,t)}function $t(){return(e,t)=>new ae(e.ast,Wo(t))}var Of=yn;function kf(e,t){let{source:r,flags:n}=e,o=n===""?`new RegExp(${N(r)})`:`new RegExp(${N(r)}, ${N(n)})`;return fs(e,{toCode:()=>({runtime:`Schema.isPattern(${o})`}),...t})}function Rf(e){let t=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;return kf(t,{expected:"a base64 encoded string",representation:{id:"effect/schema/isBase64",payload:null},toJsonSchema:()=>({pattern:t.source}),toCode:()=>({runtime:"Schema.isBase64()"}),...e})}function _f(e){return Of((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 Af=Sf.check(_f());var Ff=(e)=>(e?.includeStack===!0?1:0)|(e?.excludeCause===!0?2:0),Pf=(e)=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}};var kc=[];function Df(e){let t=Ff(e),r=kc[t];if(r!==void 0)return r;let n=Jf.pipe(Is(_c,Ri(Pf(t))));return kc[t]=n,n}var nT=Lt(globalThis.RegExp,{representation:{id:"effect/schema/RegExp",payload:null},toCode:()=>({runtime:"Schema.RegExp",Type:"globalThis.RegExp"}),expected:"RegExp",toCodecJson:()=>$t()(je({source:te,flags:te}),hr({decode:(e,t)=>tn({try:()=>new globalThis.RegExp(e.source,e.flags),catch:()=>new le({expected:"valid RegExp source and flags"},e,t)}),encode:(e)=>j({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 Uf=te.annotate({expected:"a string that will be decoded as a URL"}),oT=Lt(globalThis.URL,{representation:{id:"effect/schema/URL",payload:null},toCode:()=>({runtime:"Schema.URL",Type:"globalThis.URL"}),expected:"URL",toCodecJson:()=>$t()(Uf,_i),toArbitrary:()=>(e)=>e.webUrl().map((t)=>new globalThis.URL(t)),toEquivalence:()=>(e,t)=>e.toString()===t.toString()});var Nf=Lt(globalThis.File,{representation:{id:"effect/schema/File",payload:null},toCode:()=>({runtime:"Schema.File",Type:"globalThis.File"}),expected:"File",toCodecJson:()=>$t()(je({data:te.check(Rf()),type:te,name:te,lastModified:Af}),hr({decode:(e,t)=>qr(Wr(e.data),{onFailure:()=>A(new le({expected:"a valid Base64 string"},e.data,t)),onSuccess:(r)=>{let n=new globalThis.Uint8Array(r);return j(new globalThis.File([n],e.name,{type:e.type,lastModified:e.lastModified}))}}),encode:(e,t)=>di({try:async()=>{let r=new globalThis.Uint8Array(await e.arrayBuffer());return{data:Hr(r),type:e.type,name:e.name,lastModified:e.lastModified}},catch:()=>new le({expected:"a readable File"},e,t)})}))});var sT=Lt(globalThis.FormData,{representation:{id:"effect/schema/FormData",payload:null},toCode:()=>({runtime:"Schema.FormData",Type:"globalThis.FormData"}),expected:"FormData",toCodecJson:()=>$t()(Ef(Tf([te,ws([je({_tag:On("String"),value:te}),je({_tag:On("File"),value:Nf})])])),hr({decode:(e)=>{let t=new globalThis.FormData;for(let[r,n]of e)t.append(r,n.value);return j(t)},encode:(e)=>j(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 aT=Lt(globalThis.URLSearchParams,{representation:{id:"effect/schema/URLSearchParams",payload:null},toCode:()=>({runtime:"Schema.URLSearchParams",Type:"globalThis.URLSearchParams"}),expected:"URLSearchParams",toCodecJson:()=>$t()(te.annotate({expected:"a query string that will be decoded as URLSearchParams"}),Zo({decode:(e)=>new globalThis.URLSearchParams(e),encode:(e)=>e.toString()}))});var Mf=te.annotate({expected:"a base64 encoded string that will be decoded as Uint8Array",format:"byte",contentEncoding:"base64"}),iT=Lt(globalThis.Uint8Array,{representation:{id:"effect/schema/Uint8Array",payload:null},toCode:()=>({runtime:"Schema.Uint8Array",Type:"globalThis.Uint8Array"}),expected:"Uint8Array",toCodecJson:()=>$t()(Mf,Ai),toArbitrary:()=>(e)=>e.uint8Array()});var Lf=globalThis.Symbol.for("immer-draftable"),Ts={};function Pc(e,t,r,n,o){let s=Bf(r,t,n),a=Dc(t),u=class extends e{constructor(...[l,i]){let T=i?.["~payload"],S=T?.token===Ts?T.value:r.make(l??{},i);super(S,{...i,disableChecks:!0,"~payload":{token:Ts,value:S}})}static[wr]=wr;get[a](){return a}static[Lf]=!0;static identifier=t;static fields=r.fields;static get ast(){return s(this).ast}static pipe(){return fe(this,arguments)}static rebuild(l){return s(this).rebuild(l)}static make(l,i){return new this(l,i)}static makeOption(l,i){return In(s(this))(l??{},i)}static makeEffect(l,i){return s(this).makeEffect(l??{},i)}static annotate(l){return this.rebuild(Mt(this.ast,l))}static annotateKey(l){return this.rebuild(Tn(this.ast,l))}static check(...l){return this.rebuild(xt(this.ast,l))}static extend(l){return(i,x)=>{let T=vs(i)?i:je(i),S={...r.fields,...T.fields},h=gn(S,r.ast.checks,{identifier:l});return Pc(this,l,bs(xt(h,T.ast.checks),S),x,o)}}static mapFields(l,i){return r.mapFields(l,i)}};if(o!==void 0)Object.assign(u.prototype,o(t));return u}function $f(e){return new se(oe((t)=>new e(t,{"~payload":{token:Ts,value:t}})),mt())}function Dc(e){return`~effect/Schema/Class/${e}`}function Bf(e,t,r){let n;return(o)=>{if(n!==void 0)return n;let s=Dc(t),a=(i)=>i instanceof o||_(i,s),u=$f(o),l=Z(new ht([e.ast],()=>(i,x,T)=>a(i)?j(i):A(new we(x,i,T)),{identifier:t,[nn]:([i])=>({isConstructed:a,link:new ae(i,u)}),toCodec:([i])=>new ae(i.ast,u),toArbitrary:([i])=>()=>({arbitrary:i.arbitrary.map((x)=>new o(x)),terminal:i.terminal?.map((x)=>new o(x))}),toFormatter:([i])=>(x)=>`${o.identifier}(${i(x)})`,[rn]:Ut(e.ast),...r}));return n=Is(l,u)(e)}}function vs(e){return Rc(e)}var jf=(e)=>(t,r)=>{let n=vs(t)?t:je(t);return Pc(Nr,e,n,r,(s)=>({name:s}))},qf=(e)=>(t,r,n)=>{let o=vs(r)?r.mapFields((s)=>({_tag:On(t),...s}),{unsafePreserveChecks:!0}):vf(t,r);return jf(e??t)(o,n)};var Jf=Z(Mt(gc,{toCode:()=>({runtime:"Schema.Json",Type:"Schema.Json"})}));var Gb=te.pipe(wf("Tool.CallID"));class Nc extends qf()("Tool.Error",{message:te,error:Es(Df()),metadata:Es(yf(te,_c))}){}var Kf=je({type:kn("text"),text:te}).annotate({identifier:"Tool.TextContent"}),zf=je({type:kn("file"),uri:te,mime:te,name:Es(te)}).annotate({identifier:"Tool.FileContent"}),Kb=ws([Kf,zf]).pipe(Cf("type")).annotate({identifier:"Tool.Content"});function Lc(){return{id:"cc-safety-net",effect:(e)=>ml(function*(){let t=e.options.shell??(process.platform==="win32"?"powershell":"posix");if(t!=="posix"&&t!=="powershell")return yield*en(Error("CC Safety Net: plugin option shell must be posix or powershell."));if(yield*e.tool.hook("execute.before",(n)=>tn({try:()=>Rn({configCwd:e.location.directory,tool:n.tool,sessionID:n.sessionID,toolInput:n.input,route:n.tool==="shell"?{kind:"command",shell:t}:{kind:V(n.tool)}}),catch:(o)=>new Nc({message:o instanceof Error?o.message:String(o)})})),yield*e.shell.hook("create.before",(n)=>{if(_n(n.shell)===t)return hi;return en(Error(`CC Safety Net: actual shell "${n.shell}" does not match plugin option shell "${t}". Configure the plugin's shell option to match OpenCode; supported dialects are posix and powershell.`))}),(yield*e.command.list().pipe(hl)).data.some((n)=>n.name==="cc-safety-net"))return;yield*e.command.transform((n)=>{let o=Ir()["cc-safety-net"];if(!o)return;n.add({name:"cc-safety-net",description:o.description,execute:(s)=>e.session.prompt({...s.prompt,sessionID:s.sessionID,delivery:s.delivery,text:`${o.template}
|
|
10
|
+
|
|
11
|
+
${s.prompt.text}`}).pipe(dl)})})})}}var Vf=ks(),Hf={...Lc(),server:Vf},tw=Hf;export{Vf as CCSafetyNetPlugin,tw as default};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// cc-safety-net managed OpenClaw plugin. Do not edit. Reinstall with: npx -y cc-safety-net install --openclaw
|
|
2
|
-
// version: 2.4.
|
|
2
|
+
// version: 2.4.3
|
|
3
3
|
var tl={id:"cc-safety-net",name:"CC Safety Net",description:"Block destructive commands and secret-file access before OpenClaw runs a tool."};var fi="CC Safety Net could not analyze the command because it exceeds safe analysis limits. Simplify or split the command and retry.",$e="Command exceeds maximum recursion depth and cannot be safely analyzed. Flatten the nesting and retry.",En="CC Safety Net failed closed because command analysis failed unexpectedly. This is not caused by your command. Report it to the user.";var di={errorCode:"path-canonicalization-limit",reason:"CC Safety Net could not analyze the command because it exceeds safe analysis limits. Simplify or split the command and retry."},vn={errorCode:"structural-shell-syntax-limit",reason:"Command analysis exceeds CC Safety Net's derived-command work limit. Reduce nested or embedded command complexity and retry."},V=Object.freeze({realpathAttempts:{cap:16384,...di},processedCandidateBytes:{cap:4194304,...di},pathEnvironmentExpansion:{cap:64,...di},recursionDepth:{cap:10,errorCode:"structural-shell-syntax-limit",reason:"Command exceeds maximum recursion depth and cannot be safely analyzed. Flatten the nesting and retry."},derivedTokens:{cap:16384,...vn},trackedHeredocFiles:{cap:64,...vn},controlFlowStates:{cap:64,...vn},wrapperPeelIterations:{cap:20,...vn},derivedCommandShape:vn});class N extends Error{kind;name="AnalysisLimit";constructor(e){super(V[e].reason);this.kind=e}}function ye(){let e=new Map;return{counters:e,resolvedPaths:new Map,charge(t,n=1){let r=(e.get(t)??0)+n;if(e.set(t,r),r>V[t].cap)throw new N(t)}}}var op=[/\bgh[pousr]_[A-Za-z0-9]{20,}\b/g,/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,/\bglpat-[A-Za-z0-9_-]{20,}\b/g,/\bxox[abeprs]-[A-Za-z0-9-]{20,}\b/g,/\bnpm_[A-Za-z0-9_]{20,}\b/g,/\bpypi-[A-Za-z0-9_-]{20,}\b/g,/\b[rs]k_(?:live|test)_[A-Za-z0-9_]{20,}\b/g,/\bsk-[A-Za-z0-9_-]{20,}\b/g,/\bsk_[A-Za-z0-9]{20,}\b/g,/\bgsk_[A-Za-z0-9]{52,}\b/g,/\bxai-[A-Za-z0-9_-]{80,}\b/g,/\bpplx-[A-Za-z0-9_-]{20,}\b/g,/\bbastn_[A-Za-z0-9]{16,}\b/g,/\btgp_v1_[A-Za-z0-9_-]{43,}\b/g,/\bflp_[A-Za-z0-9]{10,}\b/g,/\bwfr_[A-Za-z0-9]{20,}\b/g,/\bfwp?_[A-Za-z0-9_-]{20,}\b/g,/\btp-[A-Za-z0-9_-]{20,}\b/g,/\bpsk-[A-Za-z0-9_-]{8,}-[A-Za-z0-9_-]{8,}\b/g,/\b[a-f0-9]{32}\.[A-Za-z0-9]{16}\b/g];function st(e){return ip(e.replace(/\b((?:DATABASE|POSTGRES|POSTGRESQL|MYSQL|MARIADB|REDIS|MONGO(?:DB)?|DB)_DSN|CONNECTION_STRING)=("[^"]*"|'[^']*'|[^\s]+(?:\s+[A-Z_][A-Z0-9_]*=[^\s]+)*)/gi,"$1=<redacted>").replace(/\b((?:DATABASE|POSTGRES|POSTGRESQL|MYSQL|MARIADB|REDIS|MONGO(?:DB)?|DB)_(?:URL|URI|CONNECTION_STRING))=("[^"]*"|'[^']*'|[^\s]+)/gi,"$1=<redacted>").replace(/\b([A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASS|KEY|CREDENTIALS)[A-Z0-9_]*)=("[^"]*"|'[^']*'|[^\s]+)/gi,"$1=<redacted>"))}function ip(e){return op.reduce((t,n)=>t.replace(n,"<redacted>"),e.replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/gi,"<redacted>").replace(/((?:(['"])(?:authorization|cookie|x-api-key|api-key)\2|(?:authorization|cookie|x-api-key|api-key))\s*:\s*)(['"])(?:\\[^\r\n]|(?!\3)[^\\\r\n])*\3/gi,"$1$3<redacted>$3").replace(/(['"]?\s*(?:authorization|cookie|x-api-key|api-key)\s*:(?!\s*(?:"<redacted>"|'<redacted>'))\s*)([^'"\r\n]+)(['"]?)/gi,"$1<redacted>$3").replace(/\b([a-z][a-z0-9+.-]*:\/\/)([^\s/:@]+):([^\s@/]+)@/gi,"$1<redacted>:<redacted>@").replace(/\b([a-z][a-z0-9+.-]*:\/\/)([^\s/@:]+)@/gi,"$1<redacted>@").replace(/(^|[\s?&;|])((?:x-amz-signature|x-goog-signature|sig|signature)=)(?:"[^"\r\n]*"|'[^'\r\n]*'|[^&#\s'"`;|<>()]*)/gi,"$1$2<redacted>").replace(/(^|\s)((?:-u|--user)(?:\s+|=))([^\s:]+):([^\s]+)/g,"$1$2<redacted>:<redacted>")).replace(/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\b/g,"<redacted>").replace(/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,"<redacted>")}var sp={hard_stop:"Do not retry this operation or attempt any workaround (other tools, flags, or paths). Report the block to the user and continue with the rest of the task.",use_alternative:"Do not retry the blocked form. Continue the task using the safer alternative described above.",scope_down:"Retry with a narrower, explicit target as described above. Escalate to the user if the broad operation is truly required.",manual_only:"If this operation is truly needed, ask the user for explicit permission and have them run the command manually.",stop_and_explain:"Do not brute-force variants. Simplify or restructure the command so it can be analyzed, or report the block to the user."};function ap(e){let t=e.maxLen??200,n=e.redact??((o)=>o),r=(o)=>o.length>t?`${o.slice(0,t)}...`:o;return["BLOCKED by CC Safety Net",`Reason: ${n(e.reason)}`,e.ruleId?`Rule: ${e.ruleId}`:void 0,e.toolName?`Tool: ${e.toolName}`:void 0,e.command?`Command: ${r(n(e.command))}`:void 0,e.segment&&e.segment!==e.command?`Segment: ${r(n(e.segment))}`:void 0,e.configWarning?`Config warning: ${n(e.configWarning)}`:void 0,sp[e.intent??"manual_only"]].filter((o)=>o!==void 0).join(`
|
|
4
4
|
|
|
5
5
|
`)}function nl(e,t){if(e.decision.kind!=="deny")return;let n=t.includeEvidence?e.decision.evidence:void 0;return{reason:e.decision.reason,ruleId:e.decision.ruleId,intent:e.decision.intent,command:n?.command,segment:n?.segment,toolName:t.toolName,...e.configFallback?{configWarning:e.configFallback.reason}:{}}}function Rn(e={}){return{reason:En,intent:"stop_and_explain",command:e.command,segment:e.segment??e.command,toolName:e.toolName}}function rl(e){return ap({...e,redact:st})}function ol(e){return st(e instanceof Error?e.message:String(e))}import{isAbsolute as wl,relative as Dp,resolve as Lp,sep as Wp}from"node:path";import{basename as al,dirname as lp,isAbsolute as cp,join as up,normalize as dp,resolve as il}from"node:path";var fp=256,Er=new Set(["CC_SAFETY_NET_HOME","CLAUDE_CONFIG_DIR","CODEX_HOME","COPILOT_HOME","GEMINI_CLI_HOME","GROK_HOME","HOME","KIMI_CODE_HOME","KIMI_SHARE_DIR","OPENCODE_CONFIG","OPENCODE_CONFIG_DIR","PI_CODING_AGENT_DIR","ProgramData","TMPDIR","XDG_CONFIG_HOME","XDG_DATA_HOME"]);function Ce(e,t=process.platform){if(t!=="win32")return e;return e.replace(/^\/([A-Za-z])(?:\/|$)/,"$1:/")}function at(e,t=process.platform){if(t!=="win32")return!1;return(e[0]==="/"||e[0]==="\\")&&(e[1]==="/"||e[1]==="\\")}function hi(e,t){return mi(e,0,t)}function mi(e,t,n){let r="",o=0;while(o<e.length){if(e[o]!=="$"){r+=e[o],o++;continue}if(e[o+1]==="{"){let s=pi(e,o+2),a=mp(e,o,t);if(a===null){if(Er.has(s))throw new N("pathEnvironmentExpansion");r+=e.slice(o);break}let l=e.slice(o,a+1);r+=pp(l,t,n),o=a+1;continue}let i=pi(e,o+1);if(!i){r+="$",o++;continue}r+=gi(i,n)??`$${i}`,o+=i.length+1}return r}function mp(e,t,n){let r=1;for(let o=t+2;o<e.length;o++){if(e[o]==="\\"){o++;continue}if(e[o]==="$"&&e[o+1]==="{"){if(r++,n+r>V.pathEnvironmentExpansion.cap)throw new N("pathEnvironmentExpansion");o++;continue}if(e[o]!=="}")continue;if(r--,r===0)return o}return null}function pp(e,t,n){let r=e.slice(2,-1),o=pi(r,0);if(!o)return e;let i=r.slice(o.length);if(!i)return gi(o,n)??e;let s=[":-",":+",":=",":?","-","+","=","?"].find((c)=>i.startsWith(c));if(!s){if(Er.has(o))throw new N("pathEnvironmentExpansion");return e}if(!Er.has(o))return e;if(s.endsWith("="))throw new N("pathEnvironmentExpansion");let a=gi(o,n),l=s.startsWith(":")?a!==null&&a!=="":a!==null;if(s.endsWith("?")&&!l)throw new N("pathEnvironmentExpansion");if(s.endsWith("-")||s.endsWith("?"))return l?a??"":mi(i.slice(s.length),t+1,n);return l?mi(i.slice(s.length),t+1,n):""}function pi(e,t){if(!/[A-Za-z_]/.test(e[t]??""))return"";let n=t+1;while(/[A-Za-z0-9_]/.test(e[n]??""))n++;return e.slice(t,n)}function gi(e,t){if(!Er.has(e))return null;if(e==="HOME")return t.env.get("HOME")??t.home;return t.env.get(e)??null}function G(e,t,n){if(!e)return e;let r=n.resolvedPaths.get(e);if(r!==void 0)return r;let o=[],i=e;while(!0){ll(n,i);let s=t.realpath(i);if(s!==null)return sl(n,e,s,o);let a=lp(i);if(a===i||o.length>=fp)return sl(n,e,i,o);o.push(al(i)),i=a}}function sl(e,t,n,r){let o=r.length===0?n:up(n,...r.reverse());return e.resolvedPaths.set(t,o),o}function gp(e,t,n){let r=n.resolvedPaths.get(e);if(r!==void 0)return r;ll(n,e);let o=t.realpath(e);if(o!==null)n.resolvedPaths.set(e,o);return o}function ll(e,t){e.charge("realpathAttempts"),e.charge("processedCandidateBytes",Buffer.byteLength(t))}function ie(e,t,n,r){let o=ul(e,t,n);if(!o)return"";return G(o,n.paths,r).replace(/\\/g,"/")}function cl(e,t,n,r,o){let i=ul(e,t,n);if(!i)return null;if(o(al(i)))return G(i,n.paths,r).replace(/\\/g,"/");let s=gp(i,n.paths,r);return s===null?null:s.replace(/\\/g,"/")}function ul(e,t,n){let r=n.home,o=hi(e.trim(),n).replace(/\\/g,"/");if(!o)return"";let i=o==="~"?r:o.startsWith("~/")?il(r,o.slice(2)):o,s=Ce(i);return dp(cp(s)?s:il(t,s))}import{types as hp}from"node:util";var yp=new Set(["find","findbyname","glob","grep","grepsearch","listdir","listpermissions","ls","read","readfile","readurlcontent","searchweb","view","viewfile"]),Cp=new Set(["command","diff","input","patch","patchtext"]),dl=new TextEncoder,bp=new TextDecoder,Sp=/\s/,vp=64;class Ve extends Error{name="ToolInputLimitError";constructor(){super("tool input traversal limit exceeded")}}var xn=Object.freeze({maxDepth:64,maxNodes:1e4,maxKeys:1e4,maxStringBytes:1048576,maxAggregateStringBytes:4194304});function Ep(e){return e.replace(/[-_\s]/g,"").toLowerCase()}function xr(e){return yp.has(Ep(e))}function wn(e){if(!e||typeof e!=="object")return;El(e);let t=Object.getOwnPropertyDescriptor(e,"command");if(!t){if("command"in e)Ue();return}if(t.get||t.set)Ue();let n=t.value;return typeof n==="string"&&n!==""?n:void 0}function hl(e,t){return yl(e,t,{nodes:0,keys:0,stringBytes:0,ancestors:new Set},1)}function yl(e,t,n,r){let o=vl(e,n,r);if(!o)return[];let i=o.entries.flatMap(([s,a])=>{let l=yl(a,t,n,r+1);return typeof a==="string"&&t.has(Cl(s))?[a]:l});return n.ancestors.delete(o.object),i}function Cl(e){return e.replace(/-/g,"_").toLowerCase()}function bl(e){return Sl(e,!0,{nodes:0,keys:0,stringBytes:0,ancestors:new Set},1).flatMap(xp)}function Sl(e,t,n,r){let o=vl(e,n,r);if(typeof e==="string")return t?[e]:[];if(!o)return[];let i=o.entries.flatMap(([s,a])=>Sl(a,o.array?t:Cp.has(Cl(s)),n,r+1));return n.ancestors.delete(o.object),i}function Rp(e,t,n){if(t.nodes++,e!==null&&typeof e==="object"&&n>xn.maxDepth||t.nodes>xn.maxNodes)Ue();if(typeof e!=="string")return;let r=Buffer.byteLength(e);if(t.stringBytes+=r,r>xn.maxStringBytes||t.stringBytes>xn.maxAggregateStringBytes)Ue()}function vl(e,t,n){if(Rp(e,t,n),!e||typeof e!=="object")return null;let r=El(e);if(t.ancestors.has(e))Ue();let o=Reflect.ownKeys(e);if(t.keys+=o.length,t.keys>xn.maxKeys)Ue();let i=o.flatMap((s)=>{let a=Object.getOwnPropertyDescriptor(e,s);if(!a||a.get||a.set)Ue();return typeof s==="string"&&a.enumerable?[[s,a.value]]:[]});return t.ancestors.add(e),{object:e,array:r,entries:i}}function El(e){if(hp.isProxy(e))Ue();let t=Array.isArray(e),n=Object.getPrototypeOf(e);if(t&&n!==Array.prototype||!t&&n!==Object.prototype&&n!==null)Ue();return t}function Ue(){throw new Ve}function xp(e){let t=[],n=e.split(/\r?\n/),r=!1,o=!1,i=null,s=null,a=()=>{o=!1,i=null,s=null};for(let l=0;l<n.length;l++){let c=n[l]??"";if(c==="*** Begin Patch"){r=!0,a();continue}if(c==="*** End Patch"){r=!1,a();continue}if(c.startsWith("@@")){let f=_p(c);if(o=!0,i=f?.oldLines??null,s=f?.newLines??null,i===0&&s===0)a();continue}if(o&&i!==null&&s!==null){let f=c.startsWith(" ")||c.startsWith("-")?1:0,d=c.startsWith(" ")||c.startsWith("+")?1:0;if(i=Math.max(0,i-f),s=Math.max(0,s-d),i===0&&s===0)a();continue}if(c.startsWith("*** ")){a(),t.push(...yi(c));continue}if(o)continue;if(c.startsWith("diff --git ")){t.push(...yi(c));continue}if(c.startsWith("--- ")){let f=n[l+1]??"";if(!f.startsWith("+++ "))continue;t.push(...bi(Rr(c.slice(4),!0),Rr(f.slice(4),!0))),l++;continue}if(!r)t.push(...yi(c))}return t}function _p(e){let t=/^@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@/.exec(e);if(!t)return null;return{oldLines:Number(t[1]??1),newLines:Number(t[2]??1)}}function yi(e){let t=/^\*\*\* (?:Add|Update|Delete) File: (.+)$/.exec(e);if(t?.[1])return gl(t[1]);let n=/^\*\*\* Move to: (.+)$/.exec(e);if(n?.[1])return gl(n[1]);if(e.startsWith("diff --git "))return wp(e.slice(11));let r=/^--- (.+)$/.exec(e);if(r?.[1])return pl(r[1]);let o=/^\+\+\+ (.+)$/.exec(e);if(o?.[1])return pl(o[1]);let i=/^(?:rename|copy) (?:from|to) (.+)$/.exec(e);if(i?.[1])return Mp(i[1]);return[]}function wp(e){let t=Pp(e);if(t.length===2&&t[0]&&t[1])return bi(t[0],t[1]);let n=Ap(e);return n?bi(e.slice(n.oldStart,n.oldEnd),e.slice(n.newStart,n.newEnd)):[]}function Pp(e){let t=[],n=0;while(n<e.length&&t.length<2){while(Rt(e[n]))n++;if(n>=e.length)break;let r=e[n]==='"'||e[n]==="'"?e[n]:void 0;if(!r){let i=n;while(n<e.length&&!Rt(e[n]))n++;t.push(e.slice(i,n));continue}let o=Rl(e,n,r);if(!o)return[];t.push(o.value),n=o.end}while(Rt(e[n]))n++;return n===e.length?t:[]}function Ap(e){let t=0;while(t<e.length&&Rt(e[t]))t++;let n=e.length;while(n>t&&Rt(e[n-1]))n--;let r=0,o=t;while(o<n){if(!Rt(e[o])){o++;continue}let i=o;while(o<n&&Rt(e[o]))o++;if(i===t||o===n)continue;if(r++,r>vp)Ue();if(Tp(e,t,i,o,n))return{oldStart:t,oldEnd:i,newStart:o,newEnd:n}}return null}function Tp(e,t,n,r,o){if(Ci(e,t,n,r,o))return!0;let i=fl(e,"/",t,n),s=fl(e,"/",r,o);if(i<=t||s<=r)return!1;if(Ci(e,t,i,r,s))return!1;return Ci(e,i+1,n,s+1,o)}function Ci(e,t,n,r,o){if(n-t!==o-r)return!1;for(let i=0;i<n-t;i++)if(e[t+i]!==e[r+i])return!1;return!0}function fl(e,t,n,r){for(let o=n;o<r;o++)if(e[o]===t)return o;return-1}function Rt(e){return e!==void 0&&Sp.test(e)}function Rl(e,t,n){let r=[],o=t+1;while(o<e.length){let i=String.fromCodePoint(e.codePointAt(o)??0);if(i===n)return{value:bp.decode(Uint8Array.from(r)),end:o+1};if(i!=="\\"||n==="'"){r.push(...dl.encode(i)),o+=i.length;continue}let s=e.slice(o+1),a=/^[0-7]{1,3}/.exec(s)?.[0];if(a){r.push(Number.parseInt(a,8)),o+=a.length+1;continue}r.push(...dl.encode(Ip(s[0]??""))),o+=2}return null}function Ip(e){return{a:"\x07",b:"\b",f:"\f",n:`
|
|
@@ -44,5 +44,5 @@ var tl={id:"cc-safety-net",name:"CC Safety Net",description:"Block destructive c
|
|
|
44
44
|
`).replace(/\\t/g,"\t").replace(/\\r/g,"\r")}function h_(e,t,n,r,o,i){let s=St(e);if(s.length===0||it(s[0]??"").toLowerCase()!=="xargs")return!1;let a=$t(s),l=s.slice(a.childStart);if(l.length===0)return!1;if(a.replacementToken==="")return!1;let c=a.replacementToken,f=c===null?[...l,Wa]:l.map((d)=>d.split(c).join(Wa));return si(f,t,n,r,o,i).some((d)=>d.target.includes(Wa))}function y_(e){let t=St(e);if(t.length===0)return null;let n=it(t[0]??"").toLowerCase();if(!Qn(n))return null;return C_(n,t.slice(1))?n:null}function C_(e,t){let n=$a(e);for(let r=0;r<t.length;r++){let o=t[r];if(o===void 0)break;if(Mm.has(o)||Wm(e,o)||/^--(?:eval|exec)=/.test(o))return!1;if(o==="-")return!0;if(o.startsWith("-")){if(n==="python"&&o==="-m")return!1;if(a_.get(n)?.has(o))r++;continue}return!1}return!0}function $a(e){return/^python\d/.test(e)?"python":e}function b_(e){let t=[];for(let n of e){if(Gm(n))continue;let r=/^[A-Za-z_][A-Za-z0-9_]*=(.*)$/.exec(n);if(r===null)break;if(r[1]!==void 0&&r[1]!=="")t.push(r[1])}return t}var wm=/^(?:\$\{home\}|\$\{env:(?:userprofile|home)\}|~)(?=[\\/])/i;function S_(e,t){if(!t||!wm.test(e))return e;return`~${e.replace(wm,"").replace(/\\/g,"/")}`}function ot(e,t){if(t==="--")return[];let n=[],r=t.indexOf("=");if(r>0&&r<t.length-1)n.push(t.slice(r+1));if(t.startsWith("-"))return n;if(e==="tar"&&/\.(?:tar|tgz|tar\.gz|zip)$/i.test(t))return n;if(e==="zip"&&/\.zip$/i.test(t))return n;return n.push(t),n}function v_(e){let t=-1,n=!1;for(let r=0;r<e.length;r++){let o=e[r]??"";if(!n&&o==="--"){n=!0;continue}if(n||!/^-(?:[A-Za-z]|-)/.test(o)){if(t===-1)t=r;continue}if(/^--(?:arg|argjson|argfile|rawfile|slurpfile)$/.test(o)){r+=2;continue}if(o==="--indent"||o==="-L"){r++;continue}if(o.startsWith("-L"))continue;if(/^-[srjcCMaSRnbehV]+$/.test(o)||/^--(?:slurp|raw-output0?|join-output|compact-output|color-output|monochrome-output|ascii-output|unbuffered|sort-keys|raw-input|null-input|binary|tab|seq|stream|stream-errors|exit-status|args|jsonargs|help|version|build-configuration)$/.test(o))continue;return e.flatMap((i)=>ot("jq",i))}return e.flatMap((r,o)=>o===t?[]:ot("jq",r))}function E_(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n]??"";if(r==="--"||!r.startsWith("-"))return[...t,...e.slice(n).flatMap((i)=>ot("git",i))];if(t.push(...ot("git",r)),!be.has(r))continue;let o=e[n+1];if(o===void 0)break;t.push(...r==="-c"&&o.includes("=")?[o.slice(o.indexOf("=")+1)]:ot("git",o)),n++}return t}function R_(e){return e.flatMap((t,n)=>{let r=__(t);if(r!==null)return Pm(r.flag,r.value);let o=x_(e[n-1]);return o===null?[]:Pm(o,t)})}function Pm(e,t){if(e==="-F"||e==="--form"){let n=t.indexOf("="),r=n===-1?t:t.slice(n+1);if(!r.startsWith("@")&&!r.startsWith("<"))return[];return Fa(r.slice(1).split(";")[0]??"")}if(e==="--data-urlencode"){let n=t.indexOf("@"),r=t.indexOf("=");if(n===-1||r!==-1&&r<n)return[];return Fa(t.slice(n+1))}return t.startsWith("@")?Fa(t.slice(1)):[]}function x_(e){if(e===void 0)return null;if(Om.has(e))return e;return/^-[A-Za-z]+[dF]$/.test(e)?`-${e.slice(-1)}`:null}function __(e){let t=e.slice(0,2);if(e.length>2&&(t==="-d"||t==="-F"))return{flag:t,value:e.slice(2)};let n=e.indexOf("=");if(n===-1)return null;let r=e.slice(0,n);return Om.has(r)?{flag:r,value:e.slice(n+1)}:null}function Fa(e){return e===""||e==="-"?[]:[e]}function w_(e,t,n,r,o,i){let s=e.findIndex((l)=>l.startsWith("-")||l==="("||l==="!"||l===";"),a=[...e.slice(0,s===-1?e.length:s)];for(let l=0;l<e.length;l++){if(!Bx.has(e[l]??""))continue;let c=e.slice(l+1),f=c.findIndex((m)=>$x.has(m)),d=f===-1?c:c.slice(0,f),u=si(d,t,n,r,o,i).map((m)=>m.target);if(a.push(...u.filter((m)=>m!=="{}")),!u.includes("{}"))continue;a.push(...e.slice(0,l).flatMap((m,p,h)=>{if(!Hx.has(m))return[];let g=h[p+1];return g===void 0?[]:[g,g.replace(/^\*+\//,"").replace(/\/\*+$/g,"").replace(/^\*+/,"").replace(/\*+$/g,"")]}))}return a}function P_(e,t,n,r,o,i,s){let a=[];for(let l=0;l<t.length;l++){let c=t[l];if(c===void 0)break;if(Mm.has(c)||Wm(e,c)){let d=t[l+1];if(d!==void 0)a.push(...oi(e,d,n,r,o,i,s)),l++;continue}let f=/^--(?:eval|exec)=(.*)$/.exec(c);if(f!==null&&f[1]!==void 0){a.push(...oi(e,f[1],n,r,o,i,s));continue}if(!c.startsWith("-"))a.push({target:c,cwd:i})}return a}function Wm(e,t){if(!t.startsWith("-")||t.startsWith("--")||t.length<=2)return!1;return Kx.get(t[t.length-1]??"")?.has($a(e))??!1}function A_(e,t,n,r,o,i){if(!e.includes("system"))return[];return ta(e)?.commands.flatMap((s)=>Sn(t.getShellSyntax(s),t,n,r,o,i))??[]}function T_(e){return Array.from(e.matchAll(/\bgetline(?:\s+[A-Za-z_][A-Za-z0-9_]*)?\s*<\s*"((?:\\.|[^"\\])*)"/g)).map((t)=>t[1]).filter((t)=>t!==void 0&&t!=="")}function I_(e){let t=Array.from(e.matchAll(/(['"`])((?:\\.|(?!\1).)*)\1/g)).map((n)=>n[2]).filter((n)=>n!==void 0&&n!=="");return[...t,...t.flatMap(Ua),...e.match(Ga)??[]]}function oi(e,t,n,r,o,i,s){let a=(m)=>({target:m,cwd:i}),l=O_(t,k_(e));if(l===null)return I_(t).map(a);let c=l.masked.match(r_)!==null||l.literals.some((m)=>o_.test(l.masked.slice(0,m.start))),f=l.masked.match(i_)!==null||l.literals.some((m)=>s_.test(l.masked.slice(0,m.start))),d=r.refineInlineData===!0&&!Xn.has(e),u=d&&!(L_(l.masked)||c||f)?[]:l.literals;return[...u.map((m)=>m.text).filter((m)=>m!=="").map(a),...u.flatMap((m)=>Ua(m.text)).map(a),...d?[]:l.literals.flatMap((m)=>m.text.match(Ga)??[]).map(a),...c?l.literals.flatMap((m)=>za(m.text,n,r,o,i,s)??[a(m.text)]):[],...f?l.literals.flatMap((m)=>oi(e,m.text.replace(/\\(.)/g,(p,h)=>h==="n"?`
|
|
45
45
|
`:h),n,r,o,i,s)):[],...(l.masked.match(Ga)??[]).map(a)]}function k_(e){let t=$a(e);if(t==="python")return"python";if(t==="osascript")return"opaque";return t==="node"||t==="bun"||t==="deno"?"javascript":"simple"}function O_(e,t){if(t==="opaque")return null;let n=e.split(""),r=[];for(let o=0;o<e.length;o++){let i=e[o]??"";if(t==="simple"&&(i==="`"||i==="%"||i==="<")){if(t_.test(e.slice(o)))return null}let s=i==="'"||i==='"'||t==="javascript"&&i==="`"?i:null;if(s===null)continue;if(s==="`"&&D_(e,o))return null;let a=t==="python"?M_(e,o):"",l=t==="python"&&e.startsWith(s.repeat(3),o)?s.repeat(3):s,c=o+l.length,f=N_(e,c,l);if(f===null)return null;let d=e.slice(c,f);if(/[fF]/.test(a)&&d.includes("{"))return null;if(t==="simple"&&s==='"'&&n_.test(d))return null;r.push({start:c,text:d});for(let u=o;u<f+l.length;u++)n[u]=" ";o=f+l.length-1}return{masked:n.join(""),literals:r}}function M_(e,t){return e_.exec(e.slice(Math.max(0,t-3),t))?.[1]??""}function N_(e,t,n){let r=n==="`",o=r||n.length===3;for(let i=t;i<e.length;i++){let s=e[i];if(s==="\\"){i++;continue}if(r&&s==="$"&&e[i+1]==="{")return null;if(!o&&(s===`
|
|
46
46
|
`||s==="\r"))return null;if(e.startsWith(n,i))return i}return null}function D_(e,t){for(let n=t-1;n>=0;n--){let r=e[n];if(!r||/\s/.test(r))continue;return/[\w$\])]/.test(r)}return!1}function L_(e){for(let t of e.matchAll(/[A-Za-z_$][A-Za-z0-9_$]*/g)){let n=t[0],r=t.index;if(jx.has(n.toLowerCase()))return!0;let o=n.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[_$\s]+/).map((i)=>i.toLowerCase());if(!o.some((i)=>Vx.has(i)))continue;if(o.length>1)return!0;if(W_(e,r)===".")return!0;if(F_(e,r+n.length)==="(")return!0}return!1}function W_(e,t){for(let n=t-1;n>=0;n--)if(!/\s/.test(e[n]??""))return e[n];return}function F_(e,t){for(let n=t;n<e.length;n++)if(!/\s/.test(e[n]??""))return e[n];return}function G_(e,t,n,r,o,i){return H_(e).flatMap((s)=>{let a=t.getShellSyntax(s);if(a.status==="invalid")return[];return[...Sn(a,t,{...n,capturedOutput:!0},r,o,i),...z_(a,r)?B_(a,r).map((l)=>({target:l,cwd:o})):[]]})}function z_(e,t){let n=So(e);for(let r=0;r<n.length;r++){let o=n[r];if(o?.kind!=="word"||it(Xe(o.text,t)).toLowerCase()!=="base64")continue;for(let i=r+1;i<n.length;i++){let s=n[i];if(s?.kind==="operator")break;if(s?.kind!=="word")continue;let a=Xe(s.text,t);if(a==="--decode"||!a.startsWith("--")&&a.startsWith("-")&&/[dD]/.test(a))return!0}}return!1}function B_(e,t){return So(e).flatMap((n)=>n.kind==="word"?[Xe(n.text,t)]:n.kind==="redirection"&&n.target?[Xe(n.target,t)]:[]).flatMap(Ua)}function Ua(e){let t=U_(e);if(t===null)return[];let n=Buffer.from(t,"base64").toString("utf8");if(n===""||$_(n))return[];return Buffer.from(n,"utf8").toString("base64").replace(/=+$/g,"")===t.replace(/=+$/g,"")?[n]:[]}function $_(e){return Array.from(e).some((t)=>{let n=t.charCodeAt(0);return n<32||n===127})}function U_(e){if(e.length<8||!/^[A-Za-z0-9+/_-]+={0,2}$/.test(e))return null;if(/=/.test(e.replace(/=+$/g,"")))return null;let t=e.replace(/=+$/g,"");if(t.length%4===1)return null;return`${t.replace(/-/g,"+").replace(/_/g,"/")}${"=".repeat((4-t.length%4)%4)}`}function H_(e){let t=[],n={inSingle:!1,inDouble:!1,escaped:!1};for(let r=0;r<e.length;r++){let o=e[r];if(!o)break;if(Nn(o,n))continue;if(Fm(e,r,n)){let i=j_(e,r+1);if(i!==null)t.push(i.body),r=i.endIndex;continue}if(!n.inSingle&&o==="`"){let i=V_(e,r);if(i!==null)t.push(i.body),r=i.endIndex}}return t}function j_(e,t){let n={inSingle:!1,inDouble:!1,escaped:!1},r=1;for(let o=t+1;o<e.length;o++){let i=e[o];if(!i)break;if(Nn(i,n))continue;if(Fm(e,o,n)){r++,o++;continue}if(!n.inSingle&&!n.inDouble&&i===")"){if(r--,r===0)return{body:e.slice(t+1,o),endIndex:o}}}return null}function V_(e,t){let n=!1;for(let r=t+1;r<e.length;r++){let o=e[r];if(!o)break;if(n){n=!1;continue}if(o==="\\"){n=!0;continue}if(o==="`")return{body:e.slice(t+1,r),endIndex:r}}return null}function Fm(e,t,n){return!n.inSingle&&e[t]==="$"&&e[t+1]==="("&&e[t+2]!=="("}function K_(e){let t=[],n=[],r=!1,o=!1,i=!1;for(let l=0;l<e.length;l++){let c=e[l];if(c===void 0)break;if(!i&&c==="--"){i=!0;continue}if(i){n.push(c);continue}let f=/^--([^=]+)(?:=(.*))?$/.exec(c);if(f!==null){let d=f[1]??"",u=f[2];if(d===Yx)o=!0;if(Xx.has(d))r=!0;if(u!==void 0){if(d===Rm)t.push(u);continue}if(Qx.has(d)){let m=e[l+1];if(d===Rm&&m!==void 0)t.push(m);l++}continue}if(c.startsWith("-")&&c.length>1){let d=c.slice(1),u="",m="";for(let h=0;h<d.length;h++){let g=d[h]??"";if(Zx.has(g))r=!0;if(Jx.has(g)){u=g,m=d.slice(h+1);break}}if(u==="")continue;if(m.length>0){if(u===Em)t.push(m);continue}let p=e[l+1];if(u===Em&&p!==void 0)t.push(p);l++;continue}n.push(c)}let a=!r&&!o?n.slice(1):n;return[...t,...a]}function St(e){let t=e.findIndex((n)=>!Gm(n)&&!/^[A-Za-z_][A-Za-z0-9_]*=.*/.test(n));return t===-1?[]:[...e.slice(t)]}function Gm(e){return e==="env"||e==="command"||e==="builtin"||e==="sudo"}var q_=new Set(["id_rsa.pub","id_ed25519.pub","id_ecdsa.pub"]),Y_=".env.",Z_=new Set([".env.example",".env.sample",".env.template",".env.defaults"]),X_=[".env.example.",".env.sample."];function J_(e){let t;try{t=new URL(e.trim())}catch{return!1}return t.protocol!=="file:"&&t.host!==""}function Q_(e){return e.length>0&&!/\s/.test(e)}function ew(e,t,n,r){try{let o=Cr(e,t,n,r);return o!==""&&n.paths.entryKind(o)!=="missing"}catch(o){if(o instanceof N)throw o;return!1}}var tw=new Set(["node_modules","__pycache__"]),nw=[["vendor","bundle"],["vendor","cache"]];function rw(e,t,n,r,o){if(J_(e))return null;let i=He(e,t,r,o);if(!i)return null;let s=B(i.split("/").pop()??""),a=B(i),l=()=>Q_(s)||ew(e,t,r,o);if(Z_.has(s)||X_.some((u)=>s.startsWith(u)))return null;let c=B(cw(e,t,r,o));for(let u of Qi){let m=`~/${u.suffixParts.join("/")}`;if((Tm(a,m)||Tm(c,m))&&rt(u.id,n))return u.id}let f=ow(i,t,n,r,o);if(f)return f;if(q_.has(s))return null;for(let u of Ji)if(s===u.basename&&rt(u.id,n))return u.id;if(s.startsWith(Y_)&&rt(Fr.id,n)&&l())return Fr.id;for(let u of es)if(s.length>u.prefix.length&&s.startsWith(u.prefix)){let m=s.slice(u.prefix.length)[0];if((m==="-"||m==="_")&&rt(u.id,n)&&l())return u.id}for(let u of ts)if(s.length>u.prefix.length&&s.startsWith(u.prefix)){if(s.slice(u.prefix.length)===u.suffix&&rt(u.id,n))return u.id}if(aw(a))return null;if(!s.includes(".")&&Dn.pattern.test(s)&&rt(Dn.id,n))return Dn.id;let d=lw(s,n);if(d)return d;return null}function ow(e,t,n,r,o){return Gr.find((i)=>{if(!rt(i.id,n))return!1;switch(i.id){case"secret.cli.claude-code":return W(e,z(r.env.get("CLAUDE_CONFIG_DIR"),"~/.claude",t,r,o),[".credentials.json"]);case"secret.cli.claude-code.config":{let s=B(e).split("/");return W(e,z(r.env.get("CLAUDE_CONFIG_DIR"),"~/.claude",t,r,o),["settings.json","settings.local.json"])||yr(e,"~/.claude.json",t,r,o)||s.at(-1)==="settings.local.json"&&s.at(-2)===".claude"||s.at(-1)===".mcp.json"}case"secret.cli.antigravity":return W(e,He("~/.gemini/config",t,r,o),["hooks.json","mcp_config.json"]);case"secret.cli.codex":{let s=z(r.env.get("CODEX_HOME"),"~/.codex",t,r,o);return W(e,s,["auth.json",".credentials.json"])||hr(e,s,["secrets",".sandbox-secrets"])}case"secret.cli.codex.config":{let s=z(r.env.get("CODEX_HOME"),"~/.codex",t,r,o),a=B(e).split("/").at(-1)??"";return W(e,s,["config.toml"])||a.endsWith(".config.toml")&&W(e,s,[a])}case"secret.cli.gemini":return W(e,ae(z(r.env.get("GEMINI_CLI_HOME"),"~",t,r,o),".gemini"),["oauth_creds.json","mcp-oauth-tokens.json","a2a-oauth-tokens.json","gemini-credentials.json"]);case"secret.cli.gemini.config":{let s=B(e).split("/"),a=r.env.get("GEMINI_CLI_SYSTEM_SETTINGS_PATH"),l=r.env.get("ProgramData")?[ae(z(r.env.get("ProgramData"),"",t,r,o),"gemini-cli")]:[];return W(e,ae(z(r.env.get("GEMINI_CLI_HOME"),"~",t,r,o),".gemini"),["settings.json","google_accounts.json"])||s.at(-1)==="settings.json"&&s.at(-2)===".gemini"||(a?.trim()?yr(e,a,t,r,o):!1)||["/Library/Application Support/GeminiCli","/etc/gemini-cli",...l].some((c)=>W(e,He(c,t,r,o),["settings.json"]))}case"secret.cli.copilot-cli":{let s=z(r.env.get("COPILOT_HOME"),"~/.copilot",t,r,o);return W(e,s,["config.json"])||hr(e,s,["mcp-oauth-config","mcp-secrets"])}case"secret.cli.copilot-cli.config":return W(e,z(r.env.get("COPILOT_HOME"),"~/.copilot",t,r,o),["mcp-config.json"]);case"secret.cli.kimi-code":{let s=z(r.env.get("KIMI_CODE_HOME"),"~/.kimi-code",t,r,o),a=z(r.env.get("KIMI_SHARE_DIR"),"~/.kimi",t,r,o);return W(e,s,["server.token"])||hr(e,s,["credentials"])||hr(e,a,["credentials","mcp-oauth"])}case"secret.cli.kimi-code.config":{let s=["config.toml","mcp.json"],a=B(e).split("/");return a.at(-1)==="mcp.json"&&a.at(-2)===".kimi-code"||W(e,z(r.env.get("KIMI_CODE_HOME"),"~/.kimi-code",t,r,o),s)||W(e,z(r.env.get("KIMI_SHARE_DIR"),"~/.kimi",t,r,o),[...s,"config.json","config.json.bak"])}case"secret.cli.opencode":{let s=ae(z(r.env.get("XDG_DATA_HOME"),"~/.local/share",t,r,o),"opencode"),a=B(e).split("/").at(-1)??"",l=r.env.get("OPENCODE_DB")?.trim(),c=l&&l!==":memory:"?[l,`${l}-wal`,`${l}-shm`]:[];return W(e,s,["auth.json","mcp-auth.json"])||/^opencode(-.+)?\.db(-wal|-shm)?$/.test(a)&&W(e,s,[a])||c.some((f)=>yr(e,f,t,r,o))}case"secret.cli.opencode.config":{let s=r.env.get("OPENCODE_CONFIG_DIR")?z(r.env.get("OPENCODE_CONFIG_DIR"),"~/.config/opencode",t,r,o):ae(z(r.env.get("XDG_CONFIG_HOME"),"~/.config",t,r,o),"opencode"),a=r.env.get("ProgramData")?[ae(z(r.env.get("ProgramData"),"",t,r,o),"opencode")]:[],l=["opencode.json","opencode.jsonc"],c=r.env.get("OPENCODE_CONFIG");return l.includes(B(e).split("/").at(-1)??"")||W(e,s,l)||(c?.trim()?yr(e,c,t,r,o):!1)||["/Library/Application Support/opencode","/etc/opencode",...a].some((f)=>W(e,He(f,t,r,o),l))}case"secret.cli.pi":return W(e,z(r.env.get("PI_CODING_AGENT_DIR"),"~/.pi/agent",t,r,o),["auth.json"]);case"secret.cli.pi.config":return W(e,z(r.env.get("PI_CODING_AGENT_DIR"),"~/.pi/agent",t,r,o),["models.json"]);case"secret.cli.amp":{let s=He("~",t,r,o);return[ae(z(r.env.get("XDG_DATA_HOME"),"~/.local/share",t,r,o),"amp"),ae(s,".local","share","amp")].some((l)=>W(e,l,["secrets.json"]))||hr(e,ae(s,".amp"),["oauth"])}case"secret.cli.amp.config":{let s=["settings.json","settings.jsonc"],a=[ae(z(r.env.get("XDG_CONFIG_HOME"),"~/.config",t,r,o),"amp"),ae(He("~",t,r,o),".config","amp")],l=B(e).split("/"),c=r.env.get("AMP_SETTINGS_FILE");return a.some((f)=>W(e,f,s))||l.at(-2)===".amp"&&s.includes(l.at(-1)??"")||(c?.trim()?yr(e,c,t,r,o):!1)}case"secret.cli.cursor":{let s=ae(z(r.env.get("XDG_CONFIG_HOME"),"~/.config",t,r,o),"cursor"),a=ae(z(r.env.get("CURSOR_DATA_DIR"),"~/.cursor",t,r,o),"projects");return W(e,He("~/.cursor",t,r,o),["auth.json"])||W(e,s,["auth.json"])||B(e).split("/").at(-1)==="mcp-auth.json"&&jt(B(e),B(a))}case"secret.cli.cursor.config":{let s=B(e).split("/");return s.at(-1)==="mcp.json"&&s.at(-2)===".cursor"}case"secret.cli.grok-build":return W(e,z(r.env.get("GROK_HOME"),"~/.grok",t,r,o),["auth.json","mcp_credentials.json"]);case"secret.cli.grok-build.config":{let s=B(e).split("/");return s.at(-1)==="config.toml"&&s.at(-2)===".grok"||W(e,z(r.env.get("GROK_HOME"),"~/.grok",t,r,o),["config.toml","managed_config.toml","requirements.toml"])||W(e,He("/etc/grok",t,r,o),["managed_config.toml","requirements.toml"])}default:return!1}})?.id??null}var Am=new WeakMap;function z(e,t,n,r,o){let i=Am.get(o)??new Map;Am.set(o,i);let s=`${n}\x00${e??""}\x00${t}`,a=i.get(s);if(a!==void 0)return a;let l=He(e?.trim()?e:t,n,r,o);return i.set(s,l),l}function W(e,t,n){return n.some((r)=>zm(e,ae(t,r)))}function hr(e,t,n){return n.some((r)=>jt(B(e),B(ae(t,r))))}function yr(e,t,n,r,o){return zm(e,He(t,n,r,o))}function zm(e,t){return B(e)===B(t)}function ae(e,...t){return Be([e,...t].filter(Boolean).join("/"))}function iw(e,t,n,r,o,i){if(n.length===0)return!1;let s=B(Cr(e,t,o,i));return n.some((a)=>jt(s,B(Cr(a,r,o,i))))}function sw(e,t,n,r,o,i){if(n.length===0)return!1;let s=B(Cr(e,t,o,i));if(!s)return!1;let a=o.env.get("HOME")??o.home,l=a?Be(G(Ce(a),o.paths,i)):"",c=B(l),f=o.env.get("CC_SAFETY_NET_HOME"),d=B(f?Be(G(ii(Ce(f)),o.paths,i)):l&&Be(G(`${l}/.cc-safety-net`,o.paths,i)));if(d&&jt(s,d))return!1;return n.some((u)=>{let m=B(Cr(u,r,o,i));if(!m)return!1;if(c&&(c===m||c.startsWith(m.endsWith("/")?m:`${m}/`)))return!1;return jt(s,m)})}function aw(e){let t=e.split("/");return t.some((n)=>tw.has(n))||nw.some(([n,r])=>t.some((o,i)=>o===n&&t[i+1]===r))}function lw(e,t){let n=e.lastIndexOf("."),r=n>0&&n<e.length-1?e.slice(n+1):"";if(r==="")return null;for(let o of ns)if(r===o.extension&&rt(o.id,t))return o.id;for(let o of rs)if(o.pattern.test(r)&&rt(o.id,t))return o.id;return null}function B(e){return e.toLowerCase()}function rt(e,t){return!t?.disabledRules?.includes(e)}function He(e,t,n,r){let{home:o,normalized:i}=Ha(e,n,r);if(!i)return"";if(!o)return i;let s=ja(i,o),a=ri(s)?s:Be(ii(t,s)),l=Be(G(a,n.paths,r));if(!jt(l,o)){if(ri(s))return l;return l===a?i:l}let c=l.slice(o.length);return c?`~${c}`:"~"}function Tm(e,t){return e===t||e.startsWith(`${t}/`)}function cw(e,t,n,r){let{home:o,normalized:i}=Ha(e,n,r);if(!i||!o)return"";let s=ja(i,o),a=Wx.normalize(ri(s)?s:Be(ii(t,s))),l=Be(Ce(n.env.get("HOME")??n.home)),c=(u)=>process.platform==="win32"?u.toLowerCase():u,f=[o,l].find((u)=>u!==""&&jt(c(a),c(u)));if(f===void 0)return"";let d=a.slice(f.length);return d?`~${d}`:"~"}function Cr(e,t,n,r){let{home:o,normalized:i}=Ha(e,n,r);if(!i)return"";let s=o?ja(i,o):i;return Be(G(ri(s)?s:ii(t,s),n.paths,r))}function Ha(e,t,n){let r=t.env.get("HOME")??t.home,o=r?Be(G(Ce(r),t.paths,n)):"",i=Be(Ce(uw(Xe(e,t))));return{home:o,normalized:i}}function uw(e){if(!e.trim().toLowerCase().startsWith("file:"))return e;try{return Gx(e)}catch{return e}}function ja(e,t){if(e==="~")return t;if(e.startsWith("~/"))return ae(t,e.slice(2));return e}function dw(e){if(process.platform==="win32")return!0;return Fx.parse(e).root.length>1}function Be(e){let t=e.trim(),n=(t.includes("\\")&&dw(t)?t.replace(/\\/g,"/"):t).replace(/\/{2,}/g,"/").replace(/^\.\//,"");if(n==="/")return n;return n.replace(/\/+$/g,"")}function jt(e,t){return e===t||e.startsWith(t.endsWith("/")?t:`${t}/`)}function it(e){return e.split(/[\\/]/).pop()?.replace(/\.exe$/i,"")??e}class Vt extends Error{stage;evaluation;name="GuardEvaluationError";constructor(e,t,n){super(`CC Safety Net ${e} dependency failed`,{cause:n});this.stage=e;this.evaluation=t}}var fw={findPolicyMutation:bm,findGitMetadataMutation:td,resolveGitMetadata:mw,loadPolicySnapshot:$c,findSensitiveTarget:Nm,analyzeCommand:um,getModes:Pi};function Bm(e,t){let n={...fw,...t.dependencies},r=hw(e),o=br(e)?e.command:r,i=vt("policy-protection",o,()=>er(e)),s=pe(i,"input-candidate"),a=pe(i,"declared-command");if(br(e)&&e.command?.trim()&&a?.program.status==="limited")return{stage:"command-analysis",decision:{kind:"deny",reason:$e,intent:"stop_and_explain",evidence:{command:e.command,segment:e.command}}};if(s?.program.status==="limited")return{stage:"command-validation",decision:{kind:"deny",reason:vd,intent:"stop_and_explain"}};let l=ye(),c=vt("policy-protection",o,()=>n.resolveGitMetadata([e.context.executionCwd,e.context.configCwd],t.environment)),f=vt("policy-protection",o,()=>n.findPolicyMutation(i,t.environment,l));if(f){let E=o??f.target;return{stage:"policy-protection",decision:{kind:"deny",reason:Cm,intent:"hard_stop",evidence:{command:E,segment:f.target}}}}let d=vt("policy-protection",o,()=>pm(i,t.environment,l));if(d){let E=o??d.target;return{stage:"policy-protection",decision:{kind:"deny",reason:mm,intent:"hard_stop",evidence:{command:E,segment:d.target}}}}let u=vt("policy-protection",o,()=>n.findGitMetadataMutation(i,c,t.environment,l));if(u){let E=o??u.target;return{stage:"policy-protection",decision:{kind:"deny",reason:Pe,intent:"hard_stop",evidence:{command:E,segment:u.target}}}}let m=vt("config-load",o,()=>n.loadPolicySnapshot(t.environment,{...t.policyOptions,cwd:e.context.configCwd})),p=m.policy,h=n.getModes(p,t.environment.env),g={level:h.effectiveLevel,...pw(m)},y=p.secretProtection.enabled===!1?null:vt("secret-protection",o,()=>n.findSensitiveTarget(i,p.secretProtection,t.environment,l,{strict:br(e)||s?.program.dialect==="powershell"?h.strict:void 0}));if(y){let E=o??y.target;return{stage:"secret-protection",...g,decision:{kind:"deny",reason:Im,intent:"hard_stop",ruleId:y.ruleId,evidence:{command:E,segment:y.target}}}}if(!br(e))return{stage:"non-command",...g,decision:{kind:"allow"}};if(!e.command||e.command.trim()==="")return{...Va("command-validation",o),...g};let v=vt("command-analysis",o,()=>dm(()=>n.analyzeCommand(e.command,{cwd:e.context.executionCwd,shell:e.route.shell,policySnapshot:m,environment:t.environment,protectedGitMetadata:c,effectiveCapabilities:h.capabilities,strict:h.strict,paranoidRm:h.paranoidRm,paranoidInterpreters:h.paranoidInterpreters,worktreeMode:h.worktreeMode,budget:l,...t.trace?{trace:t.trace}:{}},gw(i),i.store),e.command,t.trace));if(v.decision)return{stage:"command-analysis",...g,..."errorCode"in v?{errorCode:v.errorCode}:{},decision:v.decision};return{stage:"command-analysis",...g,decision:{kind:"allow"}}}function mw(e,t){let n=[...new Set(e.filter((r)=>typeof r==="string"&&r!==""))].flatMap((r)=>t.gitMetadata(r)??[]);if(n.length===0)return null;return Object.freeze({entries:Object.freeze([...new Set(n.flatMap((r)=>r.entries))]),markerFiles:Object.freeze([...new Set(n.flatMap((r)=>r.markerFiles))]),directories:Object.freeze([...new Set(n.flatMap((r)=>r.directories))]),hooksDirectories:Object.freeze([...new Set(n.flatMap((r)=>r.hooksDirectories))])})}function pw(e){if(e.state==="ready")return{};return{configFallback:{reason:e.reason}}}function gw(e){return pe(e,"declared-command")?.program}function hw(e){try{return wn(e.input)}catch(t){let n=br(e)?e.command:void 0;throw new Vt("policy-protection",Va("policy-protection",t instanceof Ve?void 0:n,t),t)}}function vt(e,t,n){try{return n()}catch(r){throw new Vt(e,Va(e,r instanceof Ve?void 0:t,r),r)}}function Va(e,t,n){let r=n instanceof N||n instanceof Le;return{stage:e,decision:{kind:"deny",reason:r?fi:En,intent:"stop_and_explain",...t?{evidence:{command:t,segment:t}}:{}}}}function br(e){return e.route.kind==="command"}import{appendFileSync as Tw,mkdirSync as Iw}from"node:fs";import{isAbsolute as kw,join as Ya}from"node:path";import{lstatSync as Um,readdirSync as yw,readFileSync as Cw,rmdirSync as bw,statSync as Hm,unlinkSync as Sw,utimesSync as vw,writeFileSync as Ew}from"node:fs";import{join as Sr}from"node:path";function $m(e,t={}){return Kr(Jt(e,t),e.home).policy.audit.retention_days}var qa=86400000,Rw=".last-prune",xw=/^\d{4}-\d{2}$/,_w=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,jm=(e)=>Math.floor(e/qa);function Km(e,t,n=()=>new Date){try{let r=n().getTime();if(!Hm(t,{throwIfNoEntry:!1})?.isDirectory())return;let o=Sr(t,Rw),i=Hm(o,{throwIfNoEntry:!1})?.mtimeMs;if(i!==void 0&&jm(i)===jm(r))return;let s=r-$m(e)*qa,a=new Date(r).toISOString().slice(0,7);for(let l of Ka(t)){if(l.isDirectory()){ww(Sr(t,l.name),s,a);continue}if(l.isFile()&&l.name.endsWith(".jsonl"))Pw(Sr(t,l.name),s)}Ew(o,"",{mode:384}),vw(o,r/1000,r/1000)}catch{}}function ww(e,t,n){for(let r of Ka(e)){if(!r.isDirectory()||!xw.test(r.name))continue;let o=Sr(e,r.name);for(let i of Ka(o)){if(!i.isFile())continue;let s=_w.exec(i.name);if(!s||s[2]!==r.name)continue;let a=Date.parse(`${s[1]}T00:00:00.000Z`)+qa;if(!Number.isFinite(a)||a>=t)continue;qm(Sr(o,i.name))}if(r.name!==n)Vm(o)}Vm(e)}function Pw(e,t){try{let n=Um(e);if(n.mtimeMs>=t)return;let r=Cw(e,"utf-8").split(`
|
|
47
|
-
`).filter((o)=>o.trim()).map(Aw);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(Um(e).mtimeMs!==n.mtimeMs)return;qm(e)}catch{}}function Aw(e){try{let t=JSON.parse(e).ts,n=typeof t==="string"?Date.parse(t):Number.NaN;return Number.isFinite(n)?n:void 0}catch{return}}function Ka(e){try{return yw(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function qm(e){try{Sw(e)}catch{}}function Vm(e){try{bw(e)}catch{}}var Ow="2.4.
|
|
47
|
+
`).filter((o)=>o.trim()).map(Aw);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(Um(e).mtimeMs!==n.mtimeMs)return;qm(e)}catch{}}function Aw(e){try{let t=JSON.parse(e).ts,n=typeof t==="string"?Date.parse(t):Number.NaN;return Number.isFinite(n)?n:void 0}catch{return}}function Ka(e){try{return yw(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function qm(e){try{Sw(e)}catch{}}function Vm(e){try{bw(e)}catch{}}var Ow="2.4.3",Mw=1e4,Nw=2000,Dw=256,Lw=32768;function Ww(e){let t=e.trim();if(!t)return null;let n=t.replace(/[^A-Za-z0-9_.-]+/g,"_");if(n=n.replace(/^[._-]+|[._-]+$/g,"").slice(0,128),!n||n==="."||n==="..")return null;return n}function Fw(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function Za(e,t,n,r,o,i,s={}){let a=Ww(t);if(!a)return;let l=zw(e);if(!l)return;try{let c=(s.now??(()=>new Date))().toISOString(),f=ai(st(n),s.failureStage?Number.POSITIVE_INFINITY:Mw),d=ai(st(r),Nw),u=s.toolName?ai(st(s.toolName),Dw):void 0,m=i===null?void 0:ai(st(i),Lw),p=Ya(l,Fw(m?.value??null),c.slice(0,7));Iw(p,{recursive:!0,mode:448});let h=Ya(p,`${c.slice(0,10)}-${a}.jsonl`),g={ts:c,id:(s.createId??Ti)(),v:Ow,sessionId:a,decision:s.decision??"deny",agent:s.agent,shape:s.shape,level:s.level,configFallback:s.configFallback,toolName:u?.value,command:f.value,segment:d.value,...f.truncated||d.truncated||u?.truncated||m?.truncated?{truncated:!0}:{},reason:o,ruleId:s.ruleId,intent:s.intent,failureStage:s.failureStage,errorCode:s.errorCode,cwd:m?.value??null};Tw(h,`${JSON.stringify(g)}
|
|
48
48
|
`,{encoding:"utf-8",mode:384}),Km(e,l,s.now)}catch{}}function ai(e,t){return{value:e.slice(0,t),truncated:e.length>t}}function Gw(e){let t=e.env.get("CC_SAFETY_NET_AUDIT_HOME");if(e.env.get("NODE_ENV")==="test"&&!t)return null;let n=t||e.home;return n&&kw(n)?n:null}function zw(e){let t=Gw(e);return t?Ya(t,".cc-safety-net","logs"):null}function Zm(e,t,n,r=!0,o){if(t.decision.kind==="allow"){if(!n||e.route.kind!=="command")return;let a=Ym(e);return{decision:"allow",command:a,segment:a,reason:"allowed",cwd:e.context.executionCwd,toolName:e.toolName,level:t.level,...t.configFallback?{configFallback:!0}:{}}}let i=t.decision.evidence,s=i?.command??(r?Ym(e):"");return{decision:"deny",command:s,segment:i?.segment??s,reason:t.decision.reason,cwd:e.context.executionCwd,toolName:e.toolName,level:t.level,...t.configFallback?{configFallback:!0}:{},ruleId:t.decision.ruleId,intent:t.decision.intent,failureStage:o?.stage,errorCode:o?.errorCode}}function Ym(e){return"command"in e?e.command??"":""}function Xm(e,t,n,r){if(!t)return;let o;try{o=n()}catch{return}if(typeof o!=="string"||!o.trim())return;Za(e,o,t.command,t.segment,t.reason,t.cwd,{decision:t.decision,agent:r.agent,shape:r.shape,level:t.level,configFallback:t.configFallback,toolName:t.toolName,ruleId:t.ruleId,intent:t.intent,failureStage:t.failureStage,errorCode:t.errorCode})}function Jm(e,t,n,r){let o;try{o=n()}catch{return}if(typeof o!=="string"||!o.trim())return;Za(e,o,t.command??"",t.segment??t.command??"",t.reason,r.cwd??null,{decision:"deny",agent:r.agent,shape:r.shape,toolName:r.toolName??t.toolName,ruleId:t.ruleId,intent:t.intent})}function ep(e,t,n){try{let r=Bm(t,{environment:e,...n.guard});return Qm(e,t,r,n),r}catch(r){if(!(r instanceof Vt))throw r;throw Qm(e,t,r.evaluation,n,!(r.cause instanceof Ve),{stage:r.stage,errorCode:Bw(r.cause)}),r}}function Qm(e,t,n,r,o=!0,i){Xm(e,Zm(t,n,r.guard?.auditAllowed??!1,o,i),r.audit.getSessionId,{agent:r.audit.agent,shape:r.audit.shape})}function Bw(e){if(e instanceof N)return V[e.kind].errorCode;if(e instanceof Ve)return"tool-input-limit";if(e instanceof Le)return"structural-shell-syntax-limit";return"unexpected-error"}function Et(e,t={}){return{malformed:!0,denial:Rn(t),cwd:e}}function tp(e,t={}){return(n,r)=>{try{return $w(n,r,e,t)}catch(o){return console.error("CC Safety Net error:",o),e.block(Rn())}}}function $w(e,t,n,r){let o=Ml();if(n.cancelled?.(t))return n.block(Rn());let i=n.extract(e,t,o.paths);if(!i)return n.allow;let s=()=>n.getSessionId(e,t);if("malformed"in i)return Jm(o,i.denial,s,{agent:n.agent,toolName:i.denial.toolName,cwd:i.cwd}),n.block(i.denial);let a=(l,c)=>{let f=nl(l,{includeEvidence:c});return f?n.block(f):n.allow};try{let l=ep(o,i,{guard:{auditAllowed:Nl(o.env),policyOptions:r.policyOptions,dependencies:r.guardDependencies},audit:{agent:n.agent,getSessionId:s}});return a(l,!0)}catch(l){if(!(l instanceof Vt))throw l;if(xt(Q.debug,o.env))console.error(`CC Safety Net debug: ${n.debugLabel} analysis failed: ${ol(l.cause)}`);return a(l.evaluation,n.includeEvidenceOnError(i))}}var np="exec",Uw=new Set(["auto","gateway"]);function rp(e){e.on("before_tool_call",Hw(e),{matcher:[np],priority:50})}function Hw(e,t={}){return tp({agent:"openclaw",debugLabel:"openclaw before_tool_call",extract:(r,o,i)=>jw(r,o,e,i),getSessionId:(r,o)=>o.sessionId??o.sessionKey,allow:void 0,block:(r)=>qw(r),includeEvidenceOnError:()=>!0,cancelled:(r)=>r.abortSignal?.aborted===!0},t)}function jw(e,t,n,r){if(!e||typeof e!=="object")return Et(null);let o=e.toolName;if(typeof o!=="string"||o.trim()==="")return Et(null);if(o!==np)return;if(e.toolKind!==void 0)return;let i=e.params;if(!i||typeof i!=="object"||Array.isArray(i))return Et(null,{toolName:o});let s=i,a=s.command;if(typeof a!=="string"||a.trim()==="")return Et(null,{toolName:o});if(s.host!==void 0&&!Uw.has(s.host))return Et(null,{command:a,toolName:o});let l=Vw(n,t.agentId,r);if(!l)return Et(null,{command:a,toolName:o});let c=Kw(l,s,r);if(!c)return Et(l,{command:a,segment:typeof s.workdir==="string"?s.workdir:void 0,toolName:o});return Pn(o,s,{kind:"command",shell:"auto"},{configCwd:l,executionCwd:c},a)}function Vw(e,t,n){if(typeof t!=="string"||t.trim()==="")return;try{let r=e.runtime.agent.resolveAgentWorkspaceDir(e.config,t);if(typeof r!=="string"||r.trim()==="")return;return Si(".",[r],n)}catch{return}}function Kw(e,t,n){if(!Object.hasOwn(t,"workdir")||t.workdir===void 0)return e;let r=t.workdir;if(typeof r!=="string"||r.trim()==="")return;return Si(r,[e],n)}function qw(e){return{block:!0,blockReason:rl(e)}}var HD={...tl,register:rp};export{HD as default};
|
package/dist/pi/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{ye,
|
|
1
|
+
import{ye,P,be,Xe,c,o,xe,R,V,et,d,p}from"../chunks/index-26getn55.js";import{Q}from"../chunks/index-p4h81vth.js";import{he,D}from"../chunks/index-sp43p448.js";var E="cc-safety-net",x="Operate CC Safety Net: explain blocks, rules, integrations, diagnostics",w="Help me with CC Safety Net.";function f(e){e.registerCommand(E,{description:x,handler:async(n,l)=>{e.sendUserMessage(N(n),l.isIdle()?void 0:{deliverAs:"followUp"})}})}function N(e){return`${Q.slice(Q.indexOf("# CC Safety Net")).trimEnd()}
|
|
2
2
|
|
|
3
3
|
## User request
|
|
4
4
|
|
|
5
|
-
${e.trim()||
|
|
5
|
+
${e.trim()||w}`}function g(e,n={}){return{malformed:!0,denial:P(n),cwd:e}}function T(e,n={}){return(l,t)=>{try{return I(l,t,e,n)}catch(i){return console.error("CC Safety Net error:",i),e.block(P())}}}function I(e,n,l,t){let i=c();if(l.cancelled?.(n))return l.block(P());let r=l.extract(e,n,i.paths);if(!r)return l.allow;let s=()=>l.getSessionId(e,n);if("malformed"in r)return he(i,r.denial,s,{agent:l.agent,toolName:r.denial.toolName,cwd:r.cwd}),l.block(r.denial);let m=(a,y)=>{let C=ye(a,{includeEvidence:y});return C?l.block(C):l.allow};try{let a=D(i,r,{guard:{auditAllowed:xe(i.env),policyOptions:t.policyOptions,dependencies:t.guardDependencies},audit:{agent:l.agent,getSessionId:s}});return m(a,!0)}catch(a){if(!(a instanceof p))throw a;if(R(o.debug,i.env))console.error(`CC Safety Net debug: ${l.debugLabel} analysis failed: ${Xe(a.cause)}`);return m(a.evaluation,l.includeEvidenceOnError(r))}}var b=new Map([["bash","posix"]]),O={agent:"pi",debugLabel:"pi tool_call",extract:(e,n,l)=>k(e,n,l),getSessionId:(e,n)=>n.sessionManager.getSessionId(),allow:void 0,block:(e)=>M(e),includeEvidenceOnError:(e)=>e.route.kind==="command"};function v(e){e.on("tool_call",S)}var S=A();function A(e={}){return T(O,e)}function k(e,n,l){if(!e||typeof e!=="object")return;let t=e;if(t.type!==void 0&&t.type!=="tool_call")return;if(typeof t.toolName!=="string"||t.toolName.trim()==="")return u(n);let i=typeof n.cwd==="string"&&n.cwd.trim()!==""?et(".",[n.cwd],l):void 0;if(!i)return u(n,t.toolName);let r=b.get(t.toolName);if(!t.input||typeof t.input!=="object")return r?u(n,t.toolName):void 0;if(!r)return d(t.toolName,t.input,{kind:V(t.toolName)},{configCwd:i,executionCwd:i},null);let s=t.input.command;if(typeof s!=="string"||s.trim()==="")return u(n,t.toolName);return d(t.toolName,t.input,{kind:"command",shell:r},{configCwd:i,executionCwd:i},s)}function u(e,n){return g(typeof e.cwd==="string"&&e.cwd.trim()?e.cwd:null,{toolName:n})}function M(e){return{block:!0,reason:be(e)}}function _(e){v(e),f(e)}export{_ as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-safety-net",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "A coding agent CLI hook - block destructive commands and secret file access",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"types": "./dist/api.d.ts",
|
|
15
15
|
"import": "./dist/api.js"
|
|
16
16
|
},
|
|
17
|
+
"./opencode/v2": {
|
|
18
|
+
"types": "./dist/opencode-v2.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
17
21
|
"./package.json": "./package.json"
|
|
18
22
|
},
|
|
19
23
|
"bin": {
|
|
@@ -61,19 +65,26 @@
|
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@ampcode/plugin": "0.0.0-20260724002649-ga3413e7",
|
|
63
67
|
"@biomejs/biome": "2.3.10",
|
|
64
|
-
"@opencode-ai/plugin": "^1.18.
|
|
68
|
+
"@opencode-ai/plugin": "^1.18.29",
|
|
69
|
+
"@opencode/plugin": "2.0.6",
|
|
70
|
+
"@opencode/schema": "2.0.6",
|
|
65
71
|
"@types/bun": "latest",
|
|
72
|
+
"effect": "4.0.0-rc.112",
|
|
66
73
|
"jscpd": "^5.0.14",
|
|
67
74
|
"knip": "^6.32.0",
|
|
68
75
|
"lefthook": "^2.1.10",
|
|
69
76
|
"typescript": "7.0.2"
|
|
70
77
|
},
|
|
71
78
|
"peerDependencies": {
|
|
72
|
-
"@opencode-ai/plugin": "^1.18.
|
|
79
|
+
"@opencode-ai/plugin": "^1.18.29",
|
|
80
|
+
"@opencode/plugin": "^2.0.6"
|
|
73
81
|
},
|
|
74
82
|
"peerDependenciesMeta": {
|
|
75
83
|
"@opencode-ai/plugin": {
|
|
76
84
|
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@opencode/plugin": {
|
|
87
|
+
"optional": true
|
|
77
88
|
}
|
|
78
89
|
},
|
|
79
90
|
"pi": {
|
|
@@ -82,6 +93,7 @@
|
|
|
82
93
|
]
|
|
83
94
|
},
|
|
84
95
|
"overrides": {
|
|
96
|
+
"@opentelemetry/core": "2.8.0",
|
|
85
97
|
"js-yaml": "^4.3.1",
|
|
86
98
|
"picomatch@^2.3.1": "2.3.2",
|
|
87
99
|
"picomatch@^4.0.1": "^4.0.5",
|
|
@@ -104,5 +116,5 @@
|
|
|
104
116
|
"grok",
|
|
105
117
|
"grok-build"
|
|
106
118
|
],
|
|
107
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "49be587b269b435362c68aeb5ba90c3b0334b3d0"
|
|
108
120
|
}
|