#!/usr/bin/env node
import {a as a$1}from'./chunk-LKAT7IAK.js';import*as i from'fs';import*as a from'path';import*as j from'os';import e from'chalk';import $ from'ora';function A(){let n=j.homedir(),t=a.join(n,".cursor"),s=a.join(process.cwd(),".cursor");return {name:"Cursor",id:"cursor",detected:i.existsSync(t)||i.existsSync(s),configPath:a.join(process.cwd(),".cursor","mcp.json"),configType:"project",instructions:"Restart Cursor to activate MCP"}}function D(){let n=j.homedir(),t,s=false;if(process.platform==="darwin"){let r=a.join(n,"Library","Application Support","Claude");s=i.existsSync(r),t=a.join(r,"claude_desktop_config.json");}else if(process.platform==="win32"){let r=process.env.APPDATA||a.join(n,"AppData","Roaming"),l=a.join(r,"Claude");s=i.existsSync(l),t=a.join(l,"claude_desktop_config.json");}else {let r=a.join(n,".config","Claude");s=i.existsSync(r),t=a.join(r,"claude_desktop_config.json");}return {name:"Claude Desktop",id:"claude-desktop",detected:s,configPath:t,configType:"user",instructions:"Restart Claude Desktop to activate MCP"}}function M(){let n=j.homedir(),t=a.join(n,".continue");return {name:"Continue (VS Code)",id:"continue",detected:i.existsSync(t),configPath:a.join(t,"config.json"),configType:"user",instructions:"Restart VS Code to activate MCP"}}function I(){let n=a.join(process.cwd(),".mcp.json"),t=a.join(process.cwd(),".claude");return {name:"Claude Code",id:"claude-code",detected:i.existsSync(n)||i.existsSync(t),configPath:n,configType:"project",instructions:"Restart Claude Code session to activate MCP"}}function N(){let n=a.join(process.cwd(),".cline");return {name:"Cline (VS Code)",id:"cline",detected:i.existsSync(n),configPath:a.join(process.cwd(),".cline","mcp.json"),configType:"project",instructions:"Restart VS Code to activate MCP"}}function x(){return [A(),I(),D(),M(),N()]}function R(n,t,s){let r=s.toLowerCase().replace(/[^a-z0-9-]/g,"-");return n.id==="continue"?{experimental:{modelContextProtocolServers:[{transport:{type:"stdio",command:"paradigm-mcp",args:["."],cwd:t}}]}}:{mcpServers:{[r]:{command:"paradigm-mcp",args:["."],cwd:t}}}}function T(n,t,s){if(s.id==="continue"){let r=n?.experimental?.modelContextProtocolServers||[],l=t?.experimental?.modelContextProtocolServers||[];return {...n,experimental:{...n?.experimental,modelContextProtocolServers:[...r,...l]}}}return {...n,mcpServers:{...n?.mcpServers,...t?.mcpServers}}}function O(n,t,s){let r=a.dirname(n.configPath);i.existsSync(r)||(i.mkdirSync(r,{recursive:true}),a$1.component("mcp-config").debug("Created config directory",{path:r}));let l=t;if(i.existsSync(n.configPath)&&!s)try{let g=i.readFileSync(n.configPath,"utf8"),c=JSON.parse(g);l=T(c,t,n),a$1.component("mcp-config").debug("Merged with existing config",{client:n.id});}catch{a$1.component("mcp-config").warn("Could not parse existing config, using new",{client:n.id});}return i.writeFileSync(n.configPath,JSON.stringify(l,null,2)+`
`),a$1.component("mcp-config").success("Config written",{client:n.id,path:n.configPath}),{success:true,message:`Config written to ${n.configPath}`}}function F(n){let t=a.join(process.cwd(),".gitignore"),s=a.relative(process.cwd(),n),r="";if(i.existsSync(t)&&(r=i.readFileSync(t,"utf8"),r.includes(s)||r.includes(a.dirname(s))))return  false;let l=`
# MCP config (contains local paths)
${s}
`;return i.appendFileSync(t,l),true}function b(){let n=a.join(process.cwd(),".paradigm","config.yaml");if(i.existsSync(n)){let s=i.readFileSync(n,"utf8").match(/project:\s*["']?([^"'\n]+)["']?/);if(s)return s[1].trim()}return a.basename(process.cwd())}async function q(n){let t=$(),s=process.cwd(),r=b();console.log(e.blue(`
\u{1F50C} Paradigm MCP Setup
`)),i.existsSync(a.join(s,".paradigm"))||i.existsSync(a.join(s,".purpose"))||(console.log(e.yellow("\u26A0\uFE0F  No .paradigm/ or .purpose file found.")),console.log(e.gray("   MCP will work, but you should run `paradigm init` first for full functionality.\n"))),t.start("Detecting AI clients...");let g=x(),c=g.filter(o=>o.detected);t.stop(),console.log(e.gray(`Detected AI clients:
`));for(let o of g){let f=o.detected?e.green("\u2713"):e.gray("\u25CB"),u=o.detected?o.name:e.gray(o.name),d=o.detected?e.gray(o.configType==="project"?"(project-level)":"(user-level)"):e.gray("(not found)");console.log(`  ${f} ${u} ${d}`);}if(console.log(),c.length===0){console.log(e.yellow(`No supported AI clients detected.
`)),console.log(e.gray("Supported clients:")),console.log(e.gray("  - Cursor (https://cursor.sh)")),console.log(e.gray("  - Claude Desktop (https://claude.ai/download)")),console.log(e.gray("  - Continue for VS Code")),console.log(e.gray(`  - Cline for VS Code
`)),console.log(e.gray(`Install one of these clients and run this command again.
`));return}let p=[];if(n.client)if(n.client==="all")p=c;else {let o=g.find(f=>f.id===n.client);if(!o){console.log(e.red(`Unknown client: ${n.client}`)),console.log(e.gray(`Available: ${g.map(f=>f.id).join(", ")}
`));return}o.detected||(console.log(e.yellow(`${o.name} not detected on this system.`)),console.log(e.gray(`Proceeding anyway...
`))),p=[o];}else if(c.length===1)p=c;else {console.log(e.cyan(`Multiple clients detected. Specify which to configure:
`)),console.log(e.white("  paradigm mcp setup --client=cursor")),console.log(e.white("  paradigm mcp setup --client=claude-desktop")),console.log(e.white("  paradigm mcp setup --client=all")),console.log();return}for(let o of p){t.start(`Configuring ${o.name}...`);let f=a$1.operation(`mcp-setup-${o.id}`).start("Configuring MCP",{client:o.id}),u=R(o,s,r),d=O(o,u,n.force||false);d.success?(t.succeed(`${o.name} configured`),f.success("MCP configured",{client:o.id,path:o.configPath}),console.log(e.gray(`   \u2192 ${o.configPath}`)),o.configType==="project"&&n.gitignore!==false&&F(o.configPath)&&(console.log(e.gray("   \u2192 Added to .gitignore")),a$1.component("gitignore").debug("Added MCP config to .gitignore",{path:o.configPath}))):(t.fail(`Failed to configure ${o.name}: ${d.message}`),console.log(e.gray("    Troubleshooting: .paradigm/docs/troubleshooting.md")),f.error("MCP configuration failed",{client:o.id,message:d.message}));}if(console.log(e.green(`
\u2713 MCP setup complete!
`)),console.log(e.cyan("Next steps:")),[...new Set(p.map(o=>o.instructions))].forEach(o=>{console.log(e.gray(`  \u2022 ${o}`));}),console.log(e.gray(`
Then try asking your AI:`)),console.log(e.white(`  "What features are in the ${r} project?"`)),console.log(e.white('  "What would break if I changed @feature-name?"')),console.log(),n.json){let o={project:r,path:s,configured:p.map(f=>({client:f.id,name:f.name,configPath:f.configPath,configType:f.configType}))};console.log(JSON.stringify(o,null,2));}}async function z(n){console.log(e.blue(`
\u{1F50C} Paradigm MCP Status
`));let t=x(),s=[];for(let r of t){let l=false,g=[];if(i.existsSync(r.configPath))try{let m=i.readFileSync(r.configPath,"utf8"),o=JSON.parse(m);if(r.id==="continue"){let f=o?.experimental?.modelContextProtocolServers||[];l=f.length>0,g=f.map((u,d)=>`server-${d+1}`);}else {let f=o?.mcpServers||{};l=Object.keys(f).length>0,g=Object.keys(f);}}catch{}let c=r.detected?l?e.green("\u2713"):e.yellow("\u25CB"):e.gray("\u25CB"),p=l?e.green("configured"):r.detected?e.yellow("not configured"):e.gray("not detected");console.log(`  ${c} ${r.name}: ${p}`),l&&g.length>0&&console.log(e.gray(`     Servers: ${g.join(", ")}`)),s.push({client:r.id,configured:l,path:r.configPath,servers:l?g:void 0});}console.log(),n.json&&console.log(JSON.stringify(s,null,2));}function J(n){if(!i.existsSync(n.configPath))return [];try{let t=i.readFileSync(n.configPath,"utf8"),s=JSON.parse(t);if(n.id==="continue")return (s?.experimental?.modelContextProtocolServers||[]).map((l,g)=>{let c=l?.transport;return {name:`server-${g+1}`,cwd:c?.cwd||"unknown",command:c?.command||"unknown",args:c?.args||[]}});{let r=s?.mcpServers||{};return Object.entries(r).map(([l,g])=>{let c=g;return {name:l,cwd:c?.cwd||"unknown",command:c?.command||"unknown",args:c?.args||[]}})}}catch{return []}}async function W(n){console.log(e.blue(`
\u{1F50C} Configured MCP Servers
`));let t=x(),s=process.cwd(),r=[],l=0;for(let g of t){let c=J(g);if(r.push({client:g,servers:c}),c.length===0)continue;l+=c.length;let p=g.configType==="project"?"this project":"user-level";console.log(e.cyan(`${g.name} (${p}):`));for(let m of c){let o=m.cwd===s,f=o?e.green("\u25CF"):e.gray("\u25CB"),u=o?e.green(m.name):e.white(m.name),d=o?e.green("(current)"):e.gray(m.cwd);console.log(`  ${f} ${u.padEnd(20)} \u2192 ${d}`);}console.log();}if(l===0?(console.log(e.yellow(`No MCP servers configured.
`)),console.log(e.gray("Run `paradigm mcp setup` to configure MCP for your AI clients.\n"))):console.log(e.gray(`Total: ${l} server(s) across ${r.filter(g=>g.servers.length>0).length} client(s)
`)),n.json){let g=r.map(c=>({client:c.client.id,name:c.client.name,configType:c.client.configType,configPath:c.client.configPath,servers:c.servers}));console.log(JSON.stringify(g,null,2));}}async function B(n,t){let s=$(),r=process.cwd(),g=b().toLowerCase().replace(/[^a-z0-9-]/g,"-"),c=n||g;console.log(e.blue(`
\u{1F50C} Paradigm MCP Remove
`));let p=x(),m=[];if(t.client)if(t.client==="all")m=p;else {let d=p.find(y=>y.id===t.client);if(!d){console.log(e.red(`Unknown client: ${t.client}`)),console.log(e.gray(`Available: ${p.map(y=>y.id).join(", ")}
`));return}m=[d];}else m=p;let o=0,f=0,u=[];for(let d of m)if(i.existsSync(d.configPath)){s.start(`Checking ${d.name}...`);try{let y=i.readFileSync(d.configPath,"utf8"),S=JSON.parse(y),w=!1;if(d.id==="continue"){let h=S?.experimental?.modelContextProtocolServers||[],P=h.length,v=h.filter(k=>(k?.transport?.cwd||"")!==r);v.length<P?(S.experimental.modelContextProtocolServers=v,w=!0,o++,u.push({client:d.id,removed:!0,serverName:"server (by path)"})):(f++,u.push({client:d.id,removed:!1,serverName:c}));}else {let h=S?.mcpServers||{};if(h[c])delete h[c],S.mcpServers=h,w=!0,o++,u.push({client:d.id,removed:!0,serverName:c});else {let P=!1;for(let[v,k]of Object.entries(h))if(k?.cwd===r){delete h[v],S.mcpServers=h,w=!0,o++,P=!0,u.push({client:d.id,removed:!0,serverName:v});break}P||(f++,u.push({client:d.id,removed:!1,serverName:c}));}}w?(i.writeFileSync(d.configPath,JSON.stringify(S,null,2)+`
`),s.succeed(`Removed from ${d.name}`)):s.info(`${d.name}: Server "${c}" not found`);}catch{s.fail(`Error reading ${d.name} config`);}}console.log(),o>0?(console.log(e.green(`\u2713 Removed from ${o} client(s)
`)),console.log(e.gray(`Remember to restart your AI client(s) for changes to take effect.
`))):(console.log(e.yellow(`Server "${c}" not found in any client config.
`)),console.log(e.gray("Use `paradigm mcp list` to see all configured servers.\n"))),t.json&&console.log(JSON.stringify({targetServer:c,projectPath:r,results:u},null,2));}export{x as a,R as b,O as c,b as d,q as e,z as f,J as g,W as h,B as i};