@adhdev/daemon-standalone 0.8.23 → 0.8.24

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.
@@ -1,8 +1,8 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-Cpt8BO0p.js","assets/vendor-BRZ4K-AC.js","assets/terminal-DYP7pi_n.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-fZXg9GuG.js","assets/vendor-BRZ4K-AC.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
2
  var ui=Object.defineProperty;var mi=(t,s,r)=>s in t?ui(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var tt=(t,s,r)=>mi(t,typeof s!="symbol"?s+"":s,r);import{r as a,j as e,M as On,a as Un,b as pi,c as fi,u as ts,R as Ze,d as zn,t as xi,e as hi,D as bi,f as gi,g as yi,h as kr,i as vi,k as wi,B as ji,l as ki,m as At,N as xr,n as Ni}from"./vendor-BRZ4K-AC.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&n(c)}).observe(document,{childList:!0,subtree:!0});function r(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(i){if(i.ep)return;i.ep=!0;const o=r(i);fetch(i.href,o)}})();const Hn=a.createContext({ides:[],updateIdeChats:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),Fn=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Gr(t){var r,n;let s=0;return"activeChat"in t&&(s+=4),(r=t.childSessions)!=null&&r.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(n=t.agents)!=null&&n.length&&(s+=1),s}function sr(t,s,r){if(r.type!=="adhdev-daemon")return r;const n={...r},i=s.version??r.version??t.version,o=s.serverVersion??t.serverVersion??r.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(n.version=i),o&&(n.serverVersion=o),i&&o&&i===o?(delete n.versionMismatch,delete n.serverVersion,n):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(n.versionMismatch=!0),n)}function $s(t){return Array.isArray(t)?t.map($s):!t||typeof t!="object"?t:Object.fromEntries(Object.entries(t).filter(([s])=>s!=="timestamp"&&s!=="_lastUpdate").sort(([s],[r])=>s.localeCompare(r)).map(([s,r])=>[s,$s(r)]))}function Si(t,s){try{return JSON.stringify($s(t))===JSON.stringify($s(s))}catch{return!1}}function gs(t,s,r){return Si(t,s)?(t._lastUpdate=r,typeof s.timestamp=="number"&&(t.timestamp=s.timestamp),t):s}function Ci(t,s,r){var d,x,l,f,b,p,S;const n=Date.now(),i=new Set((r==null?void 0:r.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(m=>({...m,_lastUpdate:n}));const o=new Map;for(const m of s)o.set(m.id,m);for(const m of t){const h=o.get(m.id);if(!h){o.set(m.id,{...m,_lastUpdate:n});continue}const y=Gr(m),g=Gr(h);if(y>g){const v=(d=m.chats)!=null&&d.length?m.chats:h.chats,K=sr(h,m,{...h,...m,chats:v,_lastUpdate:n});o.set(m.id,gs(h,K,n))}else if(y<g){const v={};if(m.status&&m.status!==h.status&&(v.status=m.status),m.cdpConnected!==void 0&&(v.cdpConnected=m.cdpConnected),(x=m.chats)!=null&&x.length&&!((l=h.chats)!=null&&l.length)&&(v.chats=m.chats),m.machineNickname!==void 0&&m.machineNickname!==h.machineNickname&&(v.machineNickname=m.machineNickname),m.version!==void 0&&(v.version=m.version),m.serverVersion!==void 0&&(v.serverVersion=m.serverVersion),m.versionMismatch===!0&&(v.versionMismatch=!0),Object.keys(v).length>0){const K=sr(h,m,{...h,...v,_lastUpdate:h._lastUpdate});o.set(m.id,gs(h,K,n))}else gs(h,{...h,_lastUpdate:h._lastUpdate},n)}else{const v=m.timestamp||n,K=h._lastUpdate||h.timestamp||0;if(v>=K){const N=(f=m.chats)!=null&&f.length?m.chats:h.chats,j=sr(h,m,{...h,...m,chats:N,_lastUpdate:n});o.set(m.id,gs(h,j,n))}else(b=m.chats)!=null&&b.length&&!((p=h.chats)!=null&&p.length)&&o.set(m.id,{...h,chats:m.chats})}}const c=new Set(t.map(m=>m.id)),u=new Set;for(const m of t){const h=m.daemonId||((S=m.id)==null?void 0:S.split(":")[0]);h&&u.add(h)}for(const[m,h]of o){const y=h.daemonId||m.split(":")[0];if(!u.has(y))continue;if(i.has(y)&&!c.has(m)){o.delete(m);continue}const g=n-(h._lastUpdate||h.timestamp||0);(h.transport==="pty"&&!c.has(m)&&g>1e4||h.transport==="acp"&&!c.has(m)&&g>1e4||h.transport==="cdp-page"&&!c.has(m)&&g>3e4)&&o.delete(m)}for(const[m,h]of o)n-(h._lastUpdate||h.timestamp||0)>3e5&&h.status!=="online"&&o.delete(m);return Array.from(o.values())}function Ii(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Ti({children:t,connectionOverrides:s}){const[r,n]=a.useState([]),[i,o]=a.useState(!1),[c,u]=a.useState([]),[d,x]=a.useState(void 0),l=a.useRef(r);a.useEffect(()=>{l.current=r},[r]);const f=a.useCallback((y,g)=>{n(v=>{let K=!1;const N=v.map(j=>j.id!==y||j.chats===g?j:(K=!0,{...j,chats:g}));return K?N:v})},[]),b=a.useCallback((y,g)=>{n(v=>{const K=v.length===0?y:Ci(y,v,g);return Ii(v,K)?v:K})},[]),p=a.useCallback(()=>o(!0),[]),S=a.useMemo(()=>({injectEntries:b,markLoaded:p,getIdes:()=>l.current}),[b,p]),m=s,h=a.useMemo(()=>({ides:r,updateIdeChats:f,initialLoaded:i,toasts:c,setToasts:u,wsStatus:(m==null?void 0:m.wsStatus)??"connected",isConnected:(m==null?void 0:m.isConnected)??!0,connectionStates:(m==null?void 0:m.connectionStates)??{},connectionTransports:(m==null?void 0:m.connectionTransports)??{},showReconnected:(m==null?void 0:m.showReconnected)??!1,retryConnection:m==null?void 0:m.retryConnection,isP2PActive:(m==null?void 0:m.isP2PActive)??!1,p2pStates:(m==null?void 0:m.p2pStates)??{},userRole:m==null?void 0:m.userRole,userName:d,setUserName:x}),[r,f,i,c,m==null?void 0:m.wsStatus,m==null?void 0:m.isConnected,m==null?void 0:m.connectionStates,m==null?void 0:m.connectionTransports,m==null?void 0:m.showReconnected,m==null?void 0:m.retryConnection,m==null?void 0:m.isP2PActive,m==null?void 0:m.p2pStates,m==null?void 0:m.userRole,d]);return e.jsx(Fn.Provider,{value:S,children:e.jsx(Hn.Provider,{value:h,children:t})})}function Zt(){return a.useContext(Hn)}function Yr(){return a.useContext(Fn)}function Vn(t){const{baseUrl:s,getToken:r,onUnauthorized:n}=t;function i(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function o(u){const d=r==null?void 0:r(),x=i(u),l=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return d&&l.searchParams.set("token",d),!u.startsWith("http")&&!s?`${l.pathname}${l.search}${l.hash}`:l.toString()}async function c(u,d={}){const x={"Content-Type":"application/json",...d.headers||{}},l=r==null?void 0:r();l&&(x.Authorization=`Bearer ${l}`);const f=i(u),b=await fetch(f,{...d,headers:x});if(b.status===401)throw n==null||n(),new Error("Unauthorized");if(!b.ok){const p=await b.json().catch(()=>({error:b.statusText}));throw new Error(p.error||`API Error: ${b.status}`)}return b.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:u=>c(`/api/v1/daemons/${u}/status`),sendCommand:(u,d,x={})=>c(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),execTerminal:(u,d,x)=>c(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:d,name:x})}),sendAgentMessage:(u,d,x)=>c(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:d,message:x})}),getAgentStatus:u=>c(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,d,x)=>c(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:d,action:x?"approve":"reject"})}),getMuxState:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,d,x={})=>c(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:d,payload:x})}),getMuxEventsUrl:u=>o(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeEventsUrl:u=>o(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:c}}const Ai=Vn({baseUrl:"http://localhost:3847"}),_i=a.createContext(Ai);function Mi({client:t,children:s}){return e.jsx(_i.Provider,{value:t,children:s})}const Pi={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},qn=a.createContext(Pi);function Li({value:t,children:s}){return e.jsx(qn.Provider,{value:t,children:s})}function Pt(){return a.useContext(qn)}const De={size:18};function Gn({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function Nr({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}function Ds({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2"}),e.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2"}),e.jsx("circle",{cx:"6",cy:"6",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"6",cy:"18",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("line",{x1:"10",y1:"6",x2:"18",y2:"6"}),e.jsx("line",{x1:"10",y1:"18",x2:"18",y2:"18"})]})}function Ri({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function Ei({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}function $i({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Bs({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),e.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"}),e.jsx("line",{x1:"9",y1:"7",x2:"16",y2:"7"}),e.jsx("line",{x1:"9",y1:"11",x2:"14",y2:"11"})]})}function Di({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"}),e.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),e.jsx("line",{x1:"8",y1:"14",x2:"14",y2:"14"}),e.jsx("line",{x1:"8",y1:"18",x2:"12",y2:"18"})]})}function zs({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Yn({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function Xn({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function Nt({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function ct({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Sr({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),e.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]})}function Bi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Qt({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function Hs({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function Fs({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function Ot({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}function Jn({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Ki({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C5 20 1 12 1 12a21.8 21.8 0 0 1 5.06-5.94"}),e.jsx("path",{d:"M9.9 4.24A10.93 10.93 0 0 1 12 4c7 0 11 8 11 8a21.77 21.77 0 0 1-2.16 3.19"}),e.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),e.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Cr({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]})}function Wi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})}function Ir({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function Oi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"})]})}function Tr({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})}function Ui({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Ut({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Zn({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function zi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"8",width:"18",height:"12",rx:"2"}),e.jsx("path",{d:"M12 2v6"}),e.jsx("circle",{cx:"8.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"15.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"})]})}function Hi({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function Fi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"9",y:"10",width:"6",height:"12",rx:"1"}),e.jsx("path",{d:"M12 2c-1.5 2-3 3.5-3 5a3 3 0 0 0 6 0c0-1.5-1.5-3-3-5z"})]})}function Vs({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),e.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function Vi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function qi({size:t=De.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function Gi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function Yi({size:t=De.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Qn(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Xi(t,s,r){const n=t;return Number(n.timestamp||n.receivedAt||n.createdAt||r[Yt(t,s)]||0)||0}function Ji(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Yt(t,s){const r=t,n=typeof r.content=="string"?r.content:Array.isArray(r.content)?r.content.map(o=>(o==null?void 0:o.text)||"").join(`
3
3
  `):String(r.content||"");return[r.id?`id:${r.id}`:"",r._localId?`local:${r._localId}`:"",r._turnKey?`turn:${r._turnKey}`:"",typeof r.index=="number"?`msgIndex:${r.index}`:"",r.timestamp?`ts:${r.timestamp}`:"",r.role?`role:${r.role}`:"",n?`content:${n.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const Xr=5e3,Zi=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(On,{remarkPlugins:[Un],children:s.text}),e.jsx("span",{className:"action-time",children:Qn(s.timestamp)})]})},(t,s)=>t.log===s.log),Qi=a.memo(function({message:s,receivedAt:r,agentName:n,userName:i,isCliMode:o,isTextExpanded:c,onToggleTextExpanded:u}){var v,K;const d=(s.role||"").toLowerCase(),x=d==="user"||d==="human",l=s.kind||(d==="tool"?"tool":"standard"),f=typeof s.content=="string"?s.content:(s.content||[]).map(N=>N.text||"").join(`
4
4
  `);if(l==="thought"){const N=((v=s.meta)==null?void 0:v.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Hi,{size:13}),e.jsx("span",{children:N})]}),e.jsx("div",{className:"chat-msg-body",children:f})]})}if(l==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:f.split(`
5
- `)[0].slice(0,80)})]});if(l==="terminal"){const N=s.meta||{},j=N.isRunning?"⏳":"✅",k=N.label||"Ran command";return e.jsxs("div",{className:"self-start chat-msg-terminal",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx("span",{children:j}),e.jsx("span",{children:k})]}),e.jsx("pre",{className:"chat-msg-body",children:f})]})}if(l==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:f.slice(0,100)});const p=String(((K=s.meta)==null?void 0:K.renderMode)||"").trim()==="preformatted",S=f,m=o&&!x&&!p&&S.length>Xr,h=m&&!c?S.slice(0,Xr):S,y=p,g=!y&&Ji(h);return e.jsx("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${x?"self-end":"self-start"}`,children:(S||x)&&e.jsxs("div",{className:`chat-bubble ${x?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${S?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:x?i||"You":s.senderName||n}),r!=null&&e.jsx("span",{className:"chat-time",children:Qn(r)})]}),S&&e.jsx("div",{className:"chat-markdown",children:y?e.jsx("pre",{className:"chat-preformatted",children:h}):g?e.jsx(On,{remarkPlugins:[Un,pi,fi],children:h}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:h})}),m&&e.jsx("button",{onClick:u,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:c?"Collapse ↑":`Show more (${Math.round(S.length/100)*100} chars) ↓`})]})})},(t,s)=>t.message===s.message&&t.receivedAt===s.receivedAt&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isTextExpanded===s.isTextExpanded),eo=a.forwardRef(function({messages:s,actionLogs:r,agentName:n="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:u="",receivedAtMap:d={},emptyState:x,onLoadMore:l,isLoadingMore:f,hasMoreHistory:b,hiddenLiveCount:p=0,loadError:S,scrollToBottomRequestNonce:m},h){var _e;const y=a.useRef(null),g=a.useRef(null),v=a.useRef(null),K=a.useRef(0),N=a.useRef(""),j=a.useRef(!1),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(null),M=a.useRef(!1),[$,U]=a.useState(new Set),D=a.useRef(!1),_=()=>{const G=y.current;return G?G.scrollHeight-G.scrollTop-G.clientHeight<200:!0},W=a.useCallback((G="auto")=>{const le=y.current;le&&le.scrollTo({top:le.scrollHeight,behavior:G})},[]),E=a.useCallback(()=>{var te;const G=y.current,le=(te=window.getSelection)==null?void 0:te.call(window);if(!G||!le||le.rangeCount===0||le.isCollapsed){M.current=!1;return}const J=le.anchorNode,he=le.focusNode;M.current=!!(J&&he&&G.contains(J)&&G.contains(he))},[]),H=a.useCallback((G="auto")=>{k.current!=null&&cancelAnimationFrame(k.current),k.current=requestAnimationFrame(()=>{k.current=null,W(G)})},[W]),X=s.length>0?`${s.length}:${(((_e=s[s.length-1])==null?void 0:_e.content)||"").length}`:"0:0";a.useEffect(()=>{const G=!j.current,le=N.current!==u;if(N.current=u,G||le){j.current=!0,D.current=!1,w.current=!0,M.current||H("auto"),K.current=s.length;return}s.length>K.current?!D.current&&!M.current&&H("auto"):_()&&!D.current&&!M.current&&H("auto"),K.current=s.length},[X,u,c,s.length,H]),a.useEffect(()=>{m&&(D.current=!1,w.current=!0,L.current!=null&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{w.current=!1,L.current=null},180),M.current||H("auto"))},[H,m]),a.useEffect(()=>()=>{k.current!=null&&cancelAnimationFrame(k.current),L.current!=null&&window.clearTimeout(L.current)},[]),a.useEffect(()=>{const G=g.current;if(!G)return;const le=()=>{L.current!=null&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{w.current=!1,L.current=null},180)},J=new ResizeObserver(()=>{w.current&&(M.current||(H("auto"),le()))});return J.observe(G),()=>{J.disconnect(),L.current!=null&&(window.clearTimeout(L.current),L.current=null)}},[H,u]),a.useImperativeHandle(h,()=>({scrollToBottom:(G="smooth")=>{W(G)}}),[W]),a.useEffect(()=>{const G=y.current;if(!G)return;let le;const J=()=>{clearTimeout(le),le=setTimeout(()=>{D.current=!_()},50)};return G.addEventListener("scroll",J,{passive:!0}),()=>{G.removeEventListener("scroll",J),clearTimeout(le)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",E),()=>document.removeEventListener("selectionchange",E)),[E]);const O=a.useRef(0),P=a.useRef(!1);a.useEffect(()=>{const G=y.current;if(!G||!P.current||O.current===0)return;const le=G.scrollHeight-O.current;le>0&&(G.scrollTop=le),O.current=0,P.current=!1},[s.length]);const R=()=>{const G=y.current;G&&(O.current=G.scrollHeight),P.current=!0,l==null||l()},F=a.useMemo(()=>{const G=s.map((te,fe)=>({type:"message",data:te,index:fe,ts:Xi(te,fe,d)}));if(!r||r.length===0)return G;const le=[...r].sort((te,fe)=>te.timestamp-fe.timestamp).map((te,fe)=>({type:"action",data:te,index:fe,ts:te.timestamp})),J=[];let he=0;for(const te of G){for(;he<le.length&&te.ts>0&&le[he].ts<te.ts;)J.push(le[he++]);J.push(te)}for(;he<le.length;)J.push(le[he++]);return J},[s,r,d]),Y=p>0||!!b,me=p>0?`↑ Show ${Math.min(p,80)} earlier messages${p>80?` (${p} hidden)`:""}`:S?`↻ ${S}`:"↑ Load older messages";return e.jsx("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:g,className:"chat-container-content",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),Y&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:R,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${S&&p===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:me})}),F.length===0&&!Y&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),F.map(G=>{if(G.type==="action"){const oe=G.data;return e.jsx(Zi,{log:oe},`action-${G.index}`)}const le=G.data,J=G.index,he=Yt(le,J),te=le.receivedAt||d[he],fe=`${u}-${he}`,ye=$.has(fe);return e.jsx(Qi,{message:le,receivedAt:te,agentName:n,userName:i,isCliMode:o,isTextExpanded:ye,onToggleTextExpanded:()=>U(oe=>{const de=new Set(oe);return ye?de.delete(fe):de.add(fe),de})},`msg-${he}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:v})]})})}),to=a.memo(eo,(t,s)=>t.messages===s.messages&&t.actionLogs===s.actionLogs&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isWorking===s.isWorking&&t.contextKey===s.contextKey&&t.receivedAtMap===s.receivedAtMap&&t.emptyState===s.emptyState&&t.onLoadMore===s.onLoadMore&&t.isLoadingMore===s.isLoadingMore&&t.hasMoreHistory===s.hasMoreHistory&&t.hiddenLiveCount===s.hiddenLiveCount&&t.loadError===s.loadError&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce),so="modulepreload",ro=function(t){return"/"+t},Jr={},no=function(s,r,n){let i=Promise.resolve();if(r&&r.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),u=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));i=Promise.allSettled(r.map(d=>{if(d=ro(d),d in Jr)return;Jr[d]=!0;const x=d.endsWith(".css"),l=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${l}`))return;const f=document.createElement("link");if(f.rel=x?"stylesheet":so,x||(f.as="script"),f.crossOrigin="",f.href=d,u&&f.setAttribute("nonce",u),document.head.appendChild(f),x)return new Promise((b,p)=>{f.addEventListener("load",b),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${d}`)))})}))}function o(c){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=c,window.dispatchEvent(u),!u.defaultPrevented)throw c}return i.then(c=>{for(const u of c||[])u.status==="rejected"&&o(u.reason);return s().catch(o)})};let Zr=!1;const ea=a.forwardRef(({onInput:t,onResize:s,fontSize:r=13,readOnly:n=!1},i)=>{const o=a.useRef(null),[c,u]=a.useState(null),d=a.useRef([]),x=a.useRef(!1),l=a.useRef(!1),f=a.useRef(!1),b=()=>{const p=o.current;if(p){x.current&&(p.clear(),x.current=!1);for(const S of d.current)p.write(S);d.current=[],l.current&&(p.fit(),l.current=!1),f.current&&(p.bumpResize(),f.current=!1)}};return a.useImperativeHandle(i,()=>({write:p=>{o.current?o.current.write(p):d.current.push(p)},clear:()=>{o.current?o.current.clear():(d.current=[],x.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(d.current=[],x.current=!0)},resize:(p,S)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(p,S)},fit:()=>{o.current?o.current.fit():l.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():f.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const p=requestAnimationFrame(()=>{b()});return()=>cancelAnimationFrame(p)},[c]),a.useEffect(()=>{let p=!1;return no(()=>import("./terminal-Cpt8BO0p.js"),__vite__mapDeps([0,1,2])).then(S=>{Zr||(Zr=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),p||u(()=>S.GhosttyTerminalView)}).catch(S=>{console.error("[CliTerminal] failed to load terminal renderer",S)}),()=>{p=!0}},[]),c?e.jsx(c,{ref:o,onInput:t,onResize:s,fontSize:r,readOnly:n,className:"w-full h-full rounded-lg overflow-hidden"}):e.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});ea.displayName="CliTerminal";function ys({label:t,value:s,sub:r,icon:n}){return e.jsxs("div",{className:"px-4 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-base flex items-center",children:n}),e.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:t})]}),e.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:s}),r&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:r})]})}function Qr({value:t,max:s,label:r,color:n="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,u=c>85?"#ef4444":c>60?"var(--status-warning)":n;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:r}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:r}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${u}, ${u}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ao({cursorPos:t,viewportRef:s,imgRef:r}){var g;if(!t||!r.current)return null;const n=r.current,i=n.getBoundingClientRect(),o=(g=s.current)==null?void 0:g.getBoundingClientRect();if(!o)return null;const c=n.naturalWidth||i.width,u=n.naturalHeight||i.height,d=c/u,x=i.width/i.height;let l,f,b,p;d>x?(l=i.width,f=i.width/d,b=0,p=(i.height-f)/2):(f=i.height,l=i.height*d,b=(i.width-l)/2,p=0);const S=i.left-o.left+b+l*t.nx,m=i.top-o.top+p+f*t.ny,h=Math.max(8,Math.min(o.width-8,S)),y=Math.max(8,Math.min(o.height-8,m));return e.jsxs("div",{style:{position:"absolute",left:h-8,top:y-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function io({inputMode:t,onToggleInputMode:s,isImeOpen:r,setIsImeOpen:n,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:u,handleImeSubmit:d,isConnActive:x,zoom:l,isMobile:f,mobileFillZoom:b,onZoomOut:p,onZoomReset:S,onZoomIn:m,transportType:h,screenshotUsage:y,lastActionStatus:g}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{n(v=>!v),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${r?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),r&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:c,autoFocus:!0,onTouchStart:v=>v.stopPropagation(),onChange:v=>u(v.target.value),onKeyDown:v=>{d(v)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{o(v=>!v),n(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),l>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(l*100),"%"]}),h==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),h==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),y&&y.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:y.budgetExhausted?"#ef4444":"#c4b5fd",background:y.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:y.budgetExhausted?"TURN blocked":`TURN ${y.dailyUsedMinutes}/${y.dailyBudgetMinutes}m`}),g&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:g})]})]}),i&&e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",l<=(f?b:1)+.01?f?"FILL":"FIT":`${Math.round(l*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:v=>{v.stopPropagation(),p()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),S()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function oo({waitingLabel:t,waitingHint:s,transportType:r}){return e.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:t}),e.jsx("div",{className:"text-[11px] text-white/40",children:s}),r==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function co(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function en(t){return t==null||typeof t=="number"||typeof t=="boolean"?t:typeof t=="string"?t.length>64?`${t.slice(0,61)}...`:t:Array.isArray(t)?`Array(${t.length})`:typeof t=="object"?"Object":typeof t}function hs(t,s){const r=a.useRef(null),n=a.useRef(0);a.useEffect(()=>{if(!co())return;n.current+=1;const i=r.current;if(!i){console.debug(`[render-trace] ${t}#${n.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,u])=>[c,en(u)]))}),r.current=s;return}const o=Object.keys({...i,...s}).filter(c=>!Object.is(i[c],s[c]));o.length>0&&console.debug(`[render-trace] ${t}#${n.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,en(s[c])]))}),r.current=s})}function lo({containerRef:t,viewportRef:s,imgRef:r,inputMode:n,setInputMode:i,minZoom:o,zoomRef:c,panXRef:u,panYRef:d,setPanX:x,setPanY:l,setZoom:f,lastWheelTimeRef:b,onAction:p,setLastActionStatus:S,spawnRippleFromNormalized:m,clampPan:h,isMobile:y,mobileFillZoom:g}){const[v,K]=a.useState(null),N=a.useRef(null),j=a.useRef(null),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(null),M=a.useRef(0),$=a.useRef(null),U=a.useRef(1),D=a.useRef({x:0,y:0}),_=a.useRef(!1),W=a.useRef(n),E=a.useRef(p),H=30,X=550,O=18,P=60,R=400,F=12,Y=()=>{if(N.current)return;const G={nx:.5,ny:.5};N.current=G,K(G)};return a.useEffect(()=>{W.current=n,n==="mouse"&&Y()},[n]),a.useEffect(()=>{E.current=p},[p]),a.useEffect(()=>{const G=t.current;if(!G)return;const le=oe=>{if(!r.current)return null;const de=r.current.getBoundingClientRect();return!de.width||!de.height?null:{nx:Math.max(0,Math.min(1,(oe.clientX-de.left)/de.width)),ny:Math.max(0,Math.min(1,(oe.clientY-de.top)/de.height))}},J=(oe,de)=>{if(!r.current)return{dnx:0,dny:0};const ue=r.current,Ce=ue.getBoundingClientRect(),Q=ue.naturalWidth||Ce.width,ie=ue.naturalHeight||Ce.height,ee=Q/ie,ge=Ce.width/Ce.height;let C,ne;return ee>ge?(C=Ce.width,ne=Ce.width/ee):(ne=Ce.height,C=Ce.height*ee),{dnx:oe/C,dny:de/ne}},he=(oe,de,ue)=>{if(ue<=1.05)return;const Ce=-(oe-.5)*100,Q=-(de-.5)*100,ie=h(Ce,Q,ue);(Math.abs(ie.x-u.current)>.1||Math.abs(ie.y-d.current)>.1)&&(x(ie.x),l(ie.y),u.current=ie.x,d.current=ie.y)},te=oe=>{const de=s.current;if(de&&oe.target instanceof Node&&de.contains(oe.target))oe.preventDefault();else return;if(oe.touches.length===1){const ue=oe.touches[0];j.current={x:ue.clientX,y:ue.clientY,time:Date.now()},k.current={x:ue.clientX,y:ue.clientY},_.current||(w.current=!1),L.current=setTimeout(()=>{if(!w.current&&!_.current)if(w.current=!0,W.current==="mouse"){const Ce=N.current||{nx:.5,ny:.5};S("Right Click"),m(Ce.nx,Ce.ny,"right"),E.current("input_click",{...Ce,button:"right"}).catch(()=>{})}else{const Ce=le(ue);Ce&&(S("Right Click"),m(Ce.nx,Ce.ny,"right"),E.current("input_click",{...Ce,button:"right"}).catch(()=>{}))}},500);return}if(oe.touches.length===2){L.current&&clearTimeout(L.current),w.current=!0,_.current=!0;const ue=oe.touches[1].clientX-oe.touches[0].clientX,Ce=oe.touches[1].clientY-oe.touches[0].clientY;$.current=Math.sqrt(ue*ue+Ce*Ce),U.current=c.current,D.current={x:(oe.touches[0].clientX+oe.touches[1].clientX)/2,y:(oe.touches[0].clientY+oe.touches[1].clientY)/2}}},fe=oe=>{const de=s.current;if(de&&oe.target instanceof Node&&de.contains(oe.target)&&oe.preventDefault(),oe.touches.length===1&&k.current){const ue=oe.touches[0],Ce=ue.clientX-k.current.x,Q=ue.clientY-k.current.y;if(!w.current&&j.current){const ie=ue.clientX-j.current.x,ee=ue.clientY-j.current.y;Math.sqrt(ie*ie+ee*ee)>8&&(w.current=!0,L.current&&clearTimeout(L.current))}if(w.current)if(W.current==="mouse"){const ie=J(Ce,Q),ee=N.current||{nx:.5,ny:.5},ge=Math.max(0,Math.min(1,ee.nx+ie.dnx)),C=Math.max(0,Math.min(1,ee.ny+ie.dny));N.current={nx:ge,ny:C},K({nx:ge,ny:C}),S(`Cursor: ${Math.round(ge*100)}%, ${Math.round(C*100)}%`),he(ge,C,c.current);const ne=Date.now();ne-b.current>=30&&(b.current=ne,E.current("input_mouseMoved",{nx:ge,ny:C}).catch(()=>{}))}else if(c.current>1){const ie=s.current;if(ie){const ee=ie.clientWidth,ge=ie.clientHeight,C=u.current+Ce/ee*100,ne=d.current+Q/ge*100,ve=h(C,ne,c.current);x(ve.x),l(ve.y),u.current=ve.x,d.current=ve.y}}else{const ie=le(ue);if(ie){const ee=Date.now();ee-b.current>=40&&(b.current=ee,S("Scroll"),E.current("input_wheel",{nx:ie.nx,ny:ie.ny,deltaX:Math.round(-Ce*2.5),deltaY:Math.round(-Q*2.5)}).catch(()=>{}))}}k.current={x:ue.clientX,y:ue.clientY};return}if(oe.touches.length===2&&$.current!==null){const ue=oe.touches[1].clientX-oe.touches[0].clientX,Ce=oe.touches[1].clientY-oe.touches[0].clientY,ie=Math.sqrt(ue*ue+Ce*Ce)/$.current,ee=(oe.touches[0].clientX+oe.touches[1].clientX)/2,ge=(oe.touches[0].clientY+oe.touches[1].clientY)/2,C=ee-D.current.x,ne=ge-D.current.y,ve=Math.abs(ie-1)>.03;if(W.current==="mouse"){if(ve){const B=Math.max(o,Math.min(5,U.current*ie));f(B),c.current=B}else if(Math.abs(C)>2||Math.abs(ne)>2){const B=N.current||{nx:.5,ny:.5},Z=Date.now();Z-b.current>=30&&(b.current=Z,S("Scroll"),E.current("input_wheel",{nx:B.nx,ny:B.ny,deltaX:Math.round(-C*3),deltaY:Math.round(-ne*3)}).catch(()=>{}))}}else{const B=Math.max(o,Math.min(5,U.current*ie));f(B),c.current=B;const Z=s.current;if(Z&&B>1){const re=Z.clientWidth,je=Z.clientHeight,ke=u.current+C/re*100,Pe=d.current+ne/je*100,Be=h(ke,Pe,B);x(Be.x),l(Be.y),u.current=Be.x,d.current=Be.y}}D.current={x:ee,y:ge}}},ye=oe=>{var de;if(L.current&&clearTimeout(L.current),$.current=null,oe.touches.length===1&&_.current){const ue=oe.touches[0];j.current={x:ue.clientX,y:ue.clientY,time:Date.now()},k.current={x:ue.clientX,y:ue.clientY},w.current=!0;return}if(oe.touches.length===0){if(_.current){_.current=!1,w.current=!1;return}if(oe.changedTouches.length===1){const ue=oe.changedTouches[0],Ce=Date.now(),Q=Ce-(((de=j.current)==null?void 0:de.time)||0),ie=j.current?ue.clientX-j.current.x:0,ee=j.current?ue.clientY-j.current.y:0,ge=Math.sqrt(ie*ie+ee*ee);if(W.current==="mouse"){if(Q<H||Q>X||ge>O){w.current=!1;return}const C=N.current||le(ue);C&&(S(`Click: ${Math.round(C.nx*100)}%, ${Math.round(C.ny*100)}%`),m(C.nx,C.ny,"left"),E.current("input_click",{...C}).catch(()=>{}))}else{if(w.current){w.current=!1;return}if(Q<P||Q>R||ge>F){w.current=!1;return}const C=le(ue);if(!C)return;Ce-M.current<300?(S("Double tap"),m(C.nx,C.ny,"double"),E.current("input_click",{...C,clickCount:2}).catch(()=>{}),M.current=0):(S(`Tap: ${Math.round(C.nx*100)}%, ${Math.round(C.ny*100)}%`),m(C.nx,C.ny,"left"),E.current("input_click",{...C}).catch(()=>{}),M.current=Ce)}}w.current=!1}};return G.addEventListener("touchstart",te,{passive:!1}),G.addEventListener("touchmove",fe,{passive:!1}),G.addEventListener("touchend",ye,{passive:!1}),()=>{G.removeEventListener("touchstart",te),G.removeEventListener("touchmove",fe),G.removeEventListener("touchend",ye),L.current&&clearTimeout(L.current)}},[t,s,r,o,c,u,d,x,l,f,b,S,m,h]),{cursorPos:v,cursorPosRef:N,handleToggleInputMode:()=>{i(G=>{const le=G==="touch"?"mouse":"touch";return le==="mouse"&&Y(),le})},handleZoomReset:()=>{const G=y?g:1;f(G),c.current=G,x(0),l(0),u.current=0,d.current=0}}}function ta({onAction:t,addLog:s,connState:r,connScreenshot:n,screenshotUsage:i,transportType:o}){const c=a.useRef(null),u=a.useRef(null),d=a.useRef(null),[x,l]=a.useState(null),[f,b]=a.useState(""),[,p]=a.useState(!1),[S,m]=a.useState([]),h=a.useRef(0),[y,g]=a.useState(!1),[v,K]=a.useState(!1),N=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[j,k]=a.useState(N?"mouse":"touch"),[w,L]=a.useState(1),M=a.useRef(!1),[$,U]=a.useState(1),[D,_]=a.useState(0),[W,E]=a.useState(0);hs("RemoteView",{connState:r,hasScreenshot:!!n,inputMode:j,zoom:$,panX:D,panY:W,isMenuOpen:y,isImeOpen:v});const H=a.useRef(0),X=a.useRef($),O=a.useRef(D),P=a.useRef(W);a.useEffect(()=>{X.current=$},[$]),a.useEffect(()=>{O.current=D},[D]),a.useEffect(()=>{P.current=W},[W]),a.useEffect(()=>{var Q;(Q=c.current)==null||Q.focus()},[]);const R=r==="connected",F=n,Y=R?"Connected. Waiting for first frame...":r==="connecting"?"Connecting to Host...":"Reconnecting to Host...",me=R?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!N||M.current||!F)return;const Q=d.current,ie=u.current;if(!Q||!ie)return;const ee=()=>{const ge=ie.clientWidth,C=ie.clientHeight,ne=Q.naturalWidth,ve=Q.naturalHeight;if(!ne||!ve||!ge||!C)return;const B=Math.min(ge/ne,C/ve),re=Math.max(ge/ne,C/ve)/B;re>1.01&&(L(re),U(re),X.current=re),M.current=!0};Q.complete&&Q.naturalWidth?ee():Q.addEventListener("load",ee,{once:!0})},[F,N]);const _e=.5;a.useEffect(()=>{$<=_e&&(_(0),E(0))},[$,_e]);const G=(Q,ie,ee)=>{if(ee<=_e)return{x:0,y:0};const ge=(ee-1)/(2*ee)*100,C=(ee-1)/(2*ee)*100;return{x:Math.max(-ge,Math.min(ge,Q)),y:Math.max(-C,Math.min(C,ie))}},le=(Q,ie)=>{if(!d.current)return null;const ee=d.current.getBoundingClientRect();return!ee.width||!ee.height?null:{nx:Math.max(0,Math.min(1,(Q-ee.left)/ee.width)),ny:Math.max(0,Math.min(1,(ie-ee.top)/ee.height))}},J=(Q,ie,ee)=>{const ge=u.current;if(!ge)return;const C=ge.getBoundingClientRect(),ne=++h.current;m(ve=>[...ve,{id:ne,x:Q-C.left,y:ie-C.top,type:ee}]),setTimeout(()=>m(ve=>ve.filter(B=>B.id!==ne)),600)},he=(Q,ie,ee)=>{const ge=d.current,C=u.current;if(!ge||!C)return;const ne=ge.getBoundingClientRect(),ve=C.getBoundingClientRect(),B=ge.naturalWidth||ne.width,Z=ge.naturalHeight||ne.height,re=B/Z,je=ne.width/ne.height;let ke,Pe,Be,We;re>je?(ke=ne.width,Pe=ne.width/re,Be=0,We=(ne.height-Pe)/2):(Pe=ne.height,ke=ne.height*re,Be=(ne.width-ke)/2,We=0);const Fe=ne.left-ve.left+Be+ke*Q,Qe=ne.top-ve.top+We+Pe*ie,Ge=++h.current;m(q=>[...q,{id:Ge,x:Fe,y:Qe,type:ee}]),setTimeout(()=>m(q=>q.filter(z=>z.id!==Ge)),600)},te=async Q=>{var ee;const ie=le(Q.clientX,Q.clientY);if(ie){l(`Click: ${Math.round(ie.nx*100)}%, ${Math.round(ie.ny*100)}%`),J(Q.clientX,Q.clientY,"left"),(ee=c.current)==null||ee.focus();try{const ge=await t("input_click",{nx:ie.nx,ny:ie.ny});ge!=null&&ge.success||s(`❌ Click failed: ${ge==null?void 0:ge.error}`)}catch(ge){s(`❌ Click error: ${ge.message||ge}`)}}},fe=async(Q,ie,ee,ge=0)=>{try{await t("input_key",{type:ee?"char":"keyDown",key:Q,code:ie,text:ee?Q:void 0,unmodifiedText:ee?Q:void 0,modifiers:ge})}catch(C){s(`❌ Key error: ${C.message||C}`)}},ye=async Q=>{if(Q.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Q.key)&&Q.preventDefault();let ee=0;Q.altKey&&(ee|=1),Q.ctrlKey&&(ee|=2),Q.metaKey&&(ee|=4),Q.shiftKey&&(ee|=8),l(`Key: ${Q.key}`),await fe(Q.key,Q.code,Q.key.length===1,ee)},oe=async Q=>{if(Q.key==="Enter"){if(Q.nativeEvent.isComposing)return;if(f){const ie=f;b(""),l(`IME Sent: ${ie}`);try{const ee=await t("input_type",{text:ie});ee!=null&&ee.success||s(`❌ IME error: ${ee==null?void 0:ee.error}`)}catch(ee){s(`❌ IME error: ${ee.message}`)}}else l("Key: Enter"),await fe("Enter","Enter",!1)}};a.useEffect(()=>{const Q=c.current;if(!Q)return;const ie=ee=>{var ge;if((ge=d.current)!=null&&ge.contains(ee.target)){ee.preventDefault();const C=Date.now();if(C-H.current<40)return;H.current=C;const ne=le(ee.clientX,ee.clientY);if(!ne)return;l(`Scroll: ${Math.round(ee.deltaY)}`),t("input_wheel",{nx:ne.nx,ny:ne.ny,deltaX:Math.round(ee.deltaX),deltaY:Math.round(ee.deltaY)}).catch(()=>{})}};return Q.addEventListener("wheel",ie,{passive:!1}),()=>Q.removeEventListener("wheel",ie)},[t]);const{cursorPos:de,handleToggleInputMode:ue,handleZoomReset:Ce}=lo({containerRef:c,viewportRef:u,imgRef:d,inputMode:j,setInputMode:k,minZoom:_e,zoomRef:X,panXRef:O,panYRef:P,setPanX:_,setPanY:E,setZoom:U,lastWheelTimeRef:H,onAction:t,setLastActionStatus:l,spawnRippleFromNormalized:he,clampPan:G,isMobile:N,mobileFillZoom:w});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:ye,onContextMenu:Q=>Q.preventDefault(),onFocus:()=>p(!0),onBlur:()=>p(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[F?e.jsx("img",{ref:d,src:F,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${$}) translate(${D}%, ${W}%)`,transformOrigin:"center center",cursor:j==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:te,onContextMenu:Q=>Q.preventDefault(),onDragStart:Q=>Q.preventDefault()}):e.jsx(oo,{waitingLabel:Y,waitingHint:me,transportType:o}),j==="mouse"&&F&&e.jsx(ao,{cursorPos:de,viewportRef:u,imgRef:d}),S.map(Q=>{const ee={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Q.type];return e.jsxs("div",{style:{position:"absolute",left:Q.x,top:Q.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${ee}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${ee}, 0.9)`,boxShadow:`0 0 12px rgba(${ee}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Q.id)})]}),e.jsx(io,{inputMode:j,onToggleInputMode:ue,isImeOpen:v,setIsImeOpen:K,isMenuOpen:y,setIsMenuOpen:g,imeText:f,setImeText:b,handleImeSubmit:oe,isConnActive:R,zoom:$,isMobile:N,mobileFillZoom:w,onZoomOut:()=>U(Q=>Math.max(.5,Q-.25)),onZoomReset:Ce,onZoomIn:()=>U(Q=>Math.min(5,Q+.25)),transportType:o,screenshotUsage:i,lastActionStatus:x}),e.jsx("style",{children:`
5
+ `)[0].slice(0,80)})]});if(l==="terminal"){const N=s.meta||{},j=N.isRunning?"⏳":"✅",k=N.label||"Ran command";return e.jsxs("div",{className:"self-start chat-msg-terminal",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx("span",{children:j}),e.jsx("span",{children:k})]}),e.jsx("pre",{className:"chat-msg-body",children:f})]})}if(l==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:f.slice(0,100)});const p=String(((K=s.meta)==null?void 0:K.renderMode)||"").trim()==="preformatted",S=f,m=o&&!x&&!p&&S.length>Xr,h=m&&!c?S.slice(0,Xr):S,y=p,g=!y&&Ji(h);return e.jsx("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${x?"self-end":"self-start"}`,children:(S||x)&&e.jsxs("div",{className:`chat-bubble ${x?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${S?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:x?i||"You":s.senderName||n}),r!=null&&e.jsx("span",{className:"chat-time",children:Qn(r)})]}),S&&e.jsx("div",{className:"chat-markdown",children:y?e.jsx("pre",{className:"chat-preformatted",children:h}):g?e.jsx(On,{remarkPlugins:[Un,pi,fi],children:h}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:h})}),m&&e.jsx("button",{onClick:u,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:c?"Collapse ↑":`Show more (${Math.round(S.length/100)*100} chars) ↓`})]})})},(t,s)=>t.message===s.message&&t.receivedAt===s.receivedAt&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isTextExpanded===s.isTextExpanded),eo=a.forwardRef(function({messages:s,actionLogs:r,agentName:n="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:u="",receivedAtMap:d={},emptyState:x,onLoadMore:l,isLoadingMore:f,hasMoreHistory:b,hiddenLiveCount:p=0,loadError:S,scrollToBottomRequestNonce:m},h){var _e;const y=a.useRef(null),g=a.useRef(null),v=a.useRef(null),K=a.useRef(0),N=a.useRef(""),j=a.useRef(!1),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(null),M=a.useRef(!1),[$,U]=a.useState(new Set),D=a.useRef(!1),_=()=>{const G=y.current;return G?G.scrollHeight-G.scrollTop-G.clientHeight<200:!0},W=a.useCallback((G="auto")=>{const le=y.current;le&&le.scrollTo({top:le.scrollHeight,behavior:G})},[]),E=a.useCallback(()=>{var te;const G=y.current,le=(te=window.getSelection)==null?void 0:te.call(window);if(!G||!le||le.rangeCount===0||le.isCollapsed){M.current=!1;return}const J=le.anchorNode,he=le.focusNode;M.current=!!(J&&he&&G.contains(J)&&G.contains(he))},[]),H=a.useCallback((G="auto")=>{k.current!=null&&cancelAnimationFrame(k.current),k.current=requestAnimationFrame(()=>{k.current=null,W(G)})},[W]),X=s.length>0?`${s.length}:${(((_e=s[s.length-1])==null?void 0:_e.content)||"").length}`:"0:0";a.useEffect(()=>{const G=!j.current,le=N.current!==u;if(N.current=u,G||le){j.current=!0,D.current=!1,w.current=!0,M.current||H("auto"),K.current=s.length;return}s.length>K.current?!D.current&&!M.current&&H("auto"):_()&&!D.current&&!M.current&&H("auto"),K.current=s.length},[X,u,c,s.length,H]),a.useEffect(()=>{m&&(D.current=!1,w.current=!0,L.current!=null&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{w.current=!1,L.current=null},180),M.current||H("auto"))},[H,m]),a.useEffect(()=>()=>{k.current!=null&&cancelAnimationFrame(k.current),L.current!=null&&window.clearTimeout(L.current)},[]),a.useEffect(()=>{const G=g.current;if(!G)return;const le=()=>{L.current!=null&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{w.current=!1,L.current=null},180)},J=new ResizeObserver(()=>{w.current&&(M.current||(H("auto"),le()))});return J.observe(G),()=>{J.disconnect(),L.current!=null&&(window.clearTimeout(L.current),L.current=null)}},[H,u]),a.useImperativeHandle(h,()=>({scrollToBottom:(G="smooth")=>{W(G)}}),[W]),a.useEffect(()=>{const G=y.current;if(!G)return;let le;const J=()=>{clearTimeout(le),le=setTimeout(()=>{D.current=!_()},50)};return G.addEventListener("scroll",J,{passive:!0}),()=>{G.removeEventListener("scroll",J),clearTimeout(le)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",E),()=>document.removeEventListener("selectionchange",E)),[E]);const O=a.useRef(0),P=a.useRef(!1);a.useEffect(()=>{const G=y.current;if(!G||!P.current||O.current===0)return;const le=G.scrollHeight-O.current;le>0&&(G.scrollTop=le),O.current=0,P.current=!1},[s.length]);const R=()=>{const G=y.current;G&&(O.current=G.scrollHeight),P.current=!0,l==null||l()},F=a.useMemo(()=>{const G=s.map((te,fe)=>({type:"message",data:te,index:fe,ts:Xi(te,fe,d)}));if(!r||r.length===0)return G;const le=[...r].sort((te,fe)=>te.timestamp-fe.timestamp).map((te,fe)=>({type:"action",data:te,index:fe,ts:te.timestamp})),J=[];let he=0;for(const te of G){for(;he<le.length&&te.ts>0&&le[he].ts<te.ts;)J.push(le[he++]);J.push(te)}for(;he<le.length;)J.push(le[he++]);return J},[s,r,d]),Y=p>0||!!b,me=p>0?`↑ Show ${Math.min(p,80)} earlier messages${p>80?` (${p} hidden)`:""}`:S?`↻ ${S}`:"↑ Load older messages";return e.jsx("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:g,className:"chat-container-content",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),Y&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:R,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${S&&p===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:me})}),F.length===0&&!Y&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),F.map(G=>{if(G.type==="action"){const oe=G.data;return e.jsx(Zi,{log:oe},`action-${G.index}`)}const le=G.data,J=G.index,he=Yt(le,J),te=le.receivedAt||d[he],fe=`${u}-${he}`,ye=$.has(fe);return e.jsx(Qi,{message:le,receivedAt:te,agentName:n,userName:i,isCliMode:o,isTextExpanded:ye,onToggleTextExpanded:()=>U(oe=>{const de=new Set(oe);return ye?de.delete(fe):de.add(fe),de})},`msg-${he}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:v})]})})}),to=a.memo(eo,(t,s)=>t.messages===s.messages&&t.actionLogs===s.actionLogs&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isWorking===s.isWorking&&t.contextKey===s.contextKey&&t.receivedAtMap===s.receivedAtMap&&t.emptyState===s.emptyState&&t.onLoadMore===s.onLoadMore&&t.isLoadingMore===s.isLoadingMore&&t.hasMoreHistory===s.hasMoreHistory&&t.hiddenLiveCount===s.hiddenLiveCount&&t.loadError===s.loadError&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce),so="modulepreload",ro=function(t){return"/"+t},Jr={},no=function(s,r,n){let i=Promise.resolve();if(r&&r.length>0){document.getElementsByTagName("link");const c=document.querySelector("meta[property=csp-nonce]"),u=(c==null?void 0:c.nonce)||(c==null?void 0:c.getAttribute("nonce"));i=Promise.allSettled(r.map(d=>{if(d=ro(d),d in Jr)return;Jr[d]=!0;const x=d.endsWith(".css"),l=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${l}`))return;const f=document.createElement("link");if(f.rel=x?"stylesheet":so,x||(f.as="script"),f.crossOrigin="",f.href=d,u&&f.setAttribute("nonce",u),document.head.appendChild(f),x)return new Promise((b,p)=>{f.addEventListener("load",b),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${d}`)))})}))}function o(c){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=c,window.dispatchEvent(u),!u.defaultPrevented)throw c}return i.then(c=>{for(const u of c||[])u.status==="rejected"&&o(u.reason);return s().catch(o)})};let Zr=!1;const ea=a.forwardRef(({onInput:t,onResize:s,fontSize:r=13,readOnly:n=!1},i)=>{const o=a.useRef(null),[c,u]=a.useState(null),d=a.useRef([]),x=a.useRef(!1),l=a.useRef(!1),f=a.useRef(!1),b=()=>{const p=o.current;if(p){x.current&&(p.clear(),x.current=!1);for(const S of d.current)p.write(S);d.current=[],l.current&&(p.fit(),l.current=!1),f.current&&(p.bumpResize(),f.current=!1)}};return a.useImperativeHandle(i,()=>({write:p=>{o.current?o.current.write(p):d.current.push(p)},clear:()=>{o.current?o.current.clear():(d.current=[],x.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(d.current=[],x.current=!0)},resize:(p,S)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(p,S)},fit:()=>{o.current?o.current.fit():l.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():f.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const p=requestAnimationFrame(()=>{b()});return()=>cancelAnimationFrame(p)},[c]),a.useEffect(()=>{let p=!1;return no(()=>import("./terminal-fZXg9GuG.js"),__vite__mapDeps([0,1,2])).then(S=>{Zr||(Zr=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),p||u(()=>S.GhosttyTerminalView)}).catch(S=>{console.error("[CliTerminal] failed to load terminal renderer",S)}),()=>{p=!0}},[]),c?e.jsx(c,{ref:o,onInput:t,onResize:s,fontSize:r,readOnly:n,className:"w-full h-full rounded-lg overflow-hidden"}):e.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});ea.displayName="CliTerminal";function ys({label:t,value:s,sub:r,icon:n}){return e.jsxs("div",{className:"px-4 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-base flex items-center",children:n}),e.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:t})]}),e.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:s}),r&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:r})]})}function Qr({value:t,max:s,label:r,color:n="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,u=c>85?"#ef4444":c>60?"var(--status-warning)":n;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:r}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:r}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${u}, ${u}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ao({cursorPos:t,viewportRef:s,imgRef:r}){var g;if(!t||!r.current)return null;const n=r.current,i=n.getBoundingClientRect(),o=(g=s.current)==null?void 0:g.getBoundingClientRect();if(!o)return null;const c=n.naturalWidth||i.width,u=n.naturalHeight||i.height,d=c/u,x=i.width/i.height;let l,f,b,p;d>x?(l=i.width,f=i.width/d,b=0,p=(i.height-f)/2):(f=i.height,l=i.height*d,b=(i.width-l)/2,p=0);const S=i.left-o.left+b+l*t.nx,m=i.top-o.top+p+f*t.ny,h=Math.max(8,Math.min(o.width-8,S)),y=Math.max(8,Math.min(o.height-8,m));return e.jsxs("div",{style:{position:"absolute",left:h-8,top:y-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function io({inputMode:t,onToggleInputMode:s,isImeOpen:r,setIsImeOpen:n,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:u,handleImeSubmit:d,isConnActive:x,zoom:l,isMobile:f,mobileFillZoom:b,onZoomOut:p,onZoomReset:S,onZoomIn:m,transportType:h,screenshotUsage:y,lastActionStatus:g}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{n(v=>!v),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${r?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),r&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:c,autoFocus:!0,onTouchStart:v=>v.stopPropagation(),onChange:v=>u(v.target.value),onKeyDown:v=>{d(v)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{o(v=>!v),n(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${i?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),l>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(l*100),"%"]}),h==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),h==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),y&&y.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:y.budgetExhausted?"#ef4444":"#c4b5fd",background:y.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:y.budgetExhausted?"TURN blocked":`TURN ${y.dailyUsedMinutes}/${y.dailyBudgetMinutes}m`}),g&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:g})]})]}),i&&e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",l<=(f?b:1)+.01?f?"FILL":"FIT":`${Math.round(l*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:v=>{v.stopPropagation(),p()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),S()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function oo({waitingLabel:t,waitingHint:s,transportType:r}){return e.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:t}),e.jsx("div",{className:"text-[11px] text-white/40",children:s}),r==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function co(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function en(t){return t==null||typeof t=="number"||typeof t=="boolean"?t:typeof t=="string"?t.length>64?`${t.slice(0,61)}...`:t:Array.isArray(t)?`Array(${t.length})`:typeof t=="object"?"Object":typeof t}function hs(t,s){const r=a.useRef(null),n=a.useRef(0);a.useEffect(()=>{if(!co())return;n.current+=1;const i=r.current;if(!i){console.debug(`[render-trace] ${t}#${n.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,u])=>[c,en(u)]))}),r.current=s;return}const o=Object.keys({...i,...s}).filter(c=>!Object.is(i[c],s[c]));o.length>0&&console.debug(`[render-trace] ${t}#${n.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,en(s[c])]))}),r.current=s})}function lo({containerRef:t,viewportRef:s,imgRef:r,inputMode:n,setInputMode:i,minZoom:o,zoomRef:c,panXRef:u,panYRef:d,setPanX:x,setPanY:l,setZoom:f,lastWheelTimeRef:b,onAction:p,setLastActionStatus:S,spawnRippleFromNormalized:m,clampPan:h,isMobile:y,mobileFillZoom:g}){const[v,K]=a.useState(null),N=a.useRef(null),j=a.useRef(null),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(null),M=a.useRef(0),$=a.useRef(null),U=a.useRef(1),D=a.useRef({x:0,y:0}),_=a.useRef(!1),W=a.useRef(n),E=a.useRef(p),H=30,X=550,O=18,P=60,R=400,F=12,Y=()=>{if(N.current)return;const G={nx:.5,ny:.5};N.current=G,K(G)};return a.useEffect(()=>{W.current=n,n==="mouse"&&Y()},[n]),a.useEffect(()=>{E.current=p},[p]),a.useEffect(()=>{const G=t.current;if(!G)return;const le=oe=>{if(!r.current)return null;const de=r.current.getBoundingClientRect();return!de.width||!de.height?null:{nx:Math.max(0,Math.min(1,(oe.clientX-de.left)/de.width)),ny:Math.max(0,Math.min(1,(oe.clientY-de.top)/de.height))}},J=(oe,de)=>{if(!r.current)return{dnx:0,dny:0};const ue=r.current,Ce=ue.getBoundingClientRect(),Q=ue.naturalWidth||Ce.width,ie=ue.naturalHeight||Ce.height,ee=Q/ie,ge=Ce.width/Ce.height;let C,ne;return ee>ge?(C=Ce.width,ne=Ce.width/ee):(ne=Ce.height,C=Ce.height*ee),{dnx:oe/C,dny:de/ne}},he=(oe,de,ue)=>{if(ue<=1.05)return;const Ce=-(oe-.5)*100,Q=-(de-.5)*100,ie=h(Ce,Q,ue);(Math.abs(ie.x-u.current)>.1||Math.abs(ie.y-d.current)>.1)&&(x(ie.x),l(ie.y),u.current=ie.x,d.current=ie.y)},te=oe=>{const de=s.current;if(de&&oe.target instanceof Node&&de.contains(oe.target))oe.preventDefault();else return;if(oe.touches.length===1){const ue=oe.touches[0];j.current={x:ue.clientX,y:ue.clientY,time:Date.now()},k.current={x:ue.clientX,y:ue.clientY},_.current||(w.current=!1),L.current=setTimeout(()=>{if(!w.current&&!_.current)if(w.current=!0,W.current==="mouse"){const Ce=N.current||{nx:.5,ny:.5};S("Right Click"),m(Ce.nx,Ce.ny,"right"),E.current("input_click",{...Ce,button:"right"}).catch(()=>{})}else{const Ce=le(ue);Ce&&(S("Right Click"),m(Ce.nx,Ce.ny,"right"),E.current("input_click",{...Ce,button:"right"}).catch(()=>{}))}},500);return}if(oe.touches.length===2){L.current&&clearTimeout(L.current),w.current=!0,_.current=!0;const ue=oe.touches[1].clientX-oe.touches[0].clientX,Ce=oe.touches[1].clientY-oe.touches[0].clientY;$.current=Math.sqrt(ue*ue+Ce*Ce),U.current=c.current,D.current={x:(oe.touches[0].clientX+oe.touches[1].clientX)/2,y:(oe.touches[0].clientY+oe.touches[1].clientY)/2}}},fe=oe=>{const de=s.current;if(de&&oe.target instanceof Node&&de.contains(oe.target)&&oe.preventDefault(),oe.touches.length===1&&k.current){const ue=oe.touches[0],Ce=ue.clientX-k.current.x,Q=ue.clientY-k.current.y;if(!w.current&&j.current){const ie=ue.clientX-j.current.x,ee=ue.clientY-j.current.y;Math.sqrt(ie*ie+ee*ee)>8&&(w.current=!0,L.current&&clearTimeout(L.current))}if(w.current)if(W.current==="mouse"){const ie=J(Ce,Q),ee=N.current||{nx:.5,ny:.5},ge=Math.max(0,Math.min(1,ee.nx+ie.dnx)),C=Math.max(0,Math.min(1,ee.ny+ie.dny));N.current={nx:ge,ny:C},K({nx:ge,ny:C}),S(`Cursor: ${Math.round(ge*100)}%, ${Math.round(C*100)}%`),he(ge,C,c.current);const ne=Date.now();ne-b.current>=30&&(b.current=ne,E.current("input_mouseMoved",{nx:ge,ny:C}).catch(()=>{}))}else if(c.current>1){const ie=s.current;if(ie){const ee=ie.clientWidth,ge=ie.clientHeight,C=u.current+Ce/ee*100,ne=d.current+Q/ge*100,ve=h(C,ne,c.current);x(ve.x),l(ve.y),u.current=ve.x,d.current=ve.y}}else{const ie=le(ue);if(ie){const ee=Date.now();ee-b.current>=40&&(b.current=ee,S("Scroll"),E.current("input_wheel",{nx:ie.nx,ny:ie.ny,deltaX:Math.round(-Ce*2.5),deltaY:Math.round(-Q*2.5)}).catch(()=>{}))}}k.current={x:ue.clientX,y:ue.clientY};return}if(oe.touches.length===2&&$.current!==null){const ue=oe.touches[1].clientX-oe.touches[0].clientX,Ce=oe.touches[1].clientY-oe.touches[0].clientY,ie=Math.sqrt(ue*ue+Ce*Ce)/$.current,ee=(oe.touches[0].clientX+oe.touches[1].clientX)/2,ge=(oe.touches[0].clientY+oe.touches[1].clientY)/2,C=ee-D.current.x,ne=ge-D.current.y,ve=Math.abs(ie-1)>.03;if(W.current==="mouse"){if(ve){const B=Math.max(o,Math.min(5,U.current*ie));f(B),c.current=B}else if(Math.abs(C)>2||Math.abs(ne)>2){const B=N.current||{nx:.5,ny:.5},Z=Date.now();Z-b.current>=30&&(b.current=Z,S("Scroll"),E.current("input_wheel",{nx:B.nx,ny:B.ny,deltaX:Math.round(-C*3),deltaY:Math.round(-ne*3)}).catch(()=>{}))}}else{const B=Math.max(o,Math.min(5,U.current*ie));f(B),c.current=B;const Z=s.current;if(Z&&B>1){const re=Z.clientWidth,je=Z.clientHeight,ke=u.current+C/re*100,Pe=d.current+ne/je*100,Be=h(ke,Pe,B);x(Be.x),l(Be.y),u.current=Be.x,d.current=Be.y}}D.current={x:ee,y:ge}}},ye=oe=>{var de;if(L.current&&clearTimeout(L.current),$.current=null,oe.touches.length===1&&_.current){const ue=oe.touches[0];j.current={x:ue.clientX,y:ue.clientY,time:Date.now()},k.current={x:ue.clientX,y:ue.clientY},w.current=!0;return}if(oe.touches.length===0){if(_.current){_.current=!1,w.current=!1;return}if(oe.changedTouches.length===1){const ue=oe.changedTouches[0],Ce=Date.now(),Q=Ce-(((de=j.current)==null?void 0:de.time)||0),ie=j.current?ue.clientX-j.current.x:0,ee=j.current?ue.clientY-j.current.y:0,ge=Math.sqrt(ie*ie+ee*ee);if(W.current==="mouse"){if(Q<H||Q>X||ge>O){w.current=!1;return}const C=N.current||le(ue);C&&(S(`Click: ${Math.round(C.nx*100)}%, ${Math.round(C.ny*100)}%`),m(C.nx,C.ny,"left"),E.current("input_click",{...C}).catch(()=>{}))}else{if(w.current){w.current=!1;return}if(Q<P||Q>R||ge>F){w.current=!1;return}const C=le(ue);if(!C)return;Ce-M.current<300?(S("Double tap"),m(C.nx,C.ny,"double"),E.current("input_click",{...C,clickCount:2}).catch(()=>{}),M.current=0):(S(`Tap: ${Math.round(C.nx*100)}%, ${Math.round(C.ny*100)}%`),m(C.nx,C.ny,"left"),E.current("input_click",{...C}).catch(()=>{}),M.current=Ce)}}w.current=!1}};return G.addEventListener("touchstart",te,{passive:!1}),G.addEventListener("touchmove",fe,{passive:!1}),G.addEventListener("touchend",ye,{passive:!1}),()=>{G.removeEventListener("touchstart",te),G.removeEventListener("touchmove",fe),G.removeEventListener("touchend",ye),L.current&&clearTimeout(L.current)}},[t,s,r,o,c,u,d,x,l,f,b,S,m,h]),{cursorPos:v,cursorPosRef:N,handleToggleInputMode:()=>{i(G=>{const le=G==="touch"?"mouse":"touch";return le==="mouse"&&Y(),le})},handleZoomReset:()=>{const G=y?g:1;f(G),c.current=G,x(0),l(0),u.current=0,d.current=0}}}function ta({onAction:t,addLog:s,connState:r,connScreenshot:n,screenshotUsage:i,transportType:o}){const c=a.useRef(null),u=a.useRef(null),d=a.useRef(null),[x,l]=a.useState(null),[f,b]=a.useState(""),[,p]=a.useState(!1),[S,m]=a.useState([]),h=a.useRef(0),[y,g]=a.useState(!1),[v,K]=a.useState(!1),N=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[j,k]=a.useState(N?"mouse":"touch"),[w,L]=a.useState(1),M=a.useRef(!1),[$,U]=a.useState(1),[D,_]=a.useState(0),[W,E]=a.useState(0);hs("RemoteView",{connState:r,hasScreenshot:!!n,inputMode:j,zoom:$,panX:D,panY:W,isMenuOpen:y,isImeOpen:v});const H=a.useRef(0),X=a.useRef($),O=a.useRef(D),P=a.useRef(W);a.useEffect(()=>{X.current=$},[$]),a.useEffect(()=>{O.current=D},[D]),a.useEffect(()=>{P.current=W},[W]),a.useEffect(()=>{var Q;(Q=c.current)==null||Q.focus()},[]);const R=r==="connected",F=n,Y=R?"Connected. Waiting for first frame...":r==="connecting"?"Connecting to Host...":"Reconnecting to Host...",me=R?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!N||M.current||!F)return;const Q=d.current,ie=u.current;if(!Q||!ie)return;const ee=()=>{const ge=ie.clientWidth,C=ie.clientHeight,ne=Q.naturalWidth,ve=Q.naturalHeight;if(!ne||!ve||!ge||!C)return;const B=Math.min(ge/ne,C/ve),re=Math.max(ge/ne,C/ve)/B;re>1.01&&(L(re),U(re),X.current=re),M.current=!0};Q.complete&&Q.naturalWidth?ee():Q.addEventListener("load",ee,{once:!0})},[F,N]);const _e=.5;a.useEffect(()=>{$<=_e&&(_(0),E(0))},[$,_e]);const G=(Q,ie,ee)=>{if(ee<=_e)return{x:0,y:0};const ge=(ee-1)/(2*ee)*100,C=(ee-1)/(2*ee)*100;return{x:Math.max(-ge,Math.min(ge,Q)),y:Math.max(-C,Math.min(C,ie))}},le=(Q,ie)=>{if(!d.current)return null;const ee=d.current.getBoundingClientRect();return!ee.width||!ee.height?null:{nx:Math.max(0,Math.min(1,(Q-ee.left)/ee.width)),ny:Math.max(0,Math.min(1,(ie-ee.top)/ee.height))}},J=(Q,ie,ee)=>{const ge=u.current;if(!ge)return;const C=ge.getBoundingClientRect(),ne=++h.current;m(ve=>[...ve,{id:ne,x:Q-C.left,y:ie-C.top,type:ee}]),setTimeout(()=>m(ve=>ve.filter(B=>B.id!==ne)),600)},he=(Q,ie,ee)=>{const ge=d.current,C=u.current;if(!ge||!C)return;const ne=ge.getBoundingClientRect(),ve=C.getBoundingClientRect(),B=ge.naturalWidth||ne.width,Z=ge.naturalHeight||ne.height,re=B/Z,je=ne.width/ne.height;let ke,Pe,Be,We;re>je?(ke=ne.width,Pe=ne.width/re,Be=0,We=(ne.height-Pe)/2):(Pe=ne.height,ke=ne.height*re,Be=(ne.width-ke)/2,We=0);const Fe=ne.left-ve.left+Be+ke*Q,Qe=ne.top-ve.top+We+Pe*ie,Ge=++h.current;m(q=>[...q,{id:Ge,x:Fe,y:Qe,type:ee}]),setTimeout(()=>m(q=>q.filter(z=>z.id!==Ge)),600)},te=async Q=>{var ee;const ie=le(Q.clientX,Q.clientY);if(ie){l(`Click: ${Math.round(ie.nx*100)}%, ${Math.round(ie.ny*100)}%`),J(Q.clientX,Q.clientY,"left"),(ee=c.current)==null||ee.focus();try{const ge=await t("input_click",{nx:ie.nx,ny:ie.ny});ge!=null&&ge.success||s(`❌ Click failed: ${ge==null?void 0:ge.error}`)}catch(ge){s(`❌ Click error: ${ge.message||ge}`)}}},fe=async(Q,ie,ee,ge=0)=>{try{await t("input_key",{type:ee?"char":"keyDown",key:Q,code:ie,text:ee?Q:void 0,unmodifiedText:ee?Q:void 0,modifiers:ge})}catch(C){s(`❌ Key error: ${C.message||C}`)}},ye=async Q=>{if(Q.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(Q.key)&&Q.preventDefault();let ee=0;Q.altKey&&(ee|=1),Q.ctrlKey&&(ee|=2),Q.metaKey&&(ee|=4),Q.shiftKey&&(ee|=8),l(`Key: ${Q.key}`),await fe(Q.key,Q.code,Q.key.length===1,ee)},oe=async Q=>{if(Q.key==="Enter"){if(Q.nativeEvent.isComposing)return;if(f){const ie=f;b(""),l(`IME Sent: ${ie}`);try{const ee=await t("input_type",{text:ie});ee!=null&&ee.success||s(`❌ IME error: ${ee==null?void 0:ee.error}`)}catch(ee){s(`❌ IME error: ${ee.message}`)}}else l("Key: Enter"),await fe("Enter","Enter",!1)}};a.useEffect(()=>{const Q=c.current;if(!Q)return;const ie=ee=>{var ge;if((ge=d.current)!=null&&ge.contains(ee.target)){ee.preventDefault();const C=Date.now();if(C-H.current<40)return;H.current=C;const ne=le(ee.clientX,ee.clientY);if(!ne)return;l(`Scroll: ${Math.round(ee.deltaY)}`),t("input_wheel",{nx:ne.nx,ny:ne.ny,deltaX:Math.round(ee.deltaX),deltaY:Math.round(ee.deltaY)}).catch(()=>{})}};return Q.addEventListener("wheel",ie,{passive:!1}),()=>Q.removeEventListener("wheel",ie)},[t]);const{cursorPos:de,handleToggleInputMode:ue,handleZoomReset:Ce}=lo({containerRef:c,viewportRef:u,imgRef:d,inputMode:j,setInputMode:k,minZoom:_e,zoomRef:X,panXRef:O,panYRef:P,setPanX:_,setPanY:E,setZoom:U,lastWheelTimeRef:H,onAction:t,setLastActionStatus:l,spawnRippleFromNormalized:he,clampPan:G,isMobile:N,mobileFillZoom:w});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:ye,onContextMenu:Q=>Q.preventDefault(),onFocus:()=>p(!0),onBlur:()=>p(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[F?e.jsx("img",{ref:d,src:F,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${$}) translate(${D}%, ${W}%)`,transformOrigin:"center center",cursor:j==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:te,onContextMenu:Q=>Q.preventDefault(),onDragStart:Q=>Q.preventDefault()}):e.jsx(oo,{waitingLabel:Y,waitingHint:me,transportType:o}),j==="mouse"&&F&&e.jsx(ao,{cursorPos:de,viewportRef:u,imgRef:d}),S.map(Q=>{const ee={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[Q.type];return e.jsxs("div",{style:{position:"absolute",left:Q.x,top:Q.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${ee}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${ee}, 0.9)`,boxShadow:`0 0 12px rgba(${ee}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},Q.id)})]}),e.jsx(io,{inputMode:j,onToggleInputMode:ue,isImeOpen:v,setIsImeOpen:K,isMenuOpen:y,setIsMenuOpen:g,imeText:f,setImeText:b,handleImeSubmit:oe,isConnActive:R,zoom:$,isMobile:N,mobileFillZoom:w,onZoomOut:()=>U(Q=>Math.max(.5,Q-.25)),onZoomReset:Ce,onZoomIn:()=>U(Q=>Math.min(5,Q+.25)),transportType:o,screenshotUsage:i,lastActionStatus:x}),e.jsx("style",{children:`
6
6
  @keyframes slideUp {
7
7
  from { opacity: 0; transform: translateY(6px); }
8
8
  to { opacity: 1; transform: translateY(0); }
@@ -27,7 +27,7 @@ var ui=Object.defineProperty;var mi=(t,s,r)=>s in t?ui(t,s,{enumerable:!0,config
27
27
  }
28
28
  `})]})}function sa(t,s={}){if(!t)return"";const{suffix:r="",nowLabel:n="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return n;const u=Math.floor(c/60);if(u<60)return`${u}m${r}`;const d=Math.floor(u/60);if(d<24)return`${d}h${r}`;const x=Math.floor(d/24);return x<7?`${x}d${r}`:new Date(t).toLocaleDateString()}const ra=t=>sa(t);function uo(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function qs(t){const s=t.connectionState==="failed"||t.connectionState==="closed",r=t.connectionState==="connecting"||t.connectionState==="new",n=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:r,isGenerating:n,isWaiting:i}}function bs(t){const s=new Map,r=(n,i)=>{n&&s.set(n,{sessionId:n,...uo(i)})};for(const n of t)if(!n.daemonMode){r(n.sessionId,n);for(const i of n.childSessions||[])r(i.id,i)}return s}function ds(t,s){if(t.sessionId){const r=s.get(t.sessionId);if(r)return r}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function us(t,s,r){const n=ds(t,s),i=qs(t),o=i.isReconnecting,c=i.isConnecting,u=i.isGenerating,d=i.isWaiting,x=n.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||d,l=n.inboxBucket==="working"||u,f=n.inboxBucket==="task_complete"&&n.unread&&!(r!=null&&r.hideOpenTaskCompleteUnread&&(r!=null&&r.isOpenConversation));return{unread:f,requiresAction:x,isWorking:l,isReconnecting:o,isConnecting:c,isGenerating:u,isWaiting:d,inboxBucket:x?"needs_attention":l?"working":f?"task_complete":"idle"}}function mo(t,s,r){return us(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:r==null?void 0:r.isOpenConversation}).unread}function po(t,s,r){return ds(t,r||new Map).surfaceHidden}function na({activeConv:t,onModalButton:s}){const[r,n]=a.useState(null);if(a.useEffect(()=>{n(null)},[t.modalMessage,t.status,t.connectionState]),!qs(t).isWaiting||!t.modalButtons)return null;const o=u=>{r||(n(u),s(u))},c=u=>u.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"text-white py-2.5 px-4 shrink-0 z-[5]",style:{background:"linear-gradient(135deg, var(--status-warning), color-mix(in srgb, var(--status-warning) 85%, #000))"},children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Fs,{size:14})," ",r?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((u,d)=>{const x=c(u).toLowerCase(),l=/^(run|approve|accept|yes|allow|always)/.test(x),f=/^(reject|deny|delete|remove|abort)/.test(x),b=r===u,p=r!==null;return e.jsx("button",{onClick:()=>o(u),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${l?"bg-white font-extrabold":f?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!b?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:l?{color:"var(--status-warning)"}:void 0,children:b?"⏳ ...":c(u)},d)})})]})]})}const tn=new Map,fo={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function xo({ideId:t,sessionId:s,ideType:r,providerType:n,displayLabel:i,controls:o,controlValues:c,serverModel:u,serverMode:d}){const{sendCommand:x}=Pt(),l=`${t}:${s||n}`,f=fo[n]||"#94a3b8",[b,p]=a.useState({}),S=a.useRef(0),m={...u?{model:u}:{},...d?{mode:d}:{},...c||{},...Date.now()<S.current?b:{}};a.useEffect(()=>{c&&Date.now()>S.current&&p({})},[c]);const[h,y]=a.useState(tn.get(l)||{}),[g,v]=a.useState(null),[K,N]=a.useState(null),j=a.useCallback(async(_,W={})=>{const E={...W,...s&&{targetSessionId:s}};return await x(t,_,E)},[t,s,x]),k=a.useCallback(async(_,W={},E)=>{try{const H=await j("invoke_provider_script",{agentType:n,ideType:r,scriptName:_,...W});return(H==null?void 0:H.success)===!1&&E?await j(E,{agentType:n,ideType:r,...W}):H}catch(H){if(!E)throw H;return await j(E,{agentType:n,ideType:r,...W})}},[j,n,r]);if(!o||o.length===0)return null;const w=o.filter(_=>_.placement==="bar").sort((_,W)=>(_.order??50)-(W.order??50));if(w.length===0)return null;const L=async _=>{var E,H,X;if(g===_.id){v(null);return}if((((E=_.options)==null?void 0:E.map(O=>O.value))||h[_.id]||[]).length>0){v(_.id);return}if(_.dynamic&&_.listScript){N(_.id);try{const O=vs(_.listScript),P=await k(_.listScript,{},O),F=((P==null?void 0:P.models)||(P==null?void 0:P.modes)||((H=P==null?void 0:P.result)==null?void 0:H.models)||((X=P==null?void 0:P.result)==null?void 0:X.modes)||(P==null?void 0:P.options)||[]).map(Y=>typeof Y=="string"?Y:(Y==null?void 0:Y.name)||(Y==null?void 0:Y.id)||(Y==null?void 0:Y.value)||String(Y));y(Y=>{const me={...Y,[_.id]:F};return tn.set(l,me),me}),v(_.id)}catch{}finally{N(null)}}},M=async(_,W)=>{v(null),p(E=>({...E,[_.id]:W})),S.current=Date.now()+5e3;try{if(!_.setScript)return;await k(_.setScript,{model:_.id==="model"?W:void 0,mode:_.id==="mode"?W:void 0,value:W},vs(_.setScript))}catch{}},$=async _=>{var P;const W=((P=_.options)==null?void 0:P.map(R=>R.value))||h[_.id]||[];if(W.length===0)return;const E=String(m[_.id]||""),X=(W.indexOf(E)+1)%W.length,O=W[X];if(typeof O=="string"){p(R=>({...R,[_.id]:O})),S.current=Date.now()+5e3;try{if(!_.setScript)return;await k(_.setScript,{value:O},vs(_.setScript))}catch{}}},U=async _=>{const E=!m[_.id];p(H=>({...H,[_.id]:E})),S.current=Date.now()+5e3;try{if(!_.setScript)return;await k(_.setScript,{value:E},vs(_.setScript))}catch{}},D=async _=>{if(_.invokeScript)try{await k(_.invokeScript)}catch{}};return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-surface-primary font-[var(--font)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide opacity-70",style:{color:f},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),w.map(_=>{var O;const W=String(m[_.id]||""),E=g===_.id,H=K===_.id,X=((O=_.options)==null?void 0:O.map(P=>P.value))||h[_.id]||[];switch(_.type){case"select":return e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:E?`${f}55`:"transparent",border:"1px solid",color:W?"var(--text-primary)":"var(--text-muted)"},onClick:()=>L(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),H?"...":W||_.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),E&&X.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>v(null)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:_.label.toUpperCase()}),X.map(P=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:P===W?`${f}18`:"transparent",color:P===W?f:"var(--text-secondary)",fontWeight:P===W?600:400,borderLeft:P===W?`2px solid ${f}`:"2px solid transparent"},onMouseEnter:R=>{R.currentTarget.style.background=`${f}12`},onMouseLeave:R=>{R.currentTarget.style.background=P===W?`${f}18`:"transparent"},onClick:()=>M(_,P),children:P},P))]})]})]},_.id);case"cycle":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap",style:{border:"1px solid transparent",color:W?"var(--text-primary)":"var(--text-muted)"},onClick:()=>$(_),title:`Click to cycle: ${X.join(" → ")}`,children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),W||_.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"⟳"})]},_.id);case"toggle":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all whitespace-nowrap",style:{border:"1px solid",borderColor:W?`${f}44`:"transparent",background:W?`${f}14`:"var(--surface-tertiary)",color:W?f:"var(--text-muted)"},onClick:()=>U(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),_.label]},_.id);case"action":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all hover:bg-[var(--surface-tertiary-hover)] whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:"var(--text-primary)"},onClick:()=>D(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),_.resultDisplay==="inline"&&W?`${_.label}: ${W}`:_.label]},_.id);case"display":return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium whitespace-nowrap",style:{border:"1px solid var(--border-default)",background:"var(--surface-tertiary)",color:W?"var(--text-primary)":"var(--text-muted)"},children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),W?`${_.label}: ${W}`:_.label]},_.id);default:return null}})]})}function vs(t){return{setModel:"set_extension_model",setMode:"set_extension_mode",listModels:"list_extension_models",listModes:"list_extension_modes",setThinkingLevel:"set_thought_level"}[t]}const ho=a.memo(function({contextKey:s,panelLabel:r,isSending:n,onSend:i,isActive:o=!0}){const c=a.useRef(null),[u,d]=a.useState("");a.useEffect(()=>{d("")},[s]),a.useEffect(()=>{var l;o&&((l=c.current)==null||l.focus())},[s,o]);const x=()=>{const l=u.trim();!l||n||(d(""),i(l))};return e.jsx("div",{className:"dashboard-input-area bg-[var(--surface-primary)] shrink-0 overflow-hidden transition-all duration-200 ease-out",style:{borderTop:o?"1px solid var(--border-subtle)":"1px solid transparent",maxHeight:o?72:0,opacity:o?1:0,transform:o?"translateY(0)":"translateY(10px)",padding:o?"10px 12px":"0 12px",pointerEvents:o?"auto":"none"},"aria-hidden":!o,children:e.jsxs("div",{className:"flex gap-2.5 items-center",title:o?`Send message to ${r}`:void 0,children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${r}...`,value:u,onChange:l=>d(l.target.value),onPaste:l=>{const f=l.clipboardData.getData("text");f&&d(b=>b+f),l.preventDefault()},onKeyDown:l=>{if(l.key==="Enter"){if(l.nativeEvent.isComposing){l.preventDefault();return}l.preventDefault(),x()}},onBlur:l=>{if(window.innerWidth<768){const f=l.relatedTarget;if((f==null?void 0:f.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:x,disabled:!u.trim()||n,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${u.trim()&&!n?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:u.trim()&&!n?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:u.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var bo=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function go(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function lt(t,s){if(go(s==null?void 0:s.activeModal))return"waiting_approval";const r=String(t||"idle").trim().toLowerCase();return r==="waiting_approval"?"waiting_approval":bo.has(r)?"generating":r==="error"?"error":r==="stopped"?"stopped":r==="starting"?"starting":r==="panel_hidden"?"panel_hidden":r==="not_monitored"?"not_monitored":r==="disconnected"?"disconnected":"idle"}function aa(t){return lt(t)==="generating"}function qe(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function yo(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const r=Math.floor(s/60),n=s%60;if(r<24)return n>0?`${r}h ${n}m`:`${r}h`;const i=Math.floor(r/24),o=r%24;return`${i}d ${o}h`}function sn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gs(t,s){const r=typeof s=="string"?s.trim():"";if(r)return r;const n=typeof t=="string"?t.trim():"";if(!n)return"";const i=n.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function vo(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),r=s[s.length-1];return r.length>12?`Machine-${r.substring(0,8)}`:r}return t}function wo(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function jo(t){return vo(t.trim().replace(/\.local$/i,""))}function ko(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function ia(t,s={}){var i,o;const r=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0&&!wo(c));if(r&&r!=="Unknown")return jo(r);const n=s.fallbackId||t.id;return n?`Machine-${n.substring(0,8)}`:s.fallbackLabel||"Machine"}function gt(t,s={}){return ko(t)||ia(t,s)}function ms(t){return t.transport==="pty"}function Xt(t){return t.transport==="acp"}function rn(t,s){return qe(t)}function nn(t,s,r){const n=(t||"").trim().toLowerCase();if(!n)return!0;const i=(s||"").trim().toLowerCase(),o=(r||"").trim().toLowerCase(),c=qe(r||"").trim().toLowerCase();return n===i||n===o||n===c}function No(t){return lt(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function So(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,r=["generating","waiting_approval","connected","idle","panel_hidden"];for(const n of t){const i=(n.name||n.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=lt(n.status);if(!o){s.set(i,{...n,status:c});continue}const u=r.indexOf(o.status||"idle"),d=r.indexOf(c||"idle");d>=0&&(u<0||d<u)&&s.set(i,{...n,status:c})}return Array.from(s.values())}function rr(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function Co(t){var r,n;const s=(n=(r=t==null?void 0:t.messages)==null?void 0:r.at)==null?void 0:n.call(r,-1);return s&&(rr(s.timestamp)||rr(s.receivedAt)||rr(s.createdAt))||0}function Io(t){return(t.recentLaunches||[]).reduce((r,n)=>Math.max(r,n.lastLaunchedAt||0),0)}function hr(t){return Math.max(Io(t),Co(t.activeChat))}function To(t,s,r,n,i,o){const c=s-t;if(c!==0)return c;const u=r.localeCompare(n);return u!==0?u:i.localeCompare(o)}function Ar(t,s){return To(hr(t),hr(s),gt(t,{fallbackId:t.id}),gt(s,{fallbackId:s.id}),t.id,s.id)}function oa({conversation:t,className:s="",onOpenNativeConversation:r,onOpenMachine:n,interactive:i=!0}){var S;const o=ts(),c=t.daemonId||((S=t.ideId)==null?void 0:S.split(":")[0])||t.ideId,u=t.transport==="cdp-page"||t.transport==="cdp-webview",d=t.streamSource==="agent-stream"&&!!t.agentName,x=!d&&(t.transport==="pty"||t.transport==="acp"),l=t.agentName||qe(t.agentType||t.ideType||""),f=(()=>{var m,h;if(t.streamSource==="agent-stream"){const y=(h=(m=t.displaySecondary)==null?void 0:m.split("·")[0])==null?void 0:h.trim();if(y)return y}return qe(t.ideType||"")})(),b=a.useCallback(()=>{if(n){n();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,n]),p=a.useCallback(()=>{if(r){r();return}const m=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;m&&o(`/dashboard?activeTab=${encodeURIComponent(m)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,r]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[u&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:f,children:[e.jsx(ct,{size:12}),e.jsx("span",{children:f})]}):e.jsxs("span",{className:"conversation-meta-chip",title:f,children:[e.jsx(ct,{size:12}),e.jsx("span",{children:f})]})),d&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(Ot,{size:12}),e.jsx("span",{children:t.agentName})]}),x&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:l,children:[e.jsx(Ot,{size:12}),e.jsx("span",{children:l})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:b,title:t.machineName,children:[e.jsx(Ds,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(Ds,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Ye=t=>t.transport==="pty",es=(t,s)=>Ye(t)?s||t.mode||"terminal":"chat",ca=(t,s)=>Ye(t)&&es(t,s)==="terminal",ze=t=>t.transport==="acp";function Ks(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
29
29
  `).replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}function zt(t){const s=Number((t==null?void 0:t.timestamp)||(t==null?void 0:t.receivedAt)||(t==null?void 0:t.createdAt)||0);return Number.isFinite(s)?s:0}function an(t){return[...t].sort((s,r)=>{const n=zt(s),i=zt(r);return n&&i&&n!==i?n-i:0})}function Ao(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const r=String((t==null?void 0:t.role)||"").toLowerCase(),n=String((s==null?void 0:s.role)||"").toLowerCase();if(r!==n)return!1;const i=Ks(t==null?void 0:t.content),o=Ks(s==null?void 0:s.content);if(!i||i!==o)return!1;const c=zt(t),u=zt(s);return c&&u?Math.abs(c-u)<=15e3:!!(t!=null&&t._localId)!=!!(s!=null&&s._localId)}function on(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),zt(t)&&(s+=1),s}function _o(t,s){const r=on(t),n=on(s);return n!==r?n>r?s:t:Ks(s==null?void 0:s.content).length>=Ks(t==null?void 0:t.content).length?s:t}function cn(t){const s=[];for(const r of t){const n=s.findIndex(i=>Ao(i,r));if(n>=0){s.splice(n,1,_o(s[n],r));continue}s.push(r)}return s}const Mo=60,Po=60;function br({activeConv:t,ideEntry:s,handleSendChat:r,isSendingChat:n=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:u,showMetaChips:d=!1,scrollToBottomRequestNonce:x,isInputActive:l=!0}){const f=a.useRef(new Map),{sendCommand:b}=Pt();hs("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:n});const p=Ze.useMemo(()=>qs(t),[t.status,t.connectionState]),S=a.useRef(new Map),m=a.useCallback(E=>(S.current.has(E)||S.current.set(E,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Mo}),S.current.get(E)),[]),h=a.useCallback((E,H)=>{const X=m(E);S.current.set(E,{...X,...H}),y(O=>O+1)},[m]),[,y]=a.useState(0),g=t.tabKey,v=m(g),K=v.messages,N=v.hasMore,j=v.error,k=Math.max(0,t.messages.length-v.visibleLiveCount),[w,L]=a.useState(!1),M=a.useCallback(async()=>{var X,O;if(w)return;const E=t.tabKey,H=m(E);if(t.messages.length>H.visibleLiveCount){h(E,{visibleLiveCount:Math.min(t.messages.length,H.visibleLiveCount+Po),error:null});return}L(!0),h(E,{error:null});try{const P=(s==null?void 0:s.daemonId)||((X=t.ideId)==null?void 0:X.split(":")[0])||"";if(!P){h(E,{hasMore:!1});return}const R=t.ideType||t.agentType||"",F=await b(P,"chat_history",{agentType:R,offset:H.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),Y=(F==null?void 0:F.result)??F;if(((O=Y.messages)==null?void 0:O.length)>0){const me=m(E);h(E,{messages:[...Y.messages,...me.messages],offset:me.offset+Y.messages.length,hasMore:!!Y.hasMore})}else h(E,{hasMore:!!Y.hasMore})}catch(P){const R=(P==null?void 0:P.message)||"";R.includes("P2P not available")||R.includes("channel not open")||R.includes("P2P not connected")||R.includes("timeout")?h(E,{error:"Connection not ready — tap to retry"}):h(E,{hasMore:!1,error:"Failed to load history"})}finally{L(!1)}},[w,s,t,b,m,h]),{allMessages:$,receivedAtMap:U}=a.useMemo(()=>{const E=k>0?t.messages.slice(-v.visibleLiveCount):t.messages;if(K.length===0){const R=an(cn(E)),F={};return R.forEach((Y,me)=>{const _e=`${t.tabKey}:${Yt(Y,me)}`;let G=zt(Y)||f.current.get(_e)||0;G||(G=Date.now(),f.current.set(_e,G)),F[Yt(Y,me)]=G}),{allMessages:R,receivedAtMap:F}}const H=new Set(E.map(R=>`${R.role}:${(R.content||"").slice(0,100)}`)),X=K.filter(R=>!H.has(`${R.role}:${(R.content||"").slice(0,100)}`)),O=an(cn([...X,...E])),P={};return O.forEach((R,F)=>{const Y=`${t.tabKey}:${Yt(R,F)}`;let me=zt(R)||f.current.get(Y)||0;me||(me=Date.now(),f.current.set(Y,me)),P[Yt(R,F)]=me}),{allMessages:O,receivedAtMap:P}},[t.messages,t.tabKey,k,K,v.visibleLiveCount]),D=a.useMemo(()=>c.filter(E=>E.ideId===t.tabKey).sort((E,H)=>E.timestamp-H.timestamp),[c,t.tabKey]),_=t.displayPrimary||t.agentName||"Agent",W=a.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if((p.isGenerating||t.status==="streaming")&&L(!1),t.status==="not_monitored")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(Ot,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qt,{size:14})," Open ",_," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(Jn,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:i,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qt,{size:14})," Open ",_," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]});if(t.status==="idle"&&!w)return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]})}},[t.messages.length,t.connectionState,t.status,i,o,w,_,p.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[d&&e.jsx(oa,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(to,{messages:$,actionLogs:D,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:Ye(t)||ze(t),isWorking:p.isGenerating,contextKey:t.tabKey,receivedAtMap:U,onLoadMore:M,isLoadingMore:w,hasMoreHistory:N,hiddenLiveCount:k,loadError:j??void 0,emptyState:W,scrollToBottomRequestNonce:x}),l&&!ca(t)&&(()=>{const E=t.streamSource!=="agent-stream",H=E?t.ideType:t.agentType,X=E?s!=null&&s.type?qe(s.type):qe(t.ideType||""):t.agentName||qe(t.agentType||""),O=!E&&(s!=null&&s.childSessions)&&s.childSessions.find(F=>F.id===t.sessionId||F.providerType===t.agentType)||s,P=O==null?void 0:O.providerControls,R=O==null?void 0:O.controlValues;return e.jsx(xo,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:H,displayLabel:X,controls:P,controlValues:R,serverModel:(O==null?void 0:O.currentModel)||void 0,serverMode:(O==null?void 0:O.currentPlan)||void 0,acpConfigOptions:ze(t)?O==null?void 0:O.acpConfigOptions:void 0,acpModes:ze(t)?O==null?void 0:O.acpModes:void 0})})(),e.jsx(ho,{contextKey:t.tabKey,panelLabel:_,isSending:n,onSend:r,isActive:l})]})}let la=Zt;function _r(){return la()}class Lo{constructor(){tt(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,r){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(r),()=>{var n;(n=this.listeners.get(s))==null||n.delete(r)}}emit(s,...r){var n;(n=this.listeners.get(s))==null||n.forEach(i=>i(...r))}}let da=new Lo;class Ro{sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,r){return!1}get(s){}onScreenshot(s,r){return()=>{}}onRuntimeEvent(s,r){return()=>{}}requestRuntimeSnapshot(s,r){return Promise.resolve()}}let Je=new Ro;function Eo(t){t.dashboardWS&&(da=t.dashboardWS),t.connectionManager&&(Je=t.connectionManager),t.useDaemonsHook&&(la=t.useDaemonsHook)}function $o({activeConv:t,clearToken:s=0,terminalRef:r,handleSendChat:n,isSendingChat:i=!1,isVisible:o=!0}){var P;const{ides:c}=Zt(),u=a.useRef(null),{sendCommand:d,sendData:x}=Pt(),[l,f]=a.useState(""),[b,p]=a.useState(!1),[S,m]=a.useState(1),h=a.useRef(!1),y=a.useRef(0),g=a.useRef(!1),v=a.useRef(""),K=a.useRef(null),N=a.useRef(!1),j=a.useRef(null),k=t.tabKey,w=t.sessionId||"",L=t.daemonId||((P=t.ideId)==null?void 0:P.split(":")[0])||t.ideId||"",M=c.find(R=>R.id===L&&R.daemonMode),$=(M==null?void 0:M.terminalSizingMode)==="fit"?"fit":"measured",U=.6,D=1.15,_=()=>{if(typeof window>"u")return 1;const R=window.innerWidth||0;return R<=360?.68:R<=390?.74:R<=430?.82:R<=480?.9:1},W=()=>{var R,F;y.current=0,g.current=!1,v.current="",K.current=null,N.current=!1,j.current!==null&&(cancelAnimationFrame(j.current),j.current=null),p(!1),(F=(R=r.current)==null?void 0:R.reset)==null||F.call(R)},E=()=>{var R,F;y.current=0,g.current=!1,v.current="",K.current=null,N.current=!1,j.current!==null&&(cancelAnimationFrame(j.current),j.current=null),p(!0),(F=(R=r.current)==null?void 0:R.reset)==null||F.call(R)},H=()=>{var F;if(j.current=null,!o)return;const R=v.current;R&&(v.current="",(F=r.current)==null||F.write(R))},X=R=>{R&&(v.current+=R,o&&j.current===null&&(j.current=requestAnimationFrame(H)))},O=(R,F=0,Y,me)=>{var _e,G,le,J,he;F>0&&y.current>=F||F===0&&g.current||(y.current=F,p(!0),typeof Y=="number"&&typeof me=="number"&&Y>0&&me>0&&((G=(_e=r.current)==null?void 0:_e.resize)==null||G.call(_e,Y,me)),(J=(le=r.current)==null?void 0:le.reset)==null||J.call(le),R&&((he=r.current)==null||he.write(R)))};return a.useEffect(()=>{W()},[w]),a.useEffect(()=>{var F;if(!w)return;const R=((F=Je.onRuntimeEvent)==null?void 0:F.call(Je,w,Y=>{if(!(!Y||Y.sessionId!==w)){if(Y.type==="runtime_snapshot"){if(!o){K.current={text:Y.text||"",seq:Y.seq||0,cols:Y.cols,rows:Y.rows};return}O(Y.text||"",Y.seq||0,Y.cols,Y.rows);return}if(Y.type==="session_output"){g.current=!0,typeof Y.seq=="number"&&(y.current=Math.max(y.current,Y.seq)),b||p(!0),typeof Y.data=="string"&&X(Y.data);return}if(Y.type==="session_cleared"){if(!o){N.current=!0,v.current="",K.current=null;return}E()}}}))||(()=>{});return()=>{R()}},[L,w,r,o,b]),a.useEffect(()=>{var F,Y,me;if(!w)return;L&&((F=Je.getState)==null?void 0:F.call(Je,L))==="connected"&&(p(!0),(Y=Je.requestRuntimeSnapshot)==null||Y.call(Je,L,w).catch(()=>{}));const R=(me=Je.onStateChange)==null?void 0:me.call(Je,(_e,G)=>{var le;_e!==L||G!=="connected"||(p(!0),(le=Je.requestRuntimeSnapshot)==null||le.call(Je,L,w).catch(()=>{}))});return()=>{R==null||R()}},[L,w,r]),a.useEffect(()=>{s&&W()},[s,k,r]),a.useEffect(()=>{f("")},[t.tabKey]),a.useEffect(()=>{const R=()=>{h.current||m(_())};return R(),window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[]),a.useEffect(()=>{var F;if(!o){(F=u.current)==null||F.blur();return}N.current&&(N.current=!1,E());const R=K.current;R&&(K.current=null,O(R.text,R.seq,R.cols,R.rows)),v.current&&j.current===null&&(j.current=requestAnimationFrame(H)),requestAnimationFrame(()=>{var Y;(Y=r.current)==null||Y.bumpResize()})},[o]),a.useEffect(()=>()=>{j.current!==null&&(cancelAnimationFrame(j.current),j.current=null)},[]),a.useEffect(()=>{const R=F=>{var me;const Y=F.detail;Y!=null&&Y.sessionId&&Y.sessionId!==w||b&&((me=r.current)==null||me.bumpResize())};return window.addEventListener("adhdev:fit-cli-terminal",R),()=>{window.removeEventListener("adhdev:fit-cli-terminal",R)}},[b,w,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117] relative",children:[e.jsxs("div",{className:"absolute right-3 top-3 z-10 flex items-center gap-1.5",children:[e.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:()=>{h.current=!0,m(R=>Math.max(U,Number((R-.1).toFixed(2))))},title:"Shrink terminal viewport",children:"-"}),e.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:()=>{h.current=!0,m(R=>Math.min(D,Number((R+.1).toFixed(2))))},title:"Increase terminal viewport",children:"+"})]}),e.jsx("div",{className:"w-full h-full overflow-auto rounded-lg",children:e.jsx("div",{style:{width:`${100/S}%`,height:`${100/S}%`,transform:`scale(${S})`,transformOrigin:"top left"},children:e.jsx(ea,{ref:r,readOnly:!b||!o,sizingMode:$,onInput:R=>{b&&(x!=null&&x(L,{type:"pty_input",targetSessionId:w,data:R})||d(L,"pty_input",{targetSessionId:w,data:R}).catch(console.error))}})})}),!b&&e.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:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:u,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:l,disabled:!b||!o||i,onChange:R=>f(R.target.value),onPaste:R=>{const F=R.clipboardData.getData("text");F&&f(Y=>Y+F),R.preventDefault()},onKeyDown:R=>{if(R.key!=="Enter")return;if(R.nativeEvent.isComposing){R.preventDefault();return}R.preventDefault();const F=l.trim();!b||!F||i||(f(""),n(F))},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:()=>{const R=l.trim();!b||!R||i||(f(""),n(R))},disabled:!b||!o||!l.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.trim()&&!i?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:l.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Do({wsStatus:t,showReconnected:s,loginUrl:r}){const n=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"accent",o={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))"},c={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)"},u={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:u[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(r?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:r,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 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-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function Bo({terminalBackend:t,isStandalone:s=!1,machineLabel:r,machineKey:n}){const i=a.useMemo(()=>!n||!t?null:`adhdev:terminal-backend-banner:dismissed:${n}:${t.backend}`,[n,t]),[o,c]=a.useState(!1);if(a.useEffect(()=>{if(!i){c(!1);return}try{c(localStorage.getItem(i)==="1")}catch{c(!1)}},[i]),!s||!t||t.backend!=="xterm"||o)return null;const u=(r==null?void 0:r.trim())||"This machine",d=()=>{if(i)try{localStorage.setItem(i,"1")}catch{}c(!0)};return e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5",style:{background:"linear-gradient(90deg, rgba(245,158,11,0.12), rgba(245,158,11,0.04))",borderBottom:"1px solid rgba(245,158,11,0.2)",color:"#d97706"},children:[e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2.5 justify-center flex-wrap",children:[e.jsxs("span",{children:[u," is using `xterm` fallback."]}),e.jsx("span",{style:{opacity:.8},children:"ghostty-vt is unavailable on this machine, so terminal rendering may be less accurate."})]}),e.jsx("button",{type:"button",onClick:d,className:"shrink-0 text-[12px] font-semibold px-2 py-1 rounded-md transition-colors",style:{color:"#b45309",background:"rgba(245,158,11,0.1)",border:"1px solid rgba(245,158,11,0.18)"},"aria-label":"Dismiss terminal backend warning",title:"Dismiss",children:"Dismiss"})]})}function Mr({mode:t,onChange:s,compact:r=!1}){const n=r?14:15;return e.jsx("button",{type:"button",onClick:()=>s(t==="chat"?"terminal":"chat"),className:"btn btn-sm btn-secondary",title:t==="chat"?"Switch to Terminal view":"Switch to Chat view",children:t==="chat"?e.jsx(Ir,{size:n}):e.jsx(Nt,{size:n})})}function ln({conversation:t,isAttention:s,shortcutIndex:r,onClick:n}){const i=[t.displaySecondary,t.machineName].filter(Boolean);return e.jsxs("button",{type:"button",className:`dashboard-header-inbox-item ${s?"is-attention":""}`.trim(),onClick:n,children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:t.displayPrimary}),(r||i.length>0)&&e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[r?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",r]}):null,i.join(" · ")]})]})}function Ko({activeConv:t,agentCount:s,wsStatus:r,isConnected:n,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:u,activeCliViewMode:d,onSetCliViewMode:x,onOpenConversation:l,onHideConversation:f,hiddenConversations:b=[],onShowConversation:p,onShowAllHidden:S,inboxOpen:m,onInboxOpenChange:h,hiddenOpen:y,onHiddenOpenChange:g,onOpenNewSession:v}){const K=_r(),N=K.p2pStates||{},j=K.ides||[],k=!!t&&Ye(t)&&!ze(t),w=d||(t?ca(t)?"terminal":"chat":null),[L,M]=a.useState(!1),$=a.useRef(null),U=a.useRef(null),D=n?"#22c55e":r==="connected"?"#eab308":"#ef4444",_=n?"0 0 4px #22c55e80":r==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",W=j.filter(J=>J.type==="adhdev-daemon"),E=a.useMemo(()=>bs(j),[j]),H=Object.values(N),X=H.filter(J=>J==="connected").length,O=H.filter(J=>J==="connecting"||J==="new"||J==="checking").length,R=r!=="connected"||W.length===0?null:O>0&&X===0?"P2P connecting...":X>0&&s===0?"Waiting for IDE...":null,F=a.useMemo(()=>i.filter(J=>!po(J,i,E)),[i,E]),Y=a.useMemo(()=>F.filter(J=>us(J,E).requiresAction),[F,E]),me=a.useMemo(()=>F.filter(J=>{const he=(t==null?void 0:t.tabKey)===J.tabKey;return us(J,E,{hideOpenTaskCompleteUnread:!0,isOpenConversation:he}).unread}),[t,F,E]),_e=a.useMemo(()=>[...Y,...me].slice(0,9),[Y,me]),G=Y.length+me.length;a.useEffect(()=>{if(!m)return;const J=he=>{var te;(te=$.current)!=null&&te.contains(he.target)||h(!1)};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[m,h]),a.useEffect(()=>{if(!y)return;const J=he=>{var te;(te=U.current)!=null&&te.contains(he.target)||g(!1)};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[y,g]),a.useEffect(()=>{if(!y&&!m)return;const J=he=>{if(!he.altKey)return;const te=he.code.match(/^Digit([1-9])$/);if(!te)return;const fe=Number(te[1])-1,ye=y?b[fe]:void 0,oe=m?_e[fe]:void 0,de=ye||oe;if(de){if(he.preventDefault(),he.stopPropagation(),ye){p==null||p(ye),g(!1);return}l==null||l(de),h(!1)}};return window.addEventListener("keydown",J,!0),()=>window.removeEventListener("keydown",J,!0)},[b,y,m,_e,g,h,l,p]);const le=J=>{if(!J)return;const he=i.find(te=>te.tabKey===J);he&&(f==null||f(he))};return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("div",{className:"header-title-block",children:e.jsxs("div",{className:"header-title-row",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(Nt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:D,boxShadow:_}})})]}),e.jsxs("div",{className:"header-subtitle",children:[v&&e.jsx("button",{type:"button",onClick:v,className:"btn btn-secondary btn-sm",title:"Start a new session","aria-label":"Start a new session",children:e.jsx(Ui,{size:14})}),e.jsx("span",{title:n?"Connected":r==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:D,boxShadow:_}}),R&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",R]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(k||!ze(t))&&e.jsxs("div",{className:"dashboard-header-actions-group",children:[e.jsx("span",{className:"dashboard-header-action-target",title:t.displaySecondary||t.displayPrimary,children:t.displayPrimary}),k&&u&&e.jsxs(e.Fragment,{children:[x&&w&&e.jsx(Mr,{mode:w,onChange:x,compact:!0}),e.jsx("button",{onClick:()=>u(t),className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(Ut,{size:14})})]}),!ze(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Sr,{size:14})}),!k&&!ze(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(ct,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:$,children:[e.jsxs("div",{className:`dashboard-header-hidden${L?" is-drop-target":""}`,ref:U,onDragEnter:J=>{J.dataTransfer.types.includes("text/tab-key")&&(J.preventDefault(),M(!0))},onDragOver:J=>{J.dataTransfer.types.includes("text/tab-key")&&(J.preventDefault(),J.dataTransfer.dropEffect="move",M(!0))},onDragLeave:J=>{J.currentTarget.contains(J.relatedTarget)||M(!1)},onDrop:J=>{const he=J.dataTransfer.getData("text/tab-key");J.preventDefault(),M(!1),le(he)},children:[e.jsxs("button",{type:"button",onClick:()=>g(!y),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Ki,{size:16}),b.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:b.length})]}),y&&e.jsxs("div",{className:"dashboard-header-hidden-popover",children:[e.jsxs("div",{className:"dashboard-header-hidden-topbar",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title mb-0",children:"Hidden tabs"}),b.length>0&&S&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{S(),g(!1)},children:"Restore all"})]}),t&&f&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>f(t),children:[e.jsx("span",{className:"dashboard-header-hidden-current-label",children:"Hide current tab"}),e.jsx("span",{className:"dashboard-header-hidden-current-title",children:t.displayPrimary})]}),b.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:b.map(J=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{p==null||p(J),g(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:J.displayPrimary}),e.jsxs("span",{className:"dashboard-header-inbox-item-meta",children:[b.indexOf(J)<9?e.jsxs("span",{className:"dashboard-header-item-shortcut",children:["⌥",b.indexOf(J)+1]}):null,[J.displaySecondary,J.machineName].filter(Boolean).join(" · ")]})]},J.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>h(!m),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(Vs,{size:16}),G>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:G})]}),m&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[Y.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),Y.map(J=>e.jsx(ln,{conversation:J,isAttention:!0,shortcutIndex:_e.indexOf(J)>=0?_e.indexOf(J)+1:void 0,onClick:()=>{l==null||l(J),h(!1)}},J.tabKey))]}),me.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),me.map(J=>e.jsx(ln,{conversation:J,shortcutIndex:_e.indexOf(J)>=0?_e.indexOf(J)+1:void 0,onClick:()=>{l==null||l(J),h(!1)}},J.tabKey))]}),G===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Wo(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(new Date(t))}catch{return new Date(t).toLocaleString()}}function Pr({activeConv:t,ides:s,isCreatingChat:r,isRefreshingHistory:n,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:u,onNewChat:d,onSwitchSession:x,onRefreshHistory:l,onResumeSavedSession:f}){var y;const b=s.find(g=>g.id===t.ideId),p=(b==null?void 0:b.chats)||[],S=(y=b==null?void 0:b.activeChat)==null?void 0:y.id,m=Ye(t)&&!ze(t),h=e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:u,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:m?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",qe(t.ideType)]})]}),e.jsx("button",{onClick:u,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[!m&&e.jsx("button",{onClick:d,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"}),m?e.jsx(e.Fragment,{children:i.map(g=>{const v=t.providerSessionId===g.providerSessionId,K=v||!g.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{K||!f||f(g)},disabled:K,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${v?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${K?"opacity-70 cursor-default":"cursor-pointer hover:border-[var(--accent-primary-light)]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:`font-bold text-sm mb-1 truncate ${v?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:g.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:Wo(g.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:g.preview||"No saved preview yet"}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3 text-[11px] text-text-muted",children:[e.jsxs("div",{className:"truncate",children:[g.workspace||"Workspace unknown",g.currentModel?` · ${g.currentModel}`:"",g.messageCount>0?` · ${g.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:v?"ACTIVE":g.canResume?c===g.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},g.id)})}):p.map(g=>e.jsxs("div",{onClick:()=>{x(t.ideId,g.id),u()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${S===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${S===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[g.id.substring(0,12),"..."]}),S===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),(m&&!o&&i.length===0||!m&&p.length===0)&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(Fi,{size:32})}),e.jsx("div",{className:"text-[13px]",children:m?"No saved sessions found yet.":"No recent chat sessions found."})]}),m&&o&&e.jsx("div",{className:"py-10 px-5 text-center text-text-muted",children:e.jsx("div",{className:"text-[13px]",children:"Refreshing saved sessions…"})})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:l,disabled:n||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:n||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Hs,{size:13})," ",m?"Refresh Sessions":"Refresh History"]})})})]})]});return typeof document>"u"?h:zn.createPortal(h,document.body)}const dn={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 ua({toasts:t,onDismiss:s,onClickToast:r}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(n=>{const i=dn[n.type]||dn.info;return e.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:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-[3px]",style:{background:`linear-gradient(180deg, ${i.accent}, color-mix(in srgb, ${i.accent} 55%, transparent))`}}),e.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 text-[13px] leading-none cursor-pointer",onClick:o=>{o.stopPropagation(),s(n.id)},"aria-label":"Dismiss",children:"×"}),e.jsxs("div",{className:"px-4 py-3.5 pl-5",children:[e.jsx("div",{className:"flex items-center gap-2 pr-8",children:e.jsx("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-[0.08em]",style:{background:i.chipBg,color:i.chipText,border:`1px solid color-mix(in srgb, ${i.accent} 22%, transparent)`},children:i.label})}),e.jsx("div",{className:"mt-2 text-[13px] font-semibold leading-[1.45] text-text-primary",children:n.message}),n.actions&&n.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-3",children:n.actions.map((o,c)=>e.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:u=>{u.stopPropagation(),o.onClick(),s(n.id)},children:o.label},c))})]})]},n.id)})})}function Lr(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(" ").replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}const Oo=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Uo(t){const s=t.workspace||"";if(!s)return"";const r=s.split(/[/\\]/).filter(Boolean);return r.length>0?r[r.length-1]:s}function zo(t){return t.sessionId||t.instanceId||t.agentType}function nr(t,s){return t||s}function un(t){return Lr(t)}function mn(t){const s=Number((t==null?void 0:t.timestamp)||(t==null?void 0:t.receivedAt)||(t==null?void 0:t.createdAt)||0);return Number.isFinite(s)?s:0}function pn(t,s){if(!t||!s)return!1;if(t===s||t.id&&s.id&&String(t.id)===String(s.id)||t._localId&&s._localId&&String(t._localId)===String(s._localId))return!0;const r=String(t.role||"").toLowerCase(),n=String(s.role||"").toLowerCase();if(r!==n)return!1;const i=un(t.content),o=un(s.content);if(!i||i!==o)return!1;const c=mn(t),u=mn(s);return c&&u?Math.abs(c-u)<=15e3:!!t._localId!=!!s._localId}function fn(t,s){const r=new Set,n=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;r.has(c)||(r.add(c),n.push(o))}return n.sort((i,o)=>i.timestamp-o.timestamp)}function ma(t=[]){const s={};for(const r of t){const n=r;(n.type==="adhdev-daemon"||n.daemonMode)&&(s[n.id]=gt(n,{fallbackId:n.id}))}return s}function Rr(t,s,r={}){var b,p,S,m,h,y;const n=[],i=r.machineName,o=r.connectionState,c=Uo(t),u=qe(t.type),d=Array.isArray(t.childSessions)?t.childSessions.map(g=>{var v,K;return{sessionId:g.id,instanceId:g.id,providerSessionId:g.providerSessionId,transport:g.transport,agentType:g.providerType,agentName:g.providerName,status:g.status,title:g.title,messages:((v=g.activeChat)==null?void 0:v.messages)||[],activeModal:((K=g.activeChat)==null?void 0:K.activeModal)||void 0,unread:g.unread,lastSeenAt:g.lastSeenAt,lastUpdated:g.lastUpdated,inboxBucket:g.inboxBucket,surfaceHidden:g.surfaceHidden}}):[],x=Oo(t),l=t.activeChat||{title:""},f=l.title&&String(l.title).trim()?String(l.title).trim():"";if(x){const g=t.sessionId||t.instanceId,v=rn(t.type),K=(b=t.activeChat)==null?void 0:b.activeModal,N=K&&Array.isArray(K.buttons)&&K.buttons.length>0,j=lt((p=t.activeChat)==null?void 0:p.status,{activeModal:(S=t.activeChat)==null?void 0:S.activeModal})||lt((h=(m=t.agents)==null?void 0:m[0])==null?void 0:h.status)||"idle",k=t.activeChat||{title:"",messages:[]};let w=k.title&&String(k.title).trim()?String(k.title).trim():"";const L=(y=t.activeChat)==null?void 0:y.id,M=t.chats;if(L&&Array.isArray(M)&&M.length>0){const H=M.find(X=>X.id===L||X.id&&String(X.id)===String(L));H!=null&&H.title&&String(H.title).trim()&&(w=String(H.title).trim())}const $=(Ye(t)||ze(t))&&(t.cliType||t.acpType)||t.type,U=(Ye(t)||ze(t))&&nn(w,v,$)?"":w,D=k.messages||[],_=fn(s,[t.id,g]),W=D.filter(H=>String((H==null?void 0:H.role)||"").toLowerCase()==="user").slice(),E=_.filter(H=>{const X=W.findIndex(O=>pn(O,H));return X>=0?(W.splice(X,1),!1):!0});n.push({ideId:t.id,sessionId:g,providerSessionId:t.providerSessionId,nativeSessionId:g,transport:t.transport,daemonId:t.daemonId||void 0,mode:Ye(t)?t.mode||"terminal":"chat",agentName:v,agentType:$,status:j,title:U,messages:[...D,...E],resume:t.resume,ideType:$,workspaceName:c,displayPrimary:c||U||(Ye(t)?t.mode==="chat"?v:"Terminal":v),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:N?K.buttons:void 0,modalMessage:N?K.message:void 0,streamSource:"native",tabKey:nr(g,t.id),machineName:i,connectionState:o})}if(x&&(Ye(t)||ze(t)))return n;for(const g of d){const v=g.activeModal&&Array.isArray(g.activeModal.buttons)&&g.activeModal.buttons.length>0,K=No(g),N=zo(g),j=`${t.id}:${N}`,k=g.title&&String(g.title).trim()||"",w=nn(k,g.agentName,g.agentType)?"":k,L=g.messages||[],M=fn(s,[j,g.sessionId,g.instanceId]),$=L.filter(_=>String((_==null?void 0:_.role)||"").toLowerCase()==="user").slice(),U=M.filter(_=>{const W=$.findIndex(E=>pn(E,_));return W>=0?($.splice(W,1),!1):!0});(g.transport==="cdp-webview"||g.sessionId||g.providerSessionId||L.length>0||U.length>0||v||w||!["idle","panel_hidden","disconnected","not_monitored"].includes(K))&&n.push({ideId:t.id,sessionId:g.sessionId||g.instanceId,providerSessionId:g.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:g.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:g.agentName,agentType:g.agentType,status:K,title:w,messages:[...L,...U],ideType:g.agentType,workspaceName:c,displayPrimary:c||f||w||u,displaySecondary:`${u} · ${g.agentName}`,cdpConnected:t.cdpConnected,modalButtons:v?g.activeModal.buttons:void 0,modalMessage:v?g.activeModal.message:void 0,streamSource:"agent-stream",tabKey:nr(g.sessionId||g.instanceId,j),machineName:i,connectionState:o})}return n.length===0&&n.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,providerSessionId:t.providerSessionId,nativeSessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:rn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:nr(t.sessionId||t.instanceId,t.id),connectionState:o}),n}function Ho(t){const s=[],r=new Map;for(const n of t)if(n.parentId){const i=r.get(n.parentId)||[];i.push(n),r.set(n.parentId,i)}else s.push(n);return{topLevel:s,childrenByParent:r}}function Fo(t,s){const r=[],{daemonId:n,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:d,childrenByParent:x}=Ho(u),l=d.filter(p=>p.kind==="workspace"&&p.transport==="cdp-page"),f=d.filter(p=>p.kind==="agent"&&p.transport==="pty"),b=d.filter(p=>p.kind==="agent"&&p.transport==="acp");r.push({...i||{},id:n,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.terminalSizingMode!==void 0&&{terminalSizingMode:t.terminalSizingMode},...t.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:l.some(p=>!!p.cdpConnected)});for(const p of l){const S=x.get(p.id)||[];r.push({id:`${n}:ide:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,status:p.cdpConnected?"online":"detected",daemonId:n,instanceId:p.id,workspace:p.workspace,terminals:0,childSessions:S,agents:S.map(m=>({id:m.id,name:m.providerName,type:m.providerType,status:m.status})),activeChat:p.activeChat,chats:[],cdpConnected:p.cdpConnected,currentModel:p.currentModel,currentPlan:p.currentPlan,currentAutoApprove:p.currentAutoApprove,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c})}for(const p of f)r.push({id:`${n}:cli:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:n,instanceId:p.id,cliName:p.providerName,mode:p.mode||"terminal",workspace:p.workspace||"",activeChat:p.activeChat,resume:p.resume,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isCli:!0});for(const p of b)r.push({id:`${n}:acp:${p.id}`,sessionId:p.id,providerSessionId:p.providerSessionId,parentSessionId:p.parentId,sessionKind:p.kind,transport:p.transport,sessionCapabilities:p.capabilities,type:p.providerType,ideType:p.providerType,agentType:p.providerType,status:p.status||"running",daemonId:n,instanceId:p.id,cliName:p.providerName,mode:"chat",workspace:p.workspace||"",activeChat:p.activeChat,runtimeKey:p.runtimeKey,runtimeDisplayName:p.runtimeDisplayName,runtimeWorkspaceLabel:p.runtimeWorkspaceLabel,runtimeWriteOwner:p.runtimeWriteOwner??null,runtimeAttachedClients:p.runtimeAttachedClients??[],currentModel:p.currentModel,currentPlan:p.currentPlan,lastUpdated:p.lastUpdated,unread:p.unread,lastSeenAt:p.lastSeenAt,inboxBucket:p.inboxBucket,surfaceHidden:p.surfaceHidden,acpConfigOptions:p.acpConfigOptions,acpModes:p.acpModes,controlValues:p.controlValues,providerControls:p.providerControls,timestamp:c,_isAcp:!0});return r}function Vo(t){const s=t.split(":");return s.length>=3&&(s[1]==="ide"||s[1]==="cli"||s[1]==="acp")?{daemonId:s[0],targetSessionId:s.slice(2).join(":")||void 0}:{daemonId:t}}function qo(t,s){const r=Vo(t);return{daemonId:r.daemonId,payload:{...s,...r.targetSessionId&&!s.targetSessionId?{targetSessionId:r.targetSessionId}:{}}}}const pa=[{id:"vscode",name:"VS Code",icon:"💙"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"windsurf",name:"Windsurf",icon:"🏄"},{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"trae",name:"Trae",icon:"🔮"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"vscodium",name:"VSCodium",icon:"💚"}],fa=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose CLI",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],xa=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],ha="adhdev_notification_prefs",xn={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Go(){try{const t=localStorage.getItem(ha);if(t){const s=JSON.parse(t);return{...xn,...s}}}catch{}return{...xn}}function Yo(t){try{localStorage.setItem(ha,JSON.stringify(t))}catch{}}let kt=Go(),_s=[];function Xo(){_s.forEach(t=>t())}function Jo(){return{...kt}}function Zo(t){kt={...kt,...t},Yo(kt),Xo()}function Qo(){const[,t]=a.useState(0);a.useEffect(()=>{const r=()=>t(n=>n+1);return _s.push(r),()=>{_s=_s.filter(n=>n!==r)}},[]);const s=a.useCallback(r=>{Zo(r)},[]);return[{...kt},s]}function $t(t){if(!kt.globalEnabled)return!1;switch(t){case"disconnect":return kt.disconnectAlert;case"completion":return kt.completionAlert;case"approval":return kt.approvalAlert;case"browser":return kt.browserNotifications;default:return!0}}const ec={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function tc(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function ba(){return"Notification"in window&&Notification.permission==="granted"}let Rt=null;async function sc(){if(Rt!==null)return Rt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Rt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Rt=!!await t.pushManager.getSubscription(),Rt):(Rt=!1,!1)}catch{return Rt=!1,!1}}function Ms(t,s,r){if(ba())try{const n=new Notification(t,{body:s,icon:"/otter-logo.png",tag:r||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>n.close(),8e3),n.onclick=()=>{window.focus(),n.close()}}catch{}}function rc(t,s={}){const r={...ec,...s},n=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{sc().then(u=>{o.current=u})},[]);const c=a.useCallback((u,d,x)=>{const l=Date.now();l-i.current<r.throttleMs||(i.current=l,Ms(u,d,x))},[r.throttleMs]);a.useEffect(()=>{var u;if(!(!r.enabled||!ba())&&$t("browser")&&o.current!==!0){if(document.hasFocus()){for(const d of t)n.current.set(d.id,lt(d.status,{activeModal:d.activeModal}));return}for(const d of t){const x=n.current.get(d.id),l=lt(d.status,{activeModal:d.activeModal}),f=d.name||d.id;if(r.onApproval&&$t("approval")&&l==="waiting_approval"&&x!=="waiting_approval"){const b=((u=d.activeModal)==null?void 0:u.message)||"Action requires your approval";c(`🔔 ${f} — Approval needed`,b.slice(0,120),`approval-${d.id}`)}r.onComplete&&$t("completion")&&aa(x)&&l==="idle"&&c(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${d.id}`),r.onError&&l==="error"&&x!=="error"&&c(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${d.id}`),n.current.set(d.id,l)}}},[t,r.enabled,r.onApproval,r.onComplete,r.onError,c])}class nc{constructor(){tt(this,"dedupMap",new Map);tt(this,"DEDUP_WINDOW_MS",5e3);tt(this,"DEDUP_MAX_SIZE",50);tt(this,"DEDUP_CLEANUP_AGE_MS",1e4);tt(this,"toastCallbacks",[]);tt(this,"systemMessageCallbacks",[]);tt(this,"clearSystemMessageCallbacks",[]);tt(this,"resolveActionFn",null);tt(this,"viewRequestRespondFn",null);tt(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(r=>r!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(r=>r!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(r=>r!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const r of this.toastCallbacks)r(s)}showToast(s,r="info",n){const i=(n==null?void 0:n.id)||Date.now();this.emitToast({id:i,message:s,type:r,timestamp:i,duration:5e3,...n})}emitSystemMessage(s,r){for(const n of this.systemMessageCallbacks)n(s,r)}emitClearSystemMessage(s,r){for(const n of this.clearSystemMessageCallbacks)n(s,r)}isDuplicate(s){const r=Date.now(),n=this.dedupMap.get(s)||0;if(r-n<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,r),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)r-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let r;if(s.targetSessionId&&(r=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(r=r||this.ides.find(i=>i.id===s.ideId)),!r&&s.instanceId&&(r=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),r){const i=r.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const n=this.ides.filter(i=>i.type==="adhdev-daemon");return n.length===1?n[0]:null}resolveRouteId(s,r){for(const n of this.ides)if(n.id.startsWith(s)&&(!r||r===n.type))return n.id;return s}findOwningSession(s){for(const r of this.ides)if(r.id===s||r.sessionId===s||(Array.isArray(r.childSessions)?r.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return r;return null}resolveActionRouteTarget(s){if(s.ideId){const r=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,r)}if(s.targetSessionId){const r=this.findOwningSession(s.targetSessionId);return(r==null?void 0:r.id)||(r==null?void 0:r.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,r){var b,p,S,m;if(!s.ideId&&s.instanceId){for(const h of this.ides)if(h.id.endsWith(`:ide:${s.instanceId}`)||h.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=h.id;break}}const n=this.resolveConversationKey(s),i=n||s.instanceId||s.ideType||s.providerType||"",o=s.effectId||s.message||s.content||s.chatTitle||"",c=`${i}:${s.event}:${o}`;if(this.isDuplicate(c))return;let u=qe(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=gt(d,{fallbackId:d.id});h&&(u=s.ideType==="adhdev-daemon"?h:`${h}/${u}`)}const x=Number.isFinite(s.timestamp)?Number(s.timestamp):Date.now();let l="",f="info";if(s.event==="provider:message"){n&&s.content&&this.emitSystemMessage(n,{role:"system",timestamp:x,content:s.content,_localId:`sys_provider_${x}_${(s.content||"").slice(0,24)}`});return}else if(s.event==="provider:toast")l=s.message||"",f=s.level||"info";else if(s.event==="provider:notification"){const h=(b=s.channels)!=null&&b.length?s.channels:["toast"],y=s.preferenceKey,g=$t("browser")&&(!y||y==="browser"||$t(y));h.includes("bubble")&&n&&s.content&&this.emitSystemMessage(n,{role:"system",timestamp:x,content:s.content,_localId:`sys_provider_notification_${s.effectId||x}`}),h.includes("browser")&&s.title&&s.message&&g&&!document.hasFocus()&&Ms(s.title,s.message,`provider-${s.effectId||x}`),h.includes("toast")&&(l=s.message||s.title||"",f=s.level||"info")}else if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${u} agent task completed${h}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}n&&Jo().chatTaskCompletionBubble&&this.emitSystemMessage(n,{role:"system",timestamp:x,content:`✅ Task completed${h}`,_localId:`sys_complete_${x}`})}else if(s.event==="agent:generating_started")n&&this.emitClearSystemMessage(n,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${u} approval needed`,f="warning",n&&!((p=s.modalButtons)!=null&&p.length)){const h=s.modalMessage||"Approval requested",y=(S=s.modalButtons)!=null&&S.length?s.modalButtons.map(g=>`[${g}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(n,{role:"system",timestamp:x,content:`⚡ Approval requested: ${h}
30
- ${y}`,_localId:`sys_approval_${x}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const y=s.agentType||s.ideType||"",g=s.ideType||"",v=s.modalButtons,K=L=>L.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),N=this.resolveActionFn,j=v.map((L,M)=>{const $=K(L).toLowerCase(),U=/^(run|approve|accept|yes|allow|always)/.test($),D=/^(reject|deny|delete|remove|abort|cancel|no)/.test($);return{label:K(L),variant:U?"primary":D?"danger":"default",onClick:()=>{const _=/^(run|approve|accept|yes|allow|always|proceed|save)/.test($);N(h,"resolve_action",{action:_?"approve":"reject",button:L,buttonIndex:M,agentType:y,ideType:g,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),k=s.modalMessage?`⚡ ${u}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,w=Date.now();this.emitToast({id:w,message:k,type:f,timestamp:w,targetKey:n||h,actions:j,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${u} agent is taking a long time${h}`,f="warning",$t("browser")&&!document.hasFocus()&&Ms(`⚠️ ${u} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",y=s.requestId,g=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",y&&g&&this.viewRequestRespondFn){const v=this.viewRequestRespondFn,K=Date.now(),N=[{label:"Approve",variant:"primary",onClick:()=>{v(g,y,"approve").catch(j=>console.error("[EventManager] approve view request failed:",j))}},{label:"Decline",variant:"danger",onClick:()=>{v(g,y,"reject").catch(j=>console.error("[EventManager] reject view request failed:",j))}}];this.emitToast({id:K,message:l,type:f,timestamp:K,actions:N,duration:3e4}),l=""}$t("browser")&&!document.hasFocus()&&Ms("👁️ View Request",`${h} wants to view your session`,`view-request-${y}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:n||s.ideId,duration:5e3})}}}const _t=new nc;function Ht(...t){return xi(hi(t))}function ac({icon:t,title:s,subtitle:r,badge:n,actions:i,className:o}){return e.jsxs("div",{className:Ht("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,n&&e.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&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Ws({icon:t,title:s,subtitle:r,badge:n,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(ac,{icon:t,title:s,subtitle:r,badge:n,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Ht("mx-auto flex w-full flex-col gap-4",o,c),children:u})})]})}function ot({title:t,icon:s,description:r,accentColor:n,className:i,children:o}){return e.jsxs("div",{className:Ht("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]",i),style:n?{borderLeftColor:n}:void 0,children:[(t||r)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),r&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o]})}function Er({icon:t,title:s,description:r,action:n,className:i}){return e.jsxs("div",{className:Ht("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:r}),n]})}const ic={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"},oc={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function cc({variant:t,children:s,onDismiss:r,className:n}){return e.jsxs("div",{className:Ht("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",ic[t],n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:oc[t]}),e.jsx("span",{children:s})]}),r&&e.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const lc={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"},dc={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function uc({status:t,label:s,className:r}){const n=s||t;return e.jsxs("span",{className:Ht("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",lc[t],r),children:[e.jsx("span",{className:Ht("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",dc[t])}),n]})}function mc(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function gr(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ps(t){return t==="system"?mc():t}function pc(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ps(gr()))}function ga(){const[t,s]=a.useState(gr),[r,n]=a.useState(()=>Ps(gr()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",r)},[r]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),u=d=>{t==="system"&&n(d.matches?"light":"dark")};return c.addEventListener("change",u),()=>c.removeEventListener("change",u)},[t]);const i=a.useCallback(c=>{s(c),n(Ps(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const u=c==="dark"?"light":c==="light"?"system":"dark";n(Ps(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:r,preference:t,setPreference:i,cycleTheme:o,isDark:r==="dark"}}function Mt({label:t,description:s,checked:r,disabled:n,onChange:i,extra:o}){return e.jsxs("div",{className:`flex justify-between items-center ${n?"opacity-60":""}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,e.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>i(!r),className:`relative inline-flex items-center ${n?"cursor-not-allowed":"cursor-pointer"}`,children:[e.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))"}}),e.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 fc({onPrefChange:t}){const[s,r]=Qo(),n=(i,o)=>{r({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vs,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>n("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ct,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>n("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vi,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>n("completionAlert",i)}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qi,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>n("approvalAlert",i)}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>n("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>n("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function xc({ides:t,emptyMessage:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Er,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(bc,{ide:c,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i},c.id))})}function hn({title:t,message:s,confirmLabel:r,confirmColor:n,onConfirm:i,onCancel:o}){const c=n==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return zn.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.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"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,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 hc(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...pa,...fa,...xa].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:t}}function bc({ide:t,allIdes:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){var _,W;const[o,c]=a.useState("idle"),[u,d]=a.useState(""),[x,l]=a.useState(null),[f,b]=a.useState("idle"),[p,S]=a.useState(""),m=t,h=m.version||m.daemonVersion||null,y=((_=m.machine)==null?void 0:_.platform)||((W=m.system)==null?void 0:W.platform)||"",g=gt(m,{fallbackId:t.id}),v=y==="win32"?"🪟":y==="darwin"?"🍎":"🐧",K=s.filter(E=>E.daemonId===t.id&&E.transport==="cdp-page"),N=s.filter(E=>E.daemonId===t.id&&E.transport==="pty"),j=s.filter(E=>E.daemonId===t.id&&E.transport==="acp"),k=m.p2p,w=async()=>{var E,H,X,O;if(r){c("upgrading"),d("Starting upgrade...");try{const P=await r(t.id,"daemon_upgrade",{});(E=P==null?void 0:P.result)!=null&&E.alreadyLatest?(c("done"),d(`Already on v${P.result.version||"latest"}.`)):(H=P==null?void 0:P.result)!=null&&H.upgraded||(X=P==null?void 0:P.result)!=null&&X.success?(c("done"),d(`Upgrade to v${P.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),d(((O=P==null?void 0:P.result)==null?void 0:O.error)||"Upgrade failed"))}catch(P){c("error"),d((P==null?void 0:P.message)||"Connection lost during upgrade")}}},L=async()=>{if(l(null),!!n){b("loading");try{await n(t.id),b("done"),S("Machine disconnected.")}catch(E){b("error"),S((E==null?void 0:E.message)||"Failed to disconnect")}}},M=async()=>{if(l(null),!!i){b("loading");try{await i(t.id),b("done"),S('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(E){b("error"),S((E==null?void 0:E.message)||"Failed to revoke token")}}},$="0.8.23",U=!h||h!==$,D=K.length+N.length+j.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:v}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:g}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),h&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${U?"":"bg-bg-secondary"}`,style:U?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",h,!U&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&U&&e.jsx("button",{onClick:w,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${$}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${$}`}`}),n&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:f==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>l("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(uc,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[k&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&D>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),D>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[K.map(E=>{const H=hc(E.type),X=E.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:H.icon}),e.jsx("span",{children:H.name}),X!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${X?"bg-green-400":"animate-pulse"}`,style:X?void 0:{background:"var(--status-warning)"},title:X?"CDP connected":"CDP connecting..."})]},E.id)}),N.map(E=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:E.cliName||"CLI"})]},E.id)),j.map(E=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:E.cliName||"ACP"})]},E.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:p||u})]}),x==="disconnect"&&e.jsx(hn,{title:"🔌 Disconnect Machine",message:`Disconnect "${g}" from ADHDev?
30
+ ${y}`,_localId:`sys_approval_${x}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const y=s.agentType||s.ideType||"",g=s.ideType||"",v=s.modalButtons,K=L=>L.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),N=this.resolveActionFn,j=v.map((L,M)=>{const $=K(L).toLowerCase(),U=/^(run|approve|accept|yes|allow|always)/.test($),D=/^(reject|deny|delete|remove|abort|cancel|no)/.test($);return{label:K(L),variant:U?"primary":D?"danger":"default",onClick:()=>{const _=/^(run|approve|accept|yes|allow|always|proceed|save)/.test($);N(h,"resolve_action",{action:_?"approve":"reject",button:L,buttonIndex:M,agentType:y,ideType:g,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),k=s.modalMessage?`⚡ ${u}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,w=Date.now();this.emitToast({id:w,message:k,type:f,timestamp:w,targetKey:n||h,actions:j,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${u} agent is taking a long time${h}`,f="warning",$t("browser")&&!document.hasFocus()&&Ms(`⚠️ ${u} — Long Running`,`Agent has been generating for over ${h.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const h=s.requesterName||"A team member",y=s.requestId,g=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",y&&g&&this.viewRequestRespondFn){const v=this.viewRequestRespondFn,K=Date.now(),N=[{label:"Approve",variant:"primary",onClick:()=>{v(g,y,"approve").catch(j=>console.error("[EventManager] approve view request failed:",j))}},{label:"Decline",variant:"danger",onClick:()=>{v(g,y,"reject").catch(j=>console.error("[EventManager] reject view request failed:",j))}}];this.emitToast({id:K,message:l,type:f,timestamp:K,actions:N,duration:3e4}),l=""}$t("browser")&&!document.hasFocus()&&Ms("👁️ View Request",`${h} wants to view your session`,`view-request-${y}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",f="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,f="warning");if(l){const h=Date.now();this.emitToast({id:h,message:l,type:f,timestamp:h,targetKey:n||s.ideId,duration:5e3})}}}const _t=new nc;function Ht(...t){return xi(hi(t))}function ac({icon:t,title:s,subtitle:r,badge:n,actions:i,className:o}){return e.jsxs("div",{className:Ht("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,n&&e.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&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:r})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Ws({icon:t,title:s,subtitle:r,badge:n,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(ac,{icon:t,title:s,subtitle:r,badge:n,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Ht("mx-auto flex w-full flex-col gap-4",o,c),children:u})})]})}function ot({title:t,icon:s,description:r,accentColor:n,className:i,children:o}){return e.jsxs("div",{className:Ht("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]",i),style:n?{borderLeftColor:n}:void 0,children:[(t||r)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),r&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:r})]}),o]})}function Er({icon:t,title:s,description:r,action:n,className:i}){return e.jsxs("div",{className:Ht("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:r}),n]})}const ic={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"},oc={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function cc({variant:t,children:s,onDismiss:r,className:n}){return e.jsxs("div",{className:Ht("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",ic[t],n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:oc[t]}),e.jsx("span",{children:s})]}),r&&e.jsx("button",{onClick:r,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const lc={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"},dc={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function uc({status:t,label:s,className:r}){const n=s||t;return e.jsxs("span",{className:Ht("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",lc[t],r),children:[e.jsx("span",{className:Ht("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",dc[t])}),n]})}function mc(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function gr(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Ps(t){return t==="system"?mc():t}function pc(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Ps(gr()))}function ga(){const[t,s]=a.useState(gr),[r,n]=a.useState(()=>Ps(gr()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",r)},[r]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),u=d=>{t==="system"&&n(d.matches?"light":"dark")};return c.addEventListener("change",u),()=>c.removeEventListener("change",u)},[t]);const i=a.useCallback(c=>{s(c),n(Ps(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const u=c==="dark"?"light":c==="light"?"system":"dark";n(Ps(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:r,preference:t,setPreference:i,cycleTheme:o,isDark:r==="dark"}}function Mt({label:t,description:s,checked:r,disabled:n,onChange:i,extra:o}){return e.jsxs("div",{className:`flex justify-between items-center ${n?"opacity-60":""}`,children:[e.jsxs("div",{className:"pr-4",children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:s})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[o,e.jsxs("button",{type:"button",role:"switch","aria-checked":r,"aria-disabled":n,disabled:n,onClick:()=>i(!r),className:`relative inline-flex items-center ${n?"cursor-not-allowed":"cursor-pointer"}`,children:[e.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))"}}),e.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 fc({onPrefChange:t}){const[s,r]=Qo(),n=(i,o)=>{r({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vs,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>n("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ct,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>n("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vi,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>n("completionAlert",i)}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qi,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>n("approvalAlert",i)}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>n("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>n("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function xc({ides:t,emptyMessage:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Er,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(bc,{ide:c,allIdes:t,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i},c.id))})}function hn({title:t,message:s,confirmLabel:r,confirmColor:n,onConfirm:i,onCancel:o}){const c=n==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return zn.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.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"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,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 hc(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),n=[...pa,...fa,...xa].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return n?{icon:n.icon,name:n.name}:{icon:"📝",name:t}}function bc({ide:t,allIdes:s,sendDaemonCommand:r,onDisconnect:n,onRevokeToken:i}){var _,W;const[o,c]=a.useState("idle"),[u,d]=a.useState(""),[x,l]=a.useState(null),[f,b]=a.useState("idle"),[p,S]=a.useState(""),m=t,h=m.version||m.daemonVersion||null,y=((_=m.machine)==null?void 0:_.platform)||((W=m.system)==null?void 0:W.platform)||"",g=gt(m,{fallbackId:t.id}),v=y==="win32"?"🪟":y==="darwin"?"🍎":"🐧",K=s.filter(E=>E.daemonId===t.id&&E.transport==="cdp-page"),N=s.filter(E=>E.daemonId===t.id&&E.transport==="pty"),j=s.filter(E=>E.daemonId===t.id&&E.transport==="acp"),k=m.p2p,w=async()=>{var E,H,X,O;if(r){c("upgrading"),d("Starting upgrade...");try{const P=await r(t.id,"daemon_upgrade",{});(E=P==null?void 0:P.result)!=null&&E.alreadyLatest?(c("done"),d(`Already on v${P.result.version||"latest"}.`)):(H=P==null?void 0:P.result)!=null&&H.upgraded||(X=P==null?void 0:P.result)!=null&&X.success?(c("done"),d(`Upgrade to v${P.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),d(((O=P==null?void 0:P.result)==null?void 0:O.error)||"Upgrade failed"))}catch(P){c("error"),d((P==null?void 0:P.message)||"Connection lost during upgrade")}}},L=async()=>{if(l(null),!!n){b("loading");try{await n(t.id),b("done"),S("Machine disconnected.")}catch(E){b("error"),S((E==null?void 0:E.message)||"Failed to disconnect")}}},M=async()=>{if(l(null),!!i){b("loading");try{await i(t.id),b("done"),S('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(E){b("error"),S((E==null?void 0:E.message)||"Failed to revoke token")}}},$="0.8.24",U=!h||h!==$,D=K.length+N.length+j.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:v}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:g}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),h&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${U?"":"bg-bg-secondary"}`,style:U?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",h,!U&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&U&&e.jsx("button",{onClick:w,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${$}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${$}`}`}),n&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:f==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>l("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(uc,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[k&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&D>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),D>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[K.map(E=>{const H=hc(E.type),X=E.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:H.icon}),e.jsx("span",{children:H.name}),X!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${X?"bg-green-400":"animate-pulse"}`,style:X?void 0:{background:"var(--status-warning)"},title:X?"CDP connected":"CDP connecting..."})]},E.id)}),N.map(E=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:E.cliName||"CLI"})]},E.id)),j.map(E=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:E.cliName||"ACP"})]},E.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:p||u})]}),x==="disconnect"&&e.jsx(hn,{title:"🔌 Disconnect Machine",message:`Disconnect "${g}" from ADHDev?
31
31
 
32
32
  This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
33
33
 
@@ -38,7 +38,7 @@ This will:
38
38
  • Delete the machine registration
39
39
  • Require restarting "adhdev-standalone" on that machine
40
40
 
41
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:M,onCancel:()=>l(null)})]})}const gc=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function yc(){const{preference:t,setPreference:s}=ga();return e.jsx("div",{className:"flex gap-2",children:gc.map(r=>e.jsxs("button",{onClick:()=>s(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:r.icon}),r.label]},r.id))})}function vc(t){const s=t.trim();return/^#[0-9a-fA-F]{6}$/.test(s)?s:/^#[0-9a-fA-F]{3}$/.test(s)?`#${s[1]}${s[1]}${s[2]}${s[2]}${s[3]}${s[3]}`:null}function wc(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function ar(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function bn(t){const{r:s,g:r,b:n}=wc(t);return .2126*ar(s)+.7152*ar(r)+.0722*ar(n)}function gn(t,s){const r=bn(t),n=bn(s),i=Math.max(r,n),o=Math.min(r,n);return(i+.05)/(o+.05)}function $r(t){const s=vc(t);if(!s)return"#111827";const r="#111827",n="#ffffff";return gn(s,r)>=gn(s,n)?r:n}const ya="adhdev-accent-color",yr="#cf7a45";function jc(t){const s=parseInt(t.slice(1,3),16)/255,r=parseInt(t.slice(3,5),16)/255,n=parseInt(t.slice(5,7),16)/255,i=Math.max(s,r,n),o=Math.min(s,r,n);let c=0,u=0;const d=(i+o)/2;if(i!==o){const x=i-o;switch(u=d>.5?x/(2-i-o):x/(i+o),i){case s:c=((r-n)/x+(r<n?6:0))/6;break;case r:c=((n-s)/x+2)/6;break;case n:c=((s-r)/x+4)/6;break}}return{h:Math.round(c*360),s:Math.round(u*100),l:Math.round(d*100)}}function yn(t,s){const{h:r,s:n,l:i}=jc(t),o=Math.min(100,i+s);return`hsl(${r}, ${n}%, ${o}%)`}function ir(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function kc(){return typeof window>"u"?yr:localStorage.getItem(ya)||yr}function Nc(){if(typeof window>"u")return!1;try{return localStorage.getItem(ya)!=null}catch{return!1}}function Sc(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",yn(t,15)),s.style.setProperty("--accent-on-primary",$r(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${yn(t,20)})`),s.style.setProperty("--border-accent",ir(t,.4)),s.style.setProperty("--nav-active-bg",ir(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${ir(t,.06)}`)}function Cc(){const t=kc();t!==yr&&Sc(t)}const vr={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},wr={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},Ic=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],va="adhdev-chat-theme",wa="adhdev-chat-theme-custom";function Ls(){if(typeof window>"u")return"ember";try{return localStorage.getItem(va)||"ember"}catch{return"ember"}}function vt(t){try{const s=localStorage.getItem(wa);if(s){const r=JSON.parse(s);return{...t==="dark"?vr:wr,...r[t]}}}catch{}return t==="dark"?vr:wr}function ws(t,s){try{localStorage.setItem(wa,JSON.stringify({dark:t,light:s}))}catch{}}function ht(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function Os(t,s){const r=Math.min(255,parseInt(t.slice(1,3),16)+s),n=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Tc={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function cs(t,s){var i;if(Nc())return;const r=(i=Tc[t])==null?void 0:i[s];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",Os(r,24)),n.style.setProperty("--accent-on-primary",$r(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${Os(r,18)})`),n.style.setProperty("--border-accent",ht(r,.35)),n.style.setProperty("--nav-active-bg",ht(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${ht(r,.06)}`)}function Bt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",ht(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",ht(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",ht(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",ht(t.borderSubtle,.5)),s.style.setProperty("--border-default",ht(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Os(t.accentColor,30)),s.style.setProperty("--accent-on-primary",$r(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Os(t.accentColor,40)})`),s.style.setProperty("--border-accent",ht(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",ht(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${ht(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${ht(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Dr(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>t.style.removeProperty(r))}function Ac(t){try{localStorage.setItem(va,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Kt()?"dark":"light";Bt(vt(s))}else Dr(),cs(t,Kt()?"dark":"light")}function _c(){const t=Ls();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Kt()?"dark":"light";Bt(vt(s))}else Dr(),cs(t,Kt()?"dark":"light")}function Kt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function it({label:t,value:s,onChange:r}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function as({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function Mc({dark:t,onColorsChange:s}){const r=t?"dark":"light",[n,i]=a.useState(()=>vt(r));a.useEffect(()=>{i(vt(r))},[r]);const o=a.useCallback((c,u)=>{i(d=>{const x={...d,[c]:u},f=vt(r==="dark"?"light":"dark");return r==="dark"?ws(x,f):ws(f,x),Bt(x),s(x),x})},[r,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(as,{title:"App Background",children:[e.jsx(it,{label:"Background",value:n.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(it,{label:"Surface",value:n.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(it,{label:"Card",value:n.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(as,{title:"App Text",children:[e.jsx(it,{label:"Primary",value:n.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(it,{label:"Secondary",value:n.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(it,{label:"Muted",value:n.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(as,{title:"Borders & Accent",children:[e.jsx(it,{label:"Border subtle",value:n.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(it,{label:"Border default",value:n.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(it,{label:"Accent",value:n.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(as,{title:"Chat Bubbles",children:[e.jsx(it,{label:"User bubble",value:n.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(it,{label:"User text",value:n.userText,onChange:c=>o("userText",c)}),e.jsx(it,{label:"Agent bubble",value:n.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(it,{label:"Agent text",value:n.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(as,{title:"Chat Layout",children:[e.jsx(it,{label:"Chat BG",value:n.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(it,{label:"Send button",value:n.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(it,{label:"Input border",value:n.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?vr:wr,d=vt(t?"light":"dark");t?ws(c,d):ws(d,c),i(c),Bt(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Pc(){const[t,s]=a.useState(Ls),[r,n]=a.useState(!0),[i,o]=a.useState(()=>vt("dark"));a.useEffect(()=>{n(Kt());const d=new MutationObserver(()=>{const f=Kt();n(f);const b=Ls();b==="custom"?Bt(vt(f?"dark":"light")):cs(b,f?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const f=Kt();n(f);const b=Ls();b==="custom"?Bt(vt(f?"dark":"light")):cs(b,f?"dark":"light")};return x.addEventListener("change",l),()=>{d.disconnect(),x.removeEventListener("change",l)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Bt(vt(r?"dark":"light")):(Dr(),cs(t,r?"dark":"light"))},[t,r]),a.useEffect(()=>{o(vt(r?"dark":"light"))},[r]);const c=d=>{s(d),Ac(d)},u=[...Ic,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(d=>{const x=t===d.id,l=r?d.preview.dark:d.preview.light,f=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.userBubble,color:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),t==="custom"&&e.jsx(Mc,{dark:r,onColorsChange:d=>o(d)})]})}const ja="adhdev_mobileDashboardMode_v1";function ka(){try{return localStorage.getItem(ja)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Lc(t){try{localStorage.setItem(ja,t)}catch{}}function Rc(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(ka()==="chat")},[]),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:r=>{s(r),Lc(r?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Na="adhdev_hiddenTabs";function Ec(){try{const t=localStorage.getItem(Na);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function qt(t){try{localStorage.setItem(Na,JSON.stringify([...t]))}catch{}}function $c(){const[t,s]=a.useState(Ec),r=a.useCallback(x=>{s(l=>{const f=new Set(l);return f.has(x)?f.delete(x):f.add(x),qt(f),f})},[]),n=a.useCallback(x=>{s(l=>{if(l.has(x))return l;const f=new Set(l);return f.add(x),qt(f),f})},[]),i=a.useCallback(x=>{s(l=>{if(!l.has(x))return l;const f=new Set(l);return f.delete(x),qt(f),f})},[]),o=a.useCallback(()=>{s(x=>{if(x.size===0)return x;const l=new Set;return qt(l),l})},[]),c=a.useCallback((x,l)=>{s(f=>{const b=new Set(f);for(const p of l)b.add(p);return qt(b),b})},[]),u=a.useCallback((x,l)=>{s(f=>{const b=new Set(f);for(const p of l)b.delete(p);return qt(b),b})},[]),d=a.useCallback(x=>t.has(x),[t]);return{hiddenTabs:t,toggleTab:r,hideTab:n,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:u,isHidden:d}}function Dc({visibleConversations:t,clearedTabs:s,setClearedTabs:r,setActionLogs:n}){a.useEffect(()=>{tc()},[]);const i=a.useMemo(()=>t.map(o=>({id:o.tabKey,name:o.title||o.agentName||o.ideId,status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[t]);return rc(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{r(u=>{const d=Date.now(),x={};for(const[l,f]of Object.entries(u))d-f<5e3&&(x[l]=f);return Object.keys(x).length===Object.keys(u).length?u:x})},5500);return()=>clearTimeout(c)},[s,r]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;n(u=>{const d=u.filter(x=>x.timestamp>c).slice(-100);return d.length===u.length?u:d})},6e4);return()=>clearInterval(o)},[n]),null}function or(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function Dt(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1];return or(s==null?void 0:s.timestamp)||or(s==null?void 0:s.receivedAt)||or(s==null?void 0:s.createdAt)||0}function jr(t,s=0){return Dt(t)||s||0}function Sa(t){return Dt(t)}function Bc(t,s,r=Sa){const n=r(s)-r(t);if(n!==0)return n;const i=(t.machineName||"").localeCompare(s.machineName||"");if(i!==0)return i;const o=t.displayPrimary.localeCompare(s.displayPrimary);if(o!==0)return o;const c=t.displaySecondary.localeCompare(s.displaySecondary);return c!==0?c:t.tabKey.localeCompare(s.tabKey)}function Kc(t){const s=t.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of s){const i=r.get(n.id);if(!i){r.set(n.id,n);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>o||(n.timestamp||0)>(i.timestamp||0))&&r.set(n.id,n)}return Array.from(r.values())}function js(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Wc(t,s){const r=Date.now();return t.map(n=>{const i=s[n.tabKey];return i&&r-i<5e3?{...n,messages:[],title:""}:n})}function Oc(t,s){const r=[],n=t.sessionId||t.instanceId;r.push({key:t.id,ref:s[t.id]}),n&&r.push({key:n,ref:s[n]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;r.push({key:c,ref:s[c]}),r.push({key:i.id,ref:s[i.id]})}return r}function Uc(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].key!==s[r].key||t[r].ref!==s[r].ref)return!1;return!0}function zc(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Hc(t){const s=zc(t);if(!s)return`empty:${t.messages.length}`;if(s.id)return`id:${String(s.id)}`;if(s._localId)return`local:${String(s._localId)}`;const r=String(s.role||""),n=Lr(s.content).slice(0,240);return`${t.messages.length}:${r}:${n}`}function Fc({ides:t,connectionStates:s,localUserMessages:r,clearedTabs:n,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),u=a.useRef([]),d=a.useRef([]),x=a.useMemo(()=>{const N=Kc(t);return js(o.current,N)?o.current:(o.current=N,N)},[t]),l=a.useMemo(()=>ma(t),[t]),f=a.useRef(new Map),b=a.useRef(new Map),p=a.useMemo(()=>{var M;const N=new Map,j=[];for(const $ of x){const U=$.daemonId||((M=$.id)==null?void 0:M.split(":")[0])||$.id,D=s[U]||"new",_=$.daemonId&&l[$.daemonId]||void 0,W=Oc($,r),E=f.current.get($.id);if(E&&E.ide===$&&E.connectionState===D&&E.machineName===_&&Uc(E.localRefs,W)){N.set($.id,E),j.push(...E.conversations);continue}const H=Rr($,r,{machineName:_,connectionState:D}),X={ide:$,connectionState:D,machineName:_,localRefs:W,conversations:H};N.set($.id,X),j.push(...H)}f.current=N;const k=new Map,w=$=>{const U=Hc($),D=b.current.get($.tabKey);if(D&&D.signature===U)return k.set($.tabKey,D),D.timestamp;const _={signature:U,timestamp:Sa($)||(D==null?void 0:D.timestamp)||0};return k.set($.tabKey,_),_.timestamp},L=[...j].sort(($,U)=>Bc($,U,w));return b.current=k,L},[x,r,s,l]),S=a.useMemo(()=>{const N=Wc(p,n);return js(c.current,N)?c.current:(c.current=N,N)},[p,n]),m=a.useMemo(()=>{const N=new Map;for(const j of S)j.sessionId&&N.set(j.sessionId,j);return N},[S]),h=a.useMemo(()=>{const N=new Map;for(const j of S)j.sessionId&&N.set(j.sessionId,j),N.set(j.ideId,j),N.set(j.tabKey,j);return N},[S]),y=a.useCallback(N=>{if(N)return m.get(N)},[m]),g=a.useCallback(N=>{if(N)return h.get(N)},[h]),v=a.useMemo(()=>{const N=S.filter(j=>!i.has(j.tabKey));return js(u.current,N)?u.current:(u.current=N,N)},[S,i]),K=a.useMemo(()=>{const N=v.map(j=>j.tabKey);return js(d.current,N)?d.current:(d.current=N,N)},[v]);return{chatIdes:x,conversations:S,visibleConversations:v,visibleTabKeys:K,resolveConversationBySessionId:y,resolveConversationByTarget:g}}function Vc({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:r,setSearchParams:n}){const i=a.useMemo(()=>{var u;return t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),o=a.useMemo(()=>{var u;return!t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),c=a.useCallback(()=>{s&&n(u=>{const d=new URLSearchParams(u);return d.delete("activeTab"),d},{replace:!0})},[n,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function qc({ides:t,sendDaemonCommand:s,setToasts:r,setLocalUserMessages:n,resolveConversationByTarget:i}){a.useEffect(()=>{_t.setIdes(t)},[t]),a.useEffect(()=>{_t.setResolveAction((o,c,u)=>{s(o,c,u).catch(()=>{})})},[s]),a.useEffect(()=>{const o=_t.onToast(d=>{r(l=>l.some(b=>b.message===d.message&&d.timestamp-b.timestamp<3e3)?l:[...l.slice(-4),{id:d.id,message:d.message,type:d.type,timestamp:d.timestamp,targetKey:d.targetKey,actions:d.actions}]);const x=d.duration||5e3;setTimeout(()=>r(l=>l.filter(f=>f.id!==d.id)),x)}),c=_t.onSystemMessage((d,x)=>{var p,S;const l=i(d),f=(p=x._localId)==null?void 0:p.startsWith("sys_approval_"),b=!!(l&&(l.status==="waiting_approval"||(S=l.modalButtons)!=null&&S.length||l.modalMessage));f&&b||n(m=>({...m,[d]:[...m[d]||[],x]}))}),u=_t.onClearSystemMessage((d,x)=>{n(l=>{var f;return(f=l[d])!=null&&f.length?{...l,[d]:l[d].filter(b=>{var p;return!(b.role==="system"&&((p=b._localId)!=null&&p.startsWith(x)))})}:l})});return()=>{o(),c(),u()}},[r,n]),a.useEffect(()=>{const o=da.on("status_event",c=>_t.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=u=>{var h;const d=u.data;if((d==null?void 0:d.type)!=="notification_action"||typeof d.action!="string"||!d.action.startsWith("approval_")||!(d.ideId||d.targetSessionId||d.targetKey))return;const x=d.targetSessionId||d.targetKey||d.ideId,l=i(x),f=(l==null?void 0:l.ideId)||d.ideId;if(!f)return;const b=Number(d.buttonIndex),p=d.button||((h=l==null?void 0:l.modalButtons)==null?void 0:h[b])||"Approve",S=String(p).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),m=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(S);s(f,"resolve_action",{action:m?"approve":"reject",button:p,...Number.isFinite(b)&&{buttonIndex:b},...(l==null?void 0:l.sessionId)&&{targetSessionId:l.sessionId},...d.targetSessionId&&{targetSessionId:d.targetSessionId}}).catch(y=>console.error("[SW Action] approval failed:",y))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",o)}},[i,s])}const Gc="adhdev_dashboardLayout_v1",Yc="adhdev_dashboardDockview_v1",is={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Ca(t,s){try{const r=localStorage.getItem(t);return r?JSON.parse(r):s}catch{return s}}function Ia(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Ta(t){return`${Gc}:${t}`}function Xc(t){const s=Ta(t);return Ca(s,null)}function Jc(t,s){try{const r=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,n=Ta(t);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Aa(t){return`${Yc}:${t}`}function Zc(t){const s=Aa(t);return Ca(s,null)}function Qc(t,s){try{const r=Aa(t);if(!s){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function el(){return{groupAssignments:[...is.groupAssignments],focusedGroup:is.focusedGroup,groupActiveTabIds:{...is.groupActiveTabIds},groupTabOrders:{...is.groupTabOrders},groupSizes:[...is.groupSizes]}}function tl(){const[t]=a.useState(()=>Ia(typeof window<"u"?window.innerWidth:1280)),[s,r]=a.useState(()=>new Map),[n,i]=a.useState(0),[o,c]=a.useState({}),[u,d]=a.useState({}),[x,l]=a.useState([]),[f,b]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,S]=a.useState(!1),m=a.useCallback(()=>{if(p)return;const h=Xc(t)??el();r(new Map(h.groupAssignments)),i(h.focusedGroup),c(h.groupActiveTabIds),d(h.groupTabOrders),l(h.groupSizes),S(!0)},[p,t]);return a.useEffect(()=>{p&&Jc(t,{groupAssignments:[...s.entries()],focusedGroup:n,groupActiveTabIds:o,groupTabOrders:u,groupSizes:x})},[p,t,s,n,o,u,x]),a.useEffect(()=>{const h=window.matchMedia("(max-width: 767px)"),y=g=>b(g.matches);return h.addEventListener("change",y),()=>h.removeEventListener("change",y)},[]),{groupAssignments:s,setGroupAssignments:r,focusedGroup:n,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:u,setGroupTabOrders:d,groupSizes:x,setGroupSizes:l,isMobile:f,hasHydratedStoredLayout:p,hydrateStoredLayout:m}}function sl({urlActiveTab:t,conversations:s,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:u,setSearchParams:d,historyModalOpen:x,activeConv:l,isRefreshingHistory:f,ides:b,handleRefreshHistory:p}){const S=a.useRef(!1),m=a.useRef(!1),h=a.useRef(null),y=a.useRef(!1);a.useEffect(()=>{if(!t||S.current||s.length===0)return;if(!i){o();return}const g=r(t);if(!g)return;const v=n.get(g.tabKey)??0;c(K=>({...K,[v]:g.tabKey})),u(v),S.current=!0,m.current=!0,h.current!=null&&(window.clearTimeout(h.current),h.current=null),d(K=>{const N=new URLSearchParams(K);return N.delete("activeTab"),N},{replace:!0})},[t,s,r,n,i,o,c,u,d]),a.useEffect(()=>{if(!(m.current||i)&&s.length!==0){if(!t){o(),m.current=!0;return}if(S.current){m.current=!0;return}if(h.current==null)return h.current=window.setTimeout(()=>{h.current=null,!(m.current||i)&&(o(),m.current=!0)},1500),()=>{h.current!=null&&(window.clearTimeout(h.current),h.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!x){y.current=!1;return}if(!l||y.current||f)return;const g=b.find(v=>v.id===l.ideId);g&&(!g.chats||g.chats.length===0)&&(y.current=!0,p())},[x,l,f,b,p]),a.useEffect(()=>{if(!l)return;let g=null,v=0,K=-1,N=0;const j=()=>{g=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(L=>L.offsetParent!==null);if(k.length===0){v<18&&(v+=1,g=requestAnimationFrame(j));return}let w=0;for(const L of k)L.scrollTop=L.scrollHeight,w+=L.scrollHeight;w===K?N+=1:(N=0,K=w),v+=1,!(N>=2||v>=18)&&(g=requestAnimationFrame(j))};return g=requestAnimationFrame(j),()=>{g!=null&&cancelAnimationFrame(g)}},[l==null?void 0:l.tabKey])}function rl({isMobile:t,location:s,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:u}){const[d,x]=a.useState(null),[l,f]=a.useState(null),b=a.useMemo(()=>{if(t||!n)return null;const y=u(n);return y&&!Ye(y)&&!ze(y)?y:null},[t,n,u]),p=a.useMemo(()=>{const y=d==null?void 0:d.ideId;if(!y)return null;const g=d!=null&&d.tabKey?o.find(v=>v.tabKey===d.tabKey):i?o.find(v=>v.tabKey===i):null;return(g==null?void 0:g.ideId)===y?g:o.find(v=>v.ideId===y&&v.streamSource==="native")||o.find(v=>v.ideId===y)||null},[o,d,i]),S=a.useMemo(()=>{if(p)return c.find(y=>y.id===p.ideId)},[c,p]);a.useEffect(()=>{b&&(x({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),f(b),r({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,r,b]);const m=a.useCallback(y=>{y&&(x({ideId:y.ideId,tabKey:y.streamSource==="native"?"native":y.tabKey}),f(y))},[]),h=a.useCallback(()=>{x(null),f(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:S,remoteDialogActiveConv:l,setRemoteDialogActiveConv:f,openRemoteDialog:m,closeRemoteDialog:h}}function Jt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ye(t)||ze(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function ps(t){return t&&(t.ideId||t.daemonId)||""}function ks(t,s){t(r=>[...r,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function vn({sendDaemonCommand:t,activeConv:s,updateIdeChats:r,setToasts:n,setLocalUserMessages:i,setClearedTabs:o}){const[c,u]=a.useState(!1),[d,x]=a.useState(!1),l=a.useCallback(async S=>{try{await t("standalone","launch_ide",{ideType:S,enableCdp:!0})}catch(m){console.error("Launch failed",m)}},[t]),f=a.useCallback(async(S,m)=>{try{const h=S||(s==null?void 0:s.daemonId)||"",y=await t(h,"switch_chat",{id:m,sessionId:m,...Jt(s)}),g=y==null?void 0:y.result;if((y==null?void 0:y.success)===!0||g==="switched"||g==="switched-by-title")return;g===!1||g==="not_found"?ks(n,"⚠️ Session tab not found — try refreshing history"):typeof g=="string"&&g.startsWith("error:")?ks(n,`⚠️ Switch error: ${g}`):ks(n,"⚠️ Session switch failed")}catch(h){console.error("Switch failed",h),ks(n,`❌ Switch failed: ${h.message||"connection error"}`)}},[s,t,n]),b=a.useCallback(async()=>{if(!(!s||c)){u(!0);try{const S=ps(s);await t(S,"new_chat",{...Jt(s)}),o(m=>({...m,[s.tabKey]:Date.now()})),i(m=>({...m,[s.tabKey]:[]}))}catch(S){console.error("New chat failed",S)}finally{u(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var S;if(!(!s||d)){x(!0);try{const m=ps(s),h=await t(m,"list_chats",{forceExpand:!0,...Jt(s)}),y=(h==null?void 0:h.chats)||((S=h==null?void 0:h.result)==null?void 0:S.chats);h!=null&&h.success&&Array.isArray(y)&&r(s.ideId,y)}catch(m){console.error("Refresh history failed",m)}finally{x(!1)}}},[s,d,t,r]);return{isCreatingChat:c,isRefreshingHistory:d,handleLaunchIde:l,handleSwitchSession:f,handleNewChat:b,handleRefreshHistory:p}}function nl(t,s){if(t.size!==s.size)return!1;for(const[r,n]of t)if(s.get(r)!==n)return!1;return!0}function al(t,s){return t.length!==s.length?!1:t.every((r,n)=>r===s[n])}function wn(t,s){const r=Object.keys(t),n=Object.keys(s);return r.length!==n.length?!1:r.every(i=>s[Number(i)]===t[Number(i)])}function Ns(t,s){const r=new Set(s),n=s.length>0?[0]:[];for(const[c,u]of t)!r.has(c)||u<=0||n.includes(u)||n.push(u);n.sort((c,u)=>c-u);const i={};n.forEach((c,u)=>{i[c]=u}),n.length===0&&(i[0]=0);const o=new Map;for(const[c,u]of t){if(!r.has(c)||u<=0)continue;const d=i[u];typeof d=="number"&&d>0&&o.set(c,d)}return{assignments:o,groupCount:Math.max(1,n.length),mapping:i,usedGroups:n}}function jn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=s[Number(n)];typeof o=="number"&&(r[o]=i)}return r}function il(t,s,r){if(s.length===0)return 0;if(typeof r[t]=="number")return r[t];const n=[...s].reverse().find(i=>i<t)??s[0];return r[n]??0}function ol(t,s,r){if(s.length<=1)return[];const n=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=n.length===s.length?n:Array(r).fill(100/r),o=i.reduce((c,u)=>c+u,0);return o>0?i.map(c=>c/o*100):Array(r).fill(100/r)}function kn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=Number(n);r[o>=s?o+1:o]=i}return r}function Nn(t){return Array(t).fill(100/t)}function cl({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:r,setGroupActiveTabIds:n,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:u,visibleConversations:d,visibleTabKeys:x}){const l=a.useRef(null),f=a.useMemo(()=>Ns(t,x),[t,x]),b=f.assignments,p=a.useMemo(()=>u?1:f.groupCount,[f.groupCount,u]),S=p>1,m=a.useCallback((N,j)=>{s(k=>{const w=new Map(Ns(k,x).assignments);return j===0?w.delete(N):w.set(N,j),w}),n(k=>({...k,[j]:N})),r(j)},[s,x,n,r]),h=a.useCallback(N=>{s(j=>{const k=Ns(j,x).assignments,w=new Map;for(const[L,M]of k)M!==N&&(M>N?w.set(L,M-1):w.set(L,M));return w}),c(j=>{if(j.length<=1)return[];const k=[...j];k.splice(N,1);const w=k.reduce((L,M)=>L+M,0);return w>0?k.map(L=>L/w*100):[]}),r(0)},[s,x,c,r]),y=a.useCallback((N,j)=>{j.preventDefault();const k=l.current;if(!k)return;const w=j.clientX,L=k.offsetWidth,M=o.length===p?[...o]:Nn(p),$=D=>{const W=(D.clientX-w)/L*100,E=[...M];E[N]=Math.max(15,M[N]+W),E[N+1]=Math.max(15,M[N+1]-W),c(E)},U=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",U),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",$),document.addEventListener("mouseup",U)},[o,p,c]),g=a.useCallback((N,j,k)=>{if(p>=4)return;const w=k==="left"?j:j+1;s(L=>{const M=Ns(L,x).assignments,$=new Map;for(const U of d){const D=M.get(U.tabKey)??0,_=D>=w?D+1:D;_>0&&$.set(U.tabKey,_)}return w>0&&$.set(N,w),$}),c(L=>{const M=L.length===p?[...L]:Nn(p),$=M[j]??100/p,U=Math.max(15,$/2),D=Math.max(15,$/2),_=[...M];_[j]=U,_.splice(w,0,D);const W=_.reduce((E,H)=>E+H,0);return _.map(E=>E/W*100)}),n(L=>{const M=kn(L,w);return M[w]=N,M}),i(L=>{const M=kn(L,w);return M[w]=[N],M}),r(w)},[p,s,x,d,c,n,i,r]);a.useEffect(()=>{nl(t,b)||s(b)},[t,b,s]),a.useEffect(()=>{const{mapping:N,usedGroups:j}=f;n(k=>{const w=jn(k,N);return wn(k,w)?k:w}),i(k=>{const w=jn(k,N);return wn(k,w)?k:w}),r(k=>{const w=u?0:il(k,j,N);return k===w?k:w}),c(k=>{const w=u?[]:ol(k,j,f.groupCount);return al(k,w)?k:w})},[f,u,n,i,r,c]);const v=a.useMemo(()=>{const N=Array.from({length:p},()=>[]);for(const j of d){const k=b.get(j.tabKey)??0,w=Math.min(k,p-1);N[w].push(j)}return N},[d,b,p]),K=a.useCallback(()=>{s(new Map),r(0)},[s,r]);return{containerRef:l,normalizedGroupAssignments:b,numGroups:p,isSplitMode:S,groupedConvs:v,moveTabToGroup:m,closeGroup:h,handleResizeStart:y,splitTabRelative:g,clearAllSplits:K}}function ll({ides:t,sendDaemonCommand:s}){const r="0.8.23",n=a.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const l=x.version||x.daemonVersion||null;return!l||!r?!1:l!==r}),[r,t]),[i,o]=a.useState(!1),[c,u]=a.useState({}),d=a.useCallback(async x=>{var l,f;u(b=>({...b,[x]:"upgrading"}));try{const b=await s(x,"daemon_upgrade",{});(l=b==null?void 0:b.result)!=null&&l.upgraded||(f=b==null?void 0:b.result)!=null&&f.success?u(p=>({...p,[x]:"done"})):u(p=>({...p,[x]:"error"}))}catch{u(b=>({...b,[x]:"error"}))}},[s]);return{versionMismatchDaemons:n,appVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:d}}function Sn(t){return!t||typeof t!="object"?t:t.result&&typeof t.result=="object"?t.result:t}function _a(t){return t instanceof Error?t.message:String(t||"")}function Cn(t){const s=_a(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Ys({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:r,setActionLogs:n,isStandalone:i}){const[o,c]=a.useState(!1),[u,d]=a.useState(!1),x=a.useRef(!1),l=a.useRef(null),f=a.useCallback(async m=>{if(!s)return;const h=m.trim();if(!h||x.current)return;const y=s.tabKey,g=Date.now(),v=l.current;if(v&&v.tabKey===y&&v.message===h&&g-v.timestamp<2e3)return;x.current=!0,d(!0),l.current={tabKey:y,message:h,timestamp:g};const K=`${g}-${Math.random().toString(36).slice(2,8)}`,N={role:"user",content:h,timestamp:g,_localId:K};r(j=>({...j,[y]:[...j[y]||[],N]}));try{const j=ps(s);if(!j)return;const k=await t(j,"send_chat",{message:h,text:h,...Jt(s)}),w=Sn(k);if(w!=null&&w.deduplicated||(w==null?void 0:w.sent)===!1){r(L=>({...L,[y]:(L[y]||[]).filter(M=>M._localId!==K)}));return}if((w==null?void 0:w.success)===!1)throw new Error((w==null?void 0:w.error)||"Send failed");setTimeout(()=>{const L=Date.now()-6e4;r(M=>{const $=M[y];if(!$)return M;const U=$.filter(D=>D.timestamp>L);return U.length===$.length?M:{...M,[y]:U}})},6e4)}catch(j){const k=_a(j);k.toLowerCase().includes("provider sendmessage did not confirm send")?console.warn("Send not confirmed by provider script:",k):console.error("Send failed",j),r(w=>({...w,[y]:(w[y]||[]).filter(L=>L._localId!==K)}))}finally{x.current=!1,d(!1)}},[s,t,r]),b=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(m){console.error("Relaunch failed",m)}},[s,t]),p=a.useCallback(async m=>{if(s)try{const y=(s.modalButtons||[]).indexOf(m),g=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),v=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),K=ps(s);if(!K)return;const N=await t(K,"resolve_action",{button:m,action:v?"approve":"reject",...y>=0&&{buttonIndex:y},...Jt(s)});Sn(N).success||n(k=>[...k,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(h){Cn(h)||console.error("[ModalButton] Error:",h),n(y=>[...y,{ideId:s.tabKey,text:Cn(h)?`⚠️ **${m}** unavailable`:`❌ **${m}** error`,timestamp:Date.now()}])}},[s,t,n]),S=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:u,isFocusingAgent:o,handleSendChat:f,handleRelaunch:b,handleModalButton:p,handleFocusAgent:S}}const Br=a.memo(function({activeConv:s,clearToken:r,isCliTerminal:n,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:u,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m=!0}){return e.jsxs(e.Fragment,{children:[e.jsx(na,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(Fs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:u,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:n?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx($o,{activeConv:s,clearToken:r,terminalRef:o,handleSendChat:d,isSendingChat:x,isVisible:n})}),!n&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(br,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m})})]}):e.jsx(br,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce&&t.isInputActive===s.isInputActive);function dl({selectedConversation:t,isAcp:s,isStandalone:r,selectedIdeEntry:n,actionLogs:i,userName:o,isSendingChat:c,isFocusingAgent:u,onBack:d,onOpenNativeConversation:x,onOpenMachine:l,onOpenHistory:f,onOpenRemote:b,onHideConversation:p,onStopCli:S,cliViewMode:m,onSetCliViewMode:h,handleSendChat:y,handleFocusAgent:g,handleModalButton:v,handleRelaunch:K}){const N=a.useRef(null),j=Ye(t)&&!s,k=j&&m==="terminal",w=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${w} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:d,type:"button","aria-label":"Back",children:e.jsx(Nr,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(oa,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>x(t),onOpenMachine:()=>l(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[j&&m&&e.jsx(Mr,{mode:m,onChange:h,compact:!0}),j&&S&&e.jsx("button",{onClick:()=>{S(t)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(Ut,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(Sr,{size:14})}),!s&&!j&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>b(t),type:"button",children:e.jsx(ct,{size:14})}),p&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(t),type:"button",title:"Close chat",children:e.jsx(Ut,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Br,{activeConv:t,clearToken:0,isCliTerminal:k,ideEntry:n,terminalRef:N,handleModalButton:v,handleRelaunch:K,handleSendChat:y,isSendingChat:c,handleFocusAgent:g,isFocusingAgent:u,actionLogs:i,userName:o})})]})}const cr={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function ul(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Ma(){const[t,s]=a.useState("unix"),[r,n]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":r;a.useEffect(()=>{s(ul())},[]);const u=a.useCallback(()=>{navigator.clipboard.writeText(cr[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:cr[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:cr[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Pa({section:t,onSectionChange:s}){const r=[{key:"machines",label:"Machines",icon:ct},{key:"chats",label:"Chats",icon:Nt}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:i,icon:o})=>{const c=t===n;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(n),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(o,{size:15})}),e.jsx("span",{children:i})]},n)})})})}function Ss({title:t,className:s=""}){return e.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${s}`,children:e.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:t})})}function Gt({children:t,className:s=""}){return e.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function os({icon:t,title:s,subtitle:r,children:n}){return e.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Cs({item:t,type:s,getAvatarText:r,onOpenConversation:n}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`group flex items-start gap-3.5 px-4 py-3.5 w-full text-left relative overflow-hidden transition-colors active:scale-[0.995] ${i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":"bg-transparent"} ${c?"opacity-70 saturate-50":""}`,onClick:()=>n(t.conversation),type:"button",children:[i||o?e.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,e.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary shadow-glow":o?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":"bg-bg-primary border border-border-subtle text-text-secondary"}`,style:i?{color:"var(--accent-on-primary)"}:void 0,children:r(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:ra(t.timestamp)})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[t.conversation.displaySecondary,t.conversation.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ct,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]},t.conversation.tabKey)}function In({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function ml({section:t,attentionItems:s,unreadItems:r,workingItems:n,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:u,onOpenConversation:d,onShowConversation:x,onShowAllHidden:l,onOpenMachine:f,onOpenSettings:b,onSectionChange:p,wsStatus:S="connected",isStandalone:m=!1}){const h=S==="disconnected"||S==="reconnecting"||S==="offline"||S==="auth_failed",y=c.length>0,g=s.length>0||r.length>0||n.length>0||i.length>0,v=t==="machines"?"Machines":"Chats",K=m?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",N=m?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]";return e.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${K}`,children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:v}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||r.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(Vs,{size:13}),e.jsx("span",{children:s.length+r.length})]}),e.jsx("button",{onClick:b,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:e.jsx(zs,{size:18})})]})]})}),e.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${N}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:h?e.jsx(os,{icon:e.jsx(In,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:S==="offline"?"Your device appears to be offline. Waiting for network…":S==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(os,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:m?"Waiting for your daemon":"Connect your first machine",subtitle:m?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!m&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Ma,{})})}):e.jsx(Gt,{children:c.map((j,k)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${k>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(j.id),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:u(j.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:j.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[j.unread," new"]}):j.total>0?`${j.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:j.subtitle}),j.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[j.total," chat",j.total!==1?"s":"",j.unread>0?` · ${j.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},j.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Needs attention",className:"mb-0"}),e.jsx(Gt,{children:s.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"needs_attention",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(Gt,{children:r.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"task_complete",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(Gt,{children:n.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"working",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[i.length>0&&e.jsx(Ss,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(Gt,{children:i.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"earlier",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))}):g?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):h?e.jsx(os,{icon:e.jsx(In,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):y?e.jsx(os,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(Nt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open the machine screen, choose a workspace, then launch your first IDE, CLI, or ACP session."}):e.jsx(os,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:l,children:"Restore all"})]}),e.jsx(Gt,{className:"bg-bg-secondary/25",children:o.map((j,k)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] opacity-50 saturate-0 ${k>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(j),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-border-subtle text-text-secondary",children:u(j.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.displayPrimary}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[j.displaySecondary,j.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ct,{size:11})," ",j.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},j.tabKey))})]})]}),e.jsx(Pa,{section:t,onSectionChange:p})]})}function pl(t){const s=t.trim();if(!s)return null;if(s.startsWith("~"))return s;if(/^[A-Za-z]:$/.test(s))return`${s[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(s))return`${s[0].toUpperCase()}:${s.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(s))return`${s[0].toUpperCase()}:\\${s.slice(2).replace(/[\\/]+/g,"\\")}`;const r=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),i=(r[2]||"").replace(/[\\/]+/g,"\\");return i?`${n}:\\${i}`:`${n}:\\`}return null}function Xs(t,s=[]){if(t==="win32"){for(const r of s){if(typeof r!="string")continue;const n=pl(r);if(n)return n}return"C:\\"}for(const r of s){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function fl(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const r=s.includes("\\")?"\\":"/",n=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}async function Kr(t,s,r){const n=await t(s,"file_list_browse",{path:r});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Could not browse folder");const i=typeof(n==null?void 0:n.path)=="string"?n.path:r,o=i.includes("\\")?"\\":"/",c=(d,x)=>/^[A-Za-z]:\\?$/.test(d)?`${d.replace(/\\?$/,"\\")}${x}`:d==="/"||d==="\\"?`${o}${x}`:`${d.replace(/[\\/]+$/,"")}${o}${x}`,u=Array.isArray(n==null?void 0:n.files)?n.files.filter(d=>(d==null?void 0:d.type)==="directory"&&typeof(d==null?void 0:d.name)=="string").map(d=>({name:d.name,path:c(i,d.name)})).sort((d,x)=>d.name.localeCompare(x.name)):[];return{path:i,directories:u}}function Js({title:t,description:s,currentPath:r,directories:n,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:u,onNavigate:d,onConfirm:x}){const[l,f]=a.useState(r);a.useEffect(()=>{f(r)},[r]);const b=fl(r),p=l.trim();return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:u,"aria-label":"Close folder browser",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!b||i||d(b)},disabled:!b||i,children:[e.jsx(Nr,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:l,onChange:S=>f(S.target.value),onKeyDown:S=>{S.key!=="Enter"||!p||i||(S.preventDefault(),d(p))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!p||i||d(p)},disabled:!p||i,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):n.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:n.map(S=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(S.path),children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Qt,{size:17})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:S.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:S.path})]})]},S.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:u,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>x(p||r),disabled:!p&&!r||i,children:c})]})]})})}function Wr({title:t,description:s,details:r,workspaceOptions:n,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:u=!1,onConfirm:d,onCancel:x}){const l=n==null?void 0:n.find(f=>f.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:x,"aria-label":"Close launch confirmation",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n&&n.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:f=>o(f.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:u,children:n.map(f=>e.jsx("option",{value:f.key,children:f.label},f.key))}),(l==null?void 0:l.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:l.description})]}),r.map(f=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:f.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:f.value})]},`${f.label}:${f.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:x,disabled:u,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:d,disabled:u,children:[e.jsx(Tr,{size:14}),u?"Launching…":c]})]})]})})}function Tn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function Wt(t){const{machine:s,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const d of s.workspaces||[])o.push({key:`saved:${d.id}`,label:`${d.id===s.defaultWorkspaceId?"⭐ ":""}${Tn(d.path,d.label)}`,description:d.path,workspaceId:d.id,workspacePath:d.path});const c=(r==null?void 0:r.trim())||"",u=c?(s.workspaces||[]).find(d=>d.path===c):null;if(c&&!u&&o.push({key:`custom:${c}`,label:Tn(c),description:c,workspaceId:null,workspacePath:c}),n){const d=`saved:${n}`;if(o.some(x=>x.key===d))return{options:o,selectedKey:d}}return u?{options:o,selectedKey:`saved:${u.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function xl({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:u,isStandalone:d,section:x,showBottomNav:l,onBack:f,onSectionChange:b,onOpenConversation:p,onOpenRecent:S,onOpenMachineDetails:m,onMachineUpgrade:h,onLaunchDetectedIde:y,onAddWorkspace:g,onBrowseDirectory:v,onLaunchWorkspaceProvider:K}){var Fe,Qe,Ge,q;const N=(z,se,T)=>z?"ide":se>0?"cli":T>0?"acp":null,[j,k]=a.useState(!1),w=z=>z==="ide"?"IDE":z==="cli"?"CLI":"ACP",L=r.slice(0,4),M=s.slice(0,3),$=(((Fe=t.detectedIdes)==null?void 0:Fe.length)||0)>0,U=a.useMemo(()=>t.workspaces||[],[t]),D=t.defaultWorkspaceId||null,[_,W]=a.useState(D||((Qe=U[0])==null?void 0:Qe.id)||""),[E,H]=a.useState(""),[X,O]=a.useState(""),[P,R]=a.useState([]),[F,Y]=a.useState(!1),[me,_e]=a.useState(""),[G,le]=a.useState(!1),[J,he]=a.useState(N($,n.length,i.length)),te=a.useRef(null),[fe,ye]=a.useState(null),oe=a.useRef("__home__"),[de,ue]=a.useState("__home__"),[Ce,Q]=a.useState(!1),ie=a.useRef(null),ee=_==="__custom__"?E.trim():((Ge=U.find(z=>z.id===_))==null?void 0:Ge.path)||"",ge=_==="__custom__"&&!!ee&&u.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(u.message),C=_!=="__custom__"&&((q=U.find(z=>z.id===_))==null?void 0:q.path)||"",ne=a.useCallback(async z=>{Y(!0),_e("");try{const se=await v(z);O(se.path),H(se.path),R(se.directories)}catch(se){_e(se instanceof Error?se.message:"Could not load folder")}finally{Y(!1)}},[v]),ve=a.useCallback(()=>{var se,T;W("__custom__"),le(!0);const z=Xs(t.platform,[E.trim(),C,(se=U.find(A=>A.id===D))==null?void 0:se.path,(T=U[0])==null?void 0:T.path]);ne(z)},[E,D,ne,C,t.platform,U]),B=a.useCallback((z,se)=>{te.current=se,oe.current=z.selectedWorkspaceKey||"__home__",ue(z.selectedWorkspaceKey||"__home__"),ye(z)},[]),Z=a.useCallback(()=>{te.current&&(Q(!0),te.current().finally(()=>{te.current=null,Q(!1),ye(null)}))},[]);a.useEffect(()=>{var z;ie.current!==t.id&&(ie.current=t.id,W(D||((z=U[0])==null?void 0:z.id)||"__custom__"),H(""),O(""),R([]),_e(""),le(!1),he(N($,n.length,i.length)))},[i.length,n.length,D,$,t.id,U]),a.useEffect(()=>{var z;_!=="__custom__"&&(_&&U.some(se=>se.id===_)||W(D||((z=U[0])==null?void 0:z.id)||"__custom__"))},[D,_,U]),a.useEffect(()=>{J==="ide"&&$||J==="cli"&&n.length>0||J==="acp"&&i.length>0||he(N($,n.length,i.length))},[J,i.length,n.length,$]);const re=a.useMemo(()=>L.map(z=>({key:`recent-launch:${z.id}`,primary:z.label,secondary:`${w(z.kind)}${z.subtitle?` · ${z.subtitle}`:""}`,onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspacePath:z.workspace});B({title:`Launch ${z.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:w(z.kind)},...z.providerType?[{label:"Provider",value:z.providerType}]:[]]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),await S({...z,workspace:(A==null?void 0:A.workspacePath)??null})})}})),[D,S,B,L,U]),je=a.useMemo(()=>M.map(z=>({key:`recent-chat:${z.conversation.tabKey}`,primary:z.conversation.displayPrimary,secondary:`Chat${z.conversation.displaySecondary?` · ${z.conversation.displaySecondary}`:""}${z.timestamp?` · ${ra(z.timestamp)}`:""}`,unread:z.unread,onClick:()=>p(z.conversation)})),[p,M]),ke=j?re:re.slice(0,4),Pe=re.length>0,Be=je.length>0,We=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`flex items-center justify-between gap-3 ${We} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:f,type:"button","aria-label":"Back",children:e.jsx(Nr,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:gt(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[Be&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:je.map(z=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${z.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:z.secondary})]},z.key))})]}),Pe&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:ke.map(z=>e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:z.secondary})]},z.key))}),re.length>4&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>k(z=>!z),children:j?"Show fewer":`Show ${re.length-4} more`})})]}),($||n.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:_,onChange:z=>{const se=z.target.value;if(W(se),se==="__custom__"){ve();return}H("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:U.length>0?e.jsxs(e.Fragment,{children:[U.map(z=>e.jsxs("option",{value:z.id,children:[z.id===D?"⭐ ":"",Gs(z.path,z.label)||z.path]},z.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),_==="__custom__"&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx("div",{className:"rounded-2xl border border-border-default/80 bg-bg-primary/80 px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Qt,{size:17})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.08em] text-text-muted mb-1",children:"Selected folder"}),e.jsx("div",{className:"text-[12px] leading-relaxed text-text-primary break-all",children:ee||X||"No folder selected yet."})]})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-secondary text-[12px] font-bold",onClick:ve,children:"Select workspace…"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[12px] font-bold disabled:opacity-40",onClick:()=>{ee&&g(ee)},disabled:!ee||F,children:"Save as workspace"})]})]}),ee&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[$&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="ide"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("ide"),children:"IDE"}),n.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="cli"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="acp"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("acp"),children:"ACP"})]}),J&&e.jsxs("div",{className:"flex flex-col gap-2.5 px-4 pt-3",children:[e.jsx("div",{className:"text-xs font-bold text-text-secondary",children:J==="ide"?"Choose an IDE":J==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:J==="ide"?(t.detectedIdes||[]).slice(0,6).map(z=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ee});B({title:`Launch ${z.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:z.name}]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),y(z.type,{workspacePath:(A==null?void 0:A.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:z.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee||"Use selected workspace"})]},z.type)):(J==="cli"?n:i).map(z=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ee});B({title:`Launch ${z.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${J.toUpperCase()}`,workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:J.toUpperCase()},{label:"Provider",value:z.displayName}]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),K(J,z.type,{workspaceId:(A==null?void 0:A.workspaceId)??null,workspacePath:(A==null?void 0:A.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[z.icon?`${z.icon} `:"",z.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee||"Use selected workspace"})]},z.type))})]}),u.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${u.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[u.message,ge&&e.jsx("div",{className:"mt-2",children:e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[34px] px-4 rounded-lg bg-surface-primary text-text-primary font-bold text-xs",onClick:()=>g(ee,{createIfMissing:!0}),children:"Create folder"})})]})]}),e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:h,children:[e.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",c]}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:m,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),G&&e.jsx(Js,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:X,directories:P,busy:F,error:me,confirmLabel:"Use this folder",onClose:()=>le(!1),onNavigate:z=>{ne(z)},onConfirm:z=>{H(z),W("__custom__"),le(!1)}}),fe&&e.jsx(Wr,{title:fe.title,description:fe.description,details:fe.details,workspaceOptions:fe.workspaceOptions,selectedWorkspaceKey:de,onWorkspaceChange:z=>{oe.current=z,ue(z)},confirmLabel:fe.confirmLabel,busy:Ce,onConfirm:Z,onCancel:()=>{te.current=null,ye(null)}}),l&&e.jsx(Pa,{section:x,onSectionChange:b})]})}function hl(t){return Lr(t)}function An(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1],r=hl(s==null?void 0:s.content);return r||(t.title?t.title:t.displaySecondary||"No messages yet")}function bl(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Is(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function gl(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function _n(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function yl(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function vl(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function wl({conversations:t,hiddenConversations:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,userName:d,requestedActiveTabKey:x,onRequestedActiveTabConsumed:l,requestedMachineId:f,onRequestedMachineConsumed:b,requestedMobileSection:p,onRequestedMobileSectionConsumed:S,onOpenHistory:m,onOpenRemote:h,onStopCli:y,wsStatus:g,isConnected:v,onShowHiddenConversation:K,onShowAllHiddenConversations:N,onHideConversation:j}){const[k,w]=a.useState(()=>{var T;return((T=t[0])==null?void 0:T.tabKey)||null}),[L,M]=a.useState(()=>t[0]?"chat":"inbox"),[$,U]=a.useState("chats"),[D,_]=a.useState(null),[W,E]=a.useState("inbox"),[H,X]=a.useState("idle"),[O,P]=a.useState(""),[R,F]=a.useState(null),Y=a.useRef(null),me=ts(),_e="0.8.23",G=a.useMemo(()=>t.find(T=>T.tabKey===k)||t[0]||null,[t,k]),le=a.useMemo(()=>G?r.find(T=>T.id===G.ideId):void 0,[r,G]),J=a.useMemo(()=>!G||ze(G)||!Ye(G)?null:es(G),[G]),he=a.useMemo(()=>r.filter(T=>T.type==="adhdev-daemon"||T.daemonMode).sort(Ar),[r]),te=a.useMemo(()=>he.find(T=>T.id===D)||null,[he,D]),fe=a.useMemo(()=>bs(r),[r]),ye=Ys({sendDaemonCommand:i,activeConv:G||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),oe=a.useCallback(T=>{if(!T||!T.sessionId)return;const A=ds(T,fe),ae=Math.max(Date.now(),Dt(T),A.lastUpdated||0);Is("mark_read:start",{tabKey:T.tabKey,sessionId:T.sessionId,displayPrimary:T.displayPrimary,inboxBucket:A.inboxBucket,unread:A.unread,lastSeenAt:A.lastSeenAt,lastUpdated:A.lastUpdated,activityAt:Dt(T),readAt:ae}),i(T.daemonId||T.ideId,"mark_session_seen",{sessionId:T.sessionId,seenAt:ae}).then(ce=>{Is("mark_read:result",{tabKey:T.tabKey,sessionId:T.sessionId,result:ce})}).catch(ce=>{Is("mark_read:error",{tabKey:T.tabKey,sessionId:T.sessionId,error:ce instanceof Error?ce.message:String(ce)})})},[fe,i]);a.useEffect(()=>{var A;if(!G){M("inbox"),w(((A=t[0])==null?void 0:A.tabKey)||null),Y.current=null;return}if(L!=="chat"){Y.current=null;return}const T=`${G.tabKey}:${G.sessionId||""}`;Y.current!==T&&(Y.current=T,oe(G))},[t,oe,L,G]),a.useEffect(()=>{if(!x)return;const T=t.find(A=>A.tabKey===x);T&&(w(T.tabKey),M("chat"),l==null||l())},[t,l,x]),a.useEffect(()=>{if(!f)return;const T=he.find(A=>A.id===f);T&&(_(T.id),X("idle"),P(""),U("machines"),E("inbox"),M("machine"),b==null||b())},[he,b,f]),a.useEffect(()=>{p&&(U(p),M("inbox"),S==null||S())},[S,p]);const de=a.useMemo(()=>t.map(T=>{const A=L==="chat"&&(G==null?void 0:G.tabKey)===T.tabKey,ae=us(T,fe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:A}),ce=Dt(T),Ie=An(T);return{conversation:T,timestamp:ce,preview:Ie,unread:ae.unread,requiresAction:ae.requiresAction,isWorking:ae.isWorking,inboxBucket:ae.inboxBucket}}),[t,fe,L,G]);a.useEffect(()=>{const T=de.filter(A=>A.inboxBucket==="task_complete"||A.unread);T.length!==0&&Is("inbox_state",{screen:L,selectedTabKey:k,items:T.map(A=>{const ae=ds(A.conversation,fe);return{liveState:ae,tabKey:A.conversation.tabKey,sessionId:A.conversation.sessionId,displayPrimary:A.conversation.displayPrimary,serverBucket:ae.inboxBucket,computedBucket:A.inboxBucket,serverUnread:ae.unread,computedUnread:A.unread,lastSeenAt:ae.lastSeenAt,lastUpdated:ae.lastUpdated,activityAt:Dt(A.conversation)}})})},[de,fe,L,k]);const ue=a.useMemo(()=>de.filter(T=>T.requiresAction),[de]),Ce=a.useMemo(()=>de.filter(T=>T.unread&&!T.requiresAction),[de]),Q=a.useMemo(()=>de.filter(T=>!T.unread&&!T.requiresAction&&T.isWorking),[de]),ie=a.useMemo(()=>de.filter(T=>!T.unread&&!T.requiresAction&&!T.isWorking),[de]),ee=a.useMemo(()=>te?de.filter(T=>T.conversation.daemonId===te.id||T.conversation.ideId===te.id):[],[de,te]),ge=a.useMemo(()=>{if(!te)return[];const T=te.recentLaunches||[];return T.length>0?T.map(A=>({id:A.id,label:A.title||A.providerName||A.providerType,kind:A.kind,providerType:A.providerType,providerSessionId:A.providerSessionId,subtitle:A.currentModel||A.workspace||void 0,workspace:A.workspace,currentModel:A.currentModel})):r.filter(A=>!A.daemonMode&&A.daemonId===te.id).map(A=>{var ce,Ie,Oe,Ee,Te;const ae=ms(A)?"cli":Xt(A)?"acp":"ide";return{id:`${ae}:${A.type}:${A.workspace||""}`,label:((ce=A.activeChat)==null?void 0:ce.title)||(ms(A)?A.cliName||A.type:Xt(A)&&A.cliName||A.type),kind:ae,providerType:A.type,providerSessionId:A.providerSessionId,subtitle:Xt(A)?A.currentModel||A.workspace||void 0:A.workspace||void 0,workspace:A.workspace||void 0,currentModel:A.currentModel,timestamp:((Te=(Ee=(Oe=(Ie=A.activeChat)==null?void 0:Ie.messages)==null?void 0:Oe.at)==null?void 0:Ee.call(Oe,-1))==null?void 0:Te.timestamp)||0}}).sort((A,ae)=>ae.timestamp-A.timestamp).map(({timestamp:A,...ae})=>ae)},[r,te]),C=(te==null?void 0:te.version)||(te==null?void 0:te.daemonVersion)||null,ne=!!te&&!!C&&!0&&C!==_e,ve=a.useMemo(()=>(te==null?void 0:te.availableProviders)||[],[te]),B=a.useMemo(()=>ve.filter(T=>T.category==="cli").map(T=>({type:T.type,displayName:T.displayName||T.type,icon:T.icon})),[ve]),Z=a.useMemo(()=>ve.filter(T=>T.category==="acp").map(T=>({type:T.type,displayName:T.displayName||T.type,icon:T.icon})),[ve]),re=a.useMemo(()=>{const T=new Map;for(const A of de){const ae=A.conversation.daemonId||A.conversation.ideId,ce=T.get(ae);ce?ce.push(A):T.set(ae,[A])}return he.map(A=>{const ae=T.get(A.id)||[],ce=[...ae].sort((Ue,et)=>et.timestamp-Ue.timestamp)[0]||null,Ie=(ce==null?void 0:ce.conversation)||null,Oe=hr(A),Ee=ae.filter(Ue=>Ue.unread||Ue.requiresAction).length,Te=A.status==="online"?"Connected":A.status||"Unknown",He=[A.platform||"machine",Te].filter(Boolean);return{id:A.id,label:gt(A,{fallbackId:A.id}),subtitle:He.join(" · "),unread:Ee,total:ae.length,latestConversation:Ie,latestTimestamp:(ce==null?void 0:ce.timestamp)||0,fallbackActivityAt:Oe,preview:Ie?`${Ie.displayPrimary} · ${An(Ie)}`:"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((A,ae)=>{const ce=A.latestTimestamp||A.fallbackActivityAt||0,Ie=ae.latestTimestamp||ae.fallbackActivityAt||0;return Ie!==ce?Ie-ce:A.label.localeCompare(ae.label)})},[de,he]),je=a.useCallback(T=>{w(T.tabKey),M("chat"),oe(T)},[oe]),ke=a.useCallback(T=>{const A=t.find(ae=>ae.ideId===T.ideId&&ae.streamSource==="native");A&&(w(A.tabKey),M("chat"),oe(A))},[t,oe]),Pe=a.useCallback(()=>{oe(G),M("inbox")},[oe,G]),Be=a.useCallback(T=>{_(T),X("idle"),P(""),F(null),U("machines"),E("inbox"),M("machine")},[]),We=a.useCallback(T=>{var ae;const A=T.daemonId||((ae=T.ideId)==null?void 0:ae.split(":")[0])||T.ideId;A&&(_(A),X("idle"),P(""),F(null),U("machines"),E("chat"),M("machine"))},[]),Fe=a.useCallback(()=>{F(null),M(W)},[W]),Qe=a.useCallback(async(T,A,ae)=>{var ce;try{X("loading"),P(`Launching ${A}…`);const Ie={ideType:A,enableCdp:!0};(ce=ae==null?void 0:ae.workspacePath)!=null&&ce.trim()&&(Ie.workspace=ae.workspacePath.trim()),await i(T,"launch_ide",Ie),X("done"),P(`${A} launch requested`)}catch(Ie){X("error"),P(Ie instanceof Error?Ie.message:"Launch IDE failed"),console.error("Launch IDE failed",Ie)}},[i]),Ge=a.useCallback(async(T,A,ae)=>{if(A.trim())try{X("loading"),P(ae!=null&&ae.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await i(T,"workspace_add",{path:A.trim(),createIfMissing:(ae==null?void 0:ae.createIfMissing)===!0});if(ce!=null&&ce.success){X("done"),P(ae!=null&&ae.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}X("error"),P((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){X("error"),P(ce instanceof Error?ce.message:"Could not save workspace")}},[i]),q=a.useCallback(async T=>{var A,ae,ce,Ie,Oe,Ee;try{X("loading"),P("Starting daemon upgrade…");const Te=await i(T,"daemon_upgrade",{});if((A=Te==null?void 0:Te.result)!=null&&A.alreadyLatest){X("done"),P(`Already on v${((ae=Te==null?void 0:Te.result)==null?void 0:ae.version)||"latest"}.`);return}if((ce=Te==null?void 0:Te.result)!=null&&ce.upgraded||(Ie=Te==null?void 0:Te.result)!=null&&Ie.success){X("done"),P(`Upgrade to v${((Oe=Te==null?void 0:Te.result)==null?void 0:Oe.version)||"latest"} started. Daemon is restarting…`);return}X("error"),P(((Ee=Te==null?void 0:Te.result)==null?void 0:Ee.error)||"Upgrade failed")}catch(Te){X("error"),P(Te instanceof Error?Te.message:"Upgrade failed")}},[i]),z=a.useCallback(async(T,A,ae,ce)=>{var Ee;const Ie=Date.now(),Oe={machineId:T,kind:A,providerType:ae,workspaceId:(ce==null?void 0:ce.workspaceId)||null,workspacePath:(ce==null?void 0:ce.workspacePath)||null,resumeSessionId:(ce==null?void 0:ce.resumeSessionId)||null,startedAt:Ie};try{X("loading"),P(`Launching ${ae}…`),F(Oe);const Te={cliType:ae};(Ee=ce==null?void 0:ce.workspacePath)!=null&&Ee.trim()?Te.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(Te.workspaceId=ce.workspaceId),ce!=null&&ce.resumeSessionId&&(Te.resumeSessionId=ce.resumeSessionId);const He=await i(T,"launch_cli",Te),Ue=(He==null?void 0:He.result)||He,et=(Ue==null?void 0:Ue.sessionId)||(Ue==null?void 0:Ue.id);if(He!=null&&He.success&&et){F(null),X("done"),P(`${ae} launched`),me(`/dashboard?activeTab=${encodeURIComponent(et)}`);return}if(He!=null&&He.success){X("loading"),P(`${ae} launch requested — waiting for session…`);return}F(null),X("error"),P((He==null?void 0:He.error)||(Ue==null?void 0:Ue.error)||`Could not launch ${A.toUpperCase()} workspace`)}catch(Te){if(yl(Te)){X("loading"),P(`${ae} launch requested — waiting for session…`);return}F(null),X("error"),P(Te instanceof Error?Te.message:`Could not launch ${A.toUpperCase()} workspace`)}},[me,i]);a.useEffect(()=>{var ce;if(!R)return;const T=_n(R.workspacePath),A=r.find(Ie=>{var et,mt,pt,ut;if(!Ie||Ie.type==="adhdev-daemon"||Ie.daemonMode||gl(Ie.daemonId||Ie.id)!==R.machineId||(Ie.transport==="acp"?"acp":Ie.transport==="pty"?"cli":null)!==R.kind||String(Ie.agentType||Ie.ideType||Ie.type||"")!==R.providerType)return!1;const He=String(Ie.providerSessionId||"");if(R.resumeSessionId&&He)return He===R.resumeSessionId;if(T){const ft=_n(Ie.workspace||Ie.runtimeWorkspaceLabel);return ft?ft===T:!1}return Number(Ie.lastUpdated||Ie._lastUpdate||Ie.timestamp||((ut=(pt=(mt=(et=Ie.activeChat)==null?void 0:et.messages)==null?void 0:mt.at)==null?void 0:pt.call(mt,-1))==null?void 0:ut.timestamp)||0)>=R.startedAt-5e3});if(!A)return;const ae=typeof A.sessionId=="string"&&A.sessionId?A.sessionId:typeof A.instanceId=="string"&&A.instanceId?A.instanceId:(ce=t.find(Ie=>Ie.ideId===A.id))==null?void 0:ce.sessionId;ae&&(F(null),X("done"),P(`${R.providerType} launched`),me(`/dashboard?activeTab=${encodeURIComponent(ae)}`))},[t,r,me,R]),a.useEffect(()=>{if(!R)return;const T=window.setTimeout(()=>{F(A=>!A||A.startedAt!==R.startedAt?A:(X("error"),P("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(T)},[R]);const se=a.useCallback(async T=>{if(te){if(T.kind==="ide"&&T.providerType){await Qe(te.id,T.providerType,{workspacePath:T.workspace||null});return}if((T.kind==="cli"||T.kind==="acp")&&T.providerType){await z(te.id,T.kind,T.providerType,{workspacePath:T.workspace||null,resumeSessionId:T.providerSessionId||null});return}}},[Qe,z,te]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:L==="chat"&&G?e.jsx(dl,{selectedConversation:G,isAcp:ze(G),isStandalone:u,selectedIdeEntry:le,actionLogs:n,userName:d,isSendingChat:ye.isSendingChat,isFocusingAgent:ye.isFocusingAgent,handleModalButton:ye.handleModalButton,handleRelaunch:ye.handleRelaunch,onBack:Pe,onOpenNativeConversation:ke,onOpenMachine:We,onHideConversation:j,onOpenHistory:m,onOpenRemote:h,onStopCli:y,cliViewMode:J,onSetCliViewMode:async T=>{if(G&&J!==T)try{await i(G.daemonId||G.ideId,"set_cli_view_mode",{targetSessionId:G.sessionId,cliType:G.ideType||G.agentType,mode:T})}catch(A){vl(A)?console.warn("Skipped CLI view mode switch:",A instanceof Error?A.message:String(A)):console.error("Failed to switch CLI view mode:",A)}},handleSendChat:ye.handleSendChat,handleFocusAgent:ye.handleFocusAgent}):L==="machine"&&te?e.jsx(xl,{selectedMachineEntry:te,selectedMachineConversations:ee,selectedMachineRecentLaunches:ge,cliProviders:B,acpProviders:Z,selectedMachineNeedsUpgrade:ne,appVersion:_e,machineAction:{state:H,message:O},isStandalone:u,section:$,showBottomNav:W==="inbox",onBack:Fe,onSectionChange:T=>{U(T),M("inbox")},onOpenConversation:je,onOpenRecent:se,onOpenMachineDetails:()=>me(`/machines/${te.id}`),onMachineUpgrade:()=>q(te.id),onLaunchDetectedIde:(T,A)=>Qe(te.id,T,A),onAddWorkspace:(T,A)=>Ge(te.id,T,A),onBrowseDirectory:async T=>{const A=await i(te.id,"file_list_browse",{path:T});if(!(A!=null&&A.success))throw new Error((A==null?void 0:A.error)||"Could not browse folder");const ae=typeof(A==null?void 0:A.path)=="string"?A.path:T,ce=ae.includes("\\")?"\\":"/",Ie=(Ee,Te)=>/^[A-Za-z]:\\?$/.test(Ee)?`${Ee.replace(/\\?$/,"\\")}${Te}`:Ee==="/"||Ee==="\\"?`${ce}${Te}`:`${Ee.replace(/[\\/]+$/,"")}${ce}${Te}`,Oe=Array.isArray(A==null?void 0:A.files)?A.files.filter(Ee=>(Ee==null?void 0:Ee.type)==="directory"&&typeof(Ee==null?void 0:Ee.name)=="string").map(Ee=>({name:Ee.name,path:Ie(ae,Ee.name)})).sort((Ee,Te)=>Ee.name.localeCompare(Te.name)):[];return{path:ae,directories:Oe}},onLaunchWorkspaceProvider:(T,A,ae)=>z(te.id,T,A,ae)}):e.jsx(ml,{section:$,attentionItems:ue,unreadItems:Ce,workingItems:Q,completedItems:ie,hiddenConversations:s,machineCards:re,getAvatarText:bl,onOpenConversation:je,onShowConversation:K,onShowAllHidden:N,onOpenMachine:Be,onOpenSettings:()=>me("/settings"),onSectionChange:U,wsStatus:g,isConnected:v,isStandalone:u})})}function lr(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function jl({conversations:t,numGroups:s,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[u,d]=a.useState(!1),[x,l]=a.useState(null),f=a.useCallback(()=>{c.current=0,d(!1),l(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const b=a.useCallback(h=>{h.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,d(!0))},[]),p=a.useCallback(h=>{if(!h.dataTransfer.types.includes("text/tab-key"))return;if(h.preventDefault(),!lr(s,r)){l("merge");return}const y=h.currentTarget.getBoundingClientRect(),g=h.clientX-y.left,v=y.width/3;g<v?l("split-left"):g>v*2?l("split-right"):l("merge")},[s,r]),S=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,d(!1),l(null))},[]),m=a.useCallback(h=>{c.current=0,d(!1);const y=h.dataTransfer.getData("text/tab-key"),g=y?t.some(K=>K.tabKey===y):!1,v=x;if(l(null),o(),!!y){if(h.preventDefault(),v==="split-left"&&lr(s,r)){r==null||r(y,"split-left");return}if(v==="split-right"&&lr(s,r)){r==null||r(y,"split-right");return}if(g){i(y);return}n==null||n(y)}},[t,x,s,r,n,i,o]);return{dragOver:u,dropAction:x,resetDragState:f,handleDragEnter:b,handleDragOver:p,handleDragLeave:S,handleDrop:m}}function kl(t,s){const r=new Set(s.map(o=>o.tabKey)),n=t.filter(o=>r.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...n,...i]}function Nl({conversations:t,initialActiveTabId:s,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[u,d]=a.useState(r??[]),[x,l]=a.useState(null),f=a.useRef(null),b=a.useRef(null),p=a.useRef(n),S=a.useRef(i);a.useEffect(()=>{p.current=n},[n]),a.useEffect(()=>{S.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{d(k=>{const w=kl(k,t);return w.length===k.length&&w.every((L,M)=>L===k[M])?k:w})},[t]);const m=a.useMemo(()=>{const k=x??u;if(k.length===0)return t;const w=new Map(k.map((L,M)=>[L,M]));return[...t].sort((L,M)=>{const $=w.get(L.tabKey)??999,U=w.get(M.tabKey)??999;return $-U})},[t,x,u]);a.useEffect(()=>{var w,L;if(m.length===0){o!==null&&(c(null),(w=p.current)==null||w.call(p,null));return}if(o&&m.some(M=>M.tabKey===o))return;const k=m[0].tabKey;k!==o&&(c(k),(L=p.current)==null||L.call(p,k))},[m,o]);const h=a.useMemo(()=>m.find(k=>k.tabKey===o),[m,o]),y=a.useCallback(k=>{var w;c(k),(w=p.current)==null||w.call(p,k)},[]),g=a.useCallback((k,w,L)=>{d(M=>{var _;const $=M.filter(W=>W!==k),U=$.indexOf(w);if(U<0)return M;const D=L==="left"?U:U+1;return $.splice(D,0,k),(_=S.current)==null||_.call(S,$),$}),l(null)},[]),v=a.useCallback((k,w,L)=>{const $=(u.length>0?u:t.map(_=>_.tabKey)).filter(_=>_!==k),U=$.indexOf(w);if(U<0)return;const D=L==="left"?U:U+1;$.splice(D,0,k),f.current=$,l($)},[u,t]),K=a.useCallback(()=>{var w;const k=f.current;k&&(d(k),(w=S.current)==null||w.call(S,k))},[]),N=a.useCallback(()=>{f.current=null,l(null)},[]),j=a.useCallback(k=>{d(w=>{var M;const L=w.filter($=>$!==k);return L.push(k),(M=S.current)==null||M.call(S,L),L})},[]);return{activeTabId:o,activeConv:h,sortedConversations:m,previewOrderRef:f,draggingTabRef:b,selectTab:y,handleTabReorder:g,updatePreviewOrder:v,commitPreviewOrder:K,clearPreviewOrder:N,moveTabToEnd:j,setDraggingTabKey:k=>{b.current=k}}}function Sl({dropAction:t,canSplit:s}){return e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function Or({conversationsCount:t,isSplitMode:s,isStandalone:r,hasRegisteredMachines:n=!1,detectedIdes:i,handleLaunchIde:o}){const c=!r&&!n,u=r?"Waiting for your daemon":n?"No conversations yet":"Connect your first machine",d=r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":n?"Your machines are connected. Open a machine, choose a workspace, then launch an IDE, CLI, or ACP session.":"Install the ADHDev daemon and link your dashboard to start.";return t===0&&!s&&i&&o?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:u}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:d}),c&&e.jsx(Ma,{}),r&&i.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Detected IDEs"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:i.map(x=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>o(x.type),children:[e.jsx(Zn,{size:14,className:"opacity-70"})," Open ",x.name]},x.type))})]}),c&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}const La="adhdev-tab-shortcuts";function Cl(){try{return JSON.parse(localStorage.getItem(La)||"{}")}catch{return{}}}function Ra({enabled:t=!0,sortedTabKeys:s,onFocus:r,onSelectTab:n}){const i=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,c]=a.useState(()=>Cl()),[u,d]=a.useState(null),x=a.useCallback(f=>{const b=[];return f.metaKey&&b.push(i?"⌘":"Meta"),f.ctrlKey&&b.push("Ctrl"),f.altKey&&b.push(i?"⌥":"Alt"),f.shiftKey&&b.push(i?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(f.key)?null:(b.push(f.key.length===1?f.key.toUpperCase():f.key),b.join("+"))},[i]),l=a.useCallback(f=>{c(f);try{localStorage.setItem(La,JSON.stringify(f))}catch{}},[]);return a.useEffect(()=>{if(!t||!u)return;const f=b=>{if(b.preventDefault(),b.stopPropagation(),b.key==="Escape"){d(null);return}const p=x(b);if(!p)return;const S={...o};for(const[m,h]of Object.entries(S))h===p&&delete S[m];S[u]=p,l(S),d(null)};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[t,u,o,l,x]),a.useEffect(()=>{if(!t)return;const f=b=>{if(!(!b.ctrlKey&&!b.metaKey&&!b.altKey)){for(const[p,S]of Object.entries(o))if(s.includes(p)&&x(b)===S){b.preventDefault(),r(),n(p);return}}};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,o,s,r,n,x]),{isMac:i,tabShortcuts:o,shortcutListening:u,setShortcutListening:d,saveShortcuts:l}}const Il=a.memo(function({conv:s,isActive:r,isDraggedTab:n,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:u,onFocus:d,onSelectTab:x,onConversationActivated:l,onPreviewReorder:f,onReorderTab:b,onCommitPreviewOrder:p,onClearPreviewOrder:S,onDragStateReset:m,onDragTabKeyChange:h,onReceiveTab:y,onOpenContextMenu:g,longPressTimer:v,isGroupActive:K}){const N=qs(s),j=N.isGenerating?"agent-tab-generating":N.isWaiting?"agent-tab-waiting":"",k=N.isReconnecting,w=a.useCallback(H=>{u.current=s.tabKey,h(s.tabKey),H.dataTransfer.setData("text/tab-key",s.tabKey),H.dataTransfer.effectAllowed="move"},[s.tabKey,u,h]),L=a.useCallback(()=>{u.current=null,h(null),p(),S(),m()},[u,h,p,S,m]),M=a.useCallback(H=>{const X=u.current;if(!(!X||X===s.tabKey)&&H.dataTransfer.types.includes("text/tab-key")){H.preventDefault(),H.stopPropagation();const O=H.currentTarget.getBoundingClientRect(),P=H.clientX<O.left+O.width/2?"left":"right";f(X,s.tabKey,P)}},[s.tabKey,u,f]),$=a.useCallback(H=>{H.preventDefault(),H.stopPropagation();const X=H.dataTransfer.getData("text/tab-key");if(X&&X!==s.tabKey){const O=H.currentTarget.getBoundingClientRect(),P=H.clientX<O.left+O.width/2?"left":"right";c.includes(X)?b(X,s.tabKey,P):y&&y(X)}S()},[s.tabKey,c,b,y,S]),U=a.useCallback(H=>{H.stopPropagation(),d(),x(s.tabKey),l(s)},[s,l,d,x]),D=a.useCallback(H=>{H.preventDefault(),g(H.clientX,H.clientY,s.tabKey)},[s.tabKey,g]),_=a.useCallback(H=>{const X=H.touches[0];v.current=setTimeout(()=>{g(X.clientX,X.clientY,s.tabKey)},600)},[s.tabKey,v,g]),W=a.useCallback(()=>{v.current&&clearTimeout(v.current)},[v]),E=["adhdev-dockview-tab",j,r&&"is-active",K&&"is-group-active",k&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:E,draggable:!0,onDragStart:w,onDragEnd:L,onDragOver:M,onDrop:$,onClick:U,onContextMenu:D,onTouchStart:_,onTouchEnd:W,onTouchMove:W,style:{cursor:"pointer",opacity:n?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:N.isGenerating?e.jsx("div",{className:"tab-spinner"}):N.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):N.isConnecting?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("span",{className:"adhdev-dockview-tab-primary",title:s.displayPrimary,children:s.displayPrimary}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):N.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[s.displaySecondary,s.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",s.machineName]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.isTaskCompleteUnread===s.isTaskCompleteUnread&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys&&t.isGroupActive===s.isGroupActive);function Tl({conversations:t,activeTabId:s,groupIndex:r,unreadTabKeys:n,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:p,onReceiveTab:S,onHideTab:m,isGroupActive:h,allowTabShortcuts:y=!0}){const[g,v]=a.useState(null),K=a.useRef(null),N=a.useRef(null),j=a.useMemo(()=>t.map(D=>D.tabKey),[t]);hs("PaneGroupTabBar",{groupIndex:r,activeTabId:s,tabCount:t.length,ctxMenuTab:(g==null?void 0:g.tabKey)||null});const{isMac:k,tabShortcuts:w,shortcutListening:L,setShortcutListening:M,saveShortcuts:$}=Ra({enabled:y,sortedTabKeys:t.map(D=>D.tabKey),onFocus:o,onSelectTab:c});a.useEffect(()=>{if(!g)return;const D=_=>{const W=document.querySelector("[data-pane-context-menu]");W&&W.contains(_.target)||v(null)};return window.addEventListener("mousedown",D,!0),()=>window.removeEventListener("mousedown",D,!0)},[g]),a.useEffect(()=>{const D=N.current;if(!D)return;const _=W=>{Math.abs(W.deltaY)>Math.abs(W.deltaX)&&(W.preventDefault(),D.scrollLeft+=W.deltaY)};return D.addEventListener("wheel",_,{passive:!1}),()=>D.removeEventListener("wheel",_)},[]);const U=a.useCallback((D,_,W)=>{v({x:D,y:_,tabKey:W})},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:e.jsxs("div",{ref:N,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(D=>e.jsx(Il,{conv:D,isActive:s===D.tabKey,isDraggedTab:i.current===D.tabKey,isTaskCompleteUnread:n.has(D.tabKey),shortcut:y?w[D.tabKey]:void 0,conversationKeys:j,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:p,onReceiveTab:S,onOpenContextMenu:U,longPressTimer:K,isGroupActive:h},D.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),g&&e.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:g.x,top:g.y},children:[y&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:D=>{D.stopPropagation(),M(g.tabKey),v(null)},children:["⌨ ",w[g.tabKey]?`Change shortcut (${w[g.tabKey]})`:"Set shortcut"]}),w[g.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const D={...w};delete D[g.tabKey],$(D),v(null)},children:"✕ Remove shortcut"})]}),m&&e.jsxs(e.Fragment,{children:[y&&e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{m(g.tabKey),v(null)},children:"🚫 Hide from Dashboard"})]})]}),y&&L&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>M(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:D=>D.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",k?"⌘+1":"Ctrl+1",", ",k?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function Al({conversations:t,ides:s,clearedTabs:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,hasRegisteredMachines:d,userName:x,groupIndex:l,onFocus:f,isSplitMode:b,numGroups:p,onMoveTab:S,onReceiveTab:m,style:h,detectedIdes:y,handleLaunchIde:g,onActiveTabChange:v,initialActiveTabId:K,initialTabOrder:N,onTabOrderChange:j,onHideTab:k,isFocused:w,allowTabShortcuts:L=!0}){const{sendCommand:M}=Pt(),$=a.useRef(null),{activeTabId:U,activeConv:D,sortedConversations:_,draggingTabRef:W,selectTab:E,handleTabReorder:H,updatePreviewOrder:X,commitPreviewOrder:O,clearPreviewOrder:P,moveTabToEnd:R,setDraggingTabKey:F}=Nl({conversations:t,initialActiveTabId:K,initialTabOrder:N,onActiveTabChange:v,onTabOrderChange:j}),Y=Ys({sendDaemonCommand:i,activeConv:D,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),{dragOver:me,dropAction:_e,resetDragState:G,handleDragEnter:le,handleDragOver:J,handleDragLeave:he,handleDrop:te}=jl({conversations:t,numGroups:p,onMoveTab:S,onReceiveTab:m,onOwnTabDrop:R,onClearPreviewOrder:P}),fe=D&&!ze(D)&&es(D)==="terminal",ye=a.useMemo(()=>D?s.find(Q=>Q.id===D.ideId):void 0,[s,D]),oe=a.useMemo(()=>D?n.filter(Q=>Q.ideId===D.tabKey):[],[n,D]),de=a.useMemo(()=>bs(s),[s]),ue=a.useMemo(()=>new Set(_.filter(Q=>mo(Q,de,{isOpenConversation:Q.tabKey===U})).map(Q=>Q.tabKey)),[U,de,_]);hs("PaneGroup",{groupIndex:l,conversationCount:t.length,activeTabId:U,dragOver:me});const Ce=a.useCallback(Q=>{Q.streamSource==="agent-stream"&&Q.agentType&&M(Q.ideId,"focus_session",{agentType:Q.agentType,...Q.sessionId&&{targetSessionId:Q.sessionId}}).catch(()=>{})},[M]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:f,style:{...h,outline:me?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Tl,{conversations:_,activeTabId:U,groupIndex:l,numGroups:p,unreadTabKeys:ue,draggingTabRef:W,onFocus:f,onSelectTab:E,onConversationActivated:Ce,onPreviewReorder:X,onReorderTab:H,onCommitPreviewOrder:O,onClearPreviewOrder:P,onDragStateReset:G,onDragTabKeyChange:F,onMoveTab:S,onReceiveTab:m,onHideTab:k,isGroupActive:w??!1,allowTabShortcuts:L}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:le,onDragOver:J,onDragLeave:he,onDrop:te,children:[me&&e.jsx(Sl,{dropAction:_e,canSplit:!!(p<4&&S)}),D?e.jsx(Br,{activeConv:D,clearToken:r[D.tabKey]||0,isCliTerminal:!!fe,ideEntry:ye,terminalRef:$,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,handleSendChat:Y.handleSendChat,isSendingChat:Y.isSendingChat,handleFocusAgent:Y.handleFocusAgent,isFocusingAgent:Y.isFocusingAgent,actionLogs:oe,userName:x,isInputActive:!b||!!w}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Or,{conversationsCount:t.length,isSplitMode:b,isStandalone:u,hasRegisteredMachines:d,detectedIdes:y,handleLaunchIde:g})})]})]})}function _l({containerRef:t,isSplitMode:s,numGroups:r,groupSizes:n,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,hasRegisteredMachines:b,userName:p,focusedGroup:S,setFocusedGroup:m,moveTabToGroup:h,splitTabRelative:y,closeGroup:g,handleResizeStart:v,detectedIdes:K,handleLaunchIde:N,groupActiveTabIds:j,setGroupActiveTabIds:k,groupTabOrders:w,setGroupTabOrders:L,toggleHiddenTab:M,allowTabShortcuts:$=!0}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((U,D)=>{const _=s&&n.length===r?`${n[D]}%`:void 0;return e.jsxs(Ze.Fragment,{children:[s&&D>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:W=>v(D-1,W),onDoubleClick:()=>g(D),title:"Drag to resize · Double-click to merge",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),e.jsx(Al,{style:s?{flexBasis:_??`${100/r}%`,flexGrow:_?0:1,flexShrink:_?0:1}:void 0,conversations:U,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,hasRegisteredMachines:b,userName:p,groupIndex:D,isFocused:s&&S===D,onFocus:()=>m(D),isSplitMode:s,numGroups:r,onMoveTab:(W,E)=>{E==="left"&&D>0?h(W,D-1):E==="right"&&D<r-1?h(W,D+1):E==="split-left"&&r<4?y(W,D,"left"):E==="split-right"&&r<4&&y(W,D,"right")},onReceiveTab:W=>h(W,D),detectedIdes:D===0?K:void 0,handleLaunchIde:D===0?N:void 0,onActiveTabChange:W=>k(E=>(E[D]??null)===(W??null)?E:{...E,[D]:W}),initialActiveTabId:j[D],initialTabOrder:w[D],onTabOrderChange:W=>L(E=>{const H=E[D]||[];return H.length===W.length&&H.every((X,O)=>X===W[O])?E:{...E,[D]:W}}),onHideTab:M,allowTabShortcuts:$})]},D)})})}function Ea({doId:t,ideId:s,ideType:r,connState:n,viewMode:i,instanceId:o}){const[c,u]=a.useState(null),[d,x]=a.useState(null),l=a.useMemo(()=>{if(!s)return r;const b=s.split(":");return b.length>=3&&b[1]==="ide"?b.slice(2).join(":"):r},[s,r]);a.useEffect(()=>t?Je.onScreenshot("ide-page",(p,S)=>{if(p!==t)return;const m=new FileReader;m.onload=()=>u(m.result),m.readAsDataURL(S)}):void 0,[t]),a.useEffect(()=>{n!=="connected"&&u(null)},[n]),a.useEffect(()=>{var p;return t?((p=Je.onStatus)==null?void 0:p.call(Je,(S,m)=>{S===t&&m!=null&&m.screenshotUsage&&x(m.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,l]),a.useEffect(()=>{const b=t?Je.get(t):null;if(!(!b||n!=="connected"))return i!=="chat"&&l?b.startScreenshots(l):b.stopScreenshots(l),()=>{b.stopScreenshots(l)}},[i,n,l,t]);const f=a.useCallback(async(b,p)=>{const S=t?Je.get(t):null;return!S||n!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):S.sendInput(b,p,o||l)},[t,n,o,l]);return{connScreenshot:c,screenshotUsage:d,handleRemoteAction:f}}const $a=a.createContext(null);function Zs(){const t=a.useContext($a);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Rs(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Ml(t){return`remote:${t}`}function fs(t){return t.startsWith("remote:")}function xs(t,s){return t.find(r=>r.ideId===s&&r.streamSource==="native")??t.find(r=>r.ideId===s)??null}function Pl(t){const[,s]=a.useState(0);a.useEffect(()=>{const r=()=>s(i=>i+1),n=[t.api.onDidActiveGroupChange(r),t.api.onDidTitleChange(r),t.api.onDidGroupChange(r),t.containerApi.onDidActivePanelChange(r)];return()=>{for(const i of n)i.dispose()}},[t.api,t.containerApi])}function Ll(t,s,r){var u;const n=[s];let i;for(const d of n){let x;for(const l of d){const f=t.addPanel({id:l.tabKey,component:"conversation",title:Rs(l),params:{kind:"conversation",tabKey:l.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});x||(x=f.id)}i=x??i}const o=r??((u=s[0])==null?void 0:u.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Mn(t,s){const r=new Set(s.map(n=>n.tabKey));for(const n of[...t.panels])fs(n.id)||r.has(n.id)||t.removePanel(n);for(const n of s){const i=t.getPanel(n.tabKey);if(i){i.update({params:{tabKey:n.tabKey}}),i.title!==Rs(n)&&i.api.setTitle(Rs(n));continue}t.addPanel({id:n.tabKey,component:"conversation",title:Rs(n),params:{kind:"conversation",tabKey:n.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Pn(t,s,r){var d,x;const n=r?Ml(r):null;for(const l of[...t.panels])fs(l.id)&&(!n||l.id!==n)&&t.removePanel(l);if(!r||!n)return;const i=xs(s,r);if(!i&&t.totalPanels===0)return;const o=t.getPanel(n),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const u=(i==null?void 0:i.tabKey)??((d=t.activePanel)==null?void 0:d.id)??((x=t.panels.find(l=>!fs(l.id)))==null?void 0:x.id);t.addPanel({id:n,component:"remote",title:c,params:{kind:"remote",ideId:r},...u?{position:{referencePanel:u,direction:"right"},inactive:!0}:{}})}function Rl({params:t,api:s}){var f;const r=Zs(),n=a.useRef(null),[i,o]=a.useState(s.isActive),c=r.conversationsByTabKey.get(t.tabKey),u=Ys({sendDaemonCommand:r.sendDaemonCommand,activeConv:c,setLocalUserMessages:r.setLocalUserMessages,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});a.useEffect(()=>{o(s.isActive);const b=[s.onDidActiveChange(p=>o(p.isActive)),s.onDidActiveGroupChange(p=>{if(!s.isActive&&!p.isActive){o(!1);return}o(s.isActive)})];return()=>{for(const p of b)p.dispose()}},[s]);const d=a.useMemo(()=>c?r.ides.find(b=>b.id===c.ideId):void 0,[r.ides,c]),x=a.useMemo(()=>c?r.actionLogs.filter(b=>b.ideId===c.tabKey):[],[r.actionLogs,c]);if(!c)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(Or,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,detectedIdes:r.detectedIdes,handleLaunchIde:r.handleLaunchIde})});const l=!ze(c)&&es(c)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Br,{activeConv:c,clearToken:r.clearedTabs[c.tabKey]||0,isCliTerminal:l,ideEntry:d,terminalRef:n,handleModalButton:u.handleModalButton,handleRelaunch:u.handleRelaunch,handleSendChat:u.handleSendChat,isSendingChat:u.isSendingChat,handleFocusAgent:u.handleFocusAgent,isFocusingAgent:u.isFocusingAgent,actionLogs:x,userName:r.userName,scrollToBottomRequestNonce:((f=r.scrollToBottomRequest)==null?void 0:f.tabKey)===c.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:i})})}function El({params:t}){var d;const s=Zs(),r=a.useMemo(()=>xs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),n=a.useMemo(()=>s.ides.find(x=>x.id===t.ideId),[s.ides,t.ideId]),i=(r==null?void 0:r.daemonId)||((d=r==null?void 0:r.ideId)==null?void 0:d.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:u}=Ea({doId:i,ideId:t.ideId,ideType:(r==null?void 0:r.ideType)||(n==null?void 0:n.type),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote",instanceId:n==null?void 0:n.instanceId});return r?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(ta,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:r.transport,onAction:u})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function $l(){const t=Zs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Or,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,hasRegisteredMachines:t.hasRegisteredMachines,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Dl(t){var p,S;Pl(t);const s=Zs(),r=a.useCallback(m=>{"button"in m&&m.button!==0||t.api.setActive()},[t.api]);if(t.params.kind==="remote"){const m=xs([...s.conversationsByTabKey.values()],t.params.ideId),h=((p=t.api.group.activePanel)==null?void 0:p.id)===t.api.id,y=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${h?" is-active":""}${y?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(m==null?void 0:m.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:m!=null&&m.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:m.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const i=((S=t.api.group.activePanel)==null?void 0:S.id)===t.api.id,o=t.api.isGroupActive,c=us(n,s.liveSessionInboxState,{isOpenConversation:i}),u=c.isReconnecting,d=c.isConnecting,x=c.isGenerating,l=c.isWaiting,f=c.unread,b=s.tabShortcuts[n.tabKey];return e.jsxs("div",{className:`adhdev-dockview-tab${i?" is-active":""}${o?" is-group-active":""}${u?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:m=>{m.preventDefault(),r(m),s.openTabContextMenu({x:m.clientX,y:m.clientY,tabKey:n.tabKey})},children:[f&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?e.jsx("div",{className:"tab-spinner"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):u?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:u?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]}),b&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:b,children:b})]})}function Bl({visibleConversations:t,clearedTabs:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,hasRegisteredMachines:d,initialDataLoaded:x,userName:l,detectedIdes:f,handleLaunchIde:b,toggleHiddenTab:p,registerActionHandlers:S,onActiveTabChange:m,requestedActiveTabKey:h,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:g,scrollToBottomRequest:v}){const{theme:K}=ga(),{sendCommand:N}=Pt(),j=a.useRef(null),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(!1),M=a.useRef(!1),$=a.useRef(null),[U,D]=a.useState(null),[_,W]=a.useState(!1),[E,H]=a.useState(!1),X=a.useRef(null),O=a.useMemo(()=>Ia(typeof window<"u"?window.innerWidth:1280),[]),P=a.useMemo(()=>new Map(t.map(B=>[B.tabKey,B])),[t]),R=a.useMemo(()=>bs(r),[r]),F=a.useCallback(()=>{var B;(B=j.current)==null||B.focus()},[]),Y=a.useCallback(B=>{const Z=j.current;if(!Z)return;const re=Z.getPanel(B);re&&(re.group.model.openPanel(re),re.api.setActive())},[]),me=a.useCallback(B=>{const Z=j.current,re=Z==null?void 0:Z.activePanel,je=(Z==null?void 0:Z.activeGroup)||(re==null?void 0:re.group);if(!Z||!re||!je)return;const ke=je.panels||[];if(ke.length<=1)return;const Pe=ke.findIndex(Fe=>Fe.id===re.id);if(Pe<0)return;const Be=(Pe+B+ke.length)%ke.length,We=ke[Be];We&&(We.group.model.openPanel(We),We.api.setActive())},[]),_e=a.useCallback(B=>{var z;const Z=j.current,re=(Z==null?void 0:Z.activeGroup)||((z=Z==null?void 0:Z.activePanel)==null?void 0:z.group);if(!Z||!re)return;const je=Z.groups||[],ke=je.find(se=>se.id===re.id);if(!ke)return;const Pe=ke.element.getBoundingClientRect(),Be=Pe.left+Pe.width/2,We=Pe.top+Pe.height/2,Fe=(se,T,A,ae)=>Math.max(0,Math.min(T,ae)-Math.max(se,A)),Qe=se=>{const T=se.element.getBoundingClientRect(),A=T.left+T.width/2,ae=T.top+T.height/2;let ce=0,Ie=0,Oe=0,Ee=!1;if(B==="left"?(Ee=A<Be,ce=Math.max(0,Pe.left-T.right),Ie=Math.abs(ae-We),Oe=Fe(Pe.top,Pe.bottom,T.top,T.bottom)):B==="right"?(Ee=A>Be,ce=Math.max(0,T.left-Pe.right),Ie=Math.abs(ae-We),Oe=Fe(Pe.top,Pe.bottom,T.top,T.bottom)):B==="above"?(Ee=ae<We,ce=Math.max(0,Pe.top-T.bottom),Ie=Math.abs(A-Be),Oe=Fe(Pe.left,Pe.right,T.left,T.right)):(Ee=ae>We,ce=Math.max(0,T.top-Pe.bottom),Ie=Math.abs(A-Be),Oe=Fe(Pe.left,Pe.right,T.left,T.right)),!Ee)return Number.POSITIVE_INFINITY;const Te=Oe>0?0:120;return ce*3+Ie+Te};let Ge=null,q=Number.POSITIVE_INFINITY;for(const se of je){if(se.id===ke.id)continue;const T=Qe(se);Number.isFinite(T)&&(T>=q||(q=T,Ge=se))}return Ge||void 0},[]),G=a.useCallback(B=>{const Z=_e(B);if(!Z)return;const re=Z.activePanel||Z.panels[0];re&&(Z.model.openPanel(re),re.api.setActive())},[_e]),le=a.useCallback((B,Z)=>{const re=j.current,je=re==null?void 0:re.activePanel,ke=(re==null?void 0:re.activeGroup)||(je==null?void 0:je.group);if(!re||!je||!ke)return;let Pe=_e(B);!Pe&&(Z!=null&&Z.createGroupIfMissing)&&(Pe=re.addGroup({referenceGroup:ke,direction:B})),Pe&&(je.api.moveTo({group:Pe,position:"center"}),je.group.model.openPanel(je),je.api.setActive())},[_e]),{isMac:J,tabShortcuts:he,shortcutListening:te,setShortcutListening:fe,saveShortcuts:ye}=Ra({sortedTabKeys:t.map(B=>B.tabKey),onFocus:F,onSelectTab:Y}),oe=a.useCallback(()=>{var re;const B=j.current;if(!B)return;const Z=B.activePanel;if(Z){if(fs(Z.id)){const je=((re=Z.params)==null?void 0:re.ideId)||Z.id.slice(7),ke=xs(t,je);ke!=null&&ke.tabKey&&fe(ke.tabKey);return}P.has(Z.id)&&fe(Z.id)}},[P,fe,t]);a.useEffect(()=>(S==null||S({setShortcutForActiveTab:oe,activatePreviousTabInGroup:()=>me(-1),activateNextTabInGroup:()=>me(1),splitActiveTabRight:()=>le("right",{createGroupIfMissing:!0}),splitActiveTabDown:()=>le("below",{createGroupIfMissing:!0}),focusLeftPane:()=>G("left"),focusRightPane:()=>G("right"),focusUpPane:()=>G("above"),focusDownPane:()=>G("below"),moveActiveTabToLeftPane:()=>le("left"),moveActiveTabToRightPane:()=>le("right"),moveActiveTabToUpPane:()=>le("above"),moveActiveTabToDownPane:()=>le("below")}),()=>S==null?void 0:S(null)),[me,G,le,S,oe]),a.useEffect(()=>{if(!U)return;const B=Z=>{const re=document.querySelector("[data-dockview-tab-context-menu]");re&&re.contains(Z.target)||D(null)};return window.addEventListener("mousedown",B,!0),()=>window.removeEventListener("mousedown",B,!0)},[U]);const de=a.useMemo(()=>({actionLogs:n,clearedTabs:s,conversationsByTabKey:P,detectedIdes:f,handleLaunchIde:b,ides:r,isStandalone:u,hasRegisteredMachines:d,liveSessionInboxState:R,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:p,userName:l,scrollToBottomRequest:v,tabShortcuts:he,openTabContextMenu:({x:B,y:Z,tabKey:re})=>D({x:B,y:Z,tabKey:re})}),[n,s,P,f,b,r,u,d,R,i,c,o,p,l,v,he]),ue=a.useCallback(B=>{if(!B)return!1;const Z=j.current;if(!Z)return!1;const re=Z.getPanel(B);return re?(re.group.model.openPanel(re),re.api.setActive(),g==null||g(),!0):!1},[g]),Ce=a.useCallback(()=>{if(M.current)return!1;const B=ue($.current);return B&&(M.current=!0),B},[ue]),Q=a.useCallback(()=>{var Z;const B=j.current;B&&Qc(O,{activeTabId:((Z=B.activePanel)==null?void 0:Z.id)??null,layout:B.toJSON()})},[O]),ie=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const re of Z)re.setAttribute("data-adhdev-force-hidden","true")},[]),ee=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const re of Z)re.removeAttribute("data-adhdev-force-hidden")},[]),ge=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll(".dv-drop-target-container");for(const ke of Z)ke.remove();const re=B.querySelectorAll(".dv-drop-target-dropzone");for(const ke of re)ke.remove();const je=B.querySelectorAll(".dv-drop-target");for(const ke of je)ke.classList.remove("dv-drop-target")},[]),C=a.useCallback(()=>{W(!1),H(!1),ee(),ie(),ge(),!(typeof window>"u")&&(X.current!=null&&window.clearTimeout(X.current),window.requestAnimationFrame(()=>{ie(),ge()}),X.current=window.setTimeout(()=>{ie(),ge(),X.current=null},80))},[ee,ie,ge]),ne=a.useCallback(B=>{var re;j.current=B.api;const Z=Zc(O);$.current=(Z==null?void 0:Z.activeTabId)??null,Z!=null&&Z.layout&&B.api.fromJSON(Z.layout,{reuseExistingPanels:!1}),L.current=!!(Z!=null&&Z.layout)&&!x&&t.length===0,L.current||(Mn(B.api,t),Pn(B.api,t,y)),B.api.totalPanels===0&&t.length>0?Ll(B.api,t,h):!L.current&&!ue(h)&&Ce(),w.current=!0,B.api.onDidActivePanelChange(je=>{var Pe;if($.current=(je==null?void 0:je.id)??null,M.current=!0,je&&fs(je.id)){const Be=((Pe=je.params)==null?void 0:Pe.ideId)||je.id.slice(7),We=xs(t,Be);m((We==null?void 0:We.tabKey)??null),Q();return}if(m((je==null?void 0:je.id)??null),Q(),!je)return;const ke=P.get(je.id);(ke==null?void 0:ke.streamSource)==="agent-stream"&&ke.agentType&&N(ke.ideId,"focus_session",{agentType:ke.agentType,...ke.sessionId&&{targetSessionId:ke.sessionId}}).catch(()=>{})}),B.api.onDidLayoutChange(()=>{Q()}),B.api.onWillDragPanel(()=>{W(!0),H(!1),ie()}),B.api.onWillDragGroup(()=>{W(!0),H(!1),ie()}),B.api.onWillShowOverlay(()=>{ee(),H(!0)}),B.api.onDidMovePanel(C),B.api.onDidDrop(C),m(((re=B.api.activePanel)==null?void 0:re.id)??null)},[ue,C,ee,P,x,O,ie,ge,m,Q,h,y,N,t]);a.useEffect(()=>{const B=j.current;if(!B||!w.current||L.current&&!x||(L.current&&(L.current=!1),Mn(B,t),Pn(B,t,y),h&&ue(h)))return;!B.activePanel&&B.panels[0]&&(B.panels[0].group.model.openPanel(B.panels[0]),B.panels[0].api.setActive()),!!(B.activePanel&&B.getPanel(B.activePanel.id))||Ce()},[ue,Ce,x,h,y,t]),a.useEffect(()=>{w.current&&ue(h)},[ue,h]),a.useEffect(()=>{if(!_||typeof window>"u")return;const B=()=>C();return window.addEventListener("pointerup",B),window.addEventListener("mouseup",B),window.addEventListener("dragend",B),()=>{window.removeEventListener("pointerup",B),window.removeEventListener("mouseup",B),window.removeEventListener("dragend",B)}},[C,_]),a.useEffect(()=>()=>{typeof window>"u"||X.current!=null&&window.clearTimeout(X.current)},[]),a.useEffect(()=>{const B=Z=>{const re=Z.target;if(!re)return;const je=re.querySelector("[data-tab-key]")||re.closest("[data-tab-key]");if(je){const ke=je.getAttribute("data-tab-key");ke&&Z.dataTransfer&&Z.dataTransfer.setData("text/tab-key",ke)}};return window.addEventListener("dragstart",B),()=>window.removeEventListener("dragstart",B)},[]);const ve=K==="light"?gi:yi;return e.jsxs($a.Provider,{value:de,children:[e.jsx("div",{ref:k,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(bi,{className:`h-full min-h-0 min-w-0 adhdev-dockview${_?" is-dragging-dockview":""}${E?" is-showing-dockview-overlay":""}`,components:{conversation:Rl,remote:El},defaultTabComponent:Dl,watermarkComponent:$l,onReady:ne,singleTabMode:"default",tabAnimation:"smooth",theme:ve})}),U&&e.jsxs("div",{"data-dockview-tab-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:U.x,top:U.y},children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors",onClick:B=>{B.stopPropagation(),fe(U.tabKey),D(null)},children:["⌨ ",he[U.tabKey]?`Change shortcut (${he[U.tabKey]})`:"Set shortcut"]}),he[U.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{const B={...he};delete B[U.tabKey],ye(B),D(null)},children:"✕ Remove shortcut"})]}),te&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>fe(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:B=>B.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",J?"⌘+1":"Ctrl+1",", ",J?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const Da="adhdev-recent-launch-args-v1",Kl=8;function Wl(t){return String(t||"").trim().replace(/\s+/g," ")}function Ba(t,s){return`${t.trim()}::${s.trim()}`}function Ka(){if(typeof window>"u")return{byKey:{}};try{const t=JSON.parse(window.localStorage.getItem(Da)||"{}");return{byKey:typeof t.byKey=="object"&&t.byKey?t.byKey:{}}}catch{return{byKey:{}}}}function Ol(t){if(!(typeof window>"u"))try{window.localStorage.setItem(Da,JSON.stringify(t))}catch{}}function Wa(t,s){var o;const r=String(t||"").trim(),n=String(s||"").trim();return!r||!n?[]:((o=Ka().byKey[Ba(r,n)])==null?void 0:o.items)||[]}function Oa(t,s,r){var l;const n=String(t||"").trim(),i=String(s||"").trim(),o=Wl(r);if(!n||!i||!o)return;const c=Ka(),u=Ba(n,i),d=((l=c.byKey[u])==null?void 0:l.items)||[],x=[o,...d.filter(f=>f!==o)].slice(0,Kl);c.byKey[u]={items:x},Ol(c)}function dr(t){var n;if(!t)return null;const s=(((n=t.detectedIdes)==null?void 0:n.length)||0)>0,r=t.availableProviders||[];return s?"ide":r.some(i=>i.category==="cli")?"cli":r.some(i=>i.category==="acp")?"acp":null}function Ts(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Ul({machines:t,onClose:s,onBrowseDirectory:r,onSaveWorkspace:n,onLaunchIde:i,onLaunchProvider:o,onListSavedSessions:c}){var Qe,Ge;const u=a.useMemo(()=>[...t].sort(Ar),[t]),[d,x]=a.useState(((Qe=u[0])==null?void 0:Qe.id)||""),l=a.useMemo(()=>u.find(q=>q.id===d)||u[0],[d,u]),f=a.useMemo(()=>(l==null?void 0:l.workspaces)||[],[l]),b=(l==null?void 0:l.defaultWorkspaceId)||null,[p,S]=a.useState(""),[m,h]=a.useState(""),[y,g]=a.useState(dr(u[0])),[v,K]=a.useState(""),[N,j]=a.useState(""),[k,w]=a.useState([]),[L,M]=a.useState(""),[$,U]=a.useState([]),[D,_]=a.useState(!1),[W,E]=a.useState(""),[H,X]=a.useState(!1),[O,P]=a.useState(null),[R,F]=a.useState(!1),[Y,me]=a.useState(""),[_e,G]=a.useState(!1),[le,J]=a.useState(""),[he,te]=a.useState([]),[fe,ye]=a.useState(!1),[oe,de]=a.useState(""),[ue,Ce]=a.useState(!1),Q=a.useRef(null),ie=a.useRef(0);a.useEffect(()=>{var q;!d&&((q=u[0])!=null&&q.id)&&x(u[0].id)},[d,u]);const ee=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="cli"),[l]),ge=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="acp"),[l]),C=a.useMemo(()=>((l==null?void 0:l.detectedIdes)||[]).map(q=>({id:q.type,label:q.name||q.type,meta:q.running?"Detected locally":"Available to open"})),[l]),ne=a.useMemo(()=>y==="cli"?ee.map(q=>({id:q.type,label:q.displayName||q.type,meta:"CLI provider"})):y==="acp"?ge.map(q=>({id:q.type,label:q.displayName||q.type,meta:"ACP provider"})):C,[ge,y,ee,C]);a.useEffect(()=>{var z;if(!l)return;if(Q.current!==l.id){Q.current=l.id,S(b||((z=f[0])==null?void 0:z.id)||"__home__"),h(""),g(dr(l)),K(""),j(""),M(""),U([]),E(""),me("");return}S(se=>{var T;return se==="__custom__"||se==="__home__"||f.some(A=>A.id===se)?se:b||((T=f[0])==null?void 0:T.id)||"__home__"}),g(se=>se==="ide"&&C.length>0||se==="cli"&&ee.length>0||se==="acp"&&ge.length>0?se:dr(l))},[ge.length,ee.length,b,C.length,l,f]),a.useEffect(()=>{var q;y&&(ne.some(z=>z.id===v)||K(((q=ne[0])==null?void 0:q.id)||""))},[y,ne,v]);const ve=a.useCallback(async(q,z)=>{const se=ie.current+1;return ie.current=se,_(!0),E(""),c(q,z).then(T=>{ie.current===se&&U(T)}).catch(T=>{ie.current===se&&(U([]),E(T instanceof Error?T.message:"Could not load saved sessions"))}).finally(()=>{ie.current===se&&_(!1)})},[c]),B=a.useCallback((q,z)=>{w(Wa(q,z))},[]);a.useEffect(()=>{if(M(""),!l||!v||y==="ide"?w([]):B(l.id,v),y!=="cli"){U([]),E(""),_(!1);return}if(!l||!v){U([]),E(""),_(!1);return}ve(l.id,v)},[y,B,ve,l,v]),a.useEffect(()=>{if(!L)return;const q=$.find(z=>z.providerSessionId===L);q!=null&&q.canResume||M("")},[$,L]);const Z=p==="__custom__"?m.trim():p==="__home__"?"":((Ge=f.find(q=>q.id===p))==null?void 0:Ge.path)||"",re=a.useCallback(q=>{const z=String(q.workspace||"").trim();if(!z)return;const se=f.find(T=>Ts(T.path)===Ts(z));if(se){S(se.id),h("");return}S("__custom__"),h(z)},[f]),je=a.useCallback(q=>{const z=String(q.workspace||"").trim();if(!z)return{workspaceId:null,workspacePath:null};const se=f.find(T=>Ts(T.path)===Ts(z));return se?{workspaceId:se.id,workspacePath:null}:{workspaceId:null,workspacePath:z}},[f]),ke=a.useMemo(()=>{var z;if(y!=="cli"||!l||!v)return null;const q=((z=ee.find(se=>se.type===v))==null?void 0:z.displayName)||v;return{ideId:l.id,daemonId:l.id,providerSessionId:L||void 0,transport:"pty",mode:"chat",agentName:q,agentType:v,status:"idle",title:q,messages:[],ideType:v,workspaceName:Z,displayPrimary:q,displaySecondary:"CLI",streamSource:"native",tabKey:`dashboard:new-session:resume-history:${l.id}:${v}`,machineName:gt(l,{fallbackId:l.id})}},[y,ee,Z,l,L,v]),Pe=a.useCallback(()=>{var z,se;if(!l)return;S("__custom__"),G(!0),de("");const q=Xs(l.platform,[m.trim(),Z,(z=f.find(T=>T.id===b))==null?void 0:z.path,(se=f[0])==null?void 0:se.path]);ye(!0),r(l.id,q).then(T=>{J(T.path),h(T.path),te(T.directories)}).catch(T=>{de(T instanceof Error?T.message:"Could not load folder")}).finally(()=>ye(!1))},[m,b,r,Z,l,f]),Be=a.useCallback(q=>{l&&(ye(!0),de(""),r(l.id,q).then(z=>{J(z.path),h(z.path),te(z.directories)}).catch(z=>{de(z instanceof Error?z.message:"Could not load folder")}).finally(()=>ye(!1)))},[r,l]),We=a.useCallback(async()=>{if(!l||!Z)return;Ce(!0),me("");const q=await n(l.id,Z);if(Ce(!1),!q.ok){me(q.error||"Could not save workspace");return}me("Workspace saved. It will appear in the list once the machine state refreshes.")},[n,Z,l]),Fe=a.useCallback(async()=>{if(!l||!y||!v)return;F(!0),me("");const q=N.trim()?N.trim().split(/\s+/).filter(Boolean):[],z=y==="ide"?await i(l.id,v,{workspacePath:Z||null}):await o(l.id,y,v,{workspaceId:p!=="__home__"&&p!=="__custom__"?p:null,workspacePath:p==="__custom__"&&Z||null,resumeSessionId:y==="cli"&&L?L:null,cliArgs:q});if(F(!1),!z.ok){me(z.error||"Could not start session");return}y!=="ide"&&N.trim()&&(Oa(l.id,v,N),B(l.id,v)),s()},[y,N,B,s,i,o,Z,l,L,v,p]);return l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"dashboard-new-title",children:e.jsxs("div",{className:"w-full max-w-3xl max-h-[min(88vh,860px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"dashboard-new-title",className:"m-0 text-base font-semibold text-text-primary",children:"New session"}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:"Pick a machine, choose a workspace, then start IDE, CLI, or ACP without leaving the dashboard."})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:s,"aria-label":"Close new session dialog",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Machine"}),e.jsx("select",{value:l.id,onChange:q=>x(q.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R,children:u.map(q=>e.jsx("option",{value:q.id,children:gt(q,{fallbackId:q.id})},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Workspace"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Saved workspace is preferred. Home and custom folders are still available."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Pe,disabled:R,children:"Browse…"})]}),e.jsxs("select",{value:p,onChange:q=>{const z=q.target.value;S(z),z==="__custom__"?Pe():me("")},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R,children:[e.jsx("option",{value:"__home__",children:"Home directory"}),f.map(q=>e.jsxs("option",{value:q.id,children:[q.id===b?"⭐ ":"",Gs(q.path,q.label)||q.path]},q.id)),e.jsx("option",{value:"__custom__",children:"Custom folder…"})]}),e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:p==="__home__"?"Launch without a workspace.":Z||"Select a workspace folder."}),p==="__custom__"&&Z&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Pe,disabled:R,children:[e.jsx(Qt,{size:14}),"Select folder"]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:We,disabled:R||ue,children:ue?"Saving…":"Save workspace"})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:"Category"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"ide",label:"IDE",enabled:C.length>0},{id:"cli",label:"CLI",enabled:ee.length>0},{id:"acp",label:"ACP",enabled:ge.length>0}].map(q=>e.jsx("button",{type:"button",className:`btn btn-sm ${y===q.id?"btn-primary":"btn-secondary"}`,onClick:()=>g(q.id),disabled:!q.enabled||R,children:q.label},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:y==="ide"?"Choose IDE":y==="cli"?"Choose CLI provider":"Choose ACP provider"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[ne.map(q=>e.jsxs("button",{type:"button",className:`w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${v===q.id?"border-accent bg-accent/10":"border-border-subtle bg-bg-secondary/40 hover:bg-bg-secondary/70"}`,onClick:()=>K(q.id),disabled:R,children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:q.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:q.meta})]},q.id)),ne.length===0&&e.jsx("div",{className:"text-sm text-text-muted",children:"Nothing available for this category on the selected machine."})]})]}),y!=="ide"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Startup arguments"}),e.jsx("input",{type:"text",value:N,onChange:q=>j(q.target.value),placeholder:"Optional flags...",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R}),k.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:k.map(q=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>j(q),disabled:R,title:q,children:q},q))})]}),y==="cli"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume from history"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Pick a saved CLI session, then launch with optional args."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:R||!l||!v||D,onClick:()=>{!l||!v||ve(l.id,v)},children:D?"Loading…":"Refresh"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:R||!l||!v,onClick:()=>{!l||!v||(X(!0),ve(l.id,v))},children:"Open History"})]}),e.jsx("div",{className:"mt-2",children:e.jsxs("select",{value:L,onChange:q=>{const z=q.target.value;if(M(z),!z)return;const se=$.find(T=>T.providerSessionId===z);!se||!se.canResume||re(se)},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R||D,children:[e.jsx("option",{value:"",children:"Start a new CLI session"}),$.map(q=>e.jsxs("option",{value:q.providerSessionId,disabled:!q.canResume,children:[q.title||q.providerSessionId,q.canResume?"":" (workspace missing)"]},q.providerSessionId))]})}),L&&(()=>{const q=$.find(z=>z.providerSessionId===L);return q?e.jsxs("div",{className:"mt-2 text-[11px] text-text-muted leading-relaxed",children:[e.jsx("div",{className:"font-mono break-all",children:q.providerSessionId}),e.jsxs("div",{className:"mt-1",children:[q.workspace||"Workspace unknown",q.currentModel?` · ${q.currentModel}`:""]})]}):null})(),W&&e.jsx("div",{className:"mt-2 text-[11px] text-status-error",children:W}),!D&&!W&&$.length===0&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"No saved sessions found for this provider yet."})]}),Y&&e.jsx("div",{className:`rounded-xl border px-4 py-3 text-sm ${Y.includes("saved")||Y.includes("requested")?"border-accent/25 bg-accent/10 text-text-primary":"border-status-error/25 bg-status-error/10 text-status-error"}`,children:Y})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:s,disabled:R,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:Fe,disabled:R||!y||!v||p==="__custom__"&&!Z,children:[e.jsx(Tr,{size:14}),R?"Starting…":"Start session"]})]})]})}),_e&&e.jsx(Js,{title:"Select workspace",description:"Pick the folder that should be used for this new session.",currentPath:le,directories:he,busy:fe,error:oe,onClose:()=>G(!1),onNavigate:Be,onConfirm:q=>{h(q),J(q),S("__custom__"),G(!1)}}),H&&ke&&e.jsx(Pr,{activeConv:ke,ides:[],isCreatingChat:!1,isRefreshingHistory:D,savedSessions:$,isSavedSessionsLoading:D,isResumingSavedSessionId:O,onClose:()=>X(!1),onNewChat:()=>{M(""),X(!1)},onSwitchSession:()=>{},onRefreshHistory:()=>{!l||!v||ve(l.id,v)},onResumeSavedSession:q=>{if(!l||!v||O||!q.canResume)return;const z=je(q);M(q.providerSessionId),re(q),P(q.providerSessionId),X(!1),F(!0),me(""),o(l.id,"cli",v,{workspaceId:z.workspaceId,workspacePath:z.workspacePath,resumeSessionId:q.providerSessionId}).then(se=>{if(!se.ok){me(se.error||"Could not resume session");return}s()}).finally(()=>{F(!1),P(se=>se===q.providerSessionId?null:se)})}})]}):null}const Ua="adhdev-dashboard-action-shortcuts",zl=1200,Hl={toggleHiddenTabs:"G H",setActiveTabShortcut:"G S",selectPreviousGroupTab:"G K",selectNextGroupTab:"G J",splitActiveTabRight:"⌘+⌥+\\",focusLeftPane:"⌘+⌥+←",focusRightPane:"⌘+⌥+→",moveActiveTabToLeftPane:"⌘+⌥+⇧+←",moveActiveTabToRightPane:"⌘+⌥+⇧+→",triggerPrimaryApprovalAction:"⌥+A",triggerSecondaryApprovalAction:"⌥+D",toggleCliView:"T"};function Fl(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function Xe(t,s){switch(t){case"openShortcutHelp":return"?";case"hideCurrentTab":return s?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return s?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return s?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return s?"⌥+R":"Ctrl+Alt+R";case"splitActiveTabRight":return s?"⌘+⌥+=":"Ctrl+Alt+\\";case"splitActiveTabDown":return s?"⌘+⌥+-":"Ctrl+Alt+-";case"focusLeftPane":return s?"⌘+⌥+[":"Ctrl+Alt+←";case"focusRightPane":return s?"⌘+⌥+]":"Ctrl+Alt+→";case"focusUpPane":return s?"⌘+⌥+U":"Ctrl+Alt+↑";case"focusDownPane":return s?"⌘+⌥+J":"Ctrl+Alt+↓";case"moveActiveTabToLeftPane":return s?"⌘+⌥+,":"Ctrl+Alt+Shift+←";case"moveActiveTabToRightPane":return s?"⌘+⌥+.":"Ctrl+Alt+Shift+→";case"moveActiveTabToUpPane":return s?"⌘+⌥+I":"Ctrl+Alt+Shift+↑";case"moveActiveTabToDownPane":return s?"⌘+⌥+K":"Ctrl+Alt+Shift+↓";case"triggerPrimaryApprovalAction":return s?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return s?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return s?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return s?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return s?"⌥+[":"Ctrl+Alt+[";case"selectNextGroupTab":return s?"⌥+]":"Ctrl+Alt+]";case"toggleCliView":return s?"⌥+T":"Ctrl+Alt+T"}}function za(t){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:Xe("openShortcutHelp",t)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:Xe("hideCurrentTab",t)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:Xe("toggleHiddenTabs",t)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:Xe("openHistoryForActiveTab",t)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:Xe("openRemoteForActiveTab",t)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:Xe("splitActiveTabRight",t)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:Xe("splitActiveTabDown",t)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:Xe("focusLeftPane",t)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:Xe("focusRightPane",t)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:Xe("focusUpPane",t)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:Xe("focusDownPane",t)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:Xe("moveActiveTabToLeftPane",t)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:Xe("moveActiveTabToRightPane",t)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:Xe("moveActiveTabToUpPane",t)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:Xe("moveActiveTabToDownPane",t)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:Xe("triggerPrimaryApprovalAction",t)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:Xe("triggerSecondaryApprovalAction",t)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:Xe("triggerTertiaryApprovalAction",t)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:Xe("setActiveTabShortcut",t)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:Xe("selectPreviousGroupTab",t)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:Xe("selectNextGroupTab",t)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:Xe("toggleCliView",t)}]}function Vl(t){if(!(t instanceof HTMLElement))return!1;if(t.isContentEditable)return!0;const s=t.tagName;return s==="INPUT"||s==="TEXTAREA"||s==="SELECT"}function Ln(t){const s=Object.fromEntries(za(t).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(Ua)||"{}"),n={...s,...r};for(const[i,o]of Object.entries(Hl))n[i]===o&&(n[i]=s[i]);return n}catch{return s}}function ql(t){return t===" "?"Space":t==="Escape"?"Esc":t==="ArrowLeft"?"←":t==="ArrowRight"?"→":t==="ArrowUp"?"↑":t==="ArrowDown"?"↓":t.length===1?t.toUpperCase():t}function Gl({enabled:t=!0,onTrigger:s}){const r=Fl(),[n,i]=a.useState(()=>Ln(r)),[o,c]=a.useState(null),[u,d]=a.useState([]),x=a.useRef({parts:[],timer:null}),l=a.useCallback(m=>{const h=[];return m.metaKey&&h.push(r?"⌘":"Meta"),m.ctrlKey&&h.push("Ctrl"),m.altKey&&h.push(r?"⌥":"Alt"),m.shiftKey&&m.key.length!==1&&h.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(m.key)?null:(h.push(ql(m.key)),h.join("+"))},[r]),f=a.useCallback(m=>{i(m);try{localStorage.setItem(Ua,JSON.stringify(m))}catch{}},[]);a.useEffect(()=>{const m=Ln(r),h=Object.entries(n),y=Object.entries(m);h.length===y.length&&h.every(([g,v])=>m[g]===v)||f(m)},[n,r,f]);const b=a.useCallback(()=>{typeof window<"u"&&x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current={parts:[],timer:null}},[]),p=a.useCallback(()=>{typeof window>"u"||(x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current.timer=window.setTimeout(()=>{x.current={parts:[],timer:null}},zl))},[]);a.useEffect(()=>{if(!o)return;const m=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){c(null),d([]);return}const y=l(h);if(!y)return;const v=!(h.metaKey||h.ctrlKey||h.altKey)&&/^[A-Z0-9]$/.test(y);if(u.length===0&&v){d([y]);return}const N=[...u,y].slice(0,2).join(" "),j={...n};for(const[k,w]of Object.entries(j))w===N&&delete j[k];j[o]=N,f(j),c(null),d([])};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[n,l,f,o,u]),a.useEffect(()=>{if(!t||o)return;const m=h=>{if(h.defaultPrevented)return;const y=l(h);if(!y)return;const g=h.metaKey||h.ctrlKey||h.altKey;if(Vl(h.target)&&!g)return;const v=x.current.parts,K=g?[y]:[...v.slice(-1),y].slice(-2),N=K.join(" "),j=K[K.length-1],k=Object.entries(n).filter(([,U])=>!!U),w=k.find(([,U])=>U===N);if(w){h.preventDefault(),b(),s(w[0]);return}if(k.some(([,U])=>U.startsWith(`${N} `))){h.preventDefault(),x.current.parts=K,p();return}const M=k.find(([,U])=>U===j);if(M){h.preventDefault(),b(),s(M[0]);return}if(k.some(([,U])=>U.startsWith(`${j} `))){h.preventDefault(),x.current.parts=[j],p();return}b()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n,p,t,l,s,b,o]),a.useEffect(()=>()=>b(),[b]);const S=a.useMemo(()=>za(r),[r]);return{isMac:r,actionDefinitions:S,actionShortcuts:n,shortcutListening:o,shortcutListeningDraft:u,setShortcutListening:c,setShortcutListeningDraft:d,saveShortcuts:f}}function Yl(t){switch(t.id){case"triggerPrimaryApprovalAction":case"triggerSecondaryApprovalAction":case"triggerTertiaryApprovalAction":return"approvals";case"splitActiveTabRight":case"splitActiveTabDown":case"focusLeftPane":case"focusRightPane":case"focusUpPane":case"focusDownPane":case"moveActiveTabToLeftPane":case"moveActiveTabToRightPane":case"moveActiveTabToUpPane":case"moveActiveTabToDownPane":return"panes";default:return"workspace"}}function Xl(t){return t instanceof Error?t.message:String(t||"")}function Jl(t){const s=Xl(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Zl({showMobileChatMode:t,isMobile:s,activeConv:r,chatIdes:n,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:u,onStopCli:d,activeCliViewMode:x,onSetActiveCliViewMode:l,mobileChatConversations:f,hiddenConversations:b,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,initialDataLoaded:v,userName:K,requestedMobileTabKey:N,onRequestedMobileTabConsumed:j,requestedMachineId:k,onRequestedMachineConsumed:w,requestedMobileSection:L,onRequestedMobileSectionConsumed:M,containerRef:$,isSplitMode:U,numGroups:D,groupSizes:_,groupedConvs:W,clearedTabs:E,focusedGroup:H,setFocusedGroup:X,moveTabToGroup:O,splitTabRelative:P,closeGroup:R,handleResizeStart:F,detectedIdes:Y,handleLaunchIde:me,groupActiveTabIds:_e,setGroupActiveTabIds:G,groupTabOrders:le,setGroupTabOrders:J,toggleHiddenTab:he,visibleConversations:te,requestedDesktopTabKey:fe,onRequestedDesktopTabConsumed:ye,onDesktopActiveTabChange:oe,onHideConversation:de,onShowHiddenConversation:ue,onShowAllHiddenConversations:Ce,scrollToBottomRequest:Q,machineEntries:ie,onBrowseMachineDirectory:ee,onSaveMachineWorkspace:ge,onLaunchMachineIde:C,onLaunchMachineProvider:ne,onListMachineSavedSessions:ve}){const B=Ze.useRef(null),[Z,re]=Ze.useState(!1),[je,ke]=Ze.useState(!1),[Pe,Be]=Ze.useState(!1),[We,Fe]=Ze.useState(!1),[Qe,Ge]=Ze.useState(!1),[q,z]=Ze.useState("quickstart"),[se,T]=Ze.useState("workspace"),A=!t&&!s,ae=Ze.useCallback(xe=>{re(xe),xe&&ke(!1)},[]),ce=Ze.useCallback(xe=>{ke(xe),xe&&re(!1)},[]),Ie=Ze.useCallback(()=>{z(te.length===0?"quickstart":"shortcuts"),T("workspace"),Be(!0),re(!1),ke(!1)},[te.length]),Oe=Ze.useCallback(async xe=>{var Ct;if(!r)return;const Ke=(Ct=r.modalButtons)==null?void 0:Ct[xe];if(!Ke)return;const wt=ps(r);if(!wt)return;const St=Ke.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),jt=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(St);try{await m(wt,"resolve_action",{button:Ke,action:jt?"approve":"reject",buttonIndex:xe,...Jt(r)})}catch(I){Jl(I)||console.error("[Shortcut approval] Failed:",I)}},[r,m]),{isMac:Ee,actionDefinitions:Te,actionShortcuts:He,shortcutListening:Ue,shortcutListeningDraft:et,setShortcutListening:mt,setShortcutListeningDraft:pt,saveShortcuts:ut}=Gl({enabled:A&&!Pe,onTrigger:xe=>{var Ke,wt,St,jt,Ct,I,V,pe,we,Le,Me,Ve,nt;if(xe==="openShortcutHelp"){Ie();return}if(xe==="hideCurrentTab"){r&&de(r);return}if(xe==="toggleHiddenTabs"){ce(!je);return}if(xe==="openHistoryForActiveTab"){r&&!ze(r)&&c(r);return}if(xe==="openRemoteForActiveTab"){r&&!Ye(r)&&!ze(r)&&u(r);return}if(xe==="splitActiveTabRight"){(Ke=B.current)==null||Ke.splitActiveTabRight();return}if(xe==="splitActiveTabDown"){(wt=B.current)==null||wt.splitActiveTabDown();return}if(xe==="focusLeftPane"){(St=B.current)==null||St.focusLeftPane();return}if(xe==="focusRightPane"){(jt=B.current)==null||jt.focusRightPane();return}if(xe==="focusUpPane"){(Ct=B.current)==null||Ct.focusUpPane();return}if(xe==="focusDownPane"){(I=B.current)==null||I.focusDownPane();return}if(xe==="moveActiveTabToLeftPane"){(V=B.current)==null||V.moveActiveTabToLeftPane();return}if(xe==="moveActiveTabToRightPane"){(pe=B.current)==null||pe.moveActiveTabToRightPane();return}if(xe==="moveActiveTabToUpPane"){(we=B.current)==null||we.moveActiveTabToUpPane();return}if(xe==="moveActiveTabToDownPane"){(Le=B.current)==null||Le.moveActiveTabToDownPane();return}if(xe==="triggerPrimaryApprovalAction"){Oe(0);return}if(xe==="triggerSecondaryApprovalAction"){Oe(1);return}if(xe==="triggerTertiaryApprovalAction"){Oe(2);return}if(xe==="setActiveTabShortcut"){(Me=B.current)==null||Me.setShortcutForActiveTab();return}if(xe==="selectPreviousGroupTab"){(Ve=B.current)==null||Ve.activatePreviousTabInGroup();return}if(xe==="selectNextGroupTab"){(nt=B.current)==null||nt.activateNextTabInGroup();return}!r||!Ye(r)||ze(r)||xe==="toggleCliView"&&l(x==="chat"?"terminal":"chat")}}),ft=Ze.useCallback(()=>{Be(!1),mt(null),pt([])},[mt,pt]),$e=Ze.useMemo(()=>se==="all"?Te:Te.filter(xe=>Yl(xe)===se),[Te,se]),Lt=Ze.useCallback(()=>{const xe=Object.fromEntries(Te.map(Ke=>[Ke.id,""]));ut(xe)},[Te,ut]),Ft=Ze.useCallback(()=>{if(typeof window<"u"&&!window.confirm("Reset all dashboard shortcuts back to their default values?"))return;const xe=Object.fromEntries(Te.map(Ke=>[Ke.id,Ke.defaultShortcut]));ut(xe)},[Te,ut]);return Ze.useEffect(()=>{const xe=Ke=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?Ke.metaKey&&Ke.key.toLowerCase()==="w":Ke.ctrlKey&&Ke.key.toLowerCase()==="w")&&(Ke.preventDefault(),r&&de&&de(r))};return window.addEventListener("keydown",xe),()=>window.removeEventListener("keydown",xe)},[r,de]),Ze.useEffect(()=>{if(!Pe||Ue)return;const xe=Ke=>{Ke.key==="Escape"&&(Ke.preventDefault(),ft())};return window.addEventListener("keydown",xe,!0),()=>window.removeEventListener("keydown",xe,!0)},[ft,Pe,Ue]),Ze.useEffect(()=>{if(!A||te.length>0){Ge(!1);return}Ge(!0);const xe=window.setTimeout(()=>{Ge(!1)},1e4);return()=>window.clearTimeout(xe)},[A,te.length]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Ko,{activeConv:r,agentCount:n.length,wsStatus:i,isConnected:o,conversations:te,hiddenConversations:b,onOpenHistory:c,onOpenConversation:ue,onHideConversation:de,onShowConversation:ue,onShowAllHidden:Ce,inboxOpen:Z,onInboxOpenChange:ae,hiddenOpen:je,onHiddenOpenChange:ce,onOpenNewSession:s?void 0:()=>Fe(!0),onOpenRemote:()=>{!r||Ye(r)||ze(r)||u(r)},onStopCli:d,activeCliViewMode:x,onSetCliViewMode:l}),t?e.jsx(wl,{conversations:f,hiddenConversations:b,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,userName:K,requestedActiveTabKey:N,onRequestedActiveTabConsumed:j,requestedMachineId:k,onRequestedMachineConsumed:w,requestedMobileSection:L,onRequestedMobileSectionConsumed:M,onOpenHistory:c,onOpenRemote:u,onStopCli:d,wsStatus:i,isConnected:o,onShowHiddenConversation:ue,onShowAllHiddenConversations:Ce}):s?e.jsx(_l,{containerRef:$,isSplitMode:U,numGroups:D,groupSizes:_,groupedConvs:W,clearedTabs:E,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,hasRegisteredMachines:ie.length>0,userName:K,focusedGroup:H,setFocusedGroup:X,moveTabToGroup:O,splitTabRelative:P,closeGroup:R,handleResizeStart:F,detectedIdes:Y,handleLaunchIde:me,groupActiveTabIds:_e,setGroupActiveTabIds:G,groupTabOrders:le,setGroupTabOrders:J,toggleHiddenTab:he,allowTabShortcuts:!1}):e.jsx(Bl,{visibleConversations:te,clearedTabs:E,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,hasRegisteredMachines:ie.length>0,initialDataLoaded:v,userName:K,detectedIdes:Y,handleLaunchIde:me,toggleHiddenTab:he,registerActionHandlers:xe=>{B.current=xe},onActiveTabChange:oe,requestedActiveTabKey:fe,onRequestedActiveTabConsumed:ye,scrollToBottomRequest:Q}),We&&e.jsx(Ul,{machines:ie,onClose:()=>Fe(!1),onBrowseDirectory:ee,onSaveWorkspace:ge,onLaunchIde:C,onLaunchProvider:ne,onListSavedSessions:ve}),Pe&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:ft,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl w-[min(560px,calc(100vw-32px))] max-h-[min(80vh,720px)] overflow-y-auto px-6 py-5 shadow-xl",onClick:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Dashboard guide"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"A quick guide to the dashboard flow, plus grouped shortcuts you can tune."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ft,children:"Close"})]}),e.jsx("div",{className:"flex gap-2 mb-4 overflow-x-auto",children:[{id:"overview",label:"Overview"},{id:"quickstart",label:"Quick start"},{id:"shortcuts",label:"Shortcuts"}].map(xe=>e.jsx("button",{type:"button",className:`btn btn-sm ${q===xe.id?"btn-primary":"btn-secondary"}`,onClick:()=>z(xe.id),children:xe.label},xe.id))}),q==="overview"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3 mb-4",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"What lives where"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Tabs:"})," active sessions across IDE, CLI, and ACP agents."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Hidden tabs:"})," stash sessions you do not want in the main strip but still want to keep around."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Activity inbox:"})," sessions waiting for approval or finished tasks you have not reviewed yet."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"CLI view toggle:"})," switch a PTY session between terminal and chat rendering without relaunching it."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Useful flows"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Review notifications:"})," open the inbox, jump to the session, then use the conversation or approval controls directly from the active pane."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Reduce clutter:"})," hide less important sessions instead of closing them, then restore from hidden tabs when needed."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Split work:"})," keep one pane active for input and let secondary panes stay read-only until you focus them."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Per-tab shortcuts:"})," right-click a Dockview tab to assign a direct shortcut for that specific session."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Approval buttons:"})," use ",Ee?"⌥J / ⌥K / ⌥L":"Ctrl+Alt+J / K / L"," for the first three visible approval actions on the active session."]})]})]})]}),q==="quickstart"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Desktop quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Start from the machine or workspace flow first. Pick or save a workspace before launching CLI or ACP sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Keep the main strip focused on active work and push overflow into Hidden tabs."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Use the inbox for approval-required or completed sessions instead of scanning every tab."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"4."})," Split only when you need parallel reading; one active pane is usually the cleanest default."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Mobile quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Stay in chat mode for review and replies; use workspace mode mainly to launch or reopen sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Start from the machine screen, choose a workspace, then launch IDE, CLI, or ACP from there."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Treat mobile as the simpler control surface: no split workflow, fewer tab mechanics, faster session switching."]})]})]})]}),q==="shortcuts"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"all",label:"All"},{id:"workspace",label:"Workspace"},{id:"panes",label:"Panes"},{id:"approvals",label:"Approvals"}].map(xe=>e.jsx("button",{type:"button",className:`btn btn-sm ${se===xe.id?"btn-primary":"btn-secondary"}`,onClick:()=>T(xe.id),children:xe.label},xe.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Lt,children:"Disable all"}),e.jsx("button",{type:"button",className:"btn btn-sm",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, var(--border-subtle, transparent))",background:"color-mix(in srgb, var(--status-error, #ef4444) 8%, var(--bg-primary, transparent))"},onClick:Ft,children:"Reset to defaults"})]})]}),e.jsx("div",{className:"space-y-2",children:$e.map(xe=>e.jsx("div",{className:`rounded-xl border px-4 py-3 ${Ue===xe.id?"border-accent bg-bg-secondary/70":"border-border-subtle bg-bg-secondary/30"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:xe.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:xe.description}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-2",children:["Default: ",e.jsx("span",{className:"font-mono",children:xe.defaultShortcut})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-[11px] font-mono px-2 py-1 rounded bg-bg-tertiary border border-border-subtle min-w-[72px] text-center",children:Ue===xe.id?et.length>0?`${et.join(" ")} ...`:"Listening...":He[xe.id]||"Off"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{mt(xe.id),pt([])},children:Ue===xe.id?"Listening":"Set"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{const Ke={...He};Ke[xe.id]="",ut(Ke)},children:"Disable"})]})]})},xe.id))}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-4",children:["Use modifier shortcuts like ",Ee?"⌥S":"Ctrl+Alt+S",". Press Esc to stop listening."]})]})]})}),!t&&Qe&&e.jsxs("button",{type:"button",onClick:Ie,className:"fixed right-4 bottom-24 z-40 hidden md:inline-flex items-center gap-2 rounded-full border border-border-subtle bg-bg-primary/88 backdrop-blur px-2.5 py-2 text-xs text-text-secondary hover:text-text-primary transition-colors",style:{boxShadow:"0 6px 18px rgba(0,0,0,0.12)"},title:"Dashboard guide","aria-label":"Open dashboard guide",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full bg-bg-secondary text-[11px] font-semibold text-text-primary shrink-0",children:"?"}),e.jsx("span",{children:"Guide"})]})]})}const ur=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Ql({onClose:t}){const[s,r]=a.useState(0),n=ur[s],i=s===ur.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:ur.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:n.visual||n.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:n.icon})," ",n.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:n.desc}),n.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),n.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():r(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
41
+ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:M,onCancel:()=>l(null)})]})}const gc=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function yc(){const{preference:t,setPreference:s}=ga();return e.jsx("div",{className:"flex gap-2",children:gc.map(r=>e.jsxs("button",{onClick:()=>s(r.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===r.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===r.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:r.icon}),r.label]},r.id))})}function vc(t){const s=t.trim();return/^#[0-9a-fA-F]{6}$/.test(s)?s:/^#[0-9a-fA-F]{3}$/.test(s)?`#${s[1]}${s[1]}${s[2]}${s[2]}${s[3]}${s[3]}`:null}function wc(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function ar(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function bn(t){const{r:s,g:r,b:n}=wc(t);return .2126*ar(s)+.7152*ar(r)+.0722*ar(n)}function gn(t,s){const r=bn(t),n=bn(s),i=Math.max(r,n),o=Math.min(r,n);return(i+.05)/(o+.05)}function $r(t){const s=vc(t);if(!s)return"#111827";const r="#111827",n="#ffffff";return gn(s,r)>=gn(s,n)?r:n}const ya="adhdev-accent-color",yr="#cf7a45";function jc(t){const s=parseInt(t.slice(1,3),16)/255,r=parseInt(t.slice(3,5),16)/255,n=parseInt(t.slice(5,7),16)/255,i=Math.max(s,r,n),o=Math.min(s,r,n);let c=0,u=0;const d=(i+o)/2;if(i!==o){const x=i-o;switch(u=d>.5?x/(2-i-o):x/(i+o),i){case s:c=((r-n)/x+(r<n?6:0))/6;break;case r:c=((n-s)/x+2)/6;break;case n:c=((s-r)/x+4)/6;break}}return{h:Math.round(c*360),s:Math.round(u*100),l:Math.round(d*100)}}function yn(t,s){const{h:r,s:n,l:i}=jc(t),o=Math.min(100,i+s);return`hsl(${r}, ${n}%, ${o}%)`}function ir(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function kc(){return typeof window>"u"?yr:localStorage.getItem(ya)||yr}function Nc(){if(typeof window>"u")return!1;try{return localStorage.getItem(ya)!=null}catch{return!1}}function Sc(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",yn(t,15)),s.style.setProperty("--accent-on-primary",$r(t)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${yn(t,20)})`),s.style.setProperty("--border-accent",ir(t,.4)),s.style.setProperty("--nav-active-bg",ir(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${ir(t,.06)}`)}function Cc(){const t=kc();t!==yr&&Sc(t)}const vr={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},wr={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},Ic=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],va="adhdev-chat-theme",wa="adhdev-chat-theme-custom";function Ls(){if(typeof window>"u")return"ember";try{return localStorage.getItem(va)||"ember"}catch{return"ember"}}function vt(t){try{const s=localStorage.getItem(wa);if(s){const r=JSON.parse(s);return{...t==="dark"?vr:wr,...r[t]}}}catch{}return t==="dark"?vr:wr}function ws(t,s){try{localStorage.setItem(wa,JSON.stringify({dark:t,light:s}))}catch{}}function ht(t,s){const r=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${r}, ${n}, ${i}, ${s})`}function Os(t,s){const r=Math.min(255,parseInt(t.slice(1,3),16)+s),n=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Tc={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function cs(t,s){var i;if(Nc())return;const r=(i=Tc[t])==null?void 0:i[s];if(!r)return;const n=document.documentElement;n.style.setProperty("--accent-primary",r),n.style.setProperty("--accent-primary-light",Os(r,24)),n.style.setProperty("--accent-on-primary",$r(r)),n.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${r}, ${Os(r,18)})`),n.style.setProperty("--border-accent",ht(r,.35)),n.style.setProperty("--nav-active-bg",ht(r,.1)),n.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${r}, 0 0 12px ${ht(r,.06)}`)}function Bt(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",ht(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",ht(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",ht(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",ht(t.borderSubtle,.5)),s.style.setProperty("--border-default",ht(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Os(t.accentColor,30)),s.style.setProperty("--accent-on-primary",$r(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Os(t.accentColor,40)})`),s.style.setProperty("--border-accent",ht(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",ht(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${ht(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${ht(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--dashboard-pane-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Dr(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-on-primary","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--dashboard-pane-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(r=>t.style.removeProperty(r))}function Ac(t){try{localStorage.setItem(va,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Kt()?"dark":"light";Bt(vt(s))}else Dr(),cs(t,Kt()?"dark":"light")}function _c(){const t=Ls();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Kt()?"dark":"light";Bt(vt(s))}else Dr(),cs(t,Kt()?"dark":"light")}function Kt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function it({label:t,value:s,onChange:r}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[e.jsx("input",{type:"color",value:s,onChange:n=>r(n.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:n=>{/^#[0-9a-fA-F]{0,6}$/.test(n.target.value)&&r(n.target.value)},style:{width:68,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function as({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function Mc({dark:t,onColorsChange:s}){const r=t?"dark":"light",[n,i]=a.useState(()=>vt(r));a.useEffect(()=>{i(vt(r))},[r]);const o=a.useCallback((c,u)=>{i(d=>{const x={...d,[c]:u},f=vt(r==="dark"?"light":"dark");return r==="dark"?ws(x,f):ws(f,x),Bt(x),s(x),x})},[r,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 14px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12,overflow:"hidden"},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(as,{title:"App Background",children:[e.jsx(it,{label:"Background",value:n.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(it,{label:"Surface",value:n.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(it,{label:"Card",value:n.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(as,{title:"App Text",children:[e.jsx(it,{label:"Primary",value:n.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(it,{label:"Secondary",value:n.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(it,{label:"Muted",value:n.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(as,{title:"Borders & Accent",children:[e.jsx(it,{label:"Border subtle",value:n.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(it,{label:"Border default",value:n.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(it,{label:"Accent",value:n.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(as,{title:"Chat Bubbles",children:[e.jsx(it,{label:"User bubble",value:n.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(it,{label:"User text",value:n.userText,onChange:c=>o("userText",c)}),e.jsx(it,{label:"Agent bubble",value:n.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(it,{label:"Agent text",value:n.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(as,{title:"Chat Layout",children:[e.jsx(it,{label:"Chat BG",value:n.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(it,{label:"Send button",value:n.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(it,{label:"Input border",value:n.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:"1 1 0",minWidth:0},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:n.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[n.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?vr:wr,d=vt(t?"light":"dark");t?ws(c,d):ws(d,c),i(c),Bt(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Pc(){const[t,s]=a.useState(Ls),[r,n]=a.useState(!0),[i,o]=a.useState(()=>vt("dark"));a.useEffect(()=>{n(Kt());const d=new MutationObserver(()=>{const f=Kt();n(f);const b=Ls();b==="custom"?Bt(vt(f?"dark":"light")):cs(b,f?"dark":"light")});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const f=Kt();n(f);const b=Ls();b==="custom"?Bt(vt(f?"dark":"light")):cs(b,f?"dark":"light")};return x.addEventListener("change",l),()=>{d.disconnect(),x.removeEventListener("change",l)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Bt(vt(r?"dark":"light")):(Dr(),cs(t,r?"dark":"light"))},[t,r]),a.useEffect(()=>{o(vt(r?"dark":"light"))},[r]);const c=d=>{s(d),Ac(d)},u=[...Ic,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(d=>{const x=t===d.id,l=r?d.preview.dark:d.preview.light,f=d.id==="honey"||d.id==="ember"?"#1a1a1a":d.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.userBubble,color:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:d.id==="custom"?"🎨 Custom":d.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),t==="custom"&&e.jsx(Mc,{dark:r,onColorsChange:d=>o(d)})]})}const ja="adhdev_mobileDashboardMode_v1";function ka(){try{return localStorage.getItem(ja)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Lc(t){try{localStorage.setItem(ja,t)}catch{}}function Rc(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(ka()==="chat")},[]),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{size:15})," Mobile Inbox (Chat Mode)"]}),description:t?"Use the chat-first mobile inbox layout. This keeps mobile closer to a messaging app.":"Use the full workspace layout on phones and tablets.",checked:t,onChange:r=>{s(r),Lc(r?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Na="adhdev_hiddenTabs";function Ec(){try{const t=localStorage.getItem(Na);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function qt(t){try{localStorage.setItem(Na,JSON.stringify([...t]))}catch{}}function $c(){const[t,s]=a.useState(Ec),r=a.useCallback(x=>{s(l=>{const f=new Set(l);return f.has(x)?f.delete(x):f.add(x),qt(f),f})},[]),n=a.useCallback(x=>{s(l=>{if(l.has(x))return l;const f=new Set(l);return f.add(x),qt(f),f})},[]),i=a.useCallback(x=>{s(l=>{if(!l.has(x))return l;const f=new Set(l);return f.delete(x),qt(f),f})},[]),o=a.useCallback(()=>{s(x=>{if(x.size===0)return x;const l=new Set;return qt(l),l})},[]),c=a.useCallback((x,l)=>{s(f=>{const b=new Set(f);for(const p of l)b.add(p);return qt(b),b})},[]),u=a.useCallback((x,l)=>{s(f=>{const b=new Set(f);for(const p of l)b.delete(p);return qt(b),b})},[]),d=a.useCallback(x=>t.has(x),[t]);return{hiddenTabs:t,toggleTab:r,hideTab:n,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:u,isHidden:d}}function Dc({visibleConversations:t,clearedTabs:s,setClearedTabs:r,setActionLogs:n}){a.useEffect(()=>{tc()},[]);const i=a.useMemo(()=>t.map(o=>({id:o.tabKey,name:o.title||o.agentName||o.ideId,status:o.status,activeModal:o.modalMessage?{message:o.modalMessage,buttons:o.modalButtons}:null})),[t]);return rc(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{r(u=>{const d=Date.now(),x={};for(const[l,f]of Object.entries(u))d-f<5e3&&(x[l]=f);return Object.keys(x).length===Object.keys(u).length?u:x})},5500);return()=>clearTimeout(c)},[s,r]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;n(u=>{const d=u.filter(x=>x.timestamp>c).slice(-100);return d.length===u.length?u:d})},6e4);return()=>clearInterval(o)},[n]),null}function or(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const s=Date.parse(t);if(Number.isFinite(s))return s}return 0}function Dt(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1];return or(s==null?void 0:s.timestamp)||or(s==null?void 0:s.receivedAt)||or(s==null?void 0:s.createdAt)||0}function jr(t,s=0){return Dt(t)||s||0}function Sa(t){return Dt(t)}function Bc(t,s,r=Sa){const n=r(s)-r(t);if(n!==0)return n;const i=(t.machineName||"").localeCompare(s.machineName||"");if(i!==0)return i;const o=t.displayPrimary.localeCompare(s.displayPrimary);if(o!==0)return o;const c=t.displaySecondary.localeCompare(s.displaySecondary);return c!==0?c:t.tabKey.localeCompare(s.tabKey)}function Kc(t){const s=t.filter(n=>n.type!=="adhdev-daemon"),r=new Map;for(const n of s){const i=r.get(n.id);if(!i){r.set(n.id,n);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((n.workspace?1:0)+(n.activeChat?1:0)>o||(n.timestamp||0)>(i.timestamp||0))&&r.set(n.id,n)}return Array.from(r.values())}function js(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r]!==s[r])return!1;return!0}function Wc(t,s){const r=Date.now();return t.map(n=>{const i=s[n.tabKey];return i&&r-i<5e3?{...n,messages:[],title:""}:n})}function Oc(t,s){const r=[],n=t.sessionId||t.instanceId;r.push({key:t.id,ref:s[t.id]}),n&&r.push({key:n,ref:s[n]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;r.push({key:c,ref:s[c]}),r.push({key:i.id,ref:s[i.id]})}return r}function Uc(t,s){if(t.length!==s.length)return!1;for(let r=0;r<t.length;r+=1)if(t[r].key!==s[r].key||t[r].ref!==s[r].ref)return!1;return!0}function zc(t){return[...t.messages].reverse().find(s=>!(s!=null&&s._localId))||t.messages[t.messages.length-1]}function Hc(t){const s=zc(t);if(!s)return`empty:${t.messages.length}`;if(s.id)return`id:${String(s.id)}`;if(s._localId)return`local:${String(s._localId)}`;const r=String(s.role||""),n=Lr(s.content).slice(0,240);return`${t.messages.length}:${r}:${n}`}function Fc({ides:t,connectionStates:s,localUserMessages:r,clearedTabs:n,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),u=a.useRef([]),d=a.useRef([]),x=a.useMemo(()=>{const N=Kc(t);return js(o.current,N)?o.current:(o.current=N,N)},[t]),l=a.useMemo(()=>ma(t),[t]),f=a.useRef(new Map),b=a.useRef(new Map),p=a.useMemo(()=>{var M;const N=new Map,j=[];for(const $ of x){const U=$.daemonId||((M=$.id)==null?void 0:M.split(":")[0])||$.id,D=s[U]||"new",_=$.daemonId&&l[$.daemonId]||void 0,W=Oc($,r),E=f.current.get($.id);if(E&&E.ide===$&&E.connectionState===D&&E.machineName===_&&Uc(E.localRefs,W)){N.set($.id,E),j.push(...E.conversations);continue}const H=Rr($,r,{machineName:_,connectionState:D}),X={ide:$,connectionState:D,machineName:_,localRefs:W,conversations:H};N.set($.id,X),j.push(...H)}f.current=N;const k=new Map,w=$=>{const U=Hc($),D=b.current.get($.tabKey);if(D&&D.signature===U)return k.set($.tabKey,D),D.timestamp;const _={signature:U,timestamp:Sa($)||(D==null?void 0:D.timestamp)||0};return k.set($.tabKey,_),_.timestamp},L=[...j].sort(($,U)=>Bc($,U,w));return b.current=k,L},[x,r,s,l]),S=a.useMemo(()=>{const N=Wc(p,n);return js(c.current,N)?c.current:(c.current=N,N)},[p,n]),m=a.useMemo(()=>{const N=new Map;for(const j of S)j.sessionId&&N.set(j.sessionId,j);return N},[S]),h=a.useMemo(()=>{const N=new Map;for(const j of S)j.sessionId&&N.set(j.sessionId,j),N.set(j.ideId,j),N.set(j.tabKey,j);return N},[S]),y=a.useCallback(N=>{if(N)return m.get(N)},[m]),g=a.useCallback(N=>{if(N)return h.get(N)},[h]),v=a.useMemo(()=>{const N=S.filter(j=>!i.has(j.tabKey));return js(u.current,N)?u.current:(u.current=N,N)},[S,i]),K=a.useMemo(()=>{const N=v.map(j=>j.tabKey);return js(d.current,N)?d.current:(d.current=N,N)},[v]);return{chatIdes:x,conversations:S,visibleConversations:v,visibleTabKeys:K,resolveConversationBySessionId:y,resolveConversationByTarget:g}}function Vc({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:r,setSearchParams:n}){const i=a.useMemo(()=>{var u;return t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),o=a.useMemo(()=>{var u;return!t||!s?null:((u=r(s))==null?void 0:u.tabKey)??null},[t,r,s]),c=a.useCallback(()=>{s&&n(u=>{const d=new URLSearchParams(u);return d.delete("activeTab"),d},{replace:!0})},[n,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function qc({ides:t,sendDaemonCommand:s,setToasts:r,setLocalUserMessages:n,resolveConversationByTarget:i}){a.useEffect(()=>{_t.setIdes(t)},[t]),a.useEffect(()=>{_t.setResolveAction((o,c,u)=>{s(o,c,u).catch(()=>{})})},[s]),a.useEffect(()=>{const o=_t.onToast(d=>{r(l=>l.some(b=>b.message===d.message&&d.timestamp-b.timestamp<3e3)?l:[...l.slice(-4),{id:d.id,message:d.message,type:d.type,timestamp:d.timestamp,targetKey:d.targetKey,actions:d.actions}]);const x=d.duration||5e3;setTimeout(()=>r(l=>l.filter(f=>f.id!==d.id)),x)}),c=_t.onSystemMessage((d,x)=>{var p,S;const l=i(d),f=(p=x._localId)==null?void 0:p.startsWith("sys_approval_"),b=!!(l&&(l.status==="waiting_approval"||(S=l.modalButtons)!=null&&S.length||l.modalMessage));f&&b||n(m=>({...m,[d]:[...m[d]||[],x]}))}),u=_t.onClearSystemMessage((d,x)=>{n(l=>{var f;return(f=l[d])!=null&&f.length?{...l,[d]:l[d].filter(b=>{var p;return!(b.role==="system"&&((p=b._localId)!=null&&p.startsWith(x)))})}:l})});return()=>{o(),c(),u()}},[r,n]),a.useEffect(()=>{const o=da.on("status_event",c=>_t.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=u=>{var h;const d=u.data;if((d==null?void 0:d.type)!=="notification_action"||typeof d.action!="string"||!d.action.startsWith("approval_")||!(d.ideId||d.targetSessionId||d.targetKey))return;const x=d.targetSessionId||d.targetKey||d.ideId,l=i(x),f=(l==null?void 0:l.ideId)||d.ideId;if(!f)return;const b=Number(d.buttonIndex),p=d.button||((h=l==null?void 0:l.modalButtons)==null?void 0:h[b])||"Approve",S=String(p).replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),m=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(S);s(f,"resolve_action",{action:m?"approve":"reject",button:p,...Number.isFinite(b)&&{buttonIndex:b},...(l==null?void 0:l.sessionId)&&{targetSessionId:l.sessionId},...d.targetSessionId&&{targetSessionId:d.targetSessionId}}).catch(y=>console.error("[SW Action] approval failed:",y))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",o)}},[i,s])}const Gc="adhdev_dashboardLayout_v1",Yc="adhdev_dashboardDockview_v1",is={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Ca(t,s){try{const r=localStorage.getItem(t);return r?JSON.parse(r):s}catch{return s}}function Ia(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function Ta(t){return`${Gc}:${t}`}function Xc(t){const s=Ta(t);return Ca(s,null)}function Jc(t,s){try{const r=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,n=Ta(t);if(r){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Aa(t){return`${Yc}:${t}`}function Zc(t){const s=Aa(t);return Ca(s,null)}function Qc(t,s){try{const r=Aa(t);if(!s){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function el(){return{groupAssignments:[...is.groupAssignments],focusedGroup:is.focusedGroup,groupActiveTabIds:{...is.groupActiveTabIds},groupTabOrders:{...is.groupTabOrders},groupSizes:[...is.groupSizes]}}function tl(){const[t]=a.useState(()=>Ia(typeof window<"u"?window.innerWidth:1280)),[s,r]=a.useState(()=>new Map),[n,i]=a.useState(0),[o,c]=a.useState({}),[u,d]=a.useState({}),[x,l]=a.useState([]),[f,b]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,S]=a.useState(!1),m=a.useCallback(()=>{if(p)return;const h=Xc(t)??el();r(new Map(h.groupAssignments)),i(h.focusedGroup),c(h.groupActiveTabIds),d(h.groupTabOrders),l(h.groupSizes),S(!0)},[p,t]);return a.useEffect(()=>{p&&Jc(t,{groupAssignments:[...s.entries()],focusedGroup:n,groupActiveTabIds:o,groupTabOrders:u,groupSizes:x})},[p,t,s,n,o,u,x]),a.useEffect(()=>{const h=window.matchMedia("(max-width: 767px)"),y=g=>b(g.matches);return h.addEventListener("change",y),()=>h.removeEventListener("change",y)},[]),{groupAssignments:s,setGroupAssignments:r,focusedGroup:n,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:u,setGroupTabOrders:d,groupSizes:x,setGroupSizes:l,isMobile:f,hasHydratedStoredLayout:p,hydrateStoredLayout:m}}function sl({urlActiveTab:t,conversations:s,resolveConversationBySessionId:r,normalizedGroupAssignments:n,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:u,setSearchParams:d,historyModalOpen:x,activeConv:l,isRefreshingHistory:f,ides:b,handleRefreshHistory:p}){const S=a.useRef(!1),m=a.useRef(!1),h=a.useRef(null),y=a.useRef(!1);a.useEffect(()=>{if(!t||S.current||s.length===0)return;if(!i){o();return}const g=r(t);if(!g)return;const v=n.get(g.tabKey)??0;c(K=>({...K,[v]:g.tabKey})),u(v),S.current=!0,m.current=!0,h.current!=null&&(window.clearTimeout(h.current),h.current=null),d(K=>{const N=new URLSearchParams(K);return N.delete("activeTab"),N},{replace:!0})},[t,s,r,n,i,o,c,u,d]),a.useEffect(()=>{if(!(m.current||i)&&s.length!==0){if(!t){o(),m.current=!0;return}if(S.current){m.current=!0;return}if(h.current==null)return h.current=window.setTimeout(()=>{h.current=null,!(m.current||i)&&(o(),m.current=!0)},1500),()=>{h.current!=null&&(window.clearTimeout(h.current),h.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!x){y.current=!1;return}if(!l||y.current||f)return;const g=b.find(v=>v.id===l.ideId);g&&(!g.chats||g.chats.length===0)&&(y.current=!0,p())},[x,l,f,b,p]),a.useEffect(()=>{if(!l)return;let g=null,v=0,K=-1,N=0;const j=()=>{g=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(L=>L.offsetParent!==null);if(k.length===0){v<18&&(v+=1,g=requestAnimationFrame(j));return}let w=0;for(const L of k)L.scrollTop=L.scrollHeight,w+=L.scrollHeight;w===K?N+=1:(N=0,K=w),v+=1,!(N>=2||v>=18)&&(g=requestAnimationFrame(j))};return g=requestAnimationFrame(j),()=>{g!=null&&cancelAnimationFrame(g)}},[l==null?void 0:l.tabKey])}function rl({isMobile:t,location:s,navigate:r,requestedRemoteTabTarget:n,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:u}){const[d,x]=a.useState(null),[l,f]=a.useState(null),b=a.useMemo(()=>{if(t||!n)return null;const y=u(n);return y&&!Ye(y)&&!ze(y)?y:null},[t,n,u]),p=a.useMemo(()=>{const y=d==null?void 0:d.ideId;if(!y)return null;const g=d!=null&&d.tabKey?o.find(v=>v.tabKey===d.tabKey):i?o.find(v=>v.tabKey===i):null;return(g==null?void 0:g.ideId)===y?g:o.find(v=>v.ideId===y&&v.streamSource==="native")||o.find(v=>v.ideId===y)||null},[o,d,i]),S=a.useMemo(()=>{if(p)return c.find(y=>y.id===p.ideId)},[c,p]);a.useEffect(()=>{b&&(x({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),f(b),r({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,r,b]);const m=a.useCallback(y=>{y&&(x({ideId:y.ideId,tabKey:y.streamSource==="native"?"native":y.tabKey}),f(y))},[]),h=a.useCallback(()=>{x(null),f(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:S,remoteDialogActiveConv:l,setRemoteDialogActiveConv:f,openRemoteDialog:m,closeRemoteDialog:h}}function Jt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ye(t)||ze(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function ps(t){return t&&(t.ideId||t.daemonId)||""}function ks(t,s){t(r=>[...r,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function vn({sendDaemonCommand:t,activeConv:s,updateIdeChats:r,setToasts:n,setLocalUserMessages:i,setClearedTabs:o}){const[c,u]=a.useState(!1),[d,x]=a.useState(!1),l=a.useCallback(async S=>{try{await t("standalone","launch_ide",{ideType:S,enableCdp:!0})}catch(m){console.error("Launch failed",m)}},[t]),f=a.useCallback(async(S,m)=>{try{const h=S||(s==null?void 0:s.daemonId)||"",y=await t(h,"switch_chat",{id:m,sessionId:m,...Jt(s)}),g=y==null?void 0:y.result;if((y==null?void 0:y.success)===!0||g==="switched"||g==="switched-by-title")return;g===!1||g==="not_found"?ks(n,"⚠️ Session tab not found — try refreshing history"):typeof g=="string"&&g.startsWith("error:")?ks(n,`⚠️ Switch error: ${g}`):ks(n,"⚠️ Session switch failed")}catch(h){console.error("Switch failed",h),ks(n,`❌ Switch failed: ${h.message||"connection error"}`)}},[s,t,n]),b=a.useCallback(async()=>{if(!(!s||c)){u(!0);try{const S=ps(s);await t(S,"new_chat",{...Jt(s)}),o(m=>({...m,[s.tabKey]:Date.now()})),i(m=>({...m,[s.tabKey]:[]}))}catch(S){console.error("New chat failed",S)}finally{u(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var S;if(!(!s||d)){x(!0);try{const m=ps(s),h=await t(m,"list_chats",{forceExpand:!0,...Jt(s)}),y=(h==null?void 0:h.chats)||((S=h==null?void 0:h.result)==null?void 0:S.chats);h!=null&&h.success&&Array.isArray(y)&&r(s.ideId,y)}catch(m){console.error("Refresh history failed",m)}finally{x(!1)}}},[s,d,t,r]);return{isCreatingChat:c,isRefreshingHistory:d,handleLaunchIde:l,handleSwitchSession:f,handleNewChat:b,handleRefreshHistory:p}}function nl(t,s){if(t.size!==s.size)return!1;for(const[r,n]of t)if(s.get(r)!==n)return!1;return!0}function al(t,s){return t.length!==s.length?!1:t.every((r,n)=>r===s[n])}function wn(t,s){const r=Object.keys(t),n=Object.keys(s);return r.length!==n.length?!1:r.every(i=>s[Number(i)]===t[Number(i)])}function Ns(t,s){const r=new Set(s),n=s.length>0?[0]:[];for(const[c,u]of t)!r.has(c)||u<=0||n.includes(u)||n.push(u);n.sort((c,u)=>c-u);const i={};n.forEach((c,u)=>{i[c]=u}),n.length===0&&(i[0]=0);const o=new Map;for(const[c,u]of t){if(!r.has(c)||u<=0)continue;const d=i[u];typeof d=="number"&&d>0&&o.set(c,d)}return{assignments:o,groupCount:Math.max(1,n.length),mapping:i,usedGroups:n}}function jn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=s[Number(n)];typeof o=="number"&&(r[o]=i)}return r}function il(t,s,r){if(s.length===0)return 0;if(typeof r[t]=="number")return r[t];const n=[...s].reverse().find(i=>i<t)??s[0];return r[n]??0}function ol(t,s,r){if(s.length<=1)return[];const n=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=n.length===s.length?n:Array(r).fill(100/r),o=i.reduce((c,u)=>c+u,0);return o>0?i.map(c=>c/o*100):Array(r).fill(100/r)}function kn(t,s){const r={};for(const[n,i]of Object.entries(t)){const o=Number(n);r[o>=s?o+1:o]=i}return r}function Nn(t){return Array(t).fill(100/t)}function cl({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:r,setGroupActiveTabIds:n,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:u,visibleConversations:d,visibleTabKeys:x}){const l=a.useRef(null),f=a.useMemo(()=>Ns(t,x),[t,x]),b=f.assignments,p=a.useMemo(()=>u?1:f.groupCount,[f.groupCount,u]),S=p>1,m=a.useCallback((N,j)=>{s(k=>{const w=new Map(Ns(k,x).assignments);return j===0?w.delete(N):w.set(N,j),w}),n(k=>({...k,[j]:N})),r(j)},[s,x,n,r]),h=a.useCallback(N=>{s(j=>{const k=Ns(j,x).assignments,w=new Map;for(const[L,M]of k)M!==N&&(M>N?w.set(L,M-1):w.set(L,M));return w}),c(j=>{if(j.length<=1)return[];const k=[...j];k.splice(N,1);const w=k.reduce((L,M)=>L+M,0);return w>0?k.map(L=>L/w*100):[]}),r(0)},[s,x,c,r]),y=a.useCallback((N,j)=>{j.preventDefault();const k=l.current;if(!k)return;const w=j.clientX,L=k.offsetWidth,M=o.length===p?[...o]:Nn(p),$=D=>{const W=(D.clientX-w)/L*100,E=[...M];E[N]=Math.max(15,M[N]+W),E[N+1]=Math.max(15,M[N+1]-W),c(E)},U=()=>{document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",U),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",$),document.addEventListener("mouseup",U)},[o,p,c]),g=a.useCallback((N,j,k)=>{if(p>=4)return;const w=k==="left"?j:j+1;s(L=>{const M=Ns(L,x).assignments,$=new Map;for(const U of d){const D=M.get(U.tabKey)??0,_=D>=w?D+1:D;_>0&&$.set(U.tabKey,_)}return w>0&&$.set(N,w),$}),c(L=>{const M=L.length===p?[...L]:Nn(p),$=M[j]??100/p,U=Math.max(15,$/2),D=Math.max(15,$/2),_=[...M];_[j]=U,_.splice(w,0,D);const W=_.reduce((E,H)=>E+H,0);return _.map(E=>E/W*100)}),n(L=>{const M=kn(L,w);return M[w]=N,M}),i(L=>{const M=kn(L,w);return M[w]=[N],M}),r(w)},[p,s,x,d,c,n,i,r]);a.useEffect(()=>{nl(t,b)||s(b)},[t,b,s]),a.useEffect(()=>{const{mapping:N,usedGroups:j}=f;n(k=>{const w=jn(k,N);return wn(k,w)?k:w}),i(k=>{const w=jn(k,N);return wn(k,w)?k:w}),r(k=>{const w=u?0:il(k,j,N);return k===w?k:w}),c(k=>{const w=u?[]:ol(k,j,f.groupCount);return al(k,w)?k:w})},[f,u,n,i,r,c]);const v=a.useMemo(()=>{const N=Array.from({length:p},()=>[]);for(const j of d){const k=b.get(j.tabKey)??0,w=Math.min(k,p-1);N[w].push(j)}return N},[d,b,p]),K=a.useCallback(()=>{s(new Map),r(0)},[s,r]);return{containerRef:l,normalizedGroupAssignments:b,numGroups:p,isSplitMode:S,groupedConvs:v,moveTabToGroup:m,closeGroup:h,handleResizeStart:y,splitTabRelative:g,clearAllSplits:K}}function ll({ides:t,sendDaemonCommand:s}){const r="0.8.24",n=a.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const l=x.version||x.daemonVersion||null;return!l||!r?!1:l!==r}),[r,t]),[i,o]=a.useState(!1),[c,u]=a.useState({}),d=a.useCallback(async x=>{var l,f;u(b=>({...b,[x]:"upgrading"}));try{const b=await s(x,"daemon_upgrade",{});(l=b==null?void 0:b.result)!=null&&l.upgraded||(f=b==null?void 0:b.result)!=null&&f.success?u(p=>({...p,[x]:"done"})):u(p=>({...p,[x]:"error"}))}catch{u(b=>({...b,[x]:"error"}))}},[s]);return{versionMismatchDaemons:n,appVersion:r,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:d}}function Sn(t){return!t||typeof t!="object"?t:t.result&&typeof t.result=="object"?t.result:t}function _a(t){return t instanceof Error?t.message:String(t||"")}function Cn(t){const s=_a(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Ys({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:r,setActionLogs:n,isStandalone:i}){const[o,c]=a.useState(!1),[u,d]=a.useState(!1),x=a.useRef(!1),l=a.useRef(null),f=a.useCallback(async m=>{if(!s)return;const h=m.trim();if(!h||x.current)return;const y=s.tabKey,g=Date.now(),v=l.current;if(v&&v.tabKey===y&&v.message===h&&g-v.timestamp<2e3)return;x.current=!0,d(!0),l.current={tabKey:y,message:h,timestamp:g};const K=`${g}-${Math.random().toString(36).slice(2,8)}`,N={role:"user",content:h,timestamp:g,_localId:K};r(j=>({...j,[y]:[...j[y]||[],N]}));try{const j=ps(s);if(!j)return;const k=await t(j,"send_chat",{message:h,text:h,...Jt(s)}),w=Sn(k);if(w!=null&&w.deduplicated||(w==null?void 0:w.sent)===!1){r(L=>({...L,[y]:(L[y]||[]).filter(M=>M._localId!==K)}));return}if((w==null?void 0:w.success)===!1)throw new Error((w==null?void 0:w.error)||"Send failed");setTimeout(()=>{const L=Date.now()-6e4;r(M=>{const $=M[y];if(!$)return M;const U=$.filter(D=>D.timestamp>L);return U.length===$.length?M:{...M,[y]:U}})},6e4)}catch(j){const k=_a(j);k.toLowerCase().includes("provider sendmessage did not confirm send")?console.warn("Send not confirmed by provider script:",k):console.error("Send failed",j),r(w=>({...w,[y]:(w[y]||[]).filter(L=>L._localId!==K)}))}finally{x.current=!1,d(!1)}},[s,t,r]),b=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(m){console.error("Relaunch failed",m)}},[s,t]),p=a.useCallback(async m=>{if(s)try{const y=(s.modalButtons||[]).indexOf(m),g=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),v=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),K=ps(s);if(!K)return;const N=await t(K,"resolve_action",{button:m,action:v?"approve":"reject",...y>=0&&{buttonIndex:y},...Jt(s)});Sn(N).success||n(k=>[...k,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(h){Cn(h)||console.error("[ModalButton] Error:",h),n(y=>[...y,{ideId:s.tabKey,text:Cn(h)?`⚠️ **${m}** unavailable`:`❌ **${m}** error`,timestamp:Date.now()}])}},[s,t,n]),S=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:u,isFocusingAgent:o,handleSendChat:f,handleRelaunch:b,handleModalButton:p,handleFocusAgent:S}}const Br=a.memo(function({activeConv:s,clearToken:r,isCliTerminal:n,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:u,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m=!0}){return e.jsxs(e.Fragment,{children:[e.jsx(na,{activeConv:s,onModalButton:c}),s.transport!=="pty"&&s.transport!=="acp"&&s.cdpConnected===!1?e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(Fs,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:u,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:n?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx($o,{activeConv:s,clearToken:r,terminalRef:o,handleSendChat:d,isSendingChat:x,isVisible:n})}),!n&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(br,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m})})]}):e.jsx(br,{activeConv:s,ideEntry:i,handleSendChat:d,isSendingChat:x,handleFocusAgent:l,isFocusingAgent:f,actionLogs:b,userName:p,scrollToBottomRequestNonce:S,isInputActive:m})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCliTerminal===s.isCliTerminal&&t.ideEntry===s.ideEntry&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName&&t.scrollToBottomRequestNonce===s.scrollToBottomRequestNonce&&t.isInputActive===s.isInputActive);function dl({selectedConversation:t,isAcp:s,isStandalone:r,selectedIdeEntry:n,actionLogs:i,userName:o,isSendingChat:c,isFocusingAgent:u,onBack:d,onOpenNativeConversation:x,onOpenMachine:l,onOpenHistory:f,onOpenRemote:b,onHideConversation:p,onStopCli:S,cliViewMode:m,onSetCliViewMode:h,handleSendChat:y,handleFocusAgent:g,handleModalButton:v,handleRelaunch:K}){const N=a.useRef(null),j=Ye(t)&&!s,k=j&&m==="terminal",w=r?"px-4 pt-3.5 pb-2.5":"px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between gap-3 ${w} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:d,type:"button","aria-label":"Back",children:e.jsx(Nr,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:t.displayPrimary||t.agentName}),e.jsx("div",{className:"min-w-0 overflow-hidden text-xs text-text-secondary",children:e.jsx(oa,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>x(t),onOpenMachine:()=>l(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[j&&m&&e.jsx(Mr,{mode:m,onChange:h,compact:!0}),j&&S&&e.jsx("button",{onClick:()=>{S(t)},className:"btn btn-secondary btn-sm",title:"Stop CLI process",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, transparent)"},children:e.jsx(Ut,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>f(t),type:"button",children:e.jsx(Sr,{size:14})}),!s&&!j&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>b(t),type:"button",children:e.jsx(ct,{size:14})}),p&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>p(t),type:"button",title:"Close chat",children:e.jsx(Ut,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Br,{activeConv:t,clearToken:0,isCliTerminal:k,ideEntry:n,terminalRef:N,handleModalButton:v,handleRelaunch:K,handleSendChat:y,isSendingChat:c,handleFocusAgent:g,isFocusingAgent:u,actionLogs:i,userName:o})})]})}const cr={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function ul(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Ma(){const[t,s]=a.useState("unix"),[r,n]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":r;a.useEffect(()=>{s(ul())},[]);const u=a.useCallback(()=>{navigator.clipboard.writeText(cr[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent-primary/12 text-accent-primary border border-accent-primary/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${r==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>n("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:cr[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:cr[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Pa({section:t,onSectionChange:s}){const r=[{key:"machines",label:"Machines",icon:ct},{key:"chats",label:"Chats",icon:Nt}];return e.jsx("div",{className:"px-3 py-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))] border-t border-border-subtle/70 bg-bg-secondary/88 backdrop-blur-md shrink-0",children:e.jsx("div",{className:"grid grid-cols-2 gap-1.5 rounded-[20px] border p-1 shadow-[0_10px_28px_rgba(15,23,42,0.08)]",style:{background:"color-mix(in srgb, var(--bg-glass) 82%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--border-subtle) 88%, var(--accent-primary) 12%)"},children:r.map(({key:n,label:i,icon:o})=>{const c=t===n;return e.jsxs("button",{className:`min-h-[46px] rounded-[16px] px-3 flex items-center justify-center gap-2.5 text-[13px] font-semibold tracking-tight transition-all border ${c?"bg-surface-primary border-border-default/90 text-text-primary shadow-[0_4px_14px_rgba(15,23,42,0.08)]":"bg-transparent border-transparent text-text-muted hover:text-text-primary"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 10%, var(--surface-primary))",borderColor:"color-mix(in srgb, var(--accent-primary) 24%, var(--border-default))",boxShadow:"0 8px 22px color-mix(in srgb, var(--accent-primary) 10%, transparent)"}:void 0,onClick:()=>s(n),type:"button","aria-pressed":c,children:[e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-full transition-colors ${c?"text-accent-primary":"bg-transparent text-current"}`,style:c?{background:"color-mix(in srgb, var(--accent-primary) 14%, transparent)"}:void 0,children:e.jsx(o,{size:15})}),e.jsx("span",{children:i})]},n)})})})}function Ss({title:t,className:s=""}){return e.jsx("div",{className:`mx-1 flex items-center justify-between gap-2 px-1 py-1 text-xs ${s}`,children:e.jsx("span",{className:"font-bold uppercase tracking-[0.18em] text-text-secondary",children:t})})}function Gt({children:t,className:s=""}){return e.jsx("div",{className:`w-full min-w-0 self-stretch overflow-hidden rounded-[24px] border border-border-subtle/80 bg-bg-secondary/40 shadow-[0_10px_30px_rgba(0,0,0,0.05)] ${s}`,children:t})}function os({icon:t,title:s,subtitle:r,children:n}){return e.jsxs("div",{className:"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-6 pt-12 pb-8 text-center",children:[e.jsx("div",{className:"mb-2 rounded-2xl border border-accent-primary/10 bg-[color:color-mix(in_oklab,var(--bg-secondary)_90%,var(--accent-primary)_10%)] p-3 shadow-[0_12px_32px_rgba(0,0,0,0.08)]",children:t}),e.jsx("div",{className:"text-lg font-bold tracking-tight text-text-primary",children:s}),e.jsx("div",{className:"text-[13px] leading-relaxed text-text-secondary max-w-[320px]",children:r}),n]})}function Cs({item:t,type:s,getAvatarText:r,onOpenConversation:n}){const i=s==="needs_attention"||s==="task_complete",o=s==="working",c=s==="earlier";return e.jsxs("button",{className:`group flex items-start gap-3.5 px-4 py-3.5 w-full text-left relative overflow-hidden transition-colors active:scale-[0.995] ${i?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_92%,var(--accent-primary)_8%)]":o?"bg-[color:color-mix(in_oklab,var(--bg-secondary)_94%,var(--accent-primary)_6%)]":"bg-transparent"} ${c?"opacity-70 saturate-50":""}`,onClick:()=>n(t.conversation),type:"button",children:[i||o?e.jsx("span",{className:"pointer-events-none absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full bg-accent-primary/80"}):null,e.jsx("span",{className:`w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 ${i?"bg-accent-primary shadow-glow":o?"bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/22 text-accent-primary":"bg-bg-primary border border-border-subtle text-text-secondary"}`,style:i?{color:"var(--accent-on-primary)"}:void 0,children:r(t.conversation.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:t.conversation.displayPrimary}),!o&&e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:ra(t.timestamp)})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[t.conversation.displaySecondary,t.conversation.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ct,{size:11})," ",t.conversation.machineName]})]}),s==="needs_attention"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsx("span",{className:"text-orange-400",children:"Action needed"})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:t.preview})]}),i&&e.jsx("span",{className:"absolute top-5 right-4 w-2 h-2 rounded-full bg-accent-primary shadow-glow"}),o&&e.jsx("span",{className:"absolute top-4 right-4 rounded-full bg-accent-primary/10 px-2 py-0.5 text-[10px] font-bold text-accent-primary",children:"Live"})]},t.conversation.tabKey)}function In({size:t=32,label:s}){return e.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[e.jsx("div",{className:"rounded-full animate-spin border-[2.5px] border-accent-primary/20 border-t-accent-primary-light",style:{width:t,height:t}}),s&&e.jsx("div",{className:"text-xs font-semibold text-accent-primary-light tracking-tight",children:s})]})}function ml({section:t,attentionItems:s,unreadItems:r,workingItems:n,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:u,onOpenConversation:d,onShowConversation:x,onShowAllHidden:l,onOpenMachine:f,onOpenSettings:b,onSectionChange:p,wsStatus:S="connected",isStandalone:m=!1}){const h=S==="disconnected"||S==="reconnecting"||S==="offline"||S==="auth_failed",y=c.length>0,g=s.length>0||r.length>0||n.length>0||i.length>0,v=t==="machines"?"Machines":"Chats",K=m?"px-5 pt-4 pb-4":"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4",N=m?"px-3 pb-3":"px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))]";return e.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:`z-10 shrink-0 bg-bg-primary ${K}`,children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-2xl font-black tracking-tight text-text-primary px-1",children:v}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||r.length>0)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full border border-accent-primary/16 bg-accent-primary/10 text-accent-primary text-[11px] font-bold shadow-[0_8px_20px_rgba(0,0,0,0.05)]",children:[e.jsx(Vs,{size:13}),e.jsx("span",{children:s.length+r.length})]}),e.jsx("button",{onClick:b,className:"w-8 h-8 flex items-center justify-center rounded-full border border-border-subtle bg-bg-secondary/70 text-text-secondary hover:text-text-primary hover:border-border-default transition-colors",children:e.jsx(zs,{size:18})})]})]})}),e.jsxs("div",{className:`flex min-h-0 w-full min-w-0 flex-1 flex-col gap-3 overflow-y-auto overflow-x-hidden [-webkit-overflow-scrolling:touch] ${N}`,children:[t==="machines"&&e.jsx("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:h?e.jsx(os,{icon:e.jsx(In,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:S==="offline"?"Your device appears to be offline. Waiting for network…":S==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(os,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:m?"Waiting for your daemon":"Connect your first machine",subtitle:m?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!m&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Ma,{})})}):e.jsx(Gt,{children:c.map((j,k)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] ${k>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(j.id),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-[color:color-mix(in_oklab,var(--bg-primary)_82%,var(--accent-primary)_18%)] border border-accent-primary/16 text-text-primary shadow-[0_2px_8px_rgba(0,0,0,0.12)]",children:u(j.label)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:j.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[j.unread," new"]}):j.total>0?`${j.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:j.subtitle}),j.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[j.total," chat",j.total!==1?"s":"",j.unread>0?` · ${j.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},j.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Needs attention",className:"mb-0"}),e.jsx(Gt,{children:s.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"needs_attention",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(Gt,{children:r.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"task_complete",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsx(Ss,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(Gt,{children:n.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"working",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[i.length>0&&e.jsx(Ss,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(Gt,{children:i.map((j,k)=>e.jsx("div",{className:k>0?"border-t border-border-subtle/70":"",children:e.jsx(Cs,{item:j,type:"earlier",getAvatarText:u,onOpenConversation:d})},j.conversation.tabKey))}):g?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):h?e.jsx(os,{icon:e.jsx(In,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):y?e.jsx(os,{icon:e.jsx("div",{className:"w-11 h-11 rounded-xl flex items-center justify-center bg-accent-primary/10 text-accent-primary-light",children:e.jsx(Nt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open the machine screen, choose a workspace, then launch your first IDE, CLI, or ACP session."}):e.jsx(os,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-10 h-10 object-contain opacity-70"}),title:"No machines connected",subtitle:"Switch to the Machines tab to connect your first machine and start chatting with AI agents."})]}),t==="chats"&&o.length>0&&e.jsxs("section",{className:"flex w-full min-w-0 flex-col gap-2 self-stretch",children:[e.jsxs("div",{className:"mx-1 mt-4 mb-1 flex items-center justify-between gap-2 px-1 py-1 text-[12px] font-bold uppercase tracking-wider text-text-secondary",children:[e.jsx("span",{children:"Hidden"}),e.jsx("button",{type:"button",className:"text-accent-primary normal-case font-semibold hover:underline",onClick:l,children:"Restore all"})]}),e.jsx(Gt,{className:"bg-bg-secondary/25",children:o.map((j,k)=>e.jsxs("button",{className:`flex items-start gap-3.5 px-4 py-3.5 w-full text-left transition-colors active:scale-[0.995] opacity-50 saturate-0 ${k>0?"border-t border-border-subtle/70":""}`,onClick:()=>x(j),type:"button",children:[e.jsx("span",{className:"w-11 h-11 rounded-full flex items-center justify-center text-sm font-bold shrink-0 bg-bg-primary border border-border-subtle text-text-secondary",children:u(j.displayPrimary)}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[15px] font-bold text-text-primary truncate tracking-tight",children:j.displayPrimary}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:"Hidden"})]}),e.jsxs("div",{className:"text-[12px] font-medium text-text-secondary truncate flex items-center",children:[j.displaySecondary,j.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1 opacity-50",children:"·"}),e.jsxs("span",{className:"flex items-center gap-1 opacity-80",children:[e.jsx(ct,{size:11})," ",j.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},j.tabKey))})]})]}),e.jsx(Pa,{section:t,onSectionChange:p})]})}function pl(t){const s=t.trim();if(!s)return null;if(s.startsWith("~"))return s;if(/^[A-Za-z]:$/.test(s))return`${s[0].toUpperCase()}:\\`;if(/^[A-Za-z]:[\\/]/.test(s))return`${s[0].toUpperCase()}:${s.slice(2).replace(/\//g,"\\")}`;if(/^[A-Za-z]:[^\\/].*$/.test(s))return`${s[0].toUpperCase()}:\\${s.slice(2).replace(/[\\/]+/g,"\\")}`;const r=s.match(/^[/\\]([A-Za-z])(?:[/\\](.*))?$/);if(r){const n=r[1].toUpperCase(),i=(r[2]||"").replace(/[\\/]+/g,"\\");return i?`${n}:\\${i}`:`${n}:\\`}return null}function Xs(t,s=[]){if(t==="win32"){for(const r of s){if(typeof r!="string")continue;const n=pl(r);if(n)return n}return"C:\\"}for(const r of s){const n=typeof r=="string"?r.trim():"";if(n)return n}return"~"}function fl(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const r=s.includes("\\")?"\\":"/",n=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(n[0]||"")?n.length<=2?`${n[0]}\\`:n.slice(0,-1).join("\\"):n.length<=2?r:n.slice(0,-1).join(r)||r}async function Kr(t,s,r){const n=await t(s,"file_list_browse",{path:r});if(!(n!=null&&n.success))throw new Error((n==null?void 0:n.error)||"Could not browse folder");const i=typeof(n==null?void 0:n.path)=="string"?n.path:r,o=i.includes("\\")?"\\":"/",c=(d,x)=>/^[A-Za-z]:\\?$/.test(d)?`${d.replace(/\\?$/,"\\")}${x}`:d==="/"||d==="\\"?`${o}${x}`:`${d.replace(/[\\/]+$/,"")}${o}${x}`,u=Array.isArray(n==null?void 0:n.files)?n.files.filter(d=>(d==null?void 0:d.type)==="directory"&&typeof(d==null?void 0:d.name)=="string").map(d=>({name:d.name,path:c(i,d.name)})).sort((d,x)=>d.name.localeCompare(x.name)):[];return{path:i,directories:u}}function Js({title:t,description:s,currentPath:r,directories:n,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:u,onNavigate:d,onConfirm:x}){const[l,f]=a.useState(r);a.useEffect(()=>{f(r)},[r]);const b=fl(r),p=l.trim();return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"workspace-browse-title",children:e.jsxs("div",{className:"w-full max-w-2xl max-h-[min(86vh,720px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"workspace-browse-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:u,"aria-label":"Close folder browser",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-start gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 min-h-[34px] px-3 rounded-lg border border-border-subtle bg-bg-secondary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors",onClick:()=>{!b||i||d(b)},disabled:!b||i,children:[e.jsx(Nr,{size:15}),"Parent"]}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-secondary px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Current folder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:l,onChange:S=>f(S.target.value),onKeyDown:S=>{S.key!=="Enter"||!p||i||(S.preventDefault(),d(p))},placeholder:"Type a folder path",className:"min-w-0 flex-1 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2 text-sm text-text-primary"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-lg border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary disabled:opacity-40 transition-colors text-xs font-semibold shrink-0",onClick:()=>{!p||i||d(p)},disabled:!p||i,children:"Go"})]})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto bg-bg-primary/40",children:i?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"Loading folders…"}):o?e.jsx("div",{className:"px-5 py-5 text-sm text-status-error",children:o}):n.length===0?e.jsx("div",{className:"px-5 py-5 text-sm text-text-secondary",children:"No subfolders here."}):e.jsx("div",{className:"p-3",children:n.map(S=>e.jsxs("button",{type:"button",className:"w-full flex items-center gap-3 px-3.5 py-3 rounded-xl text-left border border-transparent hover:border-border-subtle hover:bg-bg-secondary transition-colors",onClick:()=>d(S.path),children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Qt,{size:17})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-medium text-text-primary truncate",children:S.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:S.path})]})]},S.path))})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:u,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>x(p||r),disabled:!p&&!r||i,children:c})]})]})})}function Wr({title:t,description:s,details:r,workspaceOptions:n,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:u=!1,onConfirm:d,onCancel:x}){const l=n==null?void 0:n.find(f=>f.key===i);return e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-confirm-title",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"launch-confirm-title",className:"m-0 text-base font-semibold text-text-primary",children:t}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:s})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:x,"aria-label":"Close launch confirmation",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n&&n.length>0&&o&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Workspace"}),e.jsx("select",{value:i||"",onChange:f=>o(f.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:u,children:n.map(f=>e.jsx("option",{value:f.key,children:f.label},f.key))}),(l==null?void 0:l.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:l.description})]}),r.map(f=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-3.5 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:f.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:f.value})]},`${f.label}:${f.value}`))]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:x,disabled:u,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:d,disabled:u,children:[e.jsx(Tr,{size:14}),u?"Launching…":c]})]})]})})}function Tn(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function Wt(t){const{machine:s,currentWorkspacePath:r,currentWorkspaceId:n,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const d of s.workspaces||[])o.push({key:`saved:${d.id}`,label:`${d.id===s.defaultWorkspaceId?"⭐ ":""}${Tn(d.path,d.label)}`,description:d.path,workspaceId:d.id,workspacePath:d.path});const c=(r==null?void 0:r.trim())||"",u=c?(s.workspaces||[]).find(d=>d.path===c):null;if(c&&!u&&o.push({key:`custom:${c}`,label:Tn(c),description:c,workspaceId:null,workspacePath:c}),n){const d=`saved:${n}`;if(o.some(x=>x.key===d))return{options:o,selectedKey:d}}return u?{options:o,selectedKey:`saved:${u.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function xl({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:r,cliProviders:n,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:u,isStandalone:d,section:x,showBottomNav:l,onBack:f,onSectionChange:b,onOpenConversation:p,onOpenRecent:S,onOpenMachineDetails:m,onMachineUpgrade:h,onLaunchDetectedIde:y,onAddWorkspace:g,onBrowseDirectory:v,onLaunchWorkspaceProvider:K}){var Fe,Qe,Ge,q;const N=(z,se,T)=>z?"ide":se>0?"cli":T>0?"acp":null,[j,k]=a.useState(!1),w=z=>z==="ide"?"IDE":z==="cli"?"CLI":"ACP",L=r.slice(0,4),M=s.slice(0,3),$=(((Fe=t.detectedIdes)==null?void 0:Fe.length)||0)>0,U=a.useMemo(()=>t.workspaces||[],[t]),D=t.defaultWorkspaceId||null,[_,W]=a.useState(D||((Qe=U[0])==null?void 0:Qe.id)||""),[E,H]=a.useState(""),[X,O]=a.useState(""),[P,R]=a.useState([]),[F,Y]=a.useState(!1),[me,_e]=a.useState(""),[G,le]=a.useState(!1),[J,he]=a.useState(N($,n.length,i.length)),te=a.useRef(null),[fe,ye]=a.useState(null),oe=a.useRef("__home__"),[de,ue]=a.useState("__home__"),[Ce,Q]=a.useState(!1),ie=a.useRef(null),ee=_==="__custom__"?E.trim():((Ge=U.find(z=>z.id===_))==null?void 0:Ge.path)||"",ge=_==="__custom__"&&!!ee&&u.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(u.message),C=_!=="__custom__"&&((q=U.find(z=>z.id===_))==null?void 0:q.path)||"",ne=a.useCallback(async z=>{Y(!0),_e("");try{const se=await v(z);O(se.path),H(se.path),R(se.directories)}catch(se){_e(se instanceof Error?se.message:"Could not load folder")}finally{Y(!1)}},[v]),ve=a.useCallback(()=>{var se,T;W("__custom__"),le(!0);const z=Xs(t.platform,[E.trim(),C,(se=U.find(A=>A.id===D))==null?void 0:se.path,(T=U[0])==null?void 0:T.path]);ne(z)},[E,D,ne,C,t.platform,U]),B=a.useCallback((z,se)=>{te.current=se,oe.current=z.selectedWorkspaceKey||"__home__",ue(z.selectedWorkspaceKey||"__home__"),ye(z)},[]),Z=a.useCallback(()=>{te.current&&(Q(!0),te.current().finally(()=>{te.current=null,Q(!1),ye(null)}))},[]);a.useEffect(()=>{var z;ie.current!==t.id&&(ie.current=t.id,W(D||((z=U[0])==null?void 0:z.id)||"__custom__"),H(""),O(""),R([]),_e(""),le(!1),he(N($,n.length,i.length)))},[i.length,n.length,D,$,t.id,U]),a.useEffect(()=>{var z;_!=="__custom__"&&(_&&U.some(se=>se.id===_)||W(D||((z=U[0])==null?void 0:z.id)||"__custom__"))},[D,_,U]),a.useEffect(()=>{J==="ide"&&$||J==="cli"&&n.length>0||J==="acp"&&i.length>0||he(N($,n.length,i.length))},[J,i.length,n.length,$]);const re=a.useMemo(()=>L.map(z=>({key:`recent-launch:${z.id}`,primary:z.label,secondary:`${w(z.kind)}${z.subtitle?` · ${z.subtitle}`:""}`,onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspacePath:z.workspace});B({title:`Launch ${z.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:w(z.kind)},...z.providerType?[{label:"Provider",value:z.providerType}]:[]]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),await S({...z,workspace:(A==null?void 0:A.workspacePath)??null})})}})),[D,S,B,L,U]),je=a.useMemo(()=>M.map(z=>({key:`recent-chat:${z.conversation.tabKey}`,primary:z.conversation.displayPrimary,secondary:`Chat${z.conversation.displaySecondary?` · ${z.conversation.displaySecondary}`:""}${z.timestamp?` · ${ra(z.timestamp)}`:""}`,unread:z.unread,onClick:()=>p(z.conversation)})),[p,M]),ke=j?re:re.slice(0,4),Pe=re.length>0,Be=je.length>0,We=d?"px-4 pt-4 pb-3":"px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`flex items-center justify-between gap-3 ${We} border-b border-border-subtle/70 bg-bg-primary backdrop-blur-md`,children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{className:"w-[34px] h-[34px] rounded-full border border-border-default bg-surface-primary/70 text-text-secondary shrink-0 inline-flex items-center justify-center hover:bg-surface-primary transition-colors",onClick:f,type:"button","aria-label":"Back",children:e.jsx(Nr,{size:18})}),e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[e.jsx("div",{className:"flex items-center gap-2 text-[17px] font-extrabold tracking-tight text-text-primary truncate",children:gt(t,{fallbackId:t.id})}),e.jsxs("div",{className:"min-w-0 flex items-center flex-wrap gap-1.5 text-xs text-text-secondary truncate",children:[t.platform||"machine",t.version?` · v${t.version}`:""]})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto py-2 flex flex-col gap-2 -webkit-overflow-scrolling-touch",children:[Be&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Current Chats"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:je.map(z=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${z.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:z.secondary})]},z.key))})]}),Pe&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Recent Launches"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:ke.map(z=>e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:z.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:z.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:z.secondary})]},z.key))}),re.length>4&&e.jsx("div",{className:"flex justify-center px-4 pt-2",children:e.jsx("button",{type:"button",className:"min-h-[34px] px-3.5 rounded-full border border-border-default/80 bg-surface-primary/90 text-text-secondary text-xs font-bold",onClick:()=>k(z=>!z),children:j?"Show fewer":`Show ${re.length-4} more`})})]}),($||n.length>0||i.length>0)&&e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Start"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:e.jsxs("div",{className:"flex flex-col gap-2.5 w-full p-3.5 rounded-2xl border border-border-default/80 bg-surface-primary/90",children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Workspace"}),e.jsx("div",{className:"text-xs leading-relaxed text-text-secondary",children:"Pick a saved workspace or browse folders before choosing IDE, CLI, or ACP."}),e.jsx("select",{value:_,onChange:z=>{const se=z.target.value;if(W(se),se==="__custom__"){ve();return}H("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:U.length>0?e.jsxs(e.Fragment,{children:[U.map(z=>e.jsxs("option",{value:z.id,children:[z.id===D?"⭐ ":"",Gs(z.path,z.label)||z.path]},z.id)),e.jsx("option",{value:"__custom__",children:"Select workspace…"})]}):e.jsx("option",{value:"__custom__",children:"Select workspace…"})}),_==="__custom__"&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx("div",{className:"rounded-2xl border border-border-default/80 bg-bg-primary/80 px-3.5 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-xl bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(Qt,{size:17})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.08em] text-text-muted mb-1",children:"Selected folder"}),e.jsx("div",{className:"text-[12px] leading-relaxed text-text-primary break-all",children:ee||X||"No folder selected yet."})]})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-secondary text-[12px] font-bold",onClick:ve,children:"Select workspace…"}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[36px] px-3 rounded-xl border border-accent-primary/30 bg-accent-primary/10 text-text-primary text-[12px] font-bold disabled:opacity-40",onClick:()=>{ee&&g(ee)},disabled:!ee||F,children:"Save as workspace"})]})]}),ee&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[$&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="ide"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("ide"),children:"IDE"}),n.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="cli"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${J==="acp"?"border-accent-primary/30 bg-accent-primary/10 text-text-primary":"border-border-default/80 bg-surface-primary/90 text-text-secondary"}`,type:"button",onClick:()=>he("acp"),children:"ACP"})]}),J&&e.jsxs("div",{className:"flex flex-col gap-2.5 px-4 pt-3",children:[e.jsx("div",{className:"text-xs font-bold text-text-secondary",children:J==="ide"?"Choose an IDE":J==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:J==="ide"?(t.detectedIdes||[]).slice(0,6).map(z=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ee});B({title:`Launch ${z.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:z.name}]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),y(z.type,{workspacePath:(A==null?void 0:A.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:z.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee||"Use selected workspace"})]},z.type)):(J==="cli"?n:i).map(z=>e.jsxs("button",{type:"button",className:"flex flex-col items-start gap-1 w-full text-left p-3 rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",onClick:()=>{const{options:se,selectedKey:T}=Wt({machine:{workspaces:U,defaultWorkspaceId:D},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:ee});B({title:`Launch ${z.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${J.toUpperCase()}`,workspaceOptions:se,selectedWorkspaceKey:T,details:[{label:"Mode",value:J.toUpperCase()},{label:"Provider",value:z.displayName}]},async()=>{const A=se.find(ae=>ae.key===oe.current);A!=null&&A.workspaceId?(W(A.workspaceId),H("")):A!=null&&A.workspacePath?(W("__custom__"),H(A.workspacePath)):(W(""),H("")),K(J,z.type,{workspaceId:(A==null?void 0:A.workspaceId)??null,workspacePath:(A==null?void 0:A.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[z.icon?`${z.icon} `:"",z.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:ee||"Use selected workspace"})]},z.type))})]}),u.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${u.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[u.message,ge&&e.jsx("div",{className:"mt-2",children:e.jsx("button",{type:"button",className:"inline-flex items-center justify-center min-h-[34px] px-4 rounded-lg bg-surface-primary text-text-primary font-bold text-xs",onClick:()=>g(ee,{createIfMissing:!0}),children:"Create folder"})})]})]}),e.jsxs("section",{className:"flex flex-col gap-0",children:[e.jsx("div",{className:"text-[11px] font-extrabold tracking-[0.08em] uppercase text-text-muted px-4 pb-2",children:"Inspect"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:[o&&e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-accent-primary/25 bg-accent-primary/5 text-text-primary",type:"button",onClick:h,children:[e.jsxs("span",{className:"text-sm font-bold text-text-primary",children:["Update to v",c]}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Restart this machine with the latest daemon"})]}),e.jsxs("button",{className:"flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border border-border-default/80 bg-surface-primary/90 text-text-primary",type:"button",onClick:m,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:"Machine details"}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:"Sessions, providers, system info, and logs"})]})]})]})]}),G&&e.jsx(Js,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:X,directories:P,busy:F,error:me,confirmLabel:"Use this folder",onClose:()=>le(!1),onNavigate:z=>{ne(z)},onConfirm:z=>{H(z),W("__custom__"),le(!1)}}),fe&&e.jsx(Wr,{title:fe.title,description:fe.description,details:fe.details,workspaceOptions:fe.workspaceOptions,selectedWorkspaceKey:de,onWorkspaceChange:z=>{oe.current=z,ue(z)},confirmLabel:fe.confirmLabel,busy:Ce,onConfirm:Z,onCancel:()=>{te.current=null,ye(null)}}),l&&e.jsx(Pa,{section:x,onSectionChange:b})]})}function hl(t){return Lr(t)}function An(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1],r=hl(s==null?void 0:s.content);return r||(t.title?t.title:t.displaySecondary||"No messages yet")}function bl(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Is(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function gl(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function _n(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function yl(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function vl(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function wl({conversations:t,hiddenConversations:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,userName:d,requestedActiveTabKey:x,onRequestedActiveTabConsumed:l,requestedMachineId:f,onRequestedMachineConsumed:b,requestedMobileSection:p,onRequestedMobileSectionConsumed:S,onOpenHistory:m,onOpenRemote:h,onStopCli:y,wsStatus:g,isConnected:v,onShowHiddenConversation:K,onShowAllHiddenConversations:N,onHideConversation:j}){const[k,w]=a.useState(()=>{var T;return((T=t[0])==null?void 0:T.tabKey)||null}),[L,M]=a.useState(()=>t[0]?"chat":"inbox"),[$,U]=a.useState("chats"),[D,_]=a.useState(null),[W,E]=a.useState("inbox"),[H,X]=a.useState("idle"),[O,P]=a.useState(""),[R,F]=a.useState(null),Y=a.useRef(null),me=ts(),_e="0.8.24",G=a.useMemo(()=>t.find(T=>T.tabKey===k)||t[0]||null,[t,k]),le=a.useMemo(()=>G?r.find(T=>T.id===G.ideId):void 0,[r,G]),J=a.useMemo(()=>!G||ze(G)||!Ye(G)?null:es(G),[G]),he=a.useMemo(()=>r.filter(T=>T.type==="adhdev-daemon"||T.daemonMode).sort(Ar),[r]),te=a.useMemo(()=>he.find(T=>T.id===D)||null,[he,D]),fe=a.useMemo(()=>bs(r),[r]),ye=Ys({sendDaemonCommand:i,activeConv:G||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),oe=a.useCallback(T=>{if(!T||!T.sessionId)return;const A=ds(T,fe),ae=Math.max(Date.now(),Dt(T),A.lastUpdated||0);Is("mark_read:start",{tabKey:T.tabKey,sessionId:T.sessionId,displayPrimary:T.displayPrimary,inboxBucket:A.inboxBucket,unread:A.unread,lastSeenAt:A.lastSeenAt,lastUpdated:A.lastUpdated,activityAt:Dt(T),readAt:ae}),i(T.daemonId||T.ideId,"mark_session_seen",{sessionId:T.sessionId,seenAt:ae}).then(ce=>{Is("mark_read:result",{tabKey:T.tabKey,sessionId:T.sessionId,result:ce})}).catch(ce=>{Is("mark_read:error",{tabKey:T.tabKey,sessionId:T.sessionId,error:ce instanceof Error?ce.message:String(ce)})})},[fe,i]);a.useEffect(()=>{var A;if(!G){M("inbox"),w(((A=t[0])==null?void 0:A.tabKey)||null),Y.current=null;return}if(L!=="chat"){Y.current=null;return}const T=`${G.tabKey}:${G.sessionId||""}`;Y.current!==T&&(Y.current=T,oe(G))},[t,oe,L,G]),a.useEffect(()=>{if(!x)return;const T=t.find(A=>A.tabKey===x);T&&(w(T.tabKey),M("chat"),l==null||l())},[t,l,x]),a.useEffect(()=>{if(!f)return;const T=he.find(A=>A.id===f);T&&(_(T.id),X("idle"),P(""),U("machines"),E("inbox"),M("machine"),b==null||b())},[he,b,f]),a.useEffect(()=>{p&&(U(p),M("inbox"),S==null||S())},[S,p]);const de=a.useMemo(()=>t.map(T=>{const A=L==="chat"&&(G==null?void 0:G.tabKey)===T.tabKey,ae=us(T,fe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:A}),ce=Dt(T),Ie=An(T);return{conversation:T,timestamp:ce,preview:Ie,unread:ae.unread,requiresAction:ae.requiresAction,isWorking:ae.isWorking,inboxBucket:ae.inboxBucket}}),[t,fe,L,G]);a.useEffect(()=>{const T=de.filter(A=>A.inboxBucket==="task_complete"||A.unread);T.length!==0&&Is("inbox_state",{screen:L,selectedTabKey:k,items:T.map(A=>{const ae=ds(A.conversation,fe);return{liveState:ae,tabKey:A.conversation.tabKey,sessionId:A.conversation.sessionId,displayPrimary:A.conversation.displayPrimary,serverBucket:ae.inboxBucket,computedBucket:A.inboxBucket,serverUnread:ae.unread,computedUnread:A.unread,lastSeenAt:ae.lastSeenAt,lastUpdated:ae.lastUpdated,activityAt:Dt(A.conversation)}})})},[de,fe,L,k]);const ue=a.useMemo(()=>de.filter(T=>T.requiresAction),[de]),Ce=a.useMemo(()=>de.filter(T=>T.unread&&!T.requiresAction),[de]),Q=a.useMemo(()=>de.filter(T=>!T.unread&&!T.requiresAction&&T.isWorking),[de]),ie=a.useMemo(()=>de.filter(T=>!T.unread&&!T.requiresAction&&!T.isWorking),[de]),ee=a.useMemo(()=>te?de.filter(T=>T.conversation.daemonId===te.id||T.conversation.ideId===te.id):[],[de,te]),ge=a.useMemo(()=>{if(!te)return[];const T=te.recentLaunches||[];return T.length>0?T.map(A=>({id:A.id,label:A.title||A.providerName||A.providerType,kind:A.kind,providerType:A.providerType,providerSessionId:A.providerSessionId,subtitle:A.currentModel||A.workspace||void 0,workspace:A.workspace,currentModel:A.currentModel})):r.filter(A=>!A.daemonMode&&A.daemonId===te.id).map(A=>{var ce,Ie,Oe,Ee,Te;const ae=ms(A)?"cli":Xt(A)?"acp":"ide";return{id:`${ae}:${A.type}:${A.workspace||""}`,label:((ce=A.activeChat)==null?void 0:ce.title)||(ms(A)?A.cliName||A.type:Xt(A)&&A.cliName||A.type),kind:ae,providerType:A.type,providerSessionId:A.providerSessionId,subtitle:Xt(A)?A.currentModel||A.workspace||void 0:A.workspace||void 0,workspace:A.workspace||void 0,currentModel:A.currentModel,timestamp:((Te=(Ee=(Oe=(Ie=A.activeChat)==null?void 0:Ie.messages)==null?void 0:Oe.at)==null?void 0:Ee.call(Oe,-1))==null?void 0:Te.timestamp)||0}}).sort((A,ae)=>ae.timestamp-A.timestamp).map(({timestamp:A,...ae})=>ae)},[r,te]),C=(te==null?void 0:te.version)||(te==null?void 0:te.daemonVersion)||null,ne=!!te&&!!C&&!0&&C!==_e,ve=a.useMemo(()=>(te==null?void 0:te.availableProviders)||[],[te]),B=a.useMemo(()=>ve.filter(T=>T.category==="cli").map(T=>({type:T.type,displayName:T.displayName||T.type,icon:T.icon})),[ve]),Z=a.useMemo(()=>ve.filter(T=>T.category==="acp").map(T=>({type:T.type,displayName:T.displayName||T.type,icon:T.icon})),[ve]),re=a.useMemo(()=>{const T=new Map;for(const A of de){const ae=A.conversation.daemonId||A.conversation.ideId,ce=T.get(ae);ce?ce.push(A):T.set(ae,[A])}return he.map(A=>{const ae=T.get(A.id)||[],ce=[...ae].sort((Ue,et)=>et.timestamp-Ue.timestamp)[0]||null,Ie=(ce==null?void 0:ce.conversation)||null,Oe=hr(A),Ee=ae.filter(Ue=>Ue.unread||Ue.requiresAction).length,Te=A.status==="online"?"Connected":A.status||"Unknown",He=[A.platform||"machine",Te].filter(Boolean);return{id:A.id,label:gt(A,{fallbackId:A.id}),subtitle:He.join(" · "),unread:Ee,total:ae.length,latestConversation:Ie,latestTimestamp:(ce==null?void 0:ce.timestamp)||0,fallbackActivityAt:Oe,preview:Ie?`${Ie.displayPrimary} · ${An(Ie)}`:"No active conversations yet. Open the machine, choose a workspace, then launch an IDE, CLI, or ACP session."}}).sort((A,ae)=>{const ce=A.latestTimestamp||A.fallbackActivityAt||0,Ie=ae.latestTimestamp||ae.fallbackActivityAt||0;return Ie!==ce?Ie-ce:A.label.localeCompare(ae.label)})},[de,he]),je=a.useCallback(T=>{w(T.tabKey),M("chat"),oe(T)},[oe]),ke=a.useCallback(T=>{const A=t.find(ae=>ae.ideId===T.ideId&&ae.streamSource==="native");A&&(w(A.tabKey),M("chat"),oe(A))},[t,oe]),Pe=a.useCallback(()=>{oe(G),M("inbox")},[oe,G]),Be=a.useCallback(T=>{_(T),X("idle"),P(""),F(null),U("machines"),E("inbox"),M("machine")},[]),We=a.useCallback(T=>{var ae;const A=T.daemonId||((ae=T.ideId)==null?void 0:ae.split(":")[0])||T.ideId;A&&(_(A),X("idle"),P(""),F(null),U("machines"),E("chat"),M("machine"))},[]),Fe=a.useCallback(()=>{F(null),M(W)},[W]),Qe=a.useCallback(async(T,A,ae)=>{var ce;try{X("loading"),P(`Launching ${A}…`);const Ie={ideType:A,enableCdp:!0};(ce=ae==null?void 0:ae.workspacePath)!=null&&ce.trim()&&(Ie.workspace=ae.workspacePath.trim()),await i(T,"launch_ide",Ie),X("done"),P(`${A} launch requested`)}catch(Ie){X("error"),P(Ie instanceof Error?Ie.message:"Launch IDE failed"),console.error("Launch IDE failed",Ie)}},[i]),Ge=a.useCallback(async(T,A,ae)=>{if(A.trim())try{X("loading"),P(ae!=null&&ae.createIfMissing?"Creating folder…":"Saving workspace…");const ce=await i(T,"workspace_add",{path:A.trim(),createIfMissing:(ae==null?void 0:ae.createIfMissing)===!0});if(ce!=null&&ce.success){X("done"),P(ae!=null&&ae.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}X("error"),P((ce==null?void 0:ce.error)||"Could not save workspace")}catch(ce){X("error"),P(ce instanceof Error?ce.message:"Could not save workspace")}},[i]),q=a.useCallback(async T=>{var A,ae,ce,Ie,Oe,Ee;try{X("loading"),P("Starting daemon upgrade…");const Te=await i(T,"daemon_upgrade",{});if((A=Te==null?void 0:Te.result)!=null&&A.alreadyLatest){X("done"),P(`Already on v${((ae=Te==null?void 0:Te.result)==null?void 0:ae.version)||"latest"}.`);return}if((ce=Te==null?void 0:Te.result)!=null&&ce.upgraded||(Ie=Te==null?void 0:Te.result)!=null&&Ie.success){X("done"),P(`Upgrade to v${((Oe=Te==null?void 0:Te.result)==null?void 0:Oe.version)||"latest"} started. Daemon is restarting…`);return}X("error"),P(((Ee=Te==null?void 0:Te.result)==null?void 0:Ee.error)||"Upgrade failed")}catch(Te){X("error"),P(Te instanceof Error?Te.message:"Upgrade failed")}},[i]),z=a.useCallback(async(T,A,ae,ce)=>{var Ee;const Ie=Date.now(),Oe={machineId:T,kind:A,providerType:ae,workspaceId:(ce==null?void 0:ce.workspaceId)||null,workspacePath:(ce==null?void 0:ce.workspacePath)||null,resumeSessionId:(ce==null?void 0:ce.resumeSessionId)||null,startedAt:Ie};try{X("loading"),P(`Launching ${ae}…`),F(Oe);const Te={cliType:ae};(Ee=ce==null?void 0:ce.workspacePath)!=null&&Ee.trim()?Te.dir=ce.workspacePath.trim():ce!=null&&ce.workspaceId&&(Te.workspaceId=ce.workspaceId),ce!=null&&ce.resumeSessionId&&(Te.resumeSessionId=ce.resumeSessionId);const He=await i(T,"launch_cli",Te),Ue=(He==null?void 0:He.result)||He,et=(Ue==null?void 0:Ue.sessionId)||(Ue==null?void 0:Ue.id);if(He!=null&&He.success&&et){F(null),X("done"),P(`${ae} launched`),me(`/dashboard?activeTab=${encodeURIComponent(et)}`);return}if(He!=null&&He.success){X("loading"),P(`${ae} launch requested — waiting for session…`);return}F(null),X("error"),P((He==null?void 0:He.error)||(Ue==null?void 0:Ue.error)||`Could not launch ${A.toUpperCase()} workspace`)}catch(Te){if(yl(Te)){X("loading"),P(`${ae} launch requested — waiting for session…`);return}F(null),X("error"),P(Te instanceof Error?Te.message:`Could not launch ${A.toUpperCase()} workspace`)}},[me,i]);a.useEffect(()=>{var ce;if(!R)return;const T=_n(R.workspacePath),A=r.find(Ie=>{var et,mt,pt,ut;if(!Ie||Ie.type==="adhdev-daemon"||Ie.daemonMode||gl(Ie.daemonId||Ie.id)!==R.machineId||(Ie.transport==="acp"?"acp":Ie.transport==="pty"?"cli":null)!==R.kind||String(Ie.agentType||Ie.ideType||Ie.type||"")!==R.providerType)return!1;const He=String(Ie.providerSessionId||"");if(R.resumeSessionId&&He)return He===R.resumeSessionId;if(T){const ft=_n(Ie.workspace||Ie.runtimeWorkspaceLabel);return ft?ft===T:!1}return Number(Ie.lastUpdated||Ie._lastUpdate||Ie.timestamp||((ut=(pt=(mt=(et=Ie.activeChat)==null?void 0:et.messages)==null?void 0:mt.at)==null?void 0:pt.call(mt,-1))==null?void 0:ut.timestamp)||0)>=R.startedAt-5e3});if(!A)return;const ae=typeof A.sessionId=="string"&&A.sessionId?A.sessionId:typeof A.instanceId=="string"&&A.instanceId?A.instanceId:(ce=t.find(Ie=>Ie.ideId===A.id))==null?void 0:ce.sessionId;ae&&(F(null),X("done"),P(`${R.providerType} launched`),me(`/dashboard?activeTab=${encodeURIComponent(ae)}`))},[t,r,me,R]),a.useEffect(()=>{if(!R)return;const T=window.setTimeout(()=>{F(A=>!A||A.startedAt!==R.startedAt?A:(X("error"),P("Launch response timed out. The session may already be running in Dashboard."),null))},45e3);return()=>window.clearTimeout(T)},[R]);const se=a.useCallback(async T=>{if(te){if(T.kind==="ide"&&T.providerType){await Qe(te.id,T.providerType,{workspacePath:T.workspace||null});return}if((T.kind==="cli"||T.kind==="acp")&&T.providerType){await z(te.id,T.kind,T.providerType,{workspacePath:T.workspace||null,resumeSessionId:T.providerSessionId||null});return}}},[Qe,z,te]);return e.jsx("div",{className:"dashboard-mobile-chat w-full min-w-0",children:L==="chat"&&G?e.jsx(dl,{selectedConversation:G,isAcp:ze(G),isStandalone:u,selectedIdeEntry:le,actionLogs:n,userName:d,isSendingChat:ye.isSendingChat,isFocusingAgent:ye.isFocusingAgent,handleModalButton:ye.handleModalButton,handleRelaunch:ye.handleRelaunch,onBack:Pe,onOpenNativeConversation:ke,onOpenMachine:We,onHideConversation:j,onOpenHistory:m,onOpenRemote:h,onStopCli:y,cliViewMode:J,onSetCliViewMode:async T=>{if(G&&J!==T)try{await i(G.daemonId||G.ideId,"set_cli_view_mode",{targetSessionId:G.sessionId,cliType:G.ideType||G.agentType,mode:T})}catch(A){vl(A)?console.warn("Skipped CLI view mode switch:",A instanceof Error?A.message:String(A)):console.error("Failed to switch CLI view mode:",A)}},handleSendChat:ye.handleSendChat,handleFocusAgent:ye.handleFocusAgent}):L==="machine"&&te?e.jsx(xl,{selectedMachineEntry:te,selectedMachineConversations:ee,selectedMachineRecentLaunches:ge,cliProviders:B,acpProviders:Z,selectedMachineNeedsUpgrade:ne,appVersion:_e,machineAction:{state:H,message:O},isStandalone:u,section:$,showBottomNav:W==="inbox",onBack:Fe,onSectionChange:T=>{U(T),M("inbox")},onOpenConversation:je,onOpenRecent:se,onOpenMachineDetails:()=>me(`/machines/${te.id}`),onMachineUpgrade:()=>q(te.id),onLaunchDetectedIde:(T,A)=>Qe(te.id,T,A),onAddWorkspace:(T,A)=>Ge(te.id,T,A),onBrowseDirectory:async T=>{const A=await i(te.id,"file_list_browse",{path:T});if(!(A!=null&&A.success))throw new Error((A==null?void 0:A.error)||"Could not browse folder");const ae=typeof(A==null?void 0:A.path)=="string"?A.path:T,ce=ae.includes("\\")?"\\":"/",Ie=(Ee,Te)=>/^[A-Za-z]:\\?$/.test(Ee)?`${Ee.replace(/\\?$/,"\\")}${Te}`:Ee==="/"||Ee==="\\"?`${ce}${Te}`:`${Ee.replace(/[\\/]+$/,"")}${ce}${Te}`,Oe=Array.isArray(A==null?void 0:A.files)?A.files.filter(Ee=>(Ee==null?void 0:Ee.type)==="directory"&&typeof(Ee==null?void 0:Ee.name)=="string").map(Ee=>({name:Ee.name,path:Ie(ae,Ee.name)})).sort((Ee,Te)=>Ee.name.localeCompare(Te.name)):[];return{path:ae,directories:Oe}},onLaunchWorkspaceProvider:(T,A,ae)=>z(te.id,T,A,ae)}):e.jsx(ml,{section:$,attentionItems:ue,unreadItems:Ce,workingItems:Q,completedItems:ie,hiddenConversations:s,machineCards:re,getAvatarText:bl,onOpenConversation:je,onShowConversation:K,onShowAllHidden:N,onOpenMachine:Be,onOpenSettings:()=>me("/settings"),onSectionChange:U,wsStatus:g,isConnected:v,isStandalone:u})})}function lr(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function jl({conversations:t,numGroups:s,onMoveTab:r,onReceiveTab:n,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[u,d]=a.useState(!1),[x,l]=a.useState(null),f=a.useCallback(()=>{c.current=0,d(!1),l(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const b=a.useCallback(h=>{h.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,d(!0))},[]),p=a.useCallback(h=>{if(!h.dataTransfer.types.includes("text/tab-key"))return;if(h.preventDefault(),!lr(s,r)){l("merge");return}const y=h.currentTarget.getBoundingClientRect(),g=h.clientX-y.left,v=y.width/3;g<v?l("split-left"):g>v*2?l("split-right"):l("merge")},[s,r]),S=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,d(!1),l(null))},[]),m=a.useCallback(h=>{c.current=0,d(!1);const y=h.dataTransfer.getData("text/tab-key"),g=y?t.some(K=>K.tabKey===y):!1,v=x;if(l(null),o(),!!y){if(h.preventDefault(),v==="split-left"&&lr(s,r)){r==null||r(y,"split-left");return}if(v==="split-right"&&lr(s,r)){r==null||r(y,"split-right");return}if(g){i(y);return}n==null||n(y)}},[t,x,s,r,n,i,o]);return{dragOver:u,dropAction:x,resetDragState:f,handleDragEnter:b,handleDragOver:p,handleDragLeave:S,handleDrop:m}}function kl(t,s){const r=new Set(s.map(o=>o.tabKey)),n=t.filter(o=>r.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...n,...i]}function Nl({conversations:t,initialActiveTabId:s,initialTabOrder:r,onActiveTabChange:n,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[u,d]=a.useState(r??[]),[x,l]=a.useState(null),f=a.useRef(null),b=a.useRef(null),p=a.useRef(n),S=a.useRef(i);a.useEffect(()=>{p.current=n},[n]),a.useEffect(()=>{S.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{d(k=>{const w=kl(k,t);return w.length===k.length&&w.every((L,M)=>L===k[M])?k:w})},[t]);const m=a.useMemo(()=>{const k=x??u;if(k.length===0)return t;const w=new Map(k.map((L,M)=>[L,M]));return[...t].sort((L,M)=>{const $=w.get(L.tabKey)??999,U=w.get(M.tabKey)??999;return $-U})},[t,x,u]);a.useEffect(()=>{var w,L;if(m.length===0){o!==null&&(c(null),(w=p.current)==null||w.call(p,null));return}if(o&&m.some(M=>M.tabKey===o))return;const k=m[0].tabKey;k!==o&&(c(k),(L=p.current)==null||L.call(p,k))},[m,o]);const h=a.useMemo(()=>m.find(k=>k.tabKey===o),[m,o]),y=a.useCallback(k=>{var w;c(k),(w=p.current)==null||w.call(p,k)},[]),g=a.useCallback((k,w,L)=>{d(M=>{var _;const $=M.filter(W=>W!==k),U=$.indexOf(w);if(U<0)return M;const D=L==="left"?U:U+1;return $.splice(D,0,k),(_=S.current)==null||_.call(S,$),$}),l(null)},[]),v=a.useCallback((k,w,L)=>{const $=(u.length>0?u:t.map(_=>_.tabKey)).filter(_=>_!==k),U=$.indexOf(w);if(U<0)return;const D=L==="left"?U:U+1;$.splice(D,0,k),f.current=$,l($)},[u,t]),K=a.useCallback(()=>{var w;const k=f.current;k&&(d(k),(w=S.current)==null||w.call(S,k))},[]),N=a.useCallback(()=>{f.current=null,l(null)},[]),j=a.useCallback(k=>{d(w=>{var M;const L=w.filter($=>$!==k);return L.push(k),(M=S.current)==null||M.call(S,L),L})},[]);return{activeTabId:o,activeConv:h,sortedConversations:m,previewOrderRef:f,draggingTabRef:b,selectTab:y,handleTabReorder:g,updatePreviewOrder:v,commitPreviewOrder:K,clearPreviewOrder:N,moveTabToEnd:j,setDraggingTabKey:k=>{b.current=k}}}function Sl({dropAction:t,canSplit:s}){return e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}function Or({conversationsCount:t,isSplitMode:s,isStandalone:r,hasRegisteredMachines:n=!1,detectedIdes:i,handleLaunchIde:o}){const c=!r&&!n,u=r?"Waiting for your daemon":n?"No conversations yet":"Connect your first machine",d=r?"Start the ADHDev daemon to connect this dashboard. Once it is online, you can open an IDE or launch CLI and ACP sessions.":n?"Your machines are connected. Open a machine, choose a workspace, then launch an IDE, CLI, or ACP session.":"Install the ADHDev daemon and link your dashboard to start.";return t===0&&!s&&i&&o?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:u}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:d}),c&&e.jsx(Ma,{}),r&&i.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Detected IDEs"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:i.map(x=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>o(x.type),children:[e.jsx(Zn,{size:14,className:"opacity-70"})," Open ",x.name]},x.type))})]}),c&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}const La="adhdev-tab-shortcuts";function Cl(){try{return JSON.parse(localStorage.getItem(La)||"{}")}catch{return{}}}function Ra({enabled:t=!0,sortedTabKeys:s,onFocus:r,onSelectTab:n}){const i=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,c]=a.useState(()=>Cl()),[u,d]=a.useState(null),x=a.useCallback(f=>{const b=[];return f.metaKey&&b.push(i?"⌘":"Meta"),f.ctrlKey&&b.push("Ctrl"),f.altKey&&b.push(i?"⌥":"Alt"),f.shiftKey&&b.push(i?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(f.key)?null:(b.push(f.key.length===1?f.key.toUpperCase():f.key),b.join("+"))},[i]),l=a.useCallback(f=>{c(f);try{localStorage.setItem(La,JSON.stringify(f))}catch{}},[]);return a.useEffect(()=>{if(!t||!u)return;const f=b=>{if(b.preventDefault(),b.stopPropagation(),b.key==="Escape"){d(null);return}const p=x(b);if(!p)return;const S={...o};for(const[m,h]of Object.entries(S))h===p&&delete S[m];S[u]=p,l(S),d(null)};return window.addEventListener("keydown",f,!0),()=>window.removeEventListener("keydown",f,!0)},[t,u,o,l,x]),a.useEffect(()=>{if(!t)return;const f=b=>{if(!(!b.ctrlKey&&!b.metaKey&&!b.altKey)){for(const[p,S]of Object.entries(o))if(s.includes(p)&&x(b)===S){b.preventDefault(),r(),n(p);return}}};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,o,s,r,n,x]),{isMac:i,tabShortcuts:o,shortcutListening:u,setShortcutListening:d,saveShortcuts:l}}const Il=a.memo(function({conv:s,isActive:r,isDraggedTab:n,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:u,onFocus:d,onSelectTab:x,onConversationActivated:l,onPreviewReorder:f,onReorderTab:b,onCommitPreviewOrder:p,onClearPreviewOrder:S,onDragStateReset:m,onDragTabKeyChange:h,onReceiveTab:y,onOpenContextMenu:g,longPressTimer:v,isGroupActive:K}){const N=qs(s),j=N.isGenerating?"agent-tab-generating":N.isWaiting?"agent-tab-waiting":"",k=N.isReconnecting,w=a.useCallback(H=>{u.current=s.tabKey,h(s.tabKey),H.dataTransfer.setData("text/tab-key",s.tabKey),H.dataTransfer.effectAllowed="move"},[s.tabKey,u,h]),L=a.useCallback(()=>{u.current=null,h(null),p(),S(),m()},[u,h,p,S,m]),M=a.useCallback(H=>{const X=u.current;if(!(!X||X===s.tabKey)&&H.dataTransfer.types.includes("text/tab-key")){H.preventDefault(),H.stopPropagation();const O=H.currentTarget.getBoundingClientRect(),P=H.clientX<O.left+O.width/2?"left":"right";f(X,s.tabKey,P)}},[s.tabKey,u,f]),$=a.useCallback(H=>{H.preventDefault(),H.stopPropagation();const X=H.dataTransfer.getData("text/tab-key");if(X&&X!==s.tabKey){const O=H.currentTarget.getBoundingClientRect(),P=H.clientX<O.left+O.width/2?"left":"right";c.includes(X)?b(X,s.tabKey,P):y&&y(X)}S()},[s.tabKey,c,b,y,S]),U=a.useCallback(H=>{H.stopPropagation(),d(),x(s.tabKey),l(s)},[s,l,d,x]),D=a.useCallback(H=>{H.preventDefault(),g(H.clientX,H.clientY,s.tabKey)},[s.tabKey,g]),_=a.useCallback(H=>{const X=H.touches[0];v.current=setTimeout(()=>{g(X.clientX,X.clientY,s.tabKey)},600)},[s.tabKey,v,g]),W=a.useCallback(()=>{v.current&&clearTimeout(v.current)},[v]),E=["adhdev-dockview-tab",j,r&&"is-active",K&&"is-group-active",k&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:E,draggable:!0,onDragStart:w,onDragEnd:L,onDragOver:M,onDrop:$,onClick:U,onContextMenu:D,onTouchStart:_,onTouchEnd:W,onTouchMove:W,style:{cursor:"pointer",opacity:n?.4:void 0},children:[i&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status",children:N.isGenerating?e.jsx("div",{className:"tab-spinner"}):N.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):N.isConnecting?e.jsx("div",{className:"tab-connecting-spinner"}):s.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("span",{className:"adhdev-dockview-tab-primary",title:s.displayPrimary,children:s.displayPrimary}),e.jsx("span",{className:"adhdev-dockview-tab-meta",children:k?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):N.isConnecting?e.jsxs("span",{className:"adhdev-dockview-tab-connecting",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[s.displaySecondary,s.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",s.machineName]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.isTaskCompleteUnread===s.isTaskCompleteUnread&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys&&t.isGroupActive===s.isGroupActive);function Tl({conversations:t,activeTabId:s,groupIndex:r,unreadTabKeys:n,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:p,onReceiveTab:S,onHideTab:m,isGroupActive:h,allowTabShortcuts:y=!0}){const[g,v]=a.useState(null),K=a.useRef(null),N=a.useRef(null),j=a.useMemo(()=>t.map(D=>D.tabKey),[t]);hs("PaneGroupTabBar",{groupIndex:r,activeTabId:s,tabCount:t.length,ctxMenuTab:(g==null?void 0:g.tabKey)||null});const{isMac:k,tabShortcuts:w,shortcutListening:L,setShortcutListening:M,saveShortcuts:$}=Ra({enabled:y,sortedTabKeys:t.map(D=>D.tabKey),onFocus:o,onSelectTab:c});a.useEffect(()=>{if(!g)return;const D=_=>{const W=document.querySelector("[data-pane-context-menu]");W&&W.contains(_.target)||v(null)};return window.addEventListener("mousedown",D,!0),()=>window.removeEventListener("mousedown",D,!0)},[g]),a.useEffect(()=>{const D=N.current;if(!D)return;const _=W=>{Math.abs(W.deltaY)>Math.abs(W.deltaX)&&(W.preventDefault(),D.scrollLeft+=W.deltaY)};return D.addEventListener("wheel",_,{passive:!1}),()=>D.removeEventListener("wheel",_)},[]);const U=a.useCallback((D,_,W)=>{v({x:D,y:_,tabKey:W})},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-end shrink-0 gap-0",style:{background:"var(--surface-secondary)",paddingInline:8,paddingTop:6,paddingBottom:0},children:e.jsxs("div",{ref:N,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(D=>e.jsx(Il,{conv:D,isActive:s===D.tabKey,isDraggedTab:i.current===D.tabKey,isTaskCompleteUnread:n.has(D.tabKey),shortcut:y?w[D.tabKey]:void 0,conversationKeys:j,draggingTabRef:i,onFocus:o,onSelectTab:c,onConversationActivated:u,onPreviewReorder:d,onReorderTab:x,onCommitPreviewOrder:l,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:p,onReceiveTab:S,onOpenContextMenu:U,longPressTimer:K,isGroupActive:h},D.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),g&&e.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:g.x,top:g.y},children:[y&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:D=>{D.stopPropagation(),M(g.tabKey),v(null)},children:["⌨ ",w[g.tabKey]?`Change shortcut (${w[g.tabKey]})`:"Set shortcut"]}),w[g.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const D={...w};delete D[g.tabKey],$(D),v(null)},children:"✕ Remove shortcut"})]}),m&&e.jsxs(e.Fragment,{children:[y&&e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{m(g.tabKey),v(null)},children:"🚫 Hide from Dashboard"})]})]}),y&&L&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>M(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:D=>D.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",k?"⌘+1":"Ctrl+1",", ",k?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function Al({conversations:t,ides:s,clearedTabs:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,hasRegisteredMachines:d,userName:x,groupIndex:l,onFocus:f,isSplitMode:b,numGroups:p,onMoveTab:S,onReceiveTab:m,style:h,detectedIdes:y,handleLaunchIde:g,onActiveTabChange:v,initialActiveTabId:K,initialTabOrder:N,onTabOrderChange:j,onHideTab:k,isFocused:w,allowTabShortcuts:L=!0}){const{sendCommand:M}=Pt(),$=a.useRef(null),{activeTabId:U,activeConv:D,sortedConversations:_,draggingTabRef:W,selectTab:E,handleTabReorder:H,updatePreviewOrder:X,commitPreviewOrder:O,clearPreviewOrder:P,moveTabToEnd:R,setDraggingTabKey:F}=Nl({conversations:t,initialActiveTabId:K,initialTabOrder:N,onActiveTabChange:v,onTabOrderChange:j}),Y=Ys({sendDaemonCommand:i,activeConv:D,setLocalUserMessages:o,setActionLogs:c,isStandalone:u}),{dragOver:me,dropAction:_e,resetDragState:G,handleDragEnter:le,handleDragOver:J,handleDragLeave:he,handleDrop:te}=jl({conversations:t,numGroups:p,onMoveTab:S,onReceiveTab:m,onOwnTabDrop:R,onClearPreviewOrder:P}),fe=D&&!ze(D)&&es(D)==="terminal",ye=a.useMemo(()=>D?s.find(Q=>Q.id===D.ideId):void 0,[s,D]),oe=a.useMemo(()=>D?n.filter(Q=>Q.ideId===D.tabKey):[],[n,D]),de=a.useMemo(()=>bs(s),[s]),ue=a.useMemo(()=>new Set(_.filter(Q=>mo(Q,de,{isOpenConversation:Q.tabKey===U})).map(Q=>Q.tabKey)),[U,de,_]);hs("PaneGroup",{groupIndex:l,conversationCount:t.length,activeTabId:U,dragOver:me});const Ce=a.useCallback(Q=>{Q.streamSource==="agent-stream"&&Q.agentType&&M(Q.ideId,"focus_session",{agentType:Q.agentType,...Q.sessionId&&{targetSessionId:Q.sessionId}}).catch(()=>{})},[M]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:f,style:{...h,outline:me?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Tl,{conversations:_,activeTabId:U,groupIndex:l,numGroups:p,unreadTabKeys:ue,draggingTabRef:W,onFocus:f,onSelectTab:E,onConversationActivated:Ce,onPreviewReorder:X,onReorderTab:H,onCommitPreviewOrder:O,onClearPreviewOrder:P,onDragStateReset:G,onDragTabKeyChange:F,onMoveTab:S,onReceiveTab:m,onHideTab:k,isGroupActive:w??!1,allowTabShortcuts:L}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:le,onDragOver:J,onDragLeave:he,onDrop:te,children:[me&&e.jsx(Sl,{dropAction:_e,canSplit:!!(p<4&&S)}),D?e.jsx(Br,{activeConv:D,clearToken:r[D.tabKey]||0,isCliTerminal:!!fe,ideEntry:ye,terminalRef:$,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,handleSendChat:Y.handleSendChat,isSendingChat:Y.isSendingChat,handleFocusAgent:Y.handleFocusAgent,isFocusingAgent:Y.isFocusingAgent,actionLogs:oe,userName:x,isInputActive:!b||!!w}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Or,{conversationsCount:t.length,isSplitMode:b,isStandalone:u,hasRegisteredMachines:d,detectedIdes:y,handleLaunchIde:g})})]})]})}function _l({containerRef:t,isSplitMode:s,numGroups:r,groupSizes:n,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,hasRegisteredMachines:b,userName:p,focusedGroup:S,setFocusedGroup:m,moveTabToGroup:h,splitTabRelative:y,closeGroup:g,handleResizeStart:v,detectedIdes:K,handleLaunchIde:N,groupActiveTabIds:j,setGroupActiveTabIds:k,groupTabOrders:w,setGroupTabOrders:L,toggleHiddenTab:M,allowTabShortcuts:$=!0}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((U,D)=>{const _=s&&n.length===r?`${n[D]}%`:void 0;return e.jsxs(Ze.Fragment,{children:[s&&D>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:W=>v(D-1,W),onDoubleClick:()=>g(D),title:"Drag to resize · Double-click to merge",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),e.jsx(Al,{style:s?{flexBasis:_??`${100/r}%`,flexGrow:_?0:1,flexShrink:_?0:1}:void 0,conversations:U,clearedTabs:o,ides:c,actionLogs:u,sendDaemonCommand:d,setLocalUserMessages:x,setActionLogs:l,isStandalone:f,hasRegisteredMachines:b,userName:p,groupIndex:D,isFocused:s&&S===D,onFocus:()=>m(D),isSplitMode:s,numGroups:r,onMoveTab:(W,E)=>{E==="left"&&D>0?h(W,D-1):E==="right"&&D<r-1?h(W,D+1):E==="split-left"&&r<4?y(W,D,"left"):E==="split-right"&&r<4&&y(W,D,"right")},onReceiveTab:W=>h(W,D),detectedIdes:D===0?K:void 0,handleLaunchIde:D===0?N:void 0,onActiveTabChange:W=>k(E=>(E[D]??null)===(W??null)?E:{...E,[D]:W}),initialActiveTabId:j[D],initialTabOrder:w[D],onTabOrderChange:W=>L(E=>{const H=E[D]||[];return H.length===W.length&&H.every((X,O)=>X===W[O])?E:{...E,[D]:W}}),onHideTab:M,allowTabShortcuts:$})]},D)})})}function Ea({doId:t,ideId:s,ideType:r,connState:n,viewMode:i,instanceId:o}){const[c,u]=a.useState(null),[d,x]=a.useState(null),l=a.useMemo(()=>{if(!s)return r;const b=s.split(":");return b.length>=3&&b[1]==="ide"?b.slice(2).join(":"):r},[s,r]);a.useEffect(()=>t?Je.onScreenshot("ide-page",(p,S)=>{if(p!==t)return;const m=new FileReader;m.onload=()=>u(m.result),m.readAsDataURL(S)}):void 0,[t]),a.useEffect(()=>{n!=="connected"&&u(null)},[n]),a.useEffect(()=>{var p;return t?((p=Je.onStatus)==null?void 0:p.call(Je,(S,m)=>{S===t&&m!=null&&m.screenshotUsage&&x(m.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,l]),a.useEffect(()=>{const b=t?Je.get(t):null;if(!(!b||n!=="connected"))return i!=="chat"&&l?b.startScreenshots(l):b.stopScreenshots(l),()=>{b.stopScreenshots(l)}},[i,n,l,t]);const f=a.useCallback(async(b,p)=>{const S=t?Je.get(t):null;return!S||n!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):S.sendInput(b,p,o||l)},[t,n,o,l]);return{connScreenshot:c,screenshotUsage:d,handleRemoteAction:f}}const $a=a.createContext(null);function Zs(){const t=a.useContext($a);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Rs(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function Ml(t){return`remote:${t}`}function fs(t){return t.startsWith("remote:")}function xs(t,s){return t.find(r=>r.ideId===s&&r.streamSource==="native")??t.find(r=>r.ideId===s)??null}function Pl(t){const[,s]=a.useState(0);a.useEffect(()=>{const r=()=>s(i=>i+1),n=[t.api.onDidActiveGroupChange(r),t.api.onDidTitleChange(r),t.api.onDidGroupChange(r),t.containerApi.onDidActivePanelChange(r)];return()=>{for(const i of n)i.dispose()}},[t.api,t.containerApi])}function Ll(t,s,r){var u;const n=[s];let i;for(const d of n){let x;for(const l of d){const f=t.addPanel({id:l.tabKey,component:"conversation",title:Rs(l),params:{kind:"conversation",tabKey:l.tabKey},...x?{position:{referencePanel:x,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});x||(x=f.id)}i=x??i}const o=r??((u=s[0])==null?void 0:u.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Mn(t,s){const r=new Set(s.map(n=>n.tabKey));for(const n of[...t.panels])fs(n.id)||r.has(n.id)||t.removePanel(n);for(const n of s){const i=t.getPanel(n.tabKey);if(i){i.update({params:{tabKey:n.tabKey}}),i.title!==Rs(n)&&i.api.setTitle(Rs(n));continue}t.addPanel({id:n.tabKey,component:"conversation",title:Rs(n),params:{kind:"conversation",tabKey:n.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Pn(t,s,r){var d,x;const n=r?Ml(r):null;for(const l of[...t.panels])fs(l.id)&&(!n||l.id!==n)&&t.removePanel(l);if(!r||!n)return;const i=xs(s,r);if(!i&&t.totalPanels===0)return;const o=t.getPanel(n),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const u=(i==null?void 0:i.tabKey)??((d=t.activePanel)==null?void 0:d.id)??((x=t.panels.find(l=>!fs(l.id)))==null?void 0:x.id);t.addPanel({id:n,component:"remote",title:c,params:{kind:"remote",ideId:r},...u?{position:{referencePanel:u,direction:"right"},inactive:!0}:{}})}function Rl({params:t,api:s}){var f;const r=Zs(),n=a.useRef(null),[i,o]=a.useState(s.isActive),c=r.conversationsByTabKey.get(t.tabKey),u=Ys({sendDaemonCommand:r.sendDaemonCommand,activeConv:c,setLocalUserMessages:r.setLocalUserMessages,setActionLogs:r.setActionLogs,isStandalone:r.isStandalone});a.useEffect(()=>{o(s.isActive);const b=[s.onDidActiveChange(p=>o(p.isActive)),s.onDidActiveGroupChange(p=>{if(!s.isActive&&!p.isActive){o(!1);return}o(s.isActive)})];return()=>{for(const p of b)p.dispose()}},[s]);const d=a.useMemo(()=>c?r.ides.find(b=>b.id===c.ideId):void 0,[r.ides,c]),x=a.useMemo(()=>c?r.actionLogs.filter(b=>b.ideId===c.tabKey):[],[r.actionLogs,c]);if(!c)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(Or,{conversationsCount:0,isSplitMode:!1,isStandalone:r.isStandalone,hasRegisteredMachines:r.hasRegisteredMachines,detectedIdes:r.detectedIdes,handleLaunchIde:r.handleLaunchIde})});const l=!ze(c)&&es(c)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Br,{activeConv:c,clearToken:r.clearedTabs[c.tabKey]||0,isCliTerminal:l,ideEntry:d,terminalRef:n,handleModalButton:u.handleModalButton,handleRelaunch:u.handleRelaunch,handleSendChat:u.handleSendChat,isSendingChat:u.isSendingChat,handleFocusAgent:u.handleFocusAgent,isFocusingAgent:u.isFocusingAgent,actionLogs:x,userName:r.userName,scrollToBottomRequestNonce:((f=r.scrollToBottomRequest)==null?void 0:f.tabKey)===c.tabKey?r.scrollToBottomRequest.nonce:void 0,isInputActive:i})})}function El({params:t}){var d;const s=Zs(),r=a.useMemo(()=>xs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),n=a.useMemo(()=>s.ides.find(x=>x.id===t.ideId),[s.ides,t.ideId]),i=(r==null?void 0:r.daemonId)||((d=r==null?void 0:r.ideId)==null?void 0:d.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:u}=Ea({doId:i,ideId:t.ideId,ideType:(r==null?void 0:r.ideType)||(n==null?void 0:n.type),connState:(r==null?void 0:r.connectionState)||"new",viewMode:"remote",instanceId:n==null?void 0:n.instanceId});return r?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(ta,{addLog:()=>{},connState:r.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:r.transport,onAction:u})}):e.jsx("div",{className:"h-full min-h-0 min-w-0 flex items-center justify-center text-sm text-text-muted",children:"Remote view unavailable"})}function $l(){const t=Zs();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Or,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,hasRegisteredMachines:t.hasRegisteredMachines,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Dl(t){var p,S;Pl(t);const s=Zs(),r=a.useCallback(m=>{"button"in m&&m.button!==0||t.api.setActive()},[t.api]);if(t.params.kind==="remote"){const m=xs([...s.conversationsByTabKey.values()],t.params.ideId),h=((p=t.api.group.activePanel)==null?void 0:p.id)===t.api.id,y=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${h?" is-active":""}${y?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(m==null?void 0:m.tabKey)||"",onMouseDown:r,onTouchStart:r,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"◫"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||"Remote"}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:m!=null&&m.machineName?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Live remote view"}),e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsx("span",{className:"adhdev-dockview-tab-machine",children:m.machineName})]}):e.jsx("span",{children:"Live remote view"})})]})]})}const n=s.conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty","data-tab-key":t.params.tabKey||"",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const i=((S=t.api.group.activePanel)==null?void 0:S.id)===t.api.id,o=t.api.isGroupActive,c=us(n,s.liveSessionInboxState,{isOpenConversation:i}),u=c.isReconnecting,d=c.isConnecting,x=c.isGenerating,l=c.isWaiting,f=c.unread,b=s.tabShortcuts[n.tabKey];return e.jsxs("div",{className:`adhdev-dockview-tab${i?" is-active":""}${o?" is-group-active":""}${u?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,onMouseDown:r,onTouchStart:r,onContextMenu:m=>{m.preventDefault(),r(m),s.openTabContextMenu({x:m.clientX,y:m.clientY,tabKey:n.tabKey})},children:[f&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:x?e.jsx("div",{className:"tab-spinner"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):u?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):d?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:u?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):d?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]}),b&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:b,children:b})]})}function Bl({visibleConversations:t,clearedTabs:s,ides:r,actionLogs:n,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:u,hasRegisteredMachines:d,initialDataLoaded:x,userName:l,detectedIdes:f,handleLaunchIde:b,toggleHiddenTab:p,registerActionHandlers:S,onActiveTabChange:m,requestedActiveTabKey:h,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:g,scrollToBottomRequest:v}){const{theme:K}=ga(),{sendCommand:N}=Pt(),j=a.useRef(null),k=a.useRef(null),w=a.useRef(!1),L=a.useRef(!1),M=a.useRef(!1),$=a.useRef(null),[U,D]=a.useState(null),[_,W]=a.useState(!1),[E,H]=a.useState(!1),X=a.useRef(null),O=a.useMemo(()=>Ia(typeof window<"u"?window.innerWidth:1280),[]),P=a.useMemo(()=>new Map(t.map(B=>[B.tabKey,B])),[t]),R=a.useMemo(()=>bs(r),[r]),F=a.useCallback(()=>{var B;(B=j.current)==null||B.focus()},[]),Y=a.useCallback(B=>{const Z=j.current;if(!Z)return;const re=Z.getPanel(B);re&&(re.group.model.openPanel(re),re.api.setActive())},[]),me=a.useCallback(B=>{const Z=j.current,re=Z==null?void 0:Z.activePanel,je=(Z==null?void 0:Z.activeGroup)||(re==null?void 0:re.group);if(!Z||!re||!je)return;const ke=je.panels||[];if(ke.length<=1)return;const Pe=ke.findIndex(Fe=>Fe.id===re.id);if(Pe<0)return;const Be=(Pe+B+ke.length)%ke.length,We=ke[Be];We&&(We.group.model.openPanel(We),We.api.setActive())},[]),_e=a.useCallback(B=>{var z;const Z=j.current,re=(Z==null?void 0:Z.activeGroup)||((z=Z==null?void 0:Z.activePanel)==null?void 0:z.group);if(!Z||!re)return;const je=Z.groups||[],ke=je.find(se=>se.id===re.id);if(!ke)return;const Pe=ke.element.getBoundingClientRect(),Be=Pe.left+Pe.width/2,We=Pe.top+Pe.height/2,Fe=(se,T,A,ae)=>Math.max(0,Math.min(T,ae)-Math.max(se,A)),Qe=se=>{const T=se.element.getBoundingClientRect(),A=T.left+T.width/2,ae=T.top+T.height/2;let ce=0,Ie=0,Oe=0,Ee=!1;if(B==="left"?(Ee=A<Be,ce=Math.max(0,Pe.left-T.right),Ie=Math.abs(ae-We),Oe=Fe(Pe.top,Pe.bottom,T.top,T.bottom)):B==="right"?(Ee=A>Be,ce=Math.max(0,T.left-Pe.right),Ie=Math.abs(ae-We),Oe=Fe(Pe.top,Pe.bottom,T.top,T.bottom)):B==="above"?(Ee=ae<We,ce=Math.max(0,Pe.top-T.bottom),Ie=Math.abs(A-Be),Oe=Fe(Pe.left,Pe.right,T.left,T.right)):(Ee=ae>We,ce=Math.max(0,T.top-Pe.bottom),Ie=Math.abs(A-Be),Oe=Fe(Pe.left,Pe.right,T.left,T.right)),!Ee)return Number.POSITIVE_INFINITY;const Te=Oe>0?0:120;return ce*3+Ie+Te};let Ge=null,q=Number.POSITIVE_INFINITY;for(const se of je){if(se.id===ke.id)continue;const T=Qe(se);Number.isFinite(T)&&(T>=q||(q=T,Ge=se))}return Ge||void 0},[]),G=a.useCallback(B=>{const Z=_e(B);if(!Z)return;const re=Z.activePanel||Z.panels[0];re&&(Z.model.openPanel(re),re.api.setActive())},[_e]),le=a.useCallback((B,Z)=>{const re=j.current,je=re==null?void 0:re.activePanel,ke=(re==null?void 0:re.activeGroup)||(je==null?void 0:je.group);if(!re||!je||!ke)return;let Pe=_e(B);!Pe&&(Z!=null&&Z.createGroupIfMissing)&&(Pe=re.addGroup({referenceGroup:ke,direction:B})),Pe&&(je.api.moveTo({group:Pe,position:"center"}),je.group.model.openPanel(je),je.api.setActive())},[_e]),{isMac:J,tabShortcuts:he,shortcutListening:te,setShortcutListening:fe,saveShortcuts:ye}=Ra({sortedTabKeys:t.map(B=>B.tabKey),onFocus:F,onSelectTab:Y}),oe=a.useCallback(()=>{var re;const B=j.current;if(!B)return;const Z=B.activePanel;if(Z){if(fs(Z.id)){const je=((re=Z.params)==null?void 0:re.ideId)||Z.id.slice(7),ke=xs(t,je);ke!=null&&ke.tabKey&&fe(ke.tabKey);return}P.has(Z.id)&&fe(Z.id)}},[P,fe,t]);a.useEffect(()=>(S==null||S({setShortcutForActiveTab:oe,activatePreviousTabInGroup:()=>me(-1),activateNextTabInGroup:()=>me(1),splitActiveTabRight:()=>le("right",{createGroupIfMissing:!0}),splitActiveTabDown:()=>le("below",{createGroupIfMissing:!0}),focusLeftPane:()=>G("left"),focusRightPane:()=>G("right"),focusUpPane:()=>G("above"),focusDownPane:()=>G("below"),moveActiveTabToLeftPane:()=>le("left"),moveActiveTabToRightPane:()=>le("right"),moveActiveTabToUpPane:()=>le("above"),moveActiveTabToDownPane:()=>le("below")}),()=>S==null?void 0:S(null)),[me,G,le,S,oe]),a.useEffect(()=>{if(!U)return;const B=Z=>{const re=document.querySelector("[data-dockview-tab-context-menu]");re&&re.contains(Z.target)||D(null)};return window.addEventListener("mousedown",B,!0),()=>window.removeEventListener("mousedown",B,!0)},[U]);const de=a.useMemo(()=>({actionLogs:n,clearedTabs:s,conversationsByTabKey:P,detectedIdes:f,handleLaunchIde:b,ides:r,isStandalone:u,hasRegisteredMachines:d,liveSessionInboxState:R,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:p,userName:l,scrollToBottomRequest:v,tabShortcuts:he,openTabContextMenu:({x:B,y:Z,tabKey:re})=>D({x:B,y:Z,tabKey:re})}),[n,s,P,f,b,r,u,d,R,i,c,o,p,l,v,he]),ue=a.useCallback(B=>{if(!B)return!1;const Z=j.current;if(!Z)return!1;const re=Z.getPanel(B);return re?(re.group.model.openPanel(re),re.api.setActive(),g==null||g(),!0):!1},[g]),Ce=a.useCallback(()=>{if(M.current)return!1;const B=ue($.current);return B&&(M.current=!0),B},[ue]),Q=a.useCallback(()=>{var Z;const B=j.current;B&&Qc(O,{activeTabId:((Z=B.activePanel)==null?void 0:Z.id)??null,layout:B.toJSON()})},[O]),ie=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const re of Z)re.setAttribute("data-adhdev-force-hidden","true")},[]),ee=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const re of Z)re.removeAttribute("data-adhdev-force-hidden")},[]),ge=a.useCallback(()=>{const B=k.current;if(!B)return;const Z=B.querySelectorAll(".dv-drop-target-container");for(const ke of Z)ke.remove();const re=B.querySelectorAll(".dv-drop-target-dropzone");for(const ke of re)ke.remove();const je=B.querySelectorAll(".dv-drop-target");for(const ke of je)ke.classList.remove("dv-drop-target")},[]),C=a.useCallback(()=>{W(!1),H(!1),ee(),ie(),ge(),!(typeof window>"u")&&(X.current!=null&&window.clearTimeout(X.current),window.requestAnimationFrame(()=>{ie(),ge()}),X.current=window.setTimeout(()=>{ie(),ge(),X.current=null},80))},[ee,ie,ge]),ne=a.useCallback(B=>{var re;j.current=B.api;const Z=Zc(O);$.current=(Z==null?void 0:Z.activeTabId)??null,Z!=null&&Z.layout&&B.api.fromJSON(Z.layout,{reuseExistingPanels:!1}),L.current=!!(Z!=null&&Z.layout)&&!x&&t.length===0,L.current||(Mn(B.api,t),Pn(B.api,t,y)),B.api.totalPanels===0&&t.length>0?Ll(B.api,t,h):!L.current&&!ue(h)&&Ce(),w.current=!0,B.api.onDidActivePanelChange(je=>{var Pe;if($.current=(je==null?void 0:je.id)??null,M.current=!0,je&&fs(je.id)){const Be=((Pe=je.params)==null?void 0:Pe.ideId)||je.id.slice(7),We=xs(t,Be);m((We==null?void 0:We.tabKey)??null),Q();return}if(m((je==null?void 0:je.id)??null),Q(),!je)return;const ke=P.get(je.id);(ke==null?void 0:ke.streamSource)==="agent-stream"&&ke.agentType&&N(ke.ideId,"focus_session",{agentType:ke.agentType,...ke.sessionId&&{targetSessionId:ke.sessionId}}).catch(()=>{})}),B.api.onDidLayoutChange(()=>{Q()}),B.api.onWillDragPanel(()=>{W(!0),H(!1),ie()}),B.api.onWillDragGroup(()=>{W(!0),H(!1),ie()}),B.api.onWillShowOverlay(()=>{ee(),H(!0)}),B.api.onDidMovePanel(C),B.api.onDidDrop(C),m(((re=B.api.activePanel)==null?void 0:re.id)??null)},[ue,C,ee,P,x,O,ie,ge,m,Q,h,y,N,t]);a.useEffect(()=>{const B=j.current;if(!B||!w.current||L.current&&!x||(L.current&&(L.current=!1),Mn(B,t),Pn(B,t,y),h&&ue(h)))return;!B.activePanel&&B.panels[0]&&(B.panels[0].group.model.openPanel(B.panels[0]),B.panels[0].api.setActive()),!!(B.activePanel&&B.getPanel(B.activePanel.id))||Ce()},[ue,Ce,x,h,y,t]),a.useEffect(()=>{w.current&&ue(h)},[ue,h]),a.useEffect(()=>{if(!_||typeof window>"u")return;const B=()=>C();return window.addEventListener("pointerup",B),window.addEventListener("mouseup",B),window.addEventListener("dragend",B),()=>{window.removeEventListener("pointerup",B),window.removeEventListener("mouseup",B),window.removeEventListener("dragend",B)}},[C,_]),a.useEffect(()=>()=>{typeof window>"u"||X.current!=null&&window.clearTimeout(X.current)},[]),a.useEffect(()=>{const B=Z=>{const re=Z.target;if(!re)return;const je=re.querySelector("[data-tab-key]")||re.closest("[data-tab-key]");if(je){const ke=je.getAttribute("data-tab-key");ke&&Z.dataTransfer&&Z.dataTransfer.setData("text/tab-key",ke)}};return window.addEventListener("dragstart",B),()=>window.removeEventListener("dragstart",B)},[]);const ve=K==="light"?gi:yi;return e.jsxs($a.Provider,{value:de,children:[e.jsx("div",{ref:k,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(bi,{className:`h-full min-h-0 min-w-0 adhdev-dockview${_?" is-dragging-dockview":""}${E?" is-showing-dockview-overlay":""}`,components:{conversation:Rl,remote:El},defaultTabComponent:Dl,watermarkComponent:$l,onReady:ne,singleTabMode:"default",tabAnimation:"smooth",theme:ve})}),U&&e.jsxs("div",{"data-dockview-tab-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:U.x,top:U.y},children:[e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors",onClick:B=>{B.stopPropagation(),fe(U.tabKey),D(null)},children:["⌨ ",he[U.tabKey]?`Change shortcut (${he[U.tabKey]})`:"Set shortcut"]}),he[U.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{const B={...he};delete B[U.tabKey],ye(B),D(null)},children:"✕ Remove shortcut"})]}),te&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>fe(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:B=>B.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",J?"⌘+1":"Ctrl+1",", ",J?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const Da="adhdev-recent-launch-args-v1",Kl=8;function Wl(t){return String(t||"").trim().replace(/\s+/g," ")}function Ba(t,s){return`${t.trim()}::${s.trim()}`}function Ka(){if(typeof window>"u")return{byKey:{}};try{const t=JSON.parse(window.localStorage.getItem(Da)||"{}");return{byKey:typeof t.byKey=="object"&&t.byKey?t.byKey:{}}}catch{return{byKey:{}}}}function Ol(t){if(!(typeof window>"u"))try{window.localStorage.setItem(Da,JSON.stringify(t))}catch{}}function Wa(t,s){var o;const r=String(t||"").trim(),n=String(s||"").trim();return!r||!n?[]:((o=Ka().byKey[Ba(r,n)])==null?void 0:o.items)||[]}function Oa(t,s,r){var l;const n=String(t||"").trim(),i=String(s||"").trim(),o=Wl(r);if(!n||!i||!o)return;const c=Ka(),u=Ba(n,i),d=((l=c.byKey[u])==null?void 0:l.items)||[],x=[o,...d.filter(f=>f!==o)].slice(0,Kl);c.byKey[u]={items:x},Ol(c)}function dr(t){var n;if(!t)return null;const s=(((n=t.detectedIdes)==null?void 0:n.length)||0)>0,r=t.availableProviders||[];return s?"ide":r.some(i=>i.category==="cli")?"cli":r.some(i=>i.category==="acp")?"acp":null}function Ts(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function Ul({machines:t,onClose:s,onBrowseDirectory:r,onSaveWorkspace:n,onLaunchIde:i,onLaunchProvider:o,onListSavedSessions:c}){var Qe,Ge;const u=a.useMemo(()=>[...t].sort(Ar),[t]),[d,x]=a.useState(((Qe=u[0])==null?void 0:Qe.id)||""),l=a.useMemo(()=>u.find(q=>q.id===d)||u[0],[d,u]),f=a.useMemo(()=>(l==null?void 0:l.workspaces)||[],[l]),b=(l==null?void 0:l.defaultWorkspaceId)||null,[p,S]=a.useState(""),[m,h]=a.useState(""),[y,g]=a.useState(dr(u[0])),[v,K]=a.useState(""),[N,j]=a.useState(""),[k,w]=a.useState([]),[L,M]=a.useState(""),[$,U]=a.useState([]),[D,_]=a.useState(!1),[W,E]=a.useState(""),[H,X]=a.useState(!1),[O,P]=a.useState(null),[R,F]=a.useState(!1),[Y,me]=a.useState(""),[_e,G]=a.useState(!1),[le,J]=a.useState(""),[he,te]=a.useState([]),[fe,ye]=a.useState(!1),[oe,de]=a.useState(""),[ue,Ce]=a.useState(!1),Q=a.useRef(null),ie=a.useRef(0);a.useEffect(()=>{var q;!d&&((q=u[0])!=null&&q.id)&&x(u[0].id)},[d,u]);const ee=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="cli"),[l]),ge=a.useMemo(()=>((l==null?void 0:l.availableProviders)||[]).filter(q=>q.category==="acp"),[l]),C=a.useMemo(()=>((l==null?void 0:l.detectedIdes)||[]).map(q=>({id:q.type,label:q.name||q.type,meta:q.running?"Detected locally":"Available to open"})),[l]),ne=a.useMemo(()=>y==="cli"?ee.map(q=>({id:q.type,label:q.displayName||q.type,meta:"CLI provider"})):y==="acp"?ge.map(q=>({id:q.type,label:q.displayName||q.type,meta:"ACP provider"})):C,[ge,y,ee,C]);a.useEffect(()=>{var z;if(!l)return;if(Q.current!==l.id){Q.current=l.id,S(b||((z=f[0])==null?void 0:z.id)||"__home__"),h(""),g(dr(l)),K(""),j(""),M(""),U([]),E(""),me("");return}S(se=>{var T;return se==="__custom__"||se==="__home__"||f.some(A=>A.id===se)?se:b||((T=f[0])==null?void 0:T.id)||"__home__"}),g(se=>se==="ide"&&C.length>0||se==="cli"&&ee.length>0||se==="acp"&&ge.length>0?se:dr(l))},[ge.length,ee.length,b,C.length,l,f]),a.useEffect(()=>{var q;y&&(ne.some(z=>z.id===v)||K(((q=ne[0])==null?void 0:q.id)||""))},[y,ne,v]);const ve=a.useCallback(async(q,z)=>{const se=ie.current+1;return ie.current=se,_(!0),E(""),c(q,z).then(T=>{ie.current===se&&U(T)}).catch(T=>{ie.current===se&&(U([]),E(T instanceof Error?T.message:"Could not load saved sessions"))}).finally(()=>{ie.current===se&&_(!1)})},[c]),B=a.useCallback((q,z)=>{w(Wa(q,z))},[]);a.useEffect(()=>{if(M(""),!l||!v||y==="ide"?w([]):B(l.id,v),y!=="cli"){U([]),E(""),_(!1);return}if(!l||!v){U([]),E(""),_(!1);return}ve(l.id,v)},[y,B,ve,l,v]),a.useEffect(()=>{if(!L)return;const q=$.find(z=>z.providerSessionId===L);q!=null&&q.canResume||M("")},[$,L]);const Z=p==="__custom__"?m.trim():p==="__home__"?"":((Ge=f.find(q=>q.id===p))==null?void 0:Ge.path)||"",re=a.useCallback(q=>{const z=String(q.workspace||"").trim();if(!z)return;const se=f.find(T=>Ts(T.path)===Ts(z));if(se){S(se.id),h("");return}S("__custom__"),h(z)},[f]),je=a.useCallback(q=>{const z=String(q.workspace||"").trim();if(!z)return{workspaceId:null,workspacePath:null};const se=f.find(T=>Ts(T.path)===Ts(z));return se?{workspaceId:se.id,workspacePath:null}:{workspaceId:null,workspacePath:z}},[f]),ke=a.useMemo(()=>{var z;if(y!=="cli"||!l||!v)return null;const q=((z=ee.find(se=>se.type===v))==null?void 0:z.displayName)||v;return{ideId:l.id,daemonId:l.id,providerSessionId:L||void 0,transport:"pty",mode:"chat",agentName:q,agentType:v,status:"idle",title:q,messages:[],ideType:v,workspaceName:Z,displayPrimary:q,displaySecondary:"CLI",streamSource:"native",tabKey:`dashboard:new-session:resume-history:${l.id}:${v}`,machineName:gt(l,{fallbackId:l.id})}},[y,ee,Z,l,L,v]),Pe=a.useCallback(()=>{var z,se;if(!l)return;S("__custom__"),G(!0),de("");const q=Xs(l.platform,[m.trim(),Z,(z=f.find(T=>T.id===b))==null?void 0:z.path,(se=f[0])==null?void 0:se.path]);ye(!0),r(l.id,q).then(T=>{J(T.path),h(T.path),te(T.directories)}).catch(T=>{de(T instanceof Error?T.message:"Could not load folder")}).finally(()=>ye(!1))},[m,b,r,Z,l,f]),Be=a.useCallback(q=>{l&&(ye(!0),de(""),r(l.id,q).then(z=>{J(z.path),h(z.path),te(z.directories)}).catch(z=>{de(z instanceof Error?z.message:"Could not load folder")}).finally(()=>ye(!1)))},[r,l]),We=a.useCallback(async()=>{if(!l||!Z)return;Ce(!0),me("");const q=await n(l.id,Z);if(Ce(!1),!q.ok){me(q.error||"Could not save workspace");return}me("Workspace saved. It will appear in the list once the machine state refreshes.")},[n,Z,l]),Fe=a.useCallback(async()=>{if(!l||!y||!v)return;F(!0),me("");const q=N.trim()?N.trim().split(/\s+/).filter(Boolean):[],z=y==="ide"?await i(l.id,v,{workspacePath:Z||null}):await o(l.id,y,v,{workspaceId:p!=="__home__"&&p!=="__custom__"?p:null,workspacePath:p==="__custom__"&&Z||null,resumeSessionId:y==="cli"&&L?L:null,cliArgs:q});if(F(!1),!z.ok){me(z.error||"Could not start session");return}y!=="ide"&&N.trim()&&(Oa(l.id,v,N),B(l.id,v)),s()},[y,N,B,s,i,o,Z,l,L,v,p]);return l?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"dashboard-new-title",children:e.jsxs("div",{className:"w-full max-w-3xl max-h-[min(88vh,860px)] rounded-2xl border border-border-subtle bg-bg-secondary shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 px-5 py-4 border-b border-border-subtle",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{id:"dashboard-new-title",className:"m-0 text-base font-semibold text-text-primary",children:"New session"}),e.jsx("p",{className:"m-0 mt-1 text-xs leading-relaxed text-text-muted",children:"Pick a machine, choose a workspace, then start IDE, CLI, or ACP without leaving the dashboard."})]}),e.jsx("button",{type:"button",className:"inline-flex items-center justify-center w-8 h-8 rounded-full border border-border-subtle bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-surface-primary transition-colors shrink-0",onClick:s,"aria-label":"Close new session dialog",children:e.jsx(Ut,{size:16})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Machine"}),e.jsx("select",{value:l.id,onChange:q=>x(q.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R,children:u.map(q=>e.jsx("option",{value:q.id,children:gt(q,{fallbackId:q.id})},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Workspace"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Saved workspace is preferred. Home and custom folders are still available."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Pe,disabled:R,children:"Browse…"})]}),e.jsxs("select",{value:p,onChange:q=>{const z=q.target.value;S(z),z==="__custom__"?Pe():me("")},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R,children:[e.jsx("option",{value:"__home__",children:"Home directory"}),f.map(q=>e.jsxs("option",{value:q.id,children:[q.id===b?"⭐ ":"",Gs(q.path,q.label)||q.path]},q.id)),e.jsx("option",{value:"__custom__",children:"Custom folder…"})]}),e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:p==="__home__"?"Launch without a workspace.":Z||"Select a workspace folder."}),p==="__custom__"&&Z&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Pe,disabled:R,children:[e.jsx(Qt,{size:14}),"Select folder"]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:We,disabled:R||ue,children:ue?"Saving…":"Save workspace"})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:"Category"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"ide",label:"IDE",enabled:C.length>0},{id:"cli",label:"CLI",enabled:ee.length>0},{id:"acp",label:"ACP",enabled:ge.length>0}].map(q=>e.jsx("button",{type:"button",className:`btn btn-sm ${y===q.id?"btn-primary":"btn-secondary"}`,onClick:()=>g(q.id),disabled:!q.enabled||R,children:q.label},q.id))})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-2",children:y==="ide"?"Choose IDE":y==="cli"?"Choose CLI provider":"Choose ACP provider"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[ne.map(q=>e.jsxs("button",{type:"button",className:`w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${v===q.id?"border-accent bg-accent/10":"border-border-subtle bg-bg-secondary/40 hover:bg-bg-secondary/70"}`,onClick:()=>K(q.id),disabled:R,children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:q.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:q.meta})]},q.id)),ne.length===0&&e.jsx("div",{className:"text-sm text-text-muted",children:"Nothing available for this category on the selected machine."})]})]}),y!=="ide"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted mb-1",children:"Startup arguments"}),e.jsx("input",{type:"text",value:N,onChange:q=>j(q.target.value),placeholder:"Optional flags...",className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R}),k.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:k.map(q=>e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>j(q),disabled:R,title:q,children:q},q))})]}),y==="cli"&&e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-primary px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-text-muted",children:"Resume from history"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"Pick a saved CLI session, then launch with optional args."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:R||!l||!v||D,onClick:()=>{!l||!v||ve(l.id,v)},children:D?"Loading…":"Refresh"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",disabled:R||!l||!v,onClick:()=>{!l||!v||(X(!0),ve(l.id,v))},children:"Open History"})]}),e.jsx("div",{className:"mt-2",children:e.jsxs("select",{value:L,onChange:q=>{const z=q.target.value;if(M(z),!z)return;const se=$.find(T=>T.providerSessionId===z);!se||!se.canResume||re(se)},className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:R||D,children:[e.jsx("option",{value:"",children:"Start a new CLI session"}),$.map(q=>e.jsxs("option",{value:q.providerSessionId,disabled:!q.canResume,children:[q.title||q.providerSessionId,q.canResume?"":" (workspace missing)"]},q.providerSessionId))]})}),L&&(()=>{const q=$.find(z=>z.providerSessionId===L);return q?e.jsxs("div",{className:"mt-2 text-[11px] text-text-muted leading-relaxed",children:[e.jsx("div",{className:"font-mono break-all",children:q.providerSessionId}),e.jsxs("div",{className:"mt-1",children:[q.workspace||"Workspace unknown",q.currentModel?` · ${q.currentModel}`:""]})]}):null})(),W&&e.jsx("div",{className:"mt-2 text-[11px] text-status-error",children:W}),!D&&!W&&$.length===0&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted",children:"No saved sessions found for this provider yet."})]}),Y&&e.jsx("div",{className:`rounded-xl border px-4 py-3 text-sm ${Y.includes("saved")||Y.includes("requested")?"border-accent/25 bg-accent/10 text-text-primary":"border-status-error/25 bg-status-error/10 text-status-error"}`,children:Y})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-4 border-t border-border-subtle bg-bg-secondary",children:[e.jsx("button",{type:"button",className:"machine-btn text-xs",onClick:s,disabled:R,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold inline-flex items-center gap-2",onClick:Fe,disabled:R||!y||!v||p==="__custom__"&&!Z,children:[e.jsx(Tr,{size:14}),R?"Starting…":"Start session"]})]})]})}),_e&&e.jsx(Js,{title:"Select workspace",description:"Pick the folder that should be used for this new session.",currentPath:le,directories:he,busy:fe,error:oe,onClose:()=>G(!1),onNavigate:Be,onConfirm:q=>{h(q),J(q),S("__custom__"),G(!1)}}),H&&ke&&e.jsx(Pr,{activeConv:ke,ides:[],isCreatingChat:!1,isRefreshingHistory:D,savedSessions:$,isSavedSessionsLoading:D,isResumingSavedSessionId:O,onClose:()=>X(!1),onNewChat:()=>{M(""),X(!1)},onSwitchSession:()=>{},onRefreshHistory:()=>{!l||!v||ve(l.id,v)},onResumeSavedSession:q=>{if(!l||!v||O||!q.canResume)return;const z=je(q);M(q.providerSessionId),re(q),P(q.providerSessionId),X(!1),F(!0),me(""),o(l.id,"cli",v,{workspaceId:z.workspaceId,workspacePath:z.workspacePath,resumeSessionId:q.providerSessionId}).then(se=>{if(!se.ok){me(se.error||"Could not resume session");return}s()}).finally(()=>{F(!1),P(se=>se===q.providerSessionId?null:se)})}})]}):null}const Ua="adhdev-dashboard-action-shortcuts",zl=1200,Hl={toggleHiddenTabs:"G H",setActiveTabShortcut:"G S",selectPreviousGroupTab:"G K",selectNextGroupTab:"G J",splitActiveTabRight:"⌘+⌥+\\",focusLeftPane:"⌘+⌥+←",focusRightPane:"⌘+⌥+→",moveActiveTabToLeftPane:"⌘+⌥+⇧+←",moveActiveTabToRightPane:"⌘+⌥+⇧+→",triggerPrimaryApprovalAction:"⌥+A",triggerSecondaryApprovalAction:"⌥+D",toggleCliView:"T"};function Fl(){return typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent)}function Xe(t,s){switch(t){case"openShortcutHelp":return"?";case"hideCurrentTab":return s?"⌥+X":"Ctrl+Alt+X";case"toggleHiddenTabs":return s?"⌥+H":"Ctrl+Alt+H";case"openHistoryForActiveTab":return s?"⌥+Y":"Ctrl+Alt+Y";case"openRemoteForActiveTab":return s?"⌥+R":"Ctrl+Alt+R";case"splitActiveTabRight":return s?"⌘+⌥+=":"Ctrl+Alt+\\";case"splitActiveTabDown":return s?"⌘+⌥+-":"Ctrl+Alt+-";case"focusLeftPane":return s?"⌘+⌥+[":"Ctrl+Alt+←";case"focusRightPane":return s?"⌘+⌥+]":"Ctrl+Alt+→";case"focusUpPane":return s?"⌘+⌥+U":"Ctrl+Alt+↑";case"focusDownPane":return s?"⌘+⌥+J":"Ctrl+Alt+↓";case"moveActiveTabToLeftPane":return s?"⌘+⌥+,":"Ctrl+Alt+Shift+←";case"moveActiveTabToRightPane":return s?"⌘+⌥+.":"Ctrl+Alt+Shift+→";case"moveActiveTabToUpPane":return s?"⌘+⌥+I":"Ctrl+Alt+Shift+↑";case"moveActiveTabToDownPane":return s?"⌘+⌥+K":"Ctrl+Alt+Shift+↓";case"triggerPrimaryApprovalAction":return s?"⌥+J":"Ctrl+Alt+J";case"triggerSecondaryApprovalAction":return s?"⌥+K":"Ctrl+Alt+K";case"triggerTertiaryApprovalAction":return s?"⌥+L":"Ctrl+Alt+L";case"setActiveTabShortcut":return s?"⌥+S":"Ctrl+Alt+S";case"selectPreviousGroupTab":return s?"⌥+[":"Ctrl+Alt+[";case"selectNextGroupTab":return s?"⌥+]":"Ctrl+Alt+]";case"toggleCliView":return s?"⌥+T":"Ctrl+Alt+T"}}function za(t){return[{id:"openShortcutHelp",label:"Open shortcuts",description:"Show the keyboard shortcuts panel.",defaultShortcut:Xe("openShortcutHelp",t)},{id:"hideCurrentTab",label:"Hide current tab",description:"Hide the currently active tab into Hidden tabs.",defaultShortcut:Xe("hideCurrentTab",t)},{id:"toggleHiddenTabs",label:"Toggle hidden tabs",description:"Open or close the hidden tabs popover.",defaultShortcut:Xe("toggleHiddenTabs",t)},{id:"openHistoryForActiveTab",label:"Open history",description:"Open history for the active session.",defaultShortcut:Xe("openHistoryForActiveTab",t)},{id:"openRemoteForActiveTab",label:"Open remote",description:"Open remote control for the active session when available.",defaultShortcut:Xe("openRemoteForActiveTab",t)},{id:"splitActiveTabRight",label:"Move active tab to new right pane",description:"Create a pane to the right and move the active tab into it.",defaultShortcut:Xe("splitActiveTabRight",t)},{id:"splitActiveTabDown",label:"Move active tab to new lower pane",description:"Create a pane below and move the active tab into it.",defaultShortcut:Xe("splitActiveTabDown",t)},{id:"focusLeftPane",label:"Focus left pane",description:"Move focus to the pane on the left.",defaultShortcut:Xe("focusLeftPane",t)},{id:"focusRightPane",label:"Focus right pane",description:"Move focus to the pane on the right.",defaultShortcut:Xe("focusRightPane",t)},{id:"focusUpPane",label:"Focus upper pane",description:"Move focus to the pane above.",defaultShortcut:Xe("focusUpPane",t)},{id:"focusDownPane",label:"Focus lower pane",description:"Move focus to the pane below.",defaultShortcut:Xe("focusDownPane",t)},{id:"moveActiveTabToLeftPane",label:"Move active tab left",description:"Move the active tab into the pane on the left.",defaultShortcut:Xe("moveActiveTabToLeftPane",t)},{id:"moveActiveTabToRightPane",label:"Move active tab right",description:"Move the active tab into the pane on the right.",defaultShortcut:Xe("moveActiveTabToRightPane",t)},{id:"moveActiveTabToUpPane",label:"Move active tab up",description:"Move the active tab into the pane above.",defaultShortcut:Xe("moveActiveTabToUpPane",t)},{id:"moveActiveTabToDownPane",label:"Move active tab down",description:"Move the active tab into the pane below.",defaultShortcut:Xe("moveActiveTabToDownPane",t)},{id:"triggerPrimaryApprovalAction",label:"Approval action 1",description:"Press the first approval/action button for the active session.",defaultShortcut:Xe("triggerPrimaryApprovalAction",t)},{id:"triggerSecondaryApprovalAction",label:"Approval action 2",description:"Press the second approval/action button for the active session.",defaultShortcut:Xe("triggerSecondaryApprovalAction",t)},{id:"triggerTertiaryApprovalAction",label:"Approval action 3",description:"Press the third approval/action button for the active session.",defaultShortcut:Xe("triggerTertiaryApprovalAction",t)},{id:"setActiveTabShortcut",label:"Set active tab shortcut",description:"Start recording a direct shortcut for the active tab.",defaultShortcut:Xe("setActiveTabShortcut",t)},{id:"selectPreviousGroupTab",label:"Previous tab in group",description:"Move to the previous tab inside the active Dockview group.",defaultShortcut:Xe("selectPreviousGroupTab",t)},{id:"selectNextGroupTab",label:"Next tab in group",description:"Move to the next tab inside the active Dockview group.",defaultShortcut:Xe("selectNextGroupTab",t)},{id:"toggleCliView",label:"Toggle CLI view",description:"Toggle the active CLI session between chat and terminal view.",defaultShortcut:Xe("toggleCliView",t)}]}function Vl(t){if(!(t instanceof HTMLElement))return!1;if(t.isContentEditable)return!0;const s=t.tagName;return s==="INPUT"||s==="TEXTAREA"||s==="SELECT"}function Ln(t){const s=Object.fromEntries(za(t).map(r=>[r.id,r.defaultShortcut]));try{const r=JSON.parse(localStorage.getItem(Ua)||"{}"),n={...s,...r};for(const[i,o]of Object.entries(Hl))n[i]===o&&(n[i]=s[i]);return n}catch{return s}}function ql(t){return t===" "?"Space":t==="Escape"?"Esc":t==="ArrowLeft"?"←":t==="ArrowRight"?"→":t==="ArrowUp"?"↑":t==="ArrowDown"?"↓":t.length===1?t.toUpperCase():t}function Gl({enabled:t=!0,onTrigger:s}){const r=Fl(),[n,i]=a.useState(()=>Ln(r)),[o,c]=a.useState(null),[u,d]=a.useState([]),x=a.useRef({parts:[],timer:null}),l=a.useCallback(m=>{const h=[];return m.metaKey&&h.push(r?"⌘":"Meta"),m.ctrlKey&&h.push("Ctrl"),m.altKey&&h.push(r?"⌥":"Alt"),m.shiftKey&&m.key.length!==1&&h.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(m.key)?null:(h.push(ql(m.key)),h.join("+"))},[r]),f=a.useCallback(m=>{i(m);try{localStorage.setItem(Ua,JSON.stringify(m))}catch{}},[]);a.useEffect(()=>{const m=Ln(r),h=Object.entries(n),y=Object.entries(m);h.length===y.length&&h.every(([g,v])=>m[g]===v)||f(m)},[n,r,f]);const b=a.useCallback(()=>{typeof window<"u"&&x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current={parts:[],timer:null}},[]),p=a.useCallback(()=>{typeof window>"u"||(x.current.timer!=null&&window.clearTimeout(x.current.timer),x.current.timer=window.setTimeout(()=>{x.current={parts:[],timer:null}},zl))},[]);a.useEffect(()=>{if(!o)return;const m=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){c(null),d([]);return}const y=l(h);if(!y)return;const v=!(h.metaKey||h.ctrlKey||h.altKey)&&/^[A-Z0-9]$/.test(y);if(u.length===0&&v){d([y]);return}const N=[...u,y].slice(0,2).join(" "),j={...n};for(const[k,w]of Object.entries(j))w===N&&delete j[k];j[o]=N,f(j),c(null),d([])};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[n,l,f,o,u]),a.useEffect(()=>{if(!t||o)return;const m=h=>{if(h.defaultPrevented)return;const y=l(h);if(!y)return;const g=h.metaKey||h.ctrlKey||h.altKey;if(Vl(h.target)&&!g)return;const v=x.current.parts,K=g?[y]:[...v.slice(-1),y].slice(-2),N=K.join(" "),j=K[K.length-1],k=Object.entries(n).filter(([,U])=>!!U),w=k.find(([,U])=>U===N);if(w){h.preventDefault(),b(),s(w[0]);return}if(k.some(([,U])=>U.startsWith(`${N} `))){h.preventDefault(),x.current.parts=K,p();return}const M=k.find(([,U])=>U===j);if(M){h.preventDefault(),b(),s(M[0]);return}if(k.some(([,U])=>U.startsWith(`${j} `))){h.preventDefault(),x.current.parts=[j],p();return}b()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[n,p,t,l,s,b,o]),a.useEffect(()=>()=>b(),[b]);const S=a.useMemo(()=>za(r),[r]);return{isMac:r,actionDefinitions:S,actionShortcuts:n,shortcutListening:o,shortcutListeningDraft:u,setShortcutListening:c,setShortcutListeningDraft:d,saveShortcuts:f}}function Yl(t){switch(t.id){case"triggerPrimaryApprovalAction":case"triggerSecondaryApprovalAction":case"triggerTertiaryApprovalAction":return"approvals";case"splitActiveTabRight":case"splitActiveTabDown":case"focusLeftPane":case"focusRightPane":case"focusUpPane":case"focusDownPane":case"moveActiveTabToLeftPane":case"moveActiveTabToRightPane":case"moveActiveTabToUpPane":case"moveActiveTabToDownPane":return"panes";default:return"workspace"}}function Xl(t){return t instanceof Error?t.message:String(t||"")}function Jl(t){const s=Xl(t).toLowerCase();return s.includes("button not found")||s.includes("not in approval state")||s.includes("command failed")}function Zl({showMobileChatMode:t,isMobile:s,activeConv:r,chatIdes:n,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:u,onStopCli:d,activeCliViewMode:x,onSetActiveCliViewMode:l,mobileChatConversations:f,hiddenConversations:b,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,initialDataLoaded:v,userName:K,requestedMobileTabKey:N,onRequestedMobileTabConsumed:j,requestedMachineId:k,onRequestedMachineConsumed:w,requestedMobileSection:L,onRequestedMobileSectionConsumed:M,containerRef:$,isSplitMode:U,numGroups:D,groupSizes:_,groupedConvs:W,clearedTabs:E,focusedGroup:H,setFocusedGroup:X,moveTabToGroup:O,splitTabRelative:P,closeGroup:R,handleResizeStart:F,detectedIdes:Y,handleLaunchIde:me,groupActiveTabIds:_e,setGroupActiveTabIds:G,groupTabOrders:le,setGroupTabOrders:J,toggleHiddenTab:he,visibleConversations:te,requestedDesktopTabKey:fe,onRequestedDesktopTabConsumed:ye,onDesktopActiveTabChange:oe,onHideConversation:de,onShowHiddenConversation:ue,onShowAllHiddenConversations:Ce,scrollToBottomRequest:Q,machineEntries:ie,onBrowseMachineDirectory:ee,onSaveMachineWorkspace:ge,onLaunchMachineIde:C,onLaunchMachineProvider:ne,onListMachineSavedSessions:ve}){const B=Ze.useRef(null),[Z,re]=Ze.useState(!1),[je,ke]=Ze.useState(!1),[Pe,Be]=Ze.useState(!1),[We,Fe]=Ze.useState(!1),[Qe,Ge]=Ze.useState(!1),[q,z]=Ze.useState("quickstart"),[se,T]=Ze.useState("workspace"),A=!t&&!s,ae=Ze.useCallback(xe=>{re(xe),xe&&ke(!1)},[]),ce=Ze.useCallback(xe=>{ke(xe),xe&&re(!1)},[]),Ie=Ze.useCallback(()=>{z(te.length===0?"quickstart":"shortcuts"),T("workspace"),Be(!0),re(!1),ke(!1)},[te.length]),Oe=Ze.useCallback(async xe=>{var Ct;if(!r)return;const Ke=(Ct=r.modalButtons)==null?void 0:Ct[xe];if(!Ke)return;const wt=ps(r);if(!wt)return;const St=Ke.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").trim().toLowerCase(),jt=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(St);try{await m(wt,"resolve_action",{button:Ke,action:jt?"approve":"reject",buttonIndex:xe,...Jt(r)})}catch(I){Jl(I)||console.error("[Shortcut approval] Failed:",I)}},[r,m]),{isMac:Ee,actionDefinitions:Te,actionShortcuts:He,shortcutListening:Ue,shortcutListeningDraft:et,setShortcutListening:mt,setShortcutListeningDraft:pt,saveShortcuts:ut}=Gl({enabled:A&&!Pe,onTrigger:xe=>{var Ke,wt,St,jt,Ct,I,V,pe,we,Le,Me,Ve,nt;if(xe==="openShortcutHelp"){Ie();return}if(xe==="hideCurrentTab"){r&&de(r);return}if(xe==="toggleHiddenTabs"){ce(!je);return}if(xe==="openHistoryForActiveTab"){r&&!ze(r)&&c(r);return}if(xe==="openRemoteForActiveTab"){r&&!Ye(r)&&!ze(r)&&u(r);return}if(xe==="splitActiveTabRight"){(Ke=B.current)==null||Ke.splitActiveTabRight();return}if(xe==="splitActiveTabDown"){(wt=B.current)==null||wt.splitActiveTabDown();return}if(xe==="focusLeftPane"){(St=B.current)==null||St.focusLeftPane();return}if(xe==="focusRightPane"){(jt=B.current)==null||jt.focusRightPane();return}if(xe==="focusUpPane"){(Ct=B.current)==null||Ct.focusUpPane();return}if(xe==="focusDownPane"){(I=B.current)==null||I.focusDownPane();return}if(xe==="moveActiveTabToLeftPane"){(V=B.current)==null||V.moveActiveTabToLeftPane();return}if(xe==="moveActiveTabToRightPane"){(pe=B.current)==null||pe.moveActiveTabToRightPane();return}if(xe==="moveActiveTabToUpPane"){(we=B.current)==null||we.moveActiveTabToUpPane();return}if(xe==="moveActiveTabToDownPane"){(Le=B.current)==null||Le.moveActiveTabToDownPane();return}if(xe==="triggerPrimaryApprovalAction"){Oe(0);return}if(xe==="triggerSecondaryApprovalAction"){Oe(1);return}if(xe==="triggerTertiaryApprovalAction"){Oe(2);return}if(xe==="setActiveTabShortcut"){(Me=B.current)==null||Me.setShortcutForActiveTab();return}if(xe==="selectPreviousGroupTab"){(Ve=B.current)==null||Ve.activatePreviousTabInGroup();return}if(xe==="selectNextGroupTab"){(nt=B.current)==null||nt.activateNextTabInGroup();return}!r||!Ye(r)||ze(r)||xe==="toggleCliView"&&l(x==="chat"?"terminal":"chat")}}),ft=Ze.useCallback(()=>{Be(!1),mt(null),pt([])},[mt,pt]),$e=Ze.useMemo(()=>se==="all"?Te:Te.filter(xe=>Yl(xe)===se),[Te,se]),Lt=Ze.useCallback(()=>{const xe=Object.fromEntries(Te.map(Ke=>[Ke.id,""]));ut(xe)},[Te,ut]),Ft=Ze.useCallback(()=>{if(typeof window<"u"&&!window.confirm("Reset all dashboard shortcuts back to their default values?"))return;const xe=Object.fromEntries(Te.map(Ke=>[Ke.id,Ke.defaultShortcut]));ut(xe)},[Te,ut]);return Ze.useEffect(()=>{const xe=Ke=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?Ke.metaKey&&Ke.key.toLowerCase()==="w":Ke.ctrlKey&&Ke.key.toLowerCase()==="w")&&(Ke.preventDefault(),r&&de&&de(r))};return window.addEventListener("keydown",xe),()=>window.removeEventListener("keydown",xe)},[r,de]),Ze.useEffect(()=>{if(!Pe||Ue)return;const xe=Ke=>{Ke.key==="Escape"&&(Ke.preventDefault(),ft())};return window.addEventListener("keydown",xe,!0),()=>window.removeEventListener("keydown",xe,!0)},[ft,Pe,Ue]),Ze.useEffect(()=>{if(!A||te.length>0){Ge(!1);return}Ge(!0);const xe=window.setTimeout(()=>{Ge(!1)},1e4);return()=>window.clearTimeout(xe)},[A,te.length]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Ko,{activeConv:r,agentCount:n.length,wsStatus:i,isConnected:o,conversations:te,hiddenConversations:b,onOpenHistory:c,onOpenConversation:ue,onHideConversation:de,onShowConversation:ue,onShowAllHidden:Ce,inboxOpen:Z,onInboxOpenChange:ae,hiddenOpen:je,onHiddenOpenChange:ce,onOpenNewSession:s?void 0:()=>Fe(!0),onOpenRemote:()=>{!r||Ye(r)||ze(r)||u(r)},onStopCli:d,activeCliViewMode:x,onSetCliViewMode:l}),t?e.jsx(wl,{conversations:f,hiddenConversations:b,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,userName:K,requestedActiveTabKey:N,onRequestedActiveTabConsumed:j,requestedMachineId:k,onRequestedMachineConsumed:w,requestedMobileSection:L,onRequestedMobileSectionConsumed:M,onOpenHistory:c,onOpenRemote:u,onStopCli:d,wsStatus:i,isConnected:o,onShowHiddenConversation:ue,onShowAllHiddenConversations:Ce}):s?e.jsx(_l,{containerRef:$,isSplitMode:U,numGroups:D,groupSizes:_,groupedConvs:W,clearedTabs:E,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,hasRegisteredMachines:ie.length>0,userName:K,focusedGroup:H,setFocusedGroup:X,moveTabToGroup:O,splitTabRelative:P,closeGroup:R,handleResizeStart:F,detectedIdes:Y,handleLaunchIde:me,groupActiveTabIds:_e,setGroupActiveTabIds:G,groupTabOrders:le,setGroupTabOrders:J,toggleHiddenTab:he,allowTabShortcuts:!1}):e.jsx(Bl,{visibleConversations:te,clearedTabs:E,ides:p,actionLogs:S,sendDaemonCommand:m,setLocalUserMessages:h,setActionLogs:y,isStandalone:g,hasRegisteredMachines:ie.length>0,initialDataLoaded:v,userName:K,detectedIdes:Y,handleLaunchIde:me,toggleHiddenTab:he,registerActionHandlers:xe=>{B.current=xe},onActiveTabChange:oe,requestedActiveTabKey:fe,onRequestedActiveTabConsumed:ye,scrollToBottomRequest:Q}),We&&e.jsx(Ul,{machines:ie,onClose:()=>Fe(!1),onBrowseDirectory:ee,onSaveWorkspace:ge,onLaunchIde:C,onLaunchProvider:ne,onListSavedSessions:ve}),Pe&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:ft,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl w-[min(560px,calc(100vw-32px))] max-h-[min(80vh,720px)] overflow-y-auto px-6 py-5 shadow-xl",onClick:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:"Dashboard guide"}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:"A quick guide to the dashboard flow, plus grouped shortcuts you can tune."})]}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:ft,children:"Close"})]}),e.jsx("div",{className:"flex gap-2 mb-4 overflow-x-auto",children:[{id:"overview",label:"Overview"},{id:"quickstart",label:"Quick start"},{id:"shortcuts",label:"Shortcuts"}].map(xe=>e.jsx("button",{type:"button",className:`btn btn-sm ${q===xe.id?"btn-primary":"btn-secondary"}`,onClick:()=>z(xe.id),children:xe.label},xe.id))}),q==="overview"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3 mb-4",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"What lives where"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Tabs:"})," active sessions across IDE, CLI, and ACP agents."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Hidden tabs:"})," stash sessions you do not want in the main strip but still want to keep around."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Activity inbox:"})," sessions waiting for approval or finished tasks you have not reviewed yet."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"CLI view toggle:"})," switch a PTY session between terminal and chat rendering without relaunching it."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Useful flows"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Review notifications:"})," open the inbox, jump to the session, then use the conversation or approval controls directly from the active pane."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Reduce clutter:"})," hide less important sessions instead of closing them, then restore from hidden tabs when needed."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Split work:"})," keep one pane active for input and let secondary panes stay read-only until you focus them."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Per-tab shortcuts:"})," right-click a Dockview tab to assign a direct shortcut for that specific session."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"Approval buttons:"})," use ",Ee?"⌥J / ⌥K / ⌥L":"Ctrl+Alt+J / K / L"," for the first three visible approval actions on the active session."]})]})]})]}),q==="quickstart"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Desktop quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Start from the machine or workspace flow first. Pick or save a workspace before launching CLI or ACP sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Keep the main strip focused on active work and push overflow into Hidden tabs."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Use the inbox for approval-required or completed sessions instead of scanning every tab."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"4."})," Split only when you need parallel reading; one active pane is usually the cleanest default."]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-secondary/30 px-4 py-3",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:"Mobile quick start"}),e.jsxs("div",{className:"text-xs text-text-secondary mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"1."})," Stay in chat mode for review and replies; use workspace mode mainly to launch or reopen sessions."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"2."})," Start from the machine screen, choose a workspace, then launch IDE, CLI, or ACP from there."]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-text-primary",children:"3."})," Treat mobile as the simpler control surface: no split workflow, fewer tab mechanics, faster session switching."]})]})]})]}),q==="shortcuts"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:[{id:"all",label:"All"},{id:"workspace",label:"Workspace"},{id:"panes",label:"Panes"},{id:"approvals",label:"Approvals"}].map(xe=>e.jsx("button",{type:"button",className:`btn btn-sm ${se===xe.id?"btn-primary":"btn-secondary"}`,onClick:()=>T(xe.id),children:xe.label},xe.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Lt,children:"Disable all"}),e.jsx("button",{type:"button",className:"btn btn-sm",style:{color:"var(--status-error, #ef4444)",borderColor:"color-mix(in srgb, var(--status-error, #ef4444) 25%, var(--border-subtle, transparent))",background:"color-mix(in srgb, var(--status-error, #ef4444) 8%, var(--bg-primary, transparent))"},onClick:Ft,children:"Reset to defaults"})]})]}),e.jsx("div",{className:"space-y-2",children:$e.map(xe=>e.jsx("div",{className:`rounded-xl border px-4 py-3 ${Ue===xe.id?"border-accent bg-bg-secondary/70":"border-border-subtle bg-bg-secondary/30"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-text-primary",children:xe.label}),e.jsx("div",{className:"text-xs text-text-secondary mt-1",children:xe.description}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-2",children:["Default: ",e.jsx("span",{className:"font-mono",children:xe.defaultShortcut})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-[11px] font-mono px-2 py-1 rounded bg-bg-tertiary border border-border-subtle min-w-[72px] text-center",children:Ue===xe.id?et.length>0?`${et.join(" ")} ...`:"Listening...":He[xe.id]||"Off"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{mt(xe.id),pt([])},children:Ue===xe.id?"Listening":"Set"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:()=>{const Ke={...He};Ke[xe.id]="",ut(Ke)},children:"Disable"})]})]})},xe.id))}),e.jsxs("div",{className:"text-[11px] text-text-muted mt-4",children:["Use modifier shortcuts like ",Ee?"⌥S":"Ctrl+Alt+S",". Press Esc to stop listening."]})]})]})}),!t&&Qe&&e.jsxs("button",{type:"button",onClick:Ie,className:"fixed right-4 bottom-24 z-40 hidden md:inline-flex items-center gap-2 rounded-full border border-border-subtle bg-bg-primary/88 backdrop-blur px-2.5 py-2 text-xs text-text-secondary hover:text-text-primary transition-colors",style:{boxShadow:"0 6px 18px rgba(0,0,0,0.12)"},title:"Dashboard guide","aria-label":"Open dashboard guide",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full bg-bg-secondary text-[11px] font-semibold text-text-primary shrink-0",children:"?"}),e.jsx("span",{children:"Guide"})]})]})}const ur=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Ql({onClose:t}){const[s,r]=a.useState(0),n=ur[s],i=s===ur.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:ur.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:n.visual||n.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:n.icon})," ",n.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:n.desc}),n.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),n.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():r(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
42
42
  @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
43
43
  @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
44
44
  `})]})}function ed({hasExtensions:t,ideName:s,activeChatTab:r,extensionTabs:n,onSelectTab:i}){return t?e.jsxs("div",{className:"flex border-b border-border-subtle bg-surface-primary shrink-0",children:[e.jsx("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] ${r==="native"?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i("native"),children:s}),n.map(o=>{const c=r===o.tabKey,u=o.status==="waiting_approval",d=o.status==="generating";return e.jsxs("button",{className:`flex-1 py-2.5 px-4 border-b-2 text-[11px] font-bold tracking-wide cursor-pointer transition-all font-[var(--font)] flex items-center justify-center gap-1.5 ${c?"text-text-primary border-accent-primary bg-bg-primary":"text-text-muted border-transparent bg-transparent hover:text-text-secondary"}`,onClick:()=>i(o.tabKey),children:[e.jsx("span",{className:"shrink-0",style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:u?"var(--status-warning)":d?"var(--accent-primary)":"var(--text-muted)",boxShadow:d?"0 0 6px var(--accent-primary)":"none"}}),o.title,u&&e.jsx("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full text-[10px] font-bold ml-0.5",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)"},children:"!"})]},o.tabKey)})]}):null}function td({ideData:t,allIdes:s,connectionStates:r,localUserMessages:n,ideName:i,preferredTabKey:o}){const[c,u]=a.useState(()=>o||"native"),d=a.useMemo(()=>ma(s),[s]),x=a.useMemo(()=>{var h;if(!t)return[];const m=t.daemonId||((h=t.id)==null?void 0:h.split(":")[0])||t.id;return Rr(t,n,{machineName:t.daemonId&&d[t.daemonId]||void 0,connectionState:r[m]||"new"})},[t,n,d,r]),l=a.useMemo(()=>x.find(m=>m.streamSource==="native"),[x]),f=a.useMemo(()=>x.filter(m=>m.streamSource==="agent-stream"),[x]);a.useEffect(()=>{o&&u(o)},[o]),a.useEffect(()=>{var m;c!=="native"&&(f.some(h=>h.tabKey===c)||u(((m=f[0])==null?void 0:m.tabKey)||"native"))},[c,f]),a.useEffect(()=>{c==="native"&&(l||f[0]&&u(f[0].tabKey))},[c,l,f]);const b=a.useMemo(()=>c==="native"&&l?l:f.find(m=>m.tabKey===c)||l||f[0],[c,l,f]),p=a.useMemo(()=>f.map(m=>({tabKey:m.tabKey,title:m.title||m.agentName||i,status:m.status})),[f,i]),S=a.useCallback(m=>{if(m)return x.find(h=>h.sessionId===m||h.ideId===m||h.tabKey===m||h.ideType===m||h.agentType===m)},[x]);return{activeChatTab:c,setActiveChatTab:u,activeConv:b,conversations:x,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:S}}function sd({activeConv:t,ideEntry:s,ides:r,connectionStates:n,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:u,setActionLogs:d,isStandalone:x,userName:l,onOpenHistory:f,onConversationChange:b,onClose:p}){var W;const[S,m]=a.useState("split"),[h,y]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),g=a.useMemo(()=>s||r.find(E=>E.id===t.ideId),[t.ideId,s,r]),v=a.useMemo(()=>qe((g==null?void 0:g.type)||""),[g==null?void 0:g.type]),{conversations:K,extensionTabs:N,hasExtensions:j}=td({ideData:g,allIdes:r,connectionStates:n,localUserMessages:o,ideName:v||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{y(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const k=a.useMemo(()=>h==="native"?K.find(E=>E.streamSource==="native")||t:K.find(E=>E.tabKey===h)||t,[t,K,h]),w=k.daemonId||((W=k.ideId)==null?void 0:W.split(":")[0])||k.ideId,L=Ys({sendDaemonCommand:c,activeConv:k,setLocalUserMessages:u,setActionLogs:d,isStandalone:x}),{connScreenshot:M,screenshotUsage:$,handleRemoteAction:U}=Ea({doId:w,ideId:k.ideId,ideType:k.ideType,connState:k.connectionState||"new",viewMode:S,instanceId:g==null?void 0:g.instanceId}),D=a.useMemo(()=>i.filter(E=>E.ideId===k.tabKey),[i,k.tabKey]);a.useEffect(()=>{b==null||b(k)},[k,b]),a.useEffect(()=>{const E=H=>{H.key==="Escape"&&p()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[p]);const _=a.useCallback(E=>{E.stopPropagation()},[]);return e.jsx("div",{className:"fixed inset-0 z-[1200] flex items-center justify-center p-0 md:p-3 bg-[#030617]/[0.56] backdrop-blur-md",onClick:p,children:e.jsxs("div",{className:"w-full h-[100dvh] md:h-[calc(100vh-24px)] md:w-[calc(100vw-24px)] flex flex-col overflow-hidden md:rounded-[14px] md:border border-border-default bg-surface-primary shadow-[0_24px_80px_rgba(2,6,23,0.32)]",role:"dialog","aria-modal":"true",onClick:_,children:[e.jsxs("div",{className:"sticky top-0 z-20 flex flex-col gap-3 md:flex-row md:items-center md:justify-between px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-3 border-b border-border-subtle bg-bg-primary/96 backdrop-blur-md shrink-0 overflow-visible",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 min-w-0 w-full md:w-auto md:flex-1",children:[e.jsx("div",{className:"min-w-0 flex-1 flex flex-col justify-center",children:e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 font-extrabold text-[18px] md:text-xl tracking-tight text-text-primary",children:[e.jsx("span",{className:"w-7 h-7 flex items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary shrink-0",children:e.jsx(ct,{size:16})}),e.jsx("span",{className:"truncate",children:k.displayPrimary||k.agentName||"Remote"})]})}),e.jsx("button",{className:"btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold md:hidden shrink-0",onClick:p,children:"Close"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 w-full md:w-auto justify-between md:justify-end",children:[e.jsx("div",{className:"flex items-center gap-2 mr-auto md:mr-0",children:["split","remote"].map(E=>{const H=S===E;return e.jsx("button",{className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${H?"bg-accent-primary/12 border border-accent-primary/35 text-accent-primary shadow-glow":"bg-bg-secondary border border-border-subtle text-text-secondary hover:bg-bg-glass hover:text-text-primary"}`,onClick:()=>m(E),title:E==="split"?"Split view":"Remote only",children:E==="split"?e.jsx(Oi,{size:15}):e.jsx(ct,{size:15})},E)})}),e.jsx("div",{className:"hidden md:block w-[1px] h-5 bg-border-subtle mx-1"}),e.jsxs("button",{className:"btn btn-secondary btn-sm h-8 px-2.5 md:px-3 rounded-lg",onClick:()=>f(k),title:"Chat History",children:[e.jsx(Sr,{size:14,className:"md:mr-1.5"}),e.jsx("span",{className:"hidden md:inline",children:"History"})]}),e.jsx("button",{className:"hidden md:inline-flex btn btn-primary btn-sm h-8 px-4 rounded-lg font-bold",onClick:p,children:"Close"})]})]}),e.jsxs("div",{className:`flex-1 min-h-0 grid bg-bg-primary ${S==="split"?"grid-cols-1 grid-rows-[1fr_minmax(320px,42vh)] md:grid-cols-[minmax(360px,0.92fr)_minmax(420px,1.08fr)] md:grid-rows-1":"grid-cols-1 grid-rows-1"}`,children:[S!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${S==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(ed,{hasExtensions:j,ideName:v||"IDE",activeChatTab:h,extensionTabs:N,onSelectTab:y}),e.jsx(na,{activeConv:k,onModalButton:L.handleModalButton}),e.jsx(br,{activeConv:k,ideEntry:g,showMetaChips:!1,handleSendChat:L.handleSendChat,isSendingChat:L.isSendingChat,handleFocusAgent:L.handleFocusAgent,isFocusingAgent:L.isFocusingAgent,actionLogs:D,userName:l})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${S==="split"?"order-1 md:order-2":""}`,children:e.jsx(ta,{addLog:()=>{},connState:k.connectionState||"new",connScreenshot:M,screenshotUsage:$,transportType:k.transport,onAction:U})})]})]})})}function rd({activeConv:t,canSaveAndStop:s=!1,onCancel:r,onStopNow:n,onSaveAndStop:i}){const o=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1400] flex items-center justify-center p-4",children:[e.jsx("div",{onClick:r,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[min(92vw,420px)] md:w-[92%] md:max-w-[420px] flex flex-col overflow-hidden rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-base md:text-lg font-extrabold",children:["Stop ",o,"?"]}),e.jsx("div",{className:"mt-1 text-[13px] md:text-sm text-text-muted leading-relaxed",children:s?"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first.":"The CLI runtime will stop immediately. This provider does not expose save-and-stop."})]}),e.jsxs("div",{className:"px-4 py-4 md:px-6 md:py-5 bg-bg-primary flex flex-col gap-2.5",children:[s&&e.jsx("button",{onClick:i,className:"btn btn-primary w-full justify-center min-h-[42px]",children:"Save and stop"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center min-h-[42px] text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:r,className:"btn btn-secondary w-full justify-center min-h-[42px]",children:"Cancel"})]})]})]})}function nd({historyModalOpen:t,historyTargetConv:s,ides:r,isHistoryCreatingChat:n,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:u,onCloseHistory:d,onNewHistoryChat:x,onSwitchHistorySession:l,onRefreshHistory:f,onResumeSavedHistorySession:b,remoteDialogConv:p,remoteDialogIdeEntry:S,connectionStates:m,actionLogs:h,localUserMessages:y,sendDaemonCommand:g,setLocalUserMessages:v,setActionLogs:K,isStandalone:N,userName:j,onOpenRemoteHistory:k,onRemoteConversationChange:w,onCloseRemoteDialog:L,cliStopDialogOpen:M,cliStopTargetConv:$,onCancelCliStop:U,onStopCliNow:D,onSaveCliAndStop:_,toasts:W,onDismissToast:E,onClickToast:H,showOnboarding:X,onCloseOnboarding:O}){var P;return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(Pr,{activeConv:s,ides:r,isCreatingChat:n,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:u,onClose:d,onNewChat:x,onSwitchSession:l,onRefreshHistory:f,onResumeSavedSession:b}),p&&e.jsx(sd,{activeConv:p,ideEntry:S,ides:r,connectionStates:m,actionLogs:h,localUserMessages:y,sendDaemonCommand:g,setLocalUserMessages:v,setActionLogs:K,isStandalone:N,userName:j,onOpenHistory:k,onConversationChange:w,onClose:L}),M&&$&&Ye($)&&!ze($)&&e.jsx(rd,{activeConv:$,canSaveAndStop:!!((P=$.resume)!=null&&P.supported),onCancel:U,onStopNow:D,onSaveAndStop:_}),e.jsx(ua,{toasts:W,onDismiss:E,onClickToast:H}),X&&e.jsx(Ql,{onClose:O})]})}function ad({daemons:t,targetVersion:s,upgradingDaemons:r,onUpgrade:n,onDismiss:i}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 border-b text-xs text-text-secondary shrink-0 flex-wrap",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",borderColor:"color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",style:{color:"var(--status-warning)"},children:e.jsx(Hs,{size:14})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available",s?e.jsxs(e.Fragment,{children:[": ",e.jsxs("strong",{children:["v",s]})]}):null]}),t.map(o=>{const c=gt(o,{fallbackId:o.id}),u=r[o.id],d=o.version||o.daemonVersion||"unknown";return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 15%, transparent)"},children:[e.jsx("span",{className:"font-medium text-text-primary",children:c}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",d]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(o.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold cursor-pointer px-1.5 py-px rounded transition-colors",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},onClick:()=>n(o.id),children:"Upgrade"})]},o.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:i,title:"Dismiss",children:"✕"})]})}function id(t){if(!t)return"";const s=String(t);return s.includes(":")&&s.split(":")[0]||s}function Rn(t){return String(t||"").trim().replace(/\\/g,"/").replace(/\/+$/,"").toLowerCase()}function od(t){return(t instanceof Error?t.message:String(t||"")).includes("P2P command timeout")}function cd(t){const s=t instanceof Error?t.message:String(t||"");return s.includes("P2P command timeout")||s.includes("P2P not connected")||s.includes("CLI session not found")||s.includes("CLI_SESSION_NOT_FOUND")}function ld(){var Hr,Fr,Vr;const{sendCommand:t}=Pt(),s=kr(),r=ts(),[n,i]=vi(),o=n.get("activeTab"),c=((Hr=s.state)==null?void 0:Hr.openRemoteForTabKey)||null,u=((Fr=s.state)==null?void 0:Fr.openMachineId)||null,d=((Vr=s.state)==null?void 0:Vr.mobileSection)||null,x=_r(),l=x.ides||[],f=x.initialLoaded??!0,{updateIdeChats:b}=x,[p,S]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),m=x.toasts||[],h=x.setToasts||(()=>{}),y=x.wsStatus||"connected",g=x.isConnected??!0,v=x.connectionStates||{},K=x.showReconnected||!1,{groupAssignments:N,setGroupAssignments:j,focusedGroup:k,setFocusedGroup:w,groupActiveTabIds:L,setGroupActiveTabIds:M,groupTabOrders:$,setGroupTabOrders:U,groupSizes:D,setGroupSizes:_,isMobile:W,hasHydratedStoredLayout:E,hydrateStoredLayout:H}=tl(),[X,O]=a.useState(!1),[P,R]=a.useState(!1),[F,Y]=a.useState(null),[me,_e]=a.useState([]),[G,le]=a.useState(!1),[J,he]=a.useState(null),[te]=a.useState(()=>ka()),[fe,ye]=a.useState([]),[oe,de]=a.useState({}),[ue,Ce]=a.useState({}),[Q,ie]=a.useState(null),[ee,ge]=a.useState(null),[C,ne]=a.useState(null),ve=a.useRef(null);hs("Dashboard",{ideCount:l.length,toastCount:m.length,focusedGroup:k,groupCount:Object.keys(N).length,localMessageTabs:Object.keys(oe).length,actionLogCount:fe.length});const B=l.find(be=>be.type==="adhdev-daemon"),Z=(B==null?void 0:B.detectedIdes)||[],re=a.useMemo(()=>l.filter(be=>be.type==="adhdev-daemon"||be.daemonMode).sort(Ar),[l]),je=!!B,ke=(B==null?void 0:B.terminalBackend)||null,Pe=B?gt(B,{fallbackId:B.id}):null,Be=(B==null?void 0:B.id)||null,{hiddenTabs:We,hideTab:Fe,toggleTab:Qe,showTab:Ge,showAllTabs:q}=$c(),{chatIdes:z,conversations:se,visibleConversations:T,visibleTabKeys:A,resolveConversationBySessionId:ae,resolveConversationByTarget:ce}=Fc({ides:l,connectionStates:v,localUserMessages:oe,clearedTabs:ue,hiddenTabs:We}),Ie=a.useMemo(()=>bs(l),[l]),Oe=a.useRef(null),{containerRef:Ee,normalizedGroupAssignments:Te,numGroups:He,isSplitMode:Ue,groupedConvs:et,moveTabToGroup:mt,closeGroup:pt,handleResizeStart:ut,splitTabRelative:ft}=cl({groupAssignments:N,setGroupAssignments:j,setFocusedGroup:w,setGroupActiveTabIds:M,setGroupTabOrders:U,groupSizes:D,setGroupSizes:_,isMobile:W,visibleConversations:T,visibleTabKeys:A}),$e=a.useMemo(()=>{var Ae,Ne;if(!W){if(Q){const Se=se.find(Re=>Re.tabKey===Q);if(Se)return Se}return T[0]}const be=L[k];if(be){const Se=se.find(Re=>Re.tabKey===be);if(Se)return Se}return((Ae=et[k])==null?void 0:Ae[0])||((Ne=et[0])==null?void 0:Ne[0])},[Q,W,L,k,se,et,T]);a.useEffect(()=>{if(W){Oe.current=null;return}if(!($e!=null&&$e.sessionId)){Oe.current=null;return}const be=`${$e.tabKey}:${$e.sessionId}`;if(Oe.current===be)return;Oe.current=be;const Ae=ds($e,Ie),Ne=Math.max(Date.now(),Dt($e),Ae.lastUpdated||0);t($e.daemonId||$e.ideId,"mark_session_seen",{sessionId:$e.sessionId,seenAt:Ne}).catch(()=>{})},[$e,W,Ie,t]);const{requestedDesktopTabKey:Lt,requestedMobileTabKey:Ft,consumeRequestedActiveTab:xe}=Vc({isMobile:W,urlActiveTab:o,resolveConversationBySessionId:ae,setSearchParams:i}),{remoteDialogConv:Ke,remoteDialogIdeEntry:wt,remoteDialogActiveConv:St,setRemoteDialogActiveConv:jt,openRemoteDialog:Ct,closeRemoteDialog:I}=rl({isMobile:W,location:s,navigate:r,requestedRemoteTabTarget:c,requestedDesktopTabKey:Lt,conversations:se,ides:l,resolveConversationByTarget:ce}),V=St||Ke||$e,pe=!!V&&Ye(V)&&!ze(V),we=a.useMemo(()=>{if(!V||!pe)return null;const be=V.daemonId||V.ideId||"",Ae=V.agentType||V.ideType||"";return`${be}:${Ae}`},[V,pe]),Le=a.useMemo(()=>T,[T]),Me=W&&te==="chat",Ve=a.useMemo(()=>se.filter(be=>We.has(be.tabKey)),[se,We]),nt=a.useCallback(be=>{const Ae=new URLSearchParams(n);Ae.set("activeTab",be),i(Ae,{replace:!0})},[n,i]),xt=a.useCallback(async(be,Ae)=>Kr(t,be,Ae),[t]),st=a.useCallback(async(be,Ae)=>{if(!Ae.trim())return{ok:!1,error:"Choose a workspace path first."};try{const Ne=await t(be,"workspace_add",{path:Ae.trim()});return Ne!=null&&Ne.success?{ok:!0}:{ok:!1,error:(Ne==null?void 0:Ne.error)||"Could not save workspace"}}catch(Ne){return{ok:!1,error:Ne instanceof Error?Ne.message:"Could not save workspace"}}},[t]),ss=a.useCallback(async(be,Ae,Ne)=>{var Se;try{const Re={ideType:Ae,enableCdp:!0};(Se=Ne==null?void 0:Ne.workspacePath)!=null&&Se.trim()&&(Re.workspace=Ne.workspacePath.trim());const rt=await t(be,"launch_ide",Re);return!(rt!=null&&rt.success)&&(rt==null?void 0:rt.success)!==void 0?{ok:!1,error:(rt==null?void 0:rt.error)||"Could not launch IDE"}:(ne({machineId:be,kind:"ide",providerType:Ae,workspacePath:(Ne==null?void 0:Ne.workspacePath)||null,startedAt:Date.now()}),{ok:!0})}catch(Re){return{ok:!1,error:Re instanceof Error?Re.message:"Could not launch IDE"}}},[t]),Ha=a.useCallback(async(be,Ae,Ne,Se)=>{var rt,rs,Vt;const Re=Date.now();try{const yt={cliType:Ne};(rt=Se==null?void 0:Se.workspacePath)!=null&&rt.trim()?yt.dir=Se.workspacePath.trim():Se!=null&&Se.workspaceId&&(yt.workspaceId=Se.workspaceId),(rs=Se==null?void 0:Se.resumeSessionId)!=null&&rs.trim()&&(yt.resumeSessionId=Se.resumeSessionId.trim()),Array.isArray(Se==null?void 0:Se.cliArgs)&&Se.cliArgs.length>0&&(yt.cliArgs=Se.cliArgs),(Vt=Se==null?void 0:Se.initialModel)!=null&&Vt.trim()&&(yt.initialModel=Se.initialModel.trim());const at=await t(be,"launch_cli",yt),dt=(at==null?void 0:at.result)||at,ns=(dt==null?void 0:dt.sessionId)||(dt==null?void 0:dt.id);return at!=null&&at.success&&ns?(nt(ns),{ok:!0}):at!=null&&at.success?(ne({machineId:be,kind:Ae,providerType:Ne,workspacePath:(Se==null?void 0:Se.workspacePath)||null,resumeSessionId:(Se==null?void 0:Se.resumeSessionId)||null,startedAt:Re}),{ok:!0}):{ok:!1,error:(at==null?void 0:at.error)||(dt==null?void 0:dt.error)||`Could not launch ${Ae.toUpperCase()} session`}}catch(yt){return od(yt)?(ne({machineId:be,kind:Ae,providerType:Ne,workspacePath:(Se==null?void 0:Se.workspacePath)||null,resumeSessionId:(Se==null?void 0:Se.resumeSessionId)||null,startedAt:Re}),{ok:!0}):{ok:!1,error:yt instanceof Error?yt.message:`Could not launch ${Ae.toUpperCase()} session`}}},[nt,t]),Fa=a.useCallback(async(be,Ae)=>{if(!be||!Ae)return[];try{const Ne=await t(be,"list_saved_sessions",{providerType:Ae,kind:"cli",limit:30}),Se=(Ne==null?void 0:Ne.result)??Ne;return Array.isArray(Se==null?void 0:Se.sessions)?Se.sessions:[]}catch(Ne){return console.error("List saved sessions failed",Ne),[]}},[t]);a.useEffect(()=>{var Se;if(!C)return;const be=Rn(C.workspacePath),Ae=l.find(Re=>{var at,dt,ns,qr;if(!Re||Re.type==="adhdev-daemon"||Re.daemonMode||id(Re.daemonId||Re.id)!==C.machineId||(ms(Re)?"cli":Xt(Re)?"acp":"ide")!==C.kind||String(Re.agentType||Re.ideType||Re.type||"")!==C.providerType)return!1;if(C.resumeSessionId)return String(Re.providerSessionId||"")===C.resumeSessionId;if(be){const tr=Rn(Re.workspace||Re.runtimeWorkspaceLabel);return tr?tr===be:!1}return Number(Re.lastUpdated||Re._lastUpdate||Re.timestamp||((qr=(ns=(dt=(at=Re.activeChat)==null?void 0:at.messages)==null?void 0:dt.at)==null?void 0:ns.call(dt,-1))==null?void 0:qr.timestamp)||0)>=C.startedAt-5e3});if(!Ae)return;const Ne=typeof Ae.sessionId=="string"&&Ae.sessionId?Ae.sessionId:typeof Ae.instanceId=="string"&&Ae.instanceId?Ae.instanceId:(Se=se.find(Re=>Re.ideId===Ae.id))==null?void 0:Se.sessionId;Ne&&(ne(null),nt(Ne))},[se,nt,l,C]),a.useEffect(()=>{if(!C)return;const be=window.setTimeout(()=>{ne(Ae=>!Ae||Ae.startedAt!==C.startedAt?Ae:null)},45e3);return()=>window.clearTimeout(be)},[C]),Dc({visibleConversations:T,clearedTabs:ue,setClearedTabs:Ce,setActionLogs:ye}),qc({ides:l,sendDaemonCommand:t,setToasts:h,setLocalUserMessages:de,resolveConversationByTarget:ce});const{isRefreshingHistory:Va,handleLaunchIde:qa,handleRefreshHistory:Ga}=vn({sendDaemonCommand:t,activeConv:$e,updateIdeChats:b,setToasts:h,setLocalUserMessages:de,setClearedTabs:Ce}),{isCreatingChat:Ya,isRefreshingHistory:Xa,handleSwitchSession:Ja,handleNewChat:Za,handleRefreshHistory:Qa}=vn({sendDaemonCommand:t,activeConv:V,updateIdeChats:b,setToasts:h,setLocalUserMessages:de,setClearedTabs:Ce}),Qs=a.useCallback(async()=>{if(!(!V||!pe||G)){le(!0);try{const be=V.daemonId||V.ideId,Ae=V.agentType||V.ideType,Ne=await t(be,"list_saved_sessions",{agentType:Ae,providerType:Ae,kind:"cli",limit:50}),Se=(Ne==null?void 0:Ne.result)??Ne;_e(Array.isArray(Se==null?void 0:Se.sessions)?Se.sessions:[])}catch(be){console.error("Refresh saved sessions failed",be),_e([])}finally{le(!1)}}},[V,G,pe,t]);a.useEffect(()=>{if(!X){ve.current=null;return}if(!pe){ve.current=null,_e([]),le(!1);return}!we||G||ve.current!==we&&(ve.current=we,Qs())},[Qs,X,G,pe,we]);const ei=a.useCallback(async be=>{if(!V||!pe||!be.providerSessionId||!be.workspace)return;const Ae=V.daemonId||V.ideId,Ne=V.agentType||V.ideType;try{he(be.providerSessionId);const Se=await t(Ae,"launch_cli",{cliType:Ne,dir:be.workspace,resumeSessionId:be.providerSessionId,initialModel:be.currentModel}),Re=(Se==null?void 0:Se.result)??Se,rt=typeof(Re==null?void 0:Re.sessionId)=="string"?Re.sessionId:typeof(Re==null?void 0:Re.id)=="string"?Re.id:"";rt&&i(rs=>{const Vt=new URLSearchParams(rs);return Vt.set("activeTab",rt),Vt},{replace:!0}),O(!1)}catch(Se){console.error("Resume saved session failed",Se)}finally{he(null)}},[V,pe,t,i]);sl({urlActiveTab:W&&!Me?o:null,conversations:se,resolveConversationBySessionId:ae,normalizedGroupAssignments:Te,hasHydratedStoredLayout:W&&!Me?E:!0,hydrateStoredLayout:W&&!Me?H:()=>{},setGroupActiveTabIds:M,setFocusedGroup:w,setSearchParams:i,historyModalOpen:X,activeConv:$e,isRefreshingHistory:Va,ides:l,handleRefreshHistory:Ga});const er=a.useCallback(async(be,Ae)=>{const Ne=Ae||F||$e;if(!Ne||!Ye(Ne)||ze(Ne))return;const Se=Ne.ideType||Ne.agentType||"",Re=Ne.ideId||Ne.daemonId||"";try{await t(Re,"stop_cli",{cliType:Se,targetSessionId:Ne.sessionId,mode:be})}catch(rt){console.error("Stop CLI failed:",rt)}},[$e,F,t]),ti=a.useCallback(async be=>{const Ae=be||$e;!Ae||!Ye(Ae)||ze(Ae)||(Y(Ae),R(!0))},[$e,er]),si=a.useMemo(()=>!$e||!Ye($e)||ze($e)?null:es($e),[$e]),ri=a.useCallback(async be=>{if(!(!$e||!Ye($e)||ze($e)||es($e)===be))try{await t($e.daemonId||$e.ideId,"set_cli_view_mode",{targetSessionId:$e.sessionId,cliType:$e.ideType||$e.agentType,mode:be})}catch(Ne){cd(Ne)?console.warn("Skipped CLI view mode switch:",Ne instanceof Error?Ne.message:String(Ne)):console.error("Failed to switch CLI view mode:",Ne)}},[$e,t]),{versionMismatchDaemons:ni,appVersion:ai,versionBannerDismissed:ii,setVersionBannerDismissed:oi,upgradingDaemons:ci,handleBannerUpgrade:li}=ll({ides:l,sendDaemonCommand:t}),Ur=a.useCallback(be=>{ie(be.tabKey),i(Ae=>{const Ne=new URLSearchParams(Ae);return be.sessionId?Ne.set("activeTab",be.sessionId):Ne.delete("activeTab"),Ne},{replace:!0})},[i]),zr=a.useCallback(be=>{Ge(be.tabKey),Ur(be)},[Ur,Ge]),di=a.useCallback(be=>{Fe(be.tabKey)},[Fe]);return e.jsxs("div",{className:"page-dashboard flex-1 min-h-0 bg-bg-primary text-text-primary flex flex-col overflow-hidden",children:[e.jsx(Do,{wsStatus:y,showReconnected:K}),e.jsx(Bo,{terminalBackend:ke,isStandalone:je,machineLabel:Pe,machineKey:Be}),!ii&&e.jsx(ad,{daemons:ni,targetVersion:ai,upgradingDaemons:ci,onUpgrade:li,onDismiss:()=>oi(!0)}),e.jsx(Zl,{showMobileChatMode:Me,isMobile:W,activeConv:$e,chatIdes:z,wsStatus:y,isConnected:g,onOpenHistory:be=>{be&&jt(be),O(!0)},onOpenRemote:Ct,onStopCli:ti,activeCliViewMode:si,onSetActiveCliViewMode:ri,mobileChatConversations:Le,ides:l,actionLogs:fe,sendDaemonCommand:t,setLocalUserMessages:de,setActionLogs:ye,isStandalone:je,initialDataLoaded:f,userName:x.userName,requestedMobileTabKey:Ft,onRequestedMobileTabConsumed:xe,requestedMachineId:u,onRequestedMachineConsumed:()=>{r(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:d,onRequestedMobileSectionConsumed:()=>{r(s.pathname+s.search,{replace:!0,state:null})},containerRef:Ee,isSplitMode:Ue,numGroups:He,groupSizes:D,groupedConvs:et,clearedTabs:ue,focusedGroup:k,setFocusedGroup:w,moveTabToGroup:mt,splitTabRelative:ft,closeGroup:pt,handleResizeStart:ut,detectedIdes:Z,handleLaunchIde:qa,groupActiveTabIds:L,setGroupActiveTabIds:M,groupTabOrders:$,setGroupTabOrders:U,toggleHiddenTab:Qe,visibleConversations:T,hiddenConversations:Ve,requestedDesktopTabKey:Lt,onRequestedDesktopTabConsumed:xe,onDesktopActiveTabChange:ie,onHideConversation:di,onShowHiddenConversation:zr,onShowAllHiddenConversations:q,scrollToBottomRequest:ee,machineEntries:re,onBrowseMachineDirectory:xt,onSaveMachineWorkspace:st,onLaunchMachineIde:ss,onLaunchMachineProvider:Ha,onListMachineSavedSessions:Fa}),e.jsx("style",{children:`
@@ -52,4 +52,4 @@ This will disconnect CDP and optionally kill the process.`))try{const P=await r(
52
52
  from { opacity: 0; transform: translateX(40px); }
53
53
  to { opacity: 1; transform: translateX(0); }
54
54
  }
55
- `})]})}function Nd(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[r,n]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const u=[],d=[],x=[],l=[];Object.values(c.providers||{}).forEach(b=>{const p={name:b.name||"Unknown",status:b.status||"Stable",details:b.details||"Community Provider"};b.category==="ide"?u.push(p):b.category==="cli"?d.push(p):b.category==="extension"?x.push(p):b.category==="acp"&&l.push(p)});const f=(b,p)=>{const S={Stable:1,Beta:2,WIP:3},m=S[b.status]||99,h=S[p.status]||99;return m!==h?m-h:b.name.localeCompare(p.name)};s({ide:u.sort(f),cli:d.sort(f),ext:x.sort(f),acp:l.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>n(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Xn,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Fs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx(Cr,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((u,d)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:u.name}),e.jsx("td",{className:"py-3 px-4",children:i(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},d))})]})});return r?e.jsx(Ws,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Bs,{}),widthClassName:"max-w-5xl",children:e.jsx(Er,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(Ws,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Bs,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(ot,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(ot,{title:"IDE support",icon:e.jsx(ct,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(ot,{title:"Standalone CLI agents",icon:e.jsx(Ir,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(ot,{title:"AI extensions",icon:e.jsx(Ot,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(ot,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ot,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Sd{constructor(){tt(this,"adapters",new Map);tt(this,"states",new Map);tt(this,"runtimeListeners",new Map);tt(this,"screenshotCallbacks",new Map);tt(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const r of this.adapters.keys())if(r.startsWith("standalone"))return r}return null}register(s,r){this.adapters.set(s,r),this.states.set(s,r.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,r){this.states.set(s,r)}retryConnection(s){}get(s){const r=this.resolveDaemonId(s);return r?this.adapters.get(r):void 0}getState(s){const r=this.resolveDaemonId(s);return r&&this.states.get(r)||"disconnected"}sendData(s,r){return!1}sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,i){return!1}onScreenshot(s,r){return this.screenshotCallbacks.set(s,r),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,r){this.screenshotCallbacks.forEach(n=>n(s,r))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,r){this.statusCallbacks.forEach(n=>n(s,r))}emitRuntimeSnapshot(s,r,n=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:n,text:r,truncated:i})}emitSessionOutput(s,r,n){!s||typeof r!="string"||!r||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof n=="number"?{seq:n}:{},data:r})}onRuntimeEvent(s,r){const n=this.runtimeListeners.get(s)||new Set;return n.add(r),this.runtimeListeners.set(s,n),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(r),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,r){if(!r)return;const n=await fetch(`/api/v1/runtime/${encodeURIComponent(r)}/snapshot`);if(!n.ok)return;const i=await n.json();this.emitRuntimeEvent(r,{type:"runtime_snapshot",sessionId:r,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,r){var n;(n=this.runtimeListeners.get(s))==null||n.forEach(i=>i(r))}}const It=new Sd;function Cd(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,n=new URLSearchParams(window.location.search).get("token");return n?`${s}?token=${encodeURIComponent(n)}`:s}const Dn=Cd(),Bn=3e3,Id=3e4;let Tt=null,Td=0;const Us=new Map;let Et=null,ls=null;function Kn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Ad(t){return t==="connected"?"connected":t}async function Es(t,s,r){const n=qo(t,r||{}),i=Tt;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++Td}_${Date.now()}`;return new Promise((c,u)=>{const d=setTimeout(()=>{Us.delete(o),u(new Error(`WS command timeout: ${s}`))},3e4);Us.set(o,{resolve:x=>{clearTimeout(d),c(x)},reject:x=>{clearTimeout(d),u(x)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:n.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class _d{constructor(s){tt(this,"daemonId");tt(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Tt==null?void 0:Tt.readyState)===WebSocket.OPEN}get connectionState(){return(Tt==null?void 0:Tt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,r){return Es(this.daemonId,s,r)}async sendInput(s,r){return Es(this.daemonId,"cdp_remote_action",{action:s,params:r,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Et&&(clearInterval(Et),Et=null);const r=async()=>{if(this.hasCommandChannel)try{const n=await Es(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(n!=null&&n.success&&(n!=null&&n.base64)){const i=await fetch(`data:image/jpeg;base64,${n.base64}`).then(o=>o.blob());It.emitScreenshot(this.daemonId,i)}}catch{}};r(),Et=setInterval(r,2e3)}stopScreenshots(s){Et&&(clearInterval(Et),Et=null)}}let bt=null;function Md(t){return(!bt||bt.daemonId!==t)&&(bt=new _d(t)),bt}function Pd({children:t}){const s=a.useRef(Yr()),r=Yr();s.current=r;const{setUserName:n}=Zt(),i=a.useRef(n);i.current=n;const[,o]=a.useState("disconnected"),c=a.useCallback((b,p)=>{o(b),ls==null||ls(b,p)},[]),u=a.useRef(null),d=a.useRef(),x=a.useRef(Bn),l=a.useRef(!0),f=a.useRef(!1);return a.useEffect(()=>{l.current=!0,f.current=!1;function b(){var m,h;if(!l.current||((m=u.current)==null?void 0:m.readyState)===WebSocket.OPEN||((h=u.current)==null?void 0:h.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Dn}...`);let S;try{S=new WebSocket(Dn)}catch(y){console.error("[Standalone WS] Failed to create WebSocket:",y),p();return}u.current=S,S.onopen=()=>{if(!l.current){S.close();return}c("connected"),x.current=Bn,console.log("[Standalone WS] Connected")},Tt=S,S.onmessage=y=>{var g;try{const v=JSON.parse(y.data);if((v.type==="command_result"||v.type==="error")&&v.requestId){const K=Us.get(v.requestId);K&&(Us.delete(v.requestId),v.type==="error"?K.reject(new Error(((g=v.data)==null?void 0:g.message)||"Command failed")):K.resolve(v.data));return}if(v.type==="session_output"){const K=v.sessionId||v.cliId||v.cliType;K&&It.emitSessionOutput(K,typeof v.data=="string"?v.data:"",typeof v.seq=="number"?v.seq:void 0);return}if(v.type==="runtime_snapshot"){It.emitRuntimeSnapshot(v.sessionId,typeof v.text=="string"?v.text:"",typeof v.seq=="number"?v.seq:0,!!v.truncated);return}if(v.type==="status"||v.type==="initial_state"){const K=v.data;if(!K)return;const{injectEntries:N,markLoaded:j}=s.current,k=K.id||"standalone",w=Md(k);It.register(k,w),It.setState(k,"connected"),c("connected",k),It.emitStatus(k,K);const L=Fo(K,{daemonId:k});Kn("ws_status",{type:v.type,daemonId:k,sessions:(K.sessions||[]).map(M=>({id:M.id,parentId:M.parentId,providerType:M.providerType,kind:M.kind,transport:M.transport,unread:M.unread,inboxBucket:M.inboxBucket,lastSeenAt:M.lastSeenAt,lastUpdated:M.lastUpdated,title:M.title})),recentLaunches:(K.recentLaunches||[]).map(M=>({id:M.id,providerType:M.providerType,kind:M.kind,workspace:M.workspace,lastLaunchedAt:M.lastLaunchedAt}))}),Kn("entries",{daemonId:k,entries:L.filter(M=>M.type!=="adhdev-daemon").map(M=>({id:M.id,type:M.type,unread:M.unread,inboxBucket:M.inboxBucket,lastSeenAt:M.lastSeenAt,lastUpdated:M.lastUpdated,sessionId:M.sessionId}))}),L.length>0&&N(L,{authoritativeDaemonIds:[k]}),j(),K.userName&&i.current&&i.current(K.userName)}}catch(v){console.error("[Standalone WS] Parse error:",v)}},S.onclose=()=>{l.current&&(bt==null||bt.stopScreenshots(),bt&&It.setState(bt.daemonId,"disconnected"),c("disconnected"),u.current=null,p())},S.onerror=y=>{f.current||!l.current||console.warn("[Standalone WS] Error, will reconnect:",y)}}function p(){if(!l.current)return;clearTimeout(d.current);const S=x.current;console.log(`[Standalone WS] Reconnecting in ${S}ms...`),d.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,Id),b()},S)}return b(),()=>{l.current=!1,f.current=!0,clearTimeout(d.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Tt=null),bt&&(bt.stopScreenshots(),It.unregister(bt.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Ld({children:t}){const[s,r]=a.useState("disconnected"),[n,i]=a.useState(null);a.useEffect(()=>(ls=(c,u)=>{r(c),u&&i(u)},()=>{ls=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",u=Ad(s),d={};return n&&(d[n]=u),d.standalone=u,{wsStatus:s,isConnected:c,connectionStates:d}},[s,n]);return e.jsx(Ti,{connectionOverrides:o,children:e.jsx(Pd,{children:t})})}const Rd=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Gn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ds,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(zs,{}),label:"Settings"}];function Ed({children:t}){const s=ts(),r=kr(),[n,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=l=>{s(l),i(!1)},d=()=>{c(l=>{const f=!l;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=l=>`nav-item${r.pathname.startsWith(l)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${n?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),n&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:l=>l.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${n?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Rd.map(l=>e.jsxs("div",{className:x(l.path),id:`nav-${l.id}`,onClick:()=>u(l.path),title:o?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!o&&l.label]},l.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Bs,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${r.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Yn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.23"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:d,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const $d=[{icon:e.jsx(Ds,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Nt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Jn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(ct,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ot,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Bs,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Dd=[{icon:e.jsx(Zn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Gn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Vs,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx($i,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ri,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Xn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Bd=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function Kd(){return e.jsxs(Ws,{icon:e.jsx(Yn,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.8.23"]}),children:[e.jsx(ot,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(ot,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:$d.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-bg-secondary text-text-secondary border border-border-subtle",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(ot,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:pa.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:xa.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:fa.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(ot,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Dd.map(t=>e.jsxs("div",{className:"rounded-xl border border-accent-primary/20 bg-accent-primary/5 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(ot,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-accent-primary text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Bd.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(Er,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"mx-auto h-12 w-12 opacity-80"}),title:"Cloud is optional, not required",description:"You can stay fully local in standalone, and move to cloud later without changing how you use the dashboard.",action:e.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm no-underline",children:"Compare Cloud ↗"}),e.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(Yi,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Wd(){const{ides:t}=Zt(),s=t.find(f=>f.type==="adhdev-daemon"),r=(s==null?void 0:s.detectedIdes)||[],{sendCommand:n}=Pt(),{userName:i}=Zt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const u=f=>{const b=f.target.value.trim();s!=null&&s.id&&b!==i&&n(s.id,"set_user_name",{userName:b}).catch(console.error)},[d,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(Ws,{icon:e.jsx(zs,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(cc,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(ot,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.8.23"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(ot,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:r.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:r.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(ot,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(xc,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(ot,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(yc,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Theme"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose a preset or create a custom surface, accent, and chat palette for the standalone UI."}),e.jsx(Pc,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Mobile"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose whether phones open the dashboard as a chat app first or in the full workspace layout."}),e.jsx(Rc,{})]})]})}),e.jsx(ot,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(fc,{}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gi,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:d,onChange:l})]})}),e.jsx(ot,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:f=>c(f.target.value),onBlur:u,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}pc();_c();Cc();const Od=Vn({baseUrl:""});function Wn(){const{ides:t,initialLoaded:s}=Zt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const r=t.find(n=>n.daemonMode||n.type==="adhdev-daemon");return r?e.jsx(xr,{to:`/machines/${r.id}`,replace:!0}):e.jsx(xr,{to:"/dashboard",replace:!0})}function Ud(){return e.jsx(ji,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Mi,{client:Od,children:e.jsx(Ld,{children:e.jsx(Li,{value:{sendCommand:Es,sendData:()=>!1},children:e.jsx(Ed,{children:e.jsxs(ki,{children:[e.jsx(At,{path:"/dashboard",element:e.jsx(ld,{})}),e.jsx(At,{path:"/machine",element:e.jsx(Wn,{})}),e.jsx(At,{path:"/machines/:id",element:e.jsx(kd,{})}),e.jsx(At,{path:"/machines",element:e.jsx(Wn,{})}),e.jsx(At,{path:"/capabilities",element:e.jsx(Nd,{})}),e.jsx(At,{path:"/about",element:e.jsx(Kd,{})}),e.jsx(At,{path:"/settings",element:e.jsx(Wd,{})}),e.jsx(At,{path:"*",element:e.jsx(xr,{to:"/dashboard",replace:!0})})]})})})})})})}Eo({connectionManager:It});Ni(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Ud,{})}));
55
+ `})]})}function Nd(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[r,n]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const u=[],d=[],x=[],l=[];Object.values(c.providers||{}).forEach(b=>{const p={name:b.name||"Unknown",status:b.status||"Stable",details:b.details||"Community Provider"};b.category==="ide"?u.push(p):b.category==="cli"?d.push(p):b.category==="extension"?x.push(p):b.category==="acp"&&l.push(p)});const f=(b,p)=>{const S={Stable:1,Beta:2,WIP:3},m=S[b.status]||99,h=S[p.status]||99;return m!==h?m-h:b.name.localeCompare(p.name)};s({ide:u.sort(f),cli:d.sort(f),ext:x.sort(f),acp:l.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>n(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Xn,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Fs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx(Cr,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((u,d)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:u.name}),e.jsx("td",{className:"py-3 px-4",children:i(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},d))})]})});return r?e.jsx(Ws,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Bs,{}),widthClassName:"max-w-5xl",children:e.jsx(Er,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(Ws,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Bs,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(ot,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(ot,{title:"IDE support",icon:e.jsx(ct,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(ot,{title:"Standalone CLI agents",icon:e.jsx(Ir,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(ot,{title:"AI extensions",icon:e.jsx(Ot,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(ot,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ot,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class Sd{constructor(){tt(this,"adapters",new Map);tt(this,"states",new Map);tt(this,"runtimeListeners",new Map);tt(this,"screenshotCallbacks",new Map);tt(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const r of this.adapters.keys())if(r.startsWith("standalone"))return r}return null}register(s,r){this.adapters.set(s,r),this.states.set(s,r.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,r){this.states.set(s,r)}retryConnection(s){}get(s){const r=this.resolveDaemonId(s);return r?this.adapters.get(r):void 0}getState(s){const r=this.resolveDaemonId(s);return r&&this.states.get(r)||"disconnected"}sendData(s,r){return!1}sendPtyInput(s,r,n){return!1}sendPtyResize(s,r,n,i){return!1}onScreenshot(s,r){return this.screenshotCallbacks.set(s,r),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,r){this.screenshotCallbacks.forEach(n=>n(s,r))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,r){this.statusCallbacks.forEach(n=>n(s,r))}emitRuntimeSnapshot(s,r,n=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:n,text:r,truncated:i})}emitSessionOutput(s,r,n){!s||typeof r!="string"||!r||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof n=="number"?{seq:n}:{},data:r})}onRuntimeEvent(s,r){const n=this.runtimeListeners.get(s)||new Set;return n.add(r),this.runtimeListeners.set(s,n),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(r),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,r){if(!r)return;const n=await fetch(`/api/v1/runtime/${encodeURIComponent(r)}/snapshot`);if(!n.ok)return;const i=await n.json();this.emitRuntimeEvent(r,{type:"runtime_snapshot",sessionId:r,seq:typeof i.seq=="number"?i.seq:0,text:typeof i.text=="string"?i.text:"",truncated:!!i.truncated,cols:typeof i.cols=="number"?i.cols:void 0,rows:typeof i.rows=="number"?i.rows:void 0})}emitRuntimeEvent(s,r){var n;(n=this.runtimeListeners.get(s))==null||n.forEach(i=>i(r))}}const It=new Sd;function Cd(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,n=new URLSearchParams(window.location.search).get("token");return n?`${s}?token=${encodeURIComponent(n)}`:s}const Dn=Cd(),Bn=3e3,Id=3e4;let Tt=null,Td=0;const Us=new Map;let Et=null,ls=null;function Kn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function Ad(t){return t==="connected"?"connected":t}async function Es(t,s,r){const n=qo(t,r||{}),i=Tt;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++Td}_${Date.now()}`;return new Promise((c,u)=>{const d=setTimeout(()=>{Us.delete(o),u(new Error(`WS command timeout: ${s}`))},3e4);Us.set(o,{resolve:x=>{clearTimeout(d),c(x)},reject:x=>{clearTimeout(d),u(x)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:n.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class _d{constructor(s){tt(this,"daemonId");tt(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Tt==null?void 0:Tt.readyState)===WebSocket.OPEN}get connectionState(){return(Tt==null?void 0:Tt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,r){return Es(this.daemonId,s,r)}async sendInput(s,r){return Es(this.daemonId,"cdp_remote_action",{action:s,params:r,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Et&&(clearInterval(Et),Et=null);const r=async()=>{if(this.hasCommandChannel)try{const n=await Es(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(n!=null&&n.success&&(n!=null&&n.base64)){const i=await fetch(`data:image/jpeg;base64,${n.base64}`).then(o=>o.blob());It.emitScreenshot(this.daemonId,i)}}catch{}};r(),Et=setInterval(r,2e3)}stopScreenshots(s){Et&&(clearInterval(Et),Et=null)}}let bt=null;function Md(t){return(!bt||bt.daemonId!==t)&&(bt=new _d(t)),bt}function Pd({children:t}){const s=a.useRef(Yr()),r=Yr();s.current=r;const{setUserName:n}=Zt(),i=a.useRef(n);i.current=n;const[,o]=a.useState("disconnected"),c=a.useCallback((b,p)=>{o(b),ls==null||ls(b,p)},[]),u=a.useRef(null),d=a.useRef(),x=a.useRef(Bn),l=a.useRef(!0),f=a.useRef(!1);return a.useEffect(()=>{l.current=!0,f.current=!1;function b(){var m,h;if(!l.current||((m=u.current)==null?void 0:m.readyState)===WebSocket.OPEN||((h=u.current)==null?void 0:h.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${Dn}...`);let S;try{S=new WebSocket(Dn)}catch(y){console.error("[Standalone WS] Failed to create WebSocket:",y),p();return}u.current=S,S.onopen=()=>{if(!l.current){S.close();return}c("connected"),x.current=Bn,console.log("[Standalone WS] Connected")},Tt=S,S.onmessage=y=>{var g;try{const v=JSON.parse(y.data);if((v.type==="command_result"||v.type==="error")&&v.requestId){const K=Us.get(v.requestId);K&&(Us.delete(v.requestId),v.type==="error"?K.reject(new Error(((g=v.data)==null?void 0:g.message)||"Command failed")):K.resolve(v.data));return}if(v.type==="session_output"){const K=v.sessionId||v.cliId||v.cliType;K&&It.emitSessionOutput(K,typeof v.data=="string"?v.data:"",typeof v.seq=="number"?v.seq:void 0);return}if(v.type==="runtime_snapshot"){It.emitRuntimeSnapshot(v.sessionId,typeof v.text=="string"?v.text:"",typeof v.seq=="number"?v.seq:0,!!v.truncated);return}if(v.type==="status"||v.type==="initial_state"){const K=v.data;if(!K)return;const{injectEntries:N,markLoaded:j}=s.current,k=K.id||"standalone",w=Md(k);It.register(k,w),It.setState(k,"connected"),c("connected",k),It.emitStatus(k,K);const L=Fo(K,{daemonId:k});Kn("ws_status",{type:v.type,daemonId:k,sessions:(K.sessions||[]).map(M=>({id:M.id,parentId:M.parentId,providerType:M.providerType,kind:M.kind,transport:M.transport,unread:M.unread,inboxBucket:M.inboxBucket,lastSeenAt:M.lastSeenAt,lastUpdated:M.lastUpdated,title:M.title})),recentLaunches:(K.recentLaunches||[]).map(M=>({id:M.id,providerType:M.providerType,kind:M.kind,workspace:M.workspace,lastLaunchedAt:M.lastLaunchedAt}))}),Kn("entries",{daemonId:k,entries:L.filter(M=>M.type!=="adhdev-daemon").map(M=>({id:M.id,type:M.type,unread:M.unread,inboxBucket:M.inboxBucket,lastSeenAt:M.lastSeenAt,lastUpdated:M.lastUpdated,sessionId:M.sessionId}))}),L.length>0&&N(L,{authoritativeDaemonIds:[k]}),j(),K.userName&&i.current&&i.current(K.userName)}}catch(v){console.error("[Standalone WS] Parse error:",v)}},S.onclose=()=>{l.current&&(bt==null||bt.stopScreenshots(),bt&&It.setState(bt.daemonId,"disconnected"),c("disconnected"),u.current=null,p())},S.onerror=y=>{f.current||!l.current||console.warn("[Standalone WS] Error, will reconnect:",y)}}function p(){if(!l.current)return;clearTimeout(d.current);const S=x.current;console.log(`[Standalone WS] Reconnecting in ${S}ms...`),d.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,Id),b()},S)}return b(),()=>{l.current=!1,f.current=!0,clearTimeout(d.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Tt=null),bt&&(bt.stopScreenshots(),It.unregister(bt.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Ld({children:t}){const[s,r]=a.useState("disconnected"),[n,i]=a.useState(null);a.useEffect(()=>(ls=(c,u)=>{r(c),u&&i(u)},()=>{ls=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",u=Ad(s),d={};return n&&(d[n]=u),d.standalone=u,{wsStatus:s,isConnected:c,connectionStates:d}},[s,n]);return e.jsx(Ti,{connectionOverrides:o,children:e.jsx(Pd,{children:t})})}const Rd=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Gn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ds,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(zs,{}),label:"Settings"}];function Ed({children:t}){const s=ts(),r=kr(),[n,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=l=>{s(l),i(!1)},d=()=>{c(l=>{const f=!l;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=l=>`nav-item${r.pathname.startsWith(l)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${n?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),n&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:l=>l.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${n?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Rd.map(l=>e.jsxs("div",{className:x(l.path),id:`nav-${l.id}`,onClick:()=>u(l.path),title:o?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!o&&l.label]},l.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Bs,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${r.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Yn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.24"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:d,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const $d=[{icon:e.jsx(Ds,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Nt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Jn,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(ct,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ot,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Bs,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Dd=[{icon:e.jsx(Zn,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Gn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Vs,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx($i,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ri,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Xn,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Bd=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function Kd(){return e.jsxs(Ws,{icon:e.jsx(Yn,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.8.24"]}),children:[e.jsx(ot,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(ot,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:$d.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-bg-secondary text-text-secondary border border-border-subtle",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(ot,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:pa.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:xa.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:fa.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(ot,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Dd.map(t=>e.jsxs("div",{className:"rounded-xl border border-accent-primary/20 bg-accent-primary/5 px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent-primary/10 text-accent-primary",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(ot,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-accent-primary text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Bd.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(Er,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"mx-auto h-12 w-12 opacity-80"}),title:"Cloud is optional, not required",description:"You can stay fully local in standalone, and move to cloud later without changing how you use the dashboard.",action:e.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm no-underline",children:"Compare Cloud ↗"}),e.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(Yi,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Wd(){const{ides:t}=Zt(),s=t.find(f=>f.type==="adhdev-daemon"),r=(s==null?void 0:s.detectedIdes)||[],{sendCommand:n}=Pt(),{userName:i}=Zt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const u=f=>{const b=f.target.value.trim();s!=null&&s.id&&b!==i&&n(s.id,"set_user_name",{userName:b}).catch(console.error)},[d,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(Ws,{icon:e.jsx(zs,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(cc,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(ot,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.8.24"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(ot,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:r.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:r.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(ot,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(xc,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(ot,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(yc,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Theme"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose a preset or create a custom surface, accent, and chat palette for the standalone UI."}),e.jsx(Pc,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Mobile"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose whether phones open the dashboard as a chat app first or in the full workspace layout."}),e.jsx(Rc,{})]})]})}),e.jsx(ot,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(fc,{}),e.jsx(Mt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gi,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:d,onChange:l})]})}),e.jsx(ot,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ei,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:f=>c(f.target.value),onBlur:u,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}pc();_c();Cc();const Od=Vn({baseUrl:""});function Wn(){const{ides:t,initialLoaded:s}=Zt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const r=t.find(n=>n.daemonMode||n.type==="adhdev-daemon");return r?e.jsx(xr,{to:`/machines/${r.id}`,replace:!0}):e.jsx(xr,{to:"/dashboard",replace:!0})}function Ud(){return e.jsx(ji,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Mi,{client:Od,children:e.jsx(Ld,{children:e.jsx(Li,{value:{sendCommand:Es,sendData:()=>!1},children:e.jsx(Ed,{children:e.jsxs(ki,{children:[e.jsx(At,{path:"/dashboard",element:e.jsx(ld,{})}),e.jsx(At,{path:"/machine",element:e.jsx(Wn,{})}),e.jsx(At,{path:"/machines/:id",element:e.jsx(kd,{})}),e.jsx(At,{path:"/machines",element:e.jsx(Wn,{})}),e.jsx(At,{path:"/capabilities",element:e.jsx(Nd,{})}),e.jsx(At,{path:"/about",element:e.jsx(Kd,{})}),e.jsx(At,{path:"/settings",element:e.jsx(Wd,{})}),e.jsx(At,{path:"*",element:e.jsx(xr,{to:"/dashboard",replace:!0})})]})})})})})})}Eo({connectionManager:It});Ni(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(Ud,{})}));