#!/usr/bin/env node
import {a}from'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as c from'fs';import*as y from'path';import*as P from'os';import o from'chalk';import*as m from'js-yaml';var u=y.join(P.homedir(),".paradigm","agents"),S=".paradigm/agents",$=".agent",k={architect:{style:"deliberate",risk:"conservative",verbosity:"detailed"},builder:{style:"rapid",risk:"balanced",verbosity:"concise"},tester:{style:"methodical",risk:"conservative",verbosity:"concise"},reviewer:{style:"deliberate",risk:"conservative",verbosity:"detailed"},security:{style:"methodical",risk:"conservative",verbosity:"detailed"}};async function T(e={}){let s=process.cwd(),r=a.command("agent-list").start("Listing agent profiles",{cwd:s}),t=[];if(!e.project&&c.existsSync(u))try{let i=c.readdirSync(u).filter(l=>l.endsWith($));for(let l of i)try{let d=c.readFileSync(y.join(u,l),"utf-8"),n=m.load(d);n?.id&&t.push(n);}catch{}}catch{}let g=y.join(s,S);if(!e.global&&c.existsSync(g))try{let i=c.readdirSync(g).filter(l=>l.endsWith($));for(let l of i)try{let d=c.readFileSync(y.join(g,l),"utf-8"),n=m.load(d);if(n?.id){let f=t.findIndex(a=>a.id===n.id);f>=0?t[f]=n:t.push(n);}}catch{}}catch{}if(e.json){console.log(JSON.stringify({count:t.length,agents:t.map(C)},null,2)),r.success(`Found ${t.length} agents`);return}if(console.log(o.blue(`
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510`)),console.log(o.blue("\u2502")+o.white.bold("  paradigm agent list                              ")+o.blue("\u2502")),console.log(o.blue("\u2502")+o.gray("  Persistent agent identity profiles              ")+o.blue("\u2502")),console.log(o.blue(`\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
`)),t.length===0){console.log(o.yellow("  No .agent profiles found.")),console.log(o.gray(`  Create one: paradigm agent create <id> --global
`)),r.success("No agents found");return}for(let i of t){let d=(i.expertise||[]).sort((n,f)=>f.confidence-n.confidence).slice(0,3).map(n=>`${n.symbol} (${(n.confidence*100).toFixed(0)}%)`).join(", ")||o.gray("none yet");console.log(`  ${o.white.bold(i.id)} \u2014 ${o.gray(i.role)}`),console.log(`    Style: ${i.personality?.style||"?"} | Risk: ${i.personality?.risk||"?"} | Verbosity: ${i.personality?.verbosity||"?"}`),console.log(`    Top expertise: ${d}`),console.log(`    Projects: ${Object.keys(i.contexts||{}).join(", ")||o.gray("none")}`),console.log("");}r.success(`Listed ${t.length} agents`);}async function I(e,s={}){let r=process.cwd(),t=a.command("agent-show").start(`Showing agent ${e}`,{cwd:r}),g=x(r,e);if(!g){s.json?console.log(JSON.stringify({error:`Agent "${e}" not found`})):(console.log(o.red(`
  Agent "${e}" not found.`)),console.log(o.gray(`  Create: paradigm agent create ${e} --global
