#!/usr/bin/env node
import'./chunk-XHJ27CER.js';import*as d from'fs';import*as u from'path';import o from'chalk';import*as p from'js-yaml';function h(e){let r=u.join(e,".paradigm","graduation.yaml");if(!d.existsSync(r))return {states:{}};try{let a=d.readFileSync(r,"utf8");return p.load(a)||{states:{}}}catch{return {states:{}}}}var g={"explore-before-implement":"Explore Before Implementing","ripple-before-modify":"Ripple Before Modifying","check-fragility":"Check Fragility","wisdom-before-implement":"Check Team Wisdom","verify-before-done":"Verify Before Done","postflight-compliance":"Postflight Compliance","test-new-components":"Test New Components","purpose-coverage":"Purpose File Coverage","record-lore-for-significant":"Record Lore for Significant Changes","confidence-on-decisions":"Confidence on Decisions","gates-for-routes":"Gates for Routes","university-content-valid":"University Content Valid","university-onboarded":"University Onboarding"};({hook:o.green,habit:o.yellow,mcp:o.red});async function v(e){let r=process.cwd(),n=h(r).states||{};if(e.json){console.log(JSON.stringify({states:n},null,2));return}console.log(o.blue(`
\u26A1 Automation Tier Status
`)),console.log(o.gray("\u2500".repeat(60)));let t={hook:[],habit:[],mcp:[]},m=new Set([...Object.keys(g),...Object.keys(n)]);for(let s of m){let i=n[s]||{},l=i.tier||"habit";t[l]||(t[l]=[]),t[l].push({id:s,state:i});}let c=t.hook.length,f=t.habit.length,w=t.mcp.length,k=c+f+w;if(console.log(`  ${o.green(`${c} hook`)}  ${o.yellow(`${f} habit`)}  ${o.red(`${w} mcp`)}  (${k} total)
`),t.hook.length>0){console.log(o.green.bold("  \u26A1 Hooks (zero context cost)"));for(let{id:s,state:i}of t.hook){let l=g[s]||s,y=i.graduatedAt?` \u2014 graduated ${i.graduatedAt.split("T")[0]}`:"";console.log(`    ${o.green("\u25CF")} ${l} ${o.gray(`(${s})${y}`)}`);}console.log();}if(t.habit.length>0){console.log(o.yellow.bold("  \u{1F4AD} Habits (agent-reminded)"));for(let{id:s,state:i}of t.habit){let l=g[s]||s,y=i.neverGraduate?o.gray(" \u{1F512} never-graduate"):"",b=i.cooldownUntil&&new Date(i.cooldownUntil)>new Date?o.gray(` \u23F3 cooldown until ${i.cooldownUntil.split("T")[0]}`):"";console.log(`    ${o.yellow("\u25CF")} ${l} ${o.gray(`(${s})`)}${y}${b}`);}console.log();}if(t.mcp.length>0){console.log(o.red.bold("  \u{1F527} MCP Tools (manual, high token cost)"));for(let{id:s,state:i}of t.mcp){let l=g[s]||s;console.log(`    ${o.red("\u25CF")} ${l} ${o.gray(`(${s})`)}`);}console.log();}if(c>0){let s=c*150;console.log(o.gray(`  Estimated savings: ~${s} tokens/session from ${c} graduated habit(s)`));}console.log();}function $(e,r){let a=u.join(e,".paradigm","graduation.yaml"),n=u.dirname(a);d.existsSync(n)||d.mkdirSync(n,{recursive:true});let t=p.dump(r,{lineWidth:120,noRefs:true,sortKeys:true});d.writeFileSync(a,t,"utf8");}async function G(e){let r=process.cwd(),a=h(r);a.states||(a.states={});let n=a.states[e]||{};if(n.tier==="hook"){console.log(o.yellow(`${e} is already graduated to hook tier.`));return}if(n.neverGraduate){console.log(o.red(`${e} is marked as never-graduate (requires agent cognition).`));return}a.states[e]={...n,tier:"hook",graduatedAt:new Date().toISOString(),complianceAtGraduation:100,failureCount:0},$(r,a);let t=g[e]||e;console.log(o.green(`${o.bold("\u26A1")} Graduated "${t}" to hook tier.`)),console.log(o.gray("  MCP evaluation will skip this habit. Stop hook enforces compliance."));}async function D(e,r){let a=process.cwd(),n=h(a);n.states||(n.states={});let t=n.states[e]||{};if(t.tier!=="hook"){console.log(o.yellow(`${e} is not at hook tier (currently: ${t.tier||"habit"}).`));return}let m=r.cooldown?parseInt(r.cooldown):14,c=new Date;c.setDate(c.getDate()+m),n.states[e]={...t,tier:"habit",demotedAt:new Date().toISOString(),cooldownUntil:c.toISOString()},$(a,n);let f=g[e]||e;console.log(o.yellow(`${o.bold("\u{1F4AD}")} Demoted "${f}" back to habit tier.`)),console.log(o.gray(`  Cooldown: ${m} days (until ${c.toISOString().split("T")[0]}).`)),console.log(o.gray("  MCP evaluation will resume checking this habit."));}export{D as graduateDemoteCommand,G as graduatePromoteCommand,v as graduateStatusCommand};