#!/usr/bin/env node
import'./chunk-XHJ27CER.js';import i from'chalk';import*as o from'fs';import*as p from'path';import*as d from'js-yaml';var S={"add-feature":{gates:{specify:"manual",plan:"manual",task:"auto",implement:"sentinel",validate:"sentinel"},description:"Standard feature addition with manual spec/plan review"},"bug-fix":{gates:{specify:"auto",plan:"auto",task:"auto",implement:"sentinel",validate:"sentinel"},description:"Quick bug fix with automated gates except validation"},"security-change":{gates:{specify:"manual",plan:"manual",task:"manual",implement:"manual",validate:"manual"},description:"Security-sensitive change with all-manual gates"},refactor:{gates:{specify:"auto",plan:"manual",task:"auto",implement:"sentinel",validate:"sentinel"},description:"Code refactoring with manual plan review"}},c=["specify","plan","task","implement","validate"],g=".paradigm/pipeline";function y(n){return n.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function u(n,t){let e=y(t),a=p.join(n,g,`${e}.yaml`);return o.existsSync(a)?d.load(o.readFileSync(a,"utf8")):null}function m(n,t){let e=y(t.feature),a=p.join(n,g);o.existsSync(a)||o.mkdirSync(a,{recursive:true});let s=p.join(a,`${e}.yaml`);return o.writeFileSync(s,d.dump(t,{lineWidth:120}),"utf8"),s}function P(n){let t=p.join(n,g);return o.existsSync(t)?o.readdirSync(t).filter(e=>e.endsWith(".yaml")&&!e.startsWith("completed")).map(e=>{try{return d.load(o.readFileSync(p.join(t,e),"utf8"))}catch{return null}}).filter(Boolean):[]}function x(n,t,e){let a={specify:{status:"pending"},plan:{status:"pending"},task:{status:"pending"},implement:{status:"pending"},validate:{status:"pending"}};return a.specify.status="in-progress",{version:"1.0",feature:y(n),created:new Date().toISOString(),current_stage:"specify",gate_config:t,template:e,stages:a}}function h(n){let t=c.indexOf(n);return t<c.length-1?c[t+1]:null}function v(n,t){let e=y(t.feature),a=p.join(n,g,"completed");o.existsSync(a)||o.mkdirSync(a,{recursive:true});let s=p.join(a,`${e}.yaml`);o.writeFileSync(s,d.dump(t,{lineWidth:120}),"utf8");let r=p.join(n,g,`${e}.yaml`);o.existsSync(r)&&o.unlinkSync(r);}async function j(n,t){let e=process.cwd(),a=t.template||"add-feature",s;if(t.gates){let l=t.gates.split(",");l.length!==5&&(console.error(i.red("--gates requires 5 comma-separated modes: specify,plan,task,implement,validate")),process.exit(1)),s={specify:l[0],plan:l[1],task:l[2],implement:l[3],validate:l[4]};}else {let l=S[a];l||(console.error(i.red(`Unknown template: ${a}. Available: ${Object.keys(S).join(", ")}`)),process.exit(1)),s=l.gates;}let r=x(n,s,a),f=m(e,r);console.log(i.green(`Pipeline created: ${r.feature}`)),console.log(i.gray(`Template: ${a}`)),console.log(i.gray(`Gates: ${c.map(l=>`${l}=${s[l]}`).join(", ")}`)),console.log(i.gray(`File: ${f}`)),console.log(i.cyan(`
Current stage: specify (in-progress)`));}async function E(n){let t=process.cwd();if(n){let e=u(t,n);e||(console.error(i.red(`Pipeline not found: ${n}`)),process.exit(1)),$(e);}else {let e=P(t);if(e.length===0){console.log(i.gray("No active pipelines"));return}for(let a of e)$(a),console.log();}}function $(n){console.log(i.bold(`Pipeline: ${n.feature}`)),console.log(i.gray(`Created: ${n.created}`)),n.template&&console.log(i.gray(`Template: ${n.template}`)),console.log();for(let t of c){let e=n.stages[t],a=n.gate_config[t],s=n.current_stage===t,r=e.status==="approved"?"+":e.status==="in-progress"?">":e.status==="blocked"?"x":".",f=e.status==="approved"?i.green:e.status==="in-progress"?i.cyan:e.status==="blocked"?i.red:i.gray;console.log(f(`  ${r} ${t.padEnd(12)} [${a}] ${e.status}${s?" <- current":""}`)),e.artifact&&console.log(i.gray(`    Artifact: ${e.artifact}`)),e.symbols_touched?.length&&console.log(i.gray(`    Symbols: ${e.symbols_touched.join(", ")}`));}}async function M(n){let t=process.cwd(),e=u(t,n);e||(console.error(i.red(`Pipeline not found: ${n}`)),process.exit(1));let a=e.current_stage,s=e.gate_config[a],r=h(a);e.stages[a].status="approved",e.stages[a].approved_at=new Date().toISOString(),s==="auto"&&(e.stages[a].auto_passed_at=new Date().toISOString()),r?(e.current_stage=r,e.stages[r].status="in-progress",m(t,e),console.log(i.green(`Stage '${a}' approved. Advanced to '${r}'.`))):(m(t,e),v(t,e),console.log(i.green(`Pipeline '${e.feature}' completed and archived.`)));}async function D(n,t){let e=process.cwd(),a=u(e,n);a||(console.error(i.red(`Pipeline not found: ${n}`)),process.exit(1));let s=t.stage;c.includes(s)||(console.error(i.red(`Invalid stage: ${t.stage}`)),process.exit(1));let r=t.gate;["auto","manual","sentinel"].includes(r)||(console.error(i.red(`Invalid gate mode: ${t.gate}. Use: auto, manual, sentinel`)),process.exit(1));let f=a.gate_config[s];a.gate_config[s]=r,m(e,a),console.log(i.green(`Gate for '${s}' changed: ${f} -> ${r}`)),t.reason&&console.log(i.gray(`Reason: ${t.reason}`));}async function A(n){let t=process.cwd(),e=u(t,n);e||(console.error(i.red(`Pipeline not found: ${n}`)),process.exit(1)),v(t,e),console.log(i.yellow(`Pipeline '${e.feature}' aborted and archived.`));}async function T(){let n=process.cwd(),t=P(n);if(t.length===0){console.log(i.gray("No active pipelines."));return}console.log(i.bold(`Active Pipelines (${t.length}):
`));for(let e of t){let a=c.filter(s=>e.stages[s].status==="approved").length;console.log(`  ${i.cyan(e.feature)} -- stage ${a}/${c.length} (${e.current_stage})`);}}export{A as pipelineAbortCommand,M as pipelineAdvanceCommand,D as pipelineConfigureCommand,T as pipelineListCommand,j as pipelineStartCommand,E as pipelineStatusCommand};