@ev-ai/agent-hook 1.2.4 → 1.2.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.
- package/dist/cli.mjs +36 -36
- package/dist/hook.mjs +32 -32
- package/dist/managed-hooks-snippet.cjs +1 -1
- package/dist/managed-hooks-snippet.mjs +1 -1
- package/dist/plugin-hooks.mjs +1 -1
- package/package.json +1 -1
package/dist/hook.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from 'node:module';
|
|
2
2
|
const require = __createRequire(import.meta.url);
|
|
3
3
|
|
|
4
|
-
var mc=Object.create;var Jr=Object.defineProperty;var gc=Object.getOwnPropertyDescriptor;var _c=Object.getOwnPropertyNames;var hc=Object.getPrototypeOf,Sc=Object.prototype.hasOwnProperty;var sn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var he=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ec=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _c(t))!Sc.call(e,o)&&o!==n&&Jr(e,o,{get:()=>t[o],enumerable:!(r=gc(t,o))||r.enumerable});return e};var je=(e,t,n)=>(n=e!=null?mc(hc(e)):{},Ec(t||!e||!e.__esModule?Jr(n,"default",{value:e,enumerable:!0}):n,e));var Ot=he(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.MCP_MISSING_LAUNCH_SERIALIZED=M.MCP_LAUNCH_IDENTITY_ALGORITHM=void 0;M.foldMcpName=os;M.buildMcpFamilyCanonicalKey=Xu;M.launchContainsCredentials=qu;M.serializeMcpLaunchIdentity=ss;M.hashMcpLaunchIdentity=Ye;M.projectMcpMissingLaunchIdentity=tl;M.projectMcpLaunchIdentity=nl;M.maskMcpLaunchForDisplay=ol;M.normalizeMcpToolNames=sl;var Ju=sn("node:crypto");M.MCP_LAUNCH_IDENTITY_ALGORITHM="mcp-launch-v1";M.MCP_MISSING_LAUNCH_SERIALIZED=`${M.MCP_LAUNCH_IDENTITY_ALGORITHM}|missing`;function se(e){return e.toLocaleLowerCase("en-US")}function os(e){return se(e)}function Xu(e){return`interface:${os(e)}`}var rs=new Set(["access_token","api_key","apikey","auth","authorization","key","password","secret","token"]),Zu=/^(?:--?(?:token|api[-_]?key|password|secret|authorization)(?:=|\s+)|(?:sk-|ghp_|xox[baprs]-|Bearer\s+))/i;function be(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function qu(e){return e.kind==="url"?Qu(e.url):e.kind==="command"?e.arguments.some(t=>Zu.test(t)):!1}function Qu(e){try{let t=new URL(e);if(t.username.length>0||t.password.length>0)return!0;for(let n of t.searchParams.keys())if(rs.has(se(n)))return!0;return!1}catch{let t=e.split("://",2),n=t.length===2?t[1]:e,r=n.indexOf("@"),o=n.indexOf("/");if(r>0&&(o===-1||r<o))return!0;let s=e.split("?",2)[1];return s===void 0?!1:s.split("&").some(i=>{let a=se(i.split("=",1)[0]??"");return rs.has(a)})}}function ss(e){if(e.kind==="url")return[M.MCP_LAUNCH_IDENTITY_ALGORITHM,"url",be(se(e.url))].join("|");if(e.kind==="command"){let t=[...e.arguments].map(n=>se(n)).sort((n,r)=>n<r?-1:n>r?1:0);return[M.MCP_LAUNCH_IDENTITY_ALGORITHM,"command",be(se(e.command)),String(t.length),...t.map(be)].join("|")}return[M.MCP_LAUNCH_IDENTITY_ALGORITHM,"unknown",be(e.installationRootExternalKey),be(e.sourcePath),be(e.nativeKey)].join("|")}function Ye(e){return(0,Ju.createHash)("sha256").update(e).digest("hex")}var el=Ye(M.MCP_MISSING_LAUNCH_SERIALIZED);function tl(){return{kind:"unknown",arguments:[],serialized:M.MCP_MISSING_LAUNCH_SERIALIZED,contentHash:el}}function nl(e){let t=ss(e);return e.kind==="url"?{kind:"url",url:se(e.url),arguments:[],serialized:t,contentHash:Ye(t)}:e.kind==="command"?{kind:"command",command:se(e.command),arguments:[...e.arguments].map(n=>se(n)).sort((n,r)=>n<r?-1:n>r?1:0),serialized:t,contentHash:Ye(t)}:{kind:"unknown",arguments:[],serialized:t,contentHash:Ye(t)}}var rl=/^(https?:\/\/)([^/?#]*@)/i;function ol(e){return e.replace(rl,"$1***@").replace(/([?&](?:access_token|api_key|apikey|auth|authorization|key|password|secret|token)=)([^&]*)/gi,"$1***")}function sl(e){let t=new Set,n=[];for(let r of e)r.length===0||t.has(r)||(t.add(r),n.push(r));return n.sort((r,o)=>r<o?-1:r>o?1:0),n}});var Tt=he(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.PACKAGE_FIELD_MAX=void 0;te.npxExecBin=is;te.packageNameFromSpec=Pt;te.pinnedPackageVersionFromSpec=as;te.pinnedPackageVersionFromNpx=ml;te.npxPackageSpecs=cs;te.PACKAGE_FIELD_MAX=128;var il=/^(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*\/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*$/,al=new Set(["-p","--package"]),cl=new Set(["-c","--call"]),ul=new Set(["--registry","--userconfig","--globalconfig","--prefix","--cache","--node-options","--workspace","-w","--loglevel"]),ll=new Set(["-y","--yes","-n","--no","-q","-s","--quiet","--silent","--offline","--prefer-offline","--prefer-online","--ignore-existing","--ignore-scripts","--legacy-peer-deps","--foreground-scripts"]),dl=/^--no-/;function pl(e){return ll.has(e)||dl.test(e)}function is(e){let n=(e.replace(/\\/g,"/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="npx"?"npx":n==="npm"?"npm":null}var fl=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;function Pt(e){if(e.length===0||e.length>te.PACKAGE_FIELD_MAX)return null;let t=e.lastIndexOf("@"),n=t>0?e.slice(0,t):e;return il.test(n)?n:null}function as(e){let t=Pt(e);if(t===null||!e.startsWith(`${t}@`))return;let n=e.slice(t.length+1);return fl.test(n)?n:void 0}function ml(e,t){for(let n of cs(e,t)){let r=as(n);if(r!==void 0)return r}}function cs(e,t){let n=is(e);if(n===null)return[];let r=[...t];if(n==="npm"){let i=r[0]?.toLowerCase();if(i!=="exec"&&i!=="x")return[];r=r.slice(1)}let o=[],s=null;for(let i=0;i<r.length;i+=1){let a=r[i]??"";if(a==="--"){s=r[i+1]??null;break}if(!a.startsWith("-")){s=a;break}let c=a.indexOf("="),u=c===-1?a:a.slice(0,c);if(cl.has(u))return[];if(al.has(u)){let l=c===-1?r[i+1]:a.slice(c+1);l!==void 0&&l.length>0&&o.push(l),c===-1&&(i+=1);continue}if(!(c!==-1||pl(u))){if(ul.has(u)){i+=1;continue}return[]}}return o.length>0?o.every(i=>Pt(i)!==null)?o:[]:s===null||Pt(s)===null?[]:[s]}});var us=he(Re=>{"use strict";Object.defineProperty(Re,"__esModule",{value:!0});Re.McpPackageEcosystem=void 0;Re.resolveMcpPackageIdentity=Tl;var gl=Ot(),Un=Tt();Re.McpPackageEcosystem={NPM:"npm",PYPI:"pypi"};var _l=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/,hl=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/,Sl=/^(?:\d+!)?\d+(?:\.\d+)*(?:(?:a|b|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?(?:\+[0-9A-Za-z]+(?:[.][0-9A-Za-z]+)*)?$/;function El(e){let n=(e.replaceAll("\\","/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="uvx"||n==="uv"||n==="pipx"?n:null}var yl=new Set(["--from","--spec"]),Rl=new Set(["--python","-p","--with","--with-editable","--with-requirements","--index","--index-url","--default-index","--extra-index-url","--find-links","-f","--constraint","-c","--override","--refresh-package","--cache-dir","--directory","--project","--config-file","--color","--exclude-newer","--pip-args","--verbose-pip"]),Cl=new Set(["-q","--quiet","-v","--verbose","-n","--native-tls","--offline","--isolated","--preview","--refresh","--reinstall","--upgrade","-U","--force","--system","--system-site-packages","--path","--managed-python","--progress"]),Il=/^--no-/;function Al(e,t){let n=El(e);if(n===null)return null;let r=[...t];if(n==="uv"){if(r[0]?.toLowerCase()!=="tool"||r[1]?.toLowerCase()!=="run")return null;r=r.slice(2)}else if(n==="pipx"){if(r[0]?.toLowerCase()!=="run")return null;r=r.slice(1)}let o=null,s=null;for(let i=0;i<r.length;i+=1){let a=r[i]??"";if(a==="--"){s=r[i+1]??null;break}if(!a.startsWith("-")){s=a;break}let c=a.indexOf("="),u=c===-1?a:a.slice(0,c);if(yl.has(u)){let l=c===-1?r[i+1]:a.slice(c+1);l!==void 0&&l.length>0&&(o=l),c===-1&&(i+=1);continue}if(!(c!==-1||Cl.has(u)||Il.test(u))){if(Rl.has(u)){i+=1;continue}return null}}return o??s}function Ol(e){if(e.length===0||e.length>Un.PACKAGE_FIELD_MAX)return null;let t=e.includes("==")?"==":e.includes("@")?"@":null;if(t===null)return null;let n=e.indexOf(t),r=e.slice(0,n),o=e.slice(n+t.length);return!hl.test(r)||!Sl.test(o)?null:{ecosystem:Re.McpPackageEcosystem.PYPI,packageName:r,version:o}}function Pl(e){let t=(0,Un.packageNameFromSpec)(e);if(t===null||!e.startsWith(`${t}@`))return null;let n=e.slice(t.length+1);return _l.test(n)?{ecosystem:Re.McpPackageEcosystem.NPM,packageName:t,version:n}:null}function Tl(e){if(e?.kind!=="command"||(0,gl.launchContainsCredentials)(e))return;for(let n of(0,Un.npxPackageSpecs)(e.command,e.arguments)){let r=Pl(n);if(r!==null)return r}let t=Al(e.command,e.arguments);if(t!==null)return Ol(t)??void 0}});var gs=he(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.EMPTY_NPM_PUBLISHER=void 0;ie.isNpmRegistryPublisher=xl;ie.displayPublisherName=bl;ie.classifyMcpProvenance=Hl;var ps=Ot(),Dn=Tt();ie.EMPTY_NPM_PUBLISHER="npm:";var ls="npm:",kl=/^[A-Za-z0-9._-]+$/;function xl(e){return e.startsWith(ls)&&e!==ie.EMPTY_NPM_PUBLISHER&&kl.test(e.slice(ls.length))}function bl(e){if(!(e==null||e===""||e===ie.EMPTY_NPM_PUBLISHER))return e}function ds(e){let t=e.split(".").map(Number);return t.length!==4||t.some(n=>!Number.isInteger(n)||n<0||n>255)?!1:t[0]===0||t[0]===10||t[0]===127||t[0]===169&&t[1]===254||t[0]===172&&(t[1]??0)>=16&&(t[1]??0)<=31||t[0]===192&&t[1]===168}function Nl(e){let t=/^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i.exec(e);if(t?.[1])return t[1];let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(e);if(!n)return;let r=Number.parseInt(n[1],16),o=Number.parseInt(n[2],16);return`${r>>8&255}.${r&255}.${o>>8&255}.${o&255}`}function Fn(e){return e.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"")}function Ml(e){let t=Fn(e),n=Nl(t);return t==="localhost"||t.endsWith(".localhost")||t==="::1"||t.endsWith(".local")||!t.includes(".")&&!t.includes(":")||ds(t)||n!==void 0&&ds(n)||/^(?:fc|fd)[0-9a-f]{2}:/i.test(t)||/^fe[89ab][0-9a-f]:/i.test(t)}function wl(e){let t=Fn(e);return t.includes(":")||/^[0-9.]+$/.test(t)||t.split(".").filter(Boolean).length<2?null:t}function vl(e){let t=Fn(e.hostname),n=t.includes(":")?`[${t}]`:t,r=e.port?`:${e.port}`:"";return`${e.protocol}//${n}${r}`}function fs(e){let t={kind:"url",url:e};if((0,ps.launchContainsCredentials)(t))return{origin:"UNKNOWN"};try{let n=new URL(e);if(!["http:","https:"].includes(n.protocol)||Ml(n.hostname))return{origin:"UNKNOWN"};let r=wl(n.hostname);return{origin:"THIRD_PARTY",...r===null?{}:{publisherName:r},packageSourceUrl:vl(n)}}catch{return{origin:"UNKNOWN"}}}var ms="mcp-remote";function Ll(e,t){if(e===ms)return t.find(n=>/^https?:\/\//i.test(n))}function Ul(e,t){return{origin:"THIRD_PARTY",...t?{publisherName:t}:{},packageName:e,packageKey:e}}function Dl(e,t,n){let r=Ll(e,t);return r!==void 0?fs(r):e===ms?{origin:"UNKNOWN"}:Ul(e,n)}function Fl(e){let t=e.replaceAll("\\","/");return t.startsWith("~/")||t.startsWith("/")||/^[A-Za-z]:\//.test(t)?!1:t.startsWith("./")||t.startsWith("../")||t==="scripts"||t.startsWith("scripts/")}function Hl(e){let t=e.launch;if(t===void 0||t.kind==="unknown")return{origin:"UNKNOWN"};if((0,ps.launchContainsCredentials)(t))return{origin:"UNKNOWN"};if(t.kind==="url")return fs(t.url);let r=(0,Dn.npxPackageSpecs)(t.command,t.arguments)[0];if(r!==void 0){let o=(0,Dn.packageNameFromSpec)(r);if(o===null)return{origin:"UNKNOWN"};let s=Dl(o,t.arguments,e.publisherName),i=typeof e.packageName=="string"?(0,Dn.packageNameFromSpec)(e.packageName):null;return i!==null&&i===o&&s.packageName!==void 0?{...s,packageName:i,packageKey:i}:s}return Fl(t.command)?{origin:"INTERNAL"}:{origin:"UNKNOWN"}}});var _s=he(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.parseFrontmatterField=X.parseFrontmatterDescription=X.usableCatalogText=void 0;var jl=/^(?:>|\|)[-+]?$/,$l=/^(?:>|\|)[-+]?(?:\s+(.*))?$/,Kl=e=>{let t=e?.trim()??"";if(!(t.length===0||jl.test(t)))return t};X.usableCatalogText=Kl;var Bl=e=>(0,X.parseFrontmatterField)(e,"description");X.parseFrontmatterDescription=Bl;var Gl=(e,t)=>{let n=/^---\s*\n([\s\S]*?)\n---/.exec(e);if(n)return Vl(n[1],t)};X.parseFrontmatterField=Gl;var zl=e=>e.replace(/^["']|["']$/g,"");function Vl(e,t){let n=e.split(`
|
|
5
|
-
`),r=`${t}:`,o=n.findIndex(d=>d===r||d.startsWith(`${r} `)||d.startsWith(`${r} `));if(o<0)return;let s=(n[o]??"").slice(r.length).trim(),i
|
|
4
|
+
var Ac=Object.create;var Xr=Object.defineProperty;var Oc=Object.getOwnPropertyDescriptor;var Pc=Object.getOwnPropertyNames;var Tc=Object.getPrototypeOf,kc=Object.prototype.hasOwnProperty;var an=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var _e=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xc=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pc(t))!kc.call(e,o)&&o!==n&&Xr(e,o,{get:()=>t[o],enumerable:!(r=Oc(t,o))||r.enumerable});return e};var Ke=(e,t,n)=>(n=e!=null?Ac(Tc(e)):{},xc(t||!e||!e.__esModule?Xr(n,"default",{value:e,enumerable:!0}):n,e));var xt=_e(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.MCP_MISSING_LAUNCH_SERIALIZED=N.MCP_LAUNCH_IDENTITY_ALGORITHM=void 0;N.foldMcpName=ms;N.buildMcpFamilyCanonicalKey=gl;N.launchContainsCredentials=hl;N.serializeMcpLaunchIdentity=gs;N.hashMcpLaunchIdentity=Je;N.projectMcpMissingLaunchIdentity=yl;N.projectMcpLaunchIdentity=Rl;N.maskMcpLaunchForDisplay=Il;N.normalizeMcpToolNames=Al;var ml=an("node:crypto");N.MCP_LAUNCH_IDENTITY_ALGORITHM="mcp-launch-v1";N.MCP_MISSING_LAUNCH_SERIALIZED=`${N.MCP_LAUNCH_IDENTITY_ALGORITHM}|missing`;function re(e){return e.toLocaleLowerCase("en-US")}function ms(e){return re(e)}function gl(e){return`interface:${ms(e)}`}var fs=new Set(["access_token","api_key","apikey","auth","authorization","key","password","secret","token"]),_l=/^(?:--?(?:token|api[-_]?key|password|secret|authorization)(?:=|\s+)|(?:sk-|ghp_|xox[baprs]-|Bearer\s+))/i;function Ne(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function hl(e){return e.kind==="url"?Sl(e.url):e.kind==="command"?e.arguments.some(t=>_l.test(t)):!1}function Sl(e){try{let t=new URL(e);if(t.username.length>0||t.password.length>0)return!0;for(let n of t.searchParams.keys())if(fs.has(re(n)))return!0;return!1}catch{let t=e.split("://",2),n=t.length===2?t[1]:e,r=n.indexOf("@"),o=n.indexOf("/");if(r>0&&(o===-1||r<o))return!0;let s=e.split("?",2)[1];return s===void 0?!1:s.split("&").some(i=>{let a=re(i.split("=",1)[0]??"");return fs.has(a)})}}function gs(e){if(e.kind==="url")return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"url",Ne(re(e.url))].join("|");if(e.kind==="command"){let t=[...e.arguments].map(n=>re(n)).sort((n,r)=>n<r?-1:n>r?1:0);return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"command",Ne(re(e.command)),String(t.length),...t.map(Ne)].join("|")}return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"unknown",Ne(e.installationRootExternalKey),Ne(e.sourcePath),Ne(e.nativeKey)].join("|")}function Je(e){return(0,ml.createHash)("sha256").update(e).digest("hex")}var El=Je(N.MCP_MISSING_LAUNCH_SERIALIZED);function yl(){return{kind:"unknown",arguments:[],serialized:N.MCP_MISSING_LAUNCH_SERIALIZED,contentHash:El}}function Rl(e){let t=gs(e);return e.kind==="url"?{kind:"url",url:re(e.url),arguments:[],serialized:t,contentHash:Je(t)}:e.kind==="command"?{kind:"command",command:re(e.command),arguments:[...e.arguments].map(n=>re(n)).sort((n,r)=>n<r?-1:n>r?1:0),serialized:t,contentHash:Je(t)}:{kind:"unknown",arguments:[],serialized:t,contentHash:Je(t)}}var Cl=/^(https?:\/\/)([^/?#]*@)/i;function Il(e){return e.replace(Cl,"$1***@").replace(/([?&](?:access_token|api_key|apikey|auth|authorization|key|password|secret|token)=)([^&]*)/gi,"$1***")}function Al(e){let t=new Set,n=[];for(let r of e)r.length===0||t.has(r)||(t.add(r),n.push(r));return n.sort((r,o)=>r<o?-1:r>o?1:0),n}});var Nt=_e(q=>{"use strict";Object.defineProperty(q,"__esModule",{value:!0});q.PACKAGE_FIELD_MAX=void 0;q.npxExecBin=_s;q.packageNameFromSpec=bt;q.pinnedPackageVersionFromSpec=hs;q.pinnedPackageVersionFromNpx=wl;q.npxPackageSpecs=Ss;q.PACKAGE_FIELD_MAX=128;var Ol=/^(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*\/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*$/,Pl=new Set(["-p","--package"]),Tl=new Set(["-c","--call"]),kl=new Set(["--registry","--userconfig","--globalconfig","--prefix","--cache","--node-options","--workspace","-w","--loglevel"]),xl=new Set(["-y","--yes","-n","--no","-q","-s","--quiet","--silent","--offline","--prefer-offline","--prefer-online","--ignore-existing","--ignore-scripts","--legacy-peer-deps","--foreground-scripts"]),bl=/^--no-/;function Nl(e){return xl.has(e)||bl.test(e)}function _s(e){let n=(e.replace(/\\/g,"/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="npx"?"npx":n==="npm"?"npm":null}var Ml=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;function bt(e){if(e.length===0||e.length>q.PACKAGE_FIELD_MAX)return null;let t=e.lastIndexOf("@"),n=t>0?e.slice(0,t):e;return Ol.test(n)?n:null}function hs(e){let t=bt(e);if(t===null||!e.startsWith(`${t}@`))return;let n=e.slice(t.length+1);return Ml.test(n)?n:void 0}function wl(e,t){for(let n of Ss(e,t)){let r=hs(n);if(r!==void 0)return r}}function Ss(e,t){let n=_s(e);if(n===null)return[];let r=[...t];if(n==="npm"){let i=r[0]?.toLowerCase();if(i!=="exec"&&i!=="x")return[];r=r.slice(1)}let o=[],s=null;for(let i=0;i<r.length;i+=1){let a=r[i]??"";if(a==="--"){s=r[i+1]??null;break}if(!a.startsWith("-")){s=a;break}let c=a.indexOf("="),l=c===-1?a:a.slice(0,c);if(Tl.has(l))return[];if(Pl.has(l)){let u=c===-1?r[i+1]:a.slice(c+1);u!==void 0&&u.length>0&&o.push(u),c===-1&&(i+=1);continue}if(!(c!==-1||Nl(l))){if(kl.has(l)){i+=1;continue}return[]}}return o.length>0?o.every(i=>bt(i)!==null)?o:[]:s===null||bt(s)===null?[]:[s]}});var Es=_e(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.McpPackageEcosystem=void 0;ye.resolveMcpPackageIdentity=Vl;var vl=xt(),Un=Nt();ye.McpPackageEcosystem={NPM:"npm",PYPI:"pypi"};var Ll=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/,Ul=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/,Dl=/^(?:\d+!)?\d+(?:\.\d+)*(?:(?:a|b|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?(?:\+[0-9A-Za-z]+(?:[.][0-9A-Za-z]+)*)?$/;function Fl(e){let n=(e.replaceAll("\\","/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="uvx"||n==="uv"||n==="pipx"?n:null}var Hl=new Set(["--from","--spec"]),jl=new Set(["--python","-p","--with","--with-editable","--with-requirements","--index","--index-url","--default-index","--extra-index-url","--find-links","-f","--constraint","-c","--override","--refresh-package","--cache-dir","--directory","--project","--config-file","--color","--exclude-newer","--pip-args","--verbose-pip"]),$l=new Set(["-q","--quiet","-v","--verbose","-n","--native-tls","--offline","--isolated","--preview","--refresh","--reinstall","--upgrade","-U","--force","--system","--system-site-packages","--path","--managed-python","--progress"]),Kl=/^--no-/;function Bl(e,t){let n=Fl(e);if(n===null)return null;let r=[...t];if(n==="uv"){if(r[0]?.toLowerCase()!=="tool"||r[1]?.toLowerCase()!=="run")return null;r=r.slice(2)}else if(n==="pipx"){if(r[0]?.toLowerCase()!=="run")return null;r=r.slice(1)}let o=null,s=null;for(let i=0;i<r.length;i+=1){let a=r[i]??"";if(a==="--"){s=r[i+1]??null;break}if(!a.startsWith("-")){s=a;break}let c=a.indexOf("="),l=c===-1?a:a.slice(0,c);if(Hl.has(l)){let u=c===-1?r[i+1]:a.slice(c+1);u!==void 0&&u.length>0&&(o=u),c===-1&&(i+=1);continue}if(!(c!==-1||$l.has(l)||Kl.test(l))){if(jl.has(l)){i+=1;continue}return null}}return o??s}function Gl(e){if(e.length===0||e.length>Un.PACKAGE_FIELD_MAX)return null;let t=e.includes("==")?"==":e.includes("@")?"@":null;if(t===null)return null;let n=e.indexOf(t),r=e.slice(0,n),o=e.slice(n+t.length);return!Ul.test(r)||!Dl.test(o)?null:{ecosystem:ye.McpPackageEcosystem.PYPI,packageName:r,version:o}}function zl(e){let t=(0,Un.packageNameFromSpec)(e);if(t===null||!e.startsWith(`${t}@`))return null;let n=e.slice(t.length+1);return Ll.test(n)?{ecosystem:ye.McpPackageEcosystem.NPM,packageName:t,version:n}:null}function Vl(e){if(e?.kind!=="command"||(0,vl.launchContainsCredentials)(e))return;for(let n of(0,Un.npxPackageSpecs)(e.command,e.arguments)){let r=zl(n);if(r!==null)return r}let t=Bl(e.command,e.arguments);if(t!==null)return Gl(t)??void 0}});var Os=_e(oe=>{"use strict";Object.defineProperty(oe,"__esModule",{value:!0});oe.EMPTY_NPM_PUBLISHER=void 0;oe.isNpmRegistryPublisher=Yl;oe.displayPublisherName=Jl;oe.classifyMcpProvenance=od;var Cs=xt(),Dn=Nt();oe.EMPTY_NPM_PUBLISHER="npm:";var ys="npm:",Wl=/^[A-Za-z0-9._-]+$/;function Yl(e){return e.startsWith(ys)&&e!==oe.EMPTY_NPM_PUBLISHER&&Wl.test(e.slice(ys.length))}function Jl(e){if(!(e==null||e===""||e===oe.EMPTY_NPM_PUBLISHER))return e}function Rs(e){let t=e.split(".").map(Number);return t.length!==4||t.some(n=>!Number.isInteger(n)||n<0||n>255)?!1:t[0]===0||t[0]===10||t[0]===127||t[0]===169&&t[1]===254||t[0]===172&&(t[1]??0)>=16&&(t[1]??0)<=31||t[0]===192&&t[1]===168}function Xl(e){let t=/^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i.exec(e);if(t?.[1])return t[1];let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(e);if(!n)return;let r=Number.parseInt(n[1],16),o=Number.parseInt(n[2],16);return`${r>>8&255}.${r&255}.${o>>8&255}.${o&255}`}function Fn(e){return e.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"")}function Zl(e){let t=Fn(e),n=Xl(t);return t==="localhost"||t.endsWith(".localhost")||t==="::1"||t.endsWith(".local")||!t.includes(".")&&!t.includes(":")||Rs(t)||n!==void 0&&Rs(n)||/^(?:fc|fd)[0-9a-f]{2}:/i.test(t)||/^fe[89ab][0-9a-f]:/i.test(t)}function ql(e){let t=Fn(e);return t.includes(":")||/^[0-9.]+$/.test(t)||t.split(".").filter(Boolean).length<2?null:t}function Ql(e){let t=Fn(e.hostname),n=t.includes(":")?`[${t}]`:t,r=e.port?`:${e.port}`:"";return`${e.protocol}//${n}${r}`}function Is(e){let t={kind:"url",url:e};if((0,Cs.launchContainsCredentials)(t))return{origin:"UNKNOWN"};try{let n=new URL(e);if(!["http:","https:"].includes(n.protocol)||Zl(n.hostname))return{origin:"UNKNOWN"};let r=ql(n.hostname);return{origin:"THIRD_PARTY",...r===null?{}:{publisherName:r},packageSourceUrl:Ql(n)}}catch{return{origin:"UNKNOWN"}}}var As="mcp-remote";function ed(e,t){if(e===As)return t.find(n=>/^https?:\/\//i.test(n))}function td(e,t){return{origin:"THIRD_PARTY",...t?{publisherName:t}:{},packageName:e,packageKey:e}}function nd(e,t,n){let r=ed(e,t);return r!==void 0?Is(r):e===As?{origin:"UNKNOWN"}:td(e,n)}function rd(e){let t=e.replaceAll("\\","/");return t.startsWith("~/")||t.startsWith("/")||/^[A-Za-z]:\//.test(t)?!1:t.startsWith("./")||t.startsWith("../")||t==="scripts"||t.startsWith("scripts/")}function od(e){let t=e.launch;if(t===void 0||t.kind==="unknown")return{origin:"UNKNOWN"};if((0,Cs.launchContainsCredentials)(t))return{origin:"UNKNOWN"};if(t.kind==="url")return Is(t.url);let r=(0,Dn.npxPackageSpecs)(t.command,t.arguments)[0];if(r!==void 0){let o=(0,Dn.packageNameFromSpec)(r);if(o===null)return{origin:"UNKNOWN"};let s=nd(o,t.arguments,e.publisherName),i=typeof e.packageName=="string"?(0,Dn.packageNameFromSpec)(e.packageName):null;return i!==null&&i===o&&s.packageName!==void 0?{...s,packageName:i,packageKey:i}:s}return rd(t.command)?{origin:"INTERNAL"}:{origin:"UNKNOWN"}}});var Ps=_e(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.parseFrontmatterField=Y.parseFrontmatterDescription=Y.usableCatalogText=void 0;var sd=/^(?:>|\|)[-+]?$/,id=/^(?:>|\|)[-+]?(?:\s+(.*))?$/,ad=e=>{let t=e?.trim()??"";if(!(t.length===0||sd.test(t)))return t};Y.usableCatalogText=ad;var cd=e=>(0,Y.parseFrontmatterField)(e,"description");Y.parseFrontmatterDescription=cd;var ud=(e,t)=>{let n=/^---\s*\n([\s\S]*?)\n---/.exec(e);if(n)return dd(n[1],t)};Y.parseFrontmatterField=ud;var ld=e=>e.replace(/^["']|["']$/g,"");function dd(e,t){let n=e.split(`
|
|
5
|
+
`),r=`${t}:`,o=n.findIndex(d=>d===r||d.startsWith(`${r} `)||d.startsWith(`${r} `));if(o<0)return;let s=(n[o]??"").slice(r.length).trim(),i=id.exec(s);if(!i){let d=ld(s).trim();return(0,Y.usableCatalogText)(d)}let a=[];for(let d=o+1;d<n.length;d+=1){let g=n[d]??"";if(g.trim()===""){a.push("");continue}if(g.length===g.trimStart().length)break;a.push(g)}let c=a.reduce((d,g)=>g.trim()===""?d:Math.min(d,g.length-g.trimStart().length),Number.POSITIVE_INFINITY),l=[],u=i[1]?.trim();u&&l.push(u);for(let d of a)l.push(d.trim()===""?"":d.slice(c));for(;l.length>0&&l[l.length-1]==="";)l.pop();let m=s.startsWith(">")?l.join(`
|
|
6
6
|
`).split(/\n{2,}/).map(d=>d.split(`
|
|
7
7
|
`).map(g=>g.trim()).filter(Boolean).join(" ")).filter(d=>d.length>0).join(`
|
|
8
8
|
|
|
9
|
-
`):
|
|
10
|
-
`).trimEnd();return(0,
|
|
11
|
-
`),n=!1;return t.map(o=>n?
|
|
12
|
-
`)}function
|
|
13
|
-
`)}function Q(e,t){Rc(qr(e),{recursive:!0});let n=eo(qr(e),`.${Oc(e)}.${process.pid}.${yc(4).toString("hex")}.tmp`);try{Ac(n,t,"utf8");try{Xr(n,e)}catch(r){let o=r instanceof Error&&"code"in r?r.code:void 0;if(o==="EEXIST"||o==="EPERM"||o==="EACCES"){Zr(e),Xr(n,e);return}throw r}}catch(r){try{Zr(n)}catch{}throw r}}function ft(){return new Date().toISOString().replace(/\.\d{3}Z$/,"Z")}function to(){process.stdout.write('{"continue":true}')}function I(e){let t=process.env[e];return t===void 0||t===""?void 0:t}async function un(){return new Promise(e=>{let t="";if(process.stdin.isTTY){e("");return}process.stdin.setEncoding("utf8"),process.stdin.on("data",n=>{t+=n}),process.stdin.on("end",()=>{e(t)}),process.stdin.on("error",()=>{e(t)}),process.stdin.resume()})}async function ln(e){return new Promise(t=>{let n="",r=!1,o=i=>{r||(r=!0,clearTimeout(s),t(i||"{}"))},s=setTimeout(()=>{o(n)},e);if(process.stdin.isTTY){o("{}");return}process.stdin.setEncoding("utf8"),process.stdin.on("data",i=>{n+=i}),process.stdin.on("end",()=>{o(n)}),process.stdin.on("error",()=>{o(n)}),process.stdin.resume()})}async function J(e,t,n=3e3,r={}){let{execFile:o}=await import("node:child_process"),{promisify:s}=await import("node:util"),i=s(o);try{let{stdout:a}=await i(e,t,{timeout:n,windowsHide:!0,maxBuffer:1048576,cwd:r.cwd});return{ok:!0,stdout:a.trim()}}catch(a){let c=a,u=typeof c.code=="number"?c.code:typeof c.status=="number"?c.status:void 0;return{ok:!1,code:u,spawnFailed:u===void 0}}}async function w(e,t,n=3e3,r={}){let o=await J(e,t,n,r);return o.ok?o.stdout:""}async function dn(e=process.cwd()){let t=await J("git",["rev-parse","--show-toplevel"],2e3,{cwd:e});if(t.ok&&t.stdout)return{root:t.stdout,inGitRepo:!0};if(I("EV_AI_HOOK_DEBUG")){let r=t.ok?"empty stdout":t.spawnFailed?"spawn failed":`exit ${String(t.code??"unknown")}`;h(`DEBUG: git rev-parse --show-toplevel failed (${r}) cwd=${e}`)}let n=I("CURSOR_PROJECT_DIR")??I("CLAUDE_PROJECT_DIR");if(n&&cn(n)){let r=await J("git",["rev-parse","--show-toplevel"],2e3,{cwd:n});return r.ok&&r.stdout?{root:r.stdout,inGitRepo:!0}:{root:n,inGitRepo:!1}}return{root:e,inGitRepo:!1}}async function pn(e=process.cwd()){return(await dn(e)).root}function j(e,t){try{return JSON.parse(e)}catch{return t}}var an=new Map;function F(e,t){let n=an.get(e);if(n!==void 0)return n;try{let r=j(Ic(e,"utf8"),t);return an.set(e,r),r}catch{return an.set(e,t),t}}function Se(e){return typeof e=="string"?e:""}function re(e,t){let n=e[t];if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(!t.includes("."))return;let r=t.split("."),o=e;for(let s of r){if(o===null||typeof o!="object"||Array.isArray(o))return;o=o[s]}if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o}function _(e,t){let n=re(e,t);return typeof n=="string"?n:""}var ue=500;function no(e,t=2){if(!cn(e))return{entries:[],truncated:!1};let n=[],r=!1,o=(s,i)=>{if(i>t||r)return;let a;try{a=Cc(s,{withFileTypes:!0})}catch{return}for(let c of a){if(r)return;let u=eo(s,c.name);if(c.isDirectory()){o(u,i+1);continue}if(c.isFile()){try{n.push({name:Pc(e,u),size:Qr(u).size})}catch{continue}if(n.length>=ue){r=!0;return}}}};return o(e,1),{entries:n,truncated:r}}function fn(e){return cn(e)?{present:!0,size:Qr(e).size}:{present:!1,size:0}}function Pe(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function mn(e=process.env){return Pe(b("CURSOR_SANDBOX",e))}var bc=["CIRCLECI","BUILDKITE","TF_BUILD","JENKINS_URL","JENKINS_HOME","CODEBUILD_BUILD_ID","DRONE","DRONE_BUILD_NUMBER","TEAMCITY_VERSION","TRAVIS","APPVEYOR","BITBUCKET_BUILD_NUMBER"];function Nc(e){return bc.some(t=>!!b(t,e))}function Mc(e){if(b("KUBERNETES_SERVICE_HOST",e)||Pe(b("REMOTE_CONTAINERS",e))||Pe(b("DEVCONTAINER",e)))return!0;try{if(Tc("/.dockerenv")||kc("/proc/1/environ","utf8").includes("container="))return!0}catch{}return!1}function oo(e){return["VSCODE_PID","VSCODE_IPC_HOOK","CURSOR_EXTENSION_HOST_ROLE","CURSOR_WORKSPACE_LABEL"].some(t=>!!b(t,e))}function wc(e,t=process.platform){return oo(e)?t==="darwin"||t==="win32"?!0:["__CFBundleIdentifier","DISPLAY","WAYLAND_DISPLAY","SESSIONNAME"].some(n=>!!b(n,e)):!1}function vc(e){return e===void 0?!1:e.trim().toLowerCase().startsWith("bc-")}function Lc(e){return e==="linux"}function b(e,t){if(t){let n=t[e];return n===void 0||n===""?void 0:n}return I(e)}function Uc(e,t,n){return e.trim().toLowerCase()==="cursor"&&t.trim().toLowerCase()==="ubuntu"&&!!Dc(b("CURSOR_VERSION",n))}function Dc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function gn(e){if(vc(e.sessionId))return!0;let t=e.hostname??ro(),n=e.osUser??so(e.env);return Uc(t,n,e.env)}function Fc(e){return Pe(b("CURSOR_AGENT",e.env))?!0:gn(e)}function Hc(e){return!!(process.stdin.isTTY||process.stdout.isTTY||(b("TERM",e)??b("TERM_PROGRAM",e))||(b("SSH_TTY",e)??b("SSH_CONNECTION",e))||(b("__CFBundleIdentifier",e)??b("XPC_SERVICE_NAME",e))||oo(e)||["DISPLAY","WAYLAND_DISPLAY","XDG_SESSION_TYPE","DBUS_SESSION_BUS_ADDRESS"].some(t=>!!b(t,e))||b("SESSIONNAME",e))}function $e(e={}){let t=e.env;if(b("GITHUB_ACTIONS",t))return"github_actions";if(Pe(b("CLAUDE_CODE_REMOTE",t)))return"claude_remote";let n=e.platform??process.platform;if(!wc(t,n)&&Fc(e)&&(Pe(b("CURSOR_AGENT",t))||Lc(n)))return"cursor_cloud";if(b("CODESPACES",t)||b("CODESPACE_NAME",t))return"codespaces";if(b("GITLAB_CI",t))return"gitlab_ci";if(Nc(t))return"managed";let r=b("CI",t);return r&&r!=="false"&&r!=="0"?"managed":Mc(t)?"container":Hc(t)?"interactive":"unknown"}async function _n(){return await w("systemd-detect-virt",[],1e3)}function so(e=process.env,t=xc){for(let n of["USER","LOGNAME","USERNAME"]){let r=e[n];if(typeof r=="string"){let o=r.trim();if(o.length>0)return o}}try{return t().username??""}catch{return""}}async function hn(){let e=process.platform==="darwin"?"Darwin":process.platform==="win32"?"Windows_NT":"Linux",t="";if(process.platform==="darwin")t=await w("sw_vers",["-productVersion"],1e3);else if(process.platform==="linux"){try{let{readFileSync:s}=await import("node:fs"),i=s("/etc/os-release","utf8"),a=i.match(/^PRETTY_NAME="?([^"\n]+)"?/m)?.[1],c=i.match(/^VERSION_ID="?([^"\n]+)"?/m)?.[1];t=a??c??""}catch{t=await w("lsb_release",["-sd"],1e3).then(s=>s.replace(/^"|"$/g,""))}t||(t=await w("uname",["-r"],1e3))}else t=await w("ver",[],1e3);let n=so(),r=(process.env.SHELL??"").split(/[/\\]/).pop()??"",o="";try{o=await w("tty",[],500),o.includes("not a tty")&&(o="")}catch{o=""}return{os:e,os_version:t||null,user:n||null,shell:r||null,tty:o||null}}function Ke(){return ro()}import{createHash as jc}from"node:crypto";import{homedir as $c}from"node:os";import{dirname as uh,join as Kc,parse as lh,resolve as dh}from"node:path";var ao="https://hooks.ev-ai.ai",co=".claude/ev-ai-runtime-report.json",uo="config.json",ph=1024*1024,Bc=new Set(["localhost","127.0.0.1","[::1]","::1"]),Gc=["claude","cursor","codex"],lo=[co,".cursor/ev-ai-runtime-report.json",".codex/ev-ai-runtime-report.json"],Sn=/^[A-Za-z0-9._~-]+$/;function gt(e){return e!==void 0&&Gc.includes(e)}function mt(e,t){let n=e[t+1];return n&&!n.startsWith("--")?{value:n,next:t+1}:{next:t}}function Be(e){let t,n,r,o,s;for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0){if(a==="--runner"){let c=mt(e,i);t=c.value,i=c.next;continue}if(a.startsWith("--runner=")){t=a.slice(9);continue}if(a==="--url"){let c=mt(e,i);c.value&&(r=c.value),i=c.next;continue}if(a.startsWith("--url=")){r=a.slice(6);continue}if(a==="--token"){let c=mt(e,i);c.value&&(o=c.value),i=c.next;continue}if(a.startsWith("--token=")){o=a.slice(8);continue}if(a==="--base-url"){let c=mt(e,i);c.value&&(s=c.value),i=c.next;continue}if(a.startsWith("--base-url=")){s=a.slice(11);continue}!a.startsWith("-")&&n===void 0&&(n=a)}}return{runner:gt(t)?t:void 0,event:n,collectorUrl:r,orgToken:o,baseUrl:s}}function _t(e,t=ao){let n=t.replace(/\/+$/,""),r=e.trim();return`${n}/${r}/hook`}function En(e=$c()){return Kc(e,".ev-ai",uo)}function po(e,t){return{...e,...t}}function io(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<=32||n===127||n===39)return!0}return!1}function Ge(e){try{let t=new URL(e);return t.protocol==="https:"?!0:t.protocol==="http:"?Bc.has(t.hostname):!1}catch{return!1}}function yn(e){try{let n=new URL(e).pathname.split("/").filter(r=>r.length>0);if(n.length>=2&&n[n.length-1]==="hook"){let r=n[n.length-2];return r&&r.length>0?r:void 0}return}catch{return}}function Rn(e){let t;try{t=new URL(e)}catch{return`invalid URL (got: ${e})`}if(!Ge(e))return`must be https (or http on localhost / 127.0.0.1 / ::1) (got: ${e})`;let n=yn(e);if(!n)return`must end with /{orgToken}/hook (got: ${e})`;if(!Sn.test(n))return`org token must match ${Sn.source} (got: ${n})`;if(io(e))return`must not contain whitespace, control characters, or single quotes (got: ${e})`;if(io(t.pathname))return`pathname must not contain whitespace, control characters, or single quotes (got: ${e})`}function fo(e){return new URL(e).toString()}function Cn(e){if(e.collector_url)return e.collector_url;let t=e.repo_ingest_token,n=typeof t=="string"?t.trim():void 0;return n?_t(n):""}function ht(e){try{let t=new URL(e),n=t.pathname.split("/").filter(r=>r.length>0);return n.length>=2&&n[n.length-1]==="hook"&&(n[n.length-2]="***",t.pathname=`/${n.join("/")}`),t.toString()}catch{return"<invalid-url>"}}function mo(e){let t=e.collectorUrl?.trim(),n;if(t)n=t;else{let o=e.orgToken?.trim();o&&(n=_t(o,e.baseUrl?.trim()??void 0))}if(!n)return{};let r=Rn(n);return r?{problem:r}:{url:fo(n)}}function go(e){if(Rn(e))return;let t;try{t=new URL(e)}catch{return}let n=yn(e);if(!n)return;let o=t.pathname.split("/").filter(a=>a.length>0).slice(0,-2),s=o.length>0?`/${o.join("/")}`:"",i=`${t.origin}${s}/${n}`;return jc("sha256").update(i).digest("hex").slice(0,32)}var Et=2;var St="ev-ai-agent-hook";function zc(e){let t=e.split(/[/\\]/).pop();return t&&t.length>0?t:e}function _o(e){let t=zc(e);return t===St||t===`${St}.exe`}var mh=`current/${St}`,gh=`.ev-ai/agent-hook/${St}`,ho=5e3,So=5e3,In=3e3;var An=3e3,Eo=1500,yo=4*1024,On=256*1024,Vc=4*1024,Ro=32*1024,ze=840*60*1e3,Pn="1.2.4",_h=`@ev-ai/agent-hook@${Pn}`;import{createHash as rp}from"node:crypto";import{existsSync as op,mkdirSync as sp,readdirSync as ip,readFileSync as Js,unlinkSync as Xs,writeFileSync as ap}from"node:fs";import{homedir as Zs}from"node:os";import{join as Xn}from"node:path";import{createHash as Po,randomBytes as Jc}from"node:crypto";import{existsSync as To,mkdirSync as Tn,readFileSync as ko,unlinkSync as xo,writeFileSync as bo}from"node:fs";import{homedir as kn}from"node:os";import{dirname as yt,join as xn,resolve as Xc}from"node:path";var Wc=new Set(["action@github.com","noreply@github.com","noreply@anthropic.com","cursoragent@cursor.com"]),Yc=new Set(["github-actions","github actions","dependabot","renovate","cursoragent","cursor agent"]);function G(e,t){let n=(e??"").trim().toLowerCase(),r=(t??"").trim().toLowerCase();if(!n&&!r)return!1;if(n.includes("[bot]")||Yc.has(n)||r.includes("[bot]")||Wc.has(r))return!0;if(r.endsWith("@users.noreply.github.com")){let o=r.slice(0,r.indexOf("@")),s=o.includes("+")?o.slice(o.indexOf("+")+1):o;if(s.endsWith("bot")||s.includes("[bot]"))return!0}return!1}var Zc="installation.json",qc="cloud-bootstrap.lock",Qc=6e4;function No(e,t,n){let r=`${e}:${t??""}`;return n?`${n}:${r}`:r}function oe(e=kn()){return xn(e,".ev-ai","agent-hook")}function eu(e=kn()){return xn(oe(e),Zc)}function Mo(e){return xn(yt(e),qc)}function wo(){return Jc(8).toString("hex")}function Te(e){return Po("sha256").update(e).digest("hex").slice(0,16)}function A(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function vo(e){return/^[A-Za-z0-9._-]{8,64}$/.test(e)}function tu(e=process.env){let t=A(e.EV_AI_HOOK_INSTALLATION_ID);if(t){if(!vo(t)){h(`WARN: ignoring EV_AI_HOOK_INSTALLATION_ID (expected 8\u201364 chars [A-Za-z0-9._-], got length ${t.length})`);return}return t}}function Lo(e,t){return e&&vo(e)?e:(e&&h(`WARN: ignoring installation id override (expected 8\u201364 chars [A-Za-z0-9._-], got length ${e.length})`),tu(t))}function nu(e){return/^[0-9a-f]{16}$/.test(e)}function ru(e=process.env){if(A(e.GITHUB_ACTIONS)){let t=A(e.GITHUB_REPOSITORY_ID)??A(e.GITHUB_REPOSITORY),n=A(e.GITHUB_ACTOR)??A(e.GITHUB_TRIGGERING_ACTOR)??A(e.GITHUB_USER);if(t&&n)return Te(`github_actions|${t}|${n}`)}if(A(e.CODESPACES)||A(e.CODESPACE_NAME)){let t=A(e.CODESPACE_NAME);if(t)return Te(`codespaces|${t}`);let n=A(e.GITHUB_REPOSITORY_ID)??A(e.GITHUB_REPOSITORY),r=A(e.GITHUB_USER)??A(e.GITHUB_ACTOR);if(n&&r)return Te(`codespaces|${n}|${r}`)}if(A(e.GITLAB_CI)){let t=A(e.CI_PROJECT_ID)??A(e.CI_PROJECT_PATH),n=A(e.GITLAB_USER_LOGIN)??A(e.GITLAB_USER_EMAIL)??A(e.GITLAB_USER_NAME);if(t&&n)return Te(`gitlab|${t}|${n}`)}return null}var ou="cursoragent@cursor.com";function su(e){let t=A(e.CURSOR_USER_EMAIL);return!t||t.toLowerCase()===ou?null:t}function iu(e,t){return A(e.CURSOR_PROJECT_DIR)??A(e.CLAUDE_PROJECT_DIR)??t}function au(e){return e.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1").replace(/\.git$/i,"").toLowerCase()}async function cu(e){let t=await w("git",["config","--get","remote.origin.url"],2e3,{cwd:e});return t?au(t):e}async function uu(e){let t=A(await w("git",["config","--local","--get","user.email"],2e3,{cwd:e})||void 0);if(t&&!G(null,t))return t;let n=A(await w("git",["log","-1","--format=%ae"],2e3,{cwd:e})||void 0);return n&&!G(null,n)?n:null}function lu(e,t){let n=iu(e,t);return n?Te(`cursor_cloud|${n}|${su(e)??""}`):null}async function du(e,t){let n=A(e.CLAUDE_PROJECT_DIR)??t;if(!n)return null;let r=await cu(n),o=await uu(n);return Te(`claude_remote|${r}|${o??""}`)}function Co(e,t){let n=Lo(e,t);if(n)return n;let r=ru(t);return r||wo()}async function pu(e){let n=await w("git",["config","--get","remote.origin.url"],2e3,{cwd:e})||Xc(e);return Po("sha256").update(n).digest("hex").slice(0,16)}function fu(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&r.length>0&&(t[n]=r);return Object.keys(t).length>0?t:void 0}function mu(e){try{let t=JSON.parse(e);if(typeof t.installation_id!="string"||t.installation_id.length===0)return;let n=fu(t.platform_agent_ids);return{installation_id:t.installation_id,...t.pinned===!0?{pinned:!0}:{},...n?{platform_agent_ids:n}:{},...typeof t.operator_identity_hash=="string"?{operator_identity_hash:t.operator_identity_hash}:{},...typeof t.operator_identity_sent_at=="string"?{operator_identity_sent_at:t.operator_identity_sent_at}:{}}}catch{return}}function Ee(e){if(To(e))try{return mu(ko(e,"utf8"))}catch{}}function bn(e){return Ee(e)}function Uo(e,t,n){let r=Ee(e);if(!r||r.operator_identity_hash===t&&r.operator_identity_sent_at===n)return;let o={...r,operator_identity_hash:t,operator_identity_sent_at:n};try{Q(e,`${JSON.stringify(o,null,2)}
|
|
14
|
-
`)}catch(s){let i=s instanceof Error?s.message:String(s);h(`WARN: operator identity cache write failed open: ${i}`)}}function
|
|
15
|
-
`,{encoding:"utf8",flag:"wx"}),!0}catch(r){if(
|
|
16
|
-
`)}catch(s){let i=s instanceof Error?s.message:String(s);h(`WARN: platform_agent_id cache write failed open: ${i}`)}}function
|
|
17
|
-
`,{encoding:"utf8",flag:"wx"})}function
|
|
18
|
-
`)}function Oo(e,t){return{installation_id:e,...t&&t===e?{pinned:!0}:{}}}async function Ko(e,t={}){let n=t.home??kn(),r=t.env??process.env,o=await pu(e),s=eu(n),i={sessionId:t.sessionId,hostname:A(r.HOSTNAME)??void 0,osUser:A(r.USER)??A(r.LOGNAME)??A(r.USERNAME)??void 0,env:r},a=$e(i),c=Lo(t.overrideId,r),u=a==="cursor_cloud"&&gn(i)?lu(r,e):a==="claude_remote"?await du(r,e):null,l=Ee(s);if(l){let S=l;if(c&&c===l.installation_id&&l.pinned!==!0&&(S={...l,pinned:!0},Ao(s,S)),!!u&&u!==S.installation_id&&!c&&S.pinned!==!0&&nu(S.installation_id)&&u){let y={installation_id:u,...S.platform_agent_ids?{platform_agent_ids:S.platform_agent_ids}:{}};return Ao(s,y),{installationId:u,storePath:s,repoKey:o}}return{installationId:S.installation_id,storePath:s,repoKey:o}}let p=c??u??Co(void 0,r),m=Io(s,Oo(p,c));if(m)return{installationId:m.installation_id,storePath:s,repoKey:o};let d=c??u??Co(void 0,r),g=Io(s,Oo(d===p?wo():d,c));if(g)return{installationId:g.installation_id,storePath:s,repoKey:o};throw new Error(`Failed to create installation record at ${s}`)}import{existsSync as Mu}from"node:fs";import{existsSync as Cu}from"node:fs";import{homedir as zo}from"node:os";import{join as Iu}from"node:path";import{existsSync as _u,readdirSync as Bo}from"node:fs";import{homedir as Rt}from"node:os";import{join as K}from"node:path";function hu(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/ClaudeCode";case"win32":return K(process.env.ProgramFiles??"C:\\Program Files","ClaudeCode");default:return"/etc/claude-code"}}function Su(e=process.platform){let t=hu(e),n=[K(t,"managed-settings.json")],r=K(t,"managed-settings.d");try{if(!_u(r))return n;let o=Bo(r).filter(s=>s.endsWith(".json")&&!s.startsWith(".")).sort().map(s=>K(r,s));n.push(...o)}catch{}return n}function Nn(e=process.platform,t=Rt()){return{serverManaged:K(t,".claude","remote-settings.json"),fileBased:Su(e)}}function Eu(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/Cursor";case"win32":return K(process.env.ProgramData??"C:\\ProgramData","Cursor");default:return"/etc/cursor"}}function yu(e=process.platform,t=Rt()){let n=[K(Eu(e),"hooks.json")],r=K(t,".cursor","managed");try{for(let o of Bo(r,{withFileTypes:!0}))!o.isDirectory()||o.name.startsWith(".")||n.push(K(r,o.name,"hooks.json"))}catch{}return n}function Ru(e=process.platform,t=Rt()){let n=e==="win32"?K(process.env.ProgramData??"C:\\ProgramData","OpenAI","Codex"):"/etc/codex",r=[K(n,"requirements.toml")];return e!=="win32"&&r.push(K(n,"managed_config.toml")),r.push(K(t,".codex","managed_config.toml"),K(n,"config.toml")),r}function Ct(e,t=process.platform,n=Rt()){switch(e){case"claude":{let{serverManaged:r,fileBased:o}=Nn(t,n);return[r,...o]}case"cursor":return yu(t,n);default:return Ru(t,n)}}function Vo(e){return e.settings.filter(t=>t.toLowerCase().endsWith(".json"))}var Au={claude:{shared:{skillRoots:[".claude/skills"],dirs:[{dir:".claude/agents",kind:"SUBAGENT",extensions:[".md"]},{dir:".claude/commands",kind:"COMMAND",extensions:[".md"]},{dir:".claude/rules",kind:"RULE",extensions:[".mdc",".md"]}],memory:[["CLAUDE.md"],["CLAUDE.local.md"],[".claude/CLAUDE.md"]],settings:[".claude/settings.json",".claude/settings.local.json",".claude/hooks.json"]},homeOnly:{mcpJson:[".claude.json"],plugins:"claude",managed:"claude"},projectOnly:{mcpJson:[".mcp.json","mcp.json"]}},cursor:{shared:{skillRoots:[".cursor/skills"],dirs:[{dir:".cursor/agents",kind:"SUBAGENT",extensions:[".md"]},{dir:".cursor/commands",kind:"COMMAND",extensions:[".md"]},{dir:".cursor/rules",kind:"RULE",extensions:[".mdc",".md"]}],memory:[["AGENTS.md"]],settings:[".cursor/hooks.json",".cursor/cli-config.json"],mcpJson:[".cursor/mcp.json"]},homeOnly:{skillRoots:[".cursor/skills-cursor"],memory:[[".cursor/AGENTS.md"]],plugins:"cursor",managed:"cursor"},projectOnly:{skillRoots:[".agents/skills"]}},codex:{shared:{skillRoots:[".agents/skills",".codex/skills"],dirs:[{dir:".codex/agents",kind:"SUBAGENT",extensions:[".toml",".md"]},{dir:".codex/prompts",kind:"COMMAND",extensions:[".md"]},{dir:".codex/rules",kind:"RULE",extensions:[".md",".rules"]}],memory:[["AGENTS.override.md","AGENTS.md"]],settings:[".codex/hooks.json",".codex/config.toml"],mcpToml:[".codex/config.toml"]},homeOnly:{memory:[[".codex/AGENTS.override.md",".codex/AGENTS.md"]],managed:"codex"}}};function Go(e,t){if(!(!e&&!t))return[...e??[],...t??[]]}function Ou(e,t={}){let{shared:n}=e;return{skillRoots:[...n.skillRoots,...t.skillRoots??[]],dirs:n.dirs,memory:[...n.memory,...t.memory??[]],settings:[...n.settings,...t.settings??[]],mcpJson:Go(n.mcpJson,t.mcpJson),mcpToml:Go(n.mcpToml,t.mcpToml),plugins:t.plugins??n.plugins,managed:t.managed??n.managed}}function Wo(e){return Object.fromEntries(Object.entries(Au).map(([t,n])=>[t,Ou(n,n[e])]))}var ke=Wo("homeOnly"),de=Wo("projectOnly");function Pu(e){return[...e.skillRoots,...e.dirs.map(t=>t.dir),...e.memory.flat(),...e.settings,...e.mcpJson??[],...e.mcpToml??[]]}function Tu(e,t){return Pu(e).some(n=>Cu(Iu(t,n)))}function Yo(e,t){for(let n of e)if(Tu(n,t))return!0;return!1}function le(e){return[...new Set(e)]}function pe(e){let t=[],n=[],r=[],o=[],s=[],i=[],a=[];for(let c of e){t.push(...c.skillRoots);for(let u of c.dirs)u.kind==="SUBAGENT"?n.push(u.dir):u.kind==="COMMAND"?r.push(u.dir):o.push(u.dir);s.push(...c.memory.flat()),i.push(...c.settings),a.push(...c.mcpJson??[],...c.mcpToml??[])}return{skills:le(t),subagents:le(n),commands:le(r),rules:le(o),memory:le(s),settings:le(i),mcp:le(a)}}function ku(e,t=zo(),n=process.platform){let r=[];for(let o of e)o.managed&&r.push(...Ct(o.managed,n,t));return le(r)}var fe=pe(Object.values(ke));function Jo(e=zo(),t=process.platform){return ku(Object.values(ke),e,t)}import{existsSync as xu}from"node:fs";import{resolve as Mn}from"node:path";function z(e){return Mn(e).replaceAll("\\","/").replace(/\/$/,"")}function ye(e,t){let n=new Set(t),r=[];for(let o of e)n.delete(o)&&r.push(o);for(let o of[...n].sort())r.push(o);return r}function It(e,t){if(!e)return t;let n=`${e}/`,r=[],o=[];for(let s of t)s===e||s.startsWith(n)?r.push(s):o.push(s);return r.length===0?t:[...r,...o]}var bu=/^(?!\.)[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;function Ve(e){let t=e.replaceAll("\\","/").replace(/^\.\//,"");return!t||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.split("/").includes("..")||!bu.test(t)?null:t}function xe(e,t){let n=new Set,r=[];for(let o of[e,t]){if(!o)continue;let s=z(o);n.has(s)||(n.add(s),r.push(s))}return r}function Nu(e,t){let n=`${e}/`;return t===e||t.startsWith(n)}function ee(e,t,n,r=xu){for(let o of e)for(let s of t){let i=z(Mn(o,s)),a=Mn(o,s,n).replaceAll("\\","/");if(Nu(i,a)&&r(a))return a}return null}var Zo=/(?:^|\/|[\s"'=(])(?:\.cursor\/|\.claude\/|\.agents\/)skills(?:-cursor)?\/([^/]+)\/SKILL\.md/i,qo=/(?:^|\/|[\s"'=(])\.codex\/commands\/([^/]+)\.md\b/i,wu=/(?:^|\s)\/([a-z][a-z0-9-]{1,63}(?:\/[a-z][a-z0-9-]{1,63}){0,5})\b/gi,Xo=new Set(["applications","app","bin","boot","data","dev","etc","home","lib","media","mnt","node_modules","opt","pkg","private","proc","projects","repos","run","sbin","src","srv","sys","tmp","usr","users","var","volumes","workspace","workspaces"]),vu=/^[a-z][a-z0-9-]{1,63}$/,Lu=[".cursor/skills",".claude/skills",".agents/skills"],Uu=[".cursor/skills",".cursor/skills-cursor",".claude/skills",".agents/skills"],Du=ye(Lu,pe(Object.values(de)).skills),Fu=ye(Uu,pe(Object.values(ke)).skills),Hu=new Set(["read","read_file","view"]),ju=new Set(["bash","shell","zsh"]);function wn(e){let t=e.replace(/\\/g,"/");return Zo.exec(t)?.[1]??null}function $u(e){let t=e.replace(/\\/g,"/"),r=qo.exec(t)?.[1];return r?r.toLowerCase():null}function Ku(e){return wn(e)??$u(e)}function Bu(e){for(let t of["path","file_path","target_file"]){let n=e[t];if(typeof n=="string"&&n.length>0)return n}return null}function At(e){return typeof e=="string"?At(j(e,null)):!e||typeof e!="object"?null:Bu(e)}function Qo(e){if(typeof e=="string")return Qo(j(e,null));if(!e||typeof e!="object")return null;let t=e.command;return typeof t=="string"&&t.length>0?t:null}function vn(e){let t=Qo(e.tool_input);if(t)return t;let n=Se(e.command);return n.length>0?n:null}function Gu(e){let t=e.replace(/\\/g,"/"),n=Zo.exec(t);if(n?.[1])return n[1];let o=qo.exec(t)?.[1];return o?o.toLowerCase():null}function zu(e){return typeof e.tool_name=="string"?e.tool_name:typeof e.tool=="string"?e.tool:""}function Ln(e){let t=At(e.tool_input)??Se(e.file_path);return t.length>0?t:null}function We(e,t,n){let r=zu(e).toLowerCase();if(Hu.has(r)){let o=Ln(e);return o?t(o):null}if(ju.has(r)){let o=vn(e);return o?n(o):null}return null}function es(e){return We(e,Ku,Gu)}function Vu(e){let t=new Set,n=[];for(let r of e.matchAll(wu)){let o=r[1]?.toLowerCase();!o||t.has(o)||Wu(o)||(t.add(o),n.push(o))}return n}function Wu(e){let t=e.split("/")[0];return Xo.has(e)||t!==void 0&&Xo.has(t)}function ts(e){let t=e.skillId.toLowerCase();if(!vu.test(t))return null;let n=e.exists??Mu,r=`${t}/SKILL.md`,o=ee(xe(e.launchCwd,e.gitRoot),Du,r,n);return o!==null?o:e.home?ee([z(e.home)],Fu,r,n):null}function Yu(e){return Se(e.prompt)}function ns(e){let t=_(e,"command_name");if(t){let r=_(e,"expansion_type");if(r&&r!=="slash_command")return[];let o=t.replace(/^\//,"").toLowerCase();return o?[o]:[]}let n=Yu(e);return n?Vu(n):[]}var Kn=je(Me(),1);import{existsSync as kd}from"node:fs";var Ce={claude:".claude",cursor:".cursor",codex:".codex",opencode:".opencode"};function Je(e){let n=e.replace(/^\/+|\/+$/g,"").toLowerCase().split("/").filter(Boolean);return n.length<2?"":n.join("/")}function Td(e){if(!e)return"";let t=e.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1");t=t.replace(/\.git$/i,"");let n=t.match(/^git@[^:]+:(.+)$/);if(n?.[1])return Je(n[1]);let r=t.match(/^ssh:\/\/[^/]+\/(.+)$/i);if(r?.[1])return Je(r[1]);t=t.replace(/^https:\/\//i,""),t=t.replace(/^http:\/\//i,""),t=t.replace(/^ssh:\/\//i,"");let o=t.match(/^[^/]+\/(.+)$/);return o?.[1]?Je(o[1]):Je(t)}async function Xe(e=process.cwd()){let t=await J("git",["rev-parse","--is-inside-work-tree"],2e3,{cwd:e});if(!t.ok||t.stdout!=="true")return null;let[n,r,o,s]=await Promise.all([J("git",["remote","get-url","origin"],2e3,{cwd:e}),J("git",["branch","--show-current"],2e3,{cwd:e}),J("git",["rev-parse","HEAD"],2e3,{cwd:e}),J("git",["status","--porcelain"],2e3,{cwd:e})]),i=n.ok?n.stdout:null;return{remote:i===null?null:i.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1"),branch:r.ok?r.stdout:null,head:o.ok?o.stdout:null,dirty:s.ok?s.stdout.length>0:null}}async function Os(e,t,n,r=process.cwd(),o,s,i){if(t)return t;let a=Ce[n];if(!a)return"";let c=No(n,e.scope_path,i);if(s){let g=Ho(s,c);if(g)return g}let u=o??await Xe(r),l=u?.remote?Td(u.remote):"";if(l||(l=Je(process.env.GITHUB_REPOSITORY??"")),!l)return"";let p=e.scope_path??"",m=p?`${p}/`:"",d=`${l}:${m}${a}`;return s&&jo(s,c,d),d}var xd=[".cursor/rules",".claude/rules",".codex/rules"],bd=pe(Object.values(de)).rules;function Nd(e){return ye(It(e?Ce[e]:void 0,xd),bd)}var Md=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/rules\/[^'"\s]+?\.(?:mdc|md|rules))\b/i;function Ps(e){let t=Ve(e.relativePath);if(!t)return null;let n=e.exists??kd,r=xe(e.launchCwd,e.gitRoot),o=Nd(e.runnerPlatform),s=ee(r,o,t,n);if(s!==null)return s;if(!t.includes("/")){let i=ee(r,["."],t,n);if(i!==null)return i}return e.home?ee([z(e.home)],o,t,n):null}function wd(e){let t=e.replace(/\\/g,"/"),r=Md.exec(t)?.[1];return r?(0,Kn.nativeKeyForRulePath)(r):null}function Ts(e){return We(e,Kn.nativeKeyForRulePath,wd)}function ks(e){return e.replace(/\.(mdc|md|rules)$/i,"")}function xs(e){let t=e.attachments;if(!Array.isArray(t))return[];let n=new Set,r=[];for(let o of t){if(!o||typeof o!="object"||Array.isArray(o))continue;let s=o;if(s.type!=="rule")continue;let i=typeof s.file_path=="string"?s.file_path:"",a=Ve(i);!a||n.has(a)||(n.add(a),r.push(a))}return r}var Bn=je(Me(),1);import{existsSync as vd}from"node:fs";var Ld=[".cursor/commands",".claude/commands",".codex/prompts"],Ud=pe(Object.values(de)).commands;function Dd(e){return ye(It(e?Ce[e]:void 0,Ld),Ud)}var Fd=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/(?:commands|prompts)\/[^'"\s]+?\.(?:md|mdc))\b/i;function bs(e){let t=Ve(e.commandId);if(!t)return null;let n=e.exists??vd,r=`${t}.md`,o=Dd(e.runnerPlatform),s=ee(xe(e.launchCwd,e.gitRoot),o,r,n);return s!==null?s:e.home?ee([z(e.home)],o,r,n):null}function Hd(e){let t=e.replace(/\\/g,"/"),r=Fd.exec(t)?.[1];return r?(0,Bn.nativeKeyForCommandPath)(r):null}function Ns(e){return We(e,Bn.nativeKeyForCommandPath,Hd)}import{existsSync as ws}from"node:fs";import{homedir as vs}from"node:os";import{join as Ze,resolve as Gn,sep as Ms}from"node:path";function zn(e){return[...new Set([e,e.replaceAll(/[^A-Za-z0-9_-]/g,"_"),e.replaceAll(/[^A-Za-z0-9_-]+/g,"_")])]}function Vn(e,t){let n=t.toLowerCase();return zn(e).some(r=>r.toLowerCase()===n)}function bt(e,t,n){if(!ws(e))return;let r=F(e,{});for(let[o,s]of Object.entries(r.mcpServers??{}))n.set(o,{declared:{name:o,...t},config:s})}function jd(e,t,n){if(!ws(e))return;let r=F(e,{}),o=Gn(t),s=null;for(let a of Object.keys(r.projects??{})){let c=Gn(a);(o===c||o.startsWith(c.endsWith(Ms)?c:c+Ms))&&(s===null||c.length>Gn(s).length)&&(s=a)}if(s===null)return;let i=r.projects?.[s]?.mcpServers??{};for(let[a,c]of Object.entries(i))n.set(a,{declared:{name:a,source:"claude_json_project",sourcePath:".claude.json",scope:"user"},config:c})}function Ls(e,t,n,r){let o=new Map;for(let s of e.mcp_servers??[])s.name&&o.set(s.name,{declared:{name:s.name,source:"manifest"}});return n==="claude"?(bt(Ze(r,".claude.json"),{source:"claude_json_user"},o),jd(Ze(r,".claude.json"),t,o)):n==="cursor"&&bt(Ze(r,".cursor/mcp.json"),{source:"cursor_mcp_user"},o),bt(Ze(t,".mcp.json"),{source:"mcp_json"},o),bt(Ze(t,".cursor/mcp.json"),{source:"cursor_mcp"},o),o}async function Wn(e,t=process.cwd(),n="claude",r=vs()){return[...Ls(e,t,n,r).values()].map(o=>o.declared)}function Us(e,t,n=process.cwd(),r="claude",o=vs()){let s=Ls(t,n,r,o),i=s.get(e);if(i!==void 0)return i.config??null;for(let[a,c]of s)if(Vn(a,e))return c.config??null;return null}function Yn(e){let t=mo(e);if(t.problem){h(`WARN: ignoring --url/--token collector override: ${t.problem}`);return}return t.url}function Ds(e,t){if(_(e,"conversation_id"))return!0;if(t==="")return!1;let n=t[0];return n?.toLowerCase()===n}function $d(){return!!(I("CURSOR_VERSION")??I("CURSOR_PROJECT_DIR"))}function Jn(e,t,n){return e!=="claude"&&e!=="codex"?!1:Ds(t,n)?!0:$d()}function qe(e,t,n,r){if(Ds(e,t))return"cursor";if(gt(r))return r;let o=_(e,"conversation_id"),s=_(e,"turn_id"),i=_(e,"session_id"),a=t.toLowerCase(),c="unknown";return o||t===a&&t!==""?c="cursor":s?c="codex":(i||a==="sessionstart"||a==="sessionend"||a==="stop"||a==="stopfailure"||a==="pretooluse"||a==="posttooluse"||a==="posttoolusefailure"||a==="permissiondenied"||a==="subagentstart"||a==="subagentstop"||a==="userpromptexpansion"||a==="userpromptsubmit")&&(c="claude"),gt(n)&&(c=n),c}function Nt(e,t){let n=e.toLowerCase();return n==="sessionend"||n==="stopfailure"||n==="subagentstop"?!0:n==="stop"&&t==="codex"}function Kd(e){switch(e){case"sessionstart":return"session_start";case"stop":case"sessionend":case"stopfailure":return"session_end";case"pretooluse":case"posttooluse":case"posttoolusefailure":case"permissiondenied":case"beforemcpexecution":case"beforeshellexecution":case"aftershellexecution":case"beforereadfile":case"afterfileedit":case"subagentstart":case"subagentstop":return"tool_invoked";case"beforesubmitprompt":case"userpromptexpansion":case"userpromptsubmit":return"skill_invoked";default:return""}}function Fs(e){let t=e.toLowerCase();return t==="userpromptsubmit"||t==="beforesubmitprompt"}function Hs(e,t){return e.toLowerCase()==="userpromptsubmit"&&t==="claude"}function js(e){let t=e.toLowerCase();return t==="posttooluse"?!0:t==="posttoolusefailure"||t==="permissiondenied"?!1:null}function $s(e,t,n){let r=_(e,"session_id")||_(e,"conversation_id"),o=_(e,"prompt.id")||_(e,"prompt_id")||_(e,"generation_id")||_(e,"turn_id"),s=_(e,"hook_event_name")||_(e,"event"),i=_(e,"source"),a=qe(e,s,t,n);return{sessionId:r,turnId:o,runnerEvent:s,hookSource:i,runnerPlatform:a}}var Bd=["session_start","session_end","tool_invoked","skill_invoked"];function Gd(e){return Bd.includes(e)}function Ks(e,t){return e&&Gd(e)?e:Kd(t.toLowerCase())}var zd={beforeshellexecution:"Shell",aftershellexecution:"Shell",beforereadfile:"Read",afterfileedit:"Write"};function Bs(e){return/^mcp__/i.test(e)||/^MCP:/i.test(e)}function Gs(e,t=""){let n=_(e,"tool_name")||_(e,"tool")||null,r=t.toLowerCase();n?r==="beforemcpexecution"&&!Bs(n)&&(n=`MCP:${n}`):n=zd[r]??null;let o=e.tool_input,i=(o&&typeof o=="object"?Se(o.skill)||Se(o.skill_name):"")||_(e,"skill_name")||null,a=n&&e.tool_name!==n&&e.tool!==n?{...e,tool_name:n}:e;i??=es(a);let c=Ts(a),u=Ns(a);return{toolName:n,skillName:i,ruleName:c,commandName:u}}var Vd=/^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/;function zs(e){for(let t of["subagent_type","agent_type"]){let n=_(e,t);if(n&&Vd.test(n))return n}return null}function Vs(e){let t=re(e,"duration_ms");if(typeof t=="number")return t;let n=re(e,"duration");return typeof n=="number"?n:null}var Wd="error",Yd="interrupted",Jd="permission_denied",Xd=/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;function Qe(e){return Xd.test(e)?e:null}function Zd(e){for(let t of["failure_type","error_type"]){let n=Qe(_(e,t));if(n)return n}return null}function Ws(e,t){return re(e,"is_interrupt")===!0?Yd:t.toLowerCase()==="permissiondenied"?Jd:Zd(e)??Wd}function qd(e,t){let n=null;for(let r of t)r&&(e===r||e.startsWith(`${r}_`)||e.startsWith(`${r}-`))&&(n===null||r.length>n.length)&&(n=r);return n}function Qd(e,t){let n=null;for(let r of t)!r||!Vn(r,e)||(n===null||r.length>n.length)&&(n=r);return n}function ep(e,t){let n=null,r=0;for(let s of t)if(s)for(let i of zn(s)){let a=`${i}__`;e.length>a.length&&e.slice(0,a.length).toLowerCase()===a.toLowerCase()&&i.length>r&&(n={mcpServer:s,mcpTool:e.slice(a.length)},r=i.length)}if(n!==null)return n;let o=/^(.+?)__(.+)$/.exec(e);return!o?.[1]||!o[2]?{mcpServer:null,mcpTool:null}:{mcpServer:Qd(o[1],t)??o[1],mcpTool:o[2]}}function tp(e,t){if(/^mcp__/i.test(e))return ep(e.slice(5),t);if(/^MCP:/i.test(e)){let n=e.slice(4);if(!n)return{mcpServer:null,mcpTool:null};let r=n.indexOf(":");if(r>0)return{mcpServer:n.slice(0,r),mcpTool:n.slice(r+1)||null};let o=n.indexOf("__");return o>0?{mcpServer:n.slice(0,o),mcpTool:n.slice(o+2)||null}:{mcpServer:qd(n,t),mcpTool:n}}return{mcpServer:null,mcpTool:null}}function np(e,t){let n=`${t}__`;return e.length>n.length&&e.toLowerCase().startsWith(n.toLowerCase())?e.slice(n.length):e}function Ys(e,t=[],n=""){let r=e?tp(e,t):{mcpServer:null,mcpTool:null},o=Qe(n.trim());if(!o)return r;let s=r.mcpTool;return!s&&e&&!Bs(e)&&(s=e),s&&(s=np(s,o)),{mcpServer:o,mcpTool:s}}var qs=3e4,cp="claims",up=!0,lp=100,dp=new Set(["sessionstart","sessionend","stopfailure"]),pp=["tool_name","tool","command","file_path","url"];function fp(e=Zs()){return Xn(oe(e),cp)}function Qs(e){let t=e.split(`
|
|
19
|
-
`,1)[0]??"";return Number(
|
|
20
|
-
`,{encoding:"utf8",flag:"wx"})}catch(o){if(
|
|
21
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: cloud cache write failed open: ${r}`)}}function
|
|
22
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: cursor IDE identity cache write failed open: ${r}`)}}import{execFileSync as
|
|
9
|
+
`):l.join(`
|
|
10
|
+
`).trimEnd();return(0,Y.usableCatalogText)(m)}});var bs=_e(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=T.COMPONENT_INSPECTION_TEXT_MAX_BYTES=T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER=void 0;T.fitSnapshotInspectionTextBudget=pd;T.capComponentTextBytes=ks;T.prepareComponentInspectionText=fd;T.redactComponentSource=jn;T.componentSourceContainsRedactableSecret=kd;T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER="[REDACTED]";T.COMPONENT_INSPECTION_TEXT_MAX_BYTES=256*1024;T.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=3*1024*1024;function pd(e){let t=0;return e.map(n=>{let r=n,o=r.skill?.inspectionText;if(o===void 0)return n;let s=Buffer.byteLength(o,"utf8");return t+s<=T.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES?(t+=s,n):{...n,skill:{...r.skill,inspectionText:void 0}}})}function ks(e,t){if(e==null||e.length===0)return;let n=Buffer.from(e,"utf8");if(n.byteLength<=t)return e;let r=new TextDecoder("utf-8",{fatal:!0});for(let o=t;o>0;o-=1)try{return r.decode(n.subarray(0,o))}catch{}}function fd(e){if(!(e==null||e.length===0))return ks(jn(e),T.COMPONENT_INSPECTION_TEXT_MAX_BYTES)}var md="(?:[A-Za-z0-9_.-]*(?:passwd|password|secret|token|credential|credentials|apikey|api[_-]?key|access[_-]?key|secret[_-]?key|private[_-]?key|auth|authorization|session[_-]?id)[A-Za-z0-9_.-]*)",gd=new RegExp(`(\\b${md})(\\s*[:=]\\s*)(?:(")([^"\\n]*)(")|(')([^'\\n]*)(')|([^\\s"'][^"'\\n]*))`,"gi"),_d=[/^(?:none|null|nil|n\/a|empty|unset|not (?:required|needed|set)|no (?:password|token|auth))(?=$|[\s.,;:()—–-])/i,/^\$\{?[A-Za-z_][A-Za-z0-9_]*\}?$/,/^\$\(.*\)$/,/^\$\{\{.*\}\}$/,/^%[A-Za-z_][A-Za-z0-9_]*%$/,/^(?:process\.env|os\.environ|import\.meta\.env)\.[A-Za-z_][A-Za-z0-9_]*[,;]?$/,/^<[^<>]*>$/,/^(?:\*{3,}|\.{3,}|…|x{3,})$/i,/^your[-_ ]/i,/^(?:see|from|via|stored in|use|ask|obtain|get|fetch|run|read|provided by|generated by)\b/i];function Hn(e){let t=e.trim().replace(/^`+|`+$/g,"").trim();return _d.some(n=>n.test(t))}function hd(e){if(e.startsWith("$(")){let n=0;for(let r=1;r<e.length;r+=1)if(e[r]==="("&&(n+=1),e[r]===")"&&(n-=1,n===0))return e.slice(0,r+1);return e}return/^(?:\$\{\{[^}]*\}\}|<[^<>]*>)/.exec(e)?.[0]??/^\S+/.exec(e)?.[0]??""}var Sd=[/\bsk-(?:proj-)?[A-Za-z0-9_-]{16,}/g,/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}/g,/\bgithub_pat_[A-Za-z0-9_]{20,}/g,/\bxox[baprs]-[A-Za-z0-9-]{10,}/g,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,/\bAIza[0-9A-Za-z_-]{35}\b/g,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g],Ed=/\b[A-Za-z0-9_+/-]{32,}={0,2}\b/g,yd=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function Rd(e){let t=new Map;for(let r of e)t.set(r,(t.get(r)??0)+1);let n=0;for(let r of t.values()){let o=r/e.length;n-=o*Math.log2(o)}return n}function Cd(e){return e.replace(Ed,t=>{if(yd.test(t))return t;let n=/[A-Za-z]/.test(t),r=/\d/.test(t);return n&&r&&Rd(t)>=3.5?T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER:t})}var Id=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,Ad=/\b([a-z][a-z0-9+.-]*:\/\/)([^\s/@:]+):([^\s/@]*)@/gi,Od=/([?&](?:access_token|api_key|apikey|auth|authorization|client_secret|key|password|secret|token)=)[^&\s"'<>]+/gi,Pd=/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/,Ts=/-----END [A-Z0-9 ]*PRIVATE KEY-----/;function xs(e){return e.replace(gd,(t,n,r,o,s,i,a,c,l,u)=>{let p=`${n}${r}`;if(o!==void 0||a!==void 0){let d=o??a??"",g=i??l??"",_=s??c??"";return _===""||_.includes(T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER)||Hn(_)?t:`${p}${d}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}${g}`}let m=u??"";if(r==="="){let d=hd(m).replace(/`+$/,""),g=xs(m.slice(d.length));return d===""||d.includes(T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER)||Hn(d)?`${p}${d}${g}`:`${p}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}${g}`}return m.includes(T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER)||Hn(m)?t:`${p}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}`})}function Td(e){let t=e.replace(Ad,(n,r)=>`${r}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}:${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}@`);t=t.replace(Od,(n,r)=>`${r}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}`),t=t.replace(Id,(n,r)=>`${r}${T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}`);for(let n of Sd)t=t.replace(n,T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER);return xs(Cd(t))}function jn(e){if(e.length===0)return e;let t=e.split(`
|
|
11
|
+
`),n=!1;return t.map(o=>n?Ts.test(o)?(n=!1,o):o.trim().length===0?o:T.COMPONENT_SOURCE_REDACTION_PLACEHOLDER:Pd.test(o)&&!Ts.test(o)?(n=!0,o):Td(o)).join(`
|
|
12
|
+
`)}function kd(e){return jn(e)!==e}});var we=_e(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.redactComponentSource=f.prepareComponentInspectionText=f.fitSnapshotInspectionTextBudget=f.componentSourceContainsRedactableSecret=f.capComponentTextBytes=f.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=f.COMPONENT_SOURCE_REDACTION_PLACEHOLDER=f.COMPONENT_INSPECTION_TEXT_MAX_BYTES=f.usableCatalogText=f.parseFrontmatterField=f.parseFrontmatterDescription=f.isNpmRegistryPublisher=f.EMPTY_NPM_PUBLISHER=f.displayPublisherName=f.classifyMcpProvenance=f.resolveMcpPackageIdentity=f.McpPackageEcosystem=f.pinnedPackageVersionFromSpec=f.pinnedPackageVersionFromNpx=f.packageNameFromSpec=f.npxPackageSpecs=f.npxExecBin=f.PACKAGE_FIELD_MAX=f.serializeMcpLaunchIdentity=f.projectMcpMissingLaunchIdentity=f.projectMcpLaunchIdentity=f.normalizeMcpToolNames=f.MCP_MISSING_LAUNCH_SERIALIZED=f.MCP_LAUNCH_IDENTITY_ALGORITHM=f.maskMcpLaunchForDisplay=f.launchContainsCredentials=f.hashMcpLaunchIdentity=f.foldMcpName=f.buildMcpFamilyCanonicalKey=f.ComponentKind=void 0;f.userConfigRootFromPath=Fd;f.installationRootExternalKey=Hd;f.normalizeRepositoryRelativePath=Ns;f.nativeKeyForSkillPath=jd;f.nativeKeyForRulePath=$d;f.nativeKeyForCommandPath=Kd;f.serializeComponentIdentity=ws;f.buildComponentReference=Gd;f.validateComponentReference=zd;var xd=an("node:crypto"),bd=an("node:path"),Nd="cmp1_",Md=/^cmp1_[A-Za-z0-9_-]{43}$/,wd=["/skills/","/skills-cursor/"],vd=/(?:^|\/)\.(?:cursor|claude|codex)\/rules\/(.+)$/i,Ld=/(?:^|\/)\.(?:cursor|claude|codex)\/(?:commands|prompts)\/(.+)$/i,Ud=[".cursor",".claude",".codex"],Dd={".claude.json":".claude",".agents":".codex"};f.ComponentKind={SKILL:"SKILL",INTERFACE:"INTERFACE",RULE:"RULE",COMMAND:"COMMAND"};function Fd(e){let t=e.replaceAll("\\","/").split("/").filter(Boolean),n=t.find(o=>Ud.includes(o));return n||(t.map(o=>Dd[o]).find(o=>o!==void 0)??"unknown")}function Hd(e,t){return`runtime-install:${e}/${t}`}function Mt(e,t){if(e.length===0)throw new Error(`${t} is required`);return e}function Ns(e){let t=e.replaceAll("\\","/");if(t.startsWith("/")||/^[A-Za-z]:\//.test(t))throw new Error("sourcePath must be repository-relative");let n=bd.posix.normalize(t).replace(/^\.\//,"");if(n==="."||n===".."||n.startsWith("../"))throw new Error("sourcePath must be repository-relative");return Mt(n,"sourcePath")}function jd(e){let t=e.replaceAll("\\","/");for(let n of wd){let r=t.split(n)[1]?.split("/")[0];if(r&&r.length>0)return r}return null}function Ms(e,t,n){let r=e.replaceAll("\\","/"),s=t.exec(r)?.[1];if(!s||s.split("/").includes(".."))return null;let i=s.replace(n,"");return i.length>0?i:null}function $d(e){return Ms(e,vd,/\.(mdc|md|rules)$/i)}function Kd(e){return Ms(e,Ld,/\.(md|mdc|toml)$/i)}function Bd(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function ws(e){let t=[Mt(e.installationRootExternalKey,"installationRootExternalKey"),Mt(e.installableKind,"installableKind"),Ns(e.sourcePath),Mt(e.nativeKey,"nativeKey")];return Buffer.from(`1|${t.map(Bd).join("|")}`,"utf8")}function Gd(e){let t=(0,xd.createHash)("sha256").update(ws(e)).digest("base64url");return`${Nd}${t}`}function zd(e){return Md.test(e)}var J=xt();Object.defineProperty(f,"buildMcpFamilyCanonicalKey",{enumerable:!0,get:function(){return J.buildMcpFamilyCanonicalKey}});Object.defineProperty(f,"foldMcpName",{enumerable:!0,get:function(){return J.foldMcpName}});Object.defineProperty(f,"hashMcpLaunchIdentity",{enumerable:!0,get:function(){return J.hashMcpLaunchIdentity}});Object.defineProperty(f,"launchContainsCredentials",{enumerable:!0,get:function(){return J.launchContainsCredentials}});Object.defineProperty(f,"maskMcpLaunchForDisplay",{enumerable:!0,get:function(){return J.maskMcpLaunchForDisplay}});Object.defineProperty(f,"MCP_LAUNCH_IDENTITY_ALGORITHM",{enumerable:!0,get:function(){return J.MCP_LAUNCH_IDENTITY_ALGORITHM}});Object.defineProperty(f,"MCP_MISSING_LAUNCH_SERIALIZED",{enumerable:!0,get:function(){return J.MCP_MISSING_LAUNCH_SERIALIZED}});Object.defineProperty(f,"normalizeMcpToolNames",{enumerable:!0,get:function(){return J.normalizeMcpToolNames}});Object.defineProperty(f,"projectMcpLaunchIdentity",{enumerable:!0,get:function(){return J.projectMcpLaunchIdentity}});Object.defineProperty(f,"projectMcpMissingLaunchIdentity",{enumerable:!0,get:function(){return J.projectMcpMissingLaunchIdentity}});Object.defineProperty(f,"serializeMcpLaunchIdentity",{enumerable:!0,get:function(){return J.serializeMcpLaunchIdentity}});var Me=Nt();Object.defineProperty(f,"PACKAGE_FIELD_MAX",{enumerable:!0,get:function(){return Me.PACKAGE_FIELD_MAX}});Object.defineProperty(f,"npxExecBin",{enumerable:!0,get:function(){return Me.npxExecBin}});Object.defineProperty(f,"npxPackageSpecs",{enumerable:!0,get:function(){return Me.npxPackageSpecs}});Object.defineProperty(f,"packageNameFromSpec",{enumerable:!0,get:function(){return Me.packageNameFromSpec}});Object.defineProperty(f,"pinnedPackageVersionFromNpx",{enumerable:!0,get:function(){return Me.pinnedPackageVersionFromNpx}});Object.defineProperty(f,"pinnedPackageVersionFromSpec",{enumerable:!0,get:function(){return Me.pinnedPackageVersionFromSpec}});var vs=Es();Object.defineProperty(f,"McpPackageEcosystem",{enumerable:!0,get:function(){return vs.McpPackageEcosystem}});Object.defineProperty(f,"resolveMcpPackageIdentity",{enumerable:!0,get:function(){return vs.resolveMcpPackageIdentity}});var wt=Os();Object.defineProperty(f,"classifyMcpProvenance",{enumerable:!0,get:function(){return wt.classifyMcpProvenance}});Object.defineProperty(f,"displayPublisherName",{enumerable:!0,get:function(){return wt.displayPublisherName}});Object.defineProperty(f,"EMPTY_NPM_PUBLISHER",{enumerable:!0,get:function(){return wt.EMPTY_NPM_PUBLISHER}});Object.defineProperty(f,"isNpmRegistryPublisher",{enumerable:!0,get:function(){return wt.isNpmRegistryPublisher}});var $n=Ps();Object.defineProperty(f,"parseFrontmatterDescription",{enumerable:!0,get:function(){return $n.parseFrontmatterDescription}});Object.defineProperty(f,"parseFrontmatterField",{enumerable:!0,get:function(){return $n.parseFrontmatterField}});Object.defineProperty(f,"usableCatalogText",{enumerable:!0,get:function(){return $n.usableCatalogText}});var pe=bs();Object.defineProperty(f,"COMPONENT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return pe.COMPONENT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(f,"COMPONENT_SOURCE_REDACTION_PLACEHOLDER",{enumerable:!0,get:function(){return pe.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}});Object.defineProperty(f,"SNAPSHOT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return pe.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(f,"capComponentTextBytes",{enumerable:!0,get:function(){return pe.capComponentTextBytes}});Object.defineProperty(f,"componentSourceContainsRedactableSecret",{enumerable:!0,get:function(){return pe.componentSourceContainsRedactableSecret}});Object.defineProperty(f,"fitSnapshotInspectionTextBudget",{enumerable:!0,get:function(){return pe.fitSnapshotInspectionTextBudget}});Object.defineProperty(f,"prepareComponentInspectionText",{enumerable:!0,get:function(){return pe.prepareComponentInspectionText}});Object.defineProperty(f,"redactComponentSource",{enumerable:!0,get:function(){return pe.redactComponentSource}})});import{existsSync as Fc,readFileSync as Hc}from"node:fs";import{hostname as oo,userInfo as jc}from"node:os";import{createHash as bc,randomBytes as Nc}from"node:crypto";import{existsSync as un,mkdirSync as Mc,readdirSync as wc,readFileSync as vc,renameSync as Zr,statSync as eo,unlinkSync as qr,writeFileSync as Lc}from"node:fs";import{basename as Uc,dirname as Qr,join as to,relative as Dc}from"node:path";function h(e){process.stderr.write(`[ev-ai-agent-hook] ${e}
|
|
13
|
+
`)}function Be(e){return e.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1")}function Ge(e){return bc("sha256").update(e).digest("hex").slice(0,32)}function X(e,t){Mc(Qr(e),{recursive:!0});let n=to(Qr(e),`.${Uc(e)}.${process.pid}.${Nc(4).toString("hex")}.tmp`);try{Lc(n,t,"utf8");try{Zr(n,e)}catch(r){let o=r instanceof Error&&"code"in r?r.code:void 0;if(o==="EEXIST"||o==="EPERM"||o==="EACCES"){qr(e),Zr(n,e);return}throw r}}catch(r){try{qr(n)}catch{}throw r}}function mt(){return new Date().toISOString().replace(/\.\d{3}Z$/,"Z")}function no(){process.stdout.write('{"continue":true}')}function I(e){let t=process.env[e];return t===void 0||t===""?void 0:t}async function ln(){return new Promise(e=>{let t="";if(process.stdin.isTTY){e("");return}process.stdin.setEncoding("utf8"),process.stdin.on("data",n=>{t+=n}),process.stdin.on("end",()=>{e(t)}),process.stdin.on("error",()=>{e(t)}),process.stdin.resume()})}async function dn(e){return new Promise(t=>{let n="",r=!1,o=i=>{r||(r=!0,clearTimeout(s),t(i||"{}"))},s=setTimeout(()=>{o(n)},e);if(process.stdin.isTTY){o("{}");return}process.stdin.setEncoding("utf8"),process.stdin.on("data",i=>{n+=i}),process.stdin.on("end",()=>{o(n)}),process.stdin.on("error",()=>{o(n)}),process.stdin.resume()})}async function W(e,t,n=3e3,r={}){let{execFile:o}=await import("node:child_process"),{promisify:s}=await import("node:util"),i=s(o);try{let{stdout:a}=await i(e,t,{timeout:n,windowsHide:!0,maxBuffer:1048576,cwd:r.cwd});return{ok:!0,stdout:a.trim()}}catch(a){let c=a,l=typeof c.code=="number"?c.code:typeof c.status=="number"?c.status:void 0;return{ok:!1,code:l,spawnFailed:l===void 0}}}async function M(e,t,n=3e3,r={}){let o=await W(e,t,n,r);return o.ok?o.stdout:""}async function pn(e=process.cwd()){let t=await W("git",["rev-parse","--show-toplevel"],2e3,{cwd:e});if(t.ok&&t.stdout)return{root:t.stdout,inGitRepo:!0};if(I("EV_AI_HOOK_DEBUG")){let r=t.ok?"empty stdout":t.spawnFailed?"spawn failed":`exit ${String(t.code??"unknown")}`;h(`DEBUG: git rev-parse --show-toplevel failed (${r}) cwd=${e}`)}let n=I("CURSOR_PROJECT_DIR")??I("CLAUDE_PROJECT_DIR");if(n&&un(n)){let r=await W("git",["rev-parse","--show-toplevel"],2e3,{cwd:n});return r.ok&&r.stdout?{root:r.stdout,inGitRepo:!0}:{root:n,inGitRepo:!1}}return{root:e,inGitRepo:!1}}async function fn(e=process.cwd()){return(await pn(e)).root}function K(e,t){try{return JSON.parse(e)}catch{return t}}var cn=new Map;function L(e,t){let n=cn.get(e);if(n!==void 0)return n;try{let r=K(vc(e,"utf8"),t);return cn.set(e,r),r}catch{return cn.set(e,t),t}}function he(e){return typeof e=="string"?e:""}function te(e,t){let n=e[t];if(typeof n=="string"||typeof n=="number"||typeof n=="boolean")return n;if(!t.includes("."))return;let r=t.split("."),o=e;for(let s of r){if(o===null||typeof o!="object"||Array.isArray(o))return;o=o[s]}if(typeof o=="string"||typeof o=="number"||typeof o=="boolean")return o}function R(e,t){let n=te(e,t);return typeof n=="string"?n:""}var ae=500;function ro(e,t=2){if(!un(e))return{entries:[],truncated:!1};let n=[],r=!1,o=(s,i)=>{if(i>t||r)return;let a;try{a=wc(s,{withFileTypes:!0})}catch{return}for(let c of a){if(r)return;let l=to(s,c.name);if(c.isDirectory()){o(l,i+1);continue}if(c.isFile()){try{n.push({name:Dc(e,l),size:eo(l).size})}catch{continue}if(n.length>=ae){r=!0;return}}}};return o(e,1),{entries:n,truncated:r}}function mn(e){return un(e)?{present:!0,size:eo(e).size}:{present:!1,size:0}}function Te(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function so(e=process.env){return Te(b("CURSOR_SANDBOX",e))}var $c=["CIRCLECI","BUILDKITE","TF_BUILD","JENKINS_URL","JENKINS_HOME","CODEBUILD_BUILD_ID","DRONE","DRONE_BUILD_NUMBER","TEAMCITY_VERSION","TRAVIS","APPVEYOR","BITBUCKET_BUILD_NUMBER"];function Kc(e){return $c.some(t=>!!b(t,e))}function Bc(e){if(b("KUBERNETES_SERVICE_HOST",e)||Te(b("REMOTE_CONTAINERS",e))||Te(b("DEVCONTAINER",e)))return!0;try{if(Fc("/.dockerenv")||Hc("/proc/1/environ","utf8").includes("container="))return!0}catch{}return!1}function io(e){return["VSCODE_PID","VSCODE_IPC_HOOK","CURSOR_EXTENSION_HOST_ROLE","CURSOR_WORKSPACE_LABEL"].some(t=>!!b(t,e))}function Gc(e,t=process.platform){return io(e)?t==="darwin"||t==="win32"?!0:["__CFBundleIdentifier","DISPLAY","WAYLAND_DISPLAY","SESSIONNAME"].some(n=>!!b(n,e)):!1}function zc(e){return e===void 0?!1:e.trim().toLowerCase().startsWith("bc-")}function Vc(e){return e==="linux"}function b(e,t){if(t){let n=t[e];return n===void 0||n===""?void 0:n}return I(e)}function Wc(e,t,n){return e.trim().toLowerCase()==="cursor"&&t.trim().toLowerCase()==="ubuntu"&&!!Yc(b("CURSOR_VERSION",n))}function Yc(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function gn(e){if(zc(e.sessionId))return!0;let t=e.hostname??oo(),n=e.osUser??co(e.env);return Wc(t,n,e.env)}function Jc(e){return Te(b("CURSOR_AGENT",e.env))?!0:gn(e)}function Xc(e){return!!(process.stdin.isTTY||process.stdout.isTTY||(b("TERM",e)??b("TERM_PROGRAM",e))||(b("SSH_TTY",e)??b("SSH_CONNECTION",e))||(b("__CFBundleIdentifier",e)??b("XPC_SERVICE_NAME",e))||io(e)||["DISPLAY","WAYLAND_DISPLAY","XDG_SESSION_TYPE","DBUS_SESSION_BUS_ADDRESS"].some(t=>!!b(t,e))||b("SESSIONNAME",e))}function ze(e={}){let t=e.env;if(b("GITHUB_ACTIONS",t))return"github_actions";if(Te(b("CLAUDE_CODE_REMOTE",t)))return"claude_remote";let n=e.platform??process.platform;if(!Gc(t,n)&&Jc(e)&&(Te(b("CURSOR_AGENT",t))||Vc(n)))return"cursor_cloud";if(b("CODESPACES",t)||b("CODESPACE_NAME",t))return"codespaces";if(b("GITLAB_CI",t))return"gitlab_ci";if(Kc(t))return"managed";let r=b("CI",t);return r&&r!=="false"&&r!=="0"?"managed":Bc(t)?"container":Xc(t)?"interactive":"unknown"}async function ao(){return await M("systemd-detect-virt",[],1e3)}function co(e=process.env,t=jc){for(let n of["USER","LOGNAME","USERNAME"]){let r=e[n];if(typeof r=="string"){let o=r.trim();if(o.length>0)return o}}try{return t().username??""}catch{return""}}async function uo(){let e=process.platform==="darwin"?"Darwin":process.platform==="win32"?"Windows_NT":"Linux",t="";if(process.platform==="darwin")t=await M("sw_vers",["-productVersion"],1e3);else if(process.platform==="linux"){try{let{readFileSync:s}=await import("node:fs"),i=s("/etc/os-release","utf8"),a=i.match(/^PRETTY_NAME="?([^"\n]+)"?/m)?.[1],c=i.match(/^VERSION_ID="?([^"\n]+)"?/m)?.[1];t=a??c??""}catch{t=await M("lsb_release",["-sd"],1e3).then(s=>s.replace(/^"|"$/g,""))}t||(t=await M("uname",["-r"],1e3))}else t=await M("ver",[],1e3);let n=co(),r=(process.env.SHELL??"").split(/[/\\]/).pop()??"",o="";try{o=await M("tty",[],500),o.includes("not a tty")&&(o="")}catch{o=""}return{os:e,os_version:t||null,user:n||null,shell:r||null,tty:o||null}}function gt(){return oo()}import{createHash as Zc}from"node:crypto";import{homedir as qc}from"node:os";import{dirname as hh,join as Qc,parse as Sh,resolve as Eh}from"node:path";var po="https://hooks.ev-ai.ai",fo=".claude/ev-ai-runtime-report.json",mo="config.json",yh=1024*1024,eu=new Set(["localhost","127.0.0.1","[::1]","::1"]),tu=["claude","cursor","codex"],go=[fo,".cursor/ev-ai-runtime-report.json",".codex/ev-ai-runtime-report.json"],_n=/^[A-Za-z0-9._~-]+$/;function ht(e){return e!==void 0&&tu.includes(e)}function _t(e,t){let n=e[t+1];return n&&!n.startsWith("--")?{value:n,next:t+1}:{next:t}}function hn(e){let t,n,r,o,s;for(let i=0;i<e.length;i++){let a=e[i];if(a!==void 0){if(a==="--runner"){let c=_t(e,i);t=c.value,i=c.next;continue}if(a.startsWith("--runner=")){t=a.slice(9);continue}if(a==="--url"){let c=_t(e,i);c.value&&(r=c.value),i=c.next;continue}if(a.startsWith("--url=")){r=a.slice(6);continue}if(a==="--token"){let c=_t(e,i);c.value&&(o=c.value),i=c.next;continue}if(a.startsWith("--token=")){o=a.slice(8);continue}if(a==="--base-url"){let c=_t(e,i);c.value&&(s=c.value),i=c.next;continue}if(a.startsWith("--base-url=")){s=a.slice(11);continue}!a.startsWith("-")&&n===void 0&&(n=a)}}return{runner:ht(t)?t:void 0,event:n,collectorUrl:r,orgToken:o,baseUrl:s}}function St(e,t=po){let n=t.replace(/\/+$/,""),r=e.trim();return`${n}/${r}/hook`}function Sn(e=qc()){return Qc(e,".ev-ai",mo)}function _o(e,t){return{...e,...t}}function lo(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<=32||n===127||n===39)return!0}return!1}function Et(e){try{let t=new URL(e);return t.protocol==="https:"?!0:t.protocol==="http:"?eu.has(t.hostname):!1}catch{return!1}}function En(e){try{let n=new URL(e).pathname.split("/").filter(r=>r.length>0);if(n.length>=2&&n[n.length-1]==="hook"){let r=n[n.length-2];return r&&r.length>0?r:void 0}return}catch{return}}function yn(e){let t;try{t=new URL(e)}catch{return`invalid URL (got: ${e})`}if(!Et(e))return`must be https (or http on localhost / 127.0.0.1 / ::1) (got: ${e})`;let n=En(e);if(!n)return`must end with /{orgToken}/hook (got: ${e})`;if(!_n.test(n))return`org token must match ${_n.source} (got: ${n})`;if(lo(e))return`must not contain whitespace, control characters, or single quotes (got: ${e})`;if(lo(t.pathname))return`pathname must not contain whitespace, control characters, or single quotes (got: ${e})`}function ho(e){return new URL(e).toString()}function Rn(e){if(e.collector_url)return e.collector_url;let t=e.repo_ingest_token,n=typeof t=="string"?t.trim():void 0;return n?St(n):""}function yt(e){try{let t=new URL(e),n=t.pathname.split("/").filter(r=>r.length>0);return n.length>=2&&n[n.length-1]==="hook"&&(n[n.length-2]="***",t.pathname=`/${n.join("/")}`),t.toString()}catch{return"<invalid-url>"}}function So(e){let t=e.collectorUrl?.trim(),n;if(t)n=t;else{let o=e.orgToken?.trim();o&&(n=St(o,e.baseUrl?.trim()??void 0))}if(!n)return{};let r=yn(n);return r?{problem:r}:{url:ho(n)}}function Eo(e){if(yn(e))return;let t;try{t=new URL(e)}catch{return}let n=En(e);if(!n)return;let o=t.pathname.split("/").filter(a=>a.length>0).slice(0,-2),s=o.length>0?`/${o.join("/")}`:"",i=`${t.origin}${s}/${n}`;return Zc("sha256").update(i).digest("hex").slice(0,32)}var Ct=2;var Rt="ev-ai-agent-hook";function nu(e){let t=e.split(/[/\\]/).pop();return t&&t.length>0?t:e}function yo(e){let t=nu(e);return t===Rt||t===`${Rt}.exe`}var Ch=`current/${Rt}`,Ih=`.ev-ai/agent-hook/${Rt}`,Ro=5e3,Co=5e3,Cn=3e3;var In=3e3,Io=1500,Ao=4*1024,An=256*1024,ru=4*1024,Oo=32*1024,Ve=840*60*1e3,On="1.2.5",Ah=`@ev-ai/agent-hook@${On}`;import{existsSync as Ip,mkdirSync as Ap,readdirSync as Op,readFileSync as Pp,unlinkSync as ii,writeFileSync as Tp}from"node:fs";import{homedir as ai}from"node:os";import{join as Zn}from"node:path";import{createHash as bo,randomBytes as iu}from"node:crypto";import{existsSync as No,mkdirSync as Pn,readFileSync as Mo,unlinkSync as wo,writeFileSync as vo}from"node:fs";import{homedir as Tn}from"node:os";import{dirname as It,join as kn,resolve as au}from"node:path";var ou=new Set(["action@github.com","noreply@github.com","noreply@anthropic.com","cursoragent@cursor.com"]),su=new Set(["github-actions","github actions","dependabot","renovate","cursoragent","cursor agent"]);function B(e,t){let n=(e??"").trim().toLowerCase(),r=(t??"").trim().toLowerCase();if(!n&&!r)return!1;if(n.includes("[bot]")||su.has(n)||r.includes("[bot]")||ou.has(r))return!0;if(r.endsWith("@users.noreply.github.com")){let o=r.slice(0,r.indexOf("@")),s=o.includes("+")?o.slice(o.indexOf("+")+1):o;if(s.endsWith("bot")||s.includes("[bot]"))return!0}return!1}var cu="installation.json",uu="cloud-bootstrap.lock",lu=6e4;function Lo(e,t,n){let r=`${e}:${t??""}`;return n?`${n}:${r}`:r}function ne(e=Tn()){return kn(e,".ev-ai","agent-hook")}function du(e=Tn()){return kn(ne(e),cu)}function Uo(e){return kn(It(e),uu)}function Do(){return iu(8).toString("hex")}function ke(e){return bo("sha256").update(e).digest("hex").slice(0,16)}function A(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Fo(e){return/^[A-Za-z0-9._-]{8,64}$/.test(e)}function pu(e=process.env){let t=A(e.EV_AI_HOOK_INSTALLATION_ID);if(t){if(!Fo(t)){h(`WARN: ignoring EV_AI_HOOK_INSTALLATION_ID (expected 8\u201364 chars [A-Za-z0-9._-], got length ${t.length})`);return}return t}}function Ho(e,t){return e&&Fo(e)?e:(e&&h(`WARN: ignoring installation id override (expected 8\u201364 chars [A-Za-z0-9._-], got length ${e.length})`),pu(t))}function fu(e){return/^[0-9a-f]{16}$/.test(e)}function mu(e=process.env){if(A(e.GITHUB_ACTIONS)){let t=A(e.GITHUB_REPOSITORY_ID)??A(e.GITHUB_REPOSITORY),n=A(e.GITHUB_ACTOR)??A(e.GITHUB_TRIGGERING_ACTOR)??A(e.GITHUB_USER);if(t&&n)return ke(`github_actions|${t}|${n}`)}if(A(e.CODESPACES)||A(e.CODESPACE_NAME)){let t=A(e.CODESPACE_NAME);if(t)return ke(`codespaces|${t}`);let n=A(e.GITHUB_REPOSITORY_ID)??A(e.GITHUB_REPOSITORY),r=A(e.GITHUB_USER)??A(e.GITHUB_ACTOR);if(n&&r)return ke(`codespaces|${n}|${r}`)}if(A(e.GITLAB_CI)){let t=A(e.CI_PROJECT_ID)??A(e.CI_PROJECT_PATH),n=A(e.GITLAB_USER_LOGIN)??A(e.GITLAB_USER_EMAIL)??A(e.GITLAB_USER_NAME);if(t&&n)return ke(`gitlab|${t}|${n}`)}return null}var gu="cursoragent@cursor.com";function _u(e){let t=A(e.CURSOR_USER_EMAIL);return!t||t.toLowerCase()===gu?null:t}function hu(e,t){return A(e.CURSOR_PROJECT_DIR)??A(e.CLAUDE_PROJECT_DIR)??t}function Su(e){return Be(e).replace(/\.git$/i,"").toLowerCase()}async function Eu(e){let t=await M("git",["config","--get","remote.origin.url"],2e3,{cwd:e});return t?Su(t):e}async function yu(e){let t=A(await M("git",["config","--local","--get","user.email"],2e3,{cwd:e})||void 0);if(t&&!B(null,t))return t;let n=A(await M("git",["log","-1","--format=%ae"],2e3,{cwd:e})||void 0);return n&&!B(null,n)?n:null}function Ru(e,t){let n=hu(e,t);return n?ke(`cursor_cloud|${n}|${_u(e)??""}`):null}async function Cu(e,t){let n=A(e.CLAUDE_PROJECT_DIR)??t;if(!n)return null;let r=await Eu(n),o=await yu(n);return ke(`claude_remote|${r}|${o??""}`)}function Po(e,t){let n=Ho(e,t);if(n)return n;let r=mu(t);return r||Do()}async function Iu(e){let n=await M("git",["config","--get","remote.origin.url"],2e3,{cwd:e})||au(e);return bo("sha256").update(n).digest("hex").slice(0,16)}function Au(e){if(!e||typeof e!="object"||Array.isArray(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&r.length>0&&(t[n]=r);return Object.keys(t).length>0?t:void 0}function Ou(e){try{let t=JSON.parse(e);if(typeof t.installation_id!="string"||t.installation_id.length===0)return;let n=Au(t.platform_agent_ids);return{installation_id:t.installation_id,...t.pinned===!0?{pinned:!0}:{},...n?{platform_agent_ids:n}:{},...typeof t.operator_identity_hash=="string"?{operator_identity_hash:t.operator_identity_hash}:{},...typeof t.operator_identity_sent_at=="string"?{operator_identity_sent_at:t.operator_identity_sent_at}:{}}}catch{return}}function Se(e){if(No(e))try{return Ou(Mo(e,"utf8"))}catch{}}function xn(e){return Se(e)}function jo(e,t,n){let r=Se(e);if(!r||r.operator_identity_hash===t&&r.operator_identity_sent_at===n)return;let o={...r,operator_identity_hash:t,operator_identity_sent_at:n};try{X(e,`${JSON.stringify(o,null,2)}
|
|
14
|
+
`)}catch(s){let i=s instanceof Error?s.message:String(s);h(`WARN: operator identity cache write failed open: ${i}`)}}function $o(e,t=Date.now()){if(!e)return!0;if(Se(e)?.operator_identity_hash)return!1;let n=Uo(e);try{if(No(n)){let r=Number.NaN;try{r=Number(Mo(n,"utf8").trim())}catch{}let o=t-r;if(Number.isFinite(o)&&o>=0&&o<lu)return!1;try{wo(n)}catch{}}}catch{}try{return Pn(It(n),{recursive:!0}),vo(n,`${t}
|
|
15
|
+
`,{encoding:"utf8",flag:"wx"}),!0}catch(r){if(zo(r))return!1;let o=r instanceof Error?r.message:String(r);return h(`WARN: cloud bootstrap claim failed open: ${o}`),!0}}function Ko(e){if(e)try{wo(Uo(e))}catch{}}function Bo(e,t){let r=Se(e)?.platform_agent_ids?.[t];return typeof r=="string"&&r.length>0?r:void 0}function Go(e,t,n){if(!n)return;let r=Se(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?{operator_identity_sent_at:r.operator_identity_sent_at}:{}};try{X(e,`${JSON.stringify(o,null,2)}
|
|
16
|
+
`)}catch(s){let i=s instanceof Error?s.message:String(s);h(`WARN: platform_agent_id cache write failed open: ${i}`)}}function zo(e){return e instanceof Error&&"code"in e&&e.code==="EEXIST"}function Pu(e,t){Pn(It(e),{recursive:!0}),vo(e,`${JSON.stringify(t,null,2)}
|
|
17
|
+
`,{encoding:"utf8",flag:"wx"})}function To(e,t){try{return Pu(e,t),t}catch(n){if(!zo(n))throw n;return Se(e)}}function ko(e,t){Pn(It(e),{recursive:!0}),X(e,`${JSON.stringify(t,null,2)}
|
|
18
|
+
`)}function xo(e,t){return{installation_id:e,...t&&t===e?{pinned:!0}:{}}}async function Vo(e,t={}){let n=t.home??Tn(),r=t.env??process.env,o=await Iu(e),s=du(n),i={sessionId:t.sessionId,hostname:A(r.HOSTNAME)??void 0,osUser:A(r.USER)??A(r.LOGNAME)??A(r.USERNAME)??void 0,env:r},a=ze(i),c=Ho(t.overrideId,r),l=a==="cursor_cloud"&&gn(i)?Ru(r,e):a==="claude_remote"?await Cu(r,e):null,u=Se(s);if(u){let _=u;if(c&&c===u.installation_id&&u.pinned!==!0&&(_={...u,pinned:!0},ko(s,_)),!!l&&l!==_.installation_id&&!c&&_.pinned!==!0&&fu(_.installation_id)&&l){let E={installation_id:l,..._.platform_agent_ids?{platform_agent_ids:_.platform_agent_ids}:{}};return ko(s,E),{installationId:l,storePath:s,repoKey:o}}return{installationId:_.installation_id,storePath:s,repoKey:o}}let p=c??l??Po(void 0,r),m=To(s,xo(p,c));if(m)return{installationId:m.installation_id,storePath:s,repoKey:o};let d=c??l??Po(void 0,r),g=To(s,xo(d===p?Do():d,c));if(g)return{installationId:g.installation_id,storePath:s,repoKey:o};throw new Error(`Failed to create installation record at ${s}`)}import{open as Wo,mkdir as Tu,readFile as ku,readdir as xu,rename as bu,stat as Nu,rmdir as Mu,unlink as wu,utimes as vu}from"node:fs/promises";var At=new WeakMap;function Jo(e){if(e&&typeof e=="object"&&"code"in e)return e}function bn(e){return Jo(e)?.code==="ENOENT"}function Xo(e){return Jo(e)?.code==="EEXIST"}async function Zo(e,t){try{return await e.readdir(t)}catch(n){if(bn(n))return[];throw n}}function qo(){return{async open(e,t){let n=await Wo(e,t),r={path:e};return At.set(r,n),r},async write(e,t){let n=Yo(e),r=typeof t=="string"?Buffer.from(t,"utf8"):t;await n.write(r)},async fsync(e){await Yo(e).sync()},async close(e){let t=At.get(e);At.delete(e),t&&await t.close()},rename:bu,async readdir(e){return xu(e)},readFile:ku,async stat(e){let t=await Nu(e);return{mtimeMs:t.mtimeMs,size:t.size,isDirectory:()=>t.isDirectory()}},async mkdir(e,t){await Tu(e,t)},unlink:wu,rmdir:Mu,utimes:vu,async fsyncDir(e){if(process.platform==="win32")return;let t=await Wo(e,"r");try{await t.sync()}finally{await t.close()}}}}function Yo(e){let t=At.get(e);if(!t)throw new Error("closed");return t}import{existsSync as Zu}from"node:fs";import{existsSync as $u}from"node:fs";import{homedir as ts}from"node:os";import{join as Ku}from"node:path";import{existsSync as Lu,readdirSync as Qo}from"node:fs";import{homedir as Ot}from"node:os";import{join as j}from"node:path";function Uu(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/ClaudeCode";case"win32":return j(process.env.ProgramFiles??"C:\\Program Files","ClaudeCode");default:return"/etc/claude-code"}}function Du(e=process.platform){let t=Uu(e),n=[j(t,"managed-settings.json")],r=j(t,"managed-settings.d");try{if(!Lu(r))return n;let o=Qo(r).filter(s=>s.endsWith(".json")&&!s.startsWith(".")).sort().map(s=>j(r,s));n.push(...o)}catch{}return n}function Nn(e=process.platform,t=Ot()){return{serverManaged:j(t,".claude","remote-settings.json"),fileBased:Du(e)}}function Fu(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/Cursor";case"win32":return j(process.env.ProgramData??"C:\\ProgramData","Cursor");default:return"/etc/cursor"}}function Hu(e=process.platform,t=Ot()){let n=[j(Fu(e),"hooks.json")],r=j(t,".cursor","managed");try{for(let o of Qo(r,{withFileTypes:!0}))!o.isDirectory()||o.name.startsWith(".")||n.push(j(r,o.name,"hooks.json"))}catch{}return n}function ju(e=process.platform,t=Ot()){let n=e==="win32"?j(process.env.ProgramData??"C:\\ProgramData","OpenAI","Codex"):"/etc/codex",r=[j(n,"requirements.toml")];return e!=="win32"&&r.push(j(n,"managed_config.toml")),r.push(j(t,".codex","managed_config.toml"),j(n,"config.toml")),r}function Pt(e,t=process.platform,n=Ot()){switch(e){case"claude":{let{serverManaged:r,fileBased:o}=Nn(t,n);return[r,...o]}case"cursor":return Hu(t,n);default:return ju(t,n)}}function ns(e){return e.settings.filter(t=>t.toLowerCase().endsWith(".json"))}var Bu={claude:{shared:{skillRoots:[".claude/skills"],dirs:[{dir:".claude/agents",kind:"SUBAGENT",extensions:[".md"]},{dir:".claude/commands",kind:"COMMAND",extensions:[".md"]},{dir:".claude/rules",kind:"RULE",extensions:[".mdc",".md"]}],memory:[["CLAUDE.md"],["CLAUDE.local.md"],[".claude/CLAUDE.md"]],settings:[".claude/settings.json",".claude/settings.local.json",".claude/hooks.json"]},homeOnly:{mcpJson:[".claude.json"],plugins:"claude",managed:"claude"},projectOnly:{mcpJson:[".mcp.json","mcp.json"]}},cursor:{shared:{skillRoots:[".cursor/skills"],dirs:[{dir:".cursor/agents",kind:"SUBAGENT",extensions:[".md"]},{dir:".cursor/commands",kind:"COMMAND",extensions:[".md"]},{dir:".cursor/rules",kind:"RULE",extensions:[".mdc",".md"]}],memory:[["AGENTS.md"]],settings:[".cursor/hooks.json",".cursor/cli-config.json"],mcpJson:[".cursor/mcp.json"]},homeOnly:{skillRoots:[".cursor/skills-cursor"],memory:[[".cursor/AGENTS.md"]],plugins:"cursor",managed:"cursor"},projectOnly:{skillRoots:[".agents/skills"]}},codex:{shared:{skillRoots:[".agents/skills",".codex/skills"],dirs:[{dir:".codex/agents",kind:"SUBAGENT",extensions:[".toml",".md"]},{dir:".codex/prompts",kind:"COMMAND",extensions:[".md"]},{dir:".codex/rules",kind:"RULE",extensions:[".md",".rules"]}],memory:[["AGENTS.override.md","AGENTS.md"]],settings:[".codex/hooks.json",".codex/config.toml"],mcpToml:[".codex/config.toml"]},homeOnly:{memory:[[".codex/AGENTS.override.md",".codex/AGENTS.md"]],managed:"codex"}}};function es(e,t){if(!(!e&&!t))return[...e??[],...t??[]]}function Gu(e,t={}){let{shared:n}=e;return{skillRoots:[...n.skillRoots,...t.skillRoots??[]],dirs:n.dirs,memory:[...n.memory,...t.memory??[]],settings:[...n.settings,...t.settings??[]],mcpJson:es(n.mcpJson,t.mcpJson),mcpToml:es(n.mcpToml,t.mcpToml),plugins:t.plugins??n.plugins,managed:t.managed??n.managed}}function rs(e){return Object.fromEntries(Object.entries(Bu).map(([t,n])=>[t,Gu(n,n[e])]))}var xe=rs("homeOnly"),ue=rs("projectOnly");function zu(e){return[...e.skillRoots,...e.dirs.map(t=>t.dir),...e.memory.flat(),...e.settings,...e.mcpJson??[],...e.mcpToml??[]]}function Vu(e,t){return zu(e).some(n=>$u(Ku(t,n)))}function os(e,t){for(let n of e)if(Vu(n,t))return!0;return!1}function ce(e){return[...new Set(e)]}function le(e){let t=[],n=[],r=[],o=[],s=[],i=[],a=[];for(let c of e){t.push(...c.skillRoots);for(let l of c.dirs)l.kind==="SUBAGENT"?n.push(l.dir):l.kind==="COMMAND"?r.push(l.dir):o.push(l.dir);s.push(...c.memory.flat()),i.push(...c.settings),a.push(...c.mcpJson??[],...c.mcpToml??[])}return{skills:ce(t),subagents:ce(n),commands:ce(r),rules:ce(o),memory:ce(s),settings:ce(i),mcp:ce(a)}}function Wu(e,t=ts(),n=process.platform){let r=[];for(let o of e)o.managed&&r.push(...Pt(o.managed,n,t));return ce(r)}var de=le(Object.values(xe));function ss(e=ts(),t=process.platform){return Wu(Object.values(xe),e,t)}import{existsSync as Yu}from"node:fs";import{resolve as Mn}from"node:path";function G(e){return Mn(e).replaceAll("\\","/").replace(/\/$/,"")}function Ee(e,t){let n=new Set(t),r=[];for(let o of e)n.delete(o)&&r.push(o);for(let o of[...n].sort())r.push(o);return r}function Tt(e,t){if(!e)return t;let n=`${e}/`,r=[],o=[];for(let s of t)s===e||s.startsWith(n)?r.push(s):o.push(s);return r.length===0?t:[...r,...o]}var Ju=/^(?!\.)[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;function We(e){let t=e.replaceAll("\\","/").replace(/^\.\//,"");return!t||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.split("/").includes("..")||!Ju.test(t)?null:t}function be(e,t){let n=new Set,r=[];for(let o of[e,t]){if(!o)continue;let s=G(o);n.has(s)||(n.add(s),r.push(s))}return r}function Xu(e,t){let n=`${e}/`;return t===e||t.startsWith(n)}function Z(e,t,n,r=Yu){for(let o of e)for(let s of t){let i=G(Mn(o,s)),a=Mn(o,s,n).replaceAll("\\","/");if(Xu(i,a)&&r(a))return a}return null}var as=/(?:^|\/|[\s"'=(])(?:\.cursor\/|\.claude\/|\.agents\/)skills(?:-cursor)?\/([^/]+)\/SKILL\.md/i,cs=/(?:^|\/|[\s"'=(])\.codex\/commands\/([^/]+)\.md\b/i,qu=/(?:^|\s)\/([a-z][a-z0-9-]{1,63}(?:\/[a-z][a-z0-9-]{1,63}){0,5})\b/gi,is=new Set(["applications","app","bin","boot","data","dev","etc","home","lib","media","mnt","node_modules","opt","pkg","private","proc","projects","repos","run","sbin","src","srv","sys","tmp","usr","users","var","volumes","workspace","workspaces"]),Qu=/^[a-z][a-z0-9-]{1,63}$/,el=[".cursor/skills",".claude/skills",".agents/skills"],tl=[".cursor/skills",".cursor/skills-cursor",".claude/skills",".agents/skills"],nl=Ee(el,le(Object.values(ue)).skills),rl=Ee(tl,le(Object.values(xe)).skills),ol=new Set(["read","read_file","view"]),sl=new Set(["bash","shell","zsh"]);function wn(e){let t=e.replace(/\\/g,"/");return as.exec(t)?.[1]??null}function il(e){let t=e.replace(/\\/g,"/"),r=cs.exec(t)?.[1];return r?r.toLowerCase():null}function al(e){return wn(e)??il(e)}function cl(e){for(let t of["path","file_path","target_file"]){let n=e[t];if(typeof n=="string"&&n.length>0)return n}return null}function kt(e){return typeof e=="string"?kt(K(e,null)):!e||typeof e!="object"?null:cl(e)}function us(e){if(typeof e=="string")return us(K(e,null));if(!e||typeof e!="object")return null;let t=e.command;return typeof t=="string"&&t.length>0?t:null}function vn(e){let t=us(e.tool_input);if(t)return t;let n=he(e.command);return n.length>0?n:null}function ul(e){let t=e.replace(/\\/g,"/"),n=as.exec(t);if(n?.[1])return n[1];let o=cs.exec(t)?.[1];return o?o.toLowerCase():null}function ll(e){return typeof e.tool_name=="string"?e.tool_name:typeof e.tool=="string"?e.tool:""}function Ln(e){let t=kt(e.tool_input)??he(e.file_path);return t.length>0?t:null}function Ye(e,t,n){let r=ll(e).toLowerCase();if(ol.has(r)){let o=Ln(e);return o?t(o):null}if(sl.has(r)){let o=vn(e);return o?n(o):null}return null}function ls(e){return Ye(e,al,ul)}function dl(e){let t=new Set,n=[];for(let r of e.matchAll(qu)){let o=r[1]?.toLowerCase();!o||t.has(o)||pl(o)||(t.add(o),n.push(o))}return n}function pl(e){let t=e.split("/")[0];return is.has(e)||t!==void 0&&is.has(t)}function ds(e){let t=e.skillId.toLowerCase();if(!Qu.test(t))return null;let n=e.exists??Zu,r=`${t}/SKILL.md`,o=Z(be(e.launchCwd,e.gitRoot),nl,r,n);return o!==null?o:e.home?Z([G(e.home)],rl,r,n):null}function fl(e){return he(e.prompt)}function ps(e){let t=R(e,"command_name");if(t){let r=R(e,"expansion_type");if(r&&r!=="slash_command")return[];let o=t.replace(/^\//,"").toLowerCase();return o?[o]:[]}let n=fl(e);return n?dl(n):[]}var Kn=Ke(we(),1);import{existsSync as Wd}from"node:fs";var Re={claude:".claude",cursor:".cursor",codex:".codex",opencode:".opencode"};function Xe(e){let n=e.replace(/^\/+|\/+$/g,"").toLowerCase().split("/").filter(Boolean);return n.length<2?"":n.join("/")}function Vd(e){if(!e)return"";let t=Be(e).replace(/\.git$/i,""),n=t.match(/^git@[^:]+:(.+)$/);if(n?.[1])return Xe(n[1]);let r=t.match(/^ssh:\/\/[^/]+\/(.+)$/i);if(r?.[1])return Xe(r[1]);t=t.replace(/^https:\/\//i,""),t=t.replace(/^http:\/\//i,""),t=t.replace(/^ssh:\/\//i,"");let o=t.match(/^[^/]+\/(.+)$/);return o?.[1]?Xe(o[1]):Xe(t)}async function vt(e=process.cwd()){let t=await W("git",["rev-parse","--is-inside-work-tree"],2e3,{cwd:e});if(!t.ok||t.stdout!=="true")return null;let[n,r,o,s]=await Promise.all([W("git",["remote","get-url","origin"],2e3,{cwd:e}),W("git",["branch","--show-current"],2e3,{cwd:e}),W("git",["rev-parse","HEAD"],2e3,{cwd:e}),W("git",["status","--porcelain"],2e3,{cwd:e})]);return{remote:n.ok?Be(n.stdout):null,branch:r.ok?r.stdout:null,head:o.ok?o.stdout:null,dirty:s.ok?s.stdout.length>0:null}}async function Ls(e,t,n,r=process.cwd(),o,s,i){if(t)return t;let a=Re[n];if(!a)return"";let c=Lo(n,e.scope_path,i);if(s){let g=Bo(s,c);if(g)return g}let l=o??await vt(r),u=l?.remote?Vd(l.remote):"";if(u||(u=Xe(process.env.GITHUB_REPOSITORY??"")),!u)return"";let p=e.scope_path??"",m=p?`${p}/`:"",d=`${u}:${m}${a}`;return s&&Go(s,c,d),d}var Yd=[".cursor/rules",".claude/rules",".codex/rules"],Jd=le(Object.values(ue)).rules;function Xd(e){return Ee(Tt(e?Re[e]:void 0,Yd),Jd)}var Zd=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/rules\/[^'"\s]+?\.(?:mdc|md|rules))\b/i;function Us(e){let t=We(e.relativePath);if(!t)return null;let n=e.exists??Wd,r=be(e.launchCwd,e.gitRoot),o=Xd(e.runnerPlatform),s=Z(r,o,t,n);if(s!==null)return s;if(!t.includes("/")){let i=Z(r,["."],t,n);if(i!==null)return i}return e.home?Z([G(e.home)],o,t,n):null}function qd(e){let t=e.replace(/\\/g,"/"),r=Zd.exec(t)?.[1];return r?(0,Kn.nativeKeyForRulePath)(r):null}function Ds(e){return Ye(e,Kn.nativeKeyForRulePath,qd)}function Fs(e){return e.replace(/\.(mdc|md|rules)$/i,"")}function Hs(e){let t=e.attachments;if(!Array.isArray(t))return[];let n=new Set,r=[];for(let o of t){if(!o||typeof o!="object"||Array.isArray(o))continue;let s=o;if(s.type!=="rule")continue;let i=typeof s.file_path=="string"?s.file_path:"",a=We(i);!a||n.has(a)||(n.add(a),r.push(a))}return r}var Bn=Ke(we(),1);import{existsSync as Qd}from"node:fs";var ep=[".cursor/commands",".claude/commands",".codex/prompts"],tp=le(Object.values(ue)).commands;function np(e){return Ee(Tt(e?Re[e]:void 0,ep),tp)}var rp=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/(?:commands|prompts)\/[^'"\s]+?\.(?:md|mdc))\b/i;function js(e){let t=We(e.commandId);if(!t)return null;let n=e.exists??Qd,r=`${t}.md`,o=np(e.runnerPlatform),s=Z(be(e.launchCwd,e.gitRoot),o,r,n);return s!==null?s:e.home?Z([G(e.home)],o,r,n):null}function op(e){let t=e.replace(/\\/g,"/"),r=rp.exec(t)?.[1];return r?(0,Bn.nativeKeyForCommandPath)(r):null}function $s(e){return Ye(e,Bn.nativeKeyForCommandPath,op)}import{existsSync as Bs}from"node:fs";import{homedir as Gs}from"node:os";import{join as Ze,resolve as Gn,sep as Ks}from"node:path";function zn(e){return[...new Set([e,e.replaceAll(/[^A-Za-z0-9_-]/g,"_"),e.replaceAll(/[^A-Za-z0-9_-]+/g,"_")])]}function Vn(e,t){let n=t.toLowerCase();return zn(e).some(r=>r.toLowerCase()===n)}function Lt(e,t,n){if(!Bs(e))return;let r=L(e,{});for(let[o,s]of Object.entries(r.mcpServers??{}))n.set(o,{declared:{name:o,...t},config:s})}function sp(e,t,n){if(!Bs(e))return;let r=L(e,{}),o=Gn(t),s=null;for(let a of Object.keys(r.projects??{})){let c=Gn(a);(o===c||o.startsWith(c.endsWith(Ks)?c:c+Ks))&&(s===null||c.length>Gn(s).length)&&(s=a)}if(s===null)return;let i=r.projects?.[s]?.mcpServers??{};for(let[a,c]of Object.entries(i))n.set(a,{declared:{name:a,source:"claude_json_project",sourcePath:".claude.json",scope:"user"},config:c})}function zs(e,t,n,r){let o=new Map;for(let s of e.mcp_servers??[])s.name&&o.set(s.name,{declared:{name:s.name,source:"manifest"}});return n==="claude"?(Lt(Ze(r,".claude.json"),{source:"claude_json_user"},o),sp(Ze(r,".claude.json"),t,o)):n==="cursor"&&Lt(Ze(r,".cursor/mcp.json"),{source:"cursor_mcp_user"},o),Lt(Ze(t,".mcp.json"),{source:"mcp_json"},o),Lt(Ze(t,".cursor/mcp.json"),{source:"cursor_mcp"},o),o}async function Wn(e,t=process.cwd(),n="claude",r=Gs()){return[...zs(e,t,n,r).values()].map(o=>o.declared)}function Vs(e,t,n=process.cwd(),r="claude",o=Gs()){let s=zs(t,n,r,o),i=s.get(e);if(i!==void 0)return i.config??null;for(let[a,c]of s)if(Vn(a,e))return c.config??null;return null}function Yn(e){let t=So(e);if(t.problem){h(`WARN: ignoring --url/--token collector override: ${t.problem}`);return}return t.url}function Ws(e,t){if(R(e,"conversation_id"))return!0;if(t==="")return!1;let n=t[0];return n?.toLowerCase()===n}function ip(){return!!(I("CURSOR_VERSION")??I("CURSOR_PROJECT_DIR"))}function Ys(e,t,n){return e!=="claude"&&e!=="codex"?!1:Ws(t,n)?!0:ip()}var ap=new Set(["sessionstart","sessionend","stop","stopfailure","pretooluse","posttooluse","posttoolusefailure","permissiondenied","subagentstart","subagentstop","userpromptexpansion","userpromptsubmit"]);function qe(e,t,n,r){return Ws(e,t)?"cursor":ht(r)?r:ht(n)?n:R(e,"turn_id")?"codex":R(e,"session_id")||ap.has(t.toLowerCase())?"claude":"unknown"}function Ut(e,t){let n=e.toLowerCase();return n==="sessionend"||n==="stopfailure"||n==="subagentstop"?!0:n==="stop"&&t==="codex"}function cp(e){switch(e){case"sessionstart":return"session_start";case"stop":case"sessionend":case"stopfailure":return"session_end";case"pretooluse":case"posttooluse":case"posttoolusefailure":case"permissiondenied":case"beforemcpexecution":case"beforeshellexecution":case"aftershellexecution":case"beforereadfile":case"afterfileedit":case"subagentstart":case"subagentstop":return"tool_invoked";case"beforesubmitprompt":case"userpromptexpansion":case"userpromptsubmit":return"skill_invoked";default:return""}}function Js(e){let t=e.toLowerCase();return t==="userpromptsubmit"||t==="beforesubmitprompt"}function Xs(e,t){return e.toLowerCase()==="userpromptsubmit"&&t==="claude"}function Zs(e){let t=e.toLowerCase();return t==="posttooluse"?!0:t==="posttoolusefailure"||t==="permissiondenied"?!1:null}function Qe(e){return R(e,"session_id")||R(e,"conversation_id")}function Jn(e){return R(e,"prompt.id")||R(e,"prompt_id")||R(e,"generation_id")||R(e,"turn_id")}function Xn(e){return R(e,"hook_event_name")||R(e,"event")}function qs(e,t,n){let r=Qe(e),o=Jn(e),s=Xn(e),i=R(e,"source"),a=qe(e,s,t,n);return{sessionId:r,turnId:o,runnerEvent:s,hookSource:i,runnerPlatform:a}}var up=["session_start","session_end","tool_invoked","skill_invoked"];function lp(e){return up.includes(e)}function Qs(e,t){return e&&lp(e)?e:cp(t.toLowerCase())}var dp={beforeshellexecution:"Shell",aftershellexecution:"Shell",beforereadfile:"Read",afterfileedit:"Write"};function Dt(e){return/^mcp__/i.test(e)||/^MCP:/i.test(e)}function ei(e,t=""){let n=R(e,"tool_name")||R(e,"tool")||null,r=t.toLowerCase();n?r==="beforemcpexecution"&&!Dt(n)&&(n=`MCP:${n}`):n=dp[r]??null;let o=e.tool_input,i=(o&&typeof o=="object"?he(o.skill)||he(o.skill_name):"")||R(e,"skill_name")||null,a=n&&e.tool_name!==n&&e.tool!==n?{...e,tool_name:n}:e;i??=ls(a);let c=Ds(a),l=$s(a);return{toolName:n,skillName:i,ruleName:c,commandName:l}}var pp=/^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/;function ti(e){for(let t of["subagent_type","agent_type"]){let n=R(e,t);if(n&&pp.test(n))return n}return null}function ni(e){let t=te(e,"duration_ms");if(typeof t=="number")return t;let n=te(e,"duration");return typeof n=="number"?n:null}var fp="error",mp="interrupted",gp="permission_denied",_p=/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;function et(e){return _p.test(e)?e:null}function hp(e){for(let t of["failure_type","error_type"]){let n=et(R(e,t));if(n)return n}return null}function ri(e,t){return te(e,"is_interrupt")===!0?mp:t.toLowerCase()==="permissiondenied"?gp:hp(e)??fp}function oi(e,t){let n=null;for(let r of e)r&&t(r)&&(n===null||r.length>n.length)&&(n=r);return n}function Sp(e,t){return oi(t,n=>e===n||e.startsWith(`${n}_`)||e.startsWith(`${n}-`))}function Ep(e,t){return oi(t,n=>Vn(n,e))}function yp(e,t){let n=null,r=0;for(let s of t)if(s)for(let i of zn(s)){let a=`${i}__`;e.length>a.length&&e.slice(0,a.length).toLowerCase()===a.toLowerCase()&&i.length>r&&(n={mcpServer:s,mcpTool:e.slice(a.length)},r=i.length)}if(n!==null)return n;let o=/^(.+?)__(.+)$/.exec(e);return!o?.[1]||!o[2]?{mcpServer:null,mcpTool:null}:{mcpServer:Ep(o[1],t)??o[1],mcpTool:o[2]}}function Rp(e,t){if(/^mcp__/i.test(e))return yp(e.slice(5),t);if(/^MCP:/i.test(e)){let n=e.slice(4);if(!n)return{mcpServer:null,mcpTool:null};let r=n.indexOf(":");if(r>0)return{mcpServer:n.slice(0,r),mcpTool:n.slice(r+1)||null};let o=n.indexOf("__");return o>0?{mcpServer:n.slice(0,o),mcpTool:n.slice(o+2)||null}:{mcpServer:Sp(n,t),mcpTool:n}}return{mcpServer:null,mcpTool:null}}function Cp(e,t){let n=`${t}__`;return e.length>n.length&&e.toLowerCase().startsWith(n.toLowerCase())?e.slice(n.length):e}function si(e,t=[],n=""){let r=e?Rp(e,t):{mcpServer:null,mcpTool:null},o=et(n.trim());if(!o)return r;let s=r.mcpTool;return!s&&e&&!Dt(e)&&(s=e),s&&(s=Cp(s,o)),{mcpServer:o,mcpTool:s}}var ci=3e4,kp="claims",xp=!0,bp=100,Np=new Set(["sessionstart","sessionend","stopfailure"]),Mp=["tool_name","tool","command","file_path","url"];function wp(e=ai()){return Zn(ne(e),kp)}function ui(e,t){try{let n=Pp(e,"utf8").split(`
|
|
19
|
+
`,1)[0]??"";return t-Number(n.trim())}catch{return Number.NaN}}function vp(e){let t=[];for(let n of Mp){let r=R(e,n).trim();r&&t.push(`${n}=${r}`)}return t.length===0?"":Ge(t.join("\0"))}function Lp(e){let t=e.sessionId.trim();if(!t)return;let n=e.runnerEvent.trim().toLowerCase(),r=e.turnId.trim(),o=e.toolUseId.trim(),s=e.subagentId?.trim()??"",i=e.callFingerprint?.trim()??"",a=!!(o||r||s),c=Np.has(n);if(!a&&!c)return;let l=e.runnerPlatform.trim()||"unknown";return Ge(`${l}|${t}|${n}|${r}|${o}|${i}|${s}`)}function Up(e,t=Date.now()){let n;try{n=Op(e)}catch{return}let r=0;for(let o of n){if(r>=bp)break;r+=1;let s=Zn(e,o),i=ui(s,t);if(!(!Number.isFinite(i)||i<ci))try{ii(s)}catch{}}}function Dp(e,t,n=Date.now()){let r=Zn(t,e);try{if(Ip(r)){let o=ui(r,n);if(Number.isFinite(o)&&o>=0&&o<ci)return!1;try{ii(r)}catch{}}}catch{}try{Ap(t,{recursive:!0}),Tp(r,`${n}
|
|
20
|
+
`,{encoding:"utf8",flag:"wx"})}catch(o){if(Xo(o))return!1;let s=o instanceof Error?o.message:String(o);return h(`WARN: event claim failed open: ${s}`),!0}return Up(t,n),!0}function Fp(e,t,n){let r=Qe(e),o=Jn(e),s=R(e,"tool_use_id"),i=R(e,"subagent_id")||R(e,"agent_id"),a=qe(e,t,void 0,n),c=vp(e);return{runnerPlatform:a,sessionId:r,runnerEvent:t,turnId:o,toolUseId:s,subagentId:i,callFingerprint:c}}function li(e,t,n,r=ai(),o=Date.now()){if(!xp)return!0;let s=Lp(Fp(e,t,n));if(!s)return!0;let i=Dp(s,wp(r),o);return!i&&I("EV_AI_HOOK_DEBUG")&&h(`DEBUG: duplicate hook event suppressed (claim ${s.slice(0,8)}\u2026)`),i}import{closeSync as Hp,writeSync as jp}from"node:fs";var di="EV_AI_LAUNCHER_VERSION";var pi="EV_AI_HOOK_SOURCE",fi="EV_AI_HOOK_FALLBACK_REASON",mi="EV_AI_LAUNCHER_SCOPE",qn="EV_AI_LAUNCHER_READY_FD";var gi=Buffer.from([1]);var VS=1024*1024,WS=4*1024*1024,YS=64*1024,JS=64*1024,XS=64*1024;var Qn=4096,ZS=4*1024*1024;function _i(e=process.env){let t=e[qn];if(delete e[qn],t===void 0)return;let n=Number.parseInt(t,10);if(!(!Number.isInteger(n)||n<3)){try{jp(n,gi)}catch{}try{Hp(n)}catch{}}}function er(e=process.env){let t=e[di];if(t)return{launcherVersion:t,hookSource:e[pi]??"",fallbackReason:e[fi],launcherScope:e[mi]}}function hi(e,t){return(e?Eo(e):void 0)===t}import{realpathSync as __}from"node:fs";import{homedir as h_}from"node:os";var P=Ke(we(),1);import{existsSync as $p,readFileSync as Kp}from"node:fs";import{homedir as Si}from"node:os";import{join as Bp}from"node:path";var Gp="cloud-cache.json",zp=1440*60*1e3,Vp=900*1e3;function Wp(e=Si()){return Bp(ne(e),Gp)}function Yp(e){if(!$p(e))return;let t=K(Kp(e,"utf8"),{});if(!(typeof t.context!="string"||typeof t.probed_at!="number"||t.result!==null&&t.result!==void 0&&typeof t.result!="object"))return{context:t.context,probed_at:t.probed_at,result:t.result??null}}function Jp(e,t){try{X(e,`${JSON.stringify(t)}
|
|
21
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: cloud cache write failed open: ${r}`)}}function Xp(e,t,n){if(!e||e.context!==t)return!1;let r=e.result===null?Vp:zp;return n-e.probed_at<r}async function Zp(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,signal:AbortSignal.timeout(e)}).catch(()=>{}),fetch("http://169.254.169.254/latest/meta-data/instance-id",{headers:r,signal:AbortSignal.timeout(e)}).catch(()=>{})]);if(!o?.ok&&!s?.ok)return;let i=o?.ok?(await o.text()).trim():"",a=s?.ok?(await s.text()).trim():"";if(!(!i&&!a))return{provider:"aws",region:i,instance_id:a}}async function qp(e){let t=await fetch("http://metadata.google.internal/computeMetadata/v1/instance/?recursive=true",{headers:{"Metadata-Flavor":"Google"},signal:AbortSignal.timeout(e)}).catch(()=>{});if(!t?.ok)return;let n=await t.json(),r=typeof n.zone=="string"?n.zone.split("/").pop()??"":"",o=n.id===void 0?"":String(n.id);if(!(!r&&!o))return{provider:"gcp",region:r,instance_id:o}}async function Qp(e){let t=await fetch("http://169.254.169.254/metadata/instance?api-version=2021-02-01",{headers:{Metadata:"true"},signal:AbortSignal.timeout(e)}).catch(()=>{});if(!t?.ok)return;let n=await t.json(),r=n.compute?.location??"",o=n.compute?.vmId??"";if(!(!r&&!o))return{provider:"azure",region:r,instance_id:o}}async function ef(e){let t=await Promise.allSettled([Zp(e),qp(e),Qp(e)]);for(let n of t)if(n.status==="fulfilled"&&n.value)return n.value;return null}async function Ei(e,t){if(e==="interactive")return null;let n=t?.home??Si(),r=t?.timeoutMs??1e3,o=t?.nowMs??Date.now(),s=Wp(n),i=Yp(s);if(Xp(i,e,o))return i.result;let a=await ef(r);return Jp(s,{context:e,probed_at:o,result:a}),a}var tf=["CI","GITHUB_ACTIONS","GITLAB_CI","CIRCLECI","BUILDKITE","TF_BUILD","JENKINS_URL","JENKINS_HOME","CODEBUILD_BUILD_ID","DRONE","DRONE_BUILD_NUMBER","TEAMCITY_VERSION","TRAVIS","APPVEYOR","BITBUCKET_BUILD_NUMBER","KUBERNETES_SERVICE_HOST","REMOTE_CONTAINERS","DEVCONTAINER","GITHUB_REPOSITORY","GITHUB_REPOSITORY_ID","GITHUB_REF","GITHUB_SHA","GITHUB_RUN_ID","GITHUB_WORKFLOW","GITHUB_ACTOR","GITHUB_TRIGGERING_ACTOR","GITHUB_ACTOR_ID","GITHUB_USER","GITLAB_USER_LOGIN","GITLAB_USER_NAME","GITLAB_USER_EMAIL","BUILD_REQUESTEDFOR","BUILD_REQUESTEDFOREMAIL","BUILD_REQUESTEDFORID","BUILDKITE_BUILD_CREATOR","BUILDKITE_BUILD_CREATOR_EMAIL","BUILD_USER","BUILD_USER_ID","BUILD_USER_EMAIL","CHANGE_AUTHOR","CHANGE_AUTHOR_EMAIL","CIRCLE_USERNAME","CODEBUILD_INITIATOR","DRONE_COMMIT_AUTHOR","DRONE_COMMIT_AUTHOR_NAME","DRONE_COMMIT_AUTHOR_EMAIL","EV_AI_HOOK_OPERATOR_NAME","EV_AI_HOOK_OPERATOR_EMAIL","EV_AI_HOOK_OPERATOR_LOGIN","GIT_AUTHOR_NAME","GIT_AUTHOR_EMAIL","GIT_COMMITTER_NAME","GIT_COMMITTER_EMAIL","EMAIL","RUNNER_OS","RUNNER_ARCH","NODE_ENV","TERM_PROGRAM","CLAUDE_CODE_REMOTE","CLAUDE_CODE_REMOTE_SESSION_ID","CURSOR_AGENT","CURSOR_VERSION","CURSOR_CODE_REMOTE","CURSOR_USER_EMAIL","CODESPACES","CODESPACE_NAME","ANTHROPIC_BASE_URL","OPENAI_BASE_URL","OPENAI_API_BASE","AZURE_OPENAI_ENDPOINT","GOOGLE_GEMINI_BASE_URL","GEMINI_API_BASE","CLAUDE_CODE_USE_BEDROCK","CLAUDE_CODE_USE_VERTEX"],nf=["CURSOR_PROJECT_DIR"],rf=new Set(["key","api-key","api_key","apikey","token","sig","signature","access_token","password","pwd","secret","client_secret"]);function of(e){try{let t=new URL(e);(t.username||t.password)&&(t.username="",t.password="");for(let[n]of t.searchParams)rf.has(n.toLowerCase())&&t.searchParams.set(n,"[redacted]");return t.toString()}catch{return e}}function yi(e=process.env){let t=tf.map(r=>Object.prototype.hasOwnProperty.call(e,r)?{name:r,present:!0,value:of(e[r]??"")}:{name:r,present:!1}),n=nf.map(r=>({name:r,present:Object.prototype.hasOwnProperty.call(e,r)&&!!e[r]}));return[...t,...n]}import{homedir as Lf}from"node:os";import{homedir as Ri}from"node:os";import{join as sf}from"node:path";function af(e=Ri()){return sf(e,".claude.json")}function Ft(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Ci(e=Ri()){let n=L(af(e),{}).oauthAccount;if(!n||typeof n!="object")return null;let r=Ft(n.emailAddress),o=Ft(n.fullName)??Ft(n.displayName),s=Ft(n.accountUuid),i=r??s;return!i||B(o,r)?null:{git_user_name:null,git_user_email:null,platform_login:i,identity_source:"claude_oauth"}}import{homedir as Oi}from"node:os";import{join as Ii}from"node:path";var cf="https://api.openai.com/auth";function ve(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Pi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function uf(e){let t=e.split(".");if(t.length!==3||t.some(r=>r.length===0))return null;let n=t[1];if(!n)return null;try{let r=JSON.parse(Buffer.from(n,"base64url").toString("utf8"));return Pi(r)}catch{return null}}function Ai(e,t,n){return ve(e[n])??ve(t?.[n])}function lf(e=process.env,t=Oi()){let n=ve(e.CODEX_HOME)??Ii(t,".codex");return Ii(n,"auth.json")}function Ti(e=process.env,t=Oi()){let n=L(lf(e,t),{}),r=ve(n.auth_mode);if(r!==null&&r!=="chatgpt"||r===null&&ve(n.OPENAI_API_KEY))return null;let o=ve(n.tokens?.id_token);if(!o)return null;let s=uf(o);if(!s)return null;let i=Pi(s[cf]),a=Ai(s,i,"name"),c=Ai(s,i,"email");return!c||B(a,c)?null:{git_user_name:null,git_user_email:null,platform_login:c,identity_source:"codex_oauth"}}import{homedir as $t}from"node:os";import{join as se}from"node:path";import{join as df}from"node:path";var pf="cursor-ide-identity.json",ff=Ve;function xi(e){return df(ne(e),pf)}function ki(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function bi(e){let t=L(e,{}),n=t.read_at_ms,r=t.db_path;if(!(typeof n!="number"||!Number.isFinite(n)||typeof r!="string"))return{read_at_ms:n,db_path:r,email:ki(t.email),auth_id:ki(t.auth_id)}}function Ni(e,t,n){if(e?.db_path!==t)return!1;let r=n-e.read_at_ms;return r>=0&&r<ff}function Mi(e,t){try{X(e,`${JSON.stringify(t)}
|
|
22
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: cursor IDE identity cache write failed open: ${r}`)}}import{execFileSync as mf}from"node:child_process";import{existsSync as gf}from"node:fs";import{createRequire as _f}from"node:module";import{pathToFileURL as hf}from"node:url";var vi=_f(import.meta.url),Ht=`
|
|
23
23
|
SELECT key, value
|
|
24
24
|
FROM ItemTable
|
|
25
25
|
WHERE key LIKE 'cursorAuth/%'
|
|
26
26
|
AND key NOT LIKE '%Token%'
|
|
27
27
|
AND key NOT LIKE '%token%'
|
|
28
28
|
ORDER BY key
|
|
29
|
-
`.trim(),
|
|
30
|
-
`)){let r=n.trimEnd();if(!r)continue;let o=r.indexOf(" ");if(o<=0)continue;let s=r.slice(0,o).trim(),i=r.slice(o+1).trim();s&&i&&!
|
|
31
|
-
`);return v(n)}function
|
|
32
|
-
`)){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 yf(e,t=w){let n=await t("git",["config","--get-regexp","^user\\.(name|email)$"],2e3,{cwd:e});return Ef(n)}function Rf(e=process.env){let t=O(e.GIT_AUTHOR_NAME),n=O(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=O(e.GIT_COMMITTER_NAME),o=O(e.GIT_COMMITTER_EMAIL);if(r||o)return{git_user_name:r,git_user_email:o,platform_login:null,identity_source:"git_env"};let s=O(e.EMAIL);return s?{git_user_name:null,git_user_email:s,platform_login:null,identity_source:"git_env"}:null}function ce(e,t,n,r=null){return!e&&!t&&!r?null:{git_user_name:e,git_user_email:t,platform_login:r,identity_source:n}}function Cf(e=process.env){let t=O(e.EV_AI_HOOK_OPERATOR_EMAIL),n=O(e.EV_AI_HOOK_OPERATOR_LOGIN),r=ce(O(e.EV_AI_HOOK_OPERATOR_NAME),t,"configured",t??n);if(r)return r;let o=O(e.GITHUB_ACTOR)??O(e.GITHUB_TRIGGERING_ACTOR)??O(e.GITHUB_USER),s=ce(o,null,"github",o);if(s)return s;let i=O(e.GITLAB_USER_LOGIN),a=O(e.GITLAB_USER_EMAIL),c=ce(O(e.GITLAB_USER_NAME)??i,a,"gitlab",a??i);if(c)return c;let u=O(e.BUILD_REQUESTEDFOREMAIL),l=ce(O(e.BUILD_REQUESTEDFOR),u,"azure_devops",u??O(e.BUILD_REQUESTEDFORID));if(l)return l;let p=O(e.BUILDKITE_BUILD_CREATOR_EMAIL),m=ce(O(e.BUILDKITE_BUILD_CREATOR),p,"buildkite",p);if(m)return m;let d=O(e.BUILD_USER_EMAIL)??O(e.CHANGE_AUTHOR_EMAIL),g=ce(O(e.BUILD_USER)??O(e.CHANGE_AUTHOR),d,"jenkins",d??O(e.BUILD_USER_ID));if(g)return g;let S=O(e.CIRCLE_USERNAME),E=ce(S,null,"circleci",S);if(E)return E;let y=O(e.CODEBUILD_INITIATOR),R=ce(y,null,"codebuild",y);if(R)return R;let H=O(e.DRONE_COMMIT_AUTHOR_EMAIL),k=O(e.DRONE_COMMIT_AUTHOR),x=ce(k??O(e.DRONE_COMMIT_AUTHOR_NAME),H,"drone",H??k);if(x)return x;if(xi(e.CLAUDE_CODE_REMOTE)||xi(e.CURSOR_AGENT)){let L=O(e.CURSOR_USER_EMAIL);return{git_user_name:null,git_user_email:null,platform_login:L&&!G(null,L)?L:null,identity_source:"cloud"}}return null}function sr(e){return!!((e.git_user_name??e.git_user_email)&&!G(e.git_user_name,e.git_user_email))}function O(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function xi(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function If(e,t,n){return e==="claude"?di(t):e==="cursor"?Ti(t,n):e==="codex"?_i(n,t):null}async function ir(e,t=w,n=process.env,r={}){let o=await yf(e,t),s=Rf(n),i=sr(o)?o:s&&sr(s)?s:null,a=If(r.runnerPlatform,r.home??hf(),n);if(a)return{git_user_name:i?.git_user_name??null,git_user_email:i?.git_user_email??null,platform_login:a.platform_login,identity_source:a.identity_source};let c=Cf(n);return c?.platform_login?{git_user_name:i?.git_user_name??null,git_user_email:i?.git_user_email??null,platform_login:c.platform_login,identity_source:c.identity_source}:i?{...i,platform_login:null,identity_source:sr(o)?"git_config":"git_env"}:c||(o.git_user_name||o.git_user_email?{...o,identity_source:"git_config"}:s||{git_user_name:null,git_user_email:null,platform_login:null,identity_source:"git_config"})}async function ar(e){let{gitRoot:t,installationStorePath:n,forceResend:r}=e,o=e.exec??w,s=e.env??process.env,i=await ir(t,o,s,{runnerPlatform:e.runnerPlatform,home:e.home}),a=Sf(i.git_user_name,i.git_user_email,i.identity_source,i.platform_login),u=(n?bn(n):void 0)?.operator_identity_hash;if(!(r||u!==void 0&&u!==a||!u))return{commit:()=>{}};let d=n;return{operator:i,commit:()=>{d&&Uo(d,a,ft())}}}function cr(e){return e?!bn(e)?.operator_identity_hash:!0}function bi(e){return!0}import{existsSync as Jm,readFileSync as Xm}from"node:fs";import{homedir as Oa}from"node:os";import{join as De,resolve as Zm}from"node:path";import{basename as Km,join as Ue}from"node:path";import{dirname as $i,resolve as Ft}from"node:path";import{existsSync as Af}from"node:fs";import{homedir as wi}from"node:os";import{relative as vi,resolve as ne,sep as ge}from"node:path";var Of=["session_id","conversation_id","turn_id","generation_id","prompt.id","prompt_id","hook_event_name","event","source","status","stop_reason","reason","tool_name","tool","tool_use_id","skill_name","command_name","expansion_type","command_source","permission_mode","model","model_id","agent_id","agent_type","subagent_id","subagent_type","subagent_model","is_parallel_worker","effort","effort.level","duration_ms","duration","sandbox","failure_type","is_interrupt"],Pf=["prompt","tool_input","tool_response","last_assistant_message","command"],Tf=new Set;function kf(e){switch(e?.toLowerCase()){case"beforemcpexecution":return new Set(["command"]);case"stopfailure":return new Set(["last_assistant_message"]);default:return Tf}}function Li(e){return Ui(e)==="allowlist"}function Ui(e){return I("EV_AI_HOOK_CAPTURE_CONTENT")?.toLowerCase()==="off"||e.capture_hook_input==="allowlist"?"allowlist":e.capture_hook_input==="full"||e.debug===!0||I("EV_AI_HOOK_CAPTURE_FULL_INPUT")==="1"?"full":"content"}function xf(e){let t={};for(let n of Of){let r=re(e,n);r!==void 0&&(t[n]=r)}return t}function Ut(e,t){if(typeof e!="string"||e.length===0||!t)return null;let n=ne(e),r=ne(t),o=vi(r,n);return!o||o==="."?".":o.startsWith(`..${ge}`)||o===".."||ne(r,o)!==n?null:o.split(ge).join("/")}function Di(e,t){let n=vi(ne(t),ne(e)).split(ge).join("/");return!n||n==="."?null:n===".."||n.startsWith("../")&&n.split("/").every(r=>r==="..")?n:null}function Fi(e){return typeof e!="string"||e.length===0?null:ne(e).split(ge).join("/")}function bf(){let e=I("CURSOR_PROJECT_DIR");if(!e)return null;let t=ne(e);return Af(t)?t.split(ge).join("/"):null}function lr(e,t){return Ut(e,t)!==null}function Nf(e,t){let n=ne(t??wi(),".cursor").split(ge).join("/");return lr(e,n)}function Mf(e,t,n){return t!==null&&lr(e,t)?!0:t!==null&&Nf(e,n.home)?!1:n.inGitRepo===!0&&n.gitRoot!==void 0&&lr(e,n.gitRoot)?!0:t===null}function Hi(e,t){let n=Fi(e.cwd);if(n!==null)return n;let r=ne(process.cwd()).split(ge).join("/"),o=bf();return Mf(r,o,t)?r:o??r}function fr(e,t={}){return Hi(e,t)}function mr(e,t=wi()){let n=ne(t).split(ge).join("/").replace(/\/$/,"");return n.length<=1?e:e===n?"~":e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function Ni(e,t,n){let r=Fi(n.launchCwd)??Hi(t,n);e.cwd=mr(r,n.home);let o=n.inGitRepo===!0&&n.gitRoot!==void 0?Ut(r,n.gitRoot):null;o!==null&&(e.cwd_relative=o)}var ji="\u2026[truncated]\u2026",dr=Buffer.byteLength(ji,"utf8"),wf=8;function nt(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function Mi(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(0,t).toString("utf8")}function vf(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(n.length-t).toString("utf8")}function Lf(e,t){if(Buffer.byteLength(e,"utf8")<=t)return e;if(t<=dr)return Mi(e,t);let r=t-dr,o=Math.ceil(r/2),s=Math.floor(r/2);return`${Mi(e,o)}${ji}${vf(e,s)}`}function pr(e,t,n){if(typeof e=="string"){n.push({path:t,value:e,bytes:Buffer.byteLength(e,"utf8")});return}if(Array.isArray(e)){e.forEach((r,o)=>{pr(r,[...t,o],n)});return}if(e!==null&&typeof e=="object")for(let[r,o]of Object.entries(e))t.length===0&&r.startsWith("_")||pr(o,[...t,r],n)}function Uf(e,t,n){let r=e;for(let s=0;s<t.length-1;s++){let i=t[s];if(i===void 0)return;r=(Array.isArray(r),r[i])}let o=t[t.length-1];if(!(o===void 0||r===null||typeof r!="object")){if(Array.isArray(r)){r[o]=n;return}r[o]=n}}var Df=256;function Ff(e,t,n){let r=n,o=Math.max(n,e[0]?.bytes??n);for(;r<o;){let s=Math.ceil((r+o)/2),i=0;for(let a of e)a.bytes>s&&(i+=a.bytes-s);i>=t?r=s:o=s-1}return r}function Hf(e,t,n){let r=Number.POSITIVE_INFINITY;for(let o=0;o<6;o++){let s=nt(e);if(s<=t)return;let i=[];pr(e,[],i),i.sort((l,p)=>p.bytes-l.bytes);let a=i.filter(l=>l.bytes>n);if(a.length===0)return;let c=Ff(a,s-t,n),u=Math.max(n,Math.min(c,r-1));if(u>=r)return;r=u;for(let l of a)l.bytes>r&&Uf(e,l.path,Lf(l.value,r))}}function jf(e,t){let n=Math.max(0,t-Df),r=Object.keys(e).filter(s=>!s.startsWith("_")).map(s=>({key:s,bytes:nt(e[s])})).sort((s,i)=>i.bytes-s.bytes),o=[];for(let{key:s}of r){if(nt(e)<=n)break;delete e[s],o.push(s)}o.length>0&&(e._dropped_keys=o.slice(0,10))}function ur(e,t){let n=nt(e);if(n<=t)return e;let r=structuredClone(e);return r._truncated=!0,r._original_bytes=n,Hf(r,t,dr+wf),nt(r)>t&&jf(r,t),r}function $f(e,t,n){let r=kf(n.runnerEvent);for(let o of Pf){if(r.has(o))continue;let s=t[o];s!==void 0&&(e[o]=s)}}function Dt(e,t,n={}){let r=Ui(t);if(r==="full"){let s={...e};return delete s.cwd,delete s.transcript_path,Ni(s,e,n),ur(s,On)}let o=xf(e);return Ni(o,e,n),r==="content"?($f(o,e,n),ur(o,On)):ur(o,yo)}function Kf(e){return typeof e=="string"&&e.length>0}function gr(e){let t=Ft(e.home),n=Ft(e.launchCwd),r=e.gitRoot?Ft(e.gitRoot):null,o=new Set,s=[],i=null;e.inGitRepo&&Kf(e.remote)&&r!==null&&r!==t&&(i=r,o.add(r)),n!==t&&!o.has(n)&&(s.push({scope:"cwd",dir:n}),o.add(n)),i!==null&&s.push({scope:"repo",dir:i});let a=null,c=r!==null&&Ut(n,r)!==null;if(e.inGitRepo&&r!==null&&r!==t&&c){let u=$i(r);for(;;){let l=Ft(u);if(l===t)break;let p=$i(l);if(p===l)break;if(e.hasProjectSpec(l)){s.push({scope:"parent",dir:l}),a=Di(l,n);break}u=p}}return{anchors:s,parentRel:a}}import{existsSync as Ki,readdirSync as Bf,realpathSync as Gf}from"node:fs";import{basename as zf,dirname as Vf,relative as Wf,resolve as Yf,sep as Jf}from"node:path";var _r=400,Ht=class{constructor(t,n={}){this.home=t;this.pathMode=n.pathMode??"home-relative",this.maxEntries=n.maxEntries??ue}components=[];truncated=!1;pathMode;maxEntries;pluginExpandRemaining;seenRealpaths=new Set;componentPath(t){if(this.pathMode==="tilde"){let r=Yf(t).split(Jf).join("/");return mr(r,this.home)}let n=Wf(this.home,t).replace(/\\/g,"/");return!n||n.startsWith("..")?`external/${v(Vf(t))}/${zf(t)}`:n}claimFile(t){try{let n=Gf(t);return this.seenRealpaths.has(n)?!1:(this.seenRealpaths.add(n),!0)}catch{return this.seenRealpaths.has(t)?!1:(this.seenRealpaths.add(t),!0)}}get atGlobalCap(){return this.truncated||this.components.length>=this.maxEntries}get pluginBudgetSpent(){return this.pluginExpandRemaining!==void 0&&this.pluginExpandRemaining<=0}readEntries(t){if(!Ki(t))return[];try{return Bf(t,{withFileTypes:!0})}catch{return[]}}readJson(t,n){if(Ki(t))return F(t,n)}push(t){return this.components.length>=this.maxEntries?(this.truncated=!0,!1):this.pluginExpandRemaining!==void 0&&this.pluginExpandRemaining<=0?!1:(this.pluginExpandRemaining!==void 0&&(this.pluginExpandRemaining-=1),this.components.push(t),!0)}withPluginExpandCap(t,n){let r=this.pluginExpandRemaining;this.pluginExpandRemaining=t;try{let o=n(),s=t-(this.pluginExpandRemaining??0);return{result:o,expanded:s}}finally{this.pluginExpandRemaining=r}}};import{existsSync as hr,readFileSync as Xf,statSync as Zf}from"node:fs";import{basename as Gi,join as rt,relative as zi}from"node:path";var Sr=100*1024,qf=4;function Qf(e){return e.length<=Sr?e:`${e.slice(0,Sr-1)}\u2026`}function em(e){try{let t=Xf(e),n=t.toString("utf8");return{hash:v(t),length:t.length,text:Qf(n)}}catch{return null}}var Bi={HOOK:"EVENT",COMMAND:"EXPLICIT_INVOCATION",MEMORY:void 0,MCP_SERVER:void 0,PLUGIN:void 0,SKILL:"UNSPECIFIED",RULE:"UNSPECIFIED",SUBAGENT:"UNSPECIFIED"};function tm(e){return e in Bi?Bi[e]:"UNSPECIFIED"}function jt(e,t){if(!e.claimFile(t.absolutePath))return!1;let n=em(t.absolutePath);if(!n)return!1;let r=t.name??Gi(t.absolutePath).replace(/\.(md|mdc|toml)$/i,""),o={kind:t.kind,name:r,path:e.componentPath(t.absolutePath),text:n.text,content_hash:n.hash,content_length:n.length,origin:t.origin,enabled:t.enabled},s=tm(t.kind);return s&&(o.trigger=s),e.push(o)}function nm(e,t,n){let r=zi(e,t).replace(/\\/g,"/");return!r||r.startsWith("..")?Gi(t).replace(/\.(md|mdc|toml)$/i,""):n?r.replace(/\.(md|mdc|toml)$/i,""):r}function Ie(e,t){let{dir:n,kind:r,origin:o,enabled:s,nested:i,extensions:a}=t;Er(e,{walkRoot:n,currentDir:n,depth:0,kind:r,origin:o,enabled:s,nested:i,extensions:a})}function Er(e,t){let{walkRoot:n,currentDir:r,depth:o,kind:s,origin:i,enabled:a,nested:c,extensions:u}=t;if(!(o>qf))for(let l of e.readEntries(r)){if(e.atGlobalCap){e.truncated=!0;return}if(e.pluginBudgetSpent)return;if(c){if(!l.isDirectory())continue;let d=rt(r,l.name,c);if(hr(d)){let g=zi(n,rt(r,l.name)).replace(/\\/g,"/");jt(e,{absolutePath:d,kind:s,origin:i,enabled:a,name:g||l.name});continue}Er(e,{walkRoot:n,currentDir:rt(r,l.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:u});continue}if(l.isDirectory()){Er(e,{walkRoot:n,currentDir:rt(r,l.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:u});continue}if(!l.isFile()||!u)continue;let p=l.name.toLowerCase();if(!u.some(d=>p.endsWith(d)))continue;let m=rt(r,l.name);jt(e,{absolutePath:m,kind:s,origin:i,enabled:a,name:nm(n,m,!0)})}}function Vi(e){for(let t of e)if(hr(t))try{if(Zf(t).size>0)return t}catch{continue}return e.find(t=>hr(t))}var $t=je(Me(),1);var rm="<omitted>",om=["package_name","package_spec","package_version","package_version_source"],Wi=100,Yi=120,Kt=[{raw:"tools",attr:"tools"},{raw:"autoApprove",attr:"auto_approve"},{raw:"auto_approve",attr:"auto_approve"},{raw:"alwaysAllow",attr:"always_allow"},{raw:"always_allow",attr:"always_allow"},{raw:"enabledTools",attr:"enabled_tools"},{raw:"enabled_tools",attr:"enabled_tools"},{raw:"disabledTools",attr:"disabled_tools"},{raw:"disabled_tools",attr:"disabled_tools"}],Ji=new Set(Kt.map(e=>e.attr)),sm=["enabled","disabled"],im=["serverUrl","auth","bearer_token_env_var","default_tools_approval_mode","defaultToolsApprovalMode","env_vars","env_http_headers","http_headers"],am=new Set(["type","command","url","args","env","envVars","headers",...sm,...im,...Kt.map(e=>e.raw)]),cm=new Set(["transport","command_or_url","args","env_var_names","headers_present","auth","bearer_token_env_var","default_tools_approval_mode","env_http_header_names",...om,...Ji,...[...Ji].map(e=>`${e}_truncated`)]);function Xi(e,t){for(let n of t)am.has(n)||cm.has(n)||(e[n]=rm)}var um=/^(authorization|auth|api[-_]?key|access[-_]?token|refresh[-_]?token|secret|password|passwd|token|bearer|client[-_]?secret|client[-_]?id|private[-_]?key|signing[-_]?key)$/i,lm=/(?:^|[-_])(secret|password|passwd|token|api[-_]?key|private[-_]?key|signing[-_]?key|client[-_]?secret|client[-_]?id)(?:[-_]|$)/i,dm=/^(sk-|ghp_|gho_|github_pat_|xox[baprs]-|AKIA|ASIA|AIza|ya29\.)/,pm=/^bearer(?:\s+|$)/i;function Bt(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Zi(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function yr(e){if(Array.isArray(e)){let n=[];for(let r of e){if(typeof r!="string"||r.length===0)continue;let o=r.split("=",1)[0]?.trim();o&&n.push(o)}return n}let t=Bt(e);return t?Object.keys(t).filter(n=>n.length>0):[]}function Ae(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch{return e}}function fm(e,t){if(e!==void 0&&/^https?:\/\//i.test(e)&&(0,$t.launchContainsCredentials)({kind:"url",url:e})||(0,$t.launchContainsCredentials)({kind:"command",command:e??"",arguments:t}))return!0;let n=st([...t]);return t.some((r,o)=>n[o]===r?!1:/^https?:\/\//i.test(r)?(0,$t.launchContainsCredentials)({kind:"url",url:r}):!0)}function qi(e,t,n){fm(t,n)&&(e.launch_had_credentials=!0)}function mm(e){return dm.test(e)||pm.test(e)?"<redacted>":e.includes("://")?Ae(e):e}function Qi(e){if(/^https?:\/\//i.test(e))return Ae(e);let t=e.indexOf("=");return t>0?`${e.slice(0,t+1)}${Qi(e.slice(t+1))}`:mm(e)}function gm(e){let t=e.replace(/^-+/,"").split("=",1)[0]??"";return um.test(t)||lm.test(t)}function st(e){let t=[],n=!1;for(let r of e){if(n){t.push("<redacted>"),n=!1;continue}if(gm(r)){t.push("<redacted>"),n=!r.includes("=");continue}t.push(Qi(r))}return t}function _m(e){let t=Zi(e);if(t.length===0)return;let n=[...new Set(t.map(r=>r.length>Yi?r.slice(0,Yi):r))].sort();if(n.length!==0)return n.length>Wi?{names:n.slice(0,Wi),truncated:!0}:{names:n,truncated:!1}}function hm(e){let t=Bt(e);if(!t)return{headers:[],envVars:[]};let n=[],r=[];for(let[o,s]of Object.entries(t))o.length>0&&n.push(o),typeof s=="string"&&s.length>0&&r.push(s);return{headers:n,envVars:r}}function ea(e,t){let n=new Set;for(let{raw:r,attr:o}of Kt){if(n.has(o)||!(r in t))continue;let s=t[r];if(o==="auto_approve"&&typeof s=="boolean"){e.auto_approve=s,n.add(o);continue}let i=_m(s);i&&(e[o]=i.names,i.truncated&&(e[`${o}_truncated`]=!0),n.add(o))}}function ta(e,t){let n=Bt(e),r={transport:t};if(!n)return r;Xi(r,Object.keys(n));let o=typeof n.command=="string"?n.command:void 0,s=typeof n.url=="string"?n.url:void 0,i=typeof n.serverUrl=="string"?n.serverUrl:void 0,a=o??s??i,c=Zi(n.args);a&&(r.command_or_url=Ae(a));let u=st(c);u.length>0&&(r.args=u),qi(r,a,c);let l=hm(n.env_http_headers),p=[...new Set([...yr(n.env),...yr(n.envVars),...yr(n.env_vars),...l.envVars,...typeof n.bearer_token_env_var=="string"&&n.bearer_token_env_var.length>0?[n.bearer_token_env_var]:[]])].sort();p.length>0&&(r.env_var_names=p),l.headers.length>0&&(r.env_http_header_names=[...new Set(l.headers)].sort());for(let S of["headers","http_headers","env_http_headers"])if(n[S]!==void 0&&n[S]!==null){r.headers_present=!0;break}let m=typeof n.auth=="string"?n.auth:void 0;m&&(r.auth=m);let d=typeof n.bearer_token_env_var=="string"?n.bearer_token_env_var:void 0;d&&(r.bearer_token_env_var=d);let g=typeof n.default_tools_approval_mode=="string"?n.default_tools_approval_mode:typeof n.defaultToolsApprovalMode=="string"?n.defaultToolsApprovalMode:void 0;return g&&(r.default_tools_approval_mode=g),ea(r,n),r}function na(e){let t=Bt(e);return t?t.enabled===!1?!1:t.disabled!==!0:!0}function Ir(e,t,n=!0){let r=Object.keys(t).sort().map(o=>[o,t[o]??null]);return v(JSON.stringify({name:e,attributes:r,enabled:n}))}function ve(e){let t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function ot(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*\\[([^\\]]*)\\]`,"m").exec(e);return n?.[1]?[...n[1].matchAll(/"([^"]*)"|'([^']*)'/g)].map(r=>r[1]??r[2]??"").filter(r=>r.length>0):[]}function Cr(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(true|false)\\s*$`,"m").exec(e);if(n?.[1])return n[1]==="true"}function Rr(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(.+)$`,"m").exec(e);if(!n?.[1])return;let r=ve(n[1]);return r.length>0?r:void 0}function Sm(e,t){let n=[],r=i=>{for(let a of i.split(/[,\n]/)){let c=/^\s*"?([A-Za-z_][A-Za-z0-9_-]*)"?\s*=\s*(.+?)\s*$/.exec(a);c?.[1]&&n.push([c[1],ve(c[2]??"")])}},o=new RegExp(`^\\s*${t}\\s*=\\s*\\{([^}]*)\\}`,"m").exec(e);o?.[1]&&r(o[1]);let s=new RegExp(`(?:^|\\n)\\[[^\\]]*\\.${t}\\]\\s*\\n([\\s\\S]*?)(?=\\n\\[|$)`).exec(`
|
|
33
|
-
${e}`);return s?.[1]&&r(s[1]),n}function
|
|
34
|
-
`)){let s=
|
|
35
|
-
`)){let
|
|
36
|
-
${e}`);if(m?.[1])for(let
|
|
37
|
-
`)){let
|
|
38
|
-
`);return xm("sha512").update(t).digest("hex").slice(0,16)}function Nm(e){let t=process.platform==="win32"?it(I("LOCALAPPDATA")??e,"npm-cache"):it(e,".npm"),n=I("npm_config_cache")??I("NPM_CONFIG_CACHE");return n===void 0||n===t?[t]:[n,t]}function ua(e){return typeof e=="string"&&e.length>0&&e.length<=_e.PACKAGE_FIELD_MAX?e:null}function Mm(e,t,n){let r=bm(e);for(let o of Nm(n)){let s=it(o,"_npx",r),i=F(it(s,"node_modules",...t.split("/"),"package.json"),{}),a=ua(i.version);if(a!==null)return a;let c=F(it(s,"package-lock.json"),{}),u=ua(c.packages?.[`node_modules/${t}`]?.version);if(u!==null)return u}return null}function wm(e){return e.length<=_e.PACKAGE_FIELD_MAX?e:`${e.slice(0,_e.PACKAGE_FIELD_MAX-1)}\u2026`}function Ar(e,t,n){if(typeof e!="string"||e.length===0)return null;let r=(0,_e.npxPackageSpecs)(e,t??[]),o=r[0];if(o===void 0)return null;let s=(0,_e.packageNameFromSpec)(o);if(s===null)return null;let i=Mm(r,s,n);return{package_name:s,package_spec:wm(o),...i===null?{}:{package_version:i,package_version_source:"npx_cache"}}}function la(e,t){if(typeof e!="string"||e.length===0)return null;let[n,...r]=Gt(e.trim());return n===void 0?null:Ar(n,r,t)}function zt(e,t){if(!e||typeof e!="object"||Array.isArray(e))return null;let n=e,r=Array.isArray(n.args)?n.args.filter(o=>typeof o=="string"):[];return Ar(typeof n.command=="string"?n.command:null,r,t)}function da(e,t){let n=/^\s*command\s*=\s*(.+)$/m.exec(e);return n===null?null:Ar(ve(n[1]??""),ot(e,"args"),t)}function Um(e){if(!e||typeof e!="object"||Array.isArray(e))return"unknown";let t=e;return typeof t.type=="string"&&t.type.length>0?t.type:typeof t.url=="string"?"http":typeof t.command=="string"?"stdio":"unknown"}function pa(e,t,n){if(!e.claimFile(t))return;let o=e.readJson(t,{})?.mcpServers;if(!o||typeof o!="object")return;let s=e.componentPath(t);for(let[i,a]of Object.entries(o)){if(e.truncated)return;let c=Um(a),u=ta(a,c);Object.assign(u,zt(a,e.home)??{});let l=na(a);e.push({kind:"MCP_SERVER",name:i,path:s,content_hash:Ir(i,u,l),origin:n,enabled:l,attributes:u})}}function fa(e,t,n){if(!vm(t)||!e.claimFile(t))return;let r;try{r=Lm(t,"utf8")}catch{return}let o=e.componentPath(t),s=/^\[mcp_servers(?:\.(\w+)|\."([^"]+)"|\.'([^']+)')\]\s*$/gm,i;for(;(i=s.exec(r))!==null;){if(e.truncated)return;let a=i[1]??i[2]??i[3];if(!a)continue;let c=r.slice(i.index+i[0].length),u=c.search(/^\[mcp_servers(?:\.(?:\w+|"[^"]+"|'[^']+'))\]\s*$/m),l=u===-1?c:c.slice(0,u),p="unknown";/^\s*url\s*=/m.test(l)?p="http":/^\s*command\s*=/m.test(l)&&(p="stdio");let m=oa(l,p);Object.assign(m,da(l,e.home)??{});let d=ra(l);e.push({kind:"MCP_SERVER",name:a,path:o,content_hash:Ir(a,m,d),origin:n,enabled:d,attributes:m})}}import{existsSync as Dm,readdirSync as Fm}from"node:fs";import{join as B}from"node:path";var ma=50;function Or(e,t,n,r){if(!Dm(t))return{componentCount:0,expandTruncated:!1};let o=e.components.length,{expanded:s}=e.withPluginExpandCap(ma,()=>{Ie(e,{dir:B(t,"skills"),kind:"SKILL",origin:n,enabled:r,nested:"SKILL.md"}),Ie(e,{dir:B(t,"commands"),kind:"COMMAND",origin:n,enabled:r,extensions:[".md"]}),Ie(e,{dir:B(t,"agents"),kind:"SUBAGENT",origin:n,enabled:r,extensions:[".md"]})});Le(e,B(t,"hooks","hooks.json"),n),Le(e,B(t,"hooks.json"),n);let i=e.components.length-o,a=s>=ma;return{componentCount:i,expandTruncated:a}}function Pr(e,t){e.push({kind:"PLUGIN",name:t.pluginKey,path:t.rowPath,content_hash:t.contentHash,origin:"user",enabled:t.enabled,attributes:{...t.marketplace?{marketplace:t.marketplace}:{},...t.version?{version:t.version}:{},scope:t.scope,component_count:t.componentCount,...t.expandTruncated?{expand_truncated:!0}:{}}})}function ga(e){let t=B(e.home,".claude/plugins/installed_plugins.json"),n=e.readJson(t,{});if(!n)return;let r=n.plugins??{},s=e.readJson(B(e.home,".claude/settings.json"),{})?.enabledPlugins??{},i=e.componentPath(t);for(let[a,c]of Object.entries(r)){if(e.truncated)return;let u=Array.isArray(c)?c:[c],l=u[0]??{},p=s[a]===!0,m=a.includes("@")?a.split("@").slice(1).join("@"):"",d=typeof l.version=="string"?l.version:"",g=typeof l.scope=="string"?l.scope:"user",S=`plugin:${a}`,E=0,y=!1;for(let R of u)if(typeof R.installPath=="string"&&R.installPath.length>0){let H=Or(e,R.installPath,S,p);E+=H.componentCount,y=y||H.expandTruncated}Pr(e,{pluginKey:a,rowPath:i,enabled:p,scope:g,version:d||void 0,marketplace:m||void 0,componentCount:E,expandTruncated:y,contentHash:v(`${a}|${d}|${g}|${p}|${E}`)})}}function Hm(e){let t=e,n="";try{let r=Fm(e,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);if(r.length===1&&r[0])t=B(e,r[0]),n=r[0];else if(r.length>1){let o=[...r].sort(),s=o[o.length-1];s&&(t=B(e,s),n=s)}}catch{}return{installPath:t,version:n}}var jm=/^\d+$/;function $m(e){let t=e.filter(n=>!jm.test(n.pluginId));return t.length>0?t:e}function _a(e){let t=[{base:B(e.home,".cursor/plugins/local"),scope:"local"},{base:B(e.home,".cursor/plugins/cache"),scope:"cache"}];for(let{base:n,scope:r}of t)if(!e.truncated)for(let o of e.readEntries(n)){if(!o.isDirectory()||e.truncated)continue;if(r==="local"){let a=o.name,c=B(n,o.name),u=`plugin:${a}`,{componentCount:l,expandTruncated:p}=Or(e,c,u,!0);Pr(e,{pluginKey:a,rowPath:e.componentPath(c),enabled:!0,scope:"local",componentCount:l,expandTruncated:p,contentHash:v(`${a}|local|${l}`)});continue}let s=o.name,i=[];for(let a of e.readEntries(B(n,s))){if(!a.isDirectory())continue;let c=B(n,s,a.name),{installPath:u,version:l}=Hm(c);i.push({pluginId:a.name,installPath:u,version:l})}for(let a of $m(i)){if(e.truncated)break;let c=`${a.pluginId}@${s}`,u=`plugin:${c}`,{componentCount:l,expandTruncated:p}=Or(e,a.installPath,u,!0);Pr(e,{pluginKey:c,rowPath:e.componentPath(a.installPath),enabled:!0,scope:"cache",version:a.version||void 0,marketplace:s,componentCount:l,expandTruncated:p,contentHash:v(`${c}|${a.version}|${l}`)})}}}function Bm(e,t){let{layout:n,levelDir:r,origin:o,includeMachineWide:s}=t;for(let i of n.skillRoots)Ie(e,{dir:Ue(r,i),kind:"SKILL",origin:o,enabled:!0,nested:"SKILL.md"});for(let i of n.dirs)Ie(e,{dir:Ue(r,i.dir),kind:i.kind,origin:o,enabled:!0,extensions:i.extensions});for(let i of n.memory){let a=Vi(i.map(c=>Ue(r,c)));a&&jt(e,{absolutePath:a,kind:"MEMORY",origin:o,enabled:!0,name:Km(a)})}for(let i of Vo(n))Le(e,Ue(r,i),o);for(let i of n.mcpJson??[])pa(e,Ue(r,i),o);for(let i of n.mcpToml??[])fa(e,Ue(r,i),o);if(s){if(n.managed)for(let i of Ct(n.managed,process.platform,e.home))i.toLowerCase().endsWith(".json")&&Le(e,i,o);n.plugins==="claude"?ga(e):n.plugins==="cursor"&&_a(e)}}function ha(e,t){try{let n=new Ht(e,{pathMode:t.pathMode,maxEntries:t.maxEntries});for(let r of t.layouts)Bm(n,{layout:r,levelDir:t.levelDir,origin:t.origin,includeMachineWide:t.includeMachineWide});return{scopeRef:t.scopeRef,anchor:t.levelDir,components:n.components,truncated:n.truncated}}catch{return}}function Tr(e,t,n={}){let r={},o=n.shouldWalk;if(o===void 0||o("user","")){let c=ha(t,{layouts:Object.values(ke),levelDir:t,origin:"user",includeMachineWide:!0,pathMode:"home-relative",maxEntries:ue,scopeRef:""});c&&(r.user=c)}let s=n.inGitRepo===!0,i=null,a=n.launchCwd;if(a!==void 0){let c=Object.values(de),u=gr({launchCwd:a,gitRoot:n.gitRoot,inGitRepo:s,remote:n.remote,home:t,hasProjectSpec:l=>Yo(c,l)});i=u.parentRel;for(let l of u.anchors){let p=or(l.dir);if(o!==void 0&&!o(l.scope,p))continue;let m=ha(t,{layouts:c,levelDir:l.dir,origin:l.scope,includeMachineWide:!1,pathMode:"tilde",maxEntries:_r,scopeRef:p});m&&(r[l.scope]=m)}r.parent||(i=null)}return{scopes:r,parentRel:i,cwdInGitRepo:s}}function kr(e,t,n={}){let r=n.truncated===!0,o=tt(e),s=new Set(e.map(l=>V(l.path,l.name)));if(n.forceFull===!0||t===void 0)return{hash:o,count:e.length,truncated:r,full:!0,upserts:e,removed:[],unchanged:!1};let a=[],c=t;for(let l of e){let p=V(l.path,l.name);c[p]!==l.content_hash&&a.push(l)}let u=[];if(!r){for(let l of Object.keys(c))if(!s.has(l)){let p=ki(l);p&&u.push(p)}}return{hash:o,count:e.length,truncated:r,full:!1,upserts:a,removed:u,unchanged:a.length===0&&u.length===0}}var Ea=2*1024*1024,Gm=new Set(["HOOK","MCP_SERVER","PLUGIN"]);function xr(e,t,n){let r=new Set(t.map(s=>V(s.path,s.name))),o=[];for(let s of e)s.text!==void 0&&(n.has(s.content_hash)||r.has(V(s.path,s.name))||o.push(s));return o}function br(e,t,n){let r=new Set(e);for(let s of t)r.add(s);let o=new Set(n.map(s=>s.content_hash));return[...r].filter(s=>o.has(s))}function Sa(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function ya(e){if(e.text===void 0)return e;let{text:t,...n}=e;return n}function Nr(e,t=Ea){let n=[],r=[];for(let l of e)Gm.has(l.kind)?n.push(l):r.push(l);r.sort((l,p)=>(l.text?.length??0)-(p.text?.length??0));let o=[...n,...r],s=[],i=2,a=0,c=0,u=[];for(let l of o){let p=s.length>0?1:0,m=Sa(l)+p;if(i+m<=t){s.push(l),i+=m,l.text!==void 0&&u.push(l.content_hash);continue}if(l.text!==void 0){let d=ya(l),g=Sa(d)+p;if(i+g<=t){s.push(d),i+=g,a+=1;continue}}c+=1}return{components:s,textDeferredCount:a,droppedCount:c,textHashesSent:u}}function Mr(e,t){return t.size===0?e:e.map(n=>n.text===void 0||!t.has(n.content_hash)?n:ya(n))}var zm=["user","cwd","repo","parent"];function wr(e){let{collected:t,cacheFor:n,nowMs:r,maxBytes:o}=e,s=[];for(let k of zm){let x=t.scopes[k];if(!x)continue;let L=n(k,x.scopeRef),U=L.components,$=kr(x.components,U,{forceFull:U===void 0,truncated:x.truncated}),q=new Set(L.textHashes),D=xr(x.components,$.upserts,q),N=Mr([...$.upserts,...D],q);s.push({scope:k,walk:x,delta:$,outgoing:N,outgoingKeys:new Set(N.map(C=>V(C.path,C.name))),deliveredTextHashes:q,cachedComponents:U})}let i=s.flatMap(k=>k.outgoing),a=Nr(i,o),c=new Set(a.components.map(k=>V(k.path,k.name))),u=[],l=[],p=[],m=[],d=[],g=[],S=[];for(let k of s){let{scope:x,walk:L,delta:U}=k;g.push(...L.components),u.push(x);let $=a.components.filter(C=>k.outgoingKeys.has(V(C.path,C.name))),q=[...k.outgoingKeys].some(C=>!c.has(C)),D=U.truncated||q;D?p.push(x):U.full&&l.push(x),m.push(...$),!U.full&&!D&&d.push(...U.removed);let N=U.full?{}:{...k.cachedComponents??{}};if(!D)for(let C of U.removed)delete N[V(C.path,C.name)];for(let C of $)N[V(C.path,C.name)]=C.content_hash;S.push({scope:x,scopeRef:L.scopeRef,components:N,textHashes:br(k.deliveredTextHashes,$.filter(C=>C.text!==void 0).map(C=>C.content_hash),L.components),collectedAtMs:r,included:$.length>0||U.removed.length>0&&!D||U.full})}let E={user_spec_hash:tt(g),user_spec_count:g.length,user_spec_truncated:p.length>0};u.length>0&&(E.user_spec_scopes=u,E.user_spec_full_scopes=l,E.user_spec_truncated_scopes=p,E.user_spec_cwd_in_git_repo=t.cwdInGitRepo),l.length>0&&l.length===u.length&&(E.user_spec_full=!0),m.length>0&&(E.user_spec=m),d.length>0&&(E.user_spec_removed=d),a.textDeferredCount>0&&(E.user_spec_text_deferred=a.textDeferredCount);let y=t.scopes.cwd;y&&(E.user_spec_cwd_scope_ref=y.scopeRef);let R=t.scopes.repo;R&&(E.user_spec_repo_scope_ref=R.scopeRef);let H=t.scopes.parent;return H&&(E.user_spec_parent_scope_ref=H.scopeRef,t.parentRel&&(E.user_spec_parent_rel=t.parentRel)),{fields:E,scopes:S}}var ct={cwd:"cwd_spec",repo:"repo_spec",parent:"parent_spec"};function Vt(e){return e==="cwd"||e==="repo"||e==="parent"}function at(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function vr(e){return!at(e)||!at(e.components)||!Object.values(e.components).every(t=>typeof t=="string")||!Array.isArray(e.text_hashes)||!e.text_hashes.every(t=>typeof t=="string")?!1:typeof e.collected_at_ms=="number"&&Number.isFinite(e.collected_at_ms)}function Ra(e){return Vm(e)}function Ca(e){return Wm(e)}function Ia(e){return Ym(e)}function Vm(e){if(!at(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&(t[n]=r);return t}function Wm(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function Lr(e,t){if(!at(e))return;let n=e[t];return vr(n)?n:void 0}function Ym(e){if(!at(e))return{};let t={};for(let[n,r]of Object.entries(e))vr(r)&&(t[n]=r);return t}function Ur(e,t=20){let n=[];for(let[r,o]of Object.entries(e))vr(o)&&n.push([r,o]);return n.sort((r,o)=>o[1].collected_at_ms-r[1].collected_at_ms),Object.fromEntries(n.slice(0,t))}var qm=200,Aa=200,Qm=["allow","deny","ask"],eg=/(?<=^|[\s(,=:])(?:~|[A-Za-z]:)?[\\/][^\s,)]+/g,Fr="<path>",tg=new RegExp(`${Fr}(?:\\s+[A-Za-z.][^\\s,)]*[\\\\/][^\\s,)]*)+`,"g");function ng(e){let t=e.replace(eg,Fr).replace(tg,Fr);return t.length>Aa?`${t.slice(0,Aa)}...`:t}function Yt(e){let t=F(e,{}),n=[];for(let r of Qm)for(let o of t.permissions?.[r]??[])typeof o=="string"&&o.length>0&&n.push({key:ng(o),mode:r});return{model:t.model??"",permissionKeys:n}}function rg(e){let{serverManaged:t,fileBased:n}=Nn(process.platform,e),r=Yt(t);if(r.model||r.permissionKeys.length>0)return r;let o="",s=[];for(let i of n){let a=Yt(i);a.model&&(o=a.model),s.push(...a.permissionKeys)}return{model:o,permissionKeys:s}}function og(e){let t=new Set,n=[];for(let r of e){let o=`${r.mode}\0${r.key}`;t.has(o)||(t.add(o),n.push(r))}return n}var sg=10,ig="self-config-cache.json",Pa=2;function Jt(){return I("EV_AI_HOOK_USER_SPEC")?.toLowerCase()==="off"}function ag(){return I("EV_AI_HOOK_CWD_SPEC")?.toLowerCase()==="off"}function cg(e,t=Date.now()){return e===void 0||!Number.isFinite(e)?!0:t-e>=ze}var ug={claude:["claude"],cursor:["agent","cursor-agent"],codex:["codex"]};async function lg(e,t=w){let n=ug[e];if(!n||n.length===0)return null;let r=async o=>{let s=n[o];if(s===void 0)return null;let a=((await t(s,["--version"],2e3)).split(`
|
|
39
|
-
`)[0]??"").trim();return a||r(o+1)};return r(0)}function
|
|
40
|
-
`);return v(n)}function
|
|
41
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: self-config cache write failed open: ${r}`)}}function
|
|
42
|
-
${n}`}function
|
|
43
|
-
`);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
|
|
44
|
-
`,l=I("EV_AI_HOOK_DEBUG");l==="full"?h(`DEBUG envelope=${JSON.stringify(c)}`):l==="1"&&h(`DEBUG summary=${Yg(c,Buffer.byteLength(u,"utf8"))}`);let p=process.argv.includes(en),m=I("EV_AI_HOOK_SYNC")==="1";return Nt(n.runnerEvent,n.runnerPlatform)||p||m?qg(e,u,o):(await Qg(e,u,o),!1)}import{createReadStream as e_}from"node:fs";import{stat as t_}from"node:fs/promises";import{basename as n_,resolve as r_}from"node:path";import{createInterface as o_}from"node:readline";var s_=1024*1024;function i_(e){let t=e.replace(/\\/g,"/");return t.includes("/.claude/projects/")&&n_(t).endsWith(".jsonl")}async function Za(e){if(!e||!i_(e))return null;try{let t=r_(e),n=await t_(t);if(!n.isFile())return null;let r=Math.max(0,n.size-s_),o=[],s=o_({input:e_(t,{encoding:"utf8",start:r}),crlfDelay:1/0});for await(let i of s)i.length!==0&&o.push(i);r>0&&o.length>0&&o.shift();for(let i=o.length-1;i>=0;i--){let a=o[i];if(a)try{let c=JSON.parse(a);if(c.type!=="assistant")continue;let u=c.message;if(!u||typeof u!="object")continue;let l=u.model;if(typeof l=="string"&&l.length>0)return l}catch{continue}}return null}catch{return null}}function nn(e){return{sessionId:e.sessionId,turnId:e.turnId,installationId:e.manifest.installationId,runnerPlatform:e.runnerPlatform,platformAgentId:e.platformAgentId,runnerEvent:e.runnerEvent}}function dt(e,t){return{gitRoot:e.manifest.gitRoot,...t?{home:t}:{}}}function Br(e){return{gitRoot:e.manifest.gitRoot,inGitRepo:e.manifest.inGitRepo,runnerEvent:e.runnerEvent}}async function ec(e){let t=Date.now();await S_(e);let{gitRoot:n}=e.manifest;await rn(e,n);let r=Br(e);return{buildStartedAtMs:t,gitRoot:n,hookInput:Dt(e.hookInput,e.manifest.manifest,r),envelopeFields:nn(e),launchCwd:fr(e.hookInput,r),home:c_()}}function qa(e){try{return z(a_(e))}catch{return null}}function tc(e){return e.startsWith("/")||/^[A-Za-z]:\//.test(e)}function Qa(e,t){let n=e.replaceAll("\\","/");if(!tc(n))return null;let r=z(e),o=z(t),s=qa(e)??r,i=qa(t)??o;return s.startsWith(`${i}/`)?s.slice(i.length+1):r.startsWith(`${o}/`)?r.slice(o.length+1):null}function u_(e,t,n){if(!e)return{repositorySourcePath:null,userSourcePath:null};let r=e.replaceAll("\\","/"),s=Qa(e,t)??(tc(r)?null:r),i=Qa(e,n);return{repositorySourcePath:s,userSourcePath:i}}function tn(e,t,n,r,o,s){let{repositorySourcePath:i,userSourcePath:a}=u_(e,t,n),c=i??a,u=c===null?null:o(c),l=u!==null&&c!==null?l_({installableKind:r,sourcePath:c,nativeKey:u,inRepository:i!==null,platformAgentId:s.platformAgentId,installationId:s.manifest.installationId}):void 0;return{sourcePath:c,nativeKey:u,componentReference:l}}function l_(e){try{let t=e.inRepository?f_(e.platformAgentId,e.sourcePath):(0,P.installationRootExternalKey)(e.installationId,(0,P.userConfigRootFromPath)(e.sourcePath));return t?(0,P.buildComponentReference)({installationRootExternalKey:t,installableKind:e.installableKind,sourcePath:e.sourcePath,nativeKey:e.nativeKey}):void 0}catch{return}}function Gr(e,t,n){return He("tool_invoked",{...n,success:null,duration_ms:null,hook_input:t.hookInput},t.envelopeFields,Fe,e.manifest.collectorUrl,t.buildStartedAtMs,dt(e,t.home))}function d_(e){return Hs(e.runnerEvent,e.runnerPlatform)?[]:ns(e.hookInput)}function p_(e,t){return Gr(e,t,{})}var nc=new Set([...Object.values(Ce),".github"]);function f_(e,t){let n=e.indexOf(":");if(n<=0)return null;let r=e.slice(0,n),o=t.replaceAll("\\","/").split("/").filter(Boolean),s=o.findIndex(i=>nc.has(i));return s<0?null:`${r}:${o.slice(0,s+1).join("/")}`}function m_(e,t,n,r,o,s,i){if(e===null||t===null||!(i!==null||/^mcp__.+?__.+$/i.test(e)||/^MCP:[^:]+:.+$/i.test(e)||/^MCP:.+__.+$/i.test(e)||e.toLowerCase()===`mcp:${t.toLowerCase()}`))return;let c=s.find(g=>g.name.toLowerCase()===t.toLowerCase()),u=c?.sourcePath??(c?.source==="claude_json_user"?".claude.json":c?.source==="cursor_mcp_user"?".cursor/mcp.json":c?.source==="codex_toml_user"||c===void 0&&o==="codex"?".codex/config.toml":void 0);if((c?.scope==="user"||c?.source==="claude_json_user"||c?.source==="cursor_mcp_user"||c?.source==="codex_toml_user"||c===void 0&&o==="codex")&&u)try{let g=(0,P.userConfigRootFromPath)(u);return(0,P.buildComponentReference)({installationRootExternalKey:(0,P.installationRootExternalKey)(r,g),installableKind:P.ComponentKind.INTERFACE,sourcePath:u,nativeKey:c?.name??t})}catch{return}if(n===null)return;let p=n.indexOf(":");if(p<=0||p===n.length-1)return;let m=n.slice(p+1),d=m.replaceAll("\\","/").split("/").at(-1);if(!(d===void 0||!nc.has(d)))try{return(0,P.buildComponentReference)({installationRootExternalKey:n,installableKind:P.ComponentKind.INTERFACE,sourcePath:m,nativeKey:t})}catch{return}}function g_(...e){for(let t of e)if(t)return t;return null}function W(e,t,n){if(e.status==="fulfilled")return e.value;let r=e.reason instanceof Error?e.reason.message:String(e.reason);return h(`WARN: ${n} failed open: ${r}`),t}function __(e){let t={present:!1,size:0},n={hash:"",count:0};return{config:{runner_platform:e,config_scope:"user",cli_version:null,claude_version:null,model:null,permission_keys:[],user_scope:{skills:n,subagents:n,commands:n,rules:n,memory:t,settings:t,mcp:t},local_settings:t},commit:()=>{}}}function h_(e,t){return{runner_platform:e,config_scope:"user",...t?{operator:t}:{}}}var Oe=new Set,lt=null;async function S_(e){if(Jt())return;let t=e.manifest.installationId,n=e.manifest.installationStorePath;if(Oe.has(t))return;if(!cr(n)){Oe.add(t);return}let r=$e({sessionId:e.sessionId,hostname:Ke()});if(bi(r)){if(lt){await lt;return}lt=(async()=>{if(Oe.has(t)||!cr(n)){Oe.add(t);return}if(!Do(n)){Oe.add(t);return}let o=!1;try{let s=Date.now(),{gitRoot:i}=e.manifest,a=String(e.runnerPlatform),[c,u,l,p,m]=await Promise.allSettled([Xe(i),_n(),er(r),hn(),ar({gitRoot:i,installationStorePath:n,forceResend:!1,runnerPlatform:a})]),d=W(c,null,"gitSnapshot"),g=W(u,"","detectVirt"),S=W(l,null,"probeCloud"),E=W(p,{},"hostEnv"),y=W(m,{commit:()=>{}},"resolveOperatorForSend");await rn(e,i,d);let R={identity:{host:Ke(),context:r,virt:g||null,cloud:S,git:d},host_env:E,env_vars:tr(),self_config:h_(a,y.operator),run_meta:{trigger:"cloud_identity_bootstrap"}};o=!!await He("session_start",R,nn(e),Fe,e.manifest.collectorUrl,s,dt(e)),o&&(y.commit(),Oe.add(t))}finally{Fo(n)}})().finally(()=>{lt=null}),await lt}}async function rn(e,t,n){try{let r=n===void 0?await Xe(t):n;e.platformAgentId=await Os(e.manifest.manifest,e.platformAgentId,String(e.runnerPlatform),t,r,e.manifest.installationStorePath,e.manifest.repoKey)}catch(r){let o=r instanceof Error?r.message:String(r);h(`WARN: derivePlatformAgentId failed open: ${o}`)}}async function E_(e){let t=Date.now(),{gitRoot:n}=e.manifest,r=$e({sessionId:e.sessionId,hostname:Ke()}),o=String(e.runnerPlatform),s=Br(e),i=fr(e.hookInput,s),a=Xe(n),c=Ka().catch(()=>({})),u=Jt()?Promise.resolve({commit:()=>{}}):ar({gitRoot:n,installationStorePath:e.manifest.installationStorePath,forceResend:!1,runnerPlatform:o}),[l,p,m,d,g,S,E]=await Promise.allSettled([a,_n(),er(r),hn(),Wn(e.manifest.manifest,n,o),a.catch(()=>null).then(Y=>Ta(o,n,void 0,{installationStorePath:e.manifest.installationStorePath,gitRoot:n,launchCwd:i,inGitRepo:e.manifest.inGitRepo,remote:Y?.remote??null})),u]),y=W(l,null,"gitSnapshot"),R=W(p,"","detectVirt"),H=W(m,null,"probeCloud"),k=W(d,{},"hostEnv"),x=W(g,[],"mcpDeclared"),L=W(S,__(o),"selfConfig"),U=W(E,{commit:()=>{}},"resolveOperatorForSend"),$=L.config;await rn(e,n,y);let q=_(e.hookInput,"model");q&&($.model=q);let D={identity:{host:Ke(),context:r,virt:R||null,cloud:H,git:y},host_env:k,env_vars:tr(),mcp:{declared:x},self_config:$,run_meta:{trigger:e.hookSource||"startup"},hook_input:Dt(e.hookInput,e.manifest.manifest,{...s,launchCwd:i})},N=await c;await He("session_start",D,{...nn(e),...N},Fe,e.manifest.collectorUrl,t,dt(e))&&(L.commit(),U.commit(),Oe.add(e.manifest.installationId))}async function y_(e){let t=Date.now(),{gitRoot:n}=e.manifest;await rn(e,n);let r=e.runnerEvent.toLowerCase(),o=g_(_(e.hookInput,"status"),_(e.hookInput,"stop_reason"),_(e.hookInput,"reason"),Qe(_(e.hookInput,"error")),r==="stop"?re(e.hookInput,"is_interrupt")===!0?"interrupted":"completed":""),s=e.runnerPlatform==="claude"?await Za(_(e.hookInput,"transcript_path")):null,i=Dt(e.hookInput,e.manifest.manifest,Br(e));s&&(i.model=s),r!=="stopfailure"&&!Li(e.manifest.manifest)&&i.last_assistant_message===void 0&&(i.last_assistant_message=""),await He("session_end",{status:o,...s?{model:s}:{},hook_input:i},nn(e),Fe,e.manifest.collectorUrl,t,dt(e))}function rc(e,t,n,r){let o=r??ts({skillId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home}),s=tn(o,t.gitRoot,t.home,P.ComponentKind.SKILL,P.nativeKeyForSkillPath,e);if(s.sourcePath!==null&&wn(s.sourcePath)?.toLowerCase()===n.toLowerCase())return s.componentReference===void 0?{}:{componentReference:s.componentReference};let i=r??bs({commandId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),a=tn(i,t.gitRoot,t.home,P.ComponentKind.COMMAND,P.nativeKeyForCommandPath,e);return a.nativeKey?.toLowerCase()!==n.toLowerCase()?{}:{commandName:a.nativeKey,...a.componentReference===void 0?{}:{componentReference:a.componentReference}}}function R_(e,t,n){let r=At(e.hookInput.tool_input);return Promise.all(n.map(o=>{let s=rc(e,t,o,r);return Gr(e,t,{tool_name:"Skill",skill_name:o,...s.commandName===void 0?{}:{command_name:s.commandName},...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}function C_(e,t,n){return Promise.all(n.map(r=>{let o=Ps({relativePath:r,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),s=tn(o,t.gitRoot,t.home,P.ComponentKind.RULE,P.nativeKeyForRulePath,e),i=s.nativeKey??ks(r);return Gr(e,t,{tool_name:"Rule",rule_name:i,...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}var I_=[{kind:P.ComponentKind.SKILL,nativeKeyFn:P.nativeKeyForSkillPath},{kind:P.ComponentKind.RULE,nativeKeyFn:P.nativeKeyForRulePath},{kind:P.ComponentKind.COMMAND,nativeKeyFn:P.nativeKeyForCommandPath}];function A_(e,t,n){if(n.skillName===null&&n.ruleName===null&&n.commandName===null)return{};let r=Ln(e.hookInput);if(r===null)return n.skillName===null?{}:rc(e,t,n.skillName,null);for(let o of I_){let s=tn(r,t.gitRoot,t.home,o.kind,o.nativeKeyFn,e);if(s.nativeKey!==null)return{...s.componentReference===void 0?{}:{componentReference:s.componentReference},...o.kind===P.ComponentKind.RULE?{ruleName:s.nativeKey}:{},...o.kind===P.ComponentKind.COMMAND?{commandName:s.nativeKey}:{}}}return{}}var O_=/mcp/i;function P_(e,t,n,r){let o=O_.test(e.runnerEvent);if(!r.hasMcpIdentity&&!o)return{};let s=o?la(t,n):zt(r.declaredConfig,n);return s===null?{}:Object.fromEntries(Object.entries(s).filter(i=>typeof i[1]=="string").map(([i,a])=>[`mcp_${i}`,a]))}async function T_(e){let t=await ec(e),n=Gs(e.hookInput,e.runnerEvent),{toolName:r,skillName:o}=n,s=vn(e.hookInput),i=ca(s,t.home),a=Vs(e.hookInput),c=js(e.runnerEvent),u=c===!1?Ws(e.hookInput,e.runnerEvent):null,l=await Wn(e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home).catch(()=>[]),p=Qe(_(e.hookInput,"mcp_server_name")),{mcpServer:m,mcpTool:d}=Ys(r,l.map(L=>L.name),p??""),g=m_(r,m,e.platformAgentId,e.manifest.installationId,String(e.runnerPlatform),l,p),S=g===void 0?A_(e,t,n):{},E=m===null?null:Us(m,e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home),y=P_(e,s,t.home,{hasMcpIdentity:!!m||!!d,declaredConfig:E}),R=g??S.componentReference,H=S.ruleName??n.ruleName,k=S.commandName??n.commandName,x=zs(e.hookInput);await He("tool_invoked",{tool_name:r,skill_name:o,...H?{rule_name:H}:{},...k?{command_name:k}:{},success:c,duration_ms:a,...i?{executable:i}:{},...u?{failure_reason:u}:{},...m?{mcp_server:m}:{},...d?{mcp_tool:d}:{},...y,...R?{component_reference:R}:{},...x?{subagent_type:x}:{},hook_input:t.hookInput},t.envelopeFields,Fe,e.manifest.collectorUrl,t.buildStartedAtMs,dt(e,t.home))}async function oc(e){switch(e.internalEvent){case"session_start":await E_(e);return;case"session_end":await y_(e);return;case"skill_invoked":{let t=d_(e),n=xs(e.hookInput),r=Fs(e.runnerEvent);if(t.length===0&&n.length===0&&!r)return;let o=await ec(e);await Promise.all([r&&t.length===0&&n.length===0?p_(e,o):void 0,t.length===0?void 0:R_(e,o,t),n.length===0?void 0:C_(e,o,n)]);return}case"tool_invoked":await T_(e);return;default:return}}function sc(e){return e!=="session_start"&&e!=="session_end"&&e!=="tool_invoked"&&e!=="skill_invoked"&&e!==""}import{existsSync as Vr,readFileSync as k_}from"node:fs";import{dirname as x_,isAbsolute as b_,join as N_,relative as M_}from"node:path";function ic(e){for(let t of lo){let n=N_(e,t);if(Vr(n))return n}}async function w_(e=process.cwd(),t){let n=t??await pn(e);return ic(n)??ic(e)}async function v_(e,t){let n=t??await pn(x_(e)),r=M_(n,e);if(r.startsWith("..")||b_(r))return!1;let o=await J("git",["ls-files","--error-unmatch",r],2e3,{cwd:n});return o.ok?!0:o.code===1?!1:(h(`WARN: git ls-files failed for manifest ${e} (code=${String(o.code)}); treating as tracked`),!0)}function zr(e){let t=k_(e,"utf8");return j(t,{})}function L_(){return{schema_version:Et,mcp_servers:[]}}function U_(e,t,n,r){!t||!n||(e.capture_hook_input==="full"&&r.has("capture_hook_input")&&(h(`WARN: ignoring capture_hook_input=full in git-tracked manifest ${t}; use EV_AI_HOOK_CAPTURE_FULL_INPUT=1 or an untracked operator manifest`),delete e.capture_hook_input),e.debug===!0&&r.has("debug")&&(h(`WARN: ignoring debug=true in git-tracked manifest ${t}; set debug on ~/.ev-ai/config.json`),delete e.debug))}async function ac(e=process.cwd(),t={}){let{root:n,inGitRepo:r}=await dn(e),o=I("EV_AI_HOOK_MANIFEST"),s=o&&Vr(o)?o:void 0,i=s?void 0:Vr(En())?En():void 0,a=s?void 0:await w_(e,n),c=i?zr(i):void 0,u=a?zr(a):void 0,l,p,m,d=new Set;if(s){l=zr(s),p=s,m=s;for(let R of Object.keys(l))d.add(R)}else if(c&&u){l=po(u,c),p=i,m=a;for(let R of Object.keys(u))R in c||d.add(R)}else if(c)l=c,p=i;else if(u){l=u,p=a,m=a;for(let R of Object.keys(u))d.add(R)}else l=L_();delete l.installation_id;let g=m?await v_(m,n):!1;U_(l,m,g,d);let{installationId:S,storePath:E,repoKey:y}=await Ko(n,{sessionId:t.sessionId});return{manifestPath:p??E,manifest:l,installationId:S,installationStorePath:E,repoKey:y,collectorUrl:Cn(l),platformAgentId:l.platform_agent_id??"",gitRoot:n,inGitRepo:r}}import{createHash as D_}from"node:crypto";import{mkdirSync as F_,readdirSync as H_,readFileSync as j_,statSync as cc,unlinkSync as $_,writeFileSync as K_}from"node:fs";import{homedir as on}from"node:os";import{join as Wr}from"node:path";var B_="turns",uc=1440*60*1e3,G_=100,z_=new Set(["stop","stopfailure","sessionend"]);function Yr(e=on()){return Wr(oe(e),B_)}function V_(e){return D_("sha256").update(e).digest("hex").slice(0,32)}function lc(e,t){return Wr(e,V_(t))}function W_(e,t=Date.now()){let n;try{n=H_(e)}catch{return}let r=0;for(let o of n){if(r>=G_)return;r+=1;try{let s=Wr(e,o);t-cc(s).mtimeMs>uc&&$_(s)}catch{}}}function Y_(e,t,n=on()){let r=e.trim(),o=t.trim();if(!(!r||!o))try{let s=Yr(n);F_(s,{recursive:!0}),K_(lc(s,r),o,"utf8")}catch{}}function J_(e,t=on()){let n=e.trim();if(!n)return"";try{let r=lc(Yr(t),n);return Date.now()-cc(r).mtimeMs>uc?"":j_(r,"utf8").trim()}catch{return""}}function dc(e,t,n,r=on()){let o=t.trim(),s=z_.has(n.trim().toLowerCase());return s&&W_(Yr(r)),o?(Y_(e,o,r),o):s?J_(e,r):""}async function pc(e,t,n,r){let o=t??await ln(An),s=j(o,{}),i=_(s,"session_id")||_(s,"conversation_id"),a=await ac(process.cwd(),{sessionId:i});if(!a)return;r&&(a.collectorUrl=r);let c=$s(s,a.manifest.platform,n),u=Ks(e,c.runnerEvent);if(!u){h(`WARN: unknown hook event '${c.runnerEvent}'; skipping telemetry`);return}let l={hookInput:s,sessionId:c.sessionId,turnId:dc(c.sessionId,c.turnId,c.runnerEvent),runnerEvent:c.runnerEvent,runnerPlatform:c.runnerPlatform,hookSource:c.hookSource,internalEvent:u,manifest:a,platformAgentId:a.platformAgentId};if(sc(u)){h(`WARN: unsupported internal event '${u}'`);return}await oc(l)}function X_(e,t){if(I("EV_AI_HOOK_SYNC")==="1")return!0;let n=Be(e),r=j(t,{}),o=n.event??(_(r,"hook_event_name")||_(r,"event")),s=qe(r,o,void 0,n.runner);return Nt(o,s)}async function fc(e=process.argv.slice(2)){if(ai(),e[0]===Kr){try{await Ya(un)}catch{}return 0}if(e[0]===en){try{let t=Be(e.slice(1)),n=await un(),r=j(n,{}),o=t.event??(_(r,"hook_event_name")||_(r,"event"));if(mn()||Jn(t.runner,r,o))return 0;await pc(t.event,n,t.runner,Yn(t))}catch(t){let n=t instanceof Error?t.message:String(t);h(`WARN: detached work failed open: ${n}`)}return 0}try{let t=await ln(An),n=Be(e),r=Yn(n),o=j(t,{}),s=n.event??(_(o,"hook_event_name")||_(o,"event"));if(mn()||Jn(n.runner,o,s)||!ti(o,s,n.runner))return 0;X_(e,t)?await pc(n.event,t,n.runner,r):await Xa(t,e)}catch(t){let n=t instanceof Error?t.message:String(t);h(`WARN: hook failed open: ${n}`)}finally{to()}return 0}fc().then(e=>{process.exit(e)}).catch(e=>{let t=e instanceof Error?e.message:String(e);process.stderr.write(`[ev-ai-agent-hook] ${t}
|
|
29
|
+
`.trim(),tr=new Map;function wi(e){if(typeof e=="string"){let t=e.trim();return t.length>0?t:null}if(e instanceof Uint8Array){let t=Buffer.from(e).toString("utf8").trim();return t.length>0?t:null}return null}function Li(e){return e.toLowerCase().includes("token")}function Ui(e){let t=new Map;if(!Array.isArray(e))return t;for(let n of e){if(n===null||typeof n!="object")continue;let r=n,o=wi(r.key),s=wi(r.value);o&&s&&!Li(o)&&t.set(o,s)}return t}function Sf(e){let t=hf(e);return t.search="mode=ro&immutable=1",t.href}function Ef(e){try{let t=vi("bun:sqlite");if(typeof t.Database!="function")return null;let n=new t.Database(e,{readonly:!0,create:!1});try{let r=n.query?.(Ht)??n.prepare(Ht);return Ui(r.all?.())}finally{n.close?.()}}catch{return null}}function yf(e){let t=process.emitWarning.bind(process);process.emitWarning=((n,...r)=>{(typeof n=="string"?n:n instanceof Error?n.message:"").includes("SQLite is an experimental feature")||t(n,...r)});try{return e()}finally{process.emitWarning=t}}function Rf(e){try{return yf(()=>{let t=vi("node:sqlite");if(typeof t.DatabaseSync!="function")return null;let n=new t.DatabaseSync(e,{readOnly:!0});try{return Ui(n.prepare(Ht).all?.())}finally{n.close?.()}})}catch{return null}}function Cf(e){let t=new Map;for(let n of e.split(`
|
|
30
|
+
`)){let r=n.trimEnd();if(!r)continue;let o=r.indexOf(" ");if(o<=0)continue;let s=r.slice(0,o).trim(),i=r.slice(o+1).trim();s&&i&&!Li(s)&&t.set(s,i)}return t}function If(e){try{let t=mf("sqlite3",["-noheader","-batch","-separator"," ",e,Ht],{encoding:"utf8",timeout:2e3,maxBuffer:65536,windowsHide:!0,stdio:["ignore","pipe","ignore"]});return Cf(t)}catch{return null}}function Di(e){let t=tr.get(e);if(t)return t;if(!gf(e)){let o=new Map;return tr.set(e,o),o}let n=Sf(e),r=Ef(n)??If(n)??Rf(n)??new Map;return tr.set(e,r),r}var Af="cursorAuth/cachedEmail",Of="cursorAuth/stripeMembershipAuthId";function jt(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Pf(e=$t(),t=process.platform,n=process.env){let r=jt(n.VSCODE_PORTABLE);if(r)return se(r,"user-data");let o=jt(n.VSCODE_APPDATA);if(o)return se(o,"Cursor");switch(t){case"darwin":return se(e,"Library","Application Support","Cursor");case"win32":return se(jt(n.APPDATA)??se(e,"AppData","Roaming"),"Cursor");default:return se(jt(n.XDG_CONFIG_HOME)??se(e,".config"),"Cursor")}}function Tf(e=$t()){return se(e,".cursor","cli-config.json")}function kf(e=$t(),t=process.platform,n=process.env){return se(Pf(e,t,n),"User","globalStorage","state.vscdb")}function tt(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function xf(e){return typeof e.userId=="number"&&Number.isFinite(e.userId)?String(e.userId):tt(e.userId)}function bf(e){return tt(e.email)??tt(e.authId)??xf(e)}function nr(e){let t=tt(e.email),n=tt(e.displayName),r=bf(e);return!r||B(n,t)?null:{git_user_name:null,git_user_email:null,platform_login:r,identity_source:"cursor_oauth"}}function Nf(e){let n=L(Tf(e),{}).authInfo;return!n||typeof n!="object"?null:nr(n)}function Mf(e,t,n){let r=kf(e,process.platform,t),o=xi(e),s=bi(o);if(Ni(s,r,n))return nr({email:s?.email,authId:s?.auth_id});let i=Di(r),a=i.get(Af)??null,c=i.get(Of)??null;return Mi(o,{read_at_ms:n,db_path:r,email:a,auth_id:c}),nr({email:a,authId:c})}function Fi(e=$t(),t=process.env,n=Date.now()){return Nf(e)??Mf(e,t,n)}import{createHash as wf}from"node:crypto";import{resolve as vf}from"node:path";function v(e){return wf("sha256").update(e).digest("hex").slice(0,16)}function rr(e){return v(vf(e))}function z(e,t){return`${e}\0${t}`}function Hi(e){let t=e.indexOf("\0");return t<=0?null:{path:e.slice(0,t),name:e.slice(t+1)}}function nt(e){let n=[...e].sort((r,o)=>{let s=r.path.localeCompare(o.path);return s!==0?s:r.name.localeCompare(o.name)}).map(r=>`${r.path}|${r.name}|${r.content_hash}`).join(`
|
|
31
|
+
`);return v(n)}function Uf(e,t,n="git_config",r=null){return v(`${e??""}|${t??""}|${r??""}|${n}`)}function Df(e){let t=null,n=null;for(let r of e.split(`
|
|
32
|
+
`)){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 Ff(e,t=M){let n=await t("git",["config","--get-regexp","^user\\.(name|email)$"],2e3,{cwd:e});return Df(n)}function Hf(e=process.env){let t=O(e.GIT_AUTHOR_NAME),n=O(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=O(e.GIT_COMMITTER_NAME),o=O(e.GIT_COMMITTER_EMAIL);if(r||o)return{git_user_name:r,git_user_email:o,platform_login:null,identity_source:"git_env"};let s=O(e.EMAIL);return s?{git_user_name:null,git_user_email:s,platform_login:null,identity_source:"git_env"}:null}function ie(e,t,n,r=null){return!e&&!t&&!r?null:{git_user_name:e,git_user_email:t,platform_login:r,identity_source:n}}function jf(e=process.env){let t=O(e.EV_AI_HOOK_OPERATOR_EMAIL),n=O(e.EV_AI_HOOK_OPERATOR_LOGIN),r=ie(O(e.EV_AI_HOOK_OPERATOR_NAME),t,"configured",t??n);if(r)return r;let o=O(e.GITHUB_ACTOR)??O(e.GITHUB_TRIGGERING_ACTOR)??O(e.GITHUB_USER),s=ie(o,null,"github",o);if(s)return s;let i=O(e.GITLAB_USER_LOGIN),a=O(e.GITLAB_USER_EMAIL),c=ie(O(e.GITLAB_USER_NAME)??i,a,"gitlab",a??i);if(c)return c;let l=O(e.BUILD_REQUESTEDFOREMAIL),u=ie(O(e.BUILD_REQUESTEDFOR),l,"azure_devops",l??O(e.BUILD_REQUESTEDFORID));if(u)return u;let p=O(e.BUILDKITE_BUILD_CREATOR_EMAIL),m=ie(O(e.BUILDKITE_BUILD_CREATOR),p,"buildkite",p);if(m)return m;let d=O(e.BUILD_USER_EMAIL)??O(e.CHANGE_AUTHOR_EMAIL),g=ie(O(e.BUILD_USER)??O(e.CHANGE_AUTHOR),d,"jenkins",d??O(e.BUILD_USER_ID));if(g)return g;let _=O(e.CIRCLE_USERNAME),S=ie(_,null,"circleci",_);if(S)return S;let E=O(e.CODEBUILD_INITIATOR),y=ie(E,null,"codebuild",E);if(y)return y;let D=O(e.DRONE_COMMIT_AUTHOR_EMAIL),k=O(e.DRONE_COMMIT_AUTHOR),x=ie(k??O(e.DRONE_COMMIT_AUTHOR_NAME),D,"drone",D??k);if(x)return x;if(ji(e.CLAUDE_CODE_REMOTE)||ji(e.CURSOR_AGENT)){let U=O(e.CURSOR_USER_EMAIL);return{git_user_name:null,git_user_email:null,platform_login:U&&!B(null,U)?U:null,identity_source:"cloud"}}return null}function or(e){return!!((e.git_user_name??e.git_user_email)&&!B(e.git_user_name,e.git_user_email))}function O(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function ji(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function $f(e,t,n){return e==="claude"?Ci(t):e==="cursor"?Fi(t,n):e==="codex"?Ti(n,t):null}async function sr(e,t=M,n=process.env,r={}){let o=await Ff(e,t),s=Hf(n),i=or(o)?o:s&&or(s)?s:null,a=$f(r.runnerPlatform,r.home??Lf(),n);if(a)return{git_user_name:i?.git_user_name??null,git_user_email:i?.git_user_email??null,platform_login:a.platform_login,identity_source:a.identity_source};let c=jf(n);return c?.platform_login?{git_user_name:i?.git_user_name??null,git_user_email:i?.git_user_email??null,platform_login:c.platform_login,identity_source:c.identity_source}:i?{...i,platform_login:null,identity_source:or(o)?"git_config":"git_env"}:c||(o.git_user_name||o.git_user_email?{...o,identity_source:"git_config"}:s||{git_user_name:null,git_user_email:null,platform_login:null,identity_source:"git_config"})}async function ir(e){let{gitRoot:t,installationStorePath:n,forceResend:r}=e,o=e.exec??M,s=e.env??process.env,i=await sr(t,o,s,{runnerPlatform:e.runnerPlatform,home:e.home}),a=Uf(i.git_user_name,i.git_user_email,i.identity_source,i.platform_login),l=(n?xn(n):void 0)?.operator_identity_hash;if(!(r||l!==void 0&&l!==a||!l))return{commit:()=>{}};let d=n;return{operator:i,commit:()=>{d&&jo(d,a,mt())}}}function ar(e){return e?!xn(e)?.operator_identity_hash:!0}function $i(e){return!0}import{existsSync as fg,readFileSync as mg}from"node:fs";import{homedir as Ua}from"node:os";import{join as Fe,resolve as gg}from"node:path";import{basename as ig,join as De}from"node:path";import{dirname as qi,resolve as Gt}from"node:path";import{existsSync as Kf}from"node:fs";import{homedir as Gi}from"node:os";import{relative as zi,resolve as Q,sep as fe}from"node:path";var Bf=["session_id","conversation_id","turn_id","generation_id","prompt.id","prompt_id","hook_event_name","event","source","status","stop_reason","reason","tool_name","tool","tool_use_id","skill_name","command_name","expansion_type","command_source","permission_mode","model","model_id","agent_id","agent_type","subagent_id","subagent_type","subagent_model","is_parallel_worker","effort","effort.level","duration_ms","duration","sandbox","failure_type","is_interrupt"],Gf=["prompt","tool_input","tool_response","last_assistant_message","command"],zf=new Set;function Vf(e){switch(e?.toLowerCase()){case"beforemcpexecution":return new Set(["command"]);case"stopfailure":return new Set(["last_assistant_message"]);default:return zf}}function Vi(e){return Wi(e)==="allowlist"}function Wi(e){return I("EV_AI_HOOK_CAPTURE_CONTENT")?.toLowerCase()==="off"||e.capture_hook_input==="allowlist"?"allowlist":e.capture_hook_input==="full"||e.debug===!0||I("EV_AI_HOOK_CAPTURE_FULL_INPUT")==="1"?"full":"content"}function Wf(e){let t={};for(let n of Bf){let r=te(e,n);r!==void 0&&(t[n]=r)}return t}function Kt(e,t){if(typeof e!="string"||e.length===0||!t)return null;let n=Q(e),r=Q(t),o=zi(r,n);return!o||o==="."?".":o.startsWith(`..${fe}`)||o===".."||Q(r,o)!==n?null:o.split(fe).join("/")}function Yi(e,t){let n=zi(Q(t),Q(e)).split(fe).join("/");return!n||n==="."?null:n===".."||n.startsWith("../")&&n.split("/").every(r=>r==="..")?n:null}function Ji(e){return typeof e!="string"||e.length===0?null:Q(e).split(fe).join("/")}function Yf(){let e=I("CURSOR_PROJECT_DIR");if(!e)return null;let t=Q(e);return Kf(t)?t.split(fe).join("/"):null}function ur(e,t){return Kt(e,t)!==null}function Jf(e,t){let n=Q(t??Gi(),".cursor").split(fe).join("/");return ur(e,n)}function Xf(e,t,n){return t!==null&&ur(e,t)?!0:t!==null&&Jf(e,n.home)?!1:n.inGitRepo===!0&&n.gitRoot!==void 0&&ur(e,n.gitRoot)?!0:t===null}function Xi(e,t){let n=Ji(e.cwd);if(n!==null)return n;let r=Q(process.cwd()).split(fe).join("/"),o=Yf();return Xf(r,o,t)?r:o??r}function pr(e,t={}){return Xi(e,t)}function fr(e,t=Gi()){let n=Q(t).split(fe).join("/").replace(/\/$/,"");return n.length<=1?e:e===n?"~":e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function Ki(e,t,n){let r=Ji(n.launchCwd)??Xi(t,n);e.cwd=fr(r,n.home);let o=n.inGitRepo===!0&&n.gitRoot!==void 0?Kt(r,n.gitRoot):null;o!==null&&(e.cwd_relative=o)}var Zi="\u2026[truncated]\u2026",lr=Buffer.byteLength(Zi,"utf8"),Zf=8;function rt(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function Bi(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(0,t).toString("utf8")}function qf(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(n.length-t).toString("utf8")}function Qf(e,t){if(Buffer.byteLength(e,"utf8")<=t)return e;if(t<=lr)return Bi(e,t);let r=t-lr,o=Math.ceil(r/2),s=Math.floor(r/2);return`${Bi(e,o)}${Zi}${qf(e,s)}`}function dr(e,t,n){if(typeof e=="string"){n.push({path:t,value:e,bytes:Buffer.byteLength(e,"utf8")});return}if(Array.isArray(e)){e.forEach((r,o)=>{dr(r,[...t,o],n)});return}if(e!==null&&typeof e=="object")for(let[r,o]of Object.entries(e))t.length===0&&r.startsWith("_")||dr(o,[...t,r],n)}function em(e,t,n){let r=e;for(let s=0;s<t.length-1;s++){let i=t[s];if(i===void 0)return;r=(Array.isArray(r),r[i])}let o=t[t.length-1];if(!(o===void 0||r===null||typeof r!="object")){if(Array.isArray(r)){r[o]=n;return}r[o]=n}}var tm=256;function nm(e,t,n){let r=n,o=Math.max(n,e[0]?.bytes??n);for(;r<o;){let s=Math.ceil((r+o)/2),i=0;for(let a of e)a.bytes>s&&(i+=a.bytes-s);i>=t?r=s:o=s-1}return r}function rm(e,t,n){let r=Number.POSITIVE_INFINITY;for(let o=0;o<6;o++){let s=rt(e);if(s<=t)return;let i=[];dr(e,[],i),i.sort((u,p)=>p.bytes-u.bytes);let a=i.filter(u=>u.bytes>n);if(a.length===0)return;let c=nm(a,s-t,n),l=Math.max(n,Math.min(c,r-1));if(l>=r)return;r=l;for(let u of a)u.bytes>r&&em(e,u.path,Qf(u.value,r))}}function om(e,t){let n=Math.max(0,t-tm),r=Object.keys(e).filter(s=>!s.startsWith("_")).map(s=>({key:s,bytes:rt(e[s])})).sort((s,i)=>i.bytes-s.bytes),o=[];for(let{key:s}of r){if(rt(e)<=n)break;delete e[s],o.push(s)}o.length>0&&(e._dropped_keys=o.slice(0,10))}function cr(e,t){let n=rt(e);if(n<=t)return e;let r=structuredClone(e);return r._truncated=!0,r._original_bytes=n,rm(r,t,lr+Zf),rt(r)>t&&om(r,t),r}function sm(e,t,n){let r=Vf(n.runnerEvent);for(let o of Gf){if(r.has(o))continue;let s=t[o];s!==void 0&&(e[o]=s)}}function Bt(e,t,n={}){let r=Wi(t);if(r==="full"){let s={...e};return delete s.cwd,delete s.transcript_path,Ki(s,e,n),cr(s,An)}let o=Wf(e);return Ki(o,e,n),r==="content"?(sm(o,e,n),cr(o,An)):cr(o,Ao)}function im(e){return typeof e=="string"&&e.length>0}function mr(e){let t=Gt(e.home),n=Gt(e.launchCwd),r=e.gitRoot?Gt(e.gitRoot):null,o=new Set,s=[],i=null;e.inGitRepo&&im(e.remote)&&r!==null&&r!==t&&(i=r,o.add(r)),n!==t&&!o.has(n)&&(s.push({scope:"cwd",dir:n}),o.add(n)),i!==null&&s.push({scope:"repo",dir:i});let a=null,c=r!==null&&Kt(n,r)!==null;if(e.inGitRepo&&r!==null&&r!==t&&c){let l=qi(r);for(;;){let u=Gt(l);if(u===t)break;let p=qi(u);if(p===u)break;if(e.hasProjectSpec(u)){s.push({scope:"parent",dir:u}),a=Yi(u,n);break}l=p}}return{anchors:s,parentRel:a}}import{existsSync as Qi,readdirSync as am,realpathSync as cm}from"node:fs";import{basename as um,dirname as lm,relative as dm,resolve as pm,sep as fm}from"node:path";var gr=400,zt=class{constructor(t,n={}){this.home=t;this.pathMode=n.pathMode??"home-relative",this.maxEntries=n.maxEntries??ae}components=[];truncated=!1;pathMode;maxEntries;pluginExpandRemaining;seenRealpaths=new Set;componentPath(t){if(this.pathMode==="tilde"){let r=pm(t).split(fm).join("/");return fr(r,this.home)}let n=dm(this.home,t).replace(/\\/g,"/");return!n||n.startsWith("..")?`external/${v(lm(t))}/${um(t)}`:n}claimFile(t){try{let n=cm(t);return this.seenRealpaths.has(n)?!1:(this.seenRealpaths.add(n),!0)}catch{return this.seenRealpaths.has(t)?!1:(this.seenRealpaths.add(t),!0)}}get atGlobalCap(){return this.truncated||this.components.length>=this.maxEntries}get pluginBudgetSpent(){return this.pluginExpandRemaining!==void 0&&this.pluginExpandRemaining<=0}readEntries(t){if(!Qi(t))return[];try{return am(t,{withFileTypes:!0})}catch{return[]}}readJson(t,n){if(Qi(t))return L(t,n)}push(t){return this.components.length>=this.maxEntries?(this.truncated=!0,!1):this.pluginExpandRemaining!==void 0&&this.pluginExpandRemaining<=0?!1:(this.pluginExpandRemaining!==void 0&&(this.pluginExpandRemaining-=1),this.components.push(t),!0)}withPluginExpandCap(t,n){let r=this.pluginExpandRemaining;this.pluginExpandRemaining=t;try{let o=n(),s=t-(this.pluginExpandRemaining??0);return{result:o,expanded:s}}finally{this.pluginExpandRemaining=r}}};import{existsSync as _r,readFileSync as mm,statSync as gm}from"node:fs";import{basename as ta,join as ot,relative as na}from"node:path";var hr=100*1024,_m=4;function hm(e){return e.length<=hr?e:`${e.slice(0,hr-1)}\u2026`}function Sm(e){try{let t=mm(e),n=t.toString("utf8");return{hash:v(t),length:t.length,text:hm(n)}}catch{return null}}var ea={HOOK:"EVENT",COMMAND:"EXPLICIT_INVOCATION",MEMORY:void 0,MCP_SERVER:void 0,PLUGIN:void 0,SKILL:"UNSPECIFIED",RULE:"UNSPECIFIED",SUBAGENT:"UNSPECIFIED"};function Em(e){return e in ea?ea[e]:"UNSPECIFIED"}function Vt(e,t){if(!e.claimFile(t.absolutePath))return!1;let n=Sm(t.absolutePath);if(!n)return!1;let r=t.name??ta(t.absolutePath).replace(/\.(md|mdc|toml)$/i,""),o={kind:t.kind,name:r,path:e.componentPath(t.absolutePath),text:n.text,content_hash:n.hash,content_length:n.length,origin:t.origin,enabled:t.enabled},s=Em(t.kind);return s&&(o.trigger=s),e.push(o)}function ym(e,t,n){let r=na(e,t).replace(/\\/g,"/");return!r||r.startsWith("..")?ta(t).replace(/\.(md|mdc|toml)$/i,""):n?r.replace(/\.(md|mdc|toml)$/i,""):r}function Ce(e,t){let{dir:n,kind:r,origin:o,enabled:s,nested:i,extensions:a}=t;Sr(e,{walkRoot:n,currentDir:n,depth:0,kind:r,origin:o,enabled:s,nested:i,extensions:a})}function Sr(e,t){let{walkRoot:n,currentDir:r,depth:o,kind:s,origin:i,enabled:a,nested:c,extensions:l}=t;if(!(o>_m))for(let u of e.readEntries(r)){if(e.atGlobalCap){e.truncated=!0;return}if(e.pluginBudgetSpent)return;if(c){if(!u.isDirectory())continue;let d=ot(r,u.name,c);if(_r(d)){let g=na(n,ot(r,u.name)).replace(/\\/g,"/");Vt(e,{absolutePath:d,kind:s,origin:i,enabled:a,name:g||u.name});continue}Sr(e,{walkRoot:n,currentDir:ot(r,u.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l});continue}if(u.isDirectory()){Sr(e,{walkRoot:n,currentDir:ot(r,u.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l});continue}if(!u.isFile()||!l)continue;let p=u.name.toLowerCase();if(!l.some(d=>p.endsWith(d)))continue;let m=ot(r,u.name);Vt(e,{absolutePath:m,kind:s,origin:i,enabled:a,name:ym(n,m,!0)})}}function ra(e){for(let t of e)if(_r(t))try{if(gm(t).size>0)return t}catch{continue}return e.find(t=>_r(t))}var Wt=Ke(we(),1);var Rm="<omitted>",Cm=["package_name","package_spec","package_version","package_version_source"],oa=100,sa=120,Yt=[{raw:"tools",attr:"tools"},{raw:"autoApprove",attr:"auto_approve"},{raw:"auto_approve",attr:"auto_approve"},{raw:"alwaysAllow",attr:"always_allow"},{raw:"always_allow",attr:"always_allow"},{raw:"enabledTools",attr:"enabled_tools"},{raw:"enabled_tools",attr:"enabled_tools"},{raw:"disabledTools",attr:"disabled_tools"},{raw:"disabled_tools",attr:"disabled_tools"}],ia=new Set(Yt.map(e=>e.attr)),Im=["enabled","disabled"],Am=["serverUrl","auth","bearer_token_env_var","default_tools_approval_mode","defaultToolsApprovalMode","env_vars","env_http_headers","http_headers"],Om=new Set(["type","command","url","args","env","envVars","headers",...Im,...Am,...Yt.map(e=>e.raw)]),Pm=new Set(["transport","command_or_url","args","env_var_names","headers_present","auth","bearer_token_env_var","default_tools_approval_mode","env_http_header_names",...Cm,...ia,...[...ia].map(e=>`${e}_truncated`)]);function aa(e,t){for(let n of t)Om.has(n)||Pm.has(n)||(e[n]=Rm)}var Tm=/^(authorization|auth|api[-_]?key|access[-_]?token|refresh[-_]?token|secret|password|passwd|token|bearer|client[-_]?secret|client[-_]?id|private[-_]?key|signing[-_]?key)$/i,km=/(?:^|[-_])(secret|password|passwd|token|api[-_]?key|private[-_]?key|signing[-_]?key|client[-_]?secret|client[-_]?id)(?:[-_]|$)/i,xm=/^(sk-|ghp_|gho_|github_pat_|xox[baprs]-|AKIA|ASIA|AIza|ya29\.)/,bm=/^bearer(?:\s+|$)/i;function Jt(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function ca(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Er(e){if(Array.isArray(e)){let n=[];for(let r of e){if(typeof r!="string"||r.length===0)continue;let o=r.split("=",1)[0]?.trim();o&&n.push(o)}return n}let t=Jt(e);return t?Object.keys(t).filter(n=>n.length>0):[]}function Ie(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch{return e}}function Nm(e,t){if(e!==void 0&&/^https?:\/\//i.test(e)&&(0,Wt.launchContainsCredentials)({kind:"url",url:e})||(0,Wt.launchContainsCredentials)({kind:"command",command:e??"",arguments:t}))return!0;let n=it([...t]);return t.some((r,o)=>n[o]===r?!1:/^https?:\/\//i.test(r)?(0,Wt.launchContainsCredentials)({kind:"url",url:r}):!0)}function ua(e,t,n){Nm(t,n)&&(e.launch_had_credentials=!0)}function Mm(e){return xm.test(e)||bm.test(e)?"<redacted>":e.includes("://")?Ie(e):e}function la(e){if(/^https?:\/\//i.test(e))return Ie(e);let t=e.indexOf("=");return t>0?`${e.slice(0,t+1)}${la(e.slice(t+1))}`:Mm(e)}function wm(e){let t=e.replace(/^-+/,"").split("=",1)[0]??"";return Tm.test(t)||km.test(t)}function it(e){let t=[],n=!1;for(let r of e){if(n){t.push("<redacted>"),n=!1;continue}if(wm(r)){t.push("<redacted>"),n=!r.includes("=");continue}t.push(la(r))}return t}function vm(e){let t=ca(e);if(t.length===0)return;let n=[...new Set(t.map(r=>r.length>sa?r.slice(0,sa):r))].sort();if(n.length!==0)return n.length>oa?{names:n.slice(0,oa),truncated:!0}:{names:n,truncated:!1}}function Lm(e){let t=Jt(e);if(!t)return{headers:[],envVars:[]};let n=[],r=[];for(let[o,s]of Object.entries(t))o.length>0&&n.push(o),typeof s=="string"&&s.length>0&&r.push(s);return{headers:n,envVars:r}}function da(e,t){let n=new Set;for(let{raw:r,attr:o}of Yt){if(n.has(o)||!(r in t))continue;let s=t[r];if(o==="auto_approve"&&typeof s=="boolean"){e.auto_approve=s,n.add(o);continue}let i=vm(s);i&&(e[o]=i.names,i.truncated&&(e[`${o}_truncated`]=!0),n.add(o))}}function pa(e,t){let n=Jt(e),r={transport:t};if(!n)return r;aa(r,Object.keys(n));let o=typeof n.command=="string"?n.command:void 0,s=typeof n.url=="string"?n.url:void 0,i=typeof n.serverUrl=="string"?n.serverUrl:void 0,a=o??s??i,c=ca(n.args);a&&(r.command_or_url=Ie(a));let l=it(c);l.length>0&&(r.args=l),ua(r,a,c);let u=Lm(n.env_http_headers),p=[...new Set([...Er(n.env),...Er(n.envVars),...Er(n.env_vars),...u.envVars,...typeof n.bearer_token_env_var=="string"&&n.bearer_token_env_var.length>0?[n.bearer_token_env_var]:[]])].sort();p.length>0&&(r.env_var_names=p),u.headers.length>0&&(r.env_http_header_names=[...new Set(u.headers)].sort());for(let _ of["headers","http_headers","env_http_headers"])if(n[_]!==void 0&&n[_]!==null){r.headers_present=!0;break}let m=typeof n.auth=="string"?n.auth:void 0;m&&(r.auth=m);let d=typeof n.bearer_token_env_var=="string"?n.bearer_token_env_var:void 0;d&&(r.bearer_token_env_var=d);let g=typeof n.default_tools_approval_mode=="string"?n.default_tools_approval_mode:typeof n.defaultToolsApprovalMode=="string"?n.defaultToolsApprovalMode:void 0;return g&&(r.default_tools_approval_mode=g),da(r,n),r}function fa(e){let t=Jt(e);return t?t.enabled===!1?!1:t.disabled!==!0:!0}function Cr(e,t,n=!0){let r=Object.keys(t).sort().map(o=>[o,t[o]??null]);return v(JSON.stringify({name:e,attributes:r,enabled:n}))}function Le(e){let t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function st(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*\\[([^\\]]*)\\]`,"m").exec(e);return n?.[1]?[...n[1].matchAll(/"([^"]*)"|'([^']*)'/g)].map(r=>r[1]??r[2]??"").filter(r=>r.length>0):[]}function Rr(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(true|false)\\s*$`,"m").exec(e);if(n?.[1])return n[1]==="true"}function yr(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(.+)$`,"m").exec(e);if(!n?.[1])return;let r=Le(n[1]);return r.length>0?r:void 0}function Um(e,t){let n=[],r=i=>{for(let a of i.split(/[,\n]/)){let c=/^\s*"?([A-Za-z_][A-Za-z0-9_-]*)"?\s*=\s*(.+?)\s*$/.exec(a);c?.[1]&&n.push([c[1],Le(c[2]??"")])}},o=new RegExp(`^\\s*${t}\\s*=\\s*\\{([^}]*)\\}`,"m").exec(e);o?.[1]&&r(o[1]);let s=new RegExp(`(?:^|\\n)\\[[^\\]]*\\.${t}\\]\\s*\\n([\\s\\S]*?)(?=\\n\\[|$)`).exec(`
|
|
33
|
+
${e}`);return s?.[1]&&r(s[1]),n}function ma(e){return Rr(e,"enabled")===!1?!1:Rr(e,"disabled")!==!0}function Dm(e,t){let n={};for(let{raw:r,attr:o}of Yt){if(o==="auto_approve"){let i=Rr(t,r);if(i!==void 0){n[r]=i;continue}}let s=st(t,r);s.length>0&&(n[r]=s)}da(e,n)}var Fm=/^\s*([A-Za-z_][A-Za-z0-9_-]*)\s*[.=]/,Hm=/^\[[^\]]*\.([A-Za-z_][A-Za-z0-9_-]*)\]\s*$/gm;function jm(e){let t=new Set,n=e.search(/^\[/m),r=n===-1?e:e.slice(0,n);for(let o of r.split(`
|
|
34
|
+
`)){let s=Fm.exec(o);s?.[1]&&t.add(s[1])}for(let o of e.matchAll(Hm))o[1]&&t.add(o[1]);return[...t]}function ga(e,t){let n={transport:t};aa(n,jm(e));let r=/^\s*command\s*=\s*(.+)$/m.exec(e),o=/^\s*url\s*=\s*(.+)$/m.exec(e),s=r?Le(r[1]??""):void 0,i=o?Le(o[1]??""):void 0,a=s!==void 0&&s.length>0?s:i,c=st(e,"args");a&&(n.command_or_url=Ie(a));let l=it(c);l.length>0&&(n.args=l),ua(n,a,c);let u=new Set;for(let E of e.split(`
|
|
35
|
+
`)){let y=/^\s*env\.([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(E);y?.[1]&&u.add(y[1])}let p=/^\s*env\s*=\s*\{([^}]*)\}/m.exec(e);if(p?.[1])for(let E of p[1].split(",")){let y=/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(E);y?.[1]&&u.add(y[1])}let m=/(?:^|\n)\[[^\]]*env\]\s*\n([\s\S]*?)(?=\n\[|$)/.exec(`
|
|
36
|
+
${e}`);if(m?.[1])for(let E of m[1].split(`
|
|
37
|
+
`)){let y=/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(E);y?.[1]&&u.add(y[1])}for(let E of st(e,"env_vars"))u.add(E);let d=Um(e,"env_http_headers");for(let[,E]of d)E.length>0&&u.add(E);let g=yr(e,"bearer_token_env_var");g&&(u.add(g),n.bearer_token_env_var=g),u.size>0&&(n.env_var_names=[...u].sort()),d.length>0&&(n.env_http_header_names=[...new Set(d.map(([E])=>E))].sort()),(/^\s*(?:http_|env_http_)?headers\s*=/m.test(e)||/(?:^|\n)\[[^\]]*headers\]\s*(?:\n|$)/.test(e))&&(n.headers_present=!0);let _=yr(e,"auth");_&&(n.auth=_);let S=yr(e,"default_tools_approval_mode");return S&&(n.default_tools_approval_mode=S),Dm(n,e),n}var $m=300,Km=256;function _a(e,t){if(!t)return e;let n=[...new Set([t,t.replace(/\\/g,"/")])].filter(o=>o.length>1),r=e;for(let o of n)r=r.split(o).join("~");return r}function Xt(e){let t=[],n="",r=null;for(let o of e){if(r){o===r?r=null:n+=o;continue}if(o==='"'||o==="'"){r=o;continue}if(/\s/.test(o)){n.length>0&&(t.push(n),n="");continue}n+=o}return n.length>0&&t.push(n),t}function ha(e,t){return e.length<=t?e:`${e.slice(0,t-1)}\u2026`}function Bm(e){return ha(e,$m)}function Sa(e,t){let n=_a(e.trim(),t),r=Xt(n);if(r.length===0)return"";let[o,...s]=r,i=Ie(o),a=it(s);return Bm([i,...a].join(" "))}function Ea(e,t){if(typeof e!="string")return null;let n=_a(e.trim(),t),r=Xt(n)[0];if(!r)return null;let o=Ie(r);return o.length===0?null:ha(o,Km)}function Gm(e){if(e.prompt||e.type==="prompt")return"prompt";let t=e.command??e.bash??e.powershell??"";return/\bnpx\b/i.test(t)?"npx":/\.(sh|bash|zsh|js|mjs|cjs|ts|py)(\s|$|"|')/i.test(t)||/^(\.\/|~\/|\/|[A-Za-z]:[\\/])/.test(t.trim())?"script":"inline"}function zm(e){return Array.isArray(e.hooks)&&e.hooks.length>0?e.hooks:[{type:e.type,command:e.command,bash:e.bash,powershell:e.powershell,prompt:e.prompt}]}function Vm(e,t,n,r){let o=e.componentPath(t);for(let[s,i]of Object.entries(n))if(!(!Array.isArray(i)||e.truncated))for(let a of i){if(!a||typeof a!="object"||e.truncated)continue;let c=a;for(let l of zm(c)){if(e.truncated)return;let u=l.command??l.bash??l.prompt??l.powershell??c.powershell??"",p=Gm({type:l.type??c.type,command:l.command??c.command,bash:l.bash??c.bash,powershell:l.powershell??c.powershell,prompt:l.prompt??c.prompt}),m=typeof c.matcher=="string"?c.matcher:"",d=v(u),g=m?`${s}:${m}:${p}:${d}`:`${s}:${p}:${d}`,_=`${s}|${m}|${p}|${u}|attrs2`;e.push({kind:"HOOK",name:g,path:o,content_hash:v(_),origin:r,enabled:!0,trigger:"EVENT",attributes:{event:s,...m?{matcher:m}:{},action_kind:p,action_hash:d,...p!=="prompt"&&u.trim()?{command:Sa(u,e.home)}:{}}})}}}function Ue(e,t,n){if(!e.claimFile(t))return;let r=e.readJson(t,{});!r?.hooks||typeof r.hooks!="object"||Vm(e,t,r.hooks,n)}import{existsSync as qm,readFileSync as Qm}from"node:fs";var me=Ke(we(),1);import{createHash as Wm}from"node:crypto";import{join as at}from"node:path";function Ym(e){let t=[...e].sort((n,r)=>n.localeCompare(r,"en")).join(`
|
|
38
|
+
`);return Wm("sha512").update(t).digest("hex").slice(0,16)}function Jm(e){let t=process.platform==="win32"?at(I("LOCALAPPDATA")??e,"npm-cache"):at(e,".npm"),n=I("npm_config_cache")??I("NPM_CONFIG_CACHE");return n===void 0||n===t?[t]:[n,t]}function ya(e){return typeof e=="string"&&e.length>0&&e.length<=me.PACKAGE_FIELD_MAX?e:null}function Xm(e,t,n){let r=Ym(e);for(let o of Jm(n)){let s=at(o,"_npx",r),i=L(at(s,"node_modules",...t.split("/"),"package.json"),{}),a=ya(i.version);if(a!==null)return a;let c=L(at(s,"package-lock.json"),{}),l=ya(c.packages?.[`node_modules/${t}`]?.version);if(l!==null)return l}return null}function Zm(e){return e.length<=me.PACKAGE_FIELD_MAX?e:`${e.slice(0,me.PACKAGE_FIELD_MAX-1)}\u2026`}function Ir(e,t,n){if(typeof e!="string"||e.length===0)return null;let r=(0,me.npxPackageSpecs)(e,t??[]),o=r[0];if(o===void 0)return null;let s=(0,me.packageNameFromSpec)(o);if(s===null)return null;let i=Xm(r,s,n);return{package_name:s,package_spec:Zm(o),...i===null?{}:{package_version:i,package_version_source:"npx_cache"}}}function Ra(e,t){if(typeof e!="string"||e.length===0)return null;let[n,...r]=Xt(e.trim());return n===void 0?null:Ir(n,r,t)}function Zt(e,t){if(!e||typeof e!="object"||Array.isArray(e))return null;let n=e,r=Array.isArray(n.args)?n.args.filter(o=>typeof o=="string"):[];return Ir(typeof n.command=="string"?n.command:null,r,t)}function Ca(e,t){let n=/^\s*command\s*=\s*(.+)$/m.exec(e);return n===null?null:Ir(Le(n[1]??""),st(e,"args"),t)}function eg(e){if(!e||typeof e!="object"||Array.isArray(e))return"unknown";let t=e;return typeof t.type=="string"&&t.type.length>0?t.type:typeof t.url=="string"?"http":typeof t.command=="string"?"stdio":"unknown"}function Ia(e,t,n){if(!e.claimFile(t))return;let o=e.readJson(t,{})?.mcpServers;if(!o||typeof o!="object")return;let s=e.componentPath(t);for(let[i,a]of Object.entries(o)){if(e.truncated)return;let c=eg(a),l=pa(a,c);Object.assign(l,Zt(a,e.home)??{});let u=fa(a);e.push({kind:"MCP_SERVER",name:i,path:s,content_hash:Cr(i,l,u),origin:n,enabled:u,attributes:l})}}function Aa(e,t,n){if(!qm(t)||!e.claimFile(t))return;let r;try{r=Qm(t,"utf8")}catch{return}let o=e.componentPath(t),s=/^\[mcp_servers(?:\.(\w+)|\."([^"]+)"|\.'([^']+)')\]\s*$/gm,i;for(;(i=s.exec(r))!==null;){if(e.truncated)return;let a=i[1]??i[2]??i[3];if(!a)continue;let c=r.slice(i.index+i[0].length),l=c.search(/^\[mcp_servers(?:\.(?:\w+|"[^"]+"|'[^']+'))\]\s*$/m),u=l===-1?c:c.slice(0,l),p="unknown";/^\s*url\s*=/m.test(u)?p="http":/^\s*command\s*=/m.test(u)&&(p="stdio");let m=ga(u,p);Object.assign(m,Ca(u,e.home)??{});let d=ma(u);e.push({kind:"MCP_SERVER",name:a,path:o,content_hash:Cr(a,m,d),origin:n,enabled:d,attributes:m})}}import{existsSync as tg,readdirSync as ng}from"node:fs";import{join as $}from"node:path";var Oa=50;function Ar(e,t,n,r){if(!tg(t))return{componentCount:0,expandTruncated:!1};let o=e.components.length,{expanded:s}=e.withPluginExpandCap(Oa,()=>{Ce(e,{dir:$(t,"skills"),kind:"SKILL",origin:n,enabled:r,nested:"SKILL.md"}),Ce(e,{dir:$(t,"commands"),kind:"COMMAND",origin:n,enabled:r,extensions:[".md"]}),Ce(e,{dir:$(t,"agents"),kind:"SUBAGENT",origin:n,enabled:r,extensions:[".md"]})});Ue(e,$(t,"hooks","hooks.json"),n),Ue(e,$(t,"hooks.json"),n);let i=e.components.length-o,a=s>=Oa;return{componentCount:i,expandTruncated:a}}function Or(e,t){e.push({kind:"PLUGIN",name:t.pluginKey,path:t.rowPath,content_hash:t.contentHash,origin:"user",enabled:t.enabled,attributes:{...t.marketplace?{marketplace:t.marketplace}:{},...t.version?{version:t.version}:{},scope:t.scope,component_count:t.componentCount,...t.expandTruncated?{expand_truncated:!0}:{}}})}function Pa(e){let t=$(e.home,".claude/plugins/installed_plugins.json"),n=e.readJson(t,{});if(!n)return;let r=n.plugins??{},s=e.readJson($(e.home,".claude/settings.json"),{})?.enabledPlugins??{},i=e.componentPath(t);for(let[a,c]of Object.entries(r)){if(e.truncated)return;let l=Array.isArray(c)?c:[c],u=l[0]??{},p=s[a]===!0,m=a.includes("@")?a.split("@").slice(1).join("@"):"",d=typeof u.version=="string"?u.version:"",g=typeof u.scope=="string"?u.scope:"user",_=`plugin:${a}`,S=0,E=!1;for(let y of l)if(typeof y.installPath=="string"&&y.installPath.length>0){let D=Ar(e,y.installPath,_,p);S+=D.componentCount,E=E||D.expandTruncated}Or(e,{pluginKey:a,rowPath:i,enabled:p,scope:g,version:d||void 0,marketplace:m||void 0,componentCount:S,expandTruncated:E,contentHash:v(`${a}|${d}|${g}|${p}|${S}`)})}}function rg(e){let t=e,n="";try{let r=ng(e,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);if(r.length===1&&r[0])t=$(e,r[0]),n=r[0];else if(r.length>1){let o=[...r].sort(),s=o[o.length-1];s&&(t=$(e,s),n=s)}}catch{}return{installPath:t,version:n}}var og=/^\d+$/;function sg(e){let t=e.filter(n=>!og.test(n.pluginId));return t.length>0?t:e}function Ta(e){let t=[{base:$(e.home,".cursor/plugins/local"),scope:"local"},{base:$(e.home,".cursor/plugins/cache"),scope:"cache"}];for(let{base:n,scope:r}of t)if(!e.truncated)for(let o of e.readEntries(n)){if(!o.isDirectory()||e.truncated)continue;if(r==="local"){let a=o.name,c=$(n,o.name),l=`plugin:${a}`,{componentCount:u,expandTruncated:p}=Ar(e,c,l,!0);Or(e,{pluginKey:a,rowPath:e.componentPath(c),enabled:!0,scope:"local",componentCount:u,expandTruncated:p,contentHash:v(`${a}|local|${u}`)});continue}let s=o.name,i=[];for(let a of e.readEntries($(n,s))){if(!a.isDirectory())continue;let c=$(n,s,a.name),{installPath:l,version:u}=rg(c);i.push({pluginId:a.name,installPath:l,version:u})}for(let a of sg(i)){if(e.truncated)break;let c=`${a.pluginId}@${s}`,l=`plugin:${c}`,{componentCount:u,expandTruncated:p}=Ar(e,a.installPath,l,!0);Or(e,{pluginKey:c,rowPath:e.componentPath(a.installPath),enabled:!0,scope:"cache",version:a.version||void 0,marketplace:s,componentCount:u,expandTruncated:p,contentHash:v(`${c}|${a.version}|${u}`)})}}}function ag(e,t){let{layout:n,levelDir:r,origin:o,includeMachineWide:s}=t;for(let i of n.skillRoots)Ce(e,{dir:De(r,i),kind:"SKILL",origin:o,enabled:!0,nested:"SKILL.md"});for(let i of n.dirs)Ce(e,{dir:De(r,i.dir),kind:i.kind,origin:o,enabled:!0,extensions:i.extensions});for(let i of n.memory){let a=ra(i.map(c=>De(r,c)));a&&Vt(e,{absolutePath:a,kind:"MEMORY",origin:o,enabled:!0,name:ig(a)})}for(let i of ns(n))Ue(e,De(r,i),o);for(let i of n.mcpJson??[])Ia(e,De(r,i),o);for(let i of n.mcpToml??[])Aa(e,De(r,i),o);if(s){if(n.managed)for(let i of Pt(n.managed,process.platform,e.home))i.toLowerCase().endsWith(".json")&&Ue(e,i,o);n.plugins==="claude"?Pa(e):n.plugins==="cursor"&&Ta(e)}}function ka(e,t){try{let n=new zt(e,{pathMode:t.pathMode,maxEntries:t.maxEntries});for(let r of t.layouts)ag(n,{layout:r,levelDir:t.levelDir,origin:t.origin,includeMachineWide:t.includeMachineWide});return{scopeRef:t.scopeRef,anchor:t.levelDir,components:n.components,truncated:n.truncated}}catch{return}}function Pr(e,t,n={}){let r={},o=n.shouldWalk;if(o===void 0||o("user","")){let c=ka(t,{layouts:Object.values(xe),levelDir:t,origin:"user",includeMachineWide:!0,pathMode:"home-relative",maxEntries:ae,scopeRef:""});c&&(r.user=c)}let s=n.inGitRepo===!0,i=null,a=n.launchCwd;if(a!==void 0){let c=Object.values(ue),l=mr({launchCwd:a,gitRoot:n.gitRoot,inGitRepo:s,remote:n.remote,home:t,hasProjectSpec:u=>os(c,u)});i=l.parentRel;for(let u of l.anchors){let p=rr(u.dir);if(o!==void 0&&!o(u.scope,p))continue;let m=ka(t,{layouts:c,levelDir:u.dir,origin:u.scope,includeMachineWide:!1,pathMode:"tilde",maxEntries:gr,scopeRef:p});m&&(r[u.scope]=m)}r.parent||(i=null)}return{scopes:r,parentRel:i,cwdInGitRepo:s}}function Tr(e,t,n={}){let r=n.truncated===!0,o=nt(e),s=new Set(e.map(u=>z(u.path,u.name)));if(n.forceFull===!0||t===void 0)return{hash:o,count:e.length,truncated:r,full:!0,upserts:e,removed:[],unchanged:!1};let a=[],c=t;for(let u of e){let p=z(u.path,u.name);c[p]!==u.content_hash&&a.push(u)}let l=[];if(!r){for(let u of Object.keys(c))if(!s.has(u)){let p=Hi(u);p&&l.push(p)}}return{hash:o,count:e.length,truncated:r,full:!1,upserts:a,removed:l,unchanged:a.length===0&&l.length===0}}var ba=2*1024*1024,cg=new Set(["HOOK","MCP_SERVER","PLUGIN"]);function kr(e,t,n){let r=new Set(t.map(s=>z(s.path,s.name))),o=[];for(let s of e)s.text!==void 0&&(n.has(s.content_hash)||r.has(z(s.path,s.name))||o.push(s));return o}function xr(e,t,n){let r=new Set(e);for(let s of t)r.add(s);let o=new Set(n.map(s=>s.content_hash));return[...r].filter(s=>o.has(s))}function xa(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function Na(e){if(e.text===void 0)return e;let{text:t,...n}=e;return n}function br(e,t=ba){let n=[],r=[];for(let u of e)cg.has(u.kind)?n.push(u):r.push(u);r.sort((u,p)=>(u.text?.length??0)-(p.text?.length??0));let o=[...n,...r],s=[],i=2,a=0,c=0,l=[];for(let u of o){let p=s.length>0?1:0,m=xa(u)+p;if(i+m<=t){s.push(u),i+=m,u.text!==void 0&&l.push(u.content_hash);continue}if(u.text!==void 0){let d=Na(u),g=xa(d)+p;if(i+g<=t){s.push(d),i+=g,a+=1;continue}}c+=1}return{components:s,textDeferredCount:a,droppedCount:c,textHashesSent:l}}function Nr(e,t){return t.size===0?e:e.map(n=>n.text===void 0||!t.has(n.content_hash)?n:Na(n))}var ug=["user","cwd","repo","parent"];function Mr(e){let{collected:t,cacheFor:n,nowMs:r,maxBytes:o}=e,s=[];for(let k of ug){let x=t.scopes[k];if(!x)continue;let U=n(k,x.scopeRef),F=U.components,V=Tr(x.components,F,{forceFull:F===void 0,truncated:x.truncated}),ge=new Set(U.textHashes),H=kr(x.components,V.upserts,ge),w=Nr([...V.upserts,...H],ge);s.push({scope:k,walk:x,delta:V,outgoing:w,outgoingKeys:new Set(w.map(C=>z(C.path,C.name))),deliveredTextHashes:ge,cachedComponents:F})}let i=s.flatMap(k=>k.outgoing),a=br(i,o),c=new Set(a.components.map(k=>z(k.path,k.name))),l=[],u=[],p=[],m=[],d=[],g=[],_=[];for(let k of s){let{scope:x,walk:U,delta:F}=k;g.push(...U.components),l.push(x);let V=a.components.filter(C=>k.outgoingKeys.has(z(C.path,C.name))),ge=[...k.outgoingKeys].some(C=>!c.has(C)),H=F.truncated||ge;H?p.push(x):F.full&&u.push(x),m.push(...V),!F.full&&!H&&d.push(...F.removed);let w=F.full?{}:{...k.cachedComponents??{}};if(!H)for(let C of F.removed)delete w[z(C.path,C.name)];for(let C of V)w[z(C.path,C.name)]=C.content_hash;_.push({scope:x,scopeRef:U.scopeRef,components:w,textHashes:xr(k.deliveredTextHashes,V.filter(C=>C.text!==void 0).map(C=>C.content_hash),U.components),collectedAtMs:r,included:V.length>0||F.removed.length>0&&!H||F.full})}let S={user_spec_hash:nt(g),user_spec_count:g.length,user_spec_truncated:p.length>0};l.length>0&&(S.user_spec_scopes=l,S.user_spec_full_scopes=u,S.user_spec_truncated_scopes=p,S.user_spec_cwd_in_git_repo=t.cwdInGitRepo),u.length>0&&u.length===l.length&&(S.user_spec_full=!0),m.length>0&&(S.user_spec=m),d.length>0&&(S.user_spec_removed=d),a.textDeferredCount>0&&(S.user_spec_text_deferred=a.textDeferredCount);let E=t.scopes.cwd;E&&(S.user_spec_cwd_scope_ref=E.scopeRef);let y=t.scopes.repo;y&&(S.user_spec_repo_scope_ref=y.scopeRef);let D=t.scopes.parent;return D&&(S.user_spec_parent_scope_ref=D.scopeRef,t.parentRel&&(S.user_spec_parent_rel=t.parentRel)),{fields:S,scopes:_}}var ut={cwd:"cwd_spec",repo:"repo_spec",parent:"parent_spec"};function qt(e){return e==="cwd"||e==="repo"||e==="parent"}function ct(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function wr(e){return!ct(e)||!ct(e.components)||!Object.values(e.components).every(t=>typeof t=="string")||!Array.isArray(e.text_hashes)||!e.text_hashes.every(t=>typeof t=="string")?!1:typeof e.collected_at_ms=="number"&&Number.isFinite(e.collected_at_ms)}function Ma(e){return lg(e)}function wa(e){return dg(e)}function va(e){return pg(e)}function lg(e){if(!ct(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&(t[n]=r);return t}function dg(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function vr(e,t){if(!ct(e))return;let n=e[t];return wr(n)?n:void 0}function pg(e){if(!ct(e))return{};let t={};for(let[n,r]of Object.entries(e))wr(r)&&(t[n]=r);return t}function Lr(e,t=20){let n=[];for(let[r,o]of Object.entries(e))wr(o)&&n.push([r,o]);return n.sort((r,o)=>o[1].collected_at_ms-r[1].collected_at_ms),Object.fromEntries(n.slice(0,t))}var _g=200,La=200,hg=["allow","deny","ask"],Sg=/(?<=^|[\s(,=:])(?:~|[A-Za-z]:)?[\\/][^\s,)]+/g,Dr="<path>",Eg=new RegExp(`${Dr}(?:\\s+[A-Za-z.][^\\s,)]*[\\\\/][^\\s,)]*)+`,"g");function yg(e){let t=e.replace(Sg,Dr).replace(Eg,Dr);return t.length>La?`${t.slice(0,La)}...`:t}function en(e){let t=L(e,{}),n=[];for(let r of hg)for(let o of t.permissions?.[r]??[])typeof o=="string"&&o.length>0&&n.push({key:yg(o),mode:r});return{model:t.model??"",permissionKeys:n}}function Rg(e){let{serverManaged:t,fileBased:n}=Nn(process.platform,e),r=en(t);if(r.model||r.permissionKeys.length>0)return r;let o="",s=[];for(let i of n){let a=en(i);a.model&&(o=a.model),s.push(...a.permissionKeys)}return{model:o,permissionKeys:s}}function Cg(e){let t=new Set,n=[];for(let r of e){let o=`${r.mode}\0${r.key}`;t.has(o)||(t.add(o),n.push(r))}return n}var Ig=10,Ag="self-config-cache.json",Da=2;function He(){return I("EV_AI_HOOK_USER_SPEC")?.toLowerCase()==="off"}function Og(){return I("EV_AI_HOOK_CWD_SPEC")?.toLowerCase()==="off"}function Pg(e,t=Date.now()){return e===void 0||!Number.isFinite(e)?!0:t-e>=Ve}var Tg={claude:["claude"],cursor:["agent","cursor-agent"],codex:["codex"]};async function kg(e,t=M){let n=Tg[e];if(!n||n.length===0)return null;let r=async o=>{let s=n[o];if(s===void 0)return null;let a=((await t(s,["--version"],2e3)).split(`
|
|
39
|
+
`)[0]??"").trim();return a||r(o+1)};return r(0)}function xg(e=Ua()){return Fe(e,".ev-ai","agent-hook",Ag)}function bg(e){let n=[...e].sort((r,o)=>r.name.localeCompare(o.name)).map(r=>`${r.name}:${r.size}`).join(`
|
|
40
|
+
`);return v(n)}function Qt(e,t,n=!1){let r=bg(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 Ur(e,t,n=[]){let r=0,o=!1,s=new Set;for(let i of[...t.map(a=>Fe(e,a)),...n]){let a=gg(i);if(s.has(a))continue;s.add(a);let c=mn(i);c.present&&(o=!0,r+=c.size)}return o?{present:!0,size:r}:{present:!1,size:0}}function Ng(e){return fg(e)?K(mg(e,"utf8"),{}):{}}function Mg(e,t){try{X(e,`${JSON.stringify(t)}
|
|
41
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);h(`WARN: self-config cache write failed open: ${r}`)}}function wg(e,t,n){if(t==="user")return e.user_spec_collected_at_ms;if(qt(t))return vr(e[ut[t]],n)?.collected_at_ms}function vg(e,t,n){if(t==="user")return{components:Ma(e.user_spec_components),textHashes:wa(e.user_spec_text_hashes)};if(!qt(t))return{components:void 0,textHashes:[]};let r=vr(e[ut[t]],n);return r?{components:r.components,textHashes:r.text_hashes}:{components:void 0,textHashes:[]}}function Lg(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)}if(r){o.user_spec_layout_version=Da,r.home&&(o.user_spec_collected_at_ms=r.home.collectedAtMs,r.home.included&&(o.user_spec=r.hash,o.user_spec_components=r.home.components),o.user_spec_text_hashes=r.home.textHashes);for(let s of r.project){if(!qt(s.scope))continue;let i=ut[s.scope],a=va(o[i]),c=a[s.scopeRef];a[s.scopeRef]={components:s.included?s.components:c?.components??{},text_hashes:s.textHashes,collected_at_ms:s.collectedAtMs},o[i]=Lr(a)}}return o}async function Fa(e,t=process.cwd(),n=Ua(),r={}){let o=e==="claude",s=r.gitRoot??t,i=await kg(e),a="",c=[];if(o){let H=Rg(n),w=en(Fe(n,".claude/settings.json")),C=en(Fe(t,".claude/settings.local.json"));a=H.model||C.model||w.model,c=Cg([...H.permissionKeys,...w.permissionKeys,...C.permissionKeys]).slice(0,_g)}let l={present:!1,size:0},u=H=>{let w=[],C=!1;for(let ee of H){let ft=ro(Fe(n,ee));if(w=w.concat(ft.entries),C=C||ft.truncated,w.length>=ae){w=w.slice(0,ae),C=!0;break}}return{entries:w,truncated:C}},p=xg(n),m=Ng(p),d=m[e]??{},g=(d.send_count??0)+1,_=g>0&&g%Ig===0,S=H=>_?void 0:d[H],E=u(de.skills),y=u(de.subagents),D=u(de.commands),k=u(de.rules),x={skills:Qt(E.entries,S("skills"),E.truncated),subagents:Qt(y.entries,S("subagents"),y.truncated),commands:Qt(D.entries,S("commands"),D.truncated),rules:Qt(k.entries,S("rules"),k.truncated)},U={runner_platform:e,config_scope:"user",cli_version:i,claude_version:o?i:null,model:o&&a||null,permission_keys:c,user_scope:{skills:x.skills,subagents:x.subagents,commands:x.commands,rules:x.rules,memory:Ur(n,de.memory),settings:Ur(n,de.settings,ss(n)),mcp:Ur(n,de.mcp)},local_settings:o?mn(Fe(t,".claude/settings.local.json")):l},F=null,V=r.nowMs??Date.now();if(!He()){let H=d.user_spec_layout_version!==Da,w=Pr(e,n,{launchCwd:Og()?void 0:r.launchCwd,gitRoot:s,inGitRepo:r.inGitRepo,remote:r.remote,shouldWalk:(C,ee)=>H||Pg(wg(d,C,ee),V)});if(Object.keys(w.scopes).length>0){let C=Mr({collected:w,cacheFor:(ee,ft)=>H?{components:void 0,textHashes:[]}:vg(d,ee,ft),nowMs:V});Object.assign(U,C.fields),F={hash:C.fields.user_spec_hash,home:C.scopes.find(ee=>ee.scope==="user")??null,project:C.scopes.filter(ee=>ee.scope!=="user")}}}let ge=Lg(d,x,g,F);return{config:U,commit:()=>{m[e]=ge,Mg(p,m)}}}import{homedir as Qg}from"node:os";import{join as $a}from"node:path";function Ae(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}import{join as tn}from"node:path";function Ug(e){return tn(e,".ev-ai","agent-hook","js","signed-v1")}function Dg(e){return tn(Ug(e),"scopes")}function Ha(e,t){return tn(Dg(e),t)}function ja(e){return tn(e,"attempts")}function Fr(e){return String(e).padStart(10,"0")}var Fg=/^(\d{10})$/,Hg=/^(\d{10})\.done$/,jg=/^[0-9a-f]{128}$/,$g=64;async function za(e,t,n=!1){let r=ja(t),o=await Zo(e,r),s=new Map,i=new Map,a=Ka(o,Fg),c=Ka(o,Hg),l=async m=>{let d=await Ga(e,$a(r,Kg(m)));return d&&s.set(m,{record:Gg(d.value),mtimeMs:d.mtimeMs}),d!==void 0},u=async m=>{let d=zg((await Ga(e,$a(r,Bg(m))))?.value);return d&&i.set(m,d),d!==void 0};if(!n)return await Promise.all([...a.map(l),...c.map(u)]),{claims:s,dones:i};await Promise.all([Ba(a,l),Ba(c,u)]);let p=lt(s);return p<lt(i)&&c.includes(p)&&await u(p),{claims:s,dones:i}}function Ka(e,t){return e.flatMap(n=>{let r=t.exec(n);return r?[Number(r[1])]:[]})}async function Ba(e,t){for(let n of[...e].sort((r,o)=>o-r))if(await t(n))return}function lt(e){let t=0;for(let n of e.keys())n>t&&(t=n);return t}function Va(e){if(e.record!=="empty"&&e.record.started_at){let t=Date.parse(e.record.started_at);if(Number.isFinite(t))return t}return e.mtimeMs}function Kg(e){return Fr(e)}function Bg(e){return`${Fr(e)}.done`}async function Ga(e,t){let n;try{n=await e.stat(t)}catch(o){if(bn(o))return;throw o}let r=n.mtimeMs;if(n.size===0||n.size>Qn)return{mtimeMs:r};try{let o=await e.readFile(t);return o.byteLength===0||o.byteLength>Qn?{mtimeMs:r}:{mtimeMs:r,value:JSON.parse(o.toString("utf8"))}}catch{return{mtimeMs:r}}}function Gg(e){if(!Ae(e))return"empty";let t={};return typeof e.started_at=="string"&&(t.started_at=e.started_at),(e.owner==="bootstrap"||e.owner==="refresh")&&(t.owner=e.owner),e.resync===!0&&(t.resync=!0),t}function zg(e){if(!Ae(e))return;let t=e;if(typeof t.finished_at!="string"||typeof t.outcome!="string"||typeof t.interval_s!="number"||!Number.isFinite(t.interval_s))return;let n=Vg(t.selection);if(n)return{finished_at:t.finished_at,interval_s:t.interval_s,outcome:t.outcome,selection:n}}function Vg(e){if(!Ae(e))return;let t=e;if(t.kind==="bundled")return t.why==="server"||t.why==="bootstrap_failed"?{kind:"bundled",why:t.why}:void 0;if(t.kind==="cached"&&typeof t.digest=="string"&&jg.test(t.digest)&&typeof t.version=="string"&&t.version.length>0&&typeof t.sha512=="string"&&Wg(t.sha512)===t.digest)return{kind:"cached",digest:t.digest,version:t.version,sha512:t.sha512}}function Wg(e){if(e.length===0||!/^[A-Za-z0-9+/]+=*$/.test(e))return;let t=Buffer.from(e,"base64");if(!(t.byteLength!==$g||t.toString("base64")!==e))return t.toString("hex")}function Zg(e){return e==="bootstrap"?3e3:6e4}function qg(e,t){let n=lt(e.claims);if(n===0)return;let r=lt(e.dones),o=e.claims.get(n),s=e.dones.get(n);if(o&&!s){let a=Va(o),c=o.record==="empty"?void 0:o.record.owner,l=Zg(c)+3e4;if(t-a>l)return{n,latest_claim:n,outcome:"incomplete",finished_at:null,selection_version:Wa(e.dones.get(r)?.selection)}}if(r===0)return;let i=e.dones.get(r);if(i)return{n:r,latest_claim:n,outcome:i.outcome,finished_at:i.finished_at,selection_version:Wa(i.selection)}}async function Ya(e,t,n){try{let r=await za(qo(),Ha(e,t),!0);return qg(r,n)}catch{return}}function Wa(e){return e?.kind==="cached"&&typeof e.version=="string"?e.version:null}async function Ja(e=Qg()){let t=er()?.launcherScope;if(!t)return{};let n=await Ya(e,t,Date.now());return n?{launcher_scope:t,launcher_attempt:n}:{launcher_scope:t}}function je(e,t,n){let r={installation_id:n.installationId};n.platformAgentId&&(r.platform_agent_id=n.platformAgentId),n.sessionId&&(r.session_id=n.sessionId),n.turnId&&(r.turn_id=n.turnId);let o={schema_version:Ct,event:e,timestamp:mt(),session_id:n.sessionId||null,turn_id:n.turnId||null,installation_id:n.installationId,platform:n.runnerPlatform,platform_agent_id:n.platformAgentId||null,runner_event:n.runnerEvent||null,agent_hook_version:On,host_arch:process.arch,node_version:process.version,correlation:r,payload:t},s=er();return s&&(o.launcher_version=s.launcherVersion,o.hook_source=s.hookSource,o.hook_fallback_reason=s.fallbackReason??null,o.launcher_scope_match=hi(n.collectorUrl,s.launcherScope)),e==="session_start"&&(n.launcher_scope&&(o.launcher_scope=n.launcher_scope),n.launcher_attempt&&(o.launcher_attempt=n.launcher_attempt)),o}import{existsSync as Xa}from"node:fs";import{spawn as Za}from"node:child_process";import{fileURLToPath as t_}from"node:url";import{gzipSync as e_}from"node:zlib";function Hr(e){return I("EV_AI_HOOK_COMPRESS")==="off"?{body:e}:Buffer.byteLength(e,"utf8")<Oo?{body:e}:{body:e_(Buffer.from(e,"utf8")),contentEncoding:"gzip"}}function nn(e){let t={"Content-Type":"application/json"};return e!==void 0&&(t["Content-Encoding"]=e),t}function jr(e){return typeof e=="string"?Buffer.byteLength(e,"utf8"):e.length}var $r="__post",rn="__work";async function n_(e,t,n={}){if(He())return e;let r=await sr(n.gitRoot??process.cwd(),M,process.env,{runnerPlatform:t,home:n.home}),o=Ae(e.self_config)?e.self_config:{};return{...e,self_config:{...o,runner_platform:typeof o.runner_platform=="string"?o.runner_platform:t,operator:r}}}function r_(e,t){let n=Ae(e.payload)?Object.keys(e.payload):[],r=e.correlation&&typeof e.correlation=="object"?Object.keys(e.correlation):[];return JSON.stringify({event:e.event,schema_version:e.schema_version,agent_hook_version:e.agent_hook_version,host_arch:e.host_arch,node_version:e.node_version,build_ms:e.build_ms,body_bytes:t,correlation_keys:r,payload_keys:n})}function qa(e){switch(e){case"session_start":return Ro;case"session_end":return Co;case"tool_invoked":case"skill_invoked":return Cn;default:return Cn}}function o_(e,t,n){return`${JSON.stringify({url:e,timeoutMs:t})}
|
|
42
|
+
${n}`}function Qa(e,t=[],n=process.execPath,r=import.meta.url,o=Xa){if(yo(n))return{command:n,args:[e,...t]};let s=t_(r);return o(s)?{command:n,args:[s,e,...t]}:{command:n,args:[e,...t]}}function s_(e=process.execPath,t=import.meta.url,n=Xa){return Qa($r,[],e,t,n)}function i_(e){let t=e.indexOf(`
|
|
43
|
+
`);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 ec(e,t=fetch){let n=await e(),r=i_(n);if(!r)return;let{meta:o,body:s}=r,i=Hr(s),a=nn(i.contentEncoding);try{await t(o.url,{method:"POST",headers:a,body:i.body,signal:AbortSignal.timeout(Number(o.timeoutMs))})}catch{}}async function a_(e,t,n,r=fetch){let o=qa(e),s=Hr(t),i=nn(s.contentEncoding),a=jr(s.body);h(`POST event=${e} url=${yt(n)} size=${a} encoding=${s.contentEncoding??"identity"} platform=${process.platform}`);let c=Date.now();try{let l=await r(n,{method:"POST",headers:i,body:s.body,signal:AbortSignal.timeout(o)});if(!l.ok&&s.contentEncoding==="gzip"&&(l.status===400||l.status===415)){try{await l.text()}catch{}h(`POST gzip rejected http=${l.status} \u2014 retrying uncompressed`),l=await r(n,{method:"POST",headers:nn(),body:t,signal:AbortSignal.timeout(o)})}let u=Date.now()-c;if(l.ok)return h(`POST outcome=ok elapsed_ms=${u} http=${l.status}`),!0;let p=(await l.text()).slice(0,200).replace(/[\n\r]/g,"");return h(`POST outcome=fail elapsed_ms=${u} http=${l.status} body=${p}`),!1}catch(l){let u=Date.now()-c,p=l instanceof Error?l.message:String(l);return h(`POST outcome=fail elapsed_ms=${u} http=000 body=${p}`),!1}}async function tc(e,t,n,r,o){try{let s=r(e,t,{detached:!0,stdio:["pipe","ignore","ignore"],windowsHide:!0});s.on("error",()=>{}),s.stdin.on("error",()=>{});let i=!1;return await new Promise(a=>{let c=setTimeout(()=>{if(!i){h(`WARN: ${o} stdin handoff timed out \u2014 continuing fail-open`);try{s.stdin.destroy()}catch{}}a()},Io),l=()=>{i=!0,clearTimeout(c),a()};s.stdin.end(n,()=>l()),s.stdin.once("error",()=>l())}),s.unref(),s}catch(s){let i=s instanceof Error?s.message:String(s);return h(`WARN: ${o} spawn failed open: ${i}`),null}}async function c_(e,t,n,r=Za,o=s_){let s=qa(e),i=o_(n,s,t),{command:a,args:c}=o();return tc(a,c,i,r,"detached post")}async function nc(e,t,n=Za,r=Qa){let{command:o,args:s}=r(rn,t);return tc(o,s,e,n,"detached work")}async function $e(e,t,n,r,o,s,i){if(!o)return h("WARN: collector URL missing \u2014 pass --url on the hook command or set collector_url in manifest"),!1;if(!Et(o))return h(`WARN: collector URL blocked (https required): ${yt(o)}`),!1;let a=await n_(t,n.runnerPlatform,i),c=r(e,a,{...n,collectorUrl:o});s!==void 0&&(c.build_ms=Math.max(0,Date.now()-s));let l=JSON.stringify(c),u=`${l}
|
|
44
|
+
`,p=I("EV_AI_HOOK_DEBUG");p==="full"?h(`DEBUG envelope=${l}`):p==="1"&&h(`DEBUG summary=${r_(c,jr(u))}`);let m=process.argv.includes(rn),d=I("EV_AI_HOOK_SYNC")==="1";return Ut(n.runnerEvent,n.runnerPlatform)||m||d?a_(e,u,o):(await c_(e,u,o),!1)}import{createReadStream as u_}from"node:fs";import{stat as l_}from"node:fs/promises";import{basename as d_,resolve as p_}from"node:path";import{createInterface as f_}from"node:readline";var m_=1024*1024;function g_(e){let t=e.replace(/\\/g,"/");return t.includes("/.claude/projects/")&&d_(t).endsWith(".jsonl")}async function rc(e){if(!e||!g_(e))return null;try{let t=p_(e),n=await l_(t);if(!n.isFile())return null;let r=Math.max(0,n.size-m_),o=[],s=f_({input:u_(t,{encoding:"utf8",start:r}),crlfDelay:1/0});for await(let i of s)i.length!==0&&o.push(i);r>0&&o.length>0&&o.shift();for(let i=o.length-1;i>=0;i--){let a=o[i];if(a)try{let c=JSON.parse(a);if(c.type!=="assistant")continue;let l=c.message;if(!l||typeof l!="object")continue;let u=l.model;if(typeof u=="string"&&u.length>0)return u}catch{continue}}return null}catch{return null}}function on(e){return{sessionId:e.sessionId,turnId:e.turnId,installationId:e.manifest.installationId,runnerPlatform:e.runnerPlatform,platformAgentId:e.platformAgentId,runnerEvent:e.runnerEvent}}function pt(e,t){return{gitRoot:e.manifest.gitRoot,...t?{home:t}:{}}}function Br(e){return{gitRoot:e.manifest.gitRoot,inGitRepo:e.manifest.inGitRepo,runnerEvent:e.runnerEvent}}async function ic(e){let t=Date.now();await T_(e);let{gitRoot:n}=e.manifest;await zr(e,n);let r=Br(e);return{buildStartedAtMs:t,gitRoot:n,hookInput:Bt(e.hookInput,e.manifest.manifest,r),envelopeFields:on(e),launchCwd:pr(e.hookInput,r),home:h_()}}function oc(e){try{return G(__(e))}catch{return null}}function ac(e){return e.startsWith("/")||/^[A-Za-z]:\//.test(e)}function sc(e,t){let n=e.replaceAll("\\","/");if(!ac(n))return null;let r=G(e),o=G(t),s=oc(e)??r,i=oc(t)??o;return s.startsWith(`${i}/`)?s.slice(i.length+1):r.startsWith(`${o}/`)?r.slice(o.length+1):null}function cc(e,t,n){if(!e)return{repositorySourcePath:null,userSourcePath:null};let r=e.replaceAll("\\","/"),s=sc(e,t)??(ac(r)?null:r),i=sc(e,n);return{repositorySourcePath:s,userSourcePath:i}}function Kr(e,t,n,r,o){return uc(e,cc(n,t.gitRoot,t.home),r,o)}function uc(e,{repositorySourcePath:t,userSourcePath:n},r,o){let s=t??n,i=s===null?null:o(s),a=i!==null&&s!==null?S_({installableKind:r,sourcePath:s,nativeKey:i,inRepository:t!==null,platformAgentId:e.platformAgentId,installationId:e.manifest.installationId}):void 0;return{sourcePath:s,nativeKey:i,componentReference:a}}function S_(e){try{let t=e.inRepository?R_(e.platformAgentId,e.sourcePath):(0,P.installationRootExternalKey)(e.installationId,(0,P.userConfigRootFromPath)(e.sourcePath));return t?(0,P.buildComponentReference)({installationRootExternalKey:t,installableKind:e.installableKind,sourcePath:e.sourcePath,nativeKey:e.nativeKey}):void 0}catch{return}}function Gr(e,t,n){return $e("tool_invoked",{...n,success:null,duration_ms:null,hook_input:t.hookInput},t.envelopeFields,je,e.manifest.collectorUrl,t.buildStartedAtMs,pt(e,t.home))}function E_(e){return Xs(e.runnerEvent,e.runnerPlatform)?[]:ps(e.hookInput)}function y_(e,t){return Gr(e,t,{})}var lc=new Set([...Object.values(Re),".github"]);function R_(e,t){let n=e.indexOf(":");if(n<=0)return null;let r=e.slice(0,n),o=t.replaceAll("\\","/").split("/").filter(Boolean),s=o.findIndex(i=>lc.has(i));return s<0?null:`${r}:${o.slice(0,s+1).join("/")}`}var dc=".codex/config.toml",C_=new Map([["claude_json_user",".claude.json"],["cursor_mcp_user",".cursor/mcp.json"],["codex_toml_user",dc]]);function I_(e,t,n,r,o,s,i){if(e===null||t===null||!(i!==null||/^mcp__.+?__.+$/i.test(e)||/^MCP:[^:]+:.+$/i.test(e)||/^MCP:.+__.+$/i.test(e)||e.toLowerCase()===`mcp:${t.toLowerCase()}`))return;let c=s.find(_=>_.name.toLowerCase()===t.toLowerCase()),l=c?C_.get(c.source):o==="codex"?dc:void 0,u=c?.sourcePath??l;if((c?.scope==="user"||l!==void 0)&&u)try{let _=(0,P.userConfigRootFromPath)(u);return(0,P.buildComponentReference)({installationRootExternalKey:(0,P.installationRootExternalKey)(r,_),installableKind:P.ComponentKind.INTERFACE,sourcePath:u,nativeKey:c?.name??t})}catch{return}if(n===null)return;let m=n.indexOf(":");if(m<=0||m===n.length-1)return;let d=n.slice(m+1),g=d.replaceAll("\\","/").split("/").at(-1);if(!(g===void 0||!lc.has(g)))try{return(0,P.buildComponentReference)({installationRootExternalKey:n,installableKind:P.ComponentKind.INTERFACE,sourcePath:d,nativeKey:t})}catch{return}}function A_(...e){for(let t of e)if(t)return t;return null}function Pe(e,t,n){if(e.status==="fulfilled")return e.value;let r=e.reason instanceof Error?e.reason.message:String(e.reason);return h(`WARN: ${n} failed open: ${r}`),t}function O_(e){let t={present:!1,size:0},n={hash:"",count:0};return{config:{runner_platform:e,config_scope:"user",cli_version:null,claude_version:null,model:null,permission_keys:[],user_scope:{skills:n,subagents:n,commands:n,rules:n,memory:t,settings:t,mcp:t},local_settings:t},commit:()=>{}}}function P_(e,t){return{runner_platform:e,config_scope:"user",...t?{operator:t}:{}}}var Oe=new Set,dt=null;async function T_(e){if(He())return;let t=e.manifest.installationId,n=e.manifest.installationStorePath;if(Oe.has(t))return;if(!ar(n)){Oe.add(t);return}let r=ze({sessionId:e.sessionId,hostname:gt()});if($i(r)){if(dt){await dt;return}dt=(async()=>{if(Oe.has(t)||!ar(n)){Oe.add(t);return}if(!$o(n)){Oe.add(t);return}let o=!1;try{let s=Date.now(),{gitRoot:i}=e.manifest,a=String(e.runnerPlatform),{operatorResolved:c,fields:l}=await pc(e,r,vt(i),ir({gitRoot:i,installationStorePath:n,forceResend:!1,runnerPlatform:a})),u={...l,self_config:P_(a,c.operator),run_meta:{trigger:"cloud_identity_bootstrap"}};o=!!await $e("session_start",u,on(e),je,e.manifest.collectorUrl,s,pt(e)),o&&(c.commit(),Oe.add(t))}finally{Ko(n)}})().finally(()=>{dt=null}),await dt}}async function zr(e,t,n){try{e.platformAgentId=await Ls(e.manifest.manifest,e.platformAgentId,String(e.runnerPlatform),t,n,e.manifest.installationStorePath,e.manifest.repoKey)}catch(r){let o=r instanceof Error?r.message:String(r);h(`WARN: derivePlatformAgentId failed open: ${o}`)}}async function pc(e,t,n,r){let[o,s,i,a,c]=await Promise.allSettled([n,ao(),Ei(t),uo(),r]),l=Pe(o,null,"gitSnapshot"),u=Pe(s,"","detectVirt"),p=Pe(i,null,"probeCloud"),m=Pe(a,{},"hostEnv"),d=Pe(c,{commit:()=>{}},"resolveOperatorForSend");return await zr(e,e.manifest.gitRoot,l),{operatorResolved:d,fields:{identity:{host:gt(),context:t,virt:u||null,cloud:p,git:l},host_env:m,env_vars:yi()}}}async function k_(e){let t=Date.now(),{gitRoot:n}=e.manifest,r=ze({sessionId:e.sessionId,hostname:gt()}),o=String(e.runnerPlatform),s=Br(e),i=pr(e.hookInput,s),a=vt(n),c=Ja().catch(()=>({})),l=He()?Promise.resolve({commit:()=>{}}):ir({gitRoot:n,installationStorePath:e.manifest.installationStorePath,forceResend:!1,runnerPlatform:o}),u=pc(e,r,a,l),[p,m]=await Promise.allSettled([Wn(e.manifest.manifest,n,o),a.catch(()=>null).then(U=>Fa(o,n,void 0,{installationStorePath:e.manifest.installationStorePath,gitRoot:n,launchCwd:i,inGitRepo:e.manifest.inGitRepo,remote:U?.remote??null}))]),{operatorResolved:d,fields:g}=await u,_=Pe(p,[],"mcpDeclared"),S=Pe(m,O_(o),"selfConfig"),E=S.config,y=R(e.hookInput,"model");y&&(E.model=y);let D={...g,mcp:{declared:_},self_config:E,run_meta:{trigger:e.hookSource||"startup"},hook_input:Bt(e.hookInput,e.manifest.manifest,{...s,launchCwd:i})},k=await c;await $e("session_start",D,{...on(e),...k},je,e.manifest.collectorUrl,t,pt(e))&&(S.commit(),d.commit(),Oe.add(e.manifest.installationId))}async function x_(e){let t=Date.now(),[,n]=await Promise.all([zr(e,e.manifest.gitRoot),e.runnerPlatform==="claude"?rc(R(e.hookInput,"transcript_path")):null]),r=e.runnerEvent.toLowerCase(),o=A_(R(e.hookInput,"status"),R(e.hookInput,"stop_reason"),R(e.hookInput,"reason"),et(R(e.hookInput,"error")),r==="stop"?te(e.hookInput,"is_interrupt")===!0?"interrupted":"completed":""),s=Bt(e.hookInput,e.manifest.manifest,Br(e));n&&(s.model=n),r!=="stopfailure"&&!Vi(e.manifest.manifest)&&s.last_assistant_message===void 0&&(s.last_assistant_message=""),await $e("session_end",{status:o,...n?{model:n}:{},hook_input:s},on(e),je,e.manifest.collectorUrl,t,pt(e))}async function b_(e){let t=E_(e),n=Hs(e.hookInput),r=Js(e.runnerEvent),o=r&&t.length===0&&n.length===0;if(t.length===0&&n.length===0&&!r)return;let s=await ic(e);await Promise.all([o?y_(e,s):void 0,t.length===0?void 0:N_(e,s,t),n.length===0?void 0:M_(e,s,n)])}function fc(e,t,n,r){let o=r??ds({skillId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home}),s=Kr(e,t,o,P.ComponentKind.SKILL,P.nativeKeyForSkillPath);if(s.sourcePath!==null&&wn(s.sourcePath)?.toLowerCase()===n.toLowerCase())return s.componentReference===void 0?{}:{componentReference:s.componentReference};let i=r??js({commandId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),a=Kr(e,t,i,P.ComponentKind.COMMAND,P.nativeKeyForCommandPath);return a.nativeKey?.toLowerCase()!==n.toLowerCase()?{}:{commandName:a.nativeKey,...a.componentReference===void 0?{}:{componentReference:a.componentReference}}}function N_(e,t,n){let r=kt(e.hookInput.tool_input);return Promise.all(n.map(o=>{let s=fc(e,t,o,r);return Gr(e,t,{tool_name:"Skill",skill_name:o,...s.commandName===void 0?{}:{command_name:s.commandName},...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}function M_(e,t,n){return Promise.all(n.map(r=>{let o=Us({relativePath:r,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),s=Kr(e,t,o,P.ComponentKind.RULE,P.nativeKeyForRulePath),i=s.nativeKey??Fs(r);return Gr(e,t,{tool_name:"Rule",rule_name:i,...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}var w_=[{kind:P.ComponentKind.SKILL,nativeKeyFn:P.nativeKeyForSkillPath},{kind:P.ComponentKind.RULE,nativeKeyFn:P.nativeKeyForRulePath},{kind:P.ComponentKind.COMMAND,nativeKeyFn:P.nativeKeyForCommandPath}];function v_(e,t,n){if(n.skillName===null&&n.ruleName===null&&n.commandName===null)return{};let r=Ln(e.hookInput);if(r===null)return n.skillName===null?{}:fc(e,t,n.skillName,null);let o=cc(r,t.gitRoot,t.home);for(let s of w_){let i=uc(e,o,s.kind,s.nativeKeyFn);if(i.nativeKey!==null)return{...i.componentReference===void 0?{}:{componentReference:i.componentReference},...s.kind===P.ComponentKind.RULE?{ruleName:i.nativeKey}:{},...s.kind===P.ComponentKind.COMMAND?{commandName:i.nativeKey}:{}}}return{}}var L_=/mcp/i;function U_(e,t,n,r){let o=L_.test(e.runnerEvent);if(!r.hasMcpIdentity&&!o)return{};let s=o?Ra(t,n):Zt(r.declaredConfig,n);return s===null?{}:Object.fromEntries(Object.entries(s).filter(i=>typeof i[1]=="string").map(([i,a])=>[`mcp_${i}`,a]))}async function D_(e){let t=await ic(e),n=ei(e.hookInput,e.runnerEvent),{toolName:r,skillName:o}=n,s=vn(e.hookInput),i=Ea(s,t.home),a=ni(e.hookInput),c=Zs(e.runnerEvent),l=c===!1?ri(e.hookInput,e.runnerEvent):null,u=et(R(e.hookInput,"mcp_server_name")),p=u!==null||r!==null&&Dt(r)?await Wn(e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home).catch(()=>[]):[],{mcpServer:m,mcpTool:d}=si(r,p.map(U=>U.name),u??""),g=I_(r,m,e.platformAgentId,e.manifest.installationId,String(e.runnerPlatform),p,u),_=g===void 0?v_(e,t,n):{},S=m===null?null:Vs(m,e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home),E=U_(e,s,t.home,{hasMcpIdentity:!!m||!!d,declaredConfig:S}),y=g??_.componentReference,D=_.ruleName??n.ruleName,k=_.commandName??n.commandName,x=ti(e.hookInput);await $e("tool_invoked",{tool_name:r,skill_name:o,...D?{rule_name:D}:{},...k?{command_name:k}:{},success:c,duration_ms:a,...i?{executable:i}:{},...l?{failure_reason:l}:{},...m?{mcp_server:m}:{},...d?{mcp_tool:d}:{},...E,...y?{component_reference:y}:{},...x?{subagent_type:x}:{},hook_input:t.hookInput},t.envelopeFields,je,e.manifest.collectorUrl,t.buildStartedAtMs,pt(e,t.home))}async function mc(e){switch(e.internalEvent){case"session_start":await k_(e);return;case"session_end":await x_(e);return;case"skill_invoked":await b_(e);return;case"tool_invoked":await D_(e);return;default:return}}import{existsSync as Wr,readFileSync as F_}from"node:fs";import{dirname as H_,isAbsolute as j_,join as $_,relative as K_}from"node:path";function gc(e){for(let t of go){let n=$_(e,t);if(Wr(n))return n}}async function B_(e=process.cwd(),t){let n=t??await fn(e);return gc(n)??gc(e)}async function G_(e,t){let n=t??await fn(H_(e)),r=K_(n,e);if(r.startsWith("..")||j_(r))return!1;let o=await W("git",["ls-files","--error-unmatch",r],2e3,{cwd:n});return o.ok?!0:o.code===1?!1:(h(`WARN: git ls-files failed for manifest ${e} (code=${String(o.code)}); treating as tracked`),!0)}function Vr(e){let t=F_(e,"utf8");return K(t,{})}function z_(){return{schema_version:Ct,mcp_servers:[]}}function V_(e,t,n,r){!t||!n||(e.capture_hook_input==="full"&&r.has("capture_hook_input")&&(h(`WARN: ignoring capture_hook_input=full in git-tracked manifest ${t}; use EV_AI_HOOK_CAPTURE_FULL_INPUT=1 or an untracked operator manifest`),delete e.capture_hook_input),e.debug===!0&&r.has("debug")&&(h(`WARN: ignoring debug=true in git-tracked manifest ${t}; set debug on ~/.ev-ai/config.json`),delete e.debug))}async function _c(e=process.cwd(),t={}){let{root:n,inGitRepo:r}=await pn(e),o=I("EV_AI_HOOK_MANIFEST"),s=o&&Wr(o)?o:void 0,i=s?void 0:Wr(Sn())?Sn():void 0,a=s?void 0:await B_(e,n),c=i?Vr(i):void 0,l=a?Vr(a):void 0,u,p,m,d=new Set;if(s){u=Vr(s),p=s,m=s;for(let y of Object.keys(u))d.add(y)}else if(c&&l){u=_o(l,c),p=i,m=a;for(let y of Object.keys(l))y in c||d.add(y)}else if(c)u=c,p=i;else if(l){u=l,p=a,m=a;for(let y of Object.keys(l))d.add(y)}else u=z_();delete u.installation_id;let g=m?await G_(m,n):!1;V_(u,m,g,d);let{installationId:_,storePath:S,repoKey:E}=await Vo(n,{sessionId:t.sessionId});return{manifestPath:p??S,manifest:u,installationId:_,installationStorePath:S,repoKey:E,collectorUrl:Rn(u),platformAgentId:u.platform_agent_id??"",gitRoot:n,inGitRepo:r}}import{mkdirSync as W_,readdirSync as Y_,readFileSync as J_,statSync as hc,unlinkSync as X_,writeFileSync as Z_}from"node:fs";import{homedir as sn}from"node:os";import{join as Yr}from"node:path";var q_="turns",Sc=1440*60*1e3,Q_=100,eh=new Set(["stop","stopfailure","sessionend"]);function Jr(e=sn()){return Yr(ne(e),q_)}function Ec(e,t){return Yr(e,Ge(t))}function th(e,t=Date.now()){let n;try{n=Y_(e)}catch{return}let r=0;for(let o of n){if(r>=Q_)return;r+=1;try{let s=Yr(e,o);t-hc(s).mtimeMs>Sc&&X_(s)}catch{}}}function nh(e,t,n=sn()){let r=e.trim(),o=t.trim();if(!(!r||!o))try{let s=Jr(n);W_(s,{recursive:!0}),Z_(Ec(s,r),o,"utf8")}catch{}}function rh(e,t=sn()){let n=e.trim();if(!n)return"";try{let r=Ec(Jr(t),n);return Date.now()-hc(r).mtimeMs>Sc?"":J_(r,"utf8").trim()}catch{return""}}function yc(e,t,n,r=sn()){let o=t.trim(),s=eh.has(n.trim().toLowerCase());return s&&th(Jr(r)),o?(nh(e,o,r),o):s?rh(e,r):""}async function Rc(e,t,n,r){let o=t??await dn(In),s=K(o,{}),i=await _c(process.cwd(),{sessionId:Qe(s)});if(!i)return;r&&(i.collectorUrl=r);let a=qs(s,i.manifest.platform,n),c=Qs(e,a.runnerEvent);if(!c){h(`WARN: unknown hook event '${a.runnerEvent}'; skipping telemetry`);return}let l={hookInput:s,sessionId:a.sessionId,turnId:yc(a.sessionId,a.turnId,a.runnerEvent),runnerEvent:a.runnerEvent,runnerPlatform:a.runnerPlatform,hookSource:a.hookSource,internalEvent:c,manifest:i,platformAgentId:i.platformAgentId};await mc(l)}function oh(e){if(I("EV_AI_HOOK_SYNC")==="1")return!0;let{parsed:t,hookInput:n,runnerEvent:r}=e,o=qe(n,r,void 0,t.runner);return Ut(r,o)}function Cc(e,t){let n=hn(e),r=K(t,{}),o=n.event??Xn(r);return so()||Ys(n.runner,r,o)?null:{parsed:n,hookInput:r,runnerEvent:o}}async function Ic(e=process.argv.slice(2)){if(_i(),e[0]===$r){try{await ec(ln)}catch{}return 0}if(e[0]===rn){try{let t=await ln(),n=Cc(e.slice(1),t);if(!n)return 0;let{parsed:r}=n;await Rc(r.event,t,r.runner,Yn(r))}catch(t){let n=t instanceof Error?t.message:String(t);h(`WARN: detached work failed open: ${n}`)}return 0}try{let t=await dn(In),n=Cc(e,t);if(!n)return 0;let{parsed:r,hookInput:o,runnerEvent:s}=n;if(!li(o,s,r.runner))return 0;oh(n)?await Rc(r.event,t,r.runner,Yn(r)):await nc(t,e)}catch(t){let n=t instanceof Error?t.message:String(t);h(`WARN: hook failed open: ${n}`)}finally{no()}return 0}Ic().then(e=>{process.exit(e)}).catch(e=>{let t=e instanceof Error?e.message:String(e);process.stderr.write(`[ev-ai-agent-hook] ${t}
|
|
45
45
|
`),process.exit(1)});
|