#!/usr/bin/env node
import*as i from'fs';import*as d from'path';import*as f from'js-yaml';var o=new Map,u=null,P=false,m=["claude","claude-code-teams","claude-code","cursor-cli","claude-cli","manual"],p=["auto",...m],g=null;function l(r){o.set(r.name,r);}function h(r){return r&&o.has(r)?o.get(r)||null:u&&o.has(u)&&o.get(u)||null}function y(r){let a=process.env.PARADIGM_AGENT_PROVIDER;if(a&&p.includes(a))return a;if(g!==null)return g;let e=r||process.cwd(),t=d.join(e,".paradigm","config.yaml");if(i.existsSync(t))try{let n=i.readFileSync(t,"utf-8"),c=f.load(n)["agent-provider"];if(c&&p.includes(c))return g=c,c}catch{}return "auto"}async function A(r,a){if(!p.includes(r))throw new Error(`Invalid provider: ${r}. Valid options: ${p.join(", ")}`);let e=a||process.cwd(),t=d.join(e,".paradigm","config.yaml"),n={};if(i.existsSync(t))try{let c=i.readFileSync(t,"utf-8");n=f.load(c);}catch{}n["agent-provider"]=r,g=r;let s=d.dirname(t);i.existsSync(s)||i.mkdirSync(s,{recursive:true}),i.writeFileSync(t,f.dump(n));}async function I(r,a){await w(r);let e=a||y(r),t=e!=="auto";if(t){let n=o.get(e);if(n){try{if(await n.isAvailable())return {provider:n,name:e,reason:`Configured: ${v(e)}`,configured:!0}}catch{}console.warn(`Configured provider '${e}' not available, falling back...`);}}for(let n of m){let s=o.get(n);if(s)try{if(await s.isAvailable())return {provider:s,name:n,reason:t?`Fallback: ${v(n)} (configured '${e}' unavailable)`:v(n),configured:!1}}catch{}}throw new Error("No providers available")}async function R(r){await w(r);let a=[];for(let e of m){let t=o.get(e);if(!t)continue;let n=false;try{n=await t.isAvailable();}catch{}a.push({name:e,available:n,reason:n?v(e):C(e),features:{parallel:t.supportsParallel(),mcp:t.supportsMcp(),billing:b(e)}});}return a}async function w(r){if(P)return;let a=r||process.cwd();try{let{ClaudeAgentProvider:e}=await import('./claude-4LR3LJQZ.js');l(new e);}catch{}try{let{ClaudeCodeTeamsProvider:e}=await import('./claude-code-teams-R37HJY3Y.js');l(new e(a));}catch{}try{let{ClaudeCodeTaskProvider:e}=await import('./claude-code-RLJ4GX77.js');l(new e(a));}catch{}try{let{CursorCliProvider:e}=await import('./cursor-cli-QKF7Z6M2.js');l(new e);}catch{}try{let{ClaudeCliProvider:e}=await import('./claude-cli-UP6HGH7C.js');l(new e);}catch{}try{let{ManualProvider:e}=await import('./manual-RXSPSFLL.js');l(new e(a));}catch{}for(let e of m){let t=o.get(e);if(t)try{if(await t.isAvailable()){u=e;break}}catch{}}!u&&o.has("manual")&&(u="manual"),P=true;}function v(r){switch(r){case "claude":return "Using Anthropic API (ANTHROPIC_API_KEY found)";case "claude-code-teams":return "Using Claude Code Agent Teams (experimental, parallel teammates)";case "claude-code":return "Using Claude Code Task tool (running in Claude Code)";case "cursor-cli":return "Using Cursor agent CLI (running in Cursor)";case "claude-cli":return "Using Claude CLI (claude command found)";case "manual":return "Using manual handoff (no automation available)";default:return "Unknown provider"}}function C(r){switch(r){case "claude":return "ANTHROPIC_API_KEY not set";case "claude-code-teams":return "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS not set or not in Claude Code";case "claude-code":return "Not running inside Claude Code";case "cursor-cli":return "Not running in Cursor or agent CLI not found";case "claude-cli":return "claude CLI not found in PATH";case "manual":return "Should always be available";default:return "Unknown"}}function b(r){switch(r){case "claude":return "api";case "claude-code-teams":case "claude-code":case "cursor-cli":case "claude-cli":return "subscription";case "manual":return "none";default:return "none"}}export{h as a,y as b,A as c,I as d,R as e,w as f};