@adhdev/daemon-standalone 0.9.82-rc.543 → 0.9.82-rc.545

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-standalone",
3
- "version": "0.9.82-rc.543",
3
+ "version": "0.9.82-rc.545",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  "license": "AGPL-3.0-or-later",
38
38
  "dependencies": {
39
39
  "@adhdev/ghostty-vt-node": "*",
40
- "@adhdev/session-host-core": "0.9.82-rc.543",
40
+ "@adhdev/session-host-core": "0.9.82-rc.545",
41
41
  "@xterm/addon-serialize": "^0.14.0",
42
42
  "@xterm/xterm": "^6.0.0",
43
43
  "chalk": "^5.3.0",
@@ -50,7 +50,7 @@ ${JSON.stringify(t,null,2)}
50
50
  `),ye=((fe=ie[0])==null?void 0:fe.slice(0,80))||"(empty)";return s.jsxs("div",{className:"border border-border-default rounded overflow-hidden bg-surface-secondary",children:[s.jsxs("button",{type:"button",className:"w-full flex items-center gap-2 px-2.5 py-1.5 hover:bg-bg-glass-hover transition-colors text-left",onClick:()=>be(U),children:[s.jsx("span",{className:"text-[10px] text-text-muted w-3",children:Z?"▾":"▸"}),s.jsx("span",{className:"font-mono text-accent-primary w-20 shrink-0 text-[11px]",children:U}),!Z&&s.jsx("span",{className:"text-text-secondary truncate font-mono text-[11px]",children:ye}),s.jsxs("span",{className:"ml-auto text-text-muted text-[10px] shrink-0",children:[ie.length,"L"]})]}),Z&&s.jsx("pre",{className:"px-3 pb-2.5 pt-1 font-mono text-[11px] text-text-secondary whitespace-pre-wrap break-all bg-bg-secondary max-h-40 overflow-y-auto border-t border-border-default",children:W||"(empty)"})]},U)})})]}),s.jsx(Nn,{}),V.stateHistory&&V.stateHistory.length>0&&s.jsxs("div",{children:[s.jsxs(kn,{children:["State History (",V.stateHistory.length,")"]}),s.jsx("div",{className:"space-y-px",children:[...V.stateHistory].reverse().slice(0,20).map((U,W)=>s.jsxs("div",{className:"rounded px-2 py-1 hover:bg-bg-glass-hover transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:`font-mono text-[11px] font-semibold px-1.5 py-0.5 rounded shrink-0 ${Za(U.stateId)}`,children:U.stateId}),s.jsx("span",{className:"text-text-secondary text-[11px] shrink-0 tabular-nums",children:Pr(U.at)}),U.durationMs>0&&s.jsxs("span",{className:"text-text-muted text-[11px]",children:["held ",s.jsx("span",{className:"text-text-secondary",children:cc(U.durationMs)})]}),U.reason&&s.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-mono shrink-0 ${Fy[String(U.reason)]??"text-text-secondary bg-bg-glass border border-border-default"}`,children:String(U.reason)}),U.debounceKind&&String(U.debounceKind)!=="none"&&s.jsxs("span",{className:"text-text-muted text-[10px] font-mono",children:["debounce:",String(U.debounceKind)]}),U.matchedStateId&&String(U.matchedStateId)!==U.stateId&&s.jsxs("span",{className:"text-text-muted text-[10px] font-mono",children:["eval→",s.jsx("span",{className:"text-text-secondary",children:String(U.matchedStateId)})]})]}),U.matchedRules&&U.matchedRules.length>0&&s.jsxs("div",{className:"flex items-start gap-1 flex-wrap mt-0.5 ml-1 pl-1 border-l border-border-default",children:[U.matchedRules.slice(0,3).map((Z,ie)=>s.jsx("span",{className:"font-mono text-[10px] text-accent-primary bg-accent-primary/20 border border-accent px-1.5 py-0.5 rounded break-all",children:typeof Z=="string"?Z:JSON.stringify(Z)},ie)),U.matchedRules.length>3&&s.jsxs("span",{className:"text-[10px] text-text-muted",children:["+",U.matchedRules.length-3," more"]})]})]},W))})]}),s.jsx(Nn,{}),(()=>{const U=V.messages??V.committedMessages??[];if(U.length===0)return null;const W=U.filter(ye=>ye.role==="user").length,Z=U.filter(ye=>ye.role==="assistant").length,ie=[...U].reverse().find(ye=>ye.role==="assistant");return s.jsxs("div",{children:[s.jsxs(kn,{children:["Transcript (",U.length," — ",W,"u / ",Z,"a)"]}),ie&&s.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-md p-2.5 text-[11px]",children:[s.jsxs("div",{className:"text-text-muted mb-1 text-[10px]",children:["Last assistant ",ie.receivedAt?Pr(ie.receivedAt):""]}),s.jsxs("div",{className:"text-text-secondary font-mono whitespace-pre-wrap line-clamp-4 break-all",children:[ie.content.slice(0,400),ie.content.length>400?"…":""]})]})]})})(),V.specPath&&s.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate border-t border-border-default pt-2 mt-1",title:V.specPath,children:V.specPath}),s.jsxs("div",{children:[s.jsxs("button",{type:"button",className:"text-[11px] text-text-secondary hover:text-text-primary transition-colors flex items-center gap-1.5",onClick:()=>u(U=>!U),children:[s.jsx("span",{className:"text-text-muted",children:p?"▾":"▸"}),s.jsxs("span",{children:["Raw screen (",V.screen?V.screen.split(`
51
51
  `).length:0," lines)"]})]}),p&&s.jsx("pre",{className:"mt-1.5 px-3 py-2 font-mono text-[11px] text-text-secondary whitespace-pre bg-bg-secondary rounded-md border border-border-default max-h-64 overflow-auto",children:V.screen||"(empty)"})]})]})]})]})})}function Ky({activeConv:e,clearToken:t=0,terminalRef:r,handleSendChat:n,isSendingChat:a=!1,sendFeedbackMessage:o=null,isVisible:i=!0,isInputActive:c=!0}){var Ue;hs();const{sendPtyInput:d}=xt(),[p,u]=l.useState(!1),m=l.useRef(!1);m.current=p;const[h,y]=l.useState("Runtime terminal unavailable"),[x,f]=l.useState(!1),[j,k]=l.useState(null),[b,w]=l.useState(!1),[I,v]=l.useState(!1),[g,S]=l.useState(1),[N,C]=l.useState(!1),[R,T]=l.useState(!1),[_,P]=l.useState(!1),[B,z]=l.useState(!1),[A,O]=l.useState(!1),[$,L]=l.useState({width:0,height:0}),[E,M]=l.useState({width:0,height:0}),[H,Y]=l.useState({scrollTop:0,scrollHeight:0,clientHeight:0,atTop:!1,canScroll:!1}),[G,J]=l.useState(null),te=l.useRef(null),oe=l.useRef(null),q=l.useRef(!1),F=l.useRef(!1),V=l.useRef(i),pe=l.useRef(0),be=l.useRef(!1),ue=l.useRef(""),Ne=l.useRef(null),se=l.useRef(!1),ve=l.useRef(!1),me=l.useRef(null),U=l.useRef(null),W=l.useRef(null),Z=32*1024,ie=()=>{var ne,de,ge,$e;return((de=(ne=te.current)==null?void 0:ne.ownerDocument)==null?void 0:de.defaultView)||(($e=(ge=oe.current)==null?void 0:ge.ownerDocument)==null?void 0:$e.defaultView)||window},ye=ne=>{const de=ie();return{ownerWindow:de,frameId:de.requestAnimationFrame(ne)}},fe=()=>{const ne=me.current;if(ne){try{ne.ownerWindow.cancelAnimationFrame(ne.frameId)}catch{}me.current=null}},D=()=>{const ne=U.current;if(ne){try{ne.ownerWindow.clearTimeout(ne.timeoutId)}catch{}U.current=null}},he=()=>{const ne=W.current;if(ne){try{ne.ownerWindow.clearTimeout(ne.timeoutId)}catch{}W.current=null}},Se=()=>{i&&me.current===null&&(me.current=ye(()=>{Lt()}))},ae=e.tabKey,Q=e.sessionId||"",we=e.daemonId||((Ue=e.routeId)==null?void 0:Ue.split(":")[0])||e.routeId||"",ke=Ri(e),Le=p?o||ke:h,We=ky,ce=Ny,Ee=.05,Be=()=>{const ne=E.width,de=E.height;if(!Number.isFinite($.width)||$.width<=0||!Number.isFinite($.height)||$.height<=0||!Number.isFinite(ne)||ne<=0||!Number.isFinite(de)||de<=0)return 1;const ge=$.width/ne,$e=$.height/de;return Number(Math.min(ce,Math.max(We,Math.min(ge,$e))).toFixed(2))},Je=Be(),qe=q.current&&g>Je,je=Number.isFinite(E.width)&&E.width>0?Math.max($.width,Math.round(E.width*g)):$.width,at=Number.isFinite(E.height)&&E.height>0?Math.max($.height,Math.round(E.height*g)):$.height,Ie=()=>{ye(()=>{const ne=oe.current;ne&&(ne.scrollLeft=0,ne.scrollTop=ne.scrollHeight-ne.clientHeight)})},ot=()=>{var ne,de;pe.current=0,be.current=!1,ue.current="",Ne.current=null,se.current=!1,ve.current=!1,q.current||(F.current=!1,S(1)),me.current!==null&&fe(),u(!1),y("Runtime terminal unavailable"),he(),D(),k(null),J(null),C(!1),f(!1),w(!1),v(!1),(de=(ne=r.current)==null?void 0:ne.reset)==null||de.call(ne)},nt=()=>{var ne,de;pe.current=0,be.current=!1,ue.current="",Ne.current=null,se.current=!1,ve.current=!1,me.current!==null&&fe(),u(!0),y(""),he(),D(),k(null),J(null),C(!1),f(!1),w(!1),v(!1),(de=(ne=r.current)==null?void 0:ne.reset)==null||de.call(ne)},Qe=()=>{ve.current&&(ve.current=!1,ye(()=>{var ne,de;(de=(ne=r.current)==null?void 0:ne.scrollToTop)==null||de.call(ne)}))},Lt=()=>{if(me.current=null,!i)return;const ne=ue.current;if(!ne)return;const de=ne.slice(0,Z);ue.current=ne.slice(de.length);const ge=r.current;if(!ge){ue.current=de+ue.current,Se();return}ge.write(de,()=>{if(ue.current.length>0){Se();return}Qe()})},X=ne=>{ne&&(ue.current+=ne,Se())},ee=(ne,de=0,ge,$e,Fe={})=>{var Ze,rt,Ge,Nt;const Ye=!!Fe.force;!Ye&&de>0&&pe.current>=de||!Ye&&de===0&&be.current||(pe.current=de,de>0&&w(!0),u(!0),y(""),typeof ge=="number"&&typeof $e=="number"&&ge>0&&$e>0&&((rt=(Ze=r.current)==null?void 0:Ze.resize)==null||rt.call(Ze,ge,$e)),ue.current="",(Nt=(Ge=r.current)==null?void 0:Ge.reset)==null||Nt.call(Ge),ne?X(ne):Qe())};l.useEffect(()=>{ot()},[Q]),l.useEffect(()=>{var de;if(!Q)return;const ne=((de=bt.onRuntimeEvent)==null?void 0:de.call(bt,Q,ge=>{if(!(!ge||ge.sessionId!==Q)){if(ge.type==="runtime_snapshot"){if(!i){Ne.current={text:ge.text||"",seq:ge.seq||0,cols:ge.cols,rows:ge.rows,force:!!ge.force};return}ee(ge.text||"",ge.seq||0,ge.cols,ge.rows,{force:!!ge.force});return}if(ge.type==="session_output"){be.current=!0,typeof ge.seq=="number"&&(pe.current=Math.max(pe.current,ge.seq),ge.seq>0&&w(!0)),m.current||u(!0),m.current||y(""),typeof ge.data=="string"&&X(ge.data);return}if(ge.type==="session_cleared"){if(!i){se.current=!0,ue.current="",Ne.current=null;return}nt();return}if(ge.type==="session_io_error"){const $e=typeof ge.error=="string"&&ge.error?ge.error:typeof ge.reason=="string"&&ge.reason?ge.reason:"unknown error";u(!1),y(`Runtime input failed: ${$e}`);return}}},we))||(()=>{});return()=>{ne()}},[we,Q,r,i]);const re=async(ne={})=>{var de;if(!we||!Q)return{success:!1,error:"daemonId and sessionId are required"};ne.preserveStatus||y(ne.loadingMessage||"Loading runtime terminal...");try{const ge=await((de=bt.requestRuntimeSnapshot)==null?void 0:de.call(bt,we,Q,{sinceSeq:ne.sinceSeq,force:ne.force}));return ge&&ge.success===!1?(ne.preserveStatus||(u(!1),y(`Runtime terminal unavailable: ${ge.error}`)),ge):ge||{success:!0}}catch(ge){const $e=(ge==null?void 0:ge.message)||String(ge);return ne.preserveStatus||(u(!1),y(`Runtime terminal unavailable: ${$e}`)),{success:!1,error:$e}}},le=async ne=>{var Ye,Ze;const de=((Ye=te.current)==null?void 0:Ye.ownerDocument)||document,ge=de.defaultView||window,$e=(Ze=ge.navigator)==null?void 0:Ze.clipboard;if($e!=null&&$e.writeText&&ge.isSecureContext)try{return await $e.writeText(ne),!0}catch{}let Fe=null;try{return Fe=de.createElement("textarea"),Fe.value=ne,Fe.setAttribute("readonly","true"),Fe.style.position="fixed",Fe.style.left="-9999px",Fe.style.top="0",de.body.appendChild(Fe),Fe.focus(),Fe.select(),de.execCommand("copy")}catch{return!1}finally{Fe==null||Fe.remove()}},xe=ne=>{D(),J(ne);const de=ie();U.current={ownerWindow:de,timeoutId:de.setTimeout(()=>{U.current=null,J(ge=>ge===ne?null:ge)},2200)}},Ae=ne=>{he(),k(ne);const de=ie();W.current={ownerWindow:de,timeoutId:de.setTimeout(()=>{W.current=null,k(ge=>ge===ne?null:ge)},2200)}},De=async()=>{var Fe,Ye,Ze,rt;const ne=((Ye=(Fe=r.current)==null?void 0:Fe.getSelection)==null?void 0:Ye.call(Fe))||"",de=((rt=(Ze=r.current)==null?void 0:Ze.getVisibleText)==null?void 0:rt.call(Ze))||"",ge=ne.trimEnd()||de.trimEnd();if(!ge){xe("Nothing to copy");return}if(!await le(ge)){xe("Copy failed");return}xe(ne.trimEnd()?"Copied selection":"Copied visible terminal")},Ce=ne=>{if(!p||!i)return;((d==null?void 0:d(we,Q,ne))??!1)||xe("Terminal input failed")},Re=ne=>{Ce(Cy({ctrl:R,alt:_,shift:B},ne)),T(!1),P(!1),z(!1)},He=async()=>{if(x)return;f(!0),k("Loading older terminal output..."),ve.current=!0;const ne=await re({sinceSeq:0,force:!0,loadingMessage:"Loading older terminal output...",preserveStatus:p});if(f(!1),(ne==null?void 0:ne.success)===!1){ve.current=!1,k(`Older terminal output unavailable: ${ne.error}`);return}v(!0),Ae("Older terminal output loaded"),ye(()=>{var de;(de=r.current)==null||de.bumpResize()})};l.useEffect(()=>{var de,ge;if(!Q)return;we&&((de=bt.getState)==null?void 0:de.call(bt,we))==="connected"&&re();const ne=(ge=bt.onStateChange)==null?void 0:ge.call(bt,($e,Fe)=>{$e!==we||Fe!=="connected"||re()});return()=>{ne==null||ne()}},[we,Q,r]),l.useEffect(()=>{t&&ot()},[t,ae,r]),l.useEffect(()=>{var $e,Fe;const ne=te.current,de=(Fe=($e=ne==null?void 0:ne.ownerDocument)==null?void 0:$e.defaultView)==null?void 0:Fe.ResizeObserver;if(!ne||!de)return;const ge=new de(Ye=>{const Ze=Ye[0];if(!Ze)return;const{width:rt,height:Ge}=Ze.contentRect;L(Nt=>{const Jt=Math.round(rt),Ht=Math.round(Ge);return Nt.width===Jt&&Nt.height===Ht?Nt:{width:Jt,height:Ht}})});return ge.observe(ne),()=>ge.disconnect()},[]),l.useEffect(()=>{if(q.current)return;const ne=Be();!Number.isFinite(ne)||ne<=0||S(de=>F.current?ne<de-Ee?ne:de:(F.current=!0,ne))},[E.height,E.width,$.height,$.width]),l.useEffect(()=>{qe&&Ie()},[qe,at,je]),l.useEffect(()=>{var ge;const ne=V.current;if(V.current=i,!i)return;ne||v(!1),se.current&&(se.current=!1,nt());const de=Ne.current;de&&(Ne.current=null,ee(de.text,de.seq,de.cols,de.rows,{force:!!de.force})),we&&Q&&((ge=bt.getState)==null?void 0:ge.call(bt,we))==="connected"&&re(),ue.current&&me.current===null&&Se(),ye(()=>{var $e;($e=r.current)==null||$e.bumpResize()})},[we,i,Q]),l.useEffect(()=>()=>{me.current!==null&&fe(),D(),he()},[]),l.useEffect(()=>{const ne=$e=>{var Ye;const Fe=$e.detail;Fe!=null&&Fe.sessionId&&Fe.sessionId!==Q||p&&((Ye=r.current)==null||Ye.bumpResize())},de=ie(),ge=de===window?[window]:[window,de];for(const $e of ge)$e.addEventListener("adhdev:fit-cli-terminal",ne);return()=>{for(const $e of ge)$e.removeEventListener("adhdev:fit-cli-terminal",ne)}},[p,Q,r]);const Oe=p&&b&&!I&&(H.atTop||!H.canScroll)||x||!!j;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{ref:te,className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[Oe&&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-[11px] font-medium text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{He()},disabled:!Q||x,title:"Replay raw session scrollback so the terminal viewport can scroll farther up",children:x?"Loading older...":"Load older terminal output"}),j&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:j})]}),s.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[G&&s.jsx("span",{className:"rounded-full border border-white/10 bg-black/35 px-2 py-1 text-[10px] text-white/70 backdrop-blur-sm",children:G}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55",onClick:()=>O(ne=>!ne),title:"Spec debug — inspect current state, sections, and transition history",children:"Debug"}),s.jsx("button",{type:"button",className:"h-8 rounded-full border border-white/10 bg-black/35 px-3 text-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>{De()},disabled:!p,title:"Copy selected terminal text, or the visible terminal viewport if nothing is selected",children:"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-[11px] font-semibold text-white/85 backdrop-blur-sm transition-colors hover:bg-black/55 disabled:cursor-not-allowed disabled:opacity-60",onClick:()=>C(ne=>!ne),disabled:!p,"aria-label":"Open terminal control keys","aria-expanded":N,"aria-controls":"terminal-control-keys-popover",title:"Open mobile-friendly terminal control keys",children:"Keys"}),N&&s.jsxs("div",{id:"terminal-control-keys-popover",role:"dialog","aria-label":"Terminal control keys",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-[10px] 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-[11px] text-white/55 transition-colors hover:bg-white/10 hover:text-white/85",onClick:()=>C(!1),"aria-label":"Close terminal control keys",children:"×"})]}),s.jsx("div",{className:"mb-2 grid grid-cols-3 gap-1.5",children:[["Ctrl",R,T],["Alt",_,P],["Shift",B,z]].map(([ne,de,ge])=>s.jsx("button",{type:"button","aria-pressed":de,className:`h-9 rounded-lg border text-[12px] 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:()=>ge($e=>!$e),children:ne},ne))}),s.jsx("div",{className:"grid grid-cols-6 gap-1",children:"abcdefghijklmnopqrstuvwxyz0123456789".split("").map(ne=>s.jsx("button",{type:"button",className:"h-8 rounded-md border border-white/10 bg-white/[0.06] text-[12px] font-semibold uppercase hover:bg-white/[0.12]",onClick:()=>Re(ne),children:ne},ne))}),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-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Escape"),children:"Esc"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Tab"),children:"Tab"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Ce(""),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-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("Space"),children:"Space"}),s.jsx("button",{type:"button",className:"h-9 rounded-lg border border-white/10 bg-white/[0.06] text-[12px] font-semibold hover:bg-white/[0.12]",onClick:()=>Re("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:()=>{q.current=!0,S(ne=>{const de=Math.max(Je,Number((ne-.1).toFixed(2)));return de>Je&&Ie(),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:()=>{q.current=!0,S(ne=>{const de=Math.min(ce,Number((ne+.1).toFixed(2)));return de>Je&&Ie(),de})},title:"Increase terminal viewport",children:"+"})]}),s.jsx("div",{ref:oe,className:qe?"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:je>0?`${je}px`:"100%",height:at>0?`${at}px`:"100%",minWidth:"100%",minHeight:"100%",position:"relative"},children:s.jsx("div",{style:{width:E.width>0?`${E.width}px`:"100%",height:E.height>0?`${E.height}px`:"100%",position:"absolute",left:0,bottom:0,zoom:g},children:s.jsx(Jd,{ref:r,readOnly:!p||!i,sizingMode:"measured",onViewportMetrics:M,onScrollMetrics:Y,onInput:ne=>{!p||(d==null||d(we,Q,ne))}})})})}),!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-[11px] text-red-300 pointer-events-none",children:h})]}),s.jsx(hu,{contextKey:e.tabKey,panelLabel:ft(e),isSending:a,isBusy:!!ke,statusMessage:Le,inlineStatusMessage:Le,onSend:async ne=>ke?!1:n(ne),isActive:c&&i,showControlsToggle:!1,animateVisibility:!1}),A&&s.jsx(Wy,{activeConv:e,onClose:()=>O(!1)})]})}const Uy=5e3,zy=12e3;function Gy(e){return e==="disconnected"||e==="reconnecting"}function Vy({wsStatus:e,showReconnected:t,loginUrl:r,onReconnect:n,reconnectDelayMs:a=Uy,reconnectActionDelayMs:o=zy}){const i=Gy(e),[c,d]=l.useState(()=>!i||a<=0),[p,u]=l.useState(()=>!i||o<=0),m=l.useRef(!1);l.useEffect(()=>{if(!i){d(!1);return}if(m.current=!1,a<=0){m.current=!0,d(!0);return}d(!1);const v=setTimeout(()=>{m.current=!0,d(!0)},a);return()=>clearTimeout(v)},[a,i]),l.useEffect(()=>{if(!i){u(!1);return}if(o<=0){u(!0);return}u(!1);const v=setTimeout(()=>{u(!0)},o);return()=>clearTimeout(v)},[o,i]);const h=i?c:e==="offline"||e==="auth_failed",y=!!(n&&e!=="auth_failed"&&(!i||p)),x=l.useMemo(()=>!t||e!=="connected"?!1:a<=0||m.current,[a,t,e]),f=e==="auth_failed"?"red":e==="offline"?"orange":"accent",j={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))"},k={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)"},b={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"},w="fixed left-1/2 top-4 z-[var(--z-toast)] flex items-center justify-center pointer-events-none",I={top:"calc(env(safe-area-inset-top, 0px) + 16px)",transform:"translateX(-50%)"};return s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{className:w,style:I,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-[13px] 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:j[f],border:k[f],color:b[f]},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"&&"Network offline",e==="disconnected"&&"Reconnecting",e==="reconnecting"&&"Reconnecting",e==="auth_failed"&&(r?s.jsxs(s.Fragment,{children:["Session expired."," ",s.jsx("a",{href:r,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — refresh the page or try again shortly.")]}),y&&s.jsx("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-[12px] font-semibold hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed",onClick:()=>n==null?void 0:n(),disabled:e==="offline",children:"Reconnect now"})]})}),x&&s.jsx("div",{className:w,style:I,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"}),"Connected"]})})]})}function Qu({mode:e,onChange:t,compact:r=!1}){const n=r?14:15;return s.jsx("button",{type:"button",onClick:()=>t(e==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:e==="chat"?"Switch to Terminal view":"Switch to Chat view",children:e==="chat"?s.jsx(vi,{size:n}):s.jsx(Xs,{size:n})})}const us="New session",Zu="A connected machine is ready. Start a new session with any installed provider — CLI, ACP, or IDE.";function qy(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 Yy(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 Jy(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 aa({git:e,className:t="",compact:r=!1}){const n=qy(e),a=Yy(e);if(!n||!a)return null;const o=[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 ${Jy(a)} ${t}`.trim(),title:o.join(" · ")||n,"data-git-tone":a,children:[s.jsx("span",{"aria-hidden":"true",children:"⑂"}),s.jsx("span",{className:"truncate",children:n})]})}function Xy({wsStatus:e,isConnected:t,daemonCount:r,p2pStates:n={}}){if(e!=="connected")return{tone:"disconnected",title:"Disconnected",subtitle:null};const a=Object.values(n),o=a.filter(c=>c==="connected").length,i=a.filter(c=>c==="connecting"||c==="new"||c==="checking").length;return r>0&&i>0&&o===0?{tone:"limited",title:"Connected to dashboard",subtitle:"Connecting to machine..."}:t?{tone:"connected",title:"Connected",subtitle:null}:{tone:"limited",title:"Connected to dashboard",subtitle:null}}function dc({value:e}){return e?s.jsx("span",{className:"dashboard-header-shortcut-pill",children:e}):null}function uc({notification:e,shortcutIndex:t,onOpen:r,onMarkRead:n,onMarkUnread:a,onDelete:o}){const i=wa(e.updatedAt),c=!e.readAt;return s.jsxs("div",{className:`dashboard-header-inbox-item ${c?"is-attention":""}`.trim(),children:[s.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:r,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"?"Action needed":"Task complete",i].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:[c?s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),n()},children:"Mark read"}):s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),a()},children:"Mark unread"}),s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:d=>{d.stopPropagation(),o()},children:"Delete"})]})]})}function Qy({activeConv:e,wsStatus:t,isConnected:r,conversations:n,onOpenHistory:a,onOpenRemote:o,onStopCli:i,activeCliViewMode:c,onSetCliViewMode:d,onHideConversation:p,hiddenConversations:u=[],onShowConversation:m,onShowAllHidden:h,onResetPanelsToMain:y,inboxOpen:x,onInboxOpenChange:f,hiddenOpen:j,onHiddenOpenChange:k,onOpenNewSession:b,onOpenDashboardGuide:w,guideNudgeVisible:I=!1,actionShortcuts:v,notifications:g,notificationUnreadCount:S,onOpenNotification:N,onMarkNotificationRead:C,onMarkNotificationUnread:R,onDeleteNotification:T,onOpenGitDialog:_,onOpenMeshGraph:P}){var Ne;const{ides:B,p2pStates:z={}}=hs(),A=!!e&&lt(e)&&!it(e),O=!!e&&it(e),$=!!(e!=null&&e.daemonId)&&!!((Ne=e==null?void 0:e.coordinator)!=null&&Ne.meshId),L=c||(e?ju(e)?"terminal":"chat":null),[E,M]=l.useState(!1),H=l.useRef(null),Y=l.useRef(null),G=B.filter(se=>se.type==="adhdev-daemon"),J=Xy({wsStatus:t,isConnected:r,daemonCount:G.length,p2pStates:z}),te=J.subtitle,oe=J.tone==="connected"?"#22c55e":J.tone==="limited"?"#eab308":"#ef4444",q=J.tone==="connected"?"0 0 4px #22c55e80":J.tone==="limited"?"0 0 4px #eab30880":"0 0 4px #ef444480",F=l.useMemo(()=>g.filter(se=>!se.readAt),[g]),V=l.useMemo(()=>g.filter(se=>!!se.readAt),[g]),pe=l.useMemo(()=>F.slice(0,9),[F]),be=S;l.useEffect(()=>{if(!x)return;const se=ve=>{var me;(me=H.current)!=null&&me.contains(ve.target)||f(!1)};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},[x,f]),l.useEffect(()=>{if(!j)return;const se=ve=>{var me;(me=Y.current)!=null&&me.contains(ve.target)||k(!1)};return document.addEventListener("mousedown",se),()=>document.removeEventListener("mousedown",se)},[j,k]),l.useEffect(()=>{if(!j&&!x)return;const se=ve=>{if(!ve.altKey)return;const me=ve.code.match(/^Digit([1-9])$/);if(!me)return;const U=Number(me[1])-1,W=j?u[U]:void 0,Z=x?pe[U]:void 0;if(!(!W&&!Z)){if(ve.preventDefault(),ve.stopPropagation(),W){m==null||m(W),k(!1);return}Z&&(N(Z),f(!1))}};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[u,j,x,pe,k,f,N,m]);const ue=se=>{if(!se)return;const ve=n.find(me=>me.tabKey===se);ve&&(p==null||p(ve))};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(Xs,{size:18}),s.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),s.jsx("span",{className:"header-title-mobile",children:e?ft(e):"Dashboard"}),s.jsx("span",{title:J.title,"aria-label":J.title,className:"header-title-status-dot",style:{background:oe,boxShadow:q}}),s.jsx("span",{className:"header-count-mobile text-[10px] 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:oe,boxShadow:q}})})]}),s.jsxs("div",{className:"header-subtitle flex items-center",children:[te&&s.jsxs("span",{className:"header-subtitle-status mr-2",children:["· ",te]}),b&&s.jsx("button",{type:"button",onClick:b,className:"btn btn-secondary btn-sm ml-2",title:`${us}${v!=null&&v.openNewSession?` (${v.openNewSession})`:""}`,"aria-label":us,children:s.jsx(wi,{size:14})})]})]})})}),s.jsxs("div",{className:"flex gap-2 items-center",children:[w&&s.jsxs("button",{type:"button",onClick:w,className:"btn btn-secondary btn-sm hidden md:inline-flex items-center gap-1.5 dashboard-header-guide-button",title:"Dashboard guide","aria-label":"Open dashboard guide",children:[s.jsx("span",{className:"font-semibold leading-none",children:"?"}),I&&s.jsx("span",{children:"Guide"})]}),e&&(A||O||!it(e))&&s.jsxs("div",{className:"dashboard-header-actions-group",children:[s.jsx("span",{className:"dashboard-header-action-target",title:fr(e)||ft(e),children:ft(e)}),_&&e.git&&e.daemonId&&e.workspacePath?s.jsx("button",{type:"button",className:"appearance-none bg-transparent border-0 p-0 cursor-pointer",title:"Open git status",onClick:()=>_(e.daemonId,e.workspacePath),children:s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"})}):s.jsx(aa,{git:e.git,compact:!0,className:"max-w-[8rem] shrink-0"}),$&&P&&s.jsxs("button",{type:"button",onClick:()=>P(e),className:"btn btn-secondary btn-sm dashboard-header-mesh-button",title:"Open live repo mesh graph",children:[s.jsx(ss,{size:14}),s.jsx("span",{className:"hidden lg:inline",children:"Mesh graph"})]}),(A||O)&&i&&s.jsxs(s.Fragment,{children:[A&&d&&L&&s.jsx(Qu,{mode:L,onChange:d,compact:!0}),s.jsx("button",{onClick:()=>i(e),className:"btn btn-secondary btn-sm",title:O?"Stop ACP session":"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})})]}),!it(e)&&s.jsx("button",{onClick:()=>a(e),className:"btn btn-secondary btn-sm",title:"Chat History",children:s.jsx(gi,{size:14})}),!A&&!it(e)&&s.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Remote Control",children:s.jsx(os,{size:14})})]}),s.jsxs("div",{className:"dashboard-header-inbox",ref:H,children:[s.jsxs("div",{className:`dashboard-header-hidden${E?" is-drop-target":""}`,ref:Y,onDragEnter:se=>{se.dataTransfer.types.includes("text/tab-key")&&(se.preventDefault(),M(!0))},onDragOver:se=>{se.dataTransfer.types.includes("text/tab-key")&&(se.preventDefault(),se.dataTransfer.dropEffect="move",M(!0))},onDragLeave:se=>{se.currentTarget.contains(se.relatedTarget)||M(!1)},onDrop:se=>{const ve=se.dataTransfer.getData("text/tab-key");se.preventDefault(),M(!1),ue(ve)},children:[s.jsxs("button",{type:"button",onClick:()=>k(!j),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:`Hidden tabs${v!=null&&v.toggleHiddenTabs?` (${v.toggleHiddenTabs})`:""}. Drag a tab here to hide it.`,children:[s.jsx(yi,{size:16}),u.length>0&&s.jsx("span",{className:"dashboard-header-hidden-badge",children:u.length})]}),j&&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:"Hidden tabs"}),s.jsx(dc,{value:v==null?void 0:v.toggleHiddenTabs})]}),s.jsxs("div",{className:"dashboard-header-hidden-actions",children:[y&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-secondary",onClick:y,children:"Reset panels"}),u.length>0&&h&&s.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{h(),k(!1)},children:"Restore all"})]})]}),e&&p&&s.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>p(e),children:[s.jsxs("span",{className:"dashboard-header-hidden-current-leading",children:[s.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),s.jsx(dc,{value:v==null?void 0:v.hideCurrentTab})]}),s.jsx("span",{className:"dashboard-header-hidden-current-title",children:ft(e)})]}),u.length>0?s.jsx("div",{className:"dashboard-header-hidden-list",children:u.map(se=>s.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{m==null||m(se),k(!1)},children:[s.jsx("span",{className:"dashboard-header-inbox-item-title",children:ft(se)}),s.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[u.indexOf(se)<9?s.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",u.indexOf(se)+1]}):null,fr(se)]})]},se.tabKey))}):s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),s.jsxs("button",{type:"button",onClick:()=>f(!x),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[s.jsx(wr,{size:16}),be>0&&s.jsx("span",{className:"dashboard-header-inbox-badge",children:be})]}),x&&s.jsxs("div",{className:"dashboard-header-inbox-popover",children:[F.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Unread"}),F.map(se=>s.jsx(uc,{notification:se,shortcutIndex:pe.indexOf(se)>=0?pe.indexOf(se)+1:void 0,onOpen:()=>N(se),onMarkRead:()=>C(se.id),onMarkUnread:()=>R(se.id),onDelete:()=>T(se.id)},se.id))]}),V.length>0&&s.jsxs("div",{className:"dashboard-header-inbox-section",children:[s.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Read"}),V.map(se=>s.jsx(uc,{notification:se,onOpen:()=>N(se),onMarkRead:()=>C(se.id),onMarkUnread:()=>R(se.id),onDelete:()=>T(se.id)},se.id))]}),g.length===0&&s.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Dt(e={}){return{textQuery:e.textQuery||"",workspaceQuery:e.workspaceQuery||"",modelQuery:e.modelQuery||"",resumableOnly:!!e.resumableOnly,sortMode:e.sortMode||"recent"}}function Zy(e,t){return String(e||"")!==String(t||"")}function e0(e,t={}){const r=String(t.textQuery||"").trim().toLowerCase(),n=String(t.workspaceQuery||"").trim().toLowerCase(),a=String(t.modelQuery||"").trim().toLowerCase(),o=!!t.resumableOnly;return!r&&!n&&!a&&!o?e:e.filter(i=>!(o&&!i.canResume||r&&![i.title,i.preview].map(d=>String(d||"").toLowerCase()).join(`
52
52
  `).includes(r)||n&&!String(i.workspace||"").toLowerCase().includes(n)||a&&!lu(i.summaryMetadata).map(d=>d.toLowerCase()).join(`
53
- `).includes(a)))}function t0(e,t="recent"){const r=e.slice();return r.sort((n,a)=>{if(t==="oldest")return(Number(n.lastMessageAt)||0)-(Number(a.lastMessageAt)||0);if(t==="messages"){const o=(Number(a.messageCount)||0)-(Number(n.messageCount)||0);if(o!==0)return o}return(Number(a.lastMessageAt)||0)-(Number(n.lastMessageAt)||0)}),r}function ep(e,t={}){return t0(e0(e,t),t.sortMode||"recent")}function oa(e){return e?"Resume saved history":"Start fresh"}function Ei(e){return e?"Resuming saved history…":"Starting fresh…"}function s0(){return"Start fresh"}function r0(e,t=!1){return e==="cli"?oa(t):e==="ide"?"Start IDE":"Start ACP session"}function n0(e,t=!1){return e==="cli"?Ei(t):e==="ide"?"Starting IDE…":"Starting ACP session…"}function a0(){return"Fallback recovery for hosted runtimes after interruptions. For normal continuity, open saved history instead."}function o0(){return"Open saved history"}function i0(){return"Saved History"}function Bi(){return"Use saved history when you want continuity in the same provider conversation."}function l0(){return"No saved history found yet."}function c0(){return"Refresh saved history"}function d0(){return"Refreshing saved history…"}function ia(e,t){return e==="start-fresh"?`Start fresh with ${t}?`:`Restart ${t}?`}function la(e){return e==="start-fresh"?"Review the provider and target folder before starting fresh.":e==="restart-ide"?"Review or change the target workspace before restarting this IDE.":"Review or change the target workspace before restarting this stopped session."}function ca(e){return e==="start-fresh"?"Start fresh":"Restart"}function da(e){return e==="start-fresh"?"Starting fresh…":"Restarting…"}function tp(e){return`Resume saved history with ${e}?`}function sp(){return"Review or change the target workspace before resuming saved history."}function u0(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 rp({activeConv:e,ides:t,isCreatingChat:r,isRefreshingHistory:n,savedSessions:a=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:i=null,savedHistoryFilters:c,missingWorkspaceResumePath:d,onSavedHistoryFiltersChange:p,onClose:u,onNewChat:m,onSwitchSession:h,onRefreshHistory:y,onResumeSavedSession:x}){var T;const f=t.find(_=>_.id===e.routeId),j=(f==null?void 0:f.chats)||[],k=(T=f==null?void 0:f.activeChat)==null?void 0:T.id,b=lt(e)&&!it(e),[w,I]=l.useState(()=>Dt()),v=c||w,g=String(d||"").trim(),S=_=>{if(p){p(_);return}I(_)},N=l.useMemo(()=>a.map(_=>{const P=String(_.workspace||"").trim();return _.canResume||P||!g?_:{..._,workspace:g,canResume:!0,workspaceFallbackSource:"selected-workspace"}}),[g,a]),C=l.useMemo(()=>ep(N,{textQuery:v.textQuery,workspaceQuery:v.workspaceQuery,modelQuery:v.modelQuery,resumableOnly:v.resumableOnly,sortMode:v.sortMode}),[N,v.modelQuery,v.resumableOnly,v.sortMode,v.textQuery,v.workspaceQuery]),R=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:u,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),s.jsxs("div",{className:"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:b?i0():"Chat History"}),s.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:Ty(e)}),b&&s.jsx("div",{className:"text-[11px] text-text-muted mt-1",children:Bi()})]}),s.jsx("button",{onClick:u,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:[!b&&s.jsx("button",{onClick:m,disabled:r,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:r?"⌛ Creating...":"+ Start New Chat Session"}),b?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:v.textQuery,onChange:_=>S({...v,textQuery:_.target.value}),placeholder:"Search title or preview",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:v.workspaceQuery,onChange:_=>S({...v,workspaceQuery:_.target.value}),placeholder:"Filter by workspace",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:v.modelQuery,onChange:_=>S({...v,modelQuery:_.target.value}),placeholder:"Filter by model",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:v.sortMode,onChange:_=>S({...v,sortMode:_.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:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mt-2 flex items-center gap-2 text-[11px] text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:v.resumableOnly,onChange:_=>S({...v,resumableOnly:_.target.checked})}),"Resume-ready only"]})]}),C.map(_=>{const P=e.providerSessionId===_.providerSessionId,B=P||!_.canResume||!!i,z=_.workspaceFallbackSource==="selected-workspace";return s.jsxs("button",{type:"button",onClick:()=>{B||!x||x(_)},disabled:B,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${P?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${B?"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 ${P?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:_.providerSessionId})]}),s.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:u0(_.lastMessageAt)})]}),s.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:_.preview||"No saved preview yet"}),s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[s.jsxs("div",{className:"truncate",children:[_.workspace||"Workspace unknown",z?" · selected workspace":"",qs(_.summaryMetadata)?` · ${qs(_.summaryMetadata)}`:"",_.messageCount>0?` · ${_.messageCount} msgs`:""]}),s.jsx("div",{className:"shrink-0",children:P?"ACTIVE":_.canResume?z?"RESUME IN SELECTED WORKSPACE":i===_.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},_.id)})]}):j.map(_=>s.jsxs("div",{onClick:()=>{h(e.routeId,_.id),u()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${k===_.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 ${k===_.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[_.id.substring(0,12),"..."]}),k===_.id&&s.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},_.id)),(b&&!o&&C.length===0||!b&&j.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(Cf,{size:32})}),s.jsx("div",{className:"text-[13px]",children:b?a.length>0?"No saved history matches these filters.":l0():"No recent chat sessions found."})]}),b&&o&&s.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:s.jsx("div",{className:"text-[13px]",children:d0()})})]}),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:y,disabled:n||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||o?"⌛ Refreshing...":s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(va,{size:13})," ",b?c0():"Refresh History"]})})})]})]});return typeof document>"u"?R:dr.createPortal(R,document.body)}const pc={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Done"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Attention"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Update"}};function np({toasts:e,onDismiss:t,onClickToast:r}){return s.jsx("div",{className:"fixed right-4 z-[var(--z-toast)] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:e.map(n=>{const a=pc[n.type]||pc.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 o;(o=n.actions)!=null&&o.length||r&&r(n)},children:[s.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${a.accent}, color-mix(in srgb, ${a.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:o=>{o.stopPropagation(),t(n.id)},"aria-label":"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-[10px] font-bold uppercase tracking-[0.08em]",style:{background:a.chipBg,color:a.chipText,border:`1px solid color-mix(in srgb, ${a.accent} 22%, transparent)`},children:a.label})}),s.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:n.message}),n.actions&&n.actions.length>0&&s.jsx("div",{className:"flex gap-2 mt-3",children:n.actions.map((o,i)=>s.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${o.variant==="primary"||o.variant==="danger",""}`,style:o.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)"}:o.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:c=>{c.stopPropagation(),o.onClick(),t(n.id)},children:o.label},i))})]})]},n.id)})})}const p0=e=>e.transport==="pty"||e.transport==="acp"||e.transport==="cdp-page"?!0:e.daemonId!==e.id;function m0(e){const t=e.workspace||"";if(!t)return"";const r=t.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:t}function h0(e,t){return ap(e)||t}function ap(e){var a,o,i;const t=(o=(a=e.summaryMetadata)==null?void 0:a.items)==null?void 0:o.find(c=>(c==null?void 0:c.id)==="model"),r=((t==null?void 0:t.value)||(t==null?void 0:t.shortValue)||"").trim();if(r)return r;const n=(i=e.controlValues)==null?void 0:i.model;return typeof n=="string"&&n.trim()?n.trim():""}function f0(e){return ap(e)||void 0}function x0(e){return e.sessionId||e.instanceId||e.agentType}function op(e=[]){const t={};for(const r of e)r.type==="adhdev-daemon"&&(t[r.id]=Yt(r,{fallbackId:r.id}));return t}function ip(e,t={}){var n;const r=e.daemonId||((n=e.id)==null?void 0:n.split(":")[0])||e.id;return{machineName:Px(e,t.machineNames),connectionState:t.connectionStates?t.connectionStates[r]||t.defaultConnectionState||"new":t.defaultConnectionState}}function Fi(e,t={}){return b0(e,ip(e,t))}function b0(e,t={}){var h,y,x,f,j,k,b,w,I;const r=[],n=t.machineName,a=t.connectionState,o=m0(e),i=e.workspace||"",c=Ox(e.type,{agentName:e.cliName}),d=lt(e)||it(e)?c:Tt(e.type),p=h0(e,d),u=Array.isArray(e.childSessions)?e.childSessions.map(v=>{var g,S,N;return{sessionId:v.id,instanceId:v.id,providerSessionId:v.providerSessionId,activeChatId:(g=v.activeChat)==null?void 0:g.id,transport:v.transport,sessionCapabilities:v.capabilities,agentType:v.providerType,agentName:v.providerName||Tt(v.providerType),model:f0(v),status:v.status,title:v.title,lastMessagePreview:v.lastMessagePreview,lastMessageRole:v.lastMessageRole,lastMessageAt:v.lastMessageAt,lastMessageHash:v.lastMessageHash,messages:((S=v.activeChat)==null?void 0:S.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=p0(e);if(m){const v=e.sessionId||e.instanceId,g=(h=e.settings)==null?void 0:h.meshCoordinatorFor,S=((y=e.settings)==null?void 0:y.meshNodeFor)||!((x=e.settings)!=null&&x.meshCoordinatorFor)&&((f=e.settings)==null?void 0:f.launchedByCoordinator),N=g?" (Coordinator)":S?" (Mesh Node)":"",C=c+N,R=(j=e.activeChat)==null?void 0:j.activeModal,T=R&&Array.isArray(R.buttons)&&R.buttons.length>0,_=Hx(e.activeChat,[{status:e.status,activeModal:(k=e.activeChat)==null?void 0:k.activeModal}],e.agents||[]),P=e.activeChat||{title:"",messages:[]};let B=P.title&&String(P.title).trim()?String(P.title).trim():"";const z=(b=e.activeChat)==null?void 0:b.id,A=e.chats;if(z&&Array.isArray(A)&&A.length>0){const G=A.find(J=>J.id===z||J.id&&String(J.id)===String(z));G!=null&&G.title&&String(G.title).trim()&&(B=String(G.title).trim())}const O=(lt(e)||it(e),e.type),$=(lt(e)||it(e))&&$l(B,C,O)?"":B,L=P.messages||[],E=typeof z=="string"?z.trim():"",M=(lt(e)||it(e))&&E===String(e.type||"").trim(),H=E&&!M?E:e.providerSessionId,Y=e.coordinator||(typeof((w=e.settings)==null?void 0:w.meshCoordinatorFor)=="string"&&e.settings.meshCoordinatorFor?{meshId:e.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.push({routeId:e.id,sessionId:v,providerSessionId:e.providerSessionId,historySessionId:H,nativeSessionId:v,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:lt(e)&&e.mode||"chat",agentName:C,agentType:O,status:_,title:$,messages:L,resume:e.resume,hostIdeType:!lt(e)&&!it(e)?e.type:void 0,workspaceName:o,workspacePath:i,git:e.git,displayPrimary:o||$||(lt(e)?e.mode==="chat"?C:`Terminal${N}`:C),displaySecondary:p,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:T?R.buttons:void 0,modalMessage:T?R.message:void 0,streamSource:"native",tabKey:za(v,e.id),machineName:n,connectionState:a,settings:e.settings,coordinator:Y,messageInput:e.messageInput})}if(m&&(lt(e)||it(e)))return r;for(const v of u){const g=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,S=Wx(v),N=x0(v),C=`${e.id}:${N}`,R=v.title&&String(v.title).trim()||"",T=$l(R,v.agentName,v.agentType)?"":R,_=v.messages||[];if(!(v.transport==="cdp-webview"||!!v.sessionId||!!v.providerSessionId||_.length>0||g||!!T||!["idle","panel_hidden","disconnected","not_monitored"].includes(S)))continue;const B=v.coordinator||(typeof((I=v.settings)==null?void 0:I.meshCoordinatorFor)=="string"&&v.settings.meshCoordinatorFor?{meshId:v.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.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:S,title:T,messages:_,hostIdeType:e.type,workspaceName:o,workspacePath:i,git:v.git||e.git,displayPrimary:o||T||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:g?v.activeModal.buttons:void 0,modalMessage:g?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:za(v.sessionId||v.instanceId,C),machineName:n,connectionState:a,settings:v.settings,coordinator:B,messageInput:v.messageInput})}return r.length===0&&r.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:o,workspacePath:i,git:e.git,displayPrimary:o||d,displaySecondary:p,cdpConnected:e.cdpConnected,lastUpdated:e.lastUpdated,streamSource:"native",tabKey:za(e.sessionId||e.instanceId,e.id),connectionState:a,settings:e.settings,messageInput:e.messageInput}),r}function lp(e){return String(e.type||e.id||"").trim()}function ua(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!!t.trim()).map(t=>t.trim()):[]}function g0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.modelOptions)}function y0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.thinkingLevelOptions)}function cp(e){const t=new Map;for(const r of e||[])r!=null&&r.type&&t.set(r.type,{models:ua(r.modelOptions),thinking:ua(r.thinkingLevelOptions)});return t}function v0(e){var t;return e.category!=="cli"||!lp(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 xr(e){var n;const t=new Set,r=[];for(const a of e||[]){if(!v0(a))continue;const o=lp(a);if(!o||t.has(o))continue;t.add(o);const i=String(a.displayName||a.name||o),c=a.detectedPath||((n=a.lastDetection)==null?void 0:n.path)||null;r.push({type:o,label:i,icon:a.icon,statusLabel:c?`Detected at ${c}`:"Detected on this machine",detectedPath:c,...Array.isArray(a.modelOptions)&&a.modelOptions.length?{modelOptions:a.modelOptions}:{},...Array.isArray(a.thinkingLevelOptions)&&a.thinkingLevelOptions.length?{thinkingLevelOptions:a.thinkingLevelOptions}:{}})}return r}function br(e){const t=Array.isArray(e)?e:typeof e=="string"?e.split(/[\s,]+/):[],r=new Set,n=[];for(const a of t){const o=typeof a=="string"?a.trim():"";!o||r.has(o)||(r.add(o),n.push(o))}return n}function nn(e){return e.map(t=>t.type)}function w0(e,t){const r=br(e),n=t.trim();return!n||r.includes(n)?r:[...r,n]}function j0(e,t){return br(e).filter(r=>r!==t)}function mc(e,t,r){const n=br(e),a=n.indexOf(t);if(a<0)return n;const o=n.filter(c=>c!==t);if(r==="top")return[t,...o];if(r==="bottom")return[...o,t];const i=r==="up"?Math.max(0,a-1):Math.min(o.length,a+1);return o.splice(i,0,t),o}function hc({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 k0({value:e,availableProviders:t,onChange:r,disabled:n=!1,saveButton:a}){const[o,i]=l.useState(""),c=l.useMemo(()=>new Map(t.map(h=>[h.type,h])),[t]),d=l.useMemo(()=>br(e),[e]),p=d.filter(h=>!c.has(h)).length,u=t.filter(h=>!d.includes(h.type)),m=()=>{o&&(r(w0(d,o)),i(""))};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:d.length===0?s.jsx("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-300",children:"No provider priority configured. Launches without an explicit CLI provider will fail closed."}):d.map((h,y)=>{const x=c.get(h),f=!!x;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 ${f?"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-[10px] font-semibold text-text-muted",children:["#",y+1]}),(x==null?void 0:x.icon)&&s.jsx("span",{"aria-hidden":"true",children:x.icon}),s.jsx("span",{className:`font-mono text-[12px] ${f?"text-text-primary":"text-text-muted"}`,children:h}),f?s.jsx("span",{className:"rounded border border-green-500/20 bg-green-500/10 px-1.5 py-px text-[9px] font-semibold text-green-400",children:"available"}):s.jsx("span",{className:"rounded border border-amber-500/25 bg-amber-500/10 px-1.5 py-px text-[9px] font-semibold text-amber-400",children:"not on this machine"})]}),s.jsx("div",{className:"mt-1 text-[10px] text-text-muted",children:x?`${x.label} · ${x.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:n||y===0,title:"Move up",onClick:()=>r(mc(d,h,"up")),children:s.jsx(hc,{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:n||y===d.length-1,title:"Move down",onClick:()=>r(mc(d,h,"down")),children:s.jsx(hc,{direction:"down"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm text-red-400",disabled:n,onClick:()=>r(j0(d,h)),children:"Remove"})]})]},h)})}),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-[11px] text-text-secondary",children:[s.jsx("span",{className:"mb-1 block font-medium text-text-primary",children:"Add available CLI provider"}),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:o,onChange:h=>i(h.target.value),disabled:n||u.length===0,children:[s.jsx("option",{value:"",children:u.length?"Select provider…":"No additional detected CLI providers"}),u.map(h=>s.jsxs("option",{value:h.type,children:[h.label," (",h.type,")"]},h.type))]})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:n||!o,onClick:m,children:"Add provider"}),a]}),s.jsxs("div",{className:"mt-2 text-[11px] 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 N0(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 dp(e,t){const r=N0(e);return{daemonId:r.daemonId,payload:{...t,...r.targetSessionId&&!t.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const up=[{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:"🏄"}],pp=[{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],mp=[{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:"🟠"}],S0=up,C0=pp,I0=mp;function A0({icon:e,title:t,subtitle:r,badge:n,actions:a,className:o}){return s.jsxs("div",{className:$t("dashboard-header",o),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,n&&s.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&s.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),a&&s.jsx("div",{className:"flex gap-2",children:a})]})}function mn({icon:e,title:t,subtitle:r,badge:n,actions:a,widthClassName:o="max-w-6xl",contentClassName:i,children:c}){return s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(A0,{icon:e,title:t,subtitle:r,badge:n,actions:a}),s.jsx("div",{className:"page-content",children:s.jsx("div",{className:$t("mx-auto flex w-full flex-col gap-4",o,i),children:c})})]})}const Qo="adhdev:themechange";function M0(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function nr(){try{const e=localStorage.getItem("theme");if(e==="dark"||e==="light"||e==="system")return e}catch{}return"system"}function ar(e){return e==="system"?M0():e}function hp(e){typeof document>"u"||(document.documentElement.setAttribute("data-theme",e),document.documentElement.style.colorScheme=e)}function Wn(e,t){typeof window>"u"||window.dispatchEvent(new CustomEvent(Qo,{detail:{preference:e,theme:t}}))}function _0(){const e=nr(),t=ar(e);hp(t),Wn(e,t)}function Ts(){const[e,t]=l.useState(nr),[r,n]=l.useState(()=>ar(nr()));l.useEffect(()=>{hp(r)},[r]),l.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),c=d=>{if(e==="system"){const p=d.matches?"light":"dark";n(p),Wn("system",p)}};return i.addEventListener("change",c),()=>i.removeEventListener("change",c)},[e]),l.useEffect(()=>{const i=d=>{const p=d.detail||{},u=p.preference,m=p.theme;t(u==="dark"||u==="light"||u==="system"?u:nr()),n(m==="dark"||m==="light"?m:ar(nr()))},c=d=>{if(d.key!=="theme")return;const p=nr(),u=ar(p);t(p),n(u)};return window.addEventListener(Qo,i),window.addEventListener("storage",c),()=>{window.removeEventListener(Qo,i),window.removeEventListener("storage",c)}},[]);const a=l.useCallback(i=>{const c=ar(i);t(i),n(c);try{localStorage.setItem("theme",i)}catch{}Wn(i,c)},[]),o=l.useCallback(()=>{t(i=>{const c=i==="dark"?"light":i==="light"?"system":"dark",d=ar(c);n(d);try{localStorage.setItem("theme",c)}catch{}return Wn(c,d),c})},[]);return{theme:r,preference:e,setPreference:a,cycleTheme:o,isDark:r==="dark"}}const fc={dark:"Dark",light:"Light",system:"System"};function T0({collapsed:e}){const{preference:t,cycleTheme:r}=Ts(),n=t==="dark"?s.jsx(Af,{size:16}):t==="light"?s.jsx(If,{size:16}):s.jsx(Mf,{size:16});return s.jsxs("div",{className:`nav-item cursor-pointer ${e?"justify-center py-2.5 px-0":""}`,onClick:r,title:`Theme: ${fc[t]} (click to cycle)`,children:[s.jsx("span",{className:"nav-icon",children:n}),!e&&s.jsx("span",{className:"text-xs",children:fc[t]})]})}function eo(e,t){return e?typeof e=="function"?e(t):e:null}function L0({children:e,brand:t,navItems:r,sidebarSections:n=[],footerItems:a=[],footerInfo:o,footerActions:i,preMainContent:c,collapsedStorageKey:d="sidebar-collapsed"}){const[p,u]=l.useState(!1),[m,h]=l.useState(()=>{try{return localStorage.getItem(d)==="1"}catch{return!1}}),y=()=>u(!0),x=()=>u(!1),f=()=>{h(w=>{const I=!w;try{localStorage.setItem(d,I?"1":"0")}catch{}return I})},j=l.useMemo(()=>({collapsed:m,mobileMenuOpen:p,openMobileMenu:y,closeMobileMenu:x,toggleCollapsed:f}),[m,p]),k=w=>`nav-item${w.active?" active":""} cursor-pointer ${m?"justify-center py-2.5 px-0":""}${w.className?` ${w.className}`:""}`,b=w=>s.jsxs("div",{className:k(w),id:`nav-${w.id}`,onClick:()=>{w.onSelect(),x()},title:m?w.title??(typeof w.label=="string"?w.label:void 0):w.title,children:[s.jsx("span",{className:"nav-icon",children:w.icon}),!m&&w.label]},w.id);return s.jsxs("div",{className:`app-layout${p?" mobile-menu-open":""}${m?" sidebar-collapsed":""}`,children:[s.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:y,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":"Close menu",onClick:x,onKeyDown:w=>w.key==="Escape"&&x()}),s.jsxs("aside",{className:`sidebar ${p?"sidebar-open":""}`,children:[s.jsxs("div",{className:"sidebar-header",children:[s.jsx("div",{className:`sidebar-logo ${m?"justify-center gap-0":""}`,children:eo(t,j)}),s.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:x,children:s.jsx(wt,{size:16})})]}),s.jsx("nav",{className:"sidebar-nav",children:r.map(b)}),n.map(w=>s.jsxs("div",{className:w.className??"border-t border-border-subtle pt-2 mt-2",children:[!m&&w.title?s.jsx("div",{className:"px-3 py-1 text-[10px] text-text-muted uppercase tracking-widest",children:w.title}):null,w.items.map(b)]},w.key)),s.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[a.map(b),eo(o,j),s.jsx(T0,{collapsed:m}),eo(i,j)]})]}),s.jsx("main",{className:"main-content relative",children:s.jsxs("div",{className:"main-content-inner",children:[c,e]})})]})}function mt({title:e,icon:t,description:r,accentColor:n,className:a,collapsible:o,defaultOpen:i=!0,badge:c,children:d}){const[p,u]=l.useState(i),m=o?p:!0,h=(e||r)&&s.jsxs("div",{className:$t("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]}),r&&s.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o&&s.jsx("span",{className:$t("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:$t("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",a),style:n?{borderLeftColor:n}:void 0,children:[o&&h?s.jsx("button",{type:"button",className:"w-full bg-transparent border-none p-0 text-left cursor-pointer",onClick:()=>u(y=>!y),"aria-expanded":m,children:h}):h,m&&d]})}function Ma({icon:e,title:t,description:r,action:n,className:a}){return s.jsxs("div",{className:$t("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),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:r}),n]})}const R0={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"},P0={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Ft({variant:e,children:t,onDismiss:r,className:n}){return s.jsxs("div",{className:$t("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",R0[e],n),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{children:P0[e]}),s.jsx("span",{children:t})]}),r&&s.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}function yt({label:e,hint:t,children:r,className:n}){return s.jsxs("div",{className:$t("mb-5",n),children:[s.jsx("label",{className:"block text-xs font-semibold text-text-muted uppercase tracking-wider mb-2",children:e}),r,t&&s.jsx("p",{className:"text-xs text-text-muted mt-1.5",children:t})]})}function ts(e){const{className:t,...r}=e;return s.jsx("input",{...r,className:$t("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 D0={primary:"btn-primary",secondary:"btn-secondary",warning:"btn-warning",danger:"btn-danger",ghost:"btn-ghost"},gs=l.forwardRef(function({variant:t="secondary",size:r="md",type:n,className:a,...o},i){return s.jsx("button",{ref:i,type:n??"button",className:$t("btn",D0[t],r==="sm"&&"btn-sm",a),...o})}),$0=l.forwardRef(function({options:t,children:r,className:n,...a},o){return s.jsx("select",{ref:o,className:$t("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",n),...a,children:r??(t==null?void 0:t.map(i=>s.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value)))})}),E0={online:"bg-green-500/10 text-green-400 border-green-500/30",idle:"bg-yellow-500/10 text-yellow-400 border-yellow-500/30",busy:"bg-orange-500/10 text-orange-400 border-orange-500/30",error:"bg-red-500/10 text-red-400 border-red-500/30",offline:"bg-gray-500/10 text-text-secondary border-gray-500/30"},B0={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function F0({status:e,label:t,className:r}){const n=t||e;return s.jsxs("span",{className:$t("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",E0[e],r),children:[s.jsx("span",{className:$t("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",B0[e])}),n]})}function Es({label:e,description:t,checked:r,disabled:n,onChange:a,extra:o}){return s.jsxs("div",{className:`flex justify-between items-center ${n?"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-[11px] text-text-muted mt-0.5",children:t})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,s.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>a(!r),className:`relative inline-flex items-center ${n?"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:r?"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)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function O0({onPrefChange:e}){const[t,r]=Qx(),[n,a]=l.useState(()=>typeof window>"u"||!("Notification"in window)?"unsupported":Notification.permission);l.useEffect(()=>{const i=()=>{if(typeof window>"u"||!("Notification"in window)){a("unsupported");return}a(Notification.permission)};return i(),window.addEventListener("focus",i),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",i),document.removeEventListener("visibilitychange",i)}},[]);const o=(i,c)=>{r({[i]:c}),e==null||e(i,c)};return s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(wr,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:t.globalEnabled,onChange:i=>o("globalEnabled",i)}),t.globalEnabled&&s.jsx("div",{className:"border-t border-border-subtle my-0.5"}),t.globalEnabled&&s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(os,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:t.browserNotifications,onChange:i=>o("browserNotifications",i)}),t.globalEnabled&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx("div",{className:"text-[11px] text-text-muted",children:"Browser alerts only fire while this dashboard tab stays open in the background. If you close it, standalone cannot deliver hosted push notifications for you."}),n==="default"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-status-warning",children:[s.jsx("span",{children:"This browser has not granted notification permission yet. Allow it to receive local browser alerts."}),s.jsx("button",{onClick:()=>{uu().then(a)},className:"px-2 py-0.5 rounded border border-border-default bg-bg-glass text-text-secondary hover:text-text-primary transition-colors",children:"Allow notifications"})]}),n==="denied"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"Browser notifications are blocked in site or browser settings. Re-enable them there to receive standalone desktop alerts."}),n==="unsupported"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"This browser cannot show desktop notifications here. Keep the dashboard visible, or use another supported browser on this device."})]}),t.globalEnabled&&t.browserNotifications&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Kd,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:t.completionAlert,onChange:i=>o("completionAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(_f,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:t.approvalAlert,onChange:i=>o("approvalAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(tn,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:t.disconnectAlert,onChange:i=>o("disconnectAlert",i)})]}),!t.globalEnabled&&s.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Zo(e){const t=e.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/);if(!t)return null;const r=t[4]??null;let n=null;if(r){const a=r.match(/(?:^|\.)(\d+)$/);n=a?Number(a[1]):null}return{base:[Number(t[1]),Number(t[2]),Number(t[3])],prereleaseNumber:n,isPrerelease:r!==null}}function pa(e){var t;return((t=Zo(e))==null?void 0:t.base)??null}function H0(e,t){const r=pa(e),n=pa(t);if(!r||!n)return e.localeCompare(t);for(let a=0;a<3;a+=1){if(r[a]<n[a])return-1;if(r[a]>n[a])return 1}return 0}function W0(e,t){const r=Zo(e),n=Zo(t);if(!r||!n)return e!==t;for(let a=0;a<3;a+=1){if(r.base[a]<n.base[a])return!0;if(r.base[a]>n.base[a])return!1}return r.isPrerelease&&n.isPrerelease?r.prereleaseNumber===null||n.prereleaseNumber===null?!1:r.prereleaseNumber<n.prereleaseNumber:!1}function Oi(e,t){const r=e.version||null;return e.versionMismatch===!0?!0:!r||!t?!1:W0(r,t)}function Jr(e,t){if(e.versionUpdateRequired===!0)return!0;const r=e.version||null;if(!r||!t||r===t||H0(r,t)>=0)return!1;const n=pa(r),a=pa(t);return!n||!a?!1:n[0]!==a[0]||n[1]!==a[1]}function K0(e){return!e||typeof e!="object"?{}:"result"in e&&e.result&&typeof e.result=="object"?e.result:e}function to(e,t){return e instanceof Error?e.message:t}function U0({ides:e,emptyMessage:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){const o=e.filter(i=>i.type==="adhdev-daemon");return o.length===0?s.jsx(Ma,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:t||"Install ADHDev on a machine and sign in to connect it here."}):s.jsx("div",{className:"flex flex-col gap-2",children:o.map(i=>s.jsx(G0,{ide:i,allIdes:e,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a},i.id))})}function xc({title:e,message:t,confirmLabel:r,confirmColor:n,onConfirm:a,onCancel:o}){const i=n==="red"?"bg-status-error/20 text-status-error border-status-error/40 hover:bg-status-error/30":"";return dr.createPortal(s.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:"var(--z-modal)"},onClick:o,children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:c=>c.stopPropagation(),children:[s.jsx("div",{className:"font-semibold text-sm mb-3",children:e}),s.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:t}),s.jsxs("div",{className:"flex gap-2 justify-end",children:[s.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),s.jsx("button",{onClick:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,style:n==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:r})]})]})}),document.body)}function z0(e){const t=e.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...S0,...C0,...I0].find(a=>a.id===t||t.includes(a.id)||a.id.includes(t));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:e}}function G0({ide:e,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){var B,z;const[o,i]=l.useState("idle"),[c,d]=l.useState(""),[p,u]=l.useState(null),[m,h]=l.useState("idle"),[y,x]=l.useState(""),f=e.version||null,j=((B=e.machine)==null?void 0:B.platform)||((z=e.system)==null?void 0:z.platform)||"",k=Yt(e,{fallbackId:e.id}),b=j==="win32"?"🪟":j==="darwin"?"🍎":"🐧",w=t.filter(A=>A.daemonId===e.id&&A.transport==="cdp-page"),I=t.filter(A=>A.daemonId===e.id&&A.transport==="pty"),v=t.filter(A=>A.daemonId===e.id&&A.transport==="acp"),g=e.p2p,S=async()=>{if(r){i("upgrading"),d("Starting upgrade...");try{const A=K0(await r(e.id,"daemon_upgrade",{}));A.alreadyLatest?(i("done"),d(`Already on v${A.version||"latest"}.`)):A.upgraded||A.success?(i("done"),d(`Upgrade to v${A.version||"latest"} started. Daemon is restarting...`)):(i("error"),d(A.error||"Upgrade failed"))}catch(A){i("error"),d(to(A,"Connection lost during upgrade"))}}},N=async()=>{if(u(null),!!n){h("loading");try{await n(e.id),h("done"),x("Machine disconnected.")}catch(A){h("error"),x(to(A,"Failed to disconnect"))}}},C=async()=>{if(u(null),!!a){h("loading");try{await a(e.id),h("done"),x("Token revoked. Restart ADHDev on that machine to reconnect.")}catch(A){h("error"),x(to(A,"Failed to revoke token"))}}},R="0.9.82",T=Oi(e,R),_=Jr(e,R),P=w.length+I.length+v.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"text-xl",children:b}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium text-sm",children:k}),s.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[s.jsxs("span",{children:[e.id.substring(0,12),"…"]}),f&&s.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${T?"":"bg-bg-secondary"}`,style:T?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",f,!T&&" ✓"]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[r&&T&&s.jsx("button",{onClick:S,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${R}`,children:o==="upgrading"?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`${_?"↑ Update now":`↑ Update${` to v${R}`}`}`}),n&&s.jsx("button",{onClick:()=>u("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&s.jsx("button",{onClick:()=>u("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),s.jsx(F0,{status:e.status==="online"?"online":"error"})]})]}),s.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[g&&s.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${g.state==="connected"?"bg-status-online":"bg-text-muted/30"} ${g.state==="connecting"||g.state==="new"?"animate-pulse":""}`,style:g.state==="connecting"||g.state==="new"?{background:"var(--status-warning)"}:void 0}),s.jsxs("span",{className:"text-text-muted",children:["P2P ",g.state==="connected"?"connected":g.state==="connecting"||g.state==="new"?"connecting...":g.state||"off"]}),g.peers!==void 0&&g.peers>0&&s.jsxs("span",{className:"text-text-muted/60",children:["(",g.peers," peer",g.peers!==1?"s":"",")"]})]}),g&&P>0&&s.jsx("span",{className:"text-border-subtle",children:"·"}),P>0?s.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[w.map(A=>{const O=z0(A.type),$=A.cdpConnected;return s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:O.icon}),s.jsx("span",{children:O.name}),$!==void 0&&s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${$?"bg-status-online":"animate-pulse"}`,style:$?void 0:{background:"var(--status-warning)"},title:$?"CDP connected":"CDP connecting..."})]},A.id)}),I.map(A=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"⌨️"}),s.jsx("span",{children:A.cliName||"CLI"})]},A.id)),v.map(A=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"🔗"}),s.jsx("span",{children:A.cliName||"ACP"})]},A.id))]}):s.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(c||y)&&s.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-status-error":o==="done"||m==="done"?"text-status-online":"text-text-muted"}`,children:y||c})]}),p==="disconnect"&&s.jsx(xc,{title:"🔌 Disconnect Machine",message:`Disconnect "${k}" from ADHDev?
53
+ `).includes(a)))}function t0(e,t="recent"){const r=e.slice();return r.sort((n,a)=>{if(t==="oldest")return(Number(n.lastMessageAt)||0)-(Number(a.lastMessageAt)||0);if(t==="messages"){const o=(Number(a.messageCount)||0)-(Number(n.messageCount)||0);if(o!==0)return o}return(Number(a.lastMessageAt)||0)-(Number(n.lastMessageAt)||0)}),r}function ep(e,t={}){return t0(e0(e,t),t.sortMode||"recent")}function oa(e){return e?"Resume saved history":"Start fresh"}function Ei(e){return e?"Resuming saved history…":"Starting fresh…"}function s0(){return"Start fresh"}function r0(e,t=!1){return e==="cli"?oa(t):e==="ide"?"Start IDE":"Start ACP session"}function n0(e,t=!1){return e==="cli"?Ei(t):e==="ide"?"Starting IDE…":"Starting ACP session…"}function a0(){return"Fallback recovery for hosted runtimes after interruptions. For normal continuity, open saved history instead."}function o0(){return"Open saved history"}function i0(){return"Saved History"}function Bi(){return"Use saved history when you want continuity in the same provider conversation."}function l0(){return"No saved history found yet."}function c0(){return"Refresh saved history"}function d0(){return"Refreshing saved history…"}function ia(e,t){return e==="start-fresh"?`Start fresh with ${t}?`:`Restart ${t}?`}function la(e){return e==="start-fresh"?"Review the provider and target folder before starting fresh.":e==="restart-ide"?"Review or change the target workspace before restarting this IDE.":"Review or change the target workspace before restarting this stopped session."}function ca(e){return e==="start-fresh"?"Start fresh":"Restart"}function da(e){return e==="start-fresh"?"Starting fresh…":"Restarting…"}function tp(e){return`Resume saved history with ${e}?`}function sp(){return"Review or change the target workspace before resuming saved history."}function u0(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 rp({activeConv:e,ides:t,isCreatingChat:r,isRefreshingHistory:n,savedSessions:a=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:i=null,savedHistoryFilters:c,missingWorkspaceResumePath:d,onSavedHistoryFiltersChange:p,onClose:u,onNewChat:m,onSwitchSession:h,onRefreshHistory:y,onResumeSavedSession:x}){var T;const f=t.find(_=>_.id===e.routeId),j=(f==null?void 0:f.chats)||[],k=(T=f==null?void 0:f.activeChat)==null?void 0:T.id,b=lt(e)&&!it(e),[w,I]=l.useState(()=>Dt()),v=c||w,g=String(d||"").trim(),S=_=>{if(p){p(_);return}I(_)},N=l.useMemo(()=>a.map(_=>{const P=String(_.workspace||"").trim();return _.canResume||P||!g?_:{..._,workspace:g,canResume:!0,workspaceFallbackSource:"selected-workspace"}}),[g,a]),C=l.useMemo(()=>ep(N,{textQuery:v.textQuery,workspaceQuery:v.workspaceQuery,modelQuery:v.modelQuery,resumableOnly:v.resumableOnly,sortMode:v.sortMode}),[N,v.modelQuery,v.resumableOnly,v.sortMode,v.textQuery,v.workspaceQuery]),R=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:u,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),s.jsxs("div",{className:"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:b?i0():"Chat History"}),s.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:Ty(e)}),b&&s.jsx("div",{className:"text-[11px] text-text-muted mt-1",children:Bi()})]}),s.jsx("button",{onClick:u,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:[!b&&s.jsx("button",{onClick:m,disabled:r,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:r?"⌛ Creating...":"+ Start New Chat Session"}),b?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:v.textQuery,onChange:_=>S({...v,textQuery:_.target.value}),placeholder:"Search title or preview",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:v.workspaceQuery,onChange:_=>S({...v,workspaceQuery:_.target.value}),placeholder:"Filter by workspace",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:v.modelQuery,onChange:_=>S({...v,modelQuery:_.target.value}),placeholder:"Filter by model",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:v.sortMode,onChange:_=>S({...v,sortMode:_.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:"Most recent"}),s.jsx("option",{value:"oldest",children:"Oldest first"}),s.jsx("option",{value:"messages",children:"Most messages"})]})]}),s.jsxs("label",{className:"mt-2 flex items-center gap-2 text-[11px] text-text-muted",children:[s.jsx("input",{type:"checkbox",checked:v.resumableOnly,onChange:_=>S({...v,resumableOnly:_.target.checked})}),"Resume-ready only"]})]}),C.map(_=>{const P=e.providerSessionId===_.providerSessionId,B=P||!_.canResume||!!i,z=_.workspaceFallbackSource==="selected-workspace";return s.jsxs("button",{type:"button",onClick:()=>{B||!x||x(_)},disabled:B,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${P?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${B?"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 ${P?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:_.providerSessionId})]}),s.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:u0(_.lastMessageAt)})]}),s.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:_.preview||"No saved preview yet"}),s.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[s.jsxs("div",{className:"truncate",children:[_.workspace||"Workspace unknown",z?" · selected workspace":"",qs(_.summaryMetadata)?` · ${qs(_.summaryMetadata)}`:"",_.messageCount>0?` · ${_.messageCount} msgs`:""]}),s.jsx("div",{className:"shrink-0",children:P?"ACTIVE":_.canResume?z?"RESUME IN SELECTED WORKSPACE":i===_.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},_.id)})]}):j.map(_=>s.jsxs("div",{onClick:()=>{h(e.routeId,_.id),u()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${k===_.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 ${k===_.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:_.title||"Untitled Session"}),s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[_.id.substring(0,12),"..."]}),k===_.id&&s.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},_.id)),(b&&!o&&C.length===0||!b&&j.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(Cf,{size:32})}),s.jsx("div",{className:"text-[13px]",children:b?a.length>0?"No saved history matches these filters.":l0():"No recent chat sessions found."})]}),b&&o&&s.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:s.jsx("div",{className:"text-[13px]",children:d0()})})]}),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:y,disabled:n||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||o?"⌛ Refreshing...":s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(va,{size:13})," ",b?c0():"Refresh History"]})})})]})]});return typeof document>"u"?R:dr.createPortal(R,document.body)}const pc={success:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Done"},warning:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Attention"},info:{accent:"var(--accent-primary)",chipBg:"color-mix(in srgb, var(--accent-primary) 14%, transparent)",chipText:"var(--accent-primary-light)",label:"Update"}};function np({toasts:e,onDismiss:t,onClickToast:r}){return s.jsx("div",{className:"fixed right-4 z-[var(--z-toast)] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:e.map(n=>{const a=pc[n.type]||pc.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 o;(o=n.actions)!=null&&o.length||r&&r(n)},children:[s.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${a.accent}, color-mix(in srgb, ${a.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:o=>{o.stopPropagation(),t(n.id)},"aria-label":"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-[10px] font-bold uppercase tracking-[0.08em]",style:{background:a.chipBg,color:a.chipText,border:`1px solid color-mix(in srgb, ${a.accent} 22%, transparent)`},children:a.label})}),s.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:n.message}),n.actions&&n.actions.length>0&&s.jsx("div",{className:"flex gap-2 mt-3",children:n.actions.map((o,i)=>s.jsx("button",{className:`text-xs px-3 py-1.5 rounded-lg font-bold border transition-colors cursor-pointer ${o.variant==="primary"||o.variant==="danger",""}`,style:o.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)"}:o.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:c=>{c.stopPropagation(),o.onClick(),t(n.id)},children:o.label},i))})]})]},n.id)})})}const p0=e=>e.transport==="pty"||e.transport==="acp"||e.transport==="cdp-page"?!0:e.daemonId!==e.id;function m0(e){const t=e.workspace||"";if(!t)return"";const r=t.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:t}function h0(e,t){return ap(e)||t}function ap(e){var a,o,i;const t=(o=(a=e.summaryMetadata)==null?void 0:a.items)==null?void 0:o.find(c=>(c==null?void 0:c.id)==="model"),r=((t==null?void 0:t.value)||(t==null?void 0:t.shortValue)||"").trim();if(r)return r;const n=(i=e.controlValues)==null?void 0:i.model;return typeof n=="string"&&n.trim()?n.trim():""}function f0(e){return ap(e)||void 0}function x0(e){return e.sessionId||e.instanceId||e.agentType}function op(e=[]){const t={};for(const r of e)r.type==="adhdev-daemon"&&(t[r.id]=Yt(r,{fallbackId:r.id}));return t}function ip(e,t={}){var n;const r=e.daemonId||((n=e.id)==null?void 0:n.split(":")[0])||e.id;return{machineName:Px(e,t.machineNames),connectionState:t.connectionStates?t.connectionStates[r]||t.defaultConnectionState||"new":t.defaultConnectionState}}function Fi(e,t={}){return b0(e,ip(e,t))}function b0(e,t={}){var h,y,x,f,j,k,b,w,I;const r=[],n=t.machineName,a=t.connectionState,o=m0(e),i=e.workspace||"",c=Ox(e.type,{agentName:e.cliName}),d=lt(e)||it(e)?c:Tt(e.type),p=h0(e,d),u=Array.isArray(e.childSessions)?e.childSessions.map(v=>{var g,S,N;return{sessionId:v.id,instanceId:v.id,providerSessionId:v.providerSessionId,activeChatId:(g=v.activeChat)==null?void 0:g.id,transport:v.transport,sessionCapabilities:v.capabilities,agentType:v.providerType,agentName:v.providerName||Tt(v.providerType),model:f0(v),status:v.status,title:v.title,lastMessagePreview:v.lastMessagePreview,lastMessageRole:v.lastMessageRole,lastMessageAt:v.lastMessageAt,lastMessageHash:v.lastMessageHash,messages:((S=v.activeChat)==null?void 0:S.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=p0(e);if(m){const v=e.sessionId||e.instanceId,g=(h=e.settings)==null?void 0:h.meshCoordinatorFor,S=((y=e.settings)==null?void 0:y.meshNodeFor)||!((x=e.settings)!=null&&x.meshCoordinatorFor)&&((f=e.settings)==null?void 0:f.launchedByCoordinator),N=g?" (Coordinator)":S?" (Mesh Node)":"",C=c+N,R=(j=e.activeChat)==null?void 0:j.activeModal,T=R&&Array.isArray(R.buttons)&&R.buttons.length>0,_=Hx(e.activeChat,[{status:e.status,activeModal:(k=e.activeChat)==null?void 0:k.activeModal}],e.agents||[]),P=e.activeChat||{title:"",messages:[]};let B=P.title&&String(P.title).trim()?String(P.title).trim():"";const z=(b=e.activeChat)==null?void 0:b.id,A=e.chats;if(z&&Array.isArray(A)&&A.length>0){const G=A.find(J=>J.id===z||J.id&&String(J.id)===String(z));G!=null&&G.title&&String(G.title).trim()&&(B=String(G.title).trim())}const O=(lt(e)||it(e),e.type),$=(lt(e)||it(e))&&$l(B,C,O)?"":B,L=P.messages||[],E=typeof z=="string"?z.trim():"",M=(lt(e)||it(e))&&E===String(e.type||"").trim(),H=E&&!M?E:e.providerSessionId,Y=e.coordinator||(typeof((w=e.settings)==null?void 0:w.meshCoordinatorFor)=="string"&&e.settings.meshCoordinatorFor?{meshId:e.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.push({routeId:e.id,sessionId:v,providerSessionId:e.providerSessionId,historySessionId:H,nativeSessionId:v,transport:e.transport,daemonId:e.daemonId||void 0,sessionCapabilities:e.sessionCapabilities,mode:lt(e)&&e.mode||"chat",agentName:C,agentType:O,status:_,title:$,messages:L,resume:e.resume,hostIdeType:!lt(e)&&!it(e)?e.type:void 0,workspaceName:o,workspacePath:i,git:e.git,displayPrimary:o||$||(lt(e)?e.mode==="chat"?C:`Terminal${N}`:C),displaySecondary:p,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:T?R.buttons:void 0,modalMessage:T?R.message:void 0,streamSource:"native",tabKey:za(v,e.id),machineName:n,connectionState:a,settings:e.settings,coordinator:Y,messageInput:e.messageInput})}if(m&&(lt(e)||it(e)))return r;for(const v of u){const g=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,S=Wx(v),N=x0(v),C=`${e.id}:${N}`,R=v.title&&String(v.title).trim()||"",T=$l(R,v.agentName,v.agentType)?"":R,_=v.messages||[];if(!(v.transport==="cdp-webview"||!!v.sessionId||!!v.providerSessionId||_.length>0||g||!!T||!["idle","panel_hidden","disconnected","not_monitored"].includes(S)))continue;const B=v.coordinator||(typeof((I=v.settings)==null?void 0:I.meshCoordinatorFor)=="string"&&v.settings.meshCoordinatorFor?{meshId:v.settings.meshCoordinatorFor,role:"coordinator"}:void 0);r.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:S,title:T,messages:_,hostIdeType:e.type,workspaceName:o,workspacePath:i,git:v.git||e.git,displayPrimary:o||T||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:g?v.activeModal.buttons:void 0,modalMessage:g?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:za(v.sessionId||v.instanceId,C),machineName:n,connectionState:a,settings:v.settings,coordinator:B,messageInput:v.messageInput})}return r.length===0&&r.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:o,workspacePath:i,git:e.git,displayPrimary:o||d,displaySecondary:p,cdpConnected:e.cdpConnected,lastUpdated:e.lastUpdated,streamSource:"native",tabKey:za(e.sessionId||e.instanceId,e.id),connectionState:a,settings:e.settings,messageInput:e.messageInput}),r}function lp(e){return String(e.type||e.id||"").trim()}function ua(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!!t.trim()).map(t=>t.trim()):[]}function g0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.modelOptions)}function y0(e,t){const r=(t||"").trim();if(!r)return[];const n=(e||[]).find(a=>a.type===r);return ua(n==null?void 0:n.thinkingLevelOptions)}function cp(e){const t=new Map;for(const r of e||[])r!=null&&r.type&&t.set(r.type,{models:ua(r.modelOptions),thinking:ua(r.thinkingLevelOptions)});return t}function v0(e){var t;return e.category!=="cli"||!lp(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 xr(e){var n;const t=new Set,r=[];for(const a of e||[]){if(!v0(a))continue;const o=lp(a);if(!o||t.has(o))continue;t.add(o);const i=String(a.displayName||a.name||o),c=a.detectedPath||((n=a.lastDetection)==null?void 0:n.path)||null;r.push({type:o,label:i,icon:a.icon,statusLabel:c?`Detected at ${c}`:"Detected on this machine",detectedPath:c,...Array.isArray(a.modelOptions)&&a.modelOptions.length?{modelOptions:a.modelOptions}:{},...Array.isArray(a.thinkingLevelOptions)&&a.thinkingLevelOptions.length?{thinkingLevelOptions:a.thinkingLevelOptions}:{}})}return r}function br(e){const t=Array.isArray(e)?e:typeof e=="string"?e.split(/[\s,]+/):[],r=new Set,n=[];for(const a of t){const o=typeof a=="string"?a.trim():"";!o||r.has(o)||(r.add(o),n.push(o))}return n}function nn(e){return e.map(t=>t.type)}function w0(e,t){const r=br(e),n=t.trim();return!n||r.includes(n)?r:[...r,n]}function j0(e,t){return br(e).filter(r=>r!==t)}function mc(e,t,r){const n=br(e),a=n.indexOf(t);if(a<0)return n;const o=n.filter(c=>c!==t);if(r==="top")return[t,...o];if(r==="bottom")return[...o,t];const i=r==="up"?Math.max(0,a-1):Math.min(o.length,a+1);return o.splice(i,0,t),o}function hc({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 k0({value:e,availableProviders:t,onChange:r,disabled:n=!1,saveButton:a}){const[o,i]=l.useState(""),c=l.useMemo(()=>new Map(t.map(h=>[h.type,h])),[t]),d=l.useMemo(()=>br(e),[e]),p=d.filter(h=>!c.has(h)).length,u=t.filter(h=>!d.includes(h.type)),m=()=>{o&&(r(w0(d,o)),i(""))};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:d.length===0?s.jsx("div",{className:"rounded-md border border-amber-500/25 bg-amber-500/10 px-3 py-2 text-[12px] text-amber-300",children:"No provider priority configured. Launches without an explicit CLI provider will fail closed."}):d.map((h,y)=>{const x=c.get(h),f=!!x;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 ${f?"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-[10px] font-semibold text-text-muted",children:["#",y+1]}),(x==null?void 0:x.icon)&&s.jsx("span",{"aria-hidden":"true",children:x.icon}),s.jsx("span",{className:`font-mono text-[12px] ${f?"text-text-primary":"text-text-muted"}`,children:h}),f?s.jsx("span",{className:"rounded border border-green-500/20 bg-green-500/10 px-1.5 py-px text-[9px] font-semibold text-green-400",children:"available"}):s.jsx("span",{className:"rounded border border-amber-500/25 bg-amber-500/10 px-1.5 py-px text-[9px] font-semibold text-amber-400",children:"not on this machine"})]}),s.jsx("div",{className:"mt-1 text-[10px] text-text-muted",children:x?`${x.label} · ${x.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:n||y===0,title:"Move up",onClick:()=>r(mc(d,h,"up")),children:s.jsx(hc,{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:n||y===d.length-1,title:"Move down",onClick:()=>r(mc(d,h,"down")),children:s.jsx(hc,{direction:"down"})}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm text-red-400",disabled:n,onClick:()=>r(j0(d,h)),children:"Remove"})]})]},h)})}),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-[11px] text-text-secondary",children:[s.jsx("span",{className:"mb-1 block font-medium text-text-primary",children:"Add available CLI provider"}),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:o,onChange:h=>i(h.target.value),disabled:n||u.length===0,children:[s.jsx("option",{value:"",children:u.length?"Select provider…":"No additional detected CLI providers"}),u.map(h=>s.jsxs("option",{value:h.type,children:[h.label," (",h.type,")"]},h.type))]})]}),s.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:n||!o,onClick:m,children:"Add provider"}),a]}),s.jsxs("div",{className:"mt-2 text-[11px] 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 N0(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 dp(e,t){const r=N0(e);return{daemonId:r.daemonId,payload:{...t,...r.targetSessionId&&!t.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const up=[{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:"🏄"}],pp=[{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:"hermes-cli",name:"Hermes",icon:"⚕️"},{id:"kimi",name:"Kimi",icon:"🌙"},{id:"opencode",name:"OpenCode CLI",icon:"◆"}],mp=[{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:"🟠"}],S0=up,C0=pp,I0=mp;function A0({icon:e,title:t,subtitle:r,badge:n,actions:a,className:o}){return s.jsxs("div",{className:$t("dashboard-header",o),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,n&&s.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[n.count!==void 0?n.count:""," ",n.text]})]}),r&&s.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),a&&s.jsx("div",{className:"flex gap-2",children:a})]})}function mn({icon:e,title:t,subtitle:r,badge:n,actions:a,widthClassName:o="max-w-6xl",contentClassName:i,children:c}){return s.jsxs("div",{className:"flex flex-col h-full",children:[s.jsx(A0,{icon:e,title:t,subtitle:r,badge:n,actions:a}),s.jsx("div",{className:"page-content",children:s.jsx("div",{className:$t("mx-auto flex w-full flex-col gap-4",o,i),children:c})})]})}const Qo="adhdev:themechange";function M0(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function nr(){try{const e=localStorage.getItem("theme");if(e==="dark"||e==="light"||e==="system")return e}catch{}return"system"}function ar(e){return e==="system"?M0():e}function hp(e){typeof document>"u"||(document.documentElement.setAttribute("data-theme",e),document.documentElement.style.colorScheme=e)}function Wn(e,t){typeof window>"u"||window.dispatchEvent(new CustomEvent(Qo,{detail:{preference:e,theme:t}}))}function _0(){const e=nr(),t=ar(e);hp(t),Wn(e,t)}function Ts(){const[e,t]=l.useState(nr),[r,n]=l.useState(()=>ar(nr()));l.useEffect(()=>{hp(r)},[r]),l.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),c=d=>{if(e==="system"){const p=d.matches?"light":"dark";n(p),Wn("system",p)}};return i.addEventListener("change",c),()=>i.removeEventListener("change",c)},[e]),l.useEffect(()=>{const i=d=>{const p=d.detail||{},u=p.preference,m=p.theme;t(u==="dark"||u==="light"||u==="system"?u:nr()),n(m==="dark"||m==="light"?m:ar(nr()))},c=d=>{if(d.key!=="theme")return;const p=nr(),u=ar(p);t(p),n(u)};return window.addEventListener(Qo,i),window.addEventListener("storage",c),()=>{window.removeEventListener(Qo,i),window.removeEventListener("storage",c)}},[]);const a=l.useCallback(i=>{const c=ar(i);t(i),n(c);try{localStorage.setItem("theme",i)}catch{}Wn(i,c)},[]),o=l.useCallback(()=>{t(i=>{const c=i==="dark"?"light":i==="light"?"system":"dark",d=ar(c);n(d);try{localStorage.setItem("theme",c)}catch{}return Wn(c,d),c})},[]);return{theme:r,preference:e,setPreference:a,cycleTheme:o,isDark:r==="dark"}}const fc={dark:"Dark",light:"Light",system:"System"};function T0({collapsed:e}){const{preference:t,cycleTheme:r}=Ts(),n=t==="dark"?s.jsx(Af,{size:16}):t==="light"?s.jsx(If,{size:16}):s.jsx(Mf,{size:16});return s.jsxs("div",{className:`nav-item cursor-pointer ${e?"justify-center py-2.5 px-0":""}`,onClick:r,title:`Theme: ${fc[t]} (click to cycle)`,children:[s.jsx("span",{className:"nav-icon",children:n}),!e&&s.jsx("span",{className:"text-xs",children:fc[t]})]})}function eo(e,t){return e?typeof e=="function"?e(t):e:null}function L0({children:e,brand:t,navItems:r,sidebarSections:n=[],footerItems:a=[],footerInfo:o,footerActions:i,preMainContent:c,collapsedStorageKey:d="sidebar-collapsed"}){const[p,u]=l.useState(!1),[m,h]=l.useState(()=>{try{return localStorage.getItem(d)==="1"}catch{return!1}}),y=()=>u(!0),x=()=>u(!1),f=()=>{h(w=>{const I=!w;try{localStorage.setItem(d,I?"1":"0")}catch{}return I})},j=l.useMemo(()=>({collapsed:m,mobileMenuOpen:p,openMobileMenu:y,closeMobileMenu:x,toggleCollapsed:f}),[m,p]),k=w=>`nav-item${w.active?" active":""} cursor-pointer ${m?"justify-center py-2.5 px-0":""}${w.className?` ${w.className}`:""}`,b=w=>s.jsxs("div",{className:k(w),id:`nav-${w.id}`,onClick:()=>{w.onSelect(),x()},title:m?w.title??(typeof w.label=="string"?w.label:void 0):w.title,children:[s.jsx("span",{className:"nav-icon",children:w.icon}),!m&&w.label]},w.id);return s.jsxs("div",{className:`app-layout${p?" mobile-menu-open":""}${m?" sidebar-collapsed":""}`,children:[s.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:y,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":"Close menu",onClick:x,onKeyDown:w=>w.key==="Escape"&&x()}),s.jsxs("aside",{className:`sidebar ${p?"sidebar-open":""}`,children:[s.jsxs("div",{className:"sidebar-header",children:[s.jsx("div",{className:`sidebar-logo ${m?"justify-center gap-0":""}`,children:eo(t,j)}),s.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:x,children:s.jsx(wt,{size:16})})]}),s.jsx("nav",{className:"sidebar-nav",children:r.map(b)}),n.map(w=>s.jsxs("div",{className:w.className??"border-t border-border-subtle pt-2 mt-2",children:[!m&&w.title?s.jsx("div",{className:"px-3 py-1 text-[10px] text-text-muted uppercase tracking-widest",children:w.title}):null,w.items.map(b)]},w.key)),s.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[a.map(b),eo(o,j),s.jsx(T0,{collapsed:m}),eo(i,j)]})]}),s.jsx("main",{className:"main-content relative",children:s.jsxs("div",{className:"main-content-inner",children:[c,e]})})]})}function mt({title:e,icon:t,description:r,accentColor:n,className:a,collapsible:o,defaultOpen:i=!0,badge:c,children:d}){const[p,u]=l.useState(i),m=o?p:!0,h=(e||r)&&s.jsxs("div",{className:$t("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]}),r&&s.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o&&s.jsx("span",{className:$t("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:$t("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",n&&"border-l-[3px]",a),style:n?{borderLeftColor:n}:void 0,children:[o&&h?s.jsx("button",{type:"button",className:"w-full bg-transparent border-none p-0 text-left cursor-pointer",onClick:()=>u(y=>!y),"aria-expanded":m,children:h}):h,m&&d]})}function Ma({icon:e,title:t,description:r,action:n,className:a}){return s.jsxs("div",{className:$t("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),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:r}),n]})}const R0={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"},P0={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Ft({variant:e,children:t,onDismiss:r,className:n}){return s.jsxs("div",{className:$t("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",R0[e],n),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{children:P0[e]}),s.jsx("span",{children:t})]}),r&&s.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}function yt({label:e,hint:t,children:r,className:n}){return s.jsxs("div",{className:$t("mb-5",n),children:[s.jsx("label",{className:"block text-xs font-semibold text-text-muted uppercase tracking-wider mb-2",children:e}),r,t&&s.jsx("p",{className:"text-xs text-text-muted mt-1.5",children:t})]})}function ts(e){const{className:t,...r}=e;return s.jsx("input",{...r,className:$t("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 D0={primary:"btn-primary",secondary:"btn-secondary",warning:"btn-warning",danger:"btn-danger",ghost:"btn-ghost"},gs=l.forwardRef(function({variant:t="secondary",size:r="md",type:n,className:a,...o},i){return s.jsx("button",{ref:i,type:n??"button",className:$t("btn",D0[t],r==="sm"&&"btn-sm",a),...o})}),$0=l.forwardRef(function({options:t,children:r,className:n,...a},o){return s.jsx("select",{ref:o,className:$t("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",n),...a,children:r??(t==null?void 0:t.map(i=>s.jsx("option",{value:i.value,disabled:i.disabled,children:i.label},i.value)))})}),E0={online:"bg-green-500/10 text-green-400 border-green-500/30",idle:"bg-yellow-500/10 text-yellow-400 border-yellow-500/30",busy:"bg-orange-500/10 text-orange-400 border-orange-500/30",error:"bg-red-500/10 text-red-400 border-red-500/30",offline:"bg-gray-500/10 text-text-secondary border-gray-500/30"},B0={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function F0({status:e,label:t,className:r}){const n=t||e;return s.jsxs("span",{className:$t("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",E0[e],r),children:[s.jsx("span",{className:$t("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",B0[e])}),n]})}function Es({label:e,description:t,checked:r,disabled:n,onChange:a,extra:o}){return s.jsxs("div",{className:`flex justify-between items-center ${n?"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-[11px] text-text-muted mt-0.5",children:t})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,s.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>a(!r),className:`relative inline-flex items-center ${n?"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:r?"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)] ${r?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function O0({onPrefChange:e}){const[t,r]=Qx(),[n,a]=l.useState(()=>typeof window>"u"||!("Notification"in window)?"unsupported":Notification.permission);l.useEffect(()=>{const i=()=>{if(typeof window>"u"||!("Notification"in window)){a("unsupported");return}a(Notification.permission)};return i(),window.addEventListener("focus",i),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",i),document.removeEventListener("visibilitychange",i)}},[]);const o=(i,c)=>{r({[i]:c}),e==null||e(i,c)};return s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(wr,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:t.globalEnabled,onChange:i=>o("globalEnabled",i)}),t.globalEnabled&&s.jsx("div",{className:"border-t border-border-subtle my-0.5"}),t.globalEnabled&&s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(os,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:t.browserNotifications,onChange:i=>o("browserNotifications",i)}),t.globalEnabled&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx("div",{className:"text-[11px] text-text-muted",children:"Browser alerts only fire while this dashboard tab stays open in the background. If you close it, standalone cannot deliver hosted push notifications for you."}),n==="default"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-status-warning",children:[s.jsx("span",{children:"This browser has not granted notification permission yet. Allow it to receive local browser alerts."}),s.jsx("button",{onClick:()=>{uu().then(a)},className:"px-2 py-0.5 rounded border border-border-default bg-bg-glass text-text-secondary hover:text-text-primary transition-colors",children:"Allow notifications"})]}),n==="denied"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"Browser notifications are blocked in site or browser settings. Re-enable them there to receive standalone desktop alerts."}),n==="unsupported"&&s.jsx("div",{className:"text-[11px] text-status-warning",children:"This browser cannot show desktop notifications here. Keep the dashboard visible, or use another supported browser on this device."})]}),t.globalEnabled&&t.browserNotifications&&s.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Kd,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:t.completionAlert,onChange:i=>o("completionAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(_f,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:t.approvalAlert,onChange:i=>o("approvalAlert",i)}),s.jsx(Es,{label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(tn,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:t.disconnectAlert,onChange:i=>o("disconnectAlert",i)})]}),!t.globalEnabled&&s.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Zo(e){const t=e.trim().match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/);if(!t)return null;const r=t[4]??null;let n=null;if(r){const a=r.match(/(?:^|\.)(\d+)$/);n=a?Number(a[1]):null}return{base:[Number(t[1]),Number(t[2]),Number(t[3])],prereleaseNumber:n,isPrerelease:r!==null}}function pa(e){var t;return((t=Zo(e))==null?void 0:t.base)??null}function H0(e,t){const r=pa(e),n=pa(t);if(!r||!n)return e.localeCompare(t);for(let a=0;a<3;a+=1){if(r[a]<n[a])return-1;if(r[a]>n[a])return 1}return 0}function W0(e,t){const r=Zo(e),n=Zo(t);if(!r||!n)return e!==t;for(let a=0;a<3;a+=1){if(r.base[a]<n.base[a])return!0;if(r.base[a]>n.base[a])return!1}return r.isPrerelease&&n.isPrerelease?r.prereleaseNumber===null||n.prereleaseNumber===null?!1:r.prereleaseNumber<n.prereleaseNumber:!1}function Oi(e,t){const r=e.version||null;return e.versionMismatch===!0?!0:!r||!t?!1:W0(r,t)}function Jr(e,t){if(e.versionUpdateRequired===!0)return!0;const r=e.version||null;if(!r||!t||r===t||H0(r,t)>=0)return!1;const n=pa(r),a=pa(t);return!n||!a?!1:n[0]!==a[0]||n[1]!==a[1]}function K0(e){return!e||typeof e!="object"?{}:"result"in e&&e.result&&typeof e.result=="object"?e.result:e}function to(e,t){return e instanceof Error?e.message:t}function U0({ides:e,emptyMessage:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){const o=e.filter(i=>i.type==="adhdev-daemon");return o.length===0?s.jsx(Ma,{icon:s.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:t||"Install ADHDev on a machine and sign in to connect it here."}):s.jsx("div",{className:"flex flex-col gap-2",children:o.map(i=>s.jsx(G0,{ide:i,allIdes:e,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a},i.id))})}function xc({title:e,message:t,confirmLabel:r,confirmColor:n,onConfirm:a,onCancel:o}){const i=n==="red"?"bg-status-error/20 text-status-error border-status-error/40 hover:bg-status-error/30":"";return dr.createPortal(s.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:"var(--z-modal)"},onClick:o,children:s.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:c=>c.stopPropagation(),children:[s.jsx("div",{className:"font-semibold text-sm mb-3",children:e}),s.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:t}),s.jsxs("div",{className:"flex gap-2 justify-end",children:[s.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),s.jsx("button",{onClick:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,style:n==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:r})]})]})}),document.body)}function z0(e){const t=e.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...S0,...C0,...I0].find(a=>a.id===t||t.includes(a.id)||a.id.includes(t));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:e}}function G0({ide:e,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:a}){var B,z;const[o,i]=l.useState("idle"),[c,d]=l.useState(""),[p,u]=l.useState(null),[m,h]=l.useState("idle"),[y,x]=l.useState(""),f=e.version||null,j=((B=e.machine)==null?void 0:B.platform)||((z=e.system)==null?void 0:z.platform)||"",k=Yt(e,{fallbackId:e.id}),b=j==="win32"?"🪟":j==="darwin"?"🍎":"🐧",w=t.filter(A=>A.daemonId===e.id&&A.transport==="cdp-page"),I=t.filter(A=>A.daemonId===e.id&&A.transport==="pty"),v=t.filter(A=>A.daemonId===e.id&&A.transport==="acp"),g=e.p2p,S=async()=>{if(r){i("upgrading"),d("Starting upgrade...");try{const A=K0(await r(e.id,"daemon_upgrade",{}));A.alreadyLatest?(i("done"),d(`Already on v${A.version||"latest"}.`)):A.upgraded||A.success?(i("done"),d(`Upgrade to v${A.version||"latest"} started. Daemon is restarting...`)):(i("error"),d(A.error||"Upgrade failed"))}catch(A){i("error"),d(to(A,"Connection lost during upgrade"))}}},N=async()=>{if(u(null),!!n){h("loading");try{await n(e.id),h("done"),x("Machine disconnected.")}catch(A){h("error"),x(to(A,"Failed to disconnect"))}}},C=async()=>{if(u(null),!!a){h("loading");try{await a(e.id),h("done"),x("Token revoked. Restart ADHDev on that machine to reconnect.")}catch(A){h("error"),x(to(A,"Failed to revoke token"))}}},R="0.9.82",T=Oi(e,R),_=Jr(e,R),P=w.length+I.length+v.length;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"text-xl",children:b}),s.jsxs("div",{children:[s.jsx("div",{className:"font-medium text-sm",children:k}),s.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[s.jsxs("span",{children:[e.id.substring(0,12),"…"]}),f&&s.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${T?"":"bg-bg-secondary"}`,style:T?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",f,!T&&" ✓"]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[r&&T&&s.jsx("button",{onClick:S,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${R}`,children:o==="upgrading"?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`${_?"↑ Update now":`↑ Update${` to v${R}`}`}`}),n&&s.jsx("button",{onClick:()=>u("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&s.jsx("button",{onClick:()=>u("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),s.jsx(F0,{status:e.status==="online"?"online":"error"})]})]}),s.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[g&&s.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${g.state==="connected"?"bg-status-online":"bg-text-muted/30"} ${g.state==="connecting"||g.state==="new"?"animate-pulse":""}`,style:g.state==="connecting"||g.state==="new"?{background:"var(--status-warning)"}:void 0}),s.jsxs("span",{className:"text-text-muted",children:["P2P ",g.state==="connected"?"connected":g.state==="connecting"||g.state==="new"?"connecting...":g.state||"off"]}),g.peers!==void 0&&g.peers>0&&s.jsxs("span",{className:"text-text-muted/60",children:["(",g.peers," peer",g.peers!==1?"s":"",")"]})]}),g&&P>0&&s.jsx("span",{className:"text-border-subtle",children:"·"}),P>0?s.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[w.map(A=>{const O=z0(A.type),$=A.cdpConnected;return s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:O.icon}),s.jsx("span",{children:O.name}),$!==void 0&&s.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${$?"bg-status-online":"animate-pulse"}`,style:$?void 0:{background:"var(--status-warning)"},title:$?"CDP connected":"CDP connecting..."})]},A.id)}),I.map(A=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"⌨️"}),s.jsx("span",{children:A.cliName||"CLI"})]},A.id)),v.map(A=>s.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[s.jsx("span",{children:"🔗"}),s.jsx("span",{children:A.cliName||"ACP"})]},A.id))]}):s.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(c||y)&&s.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-status-error":o==="done"||m==="done"?"text-status-online":"text-text-muted"}`,children:y||c})]}),p==="disconnect"&&s.jsx(xc,{title:"🔌 Disconnect Machine",message:`Disconnect "${k}" from ADHDev?
54
54
 
