cc-safety-net 2.7.0 → 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.
- package/dist/amp/cc-safety-net/index.ts +49 -49
- package/dist/api.js +1 -1
- package/dist/bin/hook.js +49 -49
- package/dist/chunks/{index-tkzcnve3.js → index-09qa5y78.js} +1 -1
- package/dist/chunks/{index-b4k2tzcq.js → index-38xbyz1h.js} +2 -2
- package/dist/chunks/index-3xe319mt.js +53 -0
- package/dist/chunks/{index-sdtdk6k2.js → index-7rakvb2n.js} +1 -1
- package/dist/chunks/{index-d5x57kmb.js → index-bn4xwa1w.js} +2 -2
- package/dist/chunks/index-s5gfmv1q.js +2 -0
- package/dist/cli.js +49 -49
- package/dist/deepseek-harness/index.js +1 -1
- package/dist/index.js +4 -4
- package/dist/openclaw/cc-safety-net/index.js +49 -49
- 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 +1 -1
- package/package.json +5 -3
- package/dist/chunks/index-e31kf4tz.js +0 -53
- package/dist/chunks/index-fe2vhtvz.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ne,
|
|
1
|
+
import{ne,b,It,d}from"./index-3xe319mt.js";import{X,Ne,be,Le}from"./index-38xbyz1h.js";var ct=new Map([["bash","posix"],["powershell","powershell"]]),u={agent:"pi",debugLabel:"pi tool_call",extract:(o,e,t)=>C(o,e,t),getSessionId:(o,e)=>e.sessionManager.getSessionId(),allow:void 0,block:(o)=>p(o),includeEvidenceOnError:(o)=>o.route.kind==="command"};function kt(o){o.on("tool_call",s)}var s=m();function m(o={}){return Le(u,o)}function C(o,e,t){if(!o||typeof o!=="object")return;let l=o;if(l.type!==void 0&&l.type!=="tool_call")return;if(typeof l.toolName!=="string"||l.toolName.trim()==="")return a(e);if(typeof e.cwd!=="string"||e.cwd.trim()==="")return Ne(null,{toolName:l.toolName});let n=It(".",[e.cwd],t);if(!n)return be({directory:"session",problem:"unusable",cwd:e.cwd},{toolName:l.toolName});let i=ct.get(l.toolName);if(!l.input||typeof l.input!=="object")return i?a(e,l.toolName):void 0;if(!i)return d(l.toolName,l.input,{kind:b(l.toolName)},{configCwd:n,executionCwd:n},null);let r=l.input.command;if(typeof r!=="string"||r.trim()==="")return a(e,l.toolName);return d(l.toolName,l.input,{kind:"command",shell:i},{configCwd:n,executionCwd:n},r)}function a(o,e){return X(typeof o.cwd==="string"&&o.cwd.trim()?o.cwd:null,{toolName:e})}function p(o){return{block:!0,reason:ne(o)}}
|
|
2
2
|
export{ct,kt};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{l,a,ee,h,qe,p,et,E,H,g,G}from"./index-
|
|
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;T(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 U(t,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function T(t){try{B(t)}catch{}}function O(t){try{V(t)}catch{}}var ae="2.7.
|
|
1
|
+
import{l,a,ee,h,qe,p,et,E,H,g,G}from"./index-3xe319mt.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 U,readFileSync as j,rmdirSync as V,statSync as C,unlinkSync as B,utimesSync as K,writeFileSync as X}from"node:fs";import{join as s}from"node:path";function ue(t,e={}){return et(p(t,e),t.home).policy.audit.retention_days}var A=86400000,Y=".last-prune",Z=/^\d{4}-\d{2}$/,J=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,L=(t)=>Math.floor(t/A);function Q(t,e,r=()=>new Date){try{let n=r().getTime();if(!C(e,{throwIfNoEntry:!1})?.isDirectory())return;let o=s(e,Y),c=C(o,{throwIfNoEntry:!1})?.mtimeMs;if(c!==void 0&&L(c)===L(n))return;let i=n-ue(t)*A,d=new Date(n).toISOString().slice(0,7);for(let u of v(e)){if(u.isDirectory()){q(s(e,u.name),i,d);continue}if(u.isFile()&&u.name.endsWith(".jsonl"))te(s(e,u.name),i)}X(o,"",{mode:384}),K(o,n/1000,n/1000)}catch{}}function q(t,e,r){for(let n of v(t)){if(!n.isDirectory()||!Z.test(n.name))continue;let o=s(t,n.name);for(let c of v(o)){if(!c.isFile())continue;let i=J.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;T(s(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=j(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;T(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 U(t,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function T(t){try{B(t)}catch{}}function O(t){try{V(t)}catch{}}var ae="2.7.2",ce=1e4,de=2000,se=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 u=W(t);if(!u)return;try{let f=(i.now??(()=>new Date))().toISOString(),_=m(ee(r),i.failureStage?Number.POSITIVE_INFINITY:ce),N=m(ee(n),de),w=i.toolName?m(ee(i.toolName),se):void 0,y=c===null?void 0:m(ee(c),le),F=S(u,fe(y?.value??null),f.slice(0,7));oe(F,{recursive:!0,mode:448});let R=S(F,`${f.slice(0,10)}-${d}.jsonl`),P={ts:f,id:(i.createId??qe)(),v:ae,sessionId:d,decision:i.decision??"deny",agent:i.agent,shape:i.shape,level:i.level,configFallback:i.configFallback,toolName:w?.value,command:_.value,segment:N.value,..._.truncated||N.truncated||w?.truncated||y?.truncated?{truncated:!0}:{},reason:o,ruleId:i.ruleId,intent:i.intent,failureStage:i.failureStage,errorCode:i.errorCode,cwd:y?.value??null};re(R,`${JSON.stringify(P)}
|
|
3
3
|
`,{encoding:"utf-8",mode:384}),Q(t,u,i.now)}catch{}}function m(t,e){return{value:t.slice(0,e),truncated:t.length>e}}function ut(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 W(t){let e=ut(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=b(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?b(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 b(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 Me(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 z(t,e,r){try{let n=G(e,{environment:t,...r.guard});return M(t,e,n,r),n}catch(n){if(!(n instanceof g))throw n;throw M(t,e,n.evaluation,r,!(n.cause instanceof h),{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 a)return l[t.kind].errorCode;if(t instanceof h)return"tool-input-limit";if(t instanceof E)return"structural-shell-syntax-limit";if(t instanceof H)return"unparseable-command";return"unexpected-error"}
|
|
4
4
|
export{ue,Q,ut,W,Me,z};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ne,c,b,mt,d,w}from"./index-3xe319mt.js";import{X,Ne,be,Le}from"./index-38xbyz1h.js";import{existsSync as S,lstatSync as x,readFileSync as H}from"node:fs";import{join as C}from"node:path";function v(e,t=(s)=>s){if(!S(e))return{kind:"missing"};try{return{kind:"ok",value:JSON.parse(t(H(e,"utf-8")))}}catch{return{kind:"unreadable"}}}function B(e,t){if(e==="~")return t;if(e.startsWith("~/")||e.startsWith("~\\"))return C(t,e.slice(2));return e}function u(e){try{return x(e)}catch{return}}function We(e,t){let s=u(t);if(!s)return{platform:e,status:"n/a",configPath:t};if(!s.isSymbolicLink()&&s.isDirectory())return;return{platform:e,status:"n/a",configPath:t,errors:[`${t} is a symlink or not a directory; move or remove it before installing`]}}function n(e,t){return typeof e==="object"&&e!==null?e[t]:void 0}import{readdirSync as P}from"node:fs";import{join as k,resolve as T}from"node:path";var h="cc-safety-net";function De(e){let t=e.env.get("DSH_HOME");return k(t?.trim()?T(B(t,e.home)):k(e.home,".dsh"),"profiles")}function D(e){let t=De(e),s=u(t)?.isDirectory()?P(t,{withFileTypes:!0}).filter((o)=>o.isDirectory()&&o.name!=="node_modules").map((o)=>{let r=k(t,o.name,"package.json");return{name:o.name,configPath:r,manifest:v(r)}}):[];return{installed:s.flatMap((o)=>{if(o.manifest.kind!=="ok")return[];let r=o.manifest.value;if(n(n(r,"dependencies"),h)===void 0)return[];let i=n(n(n(r,"dsh"),"profile"),"bundles");return[{name:o.name,configPath:o.configPath,enabled:Array.isArray(i)&&i.includes(h)}]}),unreadable:s.some((o)=>o.manifest.kind==="unreadable")}}function lt(e){return D(e).installed}function Rt(e){let t=D(e.environment),s=t.installed.filter((r)=>r.enabled),a=t.installed.filter((r)=>!r.enabled),o=a.map((r)=>`${h} is installed in the ${r.name} profile but its bundle is disabled`);if(s.length>0)return{platform:"deepseek-harness",status:"configured",method:"dsh bundle",configPaths:s.map((r)=>r.configPath),...o.length>0?{errors:o}:{}};if(a.length>0)return{platform:"deepseek-harness",status:"disabled",method:"dsh bundle",configPaths:a.map((r)=>r.configPath),errors:o};return t.unreadable?{platform:"deepseek-harness",status:"not-inspected"}:{platform:"deepseek-harness",status:"n/a"}}import{randomUUID as E}from"node:crypto";import{resolve as O}from"node:path";var ze=new Map([["bash","posix"],["pwsh","powershell"]]),j={agent:"deepseek-harness",debugLabel:"deepseek-harness tool guard",extract:(e,t,s)=>_(e,t,s),getSessionId:(e)=>e?.agent?.session.header.id,allow:void 0,block:(e)=>ne(e),includeEvidenceOnError:(e)=>e.route.kind==="command"};function Tt(e){let t=I();e.tools.guard((a)=>t(a,process.cwd()));let s=new Set;e.on("tools/post-execute",async(a,o,r)=>{let i=await r(),l=A(a,s);if(!l)return i;return{...i,additionalContexts:[l,...i.additionalContexts??[]]}})}function A(e,t){try{let s=e,a=s?.agent?.session.header,o=s?.name,i=s?.arguments?.command;if(!a||typeof o!=="string"||ze.has(o)||b(o)!=="unknown"||typeof i!=="string"||i.trim()==="")return;let l=JSON.stringify([a.id,o]);if(t.has(l))return;let p=c();if(w(p,{cwd:a.cwd??process.cwd()}).policy.commandTools.some((m)=>m.name===o))return;t.add(l);let f=De(p);return Object.freeze({id:E(),role:"user",content:Object.freeze([Object.freeze({type:"text",text:`CC Safety Net did not check the command \`${o}\` just ran. It checks a plugin's shell tool only after the tool is declared. First find out where \`${o}\` runs its commands: check its tool description, and if that doesn't say, read its plugin's source under \`${f}/<profile>/node_modules\`. If it runs them on this machine, declare it with \`npx -y cc-safety-net rule tool add ${o}\`. Add \`--cwd-arg <name>\` if it takes its working directory in an argument other than \`workdir\`, \`cwd\` or \`working_directory\`. Don't test the declaration by running a destructive command; \`npx -y cc-safety-net rule tool list\` confirms it. If it runs them somewhere else, such as a remote host, or you can't tell, don't declare it. Either way, tell the user what you found and what you did.`})]),source:Object.freeze({kind:"cc-safety-net",form:"notice",summary:`${o} commands are not checked`})})}catch{return}}function I(e={}){return Le(j,e)}function _(e,t,s){if(!e||typeof e!=="object")return Ne(null);let a=e,o=a.agent?.session.header.cwd??t,r=mt([o],s),i=a.name;if(typeof i!=="string"||i.trim()==="")return X(r??null);if(!r)return be({directory:"session",problem:"unusable",cwd:o},{toolName:i});let l=a.arguments,p=ze.get(i);if(!p)return d(i,l,{kind:b(i)},{configCwd:r,executionCwd:r},null);if(!l||typeof l!=="object"||Array.isArray(l))return X(r,{toolName:i});let g=l,f=g.command;if(typeof f!=="string"||f.trim()==="")return X(r,{toolName:i});let m=g.workdir;if(m!==void 0&&(typeof m!=="string"||m.trim()===""))return X(r,{command:f,toolName:i});let y=m===void 0?r:mt([O(r,m)],s);if(!y)return be({directory:"requested",problem:"unusable",cwd:m},{command:f,toolName:i});return d(i,l,{kind:"command",shell:p},{configCwd:r,executionCwd:y},f)}
|
|
2
|
+
export{v,B,u,We,n,De,lt,Rt,ze,Tt};
|