@adhdev/daemon-standalone 0.6.66 → 0.6.67

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,12 +1,12 @@
1
- var Es=Object.defineProperty;var As=(t,s,o)=>s in t?Es(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o;var Me=(t,s,o)=>As(t,typeof s!="symbol"?s+"":s,o);import{r as n,j as e,M as Ft,a as Ht,b as $s,c as _s,u as mt,t as Rs,d as Ps,e as Ls,f as cs,R as Ds,g as ls,h as Bs,B as Ws,i as Os,k as He,N as ft,l as Ks}from"./vendor-Df99lqBA.js";import{D as Fs,o as Hs,L as Us}from"./terminal-Dm9LBRva.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"]'))a(i);new MutationObserver(i=>{for(const c of i)if(c.type==="childList")for(const r of c.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&a(r)}).observe(document,{childList:!0,subtree:!0});function o(i){const c={};return i.integrity&&(c.integrity=i.integrity),i.referrerPolicy&&(c.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?c.credentials="include":i.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function a(i){if(i.ep)return;i.ep=!0;const c=o(i);fetch(i.href,c)}})();const ds=n.createContext({ides:[],updateIdeChats:()=>{},screenshotMap:{},setScreenshotMap:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),us=n.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Ut(t){var o,a;let s=0;return"activeChat"in t&&(s+=4),(o=t.agentStreams)!=null&&o.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(a=t.agents)!=null&&a.length&&(s+=1),s}function zs(t,s){var r,x,u,h,d,l,j;const o=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:o}));const a=new Map;for(const f of s)a.set(f.id,f);for(const f of t){const p=a.get(f.id);if(!p){a.set(f.id,{...f,_lastUpdate:o});continue}const A=Ut(f),$=Ut(p);if(A>$){const w=(r=f.chats)!=null&&r.length?f.chats:p.chats;a.set(f.id,{...p,...f,chats:w,_lastUpdate:o})}else if(A<$){const w={};f.status&&f.status!==p.status&&(w.status=f.status),f.cdpConnected!==void 0&&(w.cdpConnected=f.cdpConnected),(x=f.chats)!=null&&x.length&&!((u=p.chats)!=null&&u.length)&&(w.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==p.machineNickname&&(w.machineNickname=f.machineNickname),Object.keys(w).length>0&&a.set(f.id,{...p,...w,_lastUpdate:p._lastUpdate})}else{const w=f.timestamp||o,S=p._lastUpdate||p.timestamp||0;if(w>=S){const O=(h=f.chats)!=null&&h.length?f.chats:p.chats;a.set(f.id,{...p,...f,chats:O,_lastUpdate:o})}else(d=f.chats)!=null&&d.length&&!((l=p.chats)!=null&&l.length)&&a.set(f.id,{...p,chats:f.chats})}}const i=new Set(t.map(f=>f.id)),c=new Set;for(const f of t){const p=f.daemonId||((j=f.id)==null?void 0:j.split(":")[0]);p&&c.add(p)}for(const[f,p]of a){const A=p.daemonId||f.split(":")[0];if(!c.has(A))continue;const $=o-(p._lastUpdate||p.timestamp||0);(f.includes(":cli:")&&!i.has(f)&&$>1e4||f.includes(":acp:")&&!i.has(f)&&$>1e4||f.includes(":ide:")&&!i.has(f)&&$>3e4)&&a.delete(f)}for(const[f,p]of a)o-(p._lastUpdate||p.timestamp||0)>3e5&&p.status!=="online"&&a.delete(f);return Array.from(a.values())}function Ys({children:t,connectionOverrides:s}){const[o,a]=n.useState([]),[i,c]=n.useState({}),[r,x]=n.useState(!1),[u,h]=n.useState([]),[d,l]=n.useState(void 0),j=n.useCallback((A,$)=>{a(w=>w.map(S=>S.id===A?{...S,chats:$}:S))},[]),f={injectEntries:A=>{a($=>$.length===0?A:zs(A,$))},markLoaded:()=>x(!0),getIdes:()=>o},p=s;return e.jsx(us.Provider,{value:f,children:e.jsx(ds.Provider,{value:{ides:o,updateIdeChats:j,screenshotMap:i,setScreenshotMap:c,initialLoaded:r,toasts:u,setToasts:h,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:d,setUserName:l},children:t})})}function dt(){return n.useContext(ds)}function zt(){return n.useContext(us)}function Xs(t){const{baseUrl:s,getToken:o,onUnauthorized:a}=t;async function i(c,r={}){const x={"Content-Type":"application/json",...r.headers||{}},u=o==null?void 0:o();u&&(x.Authorization=`Bearer ${u}`);const h=c.startsWith("http")?c:`${s}${c.startsWith("/")?"":"/"}${c}`,d=await fetch(h,{...r,headers:x});if(d.status===401)throw a==null||a(),new Error("Unauthorized");if(!d.ok){const l=await d.json().catch(()=>({error:d.statusText}));throw new Error(l.error||`API Error: ${d.status}`)}return d.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:c=>i(`/api/v1/daemons/${c}/status`),sendCommand:(c,r,x={})=>i(`/api/v1/daemons/${c}/command`,{method:"POST",body:JSON.stringify({type:r,payload:x})}),execTerminal:(c,r,x)=>i(`/api/v1/daemons/${c}/terminal`,{method:"POST",body:JSON.stringify({command:r,name:x})}),sendAgentMessage:(c,r,x)=>i(`/api/v1/shortcuts/${c}/chat`,{method:"POST",body:JSON.stringify({agentType:r,message:x})}),getAgentStatus:c=>i(`/api/v1/shortcuts/${c}/status`),approveAgent:(c,r,x)=>i(`/api/v1/shortcuts/${c}/approve`,{method:"POST",body:JSON.stringify({agentType:r,action:x?"approve":"reject"})}),request:i}}const Vs=Xs({baseUrl:"http://localhost:3847"});n.createContext(Vs);const qs={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},xs=n.createContext(qs);function Gs({value:t,children:s}){return e.jsx(xs.Provider,{value:t,children:s})}function Xe(){return n.useContext(xs)}const ke={size:18};function Js({size:t=ke.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 Zs({size:t=ke.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 ms({size:t=ke.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 Qs({size:t=ke.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 ps({size:t=ke.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 en({size:t=ke.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 tn({size:t=ke.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 jt({size:t=ke.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 nt({size:t=ke.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 sn({size:t=ke.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 nn({size:t=ke.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 _t({size:t=ke.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 rn({size:t=ke.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 Ot({size:t=ke.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 wt({size:t=ke.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 an({size:t=ke.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 hs({size:t=ke.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 on({size:t=ke.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 Kt({size:t=ke.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 cn({size:t=ke.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 fs({size:t=ke.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 ln({size:t=ke.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 dn({size:t=ke.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 un(t){const o=t.split(`
1
+ var As=Object.defineProperty;var $s=(t,s,o)=>s in t?As(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o;var Me=(t,s,o)=>$s(t,typeof s!="symbol"?s+"":s,o);import{r as n,j as e,M as Ht,a as zt,b as _s,c as Rs,u as pt,t as Ps,d as Ls,e as Ds,f as ls,R as Bs,g as ds,h as Ws,B as Os,i as Ks,k as He,N as gt,l as Fs}from"./vendor-Df99lqBA.js";import{D as Hs,o as zs,L as Us}from"./terminal-Dm9LBRva.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"]'))a(i);new MutationObserver(i=>{for(const c of i)if(c.type==="childList")for(const r of c.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&a(r)}).observe(document,{childList:!0,subtree:!0});function o(i){const c={};return i.integrity&&(c.integrity=i.integrity),i.referrerPolicy&&(c.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?c.credentials="include":i.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function a(i){if(i.ep)return;i.ep=!0;const c=o(i);fetch(i.href,c)}})();const us=n.createContext({ides:[],updateIdeChats:()=>{},screenshotMap:{},setScreenshotMap:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),xs=n.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Ut(t){var o,a;let s=0;return"activeChat"in t&&(s+=4),(o=t.agentStreams)!=null&&o.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(a=t.agents)!=null&&a.length&&(s+=1),s}function Ys(t,s){var r,x,u,h,d,l,v;const o=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:o}));const a=new Map;for(const f of s)a.set(f.id,f);for(const f of t){const p=a.get(f.id);if(!p){a.set(f.id,{...f,_lastUpdate:o});continue}const A=Ut(f),$=Ut(p);if(A>$){const w=(r=f.chats)!=null&&r.length?f.chats:p.chats;a.set(f.id,{...p,...f,chats:w,_lastUpdate:o})}else if(A<$){const w={};f.status&&f.status!==p.status&&(w.status=f.status),f.cdpConnected!==void 0&&(w.cdpConnected=f.cdpConnected),(x=f.chats)!=null&&x.length&&!((u=p.chats)!=null&&u.length)&&(w.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==p.machineNickname&&(w.machineNickname=f.machineNickname),Object.keys(w).length>0&&a.set(f.id,{...p,...w,_lastUpdate:p._lastUpdate})}else{const w=f.timestamp||o,S=p._lastUpdate||p.timestamp||0;if(w>=S){const O=(h=f.chats)!=null&&h.length?f.chats:p.chats;a.set(f.id,{...p,...f,chats:O,_lastUpdate:o})}else(d=f.chats)!=null&&d.length&&!((l=p.chats)!=null&&l.length)&&a.set(f.id,{...p,chats:f.chats})}}const i=new Set(t.map(f=>f.id)),c=new Set;for(const f of t){const p=f.daemonId||((v=f.id)==null?void 0:v.split(":")[0]);p&&c.add(p)}for(const[f,p]of a){const A=p.daemonId||f.split(":")[0];if(!c.has(A))continue;const $=o-(p._lastUpdate||p.timestamp||0);(f.includes(":cli:")&&!i.has(f)&&$>1e4||f.includes(":acp:")&&!i.has(f)&&$>1e4||f.includes(":ide:")&&!i.has(f)&&$>3e4)&&a.delete(f)}for(const[f,p]of a)o-(p._lastUpdate||p.timestamp||0)>3e5&&p.status!=="online"&&a.delete(f);return Array.from(a.values())}function Vs({children:t,connectionOverrides:s}){const[o,a]=n.useState([]),[i,c]=n.useState({}),[r,x]=n.useState(!1),[u,h]=n.useState([]),[d,l]=n.useState(void 0),v=n.useCallback((A,$)=>{a(w=>w.map(S=>S.id===A?{...S,chats:$}:S))},[]),f={injectEntries:A=>{a($=>$.length===0?A:Ys(A,$))},markLoaded:()=>x(!0),getIdes:()=>o},p=s;return e.jsx(xs.Provider,{value:f,children:e.jsx(us.Provider,{value:{ides:o,updateIdeChats:v,screenshotMap:i,setScreenshotMap:c,initialLoaded:r,toasts:u,setToasts:h,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:d,setUserName:l},children:t})})}function dt(){return n.useContext(us)}function Yt(){return n.useContext(xs)}function Xs(t){const{baseUrl:s,getToken:o,onUnauthorized:a}=t;async function i(c,r={}){const x={"Content-Type":"application/json",...r.headers||{}},u=o==null?void 0:o();u&&(x.Authorization=`Bearer ${u}`);const h=c.startsWith("http")?c:`${s}${c.startsWith("/")?"":"/"}${c}`,d=await fetch(h,{...r,headers:x});if(d.status===401)throw a==null||a(),new Error("Unauthorized");if(!d.ok){const l=await d.json().catch(()=>({error:d.statusText}));throw new Error(l.error||`API Error: ${d.status}`)}return d.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:c=>i(`/api/v1/daemons/${c}/status`),sendCommand:(c,r,x={})=>i(`/api/v1/daemons/${c}/command`,{method:"POST",body:JSON.stringify({type:r,payload:x})}),execTerminal:(c,r,x)=>i(`/api/v1/daemons/${c}/terminal`,{method:"POST",body:JSON.stringify({command:r,name:x})}),sendAgentMessage:(c,r,x)=>i(`/api/v1/shortcuts/${c}/chat`,{method:"POST",body:JSON.stringify({agentType:r,message:x})}),getAgentStatus:c=>i(`/api/v1/shortcuts/${c}/status`),approveAgent:(c,r,x)=>i(`/api/v1/shortcuts/${c}/approve`,{method:"POST",body:JSON.stringify({agentType:r,action:x?"approve":"reject"})}),request:i}}const qs=Xs({baseUrl:"http://localhost:3847"});n.createContext(qs);const Gs={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ms=n.createContext(Gs);function Js({value:t,children:s}){return e.jsx(ms.Provider,{value:t,children:s})}function Ve(){return n.useContext(ms)}const Ne={size:18};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("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 Qs({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 en({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 ps({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 tn({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 Ot({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 sn({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 nn({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 wt({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 Qe({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 rn({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 an({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 _t({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 hs({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 Kt({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 ut({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 on({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 fs({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 cn({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 Ft({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 ln({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 gs({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 dn({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 un({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 xn({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 mn({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 pn({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 hn({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 fn(t){const o=t.split(`
2
2
  `).map(x=>{if(!x.includes("\r"))return x;const u=x.split("\r").map(l=>l.trim()).filter(Boolean);if(u.length===0)return"";const h=u.filter(l=>l.startsWith("⏺"));if(h.length>0)return h[h.length-1];const d=u.filter(l=>!(/^[❯›>]\s*$/.test(l)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(l)&&l.length<40||/^[╭╰│├╮╯─═]+$/.test(l)));return d.length>0?d[d.length-1]:u[u.length-1]}).join(`
3
3
  `).split(`
4
4
  `),a={},i=[];let c=!1;for(const x of o){const u=x.trim();if(u===""){c=!1,i.push("");continue}if(/^❯\s*$/.test(u)||/^>\s*$/.test(u)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(u)||/^◐\s/.test(u)||/\/effort/.test(u)||/^⎿\s+(Tip|Note|Hint):/.test(u)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(u)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(u)||/Brewing[…\.]{0,3}\s*\d*$/i.test(u)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(u)||/^Auto-updating/i.test(u))continue;if(/^[⏺●·⏵]/.test(x)){const d=x.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)a[d[1]]=(a[d[1]]||0)+1;else{const l=x.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);l&&(a[l]=(a[l]||0)+1)}c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(x)||/^[╭╰│├╮╯─]+/.test(u)||/^\s+[⊙✓✗○◎▸►✦]/.test(x)||c&&/^\s{2,}/.test(x))continue;c=!1;const h=x.replace(/^❯\s+/,"");i.push(h)}const r=i.join(`
5
5
  `).replace(/\n{3,}/g,`
6
6
 
7
- `).trim();return{toolCounts:a,textContent:r,hasTools:Object.keys(a).length>0}}function St(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const xn=n.forwardRef(function({messages:s,actionLogs:o,agentName:a="Agent",userName:i,isCliMode:c=!1,isWorking:r=!1,contextKey:x="",receivedAtMap:u={},emptyState:h,onLoadMore:d,isLoadingMore:l,hasMoreHistory:j,loadError:f},p){var le;const A=n.useRef(null),$=n.useRef(null),w=n.useRef(0),S=n.useRef(""),O=n.useRef(!1),[F,R]=n.useState(new Set),[T,D]=n.useState(new Set),I=n.useRef(!1),N=()=>{const V=A.current;return V?V.scrollHeight-V.scrollTop-V.clientHeight<200:!0},ne=s.length>0?`${s.length}:${(((le=s[s.length-1])==null?void 0:le.content)||"").length}`:"0:0";n.useEffect(()=>{var ae,se;const V=!O.current,J=S.current!==x;if(S.current=x,V||J){O.current=!0,I.current=!1;const ie=()=>{var ce;(ce=$.current)==null||ce.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(ie)),setTimeout(ie,100),setTimeout(ie,300),w.current=s.length;return}s.length>w.current?I.current||(ae=$.current)==null||ae.scrollIntoView({behavior:"instant"}):N()&&!I.current&&((se=$.current)==null||se.scrollIntoView({behavior:"instant"})),w.current=s.length},[ne,x,r]),n.useImperativeHandle(p,()=>({scrollToBottom:(V="smooth")=>{var J;(J=$.current)==null||J.scrollIntoView({behavior:V})}})),n.useEffect(()=>{const V=A.current;if(!V)return;let J;const K=()=>{clearTimeout(J),J=setTimeout(()=>{I.current=!N()},50)};return V.addEventListener("scroll",K,{passive:!0}),()=>{V.removeEventListener("scroll",K),clearTimeout(J)}},[]);const _=n.useRef(0),X=n.useRef(!1);n.useEffect(()=>{const V=A.current;if(!V||!X.current||_.current===0)return;const J=V.scrollHeight-_.current;J>0&&(V.scrollTop=J),_.current=0,X.current=!1},[s.length]);const Y=()=>{const V=A.current;V&&(_.current=V.scrollHeight),X.current=!0,d==null||d()},y=(()=>{const V=s.map((se,ie)=>({type:"message",data:se,index:ie,ts:se.receivedAt||u[se.id??`i-${ie}`]||0}));if(!o||o.length===0)return V;const J=[...o].sort((se,ie)=>se.timestamp-ie.timestamp).map((se,ie)=>({type:"action",data:se,index:ie,ts:se.timestamp})),K=[];let ae=0;for(const se of V){for(;ae<J.length&&se.ts>0&&J[ae].ts<se.ts;)K.push(J[ae++]);K.push(se)}for(;ae<J.length;)K.push(J[ae++]);return K})(),Z=700;return e.jsxs("div",{ref:A,"data-chat-scroll":!0,className:"chat-container",children:[l&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),j&&!l&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:Y,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${f?"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:f?`↻ ${f}`:"↑ Load older messages"})}),y.length===0&&!j&&(h||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),y.map(V=>{var ve;if(V.type==="action"){const oe=V.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Ft,{remarkPlugins:[Ht],children:oe.text}),e.jsx("span",{className:"action-time",children:St(oe.timestamp)})]},`action-${V.index}`)}const J=V.data,K=V.index,ae=(J.role||"").toLowerCase(),se=ae==="user"||ae==="human",ie=J.kind||(ae==="tool"?"tool":"standard"),ce=J.receivedAt||u[J.id??`i-${K}`],P=`${x}-${K}`,v=F.has(P),B=T.has(P),g=typeof J.content=="string"?J.content:(J.content||[]).map(oe=>oe.text||"").join(`
8
- `);if(ie==="thought"){const oe=((ve=J.meta)==null?void 0:ve.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(ln,{size:13}),e.jsx("span",{children:oe})]}),e.jsx("div",{className:"chat-msg-body",children:g})]},`msg-${K}`)}if(ie==="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:g.split(`
9
- `)[0].slice(0,80)})]},`msg-${K}`);if(ie==="terminal"){const oe=J.meta||{},he=oe.isRunning?"⏳":"✅",L=oe.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:he}),e.jsx("span",{children:L})]}),e.jsx("pre",{className:"chat-msg-body",children:g})]},`msg-${K}`)}if(ie==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:g.slice(0,100)},`msg-${K}`);const U=!se&&c?un(g):null,z=U?U.textContent:g,de=U?Object.entries(U.toolCounts):[],we=c&&!se&&!v&&z.length>Z,je=v?g:we&&!B?z.slice(0,Z):z;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${se?"self-end":"self-start"}`,children:[de.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[de.map(([oe,he])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",oe,he>1?` ×${he}`:""]},oe)),(U==null?void 0:U.hasTools)&&e.jsx("button",{onClick:()=>R(oe=>{const he=new Set(oe);return v?he.delete(P):he.add(P),he}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:v?"Collapse":"Original"}),!z&&ce!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:St(ce)})]}),(z||se)&&e.jsxs("div",{className:`chat-bubble ${se?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${z?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:se?i||"You":a}),ce!=null&&e.jsx("span",{className:"chat-time",children:St(ce)})]}),z&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Ft,{remarkPlugins:[Ht,$s,_s],children:je})}),we&&e.jsx("button",{onClick:()=>D(oe=>{const he=new Set(oe);return B?he.delete(P):he.add(P),he}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:B?"Collapse ↑":`Show more (${Math.round(z.length/100)*100} chars) ↓`})]})]},`msg-${K}`)}),r&&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 working..."})]})}),e.jsx("div",{className:"min-h-10",ref:$})]})}),Yt={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},gs=n.forwardRef(({onInput:t,onResize:s,fontSize:o=13},a)=>{const i=n.useRef(null),c=n.useRef(null),r=n.useRef(null),[x,u]=n.useState(!1);return n.useImperativeHandle(a,()=>({write:h=>{var d;(d=c.current)==null||d.write(h)},clear:()=>{var h;(h=c.current)==null||h.clear()},fit:()=>{var h;try{(h=r.current)==null||h.fit(),c.current&&(s==null||s(c.current.cols,c.current.rows))}catch{}},bumpResize:()=>{var h;try{(h=r.current)==null||h.fit();const d=c.current;if(!d)return;const l=d.cols,j=d.rows;s==null||s(l+5,j),setTimeout(()=>{s==null||s(l,j)},100)}catch{}}})),n.useEffect(()=>{if(!i.current)return;const h=new Fs({cursorBlink:!0,cursorStyle:"bar",fontSize:o,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:Yt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),d=new Hs,l=new Us;h.loadAddon(d),h.loadAddon(l),h.open(i.current),requestAnimationFrame(()=>{d.fit(),s==null||s(h.cols,h.rows),u(!0)});const j=h.onData(p=>{t(p)}),f=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{d.fit(),s==null||s(h.cols,h.rows)}catch{}})});return f.observe(i.current),c.current=h,r.current=d,()=>{j.dispose(),f.disconnect(),h.dispose(),c.current=null,r.current=null}},[o]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:Yt.background,opacity:x?1:0}})});gs.displayName="CliTerminal";function pt({label:t,value:s,sub:o,icon:a}){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:a}),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}),o&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:o})]})}function Xt({value:t,max:s,label:o,color:a="#8b5cf6",detail:i,compact:c=!1}){const r=s>0?Math.min(Math.round(t/s*100),100):0,x=r>85?"#ef4444":r>60?"#f59e0b":a;return c?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:o}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[r,"%"]})]}),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:`${r}%`,background:x}})})]}):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:o}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[r,"%"]})]}),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:`${r}%`,background:`linear-gradient(90deg, ${x}, ${x}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function mn({onAction:t,addLog:s,connState:o,connScreenshot:a,screenshotUsage:i,transportType:c}){const r=n.useRef(null),x=n.useRef(null),u=n.useRef(null),[h,d]=n.useState(null),[l,j]=n.useState(""),[,f]=n.useState(!1),[p,A]=n.useState([]),$=n.useRef(0),[w,S]=n.useState(!1),[O,F]=n.useState(!1),R=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[T,D]=n.useState(R?"mouse":"touch"),[I,N]=n.useState(1),ne=n.useRef(!1),[_,X]=n.useState(1),[Y,y]=n.useState(0),[Z,le]=n.useState(0),V=n.useRef(0),J=n.useRef(t),K=n.useRef(null),ae=n.useRef(null),se=n.useRef(!1),ie=n.useRef(null),ce=n.useRef(0),P=n.useRef(null),v=n.useRef(1),B=n.useRef({x:0,y:0}),g=n.useRef(!1),U=n.useRef(_),z=n.useRef(Y),de=n.useRef(Z),we=n.useRef(T);n.useEffect(()=>{U.current=_},[_]),n.useEffect(()=>{z.current=Y},[Y]),n.useEffect(()=>{de.current=Z},[Z]),n.useEffect(()=>{J.current=t},[t]),n.useEffect(()=>{we.current=T},[T]),n.useEffect(()=>{var W;(W=r.current)==null||W.focus()},[]);const je=o==="connected",ve=a,oe=je?"Connected. Waiting for first frame...":o==="connecting"?"Connecting to Host...":"Reconnecting to Host...",he=je?"The remote stream is warming up":"Waiting for the remote stream to catch up";n.useEffect(()=>{if(!R||ne.current||!ve)return;const W=u.current,re=x.current;if(!W||!re)return;const ee=()=>{const xe=re.clientWidth,ye=re.clientHeight,pe=W.naturalWidth,C=W.naturalHeight;if(!pe||!C||!xe||!ye)return;const E=Math.min(xe/pe,ye/C),q=Math.max(xe/pe,ye/C)/E;q>1.01&&(N(q),X(q),U.current=q),ne.current=!0};W.complete&&W.naturalWidth?ee():W.addEventListener("load",ee,{once:!0})},[ve,R]);const L=.5;n.useEffect(()=>{_<=L&&(y(0),le(0))},[_,L]);const me=(W,re,ee)=>{if(ee<=L)return{x:0,y:0};const xe=(ee-1)/(2*ee)*100,ye=(ee-1)/(2*ee)*100;return{x:Math.max(-xe,Math.min(xe,W)),y:Math.max(-ye,Math.min(ye,re))}},ge=(W,re)=>{if(!u.current)return null;const ee=u.current.getBoundingClientRect();return!ee.width||!ee.height?null:{nx:Math.max(0,Math.min(1,(W-ee.left)/ee.width)),ny:Math.max(0,Math.min(1,(re-ee.top)/ee.height))}},fe=(W,re,ee)=>{const xe=x.current;if(!xe)return;const ye=xe.getBoundingClientRect(),pe=++$.current;A(C=>[...C,{id:pe,x:W-ye.left,y:re-ye.top,type:ee}]),setTimeout(()=>A(C=>C.filter(E=>E.id!==pe)),600)},Ce=(W,re,ee)=>{const xe=u.current,ye=x.current;if(!xe||!ye)return;const pe=xe.getBoundingClientRect(),C=ye.getBoundingClientRect(),E=xe.naturalWidth||pe.width,G=xe.naturalHeight||pe.height,q=E/G,Q=pe.width/pe.height;let b,m,k,M;q>Q?(b=pe.width,m=pe.width/q,k=0,M=(pe.height-m)/2):(m=pe.height,b=pe.height*q,k=(pe.width-b)/2,M=0);const H=pe.left-C.left+k+b*W,te=pe.top-C.top+M+m*re,ue=++$.current;A(be=>[...be,{id:ue,x:H,y:te,type:ee}]),setTimeout(()=>A(be=>be.filter(Ne=>Ne.id!==ue)),600)},$e=async W=>{var ee;const re=ge(W.clientX,W.clientY);if(re){d(`Click: ${Math.round(re.nx*100)}%, ${Math.round(re.ny*100)}%`),fe(W.clientX,W.clientY,"left"),(ee=r.current)==null||ee.focus();try{const xe=await t("input_click",{nx:re.nx,ny:re.ny});xe!=null&&xe.success||s(`❌ Click failed: ${xe==null?void 0:xe.error}`)}catch(xe){s(`❌ Click error: ${xe.message||xe}`)}}},Se=async(W,re,ee,xe=0)=>{try{await t("input_key",{type:ee?"char":"keyDown",key:W,code:re,text:ee?W:void 0,unmodifiedText:ee?W:void 0,modifiers:xe})}catch(ye){s(`❌ Key error: ${ye.message||ye}`)}},Ae=async W=>{if(W.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(W.key)&&W.preventDefault();let ee=0;W.altKey&&(ee|=1),W.ctrlKey&&(ee|=2),W.metaKey&&(ee|=4),W.shiftKey&&(ee|=8),d(`Key: ${W.key}`),await Se(W.key,W.code,W.key.length===1,ee)},Oe=async W=>{if(W.key==="Enter"){if(W.nativeEvent.isComposing)return;if(l){const re=l;j(""),d(`IME Sent: ${re}`);try{const ee=await t("input_type",{text:re});ee!=null&&ee.success||s(`❌ IME error: ${ee==null?void 0:ee.error}`)}catch(ee){s(`❌ IME error: ${ee.message}`)}}else d("Key: Enter"),await Se("Enter","Enter",!1)}};n.useEffect(()=>{const W=r.current;if(!W)return;const re=ee=>{var xe;if((xe=u.current)!=null&&xe.contains(ee.target)){ee.preventDefault();const ye=Date.now();if(ye-V.current<40)return;V.current=ye;const pe=ge(ee.clientX,ee.clientY);if(!pe)return;d(`Scroll: ${Math.round(ee.deltaY)}`),t("input_wheel",{nx:pe.nx,ny:pe.ny,deltaX:Math.round(ee.deltaX),deltaY:Math.round(ee.deltaY)}).catch(()=>{})}};return W.addEventListener("wheel",re,{passive:!1}),()=>W.removeEventListener("wheel",re)},[t]);const[_e,Re]=n.useState(null),Ee=n.useRef(null);return n.useEffect(()=>{if(T==="mouse"&&!Ee.current){const W={nx:.5,ny:.5};Ee.current=W,Re(W)}},[T]),n.useEffect(()=>{const W=r.current;if(!W)return;const re=E=>{if(!u.current)return null;const G=u.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(E.clientX-G.left)/G.width)),ny:Math.max(0,Math.min(1,(E.clientY-G.top)/G.height))}},ee=(E,G)=>{if(!u.current)return{dnx:0,dny:0};const q=u.current,Q=q.getBoundingClientRect(),b=q.naturalWidth||Q.width,m=q.naturalHeight||Q.height,k=b/m,M=Q.width/Q.height;let H,te;return k>M?(H=Q.width,te=Q.width/k):(te=Q.height,H=Q.height*k),{dnx:E/H,dny:G/te}},xe=(E,G,q)=>{if(q<=1.05)return;const Q=-(E-.5)*100,b=-(G-.5)*100,m=me(Q,b,q);(Math.abs(m.x-z.current)>.1||Math.abs(m.y-de.current)>.1)&&(y(m.x),le(m.y),z.current=m.x,de.current=m.y)},ye=E=>{const G=x.current;if(G&&E.target instanceof Node&&G.contains(E.target))E.preventDefault();else return;if(E.touches.length===1){const q=E.touches[0];K.current={x:q.clientX,y:q.clientY,time:Date.now()},ae.current={x:q.clientX,y:q.clientY},g.current||(se.current=!1),ie.current=setTimeout(()=>{if(!se.current&&!g.current)if(se.current=!0,we.current==="mouse"){const Q=Ee.current||{nx:.5,ny:.5};d("Right Click"),Ce(Q.nx,Q.ny,"right"),J.current("input_click",{...Q,button:"right"}).catch(()=>{})}else{const Q=re(q);Q&&(d("Right Click"),Ce(Q.nx,Q.ny,"right"),J.current("input_click",{...Q,button:"right"}).catch(()=>{}))}},500)}else if(E.touches.length===2){clearTimeout(ie.current),se.current=!0,g.current=!0;const q=E.touches[1].clientX-E.touches[0].clientX,Q=E.touches[1].clientY-E.touches[0].clientY;P.current=Math.sqrt(q*q+Q*Q),v.current=U.current,B.current={x:(E.touches[0].clientX+E.touches[1].clientX)/2,y:(E.touches[0].clientY+E.touches[1].clientY)/2}}},pe=E=>{const G=x.current;if(G&&E.target instanceof Node&&G.contains(E.target)&&E.preventDefault(),E.touches.length===1&&ae.current){const q=E.touches[0],Q=q.clientX-ae.current.x,b=q.clientY-ae.current.y;if(!se.current&&K.current){const m=q.clientX-K.current.x,k=q.clientY-K.current.y;Math.sqrt(m*m+k*k)>8&&(se.current=!0,clearTimeout(ie.current))}if(se.current)if(we.current==="mouse"){const m=ee(Q,b),k=Ee.current||{nx:.5,ny:.5},M=Math.max(0,Math.min(1,k.nx+m.dnx)),H=Math.max(0,Math.min(1,k.ny+m.dny));Ee.current={nx:M,ny:H},Re({nx:M,ny:H}),d(`Cursor: ${Math.round(M*100)}%, ${Math.round(H*100)}%`),xe(M,H,U.current);const te=Date.now();te-V.current>=30&&(V.current=te,J.current("input_mouseMoved",{nx:M,ny:H}).catch(()=>{}))}else if(U.current>1){const m=x.current;if(m){const k=m.clientWidth,M=m.clientHeight,H=z.current+Q/k*100,te=de.current+b/M*100,ue=me(H,te,U.current);y(ue.x),le(ue.y),z.current=ue.x,de.current=ue.y}}else{const m=re(q);if(m){const k=Date.now();k-V.current>=40&&(V.current=k,d("Scroll"),J.current("input_wheel",{nx:m.nx,ny:m.ny,deltaX:Math.round(-Q*2.5),deltaY:Math.round(-b*2.5)}).catch(()=>{}))}}ae.current={x:q.clientX,y:q.clientY}}else if(E.touches.length===2&&P.current!==null){const q=E.touches[1].clientX-E.touches[0].clientX,Q=E.touches[1].clientY-E.touches[0].clientY,m=Math.sqrt(q*q+Q*Q)/P.current,k=(E.touches[0].clientX+E.touches[1].clientX)/2,M=(E.touches[0].clientY+E.touches[1].clientY)/2,H=k-B.current.x,te=M-B.current.y,ue=Math.abs(m-1)>.03;if(we.current==="mouse"){if(ue){const be=Math.max(L,Math.min(5,v.current*m));X(be),U.current=be}else if(Math.abs(H)>2||Math.abs(te)>2){const be=Ee.current||{nx:.5,ny:.5},Ne=Date.now();Ne-V.current>=30&&(V.current=Ne,d("Scroll"),J.current("input_wheel",{nx:be.nx,ny:be.ny,deltaX:Math.round(-H*3),deltaY:Math.round(-te*3)}).catch(()=>{}))}}else{const be=Math.max(L,Math.min(5,v.current*m));X(be),U.current=be;const Ne=x.current;if(Ne&&be>1){const Ke=Ne.clientWidth,Fe=Ne.clientHeight,Ve=z.current+H/Ke*100,rt=de.current+te/Fe*100,Qe=me(Ve,rt,be);y(Qe.x),le(Qe.y),z.current=Qe.x,de.current=Qe.y}}B.current={x:k,y:M}}},C=E=>{var G;if(clearTimeout(ie.current),P.current=null,E.touches.length===1&&g.current){const q=E.touches[0];K.current={x:q.clientX,y:q.clientY,time:Date.now()},ae.current={x:q.clientX,y:q.clientY},se.current=!0;return}if(E.touches.length===0){if(g.current){g.current=!1,se.current=!1;return}if(E.changedTouches.length===1&&!se.current){const q=E.changedTouches[0],Q=Date.now(),b=Q-(((G=K.current)==null?void 0:G.time)||0);if(b<60||b>400){se.current=!1;return}if(K.current){const m=q.clientX-K.current.x,k=q.clientY-K.current.y;if(Math.sqrt(m*m+k*k)>12){se.current=!1;return}}if(we.current==="mouse"){const m=Ee.current||re(q);m&&(d(`Click: ${Math.round(m.nx*100)}%, ${Math.round(m.ny*100)}%`),Ce(m.nx,m.ny,"left"),J.current("input_click",{...m}).catch(()=>{}))}else{const m=re(q);if(!m)return;Q-ce.current<300?(d("Double tap"),Ce(m.nx,m.ny,"double"),J.current("input_click",{...m,clickCount:2}).catch(()=>{}),ce.current=0):(d(`Tap: ${Math.round(m.nx*100)}%, ${Math.round(m.ny*100)}%`),Ce(m.nx,m.ny,"left"),J.current("input_click",{...m}).catch(()=>{}),ce.current=Q)}}se.current=!1}};return W.addEventListener("touchstart",ye,{passive:!1}),W.addEventListener("touchmove",pe,{passive:!1}),W.addEventListener("touchend",C,{passive:!1}),()=>{W.removeEventListener("touchstart",ye),W.removeEventListener("touchmove",pe),W.removeEventListener("touchend",C),clearTimeout(ie.current)}},[]),e.jsxs("div",{ref:r,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Ae,onContextMenu:W=>W.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:x,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[ve?e.jsx("img",{ref:u,src:ve,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${_}) translate(${Y}%, ${Z}%)`,transformOrigin:"center center",cursor:T==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:$e,onContextMenu:W=>W.preventDefault(),onDragStart:W=>W.preventDefault()}):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:oe}),e.jsx("div",{className:"text-[11px] text-white/40",children:he}),c==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),T==="mouse"&&_e&&ve&&u.current&&(()=>{var H;const W=u.current,re=W.getBoundingClientRect(),ee=(H=x.current)==null?void 0:H.getBoundingClientRect();if(!ee)return null;const xe=W.naturalWidth||re.width,ye=W.naturalHeight||re.height,pe=xe/ye,C=re.width/re.height;let E,G,q,Q;pe>C?(E=re.width,G=re.width/pe,q=0,Q=(re.height-G)/2):(G=re.height,E=re.height*pe,q=(re.width-E)/2,Q=0);const b=re.left-ee.left+q+E*_e.nx,m=re.top-ee.top+Q+G*_e.ny,k=Math.max(8,Math.min(ee.width-8,b)),M=Math.max(8,Math.min(ee.height-8,m));return e.jsxs("div",{style:{position:"absolute",left:k-8,top:M-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)"}})]})})(),p.map(W=>{const ee={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[W.type];return e.jsxs("div",{style:{position:"absolute",left:W.x,top:W.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${ee}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${ee}, 0.9)`,boxShadow:`0 0 12px rgba(${ee}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},W.id)})]}),e.jsxs("div",{onTouchStart:W=>W.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:()=>{D(W=>{const re=W==="touch"?"mouse":"touch";if(re==="mouse"&&!Ee.current){const ee={nx:.5,ny:.5};Ee.current=ee,Re(ee)}return re})},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:()=>{F(!O),S(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${O?"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:"⌨️"})}),O&&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:l,autoFocus:!0,onTouchStart:W=>W.stopPropagation(),onChange:W=>j(W.target.value),onKeyDown:Oe,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:()=>{S(!w),F(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${w?"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:je?"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:je?"#22c55e":"#eab308",boxShadow:je?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:je?"#22c55e":"#eab308"},children:je?"Connected":"WS"})]}),_>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(_*100),"%"]}),c==="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"}),c==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#c4b5fd",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:i.budgetExhausted?"TURN blocked":`TURN ${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}m`}),h&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:h})]})]}),w&&e.jsxs("div",{onTouchStart:W=>W.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: ",_<=(R?I:1)+.01?R?"FILL":"FIT":`${Math.round(_*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:W=>{W.stopPropagation(),X(re=>Math.max(.5,re-.25))},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:W=>{W.stopPropagation();const re=R?I:1;X(re),U.current=re,y(0),le(0)},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:R?"FILL":"FIT"}),e.jsx("button",{onClick:W=>{W.stopPropagation(),X(re=>Math.min(5,re+.25))},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("style",{children:`
7
+ `).trim();return{toolCounts:a,textContent:r,hasTools:Object.keys(a).length>0}}function St(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const gn=n.forwardRef(function({messages:s,actionLogs:o,agentName:a="Agent",userName:i,isCliMode:c=!1,isWorking:r=!1,contextKey:x="",receivedAtMap:u={},emptyState:h,onLoadMore:d,isLoadingMore:l,hasMoreHistory:v,loadError:f},p){var le;const A=n.useRef(null),$=n.useRef(null),w=n.useRef(0),S=n.useRef(""),O=n.useRef(!1),[F,R]=n.useState(new Set),[T,D]=n.useState(new Set),I=n.useRef(!1),N=()=>{const X=A.current;return X?X.scrollHeight-X.scrollTop-X.clientHeight<200:!0},ne=s.length>0?`${s.length}:${(((le=s[s.length-1])==null?void 0:le.content)||"").length}`:"0:0";n.useEffect(()=>{var ae,se;const X=!O.current,J=S.current!==x;if(S.current=x,X||J){O.current=!0,I.current=!1;const ie=()=>{var ce;(ce=$.current)==null||ce.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(ie)),setTimeout(ie,100),setTimeout(ie,300),w.current=s.length;return}s.length>w.current?I.current||(ae=$.current)==null||ae.scrollIntoView({behavior:"instant"}):N()&&!I.current&&((se=$.current)==null||se.scrollIntoView({behavior:"instant"})),w.current=s.length},[ne,x,r]),n.useImperativeHandle(p,()=>({scrollToBottom:(X="smooth")=>{var J;(J=$.current)==null||J.scrollIntoView({behavior:X})}})),n.useEffect(()=>{const X=A.current;if(!X)return;let J;const K=()=>{clearTimeout(J),J=setTimeout(()=>{I.current=!N()},50)};return X.addEventListener("scroll",K,{passive:!0}),()=>{X.removeEventListener("scroll",K),clearTimeout(J)}},[]);const _=n.useRef(0),V=n.useRef(!1);n.useEffect(()=>{const X=A.current;if(!X||!V.current||_.current===0)return;const J=X.scrollHeight-_.current;J>0&&(X.scrollTop=J),_.current=0,V.current=!1},[s.length]);const Y=()=>{const X=A.current;X&&(_.current=X.scrollHeight),V.current=!0,d==null||d()},y=(()=>{const X=s.map((se,ie)=>({type:"message",data:se,index:ie,ts:se.receivedAt||u[se.id??`i-${ie}`]||0}));if(!o||o.length===0)return X;const J=[...o].sort((se,ie)=>se.timestamp-ie.timestamp).map((se,ie)=>({type:"action",data:se,index:ie,ts:se.timestamp})),K=[];let ae=0;for(const se of X){for(;ae<J.length&&se.ts>0&&J[ae].ts<se.ts;)K.push(J[ae++]);K.push(se)}for(;ae<J.length;)K.push(J[ae++]);return K})(),Z=700;return e.jsxs("div",{ref:A,"data-chat-scroll":!0,className:"chat-container",children:[l&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),v&&!l&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:Y,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${f?"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:f?`↻ ${f}`:"↑ Load older messages"})}),y.length===0&&!v&&(h||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),y.map(X=>{var je;if(X.type==="action"){const oe=X.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Ht,{remarkPlugins:[zt],children:oe.text}),e.jsx("span",{className:"action-time",children:St(oe.timestamp)})]},`action-${X.index}`)}const J=X.data,K=X.index,ae=(J.role||"").toLowerCase(),se=ae==="user"||ae==="human",ie=J.kind||(ae==="tool"?"tool":"standard"),ce=J.receivedAt||u[J.id??`i-${K}`],P=`${x}-${K}`,j=F.has(P),B=T.has(P),g=typeof J.content=="string"?J.content:(J.content||[]).map(oe=>oe.text||"").join(`
8
+ `);if(ie==="thought"){const oe=((je=J.meta)==null?void 0:je.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(dn,{size:13}),e.jsx("span",{children:oe})]}),e.jsx("div",{className:"chat-msg-body",children:g})]},`msg-${K}`)}if(ie==="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:g.split(`
9
+ `)[0].slice(0,80)})]},`msg-${K}`);if(ie==="terminal"){const oe=J.meta||{},he=oe.isRunning?"⏳":"✅",L=oe.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:he}),e.jsx("span",{children:L})]}),e.jsx("pre",{className:"chat-msg-body",children:g})]},`msg-${K}`)}if(ie==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:g.slice(0,100)},`msg-${K}`);const z=!se&&c?fn(g):null,U=z?z.textContent:g,de=z?Object.entries(z.toolCounts):[],we=c&&!se&&!j&&U.length>Z,ve=j?g:we&&!B?U.slice(0,Z):U;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${se?"self-end":"self-start"}`,children:[de.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[de.map(([oe,he])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",oe,he>1?` ×${he}`:""]},oe)),(z==null?void 0:z.hasTools)&&e.jsx("button",{onClick:()=>R(oe=>{const he=new Set(oe);return j?he.delete(P):he.add(P),he}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:j?"Collapse":"Original"}),!U&&ce!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:St(ce)})]}),(U||se)&&e.jsxs("div",{className:`chat-bubble ${se?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${U?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:se?i||"You":a}),ce!=null&&e.jsx("span",{className:"chat-time",children:St(ce)})]}),U&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Ht,{remarkPlugins:[zt,_s,Rs],children:ve})}),we&&e.jsx("button",{onClick:()=>D(oe=>{const he=new Set(oe);return B?he.delete(P):he.add(P),he}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:B?"Collapse ↑":`Show more (${Math.round(U.length/100)*100} chars) ↓`})]})]},`msg-${K}`)}),r&&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 working..."})]})}),e.jsx("div",{className:"min-h-10",ref:$})]})}),Vt={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},bs=n.forwardRef(({onInput:t,onResize:s,fontSize:o=13},a)=>{const i=n.useRef(null),c=n.useRef(null),r=n.useRef(null),[x,u]=n.useState(!1);return n.useImperativeHandle(a,()=>({write:h=>{var d;(d=c.current)==null||d.write(h)},clear:()=>{var h;(h=c.current)==null||h.clear()},fit:()=>{var h;try{(h=r.current)==null||h.fit(),c.current&&(s==null||s(c.current.cols,c.current.rows))}catch{}},bumpResize:()=>{var h;try{(h=r.current)==null||h.fit();const d=c.current;if(!d)return;const l=d.cols,v=d.rows;s==null||s(l+5,v),setTimeout(()=>{s==null||s(l,v)},100)}catch{}}})),n.useEffect(()=>{if(!i.current)return;const h=new Hs({cursorBlink:!0,cursorStyle:"bar",fontSize:o,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:Vt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),d=new zs,l=new Us;h.loadAddon(d),h.loadAddon(l),h.open(i.current),requestAnimationFrame(()=>{d.fit(),s==null||s(h.cols,h.rows),u(!0)});const v=h.onData(p=>{t(p)}),f=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{d.fit(),s==null||s(h.cols,h.rows)}catch{}})});return f.observe(i.current),c.current=h,r.current=d,()=>{v.dispose(),f.disconnect(),h.dispose(),c.current=null,r.current=null}},[o]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:Vt.background,opacity:x?1:0}})});bs.displayName="CliTerminal";function ht({label:t,value:s,sub:o,icon:a}){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:a}),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}),o&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:o})]})}function Xt({value:t,max:s,label:o,color:a="#8b5cf6",detail:i,compact:c=!1}){const r=s>0?Math.min(Math.round(t/s*100),100):0,x=r>85?"#ef4444":r>60?"#f59e0b":a;return c?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:o}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[r,"%"]})]}),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:`${r}%`,background:x}})})]}):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:o}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[r,"%"]})]}),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:`${r}%`,background:`linear-gradient(90deg, ${x}, ${x}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function bn({onAction:t,addLog:s,connState:o,connScreenshot:a,screenshotUsage:i,transportType:c}){const r=n.useRef(null),x=n.useRef(null),u=n.useRef(null),[h,d]=n.useState(null),[l,v]=n.useState(""),[,f]=n.useState(!1),[p,A]=n.useState([]),$=n.useRef(0),[w,S]=n.useState(!1),[O,F]=n.useState(!1),R=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[T,D]=n.useState(R?"mouse":"touch"),[I,N]=n.useState(1),ne=n.useRef(!1),[_,V]=n.useState(1),[Y,y]=n.useState(0),[Z,le]=n.useState(0),X=n.useRef(0),J=n.useRef(t),K=n.useRef(null),ae=n.useRef(null),se=n.useRef(!1),ie=n.useRef(null),ce=n.useRef(0),P=n.useRef(null),j=n.useRef(1),B=n.useRef({x:0,y:0}),g=n.useRef(!1),z=n.useRef(_),U=n.useRef(Y),de=n.useRef(Z),we=n.useRef(T);n.useEffect(()=>{z.current=_},[_]),n.useEffect(()=>{U.current=Y},[Y]),n.useEffect(()=>{de.current=Z},[Z]),n.useEffect(()=>{J.current=t},[t]),n.useEffect(()=>{we.current=T},[T]),n.useEffect(()=>{var W;(W=r.current)==null||W.focus()},[]);const ve=o==="connected",je=a,oe=ve?"Connected. Waiting for first frame...":o==="connecting"?"Connecting to Host...":"Reconnecting to Host...",he=ve?"The remote stream is warming up":"Waiting for the remote stream to catch up";n.useEffect(()=>{if(!R||ne.current||!je)return;const W=u.current,re=x.current;if(!W||!re)return;const ee=()=>{const xe=re.clientWidth,ye=re.clientHeight,pe=W.naturalWidth,C=W.naturalHeight;if(!pe||!C||!xe||!ye)return;const E=Math.min(xe/pe,ye/C),q=Math.max(xe/pe,ye/C)/E;q>1.01&&(N(q),V(q),z.current=q),ne.current=!0};W.complete&&W.naturalWidth?ee():W.addEventListener("load",ee,{once:!0})},[je,R]);const L=.5;n.useEffect(()=>{_<=L&&(y(0),le(0))},[_,L]);const me=(W,re,ee)=>{if(ee<=L)return{x:0,y:0};const xe=(ee-1)/(2*ee)*100,ye=(ee-1)/(2*ee)*100;return{x:Math.max(-xe,Math.min(xe,W)),y:Math.max(-ye,Math.min(ye,re))}},ge=(W,re)=>{if(!u.current)return null;const ee=u.current.getBoundingClientRect();return!ee.width||!ee.height?null:{nx:Math.max(0,Math.min(1,(W-ee.left)/ee.width)),ny:Math.max(0,Math.min(1,(re-ee.top)/ee.height))}},fe=(W,re,ee)=>{const xe=x.current;if(!xe)return;const ye=xe.getBoundingClientRect(),pe=++$.current;A(C=>[...C,{id:pe,x:W-ye.left,y:re-ye.top,type:ee}]),setTimeout(()=>A(C=>C.filter(E=>E.id!==pe)),600)},Ce=(W,re,ee)=>{const xe=u.current,ye=x.current;if(!xe||!ye)return;const pe=xe.getBoundingClientRect(),C=ye.getBoundingClientRect(),E=xe.naturalWidth||pe.width,G=xe.naturalHeight||pe.height,q=E/G,Q=pe.width/pe.height;let b,m,k,M;q>Q?(b=pe.width,m=pe.width/q,k=0,M=(pe.height-m)/2):(m=pe.height,b=pe.height*q,k=(pe.width-b)/2,M=0);const H=pe.left-C.left+k+b*W,te=pe.top-C.top+M+m*re,ue=++$.current;A(be=>[...be,{id:ue,x:H,y:te,type:ee}]),setTimeout(()=>A(be=>be.filter(ke=>ke.id!==ue)),600)},$e=async W=>{var ee;const re=ge(W.clientX,W.clientY);if(re){d(`Click: ${Math.round(re.nx*100)}%, ${Math.round(re.ny*100)}%`),fe(W.clientX,W.clientY,"left"),(ee=r.current)==null||ee.focus();try{const xe=await t("input_click",{nx:re.nx,ny:re.ny});xe!=null&&xe.success||s(`❌ Click failed: ${xe==null?void 0:xe.error}`)}catch(xe){s(`❌ Click error: ${xe.message||xe}`)}}},Se=async(W,re,ee,xe=0)=>{try{await t("input_key",{type:ee?"char":"keyDown",key:W,code:re,text:ee?W:void 0,unmodifiedText:ee?W:void 0,modifiers:xe})}catch(ye){s(`❌ Key error: ${ye.message||ye}`)}},Ae=async W=>{if(W.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(W.key)&&W.preventDefault();let ee=0;W.altKey&&(ee|=1),W.ctrlKey&&(ee|=2),W.metaKey&&(ee|=4),W.shiftKey&&(ee|=8),d(`Key: ${W.key}`),await Se(W.key,W.code,W.key.length===1,ee)},Oe=async W=>{if(W.key==="Enter"){if(W.nativeEvent.isComposing)return;if(l){const re=l;v(""),d(`IME Sent: ${re}`);try{const ee=await t("input_type",{text:re});ee!=null&&ee.success||s(`❌ IME error: ${ee==null?void 0:ee.error}`)}catch(ee){s(`❌ IME error: ${ee.message}`)}}else d("Key: Enter"),await Se("Enter","Enter",!1)}};n.useEffect(()=>{const W=r.current;if(!W)return;const re=ee=>{var xe;if((xe=u.current)!=null&&xe.contains(ee.target)){ee.preventDefault();const ye=Date.now();if(ye-X.current<40)return;X.current=ye;const pe=ge(ee.clientX,ee.clientY);if(!pe)return;d(`Scroll: ${Math.round(ee.deltaY)}`),t("input_wheel",{nx:pe.nx,ny:pe.ny,deltaX:Math.round(ee.deltaX),deltaY:Math.round(ee.deltaY)}).catch(()=>{})}};return W.addEventListener("wheel",re,{passive:!1}),()=>W.removeEventListener("wheel",re)},[t]);const[_e,Re]=n.useState(null),Ee=n.useRef(null);return n.useEffect(()=>{if(T==="mouse"&&!Ee.current){const W={nx:.5,ny:.5};Ee.current=W,Re(W)}},[T]),n.useEffect(()=>{const W=r.current;if(!W)return;const re=E=>{if(!u.current)return null;const G=u.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(E.clientX-G.left)/G.width)),ny:Math.max(0,Math.min(1,(E.clientY-G.top)/G.height))}},ee=(E,G)=>{if(!u.current)return{dnx:0,dny:0};const q=u.current,Q=q.getBoundingClientRect(),b=q.naturalWidth||Q.width,m=q.naturalHeight||Q.height,k=b/m,M=Q.width/Q.height;let H,te;return k>M?(H=Q.width,te=Q.width/k):(te=Q.height,H=Q.height*k),{dnx:E/H,dny:G/te}},xe=(E,G,q)=>{if(q<=1.05)return;const Q=-(E-.5)*100,b=-(G-.5)*100,m=me(Q,b,q);(Math.abs(m.x-U.current)>.1||Math.abs(m.y-de.current)>.1)&&(y(m.x),le(m.y),U.current=m.x,de.current=m.y)},ye=E=>{const G=x.current;if(G&&E.target instanceof Node&&G.contains(E.target))E.preventDefault();else return;if(E.touches.length===1){const q=E.touches[0];K.current={x:q.clientX,y:q.clientY,time:Date.now()},ae.current={x:q.clientX,y:q.clientY},g.current||(se.current=!1),ie.current=setTimeout(()=>{if(!se.current&&!g.current)if(se.current=!0,we.current==="mouse"){const Q=Ee.current||{nx:.5,ny:.5};d("Right Click"),Ce(Q.nx,Q.ny,"right"),J.current("input_click",{...Q,button:"right"}).catch(()=>{})}else{const Q=re(q);Q&&(d("Right Click"),Ce(Q.nx,Q.ny,"right"),J.current("input_click",{...Q,button:"right"}).catch(()=>{}))}},500)}else if(E.touches.length===2){clearTimeout(ie.current),se.current=!0,g.current=!0;const q=E.touches[1].clientX-E.touches[0].clientX,Q=E.touches[1].clientY-E.touches[0].clientY;P.current=Math.sqrt(q*q+Q*Q),j.current=z.current,B.current={x:(E.touches[0].clientX+E.touches[1].clientX)/2,y:(E.touches[0].clientY+E.touches[1].clientY)/2}}},pe=E=>{const G=x.current;if(G&&E.target instanceof Node&&G.contains(E.target)&&E.preventDefault(),E.touches.length===1&&ae.current){const q=E.touches[0],Q=q.clientX-ae.current.x,b=q.clientY-ae.current.y;if(!se.current&&K.current){const m=q.clientX-K.current.x,k=q.clientY-K.current.y;Math.sqrt(m*m+k*k)>8&&(se.current=!0,clearTimeout(ie.current))}if(se.current)if(we.current==="mouse"){const m=ee(Q,b),k=Ee.current||{nx:.5,ny:.5},M=Math.max(0,Math.min(1,k.nx+m.dnx)),H=Math.max(0,Math.min(1,k.ny+m.dny));Ee.current={nx:M,ny:H},Re({nx:M,ny:H}),d(`Cursor: ${Math.round(M*100)}%, ${Math.round(H*100)}%`),xe(M,H,z.current);const te=Date.now();te-X.current>=30&&(X.current=te,J.current("input_mouseMoved",{nx:M,ny:H}).catch(()=>{}))}else if(z.current>1){const m=x.current;if(m){const k=m.clientWidth,M=m.clientHeight,H=U.current+Q/k*100,te=de.current+b/M*100,ue=me(H,te,z.current);y(ue.x),le(ue.y),U.current=ue.x,de.current=ue.y}}else{const m=re(q);if(m){const k=Date.now();k-X.current>=40&&(X.current=k,d("Scroll"),J.current("input_wheel",{nx:m.nx,ny:m.ny,deltaX:Math.round(-Q*2.5),deltaY:Math.round(-b*2.5)}).catch(()=>{}))}}ae.current={x:q.clientX,y:q.clientY}}else if(E.touches.length===2&&P.current!==null){const q=E.touches[1].clientX-E.touches[0].clientX,Q=E.touches[1].clientY-E.touches[0].clientY,m=Math.sqrt(q*q+Q*Q)/P.current,k=(E.touches[0].clientX+E.touches[1].clientX)/2,M=(E.touches[0].clientY+E.touches[1].clientY)/2,H=k-B.current.x,te=M-B.current.y,ue=Math.abs(m-1)>.03;if(we.current==="mouse"){if(ue){const be=Math.max(L,Math.min(5,j.current*m));V(be),z.current=be}else if(Math.abs(H)>2||Math.abs(te)>2){const be=Ee.current||{nx:.5,ny:.5},ke=Date.now();ke-X.current>=30&&(X.current=ke,d("Scroll"),J.current("input_wheel",{nx:be.nx,ny:be.ny,deltaX:Math.round(-H*3),deltaY:Math.round(-te*3)}).catch(()=>{}))}}else{const be=Math.max(L,Math.min(5,j.current*m));V(be),z.current=be;const ke=x.current;if(ke&&be>1){const Ke=ke.clientWidth,Fe=ke.clientHeight,Xe=U.current+H/Ke*100,rt=de.current+te/Fe*100,et=me(Xe,rt,be);y(et.x),le(et.y),U.current=et.x,de.current=et.y}}B.current={x:k,y:M}}},C=E=>{var G;if(clearTimeout(ie.current),P.current=null,E.touches.length===1&&g.current){const q=E.touches[0];K.current={x:q.clientX,y:q.clientY,time:Date.now()},ae.current={x:q.clientX,y:q.clientY},se.current=!0;return}if(E.touches.length===0){if(g.current){g.current=!1,se.current=!1;return}if(E.changedTouches.length===1&&!se.current){const q=E.changedTouches[0],Q=Date.now(),b=Q-(((G=K.current)==null?void 0:G.time)||0);if(b<60||b>400){se.current=!1;return}if(K.current){const m=q.clientX-K.current.x,k=q.clientY-K.current.y;if(Math.sqrt(m*m+k*k)>12){se.current=!1;return}}if(we.current==="mouse"){const m=Ee.current||re(q);m&&(d(`Click: ${Math.round(m.nx*100)}%, ${Math.round(m.ny*100)}%`),Ce(m.nx,m.ny,"left"),J.current("input_click",{...m}).catch(()=>{}))}else{const m=re(q);if(!m)return;Q-ce.current<300?(d("Double tap"),Ce(m.nx,m.ny,"double"),J.current("input_click",{...m,clickCount:2}).catch(()=>{}),ce.current=0):(d(`Tap: ${Math.round(m.nx*100)}%, ${Math.round(m.ny*100)}%`),Ce(m.nx,m.ny,"left"),J.current("input_click",{...m}).catch(()=>{}),ce.current=Q)}}se.current=!1}};return W.addEventListener("touchstart",ye,{passive:!1}),W.addEventListener("touchmove",pe,{passive:!1}),W.addEventListener("touchend",C,{passive:!1}),()=>{W.removeEventListener("touchstart",ye),W.removeEventListener("touchmove",pe),W.removeEventListener("touchend",C),clearTimeout(ie.current)}},[]),e.jsxs("div",{ref:r,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Ae,onContextMenu:W=>W.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:x,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[je?e.jsx("img",{ref:u,src:je,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${_}) translate(${Y}%, ${Z}%)`,transformOrigin:"center center",cursor:T==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:$e,onContextMenu:W=>W.preventDefault(),onDragStart:W=>W.preventDefault()}):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:oe}),e.jsx("div",{className:"text-[11px] text-white/40",children:he}),c==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),T==="mouse"&&_e&&je&&u.current&&(()=>{var H;const W=u.current,re=W.getBoundingClientRect(),ee=(H=x.current)==null?void 0:H.getBoundingClientRect();if(!ee)return null;const xe=W.naturalWidth||re.width,ye=W.naturalHeight||re.height,pe=xe/ye,C=re.width/re.height;let E,G,q,Q;pe>C?(E=re.width,G=re.width/pe,q=0,Q=(re.height-G)/2):(G=re.height,E=re.height*pe,q=(re.width-E)/2,Q=0);const b=re.left-ee.left+q+E*_e.nx,m=re.top-ee.top+Q+G*_e.ny,k=Math.max(8,Math.min(ee.width-8,b)),M=Math.max(8,Math.min(ee.height-8,m));return e.jsxs("div",{style:{position:"absolute",left:k-8,top:M-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)"}})]})})(),p.map(W=>{const ee={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[W.type];return e.jsxs("div",{style:{position:"absolute",left:W.x,top:W.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${ee}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${ee}, 0.9)`,boxShadow:`0 0 12px rgba(${ee}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},W.id)})]}),e.jsxs("div",{onTouchStart:W=>W.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:()=>{D(W=>{const re=W==="touch"?"mouse":"touch";if(re==="mouse"&&!Ee.current){const ee={nx:.5,ny:.5};Ee.current=ee,Re(ee)}return re})},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:()=>{F(!O),S(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${O?"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:"⌨️"})}),O&&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:l,autoFocus:!0,onTouchStart:W=>W.stopPropagation(),onChange:W=>v(W.target.value),onKeyDown:Oe,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:()=>{S(!w),F(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${w?"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:ve?"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:ve?"#22c55e":"#eab308",boxShadow:ve?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:ve?"#22c55e":"#eab308"},children:ve?"Connected":"WS"})]}),_>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(_*100),"%"]}),c==="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"}),c==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#c4b5fd",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:i.budgetExhausted?"TURN blocked":`TURN ${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}m`}),h&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:h})]})]}),w&&e.jsxs("div",{onTouchStart:W=>W.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: ",_<=(R?I:1)+.01?R?"FILL":"FIT":`${Math.round(_*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:W=>{W.stopPropagation(),V(re=>Math.max(.5,re-.25))},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:W=>{W.stopPropagation();const re=R?I:1;V(re),z.current=re,y(0),le(0)},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:R?"FILL":"FIT"}),e.jsx("button",{onClick:W=>{W.stopPropagation(),V(re=>Math.min(5,re+.25))},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("style",{children:`
10
10
  @keyframes slideUp {
11
11
  from { opacity: 0; transform: translateY(6px); }
12
12
  to { opacity: 1; transform: translateY(0); }
@@ -29,29 +29,29 @@ var Es=Object.defineProperty;var As=(t,s,o)=>s in t?Es(t,s,{enumerable:!0,config
29
29
  50% { transform: translateY(-7px); }
30
30
  100% { transform: translateY(0px); }
31
31
  }
32
- `})]})}function pn({screenshotUrl:t,mode:s="preview",zoom:o=100,interactive:a=!1,connectionState:i,onDismiss:c,onClickAt:r,onKeyDown:x,badge:u,emptyMessage:h,aspectRatio:d,className:l,style:j}){const f=n.useRef(null),p=n.useCallback(A=>{if(!a||!r||!f.current)return;const $=f.current,w=$.getBoundingClientRect(),S=(A.clientX-w.left)/w.width*$.naturalWidth,O=(A.clientY-w.top)/w.height*$.naturalHeight;r(S,O,$.naturalWidth,$.naturalHeight)},[a,r]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${l||""}`,style:{aspectRatio:d||"16/9",...j},children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),c&&e.jsx("button",{onClick:c,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${a?"screenshot-interactive":""} ${l||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:a?0:void 0,onKeyDown:a?x:void 0,style:j,children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",onClick:a?p:void 0,className:"max-w-full max-h-full object-contain",style:{...a?{cursor:"crosshair"}:{},...o!==100?{transform:`scale(${o/100})`,transformOrigin:"center center"}:{}}}),u&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:u})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${l||""}`,style:j,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.22)] mb-1",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("p",{className:"text-base",children:h||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
32
+ `})]})}function yn({screenshotUrl:t,mode:s="preview",zoom:o=100,interactive:a=!1,connectionState:i,onDismiss:c,onClickAt:r,onKeyDown:x,badge:u,emptyMessage:h,aspectRatio:d,className:l,style:v}){const f=n.useRef(null),p=n.useCallback(A=>{if(!a||!r||!f.current)return;const $=f.current,w=$.getBoundingClientRect(),S=(A.clientX-w.left)/w.width*$.naturalWidth,O=(A.clientY-w.top)/w.height*$.naturalHeight;r(S,O,$.naturalWidth,$.naturalHeight)},[a,r]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${l||""}`,style:{aspectRatio:d||"16/9",...v},children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),c&&e.jsx("button",{onClick:c,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${a?"screenshot-interactive":""} ${l||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:a?0:void 0,onKeyDown:a?x:void 0,style:v,children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",onClick:a?p:void 0,className:"max-w-full max-h-full object-contain",style:{...a?{cursor:"crosshair"}:{},...o!==100?{transform:`scale(${o/100})`,transformOrigin:"center center"}:{}}}),u&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:u})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${l||""}`,style:v,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.22)] mb-1",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("p",{className:"text-base",children:h||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
33
33
  @keyframes remote-float {
34
34
  0% { transform: translateY(0px); }
35
35
  50% { transform: translateY(-7px); }
36
36
  100% { transform: translateY(0px); }
37
37
  }
38
- `})]})}function hn({activeConv:t,onModalButton:s}){const[o,a]=n.useState(null);if(n.useEffect(()=>{a(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=r=>{o||(a(r),s(r))},c=r=>r.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",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(Ot,{size:14})," ",o?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((r,x)=>{const u=c(r).toLowerCase(),h=/^(run|approve|accept|yes|allow|always)/.test(u),d=/^(reject|deny|delete|remove|abort)/.test(u),l=o===r,j=o!==null;return e.jsx("button",{onClick:()=>i(r),disabled:j,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${h?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${j&&!l?"opacity-40":"opacity-100"} ${j?"cursor-not-allowed":"cursor-pointer"}`,children:l?"⏳ ...":c(r)},x)})})]})]})}const Pe=new Map;function fn({ideId:t,ideType:s,agentType:o,agentName:a,serverModel:i,serverMode:c,acpConfigOptions:r,acpModes:x}){var P;const{sendCommand:u}=Xe(),h=!!(r||x),d=`${t}:${o}`,l=Pe.get(d),[j,f]=n.useState(!1),[p,A]=n.useState(!1),[$,w]=n.useState((l==null?void 0:l.models)||[]),[S,O]=n.useState((l==null?void 0:l.modes)||[]),F=v=>v?typeof v=="string"?v:typeof v=="object"?v.name||v.id||JSON.stringify(v):String(v):"",[R,T]=n.useState(F(i)),[D,I]=n.useState(F(c)),[N,ne]=n.useState(!1),[_,X]=n.useState(!1),Y=n.useRef(0),y=v=>v.map(B=>typeof B=="string"?B:(B==null?void 0:B.name)||(B==null?void 0:B.id)||String(B));n.useEffect(()=>{if(r){const v=r.find(B=>B.category==="model");if(v){const B=y(v.options.map(U=>U.value));w(B),v.currentValue&&T(F(v.currentValue));const g=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...g,models:B})}}if(x&&x.length>0){const v=y(x.map(g=>g.id));O(v);const B=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...B,modes:v})}else if(r){const v=r.find(B=>B.category!=="model");if(v){const B=y(v.options.map(U=>U.value));O(B),v.currentValue&&I(F(v.currentValue));const g=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...g,modes:B})}}},[r,x,d]),n.useEffect(()=>{f(!1),A(!1),T(F(i)),I(F(c));const v=Pe.get(d);v?(w(v.models),O(v.modes)):(w([]),O([]))},[t,o]),n.useEffect(()=>{i&&Date.now()>Y.current&&T(F(i))},[i]),n.useEffect(()=>{c&&Date.now()>Y.current&&I(F(c))},[c]);const Z=n.useCallback(async(v,B={})=>{const g={...B},U=t.split(":");return U.length>=3&&(U[1]==="ide"||U[1]==="cli"||U[1]==="acp")&&(g._targetInstance=U.slice(2).join(":"),g._targetType=U[1]),await u(t,v,g)},[t]),le=async()=>{var v,B;if($.length>0){f(!j);return}if(h){f(!0);return}ne(!0);try{const g=await Z("list_extension_models",{agentType:o,ideType:s}),U=(g==null?void 0:g.models)||((v=g==null?void 0:g.result)==null?void 0:v.models)||[],z=y(U);w(z),g!=null&&g.current&&T(F(g.current)),(B=g==null?void 0:g.result)!=null&&B.current&&T(F(g.result.current));const de=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...de,models:z}),f(!0)}catch{}finally{ne(!1)}},V=async()=>{var v,B;if(S.length>0){A(!p);return}if(h){A(!0);return}X(!0);try{const g=await Z("list_extension_modes",{agentType:o,ideType:s}),U=(g==null?void 0:g.modes)||((v=g==null?void 0:g.result)==null?void 0:v.modes)||[],z=y(U);O(z),g!=null&&g.current&&I(F(g.current)),(B=g==null?void 0:g.result)!=null&&B.current&&I(F(g.result.current));const de=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...de,modes:z}),A(!0)}catch{}finally{X(!1)}},J=async v=>{f(!1),T(v),Y.current=Date.now()+5e3;try{h?await Z("change_model",{agentType:o,ideType:s,model:v}):await Z("set_extension_model",{agentType:o,ideType:s,model:v})}catch{}},K=h&&!(x&&x.length>0)&&(r==null?void 0:r.some(v=>v.category!=="model")),ae=K?(P=r==null?void 0:r.find(v=>v.category!=="model"))==null?void 0:P.configId:void 0,se=async v=>{A(!1),I(v),Y.current=Date.now()+5e3;try{h&&K&&ae?await Z("set_thought_level",{agentType:o,ideType:s,configId:ae,value:v}):h?await Z("set_mode",{agentType:o,ideType:s,mode:v}):await Z("set_extension_mode",{agentType:o,ideType:s,mode:v})}catch{}},ce={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[o]||"#94a3b8";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-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide uppercase opacity-70",style:{color:ce},children:a}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),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:j?`${ce}55`:"transparent",border:"1px solid",color:R?"var(--text-primary)":"var(--text-muted)"},onClick:le,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),N?"...":R||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),j&&$.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>f(!1)}),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:"SELECT MODEL"}),$.map(v=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:v===R?`${ce}18`:"transparent",color:v===R?ce:"var(--text-secondary)",fontWeight:v===R?600:400,borderLeft:v===R?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:B=>{B.currentTarget.style.background=`${ce}12`},onMouseLeave:B=>{B.currentTarget.style.background=v===R?`${ce}18`:"transparent"},onClick:()=>J(v),children:v},v))]})]})]}),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:p?`${ce}55`:"transparent",border:"1px solid",color:D?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:K?"🧠":"⚡"}),_?"...":D||(K?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),p&&S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>A(!1)}),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:K?"SELECT THINKING LEVEL":"SELECT MODE"}),S.map(v=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:v===D?`${ce}18`:"transparent",color:v===D?ce:"var(--text-secondary)",fontWeight:v===D?600:400,borderLeft:v===D?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:B=>{B.currentTarget.style.background=`${ce}12`},onMouseLeave:B=>{B.currentTarget.style.background=v===D?`${ce}18`:"transparent"},onClick:()=>se(v),children:v},v))]})]})]})]})}const Be=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),We=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function bs({activeConv:t,ides:s,agentInput:o,setAgentInput:a,handleSendChat:i,handleFocusAgent:c,isFocusingAgent:r,messageReceivedAt:x,actionLogs:u,userName:h}){const d=n.useRef(null),{sendCommand:l}=Xe(),j=n.useRef(new Map),f=n.useCallback(N=>(j.current.has(N)||j.current.set(N,{messages:[],offset:0,hasMore:!0,error:null}),j.current.get(N)),[]),p=n.useCallback((N,ne)=>{const _=f(N);j.current.set(N,{..._,...ne}),A(X=>X+1)},[f]),[,A]=n.useState(0),$=t.tabKey,w=f($),S=w.messages,O=w.hasMore,F=w.error,[R,T]=n.useState(!1),D=n.useCallback(async()=>{var _,X;if(R)return;const N=t.tabKey,ne=f(N);T(!0),p(N,{error:null});try{const Y=s.find(ae=>ae.id===t.ideId),y=(Y==null?void 0:Y.daemonId)||((_=t.ideId)==null?void 0:_.split(":")[0])||"";if(!y){p(N,{hasMore:!1});return}const Z=t.ideType||t.agentType||"",le=(t.ideId||"").split(":"),V=le.length>=3?le.slice(2).join(":"):void 0,J=await l(y,"chat_history",{agentType:Z,offset:ne.offset,limit:30,instanceId:V}),K=(J==null?void 0:J.result)??J;if(((X=K.messages)==null?void 0:X.length)>0){const ae=f(N);p(N,{messages:[...K.messages,...ae.messages],offset:ae.offset+K.messages.length,hasMore:!!K.hasMore})}else p(N,{hasMore:!!K.hasMore})}catch(Y){const y=(Y==null?void 0:Y.message)||"";y.includes("P2P not available")||y.includes("channel not open")||y.includes("P2P not connected")||y.includes("timeout")?p(N,{error:"Connection not ready — tap to retry"}):p(N,{hasMore:!1,error:"Failed to load history"})}finally{T(!1)}},[R,s,t,l,f,p]),I=(()=>{const N=t.messages.map((X,Y)=>{const y=`${t.ideId}-${X.id??`i-${Y}`}`;return{...X,receivedAt:X.receivedAt||x[y]||0}});if(S.length===0)return N;const ne=new Set(N.map(X=>`${X.role}:${(X.content||"").slice(0,100)}`));return[...S.filter(X=>!ne.has(`${X.role}:${(X.content||"").slice(0,100)}`)),...N]})();return e.jsxs(e.Fragment,{children:[e.jsx(xn,{messages:I,actionLogs:u.filter(N=>N.ideId===t.tabKey).sort((N,ne)=>N.timestamp-ne.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:Be(t)||We(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:D,isLoadingMore:R,hasMoreHistory:O,loadError:F??void 0,emptyState:t.messages.length===0?t.connectionState==="connecting"||t.connectionState==="new"?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"})]})]}):t.status==="not_monitored"?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(wt,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:r,className:"btn btn-primary",children:r?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]}):t.status==="panel_hidden"?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(an,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:c,disabled:r,className:"btn btn-primary",children:r?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:14})," Open ",t.displayPrimary," 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"})]}):t.status==="idle"&&!R?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..."})]}):void 0:void 0}),!Be(t)&&(()=>{var ne,_,X,Y;const N=s.find(y=>y.id===t.ideId);return e.jsx(fn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((_=(ne=N==null?void 0:N.agents)==null?void 0:ne[0])==null?void 0:_.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((Y=(X=N==null?void 0:N.agents)==null?void 0:X[0])==null?void 0:Y.name)||t.agentName,serverModel:(N==null?void 0:N.currentModel)||void 0,serverMode:(N==null?void 0:N.currentPlan)||void 0,acpConfigOptions:We(t)?N==null?void 0:N.acpConfigOptions:void 0,acpModes:We(t)?N==null?void 0:N.acpModes:void 0})})(),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:d,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:o,onChange:N=>a(N.target.value),onPaste:N=>{const ne=N.clipboardData.getData("text");ne&&a(_=>_+ne),N.preventDefault()},onKeyDown:N=>{if(N.key==="Enter"){if(N.nativeEvent.isComposing){N.preventDefault();return}N.preventDefault(),i()}},onBlur:N=>{if(window.innerWidth<768){const ne=N.relatedTarget;if((ne==null?void 0:ne.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:i,disabled:!o.trim(),className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${o.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:o.trim()?{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:o.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const Ct=new Set,ys={emit(t,s){for(const o of Ct)o(t,s)},on(t){return Ct.add(t),()=>{Ct.delete(t)}}};function gn({activeConv:t,ptyBuffers:s,terminalRef:o,agentInput:a,setAgentInput:i,handleSendChat:c}){var j;const r=n.useRef(null),{sendCommand:x,sendData:u}=Xe(),h=(j=t.ideId)!=null&&j.includes(":cli:")?t.ideId.split(":cli:")[1]:"",d=t.tabKey,l=t.ideType||t.agentType||"";return n.useEffect(()=>{const f=s.current.get(d);if(f&&f.length>0){const p=setTimeout(()=>{var A;for(const $ of f)(A=o.current)==null||A.write($);requestAnimationFrame(()=>{var $;($=o.current)==null||$.bumpResize()})},100);return()=>clearTimeout(p)}},[d]),n.useEffect(()=>{const f=ys.on((p,A)=>{var w;if(!A)return;(p===h||p===l||p===t.ideId||p===t.tabKey)&&((w=o.current)==null||w.write(A))});return()=>{f()}},[h,l]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(gs,{ref:o,onInput:f=>{var $;const p=t.ideId||t.daemonId||"",A=($=t.ideId)!=null&&$.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(p,{type:"pty_input",cliType:A,data:f})||x(p,"pty_input",{cliType:A,data:f}).catch(console.error)},onResize:(f,p)=>{var w;const A=t.ideId||t.daemonId||"",$=(w=t.ideId)!=null&&w.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(A,{type:"pty_resize",cliType:$,cols:f,rows:p})||x(A,"pty_resize",{cliType:$,cols:f,rows:p,force:!0}).catch(()=>{})}},t.tabKey)}),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:r,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:f=>i(f.target.value),onPaste:f=>{const p=f.clipboardData.getData("text");p&&i(A=>A+p),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),c()}},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:c,disabled:!a.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${a.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:a.trim()?{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:a.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function bn({wsStatus:t,showReconnected:s,loginUrl:o}){const a=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",c={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))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},r={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},x={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[a&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:c[i],borderBottom:r[i],color:x[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"&&(o?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:o,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"]})]})}let yn=dt;function kt(){return yn()}class vn{constructor(){Me(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,o){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(o),()=>{var a;(a=this.listeners.get(s))==null||a.delete(o)}}emit(s,...o){var a;(a=this.listeners.get(s))==null||a.forEach(i=>i(...o))}}let jn=new vn;class wn{constructor(){Me(this,"ptyCallbacks",new Set)}sendPtyInput(s,o,a){return!1}sendPtyResize(s,o,a,i){return!1}async requestChatHistory(s,o,a,i,c){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,o){return!1}get(s){}onScreenshot(s,o){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,o){this.ptyCallbacks.forEach(a=>a(s,o))}}let Te=new wn,Nn=Te;const It=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Mt=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function kn({activeConv:t,agentCount:s,wsStatus:o,isConnected:a,onOpenHistory:i}){const c=mt(),r=kt(),x=r.p2pStates||{},u=r.ides||[],h=a?"#22c55e":o==="connected"?"#eab308":"#ef4444",d=a?"0 0 4px #22c55e80":o==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",l=u.filter(w=>w.type==="adhdev-daemon"),j=Object.values(x),f=j.filter(w=>w==="connected").length,p=j.filter(w=>w==="connecting"||w==="new"||w==="checking").length,$=o!=="connected"||l.length===0?null:p>0&&f===0?"P2P connecting...":f>0&&s===0?"Waiting for IDE...":null;return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"leading-tight",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(jt,{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:h,boxShadow:d}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:a?"Connected":o==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:h,boxShadow:d}}),$&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",$]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&!It(t)&&!Mt(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Kt,{size:14})," IDE"]}),t&&!It(t)&&!Mt(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(sn,{size:16})}),t&&!It(t)&&!Mt(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(nt,{size:16})})]})]})}function Le(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Sn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const o=Math.floor(s/60),a=s%60;if(o<24)return a>0?`${o}h ${a}m`:`${o}h`;const i=Math.floor(o/24),c=o%24;return`${i}d ${c}h`}function Vt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function qt(t){return(t.id||"").includes(":cli:")}function Gt(t){return(t.id||"").includes(":acp:")}function Rt(t,s){return Le(t)}function Cn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,o=["generating","streaming","active","connected","idle","panel_hidden"];for(const a of t){const i=(a.name||a.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(i);if(!c){s.set(i,a);continue}const r=o.indexOf(c.status||"idle"),x=o.indexOf(a.status||"idle");x>=0&&(r<0||x<r)&&s.set(i,a)}return Array.from(s.values())}function In({activeConv:t,ides:s,isCreatingChat:o,isRefreshingHistory:a,onClose:i,onNewChat:c,onSwitchSession:r,onRefreshHistory:x}){var l;const u=s.find(j=>j.id===t.ideId),h=(u==null?void 0:u.chats)||[],d=(l=u==null?void 0:u.activeChat)==null?void 0:l.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,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:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Le(t.ideType)]})]}),e.jsx("button",{onClick:i,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:[e.jsx("button",{onClick:c,disabled:o,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:o?"⌛ Creating...":"+ Start New Chat Session"}),h.map(j=>e.jsxs("div",{onClick:()=>{r(t.ideId,j.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===j.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 ${d===j.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:j.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:[j.id.substring(0,12),"..."]}),d===j.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},j.id)),h.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(dn,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:x,disabled:a,className:"btn btn-secondary btn-sm rounded-[10px]",children:a?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(rn,{size:13})," Refresh History"]})})})]})]})}const Jt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Mn({toasts:t,onDismiss:s,onClickToast:o}){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(a=>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:Jt[a.type]||Jt.info},onClick:()=>{var i;(i=a.actions)!=null&&i.length||(o&&o(a),s(a.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(a.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:a.message}),a.actions&&a.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:a.actions.map((i,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 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:r=>{r.stopPropagation(),i.onClick(),s(a.id)},children:i.label},c))})]},a.id))})}const Tn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function En(t){const s=t.workspace||"";if(!s)return"";const o=s.split(/[/\\]/).filter(Boolean);return o.length>0?o[o.length-1]:s}function An(t,s,o,a){var c;const i={};if(o)for(const r of o){const x=r;if(x.type==="adhdev-daemon"||x.daemonMode){const u=x.machine||{},h=x.machineNickname,d=u.hostname||((c=x.system)==null?void 0:c.hostname)||"",l=h||(d&&d!=="Unknown"?d.replace(/\.local$/,""):null)||`Machine ${(x.id||"").substring(0,6)}`;i[x.id]=l}}return t.flatMap(r=>{var S,O,F,R,T;const x=[],u=r.daemonId&&i[r.daemonId]||void 0,h=r.daemonId||((S=r.id)==null?void 0:S.split(":")[0])||r.id,d=a?a[h]||"new":void 0,l=En(r),j=Le(r.type),f=r.agentStreams,p=Array.isArray(f)?f.map(D=>({...D,activeModal:D.activeModal??void 0})):[],A=Tn(r),$=r.activeChat||{title:""},w=$.title&&String($.title).trim()?String($.title).trim():"";if(A){const D=Rt(r.type),I=(O=r.agents)==null?void 0:O[0],N=(F=r.activeChat)==null?void 0:F.activeModal,ne=N&&Array.isArray(N.buttons)&&N.buttons.length>0,_=(R=r.activeChat)==null?void 0:R.status,X=_==="generating"||_==="loading"||_&&_.toLowerCase()==="thinking",y=ne||_==="waiting_approval"?"waiting_approval":X?"working":(I==null?void 0:I.status)||"idle",Z=r.activeChat||{title:"",messages:[]};let le=Z.title&&String(Z.title).trim()?String(Z.title).trim():"";const V=(T=r.activeChat)==null?void 0:T.id,J=r.chats;if(V&&Array.isArray(J)&&J.length>0){const ce=J.find(P=>P.id===V||P.id&&String(P.id)===String(V));ce!=null&&ce.title&&String(ce.title).trim()&&(le=String(ce.title).trim())}const K=Z.messages||[],ae=s[r.id]||[],se=new Map;K.filter(ce=>ce.role==="user").forEach(ce=>{se.set(ce.content,(se.get(ce.content)||0)+1)});const ie=ae.filter(ce=>{const P=se.get(ce.content)||0;return P>0?(se.set(ce.content,P-1),!1):!0});x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:Be(r)?r.mode||"terminal":"chat",agentName:D,agentType:Be(r)||We(r)?r.cliType||r.acpType||r.type:(I==null?void 0:I.type)||"ide-native",status:y,title:le,messages:[...K,...ie],ideType:r.cliType||r.acpType||r.type,workspaceName:l,displayPrimary:le||l||(Be(r)||We(r)?"Terminal":D),displaySecondary:j,cdpConnected:r.cdpConnected,modalButtons:ne?N.buttons:void 0,modalMessage:ne?N.message:void 0,streamSource:"native",tabKey:r.id,machineName:u,connectionState:d})}if(A&&(Be(r)||We(r)))return x;for(const D of p){const I=D.activeModal&&Array.isArray(D.activeModal.buttons)&&D.activeModal.buttons.length>0,N=I?"waiting_approval":D.status==="streaming"?"working":D.status,ne=`${r.id}:${D.agentType}`,_=D.messages||[],X=s[ne]||[],Y=new Map;_.filter(Z=>Z.role==="user").forEach(Z=>{Y.set(Z.content,(Y.get(Z.content)||0)+1)});const y=X.filter(Z=>{const le=Y.get(Z.content)||0;return le>0?(Y.set(Z.content,le-1),!1):!0});x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:"chat",agentName:D.agentName,agentType:D.agentType,status:N,title:"",messages:[..._,...y],ideType:D.agentType,workspaceName:l,displayPrimary:w||l||D.agentName,displaySecondary:`${j}·${D.agentName}`,cdpConnected:r.cdpConnected,modalButtons:I?D.activeModal.buttons:void 0,modalMessage:I?D.activeModal.message:void 0,streamSource:"agent-stream",tabKey:ne,machineName:u,connectionState:d})}return x.length===0&&x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:"chat",agentName:Rt(r.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:r.type,workspaceName:l,displayPrimary:l||j,displaySecondary:j,cdpConnected:r.cdpConnected,streamSource:"native",tabKey:r.id,connectionState:d}),x})}function $n(t,s){var x,u,h,d;const o=[],{daemonId:a,existingDaemon:i,timestamp:c}=s,r=c||t.timestamp||Date.now();o.push({...i||{},id:a,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:r,...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},..."system"in t&&{system:t.system},..."hostname"in t&&{hostname:t.hostname},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:t.managedIdes.some(l=>l.cdpConnected),managedIdeIds:t.managedIdes.map(l=>`${a}:ide:${l.instanceId}`),managedCliIds:t.managedClis.map(l=>l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`),managedAcpIds:t.managedAcps.map(l=>l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`)});for(const l of t.managedIdes)o.push({id:`${a}:ide:${l.instanceId}`,type:l.ideType,ideType:l.ideType,version:l.ideVersion,status:l.cdpConnected?"online":"detected",daemonId:a,instanceId:l.instanceId,workspace:l.workspace,terminals:l.terminals,agents:l.aiAgents,activeChat:l.activeChat,chats:l.chats,agentStreams:l.agentStreams,cdpConnected:l.cdpConnected,currentModel:l.currentModel,currentPlan:l.currentPlan,currentAutoApprove:l.currentAutoApprove,timestamp:r});for(const l of t.managedClis){const j=l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`;o.push({id:j,type:l.cliType,ideType:l.cliType,agentType:l.cliType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.cliName,mode:l.mode||"terminal",workspace:l.workspace,activeChat:l.activeChat,agentStreams:[{agentType:l.cliType,agentName:l.cliName,extensionId:"cli-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((x=l.activeChat)==null?void 0:x.messages)||[],inputContent:"",activeModal:(u=l.activeChat)==null?void 0:u.activeModal}],timestamp:r,_isCli:!0})}for(const l of t.managedAcps){const j=l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`;o.push({id:j,type:l.acpType,ideType:l.acpType,agentType:l.acpType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.acpName,mode:"chat",workspace:l.workspace,activeChat:l.activeChat,currentModel:l.currentModel,currentPlan:l.currentPlan,acpConfigOptions:l.acpConfigOptions,acpModes:l.acpModes,agentStreams:[{agentType:l.acpType,agentName:l.acpName,extensionId:"acp-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((h=l.activeChat)==null?void 0:h.messages)||[],inputContent:"",activeModal:(d=l.activeChat)==null?void 0:d.activeModal}],timestamp:r,_isAcp:!0})}return o}const vs="adhdev_notification_prefs",Zt={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function _n(){try{const t=localStorage.getItem(vs);if(t){const s=JSON.parse(t);return{...Zt,...s}}}catch{}return{...Zt}}function Rn(t){try{localStorage.setItem(vs,JSON.stringify(t))}catch{}}let Ye=_n(),gt=[];function Pn(){gt.forEach(t=>t())}function Ln(t){Ye={...Ye,...t},Rn(Ye),Pn()}function Dn(){const[,t]=n.useState(0);n.useEffect(()=>{const o=()=>t(a=>a+1);return gt.push(o),()=>{gt=gt.filter(a=>a!==o)}},[]);const s=n.useCallback(o=>{Ln(o)},[]);return[{...Ye},s]}function it(t){if(!Ye.globalEnabled)return!1;switch(t){case"disconnect":return Ye.disconnectAlert;case"completion":return Ye.completionAlert;case"approval":return Ye.approvalAlert;case"browser":return Ye.browserNotifications;default:return!0}}const Bn={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Wn(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function js(){return"Notification"in window&&Notification.permission==="granted"}let qe=null;async function On(){if(qe!==null)return qe;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return qe=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(qe=!!await t.pushManager.getSubscription(),qe):(qe=!1,!1)}catch{return qe=!1,!1}}function Pt(t,s,o){if(js())try{const a=new Notification(t,{body:s,icon:"/otter-logo.png",tag:o||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>a.close(),8e3),a.onclick=()=>{window.focus(),a.close()}}catch{}}function Kn(t,s={}){const o={...Bn,...s},a=n.useRef(new Map),i=n.useRef(0),c=n.useRef(null);n.useEffect(()=>{On().then(x=>{c.current=x})},[]);const r=n.useCallback((x,u,h)=>{const d=Date.now();d-i.current<o.throttleMs||(i.current=d,Pt(x,u,h))},[o.throttleMs]);n.useEffect(()=>{var x;if(!(!o.enabled||!js())&&it("browser")&&c.current!==!0){if(document.hasFocus()){for(const u of t)a.current.set(u.id,u.status||"idle");return}for(const u of t){const h=a.current.get(u.id),d=u.status||"idle",l=u.name||u.id;if(o.onApproval&&it("approval")&&d==="waiting_approval"&&h!=="waiting_approval"){const j=((x=u.activeModal)==null?void 0:x.message)||"Action requires your approval";r(`🔔 ${l} — Approval needed`,j.slice(0,120),`approval-${u.id}`)}o.onComplete&&it("completion")&&h==="generating"&&d==="idle"&&r(`✅ ${l} — Task complete`,"Agent has finished working",`complete-${u.id}`),o.onError&&d==="error"&&h!=="error"&&r(`⚠️ ${l} — Error`,"Agent encountered an error",`error-${u.id}`),a.current.set(u.id,d)}}},[t,o.enabled,o.onApproval,o.onComplete,o.onError,r])}class Fn{constructor(){Me(this,"dedupMap",new Map);Me(this,"DEDUP_WINDOW_MS",5e3);Me(this,"DEDUP_MAX_SIZE",50);Me(this,"DEDUP_CLEANUP_AGE_MS",1e4);Me(this,"toastCallbacks",[]);Me(this,"systemMessageCallbacks",[]);Me(this,"clearSystemMessageCallbacks",[]);Me(this,"resolveActionFn",null);Me(this,"viewRequestRespondFn",null);Me(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(o=>o!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(o=>o!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(o=>o!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const o of this.toastCallbacks)o(s)}emitSystemMessage(s,o){for(const a of this.systemMessageCallbacks)a(s,o)}emitClearSystemMessage(s,o){for(const a of this.clearSystemMessageCallbacks)a(s,o)}isDuplicate(s){const o=Date.now(),a=this.dedupMap.get(s)||0;if(o-a<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,o),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,c]of this.dedupMap)o-c>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(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(i)return i}let o;if(s.ideId&&(o=this.ides.find(i=>i.id===s.ideId)),!o&&s.instanceId&&(o=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),o){const i=o.daemonId;if(i){const c=this.ides.find(r=>r.id===i&&r.type==="adhdev-daemon");if(c)return c}}const a=this.ides.filter(i=>i.type==="adhdev-daemon");return a.length===1?a[0]:null}resolveRouteId(s,o){for(const a of this.ides)if(a.id.startsWith(s)&&(!o||o===a.type))return a.id;return s}handleRawEvent(s,o){var u,h,d;const a=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;if(!s.ideId&&s.instanceId){for(const l of this.ides)if(l.id.endsWith(`:ide:${s.instanceId}`)||l.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=l.id;break}}let i=Le(s.ideType||"");const c=this.resolveOwningDaemon(s);if(c){const l=c.machineNickname||((u=c.machine)==null?void 0:u.hostname);l&&(i=s.ideType==="adhdev-daemon"?l:`${l}/${i}`)}let r="",x="info";if(s.event==="agent:generating_completed"){const l=s.duration?` (${s.duration}s)`:"";r=`✅ ${i} agent task completed${l}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${l}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(r=`⚡ ${i} approval needed`,x="warning",s.ideId){const l=s.modalMessage||"Approval requested",j=(h=s.modalButtons)!=null&&h.length?s.modalButtons.map(f=>`[${f}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${l}
39
- ${j}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((d=s.modalButtons)!=null&&d.length)&&this.resolveActionFn){const l=s.ideId,j=s.agentType||s.ideType||"",f=s.ideType||"",p=s.modalButtons,A=F=>F.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),$=this.resolveActionFn,w=p.map((F,R)=>{const T=A(F).toLowerCase(),D=/^(run|approve|accept|yes|allow|always)/.test(T),I=/^(reject|deny|delete|remove|abort|cancel|no)/.test(T);return{label:A(F),variant:D?"primary":I?"danger":"default",onClick:()=>{const N=this.resolveRouteId(l,j),ne=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(T);$(N,"resolve_action",{action:ne?"approve":"reject",button:F,buttonIndex:R,agentType:j,ideType:f})}}}),S=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:r,O=Date.now();this.emitToast({id:O,message:S,type:x,timestamp:O,ideId:l,actions:w,duration:15e3}),r=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";r=`⚠️ ${i} agent is taking a long time${l}`,x="warning",it("browser")&&!document.hasFocus()&&Pt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",j=s.requestId,f=s.orgId;if(r=`👁️ ${l} wants to view your session`,x="warning",j&&f&&this.viewRequestRespondFn){const p=this.viewRequestRespondFn,A=Date.now(),$=[{label:"Approve",variant:"primary",onClick:()=>{p(f,j,"approve").catch(w=>console.error("[EventManager] approve view request failed:",w))}},{label:"Decline",variant:"danger",onClick:()=>{p(f,j,"reject").catch(w=>console.error("[EventManager] reject view request failed:",w))}}];this.emitToast({id:A,message:r,type:x,timestamp:A,actions:$,duration:3e4}),r=""}it("browser")&&!document.hasFocus()&&Pt("👁️ View Request",`${l} wants to view your session`,`view-request-${j}`)}else s.event==="team:view_request_approved"?(r="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(r=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(r){const l=Date.now();this.emitToast({id:l,message:r,type:x,timestamp:l,ideId:s.ideId,duration:5e3})}}}const et=new Fn;function ut(...t){return Rs(Ps(t))}function ws({icon:t,title:s,subtitle:o,badge:a,actions:i,className:c}){return e.jsxs("div",{className:ut("dashboard-header",c),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,a&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[a.count!==void 0?a.count:""," ",a.text]})]}),o&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:o})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function tt({title:t,icon:s,description:o,accentColor:a,className:i,children:c}){return e.jsxs("div",{className:ut("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",a&&"border-l-[3px]",i),style:a?{borderLeftColor:a}:void 0,children:[(t||o)&&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]}),o&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:o})]}),c]})}function Hn({icon:t,title:s,description:o,action:a,className:i}){return e.jsxs("div",{className:ut("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:o}),a]})}const Un={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"},zn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Yn({status:t,label:s,className:o}){const a=s||t;return e.jsxs("span",{className:ut("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Un[t],o),children:[e.jsx("span",{className:ut("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",zn[t])}),a]})}function Xn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Qt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Tt(t){return t==="system"?Xn():t}function Vn(){const[t,s]=n.useState(Qt),[o,a]=n.useState(()=>Tt(Qt()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",o)},[o]),n.useEffect(()=>{const r=window.matchMedia("(prefers-color-scheme: light)"),x=u=>{t==="system"&&a(u.matches?"light":"dark")};return r.addEventListener("change",x),()=>r.removeEventListener("change",x)},[t]);const i=n.useCallback(r=>{s(r),a(Tt(r));try{localStorage.setItem("theme",r)}catch{}},[]),c=n.useCallback(()=>{s(r=>{const x=r==="dark"?"light":r==="light"?"system":"dark";a(Tt(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:o,preference:t,setPreference:i,cycleTheme:c,isDark:o==="dark"}}function st({label:t,description:s,checked:o,disabled:a,onChange:i,extra:c}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c,e.jsx("input",{type:"checkbox",checked:o,disabled:a,onChange:r=>i(r.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function qn({onPrefChange:t}){const[s,o]=Dn(),a=(i,c)=>{o({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(st,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>a("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(st,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>a("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(st,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>a("completionAlert",i)}),e.jsx(st,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>a("approvalAlert",i)}),e.jsx(st,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>a("disconnectAlert",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."})]})}const Ns=[{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:"💚"}],ks=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"}],Ss=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}];function Gn({ides:t,emptyMessage:s,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i}){const c=t.filter(r=>r.type==="adhdev-daemon");return c.length===0?e.jsx(Hn,{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 setup' once, then 'adhdev daemon' to connect this machine."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(r=>e.jsx(Zn,{ide:r,allIdes:t,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i},r.id))})}function es({title:t,message:s,confirmLabel:o,confirmColor:a,onConfirm:i,onCancel:c}){const r=a==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return Ls.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,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:x=>x.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:c,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 ${r}`,children:o})]})]})}),document.body)}function Jn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),a=[...Ns,...ks,...Ss].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return a?{icon:a.icon,name:a.name}:{icon:"📝",name:t}}function Zn({ide:t,allIdes:s,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i}){var Z,le,V,J;const[c,r]=n.useState("idle"),[x,u]=n.useState(""),[h,d]=n.useState(null),[l,j]=n.useState("idle"),[f,p]=n.useState(""),A=t,$=A.version||A.daemonVersion||null,w=((Z=A.machine)==null?void 0:Z.hostname)||((le=A.system)==null?void 0:le.hostname)||"",S=((V=A.machine)==null?void 0:V.platform)||((J=A.system)==null?void 0:J.platform)||"",O=A.machineNickname||(w==null?void 0:w.replace(/\.local$/,""))||"Machine",F=S==="win32"?"🪟":S==="darwin"?"🍎":"🐧",R=s.filter(K=>K.daemonId===t.id&&K.id.includes(":ide:")),T=s.filter(K=>K.daemonId===t.id&&K.id.includes(":cli:")),D=s.filter(K=>K.daemonId===t.id&&K.id.includes(":acp:")),I=A.p2p,N=async()=>{var K,ae,se;if(o){r("upgrading"),u("Installing latest version...");try{const ie=await o(t.id,"daemon_upgrade",{});(K=ie==null?void 0:ie.result)!=null&&K.upgraded||(ae=ie==null?void 0:ie.result)!=null&&ae.success?(r("done"),u(`Upgraded to v${ie.result.version||"latest"}. Daemon is restarting...`)):(r("error"),u(((se=ie==null?void 0:ie.result)==null?void 0:se.error)||"Upgrade failed"))}catch(ie){r("error"),u((ie==null?void 0:ie.message)||"Connection lost during upgrade")}}},ne=async()=>{if(d(null),!!a){j("loading");try{await a(t.id),j("done"),p("Machine disconnected.")}catch(K){j("error"),p((K==null?void 0:K.message)||"Failed to disconnect")}}},_=async()=>{if(d(null),!!i){j("loading");try{await i(t.id),j("done"),p('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(K){j("error"),p((K==null?void 0:K.message)||"Failed to revoke token")}}},X="0.6.66",Y=!$||$!==X,y=R.length+T.length+D.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:F}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:O}),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),"…"]}),$&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${Y?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",$,!Y&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o&&Y&&e.jsx("button",{onClick:N,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${X}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${X}`}`}),a&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:l==="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:()=>d("revoke"),disabled:l==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Yn,{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:[I&&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 ${I.state==="connected"?"bg-green-400":I.state==="connecting"||I.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",I.state==="connected"?"connected":I.state==="connecting"||I.state==="new"?"connecting...":I.state||"off"]}),I.peers!==void 0&&I.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",I.peers," peer",I.peers!==1?"s":"",")"]})]}),I&&y>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),y>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[R.map(K=>{const ae=Jn(K.type),se=K.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:ae.icon}),e.jsx("span",{children:ae.name}),se!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${se?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:se?"CDP connected":"CDP connecting..."})]},K.id)}),T.map(K=>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:K.cliName||"CLI"})]},K.id)),D.map(K=>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:K.cliName||"ACP"})]},K.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||l==="error"?"text-red-400":c==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:f||x})]}),h==="disconnect"&&e.jsx(es,{title:"🔌 Disconnect Machine",message:`Disconnect "${O}" from ADHDev?
38
+ `})]})}function jn({activeConv:t,onModalButton:s}){const[o,a]=n.useState(null);if(n.useEffect(()=>{a(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=r=>{o||(a(r),s(r))},c=r=>r.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",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(Kt,{size:14})," ",o?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((r,x)=>{const u=c(r).toLowerCase(),h=/^(run|approve|accept|yes|allow|always)/.test(u),d=/^(reject|deny|delete|remove|abort)/.test(u),l=o===r,v=o!==null;return e.jsx("button",{onClick:()=>i(r),disabled:v,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${h?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${v&&!l?"opacity-40":"opacity-100"} ${v?"cursor-not-allowed":"cursor-pointer"}`,children:l?"⏳ ...":c(r)},x)})})]})]})}const Pe=new Map;function vn({ideId:t,ideType:s,agentType:o,agentName:a,serverModel:i,serverMode:c,acpConfigOptions:r,acpModes:x}){var P;const{sendCommand:u}=Ve(),h=!!(r||x),d=`${t}:${o}`,l=Pe.get(d),[v,f]=n.useState(!1),[p,A]=n.useState(!1),[$,w]=n.useState((l==null?void 0:l.models)||[]),[S,O]=n.useState((l==null?void 0:l.modes)||[]),F=j=>j?typeof j=="string"?j:typeof j=="object"?j.name||j.id||JSON.stringify(j):String(j):"",[R,T]=n.useState(F(i)),[D,I]=n.useState(F(c)),[N,ne]=n.useState(!1),[_,V]=n.useState(!1),Y=n.useRef(0),y=j=>j.map(B=>typeof B=="string"?B:(B==null?void 0:B.name)||(B==null?void 0:B.id)||String(B));n.useEffect(()=>{if(r){const j=r.find(B=>B.category==="model");if(j){const B=y(j.options.map(z=>z.value));w(B),j.currentValue&&T(F(j.currentValue));const g=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...g,models:B})}}if(x&&x.length>0){const j=y(x.map(g=>g.id));O(j);const B=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...B,modes:j})}else if(r){const j=r.find(B=>B.category!=="model");if(j){const B=y(j.options.map(z=>z.value));O(B),j.currentValue&&I(F(j.currentValue));const g=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...g,modes:B})}}},[r,x,d]),n.useEffect(()=>{f(!1),A(!1),T(F(i)),I(F(c));const j=Pe.get(d);j?(w(j.models),O(j.modes)):(w([]),O([]))},[t,o]),n.useEffect(()=>{i&&Date.now()>Y.current&&T(F(i))},[i]),n.useEffect(()=>{c&&Date.now()>Y.current&&I(F(c))},[c]);const Z=n.useCallback(async(j,B={})=>{const g={...B},z=t.split(":");return z.length>=3&&(z[1]==="ide"||z[1]==="cli"||z[1]==="acp")&&(g._targetInstance=z.slice(2).join(":"),g._targetType=z[1]),await u(t,j,g)},[t]),le=async()=>{var j,B;if($.length>0){f(!v);return}if(h){f(!0);return}ne(!0);try{const g=await Z("list_extension_models",{agentType:o,ideType:s}),z=(g==null?void 0:g.models)||((j=g==null?void 0:g.result)==null?void 0:j.models)||[],U=y(z);w(U),g!=null&&g.current&&T(F(g.current)),(B=g==null?void 0:g.result)!=null&&B.current&&T(F(g.result.current));const de=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...de,models:U}),f(!0)}catch{}finally{ne(!1)}},X=async()=>{var j,B;if(S.length>0){A(!p);return}if(h){A(!0);return}V(!0);try{const g=await Z("list_extension_modes",{agentType:o,ideType:s}),z=(g==null?void 0:g.modes)||((j=g==null?void 0:g.result)==null?void 0:j.modes)||[],U=y(z);O(U),g!=null&&g.current&&I(F(g.current)),(B=g==null?void 0:g.result)!=null&&B.current&&I(F(g.result.current));const de=Pe.get(d)||{models:[],modes:[]};Pe.set(d,{...de,modes:U}),A(!0)}catch{}finally{V(!1)}},J=async j=>{f(!1),T(j),Y.current=Date.now()+5e3;try{h?await Z("change_model",{agentType:o,ideType:s,model:j}):await Z("set_extension_model",{agentType:o,ideType:s,model:j})}catch{}},K=h&&!(x&&x.length>0)&&(r==null?void 0:r.some(j=>j.category!=="model")),ae=K?(P=r==null?void 0:r.find(j=>j.category!=="model"))==null?void 0:P.configId:void 0,se=async j=>{A(!1),I(j),Y.current=Date.now()+5e3;try{h&&K&&ae?await Z("set_thought_level",{agentType:o,ideType:s,configId:ae,value:j}):h?await Z("set_mode",{agentType:o,ideType:s,mode:j}):await Z("set_extension_mode",{agentType:o,ideType:s,mode:j})}catch{}},ce={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[o]||"#94a3b8";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-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide uppercase opacity-70",style:{color:ce},children:a}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),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:v?`${ce}55`:"transparent",border:"1px solid",color:R?"var(--text-primary)":"var(--text-muted)"},onClick:le,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),N?"...":R||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),v&&$.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>f(!1)}),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:"SELECT MODEL"}),$.map(j=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:j===R?`${ce}18`:"transparent",color:j===R?ce:"var(--text-secondary)",fontWeight:j===R?600:400,borderLeft:j===R?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:B=>{B.currentTarget.style.background=`${ce}12`},onMouseLeave:B=>{B.currentTarget.style.background=j===R?`${ce}18`:"transparent"},onClick:()=>J(j),children:j},j))]})]})]}),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:p?`${ce}55`:"transparent",border:"1px solid",color:D?"var(--text-primary)":"var(--text-muted)"},onClick:X,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:K?"🧠":"⚡"}),_?"...":D||(K?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),p&&S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>A(!1)}),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:K?"SELECT THINKING LEVEL":"SELECT MODE"}),S.map(j=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:j===D?`${ce}18`:"transparent",color:j===D?ce:"var(--text-secondary)",fontWeight:j===D?600:400,borderLeft:j===D?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:B=>{B.currentTarget.style.background=`${ce}12`},onMouseLeave:B=>{B.currentTarget.style.background=j===D?`${ce}18`:"transparent"},onClick:()=>se(j),children:j},j))]})]})]})]})}const Be=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),We=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function ys({activeConv:t,ides:s,agentInput:o,setAgentInput:a,handleSendChat:i,handleFocusAgent:c,isFocusingAgent:r,messageReceivedAt:x,actionLogs:u,userName:h}){const d=n.useRef(null),{sendCommand:l}=Ve(),v=n.useRef(new Map),f=n.useCallback(N=>(v.current.has(N)||v.current.set(N,{messages:[],offset:0,hasMore:!0,error:null}),v.current.get(N)),[]),p=n.useCallback((N,ne)=>{const _=f(N);v.current.set(N,{..._,...ne}),A(V=>V+1)},[f]),[,A]=n.useState(0),$=t.tabKey,w=f($),S=w.messages,O=w.hasMore,F=w.error,[R,T]=n.useState(!1),D=n.useCallback(async()=>{var _,V;if(R)return;const N=t.tabKey,ne=f(N);T(!0),p(N,{error:null});try{const Y=s.find(ae=>ae.id===t.ideId),y=(Y==null?void 0:Y.daemonId)||((_=t.ideId)==null?void 0:_.split(":")[0])||"";if(!y){p(N,{hasMore:!1});return}const Z=t.ideType||t.agentType||"",le=(t.ideId||"").split(":"),X=le.length>=3?le.slice(2).join(":"):void 0,J=await l(y,"chat_history",{agentType:Z,offset:ne.offset,limit:30,instanceId:X}),K=(J==null?void 0:J.result)??J;if(((V=K.messages)==null?void 0:V.length)>0){const ae=f(N);p(N,{messages:[...K.messages,...ae.messages],offset:ae.offset+K.messages.length,hasMore:!!K.hasMore})}else p(N,{hasMore:!!K.hasMore})}catch(Y){const y=(Y==null?void 0:Y.message)||"";y.includes("P2P not available")||y.includes("channel not open")||y.includes("P2P not connected")||y.includes("timeout")?p(N,{error:"Connection not ready — tap to retry"}):p(N,{hasMore:!1,error:"Failed to load history"})}finally{T(!1)}},[R,s,t,l,f,p]),I=(()=>{const N=t.messages.map((V,Y)=>{const y=`${t.ideId}-${V.id??`i-${Y}`}`;return{...V,receivedAt:V.receivedAt||x[y]||0}});if(S.length===0)return N;const ne=new Set(N.map(V=>`${V.role}:${(V.content||"").slice(0,100)}`));return[...S.filter(V=>!ne.has(`${V.role}:${(V.content||"").slice(0,100)}`)),...N]})();return e.jsxs(e.Fragment,{children:[e.jsx(gn,{messages:I,actionLogs:u.filter(N=>N.ideId===t.tabKey).sort((N,ne)=>N.timestamp-ne.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:Be(t)||We(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:D,isLoadingMore:R,hasMoreHistory:O,loadError:F??void 0,emptyState:t.messages.length===0?t.connectionState==="connecting"||t.connectionState==="new"?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"})]})]}):t.status==="not_monitored"?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(ut,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:r,className:"btn btn-primary",children:r?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]}):t.status==="panel_hidden"?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(on,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:c,disabled:r,className:"btn btn-primary",children:r?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{size:14})," Open ",t.displayPrimary," 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"})]}):t.status==="idle"&&!R?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..."})]}):void 0:void 0}),!Be(t)&&(()=>{var ne,_,V,Y;const N=s.find(y=>y.id===t.ideId);return e.jsx(vn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((_=(ne=N==null?void 0:N.agents)==null?void 0:ne[0])==null?void 0:_.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((Y=(V=N==null?void 0:N.agents)==null?void 0:V[0])==null?void 0:Y.name)||t.agentName,serverModel:(N==null?void 0:N.currentModel)||void 0,serverMode:(N==null?void 0:N.currentPlan)||void 0,acpConfigOptions:We(t)?N==null?void 0:N.acpConfigOptions:void 0,acpModes:We(t)?N==null?void 0:N.acpModes:void 0})})(),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:d,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:o,onChange:N=>a(N.target.value),onPaste:N=>{const ne=N.clipboardData.getData("text");ne&&a(_=>_+ne),N.preventDefault()},onKeyDown:N=>{if(N.key==="Enter"){if(N.nativeEvent.isComposing){N.preventDefault();return}N.preventDefault(),i()}},onBlur:N=>{if(window.innerWidth<768){const ne=N.relatedTarget;if((ne==null?void 0:ne.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:i,disabled:!o.trim(),className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${o.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:o.trim()?{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:o.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const Ct=new Set,js={emit(t,s){for(const o of Ct)o(t,s)},on(t){return Ct.add(t),()=>{Ct.delete(t)}}};function wn({activeConv:t,ptyBuffers:s,terminalRef:o,agentInput:a,setAgentInput:i,handleSendChat:c}){var v;const r=n.useRef(null),{sendCommand:x,sendData:u}=Ve(),h=(v=t.ideId)!=null&&v.includes(":cli:")?t.ideId.split(":cli:")[1]:"",d=t.tabKey,l=t.ideType||t.agentType||"";return n.useEffect(()=>{const f=s.current.get(d);if(f&&f.length>0){const p=setTimeout(()=>{var A;for(const $ of f)(A=o.current)==null||A.write($);requestAnimationFrame(()=>{var $;($=o.current)==null||$.bumpResize()})},100);return()=>clearTimeout(p)}},[d]),n.useEffect(()=>{const f=js.on((p,A)=>{var w;if(!A)return;(p===h||p===l||p===t.ideId||p===t.tabKey)&&((w=o.current)==null||w.write(A))});return()=>{f()}},[h,l]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(bs,{ref:o,onInput:f=>{var $;const p=t.ideId||t.daemonId||"",A=($=t.ideId)!=null&&$.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(p,{type:"pty_input",cliType:A,data:f})||x(p,"pty_input",{cliType:A,data:f}).catch(console.error)},onResize:(f,p)=>{var w;const A=t.ideId||t.daemonId||"",$=(w=t.ideId)!=null&&w.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(A,{type:"pty_resize",cliType:$,cols:f,rows:p})||x(A,"pty_resize",{cliType:$,cols:f,rows:p,force:!0}).catch(()=>{})}},t.tabKey)}),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:r,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:f=>i(f.target.value),onPaste:f=>{const p=f.clipboardData.getData("text");p&&i(A=>A+p),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),c()}},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:c,disabled:!a.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${a.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:a.trim()?{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:a.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Nn({wsStatus:t,showReconnected:s,loginUrl:o}){const a=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",c={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))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},r={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},x={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[a&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:c[i],borderBottom:r[i],color:x[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"&&(o?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:o,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"]})]})}let kn=dt;function kt(){return kn()}class Sn{constructor(){Me(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,o){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(o),()=>{var a;(a=this.listeners.get(s))==null||a.delete(o)}}emit(s,...o){var a;(a=this.listeners.get(s))==null||a.forEach(i=>i(...o))}}let Cn=new Sn;class In{constructor(){Me(this,"ptyCallbacks",new Set)}sendPtyInput(s,o,a){return!1}sendPtyResize(s,o,a,i){return!1}async requestChatHistory(s,o,a,i,c){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,o){return!1}get(s){}onScreenshot(s,o){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,o){this.ptyCallbacks.forEach(a=>a(s,o))}}let Te=new In,Mn=Te;const It=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Mt=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function Tn({activeConv:t,agentCount:s,wsStatus:o,isConnected:a,onOpenHistory:i}){const c=pt(),r=kt(),x=r.p2pStates||{},u=r.ides||[],h=a?"#22c55e":o==="connected"?"#eab308":"#ef4444",d=a?"0 0 4px #22c55e80":o==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",l=u.filter(w=>w.type==="adhdev-daemon"),v=Object.values(x),f=v.filter(w=>w==="connected").length,p=v.filter(w=>w==="connecting"||w==="new"||w==="checking").length,$=o!=="connected"||l.length===0?null:p>0&&f===0?"P2P connecting...":f>0&&s===0?"Waiting for IDE...":null;return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"leading-tight",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(wt,{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:h,boxShadow:d}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:a?"Connected":o==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:h,boxShadow:d}}),$&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",$]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&!It(t)&&!Mt(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Ft,{size:14})," IDE"]}),t&&!It(t)&&!Mt(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(rn,{size:16})}),t&&!It(t)&&!Mt(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Qe,{size:16})})]})]})}function Le(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function En(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const o=Math.floor(s/60),a=s%60;if(o<24)return a>0?`${o}h ${a}m`:`${o}h`;const i=Math.floor(o/24),c=o%24;return`${i}d ${c}h`}function qt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gt(t){return(t.id||"").includes(":cli:")}function Jt(t){return(t.id||"").includes(":acp:")}function Rt(t,s){return Le(t)}function An(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,o=["generating","streaming","active","connected","idle","panel_hidden"];for(const a of t){const i=(a.name||a.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(i);if(!c){s.set(i,a);continue}const r=o.indexOf(c.status||"idle"),x=o.indexOf(a.status||"idle");x>=0&&(r<0||x<r)&&s.set(i,a)}return Array.from(s.values())}function $n({activeConv:t,ides:s,isCreatingChat:o,isRefreshingHistory:a,onClose:i,onNewChat:c,onSwitchSession:r,onRefreshHistory:x}){var l;const u=s.find(v=>v.id===t.ideId),h=(u==null?void 0:u.chats)||[],d=(l=u==null?void 0:u.activeChat)==null?void 0:l.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,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:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Le(t.ideType)]})]}),e.jsx("button",{onClick:i,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:[e.jsx("button",{onClick:c,disabled:o,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:o?"⌛ Creating...":"+ Start New Chat Session"}),h.map(v=>e.jsxs("div",{onClick:()=>{r(t.ideId,v.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===v.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 ${d===v.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:v.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:[v.id.substring(0,12),"..."]}),d===v.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},v.id)),h.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(un,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:x,disabled:a,className:"btn btn-secondary btn-sm rounded-[10px]",children:a?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hs,{size:13})," Refresh History"]})})})]})]})}const Zt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function _n({toasts:t,onDismiss:s,onClickToast:o}){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(a=>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:Zt[a.type]||Zt.info},onClick:()=>{var i;(i=a.actions)!=null&&i.length||(o&&o(a),s(a.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(a.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:a.message}),a.actions&&a.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:a.actions.map((i,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 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:r=>{r.stopPropagation(),i.onClick(),s(a.id)},children:i.label},c))})]},a.id))})}const Rn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function Pn(t){const s=t.workspace||"";if(!s)return"";const o=s.split(/[/\\]/).filter(Boolean);return o.length>0?o[o.length-1]:s}function Ln(t,s,o,a){var c;const i={};if(o)for(const r of o){const x=r;if(x.type==="adhdev-daemon"||x.daemonMode){const u=x.machine||{},h=x.machineNickname,d=u.hostname||((c=x.system)==null?void 0:c.hostname)||"",l=h||(d&&d!=="Unknown"?d.replace(/\.local$/,""):null)||`Machine ${(x.id||"").substring(0,6)}`;i[x.id]=l}}return t.flatMap(r=>{var S,O,F,R,T;const x=[],u=r.daemonId&&i[r.daemonId]||void 0,h=r.daemonId||((S=r.id)==null?void 0:S.split(":")[0])||r.id,d=a?a[h]||"new":void 0,l=Pn(r),v=Le(r.type),f=r.agentStreams,p=Array.isArray(f)?f.map(D=>({...D,activeModal:D.activeModal??void 0})):[],A=Rn(r),$=r.activeChat||{title:""},w=$.title&&String($.title).trim()?String($.title).trim():"";if(A){const D=Rt(r.type),I=(O=r.agents)==null?void 0:O[0],N=(F=r.activeChat)==null?void 0:F.activeModal,ne=N&&Array.isArray(N.buttons)&&N.buttons.length>0,_=(R=r.activeChat)==null?void 0:R.status,V=_==="generating"||_==="loading"||_&&_.toLowerCase()==="thinking",y=ne||_==="waiting_approval"?"waiting_approval":V?"working":(I==null?void 0:I.status)||"idle",Z=r.activeChat||{title:"",messages:[]};let le=Z.title&&String(Z.title).trim()?String(Z.title).trim():"";const X=(T=r.activeChat)==null?void 0:T.id,J=r.chats;if(X&&Array.isArray(J)&&J.length>0){const ce=J.find(P=>P.id===X||P.id&&String(P.id)===String(X));ce!=null&&ce.title&&String(ce.title).trim()&&(le=String(ce.title).trim())}const K=Z.messages||[],ae=s[r.id]||[],se=new Map;K.filter(ce=>ce.role==="user").forEach(ce=>{se.set(ce.content,(se.get(ce.content)||0)+1)});const ie=ae.filter(ce=>{const P=se.get(ce.content)||0;return P>0?(se.set(ce.content,P-1),!1):!0});x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:Be(r)?r.mode||"terminal":"chat",agentName:D,agentType:Be(r)||We(r)?r.cliType||r.acpType||r.type:(I==null?void 0:I.type)||"ide-native",status:y,title:le,messages:[...K,...ie],ideType:r.cliType||r.acpType||r.type,workspaceName:l,displayPrimary:le||l||(Be(r)||We(r)?"Terminal":D),displaySecondary:v,cdpConnected:r.cdpConnected,modalButtons:ne?N.buttons:void 0,modalMessage:ne?N.message:void 0,streamSource:"native",tabKey:r.id,machineName:u,connectionState:d})}if(A&&(Be(r)||We(r)))return x;for(const D of p){const I=D.activeModal&&Array.isArray(D.activeModal.buttons)&&D.activeModal.buttons.length>0,N=I?"waiting_approval":D.status==="streaming"?"working":D.status,ne=`${r.id}:${D.agentType}`,_=D.messages||[],V=s[ne]||[],Y=new Map;_.filter(Z=>Z.role==="user").forEach(Z=>{Y.set(Z.content,(Y.get(Z.content)||0)+1)});const y=V.filter(Z=>{const le=Y.get(Z.content)||0;return le>0?(Y.set(Z.content,le-1),!1):!0});x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:"chat",agentName:D.agentName,agentType:D.agentType,status:N,title:"",messages:[..._,...y],ideType:D.agentType,workspaceName:l,displayPrimary:w||l||D.agentName,displaySecondary:`${v}·${D.agentName}`,cdpConnected:r.cdpConnected,modalButtons:I?D.activeModal.buttons:void 0,modalMessage:I?D.activeModal.message:void 0,streamSource:"agent-stream",tabKey:ne,machineName:u,connectionState:d})}return x.length===0&&x.push({ideId:r.id,daemonId:r.daemonId||void 0,mode:"chat",agentName:Rt(r.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:r.type,workspaceName:l,displayPrimary:l||v,displaySecondary:v,cdpConnected:r.cdpConnected,streamSource:"native",tabKey:r.id,connectionState:d}),x})}function Dn(t,s){var x,u,h,d;const o=[],{daemonId:a,existingDaemon:i,timestamp:c}=s,r=c||t.timestamp||Date.now();o.push({...i||{},id:a,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:r,...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},..."system"in t&&{system:t.system},..."hostname"in t&&{hostname:t.hostname},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:t.managedIdes.some(l=>l.cdpConnected),managedIdeIds:t.managedIdes.map(l=>`${a}:ide:${l.instanceId}`),managedCliIds:t.managedClis.map(l=>l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`),managedAcpIds:t.managedAcps.map(l=>l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`)});for(const l of t.managedIdes)o.push({id:`${a}:ide:${l.instanceId}`,type:l.ideType,ideType:l.ideType,version:l.ideVersion,status:l.cdpConnected?"online":"detected",daemonId:a,instanceId:l.instanceId,workspace:l.workspace,terminals:l.terminals,agents:l.aiAgents,activeChat:l.activeChat,chats:l.chats,agentStreams:l.agentStreams,cdpConnected:l.cdpConnected,currentModel:l.currentModel,currentPlan:l.currentPlan,currentAutoApprove:l.currentAutoApprove,timestamp:r});for(const l of t.managedClis){const v=l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`;o.push({id:v,type:l.cliType,ideType:l.cliType,agentType:l.cliType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.cliName,mode:l.mode||"terminal",workspace:l.workspace,activeChat:l.activeChat,agentStreams:[{agentType:l.cliType,agentName:l.cliName,extensionId:"cli-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((x=l.activeChat)==null?void 0:x.messages)||[],inputContent:"",activeModal:(u=l.activeChat)==null?void 0:u.activeModal}],timestamp:r,_isCli:!0})}for(const l of t.managedAcps){const v=l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`;o.push({id:v,type:l.acpType,ideType:l.acpType,agentType:l.acpType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.acpName,mode:"chat",workspace:l.workspace,activeChat:l.activeChat,currentModel:l.currentModel,currentPlan:l.currentPlan,acpConfigOptions:l.acpConfigOptions,acpModes:l.acpModes,agentStreams:[{agentType:l.acpType,agentName:l.acpName,extensionId:"acp-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((h=l.activeChat)==null?void 0:h.messages)||[],inputContent:"",activeModal:(d=l.activeChat)==null?void 0:d.activeModal}],timestamp:r,_isAcp:!0})}return o}const vs="adhdev_notification_prefs",Qt={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function Bn(){try{const t=localStorage.getItem(vs);if(t){const s=JSON.parse(t);return{...Qt,...s}}}catch{}return{...Qt}}function Wn(t){try{localStorage.setItem(vs,JSON.stringify(t))}catch{}}let Ye=Bn(),bt=[];function On(){bt.forEach(t=>t())}function Kn(t){Ye={...Ye,...t},Wn(Ye),On()}function Fn(){const[,t]=n.useState(0);n.useEffect(()=>{const o=()=>t(a=>a+1);return bt.push(o),()=>{bt=bt.filter(a=>a!==o)}},[]);const s=n.useCallback(o=>{Kn(o)},[]);return[{...Ye},s]}function it(t){if(!Ye.globalEnabled)return!1;switch(t){case"disconnect":return Ye.disconnectAlert;case"completion":return Ye.completionAlert;case"approval":return Ye.approvalAlert;case"browser":return Ye.browserNotifications;default:return!0}}const Hn={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function zn(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function ws(){return"Notification"in window&&Notification.permission==="granted"}let qe=null;async function Un(){if(qe!==null)return qe;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return qe=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(qe=!!await t.pushManager.getSubscription(),qe):(qe=!1,!1)}catch{return qe=!1,!1}}function Pt(t,s,o){if(ws())try{const a=new Notification(t,{body:s,icon:"/otter-logo.png",tag:o||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>a.close(),8e3),a.onclick=()=>{window.focus(),a.close()}}catch{}}function Yn(t,s={}){const o={...Hn,...s},a=n.useRef(new Map),i=n.useRef(0),c=n.useRef(null);n.useEffect(()=>{Un().then(x=>{c.current=x})},[]);const r=n.useCallback((x,u,h)=>{const d=Date.now();d-i.current<o.throttleMs||(i.current=d,Pt(x,u,h))},[o.throttleMs]);n.useEffect(()=>{var x;if(!(!o.enabled||!ws())&&it("browser")&&c.current!==!0){if(document.hasFocus()){for(const u of t)a.current.set(u.id,u.status||"idle");return}for(const u of t){const h=a.current.get(u.id),d=u.status||"idle",l=u.name||u.id;if(o.onApproval&&it("approval")&&d==="waiting_approval"&&h!=="waiting_approval"){const v=((x=u.activeModal)==null?void 0:x.message)||"Action requires your approval";r(`🔔 ${l} — Approval needed`,v.slice(0,120),`approval-${u.id}`)}o.onComplete&&it("completion")&&h==="generating"&&d==="idle"&&r(`✅ ${l} — Task complete`,"Agent has finished working",`complete-${u.id}`),o.onError&&d==="error"&&h!=="error"&&r(`⚠️ ${l} — Error`,"Agent encountered an error",`error-${u.id}`),a.current.set(u.id,d)}}},[t,o.enabled,o.onApproval,o.onComplete,o.onError,r])}class Vn{constructor(){Me(this,"dedupMap",new Map);Me(this,"DEDUP_WINDOW_MS",5e3);Me(this,"DEDUP_MAX_SIZE",50);Me(this,"DEDUP_CLEANUP_AGE_MS",1e4);Me(this,"toastCallbacks",[]);Me(this,"systemMessageCallbacks",[]);Me(this,"clearSystemMessageCallbacks",[]);Me(this,"resolveActionFn",null);Me(this,"viewRequestRespondFn",null);Me(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(o=>o!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(o=>o!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(o=>o!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const o of this.toastCallbacks)o(s)}emitSystemMessage(s,o){for(const a of this.systemMessageCallbacks)a(s,o)}emitClearSystemMessage(s,o){for(const a of this.clearSystemMessageCallbacks)a(s,o)}isDuplicate(s){const o=Date.now(),a=this.dedupMap.get(s)||0;if(o-a<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,o),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,c]of this.dedupMap)o-c>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(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(i)return i}let o;if(s.ideId&&(o=this.ides.find(i=>i.id===s.ideId)),!o&&s.instanceId&&(o=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),o){const i=o.daemonId;if(i){const c=this.ides.find(r=>r.id===i&&r.type==="adhdev-daemon");if(c)return c}}const a=this.ides.filter(i=>i.type==="adhdev-daemon");return a.length===1?a[0]:null}resolveRouteId(s,o){for(const a of this.ides)if(a.id.startsWith(s)&&(!o||o===a.type))return a.id;return s}handleRawEvent(s,o){var u,h,d;const a=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;if(!s.ideId&&s.instanceId){for(const l of this.ides)if(l.id.endsWith(`:ide:${s.instanceId}`)||l.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=l.id;break}}let i=Le(s.ideType||"");const c=this.resolveOwningDaemon(s);if(c){const l=c.machineNickname||((u=c.machine)==null?void 0:u.hostname);l&&(i=s.ideType==="adhdev-daemon"?l:`${l}/${i}`)}let r="",x="info";if(s.event==="agent:generating_completed"){const l=s.duration?` (${s.duration}s)`:"";r=`✅ ${i} agent task completed${l}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${l}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(r=`⚡ ${i} approval needed`,x="warning",s.ideId){const l=s.modalMessage||"Approval requested",v=(h=s.modalButtons)!=null&&h.length?s.modalButtons.map(f=>`[${f}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${l}
39
+ ${v}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((d=s.modalButtons)!=null&&d.length)&&this.resolveActionFn){const l=s.ideId,v=s.agentType||s.ideType||"",f=s.ideType||"",p=s.modalButtons,A=F=>F.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),$=this.resolveActionFn,w=p.map((F,R)=>{const T=A(F).toLowerCase(),D=/^(run|approve|accept|yes|allow|always)/.test(T),I=/^(reject|deny|delete|remove|abort|cancel|no)/.test(T);return{label:A(F),variant:D?"primary":I?"danger":"default",onClick:()=>{const N=this.resolveRouteId(l,v),ne=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(T);$(N,"resolve_action",{action:ne?"approve":"reject",button:F,buttonIndex:R,agentType:v,ideType:f})}}}),S=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:r,O=Date.now();this.emitToast({id:O,message:S,type:x,timestamp:O,ideId:l,actions:w,duration:15e3}),r=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";r=`⚠️ ${i} agent is taking a long time${l}`,x="warning",it("browser")&&!document.hasFocus()&&Pt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",v=s.requestId,f=s.orgId;if(r=`👁️ ${l} wants to view your session`,x="warning",v&&f&&this.viewRequestRespondFn){const p=this.viewRequestRespondFn,A=Date.now(),$=[{label:"Approve",variant:"primary",onClick:()=>{p(f,v,"approve").catch(w=>console.error("[EventManager] approve view request failed:",w))}},{label:"Decline",variant:"danger",onClick:()=>{p(f,v,"reject").catch(w=>console.error("[EventManager] reject view request failed:",w))}}];this.emitToast({id:A,message:r,type:x,timestamp:A,actions:$,duration:3e4}),r=""}it("browser")&&!document.hasFocus()&&Pt("👁️ View Request",`${l} wants to view your session`,`view-request-${v}`)}else s.event==="team:view_request_approved"?(r="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(r=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(r){const l=Date.now();this.emitToast({id:l,message:r,type:x,timestamp:l,ideId:s.ideId,duration:5e3})}}}const tt=new Vn;function xt(...t){return Ps(Ls(t))}function Ns({icon:t,title:s,subtitle:o,badge:a,actions:i,className:c}){return e.jsxs("div",{className:xt("dashboard-header",c),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,a&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[a.count!==void 0?a.count:""," ",a.text]})]}),o&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:o})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function st({title:t,icon:s,description:o,accentColor:a,className:i,children:c}){return e.jsxs("div",{className:xt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",a&&"border-l-[3px]",i),style:a?{borderLeftColor:a}:void 0,children:[(t||o)&&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]}),o&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:o})]}),c]})}function Xn({icon:t,title:s,description:o,action:a,className:i}){return e.jsxs("div",{className:xt("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:o}),a]})}const qn={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"},Gn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Jn({status:t,label:s,className:o}){const a=s||t;return e.jsxs("span",{className:xt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",qn[t],o),children:[e.jsx("span",{className:xt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Gn[t])}),a]})}function Zn(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function es(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Tt(t){return t==="system"?Zn():t}function Qn(){const[t,s]=n.useState(es),[o,a]=n.useState(()=>Tt(es()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",o)},[o]),n.useEffect(()=>{const r=window.matchMedia("(prefers-color-scheme: light)"),x=u=>{t==="system"&&a(u.matches?"light":"dark")};return r.addEventListener("change",x),()=>r.removeEventListener("change",x)},[t]);const i=n.useCallback(r=>{s(r),a(Tt(r));try{localStorage.setItem("theme",r)}catch{}},[]),c=n.useCallback(()=>{s(r=>{const x=r==="dark"?"light":r==="light"?"system":"dark";a(Tt(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:o,preference:t,setPreference:i,cycleTheme:c,isDark:o==="dark"}}function nt({label:t,description:s,checked:o,disabled:a,onChange:i,extra:c}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c,e.jsx("input",{type:"checkbox",checked:o,disabled:a,onChange:r=>i(r.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function er({onPrefChange:t}){const[s,o]=Fn(),a=(i,c)=>{o({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xn,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>a("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>a("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(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(mn,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>a("completionAlert",i)}),e.jsx(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(pn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>a("approvalAlert",i)}),e.jsx(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>a("disconnectAlert",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."})]})}const ks=[{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:"💚"}],Ss=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"}],Cs=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}];function tr({ides:t,emptyMessage:s,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i}){const c=t.filter(r=>r.type==="adhdev-daemon");return c.length===0?e.jsx(Xn,{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 setup' once, then 'adhdev daemon' to connect this machine."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(r=>e.jsx(nr,{ide:r,allIdes:t,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i},r.id))})}function ts({title:t,message:s,confirmLabel:o,confirmColor:a,onConfirm:i,onCancel:c}){const r=a==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return Ds.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,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:x=>x.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:c,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 ${r}`,children:o})]})]})}),document.body)}function sr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),a=[...ks,...Ss,...Cs].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return a?{icon:a.icon,name:a.name}:{icon:"📝",name:t}}function nr({ide:t,allIdes:s,sendDaemonCommand:o,onDisconnect:a,onRevokeToken:i}){var Z,le,X,J;const[c,r]=n.useState("idle"),[x,u]=n.useState(""),[h,d]=n.useState(null),[l,v]=n.useState("idle"),[f,p]=n.useState(""),A=t,$=A.version||A.daemonVersion||null,w=((Z=A.machine)==null?void 0:Z.hostname)||((le=A.system)==null?void 0:le.hostname)||"",S=((X=A.machine)==null?void 0:X.platform)||((J=A.system)==null?void 0:J.platform)||"",O=A.machineNickname||(w==null?void 0:w.replace(/\.local$/,""))||"Machine",F=S==="win32"?"🪟":S==="darwin"?"🍎":"🐧",R=s.filter(K=>K.daemonId===t.id&&K.id.includes(":ide:")),T=s.filter(K=>K.daemonId===t.id&&K.id.includes(":cli:")),D=s.filter(K=>K.daemonId===t.id&&K.id.includes(":acp:")),I=A.p2p,N=async()=>{var K,ae,se;if(o){r("upgrading"),u("Installing latest version...");try{const ie=await o(t.id,"daemon_upgrade",{});(K=ie==null?void 0:ie.result)!=null&&K.upgraded||(ae=ie==null?void 0:ie.result)!=null&&ae.success?(r("done"),u(`Upgraded to v${ie.result.version||"latest"}. Daemon is restarting...`)):(r("error"),u(((se=ie==null?void 0:ie.result)==null?void 0:se.error)||"Upgrade failed"))}catch(ie){r("error"),u((ie==null?void 0:ie.message)||"Connection lost during upgrade")}}},ne=async()=>{if(d(null),!!a){v("loading");try{await a(t.id),v("done"),p("Machine disconnected.")}catch(K){v("error"),p((K==null?void 0:K.message)||"Failed to disconnect")}}},_=async()=>{if(d(null),!!i){v("loading");try{await i(t.id),v("done"),p('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(K){v("error"),p((K==null?void 0:K.message)||"Failed to revoke token")}}},V="0.6.67",Y=!$||$!==V,y=R.length+T.length+D.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:F}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:O}),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),"…"]}),$&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${Y?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",$,!Y&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o&&Y&&e.jsx("button",{onClick:N,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${V}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${V}`}`}),a&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:l==="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:()=>d("revoke"),disabled:l==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Jn,{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:[I&&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 ${I.state==="connected"?"bg-green-400":I.state==="connecting"||I.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",I.state==="connected"?"connected":I.state==="connecting"||I.state==="new"?"connecting...":I.state||"off"]}),I.peers!==void 0&&I.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",I.peers," peer",I.peers!==1?"s":"",")"]})]}),I&&y>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),y>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[R.map(K=>{const ae=sr(K.type),se=K.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:ae.icon}),e.jsx("span",{children:ae.name}),se!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${se?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:se?"CDP connected":"CDP connecting..."})]},K.id)}),T.map(K=>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:K.cliName||"CLI"})]},K.id)),D.map(K=>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:K.cliName||"ACP"})]},K.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||l==="error"?"text-red-400":c==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:f||x})]}),h==="disconnect"&&e.jsx(ts,{title:"🔌 Disconnect Machine",message:`Disconnect "${O}" from ADHDev?
40
40
 
41
41
  This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
42
42
 
43
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:ne,onCancel:()=>d(null)}),h==="revoke"&&e.jsx(es,{title:"⚠️ Remove Machine",message:`Remove "${O}" from your account?
43
+ Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:ne,onCancel:()=>d(null)}),h==="revoke"&&e.jsx(ts,{title:"⚠️ Remove Machine",message:`Remove "${O}" from your account?
44
44
 
45
45
  This will:
46
46
  • Immediately disconnect the machine
47
47
  • Delete the machine registration
48
48
  • Require running "adhdev setup" again on that machine
49
49
 
50
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:_,onCancel:()=>d(null)})]})}const Qn=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function er(){const{preference:t,setPreference:s}=Vn();return e.jsx("div",{className:"flex gap-2",children:Qn.map(o=>e.jsxs("button",{onClick:()=>s(o.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===o.id?"bg-accent border-accent text-white":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,children:[e.jsx("span",{children:o.icon}),o.label]},o.id))})}const Lt={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Dt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},tr=[{id:"midnight",name:"Midnight",description:"Default violet theme",preview:{dark:{userBubble:"linear-gradient(135deg, #8b5cf6, #4f46e5)",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #7c3aed, #0ea5e9)",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"aurora",name:"Aurora",description:"Pink-orange gradient",preview:{dark:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",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"}}}],Cs="adhdev-chat-theme",Is="adhdev-chat-theme-custom";function bt(){return typeof window>"u"?"midnight":localStorage.getItem(Cs)||"midnight"}function De(t){try{const s=localStorage.getItem(Is);if(s){const o=JSON.parse(s);return{...t==="dark"?Lt:Dt,...o[t]}}}catch{}return t==="dark"?Lt:Dt}function ht(t,s){localStorage.setItem(Is,JSON.stringify({dark:t,light:s}))}function Ue(t,s){const o=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${o}, ${a}, ${i}, ${s})`}function ts(t,s){const o=Math.min(255,parseInt(t.slice(1,3),16)+s),a=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${o.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function Ze(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ue(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ue(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ue(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",Ue(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ue(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ts(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ts(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ue(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ue(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ue(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 ${Ue(t.accentColor,.12)}`),s.style.setProperty("--chat-container-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 sr(){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-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","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(o=>t.style.removeProperty(o))}function nr(t){if(localStorage.setItem(Cs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ct()?"dark":"light";Ze(De(s))}else sr()}function rr(){const t=bt();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ct()?"dark":"light";Ze(De(s))}}function ct(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ie({label:t,value:s,onChange:o}){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)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:a=>o(a.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:a=>{/^#[0-9a-fA-F]{0,6}$/.test(a.target.value)&&o(a.target.value)},style:{width:72,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 at({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 ar({dark:t,onColorsChange:s}){const o=t?"dark":"light",[a,i]=n.useState(()=>De(o));n.useEffect(()=>{i(De(o))},[o]);const c=n.useCallback((r,x)=>{i(u=>{const h={...u,[r]:x},l=De(o==="dark"?"light":"dark");return o==="dark"?ht(h,l):ht(l,h),Ze(h),s(h),h})},[o,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},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",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(at,{title:"App Background",children:[e.jsx(Ie,{label:"Background",value:a.bgPrimary,onChange:r=>c("bgPrimary",r)}),e.jsx(Ie,{label:"Surface",value:a.bgSecondary,onChange:r=>c("bgSecondary",r)}),e.jsx(Ie,{label:"Card",value:a.surfacePrimary,onChange:r=>c("surfacePrimary",r)})]}),e.jsxs(at,{title:"App Text",children:[e.jsx(Ie,{label:"Primary",value:a.textPrimary,onChange:r=>c("textPrimary",r)}),e.jsx(Ie,{label:"Secondary",value:a.textSecondary,onChange:r=>c("textSecondary",r)}),e.jsx(Ie,{label:"Muted",value:a.textMuted,onChange:r=>c("textMuted",r)})]}),e.jsxs(at,{title:"Borders & Accent",children:[e.jsx(Ie,{label:"Border subtle",value:a.borderSubtle,onChange:r=>c("borderSubtle",r)}),e.jsx(Ie,{label:"Border default",value:a.borderDefault,onChange:r=>c("borderDefault",r)}),e.jsx(Ie,{label:"Accent",value:a.accentColor,onChange:r=>c("accentColor",r)})]})]}),e.jsxs("div",{children:[e.jsxs(at,{title:"Chat Bubbles",children:[e.jsx(Ie,{label:"User bubble",value:a.userBubble,onChange:r=>c("userBubble",r)}),e.jsx(Ie,{label:"User text",value:a.userText,onChange:r=>c("userText",r)}),e.jsx(Ie,{label:"Agent bubble",value:a.assistantBubble,onChange:r=>c("assistantBubble",r)}),e.jsx(Ie,{label:"Agent text",value:a.assistantText,onChange:r=>c("assistantText",r)})]}),e.jsxs(at,{title:"Chat Layout",children:[e.jsx(Ie,{label:"Chat BG",value:a.containerBg,onChange:r=>c("containerBg",r)}),e.jsx(Ie,{label:"Send button",value:a.sendButton,onChange:r=>c("sendButton",r)}),e.jsx(Ie,{label:"Input border",value:a.inputBorder,onChange:r=>c("inputBorder",r)}),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)",minWidth:110},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:a.bubbleRadius,onChange:r=>c("bubbleRadius",Number(r.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:[a.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const r=t?Lt:Dt,u=De(t?"light":"dark");t?ht(r,u):ht(u,r),i(r),Ze(r),s(r)},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 or(){const[t,s]=n.useState(bt),[o,a]=n.useState(!0),[i,c]=n.useState(()=>De("dark"));n.useEffect(()=>{a(ct());const u=new MutationObserver(()=>{const l=ct();a(l),bt()==="custom"&&Ze(De(l?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const h=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const l=ct();a(l),bt()==="custom"&&Ze(De(l?"dark":"light"))};return h.addEventListener("change",d),()=>{u.disconnect(),h.removeEventListener("change",d)}},[]),n.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&Ze(De(o?"dark":"light"))},[]),n.useEffect(()=>{c(De(o?"dark":"light"))},[o]);const r=u=>{s(u),nr(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},x=[...tr,{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:x.map(u=>{const h=t===u.id,d=o?u.preview.dark:u.preview.light,l=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>r(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:h?"var(--bg-glass-hover)":"var(--bg-glass)",border:h?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:h?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.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:d.userBubble,color:l},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:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[h&&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:u.id==="custom"?"🎨 Custom":u.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&e.jsx(ar,{dark:o,onColorsChange:u=>c(u)})]})}const Bt="adhdev-accent-color",ir=[{name:"Violet",color:"#8b5cf6"},{name:"Indigo",color:"#6366f1"},{name:"Blue",color:"#3b82f6"},{name:"Cyan",color:"#06b6d4"},{name:"Emerald",color:"#10b981"},{name:"Rose",color:"#f43f5e"},{name:"Orange",color:"#f97316"},{name:"Amber",color:"#f59e0b"}],xt="#8b5cf6";function cr(t){const s=parseInt(t.slice(1,3),16)/255,o=parseInt(t.slice(3,5),16)/255,a=parseInt(t.slice(5,7),16)/255,i=Math.max(s,o,a),c=Math.min(s,o,a);let r=0,x=0;const u=(i+c)/2;if(i!==c){const h=i-c;switch(x=u>.5?h/(2-i-c):h/(i+c),i){case s:r=((o-a)/h+(o<a?6:0))/6;break;case o:r=((a-s)/h+2)/6;break;case a:r=((s-o)/h+4)/6;break}}return{h:Math.round(r*360),s:Math.round(x*100),l:Math.round(u*100)}}function ss(t,s){const{h:o,s:a,l:i}=cr(t),c=Math.min(100,i+s);return`hsl(${o}, ${a}%, ${c}%)`}function yt(t,s){const o=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${o}, ${a}, ${i}, ${s})`}function ns(){return typeof window>"u"?xt:localStorage.getItem(Bt)||xt}function lr(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",ss(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${ss(t,20)})`),s.style.setProperty("--border-accent",yt(t,.4)),s.style.setProperty("--nav-active-bg",yt(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${yt(t,.06)}`)}function dr(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(o=>t.style.removeProperty(o))}function ur(t){t===xt?(localStorage.removeItem(Bt),dr()):(localStorage.setItem(Bt,t),lr(t))}function xr(){const[t,s]=n.useState(ns),[o,a]=n.useState("");n.useEffect(()=>{s(ns())},[]);const i=c=>{s(c),ur(c)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:ir.map(c=>{const r=t===c.color;return e.jsx("button",{onClick:()=>i(c.color),title:c.name,style:{width:36,height:36,borderRadius:10,background:c.color,border:r?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:r?"scale(1.1)":"scale(1)",boxShadow:r?`0 0 12px ${yt(c.color,.4)}`:"none"},children:r&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},c.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:c=>i(c.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:o||t,onChange:c=>{a(c.target.value),/^#[0-9a-fA-F]{6}$/.test(c.target.value)&&i(c.target.value)},onBlur:()=>a(""),style:{width:80,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}}),t!==xt&&e.jsx("button",{onClick:()=>i(xt),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const Ms="adhdev_hiddenTabs";function mr(){try{const t=localStorage.getItem(Ms);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ot(t){try{localStorage.setItem(Ms,JSON.stringify([...t]))}catch{}}function pr(){const[t,s]=n.useState(mr),o=n.useCallback(u=>{s(h=>{const d=new Set(h);return d.has(u)?d.delete(u):d.add(u),ot(d),d})},[]),a=n.useCallback(u=>{s(h=>{if(h.has(u))return h;const d=new Set(h);return d.add(u),ot(d),d})},[]),i=n.useCallback(u=>{s(h=>{if(!h.has(u))return h;const d=new Set(h);return d.delete(u),ot(d),d})},[]),c=n.useCallback((u,h)=>{s(d=>{const l=new Set(d);for(const j of h)l.add(j);return ot(l),l})},[]),r=n.useCallback((u,h)=>{s(d=>{const l=new Set(d);for(const j of h)l.delete(j);return ot(l),l})},[]),x=n.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:o,hideTab:a,showTab:i,hideAllForDaemon:c,showAllForDaemon:r,isHidden:x}}function Ts({sendDaemonCommand:t,activeConv:s,ides:o,updateIdeChats:a,setToasts:i,setLocalUserMessages:c,setClearedTabs:r,setActionLogs:x,pinTab:u,isStandalone:h}){const[d,l]=n.useState(""),[j,f]=n.useState(!1),[p,A]=n.useState(!1),[$,w]=n.useState(!1),S=n.useCallback(_=>_?Be(_)||We(_)?{agentType:_.agentType||_.ideType}:_.streamSource==="agent-stream"?{agentType:_.agentType}:{}:{},[]),O=n.useCallback(async()=>{if(!s)return;const _=d.trim();if(!_)return;const X=s.ideId,Y=s.tabKey;l(""),u(Y,[100,500,1500,3e3]);const y=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,Z={role:"user",content:_,timestamp:Date.now(),_localId:y};c(le=>({...le,[Y]:[...le[Y]||[],Z]}));try{const le=X||s.daemonId||"";if(!le)return;await t(le,"send_chat",{message:_,text:_,...S(s)}),setTimeout(()=>{const V=Date.now()-6e4;c(J=>{const K=J[Y];if(!K)return J;const ae=K.filter(se=>se.timestamp>V);return ae.length===K.length?J:{...J,[Y]:ae}})},6e4)}catch(le){console.error("Send failed",le),l(_),c(V=>({...V,[Y]:(V[Y]||[]).filter(J=>J._localId!==y)}))}},[s,d,t,c,u,S]),F=n.useCallback(async()=>{if(s)try{h?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(_){console.error("Relaunch failed",_)}},[s,h,t]),R=n.useCallback(async _=>{try{await t("standalone","launch_ide",{ideType:_,enableCdp:!0})}catch(X){console.error("Launch failed",X)}},[t]),T=n.useCallback(async _=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",_),x(X=>[...X,{ideId:s.tabKey,text:`🖱️ **${_}** clicked`,timestamp:Date.now()}]);try{const Y=(s.modalButtons||[]).indexOf(_),y=_.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),Z=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y),le=s.ideId||s.daemonId||"";(await t(le,"resolve_action",{button:_,action:Z?"approve":"reject",...Y>=0&&{buttonIndex:Y},...S(s)})).success||x(J=>[...J,{ideId:s.tabKey,text:`⚠️ **${_}** failed — button not found`,timestamp:Date.now()}])}catch(X){console.error("[ModalButton] Error:",X),x(Y=>[...Y,{ideId:s.tabKey,text:`❌ **${_}** error`,timestamp:Date.now()}])}}},[s,t,x,S]),D=n.useCallback(async(_,X)=>{try{const Y=_||(s==null?void 0:s.daemonId)||"",y=await t(Y,"switch_chat",{id:X,sessionId:X,...S(s)}),Z=y==null?void 0:y.result;(y==null?void 0:y.success)===!0||Z==="switched"||Z==="switched-by-title"||(Z===!1||Z==="not_found"?i(V=>[...V,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof Z=="string"&&Z.startsWith("error:")?i(V=>[...V,{id:Date.now(),message:`⚠️ Switch error: ${Z}`,type:"warning",timestamp:Date.now()}]):i(V=>[...V,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(Y){console.error("Switch failed",Y),i(y=>[...y,{id:Date.now(),message:`❌ Switch failed: ${Y.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,S]),I=n.useCallback(async()=>{if(!(!s||j)){f(!0);try{const _=s.ideId||s.daemonId||"";await t(_,"new_chat",{...S(s)}),r(X=>({...X,[s.tabKey]:Date.now()})),c(X=>({...X,[s.tabKey]:[]}))}catch(_){console.error("New chat failed",_)}finally{f(!1)}}},[s,j,t,r,c,S]),N=n.useCallback(async()=>{if(!s||$)return;w(!0);const _=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u(_,[200,1500,3e3])}catch(X){console.error("Focus agent failed",X)}finally{w(!1)}},[s,$,t,u]),ne=n.useCallback(async()=>{var _;if(!(!s||p)){A(!0);try{const X=s.ideId||s.daemonId||"",Y=await t(X,"list_chats",{forceExpand:!0,...S(s)}),y=(Y==null?void 0:Y.chats)||((_=Y==null?void 0:Y.result)==null?void 0:_.chats);Y!=null&&Y.success&&Array.isArray(y)&&a(s.ideId,y)}catch(X){console.error("Refresh history failed",X)}finally{A(!1)}}},[s,p,t,a,S]);return{agentInput:d,setAgentInput:l,isCreatingChat:j,isRefreshingHistory:p,isFocusingAgent:$,handleSendChat:O,handleRelaunch:F,handleLaunchIde:R,handleModalButton:T,handleSwitchSession:D,handleNewChat:I,handleFocusAgent:N,handleRefreshHistory:ne}}const Et={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 hr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function fr(){const[t,s]=n.useState("unix"),[o,a]=n.useState("powershell"),[i,c]=n.useState(!1),r=t==="unix"?"unix":o;n.useEffect(()=>{s(hr())},[]);const x=n.useCallback(()=>{navigator.clipboard.writeText(Et[r].cmd).catch(()=>{}),c(!0),setTimeout(()=>c(!1),2e3)},[r]);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/15 text-accent border border-accent/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/15 text-accent border border-accent/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 ${o==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${o==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:x,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Et[r].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Et[r].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted 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 && adhdev setup"})]})]})}function gr({conversations:t,ides:s,messageReceivedAt:o,actionLogs:a,ptyBuffers:i,screenshotMap:c,setScreenshotMap:r,sendDaemonCommand:x,updateIdeChats:u,setToasts:h,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:j,pinTab:f,isStandalone:p,userName:A,groupIndex:$,isFocused:w,onFocus:S,isSplitMode:O,numGroups:F,onMoveTab:R,onClose:T,onReceiveTab:D,style:I,detectedIdes:N,handleLaunchIde:ne,onActiveTabChange:_,initialActiveTabId:X,initialTabOrder:Y,onTabOrderChange:y,onHideTab:Z}){const{sendCommand:le}=Xe(),V=n.useRef(null),[J,K]=n.useState(!1),[ae,se]=n.useState(null),ie=n.useRef(0),ce=n.useRef(null),[P,v]=n.useState(X??null);n.useEffect(()=>{X&&X!==P&&v(X)},[X]);const[B,g]=n.useState(Y??[]),[U,z]=n.useState(null),de=n.useRef(null),we=n.useRef(null);n.useEffect(()=>{const C=new Set(t.map(E=>E.tabKey));g(E=>{const G=E.filter(b=>C.has(b)),q=t.filter(b=>!E.includes(b.tabKey)).map(b=>b.tabKey),Q=[...G,...q];return Q.length===E.length&&Q.every((b,m)=>b===E[m])?E:Q})},[t]);const je=U??B,ve=n.useMemo(()=>{if(je.length===0)return t;const C=new Map(je.map((E,G)=>[E,G]));return[...t].sort((E,G)=>{const q=C.get(E.tabKey)??999,Q=C.get(G.tabKey)??999;return q-Q})},[t,je]);n.useEffect(()=>{if(ve.length===0){v(null),_==null||_(null);return}P&&ve.some(C=>C.tabKey===P)||(v(ve[0].tabKey),_==null||_(ve[0].tabKey))},[ve,P]);const oe=ve.find(C=>C.tabKey===P),he=n.useCallback((C,E,G)=>{g(q=>{const Q=q.filter(k=>k!==C),b=Q.indexOf(E);if(b<0)return q;const m=G==="left"?b:b+1;return Q.splice(m,0,C),y==null||y(Q),Q}),z(null)},[y]),L=n.useCallback((C,E,G)=>{const Q=(B.length>0?B:t.map(k=>k.tabKey)).filter(k=>k!==C),b=Q.indexOf(E);if(b<0)return;const m=G==="left"?b:b+1;Q.splice(m,0,C),de.current=Q,z(Q)},[B,t]),me=Ts({sendDaemonCommand:x,activeConv:oe,ides:s,updateIdeChats:u,setToasts:h,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:j,pinTab:f,isStandalone:p}),[ge,fe]=n.useState(null);n.useEffect(()=>{if(!ge)return;const C=E=>{const G=document.querySelector("[data-pane-context-menu]");G&&G.contains(E.target)||fe(null)};return window.addEventListener("mousedown",C,!0),()=>window.removeEventListener("mousedown",C,!0)},[ge]);const Ce="adhdev-tab-shortcuts",$e=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Se,Ae]=n.useState(()=>{try{return JSON.parse(localStorage.getItem(Ce)||"{}")}catch{return{}}}),[Oe,_e]=n.useState(null),Re=n.useCallback(C=>{const E=[];C.metaKey&&E.push($e?"⌘":"Meta"),C.ctrlKey&&E.push("Ctrl"),C.altKey&&E.push($e?"⌥":"Alt"),C.shiftKey&&E.push($e?"⇧":"Shift");const G=C.key;if(["Control","Alt","Shift","Meta"].includes(G))return null;const q=G.length===1?G.toUpperCase():G;return E.push(q),E.join("+")},[$e]),Ee=n.useCallback((C,E)=>Re(C)===E,[Re]),W=n.useCallback(C=>{Ae(C),localStorage.setItem(Ce,JSON.stringify(C))},[]);n.useEffect(()=>{if(!Oe)return;const C=E=>{if(E.preventDefault(),E.stopPropagation(),E.key==="Escape"){_e(null);return}const G=Re(E);if(!G)return;const q={...Se};for(const[Q,b]of Object.entries(q))b===G&&delete q[Q];q[Oe]=G,W(q),_e(null)};return window.addEventListener("keydown",C,!0),()=>window.removeEventListener("keydown",C,!0)},[Oe,Se,W,Re]),n.useEffect(()=>{const C=E=>{if(!(!E.ctrlKey&&!E.metaKey&&!E.altKey)){for(const[G,q]of Object.entries(Se))if(Ee(E,q)&&ve.some(Q=>Q.tabKey===G)){E.preventDefault(),S(),v(G),_==null||_(G);return}}};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[Se,ve,S,_,Ee]);const[re,ee]=n.useState({}),xe=oe&&Be(oe)&&!We(oe),ye=xe?re[oe.tabKey]??oe.mode??"terminal":"chat";n.useEffect(()=>{const C=()=>{ie.current=0,K(!1),se(null)};return window.addEventListener("dragend",C),window.addEventListener("drop",C),()=>{window.removeEventListener("dragend",C),window.removeEventListener("drop",C)}},[]);const pe=n.useRef(null);return n.useEffect(()=>{const C=pe.current;if(!C)return;const E=G=>{Math.abs(G.deltaY)>Math.abs(G.deltaX)&&(G.preventDefault(),C.scrollLeft+=G.deltaY)};return C.addEventListener("wheel",E,{passive:!1}),()=>C.removeEventListener("wheel",E)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:S,style:{...I,outline:J?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx("div",{className:"flex items-center bg-bg-secondary border-b border-border-subtle shrink-0 gap-0",children:e.jsxs("div",{ref:pe,className:"flex-1 flex overflow-x-auto overflow-y-visible pt-1.5 pb-0 gap-1 select-none",style:{paddingLeft:8,paddingRight:4,scrollbarWidth:"none"},children:[ve.map((C,E)=>{const G=P===C.tabKey,q=C.status==="working"?"agent-tab-working":C.status==="waiting_approval"?"agent-tab-waiting":"",Q=C.connectionState==="failed"||C.connectionState==="closed",b=we.current===C.tabKey;return e.jsxs("div",{"data-tabkey":C.tabKey,className:`${q} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:m=>{we.current=C.tabKey,m.dataTransfer.setData("text/tab-key",C.tabKey),m.dataTransfer.effectAllowed="move"},onDragEnd:()=>{we.current=null;const m=de.current;m&&(g(m),y==null||y(m)),de.current=null,z(null),ie.current=0,K(!1)},onDragOver:m=>{const k=we.current;if(!(!k||k===C.tabKey)&&m.dataTransfer.types.includes("text/tab-key")){m.preventDefault(),m.stopPropagation();const M=m.currentTarget.getBoundingClientRect(),H=M.left+M.width/2,te=m.clientX<H?"left":"right";L(k,C.tabKey,te)}},onDrop:m=>{m.preventDefault(),m.stopPropagation();const k=m.dataTransfer.getData("text/tab-key");if(k&&k!==C.tabKey){const M=m.currentTarget.getBoundingClientRect(),H=M.left+M.width/2,te=m.clientX<H?"left":"right";ve.some(ue=>ue.tabKey===k)?he(k,C.tabKey,te):D&&D(k)}z(null)},onClick:m=>{m.stopPropagation(),S(),v(C.tabKey),_==null||_(C.tabKey),C.streamSource==="agent-stream"&&C.agentType&&le(C.ideId,"agent_stream_focus",{agentType:C.agentType}).catch(()=>{}),Be(C)&&setTimeout(()=>{var k,M;return(M=(k=V.current)==null?void 0:k.bumpResize)==null?void 0:M.call(k)},100)},onContextMenu:m=>{m.preventDefault(),fe({x:m.clientX,y:m.clientY,tabKey:C.tabKey})},onTouchStart:m=>{const k=m.touches[0],M=k.clientX,H=k.clientY;ce.current=setTimeout(()=>{fe({x:M,y:H,tabKey:C.tabKey})},600)},onTouchEnd:()=>{ce.current&&clearTimeout(ce.current)},onTouchMove:()=>{ce.current&&clearTimeout(ce.current)},style:{background:G?"var(--bg-primary)":"var(--bg-glass)",borderTop:G?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:G?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:G?"1px solid var(--border-subtle)":"1px solid transparent",opacity:b?.4:Q?G?.6:.3:G?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[C.status==="working"?e.jsx("div",{className:"tab-spinner"}):C.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):Q?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):C.connectionState==="connected"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-green-400",children:"●"}):e.jsx("span",{className:"text-[8px] px-[5px] py-px text-text-muted animate-pulse",children:"○"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-bold whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"10ch"},title:C.displayPrimary,children:C.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:Q?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[C.displaySecondary,C.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",C.machineName]})]})]})})]}),Se[C.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${Se[C.tabKey]}`,children:Se[C.tabKey]})]},C.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:C=>{C.dataTransfer.types.includes("text/tab-key")&&(ie.current++,K(!0))},onDragOver:C=>{if(C.dataTransfer.types.includes("text/tab-key")&&(C.preventDefault(),F<4&&R)){const E=C.currentTarget.getBoundingClientRect(),G=C.clientX-E.left;se(G<E.width/2?"left":"right")}},onDragLeave:()=>{ie.current--,ie.current<=0&&(ie.current=0,K(!1),se(null))},onDrop:C=>{ie.current=0,K(!1);const E=C.dataTransfer.getData("text/tab-key"),G=E?t.some(Q=>Q.tabKey===E):!1,q=ae;if(se(null),z(null),!!E){if(C.preventDefault(),q&&R&&F<4){R(E,q==="left"?"split-left":"split-right");return}G?g(Q=>{const b=Q.filter(m=>m!==E);return b.push(E),y==null||y(b),b}):D&&D(E)}},children:[J&&R&&F<4&&e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:ae==="left"?"rgba(139, 92, 246, 0.18)":"rgba(139, 92, 246, 0.08)",boxShadow:ae==="left"?"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:"Split Left"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:ae==="right"?"rgba(139, 92, 246, 0.18)":"rgba(139, 92, 246, 0.08)",boxShadow:ae==="right"?"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:"Split Right"})})]}),oe?e.jsxs(e.Fragment,{children:[xe&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-bg-primary border-b border-border-subtle shrink-0 gap-3",children:[e.jsxs("div",{className:"flex bg-bg-secondary rounded items-center p-0.5 border border-border-subtle text-[11px] shadow-sm",children:[e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${ye==="chat"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{ye!=="chat"&&ee(C=>({...C,[oe.tabKey]:"chat"}))},children:"💬 Chat"}),e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${ye==="terminal"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{ye!=="terminal"&&ee(C=>({...C,[oe.tabKey]:"terminal"}))},children:"🖥 Terminal"})]}),ye==="terminal"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(!V.current)return;const C=i.current.get(oe.tabKey);if(C&&C.length>0)for(const E of C)V.current.write(E);requestAnimationFrame(()=>{requestAnimationFrame(()=>{var E;(E=V.current)==null||E.bumpResize()})})},title:"Refresh terminal (replay buffer + TUI redraw)",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-bg-secondary text-text-secondary border border-border-subtle cursor-pointer leading-none",children:"↺"}),e.jsx("button",{onClick:async()=>{var G;const C=(G=oe.ideId)!=null&&G.includes(":cli:")?oe.ideId.split(":cli:")[1]:oe.ideType||oe.agentType||"";if(!window.confirm(`Stop ${C}?
51
- This will terminate the CLI process.`))return;const E=oe.ideId||oe.daemonId||"";try{await le(E,"stop_cli",{cliType:C})}catch(q){console.error("Stop CLI failed:",q)}},title:"Stop CLI process",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-red-500/[0.08] text-red-400 border border-red-500/30 cursor-pointer leading-none font-semibold",children:"■ Stop"})]})]}),e.jsx(hn,{activeConv:oe,onModalButton:me.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!xe&&!We(oe)&&c[oe.ideId]?e.jsx(pn,{screenshotUrl:c[oe.ideId],mode:"preview",onDismiss:()=>{const C={...c};delete C[oe.ideId],r(C)}}):!xe&&!We(oe)&&oe.cdpConnected===!1?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(Ot,{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:me.handleRelaunch,children:"Relaunch with CDP"})]}):null}),ye==="terminal"?e.jsx(gn,{activeConv:oe,ptyBuffers:i,terminalRef:V,agentInput:me.agentInput,setAgentInput:me.setAgentInput,handleSendChat:me.handleSendChat}):e.jsx(bs,{activeConv:oe,ides:s,agentInput:me.agentInput,setAgentInput:me.setAgentInput,handleSendChat:me.handleSendChat,handleFocusAgent:me.handleFocusAgent,isFocusingAgent:me.isFocusingAgent,messageReceivedAt:o,actionLogs:a,userName:A})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!O&&N&&ne?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:p?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!p&&e.jsx(fr,{}),p&&N&&N.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:N.map(C=>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:()=>ne&&ne(C.type),children:[e.jsx(cn,{size:14,className:"opacity-70"})," Launch ",C.name]},C.type))})]}),!p&&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:O?"Move a tab here to view":"No active agent"})})]}),ge&&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:ge.x,top:ge.y},children:[R&&$>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"left"),fe(null)},children:"← Move to Left Group"}),R&&$<F-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"right"),fe(null)},children:"Move to Right Group →"}),R&&F<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"split-left"),fe(null)},children:"⇤ Split Left"}),R&&F<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"split-right"),fe(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:C=>{C.stopPropagation(),_e(ge.tabKey),fe(null)},children:["⌨ ",Se[ge.tabKey]?`Change shortcut (${Se[ge.tabKey]})`:"Set shortcut"]}),Se[ge.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 C={...Se};delete C[ge.tabKey],W(C),fe(null)},children:"✕ Remove shortcut"}),Z&&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:()=>{Z(ge.tabKey),fe(null)},children:"🚫 Hide from Dashboard"})]}),!R&&!Z&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),Oe&&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:C=>C.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. ",$e?"⌘+1":"Ctrl+1",", ",$e?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const At=[{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 && adhdev setup"}];function br({onClose:t}){const[s,o]=n.useState(0),a=At[s],i=s===At.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:c=>{c.target===c.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:At.map((c,r)=>e.jsx("div",{style:{width:r===s?24:8,height:8,borderRadius:4,background:r===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},r))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:a.visual||a.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:a.icon})," ",a.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:a.desc}),a.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:"$"}),a.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():o(c=>c+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:`
50
+ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:_,onCancel:()=>d(null)})]})}const rr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ar(){const{preference:t,setPreference:s}=Qn();return e.jsx("div",{className:"flex gap-2",children:rr.map(o=>e.jsxs("button",{onClick:()=>s(o.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===o.id?"bg-accent border-accent text-white":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,children:[e.jsx("span",{children:o.icon}),o.label]},o.id))})}const Lt={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Dt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},or=[{id:"midnight",name:"Midnight",description:"Default violet theme",preview:{dark:{userBubble:"linear-gradient(135deg, #8b5cf6, #4f46e5)",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #7c3aed, #0ea5e9)",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"aurora",name:"Aurora",description:"Pink-orange gradient",preview:{dark:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",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"}}}],Is="adhdev-chat-theme",Ms="adhdev-chat-theme-custom";function yt(){return typeof window>"u"?"midnight":localStorage.getItem(Is)||"midnight"}function De(t){try{const s=localStorage.getItem(Ms);if(s){const o=JSON.parse(s);return{...t==="dark"?Lt:Dt,...o[t]}}}catch{}return t==="dark"?Lt:Dt}function ft(t,s){localStorage.setItem(Ms,JSON.stringify({dark:t,light:s}))}function ze(t,s){const o=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${o}, ${a}, ${i}, ${s})`}function ss(t,s){const o=Math.min(255,parseInt(t.slice(1,3),16)+s),a=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${o.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function Ze(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",ze(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",ze(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",ze(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",ze(t.borderSubtle,.5)),s.style.setProperty("--border-default",ze(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ss(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ss(t.accentColor,40)})`),s.style.setProperty("--border-accent",ze(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",ze(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${ze(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 ${ze(t.accentColor,.12)}`),s.style.setProperty("--chat-container-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 ir(){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-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","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(o=>t.style.removeProperty(o))}function cr(t){if(localStorage.setItem(Is,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ct()?"dark":"light";Ze(De(s))}else ir()}function lr(){const t=yt();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ct()?"dark":"light";Ze(De(s))}}function ct(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ie({label:t,value:s,onChange:o}){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)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:a=>o(a.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:a=>{/^#[0-9a-fA-F]{0,6}$/.test(a.target.value)&&o(a.target.value)},style:{width:72,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 at({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 dr({dark:t,onColorsChange:s}){const o=t?"dark":"light",[a,i]=n.useState(()=>De(o));n.useEffect(()=>{i(De(o))},[o]);const c=n.useCallback((r,x)=>{i(u=>{const h={...u,[r]:x},l=De(o==="dark"?"light":"dark");return o==="dark"?ft(h,l):ft(l,h),Ze(h),s(h),h})},[o,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},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",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(at,{title:"App Background",children:[e.jsx(Ie,{label:"Background",value:a.bgPrimary,onChange:r=>c("bgPrimary",r)}),e.jsx(Ie,{label:"Surface",value:a.bgSecondary,onChange:r=>c("bgSecondary",r)}),e.jsx(Ie,{label:"Card",value:a.surfacePrimary,onChange:r=>c("surfacePrimary",r)})]}),e.jsxs(at,{title:"App Text",children:[e.jsx(Ie,{label:"Primary",value:a.textPrimary,onChange:r=>c("textPrimary",r)}),e.jsx(Ie,{label:"Secondary",value:a.textSecondary,onChange:r=>c("textSecondary",r)}),e.jsx(Ie,{label:"Muted",value:a.textMuted,onChange:r=>c("textMuted",r)})]}),e.jsxs(at,{title:"Borders & Accent",children:[e.jsx(Ie,{label:"Border subtle",value:a.borderSubtle,onChange:r=>c("borderSubtle",r)}),e.jsx(Ie,{label:"Border default",value:a.borderDefault,onChange:r=>c("borderDefault",r)}),e.jsx(Ie,{label:"Accent",value:a.accentColor,onChange:r=>c("accentColor",r)})]})]}),e.jsxs("div",{children:[e.jsxs(at,{title:"Chat Bubbles",children:[e.jsx(Ie,{label:"User bubble",value:a.userBubble,onChange:r=>c("userBubble",r)}),e.jsx(Ie,{label:"User text",value:a.userText,onChange:r=>c("userText",r)}),e.jsx(Ie,{label:"Agent bubble",value:a.assistantBubble,onChange:r=>c("assistantBubble",r)}),e.jsx(Ie,{label:"Agent text",value:a.assistantText,onChange:r=>c("assistantText",r)})]}),e.jsxs(at,{title:"Chat Layout",children:[e.jsx(Ie,{label:"Chat BG",value:a.containerBg,onChange:r=>c("containerBg",r)}),e.jsx(Ie,{label:"Send button",value:a.sendButton,onChange:r=>c("sendButton",r)}),e.jsx(Ie,{label:"Input border",value:a.inputBorder,onChange:r=>c("inputBorder",r)}),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)",minWidth:110},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:a.bubbleRadius,onChange:r=>c("bubbleRadius",Number(r.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:[a.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const r=t?Lt:Dt,u=De(t?"light":"dark");t?ft(r,u):ft(u,r),i(r),Ze(r),s(r)},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 ur(){const[t,s]=n.useState(yt),[o,a]=n.useState(!0),[i,c]=n.useState(()=>De("dark"));n.useEffect(()=>{a(ct());const u=new MutationObserver(()=>{const l=ct();a(l),yt()==="custom"&&Ze(De(l?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const h=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const l=ct();a(l),yt()==="custom"&&Ze(De(l?"dark":"light"))};return h.addEventListener("change",d),()=>{u.disconnect(),h.removeEventListener("change",d)}},[]),n.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&Ze(De(o?"dark":"light"))},[]),n.useEffect(()=>{c(De(o?"dark":"light"))},[o]);const r=u=>{s(u),cr(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},x=[...or,{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:x.map(u=>{const h=t===u.id,d=o?u.preview.dark:u.preview.light,l=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>r(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:h?"var(--bg-glass-hover)":"var(--bg-glass)",border:h?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:h?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.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:d.userBubble,color:l},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:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[h&&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:u.id==="custom"?"🎨 Custom":u.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&e.jsx(dr,{dark:o,onColorsChange:u=>c(u)})]})}const Bt="adhdev-accent-color",xr=[{name:"Violet",color:"#8b5cf6"},{name:"Indigo",color:"#6366f1"},{name:"Blue",color:"#3b82f6"},{name:"Cyan",color:"#06b6d4"},{name:"Emerald",color:"#10b981"},{name:"Rose",color:"#f43f5e"},{name:"Orange",color:"#f97316"},{name:"Amber",color:"#f59e0b"}],mt="#8b5cf6";function mr(t){const s=parseInt(t.slice(1,3),16)/255,o=parseInt(t.slice(3,5),16)/255,a=parseInt(t.slice(5,7),16)/255,i=Math.max(s,o,a),c=Math.min(s,o,a);let r=0,x=0;const u=(i+c)/2;if(i!==c){const h=i-c;switch(x=u>.5?h/(2-i-c):h/(i+c),i){case s:r=((o-a)/h+(o<a?6:0))/6;break;case o:r=((a-s)/h+2)/6;break;case a:r=((s-o)/h+4)/6;break}}return{h:Math.round(r*360),s:Math.round(x*100),l:Math.round(u*100)}}function ns(t,s){const{h:o,s:a,l:i}=mr(t),c=Math.min(100,i+s);return`hsl(${o}, ${a}%, ${c}%)`}function jt(t,s){const o=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${o}, ${a}, ${i}, ${s})`}function rs(){return typeof window>"u"?mt:localStorage.getItem(Bt)||mt}function pr(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",ns(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${ns(t,20)})`),s.style.setProperty("--border-accent",jt(t,.4)),s.style.setProperty("--nav-active-bg",jt(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${jt(t,.06)}`)}function hr(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(o=>t.style.removeProperty(o))}function fr(t){t===mt?(localStorage.removeItem(Bt),hr()):(localStorage.setItem(Bt,t),pr(t))}function gr(){const[t,s]=n.useState(rs),[o,a]=n.useState("");n.useEffect(()=>{s(rs())},[]);const i=c=>{s(c),fr(c)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:xr.map(c=>{const r=t===c.color;return e.jsx("button",{onClick:()=>i(c.color),title:c.name,style:{width:36,height:36,borderRadius:10,background:c.color,border:r?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:r?"scale(1.1)":"scale(1)",boxShadow:r?`0 0 12px ${jt(c.color,.4)}`:"none"},children:r&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},c.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:c=>i(c.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:o||t,onChange:c=>{a(c.target.value),/^#[0-9a-fA-F]{6}$/.test(c.target.value)&&i(c.target.value)},onBlur:()=>a(""),style:{width:80,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}}),t!==mt&&e.jsx("button",{onClick:()=>i(mt),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const Ts="adhdev_hiddenTabs";function br(){try{const t=localStorage.getItem(Ts);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ot(t){try{localStorage.setItem(Ts,JSON.stringify([...t]))}catch{}}function yr(){const[t,s]=n.useState(br),o=n.useCallback(u=>{s(h=>{const d=new Set(h);return d.has(u)?d.delete(u):d.add(u),ot(d),d})},[]),a=n.useCallback(u=>{s(h=>{if(h.has(u))return h;const d=new Set(h);return d.add(u),ot(d),d})},[]),i=n.useCallback(u=>{s(h=>{if(!h.has(u))return h;const d=new Set(h);return d.delete(u),ot(d),d})},[]),c=n.useCallback((u,h)=>{s(d=>{const l=new Set(d);for(const v of h)l.add(v);return ot(l),l})},[]),r=n.useCallback((u,h)=>{s(d=>{const l=new Set(d);for(const v of h)l.delete(v);return ot(l),l})},[]),x=n.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:o,hideTab:a,showTab:i,hideAllForDaemon:c,showAllForDaemon:r,isHidden:x}}function Es({sendDaemonCommand:t,activeConv:s,ides:o,updateIdeChats:a,setToasts:i,setLocalUserMessages:c,setClearedTabs:r,setActionLogs:x,pinTab:u,isStandalone:h}){const[d,l]=n.useState(""),[v,f]=n.useState(!1),[p,A]=n.useState(!1),[$,w]=n.useState(!1),S=n.useCallback(_=>_?Be(_)||We(_)?{agentType:_.agentType||_.ideType}:_.streamSource==="agent-stream"?{agentType:_.agentType}:{}:{},[]),O=n.useCallback(async()=>{if(!s)return;const _=d.trim();if(!_)return;const V=s.ideId,Y=s.tabKey;l(""),u(Y,[100,500,1500,3e3]);const y=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,Z={role:"user",content:_,timestamp:Date.now(),_localId:y};c(le=>({...le,[Y]:[...le[Y]||[],Z]}));try{const le=V||s.daemonId||"";if(!le)return;await t(le,"send_chat",{message:_,text:_,...S(s)}),setTimeout(()=>{const X=Date.now()-6e4;c(J=>{const K=J[Y];if(!K)return J;const ae=K.filter(se=>se.timestamp>X);return ae.length===K.length?J:{...J,[Y]:ae}})},6e4)}catch(le){console.error("Send failed",le),l(_),c(X=>({...X,[Y]:(X[Y]||[]).filter(J=>J._localId!==y)}))}},[s,d,t,c,u,S]),F=n.useCallback(async()=>{if(s)try{h?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(_){console.error("Relaunch failed",_)}},[s,h,t]),R=n.useCallback(async _=>{try{await t("standalone","launch_ide",{ideType:_,enableCdp:!0})}catch(V){console.error("Launch failed",V)}},[t]),T=n.useCallback(async _=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",_),x(V=>[...V,{ideId:s.tabKey,text:`🖱️ **${_}** clicked`,timestamp:Date.now()}]);try{const Y=(s.modalButtons||[]).indexOf(_),y=_.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),Z=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y),le=s.ideId||s.daemonId||"";(await t(le,"resolve_action",{button:_,action:Z?"approve":"reject",...Y>=0&&{buttonIndex:Y},...S(s)})).success||x(J=>[...J,{ideId:s.tabKey,text:`⚠️ **${_}** failed — button not found`,timestamp:Date.now()}])}catch(V){console.error("[ModalButton] Error:",V),x(Y=>[...Y,{ideId:s.tabKey,text:`❌ **${_}** error`,timestamp:Date.now()}])}}},[s,t,x,S]),D=n.useCallback(async(_,V)=>{try{const Y=_||(s==null?void 0:s.daemonId)||"",y=await t(Y,"switch_chat",{id:V,sessionId:V,...S(s)}),Z=y==null?void 0:y.result;(y==null?void 0:y.success)===!0||Z==="switched"||Z==="switched-by-title"||(Z===!1||Z==="not_found"?i(X=>[...X,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof Z=="string"&&Z.startsWith("error:")?i(X=>[...X,{id:Date.now(),message:`⚠️ Switch error: ${Z}`,type:"warning",timestamp:Date.now()}]):i(X=>[...X,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(Y){console.error("Switch failed",Y),i(y=>[...y,{id:Date.now(),message:`❌ Switch failed: ${Y.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,S]),I=n.useCallback(async()=>{if(!(!s||v)){f(!0);try{const _=s.ideId||s.daemonId||"";await t(_,"new_chat",{...S(s)}),r(V=>({...V,[s.tabKey]:Date.now()})),c(V=>({...V,[s.tabKey]:[]}))}catch(_){console.error("New chat failed",_)}finally{f(!1)}}},[s,v,t,r,c,S]),N=n.useCallback(async()=>{if(!s||$)return;w(!0);const _=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u(_,[200,1500,3e3])}catch(V){console.error("Focus agent failed",V)}finally{w(!1)}},[s,$,t,u]),ne=n.useCallback(async()=>{var _;if(!(!s||p)){A(!0);try{const V=s.ideId||s.daemonId||"",Y=await t(V,"list_chats",{forceExpand:!0,...S(s)}),y=(Y==null?void 0:Y.chats)||((_=Y==null?void 0:Y.result)==null?void 0:_.chats);Y!=null&&Y.success&&Array.isArray(y)&&a(s.ideId,y)}catch(V){console.error("Refresh history failed",V)}finally{A(!1)}}},[s,p,t,a,S]);return{agentInput:d,setAgentInput:l,isCreatingChat:v,isRefreshingHistory:p,isFocusingAgent:$,handleSendChat:O,handleRelaunch:F,handleLaunchIde:R,handleModalButton:T,handleSwitchSession:D,handleNewChat:I,handleFocusAgent:N,handleRefreshHistory:ne}}const Et={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 jr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function vr(){const[t,s]=n.useState("unix"),[o,a]=n.useState("powershell"),[i,c]=n.useState(!1),r=t==="unix"?"unix":o;n.useEffect(()=>{s(jr())},[]);const x=n.useCallback(()=>{navigator.clipboard.writeText(Et[r].cmd).catch(()=>{}),c(!0),setTimeout(()=>c(!1),2e3)},[r]);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/15 text-accent border border-accent/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/15 text-accent border border-accent/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 ${o==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${o==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:x,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Et[r].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Et[r].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted 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 && adhdev setup"})]})]})}function wr({conversations:t,ides:s,messageReceivedAt:o,actionLogs:a,ptyBuffers:i,screenshotMap:c,setScreenshotMap:r,sendDaemonCommand:x,updateIdeChats:u,setToasts:h,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:v,pinTab:f,isStandalone:p,userName:A,groupIndex:$,isFocused:w,onFocus:S,isSplitMode:O,numGroups:F,onMoveTab:R,onClose:T,onReceiveTab:D,style:I,detectedIdes:N,handleLaunchIde:ne,onActiveTabChange:_,initialActiveTabId:V,initialTabOrder:Y,onTabOrderChange:y,onHideTab:Z}){const{sendCommand:le}=Ve(),X=n.useRef(null),[J,K]=n.useState(!1),[ae,se]=n.useState(null),ie=n.useRef(0),ce=n.useRef(null),[P,j]=n.useState(V??null);n.useEffect(()=>{V&&V!==P&&j(V)},[V]);const[B,g]=n.useState(Y??[]),[z,U]=n.useState(null),de=n.useRef(null),we=n.useRef(null);n.useEffect(()=>{const C=new Set(t.map(E=>E.tabKey));g(E=>{const G=E.filter(b=>C.has(b)),q=t.filter(b=>!E.includes(b.tabKey)).map(b=>b.tabKey),Q=[...G,...q];return Q.length===E.length&&Q.every((b,m)=>b===E[m])?E:Q})},[t]);const ve=z??B,je=n.useMemo(()=>{if(ve.length===0)return t;const C=new Map(ve.map((E,G)=>[E,G]));return[...t].sort((E,G)=>{const q=C.get(E.tabKey)??999,Q=C.get(G.tabKey)??999;return q-Q})},[t,ve]);n.useEffect(()=>{if(je.length===0){j(null),_==null||_(null);return}P&&je.some(C=>C.tabKey===P)||(j(je[0].tabKey),_==null||_(je[0].tabKey))},[je,P]);const oe=je.find(C=>C.tabKey===P),he=n.useCallback((C,E,G)=>{g(q=>{const Q=q.filter(k=>k!==C),b=Q.indexOf(E);if(b<0)return q;const m=G==="left"?b:b+1;return Q.splice(m,0,C),y==null||y(Q),Q}),U(null)},[y]),L=n.useCallback((C,E,G)=>{const Q=(B.length>0?B:t.map(k=>k.tabKey)).filter(k=>k!==C),b=Q.indexOf(E);if(b<0)return;const m=G==="left"?b:b+1;Q.splice(m,0,C),de.current=Q,U(Q)},[B,t]),me=Es({sendDaemonCommand:x,activeConv:oe,ides:s,updateIdeChats:u,setToasts:h,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:v,pinTab:f,isStandalone:p}),[ge,fe]=n.useState(null);n.useEffect(()=>{if(!ge)return;const C=E=>{const G=document.querySelector("[data-pane-context-menu]");G&&G.contains(E.target)||fe(null)};return window.addEventListener("mousedown",C,!0),()=>window.removeEventListener("mousedown",C,!0)},[ge]);const Ce="adhdev-tab-shortcuts",$e=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Se,Ae]=n.useState(()=>{try{return JSON.parse(localStorage.getItem(Ce)||"{}")}catch{return{}}}),[Oe,_e]=n.useState(null),Re=n.useCallback(C=>{const E=[];C.metaKey&&E.push($e?"⌘":"Meta"),C.ctrlKey&&E.push("Ctrl"),C.altKey&&E.push($e?"⌥":"Alt"),C.shiftKey&&E.push($e?"⇧":"Shift");const G=C.key;if(["Control","Alt","Shift","Meta"].includes(G))return null;const q=G.length===1?G.toUpperCase():G;return E.push(q),E.join("+")},[$e]),Ee=n.useCallback((C,E)=>Re(C)===E,[Re]),W=n.useCallback(C=>{Ae(C),localStorage.setItem(Ce,JSON.stringify(C))},[]);n.useEffect(()=>{if(!Oe)return;const C=E=>{if(E.preventDefault(),E.stopPropagation(),E.key==="Escape"){_e(null);return}const G=Re(E);if(!G)return;const q={...Se};for(const[Q,b]of Object.entries(q))b===G&&delete q[Q];q[Oe]=G,W(q),_e(null)};return window.addEventListener("keydown",C,!0),()=>window.removeEventListener("keydown",C,!0)},[Oe,Se,W,Re]),n.useEffect(()=>{const C=E=>{if(!(!E.ctrlKey&&!E.metaKey&&!E.altKey)){for(const[G,q]of Object.entries(Se))if(Ee(E,q)&&je.some(Q=>Q.tabKey===G)){E.preventDefault(),S(),j(G),_==null||_(G);return}}};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[Se,je,S,_,Ee]);const[re,ee]=n.useState({}),xe=oe&&Be(oe)&&!We(oe),ye=xe?re[oe.tabKey]??oe.mode??"terminal":"chat";n.useEffect(()=>{const C=()=>{ie.current=0,K(!1),se(null)};return window.addEventListener("dragend",C),window.addEventListener("drop",C),()=>{window.removeEventListener("dragend",C),window.removeEventListener("drop",C)}},[]);const pe=n.useRef(null);return n.useEffect(()=>{const C=pe.current;if(!C)return;const E=G=>{Math.abs(G.deltaY)>Math.abs(G.deltaX)&&(G.preventDefault(),C.scrollLeft+=G.deltaY)};return C.addEventListener("wheel",E,{passive:!1}),()=>C.removeEventListener("wheel",E)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:S,style:{...I,outline:J?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx("div",{className:"flex items-center bg-bg-secondary border-b border-border-subtle shrink-0 gap-0",children:e.jsxs("div",{ref:pe,className:"flex-1 flex overflow-x-auto overflow-y-visible pt-1.5 pb-0 gap-1 select-none",style:{paddingLeft:8,paddingRight:4,scrollbarWidth:"none"},children:[je.map((C,E)=>{const G=P===C.tabKey,q=C.status==="working"?"agent-tab-working":C.status==="waiting_approval"?"agent-tab-waiting":"",Q=C.connectionState==="failed"||C.connectionState==="closed",b=we.current===C.tabKey;return e.jsxs("div",{"data-tabkey":C.tabKey,className:`${q} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:m=>{we.current=C.tabKey,m.dataTransfer.setData("text/tab-key",C.tabKey),m.dataTransfer.effectAllowed="move"},onDragEnd:()=>{we.current=null;const m=de.current;m&&(g(m),y==null||y(m)),de.current=null,U(null),ie.current=0,K(!1)},onDragOver:m=>{const k=we.current;if(!(!k||k===C.tabKey)&&m.dataTransfer.types.includes("text/tab-key")){m.preventDefault(),m.stopPropagation();const M=m.currentTarget.getBoundingClientRect(),H=M.left+M.width/2,te=m.clientX<H?"left":"right";L(k,C.tabKey,te)}},onDrop:m=>{m.preventDefault(),m.stopPropagation();const k=m.dataTransfer.getData("text/tab-key");if(k&&k!==C.tabKey){const M=m.currentTarget.getBoundingClientRect(),H=M.left+M.width/2,te=m.clientX<H?"left":"right";je.some(ue=>ue.tabKey===k)?he(k,C.tabKey,te):D&&D(k)}U(null)},onClick:m=>{m.stopPropagation(),S(),j(C.tabKey),_==null||_(C.tabKey),C.streamSource==="agent-stream"&&C.agentType&&le(C.ideId,"agent_stream_focus",{agentType:C.agentType}).catch(()=>{}),Be(C)&&setTimeout(()=>{var k,M;return(M=(k=X.current)==null?void 0:k.bumpResize)==null?void 0:M.call(k)},100)},onContextMenu:m=>{m.preventDefault(),fe({x:m.clientX,y:m.clientY,tabKey:C.tabKey})},onTouchStart:m=>{const k=m.touches[0],M=k.clientX,H=k.clientY;ce.current=setTimeout(()=>{fe({x:M,y:H,tabKey:C.tabKey})},600)},onTouchEnd:()=>{ce.current&&clearTimeout(ce.current)},onTouchMove:()=>{ce.current&&clearTimeout(ce.current)},style:{background:G?"var(--bg-primary)":"var(--bg-glass)",borderTop:G?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:G?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:G?"1px solid var(--border-subtle)":"1px solid transparent",opacity:b?.4:Q?G?.6:.3:G?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[C.status==="working"?e.jsx("div",{className:"tab-spinner"}):C.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):Q?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):C.connectionState==="connected"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-green-400",children:"●"}):e.jsx("span",{className:"text-[8px] px-[5px] py-px text-text-muted animate-pulse",children:"○"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-bold whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"10ch"},title:C.displayPrimary,children:C.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:Q?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[C.displaySecondary,C.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",C.machineName]})]})]})})]}),Se[C.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${Se[C.tabKey]}`,children:Se[C.tabKey]})]},C.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:C=>{C.dataTransfer.types.includes("text/tab-key")&&(ie.current++,K(!0))},onDragOver:C=>{if(C.dataTransfer.types.includes("text/tab-key")&&(C.preventDefault(),F<4&&R)){const E=C.currentTarget.getBoundingClientRect(),G=C.clientX-E.left;se(G<E.width/2?"left":"right")}},onDragLeave:()=>{ie.current--,ie.current<=0&&(ie.current=0,K(!1),se(null))},onDrop:C=>{ie.current=0,K(!1);const E=C.dataTransfer.getData("text/tab-key"),G=E?t.some(Q=>Q.tabKey===E):!1,q=ae;if(se(null),U(null),!!E){if(C.preventDefault(),q&&R&&F<4){R(E,q==="left"?"split-left":"split-right");return}G?g(Q=>{const b=Q.filter(m=>m!==E);return b.push(E),y==null||y(b),b}):D&&D(E)}},children:[J&&R&&F<4&&e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:ae==="left"?"rgba(139, 92, 246, 0.18)":"rgba(139, 92, 246, 0.08)",boxShadow:ae==="left"?"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:"Split Left"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:ae==="right"?"rgba(139, 92, 246, 0.18)":"rgba(139, 92, 246, 0.08)",boxShadow:ae==="right"?"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:"Split Right"})})]}),oe?e.jsxs(e.Fragment,{children:[xe&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-bg-primary border-b border-border-subtle shrink-0 gap-3",children:[e.jsxs("div",{className:"flex bg-bg-secondary rounded items-center p-0.5 border border-border-subtle text-[11px] shadow-sm",children:[e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${ye==="chat"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{ye!=="chat"&&ee(C=>({...C,[oe.tabKey]:"chat"}))},children:"💬 Chat"}),e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${ye==="terminal"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{ye!=="terminal"&&ee(C=>({...C,[oe.tabKey]:"terminal"}))},children:"🖥 Terminal"})]}),ye==="terminal"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(!X.current)return;const C=i.current.get(oe.tabKey);if(C&&C.length>0)for(const E of C)X.current.write(E);requestAnimationFrame(()=>{requestAnimationFrame(()=>{var E;(E=X.current)==null||E.bumpResize()})})},title:"Refresh terminal (replay buffer + TUI redraw)",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-bg-secondary text-text-secondary border border-border-subtle cursor-pointer leading-none",children:"↺"}),e.jsx("button",{onClick:async()=>{var G;const C=(G=oe.ideId)!=null&&G.includes(":cli:")?oe.ideId.split(":cli:")[1]:oe.ideType||oe.agentType||"";if(!window.confirm(`Stop ${C}?
51
+ This will terminate the CLI process.`))return;const E=oe.ideId||oe.daemonId||"";try{await le(E,"stop_cli",{cliType:C})}catch(q){console.error("Stop CLI failed:",q)}},title:"Stop CLI process",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-red-500/[0.08] text-red-400 border border-red-500/30 cursor-pointer leading-none font-semibold",children:"■ Stop"})]})]}),e.jsx(jn,{activeConv:oe,onModalButton:me.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!xe&&!We(oe)&&c[oe.ideId]?e.jsx(yn,{screenshotUrl:c[oe.ideId],mode:"preview",onDismiss:()=>{const C={...c};delete C[oe.ideId],r(C)}}):!xe&&!We(oe)&&oe.cdpConnected===!1?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(Kt,{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:me.handleRelaunch,children:"Relaunch with CDP"})]}):null}),ye==="terminal"?e.jsx(wn,{activeConv:oe,ptyBuffers:i,terminalRef:X,agentInput:me.agentInput,setAgentInput:me.setAgentInput,handleSendChat:me.handleSendChat}):e.jsx(ys,{activeConv:oe,ides:s,agentInput:me.agentInput,setAgentInput:me.setAgentInput,handleSendChat:me.handleSendChat,handleFocusAgent:me.handleFocusAgent,isFocusingAgent:me.isFocusingAgent,messageReceivedAt:o,actionLogs:a,userName:A})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!O&&N&&ne?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:p?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!p&&e.jsx(vr,{}),p&&N&&N.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:N.map(C=>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:()=>ne&&ne(C.type),children:[e.jsx(ln,{size:14,className:"opacity-70"})," Launch ",C.name]},C.type))})]}),!p&&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:O?"Move a tab here to view":"No active agent"})})]}),ge&&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:ge.x,top:ge.y},children:[R&&$>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"left"),fe(null)},children:"← Move to Left Group"}),R&&$<F-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"right"),fe(null)},children:"Move to Right Group →"}),R&&F<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"split-left"),fe(null)},children:"⇤ Split Left"}),R&&F<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{R(ge.tabKey,"split-right"),fe(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:C=>{C.stopPropagation(),_e(ge.tabKey),fe(null)},children:["⌨ ",Se[ge.tabKey]?`Change shortcut (${Se[ge.tabKey]})`:"Set shortcut"]}),Se[ge.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 C={...Se};delete C[ge.tabKey],W(C),fe(null)},children:"✕ Remove shortcut"}),Z&&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:()=>{Z(ge.tabKey),fe(null)},children:"🚫 Hide from Dashboard"})]}),!R&&!Z&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),Oe&&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:C=>C.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. ",$e?"⌘+1":"Ctrl+1",", ",$e?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const At=[{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 && adhdev setup"}];function Nr({onClose:t}){const[s,o]=n.useState(0),a=At[s],i=s===At.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:c=>{c.target===c.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:At.map((c,r)=>e.jsx("div",{style:{width:r===s?24:8,height:8,borderRadius:4,background:r===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},r))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:a.visual||a.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:a.icon})," ",a.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:a.desc}),a.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:"$"}),a.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():o(c=>c+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:`
52
52
  @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
53
53
  @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
54
- `})]})}function yr(){const{sendCommand:t}=Xe(),[s,o]=cs(),a=s.get("activeTab"),i=kt(),{updateIdeChats:c,screenshotMap:r,setScreenshotMap:x}=i,u=i.ides||[],[h,d]=n.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),l=i.toasts||[],j=i.setToasts||(()=>{}),f=i.wsStatus||"connected",p=i.isConnected??!0,A=i.connectionStates||{};i.retryConnection;const $=i.showReconnected||!1,[w,S]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_splitGroups");if(b){const m=JSON.parse(b);return new Map(m)}}catch{}return new Map}),[O,F]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_focusedGroup");if(b)return parseInt(b,10)||0}catch{}return 0}),[R,T]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_groupActiveTabs");if(b)return JSON.parse(b)}catch{}return{}}),D=n.useRef(!1),[I,N]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_groupTabOrders");if(b)return JSON.parse(b)}catch{}return{}}),[ne,_]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_splitSizes");if(b)return JSON.parse(b)}catch{}return[]});n.useEffect(()=>{try{w.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...w.entries()]))}catch{}},[w]),n.useEffect(()=>{try{ne.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(ne)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[ne]),n.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(O))}catch{}},[O]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(R))}catch{}},[R]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(I))}catch{}},[I]);const[X,Y]=n.useState(()=>typeof window<"u"&&window.innerWidth<768);n.useEffect(()=>{const b=window.matchMedia("(max-width: 767px)"),m=k=>Y(k.matches);return b.addEventListener("change",m),()=>b.removeEventListener("change",m)},[]);const y=n.useMemo(()=>X||w.size===0?1:Math.max(1,...w.values())+1,[w,X]),Z=y>1,le=n.useCallback((b,m)=>{S(k=>{const M=new Map(k);return m===0?M.delete(b):M.set(b,m),M}),F(m)},[]),V=n.useCallback((b,m)=>{const k={};for(const[M,H]of Object.entries(b)){const te=Number(M);k[te>=m?te+1:te]=H}return k},[]),J=n.useCallback(b=>Array(b).fill(100/b),[]),K=n.useCallback(b=>{S(m=>{const k=new Map;for(const[M,H]of m)H!==b&&(H>b?k.set(M,H-1):k.set(M,H));return k}),_(m=>{if(m.length<=1)return[];const k=[...m];k.splice(b,1);const M=k.reduce((H,te)=>H+te,0);return k.map(H=>H/M*100)}),F(0)},[]),ae=n.useRef(null),se=n.useCallback((b,m)=>{m.preventDefault();const k=ae.current;if(!k)return;const M=m.clientX,H=k.offsetWidth,te=ne.length===y?[...ne]:Array(y).fill(100/y),ue=Ne=>{const Fe=(Ne.clientX-M)/H*100,Ve=[...te];Ve[b]=Math.max(15,te[b]+Fe),Ve[b+1]=Math.max(15,te[b+1]-Fe),_(Ve)},be=()=>{document.removeEventListener("mousemove",ue),document.removeEventListener("mouseup",be),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",ue),document.addEventListener("mouseup",be)},[ne,y]),[ie,ce]=n.useState({}),[P,v]=n.useState(!1),[B,g]=n.useState([]),[U,z]=n.useState({}),[de,we]=n.useState({}),je=u.find(b=>b.type==="adhdev-daemon"),ve=(je==null?void 0:je.detectedIdes)||[],oe=!!je,he=n.useMemo(()=>{const b=u.filter(k=>k.type!=="adhdev-daemon"),m=new Map;for(const k of b){const M=m.get(k.id);if(!M)m.set(k.id,k);else{const H=(M.workspace?1:0)+(M.activeChat?1:0);((k.workspace?1:0)+(k.activeChat?1:0)>H||(k.timestamp||0)>(M.timestamp||0))&&m.set(k.id,k)}}return Array.from(m.values())},[u]),L=n.useMemo(()=>{const b=An(he,U,u,A),m=Date.now();return b.map(k=>{const M=de[k.tabKey];return M&&m-M<5e3?{...k,messages:[],title:""}:k})},[he,U,de,u]),{hiddenTabs:me,toggleTab:ge}=pr(),fe=n.useMemo(()=>L.filter(b=>!me.has(b.tabKey)),[L,me]),Ce=n.useCallback((b,m,k)=>{const M=y;if(M>=4)return;const H=k==="left"?m:m+1;S(te=>{const ue=new Map;for(const be of fe){const Ne=te.get(be.tabKey)??0,Ke=Ne>=H?Ne+1:Ne;ue.set(be.tabKey,Ke)}return ue.set(b,H),ue}),_(te=>{const ue=te.length===M?[...te]:J(M),be=ue[m]??100/M,Ne=Math.max(15,be/2),Ke=Math.max(15,be/2),Fe=[...ue];Fe[m]=Ne,Fe.splice(H,0,Ke);const Ve=Fe.reduce((rt,Qe)=>rt+Qe,0);return Fe.map(rt=>rt/Ve*100)}),T(te=>{const ue=V(te,H);return ue[H]=b,ue}),N(te=>{const ue=V(te,H);return ue[H]=[b],ue}),F(H)},[y,fe,J,V]);n.useEffect(()=>{Wn()},[]);const $e=n.useMemo(()=>fe.map(b=>({id:b.tabKey,name:b.title||b.agentName||b.ideId,status:b.status,activeModal:b.modalMessage?{message:b.modalMessage,buttons:b.modalButtons}:null})),[fe]);Kn($e);const Se=n.useMemo(()=>{const b=Array.from({length:y},()=>[]);for(const m of fe){const k=w.get(m.tabKey)??0,M=Math.min(k,y-1);b[M].push(m)}return b},[fe,w,y]);n.useEffect(()=>{const b=new Set(fe.map(m=>m.tabKey));S(m=>{let k=!1;const M=new Map;for(const[H,te]of m)b.has(H)?M.set(H,te):k=!0;return k?M:m})},[L]),n.useEffect(()=>{if(Z)for(let b=y-1;b>=1;b--)[...w.values()].some(k=>k===b)||K(b)},[w,y,Z,K]),n.useEffect(()=>{if(!a||D.current||L.length===0)return;const b=L.find(m=>m.tabKey===a)||L.find(m=>m.ideId===a)||L.find(m=>m.ideType===a||m.agentType===a);if(b){const m=w.get(b.tabKey)??0;T(k=>({...k,[m]:b.tabKey})),F(m),D.current=!0,o(k=>{const M=new URLSearchParams(k);return M.delete("activeTab"),M},{replace:!0})}},[a,L,w]),n.useEffect(()=>{if(Object.keys(de).length===0)return;const m=setTimeout(()=>{we(k=>{const M=Date.now(),H={};for(const[te,ue]of Object.entries(k))M-ue<5e3&&(H[te]=ue);return Object.keys(H).length===Object.keys(k).length?k:H})},5500);return()=>clearTimeout(m)},[de]);const Ae=n.useMemo(()=>{var m,k;const b=R[O];if(b){const M=L.find(H=>H.tabKey===b);if(M)return M}return((m=Se[O])==null?void 0:m[0])||((k=Se[0])==null?void 0:k[0])},[R,O,L,Se]),Oe=n.useCallback((b,m)=>{},[]);n.useEffect(()=>{var M;const b=Date.now();let m=!1;const k={...ie};for(const H of L)(M=H.messages)!=null&&M.length&&H.messages.forEach((te,ue)=>{const be=`${H.ideId}-${te.id??`i-${ue}`}`;k[be]==null&&(k[be]=b,m=!0)});m&&ce(k)},[L]);const _e=n.useRef(!1);n.useEffect(()=>{if(!P){_e.current=!1;return}if(!Ae||_e.current||W)return;const b=u.find(m=>m.id===Ae.ideId);b&&(!b.chats||b.chats.length===0)&&(_e.current=!0,ye())},[P,Ae==null?void 0:Ae.ideId]),n.useEffect(()=>{const b=setInterval(()=>{const m=Date.now()-3e5;g(k=>{const M=k.filter(H=>H.timestamp>m).slice(-100);return M.length===k.length?k:M})},6e4);return()=>clearInterval(b)},[]);const Re=n.useRef(new Map);n.useEffect(()=>{const b=(k,M)=>{var H;if(M){ys.emit(k,M);for(const te of L){if(!Be(te))continue;const ue=(H=te.ideId)!=null&&H.includes(":cli:")?te.ideId.split(":cli:")[1]:"";if(k===ue||k===te.agentType||k===te.ideType||k===te.ideId||k===te.tabKey){const Ne=Re.current.get(te.tabKey)||[];Ne.push(M),Ne.length>1e4&&Ne.splice(0,Ne.length-5e3),Re.current.set(te.tabKey,Ne)}}}},m=Nn.onPtyOutput(b);return()=>{m()}},[L]),n.useEffect(()=>{const b=m=>{if(m.ctrlKey&&m.key==="\\"){if(m.preventDefault(),Z)S(new Map),F(0);else{const k=L[1];k&&Ce(k.tabKey,0,"right")}return}m.ctrlKey&&(m.key==="["||m.key==="]")&&Z&&(m.preventDefault(),F(k=>m.key==="]"?Math.min(k+1,y-1):Math.max(k-1,0)))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Z,L,Ce,y]),n.useEffect(()=>{et.setIdes(u)},[u]),n.useEffect(()=>{et.setResolveAction((b,m,k)=>{t(b,m,k).catch(()=>{})})},[t]),n.useEffect(()=>{const b=et.onToast(M=>{j(te=>te.some(be=>be.message===M.message&&M.timestamp-be.timestamp<3e3)?te:[...te.slice(-4),{id:M.id,message:M.message,type:M.type,timestamp:M.timestamp,ideId:M.ideId,actions:M.actions}]);const H=M.duration||5e3;setTimeout(()=>j(te=>te.filter(ue=>ue.id!==M.id)),H)}),m=et.onSystemMessage((M,H)=>{z(te=>{for(const ue of Object.keys(te))if(ue.includes(M))return{...te,[ue]:[...te[ue]||[],H]};return te})}),k=et.onClearSystemMessage((M,H)=>{z(te=>{const ue={...te};for(const be of Object.keys(ue))be.includes(M)&&(ue[be]=(ue[be]||[]).filter(Ne=>{var Ke;return!(Ne.role==="system"&&((Ke=Ne._localId)!=null&&Ke.startsWith(H)))}));return ue})});return()=>{b(),m(),k()}},[]),n.useEffect(()=>{const b=jn.on("status_event",m=>et.handleRawEvent(m,"ws"));return()=>{b()}},[]),n.useEffect(()=>{var m;const b=k=>{const M=k.data;(M==null?void 0:M.type)==="notification_action"&&M.action==="approve"&&M.ideId&&t(M.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(H=>console.error("[SW Action] approve failed:",H))};return(m=navigator.serviceWorker)==null||m.addEventListener("message",b),()=>{var k;return(k=navigator.serviceWorker)==null?void 0:k.removeEventListener("message",b)}},[]);const{isCreatingChat:Ee,isRefreshingHistory:W,handleLaunchIde:re,handleSwitchSession:ee,handleNewChat:xe,handleRefreshHistory:ye}=Ts({sendDaemonCommand:t,activeConv:Ae,ides:u,updateIdeChats:c,setToasts:j,setLocalUserMessages:z,setClearedTabs:we,setActionLogs:g,pinTab:Oe,isStandalone:oe}),pe=n.useMemo(()=>u.filter(b=>b.type==="adhdev-daemon"&&b.versionMismatch),[u]),[C,E]=n.useState(!1),[G,q]=n.useState({}),Q=n.useCallback(async b=>{var m,k;q(M=>({...M,[b]:"upgrading"}));try{const M=await t(b,"daemon_upgrade",{});(m=M==null?void 0:M.result)!=null&&m.upgraded||(k=M==null?void 0:M.result)!=null&&k.success?q(H=>({...H,[b]:"done"})):q(H=>({...H,[b]:"error"}))}catch{q(M=>({...M,[b]:"error"}))}},[t]);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(bn,{wsStatus:f,showReconnected:$}),pe.length>0&&!C&&e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0",children:"🔄"}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",pe[0].version]})," → ",e.jsxs("strong",{children:["v",pe[0].serverVersion]})]}),pe.map(b=>{var M;const m=b.machineNickname||((M=b.machine)==null?void 0:M.hostname)||b.hostname||"Machine",k=G[b.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:m}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",b.version]}),k==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):k==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):k==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>Q(b.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>Q(b.id),children:"Upgrade"})]},b.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>E(!0),title:"Dismiss",children:"✕"})]}),e.jsx(kn,{activeConv:Ae,agentCount:he.length,wsStatus:f,isConnected:p,onOpenHistory:()=>v(!0)}),e.jsx("div",{ref:ae,className:`flex-1 min-h-0 flex ${Z?"flex-row":"flex-col"} overflow-hidden`,children:Se.map((b,m)=>{const k=Z&&ne.length===y?`${ne[m]}%`:void 0;return e.jsxs(Ds.Fragment,{children:[Z&&m>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:M=>se(m-1,M),onDoubleClick:()=>K(m),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(gr,{style:Z?{flexBasis:k??`${100/y}%`,flexGrow:k?0:1,flexShrink:k?0:1}:void 0,conversations:b,ides:u,messageReceivedAt:ie,actionLogs:B,ptyBuffers:Re,screenshotMap:r,setScreenshotMap:x,sendDaemonCommand:t,updateIdeChats:c,setToasts:j,setLocalUserMessages:z,setClearedTabs:we,setActionLogs:g,pinTab:Oe,isStandalone:oe,userName:i.userName,groupIndex:m,isFocused:O===m,onFocus:()=>F(m),isSplitMode:Z,numGroups:y,onMoveTab:(M,H)=>{H==="left"&&m>0?le(M,m-1):H==="right"&&m<y-1?le(M,m+1):H==="split-left"&&y<4?Ce(M,m,"left"):H==="split-right"&&y<4&&Ce(M,m,"right")},onClose:Z?()=>K(m):void 0,onReceiveTab:M=>le(M,m),detectedIdes:m===0?ve:void 0,handleLaunchIde:m===0?re:void 0,onActiveTabChange:M=>T(H=>({...H,[m]:M})),initialActiveTabId:R[m],initialTabOrder:I[m],onTabOrderChange:M=>N(H=>({...H,[m]:M})),onHideTab:ge})]},m)})}),P&&Ae&&e.jsx(In,{activeConv:Ae,ides:u,isCreatingChat:Ee,isRefreshingHistory:W,onClose:()=>v(!1),onNewChat:xe,onSwitchSession:ee,onRefreshHistory:ye}),e.jsx("style",{children:`
54
+ `})]})}function kr(){const{sendCommand:t}=Ve(),[s,o]=ls(),a=s.get("activeTab"),i=kt(),{updateIdeChats:c,screenshotMap:r,setScreenshotMap:x}=i,u=i.ides||[],[h,d]=n.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),l=i.toasts||[],v=i.setToasts||(()=>{}),f=i.wsStatus||"connected",p=i.isConnected??!0,A=i.connectionStates||{};i.retryConnection;const $=i.showReconnected||!1,[w,S]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_splitGroups");if(b){const m=JSON.parse(b);return new Map(m)}}catch{}return new Map}),[O,F]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_focusedGroup");if(b)return parseInt(b,10)||0}catch{}return 0}),[R,T]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_groupActiveTabs");if(b)return JSON.parse(b)}catch{}return{}}),D=n.useRef(!1),[I,N]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_groupTabOrders");if(b)return JSON.parse(b)}catch{}return{}}),[ne,_]=n.useState(()=>{try{const b=localStorage.getItem("adhdev_splitSizes");if(b)return JSON.parse(b)}catch{}return[]});n.useEffect(()=>{try{w.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...w.entries()]))}catch{}},[w]),n.useEffect(()=>{try{ne.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(ne)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[ne]),n.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(O))}catch{}},[O]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(R))}catch{}},[R]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(I))}catch{}},[I]);const[V,Y]=n.useState(()=>typeof window<"u"&&window.innerWidth<768);n.useEffect(()=>{const b=window.matchMedia("(max-width: 767px)"),m=k=>Y(k.matches);return b.addEventListener("change",m),()=>b.removeEventListener("change",m)},[]);const y=n.useMemo(()=>V||w.size===0?1:Math.max(1,...w.values())+1,[w,V]),Z=y>1,le=n.useCallback((b,m)=>{S(k=>{const M=new Map(k);return m===0?M.delete(b):M.set(b,m),M}),F(m)},[]),X=n.useCallback((b,m)=>{const k={};for(const[M,H]of Object.entries(b)){const te=Number(M);k[te>=m?te+1:te]=H}return k},[]),J=n.useCallback(b=>Array(b).fill(100/b),[]),K=n.useCallback(b=>{S(m=>{const k=new Map;for(const[M,H]of m)H!==b&&(H>b?k.set(M,H-1):k.set(M,H));return k}),_(m=>{if(m.length<=1)return[];const k=[...m];k.splice(b,1);const M=k.reduce((H,te)=>H+te,0);return k.map(H=>H/M*100)}),F(0)},[]),ae=n.useRef(null),se=n.useCallback((b,m)=>{m.preventDefault();const k=ae.current;if(!k)return;const M=m.clientX,H=k.offsetWidth,te=ne.length===y?[...ne]:Array(y).fill(100/y),ue=ke=>{const Fe=(ke.clientX-M)/H*100,Xe=[...te];Xe[b]=Math.max(15,te[b]+Fe),Xe[b+1]=Math.max(15,te[b+1]-Fe),_(Xe)},be=()=>{document.removeEventListener("mousemove",ue),document.removeEventListener("mouseup",be),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",ue),document.addEventListener("mouseup",be)},[ne,y]),[ie,ce]=n.useState({}),[P,j]=n.useState(!1),[B,g]=n.useState([]),[z,U]=n.useState({}),[de,we]=n.useState({}),ve=u.find(b=>b.type==="adhdev-daemon"),je=(ve==null?void 0:ve.detectedIdes)||[],oe=!!ve,he=n.useMemo(()=>{const b=u.filter(k=>k.type!=="adhdev-daemon"),m=new Map;for(const k of b){const M=m.get(k.id);if(!M)m.set(k.id,k);else{const H=(M.workspace?1:0)+(M.activeChat?1:0);((k.workspace?1:0)+(k.activeChat?1:0)>H||(k.timestamp||0)>(M.timestamp||0))&&m.set(k.id,k)}}return Array.from(m.values())},[u]),L=n.useMemo(()=>{const b=Ln(he,z,u,A),m=Date.now();return b.map(k=>{const M=de[k.tabKey];return M&&m-M<5e3?{...k,messages:[],title:""}:k})},[he,z,de,u]),{hiddenTabs:me,toggleTab:ge}=yr(),fe=n.useMemo(()=>L.filter(b=>!me.has(b.tabKey)),[L,me]),Ce=n.useCallback((b,m,k)=>{const M=y;if(M>=4)return;const H=k==="left"?m:m+1;S(te=>{const ue=new Map;for(const be of fe){const ke=te.get(be.tabKey)??0,Ke=ke>=H?ke+1:ke;ue.set(be.tabKey,Ke)}return ue.set(b,H),ue}),_(te=>{const ue=te.length===M?[...te]:J(M),be=ue[m]??100/M,ke=Math.max(15,be/2),Ke=Math.max(15,be/2),Fe=[...ue];Fe[m]=ke,Fe.splice(H,0,Ke);const Xe=Fe.reduce((rt,et)=>rt+et,0);return Fe.map(rt=>rt/Xe*100)}),T(te=>{const ue=X(te,H);return ue[H]=b,ue}),N(te=>{const ue=X(te,H);return ue[H]=[b],ue}),F(H)},[y,fe,J,X]);n.useEffect(()=>{zn()},[]);const $e=n.useMemo(()=>fe.map(b=>({id:b.tabKey,name:b.title||b.agentName||b.ideId,status:b.status,activeModal:b.modalMessage?{message:b.modalMessage,buttons:b.modalButtons}:null})),[fe]);Yn($e);const Se=n.useMemo(()=>{const b=Array.from({length:y},()=>[]);for(const m of fe){const k=w.get(m.tabKey)??0,M=Math.min(k,y-1);b[M].push(m)}return b},[fe,w,y]);n.useEffect(()=>{const b=new Set(fe.map(m=>m.tabKey));S(m=>{let k=!1;const M=new Map;for(const[H,te]of m)b.has(H)?M.set(H,te):k=!0;return k?M:m})},[L]),n.useEffect(()=>{if(Z)for(let b=y-1;b>=1;b--)[...w.values()].some(k=>k===b)||K(b)},[w,y,Z,K]),n.useEffect(()=>{if(!a||D.current||L.length===0)return;const b=L.find(m=>m.tabKey===a)||L.find(m=>m.ideId===a)||L.find(m=>m.ideType===a||m.agentType===a);if(b){const m=w.get(b.tabKey)??0;T(k=>({...k,[m]:b.tabKey})),F(m),D.current=!0,o(k=>{const M=new URLSearchParams(k);return M.delete("activeTab"),M},{replace:!0})}},[a,L,w]),n.useEffect(()=>{if(Object.keys(de).length===0)return;const m=setTimeout(()=>{we(k=>{const M=Date.now(),H={};for(const[te,ue]of Object.entries(k))M-ue<5e3&&(H[te]=ue);return Object.keys(H).length===Object.keys(k).length?k:H})},5500);return()=>clearTimeout(m)},[de]);const Ae=n.useMemo(()=>{var m,k;const b=R[O];if(b){const M=L.find(H=>H.tabKey===b);if(M)return M}return((m=Se[O])==null?void 0:m[0])||((k=Se[0])==null?void 0:k[0])},[R,O,L,Se]),Oe=n.useCallback((b,m)=>{},[]);n.useEffect(()=>{var M;const b=Date.now();let m=!1;const k={...ie};for(const H of L)(M=H.messages)!=null&&M.length&&H.messages.forEach((te,ue)=>{const be=`${H.ideId}-${te.id??`i-${ue}`}`;k[be]==null&&(k[be]=b,m=!0)});m&&ce(k)},[L]);const _e=n.useRef(!1);n.useEffect(()=>{if(!P){_e.current=!1;return}if(!Ae||_e.current||W)return;const b=u.find(m=>m.id===Ae.ideId);b&&(!b.chats||b.chats.length===0)&&(_e.current=!0,ye())},[P,Ae==null?void 0:Ae.ideId]),n.useEffect(()=>{const b=setInterval(()=>{const m=Date.now()-3e5;g(k=>{const M=k.filter(H=>H.timestamp>m).slice(-100);return M.length===k.length?k:M})},6e4);return()=>clearInterval(b)},[]);const Re=n.useRef(new Map);n.useEffect(()=>{const b=(k,M)=>{var H;if(M){js.emit(k,M);for(const te of L){if(!Be(te))continue;const ue=(H=te.ideId)!=null&&H.includes(":cli:")?te.ideId.split(":cli:")[1]:"";if(k===ue||k===te.agentType||k===te.ideType||k===te.ideId||k===te.tabKey){const ke=Re.current.get(te.tabKey)||[];ke.push(M),ke.length>1e4&&ke.splice(0,ke.length-5e3),Re.current.set(te.tabKey,ke)}}}},m=Mn.onPtyOutput(b);return()=>{m()}},[L]),n.useEffect(()=>{const b=m=>{if(m.ctrlKey&&m.key==="\\"){if(m.preventDefault(),Z)S(new Map),F(0);else{const k=L[1];k&&Ce(k.tabKey,0,"right")}return}m.ctrlKey&&(m.key==="["||m.key==="]")&&Z&&(m.preventDefault(),F(k=>m.key==="]"?Math.min(k+1,y-1):Math.max(k-1,0)))};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[Z,L,Ce,y]),n.useEffect(()=>{tt.setIdes(u)},[u]),n.useEffect(()=>{tt.setResolveAction((b,m,k)=>{t(b,m,k).catch(()=>{})})},[t]),n.useEffect(()=>{const b=tt.onToast(M=>{v(te=>te.some(be=>be.message===M.message&&M.timestamp-be.timestamp<3e3)?te:[...te.slice(-4),{id:M.id,message:M.message,type:M.type,timestamp:M.timestamp,ideId:M.ideId,actions:M.actions}]);const H=M.duration||5e3;setTimeout(()=>v(te=>te.filter(ue=>ue.id!==M.id)),H)}),m=tt.onSystemMessage((M,H)=>{U(te=>{for(const ue of Object.keys(te))if(ue.includes(M))return{...te,[ue]:[...te[ue]||[],H]};return te})}),k=tt.onClearSystemMessage((M,H)=>{U(te=>{const ue={...te};for(const be of Object.keys(ue))be.includes(M)&&(ue[be]=(ue[be]||[]).filter(ke=>{var Ke;return!(ke.role==="system"&&((Ke=ke._localId)!=null&&Ke.startsWith(H)))}));return ue})});return()=>{b(),m(),k()}},[]),n.useEffect(()=>{const b=Cn.on("status_event",m=>tt.handleRawEvent(m,"ws"));return()=>{b()}},[]),n.useEffect(()=>{var m;const b=k=>{const M=k.data;(M==null?void 0:M.type)==="notification_action"&&M.action==="approve"&&M.ideId&&t(M.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(H=>console.error("[SW Action] approve failed:",H))};return(m=navigator.serviceWorker)==null||m.addEventListener("message",b),()=>{var k;return(k=navigator.serviceWorker)==null?void 0:k.removeEventListener("message",b)}},[]);const{isCreatingChat:Ee,isRefreshingHistory:W,handleLaunchIde:re,handleSwitchSession:ee,handleNewChat:xe,handleRefreshHistory:ye}=Es({sendDaemonCommand:t,activeConv:Ae,ides:u,updateIdeChats:c,setToasts:v,setLocalUserMessages:U,setClearedTabs:we,setActionLogs:g,pinTab:Oe,isStandalone:oe}),pe=n.useMemo(()=>u.filter(b=>b.type==="adhdev-daemon"&&b.versionMismatch),[u]),[C,E]=n.useState(!1),[G,q]=n.useState({}),Q=n.useCallback(async b=>{var m,k;q(M=>({...M,[b]:"upgrading"}));try{const M=await t(b,"daemon_upgrade",{});(m=M==null?void 0:M.result)!=null&&m.upgraded||(k=M==null?void 0:M.result)!=null&&k.success?q(H=>({...H,[b]:"done"})):q(H=>({...H,[b]:"error"}))}catch{q(M=>({...M,[b]:"error"}))}},[t]);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(Nn,{wsStatus:f,showReconnected:$}),pe.length>0&&!C&&e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx(hs,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",pe[0].version]})," → ",e.jsxs("strong",{children:["v",pe[0].serverVersion]})]}),pe.map(b=>{var M;const m=b.machineNickname||((M=b.machine)==null?void 0:M.hostname)||b.hostname||"Machine",k=G[b.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:m}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",b.version]}),k==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):k==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):k==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>Q(b.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>Q(b.id),children:"Upgrade"})]},b.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>E(!0),title:"Dismiss",children:"✕"})]}),e.jsx(Tn,{activeConv:Ae,agentCount:he.length,wsStatus:f,isConnected:p,onOpenHistory:()=>j(!0)}),e.jsx("div",{ref:ae,className:`flex-1 min-h-0 flex ${Z?"flex-row":"flex-col"} overflow-hidden`,children:Se.map((b,m)=>{const k=Z&&ne.length===y?`${ne[m]}%`:void 0;return e.jsxs(Bs.Fragment,{children:[Z&&m>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:M=>se(m-1,M),onDoubleClick:()=>K(m),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(wr,{style:Z?{flexBasis:k??`${100/y}%`,flexGrow:k?0:1,flexShrink:k?0:1}:void 0,conversations:b,ides:u,messageReceivedAt:ie,actionLogs:B,ptyBuffers:Re,screenshotMap:r,setScreenshotMap:x,sendDaemonCommand:t,updateIdeChats:c,setToasts:v,setLocalUserMessages:U,setClearedTabs:we,setActionLogs:g,pinTab:Oe,isStandalone:oe,userName:i.userName,groupIndex:m,isFocused:O===m,onFocus:()=>F(m),isSplitMode:Z,numGroups:y,onMoveTab:(M,H)=>{H==="left"&&m>0?le(M,m-1):H==="right"&&m<y-1?le(M,m+1):H==="split-left"&&y<4?Ce(M,m,"left"):H==="split-right"&&y<4&&Ce(M,m,"right")},onClose:Z?()=>K(m):void 0,onReceiveTab:M=>le(M,m),detectedIdes:m===0?je:void 0,handleLaunchIde:m===0?re:void 0,onActiveTabChange:M=>T(H=>({...H,[m]:M})),initialActiveTabId:R[m],initialTabOrder:I[m],onTabOrderChange:M=>N(H=>({...H,[m]:M})),onHideTab:ge})]},m)})}),P&&Ae&&e.jsx($n,{activeConv:Ae,ides:u,isCreatingChat:Ee,isRefreshingHistory:W,onClose:()=>j(!1),onNewChat:xe,onSwitchSession:ee,onRefreshHistory:ye}),e.jsx("style",{children:`
55
55
  body { overflow: hidden; overscroll-behavior: none; }
56
56
  .pulse-amber { animation: pulse-amber 2s infinite ease-in-out; }
57
57
  @keyframes pulse-amber {
@@ -59,13 +59,13 @@ This will terminate the CLI process.`))return;const E=oe.ideId||oe.daemonId||"";
59
59
  70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
60
60
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
61
61
  }
62
- `}),e.jsx(Mn,{toasts:l,onDismiss:b=>j(m=>m.filter(k=>k.id!==b)),onClickToast:b=>{if(b.ideId){const m=L.find(k=>k.ideId===b.ideId||k.tabKey===b.ideId);m&&F(w.get(m.tabKey)??0)}}}),e.jsx("style",{children:`
62
+ `}),e.jsx(_n,{toasts:l,onDismiss:b=>v(m=>m.filter(k=>k.id!==b)),onClickToast:b=>{if(b.ideId){const m=L.find(k=>k.ideId===b.ideId||k.tabKey===b.ideId);m&&F(w.get(m.tabKey)??0)}}}),e.jsx("style",{children:`
63
63
  @keyframes toast -in {
64
64
  from { opacity: 0; transform: translateX(40px); }
65
65
  to { opacity: 1; transform: translateX(0); }
66
66
  }
67
- `}),h&&e.jsx(br,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function vr(t){return t.split(":")[0]||""}function jr({renderHeaderActions:t}={}){var je,ve,oe,he;const{id:s}=ls(),o=mt(),a=kt(),i=a.ides||[],c=a.connectionStates||{},{sendCommand:r}=Xe(),x=n.useMemo(()=>vr(s||""),[s]),u=n.useMemo(()=>i.find(L=>L.id===s),[i,s]),h=(u==null?void 0:u.type)||void 0,d=h?h.charAt(0).toUpperCase()+h.slice(1):"IDE",l=(u==null?void 0:u.activeChat)||null,j=(u==null?void 0:u.agentStreams)||[],f=a.isConnected??!0,p=c[x]||(f?"connected":"new"),A=((je=a.connectionTransports)==null?void 0:je[x])||"unknown",$=n.useMemo(()=>i.find(L=>L.id===x||L.daemonId===x),[i,x]),w=($==null?void 0:$.machineNickname)||((ve=$==null?void 0:$.machine)==null?void 0:ve.hostname)||"",S=(u==null?void 0:u.workspace)||"",[O]=cs(),F=typeof window<"u"&&window.innerWidth<=768,R=O.get("view")||(F?"chat":"split"),[T,D]=n.useState(R),[I,N]=n.useState("native"),[ne,_]=n.useState(""),[X,Y]=n.useState(!1),[y,Z]=n.useState(null),[le,V]=n.useState(null),[J,K]=n.useState([]),ae=l==null?void 0:l.status,se=(((he=(oe=l==null?void 0:l.activeModal)==null?void 0:oe.buttons)==null?void 0:he.length)??0)>0,ie=ae==="generating"||ae==="loading"||ae&&ae.toLowerCase()==="thinking",P=se||ae==="waiting_approval"?"waiting_approval":ie?"working":ae||"idle",v=n.useMemo(()=>{var L,me;return{ideId:s||"",daemonId:x,agentName:Rt(h||""),agentType:h||"",status:P,title:(l==null?void 0:l.title)||"",messages:(l==null?void 0:l.messages)||[],ideType:h||"",workspaceName:(u==null?void 0:u.workspaceName)||"",displayPrimary:d,displaySecondary:(u==null?void 0:u.workspaceName)||"",cdpConnected:!0,modalButtons:(L=l==null?void 0:l.activeModal)==null?void 0:L.buttons,modalMessage:(me=l==null?void 0:l.activeModal)==null?void 0:me.message,streamSource:"native",tabKey:`ide-${s}`}},[s,x,h,l,u,d,P]),B=n.useMemo(()=>j.map(L=>{var ge,fe;const me=L.activeModal?"waiting_approval":L.status==="streaming"?"working":L.status||"idle";return{ideId:s||"",daemonId:x,agentName:L.agentName,agentType:L.agentType,status:me,title:"",messages:L.messages.map((Ce,$e)=>({role:Ce.role,content:Ce.content,kind:Ce.kind,id:`${L.agentType}-${$e}`,receivedAt:Ce.timestamp})),ideType:L.agentType,workspaceName:"",displayPrimary:L.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(ge=L.activeModal)==null?void 0:ge.buttons,modalMessage:(fe=L.activeModal)==null?void 0:fe.message,streamSource:"agent-stream",tabKey:`agent-stream-${L.agentType}`}}),[j,s,x]),g=n.useMemo(()=>I==="native"?v:B.find(L=>L.agentType===I)||v,[I,v,B]);n.useEffect(()=>x?Te.onScreenshot("ide-page",(me,ge)=>{if(me!==x)return;const fe=new FileReader;fe.onload=()=>Z(fe.result),fe.readAsDataURL(ge)}):void 0,[x]),n.useEffect(()=>{p!=="connected"&&Z(null)},[p]),n.useEffect(()=>{var me;return x?((me=Te.onStatus)==null?void 0:me.call(Te,(ge,fe)=>{ge===x&&fe!=null&&fe.screenshotUsage&&V(fe.screenshotUsage)}))||(()=>{}):void 0},[x]);const U=n.useMemo(()=>{if(!s)return h;const L=s.split(":");return L.length>=3&&L[1]==="ide"?L.slice(2).join(":"):h},[s,h]);n.useEffect(()=>{Z(null)},[x,s,U]),n.useEffect(()=>{const L=x?Te.get(x):null;!L||!(p==="connected")||(T!=="chat"&&U?L.startScreenshots(U):L.stopScreenshots(U))},[T,p,U,x]);const z=n.useCallback(async(L,me={})=>{if(!s)throw new Error("No IDE ID");return await r(s,L,me)},[s]),de=async()=>{const L=ne.trim();if(!(!L||!s||X)){_(""),Y(!0);try{await z("send_chat",{message:L,text:L,waitForResponse:!0,...I!=="native"&&{agentType:I}})}catch(me){console.error("[IDE] Send failed:",me)}finally{Y(!1)}}},we=j.length>0;return s?e.jsxs("div",{className:"ide-page",children:[e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(jt,{size:16}),e.jsx("span",{className:"ide-name",children:d}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),S&&e.jsx("span",{className:"ide-workspace",children:S}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${p==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:p==="connected"?"Connected":p==="connecting"?"Connecting":"WS"})]}),w&&e.jsx("span",{className:"ide-machine-label",children:w})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(L=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:T===L?"1px solid var(--accent-primary)":"none",background:T===L?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:T===L?"var(--accent-primary)":void 0},onClick:()=>D(L),children:L==="chat"?e.jsx(jt,{size:14}):L==="split"?"⊞":e.jsx(nt,{size:14})},L)),t&&t({daemonId:x,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>o(-1),children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${T==="chat"?"full":""} ${T==="remote"?"hidden":""}`,children:[we&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${I==="native"?"active":""}`,onClick:()=>N("native"),children:d}),j.map(L=>{const me=I===L.agentType,ge=L.status==="waiting_approval"||!!L.activeModal,fe=L.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${me?"active":""}`,onClick:()=>N(L.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ge?"#f59e0b":fe?"var(--accent-primary)":"#64748b",boxShadow:fe?"0 0 6px var(--accent-primary)":"none"}}),L.agentName,ge&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},L.agentType)})]}),e.jsx(bs,{activeConv:g,ides:i,agentInput:ne,setAgentInput:_,handleSendChat:de,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:a.userName})]}),e.jsx("div",{className:`ide-remote-panel ${T==="remote"?"full":""} ${T==="chat"?"hidden":""}`,children:e.jsx(mn,{addLog:()=>{},connState:p,connScreenshot:y,screenshotUsage:le,transportType:A,onAction:async(L,me)=>{const ge=x?Te.get(x):null;if(!ge||p!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const fe=(u==null?void 0:u.instanceId)||U;return await ge.sendInput(L,me,fe)}})})]}),J.length>0&&e.jsx("div",{className:"ide-toasts",children:J.map(L=>e.jsx("div",{className:`ide-toast ${L.type}`,onClick:()=>K(me=>me.filter(ge=>ge.id!==L.id)),children:L.message},L.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function wr({machineId:t,sendDaemonCommand:s,logsEndRef:o}){const[a,i]=n.useState([]),[c,r]=n.useState(null),[x,u]=n.useState(!1),[h,d]=n.useState(!1),[l,j]=n.useState(!1),[f,p]=n.useState([]),[A,$]=n.useState([]),[w,S]=n.useState(null),[O,F]=n.useState(!1),[R,T]=n.useState(""),D=n.useRef(null),I=n.useCallback(P=>{D.current=P},[]),N=n.useCallback((P,v)=>{i(B=>[...B.slice(-100),{timestamp:Date.now(),level:P,message:v}]),setTimeout(()=>{var B;return(B=o.current)==null?void 0:B.scrollIntoView({behavior:"smooth"})},100)},[o]),ne=n.useCallback(async(P,v)=>{var B;if(!(!t||c)){r(P),N("info",`Launching ${Le(P)}${v!=null&&v.workspace?` in ${v.workspace}`:""}...`);try{const g={ideType:P,enableCdp:!0};(B=v==null?void 0:v.workspace)!=null&&B.trim()?g.workspace=v.workspace.trim():v!=null&&v.useDefaultWorkspace&&(g.useDefaultWorkspace=!0);const U=await s(t,"launch_ide",g);N(U!=null&&U.success?"info":"error",U!=null&&U.success?`${Le(P)} launched`:`Failed: ${U==null?void 0:U.error}`)}catch(g){N("error",`Launch error: ${g.message}`)}finally{r(null)}}},[t,c,N,s]),_=n.useCallback(async P=>{if(!t)return;const{cliType:v,dir:B,workspaceId:g,useDefaultWorkspace:U,useHome:z,argsStr:de,model:we}=P;if(!v){N("warn","Select a CLI or ACP provider first");return}const je=de?de.split(/\s+/).filter(Boolean):void 0,ve=(B==null?void 0:B.trim())||(g?"(saved id)":U?"(default workspace)":z?"(home)":"");N("info",`Launching ${v}${ve?` in ${ve}`:""}${we?` (model: ${we})`:""}...`);try{const oe={cliType:v,cliArgs:je,initialModel:we||void 0};B!=null&&B.trim()?oe.dir=B.trim():g?oe.workspaceId=g:U?oe.useDefaultWorkspace=!0:z&&(oe.useHome=!0);const he=await s(t,"launch_cli",oe),L=(he==null?void 0:he.result)||he;he!=null&&he.success?(N("info",`${v} launched`),(L==null?void 0:L.launchSource)==="home"?N("info","📂 Running in home directory (explicit choice)"):(L==null?void 0:L.launchSource)==="defaultWorkspace"&&N("info","📂 Using default workspace (explicit choice)")):(N("error",`Failed: ${(he==null?void 0:he.error)||(L==null?void 0:L.error)}`),(he==null?void 0:he.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&S({cliType:v,argsStr:de,model:we}))}catch(oe){N("error",`Launch error: ${oe.message}`)}},[t,N,s]),X=n.useCallback((P,v,B,g)=>{if(t){if(!P){N("warn","Select a provider");return}if(!v.trim()){S({cliType:P,argsStr:B,model:g});return}_({cliType:P,dir:v,argsStr:B,model:g})}},[t,N,_]),Y=n.useCallback(async(P,v,B)=>{if(t&&window.confirm(`Stop ${P}?
68
- This will terminate the process.`))try{const g=await s(t,"stop_cli",{cliType:P,dir:v,_targetInstance:B});g!=null&&g.success?N("info",`${P} stopped`):N("error",`Stop failed: ${(g==null?void 0:g.error)||"Unknown error"}`)}catch(g){N("error",`Stop failed: ${g.message}`)}},[t,N,s]),y=n.useCallback(async P=>{try{await s(P.daemonId,"restart_ide",{ideType:P.type}),N("info",`${Le(P.type)} restart initiated`)}catch(v){N("error",`Restart failed: ${v.message}`)}},[N,s]),Z=n.useCallback(async P=>{if(window.confirm(`Stop ${Le(P.type)}?
69
- This will disconnect CDP and optionally kill the process.`))try{const v=await s(P.daemonId,"stop_ide",{ideType:P.type,killProcess:!0});v!=null&&v.success?N("info",`${Le(P.type)} stopped`):N("error",`Stop failed: ${(v==null?void 0:v.error)||"Unknown error"}`)}catch(v){N("error",`Stop failed: ${v.message}`)}},[N,s]),le=n.useCallback(async()=>{if(t)try{const P=await s(t,"detect_ides",{});N("info",`Found ${((P==null?void 0:P.result)||[]).length} IDE(s)`)}catch(P){N("error",`Detection failed: ${P.message}`)}},[t,N,s]),V=n.useCallback(async()=>{if(t){u(!0);try{const P=await s(t,"get_recent_workspaces",{});P!=null&&P.success&&Array.isArray(P==null?void 0:P.result)&&$(P.result)}catch(P){N("error",`Failed: ${P.message}`)}finally{u(!1)}}},[t,N,s]),J=n.useCallback(async P=>{if(!(!t||!P.trim())){d(!0);try{const v=await s(t,"workspace_add",{path:P.trim()});v!=null&&v.success?N("info",`Workspace added: ${P.trim()}`):N("error",(v==null?void 0:v.error)||"workspace_add failed")}catch(v){N("error",v.message)}finally{d(!1)}return!0}},[t,N,s]),K=n.useCallback(async P=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){d(!0);try{const v=await s(t,"workspace_remove",{id:P});v!=null&&v.success?N("info","Workspace removed"):N("error",(v==null?void 0:v.error)||"workspace_remove failed")}catch(v){N("error",v.message)}finally{d(!1)}}},[t,N,s]),ae=n.useCallback(async P=>{var v;if(t){d(!0);try{const B=await s(t,"workspace_set_default",P===null?{clear:!0}:{id:P});if(B!=null&&B.success){N("info",P?"Default workspace updated":"Default workspace cleared");const g=typeof B.defaultWorkspacePath=="string"?B.defaultWorkspacePath:"";g&&((v=D.current)==null||v.call(D,g))}else N("error",(B==null?void 0:B.error)||"workspace_set_default failed")}catch(B){N("error",B.message)}finally{d(!1)}}},[t,N,s]),se=n.useCallback(async P=>{var B;if(!t||!P.trim())return;const v=P.trim();d(!0);try{const g=await s(t,"workspace_set_default",{path:v});g!=null&&g.success?(N("info","Default workspace set from history"),(B=D.current)==null||B.call(D,v)):N("error",(g==null?void 0:g.error)||"Could not set default (path missing on disk?)")}catch(g){N("error",g.message)}finally{d(!1)}},[t,N,s]),ie=n.useCallback(async()=>{var P;if(t){j(!0);try{const v=await s(t,"get_cli_history",{}),B=(v==null?void 0:v.history)??((P=v==null?void 0:v.result)==null?void 0:P.history);v!=null&&v.success&&Array.isArray(B)&&p(B)}catch{}j(!1)}},[t,s]),ce=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:R}),N("info",`Nickname set to "${R||"(cleared)"}"`),F(!1)}catch(P){N("error",`Failed: ${P.message}`)}},[t,R,N,s]);return{logs:a,launchingIde:c,loadingWorkspaces:x,workspaceBusy:h,loadingHistory:l,cliHistory:f,recentWorkspaces:A,launchPick:w,setLaunchPick:S,editingNickname:O,setEditingNickname:F,nicknameInput:R,setNicknameInput:T,addLog:N,handleLaunchIde:ne,runLaunchCliCore:_,handleLaunchCli:X,handleStopCli:Y,handleRestartIde:y,handleStopIde:Z,handleDetectIdes:le,handleLoadRecentWorkspaces:V,handleWorkspaceAdd:J,handleWorkspaceRemove:K,handleWorkspaceSetDefault:ae,handleWorkspaceResumePath:se,loadCliHistory:ie,handleSaveNickname:ce,setOnDefaultWorkspaceChanged:I}}function Nr({machine:t,managedIdes:s,managedClis:o,managedAcps:a,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:r,handleWorkspaceRemove:x,handleWorkspaceSetDefault:u}=i,[h,d]=n.useState(""),l=t.availableMem??t.freeMem,j=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,f=t.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(pt,{icon:e.jsx(hs,{size:16}),label:"Uptime",value:Sn(t.uptime)}),e.jsx(pt,{icon:e.jsx(nt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(pt,{icon:e.jsx(Kt,{size:16}),label:"CLIs",value:`${o.length}`}),e.jsx(pt,{icon:e.jsx(fs,{size:16}),label:"ACPs",value:`${a.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(Xt,{value:Math.min(Math.round(f/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${f.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Xt,{value:j,max:100,label:"Memory",color:"#3b82f6",detail:`${Vt(t.totalMem-l)} / ${Vt(t.totalMem)}${t.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(_t,{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:c,value:t.defaultWorkspaceId||"",onChange:p=>void u(p.target.value===""?null:p.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(p=>e.jsx("option",{value:p.id,children:p.label||p.path},p.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:c,onChange:p=>d(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await r(h)&&d("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await r(h)&&d("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(p=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[p.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:p.path,children:p.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:c,onClick:()=>void x(p.id),children:"Remove"})]},p.id))})]})]})}const kr={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 $t({category:t,machine:s,machineId:o,providers:a,managedEntries:i,getIcon:c,actions:r,sendDaemonCommand:x}){const u=mt(),{handleLaunchIde:h,handleLaunchCli:d,handleStopCli:l,handleRestartIde:j,handleStopIde:f,handleDetectIdes:p,cliHistory:A,loadingHistory:$,loadCliHistory:w,launchingIde:S}=r,O=kr[t],F=t==="ide",R=t==="acp",T=a.filter(g=>g.category===t),[D,I]=n.useState(""),[N,ne]=n.useState(""),[_,X]=n.useState(""),[Y,y]=n.useState(s.defaultWorkspaceId||""),[Z,le]=n.useState("");n.useEffect(()=>{!D&&T.length>0&&I(T[0].type)},[D,T.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!Y&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const V=(()=>{if(Y==="__custom__")return Z.trim();if(!Y)return"";const g=(s.workspaces||[]).find(U=>U.id===Y);return(g==null?void 0:g.path)||""})(),[J,K]=n.useState({}),[ae,se]=n.useState(null);n.useEffect(()=>{if(!F||!o||!x)return;(async()=>{try{const U=await x(o,"get_ide_extensions",{}),z=(U==null?void 0:U.result)||U;z!=null&&z.success&&(z!=null&&z.ides)&&K(z.ides)}catch{}})()},[F,o,x]);const ie=g=>F?Le(g.type):t==="cli"?g.cliName:g.acpName,ce=F?s.detectedIdes||[]:[],P=()=>{F?h(D,V?{workspace:V}:void 0):d(D,V,N||void 0,R&&_||void 0)},v=g=>{F?f(g):l(g.type,g.workspace,g.id)},B=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:Y,onChange:g=>{y(g.target.value),g.target.value!=="__custom__"&&le("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(g=>e.jsxs("option",{value:g.id,children:[g.id===s.defaultWorkspaceId?"⭐ ":"",g.label||g.path.split("/").filter(Boolean).pop()||g.path," — ",g.path]},g.id)),e.jsx("option",{value:"__custom__",children:"✏️ 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:"✏️ Custom path…"})]})}),Y==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Z,onChange:g=>le(g.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${O.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",O.label]}),B,F?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ce.map(g=>{const U=g.running||i.some(z=>(z.type||"").toLowerCase()===(g.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>h(g.type||g.id||"",V?{workspace:V}:void 0),disabled:!!S,className:`machine-btn-primary flex items-center gap-1.5 ${U?"!border-green-500/30":""}`,style:{opacity:S&&S!==g.type?.4:1},children:[e.jsx("span",{children:c(g.type)}),U&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),S===g.type?"⏳ Launching...":`▶ ${g.name||Le(g.type)}`,U&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},g.type)}),ce.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:p,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(nn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:D,onChange:g=>I(g.target.value),className:"machine-input",children:T.length>0?T.map(g=>e.jsxs("option",{value:g.type,children:[g.icon," ",g.displayName]},g.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),R&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:_,onChange:g=>X(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:N,onChange:g=>ne(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:P,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.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 ",O.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(g=>{const U=F?g:null,z=R?g:null;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:c(g.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(g),(U==null?void 0:U.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",U.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:g.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",z.currentPlan]})]})]})]}),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 ${g.status==="stopped"?"bg-red-500/[0.08] text-red-500":g.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:g.status}),F&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${g.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(nt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>j(g),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),R&&e.jsx("button",{onClick:()=>u(`/ide/${g.id}`),className:"machine-btn",title:"View chat",children:e.jsx(jt,{size:14})}),g.status==="stopped"?e.jsx("button",{onClick:()=>F?h(g.type,g.workspace?{workspace:g.workspace}:void 0):d(g.type,g.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>v(g),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),U&&U.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:U.aiAgents.map(de=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${de.status==="generating"||de.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[de.name," · ",de.status]},de.id))}),U&&(J[U.type]||[]).length>0&&x&&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:(J[U.type]||[]).map(de=>e.jsxs("button",{disabled:ae===`${U.type}.${de.type}`,onClick:async()=>{const we=`${U.type}.${de.type}`;se(we);try{await x(o,"set_ide_extension",{ideType:U.type,extensionType:de.type,enabled:!de.enabled}),K(je=>({...je,[U.type]:(je[U.type]||[]).map(ve=>ve.type===de.type?{...ve,enabled:!ve.enabled}:ve)}))}catch(je){console.error("Extension toggle failed:",je)}finally{se(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 ${de.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${de.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),de.name,e.jsx("span",{className:"text-[9px] font-normal",children:de.enabled?"ON":"OFF"})]},de.type))})]})]},g.id)})}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:w,disabled:$,className:"machine-btn",children:$?"⏳":"↻ Load"})]}),(()=>{const g=new Set(T.map(z=>z.type)),U=A.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:g.has(z.cliType));return U.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:U.map((z,de)=>{var we,je;return e.jsxs("div",{onClick:()=>{I(z.cliType),(z.workspace||z.dir)&&(y("__custom__"),le(z.workspace||z.dir)),ne((z.cliArgs||[]).join(" ")),X(z.model||""),F&&h(z.cliType,z.workspace?{workspace:z.workspace}:void 0)},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:c(z.cliType)}),e.jsx("span",{children:((we=z.workspace||z.dir)==null?void 0:we.split("/").filter(Boolean).pop())||z.cliType||"root"}),z.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",z.model]}),z.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((je=z.cliArgs)==null?void 0:je.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:z.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:z.timestamp?new Date(z.timestamp).toLocaleDateString():""})]},de)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",O.label," launch history yet."]})})()]})]})}const rs=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Sr=[{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 Cr({machineId:t,provider:s,sendDaemonCommand:o,onClose:a}){const[i,c]=n.useState("config"),[r,x]=n.useState("codex-cli"),[u,h]=n.useState([]),[d,l]=n.useState(""),[j,f]=n.useState([]),[p,A]=n.useState(""),$=n.useRef(null),w=n.useRef(null),S=I=>{h(N=>N.includes(I)?N.filter(ne=>ne!==I):[...N,I])},O=()=>h([...rs]),F=()=>h([]);n.useEffect(()=>{var I;(I=$.current)==null||I.scrollIntoView({behavior:"smooth"})},[j]),n.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const R=n.useCallback(()=>{w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const I=await o(t,"provider_auto_fix_status",{providerType:s.type});(I==null?void 0:I.running)===!1&&i==="running"&&(c("done"),f(N=>[...N,`
67
+ `}),h&&e.jsx(Nr,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function Sr(t){return t.split(":")[0]||""}function Cr({renderHeaderActions:t}={}){var ve,je,oe,he;const{id:s}=ds(),o=pt(),a=kt(),i=a.ides||[],c=a.connectionStates||{},{sendCommand:r}=Ve(),x=n.useMemo(()=>Sr(s||""),[s]),u=n.useMemo(()=>i.find(L=>L.id===s),[i,s]),h=(u==null?void 0:u.type)||void 0,d=h?h.charAt(0).toUpperCase()+h.slice(1):"IDE",l=(u==null?void 0:u.activeChat)||null,v=(u==null?void 0:u.agentStreams)||[],f=a.isConnected??!0,p=c[x]||(f?"connected":"new"),A=((ve=a.connectionTransports)==null?void 0:ve[x])||"unknown",$=n.useMemo(()=>i.find(L=>L.id===x||L.daemonId===x),[i,x]),w=($==null?void 0:$.machineNickname)||((je=$==null?void 0:$.machine)==null?void 0:je.hostname)||"",S=(u==null?void 0:u.workspace)||"",[O]=ls(),F=typeof window<"u"&&window.innerWidth<=768,R=O.get("view")||(F?"chat":"split"),[T,D]=n.useState(R),[I,N]=n.useState("native"),[ne,_]=n.useState(""),[V,Y]=n.useState(!1),[y,Z]=n.useState(null),[le,X]=n.useState(null),[J,K]=n.useState([]),ae=l==null?void 0:l.status,se=(((he=(oe=l==null?void 0:l.activeModal)==null?void 0:oe.buttons)==null?void 0:he.length)??0)>0,ie=ae==="generating"||ae==="loading"||ae&&ae.toLowerCase()==="thinking",P=se||ae==="waiting_approval"?"waiting_approval":ie?"working":ae||"idle",j=n.useMemo(()=>{var L,me;return{ideId:s||"",daemonId:x,agentName:Rt(h||""),agentType:h||"",status:P,title:(l==null?void 0:l.title)||"",messages:(l==null?void 0:l.messages)||[],ideType:h||"",workspaceName:(u==null?void 0:u.workspaceName)||"",displayPrimary:d,displaySecondary:(u==null?void 0:u.workspaceName)||"",cdpConnected:!0,modalButtons:(L=l==null?void 0:l.activeModal)==null?void 0:L.buttons,modalMessage:(me=l==null?void 0:l.activeModal)==null?void 0:me.message,streamSource:"native",tabKey:`ide-${s}`}},[s,x,h,l,u,d,P]),B=n.useMemo(()=>v.map(L=>{var ge,fe;const me=L.activeModal?"waiting_approval":L.status==="streaming"?"working":L.status||"idle";return{ideId:s||"",daemonId:x,agentName:L.agentName,agentType:L.agentType,status:me,title:"",messages:L.messages.map((Ce,$e)=>({role:Ce.role,content:Ce.content,kind:Ce.kind,id:`${L.agentType}-${$e}`,receivedAt:Ce.timestamp})),ideType:L.agentType,workspaceName:"",displayPrimary:L.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(ge=L.activeModal)==null?void 0:ge.buttons,modalMessage:(fe=L.activeModal)==null?void 0:fe.message,streamSource:"agent-stream",tabKey:`agent-stream-${L.agentType}`}}),[v,s,x]),g=n.useMemo(()=>I==="native"?j:B.find(L=>L.agentType===I)||j,[I,j,B]);n.useEffect(()=>x?Te.onScreenshot("ide-page",(me,ge)=>{if(me!==x)return;const fe=new FileReader;fe.onload=()=>Z(fe.result),fe.readAsDataURL(ge)}):void 0,[x]),n.useEffect(()=>{p!=="connected"&&Z(null)},[p]),n.useEffect(()=>{var me;return x?((me=Te.onStatus)==null?void 0:me.call(Te,(ge,fe)=>{ge===x&&fe!=null&&fe.screenshotUsage&&X(fe.screenshotUsage)}))||(()=>{}):void 0},[x]);const z=n.useMemo(()=>{if(!s)return h;const L=s.split(":");return L.length>=3&&L[1]==="ide"?L.slice(2).join(":"):h},[s,h]);n.useEffect(()=>{Z(null)},[x,s,z]),n.useEffect(()=>{const L=x?Te.get(x):null;!L||!(p==="connected")||(T!=="chat"&&z?L.startScreenshots(z):L.stopScreenshots(z))},[T,p,z,x]);const U=n.useCallback(async(L,me={})=>{if(!s)throw new Error("No IDE ID");return await r(s,L,me)},[s]),de=async()=>{const L=ne.trim();if(!(!L||!s||V)){_(""),Y(!0);try{await U("send_chat",{message:L,text:L,waitForResponse:!0,...I!=="native"&&{agentType:I}})}catch(me){console.error("[IDE] Send failed:",me)}finally{Y(!1)}}},we=v.length>0;return s?e.jsxs("div",{className:"ide-page",children:[e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(wt,{size:16}),e.jsx("span",{className:"ide-name",children:d}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),S&&e.jsx("span",{className:"ide-workspace",children:S}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${p==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:p==="connected"?"Connected":p==="connecting"?"Connecting":"WS"})]}),w&&e.jsx("span",{className:"ide-machine-label",children:w})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(L=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:T===L?"1px solid var(--accent-primary)":"none",background:T===L?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:T===L?"var(--accent-primary)":void 0},onClick:()=>D(L),children:L==="chat"?e.jsx(wt,{size:14}):L==="split"?"⊞":e.jsx(Qe,{size:14})},L)),t&&t({daemonId:x,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>o(-1),children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${T==="chat"?"full":""} ${T==="remote"?"hidden":""}`,children:[we&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${I==="native"?"active":""}`,onClick:()=>N("native"),children:d}),v.map(L=>{const me=I===L.agentType,ge=L.status==="waiting_approval"||!!L.activeModal,fe=L.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${me?"active":""}`,onClick:()=>N(L.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ge?"#f59e0b":fe?"var(--accent-primary)":"#64748b",boxShadow:fe?"0 0 6px var(--accent-primary)":"none"}}),L.agentName,ge&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},L.agentType)})]}),e.jsx(ys,{activeConv:g,ides:i,agentInput:ne,setAgentInput:_,handleSendChat:de,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:a.userName})]}),e.jsx("div",{className:`ide-remote-panel ${T==="remote"?"full":""} ${T==="chat"?"hidden":""}`,children:e.jsx(bn,{addLog:()=>{},connState:p,connScreenshot:y,screenshotUsage:le,transportType:A,onAction:async(L,me)=>{const ge=x?Te.get(x):null;if(!ge||p!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const fe=(u==null?void 0:u.instanceId)||z;return await ge.sendInput(L,me,fe)}})})]}),J.length>0&&e.jsx("div",{className:"ide-toasts",children:J.map(L=>e.jsx("div",{className:`ide-toast ${L.type}`,onClick:()=>K(me=>me.filter(ge=>ge.id!==L.id)),children:L.message},L.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function Ir({machineId:t,sendDaemonCommand:s,logsEndRef:o}){const[a,i]=n.useState([]),[c,r]=n.useState(null),[x,u]=n.useState(!1),[h,d]=n.useState(!1),[l,v]=n.useState(!1),[f,p]=n.useState([]),[A,$]=n.useState([]),[w,S]=n.useState(null),[O,F]=n.useState(!1),[R,T]=n.useState(""),D=n.useRef(null),I=n.useCallback(P=>{D.current=P},[]),N=n.useCallback((P,j)=>{i(B=>[...B.slice(-100),{timestamp:Date.now(),level:P,message:j}]),setTimeout(()=>{var B;return(B=o.current)==null?void 0:B.scrollIntoView({behavior:"smooth"})},100)},[o]),ne=n.useCallback(async(P,j)=>{var B;if(!(!t||c)){r(P),N("info",`Launching ${Le(P)}${j!=null&&j.workspace?` in ${j.workspace}`:""}...`);try{const g={ideType:P,enableCdp:!0};(B=j==null?void 0:j.workspace)!=null&&B.trim()?g.workspace=j.workspace.trim():j!=null&&j.useDefaultWorkspace&&(g.useDefaultWorkspace=!0);const z=await s(t,"launch_ide",g);N(z!=null&&z.success?"info":"error",z!=null&&z.success?`${Le(P)} launched`:`Failed: ${z==null?void 0:z.error}`)}catch(g){N("error",`Launch error: ${g.message}`)}finally{r(null)}}},[t,c,N,s]),_=n.useCallback(async P=>{if(!t)return;const{cliType:j,dir:B,workspaceId:g,useDefaultWorkspace:z,useHome:U,argsStr:de,model:we}=P;if(!j){N("warn","Select a CLI or ACP provider first");return}const ve=de?de.split(/\s+/).filter(Boolean):void 0,je=(B==null?void 0:B.trim())||(g?"(saved id)":z?"(default workspace)":U?"(home)":"");N("info",`Launching ${j}${je?` in ${je}`:""}${we?` (model: ${we})`:""}...`);try{const oe={cliType:j,cliArgs:ve,initialModel:we||void 0};B!=null&&B.trim()?oe.dir=B.trim():g?oe.workspaceId=g:z?oe.useDefaultWorkspace=!0:U&&(oe.useHome=!0);const he=await s(t,"launch_cli",oe),L=(he==null?void 0:he.result)||he;he!=null&&he.success?(N("info",`${j} launched`),(L==null?void 0:L.launchSource)==="home"?N("info","📂 Running in home directory (explicit choice)"):(L==null?void 0:L.launchSource)==="defaultWorkspace"&&N("info","📂 Using default workspace (explicit choice)")):(N("error",`Failed: ${(he==null?void 0:he.error)||(L==null?void 0:L.error)}`),(he==null?void 0:he.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&S({cliType:j,argsStr:de,model:we}))}catch(oe){N("error",`Launch error: ${oe.message}`)}},[t,N,s]),V=n.useCallback((P,j,B,g)=>{if(t){if(!P){N("warn","Select a provider");return}if(!j.trim()){S({cliType:P,argsStr:B,model:g});return}_({cliType:P,dir:j,argsStr:B,model:g})}},[t,N,_]),Y=n.useCallback(async(P,j,B)=>{if(t&&window.confirm(`Stop ${P}?
68
+ This will terminate the process.`))try{const g=await s(t,"stop_cli",{cliType:P,dir:j,_targetInstance:B});g!=null&&g.success?N("info",`${P} stopped`):N("error",`Stop failed: ${(g==null?void 0:g.error)||"Unknown error"}`)}catch(g){N("error",`Stop failed: ${g.message}`)}},[t,N,s]),y=n.useCallback(async P=>{try{await s(P.daemonId,"restart_ide",{ideType:P.type}),N("info",`${Le(P.type)} restart initiated`)}catch(j){N("error",`Restart failed: ${j.message}`)}},[N,s]),Z=n.useCallback(async P=>{if(window.confirm(`Stop ${Le(P.type)}?
69
+ This will disconnect CDP and optionally kill the process.`))try{const j=await s(P.daemonId,"stop_ide",{ideType:P.type,killProcess:!0});j!=null&&j.success?N("info",`${Le(P.type)} stopped`):N("error",`Stop failed: ${(j==null?void 0:j.error)||"Unknown error"}`)}catch(j){N("error",`Stop failed: ${j.message}`)}},[N,s]),le=n.useCallback(async()=>{if(t)try{const P=await s(t,"detect_ides",{});N("info",`Found ${((P==null?void 0:P.result)||[]).length} IDE(s)`)}catch(P){N("error",`Detection failed: ${P.message}`)}},[t,N,s]),X=n.useCallback(async()=>{if(t){u(!0);try{const P=await s(t,"get_recent_workspaces",{});P!=null&&P.success&&Array.isArray(P==null?void 0:P.result)&&$(P.result)}catch(P){N("error",`Failed: ${P.message}`)}finally{u(!1)}}},[t,N,s]),J=n.useCallback(async P=>{if(!(!t||!P.trim())){d(!0);try{const j=await s(t,"workspace_add",{path:P.trim()});j!=null&&j.success?N("info",`Workspace added: ${P.trim()}`):N("error",(j==null?void 0:j.error)||"workspace_add failed")}catch(j){N("error",j.message)}finally{d(!1)}return!0}},[t,N,s]),K=n.useCallback(async P=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){d(!0);try{const j=await s(t,"workspace_remove",{id:P});j!=null&&j.success?N("info","Workspace removed"):N("error",(j==null?void 0:j.error)||"workspace_remove failed")}catch(j){N("error",j.message)}finally{d(!1)}}},[t,N,s]),ae=n.useCallback(async P=>{var j;if(t){d(!0);try{const B=await s(t,"workspace_set_default",P===null?{clear:!0}:{id:P});if(B!=null&&B.success){N("info",P?"Default workspace updated":"Default workspace cleared");const g=typeof B.defaultWorkspacePath=="string"?B.defaultWorkspacePath:"";g&&((j=D.current)==null||j.call(D,g))}else N("error",(B==null?void 0:B.error)||"workspace_set_default failed")}catch(B){N("error",B.message)}finally{d(!1)}}},[t,N,s]),se=n.useCallback(async P=>{var B;if(!t||!P.trim())return;const j=P.trim();d(!0);try{const g=await s(t,"workspace_set_default",{path:j});g!=null&&g.success?(N("info","Default workspace set from history"),(B=D.current)==null||B.call(D,j)):N("error",(g==null?void 0:g.error)||"Could not set default (path missing on disk?)")}catch(g){N("error",g.message)}finally{d(!1)}},[t,N,s]),ie=n.useCallback(async()=>{var P;if(t){v(!0);try{const j=await s(t,"get_cli_history",{}),B=(j==null?void 0:j.history)??((P=j==null?void 0:j.result)==null?void 0:P.history);j!=null&&j.success&&Array.isArray(B)&&p(B)}catch{}v(!1)}},[t,s]),ce=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:R}),N("info",`Nickname set to "${R||"(cleared)"}"`),F(!1)}catch(P){N("error",`Failed: ${P.message}`)}},[t,R,N,s]);return{logs:a,launchingIde:c,loadingWorkspaces:x,workspaceBusy:h,loadingHistory:l,cliHistory:f,recentWorkspaces:A,launchPick:w,setLaunchPick:S,editingNickname:O,setEditingNickname:F,nicknameInput:R,setNicknameInput:T,addLog:N,handleLaunchIde:ne,runLaunchCliCore:_,handleLaunchCli:V,handleStopCli:Y,handleRestartIde:y,handleStopIde:Z,handleDetectIdes:le,handleLoadRecentWorkspaces:X,handleWorkspaceAdd:J,handleWorkspaceRemove:K,handleWorkspaceSetDefault:ae,handleWorkspaceResumePath:se,loadCliHistory:ie,handleSaveNickname:ce,setOnDefaultWorkspaceChanged:I}}function Mr({machine:t,managedIdes:s,managedClis:o,managedAcps:a,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:r,handleWorkspaceRemove:x,handleWorkspaceSetDefault:u}=i,[h,d]=n.useState(""),l=t.availableMem??t.freeMem,v=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,f=t.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(ht,{icon:e.jsx(fs,{size:16}),label:"Uptime",value:En(t.uptime)}),e.jsx(ht,{icon:e.jsx(Qe,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ht,{icon:e.jsx(Ft,{size:16}),label:"CLIs",value:`${o.length}`}),e.jsx(ht,{icon:e.jsx(gs,{size:16}),label:"ACPs",value:`${a.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(Xt,{value:Math.min(Math.round(f/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${f.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Xt,{value:v,max:100,label:"Memory",color:"#3b82f6",detail:`${qt(t.totalMem-l)} / ${qt(t.totalMem)}${t.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(_t,{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:c,value:t.defaultWorkspaceId||"",onChange:p=>void u(p.target.value===""?null:p.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(p=>e.jsx("option",{value:p.id,children:p.label||p.path},p.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:c,onChange:p=>d(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await r(h)&&d("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await r(h)&&d("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(p=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[p.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:p.path,children:p.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:c,onClick:()=>void x(p.id),children:"Remove"})]},p.id))})]})]})}const Tr={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 $t({category:t,machine:s,machineId:o,providers:a,managedEntries:i,getIcon:c,actions:r,sendDaemonCommand:x}){const u=pt(),{handleLaunchIde:h,handleLaunchCli:d,handleStopCli:l,handleRestartIde:v,handleStopIde:f,handleDetectIdes:p,cliHistory:A,loadingHistory:$,loadCliHistory:w,launchingIde:S}=r,O=Tr[t],F=t==="ide",R=t==="acp",T=a.filter(g=>g.category===t),[D,I]=n.useState(""),[N,ne]=n.useState(""),[_,V]=n.useState(""),[Y,y]=n.useState(s.defaultWorkspaceId||""),[Z,le]=n.useState("");n.useEffect(()=>{!D&&T.length>0&&I(T[0].type)},[D,T.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!Y&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const X=(()=>{if(Y==="__custom__")return Z.trim();if(!Y)return"";const g=(s.workspaces||[]).find(z=>z.id===Y);return(g==null?void 0:g.path)||""})(),[J,K]=n.useState({}),[ae,se]=n.useState(null);n.useEffect(()=>{if(!F||!o||!x)return;(async()=>{try{const z=await x(o,"get_ide_extensions",{}),U=(z==null?void 0:z.result)||z;U!=null&&U.success&&(U!=null&&U.ides)&&K(U.ides)}catch{}})()},[F,o,x]);const ie=g=>F?Le(g.type):t==="cli"?g.cliName:g.acpName,ce=F?s.detectedIdes||[]:[],P=()=>{F?h(D,X?{workspace:X}:void 0):d(D,X,N||void 0,R&&_||void 0)},j=g=>{F?f(g):l(g.type,g.workspace,g.id)},B=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:Y,onChange:g=>{y(g.target.value),g.target.value!=="__custom__"&&le("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(g=>e.jsxs("option",{value:g.id,children:[g.id===s.defaultWorkspaceId?"⭐ ":"",g.label||g.path.split("/").filter(Boolean).pop()||g.path," — ",g.path]},g.id)),e.jsx("option",{value:"__custom__",children:"✏️ 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:"✏️ Custom path…"})]})}),Y==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Z,onChange:g=>le(g.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${O.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",O.label]}),B,F?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ce.map(g=>{const z=g.running||i.some(U=>(U.type||"").toLowerCase()===(g.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>h(g.type||g.id||"",X?{workspace:X}:void 0),disabled:!!S,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:S&&S!==g.type?.4:1},children:[e.jsx("span",{children:c(g.type)}),z&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),S===g.type?"⏳ Launching...":`▶ ${g.name||Le(g.type)}`,z&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},g.type)}),ce.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:p,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(an,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:D,onChange:g=>I(g.target.value),className:"machine-input",children:T.length>0?T.map(g=>e.jsxs("option",{value:g.type,children:[g.icon," ",g.displayName]},g.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),R&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:_,onChange:g=>V(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:N,onChange:g=>ne(g.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:P,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.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 ",O.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(g=>{const z=F?g:null,U=R?g:null;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:c(g.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(g),(z==null?void 0:z.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",z.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:g.workspace||"—"}),(U==null?void 0:U.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",U.currentModel]}),(U==null?void 0:U.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",U.currentPlan]})]})]})]}),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 ${g.status==="stopped"?"bg-red-500/[0.08] text-red-500":g.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:g.status}),F&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${g.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(Qe,{size:13})," Control"]}),e.jsx("button",{onClick:()=>v(g),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),R&&e.jsx("button",{onClick:()=>u(`/ide/${g.id}`),className:"machine-btn",title:"View chat",children:e.jsx(wt,{size:14})}),g.status==="stopped"?e.jsx("button",{onClick:()=>F?h(g.type,g.workspace?{workspace:g.workspace}:void 0):d(g.type,g.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>j(g),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),z&&z.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:z.aiAgents.map(de=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${de.status==="generating"||de.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[de.name," · ",de.status]},de.id))}),z&&(J[z.type]||[]).length>0&&x&&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:(J[z.type]||[]).map(de=>e.jsxs("button",{disabled:ae===`${z.type}.${de.type}`,onClick:async()=>{const we=`${z.type}.${de.type}`;se(we);try{await x(o,"set_ide_extension",{ideType:z.type,extensionType:de.type,enabled:!de.enabled}),K(ve=>({...ve,[z.type]:(ve[z.type]||[]).map(je=>je.type===de.type?{...je,enabled:!je.enabled}:je)}))}catch(ve){console.error("Extension toggle failed:",ve)}finally{se(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 ${de.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${de.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),de.name,e.jsx("span",{className:"text-[9px] font-normal",children:de.enabled?"ON":"OFF"})]},de.type))})]})]},g.id)})}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:w,disabled:$,className:"machine-btn",children:$?"⏳":"↻ Load"})]}),(()=>{const g=new Set(T.map(U=>U.type)),z=A.filter(U=>(U.category||"cli")!==t?!1:t==="ide"?!0:g.has(U.cliType));return z.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:z.map((U,de)=>{var we,ve;return e.jsxs("div",{onClick:()=>{I(U.cliType),(U.workspace||U.dir)&&(y("__custom__"),le(U.workspace||U.dir)),ne((U.cliArgs||[]).join(" ")),V(U.model||""),F&&h(U.cliType,U.workspace?{workspace:U.workspace}:void 0)},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:c(U.cliType)}),e.jsx("span",{children:((we=U.workspace||U.dir)==null?void 0:we.split("/").filter(Boolean).pop())||U.cliType||"root"}),U.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",U.model]}),U.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((ve=U.cliArgs)==null?void 0:ve.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:U.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:U.timestamp?new Date(U.timestamp).toLocaleDateString():""})]},de)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",O.label," launch history yet."]})})()]})]})}const as=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Er=[{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 Ar({machineId:t,provider:s,sendDaemonCommand:o,onClose:a}){const[i,c]=n.useState("config"),[r,x]=n.useState("codex-cli"),[u,h]=n.useState([]),[d,l]=n.useState(""),[v,f]=n.useState([]),[p,A]=n.useState(""),$=n.useRef(null),w=n.useRef(null),S=I=>{h(N=>N.includes(I)?N.filter(ne=>ne!==I):[...N,I])},O=()=>h([...as]),F=()=>h([]);n.useEffect(()=>{var I;(I=$.current)==null||I.scrollIntoView({behavior:"smooth"})},[v]),n.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const R=n.useCallback(()=>{w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const I=await o(t,"provider_auto_fix_status",{providerType:s.type});(I==null?void 0:I.running)===!1&&i==="running"&&(c("done"),f(N=>[...N,`
70
70
  ✅ Auto-fix completed!`]),w.current&&clearInterval(w.current))}catch{}},3e3)},[t,s.type,o,i]),T=async()=>{if(u.length!==0){c("running"),f(["🚀 Starting auto-fix...",`Agent: ${r}`,`Scripts: ${u.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),A("");try{const I=await o(t,"provider_auto_fix",{providerType:s.type,functions:u,agent:r,...d?{comment:d}:{}});I!=null&&I.success&&(I!=null&&I.started||I!=null&&I.running)?(f(N=>[...N,"✅ Agent started. Monitoring progress..."]),R()):(c("error"),A((I==null?void 0:I.error)||"Failed to start auto-fix"))}catch(I){c("error"),A((I==null?void 0:I.message)||"Connection failed")}}},D=async()=>{try{await o(t,"provider_auto_fix_cancel",{providerType:s.type}),f(I=>[...I,`
71
- ⚠️ Auto-fix cancelled.`]),c("done"),w.current&&clearInterval(w.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,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:I=>I.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:a,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:Sr.map(I=>e.jsxs("button",{onClick:()=>x(I.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:r===I.value?I.color+"66":"var(--border-subtle)",background:r===I.value?I.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:r===I.value?I.color:"var(--text-primary)"},children:I.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:I.desc})]},I.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:O,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:F,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:rs.map(I=>e.jsxs("button",{onClick:()=>S(I),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(I)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(I)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(I)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(I)?"☑ ":"☐ ",I]},I))})]}),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:d,onChange:I=>l(I.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:[j.map((I,N)=>e.jsx("div",{className:I.startsWith("✅")?"text-green-400":I.startsWith("❌")||I.startsWith("⚠")?"text-amber-400":"",children:I},N)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:$})]}),p&&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:p})]})]}),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"&&u.length>0&&`${u.length} script(s) selected`,i==="running"&&"Agent is working...",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:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:u.length===0,className:"machine-btn",style:{background:u.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:u.length>0?"rgba(139,92,246,0.4)":void 0,color:u.length>0?"#a78bfa":void 0,opacity:u.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:D,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:()=>{c("config"),f([]),A("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"})]})]})]})]})})}function Ir({machineId:t,providers:s,sendDaemonCommand:o,onClose:a,onCreated:i}){var R;const c=s.filter(T=>T.category==="ide"),[r,x]=n.useState(((R=c[0])==null?void 0:R.type)||""),[u,h]=n.useState(""),[d,l]=n.useState(""),[j,f]=n.useState(!1),[p,A]=n.useState(""),[$,w]=n.useState(!1),S=T=>{const D=T.toLowerCase().replace(/[^a-z0-9-]/g,"");h(D),(!d||d===O(u))&&l(O(D))},O=T=>T.split("-").map(D=>D.charAt(0).toUpperCase()+D.slice(1)).join(" "),F=async()=>{if(!(!u||!d||!r)){f(!0),A("");try{const T=await o(t,"provider_clone",{type:u,name:d,category:"ide",location:"user",cloneFrom:r});T!=null&&T.success||T!=null&&T.created?(w(!0),i==null||i(u)):A((T==null?void 0:T.error)||"Failed to create provider")}catch(T){A((T==null?void 0:T.message)||"Connection failed")}f(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,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:T=>T.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:$?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:u})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",u,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",u]})," 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:c.map(T=>e.jsxs("button",{onClick:()=>x(T.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:r===T.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:r===T.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:T.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:r===T.type?"#a78bfa":"var(--text-secondary)"},children:T.displayName})]},T.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:u,onChange:T=>S(T.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/",u||"...","/"]})]})]}),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:d,onChange:T=>l(T.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"})]}),p&&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:p})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:$?e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:F,disabled:!u||!d||j,className:"machine-btn",style:{background:u&&d?"rgba(34,197,94,0.12)":void 0,borderColor:u&&d?"rgba(34,197,94,0.3)":void 0,color:u&&d?"#86efac":void 0,opacity:!u||!d||j?.4:1},children:j?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Mr({machineId:t,providers:s,sendDaemonCommand:o}){const[a,i]=n.useState([]),[c,r]=n.useState(!1),[x,u]=n.useState(null),[h,d]=n.useState("all"),[l,j]=n.useState(null),[f,p]=n.useState(!1),A=n.useCallback(async()=>{var w;if(t){r(!0);try{const S=await o(t,"get_provider_settings",{}),O=(S==null?void 0:S.result)||S;if(S!=null&&S.success&&(O!=null&&O.settings)){const F=[];for(const[R,T]of Object.entries(O.settings)){const D=s.find(I=>I.type===R);F.push({type:R,displayName:(D==null?void 0:D.displayName)||R,icon:(D==null?void 0:D.icon)||"",category:(D==null?void 0:D.category)||"unknown",schema:T,values:((w=O.values)==null?void 0:w[R])||{}})}F.sort((R,T)=>R.category.localeCompare(T.category)||R.displayName.localeCompare(T.displayName)),i(F)}}catch{}r(!1)}},[t,s,o]);n.useEffect(()=>{a.length===0&&A()},[]);const $=async(w,S,O)=>{u(`${w}.${S}`),i(F=>F.map(R=>R.type===w?{...R,values:{...R.values,[S]:O}}:R));try{const F=await o(t,"set_provider_setting",{providerType:w,key:S,value:O});F!=null&&F.success||A()}catch{A()}u(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(w=>e.jsx("button",{onClick:()=>d(w),className:`machine-btn text-[10px] px-2 py-0.5 ${h===w?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:w.toUpperCase()},w))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>p(!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:A,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),h!=="all"&&a.filter(w=>w.category===h).length>1&&(()=>{const w=a.filter(R=>R.category===h),S=new Map;for(const R of w)for(const T of R.schema){if(T.type!=="boolean")continue;const D=S.get(T.key),I=!!(R.values[T.key]??T.default);D?(D.onCount+=I?1:0,D.total+=1):S.set(T.key,{label:T.label||T.key,onCount:I?1:0,total:1})}const O=[...S.entries()].filter(([,R])=>R.total===w.length);if(O.length===0)return null;const F=async(R,T)=>{for(const D of w)await $(D.type,R,T)};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 ",h.toUpperCase()," providers (",w.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:O.map(([R,T])=>{const D=T.onCount===T.total,I=T.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:T.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",T.onCount,"/",T.total,")"]}),e.jsx("button",{onClick:()=>void F(R,!0),disabled:D,className:`machine-btn text-[9px] px-1.5 py-px ${D?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void F(R,!1),disabled:I,className:`machine-btn text-[9px] px-1.5 py-px ${I?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},R)})})]})})(),c&&a.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:a.filter(w=>h==="all"||w.category===h).map(w=>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:w.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:w.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:w.category==="acp"?"rgba(139,92,246,0.08)":w.category==="cli"?"rgba(59,130,246,0.08)":w.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:w.category==="acp"?"#a78bfa":w.category==="cli"?"#60a5fa":w.category==="ide"?"#86efac":"#fbbf24"},children:w.category}),w.category==="ide"&&e.jsx("button",{onClick:()=>j(s.find(S=>S.type===w.type)||{type:w.type,displayName:w.displayName,icon:w.icon,category:w.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:w.schema.map(S=>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:[S.label||S.key,x===`${w.type}.${S.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),S.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:S.description})]}),e.jsx("div",{className:"shrink-0",children:S.type==="boolean"?e.jsx("button",{onClick:()=>$(w.type,S.key,!(w.values[S.key]??S.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:w.values[S.key]??S.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:w.values[S.key]??S.default?21:3}})}):S.type==="number"?e.jsx("input",{type:"number",value:w.values[S.key]??S.default??0,min:S.min,max:S.max,onChange:O=>{const F=parseInt(O.target.value)||0;S.min!==void 0&&F<S.min||S.max!==void 0&&F>S.max||$(w.type,S.key,F)},className:"machine-input w-20 text-center text-[11px]"}):S.type==="select"&&S.options?e.jsx("select",{value:w.values[S.key]??S.default??"",onChange:O=>$(w.type,S.key,O.target.value),className:"machine-input text-[11px]",children:S.options.map(O=>e.jsx("option",{value:O,children:O},O))}):e.jsx("input",{type:"text",value:w.values[S.key]??S.default??"",onBlur:O=>$(w.type,S.key,O.target.value),className:"machine-input w-[120px] text-[11px]"})})]},S.key))})]},w.type))}),l&&e.jsx(Cr,{machineId:t,provider:l,sendDaemonCommand:o,onClose:()=>j(null)}),f&&e.jsx(Ir,{machineId:t,providers:s,sendDaemonCommand:o,onClose:()=>p(!1),onCreated:()=>{p(!1),A()}})]})}function Tr({machineId:t,sendDaemonCommand:s}){const[o,a]=n.useState([]),[i,c]=n.useState(0),[r,x]=n.useState(!0),[u,h]=n.useState("debug"),d=n.useRef(null),l=n.useRef(!1);return n.useEffect(()=>{if(!t||!r)return;const j=async()=>{try{const p=await s(t,"get_logs",{count:200,minLevel:u,since:i}),A=(p==null?void 0:p.result)||p;if(p!=null&&p.success&&Array.isArray(A==null?void 0:A.logs)&&A.logs.length>0){a(w=>[...w,...A.logs.map(O=>({timestamp:O.ts,level:O.level,message:`[${O.category}] ${O.message}`}))].slice(-300));const $=Math.max(...A.logs.map(w=>w.ts));c($)}}catch{}};j();const f=setInterval(j,3e3);return()=>clearInterval(f)},[t,r,i,u,s]),n.useEffect(()=>{if(r&&o.length>0){const j=l.current?"smooth":"instant";setTimeout(()=>{var f;(f=d.current)==null||f.scrollIntoView({behavior:j}),l.current=!0},50)}},[o.length,r]),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(j=>e.jsx("button",{onClick:()=>{h(j),a([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===j?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:j.toUpperCase()},j))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[o.length," entries"]}),e.jsx("button",{onClick:()=>x(!r),className:`machine-btn ${r?"text-green-500 border-green-500/30":""}`,children:r?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{a([]),c(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:[o.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),o.map((j,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:j.level==="error"?"#ef4444":j.level==="warn"?"#f59e0b":j.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(j.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:j.level==="error"?"#ef4444":j.level==="warn"?"#f59e0b":j.level==="debug"?"#475569":"#8b5cf6"},children:j.level==="error"?"ERR":j.level==="warn"?"WRN":j.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:j.message})]},f)),e.jsx("div",{ref:d})]})]})}function Er({machine:t,launchPick:s,actions:o}){const{runLaunchCliCore:a,setLaunchPick:i}=o;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(c=>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),a({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.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),a({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),a({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 Ar(){var F,R,T,D,I,N,ne,_,X,Y;const{id:t}=ls(),s=mt(),{sendCommand:o}=Xe(),a=kt(),i=a.ides||[],c=a.initialLoaded??!0,[r,x]=n.useState("overview"),u=n.useRef(null),h=wr({machineId:t,sendDaemonCommand:o,logsEndRef:u}),d=i.find(y=>y.id===t&&y.daemonMode),l=((d==null?void 0:d.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),j={};for(const y of l)j[y.type]=y.icon;const f=y=>j[y]||"",p=d?{id:d.id,hostname:((F=d.machine)==null?void 0:F.hostname)||d.id,platform:((R=d.machine)==null?void 0:R.platform)||"unknown",arch:((T=d.machine)==null?void 0:T.arch)||"",cpus:((D=d.machine)==null?void 0:D.cpus)||0,totalMem:((I=d.machine)==null?void 0:I.totalMem)||0,freeMem:((N=d.machine)==null?void 0:N.freeMem)||0,availableMem:(ne=d.machine)==null?void 0:ne.availableMem,loadavg:((_=d.machine)==null?void 0:_.loadavg)||[],uptime:((X=d.machine)==null?void 0:X.uptime)||0,release:((Y=d.machine)==null?void 0:Y.release)||"",cdpConnected:!!(d.ides||[]).some(y=>y.cdpConnected),machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],managedIdeIds:d.managedIdeIds||[],managedCliIds:d.managedCliIds||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null,workspaceActivity:d.workspaceActivity||[]}:null,A=i.filter(y=>y.daemonId===t&&!y.daemonMode).filter(y=>!qt(y)&&!Gt(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:Cn(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:t})),$=i.filter(y=>y.daemonId===t&&qt(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:t})),w=i.filter(y=>y.daemonId===t&&Gt(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:t}));if(!p)return c?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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const S=p.machineNickname||p.hostname,O=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(on,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{size:14})," IDEs"]}),count:A.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(wt,{size:14})," CLIs"]}),count:$.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fs,{size:14})," ACP Agents"]}),count:w.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qs,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>s("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[h.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:h.nicknameInput,onChange:y=>h.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&h.handleSaveNickname(),y.key==="Escape"&&h.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:h.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>h.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{h.setEditingNickname(!0),h.setNicknameInput(p.machineNickname||"")},title:"Click to set nickname",children:S}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[p.platform," · ",p.arch," · ",p.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",d.version]}),(d==null?void 0:d.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await o(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),p.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:p.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",p.p2p.state==="connected"?`● ${p.p2p.peers}`:"○"]}),p.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),p.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",p.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:O.map(y=>e.jsxs("button",{onClick:()=>x(y.id),className:`machine-tab shrink-0${r===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[r==="overview"&&e.jsx(Nr,{machine:p,managedIdes:A,managedClis:$,managedAcps:w,actions:h}),r==="ides"&&e.jsx($t,{category:"ide",machine:p,machineId:t,providers:l,managedEntries:A,getIcon:f,actions:h,sendDaemonCommand:o}),r==="clis"&&e.jsx($t,{category:"cli",machine:p,machineId:t,providers:l,managedEntries:$,getIcon:f,actions:h}),r==="acps"&&e.jsx($t,{category:"acp",machine:p,machineId:t,providers:l,managedEntries:w,getIcon:f,actions:h}),r==="providers"&&e.jsx(Mr,{machineId:t,providers:l,sendDaemonCommand:o}),r==="logs"&&e.jsx(Tr,{machineId:t,sendDaemonCommand:o})]}),h.launchPick&&p&&e.jsx(Er,{machine:p,launchPick:h.launchPick,actions:h})]})}function $r(){const[t,s]=n.useState({ide:[],cli:[],ext:[],acp:[]}),[o,a]=n.useState(!0);n.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(r=>r.json()).then(r=>{const x=[],u=[],h=[],d=[];Object.values(r.providers||{}).forEach(j=>{const f={name:j.name||"Unknown",status:j.status||"Stable",details:j.details||"Community Provider"};j.category==="ide"?x.push(f):j.category==="cli"?u.push(f):j.category==="extension"?h.push(f):j.category==="acp"&&d.push(f)});const l=(j,f)=>{const p={Stable:1,Beta:2,WIP:3},A=p[j.status]||99,$=p[f.status]||99;return A!==$?A-$:j.name.localeCompare(f.name)};s({ide:x.sort(l),cli:u.sort(l),ext:h.sort(l),acp:d.sort(l)})}).catch(r=>console.error("Failed to load capabilities:",r)).finally(()=>a(!1))},[]);const i=r=>r==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(tn,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):r==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Ot,{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(hs,{className:"w-4 h-4"})," ",e.jsx("span",{children:r})]}),c=r=>e.jsx("div",{className:"bg-bg-panel border border-border-card rounded-md overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-subtle border-b border-border-card 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-card text-sm",children:r.map((x,u)=>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:x.name}),e.jsx("td",{className:"py-3 px-4",children:i(x.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:x.details})]},u))})]})});return o?e.jsxs("div",{className:"p-8 max-w-4xl mx-auto flex flex-col items-center justify-center min-h-[50vh]",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mb-4"}),e.jsx("p",{className:"text-text-muted",children:"Loading providers registry..."})]}):e.jsxs("div",{className:"p-8 max-w-4xl mx-auto animate-fade-in pb-20",children:[e.jsx(ws,{title:"Capabilities & Provider Status",subtitle:"Support matrix for IDEs, CLI Agents, and AI Extensions",icon:e.jsx(ms,{})}),e.jsxs("div",{className:"space-y-12 mt-8",children:[e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-blue-500/10 text-blue-400",children:e.jsx(nt,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"IDE Support"})]}),c(t.ide)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-purple-500/10 text-purple-400",children:e.jsx(Kt,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"Standalone CLI Agents"})]}),c(t.cli)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-green-500/10 text-green-400",children:e.jsx(wt,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"AI Extensions"})]}),c(t.ext)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-orange-500/10 text-orange-400",children:e.jsx(wt,{className:"w-5 h-5"})}),e.jsxs("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:["ACP Agents (",t.acp.length," loaded)"]})]}),c(t.acp)]})]})]})}function _r(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,a=new URLSearchParams(window.location.search).get("token");return a?`${s}?token=${encodeURIComponent(a)}`:s}const as=_r(),os=3e3,Rr=3e4;let ze=null,Pr=0;const Nt=new Map,Wt=new Set;let Ge=null,Lr=null,lt=null;async function vt(t,s,o){const a=ze;if(a&&a.readyState===WebSocket.OPEN){const c=`req_${++Pr}_${Date.now()}`;return new Promise((r,x)=>{const u=setTimeout(()=>{Nt.delete(c),x(new Error(`WS command timeout: ${s}`))},3e4);Nt.set(c,{resolve:h=>{clearTimeout(u),r(h)},reject:h=>{clearTimeout(u),x(h)}}),a.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:o||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:o||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class Dr{constructor(s){Me(this,"daemonId");Me(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(ze==null?void 0:ze.readyState)===WebSocket.OPEN}get connectionState(){return(ze==null?void 0:ze.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,o){return vt(this.daemonId,s,o)}async sendInput(s,o){const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return vt(a,"cdp_remote_action",{action:s,params:o})}startScreenshots(s){this.screenshotIdeType=s||null,Ge&&(clearInterval(Ge),Ge=null);const o=async()=>{if(this.hasCommandChannel)try{const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await vt(a,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(r=>r.blob());Wt.forEach(r=>r(this.daemonId,c))}}catch{}};o(),Ge=setInterval(o,2e3)}stopScreenshots(s){Ge&&(clearInterval(Ge),Ge=null)}}let Je=null;function Br(t){(!Je||Je.daemonId!==t)&&(Je=new Dr(t));const s=Te._originalGet||Te.get.bind(Te);Te._originalGet=s,Te.get=o=>o===t||o.startsWith("standalone")?Je:s(o),Te.getState=o=>(o===t||o.startsWith("standalone"))&&(Je==null?void 0:Je.connectionState)||"disconnected",Te.onScreenshot=(o,a)=>(Wt.add(a),()=>{Wt.delete(a)})}function Wr({children:t}){const s=n.useRef(zt()),o=zt();s.current=o;const{setUserName:a}=dt(),i=n.useRef(a);i.current=a;const[,c]=n.useState("disconnected"),r=n.useCallback((l,j)=>{c(l),lt==null||lt(l,j)},[]),x=n.useRef(null),u=n.useRef(),h=n.useRef(os),d=n.useRef(!0);return n.useEffect(()=>{d.current=!0;function l(){var p,A;if(!d.current||((p=x.current)==null?void 0:p.readyState)===WebSocket.OPEN||((A=x.current)==null?void 0:A.readyState)===WebSocket.CONNECTING)return;r("connecting"),console.log(`[Standalone WS] Connecting to ${as}...`);let f;try{f=new WebSocket(as)}catch($){console.error("[Standalone WS] Failed to create WebSocket:",$),j();return}x.current=f,f.onopen=()=>{if(!d.current){f.close();return}r("connected"),h.current=os,console.log("[Standalone WS] Connected")},ze=f,f.onmessage=$=>{var w;try{const S=JSON.parse($.data);if((S.type==="command_result"||S.type==="error")&&S.requestId){const O=Nt.get(S.requestId);O&&(Nt.delete(S.requestId),S.type==="error"?O.reject(new Error(((w=S.data)==null?void 0:w.message)||"Command failed")):O.resolve(S.data));return}if(S.type==="pty_output"){Te.emitPtyOutput(S.cliId,S.data);return}if(S.type==="status"||S.type==="initial_state"){const O=S.data;if(!O)return;const{injectEntries:F,markLoaded:R}=s.current,T=O.id||"standalone";Lr=T,Br(T),r("connected",T);const D=$n(O,{daemonId:T});D.length>0&&F(D),R(),O.userName&&i.current&&i.current(O.userName)}}catch(S){console.error("[Standalone WS] Parse error:",S)}},f.onclose=()=>{d.current&&(r("disconnected"),x.current=null,j())},f.onerror=$=>{console.warn("[Standalone WS] Error, will reconnect:",$)}}function j(){if(!d.current)return;clearTimeout(u.current);const f=h.current;console.log(`[Standalone WS] Reconnecting in ${f}ms...`),u.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,Rr),l()},f)}return l(),()=>{d.current=!1,clearTimeout(u.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,ze=null)}},[]),e.jsx(e.Fragment,{children:t})}function Or({children:t}){const[s,o]=n.useState("disconnected"),[a,i]=n.useState(null);n.useEffect(()=>(lt=(r,x)=>{o(r),x&&i(x)},()=>{lt=null}),[]);const c=n.useMemo(()=>{const r=s==="connected",x={};return a&&(x[a]=r?"connected":"connecting"),x.standalone=r?"connected":"connecting",{wsStatus:s,isConnected:r,connectionStates:x}},[s,a]);return e.jsx(Ys,{connectionOverrides:c,children:e.jsx(Wr,{children:t})})}const Kr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Js,{}),label:"Dashboard"},{id:"capabilities",path:"/capabilities",icon:e.jsx(ms,{}),label:"Capabilities"},{id:"machine",path:"/machines",icon:e.jsx(Zs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(ps,{}),label:"Settings"}];function Fr({children:t}){const s=mt(),o=Bs(),[a,i]=n.useState(!1),[c,r]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=d=>{s(d),i(!1)},u=()=>{r(d=>{const l=!d;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},h=d=>`nav-item${o.pathname.startsWith(d)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${a?" mobile-menu-open":""}${c?" 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"})]}),a&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:d=>d.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${a?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&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:Kr.map(d=>e.jsxs("div",{className:h(d.path),id:`nav-${d.id}`,onClick:()=>x(d.path),title:c?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!c&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${o.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(en,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.66"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&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 Hr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Ur=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],zr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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 Yr(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.66"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Hr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:Ns.map(t=>t.name)},{label:"Extension agents",items:Ss.map(t=>t.name)},{label:"CLI agents",items:ks.map(t=>t.name)}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:zr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Ur.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Xr(){const{ides:t}=dt(),s=t.find(l=>l.type==="adhdev-daemon"),o=(s==null?void 0:s.detectedIdes)||[],{sendCommand:a}=Xe(),{userName:i}=dt(),[c,r]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&r(i)},[i]);const x=l=>{const j=l.target.value.trim();s!=null&&s.id&&j!==i&&a(s.id,"set_user_name",{userName:j}).catch(console.error)},[u,h]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=l=>{h(l);try{localStorage.setItem("adhdev_sound",l?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(ws,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(tt,{title:"Daemon",className:"mb-4",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.6.66"]}),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(tt,{title:"Detected IDEs",className:"mb-4",children:o.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:o.map(l=>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 ${l.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:l.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:l.type})]},l.type))})}),e.jsx(tt,{title:"Machine",className:"mb-4",children:e.jsx(Gn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(tt,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(er,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(or,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(xr,{})]})]})}),e.jsx(tt,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(qn,{}),e.jsx(st,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:u,onChange:d})]})}),e.jsx(tt,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 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:c,onChange:l=>r(l.target.value),onBlur:x,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})]})}rr();function is(){const{ides:t}=dt(),s=t.find(o=>{var a;return o.daemonMode||((a=o.id)==null?void 0:a.startsWith("standalone"))});return s?e.jsx(ft,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(ft,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(ft,{to:"/dashboard",replace:!0})}function Vr(){return e.jsx(Ws,{children:e.jsx(Or,{children:e.jsx(Gs,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Fr,{children:e.jsxs(Os,{children:[e.jsx(He,{path:"/dashboard",element:e.jsx(yr,{})}),e.jsx(He,{path:"/ide/:id",element:e.jsx(jr,{})}),e.jsx(He,{path:"/machine",element:e.jsx(is,{})}),e.jsx(He,{path:"/machines/:id",element:e.jsx(Ar,{})}),e.jsx(He,{path:"/machines",element:e.jsx(is,{})}),e.jsx(He,{path:"/capabilities",element:e.jsx($r,{})}),e.jsx(He,{path:"/about",element:e.jsx(Yr,{})}),e.jsx(He,{path:"/settings",element:e.jsx(Xr,{})}),e.jsx(He,{path:"*",element:e.jsx(ft,{to:"/dashboard",replace:!0})})]})})})})})}Ks(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(Vr,{})}));
71
+ ⚠️ Auto-fix cancelled.`]),c("done"),w.current&&clearInterval(w.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,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:I=>I.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:a,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:Er.map(I=>e.jsxs("button",{onClick:()=>x(I.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:r===I.value?I.color+"66":"var(--border-subtle)",background:r===I.value?I.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:r===I.value?I.color:"var(--text-primary)"},children:I.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:I.desc})]},I.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:O,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:F,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:as.map(I=>e.jsxs("button",{onClick:()=>S(I),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(I)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(I)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(I)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(I)?"☑ ":"☐ ",I]},I))})]}),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:d,onChange:I=>l(I.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:[v.map((I,N)=>e.jsx("div",{className:I.startsWith("✅")?"text-green-400":I.startsWith("❌")||I.startsWith("⚠")?"text-amber-400":"",children:I},N)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:$})]}),p&&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:p})]})]}),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"&&u.length>0&&`${u.length} script(s) selected`,i==="running"&&"Agent is working...",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:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:u.length===0,className:"machine-btn",style:{background:u.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:u.length>0?"rgba(139,92,246,0.4)":void 0,color:u.length>0?"#a78bfa":void 0,opacity:u.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:D,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:()=>{c("config"),f([]),A("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"})]})]})]})]})})}function $r({machineId:t,providers:s,sendDaemonCommand:o,onClose:a,onCreated:i}){var R;const c=s.filter(T=>T.category==="ide"),[r,x]=n.useState(((R=c[0])==null?void 0:R.type)||""),[u,h]=n.useState(""),[d,l]=n.useState(""),[v,f]=n.useState(!1),[p,A]=n.useState(""),[$,w]=n.useState(!1),S=T=>{const D=T.toLowerCase().replace(/[^a-z0-9-]/g,"");h(D),(!d||d===O(u))&&l(O(D))},O=T=>T.split("-").map(D=>D.charAt(0).toUpperCase()+D.slice(1)).join(" "),F=async()=>{if(!(!u||!d||!r)){f(!0),A("");try{const T=await o(t,"provider_clone",{type:u,name:d,category:"ide",location:"user",cloneFrom:r});T!=null&&T.success||T!=null&&T.created?(w(!0),i==null||i(u)):A((T==null?void 0:T.error)||"Failed to create provider")}catch(T){A((T==null?void 0:T.message)||"Connection failed")}f(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,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:T=>T.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:$?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:u})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",u,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",u]})," 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:c.map(T=>e.jsxs("button",{onClick:()=>x(T.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:r===T.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:r===T.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:T.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:r===T.type?"#a78bfa":"var(--text-secondary)"},children:T.displayName})]},T.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:u,onChange:T=>S(T.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/",u||"...","/"]})]})]}),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:d,onChange:T=>l(T.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"})]}),p&&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:p})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:$?e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:F,disabled:!u||!d||v,className:"machine-btn",style:{background:u&&d?"rgba(34,197,94,0.12)":void 0,borderColor:u&&d?"rgba(34,197,94,0.3)":void 0,color:u&&d?"#86efac":void 0,opacity:!u||!d||v?.4:1},children:v?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function _r({machineId:t,providers:s,sendDaemonCommand:o}){const[a,i]=n.useState([]),[c,r]=n.useState(!1),[x,u]=n.useState(null),[h,d]=n.useState("all"),[l,v]=n.useState(null),[f,p]=n.useState(!1),A=n.useCallback(async()=>{var w;if(t){r(!0);try{const S=await o(t,"get_provider_settings",{}),O=(S==null?void 0:S.result)||S;if(S!=null&&S.success&&(O!=null&&O.settings)){const F=[];for(const[R,T]of Object.entries(O.settings)){const D=s.find(I=>I.type===R);F.push({type:R,displayName:(D==null?void 0:D.displayName)||R,icon:(D==null?void 0:D.icon)||"",category:(D==null?void 0:D.category)||"unknown",schema:T,values:((w=O.values)==null?void 0:w[R])||{}})}F.sort((R,T)=>R.category.localeCompare(T.category)||R.displayName.localeCompare(T.displayName)),i(F)}}catch{}r(!1)}},[t,s,o]);n.useEffect(()=>{a.length===0&&A()},[]);const $=async(w,S,O)=>{u(`${w}.${S}`),i(F=>F.map(R=>R.type===w?{...R,values:{...R.values,[S]:O}}:R));try{const F=await o(t,"set_provider_setting",{providerType:w,key:S,value:O});F!=null&&F.success||A()}catch{A()}u(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(w=>e.jsx("button",{onClick:()=>d(w),className:`machine-btn text-[10px] px-2 py-0.5 ${h===w?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:w.toUpperCase()},w))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>p(!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:A,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),h!=="all"&&a.filter(w=>w.category===h).length>1&&(()=>{const w=a.filter(R=>R.category===h),S=new Map;for(const R of w)for(const T of R.schema){if(T.type!=="boolean")continue;const D=S.get(T.key),I=!!(R.values[T.key]??T.default);D?(D.onCount+=I?1:0,D.total+=1):S.set(T.key,{label:T.label||T.key,onCount:I?1:0,total:1})}const O=[...S.entries()].filter(([,R])=>R.total===w.length);if(O.length===0)return null;const F=async(R,T)=>{for(const D of w)await $(D.type,R,T)};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 ",h.toUpperCase()," providers (",w.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:O.map(([R,T])=>{const D=T.onCount===T.total,I=T.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:T.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",T.onCount,"/",T.total,")"]}),e.jsx("button",{onClick:()=>void F(R,!0),disabled:D,className:`machine-btn text-[9px] px-1.5 py-px ${D?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void F(R,!1),disabled:I,className:`machine-btn text-[9px] px-1.5 py-px ${I?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},R)})})]})})(),c&&a.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:a.filter(w=>h==="all"||w.category===h).map(w=>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:w.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:w.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:w.category==="acp"?"rgba(139,92,246,0.08)":w.category==="cli"?"rgba(59,130,246,0.08)":w.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:w.category==="acp"?"#a78bfa":w.category==="cli"?"#60a5fa":w.category==="ide"?"#86efac":"#fbbf24"},children:w.category}),w.category==="ide"&&e.jsx("button",{onClick:()=>v(s.find(S=>S.type===w.type)||{type:w.type,displayName:w.displayName,icon:w.icon,category:w.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:w.schema.map(S=>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:[S.label||S.key,x===`${w.type}.${S.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),S.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:S.description})]}),e.jsx("div",{className:"shrink-0",children:S.type==="boolean"?e.jsx("button",{onClick:()=>$(w.type,S.key,!(w.values[S.key]??S.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:w.values[S.key]??S.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:w.values[S.key]??S.default?21:3}})}):S.type==="number"?e.jsx("input",{type:"number",value:w.values[S.key]??S.default??0,min:S.min,max:S.max,onChange:O=>{const F=parseInt(O.target.value)||0;S.min!==void 0&&F<S.min||S.max!==void 0&&F>S.max||$(w.type,S.key,F)},className:"machine-input w-20 text-center text-[11px]"}):S.type==="select"&&S.options?e.jsx("select",{value:w.values[S.key]??S.default??"",onChange:O=>$(w.type,S.key,O.target.value),className:"machine-input text-[11px]",children:S.options.map(O=>e.jsx("option",{value:O,children:O},O))}):e.jsx("input",{type:"text",value:w.values[S.key]??S.default??"",onBlur:O=>$(w.type,S.key,O.target.value),className:"machine-input w-[120px] text-[11px]"})})]},S.key))})]},w.type))}),l&&e.jsx(Ar,{machineId:t,provider:l,sendDaemonCommand:o,onClose:()=>v(null)}),f&&e.jsx($r,{machineId:t,providers:s,sendDaemonCommand:o,onClose:()=>p(!1),onCreated:()=>{p(!1),A()}})]})}function Rr({machineId:t,sendDaemonCommand:s}){const[o,a]=n.useState([]),[i,c]=n.useState(0),[r,x]=n.useState(!0),[u,h]=n.useState("debug"),d=n.useRef(null),l=n.useRef(!1);return n.useEffect(()=>{if(!t||!r)return;const v=async()=>{try{const p=await s(t,"get_logs",{count:200,minLevel:u,since:i}),A=(p==null?void 0:p.result)||p;if(p!=null&&p.success&&Array.isArray(A==null?void 0:A.logs)&&A.logs.length>0){a(w=>[...w,...A.logs.map(O=>({timestamp:O.ts,level:O.level,message:`[${O.category}] ${O.message}`}))].slice(-300));const $=Math.max(...A.logs.map(w=>w.ts));c($)}}catch{}};v();const f=setInterval(v,3e3);return()=>clearInterval(f)},[t,r,i,u,s]),n.useEffect(()=>{if(r&&o.length>0){const v=l.current?"smooth":"instant";setTimeout(()=>{var f;(f=d.current)==null||f.scrollIntoView({behavior:v}),l.current=!0},50)}},[o.length,r]),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(v=>e.jsx("button",{onClick:()=>{h(v),a([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[o.length," entries"]}),e.jsx("button",{onClick:()=>x(!r),className:`machine-btn ${r?"text-green-500 border-green-500/30":""}`,children:r?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{a([]),c(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:[o.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),o.map((v,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(v.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:v.level==="error"?"#ef4444":v.level==="warn"?"#f59e0b":v.level==="debug"?"#475569":"#8b5cf6"},children:v.level==="error"?"ERR":v.level==="warn"?"WRN":v.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:v.message})]},f)),e.jsx("div",{ref:d})]})]})}function Pr({machine:t,launchPick:s,actions:o}){const{runLaunchCliCore:a,setLaunchPick:i}=o;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(c=>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),a({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.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),a({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),a({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 Lr(){var F,R,T,D,I,N,ne,_,V,Y;const{id:t}=ds(),s=pt(),{sendCommand:o}=Ve(),a=kt(),i=a.ides||[],c=a.initialLoaded??!0,[r,x]=n.useState("overview"),u=n.useRef(null),h=Ir({machineId:t,sendDaemonCommand:o,logsEndRef:u}),d=i.find(y=>y.id===t&&y.daemonMode),l=((d==null?void 0:d.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),v={};for(const y of l)v[y.type]=y.icon;const f=y=>v[y]||"",p=d?{id:d.id,hostname:((F=d.machine)==null?void 0:F.hostname)||d.id,platform:((R=d.machine)==null?void 0:R.platform)||"unknown",arch:((T=d.machine)==null?void 0:T.arch)||"",cpus:((D=d.machine)==null?void 0:D.cpus)||0,totalMem:((I=d.machine)==null?void 0:I.totalMem)||0,freeMem:((N=d.machine)==null?void 0:N.freeMem)||0,availableMem:(ne=d.machine)==null?void 0:ne.availableMem,loadavg:((_=d.machine)==null?void 0:_.loadavg)||[],uptime:((V=d.machine)==null?void 0:V.uptime)||0,release:((Y=d.machine)==null?void 0:Y.release)||"",cdpConnected:!!(d.ides||[]).some(y=>y.cdpConnected),machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],managedIdeIds:d.managedIdeIds||[],managedCliIds:d.managedCliIds||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null,workspaceActivity:d.workspaceActivity||[]}:null,A=i.filter(y=>y.daemonId===t&&!y.daemonMode).filter(y=>!Gt(y)&&!Jt(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:An(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:t})),$=i.filter(y=>y.daemonId===t&&Gt(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:t})),w=i.filter(y=>y.daemonId===t&&Jt(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:t}));if(!p)return c?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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const S=p.machineNickname||p.hostname,O=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(cn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{size:14})," IDEs"]}),count:A.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:14})," CLIs"]}),count:$.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(gs,{size:14})," ACP Agents"]}),count:w.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tn,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>s("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[h.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:h.nicknameInput,onChange:y=>h.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&h.handleSaveNickname(),y.key==="Escape"&&h.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:h.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>h.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{h.setEditingNickname(!0),h.setNicknameInput(p.machineNickname||"")},title:"Click to set nickname",children:S}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[p.platform," · ",p.arch," · ",p.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",d.version]}),(d==null?void 0:d.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await o(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),p.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:p.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",p.p2p.state==="connected"?`● ${p.p2p.peers}`:"○"]}),p.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),p.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",p.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:O.map(y=>e.jsxs("button",{onClick:()=>x(y.id),className:`machine-tab shrink-0${r===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[r==="overview"&&e.jsx(Mr,{machine:p,managedIdes:A,managedClis:$,managedAcps:w,actions:h}),r==="ides"&&e.jsx($t,{category:"ide",machine:p,machineId:t,providers:l,managedEntries:A,getIcon:f,actions:h,sendDaemonCommand:o}),r==="clis"&&e.jsx($t,{category:"cli",machine:p,machineId:t,providers:l,managedEntries:$,getIcon:f,actions:h}),r==="acps"&&e.jsx($t,{category:"acp",machine:p,machineId:t,providers:l,managedEntries:w,getIcon:f,actions:h}),r==="providers"&&e.jsx(_r,{machineId:t,providers:l,sendDaemonCommand:o}),r==="logs"&&e.jsx(Rr,{machineId:t,sendDaemonCommand:o})]}),h.launchPick&&p&&e.jsx(Pr,{machine:p,launchPick:h.launchPick,actions:h})]})}function Dr(){const[t,s]=n.useState({ide:[],cli:[],ext:[],acp:[]}),[o,a]=n.useState(!0);n.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(r=>r.json()).then(r=>{const x=[],u=[],h=[],d=[];Object.values(r.providers||{}).forEach(v=>{const f={name:v.name||"Unknown",status:v.status||"Stable",details:v.details||"Community Provider"};v.category==="ide"?x.push(f):v.category==="cli"?u.push(f):v.category==="extension"?h.push(f):v.category==="acp"&&d.push(f)});const l=(v,f)=>{const p={Stable:1,Beta:2,WIP:3},A=p[v.status]||99,$=p[f.status]||99;return A!==$?A-$:v.name.localeCompare(f.name)};s({ide:x.sort(l),cli:u.sort(l),ext:h.sort(l),acp:d.sort(l)})}).catch(r=>console.error("Failed to load capabilities:",r)).finally(()=>a(!1))},[]);const i=r=>r==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(nn,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):r==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Kt,{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(fs,{className:"w-4 h-4"})," ",e.jsx("span",{children:r})]}),c=r=>e.jsx("div",{className:"bg-bg-panel border border-border-card rounded-md overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-subtle border-b border-border-card 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-card text-sm",children:r.map((x,u)=>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:x.name}),e.jsx("td",{className:"py-3 px-4",children:i(x.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:x.details})]},u))})]})});return o?e.jsxs("div",{className:"p-8 max-w-4xl mx-auto flex flex-col items-center justify-center min-h-[50vh]",children:[e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mb-4"}),e.jsx("p",{className:"text-text-muted",children:"Loading providers registry..."})]}):e.jsxs("div",{className:"p-8 max-w-4xl mx-auto animate-fade-in pb-20",children:[e.jsx(Ns,{title:"Capabilities & Provider Status",subtitle:"Support matrix for IDEs, CLI Agents, and AI Extensions",icon:e.jsx(ps,{})}),e.jsxs("div",{className:"space-y-12 mt-8",children:[e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-blue-500/10 text-blue-400",children:e.jsx(Qe,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"IDE Support"})]}),c(t.ide)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-purple-500/10 text-purple-400",children:e.jsx(Ft,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"Standalone CLI Agents"})]}),c(t.cli)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-green-500/10 text-green-400",children:e.jsx(ut,{className:"w-5 h-5"})}),e.jsx("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:"AI Extensions"})]}),c(t.ext)]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-2 rounded-md bg-orange-500/10 text-orange-400",children:e.jsx(ut,{className:"w-5 h-5"})}),e.jsxs("h2",{className:"text-xl font-semibold text-text-main tracking-tight",children:["ACP Agents (",t.acp.length," loaded)"]})]}),c(t.acp)]})]})]})}function Br(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,a=new URLSearchParams(window.location.search).get("token");return a?`${s}?token=${encodeURIComponent(a)}`:s}const os=Br(),is=3e3,Wr=3e4;let Ue=null,Or=0;const Nt=new Map,Wt=new Set;let Ge=null,Kr=null,lt=null;async function vt(t,s,o){const a=Ue;if(a&&a.readyState===WebSocket.OPEN){const c=`req_${++Or}_${Date.now()}`;return new Promise((r,x)=>{const u=setTimeout(()=>{Nt.delete(c),x(new Error(`WS command timeout: ${s}`))},3e4);Nt.set(c,{resolve:h=>{clearTimeout(u),r(h)},reject:h=>{clearTimeout(u),x(h)}}),a.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:o||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:o||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class Fr{constructor(s){Me(this,"daemonId");Me(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ue==null?void 0:Ue.readyState)===WebSocket.OPEN}get connectionState(){return(Ue==null?void 0:Ue.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,o){return vt(this.daemonId,s,o)}async sendInput(s,o){const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return vt(a,"cdp_remote_action",{action:s,params:o})}startScreenshots(s){this.screenshotIdeType=s||null,Ge&&(clearInterval(Ge),Ge=null);const o=async()=>{if(this.hasCommandChannel)try{const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await vt(a,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(r=>r.blob());Wt.forEach(r=>r(this.daemonId,c))}}catch{}};o(),Ge=setInterval(o,2e3)}stopScreenshots(s){Ge&&(clearInterval(Ge),Ge=null)}}let Je=null;function Hr(t){(!Je||Je.daemonId!==t)&&(Je=new Fr(t));const s=Te._originalGet||Te.get.bind(Te);Te._originalGet=s,Te.get=o=>o===t||o.startsWith("standalone")?Je:s(o),Te.getState=o=>(o===t||o.startsWith("standalone"))&&(Je==null?void 0:Je.connectionState)||"disconnected",Te.onScreenshot=(o,a)=>(Wt.add(a),()=>{Wt.delete(a)})}function zr({children:t}){const s=n.useRef(Yt()),o=Yt();s.current=o;const{setUserName:a}=dt(),i=n.useRef(a);i.current=a;const[,c]=n.useState("disconnected"),r=n.useCallback((l,v)=>{c(l),lt==null||lt(l,v)},[]),x=n.useRef(null),u=n.useRef(),h=n.useRef(is),d=n.useRef(!0);return n.useEffect(()=>{d.current=!0;function l(){var p,A;if(!d.current||((p=x.current)==null?void 0:p.readyState)===WebSocket.OPEN||((A=x.current)==null?void 0:A.readyState)===WebSocket.CONNECTING)return;r("connecting"),console.log(`[Standalone WS] Connecting to ${os}...`);let f;try{f=new WebSocket(os)}catch($){console.error("[Standalone WS] Failed to create WebSocket:",$),v();return}x.current=f,f.onopen=()=>{if(!d.current){f.close();return}r("connected"),h.current=is,console.log("[Standalone WS] Connected")},Ue=f,f.onmessage=$=>{var w;try{const S=JSON.parse($.data);if((S.type==="command_result"||S.type==="error")&&S.requestId){const O=Nt.get(S.requestId);O&&(Nt.delete(S.requestId),S.type==="error"?O.reject(new Error(((w=S.data)==null?void 0:w.message)||"Command failed")):O.resolve(S.data));return}if(S.type==="pty_output"){Te.emitPtyOutput(S.cliId,S.data);return}if(S.type==="status"||S.type==="initial_state"){const O=S.data;if(!O)return;const{injectEntries:F,markLoaded:R}=s.current,T=O.id||"standalone";Kr=T,Hr(T),r("connected",T);const D=Dn(O,{daemonId:T});D.length>0&&F(D),R(),O.userName&&i.current&&i.current(O.userName)}}catch(S){console.error("[Standalone WS] Parse error:",S)}},f.onclose=()=>{d.current&&(r("disconnected"),x.current=null,v())},f.onerror=$=>{console.warn("[Standalone WS] Error, will reconnect:",$)}}function v(){if(!d.current)return;clearTimeout(u.current);const f=h.current;console.log(`[Standalone WS] Reconnecting in ${f}ms...`),u.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,Wr),l()},f)}return l(),()=>{d.current=!1,clearTimeout(u.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,Ue=null)}},[]),e.jsx(e.Fragment,{children:t})}function Ur({children:t}){const[s,o]=n.useState("disconnected"),[a,i]=n.useState(null);n.useEffect(()=>(lt=(r,x)=>{o(r),x&&i(x)},()=>{lt=null}),[]);const c=n.useMemo(()=>{const r=s==="connected",x={};return a&&(x[a]=r?"connected":"connecting"),x.standalone=r?"connected":"connecting",{wsStatus:s,isConnected:r,connectionStates:x}},[s,a]);return e.jsx(Vs,{connectionOverrides:c,children:e.jsx(zr,{children:t})})}const Yr=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Zs,{}),label:"Dashboard"},{id:"capabilities",path:"/capabilities",icon:e.jsx(ps,{}),label:"Capabilities"},{id:"machine",path:"/machines",icon:e.jsx(Qs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Ot,{}),label:"Settings"}];function Vr({children:t}){const s=pt(),o=Ws(),[a,i]=n.useState(!1),[c,r]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=d=>{s(d),i(!1)},u=()=>{r(d=>{const l=!d;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},h=d=>`nav-item${o.pathname.startsWith(d)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${a?" mobile-menu-open":""}${c?" 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"})]}),a&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:d=>d.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${a?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&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:Yr.map(d=>e.jsxs("div",{className:h(d.path),id:`nav-${d.id}`,onClick:()=>x(d.path),title:c?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!c&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${o.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(sn,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.67"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&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 Xr=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],qr=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Gr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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 Jr(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.6.67"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Xr.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:ks.map(t=>t.name)},{label:"Extension agents",items:Cs.map(t=>t.name)},{label:"CLI agents",items:Ss.map(t=>t.name)}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Gr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:qr.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Zr(){const{ides:t}=dt(),s=t.find(l=>l.type==="adhdev-daemon"),o=(s==null?void 0:s.detectedIdes)||[],{sendCommand:a}=Ve(),{userName:i}=dt(),[c,r]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&r(i)},[i]);const x=l=>{const v=l.target.value.trim();s!=null&&s.id&&v!==i&&a(s.id,"set_user_name",{userName:v}).catch(console.error)},[u,h]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=l=>{h(l);try{localStorage.setItem("adhdev_sound",l?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Ns,{icon:e.jsx(Ot,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(st,{title:"Daemon",className:"mb-4",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.6.67"]}),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(st,{title:"Detected IDEs",className:"mb-4",children:o.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:o.map(l=>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 ${l.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:l.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:l.type})]},l.type))})}),e.jsx(st,{title:"Machine",className:"mb-4",children:e.jsx(tr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(st,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(ar,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(ur,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(gr,{})]})]})}),e.jsx(st,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(er,{}),e.jsx(nt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(hn,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:u,onChange:d})]})}),e.jsx(st,{title:"Preferences",className:"mb-4",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(en,{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:c,onChange:l=>r(l.target.value),onBlur:x,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})]})}lr();function cs(){const{ides:t}=dt(),s=t.find(o=>{var a;return o.daemonMode||((a=o.id)==null?void 0:a.startsWith("standalone"))});return s?e.jsx(gt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(gt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(gt,{to:"/dashboard",replace:!0})}function Qr(){return e.jsx(Os,{children:e.jsx(Ur,{children:e.jsx(Js,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Vr,{children:e.jsxs(Ks,{children:[e.jsx(He,{path:"/dashboard",element:e.jsx(kr,{})}),e.jsx(He,{path:"/ide/:id",element:e.jsx(Cr,{})}),e.jsx(He,{path:"/machine",element:e.jsx(cs,{})}),e.jsx(He,{path:"/machines/:id",element:e.jsx(Lr,{})}),e.jsx(He,{path:"/machines",element:e.jsx(cs,{})}),e.jsx(He,{path:"/capabilities",element:e.jsx(Dr,{})}),e.jsx(He,{path:"/about",element:e.jsx(Jr,{})}),e.jsx(He,{path:"/settings",element:e.jsx(Zr,{})}),e.jsx(He,{path:"*",element:e.jsx(gt,{to:"/dashboard",replace:!0})})]})})})})})}Fs(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(Qr,{})}));