@adhdev/daemon-standalone 0.7.30 → 0.7.33

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.
@@ -0,0 +1,68 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-Pyzj0-Nv.js","assets/vendor-BeOT3woc.js"])))=>i.map(i=>d[i]);
2
+ var wn=Object.defineProperty;var kn=(t,s,n)=>s in t?wn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var xe=(t,s,n)=>kn(t,typeof s!="symbol"?s+"":s,n);import{r as o,j as e,M as vs,a as ws,b as Nn,c as Sn,u as ct,t as Cn,d as In,e as Mn,f as Tn,g as En,D as An,R as Rn,h as ks,i as Ns,k as Ln,B as _n,l as $n,m as Ee,N as bt,n as Pn}from"./vendor-BeOT3woc.js";import{_ as Dn}from"./terminal-Pyzj0-Nv.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const c of a)if(c.type==="childList")for(const i of c.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(a){const c={};return a.integrity&&(c.integrity=a.integrity),a.referrerPolicy&&(c.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?c.credentials="include":a.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(a){if(a.ep)return;a.ep=!0;const c=n(a);fetch(a.href,c)}})();const Ss=o.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}),Cs=o.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Zt(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.childSessions)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Rt(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},a=s.version??n.version??t.version,c=s.serverVersion??t.serverVersion??n.serverVersion,i=s.versionMismatch===!0||t.versionMismatch===!0;return a&&(r.version=a),c&&(r.serverVersion=c),a&&c&&a===c?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||i&&a&&c&&a!==c)&&(r.versionMismatch=!0),r)}function Bn(t,s){var i,h,l,x,d,f,b;const n=Date.now();if(s.length===0)return t.map(u=>({...u,_lastUpdate:n}));const r=new Map;for(const u of s)r.set(u.id,u);for(const u of t){const m=r.get(u.id);if(!m){r.set(u.id,{...u,_lastUpdate:n});continue}const v=Zt(u),N=Zt(m);if(v>N){const g=(i=u.chats)!=null&&i.length?u.chats:m.chats,p=Rt(m,u,{...m,...u,chats:g,_lastUpdate:n});r.set(u.id,p)}else if(v<N){const g={};if(u.status&&u.status!==m.status&&(g.status=u.status),u.cdpConnected!==void 0&&(g.cdpConnected=u.cdpConnected),(h=u.chats)!=null&&h.length&&!((l=m.chats)!=null&&l.length)&&(g.chats=u.chats),u.machineNickname!==void 0&&u.machineNickname!==m.machineNickname&&(g.machineNickname=u.machineNickname),u.version!==void 0&&(g.version=u.version),u.serverVersion!==void 0&&(g.serverVersion=u.serverVersion),u.versionMismatch===!0&&(g.versionMismatch=!0),Object.keys(g).length>0){const p=Rt(m,u,{...m,...g,_lastUpdate:m._lastUpdate});r.set(u.id,p)}}else{const g=u.timestamp||n,p=m._lastUpdate||m.timestamp||0;if(g>=p){const w=(x=u.chats)!=null&&x.length?u.chats:m.chats,T=Rt(m,u,{...m,...u,chats:w,_lastUpdate:n});r.set(u.id,T)}else(d=u.chats)!=null&&d.length&&!((f=m.chats)!=null&&f.length)&&r.set(u.id,{...m,chats:u.chats})}}const a=new Set(t.map(u=>u.id)),c=new Set;for(const u of t){const m=u.daemonId||((b=u.id)==null?void 0:b.split(":")[0]);m&&c.add(m)}for(const[u,m]of r){const v=m.daemonId||u.split(":")[0];if(!c.has(v))continue;const N=n-(m._lastUpdate||m.timestamp||0);(m.transport==="pty"&&!a.has(u)&&N>1e4||m.transport==="acp"&&!a.has(u)&&N>1e4||m.transport==="cdp-page"&&!a.has(u)&&N>3e4)&&r.delete(u)}for(const[u,m]of r)n-(m._lastUpdate||m.timestamp||0)>3e5&&m.status!=="online"&&r.delete(u);return Array.from(r.values())}function Wn(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function On({children:t,connectionOverrides:s}){const[n,r]=o.useState([]),[a,c]=o.useState({}),[i,h]=o.useState(!1),[l,x]=o.useState([]),[d,f]=o.useState(void 0),b=o.useRef(n);o.useEffect(()=>{b.current=n},[n]);const u=o.useCallback((w,T)=>{r(y=>{let S=!1;const k=y.map(j=>j.id!==w||j.chats===T?j:(S=!0,{...j,chats:T}));return S?k:y})},[]),m=o.useCallback(w=>{r(T=>{const y=T.length===0?w:Bn(w,T);return Wn(T,y)?T:y})},[]),v=o.useCallback(()=>h(!0),[]),N=o.useMemo(()=>({injectEntries:m,markLoaded:v,getIdes:()=>b.current}),[m,v]),g=s,p=o.useMemo(()=>({ides:n,updateIdeChats:u,screenshotMap:a,setScreenshotMap:c,initialLoaded:i,toasts:l,setToasts:x,wsStatus:(g==null?void 0:g.wsStatus)??"connected",isConnected:(g==null?void 0:g.isConnected)??!0,connectionStates:(g==null?void 0:g.connectionStates)??{},connectionTransports:(g==null?void 0:g.connectionTransports)??{},showReconnected:(g==null?void 0:g.showReconnected)??!1,retryConnection:g==null?void 0:g.retryConnection,isP2PActive:(g==null?void 0:g.isP2PActive)??!1,p2pStates:(g==null?void 0:g.p2pStates)??{},userRole:g==null?void 0:g.userRole,userName:d,setUserName:f}),[n,u,a,i,l,g==null?void 0:g.wsStatus,g==null?void 0:g.isConnected,g==null?void 0:g.connectionStates,g==null?void 0:g.connectionTransports,g==null?void 0:g.showReconnected,g==null?void 0:g.retryConnection,g==null?void 0:g.isP2PActive,g==null?void 0:g.p2pStates,g==null?void 0:g.userRole,d]);return e.jsx(Cs.Provider,{value:N,children:e.jsx(Ss.Provider,{value:p,children:t})})}function it(){return o.useContext(Ss)}function Qt(){return o.useContext(Cs)}function Is(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function a(h){return h.startsWith("http")?h:`${s}${h.startsWith("/")?"":"/"}${h}`}function c(h){const l=n==null?void 0:n(),x=a(h),d=h.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!h.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function i(h,l={}){const x={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const f=a(h),b=await fetch(f,{...l,headers:x});if(b.status===401)throw r==null||r(),new Error("Unauthorized");if(!b.ok){const u=await b.json().catch(()=>({error:b.statusText}));throw new Error(u.error||`API Error: ${b.status}`)}return b.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:h=>i(`/api/v1/daemons/${h}/status`),sendCommand:(h,l,x={})=>i(`/api/v1/daemons/${h}/command`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),execTerminal:(h,l,x)=>i(`/api/v1/daemons/${h}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:x})}),sendAgentMessage:(h,l,x)=>i(`/api/v1/shortcuts/${h}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:x})}),getAgentStatus:h=>i(`/api/v1/shortcuts/${h}/status`),approveAgent:(h,l,x)=>i(`/api/v1/shortcuts/${h}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:x?"approve":"reject"})}),getMuxState:h=>i(`/api/v1/mux/${encodeURIComponent(h)}/state`),getMuxSocketInfo:h=>i(`/api/v1/mux/${encodeURIComponent(h)}/socket-info`),controlMux:(h,l,x={})=>i(`/api/v1/mux/${encodeURIComponent(h)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),getMuxEventsUrl:h=>c(`/api/v1/mux/${encodeURIComponent(h)}/events`),getRuntimeEventsUrl:h=>c(`/api/v1/runtime/${encodeURIComponent(h)}/events`),request:i}}const Kn=Is({baseUrl:"http://localhost:3847"}),zn=o.createContext(Kn);function Fn({client:t,children:s}){return e.jsx(zn.Provider,{value:t,children:s})}const Hn={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ms=o.createContext(Hn);function Un({value:t,children:s}){return e.jsx(Ms.Provider,{value:t,children:s})}function $e(){return o.useContext(Ms)}const le={size:18};function Ts({size:t=le.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 Es({size:t=le.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 Vn({size:t=le.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function qn({size:t=le.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 Yn({size:t=le.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Nt({size:t=le.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 Gn({size:t=le.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 Ht({size:t=le.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 As({size:t=le.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 Rs({size:t=le.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 Ye({size:t=le.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 _e({size:t=le.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 Ls({size:t=le.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 Xn({size:t=le.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 Dt({size:t=le.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 _s({size:t=le.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 Ut({size:t=le.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 Ge({size:t=le.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 $s({size:t=le.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 Ps({size:t=le.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 Jn({size:t=le.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 Vt({size:t=le.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 Ds({size:t=le.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 Bs({size:t=le.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 Zn({size:t=le.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 Qn({size:t=le.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 Ws({size:t=le.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 er({size:t=le.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 tr({size:t=le.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 sr({size:t=le.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 nr({size:t=le.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function rr(t){const n=t.split(`
3
+ `).map(h=>{if(!h.includes("\r"))return h;const l=h.split("\r").map(f=>f.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(f=>f.startsWith("⏺"));if(x.length>0)return x[x.length-1];const d=l.filter(f=>!(/^[❯›>]\s*$/.test(f)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(f)&&f.length<40||/^[╭╰│├╮╯─═]+$/.test(f)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
4
+ `).split(`
5
+ `),r={},a=[];let c=!1;for(const h of n){const l=h.trim();if(l===""){c=!1,a.push("");continue}if(/^❯\s*$/.test(l)||/^>\s*$/.test(l)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(l)||/^◐\s/.test(l)||/\/effort/.test(l)||/^⎿\s+(Tip|Note|Hint):/.test(l)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(l)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(l)||/Brewing[…\.]{0,3}\s*\d*$/i.test(l)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(l)||/^Auto-updating/i.test(l))continue;if(/^[⏺●·⏵]/.test(h)){const d=h.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const f=h.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);f&&(r[f]=(r[f]||0)+1)}c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(h)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(h)||c&&/^\s{2,}/.test(h))continue;c=!1;const x=h.replace(/^❯\s+/,"");a.push(x)}const i=a.join(`
6
+ `).replace(/\n{3,}/g,`
7
+
8
+ `).trim();return{toolCounts:r,textContent:i,hasTools:Object.keys(r).length>0}}function Bt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function ar(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ve(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(c=>(c==null?void 0:c.text)||"").join(`
9
+ `):String(n.content||"");return[n.id?`id:${n.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",typeof n.index=="number"?`msgIndex:${n.index}`:"",n.timestamp?`ts:${n.timestamp}`:"",n.role?`role:${n.role}`:"",r?`content:${r.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const es=700,or=o.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(vs,{remarkPlugins:[ws],children:s.text}),e.jsx("span",{className:"action-time",children:Bt(s.timestamp)})]})},(t,s)=>t.log===s.log),ir=o.memo(function({message:s,receivedAt:n,agentName:r,userName:a,isCliMode:c,isExpanded:i,isTextExpanded:h,onToggleExpanded:l,onToggleTextExpanded:x}){var T;const d=(s.role||"").toLowerCase(),f=d==="user"||d==="human",b=s.kind||(d==="tool"?"tool":"standard"),u=typeof s.content=="string"?s.content:(s.content||[]).map(y=>y.text||"").join(`
10
+ `);if(b==="thought"){const y=((T=s.meta)==null?void 0:T.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Zn,{size:13}),e.jsx("span",{children:y})]}),e.jsx("div",{className:"chat-msg-body",children:u})]})}if(b==="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:u.split(`
11
+ `)[0].slice(0,80)})]});if(b==="terminal"){const y=s.meta||{},S=y.isRunning?"⏳":"✅",k=y.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:S}),e.jsx("span",{children:k})]}),e.jsx("pre",{className:"chat-msg-body",children:u})]})}if(b==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:u.slice(0,100)});const m=!f&&c?rr(u):null,v=m?m.textContent:u,N=m?Object.entries(m.toolCounts):[],g=c&&!f&&!i&&v.length>es,p=i?u:g&&!h?v.slice(0,es):v,w=ar(p);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${f?"self-end":"self-start"}`,children:[N.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[N.map(([y,S])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",y,S>1?` ×${S}`:""]},y)),(m==null?void 0:m.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:i?"Collapse":"Original"}),!v&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Bt(n)})]}),(v||f)&&e.jsxs("div",{className:`chat-bubble ${f?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${v?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:f?a||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Bt(n)})]}),v&&e.jsx("div",{className:"chat-markdown",children:w?e.jsx(vs,{remarkPlugins:[ws,Nn,Sn],children:p}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:p})}),g&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:h?"Collapse ↑":`Show more (${Math.round(v.length/100)*100} chars) ↓`})]})]})},(t,s)=>t.message===s.message&&t.receivedAt===s.receivedAt&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isExpanded===s.isExpanded&&t.isTextExpanded===s.isTextExpanded),cr=o.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:c=!1,isWorking:i=!1,contextKey:h="",receivedAtMap:l={},emptyState:x,onLoadMore:d,isLoadingMore:f,hasMoreHistory:b,hiddenLiveCount:u=0,loadError:m},v){var Q;const N=o.useRef(null),g=o.useRef(null),p=o.useRef(0),w=o.useRef(""),T=o.useRef(!1),y=o.useRef(null),[S,k]=o.useState(new Set),[j,_]=o.useState(new Set),R=o.useRef(!1),D=()=>{const Y=N.current;return Y?Y.scrollHeight-Y.scrollTop-Y.clientHeight<200:!0},M=o.useCallback((Y="auto")=>{const se=N.current;se&&se.scrollTo({top:se.scrollHeight,behavior:Y})},[]),E=o.useCallback((Y="auto")=>{y.current!=null&&cancelAnimationFrame(y.current),y.current=requestAnimationFrame(()=>{y.current=null,M(Y)})},[M]),$=s.length>0?`${s.length}:${(((Q=s[s.length-1])==null?void 0:Q.content)||"").length}`:"0:0";o.useEffect(()=>{const Y=!T.current,se=w.current!==h;if(w.current=h,Y||se){T.current=!0,R.current=!1,E("auto"),p.current=s.length;return}s.length>p.current?R.current||E("auto"):D()&&!R.current&&E("auto"),p.current=s.length},[$,h,i,s.length,E]),o.useEffect(()=>()=>{y.current!=null&&cancelAnimationFrame(y.current)},[]),o.useImperativeHandle(v,()=>({scrollToBottom:(Y="smooth")=>{M(Y)}}),[M]),o.useEffect(()=>{const Y=N.current;if(!Y)return;let se;const ee=()=>{clearTimeout(se),se=setTimeout(()=>{R.current=!D()},50)};return Y.addEventListener("scroll",ee,{passive:!0}),()=>{Y.removeEventListener("scroll",ee),clearTimeout(se)}},[]);const O=o.useRef(0),C=o.useRef(!1);o.useEffect(()=>{const Y=N.current;if(!Y||!C.current||O.current===0)return;const se=Y.scrollHeight-O.current;se>0&&(Y.scrollTop=se),O.current=0,C.current=!1},[s.length]);const V=()=>{const Y=N.current;Y&&(O.current=Y.scrollHeight),C.current=!0,d==null||d()},Z=o.useMemo(()=>{const Y=s.map((B,P)=>({type:"message",data:B,index:P,ts:B.receivedAt||l[Ve(B,P)]||0}));if(!n||n.length===0)return Y;const se=[...n].sort((B,P)=>B.timestamp-P.timestamp).map((B,P)=>({type:"action",data:B,index:P,ts:B.timestamp})),ee=[];let ce=0;for(const B of Y){for(;ce<se.length&&B.ts>0&&se[ce].ts<B.ts;)ee.push(se[ce++]);ee.push(B)}for(;ce<se.length;)ee.push(se[ce++]);return ee},[s,n,l]),J=u>0||!!b,G=u>0?`↑ Show ${Math.min(u,80)} earlier messages${u>80?` (${u} hidden)`:""}`:m?`↻ ${m}`:"↑ Load older messages";return e.jsxs("div",{ref:N,"data-chat-scroll":!0,className:"chat-container",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),J&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:V,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${m&&u===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:G})}),Z.length===0&&!J&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Z.map(Y=>{if(Y.type==="action"){const W=Y.data;return e.jsx(or,{log:W},`action-${Y.index}`)}const se=Y.data,ee=Y.index,ce=Ve(se,ee),B=se.receivedAt||l[ce],P=`${h}-${ce}`,A=S.has(P),L=j.has(P);return e.jsx(ir,{message:se,receivedAt:B,agentName:r,userName:a,isCliMode:c,isExpanded:A,isTextExpanded:L,onToggleExpanded:()=>k(W=>{const U=new Set(W);return A?U.delete(P):U.add(P),U}),onToggleTextExpanded:()=>_(W=>{const U=new Set(W);return L?U.delete(P):U.add(P),U})},`msg-${ce}`)}),i&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:g})]})}),lr=o.memo(cr,(t,s)=>t.messages===s.messages&&t.actionLogs===s.actionLogs&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isWorking===s.isWorking&&t.contextKey===s.contextKey&&t.receivedAtMap===s.receivedAtMap&&t.emptyState===s.emptyState&&t.onLoadMore===s.onLoadMore&&t.isLoadingMore===s.isLoadingMore&&t.hasMoreHistory===s.hasMoreHistory&&t.hiddenLiveCount===s.hiddenLiveCount&&t.loadError===s.loadError);let ts=!1;const Os=o.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},a)=>{const c=o.useRef(null),[i,h]=o.useState(null),l=o.useRef([]),x=o.useRef(!1),d=o.useRef(!1),f=o.useRef(!1),b=()=>{const u=c.current;if(u){x.current&&(u.clear(),x.current=!1);for(const m of l.current)u.write(m);l.current=[],d.current&&(u.fit(),d.current=!1),f.current&&(u.bumpResize(),f.current=!1)}};return o.useImperativeHandle(a,()=>({write:u=>{c.current?c.current.write(u):l.current.push(u)},clear:()=>{c.current?c.current.clear():(l.current=[],x.current=!0)},fit:()=>{c.current?c.current.fit():d.current=!0},bumpResize:()=>{c.current?c.current.bumpResize():f.current=!0}}),[]),o.useEffect(()=>{if(!i)return;const u=requestAnimationFrame(()=>{var m;b(),(m=c.current)==null||m.fit()});return()=>cancelAnimationFrame(u)},[i]),o.useEffect(()=>{let u=!1;return Dn(()=>import("./terminal-Pyzj0-Nv.js").then(m=>m.i),__vite__mapDeps([0,1])).then(m=>{ts||(ts=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),u||h(()=>m.GhosttyTerminalView)}).catch(m=>{console.error("[CliTerminal] failed to load terminal renderer",m)}),()=>{u=!0}},[]),i?e.jsx(i,{ref:c,onInput:t,onResize:s,fontSize:n,readOnly:r,className:"w-full h-full rounded-lg overflow-hidden"}):e.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});Os.displayName="CliTerminal";function ht({label:t,value:s,sub:n,icon:r}){return e.jsxs("div",{className:"px-4 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-base flex items-center",children:r}),e.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:t})]}),e.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:s}),n&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function ss({value:t,max:s,label:n,color:r="#8b5cf6",detail:a,compact:c=!1}){const i=s>0?Math.min(Math.round(t/s*100),100):0,h=i>85?"#ef4444":i>60?"var(--status-warning)":r;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:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[i,"%"]})]}),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:`${i}%`,background:h}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[i,"%"]})]}),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:`${i}%`,background:`linear-gradient(90deg, ${h}, ${h}cc)`}})}),a&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:a})]})}function dr({cursorPos:t,viewportRef:s,imgRef:n}){var p;if(!t||!n.current)return null;const r=n.current,a=r.getBoundingClientRect(),c=(p=s.current)==null?void 0:p.getBoundingClientRect();if(!c)return null;const i=r.naturalWidth||a.width,h=r.naturalHeight||a.height,l=i/h,x=a.width/a.height;let d,f,b,u;l>x?(d=a.width,f=a.width/l,b=0,u=(a.height-f)/2):(f=a.height,d=a.height*l,b=(a.width-d)/2,u=0);const m=a.left-c.left+b+d*t.nx,v=a.top-c.top+u+f*t.ny,N=Math.max(8,Math.min(c.width-8,m)),g=Math.max(8,Math.min(c.height-8,v));return e.jsxs("div",{style:{position:"absolute",left:N-8,top:g-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function ur({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:c,imeText:i,setImeText:h,handleImeSubmit:l,isConnActive:x,zoom:d,isMobile:f,mobileFillZoom:b,onZoomOut:u,onZoomReset:m,onZoomIn:v,transportType:N,screenshotUsage:g,lastActionStatus:p}){return e.jsxs(e.Fragment,{children:[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:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{r(w=>!w),c(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),n&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:i,autoFocus:!0,onTouchStart:w=>w.stopPropagation(),onChange:w=>h(w.target.value),onKeyDown:w=>{l(w)},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:()=>{c(w=>!w),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${a?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:x?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:x?"#22c55e":"#eab308",boxShadow:x?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:x?"#22c55e":"#eab308"},children:x?"Connected":"WS"})]}),d>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),N==="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"}),N==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),g&&g.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:g.budgetExhausted?"#ef4444":"#c4b5fd",background:g.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:g.budgetExhausted?"TURN blocked":`TURN ${g.dailyUsedMinutes}/${g.dailyBudgetMinutes}m`}),p&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:p})]})]}),a&&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: ",d<=(f?b:1)+.01?f?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:w=>{w.stopPropagation(),u()},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(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:f?"FILL":"FIT"}),e.jsx("button",{onClick:w=>{w.stopPropagation(),v()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function hr({waitingLabel:t,waitingHint:s,transportType:n}){return e.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:t}),e.jsx("div",{className:"text-[11px] text-white/40",children:s}),n==="relay"&&e.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function xr(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function ns(t){return t==null||typeof t=="number"||typeof t=="boolean"?t:typeof t=="string"?t.length>64?`${t.slice(0,61)}...`:t:Array.isArray(t)?`Array(${t.length})`:typeof t=="object"?"Object":typeof t}function lt(t,s){const n=o.useRef(null),r=o.useRef(0);o.useEffect(()=>{if(!xr())return;r.current+=1;const a=n.current;if(!a){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([i,h])=>[i,ns(h)]))}),n.current=s;return}const c=Object.keys({...a,...s}).filter(i=>!Object.is(a[i],s[i]));c.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:c,snapshot:Object.fromEntries(c.map(i=>[i,ns(s[i])]))}),n.current=s})}function pr({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:a,minZoom:c,zoomRef:i,panXRef:h,panYRef:l,setPanX:x,setPanY:d,setZoom:f,lastWheelTimeRef:b,onAction:u,setLastActionStatus:m,spawnRippleFromNormalized:v,clampPan:N,isMobile:g,mobileFillZoom:p}){const[w,T]=o.useState(null),y=o.useRef(null),S=o.useRef(null),k=o.useRef(null),j=o.useRef(!1),_=o.useRef(null),R=o.useRef(0),D=o.useRef(null),M=o.useRef(1),E=o.useRef({x:0,y:0}),$=o.useRef(!1),O=o.useRef(r),C=o.useRef(u),V=()=>{if(y.current)return;const G={nx:.5,ny:.5};y.current=G,T(G)};return o.useEffect(()=>{O.current=r,r==="mouse"&&V()},[r]),o.useEffect(()=>{C.current=u},[u]),o.useEffect(()=>{const G=t.current;if(!G)return;const Q=P=>{if(!n.current)return null;const A=n.current.getBoundingClientRect();return!A.width||!A.height?null:{nx:Math.max(0,Math.min(1,(P.clientX-A.left)/A.width)),ny:Math.max(0,Math.min(1,(P.clientY-A.top)/A.height))}},Y=(P,A)=>{if(!n.current)return{dnx:0,dny:0};const L=n.current,W=L.getBoundingClientRect(),U=L.naturalWidth||W.width,H=L.naturalHeight||W.height,ae=U/H,de=W.width/W.height;let oe,re;return ae>de?(oe=W.width,re=W.width/ae):(re=W.height,oe=W.height*ae),{dnx:P/oe,dny:A/re}},se=(P,A,L)=>{if(L<=1.05)return;const W=-(P-.5)*100,U=-(A-.5)*100,H=N(W,U,L);(Math.abs(H.x-h.current)>.1||Math.abs(H.y-l.current)>.1)&&(x(H.x),d(H.y),h.current=H.x,l.current=H.y)},ee=P=>{const A=s.current;if(A&&P.target instanceof Node&&A.contains(P.target))P.preventDefault();else return;if(P.touches.length===1){const L=P.touches[0];S.current={x:L.clientX,y:L.clientY,time:Date.now()},k.current={x:L.clientX,y:L.clientY},$.current||(j.current=!1),_.current=setTimeout(()=>{if(!j.current&&!$.current)if(j.current=!0,O.current==="mouse"){const W=y.current||{nx:.5,ny:.5};m("Right Click"),v(W.nx,W.ny,"right"),C.current("input_click",{...W,button:"right"}).catch(()=>{})}else{const W=Q(L);W&&(m("Right Click"),v(W.nx,W.ny,"right"),C.current("input_click",{...W,button:"right"}).catch(()=>{}))}},500);return}if(P.touches.length===2){_.current&&clearTimeout(_.current),j.current=!0,$.current=!0;const L=P.touches[1].clientX-P.touches[0].clientX,W=P.touches[1].clientY-P.touches[0].clientY;D.current=Math.sqrt(L*L+W*W),M.current=i.current,E.current={x:(P.touches[0].clientX+P.touches[1].clientX)/2,y:(P.touches[0].clientY+P.touches[1].clientY)/2}}},ce=P=>{const A=s.current;if(A&&P.target instanceof Node&&A.contains(P.target)&&P.preventDefault(),P.touches.length===1&&k.current){const L=P.touches[0],W=L.clientX-k.current.x,U=L.clientY-k.current.y;if(!j.current&&S.current){const H=L.clientX-S.current.x,ae=L.clientY-S.current.y;Math.sqrt(H*H+ae*ae)>8&&(j.current=!0,_.current&&clearTimeout(_.current))}if(j.current)if(O.current==="mouse"){const H=Y(W,U),ae=y.current||{nx:.5,ny:.5},de=Math.max(0,Math.min(1,ae.nx+H.dnx)),oe=Math.max(0,Math.min(1,ae.ny+H.dny));y.current={nx:de,ny:oe},T({nx:de,ny:oe}),m(`Cursor: ${Math.round(de*100)}%, ${Math.round(oe*100)}%`),se(de,oe,i.current);const re=Date.now();re-b.current>=30&&(b.current=re,C.current("input_mouseMoved",{nx:de,ny:oe}).catch(()=>{}))}else if(i.current>1){const H=s.current;if(H){const ae=H.clientWidth,de=H.clientHeight,oe=h.current+W/ae*100,re=l.current+U/de*100,K=N(oe,re,i.current);x(K.x),d(K.y),h.current=K.x,l.current=K.y}}else{const H=Q(L);if(H){const ae=Date.now();ae-b.current>=40&&(b.current=ae,m("Scroll"),C.current("input_wheel",{nx:H.nx,ny:H.ny,deltaX:Math.round(-W*2.5),deltaY:Math.round(-U*2.5)}).catch(()=>{}))}}k.current={x:L.clientX,y:L.clientY};return}if(P.touches.length===2&&D.current!==null){const L=P.touches[1].clientX-P.touches[0].clientX,W=P.touches[1].clientY-P.touches[0].clientY,H=Math.sqrt(L*L+W*W)/D.current,ae=(P.touches[0].clientX+P.touches[1].clientX)/2,de=(P.touches[0].clientY+P.touches[1].clientY)/2,oe=ae-E.current.x,re=de-E.current.y,K=Math.abs(H-1)>.03;if(O.current==="mouse"){if(K){const X=Math.max(c,Math.min(5,M.current*H));f(X),i.current=X}else if(Math.abs(oe)>2||Math.abs(re)>2){const X=y.current||{nx:.5,ny:.5},F=Date.now();F-b.current>=30&&(b.current=F,m("Scroll"),C.current("input_wheel",{nx:X.nx,ny:X.ny,deltaX:Math.round(-oe*3),deltaY:Math.round(-re*3)}).catch(()=>{}))}}else{const X=Math.max(c,Math.min(5,M.current*H));f(X),i.current=X;const F=s.current;if(F&&X>1){const I=F.clientWidth,q=F.clientHeight,z=h.current+oe/I*100,ne=l.current+re/q*100,ue=N(z,ne,X);x(ue.x),d(ue.y),h.current=ue.x,l.current=ue.y}}E.current={x:ae,y:de}}},B=P=>{var A;if(_.current&&clearTimeout(_.current),D.current=null,P.touches.length===1&&$.current){const L=P.touches[0];S.current={x:L.clientX,y:L.clientY,time:Date.now()},k.current={x:L.clientX,y:L.clientY},j.current=!0;return}if(P.touches.length===0){if($.current){$.current=!1,j.current=!1;return}if(P.changedTouches.length===1&&!j.current){const L=P.changedTouches[0],W=Date.now(),U=W-(((A=S.current)==null?void 0:A.time)||0);if(U<60||U>400){j.current=!1;return}if(S.current){const H=L.clientX-S.current.x,ae=L.clientY-S.current.y;if(Math.sqrt(H*H+ae*ae)>12){j.current=!1;return}}if(O.current==="mouse"){const H=y.current||Q(L);H&&(m(`Click: ${Math.round(H.nx*100)}%, ${Math.round(H.ny*100)}%`),v(H.nx,H.ny,"left"),C.current("input_click",{...H}).catch(()=>{}))}else{const H=Q(L);if(!H)return;W-R.current<300?(m("Double tap"),v(H.nx,H.ny,"double"),C.current("input_click",{...H,clickCount:2}).catch(()=>{}),R.current=0):(m(`Tap: ${Math.round(H.nx*100)}%, ${Math.round(H.ny*100)}%`),v(H.nx,H.ny,"left"),C.current("input_click",{...H}).catch(()=>{}),R.current=W)}}j.current=!1}};return G.addEventListener("touchstart",ee,{passive:!1}),G.addEventListener("touchmove",ce,{passive:!1}),G.addEventListener("touchend",B,{passive:!1}),()=>{G.removeEventListener("touchstart",ee),G.removeEventListener("touchmove",ce),G.removeEventListener("touchend",B),_.current&&clearTimeout(_.current)}},[t,s,n,c,i,h,l,x,d,f,b,m,v,N]),{cursorPos:w,cursorPosRef:y,handleToggleInputMode:()=>{a(G=>{const Q=G==="touch"?"mouse":"touch";return Q==="mouse"&&V(),Q})},handleZoomReset:()=>{const G=g?p:1;f(G),i.current=G,x(0),d(0),h.current=0,l.current=0}}}function mr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:a,transportType:c}){const i=o.useRef(null),h=o.useRef(null),l=o.useRef(null),[x,d]=o.useState(null),[f,b]=o.useState(""),[,u]=o.useState(!1),[m,v]=o.useState([]),N=o.useRef(0),[g,p]=o.useState(!1),[w,T]=o.useState(!1),y=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[S,k]=o.useState(y?"mouse":"touch"),[j,_]=o.useState(1),R=o.useRef(!1),[D,M]=o.useState(1),[E,$]=o.useState(0),[O,C]=o.useState(0);lt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:S,zoom:D,panX:E,panY:O,isMenuOpen:g,isImeOpen:w});const V=o.useRef(0),Z=o.useRef(D),J=o.useRef(E),G=o.useRef(O);o.useEffect(()=>{Z.current=D},[D]),o.useEffect(()=>{J.current=E},[E]),o.useEffect(()=>{G.current=O},[O]),o.useEffect(()=>{var K;(K=i.current)==null||K.focus()},[]);const Q=n==="connected",Y=r,se=Q?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=Q?"The remote stream is warming up":"Waiting for the remote stream to catch up";o.useEffect(()=>{if(!y||R.current||!Y)return;const K=l.current,X=h.current;if(!K||!X)return;const F=()=>{const I=X.clientWidth,q=X.clientHeight,z=K.naturalWidth,ne=K.naturalHeight;if(!z||!ne||!I||!q)return;const ue=Math.min(I/z,q/ne),ie=Math.max(I/z,q/ne)/ue;ie>1.01&&(_(ie),M(ie),Z.current=ie),R.current=!0};K.complete&&K.naturalWidth?F():K.addEventListener("load",F,{once:!0})},[Y,y]);const ce=.5;o.useEffect(()=>{D<=ce&&($(0),C(0))},[D,ce]);const B=(K,X,F)=>{if(F<=ce)return{x:0,y:0};const I=(F-1)/(2*F)*100,q=(F-1)/(2*F)*100;return{x:Math.max(-I,Math.min(I,K)),y:Math.max(-q,Math.min(q,X))}},P=(K,X)=>{if(!l.current)return null;const F=l.current.getBoundingClientRect();return!F.width||!F.height?null:{nx:Math.max(0,Math.min(1,(K-F.left)/F.width)),ny:Math.max(0,Math.min(1,(X-F.top)/F.height))}},A=(K,X,F)=>{const I=h.current;if(!I)return;const q=I.getBoundingClientRect(),z=++N.current;v(ne=>[...ne,{id:z,x:K-q.left,y:X-q.top,type:F}]),setTimeout(()=>v(ne=>ne.filter(ue=>ue.id!==z)),600)},L=(K,X,F)=>{const I=l.current,q=h.current;if(!I||!q)return;const z=I.getBoundingClientRect(),ne=q.getBoundingClientRect(),ue=I.naturalWidth||z.width,te=I.naturalHeight||z.height,ie=ue/te,Te=z.width/z.height;let we,ke,Je,Ze;ie>Te?(we=z.width,ke=z.width/ie,Je=0,Ze=(z.height-ke)/2):(ke=z.height,we=z.height*ie,Je=(z.width-we)/2,Ze=0);const dt=z.left-ne.left+Je+we*K,He=z.top-ne.top+Ze+ke*X,ut=++N.current;v(Qe=>[...Qe,{id:ut,x:dt,y:He,type:F}]),setTimeout(()=>v(Qe=>Qe.filter(Et=>Et.id!==ut)),600)},W=async K=>{var F;const X=P(K.clientX,K.clientY);if(X){d(`Click: ${Math.round(X.nx*100)}%, ${Math.round(X.ny*100)}%`),A(K.clientX,K.clientY,"left"),(F=i.current)==null||F.focus();try{const I=await t("input_click",{nx:X.nx,ny:X.ny});I!=null&&I.success||s(`❌ Click failed: ${I==null?void 0:I.error}`)}catch(I){s(`❌ Click error: ${I.message||I}`)}}},U=async(K,X,F,I=0)=>{try{await t("input_key",{type:F?"char":"keyDown",key:K,code:X,text:F?K:void 0,unmodifiedText:F?K:void 0,modifiers:I})}catch(q){s(`❌ Key error: ${q.message||q}`)}},H=async K=>{if(K.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(K.key)&&K.preventDefault();let F=0;K.altKey&&(F|=1),K.ctrlKey&&(F|=2),K.metaKey&&(F|=4),K.shiftKey&&(F|=8),d(`Key: ${K.key}`),await U(K.key,K.code,K.key.length===1,F)},ae=async K=>{if(K.key==="Enter"){if(K.nativeEvent.isComposing)return;if(f){const X=f;b(""),d(`IME Sent: ${X}`);try{const F=await t("input_type",{text:X});F!=null&&F.success||s(`❌ IME error: ${F==null?void 0:F.error}`)}catch(F){s(`❌ IME error: ${F.message}`)}}else d("Key: Enter"),await U("Enter","Enter",!1)}};o.useEffect(()=>{const K=i.current;if(!K)return;const X=F=>{var I;if((I=l.current)!=null&&I.contains(F.target)){F.preventDefault();const q=Date.now();if(q-V.current<40)return;V.current=q;const z=P(F.clientX,F.clientY);if(!z)return;d(`Scroll: ${Math.round(F.deltaY)}`),t("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(F.deltaX),deltaY:Math.round(F.deltaY)}).catch(()=>{})}};return K.addEventListener("wheel",X,{passive:!1}),()=>K.removeEventListener("wheel",X)},[t]);const{cursorPos:de,handleToggleInputMode:oe,handleZoomReset:re}=pr({containerRef:i,viewportRef:h,imgRef:l,inputMode:S,setInputMode:k,minZoom:ce,zoomRef:Z,panXRef:J,panYRef:G,setPanX:$,setPanY:C,setZoom:M,lastWheelTimeRef:V,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:L,clampPan:B,isMobile:y,mobileFillZoom:j});return e.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:H,onContextMenu:K=>K.preventDefault(),onFocus:()=>u(!0),onBlur:()=>u(!1),tabIndex:0,children:[e.jsxs("div",{ref:h,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[Y?e.jsx("img",{ref:l,src:Y,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${D}) translate(${E}%, ${O}%)`,transformOrigin:"center center",cursor:S==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:W,onContextMenu:K=>K.preventDefault(),onDragStart:K=>K.preventDefault()}):e.jsx(hr,{waitingLabel:se,waitingHint:ee,transportType:c}),S==="mouse"&&Y&&e.jsx(dr,{cursorPos:de,viewportRef:h,imgRef:l}),m.map(K=>{const F={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[K.type];return e.jsxs("div",{style:{position:"absolute",left:K.x,top:K.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${F}, 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(${F}, 0.9)`,boxShadow:`0 0 12px rgba(${F}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},K.id)})]}),e.jsx(ur,{inputMode:S,onToggleInputMode:oe,isImeOpen:w,setIsImeOpen:T,isMenuOpen:g,setIsMenuOpen:p,imeText:f,setImeText:b,handleImeSubmit:ae,isConnActive:Q,zoom:D,isMobile:y,mobileFillZoom:j,onZoomOut:()=>M(K=>Math.max(.5,K-.25)),onZoomReset:re,onZoomIn:()=>M(K=>Math.min(5,K+.25)),transportType:c,screenshotUsage:a,lastActionStatus:x}),e.jsx("style",{children:`
12
+ @keyframes slideUp {
13
+ from { opacity: 0; transform: translateY(6px); }
14
+ to { opacity: 1; transform: translateY(0); }
15
+ }
16
+ @keyframes slideUpSidebar {
17
+ from { opacity: 0; transform: translateY(6px); }
18
+ to { opacity: 1; transform: translateY(0); }
19
+ }
20
+ @keyframes click-ripple-ring {
21
+ 0% { transform: scale(0.3); opacity: 1; }
22
+ 100% { transform: scale(2.2); opacity: 0; }
23
+ }
24
+ @keyframes click-ripple-dot {
25
+ 0% { transform: scale(1); opacity: 0.9; }
26
+ 50% { transform: scale(1.8); opacity: 0.6; }
27
+ 100% { transform: scale(0.5); opacity: 0; }
28
+ }
29
+ @keyframes remote-float {
30
+ 0% { transform: translateY(0px); }
31
+ 50% { transform: translateY(-7px); }
32
+ 100% { transform: translateY(0px); }
33
+ }
34
+ `})]})}function fr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:a,onDismiss:c,onClickAt:i,onKeyDown:h,badge:l,emptyMessage:x,aspectRatio:d,className:f,style:b}){const u=o.useRef(null),m=o.useCallback(v=>{if(!r||!i||!u.current)return;const N=u.current,g=N.getBoundingClientRect(),p=(v.clientX-g.left)/g.width*N.naturalWidth,w=(v.clientY-g.top)/g.height*N.naturalHeight;i(p,w,N.naturalWidth,N.naturalHeight)},[r,i]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${f||""}`,style:{aspectRatio:d||"16/9",...b},children:[e.jsx("img",{ref:u,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:`${r?"screenshot-interactive":""} ${f||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?h:void 0,style:b,children:[e.jsx("img",{ref:u,src:t,alt:"IDE Screenshot",onClick:r?m:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),l&&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:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${f||""}`,style:b,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:x||"Waiting for screenshot stream..."}),a&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",a]}),e.jsx("style",{children:`
35
+ @keyframes remote-float {
36
+ 0% { transform: translateY(0px); }
37
+ 50% { transform: translateY(-7px); }
38
+ 100% { transform: translateY(0px); }
39
+ }
40
+ `})]})}function Ks({activeConv:t,onModalButton:s}){const[n,r]=o.useState(null);if(o.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const a=i=>{n||(r(i),s(i))},c=i=>i.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"text-white py-2.5 px-4 shrink-0 z-[5]",style:{background:"linear-gradient(135deg, var(--status-warning), color-mix(in srgb, var(--status-warning) 85%, #000))"},children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Ut,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((i,h)=>{const l=c(i).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),f=n===i,b=n!==null;return e.jsx("button",{onClick:()=>a(i),disabled:b,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${b&&!f?"opacity-40":"opacity-100"} ${b?"cursor-not-allowed":"cursor-pointer"}`,style:x?{color:"var(--status-warning)"}:void 0,children:f?"⏳ ...":c(i)},h)})})]})]})}const Ne=new Map;function gr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:a,serverModel:c,serverMode:i,acpConfigOptions:h,acpModes:l}){var ce;const{sendCommand:x}=$e(),d=!!(h||l),f=`${t}:${s||r}`,b=Ne.get(f),[u,m]=o.useState(!1),[v,N]=o.useState(!1),[g,p]=o.useState((b==null?void 0:b.models)||[]),[w,T]=o.useState((b==null?void 0:b.modes)||[]),y=B=>B?typeof B=="string"?B:typeof B=="object"?B.name||B.id||JSON.stringify(B):String(B):"",[S,k]=o.useState(y(c)),[j,_]=o.useState(y(i)),[R,D]=o.useState(!1),[M,E]=o.useState(!1),$=o.useRef(0),O=B=>B.map(P=>typeof P=="string"?P:(P==null?void 0:P.name)||(P==null?void 0:P.id)||String(P));o.useEffect(()=>{if(h){const B=h.find(P=>P.category==="model");if(B){const P=O(B.options.map(L=>L.value));p(P),B.currentValue&&k(y(B.currentValue));const A=Ne.get(f)||{models:[],modes:[]};Ne.set(f,{...A,models:P})}}if(l&&l.length>0){const B=O(l.map(A=>A.id));T(B);const P=Ne.get(f)||{models:[],modes:[]};Ne.set(f,{...P,modes:B})}else if(h){const B=h.find(P=>P.category!=="model");if(B){const P=O(B.options.map(L=>L.value));T(P),B.currentValue&&_(y(B.currentValue));const A=Ne.get(f)||{models:[],modes:[]};Ne.set(f,{...A,modes:P})}}},[h,l,f]),o.useEffect(()=>{m(!1),N(!1),k(y(c)),_(y(i));const B=Ne.get(f);B?(p(B.models),T(B.modes)):(p([]),T([]))},[t,r,s]),o.useEffect(()=>{c&&Date.now()>$.current&&k(y(c))},[c]),o.useEffect(()=>{i&&Date.now()>$.current&&_(y(i))},[i]);const C=o.useCallback(async(B,P={})=>{const A={...P,...s&&{targetSessionId:s}};return await x(t,B,A)},[t,s,x]),V=async()=>{var B,P;if(g.length>0){m(!u);return}if(d){m(!0);return}D(!0);try{const A=await C("list_extension_models",{agentType:r,ideType:n}),L=(A==null?void 0:A.models)||((B=A==null?void 0:A.result)==null?void 0:B.models)||[],W=O(L);p(W),A!=null&&A.current&&k(y(A.current)),(P=A==null?void 0:A.result)!=null&&P.current&&k(y(A.result.current));const U=Ne.get(f)||{models:[],modes:[]};Ne.set(f,{...U,models:W}),m(!0)}catch{}finally{D(!1)}},Z=async()=>{var B,P;if(w.length>0){N(!v);return}if(d){N(!0);return}E(!0);try{const A=await C("list_extension_modes",{agentType:r,ideType:n}),L=(A==null?void 0:A.modes)||((B=A==null?void 0:A.result)==null?void 0:B.modes)||[],W=O(L);T(W),A!=null&&A.current&&_(y(A.current)),(P=A==null?void 0:A.result)!=null&&P.current&&_(y(A.result.current));const U=Ne.get(f)||{models:[],modes:[]};Ne.set(f,{...U,modes:W}),N(!0)}catch{}finally{E(!1)}},J=async B=>{m(!1),k(B),$.current=Date.now()+5e3;try{d?await C("change_model",{agentType:r,ideType:n,model:B}):await C("set_extension_model",{agentType:r,ideType:n,model:B})}catch{}},G=d&&!(l&&l.length>0)&&(h==null?void 0:h.some(B=>B.category!=="model")),Q=G?(ce=h==null?void 0:h.find(B=>B.category!=="model"))==null?void 0:ce.configId:void 0,Y=async B=>{N(!1),_(B),$.current=Date.now()+5e3;try{d&&G&&Q?await C("set_thought_level",{agentType:r,ideType:n,configId:Q,value:B}):d?await C("set_mode",{agentType:r,ideType:n,mode:B}):await C("set_extension_mode",{agentType:r,ideType:n,mode:B})}catch{}},ee={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[r]||"#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 opacity-70",style:{color:ee},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:u?`${ee}55`:"transparent",border:"1px solid",color:S?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),R?"...":S||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),u&&g.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>m(!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"}),g.map(B=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:B===S?`${ee}18`:"transparent",color:B===S?ee:"var(--text-secondary)",fontWeight:B===S?600:400,borderLeft:B===S?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:P=>{P.currentTarget.style.background=`${ee}12`},onMouseLeave:P=>{P.currentTarget.style.background=B===S?`${ee}18`:"transparent"},onClick:()=>J(B),children:B},B))]})]})]}),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?`${ee}55`:"transparent",border:"1px solid",color:j?"var(--text-primary)":"var(--text-muted)"},onClick:Z,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),M?"...":j||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),v&&w.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>N(!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:G?"SELECT THINKING LEVEL":"SELECT MODE"}),w.map(B=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:B===j?`${ee}18`:"transparent",color:B===j?ee:"var(--text-secondary)",fontWeight:B===j?600:400,borderLeft:B===j?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:P=>{P.currentTarget.style.background=`${ee}12`},onMouseLeave:P=>{P.currentTarget.style.background=B===j?`${ee}18`:"transparent"},onClick:()=>Y(B),children:B},B))]})]})]})]})}const br=o.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:a}){const c=o.useRef(null),[i,h]=o.useState("");o.useEffect(()=>{h("")},[s]);const l=()=>{const x=i.trim();!x||r||(h(""),a(x))};return e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${n}...`,value:i,onChange:x=>h(x.target.value),onPaste:x=>{const d=x.clipboardData.getData("text");d&&h(f=>f+d),x.preventDefault()},onKeyDown:x=>{if(x.key==="Enter"){if(x.nativeEvent.isComposing){x.preventDefault();return}x.preventDefault(),l()}},onBlur:x=>{if(window.innerWidth<768){const d=x.relatedTarget;if((d==null?void 0:d.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:l,disabled:!i.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${i.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:i.trim()&&!r?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:i.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})}),je=t=>t.transport==="pty",fe=t=>t.transport==="acp";var yr=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function jr(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function ve(t,s){if(jr(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":yr.has(n)?"generating":n==="error"?"error":n==="stopped"?"stopped":n==="starting"?"starting":n==="panel_hidden"?"panel_hidden":n==="not_monitored"?"not_monitored":n==="disconnected"?"disconnected":"idle"}function zs(t){return ve(t)==="generating"}function me(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function vr(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const a=Math.floor(n/24),c=n%24;return`${a}d ${c}h`}function rs(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Wt(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const a=r.replace(/[\\/]+$/,""),c=a.split(/[\\/]/).filter(Boolean);return c[c.length-1]||a}function wr(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function kr(t){return wr(t.trim().replace(/\.local$/i,""))}function Nr(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Fs(t,s={}){var a,c;const n=[t.hostname,(a=t.machine)==null?void 0:a.hostname,(c=t.system)==null?void 0:c.hostname].find(i=>typeof i=="string"&&i.trim().length>0);if(n&&n!=="Unknown")return kr(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Xe(t,s={}){return Nr(t)||Fs(t,s)}function as(t){return t.transport==="pty"}function os(t){return t.transport==="acp"}function is(t,s){return me(t)}function Sr(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const a=(s||"").trim().toLowerCase(),c=(n||"").trim().toLowerCase(),i=me(n||"").trim().toLowerCase();return r===a||r===c||r===i}function Cr(t){return ve(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Ir(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const a=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(a),i=ve(r.status);if(!c){s.set(a,{...r,status:i});continue}const h=n.indexOf(c.status||"idle"),l=n.indexOf(i||"idle");l>=0&&(h<0||l<h)&&s.set(a,{...r,status:i})}return Array.from(s.values())}const Mr=60,Tr=60;function Hs({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:a,isFocusingAgent:c,actionLogs:i,userName:h}){const l=o.useRef(new Map),{sendCommand:x}=$e();lt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:i.length,isSendingChat:r});const d=o.useRef(new Map),f=o.useCallback(M=>(d.current.has(M)||d.current.set(M,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:Mr}),d.current.get(M)),[]),b=o.useCallback((M,E)=>{const $=f(M);d.current.set(M,{...$,...E}),u(O=>O+1)},[f]),[,u]=o.useState(0),m=t.tabKey,v=f(m),N=v.messages,g=v.hasMore,p=v.error,w=Math.max(0,t.messages.length-v.visibleLiveCount),[T,y]=o.useState(!1),S=o.useCallback(async()=>{var $,O;if(T)return;const M=t.tabKey,E=f(M);if(t.messages.length>E.visibleLiveCount){b(M,{visibleLiveCount:Math.min(t.messages.length,E.visibleLiveCount+Tr),error:null});return}y(!0),b(M,{error:null});try{const C=(s==null?void 0:s.daemonId)||(($=t.ideId)==null?void 0:$.split(":")[0])||"";if(!C){b(M,{hasMore:!1});return}const V=t.ideType||t.agentType||"",Z=await x(C,"chat_history",{agentType:V,offset:E.offset,limit:30,targetSessionId:t.sessionId}),J=(Z==null?void 0:Z.result)??Z;if(((O=J.messages)==null?void 0:O.length)>0){const G=f(M);b(M,{messages:[...J.messages,...G.messages],offset:G.offset+J.messages.length,hasMore:!!J.hasMore})}else b(M,{hasMore:!!J.hasMore})}catch(C){const V=(C==null?void 0:C.message)||"";V.includes("P2P not available")||V.includes("channel not open")||V.includes("P2P not connected")||V.includes("timeout")?b(M,{error:"Connection not ready — tap to retry"}):b(M,{hasMore:!1,error:"Failed to load history"})}finally{y(!1)}},[T,s,t,x,f,b]),{allMessages:k,receivedAtMap:j}=o.useMemo(()=>{const M=w>0?t.messages.slice(-v.visibleLiveCount):t.messages;if(N.length===0){const V={};return M.forEach((Z,J)=>{const G=`${t.tabKey}:${Ve(Z,J)}`;let Q=Z.receivedAt||l.current.get(G)||0;Q||(Q=Date.now(),l.current.set(G,Q)),V[Ve(Z,J)]=Q}),{allMessages:M,receivedAtMap:V}}const E=new Set(M.map(V=>`${V.role}:${(V.content||"").slice(0,100)}`)),O=[...N.filter(V=>!E.has(`${V.role}:${(V.content||"").slice(0,100)}`)),...M],C={};return O.forEach((V,Z)=>{const J=`${t.tabKey}:${Ve(V,Z)}`;let G=V.receivedAt||l.current.get(J)||0;G||(G=Date.now(),l.current.set(J,G)),C[Ve(V,Z)]=G}),{allMessages:O,receivedAtMap:C}},[t.messages,t.tabKey,w,N,v.visibleLiveCount]),_=o.useMemo(()=>i.filter(M=>M.ideId===t.tabKey).sort((M,E)=>M.timestamp-E.timestamp),[i,t.tabKey]),R=t.displayPrimary||t.agentName||"Agent",D=o.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if(t.status==="not_monitored")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(Ge,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:a,disabled:c,className:"btn btn-primary",children:c?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dt,{size:14})," Open ",R," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx($s,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:a,disabled:c,className:"btn btn-primary",children:c?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dt,{size:14})," Open ",R," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]});if(t.status==="idle"&&!T)return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]})}},[t.messages.length,t.connectionState,t.status,a,c,T,R]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(lr,{messages:k,actionLogs:_,agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:je(t)||fe(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:j,onLoadMore:S,isLoadingMore:T,hasMoreHistory:g,hiddenLiveCount:w,loadError:p??void 0,emptyState:D}),!je(t)&&(()=>{const M=t.streamSource!=="agent-stream",E=M?t.ideType:t.agentType,$=M?s!=null&&s.type?me(s.type):me(t.ideType||""):t.agentName||me(t.agentType||"");return e.jsx(gr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:E,displayLabel:$,serverModel:(s==null?void 0:s.currentModel)||void 0,serverMode:(s==null?void 0:s.currentPlan)||void 0,acpConfigOptions:fe(t)?s==null?void 0:s.acpConfigOptions:void 0,acpModes:fe(t)?s==null?void 0:s.acpModes:void 0})})(),e.jsx(br,{contextKey:t.tabKey,panelLabel:R,isSending:r,onSend:n})]})}let Us=it;function Tt(){return Us()}class Er{constructor(){xe(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(a=>a(...n))}}let Vs=new Er;class Ar{constructor(){xe(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,a){return!1}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n,r){this.ptyCallbacks.forEach(a=>a(s,n,r))}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let he=new Ar;function Rr(t){t.dashboardWS&&(Vs=t.dashboardWS),t.connectionManager&&(he=t.connectionManager),t.useDaemonsHook&&(Us=t.useDaemonsHook)}function Lr({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:a=!1}){var T;const c=o.useRef(null),{sendCommand:i,sendData:h}=$e(),[l,x]=o.useState(""),[d,f]=o.useState(!1),b=o.useRef(0),u=o.useRef(!1),m=t.tabKey,v=t.sessionId||"",N=t.daemonId||((T=t.ideId)==null?void 0:T.split(":")[0])||t.ideId||"",g=()=>{var y;b.current=0,u.current=!1,f(!1),(y=n.current)==null||y.clear()},p=()=>{var y;b.current=0,u.current=!1,f(!0),(y=n.current)==null||y.clear()},w=(y,S=0)=>{var k,j;u.current||b.current>=S&&b.current!==0||(b.current=S,f(!0),(k=n.current)==null||k.clear(),y&&((j=n.current)==null||j.write(y)))};return o.useEffect(()=>{g()},[v]),o.useEffect(()=>{var S,k;if(!v)return;const y=((S=he.onRuntimeEvent)==null?void 0:S.call(he,v,j=>{var _;if(!(!j||j.sessionId!==v)){if(j.type==="runtime_snapshot"){w(j.text||"",j.seq||0);return}if(j.type==="session_output"){u.current=!0,typeof j.seq=="number"&&(b.current=Math.max(b.current,j.seq)),f(!0),typeof j.data=="string"&&((_=n.current)==null||_.write(j.data));return}j.type==="session_cleared"&&p()}}))||(()=>{});return(k=he.requestRuntimeSnapshot)==null||k.call(he,N,v).catch(()=>{}),()=>{y()}},[N,v,n]),o.useEffect(()=>{var S,k,j;if(!v)return;N&&((S=he.getState)==null?void 0:S.call(he,N))==="connected"&&(f(!0),(k=he.requestRuntimeSnapshot)==null||k.call(he,N,v).catch(()=>{}));const y=(j=he.onStateChange)==null?void 0:j.call(he,(_,R)=>{var D;_!==N||R!=="connected"||(f(!0),(D=he.requestRuntimeSnapshot)==null||D.call(he,N,v).catch(()=>{}))});return()=>{y==null||y()}},[N,v,n]),o.useEffect(()=>{s&&g()},[s,m,n]),o.useEffect(()=>{x("")},[t.tabKey]),o.useEffect(()=>{const y=S=>{var j;const k=S.detail;k!=null&&k.sessionId&&k.sessionId!==v||d&&((j=n.current)==null||j.fit())};return window.addEventListener("adhdev:fit-cli-terminal",y),()=>{window.removeEventListener("adhdev:fit-cli-terminal",y)}},[d,v,n]),o.useEffect(()=>{if(!d)return;const y=requestAnimationFrame(()=>{var S;(S=n.current)==null||S.fit()});return()=>cancelAnimationFrame(y)},[d,v,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(Os,{ref:n,readOnly:!d,onInput:y=>{d&&(h!=null&&h(N,{type:"pty_input",targetSessionId:v,data:y})||i(N,"pty_input",{targetSessionId:v,data:y}).catch(console.error))},onResize:(y,S)=>{d&&(h!=null&&h(N,{type:"pty_resize",targetSessionId:v,cols:y,rows:S})||i(N,"pty_resize",{targetSessionId:v,cols:y,rows:S,force:!0}).catch(()=>{}))}},t.tabKey),!d&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:l,onChange:y=>x(y.target.value),onPaste:y=>{const S=y.clipboardData.getData("text");S&&x(k=>k+S),y.preventDefault()},onKeyDown:y=>{if(y.key!=="Enter")return;if(y.nativeEvent.isComposing){y.preventDefault();return}y.preventDefault();const S=l.trim();!d||!S||a||(x(""),r(S))},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:()=>{const y=l.trim();!d||!y||a||(x(""),r(y))},disabled:!d||!l.trim()||a,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!a?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.trim()&&!a?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:l.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function _r({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",a=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))"},i={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)"},h={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:c[a],borderBottom:i[a],color:h[a]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}function $r({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:a,onStopCli:c,onFitCli:i}){const h=ct(),l=Tt(),x=l.p2pStates||{},d=l.ides||[],f=!!t&&je(t)&&!fe(t),b=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",u=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",m=d.filter(T=>T.type==="adhdev-daemon"),v=Object.values(x),N=v.filter(T=>T==="connected").length,g=v.filter(T=>T==="connecting"||T==="new"||T==="checking").length,w=n!=="connected"||m.length===0?null:g>0&&N===0?"P2P connecting...":N>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(Ye,{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:b,boxShadow:u}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:b,boxShadow:u}}),w&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",w]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[f&&c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Fit terminal to current view",children:"Fit"}),e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:"Stop"})]}),t&&!f&&!fe(t)&&e.jsxs("button",{onClick:()=>h(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Vt,{size:14})," IDE"]}),t&&!f&&!fe(t)&&e.jsx("button",{onClick:a,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Ls,{size:16})}),t&&!f&&!fe(t)&&e.jsx("button",{onClick:()=>h(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(_e,{size:16})})]})]})}function qs({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:a,onNewChat:c,onSwitchSession:i,onRefreshHistory:h}){var f;const l=s.find(b=>b.id===t.ideId),x=(l==null?void 0:l.chats)||[],d=(f=l==null?void 0:l.activeChat)==null?void 0:f.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:a,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," — ",me(t.ideType)]})]}),e.jsx("button",{onClick:a,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:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x.map(b=>e.jsxs("div",{onClick:()=>{i(t.ideId,b.id),a()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===b.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${d===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[b.id.substring(0,12),"..."]}),d===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),x.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(Qn,{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:h,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_s,{size:13})," Refresh History"]})})})]})]})}const cs={success:"rgba(16, 185, 129, 0.95)",warning:"color-mix(in srgb, var(--status-warning) 95%, transparent)",info:"rgba(99, 102, 241, 0.95)"};function Ys({toasts:t,onDismiss:s,onClickToast:n}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(r=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px] relative group",style:{background:cs[r.type]||cs.info},onClick:()=>{var a;(a=r.actions)!=null&&a.length||(n&&n(r),s(r.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:a=>{a.stopPropagation(),s(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((a,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${a.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":a.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:i=>{i.stopPropagation(),a.onClick(),s(r.id)},children:a.label},c))})]},r.id))})}const Pr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Dr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Br(t){return t.sessionId||t.instanceId||t.agentType}function xt(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
41
+ `).replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}function ls(t,s){const n=new Set,r=[];for(const a of s)if(a)for(const c of t[a]||[]){const i=c._localId||`${c.role}:${c.timestamp}:${c.content}`;n.has(i)||(n.add(i),r.push(c))}return r.sort((a,c)=>a.timestamp-c.timestamp)}function Gs(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=Xe(r,{fallbackId:r.id}))}return s}function Xs(t,s,n={}){var b,u,m,v,N,g;const r=[],a=n.machineName,c=n.connectionState,i=Dr(t),h=me(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(p=>{var w,T;return{sessionId:p.id,instanceId:p.id,agentType:p.providerType,agentName:p.providerName,status:p.status,title:p.title,messages:((w=p.activeChat)==null?void 0:w.messages)||[],activeModal:((T=p.activeChat)==null?void 0:T.activeModal)||void 0}}):[],x=Pr(t),d=t.activeChat||{title:""},f=d.title&&String(d.title).trim()?String(d.title).trim():"";if(x){const p=t.sessionId||t.instanceId,w=is(t.type),T=(b=t.activeChat)==null?void 0:b.activeModal,y=T&&Array.isArray(T.buttons)&&T.buttons.length>0,S=ve((u=t.activeChat)==null?void 0:u.status,{activeModal:(m=t.activeChat)==null?void 0:m.activeModal})||ve((N=(v=t.agents)==null?void 0:v[0])==null?void 0:N.status)||"idle",k=t.activeChat||{title:"",messages:[]};let j=k.title&&String(k.title).trim()?String(k.title).trim():"";const _=(g=t.activeChat)==null?void 0:g.id,R=t.chats;if(_&&Array.isArray(R)&&R.length>0){const O=R.find(C=>C.id===_||C.id&&String(C.id)===String(_));O!=null&&O.title&&String(O.title).trim()&&(j=String(O.title).trim())}const D=k.messages||[],M=ls(s,[t.id,p]),E=new Map;D.filter(O=>O.role==="user").forEach(O=>{const C=xt(O.content);C&&E.set(C,(E.get(C)||0)+1)});const $=M.filter(O=>{const C=xt(O.content),V=E.get(C)||0;return V>0?(E.set(C,V-1),!1):!0});r.push({ideId:t.id,sessionId:p,transport:t.transport,daemonId:t.daemonId||void 0,mode:je(t)?t.mode||"terminal":"chat",agentName:w,agentType:(je(t)||fe(t))&&(t.cliType||t.acpType)||t.type,status:S,title:j,messages:[...D,...$],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:i,displayPrimary:j||i||(je(t)||fe(t)?"Terminal":w),displaySecondary:h,cdpConnected:t.cdpConnected,modalButtons:y?T.buttons:void 0,modalMessage:y?T.message:void 0,streamSource:"native",tabKey:t.id,machineName:a,connectionState:c})}if(x&&(je(t)||fe(t)))return r;for(const p of l){const w=p.activeModal&&Array.isArray(p.activeModal.buttons)&&p.activeModal.buttons.length>0,T=Cr(p),y=Br(p),S=`${t.id}:${y}`,k=p.title&&String(p.title).trim()||"",j=Sr(k,p.agentName,p.agentType)?"":k,_=p.messages||[],R=ls(s,[S,p.sessionId,p.instanceId]),D=new Map;_.filter(E=>E.role==="user").forEach(E=>{const $=xt(E.content);$&&D.set($,(D.get($)||0)+1)});const M=R.filter(E=>{const $=xt(E.content),O=D.get($)||0;return O>0?(D.set($,O-1),!1):!0});r.push({ideId:t.id,sessionId:p.sessionId||p.instanceId,transport:p.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:p.agentName,agentType:p.agentType,status:T,title:j,messages:[..._,...M],ideType:p.agentType,workspaceName:i,displayPrimary:j||f||i||h,displaySecondary:`${h}·${p.agentName}`,cdpConnected:t.cdpConnected,modalButtons:w?p.activeModal.buttons:void 0,modalMessage:w?p.activeModal.message:void 0,streamSource:"agent-stream",tabKey:S,machineName:a,connectionState:c})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:is(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:i,displayPrimary:i||h,displaySecondary:h,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:t.id,connectionState:c}),r}function Wr(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const a=n.get(r.parentId)||[];a.push(r),n.set(r.parentId,a)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Or(t,s){const n=[],{daemonId:r,existingDaemon:a,timestamp:c}=s,i=c||t.timestamp||Date.now(),h=t.sessions||[],{topLevel:l,childrenByParent:x}=Wr(h),d=l.filter(u=>u.kind==="workspace"&&u.transport==="cdp-page"),f=l.filter(u=>u.kind==="agent"&&u.transport==="pty"),b=l.filter(u=>u.kind==="agent"&&u.transport==="acp");n.push({...a||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:i,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:d.some(u=>!!u.cdpConnected)});for(const u of d){const m=x.get(u.id)||[];n.push({id:`${r}:ide:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,status:u.cdpConnected?"online":"detected",daemonId:r,instanceId:u.id,workspace:u.workspace,terminals:0,childSessions:m,agents:m.map(v=>({id:v.id,name:v.providerName,type:v.providerType,status:v.status})),activeChat:u.activeChat,chats:[],cdpConnected:u.cdpConnected,currentModel:u.currentModel,currentPlan:u.currentPlan,currentAutoApprove:u.currentAutoApprove,timestamp:i})}for(const u of f){const m=u.runtime;n.push({id:`${r}:cli:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:"terminal",workspace:u.workspace||"",activeChat:u.activeChat,resume:u.resume,runtimeKey:u.runtimeKey??(m==null?void 0:m.runtimeKey),runtimeDisplayName:u.runtimeDisplayName??(m==null?void 0:m.displayName),runtimeWorkspaceLabel:u.runtimeWorkspaceLabel??(m==null?void 0:m.workspaceLabel),runtimeWriteOwner:u.runtimeWriteOwner??(m==null?void 0:m.writeOwner)??null,runtimeAttachedClients:u.runtimeAttachedClients??(m==null?void 0:m.attachedClients)??[],timestamp:i,_isCli:!0})}for(const u of b){const m=u.runtime;n.push({id:`${r}:acp:${u.id}`,sessionId:u.id,parentSessionId:u.parentId,sessionKind:u.kind,transport:u.transport,sessionCapabilities:u.capabilities,type:u.providerType,ideType:u.providerType,agentType:u.providerType,status:u.status||"running",daemonId:r,instanceId:u.id,cliName:u.providerName,mode:"chat",workspace:u.workspace||"",activeChat:u.activeChat,runtimeKey:u.runtimeKey??(m==null?void 0:m.runtimeKey),runtimeDisplayName:u.runtimeDisplayName??(m==null?void 0:m.displayName),runtimeWorkspaceLabel:u.runtimeWorkspaceLabel??(m==null?void 0:m.workspaceLabel),runtimeWriteOwner:u.runtimeWriteOwner??(m==null?void 0:m.writeOwner)??null,runtimeAttachedClients:u.runtimeAttachedClients??(m==null?void 0:m.attachedClients)??[],currentModel:u.currentModel,currentPlan:u.currentPlan,acpConfigOptions:u.acpConfigOptions,acpModes:u.acpModes,timestamp:i,_isAcp:!0})}return n}function Js(t){const s=t.split(":");return s.length>=3&&(s[1]==="ide"||s[1]==="cli"||s[1]==="acp")?{daemonId:s[0],targetSessionId:s.slice(2).join(":")||void 0}:{daemonId:t}}function Kr(t,s){const n=Js(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Zs=[{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:"💚"}],Qs=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose CLI",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],en=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],tn="adhdev_notification_prefs",ds={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function zr(){try{const t=localStorage.getItem(tn);if(t){const s=JSON.parse(t);return{...ds,...s}}}catch{}return{...ds}}function Fr(t){try{localStorage.setItem(tn,JSON.stringify(t))}catch{}}let Me=zr(),yt=[];function Hr(){yt.forEach(t=>t())}function Ur(){return{...Me}}function Vr(t){Me={...Me,...t},Fr(Me),Hr()}function qr(){const[,t]=o.useState(0);o.useEffect(()=>{const n=()=>t(r=>r+1);return yt.push(n),()=>{yt=yt.filter(r=>r!==n)}},[]);const s=o.useCallback(n=>{Vr(n)},[]);return[{...Me},s]}function rt(t){if(!Me.globalEnabled)return!1;switch(t){case"disconnect":return Me.disconnectAlert;case"completion":return Me.completionAlert;case"approval":return Me.approvalAlert;case"browser":return Me.browserNotifications;default:return!0}}const Yr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Gr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function sn(){return"Notification"in window&&Notification.permission==="granted"}let Be=null;async function Xr(){if(Be!==null)return Be;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Be=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Be=!!await t.pushManager.getSubscription(),Be):(Be=!1,!1)}catch{return Be=!1,!1}}function Ot(t,s,n){if(sn())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:n||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function Jr(t,s={}){const n={...Yr,...s},r=o.useRef(new Map),a=o.useRef(0),c=o.useRef(null);o.useEffect(()=>{Xr().then(h=>{c.current=h})},[]);const i=o.useCallback((h,l,x)=>{const d=Date.now();d-a.current<n.throttleMs||(a.current=d,Ot(h,l,x))},[n.throttleMs]);o.useEffect(()=>{var h;if(!(!n.enabled||!sn())&&rt("browser")&&c.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,ve(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),d=ve(l.status,{activeModal:l.activeModal}),f=l.name||l.id;if(n.onApproval&&rt("approval")&&d==="waiting_approval"&&x!=="waiting_approval"){const b=((h=l.activeModal)==null?void 0:h.message)||"Action requires your approval";i(`🔔 ${f} — Approval needed`,b.slice(0,120),`approval-${l.id}`)}n.onComplete&&rt("completion")&&zs(x)&&d==="idle"&&i(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&x!=="error"&&i(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,d)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,i])}class Zr{constructor(){xe(this,"dedupMap",new Map);xe(this,"DEDUP_WINDOW_MS",5e3);xe(this,"DEDUP_MAX_SIZE",50);xe(this,"DEDUP_CLEANUP_AGE_MS",1e4);xe(this,"toastCallbacks",[]);xe(this,"systemMessageCallbacks",[]);xe(this,"clearSystemMessageCallbacks",[]);xe(this,"resolveActionFn",null);xe(this,"viewRequestRespondFn",null);xe(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const a=(r==null?void 0:r.id)||Date.now();this.emitToast({id:a,message:s,type:n,timestamp:a,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[a,c]of this.dedupMap)n-c>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(a);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const a=this.ides.find(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(a)return a}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(a=>a.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(a=>a.id.endsWith(`:ide:${s.instanceId}`)||a.id.endsWith(`:cli:${s.instanceId}`))),n){const a=n.daemonId;if(a){const c=this.ides.find(i=>i.id===a&&i.type==="adhdev-daemon");if(c)return c}}const r=this.ides.filter(a=>a.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.childSessions)?n.childSessions:[]).some(a=>(a==null?void 0:a.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var d,f;if(!s.ideId&&s.instanceId){for(const b of this.ides)if(b.id.endsWith(`:ide:${s.instanceId}`)||b.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=b.id;break}}const r=this.resolveConversationKey(s),c=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(c))return;let i=me(s.ideType||"");const h=this.resolveOwningDaemon(s);if(h){const b=Xe(h,{fallbackId:h.id});b&&(i=s.ideType==="adhdev-daemon"?b:`${b}/${i}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const b=s.duration?` (${s.duration}s)`:"";l=`✅ ${i} agent task completed${b}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Ur().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${b}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${i} approval needed`,x="warning",r){const b=s.modalMessage||"Approval requested",u=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(m=>`[${m}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${b}
42
+ ${u}`,_localId:`sys_approval_${Date.now()}`})}if((f=s.modalButtons)!=null&&f.length&&this.resolveActionFn){const b=this.resolveActionRouteTarget(s);if(!b)return;const u=s.agentType||s.ideType||"",m=s.ideType||"",v=s.modalButtons,N=y=>y.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),g=this.resolveActionFn,p=v.map((y,S)=>{const k=N(y).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(k),_=/^(reject|deny|delete|remove|abort|cancel|no)/.test(k);return{label:N(y),variant:j?"primary":_?"danger":"default",onClick:()=>{const R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(k);g(b,"resolve_action",{action:R?"approve":"reject",button:y,buttonIndex:S,agentType:u,ideType:m,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),w=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:w,type:x,timestamp:T,targetKey:r||b,actions:p,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const b=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${i} agent is taking a long time${b}`,x="warning",rt("browser")&&!document.hasFocus()&&Ot(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${b.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const b=s.requesterName||"A team member",u=s.requestId,m=s.orgId;if(l=`👁️ ${b} wants to view your session`,x="warning",u&&m&&this.viewRequestRespondFn){const v=this.viewRequestRespondFn,N=Date.now(),g=[{label:"Approve",variant:"primary",onClick:()=>{v(m,u,"approve").catch(p=>console.error("[EventManager] approve view request failed:",p))}},{label:"Decline",variant:"danger",onClick:()=>{v(m,u,"reject").catch(p=>console.error("[EventManager] reject view request failed:",p))}}];this.emitToast({id:N,message:l,type:x,timestamp:N,actions:g,duration:3e4}),l=""}rt("browser")&&!document.hasFocus()&&Ot("👁️ View Request",`${b} wants to view your session`,`view-request-${u}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(l){const b=Date.now();this.emitToast({id:b,message:l,type:x,timestamp:b,targetKey:r||s.ideId,duration:5e3})}}}const Pe=new Zr;function Fe(...t){return Cn(In(t))}function Qr({icon:t,title:s,subtitle:n,badge:r,actions:a,className:c}){return e.jsxs("div",{className:Fe("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,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),a&&e.jsx("div",{className:"flex gap-2",children:a})]})}function St({icon:t,title:s,subtitle:n,badge:r,actions:a,widthClassName:c="max-w-6xl",contentClassName:i,children:h}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Qr,{icon:t,title:s,subtitle:n,badge:r,actions:a}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Fe("mx-auto flex w-full flex-col gap-4",c,i),children:h})})]})}function be({title:t,icon:s,description:n,accentColor:r,className:a,children:c}){return e.jsxs("div",{className:Fe("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",a),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),c]})}function qt({icon:t,title:s,description:n,action:r,className:a}){return e.jsxs("div",{className:Fe("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const ea={error:"bg-red-500/10 border-red-500/30 text-red-400",warning:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400",success:"bg-green-500/10 border-green-500/30 text-green-400",info:"bg-indigo-500/10 border-indigo-500/30 text-indigo-400"},ta={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function sa({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:Fe("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",ea[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:ta[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const na={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"},ra={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function aa({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:Fe("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",na[t],n),children:[e.jsx("span",{className:Fe("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",ra[t])}),r]})}function oa(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Kt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function jt(t){return t==="system"?oa():t}function ia(){typeof document>"u"||document.documentElement.setAttribute("data-theme",jt(Kt()))}function ca(){const[t,s]=o.useState(Kt),[n,r]=o.useState(()=>jt(Kt()));o.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),o.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),h=l=>{t==="system"&&r(l.matches?"light":"dark")};return i.addEventListener("change",h),()=>i.removeEventListener("change",h)},[t]);const a=o.useCallback(i=>{s(i),r(jt(i));try{localStorage.setItem("theme",i)}catch{}},[]),c=o.useCallback(()=>{s(i=>{const h=i==="dark"?"light":i==="light"?"system":"dark";r(jt(h));try{localStorage.setItem("theme",h)}catch{}return h})},[]);return{theme:n,preference:t,setPreference:a,cycleTheme:c,isDark:n==="dark"}}function Oe({label:t,description:s,checked:n,disabled:r,onChange:a,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:n,disabled:r,onChange:i=>a(i.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function la({onPrefChange:t}){const[s,n]=qr(),r=(a,c)=>{n({[a]:c}),t==null||t(a,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ws,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:a=>r("globalEnabled",a)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:a=>r("browserNotifications",a)}),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(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(er,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:a=>r("completionAlert",a)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(tr,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:a=>r("approvalAlert",a)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:a=>r("disconnectAlert",a)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:a=>r("chatTaskCompletionBubble",a)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function da({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){const c=t.filter(i=>i.type==="adhdev-daemon");return c.length===0?e.jsx(qt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(i=>e.jsx(ha,{ide:i,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a},i.id))})}function us({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:a,onCancel:c}){const i=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return Mn.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:h=>h.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:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,style:r==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:n})]})]})}),document.body)}function ua(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Zs,...Qs,...en].find(a=>a.id===s||s.includes(a.id)||a.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function ha({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){var $,O;const[c,i]=o.useState("idle"),[h,l]=o.useState(""),[x,d]=o.useState(null),[f,b]=o.useState("idle"),[u,m]=o.useState(""),v=t,N=v.version||v.daemonVersion||null,g=(($=v.machine)==null?void 0:$.platform)||((O=v.system)==null?void 0:O.platform)||"",p=Xe(v,{fallbackId:t.id}),w=g==="win32"?"🪟":g==="darwin"?"🍎":"🐧",T=s.filter(C=>C.daemonId===t.id&&C.transport==="cdp-page"),y=s.filter(C=>C.daemonId===t.id&&C.transport==="pty"),S=s.filter(C=>C.daemonId===t.id&&C.transport==="acp"),k=v.p2p,j=async()=>{var C,V,Z;if(n){i("upgrading"),l("Installing latest version...");try{const J=await n(t.id,"daemon_upgrade",{});(C=J==null?void 0:J.result)!=null&&C.upgraded||(V=J==null?void 0:J.result)!=null&&V.success?(i("done"),l(`Upgraded to v${J.result.version||"latest"}. Daemon is restarting...`)):(i("error"),l(((Z=J==null?void 0:J.result)==null?void 0:Z.error)||"Upgrade failed"))}catch(J){i("error"),l((J==null?void 0:J.message)||"Connection lost during upgrade")}}},_=async()=>{if(d(null),!!r){b("loading");try{await r(t.id),b("done"),m("Machine disconnected.")}catch(C){b("error"),m((C==null?void 0:C.message)||"Failed to disconnect")}}},R=async()=>{if(d(null),!!a){b("loading");try{await a(t.id),b("done"),m('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(C){b("error"),m((C==null?void 0:C.message)||"Failed to revoke token")}}},D="0.7.33",M=!N||N!==D,E=T.length+y.length+S.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:w}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:p}),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),"…"]}),N&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${M?"":"bg-bg-secondary"}`,style:M?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",N,!M&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&M&&e.jsx("button",{onClick:j,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${D}`,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${D}`}`}),r&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:f==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&e.jsx("button",{onClick:()=>d("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(aa,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[k&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${k.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${k.state==="connecting"||k.state==="new"?"animate-pulse":""}`,style:k.state==="connecting"||k.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",k.state==="connected"?"connected":k.state==="connecting"||k.state==="new"?"connecting...":k.state||"off"]}),k.peers!==void 0&&k.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",k.peers," peer",k.peers!==1?"s":"",")"]})]}),k&&E>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),E>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(C=>{const V=ua(C.type),Z=C.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:V.icon}),e.jsx("span",{children:V.name}),Z!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Z?"bg-green-400":"animate-pulse"}`,style:Z?void 0:{background:"var(--status-warning)"},title:Z?"CDP connected":"CDP connecting..."})]},C.id)}),y.map(C=>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:C.cliName||"CLI"})]},C.id)),S.map(C=>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:C.cliName||"ACP"})]},C.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(h||u)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||f==="error"?"text-red-400":c==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:u||h})]}),x==="disconnect"&&e.jsx(us,{title:"🔌 Disconnect Machine",message:`Disconnect "${p}" from ADHDev?
43
+
44
+ This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
45
+
46
+ Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:_,onCancel:()=>d(null)}),x==="revoke"&&e.jsx(us,{title:"⚠️ Remove Machine",message:`Remove "${p}" from your dashboard?
47
+
48
+ This will:
49
+ • Immediately disconnect the machine
50
+ • Delete the machine registration
51
+ • Require restarting "adhdev-standalone" on that machine
52
+
53
+ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:R,onCancel:()=>d(null)})]})}const xa=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function pa(){const{preference:t,setPreference:s}=ca();return e.jsx("div",{className:"flex gap-2",children:xa.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent text-white":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}const zt={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},Ft={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},ma=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],nn="adhdev-chat-theme",rn="adhdev-chat-theme-custom";function vt(){return typeof window>"u"?"ember":localStorage.getItem(nn)||"ember"}function Ie(t){try{const s=localStorage.getItem(rn);if(s){const n=JSON.parse(s);return{...t==="dark"?zt:Ft,...n[t]}}}catch{}return t==="dark"?zt:Ft}function pt(t,s){localStorage.setItem(rn,JSON.stringify({dark:t,light:s}))}function Se(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),a=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${a}, ${s})`}function Ct(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),a=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}const fa={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function at(t,s){var a;const n=(a=fa[t])==null?void 0:a[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",Ct(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Ct(n,18)})`),r.style.setProperty("--border-accent",Se(n,.35)),r.style.setProperty("--nav-active-bg",Se(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Se(n,.06)}`)}function Ke(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Se(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Se(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Se(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",Se(t.borderSubtle,.5)),s.style.setProperty("--border-default",Se(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Ct(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Ct(t.accentColor,40)})`),s.style.setProperty("--border-accent",Se(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Se(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Se(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 ${Se(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 Yt(){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(n=>t.style.removeProperty(n))}function ga(t){if(localStorage.setItem(nn,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Ke(Ie(s))}else Yt(),at(t,ze()?"dark":"light")}function ba(){const t=vt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Ke(Ie(s))}else Yt(),at(t,ze()?"dark":"light")}function ze(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function ge({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(r.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&n(r.target.value)},style:{width: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 et({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 ya({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,a]=o.useState(()=>Ie(n));o.useEffect(()=>{a(Ie(n))},[n]);const c=o.useCallback((i,h)=>{a(l=>{const x={...l,[i]:h},f=Ie(n==="dark"?"light":"dark");return n==="dark"?pt(x,f):pt(f,x),Ke(x),s(x),x})},[n,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(et,{title:"App Background",children:[e.jsx(ge,{label:"Background",value:r.bgPrimary,onChange:i=>c("bgPrimary",i)}),e.jsx(ge,{label:"Surface",value:r.bgSecondary,onChange:i=>c("bgSecondary",i)}),e.jsx(ge,{label:"Card",value:r.surfacePrimary,onChange:i=>c("surfacePrimary",i)})]}),e.jsxs(et,{title:"App Text",children:[e.jsx(ge,{label:"Primary",value:r.textPrimary,onChange:i=>c("textPrimary",i)}),e.jsx(ge,{label:"Secondary",value:r.textSecondary,onChange:i=>c("textSecondary",i)}),e.jsx(ge,{label:"Muted",value:r.textMuted,onChange:i=>c("textMuted",i)})]}),e.jsxs(et,{title:"Borders & Accent",children:[e.jsx(ge,{label:"Border subtle",value:r.borderSubtle,onChange:i=>c("borderSubtle",i)}),e.jsx(ge,{label:"Border default",value:r.borderDefault,onChange:i=>c("borderDefault",i)}),e.jsx(ge,{label:"Accent",value:r.accentColor,onChange:i=>c("accentColor",i)})]})]}),e.jsxs("div",{children:[e.jsxs(et,{title:"Chat Bubbles",children:[e.jsx(ge,{label:"User bubble",value:r.userBubble,onChange:i=>c("userBubble",i)}),e.jsx(ge,{label:"User text",value:r.userText,onChange:i=>c("userText",i)}),e.jsx(ge,{label:"Agent bubble",value:r.assistantBubble,onChange:i=>c("assistantBubble",i)}),e.jsx(ge,{label:"Agent text",value:r.assistantText,onChange:i=>c("assistantText",i)})]}),e.jsxs(et,{title:"Chat Layout",children:[e.jsx(ge,{label:"Chat BG",value:r.containerBg,onChange:i=>c("containerBg",i)}),e.jsx(ge,{label:"Send button",value:r.sendButton,onChange:i=>c("sendButton",i)}),e.jsx(ge,{label:"Input border",value:r.inputBorder,onChange:i=>c("inputBorder",i)}),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:r.bubbleRadius,onChange:i=>c("bubbleRadius",Number(i.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const i=t?zt:Ft,l=Ie(t?"light":"dark");t?pt(i,l):pt(l,i),a(i),Ke(i),s(i)},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 ja(){const[t,s]=o.useState(vt),[n,r]=o.useState(!0),[a,c]=o.useState(()=>Ie("dark"));o.useEffect(()=>{r(ze());const l=new MutationObserver(()=>{const f=ze();r(f);const b=vt();b==="custom"?Ke(Ie(f?"dark":"light")):at(b,f?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const f=ze();r(f);const b=vt();b==="custom"?Ke(Ie(f?"dark":"light")):at(b,f?"dark":"light")};return x.addEventListener("change",d),()=>{l.disconnect(),x.removeEventListener("change",d)}},[]),o.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Ke(Ie(n?"dark":"light")):(Yt(),at(t,n?"dark":"light"))},[t,n]),o.useEffect(()=>{c(Ie(n?"dark":"light"))},[n]);const i=l=>{s(l),ga(l)},h=[...ma,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText},light:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:h.map(l=>{const x=t===l.id,d=n?l.preview.dark:l.preview.light,f=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?a.userText:"#fff";return e.jsxs("button",{onClick:()=>i(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background: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:f},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(ya,{dark:n,onColorsChange:l=>c(l)})]})}const an="adhdev_hiddenTabs";function va(){try{const t=localStorage.getItem(an);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function tt(t){try{localStorage.setItem(an,JSON.stringify([...t]))}catch{}}function on(){const[t,s]=o.useState(va),n=o.useCallback(l=>{s(x=>{const d=new Set(x);return d.has(l)?d.delete(l):d.add(l),tt(d),d})},[]),r=o.useCallback(l=>{s(x=>{if(x.has(l))return x;const d=new Set(x);return d.add(l),tt(d),d})},[]),a=o.useCallback(l=>{s(x=>{if(!x.has(l))return x;const d=new Set(x);return d.delete(l),tt(d),d})},[]),c=o.useCallback((l,x)=>{s(d=>{const f=new Set(d);for(const b of x)f.add(b);return tt(f),f})},[]),i=o.useCallback((l,x)=>{s(d=>{const f=new Set(d);for(const b of x)f.delete(b);return tt(f),f})},[]),h=o.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:a,hideAllForDaemon:c,showAllForDaemon:i,isHidden:h}}function cn({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){o.useEffect(()=>{Gr()},[]);const a=o.useMemo(()=>t.map(c=>({id:c.tabKey,name:c.title||c.agentName||c.ideId,status:c.status,activeModal:c.modalMessage?{message:c.modalMessage,buttons:c.modalButtons}:null})),[t]);return Jr(a),o.useEffect(()=>{if(Object.keys(s).length===0)return;const i=setTimeout(()=>{n(h=>{const l=Date.now(),x={};for(const[d,f]of Object.entries(h))l-f<5e3&&(x[d]=f);return Object.keys(x).length===Object.keys(h).length?h:x})},5500);return()=>clearTimeout(i)},[s,n]),o.useEffect(()=>{const c=setInterval(()=>{const i=Date.now()-3e5;r(h=>{const l=h.filter(x=>x.timestamp>i).slice(-100);return l.length===h.length?h:l})},6e4);return()=>clearInterval(c)},[r]),null}function wa(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const a=n.get(r.id);if(!a){n.set(r.id,r);continue}const c=(a.workspace?1:0)+(a.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>c||(r.timestamp||0)>(a.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function mt(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function ka(t,s){const n=Date.now();return t.map(r=>{const a=s[r.tabKey];return a&&n-a<5e3?{...r,messages:[],title:""}:r})}function Na(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const a of t.childSessions||[]){const c=a.id||a.providerType,i=`${t.id}:${c}`;n.push({key:i,ref:s[i]}),n.push({key:a.id,ref:s[a.id]})}return n}function Sa(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n].key!==s[n].key||t[n].ref!==s[n].ref)return!1;return!0}function Ca({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:a}){const c=o.useRef([]),i=o.useRef([]),h=o.useRef([]),l=o.useRef([]),x=o.useMemo(()=>{const p=wa(t);return mt(c.current,p)?c.current:(c.current=p,p)},[t]),d=o.useMemo(()=>Gs(t),[t]),f=o.useRef(new Map),b=o.useMemo(()=>{var T;const p=new Map,w=[];for(const y of x){const S=y.daemonId||((T=y.id)==null?void 0:T.split(":")[0])||y.id,k=s[S]||"new",j=y.daemonId&&d[y.daemonId]||void 0,_=Na(y,n),R=f.current.get(y.id);if(R&&R.ide===y&&R.connectionState===k&&R.machineName===j&&Sa(R.localRefs,_)){p.set(y.id,R),w.push(...R.conversations);continue}const D=Xs(y,n,{machineName:j,connectionState:k}),M={ide:y,connectionState:k,machineName:j,localRefs:_,conversations:D};p.set(y.id,M),w.push(...D)}return f.current=p,w},[x,n,s,d]),u=o.useMemo(()=>{const p=ka(b,r);return mt(i.current,p)?i.current:(i.current=p,p)},[b,r]),m=o.useMemo(()=>{const p=new Map;for(const w of u)w.sessionId&&p.set(w.sessionId,w),p.set(w.ideId,w),p.set(w.tabKey,w),p.set(w.ideType,w),p.set(w.agentType,w);return p},[u]),v=o.useCallback(p=>{if(p)return m.get(p)},[m]),N=o.useMemo(()=>{const p=u.filter(w=>!a.has(w.tabKey));return mt(h.current,p)?h.current:(h.current=p,p)},[u,a]),g=o.useMemo(()=>{const p=N.map(w=>w.tabKey);return mt(l.current,p)?l.current:(l.current=p,p)},[N]);return{chatIdes:x,conversations:u,visibleConversations:N,visibleTabKeys:g,resolveConversationByTarget:v}}function ln({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:a}){o.useEffect(()=>{Pe.setIdes(t)},[t]),o.useEffect(()=>{Pe.setResolveAction((c,i,h)=>{s(c,i,h).catch(()=>{})})},[s]),o.useEffect(()=>{const c=Pe.onToast(l=>{n(d=>d.some(b=>b.message===l.message&&l.timestamp-b.timestamp<3e3)?d:[...d.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const x=l.duration||5e3;setTimeout(()=>n(d=>d.filter(f=>f.id!==l.id)),x)}),i=Pe.onSystemMessage((l,x)=>{r(d=>({...d,[l]:[...d[l]||[],x]}))}),h=Pe.onClearSystemMessage((l,x)=>{r(d=>{var f;return(f=d[l])!=null&&f.length?{...d,[l]:d[l].filter(b=>{var u;return!(b.role==="system"&&((u=b._localId)!=null&&u.startsWith(x)))})}:d})});return()=>{c(),i(),h()}},[n,r]),o.useEffect(()=>{const c=Vs.on("status_event",i=>Pe.handleRawEvent(i,"ws"));return()=>{c()}},[]),o.useEffect(()=>{var i;const c=h=>{const l=h.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const x=l.targetSessionId||l.targetKey||l.ideId,d=a(x),f=(d==null?void 0:d.ideId)||l.ideId;f&&s(f,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(b=>console.error("[SW Action] approve failed:",b))};return(i=navigator.serviceWorker)==null||i.addEventListener("message",c),()=>{var h;return(h=navigator.serviceWorker)==null?void 0:h.removeEventListener("message",c)}},[a,s])}const Ia="adhdev_dashboardLayout_v1",Ma="adhdev_dashboardDockview_v1",st={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"},nt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function qe(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Ta(t){try{return localStorage.getItem(t)}catch{return null}}function dn(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function un(t){return`${Ia}:${t}`}function hn(){const t=Ta(st.focusedGroup),s=qe(st.splitGroups,[]),n=qe(st.groupActiveTabs,{}),r=qe(st.groupTabOrders,{}),a=qe(st.splitSizes,[]);return t!==null||s.length>0||Object.keys(n).length>0||Object.keys(r).length>0||a.length>0?{groupAssignments:s,focusedGroup:t&&parseInt(t,10)||0,groupActiveTabIds:n,groupTabOrders:r,groupSizes:a}:null}function Ea(){return hn()}function Aa(t){const s=un(t),n=qe(s,null);return n||hn()}function Ra(t,s){try{const n=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,r=un(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function xn(t){return`${Ma}:${t}`}function La(t){const s=xn(t);return qe(s,null)}function _a(t,s){try{const n=xn(t);if(!s){localStorage.removeItem(n);return}localStorage.setItem(n,JSON.stringify(s))}catch{}}function $a(){return{groupAssignments:[...nt.groupAssignments],focusedGroup:nt.focusedGroup,groupActiveTabIds:{...nt.groupActiveTabIds},groupTabOrders:{...nt.groupTabOrders},groupSizes:[...nt.groupSizes]}}function Pa(){const[t]=o.useState(()=>dn(typeof window<"u"?window.innerWidth:1280)),[s,n]=o.useState(()=>new Map),[r,a]=o.useState(0),[c,i]=o.useState({}),[h,l]=o.useState({}),[x,d]=o.useState([]),[f,b]=o.useState(()=>typeof window<"u"&&window.innerWidth<768),[u,m]=o.useState(!1),v=o.useCallback(()=>{if(u)return;const N=Aa(t)??$a();n(new Map(N.groupAssignments)),a(N.focusedGroup),i(N.groupActiveTabIds),l(N.groupTabOrders),d(N.groupSizes),m(!0)},[u,t]);return o.useEffect(()=>{u&&Ra(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:c,groupTabOrders:h,groupSizes:x})},[u,t,s,r,c,h,x]),o.useEffect(()=>{const N=window.matchMedia("(max-width: 767px)"),g=p=>b(p.matches);return N.addEventListener("change",g),()=>N.removeEventListener("change",g)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:a,groupActiveTabIds:c,setGroupActiveTabIds:i,groupTabOrders:h,setGroupTabOrders:l,groupSizes:x,setGroupSizes:d,isMobile:f,hasHydratedStoredLayout:u,hydrateStoredLayout:v}}function Da({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:a,hydrateStoredLayout:c,setGroupActiveTabIds:i,setFocusedGroup:h,setSearchParams:l,historyModalOpen:x,activeConv:d,isRefreshingHistory:f,ides:b,handleRefreshHistory:u}){const m=o.useRef(!1),v=o.useRef(!1),N=o.useRef(null),g=o.useRef(!1);o.useEffect(()=>{if(!t||m.current||s.length===0)return;if(!a){c();return}const p=n(t);if(!p)return;const w=r.get(p.tabKey)??0;i(T=>({...T,[w]:p.tabKey})),h(w),m.current=!0,v.current=!0,N.current!=null&&(window.clearTimeout(N.current),N.current=null),l(T=>{const y=new URLSearchParams(T);return y.delete("activeTab"),y},{replace:!0})},[t,s,n,r,a,c,i,h,l]),o.useEffect(()=>{if(!(v.current||a)&&s.length!==0){if(!t){c(),v.current=!0;return}if(m.current){v.current=!0;return}if(N.current==null)return N.current=window.setTimeout(()=>{N.current=null,!(v.current||a)&&(c(),v.current=!0)},1500),()=>{N.current!=null&&(window.clearTimeout(N.current),N.current=null)}}},[t,s.length,a,c]),o.useEffect(()=>{if(!x){g.current=!1;return}if(!d||g.current||f)return;const p=b.find(w=>w.id===d.ideId);p&&(!p.chats||p.chats.length===0)&&(g.current=!0,u())},[x,d,f,b,u]),o.useEffect(()=>{if(!d)return;let p=null,w=0,T=-1,y=0;const S=()=>{p=null;const k=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(_=>_.offsetParent!==null);if(k.length===0){w<18&&(w+=1,p=requestAnimationFrame(S));return}let j=0;for(const _ of k)_.scrollTop=_.scrollHeight,j+=_.scrollHeight;j===T?y+=1:(y=0,T=j),w+=1,!(y>=2||w>=18)&&(p=requestAnimationFrame(S))};return p=requestAnimationFrame(S),()=>{p!=null&&cancelAnimationFrame(p)}},[d==null?void 0:d.tabKey])}function Le(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return je(t)||fe(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function It(t){return t&&(t.ideId||t.daemonId)||""}function ft(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function Ba({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:a,setClearedTabs:c}){const[i,h]=o.useState(!1),[l,x]=o.useState(!1),d=o.useCallback(async m=>{try{await t("standalone","launch_ide",{ideType:m,enableCdp:!0})}catch(v){console.error("Launch failed",v)}},[t]),f=o.useCallback(async(m,v)=>{try{const N=m||(s==null?void 0:s.daemonId)||"",g=await t(N,"switch_chat",{id:v,sessionId:v,...Le(s)}),p=g==null?void 0:g.result;if((g==null?void 0:g.success)===!0||p==="switched"||p==="switched-by-title")return;p===!1||p==="not_found"?ft(r,"⚠️ Session tab not found — try refreshing history"):typeof p=="string"&&p.startsWith("error:")?ft(r,`⚠️ Switch error: ${p}`):ft(r,"⚠️ Session switch failed")}catch(N){console.error("Switch failed",N),ft(r,`❌ Switch failed: ${N.message||"connection error"}`)}},[s,t,r]),b=o.useCallback(async()=>{if(!(!s||i)){h(!0);try{const m=It(s);await t(m,"new_chat",{...Le(s)}),c(v=>({...v,[s.tabKey]:Date.now()})),a(v=>({...v,[s.tabKey]:[]}))}catch(m){console.error("New chat failed",m)}finally{h(!1)}}},[s,i,t,c,a]),u=o.useCallback(async()=>{var m;if(!(!s||l)){x(!0);try{const v=It(s),N=await t(v,"list_chats",{forceExpand:!0,...Le(s)}),g=(N==null?void 0:N.chats)||((m=N==null?void 0:N.result)==null?void 0:m.chats);N!=null&&N.success&&Array.isArray(g)&&n(s.ideId,g)}catch(v){console.error("Refresh history failed",v)}finally{x(!1)}}},[s,l,t,n]);return{isCreatingChat:i,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:f,handleNewChat:b,handleRefreshHistory:u}}function Wa(t,s){if(t.size!==s.size)return!1;for(const[n,r]of t)if(s.get(n)!==r)return!1;return!0}function Oa(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function hs(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(a=>s[Number(a)]===t[Number(a)])}function gt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[i,h]of t)!n.has(i)||h<=0||r.includes(h)||r.push(h);r.sort((i,h)=>i-h);const a={};r.forEach((i,h)=>{a[i]=h}),r.length===0&&(a[0]=0);const c=new Map;for(const[i,h]of t){if(!n.has(i)||h<=0)continue;const l=a[h];typeof l=="number"&&l>0&&c.set(i,l)}return{assignments:c,groupCount:Math.max(1,r.length),mapping:a,usedGroups:r}}function xs(t,s){const n={};for(const[r,a]of Object.entries(t)){const c=s[Number(r)];typeof c=="number"&&(n[c]=a)}return n}function Ka(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(a=>a<t)??s[0];return n[r]??0}function za(t,s,n){if(s.length<=1)return[];const r=s.map(i=>t[i]).filter(i=>Number.isFinite(i)),a=r.length===s.length?r:Array(n).fill(100/n),c=a.reduce((i,h)=>i+h,0);return c>0?a.map(i=>i/c*100):Array(n).fill(100/n)}function ps(t,s){const n={};for(const[r,a]of Object.entries(t)){const c=Number(r);n[c>=s?c+1:c]=a}return n}function ms(t){return Array(t).fill(100/t)}function Fa({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:a,groupSizes:c,setGroupSizes:i,isMobile:h,visibleConversations:l,visibleTabKeys:x}){const d=o.useRef(null),f=o.useMemo(()=>gt(t,x),[t,x]),b=f.assignments,u=o.useMemo(()=>h?1:f.groupCount,[f.groupCount,h]),m=u>1,v=o.useCallback((y,S)=>{s(k=>{const j=new Map(gt(k,x).assignments);return S===0?j.delete(y):j.set(y,S),j}),r(k=>({...k,[S]:y})),n(S)},[s,x,r,n]),N=o.useCallback(y=>{s(S=>{const k=gt(S,x).assignments,j=new Map;for(const[_,R]of k)R!==y&&(R>y?j.set(_,R-1):j.set(_,R));return j}),i(S=>{if(S.length<=1)return[];const k=[...S];k.splice(y,1);const j=k.reduce((_,R)=>_+R,0);return j>0?k.map(_=>_/j*100):[]}),n(0)},[s,x,i,n]),g=o.useCallback((y,S)=>{S.preventDefault();const k=d.current;if(!k)return;const j=S.clientX,_=k.offsetWidth,R=c.length===u?[...c]:ms(u),D=E=>{const O=(E.clientX-j)/_*100,C=[...R];C[y]=Math.max(15,R[y]+O),C[y+1]=Math.max(15,R[y+1]-O),i(C)},M=()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",M),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",D),document.addEventListener("mouseup",M)},[c,u,i]),p=o.useCallback((y,S,k)=>{if(u>=4)return;const j=k==="left"?S:S+1;s(_=>{const R=gt(_,x).assignments,D=new Map;for(const M of l){const E=R.get(M.tabKey)??0,$=E>=j?E+1:E;$>0&&D.set(M.tabKey,$)}return j>0&&D.set(y,j),D}),i(_=>{const R=_.length===u?[..._]:ms(u),D=R[S]??100/u,M=Math.max(15,D/2),E=Math.max(15,D/2),$=[...R];$[S]=M,$.splice(j,0,E);const O=$.reduce((C,V)=>C+V,0);return $.map(C=>C/O*100)}),r(_=>{const R=ps(_,j);return R[j]=y,R}),a(_=>{const R=ps(_,j);return R[j]=[y],R}),n(j)},[u,s,x,l,i,r,a,n]);o.useEffect(()=>{Wa(t,b)||s(b)},[t,b,s]),o.useEffect(()=>{const{mapping:y,usedGroups:S}=f;r(k=>{const j=xs(k,y);return hs(k,j)?k:j}),a(k=>{const j=xs(k,y);return hs(k,j)?k:j}),n(k=>{const j=h?0:Ka(k,S,y);return k===j?k:j}),i(k=>{const j=h?[]:za(k,S,f.groupCount);return Oa(k,j)?k:j})},[f,h,r,a,n,i]);const w=o.useMemo(()=>{const y=Array.from({length:u},()=>[]);for(const S of l){const k=b.get(S.tabKey)??0,j=Math.min(k,u-1);y[j].push(S)}return y},[l,b,u]),T=o.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:b,numGroups:u,isSplitMode:m,groupedConvs:w,moveTabToGroup:v,closeGroup:N,handleResizeStart:g,splitTabRelative:p,clearAllSplits:T}}function Ha({ides:t,sendDaemonCommand:s}){const n="0.7.33",r=o.useMemo(()=>t.filter(x=>{if(x.type!=="adhdev-daemon")return!1;const d=x.version||x.daemonVersion||null;return!d||!n?!1:d!==n}),[n,t]),[a,c]=o.useState(!1),[i,h]=o.useState({}),l=o.useCallback(async x=>{var d,f;h(b=>({...b,[x]:"upgrading"}));try{const b=await s(x,"daemon_upgrade",{});(d=b==null?void 0:b.result)!=null&&d.upgraded||(f=b==null?void 0:b.result)!=null&&f.success?h(u=>({...u,[x]:"done"})):h(u=>({...u,[x]:"error"}))}catch{h(b=>({...b,[x]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:a,setVersionBannerDismissed:c,upgradingDaemons:i,handleBannerUpgrade:l}}const pn=o.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:a,screenshotUrl:c,clearScreenshot:i,terminalRef:h,handleModalButton:l,handleRelaunch:x,handleSendChat:d,isSendingChat:f,handleFocusAgent:b,isFocusingAgent:u,actionLogs:m,userName:v}){const N=o.useCallback(()=>{i()},[i]);return e.jsxs(e.Fragment,{children:[e.jsx(Ks,{activeConv:s,onModalButton:l}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&c?e.jsx(fr,{screenshotUrl:c,mode:"preview",onDismiss:N}):!r&&s.transport!=="acp"&&s.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(Ut,{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:x,children:"Relaunch with CDP"})]}):null}),r?e.jsx(Lr,{activeConv:s,clearToken:n,terminalRef:h,handleSendChat:d,isSendingChat:f}):e.jsx(Hs,{activeConv:s,ideEntry:a,handleSendChat:d,isSendingChat:f,handleFocusAgent:b,isFocusingAgent:u,actionLogs:m,userName:v})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName),Lt={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 Ua(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Va(){const[t,s]=o.useState("unix"),[n,r]=o.useState("powershell"),[a,c]=o.useState(!1),i=t==="unix"?"unix":n;o.useEffect(()=>{s(Ua())},[]);const h=o.useCallback(()=>{navigator.clipboard.writeText(Lt[i].cmd).catch(()=>{}),c(!0),setTimeout(()=>c(!1),2e3)},[i]);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 ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:h,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Lt[i].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Lt[i].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:a?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Gt({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:a}){return t===0&&!s&&r&&a?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(Va,{}),n&&r.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(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:()=>a(c.type),children:[e.jsx(Ds,{size:14,className:"opacity-70"})," Launch ",c.name]},c.type))})]}),!n&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:s?"Move a tab here to view":"No active agent"})}function Xt({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:a}){const[c,i]=o.useState(!1),[h,l]=o.useState(!1),x=o.useRef(!1),d=o.useCallback(async m=>{if(!s)return;const v=m.trim();if(!v||x.current)return;const N=s.tabKey;x.current=!0,l(!0);const g=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,p={role:"user",content:v,timestamp:Date.now(),_localId:g};n(w=>({...w,[N]:[...w[N]||[],p]}));try{const w=It(s);if(!w)return;await t(w,"send_chat",{message:v,text:v,...Le(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(y=>{const S=y[N];if(!S)return y;const k=S.filter(j=>j.timestamp>T);return k.length===S.length?y:{...y,[N]:k}})},6e4)}catch(w){console.error("Send failed",w),n(T=>({...T,[N]:(T[N]||[]).filter(y=>y._localId!==g)}))}finally{x.current=!1,l(!1)}},[s,t,n]),f=o.useCallback(async()=>{if(s)try{if(a){await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0});return}await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(m){console.error("Relaunch failed",m)}},[s,a,t]),b=o.useCallback(async m=>{if(s){r(v=>[...v,{ideId:s.tabKey,text:`🖱️ **${m}** clicked`,timestamp:Date.now()}]);try{const N=(s.modalButtons||[]).indexOf(m),g=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),p=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),w=It(s);if(!w)return;(await t(w,"resolve_action",{button:m,action:p?"approve":"reject",...N>=0&&{buttonIndex:N},...Le(s)})).success||r(y=>[...y,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(v){console.error("[ModalButton] Error:",v),r(N=>[...N,{ideId:s.tabKey,text:`❌ **${m}** error`,timestamp:Date.now()}])}}},[s,t,r]),u=o.useCallback(async()=>{if(!(!s||c)){i(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{i(!1)}}},[s,c,t]);return{isSendingChat:h,isFocusingAgent:c,handleSendChat:d,handleRelaunch:f,handleModalButton:b,handleFocusAgent:u}}const mn=o.createContext(null);function Jt(){const t=o.useContext(mn);if(!t)throw new Error("DashboardDockviewContext missing");return t}function wt(t){return t.displayPrimary||t.title||t.agentName||t.tabKey}function qa(t){const[,s]=o.useState(0);o.useEffect(()=>{const n=()=>s(a=>a+1),r=[t.onDidActiveGroupChange(n),t.onDidTitleChange(n),t.onDidGroupChange(n)];return()=>{for(const a of r)a.dispose()}},[t])}function Ya(t,s){if(!s)return[t];const n=new Map(s.groupAssignments),r=new Map(t.map(i=>[i.tabKey,i])),a=new Map;for(const i of t){const h=n.get(i.tabKey)??0,l=a.get(h)??[];l.push(i),a.set(h,l)}return[...a.keys()].sort((i,h)=>i-h).map(i=>{const h=a.get(i)??[],x=(s.groupTabOrders[i]??[]).map(f=>r.get(f)).filter(f=>!!f),d=new Set(x.map(f=>f.tabKey));for(const f of h)d.has(f.tabKey)||x.push(f);return x}).filter(i=>i.length>0)}function Ga(t,s,n){var l;const r=Ea(),a=Ya(s,r);let c;for(const x of a){let d;for(const f of x){const b=t.addPanel({id:f.tabKey,component:"conversation",title:wt(f),params:{tabKey:f.tabKey},...d?{position:{referencePanel:d,direction:"within"},inactive:!0}:c?{position:{referencePanel:c,direction:"right"},inactive:!0}:{}});d||(d=b.id)}c=d??c}const i=n??(r?r.groupActiveTabIds[r.focusedGroup]:null)??((l=s[0])==null?void 0:l.tabKey)??null;if(!i)return;const h=t.getPanel(i);h&&h.group.model.openPanel(h)}function fs(t,s){const n=new Set(s.map(r=>r.tabKey));for(const r of[...t.panels])n.has(r.id)||t.removePanel(r);for(const r of s){const a=t.getPanel(r.tabKey);if(a){a.update({params:{tabKey:r.tabKey}}),a.title!==wt(r)&&a.api.setTitle(wt(r));continue}t.addPanel({id:r.tabKey,component:"conversation",title:wt(r),params:{tabKey:r.tabKey},...t.activePanel?{position:{referencePanel:t.activePanel.id,direction:"within"},inactive:!0}:t.panels[0]?{position:{referencePanel:t.panels[0].id,direction:"within"},inactive:!0}:{}})}}function Xa({params:t}){const s=Jt(),n=o.useRef(null),r=s.conversationsByTabKey.get(t.tabKey),a=Xt({sendDaemonCommand:s.sendDaemonCommand,activeConv:r,setLocalUserMessages:s.setLocalUserMessages,setActionLogs:s.setActionLogs,isStandalone:s.isStandalone}),c=o.useMemo(()=>r?s.ides.find(d=>d.id===r.ideId):void 0,[s.ides,r]),i=r?s.screenshotMap[r.ideId]:void 0,h=o.useCallback(()=>{if(!r||!(r.ideId in s.screenshotMap))return;const d={...s.screenshotMap};delete d[r.ideId],s.setScreenshotMap(d)},[r,s]),l=o.useMemo(()=>r?s.actionLogs.filter(d=>d.ideId===r.tabKey):[],[s.actionLogs,r]);if(!r)return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col",children:e.jsx(Gt,{conversationsCount:0,isSplitMode:!1,isStandalone:s.isStandalone,detectedIdes:s.detectedIdes,handleLaunchIde:s.handleLaunchIde})});const x=je(r)&&!fe(r);return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:e.jsx(pn,{activeConv:r,clearToken:s.clearedTabs[r.tabKey]||0,isCli:x,ideEntry:c,screenshotUrl:i,clearScreenshot:h,terminalRef:n,handleModalButton:a.handleModalButton,handleRelaunch:a.handleRelaunch,handleSendChat:a.handleSendChat,isSendingChat:a.isSendingChat,handleFocusAgent:a.handleFocusAgent,isFocusingAgent:a.isFocusingAgent,actionLogs:l,userName:s.userName})})}function Ja(){const t=Jt();return e.jsx("div",{className:"h-full min-h-0 min-w-0 flex flex-col items-center justify-center",children:e.jsx(Gt,{conversationsCount:0,isSplitMode:!1,isStandalone:t.isStandalone,detectedIdes:t.detectedIdes,handleLaunchIde:t.handleLaunchIde})})}function Za(t){var x;qa(t.api);const n=Jt().conversationsByTabKey.get(t.params.tabKey);if(!n)return e.jsx("div",{className:"adhdev-dockview-tab adhdev-dockview-tab-empty",children:e.jsx("div",{className:"adhdev-dockview-tab-copy",children:e.jsx("div",{className:"adhdev-dockview-tab-primary",children:t.api.title||t.params.tabKey})})});const r=((x=t.api.group.activePanel)==null?void 0:x.id)===t.api.id,a=t.api.isGroupActive,c=n.connectionState==="failed"||n.connectionState==="closed",i=n.connectionState==="connecting"||n.connectionState==="new",h=n.status==="generating",l=n.status==="waiting_approval";return e.jsxs("div",{className:`adhdev-dockview-tab${r?" is-active":""}${a?" is-group-active":""}${c?" is-reconnecting":""}`,title:n.displayPrimary,children:[e.jsx("div",{className:"adhdev-dockview-tab-status","aria-hidden":"true",children:h?e.jsx("div",{className:"tab-spinner"}):l?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-waiting",children:"▲"}):c?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-reconnecting",children:"○"}):i?e.jsx("div",{className:"tab-connecting-spinner"}):n.connectionState==="connected"?e.jsx("span",{className:"adhdev-dockview-tab-status-text is-connected",children:"●"}):e.jsx("span",{className:"adhdev-dockview-tab-status-text is-idle",children:"○"})}),e.jsxs("div",{className:"adhdev-dockview-tab-copy",children:[e.jsx("div",{className:"adhdev-dockview-tab-primary",children:n.displayPrimary}),e.jsx("div",{className:"adhdev-dockview-tab-meta",children:c?e.jsx("span",{className:"adhdev-dockview-tab-reconnecting",children:"Reconnecting…"}):i?e.jsx("span",{className:"adhdev-dockview-tab-connecting",children:"Connecting…"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:n.displaySecondary}),n.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"adhdev-dockview-tab-dot",children:"·"}),e.jsxs("span",{className:"adhdev-dockview-tab-machine",children:["🖥 ",n.machineName]})]})]})})]})]})}function Qa({visibleConversations:t,clearedTabs:s,ides:n,actionLogs:r,screenshotMap:a,setScreenshotMap:c,sendDaemonCommand:i,setLocalUserMessages:h,setActionLogs:l,isStandalone:x,userName:d,detectedIdes:f,handleLaunchIde:b,toggleHiddenTab:u,onActiveTabChange:m,requestedActiveTabKey:v,onRequestedActiveTabConsumed:N}){const{sendCommand:g}=$e(),p=o.useRef(null),w=o.useRef(!1),T=o.useMemo(()=>dn(typeof window<"u"?window.innerWidth:1280),[]),y=o.useMemo(()=>new Map(t.map(R=>[R.tabKey,R])),[t]),S=o.useMemo(()=>({actionLogs:r,clearedTabs:s,conversationsByTabKey:y,detectedIdes:f,handleLaunchIde:b,ides:n,isStandalone:x,screenshotMap:a,sendDaemonCommand:i,setActionLogs:l,setLocalUserMessages:h,setScreenshotMap:c,toggleHiddenTab:u,userName:d}),[r,s,y,f,b,n,x,a,i,l,h,c,u,d]),k=o.useCallback(R=>{if(!R)return!1;const D=p.current;if(!D)return!1;const M=D.getPanel(R);return M?(M.group.model.openPanel(M),N==null||N(),!0):!1},[N]),j=o.useCallback(R=>{var M;p.current=R.api;const D=La(T);D!=null&&D.layout&&R.api.fromJSON(D.layout,{reuseExistingPanels:!1}),fs(R.api,t),R.api.totalPanels===0&&t.length>0?Ga(R.api,t,v):k(v)||k(D==null?void 0:D.activeTabId),w.current=!0,R.api.onDidActivePanelChange(E=>{if(m((E==null?void 0:E.id)??null),!E)return;const $=y.get(E.id);($==null?void 0:$.streamSource)==="agent-stream"&&$.agentType&&g($.ideId,"focus_session",{agentType:$.agentType,...$.sessionId&&{targetSessionId:$.sessionId}}).catch(()=>{})}),R.api.onDidLayoutChange(()=>{var E;_a(T,{activeTabId:((E=R.api.activePanel)==null?void 0:E.id)??null,layout:R.api.toJSON()})}),m(((M=R.api.activePanel)==null?void 0:M.id)??null)},[k,y,T,m,v,g,t]);o.useEffect(()=>{const R=p.current;!R||!w.current||(fs(R,t),!R.activePanel&&R.panels[0]&&R.panels[0].group.model.openPanel(R.panels[0]))},[t]),o.useEffect(()=>{w.current&&k(v)},[k,v]);const _=typeof document<"u"&&document.documentElement.dataset.theme==="light"?Tn:En;return e.jsx(mn.Provider,{value:S,children:e.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden",children:e.jsx(An,{className:"h-full min-h-0 min-w-0 adhdev-dockview",components:{conversation:Xa},defaultTabComponent:Za,watermarkComponent:Ja,onReady:j,singleTabMode:"default",tabAnimation:"smooth",theme:_})})})}function _t(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function eo({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:a,onClearPreviewOrder:c}){const i=o.useRef(0),[h,l]=o.useState(!1),[x,d]=o.useState(null),f=o.useCallback(()=>{i.current=0,l(!1),d(null)},[]);o.useEffect(()=>(window.addEventListener("dragend",f),window.addEventListener("drop",f),()=>{window.removeEventListener("dragend",f),window.removeEventListener("drop",f)}),[f]);const b=o.useCallback(N=>{N.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,l(!0))},[]),u=o.useCallback(N=>{if(!N.dataTransfer.types.includes("text/tab-key"))return;if(N.preventDefault(),!_t(s,n)){d("merge");return}const g=N.currentTarget.getBoundingClientRect(),p=N.clientX-g.left,w=g.width/3;p<w?d("split-left"):p>w*2?d("split-right"):d("merge")},[s,n]),m=o.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,l(!1),d(null))},[]),v=o.useCallback(N=>{i.current=0,l(!1);const g=N.dataTransfer.getData("text/tab-key"),p=g?t.some(T=>T.tabKey===g):!1,w=x;if(d(null),c(),!!g){if(N.preventDefault(),w==="split-left"&&_t(s,n)){n==null||n(g,"split-left");return}if(w==="split-right"&&_t(s,n)){n==null||n(g,"split-right");return}if(p){a(g);return}r==null||r(g)}},[t,x,s,n,r,a,c]);return{dragOver:h,dropAction:x,resetDragState:f,handleDragEnter:b,handleDragOver:u,handleDragLeave:m,handleDrop:v}}function to(t,s){const n=new Set(s.map(c=>c.tabKey)),r=t.filter(c=>n.has(c)),a=s.filter(c=>!t.includes(c.tabKey)).map(c=>c.tabKey);return[...r,...a]}function so({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:a}){const[c,i]=o.useState(s??null),[h,l]=o.useState(n??[]),[x,d]=o.useState(null),f=o.useRef(null),b=o.useRef(null),u=o.useRef(r),m=o.useRef(a);o.useEffect(()=>{u.current=r},[r]),o.useEffect(()=>{m.current=a},[a]),o.useEffect(()=>{s&&s!==c&&i(s)},[s,c]),o.useEffect(()=>{l(k=>{const j=to(k,t);return j.length===k.length&&j.every((_,R)=>_===k[R])?k:j})},[t]);const v=o.useMemo(()=>{const k=x??h;if(k.length===0)return t;const j=new Map(k.map((_,R)=>[_,R]));return[...t].sort((_,R)=>{const D=j.get(_.tabKey)??999,M=j.get(R.tabKey)??999;return D-M})},[t,x,h]);o.useEffect(()=>{var j,_;if(v.length===0){c!==null&&(i(null),(j=u.current)==null||j.call(u,null));return}if(c&&v.some(R=>R.tabKey===c))return;const k=v[0].tabKey;k!==c&&(i(k),(_=u.current)==null||_.call(u,k))},[v,c]);const N=o.useMemo(()=>v.find(k=>k.tabKey===c),[v,c]),g=o.useCallback(k=>{var j;i(k),(j=u.current)==null||j.call(u,k)},[]),p=o.useCallback((k,j,_)=>{l(R=>{var $;const D=R.filter(O=>O!==k),M=D.indexOf(j);if(M<0)return R;const E=_==="left"?M:M+1;return D.splice(E,0,k),($=m.current)==null||$.call(m,D),D}),d(null)},[]),w=o.useCallback((k,j,_)=>{const D=(h.length>0?h:t.map($=>$.tabKey)).filter($=>$!==k),M=D.indexOf(j);if(M<0)return;const E=_==="left"?M:M+1;D.splice(E,0,k),f.current=D,d(D)},[h,t]),T=o.useCallback(()=>{var j;const k=f.current;k&&(l(k),(j=m.current)==null||j.call(m,k))},[]),y=o.useCallback(()=>{f.current=null,d(null)},[]),S=o.useCallback(k=>{l(j=>{var R;const _=j.filter(D=>D!==k);return _.push(k),(R=m.current)==null||R.call(m,_),_})},[]);return{activeTabId:c,activeConv:N,sortedConversations:v,previewOrderRef:f,draggingTabRef:b,selectTab:g,handleTabReorder:p,updatePreviewOrder:w,commitPreviewOrder:T,clearPreviewOrder:y,moveTabToEnd:S,setDraggingTabKey:k=>{b.current=k}}}function no({dropAction:t,canSplit:s}){return e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:t==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:t==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]})}const fn="adhdev-tab-shortcuts";function ro(){try{return JSON.parse(localStorage.getItem(fn)||"{}")}catch{return{}}}function ao({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[a,c]=o.useState(()=>ro()),[i,h]=o.useState(null),l=o.useCallback(d=>{const f=[];return d.metaKey&&f.push(r?"⌘":"Meta"),d.ctrlKey&&f.push("Ctrl"),d.altKey&&f.push(r?"⌥":"Alt"),d.shiftKey&&f.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(f.push(d.key.length===1?d.key.toUpperCase():d.key),f.join("+"))},[r]),x=o.useCallback(d=>{c(d);try{localStorage.setItem(fn,JSON.stringify(d))}catch{}},[]);return o.useEffect(()=>{if(!i)return;const d=f=>{if(f.preventDefault(),f.stopPropagation(),f.key==="Escape"){h(null);return}const b=l(f);if(!b)return;const u={...a};for(const[m,v]of Object.entries(u))v===b&&delete u[m];u[i]=b,x(u),h(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[i,a,x,l]),o.useEffect(()=>{const d=f=>{if(!(!f.ctrlKey&&!f.metaKey&&!f.altKey)){for(const[b,u]of Object.entries(a))if(t.includes(b)&&l(f)===u){f.preventDefault(),s(),n(b);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a,t,s,n,l]),{isMac:r,tabShortcuts:a,shortcutListening:i,setShortcutListening:h,saveShortcuts:x}}const oo=o.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:a,conversationKeys:c,draggingTabRef:i,onFocus:h,onSelectTab:l,onConversationActivated:x,onPreviewReorder:d,onReorderTab:f,onCommitPreviewOrder:b,onClearPreviewOrder:u,onDragStateReset:m,onDragTabKeyChange:v,onReceiveTab:N,onOpenContextMenu:g,longPressTimer:p}){const w=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",T=s.connectionState==="failed"||s.connectionState==="closed",y=o.useCallback(E=>{i.current=s.tabKey,v(s.tabKey),E.dataTransfer.setData("text/tab-key",s.tabKey),E.dataTransfer.effectAllowed="move"},[s.tabKey,i,v]),S=o.useCallback(()=>{i.current=null,v(null),b(),u(),m()},[i,v,b,u,m]),k=o.useCallback(E=>{const $=i.current;if(!(!$||$===s.tabKey)&&E.dataTransfer.types.includes("text/tab-key")){E.preventDefault(),E.stopPropagation();const O=E.currentTarget.getBoundingClientRect(),C=E.clientX<O.left+O.width/2?"left":"right";d($,s.tabKey,C)}},[s.tabKey,i,d]),j=o.useCallback(E=>{E.preventDefault(),E.stopPropagation();const $=E.dataTransfer.getData("text/tab-key");if($&&$!==s.tabKey){const O=E.currentTarget.getBoundingClientRect(),C=E.clientX<O.left+O.width/2?"left":"right";c.includes($)?f($,s.tabKey,C):N&&N($)}u()},[s.tabKey,c,f,N,u]),_=o.useCallback(E=>{E.stopPropagation(),h(),l(s.tabKey),x(s)},[s,x,h,l]),R=o.useCallback(E=>{E.preventDefault(),g(E.clientX,E.clientY,s.tabKey)},[s.tabKey,g]),D=o.useCallback(E=>{const $=E.touches[0];p.current=setTimeout(()=>{g($.clientX,$.clientY,s.tabKey)},600)},[s.tabKey,p,g]),M=o.useCallback(()=>{p.current&&clearTimeout(p.current)},[p]);return e.jsxs("div",{"data-tabkey":s.tabKey,className:`${w} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:y,onDragEnd:S,onDragOver:k,onDrop:j,onClick:_,onContextMenu:R,onTouchStart:D,onTouchEnd:M,onTouchMove:M,style:{background:n?"var(--bg-primary)":"var(--bg-glass)",borderTop:n?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:n?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:n?"1px solid var(--border-subtle)":"1px solid transparent",opacity:r?.4:T?n?.6:.3:n?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[s.status==="generating"?e.jsx("div",{className:"tab-spinner"}):s.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):T?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):s.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:s.displayPrimary,children:s.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:T?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[s.displaySecondary,s.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",s.machineName]})]})]})})]}),a&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${a}`,children:a})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function io({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:a,onFocus:c,onSelectTab:i,onConversationActivated:h,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:u,onMoveTab:m,onReceiveTab:v,onHideTab:N}){const[g,p]=o.useState(null),w=o.useRef(null),T=o.useRef(null),y=o.useMemo(()=>t.map(M=>M.tabKey),[t]);lt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(g==null?void 0:g.tabKey)||null});const{isMac:S,tabShortcuts:k,shortcutListening:j,setShortcutListening:_,saveShortcuts:R}=ao({sortedTabKeys:t.map(M=>M.tabKey),onFocus:c,onSelectTab:i});o.useEffect(()=>{if(!g)return;const M=E=>{const $=document.querySelector("[data-pane-context-menu]");$&&$.contains(E.target)||p(null)};return window.addEventListener("mousedown",M,!0),()=>window.removeEventListener("mousedown",M,!0)},[g]),o.useEffect(()=>{const M=T.current;if(!M)return;const E=$=>{Math.abs($.deltaY)>Math.abs($.deltaX)&&($.preventDefault(),M.scrollLeft+=$.deltaY)};return M.addEventListener("wheel",E,{passive:!1}),()=>M.removeEventListener("wheel",E)},[]);const D=o.useCallback((M,E,$)=>{p({x:M,y:E,tabKey:$})},[]);return e.jsxs(e.Fragment,{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:T,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:[t.map(M=>e.jsx(oo,{conv:M,isActive:s===M.tabKey,isDraggedTab:a.current===M.tabKey,shortcut:k[M.tabKey],conversationKeys:y,draggingTabRef:a,onFocus:c,onSelectTab:i,onConversationActivated:h,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:f,onDragStateReset:b,onDragTabKeyChange:u,onReceiveTab:v,onOpenContextMenu:D,longPressTimer:w},M.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),g&&e.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:g.x,top:g.y},children:[m&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(g.tabKey,"left"),p(null)},children:"← Move to Left Group"}),m&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(g.tabKey,"right"),p(null)},children:"Move to Right Group →"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(g.tabKey,"split-left"),p(null)},children:"⇤ Split Left"}),m&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{m(g.tabKey,"split-right"),p(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:M=>{M.stopPropagation(),_(g.tabKey),p(null)},children:["⌨ ",k[g.tabKey]?`Change shortcut (${k[g.tabKey]})`:"Set shortcut"]}),k[g.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const M={...k};delete M[g.tabKey],R(M),p(null)},children:"✕ Remove shortcut"}),N&&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:()=>{N(g.tabKey),p(null)},children:"🚫 Hide from Dashboard"})]}),!m&&!N&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),j&&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:()=>_(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:M=>M.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. ",S?"⌘+1":"Ctrl+1",", ",S?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function co({conversations:t,ides:s,clearedTabs:n,actionLogs:r,screenshotMap:a,setScreenshotMap:c,sendDaemonCommand:i,setLocalUserMessages:h,setActionLogs:l,isStandalone:x,userName:d,groupIndex:f,onFocus:b,isSplitMode:u,numGroups:m,onMoveTab:v,onReceiveTab:N,style:g,detectedIdes:p,handleLaunchIde:w,onActiveTabChange:T,initialActiveTabId:y,initialTabOrder:S,onTabOrderChange:k,onHideTab:j}){const{sendCommand:_}=$e(),R=o.useRef(null),{activeTabId:D,activeConv:M,sortedConversations:E,draggingTabRef:$,selectTab:O,handleTabReorder:C,updatePreviewOrder:V,commitPreviewOrder:Z,clearPreviewOrder:J,moveTabToEnd:G,setDraggingTabKey:Q}=so({conversations:t,initialActiveTabId:y,initialTabOrder:S,onActiveTabChange:T,onTabOrderChange:k}),Y=Xt({sendDaemonCommand:i,activeConv:M,setLocalUserMessages:h,setActionLogs:l,isStandalone:x}),{dragOver:se,dropAction:ee,resetDragState:ce,handleDragEnter:B,handleDragOver:P,handleDragLeave:A,handleDrop:L}=eo({conversations:t,numGroups:m,onMoveTab:v,onReceiveTab:N,onOwnTabDrop:G,onClearPreviewOrder:J}),W=M&&je(M)&&!fe(M),U=o.useMemo(()=>M?s.find(re=>re.id===M.ideId):void 0,[s,M]),H=M?a[M.ideId]:void 0,ae=o.useCallback(()=>{if(!M||!(M.ideId in a))return;const re={...a};delete re[M.ideId],c(re)},[M,a,c]),de=o.useMemo(()=>M?r.filter(re=>re.ideId===M.tabKey):[],[r,M]);lt("PaneGroup",{groupIndex:f,conversationCount:t.length,activeTabId:D,dragOver:se});const oe=o.useCallback(re=>{re.streamSource==="agent-stream"&&re.agentType&&_(re.ideId,"focus_session",{agentType:re.agentType,...re.sessionId&&{targetSessionId:re.sessionId}}).catch(()=>{})},[_]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:b,style:{...g,outline:se?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(io,{conversations:E,activeTabId:D,groupIndex:f,numGroups:m,draggingTabRef:$,onFocus:b,onSelectTab:O,onConversationActivated:oe,onPreviewReorder:V,onReorderTab:C,onCommitPreviewOrder:Z,onClearPreviewOrder:J,onDragStateReset:ce,onDragTabKeyChange:Q,onMoveTab:v,onReceiveTab:N,onHideTab:j}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:B,onDragOver:P,onDragLeave:A,onDrop:L,children:[se&&e.jsx(no,{dropAction:ee,canSplit:!!(m<4&&v)}),M?e.jsx(pn,{activeConv:M,clearToken:n[M.tabKey]||0,isCli:!!W,ideEntry:U,screenshotUrl:H,clearScreenshot:ae,terminalRef:R,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,handleSendChat:Y.handleSendChat,isSendingChat:Y.isSendingChat,handleFocusAgent:Y.handleFocusAgent,isFocusingAgent:Y.isFocusingAgent,actionLogs:de,userName:d}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Gt,{conversationsCount:t.length,isSplitMode:u,isStandalone:x,detectedIdes:p,handleLaunchIde:w})})]})]})}function lo({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:a,clearedTabs:c,ides:i,actionLogs:h,screenshotMap:l,setScreenshotMap:x,sendDaemonCommand:d,setLocalUserMessages:f,setActionLogs:b,isStandalone:u,userName:m,setFocusedGroup:v,moveTabToGroup:N,splitTabRelative:g,closeGroup:p,handleResizeStart:w,detectedIdes:T,handleLaunchIde:y,groupActiveTabIds:S,setGroupActiveTabIds:k,groupTabOrders:j,setGroupTabOrders:_,toggleHiddenTab:R}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:a.map((D,M)=>{const E=s&&r.length===n?`${r[M]}%`:void 0;return e.jsxs(Rn.Fragment,{children:[s&&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:$=>w(M-1,$),onDoubleClick:()=>p(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(co,{style:s?{flexBasis:E??`${100/n}%`,flexGrow:E?0:1,flexShrink:E?0:1}:void 0,conversations:D,clearedTabs:c,ides:i,actionLogs:h,screenshotMap:l,setScreenshotMap:x,sendDaemonCommand:d,setLocalUserMessages:f,setActionLogs:b,isStandalone:u,userName:m,groupIndex:M,onFocus:()=>v(M),isSplitMode:s,numGroups:n,onMoveTab:($,O)=>{O==="left"&&M>0?N($,M-1):O==="right"&&M<n-1?N($,M+1):O==="split-left"&&n<4?g($,M,"left"):O==="split-right"&&n<4&&g($,M,"right")},onReceiveTab:$=>N($,M),detectedIdes:M===0?T:void 0,handleLaunchIde:M===0?y:void 0,onActiveTabChange:$=>k(O=>(O[M]??null)===($??null)?O:{...O,[M]:$}),initialActiveTabId:S[M],initialTabOrder:j[M],onTabOrderChange:$=>_(O=>{const C=O[M]||[];return C.length===$.length&&C.every((V,Z)=>V===$[Z])?O:{...O,[M]:$}}),onHideTab:R})]},M)})})}function uo({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,onDismiss:a}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 border-b text-xs text-text-secondary shrink-0 flex-wrap",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",borderColor:"color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",style:{color:"var(--status-warning)"},children:e.jsx(_s,{size:14})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available",s?e.jsxs(e.Fragment,{children:[": ",e.jsxs("strong",{children:["v",s]})]}):null]}),t.map(c=>{const i=Xe(c,{fallbackId:c.id}),h=n[c.id],l=c.version||c.daemonVersion||"unknown";return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 15%, transparent)"},children:[e.jsx("span",{className:"font-medium text-text-primary",children:i}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",l]}),h==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):h==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):h==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(c.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold cursor-pointer px-1.5 py-px rounded transition-colors",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},onClick:()=>r(c.id),children:"Upgrade"})]},c.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:a,title:"Dismiss",children:"✕"})]})}function ho({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const a=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:s,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[92%] max-w-[420px] flex flex-col overflow-hidden rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-lg font-extrabold",children:["Stop ",a,"?"]}),e.jsx("div",{className:"mt-1 text-sm text-text-muted",children:"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first."})]}),e.jsxs("div",{className:"px-6 py-5 bg-bg-primary flex flex-col gap-3",children:[e.jsx("button",{onClick:r,className:"btn btn-primary w-full justify-center",children:"Save and stop"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:s,className:"btn btn-secondary w-full justify-center",children:"Cancel"})]})]})]})}const $t=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function xo({onClose:t}){const[s,n]=o.useState(0),r=$t[s],a=s===$t.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:$t.map((c,i)=>e.jsx("div",{style:{width:i===s?24:8,height:8,borderRadius:4,background:i===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},i))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),a&&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:()=>a?t():n(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:a?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
54
+ @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
55
+ @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
56
+ `})]})}function po(){const{sendCommand:t}=$e(),[s,n]=ks(),r=s.get("activeTab"),a=Tt(),{updateIdeChats:c,screenshotMap:i,setScreenshotMap:h}=a,l=a.ides||[],[x,d]=o.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),f=a.toasts||[],b=a.setToasts||(()=>{}),u=a.wsStatus||"connected",m=a.isConnected??!0,v=a.connectionStates||{},N=a.showReconnected||!1,{groupAssignments:g,setGroupAssignments:p,focusedGroup:w,setFocusedGroup:T,groupActiveTabIds:y,setGroupActiveTabIds:S,groupTabOrders:k,setGroupTabOrders:j,groupSizes:_,setGroupSizes:R,isMobile:D,hasHydratedStoredLayout:M,hydrateStoredLayout:E}=Pa(),[$,O]=o.useState(!1),[C,V]=o.useState(!1),[Z,J]=o.useState([]),[G,Q]=o.useState({}),[Y,se]=o.useState({}),[ee,ce]=o.useState(null);lt("Dashboard",{ideCount:l.length,toastCount:f.length,focusedGroup:w,groupCount:Object.keys(g).length,localMessageTabs:Object.keys(G).length,actionLogCount:Z.length});const B=l.find(pe=>pe.type==="adhdev-daemon"),P=(B==null?void 0:B.detectedIdes)||[],A=!!B,{hiddenTabs:L,toggleTab:W}=on(),{chatIdes:U,conversations:H,visibleConversations:ae,visibleTabKeys:de,resolveConversationByTarget:oe}=Ca({ides:l,connectionStates:v,localUserMessages:G,clearedTabs:Y,hiddenTabs:L}),{containerRef:re,normalizedGroupAssignments:K,numGroups:X,isSplitMode:F,groupedConvs:I,moveTabToGroup:q,closeGroup:z,handleResizeStart:ne,splitTabRelative:ue}=Fa({groupAssignments:g,setGroupAssignments:p,setFocusedGroup:T,setGroupActiveTabIds:S,setGroupTabOrders:j,groupSizes:_,setGroupSizes:R,isMobile:D,visibleConversations:ae,visibleTabKeys:de}),te=o.useMemo(()=>{var ye,Ue;if(!D){if(ee){const De=H.find(At=>At.tabKey===ee);if(De)return De}return ae[0]}const pe=y[w];if(pe){const De=H.find(At=>At.tabKey===pe);if(De)return De}return((ye=I[w])==null?void 0:ye[0])||((Ue=I[0])==null?void 0:Ue[0])},[ee,D,y,w,H,I,ae]),ie=o.useMemo(()=>{var pe;return D||!r?null:((pe=oe(r))==null?void 0:pe.tabKey)??null},[D,oe,r]);cn({visibleConversations:ae,clearedTabs:Y,setClearedTabs:se,setActionLogs:J}),ln({ides:l,sendDaemonCommand:t,setToasts:b,setLocalUserMessages:Q,resolveConversationByTarget:oe});const{isCreatingChat:Te,isRefreshingHistory:we,handleLaunchIde:ke,handleSwitchSession:Je,handleNewChat:Ze,handleRefreshHistory:dt}=Ba({sendDaemonCommand:t,activeConv:te,updateIdeChats:c,setToasts:b,setLocalUserMessages:Q,setClearedTabs:se});Da({urlActiveTab:D?r:null,conversations:H,resolveConversationByTarget:oe,normalizedGroupAssignments:K,hasHydratedStoredLayout:D?M:!0,hydrateStoredLayout:D?E:()=>{},setGroupActiveTabIds:S,setFocusedGroup:T,setSearchParams:n,historyModalOpen:$,activeConv:te,isRefreshingHistory:we,ides:l,handleRefreshHistory:dt});const He=o.useCallback(async pe=>{if(!te||!je(te)||fe(te))return;const ye=te.ideType||te.agentType||"",Ue=te.ideId||te.daemonId||"";try{await t(Ue,"stop_cli",{cliType:ye,targetSessionId:te.sessionId,mode:pe})}catch(De){console.error("Stop CLI failed:",De)}},[te,t]),ut=o.useCallback(async()=>{var ye;if(!te||!je(te)||fe(te))return;if((ye=te.resume)!=null&&ye.supported){V(!0);return}const pe=te.ideType||te.agentType||"CLI";window.confirm(`Stop ${pe}?
57
+ This will terminate the CLI process.`)&&await He("hard")},[te,He]),Qe=o.useCallback(()=>{!te||!je(te)||fe(te)||!te.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:te.sessionId}}))},[te]),{versionMismatchDaemons:Et,appVersion:gn,versionBannerDismissed:bn,setVersionBannerDismissed:yn,upgradingDaemons:jn,handleBannerUpgrade:vn}=Ha({ides:l,sendDaemonCommand: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(_r,{wsStatus:u,showReconnected:N}),!bn&&e.jsx(uo,{daemons:Et,targetVersion:gn,upgradingDaemons:jn,onUpgrade:vn,onDismiss:()=>yn(!0)}),e.jsx($r,{activeConv:te,agentCount:U.length,wsStatus:u,isConnected:m,onOpenHistory:()=>O(!0),onFitCli:Qe,onStopCli:ut}),D?e.jsx(lo,{containerRef:re,isSplitMode:F,numGroups:X,groupSizes:_,groupedConvs:I,clearedTabs:Y,ides:l,actionLogs:Z,screenshotMap:i,setScreenshotMap:h,sendDaemonCommand:t,setLocalUserMessages:Q,setActionLogs:J,isStandalone:A,userName:a.userName,focusedGroup:w,setFocusedGroup:T,moveTabToGroup:q,splitTabRelative:ue,closeGroup:z,handleResizeStart:ne,detectedIdes:P,handleLaunchIde:ke,groupActiveTabIds:y,setGroupActiveTabIds:S,groupTabOrders:k,setGroupTabOrders:j,toggleHiddenTab:W}):e.jsx(Qa,{visibleConversations:ae,clearedTabs:Y,ides:l,actionLogs:Z,screenshotMap:i,setScreenshotMap:h,sendDaemonCommand:t,setLocalUserMessages:Q,setActionLogs:J,isStandalone:A,userName:a.userName,detectedIdes:P,handleLaunchIde:ke,toggleHiddenTab:W,onActiveTabChange:ce,requestedActiveTabKey:ie,onRequestedActiveTabConsumed:()=>{r&&n(pe=>{const ye=new URLSearchParams(pe);return ye.delete("activeTab"),ye},{replace:!0})}}),$&&te&&e.jsx(qs,{activeConv:te,ides:l,isCreatingChat:Te,isRefreshingHistory:we,onClose:()=>O(!1),onNewChat:Ze,onSwitchSession:Je,onRefreshHistory:dt}),C&&te&&je(te)&&!fe(te)&&e.jsx(ho,{activeConv:te,onCancel:()=>V(!1),onStopNow:async()=>{V(!1),await He("hard")},onSaveAndStop:async()=>{V(!1),await He("save")}}),e.jsx("style",{children:`
58
+ body { overflow: hidden; overscroll-behavior: none; }
59
+ `}),e.jsx(Ys,{toasts:f,onDismiss:pe=>b(ye=>ye.filter(Ue=>Ue.id!==pe)),onClickToast:pe=>{if(pe.targetKey){const ye=oe(pe.targetKey);ye&&T(K.get(ye.tabKey)??0)}}}),x&&e.jsx(xo,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function mo({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:a}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>a("native"),children:s}),r.map(c=>{const i=n===c.tabKey,h=c.status==="waiting_approval",l=c.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${i?"active":""}`,onClick:()=>a(c.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:h?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),c.title,h&&e.jsx("span",{className:"ide-ext-badge",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)",marginLeft:4},children:"!"})]},c.tabKey)})]}):null}function fo({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:a,onChangeView:c,onOpenHistory:i,headerActions:h,onBack:l}){return e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(Ye,{size:16}),e.jsx("span",{className:"ide-name",children:t}),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 ${n==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:n==="connected"?"Connected":n==="connecting"?"Connecting":"WS"})]}),r&&e.jsx("span",{className:"ide-machine-label",children:r})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(x=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:a===x?"1px solid var(--accent-primary)":"none",background:a===x?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:a===x?"var(--accent-primary)":void 0},onClick:()=>c(x),children:x==="chat"?e.jsx(Ye,{size:14}):x==="split"?"⊞":e.jsx(_e,{size:14})},x)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:i,title:"Chat History",children:e.jsx(Ls,{size:14})}),h,e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:l,children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]})}function go({toasts:t,onDismiss:s}){return t.length===0?null:e.jsx("div",{className:"ide-toasts",children:t.map(n=>e.jsx("div",{className:`ide-toast ${n.type}`,onClick:()=>s(n.id),children:n.message},n.id))})}function bo({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:a,updateIdeChats:c,pushToast:i}){const[h,l]=o.useState(!1),[x,d]=o.useState(!1),[f,b]=o.useState(!1),u=o.useRef(!1),m=o.useCallback(async p=>{const w=p.trim();if(!(!w||!t||f||!s)){b(!0);try{await a(t,"send_chat",{message:w,text:w,waitForResponse:!0,...Le(s)})}catch(T){console.error("[IDE] Send failed:",T)}finally{b(!1)}}},[t,f,a,s]),v=o.useCallback(async()=>{var p;if(!(!t||x||!s)){d(!0);try{const w=await a(t,"list_chats",{forceExpand:!0,...Le(s)}),T=(w==null?void 0:w.chats)||((p=w==null?void 0:w.result)==null?void 0:p.chats);w!=null&&w.success&&Array.isArray(T)&&c(t,T)}catch(w){console.error("[IDE] Refresh history failed:",w),i("히스토리 새로고침에 실패했습니다.","warning")}finally{d(!1)}}},[t,x,a,s,c,i]),N=o.useCallback(async(p,w)=>{if(!(!t||!s))try{const T=await a(t,"switch_chat",{id:w,sessionId:w,...Le(s)}),y=T==null?void 0:T.result;if((T==null?void 0:T.success)===!0||y==="switched"||y==="switched-by-title")return;y===!1||y==="not_found"?i("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof y=="string"&&y.startsWith("error:")?i(`세션 전환 오류: ${y}`,"warning"):i("세션 전환에 실패했습니다.","warning")}catch(T){console.error("[IDE] Switch session failed:",T),i(`세션 전환 실패: ${(T==null?void 0:T.message)||"connection error"}`,"warning")}},[t,a,s,i]),g=o.useCallback(async()=>{if(!(!t||h||!s)){l(!0);try{await a(t,"new_chat",{...Le(s)})}catch(p){console.error("[IDE] New chat failed:",p),i("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,h,a,s,i]);return o.useEffect(()=>{if(!n){u.current=!1;return}u.current||x||(!r||r.length===0)&&(u.current=!0,v())},[n,r,x,v]),{isSendingChat:f,isCreatingChat:h,isRefreshingHistory:x,handleSendAgent:m,handleRefreshHistory:v,handleSwitchSession:N,handleNewChat:g}}function yo({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:a}){const[c,i]=o.useState("native"),h=o.useMemo(()=>Gs(s),[s]),l=o.useMemo(()=>{var v;if(!t)return[];const m=t.daemonId||((v=t.id)==null?void 0:v.split(":")[0])||t.id;return Xs(t,r,{machineName:t.daemonId&&h[t.daemonId]||void 0,connectionState:n[m]||"new"})},[t,r,h,n]),x=o.useMemo(()=>l.find(m=>m.streamSource==="native"),[l]),d=o.useMemo(()=>l.filter(m=>m.streamSource==="agent-stream"),[l]);o.useEffect(()=>{var m;c!=="native"&&(d.some(v=>v.tabKey===c)||i(((m=d[0])==null?void 0:m.tabKey)||"native"))},[c,d]),o.useEffect(()=>{c==="native"&&(x||d[0]&&i(d[0].tabKey))},[c,x,d]);const f=o.useMemo(()=>c==="native"&&x?x:d.find(m=>m.tabKey===c)||x||d[0],[c,x,d]),b=o.useMemo(()=>d.map(m=>({tabKey:m.tabKey,title:m.title||m.agentName||a,status:m.status})),[d,a]),u=o.useCallback(m=>{if(m)return l.find(v=>v.sessionId===m||v.ideId===m||v.tabKey===m||v.ideType===m||v.agentType===m)},[l]);return{activeChatTab:c,setActiveChatTab:i,activeConv:f,conversations:l,extensionTabs:b,hasExtensions:b.length>0,resolveConversationByTarget:u}}function jo({doId:t,ideId:s,ideType:n,connState:r,viewMode:a,instanceId:c}){const[i,h]=o.useState(null),[l,x]=o.useState(null),d=o.useMemo(()=>{if(!s)return n;const b=s.split(":");return b.length>=3&&b[1]==="ide"?b.slice(2).join(":"):n},[s,n]);o.useEffect(()=>t?he.onScreenshot("ide-page",(u,m)=>{if(u!==t)return;const v=new FileReader;v.onload=()=>h(v.result),v.readAsDataURL(m)}):void 0,[t]),o.useEffect(()=>{r!=="connected"&&h(null)},[r]),o.useEffect(()=>{var u;return t?((u=he.onStatus)==null?void 0:u.call(he,(m,v)=>{m===t&&v!=null&&v.screenshotUsage&&x(v.screenshotUsage)}))||(()=>{}):void 0},[t]),o.useEffect(()=>{h(null)},[t,s,d]),o.useEffect(()=>{const b=t?he.get(t):null;if(!(!b||r!=="connected"))return a!=="chat"&&d?b.startScreenshots(d):b.stopScreenshots(d),()=>{b.stopScreenshots(d)}},[a,r,d,t]);const f=o.useCallback(async(b,u)=>{const m=t?he.get(t):null;return!m||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):m.sendInput(b,u,c||d)},[t,r,c,d]);return{connScreenshot:i,screenshotUsage:l,handleRemoteAction:f}}function vo(){const[t,s]=o.useState([]),n=o.useCallback(a=>{s(c=>c.filter(i=>i.id!==a))},[]),r=o.useCallback((a,c="warning")=>{const i=Date.now()+Math.floor(Math.random()*1e3);s(h=>[...h,{id:i,message:a,type:c}]),window.setTimeout(()=>{s(h=>h.filter(l=>l.id!==i))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function wo({renderHeaderActions:t}={}){var re;const{id:s}=Ns(),n=ct(),r=Tt(),a=r.ides||[],c=r.updateIdeChats||(()=>{}),i=r.connectionStates||{},{sendCommand:h}=$e(),l=o.useMemo(()=>Js(s||"").daemonId,[s]),x=o.useMemo(()=>a.find(K=>K.id===s),[a,s]),d=(x==null?void 0:x.type)||void 0,f=d?d.charAt(0).toUpperCase()+d.slice(1):"IDE",b=r.isConnected??!0,u=i[l]||(b?"connected":"new"),m=((re=r.connectionTransports)==null?void 0:re[l])||"unknown",v=o.useMemo(()=>a.find(K=>K.id===l||K.daemonId===l),[a,l]),N=v?Xe(v,{fallbackId:l}):"",g=(x==null?void 0:x.workspace)||"",[p]=ks(),w=typeof window<"u"&&window.innerWidth<=768,T=p.get("view")||(w?"chat":"split"),[y,S]=o.useState(T),[k,j]=o.useState(!1),{toasts:_,setToasts:R,dismissToast:D,pushToast:M}=vo(),[E,$]=o.useState([]),[O,C]=o.useState({}),[V,Z]=o.useState({}),{activeChatTab:J,setActiveChatTab:G,activeConv:Q,conversations:Y,extensionTabs:se,hasExtensions:ee,resolveConversationByTarget:ce}=yo({ideData:x,allIdes:a,connectionStates:i,localUserMessages:O,ideName:f});cn({visibleConversations:Y,clearedTabs:V,setClearedTabs:Z,setActionLogs:$});const{connScreenshot:B,screenshotUsage:P,handleRemoteAction:A}=jo({doId:l,ideId:s||"",ideType:d,connState:u,viewMode:y,instanceId:x==null?void 0:x.instanceId}),L=!!a.find(K=>K.type==="adhdev-daemon"),W=Xt({sendDaemonCommand:h,activeConv:Q,setLocalUserMessages:C,setActionLogs:$,isStandalone:L}),{isCreatingChat:U,isRefreshingHistory:H,handleRefreshHistory:ae,handleSwitchSession:de,handleNewChat:oe}=bo({ideId:s||"",activeConv:Q,historyModalOpen:k,chats:x==null?void 0:x.chats,sendDaemonCommand:h,updateIdeChats:c,pushToast:M});return ln({ides:a,sendDaemonCommand:h,setToasts:R,setLocalUserMessages:C,resolveConversationByTarget:ce}),s?Q?e.jsxs("div",{className:"ide-page",children:[e.jsx(fo,{ideName:f,workspaceName:g,connState:u,machineName:N,viewMode:y,onChangeView:S,onOpenHistory:()=>j(!0),headerActions:t==null?void 0:t({daemonId:l,ideInstanceId:s||""}),onBack:()=>n(-1)}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${y==="chat"?"full":""} ${y==="remote"?"hidden":""}`,children:[e.jsx(mo,{hasExtensions:ee,ideName:f,activeChatTab:J,extensionTabs:se,onSelectTab:K=>{G(K);const X=Y.find(F=>F.tabKey===K);(X==null?void 0:X.streamSource)==="agent-stream"&&h(X.ideId,"focus_session",{agentType:X.agentType,...X.sessionId&&{targetSessionId:X.sessionId}}).catch(()=>{})}}),e.jsx(Ks,{activeConv:Q,onModalButton:W.handleModalButton}),e.jsx(Hs,{activeConv:Q,ideEntry:a.find(K=>K.id===Q.ideId),handleSendChat:W.handleSendChat,isSendingChat:W.isSendingChat,handleFocusAgent:W.handleFocusAgent,isFocusingAgent:W.isFocusingAgent,actionLogs:E,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${y==="remote"?"full":""} ${y==="chat"?"hidden":""}`,children:e.jsx(mr,{addLog:()=>{},connState:u,connScreenshot:B,screenshotUsage:P,transportType:m,onAction:A})})]}),e.jsx(go,{toasts:_,onDismiss:D}),k&&e.jsx(qs,{activeConv:Q,ides:a,isCreatingChat:U,isRefreshingHistory:H,onClose:()=>j(!1),onNewChat:oe,onSwitchSession:de,onRefreshHistory:ae})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function ko({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:a}){const[c,i]=o.useState([]),[h,l]=o.useState(null),[x,d]=o.useState(null),[f,b]=o.useState(!1),[u,m]=o.useState(!1),[v,N]=o.useState(!1),[g,p]=o.useState([]),[w,T]=o.useState([]),[y,S]=o.useState(null),[k,j]=o.useState(!1),[_,R]=o.useState(""),D=o.useRef(null),M=o.useCallback(A=>{D.current=A},[]),E=o.useCallback((A,L,W=!1)=>{i(U=>[...U.slice(-100),{timestamp:Date.now(),level:A,message:L}]),setTimeout(()=>{var U;return(U=a.current)==null?void 0:U.scrollIntoView({behavior:"smooth"})},100),W&&Pe.showToast(L,A==="error"||A==="warn"?"warning":"success")},[a]),$=o.useCallback(async(A,L)=>{var W;if(!t||h)return!1;l(A),E("info",`Launching ${me(A)}${L!=null&&L.workspace?` in ${L.workspace}`:""}...`);try{const U={ideType:A,enableCdp:!0};(W=L==null?void 0:L.workspace)!=null&&W.trim()?U.workspace=L.workspace.trim():L!=null&&L.useDefaultWorkspace&&(U.useDefaultWorkspace=!0);const H=await n(t,"launch_ide",U);return E(H!=null&&H.success?"info":"error",H!=null&&H.success?`${me(A)} launched`:`Failed: ${H==null?void 0:H.error}`,!0),!!(H!=null&&H.success)}catch(U){return E("error",`Launch error: ${U.message}`,!0),!1}finally{l(null)}},[t,h,E,n]),O=o.useCallback(async A=>{if(!t)return{success:!1};const{cliType:L,dir:W,workspaceId:U,useDefaultWorkspace:H,useHome:ae,argsStr:de,model:oe}=A;if(!L)return E("warn","Select a CLI or ACP provider first",!0),{success:!1};const re=de?de.split(/\s+/).filter(Boolean):void 0,K=(W==null?void 0:W.trim())||(U?"(saved id)":H?"(default workspace)":ae?"(home)":"");E("info",`Launching ${L}${K?` in ${K}`:""}${oe?` (model: ${oe})`:""}...`),d(L);try{const X={cliType:L,cliArgs:re,initialModel:oe||void 0};W!=null&&W.trim()?X.dir=W.trim():U?X.workspaceId=U:H?X.useDefaultWorkspace=!0:ae&&(X.useHome=!0);const F=await n(t,"launch_cli",X),I=(F==null?void 0:F.result)||F;return F!=null&&F.success?(E("info",`${L} launched`,!0),(I==null?void 0:I.launchSource)==="home"?E("info","📂 Running in home directory (explicit choice)"):(I==null?void 0:I.launchSource)==="defaultWorkspace"&&E("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:I==null?void 0:I.sessionId}):(E("error",`Failed: ${(F==null?void 0:F.error)||(I==null?void 0:I.error)}`,!0),(F==null?void 0:F.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&S({cliType:L,argsStr:de,model:oe}),{success:!1,sessionId:I==null?void 0:I.sessionId})}catch(X){return E("error",`Launch error: ${X.message}`,!0),{success:!1}}finally{d(null)}},[t,E,n]),C=o.useCallback(async(A,L,W,U)=>t?A?L.trim()?O({cliType:A,dir:L,argsStr:W,model:U}):(S({cliType:A,argsStr:W,model:U}),{success:!1}):(E("warn","Select a provider",!0),{success:!1}):{success:!1},[t,E,O]),V=o.useCallback(async(A,L,W)=>{if(t&&window.confirm(`Stop ${A}?
60
+ This will terminate the process.`))try{const U=await n(t,"stop_cli",{cliType:A,dir:L,targetSessionId:W});U!=null&&U.success?E("info",`${A} stopped`,!0):E("error",`Stop failed: ${(U==null?void 0:U.error)||"Unknown error"}`,!0)}catch(U){E("error",`Stop failed: ${U.message}`,!0)}},[t,E,n]),Z=o.useCallback(async A=>{try{await n(A.daemonId,"restart_ide",{ideType:A.type}),E("info",`${me(A.type)} restart initiated`,!0)}catch(L){E("error",`Restart failed: ${L.message}`,!0)}},[E,n]),J=o.useCallback(async A=>{if(window.confirm(`Stop ${me(A.type)}?
61
+ This will disconnect CDP and optionally kill the process.`))try{const L=await n(A.daemonId,"stop_ide",{ideType:A.type,killProcess:!0});L!=null&&L.success?E("info",`${me(A.type)} stopped`,!0):E("error",`Stop failed: ${(L==null?void 0:L.error)||"Unknown error"}`,!0)}catch(L){E("error",`Stop failed: ${L.message}`,!0)}},[E,n]),G=o.useCallback(async()=>{if(t)try{const A=await n(t,"detect_ides",{});E("info",`Found ${((A==null?void 0:A.result)||[]).length} IDE(s)`,!0)}catch(A){E("error",`Detection failed: ${A.message}`,!0)}},[t,E,n]),Q=o.useCallback(async()=>{if(t){b(!0);try{const A=await n(t,"get_recent_workspaces",{});A!=null&&A.success&&Array.isArray(A==null?void 0:A.result)&&T(A.result)}catch(A){E("error",`Failed: ${A.message}`)}finally{b(!1)}}},[t,E,n]),Y=o.useCallback(async A=>{if(!(!t||!A.trim())){m(!0);try{const L=await n(t,"workspace_add",{path:A.trim()});L!=null&&L.success?E("info",`Workspace added: ${A.trim()}`):E("error",(L==null?void 0:L.error)||"workspace_add failed")}catch(L){E("error",L.message)}finally{m(!1)}return!0}},[t,E,n]),se=o.useCallback(async A=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){m(!0);try{const L=await n(t,"workspace_remove",{id:A});L!=null&&L.success?E("info","Workspace removed",!0):E("error",(L==null?void 0:L.error)||"workspace_remove failed",!0)}catch(L){E("error",L.message,!0)}finally{m(!1)}}},[t,E,n]),ee=o.useCallback(async A=>{var L;if(t){m(!0);try{const W=await n(t,"workspace_set_default",A===null?{clear:!0}:{id:A});if(W!=null&&W.success){E("info",A?"Default workspace updated":"Default workspace cleared",!0);const U=typeof W.defaultWorkspacePath=="string"?W.defaultWorkspacePath:"";U&&((L=D.current)==null||L.call(D,U))}else E("error",(W==null?void 0:W.error)||"workspace_set_default failed",!0)}catch(W){E("error",W.message,!0)}finally{m(!1)}}},[t,E,n]),ce=o.useCallback(async A=>{var W;if(!t||!A.trim())return;const L=A.trim();m(!0);try{const U=await n(t,"workspace_set_default",{path:L});U!=null&&U.success?(E("info","Default workspace set from history"),(W=D.current)==null||W.call(D,L)):E("error",(U==null?void 0:U.error)||"Could not set default (path missing on disk?)")}catch(U){E("error",U.message)}finally{m(!1)}},[t,E,n]),B=o.useCallback(async()=>{var A;if(t){N(!0);try{const L=await n(t,"get_cli_history",{}),W=(L==null?void 0:L.history)??((A=L==null?void 0:L.result)==null?void 0:A.history);L!=null&&L.success&&Array.isArray(W)&&p(W)}catch{}N(!1)}},[t,n]),P=o.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:_}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:_})}catch(A){E("warn",`Live nickname updated, but account sync failed: ${A.message}`)}E("info",`Nickname set to "${_||"(cleared)"}"`),j(!1)}catch(A){E("error",`Failed: ${A.message}`)}},[t,_,s,E,r,n]);return{logs:c,launchingIde:h,launchingAgentType:x,loadingWorkspaces:f,workspaceBusy:u,loadingHistory:v,cliHistory:g,recentWorkspaces:w,launchPick:y,setLaunchPick:S,editingNickname:k,setEditingNickname:j,nicknameInput:_,setNicknameInput:R,addLog:E,handleLaunchIde:$,runLaunchCliCore:O,handleLaunchCli:C,handleStopCli:V,handleRestartIde:Z,handleStopIde:J,handleDetectIdes:G,handleLoadRecentWorkspaces:Q,handleWorkspaceAdd:Y,handleWorkspaceRemove:se,handleWorkspaceSetDefault:ee,handleWorkspaceResumePath:ce,loadCliHistory:B,handleSaveNickname:P,setOnDefaultWorkspaceChanged:M}}function No(t){const s=Math.floor((Date.now()-t)/1e3);return s<45?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function So({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:a,isDashboardHidden:c,onToggleDashboardVisibility:i}){const{workspaceBusy:h,handleWorkspaceAdd:l,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=a,[f,b]=o.useState(""),u=t.availableMem??t.freeMem,m=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-u)/t.totalMem*100))):0,v=t.loadavg[0]||0,N=[...t.workspaceActivity||[]].sort((p,w)=>w.lastUsedAt-p.lastUsedAt).slice(0,5),g=[...s.map(p=>({id:p.id,label:`IDE · ${p.type}`,workspace:p.workspace||""})),...n.map(p=>({id:p.id,label:`CLI · ${p.cliName}`,workspace:p.workspace||""})),...r.map(p=>({id:p.id,label:`ACP · ${p.acpName}`,workspace:p.workspace||""}))].filter(p=>c==null?void 0:c(p.id));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(Ps,{size:16}),label:"Uptime",value:vr(t.uptime)}),e.jsx(ht,{icon:e.jsx(_e,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ht,{icon:e.jsx(Vt,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(ht,{icon:e.jsx(Bs,{size:16}),label:"ACPs",value:`${r.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(ss,{value:Math.min(Math.round(v/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${v.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(ss,{value:m,max:100,label:"Memory",color:"#3b82f6",detail:`${rs(t.totalMem-u)} / ${rs(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(Dt,{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:h,value:t.defaultWorkspaceId||"",onChange:p=>void d(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:f,disabled:h,onChange:p=>b(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await l(f)&&b("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:h,onClick:async()=>{await l(f)&&b("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(t.workspaces||[]).map(p=>e.jsxs("li",{className:"flex items-start gap-2 text-[11px] text-text-muted rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[p.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Wt(p.path,p.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:p.path,children:p.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:h,onClick:()=>void x(p.id),children:"Remove"})]},p.id))}),N.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold mb-2",children:"Recent activity"}),e.jsx("div",{className:"space-y-1.5",children:N.map(p=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px] rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-text-primary truncate",children:Wt(p.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:p.path,children:p.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[p.kind?`${p.kind} · `:"",No(p.lastUsedAt)]})]},`${p.path}:${p.lastUsedAt}`))})]})]}),g.length>0&&i&&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:"Hidden From Dashboard"}),e.jsx("div",{className:"flex flex-col gap-2",children:g.map(p=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-text-primary truncate",children:p.label}),p.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:p.workspace,children:p.workspace})]}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] px-2.5 py-1 text-zinc-300 border-zinc-500/30",onClick:()=>i(p.id),children:"Show"})]},p.id))})]})]})}function Co(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const Io={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 Pt({category:t,machine:s,machineId:n,providers:r,managedEntries:a,getIcon:c,actions:i,sendDaemonCommand:h,isDashboardHidden:l,onToggleDashboardVisibility:x}){const d=ct(),{handleLaunchIde:f,handleLaunchCli:b,handleStopCli:u,handleRestartIde:m,handleStopIde:v,handleDetectIdes:N,cliHistory:g,loadingHistory:p,loadCliHistory:w,launchingIde:T,launchingAgentType:y}=i,[S,k]=o.useState(null),j=o.useCallback(I=>{I&&d({pathname:"/",search:`?activeTab=${encodeURIComponent(I)}`})},[d]),_=Io[t],R=t==="ide",D=t==="acp",M=r.filter(I=>I.category===t),E=new Map(M.map(I=>[I.type,I.displayName||I.type])),[$,O]=o.useState(""),[C,V]=o.useState(""),[Z,J]=o.useState(""),[G,Q]=o.useState(s.defaultWorkspaceId||""),[Y,se]=o.useState(""),[ee,ce]=o.useState([]),B=ee.filter(I=>!a.some(q=>q.type===I&&ve(q.status)!=="stopped")),P=o.useRef({});o.useEffect(()=>{!$&&M.length>0&&O(M[0].type)},[$,M.length]),o.useEffect(()=>{s.defaultWorkspaceId&&!G&&Q(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const A=(()=>{if(G==="__custom__")return Y.trim();if(!G)return"";const I=(s.workspaces||[]).find(q=>q.id===G);return(I==null?void 0:I.path)||""})(),L=o.useCallback(I=>{const q=P.current[I];q&&(clearTimeout(q),delete P.current[I]),ce(z=>z.filter(ne=>ne!==I))},[]),W=o.useCallback(I=>{if(!I)return;ce(z=>z.includes(I)?z:[...z,I]);const q=P.current[I];q&&clearTimeout(q),P.current[I]=setTimeout(()=>{ce(z=>z.filter(ne=>ne!==I)),delete P.current[I]},2e4)},[]);o.useEffect(()=>{for(const I of a)ve(I.status)!=="stopped"&&L(I.type)},[a,L]),o.useEffect(()=>()=>{Object.values(P.current).forEach(clearTimeout),P.current={}},[]);const[U,H]=o.useState({}),[ae,de]=o.useState(null);o.useEffect(()=>{if(!R||!n||!h)return;(async()=>{try{const q=await h(n,"get_ide_extensions",{}),z=(q==null?void 0:q.result)||q;z!=null&&z.success&&(z!=null&&z.ideExtensions)&&H(z.ideExtensions)}catch{}})()},[R,n,h]);const oe=I=>R?me(I.type):t==="cli"?I.cliName:I.acpName,re=R?s.detectedIdes||[]:[],K=()=>{(async()=>{if(R){await f($,A?{workspace:A}:void 0)&&W($);return}const I=await b($,A,C||void 0,D&&Z||void 0);I.success&&(W($),I.sessionId&&j(I.sessionId))})()},X=I=>{R?v(I):u(I.type,I.workspace,I.id)},F=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:G,onChange:I=>{Q(I.target.value),I.target.value!=="__custom__"&&se("")},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(I=>e.jsxs("option",{value:I.id,children:[I.id===s.defaultWorkspaceId?"⭐ ":"",Wt(I.path,I.label)]},I.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…"})]})}),G==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Y,onChange:I=>se(I.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:G==="__custom__"?A?e.jsx("span",{className:"font-mono truncate block",title:A,children:A}):"Enter an absolute path to launch there.":A?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:G===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:A,children:A})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${_.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",_.label]}),F,R?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[re.map(I=>{const q=a.find(te=>(te.type||"").toLowerCase()===(I.type||"").toLowerCase()&&ve(te.status)!=="stopped"),z=I.running||!!q,ne=!!q&&q.cdpConnected,ue=ee.includes(I.type||I.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&q){d(`/ide/${q.id}`);return}ue||(async()=>await f(I.type||I.id||"",A?{workspace:A}:void 0)&&W(I.type||I.id||""))()},disabled:!!T||ue,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:T&&T!==I.type?.4:1},children:[e.jsx("span",{children:c(I.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)]"}),ue?`⏳ Waiting for ${I.name||me(I.type)}...`:ne?`Open ${I.name||me(I.type)}`:T===I.type?"⏳ Launching...":`▶ ${I.name||me(I.type)}`,z&&ne&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},I.type)}),re.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:N,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Xn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:$,onChange:I=>O(I.target.value),className:"machine-input",children:M.length>0?M.map(I=>e.jsxs("option",{value:I.type,children:[I.icon," ",I.displayName]},I.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),D&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Z,onChange:I=>J(I.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:C,onChange:I=>V(I.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:K,disabled:!!y,className:"machine-btn-primary",children:y===$?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",a.length+ee.filter(I=>!a.some(q=>q.type===I&&ve(q.status)!=="stopped")).length,")"]}),a.length===0&&B.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 ",_.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[B.map(I=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:c(I)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:R?me(I):E.get(I)||I}),e.jsx("div",{className:"text-[11px] text-text-muted",children:y===I?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${I}`)),a.map(I=>{const q=R?I:null,z=D?I:null,ne=!R&&!D?I:null,ue=ve(I.status),te=(l==null?void 0:l(I.id))??!1;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(I.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[oe(I),(q==null?void 0:q.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",q.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:I.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",{style:{color:"var(--status-warning)"},children:["📋 ",z.currentPlan]})]}),ne&&(ne.runtimeKey||ne.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ne.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",ne.runtimeKey]}),e.jsx("button",{type:"button",className:"machine-btn text-[9px] px-1.5 py-px",onClick:()=>{var ie;(ie=navigator.clipboard)==null||ie.writeText(`adhdev attach ${ne.runtimeKey}`),k(ne.runtimeKey||null),window.setTimeout(()=>{k(Te=>Te===ne.runtimeKey?null:Te)},1200)},children:S===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{style:{color:ne.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ne.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:Co(ne.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[x&&e.jsx("button",{onClick:()=>x(I.id),className:`machine-btn ${te?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:te?"Show on Dashboard":"Hide from Dashboard",children:te?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${ue==="stopped"?"bg-red-500/[0.08] text-red-500":ue==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:ue}),R&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d(`/ide/${I.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(_e,{size:13})," Control"]}),e.jsx("button",{onClick:()=>m(I),className:"machine-btn",style:{color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"},children:"↻"})]}),D&&e.jsx("button",{onClick:()=>d(`/ide/${I.id}`),className:"machine-btn",title:"View chat",children:e.jsx(Ye,{size:14})}),ne&&ue!=="stopped"&&e.jsxs("button",{onClick:()=>j(I.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(_e,{size:13})," Open"]}),ue==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(R){await f(I.type,I.workspace?{workspace:I.workspace}:void 0)&&W(I.type);return}const ie=await b(I.type,I.workspace);ie.success&&(W(I.type),ie.sessionId&&j(ie.sessionId))})()},disabled:ee.includes(I.type),className:"machine-btn text-green-500 border-green-500/30",children:ee.includes(I.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>X(I),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),q&&q.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:q.aiAgents.map(ie=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${zs(ie.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[ie.name," · ",ve(ie.status)]},ie.id))}),q&&(U[q.type]||[]).length>0&&h&&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:(U[q.type]||[]).map(ie=>e.jsxs("button",{disabled:ae===`${q.type}.${ie.type}`,onClick:async()=>{const Te=`${q.type}.${ie.type}`;de(Te);try{await h(n,"set_ide_extension",{ideType:q.type,extensionType:ie.type,enabled:!ie.enabled}),H(we=>({...we,[q.type]:(we[q.type]||[]).map(ke=>ke.type===ie.type?{...ke,enabled:!ke.enabled}:ke)}))}catch(we){console.error("Extension toggle failed:",we)}finally{de(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 ${ie.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 ${ie.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),ie.name,e.jsx("span",{className:"text-[9px] font-normal",children:ie.enabled?"ON":"OFF"})]},ie.type))})]})]},I.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:p,className:"machine-btn",children:p?"⏳":"↻ Load"})]}),(()=>{const I=new Set(M.map(z=>z.type)),q=g.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:I.has(z.cliType));return q.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:q.map((z,ne)=>{var ue,te;return e.jsxs("div",{onClick:()=>{O(z.cliType),(z.workspace||z.dir)&&(Q("__custom__"),se(z.workspace||z.dir)),V((z.cliArgs||[]).join(" ")),J(z.model||""),R&&(async()=>await f(z.cliType,z.workspace?{workspace:z.workspace}:void 0)&&W(z.cliType))()},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:((ue=z.workspace||z.dir)==null?void 0:ue.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"}),((te=z.cliArgs)==null?void 0:te.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():""})]},ne)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",_.label," launch history yet."]})})()]})]})}const gs=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Mo=[{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 To({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[a,c]=o.useState("config"),[i,h]=o.useState("codex-cli"),[l,x]=o.useState([]),[d,f]=o.useState(""),[b,u]=o.useState([]),[m,v]=o.useState(""),N=o.useRef(null),g=o.useRef(null),p=j=>{x(_=>_.includes(j)?_.filter(R=>R!==j):[..._,j])},w=()=>x([...gs]),T=()=>x([]);o.useEffect(()=>{var j;(j=N.current)==null||j.scrollIntoView({behavior:"smooth"})},[b]),o.useEffect(()=>()=>{g.current&&clearInterval(g.current)},[]);const y=o.useCallback(()=>{g.current&&clearInterval(g.current),g.current=setInterval(async()=>{try{const j=await n(t,"provider_auto_fix_status",{providerType:s.type});(j==null?void 0:j.running)===!1&&a==="running"&&(c("done"),u(_=>[..._,`
62
+ ✅ Auto-fix completed!`]),g.current&&clearInterval(g.current))}catch{}},3e3)},[t,s.type,n,a]),S=async()=>{if(l.length!==0){c("running"),u(["🚀 Starting auto-fix...",`Agent: ${i}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),v("");try{const j=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:i,...d?{comment:d}:{}});j!=null&&j.success&&(j!=null&&j.started||j!=null&&j.running)?(u(_=>[..._,"✅ Agent started. Monitoring progress..."]),y()):(c("error"),v((j==null?void 0:j.error)||"Failed to start auto-fix"))}catch(j){c("error"),v((j==null?void 0:j.message)||"Connection failed")}}},k=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),u(j=>[...j,`
63
+ ⚠️ Auto-fix cancelled.`]),c("done"),g.current&&clearInterval(g.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:r,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[a==="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:Mo.map(j=>e.jsxs("button",{onClick:()=>h(j.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:i===j.value?j.color+"66":"var(--border-subtle)",background:i===j.value?j.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:i===j.value?j.color:"var(--text-primary)"},children:j.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:j.desc})]},j.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:w,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:T,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:gs.map(j=>e.jsxs("button",{onClick:()=>p(j),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(j)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(j)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(j)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(j)?"☑ ":"☐ ",j]},j))})]}),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:j=>f(j.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"})]})]}),(a==="running"||a==="done"||a==="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:[b.map((j,_)=>e.jsx("div",{className:j.startsWith("✅")?"text-green-400":"",style:j.startsWith("❌")||j.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:j},_)),a==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:N})]}),m&&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:m})]})]}),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:[a==="config"&&l.length>0&&`${l.length} script(s) selected`,a==="running"&&"Agent is generating...",a==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[a==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:S,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:l.length>0?"rgba(139,92,246,0.4)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),a==="running"&&e.jsx("button",{onClick:k,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(a==="done"||a==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("config"),u([]),v("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Eo({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:a}){var y;const c=s.filter(S=>S.category==="ide"),[i,h]=o.useState(((y=c[0])==null?void 0:y.type)||""),[l,x]=o.useState(""),[d,f]=o.useState(""),[b,u]=o.useState(!1),[m,v]=o.useState(""),[N,g]=o.useState(!1),p=S=>{const k=S.toLowerCase().replace(/[^a-z0-9-]/g,"");x(k),(!d||d===w(l))&&f(w(k))},w=S=>S.split("-").map(k=>k.charAt(0).toUpperCase()+k.slice(1)).join(" "),T=async()=>{if(!(!l||!d||!i)){u(!0),v("");try{const S=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:i});S!=null&&S.success||S!=null&&S.created?(g(!0),a==null||a(l)):v((S==null?void 0:S.error)||"Failed to create provider")}catch(S){v((S==null?void 0:S.message)||"Connection failed")}u(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,children:e.jsxs("div",{className:"w-full max-w-[480px] rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:S=>S.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:N?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:c.map(S=>e.jsxs("button",{onClick:()=>h(S.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:i===S.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:i===S.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:S.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:i===S.type?"#a78bfa":"var(--text-secondary)"},children:S.displayName})]},S.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:l,onChange:S=>p(S.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:d,onChange:S=>f(S.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"})]}),m&&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:m})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:N?e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:!l||!d||b,className:"machine-btn",style:{background:l&&d?"rgba(34,197,94,0.12)":void 0,borderColor:l&&d?"rgba(34,197,94,0.3)":void 0,color:l&&d?"#86efac":void 0,opacity:!l||!d||b?.4:1},children:b?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Ao({machineId:t,providers:s,sendDaemonCommand:n}){const[r,a]=o.useState([]),[c,i]=o.useState(!1),[h,l]=o.useState(null),[x,d]=o.useState("all"),[f,b]=o.useState(null),[u,m]=o.useState(!1),v=o.useCallback(async()=>{var g;if(t){i(!0);try{const p=await n(t,"get_provider_settings",{}),w=(p==null?void 0:p.result)||p;if(p!=null&&p.success&&(w!=null&&w.settings)){const T=[];for(const[y,S]of Object.entries(w.settings)){const k=s.find(j=>j.type===y);T.push({type:y,displayName:(k==null?void 0:k.displayName)||y,icon:(k==null?void 0:k.icon)||"",category:(k==null?void 0:k.category)||"unknown",schema:S,values:((g=w.values)==null?void 0:g[y])||{}})}T.sort((y,S)=>y.category.localeCompare(S.category)||y.displayName.localeCompare(S.displayName)),a(T)}}catch{}i(!1)}},[t,s,n]);o.useEffect(()=>{r.length===0&&v()},[]);const N=async(g,p,w)=>{l(`${g}.${p}`),a(T=>T.map(y=>y.type===g?{...y,values:{...y.values,[p]:w}}:y));try{const T=await n(t,"set_provider_setting",{providerType:g,key:p,value:w});T!=null&&T.success||v()}catch{v()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(g=>e.jsx("button",{onClick:()=>d(g),className:`machine-btn text-[10px] px-2 py-0.5 ${x===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>m(!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:v,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(g=>g.category===x).length>1&&(()=>{const g=r.filter(y=>y.category===x),p=new Map;for(const y of g)for(const S of y.schema){if(S.type!=="boolean")continue;const k=p.get(S.key),j=!!(y.values[S.key]??S.default);k?(k.onCount+=j?1:0,k.total+=1):p.set(S.key,{label:S.label||S.key,onCount:j?1:0,total:1})}const w=[...p.entries()].filter(([,y])=>y.total===g.length);if(w.length===0)return null;const T=async(y,S)=>{for(const k of g)await N(k.type,y,S)};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 ",x.toUpperCase()," providers (",g.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(([y,S])=>{const k=S.onCount===S.total,j=S.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:S.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",S.onCount,"/",S.total,")"]}),e.jsx("button",{onClick:()=>void T(y,!0),disabled:k,className:`machine-btn text-[9px] px-1.5 py-px ${k?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(y,!1),disabled:j,className:`machine-btn text-[9px] px-1.5 py-px ${j?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},y)})})]})})(),c&&r.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:r.filter(g=>x==="all"||g.category===x).map(g=>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:g.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:g.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:g.category==="acp"?"rgba(139,92,246,0.08)":g.category==="cli"?"rgba(59,130,246,0.08)":g.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:g.category==="acp"?"#a78bfa":g.category==="cli"?"#60a5fa":g.category==="ide"?"#86efac":"var(--status-warning)"},children:g.category}),g.category==="ide"&&e.jsx("button",{onClick:()=>b(s.find(p=>p.type===g.type)||{type:g.type,displayName:g.displayName,icon:g.icon,category:g.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:g.schema.map(p=>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:[p.label||p.key,h===`${g.type}.${p.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),p.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:p.description})]}),e.jsx("div",{className:"shrink-0",children:p.type==="boolean"?e.jsx("button",{onClick:()=>N(g.type,p.key,!(g.values[p.key]??p.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:g.values[p.key]??p.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:g.values[p.key]??p.default?21:3}})}):p.type==="number"?e.jsx("input",{type:"number",value:g.values[p.key]??p.default??0,min:p.min,max:p.max,onChange:w=>{const T=parseInt(w.target.value)||0;p.min!==void 0&&T<p.min||p.max!==void 0&&T>p.max||N(g.type,p.key,T)},className:"machine-input w-20 text-center text-[11px]"}):p.type==="select"&&p.options?e.jsx("select",{value:g.values[p.key]??p.default??"",onChange:w=>N(g.type,p.key,w.target.value),className:"machine-input text-[11px]",children:p.options.map(w=>e.jsx("option",{value:w,children:w},w))}):e.jsx("input",{type:"text",value:g.values[p.key]??p.default??"",onBlur:w=>N(g.type,p.key,w.target.value),className:"machine-input w-[120px] text-[11px]"})})]},p.key))})]},g.type))}),f&&e.jsx(To,{machineId:t,provider:f,sendDaemonCommand:n,onClose:()=>b(null)}),u&&e.jsx(Eo,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>m(!1),onCreated:()=>{m(!1),v()}})]})}function Ro({machineId:t,sendDaemonCommand:s}){const[n,r]=o.useState([]),[a,c]=o.useState(0),[i,h]=o.useState(!0),[l,x]=o.useState("debug"),d=o.useRef(null),f=o.useRef(!1);return o.useEffect(()=>{if(!t||!i)return;const b=async()=>{try{const m=await s(t,"get_logs",{count:200,minLevel:l,since:a}),v=(m==null?void 0:m.result)||m;if(m!=null&&m.success&&Array.isArray(v==null?void 0:v.logs)&&v.logs.length>0){r(g=>[...g,...v.logs.map(w=>({timestamp:w.ts,level:w.level,message:`[${w.category}] ${w.message}`}))].slice(-300));const N=Math.max(...v.logs.map(g=>g.ts));c(N)}}catch{}};b();const u=setInterval(b,3e3);return()=>clearInterval(u)},[t,i,a,l,s]),o.useEffect(()=>{if(i&&n.length>0){const b=f.current?"smooth":"instant";setTimeout(()=>{var u;(u=d.current)==null||u.scrollIntoView({behavior:b}),f.current=!0},50)}},[n.length,i]),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(b=>e.jsx("button",{onClick:()=>{x(b),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>h(!i),className:`machine-btn ${i?"text-green-500 border-green-500/30":""}`,children:i?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),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:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((b,u)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"var(--status-warning)":b.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(b.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"var(--status-warning)":b.level==="debug"?"#475569":"#8b5cf6"},children:b.level==="error"?"ERR":b.level==="warn"?"WRN":b.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:b.message})]},u)),e.jsx("div",{ref:d})]})]})}function Lo({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:a}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(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:()=>{a(null),r({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:()=>{a(null),r({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{a(null),r({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>a(null),children:"Cancel"})]})]})})}function _o({onNicknameSynced:t}={}){var k,j,_,R,D,M,E,$,O;const{id:s}=Ns(),n=ct(),{sendCommand:r}=$e(),a=Tt(),c=a.ides||[],i=a.initialLoaded??!0,{isHidden:h,toggleTab:l}=on(),x=c.find(C=>C.id===s&&C.daemonMode),[d,f]=o.useState("overview"),b=o.useRef(null),u=ko({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:b});o.useEffect(()=>Pe.onToast(V=>{a.setToasts(J=>{if(J.some(Y=>Y.message===V.message&&V.timestamp-Y.timestamp<3e3))return J;const Q={id:V.id,message:V.message,type:V.type,timestamp:V.timestamp,targetKey:V.targetKey,actions:V.actions};return[...J.slice(-4),Q]});const Z=V.duration||5e3;setTimeout(()=>a.setToasts(J=>J.filter(G=>G.id!==V.id)),Z)}),[a]);const m=((x==null?void 0:x.availableProviders)||[]).map(C=>({type:C.type,displayName:C.displayName,icon:C.icon,category:C.category})),v={};for(const C of m)v[C.type]=C.icon;const N=C=>v[C]||"",g=x?{id:x.id,hostname:Fs(x,{fallbackId:x.id}),platform:((k=x.machine)==null?void 0:k.platform)||"unknown",arch:((j=x.machine)==null?void 0:j.arch)||"",cpus:((_=x.machine)==null?void 0:_.cpus)||0,totalMem:((R=x.machine)==null?void 0:R.totalMem)||0,freeMem:((D=x.machine)==null?void 0:D.freeMem)||0,availableMem:(M=x.machine)==null?void 0:M.availableMem,loadavg:((E=x.machine)==null?void 0:E.loadavg)||[],uptime:(($=x.machine)==null?void 0:$.uptime)||0,release:((O=x.machine)==null?void 0:O.release)||"",cdpConnected:!!x.cdpConnected,machineNickname:x.machineNickname||null,p2p:x.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:x.detectedIdes||[],workspaces:x.workspaces||[],defaultWorkspaceId:x.defaultWorkspaceId??x.activeWorkspaceId??null,defaultWorkspacePath:x.defaultWorkspacePath??x.activeWorkspacePath??null,workspaceActivity:x.workspaceActivity||[]}:null,p=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!as(C)&&!os(C)).map(C=>({id:C.id,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:Ir(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],childSessions:C.childSessions||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),w=c.filter(C=>C.daemonId===s&&as(C)).map(C=>({id:C.id,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,daemonId:s})),T=c.filter(C=>C.daemonId===s&&os(C)).map(C=>({id:C.id,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!g)return i?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:()=>n("/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 y=Xe(x,{fallbackId:g.id}),S=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Jn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{size:14})," IDEs"]}),count:p.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ge,{size:14})," CLIs"]}),count:w.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bs,{size:14})," ACP Agents"]}),count:T.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ht,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gn,{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:()=>n("/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:[u.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:u.nicknameInput,onChange:C=>u.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&u.handleSaveNickname(),C.key==="Escape"&&u.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:u.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>u.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{u.setEditingNickname(!0),u.setNicknameInput(g.machineNickname||"")},title:"Click to set nickname",children:y}),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:[g.platform," · ",g.arch," · ",g.cpus," cores"]}),(x==null?void 0:x.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",x.version]}),(x==null?void 0:x.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold cursor-pointer transition-colors shrink-0",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)"},onClick:async()=>{try{await r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",x.serverVersion]}),g.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:g.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:g.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",g.p2p.state==="connected"?`● ${g.p2p.peers}`:"○"]}),g.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 ●"}),g.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",g.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:S.map(C=>e.jsxs("button",{onClick:()=>f(C.id),className:`machine-tab shrink-0${d===C.id?" active":""}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:"tab-count",children:C.count})]},C.id))})]}),e.jsxs("div",{className:"page-content",children:[d==="overview"&&e.jsx(So,{machine:g,ideSessions:p,cliSessions:w,acpSessions:T,actions:u,isDashboardHidden:h,onToggleDashboardVisibility:l}),d==="ides"&&e.jsx(Pt,{category:"ide",machine:g,machineId:s,providers:m,managedEntries:p,getIcon:N,actions:u,isDashboardHidden:h,onToggleDashboardVisibility:l,sendDaemonCommand:r}),d==="clis"&&e.jsx(Pt,{category:"cli",machine:g,machineId:s,providers:m,managedEntries:w,getIcon:N,actions:u,isDashboardHidden:h,onToggleDashboardVisibility:l}),d==="acps"&&e.jsx(Pt,{category:"acp",machine:g,machineId:s,providers:m,managedEntries:T,getIcon:N,actions:u,isDashboardHidden:h,onToggleDashboardVisibility:l}),d==="providers"&&e.jsx(Ao,{machineId:s,providers:m,sendDaemonCommand:r}),d==="logs"&&e.jsx(Ro,{machineId:s,sendDaemonCommand:r})]}),u.launchPick&&g&&e.jsx(Lo,{machine:g,launchPick:u.launchPick,actions:u}),e.jsx(Ys,{toasts:a.toasts||[],onDismiss:C=>a.setToasts(V=>V.filter(Z=>Z.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
64
+ @keyframes toast-in {
65
+ from { opacity: 0; transform: translateX(40px); }
66
+ to { opacity: 1; transform: translateX(0); }
67
+ }
68
+ `})]})}function $o(){const[t,s]=o.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=o.useState(!0);o.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(i=>i.json()).then(i=>{const h=[],l=[],x=[],d=[];Object.values(i.providers||{}).forEach(b=>{const u={name:b.name||"Unknown",status:b.status||"Stable",details:b.details||"Community Provider"};b.category==="ide"?h.push(u):b.category==="cli"?l.push(u):b.category==="extension"?x.push(u):b.category==="acp"&&d.push(u)});const f=(b,u)=>{const m={Stable:1,Beta:2,WIP:3},v=m[b.status]||99,N=m[u.status]||99;return v!==N?v-N:b.name.localeCompare(u.name)};s({ide:h.sort(f),cli:l.sort(f),ext:x.sort(f),acp:d.sort(f)})}).catch(i=>console.error("Failed to load capabilities:",i)).finally(()=>r(!1))},[]);const a=i=>i==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Rs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):i==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Ut,{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(Ps,{className:"w-4 h-4"})," ",e.jsx("span",{children:i})]}),c=i=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:i.map((h,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:h.name}),e.jsx("td",{className:"py-3 px-4",children:a(h.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:h.details})]},l))})]})});return n?e.jsx(St,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Nt,{}),widthClassName:"max-w-5xl",children:e.jsx(qt,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(St,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Nt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(be,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(be,{title:"IDE support",icon:e.jsx(_e,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:c(t.ide)}),e.jsx(be,{title:"Standalone CLI agents",icon:e.jsx(Vt,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:c(t.cli)}),e.jsx(be,{title:"AI extensions",icon:e.jsx(Ge,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:c(t.ext)}),e.jsx(be,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ge,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:c(t.acp)})]})}class Po{constructor(){xe(this,"adapters",new Map);xe(this,"states",new Map);xe(this,"ptyCallbacks",new Set);xe(this,"runtimeListeners",new Map);xe(this,"screenshotCallbacks",new Map);xe(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,a){return!1}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n,r){r!=null&&r.scrollback?this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:0,text:typeof n=="string"?n:"",truncated:!1}):typeof n=="string"&&n&&this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,data:n}),this.ptyCallbacks.forEach(a=>a(s,n,r))}emitRuntimeSnapshot(s,n,r=0,a=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:a})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const a=this.runtimeListeners.get(s);a&&(a.delete(n),a.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const a=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof a.seq=="number"?a.seq:0,text:typeof a.text=="string"?a.text:"",truncated:!!a.truncated})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(a=>a(n))}}const Ae=new Po;function Do(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const bs=Do(),ys=3e3,Bo=3e4;let Re=null,Wo=0;const Mt=new Map;let We=null,ot=null;function Oo(t){return t==="connected"?"connected":t}async function kt(t,s,n){const r=Kr(t,n||{}),a=Re;if(a&&a.readyState===WebSocket.OPEN){const i=`req_${++Wo}_${Date.now()}`;return new Promise((h,l)=>{const x=setTimeout(()=>{Mt.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);Mt.set(i,{resolve:d=>{clearTimeout(x),h(d)},reject:d=>{clearTimeout(x),l(d)}}),a.send(JSON.stringify({type:"command",requestId:i,data:{type:s,payload:r.payload}}))})}const c=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!c.ok)throw new Error(`HTTP ${c.status}`);return c.json()}class Ko{constructor(s){xe(this,"daemonId");xe(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN}get connectionState(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return kt(this.daemonId,s,n)}async sendInput(s,n){return kt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,We&&(clearInterval(We),We=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await kt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const a=await fetch(`data:image/jpeg;base64,${r.base64}`).then(c=>c.blob());Ae.emitScreenshot(this.daemonId,a)}}catch{}};n(),We=setInterval(n,2e3)}stopScreenshots(s){We&&(clearInterval(We),We=null)}}let Ce=null;function zo(t){return(!Ce||Ce.daemonId!==t)&&(Ce=new Ko(t)),Ce}function Fo({children:t}){const s=o.useRef(Qt()),n=Qt();s.current=n;const{setUserName:r}=it(),a=o.useRef(r);a.current=r;const[,c]=o.useState("disconnected"),i=o.useCallback((b,u)=>{c(b),ot==null||ot(b,u)},[]),h=o.useRef(null),l=o.useRef(),x=o.useRef(ys),d=o.useRef(!0),f=o.useRef(!1);return o.useEffect(()=>{d.current=!0,f.current=!1;function b(){var v,N;if(!d.current||((v=h.current)==null?void 0:v.readyState)===WebSocket.OPEN||((N=h.current)==null?void 0:N.readyState)===WebSocket.CONNECTING)return;i("connecting"),console.log(`[Standalone WS] Connecting to ${bs}...`);let m;try{m=new WebSocket(bs)}catch(g){console.error("[Standalone WS] Failed to create WebSocket:",g),u();return}h.current=m,m.onopen=()=>{if(!d.current){m.close();return}i("connected"),x.current=ys,console.log("[Standalone WS] Connected")},Re=m,m.onmessage=g=>{var p;try{const w=JSON.parse(g.data);if((w.type==="command_result"||w.type==="error")&&w.requestId){const T=Mt.get(w.requestId);T&&(Mt.delete(w.requestId),w.type==="error"?T.reject(new Error(((p=w.data)==null?void 0:p.message)||"Command failed")):T.resolve(w.data));return}if(w.type==="pty_output"){Ae.emitPtyOutput(w.cliId,w.data);return}if(w.type==="runtime_snapshot"){Ae.emitRuntimeSnapshot(w.sessionId,typeof w.text=="string"?w.text:"",typeof w.seq=="number"?w.seq:0,!!w.truncated);return}if(w.type==="status"||w.type==="initial_state"){const T=w.data;if(!T)return;const{injectEntries:y,markLoaded:S}=s.current,k=T.id||"standalone",j=zo(k);Ae.register(k,j),Ae.setState(k,"connected"),i("connected",k),Ae.emitStatus(k,T);const _=Or(T,{daemonId:k});_.length>0&&y(_),S(),T.userName&&a.current&&a.current(T.userName)}}catch(w){console.error("[Standalone WS] Parse error:",w)}},m.onclose=()=>{d.current&&(Ce==null||Ce.stopScreenshots(),Ce&&Ae.setState(Ce.daemonId,"disconnected"),i("disconnected"),h.current=null,u())},m.onerror=g=>{f.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",g)}}function u(){if(!d.current)return;clearTimeout(l.current);const m=x.current;console.log(`[Standalone WS] Reconnecting in ${m}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,Bo),b()},m)}return b(),()=>{d.current=!1,f.current=!0,clearTimeout(l.current),h.current&&(h.current.onerror=null,h.current.onclose=null,h.current.close(),h.current=null,Re=null),Ce&&(Ce.stopScreenshots(),Ae.unregister(Ce.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function Ho({children:t}){const[s,n]=o.useState("disconnected"),[r,a]=o.useState(null);o.useEffect(()=>(ot=(i,h)=>{n(i),h&&a(h)},()=>{ot=null}),[]);const c=o.useMemo(()=>{const i=s==="connected",h=Oo(s),l={};return r&&(l[r]=h),l.standalone=h,{wsStatus:s,isConnected:i,connectionStates:l}},[s,r]);return e.jsx(On,{connectionOverrides:c,children:e.jsx(Fo,{children:t})})}const Uo=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Ts,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Es,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Ht,{}),label:"Settings"}];function Vo({children:t}){const s=ct(),n=Ln(),[r,a]=o.useState(!1),[c,i]=o.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),h=d=>{s(d),a(!1)},l=()=>{i(d=>{const f=!d;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=d=>`nav-item${n.pathname.startsWith(d)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>a(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>a(!1),onKeyDown:d=>d.key==="Escape"&&a(!1)}),e.jsxs("aside",{className:`sidebar ${r?"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:()=>a(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Uo.map(d=>e.jsxs("div",{className:x(d.path),id:`nav-${d.id}`,onClick:()=>h(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 ${c?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:c?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Nt,{})}),!c&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${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(As,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.33"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,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 qo=[{icon:e.jsx(Es,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(Ye,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx($s,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(_e,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ge,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Nt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Yo=[{icon:e.jsx(Ds,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Ts,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Ws,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Yn,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Vn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Rs,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Go=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function Xo(){return e.jsxs(St,{icon:e.jsx(As,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.7.33"]}),children:[e.jsx(be,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(be,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:qo.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent/10 text-accent-light",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(be,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:Zs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:en.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Qs.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(be,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Yo.map(t=>e.jsxs("div",{className:"rounded-xl border border-violet-500/20 bg-violet-500/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-500/10 text-violet-400",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(be,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Go.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(qt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"mx-auto h-12 w-12 opacity-80"}),title:"Cloud is optional, not required",description:"You can stay fully local in standalone, and move to cloud later without changing how you use the dashboard.",action:e.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm no-underline",children:"Compare Cloud ↗"}),e.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(nr,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Jo(){const{ides:t}=it(),s=t.find(f=>f.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=$e(),{userName:a}=it(),[c,i]=o.useState(a||"");o.useEffect(()=>{a!==void 0&&i(a)},[a]);const h=f=>{const b=f.target.value.trim();s!=null&&s.id&&b!==a&&r(s.id,"set_user_name",{userName:b}).catch(console.error)},[l,x]=o.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(St,{icon:e.jsx(Ht,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(sa,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(be,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.7.33"]}),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(be,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(f=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(be,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(da,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(be,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(pa,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Theme"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose a preset or create a custom surface, accent, and chat palette for the standalone UI."}),e.jsx(ja,{})]})]})}),e.jsx(be,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(la,{}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(sr,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(be,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(qn,{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:f=>i(f.target.value),onBlur:h,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}ia();ba();const Zo=Is({baseUrl:""});function js(){const{ides:t}=it(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(bt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(bt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(bt,{to:"/dashboard",replace:!0})}function Qo(){return e.jsx(_n,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Fn,{client:Zo,children:e.jsx(Ho,{children:e.jsx(Un,{value:{sendCommand:kt,sendData:()=>!1},children:e.jsx(Vo,{children:e.jsxs($n,{children:[e.jsx(Ee,{path:"/dashboard",element:e.jsx(po,{})}),e.jsx(Ee,{path:"/ide/:id",element:e.jsx(wo,{})}),e.jsx(Ee,{path:"/machine",element:e.jsx(js,{})}),e.jsx(Ee,{path:"/machines/:id",element:e.jsx(_o,{})}),e.jsx(Ee,{path:"/machines",element:e.jsx(js,{})}),e.jsx(Ee,{path:"/capabilities",element:e.jsx($o,{})}),e.jsx(Ee,{path:"/about",element:e.jsx(Xo,{})}),e.jsx(Ee,{path:"/settings",element:e.jsx(Jo,{})}),e.jsx(Ee,{path:"*",element:e.jsx(bt,{to:"/dashboard",replace:!0})})]})})})})})})}Rr({connectionManager:Ae});Pn(document.getElementById("root")).render(e.jsx(o.StrictMode,{children:e.jsx(Qo,{})}));