import{a as e,n as t}from"./chunk-DR8-3Aex.js";import{Ct as n,Jn as r,Xn as i,Z as a,cn as o,gn as ee,ot as s,qn as c,yn as l}from"./state-sIHsFpDu.js";import{n as u,r as d}from"./analytics-DqMQntaB.js";import{o as f,s as p}from"./log-DSV4Ht5l.js";import{$t as m,Ab as h,Ai as g,Cn as _,Di as v,Fn as y,Fr as b,GE as x,In as S,Mu as C,Nn as w,Nu as T,Ot as E,RE as D,Tt as O,_d as k,_r as A,by as j,ey as M,gi as N,jb as P,lv as F,mh as I,mn as L,ph as R,py as z,qE as B,sr as V,ty as H,uv as U,vd as W,zE as G}from"./loadAgentsDir-C_wFhytF.js";import{C as K,y as q}from"./rcDebugLog-C42A0pX1.js";import{l as J,r as Y}from"./commitAttribution-iKd8bTOI.js";import{n as X,t as Z}from"./caches-BumkMuGA.js";import{randomUUID as Q}from"crypto";function $(){let e=k();if(!e)return;e.markTranscriptReset?.();let t={type:`status`,subtype:`status`,status:`conversation_cleared`,message:`conversation_cleared`,uuid:Q()};e.writeSdkMessages([t])}async function te({setMessages:t,readFileState:o,discoveredSkillNames:u,loadedNestedMemoryPaths:f,getAppState:h,setAppState:_,setConversationId:S}){let C=L();await m(`clear`,{getAppState:h,setAppState:_,signal:AbortSignal.timeout(C),timeoutMs:C});let E=a();E&&d(`tengu_cache_eviction_hint`,{scope:`conversation_clear`,last_request_id:E});let k=new Set,j=[],M=e=>`isBackgrounded`in e&&e.isBackgrounded===!1;if(h)for(let e of Object.values(h().tasks))M(e)||(T(e)?(k.add(e.agentId),j.push(e)):P(e)&&k.add(e.identity.agentId));t(()=>[]),$();{let{setContextBlocked:t}=(q(),e(K));t(!1)}S&&S(Q()),Z(k),c(null),r(null),i(null),l(),I(s()),o.clear(),u?.clear(),f?.clear(),_&&_(e=>{let t={};for(let[n,r]of Object.entries(e.tasks)){if(!M(r)){t[n]=r;continue}try{r.status===`running`&&(U(r)&&(r.shellCommand?.kill(),r.shellCommand?.cleanup(),r.cleanupTimeoutId&&clearTimeout(r.cleanupTimeoutId)),`abortController`in r&&r.abortController?.abort(),`unregisterCleanup`in r&&r.unregisterCleanup?.())}catch(e){p(e)}w(n)}return{...e,tasks:t,attribution:Y(),standaloneAgentContext:void 0,fileHistory:{snapshots:[],trackedFiles:new Set,snapshotSequence:0},mcp:{clients:[],tools:[],commands:[],resources:{},pluginReconnectKey:e.mcp.pluginReconnectKey}}}),z(),V(),ee({setCurrentAsParent:!0}),process.env.USER_TYPE===`ant`&&process.env.CLAUDE_CODE_SESSION_ID&&(process.env.CLAUDE_CODE_SESSION_ID=n()),await N();for(let e of j)e.status===`running`&&y(e.id,A(x(e.agentId)));{let{saveMode:t}=(b(),e(g)),{isCoordinatorMode:n}=(G(),e(D));t(n()?`coordinator`:`normal`)}let F=O();F&&v(F);let R=await H(`clear`);R.length>0&&t(()=>R)}var ne=t((()=>{W(),o(),u(),h(),C(),F(),B(),J(),_(),f(),j(),R(),M(),b(),S(),E(),X()}));export{ne as n,te as t};