@adhdev/daemon-standalone 0.8.6 → 0.8.8

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,62 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-PD6SznsC.js","assets/vendor-CPghmr9Y.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
- var fa=Object.defineProperty;var ha=(t,s,n)=>s in t?fa(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Be=(t,s,n)=>ha(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as Vn,a as qn,b as ba,c as ga,u as kt,R as Ds,t as ya,d as va,e as ja,D as wa,f as ka,g as Na,h as Bs,i as Sa,k as Ca,B as Ia,l as Ma,m as at,N as Ms,n as _a}from"./vendor-CPghmr9Y.js";import{_ as Ta}from"./terminal-PD6SznsC.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"]'))r(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"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(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 r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const Gn=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}),Yn=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function an(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.childSessions)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function gs(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},i=s.version??n.version??t.version,o=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(r.version=i),o&&(r.serverVersion=o),i&&o&&i===o?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(r.versionMismatch=!0),r)}function Aa(t,s,n){var l,f,u,m,h,p,y;const r=Date.now(),i=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(s.length===0)return t.map(x=>({...x,_lastUpdate:r}));const o=new Map;for(const x of s)o.set(x.id,x);for(const x of t){const k=o.get(x.id);if(!k){o.set(x.id,{...x,_lastUpdate:r});continue}const b=an(x),g=an(k);if(b>g){const j=(l=x.chats)!=null&&l.length?x.chats:k.chats,S=gs(k,x,{...k,...x,chats:j,_lastUpdate:r});o.set(x.id,S)}else if(b<g){const j={};if(x.status&&x.status!==k.status&&(j.status=x.status),x.cdpConnected!==void 0&&(j.cdpConnected=x.cdpConnected),(f=x.chats)!=null&&f.length&&!((u=k.chats)!=null&&u.length)&&(j.chats=x.chats),x.machineNickname!==void 0&&x.machineNickname!==k.machineNickname&&(j.machineNickname=x.machineNickname),x.version!==void 0&&(j.version=x.version),x.serverVersion!==void 0&&(j.serverVersion=x.serverVersion),x.versionMismatch===!0&&(j.versionMismatch=!0),Object.keys(j).length>0){const S=gs(k,x,{...k,...j,_lastUpdate:k._lastUpdate});o.set(x.id,S)}}else{const j=x.timestamp||r,S=k._lastUpdate||k.timestamp||0;if(j>=S){const v=(m=x.chats)!=null&&m.length?x.chats:k.chats,M=gs(k,x,{...k,...x,chats:v,_lastUpdate:r});o.set(x.id,M)}else(h=x.chats)!=null&&h.length&&!((p=k.chats)!=null&&p.length)&&o.set(x.id,{...k,chats:x.chats})}}const c=new Set(t.map(x=>x.id)),d=new Set;for(const x of t){const k=x.daemonId||((y=x.id)==null?void 0:y.split(":")[0]);k&&d.add(k)}for(const[x,k]of o){const b=k.daemonId||x.split(":")[0];if(!d.has(b))continue;if(i.has(b)&&!c.has(x)){o.delete(x);continue}const g=r-(k._lastUpdate||k.timestamp||0);(k.transport==="pty"&&!c.has(x)&&g>1e4||k.transport==="acp"&&!c.has(x)&&g>1e4||k.transport==="cdp-page"&&!c.has(x)&&g>3e4)&&o.delete(x)}for(const[x,k]of o)r-(k._lastUpdate||k.timestamp||0)>3e5&&k.status!=="online"&&o.delete(x);return Array.from(o.values())}function Ra(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function La({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState(!1),[c,d]=a.useState([]),[l,f]=a.useState(void 0),u=a.useRef(n);a.useEffect(()=>{u.current=n},[n]);const m=a.useCallback((b,g)=>{r(j=>{let S=!1;const v=j.map(M=>M.id!==b||M.chats===g?M:(S=!0,{...M,chats:g}));return S?v:j})},[]),h=a.useCallback((b,g)=>{r(j=>{const S=j.length===0?b:Aa(b,j,g);return Ra(j,S)?j:S})},[]),p=a.useCallback(()=>o(!0),[]),y=a.useMemo(()=>({injectEntries:h,markLoaded:p,getIdes:()=>u.current}),[h,p]),x=s,k=a.useMemo(()=>({ides:n,updateIdeChats:m,initialLoaded:i,toasts:c,setToasts:d,wsStatus:(x==null?void 0:x.wsStatus)??"connected",isConnected:(x==null?void 0:x.isConnected)??!0,connectionStates:(x==null?void 0:x.connectionStates)??{},connectionTransports:(x==null?void 0:x.connectionTransports)??{},showReconnected:(x==null?void 0:x.showReconnected)??!1,retryConnection:x==null?void 0:x.retryConnection,isP2PActive:(x==null?void 0:x.isP2PActive)??!1,p2pStates:(x==null?void 0:x.p2pStates)??{},userRole:x==null?void 0:x.userRole,userName:l,setUserName:f}),[n,m,i,c,x==null?void 0:x.wsStatus,x==null?void 0:x.isConnected,x==null?void 0:x.connectionStates,x==null?void 0:x.connectionTransports,x==null?void 0:x.showReconnected,x==null?void 0:x.retryConnection,x==null?void 0:x.isP2PActive,x==null?void 0:x.p2pStates,x==null?void 0:x.userRole,l]);return e.jsx(Yn.Provider,{value:y,children:e.jsx(Gn.Provider,{value:k,children:t})})}function Rt(){return a.useContext(Gn)}function on(){return a.useContext(Yn)}function Xn(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function i(d){return d.startsWith("http")?d:`${s}${d.startsWith("/")?"":"/"}${d}`}function o(d){const l=n==null?void 0:n(),f=i(d),u=d.startsWith("http")?new URL(f):new URL(f,typeof window<"u"?window.location.origin:"http://localhost");return l&&u.searchParams.set("token",l),!d.startsWith("http")&&!s?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function c(d,l={}){const f={"Content-Type":"application/json",...l.headers||{}},u=n==null?void 0:n();u&&(f.Authorization=`Bearer ${u}`);const m=i(d),h=await fetch(m,{...l,headers:f});if(h.status===401)throw r==null||r(),new Error("Unauthorized");if(!h.ok){const p=await h.json().catch(()=>({error:h.statusText}));throw new Error(p.error||`API Error: ${h.status}`)}return h.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:d=>c(`/api/v1/daemons/${d}/status`),sendCommand:(d,l,f={})=>c(`/api/v1/daemons/${d}/command`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),execTerminal:(d,l,f)=>c(`/api/v1/daemons/${d}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:f})}),sendAgentMessage:(d,l,f)=>c(`/api/v1/shortcuts/${d}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:f})}),getAgentStatus:d=>c(`/api/v1/shortcuts/${d}/status`),approveAgent:(d,l,f)=>c(`/api/v1/shortcuts/${d}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:f?"approve":"reject"})}),getMuxState:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/state`),getMuxSocketInfo:d=>c(`/api/v1/mux/${encodeURIComponent(d)}/socket-info`),controlMux:(d,l,f={})=>c(`/api/v1/mux/${encodeURIComponent(d)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:f})}),getMuxEventsUrl:d=>o(`/api/v1/mux/${encodeURIComponent(d)}/events`),getRuntimeEventsUrl:d=>o(`/api/v1/runtime/${encodeURIComponent(d)}/events`),request:c}}const Pa=Xn({baseUrl:"http://localhost:3847"}),$a=a.createContext(Pa);function Ea({client:t,children:s}){return e.jsx($a.Provider,{value:t,children:s})}const Da={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Zn=a.createContext(Da);function Ba({value:t,children:s}){return e.jsx(Zn.Provider,{value:t,children:s})}function ct(){return a.useContext(Zn)}const Ne={size:18};function Jn({size:t=Ne.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 Ks({size:t=Ne.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 ts({size:t=Ne.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 Ka({size:t=Ne.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 Wa({size:t=Ne.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 Oa({size:t=Ne.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 ss({size:t=Ne.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 za({size:t=Ne.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 ds({size:t=Ne.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 Qn({size:t=Ne.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 er({size:t=Ne.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 rt({size:t=Ne.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 Fe({size:t=Ne.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 Ws({size:t=Ne.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 Ua({size:t=Ne.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 Lt({size:t=Ne.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 Os({size:t=Ne.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 zs({size:t=Ne.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 mt({size:t=Ne.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 tr({size:t=Ne.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 Ha({size:t=Ne.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 sr({size:t=Ne.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 Fa({size:t=Ne.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 Us({size:t=Ne.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 nr({size:t=Ne.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 jt({size:t=Ne.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 rr({size:t=Ne.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 Va({size:t=Ne.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 qa({size:t=Ne.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 Ga({size:t=Ne.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 us({size:t=Ne.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 Ya({size:t=Ne.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 Xa({size:t=Ne.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 Za({size:t=Ne.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 Ja({size:t=Ne.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 Qa(t){var l,f;const s=u=>u.replace(/^\d+;/,"").replace(/\u0007/g,"").trim(),r=t.split(`
3
- `).map(u=>{if(!u.includes("\r"))return u;const m=u.split("\r").map(y=>y.trim()).filter(Boolean);if(m.length===0)return"";const h=m.filter(y=>y.startsWith("⏺"));if(h.length>0)return h[h.length-1];const p=m.filter(y=>!(/^[❯›>]\s*$/.test(y)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(y)&&y.length<40||/^[╭╰│├╮╯─═]+$/.test(y)));return p.length>0?p[p.length-1]:m[m.length-1]}).join(`
4
- `).split(`
5
- `),i={},o=[];let c=!1;for(const u of r){const m=s(u);if(m===""){c=!1,o.push("");continue}if(/^❯\s*$/.test(m)||/^>\s*$/.test(m)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(m)||/^◐\s/.test(m)||/\/effort/.test(m)||/^⎿\s+(Tip|Note|Hint):/.test(m)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(m)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(m)||/Brewing[…\.]{0,3}\s*\d*$/i.test(m)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(m)||/^Auto-updating/i.test(m)||/^✳\s*Debug (?:Claude Code|Codex) CLI/i.test(m)||/^(?:─|═|╭|╰|│|├|╮|╯|┌|┐|└|┘|┬|┴|┼)+$/.test(m))continue;if(/^[⏺●·⏵]/.test(u)){const p=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(p)i[p[1]]=(i[p[1]]||0)+1;else{const y=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);y&&(i[y]=(i[y]||0)+1)}c=!0;continue}if(/^(?:Bash|Read|Write|Edit|MultiEdit|Task|Glob|Grep|LS|NotebookEdit|Exact output)(?:\(|:)/.test(m)){const p=((f=(l=m.match(/^([A-Za-z][A-Za-z0-9_ ]+)/))==null?void 0:l[1])==null?void 0:f.trim())||"Tool";i[p]=(i[p]||0)+1,c=!0;continue}if(/^Read\s+\d+\s+files?(?:\s+\(.*\))?$/i.test(m)){i.Read=(i.Read||0)+1,c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(m)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||c&&/^\s{2,}/.test(u))continue;c=!1;const h=m.replace(/^❯\s+/,"");o.push(h)}const d=o.join(`
6
- `).replace(/\n{3,}/g,`
7
-
8
- `).trim();return{toolCounts:i,textContent:d,hasTools:Object.keys(i).length>0}}function _s(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function ei(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function yt(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(o=>(o==null?void 0:o.text)||"").join(`
9
- `):String(n.content||"");return[n.id?`id:${n.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",typeof n.index=="number"?`msgIndex:${n.index}`:"",n.timestamp?`ts:${n.timestamp}`:"",n.role?`role:${n.role}`:"",r?`content:${r.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const cn=700,ti=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Vn,{remarkPlugins:[qn],children:s.text}),e.jsx("span",{className:"action-time",children:_s(s.timestamp)})]})},(t,s)=>t.log===s.log),si=a.memo(function({message:s,receivedAt:n,agentName:r,userName:i,isCliMode:o,isExpanded:c,isTextExpanded:d,onToggleExpanded:l,onToggleTextExpanded:f}){var S;const u=(s.role||"").toLowerCase(),m=u==="user"||u==="human",h=s.kind||(u==="tool"?"tool":"standard"),p=typeof s.content=="string"?s.content:(s.content||[]).map(v=>v.text||"").join(`
10
- `);if(h==="thought"){const v=((S=s.meta)==null?void 0:S.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(qa,{size:13}),e.jsx("span",{children:v})]}),e.jsx("div",{className:"chat-msg-body",children:p})]})}if(h==="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:p.split(`
11
- `)[0].slice(0,80)})]});if(h==="terminal"){const v=s.meta||{},M=v.isRunning?"⏳":"✅",w=v.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:M}),e.jsx("span",{children:w})]}),e.jsx("pre",{className:"chat-msg-body",children:p})]})}if(h==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:p.slice(0,100)});const y=!m&&o?Qa(p):null,x=y?y.textContent:p,k=y?Object.entries(y.toolCounts):[],b=o&&!m&&!c&&x.length>cn,g=c?p:b&&!d?x.slice(0,cn):x,j=ei(g);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${m?"self-end":"self-start"}`,children:[k.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[k.map(([v,M])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",v,M>1?` ×${M}`:""]},v)),(y==null?void 0:y.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!x&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:_s(n)})]}),(x||m)&&e.jsxs("div",{className:`chat-bubble ${m?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${x?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:m?i||"You":s.senderName||r}),n!=null&&e.jsx("span",{className:"chat-time",children:_s(n)})]}),x&&e.jsx("div",{className:"chat-markdown",children:j?e.jsx(Vn,{remarkPlugins:[qn,ba,ga],children:g}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:g})}),b&&e.jsx("button",{onClick:f,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:d?"Collapse ↑":`Show more (${Math.round(x.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.isExpanded===s.isExpanded&&t.isTextExpanded===s.isTextExpanded),ni=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:l={},emptyState:f,onLoadMore:u,isLoadingMore:m,hasMoreHistory:h,hiddenLiveCount:p=0,loadError:y},x){var F;const k=a.useRef(null),b=a.useRef(null),g=a.useRef(null),j=a.useRef(0),S=a.useRef(""),v=a.useRef(!1),M=a.useRef(null),w=a.useRef(!1),N=a.useRef(null),$=a.useRef(!1),[R,E]=a.useState(new Set),[L,_]=a.useState(new Set),I=a.useRef(!1),U=()=>{const q=k.current;return q?q.scrollHeight-q.scrollTop-q.clientHeight<200:!0},P=a.useCallback((q="auto")=>{const V=k.current;V&&V.scrollTo({top:V.scrollHeight,behavior:q})},[]),z=a.useCallback(()=>{var oe;const q=k.current,V=(oe=window.getSelection)==null?void 0:oe.call(window);if(!q||!V||V.rangeCount===0||V.isCollapsed){$.current=!1;return}const pe=V.anchorNode,de=V.focusNode;$.current=!!(pe&&de&&q.contains(pe)&&q.contains(de))},[]),T=a.useCallback((q="auto")=>{M.current!=null&&cancelAnimationFrame(M.current),M.current=requestAnimationFrame(()=>{M.current=null,P(q)})},[P]),B=s.length>0?`${s.length}:${(((F=s[s.length-1])==null?void 0:F.content)||"").length}`:"0:0";a.useEffect(()=>{const q=!v.current,V=S.current!==d;if(S.current=d,q||V){v.current=!0,I.current=!1,w.current=!0,$.current||T("auto"),j.current=s.length;return}s.length>j.current?!I.current&&!$.current&&T("auto"):U()&&!I.current&&!$.current&&T("auto"),j.current=s.length},[B,d,c,s.length,T]),a.useEffect(()=>()=>{M.current!=null&&cancelAnimationFrame(M.current),N.current!=null&&window.clearTimeout(N.current)},[]),a.useEffect(()=>{const q=b.current;if(!q)return;const V=()=>{N.current!=null&&window.clearTimeout(N.current),N.current=window.setTimeout(()=>{w.current=!1,N.current=null},180)},pe=new ResizeObserver(()=>{w.current&&($.current||(T("auto"),V()))});return pe.observe(q),()=>{pe.disconnect(),N.current!=null&&(window.clearTimeout(N.current),N.current=null)}},[T,d]),a.useImperativeHandle(x,()=>({scrollToBottom:(q="smooth")=>{P(q)}}),[P]),a.useEffect(()=>{const q=k.current;if(!q)return;let V;const pe=()=>{clearTimeout(V),V=setTimeout(()=>{I.current=!U()},50)};return q.addEventListener("scroll",pe,{passive:!0}),()=>{q.removeEventListener("scroll",pe),clearTimeout(V)}},[]),a.useEffect(()=>(document.addEventListener("selectionchange",z),()=>document.removeEventListener("selectionchange",z)),[z]);const O=a.useRef(0),D=a.useRef(!1);a.useEffect(()=>{const q=k.current;if(!q||!D.current||O.current===0)return;const V=q.scrollHeight-O.current;V>0&&(q.scrollTop=V),O.current=0,D.current=!1},[s.length]);const X=()=>{const q=k.current;q&&(O.current=q.scrollHeight),D.current=!0,u==null||u()},xe=a.useMemo(()=>{const q=s.map((oe,ue)=>({type:"message",data:oe,index:ue,ts:oe.receivedAt||l[yt(oe,ue)]||0}));if(!n||n.length===0)return q;const V=[...n].sort((oe,ue)=>oe.timestamp-ue.timestamp).map((oe,ue)=>({type:"action",data:oe,index:ue,ts:oe.timestamp})),pe=[];let de=0;for(const oe of q){for(;de<V.length&&oe.ts>0&&V[de].ts<oe.ts;)pe.push(V[de++]);pe.push(oe)}for(;de<V.length;)pe.push(V[de++]);return pe},[s,n,l]),ee=p>0||!!h,fe=p>0?`↑ Show ${Math.min(p,80)} earlier messages${p>80?` (${p} hidden)`:""}`:y?`↻ ${y}`:"↑ Load older messages";return e.jsx("div",{ref:k,"data-chat-scroll":!0,className:"chat-container",children:e.jsxs("div",{ref:b,className:"chat-container-content",children:[m&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),ee&&!m&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:X,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${y&&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:fe})}),xe.length===0&&!ee&&(f||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),xe.map(q=>{if(q.type==="action"){const se=q.data;return e.jsx(ti,{log:se},`action-${q.index}`)}const V=q.data,pe=q.index,de=yt(V,pe),oe=V.receivedAt||l[de],ue=`${d}-${de}`,ae=R.has(ue),ge=L.has(ue);return e.jsx(si,{message:V,receivedAt:oe,agentName:r,userName:i,isCliMode:o,isExpanded:ae,isTextExpanded:ge,onToggleExpanded:()=>E(se=>{const ce=new Set(se);return ae?ce.delete(ue):ce.add(ue),ce}),onToggleTextExpanded:()=>_(se=>{const ce=new Set(se);return ge?ce.delete(ue):ce.add(ue),ce})},`msg-${de}`)}),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:g})]})})}),ri=a.memo(ni,(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);let ln=!1;const ar=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},i)=>{const o=a.useRef(null),[c,d]=a.useState(null),l=a.useRef([]),f=a.useRef(!1),u=a.useRef(!1),m=a.useRef(!1),h=()=>{const p=o.current;if(p){f.current&&(p.clear(),f.current=!1);for(const y of l.current)p.write(y);l.current=[],u.current&&(p.fit(),u.current=!1),m.current&&(p.bumpResize(),m.current=!1)}};return a.useImperativeHandle(i,()=>({write:p=>{o.current?o.current.write(p):l.current.push(p)},clear:()=>{o.current?o.current.clear():(l.current=[],f.current=!0)},reset:()=>{o.current&&"reset"in o.current&&typeof o.current.reset=="function"?o.current.reset():(l.current=[],f.current=!0)},resize:(p,y)=>{o.current&&"resize"in o.current&&typeof o.current.resize=="function"&&o.current.resize(p,y)},fit:()=>{o.current?o.current.fit():u.current=!0},bumpResize:()=>{o.current?o.current.bumpResize():m.current=!0}}),[]),a.useEffect(()=>{if(!c)return;const p=requestAnimationFrame(()=>{h()});return()=>cancelAnimationFrame(p)},[c]),a.useEffect(()=>{let p=!1;return Ta(()=>import("./terminal-PD6SznsC.js").then(y=>y.i),__vite__mapDeps([0,1,2])).then(y=>{ln||(ln=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),p||d(()=>y.GhosttyTerminalView)}).catch(y=>{console.error("[CliTerminal] failed to load terminal renderer",y)}),()=>{p=!0}},[]),c?e.jsx(c,{ref:o,onInput:t,onResize:s,fontSize:n,readOnly:r,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"}})});ar.displayName="CliTerminal";function zt({label:t,value:s,sub:n,icon:r}){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:r}),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}),n&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function dn({value:t,max:s,label:n,color:r="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,d=c>85?"#ef4444":c>60?"var(--status-warning)":r;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:n}),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:d}})})]}):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:n}),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, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ai({cursorPos:t,viewportRef:s,imgRef:n}){var g;if(!t||!n.current)return null;const r=n.current,i=r.getBoundingClientRect(),o=(g=s.current)==null?void 0:g.getBoundingClientRect();if(!o)return null;const c=r.naturalWidth||i.width,d=r.naturalHeight||i.height,l=c/d,f=i.width/i.height;let u,m,h,p;l>f?(u=i.width,m=i.width/l,h=0,p=(i.height-m)/2):(m=i.height,u=i.height*l,h=(i.width-u)/2,p=0);const y=i.left-o.left+h+u*t.nx,x=i.top-o.top+p+m*t.ny,k=Math.max(8,Math.min(o.width-8,y)),b=Math.max(8,Math.min(o.height-8,x));return e.jsxs("div",{style:{position:"absolute",left:k-8,top:b-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 ii({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:i,setIsMenuOpen:o,imeText:c,setImeText:d,handleImeSubmit:l,isConnActive:f,zoom:u,isMobile:m,mobileFillZoom:h,onZoomOut:p,onZoomReset:y,onZoomIn:x,transportType:k,screenshotUsage:b,lastActionStatus:g}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:j=>j.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:()=>{r(j=>!j),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"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:"⌨️"})}),n&&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:j=>j.stopPropagation(),onChange:j=>d(j.target.value),onKeyDown:j=>{l(j)},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(j=>!j),r(!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:f?"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:f?"#22c55e":"#eab308",boxShadow:f?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:f?"#22c55e":"#eab308"},children:f?"Connected":"WS"})]}),u>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*100),"%"]}),k==="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"}),k==="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"}),b&&b.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:b.budgetExhausted?"#ef4444":"#c4b5fd",background:b.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:b.budgetExhausted?"TURN blocked":`TURN ${b.dailyUsedMinutes}/${b.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:j=>j.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: ",u<=(m?h:1)+.01?m?"FILL":"FIT":`${Math.round(u*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:j=>{j.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:j=>{j.stopPropagation(),y()},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:m?"FILL":"FIT"}),e.jsx("button",{onClick:j=>{j.stopPropagation(),x()},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 oi({waitingLabel:t,waitingHint:s,transportType:n}){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}),n==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function ci(){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 un(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 Et(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!ci())return;r.current+=1;const i=n.current;if(!i){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,d])=>[c,un(d)]))}),n.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}#${r.current}`,{changed:o,snapshot:Object.fromEntries(o.map(c=>[c,un(s[c])]))}),n.current=s})}function li({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:i,minZoom:o,zoomRef:c,panXRef:d,panYRef:l,setPanX:f,setPanY:u,setZoom:m,lastWheelTimeRef:h,onAction:p,setLastActionStatus:y,spawnRippleFromNormalized:x,clampPan:k,isMobile:b,mobileFillZoom:g}){const[j,S]=a.useState(null),v=a.useRef(null),M=a.useRef(null),w=a.useRef(null),N=a.useRef(!1),$=a.useRef(null),R=a.useRef(0),E=a.useRef(null),L=a.useRef(1),_=a.useRef({x:0,y:0}),I=a.useRef(!1),U=a.useRef(r),P=a.useRef(p),z=30,T=550,B=18,O=60,D=400,X=12,xe=()=>{if(v.current)return;const F={nx:.5,ny:.5};v.current=F,S(F)};return a.useEffect(()=>{U.current=r,r==="mouse"&&xe()},[r]),a.useEffect(()=>{P.current=p},[p]),a.useEffect(()=>{const F=t.current;if(!F)return;const q=ae=>{if(!n.current)return null;const ge=n.current.getBoundingClientRect();return!ge.width||!ge.height?null:{nx:Math.max(0,Math.min(1,(ae.clientX-ge.left)/ge.width)),ny:Math.max(0,Math.min(1,(ae.clientY-ge.top)/ge.height))}},V=(ae,ge)=>{if(!n.current)return{dnx:0,dny:0};const se=n.current,ce=se.getBoundingClientRect(),G=se.naturalWidth||ce.width,te=se.naturalHeight||ce.height,C=G/te,J=ce.width/ce.height;let Z,ne;return C>J?(Z=ce.width,ne=ce.width/C):(ne=ce.height,Z=ce.height*C),{dnx:ae/Z,dny:ge/ne}},pe=(ae,ge,se)=>{if(se<=1.05)return;const ce=-(ae-.5)*100,G=-(ge-.5)*100,te=k(ce,G,se);(Math.abs(te.x-d.current)>.1||Math.abs(te.y-l.current)>.1)&&(f(te.x),u(te.y),d.current=te.x,l.current=te.y)},de=ae=>{const ge=s.current;if(ge&&ae.target instanceof Node&&ge.contains(ae.target))ae.preventDefault();else return;if(ae.touches.length===1){const se=ae.touches[0];M.current={x:se.clientX,y:se.clientY,time:Date.now()},w.current={x:se.clientX,y:se.clientY},I.current||(N.current=!1),$.current=setTimeout(()=>{if(!N.current&&!I.current)if(N.current=!0,U.current==="mouse"){const ce=v.current||{nx:.5,ny:.5};y("Right Click"),x(ce.nx,ce.ny,"right"),P.current("input_click",{...ce,button:"right"}).catch(()=>{})}else{const ce=q(se);ce&&(y("Right Click"),x(ce.nx,ce.ny,"right"),P.current("input_click",{...ce,button:"right"}).catch(()=>{}))}},500);return}if(ae.touches.length===2){$.current&&clearTimeout($.current),N.current=!0,I.current=!0;const se=ae.touches[1].clientX-ae.touches[0].clientX,ce=ae.touches[1].clientY-ae.touches[0].clientY;E.current=Math.sqrt(se*se+ce*ce),L.current=c.current,_.current={x:(ae.touches[0].clientX+ae.touches[1].clientX)/2,y:(ae.touches[0].clientY+ae.touches[1].clientY)/2}}},oe=ae=>{const ge=s.current;if(ge&&ae.target instanceof Node&&ge.contains(ae.target)&&ae.preventDefault(),ae.touches.length===1&&w.current){const se=ae.touches[0],ce=se.clientX-w.current.x,G=se.clientY-w.current.y;if(!N.current&&M.current){const te=se.clientX-M.current.x,C=se.clientY-M.current.y;Math.sqrt(te*te+C*C)>8&&(N.current=!0,$.current&&clearTimeout($.current))}if(N.current)if(U.current==="mouse"){const te=V(ce,G),C=v.current||{nx:.5,ny:.5},J=Math.max(0,Math.min(1,C.nx+te.dnx)),Z=Math.max(0,Math.min(1,C.ny+te.dny));v.current={nx:J,ny:Z},S({nx:J,ny:Z}),y(`Cursor: ${Math.round(J*100)}%, ${Math.round(Z*100)}%`),pe(J,Z,c.current);const ne=Date.now();ne-h.current>=30&&(h.current=ne,P.current("input_mouseMoved",{nx:J,ny:Z}).catch(()=>{}))}else if(c.current>1){const te=s.current;if(te){const C=te.clientWidth,J=te.clientHeight,Z=d.current+ce/C*100,ne=l.current+G/J*100,be=k(Z,ne,c.current);f(be.x),u(be.y),d.current=be.x,l.current=be.y}}else{const te=q(se);if(te){const C=Date.now();C-h.current>=40&&(h.current=C,y("Scroll"),P.current("input_wheel",{nx:te.nx,ny:te.ny,deltaX:Math.round(-ce*2.5),deltaY:Math.round(-G*2.5)}).catch(()=>{}))}}w.current={x:se.clientX,y:se.clientY};return}if(ae.touches.length===2&&E.current!==null){const se=ae.touches[1].clientX-ae.touches[0].clientX,ce=ae.touches[1].clientY-ae.touches[0].clientY,te=Math.sqrt(se*se+ce*ce)/E.current,C=(ae.touches[0].clientX+ae.touches[1].clientX)/2,J=(ae.touches[0].clientY+ae.touches[1].clientY)/2,Z=C-_.current.x,ne=J-_.current.y,be=Math.abs(te-1)>.03;if(U.current==="mouse"){if(be){const we=Math.max(o,Math.min(5,L.current*te));m(we),c.current=we}else if(Math.abs(Z)>2||Math.abs(ne)>2){const we=v.current||{nx:.5,ny:.5},Se=Date.now();Se-h.current>=30&&(h.current=Se,y("Scroll"),P.current("input_wheel",{nx:we.nx,ny:we.ny,deltaX:Math.round(-Z*3),deltaY:Math.round(-ne*3)}).catch(()=>{}))}}else{const we=Math.max(o,Math.min(5,L.current*te));m(we),c.current=we;const Se=s.current;if(Se&&we>1){const Te=Se.clientWidth,Ze=Se.clientHeight,Ke=d.current+Z/Te*100,ze=l.current+ne/Ze*100,We=k(Ke,ze,we);f(We.x),u(We.y),d.current=We.x,l.current=We.y}}_.current={x:C,y:J}}},ue=ae=>{var ge;if($.current&&clearTimeout($.current),E.current=null,ae.touches.length===1&&I.current){const se=ae.touches[0];M.current={x:se.clientX,y:se.clientY,time:Date.now()},w.current={x:se.clientX,y:se.clientY},N.current=!0;return}if(ae.touches.length===0){if(I.current){I.current=!1,N.current=!1;return}if(ae.changedTouches.length===1){const se=ae.changedTouches[0],ce=Date.now(),G=ce-(((ge=M.current)==null?void 0:ge.time)||0),te=M.current?se.clientX-M.current.x:0,C=M.current?se.clientY-M.current.y:0,J=Math.sqrt(te*te+C*C);if(U.current==="mouse"){if(G<z||G>T||J>B){N.current=!1;return}const Z=v.current||q(se);Z&&(y(`Click: ${Math.round(Z.nx*100)}%, ${Math.round(Z.ny*100)}%`),x(Z.nx,Z.ny,"left"),P.current("input_click",{...Z}).catch(()=>{}))}else{if(N.current){N.current=!1;return}if(G<O||G>D||J>X){N.current=!1;return}const Z=q(se);if(!Z)return;ce-R.current<300?(y("Double tap"),x(Z.nx,Z.ny,"double"),P.current("input_click",{...Z,clickCount:2}).catch(()=>{}),R.current=0):(y(`Tap: ${Math.round(Z.nx*100)}%, ${Math.round(Z.ny*100)}%`),x(Z.nx,Z.ny,"left"),P.current("input_click",{...Z}).catch(()=>{}),R.current=ce)}}N.current=!1}};return F.addEventListener("touchstart",de,{passive:!1}),F.addEventListener("touchmove",oe,{passive:!1}),F.addEventListener("touchend",ue,{passive:!1}),()=>{F.removeEventListener("touchstart",de),F.removeEventListener("touchmove",oe),F.removeEventListener("touchend",ue),$.current&&clearTimeout($.current)}},[t,s,n,o,c,d,l,f,u,m,h,y,x,k]),{cursorPos:j,cursorPosRef:v,handleToggleInputMode:()=>{i(F=>{const q=F==="touch"?"mouse":"touch";return q==="mouse"&&xe(),q})},handleZoomReset:()=>{const F=b?g:1;m(F),c.current=F,f(0),u(0),d.current=0,l.current=0}}}function ir({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),d=a.useRef(null),l=a.useRef(null),[f,u]=a.useState(null),[m,h]=a.useState(""),[,p]=a.useState(!1),[y,x]=a.useState([]),k=a.useRef(0),[b,g]=a.useState(!1),[j,S]=a.useState(!1),v=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[M,w]=a.useState(v?"mouse":"touch"),[N,$]=a.useState(1),R=a.useRef(!1),[E,L]=a.useState(1),[_,I]=a.useState(0),[U,P]=a.useState(0);Et("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:M,zoom:E,panX:_,panY:U,isMenuOpen:b,isImeOpen:j});const z=a.useRef(0),T=a.useRef(E),B=a.useRef(_),O=a.useRef(U);a.useEffect(()=>{T.current=E},[E]),a.useEffect(()=>{B.current=_},[_]),a.useEffect(()=>{O.current=U},[U]),a.useEffect(()=>{var G;(G=c.current)==null||G.focus()},[]);const D=n==="connected",X=r,xe=D?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=D?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!v||R.current||!X)return;const G=l.current,te=d.current;if(!G||!te)return;const C=()=>{const J=te.clientWidth,Z=te.clientHeight,ne=G.naturalWidth,be=G.naturalHeight;if(!ne||!be||!J||!Z)return;const we=Math.min(J/ne,Z/be),Te=Math.max(J/ne,Z/be)/we;Te>1.01&&($(Te),L(Te),T.current=Te),R.current=!0};G.complete&&G.naturalWidth?C():G.addEventListener("load",C,{once:!0})},[X,v]);const fe=.5;a.useEffect(()=>{E<=fe&&(I(0),P(0))},[E,fe]);const F=(G,te,C)=>{if(C<=fe)return{x:0,y:0};const J=(C-1)/(2*C)*100,Z=(C-1)/(2*C)*100;return{x:Math.max(-J,Math.min(J,G)),y:Math.max(-Z,Math.min(Z,te))}},q=(G,te)=>{if(!l.current)return null;const C=l.current.getBoundingClientRect();return!C.width||!C.height?null:{nx:Math.max(0,Math.min(1,(G-C.left)/C.width)),ny:Math.max(0,Math.min(1,(te-C.top)/C.height))}},V=(G,te,C)=>{const J=d.current;if(!J)return;const Z=J.getBoundingClientRect(),ne=++k.current;x(be=>[...be,{id:ne,x:G-Z.left,y:te-Z.top,type:C}]),setTimeout(()=>x(be=>be.filter(we=>we.id!==ne)),600)},pe=(G,te,C)=>{const J=l.current,Z=d.current;if(!J||!Z)return;const ne=J.getBoundingClientRect(),be=Z.getBoundingClientRect(),we=J.naturalWidth||ne.width,Se=J.naturalHeight||ne.height,Te=we/Se,Ze=ne.width/ne.height;let Ke,ze,We,De;Te>Ze?(Ke=ne.width,ze=ne.width/Te,We=0,De=(ne.height-ze)/2):(ze=ne.height,Ke=ne.height*Te,We=(ne.width-Ke)/2,De=0);const re=ne.left-be.left+We+Ke*G,ke=ne.top-be.top+De+ze*te,je=++k.current;x(ye=>[...ye,{id:je,x:re,y:ke,type:C}]),setTimeout(()=>x(ye=>ye.filter(W=>W.id!==je)),600)},de=async G=>{var C;const te=q(G.clientX,G.clientY);if(te){u(`Click: ${Math.round(te.nx*100)}%, ${Math.round(te.ny*100)}%`),V(G.clientX,G.clientY,"left"),(C=c.current)==null||C.focus();try{const J=await t("input_click",{nx:te.nx,ny:te.ny});J!=null&&J.success||s(`❌ Click failed: ${J==null?void 0:J.error}`)}catch(J){s(`❌ Click error: ${J.message||J}`)}}},oe=async(G,te,C,J=0)=>{try{await t("input_key",{type:C?"char":"keyDown",key:G,code:te,text:C?G:void 0,unmodifiedText:C?G:void 0,modifiers:J})}catch(Z){s(`❌ Key error: ${Z.message||Z}`)}},ue=async G=>{if(G.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(G.key)&&G.preventDefault();let C=0;G.altKey&&(C|=1),G.ctrlKey&&(C|=2),G.metaKey&&(C|=4),G.shiftKey&&(C|=8),u(`Key: ${G.key}`),await oe(G.key,G.code,G.key.length===1,C)},ae=async G=>{if(G.key==="Enter"){if(G.nativeEvent.isComposing)return;if(m){const te=m;h(""),u(`IME Sent: ${te}`);try{const C=await t("input_type",{text:te});C!=null&&C.success||s(`❌ IME error: ${C==null?void 0:C.error}`)}catch(C){s(`❌ IME error: ${C.message}`)}}else u("Key: Enter"),await oe("Enter","Enter",!1)}};a.useEffect(()=>{const G=c.current;if(!G)return;const te=C=>{var J;if((J=l.current)!=null&&J.contains(C.target)){C.preventDefault();const Z=Date.now();if(Z-z.current<40)return;z.current=Z;const ne=q(C.clientX,C.clientY);if(!ne)return;u(`Scroll: ${Math.round(C.deltaY)}`),t("input_wheel",{nx:ne.nx,ny:ne.ny,deltaX:Math.round(C.deltaX),deltaY:Math.round(C.deltaY)}).catch(()=>{})}};return G.addEventListener("wheel",te,{passive:!1}),()=>G.removeEventListener("wheel",te)},[t]);const{cursorPos:ge,handleToggleInputMode:se,handleZoomReset:ce}=li({containerRef:c,viewportRef:d,imgRef:l,inputMode:M,setInputMode:w,minZoom:fe,zoomRef:T,panXRef:B,panYRef:O,setPanX:I,setPanY:P,setZoom:L,lastWheelTimeRef:z,onAction:t,setLastActionStatus:u,spawnRippleFromNormalized:pe,clampPan:F,isMobile:v,mobileFillZoom:N});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:ue,onContextMenu:G=>G.preventDefault(),onFocus:()=>p(!0),onBlur:()=>p(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[X?e.jsx("img",{ref:l,src:X,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${E}) translate(${_}%, ${U}%)`,transformOrigin:"center center",cursor:M==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:de,onContextMenu:G=>G.preventDefault(),onDragStart:G=>G.preventDefault()}):e.jsx(oi,{waitingLabel:xe,waitingHint:ee,transportType:o}),M==="mouse"&&X&&e.jsx(ai,{cursorPos:ge,viewportRef:d,imgRef:l}),y.map(G=>{const C={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[G.type];return e.jsxs("div",{style:{position:"absolute",left:G.x,top:G.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${C}, 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(${C}, 0.9)`,boxShadow:`0 0 12px rgba(${C}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},G.id)})]}),e.jsx(ii,{inputMode:M,onToggleInputMode:se,isImeOpen:j,setIsImeOpen:S,isMenuOpen:b,setIsMenuOpen:g,imeText:m,setImeText:h,handleImeSubmit:ae,isConnActive:D,zoom:E,isMobile:v,mobileFillZoom:N,onZoomOut:()=>L(G=>Math.max(.5,G-.25)),onZoomReset:ce,onZoomIn:()=>L(G=>Math.min(5,G+.25)),transportType:o,screenshotUsage:i,lastActionStatus:f}),e.jsx("style",{children:`
12
- @keyframes slideUp {
13
- from { opacity: 0; transform: translateY(6px); }
14
- to { opacity: 1; transform: translateY(0); }
15
- }
16
- @keyframes slideUpSidebar {
17
- from { opacity: 0; transform: translateY(6px); }
18
- to { opacity: 1; transform: translateY(0); }
19
- }
20
- @keyframes click-ripple-ring {
21
- 0% { transform: scale(0.3); opacity: 1; }
22
- 100% { transform: scale(2.2); opacity: 0; }
23
- }
24
- @keyframes click-ripple-dot {
25
- 0% { transform: scale(1); opacity: 0.9; }
26
- 50% { transform: scale(1.8); opacity: 0.6; }
27
- 100% { transform: scale(0.5); opacity: 0; }
28
- }
29
- @keyframes remote-float {
30
- 0% { transform: translateY(0px); }
31
- 50% { transform: translateY(-7px); }
32
- 100% { transform: translateY(0px); }
33
- }
34
- `})]})}function di(t,s={}){if(!t)return"";const{suffix:n="",nowLabel:r="now",nowThreshold:i=60}=s,o=Date.now()-t,c=Math.floor(o/1e3);if(c<i)return r;const d=Math.floor(c/60);if(d<60)return`${d}m${n}`;const l=Math.floor(d/60);if(l<24)return`${l}h${n}`;const f=Math.floor(l/24);return f<7?`${f}d${n}`:new Date(t).toLocaleDateString()}const or=t=>di(t);function ui(t){return{unread:!!t.unread,lastSeenAt:t.lastSeenAt||0,lastUpdated:t.lastUpdated||0,inboxBucket:t.inboxBucket||"idle",surfaceHidden:!!t.surfaceHidden}}function ps(t){const s=t.connectionState==="failed"||t.connectionState==="closed",n=t.connectionState==="connecting"||t.connectionState==="new",r=t.status==="generating",i=t.status==="waiting_approval";return{isReconnecting:s,isConnecting:n,isGenerating:r,isWaiting:i}}function Dt(t){const s=new Map,n=(r,i)=>{r&&s.set(r,{sessionId:r,...ui(i)})};for(const r of t)if(!r.daemonMode){n(r.sessionId,r);for(const i of r.childSessions||[])n(i.id,i)}return s}function Pt(t,s){if(t.sessionId){const n=s.get(t.sessionId);if(n)return n}return{sessionId:t.sessionId||t.tabKey,unread:!1,lastSeenAt:0,lastUpdated:0,inboxBucket:"idle",surfaceHidden:!1}}function $t(t,s,n){const r=Pt(t,s),i=ps(t),o=i.isReconnecting,c=i.isConnecting,d=i.isGenerating,l=i.isWaiting,f=r.inboxBucket==="needs_attention"||t.status==="needs_attention"||t.status==="waiting_for_user_input"||l,u=r.inboxBucket==="working"||d,m=r.inboxBucket==="task_complete"&&r.unread&&!(n!=null&&n.hideOpenTaskCompleteUnread&&(n!=null&&n.isOpenConversation));return{unread:m,requiresAction:f,isWorking:u,isReconnecting:o,isConnecting:c,isGenerating:d,isWaiting:l,inboxBucket:f?"needs_attention":u?"working":m?"task_complete":"idle"}}function pi(t,s,n){return $t(t,s,{hideOpenTaskCompleteUnread:!0,isOpenConversation:n==null?void 0:n.isOpenConversation}).unread}function xi(t,s,n){return Pt(t,n||new Map).surfaceHidden}function cr({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status,t.connectionState]),!ps(t).isWaiting||!t.modalButtons)return null;const o=d=>{n||(r(d),s(d))},c=d=>d.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(zs,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((d,l)=>{const f=c(d).toLowerCase(),u=/^(run|approve|accept|yes|allow|always)/.test(f),m=/^(reject|deny|delete|remove|abort)/.test(f),h=n===d,p=n!==null;return e.jsx("button",{onClick:()=>o(d),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${u?"bg-white font-extrabold":m?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!h?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,style:u?{color:"var(--status-warning)"}:void 0,children:h?"⏳ ...":c(d)},l)})})]})]})}const pn=new Map,mi={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"};function fi({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:i,controls:o,controlValues:c,serverModel:d,serverMode:l}){const{sendCommand:f}=ct(),u=`${t}:${s||r}`,m=mi[r]||"#94a3b8",[h,p]=a.useState({}),y=a.useRef(0),x={...d?{model:d}:{},...l?{mode:l}:{},...c||{},...Date.now()<y.current?h:{}};a.useEffect(()=>{c&&Date.now()>y.current&&p({})},[c]);const[k,b]=a.useState(pn.get(u)||{}),[g,j]=a.useState(null),[S,v]=a.useState(null),M=a.useCallback(async(_,I={})=>{const U={...I,...s&&{targetSessionId:s}};return await f(t,_,U)},[t,s,f]);if(!o||o.length===0)return null;const w=o.filter(_=>_.placement==="bar").sort((_,I)=>(_.order??50)-(I.order??50));if(w.length===0)return null;const N=async _=>{var U,P,z;if(g===_.id){j(null);return}if((((U=_.options)==null?void 0:U.map(T=>T.value))||k[_.id]||[]).length>0){j(_.id);return}if(_.dynamic&&_.listScript){v(_.id);try{const T=await M(_.listScript==="listModels"?"list_extension_models":_.listScript==="listModes"?"list_extension_modes":_.listScript,{agentType:r,ideType:n}),O=((T==null?void 0:T.models)||(T==null?void 0:T.modes)||((P=T==null?void 0:T.result)==null?void 0:P.models)||((z=T==null?void 0:T.result)==null?void 0:z.modes)||(T==null?void 0:T.options)||[]).map(D=>typeof D=="string"?D:(D==null?void 0:D.name)||(D==null?void 0:D.id)||(D==null?void 0:D.value)||String(D));b(D=>{const X={...D,[_.id]:O};return pn.set(u,X),X}),j(_.id)}catch{}finally{v(null)}}},$=async(_,I)=>{j(null),p(U=>({...U,[_.id]:I})),y.current=Date.now()+5e3;try{if(!_.setScript)return;const U=ys(_.setScript,r);await M(U,{agentType:r,ideType:n,model:_.id==="model"?I:void 0,mode:_.id==="mode"?I:void 0,value:I})}catch{}},R=async _=>{var B;const I=((B=_.options)==null?void 0:B.map(O=>O.value))||k[_.id]||[];if(I.length===0)return;const U=String(x[_.id]||""),z=(I.indexOf(U)+1)%I.length,T=I[z];if(typeof T=="string"){p(O=>({...O,[_.id]:T})),y.current=Date.now()+5e3;try{if(!_.setScript)return;const O=ys(_.setScript,r);await M(O,{agentType:r,ideType:n,value:T})}catch{}}},E=async _=>{const U=!x[_.id];p(P=>({...P,[_.id]:U})),y.current=Date.now()+5e3;try{if(!_.setScript)return;const P=ys(_.setScript,r);await M(P,{agentType:r,ideType:n,value:U})}catch{}},L=async _=>{if(_.invokeScript)try{await M("invoke_extension_script",{agentType:r,ideType:n,scriptName:_.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:m},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),w.map(_=>{var T;const I=String(x[_.id]||""),U=g===_.id,P=S===_.id,z=((T=_.options)==null?void 0:T.map(B=>B.value))||k[_.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:U?`${m}55`:"transparent",border:"1px solid",color:I?"var(--text-primary)":"var(--text-muted)"},onClick:()=>N(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),P?"...":I||_.label,e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),U&&z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>j(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()}),z.map(B=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:B===I?`${m}18`:"transparent",color:B===I?m:"var(--text-secondary)",fontWeight:B===I?600:400,borderLeft:B===I?`2px solid ${m}`:"2px solid transparent"},onMouseEnter:O=>{O.currentTarget.style.background=`${m}12`},onMouseLeave:O=>{O.currentTarget.style.background=B===I?`${m}18`:"transparent"},onClick:()=>$(_,B),children:B},B))]})]})]},_.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:I?"var(--text-primary)":"var(--text-muted)"},onClick:()=>R(_),title:`Click to cycle: ${z.join(" → ")}`,children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),I||_.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:I?`${m}44`:"transparent",background:I?`${m}14`:"var(--surface-tertiary)",color:I?m:"var(--text-muted)"},onClick:()=>E(_),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:()=>L(_),children:[_.icon&&e.jsx("span",{className:"text-[9px] opacity-60",children:_.icon}),_.label]},_.id);default:return null}})]})}function ys(t,s){return{setModel:"set_extension_model",setMode:"set_extension_mode",setThinkingLevel:"set_thought_level"}[t]||t}const hi=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:i}){const o=a.useRef(null),[c,d]=a.useState("");a.useEffect(()=>{d("")},[s]);const l=()=>{const f=c.trim();!f||r||(d(""),i(f))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 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:o,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:f=>d(f.target.value),onPaste:f=>{const u=f.clipboardData.getData("text");u&&d(m=>m+u),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),l()}},onBlur:f=>{if(window.innerWidth<768){const u=f.relatedTarget;if((u==null?void 0:u.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:l,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.trim()&&!r?{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:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})});var bi=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function gi(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function qe(t,s){if(gi(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":bi.has(n)?"generating":n==="error"?"error":n==="stopped"?"stopped":n==="starting"?"starting":n==="panel_hidden"?"panel_hidden":n==="not_monitored"?"not_monitored":n==="disconnected"?"disconnected":"idle"}function lr(t){return qe(t)==="generating"}function Me(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function yi(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function xn(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function dr(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const i=r.replace(/[\\/]+$/,""),o=i.split(/[\\/]/).filter(Boolean);return o[o.length-1]||i}function vi(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function ji(t){const s=t.trim().toLowerCase();return s.startsWith("mach_")||s.startsWith("standalone_mach_")||s.startsWith("daemon_mach_")}function wi(t){return vi(t.trim().replace(/\.local$/i,""))}function ki(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function ur(t,s={}){var i,o;const n=[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&&!ji(c));if(n&&n!=="Unknown")return wi(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function tt(t,s={}){return ki(t)||ur(t,s)}function ns(t){return t.transport==="pty"}function It(t){return t.transport==="acp"}function mn(t,s){return Me(t)}function fn(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const i=(s||"").trim().toLowerCase(),o=(n||"").trim().toLowerCase(),c=Me(n||"").trim().toLowerCase();return r===i||r===o||r===c}function Ni(t){return qe(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Si(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=qe(r.status);if(!o){s.set(i,{...r,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function vs(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 Ci(t){var n,r;const s=(r=(n=t==null?void 0:t.messages)==null?void 0:n.at)==null?void 0:r.call(n,-1);return s&&(vs(s.timestamp)||vs(s.receivedAt)||vs(s.createdAt))||0}function Ii(t){return(t.recentLaunches||[]).reduce((n,r)=>Math.max(n,r.lastLaunchedAt||0),0)}function Ts(t){return Math.max(Ii(t),Ci(t.activeChat))}function Mi(t,s,n,r,i,o){const c=s-t;if(c!==0)return c;const d=n.localeCompare(r);return d!==0?d:i.localeCompare(o)}function _i(t,s){return Mi(Ts(t),Ts(s),tt(t,{fallbackId:t.id}),tt(s,{fallbackId:s.id}),t.id,s.id)}function pr({conversation:t,className:s="",onOpenNativeConversation:n,onOpenMachine:r,interactive:i=!0}){var y;const o=kt(),c=t.daemonId||((y=t.ideId)==null?void 0:y.split(":")[0])||t.ideId,d=t.transport==="cdp-page"||t.transport==="cdp-webview",l=t.streamSource==="agent-stream"&&!!t.agentName,f=!l&&(t.transport==="pty"||t.transport==="acp"),u=t.agentName||Me(t.agentType||t.ideType||""),m=(()=>{var x,k;if(t.streamSource==="agent-stream"){const b=(k=(x=t.displaySecondary)==null?void 0:x.split("·")[0])==null?void 0:k.trim();if(b)return b}return Me(t.ideType||"")})(),h=a.useCallback(()=>{if(r){r();return}c&&o("/dashboard",{state:{openMachineId:c}})},[c,o,r]),p=a.useCallback(()=>{if(n){n();return}const x=t.streamSource==="agent-stream"?t.nativeSessionId:t.sessionId;x&&o(`/dashboard?activeTab=${encodeURIComponent(x)}`)},[t.nativeSessionId,t.sessionId,t.streamSource,o,n]);return e.jsxs("div",{className:`conversation-meta-chips ${s}`.trim(),children:[d&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:p,title:m,children:[e.jsx(Fe,{size:12}),e.jsx("span",{children:m})]}):e.jsxs("span",{className:"conversation-meta-chip",title:m,children:[e.jsx(Fe,{size:12}),e.jsx("span",{children:m})]})),l&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:t.agentName,children:[e.jsx(mt,{size:12}),e.jsx("span",{children:t.agentName})]}),f&&e.jsxs("span",{className:"conversation-meta-chip is-active",title:u,children:[e.jsx(mt,{size:12}),e.jsx("span",{children:u})]}),t.machineName&&(i?e.jsxs("button",{type:"button",className:"conversation-meta-chip is-clickable",onClick:h,title:t.machineName,children:[e.jsx(ts,{size:12}),e.jsx("span",{children:t.machineName})]}):e.jsxs("span",{className:"conversation-meta-chip",title:t.machineName,children:[e.jsx(ts,{size:12}),e.jsx("span",{children:t.machineName})]}))]})}const Ee=t=>t.transport==="pty",wt=(t,s)=>Ee(t)?s||t.mode||"terminal":"chat",xr=(t,s)=>Ee(t)&&wt(t,s)==="terminal",_e=t=>t.transport==="acp";function rs(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(`
35
- `).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 As(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 Ti(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 n=String((t==null?void 0:t.role)||"").toLowerCase(),r=String((s==null?void 0:s.role)||"").toLowerCase();if(n!==r)return!1;const i=rs(t==null?void 0:t.content),o=rs(s==null?void 0:s.content);if(!i||i!==o)return!1;const c=As(t),d=As(s);return c&&d?Math.abs(c-d)<=15e3:!!(t!=null&&t._localId)!=!!(s!=null&&s._localId)}function hn(t){let s=0;return t!=null&&t._localId||(s+=4),t!=null&&t.id&&(s+=3),t!=null&&t._turnKey&&(s+=2),As(t)&&(s+=1),s}function Ai(t,s){const n=hn(t),r=hn(s);return r!==n?r>n?s:t:rs(s==null?void 0:s.content).length>=rs(t==null?void 0:t.content).length?s:t}function bn(t){const s=[];for(const n of t){const r=s.findIndex(i=>Ti(i,n));if(r>=0){s.splice(r,1,Ai(s[r],n));continue}s.push(n)}return s}const Ri=60,Li=60;function Rs({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:i,isFocusingAgent:o,actionLogs:c,userName:d,showMetaChips:l=!1}){const f=a.useRef(new Map),{sendCommand:u}=ct();Et("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const m=Ds.useMemo(()=>ps(t),[t.status,t.connectionState]),h=a.useRef(new Map),p=a.useCallback(I=>(h.current.has(I)||h.current.set(I,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Ri}),h.current.get(I)),[]),y=a.useCallback((I,U)=>{const P=p(I);h.current.set(I,{...P,...U}),x(z=>z+1)},[p]),[,x]=a.useState(0),k=t.tabKey,b=p(k),g=b.messages,j=b.hasMore,S=b.error,v=Math.max(0,t.messages.length-b.visibleLiveCount),[M,w]=a.useState(!1),N=a.useCallback(async()=>{var P,z;if(M)return;const I=t.tabKey,U=p(I);if(t.messages.length>U.visibleLiveCount){y(I,{visibleLiveCount:Math.min(t.messages.length,U.visibleLiveCount+Li),error:null});return}w(!0),y(I,{error:null});try{const T=(s==null?void 0:s.daemonId)||((P=t.ideId)==null?void 0:P.split(":")[0])||"";if(!T){y(I,{hasMore:!1});return}const B=t.ideType||t.agentType||"",O=await u(T,"chat_history",{agentType:B,offset:U.offset,limit:30,targetSessionId:t.sessionId,historySessionId:t.providerSessionId||t.sessionId}),D=(O==null?void 0:O.result)??O;if(((z=D.messages)==null?void 0:z.length)>0){const X=p(I);y(I,{messages:[...D.messages,...X.messages],offset:X.offset+D.messages.length,hasMore:!!D.hasMore})}else y(I,{hasMore:!!D.hasMore})}catch(T){const B=(T==null?void 0:T.message)||"";B.includes("P2P not available")||B.includes("channel not open")||B.includes("P2P not connected")||B.includes("timeout")?y(I,{error:"Connection not ready — tap to retry"}):y(I,{hasMore:!1,error:"Failed to load history"})}finally{w(!1)}},[M,s,t,u,p,y]),{allMessages:$,receivedAtMap:R}=a.useMemo(()=>{const I=v>0?t.messages.slice(-b.visibleLiveCount):t.messages;if(g.length===0){const B=bn(I),O={};return B.forEach((D,X)=>{const xe=`${t.tabKey}:${yt(D,X)}`;let ee=D.receivedAt||f.current.get(xe)||0;ee||(ee=Date.now(),f.current.set(xe,ee)),O[yt(D,X)]=ee}),{allMessages:B,receivedAtMap:O}}const U=new Set(I.map(B=>`${B.role}:${(B.content||"").slice(0,100)}`)),P=g.filter(B=>!U.has(`${B.role}:${(B.content||"").slice(0,100)}`)),z=bn([...P,...I]),T={};return z.forEach((B,O)=>{const D=`${t.tabKey}:${yt(B,O)}`;let X=B.receivedAt||f.current.get(D)||0;X||(X=Date.now(),f.current.set(D,X)),T[yt(B,O)]=X}),{allMessages:z,receivedAtMap:T}},[t.messages,t.tabKey,v,g,b.visibleLiveCount]),E=a.useMemo(()=>c.filter(I=>I.ideId===t.tabKey).sort((I,U)=>I.timestamp-U.timestamp),[c,t.tabKey]),L=t.displayPrimary||t.agentName||"Agent",_=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((m.isGenerating||t.status==="streaming")&&w(!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(mt,{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(Lt,{size:14})," Open ",L," 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(tr,{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(Lt,{size:14})," Open ",L," 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"&&!M)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,M,L,m.isGenerating]);return e.jsxs("div",{className:"flex-1 min-h-0 w-full flex flex-col",children:[l&&e.jsx(pr,{conversation:t,className:"chat-pane-meta-row"}),e.jsx(ri,{messages:$,actionLogs:E,agentName:t.agentName||t.displayPrimary||"Agent",userName:d,isCliMode:Ee(t)||_e(t),isWorking:m.isGenerating,contextKey:t.tabKey,receivedAtMap:R,onLoadMore:N,isLoadingMore:M,hasMoreHistory:j,hiddenLiveCount:v,loadError:S??void 0,emptyState:_}),!xr(t)&&(()=>{const I=t.streamSource!=="agent-stream",U=I?t.ideType:t.agentType,P=I?s!=null&&s.type?Me(s.type):Me(t.ideType||""):t.agentName||Me(t.agentType||""),z=!I&&(s!=null&&s.childSessions)&&s.childSessions.find(O=>O.id===t.sessionId||O.providerType===t.agentType)||s,T=z==null?void 0:z.providerControls,B=z==null?void 0:z.controlValues;return e.jsx(fi,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:U,displayLabel:P,controls:T,controlValues:B,serverModel:(z==null?void 0:z.currentModel)||void 0,serverMode:(z==null?void 0:z.currentPlan)||void 0,acpConfigOptions:_e(t)?z==null?void 0:z.acpConfigOptions:void 0,acpModes:_e(t)?z==null?void 0:z.acpModes:void 0})})(),e.jsx(hi,{contextKey:t.tabKey,panelLabel:L,isSending:r,onSend:n})]})}let mr=Rt;function Hs(){return mr()}class Pi{constructor(){Be(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let fr=new Pi;class $i{sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let $e=new $i;function Ei(t){t.dashboardWS&&(fr=t.dashboardWS),t.connectionManager&&($e=t.connectionManager),t.useDaemonsHook&&(mr=t.useDaemonsHook)}function Di({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:i=!1,isVisible:o=!0}){var E;const c=a.useRef(null),{sendCommand:d,sendData:l}=ct(),[f,u]=a.useState(""),[m,h]=a.useState(!1),p=a.useRef(0),y=a.useRef(!1),x=a.useRef(""),k=a.useRef(null),b=a.useRef(!1),g=a.useRef(null),j=t.tabKey,S=t.sessionId||"",v=t.daemonId||((E=t.ideId)==null?void 0:E.split(":")[0])||t.ideId||"",M=()=>{var L,_;p.current=0,y.current=!1,x.current="",k.current=null,b.current=!1,g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),h(!1),(_=(L=n.current)==null?void 0:L.reset)==null||_.call(L)},w=()=>{var L,_;p.current=0,y.current=!1,x.current="",k.current=null,b.current=!1,g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),h(!0),(_=(L=n.current)==null?void 0:L.reset)==null||_.call(L)},N=()=>{var _;if(g.current=null,!o)return;const L=x.current;L&&(x.current="",(_=n.current)==null||_.write(L))},$=L=>{L&&(x.current+=L,o&&g.current===null&&(g.current=requestAnimationFrame(N)))},R=(L,_=0,I,U)=>{var P,z,T,B,O;_>0&&p.current>=_||_===0&&y.current||(p.current=_,h(!0),typeof I=="number"&&typeof U=="number"&&I>0&&U>0&&((z=(P=n.current)==null?void 0:P.resize)==null||z.call(P,I,U)),(B=(T=n.current)==null?void 0:T.reset)==null||B.call(T),L&&((O=n.current)==null||O.write(L)))};return a.useEffect(()=>{M()},[S]),a.useEffect(()=>{var _;if(!S)return;const L=((_=$e.onRuntimeEvent)==null?void 0:_.call($e,S,I=>{if(!(!I||I.sessionId!==S)){if(I.type==="runtime_snapshot"){if(!o){k.current={text:I.text||"",seq:I.seq||0,cols:I.cols,rows:I.rows};return}R(I.text||"",I.seq||0,I.cols,I.rows);return}if(I.type==="session_output"){y.current=!0,typeof I.seq=="number"&&(p.current=Math.max(p.current,I.seq)),m||h(!0),typeof I.data=="string"&&$(I.data);return}if(I.type==="session_cleared"){if(!o){b.current=!0,x.current="",k.current=null;return}w()}}}))||(()=>{});return()=>{L()}},[v,S,n,o,m]),a.useEffect(()=>{var _,I,U;if(!S)return;v&&((_=$e.getState)==null?void 0:_.call($e,v))==="connected"&&(h(!0),(I=$e.requestRuntimeSnapshot)==null||I.call($e,v,S).catch(()=>{}));const L=(U=$e.onStateChange)==null?void 0:U.call($e,(P,z)=>{var T;P!==v||z!=="connected"||(h(!0),(T=$e.requestRuntimeSnapshot)==null||T.call($e,v,S).catch(()=>{}))});return()=>{L==null||L()}},[v,S,n]),a.useEffect(()=>{s&&M()},[s,j,n]),a.useEffect(()=>{u("")},[t.tabKey]),a.useEffect(()=>{var _;if(!o){(_=c.current)==null||_.blur();return}b.current&&(b.current=!1,w());const L=k.current;L&&(k.current=null,R(L.text,L.seq,L.cols,L.rows)),x.current&&g.current===null&&(g.current=requestAnimationFrame(N))},[o]),a.useEffect(()=>()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)},[]),a.useEffect(()=>{const L=_=>{var U;const I=_.detail;I!=null&&I.sessionId&&I.sessionId!==S||m&&((U=n.current)==null||U.fit())};return window.addEventListener("adhdev:fit-cli-terminal",L),()=>{window.removeEventListener("adhdev:fit-cli-terminal",L)}},[m,S,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(ar,{ref:n,readOnly:!m||!o,onInput:L=>{m&&(l!=null&&l(v,{type:"pty_input",targetSessionId:S,data:L})||d(v,"pty_input",{targetSessionId:S,data:L}).catch(console.error))},onResize:(L,_)=>{m&&(l!=null&&l(v,{type:"pty_resize",targetSessionId:S,cols:L,rows:_})||d(v,"pty_resize",{targetSessionId:S,cols:L,rows:_,force:!0}).catch(()=>{}))}}),!m&&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:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:f,disabled:!m||!o||i,onChange:L=>u(L.target.value),onPaste:L=>{const _=L.clipboardData.getData("text");_&&u(I=>I+_),L.preventDefault()},onKeyDown:L=>{if(L.key!=="Enter")return;if(L.nativeEvent.isComposing){L.preventDefault();return}L.preventDefault();const _=f.trim();!m||!_||i||(u(""),r(_))},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 L=f.trim();!m||!L||i||(u(""),r(L))},disabled:!m||!o||!f.trim()||i,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${f.trim()&&!i?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:f.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:f.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Bi({wsStatus:t,showReconnected:s,loginUrl:n}){const r=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)"},d={red:"#ef4444",orange:"#ff6b35",accent:"var(--accent-primary-light)"};return e.jsxs(e.Fragment,{children:[r&&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:d[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"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,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 Ki({terminalBackend:t,isStandalone:s=!1,machineLabel:n,machineKey:r}){const i=a.useMemo(()=>!r||!t?null:`adhdev:terminal-backend-banner:dismissed:${r}:${t.backend}`,[r,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 d=(n==null?void 0:n.trim())||"This machine",l=()=>{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:[d," 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:l,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 Fs({mode:t,onChange:s,compact:n=!1}){const r=n?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(Us,{size:r}):e.jsx(rt,{size:r})})}function gn({conversation:t,isAttention:s,onClick:n}){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}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:t.displaySecondary})]})}function Wi({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,conversations:i,onOpenHistory:o,onOpenRemote:c,onStopCli:d,activeCliViewMode:l,onSetCliViewMode:f,onOpenConversation:u,onHideConversation:m,hiddenConversations:h=[],onShowConversation:p,onShowAllHidden:y}){const x=Hs(),k=x.p2pStates||{},b=x.ides||[],g=!!t&&Ee(t)&&!_e(t),j=l||(t?xr(t)?"terminal":"chat":null),[S,v]=a.useState(!1),[M,w]=a.useState(!1),[N,$]=a.useState(!1),R=a.useRef(null),E=a.useRef(null),L=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",_=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",I=b.filter(F=>F.type==="adhdev-daemon"),U=a.useMemo(()=>Dt(b),[b]),P=Object.values(k),z=P.filter(F=>F==="connected").length,T=P.filter(F=>F==="connecting"||F==="new"||F==="checking").length,O=n!=="connected"||I.length===0?null:T>0&&z===0?"P2P connecting...":z>0&&s===0?"Waiting for IDE...":null,D=a.useMemo(()=>i.filter(F=>!xi(F,i,U)),[i,U]),X=a.useMemo(()=>D.filter(F=>$t(F,U).requiresAction),[D,U]),xe=a.useMemo(()=>D.filter(F=>{const q=(t==null?void 0:t.tabKey)===F.tabKey;return $t(F,U,{hideOpenTaskCompleteUnread:!0,isOpenConversation:q}).unread}),[t,D,U]),ee=X.length+xe.length;a.useEffect(()=>{if(!S)return;const F=q=>{var V;(V=R.current)!=null&&V.contains(q.target)||v(!1)};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[S]),a.useEffect(()=>{if(!M)return;const F=q=>{var V;(V=E.current)!=null&&V.contains(q.target)||w(!1)};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},[M]);const fe=F=>{if(!F)return;const q=i.find(V=>V.tabKey===F);q&&(m==null||m(q))};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(rt,{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:L,boxShadow:_}})})]}),e.jsxs("div",{className:"header-subtitle",children:[e.jsxs("span",{className:"header-subtitle-copy",children:[s," agent",s!==1?"s":""," active"]}),e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"header-subtitle-dot inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:L,boxShadow:_}}),O&&e.jsxs("span",{className:"header-subtitle-status",children:["· ",O]})]})]})})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&(g||!_e(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}),g&&d&&e.jsxs(e.Fragment,{children:[f&&j&&e.jsx(Fs,{mode:j,onChange:f,compact:!0}),e.jsx("button",{onClick:d,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(jt,{size:14})})]}),!_e(t)&&e.jsx("button",{onClick:()=>o(t),className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Ws,{size:14})}),!g&&!_e(t)&&e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Fe,{size:14})})]}),e.jsxs("div",{className:"dashboard-header-inbox",ref:R,children:[e.jsxs("div",{className:`dashboard-header-hidden${N?" is-drop-target":""}`,ref:E,onDragEnter:F=>{F.dataTransfer.types.includes("text/tab-key")&&(F.preventDefault(),$(!0))},onDragOver:F=>{F.dataTransfer.types.includes("text/tab-key")&&(F.preventDefault(),F.dataTransfer.dropEffect="move",$(!0))},onDragLeave:F=>{F.currentTarget.contains(F.relatedTarget)||$(!1)},onDrop:F=>{const q=F.dataTransfer.getData("text/tab-key");F.preventDefault(),$(!1),fe(q)},children:[e.jsxs("button",{type:"button",onClick:()=>w(F=>!F),className:"btn btn-secondary btn-sm dashboard-header-hidden-button",title:"Hidden tabs. Drag a tab here to hide it.",children:[e.jsx(Ha,{size:16}),h.length>0&&e.jsx("span",{className:"dashboard-header-hidden-badge",children:h.length})]}),M&&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"}),h.length>0&&y&&e.jsx("button",{type:"button",className:"dashboard-header-hidden-restore-all",onClick:()=>{y(),w(!1)},children:"Restore all"})]}),t&&m&&e.jsxs("button",{type:"button",className:"dashboard-header-hidden-current",onClick:()=>m(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})]}),h.length>0?e.jsx("div",{className:"dashboard-header-hidden-list",children:h.map(F=>e.jsxs("button",{type:"button",className:"dashboard-header-inbox-item",onClick:()=>{p==null||p(F),w(!1)},children:[e.jsx("span",{className:"dashboard-header-inbox-item-title",children:F.displayPrimary}),e.jsx("span",{className:"dashboard-header-inbox-item-meta",children:F.displaySecondary})]},F.tabKey))}):e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No hidden tabs."})]})]}),e.jsxs("button",{type:"button",onClick:()=>v(F=>!F),className:"btn btn-secondary btn-sm dashboard-header-inbox-button",title:"Activity inbox",children:[e.jsx(us,{size:16}),ee>0&&e.jsx("span",{className:"dashboard-header-inbox-badge",children:ee})]}),S&&e.jsxs("div",{className:"dashboard-header-inbox-popover",children:[X.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Needs attention"}),X.map(F=>e.jsx(gn,{conversation:F,isAttention:!0,onClick:()=>{u==null||u(F),v(!1)}},F.tabKey))]}),xe.length>0&&e.jsxs("div",{className:"dashboard-header-inbox-section",children:[e.jsx("div",{className:"dashboard-header-inbox-section-title",children:"Task complete"}),xe.map(F=>e.jsx(gn,{conversation:F,onClick:()=>{u==null||u(F),v(!1)}},F.tabKey))]}),ee===0&&e.jsx("div",{className:"dashboard-header-inbox-empty",children:"No pending activity."})]})]})]})]})}function Oi(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 zi({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,savedSessions:i=[],isSavedSessionsLoading:o=!1,isResumingSavedSessionId:c=null,onClose:d,onNewChat:l,onSwitchSession:f,onRefreshHistory:u,onResumeSavedSession:m}){var k;const h=s.find(b=>b.id===t.ideId),p=(h==null?void 0:h.chats)||[],y=(k=h==null?void 0:h.activeChat)==null?void 0:k.id,x=Ee(t)&&!_e(t);return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-center justify-center",children:[e.jsx("div",{onClick:d,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:x?"Saved Sessions":"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Me(t.ideType)]})]}),e.jsx("button",{onClick:d,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:[!x&&e.jsx("button",{onClick:l,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x?e.jsx(e.Fragment,{children:i.map(b=>{const g=t.providerSessionId===b.providerSessionId,j=g||!b.canResume||!!c;return e.jsxs("button",{type:"button",onClick:()=>{j||!m||m(b)},disabled:j,className:`w-full text-left p-4 rounded-xl mb-2 border transition-all ${g?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"} ${j?"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 ${g?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.title||"Untitled Session"}),e.jsx("div",{className:"text-[11px] text-text-muted font-mono truncate",children:b.providerSessionId})]}),e.jsx("div",{className:"text-[11px] text-text-muted shrink-0",children:Oi(b.lastMessageAt)})]}),e.jsx("div",{className:"mt-2 text-[12px] text-text-muted line-clamp-2",children:b.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:[b.workspace||"Workspace unknown",b.currentModel?` · ${b.currentModel}`:"",b.messageCount>0?` · ${b.messageCount} msgs`:""]}),e.jsx("div",{className:"shrink-0",children:g?"ACTIVE":b.canResume?c===b.providerSessionId?"RESUMING...":"RESUME":"MISSING WORKSPACE"})]})]},b.id)})}):p.map(b=>e.jsxs("div",{onClick:()=>{f(t.ideId,b.id),d()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${y===b.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 ${y===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.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:[b.id.substring(0,12),"..."]}),y===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),(x&&!o&&i.length===0||!x&&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(Ga,{size:32})}),e.jsx("div",{className:"text-[13px]",children:x?"No saved sessions found yet.":"No recent chat sessions found."})]}),x&&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:u,disabled:r||o,className:"btn btn-secondary btn-sm rounded-[10px]",children:r||o?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Os,{size:13})," ",x?"Refresh Sessions":"Refresh History"]})})})]})]})}const yn={success:"rgba(16, 185, 129, 0.95)",warning:"color-mix(in srgb, var(--status-warning) 95%, transparent)",info:"rgba(99, 102, 241, 0.95)"};function hr({toasts:t,onDismiss:s,onClickToast:n}){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(r=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px] relative group",style:{background:yn[r.type]||yn.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(n&&n(r),s(r.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:i=>{i.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(r.id)},children:i.label},o))})]},r.id))})}function br(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 Ui=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Hi(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Fi(t){return t.sessionId||t.instanceId||t.agentType}function js(t,s){return t||s}function vn(t){return br(t)}function jn(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 wn(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 n=String(t.role||"").toLowerCase(),r=String(s.role||"").toLowerCase();if(n!==r)return!1;const i=vn(t.content),o=vn(s.content);if(!i||i!==o)return!1;const c=jn(t),d=jn(s);return c&&d?Math.abs(c-d)<=15e3:!!t._localId!=!!s._localId}function kn(t,s){const n=new Set,r=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;n.has(c)||(n.add(c),r.push(o))}return r.sort((i,o)=>i.timestamp-o.timestamp)}function gr(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=tt(r,{fallbackId:r.id}))}return s}function yr(t,s,n={}){var h,p,y,x,k,b;const r=[],i=n.machineName,o=n.connectionState,c=Hi(t),d=Me(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(g=>{var j,S;return{sessionId:g.id,instanceId:g.id,providerSessionId:g.providerSessionId,agentType:g.providerType,agentName:g.providerName,status:g.status,title:g.title,messages:((j=g.activeChat)==null?void 0:j.messages)||[],activeModal:((S=g.activeChat)==null?void 0:S.activeModal)||void 0,unread:g.unread,lastSeenAt:g.lastSeenAt,lastUpdated:g.lastUpdated,inboxBucket:g.inboxBucket,surfaceHidden:g.surfaceHidden}}):[],f=Ui(t),u=t.activeChat||{title:""},m=u.title&&String(u.title).trim()?String(u.title).trim():"";if(f){const g=t.sessionId||t.instanceId,j=mn(t.type),S=(h=t.activeChat)==null?void 0:h.activeModal,v=S&&Array.isArray(S.buttons)&&S.buttons.length>0,M=qe((p=t.activeChat)==null?void 0:p.status,{activeModal:(y=t.activeChat)==null?void 0:y.activeModal})||qe((k=(x=t.agents)==null?void 0:x[0])==null?void 0:k.status)||"idle",w=t.activeChat||{title:"",messages:[]};let N=w.title&&String(w.title).trim()?String(w.title).trim():"";const $=(b=t.activeChat)==null?void 0:b.id,R=t.chats;if($&&Array.isArray(R)&&R.length>0){const z=R.find(T=>T.id===$||T.id&&String(T.id)===String($));z!=null&&z.title&&String(z.title).trim()&&(N=String(z.title).trim())}const E=(Ee(t)||_e(t))&&(t.cliType||t.acpType)||t.type,L=(Ee(t)||_e(t))&&fn(N,j,E)?"":N,_=w.messages||[],I=kn(s,[t.id,g]),U=_.filter(z=>String((z==null?void 0:z.role)||"").toLowerCase()==="user").slice(),P=I.filter(z=>{const T=U.findIndex(B=>wn(B,z));return T>=0?(U.splice(T,1),!1):!0});r.push({ideId:t.id,sessionId:g,providerSessionId:t.providerSessionId,nativeSessionId:g,transport:t.transport,daemonId:t.daemonId||void 0,mode:Ee(t)?t.mode||"terminal":"chat",agentName:j,agentType:E,status:M,title:L,messages:[..._,...P],resume:t.resume,ideType:E,workspaceName:c,displayPrimary:c||L||(Ee(t)?t.mode==="chat"?j:"Terminal":j),displaySecondary:d,cdpConnected:t.cdpConnected,modalButtons:v?S.buttons:void 0,modalMessage:v?S.message:void 0,streamSource:"native",tabKey:js(g,t.id),machineName:i,connectionState:o})}if(f&&(Ee(t)||_e(t)))return r;for(const g of l){const j=g.activeModal&&Array.isArray(g.activeModal.buttons)&&g.activeModal.buttons.length>0,S=Ni(g),v=Fi(g),M=`${t.id}:${v}`,w=g.title&&String(g.title).trim()||"",N=fn(w,g.agentName,g.agentType)?"":w,$=g.messages||[],R=kn(s,[M,g.sessionId,g.instanceId]),E=$.filter(I=>String((I==null?void 0:I.role)||"").toLowerCase()==="user").slice(),L=R.filter(I=>{const U=E.findIndex(P=>wn(P,I));return U>=0?(E.splice(U,1),!1):!0});($.length>0||L.length>0||j||N||!["idle","panel_hidden","disconnected","not_monitored"].includes(S))&&r.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:S,title:N,messages:[...$,...L],ideType:g.agentType,workspaceName:c,displayPrimary:N||m||c||d,displaySecondary:`${d}·${g.agentName}`,cdpConnected:t.cdpConnected,modalButtons:j?g.activeModal.buttons:void 0,modalMessage:j?g.activeModal.message:void 0,streamSource:"agent-stream",tabKey:js(g.sessionId||g.instanceId,M),machineName:i,connectionState:o})}return r.length===0&&r.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:mn(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||d,displaySecondary:d,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:js(t.sessionId||t.instanceId,t.id),connectionState:o}),r}function Vi(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const i=n.get(r.parentId)||[];i.push(r),n.set(r.parentId,i)}else s.push(r);return{topLevel:s,childrenByParent:n}}function qi(t,s){const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:f}=Vi(d),u=l.filter(p=>p.kind==="workspace"&&p.transport==="cdp-page"),m=l.filter(p=>p.kind==="agent"&&p.transport==="pty"),h=l.filter(p=>p.kind==="agent"&&p.transport==="acp");n.push({...i||{},id:r,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.recentLaunches&&{recentLaunches:t.recentLaunches},...t.terminalBackend&&{terminalBackend:t.terminalBackend},...t.detectedIdes&&{detectedIdes:t.detectedIdes},...t.availableProviders&&{availableProviders:t.availableProviders},cdpConnected:u.some(p=>!!p.cdpConnected)});for(const p of u){const y=f.get(p.id)||[];n.push({id:`${r}: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:r,instanceId:p.id,workspace:p.workspace,terminals:0,childSessions:y,agents:y.map(x=>({id:x.id,name:x.providerName,type:x.providerType,status:x.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 m)n.push({id:`${r}: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:r,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 h)n.push({id:`${r}: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:r,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 n}function Gi(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 Yi(t,s){const n=Gi(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const vr=[{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:"💚"}],jr=[{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:"🧩"}],wr=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],kr="adhdev_notification_prefs",Nn={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Xi(){try{const t=localStorage.getItem(kr);if(t){const s=JSON.parse(t);return{...Nn,...s}}}catch{}return{...Nn}}function Zi(t){try{localStorage.setItem(kr,JSON.stringify(t))}catch{}}let et=Xi(),Xt=[];function Ji(){Xt.forEach(t=>t())}function Qi(){return{...et}}function eo(t){et={...et,...t},Zi(et),Ji()}function to(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Xt.push(n),()=>{Xt=Xt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{eo(n)},[]);return[{...et},s]}function Mt(t){if(!et.globalEnabled)return!1;switch(t){case"disconnect":return et.disconnectAlert;case"completion":return et.completionAlert;case"approval":return et.approvalAlert;case"browser":return et.browserNotifications;default:return!0}}const so={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function no(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Nr(){return"Notification"in window&&Notification.permission==="granted"}let lt=null;async function ro(){if(lt!==null)return lt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return lt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(lt=!!await t.pushManager.getSubscription(),lt):(lt=!1,!1)}catch{return lt=!1,!1}}function Ls(t,s,n){if(Nr())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:n||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function ao(t,s={}){const n={...so,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{ro().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,f)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Ls(d,l,f))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!Nr())&&Mt("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,qe(l.status,{activeModal:l.activeModal}));return}for(const l of t){const f=r.current.get(l.id),u=qe(l.status,{activeModal:l.activeModal}),m=l.name||l.id;if(n.onApproval&&Mt("approval")&&u==="waiting_approval"&&f!=="waiting_approval"){const h=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${m} — Approval needed`,h.slice(0,120),`approval-${l.id}`)}n.onComplete&&Mt("completion")&&lr(f)&&u==="idle"&&c(`✅ ${m} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&f!=="error"&&c(`⚠️ ${m} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class io{constructor(){Be(this,"dedupMap",new Map);Be(this,"DEDUP_WINDOW_MS",5e3);Be(this,"DEDUP_MAX_SIZE",50);Be(this,"DEDUP_CLEANUP_AGE_MS",1e4);Be(this,"toastCallbacks",[]);Be(this,"systemMessageCallbacks",[]);Be(this,"clearSystemMessageCallbacks",[]);Be(this,"resolveActionFn",null);Be(this,"viewRequestRespondFn",null);Be(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-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 n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(i=>(i==null?void 0:i.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,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 r=this.resolveConversationKey(s),o=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=Me(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const h=tt(d,{fallbackId:d.id});h&&(c=s.ideType==="adhdev-daemon"?h:`${h}/${c}`)}let l="",f="info";if(s.event==="agent:generating_completed"){const h=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${h}`,f="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Qi().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${h}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,f="warning",r){const h=s.modalMessage||"Approval requested",p=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(y=>`[${y}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${h}
36
- ${p}`,_localId:`sys_approval_${Date.now()}`})}if((m=s.modalButtons)!=null&&m.length&&this.resolveActionFn){const h=this.resolveActionRouteTarget(s);if(!h)return;const p=s.agentType||s.ideType||"",y=s.ideType||"",x=s.modalButtons,k=v=>v.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),b=this.resolveActionFn,g=x.map((v,M)=>{const w=k(v).toLowerCase(),N=/^(run|approve|accept|yes|allow|always)/.test(w),$=/^(reject|deny|delete|remove|abort|cancel|no)/.test(w);return{label:k(v),variant:N?"primary":$?"danger":"default",onClick:()=>{const R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w);b(h,"resolve_action",{action:R?"approve":"reject",button:v,buttonIndex:M,agentType:p,ideType:y,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),j=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,S=Date.now();this.emitToast({id:S,message:j,type:f,timestamp:S,targetKey:r||h,actions:g,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const h=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${h}`,f="warning",Mt("browser")&&!document.hasFocus()&&Ls(`⚠️ ${c} — 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",p=s.requestId,y=s.orgId;if(l=`👁️ ${h} wants to view your session`,f="warning",p&&y&&this.viewRequestRespondFn){const x=this.viewRequestRespondFn,k=Date.now(),b=[{label:"Approve",variant:"primary",onClick:()=>{x(y,p,"approve").catch(g=>console.error("[EventManager] approve view request failed:",g))}},{label:"Decline",variant:"danger",onClick:()=>{x(y,p,"reject").catch(g=>console.error("[EventManager] reject view request failed:",g))}}];this.emitToast({id:k,message:l,type:f,timestamp:k,actions:b,duration:3e4}),l=""}Mt("browser")&&!document.hasFocus()&&Ls("👁️ View Request",`${h} wants to view your session`,`view-request-${p}`)}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:r||s.ideId,duration:5e3})}}}const it=new io;function ft(...t){return ya(va(t))}function oo({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:ft("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,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function as({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(oo,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ft("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function He({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:ft("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&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]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Vs({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:ft("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:n}),r]})}const co={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"},lo={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function uo({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ft("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",co[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:lo[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const po={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"},xo={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function mo({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ft("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",po[t],n),children:[e.jsx("span",{className:ft("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",xo[t])}),r]})}function fo(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ps(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function Zt(t){return t==="system"?fo():t}function ho(){typeof document>"u"||document.documentElement.setAttribute("data-theme",Zt(Ps()))}function Sr(){const[t,s]=a.useState(Ps),[n,r]=a.useState(()=>Zt(Ps()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Zt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Zt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function ot({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:`flex justify-between items-center ${r?"cursor-not-allowed opacity-60":"cursor-pointer"}`,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("div",{className:"relative inline-flex items-center",children:[e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-[40px] h-[22px] rounded-full transition-colors duration-200 ease-in-out",style:{backgroundColor:n?"var(--accent-primary)":"color-mix(in srgb, var(--surface-primary) 60%, var(--border-default))"}}),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)] ${n?"translate-x-[18px]":"translate-x-0"}`})]})]})]})}function bo({onPrefChange:t}){const[s,n]=to(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(us,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fe,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("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(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ya,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Xa,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(mt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(rt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("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 go({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Vs,{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(vo,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function Sn({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return ja.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:d=>d.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:r==="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:n})]})]})}),document.body)}function yo(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...vr,...jr,...wr].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function vo({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var I,U;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[f,u]=a.useState(null),[m,h]=a.useState("idle"),[p,y]=a.useState(""),x=t,k=x.version||x.daemonVersion||null,b=((I=x.machine)==null?void 0:I.platform)||((U=x.system)==null?void 0:U.platform)||"",g=tt(x,{fallbackId:t.id}),j=b==="win32"?"🪟":b==="darwin"?"🍎":"🐧",S=s.filter(P=>P.daemonId===t.id&&P.transport==="cdp-page"),v=s.filter(P=>P.daemonId===t.id&&P.transport==="pty"),M=s.filter(P=>P.daemonId===t.id&&P.transport==="acp"),w=x.p2p,N=async()=>{var P,z,T,B;if(n){c("upgrading"),l("Starting upgrade...");try{const O=await n(t.id,"daemon_upgrade",{});(P=O==null?void 0:O.result)!=null&&P.alreadyLatest?(c("done"),l(`Already on v${O.result.version||"latest"}.`)):(z=O==null?void 0:O.result)!=null&&z.upgraded||(T=O==null?void 0:O.result)!=null&&T.success?(c("done"),l(`Upgrade to v${O.result.version||"latest"} started. Daemon is restarting...`)):(c("error"),l(((B=O==null?void 0:O.result)==null?void 0:B.error)||"Upgrade failed"))}catch(O){c("error"),l((O==null?void 0:O.message)||"Connection lost during upgrade")}}},$=async()=>{if(u(null),!!r){h("loading");try{await r(t.id),h("done"),y("Machine disconnected.")}catch(P){h("error"),y((P==null?void 0:P.message)||"Failed to disconnect")}}},R=async()=>{if(u(null),!!i){h("loading");try{await i(t.id),h("done"),y('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(P){h("error"),y((P==null?void 0:P.message)||"Failed to revoke token")}}},E="0.8.6",L=!k||k!==E,_=S.length+v.length+M.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:j}),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),"…"]}),k&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${L?"":"bg-bg-secondary"}`,style:L?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",k,!L&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&L&&e.jsx("button",{onClick:N,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${E}`,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${E}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>u("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(mo,{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:[w&&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 ${w.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${w.state==="connecting"||w.state==="new"?"animate-pulse":""}`,style:w.state==="connecting"||w.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",w.state==="connected"?"connected":w.state==="connecting"||w.state==="new"?"connecting...":w.state||"off"]}),w.peers!==void 0&&w.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",w.peers," peer",w.peers!==1?"s":"",")"]})]}),w&&_>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),_>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[S.map(P=>{const z=yo(P.type),T=P.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:z.icon}),e.jsx("span",{children:z.name}),T!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${T?"bg-green-400":"animate-pulse"}`,style:T?void 0:{background:"var(--status-warning)"},title:T?"CDP connected":"CDP connecting..."})]},P.id)}),v.map(P=>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:P.cliName||"CLI"})]},P.id)),M.map(P=>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:P.cliName||"ACP"})]},P.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||p)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-red-400":o==="done"||m==="done"?"text-green-400":"text-text-muted"}`,children:p||d})]}),f==="disconnect"&&e.jsx(Sn,{title:"🔌 Disconnect Machine",message:`Disconnect "${g}" from ADHDev?
37
-
38
- This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
39
-
40
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:$,onCancel:()=>u(null)}),f==="revoke"&&e.jsx(Sn,{title:"⚠️ Remove Machine",message:`Remove "${g}" from your dashboard?
41
-
42
- This will:
43
- • Immediately disconnect the machine
44
- • Delete the machine registration
45
- • Require restarting "adhdev-standalone" on that machine
46
-
47
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:R,onCancel:()=>u(null)})]})}const jo=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function wo(){const{preference:t,setPreference:s}=Sr();return e.jsx("div",{className:"flex gap-2",children:jo.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,style:t===n.id?{color:"var(--accent-on-primary)"}:void 0,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}function ko(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 No(t){return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16)}}function ws(t){const s=t/255;return s<=.04045?s/12.92:((s+.055)/1.055)**2.4}function Cn(t){const{r:s,g:n,b:r}=No(t);return .2126*ws(s)+.7152*ws(n)+.0722*ws(r)}function In(t,s){const n=Cn(t),r=Cn(s),i=Math.max(n,r),o=Math.min(n,r);return(i+.05)/(o+.05)}function Cr(t){const s=ko(t);if(!s)return"#111827";const n="#111827",r="#ffffff";return In(s,n)>=In(s,r)?n:r}const $s={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},Es={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},So=[{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"}}}],Ir="adhdev-chat-theme",Mr="adhdev-chat-theme-custom";function Jt(){if(typeof window>"u")return"ember";try{return localStorage.getItem(Ir)||"ember"}catch{return"ember"}}function Je(t){try{const s=localStorage.getItem(Mr);if(s){const n=JSON.parse(s);return{...t==="dark"?$s:Es,...n[t]}}}catch{}return t==="dark"?$s:Es}function Ut(t,s){try{localStorage.setItem(Mr,JSON.stringify({dark:t,light:s}))}catch{}}function Ye(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function is(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}const Co={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function _t(t,s){var i;const n=(i=Co[t])==null?void 0:i[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",is(n,24)),r.style.setProperty("--accent-on-primary",Cr(n)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${is(n,18)})`),r.style.setProperty("--border-accent",Ye(n,.35)),r.style.setProperty("--nav-active-bg",Ye(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ye(n,.06)}`)}function ut(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ye(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ye(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ye(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",Ye(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ye(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",is(t.accentColor,30)),s.style.setProperty("--accent-on-primary",Cr(t.accentColor)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${is(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ye(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ye(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ye(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 ${Ye(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 qs(){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(n=>t.style.removeProperty(n))}function Io(t){try{localStorage.setItem(Ir,t)}catch{}if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=pt()?"dark":"light";ut(Je(s))}else qs(),_t(t,pt()?"dark":"light")}function Mo(){const t=Jt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=pt()?"dark":"light";ut(Je(s))}else qs(),_t(t,pt()?"dark":"light")}function pt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ue({label:t,value:s,onChange:n}){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:r=>n(r.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:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.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 Nt({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 _o({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Je(n));a.useEffect(()=>{i(Je(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const f={...l,[c]:d},m=Je(n==="dark"?"light":"dark");return n==="dark"?Ut(f,m):Ut(m,f),ut(f),s(f),f})},[n,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(Nt,{title:"App Background",children:[e.jsx(Ue,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Ue,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Ue,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(Nt,{title:"App Text",children:[e.jsx(Ue,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Ue,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Ue,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(Nt,{title:"Borders & Accent",children:[e.jsx(Ue,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Ue,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Ue,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Nt,{title:"Chat Bubbles",children:[e.jsx(Ue,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Ue,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Ue,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Ue,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(Nt,{title:"Chat Layout",children:[e.jsx(Ue,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Ue,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Ue,{label:"Input border",value:r.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:r.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:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?$s:Es,l=Je(t?"light":"dark");t?Ut(c,l):Ut(l,c),i(c),ut(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 To(){const[t,s]=a.useState(Jt),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Je("dark"));a.useEffect(()=>{r(pt());const l=new MutationObserver(()=>{const m=pt();r(m);const h=Jt();h==="custom"?ut(Je(m?"dark":"light")):_t(h,m?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const f=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const m=pt();r(m);const h=Jt();h==="custom"?ut(Je(m?"dark":"light")):_t(h,m?"dark":"light")};return f.addEventListener("change",u),()=>{l.disconnect(),f.removeEventListener("change",u)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?ut(Je(n?"dark":"light")):(qs(),_t(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{o(Je(n?"dark":"light"))},[n]);const c=l=>{s(l),Io(l)},d=[...So,{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:d.map(l=>{const f=t===l.id,u=n?l.preview.dark:l.preview.light,m=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:f?"var(--bg-glass-hover)":"var(--bg-glass)",border:f?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:f?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.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:u.userBubble,color:m},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:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[f&&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:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(_o,{dark:n,onColorsChange:l=>o(l)})]})}const _r="adhdev_mobileDashboardMode_v1";function Tr(){try{return localStorage.getItem(_r)==="workspace"?"workspace":"chat"}catch{return"chat"}}function Ao(t){try{localStorage.setItem(_r,t)}catch{}}function Ro(){const[t,s]=a.useState(!0);return a.useEffect(()=>{s(Tr()==="chat")},[]),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(rt,{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:n=>{s(n),Ao(n?"chat":"workspace")},extra:e.jsx("span",{className:"text-[11px] text-text-muted",children:t?"Chat mode":"Workspace"})})}const Ar="adhdev_hiddenTabs";function Lo(){try{const t=localStorage.getItem(Ar);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function bt(t){try{localStorage.setItem(Ar,JSON.stringify([...t]))}catch{}}function Po(){const[t,s]=a.useState(Lo),n=a.useCallback(f=>{s(u=>{const m=new Set(u);return m.has(f)?m.delete(f):m.add(f),bt(m),m})},[]),r=a.useCallback(f=>{s(u=>{if(u.has(f))return u;const m=new Set(u);return m.add(f),bt(m),m})},[]),i=a.useCallback(f=>{s(u=>{if(!u.has(f))return u;const m=new Set(u);return m.delete(f),bt(m),m})},[]),o=a.useCallback(()=>{s(f=>{if(f.size===0)return f;const u=new Set;return bt(u),u})},[]),c=a.useCallback((f,u)=>{s(m=>{const h=new Set(m);for(const p of u)h.add(p);return bt(h),h})},[]),d=a.useCallback((f,u)=>{s(m=>{const h=new Set(m);for(const p of u)h.delete(p);return bt(h),h})},[]),l=a.useCallback(f=>t.has(f),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,showAllTabs:o,hideAllForDaemon:c,showAllForDaemon:d,isHidden:l}}function $o({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){a.useEffect(()=>{no()},[]);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 ao(i),a.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(d=>{const l=Date.now(),f={};for(const[u,m]of Object.entries(d))l-m<5e3&&(f[u]=m);return Object.keys(f).length===Object.keys(d).length?d:f})},5500);return()=>clearTimeout(c)},[s,n]),a.useEffect(()=>{const o=setInterval(()=>{const c=Date.now()-3e5;r(d=>{const l=d.filter(f=>f.timestamp>c).slice(-100);return l.length===d.length?d:l})},6e4);return()=>clearInterval(o)},[r]),null}function ks(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 vt(t){const s=[...t.messages].reverse().find(n=>!(n!=null&&n._localId))||t.messages[t.messages.length-1];return ks(s==null?void 0:s.timestamp)||ks(s==null?void 0:s.receivedAt)||ks(s==null?void 0:s.createdAt)||0}function Mn(t){return vt(t)}function Rr(t,s){const n=Mn(s)-Mn(t);if(n!==0)return n;const r=(t.machineName||"").localeCompare(s.machineName||"");if(r!==0)return r;const i=t.displayPrimary.localeCompare(s.displayPrimary);if(i!==0)return i;const o=t.displaySecondary.localeCompare(s.displaySecondary);return o!==0?o:t.tabKey.localeCompare(s.tabKey)}function Eo(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const i=n.get(r.id);if(!i){n.set(r.id,r);continue}const o=(i.workspace?1:0)+(i.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>o||(r.timestamp||0)>(i.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function Ht(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function Do(t,s){const n=Date.now();return t.map(r=>{const i=s[r.tabKey];return i&&n-i<5e3?{...r,messages:[],title:""}:r})}function Bo(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const i of t.childSessions||[]){const o=i.id||i.providerType,c=`${t.id}:${o}`;n.push({key:c,ref:s[c]}),n.push({key:i.id,ref:s[i.id]})}return n}function Ko(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n].key!==s[n].key||t[n].ref!==s[n].ref)return!1;return!0}function Wo({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:i}){const o=a.useRef([]),c=a.useRef([]),d=a.useRef([]),l=a.useRef([]),f=a.useMemo(()=>{const S=Eo(t);return Ht(o.current,S)?o.current:(o.current=S,S)},[t]),u=a.useMemo(()=>gr(t),[t]),m=a.useRef(new Map),h=a.useMemo(()=>{var M;const S=new Map,v=[];for(const w of f){const N=w.daemonId||((M=w.id)==null?void 0:M.split(":")[0])||w.id,$=s[N]||"new",R=w.daemonId&&u[w.daemonId]||void 0,E=Bo(w,n),L=m.current.get(w.id);if(L&&L.ide===w&&L.connectionState===$&&L.machineName===R&&Ko(L.localRefs,E)){S.set(w.id,L),v.push(...L.conversations);continue}const _=yr(w,n,{machineName:R,connectionState:$}),I={ide:w,connectionState:$,machineName:R,localRefs:E,conversations:_};S.set(w.id,I),v.push(..._)}return m.current=S,[...v].sort(Rr)},[f,n,s,u]),p=a.useMemo(()=>{const S=Do(h,r);return Ht(c.current,S)?c.current:(c.current=S,S)},[h,r]),y=a.useMemo(()=>{const S=new Map;for(const v of p)v.sessionId&&S.set(v.sessionId,v);return S},[p]),x=a.useMemo(()=>{const S=new Map;for(const v of p)v.sessionId&&S.set(v.sessionId,v),S.set(v.ideId,v),S.set(v.tabKey,v);return S},[p]),k=a.useCallback(S=>{if(S)return y.get(S)},[y]),b=a.useCallback(S=>{if(S)return x.get(S)},[x]),g=a.useMemo(()=>{const S=p.filter(v=>!i.has(v.tabKey));return Ht(d.current,S)?d.current:(d.current=S,S)},[p,i]),j=a.useMemo(()=>{const S=g.map(v=>v.tabKey);return Ht(l.current,S)?l.current:(l.current=S,S)},[g]);return{chatIdes:f,conversations:p,visibleConversations:g,visibleTabKeys:j,resolveConversationBySessionId:k,resolveConversationByTarget:b}}function Oo({isMobile:t,urlActiveTab:s,resolveConversationBySessionId:n,setSearchParams:r}){const i=a.useMemo(()=>{var d;return t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),o=a.useMemo(()=>{var d;return!t||!s?null:((d=n(s))==null?void 0:d.tabKey)??null},[t,n,s]),c=a.useCallback(()=>{s&&r(d=>{const l=new URLSearchParams(d);return l.delete("activeTab"),l},{replace:!0})},[r,s]);return{requestedDesktopTabKey:i,requestedMobileTabKey:o,consumeRequestedActiveTab:c}}function zo({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:i}){a.useEffect(()=>{it.setIdes(t)},[t]),a.useEffect(()=>{it.setResolveAction((o,c,d)=>{s(o,c,d).catch(()=>{})})},[s]),a.useEffect(()=>{const o=it.onToast(l=>{n(u=>u.some(h=>h.message===l.message&&l.timestamp-h.timestamp<3e3)?u:[...u.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const f=l.duration||5e3;setTimeout(()=>n(u=>u.filter(m=>m.id!==l.id)),f)}),c=it.onSystemMessage((l,f)=>{var m;const u=i(l);(u==null?void 0:u.transport)==="pty"&&((m=f._localId)!=null&&m.startsWith("sys_approval_"))||r(h=>({...h,[l]:[...h[l]||[],f]}))}),d=it.onClearSystemMessage((l,f)=>{r(u=>{var m;return(m=u[l])!=null&&m.length?{...u,[l]:u[l].filter(h=>{var p;return!(h.role==="system"&&((p=h._localId)!=null&&p.startsWith(f)))})}:u})});return()=>{o(),c(),d()}},[n,r]),a.useEffect(()=>{const o=fr.on("status_event",c=>it.handleRawEvent(c,"ws"));return()=>{o()}},[]),a.useEffect(()=>{var c;const o=d=>{const l=d.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const f=l.targetSessionId||l.targetKey||l.ideId,u=i(f),m=(u==null?void 0:u.ideId)||l.ideId;m&&s(m,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(h=>console.error("[SW Action] approve failed:",h))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",o),()=>{var d;return(d=navigator.serviceWorker)==null?void 0:d.removeEventListener("message",o)}},[i,s])}const Uo="adhdev_dashboardLayout_v1",Ho="adhdev_dashboardDockview_v1",St={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function Lr(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Pr(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function $r(t){return`${Uo}:${t}`}function Fo(t){const s=$r(t);return Lr(s,null)}function Vo(t,s){try{const n=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,r=$r(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function Er(t){return`${Ho}:${t}`}function qo(t){const s=Er(t);return Lr(s,null)}function Go(t,s){try{const n=Er(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function Yo(){return{groupAssignments:[...St.groupAssignments],focusedGroup:St.focusedGroup,groupActiveTabIds:{...St.groupActiveTabIds},groupTabOrders:{...St.groupTabOrders},groupSizes:[...St.groupSizes]}}function Xo(){const[t]=a.useState(()=>Pr(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,i]=a.useState(0),[o,c]=a.useState({}),[d,l]=a.useState({}),[f,u]=a.useState([]),[m,h]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[p,y]=a.useState(!1),x=a.useCallback(()=>{if(p)return;const k=Fo(t)??Yo();n(new Map(k.groupAssignments)),i(k.focusedGroup),c(k.groupActiveTabIds),l(k.groupTabOrders),u(k.groupSizes),y(!0)},[p,t]);return a.useEffect(()=>{p&&Vo(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:o,groupTabOrders:d,groupSizes:f})},[p,t,s,r,o,d,f]),a.useEffect(()=>{const k=window.matchMedia("(max-width: 767px)"),b=g=>h(g.matches);return k.addEventListener("change",b),()=>k.removeEventListener("change",b)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:i,groupActiveTabIds:o,setGroupActiveTabIds:c,groupTabOrders:d,setGroupTabOrders:l,groupSizes:f,setGroupSizes:u,isMobile:m,hasHydratedStoredLayout:p,hydrateStoredLayout:x}}function Zo({urlActiveTab:t,conversations:s,resolveConversationBySessionId:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:i,hydrateStoredLayout:o,setGroupActiveTabIds:c,setFocusedGroup:d,setSearchParams:l,historyModalOpen:f,activeConv:u,isRefreshingHistory:m,ides:h,handleRefreshHistory:p}){const y=a.useRef(!1),x=a.useRef(!1),k=a.useRef(null),b=a.useRef(!1);a.useEffect(()=>{if(!t||y.current||s.length===0)return;if(!i){o();return}const g=n(t);if(!g)return;const j=r.get(g.tabKey)??0;c(S=>({...S,[j]:g.tabKey})),d(j),y.current=!0,x.current=!0,k.current!=null&&(window.clearTimeout(k.current),k.current=null),l(S=>{const v=new URLSearchParams(S);return v.delete("activeTab"),v},{replace:!0})},[t,s,n,r,i,o,c,d,l]),a.useEffect(()=>{if(!(x.current||i)&&s.length!==0){if(!t){o(),x.current=!0;return}if(y.current){x.current=!0;return}if(k.current==null)return k.current=window.setTimeout(()=>{k.current=null,!(x.current||i)&&(o(),x.current=!0)},1500),()=>{k.current!=null&&(window.clearTimeout(k.current),k.current=null)}}},[t,s.length,i,o]),a.useEffect(()=>{if(!f){b.current=!1;return}if(!u||b.current||m)return;const g=h.find(j=>j.id===u.ideId);g&&(!g.chats||g.chats.length===0)&&(b.current=!0,p())},[f,u,m,h,p]),a.useEffect(()=>{if(!u)return;let g=null,j=0,S=-1,v=0;const M=()=>{g=null;const w=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter($=>$.offsetParent!==null);if(w.length===0){j<18&&(j+=1,g=requestAnimationFrame(M));return}let N=0;for(const $ of w)$.scrollTop=$.scrollHeight,N+=$.scrollHeight;N===S?v+=1:(v=0,S=N),j+=1,!(v>=2||j>=18)&&(g=requestAnimationFrame(M))};return g=requestAnimationFrame(M),()=>{g!=null&&cancelAnimationFrame(g)}},[u==null?void 0:u.tabKey])}function Jo({isMobile:t,location:s,navigate:n,requestedRemoteTabTarget:r,requestedDesktopTabKey:i,conversations:o,ides:c,resolveConversationByTarget:d}){const[l,f]=a.useState(null),[u,m]=a.useState(null),h=a.useMemo(()=>{if(t||!r)return null;const b=d(r);return b&&!Ee(b)&&!_e(b)?b:null},[t,r,d]),p=a.useMemo(()=>{const b=l==null?void 0:l.ideId;if(!b)return null;const g=l!=null&&l.tabKey?o.find(j=>j.tabKey===l.tabKey):i?o.find(j=>j.tabKey===i):null;return(g==null?void 0:g.ideId)===b?g:o.find(j=>j.ideId===b&&j.streamSource==="native")||o.find(j=>j.ideId===b)||null},[o,l,i]),y=a.useMemo(()=>{if(p)return c.find(b=>b.id===p.ideId)},[c,p]);a.useEffect(()=>{h&&(f({ideId:h.ideId,tabKey:h.streamSource==="native"?"native":h.tabKey}),m(h),n({pathname:s.pathname,search:s.search},{replace:!0,state:null}))},[s.pathname,s.search,n,h]);const x=a.useCallback(b=>{b&&(f({ideId:b.ideId,tabKey:b.streamSource==="native"?"native":b.tabKey}),m(b))},[]),k=a.useCallback(()=>{f(null),m(null)},[]);return{remoteDialogConv:p,remoteDialogIdeEntry:y,remoteDialogActiveConv:u,setRemoteDialogActiveConv:m,openRemoteDialog:x,closeRemoteDialog:k}}function Tt(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return Ee(t)||_e(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function os(t){return t&&(t.ideId||t.daemonId)||""}function Ft(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function _n({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:i,setClearedTabs:o}){const[c,d]=a.useState(!1),[l,f]=a.useState(!1),u=a.useCallback(async y=>{try{await t("standalone","launch_ide",{ideType:y,enableCdp:!0})}catch(x){console.error("Launch failed",x)}},[t]),m=a.useCallback(async(y,x)=>{try{const k=y||(s==null?void 0:s.daemonId)||"",b=await t(k,"switch_chat",{id:x,sessionId:x,...Tt(s)}),g=b==null?void 0:b.result;if((b==null?void 0:b.success)===!0||g==="switched"||g==="switched-by-title")return;g===!1||g==="not_found"?Ft(r,"⚠️ Session tab not found — try refreshing history"):typeof g=="string"&&g.startsWith("error:")?Ft(r,`⚠️ Switch error: ${g}`):Ft(r,"⚠️ Session switch failed")}catch(k){console.error("Switch failed",k),Ft(r,`❌ Switch failed: ${k.message||"connection error"}`)}},[s,t,r]),h=a.useCallback(async()=>{if(!(!s||c)){d(!0);try{const y=os(s);await t(y,"new_chat",{...Tt(s)}),o(x=>({...x,[s.tabKey]:Date.now()})),i(x=>({...x,[s.tabKey]:[]}))}catch(y){console.error("New chat failed",y)}finally{d(!1)}}},[s,c,t,o,i]),p=a.useCallback(async()=>{var y;if(!(!s||l)){f(!0);try{const x=os(s),k=await t(x,"list_chats",{forceExpand:!0,...Tt(s)}),b=(k==null?void 0:k.chats)||((y=k==null?void 0:k.result)==null?void 0:y.chats);k!=null&&k.success&&Array.isArray(b)&&n(s.ideId,b)}catch(x){console.error("Refresh history failed",x)}finally{f(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:m,handleNewChat:h,handleRefreshHistory:p}}function Qo(t,s){if(t.size!==s.size)return!1;for(const[n,r]of t)if(s.get(n)!==r)return!1;return!0}function ec(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function Tn(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[Number(i)]===t[Number(i)])}function Vt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function An(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function tc(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function sc(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Rn(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=Number(r);n[o>=s?o+1:o]=i}return n}function Ln(t){return Array(t).fill(100/t)}function nc({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:i,groupSizes:o,setGroupSizes:c,isMobile:d,visibleConversations:l,visibleTabKeys:f}){const u=a.useRef(null),m=a.useMemo(()=>Vt(t,f),[t,f]),h=m.assignments,p=a.useMemo(()=>d?1:m.groupCount,[m.groupCount,d]),y=p>1,x=a.useCallback((v,M)=>{s(w=>{const N=new Map(Vt(w,f).assignments);return M===0?N.delete(v):N.set(v,M),N}),r(w=>({...w,[M]:v})),n(M)},[s,f,r,n]),k=a.useCallback(v=>{s(M=>{const w=Vt(M,f).assignments,N=new Map;for(const[$,R]of w)R!==v&&(R>v?N.set($,R-1):N.set($,R));return N}),c(M=>{if(M.length<=1)return[];const w=[...M];w.splice(v,1);const N=w.reduce(($,R)=>$+R,0);return N>0?w.map($=>$/N*100):[]}),n(0)},[s,f,c,n]),b=a.useCallback((v,M)=>{M.preventDefault();const w=u.current;if(!w)return;const N=M.clientX,$=w.offsetWidth,R=o.length===p?[...o]:Ln(p),E=_=>{const U=(_.clientX-N)/$*100,P=[...R];P[v]=Math.max(15,R[v]+U),P[v+1]=Math.max(15,R[v+1]-U),c(P)},L=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",L),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",E),document.addEventListener("mouseup",L)},[o,p,c]),g=a.useCallback((v,M,w)=>{if(p>=4)return;const N=w==="left"?M:M+1;s($=>{const R=Vt($,f).assignments,E=new Map;for(const L of l){const _=R.get(L.tabKey)??0,I=_>=N?_+1:_;I>0&&E.set(L.tabKey,I)}return N>0&&E.set(v,N),E}),c($=>{const R=$.length===p?[...$]:Ln(p),E=R[M]??100/p,L=Math.max(15,E/2),_=Math.max(15,E/2),I=[...R];I[M]=L,I.splice(N,0,_);const U=I.reduce((P,z)=>P+z,0);return I.map(P=>P/U*100)}),r($=>{const R=Rn($,N);return R[N]=v,R}),i($=>{const R=Rn($,N);return R[N]=[v],R}),n(N)},[p,s,f,l,c,r,i,n]);a.useEffect(()=>{Qo(t,h)||s(h)},[t,h,s]),a.useEffect(()=>{const{mapping:v,usedGroups:M}=m;r(w=>{const N=An(w,v);return Tn(w,N)?w:N}),i(w=>{const N=An(w,v);return Tn(w,N)?w:N}),n(w=>{const N=d?0:tc(w,M,v);return w===N?w:N}),c(w=>{const N=d?[]:sc(w,M,m.groupCount);return ec(w,N)?w:N})},[m,d,r,i,n,c]);const j=a.useMemo(()=>{const v=Array.from({length:p},()=>[]);for(const M of l){const w=h.get(M.tabKey)??0,N=Math.min(w,p-1);v[N].push(M)}return v},[l,h,p]),S=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:h,numGroups:p,isSplitMode:y,groupedConvs:j,moveTabToGroup:x,closeGroup:k,handleResizeStart:b,splitTabRelative:g,clearAllSplits:S}}function rc({ides:t,sendDaemonCommand:s}){const n="0.8.6",r=a.useMemo(()=>t.filter(f=>{if(f.type!=="adhdev-daemon")return!1;const u=f.version||f.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[i,o]=a.useState(!1),[c,d]=a.useState({}),l=a.useCallback(async f=>{var u,m;d(h=>({...h,[f]:"upgrading"}));try{const h=await s(f,"daemon_upgrade",{});(u=h==null?void 0:h.result)!=null&&u.upgraded||(m=h==null?void 0:h.result)!=null&&m.success?d(p=>({...p,[f]:"done"})):d(p=>({...p,[f]:"error"}))}catch{d(h=>({...h,[f]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:i,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:l}}function xs({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:i}){const[o,c]=a.useState(!1),[d,l]=a.useState(!1),f=a.useRef(!1),u=a.useRef(null),m=a.useCallback(async x=>{if(!s)return;const k=x.trim();if(!k||f.current)return;const b=s.tabKey,g=Date.now(),j=u.current;if(j&&j.tabKey===b&&j.message===k&&g-j.timestamp<2e3)return;f.current=!0,l(!0),u.current={tabKey:b,message:k,timestamp:g};const S=`${g}-${Math.random().toString(36).slice(2,8)}`,v={role:"user",content:k,timestamp:g,_localId:S};n(M=>({...M,[b]:[...M[b]||[],v]}));try{const M=os(s);if(!M)return;const w=await t(M,"send_chat",{message:k,text:k,...Tt(s)});if(w!=null&&w.deduplicated||(w==null?void 0:w.sent)===!1){n(N=>({...N,[b]:(N[b]||[]).filter($=>$._localId!==S)}));return}setTimeout(()=>{const N=Date.now()-6e4;n($=>{const R=$[b];if(!R)return $;const E=R.filter(L=>L.timestamp>N);return E.length===R.length?$:{...$,[b]:E}})},6e4)}catch(M){console.error("Send failed",M),n(w=>({...w,[b]:(w[b]||[]).filter(N=>N._localId!==S)}))}finally{f.current=!1,l(!1)}},[s,t,n]),h=a.useCallback(async()=>{if(s)try{await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0})}catch(x){console.error("Relaunch failed",x)}},[s,t]),p=a.useCallback(async x=>{if(s){s.transport!=="pty"&&r(k=>[...k,{ideId:s.tabKey,text:`🖱️ **${x}** clicked`,timestamp:Date.now()}]);try{const b=(s.modalButtons||[]).indexOf(x),g=x.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),j=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),S=os(s);if(!S)return;(await t(S,"resolve_action",{button:x,action:j?"approve":"reject",...b>=0&&{buttonIndex:b},...Tt(s)})).success||r(M=>[...M,{ideId:s.tabKey,text:`⚠️ **${x}** failed — button not found`,timestamp:Date.now()}])}catch(k){console.error("[ModalButton] Error:",k),r(b=>[...b,{ideId:s.tabKey,text:`❌ **${x}** error`,timestamp:Date.now()}])}}},[s,t,r]),y=a.useCallback(async()=>{if(!(!s||o)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(x){console.error("Focus agent failed",x)}finally{c(!1)}}},[s,o,t]);return{isSendingChat:d,isFocusingAgent:o,handleSendChat:m,handleRelaunch:h,handleModalButton:p,handleFocusAgent:y}}const Gs=a.memo(function({activeConv:s,clearToken:n,isCliTerminal:r,ideEntry:i,terminalRef:o,handleModalButton:c,handleRelaunch:d,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p}){return e.jsxs(e.Fragment,{children:[e.jsx(cr,{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(zs,{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:d,children:"Relaunch with CDP"})]})}):null,s.transport==="pty"?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:r?"flex":"none",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Di,{activeConv:s,clearToken:n,terminalRef:o,handleSendChat:l,isSendingChat:f,isVisible:r})}),!r&&e.jsx("div",{style:{display:"flex",minHeight:0,flex:"1 1 0%",width:"100%",flexDirection:"column"},children:e.jsx(Rs,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p})})]}):e.jsx(Rs,{activeConv:s,ideEntry:i,handleSendChat:l,isSendingChat:f,handleFocusAgent:u,isFocusingAgent:m,actionLogs:h,userName:p})]})},(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);function ac({selectedConversation:t,isAcp:s,selectedIdeEntry:n,actionLogs:r,userName:i,isSendingChat:o,isFocusingAgent:c,onBack:d,onOpenNativeConversation:l,onOpenMachine:f,onOpenHistory:u,onOpenRemote:m,onHideConversation:h,onStopCli:p,cliViewMode:y,onSetCliViewMode:x,handleSendChat:k,handleFocusAgent:b,handleModalButton:g,handleRelaunch:j}){const S=a.useRef(null),v=Ee(t)&&!s,M=v&&y==="terminal";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(14px+env(safe-area-inset-top,0px))] pb-2.5 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(Ks,{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(pr,{conversation:t,className:"is-mobile-header",interactive:!1,onOpenNativeConversation:()=>l(t),onOpenMachine:()=>f(t)})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[v&&y&&e.jsx(Fs,{mode:y,onChange:x,compact:!0}),v&&p&&e.jsx("button",{onClick:()=>{p(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(jt,{size:14})}),e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>u(t),type:"button",children:e.jsx(Ws,{size:14})}),!s&&!v&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>m(t),type:"button",children:e.jsx(Fe,{size:14})}),h&&e.jsx("button",{className:"btn btn-secondary btn-sm",onClick:()=>h(t),type:"button",title:"Close chat",children:e.jsx(jt,{size:14})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col bg-bg-primary relative",children:e.jsx(Gs,{activeConv:t,clearToken:0,isCliTerminal:M,ideEntry:n,terminalRef:S,handleModalButton:g,handleRelaunch:j,handleSendChat:k,isSendingChat:o,handleFocusAgent:b,isFocusingAgent:c,actionLogs:r,userName:i})})]})}const Ns={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 ic(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Dr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(ic())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(Ns[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 ${n==="powershell"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent-primary/10 text-accent-primary":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-text-primary cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Ns[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Ns[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 Br({section:t,onSectionChange:s}){const n=[{key:"machines",label:"Machines",icon:Fe},{key:"chats",label:"Chats",icon:rt}];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:n.map(({key:r,label:i,icon:o})=>{const c=t===r;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(r),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})]},r)})})})}function qt({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:`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 Ct({icon:t,title:s,subtitle:n,children:r}){return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 pt-12 pb-8 px-6 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:n}),r]})}function Gt({item:t,type:s,getAvatarText:n,onOpenConversation:r}){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:()=>r(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:n(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:or(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(Fe,{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 Pn({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 oc({section:t,attentionItems:s,unreadItems:n,workingItems:r,completedItems:i,hiddenConversations:o,machineCards:c,getAvatarText:d,onOpenConversation:l,onShowConversation:f,onShowAllHidden:u,onOpenMachine:m,onOpenSettings:h,onSectionChange:p,wsStatus:y="connected",isStandalone:x=!1}){const k=y==="disconnected"||y==="reconnecting"||y==="offline"||y==="auth_failed",b=c.length>0,g=s.length>0||n.length>0||r.length>0||i.length>0,j=t==="machines"?"Machines":"Chats";return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:"px-5 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-4 shrink-0 bg-bg-primary z-10",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:j}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t==="chats"&&(s.length>0||n.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(us,{size:13}),e.jsx("span",{children:s.length+n.length})]}),e.jsx("button",{onClick:h,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(ds,{size:18})})]})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 pb-[calc(12px+env(safe-area-inset-bottom,0px))] flex flex-col gap-3 -webkit-overflow-scrolling-touch",children:[t==="machines"&&e.jsx("section",{className:"flex flex-col gap-2",children:k?e.jsx(Ct,{icon:e.jsx(Pn,{label:"Reconnecting…"}),title:"Connecting to server",subtitle:y==="offline"?"Your device appears to be offline. Waiting for network…":y==="auth_failed"?"Session expired. Please log in again.":"Establishing connection to the server. This usually takes a moment."}):c.length===0?e.jsx(Ct,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain animate-bounce",style:{animationDuration:"3s"}}),title:x?"Waiting for your IDE":"Connect your first machine",subtitle:x?"Launch any supported IDE or CLI agent — it will appear here automatically.":"Install the ADHDev daemon on your machine, then it will show up here.",children:!x&&e.jsx("div",{className:"w-full max-w-[360px] mt-4",children:e.jsx(Dr,{})})}):e.jsx(gt,{children:c.map((S,v)=>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] ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>m(S.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:d(S.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:S.label}),e.jsx("span",{className:"text-[11px] font-medium text-text-muted shrink-0",children:S.unread>0?e.jsxs("span",{className:"text-accent-primary",children:[S.unread," new"]}):S.total>0?`${S.total} chats`:"Idle"})]}),e.jsx("div",{className:"text-[12px] font-medium text-text-secondary truncate",children:S.subtitle}),S.total>0?e.jsxs("div",{className:"text-[13px] text-text-muted mt-0.5",children:[S.total," chat",S.total!==1?"s":"",S.unread>0?` · ${S.unread} unread`:""]}):e.jsx("div",{className:"text-[13px] text-text-muted mt-0.5 italic opacity-70",children:"No active chats"})]})]},S.id))})}),t==="chats"&&s.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(qt,{title:"Needs attention",className:"mb-0"}),e.jsx(gt,{children:s.map((S,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Gt,{item:S,type:"needs_attention",getAvatarText:d,onOpenConversation:l})},S.conversation.tabKey))})]}),t==="chats"&&n.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(qt,{title:"Task complete",className:"mb-0 mt-2"}),e.jsx(gt,{children:n.map((S,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Gt,{item:S,type:"task_complete",getAvatarText:d,onOpenConversation:l})},S.conversation.tabKey))})]}),t==="chats"&&r.length>0&&e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx(qt,{title:"Working now",className:"mb-0 mt-2"}),e.jsx(gt,{children:r.map((S,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Gt,{item:S,type:"working",getAvatarText:d,onOpenConversation:l})},S.conversation.tabKey))})]}),t==="chats"&&e.jsxs("section",{className:"flex flex-col gap-2",children:[i.length>0&&e.jsx(qt,{title:"Earlier",className:"mb-0 mt-2 border-border-subtle/80 bg-bg-secondary/35"}),i.length>0?e.jsx(gt,{children:i.map((S,v)=>e.jsx("div",{className:v>0?"border-t border-border-subtle/70":"",children:e.jsx(Gt,{item:S,type:"earlier",getAvatarText:d,onOpenConversation:l})},S.conversation.tabKey))}):g?e.jsx("div",{className:"py-8 text-center text-sm font-medium text-text-muted",children:"All caught up."}):k?e.jsx(Ct,{icon:e.jsx(Pn,{size:28}),title:"Connecting…",subtitle:"Waiting for server connection before loading conversations."}):b?e.jsx(Ct,{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(rt,{size:20})}),title:"No conversations yet",subtitle:"Your machines are connected. Open an IDE or launch a CLI agent to start your first conversation."}):e.jsx(Ct,{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 flex-col gap-2",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:u,children:"Restore all"})]}),e.jsx(gt,{className:"bg-bg-secondary/25",children:o.map((S,v)=>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 ${v>0?"border-t border-border-subtle/70":""}`,onClick:()=>f(S),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:d(S.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:S.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:[S.displaySecondary,S.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(Fe,{size:11})," ",S.machineName]})]})]}),e.jsx("div",{className:"text-[13px] text-text-muted truncate mt-0.5 opacity-90",children:"Tap to restore and open"})]})]},S.tabKey))})]})]}),e.jsx(Br,{section:t,onSectionChange:p})]})}function cc(t){const s=t.replace(/[\\/]+$/,"");if(!s||s==="/"||/^[A-Za-z]:$/.test(s))return null;const n=s.includes("\\")?"\\":"/",r=s.split(/[\\/]/);return/^[A-Za-z]:$/.test(r[0]||"")?r.length<=2?`${r[0]}\\`:r.slice(0,-1).join("\\"):r.length<=2?n:r.slice(0,-1).join(n)||n}async function Kr(t,s,n){const r=await t(s,"file_list_browse",{path:n});if(!(r!=null&&r.success))throw new Error((r==null?void 0:r.error)||"Could not browse folder");const i=typeof(r==null?void 0:r.path)=="string"?r.path:n,o=i.includes("\\")?"\\":"/",c=(l,f)=>/^[A-Za-z]:\\?$/.test(l)?`${l.replace(/\\?$/,"\\")}${f}`:l==="/"||l==="\\"?`${o}${f}`:`${l.replace(/[\\/]+$/,"")}${o}${f}`,d=Array.isArray(r==null?void 0:r.files)?r.files.filter(l=>(l==null?void 0:l.type)==="directory"&&typeof(l==null?void 0:l.name)=="string").map(l=>({name:l.name,path:c(i,l.name)})).sort((l,f)=>l.name.localeCompare(f.name)):[];return{path:i,directories:d}}function Ys({title:t,description:s,currentPath:n,directories:r,busy:i=!1,error:o="",confirmLabel:c="Use this folder",onClose:d,onNavigate:l,onConfirm:f}){const u=cc(n);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:d,"aria-label":"Close folder browser",children:e.jsx(jt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-3 border-b border-border-subtle bg-bg-primary/60 flex items-center 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:()=>{!u||i||l(u)},disabled:!u||i,children:[e.jsx(Ks,{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-0.5",children:"Current folder"}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:n||"Loading…"})]})]}),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}):r.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:r.map(m=>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:()=>l(m.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(Lt,{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:m.name}),e.jsx("span",{className:"block text-[11px] text-text-muted truncate",children:m.path})]})]},m.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:d,children:"Cancel"}),e.jsx("button",{type:"button",className:"btn btn-primary h-9 px-4 text-sm font-semibold",onClick:()=>f(n),disabled:!n||i,children:c})]})]})})}function Xs({title:t,description:s,details:n,workspaceOptions:r,selectedWorkspaceKey:i,onWorkspaceChange:o,confirmLabel:c="Launch",busy:d=!1,onConfirm:l,onCancel:f}){const u=r==null?void 0:r.find(m=>m.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:f,"aria-label":"Close launch confirmation",children:e.jsx(jt,{size:16})})]}),e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[r&&r.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:m=>o(m.target.value),className:"w-full rounded-lg border border-border-subtle bg-bg-secondary text-text-primary px-3 py-2.5 text-sm",disabled:d,children:r.map(m=>e.jsx("option",{value:m.key,children:m.label},m.key))}),(u==null?void 0:u.description)&&e.jsx("div",{className:"mt-2 text-[11px] text-text-muted break-all",children:u.description})]}),n.map(m=>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:m.label}),e.jsx("div",{className:"text-sm text-text-primary break-all",children:m.value})]},`${m.label}:${m.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:f,disabled:d,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:l,disabled:d,children:[e.jsx(nr,{size:14}),d?"Launching…":c]})]})]})})}function $n(t,s){return s||t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t}function xt(t){const{machine:s,currentWorkspacePath:n,currentWorkspaceId:r,includeHome:i=!0}=t,o=[];i&&o.push({key:"__home__",label:"Home directory",description:"Launch without a workspace",workspaceId:null,workspacePath:null});for(const l of s.workspaces||[])o.push({key:`saved:${l.id}`,label:`${l.id===s.defaultWorkspaceId?"⭐ ":""}${$n(l.path,l.label)}`,description:l.path,workspaceId:l.id,workspacePath:l.path});const c=(n==null?void 0:n.trim())||"",d=c?(s.workspaces||[]).find(l=>l.path===c):null;if(c&&!d&&o.push({key:`custom:${c}`,label:$n(c),description:c,workspaceId:null,workspacePath:c}),r){const l=`saved:${r}`;if(o.some(f=>f.key===l))return{options:o,selectedKey:l}}return d?{options:o,selectedKey:`saved:${d.id}`}:c?{options:o,selectedKey:`custom:${c}`}:{options:o,selectedKey:"__home__"}}function lc({selectedMachineEntry:t,selectedMachineConversations:s,selectedMachineRecentLaunches:n,cliProviders:r,acpProviders:i,selectedMachineNeedsUpgrade:o,appVersion:c,machineAction:d,section:l,showBottomNav:f,onBack:u,onSectionChange:m,onOpenConversation:h,onOpenRecent:p,onOpenMachineDetails:y,onMachineUpgrade:x,onLaunchDetectedIde:k,onAddWorkspace:b,onBrowseDirectory:g,onLaunchWorkspaceProvider:j}){var Ke,ze,We,De;const S=(re,ke,je)=>re?"ide":ke>0?"cli":je>0?"acp":null,[v,M]=a.useState(!1),w=re=>re==="ide"?"IDE":re==="cli"?"CLI":"ACP",N=n.slice(0,4),$=s.slice(0,3),R=(((Ke=t.detectedIdes)==null?void 0:Ke.length)||0)>0,E=a.useMemo(()=>t.workspaces||[],[t]),L=t.defaultWorkspaceId||null,[_,I]=a.useState(L||((ze=E[0])==null?void 0:ze.id)||""),[U,P]=a.useState(""),[z,T]=a.useState(""),[B,O]=a.useState([]),[D,X]=a.useState(!1),[xe,ee]=a.useState(""),[fe,F]=a.useState(!1),[q,V]=a.useState(S(R,r.length,i.length)),pe=a.useRef(null),[de,oe]=a.useState(null),ue=a.useRef("__home__"),[ae,ge]=a.useState("__home__"),[se,ce]=a.useState(!1),G=a.useRef(null),te=_==="__custom__"?U.trim():((We=E.find(re=>re.id===_))==null?void 0:We.path)||"",C=_==="__custom__"&&!!te&&d.state==="error"&&/(Directory path is not valid or does not exist|Path does not exist)/i.test(d.message),J=_!=="__custom__"&&((De=E.find(re=>re.id===_))==null?void 0:De.path)||"",Z=a.useCallback(async re=>{X(!0),ee("");try{const ke=await g(re);T(ke.path),P(ke.path),O(ke.directories)}catch(ke){ee(ke instanceof Error?ke.message:"Could not load folder")}finally{X(!1)}},[g]),ne=a.useCallback(()=>{var ke,je;I("__custom__"),F(!0);const re=U.trim()||J||((ke=E.find(ye=>ye.id===L))==null?void 0:ke.path)||((je=E[0])==null?void 0:je.path)||"~";Z(re)},[U,L,Z,J,E]),be=a.useCallback((re,ke)=>{pe.current=ke,ue.current=re.selectedWorkspaceKey||"__home__",ge(re.selectedWorkspaceKey||"__home__"),oe(re)},[]),we=a.useCallback(()=>{pe.current&&(ce(!0),pe.current().finally(()=>{pe.current=null,ce(!1),oe(null)}))},[]);a.useEffect(()=>{var re;G.current!==t.id&&(G.current=t.id,I(L||((re=E[0])==null?void 0:re.id)||"__custom__"),P(""),T(""),O([]),ee(""),F(!1),V(S(R,r.length,i.length)))},[i.length,r.length,L,R,t.id,E]),a.useEffect(()=>{var re;_!=="__custom__"&&(_&&E.some(ke=>ke.id===_)||I(L||((re=E[0])==null?void 0:re.id)||"__custom__"))},[L,_,E]),a.useEffect(()=>{q==="ide"&&R||q==="cli"&&r.length>0||q==="acp"&&i.length>0||V(S(R,r.length,i.length))},[q,i.length,r.length,R]);const Se=a.useMemo(()=>{const re=N.map(je=>({key:`recent-launch:${je.id}`,type:"session",primary:je.label,secondary:`${w(je.kind)}${je.subtitle?` · ${je.subtitle}`:""}`,unread:!1,onClick:()=>{const{options:ye,selectedKey:W}=xt({machine:{workspaces:E,defaultWorkspaceId:L},currentWorkspacePath:je.workspace});be({title:`Launch ${je.label}?`,description:"Recent launches require one more confirmation before they run.",confirmLabel:"Launch",workspaceOptions:ye,selectedWorkspaceKey:W,details:[{label:"Mode",value:w(je.kind)},...je.providerType?[{label:"Provider",value:je.providerType}]:[]]},async()=>{const K=ye.find(ie=>ie.key===ue.current);K!=null&&K.workspaceId?(I(K.workspaceId),P("")):K!=null&&K.workspacePath?(I("__custom__"),P(K.workspacePath)):(I(""),P("")),await p({...je,workspace:(K==null?void 0:K.workspacePath)??null})})}})),ke=$.map(je=>({key:`recent-chat:${je.conversation.tabKey}`,type:"conversation",primary:je.conversation.displayPrimary,secondary:`Chat${je.conversation.displaySecondary?` · ${je.conversation.displaySecondary}`:""}${je.timestamp?` · ${or(je.timestamp)}`:""}`,unread:je.unread,onClick:()=>h(je.conversation)}));return[...re,...ke]},[L,h,p,be,$,N,E]),Te=v?Se:Se.slice(0,5),Ze=Se.length>0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-4 pt-[calc(16px+env(safe-area-inset-top,0px))] pb-3 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:u,type:"button","aria-label":"Back",children:e.jsx(Ks,{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:tt(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:[Ze&&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"}),e.jsx("div",{className:"grid grid-cols-1 gap-2.5 px-4",children:Te.map(re=>e.jsxs("button",{className:`flex flex-col gap-1 w-full text-left p-[14px] rounded-2xl border ${re.unread?"border-accent-primary/25 bg-accent-primary/5":"border-border-default/80 bg-surface-primary/90"} text-text-primary`,type:"button",onClick:re.onClick,children:[e.jsx("span",{className:"text-sm font-bold text-text-primary",children:re.primary}),e.jsx("span",{className:"text-xs leading-relaxed text-text-secondary",children:re.secondary})]},re.key))}),Se.length>5&&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:()=>M(re=>!re),children:v?"Show fewer":`Show ${Se.length-5} more`})})]}),(R||r.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:re=>{const ke=re.target.value;if(I(ke),ke==="__custom__"){ne();return}P("")},className:"w-full rounded-xl border border-border-default/90 bg-bg-primary/90 text-text-primary px-3 py-3 text-sm",children:E.length>0?e.jsxs(e.Fragment,{children:[E.map(re=>e.jsxs("option",{value:re.id,children:[re.id===L?"⭐ ":"",re.label||re.path.split("/").filter(Boolean).pop()||re.path]},re.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(Lt,{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:te||z||"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:ne,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:()=>{te&&b(te)},disabled:!te||D,children:"Save as workspace"})]})]}),te&&e.jsx("div",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:te})]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-4",children:[R&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${q==="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:()=>V("ide"),children:"IDE"}),r.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${q==="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:()=>V("cli"),children:"CLI"}),i.length>0&&e.jsx("button",{className:`min-h-[40px] rounded-full border text-xs font-bold ${q==="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:()=>V("acp"),children:"ACP"})]}),q&&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:q==="ide"?"Choose an IDE":q==="cli"?"Choose a CLI provider":"Choose an ACP provider"}),e.jsx("div",{className:"grid grid-cols-1 gap-2",children:q==="ide"?(t.detectedIdes||[]).slice(0,6).map(re=>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:ke,selectedKey:je}=xt({machine:{workspaces:E,defaultWorkspaceId:L},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:te});be({title:`Launch ${re.name}?`,description:"Review or change the target folder before opening this IDE.",confirmLabel:"Launch IDE",workspaceOptions:ke,selectedWorkspaceKey:je,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:re.name}]},async()=>{const ye=ke.find(W=>W.key===ue.current);ye!=null&&ye.workspaceId?(I(ye.workspaceId),P("")):ye!=null&&ye.workspacePath?(I("__custom__"),P(ye.workspacePath)):(I(""),P("")),k(re.type,{workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsx("span",{className:"text-[13px] font-bold text-text-primary",children:re.name}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:te||"Use selected workspace"})]},re.type)):(q==="cli"?r:i).map(re=>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:ke,selectedKey:je}=xt({machine:{workspaces:E,defaultWorkspaceId:L},currentWorkspaceId:_!=="__custom__"?_:null,currentWorkspacePath:te});be({title:`Launch ${re.displayName}?`,description:"Review or change the provider workspace before starting this session.",confirmLabel:`Launch ${q.toUpperCase()}`,workspaceOptions:ke,selectedWorkspaceKey:je,details:[{label:"Mode",value:q.toUpperCase()},{label:"Provider",value:re.displayName}]},async()=>{const ye=ke.find(W=>W.key===ue.current);ye!=null&&ye.workspaceId?(I(ye.workspaceId),P("")):ye!=null&&ye.workspacePath?(I("__custom__"),P(ye.workspacePath)):(I(""),P("")),j(q,re.type,{workspaceId:(ye==null?void 0:ye.workspaceId)??null,workspacePath:(ye==null?void 0:ye.workspacePath)??null})})},children:[e.jsxs("span",{className:"text-[13px] font-bold text-text-primary",children:[re.icon?`${re.icon} `:"",re.displayName]}),e.jsx("span",{className:"text-[11px] leading-relaxed text-text-muted break-all",children:te||"Use selected workspace"})]},re.type))})]}),d.message&&e.jsxs("div",{className:`mx-4 mt-2.5 p-3 rounded-xl text-xs leading-relaxed ${d.state==="error"?"text-status-error bg-status-error/10":"text-text-secondary bg-surface-primary/90"}`,children:[d.message,C&&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:()=>b(te,{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:x,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:y,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"})]})]})]})]}),fe&&e.jsx(Ys,{title:"Select workspace",description:"Move through folders like a normal explorer, then use the current folder for this machine.",currentPath:z,directories:B,busy:D,error:xe,confirmLabel:"Use this folder",onClose:()=>F(!1),onNavigate:re=>{Z(re)},onConfirm:re=>{P(re),I("__custom__"),F(!1)}}),de&&e.jsx(Xs,{title:de.title,description:de.description,details:de.details,workspaceOptions:de.workspaceOptions,selectedWorkspaceKey:ae,onWorkspaceChange:re=>{ue.current=re,ge(re)},confirmLabel:de.confirmLabel,busy:se,onConfirm:we,onCancel:()=>{pe.current=null,oe(null)}}),f&&e.jsx(Br,{section:l,onSectionChange:m})]})}function dc(t){return br(t)}function En(t){const s=[...t.messages].reverse().find(r=>!(r!=null&&r._localId))||t.messages[t.messages.length-1],n=dc(s==null?void 0:s.content);return n||(t.title?t.title:t.displaySecondary||"No messages yet")}function uc(t){const s=t.trim();return s?s[0].toUpperCase():"?"}function Yt(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[mobile-read] ${t}`,s)}catch{}}function pc({conversations:t,hiddenConversations:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,requestedActiveTabKey:f,onRequestedActiveTabConsumed:u,requestedMachineId:m,onRequestedMachineConsumed:h,requestedMobileSection:p,onRequestedMobileSectionConsumed:y,onOpenHistory:x,onOpenRemote:k,onStopCli:b,wsStatus:g,isConnected:j,onShowHiddenConversation:S,onShowAllHiddenConversations:v,onHideConversation:M}){const[w,N]=a.useState(()=>{var W;return((W=t[0])==null?void 0:W.tabKey)||null}),[$,R]=a.useState(()=>t[0]?"chat":"inbox"),[E,L]=a.useState("chats"),[_,I]=a.useState(null),[U,P]=a.useState("inbox"),[z,T]=a.useState("idle"),[B,O]=a.useState(""),D=a.useRef(null),X=kt(),xe="0.8.6",ee=a.useMemo(()=>t.find(W=>W.tabKey===w)||t[0]||null,[t,w]),fe=a.useMemo(()=>ee?n.find(W=>W.id===ee.ideId):void 0,[n,ee]),F=a.useMemo(()=>!ee||_e(ee)||!Ee(ee)?null:wt(ee),[ee]),q=a.useMemo(()=>n.filter(W=>W.type==="adhdev-daemon"||W.daemonMode).sort(_i),[n]),V=a.useMemo(()=>q.find(W=>W.id===_)||null,[q,_]),pe=a.useMemo(()=>Dt(n),[n]),de=xs({sendDaemonCommand:i,activeConv:ee||void 0,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),oe=a.useCallback(W=>{if(!W||!W.sessionId)return;const K=Pt(W,pe),ie=Math.max(Date.now(),vt(W),K.lastUpdated||0);Yt("mark_read:start",{tabKey:W.tabKey,sessionId:W.sessionId,displayPrimary:W.displayPrimary,inboxBucket:K.inboxBucket,unread:K.unread,lastSeenAt:K.lastSeenAt,lastUpdated:K.lastUpdated,activityAt:vt(W),readAt:ie}),i(W.daemonId||W.ideId,"mark_session_seen",{sessionId:W.sessionId,seenAt:ie}).then(le=>{Yt("mark_read:result",{tabKey:W.tabKey,sessionId:W.sessionId,result:le})}).catch(le=>{Yt("mark_read:error",{tabKey:W.tabKey,sessionId:W.sessionId,error:le instanceof Error?le.message:String(le)})})},[pe,i]);a.useEffect(()=>{var K;if(!ee){R("inbox"),N(((K=t[0])==null?void 0:K.tabKey)||null),D.current=null;return}if($!=="chat"){D.current=null;return}const W=`${ee.tabKey}:${ee.sessionId||""}`;D.current!==W&&(D.current=W,oe(ee))},[t,oe,$,ee]),a.useEffect(()=>{if(!f)return;const W=t.find(K=>K.tabKey===f);W&&(N(W.tabKey),R("chat"),u==null||u())},[t,u,f]),a.useEffect(()=>{if(!m)return;const W=q.find(K=>K.id===m);W&&(I(W.id),T("idle"),O(""),L("machines"),P("inbox"),R("machine"),h==null||h())},[q,h,m]),a.useEffect(()=>{p&&(L(p),R("inbox"),y==null||y())},[y,p]);const ue=a.useMemo(()=>t.map(W=>{const K=$==="chat"&&(ee==null?void 0:ee.tabKey)===W.tabKey,ie=$t(W,pe,{hideOpenTaskCompleteUnread:!0,isOpenConversation:K}),le=vt(W),A=En(W);return{conversation:W,timestamp:le,preview:A,unread:ie.unread,requiresAction:ie.requiresAction,isWorking:ie.isWorking,inboxBucket:ie.inboxBucket}}).sort((W,K)=>Rr(W.conversation,K.conversation)),[t,pe,$,ee]);a.useEffect(()=>{const W=ue.filter(K=>K.inboxBucket==="task_complete"||K.unread);W.length!==0&&Yt("inbox_state",{screen:$,selectedTabKey:w,items:W.map(K=>{const ie=Pt(K.conversation,pe);return{liveState:ie,tabKey:K.conversation.tabKey,sessionId:K.conversation.sessionId,displayPrimary:K.conversation.displayPrimary,serverBucket:ie.inboxBucket,computedBucket:K.inboxBucket,serverUnread:ie.unread,computedUnread:K.unread,lastSeenAt:ie.lastSeenAt,lastUpdated:ie.lastUpdated,activityAt:vt(K.conversation)}})})},[ue,pe,$,w]);const ae=a.useMemo(()=>ue.filter(W=>W.requiresAction),[ue]),ge=a.useMemo(()=>ue.filter(W=>W.unread&&!W.requiresAction),[ue]),se=a.useMemo(()=>ue.filter(W=>!W.unread&&!W.requiresAction&&W.isWorking),[ue]),ce=a.useMemo(()=>ue.filter(W=>!W.unread&&!W.requiresAction&&!W.isWorking),[ue]),G=a.useMemo(()=>V?ue.filter(W=>W.conversation.daemonId===V.id||W.conversation.ideId===V.id):[],[ue,V]),te=a.useMemo(()=>{if(!V)return[];const W=V.recentLaunches||[];return W.length>0?W.map(K=>({id:K.id,label:K.title||K.providerName||K.providerType,kind:K.kind,providerType:K.providerType,providerSessionId:K.providerSessionId,subtitle:K.currentModel||K.workspace||void 0,workspace:K.workspace,currentModel:K.currentModel})):n.filter(K=>!K.daemonMode&&K.daemonId===V.id).map(K=>{var le,A,Y,Q,H;const ie=ns(K)?"cli":It(K)?"acp":"ide";return{id:`${ie}:${K.type}:${K.workspace||""}`,label:((le=K.activeChat)==null?void 0:le.title)||(ns(K)?K.cliName||K.type:It(K)&&K.cliName||K.type),kind:ie,providerType:K.type,providerSessionId:K.providerSessionId,subtitle:It(K)?K.currentModel||K.workspace||void 0:K.workspace||void 0,workspace:K.workspace||void 0,currentModel:K.currentModel,timestamp:((H=(Q=(Y=(A=K.activeChat)==null?void 0:A.messages)==null?void 0:Y.at)==null?void 0:Q.call(Y,-1))==null?void 0:H.timestamp)||0}}).sort((K,ie)=>ie.timestamp-K.timestamp).map(({timestamp:K,...ie})=>ie)},[n,V]),C=(V==null?void 0:V.version)||(V==null?void 0:V.daemonVersion)||null,J=!!V&&!!C&&!0&&C!==xe,Z=a.useMemo(()=>(V==null?void 0:V.availableProviders)||[],[V]),ne=a.useMemo(()=>Z.filter(W=>W.category==="cli").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[Z]),be=a.useMemo(()=>Z.filter(W=>W.category==="acp").map(W=>({type:W.type,displayName:W.displayName||W.type,icon:W.icon})),[Z]),we=a.useMemo(()=>{const W=new Map;for(const K of ue){const ie=K.conversation.daemonId||K.conversation.ideId,le=W.get(ie);le?le.push(K):W.set(ie,[K])}return q.map(K=>{const ie=W.get(K.id)||[],le=[...ie].sort((me,Ae)=>Ae.timestamp-me.timestamp)[0]||null,A=(le==null?void 0:le.conversation)||null,Y=Ts(K),Q=ie.filter(me=>me.unread||me.requiresAction).length,H=K.status==="online"?"Connected":K.status||"Unknown",Le=[K.platform||"machine",H].filter(Boolean);return{id:K.id,label:tt(K,{fallbackId:K.id}),subtitle:Le.join(" · "),unread:Q,total:ie.length,latestConversation:A,latestTimestamp:(le==null?void 0:le.timestamp)||0,fallbackActivityAt:Y,preview:A?`${A.displayPrimary} · ${En(A)}`:"No active conversations yet. Open the machine to launch an IDE, CLI, or ACP session."}}).sort((K,ie)=>{const le=K.latestTimestamp||K.fallbackActivityAt||0,A=ie.latestTimestamp||ie.fallbackActivityAt||0;return A!==le?A-le:K.label.localeCompare(ie.label)})},[ue,q]),Se=a.useCallback(W=>{N(W.tabKey),R("chat"),oe(W)},[oe]),Te=a.useCallback(W=>{const K=t.find(ie=>ie.ideId===W.ideId&&ie.streamSource==="native");K&&(N(K.tabKey),R("chat"),oe(K))},[t,oe]),Ze=a.useCallback(()=>{oe(ee),R("inbox")},[oe,ee]),Ke=a.useCallback(W=>{I(W),T("idle"),O(""),L("machines"),P("inbox"),R("machine")},[]),ze=a.useCallback(W=>{var ie;const K=W.daemonId||((ie=W.ideId)==null?void 0:ie.split(":")[0])||W.ideId;K&&(I(K),T("idle"),O(""),L("machines"),P("chat"),R("machine"))},[]),We=a.useCallback(()=>{R(U)},[U]),De=a.useCallback(async(W,K,ie)=>{var le;try{T("loading"),O(`Launching ${K}…`);const A={ideType:K,enableCdp:!0};(le=ie==null?void 0:ie.workspacePath)!=null&&le.trim()&&(A.workspace=ie.workspacePath.trim()),await i(W,"launch_ide",A),T("done"),O(`${K} launch requested`)}catch(A){T("error"),O(A instanceof Error?A.message:"Launch IDE failed"),console.error("Launch IDE failed",A)}},[i]),re=a.useCallback(async(W,K,ie)=>{if(K.trim())try{T("loading"),O(ie!=null&&ie.createIfMissing?"Creating folder…":"Saving workspace…");const le=await i(W,"workspace_add",{path:K.trim(),createIfMissing:(ie==null?void 0:ie.createIfMissing)===!0});if(le!=null&&le.success){T("done"),O(ie!=null&&ie.createIfMissing?"Folder created and workspace saved":"Workspace saved");return}T("error"),O((le==null?void 0:le.error)||"Could not save workspace")}catch(le){T("error"),O(le instanceof Error?le.message:"Could not save workspace")}},[i]),ke=a.useCallback(async W=>{var K,ie,le,A,Y,Q;try{T("loading"),O("Starting daemon upgrade…");const H=await i(W,"daemon_upgrade",{});if((K=H==null?void 0:H.result)!=null&&K.alreadyLatest){T("done"),O(`Already on v${((ie=H==null?void 0:H.result)==null?void 0:ie.version)||"latest"}.`);return}if((le=H==null?void 0:H.result)!=null&&le.upgraded||(A=H==null?void 0:H.result)!=null&&A.success){T("done"),O(`Upgrade to v${((Y=H==null?void 0:H.result)==null?void 0:Y.version)||"latest"} started. Daemon is restarting…`);return}T("error"),O(((Q=H==null?void 0:H.result)==null?void 0:Q.error)||"Upgrade failed")}catch(H){T("error"),O(H instanceof Error?H.message:"Upgrade failed")}},[i]),je=a.useCallback(async(W,K,ie,le)=>{var A;try{T("loading"),O(`Launching ${ie}…`);const Y={cliType:ie};(A=le==null?void 0:le.workspacePath)!=null&&A.trim()?Y.dir=le.workspacePath.trim():le!=null&&le.workspaceId&&(Y.workspaceId=le.workspaceId),le!=null&&le.resumeSessionId&&(Y.resumeSessionId=le.resumeSessionId);const Q=await i(W,"launch_cli",Y),H=(Q==null?void 0:Q.result)||Q,Le=(H==null?void 0:H.sessionId)||(H==null?void 0:H.id);if(Q!=null&&Q.success&&Le){T("done"),O(`${ie} launched`),X(`/dashboard?activeTab=${encodeURIComponent(Le)}`);return}T("error"),O((Q==null?void 0:Q.error)||(H==null?void 0:H.error)||`Could not launch ${K.toUpperCase()} workspace`)}catch(Y){T("error"),O(Y instanceof Error?Y.message:`Could not launch ${K.toUpperCase()} workspace`)}},[X,i]),ye=a.useCallback(async W=>{if(V){if(W.kind==="ide"&&W.providerType){await De(V.id,W.providerType,{workspacePath:W.workspace||null});return}if((W.kind==="cli"||W.kind==="acp")&&W.providerType){await je(V.id,W.kind,W.providerType,{workspacePath:W.workspace||null,resumeSessionId:W.providerSessionId||null});return}}},[De,je,V]);return e.jsx("div",{className:"dashboard-mobile-chat",children:$==="chat"&&ee?e.jsx(ac,{selectedConversation:ee,isAcp:_e(ee),selectedIdeEntry:fe,actionLogs:r,userName:l,isSendingChat:de.isSendingChat,isFocusingAgent:de.isFocusingAgent,handleModalButton:de.handleModalButton,handleRelaunch:de.handleRelaunch,onBack:Ze,onOpenNativeConversation:Te,onOpenMachine:ze,onHideConversation:M,onOpenHistory:x,onOpenRemote:k,onStopCli:b,cliViewMode:F,onSetCliViewMode:async W=>{if(ee&&F!==W)try{await i(ee.daemonId||ee.ideId,"set_cli_view_mode",{targetSessionId:ee.sessionId,cliType:ee.ideType||ee.agentType,mode:W})}catch(K){console.error("Failed to switch CLI view mode:",K)}},handleSendChat:de.handleSendChat,handleFocusAgent:de.handleFocusAgent}):$==="machine"&&V?e.jsx(lc,{selectedMachineEntry:V,selectedMachineConversations:G,selectedMachineRecentLaunches:te,cliProviders:ne,acpProviders:be,selectedMachineNeedsUpgrade:J,appVersion:xe,machineAction:{state:z,message:B},section:E,showBottomNav:U==="inbox",onBack:We,onSectionChange:W=>{L(W),R("inbox")},onOpenConversation:Se,onOpenRecent:ye,onOpenMachineDetails:()=>X(`/machines/${V.id}`),onMachineUpgrade:()=>ke(V.id),onLaunchDetectedIde:(W,K)=>De(V.id,W,K),onAddWorkspace:(W,K)=>re(V.id,W,K),onBrowseDirectory:async W=>{const K=await i(V.id,"file_list_browse",{path:W});if(!(K!=null&&K.success))throw new Error((K==null?void 0:K.error)||"Could not browse folder");const ie=typeof(K==null?void 0:K.path)=="string"?K.path:W,le=ie.includes("\\")?"\\":"/",A=(Q,H)=>/^[A-Za-z]:\\?$/.test(Q)?`${Q.replace(/\\?$/,"\\")}${H}`:Q==="/"||Q==="\\"?`${le}${H}`:`${Q.replace(/[\\/]+$/,"")}${le}${H}`,Y=Array.isArray(K==null?void 0:K.files)?K.files.filter(Q=>(Q==null?void 0:Q.type)==="directory"&&typeof(Q==null?void 0:Q.name)=="string").map(Q=>({name:Q.name,path:A(ie,Q.name)})).sort((Q,H)=>Q.name.localeCompare(H.name)):[];return{path:ie,directories:Y}},onLaunchWorkspaceProvider:(W,K,ie)=>je(V.id,W,K,ie)}):e.jsx(oc,{section:E,attentionItems:ae,unreadItems:ge,workingItems:se,completedItems:ce,hiddenConversations:s,machineCards:we,getAvatarText:uc,onOpenConversation:Se,onShowConversation:S,onShowAllHidden:v,onOpenMachine:Ke,onOpenSettings:()=>X("/settings"),onSectionChange:L,wsStatus:g,isConnected:j,isStandalone:d})})}function Ss(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function xc({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:i,onClearPreviewOrder:o}){const c=a.useRef(0),[d,l]=a.useState(!1),[f,u]=a.useState(null),m=a.useCallback(()=>{c.current=0,l(!1),u(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",m),window.addEventListener("drop",m),()=>{window.removeEventListener("dragend",m),window.removeEventListener("drop",m)}),[m]);const h=a.useCallback(k=>{k.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),p=a.useCallback(k=>{if(!k.dataTransfer.types.includes("text/tab-key"))return;if(k.preventDefault(),!Ss(s,n)){u("merge");return}const b=k.currentTarget.getBoundingClientRect(),g=k.clientX-b.left,j=b.width/3;g<j?u("split-left"):g>j*2?u("split-right"):u("merge")},[s,n]),y=a.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),x=a.useCallback(k=>{c.current=0,l(!1);const b=k.dataTransfer.getData("text/tab-key"),g=b?t.some(S=>S.tabKey===b):!1,j=f;if(u(null),o(),!!b){if(k.preventDefault(),j==="split-left"&&Ss(s,n)){n==null||n(b,"split-left");return}if(j==="split-right"&&Ss(s,n)){n==null||n(b,"split-right");return}if(g){i(b);return}r==null||r(b)}},[t,f,s,n,r,i,o]);return{dragOver:d,dropAction:f,resetDragState:m,handleDragEnter:h,handleDragOver:p,handleDragLeave:y,handleDrop:x}}function mc(t,s){const n=new Set(s.map(o=>o.tabKey)),r=t.filter(o=>n.has(o)),i=s.filter(o=>!t.includes(o.tabKey)).map(o=>o.tabKey);return[...r,...i]}function fc({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:i}){const[o,c]=a.useState(s??null),[d,l]=a.useState(n??[]),[f,u]=a.useState(null),m=a.useRef(null),h=a.useRef(null),p=a.useRef(r),y=a.useRef(i);a.useEffect(()=>{p.current=r},[r]),a.useEffect(()=>{y.current=i},[i]),a.useEffect(()=>{s&&s!==o&&c(s)},[s,o]),a.useEffect(()=>{l(w=>{const N=mc(w,t);return N.length===w.length&&N.every(($,R)=>$===w[R])?w:N})},[t]);const x=a.useMemo(()=>{const w=f??d;if(w.length===0)return t;const N=new Map(w.map(($,R)=>[$,R]));return[...t].sort(($,R)=>{const E=N.get($.tabKey)??999,L=N.get(R.tabKey)??999;return E-L})},[t,f,d]);a.useEffect(()=>{var N,$;if(x.length===0){o!==null&&(c(null),(N=p.current)==null||N.call(p,null));return}if(o&&x.some(R=>R.tabKey===o))return;const w=x[0].tabKey;w!==o&&(c(w),($=p.current)==null||$.call(p,w))},[x,o]);const k=a.useMemo(()=>x.find(w=>w.tabKey===o),[x,o]),b=a.useCallback(w=>{var N;c(w),(N=p.current)==null||N.call(p,w)},[]),g=a.useCallback((w,N,$)=>{l(R=>{var I;const E=R.filter(U=>U!==w),L=E.indexOf(N);if(L<0)return R;const _=$==="left"?L:L+1;return E.splice(_,0,w),(I=y.current)==null||I.call(y,E),E}),u(null)},[]),j=a.useCallback((w,N,$)=>{const E=(d.length>0?d:t.map(I=>I.tabKey)).filter(I=>I!==w),L=E.indexOf(N);if(L<0)return;const _=$==="left"?L:L+1;E.splice(_,0,w),m.current=E,u(E)},[d,t]),S=a.useCallback(()=>{var N;const w=m.current;w&&(l(w),(N=y.current)==null||N.call(y,w))},[]),v=a.useCallback(()=>{m.current=null,u(null)},[]),M=a.useCallback(w=>{l(N=>{var R;const $=N.filter(E=>E!==w);return $.push(w),(R=y.current)==null||R.call(y,$),$})},[]);return{activeTabId:o,activeConv:k,sortedConversations:x,previewOrderRef:m,draggingTabRef:h,selectTab:b,handleTabReorder:g,updatePreviewOrder:j,commitPreviewOrder:S,clearPreviewOrder:v,moveTabToEnd:M,setDraggingTabKey:w=>{h.current=w}}}function hc({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 Zs({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:i}){return t===0&&!s&&r&&i?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:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(Dr,{}),n&&r.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:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(o=>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:()=>i(o.type),children:[e.jsx(rr,{size:14,className:"opacity-70"})," Launch ",o.name]},o.type))})]}),!n&&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 Wr="adhdev-tab-shortcuts";function bc(){try{return JSON.parse(localStorage.getItem(Wr)||"{}")}catch{return{}}}function gc({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[i,o]=a.useState(()=>bc()),[c,d]=a.useState(null),l=a.useCallback(u=>{const m=[];return u.metaKey&&m.push(r?"⌘":"Meta"),u.ctrlKey&&m.push("Ctrl"),u.altKey&&m.push(r?"⌥":"Alt"),u.shiftKey&&m.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(m.push(u.key.length===1?u.key.toUpperCase():u.key),m.join("+"))},[r]),f=a.useCallback(u=>{o(u);try{localStorage.setItem(Wr,JSON.stringify(u))}catch{}},[]);return a.useEffect(()=>{if(!c)return;const u=m=>{if(m.preventDefault(),m.stopPropagation(),m.key==="Escape"){d(null);return}const h=l(m);if(!h)return;const p={...i};for(const[y,x]of Object.entries(p))x===h&&delete p[y];p[c]=h,f(p),d(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,i,f,l]),a.useEffect(()=>{const u=m=>{if(!(!m.ctrlKey&&!m.metaKey&&!m.altKey)){for(const[h,p]of Object.entries(i))if(t.includes(h)&&l(m)===p){m.preventDefault(),s(),n(h);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i,t,s,n,l]),{isMac:r,tabShortcuts:i,shortcutListening:c,setShortcutListening:d,saveShortcuts:f}}const yc=a.memo(function({conv:s,isActive:n,isDraggedTab:r,isTaskCompleteUnread:i,shortcut:o,conversationKeys:c,draggingTabRef:d,onFocus:l,onSelectTab:f,onConversationActivated:u,onPreviewReorder:m,onReorderTab:h,onCommitPreviewOrder:p,onClearPreviewOrder:y,onDragStateReset:x,onDragTabKeyChange:k,onReceiveTab:b,onOpenContextMenu:g,longPressTimer:j,isGroupActive:S}){const v=ps(s),M=v.isGenerating?"agent-tab-generating":v.isWaiting?"agent-tab-waiting":"",w=v.isReconnecting,N=a.useCallback(z=>{d.current=s.tabKey,k(s.tabKey),z.dataTransfer.setData("text/tab-key",s.tabKey),z.dataTransfer.effectAllowed="move"},[s.tabKey,d,k]),$=a.useCallback(()=>{d.current=null,k(null),p(),y(),x()},[d,k,p,y,x]),R=a.useCallback(z=>{const T=d.current;if(!(!T||T===s.tabKey)&&z.dataTransfer.types.includes("text/tab-key")){z.preventDefault(),z.stopPropagation();const B=z.currentTarget.getBoundingClientRect(),O=z.clientX<B.left+B.width/2?"left":"right";m(T,s.tabKey,O)}},[s.tabKey,d,m]),E=a.useCallback(z=>{z.preventDefault(),z.stopPropagation();const T=z.dataTransfer.getData("text/tab-key");if(T&&T!==s.tabKey){const B=z.currentTarget.getBoundingClientRect(),O=z.clientX<B.left+B.width/2?"left":"right";c.includes(T)?h(T,s.tabKey,O):b&&b(T)}y()},[s.tabKey,c,h,b,y]),L=a.useCallback(z=>{z.stopPropagation(),l(),f(s.tabKey),u(s)},[s,u,l,f]),_=a.useCallback(z=>{z.preventDefault(),g(z.clientX,z.clientY,s.tabKey)},[s.tabKey,g]),I=a.useCallback(z=>{const T=z.touches[0];j.current=setTimeout(()=>{g(T.clientX,T.clientY,s.tabKey)},600)},[s.tabKey,j,g]),U=a.useCallback(()=>{j.current&&clearTimeout(j.current)},[j]),P=["adhdev-dockview-tab",M,n&&"is-active",S&&"is-group-active",w&&"is-reconnecting"].filter(Boolean).join(" ");return e.jsxs("div",{"data-tabkey":s.tabKey,className:P,draggable:!0,onDragStart:N,onDragEnd:$,onDragOver:R,onDrop:E,onClick:L,onContextMenu:_,onTouchStart:I,onTouchEnd:U,onTouchMove:U,style:{cursor:"pointer",opacity:r?.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:v.isGenerating?e.jsx("div",{className:"tab-spinner"}):v.isWaiting?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):w?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"○"}):v.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:w?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):v.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 vc({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,unreadTabKeys:i,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:y,onMoveTab:x,onReceiveTab:k,onHideTab:b,isGroupActive:g}){const[j,S]=a.useState(null),v=a.useRef(null),M=a.useRef(null),w=a.useMemo(()=>t.map(I=>I.tabKey),[t]);Et("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(j==null?void 0:j.tabKey)||null});const{isMac:N,tabShortcuts:$,shortcutListening:R,setShortcutListening:E,saveShortcuts:L}=gc({sortedTabKeys:t.map(I=>I.tabKey),onFocus:c,onSelectTab:d});a.useEffect(()=>{if(!j)return;const I=U=>{const P=document.querySelector("[data-pane-context-menu]");P&&P.contains(U.target)||S(null)};return window.addEventListener("mousedown",I,!0),()=>window.removeEventListener("mousedown",I,!0)},[j]),a.useEffect(()=>{const I=M.current;if(!I)return;const U=P=>{Math.abs(P.deltaY)>Math.abs(P.deltaX)&&(P.preventDefault(),I.scrollLeft+=P.deltaY)};return I.addEventListener("wheel",U,{passive:!1}),()=>I.removeEventListener("wheel",U)},[]);const _=a.useCallback((I,U,P)=>{S({x:I,y:U,tabKey:P})},[]);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:M,className:"flex-1 flex overflow-x-auto overflow-y-visible gap-1.5 select-none",style:{scrollbarWidth:"none"},children:[t.map(I=>e.jsx(yc,{conv:I,isActive:s===I.tabKey,isDraggedTab:o.current===I.tabKey,isTaskCompleteUnread:i.has(I.tabKey),shortcut:$[I.tabKey],conversationKeys:w,draggingTabRef:o,onFocus:c,onSelectTab:d,onConversationActivated:l,onPreviewReorder:f,onReorderTab:u,onCommitPreviewOrder:m,onClearPreviewOrder:h,onDragStateReset:p,onDragTabKeyChange:y,onReceiveTab:k,onOpenContextMenu:_,longPressTimer:v,isGroupActive:g},I.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),j&&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:j.x,top:j.y},children:[x&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(j.tabKey,"left"),S(null)},children:"← Move to Left Group"}),x&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(j.tabKey,"right"),S(null)},children:"Move to Right Group →"}),x&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(j.tabKey,"split-left"),S(null)},children:"⇤ Split Left"}),x&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{x(j.tabKey,"split-right"),S(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:I=>{I.stopPropagation(),E(j.tabKey),S(null)},children:["⌨ ",$[j.tabKey]?`Change shortcut (${$[j.tabKey]})`:"Set shortcut"]}),$[j.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 I={...$};delete I[j.tabKey],L(I),S(null)},children:"✕ Remove shortcut"}),b&&e.jsxs(e.Fragment,{children:[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:()=>{b(j.tabKey),S(null)},children:"🚫 Hide from Dashboard"})]}),!x&&!b&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),R&&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:()=>E(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:I=>I.stopPropagation(),children:[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. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+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 jc({conversations:t,ides:s,clearedTabs:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,groupIndex:f,onFocus:u,isSplitMode:m,numGroups:h,onMoveTab:p,onReceiveTab:y,style:x,detectedIdes:k,handleLaunchIde:b,onActiveTabChange:g,initialActiveTabId:j,initialTabOrder:S,onTabOrderChange:v,onHideTab:M,isFocused:w}){const{sendCommand:N}=ct(),$=a.useRef(null),{activeTabId:R,activeConv:E,sortedConversations:L,draggingTabRef:_,selectTab:I,handleTabReorder:U,updatePreviewOrder:P,commitPreviewOrder:z,clearPreviewOrder:T,moveTabToEnd:B,setDraggingTabKey:O}=fc({conversations:t,initialActiveTabId:j,initialTabOrder:S,onActiveTabChange:g,onTabOrderChange:v}),D=xs({sendDaemonCommand:i,activeConv:E,setLocalUserMessages:o,setActionLogs:c,isStandalone:d}),{dragOver:X,dropAction:xe,resetDragState:ee,handleDragEnter:fe,handleDragOver:F,handleDragLeave:q,handleDrop:V}=xc({conversations:t,numGroups:h,onMoveTab:p,onReceiveTab:y,onOwnTabDrop:B,onClearPreviewOrder:T}),pe=E&&!_e(E)&&wt(E)==="terminal",de=a.useMemo(()=>E?s.find(se=>se.id===E.ideId):void 0,[s,E]),oe=a.useMemo(()=>E?r.filter(se=>se.ideId===E.tabKey):[],[r,E]),ue=a.useMemo(()=>Dt(s),[s]),ae=a.useMemo(()=>new Set(L.filter(se=>pi(se,ue,{isOpenConversation:se.tabKey===R})).map(se=>se.tabKey)),[R,ue,L]);Et("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:R,dragOver:X});const ge=a.useCallback(se=>{se.streamSource==="agent-stream"&&se.agentType&&N(se.ideId,"focus_session",{agentType:se.agentType,...se.sessionId&&{targetSessionId:se.sessionId}}).catch(()=>{})},[N]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:u,style:{...x,outline:X?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(vc,{conversations:L,activeTabId:R,groupIndex:f,numGroups:h,unreadTabKeys:ae,draggingTabRef:_,onFocus:u,onSelectTab:I,onConversationActivated:ge,onPreviewReorder:P,onReorderTab:U,onCommitPreviewOrder:z,onClearPreviewOrder:T,onDragStateReset:ee,onDragTabKeyChange:O,onMoveTab:p,onReceiveTab:y,onHideTab:M,isGroupActive:w??!1}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:fe,onDragOver:F,onDragLeave:q,onDrop:V,children:[X&&e.jsx(hc,{dropAction:xe,canSplit:!!(h<4&&p)}),E?e.jsx(Gs,{activeConv:E,clearToken:n[E.tabKey]||0,isCliTerminal:!!pe,ideEntry:de,terminalRef:$,handleModalButton:D.handleModalButton,handleRelaunch:D.handleRelaunch,handleSendChat:D.handleSendChat,isSendingChat:D.isSendingChat,handleFocusAgent:D.handleFocusAgent,isFocusingAgent:D.isFocusingAgent,actionLogs:oe,userName:l}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Zs,{conversationsCount:t.length,isSplitMode:m,isStandalone:d,detectedIdes:k,handleLaunchIde:b})})]})]})}function wc({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:i,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:m,userName:h,focusedGroup:p,setFocusedGroup:y,moveTabToGroup:x,splitTabRelative:k,closeGroup:b,handleResizeStart:g,detectedIdes:j,handleLaunchIde:S,groupActiveTabIds:v,setGroupActiveTabIds:M,groupTabOrders:w,setGroupTabOrders:N,toggleHiddenTab:$}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:i.map((R,E)=>{const L=s&&r.length===n?`${r[E]}%`:void 0;return e.jsxs(Ds.Fragment,{children:[s&&E>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:_=>g(E-1,_),onDoubleClick:()=>b(E),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(jc,{style:s?{flexBasis:L??`${100/n}%`,flexGrow:L?0:1,flexShrink:L?0:1}:void 0,conversations:R,clearedTabs:o,ides:c,actionLogs:d,sendDaemonCommand:l,setLocalUserMessages:f,setActionLogs:u,isStandalone:m,userName:h,groupIndex:E,isFocused:s&&p===E,onFocus:()=>y(E),isSplitMode:s,numGroups:n,onMoveTab:(_,I)=>{I==="left"&&E>0?x(_,E-1):I==="right"&&E<n-1?x(_,E+1):I==="split-left"&&n<4?k(_,E,"left"):I==="split-right"&&n<4&&k(_,E,"right")},onReceiveTab:_=>x(_,E),detectedIdes:E===0?j:void 0,handleLaunchIde:E===0?S:void 0,onActiveTabChange:_=>M(I=>(I[E]??null)===(_??null)?I:{...I,[E]:_}),initialActiveTabId:v[E],initialTabOrder:w[E],onTabOrderChange:_=>N(I=>{const U=I[E]||[];return U.length===_.length&&U.every((P,z)=>P===_[z])?I:{...I,[E]:_}}),onHideTab:$})]},E)})})}function Or({doId:t,ideId:s,ideType:n,connState:r,viewMode:i,instanceId:o}){const[c,d]=a.useState(null),[l,f]=a.useState(null),u=a.useMemo(()=>{if(!s)return n;const h=s.split(":");return h.length>=3&&h[1]==="ide"?h.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?$e.onScreenshot("ide-page",(p,y)=>{if(p!==t)return;const x=new FileReader;x.onload=()=>d(x.result),x.readAsDataURL(y)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&d(null)},[r]),a.useEffect(()=>{var p;return t?((p=$e.onStatus)==null?void 0:p.call($e,(y,x)=>{y===t&&x!=null&&x.screenshotUsage&&f(x.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{d(null)},[t,s,u]),a.useEffect(()=>{const h=t?$e.get(t):null;if(!(!h||r!=="connected"))return i!=="chat"&&u?h.startScreenshots(u):h.stopScreenshots(u),()=>{h.stopScreenshots(u)}},[i,r,u,t]);const m=a.useCallback(async(h,p)=>{const y=t?$e.get(t):null;return!y||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):y.sendInput(h,p,o||u)},[t,r,o,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:m}}const zr=a.createContext(null);function ms(){const t=a.useContext(zr);if(!t)throw new Error("DashboardDockviewContext missing");return t}function Qt(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function kc(t){return`remote:${t}`}function cs(t){return t.startsWith("remote:")}function fs(t,s){return t.find(n=>n.ideId===s&&n.streamSource==="native")??t.find(n=>n.ideId===s)??null}function Nc(t){const[,s]=a.useState(0);a.useEffect(()=>{const n=()=>s(i=>i+1),r=[t.api.onDidActiveGroupChange(n),t.api.onDidTitleChange(n),t.api.onDidGroupChange(n),t.containerApi.onDidActivePanelChange(n)];return()=>{for(const i of r)i.dispose()}},[t.api,t.containerApi])}function Sc(t,s,n){var d;const r=[s];let i;for(const l of r){let f;for(const u of l){const m=t.addPanel({id:u.tabKey,component:"conversation",title:Qt(u),params:{kind:"conversation",tabKey:u.tabKey},...f?{position:{referencePanel:f,direction:"within"},inactive:!0}:i?{position:{referencePanel:i,direction:"right"},inactive:!0}:{}});f||(f=m.id)}i=f??i}const o=n??((d=s[0])==null?void 0:d.tabKey)??null;if(!o)return;const c=t.getPanel(o);c&&c.group.model.openPanel(c)}function Dn(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])cs(r.id)||n.has(r.id)||t.removePanel(r);for(const r of s){const i=t.getPanel(r.tabKey);if(i){i.update({params:{tabKey:r.tabKey}}),i.title!==Qt(r)&&i.api.setTitle(Qt(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:Qt(r),params:{kind:"conversation",tabKey:r.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 Bn(t,s,n){var l,f;const r=n?kc(n):null;for(const u of[...t.panels])cs(u.id)&&(!r||u.id!==r)&&t.removePanel(u);if(!n||!r)return;const i=fs(s,n);if(!i&&t.totalPanels===0)return;const o=t.getPanel(r),c=i?`Remote · ${i.displayPrimary||i.workspaceName||i.agentName}`:"Remote";if(o){o.title!==c&&o.api.setTitle(c);return}const d=(i==null?void 0:i.tabKey)??((l=t.activePanel)==null?void 0:l.id)??((f=t.panels.find(u=>!cs(u.id)))==null?void 0:f.id);t.addPanel({id:r,component:"remote",title:c,params:{kind:"remote",ideId:n},...d?{position:{referencePanel:d,direction:"right"},inactive:!0}:{}})}function Cc({params:t}){const s=ms(),n=a.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),i=xs({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),o=a.useMemo(()=>r?s.ides.find(l=>l.id===r.ideId):void 0,[s.ides,r]),c=a.useMemo(()=>r?s.actionLogs.filter(l=>l.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(Zs,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const d=!_e(r)&&wt(r)==="terminal";return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(Gs,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCliTerminal:d,ideEntry:o,terminalRef:n,handleModalButton:i.handleModalButton,handleRelaunch:i.handleRelaunch,handleSendChat:i.handleSendChat,isSendingChat:i.isSendingChat,handleFocusAgent:i.handleFocusAgent,isFocusingAgent:i.isFocusingAgent,actionLogs:c,userName:s.userName})})}function Ic({params:t}){var l;const s=ms(),n=a.useMemo(()=>fs([...s.conversationsByTabKey.values()],t.ideId),[s.conversationsByTabKey,t.ideId]),r=a.useMemo(()=>s.ides.find(f=>f.id===t.ideId),[s.ides,t.ideId]),i=(n==null?void 0:n.daemonId)||((l=n==null?void 0:n.ideId)==null?void 0:l.split(":")[0])||t.ideId.split(":")[0]||t.ideId,{connScreenshot:o,screenshotUsage:c,handleRemoteAction:d}=Or({doId:i,ideId:t.ideId,ideType:(n==null?void 0:n.ideType)||(r==null?void 0:r.type),connState:(n==null?void 0:n.connectionState)||"new",viewMode:"remote",instanceId:r==null?void 0:r.instanceId});return n?e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden bg-black",children:e.jsx(ir,{addLog:()=>{},connState:n.connectionState||"new",connScreenshot:o,screenshotUsage:c,transportType:n.transport,onAction:d})}):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 Mc(){const t=ms();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Zs,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function _c(t){var m,h;Nc(t);const s=ms();if(t.params.kind==="remote"){const p=fs([...s.conversationsByTabKey.values()],t.params.ideId),y=((m=t.api.group.activePanel)==null?void 0:m.id)===t.api.id,x=t.api.isGroupActive;return e.jsxs("div",{className:`adhdev-dockview-tab${y?" is-active":""}${x?" is-group-active":""}`,title:t.api.title||"Remote","data-tab-key":(p==null?void 0:p.tabKey)||"",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:p!=null&&p.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:p.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 r=((h=t.api.group.activePanel)==null?void 0:h.id)===t.api.id,i=t.api.isGroupActive,o=$t(n,s.liveSessionInboxState,{isOpenConversation:r}),c=o.isReconnecting,d=o.isConnecting,l=o.isGenerating,f=o.isWaiting,u=o.unread;return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${i?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,"data-tab-key":t.params.tabKey,children:[u&&e.jsx("span",{className:"adhdev-dockview-tab-unread-dot","aria-hidden":"true"}),e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:l?e.jsx("div",{className:"tab-spinner"}):f?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?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:c?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]})]})]})})]})]})}function Tc({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,sendDaemonCommand:i,setLocalUserMessages:o,setActionLogs:c,isStandalone:d,userName:l,detectedIdes:f,handleLaunchIde:u,toggleHiddenTab:m,onActiveTabChange:h,requestedActiveTabKey:p,requestedRemoteIdeId:y,onRequestedActiveTabConsumed:x}){const{theme:k}=Sr(),{sendCommand:b}=ct(),g=a.useRef(null),j=a.useRef(null),S=a.useRef(!1),[v,M]=a.useState(!1),[w,N]=a.useState(!1),$=a.useRef(null),R=a.useMemo(()=>Pr(typeof window<"u"?window.innerWidth:1280),[]),E=a.useMemo(()=>new Map(t.map(D=>[D.tabKey,D])),[t]),L=a.useMemo(()=>Dt(n),[n]),_=a.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:E,detectedIdes:f,handleLaunchIde:u,ides:n,isStandalone:d,liveSessionInboxState:L,sendDaemonCommand:i,setActionLogs:c,setLocalUserMessages:o,toggleHiddenTab:m,userName:l}),[r,s,E,f,u,n,d,L,i,c,o,m,l]),I=a.useCallback(D=>{if(!D)return!1;const X=g.current;if(!X)return!1;const xe=X.getPanel(D);return xe?(xe.group.model.openPanel(xe),x==null||x(),!0):!1},[x]),U=a.useCallback(()=>{const D=j.current;if(!D)return;const X=D.querySelectorAll(".dv-drop-target-container, .dv-drop-target-anchor, .dv-drop-target-dropzone, .dv-drop-target-selection, .dv-render-overlay");for(const xe of X)xe.setAttribute("data-adhdev-force-hidden","true")},[]),P=a.useCallback(()=>{const D=j.current;if(!D)return;const X=D.querySelectorAll('[data-adhdev-force-hidden="true"]');for(const xe of X)xe.removeAttribute("data-adhdev-force-hidden")},[]),z=a.useCallback(()=>{const D=j.current;if(!D)return;const X=D.querySelectorAll(".dv-drop-target-container");for(const fe of X)fe.remove();const xe=D.querySelectorAll(".dv-drop-target-dropzone");for(const fe of xe)fe.remove();const ee=D.querySelectorAll(".dv-drop-target");for(const fe of ee)fe.classList.remove("dv-drop-target")},[]),T=a.useCallback(()=>{M(!1),N(!1),P(),U(),z(),!(typeof window>"u")&&($.current!=null&&window.clearTimeout($.current),window.requestAnimationFrame(()=>{U(),z()}),$.current=window.setTimeout(()=>{U(),z(),$.current=null},80))},[P,U,z]),B=a.useCallback(D=>{var xe;g.current=D.api;const X=qo(R);X!=null&&X.layout&&D.api.fromJSON(X.layout,{reuseExistingPanels:!1}),Dn(D.api,t),Bn(D.api,t,y),D.api.totalPanels===0&&t.length>0?Sc(D.api,t,p):I(p)||I(X==null?void 0:X.activeTabId),S.current=!0,D.api.onDidActivePanelChange(ee=>{var F;if(ee&&cs(ee.id)){const q=((F=ee.params)==null?void 0:F.ideId)||ee.id.slice(7),V=fs(t,q);h((V==null?void 0:V.tabKey)??null);return}if(h((ee==null?void 0:ee.id)??null),!ee)return;const fe=E.get(ee.id);(fe==null?void 0:fe.streamSource)==="agent-stream"&&fe.agentType&&b(fe.ideId,"focus_session",{agentType:fe.agentType,...fe.sessionId&&{targetSessionId:fe.sessionId}}).catch(()=>{})}),D.api.onDidLayoutChange(()=>{var ee;Go(R,{activeTabId:((ee=D.api.activePanel)==null?void 0:ee.id)??null,layout:D.api.toJSON()})}),D.api.onWillDragPanel(()=>{M(!0),N(!1),U()}),D.api.onWillDragGroup(()=>{M(!0),N(!1),U()}),D.api.onWillShowOverlay(()=>{P(),N(!0)}),D.api.onDidMovePanel(T),D.api.onDidDrop(T),h(((xe=D.api.activePanel)==null?void 0:xe.id)??null)},[I,T,P,E,R,U,z,h,p,b,t]);a.useEffect(()=>{const D=g.current;!D||!S.current||(Dn(D,t),Bn(D,t,y),!D.activePanel&&D.panels[0]&&D.panels[0].group.model.openPanel(D.panels[0]))},[y,t]),a.useEffect(()=>{S.current&&I(p)},[I,p]),a.useEffect(()=>{if(!v||typeof window>"u")return;const D=()=>T();return window.addEventListener("pointerup",D),window.addEventListener("mouseup",D),window.addEventListener("dragend",D),()=>{window.removeEventListener("pointerup",D),window.removeEventListener("mouseup",D),window.removeEventListener("dragend",D)}},[T,v]),a.useEffect(()=>()=>{typeof window>"u"||$.current!=null&&window.clearTimeout($.current)},[]),a.useEffect(()=>{const D=X=>{const xe=X.target;if(!xe)return;const ee=xe.querySelector("[data-tab-key]")||xe.closest("[data-tab-key]");if(ee){const fe=ee.getAttribute("data-tab-key");fe&&X.dataTransfer&&X.dataTransfer.setData("text/tab-key",fe)}};return window.addEventListener("dragstart",D),()=>window.removeEventListener("dragstart",D)},[]);const O=k==="light"?ka:Na;return e.jsx(zr.Provider,{value:_,children:e.jsx("div",{ref:j,className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(wa,{className:`h-full min-h-0 min-w-0 adhdev-dockview${v?" is-dragging-dockview":""}${w?" is-showing-dockview-overlay":""}`,components:{conversation:Cc,remote:Ic},defaultTabComponent:_c,watermarkComponent:Mc,onReady:B,singleTabMode:"default",tabAnimation:"smooth",theme:O})})})}function Ac({showMobileChatMode:t,isMobile:s,activeConv:n,chatIdes:r,wsStatus:i,isConnected:o,onOpenHistory:c,onOpenRemote:d,onStopCli:l,activeCliViewMode:f,onSetActiveCliViewMode:u,mobileChatConversations:m,hiddenConversations:h,ides:p,actionLogs:y,sendDaemonCommand:x,setLocalUserMessages:k,setActionLogs:b,isStandalone:g,userName:j,requestedMobileTabKey:S,onRequestedMobileTabConsumed:v,requestedMachineId:M,onRequestedMachineConsumed:w,requestedMobileSection:N,onRequestedMobileSectionConsumed:$,containerRef:R,isSplitMode:E,numGroups:L,groupSizes:_,groupedConvs:I,clearedTabs:U,focusedGroup:P,setFocusedGroup:z,moveTabToGroup:T,splitTabRelative:B,closeGroup:O,handleResizeStart:D,detectedIdes:X,handleLaunchIde:xe,groupActiveTabIds:ee,setGroupActiveTabIds:fe,groupTabOrders:F,setGroupTabOrders:q,toggleHiddenTab:V,visibleConversations:pe,requestedDesktopTabKey:de,onRequestedDesktopTabConsumed:oe,onDesktopActiveTabChange:ue,onHideConversation:ae,onShowHiddenConversation:ge,onShowAllHiddenConversations:se}){return Ds.useEffect(()=>{const ce=G=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?G.metaKey&&G.key.toLowerCase()==="w":G.ctrlKey&&G.key.toLowerCase()==="w")&&(G.preventDefault(),n&&ae&&ae(n))};return window.addEventListener("keydown",ce),()=>window.removeEventListener("keydown",ce)},[n,ae]),e.jsxs(e.Fragment,{children:[!t&&e.jsx(Wi,{activeConv:n,agentCount:r.length,wsStatus:i,isConnected:o,conversations:pe,hiddenConversations:h,onOpenHistory:c,onOpenConversation:ge,onHideConversation:ae,onShowConversation:ge,onShowAllHidden:se,onOpenRemote:()=>{!n||Ee(n)||_e(n)||d(n)},onStopCli:l,activeCliViewMode:f,onSetCliViewMode:u}),t?e.jsx(pc,{conversations:m,hiddenConversations:h,ides:p,actionLogs:y,sendDaemonCommand:x,setLocalUserMessages:k,setActionLogs:b,isStandalone:g,userName:j,requestedActiveTabKey:S,onRequestedActiveTabConsumed:v,requestedMachineId:M,onRequestedMachineConsumed:w,requestedMobileSection:N,onRequestedMobileSectionConsumed:$,onOpenHistory:c,onOpenRemote:d,onStopCli:l,wsStatus:i,isConnected:o,onShowHiddenConversation:ge,onShowAllHiddenConversations:se}):s?e.jsx(wc,{containerRef:R,isSplitMode:E,numGroups:L,groupSizes:_,groupedConvs:I,clearedTabs:U,ides:p,actionLogs:y,sendDaemonCommand:x,setLocalUserMessages:k,setActionLogs:b,isStandalone:g,userName:j,focusedGroup:P,setFocusedGroup:z,moveTabToGroup:T,splitTabRelative:B,closeGroup:O,handleResizeStart:D,detectedIdes:X,handleLaunchIde:xe,groupActiveTabIds:ee,setGroupActiveTabIds:fe,groupTabOrders:F,setGroupTabOrders:q,toggleHiddenTab:V}):e.jsx(Tc,{visibleConversations:pe,clearedTabs:U,ides:p,actionLogs:y,sendDaemonCommand:x,setLocalUserMessages:k,setActionLogs:b,isStandalone:g,userName:j,detectedIdes:X,handleLaunchIde:xe,toggleHiddenTab:V,onActiveTabChange:ue,requestedActiveTabKey:de,onRequestedActiveTabConsumed:oe})]})}const Cs=[{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 Rc({onClose:t}){const[s,n]=a.useState(0),r=Cs[s],i=s===Cs.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:Cs.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:r.visual||r.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:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.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:"$"}),r.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():n(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:`
48
- @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
49
- @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
50
- `})]})}function Lc({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,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)] ${n==="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}),r.map(o=>{const c=n===o.tabKey,d=o.status==="waiting_approval",l=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:d?"var(--status-warning)":l?"var(--accent-primary)":"var(--text-muted)",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),o.title,d&&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 Pc({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:i,preferredTabKey:o}){const[c,d]=a.useState(()=>o||"native"),l=a.useMemo(()=>gr(s),[s]),f=a.useMemo(()=>{var k;if(!t)return[];const x=t.daemonId||((k=t.id)==null?void 0:k.split(":")[0])||t.id;return yr(t,r,{machineName:t.daemonId&&l[t.daemonId]||void 0,connectionState:n[x]||"new"})},[t,r,l,n]),u=a.useMemo(()=>f.find(x=>x.streamSource==="native"),[f]),m=a.useMemo(()=>f.filter(x=>x.streamSource==="agent-stream"),[f]);a.useEffect(()=>{o&&d(o)},[o]),a.useEffect(()=>{var x;c!=="native"&&(m.some(k=>k.tabKey===c)||d(((x=m[0])==null?void 0:x.tabKey)||"native"))},[c,m]),a.useEffect(()=>{c==="native"&&(u||m[0]&&d(m[0].tabKey))},[c,u,m]);const h=a.useMemo(()=>c==="native"&&u?u:m.find(x=>x.tabKey===c)||u||m[0],[c,u,m]),p=a.useMemo(()=>m.map(x=>({tabKey:x.tabKey,title:x.title||x.agentName||i,status:x.status})),[m,i]),y=a.useCallback(x=>{if(x)return f.find(k=>k.sessionId===x||k.ideId===x||k.tabKey===x||k.ideType===x||k.agentType===x)},[f]);return{activeChatTab:c,setActiveChatTab:d,activeConv:h,conversations:f,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:y}}function $c({activeConv:t,ideEntry:s,ides:n,connectionStates:r,actionLogs:i,localUserMessages:o,sendDaemonCommand:c,setLocalUserMessages:d,setActionLogs:l,isStandalone:f,userName:u,onOpenHistory:m,onConversationChange:h,onClose:p}){var U;const[y,x]=a.useState("split"),[k,b]=a.useState(()=>t.streamSource==="native"?"native":t.tabKey),g=a.useMemo(()=>s||n.find(P=>P.id===t.ideId),[t.ideId,s,n]),j=a.useMemo(()=>Me((g==null?void 0:g.type)||""),[g==null?void 0:g.type]),{conversations:S,extensionTabs:v,hasExtensions:M}=Pc({ideData:g,allIdes:n,connectionStates:r,localUserMessages:o,ideName:j||"IDE",preferredTabKey:t.streamSource==="native"?"native":t.tabKey});a.useEffect(()=>{b(t.streamSource==="native"?"native":t.tabKey)},[t.streamSource,t.tabKey]);const w=a.useMemo(()=>k==="native"?S.find(P=>P.streamSource==="native")||t:S.find(P=>P.tabKey===k)||t,[t,S,k]),N=w.daemonId||((U=w.ideId)==null?void 0:U.split(":")[0])||w.ideId,$=xs({sendDaemonCommand:c,activeConv:w,setLocalUserMessages:d,setActionLogs:l,isStandalone:f}),{connScreenshot:R,screenshotUsage:E,handleRemoteAction:L}=Or({doId:N,ideId:w.ideId,ideType:w.ideType,connState:w.connectionState||"new",viewMode:y,instanceId:g==null?void 0:g.instanceId}),_=a.useMemo(()=>i.filter(P=>P.ideId===w.tabKey),[i,w.tabKey]);a.useEffect(()=>{h==null||h(w)},[w,h]),a.useEffect(()=>{const P=z=>{z.key==="Escape"&&p()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[p]);const I=a.useCallback(P=>{P.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:I,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(Fe,{size:16})}),e.jsx("span",{className:"truncate",children:w.displayPrimary||w.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(P=>{const z=y===P;return e.jsx("button",{className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all ${z?"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:()=>x(P),title:P==="split"?"Split view":"Remote only",children:P==="split"?e.jsx("span",{className:"font-bold text-lg leading-none mb-0.5",children:"⊞"}):e.jsx(Fe,{size:15})},P)})}),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:()=>m(w),title:"Chat History",children:[e.jsx(Ws,{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 ${y==="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:[y!=="remote"&&e.jsxs("div",{className:`flex flex-col min-w-0 min-h-0 bg-bg-primary ${y==="split"?"order-2 md:order-1 border-b md:border-b-0 md:border-r border-border-subtle":""}`,children:[e.jsx(Lc,{hasExtensions:M,ideName:j||"IDE",activeChatTab:k,extensionTabs:v,onSelectTab:b}),e.jsx(cr,{activeConv:w,onModalButton:$.handleModalButton}),e.jsx(Rs,{activeConv:w,ideEntry:g,showMetaChips:!1,handleSendChat:$.handleSendChat,isSendingChat:$.isSendingChat,handleFocusAgent:$.handleFocusAgent,isFocusingAgent:$.isFocusingAgent,actionLogs:_,userName:u})]}),e.jsx("div",{className:`flex flex-col min-w-0 min-h-0 bg-black ${y==="split"?"order-1 md:order-2":""}`,children:e.jsx(ir,{addLog:()=>{},connState:w.connectionState||"new",connScreenshot:R,screenshotUsage:E,transportType:w.transport,onAction:L})})]})]})})}function Ec({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const i=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:s,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[92%] 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-6 py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-lg font-extrabold",children:["Stop ",i,"?"]}),e.jsx("div",{className:"mt-1 text-sm text-text-muted",children:"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first."})]}),e.jsxs("div",{className:"px-6 py-5 bg-bg-primary flex flex-col gap-3",children:[e.jsx("button",{onClick:r,className:"btn btn-primary w-full justify-center",children:"Save and stop"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:s,className:"btn btn-secondary w-full justify-center",children:"Cancel"})]})]})]})}function Dc({historyModalOpen:t,historyTargetConv:s,ides:n,isHistoryCreatingChat:r,isHistoryRefreshingHistory:i,savedHistorySessions:o,isSavedHistoryLoading:c,isResumingSavedHistorySessionId:d,onCloseHistory:l,onNewHistoryChat:f,onSwitchHistorySession:u,onRefreshHistory:m,onResumeSavedHistorySession:h,remoteDialogConv:p,remoteDialogIdeEntry:y,connectionStates:x,actionLogs:k,localUserMessages:b,sendDaemonCommand:g,setLocalUserMessages:j,setActionLogs:S,isStandalone:v,userName:M,onOpenRemoteHistory:w,onRemoteConversationChange:N,onCloseRemoteDialog:$,cliStopDialogOpen:R,cliStopTargetConv:E,onCancelCliStop:L,onStopCliNow:_,onSaveCliAndStop:I,toasts:U,onDismissToast:P,onClickToast:z,showOnboarding:T,onCloseOnboarding:B}){return e.jsxs(e.Fragment,{children:[t&&s&&e.jsx(zi,{activeConv:s,ides:n,isCreatingChat:r,isRefreshingHistory:i,savedSessions:o,isSavedSessionsLoading:c,isResumingSavedSessionId:d,onClose:l,onNewChat:f,onSwitchSession:u,onRefreshHistory:m,onResumeSavedSession:h}),p&&e.jsx($c,{activeConv:p,ideEntry:y,ides:n,connectionStates:x,actionLogs:k,localUserMessages:b,sendDaemonCommand:g,setLocalUserMessages:j,setActionLogs:S,isStandalone:v,userName:M,onOpenHistory:w,onConversationChange:N,onClose:$}),R&&E&&Ee(E)&&!_e(E)&&e.jsx(Ec,{activeConv:E,onCancel:L,onStopNow:_,onSaveAndStop:I}),e.jsx(hr,{toasts:U,onDismiss:P,onClickToast:z}),T&&e.jsx(Rc,{onClose:B})]})}function Bc({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,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(Os,{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=tt(o,{fallbackId:o.id}),d=n[o.id],l=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",l]}),d==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):d==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):d==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(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:()=>r(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 Kc(){var tn,sn,nn;const{sendCommand:t}=ct(),s=Bs(),n=kt(),[r,i]=Sa(),o=r.get("activeTab"),c=((tn=s.state)==null?void 0:tn.openRemoteForTabKey)||null,d=((sn=s.state)==null?void 0:sn.openMachineId)||null,l=((nn=s.state)==null?void 0:nn.mobileSection)||null,f=Hs(),u=f.ides||[],{updateIdeChats:m}=f,[h,p]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),y=f.toasts||[],x=f.setToasts||(()=>{}),k=f.wsStatus||"connected",b=f.isConnected??!0,g=f.connectionStates||{},j=f.showReconnected||!1,{groupAssignments:S,setGroupAssignments:v,focusedGroup:M,setFocusedGroup:w,groupActiveTabIds:N,setGroupActiveTabIds:$,groupTabOrders:R,setGroupTabOrders:E,groupSizes:L,setGroupSizes:_,isMobile:I,hasHydratedStoredLayout:U,hydrateStoredLayout:P}=Xo(),[z,T]=a.useState(!1),[B,O]=a.useState(!1),[D,X]=a.useState(null),[xe,ee]=a.useState([]),[fe,F]=a.useState(!1),[q,V]=a.useState(null),[pe]=a.useState(()=>Tr()),[de,oe]=a.useState([]),[ue,ae]=a.useState({}),[ge,se]=a.useState({}),[ce,G]=a.useState(null),te=a.useRef(null);Et("Dashboard",{ideCount:u.length,toastCount:y.length,focusedGroup:M,groupCount:Object.keys(S).length,localMessageTabs:Object.keys(ue).length,actionLogCount:de.length});const C=u.find(he=>he.type==="adhdev-daemon"),J=(C==null?void 0:C.detectedIdes)||[],Z=!!C,ne=(C==null?void 0:C.terminalBackend)||null,be=C?tt(C,{fallbackId:C.id}):null,we=(C==null?void 0:C.id)||null,{hiddenTabs:Se,hideTab:Te,toggleTab:Ze,showTab:Ke,showAllTabs:ze}=Po(),{chatIdes:We,conversations:De,visibleConversations:re,visibleTabKeys:ke,resolveConversationBySessionId:je,resolveConversationByTarget:ye}=Wo({ides:u,connectionStates:g,localUserMessages:ue,clearedTabs:ge,hiddenTabs:Se}),W=a.useMemo(()=>Dt(u),[u]),K=a.useRef(null),{containerRef:ie,normalizedGroupAssignments:le,numGroups:A,isSplitMode:Y,groupedConvs:Q,moveTabToGroup:H,closeGroup:Le,handleResizeStart:me,splitTabRelative:Ae}=nc({groupAssignments:S,setGroupAssignments:v,setFocusedGroup:w,setGroupActiveTabIds:$,setGroupTabOrders:E,groupSizes:L,setGroupSizes:_,isMobile:I,visibleConversations:re,visibleTabKeys:ke}),ve=a.useMemo(()=>{var Ce,Ie;if(!I){if(ce){const Pe=De.find(Ve=>Ve.tabKey===ce);if(Pe)return Pe}return re[0]}const he=N[M];if(he){const Pe=De.find(Ve=>Ve.tabKey===he);if(Pe)return Pe}return((Ce=Q[M])==null?void 0:Ce[0])||((Ie=Q[0])==null?void 0:Ie[0])},[ce,I,N,M,De,Q,re]);a.useEffect(()=>{if(I){K.current=null;return}if(!(ve!=null&&ve.sessionId)){K.current=null;return}const he=`${ve.tabKey}:${ve.sessionId}`;if(K.current===he)return;K.current=he;const Ce=Pt(ve,W),Ie=Math.max(Date.now(),vt(ve),Ce.lastUpdated||0);t(ve.daemonId||ve.ideId,"mark_session_seen",{sessionId:ve.sessionId,seenAt:Ie}).catch(()=>{})},[ve,I,W,t]);const{requestedDesktopTabKey:Ge,requestedMobileTabKey:Oe,consumeRequestedActiveTab:ht}=Oo({isMobile:I,urlActiveTab:o,resolveConversationBySessionId:je,setSearchParams:i}),{remoteDialogConv:Js,remoteDialogIdeEntry:Ur,remoteDialogActiveConv:Hr,setRemoteDialogActiveConv:hs,openRemoteDialog:Fr,closeRemoteDialog:Vr}=Jo({isMobile:I,location:s,navigate:n,requestedRemoteTabTarget:c,requestedDesktopTabKey:Ge,conversations:De,ides:u,resolveConversationByTarget:ye}),Re=Hr||Js||ve,Qe=!!Re&&Ee(Re)&&!_e(Re),Bt=a.useMemo(()=>{if(!Re||!Qe)return null;const he=Re.daemonId||Re.ideId||"",Ce=Re.agentType||Re.ideType||"";return`${he}:${Ce}`},[Re,Qe]),qr=a.useMemo(()=>re,[re]),Kt=I&&pe==="chat",Gr=a.useMemo(()=>De.filter(he=>Se.has(he.tabKey)),[De,Se]);$o({visibleConversations:re,clearedTabs:ge,setClearedTabs:se,setActionLogs:oe}),zo({ides:u,sendDaemonCommand:t,setToasts:x,setLocalUserMessages:ae,resolveConversationByTarget:ye});const{isRefreshingHistory:Yr,handleLaunchIde:Xr,handleRefreshHistory:Zr}=_n({sendDaemonCommand:t,activeConv:ve,updateIdeChats:m,setToasts:x,setLocalUserMessages:ae,setClearedTabs:se}),{isCreatingChat:Jr,isRefreshingHistory:Qr,handleSwitchSession:ea,handleNewChat:ta,handleRefreshHistory:sa}=_n({sendDaemonCommand:t,activeConv:Re,updateIdeChats:m,setToasts:x,setLocalUserMessages:ae,setClearedTabs:se}),bs=a.useCallback(async()=>{if(!(!Re||!Qe||fe)){F(!0);try{const he=Re.daemonId||Re.ideId,Ce=Re.agentType||Re.ideType,Ie=await t(he,"list_saved_sessions",{agentType:Ce,providerType:Ce,kind:"cli",limit:50}),Pe=(Ie==null?void 0:Ie.result)??Ie;ee(Array.isArray(Pe==null?void 0:Pe.sessions)?Pe.sessions:[])}catch(he){console.error("Refresh saved sessions failed",he),ee([])}finally{F(!1)}}},[Re,fe,Qe,t]);a.useEffect(()=>{if(!z){te.current=null;return}if(!Qe){te.current=null,ee([]),F(!1);return}!Bt||fe||te.current!==Bt&&(te.current=Bt,bs())},[bs,z,fe,Qe,Bt]);const na=a.useCallback(async he=>{if(!Re||!Qe||!he.providerSessionId||!he.workspace)return;const Ce=Re.daemonId||Re.ideId,Ie=Re.agentType||Re.ideType;try{V(he.providerSessionId);const Pe=await t(Ce,"launch_cli",{cliType:Ie,dir:he.workspace,resumeSessionId:he.providerSessionId,initialModel:he.currentModel}),Ve=(Pe==null?void 0:Pe.result)??Pe,Ot=typeof(Ve==null?void 0:Ve.sessionId)=="string"?Ve.sessionId:typeof(Ve==null?void 0:Ve.id)=="string"?Ve.id:"";Ot&&i(ma=>{const rn=new URLSearchParams(ma);return rn.set("activeTab",Ot),rn},{replace:!0}),T(!1)}catch(Pe){console.error("Resume saved session failed",Pe)}finally{V(null)}},[Re,Qe,t,i]);Zo({urlActiveTab:I&&!Kt?o:null,conversations:De,resolveConversationBySessionId:je,normalizedGroupAssignments:le,hasHydratedStoredLayout:I&&!Kt?U:!0,hydrateStoredLayout:I&&!Kt?P:()=>{},setGroupActiveTabIds:$,setFocusedGroup:w,setSearchParams:i,historyModalOpen:z,activeConv:ve,isRefreshingHistory:Yr,ides:u,handleRefreshHistory:Zr});const Wt=a.useCallback(async(he,Ce)=>{const Ie=Ce||D||ve;if(!Ie||!Ee(Ie)||_e(Ie))return;const Pe=Ie.ideType||Ie.agentType||"",Ve=Ie.ideId||Ie.daemonId||"";try{await t(Ve,"stop_cli",{cliType:Pe,targetSessionId:Ie.sessionId,mode:he})}catch(Ot){console.error("Stop CLI failed:",Ot)}},[ve,D,t]),ra=a.useCallback(async he=>{var Pe;const Ce=he||ve;if(!Ce||!Ee(Ce)||_e(Ce))return;if(X(Ce),(Pe=Ce.resume)!=null&&Pe.supported){O(!0);return}const Ie=Ce.ideType||Ce.agentType||"CLI";window.confirm(`Stop ${Ie}?
51
- This will terminate the CLI process.`)&&(await Wt("hard",Ce),X(null))},[ve,Wt]),aa=a.useMemo(()=>!ve||!Ee(ve)||_e(ve)?null:wt(ve),[ve]),ia=a.useCallback(async he=>{if(!(!ve||!Ee(ve)||_e(ve)||wt(ve)===he))try{await t(ve.daemonId||ve.ideId,"set_cli_view_mode",{targetSessionId:ve.sessionId,cliType:ve.ideType||ve.agentType,mode:he})}catch(Ie){console.error("Failed to switch CLI view mode:",Ie)}},[ve,t]),{versionMismatchDaemons:oa,appVersion:ca,versionBannerDismissed:la,setVersionBannerDismissed:da,upgradingDaemons:ua,handleBannerUpgrade:pa}=rc({ides:u,sendDaemonCommand:t}),Qs=a.useCallback(he=>{G(he.tabKey),i(Ce=>{const Ie=new URLSearchParams(Ce);return he.sessionId?Ie.set("activeTab",he.sessionId):Ie.delete("activeTab"),Ie},{replace:!0})},[i]),en=a.useCallback(he=>{Ke(he.tabKey),Qs(he)},[Qs,Ke]),xa=a.useCallback(he=>{Te(he.tabKey)},[Te]);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(Bi,{wsStatus:k,showReconnected:j}),e.jsx(Ki,{terminalBackend:ne,isStandalone:Z,machineLabel:be,machineKey:we}),!la&&e.jsx(Bc,{daemons:oa,targetVersion:ca,upgradingDaemons:ua,onUpgrade:pa,onDismiss:()=>da(!0)}),e.jsx(Ac,{showMobileChatMode:Kt,isMobile:I,activeConv:ve,chatIdes:We,wsStatus:k,isConnected:b,onOpenHistory:he=>{he&&hs(he),T(!0)},onOpenRemote:Fr,onStopCli:ra,activeCliViewMode:aa,onSetActiveCliViewMode:ia,mobileChatConversations:qr,ides:u,actionLogs:de,sendDaemonCommand:t,setLocalUserMessages:ae,setActionLogs:oe,isStandalone:Z,userName:f.userName,requestedMobileTabKey:Oe,onRequestedMobileTabConsumed:ht,requestedMachineId:d,onRequestedMachineConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},requestedMobileSection:l,onRequestedMobileSectionConsumed:()=>{n(s.pathname+s.search,{replace:!0,state:null})},containerRef:ie,isSplitMode:Y,numGroups:A,groupSizes:L,groupedConvs:Q,clearedTabs:ge,focusedGroup:M,setFocusedGroup:w,moveTabToGroup:H,splitTabRelative:Ae,closeGroup:Le,handleResizeStart:me,detectedIdes:J,handleLaunchIde:Xr,groupActiveTabIds:N,setGroupActiveTabIds:$,groupTabOrders:R,setGroupTabOrders:E,toggleHiddenTab:Ze,visibleConversations:re,hiddenConversations:Gr,requestedDesktopTabKey:Ge,onRequestedDesktopTabConsumed:ht,onDesktopActiveTabChange:G,onHideConversation:xa,onShowHiddenConversation:en,onShowAllHiddenConversations:ze}),e.jsx("style",{children:`
52
- body { overflow: hidden; overscroll-behavior: none; }
53
- `}),e.jsx(Dc,{historyModalOpen:z,historyTargetConv:Re,ides:u,isHistoryCreatingChat:Jr,isHistoryRefreshingHistory:Qe?!1:Qr,savedHistorySessions:xe,isSavedHistoryLoading:fe,isResumingSavedHistorySessionId:q,onCloseHistory:()=>T(!1),onNewHistoryChat:ta,onSwitchHistorySession:ea,onRefreshHistory:Qe?bs:sa,onResumeSavedHistorySession:na,remoteDialogConv:Js,remoteDialogIdeEntry:Ur,connectionStates:g,actionLogs:de,localUserMessages:ue,sendDaemonCommand:t,setLocalUserMessages:ae,setActionLogs:oe,isStandalone:Z,userName:f.userName,onOpenRemoteHistory:he=>{he&&hs(he),T(!0)},onRemoteConversationChange:hs,onCloseRemoteDialog:Vr,cliStopDialogOpen:B,cliStopTargetConv:D,onCancelCliStop:()=>{O(!1),X(null)},onStopCliNow:async()=>{O(!1),await Wt("hard",D),X(null)},onSaveCliAndStop:async()=>{O(!1),await Wt("save",D),X(null)},toasts:y,onDismissToast:he=>x(Ce=>Ce.filter(Ie=>Ie.id!==he)),onClickToast:he=>{if(he.targetKey){const Ce=ye(he.targetKey);Ce&&(w(le.get(Ce.tabKey)??0),en(Ce))}},showOnboarding:h,onCloseOnboarding:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}p(!1)}})]})}function Wc({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[d,l]=a.useState(null),[f,u]=a.useState(null),[m,h]=a.useState(!1),[p,y]=a.useState(null),[x,k]=a.useState(!1),[b,g]=a.useState(""),j=a.useRef(null),S=a.useCallback(T=>{j.current=T},[]),v=a.useCallback((T,B,O=!1)=>{c(D=>[...D.slice(-100),{timestamp:Date.now(),level:T,message:B}]),setTimeout(()=>{var D;return(D=i.current)==null?void 0:D.scrollIntoView({behavior:"smooth"})},100),O&&it.showToast(B,T==="error"||T==="warn"?"warning":"success")},[i]),M=a.useCallback(async(T,B)=>{var O;if(!t||d)return!1;l(T),v("info",`Launching ${Me(T)}${B!=null&&B.workspace?` in ${B.workspace}`:""}...`);try{const D={ideType:T,enableCdp:!0};(O=B==null?void 0:B.workspace)!=null&&O.trim()?D.workspace=B.workspace.trim():B!=null&&B.useDefaultWorkspace&&(D.useDefaultWorkspace=!0);const X=await n(t,"launch_ide",D);return v(X!=null&&X.success?"info":"error",X!=null&&X.success?`${Me(T)} launched`:`Failed: ${X==null?void 0:X.error}`,!0),!!(X!=null&&X.success)}catch(D){return v("error",`Launch error: ${D.message}`,!0),!1}finally{l(null)}},[t,d,v,n]),w=a.useCallback(async T=>{if(!t)return{success:!1};const{cliType:B,dir:O,workspaceId:D,useDefaultWorkspace:X,useHome:xe,argsStr:ee,model:fe,resumeSessionId:F}=T;if(!B)return v("warn","Select a CLI or ACP provider first",!0),{success:!1};const q=ee?ee.split(/\s+/).filter(Boolean):void 0,V=(O==null?void 0:O.trim())||(D?"(saved id)":X?"(default workspace)":xe?"(home)":"");v("info",`Launching ${B}${V?` in ${V}`:""}${fe?` (model: ${fe})`:""}...`),u(B);try{const pe={cliType:B,cliArgs:q,initialModel:fe||void 0};O!=null&&O.trim()?pe.dir=O.trim():D?pe.workspaceId=D:X?pe.useDefaultWorkspace=!0:xe&&(pe.useHome=!0),F&&(pe.resumeSessionId=F);const de=await n(t,"launch_cli",pe),oe=(de==null?void 0:de.result)||de;return de!=null&&de.success?(v("info",`${B} launched`,!0),(oe==null?void 0:oe.launchSource)==="home"?v("info","📂 Running in home directory (explicit choice)"):(oe==null?void 0:oe.launchSource)==="defaultWorkspace"&&v("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:oe==null?void 0:oe.sessionId}):(v("error",`Failed: ${(de==null?void 0:de.error)||(oe==null?void 0:oe.error)}`,!0),(de==null?void 0:de.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&y({cliType:B,argsStr:ee,model:fe}),{success:!1,sessionId:oe==null?void 0:oe.sessionId})}catch(pe){return v("error",`Launch error: ${pe.message}`,!0),{success:!1}}finally{u(null)}},[t,v,n]),N=a.useCallback(async(T,B,O,D)=>t?T?B.trim()?w({cliType:T,dir:B,argsStr:O,model:D}):(y({cliType:T,argsStr:O,model:D}),{success:!1}):(v("warn","Select a provider",!0),{success:!1}):{success:!1},[t,v,w]),$=a.useCallback(async(T,B,O)=>{if(t&&window.confirm(`Stop ${T}?
54
- This will terminate the process.`))try{const D=await n(t,"stop_cli",{cliType:T,dir:B,targetSessionId:O});D!=null&&D.success?v("info",`${T} stopped`,!0):v("error",`Stop failed: ${(D==null?void 0:D.error)||"Unknown error"}`,!0)}catch(D){v("error",`Stop failed: ${D.message}`,!0)}},[t,v,n]),R=a.useCallback(async T=>{try{await n(T.daemonId,"restart_ide",{ideType:T.type}),v("info",`${Me(T.type)} restart initiated`,!0)}catch(B){v("error",`Restart failed: ${B.message}`,!0)}},[v,n]),E=a.useCallback(async T=>{if(window.confirm(`Stop ${Me(T.type)}?
55
- This will disconnect CDP and optionally kill the process.`))try{const B=await n(T.daemonId,"stop_ide",{ideType:T.type,killProcess:!0});B!=null&&B.success?v("info",`${Me(T.type)} stopped`,!0):v("error",`Stop failed: ${(B==null?void 0:B.error)||"Unknown error"}`,!0)}catch(B){v("error",`Stop failed: ${B.message}`,!0)}},[v,n]),L=a.useCallback(async()=>{if(t)try{const T=await n(t,"detect_ides",{});v("info",`Found ${((T==null?void 0:T.result)||[]).length} IDE(s)`,!0)}catch(T){v("error",`Detection failed: ${T.message}`,!0)}},[t,v,n]),_=a.useCallback(async T=>{if(!(!t||!T.trim())){h(!0);try{const B=await n(t,"workspace_add",{path:T.trim()});B!=null&&B.success?v("info",`Workspace added: ${T.trim()}`):v("error",(B==null?void 0:B.error)||"workspace_add failed")}catch(B){v("error",B.message)}finally{h(!1)}return!0}},[t,v,n]),I=a.useCallback(async T=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const B=await n(t,"workspace_remove",{id:T});B!=null&&B.success?v("info","Workspace removed",!0):v("error",(B==null?void 0:B.error)||"workspace_remove failed",!0)}catch(B){v("error",B.message,!0)}finally{h(!1)}}},[t,v,n]),U=a.useCallback(async T=>{var B;if(t){h(!0);try{const O=await n(t,"workspace_set_default",T===null?{clear:!0}:{id:T});if(O!=null&&O.success){v("info",T?"Default workspace updated":"Default workspace cleared",!0);const D=typeof O.defaultWorkspacePath=="string"?O.defaultWorkspacePath:"";D&&((B=j.current)==null||B.call(j,D))}else v("error",(O==null?void 0:O.error)||"workspace_set_default failed",!0)}catch(O){v("error",O.message,!0)}finally{h(!1)}}},[t,v,n]),P=a.useCallback(async T=>{var O;if(!t||!T.trim())return;const B=T.trim();h(!0);try{const D=await n(t,"workspace_set_default",{path:B});D!=null&&D.success?(v("info","Default workspace set from history"),(O=j.current)==null||O.call(j,B)):v("error",(D==null?void 0:D.error)||"Could not set default (path missing on disk?)")}catch(D){v("error",D.message)}finally{h(!1)}},[t,v,n]),z=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:b}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:b})}catch(T){v("warn",`Live nickname updated, but account sync failed: ${T.message}`)}v("info",`Nickname set to "${b||"(cleared)"}"`),k(!1)}catch(T){v("error",`Failed: ${T.message}`)}},[t,b,s,v,r,n]);return{logs:o,launchingIde:d,launchingAgentType:f,workspaceBusy:m,launchPick:p,setLaunchPick:y,editingNickname:x,setEditingNickname:k,nicknameInput:b,setNicknameInput:g,addLog:v,handleLaunchIde:M,runLaunchCliCore:w,handleLaunchCli:N,handleStopCli:$,handleRestartIde:R,handleStopIde:E,handleDetectIdes:L,handleWorkspaceAdd:_,handleWorkspaceRemove:I,handleWorkspaceSetDefault:U,handleWorkspaceResumePath:P,handleSaveNickname:z,setOnDefaultWorkspaceChanged:S}}function Oc({machineId:t,machine:s,ideSessions:n,cliSessions:r,acpSessions:i,actions:o,sendDaemonCommand:c}){const{workspaceBusy:d,handleWorkspaceAdd:l,handleWorkspaceRemove:f,handleWorkspaceSetDefault:u}=o,[m,h]=a.useState(!1),[p,y]=a.useState(""),[x,k]=a.useState([]),[b,g]=a.useState(!1),[j,S]=a.useState(""),v=a.useCallback(async R=>{g(!0),S("");try{const E=await Kr(c,t,R);y(E.path),k(E.directories)}catch(E){S(E instanceof Error?E.message:"Could not load folder")}finally{g(!1)}},[t,c]),M=a.useCallback(()=>{var E;h(!0);const R=s.defaultWorkspacePath||((E=s.workspaces[0])==null?void 0:E.path)||"~";v(R)},[v,s.defaultWorkspacePath,s.workspaces]),w=s.availableMem??s.freeMem,N=s.totalMem>0?Math.min(100,Math.max(0,Math.round((s.totalMem-w)/s.totalMem*100))):0,$=s.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(zt,{icon:e.jsx(sr,{size:16}),label:"Uptime",value:yi(s.uptime)}),e.jsx(zt,{icon:e.jsx(Fe,{size:16}),label:"IDEs",value:`${n.length}`}),e.jsx(zt,{icon:e.jsx(Us,{size:16}),label:"CLIs",value:`${r.length}`}),e.jsx(zt,{icon:e.jsx(Va,{size:16}),label:"ACPs",value:`${i.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(dn,{value:Math.min(Math.round($/s.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${$.toFixed(2)} avg / ${s.cpus} cores`}),e.jsx(dn,{value:N,max:100,label:"Memory",color:"#3b82f6",detail:`${xn(s.totalMem-w)} / ${xn(s.totalMem)}${s.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Lt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:d,value:s.defaultWorkspaceId||"",onChange:R=>void u(R.target.value===""?null:R.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(s.workspaces||[]).map(R=>e.jsx("option",{value:R.id,children:R.label||R.path},R.id))]}),s.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:s.defaultWorkspacePath,children:s.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("button",{type:"button",className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded transition-colors text-xs",disabled:d,onClick:M,children:"Select workspace…"}),e.jsx("span",{className:"text-[11px] text-text-muted",children:"Add workspaces by selecting a folder in the explorer."})]}),(s.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(s.workspaces||[]).map(R=>e.jsxs("li",{className:"flex items-start gap-2 text-[11px] text-text-muted rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[R.id===s.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:dr(R.path,R.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:R.path,children:R.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:d,onClick:()=>void f(R.id),children:"Remove"})]},R.id))})]}),m&&e.jsx(Ys,{title:"Add workspace",description:"Browse the machine like a normal explorer, then add the current folder as a saved workspace.",currentPath:p,directories:x,busy:b,error:j,confirmLabel:"Add workspace",onClose:()=>h(!1),onNavigate:R=>{v(R)},onConfirm:R=>{(async()=>{if(!R)return;await l(R)&&h(!1)})()}})]})}const Kn=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],zc=[{value:"codex-cli",label:"Codex CLI",desc:"OpenAI o3/gpt-5.4",color:"#22c55e"},{value:"claude-cli",label:"Claude Code",desc:"Anthropic Claude",color:"#a855f7"},{value:"gemini-cli",label:"Gemini CLI",desc:"Google Gemini",color:"#3b82f6"}];function Uc({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,d]=a.useState("codex-cli"),[l,f]=a.useState([]),[u,m]=a.useState(""),[h,p]=a.useState([]),[y,x]=a.useState(""),k=a.useRef(null),b=a.useRef(null),g=N=>{f($=>$.includes(N)?$.filter(R=>R!==N):[...$,N])},j=()=>f([...Kn]),S=()=>f([]);a.useEffect(()=>{var N;(N=k.current)==null||N.scrollIntoView({behavior:"smooth"})},[h]),a.useEffect(()=>()=>{b.current&&clearInterval(b.current)},[]);const v=a.useCallback(()=>{b.current&&clearInterval(b.current),b.current=setInterval(async()=>{try{const N=await n(t,"provider_auto_fix_status",{providerType:s.type});(N==null?void 0:N.running)===!1&&i==="running"&&(o("done"),p($=>[...$,`
56
- ✅ Auto-fix completed!`]),b.current&&clearInterval(b.current))}catch{}},3e3)},[t,s.type,n,i]),M=async()=>{if(l.length!==0){o("running"),p(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),x("");try{const N=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...u?{comment:u}:{}});N!=null&&N.success&&(N!=null&&N.started||N!=null&&N.running)?(p($=>[...$,"✅ Agent started. Monitoring progress..."]),v()):(o("error"),x((N==null?void 0:N.error)||"Failed to start auto-fix"))}catch(N){o("error"),x((N==null?void 0:N.message)||"Connection failed")}}},w=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),p(N=>[...N,`
57
- ⚠️ Auto-fix cancelled.`]),o("done"),b.current&&clearInterval(b.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:N=>N.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:zc.map(N=>e.jsxs("button",{onClick:()=>d(N.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===N.value?N.color+"66":"var(--border-subtle)",background:c===N.value?N.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===N.value?N.color:"var(--text-primary)"},children:N.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:N.desc})]},N.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:j,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick:S,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:Kn.map(N=>e.jsxs("button",{onClick:()=>g(N),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:l.includes(N)?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent",color:l.includes(N)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(N)?"☑ ":"☐ ",N]},N))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:u,onChange:N=>m(N.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[h.map((N,$)=>e.jsx("div",{className:N.startsWith("✅")?"text-green-400":"",style:N.startsWith("❌")||N.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:N},$)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:k})]}),y&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:y})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&l.length>0&&`${l.length} script(s) selected`,i==="running"&&"Agent is generating...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:M,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"color-mix(in srgb, var(--accent-primary) 15%, transparent)":void 0,borderColor:l.length>0?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:w,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),p([]),x("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Hc({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var v;const o=s.filter(M=>M.category==="ide"),[c,d]=a.useState(((v=o[0])==null?void 0:v.type)||""),[l,f]=a.useState(""),[u,m]=a.useState(""),[h,p]=a.useState(!1),[y,x]=a.useState(""),[k,b]=a.useState(!1),g=M=>{const w=M.toLowerCase().replace(/[^a-z0-9-]/g,"");f(w),(!u||u===j(l))&&m(j(w))},j=M=>M.split("-").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" "),S=async()=>{if(!(!l||!u||!c)){p(!0),x("");try{const M=await n(t,"provider_clone",{type:l,name:u,category:"ide",location:"user",cloneFrom:c});M!=null&&M.success||M!=null&&M.created?(b(!0),i==null||i(l)):x((M==null?void 0:M.error)||"Failed to create provider")}catch(M){x((M==null?void 0:M.message)||"Connection failed")}p(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[480px] rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:M=>M.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:k?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(M=>e.jsxs("button",{onClick:()=>d(M.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===M.type?"color-mix(in srgb, var(--accent-primary) 40%, transparent)":"var(--border-subtle)",background:c===M.type?"color-mix(in srgb, var(--accent-primary) 8%, transparent)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:M.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===M.type?"#a78bfa":"var(--text-secondary)"},children:M.displayName})]},M.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:l,onChange:M=>g(M.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:u,onChange:M=>m(M.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),y&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:y})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:k?e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:S,disabled:!l||!u||h,className:"machine-btn",style:{background:l&&u?"rgba(34,197,94,0.12)":void 0,borderColor:l&&u?"rgba(34,197,94,0.3)":void 0,color:l&&u?"#86efac":void 0,opacity:!l||!u||h?.4:1},children:h?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Fc({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[f,u]=a.useState("all"),[m,h]=a.useState(null),[p,y]=a.useState(!1),x=a.useCallback(async()=>{var b;if(t){c(!0);try{const g=await n(t,"get_provider_settings",{}),j=(g==null?void 0:g.result)||g;if(g!=null&&g.success&&(j!=null&&j.settings)){const S=[];for(const[v,M]of Object.entries(j.settings)){const w=s.find(N=>N.type===v);S.push({type:v,displayName:(w==null?void 0:w.displayName)||v,icon:(w==null?void 0:w.icon)||"",category:(w==null?void 0:w.category)||"unknown",schema:M,values:((b=j.values)==null?void 0:b[v])||{}})}S.sort((v,M)=>v.category.localeCompare(M.category)||v.displayName.localeCompare(M.displayName)),i(S)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&x()},[]);const k=async(b,g,j)=>{l(`${b}.${g}`),i(S=>S.map(v=>v.type===b?{...v,values:{...v.values,[g]:j}}:v));try{const S=await n(t,"set_provider_setting",{providerType:b,key:g,value:j});S!=null&&S.success||x()}catch{x()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(b=>e.jsx("button",{onClick:()=>u(b),className:`machine-btn text-[10px] px-2 py-0.5 ${f===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>y(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:x,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),f!=="all"&&r.filter(b=>b.category===f).length>1&&(()=>{const b=r.filter(v=>v.category===f),g=new Map;for(const v of b)for(const M of v.schema){if(M.type!=="boolean")continue;const w=g.get(M.key),N=!!(v.values[M.key]??M.default);w?(w.onCount+=N?1:0,w.total+=1):g.set(M.key,{label:M.label||M.key,onCount:N?1:0,total:1})}const j=[...g.entries()].filter(([,v])=>v.total===b.length);if(j.length===0)return null;const S=async(v,M)=>{for(const w of b)await k(w.type,v,M)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",f.toUpperCase()," providers (",b.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(([v,M])=>{const w=M.onCount===M.total,N=M.onCount===0;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"text-text-secondary font-medium",children:M.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",M.onCount,"/",M.total,")"]}),e.jsx("button",{onClick:()=>void S(v,!0),disabled:w,className:`machine-btn text-[9px] px-1.5 py-px ${w?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void S(v,!1),disabled:N,className:`machine-btn text-[9px] px-1.5 py-px ${N?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},v)})})]})})(),o&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(b=>f==="all"||b.category===f).map(b=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:b.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:b.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:b.category==="acp"?"rgba(139,92,246,0.08)":b.category==="cli"?"rgba(59,130,246,0.08)":b.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:b.category==="acp"?"#a78bfa":b.category==="cli"?"#60a5fa":b.category==="ide"?"#86efac":"var(--status-warning)"},children:b.category}),b.category==="ide"&&e.jsx("button",{onClick:()=>h(s.find(g=>g.type===b.type)||{type:b.type,name:b.displayName,displayName:b.displayName,icon:b.icon,category:b.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:b.schema.map(g=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[g.label||g.key,d===`${b.type}.${g.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),g.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:g.description})]}),e.jsx("div",{className:"shrink-0",children:g.type==="boolean"?e.jsx("button",{onClick:()=>k(b.type,g.key,!(b.values[g.key]??g.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:b.values[g.key]??g.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:b.values[g.key]??g.default?21:3}})}):g.type==="number"?e.jsx("input",{type:"number",value:b.values[g.key]??g.default??0,min:g.min,max:g.max,onChange:j=>{const S=parseInt(j.target.value)||0;g.min!==void 0&&S<g.min||g.max!==void 0&&S>g.max||k(b.type,g.key,S)},className:"machine-input w-20 text-center text-[11px]"}):g.type==="select"&&g.options?e.jsx("select",{value:b.values[g.key]??g.default??"",onChange:j=>k(b.type,g.key,j.target.value),className:"machine-input text-[11px]",children:g.options.map(j=>e.jsx("option",{value:j,children:j},j))}):e.jsx("input",{type:"text",value:b.values[g.key]??g.default??"",onBlur:j=>k(b.type,g.key,j.target.value),className:"machine-input w-[120px] text-[11px]"})})]},g.key))})]},b.type))}),m&&e.jsx(Uc,{machineId:t,provider:m,sendDaemonCommand:n,onClose:()=>h(null)}),p&&e.jsx(Hc,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>y(!1),onCreated:()=>{y(!1),x()}})]})}function Vc({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,f]=a.useState("debug"),u=a.useRef(null),m=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const h=async()=>{try{const y=await s(t,"get_logs",{count:200,minLevel:l,since:i}),x=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&Array.isArray(x==null?void 0:x.logs)&&x.logs.length>0){r(b=>[...b,...x.logs.map(j=>({timestamp:j.ts,level:j.level,message:`[${j.category}] ${j.message}`}))].slice(-300));const k=Math.max(...x.logs.map(b=>b.ts));o(k)}}catch{}};h();const p=setInterval(h,3e3);return()=>clearInterval(p)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const h=m.current?"smooth":"instant";setTimeout(()=>{var p;(p=u.current)==null||p.scrollIntoView({behavior:h}),m.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(h=>e.jsx("button",{onClick:()=>{f(h),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((h,p)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(h.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:h.level==="error"?"#ef4444":h.level==="warn"?"var(--status-warning)":h.level==="debug"?"#475569":"#8b5cf6"},children:h.level==="error"?"ERR":h.level==="warn"?"WRN":h.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:h.message})]},p)),e.jsx("div",{ref:u})]})]})}function qc({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:i}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(o=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:o.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:o.label||o.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:o.path})]},o.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function Wn({children:t}){return e.jsx("div",{className:"text-xs font-semibold text-text-muted mb-2 tracking-wide uppercase",children:t})}function Gc({machineEntry:t,providers:s,recentLaunches:n,onUpgradeDaemon:r,onOpenLogs:i,onOpenRecent:o,onOpenWorkspace:c,onGoTab:d}){const l=t.detectedIdes||[],f=s.filter(y=>y.category==="cli"),u=s.filter(y=>y.category==="acp"),m=n.slice(0,4),h=[l.length>0?{id:"ide",kind:"ide",label:"IDE Workspace",desc:"Graphical app"}:null,f.length>0?{id:"cli",kind:"cli",label:"CLI Workspace",desc:"Terminal"}:null,u.length>0?{id:"acp",kind:"acp",label:"ACP Workspace",desc:"Agent"}:null].filter(Boolean),p=y=>y==="ide"?"IDE":y==="cli"?"CLI":"ACP";return e.jsxs("div",{className:"flex flex-col gap-6 md:min-w-[280px] md:max-w-[340px] shrink-0 border-r border-[#ffffff0a] pr-4 md:pr-6 md:h-full overflow-y-auto",children:[m.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Wn,{children:"Recent Activity"}),e.jsx("div",{className:"flex flex-col gap-1.5",children:m.map(y=>e.jsxs("button",{type:"button",className:"flex flex-col gap-1 items-start text-left p-3 rounded-xl bg-bg-surface border border-[#ffffff08] hover:bg-[#ffffff0a] hover:border-[#ffffff10] transition-colors cursor-pointer group",onClick:()=>o(y),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary truncate w-full group-hover:text-accent-primary transition-colors",children:y.label}),e.jsxs("span",{className:"text-xs text-text-secondary truncate w-full opacity-80",children:[p(y.kind),y.subtitle?` · ${y.subtitle}`:""]})]},y.id))})]}),h.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Wn,{children:"New Workspace"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:h.map(y=>e.jsxs("button",{type:"button",className:"flex flex-col items-center justify-center p-3 gap-1 rounded-xl bg-bg-surface border border-[#ffffff08] hover:bg-[#ffffff0e] hover:scale-[1.02] active:scale-95 transition-all cursor-pointer",onClick:()=>c(y.kind),children:[e.jsx("span",{className:"text-sm font-semibold text-text-primary text-center",children:y.label.replace(" Workspace","")}),e.jsx("span",{className:"text-[10px] text-text-muted text-center uppercase tracking-wide",children:y.desc})]},y.id))})]}),e.jsxs("div",{className:"flex flex-col gap-2 mt-auto pt-4 border-t border-[#ffffff08]",children:[t.versionMismatch&&e.jsx("button",{type:"button",className:"btn btn-sm w-full bg-accent-primary/20 text-accent-primary border-accent-primary/30 hover:bg-accent-primary/30",onClick:r,children:"Update Daemon"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:i,children:"Logs"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:()=>d("providers"),children:"Providers"}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm flex-1",onClick:()=>d("overview"),children:"System"})]})]})]})}function Yc(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Xc={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function Is({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d,initialWorkspaceId:l,initialWorkspacePath:f}){const u=kt(),{handleLaunchIde:m,handleStopCli:h,handleRestartIde:p,handleStopIde:y,handleDetectIdes:x,launchingIde:k,launchingAgentType:b}=c,[g,j]=a.useState(null),S=a.useCallback(A=>{A&&u({pathname:"/",search:`?activeTab=${encodeURIComponent(A)}`})},[u]),v=Xc[t],M=t==="ide",w=t==="acp",N=r.filter(A=>A.category===t),$=new Map(N.map(A=>[A.type,A.displayName||A.type])),[R,E]=a.useState(""),[L,_]=a.useState(""),[I,U]=a.useState(""),[P,z]=a.useState(f?"__custom__":l||s.defaultWorkspaceId||""),[T,B]=a.useState(f||""),[O,D]=a.useState([]),[X,xe]=a.useState(!1),[ee,fe]=a.useState(""),[F,q]=a.useState([]),[V,pe]=a.useState(!1),[de,oe]=a.useState(""),ue=a.useRef(null),[ae,ge]=a.useState(null),se=a.useRef("__home__"),[ce,G]=a.useState("__home__"),[te,C]=a.useState(!1),J=O.filter(A=>!i.some(Y=>Y.type===A&&qe(Y.status)!=="stopped")),Z=a.useRef({});a.useEffect(()=>{s.defaultWorkspaceId&&!P&&z(s.defaultWorkspaceId)},[s.defaultWorkspaceId]),a.useEffect(()=>{if(f){z("__custom__"),B(f);return}l&&(z(l),B(""))},[l,f]);const ne=(()=>{if(P==="__custom__")return T.trim();if(!P)return"";const A=(s.workspaces||[]).find(Y=>Y.id===P);return(A==null?void 0:A.path)||""})(),be=a.useCallback(A=>{const Y=Z.current[A];Y&&(clearTimeout(Y),delete Z.current[A]),D(Q=>Q.filter(H=>H!==A))},[]),we=a.useCallback(async A=>{if(d){pe(!0),oe("");try{const Y=await Kr(d,n,A);fe(Y.path),B(Y.path),q(Y.directories)}catch(Y){oe(Y instanceof Error?Y.message:"Could not load folder")}finally{pe(!1)}}},[n,d]),Se=a.useCallback(()=>{var Y;if(!d)return;z("__custom__"),xe(!0);const A=T.trim()||ne||s.defaultWorkspacePath||((Y=s.workspaces[0])==null?void 0:Y.path)||"~";we(A)},[T,we,s.defaultWorkspacePath,s.workspaces,ne,d]),Te=a.useCallback((A,Y)=>{ue.current=Y,se.current=A.selectedWorkspaceKey||"__home__",G(A.selectedWorkspaceKey||"__home__"),ge(A)},[]),Ze=a.useCallback(()=>{ue.current&&(C(!0),ue.current().finally(()=>{ue.current=null,C(!1),ge(null)}))},[]),Ke=a.useCallback(A=>{if(!A)return;D(Q=>Q.includes(A)?Q:[...Q,A]);const Y=Z.current[A];Y&&clearTimeout(Y),Z.current[A]=setTimeout(()=>{D(Q=>Q.filter(H=>H!==A)),delete Z.current[A]},2e4)},[]);a.useEffect(()=>{for(const A of i)qe(A.status)!=="stopped"&&be(A.type)},[i,be]),a.useEffect(()=>()=>{Object.values(Z.current).forEach(clearTimeout),Z.current={}},[]);const[ze,We]=a.useState({}),[De,re]=a.useState(null);a.useEffect(()=>{if(!M||!n||!d)return;(async()=>{try{const Y=await d(n,"get_ide_extensions",{}),Q=(Y==null?void 0:Y.result)||Y;Q!=null&&Q.success&&(Q!=null&&Q.ideExtensions)&&We(Q.ideExtensions)}catch{}})()},[M,n,d]);const ke=A=>M?Me(A.type):t==="cli"?A.cliName:A.acpName,je=M?s.detectedIdes||[]:[],ye=a.useCallback(async A=>{const Y=(A==null?void 0:A.type)||R,Q=(A==null?void 0:A.workspacePath)??ne;if(M){await m(Y,Q?{workspace:Q}:void 0)&&Ke(Y);return}const H=await c.runLaunchCliCore({cliType:Y,dir:A!=null&&A.workspaceId?void 0:Q||void 0,workspaceId:(A==null?void 0:A.workspaceId)||void 0,useHome:(A==null?void 0:A.useHome)||!(A!=null&&A.workspaceId)&&!Q,argsStr:(A==null?void 0:A.argsStr)??(L||void 0),model:(A==null?void 0:A.model)??(w&&I||void 0)});H.success&&(Ke(Y),H.sessionId&&S(H.sessionId))},[c,m,w,M,L,I,Ke,S,ne,R]),W=()=>{const A=M?Me(R):$.get(R)||R,{options:Y,selectedKey:Q}=xt({machine:s,currentWorkspaceId:P&&P!=="__custom__"?P:null,currentWorkspacePath:ne});Te({title:`Launch ${A}?`,description:"Review the provider and target folder before starting this session.",confirmLabel:"Launch",workspaceOptions:Y,selectedWorkspaceKey:Q,details:[{label:"Mode",value:v.label},{label:"Provider",value:A},...!M&&L.trim()?[{label:"Arguments",value:L.trim()}]:[],...w&&I.trim()?[{label:"Model",value:I.trim()}]:[]]},async()=>{const H=Y.find(Le=>Le.key===se.current);H!=null&&H.workspaceId?(z(H.workspaceId),B("")):H!=null&&H.workspacePath?(z("__custom__"),B(H.workspacePath)):(z(""),B("")),await ye({workspaceId:(H==null?void 0:H.workspaceId)??null,workspacePath:(H==null?void 0:H.workspacePath)??"",useHome:!(H!=null&&H.workspaceId)&&!(H!=null&&H.workspacePath)})})},K=A=>{M?y(A):h(A.type,A.workspace,A.id)},ie=a.useCallback(async(A,Y,Q=!1)=>{if(A.mode===Y){Q&&A.sessionId&&S(A.sessionId);return}if(!d||!A.sessionId){Q&&A.sessionId&&S(A.sessionId);return}try{await d(n,"set_cli_view_mode",{targetSessionId:A.sessionId,cliType:A.type,mode:Y}),Q&&S(A.sessionId)}catch(H){console.error("Failed to switch CLI view mode:",H)}},[n,S,d]),le=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:P,onChange:A=>{const Y=A.target.value;if(z(Y),Y==="__custom__"&&d){Se();return}Y!=="__custom__"&&B("")},className:"px-3 py-1.5 rounded-md min-w-[200px] flex-1 text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(A=>e.jsxs("option",{value:A.id,children:[A.id===s.defaultWorkspaceId?"⭐ ":"",dr(A.path,A.label)]},A.id)),e.jsx("option",{value:"__custom__",children:d?"📁 Select workspace…":"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:d?"📁 Select workspace…":"✏️ Custom path…"})]})}),P==="__custom__"&&(d?e.jsx("button",{type:"button",className:"px-3 py-1.5 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] hover:border-accent-primary text-text-secondary hover:text-text-primary transition-colors",onClick:Se,children:"Select workspace…"}):e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:T,onChange:A=>B(A.target.value),className:"px-3 py-1.5 rounded-md flex-1 min-w-[200px] text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors",autoFocus:!0}))]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:P==="__custom__"?ne?e.jsx("span",{className:"font-mono truncate block",title:ne,children:ne}):d?"Browse to a folder before launching there.":"Enter an absolute path to launch there.":ne?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:P===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:ne,children:ne})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-5 rounded-xl mb-6 bg-bg-secondary border ${v.accent} relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 left-0 w-full height-[1px] bg-gradient-to-r from-transparent via-[#ffffff20] to-transparent"}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-primary/60"}),"Select ",v.label," to Launch"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:M?je.length>0?je.map(A=>{const Y=i.find(Ae=>(Ae.type||"").toLowerCase()===(A.type||"").toLowerCase()&&qe(Ae.status)!=="stopped"),Q=A.running||!!Y,H=!!Y&&Y.cdpConnected,Le=O.includes(A.type||A.id||""),me=R===(A.type||"");return e.jsxs("button",{onClick:()=>{if(H&&Y){const Ae=Y.sessionId;Ae?u(`/dashboard?activeTab=${encodeURIComponent(Ae)}`,{state:{openRemoteForTabKey:Ae}}):u("/dashboard",{state:{openRemoteForTabKey:Y.id}});return}Le||E(Ae=>Ae===(A.type||"")?"":A.type||"")},disabled:!!k||Le,className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${H?"bg-green-500/10 border-green-500/20 hover:bg-green-500/20":me?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,style:{opacity:k&&k!==A.type?.4:1},children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:o(A.type)}),Q&&e.jsx("span",{className:`absolute -top-1 -right-1 w-2 h-2 rounded-full ${H?"bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]":"bg-orange-500 shadow-[0_0_6px_rgba(249,115,22,0.6)] animate-pulse"}`})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.name||Me(A.type)}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${H?"text-green-400":Le?"text-orange-400":me?"text-accent-primary":"text-text-muted"}`,children:H?"Open Session":Le?"Starting...":me?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 flex flex-col items-center justify-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted italic gap-2",children:["No IDEs detected.",e.jsxs("button",{onClick:x,className:"btn bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary px-3 py-1.5 rounded-lg flex items-center gap-1.5",children:[e.jsx(Ua,{size:14})," Scan System"]})]}):N.length>0?N.map(A=>{const Y=R===A.type,Q=O.includes(A.type),Le=!!i.find(me=>me.type===A.type&&qe(me.status)!=="stopped");return e.jsxs("button",{onClick:()=>E(me=>me===A.type?"":A.type),className:`flex flex-col items-center justify-center p-3.5 gap-2 rounded-xl border transition-all cursor-pointer group ${Y?"bg-accent-primary/10 border-accent-primary scale-[1.02] shadow-glow":"bg-bg-primary border-[#ffffff1a] hover:bg-[#ffffff0c] hover:border-[#ffffff30]"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"text-2xl drop-shadow-sm transition-transform group-hover:scale-110 block",children:A.icon}),Le&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 rounded-full bg-green-500 shadow-[0_0_6px_rgba(34,197,94,0.6)]"})]}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("span",{className:"text-xs font-semibold text-text-primary text-center",children:A.displayName}),e.jsx("span",{className:`text-[9px] mt-0.5 uppercase tracking-wider font-medium ${Q?"text-orange-400":Y?"text-accent-primary":"text-text-muted"}`,children:Q?"Starting...":Y?"Configure":"Select"})]})]},A.type)}):e.jsxs("div",{className:"col-span-full py-6 text-center bg-bg-primary/50 border border-dashed border-[#ffffff1a] rounded-xl text-xs text-text-muted",children:["No ",t.toUpperCase()," providers available"]})}),R&&(M?je.find(A=>A.type===R):N.find(A=>A.type===R))&&e.jsxs("div",{className:"mt-5 pt-5 border-t border-[#ffffff1a] flex flex-col gap-4 animate-in slide-in-from-top-2 fade-in duration-200",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center justify-between",children:[e.jsx("span",{children:"Launch Settings"}),e.jsx("span",{className:"text-accent-primary font-bold",children:M?Me(R):$.get(R)||R})]}),le,!M&&e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[w&&e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Target Model"}),e.jsx("input",{type:"text",placeholder:"Leave empty for default",value:I,onChange:A=>U(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 flex-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-text-secondary uppercase",children:"Startup Arguments"}),e.jsx("input",{type:"text",placeholder:"Optional flags...",value:L,onChange:A=>_(A.target.value),className:"px-3 py-2 rounded-md text-sm bg-bg-primary border border-[#ffffff1a] focus:border-accent-primary focus:outline-none transition-colors w-full"})]})]}),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsx("button",{onClick:W,disabled:!!b||!!k||O.includes(R),className:"btn btn-primary h-9 px-6 font-bold transition-all flex items-center gap-2 hover:shadow-glow hover:-translate-y-px",children:b===R||k===R?"⏳ Launching...":"▶ Launch"})})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length+O.filter(A=>!i.some(Y=>Y.type===A&&qe(Y.status)!=="stopped")).length,")"]}),i.length===0&&J.length===0?e.jsxs("div",{className:"py-7.5 px-5 text-center rounded-xl bg-bg-secondary border border-dashed border-border-subtle text-text-muted text-[13px] mb-5",children:["No ",v.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[J.map(A=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(A)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:M?Me(A):$.get(A)||A}),e.jsx("div",{className:"text-[11px] text-text-muted",children:b===A?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${A}`)),i.map(A=>{const Y=M?A:null,Q=w?A:null,H=!M&&!w?A:null,Le=qe(A.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(A.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ke(A),(Y==null?void 0:Y.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",Y.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:A.workspace||"—"}),(Q==null?void 0:Q.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",Q.currentModel]}),(Q==null?void 0:Q.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",Q.currentPlan]}),(H==null?void 0:H.mode)&&e.jsx("span",{className:H.mode==="chat"?"text-violet-400":"text-text-secondary",children:H.mode==="chat"?"Chat view":"Terminal view"})]}),H&&(H.runtimeKey||H.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[H.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",H.runtimeKey]}),e.jsx("button",{type:"button",className:"flex items-center justify-center px-1.5 py-0.5 rounded text-[9px] bg-[#ffffff0a] hover:bg-[#ffffff14] border border-[#ffffff0a] text-text-muted hover:text-text-primary transition-colors cursor-pointer",onClick:()=>{var me;(me=navigator.clipboard)==null||me.writeText(`adhdev attach ${H.runtimeKey}`),j(H.runtimeKey||null),window.setTimeout(()=>{j(Ae=>Ae===H.runtimeKey?null:Ae)},1200)},children:g===H.runtimeKey?"Copied":"Copy"})]}),H.runtimeWriteOwner&&e.jsx("span",{style:{color:H.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:H.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Yc(H.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Le==="stopped"?"bg-red-500/[0.08] text-red-500":Le==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Le}),M&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{const me=A.sessionId;if(me){u(`/dashboard?activeTab=${encodeURIComponent(me)}`,{state:{openRemoteForTabKey:me}});return}u("/dashboard",{state:{openRemoteForTabKey:A.id}})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-primary transition-colors cursor-pointer",title:"Open remote control",children:e.jsx(Fe,{size:13})}),e.jsx("button",{onClick:()=>{const me=A.workspace||"",{options:Ae,selectedKey:ve}=xt({machine:s,currentWorkspacePath:me});Te({title:`Restart ${Me(A.type)}?`,description:"Review or change the target workspace before restarting this IDE.",confirmLabel:"Restart",workspaceOptions:Ae,selectedWorkspaceKey:ve,details:[{label:"Mode",value:"IDE"},{label:"Provider",value:Me(A.type)}]},async()=>{const Ge=Ae.find(ht=>ht.key===se.current),Oe=(Ge==null?void 0:Ge.workspacePath)??"";if(Oe&&Oe!==me){await ye({type:A.type,workspacePath:Oe});return}await p(A)})},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-orange-500/20 text-orange-400 transition-colors cursor-pointer",title:"Restart",children:e.jsx(Os,{size:14})})]}),w&&e.jsx("button",{onClick:()=>{const me=A.sessionId;me&&S(me)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"View chat",disabled:!A.sessionId,children:e.jsx(rt,{size:14})}),H&&Le!=="stopped"&&e.jsxs(e.Fragment,{children:[H.mode&&e.jsx(Fs,{mode:H.mode,onChange:me=>void ie(H,me,!1),compact:!0}),e.jsx("button",{onClick:()=>{const me=A.sessionId;me&&S(me)},className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-[#ffffff14] disabled:opacity-50 disabled:cursor-not-allowed text-text-primary transition-colors cursor-pointer",title:"Open current view in dashboard",disabled:!A.sessionId,children:H.mode==="chat"?e.jsx(rt,{size:14}):e.jsx(Fe,{size:13})})]}),Le==="stopped"?e.jsx("button",{onClick:()=>{const me=A.workspace||"",Ae=M?Me(A.type):ke(A),{options:ve,selectedKey:Ge}=xt({machine:s,currentWorkspacePath:me});Te({title:`Launch ${Ae}?`,description:"Review or change the target workspace before launching this stopped session again.",confirmLabel:"Launch",workspaceOptions:ve,selectedWorkspaceKey:Ge,details:[{label:"Mode",value:v.label},{label:"Provider",value:Ae}]},async()=>{const Oe=ve.find(ht=>ht.key===se.current);await ye({type:A.type,workspaceId:(Oe==null?void 0:Oe.workspaceId)??null,workspacePath:(Oe==null?void 0:Oe.workspacePath)??"",useHome:!(Oe!=null&&Oe.workspaceId)&&!(Oe!=null&&Oe.workspacePath),model:Q==null?void 0:Q.currentModel})})},disabled:O.includes(A.type),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-green-500/20 text-green-400 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",title:"Restart",children:O.includes(A.type)?"⏳":e.jsx(nr,{size:14})}):e.jsx("button",{onClick:()=>K(A),className:"flex items-center justify-center w-7 h-7 rounded bg-[#ffffff0a] hover:bg-red-500/20 text-red-400 transition-colors cursor-pointer",title:"Stop",children:e.jsx(jt,{size:14})})]})]}),Y&&Y.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:Y.aiAgents.map(me=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${lr(me.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[me.name," · ",qe(me.status)]},me.id))}),Y&&(ze[Y.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(ze[Y.type]||[]).map(me=>e.jsxs("button",{disabled:De===`${Y.type}.${me.type}`,onClick:async()=>{const Ae=`${Y.type}.${me.type}`;re(Ae);try{await d(n,"set_ide_extension",{ideType:Y.type,extensionType:me.type,enabled:!me.enabled}),We(ve=>({...ve,[Y.type]:(ve[Y.type]||[]).map(Ge=>Ge.type===me.type?{...Ge,enabled:!Ge.enabled}:Ge)}))}catch(ve){console.error("Extension toggle failed:",ve)}finally{re(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${me.enabled?"bg-accent-primary/10 border-accent-primary/20 text-accent-primary-light":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${me.enabled?"bg-accent-primary shadow-glow":"bg-zinc-600"}`}),me.name,e.jsx("span",{className:"text-[9px] font-normal",children:me.enabled?"ON":"OFF"})]},me.type))})]})]},A.id)})]}),X&&d&&e.jsx(Ys,{title:"Select workspace",description:"Choose a folder in a regular explorer-style dialog, then use it as the launch target.",currentPath:ee,directories:F,busy:V,error:de,confirmLabel:"Use this folder",onClose:()=>xe(!1),onNavigate:A=>{we(A)},onConfirm:A=>{B(A),z("__custom__"),xe(!1)}}),ae&&e.jsx(Xs,{title:ae.title,description:ae.description,details:ae.details,workspaceOptions:ae.workspaceOptions,selectedWorkspaceKey:ce,onWorkspaceChange:A=>{se.current=A,G(A)},confirmLabel:ae.confirmLabel,busy:te,onConfirm:Ze,onCancel:()=>{ue.current=null,ge(null)}})]})}const On=[{id:"ide",label:"IDE",helper:"Open a graphical workspace and attach CDP"},{id:"cli",label:"CLI",helper:"Launch a terminal-first workspace on this machine"},{id:"acp",label:"ACP",helper:"Launch an ACP-backed workspace on this machine"}];function Zc({machine:t,machineId:s,providers:n,ideSessions:r,cliSessions:i,acpSessions:o,actions:c,getIcon:d,initialCategory:l="ide",initialWorkspaceId:f,initialWorkspacePath:u,sendDaemonCommand:m}){var x;const[h,p]=a.useState(l);a.useEffect(()=>{p(l)},[l]);const y=a.useMemo(()=>({ide:r.length,cli:i.length,acp:o.length}),[r.length,i.length,o.length]);return e.jsxs("div",{className:"flex flex-col flex-1 min-w-0 h-full",children:[e.jsxs("div",{className:"flex flex-col gap-1 pb-4 border-b border-[#ffffff0a] mb-4",children:[e.jsx("div",{className:"text-lg font-semibold text-text-primary",children:"Workspace Launcher"}),e.jsx("div",{className:"text-sm text-text-secondary",children:"Choose a workspace context first, then pick how you want to open it."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-baseline gap-4 mb-4",children:[e.jsx("div",{className:"flex bg-bg-surface p-1 rounded-lg border border-[#ffffff0a] w-fit",children:On.map(k=>e.jsxs("button",{type:"button",className:`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${h===k.id?"bg-[#ffffff10] text-text-primary shadow-sm":"text-text-secondary hover:text-text-primary hover:bg-[#ffffff05]"}`,onClick:()=>p(k.id),children:[e.jsx("span",{children:k.label}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ${h===k.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:y[k.id]})]},k.id))}),e.jsx("div",{className:"text-xs text-text-muted italic",children:(x=On.find(k=>k.id===h))==null?void 0:x.helper})]}),h==="ide"&&e.jsx(Is,{category:"ide",machine:t,machineId:s,providers:n,managedEntries:r,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u}),h==="cli"&&e.jsx(Is,{category:"cli",machine:t,machineId:s,providers:n,managedEntries:i,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u}),h==="acp"&&e.jsx(Is,{category:"acp",machine:t,machineId:s,providers:n,managedEntries:o,getIcon:d,actions:c,sendDaemonCommand:m,initialWorkspaceId:f,initialWorkspacePath:u})]})}function Jc({onNicknameSynced:t}={}){var de,oe,ue,ae,ge,se,ce,G,te;const{id:s}=Ca(),n=kt(),r=Bs(),{sendCommand:i}=ct(),o=Hs(),c=o.ides||[],d=o.initialLoaded??!0,l=c.find(C=>C.id===s&&C.daemonMode),f=c.some(C=>C.type==="adhdev-daemon"),[u,m]=a.useState("workspace"),[h,p]=a.useState("ide"),y=a.useRef(null),[x,k]=a.useState(null),b=a.useRef("__home__"),[g,j]=a.useState("__home__"),[S,v]=a.useState(!1),M=a.useRef(null),w=()=>{if(f){n("/dashboard",{state:{mobileSection:"machines"}});return}n("/machines")},N=Wc({machineId:s,registeredMachineId:(l==null?void 0:l.machineId)||null,sendDaemonCommand:i,onNicknameSynced:t,logsEndRef:M});a.useEffect(()=>it.onToast(J=>{o.setToasts(ne=>{if(ne.some(Se=>Se.message===J.message&&J.timestamp-Se.timestamp<3e3))return ne;const we={id:J.id,message:J.message,type:J.type,timestamp:J.timestamp,targetKey:J.targetKey,actions:J.actions};return[...ne.slice(-4),we]});const Z=J.duration||5e3;setTimeout(()=>o.setToasts(ne=>ne.filter(be=>be.id!==J.id)),Z)}),[o]);const $=(l==null?void 0:l.availableProviders)||[],R={};for(const C of $)R[C.type]=C.icon;const E=C=>R[C]||"",L=l?{id:l.id,hostname:ur(l,{fallbackId:l.id}),platform:((de=l.machine)==null?void 0:de.platform)||"unknown",arch:((oe=l.machine)==null?void 0:oe.arch)||"",cpus:((ue=l.machine)==null?void 0:ue.cpus)||0,totalMem:((ae=l.machine)==null?void 0:ae.totalMem)||0,freeMem:((ge=l.machine)==null?void 0:ge.freeMem)||0,availableMem:(se=l.machine)==null?void 0:se.availableMem,loadavg:((ce=l.machine)==null?void 0:ce.loadavg)||[],uptime:((G=l.machine)==null?void 0:G.uptime)||0,release:((te=l.machine)==null?void 0:te.release)||"",cdpConnected:!!l.cdpConnected,machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null}:null,_=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!ns(C)&&!It(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:Si(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],childSessions:C.childSessions||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),I=c.filter(C=>C.daemonId===s&&ns(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,mode:C.mode,daemonId:s})),U=c.filter(C=>C.daemonId===s&&It(C)).map(C=>({id:C.id,sessionId:C.sessionId,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,providerSessionId:C.providerSessionId,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!L)return d?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:w,className:"machine-btn-back",children:"← Back"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const P=tt(l,{fallbackId:L.id}),z="workspace",T=r.state,B=T==null?void 0:T.initialMachineTab,O=T==null?void 0:T.initialWorkspaceCategory,D=T==null?void 0:T.initialWorkspaceId,X=T==null?void 0:T.initialWorkspacePath,xe=B==="ides"||B==="clis"||B==="acps"?"workspace":B||z,ee=B==="ides"?"ide":B==="clis"?"cli":B==="acps"?"acp":O,fe=[..._.map(C=>{var J,Z,ne,be,we;return{id:`ide:${C.type}:${C.workspace||""}`,label:((J=C.activeChat)==null?void 0:J.title)||C.type,kind:"ide",providerType:C.type,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((we=(be=(ne=(Z=C.activeChat)==null?void 0:Z.messages)==null?void 0:ne.at)==null?void 0:be.call(ne,-1))==null?void 0:we.timestamp)||0}}),...I.map(C=>{var J,Z,ne,be,we;return{id:`cli:${C.type}:${C.workspace||""}`,label:((J=C.activeChat)==null?void 0:J.title)||C.cliName,kind:"cli",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.workspace||void 0,workspace:C.workspace||void 0,timestamp:((we=(be=(ne=(Z=C.activeChat)==null?void 0:Z.messages)==null?void 0:ne.at)==null?void 0:be.call(ne,-1))==null?void 0:we.timestamp)||0}}),...U.map(C=>{var J,Z,ne,be,we;return{id:`acp:${C.type}:${C.workspace||""}`,label:((J=C.activeChat)==null?void 0:J.title)||C.acpName,kind:"acp",providerType:C.type,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace||void 0,currentModel:C.currentModel,timestamp:((we=(be=(ne=(Z=C.activeChat)==null?void 0:Z.messages)==null?void 0:ne.at)==null?void 0:be.call(ne,-1))==null?void 0:we.timestamp)||0}})].sort((C,J)=>J.timestamp-C.timestamp).map(({timestamp:C,...J})=>J),F=(l.recentLaunches||[]).length>0?l.recentLaunches.map(C=>({id:C.id,label:C.title||C.providerName||C.providerType,kind:C.kind,providerType:C.providerType,providerSessionId:C.providerSessionId,subtitle:C.currentModel||C.workspace||void 0,workspace:C.workspace,currentModel:C.currentModel})):fe,q=a.useCallback(()=>{y.current&&(v(!0),y.current().finally(()=>{y.current=null,v(!1),k(null)}))},[]),V=a.useCallback(C=>{const{options:J,selectedKey:Z}=xt({machine:L,currentWorkspacePath:C.workspace}),ne=async()=>{p(C.kind),m("workspace")};y.current=async()=>{const be=J.find(Te=>Te.key===b.current),we=(be==null?void 0:be.workspacePath)??null,Se=(be==null?void 0:be.workspaceId)??null;if(C.kind==="ide"&&C.providerType){await N.handleLaunchIde(C.providerType,we?{workspace:we}:void 0);return}if((C.kind==="cli"||C.kind==="acp")&&C.providerType){await N.runLaunchCliCore({cliType:C.providerType,dir:Se?void 0:we||"",workspaceId:Se||void 0,model:C.kind==="acp"?C.currentModel:void 0,resumeSessionId:C.providerSessionId});return}await ne()},b.current=Z,j(Z),k({title:`Launch ${C.label}?`,description:"Recent launches now require one more confirmation before they start.",confirmLabel:"Launch",workspaceOptions:J,details:[{label:"Mode",value:C.kind.toUpperCase()},...C.providerType?[{label:"Provider",value:C.providerType}]:[]]})},[N,L]);a.useEffect(()=>{m(xe)},[z,xe,L.id]),a.useEffect(()=>{ee&&p(ee)},[ee,L.id]);const pe=[{id:"workspace",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fe,{size:14})," Workspace"]}),count:_.length+I.length+U.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ds,{size:14})," Providers"]})},{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Fa,{size:14})," System"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(za,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex flex-col w-full bg-bg-surface px-4 md:px-8 pt-6 pb-0 shrink-0 border-b border-[#ffffff0a]",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-3 w-full min-w-0",children:[e.jsx("button",{onClick:w,className:"flex items-center justify-center w-8 h-8 rounded-full bg-[#ffffff0a] hover:bg-[#ffffff14] text-text-muted hover:text-text-primary transition-colors shrink-0",children:"←"}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[N.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:N.nicknameInput,onChange:C=>N.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&N.handleSaveNickname(),C.key==="Escape"&&N.setEditingNickname(!1)},placeholder:"Machine nickname...",className:"px-2.5 py-1 rounded-md border border-violet-500/30 bg-bg-secondary text-text-primary text-sm font-semibold w-[140px] md:w-[200px]"}),e.jsx("button",{onClick:N.handleSaveNickname,className:"flex items-center justify-center px-3 py-1 rounded bg-green-500/20 text-green-400 hover:bg-green-500/30 text-sm font-medium transition-colors",children:"Save"}),e.jsx("button",{onClick:()=>N.setEditingNickname(!1),className:"flex items-center justify-center px-3 py-1 rounded bg-[#ffffff0a] text-text-muted hover:bg-[#ffffff14] hover:text-text-primary text-sm font-medium transition-colors",children:"Cancel"})]}):e.jsx("h1",{className:"text-xl md:text-2xl font-bold text-text-primary cursor-pointer truncate hover:text-accent-primary transition-colors",onClick:()=>{N.setEditingNickname(!0),N.setNicknameInput(L.machineNickname||"")},title:"Click to set nickname",children:P}),e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-500 shadow-[0_0_8px_rgba(34,197,94,0.6)] shrink-0"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1 items-center mt-1.5 text-xs text-text-secondary opacity-80",children:[e.jsxs("span",{className:"font-mono bg-[#ffffff08] px-1.5 py-0.5 rounded",children:[L.platform," · ",L.arch]}),e.jsxs("span",{children:[L.cpus," cores"]}),(l==null?void 0:l.version)&&e.jsxs("span",{children:["v",l.version]}),L.p2p.available&&e.jsxs("span",{children:["P2P ",L.p2p.state==="connected"?"connected":L.p2p.state]}),L.machineNickname&&e.jsx("span",{className:"text-text-muted opacity-60 shrink-0",children:L.hostname})]})]})]})}),e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden mt-4 gap-6 px-1 border-b border-[#ffffff0a]",children:pe.map(C=>e.jsxs("button",{onClick:()=>m(C.id),className:`pb-3 text-sm font-medium border-b-2 transition-colors flex items-center gap-2 px-1 whitespace-nowrap ${u===C.id?"border-accent-primary text-accent-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] ml-1 ${u===C.id?"bg-accent-primary/20 text-accent-primary":"bg-[#ffffff10] text-text-muted"}`,children:C.count})]},C.id))})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 md:px-8 py-6",children:e.jsx("div",{className:"max-w-7xl mx-auto h-full",children:e.jsxs("div",{className:"h-full",children:[u==="workspace"&&e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 md:gap-10 h-full",children:[e.jsx(Gc,{machineEntry:l,providers:$,recentLaunches:F,onUpgradeDaemon:async()=>{try{await i(s,"daemon_upgrade",{})}catch{}},onOpenLogs:()=>m("logs"),onOpenRecent:V,onOpenWorkspace:C=>{p(C),m("workspace")},onGoTab:m}),e.jsx(Zc,{machine:L,machineId:s,providers:$,ideSessions:_,cliSessions:I,acpSessions:U,actions:N,getIcon:E,initialCategory:h,initialWorkspaceId:D,initialWorkspacePath:X,sendDaemonCommand:i})]}),u==="providers"&&e.jsx(Fc,{machineId:s,providers:$,sendDaemonCommand:i}),u==="overview"&&e.jsx(Oc,{machineId:s,machine:L,ideSessions:_,cliSessions:I,acpSessions:U,actions:N,sendDaemonCommand:i}),u==="logs"&&e.jsx(Vc,{machineId:s,sendDaemonCommand:i})]})})}),N.launchPick&&L&&e.jsx(qc,{machine:L,launchPick:N.launchPick,actions:N}),x&&e.jsx(Xs,{title:x.title,description:x.description,details:x.details,workspaceOptions:x.workspaceOptions,selectedWorkspaceKey:g,onWorkspaceChange:C=>{b.current=C,j(C)},confirmLabel:x.confirmLabel,busy:S,onConfirm:q,onCancel:()=>{y.current=null,k(null)}}),e.jsx(hr,{toasts:o.toasts||[],onDismiss:C=>o.setToasts(J=>J.filter(Z=>Z.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
58
- @keyframes toast-in {
59
- from { opacity: 0; transform: translateX(40px); }
60
- to { opacity: 1; transform: translateX(0); }
61
- }
62
- `})]})}function Qc(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],f=[],u=[];Object.values(c.providers||{}).forEach(h=>{const p={name:h.name||"Unknown",status:h.status||"Stable",details:h.details||"Community Provider"};h.category==="ide"?d.push(p):h.category==="cli"?l.push(p):h.category==="extension"?f.push(p):h.category==="acp"&&u.push(p)});const m=(h,p)=>{const y={Stable:1,Beta:2,WIP:3},x=y[h.status]||99,k=y[p.status]||99;return x!==k?x-k:h.name.localeCompare(p.name)};s({ide:d.sort(m),cli:l.sort(m),ext:f.sort(m),acp:u.sort(m)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(er,{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(zs,{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(sr,{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((d,l)=>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:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(as,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ss,{}),widthClassName:"max-w-5xl",children:e.jsx(Vs,{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(as,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ss,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(He,{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(He,{title:"IDE support",icon:e.jsx(Fe,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(He,{title:"Standalone CLI agents",icon:e.jsx(Us,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(He,{title:"AI extensions",icon:e.jsx(mt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(He,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(mt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class el{constructor(){Be(this,"adapters",new Map);Be(this,"states",new Map);Be(this,"runtimeListeners",new Map);Be(this,"screenshotCallbacks",new Map);Be(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}emitRuntimeSnapshot(s,n,r=0,i=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:i})}emitSessionOutput(s,n,r){!s||typeof n!="string"||!n||this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,...typeof r=="number"?{seq:r}:{},data:n})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const i=this.runtimeListeners.get(s);i&&(i.delete(n),i.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const i=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,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,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(i=>i(n))}}const st=new el;function tl(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const zn=tl(),Un=3e3,sl=3e4;let nt=null,nl=0;const ls=new Map;let dt=null,At=null;function Hn(t,s){if(!(typeof window>"u"))try{if(!(window.localStorage.getItem("adhdev_mobile_debug")==="1"))return;console.debug(`[standalone-status] ${t}`,s)}catch{}}function rl(t){return t==="connected"?"connected":t}async function es(t,s,n){const r=Yi(t,n||{}),i=nt;if(i&&i.readyState===WebSocket.OPEN){const o=`req_${++nl}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{ls.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);ls.set(o,{resolve:f=>{clearTimeout(l),c(f)},reject:f=>{clearTimeout(l),d(f)}}),i.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:r.payload}}))})}throw new Error(`WS command channel unavailable: ${s}`)}class al{constructor(s){Be(this,"daemonId");Be(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(nt==null?void 0:nt.readyState)===WebSocket.OPEN}get connectionState(){return(nt==null?void 0:nt.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return es(this.daemonId,s,n)}async sendInput(s,n){return es(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,dt&&(clearInterval(dt),dt=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await es(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());st.emitScreenshot(this.daemonId,i)}}catch{}};n(),dt=setInterval(n,2e3)}stopScreenshots(s){dt&&(clearInterval(dt),dt=null)}}let Xe=null;function il(t){return(!Xe||Xe.daemonId!==t)&&(Xe=new al(t)),Xe}function ol({children:t}){const s=a.useRef(on()),n=on();s.current=n;const{setUserName:r}=Rt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((h,p)=>{o(h),At==null||At(h,p)},[]),d=a.useRef(null),l=a.useRef(),f=a.useRef(Un),u=a.useRef(!0),m=a.useRef(!1);return a.useEffect(()=>{u.current=!0,m.current=!1;function h(){var x,k;if(!u.current||((x=d.current)==null?void 0:x.readyState)===WebSocket.OPEN||((k=d.current)==null?void 0:k.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${zn}...`);let y;try{y=new WebSocket(zn)}catch(b){console.error("[Standalone WS] Failed to create WebSocket:",b),p();return}d.current=y,y.onopen=()=>{if(!u.current){y.close();return}c("connected"),f.current=Un,console.log("[Standalone WS] Connected")},nt=y,y.onmessage=b=>{var g;try{const j=JSON.parse(b.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const S=ls.get(j.requestId);S&&(ls.delete(j.requestId),j.type==="error"?S.reject(new Error(((g=j.data)==null?void 0:g.message)||"Command failed")):S.resolve(j.data));return}if(j.type==="session_output"){const S=j.sessionId||j.cliId||j.cliType;S&&st.emitSessionOutput(S,typeof j.data=="string"?j.data:"",typeof j.seq=="number"?j.seq:void 0);return}if(j.type==="runtime_snapshot"){st.emitRuntimeSnapshot(j.sessionId,typeof j.text=="string"?j.text:"",typeof j.seq=="number"?j.seq:0,!!j.truncated);return}if(j.type==="status"||j.type==="initial_state"){const S=j.data;if(!S)return;const{injectEntries:v,markLoaded:M}=s.current,w=S.id||"standalone",N=il(w);st.register(w,N),st.setState(w,"connected"),c("connected",w),st.emitStatus(w,S);const $=qi(S,{daemonId:w});Hn("ws_status",{type:j.type,daemonId:w,sessions:(S.sessions||[]).map(R=>({id:R.id,parentId:R.parentId,providerType:R.providerType,kind:R.kind,transport:R.transport,unread:R.unread,inboxBucket:R.inboxBucket,lastSeenAt:R.lastSeenAt,lastUpdated:R.lastUpdated,title:R.title})),recentLaunches:(S.recentLaunches||[]).map(R=>({id:R.id,providerType:R.providerType,kind:R.kind,workspace:R.workspace,lastLaunchedAt:R.lastLaunchedAt}))}),Hn("entries",{daemonId:w,entries:$.filter(R=>R.type!=="adhdev-daemon").map(R=>({id:R.id,type:R.type,unread:R.unread,inboxBucket:R.inboxBucket,lastSeenAt:R.lastSeenAt,lastUpdated:R.lastUpdated,sessionId:R.sessionId}))}),$.length>0&&v($,{authoritativeDaemonIds:[w]}),M(),S.userName&&i.current&&i.current(S.userName)}}catch(j){console.error("[Standalone WS] Parse error:",j)}},y.onclose=()=>{u.current&&(Xe==null||Xe.stopScreenshots(),Xe&&st.setState(Xe.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},y.onerror=b=>{m.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",b)}}function p(){if(!u.current)return;clearTimeout(l.current);const y=f.current;console.log(`[Standalone WS] Reconnecting in ${y}ms...`),l.current=setTimeout(()=>{f.current=Math.min(f.current*1.5,sl),h()},y)}return h(),()=>{u.current=!1,m.current=!0,clearTimeout(l.current),d.current&&(d.current.onerror=null,d.current.onclose=null,d.current.close(),d.current=null,nt=null),Xe&&(Xe.stopScreenshots(),st.unregister(Xe.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function cl({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(At=(c,d)=>{n(c),d&&i(d)},()=>{At=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d=rl(s),l={};return r&&(l[r]=d),l.standalone=d,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(La,{connectionOverrides:o,children:e.jsx(ol,{children:t})})}const ll=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Jn,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ts,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(ds,{}),label:"Settings"}];function dl({children:t}){const s=kt(),n=Bs(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const m=!u;try{localStorage.setItem("sidebar-collapsed",m?"1":"0")}catch{}return m})},f=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" 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"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"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:ll.map(u=>e.jsxs("div",{className:f(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.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(ss,{})}),!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${n.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(Qn,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.8.6"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,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 ul=[{icon:e.jsx(ts,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(rt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(tr,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Fe,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(mt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(ss,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],pl=[{icon:e.jsx(rr,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Jn,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(us,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Oa,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ka,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(er,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],xl=[{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 ml(){return e.jsxs(as,{icon:e.jsx(Qn,{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.6"]}),children:[e.jsx(He,{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(He,{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:ul.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(He,{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:vr.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:wr.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:jr.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(He,{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:pl.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(He,{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:xl.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(Vs,{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(Ja,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function fl(){const{ides:t}=Rt(),s=t.find(m=>m.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=ct(),{userName:i}=Rt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=m=>{const h=m.target.value.trim();s!=null&&s.id&&h!==i&&r(s.id,"set_user_name",{userName:h}).catch(console.error)},[l,f]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=m=>{f(m);try{localStorage.setItem("adhdev_sound",m?"1":"0")}catch{}};return e.jsxs(as,{icon:e.jsx(ds,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(uo,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(He,{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.6"]}),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(He,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.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:n.map(m=>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 ${m.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:m.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:m.type})]},m.type))})}),e.jsx(He,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(go,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(He,{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(wo,{})]}),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(To,{})]}),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(Ro,{})]})]})}),e.jsx(He,{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(bo,{}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Za,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(He,{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(Wa,{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:m=>c(m.target.value),onBlur:d,onKeyDown:m=>{m.key==="Enter"&&m.currentTarget.blur()}})]})})})]})}ho();Mo();const hl=Xn({baseUrl:""});function Fn(){const{ides:t,initialLoaded:s}=Rt();if(!s)return e.jsx("div",{className:"p-10 text-center text-text-muted",children:"⏳ Loading machine..."});const n=t.find(r=>r.daemonMode||r.type==="adhdev-daemon");return n?e.jsx(Ms,{to:`/machines/${n.id}`,replace:!0}):e.jsx(Ms,{to:"/dashboard",replace:!0})}function bl(){return e.jsx(Ia,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Ea,{client:hl,children:e.jsx(cl,{children:e.jsx(Ba,{value:{sendCommand:es,sendData:()=>!1},children:e.jsx(dl,{children:e.jsxs(Ma,{children:[e.jsx(at,{path:"/dashboard",element:e.jsx(Kc,{})}),e.jsx(at,{path:"/machine",element:e.jsx(Fn,{})}),e.jsx(at,{path:"/machines/:id",element:e.jsx(Jc,{})}),e.jsx(at,{path:"/machines",element:e.jsx(Fn,{})}),e.jsx(at,{path:"/capabilities",element:e.jsx(Qc,{})}),e.jsx(at,{path:"/about",element:e.jsx(ml,{})}),e.jsx(at,{path:"/settings",element:e.jsx(fl,{})}),e.jsx(at,{path:"*",element:e.jsx(Ms,{to:"/dashboard",replace:!0})})]})})})})})})}Ei({connectionManager:st});_a(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(bl,{})}));