cc-safety-net 2.6.16 → 2.6.17
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 +5 -2
- package/dist/amp/cc-safety-net/index.ts +42 -42
- package/dist/api.js +1 -1
- package/dist/bin/hook.js +42 -42
- package/dist/chunks/index-7w6trghf.js +2 -0
- package/dist/chunks/{index-gkf3ty4y.js → index-823nnrjs.js} +4 -4
- package/dist/chunks/index-cxqk4wed.js +49 -0
- package/dist/chunks/{index-wkjncmhg.js → index-fpxp8rvc.js} +2 -2
- package/dist/chunks/index-p0tjjrnj.js +2 -0
- package/dist/chunks/index-qr496znd.js +2 -0
- package/dist/chunks/index-x65f5t9p.js +2 -0
- package/dist/cli.js +120 -120
- package/dist/deepseek-harness/index.js +1 -1
- package/dist/index.js +4 -4
- package/dist/openclaw/cc-safety-net/index.js +41 -41
- package/dist/openclaw/cc-safety-net/openclaw.plugin.json +1 -1
- package/dist/openclaw/cc-safety-net/package.json +1 -1
- package/dist/pi/index.js +2 -2
- package/package.json +2 -2
- package/dist/chunks/index-2r2nzahr.js +0 -2
- package/dist/chunks/index-3s2q5wht.js +0 -2
- package/dist/chunks/index-90bkfxht.js +0 -2
- package/dist/chunks/index-pzctbrv3.js +0 -49
- package/dist/chunks/index-wshq0mgp.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ie,Z,G,P,St,c,n,Oe,S,f}from"./index-cxqk4wed.js";import{Ae,H}from"./index-823nnrjs.js";function K(o,t={}){return{malformed:!0,denial:G(t),cwd:o}}function Pe(o,t={}){return{malformed:!0,denial:Z(t),cwd:o}}function ge(o,t){return{malformed:!0,denial:P(o,t),cwd:o.cwd}}function _e(o,t={}){return(e,i)=>{try{return p(e,i,o,t)}catch(a){return console.error("CC Safety Net error:",a),o.block(Z())}}}function p(o,t,e,i){let a=c();if(e.cancelled?.(t))return e.block(Z());let l=e.extract(o,t,a.paths);if(!l)return e.allow;let d=()=>e.getSessionId(o,t);if("malformed"in l)return Ae(a,l.denial,d,{agent:e.agent,toolName:l.denial.toolName,cwd:l.cwd}),e.block(l.denial);let u=(r,s)=>{let m=Ie(r,{includeEvidence:s});return m?e.block(m):e.allow};try{let r=H(a,l,{guard:{auditAllowed:Oe(a.env),policyOptions:i.policyOptions,dependencies:i.guardDependencies},audit:{agent:e.agent,getSessionId:d}});return u(r,!0)}catch(r){if(!(r instanceof f))throw r;if(S(n.debug,a.env))console.error(`CC Safety Net debug: ${e.debugLabel} analysis failed: ${St(r.cause)}`);return u(r.evaluation,e.includeEvidenceOnError(l))}}
|
|
2
|
+
export{K,Pe,ge,_e};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a,s,Y,m,
|
|
2
|
-
`).filter((o)=>o.trim()).map(ne);if(n.length===0)return;if(n.some((o)=>o===void 0||o>=e))return;if(
|
|
3
|
-
`,{encoding:"utf-8",mode:384}),J(t,l,i.now)}catch{}}function p(t,e){return{value:t.slice(0,e),truncated:t.length>e}}function
|
|
4
|
-
export{
|
|
1
|
+
import{a,s,Y,m,je,u,Ve,b,F,f,j}from"./index-cxqk4wed.js";import{appendFileSync as re,mkdirSync as oe}from"node:fs";import{isAbsolute as ie,join as S}from"node:path";import{lstatSync as D,readdirSync as V,readFileSync as B,rmdirSync as K,statSync as C,unlinkSync as X,utimesSync as z,writeFileSync as Z}from"node:fs";import{join as g}from"node:path";function se(t,e={}){return Ve(u(t,e),t.home).policy.audit.retention_days}var A=86400000,Q=".last-prune",W=/^\d{4}-\d{2}$/,q=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,L=(t)=>Math.floor(t/A);function J(t,e,r=()=>new Date){try{let n=r().getTime();if(!C(e,{throwIfNoEntry:!1})?.isDirectory())return;let o=g(e,Q),c=C(o,{throwIfNoEntry:!1})?.mtimeMs;if(c!==void 0&&L(c)===L(n))return;let i=n-se(t)*A,d=new Date(n).toISOString().slice(0,7);for(let l of v(e)){if(l.isDirectory()){ee(g(e,l.name),i,d);continue}if(l.isFile()&&l.name.endsWith(".jsonl"))te(g(e,l.name),i)}Z(o,"",{mode:384}),z(o,n/1000,n/1000)}catch{}}function ee(t,e,r){for(let n of v(t)){if(!n.isDirectory()||!W.test(n.name))continue;let o=g(t,n.name);for(let c of v(o)){if(!c.isFile())continue;let i=q.exec(c.name);if(!i||i[2]!==n.name)continue;let d=Date.parse(`${i[1]}T00:00:00.000Z`)+A;if(!Number.isFinite(d)||d>=e)continue;G(g(o,c.name))}if(n.name!==r)O(o)}O(t)}function te(t,e){try{let r=D(t);if(r.mtimeMs>=e)return;let n=B(t,"utf-8").split(`
|
|
2
|
+
`).filter((o)=>o.trim()).map(ne);if(n.length===0)return;if(n.some((o)=>o===void 0||o>=e))return;if(D(t).mtimeMs!==r.mtimeMs)return;G(t)}catch{}}function ne(t){try{let e=JSON.parse(t).ts,r=typeof e==="string"?Date.parse(e):Number.NaN;return Number.isFinite(r)?r:void 0}catch{return}}function v(t){try{return V(t,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function G(t){try{X(t)}catch{}}function O(t){try{K(t)}catch{}}var ae="2.6.17",ce=1e4,de=2000,ue=256,le=32768;function me(t){let e=t.trim();if(!e)return null;let r=e.replace(/[^A-Za-z0-9_.-]+/g,"_");if(r=r.replace(/^[._-]+|[._-]+$/g,"").slice(0,128),!r||r==="."||r==="..")return null;return r}function fe(t){return(t??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function I(t,e,r,n,o,c,i={}){let d=me(e);if(!d)return;let l=U(t);if(!l)return;try{let y=(i.now??(()=>new Date))().toISOString(),_=p(Y(r),i.failureStage?Number.POSITIVE_INFINITY:ce),N=p(Y(n),de),h=i.toolName?p(Y(i.toolName),ue):void 0,E=c===null?void 0:p(Y(c),le),w=S(l,fe(E?.value??null),y.slice(0,7));oe(w,{recursive:!0,mode:448});let R=S(w,`${y.slice(0,10)}-${d}.jsonl`),P={ts:y,id:(i.createId??je)(),v:ae,sessionId:d,decision:i.decision??"deny",agent:i.agent,shape:i.shape,level:i.level,configFallback:i.configFallback,toolName:h?.value,command:_.value,segment:N.value,..._.truncated||N.truncated||h?.truncated||E?.truncated?{truncated:!0}:{},reason:o,ruleId:i.ruleId,intent:i.intent,failureStage:i.failureStage,errorCode:i.errorCode,cwd:E?.value??null};re(R,`${JSON.stringify(P)}
|
|
3
|
+
`,{encoding:"utf-8",mode:384}),J(t,l,i.now)}catch{}}function p(t,e){return{value:t.slice(0,e),truncated:t.length>e}}function rt(t){let e=t.env.get("CC_SAFETY_NET_AUDIT_HOME");if(t.env.get("NODE_ENV")==="test"&&!e)return null;let r=e||t.home;return r&&ie(r)?r:null}function U(t){let e=rt(t);return e?S(e,".cc-safety-net","logs"):null}function k(t,e,r,n=!0,o){if(e.decision.kind==="allow"){if(!r||t.route.kind!=="command")return;let d=T(t);return{decision:"allow",command:d,segment:d,reason:"allowed",cwd:t.context.executionCwd,toolName:t.toolName,level:e.level,...e.configFallback?{configFallback:!0}:{}}}let c=e.decision.evidence,i=c?.command??(n?T(t):"");return{decision:"deny",command:i,segment:c?.segment??i,reason:e.decision.reason,cwd:t.context.executionCwd,toolName:t.toolName,level:e.level,...e.configFallback?{configFallback:!0}:{},ruleId:e.decision.ruleId,intent:e.decision.intent,failureStage:o?.stage,errorCode:o?.errorCode}}function T(t){return"command"in t?t.command??"":""}function x(t,e,r,n){if(!e)return;let o;try{o=r()}catch{return}if(typeof o!=="string"||!o.trim())return;I(t,o,e.command,e.segment,e.reason,e.cwd,{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 Ae(t,e,r,n){let o;try{o=r()}catch{return}if(typeof o!=="string"||!o.trim())return;I(t,o,e.command??"",e.segment??e.command??"",e.reason,n.cwd??null,{decision:"deny",agent:n.agent,shape:n.shape,toolName:n.toolName??e.toolName,ruleId:e.ruleId,intent:e.intent})}function H(t,e,r){try{let n=j(e,{environment:t,...r.guard});return M(t,e,n,r),n}catch(n){if(!(n instanceof f))throw n;throw M(t,e,n.evaluation,r,!(n.cause instanceof m),{stage:n.stage,errorCode:ge(n.cause)}),n}}function M(t,e,r,n,o=!0,c){x(t,k(r.promotedInvocation??e,r,n.guard?.auditAllowed??!1,o,c),n.audit.getSessionId,{agent:n.audit.agent,shape:n.audit.shape})}function ge(t){if(t instanceof s)return a[t.kind].errorCode;if(t instanceof m)return"tool-input-limit";if(t instanceof b)return"structural-shell-syntax-limit";if(t instanceof F)return"unparseable-command";return"unexpected-error"}
|
|
4
|
+
export{se,J,rt,U,Ae,H};
|