import{a as e}from"./chunk-DR8-3Aex.js";import{Rn as t,t as n,x as r}from"./src-Di342QoJ.js";import{t as i}from"./jsx-runtime-D-D469L8.js";import{Ka as a,oo as o}from"./paths-Ci1iwL5Y.js";import{F as s,U as c,z as l}from"./debug-otxXY3j-.js";import{n as u,r as d}from"./analytics-DqMQntaB.js";import{$g as f,$m as p,$o as m,Eo as h,GC as g,Qg as _,Qm as v,So as y,To as b,Uo as x,WC as S,bu as C,dh as w,uh as T,xu as E}from"./loadAgentsDir-C_wFhytF.js";import{Gt as D,Kt as O}from"./prompt-6ZKyqv6z.js";import{r as k,t as A}from"./xml-CVF7dWfi.js";import{randomUUID as j}from"crypto";t(),n(),E(),f(),w();var M=i();function N({input:e,progress:t,verbose:n}){return(0,M.jsxs)(r,{flexDirection:`column`,marginTop:1,children:[(0,M.jsx)(_,{addMargin:!1,param:{text:`<bash-input>${e}</bash-input>`,type:`text`}}),t?(0,M.jsx)(T,{fullOutput:t.fullOutput,output:t.output,elapsedTimeSeconds:t.elapsedTimeSeconds,totalLines:t.totalLines,verbose:n}):C.renderToolUseProgressMessage?.([],{verbose:n,tools:[],terminalSize:void 0})]})}u(),c(),S(),x(),o();function P(){return a().defaultShell??`bash`}E(),D(),k();async function F(t,n,r,i,a){let o=O()&&P()===`powershell`;d(`tengu_input_bash`,{powershell:o});let c=h({content:m({inputString:`<bash-input>${t}</bash-input>`,precedingInputBlocks:n})}),u;a({jsx:(0,M.jsx)(N,{input:t,progress:null,verbose:i.options.verbose}),shouldHidePromptInput:!1});try{let n={...i,setToolJSX:e=>{u=e?.jsx}},s=e=>{a({jsx:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(N,{input:t,progress:e.data,verbose:i.options.verbose}),u]}),shouldHidePromptInput:!1,showSpinner:!1})},l=null;o&&(l=(p(),e(v)).PowerShellTool);let d=l??C,f=(l?await l.call({command:t,dangerouslyDisableSandbox:!0},n,void 0,void 0,s):await C.call({command:t,dangerouslyDisableSandbox:!0},n,void 0,void 0,s)).data;if(!f)throw Error(`No result received from shell command`);let m=f.stderr,_=await g(d,{...f,stderr:``},j()),b=typeof _.content==`string`?_.content:A(f.stdout);return{messages:[y(),c,...r,h({content:`<bash-stdout>${b}</bash-stdout><bash-stderr>${A(m)}</bash-stderr>`})],shouldQuery:!1}}catch(e){return e instanceof s?e.interrupted?{messages:[y(),c,b({toolUse:!1}),...r],shouldQuery:!1}:{messages:[y(),c,...r,h({content:`<bash-stdout>${A(e.stdout)}</bash-stdout><bash-stderr>${A(e.stderr)}</bash-stderr>`})],shouldQuery:!1}:{messages:[y(),c,...r,h({content:`<bash-stderr>Command failed: ${A(l(e))}</bash-stderr>`})],shouldQuery:!1}}finally{a(null)}}export{F as processBashCommand};