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