`))),t.error(`Agent ${e} not found`);return}if(s.json){console.log(JSON.stringify(g,null,2)),t.success(`Showed agent ${e}`);return}if(console.log(o.blue(`
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510`)),console.log(o.blue("\u2502")+o.white.bold(`  Agent: ${e}`.padEnd(50))+o.blue("\u2502")),console.log(o.blue(`\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
`)),console.log(`  ${o.white.bold("Role:")} ${g.role}`),console.log(`  ${o.white.bold("Description:")} ${g.description}`),console.log(`  ${o.white.bold("Version:")} ${g.version}`),console.log(`  ${o.white.bold("Created:")} ${g.created}`),console.log(`  ${o.white.bold("Updated:")} ${g.updated}`),console.log(""),g.personality){let f=g.personality;console.log(`  ${o.white.bold("Personality")}`),console.log(`    Style: ${f.style}  |  Risk: ${f.risk}  |  Verbosity: ${f.verbosity}`),console.log("");}let i=(g.expertise||[]).sort((f,a)=>a.confidence-f.confidence);if(i.length>0){console.log(`  ${o.white.bold("Expertise")} (${i.length} symbols)`),console.log(`  ${"Symbol".padEnd(30)} ${"Confidence".padEnd(12)} ${"Sessions".padEnd(10)} Last Touch`),console.log(`  ${"-".repeat(70)}`);for(let f of i.slice(0,20)){let a=`${(f.confidence*100).toFixed(0)}%`.padEnd(12),h=String(f.sessions).padEnd(10),p=f.lastTouch?f.lastTouch.split("T")[0]:"\u2014";console.log(`  ${f.symbol.padEnd(30)} ${a} ${h} ${p}`);}i.length>20&&console.log(o.gray(`  ... and ${i.length-20} more`)),console.log("");}else console.log(o.gray("  No expertise recorded. Run `paradigm agent sync` to bootstrap from lore.\n"));let l=g.transferable||[];if(l.length>0){console.log(`  ${o.white.bold("Transferable Patterns")} (${l.length})`);for(let f of l)console.log(`    ${f.id}: ${(f.successRate*100).toFixed(0)}% success \u2014 ${f.description}`),console.log(o.gray(`      Learned in: ${f.learnedIn} | Applied in: ${f.appliedIn.join(", ")||"none"}`));console.log("");}let d=Object.entries(g.contexts||{});if(d.length>0){console.log(`  ${o.white.bold("Project Contexts")} (${d.length})`);for(let[f,a]of d)console.log(`    ${o.white(f)}: ${a.sessionsInProject||0} sessions, last active ${a.lastActive?.split("T")[0]||"\u2014"}`),a.defaultModel&&console.log(`      Model: ${a.defaultModel}`),a.focus?.length&&console.log(`      Focus: ${a.focus.join(", ")}`);console.log("");}let n=g.permissions;n&&(console.log(`  ${o.white.bold("Permissions")}`),n.paths?.read?.length&&console.log(`    Read: ${n.paths.read.join(", ")}`),n.paths?.write?.length&&console.log(`    Write: ${n.paths.write.join(", ")}`),n.paths?.deny?.length&&console.log(`    Deny: ${o.red(n.paths.deny.join(", "))}`),n.tools?.allow?.length&&console.log(`    Tools allow: ${n.tools.allow.join(", ")}`),n.tools?.deny?.length&&console.log(`    Tools deny: ${o.red(n.tools.deny.join(", "))}`),n.dangerous_actions?.length&&console.log(`    Requires approval: ${n.dangerous_actions.join(", ")}`),console.log("")),t.success(`Showed agent ${e}`);}async function D(e,s={}){let r=process.cwd(),t=s.global?"global":"project",g=a.command("agent-create").start(`Creating agent ${e} (${t})`,{cwd:r}),i=t==="global"?u:y.join(r,S);c.existsSync(i)||c.mkdirSync(i,{recursive:true});let l=y.join(i,`${e}${$}`);if(c.existsSync(l)){console.log(o.yellow(`
  Agent "${e}" already exists at ${l}`)),console.log(o.gray("  Use `paradigm agent show` to view.\n")),g.error("Agent already exists");return}let d=new Date().toISOString(),n=k[e]||{style:"deliberate",risk:"balanced",verbosity:"concise"},f={id:e,role:s.role||`${e.charAt(0).toUpperCase()+e.slice(1)} agent`,description:s.description||`Persistent identity for the ${e} agent role`,version:"1.0.0",personality:n,expertise:[],transferable:[],contexts:{},created:d,updated:d};if(s.denyPaths){let h=s.denyPaths.split(",").map(p=>p.trim());f.permissions={paths:{deny:h}};}let a$1=m.dump(f,{lineWidth:120,noRefs:true,sortKeys:false});c.writeFileSync(l,a$1,"utf-8"),console.log(o.green(`
  \u2713 Created agent "${e}" at ${l}`)),console.log(o.gray("  Run `paradigm agent sync` to bootstrap expertise from lore.\n")),g.success(`Created agent ${e}`);}async function N(e,s={}){let r=process.cwd(),t=a.command("agent-sync").start(`Syncing expertise for ${e}`,{cwd:r}),g=y.join(r,".paradigm","lore","entries");if(!c.existsSync(g)){console.log(o.yellow(`
  No lore directory found. Nothing to sync from.
