var u=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,o)=>(typeof require<"u"?require:t)[o]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});import{spawn as i}from"node:child_process";import{readFileSync as d,writeFileSync as f,existsSync as a}from"node:fs";import{homedir as l}from"node:os";import{join as c}from"node:path";async function P(){let r=c(l(),".local/share/cursor-agent/versions");if(!a(r))throw new Error(`cursor-agent not found at ${r}. Please install cursor-agent first.`);return console.log(`\u{1F527} Patching cursor-agent for CI/CD...
`),new Promise((t,o)=>{let e=c(__dirname,"../../scripts/patch-cursor-mcp.py");if(!a(e)){o(new Error("Patch script not found"));return}let n=i("python3",[e],{stdio:"inherit"});n.on("close",s=>{s===0?t({success:!0}):o(new Error(`Patch failed with code ${s}`))}),n.on("error",s=>{o(s)})})}function S(){let r=c(l(),".local/share/cursor-agent/versions");if(!a(r))return{patched:!1,installed:!1};try{let t=u("fs").readdirSync(r);if(t.length===0)return{patched:!1,installed:!1};let o=t.sort().reverse()[0],e=c(r,o,"index.js");return a(e)?{patched:d(e,"utf-8").includes("AUTO-APPROVE MCP TOOLS FOR CI/CD"),installed:!0,path:e}:{patched:!1,installed:!1}}catch(t){return{patched:!1,installed:!1,error:t.message}}}async function x(r){return console.log(`\u{1F511} Getting MCP approval keys...
`),new Promise((t,o)=>{let e=i("cursor-agent",["mcp","list"],{cwd:r,stdio:"pipe"}),n="";e.stdout.on("data",s=>{n+=s.toString(),process.stdout.write(s)}),e.stderr.on("data",s=>{process.stderr.write(s)}),e.on("close",s=>{if(s===0){let p=h(n);t({success:!0,keys:p,output:n})}else o(new Error(`Failed to get approval keys (exit code ${s})`))}),e.on("error",s=>{o(s)})})}function h(r){let t={},o=/🔑 APPROVAL KEY:\s+(\S+)\s+=>\s+(\S+)/g,e;for(;(e=o.exec(r))!==null;)t[e[1]]=e[2];return t}function A(r,t){let o=c(r,".cursor/projects"),e=c(o,"mcp-approvals.json");f(e,JSON.stringify(t,null,2)),console.log(`
\u2705 Saved approval keys to: ${e}
`)}export{S as checkCursorAgentPatched,x as getApprovalKeys,P as patchCursorAgentForCI,A as saveApprovalKeys};
