import{Bg as c,Cg as _f}from"./cli-0.5.4-36t0xmr2.mjs";import{As as Qf,DO as A,GP as Df,Kz as m,LA as M,Lh as O,Mq as E,Nj as y,Nq as Jf,OA as Yf,Tj as e,Xj as N,Yh as R,Zh as t,Zz as T,_z as Xf,ak as ff,cq as L,cv as C,dP as jf,dq as P,dv as Vf,eP as g,ej as w,eq as Gf,fP as S,go as zf,ho as Bf,iC as u,jO as I,pC as Zf,wO as v,zj as s,zs as h}from"./cli-0.5.4-k5fz4zd3.mjs";import{B6 as F,J6 as o}from"./cli-0.5.4-cbq01zg3.mjs";import{Nea as H,Pea as a}from"./cli-0.5.4-09dvrzcr.mjs";import{ima as r,qja as x,ria as U,sia as W,xia as q}from"./cli-0.5.4-jmc3bzbn.mjs";import{Wma as K,Zma as n}from"./cli-0.5.4-aacw1src.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};
