#!/usr/bin/env node
import {D as D$1,m,o,r,p,x,y}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'path';import e from'chalk';import F from'ora';function I(s,t){let r$1=r(t,"flow"),a=[];for(let p of r$1){let l=p.data,i=l?.sequence||l?.gates||p.references,g=i.indexOf(s);g!==-1&&a.push({flow:p.symbol,position:g+1,total:i.length});}return a}function O(s){let t=u.dirname(s),r=`${t}/**/*.test.{ts,tsx}`,a=`npm test -- --testPathPattern="${t}"`;return {testPath:r,testCommand:a}}function C(s){return {components:s.filter(t=>t.type==="component").map(t=>t.symbol),gates:s.filter(t=>t.type==="gate").map(t=>t.symbol),signals:s.filter(t=>t.type==="signal").map(t=>t.symbol),flows:s.filter(t=>t.type==="flow").map(t=>t.symbol),aspects:s.filter(t=>t.type==="aspect").map(t=>t.symbol)}}function B(s,t){let r=p(t,s);if(!r)return null;let a=x(t,s),p$1=y(t,s),l=C(a),i=C(p$1),g=I(s,t),{testPath:m,testCommand:y$1}=O(r.filePath);return {symbol:r.symbol,type:r.type,path:r.filePath,description:r.description,requires:r.references,requiredBy:r.referencedBy,downstream:{components:l.components,signals:l.signals,aspects:l.aspects},upstream:{gates:i.gates,flows:i.flows},partOfFlows:g,testPath:m,testCommand:y$1}}async function D(s,t,r$1={}){let a$1=process.cwd(),p=t?u.resolve(a$1,t):a$1,l=D$1(s);l||(console.log(e.red(`
\u274C Invalid symbol format: ${s}`)),console.log(e.gray("  Symbols must start with @, #, ^, !, $, %, ~, or ?")),console.log(e.gray(`  Example: paradigm ripple @checkout
`)),process.exit(1)),!r$1.quiet&&!r$1.json&&console.log(e.blue(`
\u{1F30A} Ripple Analysis for ${e.cyan(s)}
`));let i=a.command("ripple").start("Analyzing ripple effects",{symbol:s}),g=r$1.json?null:F("Analyzing impact...").start();try{let m$1=await m(p),y=o(m$1);a.operation("aggregate").debug("Symbols aggregated for ripple",{symbol:s});let o$1=B(s,y);if(!o$1){g?.fail(`Symbol not found: ${s}`),i.error("Symbol not found",{symbol:s}),console.log(e.gray(`
  Available symbols of this type:`));let c=r(y,l.type).slice(0,5);for(let n of c)console.log(e.gray(`    ${n.symbol}`));r(y,l.type).length>5&&console.log(e.gray("    ... and more")),console.log(""),process.exit(1);}if(g?.succeed("Impact analyzed"),i.success("Ripple analysis complete",{symbol:s,requires:o$1.requires.length,requiredBy:o$1.requiredBy.length}),r$1.json)return console.log(JSON.stringify(o$1,null,2)),o$1;if(console.log(e.white("Symbol Info")),console.log(e.gray("\u2500".repeat(50))),console.log(`  Type:        ${e.cyan(o$1.type)}`),console.log(`  Path:        ${e.gray(o$1.path)}`),o$1.description&&console.log(`  Description: ${o$1.description}`),console.log(""),o$1.requires.length>0){console.log(e.white("\u2B06\uFE0F  Upstream (What this requires)")),console.log(e.gray("\u2500".repeat(50))),o$1.upstream.gates.length>0&&console.log(`  Gates:    ${o$1.upstream.gates.map(n=>e.red(n)).join(", ")}`),o$1.upstream.flows.length>0&&console.log(`  Flows:    ${o$1.upstream.flows.map(n=>e.cyan(n)).join(", ")}`);let c=o$1.requires.filter(n=>!o$1.upstream.gates.includes(n)&&!o$1.upstream.flows.includes(n));c.length>0&&console.log(`  Other:    ${c.map(n=>e.gray(n)).join(", ")}`),console.log("");}if(o$1.requiredBy.length>0){console.log(e.white("\u2B07\uFE0F  Downstream (What would be affected)")),console.log(e.gray("\u2500".repeat(50))),o$1.downstream.components.length>0&&console.log(`  Components:  ${o$1.downstream.components.map(n=>e.green(n)).join(", ")}`),o$1.downstream.signals.length>0&&console.log(`  Signals:     ${o$1.downstream.signals.map(n=>e.yellow(n)).join(", ")}`),o$1.downstream.aspects.length>0&&console.log(`  Aspects:     ${o$1.downstream.aspects.map(n=>e.magenta(n)).join(", ")}`);let c=o$1.requiredBy.filter(n=>!o$1.downstream.components.includes(n)&&!o$1.downstream.signals.includes(n)&&!o$1.downstream.aspects.includes(n));c.length>0&&console.log(`  Other:       ${c.map(n=>e.gray(n)).join(", ")}`),console.log("");}if(o$1.partOfFlows.length>0){console.log(e.white("\u{1F504} Part of Flows")),console.log(e.gray("\u2500".repeat(50)));for(let{flow:c,position:n,total:x}of o$1.partOfFlows)console.log(`  ${e.cyan(c)} (step ${n} of ${x})`);console.log("");}o$1.testCommand&&(console.log(e.white("\u{1F9EA} Test Suggestion")),console.log(e.gray("\u2500".repeat(50))),console.log(`  ${e.gray(o$1.testCommand)}`),console.log(""));let f=o$1.requiredBy.length,j=f===0?"Low":f<=3?"Medium":"High",P=f===0?e.green:f<=3?e.yellow:e.red;return console.log(e.white("\u{1F4CA} Impact Summary")),console.log(e.gray("\u2500".repeat(50))),console.log(`  Direct dependents: ${e.cyan(f.toString())}`),console.log(`  Impact level:      ${P(j)}`),f>0?console.log(e.gray(`
  \u26A0\uFE0F  Changes to this symbol may affect the above dependents.`)):console.log(e.gray(`
  \u2713  This symbol has no direct dependents (safe to modify).`)),console.log(""),o$1}catch(m){g?.fail("Analysis failed"),i.error("Ripple analysis failed",{symbol:s,error:m.message}),console.log(e.red(`Error: ${m.message}
`)),process.exit(1);}}export{D as rippleCommand};