Lines 1-17javascript
1var dr="https://hooks.ev-ai.ai";function le(e,t=dr){let n=t.replace(/\/+$/,""),r=e.trim();return`${n}/${r}/hook`}var Tt=".claude/ev-ai-runtime-report.json";var ue="ev-ai-agent-hook";var fi=`current/${ue}`,mi=`.ev-ai/agent-hook/${ue}`,At=5e3,kt=5e3,xe=3e3;var Ue=3e3,Ot=1500,xt=4*1024,Ut=32*1024,pr=4*1024,be="1.0.7",gi=`@ev-ai/agent-hook@${be}`;var bt=["claude","cursor","codex"];import{createHash as Bt,randomBytes as yr}from"node:crypto";import{existsSync as $t,mkdirSync as Gt,readFileSync as Kt,unlinkSync as jt,writeFileSync as Vt}from"node:fs";import{homedir as Me}from"node:os";import{dirname ...
2`)}function B(e,t){mr(vt(e),{recursive:!0});let n=Pt(vt(e),`.${Er(e)}.${process.pid}.${fr(4).toString("hex")}.tmp`);try{hr(n,t,"utf8");try{wt(n,e)}catch(r){let o=r instanceof Error&&"code"in r?r.code:void 0;if(o==="EEXIST"||o==="EPERM"||o==="EACCES"){Nt(e),wt(n,e);return}throw r}}catch(r){try{Nt(n)}catch{}throw r}}function de(){return new Date().toISOString().replace(/\.\d{3}Z$/,"Z")}function Dt(){process.stdout.write('{"continue":true}')}function E(e){let t=process.env[e];return t===void 0||t===""?void 0:t}async function Ne(){return new Promise(e=>{let t="";if(process.stdin.isTTY){e("");retur ...
3`)}catch(s){let i=s instanceof Error?s.message:String(s);m(`WARN: operator identity cache write failed open: ${i}`)}}function Zt(e,t=Date.now()){if(!e)return!0;if(K(e)?.operator_identity_hash)return!1;let n=Wt(e);try{if($t(n)){let r=Number.NaN;try{r=Number(Kt(n,"utf8").trim())}catch{}let o=t-r;if(Number.isFinite(o)&&o>=0&&o<Tr)return!1;try{jt(n)}catch{}}}catch{}try{return Gt(Le(n),{recursive:!0}),Vt(n,`${t}
HighChild Process
Package source references child process execution.
dist/hook.mjsView on unpkg · L1 HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
dist/hook.mjsView on unpkg · L1 HighCommand Output Exfiltration
Source combines command execution, command-output handling, and outbound requests; review data flow before blocking.
dist/hook.mjsView on unpkg · L1 4`,{encoding:"utf8",flag:"wx"}),!0}catch(r){if(tn(r))return!1;let o=r instanceof Error?r.message:String(r);return m(`WARN: cloud bootstrap claim failed open: ${o}`),!0}}function Qt(e){if(e)try{jt(Wt(e))}catch{}}function qt(e,t){let r=K(e)?.platform_agent_ids?.[t];return typeof r=="string"&&r.length>0?r:void 0}function en(e,t,n){if(!n)return;let r=K(e);if(!r||r.platform_agent_ids?.[t]===n)return;let o={installation_id:r.installation_id,platform_agent_ids:{...r.platform_agent_ids,[t]:n},...r.operator_identity_hash?{operator_identity_hash:r.operator_identity_hash}:{},...r.operator_identity_sent_at ...
5`)}catch(s){let i=s instanceof Error?s.message:String(s);m(`WARN: platform_agent_id cache write failed open: ${i}`)}}function tn(e){return e instanceof Error&&"code"in e&&e.code==="EEXIST"}function wr(e,t){Gt(Le(e),{recursive:!0}),Vt(e,`${JSON.stringify(t,null,2)}
6`,{encoding:"utf8",flag:"wx"})}function Ft(e,t){try{return wr(e,t),t}catch(n){if(!tn(n))throw n;return K(e)}}async function nn(e,t={}){let n=t.home??Me(),r=t.env??process.env,o=await xr(e),s=Ar(n),i=K(s);if(i)return{installationId:i.installation_id,storePath:s,repoKey:o};let a=Ht(t.overrideId,r),c=Ft(s,{installation_id:a});if(c)return{installationId:c.installation_id,storePath:s,repoKey:o};let l=Ht(void 0,r),u=Ft(s,{installation_id:l===a?Jt():l});if(u)return{installationId:u.installation_id,storePath:s,repoKey:o};throw new Error(`Failed to create installation record at ${s}`)}var Nr={claude:". ...
7`)}catch(n){let r=n instanceof Error?n.message:String(n);m(`WARN: cloud cache write failed open: ${r}`)}}function Zr(e,t,n){if(!e||e.context!==t)return!1;let r=e.result===null?Wr:zr;return n-e.probed_at<r}async function Qr(e){let t=await fetch("http://169.254.169.254/latest/api/token",{method:"PUT",headers:{"X-aws-ec2-metadata-token-ttl-seconds":"60"},signal:AbortSignal.timeout(e)}).catch(()=>{});if(!t?.ok)return;let n=(await t.text()).trim();if(!n)return;let r={"X-aws-ec2-metadata-token":n},[o,s]=await Promise.all([fetch("http://169.254.169.254/latest/meta-data/placement/region",{headers:r,si ...
8`);return I(n)}function co(e,t,n="git_config",r=null){return I(`${e??""}|${t??""}|${r??""}|${n}`)}function lo(e){let t=null,n=null;for(let r of e.split(`
9`)){let o=r.trim();if(!o)continue;let s=o.indexOf(" ");if(s<=0)continue;let i=o.slice(0,s).toLowerCase(),a=o.slice(s+1).trim();a&&(i==="user.name"?t=a:i==="user.email"&&(n=a))}return{git_user_name:t,git_user_email:n,platform_login:null}}async function uo(e,t=R){let n=await t("git",["config","--get-regexp","^user\\.(name|email)$"],2e3,{cwd:e});return lo(n)}function po(e=process.env){let t=_(e.GIT_AUTHOR_NAME),n=_(e.GIT_AUTHOR_EMAIL);if(t||n)return{git_user_name:t,git_user_email:n,platform_login:null,identity_source:"git_env"};let r=_(e.GIT_COMMITTER_NAME),o=_(e.GIT_COMMITTER_EMAIL);if(r||o)retu ...
10`)[0]??"").trim();return a||r(o+1)};return r(0)}function ts(e=An()){return w(e,".ev-ai","agent-hook",Zo)}function ns(e){let n=[...e].sort((r,o)=>r.name.localeCompare(o.name)).map(r=>`${r.name}:${r.size}`).join(`
11`);return I(n)}function Ee(e,t,n=!1){let r=ns(e),o=e.length;return t===r?n?{hash:r,count:o,truncated:n}:{hash:r,count:o}:n?{hash:r,count:o,entries:e,truncated:n}:{hash:r,count:o,entries:e}}function rs(e){return $o(e)?O(Go(e,"utf8"),{}):{}}function os(e,t){try{B(e,`${JSON.stringify(t)}
HighCloud Metadata Access
Source reaches cloud instance metadata or link-local credential endpoints.
dist/hook.mjsView on unpkg · L1 12`)}catch(n){let r=n instanceof Error?n.message:String(n);m(`WARN: self-config cache write failed open: ${r}`)}}function ss(e,t,n,r){let o={...e,send_count:n};for(let s of Object.keys(t)){let i=t[s];i.entries!==void 0&&(o[s]=i.hash)}return r&&(o.user_spec_collected_at_ms=r.collectedAtMs,r.included&&(o.user_spec=r.hash,o.user_spec_components=r.componentHashes),o.user_spec_text_hashes=r.textHashes),o}async function kn(e,t=process.cwd(),n=An(),r={}){let o=e==="claude",s=r.gitRoot??t,i=await es(e),a="",c=[];if(o){let b=Tn(w(n,".claude/settings.json")),M=Tn(w(t,".claude/settings.local.json"));a=M.mo ...
13${n}`}function Yn(e,t=[],n=process.execPath,r=import.meta.url,o=zn){if(Ns(n)===ue)return{command:n,args:[e,...t]};let s=vs(r);return o(s)?{command:n,args:[s,e,...t]}:{command:n,args:[e,...t]}}function Ps(e=process.execPath,t=import.meta.url,n=zn){return Yn(ht,[],e,t,n)}function Ds(e){let t=e.indexOf(`
14`);if(t<0)return null;let n;try{n=JSON.parse(e.slice(0,t))}catch{return null}return{meta:n,body:e.slice(t+1)}}async function Xn(e,t=fetch){let n=await e(),r=Ds(n);if(!r)return;let{meta:o,body:s}=r,i={"Content-Type":"application/json"};try{await t(o.url,{method:"POST",headers:i,body:s,signal:AbortSignal.timeout(Number(o.timeoutMs))})}catch{}}async function Hs(e,t,n){let r=Jn(e);m(`POST event=${e} url=${dt(n)} size=${t.length} platform=${process.platform}`);let o={"Content-Type":"application/json"},s=Date.now();try{let i=await fetch(n,{method:"POST",headers:o,body:t,signal:AbortSignal.timeout(r) ...
15`,c=E("EV_AI_HOOK_DEBUG");c==="full"?m(`DEBUG envelope=${JSON.stringify(i)}`):c==="1"&&m(`DEBUG summary=${Ms(i,Buffer.byteLength(a,"utf8"))}`);let l=process.argv.includes(Ce),u=E("EV_AI_HOOK_SYNC")==="1"
Long lines were clipped for display.