#!/usr/bin/env node
import {a,b}from'./chunk-4TXOVRWD.js';import {m}from'./chunk-T6IDXUUA.js';import {b as b$1}from'./chunk-VCKKJDLP.js';import*as u from'fs';import*as p from'path';import*as $ from'js-yaml';import g from'chalk';import q from'ora';var _={"@":{category:"features",prefix:"@"},"#":{category:"components",prefix:"#"},"^":{category:"gates",prefix:"^"},$:{category:"flows",prefix:"$"},"&":{category:"integrations",prefix:"&"},"!":{category:"signals",prefix:"!"},"%":{category:"state",prefix:"%"}},N={features:["src/features/","features/","app/","src/app/","src/modules/","modules/"],components:["src/components/","components/","src/lib/","lib/","src/ui/","ui/"],gates:["middleware/","src/middleware/","auth/","src/auth/","guards/","src/guards/"],flows:["flows/","src/flows/","workflows/","src/workflows/","sagas/","src/sagas/"],integrations:["integrations/","src/integrations/","external/","src/external/","vendors/"],signals:["events/","src/events/","handlers/","src/handlers/"],state:["stores/","src/stores/","state/","src/state/","reducers/","src/reducers/"]},z={config:[".paradigm/config.yaml","package.json","tsconfig.json",".env.example"],entry:["src/index.ts","src/index.tsx","src/main.ts","src/main.tsx","index.ts","main.ts","src/app.ts","src/app.tsx"],types:["src/types/","types/","src/types.ts","types.ts"]},G={always:["node_modules/","dist/","build/",".git/",".next/",".nuxt/",".cache/","*.lock","*.log"],unless_testing:["**/*.test.ts","**/*.test.tsx","**/*.spec.ts","**/*.spec.tsx","__tests__/","test/","tests/"],unless_docs:["docs/","*.md","README*","CHANGELOG*"]};async function A(o,t,n={}){let r=n.quiet?null:q();r?.start("Generating navigator.yaml...");let s=M(o),e=L(o),c=H(o),i=U(t.symbols,t.purposeFiles),f={version:"1.0",generated:new Date().toISOString(),structure:s,key_files:e,skip_patterns:c,symbols:i},a=p.join(o,".paradigm"),l=p.join(a,"navigator.yaml");u.existsSync(a)||u.mkdirSync(a,{recursive:true}),u.writeFileSync(l,$.dump(f,{indent:2,lineWidth:120,noRefs:true,sortKeys:false}),"utf8"),r?.succeed(g.green("Navigator generated")),n.quiet||(console.log(g.gray(`  Output: ${l}`)),console.log(g.gray(`  Structure categories: ${Object.keys(s).length}`)),console.log(g.gray(`  Symbol mappings: ${Object.keys(i).length}`)),console.log());}function M(o){let t={};for(let[n,r]of Object.entries(N)){let s=r.filter(e=>{let c=p.join(o,e);return u.existsSync(c)});if(s.length>0){let e=Object.values(_).find(c=>c.category===n);t[n]={paths:s,symbol:e?.prefix||"@"};}}return t}function L(o){let t={};for(let[n,r]of Object.entries(z)){let s=r.filter(e=>{let c=p.join(o,e);return u.existsSync(c)});s.length>0&&(t[n]=s);}return t.config||(t.config=[]),t.entry||(t.entry=[]),t.types||(t.types=[]),t}function H(o){let t={...G},n=p.join(o,".gitignore");if(u.existsSync(n))try{let s=u.readFileSync(n,"utf8").split(`
`).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).filter(e=>e.endsWith("/")||e.includes("*")||["node_modules","dist","build",".cache"].some(c=>e.includes(c))).slice(0,20);for(let e of s)t.always.includes(e)||t.always.push(e);}catch{}return t}function U(o,t,n){let r={},s=new Map;for(let e of t){let c=p.dirname(e);s.set(e,c);}for(let e of o){let i=`${W(e.type)}${e.id}`;if(e.path)r[i]=e.path;else if(e.directory)r[i]=e.directory;else {let f=t.find(a=>{let l=p.dirname(a),y=e.id.toLowerCase();return l.toLowerCase().includes(y)});f&&(r[i]=p.dirname(f)+"/");}}return r}function W(o){switch(o){case "feature":return "@";case "component":return "#";case "gate":return "^";case "flow":return "$";case "integration":return "&";case "signal":return "!";case "state":return "%";case "idea":return "?";case "deprecated":return "~";default:return "@"}}function P(o){return $.load(o)}async function ce(o,t){let n=o?p.resolve(o):process.cwd(),r=p.basename(n),s=q(),e=p.join(n,".paradigm"),c=u.existsSync(e)&&u.statSync(e).isFile(),i;t.output?i=p.resolve(t.output):c?i=p.join(n,".paradigm-scan-index.json"):(i=p.join(n,".paradigm","scan-index.json"),u.existsSync(p.dirname(i))||u.mkdirSync(p.dirname(i),{recursive:true})),t.quiet||console.log(g.blue(`
\u{1F52D} Generating Paradigm Scan Index
`));let f,a$1,l,y=[p.join(n,".paradigm"),p.join(n,".paradigm","config.yaml")];for(let h of y)if(u.existsSync(h)&&u.statSync(h).isFile())try{let m=u.readFileSync(h,"utf8"),F=P(m);f=F.scan,a$1=F.graph,l=F.context?.tiers;break}catch{}s.start("Aggregating symbols from purpose and portal files...");let d;try{d=await m(n);}catch(h){s.fail(g.red("Failed to aggregate symbols")),console.error(g.gray(h.message)),process.exit(1);}if(s.succeed(`Found ${d.symbols.length} symbols`),!t.quiet){let h={components:d.symbols.filter(m=>m.type==="component").length,flows:d.symbols.filter(m=>m.type==="flow").length,gates:d.symbols.filter(m=>m.type==="gate").length,signals:d.symbols.filter(m=>m.type==="signal").length,aspects:d.symbols.filter(m=>m.type==="aspect").length};console.log(g.gray("  Breakdown:"));for(let[m,S]of Object.entries(h))S>0&&console.log(g.gray(`    ${m}: ${S}`));console.log();}s.start("Generating scan index...");let b$2=a({symbols:d.symbols,purposeFiles:d.purposeFiles,portalFiles:d.portalFiles},{projectName:r,visualTagMappings:f?.visualTagMappings,screenDefinitions:f?.screens});K(b$2,{hot:l?.["hot-threshold"],warm:l?.["warm-threshold"]});try{u.writeFileSync(i,b(b$2),"utf8"),s.succeed(g.green("Scan index generated"));}catch(h){s.fail(g.red("Failed to write scan index")),console.error(g.gray(h.message)),process.exit(1);}await A(n,d,{quiet:t.quiet});let j=await Y(n,d.purposeFiles,{quiet:t.quiet});if(j&&Object.keys(j.flows).length>0){let h=p.join(n,".paradigm","flow-index.json");u.writeFileSync(h,JSON.stringify(j,null,2),"utf8"),t.quiet||s.succeed(g.green(`Flow index generated (${Object.keys(j.flows).length} flows)`));}if(a$1?.["auto-generate"]!==false)try{let h=b$1(n),m=p.join(n,".paradigm","graphs");u.existsSync(m)||u.mkdirSync(m,{recursive:!0});let S=p.join(m,"auto.graph.json");u.writeFileSync(S,JSON.stringify(h,null,2),"utf8"),t.quiet||s.succeed(g.green(`Symbol graph updated (${h.nodes.length} nodes)`));}catch{t.quiet||s.warn(g.yellow("Could not auto-generate symbol graph"));}return t.quiet||(console.log(g.gray(`
  Output: ${i}`)),console.log(g.gray(`  Components: ${Object.keys(b$2.components).length}`)),console.log(g.gray(`  Features: ${Object.keys(b$2.features).length}`)),console.log(g.gray(`  Flows: ${Object.keys(b$2.flows).length}`)),console.log(g.gray(`  State: ${Object.keys(b$2.state).length}`)),console.log(g.gray(`  Gates: ${Object.keys(b$2.gates).length}`)),console.log(g.gray(`  Signals: ${Object.keys(b$2.signals).length}`)),console.log(),console.log(g.blue('\u2728 Scan index ready for "paradigm probe" queries')),console.log(g.gray(`   Attach an image and say "paradigm probe" to map UI to code
`))),b$2}function K(o,t){let n=t?.hot??15,r=t?.warm??5,s=new Map,e=["components","flows","gates","signals","aspects","features","state"];for(let c of e){let i=o[c];if(i)for(let[,f]of Object.entries(i)){let a=f.related;if(a)for(let l of a){let y=l.replace(/^[#$^!~]/,"");s.set(y,(s.get(y)||0)+1);}}}for(let c of e){let i=o[c];if(i)for(let[f,a]of Object.entries(i)){let l=s.get(f)||0,d=(a.visualTags||[]).length,b=l*3+d;a.tier=b>n?"hot":b>r?"warm":"cold";}}}async function Y(o,t,n){let r={},s={};for(let e of t)try{let c=u.readFileSync(e,"utf8"),i=$.load(c);if(!i?.flows)continue;if(Array.isArray(i.flows))for(let f of i.flows){let a=f;if(!a.name)continue;let l=`$${a.name}`,y=T(a.steps);if(y.length>0){let d={id:l,description:a.description||"",steps:y,definedIn:p.relative(o,e)};r[l]=d,D(l,y,s);}}else for(let[f,a]of Object.entries(i.flows)){let l=f.startsWith("$")?f:`$${f}`,y=T(a.steps);if(y.length>0){let d={id:l,description:a.description||"",trigger:a.trigger,steps:y,validation:a.validation,definedIn:p.relative(o,e)};r[l]=d,D(l,y,s);}}}catch(c){n.quiet||console.warn(g.yellow(`  Warning: Could not parse flows from ${e}: ${c.message}`));}return Object.keys(r).length===0?null:{version:"1.0",generatedAt:new Date().toISOString(),flows:r,symbolToFlows:s}}function T(o){if(!o||!Array.isArray(o))return [];let t=[];for(let n=0;n<o.length;n++){let r=o[n];if(typeof r=="object"&&r!==null){let s=r,e=s.action||s.description||s.component||"";e&&t.push({id:s.id||`step-${n+1}`,action:e,symbol:s.symbol||s.component,expect:s.expect});}}return t}function D(o,t,n){for(let r of t)r.symbol&&(n[r.symbol]||(n[r.symbol]=[]),n[r.symbol].includes(o)||n[r.symbol].push(o));}export{A as a,ce as b,Y as c};