#!/usr/bin/env node
import {d,f,b,a as a$1,g,c,e as e$1,h}from'./chunk-DOCDDDTD.js';import {a}from'./chunk-LKAT7IAK.js';import*as S from'path';import e from'chalk';import M from'ora';async function q(b$1,a$2){let i=process.cwd(),r=M(),x=a$2.target||b$1,o=a$2.quiet;o||console.log(e.blue(`
\u{1F504} Paradigm Sync
`)),o||r.start("Loading .paradigm/ configuration...");let f$1=d(i);if(!f$1)throw o||(r.fail("No .paradigm/ directory found"),console.log(e.gray("\nRun `paradigm init` to initialize Paradigm in this project.\n"))),a.command("sync").error("Missing .paradigm/ directory"),o||process.exit(1),new Error("No .paradigm/ directory found");if(o||r.succeed(`Loaded configuration for ${e.cyan(f$1.projectName)}`),a.command("sync").debug("Configuration loaded",{projectName:f$1.projectName}),a$2.all){console.log(e.gray(`
Syncing to all IDEs...
`));let n=a.operation("sync-all").start("Syncing to all IDEs"),g$1=f(i,f$1,a$2.force);for(let s of g$1)s.success?(console.log(e.green(`  \u2713 ${s.ide}`),e.gray(`\u2192 ${s.outputPath}`)),a.operation(`sync-${s.ide}`).success("IDE files generated",{path:s.outputPath})):(console.log(e.red(`  \u2717 ${s.ide}`),e.gray(`\u2192 ${s.message}`)),a.operation(`sync-${s.ide}`).error("Sync failed",{message:s.message}));let p=g$1.filter(s=>s.success).length;if(console.log(e.gray(`
${p}/${g$1.length} IDE files generated.`)),p===g$1.length?n.success("All IDE files generated",{count:g$1.length}):n.error("Some IDE syncs failed",{success:p,total:g$1.length}),a$2.mcp!==false){console.log("");let s=b();for(let u of s)if(a$1(u)?.generateMcpConfig){let y=g(i,u);y.success&&(console.log(e.green(`  \u2713 MCP config for ${u}`),e.gray(`\u2192 ${S.relative(i,y.path)}`)),a.component("mcp-config").success("MCP config generated",{ide:u,path:y.path}));}}console.log("");return}let t=x;if(!t){o||r.start("Auto-detecting IDE...");let n=c(i);n.detected?(t=n.detected,o||r.succeed(`Detected ${e.cyan(t)} (${n.reason})`)):(o||r.warn("Could not auto-detect IDE, defaulting to Cursor"),t="cursor");}let l=a$1(t);if(!l)throw o||(console.log(e.red(`
\u274C Unknown IDE: ${t}`)),console.log(e.gray(`
Available IDEs: ${b().join(", ")}
`))),a.command("sync").error("Unknown IDE",{ide:t,available:b()}),o||process.exit(1),new Error(`Unknown IDE: ${t}`);let E=l.multiFile;o||r.start(`Generating ${E?l.outputPath+"/":l.outputPath}...`);let D=a.operation(`sync-${t}`).start("Syncing IDE files",{ide:t}),d$1=e$1(i,t,f$1,a$2.force);if(d$1.success){if(!o&&(r.succeed(e.green(d$1.message)),console.log(e.gray(`
  Path: ${d$1.outputPath}`)),E&&l.generateFiles)){let n=l.generateFiles(f$1);for(let g of n)console.log(e.gray(`    \u2514\u2500 ${g.path}`));}if(D.success("IDE files generated",{ide:t,path:d$1.outputPath}),a$2.mcp!==false&&l.generateMcpConfig){let n=g(i,t);n.success&&(o||console.log(e.green(`
  \u2713 ${n.message}`)),a.component("mcp-config").success("MCP config generated",{ide:t,path:n.path}));}if(a$2.nested&&l.generateNestedContexts){let n=h(i,t,f$1);n.success&&n.count>0&&(o||console.log(e.green(`
  \u2713 ${n.message}`)),a.component("nested-contexts").success("Nested contexts generated",{ide:t,count:n.count}));}o||console.log("");}else throw o||r.fail(e.red(d$1.message)),D.error("Sync failed",{ide:t,message:d$1.message}),o||process.exit(1),new Error(d$1.message||"Sync failed")}export{q as a};