import{Bg as c,Cg as _f}from"./cli-0.5.3-4ry9q1jb.mjs";import{BO as A,EP as Df,Iz as m,JA as M,Kq as E,Lh as O,Lj as y,Lq as Jf,MA as Yf,Rj as e,Vj as N,Xh as R,Xz as T,Yh as t,Yz as Xf,_j as ff,aq as L,av as C,bP as jf,bq as P,bv as Vf,cP as g,cq as Gf,dP as S,dj as w,eo as zf,fo as Bf,gC as u,hO as I,nC as Zf,uO as v,xj as s,xs as h,ys as Qf}from"./cli-0.5.3-jbzr8k4s.mjs";import{H6 as o,z6 as F}from"./cli-0.5.3-t65dek0m.mjs";import{Lea as H,Nea as a}from"./cli-0.5.3-9vh3vpap.mjs";import{gma as r,oja as x,pia as U,qia as W,via as q}from"./cli-0.5.3-qrvd6cmy.mjs";import{Uma as K,Xma as n}from"./cli-0.5.3-0df3r78b.mjs";import{randomUUID as $f}from"crypto";async function Tf({setMessages:V,readFileState:l,discoveredSkillNames:p,loadedNestedMemoryPaths:k,getAppState:G,setAppState:J,setConversationId:X}){let Y=S();await m("clear",{getAppState:G,setAppState:J,signal:AbortSignal.timeout(Y),timeoutMs:Y});let Z=x();if(Z)H("tengu_cache_eviction_hint",{scope:"conversation_clear",last_request_id:Z});let Q=new Set,_=[],$=(f)=>("isBackgrounded"in f)&&f.isBackgrounded===!1;if(G)for(let f of Object.values(G().tasks)){if($(f))continue;if(u(f))Q.add(f.agentId),_.push(f);else if(C(f))Q.add(f.identity.agentId)}if(V(()=>[]),X)X($f());if(c(Q),T(q()),l.clear(),p?.clear(),k?.clear(),J)J((f)=>{let B={};for(let[D,z]of Object.entries(f.tasks)){if(!$(z)){B[D]=z;continue}try{if(z.status==="running"){if(E(z)){if(z.shellCommand?.kill(),z.shellCommand?.cleanup(),z.cleanupTimeoutId)clearTimeout(z.cleanupTimeoutId)}if("abortController"in z)z.abortController?.abort();if("unregisterCleanup"in z)z.unregisterCleanup?.()}}catch(i){F(i)}L(D)}return{...f,tasks:B,attribution:h(),standaloneAgentContext:void 0,fileHistory:{snapshots:[],trackedFiles:new Set,snapshotSequence:0},mcp:{clients:[],tools:[],commands:[],resources:{},pluginReconnectKey:f.mcp.pluginReconnectKey}}});y(),v();let d=U();W({setCurrentAsParent:!0}),N(d),await I();for(let f of _){if(f.status!=="running")continue;P(f.id,O(R(f.agentId)))}{let{saveMode:f}=(g(),K(jf)),{isCoordinatorMode:B}=(Bf(),K(zf));f(B()?"coordinator":"normal")}let b=w();if(b)A(b);let j=await M("clear");if(j.length>0)V(()=>j)}var bf=n(()=>{r();a();Vf();Zf();Jf();t();Qf();Df();o();e();Xf();Yf();g();Gf();ff();s();_f()});
export{Tf as zg,bf as Ag};