55
55
  This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
56
56
 
package/public/index.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <meta name="description" content="ADHDev self-hosted dashboard for controlling AI agents" />
8
8
  <link rel="icon" href="/otter-logo.png" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet" />
10
- <script type="module" crossorigin src="/assets/index-CozmbKMf.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-Vt94-N39.js"></script>
11
11
  <link rel="modulepreload" crossorigin href="/assets/vendor-MlvUnxKA.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-D_scUWf6.css">
13
13
  </head>
@@ -3429,7 +3429,19 @@ async function meshStatus(ctx, args = {}) {
3429
3429
  // workers, leaving the mobile inbox stuck on the dispatched user task.
3430
3430
  ...typeof s.lastMessagePreview === "string" && s.lastMessagePreview ? { lastMessagePreview: s.lastMessagePreview } : {},
3431
3431
  ...typeof s.lastMessageRole === "string" && s.lastMessageRole ? { lastMessageRole: s.lastMessageRole } : {},
3432
- ...typeof s.lastMessageAt === "number" && Number.isFinite(s.lastMessageAt) ? { lastMessageAt: s.lastMessageAt } : {}
3432
+ ...typeof s.lastMessageAt === "number" && Number.isFinite(s.lastMessageAt) ? { lastMessageAt: s.lastMessageAt } : {},
3433
+ // RESTORE-STICK: carry the worker's AUTHORITATIVE dashboard hide/mute
3434
+ // state (already resolved by the worker's status/builders honoring any
3435
+ // per-session user override) plus the raw userHidden/userMuted overrides.
3436
+ // The coordinator's cloud snapshot append (daemon-cloud
3437
+ // appendMeshOwnedSessionsToSnapshot) otherwise re-derives hide/mute purely
3438
+ // from mesh policy and clobbers a user's manual restore/un-mute every
3439
+ // snapshot — the un-hide flickered visible then re-hid. Dropping these
3440
+ // here is exactly what starved the coordinator of the worker's real state.
3441
+ ...typeof s.surfaceHidden === "boolean" ? { surfaceHidden: s.surfaceHidden } : {},
3442
+ ...typeof s.muted === "boolean" ? { muted: s.muted } : {},
3443
+ ...typeof s.settings?.userHidden === "boolean" ? { userHidden: s.settings.userHidden } : {},
3444
+ ...typeof s.settings?.userMuted === "boolean" ? { userMuted: s.settings.userMuted } : {}
3433
3445
  };
3434
3446
  }).filter((s) => s.id);
3435
3447
  }