cc-safety-net 2.7.1 → 2.7.2

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.
@@ -1,2 +1,2 @@
1
- import{Fe,te,V,I,ne,c,$e,h,b,de,Se,d,g}from"./index-rh1b7fd5.js";import{le}from"./index-e4b0v62z.js";import{Me,z}from"./index-cv33hcr9.js";import{join as v,resolve as w}from"node:path";function Be(){return{"cc-safety-net":{description:"Operate CC Safety Net: explain blocks, rules, integrations, diagnostics",template:le.slice(le.indexOf("# CC Safety Net"))}}}var x=new Set(["powershell","pwsh"]),O=new Set(["fish","nu"]),it="bash",Oe="shell";function Et(n={}){return async({directory:t,homeDir:a})=>{let e=w(t),o;return{config:async(i)=>{o=i;let s=Be(),l=i.command??{};i.command={...s,...l}},"tool.execute.before":async(i,s)=>{st({configCwd:e,homeDir:a,tool:i.tool,sessionID:i.sessionID,toolInput:s.args,route:k(i.tool,at(o?.shell)),guardDependencies:n})}}}}function st({configCwd:n,homeDir:t,expandHomeWorkdir:a=!1,tool:e,sessionID:o,toolInput:i,route:s,guardDependencies:l={}}){let f=t===void 0?c():{...c(),home:t},u=(r,D,T=n)=>{Me(f,r,()=>o,{agent:"opencode",toolName:D,cwd:T}),y(r)};if(typeof e!=="string"||e.trim()==="")u(V());let m;try{m=de(i)}catch(r){if(!(r instanceof h))throw r;u(te({toolName:e}),e)}if(!Se(n)){u(I({directory:"session",problem:"unusable",cwd:n},{command:m,toolName:e}),e);return}let p=P(n,i,a?f.home:void 0);if(p===null){u(V({command:m,toolName:e}),e);return}if(typeof p!=="string"){u(I(p,{command:m,toolName:e}),e,p.cwd);return}let E=d(e,i,s,{configCwd:n,executionCwd:p},m??null);try{let r=z(f,E,{guard:{auditAllowed:$e(f.env),dependencies:l},audit:{agent:"opencode",getSessionId:()=>o}});C(r)}catch(r){if(!(r instanceof g))throw r;if(r.stage==="policy-protection"||r.stage==="config-load"||r.stage==="secret-protection")throw r.cause;C(r.evaluation);return}}function at(n,t=process.platform,a=process.env.SHELL){let o=(typeof n==="string"?n:a)?.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(typeof n!=="string"&&t==="win32"&&(!o||O.has(o)))return"powershell";if(!o)return"auto";if(x.has(o))return"powershell";return o==="cmd"?"auto":"posix"}function k(n,t){if(n===it)return{kind:"command",shell:t};return{kind:b(n)}}function P(n,t,a){if(!t||typeof t!=="object"||Array.isArray(t))return n;if(!Object.hasOwn(t,"workdir"))return n;let e=t.workdir;if(typeof e!=="string"||e.trim()==="")return null;let o=process.platform==="win32"?S(e):e,i=o.startsWith("~/")||process.platform==="win32"&&o.startsWith("~\\"),s=a===void 0?o:o==="~"?a:i?v(a,o.slice(2)):o,l=w(n,s);return Se(l)?l:{directory:"requested",problem:"unusable",cwd:e}}function S(n){return n.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`)}function C(n){let t=Fe(n,{includeEvidence:!0});if(t)y(t)}function y(n){throw Error(ne(n))}
1
+ import{Fe,te,V,I,ne,c,$e,h,b,de,Se,d,g}from"./index-3xe319mt.js";import{le}from"./index-e4b0v62z.js";import{Me,z}from"./index-bn4xwa1w.js";import{join as v,resolve as w}from"node:path";function Be(){return{"cc-safety-net":{description:"Operate CC Safety Net: explain blocks, rules, integrations, diagnostics",template:le.slice(le.indexOf("# CC Safety Net"))}}}var x=new Set(["powershell","pwsh"]),O=new Set(["fish","nu"]),it="bash",Oe="shell";function Et(n={}){return async({directory:t,homeDir:a})=>{let e=w(t),o;return{config:async(i)=>{o=i;let s=Be(),l=i.command??{};i.command={...s,...l}},"tool.execute.before":async(i,s)=>{st({configCwd:e,homeDir:a,tool:i.tool,sessionID:i.sessionID,toolInput:s.args,route:k(i.tool,at(o?.shell)),guardDependencies:n})}}}}function st({configCwd:n,homeDir:t,expandHomeWorkdir:a=!1,tool:e,sessionID:o,toolInput:i,route:s,guardDependencies:l={}}){let f=t===void 0?c():{...c(),home:t},u=(r,D,T=n)=>{Me(f,r,()=>o,{agent:"opencode",toolName:D,cwd:T}),y(r)};if(typeof e!=="string"||e.trim()==="")u(V());let m;try{m=de(i)}catch(r){if(!(r instanceof h))throw r;u(te({toolName:e}),e)}if(!Se(n)){u(I({directory:"session",problem:"unusable",cwd:n},{command:m,toolName:e}),e);return}let p=P(n,i,a?f.home:void 0);if(p===null){u(V({command:m,toolName:e}),e);return}if(typeof p!=="string"){u(I(p,{command:m,toolName:e}),e,p.cwd);return}let E=d(e,i,s,{configCwd:n,executionCwd:p},m??null);try{let r=z(f,E,{guard:{auditAllowed:$e(f.env),dependencies:l},audit:{agent:"opencode",getSessionId:()=>o}});C(r)}catch(r){if(!(r instanceof g))throw r;if(r.stage==="policy-protection"||r.stage==="config-load"||r.stage==="secret-protection")throw r.cause;C(r.evaluation);return}}function at(n,t=process.platform,a=process.env.SHELL){let o=(typeof n==="string"?n:a)?.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(typeof n!=="string"&&t==="win32"&&(!o||O.has(o)))return"powershell";if(!o)return"auto";if(x.has(o))return"powershell";return o==="cmd"?"auto":"posix"}function k(n,t){if(n===it)return{kind:"command",shell:t};return{kind:b(n)}}function P(n,t,a){if(!t||typeof t!=="object"||Array.isArray(t))return n;if(!Object.hasOwn(t,"workdir"))return n;let e=t.workdir;if(typeof e!=="string"||e.trim()==="")return null;let o=process.platform==="win32"?S(e):e,i=o.startsWith("~/")||process.platform==="win32"&&o.startsWith("~\\"),s=a===void 0?o:o==="~"?a:i?v(a,o.slice(2)):o,l=w(n,s);return Se(l)?l:{directory:"requested",problem:"unusable",cwd:e}}function S(n){return n.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(a,e)=>`${e.toUpperCase()}:/`)}function C(n){let t=Fe(n,{includeEvidence:!0});if(t)y(t)}function y(n){throw Error(ne(n))}
2
2
  export{Be,it,Oe,Et,st,at};
@@ -1,2 +1,2 @@
1
- import{Fe,te,V,I,_t,c,r,$e,k,g}from"./index-rh1b7fd5.js";import{Me,z}from"./index-cv33hcr9.js";function X(n,o={}){return{malformed:!0,denial:V(o),cwd:n}}function Ne(n,o={}){return{malformed:!0,denial:te(o),cwd:n}}function be(n,o){return{malformed:!0,denial:I(n,o),cwd:n.cwd}}function Le(n,o={}){return(e,i)=>{try{return p(e,i,n,o)}catch(a){return console.error("CC Safety Net error:",a),n.block(te())}}}function p(n,o,e,i){let a=c();if(e.cancelled?.(o))return e.block(te());let t=e.extract(n,o,a.paths);if(!t)return e.allow;let d=()=>e.getSessionId(n,o);if("malformed"in t)return Me(a,t.denial,d,{agent:e.agent,toolName:t.denial.toolName,cwd:t.cwd}),e.block(t.denial);let u=(l,s)=>{let m=Fe(l,{includeEvidence:s});return m?e.block(m):e.allow};try{let l=z(a,t,{guard:{auditAllowed:$e(a.env),policyOptions:i.policyOptions,dependencies:i.guardDependencies},audit:{agent:e.agent,getSessionId:d}});return u(l,!0)}catch(l){if(!(l instanceof g))throw l;if(k(r.debug,a.env))console.error(`CC Safety Net debug: ${e.debugLabel} analysis failed: ${_t(l.cause)}`);return u(l.evaluation,e.includeEvidenceOnError(t))}}
1
+ import{Fe,te,V,I,_t,c,r,$e,k,g}from"./index-3xe319mt.js";import{Me,z}from"./index-bn4xwa1w.js";function X(n,o={}){return{malformed:!0,denial:V(o),cwd:n}}function Ne(n,o={}){return{malformed:!0,denial:te(o),cwd:n}}function be(n,o){return{malformed:!0,denial:I(n,o),cwd:n.cwd}}function Le(n,o={}){return(e,i)=>{try{return p(e,i,n,o)}catch(a){return console.error("CC Safety Net error:",a),n.block(te())}}}function p(n,o,e,i){let a=c();if(e.cancelled?.(o))return e.block(te());let t=e.extract(n,o,a.paths);if(!t)return e.allow;let d=()=>e.getSessionId(n,o);if("malformed"in t)return Me(a,t.denial,d,{agent:e.agent,toolName:t.denial.toolName,cwd:t.cwd}),e.block(t.denial);let u=(l,s)=>{let m=Fe(l,{includeEvidence:s});return m?e.block(m):e.allow};try{let l=z(a,t,{guard:{auditAllowed:$e(a.env),policyOptions:i.policyOptions,dependencies:i.guardDependencies},audit:{agent:e.agent,getSessionId:d}});return u(l,!0)}catch(l){if(!(l instanceof g))throw l;if(k(r.debug,a.env))console.error(`CC Safety Net debug: ${e.debugLabel} analysis failed: ${_t(l.cause)}`);return u(l.evaluation,e.includeEvidenceOnError(t))}}
2
2
  export{X,Ne,be,Le};