#!/usr/bin/env node
import {m as m$1,o,C,B,r}from'./chunk-T6IDXUUA.js';import'./chunk-JIXHEBGK.js';import'./chunk-QT2LKB3P.js';import {a}from'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as u from'fs';import*as m from'path';import e from'chalk';import F from'ora';function I(t){let o={gates:[],signals:[],components:[],flows:[],aspects:[]};for(let r of t){if(!r||r.length<2)continue;switch(r[0]){case "^":o.gates.push(r);break;case "!":o.signals.push(r);break;case "#":o.components.push(r);break;case "$":o.flows.push(r);break;case "~":o.aspects.push(r);break}}return o}function T(t,o){let r$1={},g={},l=B(t),a=C(t);for(let s of a){let n=I(s.references),i={type:s.type,path:s.filePath,references:s.references,referencedBy:s.referencedBy};s.description&&(i.description=s.description),s.tags&&s.tags.length>0&&(i.tags=s.tags),n.gates.length>0&&(i.gates=n.gates),n.signals.length>0&&(i.signals=n.signals),n.components.length>0&&(i.components=n.components),n.flows.length>0&&(i.flows=n.flows),n.aspects.length>0&&(i.aspects=n.aspects),r$1[s.symbol]=i;}let y=r(t,"flow");for(let s of y){let n=s.data,i=n?.sequence||n?.gates||s.references;g[s.symbol]={description:s.description,sequence:i};}return {version:"1.0",generated:new Date().toISOString(),project:o,stats:{components:l.component,flows:l.flow,gates:l.gate,signals:l.signal,aspects:l.aspect,total:Object.values(l).reduce((s,n)=>s+n,0)},stars:r$1,orbits:g}}async function z(t,o$1={}){let r=process.cwd(),g=t?m.resolve(r,t):r,l=m.basename(g),a$1=o$1.format||"json";o$1.quiet||console.log(e.blue(`
\u2728 Building Constellation...
`));let y=F("Aggregating symbols...").start(),s=a.command("constellation").start("Building constellation",{project:l});try{let n=await m$1(g),i=o(n);a.operation("aggregate").debug("Symbols aggregated",{count:C(i).length}),y.text="Building constellation...";let p=T(i,l),$=m.join(g,".paradigm");u.existsSync($)||u.mkdirSync($,{recursive:!0});let h=o$1.output||m.join($,`constellation.${a$1}`),S;if(a$1==="yaml"?S=d(p):S=JSON.stringify(p,null,2),u.writeFileSync(h,S,"utf8"),a.component("constellation-file").success("Constellation written",{path:h,format:a$1}),y.succeed("Constellation built"),s.success("Constellation built",{path:h,stars:Object.keys(p.stars).length}),!o$1.quiet){console.log(e.white(`
Constellation Stats`)),console.log(e.gray("\u2500".repeat(40)));let f=p.stats,q=[{symbol:"#",name:"Components",count:f.components,color:e.green},{symbol:"$",name:"Flows",count:f.flows,color:e.yellow},{symbol:"^",name:"Gates",count:f.gates,color:e.red},{symbol:"!",name:"Signals",count:f.signals,color:e.cyan},{symbol:"~",name:"Aspects",count:f.aspects,color:e.magenta}];for(let{symbol:c,name:R,count:O,color:E}of q)O>0&&console.log(`  ${E(c)} ${R.padEnd(12)} ${e.cyan(O.toString())}`);console.log(e.gray("\u2500".repeat(40))),console.log(`  Total stars:    ${e.cyan(f.total.toString())}`),console.log(`  Total orbits:   ${e.cyan(Object.keys(p.orbits).length.toString())}`),console.log(e.gray(`
  Output: ${h}
`));let w=Object.entries(p.stars).find(([,c])=>c.references.length>0||c.referencedBy.length>0);if(w){console.log(e.white("Sample Star")),console.log(e.gray("\u2500".repeat(40))),console.log(e.cyan(`  ${w[0]}`));let c=w[1];c.gates?.length&&console.log(e.gray(`    gates: ${c.gates.join(", ")}`)),c.components?.length&&console.log(e.gray(`    components: ${c.components.join(", ")}`)),c.signals?.length&&console.log(e.gray(`    signals: ${c.signals.join(", ")}`)),c.referencedBy.length&&console.log(e.gray(`    referencedBy: ${c.referencedBy.join(", ")}`)),console.log("");}}if(n.errors.length>0&&!o$1.quiet){console.log(e.yellow("Warnings")),console.log(e.gray("\u2500".repeat(40)));for(let f of n.errors.slice(0,5))console.log(e.yellow(`  \u26A0 ${f.filePath}: ${f.message}`));n.errors.length>5&&console.log(e.gray(`  ... and ${n.errors.length-5} more`)),console.log("");}return p}catch(n){y.fail("Failed to build constellation"),s.error("Constellation build failed",{error:n.message}),console.log(e.red(`Error: ${n.message}
`)),process.exit(1);}}function d(t,o=0){let r="  ".repeat(o);if(t==null)return "null";if(typeof t=="string")return t.includes(":")||t.includes("#")||t.includes(`
`)||t.startsWith("@")||t.startsWith("^")?`"${t.replace(/"/g,'\\"')}"`:t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t))return t.length===0?"[]":t.map(g=>`${r}- ${d(g,o)}`).join(`
`);if(typeof t=="object"){let g=Object.entries(t);return g.length===0?"{}":g.map(([l,a])=>typeof a=="object"&&a!==null&&!Array.isArray(a)?`${r}${l}:
${d(a,o+1)}`:Array.isArray(a)?a.length===0?`${r}${l}: []`:`${r}${l}:
${d(a,o+1)}`:`${r}${l}: ${d(a,o)}`).join(`
`)}return String(t)}export{z as constellationCommand};