#!/usr/bin/env node
import {h,d,e,f as f$1,a,b,c as c$1}from'./chunk-WR6D3SC6.js';import'./chunk-5TAVYPOV.js';import*as t from'fs';import*as c from'path';import*as w from'os';import {execSync}from'child_process';import C from'ora';var f=c.join(w.homedir(),".paradigm-cli"),x=["packages/paradigm/dist","packages/paradigm/lore-ui/dist","packages/paradigm-mcp/dist","packages/premise/core/dist","packages/portal/core/dist","packages/purpose/core/dist","packages/sentinel/dist"];function D(){let r=process.cwd();for(let o=0;o<5;o++){if(t.existsSync(c.join(r,"packages","paradigm","package.json"))&&t.existsSync(c.join(r,"packages","paradigm-mcp","package.json")))return r;let s=c.dirname(r);if(s===r)break;r=s;}return null}function $(r,o){let s=0,i=[];if(!t.existsSync(r))return i.push(`Source not found: ${r}`),{files:s,errors:i};t.mkdirSync(o,{recursive:true});let n=t.readdirSync(r,{withFileTypes:true});for(let l of n){let d=c.join(r,l.name),e=c.join(o,l.name);try{if(l.isDirectory()){let p=$(d,e);s+=p.files,i.push(...p.errors);}else t.copyFileSync(d,e),s++;}catch(p){i.push(`Failed to copy ${d}: ${p instanceof Error?p.message:String(p)}`);}}return {files:s,errors:i}}async function E(r){let o=C(),s=D();if(!s){r.json?h({error:"Not in paradigm source repo"}):(d("Not in the paradigm source repository."),e(`Run this command from the a-paradigm directory.
`));return}if(!t.existsSync(f)){if(!r.force){r.json?h({error:"Production directory not found",path:f}):(d(`Production directory not found: ${f}`),e("Paradigm CLI may not be globally installed."),e(`Install with: curl -fsSL https://a-company.org/install | bash
`));return}t.mkdirSync(f,{recursive:true});}if(r.json||(f$1("\u{1F4E6} Promoting local build to production"),a(""),e(`  Source: ${s}`),e(`  Target: ${f}
`)),!r.skipBuild){o.start("Building packages...");try{execSync("npm run build",{cwd:s,stdio:"pipe",timeout:12e4}),o.succeed("Build complete");}catch(e$1){o.fail("Build failed"),r.json?h({error:"Build failed",details:e$1 instanceof Error?e$1.message:String(e$1)}):(d(`${e$1 instanceof Error?e$1.message:e$1}`),e(`Fix build errors and try again, or use --skip-build.
`));return}}o.start("Copying dist/ to production...");let i=0,n=[],l=[];for(let e of x){let p=c.join(s,e),b=c.join(f,e);if(!t.existsSync(p))continue;let{files:h,errors:y}=$(p,b);i+=h,n.push(...y),y.length===0&&h>0&&l.push(e);}n.length>0?o.warn(`Copied with ${n.length} error(s)`):o.succeed(`Copied ${i} files`),o.start("Switching MCP configs to PROD...");try{let{mcpUseProdCommand:e}=await import('./switch-RXEXXIN7.js');await e({json:!0}),o.succeed("MCP configs switched to PROD");}catch{o.info("MCP config switch skipped (no configs found)");}let d$1="unknown";try{d$1=execSync("paradigm --version",{encoding:"utf-8",timeout:5e3}).trim();}catch{}if(r.json)h({success:n.length===0,source:s,target:f,packages:l,totalFiles:i,errors:n,version:d$1});else {if(a(""),n.length===0)b(`Promotion complete!
`);else {c$1(`Promotion completed with ${n.length} error(s)
`);for(let e of n.slice(0,5))d(`  ${e}`);a("");}e(`  Packages: ${l.length}`),e(`  Files:    ${i}`),e(`  Version:  ${d$1}`),a("");}}export{E as promoteCommand};