#!/usr/bin/env node
import {m,o,C,B}from'./chunk-T6IDXUUA.js';import'./chunk-JIXHEBGK.js';import'./chunk-QT2LKB3P.js';import {a}from'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as i from'fs';import*as c from'path';import n from'chalk';import O from'ora';function G(u){let o=[],g=[{pattern:"portal.yaml",desc:"Authorization topology"},{pattern:"src/lib/api.ts",desc:"API utilities"},{pattern:"src/lib/api.js",desc:"API utilities"},{pattern:"src/utils/api.ts",desc:"API utilities"},{pattern:"src/hooks/useAuth.ts",desc:"Auth hook"},{pattern:"src/hooks/useAuth.tsx",desc:"Auth hook"},{pattern:"src/context/AuthContext.tsx",desc:"Auth context"},{pattern:"src/store/index.ts",desc:"State store"},{pattern:"src/types/index.ts",desc:"Type definitions"},{pattern:"src/types.ts",desc:"Type definitions"},{pattern:".paradigm/config.yaml",desc:"Paradigm config"},{pattern:"tsconfig.json",desc:"TypeScript config"},{pattern:"package.json",desc:"Package manifest"}];for(let{pattern:r,desc:l}of g){let t=c.join(u,r);i.existsSync(t)&&o.push({path:r,description:l});}return o.slice(0,8)}function E(u){let o=c.join(u,".paradigm","prompts"),g=[];if(i.existsSync(o)){let r=i.readdirSync(o).filter(l=>l.endsWith(".md"));for(let l of r){let t=l.replace(".md","").replace(/-/g," ");g.push({name:t.charAt(0).toUpperCase()+t.slice(1),path:`.paradigm/prompts/${l}`});}}return g.slice(0,6)}function I(u,o,g,r,l){let t=[];t.push(`# Beacon - ${u}`),t.push(""),t.push("> Quick-start orientation for AI agents. Generated by Paradigm."),t.push(""),t.push("## Constellation (Symbol Map)"),t.push(""),t.push("```");let a=o.filter(e=>e.type==="component"),m=o.filter(e=>e.type==="gate");for(let e of a.slice(0,15)){let p=e.references.filter(d=>d.startsWith("^")),b=`${e.symbol.padEnd(20)} \u2192 ${c.dirname(e.filePath).padEnd(25)}`;p.length>0&&(b+=` \u2192 ${p.join(", ")}`),t.push(b);}if(a.length>15&&t.push(`... and ${a.length-15} more components`),t.push("```"),t.push(""),m.length>0){t.push("## Gates (Authorization)"),t.push("");for(let e of m.slice(0,6)){let p=e.description?` - ${e.description}`:"";t.push(`- \`${e.symbol}\`${p}`);}m.length>6&&t.push(`- ... and ${m.length-6} more gates`),t.push("");}if(g.length>0){t.push("## Landmarks (Key Files)"),t.push("");for(let e of g)t.push(`- \`${e.path}\` - ${e.description}`);t.push("");}if(r.length>0){t.push("## Pathways (Common Tasks)"),t.push("");for(let e of r)t.push(`- "${e.name}" \u2192 \`${e.path}\``);t.push("");}return t.push("## Symbol Quick Reference"),t.push(""),t.push("| Symbol | Type | Meaning |"),t.push("|--------|------|---------|"),t.push("| `#` | Component | Any documented code unit |"),t.push("| `$` | Flow | Multi-step process |"),t.push("| `^` | Gate | Authorization checkpoint |"),t.push("| `!` | Signal | Event for side effects |"),t.push("| `~` | Aspect | Rule with code anchor |"),t.push(""),t.push("## For More Context"),t.push(""),t.push("- Full symbol graph: `.paradigm/constellation.json`"),t.push("- Detailed context: `.paradigm/specs/` for detailed specifications"),t.push("- Session history: `.paradigm/thread.md` (if available)"),t.push("- Error mapping: `.paradigm/echoes.yaml` (if available)"),t.push(""),t.push("---"),t.push(`*Generated: ${new Date().toISOString().split("T")[0]}*`),t.push("*Run `paradigm beacon --refresh` to update*"),t.join(`
`)}async function q(u,o$1={}){let g=process.cwd(),r=u?c.resolve(g,u):g,l=c.basename(r),t=!o$1.json&&!o$1.quiet;t&&console.log(n.blue(`
\u{1F526} Generating Beacon...
`));let a$1=o$1.json?null:O("Scanning project...").start(),m$1=a.command("beacon").start("Generating beacon",{project:l});try{let e=c.join(r,".paradigm"),p=o$1.output||c.join(e,"beacon.md");if(!o$1.json&&i.existsSync(p)&&!o$1.refresh){if(a$1?.info("Beacon already exists"),t){console.log(n.gray(`  Use --refresh to regenerate
`)),console.log(n.gray(`  Path: ${p}
`));let w=i.readFileSync(p,"utf8").split(`
`).slice(0,15);console.log(n.white("Current Beacon (preview):")),console.log(n.gray("\u2500".repeat(40)));for(let f of w)console.log(n.gray(`  ${f}`));console.log(n.gray("  ...")),console.log("");}return}let b=await m(r),d=o(b),S=C(d);a$1&&(a$1.text="Finding landmarks...");let $=G(r);a$1&&(a$1.text="Finding pathways...");let j=E(r);if(o$1.json){let h=S.filter(s=>s.type==="component"),w=S.filter(s=>s.type==="gate"),f=B(d),k={project:l,generated:new Date().toISOString(),symbols:{features:h.filter(s=>s.tags?.includes("feature")).map(s=>({symbol:s.symbol,path:c.dirname(s.filePath),portals:s.references.filter(y=>y.startsWith("^")).length>0?s.references.filter(y=>y.startsWith("^")):void 0})),components:h.map(s=>({symbol:s.symbol,path:c.dirname(s.filePath)})),portals:w.map(s=>({symbol:s.symbol,description:s.description}))},landmarks:$,pathways:j,stats:{features:h.filter(s=>s.tags?.includes("feature")).length,components:f.component,portals:f.gate,total:Object.values(f).reduce((s,y)=>s+y,0)}};return console.log(JSON.stringify(k,null,2)),k}a$1&&(a$1.text="Generating beacon...");let F=I(l,S,$,j,r);if(i.existsSync(e)||i.mkdirSync(e,{recursive:!0}),i.writeFileSync(p,F,"utf8"),a.component("beacon-file").success("Beacon file written",{path:p}),a$1?.succeed("Beacon generated"),m$1.success("Beacon generated",{path:p,symbols:S.length}),!o$1.quiet){let h=B(d);console.log(n.white(`
Beacon Contents`)),console.log(n.gray("\u2500".repeat(40))),console.log(`  Components:  ${n.green(h.component.toString())}`),console.log(`  Flows:       ${n.yellow(h.flow.toString())}`),console.log(`  Gates:       ${n.red(h.gate.toString())}`),console.log(`  Signals:     ${n.cyan(h.signal.toString())}`),console.log(`  Aspects:     ${n.magenta(h.aspect.toString())}`),console.log(`  Landmarks:   ${n.cyan($.length.toString())}`),console.log(`  Pathways:    ${n.yellow(j.length.toString())}`),console.log(n.gray(`
  Output: ${p}
`)),console.log(n.white("Tip")),console.log(n.gray("\u2500".repeat(40))),console.log(n.gray("  AI agents should read beacon.md first for quick orientation.")),console.log(n.gray(`  Then constellation.json for detailed relationships.
`));}}catch(e){a$1?.fail("Failed to generate beacon"),m$1.error("Beacon generation failed",{error:e.message}),console.log(n.red(`Error: ${e.message}
`)),process.exit(1);}}export{q as beaconCommand};