@ev-ai/agent-hook 1.2.8 → 1.3.1
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/COLLECTED-DATA.md +13 -5
- package/dist/cli.mjs +39 -38
- package/dist/hook.mjs +34 -33
- package/dist/managed-hooks-snippet.cjs +4 -3
- package/dist/managed-hooks-snippet.mjs +4 -3
- package/dist/plugin-hooks.mjs +20 -6
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -2,50 +2,51 @@
|
|
|
2
2
|
import { createRequire as __createRequire } from 'node:module';
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
-
var Ju=Object.create;var Lo=Object.defineProperty;var Yu=Object.getOwnPropertyDescriptor;var Xu=Object.getOwnPropertyNames;var Zu=Object.getPrototypeOf,qu=Object.prototype.hasOwnProperty;var Mn=(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 be=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Qu=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xu(t))!qu.call(e,o)&&o!==n&&Lo(e,o,{get:()=>t[o],enumerable:!(r=Yu(t,o))||r.enumerable});return e};var Qe=(e,t,n)=>(n=e!=null?Ju(Zu(e)):{},Qu(t||!e||!e.__esModule?Lo(n,"default",{value:e,enumerable:!0}):n,e));var Zt=be(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.MCP_MISSING_LAUNCH_SERIALIZED=N.MCP_LAUNCH_IDENTITY_ALGORITHM=void 0;N.foldMcpName=Mi;N.buildMcpFamilyCanonicalKey=Hf;N.launchContainsCredentials=jf;N.serializeMcpLaunchIdentity=vi;N.hashMcpLaunchIdentity=ct;N.projectMcpMissingLaunchIdentity=Bf;N.projectMcpLaunchIdentity=Gf;N.maskMcpLaunchForDisplay=Vf;N.normalizeMcpToolNames=Wf;var Df=Mn("node:crypto");N.MCP_LAUNCH_IDENTITY_ALGORITHM="mcp-launch-v1";N.MCP_MISSING_LAUNCH_SERIALIZED=`${N.MCP_LAUNCH_IDENTITY_ALGORITHM}|missing`;function le(e){return e.toLocaleLowerCase("en-US")}function Mi(e){return le(e)}function Hf(e){return`interface:${Mi(e)}`}var Ni=new Set(["access_token","api_key","apikey","auth","authorization","key","password","secret","token"]),Ff=/^(?:--?(?:token|api[-_]?key|password|secret|authorization)(?:=|\s+)|(?:sk-|ghp_|xox[baprs]-|Bearer\s+))/i;function Be(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function jf(e){return e.kind==="url"?$f(e.url):e.kind==="command"?e.arguments.some(t=>Ff.test(t)):!1}function $f(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(Ni.has(le(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=le(i.split("=",1)[0]??"");return Ni.has(a)})}}function vi(e){if(e.kind==="url")return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"url",Be(le(e.url))].join("|");if(e.kind==="command"){let t=[...e.arguments].map(n=>le(n)).sort((n,r)=>n<r?-1:n>r?1:0);return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"command",Be(le(e.command)),String(t.length),...t.map(Be)].join("|")}return[N.MCP_LAUNCH_IDENTITY_ALGORITHM,"unknown",Be(e.installationRootExternalKey),Be(e.sourcePath),Be(e.nativeKey)].join("|")}function ct(e){return(0,Df.createHash)("sha256").update(e).digest("hex")}var Kf=ct(N.MCP_MISSING_LAUNCH_SERIALIZED);function Bf(){return{kind:"unknown",arguments:[],serialized:N.MCP_MISSING_LAUNCH_SERIALIZED,contentHash:Kf}}function Gf(e){let t=vi(e);return e.kind==="url"?{kind:"url",url:le(e.url),arguments:[],serialized:t,contentHash:ct(t)}:e.kind==="command"?{kind:"command",command:le(e.command),arguments:[...e.arguments].map(n=>le(n)).sort((n,r)=>n<r?-1:n>r?1:0),serialized:t,contentHash:ct(t)}:{kind:"unknown",arguments:[],serialized:t,contentHash:ct(t)}}var zf=/^(https?:\/\/)([^/?#]*@)/i;function Vf(e){return e.replace(zf,"$1***@").replace(/([?&](?:access_token|api_key|apikey|auth|authorization|key|password|secret|token)=)([^&]*)/gi,"$1***")}function Wf(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 Qt=be(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.PACKAGE_FIELD_MAX=void 0;te.npxExecBin=Li;te.packageNameFromSpec=qt;te.pinnedPackageVersionFromSpec=Ui;te.pinnedPackageVersionFromNpx=np;te.npxPackageSpecs=Di;te.PACKAGE_FIELD_MAX=128;var Jf=/^(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*\/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*$/,Yf=new Set(["-p","--package"]),Xf=new Set(["-c","--call"]),Zf=new Set(["--registry","--userconfig","--globalconfig","--prefix","--cache","--node-options","--workspace","-w","--loglevel"]),qf=new Set(["-y","--yes","-n","--no","-q","-s","--quiet","--silent","--offline","--prefer-offline","--prefer-online","--ignore-existing","--ignore-scripts","--legacy-peer-deps","--foreground-scripts"]),Qf=/^--no-/;function ep(e){return qf.has(e)||Qf.test(e)}function Li(e){let n=(e.replace(/\\/g,"/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="npx"?"npx":n==="npm"?"npm":null}var tp=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;function qt(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 Jf.test(n)?n:null}function Ui(e){let t=qt(e);if(t===null||!e.startsWith(`${t}@`))return;let n=e.slice(t.length+1);return tp.test(n)?n:void 0}function np(e,t){for(let n of Di(e,t)){let r=Ui(n);if(r!==void 0)return r}}function Di(e,t){let n=Li(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(Xf.has(l))return[];if(Yf.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||ep(l))){if(Zf.has(l)){i+=1;continue}return[]}}return o.length>0?o.every(i=>qt(i)!==null)?o:[]:s===null||qt(s)===null?[]:[s]}});var Hi=be(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.McpPackageEcosystem=void 0;we.resolveMcpPackageIdentity=gp;var rp=Zt(),Sr=Qt();we.McpPackageEcosystem={NPM:"npm",PYPI:"pypi"};var op=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/,sp=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/,ip=/^(?:\d+!)?\d+(?:\.\d+)*(?:(?:a|b|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?(?:\+[0-9A-Za-z]+(?:[.][0-9A-Za-z]+)*)?$/;function ap(e){let n=(e.replaceAll("\\","/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="uvx"||n==="uv"||n==="pipx"?n:null}var cp=new Set(["--from","--spec"]),up=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"]),lp=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"]),dp=/^--no-/;function fp(e,t){let n=ap(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(cp.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||lp.has(l)||dp.test(l))){if(up.has(l)){i+=1;continue}return null}}return o??s}function pp(e){if(e.length===0||e.length>Sr.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!sp.test(r)||!ip.test(o)?null:{ecosystem:we.McpPackageEcosystem.PYPI,packageName:r,version:o}}function mp(e){let t=(0,Sr.packageNameFromSpec)(e);if(t===null||!e.startsWith(`${t}@`))return null;let n=e.slice(t.length+1);return op.test(n)?{ecosystem:we.McpPackageEcosystem.NPM,packageName:t,version:n}:null}function gp(e){if(e?.kind!=="command"||(0,rp.launchContainsCredentials)(e))return;for(let n of(0,Sr.npxPackageSpecs)(e.command,e.arguments)){let r=mp(n);if(r!==null)return r}let t=fp(e.command,e.arguments);if(t!==null)return pp(t)??void 0}});var Gi=be(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});de.EMPTY_NPM_PUBLISHER=void 0;de.isNpmRegistryPublisher=hp;de.displayPublisherName=Sp;de.classifyMcpProvenance=bp;var $i=Zt(),Er=Qt();de.EMPTY_NPM_PUBLISHER="npm:";var Fi="npm:",_p=/^[A-Za-z0-9._-]+$/;function hp(e){return e.startsWith(Fi)&&e!==de.EMPTY_NPM_PUBLISHER&&_p.test(e.slice(Fi.length))}function Sp(e){if(!(e==null||e===""||e===de.EMPTY_NPM_PUBLISHER))return e}function ji(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 Ep(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 yr(e){return e.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"")}function yp(e){let t=yr(e),n=Ep(t);return t==="localhost"||t.endsWith(".localhost")||t==="::1"||t.endsWith(".local")||!t.includes(".")&&!t.includes(":")||ji(t)||n!==void 0&&ji(n)||/^(?:fc|fd)[0-9a-f]{2}:/i.test(t)||/^fe[89ab][0-9a-f]:/i.test(t)}function Rp(e){let t=yr(e);return t.includes(":")||/^[0-9.]+$/.test(t)||t.split(".").filter(Boolean).length<2?null:t}function Cp(e){let t=yr(e.hostname),n=t.includes(":")?`[${t}]`:t,r=e.port?`:${e.port}`:"";return`${e.protocol}//${n}${r}`}function Ki(e){let t={kind:"url",url:e};if((0,$i.launchContainsCredentials)(t))return{origin:"UNKNOWN"};try{let n=new URL(e);if(!["http:","https:"].includes(n.protocol)||yp(n.hostname))return{origin:"UNKNOWN"};let r=Rp(n.hostname);return{origin:"THIRD_PARTY",...r===null?{}:{publisherName:r},packageSourceUrl:Cp(n)}}catch{return{origin:"UNKNOWN"}}}var Bi="mcp-remote";function Ap(e,t){if(e===Bi)return t.find(n=>/^https?:\/\//i.test(n))}function Ip(e,t){return{origin:"THIRD_PARTY",...t?{publisherName:t}:{},packageName:e,packageKey:e}}function kp(e,t,n){let r=Ap(e,t);return r!==void 0?Ki(r):e===Bi?{origin:"UNKNOWN"}:Ip(e,n)}function Op(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 bp(e){let t=e.launch;if(t===void 0||t.kind==="unknown")return{origin:"UNKNOWN"};if((0,$i.launchContainsCredentials)(t))return{origin:"UNKNOWN"};if(t.kind==="url")return Ki(t.url);let r=(0,Er.npxPackageSpecs)(t.command,t.arguments)[0];if(r!==void 0){let o=(0,Er.packageNameFromSpec)(r);if(o===null)return{origin:"UNKNOWN"};let s=kp(o,t.arguments,e.publisherName),i=typeof e.packageName=="string"?(0,Er.packageNameFromSpec)(e.packageName):null;return i!==null&&i===o&&s.packageName!==void 0?{...s,packageName:i,packageKey:i}:s}return Op(t.command)?{origin:"INTERNAL"}:{origin:"UNKNOWN"}}});var zi=be(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.parseFrontmatterField=X.parseFrontmatterDescription=X.usableCatalogText=void 0;var xp=/^(?:>|\|)[-+]?$/,Pp=/^(?:>|\|)[-+]?(?:\s+(.*))?$/,Tp=e=>{let t=e?.trim()??"";if(!(t.length===0||xp.test(t)))return t};X.usableCatalogText=Tp;var wp=e=>(0,X.parseFrontmatterField)(e,"description");X.parseFrontmatterDescription=wp;var Np=(e,t)=>{let n=/^---\s*\n([\s\S]*?)\n---/.exec(e);if(n)return vp(n[1],t)};X.parseFrontmatterField=Np;var Mp=e=>e.replace(/^["']|["']$/g,"");function vp(e,t){let n=e.split(`
|
|
6
|
-
`),r=`${t}:`,o=n.findIndex(
|
|
7
|
-
`).split(/\n{2,}/).map(
|
|
8
|
-
`).map(
|
|
5
|
+
var Od=Object.create;var Gs=Object.defineProperty;var Td=Object.getOwnPropertyDescriptor;var Pd=Object.getOwnPropertyNames;var wd=Object.getPrototypeOf,Nd=Object.prototype.hasOwnProperty;var ze=(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 V=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var vd=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pd(t))!Nd.call(e,o)&&o!==n&&Gs(e,o,{get:()=>t[o],enumerable:!(r=Td(t,o))||r.enumerable});return e};var Ve=(e,t,n)=>(n=e!=null?Od(wd(e)):{},vd(t||!e||!e.__esModule?Gs(n,"default",{value:e,enumerable:!0}):n,e));var Bn=V(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.MCP_MISSING_LAUNCH_SERIALIZED=Z.MCP_LAUNCH_IDENTITY_ALGORITHM=void 0;Z.foldMcpName=ja;Z.buildMcpFamilyCanonicalKey=_g;Z.launchContainsCredentials=Eg;Z.serializeMcpLaunchIdentity=Ba;Z.hashMcpLaunchIdentity=Kt;Z.projectMcpMissingLaunchIdentity=Cg;Z.projectMcpLaunchIdentity=Ag;Z.maskMcpLaunchForDisplay=xg;Z.normalizeMcpToolNames=kg;var hg=ze("node:crypto");Z.MCP_LAUNCH_IDENTITY_ALGORITHM="mcp-launch-v1";Z.MCP_MISSING_LAUNCH_SERIALIZED=`${Z.MCP_LAUNCH_IDENTITY_ALGORITHM}|missing`;function $e(e){return e.toLocaleLowerCase("en-US")}function ja(e){return $e(e)}function _g(e){return`interface:${ja(e)}`}var $a=new Set(["access_token","api_key","apikey","auth","authorization","key","password","secret","token"]),Sg=/^(?:--?(?:token|api[-_]?key|password|secret|authorization)(?:=|\s+)|(?:sk-|ghp_|xox[baprs]-|Bearer\s+))/i;function bt(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function Eg(e){return e.kind==="url"?yg(e.url):e.kind==="command"?e.arguments.some(t=>Sg.test(t)):!1}function yg(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($a.has($e(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=$e(i.split("=",1)[0]??"");return $a.has(a)})}}function Ba(e){if(e.kind==="url")return[Z.MCP_LAUNCH_IDENTITY_ALGORITHM,"url",bt($e(e.url))].join("|");if(e.kind==="command"){let t=[...e.arguments].map(n=>$e(n)).sort((n,r)=>n<r?-1:n>r?1:0);return[Z.MCP_LAUNCH_IDENTITY_ALGORITHM,"command",bt($e(e.command)),String(t.length),...t.map(bt)].join("|")}return[Z.MCP_LAUNCH_IDENTITY_ALGORITHM,"unknown",bt(e.installationRootExternalKey),bt(e.sourcePath),bt(e.nativeKey)].join("|")}function Kt(e){return(0,hg.createHash)("sha256").update(e).digest("hex")}var Rg=Kt(Z.MCP_MISSING_LAUNCH_SERIALIZED);function Cg(){return{kind:"unknown",arguments:[],serialized:Z.MCP_MISSING_LAUNCH_SERIALIZED,contentHash:Rg}}function Ag(e){let t=Ba(e);return e.kind==="url"?{kind:"url",url:$e(e.url),arguments:[],serialized:t,contentHash:Kt(t)}:e.kind==="command"?{kind:"command",command:$e(e.command),arguments:[...e.arguments].map(n=>$e(n)).sort((n,r)=>n<r?-1:n>r?1:0),serialized:t,contentHash:Kt(t)}:{kind:"unknown",arguments:[],serialized:t,contentHash:Kt(t)}}var bg=/^(https?:\/\/)([^/?#]*@)/i;function xg(e){return e.replace(bg,"$1***@").replace(/([?&](?:access_token|api_key|apikey|auth|authorization|key|password|secret|token)=)([^&]*)/gi,"$1***")}function kg(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 Gn=V(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});Oe.PACKAGE_FIELD_MAX=void 0;Oe.npxExecBin=Ka;Oe.packageNameFromSpec=Kn;Oe.pinnedPackageVersionFromSpec=Ga;Oe.pinnedPackageVersionFromNpx=Lg;Oe.npxPackageSpecs=Wa;Oe.PACKAGE_FIELD_MAX=128;var Ig=/^(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*\/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*$/,Og=new Set(["-p","--package"]),Tg=new Set(["-c","--call"]),Pg=new Set(["--registry","--userconfig","--globalconfig","--prefix","--cache","--node-options","--workspace","-w","--loglevel"]),wg=new Set(["-y","--yes","-n","--no","-q","-s","--quiet","--silent","--offline","--prefer-offline","--prefer-online","--ignore-existing","--ignore-scripts","--legacy-peer-deps","--foreground-scripts"]),Ng=/^--no-/;function vg(e){return wg.has(e)||Ng.test(e)}function Ka(e){let n=(e.replace(/\\/g,"/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="npx"?"npx":n==="npm"?"npm":null}var Mg=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;function Kn(e){if(e.length===0||e.length>Oe.PACKAGE_FIELD_MAX)return null;let t=e.lastIndexOf("@"),n=t>0?e.slice(0,t):e;return Ig.test(n)?n:null}function Ga(e){let t=Kn(e);if(t===null||!e.startsWith(`${t}@`))return;let n=e.slice(t.length+1);return Mg.test(n)?n:void 0}function Lg(e,t){for(let n of Wa(e,t)){let r=Ga(n);if(r!==void 0)return r}}function Wa(e,t){let n=Ka(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(Tg.has(l))return[];if(Og.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||vg(l))){if(Pg.has(l)){i+=1;continue}return[]}}return o.length>0?o.every(i=>Kn(i)!==null)?o:[]:s===null||Kn(s)===null?[]:[s]}});var za=V(ut=>{"use strict";Object.defineProperty(ut,"__esModule",{value:!0});ut.McpPackageEcosystem=void 0;ut.resolveMcpPackageIdentity=Jg;var Hg=Bn(),go=Gn();ut.McpPackageEcosystem={NPM:"npm",PYPI:"pypi"};var Ug=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/,Dg=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/,Fg=/^(?:\d+!)?\d+(?:\.\d+)*(?:(?:a|b|rc)\d+)?(?:\.post\d+)?(?:\.dev\d+)?(?:\+[0-9A-Za-z]+(?:[.][0-9A-Za-z]+)*)?$/;function $g(e){let n=(e.replaceAll("\\","/").split("/").pop()??"").replace(/\.(cmd|exe|bat|ps1)$/i,"").toLowerCase();return n==="uvx"||n==="uv"||n==="pipx"?n:null}var jg=new Set(["--from","--spec"]),Bg=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"]),Kg=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"]),Gg=/^--no-/;function Wg(e,t){let n=$g(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(jg.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||Kg.has(l)||Gg.test(l))){if(Bg.has(l)){i+=1;continue}return null}}return o??s}function zg(e){if(e.length===0||e.length>go.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!Dg.test(r)||!Fg.test(o)?null:{ecosystem:ut.McpPackageEcosystem.PYPI,packageName:r,version:o}}function Vg(e){let t=(0,go.packageNameFromSpec)(e);if(t===null||!e.startsWith(`${t}@`))return null;let n=e.slice(t.length+1);return Ug.test(n)?{ecosystem:ut.McpPackageEcosystem.NPM,packageName:t,version:n}:null}function Jg(e){if(e?.kind!=="command"||(0,Hg.launchContainsCredentials)(e))return;for(let n of(0,go.npxPackageSpecs)(e.command,e.arguments)){let r=Vg(n);if(r!==null)return r}let t=Wg(e.command,e.arguments);if(t!==null)return zg(t)??void 0}});var Za=V(je=>{"use strict";Object.defineProperty(je,"__esModule",{value:!0});je.EMPTY_NPM_PUBLISHER=void 0;je.isNpmRegistryPublisher=Xg;je.displayPublisherName=qg;je.classifyMcpProvenance=ih;var Ya=Bn(),ho=Gn();je.EMPTY_NPM_PUBLISHER="npm:";var Va="npm:",Yg=/^[A-Za-z0-9._-]+$/;function Xg(e){return e.startsWith(Va)&&e!==je.EMPTY_NPM_PUBLISHER&&Yg.test(e.slice(Va.length))}function qg(e){if(!(e==null||e===""||e===je.EMPTY_NPM_PUBLISHER))return e}function Ja(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 Zg(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 _o(e){return e.toLowerCase().replace(/^\[|\]$/g,"").replace(/\.$/,"")}function Qg(e){let t=_o(e),n=Zg(t);return t==="localhost"||t.endsWith(".localhost")||t==="::1"||t.endsWith(".local")||!t.includes(".")&&!t.includes(":")||Ja(t)||n!==void 0&&Ja(n)||/^(?:fc|fd)[0-9a-f]{2}:/i.test(t)||/^fe[89ab][0-9a-f]:/i.test(t)}function eh(e){let t=_o(e);return t.includes(":")||/^[0-9.]+$/.test(t)||t.split(".").filter(Boolean).length<2?null:t}function th(e){let t=_o(e.hostname),n=t.includes(":")?`[${t}]`:t,r=e.port?`:${e.port}`:"";return`${e.protocol}//${n}${r}`}function Xa(e){let t={kind:"url",url:e};if((0,Ya.launchContainsCredentials)(t))return{origin:"UNKNOWN"};try{let n=new URL(e);if(!["http:","https:"].includes(n.protocol)||Qg(n.hostname))return{origin:"UNKNOWN"};let r=eh(n.hostname);return{origin:"THIRD_PARTY",...r===null?{}:{publisherName:r},packageSourceUrl:th(n)}}catch{return{origin:"UNKNOWN"}}}var qa="mcp-remote";function nh(e,t){if(e===qa)return t.find(n=>/^https?:\/\//i.test(n))}function rh(e,t){return{origin:"THIRD_PARTY",...t?{publisherName:t}:{},packageName:e,packageKey:e}}function oh(e,t,n){let r=nh(e,t);return r!==void 0?Xa(r):e===qa?{origin:"UNKNOWN"}:rh(e,n)}function sh(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 ih(e){let t=e.launch;if(t===void 0||t.kind==="unknown")return{origin:"UNKNOWN"};if((0,Ya.launchContainsCredentials)(t))return{origin:"UNKNOWN"};if(t.kind==="url")return Xa(t.url);let r=(0,ho.npxPackageSpecs)(t.command,t.arguments)[0];if(r!==void 0){let o=(0,ho.packageNameFromSpec)(r);if(o===null)return{origin:"UNKNOWN"};let s=oh(o,t.arguments,e.publisherName),i=typeof e.packageName=="string"?(0,ho.packageNameFromSpec)(e.packageName):null;return i!==null&&i===o&&s.packageName!==void 0?{...s,packageName:i,packageKey:i}:s}return sh(t.command)?{origin:"INTERNAL"}:{origin:"UNKNOWN"}}});var ec=V(Wn=>{"use strict";Object.defineProperty(Wn,"__esModule",{value:!0});Wn.mcpServerToolSegmentForms=Qa;Wn.mcpServerNameMatchesToolSegment=ah;function Qa(e){return[...new Set([e,e.replaceAll(/[^A-Za-z0-9_-]/g,"_"),e.replaceAll(/[^A-Za-z0-9_-]+/g,"_")])]}function ah(e,t){let n=t.toLowerCase();return Qa(e).some(r=>r.toLowerCase()===n)}});var tc=V(Ee=>{"use strict";Object.defineProperty(Ee,"__esModule",{value:!0});Ee.parseFrontmatterField=Ee.parseFrontmatterDescription=Ee.usableCatalogText=void 0;var ch=/^(?:>|\|)[-+]?$/,uh=/^(?:>|\|)[-+]?(?:\s+(.*))?$/,lh=e=>{let t=e?.trim()??"";if(!(t.length===0||ch.test(t)))return t};Ee.usableCatalogText=lh;var fh=e=>(0,Ee.parseFrontmatterField)(e,"description");Ee.parseFrontmatterDescription=fh;var dh=(e,t)=>{let n=/^---\s*\n([\s\S]*?)\n---/.exec(e);if(n)return mh(n[1],t)};Ee.parseFrontmatterField=dh;var ph=e=>e.replace(/^["']|["']$/g,"");function mh(e,t){let n=e.split(`
|
|
6
|
+
`),r=`${t}:`,o=n.findIndex(p=>p===r||p.startsWith(`${r} `)||p.startsWith(`${r} `));if(o<0)return;let s=(n[o]??"").slice(r.length).trim(),i=uh.exec(s);if(!i){let p=ph(s).trim();return(0,Ee.usableCatalogText)(p)}let a=[];for(let p=o+1;p<n.length;p+=1){let g=n[p]??"";if(g.trim()===""){a.push("");continue}if(g.length===g.trimStart().length)break;a.push(g)}let c=a.reduce((p,g)=>g.trim()===""?p:Math.min(p,g.length-g.trimStart().length),Number.POSITIVE_INFINITY),l=[],u=i[1]?.trim();u&&l.push(u);for(let p of a)l.push(p.trim()===""?"":p.slice(c));for(;l.length>0&&l[l.length-1]==="";)l.pop();let f=s.startsWith(">")?l.join(`
|
|
7
|
+
`).split(/\n{2,}/).map(p=>p.split(`
|
|
8
|
+
`).map(g=>g.trim()).filter(Boolean).join(" ")).filter(p=>p.length>0).join(`
|
|
9
9
|
|
|
10
10
|
`):l.join(`
|
|
11
|
-
`).trimEnd();return(0,
|
|
12
|
-
`),n=!1;return t.map(o=>n?
|
|
13
|
-
`)}function Zp(e){return Cr(e)!==e}});var ze=be(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.redactComponentSource=g.prepareComponentInspectionText=g.fitSnapshotInspectionTextBudget=g.componentSourceContainsRedactableSecret=g.capComponentTextBytes=g.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=g.COMPONENT_SOURCE_REDACTION_PLACEHOLDER=g.COMPONENT_INSPECTION_TEXT_MAX_BYTES=g.usableCatalogText=g.parseFrontmatterField=g.parseFrontmatterDescription=g.isNpmRegistryPublisher=g.EMPTY_NPM_PUBLISHER=g.displayPublisherName=g.classifyMcpProvenance=g.resolveMcpPackageIdentity=g.McpPackageEcosystem=g.pinnedPackageVersionFromSpec=g.pinnedPackageVersionFromNpx=g.packageNameFromSpec=g.npxPackageSpecs=g.npxExecBin=g.PACKAGE_FIELD_MAX=g.serializeMcpLaunchIdentity=g.projectMcpMissingLaunchIdentity=g.projectMcpLaunchIdentity=g.normalizeMcpToolNames=g.MCP_MISSING_LAUNCH_SERIALIZED=g.MCP_LAUNCH_IDENTITY_ALGORITHM=g.maskMcpLaunchForDisplay=g.launchContainsCredentials=g.hashMcpLaunchIdentity=g.foldMcpName=g.buildMcpFamilyCanonicalKey=g.ComponentKind=void 0;g.userConfigRootFromPath=am;g.installationRootExternalKey=cm;g.normalizeRepositoryRelativePath=Xi;g.nativeKeyForSkillPath=um;g.nativeKeyForRulePath=lm;g.nativeKeyForCommandPath=dm;g.serializeComponentIdentity=qi;g.buildComponentReference=pm;g.validateComponentReference=mm;var qp=Mn("node:crypto"),Qp=Mn("node:path"),em="cmp1_",tm=/^cmp1_[A-Za-z0-9_-]{43}$/,nm=["/skills/","/skills-cursor/"],rm=/(?:^|\/)\.(?:cursor|claude|codex)\/rules\/(.+)$/i,om=/(?:^|\/)\.(?:cursor|claude|codex)\/(?:commands|prompts)\/(.+)$/i,sm=[".cursor",".claude",".codex"],im={".claude.json":".claude",".agents":".codex"};g.ComponentKind={SKILL:"SKILL",INTERFACE:"INTERFACE",RULE:"RULE",COMMAND:"COMMAND"};function am(e){let t=e.replaceAll("\\","/").split("/").filter(Boolean),n=t.find(o=>sm.includes(o));return n||(t.map(o=>im[o]).find(o=>o!==void 0)??"unknown")}function cm(e,t){return`runtime-install:${e}/${t}`}function en(e,t){if(e.length===0)throw new Error(`${t} is required`);return e}function Xi(e){let t=e.replaceAll("\\","/");if(t.startsWith("/")||/^[A-Za-z]:\//.test(t))throw new Error("sourcePath must be repository-relative");let n=Qp.posix.normalize(t).replace(/^\.\//,"");if(n==="."||n===".."||n.startsWith("../"))throw new Error("sourcePath must be repository-relative");return en(n,"sourcePath")}function um(e){let t=e.replaceAll("\\","/");for(let n of nm){let r=t.split(n)[1]?.split("/")[0];if(r&&r.length>0)return r}return null}function Zi(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 lm(e){return Zi(e,rm,/\.(mdc|md|rules)$/i)}function dm(e){return Zi(e,om,/\.(md|mdc|toml)$/i)}function fm(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function qi(e){let t=[en(e.installationRootExternalKey,"installationRootExternalKey"),en(e.installableKind,"installableKind"),Xi(e.sourcePath),en(e.nativeKey,"nativeKey")];return Buffer.from(`1|${t.map(fm).join("|")}`,"utf8")}function pm(e){let t=(0,qp.createHash)("sha256").update(qi(e)).digest("base64url");return`${em}${t}`}function mm(e){return tm.test(e)}var Z=Zt();Object.defineProperty(g,"buildMcpFamilyCanonicalKey",{enumerable:!0,get:function(){return Z.buildMcpFamilyCanonicalKey}});Object.defineProperty(g,"foldMcpName",{enumerable:!0,get:function(){return Z.foldMcpName}});Object.defineProperty(g,"hashMcpLaunchIdentity",{enumerable:!0,get:function(){return Z.hashMcpLaunchIdentity}});Object.defineProperty(g,"launchContainsCredentials",{enumerable:!0,get:function(){return Z.launchContainsCredentials}});Object.defineProperty(g,"maskMcpLaunchForDisplay",{enumerable:!0,get:function(){return Z.maskMcpLaunchForDisplay}});Object.defineProperty(g,"MCP_LAUNCH_IDENTITY_ALGORITHM",{enumerable:!0,get:function(){return Z.MCP_LAUNCH_IDENTITY_ALGORITHM}});Object.defineProperty(g,"MCP_MISSING_LAUNCH_SERIALIZED",{enumerable:!0,get:function(){return Z.MCP_MISSING_LAUNCH_SERIALIZED}});Object.defineProperty(g,"normalizeMcpToolNames",{enumerable:!0,get:function(){return Z.normalizeMcpToolNames}});Object.defineProperty(g,"projectMcpLaunchIdentity",{enumerable:!0,get:function(){return Z.projectMcpLaunchIdentity}});Object.defineProperty(g,"projectMcpMissingLaunchIdentity",{enumerable:!0,get:function(){return Z.projectMcpMissingLaunchIdentity}});Object.defineProperty(g,"serializeMcpLaunchIdentity",{enumerable:!0,get:function(){return Z.serializeMcpLaunchIdentity}});var Ge=Qt();Object.defineProperty(g,"PACKAGE_FIELD_MAX",{enumerable:!0,get:function(){return Ge.PACKAGE_FIELD_MAX}});Object.defineProperty(g,"npxExecBin",{enumerable:!0,get:function(){return Ge.npxExecBin}});Object.defineProperty(g,"npxPackageSpecs",{enumerable:!0,get:function(){return Ge.npxPackageSpecs}});Object.defineProperty(g,"packageNameFromSpec",{enumerable:!0,get:function(){return Ge.packageNameFromSpec}});Object.defineProperty(g,"pinnedPackageVersionFromNpx",{enumerable:!0,get:function(){return Ge.pinnedPackageVersionFromNpx}});Object.defineProperty(g,"pinnedPackageVersionFromSpec",{enumerable:!0,get:function(){return Ge.pinnedPackageVersionFromSpec}});var Qi=Hi();Object.defineProperty(g,"McpPackageEcosystem",{enumerable:!0,get:function(){return Qi.McpPackageEcosystem}});Object.defineProperty(g,"resolveMcpPackageIdentity",{enumerable:!0,get:function(){return Qi.resolveMcpPackageIdentity}});var tn=Gi();Object.defineProperty(g,"classifyMcpProvenance",{enumerable:!0,get:function(){return tn.classifyMcpProvenance}});Object.defineProperty(g,"displayPublisherName",{enumerable:!0,get:function(){return tn.displayPublisherName}});Object.defineProperty(g,"EMPTY_NPM_PUBLISHER",{enumerable:!0,get:function(){return tn.EMPTY_NPM_PUBLISHER}});Object.defineProperty(g,"isNpmRegistryPublisher",{enumerable:!0,get:function(){return tn.isNpmRegistryPublisher}});var Ar=zi();Object.defineProperty(g,"parseFrontmatterDescription",{enumerable:!0,get:function(){return Ar.parseFrontmatterDescription}});Object.defineProperty(g,"parseFrontmatterField",{enumerable:!0,get:function(){return Ar.parseFrontmatterField}});Object.defineProperty(g,"usableCatalogText",{enumerable:!0,get:function(){return Ar.usableCatalogText}});var Ce=Yi();Object.defineProperty(g,"COMPONENT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return Ce.COMPONENT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(g,"COMPONENT_SOURCE_REDACTION_PLACEHOLDER",{enumerable:!0,get:function(){return Ce.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}});Object.defineProperty(g,"SNAPSHOT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return Ce.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(g,"capComponentTextBytes",{enumerable:!0,get:function(){return Ce.capComponentTextBytes}});Object.defineProperty(g,"componentSourceContainsRedactableSecret",{enumerable:!0,get:function(){return Ce.componentSourceContainsRedactableSecret}});Object.defineProperty(g,"fitSnapshotInspectionTextBudget",{enumerable:!0,get:function(){return Ce.fitSnapshotInspectionTextBudget}});Object.defineProperty(g,"prepareComponentInspectionText",{enumerable:!0,get:function(){return Ce.prepareComponentInspectionText}});Object.defineProperty(g,"redactComponentSource",{enumerable:!0,get:function(){return Ce.redactComponentSource}})});import{realpathSync as ME}from"node:fs";import{resolve as vE}from"node:path";import{fileURLToPath as LE,pathToFileURL as UE}from"node:url";import{createHash as el}from"node:crypto";import{homedir as tl}from"node:os";import{dirname as XE,join as nl,parse as ZE,resolve as qE}from"node:path";var Uo="EV_AI_LAUNCHER_VERSION";var Do="EV_AI_HOOK_SOURCE",Ho="EV_AI_HOOK_FALLBACK_REASON",Fo="EV_AI_LAUNCHER_SCOPE",vn="EV_AI_LAUNCHER_READY_FD";var jo="--defer-user-spec",$o=Buffer.from([1]);var jE=1024*1024,$E=4*1024*1024,KE=64*1024,BE=64*1024,GE=64*1024;var Ln=4096,zE=4*1024*1024;var Bo="https://hooks.ev-ai.ai",Tt=".claude/ev-ai-runtime-report.json",Go="config.json",ey=1024*1024,rl=new Set(["localhost","127.0.0.1","[::1]","::1"]),ol=["claude","cursor","codex"],wt=[Tt,".cursor/ev-ai-runtime-report.json",".codex/ev-ai-runtime-report.json"],Un=/^[A-Za-z0-9._~-]+$/;function Nt(e){return e!==void 0&&ol.includes(e)}function Pt(e,t){let n=e[t+1];return n&&!n.startsWith("--")?{value:n,next:t+1}:{next:t}}function Dn(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=Pt(e,i);t=c.value,i=c.next;continue}if(a.startsWith("--runner=")){t=a.slice(9);continue}if(a==="--url"){let c=Pt(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=Pt(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=Pt(e,i);c.value&&(s=c.value),i=c.next;continue}if(a.startsWith("--base-url=")){s=a.slice(11);continue}a!==jo&&!a.startsWith("-")&&n===void 0&&(n=a)}}return{runner:Nt(t)?t:void 0,event:n,collectorUrl:r,orgToken:o,baseUrl:s}}function Mt(e,t=Bo){let n=t.replace(/\/+$/,""),r=e.trim();return`${n}/${r}/hook`}function Hn(e=tl()){return nl(e,".ev-ai",Go)}function zo(e,t){return{...e,...t}}function Ko(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 vt(e){try{let t=new URL(e);return t.protocol==="https:"?!0:t.protocol==="http:"?rl.has(t.hostname):!1}catch{return!1}}function Fn(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 He(e){let t;try{t=new URL(e)}catch{return`invalid URL (got: ${e})`}if(!vt(e))return`must be https (or http on localhost / 127.0.0.1 / ::1) (got: ${e})`;let n=Fn(e);if(!n)return`must end with /{orgToken}/hook (got: ${e})`;if(!Un.test(n))return`org token must match ${Un.source} (got: ${n})`;if(Ko(e))return`must not contain whitespace, control characters, or single quotes (got: ${e})`;if(Ko(t.pathname))return`pathname must not contain whitespace, control characters, or single quotes (got: ${e})`}function et(e){return new URL(e).toString()}function jn(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?Mt(n):""}function Lt(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 Vo(e){let t=e.collectorUrl?.trim(),n;if(t)n=t;else{let o=e.orgToken?.trim();o&&(n=Mt(o,e.baseUrl?.trim()??void 0))}if(!n)return{};let r=He(n);return r?{problem:r}:{url:et(n)}}function Wo(e){if(He(e))return;let t;try{t=new URL(e)}catch{return}let n=Fn(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 el("sha256").update(i).digest("hex").slice(0,32)}var me=2,Jo="node_modules/@ev-ai/agent-hook/dist/hook.mjs",q="ev-ai-agent-hook";function sl(e){let t=e.split(/[/\\]/).pop();return t&&t.length>0?t:e}function Ut(e){let t=sl(e);return t===q||t===`${q}.exe`}var Yo="https://cdn.ev-ai.ai/agent-hook";var $n=`current/${q}`,Kn=`.ev-ai/agent-hook/${q}`,Xo=5e3,Zo=5e3,Bn=3e3;var Gn=3e3,qo=1500,Qo=4*1024,zn=256*1024,il=4*1024,es=32*1024,tt=840*60*1e3,oe="1.2.8",Dt=`@ev-ai/agent-hook@${oe}`,ts="ev-ai runtime report";import{chmodSync as Vs,cpSync as Ws,existsSync as _e,mkdirSync as cr,readFileSync as gd,rmSync as zt,symlinkSync as _d,writeFileSync as hd}from"node:fs";import{homedir as ce}from"node:os";import{dirname as ur,isAbsolute as Sd,join as x,relative as Js,resolve as Gs,sep as Ed}from"node:path";import{fileURLToPath as yd}from"node:url";import{existsSync as al,readdirSync as ns}from"node:fs";import{homedir as Ht}from"node:os";import{join as K}from"node:path";function rs(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 Vn(e=process.platform){let t=rs(e),n=[K(t,"managed-settings.json")],r=K(t,"managed-settings.d");try{if(!al(r))return n;let o=ns(r).filter(s=>s.endsWith(".json")&&!s.startsWith(".")).sort().map(s=>K(r,s));n.push(...o)}catch{}return n}function Wn(e=process.platform,t=Ht()){return{serverManaged:K(t,".claude","remote-settings.json"),fileBased:Vn(e)}}function cl(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 ul(e=process.platform,t=Ht()){let n=[K(cl(e),"hooks.json")],r=K(t,".cursor","managed");try{for(let o of ns(r,{withFileTypes:!0}))!o.isDirectory()||o.name.startsWith(".")||n.push(K(r,o.name,"hooks.json"))}catch{}return n}function ll(e=process.platform,t=Ht()){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 Ft(e,t=process.platform,n=Ht()){switch(e){case"claude":{let{serverManaged:r,fileBased:o}=Wn(t,n);return[r,...o]}case"cursor":return ul(t,n);default:return ll(t,n)}}import{createHash as Is,randomBytes as Ul}from"node:crypto";import{existsSync as ks,mkdirSync as Qn,readFileSync as Os,unlinkSync as bs,writeFileSync as xs}from"node:fs";import{homedir as er}from"node:os";import{dirname as Kt,join as tr,resolve as Dl}from"node:path";var dl=new Set(["action@github.com","noreply@github.com","noreply@anthropic.com","cursoragent@cursor.com"]),fl=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]")||fl.has(n)||r.includes("[bot]")||dl.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}import{existsSync as Al,readFileSync as Il}from"node:fs";import{hostname as ms,userInfo as kl}from"node:os";import{createHash as pl,randomBytes as ml}from"node:crypto";import{existsSync as Jn,mkdirSync as gl,readdirSync as _l,readFileSync as hl,renameSync as os,statSync as cs,unlinkSync as ss,writeFileSync as Sl}from"node:fs";import{basename as El,dirname as is,join as us,relative as yl}from"node:path";function p(e){process.stderr.write(`[ev-ai-agent-hook] ${e}
|
|
14
|
-
`)}function nt(e){return e.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1")}function rt(e){return pl("sha256").update(e).digest("hex").slice(0,32)}function Q(e,t){gl(is(e),{recursive:!0});let n=us(is(e),`.${El(e)}.${process.pid}.${ml(4).toString("hex")}.tmp`);try{Sl(n,t,"utf8");try{os(n,e)}catch(r){let o=r instanceof Error&&"code"in r?r.code:void 0;if(o==="EEXIST"||o==="EPERM"||o==="EACCES"){ss(e),os(n,e);return}throw r}}catch(r){try{ss(n)}catch{}throw r}}function jt(){return new Date().toISOString().replace(/\.\d{3}Z$/,"Z")}function ls(){process.stdout.write('{"continue":true}')}function A(e){let t=process.env[e];return t===void 0||t===""?void 0:t}async function ot(){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 Yn(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 Y(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 v(e,t,n=3e3,r={}){let o=await Y(e,t,n,r);return o.ok?o.stdout:""}async function Xn(e=process.cwd()){let t=await Y("git",["rev-parse","--show-toplevel"],2e3,{cwd:e});if(t.ok&&t.stdout)return{root:t.stdout,inGitRepo:!0};if(A("EV_AI_HOOK_DEBUG")){let r=t.ok?"empty stdout":t.spawnFailed?"spawn failed":`exit ${String(t.code??"unknown")}`;p(`DEBUG: git rev-parse --show-toplevel failed (${r}) cwd=${e}`)}let n=A("CURSOR_PROJECT_DIR")??A("CLAUDE_PROJECT_DIR");if(n&&Jn(n)){let r=await Y("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 se(e=process.cwd()){return(await Xn(e)).root}function z(e,t){try{return JSON.parse(e)}catch{return t}}var as=new Map;function Rl(e){return e.charCodeAt(0)===65279?e.slice(1):e}function Cl(e){let t;try{t=hl(e,"utf8")}catch{return{ok:!1,reason:"read"}}try{return{ok:!0,value:JSON.parse(Rl(t))}}catch{return{ok:!1,reason:"parse"}}}function ds(e){let t=as.get(e);if(t!==void 0)return t;let n=Cl(e);return as.set(e,n),n}function fs(e){return ds(e)}function D(e,t){let n=ds(e);return n.ok?n.value:t}function xe(e){return typeof e=="string"?e:""}function ie(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=ie(e,t);return typeof n=="string"?n:""}var ge=500;function ps(e,t=2){if(!Jn(e))return{entries:[],truncated:!1};let n=[],r=!1,o=(s,i)=>{if(i>t||r)return;let a;try{a=_l(s,{withFileTypes:!0})}catch{return}for(let c of a){if(r)return;let l=us(s,c.name);if(c.isDirectory()){o(l,i+1);continue}if(c.isFile()){try{n.push({name:yl(e,l),size:cs(l).size})}catch{continue}if(n.length>=ge){r=!0;return}}}};return o(e,1),{entries:n,truncated:r}}function Zn(e){return Jn(e)?{present:!0,size:cs(e).size}:{present:!1,size:0}}function Fe(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function gs(e=process.env){return Fe(w("CURSOR_SANDBOX",e))}var Ol=["CIRCLECI","BUILDKITE","TF_BUILD","JENKINS_URL","JENKINS_HOME","CODEBUILD_BUILD_ID","DRONE","DRONE_BUILD_NUMBER","TEAMCITY_VERSION","TRAVIS","APPVEYOR","BITBUCKET_BUILD_NUMBER"];function bl(e){return Ol.some(t=>!!w(t,e))}function xl(e){if(w("KUBERNETES_SERVICE_HOST",e)||Fe(w("REMOTE_CONTAINERS",e))||Fe(w("DEVCONTAINER",e)))return!0;try{if(Al("/.dockerenv")||Il("/proc/1/environ","utf8").includes("container="))return!0}catch{}return!1}function _s(e){return["VSCODE_PID","VSCODE_IPC_HOOK","CURSOR_EXTENSION_HOST_ROLE","CURSOR_WORKSPACE_LABEL"].some(t=>!!w(t,e))}function Pl(e,t=process.platform){return _s(e)?t==="darwin"||t==="win32"?!0:["__CFBundleIdentifier","DISPLAY","WAYLAND_DISPLAY","SESSIONNAME"].some(n=>!!w(n,e)):!1}function Tl(e){return e===void 0?!1:e.trim().toLowerCase().startsWith("bc-")}function wl(e){return e==="linux"}function w(e,t){if(t){let n=t[e];return n===void 0||n===""?void 0:n}return A(e)}function Nl(e,t,n){return e.trim().toLowerCase()==="cursor"&&t.trim().toLowerCase()==="ubuntu"&&!!Ml(w("CURSOR_VERSION",n))}function Ml(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function qn(e){if(Tl(e.sessionId))return!0;let t=e.hostname??ms(),n=e.osUser??Ss(e.env);return Nl(t,n,e.env)}function vl(e){return Fe(w("CURSOR_AGENT",e.env))?!0:qn(e)}function Ll(e){return!!(process.stdin.isTTY||process.stdout.isTTY||(w("TERM",e)??w("TERM_PROGRAM",e))||(w("SSH_TTY",e)??w("SSH_CONNECTION",e))||(w("__CFBundleIdentifier",e)??w("XPC_SERVICE_NAME",e))||_s(e)||["DISPLAY","WAYLAND_DISPLAY","XDG_SESSION_TYPE","DBUS_SESSION_BUS_ADDRESS"].some(t=>!!w(t,e))||w("SESSIONNAME",e))}function st(e={}){let t=e.env;if(w("GITHUB_ACTIONS",t))return"github_actions";if(Fe(w("CLAUDE_CODE_REMOTE",t)))return"claude_remote";let n=e.platform??process.platform;if(!Pl(t,n)&&vl(e)&&(Fe(w("CURSOR_AGENT",t))||wl(n)))return"cursor_cloud";if(w("CODESPACES",t)||w("CODESPACE_NAME",t))return"codespaces";if(w("GITLAB_CI",t))return"gitlab_ci";if(bl(t))return"managed";let r=w("CI",t);return r&&r!=="false"&&r!=="0"?"managed":xl(t)?"container":Ll(t)?"interactive":"unknown"}async function hs(){return await v("systemd-detect-virt",[],1e3)}function Ss(e=process.env,t=kl){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 Es(){let e=process.platform==="darwin"?"Darwin":process.platform==="win32"?"Windows_NT":"Linux",t="";if(process.platform==="darwin")t=await v("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 v("lsb_release",["-sd"],1e3).then(s=>s.replace(/^"|"$/g,""))}t||(t=await v("uname",["-r"],1e3))}else t=await v("ver",[],1e3);let n=Ss(),r=(process.env.SHELL??"").split(/[/\\]/).pop()??"",o="";try{o=await v("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 $t(){return ms()}var Hl="installation.json",Fl="cloud-bootstrap.lock",jl=6e4;function Ps(e,t,n){let r=`${e}:${t??""}`;return n?`${n}:${r}`:r}function ae(e=er()){return tr(e,".ev-ai","agent-hook")}function $l(e=er()){return tr(ae(e),Hl)}function Ts(e){return tr(Kt(e),Fl)}function ws(){return Ul(8).toString("hex")}function je(e){return Is("sha256").update(e).digest("hex").slice(0,16)}function I(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Ns(e){return/^[A-Za-z0-9._-]{8,64}$/.test(e)}function Kl(e=process.env){let t=I(e.EV_AI_HOOK_INSTALLATION_ID);if(t){if(!Ns(t)){p(`WARN: ignoring EV_AI_HOOK_INSTALLATION_ID (expected 8\u201364 chars [A-Za-z0-9._-], got length ${t.length})`);return}return t}}function Ms(e,t){return e&&Ns(e)?e:(e&&p(`WARN: ignoring installation id override (expected 8\u201364 chars [A-Za-z0-9._-], got length ${e.length})`),Kl(t))}function Bl(e){return/^[0-9a-f]{16}$/.test(e)}function Gl(e=process.env){if(I(e.GITHUB_ACTIONS)){let t=I(e.GITHUB_REPOSITORY_ID)??I(e.GITHUB_REPOSITORY),n=I(e.GITHUB_ACTOR)??I(e.GITHUB_TRIGGERING_ACTOR)??I(e.GITHUB_USER);if(t&&n)return je(`github_actions|${t}|${n}`)}if(I(e.CODESPACES)||I(e.CODESPACE_NAME)){let t=I(e.CODESPACE_NAME);if(t)return je(`codespaces|${t}`);let n=I(e.GITHUB_REPOSITORY_ID)??I(e.GITHUB_REPOSITORY),r=I(e.GITHUB_USER)??I(e.GITHUB_ACTOR);if(n&&r)return je(`codespaces|${n}|${r}`)}if(I(e.GITLAB_CI)){let t=I(e.CI_PROJECT_ID)??I(e.CI_PROJECT_PATH),n=I(e.GITLAB_USER_LOGIN)??I(e.GITLAB_USER_EMAIL)??I(e.GITLAB_USER_NAME);if(t&&n)return je(`gitlab|${t}|${n}`)}return null}var zl="cursoragent@cursor.com";function Vl(e){let t=I(e.CURSOR_USER_EMAIL);return!t||t.toLowerCase()===zl?null:t}function Wl(e,t){return I(e.CURSOR_PROJECT_DIR)??I(e.CLAUDE_PROJECT_DIR)??t}function Jl(e){return nt(e).replace(/\.git$/i,"").toLowerCase()}async function Yl(e){let t=await v("git",["config","--get","remote.origin.url"],2e3,{cwd:e});return t?Jl(t):e}async function Xl(e){let t=I(await v("git",["config","--local","--get","user.email"],2e3,{cwd:e})||void 0);if(t&&!G(null,t))return t;let n=I(await v("git",["log","-1","--format=%ae"],2e3,{cwd:e})||void 0);return n&&!G(null,n)?n:null}function Zl(e,t){let n=Wl(e,t);return n?je(`cursor_cloud|${n}|${Vl(e)??""}`):null}async function ql(e,t){let n=I(e.CLAUDE_PROJECT_DIR)??t;if(!n)return null;let r=await Yl(n),o=await Xl(n);return je(`claude_remote|${r}|${o??""}`)}function ys(e,t){let n=Ms(e,t);if(n)return n;let r=Gl(t);return r||ws()}async function Ql(e){let n=await v("git",["config","--get","remote.origin.url"],2e3,{cwd:e})||Dl(e);return Is("sha256").update(n).digest("hex").slice(0,16)}function ed(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 td(e){try{let t=JSON.parse(e);if(typeof t.installation_id!="string"||t.installation_id.length===0)return;let n=ed(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 Pe(e){if(ks(e))try{return td(Os(e,"utf8"))}catch{}}function nr(e){return Pe(e)}function vs(e,t,n){let r=Pe(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)}
|
|
15
|
-
`)}catch(s){let i=s instanceof Error?s.message:String(s);p(`WARN: operator identity cache write failed open: ${i}`)}}function Ls(e,t=Date.now()){if(!e)return!0;if(Pe(e)?.operator_identity_hash)return!1;let n=Ts(e);try{if(ks(n)){let r=Number.NaN;try{r=Number(Os(n,"utf8").trim())}catch{}let o=t-r;if(Number.isFinite(o)&&o>=0&&o<jl)return!1;try{bs(n)}catch{}}}catch{}try{return Qn(Kt(n),{recursive:!0}),xs(n,`${t}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
`).trimEnd();return(0,Ee.usableCatalogText)(f)}});var oc=V(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=Q.COMPONENT_INSPECTION_TEXT_MAX_BYTES=Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER=void 0;Q.fitSnapshotInspectionTextBudget=gh;Q.capComponentTextBytes=rc;Q.prepareComponentInspectionText=hh;Q.redactComponentSource=So;Q.componentSourceContainsRedactableSecret=Ah;Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER="[REDACTED]";Q.COMPONENT_INSPECTION_TEXT_MAX_BYTES=256*1024;Q.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=3*1024*1024;function gh(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<=Q.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES?(t+=s,n):{...n,skill:{...r.skill,inspectionText:void 0}}})}function rc(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 hh(e){if(!(e==null||e.length===0))return rc(So(e),Q.COMPONENT_INSPECTION_TEXT_MAX_BYTES)}var _h=[/\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],Sh=/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi,Eh=/\b([a-z][a-z0-9+.-]*:\/\/)([^\s/@:]+):([^\s/@]*)@/gi,yh=/([?&](?:access_token|api_key|apikey|auth|authorization|client_secret|key|password|secret|token)=)[^&\s"'<>]+/gi,Rh=/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/,nc=/-----END [A-Z0-9 ]*PRIVATE KEY-----/;function Ch(e){let t=e.replace(Eh,(n,r)=>`${r}${Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}:${Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}@`);t=t.replace(yh,(n,r)=>`${r}${Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}`),t=t.replace(Sh,(n,r)=>`${r}${Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}`);for(let n of _h)t=t.replace(n,Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER);return t}function So(e){if(e.length===0)return e;let t=e.split(`
|
|
12
|
+
`),n=!1;return t.map(o=>n?nc.test(o)?(n=!1,o):o.trim().length===0?o:Q.COMPONENT_SOURCE_REDACTION_PLACEHOLDER:Rh.test(o)&&!nc.test(o)?(n=!0,o):Ch(o)).join(`
|
|
13
|
+
`)}function Ah(e){return So(e)!==e}});var rt=V(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.redactComponentSource=y.prepareComponentInspectionText=y.fitSnapshotInspectionTextBudget=y.componentSourceContainsRedactableSecret=y.capComponentTextBytes=y.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES=y.COMPONENT_SOURCE_REDACTION_PLACEHOLDER=y.COMPONENT_INSPECTION_TEXT_MAX_BYTES=y.usableCatalogText=y.parseFrontmatterField=y.parseFrontmatterDescription=y.mcpServerToolSegmentForms=y.mcpServerNameMatchesToolSegment=y.isNpmRegistryPublisher=y.EMPTY_NPM_PUBLISHER=y.displayPublisherName=y.classifyMcpProvenance=y.resolveMcpPackageIdentity=y.McpPackageEcosystem=y.pinnedPackageVersionFromSpec=y.pinnedPackageVersionFromNpx=y.packageNameFromSpec=y.npxPackageSpecs=y.npxExecBin=y.PACKAGE_FIELD_MAX=y.serializeMcpLaunchIdentity=y.projectMcpMissingLaunchIdentity=y.projectMcpLaunchIdentity=y.normalizeMcpToolNames=y.MCP_MISSING_LAUNCH_SERIALIZED=y.MCP_LAUNCH_IDENTITY_ALGORITHM=y.maskMcpLaunchForDisplay=y.launchContainsCredentials=y.hashMcpLaunchIdentity=y.foldMcpName=y.buildMcpFamilyCanonicalKey=y.ComponentKind=void 0;y.userConfigRootFromPath=vh;y.installationRootExternalKey=Mh;y.normalizeRepositoryRelativePath=sc;y.nativeKeyForSkillPath=Lh;y.nativeKeyForRulePath=Hh;y.nativeKeyForCommandPath=Uh;y.serializeComponentIdentity=ac;y.buildComponentReference=Fh;y.validateComponentReference=$h;var bh=ze("node:crypto"),xh=ze("node:path"),kh="cmp1_",Ih=/^cmp1_[A-Za-z0-9_-]{43}$/,Oh=["/skills/","/skills-cursor/"],Th=/(?:^|\/)\.(?:cursor|claude|codex)\/rules\/(.+)$/i,Ph=/(?:^|\/)\.(?:cursor|claude|codex)\/(?:commands|prompts)\/(.+)$/i,wh=[".cursor",".claude",".codex"],Nh={".claude.json":".claude",".agents":".codex"};y.ComponentKind={SKILL:"SKILL",INTERFACE:"INTERFACE",RULE:"RULE",COMMAND:"COMMAND"};function vh(e){let t=e.replaceAll("\\","/").split("/").filter(Boolean),n=t.find(o=>wh.includes(o));return n||(t.map(o=>Nh[o]).find(o=>o!==void 0)??"unknown")}function Mh(e,t){return`runtime-install:${e}/${t}`}function zn(e,t){if(e.length===0)throw new Error(`${t} is required`);return e}function sc(e){let t=e.replaceAll("\\","/");if(t.startsWith("/")||/^[A-Za-z]:\//.test(t))throw new Error("sourcePath must be repository-relative");let n=xh.posix.normalize(t).replace(/^\.\//,"");if(n==="."||n===".."||n.startsWith("../"))throw new Error("sourcePath must be repository-relative");return zn(n,"sourcePath")}function Lh(e){let t=e.replaceAll("\\","/");for(let n of Oh){let r=t.split(n)[1]?.split("/")[0];if(r&&r.length>0)return r}return null}function ic(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 Hh(e){return ic(e,Th,/\.(mdc|md|rules)$/i)}function Uh(e){return ic(e,Ph,/\.(md|mdc|toml)$/i)}function Dh(e){return`${Buffer.byteLength(e,"utf8")}:${e}`}function ac(e){let t=[zn(e.installationRootExternalKey,"installationRootExternalKey"),zn(e.installableKind,"installableKind"),sc(e.sourcePath),zn(e.nativeKey,"nativeKey")];return Buffer.from(`1|${t.map(Dh).join("|")}`,"utf8")}function Fh(e){let t=(0,bh.createHash)("sha256").update(ac(e)).digest("base64url");return`${kh}${t}`}function $h(e){return Ih.test(e)}var ye=Bn();Object.defineProperty(y,"buildMcpFamilyCanonicalKey",{enumerable:!0,get:function(){return ye.buildMcpFamilyCanonicalKey}});Object.defineProperty(y,"foldMcpName",{enumerable:!0,get:function(){return ye.foldMcpName}});Object.defineProperty(y,"hashMcpLaunchIdentity",{enumerable:!0,get:function(){return ye.hashMcpLaunchIdentity}});Object.defineProperty(y,"launchContainsCredentials",{enumerable:!0,get:function(){return ye.launchContainsCredentials}});Object.defineProperty(y,"maskMcpLaunchForDisplay",{enumerable:!0,get:function(){return ye.maskMcpLaunchForDisplay}});Object.defineProperty(y,"MCP_LAUNCH_IDENTITY_ALGORITHM",{enumerable:!0,get:function(){return ye.MCP_LAUNCH_IDENTITY_ALGORITHM}});Object.defineProperty(y,"MCP_MISSING_LAUNCH_SERIALIZED",{enumerable:!0,get:function(){return ye.MCP_MISSING_LAUNCH_SERIALIZED}});Object.defineProperty(y,"normalizeMcpToolNames",{enumerable:!0,get:function(){return ye.normalizeMcpToolNames}});Object.defineProperty(y,"projectMcpLaunchIdentity",{enumerable:!0,get:function(){return ye.projectMcpLaunchIdentity}});Object.defineProperty(y,"projectMcpMissingLaunchIdentity",{enumerable:!0,get:function(){return ye.projectMcpMissingLaunchIdentity}});Object.defineProperty(y,"serializeMcpLaunchIdentity",{enumerable:!0,get:function(){return ye.serializeMcpLaunchIdentity}});var xt=Gn();Object.defineProperty(y,"PACKAGE_FIELD_MAX",{enumerable:!0,get:function(){return xt.PACKAGE_FIELD_MAX}});Object.defineProperty(y,"npxExecBin",{enumerable:!0,get:function(){return xt.npxExecBin}});Object.defineProperty(y,"npxPackageSpecs",{enumerable:!0,get:function(){return xt.npxPackageSpecs}});Object.defineProperty(y,"packageNameFromSpec",{enumerable:!0,get:function(){return xt.packageNameFromSpec}});Object.defineProperty(y,"pinnedPackageVersionFromNpx",{enumerable:!0,get:function(){return xt.pinnedPackageVersionFromNpx}});Object.defineProperty(y,"pinnedPackageVersionFromSpec",{enumerable:!0,get:function(){return xt.pinnedPackageVersionFromSpec}});var cc=za();Object.defineProperty(y,"McpPackageEcosystem",{enumerable:!0,get:function(){return cc.McpPackageEcosystem}});Object.defineProperty(y,"resolveMcpPackageIdentity",{enumerable:!0,get:function(){return cc.resolveMcpPackageIdentity}});var Vn=Za();Object.defineProperty(y,"classifyMcpProvenance",{enumerable:!0,get:function(){return Vn.classifyMcpProvenance}});Object.defineProperty(y,"displayPublisherName",{enumerable:!0,get:function(){return Vn.displayPublisherName}});Object.defineProperty(y,"EMPTY_NPM_PUBLISHER",{enumerable:!0,get:function(){return Vn.EMPTY_NPM_PUBLISHER}});Object.defineProperty(y,"isNpmRegistryPublisher",{enumerable:!0,get:function(){return Vn.isNpmRegistryPublisher}});var uc=ec();Object.defineProperty(y,"mcpServerNameMatchesToolSegment",{enumerable:!0,get:function(){return uc.mcpServerNameMatchesToolSegment}});Object.defineProperty(y,"mcpServerToolSegmentForms",{enumerable:!0,get:function(){return uc.mcpServerToolSegmentForms}});var Eo=tc();Object.defineProperty(y,"parseFrontmatterDescription",{enumerable:!0,get:function(){return Eo.parseFrontmatterDescription}});Object.defineProperty(y,"parseFrontmatterField",{enumerable:!0,get:function(){return Eo.parseFrontmatterField}});Object.defineProperty(y,"usableCatalogText",{enumerable:!0,get:function(){return Eo.usableCatalogText}});var nt=oc();Object.defineProperty(y,"COMPONENT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return nt.COMPONENT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(y,"COMPONENT_SOURCE_REDACTION_PLACEHOLDER",{enumerable:!0,get:function(){return nt.COMPONENT_SOURCE_REDACTION_PLACEHOLDER}});Object.defineProperty(y,"SNAPSHOT_INSPECTION_TEXT_MAX_BYTES",{enumerable:!0,get:function(){return nt.SNAPSHOT_INSPECTION_TEXT_MAX_BYTES}});Object.defineProperty(y,"capComponentTextBytes",{enumerable:!0,get:function(){return nt.capComponentTextBytes}});Object.defineProperty(y,"componentSourceContainsRedactableSecret",{enumerable:!0,get:function(){return nt.componentSourceContainsRedactableSecret}});Object.defineProperty(y,"fitSnapshotInspectionTextBudget",{enumerable:!0,get:function(){return nt.fitSnapshotInspectionTextBudget}});Object.defineProperty(y,"prepareComponentInspectionText",{enumerable:!0,get:function(){return nt.prepareComponentInspectionText}});Object.defineProperty(y,"redactComponentSource",{enumerable:!0,get:function(){return nt.redactComponentSource}})});var ar=V(_e=>{"use strict";_e.isInteger=e=>typeof e=="number"?Number.isInteger(e):typeof e=="string"&&e.trim()!==""?Number.isInteger(Number(e)):!1;_e.find=(e,t)=>e.nodes.find(n=>n.type===t);_e.exceedsLimit=(e,t,n=1,r)=>r===!1||!_e.isInteger(e)||!_e.isInteger(t)?!1:(Number(t)-Number(e))/Number(n)>=r;_e.escapeNode=(e,t=0,n)=>{let r=e.nodes[t];r&&(n&&r.type===n||r.type==="open"||r.type==="close")&&r.escaped!==!0&&(r.value="\\"+r.value,r.escaped=!0)};_e.encloseBrace=e=>e.type!=="brace"?!1:e.commas>>0+e.ranges>>0===0?(e.invalid=!0,!0):!1;_e.isInvalidBrace=e=>e.type!=="brace"?!1:e.invalid===!0||e.dollar?!0:e.commas>>0+e.ranges>>0===0||e.open!==!0||e.close!==!0?(e.invalid=!0,!0):!1;_e.isOpenOrClose=e=>e.type==="open"||e.type==="close"?!0:e.open===!0||e.close===!0;_e.reduce=e=>e.reduce((t,n)=>(n.type==="text"&&t.push(n.value),n.type==="range"&&(n.type="text"),t),[]);_e.flatten=(...e)=>{let t=[],n=r=>{for(let o=0;o<r.length;o++){let s=r[o];if(Array.isArray(s)){n(s);continue}s!==void 0&&t.push(s)}return t};return n(e),t}});var cr=V((lI,ku)=>{"use strict";var xu=ar();ku.exports=(e,t={})=>{let n=(r,o={})=>{let s=t.escapeInvalid&&xu.isInvalidBrace(o),i=r.invalid===!0&&t.escapeInvalid===!0,a="";if(r.value)return(s||i)&&xu.isOpenOrClose(r)?"\\"+r.value:r.value;if(r.value)return r.value;if(r.nodes)for(let c of r.nodes)a+=n(c);return a};return n(e)}});var Ou=V((fI,Iu)=>{"use strict";Iu.exports=function(e){return typeof e=="number"?e-e===0:typeof e=="string"&&e.trim()!==""?Number.isFinite?Number.isFinite(+e):isFinite(+e):!1}});var Uu=V((dI,Hu)=>{"use strict";var Tu=Ou(),ft=(e,t,n)=>{if(Tu(e)===!1)throw new TypeError("toRegexRange: expected the first argument to be a number");if(t===void 0||e===t)return String(e);if(Tu(t)===!1)throw new TypeError("toRegexRange: expected the second argument to be a number.");let r={relaxZeros:!0,...n};typeof r.strictZeros=="boolean"&&(r.relaxZeros=r.strictZeros===!1);let o=String(r.relaxZeros),s=String(r.shorthand),i=String(r.capture),a=String(r.wrap),c=e+":"+t+"="+o+s+i+a;if(ft.cache.hasOwnProperty(c))return ft.cache[c].result;let l=Math.min(e,t),u=Math.max(e,t);if(Math.abs(l-u)===1){let S=e+"|"+t;return r.capture?`(${S})`:r.wrap===!1?S:`(?:${S})`}let d=Lu(e)||Lu(t),f={min:e,max:t,a:l,b:u},p=[],g=[];if(d&&(f.isPadded=d,f.maxLen=String(f.max).length),l<0){let S=u<0?Math.abs(u):1;g=Pu(S,Math.abs(l),f,r),l=f.a=0}return u>=0&&(p=Pu(l,u,f,r)),f.negatives=g,f.positives=p,f.result=cE(g,p,r),r.capture===!0?f.result=`(${f.result})`:r.wrap!==!1&&p.length+g.length>1&&(f.result=`(?:${f.result})`),ft.cache[c]=f,f.result};function cE(e,t,n){let r=Go(e,t,"-",!1,n)||[],o=Go(t,e,"",!1,n)||[],s=Go(e,t,"-?",!0,n)||[];return r.concat(s).concat(o).join("|")}function uE(e,t){let n=1,r=1,o=Nu(e,n),s=new Set([t]);for(;e<=o&&o<=t;)s.add(o),n+=1,o=Nu(e,n);for(o=vu(t+1,r)-1;e<o&&o<=t;)s.add(o),r+=1,o=vu(t+1,r)-1;return s=[...s],s.sort(dE),s}function lE(e,t,n){if(e===t)return{pattern:e,count:[],digits:0};let r=fE(e,t),o=r.length,s="",i=0;for(let a=0;a<o;a++){let[c,l]=r[a];c===l?s+=c:c!=="0"||l!=="9"?s+=pE(c,l,n):i++}return i&&(s+=n.shorthand===!0?"\\d":"[0-9]"),{pattern:s,count:[i],digits:o}}function Pu(e,t,n,r){let o=uE(e,t),s=[],i=e,a;for(let c=0;c<o.length;c++){let l=o[c],u=lE(String(i),String(l),r),d="";if(!n.isPadded&&a&&a.pattern===u.pattern){a.count.length>1&&a.count.pop(),a.count.push(u.count[0]),a.string=a.pattern+Mu(a.count),i=l+1;continue}n.isPadded&&(d=mE(l,n,r)),u.string=d+u.pattern+Mu(u.count),s.push(u),i=l+1,a=u}return s}function Go(e,t,n,r,o){let s=[];for(let i of e){let{string:a}=i;!r&&!wu(t,"string",a)&&s.push(n+a),r&&wu(t,"string",a)&&s.push(n+a)}return s}function fE(e,t){let n=[];for(let r=0;r<e.length;r++)n.push([e[r],t[r]]);return n}function dE(e,t){return e>t?1:t>e?-1:0}function wu(e,t,n){return e.some(r=>r[t]===n)}function Nu(e,t){return Number(String(e).slice(0,-t)+"9".repeat(t))}function vu(e,t){return e-e%Math.pow(10,t)}function Mu(e){let[t=0,n=""]=e;return n||t>1?`{${t+(n?","+n:"")}}`:""}function pE(e,t,n){return`[${e}${t-e===1?"":"-"}${t}]`}function Lu(e){return/^-?(0+)\d/.test(e)}function mE(e,t,n){if(!t.isPadded)return e;let r=Math.abs(t.maxLen-String(e).length),o=n.relaxZeros!==!1;switch(r){case 0:return"";case 1:return o?"0?":"0";case 2:return o?"0{0,2}":"00";default:return o?`0{0,${r}}`:`0{${r}}`}}ft.cache={};ft.clearCache=()=>ft.cache={};Hu.exports=ft});var Vo=V((pI,Gu)=>{"use strict";var gE=ze("util"),Fu=Uu(),Du=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),hE=e=>t=>e===!0?Number(t):String(t),Wo=e=>typeof e=="number"||typeof e=="string"&&e!=="",Zt=e=>Number.isInteger(+e),zo=e=>{let t=`${e}`,n=-1;if(t[0]==="-"&&(t=t.slice(1)),t==="0")return!1;for(;t[++n]==="0";);return n>0},_E=(e,t,n)=>typeof e=="string"||typeof t=="string"?!0:n.stringify===!0,SE=(e,t,n)=>{if(t>0){let r=e[0]==="-"?"-":"";r&&(e=e.slice(1)),e=r+e.padStart(r?t-1:t,"0")}return n===!1?String(e):e},lr=(e,t)=>{let n=e[0]==="-"?"-":"";for(n&&(e=e.slice(1),t--);e.length<t;)e="0"+e;return n?"-"+e:e},EE=(e,t,n)=>{e.negatives.sort((a,c)=>a<c?-1:a>c?1:0),e.positives.sort((a,c)=>a<c?-1:a>c?1:0);let r=t.capture?"":"?:",o="",s="",i;return e.positives.length&&(o=e.positives.map(a=>lr(String(a),n)).join("|")),e.negatives.length&&(s=`-(${r}${e.negatives.map(a=>lr(String(a),n)).join("|")})`),o&&s?i=`${o}|${s}`:i=o||s,t.wrap?`(${r}${i})`:i},$u=(e,t,n,r)=>{if(n)return Fu(e,t,{wrap:!1,...r});let o=String.fromCharCode(e);if(e===t)return o;let s=String.fromCharCode(t);return`[${o}-${s}]`},ju=(e,t,n)=>{if(Array.isArray(e)){let r=n.wrap===!0,o=n.capture?"":"?:";return r?`(${o}${e.join("|")})`:e.join("|")}return Fu(e,t,n)},Bu=(...e)=>new RangeError("Invalid range arguments: "+gE.inspect(...e)),Ku=(e,t,n)=>{if(n.strictRanges===!0)throw Bu([e,t]);return[]},yE=(e,t)=>{if(t.strictRanges===!0)throw new TypeError(`Expected step "${e}" to be a number`);return[]},RE=(e,t,n=1,r={})=>{let o=Number(e),s=Number(t);if(!Number.isInteger(o)||!Number.isInteger(s)){if(r.strictRanges===!0)throw Bu([e,t]);return[]}o===0&&(o=0),s===0&&(s=0);let i=o>s,a=String(e),c=String(t),l=String(n);n=Math.max(Math.abs(n),1);let u=zo(a)||zo(c)||zo(l),d=u?Math.max(a.length,c.length,l.length):0,f=u===!1&&_E(e,t,r)===!1,p=r.transform||hE(f);if(r.toRegex&&n===1)return $u(lr(e,d),lr(t,d),!0,r);let g={negatives:[],positives:[]},S=I=>g[I<0?"negatives":"positives"].push(Math.abs(I)),A=[],b=0;for(;i?o>=s:o<=s;)r.toRegex===!0&&n>1?S(o):A.push(SE(p(o,b),d,f)),o=i?o-n:o+n,b++;return r.toRegex===!0?n>1?EE(g,r,d):ju(A,null,{wrap:!1,...r}):A},CE=(e,t,n=1,r={})=>{if(!Zt(e)&&e.length>1||!Zt(t)&&t.length>1)return Ku(e,t,r);let o=r.transform||(f=>String.fromCharCode(f)),s=`${e}`.charCodeAt(0),i=`${t}`.charCodeAt(0),a=s>i,c=Math.min(s,i),l=Math.max(s,i);if(r.toRegex&&n===1)return $u(c,l,!1,r);let u=[],d=0;for(;a?s>=i:s<=i;)u.push(o(s,d)),s=a?s-n:s+n,d++;return r.toRegex===!0?ju(u,null,{wrap:!1,options:r}):u},ur=(e,t,n,r={})=>{if(t==null&&Wo(e))return[e];if(!Wo(e)||!Wo(t))return Ku(e,t,r);if(typeof n=="function")return ur(e,t,1,{transform:n});if(Du(n))return ur(e,t,0,n);let o={...r};return o.capture===!0&&(o.wrap=!0),n=n||o.step||1,Zt(n)?Zt(e)&&Zt(t)?RE(e,t,n,o):CE(e,t,Math.max(Math.abs(n),1),o):n!=null&&!Du(n)?yE(n,o):ur(e,t,1,n)};Gu.exports=ur});var Vu=V((mI,zu)=>{"use strict";var AE=Vo(),Wu=ar(),bE=(e,t={})=>{let n=(r,o={})=>{let s=Wu.isInvalidBrace(o),i=r.invalid===!0&&t.escapeInvalid===!0,a=s===!0||i===!0,c=t.escapeInvalid===!0?"\\":"",l="";if(r.isOpen===!0)return c+r.value;if(r.isClose===!0)return console.log("node.isClose",c,r.value),c+r.value;if(r.type==="open")return a?c+r.value:"(";if(r.type==="close")return a?c+r.value:")";if(r.type==="comma")return r.prev.type==="comma"?"":a?r.value:"|";if(r.value)return r.value;if(r.nodes&&r.ranges>0){let u=Wu.reduce(r.nodes),d=AE(...u,{...t,wrap:!1,toRegex:!0,strictZeros:!0});if(d.length!==0)return u.length>1&&d.length>1?`(${d})`:d}if(r.nodes)for(let u of r.nodes)l+=n(u,r);return l};return n(e)};zu.exports=bE});var Xu=V((gI,Yu)=>{"use strict";var xE=Vo(),Ju=cr(),It=ar(),dt=(e="",t="",n=!1)=>{let r=[];if(e=[].concat(e),t=[].concat(t),!t.length)return e;if(!e.length)return n?It.flatten(t).map(o=>`{${o}}`):t;for(let o of e)if(Array.isArray(o))for(let s of o)r.push(dt(s,t,n));else for(let s of t)n===!0&&typeof s=="string"&&(s=`{${s}}`),r.push(Array.isArray(s)?dt(o,s,n):o+s);return It.flatten(r)},kE=(e,t={})=>{let n=t.rangeLimit===void 0?1e3:t.rangeLimit,r=(o,s={})=>{o.queue=[];let i=s,a=s.queue;for(;i.type!=="brace"&&i.type!=="root"&&i.parent;)i=i.parent,a=i.queue;if(o.invalid||o.dollar){a.push(dt(a.pop(),Ju(o,t)));return}if(o.type==="brace"&&o.invalid!==!0&&o.nodes.length===2){a.push(dt(a.pop(),["{}"]));return}if(o.nodes&&o.ranges>0){let d=It.reduce(o.nodes);if(It.exceedsLimit(...d,t.step,n))throw new RangeError("expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.");let f=xE(...d,t);f.length===0&&(f=Ju(o,t)),a.push(dt(a.pop(),f)),o.nodes=[];return}let c=It.encloseBrace(o),l=o.queue,u=o;for(;u.type!=="brace"&&u.type!=="root"&&u.parent;)u=u.parent,l=u.queue;for(let d=0;d<o.nodes.length;d++){let f=o.nodes[d];if(f.type==="comma"&&o.type==="brace"){d===1&&l.push(""),l.push("");continue}if(f.type==="close"){a.push(dt(a.pop(),l,c));continue}if(f.value&&f.type!=="open"){l.push(dt(l.pop(),f.value));continue}f.nodes&&r(f,o)}return l};return It.flatten(r(e))};Yu.exports=kE});var Zu=V((hI,qu)=>{"use strict";qu.exports={MAX_LENGTH:1e4,CHAR_0:"0",CHAR_9:"9",CHAR_UPPERCASE_A:"A",CHAR_LOWERCASE_A:"a",CHAR_UPPERCASE_Z:"Z",CHAR_LOWERCASE_Z:"z",CHAR_LEFT_PARENTHESES:"(",CHAR_RIGHT_PARENTHESES:")",CHAR_ASTERISK:"*",CHAR_AMPERSAND:"&",CHAR_AT:"@",CHAR_BACKSLASH:"\\",CHAR_BACKTICK:"`",CHAR_CARRIAGE_RETURN:"\r",CHAR_CIRCUMFLEX_ACCENT:"^",CHAR_COLON:":",CHAR_COMMA:",",CHAR_DOLLAR:"$",CHAR_DOT:".",CHAR_DOUBLE_QUOTE:'"',CHAR_EQUAL:"=",CHAR_EXCLAMATION_MARK:"!",CHAR_FORM_FEED:"\f",CHAR_FORWARD_SLASH:"/",CHAR_HASH:"#",CHAR_HYPHEN_MINUS:"-",CHAR_LEFT_ANGLE_BRACKET:"<",CHAR_LEFT_CURLY_BRACE:"{",CHAR_LEFT_SQUARE_BRACKET:"[",CHAR_LINE_FEED:`
|
|
14
|
+
`,CHAR_NO_BREAK_SPACE:"\xA0",CHAR_PERCENT:"%",CHAR_PLUS:"+",CHAR_QUESTION_MARK:"?",CHAR_RIGHT_ANGLE_BRACKET:">",CHAR_RIGHT_CURLY_BRACE:"}",CHAR_RIGHT_SQUARE_BRACKET:"]",CHAR_SEMICOLON:";",CHAR_SINGLE_QUOTE:"'",CHAR_SPACE:" ",CHAR_TAB:" ",CHAR_UNDERSCORE:"_",CHAR_VERTICAL_LINE:"|",CHAR_ZERO_WIDTH_NOBREAK_SPACE:"\uFEFF"}});var rl=V((_I,nl)=>{"use strict";var IE=cr(),{MAX_LENGTH:Qu,CHAR_BACKSLASH:Jo,CHAR_BACKTICK:OE,CHAR_COMMA:TE,CHAR_DOT:PE,CHAR_LEFT_PARENTHESES:wE,CHAR_RIGHT_PARENTHESES:NE,CHAR_LEFT_CURLY_BRACE:vE,CHAR_RIGHT_CURLY_BRACE:ME,CHAR_LEFT_SQUARE_BRACKET:el,CHAR_RIGHT_SQUARE_BRACKET:tl,CHAR_DOUBLE_QUOTE:LE,CHAR_SINGLE_QUOTE:HE,CHAR_NO_BREAK_SPACE:UE,CHAR_ZERO_WIDTH_NOBREAK_SPACE:DE}=Zu(),FE=(e,t={})=>{if(typeof e!="string")throw new TypeError("Expected a string");let n=t||{},r=typeof n.maxLength=="number"?Math.min(Qu,n.maxLength):Qu;if(e.length>r)throw new SyntaxError(`Input length (${e.length}), exceeds max characters (${r})`);let o={type:"root",input:e,nodes:[]},s=[o],i=o,a=o,c=0,l=e.length,u=0,d=0,f,p=()=>e[u++],g=S=>{if(S.type==="text"&&a.type==="dot"&&(a.type="text"),a&&a.type==="text"&&S.type==="text"){a.value+=S.value;return}return i.nodes.push(S),S.parent=i,S.prev=a,a=S,S};for(g({type:"bos"});u<l;)if(i=s[s.length-1],f=p(),!(f===DE||f===UE)){if(f===Jo){g({type:"text",value:(t.keepEscaping?f:"")+p()});continue}if(f===tl){g({type:"text",value:"\\"+f});continue}if(f===el){c++;let S;for(;u<l&&(S=p());){if(f+=S,S===el){c++;continue}if(S===Jo){f+=p();continue}if(S===tl&&(c--,c===0))break}g({type:"text",value:f});continue}if(f===wE){i=g({type:"paren",nodes:[]}),s.push(i),g({type:"text",value:f});continue}if(f===NE){if(i.type!=="paren"){g({type:"text",value:f});continue}i=s.pop(),g({type:"text",value:f}),i=s[s.length-1];continue}if(f===LE||f===HE||f===OE){let S=f,A;for(t.keepQuotes!==!0&&(f="");u<l&&(A=p());){if(A===Jo){f+=A+p();continue}if(A===S){t.keepQuotes===!0&&(f+=A);break}f+=A}g({type:"text",value:f});continue}if(f===vE){d++;let A={type:"brace",open:!0,close:!1,dollar:a.value&&a.value.slice(-1)==="$"||i.dollar===!0,depth:d,commas:0,ranges:0,nodes:[]};i=g(A),s.push(i),g({type:"open",value:f});continue}if(f===ME){if(i.type!=="brace"){g({type:"text",value:f});continue}let S="close";i=s.pop(),i.close=!0,g({type:S,value:f}),d--,i=s[s.length-1];continue}if(f===TE&&d>0){if(i.ranges>0){i.ranges=0;let S=i.nodes.shift();i.nodes=[S,{type:"text",value:IE(i)}]}g({type:"comma",value:f}),i.commas++;continue}if(f===PE&&d>0&&i.commas===0){let S=i.nodes;if(d===0||S.length===0){g({type:"text",value:f});continue}if(a.type==="dot"){if(i.range=[],a.value+=f,a.type="range",i.nodes.length!==3&&i.nodes.length!==5){i.invalid=!0,i.ranges=0,a.type="text";continue}i.ranges++,i.args=[];continue}if(a.type==="range"){S.pop();let A=S[S.length-1];A.value+=a.value+f,a=A,i.ranges--;continue}g({type:"dot",value:f});continue}g({type:"text",value:f})}do if(i=s.pop(),i.type!=="root"){i.nodes.forEach(b=>{b.nodes||(b.type==="open"&&(b.isOpen=!0),b.type==="close"&&(b.isClose=!0),b.nodes||(b.type="text"),b.invalid=!0)});let S=s[s.length-1],A=S.nodes.indexOf(i);S.nodes.splice(A,1,...i.nodes)}while(s.length>0);return g({type:"eos"}),o};nl.exports=FE});var il=V((SI,sl)=>{"use strict";var ol=cr(),$E=Vu(),jE=Xu(),BE=rl(),pe=(e,t={})=>{let n=[];if(Array.isArray(e))for(let r of e){let o=pe.create(r,t);Array.isArray(o)?n.push(...o):n.push(o)}else n=[].concat(pe.create(e,t));return t&&t.expand===!0&&t.nodupes===!0&&(n=[...new Set(n)]),n};pe.parse=(e,t={})=>BE(e,t);pe.stringify=(e,t={})=>ol(typeof e=="string"?pe.parse(e,t):e,t);pe.compile=(e,t={})=>(typeof e=="string"&&(e=pe.parse(e,t)),$E(e,t));pe.expand=(e,t={})=>{typeof e=="string"&&(e=pe.parse(e,t));let n=jE(e,t);return t.noempty===!0&&(n=n.filter(Boolean)),t.nodupes===!0&&(n=[...new Set(n)]),n};pe.create=(e,t={})=>e===""||e.length<3?[e]:t.expand!==!0?pe.compile(e,t):pe.expand(e,t);sl.exports=pe});var Qt=V((EI,fl)=>{"use strict";var KE=ze("path"),Pe="\\\\/",al=`[^${Pe}]`,GE=0,Ge="\\.",WE="\\+",zE="\\?",fr="\\/",VE="(?=.)",cl="[^/]",Yo=`(?:${fr}|$)`,ul=`(?:^|${fr})`,Xo=`${Ge}{1,2}${Yo}`,JE=`(?!${Ge})`,YE=`(?!${ul}${Xo})`,XE=`(?!${Ge}{0,1}${Yo})`,qE=`(?!${Xo})`,ZE=`[^.${fr}]`,QE=`${cl}*?`,ll={DOT_LITERAL:Ge,PLUS_LITERAL:WE,QMARK_LITERAL:zE,SLASH_LITERAL:fr,ONE_CHAR:VE,QMARK:cl,END_ANCHOR:Yo,DOTS_SLASH:Xo,NO_DOT:JE,NO_DOTS:YE,NO_DOT_SLASH:XE,NO_DOTS_SLASH:qE,QMARK_NO_DOT:ZE,STAR:QE,START_ANCHOR:ul},ey={...ll,SLASH_LITERAL:`[${Pe}]`,QMARK:al,STAR:`${al}*?`,DOTS_SLASH:`${Ge}{1,2}(?:[${Pe}]|$)`,NO_DOT:`(?!${Ge})`,NO_DOTS:`(?!(?:^|[${Pe}])${Ge}{1,2}(?:[${Pe}]|$))`,NO_DOT_SLASH:`(?!${Ge}{0,1}(?:[${Pe}]|$))`,NO_DOTS_SLASH:`(?!${Ge}{1,2}(?:[${Pe}]|$))`,QMARK_NO_DOT:`[^.${Pe}]`,START_ANCHOR:`(?:^|[${Pe}])`,END_ANCHOR:`(?:[${Pe}]|$)`},ty={__proto__:null,alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"\\x21-\\x7E",lower:"a-z",print:"\\x20-\\x7E ",punct:"\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",space:" \\t\\r\\n\\v\\f",upper:"A-Z",word:"A-Za-z0-9_",xdigit:"A-Fa-f0-9"};fl.exports={DEFAULT_MAX_EXTGLOB_RECURSION:GE,MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:ty,REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":"*","**/**":"**","**/**/**":"**"},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,SEP:KE.sep,extglobChars(e){return{"!":{type:"negate",open:"(?:(?!(?:",close:`))${e.STAR})`},"?":{type:"qmark",open:"(?:",close:")?"},"+":{type:"plus",open:"(?:",close:")+"},"*":{type:"star",open:"(?:",close:")*"},"@":{type:"at",open:"(?:",close:")"}}},globChars(e){return e===!0?ey:ll}}});var en=V(ce=>{"use strict";var ny=ze("path"),ry=process.platform==="win32",{REGEX_BACKSLASH:oy,REGEX_REMOVE_BACKSLASH:sy,REGEX_SPECIAL_CHARS:iy,REGEX_SPECIAL_CHARS_GLOBAL:ay}=Qt();ce.isObject=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);ce.hasRegexChars=e=>iy.test(e);ce.isRegexChar=e=>e.length===1&&ce.hasRegexChars(e);ce.escapeRegex=e=>e.replace(ay,"\\$1");ce.toPosixSlashes=e=>e.replace(oy,"/");ce.removeBackslashes=e=>e.replace(sy,t=>t==="\\"?"":t);ce.supportsLookbehinds=()=>{let e=process.version.slice(1).split(".").map(Number);return e.length===3&&e[0]>=9||e[0]===8&&e[1]>=10};ce.isWindows=e=>e&&typeof e.windows=="boolean"?e.windows:ry===!0||ny.sep==="\\";ce.escapeLast=(e,t,n)=>{let r=e.lastIndexOf(t,n);return r===-1?e:e[r-1]==="\\"?ce.escapeLast(e,t,r-1):`${e.slice(0,r)}\\${e.slice(r)}`};ce.removePrefix=(e,t={})=>{let n=e;return n.startsWith("./")&&(n=n.slice(2),t.prefix="./"),n};ce.wrapOutput=(e,t={},n={})=>{let r=n.contains?"":"^",o=n.contains?"":"$",s=`${r}(?:${e})${o}`;return t.negated===!0&&(s=`(?:^(?!${s}).*$)`),s}});var El=V((RI,Sl)=>{"use strict";var dl=en(),{CHAR_ASTERISK:qo,CHAR_AT:cy,CHAR_BACKWARD_SLASH:tn,CHAR_COMMA:uy,CHAR_DOT:Zo,CHAR_EXCLAMATION_MARK:Qo,CHAR_FORWARD_SLASH:_l,CHAR_LEFT_CURLY_BRACE:es,CHAR_LEFT_PARENTHESES:ts,CHAR_LEFT_SQUARE_BRACKET:ly,CHAR_PLUS:fy,CHAR_QUESTION_MARK:pl,CHAR_RIGHT_CURLY_BRACE:dy,CHAR_RIGHT_PARENTHESES:ml,CHAR_RIGHT_SQUARE_BRACKET:py}=Qt(),gl=e=>e===_l||e===tn,hl=e=>{e.isPrefix!==!0&&(e.depth=e.isGlobstar?1/0:1)},my=(e,t)=>{let n=t||{},r=e.length-1,o=n.parts===!0||n.scanToEnd===!0,s=[],i=[],a=[],c=e,l=-1,u=0,d=0,f=!1,p=!1,g=!1,S=!1,A=!1,b=!1,I=!1,T=!1,v=!1,O=!1,K=0,U,k,w={value:"",depth:0,isGlob:!1},L=()=>l>=r,m=()=>c.charCodeAt(l+1),x=()=>(U=k,c.charCodeAt(++l));for(;l<r;){k=x();let ie;if(k===tn){I=w.backslashes=!0,k=x(),k===es&&(b=!0);continue}if(b===!0||k===es){for(K++;L()!==!0&&(k=x());){if(k===tn){I=w.backslashes=!0,x();continue}if(k===es){K++;continue}if(b!==!0&&k===Zo&&(k=x())===Zo){if(f=w.isBrace=!0,g=w.isGlob=!0,O=!0,o===!0)continue;break}if(b!==!0&&k===uy){if(f=w.isBrace=!0,g=w.isGlob=!0,O=!0,o===!0)continue;break}if(k===dy&&(K--,K===0)){b=!1,f=w.isBrace=!0,O=!0;break}}if(o===!0)continue;break}if(k===_l){if(s.push(l),i.push(w),w={value:"",depth:0,isGlob:!1},O===!0)continue;if(U===Zo&&l===u+1){u+=2;continue}d=l+1;continue}if(n.noext!==!0&&(k===fy||k===cy||k===qo||k===pl||k===Qo)===!0&&m()===ts){if(g=w.isGlob=!0,S=w.isExtglob=!0,O=!0,k===Qo&&l===u&&(v=!0),o===!0){for(;L()!==!0&&(k=x());){if(k===tn){I=w.backslashes=!0,k=x();continue}if(k===ml){g=w.isGlob=!0,O=!0;break}}continue}break}if(k===qo){if(U===qo&&(A=w.isGlobstar=!0),g=w.isGlob=!0,O=!0,o===!0)continue;break}if(k===pl){if(g=w.isGlob=!0,O=!0,o===!0)continue;break}if(k===ly){for(;L()!==!0&&(ie=x());){if(ie===tn){I=w.backslashes=!0,x();continue}if(ie===py){p=w.isBracket=!0,g=w.isGlob=!0,O=!0;break}}if(o===!0)continue;break}if(n.nonegate!==!0&&k===Qo&&l===u){T=w.negated=!0,u++;continue}if(n.noparen!==!0&&k===ts){if(g=w.isGlob=!0,o===!0){for(;L()!==!0&&(k=x());){if(k===ts){I=w.backslashes=!0,k=x();continue}if(k===ml){O=!0;break}}continue}break}if(g===!0){if(O=!0,o===!0)continue;break}}n.noext===!0&&(S=!1,g=!1);let H=c,le="",h="";u>0&&(le=c.slice(0,u),c=c.slice(u),d-=u),H&&g===!0&&d>0?(H=c.slice(0,d),h=c.slice(d)):g===!0?(H="",h=c):H=c,H&&H!==""&&H!=="/"&&H!==c&&gl(H.charCodeAt(H.length-1))&&(H=H.slice(0,-1)),n.unescape===!0&&(h&&(h=dl.removeBackslashes(h)),H&&I===!0&&(H=dl.removeBackslashes(H)));let _={prefix:le,input:e,start:u,base:H,glob:h,isBrace:f,isBracket:p,isGlob:g,isExtglob:S,isGlobstar:A,negated:T,negatedExtglob:v};if(n.tokens===!0&&(_.maxDepth=0,gl(k)||i.push(w),_.tokens=i),n.parts===!0||n.tokens===!0){let ie;for(let D=0;D<s.length;D++){let Re=ie?ie+1:u,Ce=s[D],fe=e.slice(Re,Ce);n.tokens&&(D===0&&u!==0?(i[D].isPrefix=!0,i[D].value=le):i[D].value=fe,hl(i[D]),_.maxDepth+=i[D].depth),(D!==0||fe!=="")&&a.push(fe),ie=Ce}if(ie&&ie+1<e.length){let D=e.slice(ie+1);a.push(D),n.tokens&&(i[i.length-1].value=D,hl(i[i.length-1]),_.maxDepth+=i[i.length-1].depth)}_.slashes=s,_.parts=a}return _};Sl.exports=my});var bl=V((CI,Al)=>{"use strict";var nn=Qt(),se=en(),{MAX_LENGTH:dr,POSIX_REGEX_SOURCE:gy,REGEX_NON_SPECIAL_CHARS:hy,REGEX_SPECIAL_CHARS_BACKREF:_y,REPLACEMENTS:yl}=nn,Sy=(e,t)=>{if(typeof t.expandRange=="function")return t.expandRange(...e,t);e.sort();let n=`[${e.join("-")}]`;try{new RegExp(n)}catch{return e.map(o=>se.escapeRegex(o)).join("..")}return n},Ot=(e,t)=>`Missing ${e}: "${t}" - use "\\\\${t}" to match literal characters`,Rl=e=>{let t=[],n=0,r=0,o=0,s="",i=!1;for(let a of e){if(i===!0){s+=a,i=!1;continue}if(a==="\\"){s+=a,i=!0;continue}if(a==='"'){o=o===1?0:1,s+=a;continue}if(o===0){if(a==="[")n++;else if(a==="]"&&n>0)n--;else if(n===0){if(a==="(")r++;else if(a===")"&&r>0)r--;else if(a==="|"&&r===0){t.push(s),s="";continue}}}s+=a}return t.push(s),t},Ey=e=>{let t=!1;for(let n of e){if(t===!0){t=!1;continue}if(n==="\\"){t=!0;continue}if(/[?*+@!()[\]{}]/.test(n))return!1}return!0},Cl=e=>{let t=e.trim(),n=!0;for(;n===!0;)n=!1,/^@\([^\\()[\]{}|]+\)$/.test(t)&&(t=t.slice(2,-1),n=!0);if(Ey(t))return t.replace(/\\(.)/g,"$1")},yy=e=>{let t=e.map(Cl).filter(Boolean);for(let n=0;n<t.length;n++)for(let r=n+1;r<t.length;r++){let o=t[n],s=t[r],i=o[0];if(!(!i||o!==i.repeat(o.length)||s!==i.repeat(s.length))&&(o===s||o.startsWith(s)||s.startsWith(o)))return!0}return!1},ns=(e,t=!0)=>{if(e[0]!=="+"&&e[0]!=="*"||e[1]!=="(")return;let n=0,r=0,o=0,s=!1;for(let i=1;i<e.length;i++){let a=e[i];if(s===!0){s=!1;continue}if(a==="\\"){s=!0;continue}if(a==='"'){o=o===1?0:1;continue}if(o!==1){if(a==="["){n++;continue}if(a==="]"&&n>0){n--;continue}if(!(n>0)){if(a==="("){r++;continue}if(a===")"&&(r--,r===0))return t===!0&&i!==e.length-1?void 0:{type:e[0],body:e.slice(2,i),end:i}}}}},Ry=e=>{let t=0,n=[];for(;t<e.length;){let o=ns(e.slice(t),!1);if(!o||o.type!=="*")return;let s=Rl(o.body).map(a=>a.trim());if(s.length!==1)return;let i=Cl(s[0]);if(!i||i.length!==1)return;n.push(i),t+=o.end+1}return n.length<1?void 0:`${n.length===1?se.escapeRegex(n[0]):`[${n.map(o=>se.escapeRegex(o)).join("")}]`}*`},Cy=e=>{let t=0,n=e.trim(),r=ns(n);for(;r;)t++,n=r.body.trim(),r=ns(n);return t},Ay=(e,t)=>{if(t.maxExtglobRecursion===!1)return{risky:!1};let n=typeof t.maxExtglobRecursion=="number"?t.maxExtglobRecursion:nn.DEFAULT_MAX_EXTGLOB_RECURSION,r=Rl(e).map(o=>o.trim());if(r.length>1&&(r.some(o=>o==="")||r.some(o=>/^[*?]+$/.test(o))||yy(r)))return{risky:!0};for(let o of r){let s=Ry(o);if(s)return{risky:!0,safeOutput:s};if(Cy(o)>n)return{risky:!0}}return{risky:!1}},rs=(e,t)=>{if(typeof e!="string")throw new TypeError("Expected a string");e=yl[e]||e;let n={...t},r=typeof n.maxLength=="number"?Math.min(dr,n.maxLength):dr,o=e.length;if(o>r)throw new SyntaxError(`Input length: ${o}, exceeds maximum allowed length: ${r}`);let s={type:"bos",value:"",output:n.prepend||""},i=[s],a=n.capture?"":"?:",c=se.isWindows(t),l=nn.globChars(c),u=nn.extglobChars(l),{DOT_LITERAL:d,PLUS_LITERAL:f,SLASH_LITERAL:p,ONE_CHAR:g,DOTS_SLASH:S,NO_DOT:A,NO_DOT_SLASH:b,NO_DOTS_SLASH:I,QMARK:T,QMARK_NO_DOT:v,STAR:O,START_ANCHOR:K}=l,U=C=>`(${a}(?:(?!${K}${C.dot?S:d}).)*?)`,k=n.dot?"":A,w=n.dot?T:v,L=n.bash===!0?U(n):O;n.capture&&(L=`(${L})`),typeof n.noext=="boolean"&&(n.noextglob=n.noext);let m={input:e,index:-1,start:0,dot:n.dot===!0,consumed:"",output:"",prefix:"",backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:i};e=se.removePrefix(e,m),o=e.length;let x=[],H=[],le=[],h=s,_,ie=()=>m.index===o-1,D=m.peek=(C=1)=>e[m.index+C],Re=m.advance=()=>e[++m.index]||"",Ce=()=>e.slice(m.index+1),fe=(C="",Y=0)=>{m.consumed+=C,m.index+=Y},gn=C=>{m.output+=C.output!=null?C.output:C.value,fe(C.value)},kd=()=>{let C=1;for(;D()==="!"&&(D(2)!=="("||D(3)==="?");)Re(),m.start++,C++;return C%2===0?!1:(m.negated=!0,m.start++,!0)},hn=C=>{m[C]++,le.push(C)},We=C=>{m[C]--,le.pop()},N=C=>{if(h.type==="globstar"){let Y=m.braces>0&&(C.type==="comma"||C.type==="brace"),R=C.extglob===!0||x.length&&(C.type==="pipe"||C.type==="paren");C.type!=="slash"&&C.type!=="paren"&&!Y&&!R&&(m.output=m.output.slice(0,-h.output.length),h.type="star",h.value="*",h.output=L,m.output+=h.output)}if(x.length&&C.type!=="paren"&&(x[x.length-1].inner+=C.value),(C.value||C.output)&&gn(C),h&&h.type==="text"&&C.type==="text"){h.value+=C.value,h.output=(h.output||"")+C.value;return}C.prev=h,i.push(C),h=C},_n=(C,Y)=>{let R={...u[Y],conditions:1,inner:""};R.prev=h,R.parens=m.parens,R.output=m.output,R.startIndex=m.index,R.tokensIndex=i.length;let P=(n.capture?"(":"")+R.open;hn("parens"),N({type:C,value:Y,output:m.output?"":g}),N({type:"paren",extglob:!0,value:Re(),output:P}),x.push(R)},Id=C=>{let Y=e.slice(C.startIndex,m.index+1),R=e.slice(C.startIndex+2,m.index),P=Ay(R,n);if((C.type==="plus"||C.type==="star")&&P.risky){let G=P.safeOutput?(C.output?"":g)+(n.capture?`(${P.safeOutput})`:P.safeOutput):void 0,Ae=i[C.tokensIndex];Ae.type="text",Ae.value=Y,Ae.output=G||se.escapeRegex(Y);for(let be=C.tokensIndex+1;be<i.length;be++)i[be].value="",i[be].output="",delete i[be].suffix;m.output=C.output+Ae.output,m.backtrack=!0,N({type:"paren",extglob:!0,value:_,output:""}),We("parens");return}let z=C.close+(n.capture?")":""),re;if(C.type==="negate"){let G=L;if(C.inner&&C.inner.length>1&&C.inner.includes("/")&&(G=U(n)),(G!==L||ie()||/^\)+$/.test(Ce()))&&(z=C.close=`)$))${G}`),C.inner.includes("*")&&(re=Ce())&&/^\.[^\\/.]+$/.test(re)){let Ae=rs(re,{...t,fastpaths:!1}).output;z=C.close=`)${Ae})${G})`}C.prev.type==="bos"&&(m.negatedExtglob=!0)}N({type:"paren",extglob:!0,value:_,output:z}),We("parens")};if(n.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(e)){let C=!1,Y=e.replace(_y,(R,P,z,re,G,Ae)=>re==="\\"?(C=!0,R):re==="?"?P?P+re+(G?T.repeat(G.length):""):Ae===0?w+(G?T.repeat(G.length):""):T.repeat(z.length):re==="."?d.repeat(z.length):re==="*"?P?P+re+(G?L:""):L:P?R:`\\${R}`);return C===!0&&(n.unescape===!0?Y=Y.replace(/\\/g,""):Y=Y.replace(/\\+/g,R=>R.length%2===0?"\\\\":R?"\\":"")),Y===e&&n.contains===!0?(m.output=e,m):(m.output=se.wrapOutput(Y,m,t),m)}for(;!ie();){if(_=Re(),_==="\0")continue;if(_==="\\"){let R=D();if(R==="/"&&n.bash!==!0||R==="."||R===";")continue;if(!R){_+="\\",N({type:"text",value:_});continue}let P=/^\\+/.exec(Ce()),z=0;if(P&&P[0].length>2&&(z=P[0].length,m.index+=z,z%2!==0&&(_+="\\")),n.unescape===!0?_=Re():_+=Re(),m.brackets===0){N({type:"text",value:_});continue}}if(m.brackets>0&&(_!=="]"||h.value==="["||h.value==="[^")){if(n.posix!==!1&&_===":"){let R=h.value.slice(1);if(R.includes("[")&&(h.posix=!0,R.includes(":"))){let P=h.value.lastIndexOf("["),z=h.value.slice(0,P),re=h.value.slice(P+2),G=gy[re];if(G){h.value=z+G,m.backtrack=!0,Re(),!s.output&&i.indexOf(h)===1&&(s.output=g);continue}}}(_==="["&&D()!==":"||_==="-"&&D()==="]")&&(_=`\\${_}`),_==="]"&&(h.value==="["||h.value==="[^")&&(_=`\\${_}`),n.posix===!0&&_==="!"&&h.value==="["&&(_="^"),h.value+=_,gn({value:_});continue}if(m.quotes===1&&_!=='"'){_=se.escapeRegex(_),h.value+=_,gn({value:_});continue}if(_==='"'){m.quotes=m.quotes===1?0:1,n.keepQuotes===!0&&N({type:"text",value:_});continue}if(_==="("){hn("parens"),N({type:"paren",value:_});continue}if(_===")"){if(m.parens===0&&n.strictBrackets===!0)throw new SyntaxError(Ot("opening","("));let R=x[x.length-1];if(R&&m.parens===R.parens+1){Id(x.pop());continue}N({type:"paren",value:_,output:m.parens?")":"\\)"}),We("parens");continue}if(_==="["){if(n.nobracket===!0||!Ce().includes("]")){if(n.nobracket!==!0&&n.strictBrackets===!0)throw new SyntaxError(Ot("closing","]"));_=`\\${_}`}else hn("brackets");N({type:"bracket",value:_});continue}if(_==="]"){if(n.nobracket===!0||h&&h.type==="bracket"&&h.value.length===1){N({type:"text",value:_,output:`\\${_}`});continue}if(m.brackets===0){if(n.strictBrackets===!0)throw new SyntaxError(Ot("opening","["));N({type:"text",value:_,output:`\\${_}`});continue}We("brackets");let R=h.value.slice(1);if(h.posix!==!0&&R[0]==="^"&&!R.includes("/")&&(_=`/${_}`),h.value+=_,gn({value:_}),n.literalBrackets===!1||se.hasRegexChars(R))continue;let P=se.escapeRegex(h.value);if(m.output=m.output.slice(0,-h.value.length),n.literalBrackets===!0){m.output+=P,h.value=P;continue}h.value=`(${a}${P}|${h.value})`,m.output+=h.value;continue}if(_==="{"&&n.nobrace!==!0){hn("braces");let R={type:"brace",value:_,output:"(",outputIndex:m.output.length,tokensIndex:m.tokens.length};H.push(R),N(R);continue}if(_==="}"){let R=H[H.length-1];if(n.nobrace===!0||!R){N({type:"text",value:_,output:_});continue}let P=")";if(R.dots===!0){let z=i.slice(),re=[];for(let G=z.length-1;G>=0&&(i.pop(),z[G].type!=="brace");G--)z[G].type!=="dots"&&re.unshift(z[G].value);P=Sy(re,n),m.backtrack=!0}if(R.comma!==!0&&R.dots!==!0){let z=m.output.slice(0,R.outputIndex),re=m.tokens.slice(R.tokensIndex);R.value=R.output="\\{",_=P="\\}",m.output=z;for(let G of re)m.output+=G.output||G.value}N({type:"brace",value:_,output:P}),We("braces"),H.pop();continue}if(_==="|"){x.length>0&&x[x.length-1].conditions++,N({type:"text",value:_});continue}if(_===","){let R=_,P=H[H.length-1];P&&le[le.length-1]==="braces"&&(P.comma=!0,R="|"),N({type:"comma",value:_,output:R});continue}if(_==="/"){if(h.type==="dot"&&m.index===m.start+1){m.start=m.index+1,m.consumed="",m.output="",i.pop(),h=s;continue}N({type:"slash",value:_,output:p});continue}if(_==="."){if(m.braces>0&&h.type==="dot"){h.value==="."&&(h.output=d);let R=H[H.length-1];h.type="dots",h.output+=_,h.value+=_,R.dots=!0;continue}if(m.braces+m.parens===0&&h.type!=="bos"&&h.type!=="slash"){N({type:"text",value:_,output:d});continue}N({type:"dot",value:_,output:d});continue}if(_==="?"){if(!(h&&h.value==="(")&&n.noextglob!==!0&&D()==="("&&D(2)!=="?"){_n("qmark",_);continue}if(h&&h.type==="paren"){let P=D(),z=_;if(P==="<"&&!se.supportsLookbehinds())throw new Error("Node.js v10 or higher is required for regex lookbehinds");(h.value==="("&&!/[!=<:]/.test(P)||P==="<"&&!/<([!=]|\w+>)/.test(Ce()))&&(z=`\\${_}`),N({type:"text",value:_,output:z});continue}if(n.dot!==!0&&(h.type==="slash"||h.type==="bos")){N({type:"qmark",value:_,output:v});continue}N({type:"qmark",value:_,output:T});continue}if(_==="!"){if(n.noextglob!==!0&&D()==="("&&(D(2)!=="?"||!/[!=<:]/.test(D(3)))){_n("negate",_);continue}if(n.nonegate!==!0&&m.index===0){kd();continue}}if(_==="+"){if(n.noextglob!==!0&&D()==="("&&D(2)!=="?"){_n("plus",_);continue}if(h&&h.value==="("||n.regex===!1){N({type:"plus",value:_,output:f});continue}if(h&&(h.type==="bracket"||h.type==="paren"||h.type==="brace")||m.parens>0){N({type:"plus",value:_});continue}N({type:"plus",value:f});continue}if(_==="@"){if(n.noextglob!==!0&&D()==="("&&D(2)!=="?"){N({type:"at",extglob:!0,value:_,output:""});continue}N({type:"text",value:_});continue}if(_!=="*"){(_==="$"||_==="^")&&(_=`\\${_}`);let R=hy.exec(Ce());R&&(_+=R[0],m.index+=R[0].length),N({type:"text",value:_});continue}if(h&&(h.type==="globstar"||h.star===!0)){h.type="star",h.star=!0,h.value+=_,h.output=L,m.backtrack=!0,m.globstar=!0,fe(_);continue}let C=Ce();if(n.noextglob!==!0&&/^\([^?]/.test(C)){_n("star",_);continue}if(h.type==="star"){if(n.noglobstar===!0){fe(_);continue}let R=h.prev,P=R.prev,z=R.type==="slash"||R.type==="bos",re=P&&(P.type==="star"||P.type==="globstar");if(n.bash===!0&&(!z||C[0]&&C[0]!=="/")){N({type:"star",value:_,output:""});continue}let G=m.braces>0&&(R.type==="comma"||R.type==="brace"),Ae=x.length&&(R.type==="pipe"||R.type==="paren");if(!z&&R.type!=="paren"&&!G&&!Ae){N({type:"star",value:_,output:""});continue}for(;C.slice(0,3)==="/**";){let be=e[m.index+4];if(be&&be!=="/")break;C=C.slice(3),fe("/**",3)}if(R.type==="bos"&&ie()){h.type="globstar",h.value+=_,h.output=U(n),m.output=h.output,m.globstar=!0,fe(_);continue}if(R.type==="slash"&&R.prev.type!=="bos"&&!re&&ie()){m.output=m.output.slice(0,-(R.output+h.output).length),R.output=`(?:${R.output}`,h.type="globstar",h.output=U(n)+(n.strictSlashes?")":"|$)"),h.value+=_,m.globstar=!0,m.output+=R.output+h.output,fe(_);continue}if(R.type==="slash"&&R.prev.type!=="bos"&&C[0]==="/"){let be=C[1]!==void 0?"|$":"";m.output=m.output.slice(0,-(R.output+h.output).length),R.output=`(?:${R.output}`,h.type="globstar",h.output=`${U(n)}${p}|${p}${be})`,h.value+=_,m.output+=R.output+h.output,m.globstar=!0,fe(_+Re()),N({type:"slash",value:"/",output:""});continue}if(R.type==="bos"&&C[0]==="/"){h.type="globstar",h.value+=_,h.output=`(?:^|${p}|${U(n)}${p})`,m.output=h.output,m.globstar=!0,fe(_+Re()),N({type:"slash",value:"/",output:""});continue}m.output=m.output.slice(0,-h.output.length),h.type="globstar",h.output=U(n),h.value+=_,m.output+=h.output,m.globstar=!0,fe(_);continue}let Y={type:"star",value:_,output:L};if(n.bash===!0){Y.output=".*?",(h.type==="bos"||h.type==="slash")&&(Y.output=k+Y.output),N(Y);continue}if(h&&(h.type==="bracket"||h.type==="paren")&&n.regex===!0){Y.output=_,N(Y);continue}(m.index===m.start||h.type==="slash"||h.type==="dot")&&(h.type==="dot"?(m.output+=b,h.output+=b):n.dot===!0?(m.output+=I,h.output+=I):(m.output+=k,h.output+=k),D()!=="*"&&(m.output+=g,h.output+=g)),N(Y)}for(;m.brackets>0;){if(n.strictBrackets===!0)throw new SyntaxError(Ot("closing","]"));m.output=se.escapeLast(m.output,"["),We("brackets")}for(;m.parens>0;){if(n.strictBrackets===!0)throw new SyntaxError(Ot("closing",")"));m.output=se.escapeLast(m.output,"("),We("parens")}for(;m.braces>0;){if(n.strictBrackets===!0)throw new SyntaxError(Ot("closing","}"));m.output=se.escapeLast(m.output,"{"),We("braces")}if(n.strictSlashes!==!0&&(h.type==="star"||h.type==="bracket")&&N({type:"maybe_slash",value:"",output:`${p}?`}),m.backtrack===!0){m.output="";for(let C of m.tokens)m.output+=C.output!=null?C.output:C.value,C.suffix&&(m.output+=C.suffix)}return m};rs.fastpaths=(e,t)=>{let n={...t},r=typeof n.maxLength=="number"?Math.min(dr,n.maxLength):dr,o=e.length;if(o>r)throw new SyntaxError(`Input length: ${o}, exceeds maximum allowed length: ${r}`);e=yl[e]||e;let s=se.isWindows(t),{DOT_LITERAL:i,SLASH_LITERAL:a,ONE_CHAR:c,DOTS_SLASH:l,NO_DOT:u,NO_DOTS:d,NO_DOTS_SLASH:f,STAR:p,START_ANCHOR:g}=nn.globChars(s),S=n.dot?d:u,A=n.dot?f:u,b=n.capture?"":"?:",I={negated:!1,prefix:""},T=n.bash===!0?".*?":p;n.capture&&(T=`(${T})`);let v=k=>k.noglobstar===!0?T:`(${b}(?:(?!${g}${k.dot?l:i}).)*?)`,O=k=>{switch(k){case"*":return`${S}${c}${T}`;case".*":return`${i}${c}${T}`;case"*.*":return`${S}${T}${i}${c}${T}`;case"*/*":return`${S}${T}${a}${c}${A}${T}`;case"**":return S+v(n);case"**/*":return`(?:${S}${v(n)}${a})?${A}${c}${T}`;case"**/*.*":return`(?:${S}${v(n)}${a})?${A}${T}${i}${c}${T}`;case"**/.*":return`(?:${S}${v(n)}${a})?${i}${c}${T}`;default:{let w=/^(.*?)\.(\w+)$/.exec(k);if(!w)return;let L=O(w[1]);return L?L+i+w[2]:void 0}}},K=se.removePrefix(e,I),U=O(K);return U&&n.strictSlashes!==!0&&(U+=`${a}?`),U};Al.exports=rs});var kl=V((AI,xl)=>{"use strict";var by=ze("path"),xy=El(),os=bl(),ss=en(),ky=Qt(),Iy=e=>e&&typeof e=="object"&&!Array.isArray(e),ee=(e,t,n=!1)=>{if(Array.isArray(e)){let u=e.map(f=>ee(f,t,n));return f=>{for(let p of u){let g=p(f);if(g)return g}return!1}}let r=Iy(e)&&e.tokens&&e.input;if(e===""||typeof e!="string"&&!r)throw new TypeError("Expected pattern to be a non-empty string");let o=t||{},s=ss.isWindows(t),i=r?ee.compileRe(e,t):ee.makeRe(e,t,!1,!0),a=i.state;delete i.state;let c=()=>!1;if(o.ignore){let u={...t,ignore:null,onMatch:null,onResult:null};c=ee(o.ignore,u,n)}let l=(u,d=!1)=>{let{isMatch:f,match:p,output:g}=ee.test(u,i,t,{glob:e,posix:s}),S={glob:e,state:a,regex:i,posix:s,input:u,output:g,match:p,isMatch:f};return typeof o.onResult=="function"&&o.onResult(S),f===!1?(S.isMatch=!1,d?S:!1):c(u)?(typeof o.onIgnore=="function"&&o.onIgnore(S),S.isMatch=!1,d?S:!1):(typeof o.onMatch=="function"&&o.onMatch(S),d?S:!0)};return n&&(l.state=a),l};ee.test=(e,t,n,{glob:r,posix:o}={})=>{if(typeof e!="string")throw new TypeError("Expected input to be a string");if(e==="")return{isMatch:!1,output:""};let s=n||{},i=s.format||(o?ss.toPosixSlashes:null),a=e===r,c=a&&i?i(e):e;return a===!1&&(c=i?i(e):e,a=c===r),(a===!1||s.capture===!0)&&(s.matchBase===!0||s.basename===!0?a=ee.matchBase(e,t,n,o):a=t.exec(c)),{isMatch:!!a,match:a,output:c}};ee.matchBase=(e,t,n,r=ss.isWindows(n))=>(t instanceof RegExp?t:ee.makeRe(t,n)).test(by.basename(e));ee.isMatch=(e,t,n)=>ee(t,n)(e);ee.parse=(e,t)=>Array.isArray(e)?e.map(n=>ee.parse(n,t)):os(e,{...t,fastpaths:!1});ee.scan=(e,t)=>xy(e,t);ee.compileRe=(e,t,n=!1,r=!1)=>{if(n===!0)return e.output;let o=t||{},s=o.contains?"":"^",i=o.contains?"":"$",a=`${s}(?:${e.output})${i}`;e&&e.negated===!0&&(a=`^(?!${a}).*$`);let c=ee.toRegex(a,t);return r===!0&&(c.state=e),c};ee.makeRe=(e,t={},n=!1,r=!1)=>{if(!e||typeof e!="string")throw new TypeError("Expected a non-empty string");let o={negated:!1,fastpaths:!0};return t.fastpaths!==!1&&(e[0]==="."||e[0]==="*")&&(o.output=os.fastpaths(e,t)),o.output||(o=os(e,t)),ee.compileRe(o,t,n,r)};ee.toRegex=(e,t)=>{try{let n=t||{};return new RegExp(e,n.flags||(n.nocase?"i":""))}catch(n){if(t&&t.debug===!0)throw n;return/$^/}};ee.constants=ky;xl.exports=ee});var Ol=V((bI,Il)=>{"use strict";Il.exports=kl()});var Ml=V((xI,vl)=>{"use strict";var Pl=ze("util"),wl=il(),we=Ol(),is=en(),Tl=e=>e===""||e==="./",Nl=e=>{let t=e.indexOf("{");return t>-1&&e.indexOf("}",t)>-1},J=(e,t,n)=>{t=[].concat(t),e=[].concat(e);let r=new Set,o=new Set,s=new Set,i=0,a=u=>{s.add(u.output),n&&n.onResult&&n.onResult(u)};for(let u=0;u<t.length;u++){let d=we(String(t[u]),{...n,onResult:a},!0),f=d.state.negated||d.state.negatedExtglob;f&&i++;for(let p of e){let g=d(p,!0);(f?!g.isMatch:g.isMatch)&&(f?r.add(g.output):(r.delete(g.output),o.add(g.output)))}}let l=(i===t.length?[...s]:[...o]).filter(u=>!r.has(u));if(n&&l.length===0){if(n.failglob===!0)throw new Error(`No matches found for "${t.join(", ")}"`);if(n.nonull===!0||n.nullglob===!0)return n.unescape?t.map(u=>u.replace(/\\/g,"")):t}return l};J.match=J;J.matcher=(e,t)=>we(e,t);J.isMatch=(e,t,n)=>we(t,n)(e);J.any=J.isMatch;J.not=(e,t,n={})=>{t=[].concat(t).map(String);let r=new Set,o=[],s=a=>{n.onResult&&n.onResult(a),o.push(a.output)},i=new Set(J(e,t,{...n,onResult:s}));for(let a of o)i.has(a)||r.add(a);return[...r]};J.contains=(e,t,n)=>{if(typeof e!="string")throw new TypeError(`Expected a string: "${Pl.inspect(e)}"`);if(Array.isArray(t))return t.some(r=>J.contains(e,r,n));if(typeof t=="string"){if(Tl(e)||Tl(t))return!1;if(e.includes(t)||e.startsWith("./")&&e.slice(2).includes(t))return!0}return J.isMatch(e,t,{...n,contains:!0})};J.matchKeys=(e,t,n)=>{if(!is.isObject(e))throw new TypeError("Expected the first argument to be an object");let r=J(Object.keys(e),t,n),o={};for(let s of r)o[s]=e[s];return o};J.some=(e,t,n)=>{let r=[].concat(e);for(let o of[].concat(t)){let s=we(String(o),n);if(r.some(i=>s(i)))return!0}return!1};J.every=(e,t,n)=>{let r=[].concat(e);for(let o of[].concat(t)){let s=we(String(o),n);if(!r.every(i=>s(i)))return!1}return!0};J.all=(e,t,n)=>{if(typeof e!="string")throw new TypeError(`Expected a string: "${Pl.inspect(e)}"`);return[].concat(t).every(r=>we(r,n)(e))};J.capture=(e,t,n)=>{let r=is.isWindows(n),s=we.makeRe(String(e),{...n,capture:!0}).exec(r?is.toPosixSlashes(t):t);if(s)return s.slice(1).map(i=>i===void 0?"":i)};J.makeRe=(...e)=>we.makeRe(...e);J.scan=(...e)=>we.scan(...e);J.parse=(e,t)=>{let n=[];for(let r of[].concat(e||[]))for(let o of wl(String(r),t))n.push(we.parse(o,t));return n};J.braces=(e,t)=>{if(typeof e!="string")throw new TypeError("Expected a string");return t&&t.nobrace===!0||!Nl(e)?[e]:wl(e,t)};J.braceExpand=(e,t)=>{if(typeof e!="string")throw new TypeError("Expected a string");return J.braces(e,{...t,expand:!0})};J.hasBraces=Nl;vl.exports=J});import{realpathSync as IA}from"node:fs";import{resolve as OA}from"node:path";import{fileURLToPath as TA,pathToFileURL as PA}from"node:url";import{createHash as Md}from"node:crypto";import{homedir as Ld}from"node:os";import{dirname as GA,join as Hd,parse as WA,resolve as zA}from"node:path";var Ws="EV_AI_LAUNCHER_VERSION";var zs="EV_AI_HOOK_SOURCE",Vs="EV_AI_HOOK_FALLBACK_REASON",Js="EV_AI_LAUNCHER_SCOPE",wr="EV_AI_LAUNCHER_READY_FD";var Ys="--defer-user-spec",Xs=Buffer.from([1]);var MA=1024*1024,LA=4*1024*1024,HA=64*1024,UA=64*1024,DA=64*1024;var Nr=4096,FA=4*1024*1024;var Zs="https://hooks.ev-ai.ai",En=".claude/ev-ai-runtime-report.json",Qs="config.json",JA=1024*1024,Ud=new Set(["localhost","127.0.0.1","[::1]","::1"]),Dd=["claude","cursor","codex"],yn=[En,".cursor/ev-ai-runtime-report.json",".codex/ev-ai-runtime-report.json"],vr=/^[A-Za-z0-9._~-]+$/;function Rn(e){return e!==void 0&&Dd.includes(e)}function Sn(e,t){let n=e[t+1];return n&&!n.startsWith("--")?{value:n,next:t+1}:{next:t}}function Mr(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=Sn(e,i);t=c.value,i=c.next;continue}if(a.startsWith("--runner=")){t=a.slice(9);continue}if(a==="--url"){let c=Sn(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=Sn(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=Sn(e,i);c.value&&(s=c.value),i=c.next;continue}if(a.startsWith("--base-url=")){s=a.slice(11);continue}a!==Ys&&!a.startsWith("-")&&n===void 0&&(n=a)}}return{runner:Rn(t)?t:void 0,event:n,collectorUrl:r,orgToken:o,baseUrl:s}}function Cn(e,t=Zs){let n=t.replace(/\/+$/,""),r=e.trim();return`${n}/${r}/hook`}function Lr(e=Ld()){return Hd(e,".ev-ai",Qs)}function ei(e,t){return{...e,...t}}function qs(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 An(e){try{let t=new URL(e);return t.protocol==="https:"?!0:t.protocol==="http:"?Ud.has(t.hostname):!1}catch{return!1}}function Hr(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 Et(e){let t;try{t=new URL(e)}catch{return`invalid URL (got: ${e})`}if(!An(e))return`must be https (or http on localhost / 127.0.0.1 / ::1) (got: ${e})`;let n=Hr(e);if(!n)return`must end with /{orgToken}/hook (got: ${e})`;if(!vr.test(n))return`org token must match ${vr.source} (got: ${n})`;if(qs(e))return`must not contain whitespace, control characters, or single quotes (got: ${e})`;if(qs(t.pathname))return`pathname must not contain whitespace, control characters, or single quotes (got: ${e})`}function Ht(e){return new URL(e).toString()}function Ur(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?Cn(n):""}function bn(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 ti(e){let t=e.collectorUrl?.trim(),n;if(t)n=t;else{let o=e.orgToken?.trim();o&&(n=Cn(o,e.baseUrl?.trim()??void 0))}if(!n)return{};let r=Et(n);return r?{problem:r}:{url:Ht(n)}}function ni(e){if(Et(e))return;let t;try{t=new URL(e)}catch{return}let n=Hr(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 Md("sha256").update(i).digest("hex").slice(0,32)}var Je=2,ri="node_modules/@ev-ai/agent-hook/dist/hook.mjs",xe="ev-ai-agent-hook";function Fd(e){let t=e.split(/[/\\]/).pop();return t&&t.length>0?t:e}function xn(e){let t=Fd(e);return t===xe||t===`${xe}.exe`}var oi="https://cdn.ev-ai.ai/agent-hook";var Dr=`current/${xe}`,Fr=`.ev-ai/agent-hook/${xe}`,si=5e3,ii=5e3,$r=3e3;var kn=3e3,ai=1500,ci=4*1024,jr=256*1024,$d=4*1024,ui=32*1024,Me="1.3.1",In=`@ev-ai/agent-hook@${Me}`,li="ev-ai runtime report";import{chmodSync as ea,cpSync as ta,existsSync as Xe,mkdirSync as oo,readFileSync as Yp,rmSync as Hn,symlinkSync as Xp,writeFileSync as qp}from"node:fs";import{homedir as De}from"node:os";import{dirname as so,isAbsolute as Zp,join as W,relative as na,resolve as Zi,sep as Qp}from"node:path";import{fileURLToPath as em}from"node:url";import{existsSync as jd,readdirSync as fi}from"node:fs";import{homedir as On}from"node:os";import{join as ae}from"node:path";function di(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/ClaudeCode";case"win32":return ae(process.env.ProgramFiles??"C:\\Program Files","ClaudeCode");default:return"/etc/claude-code"}}function Br(e=process.platform){let t=di(e),n=[ae(t,"managed-settings.json")],r=ae(t,"managed-settings.d");try{if(!jd(r))return n;let o=fi(r).filter(s=>s.endsWith(".json")&&!s.startsWith(".")).sort().map(s=>ae(r,s));n.push(...o)}catch{}return n}function Kr(e=process.platform,t=On()){return{serverManaged:ae(t,".claude","remote-settings.json"),fileBased:Br(e)}}function Bd(e=process.platform){switch(e){case"darwin":return"/Library/Application Support/Cursor";case"win32":return ae(process.env.ProgramData??"C:\\ProgramData","Cursor");default:return"/etc/cursor"}}function Kd(e=process.platform,t=On()){let n=[ae(Bd(e),"hooks.json")],r=ae(t,".cursor","managed");try{for(let o of fi(r,{withFileTypes:!0}))!o.isDirectory()||o.name.startsWith(".")||n.push(ae(r,o.name,"hooks.json"))}catch{}return n}function Gd(e=process.platform,t=On()){let n=e==="win32"?ae(process.env.ProgramData??"C:\\ProgramData","OpenAI","Codex"):"/etc/codex",r=[ae(n,"requirements.toml")];return e!=="win32"&&r.push(ae(n,"managed_config.toml")),r.push(ae(t,".codex","managed_config.toml"),ae(n,"config.toml")),r}function Tn(e,t=process.platform,n=On()){switch(e){case"claude":{let{serverManaged:r,fileBased:o}=Kr(t,n);return[r,...o]}case"cursor":return Kd(t,n);default:return Gd(t,n)}}import{createHash as Ni,randomBytes as hp}from"node:crypto";import{existsSync as vi,mkdirSync as Yr,readFileSync as Mi,unlinkSync as Li,writeFileSync as Hi}from"node:fs";import{homedir as Xr}from"node:os";import{dirname as vn,join as qr,resolve as _p}from"node:path";var Wd=new Set(["action@github.com","noreply@github.com","noreply@anthropic.com","cursoragent@cursor.com"]),zd=new Set(["github-actions","github actions","dependabot","renovate","cursoragent","cursor agent"]);function de(e,t){let n=(e??"").trim().toLowerCase(),r=(t??"").trim().toLowerCase();if(!n&&!r)return!1;if(n.includes("[bot]")||zd.has(n)||r.includes("[bot]")||Wd.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}import{existsSync as rp,readFileSync as op}from"node:fs";import{hostname as Ci,userInfo as sp}from"node:os";import{createHash as Vd,randomBytes as Jd}from"node:crypto";import{existsSync as Gr,mkdirSync as Yd,readdirSync as Xd,readFileSync as qd,renameSync as pi,statSync as _i,unlinkSync as mi,writeFileSync as Zd}from"node:fs";import{basename as Qd,dirname as gi,join as Si,relative as ep}from"node:path";function E(e){process.stderr.write(`[ev-ai-agent-hook] ${e}
|
|
15
|
+
`)}function Ut(e){return e.replace(/^([a-z]+:\/\/)[^/@]+@/i,"$1")}function Dt(e){return Vd("sha256").update(e).digest("hex").slice(0,32)}function ke(e,t){Yd(gi(e),{recursive:!0});let n=Si(gi(e),`.${Qd(e)}.${process.pid}.${Jd(4).toString("hex")}.tmp`);try{Zd(n,t,"utf8");try{pi(n,e)}catch(r){let o=r instanceof Error&&"code"in r?r.code:void 0;if(o==="EEXIST"||o==="EPERM"||o==="EACCES"){mi(e),pi(n,e);return}throw r}}catch(r){try{mi(n)}catch{}throw r}}function Pn(){return new Date().toISOString().replace(/\.\d{3}Z$/,"Z")}function Wr(){process.stdout.write('{"continue":true}')}function F(e){let t=process.env[e];return t===void 0||t===""?void 0:t}async function Ft(){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 wn(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 Se(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 te(e,t,n=3e3,r={}){let o=await Se(e,t,n,r);return o.ok?o.stdout:""}async function zr(e=process.cwd()){let t=await Se("git",["rev-parse","--show-toplevel"],2e3,{cwd:e});if(t.ok&&t.stdout)return{root:t.stdout,inGitRepo:!0};if(F("EV_AI_HOOK_DEBUG")){let r=t.ok?"empty stdout":t.spawnFailed?"spawn failed":`exit ${String(t.code??"unknown")}`;E(`DEBUG: git rev-parse --show-toplevel failed (${r}) cwd=${e}`)}let n=F("CURSOR_PROJECT_DIR")??F("CLAUDE_PROJECT_DIR");if(n&&Gr(n)){let r=await Se("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 Le(e=process.cwd()){return(await zr(e)).root}function me(e,t){try{return JSON.parse(e)}catch{return t}}var hi=new Map;function tp(e){return e.charCodeAt(0)===65279?e.slice(1):e}function np(e){let t;try{t=qd(e,"utf8")}catch{return{ok:!1,reason:"read"}}try{return{ok:!0,value:JSON.parse(tp(t))}}catch{return{ok:!1,reason:"parse"}}}function Ei(e){let t=hi.get(e);if(t!==void 0)return t;let n=np(e);return hi.set(e,n),n}function yi(e){return Ei(e)}function oe(e,t){let n=Ei(e);return n.ok?n.value:t}function it(e){return typeof e=="string"?e:""}function He(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 M(e,t){let n=He(e,t);return typeof n=="string"?n:""}var Ye=500;function Ri(e,t=2){if(!Gr(e))return{entries:[],truncated:!1};let n=[],r=!1,o=(s,i)=>{if(i>t||r)return;let a;try{a=Xd(s,{withFileTypes:!0})}catch{return}for(let c of a){if(r)return;let l=Si(s,c.name);if(c.isDirectory()){o(l,i+1);continue}if(c.isFile()){try{n.push({name:ep(e,l),size:_i(l).size})}catch{continue}if(n.length>=Ye){r=!0;return}}}};return o(e,1),{entries:n,truncated:r}}function Vr(e){return Gr(e)?{present:!0,size:_i(e).size}:{present:!1,size:0}}function yt(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function Ai(e=process.env){return yt(X("CURSOR_SANDBOX",e))}var ip=["CIRCLECI","BUILDKITE","TF_BUILD","JENKINS_URL","JENKINS_HOME","CODEBUILD_BUILD_ID","DRONE","DRONE_BUILD_NUMBER","TEAMCITY_VERSION","TRAVIS","APPVEYOR","BITBUCKET_BUILD_NUMBER"];function ap(e){return ip.some(t=>!!X(t,e))}function cp(e){if(X("KUBERNETES_SERVICE_HOST",e)||yt(X("REMOTE_CONTAINERS",e))||yt(X("DEVCONTAINER",e)))return!0;try{if(rp("/.dockerenv")||op("/proc/1/environ","utf8").includes("container="))return!0}catch{}return!1}function bi(e){return["VSCODE_PID","VSCODE_IPC_HOOK","CURSOR_EXTENSION_HOST_ROLE","CURSOR_WORKSPACE_LABEL"].some(t=>!!X(t,e))}function up(e,t=process.platform){return bi(e)?t==="darwin"||t==="win32"?!0:["__CFBundleIdentifier","DISPLAY","WAYLAND_DISPLAY","SESSIONNAME"].some(n=>!!X(n,e)):!1}function lp(e){return e===void 0?!1:e.trim().toLowerCase().startsWith("bc-")}function fp(e){return e==="linux"}function X(e,t){if(t){let n=t[e];return n===void 0||n===""?void 0:n}return F(e)}function dp(e,t,n){return e.trim().toLowerCase()==="cursor"&&t.trim().toLowerCase()==="ubuntu"&&!!pp(X("CURSOR_VERSION",n))}function pp(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function Jr(e){if(lp(e.sessionId))return!0;let t=e.hostname??Ci(),n=e.osUser??ki(e.env);return dp(t,n,e.env)}function mp(e){return yt(X("CURSOR_AGENT",e.env))?!0:Jr(e)}function gp(e){return!!(process.stdin.isTTY||process.stdout.isTTY||(X("TERM",e)??X("TERM_PROGRAM",e))||(X("SSH_TTY",e)??X("SSH_CONNECTION",e))||(X("__CFBundleIdentifier",e)??X("XPC_SERVICE_NAME",e))||bi(e)||["DISPLAY","WAYLAND_DISPLAY","XDG_SESSION_TYPE","DBUS_SESSION_BUS_ADDRESS"].some(t=>!!X(t,e))||X("SESSIONNAME",e))}function $t(e={}){let t=e.env;if(X("GITHUB_ACTIONS",t))return"github_actions";if(yt(X("CLAUDE_CODE_REMOTE",t)))return"claude_remote";let n=e.platform??process.platform;if(!up(t,n)&&mp(e)&&(yt(X("CURSOR_AGENT",t))||fp(n)))return"cursor_cloud";if(X("CODESPACES",t)||X("CODESPACE_NAME",t))return"codespaces";if(X("GITLAB_CI",t))return"gitlab_ci";if(ap(t))return"managed";let r=X("CI",t);return r&&r!=="false"&&r!=="0"?"managed":cp(t)?"container":gp(t)?"interactive":"unknown"}async function xi(){return await te("systemd-detect-virt",[],1e3)}function ki(e=process.env,t=sp){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 Ii(){let e=process.platform==="darwin"?"Darwin":process.platform==="win32"?"Windows_NT":"Linux",t="";if(process.platform==="darwin")t=await te("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 te("lsb_release",["-sd"],1e3).then(s=>s.replace(/^"|"$/g,""))}t||(t=await te("uname",["-r"],1e3))}else t=await te("ver",[],1e3);let n=ki(),r=(process.env.SHELL??"").split(/[/\\]/).pop()??"",o="";try{o=await te("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 Nn(){return Ci()}var Sp="installation.json",Ep="cloud-bootstrap.lock",yp=6e4;function Ui(e,t,n){let r=`${e}:${t??""}`;return n?`${n}:${r}`:r}function Ue(e=Xr()){return qr(e,".ev-ai","agent-hook")}function Rp(e=Xr()){return qr(Ue(e),Sp)}function Di(e){return qr(vn(e),Ep)}function Fi(){return hp(8).toString("hex")}function Rt(e){return Ni("sha256").update(e).digest("hex").slice(0,16)}function $(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function $i(e){return/^[A-Za-z0-9._-]{8,64}$/.test(e)}function Cp(e=process.env){let t=$(e.EV_AI_HOOK_INSTALLATION_ID);if(t){if(!$i(t)){E(`WARN: ignoring EV_AI_HOOK_INSTALLATION_ID (expected 8\u201364 chars [A-Za-z0-9._-], got length ${t.length})`);return}return t}}function ji(e,t){return e&&$i(e)?e:(e&&E(`WARN: ignoring installation id override (expected 8\u201364 chars [A-Za-z0-9._-], got length ${e.length})`),Cp(t))}function Ap(e){return/^[0-9a-f]{16}$/.test(e)}function bp(e=process.env){if($(e.GITHUB_ACTIONS)){let t=$(e.GITHUB_REPOSITORY_ID)??$(e.GITHUB_REPOSITORY),n=$(e.GITHUB_ACTOR)??$(e.GITHUB_TRIGGERING_ACTOR)??$(e.GITHUB_USER);if(t&&n)return Rt(`github_actions|${t}|${n}`)}if($(e.CODESPACES)||$(e.CODESPACE_NAME)){let t=$(e.CODESPACE_NAME);if(t)return Rt(`codespaces|${t}`);let n=$(e.GITHUB_REPOSITORY_ID)??$(e.GITHUB_REPOSITORY),r=$(e.GITHUB_USER)??$(e.GITHUB_ACTOR);if(n&&r)return Rt(`codespaces|${n}|${r}`)}if($(e.GITLAB_CI)){let t=$(e.CI_PROJECT_ID)??$(e.CI_PROJECT_PATH),n=$(e.GITLAB_USER_LOGIN)??$(e.GITLAB_USER_EMAIL)??$(e.GITLAB_USER_NAME);if(t&&n)return Rt(`gitlab|${t}|${n}`)}return null}var xp="cursoragent@cursor.com";function kp(e){let t=$(e.CURSOR_USER_EMAIL);return!t||t.toLowerCase()===xp?null:t}function Ip(e,t){return $(e.CURSOR_PROJECT_DIR)??$(e.CLAUDE_PROJECT_DIR)??t}function Op(e){return Ut(e).replace(/\.git$/i,"").toLowerCase()}async function Tp(e){let t=await te("git",["config","--get","remote.origin.url"],2e3,{cwd:e});return t?Op(t):e}async function Pp(e){let t=$(await te("git",["config","--local","--get","user.email"],2e3,{cwd:e})||void 0);if(t&&!de(null,t))return t;let n=$(await te("git",["log","-1","--format=%ae"],2e3,{cwd:e})||void 0);return n&&!de(null,n)?n:null}function wp(e,t){let n=Ip(e,t);return n?Rt(`cursor_cloud|${n}|${kp(e)??""}`):null}async function Np(e,t){let n=$(e.CLAUDE_PROJECT_DIR)??t;if(!n)return null;let r=await Tp(n),o=await Pp(n);return Rt(`claude_remote|${r}|${o??""}`)}function Oi(e,t){let n=ji(e,t);if(n)return n;let r=bp(t);return r||Fi()}async function vp(e){let n=await te("git",["config","--get","remote.origin.url"],2e3,{cwd:e})||_p(e);return Ni("sha256").update(n).digest("hex").slice(0,16)}function Mp(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 Lp(e){try{let t=JSON.parse(e);if(typeof t.installation_id!="string"||t.installation_id.length===0)return;let n=Mp(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 at(e){if(vi(e))try{return Lp(Mi(e,"utf8"))}catch{}}function Zr(e){return at(e)}function Bi(e,t,n){let r=at(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{ke(e,`${JSON.stringify(o,null,2)}
|
|
16
|
+
`)}catch(s){let i=s instanceof Error?s.message:String(s);E(`WARN: operator identity cache write failed open: ${i}`)}}function Ki(e,t=Date.now()){if(!e)return!0;if(at(e)?.operator_identity_hash)return!1;let n=Di(e);try{if(vi(n)){let r=Number.NaN;try{r=Number(Mi(n,"utf8").trim())}catch{}let o=t-r;if(Number.isFinite(o)&&o>=0&&o<yp)return!1;try{Li(n)}catch{}}}catch{}try{return Yr(vn(n),{recursive:!0}),Hi(n,`${t}
|
|
17
|
+
`,{encoding:"utf8",flag:"wx"}),!0}catch(r){if(Vi(r))return!1;let o=r instanceof Error?r.message:String(r);return E(`WARN: cloud bootstrap claim failed open: ${o}`),!0}}function Gi(e){if(e)try{Li(Di(e))}catch{}}function Wi(e,t){let r=at(e)?.platform_agent_ids?.[t];return typeof r=="string"&&r.length>0?r:void 0}function zi(e,t,n){if(!n)return;let r=at(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{ke(e,`${JSON.stringify(o,null,2)}
|
|
18
|
+
`)}catch(s){let i=s instanceof Error?s.message:String(s);E(`WARN: platform_agent_id cache write failed open: ${i}`)}}function Vi(e){return e instanceof Error&&"code"in e&&e.code==="EEXIST"}function Hp(e,t){Yr(vn(e),{recursive:!0}),Hi(e,`${JSON.stringify(t,null,2)}
|
|
19
|
+
`,{encoding:"utf8",flag:"wx"})}function Ti(e,t){try{return Hp(e,t),t}catch(n){if(!Vi(n))throw n;return at(e)}}function Pi(e,t){Yr(vn(e),{recursive:!0}),ke(e,`${JSON.stringify(t,null,2)}
|
|
20
|
+
`)}function wi(e,t){return{installation_id:e,...t&&t===e?{pinned:!0}:{}}}async function Mn(e,t={}){let n=t.home??Xr(),r=t.env??process.env,o=await vp(e),s=Rp(n),i={sessionId:t.sessionId,hostname:$(r.HOSTNAME)??void 0,osUser:$(r.USER)??$(r.LOGNAME)??$(r.USERNAME)??void 0,env:r},a=$t(i),c=ji(t.overrideId,r),l=a==="cursor_cloud"&&Jr(i)?wp(r,e):a==="claude_remote"?await Np(r,e):null,u=at(s);if(u){let S=u;if(c&&c===u.installation_id&&u.pinned!==!0&&(S={...u,pinned:!0},Pi(s,S)),!!l&&l!==S.installation_id&&!c&&S.pinned!==!0&&Ap(S.installation_id)&&l){let b={installation_id:l,...S.platform_agent_ids?{platform_agent_ids:S.platform_agent_ids}:{}};return Pi(s,b),{installationId:l,storePath:s,repoKey:o}}return{installationId:S.installation_id,storePath:s,repoKey:o}}let d=c??l??Oi(void 0,r),f=Ti(s,wi(d,c));if(f)return{installationId:f.installation_id,storePath:s,repoKey:o};let p=c??l??Oi(void 0,r),g=Ti(s,wi(p===d?Fi():p,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 eo,readFileSync as Up}from"node:fs";import{dirname as Dp,isAbsolute as Fp,join as $p,relative as jp}from"node:path";function Ji(e){for(let t of yn){let n=$p(e,t);if(eo(n))return n}}async function Bp(e=process.cwd(),t){let n=t??await Le(e);return Ji(n)??Ji(e)}async function Kp(e,t){let n=t??await Le(Dp(e)),r=jp(n,e);if(r.startsWith("..")||Fp(r))return!1;let o=await Se("git",["ls-files","--error-unmatch",r],2e3,{cwd:n});return o.ok?!0:o.code===1?!1:(E(`WARN: git ls-files failed for manifest ${e} (code=${String(o.code)}); treating as tracked`),!0)}function Qr(e){let t=Up(e,"utf8");return me(t,{})}function Gp(){return{schema_version:Je,mcp_servers:[]}}function Wp(e,t,n,r){!t||!n||(e.capture_hook_input==="full"&&r.has("capture_hook_input")&&(E(`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")&&(E(`WARN: ignoring debug=true in git-tracked manifest ${t}; set debug on ~/.ev-ai/config.json`),delete e.debug))}async function Yi(e=process.cwd(),t={}){let{root:n,inGitRepo:r}=await zr(e),o=F("EV_AI_HOOK_MANIFEST"),s=o&&eo(o)?o:void 0,i=s?void 0:eo(Lr())?Lr():void 0,a=s?void 0:await Bp(e,n),c=i?Qr(i):void 0,l=a?Qr(a):void 0,u,d,f,p=new Set;if(s){u=Qr(s),d=s,f=s;for(let I of Object.keys(u))p.add(I)}else if(c&&l){u=ei(l,c),d=i,f=a;for(let I of Object.keys(l))I in c||p.add(I)}else if(c)u=c,d=i;else if(l){u=l,d=a,f=a;for(let I of Object.keys(l))p.add(I)}else u=Gp();delete u.installation_id;let g=f?await Kp(f,n):!1;Wp(u,f,g,p);let{installationId:S,storePath:A,repoKey:b}=await Mn(n,{sessionId:t.sessionId});return{manifestPath:d??A,manifest:u,installationId:S,installationStorePath:A,repoKey:b,collectorUrl:Ur(u),platformAgentId:u.platform_agent_id??"",gitRoot:n,inGitRepo:r}}function Xi(e){return{schema_version:Je,...e?{collector_url:e}:{},mcp_servers:[]}}var zp=["darwin-arm64","darwin-x64","linux-arm64","linux-x64","windows-x64","windows-arm64"];function Vp(e){return e==="windows-x64"||e==="windows-arm64"}function to(e=process.platform,t=process.arch){if(e==="darwin")return t==="arm64"?"darwin-arm64":t==="x64"?"darwin-x64":void 0;if(e==="linux")return t==="arm64"?"linux-arm64":t==="x64"?"linux-x64":void 0;if(e==="win32")return t==="x64"?"windows-x64":t==="arm64"?"windows-arm64":void 0}function qi(e=process.platform,t=process.arch){let n=to(e,t);if(!n)throw new Error(`Unsupported platform ${e}-${t}. Supported: ${zp.join(", ")}.`);return n}function Jp(e){return Vp(e)?`${xe}.exe`:xe}function no(e){return`compile-out/bin/${e}/${Jp(e)}`}function tm(e,t){let n=e.collectorUrl?.trim();if(!n)throw new Error(`${t} requires --url <https://hooks.ev-ai.ai/{orgToken}/hook>`);let r=Et(n);if(r)throw new Error(`collector URL rejected: ${r}`);return Ht(n)}function nm(e){let t=e.collectorUrl?.trim();if(!t)return;let n=Et(t);if(n)throw new Error(`collector URL rejected: ${n}`);return Ht(t)}function rm(e){return tm(e,"install")}function ra(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r==="--url"){let o=e[n+1];o&&!o.startsWith("--")&&(t.collectorUrl=o,n+=1);continue}if(r==="--collector-url")throw new Error("--collector-url was renamed to --url")}return t}function oa(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r==="--url"){let o=e[n+1];o&&!o.startsWith("--")&&(t.collectorUrl=o,n+=1);continue}if(r==="--collector-url")throw new Error("--collector-url was renamed to --url");if(r==="--update")throw new Error("--update was removed; use the `update` command instead of `install --update`");if(r==="--delivery"){let o=e[n+1];(o==="npx"||o==="binary"||o==="local")&&(t.delivery=o,n+=1);continue}if(r==="--force"){t.force=!0;continue}if(r==="--no-claude"){t.skipClaude=!0;continue}if(r==="--no-cursor"){t.skipCursor=!0;continue}if(r==="--no-codex"){t.skipCodex=!0;continue}}return t}function sa(e=process.execPath){return ia(e)?"binary":"npx"}function om(){return W(De(),".ev-ai","agent-hook")}function sm(e=De()){return W(e,".ev-ai","agent-hook",Dr)}function im(){let e=so(em(import.meta.url)),t=W(e,"hook.mjs");return Xe(t)?t:W(e,"..","dist","hook.mjs")}function ia(e=process.execPath){return xn(e)}function aa(e,t){let n=na(Zi(e),Zi(t));return!n.startsWith("..")&&!Zp(n)}function Un(e){return e.split(Qp).join("/")}function am(e){return`node "$(git rev-parse --show-toplevel)/${Un(e)}"`}function cm(e){return`"$(git rev-parse --show-toplevel)/${Un(e)}"`}function um(e){return W(e,Fr)}function ca(e,t){let n=um(e);oo(so(n),{recursive:!0}),ta(t,n,{force:!0});try{ea(n,493)}catch{}return n}function lm(e){let t=W(om(),"current");try{Hn(t,{recursive:!0,force:!0})}catch{}Xp(e,t,process.platform==="win32"?"junction":"dir")}function ua(e,t=Me,n=De()){let r=W(n,".ev-ai","agent-hook",t),o=W(r,xe);oo(r,{recursive:!0}),ta(e,o,{force:!0});try{ea(o,493)}catch{}return lm(r),W(n,".ev-ai","agent-hook",Dr)}function la(e){let t=to();if(!t)return;let n=[W(e,no(t)),W(e,"packages","agent-hook",no(t))];for(let r of n)if(Xe(r)&&aa(e,r))return r}function fm(e=De()){let t=sm(e);return Xe(t)?t:void 0}function dm(e,t=De()){let n=fm(t);return n||(ia()?ua(process.execPath,Me,t):la(e))}function pm(e,t=De()){let n=la(e);if(!n)throw new Error(`update requires a locally compiled binary \u2014 run this package\u2019s build:hook-binary script first.
|
|
21
|
+
To install a released binary instead: curl -fsSL https://cdn.ev-ai.ai/agent-hook/install.sh | sh`);let r=ua(n,Me,t),o=ca(e,n);return{sourcePath:n,projectPath:o,globalPath:r}}function Qi(e){let t=[W(e,"packages","agent-hook","dist","hook.mjs"),W(e,ri)],n=im();Xe(n)&&aa(e,n)&&t.unshift(n);for(let r of t){if(!Xe(r))continue;let o=Un(na(e,r));return{command:am(o),hookPath:o,strategy:"dev_mjs"}}}function mm(e){return e==="SessionStart"||e==="sessionStart"}function gm(e){return e.replace(/\s+--prefer-offline\b/g,"")}function Ln(e,t){return mm(e)?gm(t):t}function hm(e=In){return`npx -y --prefer-offline ${e}`}function _m(e,t=De(),n=sa()){if(n==="npx")return{command:hm(),hookPath:In,strategy:"npx"};if(n==="local"){let s=Qi(e);if(s)return s;throw new Error("local delivery requires packages/agent-hook/dist/hook.mjs (or node_modules/@ev-ai/agent-hook/dist/hook.mjs) under the git root \u2014 run yarn workspace @ev-ai/agent-hook build first")}let r=dm(e,t);if(r){ca(e,r);let s=Un(Fr);return{command:cm(s),hookPath:s,strategy:"project_binary"}}let o=Qi(e);if(o)return o;throw new Error(`ev-ai-agent-hook binary not found. Install from CDN:
|
|
22
|
+
curl -fsSL ${oi}/install.sh | sh
|
|
22
23
|
Or use npx delivery:
|
|
23
|
-
npx ${
|
|
24
|
-
`,"utf8")}function ue(e){if(_e(e))try{return JSON.parse(gd(e,"utf8"))}catch(t){throw t instanceof SyntaxError?new Error(`Invalid JSON in ${e} \u2014 fix or remove the file`,{cause:t}):t}}function Hd(e,t){let n=Ks(t.collectorUrl),r={...e,schema_version:e?.schema_version??n.schema_version};return t.collectorUrl!==void 0?r.collector_url=t.collectorUrl:r.collector_url=e?.collector_url??n.collector_url,delete r.repo_ingest_token,delete r.installation_id,r.mcp_servers??=n.mcp_servers,r}function Fd(e){return(e.schema_version??me)===me&&e.collector_url===void 0&&(e.mcp_servers?.length??0)===0&&e.platform_agent_id===void 0&&e.capture_hook_input===void 0&&e.debug===void 0&&e.repo_ingest_token===void 0}function oi(e,t){let n=x(e,Tt),r=ue(n),o=Hd(r,t);return t.collectorUrl!==void 0||_e(n)||!Fd(o)?(he(n,o),{manifestPath:n,wrote:!0}):{manifestPath:void 0,wrote:!1}}function ar(e){if(e===null||typeof e!="object")return!1;let t=e,n=String(t.CLAUDE_CODE_ENABLE_TELEMETRY??"").toLowerCase();return n==="1"||n==="true"?!0:Object.keys(t).some(r=>r.startsWith("OTEL_"))}function jd(e){if(ar(process.env))return!0;let t=ce();return[...Vn(),x(t,".claude","settings.json"),x(t,".claude","remote-settings.json"),x(e,".claude","settings.json"),x(e,".claude","settings.local.json")].some(r=>{try{let o=ue(r);return o?ar(o.env):!1}catch{return!1}})}function $d(e){try{let t=ue(x(e,".claude","settings.json"));return t?ar(t.env):!1}catch{return!1}}function si(e){return Array.isArray(e)?e:[]}function Wt(e){let t=[],n=r=>!!r&&typeof r=="object"&&ri(r.command);for(let r of si(e)){if(!r||typeof r!="object"){t.push(r);continue}let o=Array.isArray(r.hooks)?r.hooks:[],s=o.filter(i=>!n(i));if(!(s.length===0&&o.some(n))){if(s.length!==o.length){t.push({...r,hooks:s});continue}t.push(r)}}return t}function ii(e,t){return[...Wt(e),...t]}function dr(e){return Array.isArray(e)?e.filter(t=>!t||typeof t!="object"?!0:!ri(t.command)):[]}function Kd(e,t){return[...dr(e),{command:t}]}function Bd(e){return typeof e=="string"?[e]:e}function Gd(e){let t=(n="")=>({hooks:Bd(e).map(r=>({type:"command",command:Gt(n,r)}))});return{SessionStart:[t("SessionStart")],UserPromptExpansion:[t()],UserPromptSubmit:[t()],PreToolUse:[t()],PostToolUse:[t()],PostToolUseFailure:[t()],PermissionDenied:[t()],Stop:[t()],StopFailure:[t()],SessionEnd:[t()],SubagentStart:[t()],SubagentStop:[t()]}}function zd(e){let t=typeof e=="string"?{command:e}:e,n=(r="")=>({hooks:[{type:"command",command:Gt(r,t.command),...t.commandWindows===void 0?{}:{commandWindows:Gt(r,t.commandWindows)},statusMessage:ts}]});return{SessionStart:[n("SessionStart")],UserPromptSubmit:[n()],PreToolUse:[n()],PostToolUse:[n()],Stop:[n()]}}var Vd=["sessionStart","beforeSubmitPrompt","preToolUse","postToolUse","postToolUseFailure","beforeShellExecution","beforeReadFile","beforeMCPExecution","subagentStart","subagentStop","stop"],Wd=["afterShellExecution","afterFileEdit"];function Jd(e,t=Wd){let n={...e};for(let r of t){if(!(r in n))continue;let o=dr(n[r]);o.length===0?delete n[r]:n[r]=o}return n}function Yd(e,t,n={}){let r=x(e,".claude/settings.json"),o=lr(t,"claude"),s=ue(r)??{};if(jd(e)&&!n.force){if(s.hooks&&typeof s.hooks=="object"){let u={...s.hooks};for(let f of Object.keys(u))u[f]=Wt(u[f]),si(u[f]).length===0&&delete u[f];Object.keys(u).length===0?delete s.hooks:s.hooks=u,he(r,s)}return!1}let a=s.hooks&&typeof s.hooks=="object"?s.hooks:{},c=Gd(o),l={...a};for(let[u,f]of Object.entries(c))l[u]=ii(a[u],f);return s.hooks=l,he(r,s),!0}function Xd(e,t){let n=x(e,".cursor/hooks.json"),r=lr(t,"cursor"),o=ue(n)??{},s=o.hooks&&typeof o.hooks=="object"?o.hooks:{},i=Jd({...s});for(let a of Vd)i[a]=Kd(i[a],Gt(a,r));he(n,{...o,version:typeof o.version=="number"?o.version:1,hooks:i})}function Zd(e,t){let n=x(e,".codex/hooks.json"),r=lr(t,"codex"),o=ue(n)??{},s=o.hooks&&typeof o.hooks=="object"?o.hooks:{},i=zd(r),a={...s};for(let[c,l]of Object.entries(i))a[c]=ii(s[c],l);he(n,{...o,hooks:a})}function qd(e){let t=x(e,".claude/settings.json"),n=ue(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1;for(let s of Object.keys(r)){let i=r[s],a=Wt(i);JSON.stringify(i)!==JSON.stringify(a)&&(o=!0),a.length===0?delete r[s]:r[s]=a}o&&(Object.keys(r).length===0?delete n.hooks:n.hooks=r,he(t,n),p(`Removed ev-ai hooks from ${t}`))}function Qd(e){let t=x(e,".cursor/hooks.json"),n=ue(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1,s=0;for(let i of Object.keys(r)){let a=r[i],c=dr(a);JSON.stringify(a)!==JSON.stringify(c)&&(o=!0),c.length===0?delete r[i]:(r[i]=c,s+=c.length)}if(o){if(s===0&&Object.keys(r).length===0&&Object.keys(n).filter(a=>a!=="hooks"&&a!=="version").length===0){zt(t,{force:!0}),p(`Removed ${t}`);return}he(t,{...n,hooks:r}),p(`Removed ev-ai hooks from ${t}`)}}function ef(e){let t=x(e,".codex/hooks.json"),n=ue(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1,s=0;for(let i of Object.keys(r)){let a=r[i],c=Wt(a);JSON.stringify(a)!==JSON.stringify(c)&&(o=!0),c.length===0?delete r[i]:(r[i]=c,s+=c.length)}if(o){if(s===0&&Object.keys(r).length===0&&Object.keys(n).filter(a=>a!=="hooks").length===0){zt(t,{force:!0}),p(`Removed ${t}`);return}he(t,{...n,hooks:r}),p(`Removed ev-ai hooks from ${t}`)}}function fr(e=process.platform,t=process.arch,n={}){if(e==="win32")throw new Error("Windows install is not supported yet. Use macOS/Linux, or wait for phase-2 native commands.");(n.requireBinaryArch??!0)&&Bs(e,t)}async function ai(e={}){let t=Ad(e);e.collectorUrl=t;let n=e.skipClaude===!0,r=e.skipCursor===!0,o=e.skipCodex===!0;if(n&&r&&o)throw new Error("at least one runner must be wired; refuse --no-claude --no-cursor --no-codex together");let s=e.delivery??Zs();fr(process.platform,process.arch,{requireBinaryArch:s==="binary"});let i=e.cwd??process.cwd(),a=await se(i),{command:c,hookPath:l,strategy:u}=Dd(a,ce(),s),{installationId:f,storePath:m}=await Bt(a,{overrideId:e.installationId}),{manifestPath:d,wrote:_}=oi(a,e),h=[];return n?p("Skipped Claude hook \u2014 --no-claude"):Yd(a,c,{force:e.force})?(h.push("Claude"),e.force&&$d(a)&&p("Forced Claude hook despite project native OTEL \u2014 expect duplicate session/tool events")):p("Skipped Claude hook \u2014 native OTEL telemetry already enabled (avoids duplicate events); pass --force to wire anyway"),r?p("Skipped Cursor hook \u2014 --no-cursor"):(Xd(a,c),h.push("Cursor")),o?p("Skipped Codex hook \u2014 --no-codex"):(Zd(a,c),h.push("Codex")),p(`Installed hook (${u}) at ${l}`),p(`Installation identity ${f} at ${m}`),_&&d?p(`Shared manifest written to ${d}`):p("Using package default collector config (no shared manifest file needed)"),p(h.length>0?`Wired ${h.join(", ")} hooks in ${a} (commands include --runner)`:`No runner hooks wired in ${a} (Claude skipped by OTEL; Cursor/Codex excluded via flags)`),u==="npx"?p("Hook commands use npx and may be committed; teammates need Node on PATH only (no install step, no env vars when collector_url is in the shared manifest)."):u==="project_binary"?p("Hook commands are git-root-relative and may be committed; each collaborator runs install once to populate .ev-ai/agent-hook/ (gitignored)."):u==="dev_mjs"&&p("Hook commands use node + monorepo packages/agent-hook/dist/hook.mjs (local delivery; rebuild with yarn workspace @ev-ai/agent-hook build)."),_&&d&&e.collectorUrl&&p("Shared manifest includes collector_url \u2014 commit it with hook configs so teammates post without env vars."),{gitRoot:a,hookPath:l,manifestPath:d,installationStorePath:m,strategy:u}}async function ci(e=process.cwd()){fr(process.platform,process.arch,{requireBinaryArch:!0});let t=await se(e),{projectPath:n,globalPath:r}=Md(t);p(`Refreshed ${r}`),p(`Refreshed ${n}`),p("Hook configs and shared manifest left unchanged")}async function ui(e={}){let t=Cd(e);e.collectorUrl=t,fr(process.platform,process.arch,{requireBinaryArch:!1});let n=e.cwd??process.cwd(),r=await se(n),{manifestPath:o,wrote:s}=oi(r,e);if(t!==void 0&&(!o||!s))throw new Error("configure failed to write shared collector manifest");return s&&o?p(`Wrote ${o}`):t===void 0&&p("No --url given and no shared manifest yet \u2014 pass --url <\u2026/{orgToken}/hook> to write collector destination."),p("Manifest only \u2014 enable ev-ai marketplace plugins. Do not also run file-wiring install for the same events."),{gitRoot:r,manifestPath:o}}function li(e){for(let t of[()=>qd(e),()=>Qd(e),()=>ef(e)])try{t()}catch(n){let r=n instanceof Error?n.message:String(n);p(`WARN: strip skipped a hook file: ${r}`)}}async function di(e=process.cwd()){let t=await se(e);return li(t),p("Stripped ev-ai file-wired hooks; shared collector manifest left in place."),p("Next: enable ev-ai marketplace plugins, then restart runners."),{gitRoot:t}}async function fi(e=process.cwd()){let t=await se(e);li(t);for(let n of wt){let r=x(t,n);if(_e(r))try{zt(r,{force:!0}),p(`Removed ${r}`)}catch(o){let s=o instanceof Error?o.message:String(o);p(`WARN: uninstall could not remove ${r}: ${s}`)}}}import{existsSync as Vm,mkdirSync as Wm,readdirSync as Jm,readFileSync as Ym,unlinkSync as ka,writeFileSync as Xm}from"node:fs";import{homedir as Oa}from"node:os";import{join as Mr}from"node:path";import{open as pi,mkdir as tf,readFile as nf,readdir as rf,rename as of,stat as sf,rmdir as af,unlink as cf,utimes as uf}from"node:fs/promises";var Jt=new WeakMap;function gi(e){if(e&&typeof e=="object"&&"code"in e)return e}function pr(e){return gi(e)?.code==="ENOENT"}function _i(e){return gi(e)?.code==="EEXIST"}async function hi(e,t){try{return await e.readdir(t)}catch(n){if(pr(n))return[];throw n}}function Si(){return{async open(e,t){let n=await pi(e,t),r={path:e};return Jt.set(r,n),r},async write(e,t){let n=mi(e),r=typeof t=="string"?Buffer.from(t,"utf8"):t;await n.write(r)},async fsync(e){await mi(e).sync()},async close(e){let t=Jt.get(e);Jt.delete(e),t&&await t.close()},rename:of,async readdir(e){return rf(e)},readFile:nf,async stat(e){let t=await sf(e);return{mtimeMs:t.mtimeMs,size:t.size,isDirectory:()=>t.isDirectory()}},async mkdir(e,t){await tf(e,t)},unlink:cf,rmdir:af,utimes:uf,async fsyncDir(e){if(process.platform==="win32")return;let t=await pi(e,"r");try{await t.sync()}finally{await t.close()}}}}function mi(e){let t=Jt.get(e);if(!t)throw new Error("closed");return t}import{existsSync as yf}from"node:fs";import{existsSync as lf}from"node:fs";import{homedir as yi}from"node:os";import{join as df}from"node:path";function Ri(e){return e.settings.filter(t=>t.toLowerCase().endsWith(".json"))}var ff={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/sandbox.json",".cursor/permissions.json"],mcpJson:[".cursor/mcp.json"]},homeOnly:{skillRoots:[".cursor/skills-cursor"],memory:[[".cursor/AGENTS.md"]],settings:[".cursor/cli-config.json"],plugins:"cursor",managed:"cursor"},projectOnly:{skillRoots:[".agents/skills"],settings:[".cursor/cli.json"]}},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 Ei(e,t){if(!(!e&&!t))return[...e??[],...t??[]]}function pf(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:Ei(n.mcpJson,t.mcpJson),mcpToml:Ei(n.mcpToml,t.mcpToml),plugins:t.plugins??n.plugins,managed:t.managed??n.managed}}function Ci(e){return Object.fromEntries(Object.entries(ff).map(([t,n])=>[t,pf(n,n[e])]))}var $e=Ci("homeOnly"),Ee=Ci("projectOnly");function mf(e){return[...e.skillRoots,...e.dirs.map(t=>t.dir),...e.memory.flat(),...e.settings,...e.mcpJson??[],...e.mcpToml??[]]}function gf(e,t){return mf(e).some(n=>lf(df(t,n)))}function Ai(e,t){for(let n of e)if(gf(n,t))return!0;return!1}function Se(e){return[...new Set(e)]}function ye(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:Se(t),subagents:Se(n),commands:Se(r),rules:Se(o),memory:Se(s),settings:Se(i),mcp:Se(a)}}function _f(e,t=yi(),n=process.platform){let r=[];for(let o of e)o.managed&&r.push(...Ft(o.managed,n,t));return Se(r)}var Re=ye(Object.values($e));function Ii(e=yi(),t=process.platform){return _f(Object.values($e),e,t)}import{existsSync as hf}from"node:fs";import{resolve as mr}from"node:path";function V(e){return mr(e).replaceAll("\\","/").replace(/\/$/,"")}function Te(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 Yt(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 Sf=/^(?!\.)[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;function it(e){let t=e.replaceAll("\\","/").replace(/^\.\//,"");return!t||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.split("/").includes("..")||!Sf.test(t)?null:t}function Ke(e,t){let n=new Set,r=[];for(let o of[e,t]){if(!o)continue;let s=V(o);n.has(s)||(n.add(s),r.push(s))}return r}function Ef(e,t){let n=`${e}/`;return t===e||t.startsWith(n)}function ee(e,t,n,r=hf){for(let o of e)for(let s of t){let i=V(mr(o,s)),a=mr(o,s,n).replaceAll("\\","/");if(Ef(i,a)&&r(a))return a}return null}var Oi=/(?:^|\/|[\s"'=(])(?:\.cursor\/|\.claude\/|\.agents\/)skills(?:-cursor)?\/([^/]+)\/SKILL\.md/i,bi=/(?:^|\/|[\s"'=(])\.codex\/commands\/([^/]+)\.md\b/i,Rf=/(?:^|\s)\/([a-z][a-z0-9-]{1,63}(?:\/[a-z][a-z0-9-]{1,63}){0,5})\b/gi,ki=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"]),Cf=/^[a-z][a-z0-9-]{1,63}$/,Af=[".cursor/skills",".claude/skills",".agents/skills"],If=[".cursor/skills",".cursor/skills-cursor",".claude/skills",".agents/skills"],kf=Te(Af,ye(Object.values(Ee)).skills),Of=Te(If,ye(Object.values($e)).skills),bf=new Set(["read","read_file","view"]),xf=new Set(["bash","shell","zsh"]);function gr(e){let t=e.replace(/\\/g,"/");return Oi.exec(t)?.[1]??null}function Pf(e){let t=e.replace(/\\/g,"/"),r=bi.exec(t)?.[1];return r?r.toLowerCase():null}function Tf(e){return gr(e)??Pf(e)}function wf(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 Xt(e){return typeof e=="string"?Xt(z(e,null)):!e||typeof e!="object"?null:wf(e)}function xi(e){if(typeof e=="string")return xi(z(e,null));if(!e||typeof e!="object")return null;let t=e.command;return typeof t=="string"&&t.length>0?t:null}function _r(e){let t=xi(e.tool_input);if(t)return t;let n=xe(e.command);return n.length>0?n:null}function Nf(e){let t=e.replace(/\\/g,"/"),n=Oi.exec(t);if(n?.[1])return n[1];let o=bi.exec(t)?.[1];return o?o.toLowerCase():null}function Mf(e){return typeof e.tool_name=="string"?e.tool_name:typeof e.tool=="string"?e.tool:""}function hr(e){let t=Xt(e.tool_input)??xe(e.file_path);return t.length>0?t:null}function at(e,t,n){let r=Mf(e).toLowerCase();if(bf.has(r)){let o=hr(e);return o?t(o):null}if(xf.has(r)){let o=_r(e);return o?n(o):null}return null}function Pi(e){return at(e,Tf,Nf)}function vf(e){let t=new Set,n=[];for(let r of e.matchAll(Rf)){let o=r[1]?.toLowerCase();!o||t.has(o)||Lf(o)||(t.add(o),n.push(o))}return n}function Lf(e){let t=e.split("/")[0];return ki.has(e)||t!==void 0&&ki.has(t)}function Ti(e){let t=e.skillId.toLowerCase();if(!Cf.test(t))return null;let n=e.exists??yf,r=`${t}/SKILL.md`,o=ee(Ke(e.launchCwd,e.gitRoot),kf,r,n);return o!==null?o:e.home?ee([V(e.home)],Of,r,n):null}function Uf(e){return xe(e.prompt)}function wi(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=Uf(e);return n?vf(n):[]}var Ir=Qe(ze(),1);import{existsSync as _m}from"node:fs";var Ne={claude:".claude",cursor:".cursor",codex:".codex",opencode:".opencode"};function ut(e){let n=e.replace(/^\/+|\/+$/g,"").toLowerCase().split("/").filter(Boolean);return n.length<2?"":n.join("/")}function gm(e){if(!e)return"";let t=nt(e).replace(/\.git$/i,""),n=t.match(/^git@[^:]+:(.+)$/);if(n?.[1])return ut(n[1]);let r=t.match(/^ssh:\/\/[^/]+\/(.+)$/i);if(r?.[1])return ut(r[1]);t=t.replace(/^https:\/\//i,""),t=t.replace(/^http:\/\//i,""),t=t.replace(/^ssh:\/\//i,"");let o=t.match(/^[^/]+\/(.+)$/);return o?.[1]?ut(o[1]):ut(t)}async function nn(e=process.cwd()){let t=await Y("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([Y("git",["remote","get-url","origin"],2e3,{cwd:e}),Y("git",["branch","--show-current"],2e3,{cwd:e}),Y("git",["rev-parse","HEAD"],2e3,{cwd:e}),Y("git",["status","--porcelain"],2e3,{cwd:e})]);return{remote:n.ok?nt(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 ea(e,t,n,r=process.cwd(),o,s,i){if(t)return t;let a=Ne[n];if(!a)return"";let c=Ps(n,e.scope_path,i);if(s){let _=Ds(s,c);if(_)return _}let l=o??await nn(r),u=l?.remote?gm(l.remote):"";if(u||(u=ut(process.env.GITHUB_REPOSITORY??"")),!u)return"";let f=e.scope_path??"",m=f?`${f}/`:"",d=`${u}:${m}${a}`;return s&&Hs(s,c,d),d}var hm=[".cursor/rules",".claude/rules",".codex/rules"],Sm=ye(Object.values(Ee)).rules;function Em(e){return Te(Yt(e?Ne[e]:void 0,hm),Sm)}var ym=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/rules\/[^'"\s]+?\.(?:mdc|md|rules))\b/i;function ta(e){let t=it(e.relativePath);if(!t)return null;let n=e.exists??_m,r=Ke(e.launchCwd,e.gitRoot),o=Em(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([V(e.home)],o,t,n):null}function Rm(e){let t=e.replace(/\\/g,"/"),r=ym.exec(t)?.[1];return r?(0,Ir.nativeKeyForRulePath)(r):null}function na(e){return at(e,Ir.nativeKeyForRulePath,Rm)}function ra(e){return e.replace(/\.(mdc|md|rules)$/i,"")}function oa(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=it(i);!a||n.has(a)||(n.add(a),r.push(a))}return r}var kr=Qe(ze(),1);import{existsSync as Cm}from"node:fs";var Am=[".cursor/commands",".claude/commands",".codex/prompts"],Im=ye(Object.values(Ee)).commands;function km(e){return Te(Yt(e?Ne[e]:void 0,Am),Im)}var Om=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/(?:commands|prompts)\/[^'"\s]+?\.(?:md|mdc))\b/i;function sa(e){let t=it(e.commandId);if(!t)return null;let n=e.exists??Cm,r=`${t}.md`,o=km(e.runnerPlatform),s=ee(Ke(e.launchCwd,e.gitRoot),o,r,n);return s!==null?s:e.home?ee([V(e.home)],o,r,n):null}function bm(e){let t=e.replace(/\\/g,"/"),r=Om.exec(t)?.[1];return r?(0,kr.nativeKeyForCommandPath)(r):null}function ia(e){return at(e,kr.nativeKeyForCommandPath,bm)}import{existsSync as ca}from"node:fs";import{homedir as ua}from"node:os";import{join as lt,resolve as Or,sep as aa}from"node:path";function br(e){return[...new Set([e,e.replaceAll(/[^A-Za-z0-9_-]/g,"_"),e.replaceAll(/[^A-Za-z0-9_-]+/g,"_")])]}function xr(e,t){let n=t.toLowerCase();return br(e).some(r=>r.toLowerCase()===n)}function rn(e,t,n){if(!ca(e))return;let r=D(e,{});for(let[o,s]of Object.entries(r.mcpServers??{}))n.set(o,{declared:{name:o,...t},config:s})}function xm(e,t,n){if(!ca(e))return;let r=D(e,{}),o=Or(t),s=null;for(let a of Object.keys(r.projects??{})){let c=Or(a);(o===c||o.startsWith(c.endsWith(aa)?c:c+aa))&&(s===null||c.length>Or(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 la(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"?(rn(lt(r,".claude.json"),{source:"claude_json_user"},o),xm(lt(r,".claude.json"),t,o)):n==="cursor"&&rn(lt(r,".cursor/mcp.json"),{source:"cursor_mcp_user"},o),rn(lt(t,".mcp.json"),{source:"mcp_json"},o),rn(lt(t,".cursor/mcp.json"),{source:"cursor_mcp"},o),o}async function Pr(e,t=process.cwd(),n="claude",r=ua()){return[...la(e,t,n,r).values()].map(o=>o.declared)}function da(e,t,n=process.cwd(),r="claude",o=ua()){let s=la(t,n,r,o),i=s.get(e);if(i!==void 0)return i.config??null;for(let[a,c]of s)if(xr(a,e))return c.config??null;return null}function Tr(e){let t=Vo(e);if(t.problem){p(`WARN: ignoring --url/--token collector override: ${t.problem}`);return}return t.url}function fa(e,t){if(R(e,"conversation_id"))return!0;if(t==="")return!1;let n=t[0];return n?.toLowerCase()===n}function Pm(){return!!(A("CURSOR_VERSION")??A("CURSOR_PROJECT_DIR"))}function pa(e,t,n){return e!=="claude"&&e!=="codex"?!1:fa(t,n)?!0:Pm()}var Tm=new Set(["sessionstart","sessionend","stop","stopfailure","pretooluse","posttooluse","posttoolusefailure","permissiondenied","subagentstart","subagentstop","userpromptexpansion","userpromptsubmit"]);function dt(e,t,n,r){return fa(e,t)?"cursor":Nt(r)?r:Nt(n)?n:R(e,"turn_id")?"codex":R(e,"session_id")||Tm.has(t.toLowerCase())?"claude":"unknown"}function on(e,t){let n=e.toLowerCase();return n==="sessionend"||n==="stopfailure"||n==="subagentstop"?!0:n==="stop"&&t==="codex"}function wm(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 ma(e){let t=e.toLowerCase();return t==="userpromptsubmit"||t==="beforesubmitprompt"}function ga(e,t){return e.toLowerCase()==="userpromptsubmit"&&t==="claude"}function _a(e){let t=e.toLowerCase();return t==="posttooluse"?!0:t==="posttoolusefailure"||t==="permissiondenied"?!1:null}function ft(e){return R(e,"session_id")||R(e,"conversation_id")}function wr(e){return R(e,"prompt.id")||R(e,"prompt_id")||R(e,"generation_id")||R(e,"turn_id")}function Nr(e){return R(e,"hook_event_name")||R(e,"event")}function ha(e,t,n){let r=ft(e),o=wr(e),s=Nr(e),i=R(e,"source"),a=dt(e,s,t,n);return{sessionId:r,turnId:o,runnerEvent:s,hookSource:i,runnerPlatform:a}}var Nm=["session_start","session_end","tool_invoked","skill_invoked"];function Mm(e){return Nm.includes(e)}function Sa(e,t){return e&&Mm(e)?e:wm(t.toLowerCase())}var vm={beforeshellexecution:"Shell",aftershellexecution:"Shell",beforereadfile:"Read",afterfileedit:"Write"};function sn(e){return/^mcp__/i.test(e)||/^MCP:/i.test(e)}function Ea(e,t=""){let n=R(e,"tool_name")||R(e,"tool")||null,r=t.toLowerCase();n?r==="beforemcpexecution"&&!sn(n)&&(n=`MCP:${n}`):n=vm[r]??null;let o=e.tool_input,i=(o&&typeof o=="object"?xe(o.skill)||xe(o.skill_name):"")||R(e,"skill_name")||null,a=n&&e.tool_name!==n&&e.tool!==n?{...e,tool_name:n}:e;i??=Pi(a);let c=na(a),l=ia(a);return{toolName:n,skillName:i,ruleName:c,commandName:l}}var Lm=/^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/;function ya(e){for(let t of["subagent_type","agent_type"]){let n=R(e,t);if(n&&Lm.test(n))return n}return null}function Ra(e){let t=ie(e,"duration_ms");if(typeof t=="number")return t;let n=ie(e,"duration");return typeof n=="number"?n:null}var Um="error",Dm="interrupted",Hm="permission_denied",Fm=/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;function pt(e){return Fm.test(e)?e:null}function jm(e){for(let t of["failure_type","error_type"]){let n=pt(R(e,t));if(n)return n}return null}function Ca(e,t){return ie(e,"is_interrupt")===!0?Dm:t.toLowerCase()==="permissiondenied"?Hm:jm(e)??Um}function Aa(e,t){let n=null;for(let r of e)r&&t(r)&&(n===null||r.length>n.length)&&(n=r);return n}function $m(e,t){return Aa(t,n=>e===n||e.startsWith(`${n}_`)||e.startsWith(`${n}-`))}function Km(e,t){return Aa(t,n=>xr(n,e))}function Bm(e,t){let n=null,r=0;for(let s of t)if(s)for(let i of br(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:Km(o[1],t)??o[1],mcpTool:o[2]}}function Gm(e,t){if(/^mcp__/i.test(e))return Bm(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:$m(n,t),mcpTool:n}}return{mcpServer:null,mcpTool:null}}function zm(e,t){let n=`${t}__`;return e.length>n.length&&e.toLowerCase().startsWith(n.toLowerCase())?e.slice(n.length):e}function Ia(e,t=[],n=""){let r=e?Gm(e,t):{mcpServer:null,mcpTool:null},o=pt(n.trim());if(!o)return r;let s=r.mcpTool;return!s&&e&&!sn(e)&&(s=e),s&&(s=zm(s,o)),{mcpServer:o,mcpTool:s}}var ba=3e4,Zm="claims",qm=!0,Qm=100,eg=new Set(["sessionstart","sessionend","stopfailure"]),tg=["tool_name","tool","command","file_path","url"];function ng(e=Oa()){return Mr(ae(e),Zm)}function xa(e,t){try{let n=Ym(e,"utf8").split(`
|
|
25
|
-
`,1)[0]??"";return t-Number(n.trim())}catch{return Number.NaN}}function
|
|
26
|
-
`,{encoding:"utf8",flag:"wx"})}catch(o){if(
|
|
27
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);
|
|
28
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);
|
|
24
|
+
npx ${In} install`)}function fa(e){return typeof e!="string"?!1:e.includes("@ev-ai/agent-hook")||e.includes("agent-hook/dist/hook")||e.includes(".ev-ai/agent-hook")||e.includes(xe)||/(?:^|[\s/"'])ev-ai-agent-hook(?:$|[\s"'])/.test(e)}function io(e,t){return`${e.replace(/\s+--runner(?:=|\s+)\S+/g,"").trimEnd()} --runner ${t}`}function qe(e,t){oo(so(e),{recursive:!0}),qp(e,`${JSON.stringify(t,null,2)}
|
|
25
|
+
`,"utf8")}function Fe(e){if(Xe(e))try{return JSON.parse(Yp(e,"utf8"))}catch(t){throw t instanceof SyntaxError?new Error(`Invalid JSON in ${e} \u2014 fix or remove the file`,{cause:t}):t}}function Sm(e,t){let n=Xi(t.collectorUrl),r={...e,schema_version:e?.schema_version??n.schema_version};return t.collectorUrl!==void 0?r.collector_url=t.collectorUrl:r.collector_url=e?.collector_url??n.collector_url,delete r.repo_ingest_token,delete r.installation_id,r.mcp_servers??=n.mcp_servers,r}function Em(e){return(e.schema_version??Je)===Je&&e.collector_url===void 0&&(e.mcp_servers?.length??0)===0&&e.platform_agent_id===void 0&&e.capture_hook_input===void 0&&e.debug===void 0&&e.repo_ingest_token===void 0}function da(e,t){let n=W(e,En),r=Fe(n),o=Sm(r,t);return t.collectorUrl!==void 0||Xe(n)||!Em(o)?(qe(n,o),{manifestPath:n,wrote:!0}):{manifestPath:void 0,wrote:!1}}function ro(e){if(e===null||typeof e!="object")return!1;let t=e,n=String(t.CLAUDE_CODE_ENABLE_TELEMETRY??"").toLowerCase();return n==="1"||n==="true"?!0:Object.keys(t).some(r=>r.startsWith("OTEL_"))}function ym(e){if(ro(process.env))return!0;let t=De();return[...Br(),W(t,".claude","settings.json"),W(t,".claude","remote-settings.json"),W(e,".claude","settings.json"),W(e,".claude","settings.local.json")].some(r=>{try{let o=Fe(r);return o?ro(o.env):!1}catch{return!1}})}function Rm(e){try{let t=Fe(W(e,".claude","settings.json"));return t?ro(t.env):!1}catch{return!1}}function pa(e){return Array.isArray(e)?e:[]}function Dn(e){let t=[],n=r=>!!r&&typeof r=="object"&&fa(r.command);for(let r of pa(e)){if(!r||typeof r!="object"){t.push(r);continue}let o=Array.isArray(r.hooks)?r.hooks:[],s=o.filter(i=>!n(i));if(!(s.length===0&&o.some(n))){if(s.length!==o.length){t.push({...r,hooks:s});continue}t.push(r)}}return t}function ma(e,t){return[...Dn(e),...t]}function ao(e){return Array.isArray(e)?e.filter(t=>!t||typeof t!="object"?!0:!fa(t.command)):[]}function Cm(e,t){return[...ao(e),{command:t}]}function Am(e){return typeof e=="string"?[e]:e}function bm(e){let t=(n="")=>({hooks:Am(e).map(r=>({type:"command",command:Ln(n,r)}))});return{SessionStart:[t("SessionStart")],UserPromptExpansion:[t()],UserPromptSubmit:[t()],PreToolUse:[t()],PostToolUse:[t()],PostToolUseFailure:[t()],PermissionDenied:[t()],Stop:[t()],StopFailure:[t()],SessionEnd:[t()],SubagentStart:[t()],SubagentStop:[t()]}}function xm(e){let t=typeof e=="string"?{command:e}:e,n=(r="")=>({hooks:[{type:"command",command:Ln(r,t.command),...t.commandWindows===void 0?{}:{commandWindows:Ln(r,t.commandWindows)},statusMessage:li}]});return{SessionStart:[n("SessionStart")],UserPromptSubmit:[n()],PreToolUse:[n()],PostToolUse:[n()],Stop:[n()],SubagentStart:[n()],SubagentStop:[n()]}}var km=["sessionStart","beforeSubmitPrompt","preToolUse","postToolUse","postToolUseFailure","beforeShellExecution","beforeReadFile","beforeMCPExecution","subagentStart","subagentStop","stop"],Im=["afterShellExecution","afterFileEdit"];function Om(e,t=Im){let n={...e};for(let r of t){if(!(r in n))continue;let o=ao(n[r]);o.length===0?delete n[r]:n[r]=o}return n}function Tm(e,t,n={}){let r=W(e,".claude/settings.json"),o=io(t,"claude"),s=Fe(r)??{};if(ym(e)&&!n.force){if(s.hooks&&typeof s.hooks=="object"){let u={...s.hooks};for(let d of Object.keys(u))u[d]=Dn(u[d]),pa(u[d]).length===0&&delete u[d];Object.keys(u).length===0?delete s.hooks:s.hooks=u,qe(r,s)}return!1}let a=s.hooks&&typeof s.hooks=="object"?s.hooks:{},c=bm(o),l={...a};for(let[u,d]of Object.entries(c))l[u]=ma(a[u],d);return s.hooks=l,qe(r,s),!0}function Pm(e,t){let n=W(e,".cursor/hooks.json"),r=io(t,"cursor"),o=Fe(n)??{},s=o.hooks&&typeof o.hooks=="object"?o.hooks:{},i=Om({...s});for(let a of km)i[a]=Cm(i[a],Ln(a,r));qe(n,{...o,version:typeof o.version=="number"?o.version:1,hooks:i})}function wm(e,t){let n=W(e,".codex/hooks.json"),r=io(t,"codex"),o=Fe(n)??{},s=o.hooks&&typeof o.hooks=="object"?o.hooks:{},i=xm(r),a={...s};for(let[c,l]of Object.entries(i))a[c]=ma(s[c],l);qe(n,{...o,hooks:a})}function Nm(e){let t=W(e,".claude/settings.json"),n=Fe(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1;for(let s of Object.keys(r)){let i=r[s],a=Dn(i);JSON.stringify(i)!==JSON.stringify(a)&&(o=!0),a.length===0?delete r[s]:r[s]=a}o&&(Object.keys(r).length===0?delete n.hooks:n.hooks=r,qe(t,n),E(`Removed ev-ai hooks from ${t}`))}function vm(e){let t=W(e,".cursor/hooks.json"),n=Fe(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1,s=0;for(let i of Object.keys(r)){let a=r[i],c=ao(a);JSON.stringify(a)!==JSON.stringify(c)&&(o=!0),c.length===0?delete r[i]:(r[i]=c,s+=c.length)}if(o){if(s===0&&Object.keys(r).length===0&&Object.keys(n).filter(a=>a!=="hooks"&&a!=="version").length===0){Hn(t,{force:!0}),E(`Removed ${t}`);return}qe(t,{...n,hooks:r}),E(`Removed ev-ai hooks from ${t}`)}}function Mm(e){let t=W(e,".codex/hooks.json"),n=Fe(t);if(!n?.hooks||typeof n.hooks!="object")return;let r={...n.hooks},o=!1,s=0;for(let i of Object.keys(r)){let a=r[i],c=Dn(a);JSON.stringify(a)!==JSON.stringify(c)&&(o=!0),c.length===0?delete r[i]:(r[i]=c,s+=c.length)}if(o){if(s===0&&Object.keys(r).length===0&&Object.keys(n).filter(a=>a!=="hooks").length===0){Hn(t,{force:!0}),E(`Removed ${t}`);return}qe(t,{...n,hooks:r}),E(`Removed ev-ai hooks from ${t}`)}}function co(e=process.platform,t=process.arch,n={}){if(e==="win32")throw new Error("Windows install is not supported yet. Use macOS/Linux, or wait for phase-2 native commands.");(n.requireBinaryArch??!0)&&qi(e,t)}async function ga(e={}){let t=rm(e);e.collectorUrl=t;let n=e.skipClaude===!0,r=e.skipCursor===!0,o=e.skipCodex===!0;if(n&&r&&o)throw new Error("at least one runner must be wired; refuse --no-claude --no-cursor --no-codex together");let s=e.delivery??sa();co(process.platform,process.arch,{requireBinaryArch:s==="binary"});let i=e.cwd??process.cwd(),a=await Le(i),{command:c,hookPath:l,strategy:u}=_m(a,De(),s),{installationId:d,storePath:f}=await Mn(a,{overrideId:e.installationId}),{manifestPath:p,wrote:g}=da(a,e),S=[];return n?E("Skipped Claude hook \u2014 --no-claude"):Tm(a,c,{force:e.force})?(S.push("Claude"),e.force&&Rm(a)&&E("Forced Claude hook despite project native OTEL \u2014 expect duplicate session/tool events")):E("Skipped Claude hook \u2014 native OTEL telemetry already enabled (avoids duplicate events); pass --force to wire anyway"),r?E("Skipped Cursor hook \u2014 --no-cursor"):(Pm(a,c),S.push("Cursor")),o?E("Skipped Codex hook \u2014 --no-codex"):(wm(a,c),S.push("Codex")),E(`Installed hook (${u}) at ${l}`),E(`Installation identity ${d} at ${f}`),g&&p?E(`Shared manifest written to ${p}`):E("Using package default collector config (no shared manifest file needed)"),E(S.length>0?`Wired ${S.join(", ")} hooks in ${a} (commands include --runner)`:`No runner hooks wired in ${a} (Claude skipped by OTEL; Cursor/Codex excluded via flags)`),u==="npx"?E("Hook commands use npx and may be committed; teammates need Node on PATH only (no install step, no env vars when collector_url is in the shared manifest)."):u==="project_binary"?E("Hook commands are git-root-relative and may be committed; each collaborator runs install once to populate .ev-ai/agent-hook/ (gitignored)."):u==="dev_mjs"&&E("Hook commands use node + monorepo packages/agent-hook/dist/hook.mjs (local delivery; rebuild with yarn workspace @ev-ai/agent-hook build)."),g&&p&&e.collectorUrl&&E("Shared manifest includes collector_url \u2014 commit it with hook configs so teammates post without env vars."),{gitRoot:a,hookPath:l,manifestPath:p,installationStorePath:f,strategy:u}}async function ha(e=process.cwd()){co(process.platform,process.arch,{requireBinaryArch:!0});let t=await Le(e),{projectPath:n,globalPath:r}=pm(t);E(`Refreshed ${r}`),E(`Refreshed ${n}`),E("Hook configs and shared manifest left unchanged")}async function _a(e={}){let t=nm(e);e.collectorUrl=t,co(process.platform,process.arch,{requireBinaryArch:!1});let n=e.cwd??process.cwd(),r=await Le(n),{manifestPath:o,wrote:s}=da(r,e);if(t!==void 0&&(!o||!s))throw new Error("configure failed to write shared collector manifest");return s&&o?E(`Wrote ${o}`):t===void 0&&E("No --url given and no shared manifest yet \u2014 pass --url <\u2026/{orgToken}/hook> to write collector destination."),E("Manifest only \u2014 enable ev-ai marketplace plugins. Do not also run file-wiring install for the same events."),{gitRoot:r,manifestPath:o}}function Sa(e){for(let t of[()=>Nm(e),()=>vm(e),()=>Mm(e)])try{t()}catch(n){let r=n instanceof Error?n.message:String(n);E(`WARN: strip skipped a hook file: ${r}`)}}async function Ea(e=process.cwd()){let t=await Le(e);return Sa(t),E("Stripped ev-ai file-wired hooks; shared collector manifest left in place."),E("Next: enable ev-ai marketplace plugins, then restart runners."),{gitRoot:t}}async function ya(e=process.cwd()){let t=await Le(e);Sa(t);for(let n of yn){let r=W(t,n);if(Xe(r))try{Hn(r,{force:!0}),E(`Removed ${r}`)}catch(o){let s=o instanceof Error?o.message:String(o);E(`WARN: uninstall could not remove ${r}: ${s}`)}}}import{existsSync as __,mkdirSync as S_,readdirSync as E_,readFileSync as y_,unlinkSync as Pc,writeFileSync as R_}from"node:fs";import{homedir as wc}from"node:os";import{join as xo}from"node:path";import{open as Ra,mkdir as Lm,readFile as Hm,readdir as Um,rename as Dm,stat as Fm,rmdir as $m,unlink as jm,utimes as Bm}from"node:fs/promises";var Fn=new WeakMap;function Aa(e){if(e&&typeof e=="object"&&"code"in e)return e}function uo(e){return Aa(e)?.code==="ENOENT"}function ba(e){return Aa(e)?.code==="EEXIST"}async function xa(e,t){try{return await e.readdir(t)}catch(n){if(uo(n))return[];throw n}}function ka(){return{async open(e,t){let n=await Ra(e,t),r={path:e};return Fn.set(r,n),r},async write(e,t){let n=Ca(e),r=typeof t=="string"?Buffer.from(t,"utf8"):t;await n.write(r)},async fsync(e){await Ca(e).sync()},async close(e){let t=Fn.get(e);Fn.delete(e),t&&await t.close()},rename:Dm,async readdir(e){return Um(e)},readFile:Hm,async stat(e){let t=await Fm(e);return{mtimeMs:t.mtimeMs,size:t.size,isDirectory:()=>t.isDirectory()}},async mkdir(e,t){await Lm(e,t)},unlink:jm,rmdir:$m,utimes:Bm,async fsyncDir(e){if(process.platform==="win32")return;let t=await Ra(e,"r");try{await t.sync()}finally{await t.close()}}}}function Ca(e){let t=Fn.get(e);if(!t)throw new Error("closed");return t}import{existsSync as Qm}from"node:fs";import{existsSync as Km}from"node:fs";import{homedir as Oa}from"node:os";import{join as Gm}from"node:path";function Ta(e){return e.settings.filter(t=>t.toLowerCase().endsWith(".json"))}var Wm={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/sandbox.json",".cursor/permissions.json"],mcpJson:[".cursor/mcp.json"]},homeOnly:{skillRoots:[".cursor/skills-cursor"],memory:[[".cursor/AGENTS.md"]],settings:[".cursor/cli-config.json"],plugins:"cursor",managed:"cursor"},projectOnly:{skillRoots:[".agents/skills"],settings:[".cursor/cli.json"]}},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 Ia(e,t){if(!(!e&&!t))return[...e??[],...t??[]]}function zm(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:Ia(n.mcpJson,t.mcpJson),mcpToml:Ia(n.mcpToml,t.mcpToml),plugins:t.plugins??n.plugins,managed:t.managed??n.managed}}function Pa(e){return Object.fromEntries(Object.entries(Wm).map(([t,n])=>[t,zm(n,n[e])]))}var Ct=Pa("homeOnly"),Qe=Pa("projectOnly");function Vm(e){return[...e.skillRoots,...e.dirs.map(t=>t.dir),...e.memory.flat(),...e.settings,...e.mcpJson??[],...e.mcpToml??[]]}function Jm(e,t){return Vm(e).some(n=>Km(Gm(t,n)))}function wa(e,t){for(let n of e)if(Jm(n,t))return!0;return!1}function Ze(e){return[...new Set(e)]}function et(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:Ze(t),subagents:Ze(n),commands:Ze(r),rules:Ze(o),memory:Ze(s),settings:Ze(i),mcp:Ze(a)}}function Ym(e,t=Oa(),n=process.platform){let r=[];for(let o of e)o.managed&&r.push(...Tn(o.managed,n,t));return Ze(r)}var tt=et(Object.values(Ct));function Na(e=Oa(),t=process.platform){return Ym(Object.values(Ct),e,t)}import{existsSync as Xm}from"node:fs";import{resolve as lo}from"node:path";function ge(e){return lo(e).replaceAll("\\","/").replace(/\/$/,"")}function ct(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 $n(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 qm=/^(?!\.)[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;function jt(e){let t=e.replaceAll("\\","/").replace(/^\.\//,"");return!t||t.startsWith("/")||/^[A-Za-z]:\//.test(t)||t.split("/").includes("..")||!qm.test(t)?null:t}function At(e,t){let n=new Set,r=[];for(let o of[e,t]){if(!o)continue;let s=ge(o);n.has(s)||(n.add(s),r.push(s))}return r}function Zm(e,t){let n=`${e}/`;return t===e||t.startsWith(n)}function Ie(e,t,n,r=Xm){for(let o of e)for(let s of t){let i=ge(lo(o,s)),a=lo(o,s,n).replaceAll("\\","/");if(Zm(i,a)&&r(a))return a}return null}var Ma=/(?:^|\/|[\s"'=(])(?:\.cursor\/|\.claude\/|\.agents\/)skills(?:-cursor)?\/([^/]+)\/SKILL\.md/i,La=/(?:^|\/|[\s"'=(])\.codex\/commands\/([^/]+)\.md\b/i,eg=/(?:^|\s)\/([a-z][a-z0-9-]{1,63}(?:\/[a-z][a-z0-9-]{1,63}){0,5})\b/gi,va=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"]),tg=/^[a-z][a-z0-9-]{1,63}$/,ng=[".cursor/skills",".claude/skills",".agents/skills"],rg=[".cursor/skills",".cursor/skills-cursor",".claude/skills",".agents/skills"],og=ct(ng,et(Object.values(Qe)).skills),sg=ct(rg,et(Object.values(Ct)).skills),ig=new Set(["read","read_file","view"]),ag=new Set(["bash","shell","zsh"]);function fo(e){let t=e.replace(/\\/g,"/");return Ma.exec(t)?.[1]??null}function cg(e){let t=e.replace(/\\/g,"/"),r=La.exec(t)?.[1];return r?r.toLowerCase():null}function ug(e){return fo(e)??cg(e)}function lg(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 jn(e){return typeof e=="string"?jn(me(e,null)):!e||typeof e!="object"?null:lg(e)}function Ha(e){if(typeof e=="string")return Ha(me(e,null));if(!e||typeof e!="object")return null;let t=e.command;return typeof t=="string"&&t.length>0?t:null}function po(e){let t=Ha(e.tool_input);if(t)return t;let n=it(e.command);return n.length>0?n:null}function fg(e){let t=e.replace(/\\/g,"/"),n=Ma.exec(t);if(n?.[1])return n[1];let o=La.exec(t)?.[1];return o?o.toLowerCase():null}function dg(e){return typeof e.tool_name=="string"?e.tool_name:typeof e.tool=="string"?e.tool:""}function mo(e){let t=jn(e.tool_input)??it(e.file_path);return t.length>0?t:null}function Bt(e,t,n){let r=dg(e).toLowerCase();if(ig.has(r)){let o=mo(e);return o?t(o):null}if(ag.has(r)){let o=po(e);return o?n(o):null}return null}function Ua(e){return Bt(e,ug,fg)}function pg(e){let t=new Set,n=[];for(let r of e.matchAll(eg)){let o=r[1]?.toLowerCase();!o||t.has(o)||mg(o)||(t.add(o),n.push(o))}return n}function mg(e){let t=e.split("/")[0];return va.has(e)||t!==void 0&&va.has(t)}function Da(e){let t=e.skillId.toLowerCase();if(!tg.test(t))return null;let n=e.exists??Qm,r=`${t}/SKILL.md`,o=Ie(At(e.launchCwd,e.gitRoot),og,r,n);return o!==null?o:e.home?Ie([ge(e.home)],sg,r,n):null}function gg(e){return it(e.prompt)}function Fa(e){let t=M(e,"command_name");if(t){let r=M(e,"expansion_type");if(r&&r!=="slash_command")return[];let o=t.replace(/^\//,"").toLowerCase();return o?[o]:[]}let n=gg(e);return n?pg(n):[]}var yo=Ve(rt(),1);import{existsSync as Bh}from"node:fs";var lt={claude:".claude",cursor:".cursor",codex:".codex",opencode:".opencode"};function Gt(e){let n=e.replace(/^\/+|\/+$/g,"").toLowerCase().split("/").filter(Boolean);return n.length<2?"":n.join("/")}function jh(e){if(!e)return"";let t=Ut(e).replace(/\.git$/i,""),n=t.match(/^git@[^:]+:(.+)$/);if(n?.[1])return Gt(n[1]);let r=t.match(/^ssh:\/\/[^/]+\/(.+)$/i);if(r?.[1])return Gt(r[1]);t=t.replace(/^https:\/\//i,""),t=t.replace(/^http:\/\//i,""),t=t.replace(/^ssh:\/\//i,"");let o=t.match(/^[^/]+\/(.+)$/);return o?.[1]?Gt(o[1]):Gt(t)}async function Jn(e=process.cwd()){let t=await Se("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([Se("git",["remote","get-url","origin"],2e3,{cwd:e}),Se("git",["branch","--show-current"],2e3,{cwd:e}),Se("git",["rev-parse","HEAD"],2e3,{cwd:e}),Se("git",["status","--porcelain"],2e3,{cwd:e})]);return{remote:n.ok?Ut(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 lc(e,t,n,r=process.cwd(),o,s,i){if(t)return t;let a=lt[n];if(!a)return"";let c=Ui(n,e.scope_path,i);if(s){let g=Wi(s,c);if(g)return g}let l=o??await Jn(r),u=l?.remote?jh(l.remote):"";if(u||(u=Gt(process.env.GITHUB_REPOSITORY??"")),!u)return"";let d=e.scope_path??"",f=d?`${d}/`:"",p=`${u}:${f}${a}`;return s&&zi(s,c,p),p}var Kh=[".cursor/rules",".claude/rules",".codex/rules"],Gh=et(Object.values(Qe)).rules;function Wh(e){return ct($n(e?lt[e]:void 0,Kh),Gh)}var zh=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/rules\/[^'"\s]+?\.(?:mdc|md|rules))\b/i;function fc(e){let t=jt(e.relativePath);if(!t)return null;let n=e.exists??Bh,r=At(e.launchCwd,e.gitRoot),o=Wh(e.runnerPlatform),s=Ie(r,o,t,n);if(s!==null)return s;if(!t.includes("/")){let i=Ie(r,["."],t,n);if(i!==null)return i}return e.home?Ie([ge(e.home)],o,t,n):null}function Vh(e){let t=e.replace(/\\/g,"/"),r=zh.exec(t)?.[1];return r?(0,yo.nativeKeyForRulePath)(r):null}function dc(e){return Bt(e,yo.nativeKeyForRulePath,Vh)}function pc(e){return e.replace(/\.(mdc|md|rules)$/i,"")}function mc(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=jt(i);!a||n.has(a)||(n.add(a),r.push(a))}return r}var Ro=Ve(rt(),1);import{existsSync as Jh}from"node:fs";var Yh=[".cursor/commands",".claude/commands",".codex/prompts"],Xh=et(Object.values(Qe)).commands;function qh(e){return ct($n(e?lt[e]:void 0,Yh),Xh)}var Zh=/(?:^|\/|[\s"'=(])((?:\.cursor|\.claude|\.codex)\/(?:commands|prompts)\/[^'"\s]+?\.(?:md|mdc))\b/i;function gc(e){let t=jt(e.commandId);if(!t)return null;let n=e.exists??Jh,r=`${t}.md`,o=qh(e.runnerPlatform),s=Ie(At(e.launchCwd,e.gitRoot),o,r,n);return s!==null?s:e.home?Ie([ge(e.home)],o,r,n):null}function Qh(e){let t=e.replace(/\\/g,"/"),r=Zh.exec(t)?.[1];return r?(0,Ro.nativeKeyForCommandPath)(r):null}function hc(e){return Bt(e,Ro.nativeKeyForCommandPath,Qh)}var Yn=Ve(rt(),1);function Co(e){let t=ti(e);if(t.problem){E(`WARN: ignoring --url/--token collector override: ${t.problem}`);return}return t.url}function _c(e,t){if(M(e,"conversation_id"))return!0;if(t==="")return!1;let n=t[0];return n?.toLowerCase()===n}function e_(){return!!(F("CURSOR_VERSION")??F("CURSOR_PROJECT_DIR"))}function Sc(e,t,n){return e!=="claude"&&e!=="codex"?!1:_c(t,n)?!0:e_()}var t_=new Set(["sessionstart","sessionend","stop","stopfailure","pretooluse","posttooluse","posttoolusefailure","permissiondenied","subagentstart","subagentstop","userpromptexpansion","userpromptsubmit"]);function Wt(e,t,n,r){return _c(e,t)?"cursor":Rn(r)?r:Rn(n)?n:M(e,"turn_id")?"codex":M(e,"session_id")||t_.has(t.toLowerCase())?"claude":"unknown"}function Xn(e,t){let n=e.toLowerCase();return n==="sessionend"||n==="stopfailure"||n==="subagentstop"?!0:n==="stop"&&t==="codex"}function n_(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 Ec(e){let t=e.toLowerCase();return t==="userpromptsubmit"||t==="beforesubmitprompt"}function yc(e,t){return e.toLowerCase()==="userpromptsubmit"&&t==="claude"}function Rc(e){let t=e.toLowerCase();return t==="posttooluse"?!0:t==="posttoolusefailure"||t==="permissiondenied"?!1:null}function zt(e){return M(e,"session_id")||M(e,"conversation_id")}function Ao(e){return M(e,"prompt.id")||M(e,"prompt_id")||M(e,"generation_id")||M(e,"turn_id")}function bo(e){return M(e,"hook_event_name")||M(e,"event")}function Cc(e,t,n){let r=zt(e),o=Ao(e),s=bo(e),i=M(e,"source"),a=Wt(e,s,t,n);return{sessionId:r,turnId:o,runnerEvent:s,hookSource:i,runnerPlatform:a}}var r_=["session_start","session_end","tool_invoked","skill_invoked"];function o_(e){return r_.includes(e)}function Ac(e,t){return e&&o_(e)?e:n_(t.toLowerCase())}var s_={beforeshellexecution:"Shell",aftershellexecution:"Shell",beforereadfile:"Read",afterfileedit:"Write"};function qn(e){return/^mcp__/i.test(e)||/^MCP:/i.test(e)}function bc(e,t=""){let n=M(e,"tool_name")||M(e,"tool")||null,r=t.toLowerCase();n?r==="beforemcpexecution"&&!qn(n)&&(n=`MCP:${n}`):n=s_[r]??null;let o=e.tool_input,i=(o&&typeof o=="object"?it(o.skill)||it(o.skill_name):"")||M(e,"skill_name")||null,a=n&&e.tool_name!==n&&e.tool!==n?{...e,tool_name:n}:e;i??=Ua(a);let c=dc(a),l=hc(a);return{toolName:n,skillName:i,ruleName:c,commandName:l}}var i_=/^[A-Za-z][A-Za-z0-9_.:-]{0,63}$/;function xc(e){for(let t of["subagent_type","agent_type"]){let n=M(e,t);if(n&&i_.test(n))return n}return null}function kc(e){let t=He(e,"duration_ms");if(typeof t=="number")return t;let n=He(e,"duration");return typeof n=="number"?n:null}var a_="error",c_="interrupted",u_="permission_denied",l_=/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;function Vt(e){return l_.test(e)?e:null}function f_(e){for(let t of["failure_type","error_type"]){let n=Vt(M(e,t));if(n)return n}return null}function Ic(e,t){return He(e,"is_interrupt")===!0?c_:t.toLowerCase()==="permissiondenied"?u_:f_(e)??a_}function Oc(e,t){let n=null;for(let r of e)r&&t(r)&&(n===null||r.length>n.length)&&(n=r);return n}function d_(e,t){return Oc(t,n=>e===n||e.startsWith(`${n}_`)||e.startsWith(`${n}-`))}function p_(e,t){return Oc(t,n=>(0,Yn.mcpServerNameMatchesToolSegment)(n,e))}function m_(e,t){let n=null,r=0;for(let s of t)if(s)for(let i of(0,Yn.mcpServerToolSegmentForms)(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:p_(o[1],t)??o[1],mcpTool:o[2]}}function g_(e,t){if(/^mcp__/i.test(e))return m_(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:d_(n,t),mcpTool:n}}return{mcpServer:null,mcpTool:null}}function h_(e,t){let n=`${t}__`;return e.length>n.length&&e.toLowerCase().startsWith(n.toLowerCase())?e.slice(n.length):e}function Tc(e,t=[],n=""){let r=e?g_(e,t):{mcpServer:null,mcpTool:null},o=Vt(n.trim());if(!o)return r;let s=r.mcpTool;return!s&&e&&!qn(e)&&(s=e),s&&(s=h_(s,o)),{mcpServer:o,mcpTool:s}}var Nc=3e4,C_="claims",A_=!0,b_=100,x_=new Set(["sessionstart","sessionend","stopfailure"]),k_=["tool_name","tool","command","file_path","url"];function I_(e=wc()){return xo(Ue(e),C_)}function vc(e,t){try{let n=y_(e,"utf8").split(`
|
|
26
|
+
`,1)[0]??"";return t-Number(n.trim())}catch{return Number.NaN}}function O_(e){let t=[];for(let n of k_){let r=M(e,n).trim();r&&t.push(`${n}=${r}`)}return t.length===0?"":Dt(t.join("\0"))}function T_(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=x_.has(n);if(!a&&!c)return;let l=e.runnerPlatform.trim()||"unknown";return Dt(`${l}|${t}|${n}|${r}|${o}|${i}|${s}`)}function P_(e,t=Date.now()){let n;try{n=E_(e)}catch{return}let r=0;for(let o of n){if(r>=b_)break;r+=1;let s=xo(e,o),i=vc(s,t);if(!(!Number.isFinite(i)||i<Nc))try{Pc(s)}catch{}}}function w_(e,t,n=Date.now()){let r=xo(t,e);try{if(__(r)){let o=vc(r,n);if(Number.isFinite(o)&&o>=0&&o<Nc)return!1;try{Pc(r)}catch{}}}catch{}try{S_(t,{recursive:!0}),R_(r,`${n}
|
|
27
|
+
`,{encoding:"utf8",flag:"wx"})}catch(o){if(ba(o))return!1;let s=o instanceof Error?o.message:String(o);return E(`WARN: event claim failed open: ${s}`),!0}return P_(t,n),!0}function N_(e,t,n){let r=zt(e),o=Ao(e),s=M(e,"tool_use_id"),i=M(e,"subagent_id")||M(e,"agent_id"),a=Wt(e,t,void 0,n),c=O_(e);return{runnerPlatform:a,sessionId:r,runnerEvent:t,turnId:o,toolUseId:s,subagentId:i,callFingerprint:c}}function Mc(e,t,n,r=wc(),o=Date.now()){if(!A_)return!0;let s=T_(N_(e,t,n));if(!s)return!0;let i=w_(s,I_(r),o);return!i&&F("EV_AI_HOOK_DEBUG")&&E(`DEBUG: duplicate hook event suppressed (claim ${s.slice(0,8)}\u2026)`),i}import{closeSync as v_,writeSync as M_}from"node:fs";function Lc(e=process.env){let t=e[wr];if(delete e[wr],t===void 0)return;let n=Number.parseInt(t,10);if(!(!Number.isInteger(n)||n<3)){try{M_(n,Xs)}catch{}try{v_(n)}catch{}}}function ko(e=process.env){let t=e[Ws];if(t)return{launcherVersion:t,hookSource:e[zs]??"",fallbackReason:e[Vs],launcherScope:e[Js]}}function Hc(e,t){return(e?ni(e):void 0)===t}import{realpathSync as VC}from"node:fs";import{homedir as JC}from"node:os";var B=Ve(rt(),1);import{existsSync as L_,readFileSync as H_}from"node:fs";import{homedir as Uc}from"node:os";import{join as U_}from"node:path";var D_="cloud-cache.json",F_=1440*60*1e3,$_=900*1e3;function j_(e=Uc()){return U_(Ue(e),D_)}function B_(e){if(!L_(e))return;let t=me(H_(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 K_(e,t){try{ke(e,`${JSON.stringify(t)}
|
|
28
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);E(`WARN: cloud cache write failed open: ${r}`)}}function G_(e,t,n){if(!e||e.context!==t)return!1;let r=e.result===null?$_:F_;return n-e.probed_at<r}async function W_(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 z_(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 V_(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 J_(e){let t=await Promise.allSettled([W_(e),z_(e),V_(e)]);for(let n of t)if(n.status==="fulfilled"&&n.value)return n.value;return null}async function Dc(e,t){if(e==="interactive")return null;let n=t?.home??Uc(),r=t?.timeoutMs??1e3,o=t?.nowMs??Date.now(),s=j_(n),i=B_(s);if(G_(i,e,o))return i.result;let a=await J_(r);return K_(s,{context:e,probed_at:o,result:a}),a}var Bc=Ve(rt(),1);import{existsSync as $c}from"node:fs";import{homedir as jc}from"node:os";import{join as Jt,resolve as Io,sep as Fc}from"node:path";function Zn(e,t,n){if(!$c(e))return;let r=oe(e,{});for(let[o,s]of Object.entries(r.mcpServers??{}))n.set(o,{declared:{name:o,...t},config:s})}function Y_(e,t,n){if(!$c(e))return;let r=oe(e,{}),o=Io(t),s=null;for(let a of Object.keys(r.projects??{})){let c=Io(a);(o===c||o.startsWith(c.endsWith(Fc)?c:c+Fc))&&(s===null||c.length>Io(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 Kc(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"?(Zn(Jt(r,".claude.json"),{source:"claude_json_user"},o),Y_(Jt(r,".claude.json"),t,o)):n==="cursor"&&Zn(Jt(r,".cursor/mcp.json"),{source:"cursor_mcp_user"},o),Zn(Jt(t,".mcp.json"),{source:"mcp_json"},o),Zn(Jt(t,".cursor/mcp.json"),{source:"cursor_mcp"},o),o}async function Oo(e,t=process.cwd(),n="claude",r=jc()){return[...Kc(e,t,n,r).values()].map(o=>o.declared)}function Gc(e,t,n=process.cwd(),r="claude",o=jc()){let s=Kc(t,n,r,o),i=s.get(e);if(i!==void 0)return i.config??null;for(let[a,c]of s)if((0,Bc.mcpServerNameMatchesToolSegment)(a,e))return c.config??null;return null}var X_=["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"],q_=["CURSOR_PROJECT_DIR"],Z_=new Set(["key","api-key","api_key","apikey","token","sig","signature","access_token","password","pwd","secret","client_secret"]);function Q_(e){try{let t=new URL(e);(t.username||t.password)&&(t.username="",t.password="");for(let[n]of t.searchParams)Z_.has(n.toLowerCase())&&t.searchParams.set(n,"[redacted]");return t.toString()}catch{return e}}function Wc(e=process.env){let t=X_.map(r=>Object.prototype.hasOwnProperty.call(e,r)?{name:r,present:!0,value:Q_(e[r]??"")}:{name:r,present:!1}),n=q_.map(r=>({name:r,present:Object.prototype.hasOwnProperty.call(e,r)&&!!e[r]}));return[...t,...n]}import{homedir as TS}from"node:os";import{homedir as zc}from"node:os";import{join as eS}from"node:path";function tS(e=zc()){return eS(e,".claude.json")}function Qn(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Vc(e=zc()){let n=oe(tS(e),{}).oauthAccount;if(!n||typeof n!="object")return null;let r=Qn(n.emailAddress),o=Qn(n.fullName)??Qn(n.displayName),s=Qn(n.accountUuid),i=r??s;return!i||de(o,r)?null:{git_user_name:null,git_user_email:null,platform_login:i,identity_source:"claude_oauth"}}import{homedir as Xc}from"node:os";import{join as Jc}from"node:path";var nS="https://api.openai.com/auth";function kt(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function qc(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function rS(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 qc(r)}catch{return null}}function Yc(e,t,n){return kt(e[n])??kt(t?.[n])}function oS(e=process.env,t=Xc()){let n=kt(e.CODEX_HOME)??Jc(t,".codex");return Jc(n,"auth.json")}function Zc(e=process.env,t=Xc()){let n=oe(oS(e,t),{}),r=kt(n.auth_mode);if(r!==null&&r!=="chatgpt"||r===null&&kt(n.OPENAI_API_KEY))return null;let o=kt(n.tokens?.id_token);if(!o)return null;let s=rS(o);if(!s)return null;let i=qc(s[nS]),a=Yc(s,i,"name"),c=Yc(s,i,"email");return!c||de(a,c)?null:{git_user_name:null,git_user_email:null,platform_login:c,identity_source:"codex_oauth"}}import{homedir as nr}from"node:os";import{join as Be}from"node:path";import{join as sS}from"node:path";var iS="cursor-ide-identity.json",aS=840*60*1e3;function eu(e){return sS(Ue(e),iS)}function Qc(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function tu(e){let t=oe(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:Qc(t.email),auth_id:Qc(t.auth_id)}}function nu(e,t,n){if(e?.db_path!==t)return!1;let r=n-e.read_at_ms;return r>=0&&r<aS}function ru(e,t){try{ke(e,`${JSON.stringify(t)}
|
|
29
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);E(`WARN: cursor IDE identity cache write failed open: ${r}`)}}import{execFileSync as cS}from"node:child_process";import{existsSync as uS}from"node:fs";import{createRequire as lS}from"node:module";import{pathToFileURL as fS}from"node:url";var su=lS(import.meta.url),er=`
|
|
29
30
|
SELECT key, value
|
|
30
31
|
FROM ItemTable
|
|
31
32
|
WHERE key LIKE 'cursorAuth/%'
|
|
32
33
|
AND key NOT LIKE '%Token%'
|
|
33
34
|
AND key NOT LIKE '%token%'
|
|
34
35
|
ORDER BY key
|
|
35
|
-
`.trim(),
|
|
36
|
-
`)){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&&!
|
|
37
|
-
`);return
|
|
38
|
-
`)){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 i_(e,t=v){let n=await t("git",["config","--get-regexp","^user\\.(name|email)$"],2e3,{cwd:e});return s_(n)}function a_(e=process.env){let t=k(e.GIT_AUTHOR_NAME),n=k(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=k(e.GIT_COMMITTER_NAME),o=k(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=k(e.EMAIL);return s?{git_user_name:null,git_user_email:s,platform_login:null,identity_source:"git_env"}:null}function pe(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 c_(e=process.env){let t=k(e.EV_AI_HOOK_OPERATOR_EMAIL),n=k(e.EV_AI_HOOK_OPERATOR_LOGIN),r=pe(k(e.EV_AI_HOOK_OPERATOR_NAME),t,"configured",t??n);if(r)return r;let o=k(e.GITHUB_ACTOR)??k(e.GITHUB_TRIGGERING_ACTOR)??k(e.GITHUB_USER),s=pe(o,null,"github",o);if(s)return s;let i=k(e.GITLAB_USER_LOGIN),a=k(e.GITLAB_USER_EMAIL),c=pe(k(e.GITLAB_USER_NAME)??i,a,"gitlab",a??i);if(c)return c;let l=k(e.BUILD_REQUESTEDFOREMAIL),u=pe(k(e.BUILD_REQUESTEDFOR),l,"azure_devops",l??k(e.BUILD_REQUESTEDFORID));if(u)return u;let f=k(e.BUILDKITE_BUILD_CREATOR_EMAIL),m=pe(k(e.BUILDKITE_BUILD_CREATOR),f,"buildkite",f);if(m)return m;let d=k(e.BUILD_USER_EMAIL)??k(e.CHANGE_AUTHOR_EMAIL),_=pe(k(e.BUILD_USER)??k(e.CHANGE_AUTHOR),d,"jenkins",d??k(e.BUILD_USER_ID));if(_)return _;let h=k(e.CIRCLE_USERNAME),S=pe(h,null,"circleci",h);if(S)return S;let E=k(e.CODEBUILD_INITIATOR),y=pe(E,null,"codebuild",E);if(y)return y;let F=k(e.DRONE_COMMIT_AUTHOR_EMAIL),P=k(e.DRONE_COMMIT_AUTHOR),T=pe(P??k(e.DRONE_COMMIT_AUTHOR_NAME),F,"drone",F??P);if(T)return T;if(ec(e.CLAUDE_CODE_REMOTE)||ec(e.CURSOR_AGENT)){let H=k(e.CURSOR_USER_EMAIL);return{git_user_name:null,git_user_email:null,platform_login:H&&!G(null,H)?H:null,identity_source:"cloud"}}return null}function Hr(e){return!!((e.git_user_name??e.git_user_email)&&!G(e.git_user_name,e.git_user_email))}function k(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function ec(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function u_(e,t,n){return e==="claude"?Ua(t):e==="cursor"?qa(t,n):e==="codex"?$a(n,t):null}async function Fr(e,t=v,n=process.env,r={}){let o=await i_(e,t),s=a_(n),i=Hr(o)?o:s&&Hr(s)?s:null,a=u_(r.runnerPlatform,r.home??r_(),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=c_(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:Hr(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 jr(e){let{gitRoot:t,installationStorePath:n,forceResend:r}=e,o=e.exec??v,s=e.env??process.env,i=await Fr(t,o,s,{runnerPlatform:e.runnerPlatform,home:e.home}),a=o_(i.git_user_name,i.git_user_email,i.identity_source,i.platform_login),l=(n?nr(n):void 0)?.operator_identity_hash;if(!(r||l!==void 0&&l!==a||!l))return{commit:()=>{}};let d=n;return{operator:i,commit:()=>{d&&vs(d,a,jt())}}}function $r(e){return e?!nr(e)?.operator_identity_hash:!0}function tc(e){return!0}import{existsSync as eS,readFileSync as tS}from"node:fs";import{homedir as cu}from"node:os";import{join as Ye,resolve as nS}from"node:path";import{basename as Vh,join as Je}from"node:path";import{dirname as fc,resolve as pn}from"node:path";import{existsSync as l_}from"node:fs";import{homedir as oc}from"node:os";import{relative as sc,resolve as ne,sep as Ae}from"node:path";var d_=["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"],f_=["prompt","tool_input","tool_response","last_assistant_message","command"],p_=new Set;function m_(e){switch(e?.toLowerCase()){case"beforemcpexecution":return new Set(["command"]);case"stopfailure":return new Set(["last_assistant_message"]);default:return p_}}function ic(e){return ac(e)==="allowlist"}function ac(e){return A("EV_AI_HOOK_CAPTURE_CONTENT")?.toLowerCase()==="off"||e.capture_hook_input==="allowlist"?"allowlist":e.capture_hook_input==="full"||e.debug===!0||A("EV_AI_HOOK_CAPTURE_FULL_INPUT")==="1"?"full":"content"}function g_(e){let t={};for(let n of d_){let r=ie(e,n);r!==void 0&&(t[n]=r)}return t}function dn(e,t){if(typeof e!="string"||e.length===0||!t)return null;let n=ne(e),r=ne(t),o=sc(r,n);return!o||o==="."?".":o.startsWith(`..${Ae}`)||o===".."||ne(r,o)!==n?null:o.split(Ae).join("/")}function cc(e,t){let n=sc(ne(t),ne(e)).split(Ae).join("/");return!n||n==="."?null:n===".."||n.startsWith("../")&&n.split("/").every(r=>r==="..")?n:null}function uc(e){return typeof e!="string"||e.length===0?null:ne(e).split(Ae).join("/")}function __(){let e=A("CURSOR_PROJECT_DIR");if(!e)return null;let t=ne(e);return l_(t)?t.split(Ae).join("/"):null}function Br(e,t){return dn(e,t)!==null}function h_(e,t){let n=ne(t??oc(),".cursor").split(Ae).join("/");return Br(e,n)}function S_(e,t,n){return t!==null&&Br(e,t)?!0:t!==null&&h_(e,n.home)?!1:n.inGitRepo===!0&&n.gitRoot!==void 0&&Br(e,n.gitRoot)?!0:t===null}function lc(e,t){let n=uc(e.cwd);if(n!==null)return n;let r=ne(process.cwd()).split(Ae).join("/"),o=__();return S_(r,o,t)?r:o??r}function Vr(e,t={}){return lc(e,t)}function Wr(e,t=oc()){let n=ne(t).split(Ae).join("/").replace(/\/$/,"");return n.length<=1?e:e===n?"~":e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function nc(e,t,n){let r=uc(n.launchCwd)??lc(t,n);e.cwd=Wr(r,n.home);let o=n.inGitRepo===!0&&n.gitRoot!==void 0?dn(r,n.gitRoot):null;o!==null&&(e.cwd_relative=o)}var dc="\u2026[truncated]\u2026",Gr=Buffer.byteLength(dc,"utf8"),E_=8;function _t(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function rc(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(0,t).toString("utf8")}function y_(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 R_(e,t){if(Buffer.byteLength(e,"utf8")<=t)return e;if(t<=Gr)return rc(e,t);let r=t-Gr,o=Math.ceil(r/2),s=Math.floor(r/2);return`${rc(e,o)}${dc}${y_(e,s)}`}function zr(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)=>{zr(r,[...t,o],n)});return}if(e!==null&&typeof e=="object")for(let[r,o]of Object.entries(e))t.length===0&&r.startsWith("_")||zr(o,[...t,r],n)}function C_(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 A_=256;function I_(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 k_(e,t,n){let r=Number.POSITIVE_INFINITY;for(let o=0;o<6;o++){let s=_t(e);if(s<=t)return;let i=[];zr(e,[],i),i.sort((u,f)=>f.bytes-u.bytes);let a=i.filter(u=>u.bytes>n);if(a.length===0)return;let c=I_(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&&C_(e,u.path,R_(u.value,r))}}function O_(e,t){let n=Math.max(0,t-A_),r=Object.keys(e).filter(s=>!s.startsWith("_")).map(s=>({key:s,bytes:_t(e[s])})).sort((s,i)=>i.bytes-s.bytes),o=[];for(let{key:s}of r){if(_t(e)<=n)break;delete e[s],o.push(s)}o.length>0&&(e._dropped_keys=o.slice(0,10))}function Kr(e,t){let n=_t(e);if(n<=t)return e;let r=structuredClone(e);return r._truncated=!0,r._original_bytes=n,k_(r,t,Gr+E_),_t(r)>t&&O_(r,t),r}function b_(e,t,n){let r=m_(n.runnerEvent);for(let o of f_){if(r.has(o))continue;let s=t[o];s!==void 0&&(e[o]=s)}}function fn(e,t,n={}){let r=ac(t);if(r==="full"){let s={...e};return delete s.cwd,delete s.transcript_path,nc(s,e,n),Kr(s,zn)}let o=g_(e);return nc(o,e,n),r==="content"?(b_(o,e,n),Kr(o,zn)):Kr(o,Qo)}function x_(e){return typeof e=="string"&&e.length>0}function Jr(e){let t=pn(e.home),n=pn(e.launchCwd),r=e.gitRoot?pn(e.gitRoot):null,o=new Set,s=[],i=null;e.inGitRepo&&x_(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&&dn(n,r)!==null;if(e.inGitRepo&&r!==null&&r!==t&&c){let l=fc(r);for(;;){let u=pn(l);if(u===t)break;let f=fc(u);if(f===u)break;if(e.hasProjectSpec(u)){s.push({scope:"parent",dir:u}),a=cc(u,n);break}l=f}}return{anchors:s,parentRel:a}}import{existsSync as pc,readdirSync as P_,realpathSync as T_}from"node:fs";import{basename as w_,dirname as N_,relative as M_,resolve as v_,sep as L_}from"node:path";var Yr=400,mn=class{constructor(t,n={}){this.home=t;this.pathMode=n.pathMode??"home-relative",this.maxEntries=n.maxEntries??ge}components=[];truncated=!1;pathMode;maxEntries;pluginExpandRemaining;seenRealpaths=new Set;componentPath(t){if(this.pathMode==="tilde"){let r=v_(t).split(L_).join("/");return Wr(r,this.home)}let n=M_(this.home,t).replace(/\\/g,"/");return!n||n.startsWith("..")?`external/${M(N_(t))}/${w_(t)}`:n}claimFile(t){try{let n=T_(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(!pc(t))return[];try{return P_(t,{withFileTypes:!0})}catch{return[]}}readJson(t,n){if(pc(t))return D(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 Xr,readFileSync as U_,statSync as D_}from"node:fs";import{basename as gc,join as ht,relative as _c}from"node:path";var Zr=100*1024,H_=4;function F_(e){return e.length<=Zr?e:`${e.slice(0,Zr-1)}\u2026`}function j_(e){try{let t=U_(e),n=t.toString("utf8");return{hash:M(t),length:t.length,text:F_(n)}}catch{return null}}var mc={HOOK:"EVENT",COMMAND:"EXPLICIT_INVOCATION",MEMORY:void 0,MCP_SERVER:void 0,PLUGIN:void 0,SKILL:"UNSPECIFIED",RULE:"UNSPECIFIED",SUBAGENT:"UNSPECIFIED"};function $_(e){return e in mc?mc[e]:"UNSPECIFIED"}function gn(e,t){if(!e.claimFile(t.absolutePath))return!1;let n=j_(t.absolutePath);if(!n)return!1;let r=t.name??gc(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=$_(t.kind);return s&&(o.trigger=s),e.push(o)}function K_(e,t,n){let r=_c(e,t).replace(/\\/g,"/");return!r||r.startsWith("..")?gc(t).replace(/\.(md|mdc|toml)$/i,""):n?r.replace(/\.(md|mdc|toml)$/i,""):r}function Me(e,t){let{dir:n,kind:r,origin:o,enabled:s,nested:i,extensions:a}=t;qr(e,{walkRoot:n,currentDir:n,depth:0,kind:r,origin:o,enabled:s,nested:i,extensions:a})}function qr(e,t){let{walkRoot:n,currentDir:r,depth:o,kind:s,origin:i,enabled:a,nested:c,extensions:l}=t;if(!(o>H_))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=ht(r,u.name,c);if(Xr(d)){let _=_c(n,ht(r,u.name)).replace(/\\/g,"/");gn(e,{absolutePath:d,kind:s,origin:i,enabled:a,name:_||u.name});continue}qr(e,{walkRoot:n,currentDir:ht(r,u.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l});continue}if(u.isDirectory()){qr(e,{walkRoot:n,currentDir:ht(r,u.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l});continue}if(!u.isFile()||!l)continue;let f=u.name.toLowerCase();if(!l.some(d=>f.endsWith(d)))continue;let m=ht(r,u.name);gn(e,{absolutePath:m,kind:s,origin:i,enabled:a,name:K_(n,m,!0)})}}function hc(e){for(let t of e)if(Xr(t))try{if(D_(t).size>0)return t}catch{continue}return e.find(t=>Xr(t))}import{existsSync as hh,readFileSync as Sh}from"node:fs";var _n=Qe(ze(),1);var B_="<omitted>",G_=["package_name","package_spec","package_version","package_version_source"],Sc=100,Ec=120,hn=[{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"}],yc=new Set(hn.map(e=>e.attr)),z_=["enabled","disabled"],V_=["serverUrl","auth","bearer_token_env_var","default_tools_approval_mode","defaultToolsApprovalMode","env_vars","env_http_headers","http_headers"],W_=new Set(["type","command","url","args","env","envVars","headers",...z_,...V_,...hn.map(e=>e.raw)]),J_=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",...G_,...yc,...[...yc].map(e=>`${e}_truncated`)]);function Rc(e,t){for(let n of t)W_.has(n)||J_.has(n)||(e[n]=B_)}var Y_=/^(authorization|auth|api[-_]?key|access[-_]?token|refresh[-_]?token|secret|password|passwd|token|bearer|client[-_]?secret|client[-_]?id|private[-_]?key|signing[-_]?key)$/i,X_=/(?:^|[-_])(secret|password|passwd|token|api[-_]?key|private[-_]?key|signing[-_]?key|client[-_]?secret|client[-_]?id)(?:[-_]|$)/i,Z_=/^(sk-|ghp_|gho_|github_pat_|xox[baprs]-|AKIA|ASIA|AIza|ya29\.)/,q_=/^bearer(?:\s+|$)/i;function Sn(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Cc(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Qr(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=Sn(e);return t?Object.keys(t).filter(n=>n.length>0):[]}function ve(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch{return e}}function Q_(e,t){if(e!==void 0&&/^https?:\/\//i.test(e)&&(0,_n.launchContainsCredentials)({kind:"url",url:e})||(0,_n.launchContainsCredentials)({kind:"command",command:e??"",arguments:t}))return!0;let n=Et([...t]);return t.some((r,o)=>n[o]===r?!1:/^https?:\/\//i.test(r)?(0,_n.launchContainsCredentials)({kind:"url",url:r}):!0)}function Ac(e,t,n){Q_(t,n)&&(e.launch_had_credentials=!0)}function eh(e){return Z_.test(e)||q_.test(e)?"<redacted>":e.includes("://")?ve(e):e}function Ic(e){if(/^https?:\/\//i.test(e))return ve(e);let t=e.indexOf("=");return t>0?`${e.slice(0,t+1)}${Ic(e.slice(t+1))}`:eh(e)}function th(e){let t=e.replace(/^-+/,"").split("=",1)[0]??"";return Y_.test(t)||X_.test(t)}function Et(e){let t=[],n=!1;for(let r of e){if(n){t.push("<redacted>"),n=!1;continue}if(th(r)){t.push("<redacted>"),n=!r.includes("=");continue}t.push(Ic(r))}return t}function nh(e){let t=Cc(e);if(t.length===0)return;let n=[...new Set(t.map(r=>r.length>Ec?r.slice(0,Ec):r))].sort();if(n.length!==0)return n.length>Sc?{names:n.slice(0,Sc),truncated:!0}:{names:n,truncated:!1}}function rh(e){let t=Sn(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 kc(e,t){let n=new Set;for(let{raw:r,attr:o}of hn){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=nh(s);i&&(e[o]=i.names,i.truncated&&(e[`${o}_truncated`]=!0),n.add(o))}}function Oc(e,t){let n=Sn(e),r={transport:t};if(!n)return r;Rc(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=Cc(n.args);a&&(r.command_or_url=ve(a));let l=Et(c);l.length>0&&(r.args=l),Ac(r,a,c);let u=rh(n.env_http_headers),f=[...new Set([...Qr(n.env),...Qr(n.envVars),...Qr(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();f.length>0&&(r.env_var_names=f),u.headers.length>0&&(r.env_http_header_names=[...new Set(u.headers)].sort());for(let h of["headers","http_headers","env_http_headers"])if(n[h]!==void 0&&n[h]!==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 _=typeof n.default_tools_approval_mode=="string"?n.default_tools_approval_mode:typeof n.defaultToolsApprovalMode=="string"?n.defaultToolsApprovalMode:void 0;return _&&(r.default_tools_approval_mode=_),kc(r,n),r}function bc(e){let t=Sn(e);return t?t.enabled===!1?!1:t.disabled!==!0:!0}function no(e,t,n=!0){let r=Object.keys(t).sort().map(o=>[o,t[o]??null]);return M(JSON.stringify({name:e,attributes:r,enabled:n}))}function We(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 to(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(true|false)\\s*$`,"m").exec(e);if(n?.[1])return n[1]==="true"}function eo(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(.+)$`,"m").exec(e);if(!n?.[1])return;let r=We(n[1]);return r.length>0?r:void 0}function oh(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],We(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(`
|
|
39
|
-
${e}`);return s?.[1]&&r(s[1]),n}function
|
|
40
|
-
`)){let s=
|
|
41
|
-
`)){let
|
|
42
|
-
${e}`);if(
|
|
43
|
-
`)){let
|
|
44
|
-
`);return fh("sha512").update(t).digest("hex").slice(0,16)}function mh(e){let t=process.platform==="win32"?yt(A("LOCALAPPDATA")??e,"npm-cache"):yt(e,".npm"),n=A("npm_config_cache")??A("NPM_CONFIG_CACHE");return n===void 0||n===t?[t]:[n,t]}function vc(e){return typeof e=="string"&&e.length>0&&e.length<=Ie.PACKAGE_FIELD_MAX?e:null}function gh(e,t,n){let r=ph(e);for(let o of mh(n)){let s=yt(o,"_npx",r),i=D(yt(s,"node_modules",...t.split("/"),"package.json"),{}),a=vc(i.version);if(a!==null)return a;let c=D(yt(s,"package-lock.json"),{}),l=vc(c.packages?.[`node_modules/${t}`]?.version);if(l!==null)return l}return null}function _h(e){return e.length<=Ie.PACKAGE_FIELD_MAX?e:`${e.slice(0,Ie.PACKAGE_FIELD_MAX-1)}\u2026`}function ro(e,t,n){if(typeof e!="string"||e.length===0)return null;let r=(0,Ie.npxPackageSpecs)(e,t??[]),o=r[0];if(o===void 0)return null;let s=(0,Ie.packageNameFromSpec)(o);if(s===null)return null;let i=gh(r,s,n);return{package_name:s,package_spec:_h(o),...i===null?{}:{package_version:i,package_version_source:"npx_cache"}}}function Lc(e,t){if(typeof e!="string"||e.length===0)return null;let[n,...r]=En(e.trim());return n===void 0?null:ro(n,r,t)}function yn(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 ro(typeof n.command=="string"?n.command:null,r,t)}function Uc(e,t){let n=/^\s*command\s*=\s*(.+)$/m.exec(e);return n===null?null:ro(We(n[1]??""),St(e,"args"),t)}function Eh(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 Dc(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=Eh(a),l=Oc(a,c);Object.assign(l,yn(a,e.home)??{});let u=bc(a);e.push({kind:"MCP_SERVER",name:i,path:s,content_hash:no(i,l,u),origin:n,enabled:u,attributes:l})}}function Hc(e,t,n){if(!hh(t)||!e.claimFile(t))return;let r;try{r=Sh(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),f="unknown";/^\s*url\s*=/m.test(u)?f="http":/^\s*command\s*=/m.test(u)&&(f="stdio");let m=Pc(u,f);Object.assign(m,Uc(u,e.home)??{});let d=xc(u);e.push({kind:"MCP_SERVER",name:a,path:o,content_hash:no(a,m,d),origin:n,enabled:d,attributes:m})}}import{existsSync as Ch,readdirSync as Ah}from"node:fs";import{join as B}from"node:path";function yh(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 Rh(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 oo(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 Rh(c)){if(e.truncated)return;let u=l.command??l.bash??l.prompt??l.powershell??c.powershell??"",f=yh({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=M(u),_=m?`${s}:${m}:${f}:${d}`:`${s}:${f}:${d}`,h=`${s}|${m}|${f}|${u}|attrs2`;e.push({kind:"HOOK",name:_,path:o,content_hash:M(h),origin:r,enabled:!0,trigger:"EVENT",attributes:{event:s,...m?{matcher:m}:{},action_kind:f,action_hash:d,...f!=="prompt"&&u.trim()?{command:Nc(u,e.home)}:{}}})}}}function so(e,t,n){if(!e.claimFile(t))return;let r=e.readJson(t,{});!r?.hooks||typeof r.hooks!="object"||oo(e,t,r.hooks,n)}var Fc=50;function io(e,t,n,r){if(!Ch(t))return{componentCount:0,expandTruncated:!1};let o=e.components.length,{expanded:s}=e.withPluginExpandCap(Fc,()=>{Me(e,{dir:B(t,"skills"),kind:"SKILL",origin:n,enabled:r,nested:"SKILL.md"}),Me(e,{dir:B(t,"commands"),kind:"COMMAND",origin:n,enabled:r,extensions:[".md"]}),Me(e,{dir:B(t,"agents"),kind:"SUBAGENT",origin:n,enabled:r,extensions:[".md"]})});so(e,B(t,"hooks","hooks.json"),n),so(e,B(t,"hooks.json"),n);let i=e.components.length-o,a=s>=Fc;return{componentCount:i,expandTruncated:a}}function ao(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 jc(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 l=Array.isArray(c)?c:[c],u=l[0]??{},f=s[a]===!0,m=a.includes("@")?a.split("@").slice(1).join("@"):"",d=typeof u.version=="string"?u.version:"",_=typeof u.scope=="string"?u.scope:"user",h=`plugin:${a}`,S=0,E=!1;for(let y of l)if(typeof y.installPath=="string"&&y.installPath.length>0){let F=io(e,y.installPath,h,f);S+=F.componentCount,E=E||F.expandTruncated}ao(e,{pluginKey:a,rowPath:i,enabled:f,scope:_,version:d||void 0,marketplace:m||void 0,componentCount:S,expandTruncated:E,contentHash:M(`${a}|${d}|${_}|${f}|${S}`)})}}function Ih(e){let t=e,n="";try{let r=Ah(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 kh=/^\d+$/;function Oh(e){let t=e.filter(n=>!kh.test(n.pluginId));return t.length>0?t:e}function $c(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),l=`plugin:${a}`,{componentCount:u,expandTruncated:f}=io(e,c,l,!0);ao(e,{pluginKey:a,rowPath:e.componentPath(c),enabled:!0,scope:"local",componentCount:u,expandTruncated:f,contentHash:M(`${a}|local|${u}`)});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:l,version:u}=Ih(c);i.push({pluginId:a.name,installPath:l,version:u})}for(let a of Oh(i)){if(e.truncated)break;let c=`${a.pluginId}@${s}`,l=`plugin:${c}`,{componentCount:u,expandTruncated:f}=io(e,a.installPath,l,!0);ao(e,{pluginKey:c,rowPath:e.componentPath(a.installPath),enabled:!0,scope:"cache",version:a.version||void 0,marketplace:s,componentCount:u,expandTruncated:f,contentHash:M(`${c}|${a.version}|${u}`)})}}}import{existsSync as Ph}from"node:fs";var bh=/(?<=^|[\s(,=:])(?:~|[A-Za-z]:)?[\\/][^\s,)]+/g,co="<path>",xh=new RegExp(`${co}(?:\\s+[A-Za-z.][^\\s,)]*[\\\\/][^\\s,)]*)+`,"g");function Rn(e){let t=e.replace(bh,co).replace(xh,co);return t.length>200?`${t.slice(0,200)}...`:t}var Kc=200,Bc=200,uo=16*1024,Gc=6,Th=new Set(["permissions","sandbox","enableAllProjectMcpServers","enabledMcpjsonServers","disabledMcpjsonServers","disableAllHooks","disableAutoMode","allowManagedHooksOnly","allowManagedPermissionRulesOnly","allowManagedMcpServersOnly","strictKnownMarketplaces","strictPluginOnlyCustomization","disableSideloadFlags","forceLoginMethod","forceLoginOrgUUID"]),wh=new Set(["type","additionalReadwritePaths","additionalReadonlyPaths","disableTmpWrite","enableSharedBuildCache","networkPolicy"]),Nh=new Set(["terminalAllowlist","mcpAllowlist","autoRun"]),Mh=new Set(["permissions"]),vh={claude:Th,cursor_sandbox:wh,cursor_permissions:Nh,cursor_cli:Mh},Lh=new Set(["allow","deny","ask"]);function ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Cn(e){return e.replace(/\\/g,"/")}function lo(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(r=>lo(r)).join(",")}]`;let t=e;return`{${Object.keys(t).filter(r=>t[r]!==void 0).sort().map(r=>`${JSON.stringify(r)}:${lo(t[r])}`).join(",")}}`}function Uh(e){return M(`${lo(e)}|settings1`)}function Yc(e){let t=Cn(e);if(t.endsWith(".claude/settings.json")||t.endsWith(".claude/settings.local.json"))return"claude";if(t.endsWith(".cursor/sandbox.json"))return"cursor_sandbox";if(t.endsWith(".cursor/permissions.json"))return"cursor_permissions";if(t.endsWith(".cursor/cli-config.json")||t.endsWith(".cursor/cli.json"))return"cursor_cli"}function Xc(e,t){if(e!=="claude")return{};let n=Cn(t);return n.endsWith("/.claude/remote-settings.json")?{profile:"claude",managedSource:"server"}:n.includes("/managed-settings.d/")&&n.endsWith(".json")?{profile:"claude",managedSource:"file_dropin"}:n.endsWith("/managed-settings.json")?{profile:"claude",managedSource:"file"}:{profile:"claude"}}function Zc(e){let t=Cn(e).replace(/\/+$/,"");return t.length<=1?"":t}function qc(e){return/^[A-Za-z]:/.test(e)||e.includes("\\")}function Dh(e,t){let n=Cn(e);if(n==="~"||n.startsWith("~/"))return n;let r=Zc(t);if(!r)return n;let o=n.slice(0,r.length);if(!(qc(t)?o.toLowerCase()===r.toLowerCase():o===r))return n;let i=n.slice(r.length);return i===""?"~":i.startsWith("/")?`~${i}`:n}var zc=new Map;function Hh(e){let t=zc.get(e);if(t!==void 0)return t;let n=Zc(e),r=null;if(n){let o=n.split("/").map(s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("[\\\\/]+");r=new RegExp(`(?<![\\w.-])${o}(?![\\w.-])`,qc(e)?"gi":"g")}return zc.set(e,r),r}function Fh(e,t){let n=Hh(t);return n?e.replace(n,"~"):e}function Vc(e,t){return e.length<=Bc?e:(t.truncated=!0,e.slice(0,Bc))}function Qc(e,t){return e.length<=Kc?e:(t.truncated=!0,e.slice(0,Kc))}function L(e,t,n,r){if(typeof e=="string"){if(t==="path")return Vc(Dh(e,n),r);let o=t==="rule"?Rn(e):e;return Vc(Fh(o,n),r)}if(typeof e=="number"||typeof e=="boolean"||e===null)return typeof e=="number"&&!Number.isFinite(e)?void 0:e;if(Array.isArray(e)){let o=Qc(e,r),s=[];for(let i of o){let a=L(i,t,n,r);a!==void 0&&s.push(a)}return s}if(ke(e)){let o={};for(let[s,i]of Object.entries(e)){let a=L(i,t,n,r);a!==void 0&&(o[s]=a)}return o}}function Wc(e,t,n){if(!ke(e))return L(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let i="plain";Lh.has(o)?i="rule":o==="additionalDirectories"&&(i="path");let a=L(s,i,t,n);a!==void 0&&(r[o]=a)}return r}function jh(e,t,n){if(!ke(e))return L(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){if(o==="files"&&Array.isArray(s)){let a=Qc(s,n);r[o]=a.map(c=>{if(!ke(c))return L(c,"plain",t,n);let l={};for(let[u,f]of Object.entries(c)){let d=L(f,u==="path"?"path":"plain",t,n);d!==void 0&&(l[u]=d)}return l});continue}let i=L(s,"plain",t,n);i!==void 0&&(r[o]=i)}return r}function $h(e,t,n){if(!ke(e))return L(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let a=L(s,o==="allowUnixSockets"?"path":"plain",t,n);a!==void 0&&(r[o]=a)}return r}function Kh(e,t,n){if(!ke(e))return L(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let i;o==="excludedCommands"?i=L(s,"rule",t,n):o==="filesystem"?i=L(s,"path",t,n):o==="network"?i=$h(s,t,n):o==="credentials"?i=jh(s,t,n):i=L(s,"plain",t,n),i!==void 0&&(r[o]=i)}return r}function Bh(e,t,n,r,o){return n==="claude"?e==="permissions"?Wc(t,r,o):e==="sandbox"?Kh(t,r,o):L(t,"plain",r,o):n==="cursor_sandbox"?e==="additionalReadwritePaths"||e==="additionalReadonlyPaths"?L(t,"path",r,o):L(t,"plain",r,o):n==="cursor_permissions"?e==="terminalAllowlist"||e==="mcpAllowlist"?L(t,"rule",r,o):L(t,"plain",r,o):e==="permissions"?Wc(t,r,o):L(t,"plain",r,o)}function Rt(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function fo(e,t){return e?`${e}.${t}`:t}function po(e,t,n,r){if(Array.isArray(e)){for(let o=e.length-1;o>=0;o-=1){let s=e[o];s!==null&&typeof s=="object"&&(t+1>=Gc?(e.splice(o,1),r.add(n)):po(s,t+1,n,r))}return}if(!(e===null||typeof e!="object"))for(let[o,s]of Object.entries(e))s!==null&&typeof s=="object"&&(t+1>=Gc?(delete e[o],r.add(fo(n,o))):po(s,t+1,fo(n,o),r))}function eu(e,t,n){if(Array.isArray(e)){e.length>0&&n.push({path:t,items:e,bytes:Rt(e)});return}if(!(e===null||typeof e!="object"))for(let[r,o]of Object.entries(e))eu(o,fo(t,r),n)}function Gh(e,t,n){let r=Rt(e);if(r<=uo)return;t.truncated=!0;let o=[];for(eu(e,"",o);r>uo;){let s;for(let c of o)c.items.length>0&&(!s||c.bytes>s.bytes)&&(s=c);if(!s)break;let i=s.items.pop(),a=Rt(i)+(s.items.length>0?1:0);s.bytes-=a,r-=a,n.add(s.path)}for(;Rt(e)>uo;){let s,i=-1;for(let[a,c]of Object.entries(e)){let l=Rt(c);l>i&&(s=a,i=l)}if(s===void 0)break;delete e[s],n.add(s)}}function zh(e,t,n){let r=vh[t],o={truncated:!1},s={},i=[];for(let c of Object.keys(e)){if(!r.has(c)){i.push(c);continue}let l=Bh(c,e[c],t,n,o);l!==void 0&&(s[c]=l)}i.sort();let a=new Set;return po(s,1,"",a),a.size>0&&(o.truncated=!0),Gh(s,o,a),{settings:s,keys_omitted:i,truncated:o.truncated,trimmed_paths:[...a].sort()}}function Jc(e,t){let n={kind:t.kind,name:"settings",path:e.componentPath(t.absPath),origin:t.origin,enabled:!0,content_hash:Uh(t.attributes),attributes:t.attributes};e.push(n)}function mo(e,t,n,r){if(!e.claimFile(t)||!Ph(t))return;let o=fs(t);if(!o.ok||!ke(o.value)){if(r.profile){let l=!o.ok&&o.reason==="read"?"read_error":"parse_error",u={profile:r.profile,[l]:!0};r.managedSource&&(u.managed_source=r.managedSource),Jc(e,{kind:r.kind,absPath:t,origin:n,attributes:u})}return}let s=o.value,i=s.hooks;if(ke(i)&&oo(e,t,i,n),!r.profile)return;let a=zh(s,r.profile,e.home),c={profile:r.profile,settings:a.settings,keys_omitted:a.keys_omitted};a.truncated&&(c.truncated=!0),a.trimmed_paths.length>0&&(c.trimmed_paths=a.trimmed_paths),r.managedSource&&(c.managed_source=r.managedSource),Jc(e,{kind:r.kind,absPath:t,origin:n,attributes:c})}function Wh(e,t){let{layout:n,levelDir:r,origin:o,includeMachineWide:s}=t;for(let i of n.skillRoots)Me(e,{dir:Je(r,i),kind:"SKILL",origin:o,enabled:!0,nested:"SKILL.md"});for(let i of n.dirs)Me(e,{dir:Je(r,i.dir),kind:i.kind,origin:o,enabled:!0,extensions:i.extensions});for(let i of n.memory){let a=hc(i.map(c=>Je(r,c)));a&&gn(e,{absolutePath:a,kind:"MEMORY",origin:o,enabled:!0,name:Vh(a)})}for(let i of Ri(n))mo(e,Je(r,i),o,{kind:"SETTINGS",profile:Yc(i)});for(let i of n.mcpJson??[])Dc(e,Je(r,i),o);for(let i of n.mcpToml??[])Hc(e,Je(r,i),o);if(s){if(n.managed){for(let i of Ft(n.managed,process.platform,e.home))if(i.toLowerCase().endsWith(".json")){let a=Xc(n.managed,i);mo(e,i,o,{kind:"MANAGED_SETTINGS",...a})}}n.plugins==="claude"?jc(e):n.plugins==="cursor"&&$c(e)}}function tu(e,t){try{let n=new mn(e,{pathMode:t.pathMode,maxEntries:t.maxEntries});for(let r of t.layouts)Wh(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 go(e,t,n={}){let r={},o=n.shouldWalk;if(o===void 0||o("user","")){let c=tu(t,{layouts:Object.values($e),levelDir:t,origin:"user",includeMachineWide:!0,pathMode:"home-relative",maxEntries:ge,scopeRef:""});c&&(r.user=c)}let s=n.inGitRepo===!0,i=null,a=n.launchCwd;if(a!==void 0){let c=Object.values(Ee),l=Jr({launchCwd:a,gitRoot:n.gitRoot,inGitRepo:s,remote:n.remote,home:t,hasProjectSpec:u=>Ai(c,u)});i=l.parentRel;for(let u of l.anchors){let f=Dr(u.dir);if(o!==void 0&&!o(u.scope,f))continue;let m=tu(t,{layouts:c,levelDir:u.dir,origin:u.scope,includeMachineWide:!1,pathMode:"tilde",maxEntries:Yr,scopeRef:f});m&&(r[u.scope]=m)}r.parent||(i=null)}return{scopes:r,parentRel:i,cwdInGitRepo:s}}function _o(e,t,n={}){let r=n.truncated===!0,o=gt(e),s=new Set(e.map(u=>W(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 f=W(u.path,u.name);c[f]!==u.content_hash&&a.push(u)}let l=[];if(!r){for(let u of Object.keys(c))if(!s.has(u)){let f=Qa(u);f&&l.push(f)}}return{hash:o,count:e.length,truncated:r,full:!1,upserts:a,removed:l,unchanged:a.length===0&&l.length===0}}var ru=2*1024*1024,Jh=new Set(["HOOK","MCP_SERVER","PLUGIN","SETTINGS","MANAGED_SETTINGS"]);function ho(e,t,n){let r=new Set(t.map(s=>W(s.path,s.name))),o=[];for(let s of e)s.text!==void 0&&(n.has(s.content_hash)||r.has(W(s.path,s.name))||o.push(s));return o}function So(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 nu(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function ou(e){if(e.text===void 0)return e;let{text:t,...n}=e;return n}function Eo(e,t=ru){let n=[],r=[];for(let u of e)Jh.has(u.kind)?n.push(u):r.push(u);r.sort((u,f)=>(u.text?.length??0)-(f.text?.length??0));let o=[...n,...r],s=[],i=2,a=0,c=0,l=[];for(let u of o){let f=s.length>0?1:0,m=nu(u)+f;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=ou(u),_=nu(d)+f;if(i+_<=t){s.push(d),i+=_,a+=1;continue}}c+=1}return{components:s,textDeferredCount:a,droppedCount:c,textHashesSent:l}}function yo(e,t){return t.size===0?e:e.map(n=>n.text===void 0||!t.has(n.content_hash)?n:ou(n))}var Yh=["user","cwd","repo","parent"];function Ro(e){let{collected:t,cacheFor:n,nowMs:r,maxBytes:o}=e,s=[];for(let P of Yh){let T=t.scopes[P];if(!T)continue;let H=n(P,T.scopeRef),j=H.components,J=_o(T.components,j,{forceFull:j===void 0,truncated:T.truncated}),Oe=new Set(H.textHashes),$=ho(T.components,J.upserts,Oe),U=yo([...J.upserts,...$],Oe);s.push({scope:P,walk:T,delta:J,outgoing:U,outgoingKeys:new Set(U.map(C=>W(C.path,C.name))),deliveredTextHashes:Oe,cachedComponents:j})}let i=s.flatMap(P=>P.outgoing),a=Eo(i,o),c=new Set(a.components.map(P=>W(P.path,P.name))),l=[],u=[],f=[],m=[],d=[],_=[],h=[];for(let P of s){let{scope:T,walk:H,delta:j}=P;_.push(...H.components),l.push(T);let J=a.components.filter(C=>P.outgoingKeys.has(W(C.path,C.name))),Oe=[...P.outgoingKeys].some(C=>!c.has(C)),$=j.truncated||Oe;$?f.push(T):j.full&&u.push(T),m.push(...J),!j.full&&!$&&d.push(...j.removed);let U=j.full?{}:{...P.cachedComponents??{}};if(!$)for(let C of j.removed)delete U[W(C.path,C.name)];for(let C of J)U[W(C.path,C.name)]=C.content_hash;h.push({scope:T,scopeRef:H.scopeRef,components:U,textHashes:So(P.deliveredTextHashes,J.filter(C=>C.text!==void 0).map(C=>C.content_hash),H.components),collectedAtMs:r,included:J.length>0||j.removed.length>0&&!$||j.full})}let S={user_spec_hash:gt(_),user_spec_count:_.length,user_spec_truncated:f.length>0};l.length>0&&(S.user_spec_scopes=l,S.user_spec_full_scopes=u,S.user_spec_truncated_scopes=f,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 F=t.scopes.parent;return F&&(S.user_spec_parent_scope_ref=F.scopeRef,t.parentRel&&(S.user_spec_parent_rel=t.parentRel)),{fields:S,scopes:h}}var At={cwd:"cwd_spec",repo:"repo_spec",parent:"parent_spec"};function An(e){return e==="cwd"||e==="repo"||e==="parent"}function Ct(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Co(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 su(e){return Xh(e)}function iu(e){return Zh(e)}function au(e){return qh(e)}function Xh(e){if(!Ct(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&(t[n]=r);return t}function Zh(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function Ao(e,t){if(!Ct(e))return;let n=e[t];return Co(n)?n:void 0}function qh(e){if(!Ct(e))return{};let t={};for(let[n,r]of Object.entries(e))Co(r)&&(t[n]=r);return t}function Io(e,t=20){let n=[];for(let[r,o]of Object.entries(e))Co(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 rS=["allow","deny","ask"];function kn(e){let t=D(e,{}),n=[];for(let r of rS)for(let o of t.permissions?.[r]??[])typeof o=="string"&&o.length>0&&n.push({key:Rn(o),mode:r});return{model:t.model??"",permissionKeys:n}}function oS(e){let{serverManaged:t,fileBased:n}=Wn(process.platform,e),r=kn(t);if(r.model||r.permissionKeys.length>0)return r;let o="",s=[];for(let i of n){let a=kn(i);a.model&&(o=a.model),s.push(...a.permissionKeys)}return{model:o,permissionKeys:s}}function sS(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 iS=10,aS="self-config-cache.json",uu=4;function Xe(){return A("EV_AI_HOOK_USER_SPEC")?.toLowerCase()==="off"}function cS(){return A("EV_AI_HOOK_CWD_SPEC")?.toLowerCase()==="off"}function uS(e,t=Date.now()){return e===void 0||!Number.isFinite(e)?!0:t-e>=tt}var lS={claude:["claude"],cursor:["agent","cursor-agent"],codex:["codex"]};async function dS(e,t=v){let n=lS[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(`
|
|
45
|
-
`)[0]??"").trim();return a||r(o+1)};return r(0)}function
|
|
46
|
-
`);return
|
|
47
|
-
`)}catch(n){let r=n instanceof Error?n.message:String(n);
|
|
48
|
-
${n}`}function
|
|
49
|
-
`);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
|
|
50
|
-
`,f=A("EV_AI_HOOK_DEBUG");f==="full"?p(`DEBUG envelope=${l}`):f==="1"&&p(`DEBUG summary=${jS(c,xo(u))}`);let m=process.argv.includes(xn),d=A("EV_AI_HOOK_SYNC")==="1";return on(n.runnerEvent,n.runnerPlatform)||m||d?GS(e,u,o):(await zS(e,u,o),!1)}import{createReadStream as VS}from"node:fs";import{stat as WS}from"node:fs/promises";import{basename as JS,resolve as YS}from"node:path";import{createInterface as XS}from"node:readline";var ZS=1024*1024;function qS(e){let t=e.replace(/\\/g,"/");return t.includes("/.claude/projects/")&&JS(t).endsWith(".jsonl")}async function xu(e){if(!e||!qS(e))return null;try{let t=YS(e),n=await WS(t);if(!n.isFile())return null;let r=Math.max(0,n.size-ZS),o=[],s=XS({input:VS(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 Tn(e){return{sessionId:e.sessionId,turnId:e.turnId,installationId:e.manifest.installationId,runnerPlatform:e.runnerPlatform,platformAgentId:e.platformAgentId,runnerEvent:e.runnerEvent}}function bt(e,t){return{gitRoot:e.manifest.gitRoot,...t?{home:t}:{}}}function To(e){return{gitRoot:e.manifest.gitRoot,inGitRepo:e.manifest.inGitRepo,runnerEvent:e.runnerEvent}}async function wu(e){let t=Date.now();await lE(e);let{gitRoot:n}=e.manifest;await No(e,n);let r=To(e);return{buildStartedAtMs:t,gitRoot:n,hookInput:fn(e.hookInput,e.manifest.manifest,r),envelopeFields:Tn(e),launchCwd:Vr(e.hookInput,r),home:eE()}}function Pu(e){try{return V(QS(e))}catch{return null}}function Nu(e){return e.startsWith("/")||/^[A-Za-z]:\//.test(e)}function Tu(e,t){let n=e.replaceAll("\\","/");if(!Nu(n))return null;let r=V(e),o=V(t),s=Pu(e)??r,i=Pu(t)??o;return s.startsWith(`${i}/`)?s.slice(i.length+1):r.startsWith(`${o}/`)?r.slice(o.length+1):null}function Mu(e,t,n){if(!e)return{repositorySourcePath:null,userSourcePath:null};let r=e.replaceAll("\\","/"),s=Tu(e,t)??(Nu(r)?null:r),i=Tu(e,n);return{repositorySourcePath:s,userSourcePath:i}}function Po(e,t,n,r,o){return vu(e,Mu(n,t.gitRoot,t.home),r,o)}function vu(e,{repositorySourcePath:t,userSourcePath:n},r,o){let s=t??n,i=s===null?null:o(s),a=i!==null&&s!==null?tE({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 tE(e){try{let t=e.inRepository?oE(e.platformAgentId,e.sourcePath):(0,O.installationRootExternalKey)(e.installationId,(0,O.userConfigRootFromPath)(e.sourcePath));return t?(0,O.buildComponentReference)({installationRootExternalKey:t,installableKind:e.installableKind,sourcePath:e.sourcePath,nativeKey:e.nativeKey}):void 0}catch{return}}function wo(e,t,n){return qe("tool_invoked",{...n,success:null,duration_ms:null,hook_input:t.hookInput},t.envelopeFields,Ze,e.manifest.collectorUrl,t.buildStartedAtMs,bt(e,t.home))}function nE(e){return ga(e.runnerEvent,e.runnerPlatform)?[]:wi(e.hookInput)}function rE(e,t){return wo(e,t,{})}var Lu=new Set([...Object.values(Ne),".github"]);function oE(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=>Lu.has(i));return s<0?null:`${r}:${o.slice(0,s+1).join("/")}`}var Uu=".codex/config.toml",sE=new Map([["claude_json_user",".claude.json"],["cursor_mcp_user",".cursor/mcp.json"],["codex_toml_user",Uu]]);function iE(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(h=>h.name.toLowerCase()===t.toLowerCase()),l=c?sE.get(c.source):o==="codex"?Uu:void 0,u=c?.sourcePath??l;if((c?.scope==="user"||l!==void 0)&&u)try{let h=(0,O.userConfigRootFromPath)(u);return(0,O.buildComponentReference)({installationRootExternalKey:(0,O.installationRootExternalKey)(r,h),installableKind:O.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),_=d.replaceAll("\\","/").split("/").at(-1);if(!(_===void 0||!Lu.has(_)))try{return(0,O.buildComponentReference)({installationRootExternalKey:n,installableKind:O.ComponentKind.INTERFACE,sourcePath:d,nativeKey:t})}catch{return}}function aE(...e){for(let t of e)if(t)return t;return null}function De(e,t,n){if(e.status==="fulfilled")return e.value;let r=e.reason instanceof Error?e.reason.message:String(e.reason);return p(`WARN: ${n} failed open: ${r}`),t}function cE(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 uE(e,t){return{runner_platform:e,config_scope:"user",...t?{operator:t}:{}}}var Ue=new Set,Ot=null;async function lE(e){if(Xe())return;let t=e.manifest.installationId,n=e.manifest.installationStorePath;if(Ue.has(t))return;if(!$r(n)){Ue.add(t);return}let r=st({sessionId:e.sessionId,hostname:$t()});if(tc(r)){if(Ot){await Ot;return}Ot=(async()=>{if(Ue.has(t)||!$r(n)){Ue.add(t);return}if(!Ls(n)){Ue.add(t);return}let o=!1;try{let s=Date.now(),{gitRoot:i}=e.manifest,a=String(e.runnerPlatform),{operatorResolved:c,fields:l}=await Du(e,r,nn(i),jr({gitRoot:i,installationStorePath:n,forceResend:!1,runnerPlatform:a})),u={...l,self_config:uE(a,c.operator),run_meta:{trigger:"cloud_identity_bootstrap"}};o=!!await qe("session_start",u,Tn(e),Ze,e.manifest.collectorUrl,s,bt(e)),o&&(c.commit(),Ue.add(t))}finally{Us(n)}})().finally(()=>{Ot=null}),await Ot}}async function No(e,t,n){try{e.platformAgentId=await ea(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);p(`WARN: derivePlatformAgentId failed open: ${o}`)}}async function Du(e,t,n,r){let[o,s,i,a,c]=await Promise.allSettled([n,hs(),Ma(t),Es(),r]),l=De(o,null,"gitSnapshot"),u=De(s,"","detectVirt"),f=De(i,null,"probeCloud"),m=De(a,{},"hostEnv"),d=De(c,{commit:()=>{}},"resolveOperatorForSend");return await No(e,e.manifest.gitRoot,l),{operatorResolved:d,fields:{identity:{host:$t(),context:t,virt:u||null,cloud:f,git:l},host_env:m,env_vars:va()}}}async function dE(e){let t=Date.now(),{gitRoot:n}=e.manifest,r=st({sessionId:e.sessionId,hostname:$t()}),o=String(e.runnerPlatform),s=To(e),i=Vr(e.hookInput,s),a=nn(n),c=Ru().catch(()=>({})),l=Xe()?Promise.resolve({commit:()=>{}}):jr({gitRoot:n,installationStorePath:e.manifest.installationStorePath,forceResend:!1,runnerPlatform:o}),u=Du(e,r,a,l),[f,m]=await Promise.allSettled([Pr(e.manifest.manifest,n,o),a.catch(()=>null).then(H=>lu(o,n,void 0,{installationStorePath:e.manifest.installationStorePath,gitRoot:n,launchCwd:i,inGitRepo:e.manifest.inGitRepo,remote:H?.remote??null}))]),{operatorResolved:d,fields:_}=await u,h=De(f,[],"mcpDeclared"),S=De(m,cE(o),"selfConfig"),E=S.config,y=R(e.hookInput,"model");y&&(E.model=y);let F={..._,mcp:{declared:h},self_config:E,run_meta:{trigger:e.hookSource||"startup"},hook_input:fn(e.hookInput,e.manifest.manifest,{...s,launchCwd:i})},P=await c;await qe("session_start",F,{...Tn(e),...P},Ze,e.manifest.collectorUrl,t,bt(e))&&(S.commit(),d.commit(),Ue.add(e.manifest.installationId))}async function fE(e){let t=Date.now(),[,n]=await Promise.all([No(e,e.manifest.gitRoot),e.runnerPlatform==="claude"?xu(R(e.hookInput,"transcript_path")):null]),r=e.runnerEvent.toLowerCase(),o=aE(R(e.hookInput,"status"),R(e.hookInput,"stop_reason"),R(e.hookInput,"reason"),pt(R(e.hookInput,"error")),r==="stop"?ie(e.hookInput,"is_interrupt")===!0?"interrupted":"completed":""),s=fn(e.hookInput,e.manifest.manifest,To(e));n&&(s.model=n),r!=="stopfailure"&&!ic(e.manifest.manifest)&&s.last_assistant_message===void 0&&(s.last_assistant_message=""),await qe("session_end",{status:o,...n?{model:n}:{},hook_input:s},Tn(e),Ze,e.manifest.collectorUrl,t,bt(e))}async function pE(e){let t=nE(e),n=oa(e.hookInput),r=ma(e.runnerEvent),o=r&&t.length===0&&n.length===0;if(t.length===0&&n.length===0&&!r)return;let s=await wu(e);await Promise.all([o?rE(e,s):void 0,t.length===0?void 0:mE(e,s,t),n.length===0?void 0:gE(e,s,n)])}function Hu(e,t,n,r){let o=r??Ti({skillId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home}),s=Po(e,t,o,O.ComponentKind.SKILL,O.nativeKeyForSkillPath);if(s.sourcePath!==null&&gr(s.sourcePath)?.toLowerCase()===n.toLowerCase())return s.componentReference===void 0?{}:{componentReference:s.componentReference};let i=r??sa({commandId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),a=Po(e,t,i,O.ComponentKind.COMMAND,O.nativeKeyForCommandPath);return a.nativeKey?.toLowerCase()!==n.toLowerCase()?{}:{commandName:a.nativeKey,...a.componentReference===void 0?{}:{componentReference:a.componentReference}}}function mE(e,t,n){let r=Xt(e.hookInput.tool_input);return Promise.all(n.map(o=>{let s=Hu(e,t,o,r);return wo(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 gE(e,t,n){return Promise.all(n.map(r=>{let o=ta({relativePath:r,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),s=Po(e,t,o,O.ComponentKind.RULE,O.nativeKeyForRulePath),i=s.nativeKey??ra(r);return wo(e,t,{tool_name:"Rule",rule_name:i,...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}var _E=[{kind:O.ComponentKind.SKILL,nativeKeyFn:O.nativeKeyForSkillPath},{kind:O.ComponentKind.RULE,nativeKeyFn:O.nativeKeyForRulePath},{kind:O.ComponentKind.COMMAND,nativeKeyFn:O.nativeKeyForCommandPath}];function hE(e,t,n){if(n.skillName===null&&n.ruleName===null&&n.commandName===null)return{};let r=hr(e.hookInput);if(r===null)return n.skillName===null?{}:Hu(e,t,n.skillName,null);let o=Mu(r,t.gitRoot,t.home);for(let s of _E){let i=vu(e,o,s.kind,s.nativeKeyFn);if(i.nativeKey!==null)return{...i.componentReference===void 0?{}:{componentReference:i.componentReference},...s.kind===O.ComponentKind.RULE?{ruleName:i.nativeKey}:{},...s.kind===O.ComponentKind.COMMAND?{commandName:i.nativeKey}:{}}}return{}}var SE=/mcp/i;function EE(e,t,n,r){let o=SE.test(e.runnerEvent);if(!r.hasMcpIdentity&&!o)return{};let s=o?Lc(t,n):yn(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 yE(e){let t=await wu(e),n=Ea(e.hookInput,e.runnerEvent),{toolName:r,skillName:o}=n,s=_r(e.hookInput),i=Mc(s,t.home),a=Ra(e.hookInput),c=_a(e.runnerEvent),l=c===!1?Ca(e.hookInput,e.runnerEvent):null,u=pt(R(e.hookInput,"mcp_server_name")),f=u!==null||r!==null&&sn(r)?await Pr(e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home).catch(()=>[]):[],{mcpServer:m,mcpTool:d}=Ia(r,f.map(H=>H.name),u??""),_=iE(r,m,e.platformAgentId,e.manifest.installationId,String(e.runnerPlatform),f,u),h=_===void 0?hE(e,t,n):{},S=m===null?null:da(m,e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home),E=EE(e,s,t.home,{hasMcpIdentity:!!m||!!d,declaredConfig:S}),y=_??h.componentReference,F=h.ruleName??n.ruleName,P=h.commandName??n.commandName,T=ya(e.hookInput);await qe("tool_invoked",{tool_name:r,skill_name:o,...F?{rule_name:F}:{},...P?{command_name:P}:{},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}:{},...T?{subagent_type:T}:{},hook_input:t.hookInput},t.envelopeFields,Ze,e.manifest.collectorUrl,t.buildStartedAtMs,bt(e,t.home))}async function Fu(e){switch(e.internalEvent){case"session_start":await dE(e);return;case"session_end":await fE(e);return;case"skill_invoked":await pE(e);return;case"tool_invoked":await yE(e);return;default:return}}import{mkdirSync as RE,readdirSync as CE,readFileSync as AE,statSync as ju,unlinkSync as IE,writeFileSync as kE}from"node:fs";import{homedir as wn}from"node:os";import{join as Mo}from"node:path";var OE="turns",$u=1440*60*1e3,bE=100,xE=new Set(["stop","stopfailure","sessionend"]);function vo(e=wn()){return Mo(ae(e),OE)}function Ku(e,t){return Mo(e,rt(t))}function PE(e,t=Date.now()){let n;try{n=CE(e)}catch{return}let r=0;for(let o of n){if(r>=bE)return;r+=1;try{let s=Mo(e,o);t-ju(s).mtimeMs>$u&&IE(s)}catch{}}}function TE(e,t,n=wn()){let r=e.trim(),o=t.trim();if(!(!r||!o))try{let s=vo(n);RE(s,{recursive:!0}),kE(Ku(s,r),o,"utf8")}catch{}}function wE(e,t=wn()){let n=e.trim();if(!n)return"";try{let r=Ku(vo(t),n);return Date.now()-ju(r).mtimeMs>$u?"":AE(r,"utf8").trim()}catch{return""}}function Bu(e,t,n,r=wn()){let o=t.trim(),s=xE.has(n.trim().toLowerCase());return s&&PE(vo(r)),o?(TE(e,o,r),o):s?wE(e,r):""}async function Gu(e,t,n,r){let o=t??await Yn(Gn),s=z(o,{}),i=await $s(process.cwd(),{sessionId:ft(s)});if(!i)return;r&&(i.collectorUrl=r);let a=ha(s,i.manifest.platform,n),c=Sa(e,a.runnerEvent);if(!c){p(`WARN: unknown hook event '${a.runnerEvent}'; skipping telemetry`);return}let l={hookInput:s,sessionId:a.sessionId,turnId:Bu(a.sessionId,a.turnId,a.runnerEvent),runnerEvent:a.runnerEvent,runnerPlatform:a.runnerPlatform,hookSource:a.hookSource,internalEvent:c,manifest:i,platformAgentId:i.platformAgentId};await Fu(l)}function NE(e){if(A("EV_AI_HOOK_SYNC")==="1")return!0;let{parsed:t,hookInput:n,runnerEvent:r}=e,o=dt(n,r,void 0,t.runner);return on(r,o)}function zu(e,t){let n=Dn(e),r=z(t,{}),o=n.event??Nr(r);return gs()||pa(n.runner,r,o)?null:{parsed:n,hookInput:r,runnerEvent:o}}async function Vu(e=process.argv.slice(2)){if(Ta(),e[0]===kt){try{await Pn(ot)}catch{}return 0}if(e[0]===xn){try{let t=await ot(),n=zu(e.slice(1),t);if(!n)return 0;let{parsed:r}=n;await Gu(r.event,t,r.runner,Tr(r))}catch(t){let n=t instanceof Error?t.message:String(t);p(`WARN: detached work failed open: ${n}`)}return 0}try{let t=await Yn(Gn),n=zu(e,t);if(!n)return 0;let{parsed:r,hookInput:o,runnerEvent:s}=n;if(!Pa(o,s,r.runner))return 0;NE(n)?await Gu(r.event,t,r.runner,Tr(r)):await bu(t,e)}catch(t){let n=t instanceof Error?t.message:String(t);p(`WARN: hook failed open: ${n}`)}finally{ls()}return 0}function Nn(){p("Usage: ev-ai-agent-hook <configure|install|migrate-to-plugin|update|uninstall|--version>"),p(" configure [--url <\u2026/{orgToken}/hook>]"),p(" (manifest only \u2014 pair with marketplace plugins)"),p(" install --url <\u2026/{orgToken}/hook>"),p(" [--delivery npx|binary|local] [--force]"),p(" [--no-claude] [--no-cursor] [--no-codex]"),p(" (fallback: merge hooks into .claude / .cursor / .codex configs)"),p(" (writes collector_url to shared manifest; hook commands use --runner only)"),p(" migrate-to-plugin"),p(" (strip ev-ai file hooks; keep collector manifest)"),p(" update (refresh binary pins from a local build; leaves hook configs alone)"),p(" uninstall"),p("Hook mode: --runner <platform> [--url <\u2026/hook>|--token <orgToken>] [event]"),p(" (--url/--token optional overrides; else collector_url from manifest)")}function Wu(e){return e.includes("--help")||e.includes("-h")}async function DE(e=process.argv.slice(2)){let[t,...n]=e;if(t===kt){try{await Pn(ot)}catch{}return 0}return t==="--version"||t==="-V"?(process.stdout.write(`${oe}
|
|
51
|
-
`),0):t==="configure"?
|
|
36
|
+
`.trim(),To=new Map;function ou(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 iu(e){return e.toLowerCase().includes("token")}function au(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=ou(r.key),s=ou(r.value);o&&s&&!iu(o)&&t.set(o,s)}return t}function dS(e){let t=fS(e);return t.search="mode=ro&immutable=1",t.href}function pS(e){try{let t=su("bun:sqlite");if(typeof t.Database!="function")return null;let n=new t.Database(e,{readonly:!0,create:!1});try{let r=n.query?.(er)??n.prepare(er);return au(r.all?.())}finally{n.close?.()}}catch{return null}}function mS(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 gS(e){try{return mS(()=>{let t=su("node:sqlite");if(typeof t.DatabaseSync!="function")return null;let n=new t.DatabaseSync(e,{readOnly:!0});try{return au(n.prepare(er).all?.())}finally{n.close?.()}})}catch{return null}}function hS(e){let t=new Map;for(let n of e.split(`
|
|
37
|
+
`)){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&&!iu(s)&&t.set(s,i)}return t}function _S(e){try{let t=cS("sqlite3",["-noheader","-batch","-separator"," ",e,er],{encoding:"utf8",timeout:2e3,maxBuffer:65536,windowsHide:!0,stdio:["ignore","pipe","ignore"]});return hS(t)}catch{return null}}function cu(e){let t=To.get(e);if(t)return t;if(!uS(e)){let o=new Map;return To.set(e,o),o}let n=dS(e),r=pS(n)??_S(n)??gS(n)??new Map;return To.set(e,r),r}var SS="cursorAuth/cachedEmail",ES="cursorAuth/stripeMembershipAuthId";function tr(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function yS(e=nr(),t=process.platform,n=process.env){let r=tr(n.VSCODE_PORTABLE);if(r)return Be(r,"user-data");let o=tr(n.VSCODE_APPDATA);if(o)return Be(o,"Cursor");switch(t){case"darwin":return Be(e,"Library","Application Support","Cursor");case"win32":return Be(tr(n.APPDATA)??Be(e,"AppData","Roaming"),"Cursor");default:return Be(tr(n.XDG_CONFIG_HOME)??Be(e,".config"),"Cursor")}}function RS(e=nr()){return Be(e,".cursor","cli-config.json")}function CS(e=nr(),t=process.platform,n=process.env){return Be(yS(e,t,n),"User","globalStorage","state.vscdb")}function Yt(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function AS(e){return typeof e.userId=="number"&&Number.isFinite(e.userId)?String(e.userId):Yt(e.userId)}function bS(e){return Yt(e.email)??Yt(e.authId)??AS(e)}function Po(e){let t=Yt(e.email),n=Yt(e.displayName),r=bS(e);return!r||de(n,t)?null:{git_user_name:null,git_user_email:null,platform_login:r,identity_source:"cursor_oauth"}}function xS(e){let n=oe(RS(e),{}).authInfo;return!n||typeof n!="object"?null:Po(n)}function kS(e,t,n){let r=CS(e,process.platform,t),o=eu(e),s=tu(o);if(nu(s,r,n))return Po({email:s?.email,authId:s?.auth_id});let i=cu(r),a=i.get(SS)??null,c=i.get(ES)??null;return ru(o,{read_at_ms:n,db_path:r,email:a,auth_id:c}),Po({email:a,authId:c})}function uu(e=nr(),t=process.env,n=Date.now()){return xS(e)??kS(e,t,n)}import{createHash as IS}from"node:crypto";import{resolve as OS}from"node:path";function q(e){return IS("sha256").update(e).digest("hex").slice(0,16)}function wo(e){return q(OS(e))}function he(e,t){return`${e}\0${t}`}function lu(e){let t=e.indexOf("\0");return t<=0?null:{path:e.slice(0,t),name:e.slice(t+1)}}function Xt(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(`
|
|
38
|
+
`);return q(n)}function PS(e,t,n="git_config",r=null){return q(`${e??""}|${t??""}|${r??""}|${n}`)}function wS(e){let t=null,n=null;for(let r of e.split(`
|
|
39
|
+
`)){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 NS(e,t=te){let n=await t("git",["config","--get-regexp","^user\\.(name|email)$"],2e3,{cwd:e});return wS(n)}function vS(e=process.env){let t=j(e.GIT_AUTHOR_NAME),n=j(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=j(e.GIT_COMMITTER_NAME),o=j(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=j(e.EMAIL);return s?{git_user_name:null,git_user_email:s,platform_login:null,identity_source:"git_env"}:null}function Ke(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 MS(e=process.env){let t=j(e.EV_AI_HOOK_OPERATOR_EMAIL),n=j(e.EV_AI_HOOK_OPERATOR_LOGIN),r=Ke(j(e.EV_AI_HOOK_OPERATOR_NAME),t,"configured",t??n);if(r)return r;let o=j(e.GITHUB_ACTOR)??j(e.GITHUB_TRIGGERING_ACTOR)??j(e.GITHUB_USER),s=Ke(o,null,"github",o);if(s)return s;let i=j(e.GITLAB_USER_LOGIN),a=j(e.GITLAB_USER_EMAIL),c=Ke(j(e.GITLAB_USER_NAME)??i,a,"gitlab",a??i);if(c)return c;let l=j(e.BUILD_REQUESTEDFOREMAIL),u=Ke(j(e.BUILD_REQUESTEDFOR),l,"azure_devops",l??j(e.BUILD_REQUESTEDFORID));if(u)return u;let d=j(e.BUILDKITE_BUILD_CREATOR_EMAIL),f=Ke(j(e.BUILDKITE_BUILD_CREATOR),d,"buildkite",d);if(f)return f;let p=j(e.BUILD_USER_EMAIL)??j(e.CHANGE_AUTHOR_EMAIL),g=Ke(j(e.BUILD_USER)??j(e.CHANGE_AUTHOR),p,"jenkins",p??j(e.BUILD_USER_ID));if(g)return g;let S=j(e.CIRCLE_USERNAME),A=Ke(S,null,"circleci",S);if(A)return A;let b=j(e.CODEBUILD_INITIATOR),I=Ke(b,null,"codebuild",b);if(I)return I;let T=j(e.DRONE_COMMIT_AUTHOR_EMAIL),v=j(e.DRONE_COMMIT_AUTHOR),O=Ke(v??j(e.DRONE_COMMIT_AUTHOR_NAME),T,"drone",T??v);if(O)return O;if(fu(e.CLAUDE_CODE_REMOTE)||fu(e.CURSOR_AGENT)){let K=j(e.CURSOR_USER_EMAIL);return{git_user_name:null,git_user_email:null,platform_login:K&&!de(null,K)?K:null,identity_source:"cloud"}}return null}function No(e){return!!((e.git_user_name??e.git_user_email)&&!de(e.git_user_name,e.git_user_email))}function j(e){if(e===void 0)return null;let t=e.trim();return t.length>0?t:null}function fu(e){if(e===void 0||e==="")return!1;let t=e.trim().toLowerCase();return t!=="0"&&t!=="false"&&t!=="no"}function LS(e,t,n){return e==="claude"?Vc(t):e==="cursor"?uu(t,n):e==="codex"?Zc(n,t):null}async function vo(e,t=te,n=process.env,r={}){let o=await NS(e,t),s=vS(n),i=No(o)?o:s&&No(s)?s:null,a=LS(r.runnerPlatform,r.home??TS(),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=MS(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:No(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 Mo(e){let{gitRoot:t,installationStorePath:n,forceResend:r}=e,o=e.exec??te,s=e.env??process.env,i=await vo(t,o,s,{runnerPlatform:e.runnerPlatform,home:e.home}),a=PS(i.git_user_name,i.git_user_email,i.identity_source,i.platform_login),l=(n?Zr(n):void 0)?.operator_identity_hash;if(!(r||l!==void 0&&l!==a||!l))return{commit:()=>{}};let p=n;return{operator:i,commit:()=>{p&&Bi(p,a,Pn())}}}function Lo(e){return e?!Zr(e)?.operator_identity_hash:!0}function du(e){return!0}import{existsSync as XR,readFileSync as qR}from"node:fs";import{homedir as Df}from"node:os";import{join as Nt,resolve as ZR}from"node:path";import{basename as BR,join as wt}from"node:path";import{dirname as Au,resolve as sr}from"node:path";import{existsSync as HS}from"node:fs";import{homedir as gu}from"node:os";import{relative as hu,resolve as Te,sep as ot}from"node:path";var US=["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"],DS=["prompt","tool_input","tool_response","last_assistant_message","command"],FS=new Set;function $S(e){switch(e?.toLowerCase()){case"beforemcpexecution":return new Set(["command"]);case"stopfailure":return new Set(["last_assistant_message"]);default:return FS}}function _u(e){return Su(e)==="allowlist"}function Su(e){return F("EV_AI_HOOK_CAPTURE_CONTENT")?.toLowerCase()==="off"||e.capture_hook_input==="allowlist"?"allowlist":e.capture_hook_input==="full"||e.debug===!0||F("EV_AI_HOOK_CAPTURE_FULL_INPUT")==="1"?"full":"content"}function jS(e){let t={};for(let n of US){let r=He(e,n);r!==void 0&&(t[n]=r)}return t}function rr(e,t){if(typeof e!="string"||e.length===0||!t)return null;let n=Te(e),r=Te(t),o=hu(r,n);return!o||o==="."?".":o.startsWith(`..${ot}`)||o===".."||Te(r,o)!==n?null:o.split(ot).join("/")}function Eu(e,t){let n=hu(Te(t),Te(e)).split(ot).join("/");return!n||n==="."?null:n===".."||n.startsWith("../")&&n.split("/").every(r=>r==="..")?n:null}function yu(e){return typeof e!="string"||e.length===0?null:Te(e).split(ot).join("/")}function BS(){let e=F("CURSOR_PROJECT_DIR");if(!e)return null;let t=Te(e);return HS(t)?t.split(ot).join("/"):null}function Uo(e,t){return rr(e,t)!==null}function KS(e,t){let n=Te(t??gu(),".cursor").split(ot).join("/");return Uo(e,n)}function GS(e,t,n){return t!==null&&Uo(e,t)?!0:t!==null&&KS(e,n.home)?!1:n.inGitRepo===!0&&n.gitRoot!==void 0&&Uo(e,n.gitRoot)?!0:t===null}function Ru(e,t){let n=yu(e.cwd);if(n!==null)return n;let r=Te(process.cwd()).split(ot).join("/"),o=BS();return GS(r,o,t)?r:o??r}function $o(e,t={}){return Ru(e,t)}function jo(e,t=gu()){let n=Te(t).split(ot).join("/").replace(/\/$/,"");return n.length<=1?e:e===n?"~":e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}function pu(e,t,n){let r=yu(n.launchCwd)??Ru(t,n);e.cwd=jo(r,n.home);let o=n.inGitRepo===!0&&n.gitRoot!==void 0?rr(r,n.gitRoot):null;o!==null&&(e.cwd_relative=o)}var Cu="\u2026[truncated]\u2026",Do=Buffer.byteLength(Cu,"utf8"),WS=8;function qt(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function mu(e,t){if(t<=0)return"";let n=Buffer.from(e,"utf8");return n.length<=t?e:n.subarray(0,t).toString("utf8")}function zS(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 VS(e,t){if(Buffer.byteLength(e,"utf8")<=t)return e;if(t<=Do)return mu(e,t);let r=t-Do,o=Math.ceil(r/2),s=Math.floor(r/2);return`${mu(e,o)}${Cu}${zS(e,s)}`}function Fo(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)=>{Fo(r,[...t,o],n)});return}if(e!==null&&typeof e=="object")for(let[r,o]of Object.entries(e))t.length===0&&r.startsWith("_")||Fo(o,[...t,r],n)}function JS(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 YS=256;function XS(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 qS(e,t,n){let r=Number.POSITIVE_INFINITY;for(let o=0;o<6;o++){let s=qt(e);if(s<=t)return;let i=[];Fo(e,[],i),i.sort((u,d)=>d.bytes-u.bytes);let a=i.filter(u=>u.bytes>n);if(a.length===0)return;let c=XS(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&&JS(e,u.path,VS(u.value,r))}}function ZS(e,t){let n=Math.max(0,t-YS),r=Object.keys(e).filter(s=>!s.startsWith("_")).map(s=>({key:s,bytes:qt(e[s])})).sort((s,i)=>i.bytes-s.bytes),o=[];for(let{key:s}of r){if(qt(e)<=n)break;delete e[s],o.push(s)}o.length>0&&(e._dropped_keys=o.slice(0,10))}function Ho(e,t){let n=qt(e);if(n<=t)return e;let r=structuredClone(e);return r._truncated=!0,r._original_bytes=n,qS(r,t,Do+WS),qt(r)>t&&ZS(r,t),r}function QS(e,t,n){let r=$S(n.runnerEvent);for(let o of DS){if(r.has(o))continue;let s=t[o];s!==void 0&&(e[o]=s)}}function or(e,t,n={}){let r=Su(t);if(r==="full"){let s={...e};return delete s.cwd,delete s.transcript_path,pu(s,e,n),Ho(s,jr)}let o=jS(e);return pu(o,e,n),r==="content"?(QS(o,e,n),Ho(o,jr)):Ho(o,ci)}function eE(e){return typeof e=="string"&&e.length>0}function Bo(e){let t=sr(e.home),n=sr(e.launchCwd),r=e.gitRoot?sr(e.gitRoot):null,o=new Set,s=[],i=null;e.inGitRepo&&eE(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&&rr(n,r)!==null;if(e.inGitRepo&&r!==null&&r!==t&&c){let l=Au(r);for(;;){let u=sr(l);if(u===t)break;let d=Au(u);if(d===u)break;if(e.hasProjectSpec(u)){s.push({scope:"parent",dir:u}),a=Eu(u,n);break}l=d}}return{anchors:s,parentRel:a}}import{existsSync as bu,readdirSync as tE,realpathSync as nE}from"node:fs";import{basename as rE,dirname as oE,relative as sE,resolve as iE,sep as aE}from"node:path";var Ko=400,ir=class{constructor(t,n={}){this.home=t;this.pathMode=n.pathMode??"home-relative",this.maxEntries=n.maxEntries??Ye}components=[];truncated=!1;pathMode;maxEntries;pluginExpandRemaining;seenRealpaths=new Set;componentPath(t){if(this.pathMode==="tilde"){let r=iE(t).split(aE).join("/");return jo(r,this.home)}let n=sE(this.home,t).replace(/\\/g,"/");return!n||n.startsWith("..")?`external/${q(oE(t))}/${rE(t)}`:n}claimFile(t){try{let n=nE(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(!bu(t))return[];try{return tE(t,{withFileTypes:!0})}catch{return[]}}readJson(t,n){if(bu(t))return oe(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 as,readFileSync as Py,statSync as wy}from"node:fs";import{basename as Fl,join as pt,relative as cs}from"node:path";var Ll=Ve(Ml());var Oy=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/.trash/**","**/.claude/cache/**","**/.codex/skills/.system/**","**/vendor/**","**/.yarn/**","**/coverage/**","**/.next/**"],Hl=Oy.map(e=>Ll.default.matcher(e,{dot:!0}));function Ty(e){return e===""?!1:Hl.some(t=>t(`${e}/`))}function Ul(e,t){if(t==="")return!1;if(e==="")return Ty(t);let n=e.replace(/\/+$/,"");return Hl.some(r=>r(`${n}/${t}/`)&&!r(`${n}/`))}var us=100*1024,Ny=4;function vy(e){return e.length<=us?e:`${e.slice(0,us-1)}\u2026`}function My(e){try{let t=Py(e),n=t.toString("utf8");return{hash:q(t),length:t.length,text:vy(n)}}catch{return null}}var Dl={HOOK:"EVENT",COMMAND:"EXPLICIT_INVOCATION",MEMORY:void 0,MCP_SERVER:void 0,PLUGIN:void 0,SKILL:"UNSPECIFIED",RULE:"UNSPECIFIED",SUBAGENT:"UNSPECIFIED"};function Ly(e){return e in Dl?Dl[e]:"UNSPECIFIED"}function Tt(e,t){if(!e.claimFile(t.absolutePath))return!1;let n=My(t.absolutePath);if(!n)return!1;let r=t.name??Fl(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=Ly(t.kind);return s&&(o.trigger=s),t.attributes&&(o.attributes=t.attributes),e.push(o)}function Hy(e,t,n){let r=cs(e,t).replace(/\\/g,"/");return!r||r.startsWith("..")?Fl(t).replace(/\.(md|mdc|toml)$/i,""):n?r.replace(/\.(md|mdc|toml)$/i,""):r}function mt(e,t){let{dir:n,kind:r,origin:o,enabled:s,nested:i,extensions:a,skipDirs:c}=t;ls(e,{walkRoot:n,currentDir:n,depth:0,kind:r,origin:o,enabled:s,nested:i,extensions:a,skipDirs:c})}function ls(e,t){let{walkRoot:n,currentDir:r,depth:o,kind:s,origin:i,enabled:a,nested:c,extensions:l,skipDirs:u}=t;if(!(o>Ny))for(let d of e.readEntries(r)){if(e.atGlobalCap){e.truncated=!0;return}if(e.pluginBudgetSpent)return;if(d.isDirectory()&&Ul(n.replace(/\\/g,"/"),cs(n,pt(r,d.name)).replace(/\\/g,"/"))||d.isDirectory()&&u?.includes(pt(r,d.name)))continue;if(c){if(!d.isDirectory())continue;let g=pt(r,d.name,c);if(as(g)){let S=cs(n,pt(r,d.name)).replace(/\\/g,"/");Tt(e,{absolutePath:g,kind:s,origin:i,enabled:a,name:S||d.name});continue}ls(e,{walkRoot:n,currentDir:pt(r,d.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l,skipDirs:u});continue}if(d.isDirectory()){ls(e,{walkRoot:n,currentDir:pt(r,d.name),depth:o+1,kind:s,origin:i,enabled:a,nested:c,extensions:l,skipDirs:u});continue}if(!d.isFile()||!l)continue;let f=d.name.toLowerCase();if(!l.some(g=>f.endsWith(g)))continue;let p=pt(r,d.name);Tt(e,{absolutePath:p,kind:s,origin:i,enabled:a,name:Hy(n,p,!0)})}}function $l(e){for(let t of e)if(as(t))try{if(wy(t).size>0)return t}catch{continue}return e.find(t=>as(t))}import{existsSync as dR,readFileSync as pR}from"node:fs";var pr=Ve(rt(),1);var Uy="<omitted>",Dy=["package_name","package_spec","package_version","package_version_source"],jl=100,Bl=120,mr=[{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"}],Kl=new Set(mr.map(e=>e.attr)),Fy=["enabled","disabled"],$y=["serverUrl","auth","bearer_token_env_var","default_tools_approval_mode","defaultToolsApprovalMode","env_vars","env_http_headers","http_headers"],jy=new Set(["type","command","url","args","env","envVars","headers",...Fy,...$y,...mr.map(e=>e.raw)]),By=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",...Dy,...Kl,...[...Kl].map(e=>`${e}_truncated`)]);function Gl(e,t){for(let n of t)jy.has(n)||By.has(n)||(e[n]=Uy)}var Ky=/^(authorization|auth|api[-_]?key|access[-_]?token|refresh[-_]?token|secret|password|passwd|token|bearer|client[-_]?secret|client[-_]?id|private[-_]?key|signing[-_]?key)$/i,Gy=/(?:^|[-_])(secret|password|passwd|token|api[-_]?key|private[-_]?key|signing[-_]?key|client[-_]?secret|client[-_]?id)(?:[-_]|$)/i,Wy=/^(sk-|ghp_|gho_|github_pat_|xox[baprs]-|AKIA|ASIA|AIza|ya29\.)/,zy=/^bearer(?:\s+|$)/i;function gr(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function Wl(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function fs(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=gr(e);return t?Object.keys(t).filter(n=>n.length>0):[]}function gt(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch{return e}}function Vy(e,t){if(e!==void 0&&/^https?:\/\//i.test(e)&&(0,pr.launchContainsCredentials)({kind:"url",url:e})||(0,pr.launchContainsCredentials)({kind:"command",command:e??"",arguments:t}))return!0;let n=on([...t]);return t.some((r,o)=>n[o]===r?!1:/^https?:\/\//i.test(r)?(0,pr.launchContainsCredentials)({kind:"url",url:r}):!0)}function zl(e,t,n){Vy(t,n)&&(e.launch_had_credentials=!0)}function Jy(e){return Wy.test(e)||zy.test(e)?"<redacted>":e.includes("://")?gt(e):e}function Vl(e){if(/^https?:\/\//i.test(e))return gt(e);let t=e.indexOf("=");return t>0?`${e.slice(0,t+1)}${Vl(e.slice(t+1))}`:Jy(e)}function Yy(e){let t=e.replace(/^-+/,"").split("=",1)[0]??"";return Ky.test(t)||Gy.test(t)}function on(e){let t=[],n=!1;for(let r of e){if(n){t.push("<redacted>"),n=!1;continue}if(Yy(r)){t.push("<redacted>"),n=!r.includes("=");continue}t.push(Vl(r))}return t}function Xy(e){let t=Wl(e);if(t.length===0)return;let n=[...new Set(t.map(r=>r.length>Bl?r.slice(0,Bl):r))].sort();if(n.length!==0)return n.length>jl?{names:n.slice(0,jl),truncated:!0}:{names:n,truncated:!1}}function qy(e){let t=gr(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 Jl(e,t){let n=new Set;for(let{raw:r,attr:o}of mr){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=Xy(s);i&&(e[o]=i.names,i.truncated&&(e[`${o}_truncated`]=!0),n.add(o))}}function Yl(e,t){let n=gr(e),r={transport:t};if(!n)return r;Gl(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=Wl(n.args);a&&(r.command_or_url=gt(a));let l=on(c);l.length>0&&(r.args=l),zl(r,a,c);let u=qy(n.env_http_headers),d=[...new Set([...fs(n.env),...fs(n.envVars),...fs(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();d.length>0&&(r.env_var_names=d),u.headers.length>0&&(r.env_http_header_names=[...new Set(u.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 f=typeof n.auth=="string"?n.auth:void 0;f&&(r.auth=f);let p=typeof n.bearer_token_env_var=="string"?n.bearer_token_env_var:void 0;p&&(r.bearer_token_env_var=p);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),Jl(r,n),r}function Xl(e){let t=gr(e);return t?t.enabled===!1?!1:t.disabled!==!0:!0}function ms(e,t,n=!0){let r=Object.keys(t).sort().map(o=>[o,t[o]??null]);return q(JSON.stringify({name:e,attributes:r,enabled:n}))}function Pt(e){let t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function rn(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 ps(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(true|false)\\s*$`,"m").exec(e);if(n?.[1])return n[1]==="true"}function ds(e,t){let n=new RegExp(`^\\s*${t}\\s*=\\s*(.+)$`,"m").exec(e);if(!n?.[1])return;let r=Pt(n[1]);return r.length>0?r:void 0}function Zy(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],Pt(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(`
|
|
40
|
+
${e}`);return s?.[1]&&r(s[1]),n}function ql(e){return ps(e,"enabled")===!1?!1:ps(e,"disabled")!==!0}function Qy(e,t){let n={};for(let{raw:r,attr:o}of mr){if(o==="auto_approve"){let i=ps(t,r);if(i!==void 0){n[r]=i;continue}}let s=rn(t,r);s.length>0&&(n[r]=s)}Jl(e,n)}var eR=/^\s*([A-Za-z_][A-Za-z0-9_-]*)\s*[.=]/,tR=/^\[[^\]]*\.([A-Za-z_][A-Za-z0-9_-]*)\]\s*$/gm;function nR(e){let t=new Set,n=e.search(/^\[/m),r=n===-1?e:e.slice(0,n);for(let o of r.split(`
|
|
41
|
+
`)){let s=eR.exec(o);s?.[1]&&t.add(s[1])}for(let o of e.matchAll(tR))o[1]&&t.add(o[1]);return[...t]}function Zl(e,t){let n={transport:t};Gl(n,nR(e));let r=/^\s*command\s*=\s*(.+)$/m.exec(e),o=/^\s*url\s*=\s*(.+)$/m.exec(e),s=r?Pt(r[1]??""):void 0,i=o?Pt(o[1]??""):void 0,a=s!==void 0&&s.length>0?s:i,c=rn(e,"args");a&&(n.command_or_url=gt(a));let l=on(c);l.length>0&&(n.args=l),zl(n,a,c);let u=new Set;for(let b of e.split(`
|
|
42
|
+
`)){let I=/^\s*env\.([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(b);I?.[1]&&u.add(I[1])}let d=/^\s*env\s*=\s*\{([^}]*)\}/m.exec(e);if(d?.[1])for(let b of d[1].split(",")){let I=/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(b);I?.[1]&&u.add(I[1])}let f=/(?:^|\n)\[[^\]]*env\]\s*\n([\s\S]*?)(?=\n\[|$)/.exec(`
|
|
43
|
+
${e}`);if(f?.[1])for(let b of f[1].split(`
|
|
44
|
+
`)){let I=/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(b);I?.[1]&&u.add(I[1])}for(let b of rn(e,"env_vars"))u.add(b);let p=Zy(e,"env_http_headers");for(let[,b]of p)b.length>0&&u.add(b);let g=ds(e,"bearer_token_env_var");g&&(u.add(g),n.bearer_token_env_var=g),u.size>0&&(n.env_var_names=[...u].sort()),p.length>0&&(n.env_http_header_names=[...new Set(p.map(([b])=>b))].sort()),(/^\s*(?:http_|env_http_)?headers\s*=/m.test(e)||/(?:^|\n)\[[^\]]*headers\]\s*(?:\n|$)/.test(e))&&(n.headers_present=!0);let S=ds(e,"auth");S&&(n.auth=S);let A=ds(e,"default_tools_approval_mode");return A&&(n.default_tools_approval_mode=A),Qy(n,e),n}var Ne=Ve(rt(),1);import{createHash as iR}from"node:crypto";import{join as sn}from"node:path";var rR=300,oR=256;function Ql(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 hr(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 ef(e,t){return e.length<=t?e:`${e.slice(0,t-1)}\u2026`}function sR(e){return ef(e,rR)}function tf(e,t){let n=Ql(e.trim(),t),r=hr(n);if(r.length===0)return"";let[o,...s]=r,i=gt(o),a=on(s);return sR([i,...a].join(" "))}function nf(e,t){if(typeof e!="string")return null;let n=Ql(e.trim(),t),r=hr(n)[0];if(!r)return null;let o=gt(r);return o.length===0?null:ef(o,oR)}function aR(e,t){if(t!==null)return{package_version:t,package_version_source:"npx_cache"};let n=(0,Ne.pinnedPackageVersionFromSpec)(e);return n===void 0?{}:{package_version:n,package_version_source:"declared_pin"}}function cR(e){let t=[...e].sort((n,r)=>n.localeCompare(r,"en")).join(`
|
|
45
|
+
`);return iR("sha512").update(t).digest("hex").slice(0,16)}function uR(e){let t=process.platform==="win32"?sn(F("LOCALAPPDATA")??e,"npm-cache"):sn(e,".npm"),n=F("npm_config_cache")??F("NPM_CONFIG_CACHE");return n===void 0||n===t?[t]:[n,t]}function rf(e){return typeof e=="string"&&e.length>0&&e.length<=Ne.PACKAGE_FIELD_MAX?e:null}function lR(e,t,n){let r=cR(e);for(let o of uR(n)){let s=sn(o,"_npx",r),i=oe(sn(s,"node_modules",...t.split("/"),"package.json"),{}),a=rf(i.version);if(a!==null)return a;let c=oe(sn(s,"package-lock.json"),{}),l=rf(c.packages?.[`node_modules/${t}`]?.version);if(l!==null)return l}return null}function fR(e){return e.length<=Ne.PACKAGE_FIELD_MAX?e:`${e.slice(0,Ne.PACKAGE_FIELD_MAX-1)}\u2026`}function gs(e,t,n){if(typeof e!="string"||e.length===0)return null;let r=(0,Ne.npxPackageSpecs)(e,t??[]),o=r[0];if(o===void 0)return null;let s=(0,Ne.packageNameFromSpec)(o);return s===null?null:{package_name:s,package_spec:fR(o),...aR(o,lR(r,s,n))}}function of(e,t){if(typeof e!="string"||e.length===0)return null;let[n,...r]=hr(e.trim());return n===void 0?null:gs(n,r,t)}function _r(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 gs(typeof n.command=="string"?n.command:null,r,t)}function sf(e,t){let n=/^\s*command\s*=\s*(.+)$/m.exec(e);return n===null?null:gs(Pt(n[1]??""),rn(e,"args"),t)}function mR(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 af(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=mR(a),l=Yl(a,c);Object.assign(l,_r(a,e.home)??{});let u=Xl(a);e.push({kind:"MCP_SERVER",name:i,path:s,content_hash:ms(i,l,u),origin:n,enabled:u,attributes:l})}}function cf(e,t,n){if(!dR(t)||!e.claimFile(t))return;let r;try{r=pR(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),d="unknown";/^\s*url\s*=/m.test(u)?d="http":/^\s*command\s*=/m.test(u)&&(d="stdio");let f=Zl(u,d);Object.assign(f,sf(u,e.home)??{});let p=ql(u);e.push({kind:"MCP_SERVER",name:a,path:o,content_hash:ms(a,f,p),origin:n,enabled:p,attributes:f})}}import{existsSync as _R,readdirSync as SR}from"node:fs";import{join as ue}from"node:path";function gR(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 hR(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 hs(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 hR(c)){if(e.truncated)return;let u=l.command??l.bash??l.prompt??l.powershell??c.powershell??"",d=gR({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}),f=typeof c.matcher=="string"?c.matcher:"",p=q(u),g=f?`${s}:${f}:${d}:${p}`:`${s}:${d}:${p}`,S=`${s}|${f}|${d}|${u}|attrs2`;e.push({kind:"HOOK",name:g,path:o,content_hash:q(S),origin:r,enabled:!0,trigger:"EVENT",attributes:{event:s,...f?{matcher:f}:{},action_kind:d,action_hash:p,...d!=="prompt"&&u.trim()?{command:tf(u,e.home)}:{}}})}}}function _s(e,t,n){if(!e.claimFile(t))return;let r=e.readJson(t,{});!r?.hooks||typeof r.hooks!="object"||hs(e,t,r.hooks,n)}var uf=50;function an(e,t,n,r){if(!_R(t))return{componentCount:0,expandTruncated:!1};let o=e.components.length,{expanded:s}=e.withPluginExpandCap(uf,()=>{mt(e,{dir:ue(t,"skills"),kind:"SKILL",origin:n,enabled:r,nested:"SKILL.md"}),mt(e,{dir:ue(t,"commands"),kind:"COMMAND",origin:n,enabled:r,extensions:[".md"]}),mt(e,{dir:ue(t,"agents"),kind:"SUBAGENT",origin:n,enabled:r,extensions:[".md"]})});_s(e,ue(t,"hooks","hooks.json"),n),_s(e,ue(t,"hooks.json"),n);let i=e.components.length-o,a=s>=uf;return{componentCount:i,expandTruncated:a}}function cn(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 lf(e){let t=ue(e.home,".claude/plugins/installed_plugins.json"),n=e.readJson(t,{});if(!n)return;let r=n.plugins??{},s=e.readJson(ue(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]??{},d=s[a]===!0,f=a.includes("@")?a.split("@").slice(1).join("@"):"",p=typeof u.version=="string"?u.version:"",g=typeof u.scope=="string"?u.scope:"user",S=`plugin:${a}`,A=0,b=!1;for(let I of l)if(typeof I.installPath=="string"&&I.installPath.length>0){let T=an(e,I.installPath,S,d);A+=T.componentCount,b=b||T.expandTruncated}cn(e,{pluginKey:a,rowPath:i,enabled:d,scope:g,version:p||void 0,marketplace:f||void 0,componentCount:A,expandTruncated:b,contentHash:q(`${a}|${p}|${g}|${d}|${A}`)})}}function ER(e){let t=e,n="";try{let r=SR(e,{withFileTypes:!0}).filter(o=>o.isDirectory()).map(o=>o.name);if(r.length===1&&r[0])t=ue(e,r[0]),n=r[0];else if(r.length>1){let o=[...r].sort(),s=o[o.length-1];s&&(t=ue(e,s),n=s)}}catch{}return{installPath:t,version:n}}var yR=/^\d+$/;function RR(e){let t=e.filter(n=>!yR.test(n.pluginId));return t.length>0?t:e}function ff(e){let t=[{base:ue(e.home,".cursor/plugins/local"),scope:"local"},{base:ue(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=ue(n,o.name),l=`plugin:${a}`,{componentCount:u,expandTruncated:d}=an(e,c,l,!0);cn(e,{pluginKey:a,rowPath:e.componentPath(c),enabled:!0,scope:"local",componentCount:u,expandTruncated:d,contentHash:q(`${a}|local|${u}`)});continue}let s=o.name,i=[];for(let a of e.readEntries(ue(n,s))){if(!a.isDirectory())continue;let c=ue(n,s,a.name),{installPath:l,version:u}=ER(c);i.push({pluginId:a.name,installPath:l,version:u})}for(let a of RR(i)){if(e.truncated)break;let c=`${a.pluginId}@${s}`,l=`plugin:${c}`,{componentCount:u,expandTruncated:d}=an(e,a.installPath,l,!0);cn(e,{pluginKey:c,rowPath:e.componentPath(a.installPath),enabled:!0,scope:"cache",version:a.version||void 0,marketplace:s,componentCount:u,expandTruncated:d,contentHash:q(`${c}|${a.version}|${u}`)})}}}import{existsSync as bR}from"node:fs";var CR=/(?<=^|[\s(,=:])(?:~|[A-Za-z]:)?[\\/][^\s,)]+/g,Ss="<path>",AR=new RegExp(`${Ss}(?:\\s+[A-Za-z.][^\\s,)]*[\\\\/][^\\s,)]*)+`,"g");function Sr(e){let t=e.replace(CR,Ss).replace(AR,Ss);return t.length>200?`${t.slice(0,200)}...`:t}var df=200,pf=200,Es=16*1024,mf=6,xR=new Set(["permissions","sandbox","enableAllProjectMcpServers","enabledMcpjsonServers","disabledMcpjsonServers","disableAllHooks","disableAutoMode","allowManagedHooksOnly","allowManagedPermissionRulesOnly","allowManagedMcpServersOnly","strictKnownMarketplaces","strictPluginOnlyCustomization","disableSideloadFlags","forceLoginMethod","forceLoginOrgUUID"]),kR=new Set(["type","additionalReadwritePaths","additionalReadonlyPaths","disableTmpWrite","enableSharedBuildCache","networkPolicy"]),IR=new Set(["terminalAllowlist","mcpAllowlist","autoRun"]),OR=new Set(["permissions"]),TR={claude:xR,cursor_sandbox:kR,cursor_permissions:IR,cursor_cli:OR},PR=new Set(["allow","deny","ask"]);function st(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Er(e){return e.replace(/\\/g,"/")}function ys(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(r=>ys(r)).join(",")}]`;let t=e;return`{${Object.keys(t).filter(r=>t[r]!==void 0).sort().map(r=>`${JSON.stringify(r)}:${ys(t[r])}`).join(",")}}`}function wR(e){return q(`${ys(e)}|settings1`)}function Ef(e){let t=Er(e);if(t.endsWith(".claude/settings.json")||t.endsWith(".claude/settings.local.json"))return"claude";if(t.endsWith(".cursor/sandbox.json"))return"cursor_sandbox";if(t.endsWith(".cursor/permissions.json"))return"cursor_permissions";if(t.endsWith(".cursor/cli-config.json")||t.endsWith(".cursor/cli.json"))return"cursor_cli"}function yf(e,t){if(e!=="claude")return{};let n=Er(t);return n.endsWith("/.claude/remote-settings.json")?{profile:"claude",managedSource:"server"}:n.includes("/managed-settings.d/")&&n.endsWith(".json")?{profile:"claude",managedSource:"file_dropin"}:n.endsWith("/managed-settings.json")?{profile:"claude",managedSource:"file"}:{profile:"claude"}}function Rf(e){let t=Er(e).replace(/\/+$/,"");return t.length<=1?"":t}function Cf(e){return/^[A-Za-z]:/.test(e)||e.includes("\\")}function NR(e,t){let n=Er(e);if(n==="~"||n.startsWith("~/"))return n;let r=Rf(t);if(!r)return n;let o=n.slice(0,r.length);if(!(Cf(t)?o.toLowerCase()===r.toLowerCase():o===r))return n;let i=n.slice(r.length);return i===""?"~":i.startsWith("/")?`~${i}`:n}var gf=new Map;function vR(e){let t=gf.get(e);if(t!==void 0)return t;let n=Rf(e),r=null;if(n){let o=n.split("/").map(s=>s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("[\\\\/]+");r=new RegExp(`(?<![\\w.-])${o}(?![\\w.-])`,Cf(e)?"gi":"g")}return gf.set(e,r),r}function MR(e,t){let n=vR(t);return n?e.replace(n,"~"):e}function hf(e,t){return e.length<=pf?e:(t.truncated=!0,e.slice(0,pf))}function Af(e,t){return e.length<=df?e:(t.truncated=!0,e.slice(0,df))}function ne(e,t,n,r){if(typeof e=="string"){if(t==="path")return hf(NR(e,n),r);let o=t==="rule"?Sr(e):e;return hf(MR(o,n),r)}if(typeof e=="number"||typeof e=="boolean"||e===null)return typeof e=="number"&&!Number.isFinite(e)?void 0:e;if(Array.isArray(e)){let o=Af(e,r),s=[];for(let i of o){let a=ne(i,t,n,r);a!==void 0&&s.push(a)}return s}if(st(e)){let o={};for(let[s,i]of Object.entries(e)){let a=ne(i,t,n,r);a!==void 0&&(o[s]=a)}return o}}function _f(e,t,n){if(!st(e))return ne(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let i="plain";PR.has(o)?i="rule":o==="additionalDirectories"&&(i="path");let a=ne(s,i,t,n);a!==void 0&&(r[o]=a)}return r}function LR(e,t,n){if(!st(e))return ne(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){if(o==="files"&&Array.isArray(s)){let a=Af(s,n);r[o]=a.map(c=>{if(!st(c))return ne(c,"plain",t,n);let l={};for(let[u,d]of Object.entries(c)){let p=ne(d,u==="path"?"path":"plain",t,n);p!==void 0&&(l[u]=p)}return l});continue}let i=ne(s,"plain",t,n);i!==void 0&&(r[o]=i)}return r}function HR(e,t,n){if(!st(e))return ne(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let a=ne(s,o==="allowUnixSockets"?"path":"plain",t,n);a!==void 0&&(r[o]=a)}return r}function UR(e,t,n){if(!st(e))return ne(e,"plain",t,n);let r={};for(let[o,s]of Object.entries(e)){let i;o==="excludedCommands"?i=ne(s,"rule",t,n):o==="filesystem"?i=ne(s,"path",t,n):o==="network"?i=HR(s,t,n):o==="credentials"?i=LR(s,t,n):i=ne(s,"plain",t,n),i!==void 0&&(r[o]=i)}return r}function DR(e,t,n,r,o){return n==="claude"?e==="permissions"?_f(t,r,o):e==="sandbox"?UR(t,r,o):ne(t,"plain",r,o):n==="cursor_sandbox"?e==="additionalReadwritePaths"||e==="additionalReadonlyPaths"?ne(t,"path",r,o):ne(t,"plain",r,o):n==="cursor_permissions"?e==="terminalAllowlist"||e==="mcpAllowlist"?ne(t,"rule",r,o):ne(t,"plain",r,o):e==="permissions"?_f(t,r,o):ne(t,"plain",r,o)}function un(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function Rs(e,t){return e?`${e}.${t}`:t}function Cs(e,t,n,r){if(Array.isArray(e)){for(let o=e.length-1;o>=0;o-=1){let s=e[o];s!==null&&typeof s=="object"&&(t+1>=mf?(e.splice(o,1),r.add(n)):Cs(s,t+1,n,r))}return}if(!(e===null||typeof e!="object"))for(let[o,s]of Object.entries(e))s!==null&&typeof s=="object"&&(t+1>=mf?(delete e[o],r.add(Rs(n,o))):Cs(s,t+1,Rs(n,o),r))}function bf(e,t,n){if(Array.isArray(e)){e.length>0&&n.push({path:t,items:e,bytes:un(e)});return}if(!(e===null||typeof e!="object"))for(let[r,o]of Object.entries(e))bf(o,Rs(t,r),n)}function FR(e,t,n){let r=un(e);if(r<=Es)return;t.truncated=!0;let o=[];for(bf(e,"",o);r>Es;){let s;for(let c of o)c.items.length>0&&(!s||c.bytes>s.bytes)&&(s=c);if(!s)break;let i=s.items.pop(),a=un(i)+(s.items.length>0?1:0);s.bytes-=a,r-=a,n.add(s.path)}for(;un(e)>Es;){let s,i=-1;for(let[a,c]of Object.entries(e)){let l=un(c);l>i&&(s=a,i=l)}if(s===void 0)break;delete e[s],n.add(s)}}function $R(e,t,n){let r=TR[t],o={truncated:!1},s={},i=[];for(let c of Object.keys(e)){if(!r.has(c)){i.push(c);continue}let l=DR(c,e[c],t,n,o);l!==void 0&&(s[c]=l)}i.sort();let a=new Set;return Cs(s,1,"",a),a.size>0&&(o.truncated=!0),FR(s,o,a),{settings:s,keys_omitted:i,truncated:o.truncated,trimmed_paths:[...a].sort()}}function Sf(e,t){let n={kind:t.kind,name:"settings",path:e.componentPath(t.absPath),origin:t.origin,enabled:!0,content_hash:wR(t.attributes),attributes:t.attributes};e.push(n)}function As(e,t,n,r){if(!e.claimFile(t)||!bR(t))return;let o=yi(t);if(!o.ok||!st(o.value)){if(r.profile){let l=!o.ok&&o.reason==="read"?"read_error":"parse_error",u={profile:r.profile,[l]:!0};r.managedSource&&(u.managed_source=r.managedSource),Sf(e,{kind:r.kind,absPath:t,origin:n,attributes:u})}return}let s=o.value,i=s.hooks;if(st(i)&&hs(e,t,i,n),!r.profile)return;let a=$R(s,r.profile,e.home),c={profile:r.profile,settings:a.settings,keys_omitted:a.keys_omitted};a.truncated&&(c.truncated=!0),a.trimmed_paths.length>0&&(c.trimmed_paths=a.trimmed_paths),r.managedSource&&(c.managed_source=r.managedSource),Sf(e,{kind:r.kind,absPath:t,origin:n,attributes:c})}import{existsSync as jR}from"node:fs";import{join as ve}from"node:path";var xf=".claude/skills/synced",kf=".claude/plugins/synced";function If(e){return[ve(e,xf),ve(e,kf)]}function yr(e){return typeof e=="string"&&e.length>0?e:void 0}function Of(e){let t=ve(e.home,xf);for(let n of e.readEntries(t)){if(!n.isDirectory()||n.name.startsWith("."))continue;let r=ve(t,n.name),o=e.readJson(ve(r,"manifest.json"),{}),s=new Map((o?.skills??[]).flatMap(i=>i.name?[[i.name,i]]:[]));for(let i of e.readEntries(r)){if(e.atGlobalCap){e.truncated=!0;return}let a=ve(r,i.name,"SKILL.md");if(!i.isDirectory()||!jR(a))continue;let c=s.get(i.name),l=yr(c?.source),u=yr(c?.creatorType);Tt(e,{absolutePath:a,kind:"SKILL",origin:"user",enabled:!0,name:i.name,attributes:{scope:"synced",...l?{source:l}:{},...u?{creator_type:u}:{}}})}}}function Tf(e){let t=ve(e.home,kf);for(let n of e.readEntries(t)){if(!n.isDirectory()||n.name.startsWith("."))continue;let r=ve(t,n.name),o=e.readJson(ve(r,"manifest.json"),{}),s=new Map((o?.plugins??[]).flatMap(i=>i.name?[[i.name,i]]:[]));for(let i of e.readEntries(r)){if(e.truncated)return;if(!i.isDirectory()||i.name.startsWith("."))continue;let a=s.get(i.name),c=yr(a?.marketplaceName),l=yr(a?.version),u=c?`${i.name}@${c}`:i.name,d=ve(r,i.name),{componentCount:f,expandTruncated:p}=an(e,d,`plugin:${u}`,!0);cn(e,{pluginKey:u,rowPath:e.componentPath(d),enabled:!0,scope:"synced",version:l,marketplace:c,componentCount:f,expandTruncated:p,contentHash:q(`${u}|${l??""}|synced|${f}`)})}}}function KR(e,t){let{layout:n,levelDir:r,origin:o,includeMachineWide:s}=t;for(let i of n.skillRoots)mt(e,{dir:wt(r,i),kind:"SKILL",origin:o,enabled:!0,nested:"SKILL.md",skipDirs:If(e.home)});for(let i of n.dirs)mt(e,{dir:wt(r,i.dir),kind:i.kind,origin:o,enabled:!0,extensions:i.extensions});for(let i of n.memory){let a=$l(i.map(c=>wt(r,c)));a&&Tt(e,{absolutePath:a,kind:"MEMORY",origin:o,enabled:!0,name:BR(a)})}for(let i of Ta(n))As(e,wt(r,i),o,{kind:"SETTINGS",profile:Ef(i)});for(let i of n.mcpJson??[])af(e,wt(r,i),o);for(let i of n.mcpToml??[])cf(e,wt(r,i),o);if(s){if(n.managed){for(let i of Tn(n.managed,process.platform,e.home))if(i.toLowerCase().endsWith(".json")){let a=yf(n.managed,i);As(e,i,o,{kind:"MANAGED_SETTINGS",...a})}}n.plugins==="claude"?(lf(e),Tf(e),Of(e)):n.plugins==="cursor"&&ff(e)}}function Pf(e,t){try{let n=new ir(e,{pathMode:t.pathMode,maxEntries:t.maxEntries});for(let r of t.layouts)KR(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 bs(e,t,n={}){let r={},o=n.shouldWalk;if(o===void 0||o("user","")){let c=Pf(t,{layouts:Object.values(Ct),levelDir:t,origin:"user",includeMachineWide:!0,pathMode:"home-relative",maxEntries:Ye,scopeRef:""});c&&(r.user=c)}let s=n.inGitRepo===!0,i=null,a=n.launchCwd;if(a!==void 0){let c=Object.values(Qe),l=Bo({launchCwd:a,gitRoot:n.gitRoot,inGitRepo:s,remote:n.remote,home:t,hasProjectSpec:u=>wa(c,u)});i=l.parentRel;for(let u of l.anchors){let d=wo(u.dir);if(o!==void 0&&!o(u.scope,d))continue;let f=Pf(t,{layouts:c,levelDir:u.dir,origin:u.scope,includeMachineWide:!1,pathMode:"tilde",maxEntries:Ko,scopeRef:d});f&&(r[u.scope]=f)}r.parent||(i=null)}return{scopes:r,parentRel:i,cwdInGitRepo:s}}function xs(e,t,n={}){let r=n.truncated===!0,o=Xt(e),s=new Set(e.map(u=>he(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 d=he(u.path,u.name);c[d]!==u.content_hash&&a.push(u)}let l=[];if(!r){for(let u of Object.keys(c))if(!s.has(u)){let d=lu(u);d&&l.push(d)}}return{hash:o,count:e.length,truncated:r,full:!1,upserts:a,removed:l,unchanged:a.length===0&&l.length===0}}var Nf=2*1024*1024,GR=new Set(["HOOK","MCP_SERVER","PLUGIN","SETTINGS","MANAGED_SETTINGS"]);function ks(e,t,n){let r=new Set(t.map(s=>he(s.path,s.name))),o=[];for(let s of e)s.text!==void 0&&(n.has(s.content_hash)||r.has(he(s.path,s.name))||o.push(s));return o}function Is(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 wf(e){return Buffer.byteLength(JSON.stringify(e),"utf8")}function vf(e){if(e.text===void 0)return e;let{text:t,...n}=e;return n}function Os(e,t=Nf){let n=[],r=[];for(let u of e)GR.has(u.kind)?n.push(u):r.push(u);r.sort((u,d)=>(u.text?.length??0)-(d.text?.length??0));let o=[...n,...r],s=[],i=2,a=0,c=0,l=[];for(let u of o){let d=s.length>0?1:0,f=wf(u)+d;if(i+f<=t){s.push(u),i+=f,u.text!==void 0&&l.push(u.content_hash);continue}if(u.text!==void 0){let p=vf(u),g=wf(p)+d;if(i+g<=t){s.push(p),i+=g,a+=1;continue}}c+=1}return{components:s,textDeferredCount:a,droppedCount:c,textHashesSent:l}}function Ts(e,t){return t.size===0?e:e.map(n=>n.text===void 0||!t.has(n.content_hash)?n:vf(n))}var WR=["user","cwd","repo","parent"];function Ps(e){let{collected:t,cacheFor:n,nowMs:r,maxBytes:o}=e,s=[];for(let v of WR){let O=t.scopes[v];if(!O)continue;let K=n(v,O.scopeRef),U=K.components,k=xs(O.components,U,{forceFull:U===void 0,truncated:O.truncated}),w=new Set(K.textHashes),L=ks(O.components,k.upserts,w),m=Ts([...k.upserts,...L],w);s.push({scope:v,walk:O,delta:k,outgoing:m,outgoingKeys:new Set(m.map(x=>he(x.path,x.name))),deliveredTextHashes:w,cachedComponents:U})}let i=s.flatMap(v=>v.outgoing),a=Os(i,o),c=new Set(a.components.map(v=>he(v.path,v.name))),l=[],u=[],d=[],f=[],p=[],g=[],S=[];for(let v of s){let{scope:O,walk:K,delta:U}=v;g.push(...K.components),l.push(O);let k=a.components.filter(x=>v.outgoingKeys.has(he(x.path,x.name))),w=[...v.outgoingKeys].some(x=>!c.has(x)),L=U.truncated||w;L?d.push(O):U.full&&u.push(O),f.push(...k),!U.full&&!L&&p.push(...U.removed);let m=U.full?{}:{...v.cachedComponents??{}};if(!L)for(let x of U.removed)delete m[he(x.path,x.name)];for(let x of k)m[he(x.path,x.name)]=x.content_hash;S.push({scope:O,scopeRef:K.scopeRef,components:m,textHashes:Is(v.deliveredTextHashes,k.filter(x=>x.text!==void 0).map(x=>x.content_hash),K.components),collectedAtMs:r,included:k.length>0||U.removed.length>0&&!L||U.full})}let A={user_spec_hash:Xt(g),user_spec_count:g.length,user_spec_truncated:d.length>0};l.length>0&&(A.user_spec_scopes=l,A.user_spec_full_scopes=u,A.user_spec_truncated_scopes=d,A.user_spec_cwd_in_git_repo=t.cwdInGitRepo),u.length>0&&u.length===l.length&&(A.user_spec_full=!0),f.length>0&&(A.user_spec=f),p.length>0&&(A.user_spec_removed=p),a.textDeferredCount>0&&(A.user_spec_text_deferred=a.textDeferredCount);let b=t.scopes.cwd;b&&(A.user_spec_cwd_scope_ref=b.scopeRef);let I=t.scopes.repo;I&&(A.user_spec_repo_scope_ref=I.scopeRef);let T=t.scopes.parent;return T&&(A.user_spec_parent_scope_ref=T.scopeRef,t.parentRel&&(A.user_spec_parent_rel=t.parentRel)),{fields:A,scopes:S}}var Rr={cwd:"cwd_spec",repo:"repo_spec",parent:"parent_spec"};function ws(e){return e==="cwd"||e==="repo"||e==="parent"}function ln(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ns(e){return!ln(e)||!ln(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 Mf(e){return zR(e)}function Lf(e){return VR(e)}function Hf(e){return JR(e)}function zR(e){if(!ln(e))return;let t={};for(let[n,r]of Object.entries(e))typeof r=="string"&&(t[n]=r);return t}function VR(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function Uf(e,t){if(!ln(e))return;let n=e[t];return Ns(n)?n:void 0}function JR(e){if(!ln(e))return{};let t={};for(let[n,r]of Object.entries(e))Ns(r)&&(t[n]=r);return t}function vs(e,t=20){let n=[];for(let[r,o]of Object.entries(e))Ns(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 QR=["allow","deny","ask"];function Ar(e){let t=oe(e,{}),n=[];for(let r of QR)for(let o of t.permissions?.[r]??[])typeof o=="string"&&o.length>0&&n.push({key:Sr(o),mode:r});return{model:t.model??"",permissionKeys:n}}function eC(e){let{serverManaged:t,fileBased:n}=Kr(process.platform,e),r=Ar(t);if(r.model||r.permissionKeys.length>0)return r;let o="",s=[];for(let i of n){let a=Ar(i);a.model&&(o=a.model),s.push(...a.permissionKeys)}return{model:o,permissionKeys:s}}function tC(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 nC=10,rC="self-config-cache.json",Ff=4;function vt(){return F("EV_AI_HOOK_USER_SPEC")?.toLowerCase()==="off"}function oC(){return F("EV_AI_HOOK_CWD_SPEC")?.toLowerCase()==="off"}var sC={claude:["claude"],cursor:["agent","cursor-agent"],codex:["codex"]};async function iC(e,t=te){let n=sC[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(`
|
|
46
|
+
`)[0]??"").trim();return a||r(o+1)};return r(0)}function aC(e=Df()){return Nt(e,".ev-ai","agent-hook",rC)}function cC(e){let n=[...e].sort((r,o)=>r.name.localeCompare(o.name)).map(r=>`${r.name}:${r.size}`).join(`
|
|
47
|
+
`);return q(n)}function Cr(e,t,n=!1){let r=cC(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 Ms(e,t,n=[]){let r=0,o=!1,s=new Set;for(let i of[...t.map(a=>Nt(e,a)),...n]){let a=ZR(i);if(s.has(a))continue;s.add(a);let c=Vr(i);c.present&&(o=!0,r+=c.size)}return o?{present:!0,size:r}:{present:!1,size:0}}function uC(e){return XR(e)?me(qR(e,"utf8"),{}):{}}function lC(e,t){try{ke(e,`${JSON.stringify(t)}
|
|
48
|
+
`)}catch(n){let r=n instanceof Error?n.message:String(n);E(`WARN: self-config cache write failed open: ${r}`)}}function fC(e,t,n){if(t==="user")return{components:Mf(e.user_spec_components),textHashes:Lf(e.user_spec_text_hashes)};if(!ws(t))return{components:void 0,textHashes:[]};let r=Uf(e[Rr[t]],n);return r?{components:r.components,textHashes:r.text_hashes}:{components:void 0,textHashes:[]}}function dC(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=Ff,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(!ws(s.scope))continue;let i=Rr[s.scope],a=Hf(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]=vs(a)}}return o}async function $f(e,t=process.cwd(),n=Df(),r={}){let o=e==="claude",s=r.gitRoot??t,i=await iC(e),a="",c=[];if(o){let L=eC(n),m=Ar(Nt(n,".claude/settings.json")),x=Ar(Nt(t,".claude/settings.local.json"));a=L.model||x.model||m.model,c=tC([...L.permissionKeys,...m.permissionKeys,...x.permissionKeys]).slice(0,200)}let l={present:!1,size:0},u=L=>{let m=[],x=!1;for(let H of L){let le=Ri(Nt(n,H));if(m=m.concat(le.entries),x=x||le.truncated,m.length>=Ye){m=m.slice(0,Ye),x=!0;break}}return{entries:m,truncated:x}},d=aC(n),f=uC(d),p=f[e]??{},g=(p.send_count??0)+1,S=g>0&&g%nC===0,A=L=>S?void 0:p[L],b=u(tt.skills),I=u(tt.subagents),T=u(tt.commands),v=u(tt.rules),O={skills:Cr(b.entries,A("skills"),b.truncated),subagents:Cr(I.entries,A("subagents"),I.truncated),commands:Cr(T.entries,A("commands"),T.truncated),rules:Cr(v.entries,A("rules"),v.truncated)},K={runner_platform:e,config_scope:"user",cli_version:i,claude_version:o?i:null,model:o&&a||null,permission_keys:c,user_scope:{skills:O.skills,subagents:O.subagents,commands:O.commands,rules:O.rules,memory:Ms(n,tt.memory),settings:Ms(n,tt.settings,Na(n)),mcp:Ms(n,tt.mcp)},local_settings:o?Vr(Nt(t,".claude/settings.local.json")):l},U=null,k=r.nowMs??Date.now();if(!vt()){let L=p.user_spec_layout_version!==Ff,m=bs(e,n,{launchCwd:oC()?void 0:r.launchCwd,gitRoot:s,inGitRepo:r.inGitRepo,remote:r.remote});if(Object.keys(m.scopes).length>0){let x=Ps({collected:m,cacheFor:(H,le)=>L?{components:void 0,textHashes:[]}:fC(p,H,le),nowMs:k});Object.assign(K,x.fields),U={hash:x.fields.user_spec_hash,home:x.scopes.find(H=>H.scope==="user")??null,project:x.scopes.filter(H=>H.scope!=="user")}}}let w=dC(p,O,g,U);return{config:K,commit:()=>{f[e]=w,lC(d,f)}}}import{homedir as PC}from"node:os";import{join as Kf}from"node:path";function ht(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}import{join as br}from"node:path";function pC(e){return br(e,".ev-ai","agent-hook","js","signed-v1")}function mC(e){return br(pC(e),"scopes")}function jf(e,t){return br(mC(e),t)}function Bf(e){return br(e,"attempts")}function Ls(e){return String(e).padStart(10,"0")}var gC=/^(\d{10})$/,hC=/^(\d{10})\.done$/,_C=/^[0-9a-f]{128}$/,SC=64;async function Vf(e,t,n=!1){let r=Bf(t),o=await xa(e,r),s=new Map,i=new Map,a=Gf(o,gC),c=Gf(o,hC),l=async f=>{let p=await zf(e,Kf(r,EC(f)));return p&&s.set(f,{record:RC(p.value),mtimeMs:p.mtimeMs}),p!==void 0},u=async f=>{let p=CC((await zf(e,Kf(r,yC(f))))?.value);return p&&i.set(f,p),p!==void 0};if(!n)return await Promise.all([...a.map(l),...c.map(u)]),{claims:s,dones:i};await Promise.all([Wf(a,l),Wf(c,u)]);let d=fn(s);return d<fn(i)&&c.includes(d)&&await u(d),{claims:s,dones:i}}function Gf(e,t){return e.flatMap(n=>{let r=t.exec(n);return r?[Number(r[1])]:[]})}async function Wf(e,t){for(let n of[...e].sort((r,o)=>o-r))if(await t(n))return}function fn(e){let t=0;for(let n of e.keys())n>t&&(t=n);return t}function Jf(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 EC(e){return Ls(e)}function yC(e){return`${Ls(e)}.done`}async function zf(e,t){let n;try{n=await e.stat(t)}catch(o){if(uo(o))return;throw o}let r=n.mtimeMs;if(n.size===0||n.size>Nr)return{mtimeMs:r};try{let o=await e.readFile(t);return o.byteLength===0||o.byteLength>Nr?{mtimeMs:r}:{mtimeMs:r,value:JSON.parse(o.toString("utf8"))}}catch{return{mtimeMs:r}}}function RC(e){if(!ht(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 CC(e){if(!ht(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=AC(t.selection);if(n)return{finished_at:t.finished_at,interval_s:t.interval_s,outcome:t.outcome,selection:n}}function AC(e){if(!ht(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"&&_C.test(t.digest)&&typeof t.version=="string"&&t.version.length>0&&typeof t.sha512=="string"&&bC(t.sha512)===t.digest)return{kind:"cached",digest:t.digest,version:t.version,sha512:t.sha512}}function bC(e){if(e.length===0||!/^[A-Za-z0-9+/]+=*$/.test(e))return;let t=Buffer.from(e,"base64");if(!(t.byteLength!==SC||t.toString("base64")!==e))return t.toString("hex")}function OC(e){return e==="bootstrap"?3e3:6e4}function TC(e,t){let n=fn(e.claims);if(n===0)return;let r=fn(e.dones),o=e.claims.get(n),s=e.dones.get(n);if(o&&!s){let a=Jf(o),c=o.record==="empty"?void 0:o.record.owner,l=OC(c)+3e4;if(t-a>l)return{n,latest_claim:n,outcome:"incomplete",finished_at:null,selection_version:Yf(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:Yf(i.selection)}}async function Xf(e,t,n){try{let r=await Vf(ka(),jf(e,t),!0);return TC(r,n)}catch{return}}function Yf(e){return e?.kind==="cached"&&typeof e.version=="string"?e.version:null}async function qf(e=PC()){let t=ko()?.launcherScope;if(!t)return{};let n=await Xf(e,t,Date.now());return n?{launcher_scope:t,launcher_attempt:n}:{launcher_scope:t}}function Mt(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:Je,event:e,timestamp:Pn(),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:Me,host_arch:process.arch,node_version:process.version,policy_version:null,policy_capabilities:[],correlation:r,payload:t},s=ko();return s&&(o.launcher_version=s.launcherVersion,o.hook_source=s.hookSource,o.hook_fallback_reason=s.fallbackReason??null,o.launcher_scope_match=Hc(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 Zf}from"node:fs";import{spawn as Qf}from"node:child_process";import{fileURLToPath as NC}from"node:url";import{gzipSync as wC}from"node:zlib";function Hs(e){return F("EV_AI_HOOK_COMPRESS")==="off"?{body:e}:Buffer.byteLength(e,"utf8")<ui?{body:e}:{body:wC(Buffer.from(e,"utf8")),contentEncoding:"gzip"}}function xr(e){let t={"Content-Type":"application/json"};return e!==void 0&&(t["Content-Encoding"]=e),t}function Us(e){return typeof e=="string"?Buffer.byteLength(e,"utf8"):e.length}var dn="__post",kr="__work";async function vC(e,t,n={}){if(vt())return e;let r=await vo(n.gitRoot??process.cwd(),te,process.env,{runnerPlatform:t,home:n.home}),o=ht(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 MC(e,t){let n=ht(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 ed(e){switch(e){case"session_start":return si;case"session_end":return ii;case"tool_invoked":case"skill_invoked":return $r;default:return $r}}function LC(e,t,n){return`${JSON.stringify({url:e,timeoutMs:t})}
|
|
49
|
+
${n}`}function td(e,t=[],n=process.execPath,r=import.meta.url,o=Zf){if(xn(n))return{command:n,args:[e,...t]};let s=NC(r);return o(s)?{command:n,args:[s,e,...t]}:{command:n,args:[e,...t]}}function HC(e=process.execPath,t=import.meta.url,n=Zf){return td(dn,[],e,t,n)}function UC(e){let t=e.indexOf(`
|
|
50
|
+
`);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 nd(e){if(!(!e.ok||typeof e.text!="function"))try{await e.text()}catch{}}async function Ir(e,t=fetch){let n=await e(),r=UC(n);if(!r)return;let{meta:o,body:s}=r,i=Hs(s),a=xr(i.contentEncoding);try{let c=await t(o.url,{method:"POST",headers:a,body:i.body,signal:AbortSignal.timeout(Number(o.timeoutMs))});await nd(c)}catch{}}async function DC(e,t,n,r=fetch){let o=ed(e),s=Hs(t),i=xr(s.contentEncoding),a=Us(s.body);E(`POST event=${e} url=${bn(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{}E(`POST gzip rejected http=${l.status} \u2014 retrying uncompressed`),l=await r(n,{method:"POST",headers:xr(),body:t,signal:AbortSignal.timeout(o)})}let u=Date.now()-c;if(l.ok)return E(`POST outcome=ok elapsed_ms=${u} http=${l.status}`),await nd(l),!0;let d=(await l.text()).slice(0,200).replace(/[\n\r]/g,"");return E(`POST outcome=fail elapsed_ms=${u} http=${l.status} body=${d}`),!1}catch(l){let u=Date.now()-c,d=l instanceof Error?l.message:String(l);return E(`POST outcome=fail elapsed_ms=${u} http=000 body=${d}`),!1}}async function rd(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){E(`WARN: ${o} stdin handoff timed out \u2014 continuing fail-open`);try{s.stdin.destroy()}catch{}}a()},ai),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 E(`WARN: ${o} spawn failed open: ${i}`),null}}async function FC(e,t,n,r=Qf,o=HC){let s=ed(e),i=LC(n,s,t),{command:a,args:c}=o();return rd(a,c,i,r,"detached post")}async function od(e,t,n=Qf,r=td){let{command:o,args:s}=r(kr,t);return rd(o,s,e,n,"detached work")}async function Lt(e,t,n,r,o,s,i){if(!o)return E("WARN: collector URL missing \u2014 pass --url on the hook command or set collector_url in manifest"),!1;if(!An(o))return E(`WARN: collector URL blocked (https required): ${bn(o)}`),!1;let a=await vC(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}
|
|
51
|
+
`,d=F("EV_AI_HOOK_DEBUG");d==="full"?E(`DEBUG envelope=${l}`):d==="1"&&E(`DEBUG summary=${MC(c,Us(u))}`);let f=process.argv.includes(kr),p=F("EV_AI_HOOK_SYNC")==="1";return Xn(n.runnerEvent,n.runnerPlatform)||f||p?DC(e,u,o):(await FC(e,u,o),!1)}import{createReadStream as $C}from"node:fs";import{stat as jC}from"node:fs/promises";import{basename as BC,resolve as KC}from"node:path";import{createInterface as GC}from"node:readline";var WC=1024*1024;function zC(e){let t=e.replace(/\\/g,"/");return t.includes("/.claude/projects/")&&BC(t).endsWith(".jsonl")}async function sd(e){if(!e||!zC(e))return null;try{let t=KC(e),n=await jC(t);if(!n.isFile())return null;let r=Math.max(0,n.size-WC),o=[],s=GC({input:$C(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 Or(e){return{sessionId:e.sessionId,turnId:e.turnId,installationId:e.manifest.installationId,runnerPlatform:e.runnerPlatform,platformAgentId:e.platformAgentId,runnerEvent:e.runnerEvent}}function mn(e,t){return{gitRoot:e.manifest.gitRoot,...t?{home:t}:{}}}function Fs(e){return{gitRoot:e.manifest.gitRoot,inGitRepo:e.manifest.inGitRepo,runnerEvent:e.runnerEvent}}async function cd(e){let t=Date.now();await oA(e);let{gitRoot:n}=e.manifest;await js(e,n);let r=Fs(e);return{buildStartedAtMs:t,gitRoot:n,hookInput:or(e.hookInput,e.manifest.manifest,r),envelopeFields:Or(e),launchCwd:$o(e.hookInput,r),home:JC()}}function id(e){try{return ge(VC(e))}catch{return null}}function ud(e){return e.startsWith("/")||/^[A-Za-z]:\//.test(e)}function ad(e,t){let n=e.replaceAll("\\","/");if(!ud(n))return null;let r=ge(e),o=ge(t),s=id(e)??r,i=id(t)??o;return s.startsWith(`${i}/`)?s.slice(i.length+1):r.startsWith(`${o}/`)?r.slice(o.length+1):null}function ld(e,t,n){if(!e)return{repositorySourcePath:null,userSourcePath:null};let r=e.replaceAll("\\","/"),s=ad(e,t)??(ud(r)?null:r),i=ad(e,n);return{repositorySourcePath:s,userSourcePath:i}}function Ds(e,t,n,r,o){return fd(e,ld(n,t.gitRoot,t.home),r,o)}function fd(e,{repositorySourcePath:t,userSourcePath:n},r,o){let s=t??n,i=s===null?null:o(s),a=i!==null&&s!==null?YC({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 YC(e){try{let t=e.inRepository?ZC(e.platformAgentId,e.sourcePath):(0,B.installationRootExternalKey)(e.installationId,(0,B.userConfigRootFromPath)(e.sourcePath));return t?(0,B.buildComponentReference)({installationRootExternalKey:t,installableKind:e.installableKind,sourcePath:e.sourcePath,nativeKey:e.nativeKey}):void 0}catch{return}}function dd(e){let t=e.policyFindings;return t===void 0||t.length===0?{}:{policy_findings:t,...e.policyJudgeSpawnMs!==void 0?{policy_judge_spawn_ms:e.policyJudgeSpawnMs}:{}}}function $s(e,t,n){return Lt("tool_invoked",{...n,...dd(e),success:null,duration_ms:null,hook_input:t.hookInput},t.envelopeFields,Mt,e.manifest.collectorUrl,t.buildStartedAtMs,mn(e,t.home))}function XC(e){return yc(e.runnerEvent,e.runnerPlatform)?[]:Fa(e.hookInput)}function qC(e,t){return $s(e,t,{})}var pd=new Set([...Object.values(lt),".github"]);function ZC(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=>pd.has(i));return s<0?null:`${r}:${o.slice(0,s+1).join("/")}`}var md=".codex/config.toml",QC=new Map([["claude_json_user",".claude.json"],["cursor_mcp_user",".cursor/mcp.json"],["codex_toml_user",md]]);function eA(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(S=>S.name.toLowerCase()===t.toLowerCase()),l=c?QC.get(c.source):o==="codex"?md:void 0,u=c?.sourcePath??l;if((c?.scope==="user"||l!==void 0)&&u)try{let S=(0,B.userConfigRootFromPath)(u);return(0,B.buildComponentReference)({installationRootExternalKey:(0,B.installationRootExternalKey)(r,S),installableKind:B.ComponentKind.INTERFACE,sourcePath:u,nativeKey:c?.name??t})}catch{return}if(n===null)return;let f=n.indexOf(":");if(f<=0||f===n.length-1)return;let p=n.slice(f+1),g=p.replaceAll("\\","/").split("/").at(-1);if(!(g===void 0||!pd.has(g)))try{return(0,B.buildComponentReference)({installationRootExternalKey:n,installableKind:B.ComponentKind.INTERFACE,sourcePath:p,nativeKey:t})}catch{return}}function tA(...e){for(let t of e)if(t)return t;return null}function St(e,t,n){if(e.status==="fulfilled")return e.value;let r=e.reason instanceof Error?e.reason.message:String(e.reason);return E(`WARN: ${n} failed open: ${r}`),t}function nA(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 rA(e,t){return{runner_platform:e,config_scope:"user",...t?{operator:t}:{}}}var _t=new Set,pn=null;async function oA(e){if(vt())return;let t=e.manifest.installationId,n=e.manifest.installationStorePath;if(_t.has(t))return;if(!Lo(n)){_t.add(t);return}let r=$t({sessionId:e.sessionId,hostname:Nn()});if(du(r)){if(pn){await pn;return}pn=(async()=>{if(_t.has(t)||!Lo(n)){_t.add(t);return}if(!Ki(n)){_t.add(t);return}let o=!1;try{let s=Date.now(),{gitRoot:i}=e.manifest,a=String(e.runnerPlatform),{operatorResolved:c,fields:l}=await gd(e,r,Jn(i),Mo({gitRoot:i,installationStorePath:n,forceResend:!1,runnerPlatform:a})),u={...l,self_config:rA(a,c.operator),run_meta:{trigger:"cloud_identity_bootstrap"}};o=!!await Lt("session_start",u,Or(e),Mt,e.manifest.collectorUrl,s,mn(e)),o&&(c.commit(),_t.add(t))}finally{Gi(n)}})().finally(()=>{pn=null}),await pn}}async function js(e,t,n){try{e.platformAgentId=await lc(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);E(`WARN: derivePlatformAgentId failed open: ${o}`)}}async function gd(e,t,n,r){let[o,s,i,a,c]=await Promise.allSettled([n,xi(),Dc(t),Ii(),r]),l=St(o,null,"gitSnapshot"),u=St(s,"","detectVirt"),d=St(i,null,"probeCloud"),f=St(a,{},"hostEnv"),p=St(c,{commit:()=>{}},"resolveOperatorForSend");return await js(e,e.manifest.gitRoot,l),{operatorResolved:p,fields:{identity:{host:Nn(),context:t,virt:u||null,cloud:d,git:l},host_env:f,env_vars:Wc()}}}async function sA(e){let t=Date.now(),{gitRoot:n}=e.manifest,r=$t({sessionId:e.sessionId,hostname:Nn()}),o=String(e.runnerPlatform),s=Fs(e),i=$o(e.hookInput,s),a=Jn(n),c=qf().catch(()=>({})),l=vt()?Promise.resolve({commit:()=>{}}):Mo({gitRoot:n,installationStorePath:e.manifest.installationStorePath,forceResend:!1,runnerPlatform:o}),u=gd(e,r,a,l),[d,f]=await Promise.allSettled([Oo(e.manifest.manifest,n,o),a.catch(()=>null).then(K=>$f(o,n,void 0,{installationStorePath:e.manifest.installationStorePath,gitRoot:n,launchCwd:i,inGitRepo:e.manifest.inGitRepo,remote:K?.remote??null}))]),{operatorResolved:p,fields:g}=await u,S=St(d,[],"mcpDeclared"),A=St(f,nA(o),"selfConfig"),b=A.config,I=M(e.hookInput,"model");I&&(b.model=I);let T={...g,mcp:{declared:S},self_config:b,run_meta:{trigger:e.hookSource||"startup"},hook_input:or(e.hookInput,e.manifest.manifest,{...s,launchCwd:i})},v=await c;await Lt("session_start",T,{...Or(e),...v},Mt,e.manifest.collectorUrl,t,mn(e))&&(A.commit(),p.commit(),_t.add(e.manifest.installationId))}async function iA(e){let t=Date.now(),[,n]=await Promise.all([js(e,e.manifest.gitRoot),e.runnerPlatform==="claude"?sd(M(e.hookInput,"transcript_path")):null]),r=e.runnerEvent.toLowerCase(),o=tA(M(e.hookInput,"status"),M(e.hookInput,"stop_reason"),M(e.hookInput,"reason"),Vt(M(e.hookInput,"error")),r==="stop"?He(e.hookInput,"is_interrupt")===!0?"interrupted":"completed":""),s=or(e.hookInput,e.manifest.manifest,Fs(e));n&&(s.model=n),r!=="stopfailure"&&!_u(e.manifest.manifest)&&s.last_assistant_message===void 0&&(s.last_assistant_message=""),await Lt("session_end",{status:o,...n?{model:n}:{},hook_input:s},Or(e),Mt,e.manifest.collectorUrl,t,mn(e))}async function aA(e){let t=XC(e),n=mc(e.hookInput),r=Ec(e.runnerEvent),o=r&&t.length===0&&n.length===0;if(t.length===0&&n.length===0&&!r)return;let s=await cd(e);await Promise.all([o?qC(e,s):void 0,t.length===0?void 0:cA(e,s,t),n.length===0?void 0:uA(e,s,n)])}function hd(e,t,n,r){let o=r??Da({skillId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home}),s=Ds(e,t,o,B.ComponentKind.SKILL,B.nativeKeyForSkillPath);if(s.sourcePath!==null&&fo(s.sourcePath)?.toLowerCase()===n.toLowerCase())return s.componentReference===void 0?{}:{componentReference:s.componentReference};let i=r??gc({commandId:n,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),a=Ds(e,t,i,B.ComponentKind.COMMAND,B.nativeKeyForCommandPath);return a.nativeKey?.toLowerCase()!==n.toLowerCase()?{}:{commandName:a.nativeKey,...a.componentReference===void 0?{}:{componentReference:a.componentReference}}}function cA(e,t,n){let r=jn(e.hookInput.tool_input);return Promise.all(n.map(o=>{let s=hd(e,t,o,r);return $s(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 uA(e,t,n){return Promise.all(n.map(r=>{let o=fc({relativePath:r,launchCwd:t.launchCwd,gitRoot:t.gitRoot,home:t.home,runnerPlatform:e.runnerPlatform}),s=Ds(e,t,o,B.ComponentKind.RULE,B.nativeKeyForRulePath),i=s.nativeKey??pc(r);return $s(e,t,{tool_name:"Rule",rule_name:i,...s.componentReference===void 0?{}:{component_reference:s.componentReference}})}))}var lA=[{kind:B.ComponentKind.SKILL,nativeKeyFn:B.nativeKeyForSkillPath},{kind:B.ComponentKind.RULE,nativeKeyFn:B.nativeKeyForRulePath},{kind:B.ComponentKind.COMMAND,nativeKeyFn:B.nativeKeyForCommandPath}];function fA(e,t,n){if(n.skillName===null&&n.ruleName===null&&n.commandName===null)return{};let r=mo(e.hookInput);if(r===null)return n.skillName===null?{}:hd(e,t,n.skillName,null);let o=ld(r,t.gitRoot,t.home);for(let s of lA){let i=fd(e,o,s.kind,s.nativeKeyFn);if(i.nativeKey!==null)return{...i.componentReference===void 0?{}:{componentReference:i.componentReference},...s.kind===B.ComponentKind.RULE?{ruleName:i.nativeKey}:{},...s.kind===B.ComponentKind.COMMAND?{commandName:i.nativeKey}:{}}}return{}}var dA=/mcp/i;function pA(e,t,n,r){let o=dA.test(e.runnerEvent);if(!r.hasMcpIdentity&&!o)return{};let s=o?of(t,n):_r(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 mA(e){let t=await cd(e),n=bc(e.hookInput,e.runnerEvent),{toolName:r,skillName:o}=n,s=po(e.hookInput),i=nf(s,t.home),a=kc(e.hookInput),c=Rc(e.runnerEvent),l=c===!1?Ic(e.hookInput,e.runnerEvent):null,u=Vt(M(e.hookInput,"mcp_server_name")),d=u!==null||r!==null&&qn(r)?await Oo(e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home).catch(()=>[]):[],{mcpServer:f,mcpTool:p}=Tc(r,d.map(K=>K.name),u??""),g=eA(r,f,e.platformAgentId,e.manifest.installationId,String(e.runnerPlatform),d,u),S=g===void 0?fA(e,t,n):{},A=f===null?null:Gc(f,e.manifest.manifest,e.manifest.gitRoot,String(e.runnerPlatform),t.home),b=pA(e,s,t.home,{hasMcpIdentity:!!f||!!p,declaredConfig:A}),I=g??S.componentReference,T=S.ruleName??n.ruleName,v=S.commandName??n.commandName,O=xc(e.hookInput);await Lt("tool_invoked",{tool_name:r,skill_name:o,...T?{rule_name:T}:{},...v?{command_name:v}:{},success:c,duration_ms:a,...i?{executable:i}:{},...l?{failure_reason:l}:{},...f?{mcp_server:f}:{},...p?{mcp_tool:p}:{},...b,...I?{component_reference:I}:{},...O?{subagent_type:O}:{},...dd(e),hook_input:t.hookInput},t.envelopeFields,Mt,e.manifest.collectorUrl,t.buildStartedAtMs,mn(e,t.home))}async function _d(e){switch(e.internalEvent){case"session_start":await sA(e);return;case"session_end":await iA(e);return;case"skill_invoked":await aA(e);return;case"tool_invoked":await mA(e);return;default:return}}import{mkdirSync as gA,readdirSync as hA,readFileSync as _A,statSync as Sd,unlinkSync as SA,writeFileSync as EA}from"node:fs";import{homedir as Tr}from"node:os";import{join as Bs}from"node:path";var yA="turns",Ed=1440*60*1e3,RA=100,CA=new Set(["stop","stopfailure","sessionend"]);function Ks(e=Tr()){return Bs(Ue(e),yA)}function yd(e,t){return Bs(e,Dt(t))}function AA(e,t=Date.now()){let n;try{n=hA(e)}catch{return}let r=0;for(let o of n){if(r>=RA)return;r+=1;try{let s=Bs(e,o);t-Sd(s).mtimeMs>Ed&&SA(s)}catch{}}}function bA(e,t,n=Tr()){let r=e.trim(),o=t.trim();if(!(!r||!o))try{let s=Ks(n);gA(s,{recursive:!0}),EA(yd(s,r),o,"utf8")}catch{}}function xA(e,t=Tr()){let n=e.trim();if(!n)return"";try{let r=yd(Ks(t),n);return Date.now()-Sd(r).mtimeMs>Ed?"":_A(r,"utf8").trim()}catch{return""}}function Rd(e,t,n,r=Tr()){let o=t.trim(),s=CA.has(n.trim().toLowerCase());return s&&AA(Ks(r)),o?(bA(e,o,r),o):s?xA(e,r):""}async function Cd(e,t,n,r){let o=t??await wn(kn),s=me(o,{}),i=await Yi(process.cwd(),{sessionId:zt(s)});if(!i)return;r&&(i.collectorUrl=r);let a=Cc(s,i.manifest.platform,n),c=Ac(e,a.runnerEvent);if(!c){E(`WARN: unknown hook event '${a.runnerEvent}'; skipping telemetry`);return}let l={hookInput:s,sessionId:a.sessionId,turnId:Rd(a.sessionId,a.turnId,a.runnerEvent),runnerEvent:a.runnerEvent,runnerPlatform:a.runnerPlatform,hookSource:a.hookSource,internalEvent:c,manifest:i,platformAgentId:i.platformAgentId};await _d(l)}function kA(e,t=!1){if(F("EV_AI_HOOK_SYNC")==="1")return!0;let{parsed:n,hookInput:r,runnerEvent:o}=e,s=Wt(r,o,void 0,n.runner);return Xn(o,s)?!0:t}function Ad(e,t){let n=Mr(e),r=me(t,{}),o=n.event??bo(r);return Ai()||Sc(n.runner,r,o)?null:{parsed:n,hookInput:r,runnerEvent:o}}async function bd(e=process.argv.slice(2)){if(Lc(),F("EV_AI_HOOK_JUDGE")==="1"){try{await wn(kn)}catch{}return Wr(),0}if(e[0]===dn){try{await Ir(Ft)}catch{}return 0}if(e[0]===kr){try{let t=await Ft(),n=Ad(e.slice(1),t);if(!n)return 0;let{parsed:r}=n;await Cd(r.event,t,r.runner,Co(r))}catch(t){let n=t instanceof Error?t.message:String(t);E(`WARN: detached work failed open: ${n}`)}return 0}try{let t=await wn(kn),n=Ad(e,t);if(!n)return 0;let{parsed:r,hookInput:o,runnerEvent:s}=n;if(!Mc(o,s,r.runner))return 0;kA(n)?await Cd(r.event,t,r.runner,Co(r)):await od(t,e)}catch(t){let n=t instanceof Error?t.message:String(t);E(`WARN: hook failed open: ${n}`)}finally{Wr()}return 0}function Pr(){E("Usage: ev-ai-agent-hook <configure|install|migrate-to-plugin|update|uninstall|--version>"),E(" configure [--url <\u2026/{orgToken}/hook>]"),E(" (manifest only \u2014 pair with marketplace plugins)"),E(" install --url <\u2026/{orgToken}/hook>"),E(" [--delivery npx|binary|local] [--force]"),E(" [--no-claude] [--no-cursor] [--no-codex]"),E(" (fallback: merge hooks into .claude / .cursor / .codex configs)"),E(" (writes collector_url to shared manifest; hook commands use --runner only)"),E(" migrate-to-plugin"),E(" (strip ev-ai file hooks; keep collector manifest)"),E(" update (refresh binary pins from a local build; leaves hook configs alone)"),E(" uninstall"),E("Hook mode: --runner <platform> [--url <\u2026/hook>|--token <orgToken>] [event]"),E(" (--url/--token optional overrides; else collector_url from manifest)")}function xd(e){return e.includes("--help")||e.includes("-h")}async function wA(e=process.argv.slice(2)){let[t,...n]=e;if(t===dn){try{await Ir(Ft)}catch{}return 0}return t==="--version"||t==="-V"?(process.stdout.write(`${Me}
|
|
52
|
+
`),0):t==="configure"?xd(n)?(Pr(),0):(await _a(ra(n)),0):t==="install"?xd(n)?(Pr(),0):(await ga(oa(n)),0):t==="migrate-to-plugin"?(await Ea(),0):t==="update"?(await ha(),0):t==="uninstall"?(await ya(),0):t==="help"||t==="--help"||t==="-h"?(Pr(),0):t===void 0?(Pr(),1):bd(e)}function NA(e,t,n=IA){if(!t)return!1;try{return e===PA(OA(t)).href?!0:n(TA(e))===n(t)}catch{return!1}}NA(import.meta.url,process.argv[1])&&process.env.VITEST===void 0&&wA().then(e=>{process.exit(e)}).catch(e=>{let t=e instanceof Error?e.message:String(e);E(t),process.exit(1)});export{NA as isCliEntrypoint,wA as main};
|