#!/usr/bin/env node
import {b as b$1}from'./chunk-ORDKEGII.js';import {d}from'./chunk-BV5PRPLB.js';import {e}from'./chunk-AO7ZSRME.js';import'./chunk-FYDRENK7.js';import {d as d$1}from'./chunk-EKZDFEJW.js';import'./chunk-5TAVYPOV.js';import*as b from'path';import r from'chalk';import x from'ora';async function J(t,m,o){let f=m?b.resolve(m):process.cwd();if(!o.task){o.json?console.log(JSON.stringify({error:'Task is required. Use --task "..."'})):(console.log(r.red(`
Task is required. Use --task "..."`)),console.log(r.gray(`Example: paradigm team spawn architect --task "Design the payment API"
`)));return}let a=e(f);if(!a){o.json?console.log(JSON.stringify({error:"Team not configured"})):console.log(r.yellow("\nTeam not configured. Run `paradigm team init` first.\n"));return}if(!a.agents[t]){o.json?console.log(JSON.stringify({error:`Unknown agent: ${t}`,available:Object.keys(a.agents)})):(console.log(r.red(`
Unknown agent: ${t}`)),console.log(r.gray(`Available agents: ${Object.keys(a.agents).join(", ")}
`)));return}let c;if(o.budget){let e=o.budget.split(",");c={};for(let s of e){let[l,d]=s.split("=");l==="tokens"&&(c.maxTokens=parseInt(d)),l==="cost"&&(c.maxCostUsd=parseFloat(d));}}let n=x({text:`Initializing ${t} agent...`,isSilent:o.quiet||o.json}).start(),y=new b$1(f);try{await y.initialize();}catch(e){n.fail("Failed to initialize spawner"),o.json?console.log(JSON.stringify({error:e instanceof Error?e.message:String(e)})):console.log(r.red(`
Error: ${e instanceof Error?e.message:e}
`));return}let g;try{g=await d(f,o.provider);}catch{n.fail("No agent provider available"),o.json?console.log(JSON.stringify({error:"No agent provider available"})):(console.log(r.red(`
No agent provider available.`)),console.log(r.gray("Run `paradigm team providers` to see options.\n")));return}!o.quiet&&!o.json&&(n.text=`Using provider: ${g.name}`),!o.quiet&&!o.json&&(n.text=`Spawning ${r.cyan(t)} (${o.model||"default model"})...`);let u="",S=e=>{if(!o.json&&!o.quiet)if(e.type==="text")n.isSpinning&&n.stop(),process.stdout.write(e.content),u+=e.content;else if(e.type==="tool_use")n.isSpinning||n.start(),n.text=`${t}: ${e.content}`;else if(e.type==="tool_result"){let s=typeof e.toolResult=="string"?e.toolResult.slice(0,100):JSON.stringify(e.toolResult).slice(0,100);n.text=`${t}: Tool result (${s}...)`;}else e.type==="error"&&n.fail(e.content);},h=async e=>o.checkpoint?(console.log(r.yellow(`
\u26A0 Checkpoint: ${e}`)),console.log(r.gray("Press Enter to continue, or Ctrl+C to abort...")),new Promise(s=>{process.stdin.once("data",()=>s(true));})):true,i=await y.spawn(t,o.task,{provider:o.provider,model:o.model,budget:c,timeout:o.timeout?parseInt(o.timeout):void 0,checkpoints:o.checkpoint?{beforeActions:["write","delete","execute"]}:void 0,onMessage:S,onCheckpoint:h});if(u&&!u.endsWith(`
`)&&console.log(),o.json){console.log(JSON.stringify({success:i.success,sessionId:i.sessionId,agent:t,provider:g.name,model:o.model||"default",task:o.task,relay:i.relay,error:i.error},null,2));return}if(console.log(),console.log(r.gray("\u2500".repeat(50))),console.log(r.gray(`  Provider: ${g.name}`)),i.success?console.log(r.green(`\u2713 ${t} completed successfully`)):console.log(r.red(`\u2717 ${t} failed: ${i.error||"Unknown error"}`)),i.relay){let{metrics:e,outputs:s}=i.relay;if(console.log(r.gray(`  Tokens: ${d$1(e.tokens_used.total)}`)),console.log(r.gray(`  Duration: ${(e.duration_ms/1e3).toFixed(1)}s`)),console.log(r.gray(`  Files read: ${e.files_read}, written: ${e.files_written}`)),s.symbols.length>0&&console.log(r.gray(`  Symbols: ${s.symbols.join(", ")}`)),s.artifacts.length>0){console.log(r.cyan(`
  Artifacts:`));for(let l of s.artifacts){let d=l.action==="created"?"+":l.action==="deleted"?"-":"~";console.log(r.gray(`    ${d} ${l.path}`));}}}console.log(r.gray(`  Session: ${i.sessionId}`)),console.log();}export{J as teamSpawnCommand};