import{n as e,o as t}from"./chunk-DR8-3Aex.js";import{n,t as r}from"./figures-gfT9mM8P.js";import{F as i,In as a,Ln as o,Rn as s,b as c,t as l,tn as u,x as d}from"./src-Di342QoJ.js";import{t as f}from"./jsx-runtime-D-D469L8.js";import{Ct as p,cn as m,ot as h}from"./state-sIHsFpDu.js";import{o as g,s as _}from"./log-DSV4Ht5l.js";import{Fr as v,Gr as y,Jr as b,Jy as x,Ky as S,Lr as C,Oi as w,Ri as T,Sr as E,Xr as D,fv as O,gT as k,hT as A,kr as j,pv as M,zi as N,zr as P}from"./loadAgentsDir-C_wFhytF.js";import{t as F}from"./useTerminalSize-Du-EamDN.js";import{n as I,r as L}from"./modalContext-c5Yqx_CQ.js";import{a as R,i as z,n as B,o as V,r as H,t as U}from"./crossProjectResume-CjJISRBQ.js";function W(e){switch(e.resultType){case`sessionNotFound`:return`Session ${a.bold(e.arg)} was not found. Run ${a.bold(`/resume`)} without arguments to browse all sessions.`;case`multipleMatches`:return`Found ${e.count} sessions matching ${a.bold(e.arg)}. Run ${a.bold(`/resume`)} to pick one from the list.`}}function G({message:e,args:t,onDone:n}){return J.useEffect(()=>{let e=setTimeout(n,0);return()=>clearTimeout(e)},[n]),(0,Y.jsxs)(d,{flexDirection:`column`,children:[(0,Y.jsxs)(c,{dimColor:!0,children:[r.pointer,` /resume `,t]}),(0,Y.jsx)(A,{children:(0,Y.jsx)(c,{children:e})})]})}function K({onDone:e,onResume:t}){let[n,r]=J.useState([]),[a,o]=J.useState([]),[s,l]=J.useState(!0),[f,m]=J.useState(!1),[g,_]=J.useState(!1),{rows:v}=i(),x=L(),C=J.useCallback(async(t,n)=>{l(!0);try{let i=q(t?await y():await D(n),p());if(i.length===0){e(`No conversations found to resume`);return}r(i)}catch{e(`Failed to load conversations`)}finally{l(!1)}},[e]);J.useEffect(()=>{async function e(){let e=await T(h());o(e),C(!1,e)}e()},[C]);let w=J.useCallback(()=>{let e=!g;_(e),C(e,a)},[g,C,a]);async function E(n){let r=M(j(n));if(!r){e(`Failed to resume conversation`);return}let i=P(n)?await b(n):n,o=U(i,g,a);if(o.isCrossProject){if(o.isSameRepoWorktree){m(!0),t(r,i,`slash_command_picker`);return}let n=await u(o.command);n&&process.stdout.write(n),e([``,`This conversation is from a different directory.`,``,`To resume, run:`,`  ${o.command}`,``,`(Command copied to clipboard)`,``].join(`
`),{display:`user`});return}m(!0),t(r,i,`slash_command_picker`)}function O(){e(`Resume cancelled`,{display:`system`})}return s?(0,Y.jsxs)(d,{children:[(0,Y.jsx)(S,{}),(0,Y.jsx)(c,{children:` Loading conversations…`})]}):f?(0,Y.jsxs)(d,{children:[(0,Y.jsx)(S,{}),(0,Y.jsx)(c,{children:` Resuming conversation…`})]}):(0,Y.jsx)(R,{logs:n,maxHeight:x?Math.floor(v/2):v-2,onCancel:O,onSelect:E,onLogsChanged:()=>C(g,a),showAllProjects:g,onToggleAllProjects:w,onAgenticSearch:H})}function q(e,t){return e.filter(e=>!e.isSidechain&&j(e)!==t)}var J,Y,X;e((()=>{o(),n(),J=t(s(),1),m(),V(),k(),x(),I(),F(),l(),z(),B(),N(),g(),v(),O(),Y=f(),X=async(e,t,n)=>{let r=async(n,r,i)=>{try{await t.resume?.(n,r,i),e(void 0,{display:`skip`})}catch(t){_(t),e(`Failed to resume: ${t.message}`)}},i=n?.trim();if(!i)return(0,Y.jsx)(K,{onDone:e,onResume:r},Date.now());let a=await D(await T(h()));if(a.length===0){let t=`No conversations found to resume.`;return(0,Y.jsx)(G,{message:t,args:i,onDone:()=>e(t)})}let o=M(i);if(o){let e=a.filter(e=>j(e)===o).sort((e,t)=>t.modified.getTime()-e.modified.getTime());if(e.length>0){let t=e[0];return r(o,P(t)?await b(t):t,`slash_command_session_id`),null}let t=await E(o);if(t)return r(o,t,`slash_command_session_id`),null}if(C()){let t=await w(i,{exact:!0});if(t.length===1){let e=t[0],n=j(e);if(n)return r(n,P(e)?await b(e):e,`slash_command_title`),null}if(t.length>1){let n=W({resultType:`multipleMatches`,arg:i,count:t.length});return(0,Y.jsx)(G,{message:n,args:i,onDone:()=>e(n)})}}let s=W({resultType:`sessionNotFound`,arg:i});return(0,Y.jsx)(G,{message:s,args:i,onDone:()=>e(s)})}}))();export{X as call,q as filterResumableSessions};