#!/usr/bin/env node
import {a as a$1,c}from'./chunk-JBDMCRPP.js';import {a,b}from'./chunk-4TXOVRWD.js';import {m}from'./chunk-T6IDXUUA.js';import'./chunk-JIXHEBGK.js';import'./chunk-QT2LKB3P.js';import'./chunk-VCKKJDLP.js';import'./chunk-WR6D3SC6.js';import {e as e$1}from'./chunk-JQKKVAAN.js';import'./chunk-5TAVYPOV.js';import*as n from'fs';import*as e from'path';import s from'chalk';import I from'ora';async function T(i,o){let a$2=i?e.resolve(i):process.cwd(),m$1=e.basename(a$2),g=I(),f=e.join(a$2,".paradigm"),F=n.existsSync(f)&&n.statSync(f).isFile(),p;o.output?p=e.resolve(o.output):F?p=e.join(a$2,".paradigm-scan-index.json"):(p=e.join(a$2,".paradigm","scan-index.json"),n.existsSync(e.dirname(p))||n.mkdirSync(e.dirname(p),{recursive:true})),o.quiet||console.log(s.blue(`
\u{1F52D} Generating Paradigm Scan Index
`));let y,k=[e.join(a$2,".paradigm"),e.join(a$2,".paradigm","config.yaml")];for(let c of k)if(n.existsSync(c)&&n.statSync(c).isFile())try{let t=n.readFileSync(c,"utf8");y=e$1(t).scan;break}catch{}g.start("Aggregating symbols from purpose and gate files...");let r;try{r=await m(a$2);}catch(c){g.fail(s.red("Failed to aggregate symbols")),console.error(s.gray(c.message)),process.exit(1);}if(g.succeed(`Found ${r.symbols.length} symbols`),!o.quiet){let c={components:r.symbols.filter(t=>t.type==="component").length,flows:r.symbols.filter(t=>t.type==="flow").length,gates:r.symbols.filter(t=>t.type==="gate").length,signals:r.symbols.filter(t=>t.type==="signal").length,aspects:r.symbols.filter(t=>t.type==="aspect").length};console.log(s.gray("  Breakdown:"));for(let[t,u]of Object.entries(c))u>0&&console.log(s.gray(`    ${t}: ${u}`));console.log();}g.start("Generating scan index...");let l=a({symbols:r.symbols,purposeFiles:r.purposeFiles,portalFiles:r.portalFiles},{projectName:m$1,visualTagMappings:y?.visualTagMappings,screenDefinitions:y?.screens});try{n.writeFileSync(p,b(l),"utf8"),g.succeed(s.green("Scan index generated"));}catch(c){g.fail(s.red("Failed to write scan index")),console.error(s.gray(c.message)),process.exit(1);}await a$1(a$2,r,{quiet:o.quiet});let d=await c(a$2,r.purposeFiles,{quiet:o.quiet});if(d&&Object.keys(d.flows).length>0){let c=e.join(a$2,".paradigm","flow-index.json");if(n.writeFileSync(c,JSON.stringify(d,null,2),"utf8"),!o.quiet){let t=Object.keys(d.symbolToFlows).length;g.succeed(s.green(`Flow index generated (${Object.keys(d.flows).length} flows, ${t} symbol mappings)`));}}return o.quiet||(console.log(s.gray(`
  Output: ${p}`)),console.log(s.gray(`  Components: ${Object.keys(l.components).length}`)),console.log(s.gray(`  Features: ${Object.keys(l.features).length}`)),console.log(s.gray(`  Flows: ${Object.keys(l.flows).length}`)),console.log(s.gray(`  State: ${Object.keys(l.state).length}`)),console.log(s.gray(`  Gates: ${Object.keys(l.gates).length}`)),console.log(s.gray(`  Signals: ${Object.keys(l.signals).length}`)),console.log(s.gray(`  Aspects: ${Object.keys(l.aspects).length}`)),console.log(),console.log(s.blue('\u2728 Scan index ready for "paradigm scan" queries')),console.log(s.gray(`   Attach an image and say "paradigm scan" to map UI to code
`))),l}function N(i){let o=e.join(i,".paradigm");return n.existsSync(o)&&n.statSync(o).isFile()?e.join(i,".paradigm-scan-index.json"):e.join(i,".paradigm","scan-index.json")}function R(i){return n.existsSync(e.join(i,".paradigm","scan-index.json"))||n.existsSync(e.join(i,".paradigm-scan-index.json"))}function E(i){let o=[e.join(i,".paradigm","scan-index.json"),e.join(i,".paradigm-scan-index.json")];for(let a of o)if(n.existsSync(a))try{let m=n.readFileSync(a,"utf8"),g=JSON.parse(m),f=new Date(g.$meta.generatedAt).getTime();return Date.now()-f}catch{continue}return null}export{E as getScanIndexAge,N as getScanIndexPath,T as indexCommand,R as scanIndexExists};