`)),t.error("No lore found");return}let i=x(r,e);if(!i){if(s.dryRun){console.log(o.yellow(`
  Agent "${e}" not found. Would create with --no-dry-run.
`)),t.success("Dry run \u2014 would create");return}let h=(c.existsSync(y.join(u,`${e}${$}`))?"global":"project")==="global"?u:y.join(r,S);c.existsSync(h)||c.mkdirSync(h,{recursive:true});let p=new Date().toISOString(),w=k[e]||{style:"deliberate",risk:"balanced",verbosity:"concise"};i={id:e,role:`${e.charAt(0).toUpperCase()+e.slice(1)} agent`,description:`Persistent identity for the ${e} agent role`,version:"1.0.0",personality:w,expertise:[],transferable:[],contexts:{},created:p,updated:p};}let l=i.expertise||[],d=0,n=new Set,f=F(g);for(let a of f)if(!(!a.symbols_touched||a.symbols_touched.length===0)){d++;for(let h of a.symbols_touched){n.add(h);let p=l.find(w=>w.symbol===h);p?(p.sessions++,p.lastTouch=a.timestamp||p.lastTouch,a.confidence!=null&&(p.confidence=.7*p.confidence+.3*a.confidence)):l.push({symbol:h,confidence:a.confidence??.5,sessions:1,lastTouch:a.timestamp||new Date().toISOString()});}}if(i.expertise=l,s.json)console.log(JSON.stringify({agentId:e,entriesProcessed:d,symbolsUpdated:n.size,dryRun:!!s.dryRun,topExpertise:l.sort((a,h)=>h.confidence-a.confidence).slice(0,10)},null,2));else if(console.log(o.blue(`
  Syncing expertise for "${e}" from ${d} lore entries...`)),console.log(`  ${o.green("\u2713")} ${n.size} symbols updated`),console.log(`  ${o.green("\u2713")} ${d} entries processed`),l.length>0){console.log(`
  Top expertise:`);for(let a of l.sort((h,p)=>p.confidence-h.confidence).slice(0,5))console.log(`    ${a.symbol}: ${(a.confidence*100).toFixed(0)}% (${a.sessions} sessions)`);}if(s.dryRun)s.json||console.log(o.yellow(`
  Dry run \u2014 no changes written.
`));else {i.updated=new Date().toISOString();let a=y.join(r,S,`${e}${$}`),h=y.join(u,`${e}${$}`),p=c.existsSync(a)?"project":"global",w=p==="global"?u:y.join(r,S);c.existsSync(w)||c.mkdirSync(w,{recursive:true});let j=p==="global"?h:a;c.writeFileSync(j,m.dump(i,{lineWidth:120,noRefs:true,sortKeys:false}),"utf-8"),s.json||console.log(o.green(`
  \u2713 Saved to ${j}
`));}t.success(`Synced ${n.size} symbols from ${d} entries`);}async function _(e={}){let s=process.cwd(),r=a.command("agent-roster").start("Agent roster",{cwd:s}),t=[];if(c.existsSync(u))for(let d of c.readdirSync(u).filter(n=>n.endsWith($)))try{let n=m.load(c.readFileSync(y.join(u,d),"utf-8"));n?.id&&t.push(n);}catch{}let g=y.join(s,S);if(c.existsSync(g))for(let d of c.readdirSync(g).filter(n=>n.endsWith($)))try{let n=m.load(c.readFileSync(y.join(g,d),"utf-8"));if(n?.id){let f=t.findIndex(a=>a.id===n.id);f>=0?t[f]=n:t.push(n);}}catch{}let i=t.filter(d=>!d.benched),l=t.filter(d=>d.benched);if(e.json){console.log(JSON.stringify({active:i.map(v),benched:l.map(v)},null,2)),r.success(`${i.length} active, ${l.length} benched`);return}if(console.log(o.blue(`
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510`)),console.log(o.blue("\u2502")+o.white.bold("  Agent Roster                                    ")+o.blue("\u2502")),console.log(o.blue(`\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
`)),i.length>0){console.log(o.green.bold("  Active"));for(let d of i)A(d);}if(l.length>0){console.log(o.gray.bold(`
  Benched`));for(let d of l)A(d,true);}t.length===0?console.log(o.yellow(`  No agents found.
