#!/usr/bin/env node
import {a}from'./chunk-LKAT7IAK.js';import*as c from'fs/promises';import*as p from'path';import*as g from'crypto';import*as l from'js-yaml';import i from'chalk';var f=".paradigm/adoptions.yaml",y=".paradigm/roster.yaml";function m(s){let r=Object.keys(s).sort(),t={};for(let e of r)t[e]=s[e];let o=JSON.stringify(t);return g.createHash("sha256").update(o).digest("hex")}async function w(s){let r=p.join(s,f);try{let t=await c.readFile(r,"utf-8"),o=l.load(t);if(!o||typeof o!="object")return null;let e=h(o.agents),d=o["integrity-hash"]||o.integrityHash||void 0,n=!0;if(d){let a$1=m(e);a$1!==d&&(n=!1,a.component("adoption").warn("Adoption integrity hash mismatch \u2014 adoptions.yaml may have been tampered with",{expected:d.slice(0,12)+"...",computed:a$1.slice(0,12)+"..."}));}return {version:o.version||"1.0",adoptedAt:o["adopted-at"]||o.adoptedAt||"",projectType:o["project-type"]||o.projectType||"",agents:e,verified:n,integrityHash:d}}catch(t){return t.code==="ENOENT"||a.component("adoption").warn("Failed to parse adoptions.yaml",{error:String(t)}),null}}async function R(s,r){let t=p.join(s,f),o=p.dirname(t);await c.mkdir(o,{recursive:true});let e=m(r.agents),d={version:r.version,"adopted-at":r.adoptedAt,"project-type":r.projectType,"integrity-hash":e,agents:v(r.agents)},n=l.dump(d,{lineWidth:-1,noRefs:true,sortKeys:false,quotingType:'"'});await c.writeFile(t,n,"utf-8");}async function b(s){let r=p.join(s,y),t=new Date().toISOString(),o={active:[]};try{let d=await c.readFile(r,"utf-8"),n=l.load(d);n&&typeof n=="object"&&(o={version:n.version,active:n.active||[],type:n.type});}catch{a.component("adoption").debug("No roster.yaml found for migration");}let e={version:"1.0",adoptedAt:t,projectType:o.type||"unknown",agents:{}};for(let d of o.active||[])e.agents[d]={adopted:t,source:"core",defaultsAccepted:true};return a.component("adoption").debug("Migrated roster to adoptions",{count:Object.keys(e.agents).length}),e}function k(s){return {version:"1.0",adoptedAt:new Date().toISOString(),projectType:s,agents:{}}}function j(s,r){let t=[],o=i.dim("\u2500".repeat(49)),e=s.filter(n=>n.source==="core"),d=s.filter(n=>n.source==="ecosystem");if(t.push(""),t.push(`  ${i.bold("Agent Adoption")}`),t.push(`  ${o}`),t.push(`  ${i.dim("Detected:")} ${r}`),e.length>0){t.push(""),t.push(`  ${i.bold(`Core team (${e.length}):`)}`);for(let n of e){let a=n.nickname?`${n.id} (${n.nickname})`:n.id;t.push(`    ${i.white(a.padEnd(22))}${i.gray(n.role)}`);}}if(d.length>0){t.push(""),t.push(`  ${i.bold(`Ecosystem (${d.length} detected):`)}`);for(let n of d){let a=n.nickname?`${n.id} (${n.nickname})`:n.id;t.push(`    ${i.white(a.padEnd(22))}${i.gray(n.role)}`);}}return t.push(""),t.push(`  ${i.dim("All using default scopes.")}`),t.push(`  ${i.dim("[Enter]")} accept all  ${i.dim("|")}  ${i.dim("[r]")} review individually  ${i.dim("|")}  ${i.dim("[c]")} customize`),t.push(""),t.join(`
`)}function h(s){if(!s||typeof s!="object")return {};let r={};for(let[t,o]of Object.entries(s)){if(!o||typeof o!="object")continue;let e=o;r[t]={adopted:e.adopted||"",source:e.source||"core",defaultsAccepted:e["defaults-accepted"]!=null?!!e["defaults-accepted"]:e.defaultsAccepted!=null?!!e.defaultsAccepted:true,...e.version!=null&&{version:e.version},...e.overrides!=null&&{overrides:e.overrides},...e["scopes-approved"]!=null&&{scopesApproved:e["scopes-approved"]},...e.scopesApproved!=null&&{scopesApproved:e.scopesApproved},...e["detected-from"]!=null&&{detectedFrom:e["detected-from"]},...e.detectedFrom!=null&&{detectedFrom:e.detectedFrom}};}return r}function v(s){let r={};for(let[t,o]of Object.entries(s)){let e={adopted:o.adopted,source:o.source,"defaults-accepted":o.defaultsAccepted};o.version!=null&&(e.version=o.version),o.overrides!=null&&(e.overrides=o.overrides),o.scopesApproved!=null&&(e["scopes-approved"]=o.scopesApproved),o.detectedFrom!=null&&(e["detected-from"]=o.detectedFrom),r[t]=e;}return r}export{w as a,R as b,b as c,k as d,j as e};