cc-safety-net 2.3.1 → 2.3.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/README.md +1 -1
- package/dist/amp/cc-safety-net/index.ts +2 -2
- package/dist/bin/cc-safety-net.js +105 -99
- package/dist/chunks/{index-2z9vsvqb.js → index-jnb1nckj.js} +1 -1
- package/dist/index.js +1 -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/pi/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ The skill is the operating manual for CC Safety Net. Ask it anything about the t
|
|
|
161
161
|
/cc-safety-net is secret protection active in Codex?
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
The command ships with the Claude Code
|
|
164
|
+
The command ships with the Claude Code and Codex plugins and is built into the OpenCode and Pi integrations. The skill loads only when you invoke it, so it takes no context-window space until you type the command. The agent cannot trigger it on its own.
|
|
165
165
|
|
|
166
166
|
## Library API
|
|
167
167
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// cc-safety-net managed Amp plugin. Do not edit. Reinstall with: npx -y cc-safety-net install --amp
|
|
2
|
-
// version: 2.3.
|
|
2
|
+
// version: 2.3.2
|
|
3
3
|
// @bun
|
|
4
4
|
var XE=Object.defineProperty;var QE=(e)=>e;function ew(e,t){this[e]=QE.bind(null,t)}var ln=(e,t)=>{for(var n in t)XE(e,n,{get:t[n],enumerable:!0,configurable:!0,set:ew.bind(t,n)})};import{randomBytes as Kw}from"crypto";import{appendFileSync as Yw,mkdirSync as Jw}from"fs";import{homedir as Xw,userInfo as Qw}from"os";import{isAbsolute as eR,join as Il}from"path";var tw=[/\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 Tt(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 nw(t)}function nw(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 tw)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 ey,readdirSync as Mw,readFileSync as oy,rmdirSync as $w,statSync as ty,unlinkSync as Lw,utimesSync as Ww,writeFileSync as Fw}from"fs";import{dirname as Gw,join as Hn}from"path";var Oi=30,Cl=1,El=365;function zi(e){if(typeof e!=="number"||!Number.isInteger(e))return 30;if(e<1)return 1;return e>365?365:e}import{homedir as Ew}from"os";import{dirname as Un,isAbsolute as ww,join as Bn,relative as Rw,resolve as fn,sep as Pw}from"path";import{lstatSync as rw,realpathSync as ow}from"fs";import{homedir as iw,tmpdir as sw}from"os";var Be={realpath:(e)=>{try{return ow(e)}catch{return null}},entryKind:(e)=>{let t=rw(e,{throwIfNoEntry:!1});if(!t)return"missing";return t.isSymbolicLink()?"symlink":"present"}};function ze(e,t=process.platform){if(t!=="win32")return e;return e.replace(/^\/([A-Za-z])(?:\/|$)/,"$1:/")}function un(){return ze(process.env.HOME||iw())}function Qe(){return{env:new Map(Object.entries(process.env).flatMap(([e,t])=>t===void 0?[]:[[e,t]])),home:un(),tmpdir:sw(),paths:Be}}import{closeSync as aw,constants as Mh,fstatSync as cw,fsyncSync as C1,lstatSync as $h,mkdirSync as E1,openSync as lw,readdirSync as w1,readFileSync as uw,realpathSync as Ni,renameSync as R1,rmdirSync as P1,statSync as dw,unlinkSync as A1,writeFileSync as k1}from"fs";import{isAbsolute as Lh,join as Wh,normalize as mw,parse as fw,relative as wl,resolve as Rl,sep as Pl}from"path";var pw=Symbol("PolicyFilesystemScope"),gw=Symbol("PolicyFilesystemTarget"),hw=Mh.O_NOFOLLOW??0;class pe extends Error{constructor(e){super(`Unable to access ${e} filesystem safely.`);this.name="PolicyFilesystemError"}}function dn(e,t){return{[pw]:!0,root:Rl(e),label:t}}function Fh(e,t){let n=mw(t);if(t===""||Lh(t)||n===".."||n.startsWith(`..${Pl}`))throw new pe(e.label);return{[gw]:!0,scope:e,relativePath:n,path:Wh(e.root,n)}}function Jr(e,t){let n=wl(e.root,Rl(t));return Fh(e,n)}function Gh(e,t="rules policy"){let n=Rl(e),r=fw(n).dir;return Fh(dn(r,t),wl(r,n))}function Mi(e){try{if(!Di(e,!1).exists)return null;let n=lw(e.path,Mh.O_RDONLY|hw);try{let r=cw(n);if(!r.isFile())throw new pe(e.scope.label);let o=uw(n,"utf-8"),i=$h(e.path);if(!i.isFile()||i.isSymbolicLink()||r.dev!==i.dev||r.ino!==i.ino)throw new pe(e.scope.label);return Di(e,!1),o}finally{aw(n)}}catch(t){vw(e.scope.label,t)}}function Zh(e,t){if(e.path===t.path)return!0;try{if(!Di(e,!1).exists||!Di(t,!1).exists)return!1;return Ni(e.path)===Ni(t.path)}catch(n){if(n instanceof pe)throw n;throw new pe(e.scope.label)}}function Di(e,t,n="file"){let r=yw(e.scope);if(!r)return{exists:!1};let o=e.relativePath.split(Pl);for(let i of o.keys()){let s=Wh(e.scope.root,...o.slice(0,i+1)),a=jh(s);if(!a){if(i===o.length-1&&t)return{exists:!1};return{exists:!1}}if(a.isSymbolicLink())throw new pe(e.scope.label);if(i<o.length-1&&!a.isDirectory())throw new pe(e.scope.label);if(i===o.length-1&&(n==="file"?!a.isFile():!a.isDirectory()))throw new pe(e.scope.label);bw(r,Ni(s),e.scope.label)}return{exists:!0}}function yw(e){if(!jh(e.root))return null;if(!dw(e.root).isDirectory())throw new pe(e.label);return Ni(e.root)}function bw(e,t,n){let r=wl(e,t);if(r===".."||r.startsWith(`..${Pl}`)||Lh(r))throw new pe(n)}function jh(e){try{return $h(e)}catch(t){if(_w(t)&&t.code==="ENOENT")return null;throw t}}function vw(e,t){if(t instanceof pe)throw t;throw new pe(e)}function _w(e){return e instanceof Error&&"code"in e}var mn=/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/,Uh="rulebook.json",Bh=".cc-safety-net/rules";var Vh=/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(.+)$/;var Sw=/^[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/,xw=".cc-safety-net/rules".replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Cw="rulebook.json".replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),O1=new RegExp(`^${xw}/(${mn.source.slice(1,-1)})/${Cw}$`);function Hh(e){return`.cc-safety-net/rules/${e}/rulebook.json`}function qh(e){if($i(e))try{return Al(e),null}catch(t){return t instanceof Error?t.message:String(t)}return mn.test(e)?null:`Local rulebook sources must be bare names matching ${mn}: ${e}`}function Al(e){if(e.startsWith("github:"))throw Error(`Invalid rulebook source: ${e}`);let t=e.match(Vh);if(!t?.[1]||!t[2]||!t[3])throw Error(`Invalid GitHub rulebook source: ${e}`);let n=t[3].lastIndexOf("/");if(n<1)throw Error(`GitHub rulebook sources must be owner/repo#ref/<rulebook-name>: ${e}`);let r=t[3].slice(0,n),o=t[3].slice(n+1);if(!r||!Sw.test(r))throw Error(`GitHub rulebook refs must use valid path segments: ${e}`);if(!o||!mn.test(o))throw Error(`GitHub rulebook sources must be owner/repo#ref/<rulebook-name>: ${e}`);return{owner:t[1],repo:t[2],ref:r,path:Hh(o),name:o}}function $i(e){return Vh.test(e)}var Kh="rule.json",pn="policy.json";var Yh=".cc-safety-net",Aw="rules",kw="CC_SAFETY_NET_HOME",Jh="`cc-safety-net rule update`";function Tw(e){return fn(e??process.cwd(),Bh)}function Iw(e){return Bn(Tw(e),Kh)}function Xr(e){return Bn(fn(e??process.cwd()),Yh,pn)}function Vn(e){return e?.userConfigDir??(e?.userConfigPath?Un(e.userConfigPath):Bn(Ow(),Aw))}function Ow(){let e=process.env[kw];return e?fn(ze(e)):Bn(Ew(),Yh)}function zw(e){return Bn(Vn(e),Kh)}function Xh(e){let t=e.userConfigPath??zw(e),n=e.projectConfigPath??Iw(e.cwd),r=Nw(t,e),o=Dw(n,e);return{userConfigPath:t,projectConfigPath:n,userScope:r,projectScope:o,userConfigTarget:Jr(r,t),projectConfigTarget:Jr(o,n)}}function Nw(e,t){let n=t.userConfigPath?Un(Un(fn(t.userConfigPath))):Un(fn(t.userConfigDir??Vn(t)));return dn(n,"user policy")}function Dw(e,t){let n=fn(t.cwd??process.cwd()),r=fn(e),o=Rw(n,r);if(o!==".."&&!o.startsWith(`..${Pw}`)&&!ww(o))return dn(n,"project policy");return dn(Un(Un(r)),"project policy")}function Qh(e,t){return Bn(e,t,Uh)}var Tl=86400000,Zw=".last-prune",jw=/^\d{4}-\d{2}$/,Uw=/^((\d{4}-\d{2})-\d{2})-.+\.jsonl$/,ny=(e)=>Math.floor(e/Tl);function Bw(e){try{let t=Hn(Gw(Vn(e)),pn),n=JSON.parse(oy(t,"utf-8"));return zi(n?.audit?.retention_days)}catch{return Oi}}function iy(e,t=()=>new Date){try{let n=t().getTime();if(!ty(e,{throwIfNoEntry:!1})?.isDirectory())return;let r=Hn(e,Zw),o=ty(r,{throwIfNoEntry:!1})?.mtimeMs;if(o!==void 0&&ny(o)===ny(n))return;let i=n-Bw()*Tl,s=new Date(n).toISOString().slice(0,7);for(let a of kl(e)){if(a.isDirectory()){Vw(Hn(e,a.name),i,s);continue}if(a.isFile()&&a.name.endsWith(".jsonl"))Hw(Hn(e,a.name),i)}Fw(r,"",{mode:384}),Ww(r,n/1000,n/1000)}catch{}}function Vw(e,t,n){for(let r of kl(e)){if(!r.isDirectory()||!jw.test(r.name))continue;let o=Hn(e,r.name);for(let i of kl(o)){if(!i.isFile())continue;let s=Uw.exec(i.name);if(!s||s[2]!==r.name)continue;let a=Date.parse(`${s[1]}T00:00:00.000Z`)+Tl;if(!Number.isFinite(a)||a>=t)continue;sy(Hn(o,i.name))}if(r.name!==n)ry(o)}ry(e)}function Hw(e,t){try{let n=ey(e);if(n.mtimeMs>=t)return;let r=oy(e,"utf-8").split(`
|
|
5
|
-
`).filter((o)=>o.trim()).map(qw);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(ey(e).mtimeMs!==n.mtimeMs)return;sy(e)}catch{}}function qw(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 kl(e){try{return Mw(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function sy(e){try{Lw(e)}catch{}}function ry(e){try{$w(e)}catch{}}var tR="2.3.
|
|
5
|
+
`).filter((o)=>o.trim()).map(qw);if(r.length===0)return;if(r.some((o)=>o===void 0||o>=t))return;if(ey(e).mtimeMs!==n.mtimeMs)return;sy(e)}catch{}}function qw(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 kl(e){try{return Mw(e,{withFileTypes:!0,encoding:"utf8"})}catch{return[]}}function sy(e){try{Lw(e)}catch{}}function ry(e){try{$w(e)}catch{}}var tR="2.3.2",nR=1e4,rR=2000,oR=256,iR=32768;function sR(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 aR(e){return(e??"").replace(/[^A-Za-z0-9]/g,"-").slice(0,180)||"no-cwd"}function Ol(e,t,n,r,o,i={}){let s=sR(e);if(!s)return;let a=i.homeDir??ay();if(!a)return;let c=cR(a);if(!c)return;try{let l=(i.now??(()=>new Date))().toISOString(),u=Li(Tt(t),i.failureStage?Number.POSITIVE_INFINITY:nR),d=Li(Tt(n),rR),m=i.toolName?Li(Tt(i.toolName),oR):void 0,f=o===null?void 0:Li(Tt(o),iR),p=Il(c,aR(f?.value??null),l.slice(0,7));Jw(p,{recursive:!0,mode:448});let h=Il(p,`${l.slice(0,10)}-${s}.jsonl`),y={ts:l,id:(i.createId??(()=>Kw(8).toString("hex")))(),v:tR,sessionId:s,decision:i.decision??"deny",agent:i.agent,shape:i.shape,level:i.level,configFallback:i.configFallback,toolName:m?.value,command:u.value,segment:d.value,...u.truncated||d.truncated||m?.truncated||f?.truncated?{truncated:!0}:{},reason:r,ruleId:i.ruleId,intent:i.intent,failureStage:i.failureStage,errorCode:i.errorCode,cwd:f?.value??null};Yw(h,`${JSON.stringify(y)}
|
|
6
6
|
`,{encoding:"utf-8",mode:384}),iy(c,i.now)}catch{}}function Li(e,t){return{value:e.slice(0,t),truncated:e.length>t}}function ay(e=process.env.CC_SAFETY_NET_AUDIT_HOME||process.env.HOME){let t=e||Xw()||Qw().homedir;return t&&eR(t)?t:null}function cR(e=ay()){return e?Il(e,".cc-safety-net","logs"):null}function ly(e,t,n,r=!0,o){if(t.decision.kind==="allow"){if(!n||e.route.kind!=="command")return;let a=cy(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?cy(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 cy(e){return"command"in e?e.command??"":""}function uy(e,t,n){if(!e)return;let r;try{r=t()}catch{return}if(typeof r!=="string"||!r.trim())return;Ol(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 dy(e,t,n){let r;try{r=t()}catch{return}if(typeof r!=="string"||!r.trim())return;Ol(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 sL,constants as aL,realpathSync as hR,statSync as yR}from"fs";import{isAbsolute as Nl,relative as bR,resolve as my,sep as vR}from"path";import{dirname as lR,isAbsolute as uR,parse as dR,sep as mR}from"path";function Zt(e,t=process.platform){if(t!=="win32")return!1;return(e[0]==="/"||e[0]==="\\")&&(e[1]==="/"||e[1]==="\\")}function jt(e,t,n){if(Zt(t))throw Error("Unsupported Windows namespace path");let r=uR(t)?pR(t):"",o=r||e;for(let i of gR(r?t.slice(r.length):t)){if(i===""||i===".")continue;if(i===".."){o=lR(o);continue}let s=fR(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 fR(e,t){return e.endsWith("/")||e.endsWith("\\")?`${e}${t}`:`${e}${mR}${t}`}function pR(e){return dR(e).root}function gR(e){let t=process.platform==="win32"?/[\\/]+/:/\/+/;return e.split(t)}function Dl(e,t){if(Zt(e))return;let n=t.flatMap((o)=>zl(o));if(!n[0])return;let r=zl(Nl(e)?e:my(n[0],e))[0];if(!r)return;return n.some((o)=>py(r,o))?r:void 0}function fy(e,t){if(Zt(e))return;return zl(Nl(e)?e:my(t,e))[0]}function zl(e){try{let t=hR(e);return yR(t).isDirectory()?[t]:[]}catch{return[]}}function py(e,t){let n=bR(t,e);return n===""||n!==".."&&!n.startsWith(`..${vR}`)&&!Nl(n)}var Ut="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.",gy="CC Safety Net could not validate the command because its structure exceeds safe analysis limits.",hy="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 by(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
|
|
7
7
|
|
|
8
8
|
Reason: ${s(t)}`;if(e.ruleId)a+=`
|