`)):console.log(""),r.success(`${i.length} active, ${l.length} benched`);}function A(e,s=false){let r=(e.expertise||[]).sort((n,f)=>f.confidence-n.confidence),t=r[0]?`${r[0].symbol} (${(r[0].confidence*100).toFixed(0)}%)`:o.gray("\u2014"),g=s?o.gray:o.white,i=e.nickname?` (${e.nickname})`:"",l=e.attention?.threshold,d=l!=null?` | thr: ${l.toFixed(2)}`:"";console.log(`    ${g.bold(e.id)}${o.gray(i)} \u2014 ${o.gray(e.role)}`),console.log(`      Top: ${t} | ${r.length} symbols${d}`);}function v(e){let s=(e.expertise||[]).sort((r,t)=>t.confidence-r.confidence);return {id:e.id,role:e.role,nickname:e.nickname,benched:e.benched||false,expertiseCount:s.length,topExpertise:s.slice(0,3).map(r=>({symbol:r.symbol,confidence:parseFloat(r.confidence.toFixed(2))})),threshold:e.attention?.threshold}}async function L(e){let s=process.cwd(),r=a.command("agent-bench").start(`Benching agent ${e}`,{cwd:s}),t=x(s,e);if(!t){console.log(o.red(`
  Agent "${e}" not found.
`)),r.error("Not found");return}t.benched=true,t.updated=new Date().toISOString(),R(s,e,t),console.log(o.yellow(`
  \u23F8 Agent "${e}" is now benched.`)),console.log(o.gray(`  Maestro will skip this agent during orchestration.
`)),r.success(`Benched ${e}`);}async function W(e){let s=process.cwd(),r=a.command("agent-activate").start(`Activating agent ${e}`,{cwd:s}),t=x(s,e);if(!t){console.log(o.red(`
  Agent "${e}" not found.
`)),r.error("Not found");return}t.benched=false,t.updated=new Date().toISOString(),R(s,e,t),console.log(o.green(`
  \u25B6 Agent "${e}" is now active.`)),console.log(o.gray(`  Maestro will include this agent in orchestration.
`)),r.success(`Activated ${e}`);}function R(e,s,r){let t=y.join(e,S,`${s}${$}`);if(c.existsSync(t)){c.writeFileSync(t,m.dump(r,{lineWidth:120,noRefs:true,sortKeys:false}),"utf-8");return}let g=y.join(u,`${s}${$}`),i=u;c.existsSync(i)||c.mkdirSync(i,{recursive:true}),c.writeFileSync(g,m.dump(r,{lineWidth:120,noRefs:true,sortKeys:false}),"utf-8");}function x(e,s){let r=y.join(e,S,`${s}${$}`);if(c.existsSync(r))try{return m.load(c.readFileSync(r,"utf-8"))}catch{}let t=y.join(u,`${s}${$}`);if(c.existsSync(t))try{return m.load(c.readFileSync(t,"utf-8"))}catch{}return null}function C(e){return {id:e.id,role:e.role,personality:e.personality,expertiseCount:(e.expertise||[]).length,topExpertise:(e.expertise||[]).sort((s,r)=>r.confidence-s.confidence).slice(0,3).map(s=>({symbol:s.symbol,confidence:parseFloat(s.confidence.toFixed(2))})),projectContexts:Object.keys(e.contexts||{}),transferableCount:(e.transferable||[]).length}}function F(e){let s=[];try{let r=c.readdirSync(e,{withFileTypes:!0});for(let t of r){if(!t.isDirectory())continue;let g=y.join(e,t.name);try{let i=c.readdirSync(g).filter(l=>l.endsWith(".yaml")||l.endsWith(".yml"));for(let l of i)try{let d=c.readFileSync(y.join(g,l),"utf-8"),n=m.load(d);n?.symbols_touched&&Array.isArray(n.symbols_touched)&&s.push({symbols_touched:n.symbols_touched,confidence:typeof n.confidence=="number"?n.confidence:void 0,timestamp:n.timestamp||t.name});}catch{}}catch{}}}catch{}return s}export{W as agentActivateCommand,L as agentBenchCommand,D as agentCreateCommand,T as agentListCommand,_ as agentRosterCommand,I as agentShowCommand,N as agentSyncCommand};