@adhdev/daemon-standalone 1.0.60-rc.13 → 1.0.60-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,7 +49,7 @@ ${JSON.stringify(t,null,2)}
|
|
|
49
49
|
`).length:0," lines)"]})]}),u&&s.jsx("pre",{className:"mt-1.5 px-3 py-2 font-mono text-2xs text-text-secondary whitespace-pre bg-bg-secondary rounded-md border border-border-default max-h-64 overflow-auto",children:Y.screen||"(empty)"})]})]})]})]})})})}function _f(e,t){if(typeof window>"u")return!1;try{return window[e]===!0||window.localStorage.getItem(t)==="1"}catch{return window[e]===!0}}function h1(){return _f("__ADHDEV_DEBUG_SPEC__","adhdev_debug_spec")}function f1(){return _f("__ADHDEV_DEBUG_MOBILE_BUNDLE__","adhdev_debug_mobile_bundle")}function g1({activeConv:e,clearToken:t=0,terminalRef:n,handleSendChat:a,isSendingChat:o=!1,sendFeedbackMessage:r=null,isVisible:i=!0,isInputActive:c=!0}){var ht;const{t:d}=ye("common");Gs();const{sendPtyInput:u}=wt(),[p,m]=l.useState(!1),h=l.useRef(!1);h.current=p;const[f,x]=l.useState("Runtime terminal unavailable"),[b,g]=l.useState(!1),[S,j]=l.useState(null),[y,k]=l.useState(!1),[v,C]=l.useState(!1),[w,N]=l.useState(1),[T,A]=l.useState(!1),[P,D]=l.useState(!1),[L,I]=l.useState(!1),[R,_]=l.useState(!1),[M,$]=l.useState(!1),V=h1(),[z,W]=l.useState({width:0,height:0}),[F,B]=l.useState({width:0,height:0}),[E,H]=l.useState({scrollTop:0,scrollHeight:0,clientHeight:0,atTop:!1,canScroll:!1}),[J,q]=l.useState(null),ie=l.useRef(null),xe=l.useRef(null),Y=l.useRef(!1),ne=l.useRef(!1),me=l.useRef(i),ce=l.useRef(0),ae=l.useRef(!1),he=l.useRef(""),oe=l.useRef(null),re=l.useRef(!1),ee=l.useRef(!1),G=l.useRef(null),Q=l.useRef(null),ue=l.useRef(null),pe=32*1024,Ae=()=>{var ke,De,Re,Xe;return((De=(ke=ie.current)==null?void 0:ke.ownerDocument)==null?void 0:De.defaultView)||((Xe=(Re=xe.current)==null?void 0:Re.ownerDocument)==null?void 0:Xe.defaultView)||window},Me=ke=>{const De=Ae();return{ownerWindow:De,frameId:De.requestAnimationFrame(ke)}},He=()=>{const ke=G.current;if(ke){try{ke.ownerWindow.cancelAnimationFrame(ke.frameId)}catch{}G.current=null}},je=()=>{const ke=Q.current;if(ke){try{ke.ownerWindow.clearTimeout(ke.timeoutId)}catch{}Q.current=null}},Z=()=>{const ke=ue.current;if(ke){try{ke.ownerWindow.clearTimeout(ke.timeoutId)}catch{}ue.current=null}},O=()=>{i&&G.current===null&&(G.current=Me(()=>{be()}))},X=e.tabKey,te=e.sessionId||"",de=e.daemonId||((ht=e.routeId)==null?void 0:ht.split(":")[0])||e.routeId||"",ve=ad(e),fe=p?ve?cf:r:f,U=p&&r||null,Ce=zA,Pe=GA,Be=.05,qe=()=>{const ke=F.width,De=F.height;if(!Number.isFinite(z.width)||z.width<=0||!Number.isFinite(z.height)||z.height<=0||!Number.isFinite(ke)||ke<=0||!Number.isFinite(De)||De<=0)return 1;const Re=z.width/ke,Xe=z.height/De;return Number(Math.min(Pe,Math.max(Ce,Math.min(Re,Xe))).toFixed(2))},We=qe(),Ie=Y.current&&w>We,ge=Number.isFinite(F.width)&&F.width>0?Math.max(z.width,Math.round(F.width*w)):z.width,Se=Number.isFinite(F.height)&&F.height>0?Math.max(z.height,Math.round(F.height*w)):z.height,Te=()=>{Me(()=>{const ke=xe.current;ke&&(ke.scrollLeft=0,ke.scrollTop=ke.scrollHeight-ke.clientHeight)})},Je=()=>{var ke,De;ce.current=0,ae.current=!1,he.current="",oe.current=null,re.current=!1,ee.current=!1,Y.current||(ne.current=!1,N(1)),G.current!==null&&He(),m(!1),x("Runtime terminal unavailable"),Z(),je(),j(null),q(null),A(!1),g(!1),k(!1),C(!1),(De=(ke=n.current)==null?void 0:ke.reset)==null||De.call(ke)},K=()=>{var ke,De;ce.current=0,ae.current=!1,he.current="",oe.current=null,re.current=!1,ee.current=!1,G.current!==null&&He(),m(!0),x(""),Z(),je(),j(null),q(null),A(!1),g(!1),k(!1),C(!1),(De=(ke=n.current)==null?void 0:ke.reset)==null||De.call(ke)},se=()=>{ee.current&&(ee.current=!1,Me(()=>{var ke,De;(De=(ke=n.current)==null?void 0:ke.scrollToTop)==null||De.call(ke)}))},be=()=>{if(G.current=null,!i)return;const ke=he.current;if(!ke)return;const De=ke.slice(0,pe);he.current=ke.slice(De.length);const Re=n.current;if(!Re){he.current=De+he.current,O();return}Re.write(De,()=>{if(he.current.length>0){O();return}se()})},we=ke=>{ke&&(he.current+=ke,O())},Ne=(ke,De=0,Re,Xe,st={})=>{var mt,Et,bt,Qt;const ze=!!st.force;!ze&&De>0&&ce.current>=De||!ze&&De===0&&ae.current||(ce.current=De,De>0&&k(!0),m(!0),x(""),typeof Re=="number"&&typeof Xe=="number"&&Re>0&&Xe>0&&((Et=(mt=n.current)==null?void 0:mt.resize)==null||Et.call(mt,Re,Xe)),he.current="",(Qt=(bt=n.current)==null?void 0:bt.reset)==null||Qt.call(bt),ke?we(ke):se())};l.useEffect(()=>{Je()},[te]),l.useEffect(()=>{var De;if(!te)return;const ke=((De=_t.onRuntimeEvent)==null?void 0:De.call(_t,te,Re=>{if(!(!Re||Re.sessionId!==te)){if(Re.type==="runtime_snapshot"){if(!i){oe.current={text:Re.text||"",seq:Re.seq||0,cols:Re.cols,rows:Re.rows,force:!!Re.force};return}Ne(Re.text||"",Re.seq||0,Re.cols,Re.rows,{force:!!Re.force});return}if(Re.type==="session_output"){ae.current=!0,typeof Re.seq=="number"&&(ce.current=Math.max(ce.current,Re.seq),Re.seq>0&&k(!0)),h.current||m(!0),h.current||x(""),typeof Re.data=="string"&&we(Re.data);return}if(Re.type==="session_cleared"){if(!i){re.current=!0,he.current="",oe.current=null;return}K();return}if(Re.type==="session_io_error"){const Xe=typeof Re.error=="string"&&Re.error?Re.error:typeof Re.reason=="string"&&Re.reason?Re.reason:"unknown error";m(!1),x(`Runtime input failed: ${Xe}`);return}}},de))||(()=>{});return()=>{ke()}},[de,te,n,i]);const Le=async(ke={})=>{var De;if(!de||!te)return{success:!1,error:"daemonId and sessionId are required"};ke.preserveStatus||x(ke.loadingMessage||"Loading runtime terminal...");try{const Re=await((De=_t.requestRuntimeSnapshot)==null?void 0:De.call(_t,de,te,{sinceSeq:ke.sinceSeq,force:ke.force}));return Re&&Re.success===!1?(ke.preserveStatus||(m(!1),x(`Runtime terminal unavailable: ${Re.error}`)),Re):Re||{success:!0}}catch(Re){const Xe=(Re==null?void 0:Re.message)||String(Re);return ke.preserveStatus||(m(!1),x(`Runtime terminal unavailable: ${Xe}`)),{success:!1,error:Xe}}},$e=async ke=>{var ze,mt;const De=((ze=ie.current)==null?void 0:ze.ownerDocument)||document,Re=De.defaultView||window,Xe=(mt=Re.navigator)==null?void 0:mt.clipboard;if(Xe!=null&&Xe.writeText&&Re.isSecureContext)try{return await Xe.writeText(ke),!0}catch{}let st=null;try{return st=De.createElement("textarea"),st.value=ke,st.setAttribute("readonly","true"),st.style.position="fixed",st.style.left="-9999px",st.style.top="0",De.body.appendChild(st),st.focus(),st.select(),De.execCommand("copy")}catch{return!1}finally{st==null||st.remove()}},Fe=ke=>{je(),q(ke);const De=Ae();Q.current={ownerWindow:De,timeoutId:De.setTimeout(()=>{Q.current=null,q(Re=>Re===ke?null:Re)},2200)}},tt=ke=>{Z(),j(ke);const De=Ae();ue.current={ownerWindow:De,timeoutId:De.setTimeout(()=>{ue.current=null,j(Re=>Re===ke?null:Re)},2200)}},nt=async()=>{var st,ze,mt,Et;const ke=((ze=(st=n.current)==null?void 0:st.getSelection)==null?void 0:ze.call(st))||"",De=((Et=(mt=n.current)==null?void 0:mt.getVisibleText)==null?void 0:Et.call(mt))||"",Re=ke.trimEnd()||De.trimEnd();if(!Re){Fe("Nothing to copy");return}if(!await $e(Re)){Fe("Copy failed");return}Fe(ke.trimEnd()?"Copied selection":"Copied visible terminal")},rt=ke=>{if(!p||!i)return;((u==null?void 0:u(de,te,ke))??!1)||Fe("Terminal input failed")},Ue=ke=>{rt(VA({ctrl:P,alt:L,shift:R},ke)),D(!1),I(!1),_(!1)},at=async()=>{if(b)return;g(!0),j("Loading older terminal output..."),ee.current=!0;const ke=await Le({sinceSeq:0,force:!0,loadingMessage:"Loading older terminal output...",preserveStatus:p});if(g(!1),(ke==null?void 0:ke.success)===!1){ee.current=!1,j(`Older terminal output unavailable: ${ke.error}`);return}C(!0),tt("Older terminal output loaded"),Me(()=>{var De;(De=n.current)==null||De.bumpResize()})};l.useEffect(()=>{var De,Re;if(!te)return;de&&((De=_t.getState)==null?void 0:De.call(_t,de))==="connected"&&Le();const ke=(Re=_t.onStateChange)==null?void 0:Re.call(_t,(Xe,st)=>{Xe!==de||st!=="connected"||Le()});return()=>{ke==null||ke()}},[de,te,n]),l.useEffect(()=>{t&&Je()},[t,X,n]),l.useEffect(()=>{var Xe,st;const ke=ie.current,De=(st=(Xe=ke==null?void 0:ke.ownerDocument)==null?void 0:Xe.defaultView)==null?void 0:st.ResizeObserver;if(!ke||!De)return;const Re=new De(ze=>{const mt=ze[0];if(!mt)return;const{width:Et,height:bt}=mt.contentRect;W(Qt=>{const Ht=Math.round(Et),Lt=Math.round(bt);return Qt.width===Ht&&Qt.height===Lt?Qt:{width:Ht,height:Lt}})});return Re.observe(ke),()=>Re.disconnect()},[]),l.useEffect(()=>{if(Y.current)return;const ke=qe();!Number.isFinite(ke)||ke<=0||N(De=>ne.current?ke<De-Be?ke:De:(ne.current=!0,ke))},[F.height,F.width,z.height,z.width]),l.useEffect(()=>{Ie&&Te()},[Ie,Se,ge]),l.useEffect(()=>{var Re;const ke=me.current;if(me.current=i,!i)return;ke||C(!1),re.current&&(re.current=!1,K());const De=oe.current;De&&(oe.current=null,Ne(De.text,De.seq,De.cols,De.rows,{force:!!De.force})),de&&te&&((Re=_t.getState)==null?void 0:Re.call(_t,de))==="connected"&&Le(),he.current&&G.current===null&&O(),Me(()=>{var Xe;(Xe=n.current)==null||Xe.bumpResize()})},[de,i,te]),l.useEffect(()=>()=>{G.current!==null&&He(),je(),Z()},[]),l.useEffect(()=>{const ke=Xe=>{var ze;const st=Xe.detail;st!=null&&st.sessionId&&st.sessionId!==te||p&&((ze=n.current)==null||ze.bumpResize())},De=Ae(),Re=De===window?[window]:[window,De];for(const Xe of Re)Xe.addEventListener("adhdev:fit-cli-terminal",ke);return()=>{for(const Xe of Re)Xe.removeEventListener("adhdev:fit-cli-terminal",ke)}},[p,te,n]);const Qe=p&&y&&!v&&(E.atTop||!E.canScroll)||b||!!S;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{ref:ie,className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[Qe&&s.jsxs("div",{className:"absolute left-3 top-3 z-10 flex items-center gap-2",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-2xs font-medium text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{at()},disabled:!te||b,title:"Replay raw session scrollback so the terminal viewport can scroll farther up",children:d(b?"terminal.loadingOlder":"terminal.loadOlderOutput")}),S&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-3xs text-white/70 backdrop-blur-sm",children:S})]}),s.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[J&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-3xs text-white/70 backdrop-blur-sm",children:J}),V&&s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-2xs font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>$(ke=>!ke),title:"Spec debug — inspect current state, sections, and transition history",children:d("terminal.debug")}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-2xs font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{nt()},disabled:!p,title:"Copy selected terminal text, or the visible terminal viewport if nothing is selected",children:d("terminal.copy")}),s.jsxs("div",{className:"relative",children:[s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-2xs font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>A(ke=>!ke),disabled:!p,"aria-label":d(T?"terminal.closeControlKeys":"terminal.openControlKeys"),"aria-expanded":T,"aria-controls":"terminal-control-keys-popover",title:"Open mobile-friendly terminal control keys",children:"Keys"}),T&&s.jsxs("div",{id:"terminal-control-keys-popover",role:"dialog","aria-label":d("terminal.openControlKeys"),className:"absolute right-0 top-10 w-72 rounded-2xl border border-white/10 bg-[#0b0d12]/95 p-3 text-white/85 shadow-2xl shadow-black/40 backdrop-blur-md",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-3xs font-semibold uppercase tracking-[0.14em] text-white/45",children:"Terminal keys"}),s.jsx("button",{type:"button",className:"rounded-full px-2 py-0.5 text-2xs text-white/55 transition-colors hover:bg-white/10 hover:text-white/85",onClick:()=>A(!1),"aria-label":d("terminal.closeControlKeys"),children:"×"})]}),s.jsx("div",{className:"mb-2 grid grid-cols-3 gap-1.5",children:[["Ctrl",P,D],["Alt",L,I],["Shift",R,_]].map(([ke,De,Re])=>s.jsx("button",{type:"button","aria-pressed":De,className:`h-9 rounded-lg border text-xs font-semibold transition-colors ${De?"border-sky-400/50 bg-sky-400/25 text-white":"border-white/10 bg-white/[0.06] hover:bg-white/[0.12]"}`,onClick:()=>Re(Xe=>!Xe),children:ke},ke))}),s.jsx("div",{className:"my-2 h-px bg-white/10"}),s.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("Escape"),children:"Esc"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("Tab"),children:"Tab"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("Enter"),children:"Enter"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] leading-[22px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("ArrowUp"),"aria-label":"Arrow up",children:"↑"}),s.jsx("span",{"aria-hidden":"true"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] leading-[22px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("ArrowLeft"),"aria-label":"Arrow left",children:"←"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] leading-[22px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("ArrowDown"),"aria-label":"Arrow down",children:"↓"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[15px] leading-[22px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("ArrowRight"),"aria-label":"Arrow right",children:"→"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>rt(""),title:"Send SIGINT (Ctrl-C)",children:"Ctrl-C"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("Space"),children:"Space"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-xs font-semibold hover:bg-white/[0.12]",onClick:()=>Ue("Backspace"),children:"Bksp"})]})]})]}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{Y.current=!0,N(ke=>{const De=Math.max(We,Number((ke-.1).toFixed(2)));return De>We&&Te(),De})},title:"Shrink terminal viewport",children:"-"}),s.jsx("button",{type:"button",className:"h-8 w-8 rounded-full border border-white/10 bg-black/35 text-sm font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>{Y.current=!0,N(ke=>{const De=Math.min(Pe,Number((ke+.1).toFixed(2)));return De>We&&Te(),De})},title:"Increase terminal viewport",children:"+"})]}),s.jsx("div",{ref:xe,className:Ie?"w-full h-full overflow-auto rounded-lg overscroll-contain":"w-full h-full overflow-hidden rounded-lg overscroll-contain",children:s.jsx("div",{style:{width:ge>0?`${ge}px`:"100%",height:Se>0?`${Se}px`:"100%",minWidth:"100%",minHeight:"100%",position:"relative"},children:s.jsx("div",{style:{width:F.width>0?`${F.width}px`:"100%",height:F.height>0?`${F.height}px`:"100%",position:"absolute",left:0,bottom:0,zoom:w},children:s.jsx(gh,{ref:n,readOnly:!p||!i,sizingMode:"measured",onViewportMetrics:B,onScrollMetrics:H,onInput:ke=>{!p||(u==null||u(de,te,ke))}})})})}),!p&&s.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-2xs text-red-300 pointer-events-none",children:f})]}),s.jsx(Wh,{contextKey:e.tabKey,panelLabel:At(e),isSending:o,isBusy:!!ve,statusMessage:fe,inlineStatusMessage:U,onSend:async ke=>ve?!1:a(ke),isActive:c&&i,showControlsToggle:!1,animateVisibility:!1}),M&&s.jsx(m1,{activeConv:e,onClose:()=>$(!1)})]})}const b1=5e3,x1=12e3,v1=15e3;function y1(e){return e==="disconnected"||e==="reconnecting"}function w1({wsStatus:e,showReconnected:t,loginUrl:n,onReconnect:a,reconnectDelayMs:o=b1,reconnectActionDelayMs:r=x1}){const{t:i}=ye(),c=y1(e),[d,u]=l.useState(()=>!c||o<=0),[p,m]=l.useState(()=>!c||r<=0),h=l.useRef(!1),[f,x]=l.useState(!1);l.useEffect(()=>{if(!c){u(!1);return}if(h.current=!1,o<=0){h.current=!0,u(!0);return}u(!1);const T=setTimeout(()=>{h.current=!0,u(!0)},o);return()=>clearTimeout(T)},[o,c]),l.useEffect(()=>{if(!c){m(!1);return}if(r<=0){m(!0);return}m(!1);const T=setTimeout(()=>{m(!0)},r);return()=>clearTimeout(T)},[r,c]),l.useEffect(()=>{e!=="reconnecting"&&x(!1)},[e]),l.useEffect(()=>{if(!f)return;const T=setTimeout(()=>x(!1),v1);return()=>clearTimeout(T)},[f]);const b=()=>{x(!0),a==null||a()},g=c?d:e==="offline"||e==="auth_failed",S=!!(a&&e!=="auth_failed"&&(!c||p)),j=l.useMemo(()=>!t||e!=="connected"?!1:o<=0||h.current,[o,t,e]),y=e==="auth_failed"?"red":e==="offline"?"orange":"accent",k={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",accent:"linear-gradient(90deg, color-mix(in srgb, var(--accent-primary) 18%, transparent), color-mix(in srgb, var(--accent-primary) 6%, transparent))"},v={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",accent:"1px solid color-mix(in srgb, var(--accent-primary) 28%, transparent)"},C={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"},w="fixed left-1/2 top-[calc(env(safe-area-inset-top,0px)+64px)] sm:top-[calc(env(safe-area-inset-top,0px)+16px)] z-[var(--z-toast)] flex items-center justify-center pointer-events-none",N={transform:"translateX(-50%)"};return s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{className:w,style:N,children:s.jsxs("div",{className:"pointer-events-auto max-w-[min(720px,calc(100vw-24px))] rounded-2xl border px-3 py-2.5 sm:px-4 sm:py-3 text-xxs font-semibold flex flex-wrap items-center gap-x-2.5 gap-y-2 justify-center shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:k[y],border:v[y],color:C[y]},children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5 shrink-0",style:{opacity:e==="auth_failed"?.6:1,animation:e==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:e==="auth_failed"?"grayscale(1)":void 0}}),s.jsxs("span",{className:"min-w-0 text-center whitespace-nowrap",children:[e==="offline"&&i("connection.networkOffline"),e==="disconnected"&&i("connection.reconnecting"),e==="reconnecting"&&i("connection.reconnecting"),e==="auth_failed"&&(n?s.jsxs(s.Fragment,{children:[i("connection.sessionExpired")," ",s.jsx("a",{href:n,className:"text-inherit underline",children:i("connection.logInAgain")})]}):i("connection.connectionFailed"))]}),S&&s.jsxs("button",{type:"button",className:"basis-full sm:basis-auto mx-auto sm:mx-0 sm:ml-1 shrink-0 px-2.5 py-1 rounded-md border border-current/30 text-xs font-semibold hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center gap-1.5",onClick:b,disabled:e==="offline"||f,children:[f&&s.jsx(Cs,{size:11,thickness:2,color:"muted"}),i(f?"connection.reconnecting":"connection.reconnectNow")]})]})}),j&&s.jsx("div",{className:w,style:N,children:s.jsxs("div",{className:"pointer-events-none rounded-2xl border px-4 py-2 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-green-500/15 shadow-[0_18px_40px_rgba(2,6,23,0.2)] backdrop-blur-xl animate-[fadeIn_0.3s_ease]",children:[s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),i("connection.connected")]})})]})}function Ef({mode:e,onChange:t,compact:n=!1}){const{t:a}=ye("common"),o=n?14:15;return s.jsx("button",{type:"button",onClick:()=>t(e==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:a(e==="chat"?"cliView.switchToTerminal":"cliView.switchToChat"),children:e==="chat"?s.jsx(Uc,{size:o}):s.jsx(Ks,{size:o})})}function k1(e){if(!e||e.isGitRepo===!1||e.reason==="not_git_repo")return null;if(e.hasConflicts)return`${e.branch||"Git"} · conflicts${e.changedFiles>0?` ${e.changedFiles}`:""}`;const t=[e.branch||"Git"];return e.changedFiles>0&&t.push(`±${e.changedFiles}`),e.ahead>0&&t.push(`↑${e.ahead}`),e.behind>0&&t.push(`↓${e.behind}`),t.length===1&&e.dirty&&t.push("dirty"),t.join(" ")}function S1(e){return!e||e.isGitRepo===!1||e.reason==="not_git_repo"?null:e.hasConflicts?"conflict":e.error?"error":e.dirty||e.changedFiles>0||e.ahead>0||e.behind>0?"dirty":"quiet"}function C1(e){switch(e){case"conflict":return"border-status-error/40 bg-status-error/10 text-status-error";case"error":return"border-yellow-500/25 bg-yellow-500/[0.08] text-yellow-500";case"dirty":return"border-orange-500/25 bg-orange-500/[0.08] text-orange-400";case"quiet":default:return"border-status-online/40 bg-status-online/10 text-status-online"}}function Pr({git:e,className:t="",compact:n=!1}){const a=k1(e),o=S1(e);if(!a||!o)return null;const r=[e!=null&&e.branch?`Branch: ${e.branch}`:null,e!=null&&e.changedFiles?`Changed files: ${e.changedFiles}`:null,e!=null&&e.ahead?`Ahead: ${e.ahead}`:null,e!=null&&e.behind?`Behind: ${e.behind}`:null,e!=null&&e.hasConflicts?"Conflicts detected":null,e!=null&&e.error?`Git error: ${e.error}`:null].filter(Boolean);return s.jsxs("span",{className:`inline-flex min-w-0 max-w-[12rem] items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold leading-none ${C1(o)} ${t}`.trim(),title:r.join(" · ")||a,"data-git-tone":o,children:[s.jsx("span",{"aria-hidden":"true",children:"⑂"}),s.jsx("span",{className:"truncate",children:a})]})}function j1({wsStatus:e,isConnected:t,daemonCount:n,p2pStates:a={},usesP2P:o=!0}){if(e!=="connected")return{tone:"disconnected",titleKey:"connection.disconnected",subtitleKey:null};if(n>0&&!o)return t?{tone:"connected",titleKey:"connection.connected",subtitleKey:null}:{tone:"limited",titleKey:"connection.connectedToDashboard",subtitleKey:null};const i=Object.values(a).filter(c=>c==="connected").length;return n>0?i>=n?{tone:"connected",titleKey:"connection.connected",subtitleKey:null}:{tone:"limited",titleKey:"connection.connectedToDashboard",subtitleKey:"connection.machinesConnectedCount",subtitleParams:{connected:i,total:n}}:t?{tone:"connected",titleKey:"connection.connected",subtitleKey:null}:{tone:"limited",titleKey:"connection.connectedToDashboard",subtitleKey:null}}function ap({value:e}){return e?s.jsx("span",{className:"dashboard-header-shortcut-pill",children:e}):null}function op({notification:e,shortcutIndex:t,onOpen:n,onMarkRead:a,onMarkUnread:o,onDelete:r}){const{t:i}=ye(),c=ni(e.updatedAt),d=!e.readAt;return s.jsxs("div",{className:`dashboard-header-inbox-item ${d?"is-attention":""}`.trim(),children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:n,children:[s.jsx("span",{className:"dashboard-header-inbox-item-title",children:e.title}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[t?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",t]}):null,[e.type==="needs_attention"?i("notification.actionNeeded"):i("notification.taskComplete"),c].filter(Boolean).join(" · ")]}),e.preview?s.jsx("span",{className:"dashboard-header-inbox-item-meta dashboard-header-inbox-item-preview",children:e.preview}):null]}),s.jsxs("div",{className:"ml-3 flex shrink-0 items-center gap-1.5",children:[d?s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:u=>{u.stopPropagation(),a()},children:i("notification.markRead")}):s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:u=>{u.stopPropagation(),o()},children:i("notification.markUnread")}),s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:u=>{u.stopPropagation(),r()},children:i("notification.delete")})]})]})}function N1({activeConv:e,wsStatus:t,isConnected:n,conversations:a,onOpenHistory:o,onOpenRemote:r,onStopCli:i,activeCliViewMode:c,onSetCliViewMode:d,onHideConversation:u,hiddenConversations:p=[],onShowConversation:m,onShowAllHidden:h,onResetPanelsToMain:f,inboxOpen:x,onInboxOpenChange:b,hiddenOpen:g,onHiddenOpenChange:S,onOpenNewSession:j,onOpenDashboardGuide:y,guideNudgeVisible:k=!1,actionShortcuts:v,notifications:C,notificationUnreadCount:w,onOpenNotification:N,onMarkNotificationRead:T,onMarkNotificationUnread:A,onDeleteNotification:P,onOpenGitDialog:D,onOpenMeshGraph:L}){var ue;const{t:I}=ye(),{ides:R,p2pStates:_={},usesP2P:M=!0}=Gs(),$=!!e&&vt(e)&&!gt(e),V=!!e&>(e),z=!!(e!=null&&e.daemonId)&&!!((ue=e==null?void 0:e.coordinator)!=null&&ue.meshId),W=c||(e?sf(e)?"terminal":"chat":null),[F,B]=l.useState(!1),[E,H]=l.useState(!1),J=l.useRef(null),q=l.useRef(null),ie=l.useRef(null),xe=R.filter(pe=>pe.type==="adhdev-daemon"),Y=j1({wsStatus:t,isConnected:n,daemonCount:xe.length,p2pStates:_,usesP2P:M}),ne=I(Y.titleKey),me=Y.subtitleKey?I(Y.subtitleKey,Y.subtitleParams):null,ce=Y.tone==="connected"?"#22c55e":Y.tone==="limited"?"#eab308":"#ef4444",ae=Y.tone==="connected"?"0 0 4px #22c55e80":Y.tone==="limited"?"0 0 4px #eab30880":"0 0 4px #ef444480",he=l.useMemo(()=>C.filter(pe=>!pe.readAt),[C]),oe=l.useMemo(()=>C.filter(pe=>!!pe.readAt),[C]),re=l.useMemo(()=>he.slice(0,9),[he]),ee=w;l.useEffect(()=>{if(!x)return;const pe=Ae=>{var Me;(Me=q.current)!=null&&Me.contains(Ae.target)||b(!1)};return document.addEventListener("mousedown",pe),()=>document.removeEventListener("mousedown",pe)},[x,b]),l.useEffect(()=>{if(!g)return;const pe=Ae=>{var Me;(Me=ie.current)!=null&&Me.contains(Ae.target)||S(!1)};return document.addEventListener("mousedown",pe),()=>document.removeEventListener("mousedown",pe)},[g,S]),l.useEffect(()=>{if(!g&&!x)return;const pe=Ae=>{if(!Ae.altKey)return;const Me=Ae.code.match(/^Digit([1-9])$/);if(!Me)return;const He=Number(Me[1])-1,je=g?p[He]:void 0,Z=x?re[He]:void 0;if(!(!je&&!Z)){if(Ae.preventDefault(),Ae.stopPropagation(),je){m==null||m(je),S(!1);return}Z&&(N(Z),b(!1))}};return window.addEventListener("keydown",pe,!0),()=>window.removeEventListener("keydown",pe,!0)},[p,g,x,re,S,b,N,m]),l.useEffect(()=>{const pe=p.length;if(J.current===null){J.current=pe;return}pe>J.current&&H(!0),J.current=pe},[p.length]);const G=()=>H(!1),Q=pe=>{if(!pe)return;const Ae=a.find(Me=>Me.tabKey===pe);Ae&&(u==null||u(Ae))};return s.jsxs("div",{className:"dashboard-header",children:[s.jsx("div",{className:"flex items-center gap-3",children:s.jsx("div",{className:"header-title-block",children:s.jsxs("div",{className:"header-title-row",children:[s.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[s.jsx(Ks,{size:18}),s.jsx("span",{className:"header-title-desktop",children:I("dashboard.header.title")}),s.jsx("span",{className:"header-title-mobile",children:e?At(e):I("dashboard.header.title")}),s.jsx("span",{title:ne,"aria-label":ne,className:"header-title-status-dot",style:{background:ce,boxShadow:ae}}),s.jsx("span",{className:"header-count-mobile text-3xs font-semibold opacity-60 ml-2 tracking-wide",children:s.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:ce,boxShadow:ae}})})]}),s.jsxs("div",{className:"header-subtitle flex items-center",children:[me&&s.jsxs("span",{className:"header-subtitle-status mr-2",children:["· ",me]}),j&&s.jsx("button",{type:"button",onClick:j,className:"btn btn-secondary btn-sm ml-2",title:`${I("paneGroup.newSession")}${v!=null&&v.openNewSession?` (${v.openNewSession})`:""}`,"aria-label":I("paneGroup.newSession"),children:s.jsx(co,{size:14})})]})]})})}),s.jsxs("div",{className:"flex gap-2 items-center",children:[y&&s.jsxs("button",{type:"button",onClick:y,className:"btn btn-secondary btn-sm hidden md:inline-flex items-center gap-1.5 dashboard-header-guide-button",title:I("dashboard.header.guide"),"aria-label":I("dashboard.header.guideOpen"),children:[s.jsx("span",{className:"font-semibold leading-none",children:"?"}),k&&s.jsx("span",{children:I("dashboard.header.guideShort")})]}),e&&($||V||!gt(e))&&s.jsxs("div",{className:"dashboard-header-actions-group",children:[s.jsx("span",{className:"dashboard-header-action-target",title:wa(e)||At(e),children:At(e)}),D&&e.git&&e.daemonId&&e.workspacePath?s.jsx("button",{type:"button",className:"appearance-none bg-transparent border-0 p-0 cursor-pointer",title:I("dashboard.header.openGitStatus"),onClick:()=>D(e.daemonId,e.workspacePath),children:s.jsx(Pr,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"})}):s.jsx(Pr,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"}),z&&L&&s.jsxs("button",{type:"button",onClick:()=>L(e),className:"btn btn-secondary btn-sm dashboard-header-mesh-button",title:I("dashboard.header.openMeshGraph"),children:[s.jsx(js,{size:14}),s.jsx("span",{className:"hidden lg:inline",children:I("dashboard.header.meshGraph")})]}),($||V)&&i&&s.jsxs(s.Fragment,{children:[$&&d&&W&&s.jsx(Ef,{mode:W,onChange:d,compact:!0}),s.jsx("button",{onClick:()=>i(e),className:"btn btn-secondary btn-sm",title:I(V?"dashboard.header.stopAcpSession":"dashboard.header.stopCliProcess"),style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(Wt,{size:14})})]}),!gt(e)&&s.jsx("button",{onClick:()=>o(e),className:"btn btn-secondary btn-sm",title:I("dashboard.header.chatHistory"),children:s.jsx(Wc,{size:14})}),!$&&!gt(e)&&s.jsx("button",{onClick:r,className:"btn btn-secondary btn-sm",title:I("dashboard.header.remoteControl"),children:s.jsx(Es,{size:14})})]}),s.jsxs("div",{className:"dashboard-header-inbox",ref:q,children:[s.jsxs("div",{className:`dashboard-header-hidden${F?" is-drop-target":""}${E?" hidden-spawn-flash":""}${(p??[]).some(qn)?" hidden-generating-spin":""}`,onAnimationEnd:G,ref:ie,onDragEnter:pe=>{pe.dataTransfer.types.includes("text/tab-key")&&(pe.preventDefault(),B(!0))},onDragOver:pe=>{pe.dataTransfer.types.includes("text/tab-key")&&(pe.preventDefault(),pe.dataTransfer.dropEffect="move",B(!0))},onDragLeave:pe=>{pe.currentTarget.contains(pe.relatedTarget)||B(!1)},onDrop:pe=>{const Ae=pe.dataTransfer.getData("text/tab-key");pe.preventDefault(),B(!1),Q(Ae)},children:[s.jsxs("button",{type:"button",onClick:()=>S(!g),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:`${I("dashboard.hidden.title")}${v!=null&&v.toggleHiddenTabs?` (${v.toggleHiddenTabs})`:""}. ${I("dashboard.hidden.dragHint")}`,children:[s.jsx(Xr,{size:16}),p.length>0&&s.jsx("span",{className:`dashboard-header-hidden-badge${E?" hidden-badge-pop":""}`,children:p.length})]}),g&&s.jsxs("div",{className:"dashboard-header-hidden-popover",children:[s.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:I("dashboard.hidden.title")}),s.jsx(ap,{value:v==null?void 0:v.toggleHiddenTabs})]}),s.jsxs("div",{className:"dashboard-header-hidden-actions",children:[f&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:f,children:I("dashboard.hidden.resetPanels")}),p.length>0&&h&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{h(),S(!1)},children:I("dashboard.hidden.restoreAll")})]})]}),e&&u&&s.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>u(e),children:[s.jsxs("span",{className:"dashboard-header-hidden-current-leading",children:[s.jsx("span",{className:"dashboard-header-hidden-current-label",children:I("dashboard.hidden.hideCurrentTab")}),s.jsx(ap,{value:v==null?void 0:v.hideCurrentTab})]}),s.jsx("span",{className:"dashboard-header-hidden-current-title",children:At(e)})]}),p.length>0?s.jsx("div",{className:"dashboard-header-hidden-list",children:p.map(pe=>s.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{m==null||m(pe),S(!1)},children:[s.jsxs("span",{className:"dashboard-header-inbox-item-title",children:[qn(pe)&&s.jsx(Cs,{size:12,thickness:2,color:"success",label:I("dashboard.header.generating")}),At(pe)]}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[p.indexOf(pe)<9?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",p.indexOf(pe)+1]}):null,wa(pe)]})]},pe.tabKey))}):s.jsx("div",{className:"dashboard-header-inbox-empty",children:I("dashboard.hidden.empty")})]})]}),s.jsxs("button",{type:"button",onClick:()=>b(!x),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:I("dashboard.header.activityInbox"),children:[s.jsx(vn,{size:16}),ee>0&&s.jsx("span",{className:"dashboard-header-inbox-badge",children:ee})]}),x&&s.jsxs("div",{className:"dashboard-header-inbox-popover",children:[he.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:I("dashboard.inbox.unread")}),he.map(pe=>s.jsx(op,{notification:pe,shortcutIndex:re.indexOf(pe)>=0?re.indexOf(pe)+1:void 0,onOpen:()=>N(pe),onMarkRead:()=>T(pe.id),onMarkUnread:()=>A(pe.id),onDelete:()=>P(pe.id)},pe.id))]}),oe.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:I("dashboard.inbox.read")}),oe.map(pe=>s.jsx(op,{notification:pe,onOpen:()=>N(pe),onMarkRead:()=>T(pe.id),onMarkUnread:()=>A(pe.id),onDelete:()=>P(pe.id)},pe.id))]}),C.length===0&&s.jsx("div",{className:"dashboard-header-inbox-empty",children:I("dashboard.inbox.empty")})]})]})]})]})}function as(e={}){return{textQuery:e.textQuery||"",workspaceQuery:e.workspaceQuery||"",modelQuery:e.modelQuery||"",resumableOnly:!!e.resumableOnly,sortMode:e.sortMode||"recent"}}function A1(e,t){return String(e||"")!==String(t||"")}function T1(e,t={}){const n=String(t.textQuery||"").trim().toLowerCase(),a=String(t.workspaceQuery||"").trim().toLowerCase(),o=String(t.modelQuery||"").trim().toLowerCase(),r=!!t.resumableOnly;return!n&&!a&&!o&&!r?e:e.filter(i=>!(r&&!i.canResume||n&&![i.title,i.preview].map(d=>String(d||"").toLowerCase()).join(`
|
|
50
50
|
`).includes(n)||a&&!String(i.workspace||"").toLowerCase().includes(a)||o&&!Rh(i.summaryMetadata).map(d=>d.toLowerCase()).join(`
|
|
51
51
|
`).includes(o)))}function I1(e,t="recent"){const n=e.slice();return n.sort((a,o)=>{if(t==="oldest")return(Number(a.lastMessageAt)||0)-(Number(o.lastMessageAt)||0);if(t==="messages"){const r=(Number(o.messageCount)||0)-(Number(a.messageCount)||0);if(r!==0)return r}return(Number(o.lastMessageAt)||0)-(Number(a.lastMessageAt)||0)}),n}function Hf(e,t={}){return I1(T1(e,t),t.sortMode||"recent")}function lc(e,t){return typeof e=="function"?e(t??!1?"launch.resumeSavedHistory":"launch.startFresh"):e?"Resume saved history":"Start fresh"}function Ff(e,t){return typeof e=="function"?e(t??!1?"launch.resumingSavedHistory":"launch.startingFresh"):e?"Resuming saved history…":"Starting fresh…"}function P1(e){return e?e("launch.startFresh"):"Start fresh"}function L1(e){return e?e("launch.hostedRuntimeRecoveryDescription"):"Fallback recovery for hosted runtimes after interruptions. For normal continuity, open saved history instead."}function D1(e){return e?e("launch.openSavedHistory"):"Open saved history"}function rp(e){return e?e("launch.savedHistoryTitle"):"Saved History"}function ld(e){return e?e("launch.savedHistoryHelper"):"Use saved history when you want continuity in the same provider conversation."}function M1(e){return e?e("launch.savedHistoryEmpty"):"No saved history found yet."}function R1(e){return e?e("launch.refreshSavedHistory"):"Refresh saved history"}function _1(e){return e?e("launch.refreshingSavedHistory"):"Refreshing saved history…"}function Lr(e,t,n){if(typeof e=="function"){const r=t,i=n;return r==="start-fresh"?e("launch.startFreshWith",{label:i}):e("launch.restart",{label:i})}const a=e,o=t;return a==="start-fresh"?`Start fresh with ${o}?`:`Restart ${o}?`}function Dr(e,t){if(typeof e=="function"){const a=t;return e(a==="start-fresh"?"launch.startFreshReview":a==="restart-ide"?"launch.restartIdeReview":"launch.restartStoppedReview")}const n=e;return n==="start-fresh"?"Review the provider and target folder before starting fresh.":n==="restart-ide"?"Review or change the target workspace before restarting this IDE.":"Review or change the target workspace before restarting this stopped session."}function Mr(e,t){return typeof e=="function"?e(t==="start-fresh"?"launch.confirmStartFresh":"launch.confirmRestart"):e==="start-fresh"?"Start fresh":"Restart"}function Rr(e,t){return typeof e=="function"?e(t==="start-fresh"?"launch.confirmStartingFresh":"launch.confirmRestarting"):e==="start-fresh"?"Starting fresh…":"Restarting…"}function $f(e,t){return typeof e=="function"?e("launch.resumeWith",{label:t}):`Resume saved history with ${e}?`}function Bf(e){return e?e("launch.resumeReview"):"Review or change the target workspace before resuming saved history."}function ip(e){if(!e)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(e))}catch{return new Date(e).toLocaleString()}}function Wf({activeConv:e,ides:t,isCreatingChat:n,isRefreshingHistory:a,savedSessions:o=[],isSavedSessionsLoading:r=!1,isResumingSavedSessionId:i=null,savedHistoryFilters:c,missingWorkspaceResumePath:d,onSavedHistoryFiltersChange:u,onClose:p,onNewChat:m,onSwitchSession:h,onRefreshHistory:f,onResumeSavedSession:x}){var L;const{t:b}=ye("common"),g=t.find(I=>I.id===e.routeId),S=(g==null?void 0:g.chats)||[],j=(L=g==null?void 0:g.activeChat)==null?void 0:L.id,y=vt(e)&&!gt(e),[k,v]=l.useState(()=>as()),[C,w]=l.useState(null),N=c||k,T=String(d||"").trim(),A=I=>{if(u){u(I);return}v(I)},P=l.useMemo(()=>o.map(I=>{const R=String(I.workspace||"").trim();return I.canResume||R||!T?I:{...I,workspace:T,canResume:!0,workspaceFallbackSource:"selected-workspace"}}),[T,o]),D=l.useMemo(()=>Hf(P,{textQuery:N.textQuery,workspaceQuery:N.workspaceQuery,modelQuery:N.modelQuery,resumableOnly:N.resumableOnly,sortMode:N.sortMode}),[P,N.modelQuery,N.resumableOnly,N.sortMode,N.textQuery,N.workspaceQuery]);return s.jsxs(s.Fragment,{children:[s.jsxs(va,{chrome:!1,onClose:p,closeOnEsc:!C,ariaLabel:y?rp(b):b("historyModal.chatHistory"),overlayClassName:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4 bg-black/60 backdrop-blur-sm",surfaceClassName:"card fade-in relative w-full sm:w-[90%] max-w-[500px] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[24px] sm:rounded-[20px]",children:[s.jsxs("div",{className:"px-4 py-4 sm:px-6 sm:py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)] shrink-0",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"m-0 text-lg font-extrabold",children:y?rp(b):b("historyModal.chatHistory")}),s.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:ZA(e)}),y&&s.jsx("div",{className:"text-2xs text-text-muted mt-1",children:ld(b)})]}),s.jsx("button",{onClick:p,className:"btn btn-secondary btn-sm rounded-md px-1.5 py-1.5 border-transparent bg-transparent hover:bg-bg-secondary",children:s.jsx(Wt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto p-3 bg-bg-primary",children:[!y&&s.jsx("button",{onClick:m,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:b(n?"historyModal.creating":"historyModal.startNewChat")}),y?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-[var(--surface-secondary)] p-3 mb-3",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-2",children:[s.jsx("input",{type:"text",value:N.textQuery,onChange:I=>A({...N,textQuery:I.target.value}),placeholder:b("historyModal.searchPlaceholder"),className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("input",{type:"text",value:N.workspaceQuery,onChange:I=>A({...N,workspaceQuery:I.target.value}),placeholder:b("historyModal.filterWorkspace"),className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("input",{type:"text",value:N.modelQuery,onChange:I=>A({...N,modelQuery:I.target.value}),placeholder:b("historyModal.filterModel"),className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsxs("select",{value:N.sortMode,onChange:I=>A({...N,sortMode:I.target.value}),className:"w-full rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary",children:[s.jsx("option",{value:"recent",children:b("historyModal.sortRecent")}),s.jsx("option",{value:"oldest",children:b("historyModal.sortOldest")}),s.jsx("option",{value:"messages",children:b("historyModal.sortMessages")})]})]}),s.jsxs("label",{className:"mt-2 flex items-center gap-2 text-2xs text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:N.resumableOnly,onChange:I=>A({...N,resumableOnly:I.target.checked})}),b("historyModal.resumeReadyOnly")]})]}),D.map(I=>{const R=e.providerSessionId===I.providerSessionId,_=R||!I.canResume||!!i,M=I.workspaceFallbackSource==="selected-workspace";return s.jsxs("button",{type:"button",onClick:()=>{_||!x||w({kind:"saved",session:I})},disabled:_,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${R?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${_?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:`font-bold text-sm mb-1 truncate ${R?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:I.title||b("historyModal.untitledSession")}),s.jsx("div",{className:"text-2xs text-text-muted font-mono truncate",children:I.providerSessionId})]}),s.jsx("div",{className:"text-2xs text-text-muted shrink-0",children:ip(I.lastMessageAt)})]}),s.jsx("div",{className:"mt-2 text-xs text-text-muted line-clamp-2",children:I.preview||b("historyModal.noSavedPreview")}),s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-2xs text-text-muted",children:[s.jsxs("div",{className:"truncate",children:[I.workspace||b("historyModal.workspaceUnknown"),M?b("historyModal.selectedWorkspaceSuffix"):"",zn(I.summaryMetadata)?` · ${zn(I.summaryMetadata)}`:"",I.messageCount>0?` · ${b("historyModal.msgCount",{count:I.messageCount})}`:""]}),s.jsx("div",{className:"shrink-0",children:R?b("historyModal.statusActive"):I.canResume?M?b("historyModal.statusResumeSelectedWorkspace"):i===I.providerSessionId?b("historyModal.statusResuming"):b("historyModal.statusResume"):b("historyModal.statusMissingWorkspace")})]})]},I.id)})]}):S.map(I=>s.jsxs("div",{onClick:()=>{I.id!==j&&w({kind:"chat",id:I.id,title:I.title||b("historyModal.untitledSession")})},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${j===I.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[s.jsx("div",{className:`font-bold text-sm mb-1 ${j===I.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:I.title||b("historyModal.untitledSession")}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"text-2xs text-text-muted font-mono",children:[I.id.substring(0,12),"..."]}),j===I.id&&s.jsx("span",{className:"text-3xs bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:b("historyModal.statusActive")})]})]},I.id)),(y&&!r&&D.length===0||!y&&S.length===0)&&s.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[s.jsx("div",{className:"text-3xl mb-3 opacity-60",children:s.jsx(iv,{size:32})}),s.jsx("div",{className:"text-xxs",children:y?o.length>0?b("historyModal.noMatchingHistory"):M1(b):b("historyModal.noRecentChats")})]}),y&&r&&s.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:s.jsx("div",{className:"text-xxs",children:_1(b)})})]}),s.jsx("div",{className:"px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right shrink-0",children:s.jsx("button",{onClick:f,disabled:a||r,className:"btn btn-secondary btn-sm rounded-[10px]",children:a||r?b("historyModal.refreshing"):s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(xn,{size:13})," ",y?R1(b):b("historyModal.refreshHistory")]})})})]}),C&&s.jsxs(va,{chrome:!1,onClose:()=>w(null),overlayClassName:"fixed inset-0 z-[var(--z-modal)] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",surfaceClassName:"card fade-in relative w-full sm:w-[min(92vw,420px)] max-w-[420px] flex flex-col overflow-hidden rounded-[24px] sm:rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-bg-primary",children:[s.jsx("h3",{className:"m-0 text-base md:text-lg font-extrabold",children:b("historyModal.confirmSwitchTitle")}),s.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:b("historyModal.confirmSwitchDescription",{target:C.kind==="chat"?C.title:C.session.title||b("historyModal.untitledSession")})}),C.kind==="saved"&&s.jsxs("div",{className:"mt-2 text-2xs text-text-muted font-mono truncate",children:[C.session.workspace||b("historyModal.workspaceUnknown"),C.session.lastMessageAt?` · ${ip(C.session.lastMessageAt)}`:""]})]}),s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s.jsx("button",{onClick:()=>{const I=C;w(null),I.kind==="chat"?(h(e.routeId,I.id),p()):x&&x(I.session)},className:"btn btn-primary w-full justify-center min-h-[42px]",children:b("historyModal.confirmSwitchAction")}),s.jsx("button",{onClick:()=>w(null),className:"btn btn-secondary w-full justify-center min-h-[42px]",children:b("common.cancel")})]})]})]})}const lp={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",labelKey:"toast.label.success"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",labelKey:"toast.label.warning"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",labelKey:"toast.label.info"}};function Of({toasts:e,onDismiss:t,onClickToast:n}){const{t:a}=ye();return s.jsx("div",{className:"fixed right-4 top-[calc(env(safe-area-inset-top,0px)+64px)] z-[var(--z-toast)] flex flex-col gap-2 pointer-events-none sm:top-[calc(env(safe-area-inset-top,0px)+16px)]",children:e.map(o=>{const r=lp[o.type]||lp.info;return s.jsxs("div",{className:"fade-in pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[380px] relative group overflow-hidden rounded-[16px] border shadow-[0_18px_40px_rgba(2,6,23,0.24)] backdrop-blur-xl",style:{background:"color-mix(in srgb, var(--surface-primary) 94%, var(--bg-secondary) 6%)",borderColor:"color-mix(in srgb, var(--border-default) 88%, transparent)",color:"var(--text-primary)"},onClick:()=>{var i;(i=o.actions)!=null&&i.length||n&&n(o)},children:[s.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${r.accent}, color-mix(in srgb, ${r.accent} 55%, transparent))`}}),s.jsx("button",{className:"absolute top-2 right-2 w-7 h-7 rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-glass transition-colors leading-none cursor-pointer",onClick:i=>{i.stopPropagation(),t(o.id)},"aria-label":a("toast.dismiss"),children:s.jsx(Wt,{size:14})}),s.jsxs("div",{className:"px-4 py-3.5 pl-5",children:[s.jsx("div",{className:"flex items-center gap-2 pr-8",children:s.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-3xs font-bold uppercase tracking-[0.08em]",style:{background:r.chipBg,color:r.chipText,border:`1px solid color-mix(in srgb, ${r.accent} 22%, transparent)`},children:a(r.labelKey)})}),s.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:o.message}),o.actions&&o.actions.length>0&&s.jsx("div",{className:"flex gap-2 mt-3",children:o.actions.map((i,c)=>s.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${i.variant==="primary"||i.variant==="danger",""}`,style:i.variant==="primary"?{background:"color-mix(in srgb, var(--accent-primary) 12%, var(--surface-primary))",color:"var(--text-primary)",borderColor:"color-mix(in srgb, var(--accent-primary) 26%, transparent)"}:i.variant==="danger"?{background:"color-mix(in srgb, var(--status-error) 10%, var(--surface-primary))",color:"var(--status-error)",borderColor:"color-mix(in srgb, var(--status-error) 22%, transparent)"}:{background:"var(--surface-secondary)",color:"var(--text-secondary)",borderColor:"var(--border-subtle)"},onClick:d=>{d.stopPropagation(),i.onClick(),t(o.id)},children:i.label},c))})]})]},o.id)})})}const E1=e=>e.transport==="pty"||e.transport==="acp"||e.transport==="cdp-page"?!0:e.daemonId!==e.id;function H1(e){const t=e.workspace||"";if(!t)return"";const n=t.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:t}function F1(e,t){return Uf(e)||t}function Uf(e){var o,r,i;const t=(r=(o=e.summaryMetadata)==null?void 0:o.items)==null?void 0:r.find(c=>(c==null?void 0:c.id)==="model"),n=((t==null?void 0:t.value)||(t==null?void 0:t.shortValue)||"").trim();if(n)return n;const a=(i=e.controlValues)==null?void 0:i.model;return typeof a=="string"&&a.trim()?a.trim():""}function $1(e){return Uf(e)||void 0}function B1(e){return e.sessionId||e.instanceId||e.agentType}function qf(e=[]){const t={};for(const n of e)n.type==="adhdev-daemon"&&(t[n.id]=Ns(n,{fallbackId:n.id}));return t}function zf(e,t={}){var a;const n=e.daemonId||((a=e.id)==null?void 0:a.split(":")[0])||e.id;return{machineName:XS(e,t.machineNames),connectionState:t.connectionStates?t.connectionStates[n]||t.defaultConnectionState||"new":t.defaultConnectionState}}function cd(e,t={}){return W1(e,zf(e,t))}function W1(e,t={}){var h,f,x,b,g,S,j,y,k;const n=[],a=t.machineName,o=t.connectionState,r=H1(e),i=e.workspace||"",c=aC(e.type,{agentName:e.cliName}),d=vt(e)||gt(e)?c:es(e.type),u=F1(e,d),p=Array.isArray(e.childSessions)?e.childSessions.map(v=>{var C,w,N;return{sessionId:v.id,instanceId:v.id,providerSessionId:v.providerSessionId,activeChatId:(C=v.activeChat)==null?void 0:C.id,transport:v.transport,sessionCapabilities:v.capabilities,agentType:v.providerType,agentName:v.providerName||es(v.providerType),model:$1(v),status:v.status,title:v.title,lastMessagePreview:v.lastMessagePreview,lastMessageRole:v.lastMessageRole,lastMessageAt:v.lastMessageAt,lastMessageHash:v.lastMessageHash,messages:((w=v.activeChat)==null?void 0:w.messages)||[],activeModal:((N=v.activeChat)==null?void 0:N.activeModal)||void 0,unread:v.unread,lastSeenAt:v.lastSeenAt,lastUpdated:v.lastUpdated,inboxBucket:v.inboxBucket,completionMarker:v.completionMarker,surfaceHidden:v.surfaceHidden,muted:v.muted,git:v.git,settings:v.settings,coordinator:v.coordinator,messageInput:v.messageInput}}):[],m=E1(e);if(m){const v=e.sessionId||e.instanceId,C=(h=e.settings)==null?void 0:h.meshCoordinatorFor,w=((f=e.settings)==null?void 0:f.meshNodeFor)||!((x=e.settings)!=null&&x.meshCoordinatorFor)&&((b=e.settings)==null?void 0:b.launchedByCoordinator),N=C?" (Coordinator)":w?" (Mesh Node)":"",T=c+N,A=(g=e.activeChat)==null?void 0:g.activeModal,P=A&&Array.isArray(A.buttons)&&A.buttons.length>0,D=oC(e.activeChat,[{status:e.status,activeModal:(S=e.activeChat)==null?void 0:S.activeModal}],e.agents||[]),L=e.activeChat||{title:"",messages:[]};let I=L.title&&String(L.title).trim()?String(L.title).trim():"";const R=(j=e.activeChat)==null?void 0:j.id,_=e.chats;if(R&&Array.isArray(_)&&_.length>0){const E=_.find(H=>H.id===R||H.id&&String(H.id)===String(R));E!=null&&E.title&&String(E.title).trim()&&(I=String(E.title).trim())}const M=(vt(e)||gt(e),e.type),$=(vt(e)||gt(e))&&gu(I,T,M)?"":I,V=L.messages||[],z=typeof R=="string"?R.trim():"",W=(vt(e)||gt(e))&&z===String(e.type||"").trim(),F=z&&!W?z:e.providerSessionId,B=e.coordinator||(typeof((y=e.settings)==null?void 0:y.meshCoordinatorFor)=="string"&&e.settings.meshCoordinatorFor?{meshId:e.settings.meshCoordinatorFor,role:"coordinator"}:void 0);n.push({routeId:e.id,sessionId:v,providerSessionId:e.providerSessionId,historySessionId:F,nativeSessionId:v,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:vt(e)&&e.mode||"chat",agentName:T,agentType:M,status:D,title:$,messages:V,resume:e.resume,hostIdeType:!vt(e)&&!gt(e)?e.type:void 0,workspaceName:r,workspacePath:i,git:e.git,displayPrimary:r||$||(vt(e)?e.mode==="chat"?T:`Terminal${N}`:T),displaySecondary:u,cdpConnected:e.cdpConnected,lastMessagePreview:e.lastMessagePreview,lastMessageRole:e.lastMessageRole,lastMessageAt:e.lastMessageAt,lastMessageHash:e.lastMessageHash,lastUpdated:e.lastUpdated,inboxBucket:e.inboxBucket,completionMarker:e.completionMarker,modalButtons:P?A.buttons:void 0,modalMessage:P?A.message:void 0,streamSource:"native",tabKey:Bi(v,e.id),machineName:a,connectionState:o,settings:e.settings,coordinator:B,messageInput:e.messageInput})}if(m&&(vt(e)||gt(e)))return n;for(const v of p){const C=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,w=rC(v),N=B1(v),T=`${e.id}:${N}`,A=v.title&&String(v.title).trim()||"",P=gu(A,v.agentName,v.agentType)?"":A,D=v.messages||[];if(!(v.transport==="cdp-webview"||!!v.sessionId||!!v.providerSessionId||D.length>0||C||!!P||!["idle","panel_hidden","disconnected","not_monitored"].includes(w)))continue;const I=v.coordinator||(typeof((k=v.settings)==null?void 0:k.meshCoordinatorFor)=="string"&&v.settings.meshCoordinatorFor?{meshId:v.settings.meshCoordinatorFor,role:"coordinator"}:void 0);n.push({routeId:e.id,sessionId:v.sessionId||v.instanceId,providerSessionId:v.providerSessionId,historySessionId:v.activeChatId||v.providerSessionId,nativeSessionId:e.sessionId||e.instanceId,transport:v.transport||"cdp-webview",daemonId:e.daemonId||void 0,sessionCapabilities:v.sessionCapabilities,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:w,title:P,messages:D,hostIdeType:e.type,workspaceName:r,workspacePath:i,git:v.git||e.git,displayPrimary:r||P||v.agentName||d,displaySecondary:v.model&&v.model.trim()?v.model.trim():`${d} · ${v.agentName}`,cdpConnected:e.cdpConnected,lastMessagePreview:v.lastMessagePreview,lastMessageRole:v.lastMessageRole,lastMessageAt:v.lastMessageAt,lastMessageHash:v.lastMessageHash,lastUpdated:v.lastUpdated||e.lastUpdated,inboxBucket:v.inboxBucket,completionMarker:v.completionMarker,modalButtons:C?v.activeModal.buttons:void 0,modalMessage:C?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:Bi(v.sessionId||v.instanceId,T),machineName:a,connectionState:o,settings:v.settings,coordinator:I,messageInput:v.messageInput})}return n.length===0&&n.push({routeId:e.id,sessionId:e.sessionId||e.instanceId,providerSessionId:e.providerSessionId,nativeSessionId:e.sessionId||e.instanceId,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:"chat",agentName:c,agentType:"ide-native",status:"idle",title:"",messages:[],hostIdeType:e.type,workspaceName:r,workspacePath:i,git:e.git,displayPrimary:r||d,displaySecondary:u,cdpConnected:e.cdpConnected,lastUpdated:e.lastUpdated,streamSource:"native",tabKey:Bi(e.sessionId||e.instanceId,e.id),connectionState:o,settings:e.settings,messageInput:e.messageInput}),n}function Gf(e){return String(e.type||e.id||"").trim()}function _r(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!!t.trim()).map(t=>t.trim()):[]}function O1(e,t){const n=(t||"").trim();if(!n)return[];const a=(e||[]).find(o=>o.type===n);return _r(a==null?void 0:a.modelOptions)}function U1(e,t){const n=(t||"").trim();if(!n)return[];const a=(e||[]).find(o=>o.type===n);return _r(a==null?void 0:a.thinkingLevelOptions)}function Kf(e){const t=new Map;for(const n of e||[])n!=null&&n.type&&t.set(n.type,{models:_r(n.modelOptions),thinking:_r(n.thinkingLevelOptions)});return t}function q1(e){var t;return e.category!=="cli"||!Gf(e)||e.enabled===!1?!1:e.machineStatus?e.machineStatus==="detected":((t=e.lastDetection)==null?void 0:t.ok)===!0||e.installed===!0||!!e.detectedPath}function kn(e){var a;const t=new Set,n=[];for(const o of e||[]){if(!q1(o))continue;const r=Gf(o);if(!r||t.has(r))continue;t.add(r);const i=String(o.displayName||o.name||r),c=o.detectedPath||((a=o.lastDetection)==null?void 0:a.path)||null;n.push({type:r,label:i,icon:o.icon,statusLabel:c?`Detected at ${c}`:"Detected on this machine",detectedPath:c,...Array.isArray(o.modelOptions)&&o.modelOptions.length?{modelOptions:o.modelOptions}:{},...Array.isArray(o.thinkingLevelOptions)&&o.thinkingLevelOptions.length?{thinkingLevelOptions:o.thinkingLevelOptions}:{}})}return n}function jo(e){const t=Array.isArray(e)?e:typeof e=="string"?e.split(/[\s,]+/):[],n=new Set,a=[];for(const o of t){const r=typeof o=="string"?o.trim():"";!r||n.has(r)||(n.add(r),a.push(r))}return a}function Kn(e){return e.map(t=>t.type)}function z1(e,t){const n=jo(e),a=t.trim();return!a||n.includes(a)?n:[...n,a]}function G1(e,t){return jo(e).filter(n=>n!==t)}function cp(e,t,n){const a=jo(e),o=a.indexOf(t);if(o<0)return a;const r=a.filter(c=>c!==t);if(n==="top")return[t,...r];if(n==="bottom")return[...r,t];const i=n==="up"?Math.max(0,o-1):Math.min(r.length,o+1);return r.splice(i,0,t),r}const K1={"claude-cli":{monogram:"CL",hue:"#D97757"},"codex-cli":{monogram:"CX",hue:"#10A37F"},"gemini-cli":{monogram:"GM",hue:"#4285F4"},"kimi-cli":{monogram:"KM",hue:"#6366F1"},"antigravity-cli":{monogram:"AG",hue:"#8B5CF6"},"cursor-cli":{monogram:"CU",hue:"#64748B"},"opencode-cli":{monogram:"OC",hue:"#CA8A04"},"hermes-cli":{monogram:"HM",hue:"#14B8A6"},"grok-cli":{monogram:"GK",hue:"#475569"},antigravity:{monogram:"AG",hue:"#8B5CF6"},cursor:{monogram:"CU",hue:"#64748B"},kiro:{monogram:"KI",hue:"#F59E0B"},pearai:{monogram:"PA",hue:"#22C55E"},trae:{monogram:"TR",hue:"#EF4444"},vscode:{monogram:"VS",hue:"#3B82F6"},vscodium:{monogram:"VC",hue:"#2DD4BF"},windsurf:{monogram:"WS",hue:"#0EA5E9"},cline:{monogram:"CN",hue:"#0284C7"},"roo-code":{monogram:"RC",hue:"#F97316"}},dp=["#0EA5E9","#8B5CF6","#10B981","#F59E0B","#EF4444","#14B8A6","#6366F1","#EC4899","#84CC16","#F97316","#06B6D4","#A855F7"];function V1(e){let t=0;for(let n=0;n<e.length;n+=1)t=(t<<5)-t+e.charCodeAt(n)|0;return Math.abs(t)}function Y1(e){const t=e.replace(/[-_./]+/g," ").split(/\s+/).map(n=>n.trim()).filter(Boolean);return t.length===0?"?":t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function No({type:e,label:t,size:n=16,className:a}){const o=(e||"").trim().toLowerCase(),r=(t==null?void 0:t.trim())||o;if(!r)return s.jsx(gv,{size:n,className:a});const i=K1[o],c=(i==null?void 0:i.monogram)??Y1((t==null?void 0:t.trim())||o.replace(/-cli$/,"")),d=(i==null?void 0:i.hue)??dp[V1(o||r)%dp.length];return s.jsx("span",{"aria-hidden":!0,className:`inline-flex shrink-0 select-none items-center justify-center font-semibold ${a??""}`,style:{width:n,height:n,borderRadius:Math.max(4,Math.round(n*.3)),backgroundColor:`${d}21`,border:`1px solid ${d}4D`,color:d,fontSize:Math.max(7,Math.round(n*.42)),letterSpacing:"0.02em",lineHeight:1},children:c})}function up({direction:e}){return s.jsx("svg",{"aria-hidden":"true",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e==="up"?s.jsx("polyline",{points:"18 15 12 9 6 15"}):s.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Q1({value:e,availableProviders:t,onChange:n,disabled:a=!1,saveButton:o}){const{t:r}=ye("common"),[i,c]=l.useState(""),d=l.useMemo(()=>new Map(t.map(f=>[f.type,f])),[t]),u=l.useMemo(()=>jo(e),[e]),p=u.filter(f=>!d.has(f)).length,m=t.filter(f=>!u.includes(f.type)),h=()=>{i&&(n(z1(u,i)),c(""))};return s.jsxs("div",{className:"rounded-lg border border-border-subtle bg-bg-secondary/60 p-3",children:[s.jsx("div",{className:"flex flex-col gap-2",children:u.length===0?s.jsx("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-xs text-amber-300",children:"No provider priority configured. Launches without an explicit CLI provider will fail closed."}):u.map((f,x)=>{const b=d.get(f),g=!!b;return s.jsxs("div",{className:`flex flex-col gap-2 rounded-md border border-border-subtle px-3 py-2 sm:flex-row sm:items-center sm:justify-between ${g?"bg-bg-primary":"bg-bg-primary/40"}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("span",{className:"text-3xs font-semibold text-text-muted",children:["#",x+1]}),s.jsx(No,{type:f,label:b==null?void 0:b.label,size:14}),s.jsx("span",{className:`font-mono text-xs ${g?"text-text-primary":"text-text-muted"}`,children:f}),g?s.jsx("span",{className:"rounded border border-green-500/20 bg-green-500/10 px-1.5 py-px text-4xs font-semibold text-green-400",children:r("settings.providerPriority.available")}):s.jsx("span",{className:"rounded border border-amber-500/25 bg-amber-500/10 px-1.5 py-px text-4xs font-semibold text-amber-400",children:r("settings.providerPriority.notOnMachine")})]}),s.jsx("div",{className:"mt-1 text-3xs text-text-muted",children:b?`${b.label} · ${b.statusLabel}`:"Kept in order; skipped at launch until detected here."})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex h-8 w-8 items-center justify-center p-0","aria-label":"Move up",disabled:a||x===0,title:"Move up",onClick:()=>n(cp(u,f,"up")),children:s.jsx(up,{direction:"up"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex h-8 w-8 items-center justify-center p-0","aria-label":"Move down",disabled:a||x===u.length-1,title:"Move down",onClick:()=>n(cp(u,f,"down")),children:s.jsx(up,{direction:"down"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm text-red-400",disabled:a,onClick:()=>n(G1(u,f)),children:r("settings.providerPriority.remove")})]})]},f)})}),s.jsxs("div",{className:"mt-3 flex flex-col gap-2 sm:flex-row sm:items-end",children:[s.jsxs("label",{className:"flex-1 text-2xs text-text-secondary",children:[s.jsx("span",{className:"mb-1 block font-medium text-text-primary",children:r("settings.providerPriority.addCliLabel")}),s.jsxs("select",{className:"w-full rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2 text-sm text-text-primary",value:i,onChange:f=>c(f.target.value),disabled:a||m.length===0,children:[s.jsx("option",{value:"",children:m.length?"Select provider…":"No additional detected CLI providers"}),m.map(f=>s.jsxs("option",{value:f.type,children:[f.label," (",f.type,")"]},f.type))]})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:a||!i,onClick:h,children:r("settings.providerPriority.addProvider")}),o]}),s.jsxs("div",{className:"mt-2 text-2xs text-text-muted",children:["Launches use this order, top to bottom.",p>0?` ${p} provider${p===1?"":"s"} not detected here — kept in order, skipped until available.`:""]})]})}function J1(e){const t=e.split(":");return t.length>=3&&(t[1]==="ide"||t[1]==="cli"||t[1]==="acp")?{daemonId:t[0],targetSessionId:t.slice(2).join(":")||void 0}:{daemonId:e}}function Vf(e,t){const n=J1(e);return{daemonId:n.daemonId,payload:{...t,...n.targetSessionId&&!t.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const X1=[{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"trae",name:"Trae",icon:"🔮"},{id:"vscode",name:"VS Code",icon:"💙"},{id:"vscodium",name:"VSCodium",icon:"💚"},{id:"windsurf",name:"Windsurf",icon:"🏄"}],Z1=[{id:"antigravity-cli",name:"Antigravity CLI",icon:"🪐"},{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"grok-cli",name:"Grok",icon:"🛰️"},{id:"hermes-cli",name:"Hermes",icon:"⚕️"},{id:"kimi",name:"Kimi",icon:"🌙"},{id:"opencode",name:"OpenCode CLI",icon:"◆"}],eT=[{id:"cline",name:"Cline",icon:"🧠"},{id:"codex",name:"Codex",icon:"📦"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"claude-code-vscode",name:"Claude Code (VS Code)",icon:"🟠"}];function Yf({icon:e,title:t,subtitle:n,badge:a,actions:o,className:r}){return s.jsxs("div",{className:Ut("dashboard-header",r),children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"header-title flex items-center gap-2",children:[s.jsx("span",{className:"flex items-center text-lg",children:e})," ",t,a&&s.jsxs("span",{className:"text-3xs font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[a.count!==void 0?a.count:""," ",a.text]})]}),n&&s.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),o&&s.jsx("div",{className:"flex gap-2",children:o})]})}function Ao({icon:e,title:t,subtitle:n,badge:a,actions:o,widthClassName:r="max-w-6xl",contentClassName:i,children:c}){return s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(Yf,{icon:e,title:t,subtitle:n,badge:a,actions:o}),s.jsx("div",{className:"page-content",children:s.jsx("div",{className:Ut("mx-auto flex w-full flex-col gap-4",r,i),children:c})})]})}const cc="adhdev:themechange";function tT(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function la(){try{const e=localStorage.getItem("theme");if(e==="dark"||e==="light"||e==="system")return e}catch{}return"system"}function ca(e){return e==="system"?tT():e}function Qf(e){typeof document>"u"||(document.documentElement.setAttribute("data-theme",e),document.documentElement.style.colorScheme=e)}function pr(e,t){typeof window>"u"||window.dispatchEvent(new CustomEvent(cc,{detail:{preference:e,theme:t}}))}function sT(){const e=la(),t=ca(e);Qf(t),pr(e,t)}function nn(){const[e,t]=l.useState(la),[n,a]=l.useState(()=>ca(la()));l.useEffect(()=>{Qf(n)},[n]),l.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),c=d=>{if(e==="system"){const u=d.matches?"light":"dark";a(u),pr("system",u)}};return i.addEventListener("change",c),()=>i.removeEventListener("change",c)},[e]),l.useEffect(()=>{const i=d=>{const u=d.detail||{},p=u.preference,m=u.theme;t(p==="dark"||p==="light"||p==="system"?p:la()),a(m==="dark"||m==="light"?m:ca(la()))},c=d=>{if(d.key!=="theme")return;const u=la(),p=ca(u);t(u),a(p)};return window.addEventListener(cc,i),window.addEventListener("storage",c),()=>{window.removeEventListener(cc,i),window.removeEventListener("storage",c)}},[]);const o=l.useCallback(i=>{const c=ca(i);t(i),a(c);try{localStorage.setItem("theme",i)}catch{}pr(i,c)},[]),r=l.useCallback(()=>{t(i=>{const c=i==="dark"?"light":i==="light"?"system":"dark",d=ca(c);a(d);try{localStorage.setItem("theme",c)}catch{}return pr(c,d),c})},[]);return{theme:n,preference:e,setPreference:o,cycleTheme:r,isDark:n==="dark"}}const pp={dark:"Dark",light:"Light",system:"System"};function nT({collapsed:e}){const{preference:t,cycleTheme:n}=nn(),a=t==="dark"?s.jsx(sh,{size:16}):t==="light"?s.jsx(th,{size:16}):s.jsx(nh,{size:16});return s.jsxs("div",{className:`nav-item cursor-pointer ${e?"justify-center py-2.5 px-0":""}`,onClick:n,title:`Theme: ${pp[t]} (click to cycle)`,children:[s.jsx("span",{className:"nav-icon",children:a}),!e&&s.jsx("span",{className:"text-xs",children:pp[t]})]})}const dc="adhdev:langchange";function aT(){const e=Nt.language;return ua(e)?e:Ih()}function oT(e){typeof window>"u"||window.dispatchEvent(new CustomEvent(dc,{detail:{language:e}}))}function rT(){const[e,t]=l.useState(aT);l.useEffect(()=>{const a=i=>{ua(i)&&t(i)},o=i=>{const c=i.detail||{};ua(c.language)&&t(c.language)},r=i=>{if(i.key!==Ql)return;const c=i.newValue;ua(c)&&c!==Nt.language&&(Nt.changeLanguage(c),Jl(c))};return Nt.on("languageChanged",a),window.addEventListener(dc,o),window.addEventListener("storage",r),()=>{Nt.off("languageChanged",a),window.removeEventListener(dc,o),window.removeEventListener("storage",r)}},[]);const n=l.useCallback(a=>{if(ua(a)){t(a);try{localStorage.setItem(Ql,a)}catch{}Nt.changeLanguage(a),Jl(a),oT(a)}},[]);return{language:e,setLanguage:n}}function iT({trigger:e,viewport:t,menu:n,variant:a,gap:o=6,margin:r=8}){const i=e.top-r,c=t.height-e.bottom-r,d=a==="sidebar";let u=d;d&&i<n.height&&c>i&&(u=!1),!d&&c<n.height&&i>c&&(u=!0);const p=u?i:c,m=Math.max(80,Math.min(n.height,p));let h;u?h=e.top-o-m:h=e.bottom+o,h=mp(h,r,Math.max(r,t.height-m-r));const f=mp(e.left,r,Math.max(r,t.width-n.width-r));return{top:h,left:f,maxHeight:m}}function mp(e,t,n){return Math.min(Math.max(e,t),n)}function lT({open:e}){return s.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:`lang-switch-caret${e?" open":""}`,children:s.jsx("polyline",{points:"6 9 12 15 18 9"})})}function cT({collapsed:e,variant:t="sidebar"}){const{language:n,setLanguage:a}=rT(),{t:o}=ye("common"),[r,i]=l.useState(!1),[c,d]=l.useState(0),u=l.useRef(null),p=l.useRef(null),m=l.useRef(null),h=l.useId(),[f,x]=l.useState(null),b=l.useCallback(()=>{const D=p.current;if(!D)return;const L=D.getBoundingClientRect(),I=m.current,R=Math.max((I==null?void 0:I.offsetWidth)??0,168),_=(I==null?void 0:I.scrollHeight)??Nn.length*36+12;x(iT({trigger:{top:L.top,left:L.left,right:L.right,bottom:L.bottom,width:L.width,height:L.height},viewport:{width:window.innerWidth,height:window.innerHeight},menu:{width:R,height:_},variant:t}))},[t]),g=Math.max(0,Nn.findIndex(D=>D.code===n)),S=Nn[g]??Nn[0],j=o("language.label",{defaultValue:"Language"}),y=o("language.select",{defaultValue:"Select language"}),k=D=>`${h}-opt-${D}`,v=l.useCallback(()=>{d(g),i(!0)},[g]),C=l.useCallback((D=!0)=>{var L;i(!1),D&&((L=p.current)==null||L.focus())},[]),w=l.useCallback(D=>{const L=Nn[D];L&&a(L.code),C()},[a,C]);l.useEffect(()=>{if(!r)return;const D=R=>{var _,M;return!!((_=u.current)!=null&&_.contains(R)||(M=m.current)!=null&&M.contains(R))},L=R=>{D(R.target)||i(!1)},I=R=>{D(R.target)||i(!1)};return document.addEventListener("pointerdown",L,!0),document.addEventListener("focusin",I,!0),()=>{document.removeEventListener("pointerdown",L,!0),document.removeEventListener("focusin",I,!0)}},[r]),l.useLayoutEffect(()=>{if(!r){x(null);return}b();const D=()=>b();return window.addEventListener("resize",D),window.addEventListener("scroll",D,!0),()=>{window.removeEventListener("resize",D),window.removeEventListener("scroll",D,!0)}},[r,b]),l.useEffect(()=>{var D;r&&f&&((D=m.current)==null||D.focus())},[r,f]);const N=D=>{const L=Nn.length-1;switch(D.key){case"ArrowDown":D.preventDefault(),d(I=>I>=L?0:I+1);break;case"ArrowUp":D.preventDefault(),d(I=>I<=0?L:I-1);break;case"Home":D.preventDefault(),d(0);break;case"End":D.preventDefault(),d(L);break;case"Enter":case" ":D.preventDefault(),w(c);break;case"Escape":D.preventDefault(),C();break;case"Tab":i(!1);break}},T=D=>{r||(D.key==="ArrowDown"||D.key==="ArrowUp"||D.key==="Enter"||D.key===" ")&&(D.preventDefault(),v())},A=t==="landing"?"lang-switch-trigger lang-switch-trigger--landing":`lang-switch-trigger lang-switch-trigger--sidebar nav-item cursor-pointer${e?" justify-center py-2.5 px-0":""}`,P=t==="landing"||!e;return s.jsxs("div",{ref:u,className:"lang-switch",children:[s.jsxs("button",{ref:p,type:"button",className:A,"aria-haspopup":"listbox","aria-expanded":r,"aria-label":`${j}: ${S.label}`,title:`${j}: ${S.label}`,onClick:()=>r?C(!1):v(),onKeyDown:T,children:[s.jsx("span",{className:"nav-icon lang-switch-icon",children:s.jsx(oh,{size:16})}),P&&s.jsx("span",{className:"lang-switch-label text-xs",children:S.label}),P&&s.jsx(lT,{open:r})]}),r&&typeof document<"u"&&bn.createPortal(s.jsx("ul",{ref:m,role:"listbox",tabIndex:-1,"aria-label":y,"aria-activedescendant":k(c),className:`lang-switch-menu lang-switch-menu--${t}`,style:{position:"fixed",top:(f==null?void 0:f.top)??0,left:(f==null?void 0:f.left)??0,maxHeight:f==null?void 0:f.maxHeight,overflowY:"auto",visibility:f?"visible":"hidden"},onKeyDown:N,children:Nn.map((D,L)=>{const I=D.code===S.code,R=L===c;return s.jsxs("li",{id:k(L),role:"option","aria-selected":I,className:`lang-switch-option${R?" is-active":""}${I?" is-selected":""}`,onMouseEnter:()=>d(L),onClick:()=>w(L),children:[s.jsx("span",{className:"lang-switch-check","aria-hidden":"true",children:I?s.jsx(Ca,{size:14}):null}),s.jsx("span",{className:"lang-switch-option-label",children:D.label})]},D.code)})}),document.body)]})}const dT=[],uT=[];function Yi(e,t){return e?typeof e=="function"?e(t):e:null}const pT=l.memo(function({renderState:t,brand:n,navItems:a,sidebarSections:o,footerItems:r,footerInfo:i,footerActions:c,closeMobileMenu:d}){const{t:u}=ye("common"),{collapsed:p,mobileMenuOpen:m}=t,h=x=>`nav-item${x.active?" active":""} cursor-pointer ${p?"justify-center py-2.5 px-0":""}${x.className?` ${x.className}`:""}`,f=x=>s.jsxs("div",{className:h(x),id:`nav-${x.id}`,onClick:()=>{x.onSelect(),d()},title:p?x.title??(typeof x.label=="string"?x.label:void 0):x.title,children:[s.jsx("span",{className:"nav-icon",children:x.icon}),!p&&x.label]},x.id);return s.jsxs("aside",{className:`sidebar ${m?"sidebar-open":""}`,children:[s.jsxs("div",{className:"sidebar-header",children:[s.jsx("div",{className:`sidebar-logo ${p?"justify-center gap-0":""}`,children:Yi(n,t)}),s.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":u("app.closeMenu"),onClick:d,children:s.jsx(Wt,{size:16})})]}),s.jsx("nav",{className:"sidebar-nav",children:a.map(f)}),o.map(x=>s.jsxs("div",{className:x.className??"border-t border-border-subtle pt-2 mt-2",children:[!p&&x.title?s.jsx("div",{className:"px-3 py-1 text-3xs text-text-muted uppercase tracking-widest",children:x.title}):null,x.items.map(f)]},x.key)),s.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[r.map(f),Yi(i,t),s.jsx(nT,{collapsed:p}),s.jsx(cT,{collapsed:p}),Yi(c,t)]})]})});function mT({children:e,brand:t,navItems:n,sidebarSections:a=dT,footerItems:o=uT,footerInfo:r,footerActions:i,preMainContent:c,collapsedStorageKey:d="sidebar-collapsed"}){const{t:u}=ye("common"),[p,m]=l.useState(!1),[h,f]=l.useState(()=>{try{return localStorage.getItem(d)==="1"}catch{return!1}}),x=l.useCallback(()=>m(!0),[]),b=l.useCallback(()=>m(!1),[]),g=l.useCallback(()=>{f(j=>{const y=!j;try{localStorage.setItem(d,y?"1":"0")}catch{}return y})},[d]),S=l.useMemo(()=>({collapsed:h,mobileMenuOpen:p,openMobileMenu:x,closeMobileMenu:b,toggleCollapsed:g}),[h,p,x,b,g]);return s.jsxs("div",{className:`app-layout${p?" mobile-menu-open":""}${h?" sidebar-collapsed":""}`,children:[s.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":u("app.openMenu"),onClick:x,children:[s.jsx("span",{className:"mobile-menu-icon"}),s.jsx("span",{className:"mobile-menu-icon"}),s.jsx("span",{className:"mobile-menu-icon"})]}),p&&s.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":u("app.closeMenu"),onClick:b,onKeyDown:j=>j.key==="Escape"&&b()}),s.jsx(pT,{renderState:S,brand:t,navItems:n,sidebarSections:a,footerItems:o,footerInfo:r,footerActions:i,closeMobileMenu:b}),s.jsx("main",{className:"main-content relative",children:s.jsxs("div",{className:"main-content-inner",children:[c,e]})})]})}function yt({title:e,icon:t,description:n,accentColor:a,className:o,collapsible:r,defaultOpen:i=!0,badge:c,children:d}){const[u,p]=l.useState(i),m=r?u:!0,h=(e||n)&&s.jsxs("div",{className:Ut("flex items-start justify-between gap-3",m&&"mb-4"),children:[s.jsxs("div",{className:"min-w-0",children:[e&&s.jsxs("h3",{className:"text-base font-semibold text-text-primary flex items-center gap-1.5",children:[t&&s.jsx("span",{children:t}),s.jsx("span",{children:e}),c]}),n&&s.jsx("p",{className:"text-xxs text-text-muted mt-1",children:n})]}),r&&s.jsx("span",{className:Ut("mt-0.5 shrink-0 text-text-muted transition-transform select-none",m?"rotate-90":"rotate-0"),"aria-hidden":!0,children:"▸"})]});return s.jsxs("div",{className:Ut("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",a&&"border-l-[3px]",o),style:a?{borderLeftColor:a}:void 0,children:[r&&h?s.jsx("button",{type:"button",className:"w-full bg-transparent border-none p-0 text-left cursor-pointer",onClick:()=>p(f=>!f),"aria-expanded":m,children:h}):h,m&&d]})}function fi({icon:e,title:t,description:n,action:a,className:o}){return s.jsxs("div",{className:Ut("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),children:[s.jsx("div",{className:"text-5xl mb-4 opacity-50",children:e}),s.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:t}),s.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),a]})}const hT={error:"bg-red-500/10 border-red-500/30 text-red-400",warning:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400",success:"bg-green-500/10 border-green-500/30 text-green-400",info:"bg-indigo-500/10 border-indigo-500/30 text-indigo-400"},fT={error:ds,warning:ds,success:wo,info:Jr};function qt({variant:e,children:t,onDismiss:n,className:a}){return s.jsxs("div",{className:Ut("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-xxs",hT[e],a),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[(()=>{const o=fT[e];return s.jsx(o,{size:14})})(),s.jsx("span",{children:t})]}),n&&s.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}function $t({label:e,hint:t,children:n,className:a}){return s.jsxs("div",{className:Ut("mb-5",a),children:[s.jsx("label",{className:"block text-xs font-semibold text-text-muted uppercase tracking-wider mb-2",children:e}),n,t&&s.jsx("p",{className:"text-xs text-text-muted mt-1.5",children:t})]})}function Ms(e){const{className:t,...n}=e;return s.jsx("input",{...n,className:Ut("w-full px-4 py-3 rounded-xl border border-border-subtle bg-bg-secondary","text-text-primary text-sm outline-none","focus:border-accent transition-colors",t)})}const gT={primary:"btn-primary",secondary:"btn-secondary",warning:"btn-warning",danger:"btn-danger",ghost:"btn-ghost"},en=l.forwardRef(function({variant:t="secondary",size:n="md",type:a,className:o,...r},i){return s.jsx("button",{ref:i,type:a??"button",className:Ut("btn",gT[t],n==="sm"&&"btn-sm",o),...r})}),bT=l.forwardRef(function({options:t,children:n,className:a,...o},r){return s.jsx("select",{ref:r,className:Ut("w-full px-4 py-3 rounded-xl border border-border-subtle bg-bg-secondary","text-text-primary text-sm outline-none cursor-pointer","focus:border-accent transition-colors",a),...o,children:n??(t==null?void 0:t.map(i=>s.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value)))})});function Jf({tabs:e,defaultTabKey:t,activeKey:n,onTabChange:a,variant:o="pill",ariaLabel:r,className:i,tabListClassName:c,panelClassName:d,tabIdPrefix:u,unmountInactivePanels:p=!1}){var S;const[m,h]=l.useState(t??((S=e[0])==null?void 0:S.key)),f=n!==void 0,x=f?n:m,b=j=>{f||h(j),a==null||a(j)},g=o==="underline";return s.jsxs("div",{className:i,children:[s.jsx("div",{className:Ut(g?"flex shrink-0 items-center gap-1 border-b border-border-subtle px-4 md:px-6":"mb-5 inline-flex w-full flex-wrap items-center gap-1 rounded-xl border border-border-subtle bg-bg-secondary/60 p-1 sm:w-fit",c),role:"tablist","aria-label":r,children:e.map(j=>{const y=j.key===x;return s.jsxs("button",{id:u?`${u}-${j.key}`:void 0,type:"button",role:"tab","aria-selected":y,className:Ut(g?["-mb-px flex cursor-pointer items-center gap-1.5 border-b-2 px-3 py-2.5 text-xxs font-medium transition-colors",y?"border-accent text-accent":"border-transparent text-text-muted hover:text-text-secondary"]:["flex flex-1 items-center justify-center gap-1.5 rounded-lg px-3.5 py-1.5 text-xxs font-medium transition-colors sm:flex-none",y?"bg-bg-card text-text-primary shadow-sm border border-border-default":"text-text-muted border border-transparent hover:text-text-secondary hover:bg-white/[0.03]"]),onClick:()=>b(j.key),children:[j.icon,j.label]},j.key)})}),e.map(j=>{const y=j.key===x;return p&&!y?null:s.jsx("div",{className:y?Ut("flex flex-col gap-4",d):"hidden",children:j.content},j.key)})]})}class xT extends l.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){console.error("[ErrorBoundary] Uncaught error:",t,n)}render(){return this.state.hasError?s.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"100vh",background:"var(--bg-primary, #0a0e1a)",color:"var(--text-secondary, #c4c9d4)",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:s.jsxs("div",{style:{textAlign:"center",maxWidth:420,padding:24},children:[s.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:16},children:s.jsx(ds,{size:44,className:"text-status-warning"})}),s.jsx("h2",{style:{margin:"0 0 8px",fontSize:18,fontWeight:600,color:"var(--text-primary, #eee)"},children:"Something went wrong"}),s.jsx("p",{style:{margin:"0 0 20px",fontSize:14,opacity:.7,lineHeight:1.5},children:"An unexpected error occurred. Please reload the page to continue."}),s.jsx("button",{onClick:()=>window.location.reload(),style:{padding:"10px 24px",borderRadius:8,border:"1px solid rgba(99, 102, 241, 0.4)",background:"rgba(99, 102, 241, 0.1)",color:"#a5b4fc",fontSize:14,fontWeight:500,cursor:"pointer"},children:"Reload page"})]})}):this.props.children}}function Js({label:e,description:t,checked:n,disabled:a,onChange:o,extra:r}){return s.jsxs("div",{className:`flex justify-between items-center ${a?"opacity-60":""}`,children:[s.jsxs("div",{className:"pr-4",children:[s.jsx("div",{className:"font-medium text-sm",children:e}),s.jsx("div",{className:"text-2xs text-text-muted mt-0.5",children:t})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[r,s.jsxs("button",{type:"button",role:"switch","aria-checked":n,"aria-disabled":a,disabled:a,onClick:()=>o(!n),className:`relative inline-flex items-center ${a?"cursor-not-allowed":"cursor-pointer"}`,children:[s.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),s.jsx("div",{className:`absolute left-[1.5px] top-[1.5px] w-[19px] h-[19px] bg-white rounded-full transition-transform duration-200 ease-in-out shadow-[0_1px_2px_rgba(0,0,0,0.15)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}const vT=["default","claude-cli","codex-cli","antigravity-cli","hermes-cli"];function yT({daemonId:e,knownCliTypes:t=vT}){const{t:n}=ye("common"),{sendCommand:a}=wt(),[o,r]=l.useState({}),[i,c]=l.useState({}),[d,u]=l.useState(!0),[p,m]=l.useState(null),[h,f]=l.useState(null),[x,b]=l.useState(""),[g,S]=l.useState(!1),[j,y]=l.useState(null),k=l.useCallback(async()=>{if(e){u(!0),f(null);try{const P=await a(e,"list_coordinator_prompts",{}),D=P!=null&&P.result&&typeof P.result=="object"?P.result:P;if(!(D!=null&&D.success)){f((D==null?void 0:D.error)||"Failed to load");return}const L=D.entries||{};b(D.dir||"");const I={};for(const R of t)I[R]=L[R]||{override:"",append:""};for(const R of Object.keys(L))I[R]||(I[R]=L[R]);r(I),c(JSON.parse(JSON.stringify(I)))}catch(P){f((P==null?void 0:P.message)||String(P))}finally{u(!1)}}},[a,e,t]);l.useEffect(()=>{k()},[k]);const v=l.useCallback(async(P,D)=>{var L;if(e){m(`${P}:${D}`),f(null);try{const I=((L=o[P])==null?void 0:L[D])||"",R=await a(e,"write_coordinator_prompt",{key:P,kind:D,content:I}),_=R!=null&&R.result&&typeof R.result=="object"?R.result:R;if(!(_!=null&&_.success)){f((_==null?void 0:_.error)||"Save failed");return}c(M=>({...M,[P]:{...M[P]||{override:"",append:""},[D]:I}}))}catch(I){f((I==null?void 0:I.message)||String(I))}finally{m(null)}}},[a,e,o]),C=l.useMemo(()=>(P,D)=>{var L,I;return(((L=o[P])==null?void 0:L[D])||"")!==(((I=i[P])==null?void 0:I[D])||"")},[o,i]),w=l.useCallback(P=>{const D=i[P];return!!(D&&((D.override||"").trim()||(D.append||"").trim()))},[i]),N=Object.keys(o),T=N.filter(w),A=j&&o[j]?j:N[0];return e?g?s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"text-xs text-text-muted",children:[s.jsxs("p",{children:["Customize the coordinator prompt this daemon's mesh coordinator sessions get. ",s.jsx("span",{className:"font-mono text-2xs",children:x||"~/.adhdev/coordinator-prompts/"})]}),s.jsxs("p",{className:"mt-1",children:[s.jsx(Dl,{i18nKey:"settings.coordinatorPrompts.overrideDesc",ns:"common",components:{strong:s.jsx("strong",{})}})," ",s.jsx(Dl,{i18nKey:"settings.coordinatorPrompts.appendDesc",ns:"common",components:{strong:s.jsx("strong",{})}}),"Leave a field empty + Save to remove it (reset to default). Supports placeholders: ","{{meshName}}",", ","{{repo}}",", ","{{nodes}}",", ","{{rules}}",", etc."]})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm shrink-0",onClick:()=>S(!1),children:n("settings.coordinatorPrompts.collapseLabel")})]}),h&&s.jsx("div",{className:"text-xs text-status-error bg-status-error/10 border border-status-error/40 rounded px-3 py-2",children:h}),d&&s.jsx("div",{className:"text-xs text-text-muted",children:"Loading…"}),N.length>0&&s.jsx(Jf,{activeKey:A,onTabChange:y,ariaLabel:n("settings.coordinatorPrompts.tabsAriaLabel"),tabIdPrefix:"coordinator-prompt-tab",tabs:N.map(P=>{const D=o[P],L=C(P,"override")||C(P,"append");return{key:P,label:s.jsxs("span",{className:"flex items-center gap-1.5 font-mono text-xs",children:[P,w(P)&&s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-primary",title:n("settings.coordinatorPrompts.customizedBadge")}),L&&s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:"var(--status-warning)"},"aria-hidden":!0})]}),content:s.jsxs("div",{className:"rounded-lg border border-border-subtle bg-bg-secondary/40 p-3",children:[s.jsx("label",{className:"block text-2xs uppercase tracking-wide text-text-muted mb-1",children:n("settings.coordinatorPrompts.overrideLabel")}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-xs font-mono text-text-primary",rows:4,value:D.override,onChange:I=>r(R=>({...R,[P]:{...R[P],override:I.target.value}})),placeholder:"(empty — use daemon default base prompt)",disabled:p===`${P}:override`}),s.jsx("div",{className:"mt-1 mb-3 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void v(P,"override"),disabled:p===`${P}:override`||!C(P,"override"),children:p===`${P}:override`?"Saving…":C(P,"override")?"Save override":"Saved"})}),s.jsx("label",{className:"block text-2xs uppercase tracking-wide text-text-muted mb-1",children:n("settings.coordinatorPrompts.appendLabel")}),s.jsx("textarea",{className:"w-full px-3 py-2 rounded bg-bg-secondary border border-border-subtle text-xs font-mono text-text-primary",rows:3,value:D.append,onChange:I=>r(R=>({...R,[P]:{...R[P],append:I.target.value}})),placeholder:"(empty — nothing appended at this layer)",disabled:p===`${P}:append`}),s.jsx("div",{className:"mt-1 flex justify-end",children:s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>void v(P,"append"),disabled:p===`${P}:append`||!C(P,"append"),children:p===`${P}:append`?"Saving…":C(P,"append")?"Save append":"Saved"})})]})}})})]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[h&&s.jsx("div",{className:"text-xs text-status-error bg-status-error/10 border border-status-error/40 rounded px-3 py-2",children:h}),s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-border-subtle bg-bg-secondary/40 px-3 py-2.5",children:[s.jsx("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5 text-xs text-text-muted",children:d?s.jsx("span",{children:"Loading…"}):T.length===0?s.jsx("span",{children:n("settings.coordinatorPrompts.collapsedNone")}):s.jsxs(s.Fragment,{children:[s.jsxs("span",{children:[n("settings.coordinatorPrompts.customizedBadge"),":"]}),T.map(P=>s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-accent-primary/10 px-1.5 py-0.5 font-mono text-2xs text-accent-primary",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-primary","aria-hidden":!0}),P]},P))]})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm shrink-0",onClick:()=>S(!0),children:n("settings.coordinatorPrompts.expandLabel")})]})]}):s.jsx("div",{className:"text-xs text-text-muted",children:"Connect a daemon to edit coordinator prompts."})}const wT=[{id:"dark",label:"Dark",icon:sh},{id:"light",label:"Light",icon:th},{id:"system",label:"System",icon:nh}];function kT(){const{preference:e,setPreference:t}=nn();return s.jsx("div",{className:"flex gap-2",children:wT.map(n=>s.jsxs("button",{onClick:()=>t(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${e===n.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:e===n.id?{color:"var(--accent-on-primary)"}:void 0,children:[s.jsx(n.icon,{size:14}),n.label]},n.id))})}function ST(e){const t=e.trim();return/^#[0-9a-fA-F]{6}$/.test(t)?t:/^#[0-9a-fA-F]{3}$/.test(t)?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:null}function CT(e){return{r:parseInt(e.slice(1,3),16),g:parseInt(e.slice(3,5),16),b:parseInt(e.slice(5,7),16)}}function Qi(e){const t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}function hp(e){const{r:t,g:n,b:a}=CT(e);return .2126*Qi(t)+.7152*Qi(n)+.0722*Qi(a)}function fp(e,t){const n=hp(e),a=hp(t),o=Math.max(n,a),r=Math.min(n,a);return(o+.05)/(r+.05)}function Xf(e){const t=ST(e);if(!t)return"#111827";const n="#111827",a="#ffffff";return fp(t,n)>=fp(t,a)?n:a}const uc={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},pc={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},jT=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],Zf="adhdev-chat-theme",eg="adhdev-chat-theme-custom";function mr(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Zf)||"ember"}catch{return"ember"}}function Ds(e){try{const t=localStorage.getItem(eg);if(t){const n=JSON.parse(t);return{...e==="dark"?uc:pc,...n[e]}}}catch{}return e==="dark"?uc:pc}function Uo(e,t){try{localStorage.setItem(eg,JSON.stringify({dark:e,light:t}))}catch{}}function ws(e,t){const n=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16);return`rgba(${n}, ${a}, ${o}, ${t})`}function Er(e,t){const n=Math.min(255,parseInt(e.slice(1,3),16)+t),a=Math.min(255,parseInt(e.slice(3,5),16)+t),o=Math.min(255,parseInt(e.slice(5,7),16)+t);return`#${n.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const NT={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function ao(e,t){var o;const n=(o=NT[e])==null?void 0:o[t];if(!n)return;const a=document.documentElement;a.style.setProperty("--accent-primary",n),a.style.setProperty("--accent-primary-light",Er(n,24)),a.style.setProperty("--accent-on-primary",Xf(n)),a.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Er(n,18)})`),a.style.setProperty("--border-accent",ws(n,.35)),a.style.setProperty("--nav-active-bg",ws(n,.1)),a.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${ws(n,.06)}`)}function Fn(e){const t=document.documentElement;t.style.setProperty("--bg-primary",e.bgPrimary),t.style.setProperty("--bg-secondary",e.bgSecondary),t.style.setProperty("--bg-card",ws(e.surfacePrimary,.92)),t.style.setProperty("--surface-primary",e.surfacePrimary),t.style.setProperty("--surface-secondary",e.bgSecondary),t.style.setProperty("--bg-glass",ws(e.borderSubtle,.15)),t.style.setProperty("--bg-glass-hover",ws(e.borderSubtle,.25)),t.style.setProperty("--text-primary",e.textPrimary),t.style.setProperty("--text-secondary",e.textSecondary),t.style.setProperty("--text-muted",e.textMuted),t.style.setProperty("--border-subtle",ws(e.borderSubtle,.5)),t.style.setProperty("--border-default",ws(e.borderDefault,.5)),t.style.setProperty("--accent-primary",e.accentColor),t.style.setProperty("--accent-primary-light",Er(e.accentColor,30)),t.style.setProperty("--accent-on-primary",Xf(e.accentColor)),t.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${e.accentColor}, ${Er(e.accentColor,40)})`),t.style.setProperty("--border-accent",ws(e.accentColor,.35)),t.style.setProperty("--nav-active-bg",ws(e.accentColor,.1)),t.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${e.accentColor}, 0 0 12px ${ws(e.accentColor,.06)}`),t.style.setProperty("--chat-user-bg",e.userBubble),t.style.setProperty("--chat-user-color",e.userText),t.style.setProperty("--chat-user-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px 4px ${e.bubbleRadius}px`),t.style.setProperty("--chat-assistant-bg",e.assistantBubble),t.style.setProperty("--chat-assistant-color",e.assistantText),t.style.setProperty("--chat-assistant-radius",`${e.bubbleRadius}px ${e.bubbleRadius}px ${e.bubbleRadius}px 4px`),t.style.setProperty("--chat-assistant-border",`1px solid ${ws(e.accentColor,.12)}`),t.style.setProperty("--chat-container-bg",e.containerBg),t.style.setProperty("--dashboard-pane-bg",e.containerBg),t.style.setProperty("--chat-thought-accent",e.accentColor),t.style.setProperty("--chat-tool-accent",e.accentColor),t.style.setProperty("--chat-action-color",e.accentColor),t.style.setProperty("--chat-send-bg",e.sendButton),t.style.setProperty("--chat-input-border",e.inputBorder)}function dd(){const e=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>e.style.removeProperty(n))}function AT(e){try{localStorage.setItem(Zf,e)}catch{}if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=$n()?"dark":"light";Fn(Ds(t))}else dd(),ao(e,$n()?"dark":"light")}function TT(){try{localStorage.removeItem("adhdev-accent-color")}catch{}const e=mr();if(document.documentElement.setAttribute("data-chat-theme",e),e==="custom"){const t=$n()?"dark":"light";Fn(Ds(t))}else dd(),ao(e,$n()?"dark":"light")}function $n(){const e=document.documentElement.getAttribute("data-theme");return e?e==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function ns({label:e,value:t,onChange:n}){return s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:e}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[s.jsx("input",{type:"color",value:t,onChange:a=>n(a.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),s.jsx("input",{type:"text",value:t,onChange:a=>{/^#[0-9a-fA-F]{0,6}$/.test(a.target.value)&&n(a.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function Wa({title:e,children:t}){return s.jsxs("div",{style:{marginBottom:14},children:[s.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:e}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:t})]})}function IT({dark:e,onColorsChange:t}){const{t:n}=ye("common"),a=e?"dark":"light",[o,r]=l.useState(()=>Ds(a));l.useEffect(()=>{r(Ds(a))},[a]);const i=l.useCallback((c,d)=>{r(u=>{const p={...u,[c]:d},h=Ds(a==="dark"?"light":"dark");return a==="dark"?Uo(p,h):Uo(h,p),Fn(p),t(p),p})},[a,t]);return s.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[s.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[n("settings.theme.customEditorTitle"),s.jsx("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:n(e?"settings.theme.darkMode":"settings.theme.lightMode")})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsxs(Wa,{title:n("settings.theme.sectionAppBackground"),children:[s.jsx(ns,{label:n("settings.theme.colorBackground"),value:o.bgPrimary,onChange:c=>i("bgPrimary",c)}),s.jsx(ns,{label:n("settings.theme.colorSurface"),value:o.bgSecondary,onChange:c=>i("bgSecondary",c)}),s.jsx(ns,{label:n("settings.theme.colorCard"),value:o.surfacePrimary,onChange:c=>i("surfacePrimary",c)})]}),s.jsxs(Wa,{title:n("settings.theme.sectionAppText"),children:[s.jsx(ns,{label:n("settings.theme.colorPrimary"),value:o.textPrimary,onChange:c=>i("textPrimary",c)}),s.jsx(ns,{label:n("settings.theme.colorSecondary"),value:o.textSecondary,onChange:c=>i("textSecondary",c)}),s.jsx(ns,{label:n("settings.theme.colorMuted"),value:o.textMuted,onChange:c=>i("textMuted",c)})]}),s.jsxs(Wa,{title:n("settings.theme.sectionBordersAccent"),children:[s.jsx(ns,{label:n("settings.theme.colorBorderSubtle"),value:o.borderSubtle,onChange:c=>i("borderSubtle",c)}),s.jsx(ns,{label:n("settings.theme.colorBorderDefault"),value:o.borderDefault,onChange:c=>i("borderDefault",c)}),s.jsx(ns,{label:n("settings.theme.colorAccent"),value:o.accentColor,onChange:c=>i("accentColor",c)})]})]}),s.jsxs("div",{children:[s.jsxs(Wa,{title:n("settings.theme.sectionChatBubbles"),children:[s.jsx(ns,{label:n("settings.theme.colorUserBubble"),value:o.userBubble,onChange:c=>i("userBubble",c)}),s.jsx(ns,{label:n("settings.theme.colorUserText"),value:o.userText,onChange:c=>i("userText",c)}),s.jsx(ns,{label:n("settings.theme.colorAgentBubble"),value:o.assistantBubble,onChange:c=>i("assistantBubble",c)}),s.jsx(ns,{label:n("settings.theme.colorAgentText"),value:o.assistantText,onChange:c=>i("assistantText",c)})]}),s.jsxs(Wa,{title:n("settings.theme.sectionChatLayout"),children:[s.jsx(ns,{label:n("settings.theme.colorChatBg"),value:o.containerBg,onChange:c=>i("containerBg",c)}),s.jsx(ns,{label:n("settings.theme.colorSendButton"),value:o.sendButton,onChange:c=>i("sendButton",c)}),s.jsx(ns,{label:n("settings.theme.colorInputBorder"),value:o.inputBorder,onChange:c=>i("inputBorder",c)}),s.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:n("settings.theme.labelBubbleRadius")}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[s.jsx("input",{type:"range",min:4,max:24,value:o.bubbleRadius,onChange:c=>i("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),s.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[o.bubbleRadius,"px"]})]})]})]})]})]}),s.jsx("button",{onClick:()=>{const c=e?uc:pc,u=Ds(e?"light":"dark");e?Uo(c,u):Uo(u,c),r(c),Fn(c),t(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:n("settings.theme.resetToDefaults")})]})}function PT(){const{t:e}=ye("common"),[t,n]=l.useState(mr),[a,o]=l.useState(!0),[r,i]=l.useState(()=>Ds("dark"));l.useEffect(()=>{o($n());const u=new MutationObserver(()=>{const h=$n();o(h);const f=mr();f==="custom"?Fn(Ds(h?"dark":"light")):ao(f,h?"dark":"light")});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const p=window.matchMedia("(prefers-color-scheme: dark)"),m=()=>{const h=$n();o(h);const f=mr();f==="custom"?Fn(Ds(h?"dark":"light")):ao(f,h?"dark":"light")};return p.addEventListener("change",m),()=>{u.disconnect(),p.removeEventListener("change",m)}},[]),l.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Fn(Ds(a?"dark":"light")):(dd(),ao(t,a?"dark":"light"))},[t,a]),l.useEffect(()=>{i(Ds(a?"dark":"light"))},[a]);const c=u=>{n(u),AT(u)},d=[...jT,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:r.userBubble,assistantBubble:r.assistantBubble,assistantBorder:`1px solid ${r.accentColor}22`,containerBg:r.containerBg,textColor:r.assistantText},light:{userBubble:r.userBubble,assistantBubble:r.assistantBubble,assistantBorder:`1px solid ${r.accentColor}22`,containerBg:r.containerBg,textColor:r.assistantText}}}];return s.jsxs("div",{children:[s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(u=>{const p=t===u.id,m=a?u.preview.dark:u.preview.light,h=u.id==="honey"||u.id==="ember"?"#1a1a1a":u.id==="custom"?r.userText:"#fff";return s.jsxs("button",{onClick:()=>c(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:p?"var(--bg-glass-hover)":"var(--bg-glass)",border:p?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:p?1:.75},children:[s.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:m.containerBg},children:[s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-3xs max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.textColor},children:e("settings.theme.helloHelp")}),s.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-3xs max-w-[75%]",style:{background:m.userBubble,color:h},children:e("settings.theme.fixBug")}),s.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-3xs max-w-[75%]",style:{background:m.assistantBubble,border:m.assistantBorder,color:m.textColor},children:e("settings.theme.onIt")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[p&&s.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-bold text-text-primary",children:u.id==="custom"?e("settings.theme.customLabel"):u.name}),s.jsx("div",{className:"text-3xs text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&s.jsx(IT,{dark:a,onColorsChange:u=>i(u)})]})}const ud="adhdev_mobileDashboardMode_v1",mc="adhdev:mobile-dashboard-mode-change";function pd(){try{return localStorage.getItem(ud)==="workspace"?"workspace":"chat"}catch{return"chat"}}function LT(e){if(typeof window>"u")return()=>{};const t=o=>{e(o??pd())},n=o=>{const r=o.detail;t(r)},a=o=>{o.key&&o.key!==ud||t()};return window.addEventListener(mc,n),window.addEventListener("storage",a),()=>{window.removeEventListener(mc,n),window.removeEventListener("storage",a)}}function DT(e){try{localStorage.setItem(ud,e)}catch{}typeof window<"u"&&window.dispatchEvent(new CustomEvent(mc,{detail:e}))}function MT(){const[e,t]=l.useState(!0);return l.useEffect(()=>{t(pd()==="chat")},[]),s.jsx(Js,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Ks,{size:15})," Mobile Inbox (Chat Mode)"]}),description:e?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:e,onChange:n=>{t(n),DT(n?"chat":"workspace")},extra:s.jsx("span",{className:"text-2xs text-text-muted",children:e?"Chat mode":"Workspace"})})}function RT(){const{t:e}=ye("common"),[t,n]=l.useState(()=>En());return l.useEffect(()=>Gc(n),[]),s.jsx(Js,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(rv,{size:15})," ",e("settings.chatActivity.rowLabel")]}),description:e(t?"settings.chatActivity.descriptionOn":"settings.chatActivity.descriptionOff"),checked:t,onChange:a=>{n(a),ph(a)}})}const _T="Choose a preset or create a fully custom theme. Custom themes control the entire app — backgrounds, text, borders, and chat bubbles.",ET="Choose whether the dashboard opens like a chat app on phones or keeps the full workspace layout.";function HT({themeDescription:e=_T,mobileDescription:t=ET,fontsSlot:n}){const{t:a}=ye("common");return s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:a("settings.appearance.modeLabel")}),s.jsx(kT,{})]}),s.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[s.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:a("settings.appearance.themeLabel")}),s.jsx("p",{className:"text-2xs text-text-muted mb-3",children:e}),s.jsx(PT,{})]}),s.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[s.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:a("settings.appearance.chatLabel")}),s.jsx(RT,{})]}),n,s.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[s.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:a("settings.appearance.mobileLabel")}),s.jsx("p",{className:"text-2xs text-text-muted mb-3",children:t}),s.jsx(MT,{})]})]})}const Ji=new Map,gp=new Map;function FT(e){if(!e||typeof e!="object")return null;const t=e,n=t.result&&typeof t.result=="object"?t.result:t,a=n.machine;return!a||typeof a!="object"?null:{machine:a,timestamp:typeof n.timestamp=="number"?n.timestamp:void 0}}function $T(e,t,n,a){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:a,platform:n.platform,machine:n}}function tg(){const{sendCommand:e}=wt(),{injectEntries:t,getIdes:n}=ba();return l.useCallback(async(a,o)=>{if(!a)return;const r=(o==null?void 0:o.minFreshMs)??DN,i=gp.get(a)||0;if(!(o!=null&&o.force)&&i>0&&Date.now()-i<r)return;const c=Ji.get(a);if(c)return c;const d=(async()=>{const u=await e(a,"get_machine_runtime_stats"),p=FT(u);if(!p)return;const m=n().find(f=>f.id===a),h=$T(m,a,p.machine,p.timestamp||Date.now());t([h]),gp.set(a,Date.now())})().finally(()=>{Ji.delete(a)});return Ji.set(a,d),d},[n,t,e])}function BT(e,t,n){return{...e||{},id:t,type:(e==null?void 0:e.type)||"adhdev-daemon",status:(e==null?void 0:e.status)||"online",timestamp:n.timestamp,platform:n.machine.platform,machine:{...(e==null?void 0:e.machine)||{},...n.machine}}}function WT(e,t){const{sendData:n}=wt(),{injectEntries:a,getIdes:o}=ba(),r=Array.from(new Set(e.filter(Boolean))).join("|");l.useEffect(()=>{if(!(t!=null&&t.enabled)||!n)return;const i=r?r.split("|"):[];if(i.length===0)return;const c=i.map(d=>As.subscribe({sendData:n},d,{type:"subscribe",topic:"machine.runtime",key:`machine:${d}`,params:{intervalMs:t==null?void 0:t.intervalMs}},p=>{const m=o().find(f=>f.id===d),h=BT(m,d,p);a([h])}));return()=>{c.forEach(d=>d())}},[r,o,a,t==null?void 0:t.enabled,t==null?void 0:t.intervalMs,n])}function OT(e,t){const{sendData:n}=wt(),[a,o]=l.useState(null),[r,i]=l.useState(!1);return l.useEffect(()=>{if(!e){o(null),i(!1);return}if(!(t!=null&&t.enabled)||!n){i(!1);return}o(null),i(!0);let c=null;const d=As.subscribe({sendData:n},e,{type:"subscribe",topic:"session_host.diagnostics",key:`session_host:${e}`,params:{includeSessions:(t==null?void 0:t.includeSessions)!==!1,...typeof(t==null?void 0:t.limit)=="number"?{limit:t.limit}:{},...typeof(t==null?void 0:t.intervalMs)=="number"?{intervalMs:t.intervalMs}:{}}},u=>{c&&(clearTimeout(c),c=null),o(u.diagnostics),i(!1)});return d.initialSendAccepted?c=setTimeout(()=>{i(!1)},_N):i(!1),()=>{c&&clearTimeout(c),d()}},[e,t==null?void 0:t.enabled,t==null?void 0:t.includeSessions,t==null?void 0:t.intervalMs,t==null?void 0:t.limit,n]),{diagnostics:a,loading:r,applyDiagnostics:o}}function bp(e){return e.daemonId||(e.routeId.includes(":")?e.routeId.split(":")[0]||null:e.routeId||null)}function sg(e){const{sendData:t,isConnected:n}=wt(),[a,o]=l.useState({}),r=l.useRef(null);return l.useEffect(()=>{const i=bp(e);if(!i||!e.sessionId||!t){o({});return}const c=As.subscribe({sendData:t},i,{type:"subscribe",topic:"session.modal",key:`daemon:${i}:session-modal:${e.sessionId}`,params:{targetSessionId:e.sessionId}},d=>{o({status:d.status,modalMessage:d.modalMessage,modalButtons:d.modalButtons}),On.record({interactionId:d.interactionId,kind:"dashboard.session_modal_applied",topic:"session.modal",payload:{sessionId:e.sessionId,status:d.status,modalButtonCount:Array.isArray(d.modalButtons)?d.modalButtons.length:0}})});return c.initialSendAccepted||o({}),r.current=()=>{As.resubscribeForDaemon(i,{sendData:t}),On.record({kind:"dashboard.session_modal_resync",topic:"session.modal",payload:{sessionId:e.sessionId}})},()=>{r.current=null,c()}},[e.daemonId,e.routeId,e.sessionId,t]),l.useEffect(()=>{const i=bp(e);if(!i||!e.sessionId||!t)return;const c=()=>{var h;return(h=r.current)==null?void 0:h.call(r)},d=()=>{typeof document>"u"||document.visibilityState==="visible"&&c()},u=h=>{h.persisted&&c()};typeof document<"u"&&document.addEventListener("visibilitychange",d),typeof window<"u"&&window.addEventListener("pageshow",u);let p=n?n(i):!0;const m=()=>{if(!n)return;const h=n(i);h&&!p&&c(),p=h};return typeof document<"u"&&document.addEventListener("visibilitychange",m),typeof window<"u"&&window.addEventListener("online",m),()=>{typeof document<"u"&&(document.removeEventListener("visibilitychange",d),document.removeEventListener("visibilitychange",m)),typeof window<"u"&&(window.removeEventListener("pageshow",u),window.removeEventListener("online",m))}},[e.daemonId,e.routeId,e.sessionId,t,n]),a}function ng(e){return e instanceof Error?e.message:String(e||"")}function UT(e){const t=ng(e);return t.includes("P2P command timeout")||t.includes("P2P not connected")||t.includes("P2P channel not open")||t.includes("P2P not available")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}function qT(e){const t=ng(e);return t.includes("P2P command timeout")||t.includes("P2P data channel closed")||t.includes("P2P receiver stopped")}async function ag({conversation:e,mode:t,ides:n,sendDaemonCommand:a,setCliViewModeOverrides:o}){if(!e||!vt(e)||gt(e))return;const r=ja(e);if(r===t)return;const i=e.sessionId;i&&o(c=>({...c,[i]:t}));try{await a(sn(e)||e.routeId,"set_cli_view_mode",{targetSessionId:e.sessionId,cliType:qs(e),mode:t})}catch(c){const d=qT(c);i&&!d&&o(u=>{const p={...u};return r===GT(n,i)?delete p[i]:p[i]=r,p}),UT(c)?console.warn(d?"CLI view mode result was lost after send; keeping optimistic mode override:":"Skipped CLI view mode switch:",c instanceof Error?c.message:String(c)):console.error("Failed to switch CLI view mode:",c)}}function xp(e,t){const n=typeof e.sessionId=="string"&&e.sessionId?e.sessionId:typeof e.id=="string"?e.id:"";if(!n||e.transport!=="pty")return e;const a=t[n];return!a||e.mode===a?e:{...e,mode:a}}function zT(e,t){if(!Array.isArray(e)||e.length===0||!t||Object.keys(t).length===0)return e;let n=!1;const a=e.map(o=>{const r=xp(o,t),i=Array.isArray(o.childSessions)?o.childSessions.map(d=>xp(d,t)):o.childSessions,c=i!==o.childSessions;return r!==o||c?(n=!0,{...r,...c?{childSessions:i}:{}}):o});return n?a:e}function GT(e,t){if(!t)return null;for(const n of e){if(n.sessionId===t&&n.transport==="pty")return n.mode==="chat"?"chat":"terminal";for(const a of n.childSessions||[])if(a.id===t&&a.transport==="pty")return a.mode==="chat"?"chat":"terminal"}return null}function KT({visibleConversations:e,clearedTabs:t,setClearedTabs:n,setActionLogs:a,isConversationMuted:o}){l.useEffect(()=>{Hh()},[]);const r=l.useMemo(()=>e.map(i=>({id:i.tabKey,name:Df(i),status:i.status,activeModal:i.modalMessage?{message:i.modalMessage,buttons:i.modalButtons}:null,target:{providerSessionId:i.providerSessionId,sessionId:i.sessionId,tabKey:i.tabKey,routeId:i.routeId},muted:o?o(i):!1})),[e,o]);return wC(r),l.useEffect(()=>{if(Object.keys(t).length===0)return;const c=setTimeout(()=>{n(d=>{const u=Date.now(),p={};for(const[m,h]of Object.entries(d))u-h<5e3&&(p[m]=h);return Object.keys(p).length===Object.keys(d).length?d:p})},5500);return()=>clearTimeout(c)},[t,n]),l.useEffect(()=>{const i=setInterval(()=>{const c=Date.now()-3e5;a(d=>{const u=d.filter(p=>p.timestamp>c).slice(-100);return u.length===d.length?d:u})},6e4);return()=>clearInterval(i)},[a]),null}function vp(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function Bn(e){const t=[...e.messages].reverse().find(o=>!(o!=null&&o._localId))||e.messages[e.messages.length-1],n=typeof e.lastMessageAt=="number"&&Number.isFinite(e.lastMessageAt)?e.lastMessageAt:0,a=vp(t==null?void 0:t.receivedAt)||vp(t==null?void 0:t.timestamp)||0;return Math.max(n,a)}function hc(e,t=0){return Bn(e)||e.lastUpdated||t||0}function og(e){return Bn(e)||e.lastUpdated||0}function rg(e,t,n=og){const a=n(t)-n(e);if(a!==0)return a;const o=(e.machineName||"").localeCompare(t.machineName||"");if(o!==0)return o;const r=e.displayPrimary.localeCompare(t.displayPrimary);if(r!==0)return r;const i=e.displaySecondary.localeCompare(t.displaySecondary);return i!==0?i:e.tabKey.localeCompare(t.tabKey)}function fc(e){var n;const t=gs(e.status,{activeModal:(n=e.modalButtons)!=null&&n.length?{buttons:e.modalButtons}:null});return t==="generating"||t==="waiting_approval"}function VT(e){var t;return e.messages.length===0&&!((t=e.modalButtons)!=null&&t.length)&&!fc(e)&&!e.title.trim()}function YT(e){return e.length===0?null:[...e].sort((t,n)=>{const a=Number(fc(n))-Number(fc(t));if(a!==0)return a;const o=n.messages.length-t.messages.length;return o!==0?o:rg(t,n)})[0]||null}function _s(e,t){const n=e.filter(i=>i.routeId===t);if(n.length===0)return null;const a=n.find(i=>i.streamSource==="native")||null,o=n.filter(i=>i.streamSource==="agent-stream"),r=YT(o);return a?r&&VT(a)?r:a:r||n[0]||null}function QT(e){const t=e.filter(o=>o.type!=="adhdev-daemon"),n=new Set;for(const o of t){if(!Xl(o))continue;const r=Dh(o);r&&n.add(r)}const a=new Map;for(const o of t){const r=JS(o,n),i=a.get(r);if(!i){a.set(r,o);continue}const c=m=>(m.workspace?1:0)+(m.activeChat?1:0)+(m.lastMessagePreview?1:0),d=c(i),u=c(o),p=u>d||u===d&&(o.timestamp||0)>(i.timestamp||0)?o:i;a.set(r,JT(p,p===o?i:o))}return Array.from(a.values())}function JT(e,t){const n=Xl(t),a=Xl(e);if(!n&&!a)return e;const o=a?n?void 0:t:e,r=a?e:n?t:void 0,i=o&&String(o.daemonId||"").trim()||String(e.ownerDaemonId||"").trim()||String(t.ownerDaemonId||"").trim()||void 0,c=String(e.ownerMachineName||"").trim()||String(t.ownerMachineName||"").trim()||void 0,d=r==null?void 0:r.settings;return{...e,...i&&{ownerDaemonId:i},...c&&!e.ownerMachineName&&{ownerMachineName:c},...d&&!a&&{settings:{...d,...e.settings??{}}}}}function Xi(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function XT(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function yp(e){if(!e)return"";const t=Array.isArray(e.messages)?e.messages:[],n=t[t.length-1],a=n?XT(ga(n.content)):"";return[e.id||"",e.title||"",e.status||"",t.length,String((n==null?void 0:n.id)||""),String((n==null?void 0:n.index)??""),String((n==null?void 0:n.receivedAt)??(n==null?void 0:n.timestamp)??""),a].join(":")}function ZT(e){const t=Array.isArray(e.childSessions)?e.childSessions:[];return[e.id,e.sessionId||"",e.providerSessionId||"",e.transport||"",e.mode||"",e.status||"",e.workspace||"",e.lastMessageHash||"",String(e.lastMessageAt||""),e.lastMessagePreview||"",e.lastMessageRole||"",String(e.lastUpdated||""),yp(e.activeChat),...t.map(n=>[n.id||"",n.providerSessionId||"",n.transport||"",n.mode||"",n.status||"",n.title||"",n.lastMessageHash||"",String(n.lastMessageAt||""),n.lastMessagePreview||"",n.lastMessageRole||"",String(n.lastUpdated||""),yp(n.activeChat)].join(":"))].join("|")}function eI(e,t){const n=Date.now();return e.map(a=>{const o=t[a.tabKey];return o&&n-o<5e3?{...a,messages:[],title:""}:a})}function tI(e,t){const n=new Map;for(const a of e){const o=t.get(a.routeId)||a;for(const r of no({routeId:a.routeId}))n.set(r,o);for(const r of no({providerSessionId:a.providerSessionId,sessionId:a.sessionId}))n.set(r,a.streamSource==="native"?o:a);for(const r of no({tabKey:a.tabKey}))n.set(r,a)}return n}function sI(e){return[...e.messages].reverse().find(t=>!(t!=null&&t._localId))||e.messages[e.messages.length-1]}function nI(e){const t=sI(e);if(!t)return`empty:${e.messages.length}`;if(t.id)return`id:${String(t.id)}`;if(t._localId)return`local:${String(t._localId)}`;const n=String(t.role||""),a=ga(t.content).slice(0,240);return`${e.messages.length}:${n}:${a}`}function aI({ides:e,connectionStates:t,clearedTabs:n}){const a=l.useMemo(()=>QT(e),[e]),o=l.useMemo(()=>Sh(e),[e]),r=l.useMemo(()=>qf(e),[e]),i=l.useRef([]),c=l.useRef([]),d=l.useRef([]),u=l.useRef(new Map),p=l.useRef(new Map),m=l.useMemo(()=>{const k=new Map,v=[];for(const T of a){const{connectionState:A="new",machineName:P}=zf(T,{machineNames:r,connectionStates:t,defaultConnectionState:"new"}),D=ZT(T),L=u.current.get(T.id);if(L&&L.ide===T&&L.sourceSignature===D&&L.connectionState===A&&L.machineName===P){k.set(T.id,L),v.push(...L.conversations);continue}const I=cd(T,{machineNames:r,connectionStates:t,defaultConnectionState:"new"}),R={ide:T,sourceSignature:D,connectionState:A,machineName:P,conversations:I};k.set(T.id,R),v.push(...I)}u.current=k;const C=new Map,w=T=>{const A=nI(T),P=p.current.get(T.tabKey);if(P&&P.signature===A)return C.set(T.tabKey,P),P.timestamp;const D={signature:A,timestamp:og(T)||(P==null?void 0:P.timestamp)||0};return C.set(T.tabKey,D),D.timestamp},N=[...v].sort((T,A)=>rg(T,A,w));return p.current=C,N},[a,t,r]),h=l.useMemo(()=>{const k=eI(m,n);return Xi(i.current,k)?i.current:(i.current=k,k)},[m,n]),f=l.useMemo(()=>{const k=new Map,v=Array.from(new Set(h.map(C=>C.routeId)));for(const C of v){const w=_s(h,C);w&&k.set(C,w)}return k},[h]),x=l.useMemo(()=>{const k=new Map;for(const v of h){const C=f.get(v.routeId),w=v.streamSource==="native"&&C?C:v;for(const N of no({providerSessionId:v.providerSessionId,sessionId:v.sessionId,tabKey:v.tabKey}))k.set(N,w)}return k},[h,f]),b=l.useMemo(()=>tI(h,f),[h,f]),g=l.useCallback(k=>{if(k)return x.get(k)},[x]),S=l.useCallback(k=>{if(k)return b.get(k)},[b]),j=l.useMemo(()=>{const k=h.filter(v=>!yn(v,o).surfaceHidden);return Xi(c.current,k)?c.current:(c.current=k,k)},[h,o]),y=l.useMemo(()=>{const k=j.map(v=>v.tabKey);return Xi(d.current,k)?d.current:(d.current=k,k)},[j]);return{chatIdes:a,conversations:h,visibleConversations:j,visibleTabKeys:y,resolveConversationBySessionId:g,resolveConversationByTarget:S}}function oI({isMobile:e,urlActiveTab:t,resolveConversationBySessionId:n,setSearchParams:a}){const o=l.useMemo(()=>{var c;return e||!t?null:((c=n(t))==null?void 0:c.tabKey)??null},[e,n,t]),r=l.useMemo(()=>{var c;return!e||!t?null:((c=n(t))==null?void 0:c.tabKey)??null},[e,n,t]),i=l.useCallback(()=>{t&&a(c=>{const d=new URLSearchParams(c);return d.delete("activeTab"),d},{replace:!0})},[a,t]);return{requestedDesktopTabKey:o,requestedMobileTabKey:r,consumeRequestedActiveTab:i}}function rI({ides:e,sendDaemonCommand:t,setToasts:n,resolveConversationByTarget:a,hydrateInteractivePrompt:o}){l.useEffect(()=>{ft.setIdes(e)},[e]),l.useEffect(()=>{ft.setResolveAction((r,i,c)=>{t(r,i,c).catch(()=>{})})},[t]),l.useEffect(()=>{ft.setHydrateInteractivePrompt(o)},[o]),l.useEffect(()=>{const r=ft.onToast(i=>{n(d=>d.some(p=>p.message===i.message&&i.timestamp-p.timestamp<3e3)?d:[...d.slice(-4),{id:i.id,message:i.message,type:i.type,timestamp:i.timestamp,targetKey:i.targetKey,actions:i.actions}]);const c=i.duration||5e3;setTimeout(()=>n(d=>d.filter(u=>u.id!==i.id)),c)});return()=>{r()}},[n]),l.useEffect(()=>{const r=Yh.on("status_event",i=>{ft.handleRawEvent(i,"ws")});return()=>{r()}},[]),l.useEffect(()=>{var i;const r=c=>{var g;const d=c.data;if((d==null?void 0:d.type)!=="notification_action"||typeof d.action!="string"||!d.action.startsWith("approval_")||!(d.daemonId||d.targetSessionId||d.targetKey))return;const u=d.targetSessionId||d.targetKey||d.daemonId,p=a(u),m=(p==null?void 0:p.routeId)||d.daemonId;if(!m)return;const h=Number(d.buttonIndex),f=d.button||((g=p==null?void 0:p.modalButtons)==null?void 0:g[h])||"Approve",x=String(f).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(x);t(m,"resolve_action",{action:b?"approve":"reject",button:f,...Number.isFinite(h)&&{buttonIndex:h},...(p==null?void 0:p.sessionId)&&{targetSessionId:p.sessionId},...d.targetSessionId&&{targetSessionId:d.targetSessionId}}).catch(S=>console.error("[SW Action] approval failed:",S))};return(i=navigator.serviceWorker)==null||i.addEventListener("message",r),()=>{var c;return(c=navigator.serviceWorker)==null?void 0:c.removeEventListener("message",r)}},[a,t])}const iI="adhdev_dashboardLayout_v1",lI="adhdev_dashboardDockview_v1",cI="adhdev_dashboardDockviewHiddenRestore_v1",Oa={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function md(e,t){try{const n=localStorage.getItem(e);return n?JSON.parse(n):t}catch{return t}}function dI(e){return e<768?"mobile":e<1280?"desktop-narrow":"desktop-wide"}function ig(e){return`${iI}:${e}`}function uI(e){const t=ig(e);return md(t,null)}function pI(e,t){try{const n=t.groupAssignments.length===0&&t.focusedGroup===0&&Object.keys(t.groupActiveTabIds).length===0&&Object.keys(t.groupTabOrders).length===0&&t.groupSizes.length===0,a=ig(e);if(n){localStorage.removeItem(a);return}localStorage.setItem(a,JSON.stringify(t))}catch{}}function lg(e){return`${lI}:${e}`}function mI(e){const t=lg(e);return md(t,null)}function hI(e,t){try{const n=lg(e);if(!t){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(t))}catch{}}function cg(e){return`${cI}:${e}`}function fI(e){const t=cg(e);return md(t,{})}function gI(e,t){try{const n=cg(e);if(Object.keys(t).length===0){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(t))}catch{}}function bI(){return{groupAssignments:[...Oa.groupAssignments],focusedGroup:Oa.focusedGroup,groupActiveTabIds:{...Oa.groupActiveTabIds},groupTabOrders:{...Oa.groupTabOrders},groupSizes:[...Oa.groupSizes]}}function xI(e,t){return e?e.length===t.length&&e.every((n,a)=>n===t[a]):t.length===0}function vI(){const[e]=l.useState(()=>dI(typeof window<"u"?window.innerWidth:1280)),[t,n]=l.useState(()=>new Map),[a,o]=l.useState(0),[r,i]=l.useState({}),[c,d]=l.useState({}),[u,p]=l.useState([]),[m,h]=l.useState(()=>typeof window<"u"&&window.innerWidth<768),[f,x]=l.useState(!1),b=l.useCallback(()=>{if(f)return;const T=uI(e)??bI();n(new Map(T.groupAssignments)),o(T.focusedGroup),i(T.groupActiveTabIds),d(T.groupTabOrders),p(T.groupSizes),x(!0)},[f,e]);l.useEffect(()=>{f&&pI(e,{groupAssignments:[...t.entries()],focusedGroup:a,groupActiveTabIds:r,groupTabOrders:c,groupSizes:u})},[f,e,t,a,r,c,u]),l.useEffect(()=>{const T=window.matchMedia("(max-width: 767px)"),A=P=>h(P.matches);return T.addEventListener("change",A),()=>T.removeEventListener("change",A)},[]);const g=l.useCallback(T=>{n(T)},[]),S=l.useCallback(T=>{o(T)},[]),j=l.useCallback(T=>{i(T)},[]),y=l.useCallback(T=>{d(T)},[]),k=l.useCallback(T=>{p(T)},[]),v=l.useCallback(T=>{S(T)},[S]),C=l.useCallback((T,A)=>{i(P=>(P[T]??null)===(A??null)?P:{...P,[T]:A})},[]),w=l.useCallback((T,A)=>{d(P=>{const D=P[T];return xI(D,A)?P:{...P,[T]:A}})},[]),N=l.useCallback((T,A)=>{const P=A.get(T)??0;return C(P,T),v(P),P},[v,C]);return{layoutProfile:e,groupAssignments:t,updateGroupAssignments:g,focusedGroup:a,updateFocusedGroup:S,focusGroup:v,groupActiveTabIds:r,updateGroupActiveTabIds:j,setGroupActiveTab:C,groupTabOrders:c,updateGroupTabOrders:y,setGroupTabOrder:w,groupSizes:u,updateGroupSizes:k,isMobile:m,hasHydratedStoredLayout:f,hydrateStoredLayout:b,focusConversationTab:N}}function yI(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const n=e[0],a=oi(t);return typeof(n==null?void 0:n.id)=="string"&&a.includes(n.id)}function wI({urlActiveTab:e,conversations:t,resolveConversationBySessionId:n,normalizedGroupAssignments:a,hasHydratedStoredLayout:o,hydrateStoredLayout:r,focusConversationTab:i,setSearchParams:c,historyModalOpen:d,activeConv:u,isRefreshingHistory:p,ides:m,handleRefreshHistory:h}){const f=l.useRef(!1),x=l.useRef(!1),b=l.useRef(null),g=l.useRef(!1);l.useEffect(()=>{if(!e||f.current||t.length===0)return;if(!o){r();return}const S=n(e);S&&(i(S.tabKey,a),f.current=!0,x.current=!0,b.current!=null&&(window.clearTimeout(b.current),b.current=null),c(j=>{const y=new URLSearchParams(j);return y.delete("activeTab"),y},{replace:!0}))},[e,t,n,a,o,r,i,c]),l.useEffect(()=>{if(!(x.current||o)&&t.length!==0){if(!e){r(),x.current=!0;return}if(f.current){x.current=!0;return}if(b.current==null)return b.current=window.setTimeout(()=>{b.current=null,!(x.current||o)&&(r(),x.current=!0)},1500),()=>{b.current!=null&&(window.clearTimeout(b.current),b.current=null)}}},[e,t.length,o,r]),l.useEffect(()=>{if(!d){g.current=!1;return}if(!u||g.current||p)return;const S=m.find(j=>j.id===u.routeId);S&&(!S.chats||S.chats.length===0||yI(S.chats,u))&&(g.current=!0,h())},[d,u,p,m,h])}function Zi(e,t){if(!Array.isArray(e)||e.length!==1||!t)return!1;const n=e[0];if((n==null?void 0:n.active)===!0)return!0;const a=oi(t);return typeof(n==null?void 0:n.id)=="string"&&a.includes(n.id)}function dg({sendDaemonCommand:e,activeConv:t,chats:n,updateRouteChats:a,setToasts:o,setClearedTabs:r}){const[i,c]=l.useState(!1),[d,u]=l.useState(!1),p=l.useCallback(async x=>{try{await e("standalone","launch_ide",{ideType:x,enableCdp:!0})}catch(b){console.error("Launch failed",b)}},[e]),m=l.useCallback(async(x,b)=>{try{const g=x||(t==null?void 0:t.daemonId)||"",S=await e(g,"switch_chat",{id:b,sessionId:b,...gn(t)}),j=S==null?void 0:S.result;if((S==null?void 0:S.success)===!0||j==="switched"||j==="switched-by-title")return;j===!1||j==="not_found"?ia(o,"⚠️ Session tab not found — try refreshing history"):typeof j=="string"&&j.startsWith("error:")?ia(o,`⚠️ Switch error: ${j}`):ia(o,"⚠️ Session switch failed")}catch(g){console.error("Switch failed",g),ia(o,`❌ Switch failed: ${g.message||"connection error"}`)}},[t,e,o]),h=l.useCallback(async()=>{if(!(!t||i)){c(!0);try{const x=pn(t);await e(x,"new_chat",{...gn(t)}),hA(x,t.sessionId,oi(t)[0]),r(b=>({...b,[t.tabKey]:Date.now()}))}catch(x){console.error("New chat failed",x)}finally{c(!1)}}},[t,i,e,r]),f=l.useCallback(async()=>{var x,b;if(!(!t||d)){u(!0);try{const g=pn(t),S=async()=>e(g,"list_chats",{forceExpand:!0,...gn(t)});let j=await S(),y=(j==null?void 0:j.chats)||((x=j==null?void 0:j.result)==null?void 0:x.chats);Zi(y,t)&&(await new Promise(k=>setTimeout(k,450)),j=await S(),y=(j==null?void 0:j.chats)||((b=j==null?void 0:j.result)==null?void 0:b.chats)),j!=null&&j.success&&Array.isArray(y)&&(a(t.routeId,y),Zi(y,t)&&!Zi(n,t)&&ia(o,"⚠️ History dialog did not fully open — try once more"))}catch(g){console.error("Refresh history failed",g)}finally{u(!1)}}},[t,n,d,e,a,o]);return{isCreatingChat:i,isRefreshingHistory:d,handleLaunchIde:p,handleSwitchSession:m,handleNewChat:h,handleRefreshHistory:f}}function kI(e,t){if(e.size!==t.size)return!1;for(const[n,a]of e)if(t.get(n)!==a)return!1;return!0}function SI(e,t){return e.length!==t.length?!1:e.every((n,a)=>n===t[a])}function wp(e,t){const n=Object.keys(e),a=Object.keys(t);return n.length!==a.length?!1:n.every(o=>t[Number(o)]===e[Number(o)])}function qo(e,t){const n=new Set(t),a=t.length>0?[0]:[];for(const[i,c]of e)!n.has(i)||c<=0||a.includes(c)||a.push(c);a.sort((i,c)=>i-c);const o={};a.forEach((i,c)=>{o[i]=c}),a.length===0&&(o[0]=0);const r=new Map;for(const[i,c]of e){if(!n.has(i)||c<=0)continue;const d=o[c];typeof d=="number"&&d>0&&r.set(i,d)}return{assignments:r,groupCount:Math.max(1,a.length),mapping:o,usedGroups:a}}function kp(e,t){const n={};for(const[a,o]of Object.entries(e)){const r=t[Number(a)];typeof r=="number"&&(n[r]=o)}return n}function CI(e,t,n){if(t.length===0)return 0;if(typeof n[e]=="number")return n[e];const a=[...t].reverse().find(o=>o<e)??t[0];return n[a]??0}function jI(e,t,n){if(t.length<=1)return[];const a=t.map(i=>e[i]).filter(i=>Number.isFinite(i)),o=a.length===t.length?a:Array(n).fill(100/n),r=o.reduce((i,c)=>i+c,0);return r>0?o.map(i=>i/r*100):Array(n).fill(100/n)}function Sp(e,t){const n={};for(const[a,o]of Object.entries(e)){const r=Number(a);n[r>=t?r+1:r]=o}return n}function Cp(e){return Array(e).fill(100/e)}function NI({groupAssignments:e,updateGroupAssignments:t,updateFocusedGroup:n,updateGroupActiveTabIds:a,updateGroupTabOrders:o,groupSizes:r,updateGroupSizes:i,isMobile:c,visibleConversations:d,visibleTabKeys:u}){const p=l.useRef(null),m=l.useMemo(()=>qo(e,u),[e,u]),h=m.assignments,f=l.useMemo(()=>c?1:m.groupCount,[m.groupCount,c]),x=f>1,b=l.useCallback((v,C)=>{t(w=>{const N=new Map(qo(w,u).assignments);return C===0?N.delete(v):N.set(v,C),N}),a(w=>({...w,[C]:v})),n(C)},[t,u,a,n]),g=l.useCallback(v=>{t(C=>{const w=qo(C,u).assignments,N=new Map;for(const[T,A]of w)A!==v&&(A>v?N.set(T,A-1):N.set(T,A));return N}),i(C=>{if(C.length<=1)return[];const w=[...C];w.splice(v,1);const N=w.reduce((T,A)=>T+A,0);return N>0?w.map(T=>T/N*100):[]}),n(0)},[t,u,i,n]),S=l.useCallback((v,C)=>{C.preventDefault();const w=p.current;if(!w)return;const N=C.clientX,T=w.offsetWidth,A=r.length===f?[...r]:Cp(f),P=L=>{const R=(L.clientX-N)/T*100,_=[...A];_[v]=Math.max(15,A[v]+R),_[v+1]=Math.max(15,A[v+1]-R),i(_)},D=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",D),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",P),document.addEventListener("mouseup",D)},[r,f,i]),j=l.useCallback((v,C,w)=>{if(f>=4)return;const N=w==="left"?C:C+1;t(T=>{const A=qo(T,u).assignments,P=new Map;for(const D of d){const L=A.get(D.tabKey)??0,I=L>=N?L+1:L;I>0&&P.set(D.tabKey,I)}return N>0&&P.set(v,N),P}),i(T=>{const A=T.length===f?[...T]:Cp(f),P=A[C]??100/f,D=Math.max(15,P/2),L=Math.max(15,P/2),I=[...A];I[C]=D,I.splice(N,0,L);const R=I.reduce((_,M)=>_+M,0);return I.map(_=>_/R*100)}),a(T=>{const A=Sp(T,N);return A[N]=v,A}),o(T=>{const A=Sp(T,N);return A[N]=[v],A}),n(N)},[f,t,u,d,i,a,o,n]);l.useEffect(()=>{kI(e,h)||t(h)},[e,h,t]),l.useEffect(()=>{const{mapping:v,usedGroups:C}=m;a(w=>{const N=kp(w,v);return wp(w,N)?w:N}),o(w=>{const N=kp(w,v);return wp(w,N)?w:N}),n(w=>{const N=c?0:CI(w,C,v);return w===N?w:N}),i(w=>{const N=c?[]:jI(w,C,m.groupCount);return SI(w,N)?w:N})},[m,c,a,o,n,i]);const y=l.useMemo(()=>{const v=Array.from({length:f},()=>[]);for(const C of d){const w=h.get(C.tabKey)??0,N=Math.min(w,f-1);v[N].push(C)}return v},[d,h,f]),k=l.useCallback(()=>{t(new Map),n(0)},[t,n]);return{containerRef:p,normalizedGroupAssignments:h,numGroups:f,isSplitMode:x,groupedConvs:y,moveTabToGroup:b,closeGroup:g,handleResizeStart:S,splitTabRelative:j,clearAllSplits:k}}function el(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="stable"||t==="latest"?"stable":t==="preview"||t==="next"?"preview":null}function AI(e){if(typeof e!="string")return null;const t=e.trim().toLowerCase();return t==="latest"||t==="stable"?"latest":t==="next"||t==="preview"?"next":null}function Xa(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function hd(e){const t=e.updatePolicy&&typeof e.updatePolicy=="object"?e.updatePolicy:{},n=el(t.channel)||el(e.updateChannel)||el(e.releaseChannel)||void 0,a=AI(t.npmTag)||(n==="preview"?"next":n==="stable"?"latest":void 0),o=Xa(t.targetVersion)||Xa(e.serverVersion)||void 0,r=Xa(t.minVersion)||void 0,i=Xa(t.updateCommand)||(n?"adhdev update":void 0);return{...n?{channel:n}:{},...a?{npmTag:a}:{},...o?{targetVersion:o}:{},...r?{minVersion:r}:{},...i?{updateCommand:i}:{}}}function Dn(e,t=null){return hd(e).targetVersion||t}function TI(e){return hd(e).channel||null}function fd(e){return!e||!hd(e).channel?null:{}}function ug(e,t={}){const n=Xa(t.targetVersion);return n?`Update to v${n}`:t.fallback||(t.required?"Update now":"Upgrade")}function Hr(e){const t=e.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/);if(!t)return null;const n=t[4]??null;let a=null;if(n){const o=n.match(/(?:^|\.)(\d+)$/);a=o?Number(o[1]):null}return{base:[Number(t[1]),Number(t[2]),Number(t[3])],prereleaseNumber:a,isPrerelease:n!==null}}function jp(e){var t;return((t=Hr(e))==null?void 0:t.base)??null}function pg(e,t){const n=Hr(e),a=Hr(t);if(!n||!a)return e!==t;for(let o=0;o<3;o+=1){if(n.base[o]<a.base[o])return!0;if(n.base[o]>a.base[o])return!1}return n.isPrerelease&&a.isPrerelease?n.prereleaseNumber===null||a.prereleaseNumber===null?!1:n.prereleaseNumber<a.prereleaseNumber:!1}function gd(e,t){const n=e.version||null;return!n||!t||e.versionMismatch===!0&&!Hr(t)?!1:pg(n,t)}function hr(e,t){if(e.versionUpdateRequired===!0)return!0;const n=e.version||null;if(!n||!t||!pg(n,t))return!1;const a=jp(n),o=jp(t);return!a||!o?!1:a[0]!==o[0]||a[1]!==o[1]}function II({ides:e,sendDaemonCommand:t}){const n="1.0.59",a=l.useMemo(()=>e.filter(m=>m.type!=="adhdev-daemon"?!1:gd(m,Dn(m,n))).sort((m,h)=>Number(hr(h,Dn(h,n)))-Number(hr(m,Dn(m,n)))),[n,e]),o=l.useMemo(()=>a.some(m=>hr(m,Dn(m,n))),[n,a]),r=l.useMemo(()=>a.map(m=>Dn(m,n)).find(m=>typeof m=="string"&&m.trim().length>0)||n,[n,a]),[i,c]=l.useState(!1),[d,u]=l.useState({}),p=l.useCallback(async m=>{var x,b;const h=e.find(g=>g.id===m);if(!h)return;u(g=>({...g,[m]:"upgrading"}));const f=fd(h);if(!f){u(g=>({...g,[m]:"error"}));return}try{const g=await t(m,"daemon_upgrade",f);(x=g==null?void 0:g.result)!=null&&x.upgraded||(b=g==null?void 0:g.result)!=null&&b.success?u(S=>({...S,[m]:"done"})):u(S=>({...S,[m]:"error"}))}catch{u(g=>({...g,[m]:"error"}))}},[e,t]);return{versionMismatchDaemons:a,hasRequiredVersionDaemons:o,targetVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:c,upgradingDaemons:d,handleBannerUpgrade:p}}const mg=80;function fr(e,t=Date.now()){return typeof e=="number"&&Number.isFinite(e)?e:t}function PI(e){return{...e,createdAt:fr(e.createdAt),updatedAt:fr(e.updatedAt,e.createdAt),lastEventAt:fr(e.lastEventAt,e.updatedAt||e.createdAt)}}function LI(e){const t=Lh(e);return t==="unknown:"?e.id:t}function DI(e){return[e.type,Ph(e)||"",e.lastMessageHash||"",String(e.lastMessageAt||e.lastUpdated||0)].join("|")}function MI(e,t=mg){const n=new Map;for(const a of e){if(a.deletedAt)continue;const o=LI(a),r=n.get(o);if(!r){n.set(o,a);continue}(a.updatedAt>r.updatedAt||a.updatedAt===r.updatedAt&&a.createdAt>r.createdAt)&&n.set(o,a)}return Array.from(n.values()).sort((a,o)=>{const r=o.updatedAt-a.updatedAt;return r!==0?r:o.createdAt-a.createdAt}).slice(0,Math.max(0,t))}function RI(e,t){const n=Date.now(),a=[];for(const o of e){const r=o.sessionId?t.get(o.sessionId):void 0;if(r!=null&&r.surfaceHidden||r!=null&&r.muted)continue;const i=ai(o,t),c=i.inboxBucket==="needs_attention"?"needs_attention":i.inboxBucket==="task_complete"&&i.unread?"task_complete":null;if(!c)continue;const d=fr(o.lastMessageAt||(r==null?void 0:r.lastUpdated)||o.lastUpdated,n),u=DI({type:c,sessionId:o.sessionId,providerSessionId:o.providerSessionId,tabKey:o.tabKey,lastMessageHash:o.lastMessageHash,lastMessageAt:o.lastMessageAt,lastUpdated:(r==null?void 0:r.lastUpdated)||o.lastUpdated});a.push(PI({id:u,dedupKey:u,type:c,routeId:o.routeId,machineId:o.daemonId||o.routeId,sessionId:o.sessionId,providerSessionId:o.providerSessionId,tabKey:o.tabKey,title:af(o),preview:iN(o),createdAt:d,updatedAt:d,lastEventAt:d}))}return MI(a)}function _I(e){return e.filter(t=>!t.readAt&&!t.deletedAt).length}function EI(e){const{conversations:t,liveSessionInboxState:n,maxItems:a=mg}=e,o=l.useMemo(()=>RI(t,n).slice(0,Math.max(0,a)),[t,n,a]),r=l.useMemo(()=>_I(o),[o]);return{notifications:o,unreadCount:r}}function HI({notifications:e,sendDaemonCommand:t}){const n=l.useCallback(r=>{const i=e.find(d=>d.id===r),c=Math.max(Date.now(),(i==null?void 0:i.updatedAt)||0);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_session_seen",{sessionId:i.sessionId,seenAt:c}).catch(()=>{})},[e,t]),a=l.useCallback(r=>{const i=e.find(c=>c.id===r);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"mark_notification_unread",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]),o=l.useCallback(r=>{const i=e.find(c=>c.id===r);i!=null&&i.sessionId&&t(i.machineId||i.routeId,"delete_notification",{sessionId:i.sessionId,notificationId:i.id}).catch(()=>{})},[e,t]);return{handleMarkDashboardNotificationRead:n,handleMarkDashboardNotificationUnread:a,handleDeleteDashboardNotification:o}}function bd(...e){const t=new Set,n=[],a=o=>{const r=typeof o=="string"?o.trim():"";if(!r)return;const i=r.toLowerCase();t.has(i)||(t.add(i),n.push(r))};for(const o of e){if(Array.isArray(o)){for(const r of o)a(r);continue}a(o)}return n}function FI(e){const t=e.trim();if(!t)return null;if(t.startsWith("~"))return t;if(/^[A-Za-z]:$/.test(t))return`${t[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(t))return`${t[0].toUpperCase()}:${t.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(t))return`${t[0].toUpperCase()}:\\${t.slice(2).replace(/[\\/]+/g,"\\")}`;const n=t.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(n){const a=n[1].toUpperCase(),o=(n[2]||"").replace(/[\\/]+/g,"\\");return o?`${a}:\\${o}`:`${a}:\\`}return null}function xd(e,t=[]){if(e==="win32"){for(const n of t){if(typeof n!="string")continue;const a=FI(n);if(a)return a}return"C:\\"}for(const n of t){const a=typeof n=="string"?n.trim():"";if(a)return a}return"~"}function $I(e){const t=e.replace(/[\\/]+$/,"");if(!t||t==="/"||/^[A-Za-z]:$/.test(t))return null;const n=t.includes("\\")?"\\":"/",a=t.split(/[\\/]/);return/^[A-Za-z]:$/.test(a[0]||"")?a.length<=2?`${a[0]}\\`:a.slice(0,-1).join("\\"):a.length<=2?n:a.slice(0,-1).join(n)||n}function BI(e){return e!=null&&e.result&&typeof e.result=="object"&&"success"in e.result?e.result:e}async function vd(e,t,n){const a=await e(t,"file_list_browse",{path:n}),o=BI(a);if(!(o!=null&&o.success))throw new Error((o==null?void 0:o.error)||(a==null?void 0:a.error)||"Could not browse folder");const r=typeof(o==null?void 0:o.path)=="string"?o.path:n,i=r.includes("\\")?"\\":"/",c=(u,p)=>/^[A-Za-z]:\\?$/.test(u)?`${u.replace(/\\?$/,"\\")}${p}`:u==="/"||u==="\\"?`${i}${p}`:`${u.replace(/[\\/]+$/,"")}${i}${p}`,d=Array.isArray(o==null?void 0:o.files)?o.files.filter(u=>(u==null?void 0:u.type)==="directory"&&typeof(u==null?void 0:u.name)=="string").map(u=>({name:u.name,path:typeof(u==null?void 0:u.path)=="string"&&u.path.trim()?u.path:c(r,u.name)})).sort((u,p)=>u.name.localeCompare(p.name)):[];return{path:r,directories:d}}function Np(e,t){const n=t.meshId||"",a={meshId:n,workspace:t.workspace||"",serverName:t.serverName||"adhdev-mesh",adhdevMcpCommand:t.adhdevMcpCommand||"adhdev-mcp",adhdevMcpArgs:t.adhdevMcpArgs||`mcp --mode ipc --repo-mesh ${n}`};return e.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand|adhdevMcpArgs)\s*\}\}/g,(o,r)=>a[r]||"")}function hg(e,t={}){const n=e==null?void 0:e.mcpConfig;if((n==null?void 0:n.mode)!=="manual")return null;const o=Np(n.template||"",{...t,serverName:n.serverName||"adhdev-mesh"}).trim();return!o.includes(`
|
|
52
|
-
`)&&!o.startsWith("{")?null:{serverName:n.serverName||"adhdev-mesh",configFormat:n.format,configPathCommand:n.configPathCommand,requiresRestart:n.requiresRestart===!0,instructions:n.instructions||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:Np(n.template||"",{...t,serverName:n.serverName||"adhdev-mesh"})}}function WI(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.instructions=="string"?t.instructions:"",a=typeof t.template=="string"?t.template:"";return!n&&!a?null:{serverName:typeof t.serverName=="string"?t.serverName:void 0,configFormat:typeof t.configFormat=="string"?t.configFormat:void 0,configPathCommand:typeof t.configPathCommand=="string"?t.configPathCommand:void 0,requiresRestart:t.requiresRestart===!0,instructions:n||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:a}}function go(e){return`/dashboard?activeTab=${encodeURIComponent(e)}`}function fg(e){return ri(e)||e.tabKey||e.routeId||null}function gg(e){const t=typeof e.entrySessionId=="string"?e.entrySessionId.trim():"",n=typeof e.entryInstanceId=="string"?e.entryInstanceId.trim():"",a=typeof e.entryRouteId=="string"?e.entryRouteId.trim():"",o=e.conversations.find(r=>{if(a&&r.routeId!==a)return!1;const i=[r.providerSessionId,r.sessionId,r.nativeSessionId,r.tabKey].map(c=>typeof c=="string"?c.trim():"").filter(Boolean);return!!(t&&i.includes(t)||n&&i.includes(n)||a&&r.routeId===a)});if(o!=null&&o.tabKey)return o.tabKey;if(a){const r=_s(e.conversations,a)||e.conversations.find(i=>i.routeId===a);if(r!=null&&r.tabKey)return r.tabKey}return t||n||a||null}function cn(e){return String(e||"").trim()}function bg(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function Fr(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function OI(e,t){return!e||!t?!1:e===t||e.endsWith(`/${t}`)||t.endsWith(`/${e}`)}function UI(e,t){const n=cn(e.providerSessionId),a=cn(e.targetSessionId),o=t.find(r=>{const i=[r.providerSessionId,r.sessionId,r.nativeSessionId,r.tabKey,r.routeId].map(cn).filter(Boolean);return!!(n&&i.includes(n)||a&&i.includes(a))});return o?o.tabKey:a||n||null}function qI(e,t,n){if(t.event!=="agent:generating_completed")return null;const a=bg(t.daemonId);if(a&&a!==e.machineId)return null;const o=cn(t.providerType);if(e.providerType&&o!==e.providerType)return null;const r=cn(e.resumeSessionId),i=cn(e.launchedSessionId),c=cn(t.providerSessionId),d=cn(t.targetSessionId);if(r&&r!==c&&r!==d||i&&i!==c&&i!==d)return null;const u=Fr(e.workspacePath);if(u){const p=Fr(t.workspaceName);if(p&&!OI(p,u))return null}return UI(t,n)}function Ap(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function zI({ides:e,conversations:t,onOpenSession:n}){const[a,o]=l.useState(null),r=l.useRef(null),i=l.useCallback(()=>{r.current=null,o(null)},[]),c=l.useCallback(d=>{r.current=d,o(d)},[]);return l.useEffect(()=>{if(!a)return;const d=Fr(a.workspacePath),u=e.find(m=>{var g,S,j,y;if(!m||m.type==="adhdev-daemon"||bg(m.daemonId||m.id)!==a.machineId||(mo(m)?"cli":ha(m)?"acp":"ide")!==a.kind)return!1;const x=String(m.agentType||m.type||"");if(a.providerType&&x!==a.providerType)return!1;if(a.resumeSessionId)return String(m.providerSessionId||"")===a.resumeSessionId;if(a.launchedSessionId){const k=String(a.launchedSessionId||"");return[m.providerSessionId,m.sessionId,m.instanceId,m.id].map(C=>String(C||"")).filter(Boolean).includes(k)}if(d){const k=Fr(m.workspace||m.runtimeWorkspaceLabel);return k?k===d:!1}return Number(m.lastUpdated||m._lastUpdate||m.timestamp||((y=(j=(S=(g=m.activeChat)==null?void 0:g.messages)==null?void 0:S.at)==null?void 0:j.call(S,-1))==null?void 0:y.timestamp)||0)>=a.startedAt-5e3});if(!u)return;const p=gg({entrySessionId:u.sessionId,entryInstanceId:u.instanceId,entryRouteId:u.id,conversations:t});p&&(i(),n(p))},[i,t,e,n,a]),l.useEffect(()=>ft.onStatusEvent(d=>{const u=r.current;if(!u)return;const p=qI(u,d,t);p&&(i(),n(p))}),[i,t,n]),l.useEffect(()=>{if(!a)return;const d=window.setTimeout(()=>{o(u=>!u||u.startedAt!==a.startedAt?u:(r.current=null,null))},45e3);return()=>window.clearTimeout(d)},[a]),{trackPendingLaunch:c}}function GI(e,t){var a,o,r,i;const n={cliType:e};return(a=t==null?void 0:t.workspacePath)!=null&&a.trim()?n.dir=t.workspacePath.trim():t!=null&&t.workspaceId?n.workspaceId=t.workspaceId:t!=null&&t.useHome&&(n.useHome=!0),(o=t==null?void 0:t.resumeSessionId)!=null&&o.trim()&&(n.resumeSessionId=t.resumeSessionId.trim()),Array.isArray(t==null?void 0:t.cliArgs)&&t.cliArgs.length>0&&(n.cliArgs=t.cliArgs),(r=t==null?void 0:t.initialModel)!=null&&r.trim()&&(n.initialModel=t.initialModel.trim()),(i=t==null?void 0:t.initialThinkingLevel)!=null&&i.trim()&&(n.initialThinkingLevel=t.initialThinkingLevel.trim()),t!=null&&t.settings&&(n.settings=t.settings),n}function KI(e,t,n){var i,c,d,u;const a={meshId:e.trim()};t.trim()&&(a.cliType=t.trim());const o=(i=n==null?void 0:n.initialModel)==null?void 0:i.trim(),r=(c=n==null?void 0:n.initialThinkingLevel)==null?void 0:c.trim();return o&&(a.initialModel=o),r&&(a.initialThinkingLevel=r),(d=n==null?void 0:n.settings)!=null&&d.autoApproveMode?a.autoApproveMode=n.settings.autoApproveMode:typeof((u=n==null?void 0:n.settings)==null?void 0:u.autoApprove)=="boolean"&&(a.autoApprove=n.settings.autoApprove),a}function VI({sendDaemonCommand:e,trackPendingLaunch:t,onOpenSession:n,activeConv:a,ides:o,setCliViewModeOverrides:r}){const i=ci(),{launchCli:c}=ei(),d=l.useCallback(async(g,S)=>vd(e,g,S),[e]),u=l.useCallback(async(g,S)=>{if(!S.trim())return{ok:!1,error:"Choose a workspace path first."};try{const j=await e(g,"workspace_add",{path:S.trim()});return j!=null&&j.success?{ok:!0}:{ok:!1,error:(j==null?void 0:j.error)||"Could not save workspace"}}catch(j){return{ok:!1,error:j instanceof Error?j.message:"Could not save workspace"}}},[e]),p=l.useCallback(async(g,S,j)=>{var y;try{const k={ideType:S,enableCdp:!0};(y=j==null?void 0:j.workspacePath)!=null&&y.trim()&&(k.workspace=j.workspacePath.trim());const v=await e(g,"launch_ide",k);return!(v!=null&&v.success)&&(v==null?void 0:v.success)!==void 0?{ok:!1,error:(v==null?void 0:v.error)||"Could not launch IDE"}:(t({machineId:g,kind:"ide",providerType:S,workspacePath:(j==null?void 0:j.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(k){return{ok:!1,error:k instanceof Error?k.message:"Could not launch IDE"}}},[e,t]),m=l.useCallback(async(g,S,j,y)=>{const k=Date.now();try{const v=GI(j,y),C=await c(g,v),w=(C==null?void 0:C.result)||C,N=(w==null?void 0:w.sessionId)||(w==null?void 0:w.id);return C!=null&&C.success&&N?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,launchedSessionId:N,startedAt:k}),{ok:!0}):C!=null&&C.success?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,startedAt:k}),{ok:!0}):{ok:!1,error:(C==null?void 0:C.error)||(w==null?void 0:w.error)||`Could not launch ${S.toUpperCase()} session`,code:(C==null?void 0:C.code)||(w==null?void 0:w.code)||void 0}}catch(v){return Ap(v)?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,startedAt:k}),{ok:!0}):{ok:!1,error:v instanceof Error?v.message:`Could not launch ${S.toUpperCase()} session`}}},[c,e,t]),h=l.useCallback(async g=>{var S;if(i!=null&&i.listMeshes)return i.listMeshes(g);if(!g)return[];try{const j=await e(g,"list_meshes",{}),y=(j==null?void 0:j.result)??j;if((y==null?void 0:y.success)===!1)throw new Error((y==null?void 0:y.error)||"Could not load meshes");return(Array.isArray(y==null?void 0:y.meshes)?y.meshes:Array.isArray((S=y==null?void 0:y.result)==null?void 0:S.meshes)?y.result.meshes:[]).map(v=>{var C;return{id:String((v==null?void 0:v.id)||""),name:String((v==null?void 0:v.name)||(v==null?void 0:v.id)||"Untitled mesh"),repoIdentity:(v==null?void 0:v.repoIdentity)||(v==null?void 0:v.repo_identity)||null,workspace:Array.isArray(v==null?void 0:v.nodes)&&v.nodes.length>0?String(((C=v.nodes[0])==null?void 0:C.workspace)||""):null,nodesCount:Array.isArray(v==null?void 0:v.nodes)?v.nodes.length:void 0,status:(v==null?void 0:v.status)||null}}).filter(v=>v.id)}catch(j){throw console.error("List meshes failed",j),j}},[i,e]),f=l.useCallback(async(g,S,j,y)=>{if(!S.trim())return{ok:!1,error:"Choose a mesh first."};if(i!=null&&i.launchMeshCoordinator)return i.launchMeshCoordinator(g,S,j,y);const k=Date.now();try{const v=KI(S,j,y),C=await e(g,"launch_mesh_coordinator",v),w=(C==null?void 0:C.result)??C;if((w==null?void 0:w.success)===!1||(C==null?void 0:C.success)===!1){const T=String((w==null?void 0:w.code)||(C==null?void 0:C.code)||""),A=WI((w==null?void 0:w.meshCoordinatorSetup)||(w==null?void 0:w.manualSetup)||(C==null?void 0:C.meshCoordinatorSetup)||(C==null?void 0:C.manualSetup));return{ok:!1,error:(w==null?void 0:w.error)||(C==null?void 0:C.error)||"Could not launch mesh coordinator",code:T||void 0,manualSetup:A}}const N=(w==null?void 0:w.sessionId)||(w==null?void 0:w.id);return N?n(N):t({machineId:g,kind:"cli",providerType:(w==null?void 0:w.cliType)||j.trim()||void 0,workspacePath:(w==null?void 0:w.workspace)||null,startedAt:k}),{ok:!0}}catch(v){return Ap(v)?(t({machineId:g,kind:"cli",providerType:j.trim()||void 0,startedAt:k}),{ok:!0}):{ok:!1,error:v instanceof Error?v.message:"Could not launch mesh coordinator"}}},[i,n,e,t]),x=l.useCallback(async(g,S)=>{if(!g||!S)return[];try{const j=await e(g,"list_saved_sessions",{providerType:S,kind:"cli",limit:30}),y=(j==null?void 0:j.result)??j;return Array.isArray(y==null?void 0:y.sessions)?y.sessions:[]}catch(j){return console.error("List saved sessions failed",j),[]}},[e]),b=l.useCallback(async g=>{await ag({conversation:a,mode:g,ides:o,sendDaemonCommand:e,setCliViewModeOverrides:r})},[a,o,e,r]);return{handleBrowseMachineDirectory:d,handleSaveMachineWorkspace:u,handleLaunchMachineIde:p,handleLaunchMachineProvider:m,handleListMachineMeshes:h,handleLaunchMeshCoordinator:f,handleListMachineSavedSessions:x,setActiveCliViewMode:b}}function YI(e){switch(e){case"notification-open":case"toast-open":case"conversation-open":case"requested-tab":return!0;case"dockview-shortcut":case"dockview-focus":case"dockview-move":case"dockview-split":case"stored-layout-restore":case"passive-tab-sync":return!1;default:return!1}}function QI(e,t,n=Date.now()){return!e||!YI(t)?null:{tabKey:e,nonce:n}}function JI({isMobile:e,conversations:t,visibleConversations:n,groupActiveTabIds:a,focusedGroup:o,groupedConvs:r,setSearchParams:i}){const[c,d]=l.useState(null),[u,p]=l.useState(null),m=l.useMemo(()=>{var g,S;if(!e){if(c){const j=t.find(y=>y.tabKey===c);if(j)return j}return n[0]}const b=a[o];if(b){const j=t.find(y=>y.tabKey===b);if(j)return j}return((g=r[o])==null?void 0:g[0])||((S=r[0])==null?void 0:S[0])},[t,c,o,a,r,e,n]),h=l.useCallback(b=>{d(b)},[]),f=l.useCallback(b=>{d(b.tabKey),i(g=>{const S=new URLSearchParams(g),j=cN(b);return j?S.set("activeTab",j):S.delete("activeTab"),S},{replace:!0})},[i]),x=l.useCallback((b,g)=>{const S=QI(b,g);S&&p(S)},[]);return{activeConv:m,openDesktopConversation:f,requestScrollToBottom:x,scrollToBottomRequest:u,setDesktopActiveTab:h}}function XI(e){const t=e.completedKey||null,n=e.pendingKey||null;return e.shouldMarkSeen?t===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:n!==null&&n!==e.autoReadKey,nextPendingKey:n===e.autoReadKey?n:null}:n===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:!1,nextPendingKey:n}:{shouldSchedule:!0,shouldCancelPending:n!==null&&n!==e.autoReadKey,nextPendingKey:e.autoReadKey}:{shouldSchedule:!1,shouldCancelPending:!!n,nextPendingKey:null}}function ZI(e){const t=String(e.liveState.completionMarker||""),n=String(e.liveState.seenCompletionMarker||""),a=String(e.liveState.inboxBucket||"idle"),o=!!e.liveState.unread,r=[e.tabKey,e.historySessionId||"",t,n,a,o?"1":"0"].join(":");return{shouldMarkSeen:!!(a==="task_complete"&&o&&(!t||t!==n)),autoReadKey:r,completionMarker:t,readAt:Math.max(Date.now(),e.timestamp||0,e.liveState.lastUpdated||0)}}function eP({activeConv:e,isMobile:t,liveSessionInboxState:n,sendDaemonCommand:a}){const o=l.useRef(null),r=l.useRef(null),i=l.useRef(null),c=l.useRef(null),d=l.useRef(null);l.useEffect(()=>{const u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(clearTimeout(c.current),c.current=null),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null),r.current=null};if(t){u(),o.current=null;return}if(!(e!=null&&e.sessionId)){u(),o.current=null;return}const p=yn(e,n),m=ZI({tabKey:e.tabKey,historySessionId:ri(e)||"",lastMessageHash:e.lastMessageHash||"",lastMessageAt:Number(e.lastMessageAt||0),timestamp:Bn(e),liveState:p}),h=m.autoReadKey,f=XI({autoReadKey:h,shouldMarkSeen:m.shouldMarkSeen,completedKey:o.current,pendingKey:r.current});if(!m.shouldMarkSeen){f.shouldCancelPending&&u(),o.current=h;return}if(!f.shouldSchedule)return;f.shouldCancelPending&&u();const x=()=>{if(document.visibilityState!=="visible"||o.current===h)return;o.current=h,r.current=null,i.current=null,c.current=null,d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null);const g=m.readAt;a(e.daemonId||e.routeId,"mark_session_seen",{sessionId:e.sessionId,providerSessionId:e.providerSessionId,seenAt:g,completionMarker:m.completionMarker}).catch(()=>{})};if(r.current=f.nextPendingKey,document.visibilityState==="visible"){i.current=setTimeout(x,1500);const g=()=>{document.visibilityState!=="visible"&&i.current&&(clearTimeout(i.current),i.current=null)};d.current=g,document.addEventListener("visibilitychange",g);return}const b=()=>{document.visibilityState==="visible"&&(c.current&&clearTimeout(c.current),c.current=setTimeout(x,800),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null))};d.current=b,document.addEventListener("visibilitychange",b)},[e,t,n,a]),l.useEffect(()=>()=>{i.current&&clearTimeout(i.current),c.current&&clearTimeout(c.current),d.current&&document.removeEventListener("visibilitychange",d.current)},[])}function tl(e){if(!e)return"";const t=String(e.workspacePath||"").trim();if(t)return t;const n=String(e.workspaceName||"").trim();return/^(?:~\/|\/|[A-Za-z]:[\\/])/.test(n)?n:""}function tP({activeConv:e,remoteDialogConv:t,remoteDialogActiveConv:n,ides:a,sendDaemonCommand:o,updateRouteChats:r,setToasts:i,setClearedTabs:c,setSearchParams:d}){var $;const{launchCli:u}=ei(),[p,m]=l.useState(!1),[h,f]=l.useState([]),[x,b]=l.useState(()=>as()),[g,S]=l.useState(!1),[j,y]=l.useState(null),k=l.useRef(null),v=l.useMemo(()=>n||t||e,[e,n,t]),C=!!v&&vt(v)&&!gt(v),w=l.useMemo(()=>{if(!v||!C)return null;const V=v.daemonId||v.routeId||"",z=qs(v),W=tl(v);return`${V}:${z}:${v.providerSessionId||""}:${W}`},[v,C]),N=l.useMemo(()=>!v||!C?"":tl(v),[v,C]),{isCreatingChat:T,isRefreshingHistory:A,handleSwitchSession:P,handleNewChat:D,handleRefreshHistory:L}=dg({sendDaemonCommand:o,activeConv:v,chats:($=a.find(V=>V.id===(v==null?void 0:v.routeId)))==null?void 0:$.chats,updateRouteChats:r,setToasts:i,setClearedTabs:c}),I=l.useCallback(()=>{m(!0)},[]),R=l.useCallback(()=>{m(!1)},[]),_=l.useCallback(async()=>{if(!(!v||!C||g)){S(!0);try{const V=v.daemonId||v.routeId,z=qs(v),W=tl(v),F=await o(V,"list_saved_sessions",{agentType:z,providerType:z,kind:"cli",limit:50,...v.providerSessionId?{providerSessionId:v.providerSessionId}:{},...W?{workspace:W}:{}}),B=(F==null?void 0:F.result)??F;f(Array.isArray(B==null?void 0:B.sessions)?B.sessions:[])}catch(V){console.error("Refresh saved sessions failed",V),f([])}finally{S(!1)}}},[v,g,C,o]);l.useEffect(()=>{if(!p){k.current=null;return}if(!C){k.current=null,f([]),S(!1);return}!w||g||k.current!==w&&(k.current=w,_())},[_,p,g,C,w]);const M=l.useCallback(async V=>{if(!v||!C||!V.providerSessionId||!V.workspace)return;const z=v.daemonId||v.routeId,W=qs(v);try{y(V.providerSessionId);const F=await u(z,{cliType:W,dir:V.workspace,resumeSessionId:V.providerSessionId,initialModel:_h(V.summaryMetadata,"model",{preferShortValue:!0})||void 0}),B=(F==null?void 0:F.result)??F,E=typeof(B==null?void 0:B.sessionId)=="string"?B.sessionId:typeof(B==null?void 0:B.id)=="string"?B.id:"";E&&d(H=>{const J=new URLSearchParams(H);return J.set("activeTab",E),J},{replace:!0}),R()}catch(F){console.error("Resume saved session failed",F)}finally{y(null)}},[R,v,C,o,d]);return{historyModalOpen:p,openHistoryModal:I,closeHistoryModal:R,historyTargetConv:v,isSavedSessionHistoryTarget:C,isHistoryCreatingChat:T,isHistoryRefreshingHistory:A,handleHistorySwitchSession:P,handleHistoryNewChat:D,handleHistoryRefresh:L,savedHistorySessions:h,savedHistoryFilters:x,setSavedHistoryFilters:b,missingWorkspaceResumePath:N,isSavedHistoryLoading:g,resumingSavedHistorySessionId:j,handleRefreshSavedHistory:_,handleResumeSavedHistorySession:M}}function sP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c}){const[d,u]=l.useState(null),[p,m]=l.useState(null),h=l.useMemo(()=>{if(e||!a)return null;const S=c(a);return S&&!vt(S)&&!gt(S)?S:null},[e,a,c]),f=l.useMemo(()=>{const S=d==null?void 0:d.routeId;if(!S)return null;const j=d!=null&&d.tabKey?r.find(y=>y.tabKey===d.tabKey):o?r.find(y=>y.tabKey===o):null;return(j==null?void 0:j.routeId)===S?j:_s(r,S)},[r,d,o]),x=l.useMemo(()=>{if(f)return i.find(S=>S.id===f.routeId)},[i,f]);l.useEffect(()=>{h&&(u({routeId:h.routeId,tabKey:Pu(h)}),m(h),n({pathname:t.pathname,search:t.search},{replace:!0,state:null}))},[t.pathname,t.search,n,h]);const b=l.useCallback(S=>{S&&(u({routeId:S.routeId,tabKey:Pu(S)}),m(S))},[]),g=l.useCallback(()=>{u(null),m(null)},[]);return{remoteDialogConv:f,remoteDialogIdeEntry:x,remoteDialogActiveConv:p,setRemoteDialogActiveConv:m,openRemoteDialog:b,closeRemoteDialog:g}}function nP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c,activeConv:d,sendDaemonCommand:u}){const{remoteDialogConv:p,remoteDialogIdeEntry:m,remoteDialogActiveConv:h,setRemoteDialogActiveConv:f,openRemoteDialog:x,closeRemoteDialog:b}=sP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c}),[g,S]=l.useState(!1),[j,y]=l.useState(null),k=l.useCallback(async w=>{const N=w||d;!N||!vt(N)&&!gt(N)||(y(N),S(!0))},[d]),v=l.useCallback(()=>{S(!1),y(null)},[]),C=l.useCallback(async w=>{const N=j||d;if(!N||!vt(N)&&!gt(N)){v();return}S(!1);try{const T=qs(N),A=N.routeId||N.daemonId||"";await u(A,"stop_cli",{cliType:T,targetSessionId:N.sessionId,mode:w,...ui(N)})}catch(T){console.error("Stop CLI failed:",T)}finally{y(null)}},[d,v,j,u]);return{remoteDialogConv:p,remoteDialogIdeEntry:m,remoteDialogActiveConv:h,setRemoteDialogActiveConv:f,openRemoteDialog:x,closeRemoteDialog:b,cliStopDialogOpen:g,cliStopTargetConv:j,requestCliStop:k,cancelCliStop:v,confirmCliStop:C}}function sl(e,t=!0){return(e??!0)&&t}const yd=l.memo(function({activeConv:t,clearToken:n,isCliTerminal:a,ideEntry:o,terminalRef:r,commands:i,actionLogs:c,userName:d,scrollToBottomRequestNonce:u,isInputActive:p=!0,isVisible:m=!0}){const{handleModalButton:h,handleRelaunch:f,handleSendChat:x,handleSendNowQueued:b,handleCancelQueued:g,isSendingChat:S,sendFeedbackMessage:j,pendingLocalMessage:y,pendingLocalMessages:k,retireEchoedPendingMessages:v,handleFocusAgent:C,isFocusingAgent:w}=i,N=a,T=!a,A=sl(m,N),P=sl(m,T),D=sl(m),L=sg(t),I=L.status||L.modalMessage||L.modalButtons?{...t,...L.status?{status:L.status}:{},...L.modalMessage!==void 0?{modalMessage:L.modalMessage}:{},...L.modalButtons!==void 0?{modalButtons:L.modalButtons}:{}}:t,R=_=>s.jsx(Tf,{activeConv:I,ideEntry:o,handleSendChat:x,handleSendNowQueued:b,handleCancelQueued:g,isSendingChat:S,sendFeedbackMessage:j,pendingLocalMessage:y,pendingLocalMessages:k,retireEchoedPendingMessages:v,handleFocusAgent:C,isFocusingAgent:w,actionLogs:c,userName:d,scrollToBottomRequestNonce:u,isInputActive:p&&_,isVisible:_});return s.jsxs(s.Fragment,{children:[s.jsx(Ah,{activeConv:I,onModalButton:h}),I.transport!=="pty"&&I.transport!=="acp"&&I.cdpConnected===!1?s.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[s.jsx("span",{className:"text-sm",children:s.jsx(ds,{size:14})}),s.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),s.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-3xs whitespace-nowrap shrink-0",onClick:f,children:"Relaunch with CDP"})]})}):null,I.transport==="pty"?s.jsxs("div",{style:{position:"relative",minHeight:0,flex:"1 1 0%",width:"100%",overflow:"hidden"},children:[s.jsx("div",{"aria-hidden":!a,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:N?"visible":"hidden",pointerEvents:N?"auto":"none"},children:s.jsx(g1,{activeConv:I,clearToken:n,terminalRef:r,handleSendChat:x,isSendingChat:S,sendFeedbackMessage:j,isVisible:A,isInputActive:p&&A})}),s.jsx("div",{"aria-hidden":a,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:T?"visible":"hidden",pointerEvents:T?"auto":"none"},children:R(P)})]}):R(D)]})},(e,t)=>e.activeConv===t.activeConv&&e.isCliTerminal===t.isCliTerminal&&e.ideEntry===t.ideEntry&&e.terminalRef===t.terminalRef&&e.commands===t.commands&&e.actionLogs===t.actionLogs&&e.userName===t.userName&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isInputActive===t.isInputActive&&e.isVisible===t.isVisible);function aP({conversation:e,className:t="",onOpenNativeConversation:n,onOpenMachine:a,interactive:o=!0,meshOnly:r=!1}){var k,v,C;const{t:i}=ye("common"),c=Qn(),d=sn(e),u=r?null:nf(e),p=!r&&(e.transport==="cdp-page"||e.transport==="cdp-webview"),m=!r&&e.streamSource==="agent-stream"&&!!e.agentName,h=!r&&!m&&(e.transport==="pty"||e.transport==="acp"),f=ya(e),x=lN(e),b=(k=e.settings)==null?void 0:k.meshNodeFor,g=e.meshQueueStats,S=((v=e.coordinator)==null?void 0:v.meshId)||((C=e.settings)==null?void 0:C.meshCoordinatorFor),j=l.useCallback(()=>{if(a){a();return}d&&c("/dashboard",{state:{openMachineId:d}})},[d,c,a]),y=l.useCallback(()=>{if(n){n();return}const w=fg(e);w&&c(go(w))},[e,c,n]);return!p&&!m&&!h&&!u&&!b&&!g?null:s.jsxs("div",{className:`conversation-meta-chips ${t}`.trim(),children:[p&&(o?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:y,title:x,children:[s.jsx(Es,{size:12}),s.jsx("span",{children:x})]}):s.jsxs("span",{className:"conversation-meta-chip",title:x,children:[s.jsx(Es,{size:12}),s.jsx("span",{children:x})]})),m&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(xa,{size:12}),s.jsx("span",{children:f})]}),h&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(xa,{size:12}),s.jsx("span",{children:f})]}),u&&(o?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:j,title:u,children:[s.jsx(hn,{size:12}),s.jsx("span",{children:u})]}):s.jsxs("span",{className:"conversation-meta-chip",title:u,children:[s.jsx(hn,{size:12}),s.jsx("span",{children:u})]})),b&&s.jsxs("span",{className:"conversation-meta-chip",title:"Mesh node",children:[s.jsx(hn,{size:12}),s.jsx("span",{children:i("dashboard.metaChips.meshNode")})]}),S&&g&&s.jsxs("span",{className:`conversation-meta-chip ${g.pending>0?"is-active":""}`,style:g.failed>0?{color:"var(--color-red-400)",borderColor:"var(--color-red-400)"}:void 0,title:`Queue: ${g.pending} pending, ${g.assigned} assigned, ${g.completed} completed, ${g.failed} failed`,children:[s.jsx(ev,{size:12}),s.jsxs("span",{children:[g.pending," Pending"]})]})]})}function oP({selectedConversation:e,isAcp:t,isStandalone:n,selectedIdeEntry:a,actionLogs:o,userName:r,commands:i,onBack:c,onOpenNativeConversation:d,onOpenMachine:u,onOpenHistory:p,onOpenRemote:m,onOpenMeshGraph:h,onStopCli:f,cliViewMode:x,onSetCliViewMode:b}){var v,C;const g=l.useRef(null),S=vt(e)&&!t,j=S&&x==="terminal",y=!!e.daemonId&&!!((v=e.coordinator)!=null&&v.meshId||(C=e.settings)!=null&&C.meshCoordinatorFor),k=n?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center justify-between gap-3 ${k} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:c,type:"button","aria-label":"Back",children:s.jsx(Bc,{size:18})}),s.jsxs("div",{className:"min-w-0 flex-1 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] leading-[26px] font-extrabold tracking-tight text-text-primary truncate",children:At(e)}),s.jsx("div",{className:"min-w-0 max-w-full text-xs text-text-secondary",children:s.jsx(aP,{conversation:e,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>d(e),onOpenMachine:()=>u(e)})})]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S&&x&&s.jsx(Ef,{mode:x,onChange:b,compact:!0}),S&&f&&s.jsx("button",{onClick:()=>{f(e)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(Wt,{size:14})}),y&&h&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(e),type:"button",title:"Open live repo mesh graph","aria-label":"Open live repo mesh graph",children:s.jsx(js,{size:14})}),s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(e),type:"button",children:s.jsx(Wc,{size:14})}),!t&&!S&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(e),type:"button",children:s.jsx(Es,{size:14})})]})]}),s.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:s.jsx(yd,{activeConv:e,clearToken:0,isCliTerminal:j,ideEntry:a,terminalRef:g,commands:i,actionLogs:o,userName:r})})]})}function rP(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function xg({isStandalone:e=!1}={}){const[t,n]=l.useState("unix"),[a,o]=l.useState("powershell"),[r,i]=l.useState(!1),c=t==="unix"?"unix":a,d=l.useMemo(()=>CA(),[]);l.useEffect(()=>{n(rP())},[]);const u=l.useCallback(()=>{navigator.clipboard.writeText(d[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return s.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-3xs px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>n("unix"),children:"macOS / Linux"}),s.jsx("button",{className:`text-3xs px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>n("windows"),children:"Windows"})]}),t==="windows"&&s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-4xs px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${a==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>o("powershell"),children:"PowerShell"}),s.jsx("button",{className:`text-4xs px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${a==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>o("cmd"),children:">_ CMD"})]}),s.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:u,title:"Click to copy",children:[s.jsx("span",{className:"text-text-muted select-none",children:d[c].prompt}),s.jsx("span",{className:"flex-1 break-all",children:d[c].cmd}),s.jsx("span",{className:"text-4xs font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:r?s.jsx(Ca,{size:12}):s.jsx(Qr,{size:12})})]}),s.jsxs("div",{className:"text-text-muted text-3xs font-sans mt-2",children:["Or via npm: ",s.jsx("span",{className:"text-text-secondary font-mono",children:e?"npm i -g @adhdev/daemon-standalone && adhdev-standalone":"npm i -g adhdev && adhdev login"})]})]})}function vg({section:e,onSectionChange:t}){const{t:n}=ye("common"),a=[{key:"machines",label:n("nav.machines"),icon:Es},{key:"chats",label:n("nav.chats"),icon:Ks}];return s.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:s.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:a.map(({key:o,label:r,icon:i})=>{const c=e===o;return s.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-xxs font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>t(o),type:"button","aria-pressed":c,children:[s.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:s.jsx(i,{size:15})}),s.jsx("span",{children:r})]},o)})})})}function zo({title:e,className:t=""}){return s.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${t}`,children:s.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:e})})}function sa({children:e,className:t=""}){return s.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${t}`,children:e})}function Tn({icon:e,title:t,subtitle:n,children:a}){return s.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[s.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:e}),s.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:t}),s.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),a]})}function iP({conversation:e,onCancel:t,onConfirm:n}){const{t:a}=ye(),o=At(e);return s.jsx(xs,{children:s.jsxs("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",children:[s.jsx("div",{onClick:t,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"mobile-hide-confirm-title",className:"card fade-in mobile-compact-dialog relative w-full sm:w-[min(92vw,420px)] md:w-[92%] md:max-w-[420px] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] flex flex-col overflow-hidden rounded-[24px] sm:rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-bg-primary",children:[s.jsx("h3",{id:"mobile-hide-confirm-title",className:"m-0 text-base md:text-lg font-extrabold",children:a("mobileInbox.hideTitle",{title:o})}),s.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:a("mobileInbox.hideDescription")})]}),s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s.jsx("button",{onClick:n,className:"btn btn-primary w-full justify-center min-h-[42px]",children:a("mobileInbox.hide")}),s.jsx("button",{onClick:t,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:a("common.cancel")})]})]})]})})}function Go({item:e,type:t,getAvatarText:n,onOpenConversation:a,onRequestHideConversation:o,onRequestStopCli:r,onOpenMeshGraph:i,onCollectChatDebugBundle:c,isMuted:d,onToggleMute:u}){const{t:p}=ye(),m=t==="needs_attention"||t==="task_complete",h=t==="working",f=t==="earlier",x=t==="task_complete",{isReconnecting:b,isConnecting:g,isErrored:S}=Xn(e.conversation),j=At(e.conversation),y=wa(e.conversation),k=Lf(e.conversation,{requiresAction:t==="needs_attention"}),v=m?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":h?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":f?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",C=m?"bg-accent-primary shadow-glow":h?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":f?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",w=f?"text-text-secondary":"text-text-primary",N=f?"text-text-muted":"text-text-secondary",T=f?"text-text-secondary opacity-80":"text-text-muted",A=f?"text-text-muted opacity-80":"text-text-muted",P=!h&&!x,D=If(e.conversation),L="text-[color:var(--status-warning)]",I=R=>{if(!c||!f1())return;R.preventDefault(),R.stopPropagation();const _=c==null?void 0:c(e.conversation);Promise.resolve(_).catch(M=>{console.warn("[chat-debug-bundle] failed to collect mobile inbox debug bundle",M)})};return s.jsx("div",{className:`group relative overflow-hidden transition-colors active:scale-[0.995] ${v}`,children:s.jsxs("div",{className:"relative flex w-full items-start gap-3.5 px-4 py-3.5 text-left",children:[m||h?s.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,s.jsxs("div",{className:"mobile-inbox-leading-rail flex w-11 shrink-0 flex-col items-center gap-1.5",children:[s.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${C}`,style:m?{color:"var(--accent-on-primary)"}:void 0,children:n(j)}),D&&i&&s.jsx("button",{type:"button",className:"mobile-inbox-mesh-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary/70 text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:R=>{R.preventDefault(),R.stopPropagation(),i(e.conversation)},"aria-label":p("mobileInbox.openMeshGraphFor",{title:j}),title:p("mobileInbox.openLiveMeshGraph"),children:s.jsx(js,{size:13})})]}),s.jsxs("button",{className:"relative flex min-w-0 flex-1 flex-col gap-0.5 text-left",onClick:()=>a(e.conversation),onContextMenu:I,type:"button",children:[s.jsx("div",{className:"flex items-center gap-2 pr-[124px]",children:s.jsx("span",{className:`text-[15px] leading-[22px] font-bold truncate tracking-tight ${w}`,children:j})}),s.jsxs("div",{className:`text-xs font-medium truncate flex items-center ${N}`,children:[s.jsx("span",{className:"truncate",children:y}),s.jsx(Pr,{git:e.conversation.git,compact:!0,className:"ml-1 max-w-[6.5rem] shrink-0"}),b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:`${L} animate-pulse`,children:p("mobileInbox.reconnectingItem")})]}):g?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-text-muted",children:p("mobileInbox.connectingItem")})]}):k==="Action needed"?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:L,children:p("mobileInbox.actionNeeded")})]}):S&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-[color:var(--status-error)]",children:p("mobileInbox.needsAttention")})]})]}),s.jsx("div",{className:`mt-0.5 truncate text-xxs ${T}`,children:e.preview})]}),s.jsxs("div",{className:"mobile-inbox-corner-actions absolute top-3 right-3 flex items-center gap-1.5",children:[P&&s.jsx("span",{className:`mr-0.5 text-2xs font-medium shrink-0 ${A}`,children:kh(e.timestamp)}),x&&s.jsx("span",{className:"rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-3xs font-bold text-accent-primary",children:p("mobileInbox.done")}),u&&s.jsx("button",{type:"button",className:`mobile-inbox-mute-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border transition-colors ${d?"border-amber-500/60 bg-amber-500 text-white hover:bg-amber-600":"border-border-subtle bg-bg-primary/70 text-text-muted hover:border-border-default hover:text-text-primary"}`,onClick:R=>{R.preventDefault(),R.stopPropagation(),u()},"aria-label":d?p("mobileInbox.unmute",{title:j}):p("mobileInbox.mute",{title:j}),title:p(d?"mobileInbox.mutedTitle":"mobileInbox.muteNotifications"),children:d?s.jsx(eh,{size:13}):s.jsx(vn,{size:13})}),o&&s.jsx("button",{type:"button",className:"mobile-inbox-hide-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary/70 text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:R=>{R.preventDefault(),R.stopPropagation(),o()},"aria-label":p("mobileInbox.hideConversationAria",{title:j}),title:p("mobileInbox.hideConversationTitle"),children:s.jsx(Xr,{size:13})}),r&&s.jsx("button",{type:"button",className:"mobile-inbox-stop-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-status-error/30 bg-bg-primary/70 text-status-error transition-colors hover:border-status-error/60 hover:bg-status-error/10",onClick:R=>{R.preventDefault(),R.stopPropagation(),r()},"aria-label":p("mobileInbox.stopSessionAria",{title:j}),title:p("mobileInbox.stopSessionTitle"),children:s.jsx(Wt,{size:13})})]})]})},e.conversation.tabKey)}function Tp({count:e,label:t}){return e<=0?null:s.jsxs("span",{className:"inline-flex items-center gap-1.5 text-accent-primary","aria-live":"polite",children:[s.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary/60"}),s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-accent-primary"})]}),s.jsx("span",{className:"font-semibold",children:t})]})}function lP({section:e,attentionItems:t,unreadItems:n,workingItems:a,completedItems:o,hiddenConversations:r,machineCards:i,getAvatarText:c,actionLogs:d,sendDaemonCommand:u,onOpenConversation:p,onShowAllHidden:m,onHideConversation:h,onOpenMeshGraph:f,onStopCli:x,onOpenNewSession:b,onOpenMachine:g,onOpenSettings:S,onSectionChange:j,wsStatus:y="connected",initialDataLoaded:k=!0,conversationsLoaded:v,isStandalone:C=!1,onCollectChatDebugBundle:w,isConversationMuted:N,onToggleMuteConversation:T}){const{t:A}=ye(),[P,D]=l.useState(null),L=y==="disconnected"||y==="reconnecting"||y==="offline"||y==="auth_failed",I=!L&&!k,R=!L&&!(v??k),_=i.length>0,M=t.length>0||n.length>0||a.length>0||o.length>0,$=A(e==="machines"?"mobileInbox.machines":"mobileInbox.chats"),V=C?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",z=C?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]",W=l.useCallback(async E=>{const H=pn(E);if(!H)return;const J=Array.isArray(E.messages)?E.messages:[],q=uf({activeConv:E,visibleMessages:J,actionLogs:d,visibleBarControlCount:0,chatTailState:{hasMoreHistory:!1,historyError:null,historyMessages:[]},ui:{controlsVisible:!1,visibleLiveCount:J.length,hiddenLiveCount:0,isInputActive:!1,isVisible:!0}}),ie=await u(H,"get_chat_debug_bundle",{...gn(E),delivery:"daemon_file",frontendSnapshot:q}),xe=Rn(ie),Y=hf(xe),ne=await mf(Y);ne==="failed"&&console.warn("[chat-debug-bundle] failed to copy or present mobile inbox debug bundle locator"),ft.showToast(pf(xe,{locatorCopyStatus:ne}),ne==="failed"?"warning":"success")},[d,u]),F=w||W,B=l.useCallback(()=>{P&&(h==null||h(P),D(null))},[P,h]);return s.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[s.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${V}`,children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:$}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e==="chats"&&(t.length>0||n.length>0)&&s.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-2xs font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[s.jsx(vn,{size:13}),s.jsx("span",{children:t.length+n.length})]}),s.jsx("button",{onClick:S,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:s.jsx(yo,{size:18})})]})]})}),s.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${z}`,children:[e==="machines"&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:L?s.jsx(Tn,{icon:s.jsx(Cs,{size:32}),title:A(y==="offline"?"mobileInbox.networkOffline":y==="auth_failed"?"mobileInbox.sessionExpired":"mobileInbox.reconnecting"),subtitle:A(y==="offline"?"mobileInbox.waitingForNetwork":y==="auth_failed"?"mobileInbox.pleaseLogInAgain":"mobileInbox.restoringConnection")}):I?s.jsx(Tn,{icon:s.jsx(Cs,{size:32}),title:A("mobileInbox.loading"),subtitle:A("mobileInbox.loadingSubtitle")}):i.length===0?s.jsx(Tn,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:A(C?"mobileInbox.waitingForDaemon":"mobileInbox.connectYourMachines"),subtitle:A(C?"mobileInbox.waitingForDaemonSubtitle":"mobileInbox.connectYourMachinesSubtitle"),children:!C&&s.jsx("div",{className:"w-full max-w-[360px] mt-4",children:s.jsx(xg,{})})}):s.jsx(sa,{children:i.map((E,H)=>s.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${H>0?"border-t border-border-subtle/70":""}`,onClick:()=>g(E.id),type:"button",children:[s.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:c(E.label)}),s.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[15px] leading-[22px] font-bold text-text-primary truncate tracking-tight",children:E.label}),s.jsxs("span",{className:"flex items-center gap-2 text-2xs font-medium text-text-muted shrink-0",children:[s.jsx(Tp,{count:E.generatingCount,label:A("mobileInbox.generatingCount",{count:E.generatingCount})}),E.unread>0?s.jsx("span",{className:"text-accent-primary",children:A("mobileInbox.newCount",{count:E.unread})}):E.total>0?A("mobileInbox.chatCount",{count:E.total}):A("mobileInbox.idle")]})]}),s.jsx("div",{className:"text-xs font-medium text-text-secondary truncate",children:E.subtitle}),E.total>0?s.jsxs("div",{className:"text-xxs text-text-muted mt-0.5",children:[A("mobileInbox.chatCount",{count:E.total}),E.unread>0?A("mobileInbox.unreadSuffix",{count:E.unread}):"",E.generatingCount>0?A("mobileInbox.collapsedGeneratingSuffix",{count:E.generatingCount}):""]}):E.generatingCount>0?s.jsx("div",{className:"text-xxs text-accent-primary mt-0.5 font-medium",children:A("mobileInbox.generatingCount",{count:E.generatingCount})}):s.jsx("div",{className:"text-xxs text-text-muted mt-0.5 italic opacity-70",children:A("mobileInbox.noActiveChats")})]})]},E.id))})}),e==="chats"&&t.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.needsAttention"),className:"mb-0"}),s.jsx(sa,{children:t.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"needs_attention",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&n.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.taskComplete"),className:"mb-0 mt-2"}),s.jsx(sa,{children:n.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"task_complete",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&a.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.workingNow"),className:"mb-0 mt-2"}),s.jsx(sa,{children:a.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"working",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[o.length>0&&s.jsx(zo,{title:A("mobileInbox.earlier"),className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),o.length>0?s.jsx(sa,{children:o.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"earlier",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))}):M?s.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:A("mobileInbox.allCaughtUp")}):L?s.jsx(Tn,{icon:s.jsx(Cs,{size:28}),title:A("mobileInbox.connecting"),subtitle:A("mobileInbox.connectingSubtitle")}):R?s.jsx(Tn,{icon:s.jsx(Cs,{size:28}),title:A("mobileInbox.loading"),subtitle:A("mobileInbox.loadingSubtitle")}):_?s.jsx(Tn,{icon:s.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:s.jsx(Ks,{size:20})}),title:A("mobileInbox.noConversations"),subtitle:A("paneGroup.newSessionDescription"),children:b&&s.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex items-center gap-2 mt-4",onClick:b,"aria-label":A("paneGroup.newSession"),title:A("paneGroup.newSession"),children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),s.jsx("span",{children:A("paneGroup.newSession")})]})}):s.jsx(Tn,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:A("mobileInbox.noMachinesConnected"),subtitle:A("mobileInbox.noMachinesSubtitle")})]}),e==="chats"&&r.length>0&&(()=>{const E=Ty(r);return s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:s.jsx(sa,{className:"mt-4 border-dashed bg-bg-secondary/20",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 text-left",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-text-secondary",children:A("mobileInbox.hiddenTabs")}),s.jsx(Tp,{count:E,label:A("mobileInbox.generatingCount",{count:E})})]}),s.jsxs("div",{className:"mt-0.5 text-xxs text-text-muted",children:[A("mobileInbox.collapsedCount",{count:r.length}),E>0?A("mobileInbox.collapsedGeneratingSuffix",{count:E}):""]})]}),s.jsx("button",{type:"button",className:"shrink-0 rounded-full border border-border-subtle bg-bg-primary/70 px-3 py-1.5 text-xs font-semibold text-accent-primary hover:border-border-default",onClick:m,children:A("mobileInbox.restoreAll")})]})})})})()]}),e==="chats"&&b&&M&&s.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:b,"aria-label":A("paneGroup.newSession"),title:A("paneGroup.newSession"),children:s.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),P&&s.jsx(iP,{conversation:P,onCancel:()=>D(null),onConfirm:B}),s.jsx(vg,{section:e,onSectionChange:j})]})}function cP(e){if(!e)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(e))}catch{return new Date(e).toLocaleString()}}function yg(e){const t=[e.workspace||"Workspace unknown"],n=zn(e.summaryMetadata);n&&t.push(n),(e.messageCount||0)>0&&t.push(`${e.messageCount} msgs`);const a=cP(e.lastMessageAt);return{title:e.title||e.providerSessionId,providerSessionId:e.providerSessionId,metaLine:t.join(" · "),updatedLabel:a?`Updated ${a}`:"",preview:(e.preview||"").trim()}}function wd({title:e,description:t,currentPath:n,directories:a,busy:o=!1,error:r="",confirmLabel:i,onClose:c,onNavigate:d,onConfirm:u}){const[p,m]=l.useState(n),{t:h}=ye("common"),f=i??h("machine.workspaceBrowse.useThisFolder");l.useEffect(()=>{m(n)},[n]);const x=$I(n),b=p.trim();return s.jsx(xs,{children:s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:s.jsxs("div",{className:"w-full max-w-2xl max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(86vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:c,"aria-label":"Close folder browser",children:s.jsx(Wt,{size:16})})]}),s.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!x||o||d(x)},disabled:!x||o,children:[s.jsx(Bc,{size:15}),h("machine.workspaceBrowse.parent")]}),s.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:h("machine.workspaceBrowse.currentFolder")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"text",value:p,onChange:g=>m(g.target.value),onKeyDown:g=>{g.key!=="Enter"||!b||o||(g.preventDefault(),d(b))},placeholder:h("machine.workspaceBrowse.pathPlaceholder"),className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!b||o||d(b)},disabled:!b||o,children:h("machine.workspaceBrowse.go")})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:o?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:h("machine.workspaceBrowse.loading")}):r?s.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:r}):a.length===0?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:h("machine.workspaceBrowse.noSubfolders")}):s.jsx("div",{className:"p-3",children:a.map(g=>s.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(g.path),children:[s.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:s.jsx(Un,{size:17})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:g.name}),s.jsx("span",{className:"block text-2xs text-text-muted truncate",children:g.path})]})]},g.path))})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"btn btn-secondary h-9 px-4 text-sm",onClick:c,children:h("common.cancel")}),s.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>u(b||n),disabled:!b&&!n||o,children:f})]})]})})})}function gi({title:e,description:t,details:n,workspaceOptions:a,selectedWorkspaceKey:o,onWorkspaceChange:r,confirmLabel:i,busyLabel:c,busy:d=!1,showArgsInput:u,argsValue:p,onArgsChange:m,showModelInput:h,modelValue:f,onModelChange:x,historyProviderNode:b,onConfirm:g,onCancel:S}){const{t:j}=ye("common"),y=i??j("machine.launchConfirm.launch"),k=c??j("machine.launchConfirm.launching"),v=a==null?void 0:a.find(w=>w.key===o),C=s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:s.jsxs("div",{className:"w-full max-w-lg max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(88vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:S,"aria-label":j("machine.launchConfirm.closeAria"),children:s.jsx(Wt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-5 sm:py-4 flex flex-col gap-3",children:[a&&a.length>0&&r&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.workspace")}),s.jsx("select",{value:o||"",onChange:w=>r(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:a.map(w=>s.jsx("option",{value:w.key,children:w.label},w.key))}),(v==null?void 0:v.description)&&s.jsx("div",{className:"mt-2 text-2xs text-text-muted break-all",children:v.description})]}),b,n.map((w,N)=>s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:w.label}),s.jsx("div",{className:"text-sm text-text-primary break-all",children:w.value})]},`${w.label}:${N}`)),h&&x&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.languageModel")}),s.jsx("input",{type:"text",value:f||"",onChange:w=>x(w.target.value),placeholder:j("machine.launchConfirm.autoDetect"),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]}),u&&m&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.cliArgs")}),s.jsx("input",{type:"text",value:p||"",onChange:w=>m(w.target.value),placeholder:j("machine.launchConfirm.cliArgsPlaceholder"),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:S,disabled:d,children:j("machine.launchConfirm.cancel")}),s.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:g,disabled:d,children:[s.jsx(Zm,{size:14}),d?k:y]})]})]})});return typeof document>"u"?C:bn.createPortal(C,document.body)}function Ip(e,t){return t||e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||e}function wg(e){const{machine:t,currentWorkspacePath:n,currentWorkspaceId:a,includeHome:o=!0,homeLabel:r="Home directory",homeDescription:i="Launch without a workspace"}=e,c=[];o&&c.push({key:"__home__",label:r,description:i,workspaceId:null,workspacePath:null});for(const p of t.workspaces||[])c.push({key:`saved:${p.id}`,label:`${p.id===t.defaultWorkspaceId?"⭐ ":""}${Ip(p.path,p.label)}`,description:p.path,workspaceId:p.id,workspacePath:p.path});const d=(n==null?void 0:n.trim())||"",u=d?(t.workspaces||[]).find(p=>p.path===d):null;if(d&&!u&&c.push({key:`custom:${d}`,label:Ip(d),description:d,workspaceId:null,workspacePath:d}),a){const p=`saved:${a}`;if(c.some(m=>m.key===p))return{options:c,selectedKey:p}}return u?{options:c,selectedKey:`saved:${u.id}`}:d?{options:c,selectedKey:`custom:${d}`}:{options:c,selectedKey:"__home__"}}function dP(e){return e==="ide"?"IDE":e==="cli"?"CLI":"ACP"}function uP(e){return[dP(e.kind),e.subtitle||"",e.providerSessionId?"Saved history":""].filter(Boolean).join(" · ")}function pP(e){return e.lastLaunchedAt?ni(e.lastLaunchedAt):""}function kg(e){return{metaText:uP(e),updatedLabel:pP(e)}}function nl(e,t,n){return e?"ide":t>0?"cli":n>0?"acp":null}function mP({selectedMachineEntry:e,cliProviders:t,acpProviders:n,machineAction:a,onBrowseDirectory:o,onListSavedSessions:r}){var qe,We,Ie,ge;const i=Na(),[c,d]=l.useState(!1),u=(((qe=e.detectedIdes)==null?void 0:qe.length)||0)>0,p=l.useMemo(()=>(e.workspaces||[]).map(Se=>({id:Se.id,path:Se.path,label:Se.label})),[e]),m=e.defaultWorkspaceId||null,[h,f]=l.useState(m||((We=p[0])==null?void 0:We.id)||""),[x,b]=l.useState(""),[g,S]=l.useState(""),[j,y]=l.useState([]),[k,v]=l.useState(!1),[C,w]=l.useState(""),[N,T]=l.useState(!1),[A,P]=l.useState(nl(u,t.length,n.length)),D=l.useRef(null),[L,I]=l.useState(null),R=l.useRef("__home__"),[_,M]=l.useState("__home__"),[$,V]=l.useState(""),[z,W]=l.useState(""),[F,B]=l.useState(""),[E,H]=l.useState([]),[J,q]=l.useState(()=>as().textQuery),[ie,xe]=l.useState(()=>as().workspaceQuery),[Y,ne]=l.useState(()=>as().modelQuery),[me,ce]=l.useState(()=>as().resumableOnly),[ae,he]=l.useState(()=>as().sortMode),[oe,re]=l.useState(!1),[ee,G]=l.useState(!1),Q=l.useRef(0),ue=l.useRef(0),pe=l.useRef(null),Ae=l.useRef(null);l.useEffect(()=>{(!e.workspaces||!e.availableProviders||!e.detectedIdes||!e.recentLaunches)&&i(e.id,{minFreshMs:3e4}).catch(()=>{})},[i,e]);const Me=h==="__custom__"?x.trim():((Ie=p.find(Se=>Se.id===h))==null?void 0:Ie.path)||"",He=h==="__custom__"&&!!Me&&a.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(a.message),je=h!=="__custom__"&&((ge=p.find(Se=>Se.id===h))==null?void 0:ge.path)||"",Z=l.useMemo(()=>(e.recentLaunches||[]).map(Se=>Se.workspace),[e]),O=l.useCallback(async Se=>{const Te=Q.current+1;Q.current=Te,v(!0),w("");try{const Je=await o(Se);if(Q.current!==Te)return;S(Je.path),b(Je.path),y(Je.directories)}catch(Je){if(Q.current!==Te)return;w(Je instanceof Error?Je.message:"Could not load folder")}finally{Q.current===Te&&v(!1)}},[o]),X=l.useCallback(()=>{var Te;f("__custom__"),T(!0);const Se=xd(e.platform,bd(x.trim(),je,Z,e.defaultWorkspacePath,(Te=p.find(Je=>Je.id===m))==null?void 0:Te.path,p.map(Je=>Je.path)));O(Se)},[x,m,O,Z,je,e.platform,p]),te=l.useCallback(Se=>{if(Se!=null&&Se.workspaceId){f(Se.workspaceId),b("");return}if(Se!=null&&Se.workspacePath){f("__custom__"),b(Se.workspacePath);return}f(""),b("")},[]),de=l.useCallback(Se=>{if(f(Se),Se==="__custom__"){X();return}b("")},[X]),ve=l.useCallback(Se=>{f("__custom__"),b(Se)},[]),fe=l.useCallback((Se,Te)=>{const Je=ue.current+1;ue.current=Je,D.current=Te,R.current=Se.selectedWorkspaceKey||"__home__",M(Se.selectedWorkspaceKey||"__home__"),V(Se.initialArgs||""),W(Se.initialModel||""),B(""),H([]);const K=Se.providerType?`${e.id}:${Se.providerType}`:null;if(A1(Ae.current,K)){const se=as();q(se.textQuery),xe(se.workspaceQuery),ne(se.modelQuery),ce(se.resumableOnly),he(se.sortMode)}Ae.current=K,I(Se),Se.providerType&&r?(re(!0),r(Se.providerType).then(se=>{ue.current===Je&&H(se||[])}).catch(se=>{ue.current===Je&&console.warn("Failed to load saved sessions",se)}).finally(()=>{ue.current===Je&&re(!1)})):re(!1)},[r,e.id]),U=l.useMemo(()=>Hf(E,{textQuery:J,workspaceQuery:ie,modelQuery:Y,resumableOnly:me,sortMode:ae}),[Y,me,E,ae,J,ie]);l.useEffect(()=>{F&&(U.some(Se=>Se.providerSessionId===F)||B(""))},[U,F]);const Ce=l.useCallback(()=>{D.current&&(G(!0),D.current().finally(()=>{D.current=null,G(!1),I(null)}))},[]),Pe=l.useCallback(()=>{ue.current+=1,D.current=null,re(!1),I(null)},[]),Be=l.useCallback(Se=>{R.current=Se,M(Se)},[]);return l.useEffect(()=>{var Se;pe.current!==e.id&&(Q.current+=1,ue.current+=1,pe.current=e.id,f(m||((Se=p[0])==null?void 0:Se.id)||"__custom__"),b(""),S(""),y([]),v(!1),w(""),T(!1),D.current=null,I(null),H([]),re(!1),G(!1),q(as().textQuery),xe(as().workspaceQuery),ne(as().modelQuery),ce(as().resumableOnly),he(as().sortMode),Ae.current=null,P(nl(u,t.length,n.length)))},[n.length,t.length,m,u,e.id,p]),l.useEffect(()=>{var Se;h!=="__custom__"&&(h&&p.some(Te=>Te.id===h)||f(m||((Se=p[0])==null?void 0:Se.id)||"__custom__"))},[m,h,p]),l.useEffect(()=>{A==="ide"&&u||A==="cli"&&t.length>0||A==="acp"&&n.length>0||P(nl(u,t.length,n.length))},[A,n.length,t.length,u]),{showAllRecent:c,setShowAllRecent:d,hasIdeOptions:u,workspaceRows:p,defaultWorkspaceId:m,workspaceChoice:h,customWorkspacePath:x,browseCurrentPath:g,browseDirectories:j,browseBusy:k,browseError:C,browseDialogOpen:N,activeLauncherKind:A,launchConfirm:L,launchConfirmWorkspaceKeyRef:R,launchConfirmWorkspaceKey:_,launchConfirmArgs:$,launchConfirmModel:z,launchConfirmResumeId:F,launchConfirmSavedSessions:E,launchConfirmTextFilter:J,launchConfirmWorkspaceFilter:ie,launchConfirmModelFilter:Y,launchConfirmResumableOnly:me,launchConfirmSortMode:ae,filteredLaunchConfirmSavedSessions:U,launchConfirmSessionsLoading:oe,launchConfirmBusy:ee,resolvedWorkspacePath:Me,canCreateMissingWorkspace:He,openBrowseDialog:X,loadBrowsePath:O,handleWorkspaceChoiceChange:de,chooseCustomWorkspacePath:ve,setCustomWorkspacePath:b,setBrowseDialogOpen:T,setActiveLauncherKind:P,openLaunchConfirm:fe,handleConfirmLaunch:Ce,closeLaunchConfirm:Pe,setWorkspaceSelectionFromOption:te,setLaunchConfirmWorkspaceKeyAndSync:Be,setLaunchConfirmArgs:V,setLaunchConfirmModel:W,setLaunchConfirmResumeId:B,setLaunchConfirmTextFilter:q,setLaunchConfirmWorkspaceFilter:xe,setLaunchConfirmModelFilter:ne,setLaunchConfirmResumableOnly:ce,setLaunchConfirmSortMode:he}}function hP({selectedMachineEntry:e,selectedMachineConversations:t,selectedMachineRecentLaunches:n,cliProviders:a,acpProviders:o,selectedMachineNeedsUpgrade:r,appVersion:i,machineAction:c,isStandalone:d,section:u,showBottomNav:p,onBack:m,onSectionChange:h,onOpenConversation:f,onOpenRecent:x,onOpenMachineDetails:b,onMachineUpgrade:g,onLaunchDetectedIde:S,onAddWorkspace:j,onBrowseDirectory:y,onLaunchWorkspaceProvider:k,onListSavedSessions:v}){const{t:C}=ye("common"),w=M=>M==="ide"?"IDE":M==="cli"?"CLI":"ACP",N=n.slice(0,4),T=t.slice(0,3),A=mP({selectedMachineEntry:e,cliProviders:a,acpProviders:o,machineAction:c,onBrowseDirectory:y,onListSavedSessions:v}),P=l.useMemo(()=>N.map(M=>{const{metaText:$,updatedLabel:V}=kg(M);return{key:`recent-launch:${M.id}`,primary:M.label,secondary:$,updatedLabel:V,onClick:()=>{const{options:z,selectedKey:W}=wg({machine:{workspaces:A.workspaceRows,defaultWorkspaceId:A.defaultWorkspaceId},currentWorkspacePath:M.workspace,homeLabel:C("newSession.homeDirectory"),homeDescription:C("newSession.launchWithoutWorkspace")});A.openLaunchConfirm({title:M.kind==="ide"?Lr(C,"restart-ide",M.label):M.providerSessionId?$f(C,M.label):Lr(C,"start-fresh",M.label),description:M.kind==="ide"?Dr(C,"restart-ide"):M.providerSessionId?Bf(C):Dr(C,"start-fresh"),confirmLabel:M.kind==="ide"?Mr(C,"restart-ide"):M.providerSessionId?lc(C,!0):Mr(C,"start-fresh"),busyLabel:M.kind==="ide"?Rr(C,"restart-ide"):M.providerSessionId?Ff(C,!0):Rr(C,"start-fresh"),workspaceOptions:z,selectedWorkspaceKey:W,details:[{label:"Mode",value:w(M.kind)},...M.providerType?[{label:"Provider",value:M.providerType}]:[]]},async()=>{const F=z.find(B=>B.key===A.launchConfirmWorkspaceKeyRef.current);A.setWorkspaceSelectionFromOption(F),await x({...M,workspace:(F==null?void 0:F.workspacePath)??null})})}}}),[A,x,N,C]),D=l.useMemo(()=>T.map(M=>({key:`recent-chat:${M.conversation.tabKey}`,primary:At(M.conversation),secondary:JA(M.conversation,{timestampLabel:M.timestamp?kh(M.timestamp):null}),unread:M.unread,onClick:()=>f(M.conversation)})),[f,T]),L=A.showAllRecent?P:P.slice(0,4),I=P.length>0,R=D.length>0,_=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`flex items-center justify-between gap-3 ${_} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:m,type:"button","aria-label":"Back",children:s.jsx(Bc,{size:18})}),s.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] leading-[26px] font-extrabold tracking-tight text-text-primary truncate",children:Ns(e,{fallbackId:e.id})}),s.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[e.platform||"machine",e.version?` · v${e.version}`:""]})]})]})}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[R&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:D.map(M=>s.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${M.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:M.onClick,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:M.primary}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:M.secondary})]},M.key))})]}),I&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:L.map(M=>s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:M.onClick,children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsx("span",{className:"text-sm font-bold text-text-primary truncate",children:M.primary}),M.updatedLabel&&s.jsx("span",{className:"text-2xs text-text-muted shrink-0",children:M.updatedLabel})]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:M.secondary})]},M.key))}),P.length>4&&s.jsx("div",{className:"flex justify-center px-4 pt-2",children:s.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>A.setShowAllRecent(M=>!M),children:A.showAllRecent?"Show fewer":`Show ${P.length-4} more`})})]}),!1,s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),s.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[r&&s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:g,children:[s.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",i]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:b,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),A.browseDialogOpen&&s.jsx(wd,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:A.browseCurrentPath,directories:A.browseDirectories,busy:A.browseBusy,error:A.browseError,confirmLabel:"Use this folder",onClose:()=>A.setBrowseDialogOpen(!1),onNavigate:M=>{A.loadBrowsePath(M)},onConfirm:M=>{A.chooseCustomWorkspacePath(M),A.setBrowseDialogOpen(!1)}}),A.launchConfirm&&s.jsx(gi,{title:A.launchConfirm.title,description:A.launchConfirm.description,details:A.launchConfirm.details,workspaceOptions:A.launchConfirm.workspaceOptions,selectedWorkspaceKey:A.launchConfirmWorkspaceKey,onWorkspaceChange:A.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:A.launchConfirm.providerType?lc(C,!!A.launchConfirmResumeId):A.launchConfirm.confirmLabel,busyLabel:A.launchConfirm.providerType?void 0:A.launchConfirm.busyLabel,busy:A.launchConfirmBusy,showArgsInput:A.launchConfirm.showArgsInput,argsValue:A.launchConfirmArgs,onArgsChange:A.setLaunchConfirmArgs,showModelInput:A.launchConfirm.showModelInput,modelValue:A.launchConfirmModel,onModelChange:A.setLaunchConfirmModel,historyProviderNode:A.launchConfirm.providerType&&(A.launchConfirmSessionsLoading||A.launchConfirmSavedSessions.length>0)&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted",children:"Resume saved history"}),A.launchConfirmSessionsLoading&&s.jsx("div",{className:"text-3xs text-text-secondary font-medium",children:"Loading..."})]}),s.jsx("div",{className:"text-2xs text-text-secondary mb-2",children:ld(C)}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:A.launchConfirmTextFilter,onChange:M=>A.setLaunchConfirmTextFilter(M.target.value),placeholder:"Search title or preview",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:A.launchConfirmWorkspaceFilter,onChange:M=>A.setLaunchConfirmWorkspaceFilter(M.target.value),placeholder:"Filter by workspace",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:A.launchConfirmModelFilter,onChange:M=>A.setLaunchConfirmModelFilter(M.target.value),placeholder:"Filter by model",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsxs("select",{value:A.launchConfirmSortMode,onChange:M=>A.setLaunchConfirmSortMode(M.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"recent",children:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mb-2 flex items-center gap-2 text-2xs text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:A.launchConfirmResumableOnly,onChange:M=>A.setLaunchConfirmResumableOnly(M.target.checked),disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),"Resume-ready only"]}),s.jsxs("select",{value:A.launchConfirmResumeId,onChange:M=>A.setLaunchConfirmResumeId(M.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"",children:P1(C)}),A.filteredLaunchConfirmSavedSessions.map(M=>s.jsxs("option",{value:M.providerSessionId,disabled:!M.canResume,children:[M.title||M.providerSessionId," ",M.canResume?"":"(workspace missing)"]},M.providerSessionId))]}),!A.launchConfirmSessionsLoading&&A.launchConfirmSavedSessions.length>0&&A.filteredLaunchConfirmSavedSessions.length===0&&s.jsx("div",{className:"mt-2 text-2xs text-text-muted",children:"No saved history matches these filters."}),A.launchConfirmResumeId&&(()=>{const M=A.filteredLaunchConfirmSavedSessions.find(V=>V.providerSessionId===A.launchConfirmResumeId);if(!M)return null;const $=yg(M);return s.jsxs("div",{className:"mt-2 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2.5 text-2xs text-text-muted leading-relaxed",children:[s.jsx("div",{className:"font-semibold text-text-primary truncate",children:$.title}),s.jsx("div",{className:"font-mono break-all mt-0.5",children:$.providerSessionId}),s.jsx("div",{className:"mt-1",children:$.metaLine}),$.updatedLabel&&s.jsx("div",{className:"mt-1 text-text-secondary",children:$.updatedLabel}),$.preview&&s.jsx("div",{className:"mt-2 line-clamp-2 text-text-secondary",children:$.preview})]})})()]}),onConfirm:A.handleConfirmLaunch,onCancel:A.closeLaunchConfirm}),p&&s.jsx(vg,{section:u,onSectionChange:h})]})}const Pp=8e3;function fP(e){const t=e&&typeof e=="object"&&"result"in e?e.result:e,n=t&&typeof t=="object",a=n&&t.success===!1,o=n&&t.mirrorStale===!0;return!a&&!o?{confirmed:!0}:{confirmed:!1,reason:a&&typeof t.error=="string"?t.error:o?"the coordinator did not confirm the change":"command was rejected"}}function Sg(e,t,n){const a=l.useRef(new Map),[,o]=l.useState(0),r=l.useCallback(()=>o(f=>f+1),[]);l.useEffect(()=>{const f=a.current;if(f.size===0)return;const x=Date.now();let b=!1;for(const[g,S]of f){const j=e.get(g),y=S.muted===void 0||(j?j.muted===S.muted:!1),k=S.hidden===void 0||(j?j.surfaceHidden===S.hidden:!1),v=x-S.at>Pp;(y&&k||v)&&(f.delete(g),b=!0)}b&&r()},[e,r]),l.useEffect(()=>{if(a.current.size===0)return;const f=setInterval(()=>{const x=a.current,b=Date.now();let g=!1;for(const[S,j]of x)b-j.at>Pp&&(x.delete(S),g=!0);g&&r(),x.size===0&&clearInterval(f)},1e3);return()=>clearInterval(f)});const i=l.useCallback((f,x)=>{const b=a.current.get(f);a.current.set(f,{...b,...x,at:Date.now()}),r()},[r]),c=l.useCallback(f=>{const x=f.sessionId,b=x?a.current.get(x):void 0;return(b==null?void 0:b.muted)!==void 0?b.muted:yn(f,e).muted??!1},[e]),d=l.useCallback(f=>{const x=f.sessionId,b=x?a.current.get(x):void 0;return(b==null?void 0:b.hidden)!==void 0?b.hidden:yn(f,e).surfaceHidden??!1},[e]),u=l.useCallback((f,x)=>{const b=sn(f),g=f.sessionId;!b||!g||(i(g,x),t(b,"set_conversation_prefs",{sessionId:g,...x,...ui(f)}).then(S=>{const j=fP(S);j.confirmed||(console.warn("[conversation-prefs] set_conversation_prefs not confirmed",j.reason),a.current.delete(g),r(),n==null||n(`Couldn't update conversation — ${j.reason}`))}).catch(S=>{console.warn("[conversation-prefs] set_conversation_prefs failed",S),a.current.delete(g),r();const j=S instanceof Error?S.message:String(S??"the daemon is unreachable");n==null||n(`Couldn't update conversation — ${j}`)}))},[t,i,r,n]),p=l.useCallback(f=>{u(f,{muted:!c(f)})},[u,c]),m=l.useCallback((f,x)=>{u(f,{hidden:x})},[u]),h=l.useCallback(f=>{u(f,{hidden:!d(f)})},[u,d]);return{isMuted:c,isHidden:d,toggleMute:p,setHidden:m,toggleHidden:h}}function gr(e){return[...e].sort((t,n)=>{const a=n.timestamp-t.timestamp;return a!==0?a:t.conversation.tabKey.localeCompare(n.conversation.tabKey)})}function gP(e,t=[]){const n=new Map(e.map(o=>[o.conversation.tabKey,o])),a=t.map(o=>n.get(o)).filter(o=>!!o);return a.length===e.length?a:gr(e)}function bP(e,t=[]){const n=e.filter(i=>i.requiresAction),a=e.filter(i=>i.unread&&!i.requiresAction),o=e.filter(i=>!i.unread&&!i.requiresAction&&i.isWorking),r=e.filter(i=>!i.unread&&!i.requiresAction&&!i.isWorking);return{attentionItems:gr(n),unreadItems:gr(a),workingItems:gP(o,t),completedItems:gr(r)}}function bi(e,t){if(!t)return!1;const n=e.filter(a=>a.type==="adhdev-daemon"&&Cg(a)==="Connected");return n.length===0?!0:n.every(a=>a._sessionListAuthoritative===!0)}function Cg(e){var a,o,r;const t=((a=e.p2p)==null?void 0:a.state)||"";return t==="connected"?"Connected":t==="connecting"||t==="new"||t==="checking"?"Connecting":!(!!((o=e.p2p)!=null&&o.available)||!!((r=e.p2p)!=null&&r.state))&&e.status&&e.status!=="offline"?"Connected":"Offline"}function xP(e,t){if(!e)return[];const n=e.recentLaunches||[];return n.length>0?n.map(a=>({id:a.id,label:a.title||a.providerName||a.providerType,kind:a.kind,providerType:a.providerType,providerSessionId:a.providerSessionId,subtitle:zn(a.summaryMetadata)||a.workspace||void 0,workspace:a.workspace,summaryMetadata:a.summaryMetadata})):t.filter(a=>a.type!=="adhdev-daemon"&&a.daemonId===e.id).map(a=>{var i;const o=mo(a)?"cli":ha(a)?"acp":"ide",r=zn(a.summaryMetadata);return{id:`${o}:${a.type}:${a.workspace||""}`,label:((i=a.activeChat)==null?void 0:i.title)||(mo(a)?a.cliName||a.type:ha(a)&&a.cliName||a.type),kind:o,providerType:a.type,providerSessionId:a.providerSessionId,subtitle:ha(a)?r||a.workspace||void 0:a.workspace||void 0,workspace:a.workspace||void 0,timestamp:a.lastMessageAt||0}}).sort((a,o)=>o.timestamp-a.timestamp).map(({timestamp:a,...o})=>o)}function vP(e,t,n=[]){const a=new Map;for(const r of t){const i=sn(r.conversation),c=a.get(i);c?c.push(r):a.set(i,[r])}const o=new Map;for(const r of n){const i=sn(r),c=o.get(i);c?c.push(r):o.set(i,[r])}return e.map(r=>{const i=a.get(r.id)||[],c=o.get(r.id)||[],d=[...i].sort((b,g)=>g.timestamp-b.timestamp)[0]||null,u=(d==null?void 0:d.conversation)||null,p=Zl(r),m=i.filter(b=>b.unread||b.requiresAction).length,h=i.filter(b=>qn(b.conversation)).length+c.filter(qn).length,f=Cg(r),x=[r.platform||"machine",f].filter(Boolean);return{id:r.id,label:Ns(r,{fallbackId:r.id}),subtitle:x.join(" · "),unread:m,total:i.length,generatingCount:h,latestConversation:u,latestTimestamp:(d==null?void 0:d.timestamp)||0,fallbackActivityAt:p,preview:u?XA(u,Sf(u)):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((r,i)=>{const c=r.latestTimestamp||r.fallbackActivityAt||0,d=i.latestTimestamp||i.fallbackActivityAt||0;return d!==c?d-c:r.label.localeCompare(i.label)})}function yP(e){return e==="chat"}function Ko(e,t){var n;if(!(typeof window>"u"))try{if(!(!!((n=import.meta.env)!=null&&n.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${e}`,t)}catch{}}function wP({conversations:e,machineEntries:t,items:n,selectedConversation:a,selectedTabKey:o,screen:r,liveSessionInboxState:i,sendDaemonCommand:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,setSelectedTabKey:x,setScreen:b,setSelectedMachineId:g,setSection:S,setMachineBackTarget:j,resetMachineAction:y}){const k=l.useRef(null),v=l.useCallback(C=>{if(!(C!=null&&C.sessionId))return;const w=yn(C,i),N=Math.max(Date.now(),Bn(C),w.lastUpdated||0);Ko("mark_read:start",{tabKey:C.tabKey,sessionId:C.sessionId,displayPrimary:At(C),inboxBucket:w.inboxBucket,unread:w.unread,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,activityAt:Bn(C),readAt:N}),c(sn(C)||C.routeId,"mark_session_seen",{sessionId:C.sessionId,providerSessionId:C.providerSessionId,seenAt:N,completionMarker:w.completionMarker}).then(T=>{Ko("mark_read:result",{tabKey:C.tabKey,sessionId:C.sessionId,result:T})}).catch(T=>{Ko("mark_read:error",{tabKey:C.tabKey,sessionId:C.sessionId,error:T instanceof Error?T.message:String(T)})})},[i,c]);return l.useEffect(()=>{var w;if(!a){yP(r)&&b("inbox"),x(((w=e[0])==null?void 0:w.tabKey)||null),k.current=null;return}if(r!=="chat"){k.current=null;return}const C=`${a.tabKey}:${a.sessionId||""}`;k.current!==C&&(k.current=C,v(a))},[e,v,r,a,b,x]),l.useEffect(()=>{if(!d)return;const C=e.find(w=>w.tabKey===d);C&&(x(C.tabKey),b("chat"),u==null||u())},[e,u,d,b,x]),l.useEffect(()=>{if(!p)return;const C=t.find(w=>w.id===p);C&&(g(C.id),y(),S("machines"),j("inbox"),b("machine"),m==null||m())},[t,m,p,y,j,b,S,g]),l.useEffect(()=>{h&&(S(h),b("inbox"),f==null||f())},[f,h,b,S]),l.useEffect(()=>{const C=n.filter(w=>w.inboxBucket==="task_complete"||w.unread);C.length!==0&&Ko("inbox_state",{screen:r,selectedTabKey:o,items:C.map(w=>{const N=yn(w.conversation,i);return{liveState:N,tabKey:w.conversation.tabKey,sessionId:w.conversation.sessionId,displayPrimary:At(w.conversation),serverBucket:N.inboxBucket,computedBucket:w.inboxBucket,serverUnread:N.unread,computedUnread:w.unread,lastSeenAt:N.lastSeenAt,lastUpdated:N.lastUpdated,activityAt:Bn(w.conversation)}})})},[n,i,r,o]),{markConversationRead:v}}const kP="Cannot update: node update policy unavailable; refresh and try again";async function SP(e,t,n){var o,r,i,c,d,u;const a=fd(n);if(!a)return{state:"error",message:kP};try{const p=await e(t,"daemon_upgrade",a);return(o=p==null?void 0:p.result)!=null&&o.alreadyLatest?{state:"done",message:`Already on v${((r=p==null?void 0:p.result)==null?void 0:r.version)||"latest"}.`}:(i=p==null?void 0:p.result)!=null&&i.upgraded||(c=p==null?void 0:p.result)!=null&&c.success?{state:"done",message:`Upgrade to v${((d=p==null?void 0:p.result)==null?void 0:d.version)||"latest"} started. Daemon is restarting…`}:{state:"error",message:((u=p==null?void 0:p.result)==null?void 0:u.error)||"Upgrade failed"}}catch(p){return{state:"error",message:p instanceof Error?p.message:"Upgrade failed"}}}function CP(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function Lp(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function jP(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function NP({sendDaemonCommand:e,navigate:t,ides:n,conversations:a}){const{launchCli:o}=ei(),[r,i]=l.useState("idle"),[c,d]=l.useState(""),[u,p]=l.useState(null),m=l.useCallback(()=>{i("idle"),d(""),p(null)},[]),h=l.useCallback(async(y,k,v)=>{var C;try{i("loading"),d(`Launching ${k}…`);const w={ideType:k,enableCdp:!0};(C=v==null?void 0:v.workspacePath)!=null&&C.trim()&&(w.workspace=v.workspacePath.trim()),await e(y,"launch_ide",w),i("done"),d(`${k} launch requested`)}catch(w){i("error"),d(w instanceof Error?w.message:"Launch IDE failed"),console.error("Launch IDE failed",w)}},[e]),f=l.useCallback(async(y,k,v)=>{if(k.trim())try{i("loading"),d(v!=null&&v.createIfMissing?"Creating folder…":"Saving workspace…");const C=await e(y,"workspace_add",{path:k.trim(),createIfMissing:(v==null?void 0:v.createIfMissing)===!0});if(C!=null&&C.success){i("done"),d(v!=null&&v.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),d((C==null?void 0:C.error)||"Could not save workspace")}catch(C){i("error"),d(C instanceof Error?C.message:"Could not save workspace")}},[e]),x=l.useCallback(async y=>{i("loading"),d("Starting daemon upgrade…");const k=n.find(C=>C.id===y||C.daemonId===y),v=await SP(e,y,k);i(v.state),d(v.message)},[n,e]),b=l.useCallback(async(y,k,v,C)=>{var T,A,P;const w=Date.now(),N={machineId:y,kind:k,providerType:v,workspaceId:(C==null?void 0:C.workspaceId)||null,workspacePath:(C==null?void 0:C.workspacePath)||null,resumeSessionId:(C==null?void 0:C.resumeSessionId)||null,startedAt:w};try{i("loading"),d(`Launching ${v}…`),p(N);const D={cliType:v};(T=C==null?void 0:C.workspacePath)!=null&&T.trim()?D.dir=C.workspacePath.trim():C!=null&&C.workspaceId?D.workspaceId=C.workspaceId:C!=null&&C.useHome&&(D.useHome=!0),C!=null&&C.resumeSessionId&&(D.resumeSessionId=C.resumeSessionId),(A=C==null?void 0:C.args)!=null&&A.trim()&&(D.cliArgs=C.args.trim().split(/\s+/).filter(Boolean)),(P=C==null?void 0:C.model)!=null&&P.trim()&&(D.initialModel=C.model.trim());const L=await o(y,D),I=(L==null?void 0:L.result)||L,R=(I==null?void 0:I.sessionId)||(I==null?void 0:I.id);if(L!=null&&L.success&&R){p(null),i("done"),d(`${v} launched`),t(go(R));return}if(L!=null&&L.success){i("loading"),d(`${v} launch requested — waiting for session…`);return}p(null),i("error"),d((L==null?void 0:L.error)||(I==null?void 0:I.error)||`Could not launch ${k.toUpperCase()} workspace`)}catch(D){if(jP(D)){i("loading"),d(`${v} launch requested — waiting for session…`);return}p(null),i("error"),d(D instanceof Error?D.message:`Could not launch ${k.toUpperCase()} workspace`)}},[t,e]),g=l.useCallback(async(y,k)=>{try{const v=await e(y,"list_saved_sessions",{providerType:k,kind:"cli",limit:30}),C=(v==null?void 0:v.result)??v;return Array.isArray(C==null?void 0:C.sessions)?C.sessions:[]}catch(v){return console.error("Failed to list saved sessions on mobile:",v),[]}},[e]),S=l.useCallback(async(y,k)=>vd(e,y,k),[e]);l.useEffect(()=>{if(!u)return;const y=Lp(u.workspacePath),k=n.find(C=>{var D,L,I,R;if(!C||C.type==="adhdev-daemon"||CP(C.daemonId||C.id)!==u.machineId||(C.transport==="acp"?"acp":C.transport==="pty"?"cli":null)!==u.kind||String(C.agentType||C.type||"")!==u.providerType)return!1;const A=String(C.providerSessionId||"");if(u.resumeSessionId&&A)return A===u.resumeSessionId;if(y){const _=Lp(C.workspace||C.runtimeWorkspaceLabel);return _?_===y:!1}return Number(C.lastUpdated||C._lastUpdate||C.timestamp||((R=(I=(L=(D=C.activeChat)==null?void 0:D.messages)==null?void 0:L.at)==null?void 0:I.call(L,-1))==null?void 0:R.timestamp)||0)>=u.startedAt-5e3});if(!k)return;const v=gg({entrySessionId:k.sessionId,entryInstanceId:k.instanceId,entryRouteId:k.id,conversations:a});v&&(p(null),i("done"),d(`${u.providerType} launched`),t(go(v)))},[a,n,t,u]),l.useEffect(()=>{if(!u)return;const y=window.setTimeout(()=>{p(k=>!k||k.startedAt!==u.startedAt?k:(i("error"),d("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(y)},[u]);const j=l.useCallback(async(y,k)=>{var v;if(k.kind==="ide"&&k.providerType){await h(y,k.providerType,{workspacePath:k.workspace||null});return}if((k.kind==="cli"||k.kind==="acp")&&k.providerType){const C=((v=k.workspace)==null?void 0:v.trim())||"";await b(y,k.kind,k.providerType,{workspacePath:C||null,useHome:!C,resumeSessionId:k.providerSessionId||null})}},[h,b]);return{machineAction:{state:r,message:c},resetMachineAction:m,handleLaunchDetectedIde:h,handleAddWorkspace:f,handleMachineUpgrade:x,handleLaunchWorkspaceProvider:b,handleListSavedSessions:g,handleBrowseDirectory:S,handleOpenRecent:j}}function AP({conversations:e,selectedConversation:t,machineBackTarget:n,markConversationRead:a,resetMachineAction:o,setSelectedTabKey:r,setScreen:i,setSelectedMachineId:c,setSection:d,setMachineBackTarget:u}){const p=l.useCallback(S=>{r(S.tabKey),i("chat"),a(S)},[a,i,r]),m=l.useCallback(S=>{const j=e.find(y=>y.routeId===S.routeId&&y.streamSource==="native");j&&(r(j.tabKey),i("chat"),a(j))},[e,a,i,r]),h=l.useCallback(()=>{a(t),i("inbox")},[a,t,i]),f=l.useCallback((S,j="inbox")=>{c(S),o(),d("machines"),u(j),i("machine")},[o,u,i,d,c]),x=l.useCallback(S=>{const j=sn(S);j&&f(j,"chat")},[f]),b=l.useCallback(()=>{o(),i(n)},[n,o,i]),g=l.useCallback(S=>{d(S),i("inbox")},[i,d]);return{openConversation:p,openNativeConversation:m,backFromConversation:h,openMachine:f,openConversationMachine:x,backFromMachine:b,changeMachineSection:g}}function bo(e,t){return e.category!==t?!1:t==="ide"?!0:e.enabled===!0}function TP(e){const t=e.trim();return t?t[0].toUpperCase():"?"}function IP({conversations:e,hiddenConversations:t,ides:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,userName:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,onOpenHistory:x,onOpenRemote:b,onStopCli:g,wsStatus:S,isConnected:j,initialDataLoaded:y=!0,onShowAllHiddenConversations:k,onHideConversation:v,onOpenMeshGraph:C,onOpenNewSession:w,liveSessionInboxState:N,setCliViewModeOverrides:T}){const[A,P]=l.useState(()=>{var X;return((X=e[0])==null?void 0:X.tabKey)||null}),[D,L]=l.useState(()=>e[0]?"chat":"inbox"),[I,R]=l.useState("chats"),[_,M]=l.useState(null),[$,V]=l.useState("inbox"),z=l.useRef([]),W=Qn(),F="1.0.59",B=l.useMemo(()=>e.find(X=>X.tabKey===A)||e[0]||null,[e,A]),E=l.useMemo(()=>B?n.find(X=>X.id===B.routeId):void 0,[n,B]),H=l.useMemo(()=>!B||gt(B)||!vt(B)?null:ja(B),[B]),J=l.useMemo(()=>n.filter(X=>X.type==="adhdev-daemon").sort(Sr),[n]),q=l.useMemo(()=>J.find(X=>X.id===_)||null,[J,_]),ie=pi({sendDaemonCommand:o,activeConv:B||void 0,setActionLogs:r,isStandalone:i}),xe=NP({sendDaemonCommand:o,navigate:W,ides:n,conversations:e}),Y=oA(e),ne=l.useMemo(()=>e.map(X=>{const te=D==="chat"&&(B==null?void 0:B.tabKey)===X.tabKey,de=ai(X,N,{hideOpenTaskCompleteUnread:!0,isOpenConversation:te}),ve=Bn(X),fe=Sf(X),U=Pf(X,fe);return{conversation:X,timestamp:ve,preview:U,unread:de.unread,requiresAction:de.requiresAction,isWorking:de.isWorking,inboxBucket:de.inboxBucket}}),[e,N,D,B,Y]),{markConversationRead:me}=wP({conversations:e,machineEntries:J,items:ne,selectedConversation:B,selectedTabKey:A,screen:D,liveSessionInboxState:N,sendDaemonCommand:o,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,setSelectedTabKey:P,setScreen:L,setSelectedMachineId:M,setSection:R,setMachineBackTarget:V,resetMachineAction:xe.resetMachineAction}),ce=AP({conversations:e,selectedConversation:B,machineBackTarget:$,markConversationRead:me,resetMachineAction:xe.resetMachineAction,setSelectedTabKey:P,setScreen:L,setSelectedMachineId:M,setSection:R,setMachineBackTarget:V}),{isMuted:ae,toggleMute:he}=Sg(N,o),{attentionItems:oe,unreadItems:re,workingItems:ee,completedItems:G}=l.useMemo(()=>bP(ne,z.current),[ne]);l.useEffect(()=>{z.current=ee.map(X=>X.conversation.tabKey)},[ee]);const Q=l.useMemo(()=>q?ne.filter(X=>sn(X.conversation)===q.id):[],[ne,q]),ue=l.useMemo(()=>xP(q,n),[n,q]),pe=!!q&&gd(q,Dn(q,F)),Ae=l.useMemo(()=>(q==null?void 0:q.availableProviders)||[],[q]),Me=l.useMemo(()=>Ae.filter(X=>bo(X,"cli")).map(X=>({type:X.type,displayName:X.displayName||X.type,icon:X.icon})),[Ae]),He=l.useMemo(()=>Ae.filter(X=>bo(X,"acp")).map(X=>({type:X.type,displayName:X.displayName||X.type,icon:X.icon})),[Ae]),je=l.useMemo(()=>vP(J,ne,t),[ne,J,t]),Z=l.useMemo(()=>bi(n,y),[n,y]),O=l.useCallback(async X=>{q&&await xe.handleOpenRecent(q.id,X)},[xe,q]);return s.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:D==="chat"&&B?s.jsx(oP,{selectedConversation:B,isAcp:gt(B),isStandalone:i,selectedIdeEntry:E,actionLogs:a,userName:c,commands:ie,onBack:ce.backFromConversation,onOpenNativeConversation:ce.openNativeConversation,onOpenMachine:ce.openConversationMachine,onOpenHistory:x,onOpenRemote:b,onOpenMeshGraph:C,onStopCli:g,cliViewMode:H,onSetCliViewMode:async X=>{await ag({conversation:B,mode:X,ides:n,sendDaemonCommand:o,setCliViewModeOverrides:T})}}):D==="machine"&&q?s.jsx(hP,{selectedMachineEntry:q,selectedMachineConversations:Q,selectedMachineRecentLaunches:ue,cliProviders:Me,acpProviders:He,selectedMachineNeedsUpgrade:pe,appVersion:F,machineAction:xe.machineAction,isStandalone:i,section:I,showBottomNav:$==="inbox",onBack:ce.backFromMachine,onSectionChange:ce.changeMachineSection,onOpenConversation:ce.openConversation,onOpenRecent:O,onOpenMachineDetails:()=>W(`/machines/${q.id}`),onMachineUpgrade:()=>xe.handleMachineUpgrade(q.id),onLaunchDetectedIde:(X,te)=>xe.handleLaunchDetectedIde(q.id,X,te),onAddWorkspace:(X,te)=>xe.handleAddWorkspace(q.id,X,te),onBrowseDirectory:X=>xe.handleBrowseDirectory(q.id,X),onLaunchWorkspaceProvider:(X,te,de)=>xe.handleLaunchWorkspaceProvider(q.id,X,te,de),onListSavedSessions:X=>xe.handleListSavedSessions(q.id,X)}):s.jsx(lP,{section:I,attentionItems:oe,unreadItems:re,workingItems:ee,completedItems:G,hiddenConversations:t,machineCards:je,getAvatarText:TP,actionLogs:a,sendDaemonCommand:o,onOpenConversation:ce.openConversation,onShowAllHidden:k,onHideConversation:v,onOpenMeshGraph:C,onStopCli:g,onOpenNewSession:w,onOpenMachine:ce.openMachine,onOpenSettings:()=>W("/settings"),onSectionChange:R,wsStatus:S,isConnected:j,initialDataLoaded:y,conversationsLoaded:Z,isStandalone:i,isConversationMuted:ae,onToggleMuteConversation:he})})}function al(e,t){return!!(e<4&&t&&window.innerWidth>=768)}function PP({conversations:e,numGroups:t,onMoveTab:n,onReceiveTab:a,onOwnTabDrop:o,onClearPreviewOrder:r}){const i=l.useRef(0),[c,d]=l.useState(!1),[u,p]=l.useState(null),m=l.useCallback(()=>{i.current=0,d(!1),p(null)},[]);l.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=l.useCallback(g=>{g.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,d(!0))},[]),f=l.useCallback(g=>{if(!g.dataTransfer.types.includes("text/tab-key"))return;if(g.preventDefault(),!al(t,n)){p("merge");return}const S=g.currentTarget.getBoundingClientRect(),j=g.clientX-S.left,y=S.width/3;j<y?p("split-left"):j>y*2?p("split-right"):p("merge")},[t,n]),x=l.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,d(!1),p(null))},[]),b=l.useCallback(g=>{i.current=0,d(!1);const S=g.dataTransfer.getData("text/tab-key"),j=S?e.some(k=>k.tabKey===S):!1,y=u;if(p(null),r(),!!S){if(g.preventDefault(),y==="split-left"&&al(t,n)){n==null||n(S,"split-left");return}if(y==="split-right"&&al(t,n)){n==null||n(S,"split-right");return}if(j){o(S);return}a==null||a(S)}},[e,u,t,n,a,o,r]);return{dragOver:c,dropAction:u,resetDragState:m,handleDragEnter:h,handleDragOver:f,handleDragLeave:x,handleDrop:b}}function LP(e,t){const n=new Set(t.map(r=>r.tabKey)),a=e.filter(r=>n.has(r)),o=t.filter(r=>!e.includes(r.tabKey)).map(r=>r.tabKey);return[...a,...o]}function DP({conversations:e,initialActiveTabId:t,initialTabOrder:n,onActiveTabChange:a,onTabOrderChange:o}){const[r,i]=l.useState(t??null),[c,d]=l.useState(n??[]),[u,p]=l.useState(null),m=l.useRef(null),h=l.useRef(null),f=l.useRef(a),x=l.useRef(o);l.useEffect(()=>{f.current=a},[a]),l.useEffect(()=>{x.current=o},[o]),l.useEffect(()=>{t&&t!==r&&i(t)},[t,r]),l.useEffect(()=>{d(w=>{const N=LP(w,e);return N.length===w.length&&N.every((T,A)=>T===w[A])?w:N})},[e]);const b=l.useMemo(()=>{const w=u??c;if(w.length===0)return e;const N=new Map(w.map((T,A)=>[T,A]));return[...e].sort((T,A)=>{const P=N.get(T.tabKey)??999,D=N.get(A.tabKey)??999;return P-D})},[e,u,c]);l.useEffect(()=>{var N,T;if(b.length===0){r!==null&&(i(null),(N=f.current)==null||N.call(f,null));return}if(r&&b.some(A=>A.tabKey===r))return;const w=b[0].tabKey;w!==r&&(i(w),(T=f.current)==null||T.call(f,w))},[b,r]);const g=l.useMemo(()=>b.find(w=>w.tabKey===r),[b,r]),S=l.useCallback(w=>{var N;i(w),(N=f.current)==null||N.call(f,w)},[]),j=l.useCallback((w,N,T)=>{d(A=>{var I;const P=A.filter(R=>R!==w),D=P.indexOf(N);if(D<0)return A;const L=T==="left"?D:D+1;return P.splice(L,0,w),(I=x.current)==null||I.call(x,P),P}),p(null)},[]),y=l.useCallback((w,N,T)=>{const P=(c.length>0?c:e.map(I=>I.tabKey)).filter(I=>I!==w),D=P.indexOf(N);if(D<0)return;const L=T==="left"?D:D+1;P.splice(L,0,w),m.current=P,p(P)},[c,e]),k=l.useCallback(()=>{var N;const w=m.current;w&&(d(w),(N=x.current)==null||N.call(x,w))},[]),v=l.useCallback(()=>{m.current=null,p(null)},[]),C=l.useCallback(w=>{d(N=>{var A;const T=N.filter(P=>P!==w);return T.push(w),(A=x.current)==null||A.call(x,T),T})},[]);return{activeTabId:r,activeConv:g,sortedConversations:b,previewOrderRef:m,draggingTabRef:h,selectTab:S,handleTabReorder:j,updatePreviewOrder:y,commitPreviewOrder:k,clearPreviewOrder:v,moveTabToEnd:C,setDraggingTabKey:w=>{h.current=w}}}function MP({dropAction:e,canSplit:t}){return s.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),s.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function kd({conversationsCount:e,isSplitMode:t,isStandalone:n,hasRegisteredMachines:a=!1,suppressGuide:o=!1,onOpenNewSession:r,isLoading:i=!1}){const{t:c}=ye("common");if(o)return s.jsx("div",{className:"text-sm text-text-muted opacity-0 select-none","aria-hidden":"true",children:c("paneGroup.noActiveAgent")});if(i)return s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center gap-3 -mt-8 text-text-muted",children:[s.jsx(Cs,{}),s.jsx("p",{className:"text-sm",children:c("paneGroup.loadingSessions")})]});const d=!n&&!a,u=a&&!!r,p=c(a?"paneGroup.noConversations":n?"paneGroup.waitingForDaemon":"paneGroup.connectYourMachines"),m=c(a?"paneGroup.newSessionDescription":n?"paneGroup.daemonDescription":"paneGroup.installDescription");return e===0&&!t?s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[s.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),s.jsxs("div",{className:"text-center max-w-lg",children:[s.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:p}),s.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:m}),u&&s.jsx("div",{className:"flex items-center justify-center mb-4",children:s.jsxs("button",{type:"button",onClick:r,className:"btn btn-primary btn-sm inline-flex items-center gap-2",title:c("paneGroup.newSession"),"aria-label":c("paneGroup.newSession"),children:[s.jsx(co,{size:14}),s.jsx("span",{children:c("paneGroup.newSession")})]})}),d&&s.jsx(xg,{}),d&&s.jsx("div",{className:"mt-8",children:s.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:c("machine.card.emptyDocsLink")})})]})]}):s.jsx("div",{className:"text-sm text-text-muted opacity-50",children:c(t?"paneGroup.moveTabHere":"paneGroup.noActiveAgent")})}const jg="adhdev-tab-shortcuts";function Ng(){try{return JSON.parse(localStorage.getItem(jg)||"{}")}catch{return{}}}function Ag({enabled:e=!0,sortedTabKeys:t,onFocus:n,onSelectTab:a}){const o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[r,i]=l.useState(()=>Ng()),[c,d]=l.useState(null),u=l.useCallback(m=>{const h=[];return m.metaKey&&h.push(o?"⌘":"Meta"),m.ctrlKey&&h.push("Ctrl"),m.altKey&&h.push(o?"⌥":"Alt"),m.shiftKey&&h.push(o?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(m.key)?null:(h.push(m.key.length===1?m.key.toUpperCase():m.key),h.join("+"))},[o]),p=l.useCallback(m=>{i(m);try{localStorage.setItem(jg,JSON.stringify(m))}catch{}},[]);return l.useEffect(()=>{if(!e||!c)return;const m=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){d(null);return}const f=u(h);if(!f)return;const x={...r};for(const[b,g]of Object.entries(x))g===f&&delete x[b];x[c]=f,p(x),d(null)};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[e,c,r,p,u]),l.useEffect(()=>{if(!e)return;const m=h=>{if(!(!h.ctrlKey&&!h.metaKey&&!h.altKey)){for(const[f,x]of Object.entries(r))if(t.includes(f)&&u(h)===x){h.preventDefault(),n(),a(f);return}}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[e,r,t,n,a,u]),{isMac:o,tabShortcuts:r,shortcutListening:c,setShortcutListening:d,saveShortcuts:p}}const ol=e=>{e.preventDefault()},RP=l.memo(function({conv:t,isActive:n,isDraggedTab:a,isTaskCompleteUnread:o,shortcut:r,conversationKeys:i,draggingTabRef:c,onFocus:d,onSelectTab:u,onConversationActivated:p,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:f,onClearPreviewOrder:x,onDragStateReset:b,onDragTabKeyChange:g,onReceiveTab:S,onOpenContextMenu:j,longPressTimer:y,isGroupActive:k}){const v=Xn(t),C=v.isGenerating?"agent-tab-generating":v.isWaiting?"agent-tab-waiting":"",w=v.isReconnecting,N=YA(t),T=QA(t),A=If(t),P=l.useCallback(z=>{c.current=t.tabKey,g(t.tabKey),z.dataTransfer.setData("text/tab-key",t.tabKey),z.dataTransfer.effectAllowed="move"},[t.tabKey,c,g]),D=l.useCallback(()=>{c.current=null,g(null),f(),x(),b()},[c,g,f,x,b]),L=l.useCallback(z=>{const W=c.current;if(!(!W||W===t.tabKey)&&z.dataTransfer.types.includes("text/tab-key")){z.preventDefault(),z.stopPropagation();const F=z.currentTarget.getBoundingClientRect(),B=z.clientX<F.left+F.width/2?"left":"right";m(W,t.tabKey,B)}},[t.tabKey,c,m]),I=l.useCallback(z=>{z.preventDefault(),z.stopPropagation();const W=z.dataTransfer.getData("text/tab-key");if(W&&W!==t.tabKey){const F=z.currentTarget.getBoundingClientRect(),B=z.clientX<F.left+F.width/2?"left":"right";i.includes(W)?h(W,t.tabKey,B):S&&S(W)}x()},[t.tabKey,i,h,S,x]),R=l.useCallback(z=>{z.stopPropagation(),d(),u(t.tabKey),p(t)},[t,p,d,u]),_=l.useCallback(z=>{z.preventDefault(),j(z.clientX,z.clientY,t.tabKey)},[t.tabKey,j]),M=l.useCallback(z=>{const W=z.touches[0];y.current=setTimeout(()=>{j(W.clientX,W.clientY,t.tabKey)},600)},[t.tabKey,y,j]),$=l.useCallback(()=>{y.current&&clearTimeout(y.current)},[y]),V=["adhdev-dockview-tab",C,n&&"is-active",k&&"is-group-active",w&&"is-reconnecting"].filter(Boolean).join(" ");return s.jsxs("div",{"data-tabkey":t.tabKey,className:V,draggable:!0,onDragStart:P,onDragEnd:D,onDragOver:L,onDrop:I,onClick:R,onContextMenu:_,onTouchStart:M,onTouchEnd:$,onTouchMove:$,style:{position:"relative",cursor:"pointer",opacity:a?.4:void 0},children:[A&&s.jsx("span",{className:"adhdev-dockview-tab-mesh-badge pointer-events-none absolute top-0.5 right-0.5 text-text-muted",title:"Mesh chat","aria-label":"Mesh chat",children:s.jsx(js,{size:11})}),o&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status",children:v.isGenerating?s.jsx(Cs,{size:12,thickness:2,color:"success"}):v.isWaiting?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):w?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):v.isConnecting?s.jsx(Cs,{size:12,thickness:2}):t.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),N.length>0&&s.jsx("span",{className:"adhdev-dockview-tab-mesh-role",title:T,"aria-label":T||N.join(" · "),children:N.join(" · ")}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("span",{className:"adhdev-dockview-tab-primary",title:At(t),children:At(t)}),s.jsxs("span",{className:"adhdev-dockview-tab-meta inline-flex min-w-0 items-center gap-1",children:[w?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting truncate",children:Hn(t)}):v.isConnecting?s.jsxs("span",{className:"adhdev-dockview-tab-connecting truncate",children:[Hn(t),s.jsx("span",{className:"connecting-dots"})]}):s.jsx("span",{className:"truncate",children:Hn(t)}),s.jsx(Pr,{git:t.git,compact:!0,className:"max-w-[6.5rem] shrink-0"})]})]}),r&&s.jsx("span",{className:"text-4xs opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:r,children:r})]})},(e,t)=>e.conv===t.conv&&e.isActive===t.isActive&&e.isDraggedTab===t.isDraggedTab&&e.isTaskCompleteUnread===t.isTaskCompleteUnread&&e.shortcut===t.shortcut&&e.conversationKeys===t.conversationKeys&&e.isGroupActive===t.isGroupActive);function _P({conversations:e,activeTabId:t,groupIndex:n,unreadTabKeys:a,draggingTabRef:o,onFocus:r,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:u,onCommitPreviewOrder:p,onClearPreviewOrder:m,onDragStateReset:h,onDragTabKeyChange:f,onReceiveTab:x,onHideTab:b,isGroupActive:g,allowTabShortcuts:S=!0}){const{t:j}=ye("common"),[y,k]=l.useState(null),v=l.useRef(null),C=l.useRef(null),w=l.useMemo(()=>e.map(I=>I.tabKey),[e]);ko("PaneGroupTabBar",{groupIndex:n,activeTabId:t,tabCount:e.length,ctxMenuTab:(y==null?void 0:y.tabKey)||null});const{isMac:N,tabShortcuts:T,shortcutListening:A,setShortcutListening:P,saveShortcuts:D}=Ag({enabled:S,sortedTabKeys:e.map(I=>I.tabKey),onFocus:r,onSelectTab:i});l.useEffect(()=>{if(!y)return;const I=R=>{const _=document.querySelector("[data-pane-context-menu]");_&&_.contains(R.target)||k(null)};return window.addEventListener("mousedown",I,!0),()=>window.removeEventListener("mousedown",I,!0)},[y]),l.useEffect(()=>{const I=C.current;if(!I)return;const R=_=>{Math.abs(_.deltaY)<=Math.abs(_.deltaX)||(_.preventDefault(),I.scrollLeft+=_.deltaY)};return I.addEventListener("wheel",R,{passive:!1}),()=>I.removeEventListener("wheel",R)},[]);const L=l.useCallback((I,R,_)=>{k({x:I,y:R,tabKey:_})},[]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:s.jsxs("div",{ref:C,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none",overscrollBehaviorX:"contain"},children:[e.map(I=>s.jsx(RP,{conv:I,isActive:t===I.tabKey,isDraggedTab:o.current===I.tabKey,isTaskCompleteUnread:a.has(I.tabKey),shortcut:S?T[I.tabKey]:void 0,conversationKeys:w,draggingTabRef:o,onFocus:r,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:u,onCommitPreviewOrder:p,onClearPreviewOrder:m,onDragStateReset:h,onDragTabKeyChange:f,onReceiveTab:x,onOpenContextMenu:L,longPressTimer:v,isGroupActive:g},I.tabKey)),e.length===0&&s.jsx("div",{className:"p-2 text-xs opacity-40",children:j("paneGroup.noTabsInGroup")})]})}),y&&s.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:y.x,top:y.y},children:[S&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onMouseDown:ol,onClick:I=>{I.stopPropagation(),P(y.tabKey),k(null)},children:["⌨ ",T[y.tabKey]?`Change shortcut (${T[y.tabKey]})`:"Set shortcut"]}),T[y.tabKey]&&s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onMouseDown:ol,onClick:()=>{const I={...T};delete I[y.tabKey],D(I),k(null)},children:"✕ Remove shortcut"})]}),b&&s.jsxs(s.Fragment,{children:[S&&s.jsx("div",{className:"border-t border-border-subtle my-1"}),s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onMouseDown:ol,onClick:()=>{b(y.tabKey),k(null)},children:s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(Xr,{size:12}),"Hide from Dashboard"]})})]})]}),S&&A&&s.jsx(xs,{children:s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-center justify-center bg-black/50",style:{backdropFilter:"blur(2px)"},onClick:()=>P(null),children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:I=>I.stopPropagation(),children:[s.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),s.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),s.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),s.jsx("div",{className:"text-3xs text-text-muted mt-3",children:j("paneGroup.pressEscToCancel")})]})})})]})}function EP({conversations:e,ides:t,clearedTabs:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d=!0,userName:u,groupIndex:p,onFocus:m,isSplitMode:h,numGroups:f,onMoveTab:x,onReceiveTab:b,style:g,onActiveTabChange:S,initialActiveTabId:j,initialTabOrder:y,onTabOrderChange:k,onHideTab:v,isFocused:C,allowTabShortcuts:w=!0,onOpenNewSession:N,liveSessionInboxState:T}){const{sendCommand:A}=wt(),P=l.useRef(null),{activeTabId:D,activeConv:L,sortedConversations:I,draggingTabRef:R,selectTab:_,handleTabReorder:M,updatePreviewOrder:$,commitPreviewOrder:V,clearPreviewOrder:z,moveTabToEnd:W,setDraggingTabKey:F}=DP({conversations:e,initialActiveTabId:j,initialTabOrder:y,onActiveTabChange:S,onTabOrderChange:k}),B=pi({sendDaemonCommand:o,activeConv:L,setActionLogs:r,isStandalone:i}),{dragOver:E,dropAction:H,resetDragState:J,handleDragEnter:q,handleDragOver:ie,handleDragLeave:xe,handleDrop:Y}=PP({conversations:e,numGroups:f,onMoveTab:x,onReceiveTab:b,onOwnTabDrop:W,onClearPreviewOrder:z}),ne=L&&!gt(L)&&ja(L)==="terminal",me=l.useMemo(()=>L?t.find(oe=>oe.id===L.routeId):void 0,[t,L]),ce=l.useMemo(()=>L?a.filter(oe=>oe.routeId===L.tabKey):[],[a,L]),ae=l.useMemo(()=>new Set(I.filter(oe=>Py(oe,T,{isOpenConversation:oe.tabKey===D})).map(oe=>oe.tabKey)),[D,T,I]);ko("PaneGroup",{groupIndex:p,conversationCount:e.length,activeTabId:D,dragOver:E});const he=l.useCallback(oe=>{oe.streamSource==="agent-stream"&&oe.agentType&&A(oe.routeId,df(),{agentType:oe.agentType,...oe.sessionId&&{targetSessionId:oe.sessionId}}).catch(()=>{})},[A]);return s.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:m,style:{...g,outline:E?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[s.jsx(_P,{conversations:I,activeTabId:D,groupIndex:p,numGroups:f,unreadTabKeys:ae,draggingTabRef:R,onFocus:m,onSelectTab:_,onConversationActivated:he,onPreviewReorder:$,onReorderTab:M,onCommitPreviewOrder:V,onClearPreviewOrder:z,onDragStateReset:J,onDragTabKeyChange:F,onMoveTab:x,onReceiveTab:b,onHideTab:v,isGroupActive:C??!1,allowTabShortcuts:w}),s.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:q,onDragOver:ie,onDragLeave:xe,onDrop:Y,children:[E&&s.jsx(MP,{dropAction:H,canSplit:!!(f<4&&x)}),L?s.jsx(yd,{activeConv:L,clearToken:n[L.tabKey]||0,isCliTerminal:!!ne,ideEntry:me,terminalRef:P,commands:B,actionLogs:ce,userName:u,isInputActive:!h||!!C}):s.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:s.jsx(kd,{conversationsCount:e.length,isSplitMode:h,isStandalone:i,hasRegisteredMachines:c,onOpenNewSession:N,isLoading:!bi(t,d)})})]})]})}function HP({containerRef:e,isSplitMode:t,numGroups:n,groupSizes:a,groupedConvs:o,clearedTabs:r,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:u,isStandalone:p,hasRegisteredMachines:m,initialDataLoaded:h,userName:f,focusedGroup:x,focusGroup:b,moveTabToGroup:g,splitTabRelative:S,closeGroup:j,handleResizeStart:y,groupActiveTabIds:k,setGroupActiveTab:v,groupTabOrders:C,setGroupTabOrder:w,toggleHiddenTab:N,onOpenNewSession:T,allowTabShortcuts:A=!0,liveSessionInboxState:P}){return s.jsx("div",{ref:e,className:`flex-1 min-h-0 flex ${t?"flex-row":"flex-col"} overflow-hidden`,children:o.map((D,L)=>{const I=t&&a.length===n?`${a[L]}%`:void 0;return s.jsxs(jt.Fragment,{children:[t&&L>0&&s.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:R=>y(L-1,R),onDoubleClick:()=>j(L),title:"Drag to resize · Double-click to merge",children:s.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),s.jsx(EP,{style:t?{flexBasis:I??`${100/n}%`,flexGrow:I?0:1,flexShrink:I?0:1}:void 0,conversations:D,clearedTabs:r,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:u,isStandalone:p,hasRegisteredMachines:m,initialDataLoaded:h,userName:f,groupIndex:L,isFocused:t&&x===L,onFocus:()=>b(L),isSplitMode:t,numGroups:n,onMoveTab:(R,_)=>{_==="left"&&L>0?g(R,L-1):_==="right"&&L<n-1?g(R,L+1):_==="split-left"&&n<4?S(R,L,"left"):_==="split-right"&&n<4&&S(R,L,"right")},onReceiveTab:R=>g(R,L),onActiveTabChange:R=>v(L,R),initialActiveTabId:k[L],initialTabOrder:C[L],onTabOrderChange:R=>w(L,R),onHideTab:N,onOpenNewSession:T,allowTabShortcuts:A,liveSessionInboxState:P})]},L)})})}const Tg="adhdev-dashboard-action-shortcuts",FP=1200,$P=[["toggleHiddenTabs","G H"],["openNewSession","N"],["setActiveTabShortcut","G S"],["selectPreviousGroupTab","G K"],["selectPreviousGroupTab","T ←"],["selectPreviousGroupTab","⌥+["],["selectPreviousGroupTab","Ctrl+Alt+["],["selectNextGroupTab","G J"],["selectNextGroupTab","T →"],["selectNextGroupTab","⌥+]"],["selectNextGroupTab","Ctrl+Alt+]"],["splitActiveTabDown","S ↓"],["splitActiveTabDown","⌘+⌥+-"],["splitActiveTabDown","Ctrl+Alt+-"],["splitActiveTabRight","S →"],["splitActiveTabRight","⌘+⌥+\\"],["splitActiveTabRight","⌘+⌥+="],["splitActiveTabRight","Ctrl+Alt+\\"],["focusLeftPane","F ←"],["focusLeftPane","⌘+⌥+←"],["focusLeftPane","⌘+⌥+["],["focusLeftPane","Ctrl+Alt+←"],["focusRightPane","F →"],["focusRightPane","⌘+⌥+→"],["focusRightPane","⌘+⌥+]"],["focusRightPane","Ctrl+Alt+→"],["focusUpPane","F ↑"],["focusUpPane","⌘+⌥+U"],["focusUpPane","Ctrl+Alt+↑"],["focusDownPane","F ↓"],["focusDownPane","⌘+⌥+J"],["focusDownPane","Ctrl+Alt+↓"],["moveActiveTabToLeftPane","M ←"],["moveActiveTabToLeftPane","⌘+⌥+⇧+←"],["moveActiveTabToLeftPane","⌘+⌥+,"],["moveActiveTabToLeftPane","Ctrl+Alt+Shift+←"],["moveActiveTabToRightPane","M →"],["moveActiveTabToRightPane","⌘+⌥+⇧+→"],["moveActiveTabToRightPane","⌘+⌥+."],["moveActiveTabToRightPane","Ctrl+Alt+Shift+→"],["moveActiveTabToUpPane","M ↑"],["moveActiveTabToUpPane","⌘+⌥+I"],["moveActiveTabToUpPane","Ctrl+Alt+Shift+↑"],["moveActiveTabToDownPane","M ↓"],["moveActiveTabToDownPane","⌘+⌥+K"],["moveActiveTabToDownPane","Ctrl+Alt+Shift+↓"],["triggerPrimaryApprovalAction","⌥+A"],["triggerSecondaryApprovalAction","⌥+D"],["toggleCliView","T"]];function BP(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function xt(e,t){switch(e){case"openShortcutHelp":return"?";case"openNewSession":return t?"⌘+⇧+Enter":"Ctrl+Shift+Enter";case"hideCurrentTab":return t?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return t?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return t?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return t?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return t?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return t?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return t?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return t?"⌘+Ctrl+⇧+→":"Ctrl+Alt+Shift+→";case"splitActiveTabDown":return t?"⌘+Ctrl+⇧+↓":"Ctrl+Alt+Shift+↓";case"focusLeftPane":return"";case"focusRightPane":return"";case"focusUpPane":return"";case"focusDownPane":return"";case"moveActiveTabToLeftPane":return"";case"moveActiveTabToRightPane":return"";case"moveActiveTabToUpPane":return"";case"moveActiveTabToDownPane":return"";case"triggerPrimaryApprovalAction":return t?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return t?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return t?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return t?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return t?"⌘+⇧+←":"Ctrl+Shift+←";case"selectNextGroupTab":return t?"⌘+⇧+→":"Ctrl+Shift+→";case"toggleCliView":return t?"⌥+T":"Ctrl+Alt+T"}}function Ig(e){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:xt("openShortcutHelp",e)},{id:"openNewSession",label:"New session",description:"Open the new session launcher.",defaultShortcut:xt("openNewSession",e)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:xt("hideCurrentTab",e)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:xt("toggleHiddenTabs",e)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:xt("openHistoryForActiveTab",e)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:xt("openRemoteForActiveTab",e)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:xt("floatActiveTab",e)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:xt("popoutActiveTab",e)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:xt("dockActiveTab",e)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:xt("splitActiveTabRight",e)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:xt("splitActiveTabDown",e)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:xt("focusLeftPane",e)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:xt("focusRightPane",e)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:xt("focusUpPane",e)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:xt("focusDownPane",e)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:xt("moveActiveTabToLeftPane",e)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:xt("moveActiveTabToRightPane",e)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:xt("moveActiveTabToUpPane",e)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:xt("moveActiveTabToDownPane",e)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:xt("triggerPrimaryApprovalAction",e)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:xt("triggerSecondaryApprovalAction",e)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:xt("triggerTertiaryApprovalAction",e)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:xt("setActiveTabShortcut",e)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:xt("selectPreviousGroupTab",e)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:xt("selectNextGroupTab",e)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:xt("toggleCliView",e)}]}function gc(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"}function $r(e){const t=Object.fromEntries(Ig(e).map(n=>[n.id,n.defaultShortcut]));try{const n=JSON.parse(localStorage.getItem(Tg)||"{}"),a={...t,...n};for(const[o,r]of $P)a[o]===r&&(a[o]=t[o]);return a}catch{return t}}function Pg(e){return e===" "?"Space":e==="Escape"?"Esc":e==="ArrowLeft"?"←":e==="ArrowRight"?"→":e==="ArrowUp"?"↑":e==="ArrowDown"?"↓":e.length===1?e.toUpperCase():e}function WP({enabled:e=!0,onTrigger:t}){const n=BP(),[a,o]=l.useState(()=>$r(n)),[r,i]=l.useState(null),[c,d]=l.useState([]),u=l.useRef({parts:[],timer:null}),p=l.useCallback(b=>{const g=[];return b.metaKey&&g.push(n?"⌘":"Meta"),b.ctrlKey&&g.push("Ctrl"),b.altKey&&g.push(n?"⌥":"Alt"),b.shiftKey&&b.key.length!==1&&g.push(n?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(b.key)?null:(g.push(Pg(b.key)),g.join("+"))},[n]),m=l.useCallback(b=>{o(b);try{localStorage.setItem(Tg,JSON.stringify(b))}catch{}},[]);l.useEffect(()=>{const b=$r(n),g=Object.entries(a),S=Object.entries(b);g.length===S.length&&g.every(([j,y])=>b[j]===y)||m(b)},[a,n,m]);const h=l.useCallback(()=>{typeof window<"u"&&u.current.timer!=null&&window.clearTimeout(u.current.timer),u.current={parts:[],timer:null}},[]),f=l.useCallback(()=>{typeof window>"u"||(u.current.timer!=null&&window.clearTimeout(u.current.timer),u.current.timer=window.setTimeout(()=>{u.current={parts:[],timer:null}},FP))},[]);l.useEffect(()=>{if(!r)return;const b=g=>{if(g.preventDefault(),g.stopPropagation(),g.key==="Escape"){i(null),d([]);return}const S=p(g);if(!S)return;const y=!(g.metaKey||g.ctrlKey||g.altKey)&&/^[A-Z0-9]$/.test(S);if(c.length===0&&y){d([S]);return}const v=[...c,S].slice(0,2).join(" "),C={...a};for(const[w,N]of Object.entries(C))N===v&&delete C[w];C[r]=v,m(C),i(null),d([])};return window.addEventListener("keydown",b,!0),()=>window.removeEventListener("keydown",b,!0)},[a,p,m,r,c]),l.useEffect(()=>{if(!e||r)return;const b=g=>{if(g.defaultPrevented)return;const S=p(g);if(!S)return;const j=g.metaKey||g.ctrlKey||g.altKey;if(gc(g.target))return;const y=u.current.parts,k=j?[S]:[...y.slice(-1),S].slice(-2),v=k.join(" "),C=k[k.length-1],w=Object.entries(a).filter(([,D])=>!!D),N=w.find(([,D])=>D===v);if(N){g.preventDefault(),h(),t(N[0]);return}if(w.some(([,D])=>D.startsWith(`${v} `))){g.preventDefault(),u.current.parts=k,f();return}const A=w.find(([,D])=>D===C);if(A){g.preventDefault(),h(),t(A[0]);return}if(w.some(([,D])=>D.startsWith(`${C} `))){g.preventDefault(),u.current.parts=[C],f();return}h()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[a,f,e,p,t,h,r]),l.useEffect(()=>()=>h(),[h]);const x=l.useMemo(()=>Ig(n),[n]);return{isMac:n,actionDefinitions:x,actionShortcuts:a,shortcutListening:r,shortcutListeningDraft:c,setShortcutListening:i,setShortcutListeningDraft:d,saveShortcuts:m}}function OP({isTabInPopout:e,isTabFloating:t,tabShortcut:n,actionShortcuts:a}){const o=[];return e?(t&&o.push({type:"action",id:"dockInWindow",label:"Dock in window",shortcut:a.dockActiveTab}),o.push({type:"action",id:"moveBackToMain",label:"Move back to main window",shortcut:a.dockActiveTab})):t?o.push({type:"action",id:"dockBackToGrid",label:"Dock back to grid",shortcut:a.dockActiveTab}):o.push({type:"action",id:"floatAsPanel",label:"Float as panel",shortcut:a.floatActiveTab},{type:"action",id:"openInNewWindow",label:"Open in new window",shortcut:a.popoutActiveTab}),o.push({type:"separator",id:"before-shortcut-actions"},{type:"action",id:"setShortcut",label:n?`Change shortcut (${n})`:"Set shortcut",shortcut:a.setActiveTabShortcut}),n&&o.push({type:"action",id:"removeShortcut",label:"Remove shortcut",tone:"muted"}),o.push({type:"separator",id:"before-hide-tab"},{type:"action",id:"hideTab",label:"Hide tab",shortcut:a.hideCurrentTab,tone:"muted"}),o}function Lg(e){return e.some(t=>t.type!=="adhdev-daemon")||e.some(t=>t.type==="adhdev-daemon"&&!!t.machine)}function Dp({hasStoredLayout:e,initialDataLoaded:t,visibleConversationCount:n,ides:a}){return!e||n>0?!1:t?!Lg(a):!0}function UP({previousVisibleConversationCount:e,visibleConversationCount:t,ides:n}){return t>0||e<=0?!1:Lg(n)}const Dg=1e3,qP=4;function Mp(e,t){return t?e.clientX>=t.left&&e.clientX<=t.right&&e.clientY>=t.top&&e.clientY<=t.bottom:!1}function Rp(e,t,n){return Math.abs(t.clientX-e.clientX)>n||Math.abs(t.clientY-e.clientY)>n}function zP({detachDelayMs:e=Dg,stillnessThresholdPx:t=qP,onDetach:n,setTimeoutFn:a=globalThis.setTimeout.bind(globalThis),clearTimeoutFn:o=globalThis.clearTimeout.bind(globalThis)}){let r=null,i=null,c=null,d=null,u=null,p=!1;const m=()=>{u!=null&&(o(u),u=null)},h=()=>{m(),c=null},f=()=>{m(),r=null,i=null,c=null,d=null,p=!1},x=()=>{!r||!c||!d||p||u!=null||(u=a(()=>{u=null,!(!r||!c||!d||p)&&Mp(d,i)&&(Rp(c,d,t)||(p=!0,n({panelId:r,clientX:d.clientX,clientY:d.clientY})))},e))},b=S=>{if(!(!r||p)){if(!Mp(S,i)){d={clientX:S.clientX,clientY:S.clientY},h();return}(!c||Rp(c,S,t))&&(m(),c={clientX:S.clientX,clientY:S.clientY}),d={clientX:S.clientX,clientY:S.clientY},x()}},g=S=>{!r||p||(S&&(d={clientX:S.clientX,clientY:S.clientY}),h())};return{startDrag:S=>{m(),r=S.panelId,i=S.selfPanelBounds??null,c=null,d={clientX:S.clientX,clientY:S.clientY},p=!1},markSelfPanel:b,markNonSelfPanel:g,markNoDropTarget:g,markDockTarget:g,endDrag:f,isDragging:()=>r!=null,hasDetached:()=>p,dispose:f}}function GP(e=typeof window>"u"?null:window.localStorage){return(e==null?void 0:e.getItem("adhdev:dockviewIdleDragFloat"))!=="off"}function br(e){return At(e)||e.tabKey}function KP(e){return`remote:${e}`}function Ps(e){return e.startsWith("remote:")}function _p(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function rl(e){var a;const t=e==null?void 0:e.defaultView;if(!t)return;const n=o=>{if(o)try{o.focus({preventScroll:!0})}catch{try{o.focus()}catch{}}};try{t.focus(),n(e==null?void 0:e.body),n(e==null?void 0:e.documentElement),(a=t.requestAnimationFrame)==null||a.call(t,()=>{try{t.focus(),n(e==null?void 0:e.body)}catch{}})}catch{}}function il(e,t){e.classList.remove(Ml.className,Rl.className),e.classList.add(t==="light"?Ml.className:Rl.className)}function Ep(e){return e?Array.from(new Set(e.groups.map(t=>{var n,a;return(a=(n=t.element)==null?void 0:n.ownerDocument)==null?void 0:a.defaultView}).filter(t=>!!t&&t!==window))):[]}function VP(e,t,n){var i;const a=[t];let o;for(const c of a){let d;for(const u of c){const p=e.addPanel({id:u.tabKey,component:"conversation",title:br(u),params:{kind:"conversation",tabKey:u.tabKey},...d?{position:{referencePanel:d,direction:"within"},inactive:!0}:o?{position:{referencePanel:o,direction:"right"},inactive:!0}:{}});d||(d=p.id)}o=d??o}return n??((i=t[0])==null?void 0:i.tabKey)??null}function Hp(e,t){const n=new Set(t.map(o=>o.tabKey)),a=new Map;for(const o of t)a.set(o.tabKey,(a.get(o.tabKey)||0)+1);for(const o of[...e.panels])Ps(o.id)||n.has(o.id)||e.removePanel(o);for(const o of t){const r=e.getPanel(o.tabKey);if(r){(a.get(o.tabKey)||0)>1&&console.warn("[dashboard-conversations] Dockview panel already exists for duplicate tabKey",{tabKey:o.tabKey,daemonId:o.daemonId,sessionId:o.sessionId,providerSessionId:o.providerSessionId,panelId:r.id}),r.update({params:{tabKey:o.tabKey}}),r.title!==br(o)&&r.api.setTitle(br(o));continue}e.addPanel({id:o.tabKey,component:"conversation",title:br(o),params:{kind:"conversation",tabKey:o.tabKey},...e.activePanel?{position:{referencePanel:e.activePanel.id,direction:"within"},inactive:!0}:e.panels[0]?{position:{referencePanel:e.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Fp(e,t,n){var d,u;const a=n?KP(n):null;for(const p of[...e.panels])Ps(p.id)&&(!a||p.id!==a)&&e.removePanel(p);if(!n||!a)return;const o=_s(t,n);if(!o&&e.totalPanels===0)return;const r=e.getPanel(a),i=Mf(o);if(r){r.title!==i&&r.api.setTitle(i);return}const c=(o==null?void 0:o.tabKey)??((d=e.activePanel)==null?void 0:d.id)??((u=e.panels.find(p=>!Ps(p.id)))==null?void 0:u.id);e.addPanel({id:a,component:"remote",title:i,params:{kind:"remote",routeId:n},...c?{position:{referencePanel:c,direction:"right"},inactive:!0}:{}})}function Mg({doId:e,targetSessionId:t,connState:n,viewMode:a}){const[o,r]=l.useState(null),[i,c]=l.useState(null);l.useEffect(()=>e?_t.onScreenshot("ide-page",(p,m)=>{if(p!==e)return;const h=new FileReader;h.onload=()=>r(h.result),h.readAsDataURL(m)}):void 0,[e]),l.useEffect(()=>{n!=="connected"&&r(null)},[n]),l.useEffect(()=>{var p;return e?((p=_t.onStatus)==null?void 0:p.call(_t,(m,h)=>{m===e&&h!=null&&h.screenshotUsage&&c(h.screenshotUsage)}))||(()=>{}):void 0},[e]),l.useEffect(()=>{r(null)},[e,t]),l.useEffect(()=>{const u=e?_t.get(e):null;if(!(!u||n!=="connected"))return a!=="chat"&&t?u.startScreenshots(t):u.stopScreenshots(t),()=>{u.stopScreenshots(t)}},[a,n,t,e]);const d=l.useCallback(async(u,p)=>{const m=e?_t.get(e):null;return!m||n!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):m.sendInput(u,p,t)},[e,n,t]);return{connScreenshot:o,screenshotUsage:i,handleRemoteAction:d}}const Rg=l.createContext(null);function xi(){const e=l.useContext(Rg);if(!e)throw new Error("DashboardDockviewContext missing");return e}function YP(e){const[,t]=l.useState(0);l.useEffect(()=>{const n=()=>t(o=>o+1),a=[e.api.onDidActiveGroupChange(n),e.api.onDidTitleChange(n),e.api.onDidGroupChange(n),e.containerApi.onDidActivePanelChange(n)];return()=>{for(const o of a)o.dispose()}},[e.api,e.containerApi])}function QP({params:e}){var d;const t=xi(),n=l.useMemo(()=>_s([...t.conversationsByTabKey.values()],e.routeId),[t.conversationsByTabKey,e.routeId]),a=l.useMemo(()=>t.ides.find(u=>u.id===e.routeId),[t.ides,e.routeId]),o=(n==null?void 0:n.daemonId)||((d=n==null?void 0:n.routeId)==null?void 0:d.split(":")[0])||e.routeId.split(":")[0]||e.routeId,{connScreenshot:r,screenshotUsage:i,handleRemoteAction:c}=Mg({doId:o,targetSessionId:n?lf(n):(a==null?void 0:a.sessionId)||(a==null?void 0:a.instanceId),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote"});return n?s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:s.jsx(xh,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:r,screenshotUsage:i,transportType:n.transport,onAction:c})}):s.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function JP(){const e=xi();return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:s.jsx(kd,{conversationsCount:0,isSplitMode:!1,isStandalone:e.isStandalone,hasRegisteredMachines:e.hasRegisteredMachines,onOpenNewSession:e.onOpenNewSession,suppressGuide:e.hasDetachedConversationPanels,isLoading:!bi(e.ides,e.initialDataLoaded)})})}function XP(e){var j,y;YP(e);const t=xi(),n=l.useCallback(k=>{"button"in k&&k.button!==0||e.api.setActive()},[e.api]),a=e.params.kind==="remote"?void 0:t.conversationsByTabKey.get(e.params.tabKey),o=a==null?void 0:a.sessionId,r=l.useCallback(k=>TA(k),[]),i=l.useCallback(()=>AA(o),[o]),c=l.useSyncExternalStore(r,i,i);if(e.params.kind==="remote"){const k=_s([...t.conversationsByTabKey.values()],e.params.routeId),v=((j=e.api.group.activePanel)==null?void 0:j.id)===e.api.id,C=e.api.isGroupActive;return s.jsxs("div",{className:`adhdev-dockview-tab${v?" is-active":""}${C?" is-group-active":""}`,title:e.api.title||"Remote","data-tab-key":(k==null?void 0:k.tabKey)||"",onMouseDown:n,onTouchStart:n,children:[s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||"Remote"}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:k!=null&&k.machineName?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"Live remote view"}),s.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),s.jsx("span",{className:"adhdev-dockview-tab-machine",children:k.machineName})]}):s.jsx("span",{children:"Live remote view"})})]})]})}const d=t.conversationsByTabKey.get(e.params.tabKey);if(!d)return s.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":e.params.tabKey||"",children:s.jsx("div",{className:"adhdev-dockview-tab-copy",children:s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||e.params.tabKey})})});const u=((y=e.api.group.activePanel)==null?void 0:y.id)===e.api.id,p=e.api.isGroupActive,m=ai(d,t.liveSessionInboxState,{isOpenConversation:u}),h=m.isReconnecting,f=m.isConnecting,x=m.isGenerating||c,b=m.isWaiting,g=m.unread,S=t.tabShortcuts[d.tabKey];return s.jsxs("div",{className:`adhdev-dockview-tab${u?" is-active":""}${p?" is-group-active":""}${h?" is-reconnecting":""}`,title:At(d),"data-tab-key":e.params.tabKey,onMouseDown:n,onTouchStart:n,onContextMenu:k=>{var v;k.preventDefault(),n(k),t.openTabContextMenu({x:k.clientX,y:k.clientY,tabKey:d.tabKey,sourceDocument:((v=k.target)==null?void 0:v.ownerDocument)??document})},children:[g&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?s.jsx(Cs,{size:12,thickness:2,color:"success"}):b?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):h?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):f?s.jsx(Cs,{size:12,thickness:2}):d.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:At(d)}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:h?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Hn(d)}):f?s.jsx("span",{className:"adhdev-dockview-tab-connecting",children:Hn(d)}):s.jsx("span",{children:Hn(d)})})]}),S&&s.jsx("span",{className:"text-4xs opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:S,children:S})]})}const ZP=[];function Vo(e){return e.isActive}function $p(e){return e.isVisible}function eL(e){e.preventDefault()}function tL({params:e,api:t}){var x;const n=xi(),a=l.useRef(null),[o,r]=l.useState(()=>Vo(t)),[i,c]=l.useState(()=>$p(t)),d=n.conversationsByTabKey.get(e.tabKey),u=pi({sendDaemonCommand:n.sendDaemonCommand,activeConv:d,setActionLogs:n.setActionLogs,isStandalone:n.isStandalone});l.useEffect(()=>{r(Vo(t)),c($p(t));const b=[t.onDidActiveChange(g=>r(g.isActive)),t.onDidActiveGroupChange(g=>{if(!Vo(t)&&!g.isActive){r(!1);return}r(Vo(t))}),t.onDidVisibilityChange(g=>c(g.isVisible))];return()=>{for(const g of b)g.dispose()}},[t]);const p=l.useMemo(()=>d?n.ides.find(b=>b.id===d.routeId):void 0,[n.ides,d]),m=d==null?void 0:d.tabKey,h=l.useMemo(()=>m?n.actionLogs.filter(b=>b.routeId===m):ZP,[n.actionLogs,m]);if(!d)return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:s.jsx(kd,{conversationsCount:0,isSplitMode:!1,isStandalone:n.isStandalone,hasRegisteredMachines:n.hasRegisteredMachines,onOpenNewSession:n.onOpenNewSession,suppressGuide:n.hasDetachedConversationPanels,isLoading:!bi(n.ides,n.initialDataLoaded)})});const f=!gt(d)&&ja(d)==="terminal";return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:s.jsx(yd,{activeConv:d,clearToken:n.clearedTabs[d.tabKey]||0,isCliTerminal:f,ideEntry:p,terminalRef:a,commands:u,actionLogs:h,userName:n.userName,scrollToBottomRequestNonce:((x=n.scrollToBottomRequest)==null?void 0:x.tabKey)===d.tabKey?n.scrollToBottomRequest.nonce:void 0,isInputActive:o,isVisible:i})})}function sL({visibleConversations:e,clearedTabs:t,ides:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d,userName:u,toggleHiddenTab:p,actionShortcuts:m,registerActionHandlers:h,onActiveTabChange:f,onOpenNewSession:x,onRequestScrollToBottom:b,requestedActiveTabKey:g,requestedRemoteIdeId:S,onRequestedActiveTabConsumed:j,scrollToBottomRequest:y,liveSessionInboxState:k,layoutProfile:v}){var Se,Te,Je;const{theme:C}=nn(),{sendCommand:w}=wt(),N=l.useRef(null),T=l.useRef(null),A=l.useRef(null),P=l.useRef(!1),D=l.useRef(!1),L=l.useRef(!1),I=l.useRef(null),R=l.useRef([]),[_,M]=l.useState(null),[$,V]=l.useState(0),z=l.useRef(typeof window>"u"?{}:fI(v)),W=l.useMemo(()=>new Map(e.map(K=>[K.tabKey,K])),[e]),F=l.useMemo(()=>{const K=N.current;return K?K.groups.some(se=>{try{const be=se.model.location.type;return be!=="floating"&&be!=="popout"?!1:se.panels.some(we=>W.has(we.id))}catch{return!1}}):!1},[W,$,e]),B=l.useCallback(()=>{var K;(K=N.current)==null||K.focus()},[]),E=l.useCallback((K,se)=>{b==null||b(K,se)},[b]),H=l.useCallback(K=>{const se=document,be=K.document;for(const Fe of se.querySelectorAll('link[rel="stylesheet"]')){const tt=be.createElement("link");tt.rel="stylesheet",tt.href=Fe.href,Fe.crossOrigin&&(tt.crossOrigin=Fe.crossOrigin),be.head.appendChild(tt)}for(const Fe of se.querySelectorAll("style")){const tt=be.createElement("style");tt.textContent=Fe.textContent,be.head.appendChild(tt)}const we=[];for(const Fe of se.styleSheets)try{for(const tt of Fe.cssRules)tt instanceof CSSStyleRule&&(tt.selectorText===":root"||tt.selectorText==="html")&&we.push(tt.cssText)}catch{}if(we.length>0){const Fe=be.createElement("style");Fe.textContent=we.join(`
|
|
52
|
+
`)&&!o.startsWith("{")?null:{serverName:n.serverName||"adhdev-mesh",configFormat:n.format,configPathCommand:n.configPathCommand,requiresRestart:n.requiresRestart===!0,instructions:n.instructions||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:Np(n.template||"",{...t,serverName:n.serverName||"adhdev-mesh"})}}function WI(e){if(!e||typeof e!="object")return null;const t=e,n=typeof t.instructions=="string"?t.instructions:"",a=typeof t.template=="string"?t.template:"";return!n&&!a?null:{serverName:typeof t.serverName=="string"?t.serverName:void 0,configFormat:typeof t.configFormat=="string"?t.configFormat:void 0,configPathCommand:typeof t.configPathCommand=="string"?t.configPathCommand:void 0,requiresRestart:t.requiresRestart===!0,instructions:n||"This provider requires manual MCP setup before it can act as a Repo Mesh coordinator.",template:a}}function go(e){return`/dashboard?activeTab=${encodeURIComponent(e)}`}function fg(e){return ri(e)||e.tabKey||e.routeId||null}function gg(e){const t=typeof e.entrySessionId=="string"?e.entrySessionId.trim():"",n=typeof e.entryInstanceId=="string"?e.entryInstanceId.trim():"",a=typeof e.entryRouteId=="string"?e.entryRouteId.trim():"",o=e.conversations.find(r=>{if(a&&r.routeId!==a)return!1;const i=[r.providerSessionId,r.sessionId,r.nativeSessionId,r.tabKey].map(c=>typeof c=="string"?c.trim():"").filter(Boolean);return!!(t&&i.includes(t)||n&&i.includes(n)||a&&r.routeId===a)});if(o!=null&&o.tabKey)return o.tabKey;if(a){const r=_s(e.conversations,a)||e.conversations.find(i=>i.routeId===a);if(r!=null&&r.tabKey)return r.tabKey}return t||n||a||null}function cn(e){return String(e||"").trim()}function bg(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function Fr(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function OI(e,t){return!e||!t?!1:e===t||e.endsWith(`/${t}`)||t.endsWith(`/${e}`)}function UI(e,t){const n=cn(e.providerSessionId),a=cn(e.targetSessionId),o=t.find(r=>{const i=[r.providerSessionId,r.sessionId,r.nativeSessionId,r.tabKey,r.routeId].map(cn).filter(Boolean);return!!(n&&i.includes(n)||a&&i.includes(a))});return o?o.tabKey:a||n||null}function qI(e,t,n){if(t.event!=="agent:generating_completed")return null;const a=bg(t.daemonId);if(a&&a!==e.machineId)return null;const o=cn(t.providerType);if(e.providerType&&o!==e.providerType)return null;const r=cn(e.resumeSessionId),i=cn(e.launchedSessionId),c=cn(t.providerSessionId),d=cn(t.targetSessionId);if(r&&r!==c&&r!==d||i&&i!==c&&i!==d)return null;const u=Fr(e.workspacePath);if(u){const p=Fr(t.workspaceName);if(p&&!OI(p,u))return null}return UI(t,n)}function Ap(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function zI({ides:e,conversations:t,onOpenSession:n}){const[a,o]=l.useState(null),r=l.useRef(null),i=l.useCallback(()=>{r.current=null,o(null)},[]),c=l.useCallback(d=>{r.current=d,o(d)},[]);return l.useEffect(()=>{if(!a)return;const d=Fr(a.workspacePath),u=e.find(m=>{var g,S,j,y;if(!m||m.type==="adhdev-daemon"||bg(m.daemonId||m.id)!==a.machineId||(mo(m)?"cli":ha(m)?"acp":"ide")!==a.kind)return!1;const x=String(m.agentType||m.type||"");if(a.providerType&&x!==a.providerType)return!1;if(a.resumeSessionId)return String(m.providerSessionId||"")===a.resumeSessionId;if(a.launchedSessionId){const k=String(a.launchedSessionId||"");return[m.providerSessionId,m.sessionId,m.instanceId,m.id].map(C=>String(C||"")).filter(Boolean).includes(k)}if(d){const k=Fr(m.workspace||m.runtimeWorkspaceLabel);return k?k===d:!1}return Number(m.lastUpdated||m._lastUpdate||m.timestamp||((y=(j=(S=(g=m.activeChat)==null?void 0:g.messages)==null?void 0:S.at)==null?void 0:j.call(S,-1))==null?void 0:y.timestamp)||0)>=a.startedAt-5e3});if(!u)return;const p=gg({entrySessionId:u.sessionId,entryInstanceId:u.instanceId,entryRouteId:u.id,conversations:t});p&&(i(),n(p))},[i,t,e,n,a]),l.useEffect(()=>ft.onStatusEvent(d=>{const u=r.current;if(!u)return;const p=qI(u,d,t);p&&(i(),n(p))}),[i,t,n]),l.useEffect(()=>{if(!a)return;const d=window.setTimeout(()=>{o(u=>!u||u.startedAt!==a.startedAt?u:(r.current=null,null))},45e3);return()=>window.clearTimeout(d)},[a]),{trackPendingLaunch:c}}function GI(e,t){var a,o,r,i;const n={cliType:e};return(a=t==null?void 0:t.workspacePath)!=null&&a.trim()?n.dir=t.workspacePath.trim():t!=null&&t.workspaceId?n.workspaceId=t.workspaceId:t!=null&&t.useHome&&(n.useHome=!0),(o=t==null?void 0:t.resumeSessionId)!=null&&o.trim()&&(n.resumeSessionId=t.resumeSessionId.trim()),Array.isArray(t==null?void 0:t.cliArgs)&&t.cliArgs.length>0&&(n.cliArgs=t.cliArgs),(r=t==null?void 0:t.initialModel)!=null&&r.trim()&&(n.initialModel=t.initialModel.trim()),(i=t==null?void 0:t.initialThinkingLevel)!=null&&i.trim()&&(n.initialThinkingLevel=t.initialThinkingLevel.trim()),t!=null&&t.settings&&(n.settings=t.settings),n}function KI(e,t,n){var i,c,d,u;const a={meshId:e.trim()};t.trim()&&(a.cliType=t.trim());const o=(i=n==null?void 0:n.initialModel)==null?void 0:i.trim(),r=(c=n==null?void 0:n.initialThinkingLevel)==null?void 0:c.trim();return o&&(a.initialModel=o),r&&(a.initialThinkingLevel=r),(d=n==null?void 0:n.settings)!=null&&d.autoApproveMode?a.autoApproveMode=n.settings.autoApproveMode:typeof((u=n==null?void 0:n.settings)==null?void 0:u.autoApprove)=="boolean"&&(a.autoApprove=n.settings.autoApprove),a}function VI({sendDaemonCommand:e,trackPendingLaunch:t,onOpenSession:n,activeConv:a,ides:o,setCliViewModeOverrides:r}){const i=ci(),{launchCli:c}=ei(),d=l.useCallback(async(g,S)=>vd(e,g,S),[e]),u=l.useCallback(async(g,S)=>{if(!S.trim())return{ok:!1,error:"Choose a workspace path first."};try{const j=await e(g,"workspace_add",{path:S.trim()});return j!=null&&j.success?{ok:!0}:{ok:!1,error:(j==null?void 0:j.error)||"Could not save workspace"}}catch(j){return{ok:!1,error:j instanceof Error?j.message:"Could not save workspace"}}},[e]),p=l.useCallback(async(g,S,j)=>{var y;try{const k={ideType:S,enableCdp:!0};(y=j==null?void 0:j.workspacePath)!=null&&y.trim()&&(k.workspace=j.workspacePath.trim());const v=await e(g,"launch_ide",k);return!(v!=null&&v.success)&&(v==null?void 0:v.success)!==void 0?{ok:!1,error:(v==null?void 0:v.error)||"Could not launch IDE"}:(t({machineId:g,kind:"ide",providerType:S,workspacePath:(j==null?void 0:j.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(k){return{ok:!1,error:k instanceof Error?k.message:"Could not launch IDE"}}},[e,t]),m=l.useCallback(async(g,S,j,y)=>{const k=Date.now();try{const v=GI(j,y),C=await c(g,v),w=(C==null?void 0:C.result)||C,N=(w==null?void 0:w.sessionId)||(w==null?void 0:w.id);return C!=null&&C.success&&N?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,launchedSessionId:N,startedAt:k}),{ok:!0}):C!=null&&C.success?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,startedAt:k}),{ok:!0}):{ok:!1,error:(C==null?void 0:C.error)||(w==null?void 0:w.error)||`Could not launch ${S.toUpperCase()} session`,code:(C==null?void 0:C.code)||(w==null?void 0:w.code)||void 0}}catch(v){return Ap(v)?(t({machineId:g,kind:S,providerType:j,workspacePath:(y==null?void 0:y.workspacePath)||null,resumeSessionId:(y==null?void 0:y.resumeSessionId)||null,startedAt:k}),{ok:!0}):{ok:!1,error:v instanceof Error?v.message:`Could not launch ${S.toUpperCase()} session`}}},[c,e,t]),h=l.useCallback(async g=>{var S;if(i!=null&&i.listMeshes)return i.listMeshes(g);if(!g)return[];try{const j=await e(g,"list_meshes",{}),y=(j==null?void 0:j.result)??j;if((y==null?void 0:y.success)===!1)throw new Error((y==null?void 0:y.error)||"Could not load meshes");return(Array.isArray(y==null?void 0:y.meshes)?y.meshes:Array.isArray((S=y==null?void 0:y.result)==null?void 0:S.meshes)?y.result.meshes:[]).map(v=>{var C;return{id:String((v==null?void 0:v.id)||""),name:String((v==null?void 0:v.name)||(v==null?void 0:v.id)||"Untitled mesh"),repoIdentity:(v==null?void 0:v.repoIdentity)||(v==null?void 0:v.repo_identity)||null,workspace:Array.isArray(v==null?void 0:v.nodes)&&v.nodes.length>0?String(((C=v.nodes[0])==null?void 0:C.workspace)||""):null,nodesCount:Array.isArray(v==null?void 0:v.nodes)?v.nodes.length:void 0,status:(v==null?void 0:v.status)||null}}).filter(v=>v.id)}catch(j){throw console.error("List meshes failed",j),j}},[i,e]),f=l.useCallback(async(g,S,j,y)=>{if(!S.trim())return{ok:!1,error:"Choose a mesh first."};if(i!=null&&i.launchMeshCoordinator)return i.launchMeshCoordinator(g,S,j,y);const k=Date.now();try{const v=KI(S,j,y),C=await e(g,"launch_mesh_coordinator",v),w=(C==null?void 0:C.result)??C;if((w==null?void 0:w.success)===!1||(C==null?void 0:C.success)===!1){const T=String((w==null?void 0:w.code)||(C==null?void 0:C.code)||""),A=WI((w==null?void 0:w.meshCoordinatorSetup)||(w==null?void 0:w.manualSetup)||(C==null?void 0:C.meshCoordinatorSetup)||(C==null?void 0:C.manualSetup));return{ok:!1,error:(w==null?void 0:w.error)||(C==null?void 0:C.error)||"Could not launch mesh coordinator",code:T||void 0,manualSetup:A}}const N=(w==null?void 0:w.sessionId)||(w==null?void 0:w.id);return N?n(N):t({machineId:g,kind:"cli",providerType:(w==null?void 0:w.cliType)||j.trim()||void 0,workspacePath:(w==null?void 0:w.workspace)||null,startedAt:k}),{ok:!0}}catch(v){return Ap(v)?(t({machineId:g,kind:"cli",providerType:j.trim()||void 0,startedAt:k}),{ok:!0}):{ok:!1,error:v instanceof Error?v.message:"Could not launch mesh coordinator"}}},[i,n,e,t]),x=l.useCallback(async(g,S)=>{if(!g||!S)return[];try{const j=await e(g,"list_saved_sessions",{providerType:S,kind:"cli",limit:30}),y=(j==null?void 0:j.result)??j;return Array.isArray(y==null?void 0:y.sessions)?y.sessions:[]}catch(j){return console.error("List saved sessions failed",j),[]}},[e]),b=l.useCallback(async g=>{await ag({conversation:a,mode:g,ides:o,sendDaemonCommand:e,setCliViewModeOverrides:r})},[a,o,e,r]);return{handleBrowseMachineDirectory:d,handleSaveMachineWorkspace:u,handleLaunchMachineIde:p,handleLaunchMachineProvider:m,handleListMachineMeshes:h,handleLaunchMeshCoordinator:f,handleListMachineSavedSessions:x,setActiveCliViewMode:b}}function YI(e){switch(e){case"notification-open":case"toast-open":case"conversation-open":case"requested-tab":return!0;case"dockview-shortcut":case"dockview-focus":case"dockview-move":case"dockview-split":case"stored-layout-restore":case"passive-tab-sync":return!1;default:return!1}}function QI(e,t,n=Date.now()){return!e||!YI(t)?null:{tabKey:e,nonce:n}}function JI({isMobile:e,conversations:t,visibleConversations:n,groupActiveTabIds:a,focusedGroup:o,groupedConvs:r,setSearchParams:i}){const[c,d]=l.useState(null),[u,p]=l.useState(null),m=l.useMemo(()=>{var g,S;if(!e){if(c){const j=t.find(y=>y.tabKey===c);if(j)return j}return n[0]}const b=a[o];if(b){const j=t.find(y=>y.tabKey===b);if(j)return j}return((g=r[o])==null?void 0:g[0])||((S=r[0])==null?void 0:S[0])},[t,c,o,a,r,e,n]),h=l.useCallback(b=>{d(b)},[]),f=l.useCallback(b=>{d(b.tabKey),i(g=>{const S=new URLSearchParams(g),j=cN(b);return j?S.set("activeTab",j):S.delete("activeTab"),S},{replace:!0})},[i]),x=l.useCallback((b,g)=>{const S=QI(b,g);S&&p(S)},[]);return{activeConv:m,openDesktopConversation:f,requestScrollToBottom:x,scrollToBottomRequest:u,setDesktopActiveTab:h}}function XI(e){const t=e.completedKey||null,n=e.pendingKey||null;return e.shouldMarkSeen?t===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:n!==null&&n!==e.autoReadKey,nextPendingKey:n===e.autoReadKey?n:null}:n===e.autoReadKey?{shouldSchedule:!1,shouldCancelPending:!1,nextPendingKey:n}:{shouldSchedule:!0,shouldCancelPending:n!==null&&n!==e.autoReadKey,nextPendingKey:e.autoReadKey}:{shouldSchedule:!1,shouldCancelPending:!!n,nextPendingKey:null}}function ZI(e){const t=String(e.liveState.completionMarker||""),n=String(e.liveState.seenCompletionMarker||""),a=String(e.liveState.inboxBucket||"idle"),o=!!e.liveState.unread,r=[e.tabKey,e.historySessionId||"",t,n,a,o?"1":"0"].join(":");return{shouldMarkSeen:!!(a==="task_complete"&&o&&(!t||t!==n)),autoReadKey:r,completionMarker:t,readAt:Math.max(Date.now(),e.timestamp||0,e.liveState.lastUpdated||0)}}function eP({activeConv:e,isMobile:t,liveSessionInboxState:n,sendDaemonCommand:a}){const o=l.useRef(null),r=l.useRef(null),i=l.useRef(null),c=l.useRef(null),d=l.useRef(null);l.useEffect(()=>{const u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(clearTimeout(c.current),c.current=null),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null),r.current=null};if(t){u(),o.current=null;return}if(!(e!=null&&e.sessionId)){u(),o.current=null;return}const p=yn(e,n),m=ZI({tabKey:e.tabKey,historySessionId:ri(e)||"",lastMessageHash:e.lastMessageHash||"",lastMessageAt:Number(e.lastMessageAt||0),timestamp:Bn(e),liveState:p}),h=m.autoReadKey,f=XI({autoReadKey:h,shouldMarkSeen:m.shouldMarkSeen,completedKey:o.current,pendingKey:r.current});if(!m.shouldMarkSeen){f.shouldCancelPending&&u(),o.current=h;return}if(!f.shouldSchedule)return;f.shouldCancelPending&&u();const x=()=>{if(document.visibilityState!=="visible"||o.current===h)return;o.current=h,r.current=null,i.current=null,c.current=null,d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null);const g=m.readAt;a(e.daemonId||e.routeId,"mark_session_seen",{sessionId:e.sessionId,providerSessionId:e.providerSessionId,seenAt:g,completionMarker:m.completionMarker}).catch(()=>{})};if(r.current=f.nextPendingKey,document.visibilityState==="visible"){i.current=setTimeout(x,1500);const g=()=>{document.visibilityState!=="visible"&&i.current&&(clearTimeout(i.current),i.current=null)};d.current=g,document.addEventListener("visibilitychange",g);return}const b=()=>{document.visibilityState==="visible"&&(c.current&&clearTimeout(c.current),c.current=setTimeout(x,800),d.current&&(document.removeEventListener("visibilitychange",d.current),d.current=null))};d.current=b,document.addEventListener("visibilitychange",b)},[e,t,n,a]),l.useEffect(()=>()=>{i.current&&clearTimeout(i.current),c.current&&clearTimeout(c.current),d.current&&document.removeEventListener("visibilitychange",d.current)},[])}function tl(e){if(!e)return"";const t=String(e.workspacePath||"").trim();if(t)return t;const n=String(e.workspaceName||"").trim();return/^(?:~\/|\/|[A-Za-z]:[\\/])/.test(n)?n:""}function tP({activeConv:e,remoteDialogConv:t,remoteDialogActiveConv:n,ides:a,sendDaemonCommand:o,updateRouteChats:r,setToasts:i,setClearedTabs:c,setSearchParams:d}){var $;const{launchCli:u}=ei(),[p,m]=l.useState(!1),[h,f]=l.useState([]),[x,b]=l.useState(()=>as()),[g,S]=l.useState(!1),[j,y]=l.useState(null),k=l.useRef(null),v=l.useMemo(()=>n||t||e,[e,n,t]),C=!!v&&vt(v)&&!gt(v),w=l.useMemo(()=>{if(!v||!C)return null;const V=v.daemonId||v.routeId||"",z=qs(v),W=tl(v);return`${V}:${z}:${v.providerSessionId||""}:${W}`},[v,C]),N=l.useMemo(()=>!v||!C?"":tl(v),[v,C]),{isCreatingChat:T,isRefreshingHistory:A,handleSwitchSession:P,handleNewChat:D,handleRefreshHistory:L}=dg({sendDaemonCommand:o,activeConv:v,chats:($=a.find(V=>V.id===(v==null?void 0:v.routeId)))==null?void 0:$.chats,updateRouteChats:r,setToasts:i,setClearedTabs:c}),I=l.useCallback(()=>{m(!0)},[]),R=l.useCallback(()=>{m(!1)},[]),_=l.useCallback(async()=>{if(!(!v||!C||g)){S(!0);try{const V=v.daemonId||v.routeId,z=qs(v),W=tl(v),F=await o(V,"list_saved_sessions",{agentType:z,providerType:z,kind:"cli",limit:50,...v.providerSessionId?{providerSessionId:v.providerSessionId}:{},...W?{workspace:W}:{}}),B=(F==null?void 0:F.result)??F;f(Array.isArray(B==null?void 0:B.sessions)?B.sessions:[])}catch(V){console.error("Refresh saved sessions failed",V),f([])}finally{S(!1)}}},[v,g,C,o]);l.useEffect(()=>{if(!p){k.current=null;return}if(!C){k.current=null,f([]),S(!1);return}!w||g||k.current!==w&&(k.current=w,_())},[_,p,g,C,w]);const M=l.useCallback(async V=>{if(!v||!C||!V.providerSessionId||!V.workspace)return;const z=v.daemonId||v.routeId,W=qs(v);try{y(V.providerSessionId);const F=await u(z,{cliType:W,dir:V.workspace,resumeSessionId:V.providerSessionId,initialModel:_h(V.summaryMetadata,"model",{preferShortValue:!0})||void 0}),B=(F==null?void 0:F.result)??F,E=typeof(B==null?void 0:B.sessionId)=="string"?B.sessionId:typeof(B==null?void 0:B.id)=="string"?B.id:"";E&&d(H=>{const J=new URLSearchParams(H);return J.set("activeTab",E),J},{replace:!0}),R()}catch(F){console.error("Resume saved session failed",F)}finally{y(null)}},[R,v,C,o,d]);return{historyModalOpen:p,openHistoryModal:I,closeHistoryModal:R,historyTargetConv:v,isSavedSessionHistoryTarget:C,isHistoryCreatingChat:T,isHistoryRefreshingHistory:A,handleHistorySwitchSession:P,handleHistoryNewChat:D,handleHistoryRefresh:L,savedHistorySessions:h,savedHistoryFilters:x,setSavedHistoryFilters:b,missingWorkspaceResumePath:N,isSavedHistoryLoading:g,resumingSavedHistorySessionId:j,handleRefreshSavedHistory:_,handleResumeSavedHistorySession:M}}function sP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c}){const[d,u]=l.useState(null),[p,m]=l.useState(null),h=l.useMemo(()=>{if(e||!a)return null;const S=c(a);return S&&!vt(S)&&!gt(S)?S:null},[e,a,c]),f=l.useMemo(()=>{const S=d==null?void 0:d.routeId;if(!S)return null;const j=d!=null&&d.tabKey?r.find(y=>y.tabKey===d.tabKey):o?r.find(y=>y.tabKey===o):null;return(j==null?void 0:j.routeId)===S?j:_s(r,S)},[r,d,o]),x=l.useMemo(()=>{if(f)return i.find(S=>S.id===f.routeId)},[i,f]);l.useEffect(()=>{h&&(u({routeId:h.routeId,tabKey:Pu(h)}),m(h),n({pathname:t.pathname,search:t.search},{replace:!0,state:null}))},[t.pathname,t.search,n,h]);const b=l.useCallback(S=>{S&&(u({routeId:S.routeId,tabKey:Pu(S)}),m(S))},[]),g=l.useCallback(()=>{u(null),m(null)},[]);return{remoteDialogConv:f,remoteDialogIdeEntry:x,remoteDialogActiveConv:p,setRemoteDialogActiveConv:m,openRemoteDialog:b,closeRemoteDialog:g}}function nP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c,activeConv:d,sendDaemonCommand:u}){const{remoteDialogConv:p,remoteDialogIdeEntry:m,remoteDialogActiveConv:h,setRemoteDialogActiveConv:f,openRemoteDialog:x,closeRemoteDialog:b}=sP({isMobile:e,location:t,navigate:n,requestedRemoteTabTarget:a,requestedDesktopTabKey:o,conversations:r,ides:i,resolveConversationByTarget:c}),[g,S]=l.useState(!1),[j,y]=l.useState(null),k=l.useCallback(async w=>{const N=w||d;!N||!vt(N)&&!gt(N)||(y(N),S(!0))},[d]),v=l.useCallback(()=>{S(!1),y(null)},[]),C=l.useCallback(async w=>{const N=j||d;if(!N||!vt(N)&&!gt(N)){v();return}S(!1);try{const T=qs(N),A=N.routeId||N.daemonId||"";await u(A,"stop_cli",{cliType:T,targetSessionId:N.sessionId,mode:w,...ui(N)})}catch(T){console.error("Stop CLI failed:",T)}finally{y(null)}},[d,v,j,u]);return{remoteDialogConv:p,remoteDialogIdeEntry:m,remoteDialogActiveConv:h,setRemoteDialogActiveConv:f,openRemoteDialog:x,closeRemoteDialog:b,cliStopDialogOpen:g,cliStopTargetConv:j,requestCliStop:k,cancelCliStop:v,confirmCliStop:C}}function sl(e,t=!0){return(e??!0)&&t}const yd=l.memo(function({activeConv:t,clearToken:n,isCliTerminal:a,ideEntry:o,terminalRef:r,commands:i,actionLogs:c,userName:d,scrollToBottomRequestNonce:u,isInputActive:p=!0,isVisible:m=!0}){const{handleModalButton:h,handleRelaunch:f,handleSendChat:x,handleSendNowQueued:b,handleCancelQueued:g,isSendingChat:S,sendFeedbackMessage:j,pendingLocalMessage:y,pendingLocalMessages:k,retireEchoedPendingMessages:v,handleFocusAgent:C,isFocusingAgent:w}=i,N=a,T=!a,A=sl(m,N),P=sl(m,T),D=sl(m),L=sg(t),I=L.status||L.modalMessage||L.modalButtons?{...t,...L.status?{status:L.status}:{},...L.modalMessage!==void 0?{modalMessage:L.modalMessage}:{},...L.modalButtons!==void 0?{modalButtons:L.modalButtons}:{}}:t,R=_=>s.jsx(Tf,{activeConv:I,ideEntry:o,handleSendChat:x,handleSendNowQueued:b,handleCancelQueued:g,isSendingChat:S,sendFeedbackMessage:j,pendingLocalMessage:y,pendingLocalMessages:k,retireEchoedPendingMessages:v,handleFocusAgent:C,isFocusingAgent:w,actionLogs:c,userName:d,scrollToBottomRequestNonce:u,isInputActive:p&&_,isVisible:_});return s.jsxs(s.Fragment,{children:[s.jsx(Ah,{activeConv:I,onModalButton:h}),I.transport!=="pty"&&I.transport!=="acp"&&I.cdpConnected===!1?s.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[s.jsx("span",{className:"text-sm",children:s.jsx(ds,{size:14})}),s.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),s.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-3xs whitespace-nowrap shrink-0",onClick:f,children:"Relaunch with CDP"})]})}):null,I.transport==="pty"?s.jsxs("div",{style:{position:"relative",minHeight:0,flex:"1 1 0%",width:"100%",overflow:"hidden"},children:[s.jsx("div",{"aria-hidden":!a,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:N?"visible":"hidden",pointerEvents:N?"auto":"none"},children:s.jsx(g1,{activeConv:I,clearToken:n,terminalRef:r,handleSendChat:x,isSendingChat:S,sendFeedbackMessage:j,isVisible:A,isInputActive:p&&A})}),s.jsx("div",{"aria-hidden":a,style:{position:"absolute",inset:0,display:"flex",minHeight:0,width:"100%",flexDirection:"column",visibility:T?"visible":"hidden",pointerEvents:T?"auto":"none"},children:R(P)})]}):R(D)]})},(e,t)=>e.activeConv===t.activeConv&&e.isCliTerminal===t.isCliTerminal&&e.ideEntry===t.ideEntry&&e.terminalRef===t.terminalRef&&e.commands===t.commands&&e.actionLogs===t.actionLogs&&e.userName===t.userName&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isInputActive===t.isInputActive&&e.isVisible===t.isVisible);function aP({conversation:e,className:t="",onOpenNativeConversation:n,onOpenMachine:a,interactive:o=!0,meshOnly:r=!1}){var k,v,C;const{t:i}=ye("common"),c=Qn(),d=sn(e),u=r?null:nf(e),p=!r&&(e.transport==="cdp-page"||e.transport==="cdp-webview"),m=!r&&e.streamSource==="agent-stream"&&!!e.agentName,h=!r&&!m&&(e.transport==="pty"||e.transport==="acp"),f=ya(e),x=lN(e),b=(k=e.settings)==null?void 0:k.meshNodeFor,g=e.meshQueueStats,S=((v=e.coordinator)==null?void 0:v.meshId)||((C=e.settings)==null?void 0:C.meshCoordinatorFor),j=l.useCallback(()=>{if(a){a();return}d&&c("/dashboard",{state:{openMachineId:d}})},[d,c,a]),y=l.useCallback(()=>{if(n){n();return}const w=fg(e);w&&c(go(w))},[e,c,n]);return!p&&!m&&!h&&!u&&!b&&!g?null:s.jsxs("div",{className:`conversation-meta-chips ${t}`.trim(),children:[p&&(o?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:y,title:x,children:[s.jsx(Es,{size:12}),s.jsx("span",{children:x})]}):s.jsxs("span",{className:"conversation-meta-chip",title:x,children:[s.jsx(Es,{size:12}),s.jsx("span",{children:x})]})),m&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(xa,{size:12}),s.jsx("span",{children:f})]}),h&&s.jsxs("span",{className:"conversation-meta-chip is-active",title:f,children:[s.jsx(xa,{size:12}),s.jsx("span",{children:f})]}),u&&(o?s.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:j,title:u,children:[s.jsx(hn,{size:12}),s.jsx("span",{children:u})]}):s.jsxs("span",{className:"conversation-meta-chip",title:u,children:[s.jsx(hn,{size:12}),s.jsx("span",{children:u})]})),b&&s.jsxs("span",{className:"conversation-meta-chip",title:"Mesh node",children:[s.jsx(hn,{size:12}),s.jsx("span",{children:i("dashboard.metaChips.meshNode")})]}),S&&g&&s.jsxs("span",{className:`conversation-meta-chip ${g.pending>0?"is-active":""}`,style:g.failed>0?{color:"var(--color-red-400)",borderColor:"var(--color-red-400)"}:void 0,title:`Queue: ${g.pending} pending, ${g.assigned} assigned, ${g.completed} completed, ${g.failed} failed`,children:[s.jsx(ev,{size:12}),s.jsxs("span",{children:[g.pending," Pending"]})]})]})}function oP({selectedConversation:e,isAcp:t,isStandalone:n,selectedIdeEntry:a,actionLogs:o,userName:r,commands:i,onBack:c,onOpenNativeConversation:d,onOpenMachine:u,onOpenHistory:p,onOpenRemote:m,onOpenMeshGraph:h,onStopCli:f,cliViewMode:x,onSetCliViewMode:b}){var v,C;const g=l.useRef(null),S=vt(e)&&!t,j=S&&x==="terminal",y=!!e.daemonId&&!!((v=e.coordinator)!=null&&v.meshId||(C=e.settings)!=null&&C.meshCoordinatorFor),k=n?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:`flex items-center justify-between gap-3 ${k} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:c,type:"button","aria-label":"Back",children:s.jsx(Bc,{size:18})}),s.jsxs("div",{className:"min-w-0 flex-1 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] leading-[26px] font-extrabold tracking-tight text-text-primary truncate",children:At(e)}),s.jsx("div",{className:"min-w-0 max-w-full text-xs text-text-secondary",children:s.jsx(aP,{conversation:e,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>d(e),onOpenMachine:()=>u(e)})})]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[S&&x&&s.jsx(Ef,{mode:x,onChange:b,compact:!0}),S&&f&&s.jsx("button",{onClick:()=>{f(e)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:s.jsx(Wt,{size:14})}),y&&h&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(e),type:"button",title:"Open live repo mesh graph","aria-label":"Open live repo mesh graph",children:s.jsx(js,{size:14})}),s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(e),type:"button",children:s.jsx(Wc,{size:14})}),!t&&!S&&s.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(e),type:"button",children:s.jsx(Es,{size:14})})]})]}),s.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:s.jsx(yd,{activeConv:e,clearToken:0,isCliTerminal:j,ideEntry:a,terminalRef:g,commands:i,actionLogs:o,userName:r})})]})}function rP(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function xg({isStandalone:e=!1}={}){const[t,n]=l.useState("unix"),[a,o]=l.useState("powershell"),[r,i]=l.useState(!1),c=t==="unix"?"unix":a,d=l.useMemo(()=>CA(),[]);l.useEffect(()=>{n(rP())},[]);const u=l.useCallback(()=>{navigator.clipboard.writeText(d[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return s.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-3xs px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>n("unix"),children:"macOS / Linux"}),s.jsx("button",{className:`text-3xs px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>n("windows"),children:"Windows"})]}),t==="windows"&&s.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[s.jsx("button",{className:`text-4xs px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${a==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>o("powershell"),children:"PowerShell"}),s.jsx("button",{className:`text-4xs px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${a==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>o("cmd"),children:">_ CMD"})]}),s.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:u,title:"Click to copy",children:[s.jsx("span",{className:"text-text-muted select-none",children:d[c].prompt}),s.jsx("span",{className:"flex-1 break-all",children:d[c].cmd}),s.jsx("span",{className:"text-4xs font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:r?s.jsx(Ca,{size:12}):s.jsx(Qr,{size:12})})]}),s.jsxs("div",{className:"text-text-muted text-3xs font-sans mt-2",children:["Or via npm: ",s.jsx("span",{className:"text-text-secondary font-mono",children:e?"npm i -g @adhdev/daemon-standalone && adhdev-standalone":"npm i -g adhdev && adhdev login"})]})]})}function vg({section:e,onSectionChange:t}){const{t:n}=ye("common"),a=[{key:"machines",label:n("nav.machines"),icon:Es},{key:"chats",label:n("nav.chats"),icon:Ks}];return s.jsx("div",{className:"px-3 py-2.5 pb-[max(10px,env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:s.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:a.map(({key:o,label:r,icon:i})=>{const c=e===o;return s.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-xxs font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>t(o),type:"button","aria-pressed":c,children:[s.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:s.jsx(i,{size:15})}),s.jsx("span",{children:r})]},o)})})})}function zo({title:e,className:t=""}){return s.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${t}`,children:s.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:e})})}function sa({children:e,className:t=""}){return s.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${t}`,children:e})}function Tn({icon:e,title:t,subtitle:n,children:a}){return s.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[s.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:e}),s.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:t}),s.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:n}),a]})}function iP({conversation:e,onCancel:t,onConfirm:n}){const{t:a}=ye(),o=At(e);return s.jsx(xs,{children:s.jsxs("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",children:[s.jsx("div",{onClick:t,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),s.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"mobile-hide-confirm-title",className:"card fade-in mobile-compact-dialog relative w-full sm:w-[min(92vw,420px)] md:w-[92%] md:max-w-[420px] max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] flex flex-col overflow-hidden rounded-[24px] sm:rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-bg-primary",children:[s.jsx("h3",{id:"mobile-hide-confirm-title",className:"m-0 text-base md:text-lg font-extrabold",children:a("mobileInbox.hideTitle",{title:o})}),s.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:a("mobileInbox.hideDescription")})]}),s.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s.jsx("button",{onClick:n,className:"btn btn-primary w-full justify-center min-h-[42px]",children:a("mobileInbox.hide")}),s.jsx("button",{onClick:t,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:a("common.cancel")})]})]})]})})}function Go({item:e,type:t,getAvatarText:n,onOpenConversation:a,onRequestHideConversation:o,onRequestStopCli:r,onOpenMeshGraph:i,onCollectChatDebugBundle:c,isMuted:d,onToggleMute:u}){const{t:p}=ye(),m=t==="needs_attention"||t==="task_complete",h=t==="working",f=t==="earlier",x=t==="task_complete",{isReconnecting:b,isConnecting:g,isErrored:S}=Xn(e.conversation),j=At(e.conversation),y=wa(e.conversation),k=Lf(e.conversation,{requiresAction:t==="needs_attention"}),v=m?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":h?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":f?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_97%,var(--text-muted)_3%)]":"bg-transparent",C=m?"bg-accent-primary shadow-glow":h?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":f?"bg-[color:color-mix(in_oklab,var(--bg-primary)_95%,var(--text-muted)_5%)] border border-border-subtle/80 text-text-muted":"bg-bg-primary border border-border-subtle text-text-secondary",w=f?"text-text-secondary":"text-text-primary",N=f?"text-text-muted":"text-text-secondary",T=f?"text-text-secondary opacity-80":"text-text-muted",A=f?"text-text-muted opacity-80":"text-text-muted",P=!h&&!x,D=If(e.conversation),L="text-[color:var(--status-warning)]",I=R=>{if(!c||!f1())return;R.preventDefault(),R.stopPropagation();const _=c==null?void 0:c(e.conversation);Promise.resolve(_).catch(M=>{console.warn("[chat-debug-bundle] failed to collect mobile inbox debug bundle",M)})};return s.jsx("div",{className:`group relative overflow-hidden transition-colors active:scale-[0.995] ${v}`,children:s.jsxs("div",{className:"relative flex w-full items-start gap-3.5 px-4 py-3.5 text-left",children:[m||h?s.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,s.jsxs("div",{className:"mobile-inbox-leading-rail flex w-11 shrink-0 flex-col items-center gap-1.5",children:[s.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${C}`,style:m?{color:"var(--accent-on-primary)"}:void 0,children:n(j)}),D&&i&&s.jsx("button",{type:"button",className:"mobile-inbox-mesh-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary/70 text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:R=>{R.preventDefault(),R.stopPropagation(),i(e.conversation)},"aria-label":p("mobileInbox.openMeshGraphFor",{title:j}),title:p("mobileInbox.openLiveMeshGraph"),children:s.jsx(js,{size:13})})]}),s.jsxs("button",{className:"relative flex min-w-0 flex-1 flex-col gap-0.5 text-left",onClick:()=>a(e.conversation),onContextMenu:I,type:"button",children:[s.jsx("div",{className:"flex items-center gap-2 pr-[124px]",children:s.jsx("span",{className:`text-[15px] leading-[22px] font-bold truncate tracking-tight ${w}`,children:j})}),s.jsxs("div",{className:`text-xs font-medium truncate flex items-center ${N}`,children:[s.jsx("span",{className:"truncate",children:y}),s.jsx(Pr,{git:e.conversation.git,compact:!0,className:"ml-1 max-w-[6.5rem] shrink-0"}),b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:`${L} animate-pulse`,children:p("mobileInbox.reconnectingItem")})]}):g?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-text-muted",children:p("mobileInbox.connectingItem")})]}):k==="Action needed"?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:L,children:p("mobileInbox.actionNeeded")})]}):S&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{className:"text-[color:var(--status-error)]",children:p("mobileInbox.needsAttention")})]})]}),s.jsx("div",{className:`mt-0.5 truncate text-xxs ${T}`,children:e.preview})]}),s.jsxs("div",{className:"mobile-inbox-corner-actions absolute top-3 right-3 flex items-center gap-1.5",children:[P&&s.jsx("span",{className:`mr-0.5 text-2xs font-medium shrink-0 ${A}`,children:kh(e.timestamp)}),x&&s.jsx("span",{className:"rounded-full border border-accent-primary/16 bg-accent-primary/10 px-2 py-0.5 text-3xs font-bold text-accent-primary",children:p("mobileInbox.done")}),u&&s.jsx("button",{type:"button",className:`mobile-inbox-mute-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border transition-colors ${d?"border-amber-500/60 bg-amber-500 text-white hover:bg-amber-600":"border-border-subtle bg-bg-primary/70 text-text-muted hover:border-border-default hover:text-text-primary"}`,onClick:R=>{R.preventDefault(),R.stopPropagation(),u()},"aria-label":d?p("mobileInbox.unmute",{title:j}):p("mobileInbox.mute",{title:j}),title:p(d?"mobileInbox.mutedTitle":"mobileInbox.muteNotifications"),children:d?s.jsx(eh,{size:13}):s.jsx(vn,{size:13})}),o&&s.jsx("button",{type:"button",className:"mobile-inbox-hide-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border-subtle bg-bg-primary/70 text-text-muted transition-colors hover:border-border-default hover:text-text-primary",onClick:R=>{R.preventDefault(),R.stopPropagation(),o()},"aria-label":p("mobileInbox.hideConversationAria",{title:j}),title:p("mobileInbox.hideConversationTitle"),children:s.jsx(Xr,{size:13})}),r&&s.jsx("button",{type:"button",className:"mobile-inbox-stop-button inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-status-error/30 bg-bg-primary/70 text-status-error transition-colors hover:border-status-error/60 hover:bg-status-error/10",onClick:R=>{R.preventDefault(),R.stopPropagation(),r()},"aria-label":p("mobileInbox.stopSessionAria",{title:j}),title:p("mobileInbox.stopSessionTitle"),children:s.jsx(Wt,{size:13})})]})]})},e.conversation.tabKey)}function Tp({count:e,label:t}){return e<=0?null:s.jsxs("span",{className:"inline-flex items-center gap-1.5 text-accent-primary","aria-live":"polite",children:[s.jsxs("span",{className:"relative flex h-2 w-2 shrink-0",children:[s.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-primary/60"}),s.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-accent-primary"})]}),s.jsx("span",{className:"font-semibold",children:t})]})}function lP({section:e,attentionItems:t,unreadItems:n,workingItems:a,completedItems:o,hiddenConversations:r,machineCards:i,getAvatarText:c,actionLogs:d,sendDaemonCommand:u,onOpenConversation:p,onShowAllHidden:m,onHideConversation:h,onOpenMeshGraph:f,onStopCli:x,onOpenNewSession:b,onOpenMachine:g,onOpenSettings:S,onSectionChange:j,wsStatus:y="connected",initialDataLoaded:k=!0,conversationsLoaded:v,isStandalone:C=!1,onCollectChatDebugBundle:w,isConversationMuted:N,onToggleMuteConversation:T}){const{t:A}=ye(),[P,D]=l.useState(null),L=y==="disconnected"||y==="reconnecting"||y==="offline"||y==="auth_failed",I=!L&&!k,R=!L&&!(v??k),_=i.length>0,M=t.length>0||n.length>0||a.length>0||o.length>0,$=A(e==="machines"?"mobileInbox.machines":"mobileInbox.chats"),V=C?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",z=C?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]",W=l.useCallback(async E=>{const H=pn(E);if(!H)return;const J=Array.isArray(E.messages)?E.messages:[],q=uf({activeConv:E,visibleMessages:J,actionLogs:d,visibleBarControlCount:0,chatTailState:{hasMoreHistory:!1,historyError:null,historyMessages:[]},ui:{controlsVisible:!1,visibleLiveCount:J.length,hiddenLiveCount:0,isInputActive:!1,isVisible:!0}}),ie=await u(H,"get_chat_debug_bundle",{...gn(E),delivery:"daemon_file",frontendSnapshot:q}),xe=Rn(ie),Y=hf(xe),ne=await mf(Y);ne==="failed"&&console.warn("[chat-debug-bundle] failed to copy or present mobile inbox debug bundle locator"),ft.showToast(pf(xe,{locatorCopyStatus:ne}),ne==="failed"?"warning":"success")},[d,u]),F=w||W,B=l.useCallback(()=>{P&&(h==null||h(P),D(null))},[P,h]);return s.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[s.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${V}`,children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:$}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e==="chats"&&(t.length>0||n.length>0)&&s.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-2xs font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[s.jsx(vn,{size:13}),s.jsx("span",{children:t.length+n.length})]}),s.jsx("button",{onClick:S,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:s.jsx(yo,{size:18})})]})]})}),s.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${z}`,children:[e==="machines"&&s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:L?s.jsx(Tn,{icon:s.jsx(Cs,{size:32}),title:A(y==="offline"?"mobileInbox.networkOffline":y==="auth_failed"?"mobileInbox.sessionExpired":"mobileInbox.reconnecting"),subtitle:A(y==="offline"?"mobileInbox.waitingForNetwork":y==="auth_failed"?"mobileInbox.pleaseLogInAgain":"mobileInbox.restoringConnection")}):I?s.jsx(Tn,{icon:s.jsx(Cs,{size:32}),title:A("mobileInbox.loading"),subtitle:A("mobileInbox.loadingSubtitle")}):i.length===0?s.jsx(Tn,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:A(C?"mobileInbox.waitingForDaemon":"mobileInbox.connectYourMachines"),subtitle:A(C?"mobileInbox.waitingForDaemonSubtitle":"mobileInbox.connectYourMachinesSubtitle"),children:!C&&s.jsx("div",{className:"w-full max-w-[360px] mt-4",children:s.jsx(xg,{})})}):s.jsx(sa,{children:i.map((E,H)=>s.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${H>0?"border-t border-border-subtle/70":""}`,onClick:()=>g(E.id),type:"button",children:[s.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:c(E.label)}),s.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[15px] leading-[22px] font-bold text-text-primary truncate tracking-tight",children:E.label}),s.jsxs("span",{className:"flex items-center gap-2 text-2xs font-medium text-text-muted shrink-0",children:[s.jsx(Tp,{count:E.generatingCount,label:A("mobileInbox.generatingCount",{count:E.generatingCount})}),E.unread>0?s.jsx("span",{className:"text-accent-primary",children:A("mobileInbox.newCount",{count:E.unread})}):E.total>0?A("mobileInbox.chatCount",{count:E.total}):A("mobileInbox.idle")]})]}),s.jsx("div",{className:"text-xs font-medium text-text-secondary truncate",children:E.subtitle}),E.total>0?s.jsxs("div",{className:"text-xxs text-text-muted mt-0.5",children:[A("mobileInbox.chatCount",{count:E.total}),E.unread>0?A("mobileInbox.unreadSuffix",{count:E.unread}):"",E.generatingCount>0?A("mobileInbox.collapsedGeneratingSuffix",{count:E.generatingCount}):""]}):E.generatingCount>0?s.jsx("div",{className:"text-xxs text-accent-primary mt-0.5 font-medium",children:A("mobileInbox.generatingCount",{count:E.generatingCount})}):s.jsx("div",{className:"text-xxs text-text-muted mt-0.5 italic opacity-70",children:A("mobileInbox.noActiveChats")})]})]},E.id))})}),e==="chats"&&t.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.needsAttention"),className:"mb-0"}),s.jsx(sa,{children:t.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"needs_attention",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&n.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.taskComplete"),className:"mb-0 mt-2"}),s.jsx(sa,{children:n.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"task_complete",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&a.length>0&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[s.jsx(zo,{title:A("mobileInbox.workingNow"),className:"mb-0 mt-2"}),s.jsx(sa,{children:a.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"working",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))})]}),e==="chats"&&s.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[o.length>0&&s.jsx(zo,{title:A("mobileInbox.earlier"),className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),o.length>0?s.jsx(sa,{children:o.map((E,H)=>s.jsx("div",{className:H>0?"border-t border-border-subtle/70":"",children:s.jsx(Go,{item:E,type:"earlier",getAvatarText:c,onOpenConversation:p,onRequestHideConversation:h?()=>D(E.conversation):void 0,onRequestStopCli:x?()=>x(E.conversation):void 0,onOpenMeshGraph:f,onCollectChatDebugBundle:F,isMuted:N==null?void 0:N(E.conversation),onToggleMute:T?()=>T(E.conversation):void 0})},E.conversation.tabKey))}):M?s.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:A("mobileInbox.allCaughtUp")}):L?s.jsx(Tn,{icon:s.jsx(Cs,{size:28}),title:A("mobileInbox.connecting"),subtitle:A("mobileInbox.connectingSubtitle")}):R?s.jsx(Tn,{icon:s.jsx(Cs,{size:28}),title:A("mobileInbox.loading"),subtitle:A("mobileInbox.loadingSubtitle")}):_?s.jsx(Tn,{icon:s.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:s.jsx(Ks,{size:20})}),title:A("mobileInbox.noConversations"),subtitle:A("paneGroup.newSessionDescription"),children:b&&s.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm inline-flex items-center gap-2 mt-4",onClick:b,"aria-label":A("paneGroup.newSession"),title:A("paneGroup.newSession"),children:[s.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),s.jsx("span",{children:A("paneGroup.newSession")})]})}):s.jsx(Tn,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:A("mobileInbox.noMachinesConnected"),subtitle:A("mobileInbox.noMachinesSubtitle")})]}),e==="chats"&&r.length>0&&(()=>{const E=Ty(r);return s.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:s.jsx(sa,{className:"mt-4 border-dashed bg-bg-secondary/20",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 text-left",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-text-secondary",children:A("mobileInbox.hiddenTabs")}),s.jsx(Tp,{count:E,label:A("mobileInbox.generatingCount",{count:E})})]}),s.jsxs("div",{className:"mt-0.5 text-xxs text-text-muted",children:[A("mobileInbox.collapsedCount",{count:r.length}),E>0?A("mobileInbox.collapsedGeneratingSuffix",{count:E}):""]})]}),s.jsx("button",{type:"button",className:"shrink-0 rounded-full border border-border-subtle bg-bg-primary/70 px-3 py-1.5 text-xs font-semibold text-accent-primary hover:border-border-default",onClick:m,children:A("mobileInbox.restoreAll")})]})})})})()]}),e==="chats"&&b&&M&&s.jsx("button",{className:"fixed right-5 bottom-[calc(env(safe-area-inset-bottom,0px)+64px+20px)] z-50 flex items-center justify-center w-14 h-14 rounded-full hover:scale-105 active:scale-95 transition-transform",style:{background:"var(--accent-primary)",color:"var(--accent-on-primary)",boxShadow:"var(--shadow-md)"},onClick:b,"aria-label":A("paneGroup.newSession"),title:A("paneGroup.newSession"),children:s.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),P&&s.jsx(iP,{conversation:P,onCancel:()=>D(null),onConfirm:B}),s.jsx(vg,{section:e,onSectionChange:j})]})}function cP(e){if(!e)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(e))}catch{return new Date(e).toLocaleString()}}function yg(e){const t=[e.workspace||"Workspace unknown"],n=zn(e.summaryMetadata);n&&t.push(n),(e.messageCount||0)>0&&t.push(`${e.messageCount} msgs`);const a=cP(e.lastMessageAt);return{title:e.title||e.providerSessionId,providerSessionId:e.providerSessionId,metaLine:t.join(" · "),updatedLabel:a?`Updated ${a}`:"",preview:(e.preview||"").trim()}}function wd({title:e,description:t,currentPath:n,directories:a,busy:o=!1,error:r="",confirmLabel:i,onClose:c,onNavigate:d,onConfirm:u}){const[p,m]=l.useState(n),{t:h}=ye("common"),f=i??h("machine.workspaceBrowse.useThisFolder");l.useEffect(()=>{m(n)},[n]);const x=$I(n),b=p.trim();return s.jsx(xs,{children:s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:s.jsxs("div",{className:"w-full max-w-2xl max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(86vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:c,"aria-label":"Close folder browser",children:s.jsx(Wt,{size:16})})]}),s.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!x||o||d(x)},disabled:!x||o,children:[s.jsx(Bc,{size:15}),h("machine.workspaceBrowse.parent")]}),s.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:h("machine.workspaceBrowse.currentFolder")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"text",value:p,onChange:g=>m(g.target.value),onKeyDown:g=>{g.key!=="Enter"||!b||o||(g.preventDefault(),d(b))},placeholder:h("machine.workspaceBrowse.pathPlaceholder"),className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!b||o||d(b)},disabled:!b||o,children:h("machine.workspaceBrowse.go")})]})]})]}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:o?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:h("machine.workspaceBrowse.loading")}):r?s.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:r}):a.length===0?s.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:h("machine.workspaceBrowse.noSubfolders")}):s.jsx("div",{className:"p-3",children:a.map(g=>s.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(g.path),children:[s.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:s.jsx(Un,{size:17})}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:g.name}),s.jsx("span",{className:"block text-2xs text-text-muted truncate",children:g.path})]})]},g.path))})}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"btn btn-secondary h-9 px-4 text-sm",onClick:c,children:h("common.cancel")}),s.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>u(b||n),disabled:!b&&!n||o,children:f})]})]})})})}function gi({title:e,description:t,details:n,workspaceOptions:a,selectedWorkspaceKey:o,onWorkspaceChange:r,confirmLabel:i,busyLabel:c,busy:d=!1,showArgsInput:u,argsValue:p,onArgsChange:m,showModelInput:h,modelValue:f,onModelChange:x,historyProviderNode:b,onConfirm:g,onCancel:S}){const{t:j}=ye("common"),y=i??j("machine.launchConfirm.launch"),k=c??j("machine.launchConfirm.launching"),v=a==null?void 0:a.find(w=>w.key===o),C=s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-end justify-center overflow-y-auto bg-black/60 backdrop-blur-[2px] px-2 pt-[calc(8px+env(safe-area-inset-top,0px))] pb-[calc(8px+env(safe-area-inset-bottom,0px))] sm:items-center sm:p-4",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:s.jsxs("div",{className:"w-full max-w-lg max-h-[calc(100dvh-env(safe-area-inset-top,0px)-env(safe-area-inset-bottom,0px)-16px)] sm:max-h-[min(88vh,720px)] rounded-[24px] sm:rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:e}),s.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:t})]}),s.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:S,"aria-label":j("machine.launchConfirm.closeAria"),children:s.jsx(Wt,{size:16})})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 sm:px-5 sm:py-4 flex flex-col gap-3",children:[a&&a.length>0&&r&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.workspace")}),s.jsx("select",{value:o||"",onChange:w=>r(w.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:a.map(w=>s.jsx("option",{value:w.key,children:w.label},w.key))}),(v==null?void 0:v.description)&&s.jsx("div",{className:"mt-2 text-2xs text-text-muted break-all",children:v.description})]}),b,n.map((w,N)=>s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:w.label}),s.jsx("div",{className:"text-sm text-text-primary break-all",children:w.value})]},`${w.label}:${N}`)),h&&x&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.languageModel")}),s.jsx("input",{type:"text",value:f||"",onChange:w=>x(w.target.value),placeholder:j("machine.launchConfirm.autoDetect"),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]}),u&&m&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted mb-1",children:j("machine.launchConfirm.cliArgs")}),s.jsx("input",{type:"text",value:p||"",onChange:w=>m(w.target.value),placeholder:j("machine.launchConfirm.cliArgsPlaceholder"),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm placeholder:text-text-muted",disabled:d})]})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-[calc(12px+env(safe-area-inset-bottom,0px))] sm:px-5 sm:py-4 border-t border-border-subtle bg-bg-secondary shrink-0",children:[s.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:S,disabled:d,children:j("machine.launchConfirm.cancel")}),s.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:g,disabled:d,children:[s.jsx(Zm,{size:14}),d?k:y]})]})]})});return typeof document>"u"?C:bn.createPortal(C,document.body)}function Ip(e,t){return t||e.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||e}function wg(e){const{machine:t,currentWorkspacePath:n,currentWorkspaceId:a,includeHome:o=!0,homeLabel:r="Home directory",homeDescription:i="Launch without a workspace"}=e,c=[];o&&c.push({key:"__home__",label:r,description:i,workspaceId:null,workspacePath:null});for(const p of t.workspaces||[])c.push({key:`saved:${p.id}`,label:`${p.id===t.defaultWorkspaceId?"⭐ ":""}${Ip(p.path,p.label)}`,description:p.path,workspaceId:p.id,workspacePath:p.path});const d=(n==null?void 0:n.trim())||"",u=d?(t.workspaces||[]).find(p=>p.path===d):null;if(d&&!u&&c.push({key:`custom:${d}`,label:Ip(d),description:d,workspaceId:null,workspacePath:d}),a){const p=`saved:${a}`;if(c.some(m=>m.key===p))return{options:c,selectedKey:p}}return u?{options:c,selectedKey:`saved:${u.id}`}:d?{options:c,selectedKey:`custom:${d}`}:{options:c,selectedKey:"__home__"}}function dP(e){return e==="ide"?"IDE":e==="cli"?"CLI":"ACP"}function uP(e){return[dP(e.kind),e.subtitle||"",e.providerSessionId?"Saved history":""].filter(Boolean).join(" · ")}function pP(e){return e.lastLaunchedAt?ni(e.lastLaunchedAt):""}function kg(e){return{metaText:uP(e),updatedLabel:pP(e)}}function nl(e,t,n){return e?"ide":t>0?"cli":n>0?"acp":null}function mP({selectedMachineEntry:e,cliProviders:t,acpProviders:n,machineAction:a,onBrowseDirectory:o,onListSavedSessions:r}){var qe,We,Ie,ge;const i=Na(),[c,d]=l.useState(!1),u=(((qe=e.detectedIdes)==null?void 0:qe.length)||0)>0,p=l.useMemo(()=>(e.workspaces||[]).map(Se=>({id:Se.id,path:Se.path,label:Se.label})),[e]),m=e.defaultWorkspaceId||null,[h,f]=l.useState(m||((We=p[0])==null?void 0:We.id)||""),[x,b]=l.useState(""),[g,S]=l.useState(""),[j,y]=l.useState([]),[k,v]=l.useState(!1),[C,w]=l.useState(""),[N,T]=l.useState(!1),[A,P]=l.useState(nl(u,t.length,n.length)),D=l.useRef(null),[L,I]=l.useState(null),R=l.useRef("__home__"),[_,M]=l.useState("__home__"),[$,V]=l.useState(""),[z,W]=l.useState(""),[F,B]=l.useState(""),[E,H]=l.useState([]),[J,q]=l.useState(()=>as().textQuery),[ie,xe]=l.useState(()=>as().workspaceQuery),[Y,ne]=l.useState(()=>as().modelQuery),[me,ce]=l.useState(()=>as().resumableOnly),[ae,he]=l.useState(()=>as().sortMode),[oe,re]=l.useState(!1),[ee,G]=l.useState(!1),Q=l.useRef(0),ue=l.useRef(0),pe=l.useRef(null),Ae=l.useRef(null);l.useEffect(()=>{(!e.workspaces||!e.availableProviders||!e.detectedIdes||!e.recentLaunches)&&i(e.id,{minFreshMs:3e4}).catch(()=>{})},[i,e]);const Me=h==="__custom__"?x.trim():((Ie=p.find(Se=>Se.id===h))==null?void 0:Ie.path)||"",He=h==="__custom__"&&!!Me&&a.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(a.message),je=h!=="__custom__"&&((ge=p.find(Se=>Se.id===h))==null?void 0:ge.path)||"",Z=l.useMemo(()=>(e.recentLaunches||[]).map(Se=>Se.workspace),[e]),O=l.useCallback(async Se=>{const Te=Q.current+1;Q.current=Te,v(!0),w("");try{const Je=await o(Se);if(Q.current!==Te)return;S(Je.path),b(Je.path),y(Je.directories)}catch(Je){if(Q.current!==Te)return;w(Je instanceof Error?Je.message:"Could not load folder")}finally{Q.current===Te&&v(!1)}},[o]),X=l.useCallback(()=>{var Te;f("__custom__"),T(!0);const Se=xd(e.platform,bd(x.trim(),je,Z,e.defaultWorkspacePath,(Te=p.find(Je=>Je.id===m))==null?void 0:Te.path,p.map(Je=>Je.path)));O(Se)},[x,m,O,Z,je,e.platform,p]),te=l.useCallback(Se=>{if(Se!=null&&Se.workspaceId){f(Se.workspaceId),b("");return}if(Se!=null&&Se.workspacePath){f("__custom__"),b(Se.workspacePath);return}f(""),b("")},[]),de=l.useCallback(Se=>{if(f(Se),Se==="__custom__"){X();return}b("")},[X]),ve=l.useCallback(Se=>{f("__custom__"),b(Se)},[]),fe=l.useCallback((Se,Te)=>{const Je=ue.current+1;ue.current=Je,D.current=Te,R.current=Se.selectedWorkspaceKey||"__home__",M(Se.selectedWorkspaceKey||"__home__"),V(Se.initialArgs||""),W(Se.initialModel||""),B(""),H([]);const K=Se.providerType?`${e.id}:${Se.providerType}`:null;if(A1(Ae.current,K)){const se=as();q(se.textQuery),xe(se.workspaceQuery),ne(se.modelQuery),ce(se.resumableOnly),he(se.sortMode)}Ae.current=K,I(Se),Se.providerType&&r?(re(!0),r(Se.providerType).then(se=>{ue.current===Je&&H(se||[])}).catch(se=>{ue.current===Je&&console.warn("Failed to load saved sessions",se)}).finally(()=>{ue.current===Je&&re(!1)})):re(!1)},[r,e.id]),U=l.useMemo(()=>Hf(E,{textQuery:J,workspaceQuery:ie,modelQuery:Y,resumableOnly:me,sortMode:ae}),[Y,me,E,ae,J,ie]);l.useEffect(()=>{F&&(U.some(Se=>Se.providerSessionId===F)||B(""))},[U,F]);const Ce=l.useCallback(()=>{D.current&&(G(!0),D.current().finally(()=>{D.current=null,G(!1),I(null)}))},[]),Pe=l.useCallback(()=>{ue.current+=1,D.current=null,re(!1),I(null)},[]),Be=l.useCallback(Se=>{R.current=Se,M(Se)},[]);return l.useEffect(()=>{var Se;pe.current!==e.id&&(Q.current+=1,ue.current+=1,pe.current=e.id,f(m||((Se=p[0])==null?void 0:Se.id)||"__custom__"),b(""),S(""),y([]),v(!1),w(""),T(!1),D.current=null,I(null),H([]),re(!1),G(!1),q(as().textQuery),xe(as().workspaceQuery),ne(as().modelQuery),ce(as().resumableOnly),he(as().sortMode),Ae.current=null,P(nl(u,t.length,n.length)))},[n.length,t.length,m,u,e.id,p]),l.useEffect(()=>{var Se;h!=="__custom__"&&(h&&p.some(Te=>Te.id===h)||f(m||((Se=p[0])==null?void 0:Se.id)||"__custom__"))},[m,h,p]),l.useEffect(()=>{A==="ide"&&u||A==="cli"&&t.length>0||A==="acp"&&n.length>0||P(nl(u,t.length,n.length))},[A,n.length,t.length,u]),{showAllRecent:c,setShowAllRecent:d,hasIdeOptions:u,workspaceRows:p,defaultWorkspaceId:m,workspaceChoice:h,customWorkspacePath:x,browseCurrentPath:g,browseDirectories:j,browseBusy:k,browseError:C,browseDialogOpen:N,activeLauncherKind:A,launchConfirm:L,launchConfirmWorkspaceKeyRef:R,launchConfirmWorkspaceKey:_,launchConfirmArgs:$,launchConfirmModel:z,launchConfirmResumeId:F,launchConfirmSavedSessions:E,launchConfirmTextFilter:J,launchConfirmWorkspaceFilter:ie,launchConfirmModelFilter:Y,launchConfirmResumableOnly:me,launchConfirmSortMode:ae,filteredLaunchConfirmSavedSessions:U,launchConfirmSessionsLoading:oe,launchConfirmBusy:ee,resolvedWorkspacePath:Me,canCreateMissingWorkspace:He,openBrowseDialog:X,loadBrowsePath:O,handleWorkspaceChoiceChange:de,chooseCustomWorkspacePath:ve,setCustomWorkspacePath:b,setBrowseDialogOpen:T,setActiveLauncherKind:P,openLaunchConfirm:fe,handleConfirmLaunch:Ce,closeLaunchConfirm:Pe,setWorkspaceSelectionFromOption:te,setLaunchConfirmWorkspaceKeyAndSync:Be,setLaunchConfirmArgs:V,setLaunchConfirmModel:W,setLaunchConfirmResumeId:B,setLaunchConfirmTextFilter:q,setLaunchConfirmWorkspaceFilter:xe,setLaunchConfirmModelFilter:ne,setLaunchConfirmResumableOnly:ce,setLaunchConfirmSortMode:he}}function hP({selectedMachineEntry:e,selectedMachineConversations:t,selectedMachineRecentLaunches:n,cliProviders:a,acpProviders:o,selectedMachineNeedsUpgrade:r,appVersion:i,machineAction:c,isStandalone:d,section:u,showBottomNav:p,onBack:m,onSectionChange:h,onOpenConversation:f,onOpenRecent:x,onOpenMachineDetails:b,onMachineUpgrade:g,onLaunchDetectedIde:S,onAddWorkspace:j,onBrowseDirectory:y,onLaunchWorkspaceProvider:k,onListSavedSessions:v}){const{t:C}=ye("common"),w=M=>M==="ide"?"IDE":M==="cli"?"CLI":"ACP",N=n.slice(0,4),T=t.slice(0,3),A=mP({selectedMachineEntry:e,cliProviders:a,acpProviders:o,machineAction:c,onBrowseDirectory:y,onListSavedSessions:v}),P=l.useMemo(()=>N.map(M=>{const{metaText:$,updatedLabel:V}=kg(M);return{key:`recent-launch:${M.id}`,primary:M.label,secondary:$,updatedLabel:V,onClick:()=>{const{options:z,selectedKey:W}=wg({machine:{workspaces:A.workspaceRows,defaultWorkspaceId:A.defaultWorkspaceId},currentWorkspacePath:M.workspace,homeLabel:C("newSession.homeDirectory"),homeDescription:C("newSession.launchWithoutWorkspace")});A.openLaunchConfirm({title:M.kind==="ide"?Lr(C,"restart-ide",M.label):M.providerSessionId?$f(C,M.label):Lr(C,"start-fresh",M.label),description:M.kind==="ide"?Dr(C,"restart-ide"):M.providerSessionId?Bf(C):Dr(C,"start-fresh"),confirmLabel:M.kind==="ide"?Mr(C,"restart-ide"):M.providerSessionId?lc(C,!0):Mr(C,"start-fresh"),busyLabel:M.kind==="ide"?Rr(C,"restart-ide"):M.providerSessionId?Ff(C,!0):Rr(C,"start-fresh"),workspaceOptions:z,selectedWorkspaceKey:W,details:[{label:"Mode",value:w(M.kind)},...M.providerType?[{label:"Provider",value:M.providerType}]:[]]},async()=>{const F=z.find(B=>B.key===A.launchConfirmWorkspaceKeyRef.current);A.setWorkspaceSelectionFromOption(F),await x({...M,workspace:(F==null?void 0:F.workspacePath)??null})})}}}),[A,x,N,C]),D=l.useMemo(()=>T.map(M=>({key:`recent-chat:${M.conversation.tabKey}`,primary:At(M.conversation),secondary:JA(M.conversation,{timestampLabel:M.timestamp?kh(M.timestamp):null}),unread:M.unread,onClick:()=>f(M.conversation)})),[f,T]),L=A.showAllRecent?P:P.slice(0,4),I=P.length>0,R=D.length>0,_=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:`flex items-center justify-between gap-3 ${_} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:s.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[s.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:m,type:"button","aria-label":"Back",children:s.jsx(Bc,{size:18})}),s.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[s.jsx("div",{className:"flex items-center gap-2 text-[17px] leading-[26px] font-extrabold tracking-tight text-text-primary truncate",children:Ns(e,{fallbackId:e.id})}),s.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[e.platform||"machine",e.version?` · v${e.version}`:""]})]})]})}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[R&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:D.map(M=>s.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${M.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:M.onClick,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:M.primary}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:M.secondary})]},M.key))})]}),I&&s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),s.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:L.map(M=>s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:M.onClick,children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsx("span",{className:"text-sm font-bold text-text-primary truncate",children:M.primary}),M.updatedLabel&&s.jsx("span",{className:"text-2xs text-text-muted shrink-0",children:M.updatedLabel})]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:M.secondary})]},M.key))}),P.length>4&&s.jsx("div",{className:"flex justify-center px-4 pt-2",children:s.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>A.setShowAllRecent(M=>!M),children:A.showAllRecent?"Show fewer":`Show ${P.length-4} more`})})]}),!1,s.jsxs("section",{className:"flex flex-col gap-0",children:[s.jsx("div",{className:"text-2xs font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),s.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[r&&s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:g,children:[s.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",i]}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),s.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:b,children:[s.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),s.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),A.browseDialogOpen&&s.jsx(wd,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:A.browseCurrentPath,directories:A.browseDirectories,busy:A.browseBusy,error:A.browseError,confirmLabel:"Use this folder",onClose:()=>A.setBrowseDialogOpen(!1),onNavigate:M=>{A.loadBrowsePath(M)},onConfirm:M=>{A.chooseCustomWorkspacePath(M),A.setBrowseDialogOpen(!1)}}),A.launchConfirm&&s.jsx(gi,{title:A.launchConfirm.title,description:A.launchConfirm.description,details:A.launchConfirm.details,workspaceOptions:A.launchConfirm.workspaceOptions,selectedWorkspaceKey:A.launchConfirmWorkspaceKey,onWorkspaceChange:A.setLaunchConfirmWorkspaceKeyAndSync,confirmLabel:A.launchConfirm.providerType?lc(C,!!A.launchConfirmResumeId):A.launchConfirm.confirmLabel,busyLabel:A.launchConfirm.providerType?void 0:A.launchConfirm.busyLabel,busy:A.launchConfirmBusy,showArgsInput:A.launchConfirm.showArgsInput,argsValue:A.launchConfirmArgs,onArgsChange:A.setLaunchConfirmArgs,showModelInput:A.launchConfirm.showModelInput,modelValue:A.launchConfirmModel,onModelChange:A.setLaunchConfirmModel,historyProviderNode:A.launchConfirm.providerType&&(A.launchConfirmSessionsLoading||A.launchConfirmSavedSessions.length>0)&&s.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("div",{className:"text-3xs uppercase tracking-[0.08em] text-text-muted",children:"Resume saved history"}),A.launchConfirmSessionsLoading&&s.jsx("div",{className:"text-3xs text-text-secondary font-medium",children:"Loading..."})]}),s.jsx("div",{className:"text-2xs text-text-secondary mb-2",children:ld(C)}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 mb-2",children:[s.jsx("input",{type:"text",value:A.launchConfirmTextFilter,onChange:M=>A.setLaunchConfirmTextFilter(M.target.value),placeholder:"Search title or preview",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:A.launchConfirmWorkspaceFilter,onChange:M=>A.setLaunchConfirmWorkspaceFilter(M.target.value),placeholder:"Filter by workspace",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsx("input",{type:"text",value:A.launchConfirmModelFilter,onChange:M=>A.setLaunchConfirmModelFilter(M.target.value),placeholder:"Filter by model",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),s.jsxs("select",{value:A.launchConfirmSortMode,onChange:M=>A.setLaunchConfirmSortMode(M.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"recent",children:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mb-2 flex items-center gap-2 text-2xs text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:A.launchConfirmResumableOnly,onChange:M=>A.setLaunchConfirmResumableOnly(M.target.checked),disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading}),"Resume-ready only"]}),s.jsxs("select",{value:A.launchConfirmResumeId,onChange:M=>A.setLaunchConfirmResumeId(M.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2 text-sm",disabled:A.launchConfirmBusy||A.launchConfirmSessionsLoading,children:[s.jsx("option",{value:"",children:P1(C)}),A.filteredLaunchConfirmSavedSessions.map(M=>s.jsxs("option",{value:M.providerSessionId,disabled:!M.canResume,children:[M.title||M.providerSessionId," ",M.canResume?"":"(workspace missing)"]},M.providerSessionId))]}),!A.launchConfirmSessionsLoading&&A.launchConfirmSavedSessions.length>0&&A.filteredLaunchConfirmSavedSessions.length===0&&s.jsx("div",{className:"mt-2 text-2xs text-text-muted",children:"No saved history matches these filters."}),A.launchConfirmResumeId&&(()=>{const M=A.filteredLaunchConfirmSavedSessions.find(V=>V.providerSessionId===A.launchConfirmResumeId);if(!M)return null;const $=yg(M);return s.jsxs("div",{className:"mt-2 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2.5 text-2xs text-text-muted leading-relaxed",children:[s.jsx("div",{className:"font-semibold text-text-primary truncate",children:$.title}),s.jsx("div",{className:"font-mono break-all mt-0.5",children:$.providerSessionId}),s.jsx("div",{className:"mt-1",children:$.metaLine}),$.updatedLabel&&s.jsx("div",{className:"mt-1 text-text-secondary",children:$.updatedLabel}),$.preview&&s.jsx("div",{className:"mt-2 line-clamp-2 text-text-secondary",children:$.preview})]})})()]}),onConfirm:A.handleConfirmLaunch,onCancel:A.closeLaunchConfirm}),p&&s.jsx(vg,{section:u,onSectionChange:h})]})}const Pp=8e3;function fP(e){const t=e&&typeof e=="object"&&"result"in e?e.result:e,n=t&&typeof t=="object",a=n&&t.success===!1,o=n&&t.mirrorStale===!0;return!a&&!o?{confirmed:!0}:{confirmed:!1,reason:a&&typeof t.error=="string"?t.error:o?"the coordinator did not confirm the change":"command was rejected"}}function Sg(e,t,n){const a=l.useRef(new Map),[,o]=l.useState(0),r=l.useCallback(()=>o(f=>f+1),[]);l.useEffect(()=>{const f=a.current;if(f.size===0)return;const x=Date.now();let b=!1;for(const[g,S]of f){const j=e.get(g),y=S.muted===void 0||(j?j.muted===S.muted:!1),k=S.hidden===void 0||(j?j.surfaceHidden===S.hidden:!1),v=x-S.at>Pp;(y&&k||v)&&(f.delete(g),b=!0)}b&&r()},[e,r]),l.useEffect(()=>{if(a.current.size===0)return;const f=setInterval(()=>{const x=a.current,b=Date.now();let g=!1;for(const[S,j]of x)b-j.at>Pp&&(x.delete(S),g=!0);g&&r(),x.size===0&&clearInterval(f)},1e3);return()=>clearInterval(f)});const i=l.useCallback((f,x)=>{const b=a.current.get(f);a.current.set(f,{...b,...x,at:Date.now()}),r()},[r]),c=l.useCallback(f=>{const x=f.sessionId,b=x?a.current.get(x):void 0;return(b==null?void 0:b.muted)!==void 0?b.muted:yn(f,e).muted??!1},[e]),d=l.useCallback(f=>{const x=f.sessionId,b=x?a.current.get(x):void 0;return(b==null?void 0:b.hidden)!==void 0?b.hidden:yn(f,e).surfaceHidden??!1},[e]),u=l.useCallback((f,x)=>{const b=sn(f),g=f.sessionId;!b||!g||(i(g,x),t(b,"set_conversation_prefs",{sessionId:g,...x,...ui(f)}).then(S=>{const j=fP(S);j.confirmed||(console.warn("[conversation-prefs] set_conversation_prefs not confirmed",j.reason),a.current.delete(g),r(),n==null||n(`Couldn't update conversation — ${j.reason}`))}).catch(S=>{console.warn("[conversation-prefs] set_conversation_prefs failed",S),a.current.delete(g),r();const j=S instanceof Error?S.message:String(S??"the daemon is unreachable");n==null||n(`Couldn't update conversation — ${j}`)}))},[t,i,r,n]),p=l.useCallback(f=>{u(f,{muted:!c(f)})},[u,c]),m=l.useCallback((f,x)=>{u(f,{hidden:x})},[u]),h=l.useCallback(f=>{u(f,{hidden:!d(f)})},[u,d]);return{isMuted:c,isHidden:d,toggleMute:p,setHidden:m,toggleHidden:h}}function gr(e){return[...e].sort((t,n)=>{const a=n.timestamp-t.timestamp;return a!==0?a:t.conversation.tabKey.localeCompare(n.conversation.tabKey)})}function gP(e,t=[]){const n=new Map(e.map(o=>[o.conversation.tabKey,o])),a=t.map(o=>n.get(o)).filter(o=>!!o);return a.length===e.length?a:gr(e)}function bP(e,t=[]){const n=e.filter(i=>i.requiresAction),a=e.filter(i=>i.unread&&!i.requiresAction),o=e.filter(i=>!i.unread&&!i.requiresAction&&i.isWorking),r=e.filter(i=>!i.unread&&!i.requiresAction&&!i.isWorking);return{attentionItems:gr(n),unreadItems:gr(a),workingItems:gP(o,t),completedItems:gr(r)}}function bi(e,t){if(!t)return!1;const n=e.filter(a=>a.type==="adhdev-daemon"&&Cg(a)==="Connected");return n.length===0?!0:n.every(a=>a._sessionListAuthoritative===!0)}function Cg(e){var a,o,r;const t=((a=e.p2p)==null?void 0:a.state)||"";return t==="connected"?"Connected":t==="connecting"||t==="new"||t==="checking"?"Connecting":!(!!((o=e.p2p)!=null&&o.available)||!!((r=e.p2p)!=null&&r.state))&&e.status&&e.status!=="offline"?"Connected":"Offline"}function xP(e,t){if(!e)return[];const n=e.recentLaunches||[];return n.length>0?n.map(a=>({id:a.id,label:a.title||a.providerName||a.providerType,kind:a.kind,providerType:a.providerType,providerSessionId:a.providerSessionId,subtitle:zn(a.summaryMetadata)||a.workspace||void 0,workspace:a.workspace,summaryMetadata:a.summaryMetadata})):t.filter(a=>a.type!=="adhdev-daemon"&&a.daemonId===e.id).map(a=>{var i;const o=mo(a)?"cli":ha(a)?"acp":"ide",r=zn(a.summaryMetadata);return{id:`${o}:${a.type}:${a.workspace||""}`,label:((i=a.activeChat)==null?void 0:i.title)||(mo(a)?a.cliName||a.type:ha(a)&&a.cliName||a.type),kind:o,providerType:a.type,providerSessionId:a.providerSessionId,subtitle:ha(a)?r||a.workspace||void 0:a.workspace||void 0,workspace:a.workspace||void 0,timestamp:a.lastMessageAt||0}}).sort((a,o)=>o.timestamp-a.timestamp).map(({timestamp:a,...o})=>o)}function vP(e,t,n=[]){const a=new Map;for(const r of t){const i=sn(r.conversation),c=a.get(i);c?c.push(r):a.set(i,[r])}const o=new Map;for(const r of n){const i=sn(r),c=o.get(i);c?c.push(r):o.set(i,[r])}return e.map(r=>{const i=a.get(r.id)||[],c=o.get(r.id)||[],d=[...i].sort((b,g)=>g.timestamp-b.timestamp)[0]||null,u=(d==null?void 0:d.conversation)||null,p=Zl(r),m=i.filter(b=>b.unread||b.requiresAction).length,h=i.filter(b=>qn(b.conversation)).length+c.filter(qn).length,f=Cg(r),x=[r.platform||"machine",f].filter(Boolean);return{id:r.id,label:Ns(r,{fallbackId:r.id}),subtitle:x.join(" · "),unread:m,total:i.length,generatingCount:h,latestConversation:u,latestTimestamp:(d==null?void 0:d.timestamp)||0,fallbackActivityAt:p,preview:u?XA(u,Sf(u)):"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((r,i)=>{const c=r.latestTimestamp||r.fallbackActivityAt||0,d=i.latestTimestamp||i.fallbackActivityAt||0;return d!==c?d-c:r.label.localeCompare(i.label)})}function yP(e){return e==="chat"}function Ko(e,t){var n;if(!(typeof window>"u"))try{if(!(!!((n=import.meta.env)!=null&&n.DEV)||window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${e}`,t)}catch{}}function wP({conversations:e,machineEntries:t,items:n,selectedConversation:a,selectedTabKey:o,screen:r,liveSessionInboxState:i,sendDaemonCommand:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,setSelectedTabKey:x,setScreen:b,setSelectedMachineId:g,setSection:S,setMachineBackTarget:j,resetMachineAction:y}){const k=l.useRef(null),v=l.useCallback(C=>{if(!(C!=null&&C.sessionId))return;const w=yn(C,i),N=Math.max(Date.now(),Bn(C),w.lastUpdated||0);Ko("mark_read:start",{tabKey:C.tabKey,sessionId:C.sessionId,displayPrimary:At(C),inboxBucket:w.inboxBucket,unread:w.unread,lastSeenAt:w.lastSeenAt,lastUpdated:w.lastUpdated,activityAt:Bn(C),readAt:N}),c(sn(C)||C.routeId,"mark_session_seen",{sessionId:C.sessionId,providerSessionId:C.providerSessionId,seenAt:N,completionMarker:w.completionMarker}).then(T=>{Ko("mark_read:result",{tabKey:C.tabKey,sessionId:C.sessionId,result:T})}).catch(T=>{Ko("mark_read:error",{tabKey:C.tabKey,sessionId:C.sessionId,error:T instanceof Error?T.message:String(T)})})},[i,c]);return l.useEffect(()=>{var w;if(!a){yP(r)&&b("inbox"),x(((w=e[0])==null?void 0:w.tabKey)||null),k.current=null;return}if(r!=="chat"){k.current=null;return}const C=`${a.tabKey}:${a.sessionId||""}`;k.current!==C&&(k.current=C,v(a))},[e,v,r,a,b,x]),l.useEffect(()=>{if(!d)return;const C=e.find(w=>w.tabKey===d);C&&(x(C.tabKey),b("chat"),u==null||u())},[e,u,d,b,x]),l.useEffect(()=>{if(!p)return;const C=t.find(w=>w.id===p);C&&(g(C.id),y(),S("machines"),j("inbox"),b("machine"),m==null||m())},[t,m,p,y,j,b,S,g]),l.useEffect(()=>{h&&(S(h),b("inbox"),f==null||f())},[f,h,b,S]),l.useEffect(()=>{const C=n.filter(w=>w.inboxBucket==="task_complete"||w.unread);C.length!==0&&Ko("inbox_state",{screen:r,selectedTabKey:o,items:C.map(w=>{const N=yn(w.conversation,i);return{liveState:N,tabKey:w.conversation.tabKey,sessionId:w.conversation.sessionId,displayPrimary:At(w.conversation),serverBucket:N.inboxBucket,computedBucket:w.inboxBucket,serverUnread:N.unread,computedUnread:w.unread,lastSeenAt:N.lastSeenAt,lastUpdated:N.lastUpdated,activityAt:Bn(w.conversation)}})})},[n,i,r,o]),{markConversationRead:v}}const kP="Cannot update: node update policy unavailable; refresh and try again";async function SP(e,t,n){var o,r,i,c,d,u;const a=fd(n);if(!a)return{state:"error",message:kP};try{const p=await e(t,"daemon_upgrade",a);return(o=p==null?void 0:p.result)!=null&&o.alreadyLatest?{state:"done",message:`Already on v${((r=p==null?void 0:p.result)==null?void 0:r.version)||"latest"}.`}:(i=p==null?void 0:p.result)!=null&&i.upgraded||(c=p==null?void 0:p.result)!=null&&c.success?{state:"done",message:`Upgrade to v${((d=p==null?void 0:p.result)==null?void 0:d.version)||"latest"} started. Daemon is restarting…`}:{state:"error",message:((u=p==null?void 0:p.result)==null?void 0:u.error)||"Upgrade failed"}}catch(p){return{state:"error",message:p instanceof Error?p.message:"Upgrade failed"}}}function CP(e){if(!e)return"";const t=String(e);return t.includes(":")&&t.split(":")[0]||t}function Lp(e){return String(e||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function jP(e){return(e instanceof Error?e.message:String(e||"")).includes("P2P command timeout")}function NP({sendDaemonCommand:e,navigate:t,ides:n,conversations:a}){const{launchCli:o}=ei(),[r,i]=l.useState("idle"),[c,d]=l.useState(""),[u,p]=l.useState(null),m=l.useCallback(()=>{i("idle"),d(""),p(null)},[]),h=l.useCallback(async(y,k,v)=>{var C;try{i("loading"),d(`Launching ${k}…`);const w={ideType:k,enableCdp:!0};(C=v==null?void 0:v.workspacePath)!=null&&C.trim()&&(w.workspace=v.workspacePath.trim()),await e(y,"launch_ide",w),i("done"),d(`${k} launch requested`)}catch(w){i("error"),d(w instanceof Error?w.message:"Launch IDE failed"),console.error("Launch IDE failed",w)}},[e]),f=l.useCallback(async(y,k,v)=>{if(k.trim())try{i("loading"),d(v!=null&&v.createIfMissing?"Creating folder…":"Saving workspace…");const C=await e(y,"workspace_add",{path:k.trim(),createIfMissing:(v==null?void 0:v.createIfMissing)===!0});if(C!=null&&C.success){i("done"),d(v!=null&&v.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}i("error"),d((C==null?void 0:C.error)||"Could not save workspace")}catch(C){i("error"),d(C instanceof Error?C.message:"Could not save workspace")}},[e]),x=l.useCallback(async y=>{i("loading"),d("Starting daemon upgrade…");const k=n.find(C=>C.id===y||C.daemonId===y),v=await SP(e,y,k);i(v.state),d(v.message)},[n,e]),b=l.useCallback(async(y,k,v,C)=>{var T,A,P;const w=Date.now(),N={machineId:y,kind:k,providerType:v,workspaceId:(C==null?void 0:C.workspaceId)||null,workspacePath:(C==null?void 0:C.workspacePath)||null,resumeSessionId:(C==null?void 0:C.resumeSessionId)||null,startedAt:w};try{i("loading"),d(`Launching ${v}…`),p(N);const D={cliType:v};(T=C==null?void 0:C.workspacePath)!=null&&T.trim()?D.dir=C.workspacePath.trim():C!=null&&C.workspaceId?D.workspaceId=C.workspaceId:C!=null&&C.useHome&&(D.useHome=!0),C!=null&&C.resumeSessionId&&(D.resumeSessionId=C.resumeSessionId),(A=C==null?void 0:C.args)!=null&&A.trim()&&(D.cliArgs=C.args.trim().split(/\s+/).filter(Boolean)),(P=C==null?void 0:C.model)!=null&&P.trim()&&(D.initialModel=C.model.trim());const L=await o(y,D),I=(L==null?void 0:L.result)||L,R=(I==null?void 0:I.sessionId)||(I==null?void 0:I.id);if(L!=null&&L.success&&R){p(null),i("done"),d(`${v} launched`),t(go(R));return}if(L!=null&&L.success){i("loading"),d(`${v} launch requested — waiting for session…`);return}p(null),i("error"),d((L==null?void 0:L.error)||(I==null?void 0:I.error)||`Could not launch ${k.toUpperCase()} workspace`)}catch(D){if(jP(D)){i("loading"),d(`${v} launch requested — waiting for session…`);return}p(null),i("error"),d(D instanceof Error?D.message:`Could not launch ${k.toUpperCase()} workspace`)}},[t,e]),g=l.useCallback(async(y,k)=>{try{const v=await e(y,"list_saved_sessions",{providerType:k,kind:"cli",limit:30}),C=(v==null?void 0:v.result)??v;return Array.isArray(C==null?void 0:C.sessions)?C.sessions:[]}catch(v){return console.error("Failed to list saved sessions on mobile:",v),[]}},[e]),S=l.useCallback(async(y,k)=>vd(e,y,k),[e]);l.useEffect(()=>{if(!u)return;const y=Lp(u.workspacePath),k=n.find(C=>{var D,L,I,R;if(!C||C.type==="adhdev-daemon"||CP(C.daemonId||C.id)!==u.machineId||(C.transport==="acp"?"acp":C.transport==="pty"?"cli":null)!==u.kind||String(C.agentType||C.type||"")!==u.providerType)return!1;const A=String(C.providerSessionId||"");if(u.resumeSessionId&&A)return A===u.resumeSessionId;if(y){const _=Lp(C.workspace||C.runtimeWorkspaceLabel);return _?_===y:!1}return Number(C.lastUpdated||C._lastUpdate||C.timestamp||((R=(I=(L=(D=C.activeChat)==null?void 0:D.messages)==null?void 0:L.at)==null?void 0:I.call(L,-1))==null?void 0:R.timestamp)||0)>=u.startedAt-5e3});if(!k)return;const v=gg({entrySessionId:k.sessionId,entryInstanceId:k.instanceId,entryRouteId:k.id,conversations:a});v&&(p(null),i("done"),d(`${u.providerType} launched`),t(go(v)))},[a,n,t,u]),l.useEffect(()=>{if(!u)return;const y=window.setTimeout(()=>{p(k=>!k||k.startedAt!==u.startedAt?k:(i("error"),d("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(y)},[u]);const j=l.useCallback(async(y,k)=>{var v;if(k.kind==="ide"&&k.providerType){await h(y,k.providerType,{workspacePath:k.workspace||null});return}if((k.kind==="cli"||k.kind==="acp")&&k.providerType){const C=((v=k.workspace)==null?void 0:v.trim())||"";await b(y,k.kind,k.providerType,{workspacePath:C||null,useHome:!C,resumeSessionId:k.providerSessionId||null})}},[h,b]);return{machineAction:{state:r,message:c},resetMachineAction:m,handleLaunchDetectedIde:h,handleAddWorkspace:f,handleMachineUpgrade:x,handleLaunchWorkspaceProvider:b,handleListSavedSessions:g,handleBrowseDirectory:S,handleOpenRecent:j}}function AP({conversations:e,selectedConversation:t,machineBackTarget:n,markConversationRead:a,resetMachineAction:o,setSelectedTabKey:r,setScreen:i,setSelectedMachineId:c,setSection:d,setMachineBackTarget:u}){const p=l.useCallback(S=>{r(S.tabKey),i("chat"),a(S)},[a,i,r]),m=l.useCallback(S=>{const j=e.find(y=>y.routeId===S.routeId&&y.streamSource==="native");j&&(r(j.tabKey),i("chat"),a(j))},[e,a,i,r]),h=l.useCallback(()=>{a(t),i("inbox")},[a,t,i]),f=l.useCallback((S,j="inbox")=>{c(S),o(),d("machines"),u(j),i("machine")},[o,u,i,d,c]),x=l.useCallback(S=>{const j=sn(S);j&&f(j,"chat")},[f]),b=l.useCallback(()=>{o(),i(n)},[n,o,i]),g=l.useCallback(S=>{d(S),i("inbox")},[i,d]);return{openConversation:p,openNativeConversation:m,backFromConversation:h,openMachine:f,openConversationMachine:x,backFromMachine:b,changeMachineSection:g}}function bo(e,t){return e.category!==t?!1:t==="ide"?!0:e.enabled===!0}function TP(e){const t=e.trim();return t?t[0].toUpperCase():"?"}function IP({conversations:e,hiddenConversations:t,ides:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,userName:c,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,onOpenHistory:x,onOpenRemote:b,onStopCli:g,wsStatus:S,isConnected:j,initialDataLoaded:y=!0,onShowAllHiddenConversations:k,onHideConversation:v,onOpenMeshGraph:C,onOpenNewSession:w,liveSessionInboxState:N,setCliViewModeOverrides:T}){const[A,P]=l.useState(()=>{var X;return((X=e[0])==null?void 0:X.tabKey)||null}),[D,L]=l.useState(()=>e[0]?"chat":"inbox"),[I,R]=l.useState("chats"),[_,M]=l.useState(null),[$,V]=l.useState("inbox"),z=l.useRef([]),W=Qn(),F="1.0.59",B=l.useMemo(()=>e.find(X=>X.tabKey===A)||e[0]||null,[e,A]),E=l.useMemo(()=>B?n.find(X=>X.id===B.routeId):void 0,[n,B]),H=l.useMemo(()=>!B||gt(B)||!vt(B)?null:ja(B),[B]),J=l.useMemo(()=>n.filter(X=>X.type==="adhdev-daemon").sort(Sr),[n]),q=l.useMemo(()=>J.find(X=>X.id===_)||null,[J,_]),ie=pi({sendDaemonCommand:o,activeConv:B||void 0,setActionLogs:r,isStandalone:i}),xe=NP({sendDaemonCommand:o,navigate:W,ides:n,conversations:e}),Y=oA(e),ne=l.useMemo(()=>e.map(X=>{const te=D==="chat"&&(B==null?void 0:B.tabKey)===X.tabKey,de=ai(X,N,{hideOpenTaskCompleteUnread:!0,isOpenConversation:te}),ve=Bn(X),fe=Sf(X),U=Pf(X,fe);return{conversation:X,timestamp:ve,preview:U,unread:de.unread,requiresAction:de.requiresAction,isWorking:de.isWorking,inboxBucket:de.inboxBucket}}),[e,N,D,B,Y]),{markConversationRead:me}=wP({conversations:e,machineEntries:J,items:ne,selectedConversation:B,selectedTabKey:A,screen:D,liveSessionInboxState:N,sendDaemonCommand:o,requestedActiveTabKey:d,onRequestedActiveTabConsumed:u,requestedMachineId:p,onRequestedMachineConsumed:m,requestedMobileSection:h,onRequestedMobileSectionConsumed:f,setSelectedTabKey:P,setScreen:L,setSelectedMachineId:M,setSection:R,setMachineBackTarget:V,resetMachineAction:xe.resetMachineAction}),ce=AP({conversations:e,selectedConversation:B,machineBackTarget:$,markConversationRead:me,resetMachineAction:xe.resetMachineAction,setSelectedTabKey:P,setScreen:L,setSelectedMachineId:M,setSection:R,setMachineBackTarget:V}),{isMuted:ae,toggleMute:he}=Sg(N,o),{attentionItems:oe,unreadItems:re,workingItems:ee,completedItems:G}=l.useMemo(()=>bP(ne,z.current),[ne]);l.useEffect(()=>{z.current=ee.map(X=>X.conversation.tabKey)},[ee]);const Q=l.useMemo(()=>q?ne.filter(X=>sn(X.conversation)===q.id):[],[ne,q]),ue=l.useMemo(()=>xP(q,n),[n,q]),pe=!!q&&gd(q,Dn(q,F)),Ae=l.useMemo(()=>(q==null?void 0:q.availableProviders)||[],[q]),Me=l.useMemo(()=>Ae.filter(X=>bo(X,"cli")).map(X=>({type:X.type,displayName:X.displayName||X.type,icon:X.icon})),[Ae]),He=l.useMemo(()=>Ae.filter(X=>bo(X,"acp")).map(X=>({type:X.type,displayName:X.displayName||X.type,icon:X.icon})),[Ae]),je=l.useMemo(()=>vP(J,ne,t),[ne,J,t]),Z=l.useMemo(()=>bi(n,y),[n,y]),O=l.useCallback(async X=>{q&&await xe.handleOpenRecent(q.id,X)},[xe,q]);return s.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:D==="chat"&&B?s.jsx(oP,{selectedConversation:B,isAcp:gt(B),isStandalone:i,selectedIdeEntry:E,actionLogs:a,userName:c,commands:ie,onBack:ce.backFromConversation,onOpenNativeConversation:ce.openNativeConversation,onOpenMachine:ce.openConversationMachine,onOpenHistory:x,onOpenRemote:b,onOpenMeshGraph:C,onStopCli:g,cliViewMode:H,onSetCliViewMode:async X=>{await ag({conversation:B,mode:X,ides:n,sendDaemonCommand:o,setCliViewModeOverrides:T})}}):D==="machine"&&q?s.jsx(hP,{selectedMachineEntry:q,selectedMachineConversations:Q,selectedMachineRecentLaunches:ue,cliProviders:Me,acpProviders:He,selectedMachineNeedsUpgrade:pe,appVersion:F,machineAction:xe.machineAction,isStandalone:i,section:I,showBottomNav:$==="inbox",onBack:ce.backFromMachine,onSectionChange:ce.changeMachineSection,onOpenConversation:ce.openConversation,onOpenRecent:O,onOpenMachineDetails:()=>W(`/machines/${q.id}`),onMachineUpgrade:()=>xe.handleMachineUpgrade(q.id),onLaunchDetectedIde:(X,te)=>xe.handleLaunchDetectedIde(q.id,X,te),onAddWorkspace:(X,te)=>xe.handleAddWorkspace(q.id,X,te),onBrowseDirectory:X=>xe.handleBrowseDirectory(q.id,X),onLaunchWorkspaceProvider:(X,te,de)=>xe.handleLaunchWorkspaceProvider(q.id,X,te,de),onListSavedSessions:X=>xe.handleListSavedSessions(q.id,X)}):s.jsx(lP,{section:I,attentionItems:oe,unreadItems:re,workingItems:ee,completedItems:G,hiddenConversations:t,machineCards:je,getAvatarText:TP,actionLogs:a,sendDaemonCommand:o,onOpenConversation:ce.openConversation,onShowAllHidden:k,onHideConversation:v,onOpenMeshGraph:C,onStopCli:g,onOpenNewSession:w,onOpenMachine:ce.openMachine,onOpenSettings:()=>W("/settings"),onSectionChange:R,wsStatus:S,isConnected:j,initialDataLoaded:y,conversationsLoaded:Z,isStandalone:i,isConversationMuted:ae,onToggleMuteConversation:he})})}function al(e,t){return!!(e<4&&t&&window.innerWidth>=768)}function PP({conversations:e,numGroups:t,onMoveTab:n,onReceiveTab:a,onOwnTabDrop:o,onClearPreviewOrder:r}){const i=l.useRef(0),[c,d]=l.useState(!1),[u,p]=l.useState(null),m=l.useCallback(()=>{i.current=0,d(!1),p(null)},[]);l.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=l.useCallback(g=>{g.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,d(!0))},[]),f=l.useCallback(g=>{if(!g.dataTransfer.types.includes("text/tab-key"))return;if(g.preventDefault(),!al(t,n)){p("merge");return}const S=g.currentTarget.getBoundingClientRect(),j=g.clientX-S.left,y=S.width/3;j<y?p("split-left"):j>y*2?p("split-right"):p("merge")},[t,n]),x=l.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,d(!1),p(null))},[]),b=l.useCallback(g=>{i.current=0,d(!1);const S=g.dataTransfer.getData("text/tab-key"),j=S?e.some(k=>k.tabKey===S):!1,y=u;if(p(null),r(),!!S){if(g.preventDefault(),y==="split-left"&&al(t,n)){n==null||n(S,"split-left");return}if(y==="split-right"&&al(t,n)){n==null||n(S,"split-right");return}if(j){o(S);return}a==null||a(S)}},[e,u,t,n,a,o,r]);return{dragOver:c,dropAction:u,resetDragState:m,handleDragEnter:h,handleDragOver:f,handleDragLeave:x,handleDrop:b}}function LP(e,t){const n=new Set(t.map(r=>r.tabKey)),a=e.filter(r=>n.has(r)),o=t.filter(r=>!e.includes(r.tabKey)).map(r=>r.tabKey);return[...a,...o]}function DP({conversations:e,initialActiveTabId:t,initialTabOrder:n,onActiveTabChange:a,onTabOrderChange:o}){const[r,i]=l.useState(t??null),[c,d]=l.useState(n??[]),[u,p]=l.useState(null),m=l.useRef(null),h=l.useRef(null),f=l.useRef(a),x=l.useRef(o);l.useEffect(()=>{f.current=a},[a]),l.useEffect(()=>{x.current=o},[o]),l.useEffect(()=>{t&&t!==r&&i(t)},[t,r]),l.useEffect(()=>{d(w=>{const N=LP(w,e);return N.length===w.length&&N.every((T,A)=>T===w[A])?w:N})},[e]);const b=l.useMemo(()=>{const w=u??c;if(w.length===0)return e;const N=new Map(w.map((T,A)=>[T,A]));return[...e].sort((T,A)=>{const P=N.get(T.tabKey)??999,D=N.get(A.tabKey)??999;return P-D})},[e,u,c]);l.useEffect(()=>{var N,T;if(b.length===0){r!==null&&(i(null),(N=f.current)==null||N.call(f,null));return}if(r&&b.some(A=>A.tabKey===r))return;const w=b[0].tabKey;w!==r&&(i(w),(T=f.current)==null||T.call(f,w))},[b,r]);const g=l.useMemo(()=>b.find(w=>w.tabKey===r),[b,r]),S=l.useCallback(w=>{var N;i(w),(N=f.current)==null||N.call(f,w)},[]),j=l.useCallback((w,N,T)=>{d(A=>{var I;const P=A.filter(R=>R!==w),D=P.indexOf(N);if(D<0)return A;const L=T==="left"?D:D+1;return P.splice(L,0,w),(I=x.current)==null||I.call(x,P),P}),p(null)},[]),y=l.useCallback((w,N,T)=>{const P=(c.length>0?c:e.map(I=>I.tabKey)).filter(I=>I!==w),D=P.indexOf(N);if(D<0)return;const L=T==="left"?D:D+1;P.splice(L,0,w),m.current=P,p(P)},[c,e]),k=l.useCallback(()=>{var N;const w=m.current;w&&(d(w),(N=x.current)==null||N.call(x,w))},[]),v=l.useCallback(()=>{m.current=null,p(null)},[]),C=l.useCallback(w=>{d(N=>{var A;const T=N.filter(P=>P!==w);return T.push(w),(A=x.current)==null||A.call(x,T),T})},[]);return{activeTabId:r,activeConv:g,sortedConversations:b,previewOrderRef:m,draggingTabRef:h,selectTab:S,handleTabReorder:j,updatePreviewOrder:y,commitPreviewOrder:k,clearPreviewOrder:v,moveTabToEnd:C,setDraggingTabKey:w=>{h.current=w}}}function MP({dropAction:e,canSplit:t}){return s.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),s.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:e==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),s.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:e==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:e==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:t?1:.45},children:s.jsx("div",{className:"px-3 py-1.5 rounded-full text-2xs font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function kd({conversationsCount:e,isSplitMode:t,isStandalone:n,hasRegisteredMachines:a=!1,suppressGuide:o=!1,onOpenNewSession:r,isLoading:i=!1}){const{t:c}=ye("common");if(o)return s.jsx("div",{className:"text-sm text-text-muted opacity-0 select-none","aria-hidden":"true",children:c("paneGroup.noActiveAgent")});if(i)return s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center gap-3 -mt-8 text-text-muted",children:[s.jsx(Cs,{}),s.jsx("p",{className:"text-sm",children:c("paneGroup.loadingSessions")})]});const d=!n&&!a,u=a&&!!r,p=c(a?"paneGroup.noConversations":n?"paneGroup.waitingForDaemon":"paneGroup.connectYourMachines"),m=c(a?"paneGroup.newSessionDescription":n?"paneGroup.daemonDescription":"paneGroup.installDescription");return e===0&&!t?s.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[s.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),s.jsxs("div",{className:"text-center max-w-lg",children:[s.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:p}),s.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:m}),u&&s.jsx("div",{className:"flex items-center justify-center mb-4",children:s.jsxs("button",{type:"button",onClick:r,className:"btn btn-primary btn-sm inline-flex items-center gap-2",title:c("paneGroup.newSession"),"aria-label":c("paneGroup.newSession"),children:[s.jsx(co,{size:14}),s.jsx("span",{children:c("paneGroup.newSession")})]})}),d&&s.jsx(xg,{}),d&&s.jsx("div",{className:"mt-8",children:s.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:c("machine.card.emptyDocsLink")})})]})]}):s.jsx("div",{className:"text-sm text-text-muted opacity-50",children:c(t?"paneGroup.moveTabHere":"paneGroup.noActiveAgent")})}const jg="adhdev-tab-shortcuts";function Ng(){try{return JSON.parse(localStorage.getItem(jg)||"{}")}catch{return{}}}function Ag({enabled:e=!0,sortedTabKeys:t,onFocus:n,onSelectTab:a}){const o=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[r,i]=l.useState(()=>Ng()),[c,d]=l.useState(null),u=l.useCallback(m=>{const h=[];return m.metaKey&&h.push(o?"⌘":"Meta"),m.ctrlKey&&h.push("Ctrl"),m.altKey&&h.push(o?"⌥":"Alt"),m.shiftKey&&h.push(o?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(m.key)?null:(h.push(m.key.length===1?m.key.toUpperCase():m.key),h.join("+"))},[o]),p=l.useCallback(m=>{i(m);try{localStorage.setItem(jg,JSON.stringify(m))}catch{}},[]);return l.useEffect(()=>{if(!e||!c)return;const m=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){d(null);return}const f=u(h);if(!f)return;const x={...r};for(const[b,g]of Object.entries(x))g===f&&delete x[b];x[c]=f,p(x),d(null)};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[e,c,r,p,u]),l.useEffect(()=>{if(!e)return;const m=h=>{if(!(!h.ctrlKey&&!h.metaKey&&!h.altKey)){for(const[f,x]of Object.entries(r))if(t.includes(f)&&u(h)===x){h.preventDefault(),n(),a(f);return}}};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[e,r,t,n,a,u]),{isMac:o,tabShortcuts:r,shortcutListening:c,setShortcutListening:d,saveShortcuts:p}}const ol=e=>{e.preventDefault()},RP=l.memo(function({conv:t,isActive:n,isDraggedTab:a,isTaskCompleteUnread:o,shortcut:r,conversationKeys:i,draggingTabRef:c,onFocus:d,onSelectTab:u,onConversationActivated:p,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:f,onClearPreviewOrder:x,onDragStateReset:b,onDragTabKeyChange:g,onReceiveTab:S,onOpenContextMenu:j,longPressTimer:y,isGroupActive:k}){const v=Xn(t),C=v.isGenerating?"agent-tab-generating":v.isWaiting?"agent-tab-waiting":"",w=v.isReconnecting,N=YA(t),T=QA(t),A=If(t),P=l.useCallback(z=>{c.current=t.tabKey,g(t.tabKey),z.dataTransfer.setData("text/tab-key",t.tabKey),z.dataTransfer.effectAllowed="move"},[t.tabKey,c,g]),D=l.useCallback(()=>{c.current=null,g(null),f(),x(),b()},[c,g,f,x,b]),L=l.useCallback(z=>{const W=c.current;if(!(!W||W===t.tabKey)&&z.dataTransfer.types.includes("text/tab-key")){z.preventDefault(),z.stopPropagation();const F=z.currentTarget.getBoundingClientRect(),B=z.clientX<F.left+F.width/2?"left":"right";m(W,t.tabKey,B)}},[t.tabKey,c,m]),I=l.useCallback(z=>{z.preventDefault(),z.stopPropagation();const W=z.dataTransfer.getData("text/tab-key");if(W&&W!==t.tabKey){const F=z.currentTarget.getBoundingClientRect(),B=z.clientX<F.left+F.width/2?"left":"right";i.includes(W)?h(W,t.tabKey,B):S&&S(W)}x()},[t.tabKey,i,h,S,x]),R=l.useCallback(z=>{z.stopPropagation(),d(),u(t.tabKey),p(t)},[t,p,d,u]),_=l.useCallback(z=>{z.preventDefault(),j(z.clientX,z.clientY,t.tabKey)},[t.tabKey,j]),M=l.useCallback(z=>{const W=z.touches[0];y.current=setTimeout(()=>{j(W.clientX,W.clientY,t.tabKey)},600)},[t.tabKey,y,j]),$=l.useCallback(()=>{y.current&&clearTimeout(y.current)},[y]),V=["adhdev-dockview-tab",C,n&&"is-active",k&&"is-group-active",w&&"is-reconnecting"].filter(Boolean).join(" ");return s.jsxs("div",{"data-tabkey":t.tabKey,className:V,draggable:!0,onDragStart:P,onDragEnd:D,onDragOver:L,onDrop:I,onClick:R,onContextMenu:_,onTouchStart:M,onTouchEnd:$,onTouchMove:$,style:{position:"relative",cursor:"pointer",opacity:a?.4:void 0},children:[A&&s.jsx("span",{className:"adhdev-dockview-tab-mesh-badge pointer-events-none absolute top-0.5 right-0.5 text-text-muted",title:"Mesh chat","aria-label":"Mesh chat",children:s.jsx(js,{size:11})}),o&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status",children:v.isGenerating?s.jsx(Cs,{size:12,thickness:2,color:"success"}):v.isWaiting?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):w?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):v.isConnecting?s.jsx(Cs,{size:12,thickness:2}):t.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),N.length>0&&s.jsx("span",{className:"adhdev-dockview-tab-mesh-role",title:T,"aria-label":T||N.join(" · "),children:N.join(" · ")}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("span",{className:"adhdev-dockview-tab-primary",title:At(t),children:At(t)}),s.jsxs("span",{className:"adhdev-dockview-tab-meta inline-flex min-w-0 items-center gap-1",children:[w?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting truncate",children:Hn(t)}):v.isConnecting?s.jsxs("span",{className:"adhdev-dockview-tab-connecting truncate",children:[Hn(t),s.jsx("span",{className:"connecting-dots"})]}):s.jsx("span",{className:"truncate",children:Hn(t)}),s.jsx(Pr,{git:t.git,compact:!0,className:"max-w-[6.5rem] shrink-0"})]})]}),r&&s.jsx("span",{className:"text-4xs opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:r,children:r})]})},(e,t)=>e.conv===t.conv&&e.isActive===t.isActive&&e.isDraggedTab===t.isDraggedTab&&e.isTaskCompleteUnread===t.isTaskCompleteUnread&&e.shortcut===t.shortcut&&e.conversationKeys===t.conversationKeys&&e.isGroupActive===t.isGroupActive);function _P({conversations:e,activeTabId:t,groupIndex:n,unreadTabKeys:a,draggingTabRef:o,onFocus:r,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:u,onCommitPreviewOrder:p,onClearPreviewOrder:m,onDragStateReset:h,onDragTabKeyChange:f,onReceiveTab:x,onHideTab:b,isGroupActive:g,allowTabShortcuts:S=!0}){const{t:j}=ye("common"),[y,k]=l.useState(null),v=l.useRef(null),C=l.useRef(null),w=l.useMemo(()=>e.map(I=>I.tabKey),[e]);ko("PaneGroupTabBar",{groupIndex:n,activeTabId:t,tabCount:e.length,ctxMenuTab:(y==null?void 0:y.tabKey)||null});const{isMac:N,tabShortcuts:T,shortcutListening:A,setShortcutListening:P,saveShortcuts:D}=Ag({enabled:S,sortedTabKeys:e.map(I=>I.tabKey),onFocus:r,onSelectTab:i});l.useEffect(()=>{if(!y)return;const I=R=>{const _=document.querySelector("[data-pane-context-menu]");_&&_.contains(R.target)||k(null)};return window.addEventListener("mousedown",I,!0),()=>window.removeEventListener("mousedown",I,!0)},[y]),l.useEffect(()=>{const I=C.current;if(!I)return;const R=_=>{Math.abs(_.deltaY)<=Math.abs(_.deltaX)||(_.preventDefault(),I.scrollLeft+=_.deltaY)};return I.addEventListener("wheel",R,{passive:!1}),()=>I.removeEventListener("wheel",R)},[]);const L=l.useCallback((I,R,_)=>{k({x:I,y:R,tabKey:_})},[]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:s.jsxs("div",{ref:C,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none",overscrollBehaviorX:"contain"},children:[e.map(I=>s.jsx(RP,{conv:I,isActive:t===I.tabKey,isDraggedTab:o.current===I.tabKey,isTaskCompleteUnread:a.has(I.tabKey),shortcut:S?T[I.tabKey]:void 0,conversationKeys:w,draggingTabRef:o,onFocus:r,onSelectTab:i,onConversationActivated:c,onPreviewReorder:d,onReorderTab:u,onCommitPreviewOrder:p,onClearPreviewOrder:m,onDragStateReset:h,onDragTabKeyChange:f,onReceiveTab:x,onOpenContextMenu:L,longPressTimer:v,isGroupActive:g},I.tabKey)),e.length===0&&s.jsx("div",{className:"p-2 text-xs opacity-40",children:j("paneGroup.noTabsInGroup")})]})}),y&&s.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:y.x,top:y.y},children:[S&&s.jsxs(s.Fragment,{children:[s.jsxs("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onMouseDown:ol,onClick:I=>{I.stopPropagation(),P(y.tabKey),k(null)},children:["⌨ ",T[y.tabKey]?`Change shortcut (${T[y.tabKey]})`:"Set shortcut"]}),T[y.tabKey]&&s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onMouseDown:ol,onClick:()=>{const I={...T};delete I[y.tabKey],D(I),k(null)},children:"✕ Remove shortcut"})]}),b&&s.jsxs(s.Fragment,{children:[S&&s.jsx("div",{className:"border-t border-border-subtle my-1"}),s.jsx("button",{type:"button",className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onMouseDown:ol,onClick:()=>{b(y.tabKey),k(null)},children:s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(Xr,{size:12}),"Hide from Dashboard"]})})]})]}),S&&A&&s.jsx(xs,{children:s.jsx("div",{className:"fixed inset-0 z-[var(--z-modal)] flex items-center justify-center bg-black/50",style:{backdropFilter:"blur(2px)"},onClick:()=>P(null),children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:I=>I.stopPropagation(),children:[s.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),s.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),s.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),s.jsx("div",{className:"text-3xs text-text-muted mt-3",children:j("paneGroup.pressEscToCancel")})]})})})]})}function EP({conversations:e,ides:t,clearedTabs:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d=!0,userName:u,groupIndex:p,onFocus:m,isSplitMode:h,numGroups:f,onMoveTab:x,onReceiveTab:b,style:g,onActiveTabChange:S,initialActiveTabId:j,initialTabOrder:y,onTabOrderChange:k,onHideTab:v,isFocused:C,allowTabShortcuts:w=!0,onOpenNewSession:N,liveSessionInboxState:T}){const{sendCommand:A}=wt(),P=l.useRef(null),{activeTabId:D,activeConv:L,sortedConversations:I,draggingTabRef:R,selectTab:_,handleTabReorder:M,updatePreviewOrder:$,commitPreviewOrder:V,clearPreviewOrder:z,moveTabToEnd:W,setDraggingTabKey:F}=DP({conversations:e,initialActiveTabId:j,initialTabOrder:y,onActiveTabChange:S,onTabOrderChange:k}),B=pi({sendDaemonCommand:o,activeConv:L,setActionLogs:r,isStandalone:i}),{dragOver:E,dropAction:H,resetDragState:J,handleDragEnter:q,handleDragOver:ie,handleDragLeave:xe,handleDrop:Y}=PP({conversations:e,numGroups:f,onMoveTab:x,onReceiveTab:b,onOwnTabDrop:W,onClearPreviewOrder:z}),ne=L&&!gt(L)&&ja(L)==="terminal",me=l.useMemo(()=>L?t.find(oe=>oe.id===L.routeId):void 0,[t,L]),ce=l.useMemo(()=>L?a.filter(oe=>oe.routeId===L.tabKey):[],[a,L]),ae=l.useMemo(()=>new Set(I.filter(oe=>Py(oe,T,{isOpenConversation:oe.tabKey===D})).map(oe=>oe.tabKey)),[D,T,I]);ko("PaneGroup",{groupIndex:p,conversationCount:e.length,activeTabId:D,dragOver:E});const he=l.useCallback(oe=>{oe.streamSource==="agent-stream"&&oe.agentType&&A(oe.routeId,df(),{agentType:oe.agentType,...oe.sessionId&&{targetSessionId:oe.sessionId}}).catch(()=>{})},[A]);return s.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:m,style:{...g,outline:E?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[s.jsx(_P,{conversations:I,activeTabId:D,groupIndex:p,numGroups:f,unreadTabKeys:ae,draggingTabRef:R,onFocus:m,onSelectTab:_,onConversationActivated:he,onPreviewReorder:$,onReorderTab:M,onCommitPreviewOrder:V,onClearPreviewOrder:z,onDragStateReset:J,onDragTabKeyChange:F,onMoveTab:x,onReceiveTab:b,onHideTab:v,isGroupActive:C??!1,allowTabShortcuts:w}),s.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:q,onDragOver:ie,onDragLeave:xe,onDrop:Y,children:[E&&s.jsx(MP,{dropAction:H,canSplit:!!(f<4&&x)}),L?s.jsx(yd,{activeConv:L,clearToken:n[L.tabKey]||0,isCliTerminal:!!ne,ideEntry:me,terminalRef:P,commands:B,actionLogs:ce,userName:u,isInputActive:!h||!!C}):s.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:s.jsx(kd,{conversationsCount:e.length,isSplitMode:h,isStandalone:i,hasRegisteredMachines:c,onOpenNewSession:N,isLoading:!bi(t,d)})})]})]})}function HP({containerRef:e,isSplitMode:t,numGroups:n,groupSizes:a,groupedConvs:o,clearedTabs:r,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:u,isStandalone:p,hasRegisteredMachines:m,initialDataLoaded:h,userName:f,focusedGroup:x,focusGroup:b,moveTabToGroup:g,splitTabRelative:S,closeGroup:j,handleResizeStart:y,groupActiveTabIds:k,setGroupActiveTab:v,groupTabOrders:C,setGroupTabOrder:w,toggleHiddenTab:N,onOpenNewSession:T,allowTabShortcuts:A=!0,liveSessionInboxState:P}){return s.jsx("div",{ref:e,className:`flex-1 min-h-0 flex ${t?"flex-row":"flex-col"} overflow-hidden`,children:o.map((D,L)=>{const I=t&&a.length===n?`${a[L]}%`:void 0;return s.jsxs(jt.Fragment,{children:[t&&L>0&&s.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:R=>y(L-1,R),onDoubleClick:()=>j(L),title:"Drag to resize · Double-click to merge",children:s.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),s.jsx(EP,{style:t?{flexBasis:I??`${100/n}%`,flexGrow:I?0:1,flexShrink:I?0:1}:void 0,conversations:D,clearedTabs:r,ides:i,actionLogs:c,sendDaemonCommand:d,setActionLogs:u,isStandalone:p,hasRegisteredMachines:m,initialDataLoaded:h,userName:f,groupIndex:L,isFocused:t&&x===L,onFocus:()=>b(L),isSplitMode:t,numGroups:n,onMoveTab:(R,_)=>{_==="left"&&L>0?g(R,L-1):_==="right"&&L<n-1?g(R,L+1):_==="split-left"&&n<4?S(R,L,"left"):_==="split-right"&&n<4&&S(R,L,"right")},onReceiveTab:R=>g(R,L),onActiveTabChange:R=>v(L,R),initialActiveTabId:k[L],initialTabOrder:C[L],onTabOrderChange:R=>w(L,R),onHideTab:N,onOpenNewSession:T,allowTabShortcuts:A,liveSessionInboxState:P})]},L)})})}const Tg="adhdev-dashboard-action-shortcuts",FP=1200,$P=[["toggleHiddenTabs","G H"],["openNewSession","N"],["setActiveTabShortcut","G S"],["selectPreviousGroupTab","G K"],["selectPreviousGroupTab","T ←"],["selectPreviousGroupTab","⌥+["],["selectPreviousGroupTab","Ctrl+Alt+["],["selectNextGroupTab","G J"],["selectNextGroupTab","T →"],["selectNextGroupTab","⌥+]"],["selectNextGroupTab","Ctrl+Alt+]"],["splitActiveTabDown","S ↓"],["splitActiveTabDown","⌘+⌥+-"],["splitActiveTabDown","Ctrl+Alt+-"],["splitActiveTabRight","S →"],["splitActiveTabRight","⌘+⌥+\\"],["splitActiveTabRight","⌘+⌥+="],["splitActiveTabRight","Ctrl+Alt+\\"],["focusLeftPane","F ←"],["focusLeftPane","⌘+⌥+←"],["focusLeftPane","⌘+⌥+["],["focusLeftPane","Ctrl+Alt+←"],["focusRightPane","F →"],["focusRightPane","⌘+⌥+→"],["focusRightPane","⌘+⌥+]"],["focusRightPane","Ctrl+Alt+→"],["focusUpPane","F ↑"],["focusUpPane","⌘+⌥+U"],["focusUpPane","Ctrl+Alt+↑"],["focusDownPane","F ↓"],["focusDownPane","⌘+⌥+J"],["focusDownPane","Ctrl+Alt+↓"],["moveActiveTabToLeftPane","M ←"],["moveActiveTabToLeftPane","⌘+⌥+⇧+←"],["moveActiveTabToLeftPane","⌘+⌥+,"],["moveActiveTabToLeftPane","Ctrl+Alt+Shift+←"],["moveActiveTabToRightPane","M →"],["moveActiveTabToRightPane","⌘+⌥+⇧+→"],["moveActiveTabToRightPane","⌘+⌥+."],["moveActiveTabToRightPane","Ctrl+Alt+Shift+→"],["moveActiveTabToUpPane","M ↑"],["moveActiveTabToUpPane","⌘+⌥+I"],["moveActiveTabToUpPane","Ctrl+Alt+Shift+↑"],["moveActiveTabToDownPane","M ↓"],["moveActiveTabToDownPane","⌘+⌥+K"],["moveActiveTabToDownPane","Ctrl+Alt+Shift+↓"],["triggerPrimaryApprovalAction","⌥+A"],["triggerSecondaryApprovalAction","⌥+D"],["toggleCliView","T"]];function BP(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function xt(e,t){switch(e){case"openShortcutHelp":return"?";case"openNewSession":return t?"⌘+⇧+Enter":"Ctrl+Shift+Enter";case"hideCurrentTab":return t?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return t?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return t?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return t?"⌥+R":"Ctrl+Alt+R";case"floatActiveTab":return t?"⌥+F":"Ctrl+Alt+F";case"popoutActiveTab":return t?"⌥+P":"Ctrl+Alt+P";case"dockActiveTab":return t?"⌥+D":"Ctrl+Alt+D";case"splitActiveTabRight":return t?"⌘+Ctrl+⇧+→":"Ctrl+Alt+Shift+→";case"splitActiveTabDown":return t?"⌘+Ctrl+⇧+↓":"Ctrl+Alt+Shift+↓";case"focusLeftPane":return"";case"focusRightPane":return"";case"focusUpPane":return"";case"focusDownPane":return"";case"moveActiveTabToLeftPane":return"";case"moveActiveTabToRightPane":return"";case"moveActiveTabToUpPane":return"";case"moveActiveTabToDownPane":return"";case"triggerPrimaryApprovalAction":return t?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return t?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return t?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return t?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return t?"⌘+⇧+←":"Ctrl+Shift+←";case"selectNextGroupTab":return t?"⌘+⇧+→":"Ctrl+Shift+→";case"toggleCliView":return t?"⌥+T":"Ctrl+Alt+T"}}function Ig(e){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:xt("openShortcutHelp",e)},{id:"openNewSession",label:"New session",description:"Open the new session launcher.",defaultShortcut:xt("openNewSession",e)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:xt("hideCurrentTab",e)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:xt("toggleHiddenTabs",e)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:xt("openHistoryForActiveTab",e)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:xt("openRemoteForActiveTab",e)},{id:"floatActiveTab",label:"Float active tab",description:"Move the active tab into a floating panel.",defaultShortcut:xt("floatActiveTab",e)},{id:"popoutActiveTab",label:"Open active tab in new window",description:"Move the active tab into a detached popout window.",defaultShortcut:xt("popoutActiveTab",e)},{id:"dockActiveTab",label:"Dock active tab",description:"Dock a floating tab back into the grid, or move a popout tab back to the main window.",defaultShortcut:xt("dockActiveTab",e)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:xt("splitActiveTabRight",e)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:xt("splitActiveTabDown",e)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:xt("focusLeftPane",e)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:xt("focusRightPane",e)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:xt("focusUpPane",e)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:xt("focusDownPane",e)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:xt("moveActiveTabToLeftPane",e)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:xt("moveActiveTabToRightPane",e)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:xt("moveActiveTabToUpPane",e)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:xt("moveActiveTabToDownPane",e)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:xt("triggerPrimaryApprovalAction",e)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:xt("triggerSecondaryApprovalAction",e)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:xt("triggerTertiaryApprovalAction",e)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:xt("setActiveTabShortcut",e)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:xt("selectPreviousGroupTab",e)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:xt("selectNextGroupTab",e)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:xt("toggleCliView",e)}]}function gc(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"}function $r(e){const t=Object.fromEntries(Ig(e).map(n=>[n.id,n.defaultShortcut]));try{const n=JSON.parse(localStorage.getItem(Tg)||"{}"),a={...t,...n};for(const[o,r]of $P)a[o]===r&&(a[o]=t[o]);return a}catch{return t}}function Pg(e){return e===" "?"Space":e==="Escape"?"Esc":e==="ArrowLeft"?"←":e==="ArrowRight"?"→":e==="ArrowUp"?"↑":e==="ArrowDown"?"↓":e.length===1?e.toUpperCase():e}function WP({enabled:e=!0,onTrigger:t}){const n=BP(),[a,o]=l.useState(()=>$r(n)),[r,i]=l.useState(null),[c,d]=l.useState([]),u=l.useRef({parts:[],timer:null}),p=l.useCallback(b=>{const g=[];return b.metaKey&&g.push(n?"⌘":"Meta"),b.ctrlKey&&g.push("Ctrl"),b.altKey&&g.push(n?"⌥":"Alt"),b.shiftKey&&b.key.length!==1&&g.push(n?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(b.key)?null:(g.push(Pg(b.key)),g.join("+"))},[n]),m=l.useCallback(b=>{o(b);try{localStorage.setItem(Tg,JSON.stringify(b))}catch{}},[]);l.useEffect(()=>{const b=$r(n),g=Object.entries(a),S=Object.entries(b);g.length===S.length&&g.every(([j,y])=>b[j]===y)||m(b)},[a,n,m]);const h=l.useCallback(()=>{typeof window<"u"&&u.current.timer!=null&&window.clearTimeout(u.current.timer),u.current={parts:[],timer:null}},[]),f=l.useCallback(()=>{typeof window>"u"||(u.current.timer!=null&&window.clearTimeout(u.current.timer),u.current.timer=window.setTimeout(()=>{u.current={parts:[],timer:null}},FP))},[]);l.useEffect(()=>{if(!r)return;const b=g=>{if(g.preventDefault(),g.stopPropagation(),g.key==="Escape"){i(null),d([]);return}const S=p(g);if(!S)return;const y=!(g.metaKey||g.ctrlKey||g.altKey)&&/^[A-Z0-9]$/.test(S);if(c.length===0&&y){d([S]);return}const v=[...c,S].slice(0,2).join(" "),C={...a};for(const[w,N]of Object.entries(C))N===v&&delete C[w];C[r]=v,m(C),i(null),d([])};return window.addEventListener("keydown",b,!0),()=>window.removeEventListener("keydown",b,!0)},[a,p,m,r,c]),l.useEffect(()=>{if(!e||r)return;const b=g=>{if(g.defaultPrevented)return;const S=p(g);if(!S)return;const j=g.metaKey||g.ctrlKey||g.altKey;if(gc(g.target))return;const y=u.current.parts,k=j?[S]:[...y.slice(-1),S].slice(-2),v=k.join(" "),C=k[k.length-1],w=Object.entries(a).filter(([,D])=>!!D),N=w.find(([,D])=>D===v);if(N){g.preventDefault(),h(),t(N[0]);return}if(w.some(([,D])=>D.startsWith(`${v} `))){g.preventDefault(),u.current.parts=k,f();return}const A=w.find(([,D])=>D===C);if(A){g.preventDefault(),h(),t(A[0]);return}if(w.some(([,D])=>D.startsWith(`${C} `))){g.preventDefault(),u.current.parts=[C],f();return}h()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[a,f,e,p,t,h,r]),l.useEffect(()=>()=>h(),[h]);const x=l.useMemo(()=>Ig(n),[n]);return{isMac:n,actionDefinitions:x,actionShortcuts:a,shortcutListening:r,shortcutListeningDraft:c,setShortcutListening:i,setShortcutListeningDraft:d,saveShortcuts:m}}function OP({isTabInPopout:e,isTabFloating:t,tabShortcut:n,actionShortcuts:a}){const o=[];return e?(t&&o.push({type:"action",id:"dockInWindow",label:"Dock in window",shortcut:a.dockActiveTab}),o.push({type:"action",id:"moveBackToMain",label:"Move back to main window",shortcut:a.dockActiveTab})):t?o.push({type:"action",id:"dockBackToGrid",label:"Dock back to grid",shortcut:a.dockActiveTab}):o.push({type:"action",id:"floatAsPanel",label:"Float as panel",shortcut:a.floatActiveTab},{type:"action",id:"openInNewWindow",label:"Open in new window",shortcut:a.popoutActiveTab}),o.push({type:"separator",id:"before-shortcut-actions"},{type:"action",id:"setShortcut",label:n?`Change shortcut (${n})`:"Set shortcut",shortcut:a.setActiveTabShortcut}),n&&o.push({type:"action",id:"removeShortcut",label:"Remove shortcut",tone:"muted"}),o.push({type:"separator",id:"before-hide-tab"},{type:"action",id:"hideTab",label:"Hide tab",shortcut:a.hideCurrentTab,tone:"muted"}),o}function Lg(e){return e.some(t=>t.type!=="adhdev-daemon")||e.some(t=>t.type==="adhdev-daemon"&&!!t.machine)}function Dp({hasStoredLayout:e,initialDataLoaded:t,visibleConversationCount:n,ides:a}){return!e||n>0?!1:t?!Lg(a):!0}function UP({previousVisibleConversationCount:e,visibleConversationCount:t,ides:n}){return t>0||e<=0?!1:Lg(n)}const Dg=1e3,qP=4;function Mp(e,t){return t?e.clientX>=t.left&&e.clientX<=t.right&&e.clientY>=t.top&&e.clientY<=t.bottom:!1}function Rp(e,t,n){return Math.abs(t.clientX-e.clientX)>n||Math.abs(t.clientY-e.clientY)>n}function zP({detachDelayMs:e=Dg,stillnessThresholdPx:t=qP,onDetach:n,setTimeoutFn:a=globalThis.setTimeout.bind(globalThis),clearTimeoutFn:o=globalThis.clearTimeout.bind(globalThis)}){let r=null,i=null,c=null,d=null,u=null,p=!1;const m=()=>{u!=null&&(o(u),u=null)},h=()=>{m(),c=null},f=()=>{m(),r=null,i=null,c=null,d=null,p=!1},x=()=>{!r||!c||!d||p||u!=null||(u=a(()=>{u=null,!(!r||!c||!d||p)&&Mp(d,i)&&(Rp(c,d,t)||(p=!0,n({panelId:r,clientX:d.clientX,clientY:d.clientY})))},e))},b=S=>{if(!(!r||p)){if(!Mp(S,i)){d={clientX:S.clientX,clientY:S.clientY},h();return}(!c||Rp(c,S,t))&&(m(),c={clientX:S.clientX,clientY:S.clientY}),d={clientX:S.clientX,clientY:S.clientY},x()}},g=S=>{!r||p||(S&&(d={clientX:S.clientX,clientY:S.clientY}),h())};return{startDrag:S=>{m(),r=S.panelId,i=S.selfPanelBounds??null,c=null,d={clientX:S.clientX,clientY:S.clientY},p=!1},markSelfPanel:b,markNonSelfPanel:g,markNoDropTarget:g,markDockTarget:g,endDrag:f,isDragging:()=>r!=null,hasDetached:()=>p,dispose:f}}function GP(e=typeof window>"u"?null:window.localStorage){return(e==null?void 0:e.getItem("adhdev:dockviewIdleDragFloat"))!=="off"}function br(e){return At(e)||e.tabKey}function KP(e){return`remote:${e}`}function Ps(e){return e.startsWith("remote:")}function _p(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function rl(e){var a;const t=e==null?void 0:e.defaultView;if(!t)return;const n=o=>{if(o)try{o.focus({preventScroll:!0})}catch{try{o.focus()}catch{}}};try{t.focus(),n(e==null?void 0:e.body),n(e==null?void 0:e.documentElement),(a=t.requestAnimationFrame)==null||a.call(t,()=>{try{t.focus(),n(e==null?void 0:e.body)}catch{}})}catch{}}function il(e,t){e.classList.remove(Ml.className,Rl.className),e.classList.add(t==="light"?Ml.className:Rl.className)}function Ep(e){return e?Array.from(new Set(e.groups.map(t=>{var n,a;return(a=(n=t.element)==null?void 0:n.ownerDocument)==null?void 0:a.defaultView}).filter(t=>!!t&&t!==window))):[]}function VP(e,t,n){var i;const a=[t];let o;for(const c of a){let d;for(const u of c){const p=e.addPanel({id:u.tabKey,component:"conversation",title:br(u),params:{kind:"conversation",tabKey:u.tabKey},...d?{position:{referencePanel:d,direction:"within"},inactive:!0}:o?{position:{referencePanel:o,direction:"right"},inactive:!0}:{}});d||(d=p.id)}o=d??o}return n??((i=t[0])==null?void 0:i.tabKey)??null}function Hp(e,t){const n=new Set(t.map(o=>o.tabKey)),a=new Map;for(const o of t)a.set(o.tabKey,(a.get(o.tabKey)||0)+1);for(const o of[...e.panels])Ps(o.id)||n.has(o.id)||e.removePanel(o);for(const o of t){const r=e.getPanel(o.tabKey);if(r){(a.get(o.tabKey)||0)>1&&console.warn("[dashboard-conversations] Dockview panel already exists for duplicate tabKey",{tabKey:o.tabKey,daemonId:o.daemonId,sessionId:o.sessionId,providerSessionId:o.providerSessionId,panelId:r.id}),r.update({params:{tabKey:o.tabKey}}),r.title!==br(o)&&r.api.setTitle(br(o));continue}e.addPanel({id:o.tabKey,component:"conversation",title:br(o),params:{kind:"conversation",tabKey:o.tabKey},...e.activePanel?{position:{referencePanel:e.activePanel.id,direction:"within"},inactive:!0}:e.panels[0]?{position:{referencePanel:e.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Fp(e,t,n){var d,u;const a=n?KP(n):null;for(const p of[...e.panels])Ps(p.id)&&(!a||p.id!==a)&&e.removePanel(p);if(!n||!a)return;const o=_s(t,n);if(!o&&e.totalPanels===0)return;const r=e.getPanel(a),i=Mf(o);if(r){r.title!==i&&r.api.setTitle(i);return}const c=(o==null?void 0:o.tabKey)??((d=e.activePanel)==null?void 0:d.id)??((u=e.panels.find(p=>!Ps(p.id)))==null?void 0:u.id);e.addPanel({id:a,component:"remote",title:i,params:{kind:"remote",routeId:n},...c?{position:{referencePanel:c,direction:"right"},inactive:!0}:{}})}function Mg({doId:e,targetSessionId:t,connState:n,viewMode:a}){const[o,r]=l.useState(null),[i,c]=l.useState(null);l.useEffect(()=>e?_t.onScreenshot("ide-page",(p,m)=>{if(p!==e)return;const h=new FileReader;h.onload=()=>r(h.result),h.readAsDataURL(m)}):void 0,[e]),l.useEffect(()=>{n!=="connected"&&r(null)},[n]),l.useEffect(()=>{var p;return e?((p=_t.onStatus)==null?void 0:p.call(_t,(m,h)=>{m===e&&h!=null&&h.screenshotUsage&&c(h.screenshotUsage)}))||(()=>{}):void 0},[e]),l.useEffect(()=>{r(null)},[e,t]),l.useEffect(()=>{const u=e?_t.get(e):null;if(!(!u||n!=="connected"))return a!=="chat"&&t?u.startScreenshots(t):u.stopScreenshots(t),()=>{u.stopScreenshots(t)}},[a,n,t,e]);const d=l.useCallback(async(u,p)=>{const m=e?_t.get(e):null;return!m||n!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):m.sendInput(u,p,t)},[e,n,t]);return{connScreenshot:o,screenshotUsage:i,handleRemoteAction:d}}const Rg=l.createContext(null);function xi(){const e=l.useContext(Rg);if(!e)throw new Error("DashboardDockviewContext missing");return e}function YP(e){const[,t]=l.useState(0);l.useEffect(()=>{const n=()=>t(o=>o+1),a=[e.api.onDidActiveGroupChange(n),e.api.onDidTitleChange(n),e.api.onDidGroupChange(n),e.containerApi.onDidActivePanelChange(n)];return()=>{for(const o of a)o.dispose()}},[e.api,e.containerApi])}function QP({params:e}){var d;const t=xi(),n=l.useMemo(()=>_s([...t.conversationsByTabKey.values()],e.routeId),[t.conversationsByTabKey,e.routeId]),a=l.useMemo(()=>t.ides.find(u=>u.id===e.routeId),[t.ides,e.routeId]),o=(n==null?void 0:n.daemonId)||((d=n==null?void 0:n.routeId)==null?void 0:d.split(":")[0])||e.routeId.split(":")[0]||e.routeId,{connScreenshot:r,screenshotUsage:i,handleRemoteAction:c}=Mg({doId:o,targetSessionId:n?lf(n):(a==null?void 0:a.sessionId)||(a==null?void 0:a.instanceId),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote"});return n?s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:s.jsx(xh,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:r,screenshotUsage:i,transportType:n.transport,onAction:c})}):s.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function JP(){const e=xi();return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:s.jsx(kd,{conversationsCount:0,isSplitMode:!1,isStandalone:e.isStandalone,hasRegisteredMachines:e.hasRegisteredMachines,onOpenNewSession:e.onOpenNewSession,suppressGuide:e.hasDetachedConversationPanels,isLoading:!bi(e.ides,e.initialDataLoaded)})})}function XP(e){var j,y;YP(e);const t=xi(),n=l.useCallback(k=>{"button"in k&&k.button!==0||e.api.setActive()},[e.api]),a=e.params.kind==="remote"?void 0:t.conversationsByTabKey.get(e.params.tabKey),o=a==null?void 0:a.sessionId,r=l.useCallback(k=>TA(k),[]),i=l.useCallback(()=>AA(o),[o]),c=l.useSyncExternalStore(r,i,i);if(e.params.kind==="remote"){const k=_s([...t.conversationsByTabKey.values()],e.params.routeId),v=((j=e.api.group.activePanel)==null?void 0:j.id)===e.api.id,C=e.api.isGroupActive;return s.jsxs("div",{className:`adhdev-dockview-tab${v?" is-active":""}${C?" is-group-active":""}`,title:e.api.title||"Remote","data-tab-key":(k==null?void 0:k.tabKey)||"",onMouseDown:n,onTouchStart:n,children:[s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||"Remote"}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:k!=null&&k.machineName?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"Live remote view"}),s.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),s.jsx("span",{className:"adhdev-dockview-tab-machine",children:k.machineName})]}):s.jsx("span",{children:"Live remote view"})})]})]})}const d=t.conversationsByTabKey.get(e.params.tabKey);if(!d)return s.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":e.params.tabKey||"",children:s.jsx("div",{className:"adhdev-dockview-tab-copy",children:s.jsx("div",{className:"adhdev-dockview-tab-primary",children:e.api.title||e.params.tabKey})})});const u=((y=e.api.group.activePanel)==null?void 0:y.id)===e.api.id,p=e.api.isGroupActive,m=ai(d,t.liveSessionInboxState,{isOpenConversation:u}),h=m.isReconnecting,f=m.isConnecting,x=m.isGenerating||c,b=m.isWaiting,g=m.unread,S=t.tabShortcuts[d.tabKey];return s.jsxs("div",{className:`adhdev-dockview-tab${u?" is-active":""}${p?" is-group-active":""}${h?" is-reconnecting":""}`,title:At(d),"data-tab-key":e.params.tabKey,onMouseDown:n,onTouchStart:n,onContextMenu:k=>{var v;k.preventDefault(),n(k),t.openTabContextMenu({x:k.clientX,y:k.clientY,tabKey:d.tabKey,sourceDocument:((v=k.target)==null?void 0:v.ownerDocument)??document})},children:[g&&s.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),s.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?s.jsx(Cs,{size:12,thickness:2,color:"success"}):b?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):h?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):f?s.jsx(Cs,{size:12,thickness:2}):d.connectionState==="connected"?s.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):s.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),s.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[s.jsx("div",{className:"adhdev-dockview-tab-primary",children:At(d)}),s.jsx("div",{className:"adhdev-dockview-tab-meta",children:h?s.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:Hn(d)}):f?s.jsx("span",{className:"adhdev-dockview-tab-connecting",children:Hn(d)}):s.jsx("span",{children:Hn(d)})})]}),S&&s.jsx("span",{className:"text-4xs opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:S,children:S})]})}const ZP=[];function Vo(e){return e.isActive}function $p(e){return e.isVisible}function eL(e){e.preventDefault()}function tL({params:e,api:t}){var x;const n=xi(),a=l.useRef(null),[o,r]=l.useState(()=>Vo(t)),[i,c]=l.useState(()=>$p(t)),d=n.conversationsByTabKey.get(e.tabKey),u=pi({sendDaemonCommand:n.sendDaemonCommand,activeConv:d,setActionLogs:n.setActionLogs,isStandalone:n.isStandalone});l.useEffect(()=>{r(Vo(t)),c($p(t));const b=[t.onDidActiveChange(g=>r(g.isActive)),t.onDidActiveGroupChange(g=>{if(!Vo(t)&&!g.isActive){r(!1);return}r(Vo(t))}),t.onDidVisibilityChange(g=>c(g.isVisible))];return()=>{for(const g of b)g.dispose()}},[t]);const p=l.useMemo(()=>d?n.ides.find(b=>b.id===d.routeId):void 0,[n.ides,d]),m=d==null?void 0:d.tabKey,h=l.useMemo(()=>m?n.actionLogs.filter(b=>b.routeId===m):ZP,[n.actionLogs,m]);if(!d)return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:s.jsx(kd,{conversationsCount:0,isSplitMode:!1,isStandalone:n.isStandalone,hasRegisteredMachines:n.hasRegisteredMachines,onOpenNewSession:n.onOpenNewSession,suppressGuide:n.hasDetachedConversationPanels,isLoading:!bi(n.ides,n.initialDataLoaded)})});const f=!gt(d)&&ja(d)==="terminal";return s.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:s.jsx(yd,{activeConv:d,clearToken:n.clearedTabs[d.tabKey]||0,isCliTerminal:f,ideEntry:p,terminalRef:a,commands:u,actionLogs:h,userName:n.userName,scrollToBottomRequestNonce:((x=n.scrollToBottomRequest)==null?void 0:x.tabKey)===d.tabKey?n.scrollToBottomRequest.nonce:void 0,isInputActive:o,isVisible:i})})}function sL({visibleConversations:e,clearedTabs:t,ides:n,actionLogs:a,sendDaemonCommand:o,setActionLogs:r,isStandalone:i,hasRegisteredMachines:c,initialDataLoaded:d,userName:u,toggleHiddenTab:p,actionShortcuts:m,registerActionHandlers:h,onActiveTabChange:f,onOpenNewSession:x,onRequestScrollToBottom:b,requestedActiveTabKey:g,requestedRemoteIdeId:S,onRequestedActiveTabConsumed:j,scrollToBottomRequest:y,liveSessionInboxState:k,layoutProfile:v}){var Se,Te,Je;const{theme:C}=nn(),{sendCommand:w}=wt(),N=l.useRef(null),T=l.useRef(null),A=l.useRef(null),P=l.useRef(!1),D=l.useRef(!1),L=l.useRef(!1),I=l.useRef(null),R=l.useRef([]),[_,M]=l.useState(null),[$,V]=l.useState(0),z=l.useRef(typeof window>"u"?{}:fI(v)),W=l.useMemo(()=>new Map(e.map(K=>[K.tabKey,K])),[e]),F=l.useMemo(()=>{const K=N.current;return K?K.groups.some(se=>{try{const be=se.model.location.type;return be!=="floating"&&be!=="popout"?!1:se.panels.some(we=>W.has(we.id))}catch{return!1}}):!1},[W,$,e]),B=l.useCallback(()=>{var K;(K=N.current)==null||K.focus()},[]),E=l.useCallback((K,se)=>{b==null||b(K,se)},[b]),H=l.useCallback(K=>{const se=document,be=K.document;for(const Fe of se.querySelectorAll('link[rel="stylesheet"]')){const tt=be.createElement("link");tt.rel="stylesheet",tt.href=Fe.href,Fe.crossOrigin&&(tt.crossOrigin=Fe.crossOrigin),be.head.appendChild(tt)}for(const Fe of se.querySelectorAll("style")){const tt=be.createElement("style");tt.textContent=Fe.textContent,be.head.appendChild(tt)}const we=[];for(const Fe of se.styleSheets)try{for(const tt of Fe.cssRules)tt instanceof CSSStyleRule&&(tt.selectorText===":root"||tt.selectorText==="html")&&we.push(tt.cssText)}catch{}if(we.length>0){const Fe=be.createElement("style");Fe.textContent=we.join(`
|
|
53
53
|
`),be.head.appendChild(Fe)}const Ne=se.documentElement.getAttribute("data-theme");Ne&&be.documentElement.setAttribute("data-theme",Ne),be.documentElement.style.colorScheme=Ne==="light"?"light":"dark",be.body.className=se.body.className;const Le=se.documentElement.getAttribute("style");Le&&be.documentElement.setAttribute("style",Le);const $e=be.getElementById("dv-popout-window");$e instanceof HTMLElement&&($e.classList.add("adhdev-dockview"),il($e,C))},[C]),J=l.useCallback(()=>{var se;const K=N.current;if(K)for(const be of K.groups)try{const we=(se=be.element)==null?void 0:se.ownerDocument;if(!we||we===document)continue;const Ne=we.getElementById("dv-popout-window");Ne instanceof HTMLElement&&(Ne.classList.add("adhdev-dockview"),il(Ne,C));const Le=document.documentElement.getAttribute("data-theme");Le&&we.documentElement.setAttribute("data-theme",Le),we.documentElement.style.colorScheme=Le==="light"?"light":"dark",we.body.className=document.body.className;const $e=document.documentElement.getAttribute("style");$e?we.documentElement.setAttribute("style",$e):we.documentElement.removeAttribute("style")}catch{}},[C]),q=l.useCallback(K=>{const se=N.current;if(!se)return;const be=se.getPanel(K);be&&se.addPopoutGroup(be,{popoutUrl:"/popout.html",onDidOpen:({window:we})=>{H(we),oe();const Ne=W.get(K);we.document.title=Ne?`${At(Ne)} — ADHDev`:"ADHDev — Popout"}})},[W,H]),ie=l.useCallback(K=>{const se=N.current,be=se==null?void 0:se.getPanel(K);if(!se||!be)return;const we=se.groups.filter(Ne=>{var Le;try{return((Le=Ne.element)==null?void 0:Le.ownerDocument)===document}catch{return!0}});we.length>0?be.api.moveTo({group:we[0],position:"center"}):be.api.moveTo({position:"center"}),be.api.setActive()},[]),xe=l.useCallback(K=>{var we;const se=N.current;if(!se)return!1;const be=se.getPanel(K);if(!be)return!1;try{return((we=be.group.element)==null?void 0:we.ownerDocument)!==document}catch{return!1}},[]),Y=l.useCallback(K=>{xe(K)&&ie(K),p(K)},[xe,ie,p]),ne=l.useCallback(K=>{const se=N.current,be=se==null?void 0:se.getPanel(K);!se||!be||se.addFloatingGroup(be,{width:600,height:500})},[]),me=l.useCallback(K=>{var be;const se=(be=N.current)==null?void 0:be.getPanel(K);if(!se)return!1;try{return se.group.model.location.type==="floating"}catch{return!1}},[]),ce=l.useCallback(()=>{var se,be;const K=(be=(se=N.current)==null?void 0:se.activePanel)==null?void 0:be.id;return!K||Ps(K)?null:W.has(K)?K:null},[W]),ae=l.useCallback(K=>{const se=N.current,be=se==null?void 0:se.getPanel(K);if(!se||!be)return;const we=se.groups.filter(Ne=>{try{return Ne.model.location.type==="grid"}catch{return!0}});we.length>0?be.api.moveTo({group:we[0],position:"center"}):be.api.moveTo({position:"center"}),be.api.setActive()},[]),he=l.useCallback(()=>{var Le;const K=N.current;if(!K)return;const be=K.groups.filter($e=>{var Fe;try{return((Fe=$e.element)==null?void 0:Fe.ownerDocument)===document&&$e.model.location.type==="grid"}catch{return!1}})[0]||null,we=[...K.panels];for(const $e of we){const Fe=(Le=$e.group.element)==null?void 0:Le.ownerDocument,tt=$e.group.model.location.type;Fe===document&&tt==="grid"||(be&&be.id!==$e.group.id?$e.api.moveTo({group:be,position:"center"}):$e.api.moveTo({position:"center"}))}const Ne=K.activePanel;Ne&&(Ne.group.model.openPanel(Ne),Ne.api.setActive()),rl(document)},[]),oe=l.useCallback(()=>{var se,be;const K=N.current;if(K)for(const we of K.groups){const Ne=(se=we.element)==null?void 0:se.ownerDocument;if(!Ne||Ne===document)continue;const Le=Ne.getElementById("dv-popout-window");if(!(Le instanceof HTMLElement))continue;let $e=null,Fe=Ne.title||"ADHDev",tt="Popout workspace";const nt=we.activePanel;if(nt)if($e=nt.id,Ps(nt.id)){const Qe=((be=nt.params)==null?void 0:be.routeId)||nt.id.slice(7),ht=_s([...W.values()],Qe);Fe=Mf(ht),tt=ht!=null&&ht.machineName?`Remote view · ${ht.machineName}`:"Remote view"}else{const Qe=W.get(nt.id);Fe=Qe?At(Qe):nt.title||nt.id,tt=Qe?Hn(Qe):"Dockview panel"}Ne.title=`${Fe} — ADHDev`;const rt=Array.from(Ne.querySelectorAll("#adhdev-popout-header"));for(const Qe of rt)Qe.remove();const Ue=Ne.createElement("div");Ue.id="adhdev-popout-header",Ne.body.appendChild(Ue),Ue.setAttribute("style",["position:absolute","top:0","left:0","right:0","height:52px","display:flex","align-items:center","justify-content:space-between","gap:12px","padding:0 14px","box-sizing:border-box","background:var(--surface-secondary)","border-bottom:1px solid var(--border-subtle)","z-index:5","backdrop-filter:blur(14px)"].join(";")),Ue.innerHTML=`
|
|
54
54
|
<div style="min-width:0;display:flex;flex-direction:column;gap:2px;">
|
|
55
55
|
<div style="font-size:10px;line-height:1;color:var(--text-muted);text-transform:uppercase;letter-spacing:0.08em;">ADHDev</div>
|