import{Cg as c,Dg as _f}from"./cli-0.5.12-eb1c0sqs.mjs";import{$z as T,BP as g,Bs as h,Cs as Qf,Dk as y,Jk as zf,Mz as m,NA as M,Nk as N,Oq as E,Pq as Jf,QA as Yf,Rj as s,Sj as e,Sk as Bf,TN as I,Yj as w,Zu as C,_u as Vf,aA as Xf,bQ as Df,cQ as S,di as O,dq as L,eq as P,fq as Gf,hP as v,kC as u,qi as R,rC as Zf,ri as t,rk as ff,sO as jf,uP as A}from"./cli-0.5.12-zc0qwdy2.mjs";import{Bca as H,Jca as a}from"./cli-0.5.12-g4wb8mj2.mjs";import{dfa as F,ffa as o}from"./cli-0.5.12-2jxq8gnm.mjs";import{Aia as U,Bia as W,Gia as q,rma as r,zja as x}from"./cli-0.5.12-c8f4daey.mjs";import{Zna as K,aoa as n}from"./cli-0.5.12-xzeb7mtb.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=I();await m("clear",{getAppState:G,setAppState:J,signal:AbortSignal.timeout(Y),timeoutMs:Y});let Z=x();if(Z)F("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){H(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(),A();let d=U();W({setCurrentAsParent:!0}),N(d),await v();for(let f of _){if(f.status!=="running")continue;P(f.id,O(R(f.agentId)))}{let{saveMode:f}=(S(),K(Df)),{isCoordinatorMode:B}=(e(),K(s));f(B()?"coordinator":"normal")}let b=w();if(b)g(b);let j=await M("clear");if(j.length>0)V(()=>j)}var bf=n(()=>{r();o();Vf();Zf();Jf();t();Qf();jf();a();zf();Xf();Yf();S();Gf();Bf();ff();_f()});
export{Tf as Ag,bf as Bg};
