#!/usr/bin/env node
import {b,c as c$2}from'./chunk-W7C6FFMO.js';import'./chunk-4TXOVRWD.js';import {g}from'./chunk-T6IDXUUA.js';import {c as c$1}from'./chunk-JIXHEBGK.js';import'./chunk-QT2LKB3P.js';import {d as d$1,b as b$1,a}from'./chunk-JQKKVAAN.js';import'./chunk-XHJ27CER.js';import*as n from'fs';import*as c from'path';import*as D from'readline';import e from'chalk';function x(){return D.createInterface({input:process.stdin,output:process.stdout})}async function d(s,r){return new Promise(t=>{s.question(r,o=>{t(o.trim());});})}async function p(s,r,t){console.log(`
${e.cyan(r)}`),t.forEach((i,u)=>{console.log(e.gray(`  ${u+1}) `)+i.name);});let o=await d(s,e.white(`Enter number (1-${t.length}): `)),a=parseInt(o,10)-1;return a>=0&&a<t.length?t[a].value:t[0].value}async function k(s,r,t){return console.log(`
${e.cyan(r)}`),t.forEach((i,u)=>{console.log(e.gray(`  ${u+1}) `)+i.name);}),(await d(s,e.white("Enter numbers separated by commas (e.g., 1,2,3): "))).split(",").map(i=>parseInt(i.trim(),10)-1).filter(i=>i>=0&&i<t.length).map(i=>t[i].value)}function A(s){let r={};for(let t of ["src","app","lib","packages"])if(n.existsSync(c.join(s,t))){r.sourceDir=t;break}if(r.sourceDir){let t=c.join(s,r.sourceDir);try{let o=n.readdirSync(t,{withFileTypes:!0});r.directories=o.filter(a=>a.isDirectory()).map(a=>a.name).filter(a=>!a.startsWith(".")&&!a.startsWith("_"));}catch{}}return r}function I(s,r){let t={version:"1.0","agent-guidelines":{overview:`${r} uses Paradigm for structured AI context management.`,"how-to-use":["Check .purpose files in directories before making changes","Run `paradigm status` to see all symbols in the project","Run `paradigm visualize` to explore the Dreamscape","Reference symbols using @ # $ % ~ ^ ! ? prefixes"],"update-rules":["When adding a feature, create/update the nearest .purpose file","When adding authorization, update portal.yaml","When exploring ideas, add to .premise with ? prefix","Run `paradigm cursorrules` after updating .paradigm"]},"symbol-system":a,states:{},"purpose-required":[],conventions:b$1};if(t.states||(t.states={}),s.hasAuth&&s.hasAuth!=="none"&&(t.states.user={authenticated:{type:"boolean",default:false,description:"User is logged in"},role:{type:"enum",values:["guest","user","admin"],description:"User access level"}},s.hasAuth==="session"&&(t.states.user.sessionExpiry={type:"string",description:"Session expiration time"})),s.hasSubscription&&s.hasSubscription!=="none"&&(t.states.user||(t.states.user={}),s.hasSubscription==="tiers"?t.states.user.subscription={type:"enum",values:["free","trial","pro","enterprise"],description:"Subscription tier"}:t.states.user.isPremium={type:"boolean",default:false,description:"Has premium access"}),s.hasGates==="yes"&&t["agent-guidelines"]["how-to-use"].push("Check portal.yaml for authorization rules before modifying access control"),s.directories&&s.directories.length>0&&s.sourceDir&&(t["purpose-required"]=s.directories.map(o=>({pattern:`${s.sourceDir}/${o}/*`,depth:1}))),s.customStates){let o=s.customStates.split(",").map(a=>a.trim()).filter(Boolean);for(let a of o){let i=a.split(".");if(i.length>=2){let u=i[0],g=i.slice(1).join(".");t.states[u]||(t.states[u]={}),t.states[u][g]={type:"boolean",description:`Custom state: ${a}`};}}}return t}async function j(s){let r=x(),t={};console.log(e.blue(`
\u{1F305} Paradigm Setup Wizard
`)),console.log(e.gray("\u2500".repeat(55)));let o=A(s);return console.log(e.white(`
\u{1F4C2} Detected project structure:`)),o.sourceDir&&console.log(e.gray(`   Source directory: ${o.sourceDir}/`)),o.directories?.length&&console.log(e.gray(`   Subdirectories: ${o.directories.slice(0,5).join(", ")}${o.directories.length>5?"...":""}`)),console.log(e.gray(`
\u2500`.repeat(55))),console.log(e.white(`
\u{1F4C1} Project Structure
`)),t.sourceDir=await p(r,"What is your main source directory?",[{name:`${o.sourceDir||"src"}/ (detected)`,value:o.sourceDir||"src"},{name:"src/",value:"src"},{name:"app/",value:"app"},{name:"lib/",value:"lib"},{name:"packages/",value:"packages"}]),t.directories=await k(r,"Which directories should have .purpose files?",[{name:"features/ (user-facing capabilities)",value:"features"},{name:"components/ (reusable UI/code)",value:"components"},{name:"services/ (business logic)",value:"services"},{name:"routes/ or api/ (endpoints)",value:"routes"},{name:"pages/ (page components)",value:"pages"},{name:"lib/ (utilities)",value:"lib"}]),console.log(e.gray(`
\u2500`.repeat(55))),console.log(e.white(`
\u{1F510} State Tracking
`)),t.hasAuth=await p(r,"Does your app have user authentication?",[{name:"Yes, with sessions/JWT",value:"session"},{name:"Yes, OAuth only",value:"oauth"},{name:"No authentication",value:"none"}]),t.hasSubscription=await p(r,"Do you have subscription tiers or paid features?",[{name:"Yes (multiple tiers: free, pro, enterprise)",value:"tiers"},{name:"Yes (single paid tier)",value:"single"},{name:"No paid features",value:"none"}]),console.log(e.gray(`
\u2500`.repeat(55))),console.log(e.white(`
\u{1F6AA} Authorization Gates
`)),t.hasGates=await p(r,"Will you use Gate for authorization topology?",[{name:"Yes - I have role-based or feature-gated access",value:"yes"},{name:"No - simple or no authorization",value:"no"}]),console.log(`
`),t.customStates=await d(r,e.cyan("Any custom states to track? ")+e.gray(`(comma-separated, e.g., app.maintenance, cart.items)
`)+e.white("> ")),console.log(e.gray(`
\u2500`.repeat(55))),console.log(e.white(`
\u{1F916} Cursor Integration
`)),c$2(s)?t.cursorMode=await p(r,"A .cursorrules file exists. How should we handle it?",[{name:"Append Paradigm section to existing file",value:"append"},{name:"Replace with new .cursorrules",value:"create"},{name:"Skip - do not modify .cursorrules",value:"skip"}]):t.cursorMode=await p(r,"Generate a .cursorrules file for Cursor AI?",[{name:"Yes - create .cursorrules with Paradigm context",value:"create"},{name:"No - skip Cursor integration",value:"skip"}]),r.close(),t}async function W(s,r){let t=s?c.resolve(s):process.cwd(),o=c.basename(t),a=c.join(t,".paradigm");if(n.existsSync(a)&&!r.force){console.log(e.yellow(`
\u26A0\uFE0F  .paradigm already exists in this directory.`)),console.log(e.gray(`   Use --force to overwrite, or edit .paradigm directly.
`));return}let i;r.yes?(i={sourceDir:A(t).sourceDir||"src",directories:["features","components"],hasAuth:"session",hasSubscription:"none",hasGates:"yes",cursorMode:"create"},console.log(e.blue(`
\u{1F305} Using default configuration...
`))):i=await j(t);let u=I(i,o);n.writeFileSync(a,d$1(u),"utf8"),console.log(e.green(`
\u2705 Created .paradigm configuration`));let g$1=c.join(t,".premise");n.existsSync(g$1)||(n.writeFileSync(g$1,g(o),"utf8"),console.log(e.green("\u2705 Created .premise file")));let f=c.join(t,".purpose");n.existsSync(f)||(n.writeFileSync(f,c$1(),"utf8"),console.log(e.green("\u2705 Created .purpose file")));let h=c.join(t,"portal.yaml");if(i.hasGates==="yes"&&!n.existsSync(h)){let{getDefaultGateConfig:l}=await import('./dist-VWC6FA46.js');n.writeFileSync(h,l(),"utf8"),console.log(e.green("\u2705 Created portal.yaml"));}let m=i.cursorMode||"skip";if(m!=="skip"){let l=b(t,u,m,o);l.success&&l.path&&console.log(e.green(`\u2705 ${l.message}`));}console.log(e.gray(`
\u2500`.repeat(55))),console.log(e.blue(`
\u{1F389} Paradigm setup complete!
`)),console.log(e.white("Files created:")),console.log(e.gray("  \u2022 .paradigm      ")+e.white("AI guidelines, symbols, states")),console.log(e.gray("  \u2022 .premise        ")+e.white("Project overview & ideas")),console.log(e.gray("  \u2022 .purpose      ")+e.white("Root context & features")),i.hasGates==="yes"&&console.log(e.gray("  \u2022 portal.yaml     ")+e.white("Authorization topology")),m!=="skip"&&console.log(e.gray("  \u2022 .cursorrules  ")+e.white("Cursor AI integration")),console.log(e.white(`
Next steps:`)),console.log(e.gray("  1. ")+"Review and customize "+e.cyan(".paradigm")),console.log(e.gray("  2. ")+"Edit "+e.cyan(".purpose")+" to define your project context"),console.log(e.gray("  3. ")+"Run "+e.cyan("paradigm visualize")+" to open the Dreamscape"),console.log(e.gray("  4. ")+"Run "+e.cyan("paradigm cursorrules")+` after changes to regenerate
`);}export{W as setupCommand};