import{a as k}from"./chunk-3OYDEY6T.js";import{a as f}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var E={name:"doctor",summary:"verify ag-bash environment health",usage:"doctor [OPTIONS]",options:["--quick     only run essential checks (fast)","--verbose   show detailed output for each check"],examples:["doctor           # run all checks","doctor --quick   # fast essential checks only"]};async function d(i,a,l,r){if(!i.exec)return{name:a,passed:!1,detail:"exec not available"};try{let t=await i.exec(l,{cwd:i.cwd});return t.exitCode!==0?{name:a,passed:!1,detail:t.stderr.trim()||`exit code ${t.exitCode}`}:r!==void 0&&!t.stdout.includes(r)?{name:a,passed:!1,detail:`expected "${r}", got "${t.stdout.trim()}"`}:{name:a,passed:!0,detail:t.stdout.trim()}}catch(t){let e=t instanceof Error?t.message:String(t);return{name:a,passed:!1,detail:e}}}var S={name:"doctor",execute:async(i,a)=>{if(i.includes("--help")||i.includes("-h"))return f(E);let l=i.includes("--quick"),r=i.includes("--verbose"),t=[],e=`ag-bash doctor v${k} \u2014 Environment Health Check

`;e+=`CORE ENGINE
`;let $=[{name:"Interpreter operational",script:"echo hello",expected:"hello"},{name:"Variable expansion",script:"x=42; echo $x",expected:"42"},{name:"Pipe execution",script:"echo test | cat",expected:"test"},{name:"Command substitution",script:"echo $(echo nested)",expected:"nested"},{name:"Arithmetic expansion",script:"echo $((2 + 3))",expected:"5"}];for(let n of $){let c=await d(a,n.name,n.script,n.expected);t.push(c),e+=c.passed?`  * ${c.name}
`:`  x ${c.name} \u2014 FAILED${c.detail?`: ${c.detail}`:""}
`,r&&c.detail&&(e+=`    ${c.detail}
`)}e+=`
`,e+=`FILESYSTEM
`;let x=[{name:"File write/read",script:"echo content > /tmp/doctor_test && cat /tmp/doctor_test",expected:"content"},{name:"Directory creation",script:"mkdir -p /tmp/doctor_dir && ls -d /tmp/doctor_dir",expected:"/tmp/doctor_dir"},{name:"File deletion",script:"rm /tmp/doctor_test && test ! -f /tmp/doctor_test && echo ok",expected:"ok"}];for(let n of x){let c=await d(a,n.name,n.script,n.expected);t.push(c),e+=c.passed?`  * ${c.name}
`:`  x ${c.name} \u2014 FAILED${c.detail?`: ${c.detail}`:""}
`,r&&c.detail&&(e+=`    ${c.detail}
`)}if(e+=`
`,!l){let n=a.getRegisteredCommands?a.getRegisteredCommands():[];e+=`COMMANDS (${n.length} registered)
`;let c=[{name:"Core I/O (echo, cat, ls)",script:"echo ok && cat /dev/null && ls / > /dev/null && echo pass",expected:"pass"},{name:"Text processing (grep, sort)",script:"echo hello | grep hello && echo a | sort && echo pass",expected:"pass"},{name:"Data (jq, base64)",script:`echo '{"a":1}' | jq .a && echo pass`,expected:"pass"}];for(let o of c){let s=await d(a,o.name,o.script,o.expected);t.push(s),e+=s.passed?`  * ${s.name}
`:`  x ${s.name} \u2014 FAILED${s.detail?`: ${s.detail}`:""}
`,r&&s.detail&&(e+=`    ${s.detail}
`)}e+=`
`,e+=`FEATURES
`;let g=[{name:"Brace expansion",script:"echo {1..3}",expected:"1 2 3"},{name:"Parameter default",script:"echo ${UNSET_VAR:-fallback}",expected:"fallback"},{name:"Glob expansion",script:"mkdir -p /tmp/dglob && touch /tmp/dglob/a.txt /tmp/dglob/b.txt && ls /tmp/dglob/*.txt | wc -l",expected:"2"},{name:"Conditional execution",script:"true && echo yes || echo no",expected:"yes"}];for(let o of g){let s=await d(a,o.name,o.script,o.expected);t.push(s),e+=s.passed?`  * ${s.name}
`:`  x ${s.name} \u2014 FAILED${s.detail?`: ${s.detail}`:""}
`,r&&s.detail&&(e+=`    ${s.detail}
`)}e+=`
`,e+=`OPTIONAL RUNTIMES
`;let b=[{name:"Python3 (WASM)",script:"python3 -c 'print(1+1)'",flag:"--python"},{name:"JavaScript (QuickJS)",script:"js-exec -e 'console.log(1+1)'",flag:"--javascript"},{name:"Network (curl)",script:"echo network-check",flag:"--allow-network"}];for(let o of b){if(!a.exec){t.push({name:o.name,passed:!1,skipped:!0}),e+=`  - ${o.name} (not available)
`;continue}let s=await d(a,o.name,o.script);s.passed?(e+=`  * ${o.name}
`,t.push(s)):(e+=`  - ${o.name} (not enabled \u2014 use ${o.flag})
`,t.push({...s,skipped:!0}))}e+=`
`}let m=t.filter(n=>n.passed).length,p=t.filter(n=>!n.passed&&!n.skipped).length,h=t.filter(n=>n.skipped).length,u=m+p;return p===0?e+=`RESULT: ${m}/${u} checks passed *
`:e+=`RESULT: ${m}/${u} checks passed, ${p} FAILED
`,h>0&&(e+=`       (${h} optional checks skipped)
`),{stdout:e,stderr:"",exitCode:p>0?1:0}}};export{S as doctorCommand};
