cc-safety-net 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import{$ as Y,I as F,L as O,aa as _,ia as m,na as U,q as C,r as w,ub as h,vb as W}from"./index-4g6x1r63.js";import{lstatSync as N,readdirSync as J,readFileSync as x,rmdirSync as X,statSync as v,unlinkSync as q,utimesSync as ee,writeFileSync as te}from"node:fs";import{dirname as ne,join as u}from"node:path";var A=86400000,re=".last-prune",ie=/^\d{4}-\d{2}$/,oe=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,k=(e)=>Math.floor(e/A);function ae(e){try{let n=u(ne(O(e)),F),t=JSON.parse(x(n,"utf-8"));return w(t?.audit?.retention_days)}catch{return C}}function R(e,n=()=>new Date){try{let t=n().getTime();if(!v(e,{throwIfNoEntry:!1})?.isDirectory())return;let r=u(e,re),i=v(r,{throwIfNoEntry:!1})?.mtimeMs;if(i!==void 0&&k(i)===k(t))return;let o=t-ae()*A,s=new Date(t).toISOString().slice(0,7);for(let a of p(e)){if(a.isDirectory()){se(u(e,a.name),o,s);continue}if(a.isFile()&&a.name.endsWith(".jsonl"))ce(u(e,a.name),o)}te(r,"",{mode:384}),ee(r,t/1000,t/1000)}catch{}}function se(e,n,t){for(let r of p(e)){if(!r.isDirectory()||!ie.test(r.name))continue;let i=u(e,r.name);for(let o of p(i)){if(!o.isFile())continue;let s=oe.exec(o.name);if(!s||s[2]!==r.name)continue;let a=Date.parse(`${s[1]}T00:00:00.000Z`)+A;if(!Number.isFinite(a)||a>=n)continue;L(u(i,o.name))}if(r.name!==t)T(i)}T(e)}function ce(e,n){try{let t=N(e);if(t.mtimeMs>=n)return;let r=x(e,"utf-8").split(`
2
- `).filter((i)=>i.trim()).map(de);if(r.length===0)return;if(r.some((i)=>i===void 0||i>=n))return;if(N(e).mtimeMs!==t.mtimeMs)return;L(e)}catch{}}function de(e){try{let n=JSON.parse(e).ts,t=typeof n==="string"?Date.parse(n):Number.NaN;return Number.isFinite(t)?t:void 0}catch{return}}function p(e){try{return J(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function L(e){try{q(e)}catch{}}function T(e){try{X(e)}catch{}}import{randomBytes as fe}from"node:crypto";import{appendFileSync as pe,mkdirSync as Ae}from"node:fs";import{homedir as Ee,userInfo as ye}from"node:os";import{isAbsolute as _e,join as E}from"node:path";var ue=[/\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 d(e){let n=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>");return z(n)}function z(e){let n=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>");for(let t of ue)n=n.replace(t,"<redacted>");return n.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>")}function le(e){return G(e).reduceRight((t,r)=>`${t.slice(0,r.valueStart)}<redacted>${t.slice(r.valueEnd)}`,e)}function Le(e){return z(le(e))}function ze(e){return G(e).map((n)=>e.slice(n.valueStart,n.valueEnd))}function Ge(e){return/[A-Za-z_][A-Za-z0-9_]*=/.test(e)}function G(e){let n=[],t=/[A-Za-z_][A-Za-z0-9_]*=/g;for(let r of e.matchAll(t)){let i=r.index,o=e[i-1];if(i>0&&o&&!/[\s"'([{]/.test(o))continue;let s=i+r[0].length;if(s>=e.length)continue;n.push({valueStart:s,valueEnd:me(e,s)})}return n}function me(e,n){if(e.startsWith("$(",n))return ge(e,n);let t=e[n];if(t==='"'||t==="'"){for(let i=n+1;i<e.length;i++)if(t==='"'&&e[i]==="\\")i++;else if(e[i]===t)return i+1}let r=n;while(r<e.length&&!/\s/.test(e[r]??""))r++;return r}function ge(e,n){let t=0,r;for(let i=n;i<e.length;i++){let o=e[i];if(r){if(r==='"'&&o==="\\")i++;else if(o===r)r=void 0;continue}if(o==='"'||o==="'"){r=o;continue}if(o==="$"&&e[i+1]==="("){t++,i++;continue}if(o!==")")continue;if(t--,t===0)return i+1}return e.length}var he="2.1.0",Se=1e4,be=2000,Ie=256,De=32768;function Ne(e){let n=e.trim();if(!n)return null;let t=n.replace(/[^A-Za-z0-9_.-]+/g,"_");if(t=t.replace(/^[._-]+|[._-]+$/g,"").slice(0,128),!t||t==="."||t==="..")return null;return t}function ve(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function y(e,n,t,r,i,o={}){let s=Ne(e);if(!s)return;let a=o.homeDir??Z();if(!a)return;let c=ke(a);if(!c)return;try{let g=(o.now??(()=>new Date))().toISOString(),S=l(d(n),o.failureStage?Number.POSITIVE_INFINITY:Se),b=l(d(t),be),I=o.toolName?l(d(o.toolName),Ie):void 0,f=i===null?void 0:l(d(i),De),D=E(c,ve(f?.value??null),g.slice(0,7));Ae(D,{recursive:!0,mode:448});let j=E(D,`${g.slice(0,10)}-${s}.jsonl`),Q={ts:g,id:(o.createId??(()=>fe(8).toString("hex")))(),v:he,sessionId:s,decision:o.decision??"deny",agent:o.agent,shape:o.shape,level:o.level,configFallback:o.configFallback,toolName:I?.value,command:S.value,segment:b.value,...S.truncated||b.truncated||I?.truncated||f?.truncated?{truncated:!0}:{},reason:r,ruleId:o.ruleId,intent:o.intent,failureStage:o.failureStage,errorCode:o.errorCode,cwd:f?.value??null};pe(j,`${JSON.stringify(Q)}
2
+ `).filter((i)=>i.trim()).map(de);if(r.length===0)return;if(r.some((i)=>i===void 0||i>=n))return;if(N(e).mtimeMs!==t.mtimeMs)return;L(e)}catch{}}function de(e){try{let n=JSON.parse(e).ts,t=typeof n==="string"?Date.parse(n):Number.NaN;return Number.isFinite(t)?t:void 0}catch{return}}function p(e){try{return J(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function L(e){try{q(e)}catch{}}function T(e){try{X(e)}catch{}}import{randomBytes as fe}from"node:crypto";import{appendFileSync as pe,mkdirSync as Ae}from"node:fs";import{homedir as Ee,userInfo as ye}from"node:os";import{isAbsolute as _e,join as E}from"node:path";var ue=[/\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 d(e){let n=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>");return z(n)}function z(e){let n=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>");for(let t of ue)n=n.replace(t,"<redacted>");return n.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>")}function le(e){return G(e).reduceRight((t,r)=>`${t.slice(0,r.valueStart)}<redacted>${t.slice(r.valueEnd)}`,e)}function Le(e){return z(le(e))}function ze(e){return G(e).map((n)=>e.slice(n.valueStart,n.valueEnd))}function Ge(e){return/[A-Za-z_][A-Za-z0-9_]*=/.test(e)}function G(e){let n=[],t=/[A-Za-z_][A-Za-z0-9_]*=/g;for(let r of e.matchAll(t)){let i=r.index,o=e[i-1];if(i>0&&o&&!/[\s"'([{]/.test(o))continue;let s=i+r[0].length;if(s>=e.length)continue;n.push({valueStart:s,valueEnd:me(e,s)})}return n}function me(e,n){if(e.startsWith("$(",n))return ge(e,n);let t=e[n];if(t==='"'||t==="'"){for(let i=n+1;i<e.length;i++)if(t==='"'&&e[i]==="\\")i++;else if(e[i]===t)return i+1}let r=n;while(r<e.length&&!/\s/.test(e[r]??""))r++;return r}function ge(e,n){let t=0,r;for(let i=n;i<e.length;i++){let o=e[i];if(r){if(r==='"'&&o==="\\")i++;else if(o===r)r=void 0;continue}if(o==='"'||o==="'"){r=o;continue}if(o==="$"&&e[i+1]==="("){t++,i++;continue}if(o!==")")continue;if(t--,t===0)return i+1}return e.length}var he="2.1.1",Se=1e4,be=2000,Ie=256,De=32768;function Ne(e){let n=e.trim();if(!n)return null;let t=n.replace(/[^A-Za-z0-9_.-]+/g,"_");if(t=t.replace(/^[._-]+|[._-]+$/g,"").slice(0,128),!t||t==="."||t==="..")return null;return t}function ve(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function y(e,n,t,r,i,o={}){let s=Ne(e);if(!s)return;let a=o.homeDir??Z();if(!a)return;let c=ke(a);if(!c)return;try{let g=(o.now??(()=>new Date))().toISOString(),S=l(d(n),o.failureStage?Number.POSITIVE_INFINITY:Se),b=l(d(t),be),I=o.toolName?l(d(o.toolName),Ie):void 0,f=i===null?void 0:l(d(i),De),D=E(c,ve(f?.value??null),g.slice(0,7));Ae(D,{recursive:!0,mode:448});let j=E(D,`${g.slice(0,10)}-${s}.jsonl`),Q={ts:g,id:(o.createId??(()=>fe(8).toString("hex")))(),v:he,sessionId:s,decision:o.decision??"deny",agent:o.agent,shape:o.shape,level:o.level,configFallback:o.configFallback,toolName:I?.value,command:S.value,segment:b.value,...S.truncated||b.truncated||I?.truncated||f?.truncated?{truncated:!0}:{},reason:r,ruleId:o.ruleId,intent:o.intent,failureStage:o.failureStage,errorCode:o.errorCode,cwd:f?.value??null};pe(j,`${JSON.stringify(Q)}
3
3
  `,{encoding:"utf-8",mode:384}),R(c,o.now)}catch{}}function l(e,n){return{value:e.slice(0,n),truncated:e.length>n}}function Z(e=process.env.CC_SAFETY_NET_AUDIT_HOME||process.env.HOME){let n=e||Ee()||ye().homedir;return n&&_e(n)?n:null}function ke(e=Z()){return e?E(e,".cc-safety-net","logs"):null}function B(e,n,t,r=!0,i){if(n.decision.kind==="allow"){if(!t||e.route.kind!=="command")return;let a=M(e);return{decision:"allow",command:a,segment:a,reason:"allowed",cwd:e.context.executionCwd,toolName:e.toolName,level:n.level,...n.configFallback?{configFallback:!0}:{}}}let o=n.decision.evidence.find((a)=>a.kind==="command"),s=o?.command??(r?M(e):"");return{decision:"deny",command:s,segment:o?.segment??s,reason:n.decision.reason,cwd:e.context.executionCwd,toolName:e.toolName,level:n.level,...n.configFallback?{configFallback:!0}:{},ruleId:n.decision.ruleId,intent:n.decision.intent,failureStage:i?.stage,errorCode:i?.errorCode}}function M(e){return"command"in e?e.command??"":""}function P(e,n,t){if(!e)return;let r;try{r=n()}catch{return}if(typeof r!=="string"||!r.trim())return;y(r,e.command,e.segment,e.reason,e.cwd,{homeDir:t.homeDir,decision:e.decision,agent:t.agent,shape:t.shape,level:e.level,configFallback:e.configFallback,toolName:e.toolName,ruleId:e.ruleId,intent:e.intent,failureStage:e.failureStage,errorCode:e.errorCode})}function We(e,n,t){let r;try{r=n()}catch{return}if(typeof r!=="string"||!r.trim())return;y(r,e.command??"",e.segment??e.command??"",e.reason,t.cwd??null,{homeDir:t.homeDir,decision:"deny",agent:t.agent,shape:t.shape,toolName:t.toolName??e.toolName,ruleId:e.ruleId,intent:e.intent})}function K(e){let{reason:n,command:t,segment:r,toolName:i}=e,o=e.maxLen??200,s=e.redact??((c)=>c),a=`BLOCKED by CC Safety Net
4
4
 
5
5
  Reason: ${s(n)}`;if(e.ruleId)a+=`
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as d}from"./chunks/index-25nh5wqs.js";import{k as w,l as y,m as l,n as h,p as R}from"./chunks/index-znwvxg7d.js";import{Fa as k,X as p,ia as E,ja as v,ka as D,ub as P,xa as x}from"./chunks/index-4g6x1r63.js";import{resolve as T}from"node:path";function f(){return{"cc-safety-net":{description:"Manage CC Safety Net rulebooks",template:d.slice(d.indexOf("## Workflow"))}}}var z=new Set(["powershell","pwsh"]),B=new Set(["bash","dash","ksh","sh","zsh"]);function S(o={}){return async({directory:r,homeDir:t})=>{let n=T(r),a;return{config:async(i)=>{a=i;let c=f(),s=i.command??{};i.command={...c,...s}},"tool.execute.before":async(i,c)=>{let s=(e,O,_=n)=>{w(e,()=>i.sessionID,{agent:"opencode",toolName:O,cwd:_,homeDir:t}),A(e)};if(typeof i.tool!=="string"||i.tool.trim()==="")s(l());let u=c.args,m;try{m=D(u)}catch(e){if(!(e instanceof E))throw e;s(l({toolName:i.tool}),i.tool)}let I=U(a?.shell),b=G(i.tool,I),g=W(n,u);if(!p(n)||!g)return s(l({command:m,toolName:i.tool}),i.tool);let L={configCwd:n,executionCwd:g},N=k(i.tool,u,b,L,m??null);try{let e=R(N,{guard:{auditAllowed:x(),dependencies:o},audit:{agent:"opencode",homeDir:t,getSessionId:()=>i.sessionID}});C(e,!0)}catch(e){if(!(e instanceof P))throw e;if(e.stage==="policy-protection"||e.stage==="config-load"||e.stage==="secret-protection")throw e.cause;C(e.evaluation,!0);return}}}}}function U(o,r=process.platform,t=process.env.SHELL){if(typeof o!=="string"&&r==="win32")return"powershell";let n=typeof o==="string"?o:t;if(typeof n!=="string")return"auto";let a=n.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(!a)return"auto";if(z.has(a))return"powershell";if(B.has(a))return"posix";return"auto"}function G(o,r){if(o==="bash")return{kind:"command",shell:r};return{kind:v(o)}}function W(o,r){if(!r||typeof r!=="object"||Array.isArray(r))return o;if(!Object.hasOwn(r,"workdir"))return o;let t=r.workdir;if(typeof t!=="string"||t.trim()==="")return null;let n=process.platform==="win32"?Z(t):t,a=T(o,n);return p(a)?a:null}function Z(o){return o.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`)}function C(o,r){let t=y(o,{includeEvidence:r});if(t)A(t)}function A(o){throw Error(h(o))}var io=S();export{io as CCSafetyNetPlugin};
1
+ import{a as d}from"./chunks/index-25nh5wqs.js";import{k as w,l as y,m as l,n as h,p as R}from"./chunks/index-gdm1kya3.js";import{Fa as k,X as p,ia as E,ja as v,ka as D,ub as P,xa as x}from"./chunks/index-4g6x1r63.js";import{resolve as T}from"node:path";function f(){return{"cc-safety-net":{description:"Manage CC Safety Net rulebooks",template:d.slice(d.indexOf("## Workflow"))}}}var z=new Set(["powershell","pwsh"]),B=new Set(["bash","dash","ksh","sh","zsh"]);function S(o={}){return async({directory:r,homeDir:t})=>{let n=T(r),a;return{config:async(i)=>{a=i;let c=f(),s=i.command??{};i.command={...c,...s}},"tool.execute.before":async(i,c)=>{let s=(e,O,_=n)=>{w(e,()=>i.sessionID,{agent:"opencode",toolName:O,cwd:_,homeDir:t}),A(e)};if(typeof i.tool!=="string"||i.tool.trim()==="")s(l());let u=c.args,m;try{m=D(u)}catch(e){if(!(e instanceof E))throw e;s(l({toolName:i.tool}),i.tool)}let I=U(a?.shell),b=G(i.tool,I),g=W(n,u);if(!p(n)||!g)return s(l({command:m,toolName:i.tool}),i.tool);let L={configCwd:n,executionCwd:g},N=k(i.tool,u,b,L,m??null);try{let e=R(N,{guard:{auditAllowed:x(),dependencies:o},audit:{agent:"opencode",homeDir:t,getSessionId:()=>i.sessionID}});C(e,!0)}catch(e){if(!(e instanceof P))throw e;if(e.stage==="policy-protection"||e.stage==="config-load"||e.stage==="secret-protection")throw e.cause;C(e.evaluation,!0);return}}}}}function U(o,r=process.platform,t=process.env.SHELL){if(typeof o!=="string"&&r==="win32")return"powershell";let n=typeof o==="string"?o:t;if(typeof n!=="string")return"auto";let a=n.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(!a)return"auto";if(z.has(a))return"powershell";if(B.has(a))return"posix";return"auto"}function G(o,r){if(o==="bash")return{kind:"command",shell:r};return{kind:v(o)}}function W(o,r){if(!r||typeof r!=="object"||Array.isArray(r))return o;if(!Object.hasOwn(r,"workdir"))return o;let t=r.workdir;if(typeof t!=="string"||t.trim()==="")return null;let n=process.platform==="win32"?Z(t):t,a=T(o,n);return p(a)?a:null}function Z(o){return o.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(t,n)=>`${n.toUpperCase()}:/`)}function C(o,r){let t=y(o,{includeEvidence:r});if(t)A(t)}function A(o){throw Error(h(o))}var io=S();export{io as CCSafetyNetPlugin};
@@ -1,7 +1,7 @@
1
1
  // cc-safety-net managed OpenClaw plugin. Do not edit. Reinstall with: npx -y cc-safety-net install --openclaw
2
- // version: 2.1.0
2
+ // version: 2.1.1
3
3
  var Ew=Object.defineProperty;var Rw=(e)=>e;function Pw(e,t){this[e]=Rw.bind(null,t)}var dn=(e,t)=>{for(var n in t)Ew(e,n,{get:t[n],enumerable:!0,configurable:!0,set:Pw.bind(t,n)})};var Ih={id:"cc-safety-net",name:"CC Safety Net",description:"Block destructive commands and secret-file access before OpenClaw runs a tool."};import{randomBytes as _E}from"node:crypto";import{appendFileSync as xE,mkdirSync as CE}from"node:fs";import{homedir as wE,userInfo as EE}from"node:os";import{isAbsolute as RE,join as Ol}from"node:path";var kw=[/\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 kt(e){let t=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>");return Aw(t)}function Aw(e){let t=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>");for(let n of kw)t=t.replace(n,"<redacted>");return t.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>")}import{lstatSync as Hh,readdirSync as cE,readFileSync as Yh,rmdirSync as lE,statSync as Vh,unlinkSync as uE,utimesSync as dE,writeFileSync as mE}from"node:fs";import{dirname as fE,join as Kn}from"node:path";var Ai=30,_l=1,xl=365;function Ti(e){if(typeof e!=="number"||!Number.isInteger(e))return 30;if(e<1)return 1;return e>365?365:e}import{homedir as Vw}from"node:os";import{dirname as Ut,isAbsolute as Kw,join as jt,relative as qw,resolve as Tt,sep as Yw}from"node:path";import{closeSync as Tw,constants as Oh,fstatSync as Iw,fsyncSync as zL,lstatSync as zh,mkdirSync as NL,openSync as Ow,readdirSync as DL,readFileSync as zw,realpathSync as Ii,renameSync as $L,rmdirSync as LL,statSync as Nw,unlinkSync as ML,writeFileSync as WL}from"node:fs";import{isAbsolute as Nh,join as Dh,normalize as Dw,parse as $w,relative as Cl,resolve as wl,sep as El}from"node:path";var Lw=Symbol("PolicyFilesystemScope"),Mw=Symbol("PolicyFilesystemTarget"),Ww=Oh.O_NOFOLLOW??0;class ae extends Error{constructor(e){super(`Unable to access ${e} filesystem safely.`);this.name="PolicyFilesystemError"}}function Bt(e,t){return{[Lw]:!0,root:wl(e),label:t}}function $h(e,t){let n=Dw(t);if(t===""||Nh(t)||n===".."||n.startsWith(`..${El}`))throw new ae(e.label);return{[Mw]:!0,scope:e,relativePath:n,path:Dh(e.root,n)}}function At(e,t){let n=Cl(e.root,wl(t));return $h(e,n)}function zi(e,t="rules policy"){let n=wl(e),r=$w(n).dir;return $h(Bt(r,t),Cl(r,n))}function mn(e){try{if(!Oi(e,!1).exists)return null;let n=Ow(e.path,Oh.O_RDONLY|Ww);try{let r=Iw(n);if(!r.isFile())throw new ae(e.scope.label);let o=zw(n,"utf-8"),i=zh(e.path);if(!i.isFile()||i.isSymbolicLink()||r.dev!==i.dev||r.ino!==i.ino)throw new ae(e.scope.label);return Oi(e,!1),o}finally{Tw(n)}}catch(t){Zw(e.scope.label,t)}}function Lh(e,t){if(e.path===t.path)return!0;try{if(!Oi(e,!1).exists||!Oi(t,!1).exists)return!1;return Ii(e.path)===Ii(t.path)}catch(n){if(n instanceof ae)throw n;throw new ae(e.scope.label)}}function Oi(e,t,n="file"){let r=Fw(e.scope);if(!r)return{exists:!1};let o=e.relativePath.split(El);for(let i of o.keys()){let s=Dh(e.scope.root,...o.slice(0,i+1)),a=Mh(s);if(!a){if(i===o.length-1&&t)return{exists:!1};return{exists:!1}}if(a.isSymbolicLink())throw new ae(e.scope.label);if(i<o.length-1&&!a.isDirectory())throw new ae(e.scope.label);if(i===o.length-1&&(n==="file"?!a.isFile():!a.isDirectory()))throw new ae(e.scope.label);Gw(r,Ii(s),e.scope.label)}return{exists:!0}}function Fw(e){if(!Mh(e.root))return null;if(!Nw(e.root).isDirectory())throw new ae(e.label);return Ii(e.root)}function Gw(e,t,n){let r=Cl(e,t);if(r===".."||r.startsWith(`..${El}`)||Nh(r))throw new ae(n)}function Mh(e){try{return zh(e)}catch(t){if(Bw(t)&&t.code==="ENOENT")return null;throw t}}function Zw(e,t){if(t instanceof ae)throw t;throw new ae(e)}function Bw(e){return e instanceof Error&&"code"in e}var ut=/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/,Rl="rulebook.json",Pl=".cc-safety-net/rules";var Wh=/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(.+)$/;var Uw=/^[A-Za-z0-9._-]+$/,jw=".cc-safety-net/rules".replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Hw="rulebook.json".replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Fh=new RegExp(`^${jw}/(${ut.source.slice(1,-1)})/${Hw}$`);function Gh(e){return`.cc-safety-net/rules/${e}/rulebook.json`}function Xr(e){if(Di(e))try{return Ni(e),null}catch(t){return t instanceof Error?t.message:String(t)}return ut.test(e)?null:`Local rulebook sources must be bare names matching ${ut}: ${e}`}function Ni(e){if(e.startsWith("github:"))throw Error(`Invalid rulebook source: ${e}`);let t=e.match(Wh);if(!t?.[1]||!t[2]||!t[3])throw Error(`Invalid GitHub rulebook source: ${e}`);let[n,r,...o]=t[3].split("/");if(!n||!Uw.test(n))throw Error(`GitHub rulebook refs must be a single path segment: ${e}`);if(!r||o.length>0||!ut.test(r))throw Error(`GitHub rulebook sources must be owner/repo#ref/<rulebook-name>: ${e}`);return{owner:t[1],repo:t[2],ref:n,path:Gh(r),name:r}}function Di(e){return Wh.test(e)}var Bh="rule.json",$i="policy.json",Jw="rule.lock";var Uh=".cc-safety-net",Xw="rules",Zh="cache",Qw="CC_SAFETY_NET_HOME",Ht="`cc-safety-net rule sync`";function eE(e){return Tt(e??process.cwd(),Pl)}function tE(e){return jt(eE(e),Bh)}function fn(e){return e?.userConfigDir??(e?.userConfigPath?Ut(e.userConfigPath):jt(nE(),Xw))}function nE(){let e=process.env[Qw];return e?Tt(e):jt(Vw(),Uh)}function rE(e){return jt(fn(e),Bh)}function Qr(e){return jt(Ut(e),Jw)}function jh(e){let t=e.userConfigPath??rE(e),n=e.projectConfigPath??tE(e.cwd),r=oE(t,e),o=iE(n,e);return{userConfigPath:t,projectConfigPath:n,userLockPath:Qr(t),projectLockPath:Qr(n),userScope:r,projectScope:o,userConfigTarget:At(r,t),projectConfigTarget:At(o,n),userLockTarget:At(r,Qr(t)),projectLockTarget:At(o,Qr(n))}}function oE(e,t){let n=t.userConfigPath?Ut(Ut(Tt(t.userConfigPath))):Ut(Tt(t.userConfigDir??fn(t)));return Bt(n,"user policy")}function iE(e,t){let n=Tt(t.cwd??process.cwd()),r=Tt(e),o=qw(n,r);if(o!==".."&&!o.startsWith(`..${Yw}`)&&!Kw(o))return Bt(n,"project policy");return Bt(Ut(Ut(r)),"project policy")}function kl(e,t){let n=e.digest.startsWith("sha256:")?e.digest.slice(7):e.digest;return jt(aE(t),"rulebooks",`${sE(e)}--${n.slice(0,12)}`,Rl)}function Al(e,t){let n=t;return{cacheConfigDir:e,cwd:t.cwd,global:n.global}}function sE(e){return(e.kind==="github"&&e.display_ref?`${e.owner}/${e.repo}#${e.display_ref}/${e.name}`:e.spec).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"rulebook"}function aE(e){let t=e?.cacheConfigDir??fn(e),n=e;if(n&&!n.global&&n.cwd&&Tt(t)===Tt(n.cwd))return jt(Tt(n.cwd),Uh,Zh);return jt(Ut(t),Zh)}var Il=86400000,pE=".last-prune",gE=/^\d{4}-\d{2}$/,hE=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,Kh=(e)=>Math.floor(e/Il);function yE(e){try{let t=Kn(fE(fn(e)),$i),n=JSON.parse(Yh(t,"utf-8"));return Ti(n?.audit?.retention_days)}catch{return Ai}}function Jh(e,t=()=>new Date){try{let n=t().getTime();if(!Vh(e,{throwIfNoEntry:!1})?.isDirectory())return;let r=Kn(e,pE),o=Vh(r,{throwIfNoEntry:!1})?.mtimeMs;if(o!==void 0&&Kh(o)===Kh(n))return;let i=n-yE()*Il,s=new Date(n).toISOString().slice(0,7);for(let a of Tl(e)){if(a.isDirectory()){bE(Kn(e,a.name),i,s);continue}if(a.isFile()&&a.name.endsWith(".jsonl"))vE(Kn(e,a.name),i)}mE(r,"",{mode:384}),dE(r,n/1000,n/1000)}catch{}}function bE(e,t,n){for(let r of Tl(e)){if(!r.isDirectory()||!gE.test(r.name))continue;let o=Kn(e,r.name);for(let i of Tl(o)){if(!i.isFile())continue;let s=hE.exec(i.name);if(!s||s[2]!==r.name)continue;let a=Date.parse(`${s[1]}T00:00:00.000Z`)+Il;if(!Number.isFinite(a)||a>=t)continue;Xh(Kn(o,i.name))}if(r.name!==n)qh(o)}qh(e)}function vE(e,t){try{let n=Hh(e);if(n.mtimeMs>=t)return;let r=Yh(e,"utf-8").split(`
4
- `).filter((o)=>o.trim()).map(SE);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(Hh(e).mtimeMs!==n.mtimeMs)return;Xh(e)}catch{}}function SE(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 Tl(e){try{return cE(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function Xh(e){try{uE(e)}catch{}}function qh(e){try{lE(e)}catch{}}var PE="2.1.0",kE=1e4,AE=2000,TE=256,IE=32768;function OE(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 zE(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function zl(e,t,n,r,o,i={}){let s=OE(e);if(!s)return;let a=i.homeDir??Qh();if(!a)return;let c=NE(a);if(!c)return;try{let l=(i.now??(()=>new Date))().toISOString(),u=Li(kt(t),i.failureStage?Number.POSITIVE_INFINITY:kE),d=Li(kt(n),AE),f=i.toolName?Li(kt(i.toolName),TE):void 0,m=o===null?void 0:Li(kt(o),IE),p=Ol(c,zE(m?.value??null),l.slice(0,7));CE(p,{recursive:!0,mode:448});let h=Ol(p,`${l.slice(0,10)}-${s}.jsonl`),b={ts:l,id:(i.createId??(()=>_E(8).toString("hex")))(),v:PE,sessionId:s,decision:i.decision??"deny",agent:i.agent,shape:i.shape,level:i.level,configFallback:i.configFallback,toolName:f?.value,command:u.value,segment:d.value,...u.truncated||d.truncated||f?.truncated||m?.truncated?{truncated:!0}:{},reason:r,ruleId:i.ruleId,intent:i.intent,failureStage:i.failureStage,errorCode:i.errorCode,cwd:m?.value??null};xE(h,`${JSON.stringify(b)}
4
+ `).filter((o)=>o.trim()).map(SE);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(Hh(e).mtimeMs!==n.mtimeMs)return;Xh(e)}catch{}}function SE(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 Tl(e){try{return cE(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function Xh(e){try{uE(e)}catch{}}function qh(e){try{lE(e)}catch{}}var PE="2.1.1",kE=1e4,AE=2000,TE=256,IE=32768;function OE(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 zE(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function zl(e,t,n,r,o,i={}){let s=OE(e);if(!s)return;let a=i.homeDir??Qh();if(!a)return;let c=NE(a);if(!c)return;try{let l=(i.now??(()=>new Date))().toISOString(),u=Li(kt(t),i.failureStage?Number.POSITIVE_INFINITY:kE),d=Li(kt(n),AE),f=i.toolName?Li(kt(i.toolName),TE):void 0,m=o===null?void 0:Li(kt(o),IE),p=Ol(c,zE(m?.value??null),l.slice(0,7));CE(p,{recursive:!0,mode:448});let h=Ol(p,`${l.slice(0,10)}-${s}.jsonl`),b={ts:l,id:(i.createId??(()=>_E(8).toString("hex")))(),v:PE,sessionId:s,decision:i.decision??"deny",agent:i.agent,shape:i.shape,level:i.level,configFallback:i.configFallback,toolName:f?.value,command:u.value,segment:d.value,...u.truncated||d.truncated||f?.truncated||m?.truncated?{truncated:!0}:{},reason:r,ruleId:i.ruleId,intent:i.intent,failureStage:i.failureStage,errorCode:i.errorCode,cwd:m?.value??null};xE(h,`${JSON.stringify(b)}
5
5
  `,{encoding:"utf-8",mode:384}),Jh(c,i.now)}catch{}}function Li(e,t){return{value:e.slice(0,t),truncated:e.length>t}}function Qh(e=process.env.CC_SAFETY_NET_AUDIT_HOME||process.env.HOME){let t=e||wE()||EE().homedir;return t&&RE(t)?t:null}function NE(e=Qh()){return e?Ol(e,".cc-safety-net","logs"):null}function ty(e,t,n,r=!0,o){if(t.decision.kind==="allow"){if(!n||e.route.kind!=="command")return;let a=ey(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.find((a)=>a.kind==="command"),s=i?.command??(r?ey(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 ey(e){return"command"in e?e.command??"":""}function ny(e,t,n){if(!e)return;let r;try{r=t()}catch{return}if(typeof r!=="string"||!r.trim())return;zl(r,e.command,e.segment,e.reason,e.cwd,{homeDir:n.homeDir,decision:e.decision,agent:n.agent,shape:n.shape,level:e.level,configFallback:e.configFallback,toolName:e.toolName,ruleId:e.ruleId,intent:e.intent,failureStage:e.failureStage,errorCode:e.errorCode})}function ry(e,t,n){let r;try{r=t()}catch{return}if(typeof r!=="string"||!r.trim())return;zl(r,e.command??"",e.segment??e.command??"",e.reason,n.cwd??null,{homeDir:n.homeDir,decision:"deny",agent:n.agent,shape:n.shape,toolName:n.toolName??e.toolName,ruleId:e.ruleId,intent:e.intent})}import{accessSync as pM,constants as gM,realpathSync as ZE,statSync as BE}from"node:fs";import{isAbsolute as iy,relative as UE,resolve as jE,sep as HE}from"node:path";import{dirname as DE,isAbsolute as $E,parse as LE,sep as ME}from"node:path";function pn(e,t=process.platform){if(t!=="win32")return!1;return(e[0]==="/"||e[0]==="\\")&&(e[1]==="/"||e[1]==="\\")}function Vt(e,t,n){if(pn(t))throw Error("Unsupported Windows namespace path");let r=$E(t)?FE(t):"",o=r||e;for(let i of GE(r?t.slice(r.length):t)){if(i===""||i===".")continue;if(i===".."){o=DE(o);continue}let s=WE(o,i),a=n.entryKind(s),c=a==="symlink"?n.realpath(s):s;if(a==="missing"||c===null)throw Error(`Cannot resolve path component: ${s}`);o=c}return o}function WE(e,t){return e.endsWith("/")||e.endsWith("\\")?`${e}${t}`:`${e}${ME}${t}`}function FE(e){return LE(e).root}function GE(e){let t=process.platform==="win32"?/[\\/]+/:/\/+/;return e.split(t)}function Mi(e,t){if(pn(e))return;let n=t.flatMap((o)=>oy(o));if(!n[0])return;let r=oy(iy(e)?e:jE(n[0],e))[0];if(!r)return;return n.some((o)=>sy(r,o))?r:void 0}function oy(e){try{let t=ZE(e);return BE(t).isDirectory()?[t]:[]}catch{return[]}}function sy(e,t){let n=UE(t,e);return n===""||n!==".."&&!n.startsWith(`..${HE}`)&&!iy(n)}var Kt="Command could not be safely analyzed (strict mode). Simplify the command and retry, or ask the user to verify.",It="Command exceeds maximum recursion depth and cannot be safely analyzed. Flatten the nesting and retry.",ay="CC Safety Net could not validate the command because its structure exceeds safe analysis limits.",cy="CC Safety Net could not analyze the command because it exceeds safe analysis limits. Simplify or split the command and retry.",Wi="CC Safety Net failed closed because command analysis failed unexpectedly. This is not caused by your command. Report it to the user.";function uy(e){let{reason:t,command:n,segment:r,toolName:o}=e,i=e.maxLen??200,s=e.redact??((c)=>c),a=`BLOCKED by CC Safety Net
6
6
 
7
7
  Reason: ${s(t)}`;if(e.ruleId)a+=`
@@ -2,7 +2,7 @@
2
2
  "id": "cc-safety-net",
3
3
  "name": "CC Safety Net",
4
4
  "description": "Block destructive commands and secret-file access before OpenClaw runs a tool.",
5
- "version": "2.1.0",
5
+ "version": "2.1.1",
6
6
  "activation": {
7
7
  "onStartup": true
8
8
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-safety-net",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Block destructive commands and secret-file access before OpenClaw runs a tool.",
5
5
  "type": "module",
6
6
  "openclaw": {
package/dist/pi/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a}from"../chunks/index-25nh5wqs.js";import{k as u,l as c,m as f,n as C,o as g,p as E}from"../chunks/index-znwvxg7d.js";import{Fa as d,Y as p,ja as P,ub as v,va as y,xa as T,za as w}from"../chunks/index-4g6x1r63.js";var D="cc-safety-net",I="Manage CC Safety Net rulebooks",M="Help me configure CC Safety Net.";function s(e){e.registerCommand(D,{description:I,handler:async(n,o)=>{e.sendUserMessage(S(n),o.isIdle()?void 0:{deliverAs:"followUp"})}})}function S(e){return`${a.slice(a.indexOf("## Workflow")).trimEnd()}
1
+ import{a}from"../chunks/index-25nh5wqs.js";import{k as u,l as c,m as f,n as C,o as g,p as E}from"../chunks/index-gdm1kya3.js";import{Fa as d,Y as p,ja as P,ub as v,va as y,xa as T,za as w}from"../chunks/index-4g6x1r63.js";var D="cc-safety-net",I="Manage CC Safety Net rulebooks",M="Help me configure CC Safety Net.";function s(e){e.registerCommand(D,{description:I,handler:async(n,o)=>{e.sendUserMessage(S(n),o.isIdle()?void 0:{deliverAs:"followUp"})}})}function S(e){return`${a.slice(a.indexOf("## Workflow")).trimEnd()}
2
2
 
3
3
  ## User request
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-safety-net",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
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",
@@ -107,5 +107,5 @@
107
107
  "cursor",
108
108
  "amp"
109
109
  ],
110
- "gitHead": "26d5803abf011ec7f674c27bdc97991bd1e627bf"
110
+ "gitHead": "b29fa191843e4820e6a095eec0cd87361b0b2099"
111
111
  }