#!/usr/bin/env node
import {a,g}from'./chunk-22ISTMKI.js';import'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as m from'fs';import*as p from'path';import n from'chalk';import y from'ora';function C(){let o=process.cwd();for(let t=0;t<5;t++){if(m.existsSync(p.join(o,"packages","paradigm-mcp","dist","index.js")))return o;let i=p.dirname(o);if(i===o)break;o=i;}return null}function S(o,t){return o.toLowerCase().includes("paradigm")||t==="paradigm-mcp"||t.includes("paradigm-mcp")}function w(o,t,i){if(!m.existsSync(o.configPath))return {success:false,message:"Config file not found",changed:false};let r;try{let g=m.readFileSync(o.configPath,"utf-8");r=JSON.parse(g);}catch{return {success:false,message:"Could not parse config",changed:false}}let a=false;if(o.id==="continue"){let g=r?.experimental?.modelContextProtocolServers||[];for(let s of g){let e=s?.transport;if(!e)continue;(e.command==="paradigm-mcp"||e.command==="node"&&String(e.args?.[0]||"").includes("paradigm-mcp"))&&(t==="dev"?(e.command="node",e.args=[i,"."]):(e.command="paradigm-mcp",e.args=["."]),a=true);}}else {let g=r?.mcpServers||{};for(let[s,e]of Object.entries(g))S(s,e?.command||"")&&(t==="dev"?(e.command="node",e.args=[i,...e.args?.filter(c=>c!=="paradigm-mcp")||["."]],e.args.some(c=>c==="."||c.startsWith("/"))||e.args.push("."),e.args=[...new Set(e.args)]):(e.command="paradigm-mcp",e.args=["."]),a=true);}return a&&m.writeFileSync(o.configPath,JSON.stringify(r,null,2)+`
`),{success:true,message:a?`Switched to ${t} mode`:"No paradigm server found",changed:a}}async function k(o){let t=y(),i=C();if(!i){o.json?console.log(JSON.stringify({error:"Not in paradigm source repo or packages/paradigm-mcp/dist/index.js not found"})):(console.log(n.red(`
Not in paradigm source repo.`)),console.log(n.gray("Run from the a-paradigm directory, or ensure packages/paradigm-mcp/dist/index.js exists.")),console.log(n.gray("You may need to run `npm run build` first.\n")));return}let r=p.join(i,"packages","paradigm-mcp","dist","index.js");if(!m.existsSync(r)){o.json?console.log(JSON.stringify({error:"MCP dist not built",path:r})):(console.log(n.red(`
MCP dist not built.`)),console.log(n.gray(`Expected: ${r}`)),console.log(n.gray("Run `npm run build` first.\n")));return}o.json||(console.log(n.blue(`
\u{1F527} Switching to DEV mode
`)),console.log(n.gray(`  Source: ${r}
`)));let a$1=a(),g=o.client?a$1.filter(c=>c.id===o.client):a$1,s=[];for(let c of g){t.start(`Switching ${c.name}...`);let d=w(c,"dev",r);d.changed?t.succeed(`${c.name} \u2192 DEV`):d.success?t.info(`${c.name}: ${d.message}`):t.warn(`${c.name}: ${d.message}`),s.push({client:c.id,changed:d.changed,message:d.message});}let e=s.filter(c=>c.changed).length;o.json||(console.log(),e>0?(console.log(n.green(`\u2713 Switched ${e} client(s) to DEV mode
`)),console.log(n.gray("  Restart your AI client(s) for changes to take effect.")),console.log(n.gray("  Run `paradigm mcp use-prod` to switch back.\n"))):(console.log(n.yellow(`No paradigm MCP servers found to switch.
`)),console.log(n.gray("Run `paradigm mcp setup` first to configure MCP.\n")))),o.json&&console.log(JSON.stringify({mode:"dev",devPath:r,results:s},null,2));}async function x(o){let t=y();o.json||console.log(n.blue(`
\u{1F527} Switching to PROD mode
`));let i=a(),r=o.client?i.filter(s=>s.id===o.client):i,a$1=[];for(let s of r){t.start(`Switching ${s.name}...`);let e=w(s,"prod","");e.changed?t.succeed(`${s.name} \u2192 PROD`):e.success?t.info(`${s.name}: ${e.message}`):t.warn(`${s.name}: ${e.message}`),a$1.push({client:s.id,changed:e.changed,message:e.message});}let g=a$1.filter(s=>s.changed).length;o.json||(console.log(),g>0?(console.log(n.green(`\u2713 Switched ${g} client(s) to PROD mode
`)),console.log(n.gray(`  Restart your AI client(s) for changes to take effect.
`))):console.log(n.yellow(`No paradigm MCP servers found to switch.
`))),o.json&&console.log(JSON.stringify({mode:"prod",results:a$1},null,2));}async function O(o){console.log(n.blue(`
\u{1F50C} Paradigm MCP Status
`));let t=a(),i=[];for(let r of t){let g$1=g(r).filter(l=>S(l.name,l.command)),s="none",e=[];for(let l of g$1){let f="unknown";l.command==="paradigm-mcp"?f="prod":l.command==="node"&&l.args.some(P=>P.includes("paradigm-mcp"))&&(f="dev"),e.push({name:l.name,command:l.command,mode:f}),s==="none"&&(s=f);}let c=g$1.length>0,d=s==="dev"?n.yellow("[DEV]"):s==="prod"?n.green("[PROD]"):s==="none"?n.gray("[\u2014]"):n.gray("[?]"),v=r.detected?c?n.green("\u2713"):n.yellow("\u25CB"):n.gray("\u25CB"),M=c?`configured ${d}`:r.detected?n.yellow("not configured"):n.gray("not detected");if(console.log(`  ${v} ${r.name}: ${M}`),c)for(let l of e){let f=l.mode==="dev"?n.yellow("DEV"):l.mode==="prod"?n.green("PROD"):n.gray("?");console.log(n.gray(`     ${l.name}: ${l.command} (${f})`));}i.push({client:r.id,name:r.name,detected:r.detected,configured:c,mode:s,path:r.configPath,servers:e});}console.log(),o.json&&console.log(JSON.stringify(i,null,2));}export{O as mcpSwitchStatusCommand,k as mcpUseDevCommand,x as mcpUseProdCommand};