var x=Object.defineProperty;var l=(e,o)=>x(e,"name",{value:o,configurable:!0});import{b as h,h as E,_ as S,R as v}from"../packem_shared/ai-analysis-3QD_RS6F.js";import{d as w,R as D,y as P}from"./bin.js";import{j as I,E as d,q as R,I as j,e as N}from"../packem_shared/Table-3pFgIUZ2-DABgc6rj.js";var C=Object.defineProperty,u=l((e,o)=>C(e,"name",{value:o,configurable:!0}),"s");const f={command:"ai",description:"AI-assisted commands: provider detection, cache management, and failure-fix proposals."},O=u(e=>{if(typeof e!="function")return String(e);const{name:o}=e;return o==="Boolean"?"boolean":o==="Number"?"number":o==="String"?"string":o??"unknown"},"typeName"),A=u(e=>{const o=[...e.commandPath??[],e.name].join(" "),i=(e.examples??[]).map(([a,s])=>({command:a??"",description:s??""})),t=(e.options??[]).map(a=>({defaultValue:a.defaultValue,description:a.description,name:a.name,type:O(a.type)}));return{argument:e.argument?{description:e.argument.description,name:e.argument.name}:void 0,description:e.description??"",examples:i,name:e.name,options:t,path:o}},"buildSubcommand"),g=u((e,o=f)=>({command:o.command,description:o.description,subcommands:e.map(i=>A(i))}),"buildDiscoveryPayload"),J=u((e,o=f)=>`${JSON.stringify(g(e,o),void 0,2)}
`,"renderDiscoveryJson"),T=u((e,o=f)=>{const i=g(e,o),t=[I(`vis ${i.command} — ${i.description}`),"",d("Subcommands:")];for(const a of i.subcommands){const s=a.argument?` ${R(`<${a.argument.name}>`)}`:"";if(t.push(""),t.push(`  ${j(`vis ${a.path}`)}${s}`),a.description&&t.push(`    ${a.description}`),a.options.length>0){const n=a.options.map(c=>`--${c.name}${c.type==="boolean"?"":`=<${c.type}>`}`).join(", ");t.push(d(`    options: ${n}`))}if(a.examples.length>0){t.push(d("    examples:"));for(const n of a.examples){const c=n.description?d(` — ${n.description}`):"";t.push(`      ${N(n.command)}${c}`)}}}return t.push(""),t.push(d(`Run \`vis ${i.command} discover-help\` for the machine-readable JSON catalogue (designed for AI agents).`)),t.push(d(`Run \`vis ${i.command} <subcommand> --help\` for full usage of a specific subcommand.`)),`${t.join(`
`)}
`},"renderDiscoveryText");var F=Object.defineProperty,p=l((e,o)=>F(e,"name",{value:o,configurable:!0}),"r");const y=p(async()=>{const{default:e}=await import("./bin.js").then(o=>o.c6);return e.filter(o=>o.name!=="ai")},"loadDiscoverableSubcommands"),q=p(async()=>{const e=await y();process.stderr.write(T(e))},"aiRootExecute"),B=p(async()=>{const e=await y();process.stdout.write(J(e))},"aiDiscoverHelpExecute"),K=p(async({logger:e,visConfig:o})=>{const i=o?.ai,t=h(i);if(!t){e.error("No AI provider available to test."),process.exitCode=1;return}e.info(`Testing ${t.name}...`);try{const a=await E(t,"Reply with exactly: OK",{timeoutMs:3e4});e.info(`Provider ${t.name} responded: ${a.stdout.trim().slice(0,200)}`)}catch(a){const s=a instanceof Error?a.message:String(a);e.error(`Provider ${t.name} failed: ${s}`),process.exitCode=1}},"aiTestExecute"),L=p(({logger:e,options:o,visConfig:i})=>{const t=o.format??"table",a=i?.ai,s=S(),n=h(a);if(t==="json"){const r=s.map(m=>({available:m.available,method:m.detectionMethod,name:m.name,path:m.path,priority:v[m.name]??0,selected:m.name===n?.name,version:m.version}));process.stdout.write(`${JSON.stringify(r,void 0,2)}
`);return}const c=s.map(r=>({method:r.detectionMethod??"-",path:r.path??"-",priority:String(v[r.name]??0),provider:r.name,selected:r.name===n?.name?">>>":"",status:r.available?"available":"not found",version:r.version??"-"})),$=process.stdout.columns||80,b=w(D.createElement(P,{data:c}),{columns:$});e.info(b),n?e.info(`
Selected provider: ${n.name} (priority ${String(v[n.name]??0)})`):e.info(`
No AI provider available. Install one of the supported AI CLI tools.`)},"aiProvidersExecute"),_=p(async e=>{const{aiFix:o}=await import("./fix.js");await o(e)},"aiFixExecute");export{B as aiDiscoverHelpExecute,_ as aiFixExecute,L as aiProvidersExecute,q as aiRootExecute,K as aiTestExecute};
