cc-safety-net 2.7.4 → 2.7.5

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.
@@ -0,0 +1,2 @@
1
+ import{re,c,S,bt,d,w}from"./index-dm4v8s9a.js";import{Q,Ne,ve,Le}from"./index-a1hayde0.js";import{existsSync as x,lstatSync as H,readFileSync as C}from"node:fs";import{join as P}from"node:path";function b(e,t=(s)=>s){if(!x(e))return{kind:"missing"};try{return{kind:"ok",value:JSON.parse(t(C(e,"utf-8")))}}catch{return{kind:"unreadable"}}}function B(e,t){if(e==="~")return t;if(e.startsWith("~/")||e.startsWith("~\\"))return P(t,e.slice(2));return e}function u(e){try{return H(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 T}from"node:fs";import{join as k,resolve as E}from"node:path";var h="cc-safety-net";function De(e){let t=e.env.get("DSH_HOME");return k(t?.trim()?E(B(t,e.home)):k(e.home,".dsh"),"profiles")}function D(e){let t=De(e),s=u(t)?.isDirectory()?T(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:b(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 v}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)=>A(e,t,s),getSessionId:(e)=>e?.agent?.session.header.id,allow:void 0,block:(e)=>re(e),includeEvidenceOnError:(e)=>e.route.kind==="command"};function Tt(e){let t=_();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=I(a,s);if(!l)return i;return{...i,additionalContexts:[l,...i.additionalContexts??[]]}})}function I(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)||S(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:v(),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}\`, and add \`--cwd-arg <name>\` if it takes its working directory in an argument other than \`workdir\`, \`cwd\` or \`working_directory\`. If it runs them somewhere else, such as a remote host, or you can't tell, declare it with \`npx -y cc-safety-net rule tool add ${o} --no-cwd-arg\`: its commands are then checked as if they ran in this session's directory. Don't test the declaration by running a destructive command; \`npx -y cc-safety-net rule tool list\` confirms 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 _(e={}){return Le(j,e)}function A(e,t,s){if(!e||typeof e!=="object")return Ne(null);let a=e,o=a.agent?.session.header.cwd??t,r=bt([o],s),i=a.name;if(typeof i!=="string"||i.trim()==="")return Q(r??null);if(!r)return ve({directory:"session",problem:"unusable",cwd:o},{toolName:i});let l=a.arguments,p=ze.get(i);if(!p)return d(i,l,{kind:S(i)},{configCwd:r,executionCwd:r},null);if(!l||typeof l!=="object"||Array.isArray(l))return Q(r,{toolName:i});let g=l,f=g.command;if(typeof f!=="string"||f.trim()==="")return Q(r,{toolName:i});let m=g.workdir;if(m!==void 0&&(typeof m!=="string"||m.trim()===""))return Q(r,{command:f,toolName:i});let y=m===void 0?r:bt([O(r,m)],s);if(!y)return ve({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{b,B,u,We,n,De,lt,Rt,ze,Tt};
@@ -0,0 +1,2 @@
1
+ import{Fe,ne,q,I,re,c,$e,Lt,h,S,ye,Pe,d,g}from"./index-dm4v8s9a.js";import{le}from"./index-e4b0v62z.js";import{Me,z}from"./index-r6tk9ysc.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(e={}){return async({directory:o,homeDir:a})=>{let n=w(o),r;return{config:async(t)=>{r=t;let s=Be(),u=t.command??{};t.command={...s,...u}},"tool.execute.before":async(t,s)=>{st({configCwd:n,homeDir:a,tool:t.tool,sessionID:t.sessionID,toolInput:s.args,route:k(t.tool,at(r?.shell)),guardDependencies:e})}}}}function st({configCwd:e,homeDir:o,expandHomeWorkdir:a=!1,tool:n,sessionID:r,toolInput:t,route:s,guardDependencies:u={}}){let l=o===void 0?c():{...c(),home:o},m=(i,E,T=e)=>{Me(l,i,()=>r,{agent:"opencode",toolName:E,cwd:T}),y(i)};if(typeof n!=="string"||n.trim()==="")m(q());let p;try{p=ye(t)}catch(i){if(!(i instanceof h))throw i;m(ne({toolName:n}),n)}if(!Pe(e)){m(I({directory:"session",problem:"unusable",cwd:e},{command:p,toolName:n}),n);return}let f=P(e,t,a?l.home:void 0,()=>s.kind==="unknown"&&Lt(l,e,n));if(f===null){m(q({command:p,toolName:n}),n);return}if(typeof f!=="string"){m(I(f,{command:p,toolName:n}),n,f.cwd);return}let D=d(n,t,s,{configCwd:e,executionCwd:f},p??null);try{let i=z(l,D,{guard:{auditAllowed:$e(l.env),dependencies:u},audit:{agent:"opencode",getSessionId:()=>r}});C(i)}catch(i){if(!(i instanceof g))throw i;if(i.stage==="policy-protection"||i.stage==="config-load"||i.stage==="secret-protection")throw i.cause;C(i.evaluation);return}}function at(e,o=process.platform,a=process.env.SHELL){let r=(typeof e==="string"?e:a)?.trim().split(/[\\/]/).at(-1)?.toLowerCase().replace(/\.exe$/,"");if(typeof e!=="string"&&o==="win32"&&(!r||O.has(r)))return"powershell";if(!r)return"auto";if(x.has(r))return"powershell";return r==="cmd"?"auto":"posix"}function k(e,o){if(e===it)return{kind:"command",shell:o};return{kind:S(e)}}function P(e,o,a,n){if(!o||typeof o!=="object"||Array.isArray(o))return e;if(!Object.hasOwn(o,"workdir")||n())return e;let r=o.workdir;if(typeof r!=="string"||r.trim()==="")return null;let t=process.platform==="win32"?A(r):r,s=t.startsWith("~/")||process.platform==="win32"&&t.startsWith("~\\"),u=a===void 0?t:t==="~"?a:s?v(a,t.slice(2)):t,l=w(e,u);return Pe(l)?l:{directory:"requested",problem:"unusable",cwd:r}}function A(e){return e.replace(/^\/([a-zA-Z]):(?:[\\/]|$)/,(a,n)=>`${n.toUpperCase()}:/`).replace(/^\/([a-zA-Z])(?:[\\/]|$)/,(a,n)=>`${n.toUpperCase()}:/`).replace(/^\/cygdrive\/([a-zA-Z])(?:[\\/]|$)/,(a,n)=>`${n.toUpperCase()}:/`).replace(/^\/mnt\/([a-zA-Z])(?:[\\/]|$)/,(a,n)=>`${n.toUpperCase()}:/`)}function C(e){let o=Fe(e,{includeEvidence:!0});if(o)y(o)}function y(e){throw Error(re(e))}
2
+ export{Be,it,Oe,Et,st,at};
@@ -1,2 +1,2 @@
1
- import{ne,b,It,d}from"./index-k92nxp12.js";import{X,Ne,be,Le}from"./index-gyftnsm3.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)}}
1
+ import{re,S,Mt,d}from"./index-dm4v8s9a.js";import{Q,Ne,ve,Le}from"./index-a1hayde0.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=Mt(".",[e.cwd],t);if(!n)return ve({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:S(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 Q(typeof o.cwd==="string"&&o.cwd.trim()?o.cwd:null,{toolName:e})}function p(o){return{block:!0,reason:re(o)}}
2
2
  export{ct,kt};
@@ -0,0 +1,4 @@
1
+ import{l,a,te,Ve,p,h,et,E,H,g,G}from"./index-dm4v8s9a.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 ee(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"))q(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 q(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.5",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(te(r),i.failureStage?Number.POSITIVE_INFINITY:ce),N=m(te(n),de),w=i.toolName?m(te(i.toolName),se):void 0,y=c===null?void 0:m(te(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??Ve)(),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
+ `,{encoding:"utf-8",mode:384}),ee(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
+ export{ue,ee,ut,W,Me,z};