@adhdev/daemon-standalone 0.7.14 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-SgUt8Azj.js","assets/vendor-tc3018Wt.js"])))=>i.map(i=>d[i]);
2
- var xn=Object.defineProperty;var hn=(t,s,n)=>s in t?xn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ue=(t,s,n)=>hn(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as ms,a as fs,b as pn,c as mn,u as it,t as fn,d as gn,e as bn,R as yn,f as gs,g as bs,h as jn,B as vn,i as wn,k as Ee,N as gt,l as Nn}from"./vendor-tc3018Wt.js";import{_ as kn}from"./terminal-SgUt8Azj.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const c of o)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(o){const c={};return o.integrity&&(c.integrity=o.integrity),o.referrerPolicy&&(c.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?c.credentials="include":o.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(o){if(o.ep)return;o.ep=!0;const c=n(o);fetch(o.href,c)}})();const ys=a.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}),js=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function qt(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.agentStreams)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Et(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},o=s.version??n.version??t.version,c=s.serverVersion??t.serverVersion??n.serverVersion,i=s.versionMismatch===!0||t.versionMismatch===!0;return o&&(r.version=o),c&&(r.serverVersion=c),o&&c&&o===c?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||i&&o&&c&&o!==c)&&(r.versionMismatch=!0),r)}function Sn(t,s){var i,u,l,x,d,p,g;const n=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:n}));const r=new Map;for(const f of s)r.set(f.id,f);for(const f of t){const j=r.get(f.id);if(!j){r.set(f.id,{...f,_lastUpdate:n});continue}const k=qt(f),I=qt(j);if(k>I){const h=(i=f.chats)!=null&&i.length?f.chats:j.chats,b=Et(j,f,{...j,...f,chats:h,_lastUpdate:n});r.set(f.id,b)}else if(k<I){const h={};if(f.status&&f.status!==j.status&&(h.status=f.status),f.cdpConnected!==void 0&&(h.cdpConnected=f.cdpConnected),(u=f.chats)!=null&&u.length&&!((l=j.chats)!=null&&l.length)&&(h.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==j.machineNickname&&(h.machineNickname=f.machineNickname),f.version!==void 0&&(h.version=f.version),f.serverVersion!==void 0&&(h.serverVersion=f.serverVersion),f.versionMismatch===!0&&(h.versionMismatch=!0),Object.keys(h).length>0){const b=Et(j,f,{...j,...h,_lastUpdate:j._lastUpdate});r.set(f.id,b)}}else{const h=f.timestamp||n,b=j._lastUpdate||j.timestamp||0;if(h>=b){const v=(x=f.chats)!=null&&x.length?f.chats:j.chats,T=Et(j,f,{...j,...f,chats:v,_lastUpdate:n});r.set(f.id,T)}else(d=f.chats)!=null&&d.length&&!((p=j.chats)!=null&&p.length)&&r.set(f.id,{...j,chats:f.chats})}}const o=new Set(t.map(f=>f.id)),c=new Set;for(const f of t){const j=f.daemonId||((g=f.id)==null?void 0:g.split(":")[0]);j&&c.add(j)}for(const[f,j]of r){const k=j.daemonId||f.split(":")[0];if(!c.has(k))continue;const I=n-(j._lastUpdate||j.timestamp||0);(j.transport==="pty"&&!o.has(f)&&I>1e4||j.transport==="acp"&&!o.has(f)&&I>1e4||j.transport==="cdp-page"&&!o.has(f)&&I>3e4)&&r.delete(f)}for(const[f,j]of r)n-(j._lastUpdate||j.timestamp||0)>3e5&&j.status!=="online"&&r.delete(f);return Array.from(r.values())}function Cn(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 In({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[o,c]=a.useState({}),[i,u]=a.useState(!1),[l,x]=a.useState([]),[d,p]=a.useState(void 0),g=a.useRef(n);a.useEffect(()=>{g.current=n},[n]);const f=a.useCallback((v,T)=>{r(m=>{let N=!1;const w=m.map(y=>y.id!==v||y.chats===T?y:(N=!0,{...y,chats:T}));return N?w:m})},[]),j=a.useCallback(v=>{r(T=>{const m=T.length===0?v:Sn(v,T);return Cn(T,m)?T:m})},[]),k=a.useCallback(()=>u(!0),[]),I=a.useMemo(()=>({injectEntries:j,markLoaded:k,getIdes:()=>g.current}),[j,k]),h=s,b=a.useMemo(()=>({ides:n,updateIdeChats:f,screenshotMap:o,setScreenshotMap:c,initialLoaded:i,toasts:l,setToasts:x,wsStatus:(h==null?void 0:h.wsStatus)??"connected",isConnected:(h==null?void 0:h.isConnected)??!0,connectionStates:(h==null?void 0:h.connectionStates)??{},connectionTransports:(h==null?void 0:h.connectionTransports)??{},showReconnected:(h==null?void 0:h.showReconnected)??!1,retryConnection:h==null?void 0:h.retryConnection,isP2PActive:(h==null?void 0:h.isP2PActive)??!1,p2pStates:(h==null?void 0:h.p2pStates)??{},userRole:h==null?void 0:h.userRole,userName:d,setUserName:p}),[n,f,o,i,l,h==null?void 0:h.wsStatus,h==null?void 0:h.isConnected,h==null?void 0:h.connectionStates,h==null?void 0:h.connectionTransports,h==null?void 0:h.showReconnected,h==null?void 0:h.retryConnection,h==null?void 0:h.isP2PActive,h==null?void 0:h.p2pStates,h==null?void 0:h.userRole,d]);return e.jsx(js.Provider,{value:I,children:e.jsx(ys.Provider,{value:b,children:t})})}function ot(){return a.useContext(ys)}function Xt(){return a.useContext(js)}function vs(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function o(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function c(u){const l=n==null?void 0:n(),x=o(u),d=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!u.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function i(u,l={}){const x={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const p=o(u),g=await fetch(p,{...l,headers:x});if(g.status===401)throw r==null||r(),new Error("Unauthorized");if(!g.ok){const f=await g.json().catch(()=>({error:g.statusText}));throw new Error(f.error||`API Error: ${g.status}`)}return g.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:u=>i(`/api/v1/daemons/${u}/status`),sendCommand:(u,l,x={})=>i(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),execTerminal:(u,l,x)=>i(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:x})}),sendAgentMessage:(u,l,x)=>i(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:x})}),getAgentStatus:u=>i(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,l,x)=>i(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:x?"approve":"reject"})}),getMuxState:u=>i(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>i(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,l,x={})=>i(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),getMuxEventsUrl:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeSnapshot:u=>i(`/api/v1/runtime/${encodeURIComponent(u)}/snapshot`),getRuntimeEventsUrl:u=>c(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:i}}const Mn=vs({baseUrl:"http://localhost:3847"}),ws=a.createContext(Mn);function Tn({client:t,children:s}){return e.jsx(ws.Provider,{value:t,children:s})}function En(){return a.useContext(ws)}const An={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ns=a.createContext(An);function Ln({value:t,children:s}){return e.jsx(Ns.Provider,{value:t,children:s})}function Pe(){return a.useContext(Ns)}const ce={size:18};function ks({size:t=ce.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 Ss({size:t=ce.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 Rn({size:t=ce.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 _n({size:t=ce.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 $n({size:t=ce.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 wt({size:t=ce.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 Pn({size:t=ce.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=ce.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 Cs({size:t=ce.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 Is({size:t=ce.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=ce.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 Re({size:t=ce.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 Ms({size:t=ce.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 Dn({size:t=ce.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 Pt({size:t=ce.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 Ts({size:t=ce.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=ce.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 qe({size:t=ce.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 Es({size:t=ce.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 As({size:t=ce.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 Bn({size:t=ce.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})}function Ft({size:t=ce.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 Ls({size:t=ce.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 Rs({size:t=ce.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 Wn({size:t=ce.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 On({size:t=ce.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 _s({size:t=ce.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 Kn({size:t=ce.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 zn({size:t=ce.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function Hn({size:t=ce.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 Un({size:t=ce.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 Fn(t){const n=t.split(`
3
- `).map(u=>{if(!u.includes("\r"))return u;const l=u.split("\r").map(p=>p.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(p=>p.startsWith("⏺"));if(x.length>0)return x[x.length-1];const d=l.filter(p=>!(/^[❯›>]\s*$/.test(p)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(p)&&p.length<40||/^[╭╰│├╮╯─═]+$/.test(p)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-5UKRXqR3.js","assets/vendor-tc3018Wt.js"])))=>i.map(i=>d[i]);
2
+ var xn=Object.defineProperty;var pn=(t,s,n)=>s in t?xn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ue=(t,s,n)=>pn(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as ms,a as fs,b as hn,c as mn,u as it,t as fn,d as gn,e as bn,R as yn,f as gs,g as bs,h as jn,B as vn,i as wn,k as Ee,N as gt,l as Nn}from"./vendor-tc3018Wt.js";import{_ as kn}from"./terminal-5UKRXqR3.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const c of o)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(o){const c={};return o.integrity&&(c.integrity=o.integrity),o.referrerPolicy&&(c.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?c.credentials="include":o.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(o){if(o.ep)return;o.ep=!0;const c=n(o);fetch(o.href,c)}})();const ys=a.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}),js=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Yt(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.agentStreams)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Et(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},o=s.version??n.version??t.version,c=s.serverVersion??t.serverVersion??n.serverVersion,i=s.versionMismatch===!0||t.versionMismatch===!0;return o&&(r.version=o),c&&(r.serverVersion=c),o&&c&&o===c?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||i&&o&&c&&o!==c)&&(r.versionMismatch=!0),r)}function Sn(t,s){var i,u,l,x,d,h,g;const n=Date.now();if(s.length===0)return t.map(m=>({...m,_lastUpdate:n}));const r=new Map;for(const m of s)r.set(m.id,m);for(const m of t){const b=r.get(m.id);if(!b){r.set(m.id,{...m,_lastUpdate:n});continue}const k=Yt(m),I=Yt(b);if(k>I){const p=(i=m.chats)!=null&&i.length?m.chats:b.chats,y=Et(b,m,{...b,...m,chats:p,_lastUpdate:n});r.set(m.id,y)}else if(k<I){const p={};if(m.status&&m.status!==b.status&&(p.status=m.status),m.cdpConnected!==void 0&&(p.cdpConnected=m.cdpConnected),(u=m.chats)!=null&&u.length&&!((l=b.chats)!=null&&l.length)&&(p.chats=m.chats),m.machineNickname!==void 0&&m.machineNickname!==b.machineNickname&&(p.machineNickname=m.machineNickname),m.version!==void 0&&(p.version=m.version),m.serverVersion!==void 0&&(p.serverVersion=m.serverVersion),m.versionMismatch===!0&&(p.versionMismatch=!0),Object.keys(p).length>0){const y=Et(b,m,{...b,...p,_lastUpdate:b._lastUpdate});r.set(m.id,y)}}else{const p=m.timestamp||n,y=b._lastUpdate||b.timestamp||0;if(p>=y){const v=(x=m.chats)!=null&&x.length?m.chats:b.chats,T=Et(b,m,{...b,...m,chats:v,_lastUpdate:n});r.set(m.id,T)}else(d=m.chats)!=null&&d.length&&!((h=b.chats)!=null&&h.length)&&r.set(m.id,{...b,chats:m.chats})}}const o=new Set(t.map(m=>m.id)),c=new Set;for(const m of t){const b=m.daemonId||((g=m.id)==null?void 0:g.split(":")[0]);b&&c.add(b)}for(const[m,b]of r){const k=b.daemonId||m.split(":")[0];if(!c.has(k))continue;const I=n-(b._lastUpdate||b.timestamp||0);(b.transport==="pty"&&!o.has(m)&&I>1e4||b.transport==="acp"&&!o.has(m)&&I>1e4||b.transport==="cdp-page"&&!o.has(m)&&I>3e4)&&r.delete(m)}for(const[m,b]of r)n-(b._lastUpdate||b.timestamp||0)>3e5&&b.status!=="online"&&r.delete(m);return Array.from(r.values())}function Cn(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 In({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[o,c]=a.useState({}),[i,u]=a.useState(!1),[l,x]=a.useState([]),[d,h]=a.useState(void 0),g=a.useRef(n);a.useEffect(()=>{g.current=n},[n]);const m=a.useCallback((v,T)=>{r(f=>{let N=!1;const w=f.map(j=>j.id!==v||j.chats===T?j:(N=!0,{...j,chats:T}));return N?w:f})},[]),b=a.useCallback(v=>{r(T=>{const f=T.length===0?v:Sn(v,T);return Cn(T,f)?T:f})},[]),k=a.useCallback(()=>u(!0),[]),I=a.useMemo(()=>({injectEntries:b,markLoaded:k,getIdes:()=>g.current}),[b,k]),p=s,y=a.useMemo(()=>({ides:n,updateIdeChats:m,screenshotMap:o,setScreenshotMap:c,initialLoaded:i,toasts:l,setToasts:x,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:d,setUserName:h}),[n,m,o,i,l,p==null?void 0:p.wsStatus,p==null?void 0:p.isConnected,p==null?void 0:p.connectionStates,p==null?void 0:p.connectionTransports,p==null?void 0:p.showReconnected,p==null?void 0:p.retryConnection,p==null?void 0:p.isP2PActive,p==null?void 0:p.p2pStates,p==null?void 0:p.userRole,d]);return e.jsx(js.Provider,{value:I,children:e.jsx(ys.Provider,{value:y,children:t})})}function ot(){return a.useContext(ys)}function Xt(){return a.useContext(js)}function vs(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function o(u){return u.startsWith("http")?u:`${s}${u.startsWith("/")?"":"/"}${u}`}function c(u){const l=n==null?void 0:n(),x=o(u),d=u.startsWith("http")?new URL(x):new URL(x,typeof window<"u"?window.location.origin:"http://localhost");return l&&d.searchParams.set("token",l),!u.startsWith("http")&&!s?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function i(u,l={}){const x={"Content-Type":"application/json",...l.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const h=o(u),g=await fetch(h,{...l,headers:x});if(g.status===401)throw r==null||r(),new Error("Unauthorized");if(!g.ok){const m=await g.json().catch(()=>({error:g.statusText}));throw new Error(m.error||`API Error: ${g.status}`)}return g.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:u=>i(`/api/v1/daemons/${u}/status`),sendCommand:(u,l,x={})=>i(`/api/v1/daemons/${u}/command`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),execTerminal:(u,l,x)=>i(`/api/v1/daemons/${u}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:x})}),sendAgentMessage:(u,l,x)=>i(`/api/v1/shortcuts/${u}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:x})}),getAgentStatus:u=>i(`/api/v1/shortcuts/${u}/status`),approveAgent:(u,l,x)=>i(`/api/v1/shortcuts/${u}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:x?"approve":"reject"})}),getMuxState:u=>i(`/api/v1/mux/${encodeURIComponent(u)}/state`),getMuxSocketInfo:u=>i(`/api/v1/mux/${encodeURIComponent(u)}/socket-info`),controlMux:(u,l,x={})=>i(`/api/v1/mux/${encodeURIComponent(u)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:x})}),getMuxEventsUrl:u=>c(`/api/v1/mux/${encodeURIComponent(u)}/events`),getRuntimeSnapshot:u=>i(`/api/v1/runtime/${encodeURIComponent(u)}/snapshot`),getRuntimeEventsUrl:u=>c(`/api/v1/runtime/${encodeURIComponent(u)}/events`),request:i}}const Mn=vs({baseUrl:"http://localhost:3847"}),ws=a.createContext(Mn);function Tn({client:t,children:s}){return e.jsx(ws.Provider,{value:t,children:s})}function En(){return a.useContext(ws)}const An={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ns=a.createContext(An);function Rn({value:t,children:s}){return e.jsx(Ns.Provider,{value:t,children:s})}function Pe(){return a.useContext(Ns)}const ce={size:18};function ks({size:t=ce.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 Ss({size:t=ce.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 Ln({size:t=ce.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 _n({size:t=ce.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 $n({size:t=ce.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 wt({size:t=ce.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 Pn({size:t=ce.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=ce.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 Cs({size:t=ce.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 Is({size:t=ce.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 qe({size:t=ce.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 Le({size:t=ce.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 Ms({size:t=ce.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 Dn({size:t=ce.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 Pt({size:t=ce.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 Ts({size:t=ce.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 Ft({size:t=ce.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 Ye({size:t=ce.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 Es({size:t=ce.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 As({size:t=ce.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 Bn({size:t=ce.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 Ut({size:t=ce.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 Rs({size:t=ce.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 Ls({size:t=ce.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 Wn({size:t=ce.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 On({size:t=ce.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 _s({size:t=ce.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 Kn({size:t=ce.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 zn({size:t=ce.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function Hn({size:t=ce.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function Fn({size:t=ce.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 Un(t){const n=t.split(`
3
+ `).map(u=>{if(!u.includes("\r"))return u;const l=u.split("\r").map(h=>h.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(h=>h.startsWith("⏺"));if(x.length>0)return x[x.length-1];const d=l.filter(h=>!(/^[❯›>]\s*$/.test(h)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(h)&&h.length<40||/^[╭╰│├╮╯─═]+$/.test(h)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
4
4
  `).split(`
5
- `),r={},o=[];let c=!1;for(const u of n){const l=u.trim();if(l===""){c=!1,o.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(u)){const d=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const p=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);p&&(r[p]=(r[p]||0)+1)}c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||c&&/^\s{2,}/.test(u))continue;c=!1;const x=u.replace(/^❯\s+/,"");o.push(x)}const i=o.join(`
5
+ `),r={},o=[];let c=!1;for(const u of n){const l=u.trim();if(l===""){c=!1,o.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(u)){const d=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const h=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);h&&(r[h]=(r[h]||0)+1)}c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||c&&/^\s{2,}/.test(u))continue;c=!1;const x=u.replace(/^❯\s+/,"");o.push(x)}const i=o.join(`
6
6
  `).replace(/\n{3,}/g,`
7
7
 
8
8
  `).trim();return{toolCounts:r,textContent:i,hasTools:Object.keys(r).length>0}}function Dt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Vn(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 Gt=700,Yn=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(ms,{remarkPlugins:[fs],children:s.text}),e.jsx("span",{className:"action-time",children:Dt(s.timestamp)})]})},(t,s)=>t.log===s.log),qn=a.memo(function({message:s,receivedAt:n,agentName:r,userName:o,isCliMode:c,isExpanded:i,isTextExpanded:u,onToggleExpanded:l,onToggleTextExpanded:x}){var T;const d=(s.role||"").toLowerCase(),p=d==="user"||d==="human",g=s.kind||(d==="tool"?"tool":"standard"),f=typeof s.content=="string"?s.content:(s.content||[]).map(m=>m.text||"").join(`
10
- `);if(g==="thought"){const m=((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(Wn,{size:13}),e.jsx("span",{children:m})]}),e.jsx("div",{className:"chat-msg-body",children:f})]})}if(g==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:f.split(`
11
- `)[0].slice(0,80)})]});if(g==="terminal"){const m=s.meta||{},N=m.isRunning?"⏳":"✅",w=m.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:N}),e.jsx("span",{children:w})]}),e.jsx("pre",{className:"chat-msg-body",children:f})]})}if(g==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:f.slice(0,100)});const j=!p&&c?Fn(f):null,k=j?j.textContent:f,I=j?Object.entries(j.toolCounts):[],h=c&&!p&&!i&&k.length>Gt,b=i?f:h&&!u?k.slice(0,Gt):k,v=Vn(b);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${p?"self-end":"self-start"}`,children:[I.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[I.map(([m,N])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",m,N>1?` ×${N}`:""]},m)),(j==null?void 0:j.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:i?"Collapse":"Original"}),!k&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Dt(n)})]}),(k||p)&&e.jsxs("div",{className:`chat-bubble ${p?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${k?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:p?o||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Dt(n)})]}),k&&e.jsx("div",{className:"chat-markdown",children:v?e.jsx(ms,{remarkPlugins:[fs,pn,mn],children:b}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:b})}),h&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:u?"Collapse ↑":`Show more (${Math.round(k.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),Xn=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:o,isCliMode:c=!1,isWorking:i=!1,contextKey:u="",receivedAtMap:l={},emptyState:x,onLoadMore:d,isLoadingMore:p,hasMoreHistory:g,hiddenLiveCount:f=0,loadError:j},k){var se;const I=a.useRef(null),h=a.useRef(null),b=a.useRef(0),v=a.useRef(""),T=a.useRef(!1),m=a.useRef(null),[N,w]=a.useState(new Set),[y,A]=a.useState(new Set),R=a.useRef(!1),D=()=>{const X=I.current;return X?X.scrollHeight-X.scrollTop-X.clientHeight<200:!0},L=a.useCallback((X="auto")=>{const te=I.current;te&&te.scrollTo({top:te.scrollHeight,behavior:X})},[]),S=a.useCallback((X="auto")=>{m.current!=null&&cancelAnimationFrame(m.current),m.current=requestAnimationFrame(()=>{m.current=null,L(X)})},[L]),P=s.length>0?`${s.length}:${(((se=s[s.length-1])==null?void 0:se.content)||"").length}`:"0:0";a.useEffect(()=>{const X=!T.current,te=v.current!==u;if(v.current=u,X||te){T.current=!0,R.current=!1,S("auto"),b.current=s.length;return}s.length>b.current?R.current||S("auto"):D()&&!R.current&&S("auto"),b.current=s.length},[P,u,i,s.length,S]),a.useEffect(()=>()=>{m.current!=null&&cancelAnimationFrame(m.current)},[]),a.useImperativeHandle(k,()=>({scrollToBottom:(X="smooth")=>{L(X)}}),[L]),a.useEffect(()=>{const X=I.current;if(!X)return;let te;const ee=()=>{clearTimeout(te),te=setTimeout(()=>{R.current=!D()},50)};return X.addEventListener("scroll",ee,{passive:!0}),()=>{X.removeEventListener("scroll",ee),clearTimeout(te)}},[]);const K=a.useRef(0),C=a.useRef(!1);a.useEffect(()=>{const X=I.current;if(!X||!C.current||K.current===0)return;const te=X.scrollHeight-K.current;te>0&&(X.scrollTop=te),K.current=0,C.current=!1},[s.length]);const H=()=>{const X=I.current;X&&(K.current=X.scrollHeight),C.current=!0,d==null||d()},Q=a.useMemo(()=>{const X=s.map((O,$)=>({type:"message",data:O,index:$,ts:O.receivedAt||l[Ve(O,$)]||0}));if(!n||n.length===0)return X;const te=[...n].sort((O,$)=>O.timestamp-$.timestamp).map((O,$)=>({type:"action",data:O,index:$,ts:O.timestamp})),ee=[];let oe=0;for(const O of X){for(;oe<te.length&&O.ts>0&&te[oe].ts<O.ts;)ee.push(te[oe++]);ee.push(O)}for(;oe<te.length;)ee.push(te[oe++]);return ee},[s,n,l]),J=f>0||!!g,G=f>0?`↑ Show ${Math.min(f,80)} earlier messages${f>80?` (${f} hidden)`:""}`:j?`↻ ${j}`:"↑ Load older messages";return e.jsxs("div",{ref:I,"data-chat-scroll":!0,className:"chat-container",children:[p&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),J&&!p&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:H,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${j&&f===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})}),Q.length===0&&!J&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Q.map(X=>{if(X.type==="action"){const B=X.data;return e.jsx(Yn,{log:B},`action-${X.index}`)}const te=X.data,ee=X.index,oe=Ve(te,ee),O=te.receivedAt||l[oe],$=`${u}-${oe}`,E=N.has($),_=y.has($);return e.jsx(qn,{message:te,receivedAt:O,agentName:r,userName:o,isCliMode:c,isExpanded:E,isTextExpanded:_,onToggleExpanded:()=>w(B=>{const F=new Set(B);return E?F.delete($):F.add($),F}),onToggleTextExpanded:()=>A(B=>{const F=new Set(B);return _?F.delete($):F.add($),F})},`msg-${oe}`)}),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:h})]})}),Gn=a.memo(Xn,(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),$s=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},o)=>{const c=a.useRef(null),[i,u]=a.useState(null);return a.useImperativeHandle(o,()=>({write:l=>{var x;return(x=c.current)==null?void 0:x.write(l)},clear:()=>{var l;return(l=c.current)==null?void 0:l.clear()},fit:()=>{var l;return(l=c.current)==null?void 0:l.fit()},bumpResize:()=>{var l;return(l=c.current)==null?void 0:l.bumpResize()}}),[]),a.useEffect(()=>{let l=!1;return kn(()=>import("./terminal-SgUt8Azj.js").then(x=>x.i),__vite__mapDeps([0,1])).then(x=>{l||u(()=>x.GhosttyTerminalView)}).catch(x=>{console.error("[CliTerminal] failed to load terminal renderer",x)}),()=>{l=!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"}})});$s.displayName="CliTerminal";function ut({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 Jt({value:t,max:s,label:n,color:r="#8b5cf6",detail:o,compact:c=!1}){const i=s>0?Math.min(Math.round(t/s*100),100):0,u=i>85?"#ef4444":i>60?"#f59e0b":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:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children: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, ${u}, ${u}cc)`}})}),o&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:o})]})}function Jn({cursorPos:t,viewportRef:s,imgRef:n}){var b;if(!t||!n.current)return null;const r=n.current,o=r.getBoundingClientRect(),c=(b=s.current)==null?void 0:b.getBoundingClientRect();if(!c)return null;const i=r.naturalWidth||o.width,u=r.naturalHeight||o.height,l=i/u,x=o.width/o.height;let d,p,g,f;l>x?(d=o.width,p=o.width/l,g=0,f=(o.height-p)/2):(p=o.height,d=o.height*l,g=(o.width-d)/2,f=0);const j=o.left-c.left+g+d*t.nx,k=o.top-c.top+f+p*t.ny,I=Math.max(8,Math.min(c.width-8,j)),h=Math.max(8,Math.min(c.height-8,k));return e.jsxs("div",{style:{position:"absolute",left:I-8,top:h-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 Zn({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:o,setIsMenuOpen:c,imeText:i,setImeText:u,handleImeSubmit:l,isConnActive:x,zoom:d,isMobile:p,mobileFillZoom:g,onZoomOut:f,onZoomReset:j,onZoomIn:k,transportType:I,screenshotUsage:h,lastActionStatus:b}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{r(v=>!v),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:v=>v.stopPropagation(),onChange:v=>u(v.target.value),onKeyDown:v=>{l(v)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{c(v=>!v),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${o?"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),"%"]}),I==="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"}),I==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),h&&h.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:h.budgetExhausted?"#ef4444":"#c4b5fd",background:h.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:h.budgetExhausted?"TURN blocked":`TURN ${h.dailyUsedMinutes}/${h.dailyBudgetMinutes}m`}),b&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:b})]})]}),o&&e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(p?g:1)+.01?p?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:v=>{v.stopPropagation(),f()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),j()},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:p?"FILL":"FIT"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),k()},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 Qn({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] text-amber-300/80",children:"TURN relay active"})]})}function er(){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 Zt(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 ct(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!er())return;r.current+=1;const o=n.current;if(!o){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([i,u])=>[i,Zt(u)]))}),n.current=s;return}const c=Object.keys({...o,...s}).filter(i=>!Object.is(o[i],s[i]));c.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:c,snapshot:Object.fromEntries(c.map(i=>[i,Zt(s[i])]))}),n.current=s})}function tr({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:o,minZoom:c,zoomRef:i,panXRef:u,panYRef:l,setPanX:x,setPanY:d,setZoom:p,lastWheelTimeRef:g,onAction:f,setLastActionStatus:j,spawnRippleFromNormalized:k,clampPan:I,isMobile:h,mobileFillZoom:b}){const[v,T]=a.useState(null),m=a.useRef(null),N=a.useRef(null),w=a.useRef(null),y=a.useRef(!1),A=a.useRef(null),R=a.useRef(0),D=a.useRef(null),L=a.useRef(1),S=a.useRef({x:0,y:0}),P=a.useRef(!1),K=a.useRef(r),C=a.useRef(f),H=()=>{if(m.current)return;const G={nx:.5,ny:.5};m.current=G,T(G)};return a.useEffect(()=>{K.current=r,r==="mouse"&&H()},[r]),a.useEffect(()=>{C.current=f},[f]),a.useEffect(()=>{const G=t.current;if(!G)return;const se=$=>{if(!n.current)return null;const E=n.current.getBoundingClientRect();return!E.width||!E.height?null:{nx:Math.max(0,Math.min(1,($.clientX-E.left)/E.width)),ny:Math.max(0,Math.min(1,($.clientY-E.top)/E.height))}},X=($,E)=>{if(!n.current)return{dnx:0,dny:0};const _=n.current,B=_.getBoundingClientRect(),F=_.naturalWidth||B.width,V=_.naturalHeight||B.height,re=F/V,le=B.width/B.height;let ie,de;return re>le?(ie=B.width,de=B.width/re):(de=B.height,ie=B.height*re),{dnx:$/ie,dny:E/de}},te=($,E,_)=>{if(_<=1.05)return;const B=-($-.5)*100,F=-(E-.5)*100,V=I(B,F,_);(Math.abs(V.x-u.current)>.1||Math.abs(V.y-l.current)>.1)&&(x(V.x),d(V.y),u.current=V.x,l.current=V.y)},ee=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target))$.preventDefault();else return;if($.touches.length===1){const _=$.touches[0];N.current={x:_.clientX,y:_.clientY,time:Date.now()},w.current={x:_.clientX,y:_.clientY},P.current||(y.current=!1),A.current=setTimeout(()=>{if(!y.current&&!P.current)if(y.current=!0,K.current==="mouse"){const B=m.current||{nx:.5,ny:.5};j("Right Click"),k(B.nx,B.ny,"right"),C.current("input_click",{...B,button:"right"}).catch(()=>{})}else{const B=se(_);B&&(j("Right Click"),k(B.nx,B.ny,"right"),C.current("input_click",{...B,button:"right"}).catch(()=>{}))}},500);return}if($.touches.length===2){A.current&&clearTimeout(A.current),y.current=!0,P.current=!0;const _=$.touches[1].clientX-$.touches[0].clientX,B=$.touches[1].clientY-$.touches[0].clientY;D.current=Math.sqrt(_*_+B*B),L.current=i.current,S.current={x:($.touches[0].clientX+$.touches[1].clientX)/2,y:($.touches[0].clientY+$.touches[1].clientY)/2}}},oe=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target)&&$.preventDefault(),$.touches.length===1&&w.current){const _=$.touches[0],B=_.clientX-w.current.x,F=_.clientY-w.current.y;if(!y.current&&N.current){const V=_.clientX-N.current.x,re=_.clientY-N.current.y;Math.sqrt(V*V+re*re)>8&&(y.current=!0,A.current&&clearTimeout(A.current))}if(y.current)if(K.current==="mouse"){const V=X(B,F),re=m.current||{nx:.5,ny:.5},le=Math.max(0,Math.min(1,re.nx+V.dnx)),ie=Math.max(0,Math.min(1,re.ny+V.dny));m.current={nx:le,ny:ie},T({nx:le,ny:ie}),j(`Cursor: ${Math.round(le*100)}%, ${Math.round(ie*100)}%`),te(le,ie,i.current);const de=Date.now();de-g.current>=30&&(g.current=de,C.current("input_mouseMoved",{nx:le,ny:ie}).catch(()=>{}))}else if(i.current>1){const V=s.current;if(V){const re=V.clientWidth,le=V.clientHeight,ie=u.current+B/re*100,de=l.current+F/le*100,W=I(ie,de,i.current);x(W.x),d(W.y),u.current=W.x,l.current=W.y}}else{const V=se(_);if(V){const re=Date.now();re-g.current>=40&&(g.current=re,j("Scroll"),C.current("input_wheel",{nx:V.nx,ny:V.ny,deltaX:Math.round(-B*2.5),deltaY:Math.round(-F*2.5)}).catch(()=>{}))}}w.current={x:_.clientX,y:_.clientY};return}if($.touches.length===2&&D.current!==null){const _=$.touches[1].clientX-$.touches[0].clientX,B=$.touches[1].clientY-$.touches[0].clientY,V=Math.sqrt(_*_+B*B)/D.current,re=($.touches[0].clientX+$.touches[1].clientX)/2,le=($.touches[0].clientY+$.touches[1].clientY)/2,ie=re-S.current.x,de=le-S.current.y,W=Math.abs(V-1)>.03;if(K.current==="mouse"){if(W){const q=Math.max(c,Math.min(5,L.current*V));p(q),i.current=q}else if(Math.abs(ie)>2||Math.abs(de)>2){const q=m.current||{nx:.5,ny:.5},U=Date.now();U-g.current>=30&&(g.current=U,j("Scroll"),C.current("input_wheel",{nx:q.nx,ny:q.ny,deltaX:Math.round(-ie*3),deltaY:Math.round(-de*3)}).catch(()=>{}))}}else{const q=Math.max(c,Math.min(5,L.current*V));p(q),i.current=q;const U=s.current;if(U&&q>1){const M=U.clientWidth,Y=U.clientHeight,z=u.current+ie/M*100,ne=l.current+de/Y*100,Z=I(z,ne,q);x(Z.x),d(Z.y),u.current=Z.x,l.current=Z.y}}S.current={x:re,y:le}}},O=$=>{var E;if(A.current&&clearTimeout(A.current),D.current=null,$.touches.length===1&&P.current){const _=$.touches[0];N.current={x:_.clientX,y:_.clientY,time:Date.now()},w.current={x:_.clientX,y:_.clientY},y.current=!0;return}if($.touches.length===0){if(P.current){P.current=!1,y.current=!1;return}if($.changedTouches.length===1&&!y.current){const _=$.changedTouches[0],B=Date.now(),F=B-(((E=N.current)==null?void 0:E.time)||0);if(F<60||F>400){y.current=!1;return}if(N.current){const V=_.clientX-N.current.x,re=_.clientY-N.current.y;if(Math.sqrt(V*V+re*re)>12){y.current=!1;return}}if(K.current==="mouse"){const V=m.current||se(_);V&&(j(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}))}else{const V=se(_);if(!V)return;B-R.current<300?(j("Double tap"),k(V.nx,V.ny,"double"),C.current("input_click",{...V,clickCount:2}).catch(()=>{}),R.current=0):(j(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}),R.current=B)}}y.current=!1}};return G.addEventListener("touchstart",ee,{passive:!1}),G.addEventListener("touchmove",oe,{passive:!1}),G.addEventListener("touchend",O,{passive:!1}),()=>{G.removeEventListener("touchstart",ee),G.removeEventListener("touchmove",oe),G.removeEventListener("touchend",O),A.current&&clearTimeout(A.current)}},[t,s,n,c,i,u,l,x,d,p,g,j,k,I]),{cursorPos:v,cursorPosRef:m,handleToggleInputMode:()=>{o(G=>{const se=G==="touch"?"mouse":"touch";return se==="mouse"&&H(),se})},handleZoomReset:()=>{const G=h?b:1;p(G),i.current=G,x(0),d(0),u.current=0,l.current=0}}}function sr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:o,transportType:c}){const i=a.useRef(null),u=a.useRef(null),l=a.useRef(null),[x,d]=a.useState(null),[p,g]=a.useState(""),[,f]=a.useState(!1),[j,k]=a.useState([]),I=a.useRef(0),[h,b]=a.useState(!1),[v,T]=a.useState(!1),m=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[N,w]=a.useState(m?"mouse":"touch"),[y,A]=a.useState(1),R=a.useRef(!1),[D,L]=a.useState(1),[S,P]=a.useState(0),[K,C]=a.useState(0);ct("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:N,zoom:D,panX:S,panY:K,isMenuOpen:h,isImeOpen:v});const H=a.useRef(0),Q=a.useRef(D),J=a.useRef(S),G=a.useRef(K);a.useEffect(()=>{Q.current=D},[D]),a.useEffect(()=>{J.current=S},[S]),a.useEffect(()=>{G.current=K},[K]),a.useEffect(()=>{var W;(W=i.current)==null||W.focus()},[]);const se=n==="connected",X=r,te=se?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=se?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!m||R.current||!X)return;const W=l.current,q=u.current;if(!W||!q)return;const U=()=>{const M=q.clientWidth,Y=q.clientHeight,z=W.naturalWidth,ne=W.naturalHeight;if(!z||!ne||!M||!Y)return;const Z=Math.min(M/z,Y/ne),ae=Math.max(M/z,Y/ne)/Z;ae>1.01&&(A(ae),L(ae),Q.current=ae),R.current=!0};W.complete&&W.naturalWidth?U():W.addEventListener("load",U,{once:!0})},[X,m]);const oe=.5;a.useEffect(()=>{D<=oe&&(P(0),C(0))},[D,oe]);const O=(W,q,U)=>{if(U<=oe)return{x:0,y:0};const M=(U-1)/(2*U)*100,Y=(U-1)/(2*U)*100;return{x:Math.max(-M,Math.min(M,W)),y:Math.max(-Y,Math.min(Y,q))}},$=(W,q)=>{if(!l.current)return null;const U=l.current.getBoundingClientRect();return!U.width||!U.height?null:{nx:Math.max(0,Math.min(1,(W-U.left)/U.width)),ny:Math.max(0,Math.min(1,(q-U.top)/U.height))}},E=(W,q,U)=>{const M=u.current;if(!M)return;const Y=M.getBoundingClientRect(),z=++I.current;k(ne=>[...ne,{id:z,x:W-Y.left,y:q-Y.top,type:U}]),setTimeout(()=>k(ne=>ne.filter(Z=>Z.id!==z)),600)},_=(W,q,U)=>{const M=l.current,Y=u.current;if(!M||!Y)return;const z=M.getBoundingClientRect(),ne=Y.getBoundingClientRect(),Z=M.naturalWidth||z.width,be=M.naturalHeight||z.height,ae=Z/be,Me=z.width/z.height;let Se,Ce,Ge,He;ae>Me?(Se=z.width,Ce=z.width/ae,Ge=0,He=(z.height-Ce)/2):(Ce=z.height,Se=z.height*ae,Ge=(z.width-Se)/2,He=0);const Ue=z.left-ne.left+Ge+Se*W,Mt=z.top-ne.top+He+Ce*q,lt=++I.current;k(Je=>[...Je,{id:lt,x:Ue,y:Mt,type:U}]),setTimeout(()=>k(Je=>Je.filter(Tt=>Tt.id!==lt)),600)},B=async W=>{var U;const q=$(W.clientX,W.clientY);if(q){d(`Click: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),E(W.clientX,W.clientY,"left"),(U=i.current)==null||U.focus();try{const M=await t("input_click",{nx:q.nx,ny:q.ny});M!=null&&M.success||s(`❌ Click failed: ${M==null?void 0:M.error}`)}catch(M){s(`❌ Click error: ${M.message||M}`)}}},F=async(W,q,U,M=0)=>{try{await t("input_key",{type:U?"char":"keyDown",key:W,code:q,text:U?W:void 0,unmodifiedText:U?W:void 0,modifiers:M})}catch(Y){s(`❌ Key error: ${Y.message||Y}`)}},V=async W=>{if(W.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(W.key)&&W.preventDefault();let U=0;W.altKey&&(U|=1),W.ctrlKey&&(U|=2),W.metaKey&&(U|=4),W.shiftKey&&(U|=8),d(`Key: ${W.key}`),await F(W.key,W.code,W.key.length===1,U)},re=async W=>{if(W.key==="Enter"){if(W.nativeEvent.isComposing)return;if(p){const q=p;g(""),d(`IME Sent: ${q}`);try{const U=await t("input_type",{text:q});U!=null&&U.success||s(`❌ IME error: ${U==null?void 0:U.error}`)}catch(U){s(`❌ IME error: ${U.message}`)}}else d("Key: Enter"),await F("Enter","Enter",!1)}};a.useEffect(()=>{const W=i.current;if(!W)return;const q=U=>{var M;if((M=l.current)!=null&&M.contains(U.target)){U.preventDefault();const Y=Date.now();if(Y-H.current<40)return;H.current=Y;const z=$(U.clientX,U.clientY);if(!z)return;d(`Scroll: ${Math.round(U.deltaY)}`),t("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(U.deltaX),deltaY:Math.round(U.deltaY)}).catch(()=>{})}};return W.addEventListener("wheel",q,{passive:!1}),()=>W.removeEventListener("wheel",q)},[t]);const{cursorPos:le,handleToggleInputMode:ie,handleZoomReset:de}=tr({containerRef:i,viewportRef:u,imgRef:l,inputMode:N,setInputMode:w,minZoom:oe,zoomRef:Q,panXRef:J,panYRef:G,setPanX:P,setPanY:C,setZoom:L,lastWheelTimeRef:H,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:_,clampPan:O,isMobile:m,mobileFillZoom:y});return e.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:V,onContextMenu:W=>W.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[X?e.jsx("img",{ref:l,src:X,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${D}) translate(${S}%, ${K}%)`,transformOrigin:"center center",cursor:N==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:B,onContextMenu:W=>W.preventDefault(),onDragStart:W=>W.preventDefault()}):e.jsx(Qn,{waitingLabel:te,waitingHint:ee,transportType:c}),N==="mouse"&&X&&e.jsx(Jn,{cursorPos:le,viewportRef:u,imgRef:l}),j.map(W=>{const U={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[W.type];return e.jsxs("div",{style:{position:"absolute",left:W.x,top:W.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${U}, 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(${U}, 0.9)`,boxShadow:`0 0 12px rgba(${U}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},W.id)})]}),e.jsx(Zn,{inputMode:N,onToggleInputMode:ie,isImeOpen:v,setIsImeOpen:T,isMenuOpen:h,setIsMenuOpen:b,imeText:p,setImeText:g,handleImeSubmit:re,isConnActive:se,zoom:D,isMobile:m,mobileFillZoom:y,onZoomOut:()=>L(W=>Math.max(.5,W-.25)),onZoomReset:de,onZoomIn:()=>L(W=>Math.min(5,W+.25)),transportType:c,screenshotUsage:o,lastActionStatus:x}),e.jsx("style",{children:`
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 Gt=700,qn=a.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(ms,{remarkPlugins:[fs],children:s.text}),e.jsx("span",{className:"action-time",children:Dt(s.timestamp)})]})},(t,s)=>t.log===s.log),Yn=a.memo(function({message:s,receivedAt:n,agentName:r,userName:o,isCliMode:c,isExpanded:i,isTextExpanded:u,onToggleExpanded:l,onToggleTextExpanded:x}){var T;const d=(s.role||"").toLowerCase(),h=d==="user"||d==="human",g=s.kind||(d==="tool"?"tool":"standard"),m=typeof s.content=="string"?s.content:(s.content||[]).map(f=>f.text||"").join(`
10
+ `);if(g==="thought"){const f=((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(Wn,{size:13}),e.jsx("span",{children:f})]}),e.jsx("div",{className:"chat-msg-body",children:m})]})}if(g==="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:m.split(`
11
+ `)[0].slice(0,80)})]});if(g==="terminal"){const f=s.meta||{},N=f.isRunning?"⏳":"✅",w=f.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:N}),e.jsx("span",{children:w})]}),e.jsx("pre",{className:"chat-msg-body",children:m})]})}if(g==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:m.slice(0,100)});const b=!h&&c?Un(m):null,k=b?b.textContent:m,I=b?Object.entries(b.toolCounts):[],p=c&&!h&&!i&&k.length>Gt,y=i?m:p&&!u?k.slice(0,Gt):k,v=Vn(y);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${h?"self-end":"self-start"}`,children:[I.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[I.map(([f,N])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",f,N>1?` ×${N}`:""]},f)),(b==null?void 0:b.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:i?"Collapse":"Original"}),!k&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Dt(n)})]}),(k||h)&&e.jsxs("div",{className:`chat-bubble ${h?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${k?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:h?o||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Dt(n)})]}),k&&e.jsx("div",{className:"chat-markdown",children:v?e.jsx(ms,{remarkPlugins:[fs,hn,mn],children:y}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:y})}),p&&e.jsx("button",{onClick:x,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:u?"Collapse ↑":`Show more (${Math.round(k.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),Xn=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:o,isCliMode:c=!1,isWorking:i=!1,contextKey:u="",receivedAtMap:l={},emptyState:x,onLoadMore:d,isLoadingMore:h,hasMoreHistory:g,hiddenLiveCount:m=0,loadError:b},k){var se;const I=a.useRef(null),p=a.useRef(null),y=a.useRef(0),v=a.useRef(""),T=a.useRef(!1),f=a.useRef(null),[N,w]=a.useState(new Set),[j,A]=a.useState(new Set),L=a.useRef(!1),D=()=>{const X=I.current;return X?X.scrollHeight-X.scrollTop-X.clientHeight<200:!0},R=a.useCallback((X="auto")=>{const te=I.current;te&&te.scrollTo({top:te.scrollHeight,behavior:X})},[]),S=a.useCallback((X="auto")=>{f.current!=null&&cancelAnimationFrame(f.current),f.current=requestAnimationFrame(()=>{f.current=null,R(X)})},[R]),P=s.length>0?`${s.length}:${(((se=s[s.length-1])==null?void 0:se.content)||"").length}`:"0:0";a.useEffect(()=>{const X=!T.current,te=v.current!==u;if(v.current=u,X||te){T.current=!0,L.current=!1,S("auto"),y.current=s.length;return}s.length>y.current?L.current||S("auto"):D()&&!L.current&&S("auto"),y.current=s.length},[P,u,i,s.length,S]),a.useEffect(()=>()=>{f.current!=null&&cancelAnimationFrame(f.current)},[]),a.useImperativeHandle(k,()=>({scrollToBottom:(X="smooth")=>{R(X)}}),[R]),a.useEffect(()=>{const X=I.current;if(!X)return;let te;const ee=()=>{clearTimeout(te),te=setTimeout(()=>{L.current=!D()},50)};return X.addEventListener("scroll",ee,{passive:!0}),()=>{X.removeEventListener("scroll",ee),clearTimeout(te)}},[]);const K=a.useRef(0),C=a.useRef(!1);a.useEffect(()=>{const X=I.current;if(!X||!C.current||K.current===0)return;const te=X.scrollHeight-K.current;te>0&&(X.scrollTop=te),K.current=0,C.current=!1},[s.length]);const H=()=>{const X=I.current;X&&(K.current=X.scrollHeight),C.current=!0,d==null||d()},Q=a.useMemo(()=>{const X=s.map((O,$)=>({type:"message",data:O,index:$,ts:O.receivedAt||l[Ve(O,$)]||0}));if(!n||n.length===0)return X;const te=[...n].sort((O,$)=>O.timestamp-$.timestamp).map((O,$)=>({type:"action",data:O,index:$,ts:O.timestamp})),ee=[];let oe=0;for(const O of X){for(;oe<te.length&&O.ts>0&&te[oe].ts<O.ts;)ee.push(te[oe++]);ee.push(O)}for(;oe<te.length;)ee.push(te[oe++]);return ee},[s,n,l]),J=m>0||!!g,G=m>0?`↑ Show ${Math.min(m,80)} earlier messages${m>80?` (${m} hidden)`:""}`:b?`↻ ${b}`:"↑ Load older messages";return e.jsxs("div",{ref:I,"data-chat-scroll":!0,className:"chat-container",children:[h&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),J&&!h&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:H,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${b&&m===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})}),Q.length===0&&!J&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Q.map(X=>{if(X.type==="action"){const B=X.data;return e.jsx(qn,{log:B},`action-${X.index}`)}const te=X.data,ee=X.index,oe=Ve(te,ee),O=te.receivedAt||l[oe],$=`${u}-${oe}`,E=N.has($),_=j.has($);return e.jsx(Yn,{message:te,receivedAt:O,agentName:r,userName:o,isCliMode:c,isExpanded:E,isTextExpanded:_,onToggleExpanded:()=>w(B=>{const U=new Set(B);return E?U.delete($):U.add($),U}),onToggleTextExpanded:()=>A(B=>{const U=new Set(B);return _?U.delete($):U.add($),U})},`msg-${oe}`)}),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:p})]})}),Gn=a.memo(Xn,(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),$s=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},o)=>{const c=a.useRef(null),[i,u]=a.useState(null),l=a.useRef([]),x=a.useRef(!1),d=a.useRef(!1),h=a.useRef(!1),g=()=>{const m=c.current;if(m){x.current&&(m.clear(),x.current=!1);for(const b of l.current)m.write(b);l.current=[],d.current&&(m.fit(),d.current=!1),h.current&&(m.bumpResize(),h.current=!1)}};return a.useImperativeHandle(o,()=>({write:m=>{c.current?c.current.write(m):l.current.push(m)},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():h.current=!0}}),[]),a.useEffect(()=>{if(!i)return;const m=requestAnimationFrame(()=>{var b;g(),(b=c.current)==null||b.fit()});return()=>cancelAnimationFrame(m)},[i]),a.useEffect(()=>{let m=!1;return kn(()=>import("./terminal-5UKRXqR3.js").then(b=>b.i),__vite__mapDeps([0,1])).then(b=>{m||u(()=>b.GhosttyTerminalView)}).catch(b=>{console.error("[CliTerminal] failed to load terminal renderer",b)}),()=>{m=!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"}})});$s.displayName="CliTerminal";function ut({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 Jt({value:t,max:s,label:n,color:r="#8b5cf6",detail:o,compact:c=!1}){const i=s>0?Math.min(Math.round(t/s*100),100):0,u=i>85?"#ef4444":i>60?"#f59e0b":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:u}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children: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, ${u}, ${u}cc)`}})}),o&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:o})]})}function Jn({cursorPos:t,viewportRef:s,imgRef:n}){var y;if(!t||!n.current)return null;const r=n.current,o=r.getBoundingClientRect(),c=(y=s.current)==null?void 0:y.getBoundingClientRect();if(!c)return null;const i=r.naturalWidth||o.width,u=r.naturalHeight||o.height,l=i/u,x=o.width/o.height;let d,h,g,m;l>x?(d=o.width,h=o.width/l,g=0,m=(o.height-h)/2):(h=o.height,d=o.height*l,g=(o.width-d)/2,m=0);const b=o.left-c.left+g+d*t.nx,k=o.top-c.top+m+h*t.ny,I=Math.max(8,Math.min(c.width-8,b)),p=Math.max(8,Math.min(c.height-8,k));return e.jsxs("div",{style:{position:"absolute",left:I-8,top:p-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 Zn({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:o,setIsMenuOpen:c,imeText:i,setImeText:u,handleImeSubmit:l,isConnActive:x,zoom:d,isMobile:h,mobileFillZoom:g,onZoomOut:m,onZoomReset:b,onZoomIn:k,transportType:I,screenshotUsage:p,lastActionStatus:y}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:s,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${t==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:t==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${t==="mouse"?"text-blue-400":"text-slate-400"}`,children:t==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{r(v=>!v),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:v=>v.stopPropagation(),onChange:v=>u(v.target.value),onKeyDown:v=>{l(v)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{c(v=>!v),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${o?"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),"%"]}),I==="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"}),I==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),p&&p.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:p.budgetExhausted?"#ef4444":"#c4b5fd",background:p.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:p.budgetExhausted?"TURN blocked":`TURN ${p.dailyUsedMinutes}/${p.dailyBudgetMinutes}m`}),y&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:y})]})]}),o&&e.jsxs("div",{onTouchStart:v=>v.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(h?g:1)+.01?h?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:v=>{v.stopPropagation(),m()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),b()},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:h?"FILL":"FIT"}),e.jsx("button",{onClick:v=>{v.stopPropagation(),k()},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 Qn({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] text-amber-300/80",children:"TURN relay active"})]})}function er(){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 Zt(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 ct(t,s){const n=a.useRef(null),r=a.useRef(0);a.useEffect(()=>{if(!er())return;r.current+=1;const o=n.current;if(!o){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([i,u])=>[i,Zt(u)]))}),n.current=s;return}const c=Object.keys({...o,...s}).filter(i=>!Object.is(o[i],s[i]));c.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:c,snapshot:Object.fromEntries(c.map(i=>[i,Zt(s[i])]))}),n.current=s})}function tr({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:o,minZoom:c,zoomRef:i,panXRef:u,panYRef:l,setPanX:x,setPanY:d,setZoom:h,lastWheelTimeRef:g,onAction:m,setLastActionStatus:b,spawnRippleFromNormalized:k,clampPan:I,isMobile:p,mobileFillZoom:y}){const[v,T]=a.useState(null),f=a.useRef(null),N=a.useRef(null),w=a.useRef(null),j=a.useRef(!1),A=a.useRef(null),L=a.useRef(0),D=a.useRef(null),R=a.useRef(1),S=a.useRef({x:0,y:0}),P=a.useRef(!1),K=a.useRef(r),C=a.useRef(m),H=()=>{if(f.current)return;const G={nx:.5,ny:.5};f.current=G,T(G)};return a.useEffect(()=>{K.current=r,r==="mouse"&&H()},[r]),a.useEffect(()=>{C.current=m},[m]),a.useEffect(()=>{const G=t.current;if(!G)return;const se=$=>{if(!n.current)return null;const E=n.current.getBoundingClientRect();return!E.width||!E.height?null:{nx:Math.max(0,Math.min(1,($.clientX-E.left)/E.width)),ny:Math.max(0,Math.min(1,($.clientY-E.top)/E.height))}},X=($,E)=>{if(!n.current)return{dnx:0,dny:0};const _=n.current,B=_.getBoundingClientRect(),U=_.naturalWidth||B.width,V=_.naturalHeight||B.height,re=U/V,le=B.width/B.height;let ie,de;return re>le?(ie=B.width,de=B.width/re):(de=B.height,ie=B.height*re),{dnx:$/ie,dny:E/de}},te=($,E,_)=>{if(_<=1.05)return;const B=-($-.5)*100,U=-(E-.5)*100,V=I(B,U,_);(Math.abs(V.x-u.current)>.1||Math.abs(V.y-l.current)>.1)&&(x(V.x),d(V.y),u.current=V.x,l.current=V.y)},ee=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target))$.preventDefault();else return;if($.touches.length===1){const _=$.touches[0];N.current={x:_.clientX,y:_.clientY,time:Date.now()},w.current={x:_.clientX,y:_.clientY},P.current||(j.current=!1),A.current=setTimeout(()=>{if(!j.current&&!P.current)if(j.current=!0,K.current==="mouse"){const B=f.current||{nx:.5,ny:.5};b("Right Click"),k(B.nx,B.ny,"right"),C.current("input_click",{...B,button:"right"}).catch(()=>{})}else{const B=se(_);B&&(b("Right Click"),k(B.nx,B.ny,"right"),C.current("input_click",{...B,button:"right"}).catch(()=>{}))}},500);return}if($.touches.length===2){A.current&&clearTimeout(A.current),j.current=!0,P.current=!0;const _=$.touches[1].clientX-$.touches[0].clientX,B=$.touches[1].clientY-$.touches[0].clientY;D.current=Math.sqrt(_*_+B*B),R.current=i.current,S.current={x:($.touches[0].clientX+$.touches[1].clientX)/2,y:($.touches[0].clientY+$.touches[1].clientY)/2}}},oe=$=>{const E=s.current;if(E&&$.target instanceof Node&&E.contains($.target)&&$.preventDefault(),$.touches.length===1&&w.current){const _=$.touches[0],B=_.clientX-w.current.x,U=_.clientY-w.current.y;if(!j.current&&N.current){const V=_.clientX-N.current.x,re=_.clientY-N.current.y;Math.sqrt(V*V+re*re)>8&&(j.current=!0,A.current&&clearTimeout(A.current))}if(j.current)if(K.current==="mouse"){const V=X(B,U),re=f.current||{nx:.5,ny:.5},le=Math.max(0,Math.min(1,re.nx+V.dnx)),ie=Math.max(0,Math.min(1,re.ny+V.dny));f.current={nx:le,ny:ie},T({nx:le,ny:ie}),b(`Cursor: ${Math.round(le*100)}%, ${Math.round(ie*100)}%`),te(le,ie,i.current);const de=Date.now();de-g.current>=30&&(g.current=de,C.current("input_mouseMoved",{nx:le,ny:ie}).catch(()=>{}))}else if(i.current>1){const V=s.current;if(V){const re=V.clientWidth,le=V.clientHeight,ie=u.current+B/re*100,de=l.current+U/le*100,W=I(ie,de,i.current);x(W.x),d(W.y),u.current=W.x,l.current=W.y}}else{const V=se(_);if(V){const re=Date.now();re-g.current>=40&&(g.current=re,b("Scroll"),C.current("input_wheel",{nx:V.nx,ny:V.ny,deltaX:Math.round(-B*2.5),deltaY:Math.round(-U*2.5)}).catch(()=>{}))}}w.current={x:_.clientX,y:_.clientY};return}if($.touches.length===2&&D.current!==null){const _=$.touches[1].clientX-$.touches[0].clientX,B=$.touches[1].clientY-$.touches[0].clientY,V=Math.sqrt(_*_+B*B)/D.current,re=($.touches[0].clientX+$.touches[1].clientX)/2,le=($.touches[0].clientY+$.touches[1].clientY)/2,ie=re-S.current.x,de=le-S.current.y,W=Math.abs(V-1)>.03;if(K.current==="mouse"){if(W){const Y=Math.max(c,Math.min(5,R.current*V));h(Y),i.current=Y}else if(Math.abs(ie)>2||Math.abs(de)>2){const Y=f.current||{nx:.5,ny:.5},F=Date.now();F-g.current>=30&&(g.current=F,b("Scroll"),C.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-ie*3),deltaY:Math.round(-de*3)}).catch(()=>{}))}}else{const Y=Math.max(c,Math.min(5,R.current*V));h(Y),i.current=Y;const F=s.current;if(F&&Y>1){const M=F.clientWidth,q=F.clientHeight,z=u.current+ie/M*100,ne=l.current+de/q*100,Z=I(z,ne,Y);x(Z.x),d(Z.y),u.current=Z.x,l.current=Z.y}}S.current={x:re,y:le}}},O=$=>{var E;if(A.current&&clearTimeout(A.current),D.current=null,$.touches.length===1&&P.current){const _=$.touches[0];N.current={x:_.clientX,y:_.clientY,time:Date.now()},w.current={x:_.clientX,y:_.clientY},j.current=!0;return}if($.touches.length===0){if(P.current){P.current=!1,j.current=!1;return}if($.changedTouches.length===1&&!j.current){const _=$.changedTouches[0],B=Date.now(),U=B-(((E=N.current)==null?void 0:E.time)||0);if(U<60||U>400){j.current=!1;return}if(N.current){const V=_.clientX-N.current.x,re=_.clientY-N.current.y;if(Math.sqrt(V*V+re*re)>12){j.current=!1;return}}if(K.current==="mouse"){const V=f.current||se(_);V&&(b(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}))}else{const V=se(_);if(!V)return;B-L.current<300?(b("Double tap"),k(V.nx,V.ny,"double"),C.current("input_click",{...V,clickCount:2}).catch(()=>{}),L.current=0):(b(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),k(V.nx,V.ny,"left"),C.current("input_click",{...V}).catch(()=>{}),L.current=B)}}j.current=!1}};return G.addEventListener("touchstart",ee,{passive:!1}),G.addEventListener("touchmove",oe,{passive:!1}),G.addEventListener("touchend",O,{passive:!1}),()=>{G.removeEventListener("touchstart",ee),G.removeEventListener("touchmove",oe),G.removeEventListener("touchend",O),A.current&&clearTimeout(A.current)}},[t,s,n,c,i,u,l,x,d,h,g,b,k,I]),{cursorPos:v,cursorPosRef:f,handleToggleInputMode:()=>{o(G=>{const se=G==="touch"?"mouse":"touch";return se==="mouse"&&H(),se})},handleZoomReset:()=>{const G=p?y:1;h(G),i.current=G,x(0),d(0),u.current=0,l.current=0}}}function sr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:o,transportType:c}){const i=a.useRef(null),u=a.useRef(null),l=a.useRef(null),[x,d]=a.useState(null),[h,g]=a.useState(""),[,m]=a.useState(!1),[b,k]=a.useState([]),I=a.useRef(0),[p,y]=a.useState(!1),[v,T]=a.useState(!1),f=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[N,w]=a.useState(f?"mouse":"touch"),[j,A]=a.useState(1),L=a.useRef(!1),[D,R]=a.useState(1),[S,P]=a.useState(0),[K,C]=a.useState(0);ct("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:N,zoom:D,panX:S,panY:K,isMenuOpen:p,isImeOpen:v});const H=a.useRef(0),Q=a.useRef(D),J=a.useRef(S),G=a.useRef(K);a.useEffect(()=>{Q.current=D},[D]),a.useEffect(()=>{J.current=S},[S]),a.useEffect(()=>{G.current=K},[K]),a.useEffect(()=>{var W;(W=i.current)==null||W.focus()},[]);const se=n==="connected",X=r,te=se?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=se?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!f||L.current||!X)return;const W=l.current,Y=u.current;if(!W||!Y)return;const F=()=>{const M=Y.clientWidth,q=Y.clientHeight,z=W.naturalWidth,ne=W.naturalHeight;if(!z||!ne||!M||!q)return;const Z=Math.min(M/z,q/ne),ae=Math.max(M/z,q/ne)/Z;ae>1.01&&(A(ae),R(ae),Q.current=ae),L.current=!0};W.complete&&W.naturalWidth?F():W.addEventListener("load",F,{once:!0})},[X,f]);const oe=.5;a.useEffect(()=>{D<=oe&&(P(0),C(0))},[D,oe]);const O=(W,Y,F)=>{if(F<=oe)return{x:0,y:0};const M=(F-1)/(2*F)*100,q=(F-1)/(2*F)*100;return{x:Math.max(-M,Math.min(M,W)),y:Math.max(-q,Math.min(q,Y))}},$=(W,Y)=>{if(!l.current)return null;const F=l.current.getBoundingClientRect();return!F.width||!F.height?null:{nx:Math.max(0,Math.min(1,(W-F.left)/F.width)),ny:Math.max(0,Math.min(1,(Y-F.top)/F.height))}},E=(W,Y,F)=>{const M=u.current;if(!M)return;const q=M.getBoundingClientRect(),z=++I.current;k(ne=>[...ne,{id:z,x:W-q.left,y:Y-q.top,type:F}]),setTimeout(()=>k(ne=>ne.filter(Z=>Z.id!==z)),600)},_=(W,Y,F)=>{const M=l.current,q=u.current;if(!M||!q)return;const z=M.getBoundingClientRect(),ne=q.getBoundingClientRect(),Z=M.naturalWidth||z.width,be=M.naturalHeight||z.height,ae=Z/be,Me=z.width/z.height;let Se,Ce,Ge,He;ae>Me?(Se=z.width,Ce=z.width/ae,Ge=0,He=(z.height-Ce)/2):(Ce=z.height,Se=z.height*ae,Ge=(z.width-Se)/2,He=0);const Fe=z.left-ne.left+Ge+Se*W,Mt=z.top-ne.top+He+Ce*Y,lt=++I.current;k(Je=>[...Je,{id:lt,x:Fe,y:Mt,type:F}]),setTimeout(()=>k(Je=>Je.filter(Tt=>Tt.id!==lt)),600)},B=async W=>{var F;const Y=$(W.clientX,W.clientY);if(Y){d(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),E(W.clientX,W.clientY,"left"),(F=i.current)==null||F.focus();try{const M=await t("input_click",{nx:Y.nx,ny:Y.ny});M!=null&&M.success||s(`❌ Click failed: ${M==null?void 0:M.error}`)}catch(M){s(`❌ Click error: ${M.message||M}`)}}},U=async(W,Y,F,M=0)=>{try{await t("input_key",{type:F?"char":"keyDown",key:W,code:Y,text:F?W:void 0,unmodifiedText:F?W:void 0,modifiers:M})}catch(q){s(`❌ Key error: ${q.message||q}`)}},V=async W=>{if(W.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(W.key)&&W.preventDefault();let F=0;W.altKey&&(F|=1),W.ctrlKey&&(F|=2),W.metaKey&&(F|=4),W.shiftKey&&(F|=8),d(`Key: ${W.key}`),await U(W.key,W.code,W.key.length===1,F)},re=async W=>{if(W.key==="Enter"){if(W.nativeEvent.isComposing)return;if(h){const Y=h;g(""),d(`IME Sent: ${Y}`);try{const F=await t("input_type",{text:Y});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)}};a.useEffect(()=>{const W=i.current;if(!W)return;const Y=F=>{var M;if((M=l.current)!=null&&M.contains(F.target)){F.preventDefault();const q=Date.now();if(q-H.current<40)return;H.current=q;const z=$(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 W.addEventListener("wheel",Y,{passive:!1}),()=>W.removeEventListener("wheel",Y)},[t]);const{cursorPos:le,handleToggleInputMode:ie,handleZoomReset:de}=tr({containerRef:i,viewportRef:u,imgRef:l,inputMode:N,setInputMode:w,minZoom:oe,zoomRef:Q,panXRef:J,panYRef:G,setPanX:P,setPanY:C,setZoom:R,lastWheelTimeRef:H,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:_,clampPan:O,isMobile:f,mobileFillZoom:j});return e.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:V,onContextMenu:W=>W.preventDefault(),onFocus:()=>m(!0),onBlur:()=>m(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[X?e.jsx("img",{ref:l,src:X,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${D}) translate(${S}%, ${K}%)`,transformOrigin:"center center",cursor:N==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:B,onContextMenu:W=>W.preventDefault(),onDragStart:W=>W.preventDefault()}):e.jsx(Qn,{waitingLabel:te,waitingHint:ee,transportType:c}),N==="mouse"&&X&&e.jsx(Jn,{cursorPos:le,viewportRef:u,imgRef:l}),b.map(W=>{const F={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[W.type];return e.jsxs("div",{style:{position:"absolute",left:W.x,top:W.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${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}})]},W.id)})]}),e.jsx(Zn,{inputMode:N,onToggleInputMode:ie,isImeOpen:v,setIsImeOpen:T,isMenuOpen:p,setIsMenuOpen:y,imeText:h,setImeText:g,handleImeSubmit:re,isConnActive:se,zoom:D,isMobile:f,mobileFillZoom:j,onZoomOut:()=>R(W=>Math.max(.5,W-.25)),onZoomReset:de,onZoomIn:()=>R(W=>Math.min(5,W+.25)),transportType:c,screenshotUsage:o,lastActionStatus:x}),e.jsx("style",{children:`
12
12
  @keyframes slideUp {
13
13
  from { opacity: 0; transform: translateY(6px); }
14
14
  to { opacity: 1; transform: translateY(0); }
@@ -31,38 +31,38 @@ var xn=Object.defineProperty;var hn=(t,s,n)=>s in t?xn(t,s,{enumerable:!0,config
31
31
  50% { transform: translateY(-7px); }
32
32
  100% { transform: translateY(0px); }
33
33
  }
34
- `})]})}function nr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:o,onDismiss:c,onClickAt:i,onKeyDown:u,badge:l,emptyMessage:x,aspectRatio:d,className:p,style:g}){const f=a.useRef(null),j=a.useCallback(k=>{if(!r||!i||!f.current)return;const I=f.current,h=I.getBoundingClientRect(),b=(k.clientX-h.left)/h.width*I.naturalWidth,v=(k.clientY-h.top)/h.height*I.naturalHeight;i(b,v,I.naturalWidth,I.naturalHeight)},[r,i]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${p||""}`,style:{aspectRatio:d||"16/9",...g},children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),c&&e.jsx("button",{onClick:c,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${r?"screenshot-interactive":""} ${p||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?u:void 0,style:g,children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",onClick:r?j: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 ${p||""}`,style:g,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..."}),o&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",o]}),e.jsx("style",{children:`
34
+ `})]})}function nr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:o,onDismiss:c,onClickAt:i,onKeyDown:u,badge:l,emptyMessage:x,aspectRatio:d,className:h,style:g}){const m=a.useRef(null),b=a.useCallback(k=>{if(!r||!i||!m.current)return;const I=m.current,p=I.getBoundingClientRect(),y=(k.clientX-p.left)/p.width*I.naturalWidth,v=(k.clientY-p.top)/p.height*I.naturalHeight;i(y,v,I.naturalWidth,I.naturalHeight)},[r,i]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${h||""}`,style:{aspectRatio:d||"16/9",...g},children:[e.jsx("img",{ref:m,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":""} ${h||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?u:void 0,style:g,children:[e.jsx("img",{ref:m,src:t,alt:"IDE Screenshot",onClick:r?b: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 ${h||""}`,style:g,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..."}),o&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",o]}),e.jsx("style",{children:`
35
35
  @keyframes remote-float {
36
36
  0% { transform: translateY(0px); }
37
37
  50% { transform: translateY(-7px); }
38
38
  100% { transform: translateY(0px); }
39
39
  }
40
- `})]})}function Ps({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const o=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:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Ut,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((i,u)=>{const l=c(i).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),p=n===i,g=n!==null;return e.jsx("button",{onClick:()=>o(i),disabled:g,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${g&&!p?"opacity-40":"opacity-100"} ${g?"cursor-not-allowed":"cursor-pointer"}`,children:p?"⏳ ...":c(i)},u)})})]})]})}const we=new Map;function rr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:o,serverModel:c,serverMode:i,acpConfigOptions:u,acpModes:l}){var oe;const{sendCommand:x}=Pe(),d=!!(u||l),p=`${t}:${s||r}`,g=we.get(p),[f,j]=a.useState(!1),[k,I]=a.useState(!1),[h,b]=a.useState((g==null?void 0:g.models)||[]),[v,T]=a.useState((g==null?void 0:g.modes)||[]),m=O=>O?typeof O=="string"?O:typeof O=="object"?O.name||O.id||JSON.stringify(O):String(O):"",[N,w]=a.useState(m(c)),[y,A]=a.useState(m(i)),[R,D]=a.useState(!1),[L,S]=a.useState(!1),P=a.useRef(0),K=O=>O.map($=>typeof $=="string"?$:($==null?void 0:$.name)||($==null?void 0:$.id)||String($));a.useEffect(()=>{if(u){const O=u.find($=>$.category==="model");if(O){const $=K(O.options.map(_=>_.value));b($),O.currentValue&&w(m(O.currentValue));const E=we.get(p)||{models:[],modes:[]};we.set(p,{...E,models:$})}}if(l&&l.length>0){const O=K(l.map(E=>E.id));T(O);const $=we.get(p)||{models:[],modes:[]};we.set(p,{...$,modes:O})}else if(u){const O=u.find($=>$.category!=="model");if(O){const $=K(O.options.map(_=>_.value));T($),O.currentValue&&A(m(O.currentValue));const E=we.get(p)||{models:[],modes:[]};we.set(p,{...E,modes:$})}}},[u,l,p]),a.useEffect(()=>{j(!1),I(!1),w(m(c)),A(m(i));const O=we.get(p);O?(b(O.models),T(O.modes)):(b([]),T([]))},[t,r,s]),a.useEffect(()=>{c&&Date.now()>P.current&&w(m(c))},[c]),a.useEffect(()=>{i&&Date.now()>P.current&&A(m(i))},[i]);const C=a.useCallback(async(O,$={})=>{const E={...$,...s&&{targetSessionId:s}};return await x(t,O,E)},[t,s,x]),H=async()=>{var O,$;if(h.length>0){j(!f);return}if(d){j(!0);return}D(!0);try{const E=await C("list_extension_models",{agentType:r,ideType:n}),_=(E==null?void 0:E.models)||((O=E==null?void 0:E.result)==null?void 0:O.models)||[],B=K(_);b(B),E!=null&&E.current&&w(m(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&w(m(E.result.current));const F=we.get(p)||{models:[],modes:[]};we.set(p,{...F,models:B}),j(!0)}catch{}finally{D(!1)}},Q=async()=>{var O,$;if(v.length>0){I(!k);return}if(d){I(!0);return}S(!0);try{const E=await C("list_extension_modes",{agentType:r,ideType:n}),_=(E==null?void 0:E.modes)||((O=E==null?void 0:E.result)==null?void 0:O.modes)||[],B=K(_);T(B),E!=null&&E.current&&A(m(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&A(m(E.result.current));const F=we.get(p)||{models:[],modes:[]};we.set(p,{...F,modes:B}),I(!0)}catch{}finally{S(!1)}},J=async O=>{j(!1),w(O),P.current=Date.now()+5e3;try{d?await C("change_model",{agentType:r,ideType:n,model:O}):await C("set_extension_model",{agentType:r,ideType:n,model:O})}catch{}},G=d&&!(l&&l.length>0)&&(u==null?void 0:u.some(O=>O.category!=="model")),se=G?(oe=u==null?void 0:u.find(O=>O.category!=="model"))==null?void 0:oe.configId:void 0,X=async O=>{I(!1),A(O),P.current=Date.now()+5e3;try{d&&G&&se?await C("set_thought_level",{agentType:r,ideType:n,configId:se,value:O}):d?await C("set_mode",{agentType:r,ideType:n,mode:O}):await C("set_extension_mode",{agentType:r,ideType:n,mode:O})}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:o}),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:f?`${ee}55`:"transparent",border:"1px solid",color:N?"var(--text-primary)":"var(--text-muted)"},onClick:H,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),R?"...":N||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),f&&h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>j(!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"}),h.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===N?`${ee}18`:"transparent",color:O===N?ee:"var(--text-secondary)",fontWeight:O===N?600:400,borderLeft:O===N?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=O===N?`${ee}18`:"transparent"},onClick:()=>J(O),children:O},O))]})]})]}),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:k?`${ee}55`:"transparent",border:"1px solid",color:y?"var(--text-primary)":"var(--text-muted)"},onClick:Q,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),L?"...":y||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),k&&v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(!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"}),v.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===y?`${ee}18`:"transparent",color:O===y?ee:"var(--text-secondary)",fontWeight:O===y?600:400,borderLeft:O===y?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=O===y?`${ee}18`:"transparent"},onClick:()=>X(O),children:O},O))]})]})]})]})}const ar=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:o}){const c=a.useRef(null),[i,u]=a.useState("");a.useEffect(()=>{u("")},[s]);const l=()=>{const x=i.trim();!x||r||(u(""),o(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=>u(x.target.value),onPaste:x=>{const d=x.clipboardData.getData("text");d&&u(p=>p+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"})})})]})})}),ye=t=>t.transport==="pty",ge=t=>t.transport==="acp";var or=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ir(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function me(t,s){if(ir(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":or.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 Ds(t){return me(t)==="generating"}function xe(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function cr(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 o=Math.floor(n/24),c=n%24;return`${o}d ${c}h`}function Qt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Bt(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const o=r.replace(/[\\/]+$/,""),c=o.split(/[\\/]/).filter(Boolean);return c[c.length-1]||o}function lr(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 dr(t){return lr(t.trim().replace(/\.local$/i,""))}function ur(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Bs(t,s={}){var o,c;const n=[t.hostname,(o=t.machine)==null?void 0:o.hostname,(c=t.system)==null?void 0:c.hostname].find(i=>typeof i=="string"&&i.trim().length>0);if(n&&n!=="Unknown")return dr(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Xe(t,s={}){return ur(t)||Bs(t,s)}function es(t){return t.transport==="pty"}function ts(t){return t.transport==="acp"}function ss(t,s){return xe(t)}function xr(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const o=(s||"").trim().toLowerCase(),c=(n||"").trim().toLowerCase(),i=xe(n||"").trim().toLowerCase();return r===o||r===c||r===i}function hr(t){return me(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function pr(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 o=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(o),i=me(r.status);if(!c){s.set(o,{...r,status:i});continue}const u=n.indexOf(c.status||"idle"),l=n.indexOf(i||"idle");l>=0&&(u<0||l<u)&&s.set(o,{...r,status:i})}return Array.from(s.values())}const mr=60,fr=60;function Ws({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:o,isFocusingAgent:c,actionLogs:i,userName:u}){const l=a.useRef(new Map),{sendCommand:x}=Pe();ct("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:i.length,isSendingChat:r});const d=a.useRef(new Map),p=a.useCallback(L=>(d.current.has(L)||d.current.set(L,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:mr}),d.current.get(L)),[]),g=a.useCallback((L,S)=>{const P=p(L);d.current.set(L,{...P,...S}),f(K=>K+1)},[p]),[,f]=a.useState(0),j=t.tabKey,k=p(j),I=k.messages,h=k.hasMore,b=k.error,v=Math.max(0,t.messages.length-k.visibleLiveCount),[T,m]=a.useState(!1),N=a.useCallback(async()=>{var P,K;if(T)return;const L=t.tabKey,S=p(L);if(t.messages.length>S.visibleLiveCount){g(L,{visibleLiveCount:Math.min(t.messages.length,S.visibleLiveCount+fr),error:null});return}m(!0),g(L,{error:null});try{const C=(s==null?void 0:s.daemonId)||((P=t.ideId)==null?void 0:P.split(":")[0])||"";if(!C){g(L,{hasMore:!1});return}const H=t.ideType||t.agentType||"",Q=await x(C,"chat_history",{agentType:H,offset:S.offset,limit:30,targetSessionId:t.sessionId}),J=(Q==null?void 0:Q.result)??Q;if(((K=J.messages)==null?void 0:K.length)>0){const G=p(L);g(L,{messages:[...J.messages,...G.messages],offset:G.offset+J.messages.length,hasMore:!!J.hasMore})}else g(L,{hasMore:!!J.hasMore})}catch(C){const H=(C==null?void 0:C.message)||"";H.includes("P2P not available")||H.includes("channel not open")||H.includes("P2P not connected")||H.includes("timeout")?g(L,{error:"Connection not ready — tap to retry"}):g(L,{hasMore:!1,error:"Failed to load history"})}finally{m(!1)}},[T,s,t,x,p,g]),{allMessages:w,receivedAtMap:y}=a.useMemo(()=>{const L=v>0?t.messages.slice(-k.visibleLiveCount):t.messages;if(I.length===0){const H={};return L.forEach((Q,J)=>{const G=`${t.tabKey}:${Ve(Q,J)}`;let se=Q.receivedAt||l.current.get(G)||0;se||(se=Date.now(),l.current.set(G,se)),H[Ve(Q,J)]=se}),{allMessages:L,receivedAtMap:H}}const S=new Set(L.map(H=>`${H.role}:${(H.content||"").slice(0,100)}`)),K=[...I.filter(H=>!S.has(`${H.role}:${(H.content||"").slice(0,100)}`)),...L],C={};return K.forEach((H,Q)=>{const J=`${t.tabKey}:${Ve(H,Q)}`;let G=H.receivedAt||l.current.get(J)||0;G||(G=Date.now(),l.current.set(J,G)),C[Ve(H,Q)]=G}),{allMessages:K,receivedAtMap:C}},[t.messages,t.tabKey,v,I,k.visibleLiveCount]),A=a.useMemo(()=>i.filter(L=>L.ideId===t.tabKey).sort((L,S)=>L.timestamp-S.timestamp),[i,t.tabKey]),R=t.displayPrimary||t.agentName||"Agent",D=a.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if(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(qe,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{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(Es,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{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,o,c,T,R]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(Gn,{messages:w,actionLogs:A,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:ye(t)||ge(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:y,onLoadMore:N,isLoadingMore:T,hasMoreHistory:h,hiddenLiveCount:v,loadError:b??void 0,emptyState:D}),!ye(t)&&(()=>{const L=t.streamSource!=="agent-stream",S=L?t.ideType:t.agentType,P=L?s!=null&&s.type?xe(s.type):xe(t.ideType||""):t.agentName||xe(t.agentType||"");return e.jsx(rr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:S,displayLabel:P,serverModel:(s==null?void 0:s.currentModel)||void 0,serverMode:(s==null?void 0:s.currentPlan)||void 0,acpConfigOptions:ge(t)?s==null?void 0:s.acpConfigOptions:void 0,acpModes:ge(t)?s==null?void 0:s.acpModes:void 0})})(),e.jsx(ar,{contextKey:t.tabKey,panelLabel:R,isSending:r,onSend:n})]})}let Os=ot;function It(){return Os()}class gr{constructor(){ue(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(o=>o(...n))}}let Ks=new gr;class br{constructor(){ue(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,o){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){this.ptyCallbacks.forEach(r=>r(s,n))}}let he=new br;function yr(t){t.dashboardWS&&(Ks=t.dashboardWS),t.connectionManager&&(he=t.connectionManager),t.useDaemonsHook&&(Os=t.useDaemonsHook)}function jr({activeConv:t,clearToken:s=0,ptyBuffers:n,terminalRef:r,handleSendChat:o,isSendingChat:c=!1}){var w;const i=a.useRef(null),{sendCommand:u,sendData:l}=Pe(),x=En(),[d,p]=a.useState(""),[g,f]=a.useState(!1),j=a.useRef(0),k=a.useRef(!1),I=t.tabKey,h=t.sessionId||"",b=t.daemonId||((w=t.ideId)==null?void 0:w.split(":")[0])||t.ideId||"",v=y=>y===h||y===t.ideId||y===t.tabKey,T=()=>{var y;j.current=0,k.current=!1,f(!1),(y=r.current)==null||y.clear()},m=()=>{var y;j.current=0,k.current=!1,f(!0),(y=r.current)==null||y.clear()},N=(y,A=0)=>{var R,D;k.current||j.current>=A&&j.current!==0||(j.current=A,f(!0),(R=r.current)==null||R.clear(),y&&((D=r.current)==null||D.write(y)))};return a.useEffect(()=>{T()},[h]),a.useEffect(()=>{if(!h)return;const y=new EventSource(x.getRuntimeEventsUrl(h)),A=L=>{try{const S=JSON.parse(L.data);if(S.sessionId!==h)return;N(S.text||"",S.seq||0)}catch{}},R=L=>{var S;try{const P=JSON.parse(L.data);if(P.sessionId!==h)return;k.current=!0,typeof P.seq=="number"&&(j.current=Math.max(j.current,P.seq)),f(!0),typeof P.data=="string"&&((S=r.current)==null||S.write(P.data))}catch{}},D=L=>{try{if(JSON.parse(L.data).sessionId!==h)return;m()}catch{}};return y.addEventListener("runtime_snapshot",A),y.addEventListener("session_output",R),y.addEventListener("session_cleared",D),y.onerror=()=>{},()=>{y.removeEventListener("runtime_snapshot",A),y.removeEventListener("session_output",R),y.removeEventListener("session_cleared",D),y.close()}},[x,h]),a.useEffect(()=>{var D,L,S,P;if(!h)return;const y=((D=n.current.get(I))==null?void 0:D.join(""))||"";y?N(y,2):t.terminalHistory&&N(t.terminalHistory,1),b&&((L=he.getState)==null?void 0:L.call(he,b))==="connected"&&f(!0);const A=((S=he.onPtyOutput)==null?void 0:S.call(he,(K,C)=>{var H;v(K)&&(k.current=!0,f(!0),typeof C=="string"&&C&&((H=r.current)==null||H.write(C)))}))||(()=>{}),R=(P=he.onStateChange)==null?void 0:P.call(he,(K,C)=>{K!==b||C!=="connected"||f(!0)});return()=>{A(),R==null||R()}},[t.ideId,t.tabKey,t.terminalHistory,b,n,h,r]),a.useEffect(()=>{s&&(n.current.delete(I),T())},[s,I,n,r]),a.useEffect(()=>{p("")},[t.tabKey]),a.useEffect(()=>{const y=A=>{var D;const R=A.detail;R!=null&&R.sessionId&&R.sessionId!==h||g&&((D=r.current)==null||D.fit())};return window.addEventListener("adhdev:fit-cli-terminal",y),()=>{window.removeEventListener("adhdev:fit-cli-terminal",y)}},[g,h,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx($s,{ref:r,readOnly:!g,onInput:y=>{g&&(l!=null&&l(b,{type:"pty_input",targetSessionId:h,data:y})||u(b,"pty_input",{targetSessionId:h,data:y}).catch(console.error))},onResize:(y,A)=>{g&&(l!=null&&l(b,{type:"pty_resize",targetSessionId:h,cols:y,rows:A})||u(b,"pty_resize",{targetSessionId:h,cols:y,rows:A,force:!0}).catch(()=>{}))}},t.tabKey),!g&&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:i,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:d,onChange:y=>p(y.target.value),onPaste:y=>{const A=y.clipboardData.getData("text");A&&p(R=>R+A),y.preventDefault()},onKeyDown:y=>{if(y.key!=="Enter")return;if(y.nativeEvent.isComposing){y.preventDefault();return}y.preventDefault();const A=d.trim();!g||!A||c||(p(""),o(A))},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=d.trim();!g||!y||c||(p(""),o(y))},disabled:!g||!d.trim()||c,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${d.trim()&&!c?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:d.trim()&&!c?{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:d.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function vr({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",o=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)"},u={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[o],borderBottom:i[o],color:u[o]},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 wr({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:o,onStopCli:c,onFitCli:i}){const u=it(),l=It(),x=l.p2pStates||{},d=l.ides||[],p=!!t&&ye(t)&&!ge(t),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",f=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",j=d.filter(T=>T.type==="adhdev-daemon"),k=Object.values(x),I=k.filter(T=>T==="connected").length,h=k.filter(T=>T==="connecting"||T==="new"||T==="checking").length,v=n!=="connected"||j.length===0?null:h>0&&I===0?"P2P connecting...":I>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:g,boxShadow:f}})})]}),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:g,boxShadow:f}}),v&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",v]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[p&&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&&!p&&!ge(t)&&e.jsxs("button",{onClick:()=>u(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Ft,{size:14})," IDE"]}),t&&!p&&!ge(t)&&e.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Ms,{size:16})}),t&&!p&&!ge(t)&&e.jsx("button",{onClick:()=>u(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Re,{size:16})})]})]})}function zs({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:o,onNewChat:c,onSwitchSession:i,onRefreshHistory:u}){var p;const l=s.find(g=>g.id===t.ideId),x=(l==null?void 0:l.chats)||[],d=(p=l==null?void 0:l.activeChat)==null?void 0:p.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:o,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," — ",xe(t.ideType)]})]}),e.jsx("button",{onClick:o,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(g=>e.jsxs("div",{onClick:()=>{i(t.ideId,g.id),o()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${d===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[g.id.substring(0,12),"..."]}),d===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),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(On,{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:u,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(Ts,{size:13})," Refresh History"]})})})]})]})}const ns={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Hs({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:ns[r.type]||ns.info},onClick:()=>{var o;(o=r.actions)!=null&&o.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:o=>{o.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((o,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${o.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":o.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(),o.onClick(),s(r.id)},children:o.label},c))})]},r.id))})}const Nr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function kr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Sr(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 rs(t,s){const n=new Set,r=[];for(const o of s)if(o)for(const c of t[o]||[]){const i=c._localId||`${c.role}:${c.timestamp}:${c.content}`;n.has(i)||(n.add(i),r.push(c))}return r.sort((o,c)=>o.timestamp-c.timestamp)}function Us(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 Fs(t,s,n={}){var f,j,k,I,h,b;const r=[],o=n.machineName,c=n.connectionState,i=kr(t),u=xe(t.type),l=t.agentStreams,x=Array.isArray(l)?l.map(v=>({...v,activeModal:v.activeModal??void 0})):[],d=Nr(t),p=t.activeChat||{title:""},g=p.title&&String(p.title).trim()?String(p.title).trim():"";if(d){const v=t.sessionId||t.instanceId,T=ss(t.type),m=(f=t.activeChat)==null?void 0:f.activeModal,N=m&&Array.isArray(m.buttons)&&m.buttons.length>0,w=me((j=t.activeChat)==null?void 0:j.status,{activeModal:(k=t.activeChat)==null?void 0:k.activeModal})||me((h=(I=t.agents)==null?void 0:I[0])==null?void 0:h.status)||"idle",y=t.activeChat||{title:"",messages:[]};let A=y.title&&String(y.title).trim()?String(y.title).trim():"";const R=(b=t.activeChat)==null?void 0:b.id,D=t.chats;if(R&&Array.isArray(D)&&D.length>0){const C=D.find(H=>H.id===R||H.id&&String(H.id)===String(R));C!=null&&C.title&&String(C.title).trim()&&(A=String(C.title).trim())}const L=y.messages||[],S=rs(s,[t.id,v]),P=new Map;L.filter(C=>C.role==="user").forEach(C=>{const H=xt(C.content);H&&P.set(H,(P.get(H)||0)+1)});const K=S.filter(C=>{const H=xt(C.content),Q=P.get(H)||0;return Q>0?(P.set(H,Q-1),!1):!0});r.push({ideId:t.id,sessionId:v,transport:t.transport,daemonId:t.daemonId||void 0,mode:ye(t)?t.mode||"terminal":"chat",agentName:T,agentType:(ye(t)||ge(t))&&(t.cliType||t.acpType)||t.type,status:w,title:A,messages:[...L,...K],terminalHistory:typeof y.terminalHistory=="string"?y.terminalHistory:"",resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:i,displayPrimary:A||i||(ye(t)||ge(t)?"Terminal":T),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:N?m.buttons:void 0,modalMessage:N?m.message:void 0,streamSource:"native",tabKey:t.id,machineName:o,connectionState:c})}if(d&&(ye(t)||ge(t)))return r;for(const v of x){const T=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,m=hr(v),N=Sr(v),w=`${t.id}:${N}`,y=v.title&&String(v.title).trim()||"",A=xr(y,v.agentName,v.agentType)?"":y,R=v.messages||[],D=rs(s,[w,v.sessionId,v.instanceId]),L=new Map;R.filter(P=>P.role==="user").forEach(P=>{const K=xt(P.content);K&&L.set(K,(L.get(K)||0)+1)});const S=D.filter(P=>{const K=xt(P.content),C=L.get(K)||0;return C>0?(L.set(K,C-1),!1):!0});r.push({ideId:t.id,sessionId:v.sessionId||v.instanceId,transport:v.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:m,title:A,messages:[...R,...S],ideType:v.agentType,workspaceName:i,displayPrimary:A||g||i||u,displaySecondary:`${u}·${v.agentName}`,cdpConnected:t.cdpConnected,modalButtons:T?v.activeModal.buttons:void 0,modalMessage:T?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:w,machineName:o,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:ss(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:i,displayPrimary:i||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:t.id,connectionState:c}),r}function Cr(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const o=n.get(r.parentId)||[];o.push(r),n.set(r.parentId,o)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Ir(t,s){var f,j,k,I,h,b,v,T;const n=[],{daemonId:r,existingDaemon:o,timestamp:c}=s,i=c||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:l,childrenByParent:x}=Cr(u),d=l.filter(m=>m.kind==="workspace"&&m.transport==="cdp-page"),p=l.filter(m=>m.kind==="agent"&&m.transport==="pty"),g=l.filter(m=>m.kind==="agent"&&m.transport==="acp");n.push({...o||{},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(m=>!!m.cdpConnected)});for(const m of d){const N=x.get(m.id)||[];n.push({id:`${r}:ide:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,status:m.cdpConnected?"online":"detected",daemonId:r,instanceId:m.id,workspace:m.workspace,terminals:0,agents:N.map(w=>({id:w.id,name:w.providerName,type:w.providerType,status:w.status})),activeChat:m.activeChat,chats:[],agentStreams:N.map(w=>{var y,A,R,D;return{sessionId:w.id,instanceId:w.id,parentSessionId:w.parentId,agentType:w.providerType,agentName:w.providerName,extensionId:w.providerType,transport:w.transport,status:me(w.status,{activeModal:(y=w.activeChat)==null?void 0:y.activeModal}),title:w.title,messages:((A=w.activeChat)==null?void 0:A.messages)||[],inputContent:((R=w.activeChat)==null?void 0:R.inputContent)||"",activeModal:((D=w.activeChat)==null?void 0:D.activeModal)||null,model:w.currentModel}}),cdpConnected:m.cdpConnected,currentModel:m.currentModel,currentPlan:m.currentPlan,currentAutoApprove:m.currentAutoApprove,timestamp:i})}for(const m of p){const N=m.runtime;n.push({id:`${r}:cli:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:"terminal",workspace:m.workspace||"",activeChat:m.activeChat,resume:m.resume,runtimeKey:m.runtimeKey??(N==null?void 0:N.runtimeKey),runtimeDisplayName:m.runtimeDisplayName??(N==null?void 0:N.displayName),runtimeWorkspaceLabel:m.runtimeWorkspaceLabel??(N==null?void 0:N.workspaceLabel),runtimeWriteOwner:m.runtimeWriteOwner??(N==null?void 0:N.writeOwner)??null,runtimeAttachedClients:m.runtimeAttachedClients??(N==null?void 0:N.attachedClients)??[],agentStreams:[{sessionId:m.id,instanceId:m.id,parentSessionId:m.parentId,agentType:m.providerType,agentName:m.providerName,extensionId:"cli-agent",transport:m.transport,status:me(m.status,{activeModal:(f=m.activeChat)==null?void 0:f.activeModal}),title:m.title,messages:((j=m.activeChat)==null?void 0:j.messages)||[],inputContent:((k=m.activeChat)==null?void 0:k.inputContent)||"",activeModal:(I=m.activeChat)==null?void 0:I.activeModal}],timestamp:i,_isCli:!0})}for(const m of g){const N=m.runtime;n.push({id:`${r}:acp:${m.id}`,sessionId:m.id,parentSessionId:m.parentId,sessionKind:m.kind,transport:m.transport,sessionCapabilities:m.capabilities,type:m.providerType,ideType:m.providerType,agentType:m.providerType,status:m.status||"running",daemonId:r,instanceId:m.id,cliName:m.providerName,mode:"chat",workspace:m.workspace||"",activeChat:m.activeChat,runtimeKey:m.runtimeKey??(N==null?void 0:N.runtimeKey),runtimeDisplayName:m.runtimeDisplayName??(N==null?void 0:N.displayName),runtimeWorkspaceLabel:m.runtimeWorkspaceLabel??(N==null?void 0:N.workspaceLabel),runtimeWriteOwner:m.runtimeWriteOwner??(N==null?void 0:N.writeOwner)??null,runtimeAttachedClients:m.runtimeAttachedClients??(N==null?void 0:N.attachedClients)??[],currentModel:m.currentModel,currentPlan:m.currentPlan,acpConfigOptions:m.acpConfigOptions,acpModes:m.acpModes,agentStreams:[{sessionId:m.id,instanceId:m.id,parentSessionId:m.parentId,agentType:m.providerType,agentName:m.providerName,extensionId:"acp-agent",transport:m.transport,status:me(m.status,{activeModal:(h=m.activeChat)==null?void 0:h.activeModal}),title:m.title,messages:((b=m.activeChat)==null?void 0:b.messages)||[],inputContent:((v=m.activeChat)==null?void 0:v.inputContent)||"",activeModal:(T=m.activeChat)==null?void 0:T.activeModal}],timestamp:i,_isAcp:!0})}return n}function Vs(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 Mr(t,s){const n=Vs(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Ys=[{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:"🧩"}],Xs=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Gs="adhdev_notification_prefs",as={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Tr(){try{const t=localStorage.getItem(Gs);if(t){const s=JSON.parse(t);return{...as,...s}}}catch{}return{...as}}function Er(t){try{localStorage.setItem(Gs,JSON.stringify(t))}catch{}}let Te=Tr(),bt=[];function Ar(){bt.forEach(t=>t())}function Lr(){return{...Te}}function Rr(t){Te={...Te,...t},Er(Te),Ar()}function _r(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return bt.push(n),()=>{bt=bt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{Rr(n)},[]);return[{...Te},s]}function nt(t){if(!Te.globalEnabled)return!1;switch(t){case"disconnect":return Te.disconnectAlert;case"completion":return Te.completionAlert;case"approval":return Te.approvalAlert;case"browser":return Te.browserNotifications;default:return!0}}const $r={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Pr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Js(){return"Notification"in window&&Notification.permission==="granted"}let De=null;async function Dr(){if(De!==null)return De;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return De=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(De=!!await t.pushManager.getSubscription(),De):(De=!1,!1)}catch{return De=!1,!1}}function Wt(t,s,n){if(Js())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 Br(t,s={}){const n={...$r,...s},r=a.useRef(new Map),o=a.useRef(0),c=a.useRef(null);a.useEffect(()=>{Dr().then(u=>{c.current=u})},[]);const i=a.useCallback((u,l,x)=>{const d=Date.now();d-o.current<n.throttleMs||(o.current=d,Wt(u,l,x))},[n.throttleMs]);a.useEffect(()=>{var u;if(!(!n.enabled||!Js())&&nt("browser")&&c.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,me(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),d=me(l.status,{activeModal:l.activeModal}),p=l.name||l.id;if(n.onApproval&&nt("approval")&&d==="waiting_approval"&&x!=="waiting_approval"){const g=((u=l.activeModal)==null?void 0:u.message)||"Action requires your approval";i(`🔔 ${p} — Approval needed`,g.slice(0,120),`approval-${l.id}`)}n.onComplete&&nt("completion")&&Ds(x)&&d==="idle"&&i(`✅ ${p} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&x!=="error"&&i(`⚠️ ${p} — 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 Wr{constructor(){ue(this,"dedupMap",new Map);ue(this,"DEDUP_WINDOW_MS",5e3);ue(this,"DEDUP_MAX_SIZE",50);ue(this,"DEDUP_CLEANUP_AGE_MS",1e4);ue(this,"toastCallbacks",[]);ue(this,"systemMessageCallbacks",[]);ue(this,"clearSystemMessageCallbacks",[]);ue(this,"resolveActionFn",null);ue(this,"viewRequestRespondFn",null);ue(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 o=(r==null?void 0:r.id)||Date.now();this.emitToast({id:o,message:s,type:n,timestamp:o,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[o,c]of this.dedupMap)n-c>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(o);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const o=this.ides.find(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(o)return o}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(o=>o.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(o=>o.id.endsWith(`:ide:${s.instanceId}`)||o.id.endsWith(`:cli:${s.instanceId}`))),n){const o=n.daemonId;if(o){const c=this.ides.find(i=>i.id===o&&i.type==="adhdev-daemon");if(c)return c}}const r=this.ides.filter(o=>o.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.agentStreams)?n.agentStreams:[]).some(o=>(o==null?void 0:o.sessionId)===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,p;if(!s.ideId&&s.instanceId){for(const g of this.ides)if(g.id.endsWith(`:ide:${s.instanceId}`)||g.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=g.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=xe(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const g=Xe(u,{fallbackId:u.id});g&&(i=s.ideType==="adhdev-daemon"?g:`${g}/${i}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const g=s.duration?` (${s.duration}s)`:"";l=`✅ ${i} agent task completed${g}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Lr().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${g}`,_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 g=s.modalMessage||"Approval requested",f=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(j=>`[${j}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${g}
42
- ${f}`,_localId:`sys_approval_${Date.now()}`})}if((p=s.modalButtons)!=null&&p.length&&this.resolveActionFn){const g=this.resolveActionRouteTarget(s);if(!g)return;const f=s.agentType||s.ideType||"",j=s.ideType||"",k=s.modalButtons,I=m=>m.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),h=this.resolveActionFn,b=k.map((m,N)=>{const w=I(m).toLowerCase(),y=/^(run|approve|accept|yes|allow|always)/.test(w),A=/^(reject|deny|delete|remove|abort|cancel|no)/.test(w);return{label:I(m),variant:y?"primary":A?"danger":"default",onClick:()=>{const R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w);h(g,"resolve_action",{action:R?"approve":"reject",button:m,buttonIndex:N,agentType:f,ideType:j,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),v=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:v,type:x,timestamp:T,targetKey:r||g,actions:b,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const g=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${i} agent is taking a long time${g}`,x="warning",nt("browser")&&!document.hasFocus()&&Wt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${g.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const g=s.requesterName||"A team member",f=s.requestId,j=s.orgId;if(l=`👁️ ${g} wants to view your session`,x="warning",f&&j&&this.viewRequestRespondFn){const k=this.viewRequestRespondFn,I=Date.now(),h=[{label:"Approve",variant:"primary",onClick:()=>{k(j,f,"approve").catch(b=>console.error("[EventManager] approve view request failed:",b))}},{label:"Decline",variant:"danger",onClick:()=>{k(j,f,"reject").catch(b=>console.error("[EventManager] reject view request failed:",b))}}];this.emitToast({id:I,message:l,type:x,timestamp:I,actions:h,duration:3e4}),l=""}nt("browser")&&!document.hasFocus()&&Wt("👁️ View Request",`${g} wants to view your session`,`view-request-${f}`)}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 g=Date.now();this.emitToast({id:g,message:l,type:x,timestamp:g,targetKey:r||s.ideId,duration:5e3})}}}const _e=new Wr;function ze(...t){return fn(gn(t))}function Or({icon:t,title:s,subtitle:n,badge:r,actions:o,className:c}){return e.jsxs("div",{className:ze("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})]}),o&&e.jsx("div",{className:"flex gap-2",children:o})]})}function Nt({icon:t,title:s,subtitle:n,badge:r,actions:o,widthClassName:c="max-w-6xl",contentClassName:i,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Or,{icon:t,title:s,subtitle:n,badge:r,actions:o}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ze("mx-auto flex w-full flex-col gap-4",c,i),children:u})})]})}function fe({title:t,icon:s,description:n,accentColor:r,className:o,children:c}){return e.jsxs("div",{className:ze("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]",o),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 Vt({icon:t,title:s,description:n,action:r,className:o}){return e.jsxs("div",{className:ze("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),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 Kr={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"},zr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Hr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ze("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Kr[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:zr[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 Ur={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"},Fr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Vr({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ze("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Ur[t],n),children:[e.jsx("span",{className:ze("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Fr[t])}),r]})}function Yr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ot(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function yt(t){return t==="system"?Yr():t}function qr(){typeof document>"u"||document.documentElement.setAttribute("data-theme",yt(Ot()))}function Xr(){const[t,s]=a.useState(Ot),[n,r]=a.useState(()=>yt(Ot()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),u=l=>{t==="system"&&r(l.matches?"light":"dark")};return i.addEventListener("change",u),()=>i.removeEventListener("change",u)},[t]);const o=a.useCallback(i=>{s(i),r(yt(i));try{localStorage.setItem("theme",i)}catch{}},[]),c=a.useCallback(()=>{s(i=>{const u=i==="dark"?"light":i==="light"?"system":"dark";r(yt(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:n,preference:t,setPreference:o,cycleTheme:c,isDark:n==="dark"}}function We({label:t,description:s,checked:n,disabled:r,onChange:o,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=>o(i.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Gr({onPrefChange:t}){const[s,n]=_r(),r=(o,c)=>{n({[o]:c}),t==null||t(o,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_s,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:o=>r("globalEnabled",o)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Re,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:o=>r("browserNotifications",o)}),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(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kn,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:o=>r("completionAlert",o)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(zn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:o=>r("approvalAlert",o)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:o=>r("disconnectAlert",o)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(We,{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:o=>r("chatTaskCompletionBubble",o)}),!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 Jr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){const c=t.filter(i=>i.type==="adhdev-daemon");return c.length===0?e.jsx(Vt,{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(Qr,{ide:i,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o},i.id))})}function os({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:o,onCancel:c}){const i=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return bn.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:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick: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:o,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,children:n})]})]})}),document.body)}function Zr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Ys,...qs,...Xs].find(o=>o.id===s||s.includes(o.id)||o.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Qr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){var P,K;const[c,i]=a.useState("idle"),[u,l]=a.useState(""),[x,d]=a.useState(null),[p,g]=a.useState("idle"),[f,j]=a.useState(""),k=t,I=k.version||k.daemonVersion||null,h=((P=k.machine)==null?void 0:P.platform)||((K=k.system)==null?void 0:K.platform)||"",b=Xe(k,{fallbackId:t.id}),v=h==="win32"?"🪟":h==="darwin"?"🍎":"🐧",T=s.filter(C=>C.daemonId===t.id&&C.transport==="cdp-page"),m=s.filter(C=>C.daemonId===t.id&&C.transport==="pty"),N=s.filter(C=>C.daemonId===t.id&&C.transport==="acp"),w=k.p2p,y=async()=>{var C,H,Q;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||(H=J==null?void 0:J.result)!=null&&H.success?(i("done"),l(`Upgraded to v${J.result.version||"latest"}. Daemon is restarting...`)):(i("error"),l(((Q=J==null?void 0:J.result)==null?void 0:Q.error)||"Upgrade failed"))}catch(J){i("error"),l((J==null?void 0:J.message)||"Connection lost during upgrade")}}},A=async()=>{if(d(null),!!r){g("loading");try{await r(t.id),g("done"),j("Machine disconnected.")}catch(C){g("error"),j((C==null?void 0:C.message)||"Failed to disconnect")}}},R=async()=>{if(d(null),!!o){g("loading");try{await o(t.id),g("done"),j('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(C){g("error"),j((C==null?void 0:C.message)||"Failed to revoke token")}}},D="0.7.14",L=!I||I!==D,S=T.length+m.length+N.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:v}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:b}),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),"…"]}),I&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${L?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",I,!L&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&L&&e.jsx("button",{onClick:y,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:p==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),o&&e.jsx("button",{onClick:()=>d("revoke"),disabled:p==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Vr,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[w&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w.state==="connected"?"bg-green-400":w.state==="connecting"||w.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",w.state==="connected"?"connected":w.state==="connecting"||w.state==="new"?"connecting...":w.state||"off"]}),w.peers!==void 0&&w.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",w.peers," peer",w.peers!==1?"s":"",")"]})]}),w&&S>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),S>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(C=>{const H=Zr(C.type),Q=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:H.icon}),e.jsx("span",{children:H.name}),Q!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Q?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:Q?"CDP connected":"CDP connecting..."})]},C.id)}),m.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)),N.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"})]}),(u||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||p==="error"?"text-red-400":c==="done"||p==="done"?"text-green-400":"text-text-muted"}`,children:f||u})]}),x==="disconnect"&&e.jsx(os,{title:"🔌 Disconnect Machine",message:`Disconnect "${b}" from ADHDev?
40
+ `})]})}function Ps({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const o=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:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Ft,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((i,u)=>{const l=c(i).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),h=n===i,g=n!==null;return e.jsx("button",{onClick:()=>o(i),disabled:g,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${g&&!h?"opacity-40":"opacity-100"} ${g?"cursor-not-allowed":"cursor-pointer"}`,children:h?"⏳ ...":c(i)},u)})})]})]})}const we=new Map;function rr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:o,serverModel:c,serverMode:i,acpConfigOptions:u,acpModes:l}){var oe;const{sendCommand:x}=Pe(),d=!!(u||l),h=`${t}:${s||r}`,g=we.get(h),[m,b]=a.useState(!1),[k,I]=a.useState(!1),[p,y]=a.useState((g==null?void 0:g.models)||[]),[v,T]=a.useState((g==null?void 0:g.modes)||[]),f=O=>O?typeof O=="string"?O:typeof O=="object"?O.name||O.id||JSON.stringify(O):String(O):"",[N,w]=a.useState(f(c)),[j,A]=a.useState(f(i)),[L,D]=a.useState(!1),[R,S]=a.useState(!1),P=a.useRef(0),K=O=>O.map($=>typeof $=="string"?$:($==null?void 0:$.name)||($==null?void 0:$.id)||String($));a.useEffect(()=>{if(u){const O=u.find($=>$.category==="model");if(O){const $=K(O.options.map(_=>_.value));y($),O.currentValue&&w(f(O.currentValue));const E=we.get(h)||{models:[],modes:[]};we.set(h,{...E,models:$})}}if(l&&l.length>0){const O=K(l.map(E=>E.id));T(O);const $=we.get(h)||{models:[],modes:[]};we.set(h,{...$,modes:O})}else if(u){const O=u.find($=>$.category!=="model");if(O){const $=K(O.options.map(_=>_.value));T($),O.currentValue&&A(f(O.currentValue));const E=we.get(h)||{models:[],modes:[]};we.set(h,{...E,modes:$})}}},[u,l,h]),a.useEffect(()=>{b(!1),I(!1),w(f(c)),A(f(i));const O=we.get(h);O?(y(O.models),T(O.modes)):(y([]),T([]))},[t,r,s]),a.useEffect(()=>{c&&Date.now()>P.current&&w(f(c))},[c]),a.useEffect(()=>{i&&Date.now()>P.current&&A(f(i))},[i]);const C=a.useCallback(async(O,$={})=>{const E={...$,...s&&{targetSessionId:s}};return await x(t,O,E)},[t,s,x]),H=async()=>{var O,$;if(p.length>0){b(!m);return}if(d){b(!0);return}D(!0);try{const E=await C("list_extension_models",{agentType:r,ideType:n}),_=(E==null?void 0:E.models)||((O=E==null?void 0:E.result)==null?void 0:O.models)||[],B=K(_);y(B),E!=null&&E.current&&w(f(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&w(f(E.result.current));const U=we.get(h)||{models:[],modes:[]};we.set(h,{...U,models:B}),b(!0)}catch{}finally{D(!1)}},Q=async()=>{var O,$;if(v.length>0){I(!k);return}if(d){I(!0);return}S(!0);try{const E=await C("list_extension_modes",{agentType:r,ideType:n}),_=(E==null?void 0:E.modes)||((O=E==null?void 0:E.result)==null?void 0:O.modes)||[],B=K(_);T(B),E!=null&&E.current&&A(f(E.current)),($=E==null?void 0:E.result)!=null&&$.current&&A(f(E.result.current));const U=we.get(h)||{models:[],modes:[]};we.set(h,{...U,modes:B}),I(!0)}catch{}finally{S(!1)}},J=async O=>{b(!1),w(O),P.current=Date.now()+5e3;try{d?await C("change_model",{agentType:r,ideType:n,model:O}):await C("set_extension_model",{agentType:r,ideType:n,model:O})}catch{}},G=d&&!(l&&l.length>0)&&(u==null?void 0:u.some(O=>O.category!=="model")),se=G?(oe=u==null?void 0:u.find(O=>O.category!=="model"))==null?void 0:oe.configId:void 0,X=async O=>{I(!1),A(O),P.current=Date.now()+5e3;try{d&&G&&se?await C("set_thought_level",{agentType:r,ideType:n,configId:se,value:O}):d?await C("set_mode",{agentType:r,ideType:n,mode:O}):await C("set_extension_mode",{agentType:r,ideType:n,mode:O})}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:o}),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:m?`${ee}55`:"transparent",border:"1px solid",color:N?"var(--text-primary)":"var(--text-muted)"},onClick:H,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),L?"...":N||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),m&&p.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>b(!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"}),p.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===N?`${ee}18`:"transparent",color:O===N?ee:"var(--text-secondary)",fontWeight:O===N?600:400,borderLeft:O===N?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=O===N?`${ee}18`:"transparent"},onClick:()=>J(O),children:O},O))]})]})]}),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:k?`${ee}55`:"transparent",border:"1px solid",color:j?"var(--text-primary)":"var(--text-muted)"},onClick:Q,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),R?"...":j||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),k&&v.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(!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"}),v.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===j?`${ee}18`:"transparent",color:O===j?ee:"var(--text-secondary)",fontWeight:O===j?600:400,borderLeft:O===j?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=O===j?`${ee}18`:"transparent"},onClick:()=>X(O),children:O},O))]})]})]})]})}const ar=a.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:o}){const c=a.useRef(null),[i,u]=a.useState("");a.useEffect(()=>{u("")},[s]);const l=()=>{const x=i.trim();!x||r||(u(""),o(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=>u(x.target.value),onPaste:x=>{const d=x.clipboardData.getData("text");d&&u(h=>h+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"})})})]})})}),ye=t=>t.transport==="pty",ge=t=>t.transport==="acp";var or=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function ir(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function me(t,s){if(ir(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":or.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 Ds(t){return me(t)==="generating"}function xe(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function cr(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 o=Math.floor(n/24),c=n%24;return`${o}d ${c}h`}function Qt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Bt(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const o=r.replace(/[\\/]+$/,""),c=o.split(/[\\/]/).filter(Boolean);return c[c.length-1]||o}function lr(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 dr(t){return lr(t.trim().replace(/\.local$/i,""))}function ur(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Bs(t,s={}){var o,c;const n=[t.hostname,(o=t.machine)==null?void 0:o.hostname,(c=t.system)==null?void 0:c.hostname].find(i=>typeof i=="string"&&i.trim().length>0);if(n&&n!=="Unknown")return dr(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Xe(t,s={}){return ur(t)||Bs(t,s)}function es(t){return t.transport==="pty"}function ts(t){return t.transport==="acp"}function ss(t,s){return xe(t)}function xr(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const o=(s||"").trim().toLowerCase(),c=(n||"").trim().toLowerCase(),i=xe(n||"").trim().toLowerCase();return r===o||r===c||r===i}function pr(t){return me(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function hr(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 o=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(o),i=me(r.status);if(!c){s.set(o,{...r,status:i});continue}const u=n.indexOf(c.status||"idle"),l=n.indexOf(i||"idle");l>=0&&(u<0||l<u)&&s.set(o,{...r,status:i})}return Array.from(s.values())}const mr=60,fr=60;function Ws({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:o,isFocusingAgent:c,actionLogs:i,userName:u}){const l=a.useRef(new Map),{sendCommand:x}=Pe();ct("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:i.length,isSendingChat:r});const d=a.useRef(new Map),h=a.useCallback(R=>(d.current.has(R)||d.current.set(R,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:mr}),d.current.get(R)),[]),g=a.useCallback((R,S)=>{const P=h(R);d.current.set(R,{...P,...S}),m(K=>K+1)},[h]),[,m]=a.useState(0),b=t.tabKey,k=h(b),I=k.messages,p=k.hasMore,y=k.error,v=Math.max(0,t.messages.length-k.visibleLiveCount),[T,f]=a.useState(!1),N=a.useCallback(async()=>{var P,K;if(T)return;const R=t.tabKey,S=h(R);if(t.messages.length>S.visibleLiveCount){g(R,{visibleLiveCount:Math.min(t.messages.length,S.visibleLiveCount+fr),error:null});return}f(!0),g(R,{error:null});try{const C=(s==null?void 0:s.daemonId)||((P=t.ideId)==null?void 0:P.split(":")[0])||"";if(!C){g(R,{hasMore:!1});return}const H=t.ideType||t.agentType||"",Q=await x(C,"chat_history",{agentType:H,offset:S.offset,limit:30,targetSessionId:t.sessionId}),J=(Q==null?void 0:Q.result)??Q;if(((K=J.messages)==null?void 0:K.length)>0){const G=h(R);g(R,{messages:[...J.messages,...G.messages],offset:G.offset+J.messages.length,hasMore:!!J.hasMore})}else g(R,{hasMore:!!J.hasMore})}catch(C){const H=(C==null?void 0:C.message)||"";H.includes("P2P not available")||H.includes("channel not open")||H.includes("P2P not connected")||H.includes("timeout")?g(R,{error:"Connection not ready — tap to retry"}):g(R,{hasMore:!1,error:"Failed to load history"})}finally{f(!1)}},[T,s,t,x,h,g]),{allMessages:w,receivedAtMap:j}=a.useMemo(()=>{const R=v>0?t.messages.slice(-k.visibleLiveCount):t.messages;if(I.length===0){const H={};return R.forEach((Q,J)=>{const G=`${t.tabKey}:${Ve(Q,J)}`;let se=Q.receivedAt||l.current.get(G)||0;se||(se=Date.now(),l.current.set(G,se)),H[Ve(Q,J)]=se}),{allMessages:R,receivedAtMap:H}}const S=new Set(R.map(H=>`${H.role}:${(H.content||"").slice(0,100)}`)),K=[...I.filter(H=>!S.has(`${H.role}:${(H.content||"").slice(0,100)}`)),...R],C={};return K.forEach((H,Q)=>{const J=`${t.tabKey}:${Ve(H,Q)}`;let G=H.receivedAt||l.current.get(J)||0;G||(G=Date.now(),l.current.set(J,G)),C[Ve(H,Q)]=G}),{allMessages:K,receivedAtMap:C}},[t.messages,t.tabKey,v,I,k.visibleLiveCount]),A=a.useMemo(()=>i.filter(R=>R.ideId===t.tabKey).sort((R,S)=>R.timestamp-S.timestamp),[i,t.tabKey]),L=t.displayPrimary||t.agentName||"Agent",D=a.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]});if(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(Ye,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",L," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(Es,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pt,{size:14})," Open ",L," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]});if(t.status==="idle"&&!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,o,c,T,L]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(Gn,{messages:w,actionLogs:A,agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:ye(t)||ge(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:j,onLoadMore:N,isLoadingMore:T,hasMoreHistory:p,hiddenLiveCount:v,loadError:y??void 0,emptyState:D}),!ye(t)&&(()=>{const R=t.streamSource!=="agent-stream",S=R?t.ideType:t.agentType,P=R?s!=null&&s.type?xe(s.type):xe(t.ideType||""):t.agentName||xe(t.agentType||"");return e.jsx(rr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:S,displayLabel:P,serverModel:(s==null?void 0:s.currentModel)||void 0,serverMode:(s==null?void 0:s.currentPlan)||void 0,acpConfigOptions:ge(t)?s==null?void 0:s.acpConfigOptions:void 0,acpModes:ge(t)?s==null?void 0:s.acpModes:void 0})})(),e.jsx(ar,{contextKey:t.tabKey,panelLabel:L,isSending:r,onSend:n})]})}let Os=ot;function It(){return Os()}class gr{constructor(){ue(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(o=>o(...n))}}let Ks=new gr;class br{constructor(){ue(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,o){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){this.ptyCallbacks.forEach(r=>r(s,n))}}let pe=new br;function yr(t){t.dashboardWS&&(Ks=t.dashboardWS),t.connectionManager&&(pe=t.connectionManager),t.useDaemonsHook&&(Os=t.useDaemonsHook)}function jr({activeConv:t,clearToken:s=0,ptyBuffers:n,terminalRef:r,handleSendChat:o,isSendingChat:c=!1}){var w;const i=a.useRef(null),{sendCommand:u,sendData:l}=Pe(),x=En(),[d,h]=a.useState(""),[g,m]=a.useState(!1),b=a.useRef(0),k=a.useRef(!1),I=t.tabKey,p=t.sessionId||"",y=t.daemonId||((w=t.ideId)==null?void 0:w.split(":")[0])||t.ideId||"",v=j=>j===p||j===t.ideId||j===t.tabKey,T=()=>{var j;b.current=0,k.current=!1,m(!1),(j=r.current)==null||j.clear()},f=()=>{var j;b.current=0,k.current=!1,m(!0),(j=r.current)==null||j.clear()},N=(j,A=0)=>{var L,D;k.current||b.current>=A&&b.current!==0||(b.current=A,m(!0),(L=r.current)==null||L.clear(),j&&((D=r.current)==null||D.write(j)))};return a.useEffect(()=>{T()},[p]),a.useEffect(()=>{if(!p)return;const j=new EventSource(x.getRuntimeEventsUrl(p)),A=R=>{try{const S=JSON.parse(R.data);if(S.sessionId!==p)return;N(S.text||"",S.seq||0)}catch{}},L=R=>{var S;try{const P=JSON.parse(R.data);if(P.sessionId!==p)return;k.current=!0,typeof P.seq=="number"&&(b.current=Math.max(b.current,P.seq)),m(!0),typeof P.data=="string"&&((S=r.current)==null||S.write(P.data))}catch{}},D=R=>{try{if(JSON.parse(R.data).sessionId!==p)return;f()}catch{}};return j.addEventListener("runtime_snapshot",A),j.addEventListener("session_output",L),j.addEventListener("session_cleared",D),j.onerror=()=>{},()=>{j.removeEventListener("runtime_snapshot",A),j.removeEventListener("session_output",L),j.removeEventListener("session_cleared",D),j.close()}},[x,p]),a.useEffect(()=>{var D,R,S,P;if(!p)return;const j=((D=n.current.get(I))==null?void 0:D.join(""))||"";j?N(j,2):t.terminalHistory&&N(t.terminalHistory,1),y&&((R=pe.getState)==null?void 0:R.call(pe,y))==="connected"&&m(!0);const A=((S=pe.onPtyOutput)==null?void 0:S.call(pe,(K,C)=>{var H;v(K)&&(k.current=!0,m(!0),typeof C=="string"&&C&&((H=r.current)==null||H.write(C)))}))||(()=>{}),L=(P=pe.onStateChange)==null?void 0:P.call(pe,(K,C)=>{K!==y||C!=="connected"||m(!0)});return()=>{A(),L==null||L()}},[t.ideId,t.tabKey,t.terminalHistory,y,n,p,r]),a.useEffect(()=>{s&&(n.current.delete(I),T())},[s,I,n,r]),a.useEffect(()=>{h("")},[t.tabKey]),a.useEffect(()=>{const j=A=>{var D;const L=A.detail;L!=null&&L.sessionId&&L.sessionId!==p||g&&((D=r.current)==null||D.fit())};return window.addEventListener("adhdev:fit-cli-terminal",j),()=>{window.removeEventListener("adhdev:fit-cli-terminal",j)}},[g,p,r]),a.useEffect(()=>{if(!g)return;const j=requestAnimationFrame(()=>{var A;(A=r.current)==null||A.fit()});return()=>cancelAnimationFrame(j)},[g,p,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx($s,{ref:r,readOnly:!g,onInput:j=>{g&&(l!=null&&l(y,{type:"pty_input",targetSessionId:p,data:j})||u(y,"pty_input",{targetSessionId:p,data:j}).catch(console.error))},onResize:(j,A)=>{g&&(l!=null&&l(y,{type:"pty_resize",targetSessionId:p,cols:j,rows:A})||u(y,"pty_resize",{targetSessionId:p,cols:j,rows:A,force:!0}).catch(()=>{}))}},t.tabKey),!g&&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:i,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:d,onChange:j=>h(j.target.value),onPaste:j=>{const A=j.clipboardData.getData("text");A&&h(L=>L+A),j.preventDefault()},onKeyDown:j=>{if(j.key!=="Enter")return;if(j.nativeEvent.isComposing){j.preventDefault();return}j.preventDefault();const A=d.trim();!g||!A||c||(h(""),o(A))},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 j=d.trim();!g||!j||c||(h(""),o(j))},disabled:!g||!d.trim()||c,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${d.trim()&&!c?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:d.trim()&&!c?{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:d.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function vr({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",o=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)"},u={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[o],borderBottom:i[o],color:u[o]},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 wr({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:o,onStopCli:c,onFitCli:i}){const u=it(),l=It(),x=l.p2pStates||{},d=l.ides||[],h=!!t&&ye(t)&&!ge(t),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",m=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",b=d.filter(T=>T.type==="adhdev-daemon"),k=Object.values(x),I=k.filter(T=>T==="connected").length,p=k.filter(T=>T==="connecting"||T==="new"||T==="checking").length,v=n!=="connected"||b.length===0?null:p>0&&I===0?"P2P connecting...":I>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(qe,{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:g,boxShadow:m}})})]}),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:g,boxShadow:m}}),v&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",v]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[h&&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&&!h&&!ge(t)&&e.jsxs("button",{onClick:()=>u(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Ut,{size:14})," IDE"]}),t&&!h&&!ge(t)&&e.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Ms,{size:16})}),t&&!h&&!ge(t)&&e.jsx("button",{onClick:()=>u(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Le,{size:16})})]})]})}function zs({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:o,onNewChat:c,onSwitchSession:i,onRefreshHistory:u}){var h;const l=s.find(g=>g.id===t.ideId),x=(l==null?void 0:l.chats)||[],d=(h=l==null?void 0:l.activeChat)==null?void 0:h.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:o,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," — ",xe(t.ideType)]})]}),e.jsx("button",{onClick:o,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(g=>e.jsxs("div",{onClick:()=>{i(t.ideId,g.id),o()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${d===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[g.id.substring(0,12),"..."]}),d===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),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(On,{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:u,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(Ts,{size:13})," Refresh History"]})})})]})]})}const ns={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Hs({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:ns[r.type]||ns.info},onClick:()=>{var o;(o=r.actions)!=null&&o.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:o=>{o.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((o,c)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${o.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":o.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(),o.onClick(),s(r.id)},children:o.label},c))})]},r.id))})}const Nr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function kr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function Sr(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 rs(t,s){const n=new Set,r=[];for(const o of s)if(o)for(const c of t[o]||[]){const i=c._localId||`${c.role}:${c.timestamp}:${c.content}`;n.has(i)||(n.add(i),r.push(c))}return r.sort((o,c)=>o.timestamp-c.timestamp)}function Fs(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 Us(t,s,n={}){var m,b,k,I,p,y;const r=[],o=n.machineName,c=n.connectionState,i=kr(t),u=xe(t.type),l=t.agentStreams,x=Array.isArray(l)?l.map(v=>({...v,activeModal:v.activeModal??void 0})):[],d=Nr(t),h=t.activeChat||{title:""},g=h.title&&String(h.title).trim()?String(h.title).trim():"";if(d){const v=t.sessionId||t.instanceId,T=ss(t.type),f=(m=t.activeChat)==null?void 0:m.activeModal,N=f&&Array.isArray(f.buttons)&&f.buttons.length>0,w=me((b=t.activeChat)==null?void 0:b.status,{activeModal:(k=t.activeChat)==null?void 0:k.activeModal})||me((p=(I=t.agents)==null?void 0:I[0])==null?void 0:p.status)||"idle",j=t.activeChat||{title:"",messages:[]};let A=j.title&&String(j.title).trim()?String(j.title).trim():"";const L=(y=t.activeChat)==null?void 0:y.id,D=t.chats;if(L&&Array.isArray(D)&&D.length>0){const C=D.find(H=>H.id===L||H.id&&String(H.id)===String(L));C!=null&&C.title&&String(C.title).trim()&&(A=String(C.title).trim())}const R=j.messages||[],S=rs(s,[t.id,v]),P=new Map;R.filter(C=>C.role==="user").forEach(C=>{const H=xt(C.content);H&&P.set(H,(P.get(H)||0)+1)});const K=S.filter(C=>{const H=xt(C.content),Q=P.get(H)||0;return Q>0?(P.set(H,Q-1),!1):!0});r.push({ideId:t.id,sessionId:v,transport:t.transport,daemonId:t.daemonId||void 0,mode:ye(t)?t.mode||"terminal":"chat",agentName:T,agentType:(ye(t)||ge(t))&&(t.cliType||t.acpType)||t.type,status:w,title:A,messages:[...R,...K],terminalHistory:typeof j.terminalHistory=="string"?j.terminalHistory:"",resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:i,displayPrimary:A||i||(ye(t)||ge(t)?"Terminal":T),displaySecondary:u,cdpConnected:t.cdpConnected,modalButtons:N?f.buttons:void 0,modalMessage:N?f.message:void 0,streamSource:"native",tabKey:t.id,machineName:o,connectionState:c})}if(d&&(ye(t)||ge(t)))return r;for(const v of x){const T=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,f=pr(v),N=Sr(v),w=`${t.id}:${N}`,j=v.title&&String(v.title).trim()||"",A=xr(j,v.agentName,v.agentType)?"":j,L=v.messages||[],D=rs(s,[w,v.sessionId,v.instanceId]),R=new Map;L.filter(P=>P.role==="user").forEach(P=>{const K=xt(P.content);K&&R.set(K,(R.get(K)||0)+1)});const S=D.filter(P=>{const K=xt(P.content),C=R.get(K)||0;return C>0?(R.set(K,C-1),!1):!0});r.push({ideId:t.id,sessionId:v.sessionId||v.instanceId,transport:v.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:f,title:A,messages:[...L,...S],ideType:v.agentType,workspaceName:i,displayPrimary:A||g||i||u,displaySecondary:`${u}·${v.agentName}`,cdpConnected:t.cdpConnected,modalButtons:T?v.activeModal.buttons:void 0,modalMessage:T?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:w,machineName:o,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:ss(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:i,displayPrimary:i||u,displaySecondary:u,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:t.id,connectionState:c}),r}function Cr(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const o=n.get(r.parentId)||[];o.push(r),n.set(r.parentId,o)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Ir(t,s){var m,b,k,I,p,y,v,T;const n=[],{daemonId:r,existingDaemon:o,timestamp:c}=s,i=c||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:l,childrenByParent:x}=Cr(u),d=l.filter(f=>f.kind==="workspace"&&f.transport==="cdp-page"),h=l.filter(f=>f.kind==="agent"&&f.transport==="pty"),g=l.filter(f=>f.kind==="agent"&&f.transport==="acp");n.push({...o||{},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(f=>!!f.cdpConnected)});for(const f of d){const N=x.get(f.id)||[];n.push({id:`${r}:ide:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,status:f.cdpConnected?"online":"detected",daemonId:r,instanceId:f.id,workspace:f.workspace,terminals:0,agents:N.map(w=>({id:w.id,name:w.providerName,type:w.providerType,status:w.status})),activeChat:f.activeChat,chats:[],agentStreams:N.map(w=>{var j,A,L,D;return{sessionId:w.id,instanceId:w.id,parentSessionId:w.parentId,agentType:w.providerType,agentName:w.providerName,extensionId:w.providerType,transport:w.transport,status:me(w.status,{activeModal:(j=w.activeChat)==null?void 0:j.activeModal}),title:w.title,messages:((A=w.activeChat)==null?void 0:A.messages)||[],inputContent:((L=w.activeChat)==null?void 0:L.inputContent)||"",activeModal:((D=w.activeChat)==null?void 0:D.activeModal)||null,model:w.currentModel}}),cdpConnected:f.cdpConnected,currentModel:f.currentModel,currentPlan:f.currentPlan,currentAutoApprove:f.currentAutoApprove,timestamp:i})}for(const f of h){const N=f.runtime;n.push({id:`${r}:cli:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,agentType:f.providerType,status:f.status||"running",daemonId:r,instanceId:f.id,cliName:f.providerName,mode:"terminal",workspace:f.workspace||"",activeChat:f.activeChat,resume:f.resume,runtimeKey:f.runtimeKey??(N==null?void 0:N.runtimeKey),runtimeDisplayName:f.runtimeDisplayName??(N==null?void 0:N.displayName),runtimeWorkspaceLabel:f.runtimeWorkspaceLabel??(N==null?void 0:N.workspaceLabel),runtimeWriteOwner:f.runtimeWriteOwner??(N==null?void 0:N.writeOwner)??null,runtimeAttachedClients:f.runtimeAttachedClients??(N==null?void 0:N.attachedClients)??[],agentStreams:[{sessionId:f.id,instanceId:f.id,parentSessionId:f.parentId,agentType:f.providerType,agentName:f.providerName,extensionId:"cli-agent",transport:f.transport,status:me(f.status,{activeModal:(m=f.activeChat)==null?void 0:m.activeModal}),title:f.title,messages:((b=f.activeChat)==null?void 0:b.messages)||[],inputContent:((k=f.activeChat)==null?void 0:k.inputContent)||"",activeModal:(I=f.activeChat)==null?void 0:I.activeModal}],timestamp:i,_isCli:!0})}for(const f of g){const N=f.runtime;n.push({id:`${r}:acp:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,agentType:f.providerType,status:f.status||"running",daemonId:r,instanceId:f.id,cliName:f.providerName,mode:"chat",workspace:f.workspace||"",activeChat:f.activeChat,runtimeKey:f.runtimeKey??(N==null?void 0:N.runtimeKey),runtimeDisplayName:f.runtimeDisplayName??(N==null?void 0:N.displayName),runtimeWorkspaceLabel:f.runtimeWorkspaceLabel??(N==null?void 0:N.workspaceLabel),runtimeWriteOwner:f.runtimeWriteOwner??(N==null?void 0:N.writeOwner)??null,runtimeAttachedClients:f.runtimeAttachedClients??(N==null?void 0:N.attachedClients)??[],currentModel:f.currentModel,currentPlan:f.currentPlan,acpConfigOptions:f.acpConfigOptions,acpModes:f.acpModes,agentStreams:[{sessionId:f.id,instanceId:f.id,parentSessionId:f.parentId,agentType:f.providerType,agentName:f.providerName,extensionId:"acp-agent",transport:f.transport,status:me(f.status,{activeModal:(p=f.activeChat)==null?void 0:p.activeModal}),title:f.title,messages:((y=f.activeChat)==null?void 0:y.messages)||[],inputContent:((v=f.activeChat)==null?void 0:v.inputContent)||"",activeModal:(T=f.activeChat)==null?void 0:T.activeModal}],timestamp:i,_isAcp:!0})}return n}function Vs(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 Mr(t,s){const n=Vs(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const qs=[{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:"💚"}],Ys=[{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:"🧩"}],Xs=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Gs="adhdev_notification_prefs",as={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Tr(){try{const t=localStorage.getItem(Gs);if(t){const s=JSON.parse(t);return{...as,...s}}}catch{}return{...as}}function Er(t){try{localStorage.setItem(Gs,JSON.stringify(t))}catch{}}let Te=Tr(),bt=[];function Ar(){bt.forEach(t=>t())}function Rr(){return{...Te}}function Lr(t){Te={...Te,...t},Er(Te),Ar()}function _r(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return bt.push(n),()=>{bt=bt.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{Lr(n)},[]);return[{...Te},s]}function nt(t){if(!Te.globalEnabled)return!1;switch(t){case"disconnect":return Te.disconnectAlert;case"completion":return Te.completionAlert;case"approval":return Te.approvalAlert;case"browser":return Te.browserNotifications;default:return!0}}const $r={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Pr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Js(){return"Notification"in window&&Notification.permission==="granted"}let De=null;async function Dr(){if(De!==null)return De;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return De=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(De=!!await t.pushManager.getSubscription(),De):(De=!1,!1)}catch{return De=!1,!1}}function Wt(t,s,n){if(Js())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 Br(t,s={}){const n={...$r,...s},r=a.useRef(new Map),o=a.useRef(0),c=a.useRef(null);a.useEffect(()=>{Dr().then(u=>{c.current=u})},[]);const i=a.useCallback((u,l,x)=>{const d=Date.now();d-o.current<n.throttleMs||(o.current=d,Wt(u,l,x))},[n.throttleMs]);a.useEffect(()=>{var u;if(!(!n.enabled||!Js())&&nt("browser")&&c.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,me(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),d=me(l.status,{activeModal:l.activeModal}),h=l.name||l.id;if(n.onApproval&&nt("approval")&&d==="waiting_approval"&&x!=="waiting_approval"){const g=((u=l.activeModal)==null?void 0:u.message)||"Action requires your approval";i(`🔔 ${h} — Approval needed`,g.slice(0,120),`approval-${l.id}`)}n.onComplete&&nt("completion")&&Ds(x)&&d==="idle"&&i(`✅ ${h} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&x!=="error"&&i(`⚠️ ${h} — 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 Wr{constructor(){ue(this,"dedupMap",new Map);ue(this,"DEDUP_WINDOW_MS",5e3);ue(this,"DEDUP_MAX_SIZE",50);ue(this,"DEDUP_CLEANUP_AGE_MS",1e4);ue(this,"toastCallbacks",[]);ue(this,"systemMessageCallbacks",[]);ue(this,"clearSystemMessageCallbacks",[]);ue(this,"resolveActionFn",null);ue(this,"viewRequestRespondFn",null);ue(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 o=(r==null?void 0:r.id)||Date.now();this.emitToast({id:o,message:s,type:n,timestamp:o,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[o,c]of this.dedupMap)n-c>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(o);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const o=this.ides.find(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(o)return o}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(o=>o.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(o=>o.id.endsWith(`:ide:${s.instanceId}`)||o.id.endsWith(`:cli:${s.instanceId}`))),n){const o=n.daemonId;if(o){const c=this.ides.find(i=>i.id===o&&i.type==="adhdev-daemon");if(c)return c}}const r=this.ides.filter(o=>o.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.agentStreams)?n.agentStreams:[]).some(o=>(o==null?void 0:o.sessionId)===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,h;if(!s.ideId&&s.instanceId){for(const g of this.ides)if(g.id.endsWith(`:ide:${s.instanceId}`)||g.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=g.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=xe(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const g=Xe(u,{fallbackId:u.id});g&&(i=s.ideType==="adhdev-daemon"?g:`${g}/${i}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const g=s.duration?` (${s.duration}s)`:"";l=`✅ ${i} agent task completed${g}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Rr().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${g}`,_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 g=s.modalMessage||"Approval requested",m=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${g}
42
+ ${m}`,_localId:`sys_approval_${Date.now()}`})}if((h=s.modalButtons)!=null&&h.length&&this.resolveActionFn){const g=this.resolveActionRouteTarget(s);if(!g)return;const m=s.agentType||s.ideType||"",b=s.ideType||"",k=s.modalButtons,I=f=>f.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),p=this.resolveActionFn,y=k.map((f,N)=>{const w=I(f).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(w),A=/^(reject|deny|delete|remove|abort|cancel|no)/.test(w);return{label:I(f),variant:j?"primary":A?"danger":"default",onClick:()=>{const L=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w);p(g,"resolve_action",{action:L?"approve":"reject",button:f,buttonIndex:N,agentType:m,ideType:b,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),v=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:v,type:x,timestamp:T,targetKey:r||g,actions:y,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const g=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${i} agent is taking a long time${g}`,x="warning",nt("browser")&&!document.hasFocus()&&Wt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${g.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const g=s.requesterName||"A team member",m=s.requestId,b=s.orgId;if(l=`👁️ ${g} wants to view your session`,x="warning",m&&b&&this.viewRequestRespondFn){const k=this.viewRequestRespondFn,I=Date.now(),p=[{label:"Approve",variant:"primary",onClick:()=>{k(b,m,"approve").catch(y=>console.error("[EventManager] approve view request failed:",y))}},{label:"Decline",variant:"danger",onClick:()=>{k(b,m,"reject").catch(y=>console.error("[EventManager] reject view request failed:",y))}}];this.emitToast({id:I,message:l,type:x,timestamp:I,actions:p,duration:3e4}),l=""}nt("browser")&&!document.hasFocus()&&Wt("👁️ View Request",`${g} wants to view your session`,`view-request-${m}`)}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 g=Date.now();this.emitToast({id:g,message:l,type:x,timestamp:g,targetKey:r||s.ideId,duration:5e3})}}}const _e=new Wr;function ze(...t){return fn(gn(t))}function Or({icon:t,title:s,subtitle:n,badge:r,actions:o,className:c}){return e.jsxs("div",{className:ze("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})]}),o&&e.jsx("div",{className:"flex gap-2",children:o})]})}function Nt({icon:t,title:s,subtitle:n,badge:r,actions:o,widthClassName:c="max-w-6xl",contentClassName:i,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Or,{icon:t,title:s,subtitle:n,badge:r,actions:o}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ze("mx-auto flex w-full flex-col gap-4",c,i),children:u})})]})}function fe({title:t,icon:s,description:n,accentColor:r,className:o,children:c}){return e.jsxs("div",{className:ze("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]",o),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 Vt({icon:t,title:s,description:n,action:r,className:o}){return e.jsxs("div",{className:ze("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),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 Kr={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"},zr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Hr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ze("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Kr[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:zr[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 Fr={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"},Ur={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Vr({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ze("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Fr[t],n),children:[e.jsx("span",{className:ze("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Ur[t])}),r]})}function qr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Ot(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function yt(t){return t==="system"?qr():t}function Yr(){typeof document>"u"||document.documentElement.setAttribute("data-theme",yt(Ot()))}function Xr(){const[t,s]=a.useState(Ot),[n,r]=a.useState(()=>yt(Ot()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),u=l=>{t==="system"&&r(l.matches?"light":"dark")};return i.addEventListener("change",u),()=>i.removeEventListener("change",u)},[t]);const o=a.useCallback(i=>{s(i),r(yt(i));try{localStorage.setItem("theme",i)}catch{}},[]),c=a.useCallback(()=>{s(i=>{const u=i==="dark"?"light":i==="light"?"system":"dark";r(yt(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:n,preference:t,setPreference:o,cycleTheme:c,isDark:n==="dark"}}function We({label:t,description:s,checked:n,disabled:r,onChange:o,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=>o(i.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Gr({onPrefChange:t}){const[s,n]=_r(),r=(o,c)=>{n({[o]:c}),t==null||t(o,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_s,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:o=>r("globalEnabled",o)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:o=>r("browserNotifications",o)}),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(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kn,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:o=>r("completionAlert",o)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(zn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:o=>r("approvalAlert",o)}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:o=>r("disconnectAlert",o)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:o=>r("chatTaskCompletionBubble",o)}),!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 Jr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){const c=t.filter(i=>i.type==="adhdev-daemon");return c.length===0?e.jsx(Vt,{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(Qr,{ide:i,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o},i.id))})}function os({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:o,onCancel:c}){const i=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return bn.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:u=>u.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick: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:o,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,children:n})]})]})}),document.body)}function Zr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...qs,...Ys,...Xs].find(o=>o.id===s||s.includes(o.id)||o.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Qr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){var P,K;const[c,i]=a.useState("idle"),[u,l]=a.useState(""),[x,d]=a.useState(null),[h,g]=a.useState("idle"),[m,b]=a.useState(""),k=t,I=k.version||k.daemonVersion||null,p=((P=k.machine)==null?void 0:P.platform)||((K=k.system)==null?void 0:K.platform)||"",y=Xe(k,{fallbackId:t.id}),v=p==="win32"?"🪟":p==="darwin"?"🍎":"🐧",T=s.filter(C=>C.daemonId===t.id&&C.transport==="cdp-page"),f=s.filter(C=>C.daemonId===t.id&&C.transport==="pty"),N=s.filter(C=>C.daemonId===t.id&&C.transport==="acp"),w=k.p2p,j=async()=>{var C,H,Q;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||(H=J==null?void 0:J.result)!=null&&H.success?(i("done"),l(`Upgraded to v${J.result.version||"latest"}. Daemon is restarting...`)):(i("error"),l(((Q=J==null?void 0:J.result)==null?void 0:Q.error)||"Upgrade failed"))}catch(J){i("error"),l((J==null?void 0:J.message)||"Connection lost during upgrade")}}},A=async()=>{if(d(null),!!r){g("loading");try{await r(t.id),g("done"),b("Machine disconnected.")}catch(C){g("error"),b((C==null?void 0:C.message)||"Failed to disconnect")}}},L=async()=>{if(d(null),!!o){g("loading");try{await o(t.id),g("done"),b('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(C){g("error"),b((C==null?void 0:C.message)||"Failed to revoke token")}}},D="0.7.15",R=!I||I!==D,S=T.length+f.length+N.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:v}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:y}),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),"…"]}),I&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${R?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",I,!R&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&R&&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:h==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),o&&e.jsx("button",{onClick:()=>d("revoke"),disabled:h==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Vr,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[w&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w.state==="connected"?"bg-green-400":w.state==="connecting"||w.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",w.state==="connected"?"connected":w.state==="connecting"||w.state==="new"?"connecting...":w.state||"off"]}),w.peers!==void 0&&w.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",w.peers," peer",w.peers!==1?"s":"",")"]})]}),w&&S>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),S>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(C=>{const H=Zr(C.type),Q=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:H.icon}),e.jsx("span",{children:H.name}),Q!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Q?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:Q?"CDP connected":"CDP connecting..."})]},C.id)}),f.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)),N.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"})]}),(u||m)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||h==="error"?"text-red-400":c==="done"||h==="done"?"text-green-400":"text-text-muted"}`,children:m||u})]}),x==="disconnect"&&e.jsx(os,{title:"🔌 Disconnect Machine",message:`Disconnect "${y}" from ADHDev?
43
43
 
44
44
  This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
45
45
 
46
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:A,onCancel:()=>d(null)}),x==="revoke"&&e.jsx(os,{title:"⚠️ Remove Machine",message:`Remove "${b}" from your dashboard?
46
+ Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:A,onCancel:()=>d(null)}),x==="revoke"&&e.jsx(os,{title:"⚠️ Remove Machine",message:`Remove "${y}" from your dashboard?
47
47
 
48
48
  This will:
49
49
  • Immediately disconnect the machine
50
50
  • Delete the machine registration
51
51
  • Require restarting "adhdev-standalone" on that machine
52
52
 
53
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:R,onCancel:()=>d(null)})]})}const ea=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ta(){const{preference:t,setPreference:s}=Xr();return e.jsx("div",{className:"flex gap-2",children:ea.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 Kt={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},zt={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},sa=[{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"}}}],Zs="adhdev-chat-theme",Qs="adhdev-chat-theme-custom";function jt(){return typeof window>"u"?"ember":localStorage.getItem(Zs)||"ember"}function Ie(t){try{const s=localStorage.getItem(Qs);if(s){const n=JSON.parse(s);return{...t==="dark"?Kt:zt,...n[t]}}}catch{}return t==="dark"?Kt:zt}function ht(t,s){localStorage.setItem(Qs,JSON.stringify({dark:t,light:s}))}function Ne(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${o}, ${s})`}function kt(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),o=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const na={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function rt(t,s){var o;const n=(o=na[t])==null?void 0:o[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",kt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${kt(n,18)})`),r.style.setProperty("--border-accent",Ne(n,.35)),r.style.setProperty("--nav-active-bg",Ne(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ne(n,.06)}`)}function Oe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ne(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ne(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ne(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",Ne(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ne(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",kt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${kt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ne(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ne(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ne(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 ${Ne(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 ra(t){if(localStorage.setItem(Zs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else Yt(),rt(t,Ke()?"dark":"light")}function aa(){const t=jt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else Yt(),rt(t,Ke()?"dark":"light")}function Ke(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function pe({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 Ze({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 oa({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,o]=a.useState(()=>Ie(n));a.useEffect(()=>{o(Ie(n))},[n]);const c=a.useCallback((i,u)=>{o(l=>{const x={...l,[i]:u},p=Ie(n==="dark"?"light":"dark");return n==="dark"?ht(x,p):ht(p,x),Oe(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(Ze,{title:"App Background",children:[e.jsx(pe,{label:"Background",value:r.bgPrimary,onChange:i=>c("bgPrimary",i)}),e.jsx(pe,{label:"Surface",value:r.bgSecondary,onChange:i=>c("bgSecondary",i)}),e.jsx(pe,{label:"Card",value:r.surfacePrimary,onChange:i=>c("surfacePrimary",i)})]}),e.jsxs(Ze,{title:"App Text",children:[e.jsx(pe,{label:"Primary",value:r.textPrimary,onChange:i=>c("textPrimary",i)}),e.jsx(pe,{label:"Secondary",value:r.textSecondary,onChange:i=>c("textSecondary",i)}),e.jsx(pe,{label:"Muted",value:r.textMuted,onChange:i=>c("textMuted",i)})]}),e.jsxs(Ze,{title:"Borders & Accent",children:[e.jsx(pe,{label:"Border subtle",value:r.borderSubtle,onChange:i=>c("borderSubtle",i)}),e.jsx(pe,{label:"Border default",value:r.borderDefault,onChange:i=>c("borderDefault",i)}),e.jsx(pe,{label:"Accent",value:r.accentColor,onChange:i=>c("accentColor",i)})]})]}),e.jsxs("div",{children:[e.jsxs(Ze,{title:"Chat Bubbles",children:[e.jsx(pe,{label:"User bubble",value:r.userBubble,onChange:i=>c("userBubble",i)}),e.jsx(pe,{label:"User text",value:r.userText,onChange:i=>c("userText",i)}),e.jsx(pe,{label:"Agent bubble",value:r.assistantBubble,onChange:i=>c("assistantBubble",i)}),e.jsx(pe,{label:"Agent text",value:r.assistantText,onChange:i=>c("assistantText",i)})]}),e.jsxs(Ze,{title:"Chat Layout",children:[e.jsx(pe,{label:"Chat BG",value:r.containerBg,onChange:i=>c("containerBg",i)}),e.jsx(pe,{label:"Send button",value:r.sendButton,onChange:i=>c("sendButton",i)}),e.jsx(pe,{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?Kt:zt,l=Ie(t?"light":"dark");t?ht(i,l):ht(l,i),o(i),Oe(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 ia(){const[t,s]=a.useState(jt),[n,r]=a.useState(!0),[o,c]=a.useState(()=>Ie("dark"));a.useEffect(()=>{r(Ke());const l=new MutationObserver(()=>{const p=Ke();r(p);const g=jt();g==="custom"?Oe(Ie(p?"dark":"light")):rt(g,p?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const p=Ke();r(p);const g=jt();g==="custom"?Oe(Ie(p?"dark":"light")):rt(g,p?"dark":"light")};return x.addEventListener("change",d),()=>{l.disconnect(),x.removeEventListener("change",d)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Oe(Ie(n?"dark":"light")):(Yt(),rt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{c(Ie(n?"dark":"light"))},[n]);const i=l=>{s(l),ra(l)},u=[...sa,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText},light:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(l=>{const x=t===l.id,d=n?l.preview.dark:l.preview.light,p=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?o.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:p},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(oa,{dark:n,onColorsChange:l=>c(l)})]})}const en="adhdev_hiddenTabs";function ca(){try{const t=localStorage.getItem(en);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Qe(t){try{localStorage.setItem(en,JSON.stringify([...t]))}catch{}}function tn(){const[t,s]=a.useState(ca),n=a.useCallback(l=>{s(x=>{const d=new Set(x);return d.has(l)?d.delete(l):d.add(l),Qe(d),d})},[]),r=a.useCallback(l=>{s(x=>{if(x.has(l))return x;const d=new Set(x);return d.add(l),Qe(d),d})},[]),o=a.useCallback(l=>{s(x=>{if(!x.has(l))return x;const d=new Set(x);return d.delete(l),Qe(d),d})},[]),c=a.useCallback((l,x)=>{s(d=>{const p=new Set(d);for(const g of x)p.add(g);return Qe(p),p})},[]),i=a.useCallback((l,x)=>{s(d=>{const p=new Set(d);for(const g of x)p.delete(g);return Qe(p),p})},[]),u=a.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:o,hideAllForDaemon:c,showAllForDaemon:i,isHidden:u}}const At=new Set,la={emit(t,s){for(const n of At)n(t,s)},on(t){return At.add(t),()=>{At.delete(t)}}};function sn({conversations:t,visibleConversations:s,clearedTabs:n,setClearedTabs:r,setActionLogs:o}){const c=a.useRef(new Map);a.useEffect(()=>{Pr()},[]);const i=a.useMemo(()=>s.map(u=>({id:u.tabKey,name:u.title||u.agentName||u.ideId,status:u.status,activeModal:u.modalMessage?{message:u.modalMessage,buttons:u.modalButtons}:null})),[s]);return Br(i),a.useEffect(()=>{if(Object.keys(n).length===0)return;const l=setTimeout(()=>{r(x=>{const d=Date.now(),p={};for(const[g,f]of Object.entries(x))d-f<5e3&&(p[g]=f);return Object.keys(p).length===Object.keys(x).length?x:p})},5500);return()=>clearTimeout(l)},[n,r]),a.useEffect(()=>{const u=setInterval(()=>{const l=Date.now()-3e5;o(x=>{const d=x.filter(p=>p.timestamp>l).slice(-100);return d.length===x.length?x:d})},6e4);return()=>clearInterval(u)},[o]),a.useEffect(()=>{const u=(x,d)=>{if(d){la.emit(x,d);for(const p of t){if(!ye(p)||!(x===p.sessionId||x===p.ideId||x===p.tabKey))continue;const f=c.current.get(p.tabKey)||[];f.push(d),f.length>1e4&&f.splice(0,f.length-5e3),c.current.set(p.tabKey,f)}}},l=he.onPtyOutput(u);return()=>{l()}},[t]),{ptyBuffers:c}}function da(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const o=n.get(r.id);if(!o){n.set(r.id,r);continue}const c=(o.workspace?1:0)+(o.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>c||(r.timestamp||0)>(o.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function pt(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 ua(t,s){const n=Date.now();return t.map(r=>{const o=s[r.tabKey];return o&&n-o<5e3?{...r,messages:[],title:""}:r})}function xa(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 o of t.agentStreams||[]){const c=o.sessionId||o.instanceId||o.agentType,i=`${t.id}:${c}`;n.push({key:i,ref:s[i]}),o.sessionId&&n.push({key:o.sessionId,ref:s[o.sessionId]}),o.instanceId&&n.push({key:o.instanceId,ref:s[o.instanceId]})}return n}function ha(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 pa({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:o}){const c=a.useRef([]),i=a.useRef([]),u=a.useRef([]),l=a.useRef([]),x=a.useMemo(()=>{const b=da(t);return pt(c.current,b)?c.current:(c.current=b,b)},[t]),d=a.useMemo(()=>Us(t),[t]),p=a.useRef(new Map),g=a.useMemo(()=>{var T;const b=new Map,v=[];for(const m of x){const N=m.daemonId||((T=m.id)==null?void 0:T.split(":")[0])||m.id,w=s[N]||"new",y=m.daemonId&&d[m.daemonId]||void 0,A=xa(m,n),R=p.current.get(m.id);if(R&&R.ide===m&&R.connectionState===w&&R.machineName===y&&ha(R.localRefs,A)){b.set(m.id,R),v.push(...R.conversations);continue}const D=Fs(m,n,{machineName:y,connectionState:w}),L={ide:m,connectionState:w,machineName:y,localRefs:A,conversations:D};b.set(m.id,L),v.push(...D)}return p.current=b,v},[x,n,s,d]),f=a.useMemo(()=>{const b=ua(g,r);return pt(i.current,b)?i.current:(i.current=b,b)},[g,r]),j=a.useMemo(()=>{const b=new Map;for(const v of f)v.sessionId&&b.set(v.sessionId,v),b.set(v.ideId,v),b.set(v.tabKey,v),b.set(v.ideType,v),b.set(v.agentType,v);return b},[f]),k=a.useCallback(b=>{if(b)return j.get(b)},[j]),I=a.useMemo(()=>{const b=f.filter(v=>!o.has(v.tabKey));return pt(u.current,b)?u.current:(u.current=b,b)},[f,o]),h=a.useMemo(()=>{const b=I.map(v=>v.tabKey);return pt(l.current,b)?l.current:(l.current=b,b)},[I]);return{chatIdes:x,conversations:f,visibleConversations:I,visibleTabKeys:h,resolveConversationByTarget:k}}function nn({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:o}){a.useEffect(()=>{_e.setIdes(t)},[t]),a.useEffect(()=>{_e.setResolveAction((c,i,u)=>{s(c,i,u).catch(()=>{})})},[s]),a.useEffect(()=>{const c=_e.onToast(l=>{n(d=>d.some(g=>g.message===l.message&&l.timestamp-g.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(p=>p.id!==l.id)),x)}),i=_e.onSystemMessage((l,x)=>{r(d=>({...d,[l]:[...d[l]||[],x]}))}),u=_e.onClearSystemMessage((l,x)=>{r(d=>{var p;return(p=d[l])!=null&&p.length?{...d,[l]:d[l].filter(g=>{var f;return!(g.role==="system"&&((f=g._localId)!=null&&f.startsWith(x)))})}:d})});return()=>{c(),i(),u()}},[n,r]),a.useEffect(()=>{const c=Ks.on("status_event",i=>_e.handleRawEvent(i,"ws"));return()=>{c()}},[]),a.useEffect(()=>{var i;const c=u=>{const l=u.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=o(x),p=(d==null?void 0:d.ideId)||l.ideId;p&&s(p,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(g=>console.error("[SW Action] approve failed:",g))};return(i=navigator.serviceWorker)==null||i.addEventListener("message",c),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",c)}},[o,s])}const ma="adhdev_dashboardLayout_v1",et={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"},tt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function st(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function fa(t){try{return localStorage.getItem(t)}catch{return null}}function ga(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function rn(t){return`${ma}:${t}`}function ba(){const t=fa(et.focusedGroup),s=st(et.splitGroups,[]),n=st(et.groupActiveTabs,{}),r=st(et.groupTabOrders,{}),o=st(et.splitSizes,[]);return t!==null||s.length>0||Object.keys(n).length>0||Object.keys(r).length>0||o.length>0?{groupAssignments:s,focusedGroup:t&&parseInt(t,10)||0,groupActiveTabIds:n,groupTabOrders:r,groupSizes:o}:null}function ya(t){const s=rn(t),n=st(s,null);return n||ba()}function ja(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=rn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function va(){return{groupAssignments:[...tt.groupAssignments],focusedGroup:tt.focusedGroup,groupActiveTabIds:{...tt.groupActiveTabIds},groupTabOrders:{...tt.groupTabOrders},groupSizes:[...tt.groupSizes]}}function wa(){const[t]=a.useState(()=>ga(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,o]=a.useState(0),[c,i]=a.useState({}),[u,l]=a.useState({}),[x,d]=a.useState([]),[p,g]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[f,j]=a.useState(!1),k=a.useCallback(()=>{if(f)return;const I=ya(t)??va();n(new Map(I.groupAssignments)),o(I.focusedGroup),i(I.groupActiveTabIds),l(I.groupTabOrders),d(I.groupSizes),j(!0)},[f,t]);return a.useEffect(()=>{f&&ja(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:c,groupTabOrders:u,groupSizes:x})},[f,t,s,r,c,u,x]),a.useEffect(()=>{const I=window.matchMedia("(max-width: 767px)"),h=b=>g(b.matches);return I.addEventListener("change",h),()=>I.removeEventListener("change",h)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:o,groupActiveTabIds:c,setGroupActiveTabIds:i,groupTabOrders:u,setGroupTabOrders:l,groupSizes:x,setGroupSizes:d,isMobile:p,hasHydratedStoredLayout:f,hydrateStoredLayout:k}}function Na({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:o,hydrateStoredLayout:c,setGroupActiveTabIds:i,setFocusedGroup:u,setSearchParams:l,historyModalOpen:x,activeConv:d,isRefreshingHistory:p,ides:g,handleRefreshHistory:f,isSplitMode:j,splitTabRelative:k,numGroups:I,clearAllSplits:h}){const b=a.useRef(!1),v=a.useRef(!1),T=a.useRef(null),m=a.useRef(!1);a.useEffect(()=>{if(!t||b.current||s.length===0)return;if(!o){c();return}const N=n(t);if(!N)return;const w=r.get(N.tabKey)??0;i(y=>({...y,[w]:N.tabKey})),u(w),b.current=!0,v.current=!0,T.current!=null&&(window.clearTimeout(T.current),T.current=null),l(y=>{const A=new URLSearchParams(y);return A.delete("activeTab"),A},{replace:!0})},[t,s,n,r,o,c,i,u,l]),a.useEffect(()=>{if(!(v.current||o)&&s.length!==0){if(!t){c(),v.current=!0;return}if(b.current){v.current=!0;return}if(T.current==null)return T.current=window.setTimeout(()=>{T.current=null,!(v.current||o)&&(c(),v.current=!0)},1500),()=>{T.current!=null&&(window.clearTimeout(T.current),T.current=null)}}},[t,s.length,o,c]),a.useEffect(()=>{if(!x){m.current=!1;return}if(!d||m.current||p)return;const N=g.find(w=>w.id===d.ideId);N&&(!N.chats||N.chats.length===0)&&(m.current=!0,f())},[x,d,p,g,f]),a.useEffect(()=>{const N=w=>{if(w.ctrlKey&&w.key==="\\"){if(w.preventDefault(),j)h();else{const y=s[1];y&&k(y.tabKey,0,"right")}return}w.ctrlKey&&(w.key==="["||w.key==="]")&&j&&(w.preventDefault(),u(y=>w.key==="]"?Math.min(y+1,I-1):Math.max(y-1,0)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[j,s,k,I,h,u]),a.useEffect(()=>{if(!d)return;let N=null,w=0,y=-1,A=0;const R=()=>{N=null;const D=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(S=>S.offsetParent!==null);if(D.length===0){w<18&&(w+=1,N=requestAnimationFrame(R));return}let L=0;for(const S of D)S.scrollTop=S.scrollHeight,L+=S.scrollHeight;L===y?A+=1:(A=0,y=L),w+=1,!(A>=2||w>=18)&&(N=requestAnimationFrame(R))};return N=requestAnimationFrame(R),()=>{N!=null&&cancelAnimationFrame(N)}},[d==null?void 0:d.tabKey])}function Le(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return ye(t)||ge(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function St(t){return t&&(t.ideId||t.daemonId)||""}function mt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function ka({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:o,setClearedTabs:c}){const[i,u]=a.useState(!1),[l,x]=a.useState(!1),d=a.useCallback(async j=>{try{await t("standalone","launch_ide",{ideType:j,enableCdp:!0})}catch(k){console.error("Launch failed",k)}},[t]),p=a.useCallback(async(j,k)=>{try{const I=j||(s==null?void 0:s.daemonId)||"",h=await t(I,"switch_chat",{id:k,sessionId:k,...Le(s)}),b=h==null?void 0:h.result;if((h==null?void 0:h.success)===!0||b==="switched"||b==="switched-by-title")return;b===!1||b==="not_found"?mt(r,"⚠️ Session tab not found — try refreshing history"):typeof b=="string"&&b.startsWith("error:")?mt(r,`⚠️ Switch error: ${b}`):mt(r,"⚠️ Session switch failed")}catch(I){console.error("Switch failed",I),mt(r,`❌ Switch failed: ${I.message||"connection error"}`)}},[s,t,r]),g=a.useCallback(async()=>{if(!(!s||i)){u(!0);try{const j=St(s);await t(j,"new_chat",{...Le(s)}),c(k=>({...k,[s.tabKey]:Date.now()})),o(k=>({...k,[s.tabKey]:[]}))}catch(j){console.error("New chat failed",j)}finally{u(!1)}}},[s,i,t,c,o]),f=a.useCallback(async()=>{var j;if(!(!s||l)){x(!0);try{const k=St(s),I=await t(k,"list_chats",{forceExpand:!0,...Le(s)}),h=(I==null?void 0:I.chats)||((j=I==null?void 0:I.result)==null?void 0:j.chats);I!=null&&I.success&&Array.isArray(h)&&n(s.ideId,h)}catch(k){console.error("Refresh history failed",k)}finally{x(!1)}}},[s,l,t,n]);return{isCreatingChat:i,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:p,handleNewChat:g,handleRefreshHistory:f}}function Sa(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 Ca(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function is(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(o=>s[Number(o)]===t[Number(o)])}function ft(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[i,u]of t)!n.has(i)||u<=0||r.includes(u)||r.push(u);r.sort((i,u)=>i-u);const o={};r.forEach((i,u)=>{o[i]=u}),r.length===0&&(o[0]=0);const c=new Map;for(const[i,u]of t){if(!n.has(i)||u<=0)continue;const l=o[u];typeof l=="number"&&l>0&&c.set(i,l)}return{assignments:c,groupCount:Math.max(1,r.length),mapping:o,usedGroups:r}}function cs(t,s){const n={};for(const[r,o]of Object.entries(t)){const c=s[Number(r)];typeof c=="number"&&(n[c]=o)}return n}function Ia(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(o=>o<t)??s[0];return n[r]??0}function Ma(t,s,n){if(s.length<=1)return[];const r=s.map(i=>t[i]).filter(i=>Number.isFinite(i)),o=r.length===s.length?r:Array(n).fill(100/n),c=o.reduce((i,u)=>i+u,0);return c>0?o.map(i=>i/c*100):Array(n).fill(100/n)}function ls(t,s){const n={};for(const[r,o]of Object.entries(t)){const c=Number(r);n[c>=s?c+1:c]=o}return n}function ds(t){return Array(t).fill(100/t)}function Ta({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:o,groupSizes:c,setGroupSizes:i,isMobile:u,visibleConversations:l,visibleTabKeys:x}){const d=a.useRef(null),p=a.useMemo(()=>ft(t,x),[t,x]),g=p.assignments,f=a.useMemo(()=>u?1:p.groupCount,[p.groupCount,u]),j=f>1,k=a.useCallback((m,N)=>{s(w=>{const y=new Map(ft(w,x).assignments);return N===0?y.delete(m):y.set(m,N),y}),r(w=>({...w,[N]:m})),n(N)},[s,x,r,n]),I=a.useCallback(m=>{s(N=>{const w=ft(N,x).assignments,y=new Map;for(const[A,R]of w)R!==m&&(R>m?y.set(A,R-1):y.set(A,R));return y}),i(N=>{if(N.length<=1)return[];const w=[...N];w.splice(m,1);const y=w.reduce((A,R)=>A+R,0);return y>0?w.map(A=>A/y*100):[]}),n(0)},[s,x,i,n]),h=a.useCallback((m,N)=>{N.preventDefault();const w=d.current;if(!w)return;const y=N.clientX,A=w.offsetWidth,R=c.length===f?[...c]:ds(f),D=S=>{const K=(S.clientX-y)/A*100,C=[...R];C[m]=Math.max(15,R[m]+K),C[m+1]=Math.max(15,R[m+1]-K),i(C)},L=()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",L),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",D),document.addEventListener("mouseup",L)},[c,f,i]),b=a.useCallback((m,N,w)=>{if(f>=4)return;const y=w==="left"?N:N+1;s(A=>{const R=ft(A,x).assignments,D=new Map;for(const L of l){const S=R.get(L.tabKey)??0,P=S>=y?S+1:S;P>0&&D.set(L.tabKey,P)}return y>0&&D.set(m,y),D}),i(A=>{const R=A.length===f?[...A]:ds(f),D=R[N]??100/f,L=Math.max(15,D/2),S=Math.max(15,D/2),P=[...R];P[N]=L,P.splice(y,0,S);const K=P.reduce((C,H)=>C+H,0);return P.map(C=>C/K*100)}),r(A=>{const R=ls(A,y);return R[y]=m,R}),o(A=>{const R=ls(A,y);return R[y]=[m],R}),n(y)},[f,s,x,l,i,r,o,n]);a.useEffect(()=>{Sa(t,g)||s(g)},[t,g,s]),a.useEffect(()=>{const{mapping:m,usedGroups:N}=p;r(w=>{const y=cs(w,m);return is(w,y)?w:y}),o(w=>{const y=cs(w,m);return is(w,y)?w:y}),n(w=>{const y=u?0:Ia(w,N,m);return w===y?w:y}),i(w=>{const y=u?[]:Ma(w,N,p.groupCount);return Ca(w,y)?w:y})},[p,u,r,o,n,i]);const v=a.useMemo(()=>{const m=Array.from({length:f},()=>[]);for(const N of l){const w=g.get(N.tabKey)??0,y=Math.min(w,f-1);m[y].push(N)}return m},[l,g,f]),T=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:g,numGroups:f,isSplitMode:j,groupedConvs:v,moveTabToGroup:k,closeGroup:I,handleResizeStart:h,splitTabRelative:b,clearAllSplits:T}}function Ea({ides:t,sendDaemonCommand:s}){const n=a.useMemo(()=>t.filter(l=>l.type==="adhdev-daemon"&&l.versionMismatch),[t]),[r,o]=a.useState(!1),[c,i]=a.useState({}),u=a.useCallback(async l=>{var x,d;i(p=>({...p,[l]:"upgrading"}));try{const p=await s(l,"daemon_upgrade",{});(x=p==null?void 0:p.result)!=null&&x.upgraded||(d=p==null?void 0:p.result)!=null&&d.success?i(g=>({...g,[l]:"done"})):i(g=>({...g,[l]:"error"}))}catch{i(p=>({...p,[l]:"error"}))}},[s]);return{versionMismatchDaemons:n,versionBannerDismissed:r,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:u}}function an({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:o}){const[c,i]=a.useState(!1),[u,l]=a.useState(!1),x=a.useRef(!1),d=a.useCallback(async j=>{if(!s)return;const k=j.trim();if(!k||x.current)return;const I=s.tabKey;x.current=!0,l(!0);const h=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,b={role:"user",content:k,timestamp:Date.now(),_localId:h};n(v=>({...v,[I]:[...v[I]||[],b]}));try{const v=St(s);if(!v)return;await t(v,"send_chat",{message:k,text:k,...Le(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(m=>{const N=m[I];if(!N)return m;const w=N.filter(y=>y.timestamp>T);return w.length===N.length?m:{...m,[I]:w}})},6e4)}catch(v){console.error("Send failed",v),n(T=>({...T,[I]:(T[I]||[]).filter(m=>m._localId!==h)}))}finally{x.current=!1,l(!1)}},[s,t,n]),p=a.useCallback(async()=>{if(s)try{if(o){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(j){console.error("Relaunch failed",j)}},[s,o,t]),g=a.useCallback(async j=>{if(s){r(k=>[...k,{ideId:s.tabKey,text:`🖱️ **${j}** clicked`,timestamp:Date.now()}]);try{const I=(s.modalButtons||[]).indexOf(j),h=j.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),b=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(h),v=St(s);if(!v)return;(await t(v,"resolve_action",{button:j,action:b?"approve":"reject",...I>=0&&{buttonIndex:I},...Le(s)})).success||r(m=>[...m,{ideId:s.tabKey,text:`⚠️ **${j}** failed — button not found`,timestamp:Date.now()}])}catch(k){console.error("[ModalButton] Error:",k),r(I=>[...I,{ideId:s.tabKey,text:`❌ **${j}** error`,timestamp:Date.now()}])}}},[s,t,r]),f=a.useCallback(async()=>{if(!(!s||c)){i(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(j){console.error("Focus agent failed",j)}finally{i(!1)}}},[s,c,t]);return{isSendingChat:u,isFocusingAgent:c,handleSendChat:d,handleRelaunch:p,handleModalButton:g,handleFocusAgent:f}}function Lt(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Aa({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:o,onClearPreviewOrder:c}){const i=a.useRef(0),[u,l]=a.useState(!1),[x,d]=a.useState(null),p=a.useCallback(()=>{i.current=0,l(!1),d(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",p),window.addEventListener("drop",p),()=>{window.removeEventListener("dragend",p),window.removeEventListener("drop",p)}),[p]);const g=a.useCallback(I=>{I.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,l(!0))},[]),f=a.useCallback(I=>{if(!I.dataTransfer.types.includes("text/tab-key"))return;if(I.preventDefault(),!Lt(s,n)){d("merge");return}const h=I.currentTarget.getBoundingClientRect(),b=I.clientX-h.left,v=h.width/3;b<v?d("split-left"):b>v*2?d("split-right"):d("merge")},[s,n]),j=a.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,l(!1),d(null))},[]),k=a.useCallback(I=>{i.current=0,l(!1);const h=I.dataTransfer.getData("text/tab-key"),b=h?t.some(T=>T.tabKey===h):!1,v=x;if(d(null),c(),!!h){if(I.preventDefault(),v==="split-left"&&Lt(s,n)){n==null||n(h,"split-left");return}if(v==="split-right"&&Lt(s,n)){n==null||n(h,"split-right");return}if(b){o(h);return}r==null||r(h)}},[t,x,s,n,r,o,c]);return{dragOver:u,dropAction:x,resetDragState:p,handleDragEnter:g,handleDragOver:f,handleDragLeave:j,handleDrop:k}}function La(t,s){const n=new Set(s.map(c=>c.tabKey)),r=t.filter(c=>n.has(c)),o=s.filter(c=>!t.includes(c.tabKey)).map(c=>c.tabKey);return[...r,...o]}function Ra({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:o}){const[c,i]=a.useState(s??null),[u,l]=a.useState(n??[]),[x,d]=a.useState(null),p=a.useRef(null),g=a.useRef(null),f=a.useRef(r),j=a.useRef(o);a.useEffect(()=>{f.current=r},[r]),a.useEffect(()=>{j.current=o},[o]),a.useEffect(()=>{s&&s!==c&&i(s)},[s,c]),a.useEffect(()=>{l(w=>{const y=La(w,t);return y.length===w.length&&y.every((A,R)=>A===w[R])?w:y})},[t]);const k=a.useMemo(()=>{const w=x??u;if(w.length===0)return t;const y=new Map(w.map((A,R)=>[A,R]));return[...t].sort((A,R)=>{const D=y.get(A.tabKey)??999,L=y.get(R.tabKey)??999;return D-L})},[t,x,u]);a.useEffect(()=>{var y,A;if(k.length===0){c!==null&&(i(null),(y=f.current)==null||y.call(f,null));return}if(c&&k.some(R=>R.tabKey===c))return;const w=k[0].tabKey;w!==c&&(i(w),(A=f.current)==null||A.call(f,w))},[k,c]);const I=a.useMemo(()=>k.find(w=>w.tabKey===c),[k,c]),h=a.useCallback(w=>{var y;i(w),(y=f.current)==null||y.call(f,w)},[]),b=a.useCallback((w,y,A)=>{l(R=>{var P;const D=R.filter(K=>K!==w),L=D.indexOf(y);if(L<0)return R;const S=A==="left"?L:L+1;return D.splice(S,0,w),(P=j.current)==null||P.call(j,D),D}),d(null)},[]),v=a.useCallback((w,y,A)=>{const D=(u.length>0?u:t.map(P=>P.tabKey)).filter(P=>P!==w),L=D.indexOf(y);if(L<0)return;const S=A==="left"?L:L+1;D.splice(S,0,w),p.current=D,d(D)},[u,t]),T=a.useCallback(()=>{var y;const w=p.current;w&&(l(w),(y=j.current)==null||y.call(j,w))},[]),m=a.useCallback(()=>{p.current=null,d(null)},[]),N=a.useCallback(w=>{l(y=>{var R;const A=y.filter(D=>D!==w);return A.push(w),(R=j.current)==null||R.call(j,A),A})},[]);return{activeTabId:c,activeConv:I,sortedConversations:k,previewOrderRef:p,draggingTabRef:g,selectTab:h,handleTabReorder:b,updatePreviewOrder:v,commitPreviewOrder:T,clearPreviewOrder:m,moveTabToEnd:N,setDraggingTabKey:w=>{g.current=w}}}const _a=a.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:o,screenshotUrl:c,clearScreenshot:i,ptyBuffers:u,terminalRef:l,handleModalButton:x,handleRelaunch:d,handleSendChat:p,isSendingChat:g,handleFocusAgent:f,isFocusingAgent:j,actionLogs:k,userName:I}){const h=a.useCallback(()=>{i()},[i]);return e.jsxs(e.Fragment,{children:[e.jsx(Ps,{activeConv:s,onModalButton:x}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&c?e.jsx(nr,{screenshotUrl:c,mode:"preview",onDismiss:h}):!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:d,children:"Relaunch with CDP"})]}):null}),r?e.jsx(jr,{activeConv:s,clearToken:n,ptyBuffers:u,terminalRef:l,handleSendChat:p,isSendingChat:g}):e.jsx(Ws,{activeConv:s,ideEntry:o,handleSendChat:p,isSendingChat:g,handleFocusAgent:f,isFocusingAgent:j,actionLogs:k,userName:I})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.ptyBuffers===s.ptyBuffers&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function $a({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 Rt={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 Pa(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Da(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[o,c]=a.useState(!1),i=t==="unix"?"unix":n;a.useEffect(()=>{s(Pa())},[]);const u=a.useCallback(()=>{navigator.clipboard.writeText(Rt[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:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Rt[i].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Rt[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:o?"✓":"📋"})]}),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 Ba({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:o}){return t===0&&!s&&r&&o?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"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(Da,{}),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:()=>o(c.type),children:[e.jsx(Ls,{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"})}const on="adhdev-tab-shortcuts";function Wa(){try{return JSON.parse(localStorage.getItem(on)||"{}")}catch{return{}}}function Oa({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,c]=a.useState(()=>Wa()),[i,u]=a.useState(null),l=a.useCallback(d=>{const p=[];return d.metaKey&&p.push(r?"⌘":"Meta"),d.ctrlKey&&p.push("Ctrl"),d.altKey&&p.push(r?"⌥":"Alt"),d.shiftKey&&p.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(p.push(d.key.length===1?d.key.toUpperCase():d.key),p.join("+"))},[r]),x=a.useCallback(d=>{c(d);try{localStorage.setItem(on,JSON.stringify(d))}catch{}},[]);return a.useEffect(()=>{if(!i)return;const d=p=>{if(p.preventDefault(),p.stopPropagation(),p.key==="Escape"){u(null);return}const g=l(p);if(!g)return;const f={...o};for(const[j,k]of Object.entries(f))k===g&&delete f[j];f[i]=g,x(f),u(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[i,o,x,l]),a.useEffect(()=>{const d=p=>{if(!(!p.ctrlKey&&!p.metaKey&&!p.altKey)){for(const[g,f]of Object.entries(o))if(t.includes(g)&&l(p)===f){p.preventDefault(),s(),n(g);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[o,t,s,n,l]),{isMac:r,tabShortcuts:o,shortcutListening:i,setShortcutListening:u,saveShortcuts:x}}const Ka=a.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:o,conversationKeys:c,draggingTabRef:i,onFocus:u,onSelectTab:l,onConversationActivated:x,onPreviewReorder:d,onReorderTab:p,onCommitPreviewOrder:g,onClearPreviewOrder:f,onDragStateReset:j,onDragTabKeyChange:k,onReceiveTab:I,onOpenContextMenu:h,longPressTimer:b}){const v=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",T=s.connectionState==="failed"||s.connectionState==="closed",m=a.useCallback(S=>{i.current=s.tabKey,k(s.tabKey),S.dataTransfer.setData("text/tab-key",s.tabKey),S.dataTransfer.effectAllowed="move"},[s.tabKey,i,k]),N=a.useCallback(()=>{i.current=null,k(null),g(),f(),j()},[i,k,g,f,j]),w=a.useCallback(S=>{const P=i.current;if(!(!P||P===s.tabKey)&&S.dataTransfer.types.includes("text/tab-key")){S.preventDefault(),S.stopPropagation();const K=S.currentTarget.getBoundingClientRect(),C=S.clientX<K.left+K.width/2?"left":"right";d(P,s.tabKey,C)}},[s.tabKey,i,d]),y=a.useCallback(S=>{S.preventDefault(),S.stopPropagation();const P=S.dataTransfer.getData("text/tab-key");if(P&&P!==s.tabKey){const K=S.currentTarget.getBoundingClientRect(),C=S.clientX<K.left+K.width/2?"left":"right";c.includes(P)?p(P,s.tabKey,C):I&&I(P)}f()},[s.tabKey,c,p,I,f]),A=a.useCallback(S=>{S.stopPropagation(),u(),l(s.tabKey),x(s)},[s,x,u,l]),R=a.useCallback(S=>{S.preventDefault(),h(S.clientX,S.clientY,s.tabKey)},[s.tabKey,h]),D=a.useCallback(S=>{const P=S.touches[0];b.current=setTimeout(()=>{h(P.clientX,P.clientY,s.tabKey)},600)},[s.tabKey,b,h]),L=a.useCallback(()=>{b.current&&clearTimeout(b.current)},[b]);return e.jsxs("div",{"data-tabkey":s.tabKey,className:`${v} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:m,onDragEnd:N,onDragOver:w,onDrop:y,onClick:A,onContextMenu:R,onTouchStart:D,onTouchEnd:L,onTouchMove:L,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]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function za({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:o,onFocus:c,onSelectTab:i,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:p,onDragStateReset:g,onDragTabKeyChange:f,onMoveTab:j,onReceiveTab:k,onHideTab:I}){const[h,b]=a.useState(null),v=a.useRef(null),T=a.useRef(null),m=a.useMemo(()=>t.map(L=>L.tabKey),[t]);ct("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(h==null?void 0:h.tabKey)||null});const{isMac:N,tabShortcuts:w,shortcutListening:y,setShortcutListening:A,saveShortcuts:R}=Oa({sortedTabKeys:t.map(L=>L.tabKey),onFocus:c,onSelectTab:i});a.useEffect(()=>{if(!h)return;const L=S=>{const P=document.querySelector("[data-pane-context-menu]");P&&P.contains(S.target)||b(null)};return window.addEventListener("mousedown",L,!0),()=>window.removeEventListener("mousedown",L,!0)},[h]),a.useEffect(()=>{const L=T.current;if(!L)return;const S=P=>{Math.abs(P.deltaY)>Math.abs(P.deltaX)&&(P.preventDefault(),L.scrollLeft+=P.deltaY)};return L.addEventListener("wheel",S,{passive:!1}),()=>L.removeEventListener("wheel",S)},[]);const D=a.useCallback((L,S,P)=>{b({x:L,y:S,tabKey:P})},[]);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(L=>e.jsx(Ka,{conv:L,isActive:s===L.tabKey,isDraggedTab:o.current===L.tabKey,shortcut:w[L.tabKey],conversationKeys:m,draggingTabRef:o,onFocus:c,onSelectTab:i,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:p,onDragStateReset:g,onDragTabKeyChange:f,onReceiveTab:k,onOpenContextMenu:D,longPressTimer:v},L.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),h&&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:h.x,top:h.y},children:[j&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{j(h.tabKey,"left"),b(null)},children:"← Move to Left Group"}),j&&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:()=>{j(h.tabKey,"right"),b(null)},children:"Move to Right Group →"}),j&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{j(h.tabKey,"split-left"),b(null)},children:"⇤ Split Left"}),j&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{j(h.tabKey,"split-right"),b(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:L=>{L.stopPropagation(),A(h.tabKey),b(null)},children:["⌨ ",w[h.tabKey]?`Change shortcut (${w[h.tabKey]})`:"Set shortcut"]}),w[h.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 L={...w};delete L[h.tabKey],R(L),b(null)},children:"✕ Remove shortcut"}),I&&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:()=>{I(h.tabKey),b(null)},children:"🚫 Hide from Dashboard"})]}),!j&&!I&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),y&&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:()=>A(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:L=>L.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function Ha({conversations:t,ides:s,clearedTabs:n,actionLogs:r,ptyBuffers:o,screenshotMap:c,setScreenshotMap:i,sendDaemonCommand:u,setLocalUserMessages:l,setActionLogs:x,isStandalone:d,userName:p,groupIndex:g,onFocus:f,isSplitMode:j,numGroups:k,onMoveTab:I,onReceiveTab:h,style:b,detectedIdes:v,handleLaunchIde:T,onActiveTabChange:m,initialActiveTabId:N,initialTabOrder:w,onTabOrderChange:y,onHideTab:A}){const{sendCommand:R}=Pe(),D=a.useRef(null),{activeTabId:L,activeConv:S,sortedConversations:P,draggingTabRef:K,selectTab:C,handleTabReorder:H,updatePreviewOrder:Q,commitPreviewOrder:J,clearPreviewOrder:G,moveTabToEnd:se,setDraggingTabKey:X}=Ra({conversations:t,initialActiveTabId:N,initialTabOrder:w,onActiveTabChange:m,onTabOrderChange:y}),te=an({sendDaemonCommand:u,activeConv:S,setLocalUserMessages:l,setActionLogs:x,isStandalone:d}),{dragOver:ee,dropAction:oe,resetDragState:O,handleDragEnter:$,handleDragOver:E,handleDragLeave:_,handleDrop:B}=Aa({conversations:t,numGroups:k,onMoveTab:I,onReceiveTab:h,onOwnTabDrop:se,onClearPreviewOrder:G}),F=S&&ye(S)&&!ge(S),V=a.useMemo(()=>S?s.find(W=>W.id===S.ideId):void 0,[s,S]),re=S?c[S.ideId]:void 0,le=a.useCallback(()=>{if(!S||!(S.ideId in c))return;const W={...c};delete W[S.ideId],i(W)},[S,c,i]),ie=a.useMemo(()=>S?r.filter(W=>W.ideId===S.tabKey):[],[r,S]);ct("PaneGroup",{groupIndex:g,conversationCount:t.length,activeTabId:L,dragOver:ee});const de=a.useCallback(W=>{W.streamSource==="agent-stream"&&W.agentType&&R(W.ideId,"focus_session",{agentType:W.agentType,...W.sessionId&&{targetSessionId:W.sessionId}}).catch(()=>{})},[R]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:f,style:{...b,outline:ee?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(za,{conversations:P,activeTabId:L,groupIndex:g,numGroups:k,draggingTabRef:K,onFocus:f,onSelectTab:C,onConversationActivated:de,onPreviewReorder:Q,onReorderTab:H,onCommitPreviewOrder:J,onClearPreviewOrder:G,onDragStateReset:O,onDragTabKeyChange:X,onMoveTab:I,onReceiveTab:h,onHideTab:A}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:$,onDragOver:E,onDragLeave:_,onDrop:B,children:[ee&&e.jsx($a,{dropAction:oe,canSplit:!!(k<4&&I)}),S?e.jsx(_a,{activeConv:S,clearToken:n[S.tabKey]||0,isCli:!!F,ideEntry:V,screenshotUrl:re,clearScreenshot:le,ptyBuffers:o,terminalRef:D,handleModalButton:te.handleModalButton,handleRelaunch:te.handleRelaunch,handleSendChat:te.handleSendChat,isSendingChat:te.isSendingChat,handleFocusAgent:te.handleFocusAgent,isFocusingAgent:te.isFocusingAgent,actionLogs:ie,userName:p}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Ba,{conversationsCount:t.length,isSplitMode:j,isStandalone:d,detectedIdes:v,handleLaunchIde:T})})]})]})}function Ua({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:o,clearedTabs:c,ides:i,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:f,isStandalone:j,userName:k,setFocusedGroup:I,moveTabToGroup:h,splitTabRelative:b,closeGroup:v,handleResizeStart:T,detectedIdes:m,handleLaunchIde:N,groupActiveTabIds:w,setGroupActiveTabIds:y,groupTabOrders:A,setGroupTabOrders:R,toggleHiddenTab:D}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:o.map((L,S)=>{const P=s&&r.length===n?`${r[S]}%`:void 0;return e.jsxs(yn.Fragment,{children:[s&&S>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:K=>T(S-1,K),onDoubleClick:()=>v(S),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(Ha,{style:s?{flexBasis:P??`${100/n}%`,flexGrow:P?0:1,flexShrink:P?0:1}:void 0,conversations:L,clearedTabs:c,ides:i,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:p,setLocalUserMessages:g,setActionLogs:f,isStandalone:j,userName:k,groupIndex:S,onFocus:()=>I(S),isSplitMode:s,numGroups:n,onMoveTab:(K,C)=>{C==="left"&&S>0?h(K,S-1):C==="right"&&S<n-1?h(K,S+1):C==="split-left"&&n<4?b(K,S,"left"):C==="split-right"&&n<4&&b(K,S,"right")},onReceiveTab:K=>h(K,S),detectedIdes:S===0?m:void 0,handleLaunchIde:S===0?N:void 0,onActiveTabChange:K=>y(C=>(C[S]??null)===(K??null)?C:{...C,[S]:K}),initialActiveTabId:w[S],initialTabOrder:A[S],onTabOrderChange:K=>R(C=>{const H=C[S]||[];return H.length===K.length&&H.every((Q,J)=>Q===K[J])?C:{...C,[S]:K}}),onHideTab:D})]},S)})})}function Fa({daemons:t,upgradingDaemons:s,onUpgrade:n,onDismiss:r}){if(t.length===0)return null;const o=t[0];return e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx(Ts,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",o.version]})," → ",e.jsxs("strong",{children:["v",o.serverVersion]})]}),t.map(c=>{const i=Xe(c,{fallbackId:c.id}),u=s[c.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:i}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",c.version]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(c.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>n(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:r,title:"Dismiss",children:"✕"})]})}function Va({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const o=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 ",o,"?"]}),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 Ya({onClose:t}){const[s,n]=a.useState(0),r=_t[s],o=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]}),o&&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:()=>o?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:o?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
53
+ Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:L,onCancel:()=>d(null)})]})}const ea=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ta(){const{preference:t,setPreference:s}=Xr();return e.jsx("div",{className:"flex gap-2",children:ea.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 Kt={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},zt={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},sa=[{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"}}}],Zs="adhdev-chat-theme",Qs="adhdev-chat-theme-custom";function jt(){return typeof window>"u"?"ember":localStorage.getItem(Zs)||"ember"}function Ie(t){try{const s=localStorage.getItem(Qs);if(s){const n=JSON.parse(s);return{...t==="dark"?Kt:zt,...n[t]}}}catch{}return t==="dark"?Kt:zt}function pt(t,s){localStorage.setItem(Qs,JSON.stringify({dark:t,light:s}))}function Ne(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${o}, ${s})`}function kt(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),o=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}const na={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function rt(t,s){var o;const n=(o=na[t])==null?void 0:o[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",kt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${kt(n,18)})`),r.style.setProperty("--border-accent",Ne(n,.35)),r.style.setProperty("--nav-active-bg",Ne(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ne(n,.06)}`)}function Oe(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ne(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ne(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ne(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",Ne(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ne(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",kt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${kt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ne(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ne(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ne(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 ${Ne(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 qt(){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 ra(t){if(localStorage.setItem(Zs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else qt(),rt(t,Ke()?"dark":"light")}function aa(){const t=jt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Ke()?"dark":"light";Oe(Ie(s))}else qt(),rt(t,Ke()?"dark":"light")}function Ke(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function he({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 Ze({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 oa({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,o]=a.useState(()=>Ie(n));a.useEffect(()=>{o(Ie(n))},[n]);const c=a.useCallback((i,u)=>{o(l=>{const x={...l,[i]:u},h=Ie(n==="dark"?"light":"dark");return n==="dark"?pt(x,h):pt(h,x),Oe(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(Ze,{title:"App Background",children:[e.jsx(he,{label:"Background",value:r.bgPrimary,onChange:i=>c("bgPrimary",i)}),e.jsx(he,{label:"Surface",value:r.bgSecondary,onChange:i=>c("bgSecondary",i)}),e.jsx(he,{label:"Card",value:r.surfacePrimary,onChange:i=>c("surfacePrimary",i)})]}),e.jsxs(Ze,{title:"App Text",children:[e.jsx(he,{label:"Primary",value:r.textPrimary,onChange:i=>c("textPrimary",i)}),e.jsx(he,{label:"Secondary",value:r.textSecondary,onChange:i=>c("textSecondary",i)}),e.jsx(he,{label:"Muted",value:r.textMuted,onChange:i=>c("textMuted",i)})]}),e.jsxs(Ze,{title:"Borders & Accent",children:[e.jsx(he,{label:"Border subtle",value:r.borderSubtle,onChange:i=>c("borderSubtle",i)}),e.jsx(he,{label:"Border default",value:r.borderDefault,onChange:i=>c("borderDefault",i)}),e.jsx(he,{label:"Accent",value:r.accentColor,onChange:i=>c("accentColor",i)})]})]}),e.jsxs("div",{children:[e.jsxs(Ze,{title:"Chat Bubbles",children:[e.jsx(he,{label:"User bubble",value:r.userBubble,onChange:i=>c("userBubble",i)}),e.jsx(he,{label:"User text",value:r.userText,onChange:i=>c("userText",i)}),e.jsx(he,{label:"Agent bubble",value:r.assistantBubble,onChange:i=>c("assistantBubble",i)}),e.jsx(he,{label:"Agent text",value:r.assistantText,onChange:i=>c("assistantText",i)})]}),e.jsxs(Ze,{title:"Chat Layout",children:[e.jsx(he,{label:"Chat BG",value:r.containerBg,onChange:i=>c("containerBg",i)}),e.jsx(he,{label:"Send button",value:r.sendButton,onChange:i=>c("sendButton",i)}),e.jsx(he,{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?Kt:zt,l=Ie(t?"light":"dark");t?pt(i,l):pt(l,i),o(i),Oe(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 ia(){const[t,s]=a.useState(jt),[n,r]=a.useState(!0),[o,c]=a.useState(()=>Ie("dark"));a.useEffect(()=>{r(Ke());const l=new MutationObserver(()=>{const h=Ke();r(h);const g=jt();g==="custom"?Oe(Ie(h?"dark":"light")):rt(g,h?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const h=Ke();r(h);const g=jt();g==="custom"?Oe(Ie(h?"dark":"light")):rt(g,h?"dark":"light")};return x.addEventListener("change",d),()=>{l.disconnect(),x.removeEventListener("change",d)}},[]),a.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Oe(Ie(n?"dark":"light")):(qt(),rt(t,n?"dark":"light"))},[t,n]),a.useEffect(()=>{c(Ie(n?"dark":"light"))},[n]);const i=l=>{s(l),ra(l)},u=[...sa,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText},light:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(l=>{const x=t===l.id,d=n?l.preview.dark:l.preview.light,h=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?o.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:h},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(oa,{dark:n,onColorsChange:l=>c(l)})]})}const en="adhdev_hiddenTabs";function ca(){try{const t=localStorage.getItem(en);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Qe(t){try{localStorage.setItem(en,JSON.stringify([...t]))}catch{}}function tn(){const[t,s]=a.useState(ca),n=a.useCallback(l=>{s(x=>{const d=new Set(x);return d.has(l)?d.delete(l):d.add(l),Qe(d),d})},[]),r=a.useCallback(l=>{s(x=>{if(x.has(l))return x;const d=new Set(x);return d.add(l),Qe(d),d})},[]),o=a.useCallback(l=>{s(x=>{if(!x.has(l))return x;const d=new Set(x);return d.delete(l),Qe(d),d})},[]),c=a.useCallback((l,x)=>{s(d=>{const h=new Set(d);for(const g of x)h.add(g);return Qe(h),h})},[]),i=a.useCallback((l,x)=>{s(d=>{const h=new Set(d);for(const g of x)h.delete(g);return Qe(h),h})},[]),u=a.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:o,hideAllForDaemon:c,showAllForDaemon:i,isHidden:u}}const At=new Set,la={emit(t,s){for(const n of At)n(t,s)},on(t){return At.add(t),()=>{At.delete(t)}}};function sn({conversations:t,visibleConversations:s,clearedTabs:n,setClearedTabs:r,setActionLogs:o}){const c=a.useRef(new Map);a.useEffect(()=>{Pr()},[]);const i=a.useMemo(()=>s.map(u=>({id:u.tabKey,name:u.title||u.agentName||u.ideId,status:u.status,activeModal:u.modalMessage?{message:u.modalMessage,buttons:u.modalButtons}:null})),[s]);return Br(i),a.useEffect(()=>{if(Object.keys(n).length===0)return;const l=setTimeout(()=>{r(x=>{const d=Date.now(),h={};for(const[g,m]of Object.entries(x))d-m<5e3&&(h[g]=m);return Object.keys(h).length===Object.keys(x).length?x:h})},5500);return()=>clearTimeout(l)},[n,r]),a.useEffect(()=>{const u=setInterval(()=>{const l=Date.now()-3e5;o(x=>{const d=x.filter(h=>h.timestamp>l).slice(-100);return d.length===x.length?x:d})},6e4);return()=>clearInterval(u)},[o]),a.useEffect(()=>{const u=(x,d)=>{if(d){la.emit(x,d);for(const h of t){if(!ye(h)||!(x===h.sessionId||x===h.ideId||x===h.tabKey))continue;const m=c.current.get(h.tabKey)||[];m.push(d),m.length>1e4&&m.splice(0,m.length-5e3),c.current.set(h.tabKey,m)}}},l=pe.onPtyOutput(u);return()=>{l()}},[t]),{ptyBuffers:c}}function da(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const o=n.get(r.id);if(!o){n.set(r.id,r);continue}const c=(o.workspace?1:0)+(o.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>c||(r.timestamp||0)>(o.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function ht(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function ua(t,s){const n=Date.now();return t.map(r=>{const o=s[r.tabKey];return o&&n-o<5e3?{...r,messages:[],title:""}:r})}function xa(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 o of t.agentStreams||[]){const c=o.sessionId||o.instanceId||o.agentType,i=`${t.id}:${c}`;n.push({key:i,ref:s[i]}),o.sessionId&&n.push({key:o.sessionId,ref:s[o.sessionId]}),o.instanceId&&n.push({key:o.instanceId,ref:s[o.instanceId]})}return n}function pa(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 ha({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:o}){const c=a.useRef([]),i=a.useRef([]),u=a.useRef([]),l=a.useRef([]),x=a.useMemo(()=>{const y=da(t);return ht(c.current,y)?c.current:(c.current=y,y)},[t]),d=a.useMemo(()=>Fs(t),[t]),h=a.useRef(new Map),g=a.useMemo(()=>{var T;const y=new Map,v=[];for(const f of x){const N=f.daemonId||((T=f.id)==null?void 0:T.split(":")[0])||f.id,w=s[N]||"new",j=f.daemonId&&d[f.daemonId]||void 0,A=xa(f,n),L=h.current.get(f.id);if(L&&L.ide===f&&L.connectionState===w&&L.machineName===j&&pa(L.localRefs,A)){y.set(f.id,L),v.push(...L.conversations);continue}const D=Us(f,n,{machineName:j,connectionState:w}),R={ide:f,connectionState:w,machineName:j,localRefs:A,conversations:D};y.set(f.id,R),v.push(...D)}return h.current=y,v},[x,n,s,d]),m=a.useMemo(()=>{const y=ua(g,r);return ht(i.current,y)?i.current:(i.current=y,y)},[g,r]),b=a.useMemo(()=>{const y=new Map;for(const v of m)v.sessionId&&y.set(v.sessionId,v),y.set(v.ideId,v),y.set(v.tabKey,v),y.set(v.ideType,v),y.set(v.agentType,v);return y},[m]),k=a.useCallback(y=>{if(y)return b.get(y)},[b]),I=a.useMemo(()=>{const y=m.filter(v=>!o.has(v.tabKey));return ht(u.current,y)?u.current:(u.current=y,y)},[m,o]),p=a.useMemo(()=>{const y=I.map(v=>v.tabKey);return ht(l.current,y)?l.current:(l.current=y,y)},[I]);return{chatIdes:x,conversations:m,visibleConversations:I,visibleTabKeys:p,resolveConversationByTarget:k}}function nn({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:o}){a.useEffect(()=>{_e.setIdes(t)},[t]),a.useEffect(()=>{_e.setResolveAction((c,i,u)=>{s(c,i,u).catch(()=>{})})},[s]),a.useEffect(()=>{const c=_e.onToast(l=>{n(d=>d.some(g=>g.message===l.message&&l.timestamp-g.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(h=>h.id!==l.id)),x)}),i=_e.onSystemMessage((l,x)=>{r(d=>({...d,[l]:[...d[l]||[],x]}))}),u=_e.onClearSystemMessage((l,x)=>{r(d=>{var h;return(h=d[l])!=null&&h.length?{...d,[l]:d[l].filter(g=>{var m;return!(g.role==="system"&&((m=g._localId)!=null&&m.startsWith(x)))})}:d})});return()=>{c(),i(),u()}},[n,r]),a.useEffect(()=>{const c=Ks.on("status_event",i=>_e.handleRawEvent(i,"ws"));return()=>{c()}},[]),a.useEffect(()=>{var i;const c=u=>{const l=u.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=o(x),h=(d==null?void 0:d.ideId)||l.ideId;h&&s(h,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(g=>console.error("[SW Action] approve failed:",g))};return(i=navigator.serviceWorker)==null||i.addEventListener("message",c),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",c)}},[o,s])}const ma="adhdev_dashboardLayout_v1",et={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"},tt={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function st(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function fa(t){try{return localStorage.getItem(t)}catch{return null}}function ga(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function rn(t){return`${ma}:${t}`}function ba(){const t=fa(et.focusedGroup),s=st(et.splitGroups,[]),n=st(et.groupActiveTabs,{}),r=st(et.groupTabOrders,{}),o=st(et.splitSizes,[]);return t!==null||s.length>0||Object.keys(n).length>0||Object.keys(r).length>0||o.length>0?{groupAssignments:s,focusedGroup:t&&parseInt(t,10)||0,groupActiveTabIds:n,groupTabOrders:r,groupSizes:o}:null}function ya(t){const s=rn(t),n=st(s,null);return n||ba()}function ja(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=rn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function va(){return{groupAssignments:[...tt.groupAssignments],focusedGroup:tt.focusedGroup,groupActiveTabIds:{...tt.groupActiveTabIds},groupTabOrders:{...tt.groupTabOrders},groupSizes:[...tt.groupSizes]}}function wa(){const[t]=a.useState(()=>ga(typeof window<"u"?window.innerWidth:1280)),[s,n]=a.useState(()=>new Map),[r,o]=a.useState(0),[c,i]=a.useState({}),[u,l]=a.useState({}),[x,d]=a.useState([]),[h,g]=a.useState(()=>typeof window<"u"&&window.innerWidth<768),[m,b]=a.useState(!1),k=a.useCallback(()=>{if(m)return;const I=ya(t)??va();n(new Map(I.groupAssignments)),o(I.focusedGroup),i(I.groupActiveTabIds),l(I.groupTabOrders),d(I.groupSizes),b(!0)},[m,t]);return a.useEffect(()=>{m&&ja(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:c,groupTabOrders:u,groupSizes:x})},[m,t,s,r,c,u,x]),a.useEffect(()=>{const I=window.matchMedia("(max-width: 767px)"),p=y=>g(y.matches);return I.addEventListener("change",p),()=>I.removeEventListener("change",p)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:o,groupActiveTabIds:c,setGroupActiveTabIds:i,groupTabOrders:u,setGroupTabOrders:l,groupSizes:x,setGroupSizes:d,isMobile:h,hasHydratedStoredLayout:m,hydrateStoredLayout:k}}function Na({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:o,hydrateStoredLayout:c,setGroupActiveTabIds:i,setFocusedGroup:u,setSearchParams:l,historyModalOpen:x,activeConv:d,isRefreshingHistory:h,ides:g,handleRefreshHistory:m,isSplitMode:b,splitTabRelative:k,numGroups:I,clearAllSplits:p}){const y=a.useRef(!1),v=a.useRef(!1),T=a.useRef(null),f=a.useRef(!1);a.useEffect(()=>{if(!t||y.current||s.length===0)return;if(!o){c();return}const N=n(t);if(!N)return;const w=r.get(N.tabKey)??0;i(j=>({...j,[w]:N.tabKey})),u(w),y.current=!0,v.current=!0,T.current!=null&&(window.clearTimeout(T.current),T.current=null),l(j=>{const A=new URLSearchParams(j);return A.delete("activeTab"),A},{replace:!0})},[t,s,n,r,o,c,i,u,l]),a.useEffect(()=>{if(!(v.current||o)&&s.length!==0){if(!t){c(),v.current=!0;return}if(y.current){v.current=!0;return}if(T.current==null)return T.current=window.setTimeout(()=>{T.current=null,!(v.current||o)&&(c(),v.current=!0)},1500),()=>{T.current!=null&&(window.clearTimeout(T.current),T.current=null)}}},[t,s.length,o,c]),a.useEffect(()=>{if(!x){f.current=!1;return}if(!d||f.current||h)return;const N=g.find(w=>w.id===d.ideId);N&&(!N.chats||N.chats.length===0)&&(f.current=!0,m())},[x,d,h,g,m]),a.useEffect(()=>{const N=w=>{if(w.ctrlKey&&w.key==="\\"){if(w.preventDefault(),b)p();else{const j=s[1];j&&k(j.tabKey,0,"right")}return}w.ctrlKey&&(w.key==="["||w.key==="]")&&b&&(w.preventDefault(),u(j=>w.key==="]"?Math.min(j+1,I-1):Math.max(j-1,0)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[b,s,k,I,p,u]),a.useEffect(()=>{if(!d)return;let N=null,w=0,j=-1,A=0;const L=()=>{N=null;const D=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(S=>S.offsetParent!==null);if(D.length===0){w<18&&(w+=1,N=requestAnimationFrame(L));return}let R=0;for(const S of D)S.scrollTop=S.scrollHeight,R+=S.scrollHeight;R===j?A+=1:(A=0,j=R),w+=1,!(A>=2||w>=18)&&(N=requestAnimationFrame(L))};return N=requestAnimationFrame(L),()=>{N!=null&&cancelAnimationFrame(N)}},[d==null?void 0:d.tabKey])}function Re(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return ye(t)||ge(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function St(t){return t&&(t.ideId||t.daemonId)||""}function mt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function ka({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:o,setClearedTabs:c}){const[i,u]=a.useState(!1),[l,x]=a.useState(!1),d=a.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(k){console.error("Launch failed",k)}},[t]),h=a.useCallback(async(b,k)=>{try{const I=b||(s==null?void 0:s.daemonId)||"",p=await t(I,"switch_chat",{id:k,sessionId:k,...Re(s)}),y=p==null?void 0:p.result;if((p==null?void 0:p.success)===!0||y==="switched"||y==="switched-by-title")return;y===!1||y==="not_found"?mt(r,"⚠️ Session tab not found — try refreshing history"):typeof y=="string"&&y.startsWith("error:")?mt(r,`⚠️ Switch error: ${y}`):mt(r,"⚠️ Session switch failed")}catch(I){console.error("Switch failed",I),mt(r,`❌ Switch failed: ${I.message||"connection error"}`)}},[s,t,r]),g=a.useCallback(async()=>{if(!(!s||i)){u(!0);try{const b=St(s);await t(b,"new_chat",{...Re(s)}),c(k=>({...k,[s.tabKey]:Date.now()})),o(k=>({...k,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{u(!1)}}},[s,i,t,c,o]),m=a.useCallback(async()=>{var b;if(!(!s||l)){x(!0);try{const k=St(s),I=await t(k,"list_chats",{forceExpand:!0,...Re(s)}),p=(I==null?void 0:I.chats)||((b=I==null?void 0:I.result)==null?void 0:b.chats);I!=null&&I.success&&Array.isArray(p)&&n(s.ideId,p)}catch(k){console.error("Refresh history failed",k)}finally{x(!1)}}},[s,l,t,n]);return{isCreatingChat:i,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:h,handleNewChat:g,handleRefreshHistory:m}}function Sa(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 Ca(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function is(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(o=>s[Number(o)]===t[Number(o)])}function ft(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[i,u]of t)!n.has(i)||u<=0||r.includes(u)||r.push(u);r.sort((i,u)=>i-u);const o={};r.forEach((i,u)=>{o[i]=u}),r.length===0&&(o[0]=0);const c=new Map;for(const[i,u]of t){if(!n.has(i)||u<=0)continue;const l=o[u];typeof l=="number"&&l>0&&c.set(i,l)}return{assignments:c,groupCount:Math.max(1,r.length),mapping:o,usedGroups:r}}function cs(t,s){const n={};for(const[r,o]of Object.entries(t)){const c=s[Number(r)];typeof c=="number"&&(n[c]=o)}return n}function Ia(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(o=>o<t)??s[0];return n[r]??0}function Ma(t,s,n){if(s.length<=1)return[];const r=s.map(i=>t[i]).filter(i=>Number.isFinite(i)),o=r.length===s.length?r:Array(n).fill(100/n),c=o.reduce((i,u)=>i+u,0);return c>0?o.map(i=>i/c*100):Array(n).fill(100/n)}function ls(t,s){const n={};for(const[r,o]of Object.entries(t)){const c=Number(r);n[c>=s?c+1:c]=o}return n}function ds(t){return Array(t).fill(100/t)}function Ta({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:o,groupSizes:c,setGroupSizes:i,isMobile:u,visibleConversations:l,visibleTabKeys:x}){const d=a.useRef(null),h=a.useMemo(()=>ft(t,x),[t,x]),g=h.assignments,m=a.useMemo(()=>u?1:h.groupCount,[h.groupCount,u]),b=m>1,k=a.useCallback((f,N)=>{s(w=>{const j=new Map(ft(w,x).assignments);return N===0?j.delete(f):j.set(f,N),j}),r(w=>({...w,[N]:f})),n(N)},[s,x,r,n]),I=a.useCallback(f=>{s(N=>{const w=ft(N,x).assignments,j=new Map;for(const[A,L]of w)L!==f&&(L>f?j.set(A,L-1):j.set(A,L));return j}),i(N=>{if(N.length<=1)return[];const w=[...N];w.splice(f,1);const j=w.reduce((A,L)=>A+L,0);return j>0?w.map(A=>A/j*100):[]}),n(0)},[s,x,i,n]),p=a.useCallback((f,N)=>{N.preventDefault();const w=d.current;if(!w)return;const j=N.clientX,A=w.offsetWidth,L=c.length===m?[...c]:ds(m),D=S=>{const K=(S.clientX-j)/A*100,C=[...L];C[f]=Math.max(15,L[f]+K),C[f+1]=Math.max(15,L[f+1]-K),i(C)},R=()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",R),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",R)},[c,m,i]),y=a.useCallback((f,N,w)=>{if(m>=4)return;const j=w==="left"?N:N+1;s(A=>{const L=ft(A,x).assignments,D=new Map;for(const R of l){const S=L.get(R.tabKey)??0,P=S>=j?S+1:S;P>0&&D.set(R.tabKey,P)}return j>0&&D.set(f,j),D}),i(A=>{const L=A.length===m?[...A]:ds(m),D=L[N]??100/m,R=Math.max(15,D/2),S=Math.max(15,D/2),P=[...L];P[N]=R,P.splice(j,0,S);const K=P.reduce((C,H)=>C+H,0);return P.map(C=>C/K*100)}),r(A=>{const L=ls(A,j);return L[j]=f,L}),o(A=>{const L=ls(A,j);return L[j]=[f],L}),n(j)},[m,s,x,l,i,r,o,n]);a.useEffect(()=>{Sa(t,g)||s(g)},[t,g,s]),a.useEffect(()=>{const{mapping:f,usedGroups:N}=h;r(w=>{const j=cs(w,f);return is(w,j)?w:j}),o(w=>{const j=cs(w,f);return is(w,j)?w:j}),n(w=>{const j=u?0:Ia(w,N,f);return w===j?w:j}),i(w=>{const j=u?[]:Ma(w,N,h.groupCount);return Ca(w,j)?w:j})},[h,u,r,o,n,i]);const v=a.useMemo(()=>{const f=Array.from({length:m},()=>[]);for(const N of l){const w=g.get(N.tabKey)??0,j=Math.min(w,m-1);f[j].push(N)}return f},[l,g,m]),T=a.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:g,numGroups:m,isSplitMode:b,groupedConvs:v,moveTabToGroup:k,closeGroup:I,handleResizeStart:p,splitTabRelative:y,clearAllSplits:T}}function Ea({ides:t,sendDaemonCommand:s}){const n=a.useMemo(()=>t.filter(l=>l.type==="adhdev-daemon"&&l.versionMismatch),[t]),[r,o]=a.useState(!1),[c,i]=a.useState({}),u=a.useCallback(async l=>{var x,d;i(h=>({...h,[l]:"upgrading"}));try{const h=await s(l,"daemon_upgrade",{});(x=h==null?void 0:h.result)!=null&&x.upgraded||(d=h==null?void 0:h.result)!=null&&d.success?i(g=>({...g,[l]:"done"})):i(g=>({...g,[l]:"error"}))}catch{i(h=>({...h,[l]:"error"}))}},[s]);return{versionMismatchDaemons:n,versionBannerDismissed:r,setVersionBannerDismissed:o,upgradingDaemons:c,handleBannerUpgrade:u}}function an({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:o}){const[c,i]=a.useState(!1),[u,l]=a.useState(!1),x=a.useRef(!1),d=a.useCallback(async b=>{if(!s)return;const k=b.trim();if(!k||x.current)return;const I=s.tabKey;x.current=!0,l(!0);const p=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,y={role:"user",content:k,timestamp:Date.now(),_localId:p};n(v=>({...v,[I]:[...v[I]||[],y]}));try{const v=St(s);if(!v)return;await t(v,"send_chat",{message:k,text:k,...Re(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(f=>{const N=f[I];if(!N)return f;const w=N.filter(j=>j.timestamp>T);return w.length===N.length?f:{...f,[I]:w}})},6e4)}catch(v){console.error("Send failed",v),n(T=>({...T,[I]:(T[I]||[]).filter(f=>f._localId!==p)}))}finally{x.current=!1,l(!1)}},[s,t,n]),h=a.useCallback(async()=>{if(s)try{if(o){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(b){console.error("Relaunch failed",b)}},[s,o,t]),g=a.useCallback(async b=>{if(s){r(k=>[...k,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const I=(s.modalButtons||[]).indexOf(b),p=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(p),v=St(s);if(!v)return;(await t(v,"resolve_action",{button:b,action:y?"approve":"reject",...I>=0&&{buttonIndex:I},...Re(s)})).success||r(f=>[...f,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(k){console.error("[ModalButton] Error:",k),r(I=>[...I,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,r]),m=a.useCallback(async()=>{if(!(!s||c)){i(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(b){console.error("Focus agent failed",b)}finally{i(!1)}}},[s,c,t]);return{isSendingChat:u,isFocusingAgent:c,handleSendChat:d,handleRelaunch:h,handleModalButton:g,handleFocusAgent:m}}function Rt(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Aa({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:o,onClearPreviewOrder:c}){const i=a.useRef(0),[u,l]=a.useState(!1),[x,d]=a.useState(null),h=a.useCallback(()=>{i.current=0,l(!1),d(null)},[]);a.useEffect(()=>(window.addEventListener("dragend",h),window.addEventListener("drop",h),()=>{window.removeEventListener("dragend",h),window.removeEventListener("drop",h)}),[h]);const g=a.useCallback(I=>{I.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,l(!0))},[]),m=a.useCallback(I=>{if(!I.dataTransfer.types.includes("text/tab-key"))return;if(I.preventDefault(),!Rt(s,n)){d("merge");return}const p=I.currentTarget.getBoundingClientRect(),y=I.clientX-p.left,v=p.width/3;y<v?d("split-left"):y>v*2?d("split-right"):d("merge")},[s,n]),b=a.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,l(!1),d(null))},[]),k=a.useCallback(I=>{i.current=0,l(!1);const p=I.dataTransfer.getData("text/tab-key"),y=p?t.some(T=>T.tabKey===p):!1,v=x;if(d(null),c(),!!p){if(I.preventDefault(),v==="split-left"&&Rt(s,n)){n==null||n(p,"split-left");return}if(v==="split-right"&&Rt(s,n)){n==null||n(p,"split-right");return}if(y){o(p);return}r==null||r(p)}},[t,x,s,n,r,o,c]);return{dragOver:u,dropAction:x,resetDragState:h,handleDragEnter:g,handleDragOver:m,handleDragLeave:b,handleDrop:k}}function Ra(t,s){const n=new Set(s.map(c=>c.tabKey)),r=t.filter(c=>n.has(c)),o=s.filter(c=>!t.includes(c.tabKey)).map(c=>c.tabKey);return[...r,...o]}function La({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:o}){const[c,i]=a.useState(s??null),[u,l]=a.useState(n??[]),[x,d]=a.useState(null),h=a.useRef(null),g=a.useRef(null),m=a.useRef(r),b=a.useRef(o);a.useEffect(()=>{m.current=r},[r]),a.useEffect(()=>{b.current=o},[o]),a.useEffect(()=>{s&&s!==c&&i(s)},[s,c]),a.useEffect(()=>{l(w=>{const j=Ra(w,t);return j.length===w.length&&j.every((A,L)=>A===w[L])?w:j})},[t]);const k=a.useMemo(()=>{const w=x??u;if(w.length===0)return t;const j=new Map(w.map((A,L)=>[A,L]));return[...t].sort((A,L)=>{const D=j.get(A.tabKey)??999,R=j.get(L.tabKey)??999;return D-R})},[t,x,u]);a.useEffect(()=>{var j,A;if(k.length===0){c!==null&&(i(null),(j=m.current)==null||j.call(m,null));return}if(c&&k.some(L=>L.tabKey===c))return;const w=k[0].tabKey;w!==c&&(i(w),(A=m.current)==null||A.call(m,w))},[k,c]);const I=a.useMemo(()=>k.find(w=>w.tabKey===c),[k,c]),p=a.useCallback(w=>{var j;i(w),(j=m.current)==null||j.call(m,w)},[]),y=a.useCallback((w,j,A)=>{l(L=>{var P;const D=L.filter(K=>K!==w),R=D.indexOf(j);if(R<0)return L;const S=A==="left"?R:R+1;return D.splice(S,0,w),(P=b.current)==null||P.call(b,D),D}),d(null)},[]),v=a.useCallback((w,j,A)=>{const D=(u.length>0?u:t.map(P=>P.tabKey)).filter(P=>P!==w),R=D.indexOf(j);if(R<0)return;const S=A==="left"?R:R+1;D.splice(S,0,w),h.current=D,d(D)},[u,t]),T=a.useCallback(()=>{var j;const w=h.current;w&&(l(w),(j=b.current)==null||j.call(b,w))},[]),f=a.useCallback(()=>{h.current=null,d(null)},[]),N=a.useCallback(w=>{l(j=>{var L;const A=j.filter(D=>D!==w);return A.push(w),(L=b.current)==null||L.call(b,A),A})},[]);return{activeTabId:c,activeConv:I,sortedConversations:k,previewOrderRef:h,draggingTabRef:g,selectTab:p,handleTabReorder:y,updatePreviewOrder:v,commitPreviewOrder:T,clearPreviewOrder:f,moveTabToEnd:N,setDraggingTabKey:w=>{g.current=w}}}const _a=a.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:o,screenshotUrl:c,clearScreenshot:i,ptyBuffers:u,terminalRef:l,handleModalButton:x,handleRelaunch:d,handleSendChat:h,isSendingChat:g,handleFocusAgent:m,isFocusingAgent:b,actionLogs:k,userName:I}){const p=a.useCallback(()=>{i()},[i]);return e.jsxs(e.Fragment,{children:[e.jsx(Ps,{activeConv:s,onModalButton:x}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&c?e.jsx(nr,{screenshotUrl:c,mode:"preview",onDismiss:p}):!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(Ft,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:d,children:"Relaunch with CDP"})]}):null}),r?e.jsx(jr,{activeConv:s,clearToken:n,ptyBuffers:u,terminalRef:l,handleSendChat:h,isSendingChat:g}):e.jsx(Ws,{activeConv:s,ideEntry:o,handleSendChat:h,isSendingChat:g,handleFocusAgent:m,isFocusingAgent:b,actionLogs:k,userName:I})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.ptyBuffers===s.ptyBuffers&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function $a({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 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 Pa(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Da(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[o,c]=a.useState(!1),i=t==="unix"?"unix":n;a.useEffect(()=>{s(Pa())},[]);const u=a.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:u,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:o?"✓":"📋"})]}),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 Ba({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:o}){return t===0&&!s&&r&&o?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"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(Da,{}),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:()=>o(c.type),children:[e.jsx(Rs,{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"})}const on="adhdev-tab-shortcuts";function Wa(){try{return JSON.parse(localStorage.getItem(on)||"{}")}catch{return{}}}function Oa({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,c]=a.useState(()=>Wa()),[i,u]=a.useState(null),l=a.useCallback(d=>{const h=[];return d.metaKey&&h.push(r?"⌘":"Meta"),d.ctrlKey&&h.push("Ctrl"),d.altKey&&h.push(r?"⌥":"Alt"),d.shiftKey&&h.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(h.push(d.key.length===1?d.key.toUpperCase():d.key),h.join("+"))},[r]),x=a.useCallback(d=>{c(d);try{localStorage.setItem(on,JSON.stringify(d))}catch{}},[]);return a.useEffect(()=>{if(!i)return;const d=h=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape"){u(null);return}const g=l(h);if(!g)return;const m={...o};for(const[b,k]of Object.entries(m))k===g&&delete m[b];m[i]=g,x(m),u(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[i,o,x,l]),a.useEffect(()=>{const d=h=>{if(!(!h.ctrlKey&&!h.metaKey&&!h.altKey)){for(const[g,m]of Object.entries(o))if(t.includes(g)&&l(h)===m){h.preventDefault(),s(),n(g);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[o,t,s,n,l]),{isMac:r,tabShortcuts:o,shortcutListening:i,setShortcutListening:u,saveShortcuts:x}}const Ka=a.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:o,conversationKeys:c,draggingTabRef:i,onFocus:u,onSelectTab:l,onConversationActivated:x,onPreviewReorder:d,onReorderTab:h,onCommitPreviewOrder:g,onClearPreviewOrder:m,onDragStateReset:b,onDragTabKeyChange:k,onReceiveTab:I,onOpenContextMenu:p,longPressTimer:y}){const v=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",T=s.connectionState==="failed"||s.connectionState==="closed",f=a.useCallback(S=>{i.current=s.tabKey,k(s.tabKey),S.dataTransfer.setData("text/tab-key",s.tabKey),S.dataTransfer.effectAllowed="move"},[s.tabKey,i,k]),N=a.useCallback(()=>{i.current=null,k(null),g(),m(),b()},[i,k,g,m,b]),w=a.useCallback(S=>{const P=i.current;if(!(!P||P===s.tabKey)&&S.dataTransfer.types.includes("text/tab-key")){S.preventDefault(),S.stopPropagation();const K=S.currentTarget.getBoundingClientRect(),C=S.clientX<K.left+K.width/2?"left":"right";d(P,s.tabKey,C)}},[s.tabKey,i,d]),j=a.useCallback(S=>{S.preventDefault(),S.stopPropagation();const P=S.dataTransfer.getData("text/tab-key");if(P&&P!==s.tabKey){const K=S.currentTarget.getBoundingClientRect(),C=S.clientX<K.left+K.width/2?"left":"right";c.includes(P)?h(P,s.tabKey,C):I&&I(P)}m()},[s.tabKey,c,h,I,m]),A=a.useCallback(S=>{S.stopPropagation(),u(),l(s.tabKey),x(s)},[s,x,u,l]),L=a.useCallback(S=>{S.preventDefault(),p(S.clientX,S.clientY,s.tabKey)},[s.tabKey,p]),D=a.useCallback(S=>{const P=S.touches[0];y.current=setTimeout(()=>{p(P.clientX,P.clientY,s.tabKey)},600)},[s.tabKey,y,p]),R=a.useCallback(()=>{y.current&&clearTimeout(y.current)},[y]);return e.jsxs("div",{"data-tabkey":s.tabKey,className:`${v} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:f,onDragEnd:N,onDragOver:w,onDrop:j,onClick:A,onContextMenu:L,onTouchStart:D,onTouchEnd:R,onTouchMove:R,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]})]})]})})]}),o&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${o}`,children:o})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function za({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:o,onFocus:c,onSelectTab:i,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:m,onMoveTab:b,onReceiveTab:k,onHideTab:I}){const[p,y]=a.useState(null),v=a.useRef(null),T=a.useRef(null),f=a.useMemo(()=>t.map(R=>R.tabKey),[t]);ct("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(p==null?void 0:p.tabKey)||null});const{isMac:N,tabShortcuts:w,shortcutListening:j,setShortcutListening:A,saveShortcuts:L}=Oa({sortedTabKeys:t.map(R=>R.tabKey),onFocus:c,onSelectTab:i});a.useEffect(()=>{if(!p)return;const R=S=>{const P=document.querySelector("[data-pane-context-menu]");P&&P.contains(S.target)||y(null)};return window.addEventListener("mousedown",R,!0),()=>window.removeEventListener("mousedown",R,!0)},[p]),a.useEffect(()=>{const R=T.current;if(!R)return;const S=P=>{Math.abs(P.deltaY)>Math.abs(P.deltaX)&&(P.preventDefault(),R.scrollLeft+=P.deltaY)};return R.addEventListener("wheel",S,{passive:!1}),()=>R.removeEventListener("wheel",S)},[]);const D=a.useCallback((R,S,P)=>{y({x:R,y:S,tabKey:P})},[]);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(R=>e.jsx(Ka,{conv:R,isActive:s===R.tabKey,isDraggedTab:o.current===R.tabKey,shortcut:w[R.tabKey],conversationKeys:f,draggingTabRef:o,onFocus:c,onSelectTab:i,onConversationActivated:u,onPreviewReorder:l,onReorderTab:x,onCommitPreviewOrder:d,onClearPreviewOrder:h,onDragStateReset:g,onDragTabKeyChange:m,onReceiveTab:k,onOpenContextMenu:D,longPressTimer:v},R.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),p&&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:p.x,top:p.y},children:[b&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(p.tabKey,"left"),y(null)},children:"← Move to Left Group"}),b&&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:()=>{b(p.tabKey,"right"),y(null)},children:"Move to Right Group →"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(p.tabKey,"split-left"),y(null)},children:"⇤ Split Left"}),b&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{b(p.tabKey,"split-right"),y(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:R=>{R.stopPropagation(),A(p.tabKey),y(null)},children:["⌨ ",w[p.tabKey]?`Change shortcut (${w[p.tabKey]})`:"Set shortcut"]}),w[p.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 R={...w};delete R[p.tabKey],L(R),y(null)},children:"✕ Remove shortcut"}),I&&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:()=>{I(p.tabKey),y(null)},children:"🚫 Hide from Dashboard"})]}),!b&&!I&&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:()=>A(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:R=>R.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",N?"⌘+1":"Ctrl+1",", ",N?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}function Ha({conversations:t,ides:s,clearedTabs:n,actionLogs:r,ptyBuffers:o,screenshotMap:c,setScreenshotMap:i,sendDaemonCommand:u,setLocalUserMessages:l,setActionLogs:x,isStandalone:d,userName:h,groupIndex:g,onFocus:m,isSplitMode:b,numGroups:k,onMoveTab:I,onReceiveTab:p,style:y,detectedIdes:v,handleLaunchIde:T,onActiveTabChange:f,initialActiveTabId:N,initialTabOrder:w,onTabOrderChange:j,onHideTab:A}){const{sendCommand:L}=Pe(),D=a.useRef(null),{activeTabId:R,activeConv:S,sortedConversations:P,draggingTabRef:K,selectTab:C,handleTabReorder:H,updatePreviewOrder:Q,commitPreviewOrder:J,clearPreviewOrder:G,moveTabToEnd:se,setDraggingTabKey:X}=La({conversations:t,initialActiveTabId:N,initialTabOrder:w,onActiveTabChange:f,onTabOrderChange:j}),te=an({sendDaemonCommand:u,activeConv:S,setLocalUserMessages:l,setActionLogs:x,isStandalone:d}),{dragOver:ee,dropAction:oe,resetDragState:O,handleDragEnter:$,handleDragOver:E,handleDragLeave:_,handleDrop:B}=Aa({conversations:t,numGroups:k,onMoveTab:I,onReceiveTab:p,onOwnTabDrop:se,onClearPreviewOrder:G}),U=S&&ye(S)&&!ge(S),V=a.useMemo(()=>S?s.find(W=>W.id===S.ideId):void 0,[s,S]),re=S?c[S.ideId]:void 0,le=a.useCallback(()=>{if(!S||!(S.ideId in c))return;const W={...c};delete W[S.ideId],i(W)},[S,c,i]),ie=a.useMemo(()=>S?r.filter(W=>W.ideId===S.tabKey):[],[r,S]);ct("PaneGroup",{groupIndex:g,conversationCount:t.length,activeTabId:R,dragOver:ee});const de=a.useCallback(W=>{W.streamSource==="agent-stream"&&W.agentType&&L(W.ideId,"focus_session",{agentType:W.agentType,...W.sessionId&&{targetSessionId:W.sessionId}}).catch(()=>{})},[L]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:m,style:{...y,outline:ee?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(za,{conversations:P,activeTabId:R,groupIndex:g,numGroups:k,draggingTabRef:K,onFocus:m,onSelectTab:C,onConversationActivated:de,onPreviewReorder:Q,onReorderTab:H,onCommitPreviewOrder:J,onClearPreviewOrder:G,onDragStateReset:O,onDragTabKeyChange:X,onMoveTab:I,onReceiveTab:p,onHideTab:A}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:$,onDragOver:E,onDragLeave:_,onDrop:B,children:[ee&&e.jsx($a,{dropAction:oe,canSplit:!!(k<4&&I)}),S?e.jsx(_a,{activeConv:S,clearToken:n[S.tabKey]||0,isCli:!!U,ideEntry:V,screenshotUrl:re,clearScreenshot:le,ptyBuffers:o,terminalRef:D,handleModalButton:te.handleModalButton,handleRelaunch:te.handleRelaunch,handleSendChat:te.handleSendChat,isSendingChat:te.isSendingChat,handleFocusAgent:te.handleFocusAgent,isFocusingAgent:te.isFocusingAgent,actionLogs:ie,userName:h}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Ba,{conversationsCount:t.length,isSplitMode:b,isStandalone:d,detectedIdes:v,handleLaunchIde:T})})]})]})}function Fa({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:o,clearedTabs:c,ides:i,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:h,setLocalUserMessages:g,setActionLogs:m,isStandalone:b,userName:k,setFocusedGroup:I,moveTabToGroup:p,splitTabRelative:y,closeGroup:v,handleResizeStart:T,detectedIdes:f,handleLaunchIde:N,groupActiveTabIds:w,setGroupActiveTabIds:j,groupTabOrders:A,setGroupTabOrders:L,toggleHiddenTab:D}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:o.map((R,S)=>{const P=s&&r.length===n?`${r[S]}%`:void 0;return e.jsxs(yn.Fragment,{children:[s&&S>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:K=>T(S-1,K),onDoubleClick:()=>v(S),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(Ha,{style:s?{flexBasis:P??`${100/n}%`,flexGrow:P?0:1,flexShrink:P?0:1}:void 0,conversations:R,clearedTabs:c,ides:i,actionLogs:u,ptyBuffers:l,screenshotMap:x,setScreenshotMap:d,sendDaemonCommand:h,setLocalUserMessages:g,setActionLogs:m,isStandalone:b,userName:k,groupIndex:S,onFocus:()=>I(S),isSplitMode:s,numGroups:n,onMoveTab:(K,C)=>{C==="left"&&S>0?p(K,S-1):C==="right"&&S<n-1?p(K,S+1):C==="split-left"&&n<4?y(K,S,"left"):C==="split-right"&&n<4&&y(K,S,"right")},onReceiveTab:K=>p(K,S),detectedIdes:S===0?f:void 0,handleLaunchIde:S===0?N:void 0,onActiveTabChange:K=>j(C=>(C[S]??null)===(K??null)?C:{...C,[S]:K}),initialActiveTabId:w[S],initialTabOrder:A[S],onTabOrderChange:K=>L(C=>{const H=C[S]||[];return H.length===K.length&&H.every((Q,J)=>Q===K[J])?C:{...C,[S]:K}}),onHideTab:D})]},S)})})}function Ua({daemons:t,upgradingDaemons:s,onUpgrade:n,onDismiss:r}){if(t.length===0)return null;const o=t[0];return e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx(Ts,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",o.version]})," → ",e.jsxs("strong",{children:["v",o.serverVersion]})]}),t.map(c=>{const i=Xe(c,{fallbackId:c.id}),u=s[c.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:i}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",c.version]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(c.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>n(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:r,title:"Dismiss",children:"✕"})]})}function Va({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const o=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 ",o,"?"]}),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 qa({onClose:t}){const[s,n]=a.useState(0),r=_t[s],o=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]}),o&&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:()=>o?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:o?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
54
54
  @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
55
55
  @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
56
- `})]})}function qa(){const{sendCommand:t}=Pe(),[s,n]=gs(),r=s.get("activeTab"),o=It(),{updateIdeChats:c,screenshotMap:i,setScreenshotMap:u}=o,l=o.ides||[],[x,d]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),p=o.toasts||[],g=o.setToasts||(()=>{}),f=o.wsStatus||"connected",j=o.isConnected??!0,k=o.connectionStates||{},I=o.showReconnected||!1,{groupAssignments:h,setGroupAssignments:b,focusedGroup:v,setFocusedGroup:T,groupActiveTabIds:m,setGroupActiveTabIds:N,groupTabOrders:w,setGroupTabOrders:y,groupSizes:A,setGroupSizes:R,isMobile:D,hasHydratedStoredLayout:L,hydrateStoredLayout:S}=wa(),[P,K]=a.useState(!1),[C,H]=a.useState(!1),[Q,J]=a.useState([]),[G,se]=a.useState({}),[X,te]=a.useState({});ct("Dashboard",{ideCount:l.length,toastCount:p.length,focusedGroup:v,groupCount:Object.keys(h).length,localMessageTabs:Object.keys(G).length,actionLogCount:Q.length});const ee=l.find(je=>je.type==="adhdev-daemon"),oe=(ee==null?void 0:ee.detectedIdes)||[],O=!!ee,{hiddenTabs:$,toggleTab:E}=tn(),{chatIdes:_,conversations:B,visibleConversations:F,visibleTabKeys:V,resolveConversationByTarget:re}=pa({ides:l,connectionStates:k,localUserMessages:G,clearedTabs:X,hiddenTabs:$}),{containerRef:le,normalizedGroupAssignments:ie,numGroups:de,isSplitMode:W,groupedConvs:q,moveTabToGroup:U,closeGroup:M,handleResizeStart:Y,splitTabRelative:z,clearAllSplits:ne}=Ta({groupAssignments:h,setGroupAssignments:b,setFocusedGroup:T,setGroupActiveTabIds:N,setGroupTabOrders:y,groupSizes:A,setGroupSizes:R,isMobile:D,visibleConversations:F,visibleTabKeys:V}),Z=a.useMemo(()=>{var ve,Fe;const je=m[v];if(je){const dt=B.find(un=>un.tabKey===je);if(dt)return dt}return((ve=q[v])==null?void 0:ve[0])||((Fe=q[0])==null?void 0:Fe[0])},[m,v,B,q]),{ptyBuffers:be}=sn({conversations:B,visibleConversations:F,clearedTabs:X,setClearedTabs:te,setActionLogs:J});nn({ides:l,sendDaemonCommand:t,setToasts:g,setLocalUserMessages:se,resolveConversationByTarget:re});const{isCreatingChat:ae,isRefreshingHistory:Me,handleLaunchIde:Se,handleSwitchSession:Ce,handleNewChat:Ge,handleRefreshHistory:He}=ka({sendDaemonCommand:t,activeConv:Z,updateIdeChats:c,setToasts:g,setLocalUserMessages:se,setClearedTabs:te});Na({urlActiveTab:r,conversations:B,resolveConversationByTarget:re,normalizedGroupAssignments:ie,hasHydratedStoredLayout:L,hydrateStoredLayout:S,setGroupActiveTabIds:N,setFocusedGroup:T,setSearchParams:n,historyModalOpen:P,activeConv:Z,isRefreshingHistory:Me,ides:l,handleRefreshHistory:He,isSplitMode:W,splitTabRelative:z,numGroups:de,clearAllSplits:ne});const Ue=a.useCallback(async je=>{if(!Z||!ye(Z)||ge(Z))return;const ve=Z.ideType||Z.agentType||"",Fe=Z.ideId||Z.daemonId||"";try{await t(Fe,"stop_cli",{cliType:ve,targetSessionId:Z.sessionId,mode:je})}catch(dt){console.error("Stop CLI failed:",dt)}},[Z,t]),Mt=a.useCallback(async()=>{var ve;if(!Z||!ye(Z)||ge(Z))return;if((ve=Z.resume)!=null&&ve.supported){H(!0);return}const je=Z.ideType||Z.agentType||"CLI";window.confirm(`Stop ${je}?
57
- This will terminate the CLI process.`)&&await Ue("hard")},[Z,Ue]),lt=a.useCallback(()=>{!Z||!ye(Z)||ge(Z)||!Z.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:Z.sessionId}}))},[Z]),{versionMismatchDaemons:Je,versionBannerDismissed:Tt,setVersionBannerDismissed:cn,upgradingDaemons:ln,handleBannerUpgrade:dn}=Ea({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(vr,{wsStatus:f,showReconnected:I}),!Tt&&e.jsx(Fa,{daemons:Je,upgradingDaemons:ln,onUpgrade:dn,onDismiss:()=>cn(!0)}),e.jsx(wr,{activeConv:Z,agentCount:_.length,wsStatus:f,isConnected:j,onOpenHistory:()=>K(!0),onFitCli:lt,onStopCli:Mt}),e.jsx(Ua,{containerRef:le,isSplitMode:W,numGroups:de,groupSizes:A,groupedConvs:q,clearedTabs:X,ides:l,actionLogs:Q,ptyBuffers:be,screenshotMap:i,setScreenshotMap:u,sendDaemonCommand:t,setLocalUserMessages:se,setActionLogs:J,isStandalone:O,userName:o.userName,focusedGroup:v,setFocusedGroup:T,moveTabToGroup:U,splitTabRelative:z,closeGroup:M,handleResizeStart:Y,detectedIdes:oe,handleLaunchIde:Se,groupActiveTabIds:m,setGroupActiveTabIds:N,groupTabOrders:w,setGroupTabOrders:y,toggleHiddenTab:E}),P&&Z&&e.jsx(zs,{activeConv:Z,ides:l,isCreatingChat:ae,isRefreshingHistory:Me,onClose:()=>K(!1),onNewChat:Ge,onSwitchSession:Ce,onRefreshHistory:He}),C&&Z&&ye(Z)&&!ge(Z)&&e.jsx(Va,{activeConv:Z,onCancel:()=>H(!1),onStopNow:async()=>{H(!1),await Ue("hard")},onSaveAndStop:async()=>{H(!1),await Ue("save")}}),e.jsx("style",{children:`
56
+ `})]})}function Ya(){const{sendCommand:t}=Pe(),[s,n]=gs(),r=s.get("activeTab"),o=It(),{updateIdeChats:c,screenshotMap:i,setScreenshotMap:u}=o,l=o.ides||[],[x,d]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),h=o.toasts||[],g=o.setToasts||(()=>{}),m=o.wsStatus||"connected",b=o.isConnected??!0,k=o.connectionStates||{},I=o.showReconnected||!1,{groupAssignments:p,setGroupAssignments:y,focusedGroup:v,setFocusedGroup:T,groupActiveTabIds:f,setGroupActiveTabIds:N,groupTabOrders:w,setGroupTabOrders:j,groupSizes:A,setGroupSizes:L,isMobile:D,hasHydratedStoredLayout:R,hydrateStoredLayout:S}=wa(),[P,K]=a.useState(!1),[C,H]=a.useState(!1),[Q,J]=a.useState([]),[G,se]=a.useState({}),[X,te]=a.useState({});ct("Dashboard",{ideCount:l.length,toastCount:h.length,focusedGroup:v,groupCount:Object.keys(p).length,localMessageTabs:Object.keys(G).length,actionLogCount:Q.length});const ee=l.find(je=>je.type==="adhdev-daemon"),oe=(ee==null?void 0:ee.detectedIdes)||[],O=!!ee,{hiddenTabs:$,toggleTab:E}=tn(),{chatIdes:_,conversations:B,visibleConversations:U,visibleTabKeys:V,resolveConversationByTarget:re}=ha({ides:l,connectionStates:k,localUserMessages:G,clearedTabs:X,hiddenTabs:$}),{containerRef:le,normalizedGroupAssignments:ie,numGroups:de,isSplitMode:W,groupedConvs:Y,moveTabToGroup:F,closeGroup:M,handleResizeStart:q,splitTabRelative:z,clearAllSplits:ne}=Ta({groupAssignments:p,setGroupAssignments:y,setFocusedGroup:T,setGroupActiveTabIds:N,setGroupTabOrders:j,groupSizes:A,setGroupSizes:L,isMobile:D,visibleConversations:U,visibleTabKeys:V}),Z=a.useMemo(()=>{var ve,Ue;const je=f[v];if(je){const dt=B.find(un=>un.tabKey===je);if(dt)return dt}return((ve=Y[v])==null?void 0:ve[0])||((Ue=Y[0])==null?void 0:Ue[0])},[f,v,B,Y]),{ptyBuffers:be}=sn({conversations:B,visibleConversations:U,clearedTabs:X,setClearedTabs:te,setActionLogs:J});nn({ides:l,sendDaemonCommand:t,setToasts:g,setLocalUserMessages:se,resolveConversationByTarget:re});const{isCreatingChat:ae,isRefreshingHistory:Me,handleLaunchIde:Se,handleSwitchSession:Ce,handleNewChat:Ge,handleRefreshHistory:He}=ka({sendDaemonCommand:t,activeConv:Z,updateIdeChats:c,setToasts:g,setLocalUserMessages:se,setClearedTabs:te});Na({urlActiveTab:r,conversations:B,resolveConversationByTarget:re,normalizedGroupAssignments:ie,hasHydratedStoredLayout:R,hydrateStoredLayout:S,setGroupActiveTabIds:N,setFocusedGroup:T,setSearchParams:n,historyModalOpen:P,activeConv:Z,isRefreshingHistory:Me,ides:l,handleRefreshHistory:He,isSplitMode:W,splitTabRelative:z,numGroups:de,clearAllSplits:ne});const Fe=a.useCallback(async je=>{if(!Z||!ye(Z)||ge(Z))return;const ve=Z.ideType||Z.agentType||"",Ue=Z.ideId||Z.daemonId||"";try{await t(Ue,"stop_cli",{cliType:ve,targetSessionId:Z.sessionId,mode:je})}catch(dt){console.error("Stop CLI failed:",dt)}},[Z,t]),Mt=a.useCallback(async()=>{var ve;if(!Z||!ye(Z)||ge(Z))return;if((ve=Z.resume)!=null&&ve.supported){H(!0);return}const je=Z.ideType||Z.agentType||"CLI";window.confirm(`Stop ${je}?
57
+ This will terminate the CLI process.`)&&await Fe("hard")},[Z,Fe]),lt=a.useCallback(()=>{!Z||!ye(Z)||ge(Z)||!Z.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:Z.sessionId}}))},[Z]),{versionMismatchDaemons:Je,versionBannerDismissed:Tt,setVersionBannerDismissed:cn,upgradingDaemons:ln,handleBannerUpgrade:dn}=Ea({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(vr,{wsStatus:m,showReconnected:I}),!Tt&&e.jsx(Ua,{daemons:Je,upgradingDaemons:ln,onUpgrade:dn,onDismiss:()=>cn(!0)}),e.jsx(wr,{activeConv:Z,agentCount:_.length,wsStatus:m,isConnected:b,onOpenHistory:()=>K(!0),onFitCli:lt,onStopCli:Mt}),e.jsx(Fa,{containerRef:le,isSplitMode:W,numGroups:de,groupSizes:A,groupedConvs:Y,clearedTabs:X,ides:l,actionLogs:Q,ptyBuffers:be,screenshotMap:i,setScreenshotMap:u,sendDaemonCommand:t,setLocalUserMessages:se,setActionLogs:J,isStandalone:O,userName:o.userName,focusedGroup:v,setFocusedGroup:T,moveTabToGroup:F,splitTabRelative:z,closeGroup:M,handleResizeStart:q,detectedIdes:oe,handleLaunchIde:Se,groupActiveTabIds:f,setGroupActiveTabIds:N,groupTabOrders:w,setGroupTabOrders:j,toggleHiddenTab:E}),P&&Z&&e.jsx(zs,{activeConv:Z,ides:l,isCreatingChat:ae,isRefreshingHistory:Me,onClose:()=>K(!1),onNewChat:Ge,onSwitchSession:Ce,onRefreshHistory:He}),C&&Z&&ye(Z)&&!ge(Z)&&e.jsx(Va,{activeConv:Z,onCancel:()=>H(!1),onStopNow:async()=>{H(!1),await Fe("hard")},onSaveAndStop:async()=>{H(!1),await Fe("save")}}),e.jsx("style",{children:`
58
58
  body { overflow: hidden; overscroll-behavior: none; }
59
- `}),e.jsx(Hs,{toasts:p,onDismiss:je=>g(ve=>ve.filter(Fe=>Fe.id!==je)),onClickToast:je=>{if(je.targetKey){const ve=re(je.targetKey);ve&&T(ie.get(ve.tabKey)??0)}}}),x&&e.jsx(Ya,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function Xa({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:o}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>o("native"),children:s}),r.map(c=>{const i=n===c.tabKey,u=c.status==="waiting_approval",l=c.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${i?"active":""}`,onClick:()=>o(c.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:u?"#f59e0b":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),c.title,u&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},c.tabKey)})]}):null}function Ga({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:o,onChangeView:c,onOpenHistory:i,headerActions:u,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:o===x?"1px solid var(--accent-primary)":"none",background:o===x?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:o===x?"var(--accent-primary)":void 0},onClick:()=>c(x),children:x==="chat"?e.jsx(Ye,{size:14}):x==="split"?"⊞":e.jsx(Re,{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(Ms,{size:14})}),u,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 Ja({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 Za({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:o,updateIdeChats:c,pushToast:i}){const[u,l]=a.useState(!1),[x,d]=a.useState(!1),[p,g]=a.useState(!1),f=a.useRef(!1),j=a.useCallback(async b=>{const v=b.trim();if(!(!v||!t||p||!s)){g(!0);try{await o(t,"send_chat",{message:v,text:v,waitForResponse:!0,...Le(s)})}catch(T){console.error("[IDE] Send failed:",T)}finally{g(!1)}}},[t,p,o,s]),k=a.useCallback(async()=>{var b;if(!(!t||x||!s)){d(!0);try{const v=await o(t,"list_chats",{forceExpand:!0,...Le(s)}),T=(v==null?void 0:v.chats)||((b=v==null?void 0:v.result)==null?void 0:b.chats);v!=null&&v.success&&Array.isArray(T)&&c(t,T)}catch(v){console.error("[IDE] Refresh history failed:",v),i("히스토리 새로고침에 실패했습니다.","warning")}finally{d(!1)}}},[t,x,o,s,c,i]),I=a.useCallback(async(b,v)=>{if(!(!t||!s))try{const T=await o(t,"switch_chat",{id:v,sessionId:v,...Le(s)}),m=T==null?void 0:T.result;if((T==null?void 0:T.success)===!0||m==="switched"||m==="switched-by-title")return;m===!1||m==="not_found"?i("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof m=="string"&&m.startsWith("error:")?i(`세션 전환 오류: ${m}`,"warning"):i("세션 전환에 실패했습니다.","warning")}catch(T){console.error("[IDE] Switch session failed:",T),i(`세션 전환 실패: ${(T==null?void 0:T.message)||"connection error"}`,"warning")}},[t,o,s,i]),h=a.useCallback(async()=>{if(!(!t||u||!s)){l(!0);try{await o(t,"new_chat",{...Le(s)})}catch(b){console.error("[IDE] New chat failed:",b),i("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,u,o,s,i]);return a.useEffect(()=>{if(!n){f.current=!1;return}f.current||x||(!r||r.length===0)&&(f.current=!0,k())},[n,r,x,k]),{isSendingChat:p,isCreatingChat:u,isRefreshingHistory:x,handleSendAgent:j,handleRefreshHistory:k,handleSwitchSession:I,handleNewChat:h}}function Qa({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:o}){const[c,i]=a.useState("native"),u=a.useMemo(()=>Us(s),[s]),l=a.useMemo(()=>{var k;if(!t)return[];const j=t.daemonId||((k=t.id)==null?void 0:k.split(":")[0])||t.id;return Fs(t,r,{machineName:t.daemonId&&u[t.daemonId]||void 0,connectionState:n[j]||"new"})},[t,r,u,n]),x=a.useMemo(()=>l.find(j=>j.streamSource==="native"),[l]),d=a.useMemo(()=>l.filter(j=>j.streamSource==="agent-stream"),[l]);a.useEffect(()=>{var j;c!=="native"&&(d.some(k=>k.tabKey===c)||i(((j=d[0])==null?void 0:j.tabKey)||"native"))},[c,d]),a.useEffect(()=>{c==="native"&&(x||d[0]&&i(d[0].tabKey))},[c,x,d]);const p=a.useMemo(()=>c==="native"&&x?x:d.find(j=>j.tabKey===c)||x||d[0],[c,x,d]),g=a.useMemo(()=>d.map(j=>({tabKey:j.tabKey,title:j.title||j.agentName||o,status:j.status})),[d,o]),f=a.useCallback(j=>{if(j)return l.find(k=>k.sessionId===j||k.ideId===j||k.tabKey===j||k.ideType===j||k.agentType===j)},[l]);return{activeChatTab:c,setActiveChatTab:i,activeConv:p,conversations:l,extensionTabs:g,hasExtensions:g.length>0,resolveConversationByTarget:f}}function eo({doId:t,ideId:s,ideType:n,connState:r,viewMode:o,instanceId:c}){const[i,u]=a.useState(null),[l,x]=a.useState(null),d=a.useMemo(()=>{if(!s)return n;const g=s.split(":");return g.length>=3&&g[1]==="ide"?g.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?he.onScreenshot("ide-page",(f,j)=>{if(f!==t)return;const k=new FileReader;k.onload=()=>u(k.result),k.readAsDataURL(j)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&u(null)},[r]),a.useEffect(()=>{var f;return t?((f=he.onStatus)==null?void 0:f.call(he,(j,k)=>{j===t&&k!=null&&k.screenshotUsage&&x(k.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,d]),a.useEffect(()=>{const g=t?he.get(t):null;if(!(!g||r!=="connected"))return o!=="chat"&&d?g.startScreenshots(d):g.stopScreenshots(d),()=>{g.stopScreenshots(d)}},[o,r,d,t]);const p=a.useCallback(async(g,f)=>{const j=t?he.get(t):null;return!j||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):j.sendInput(g,f,c||d)},[t,r,c,d]);return{connScreenshot:i,screenshotUsage:l,handleRemoteAction:p}}function to(){const[t,s]=a.useState([]),n=a.useCallback(o=>{s(c=>c.filter(i=>i.id!==o))},[]),r=a.useCallback((o,c="warning")=>{const i=Date.now()+Math.floor(Math.random()*1e3);s(u=>[...u,{id:i,message:o,type:c}]),window.setTimeout(()=>{s(u=>u.filter(l=>l.id!==i))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function so({renderHeaderActions:t}={}){var de;const{id:s}=bs(),n=it(),r=It(),o=r.ides||[],c=r.updateIdeChats||(()=>{}),i=r.connectionStates||{},{sendCommand:u}=Pe(),l=a.useMemo(()=>Vs(s||"").daemonId,[s]),x=a.useMemo(()=>o.find(W=>W.id===s),[o,s]),d=(x==null?void 0:x.type)||void 0,p=d?d.charAt(0).toUpperCase()+d.slice(1):"IDE",g=r.isConnected??!0,f=i[l]||(g?"connected":"new"),j=((de=r.connectionTransports)==null?void 0:de[l])||"unknown",k=a.useMemo(()=>o.find(W=>W.id===l||W.daemonId===l),[o,l]),I=k?Xe(k,{fallbackId:l}):"",h=(x==null?void 0:x.workspace)||"",[b]=gs(),v=typeof window<"u"&&window.innerWidth<=768,T=b.get("view")||(v?"chat":"split"),[m,N]=a.useState(T),[w,y]=a.useState(!1),{toasts:A,setToasts:R,dismissToast:D,pushToast:L}=to(),[S,P]=a.useState([]),[K,C]=a.useState({}),[H,Q]=a.useState({}),{activeChatTab:J,setActiveChatTab:G,activeConv:se,conversations:X,extensionTabs:te,hasExtensions:ee,resolveConversationByTarget:oe}=Qa({ideData:x,allIdes:o,connectionStates:i,localUserMessages:K,ideName:p});sn({conversations:X,visibleConversations:X,clearedTabs:H,setClearedTabs:Q,setActionLogs:P});const{connScreenshot:O,screenshotUsage:$,handleRemoteAction:E}=eo({doId:l,ideId:s||"",ideType:d,connState:f,viewMode:m,instanceId:x==null?void 0:x.instanceId}),_=!!o.find(W=>W.type==="adhdev-daemon"),B=an({sendDaemonCommand:u,activeConv:se,setLocalUserMessages:C,setActionLogs:P,isStandalone:_}),{isCreatingChat:F,isRefreshingHistory:V,handleRefreshHistory:re,handleSwitchSession:le,handleNewChat:ie}=Za({ideId:s||"",activeConv:se,historyModalOpen:w,chats:x==null?void 0:x.chats,sendDaemonCommand:u,updateIdeChats:c,pushToast:L});return nn({ides:o,sendDaemonCommand:u,setToasts:R,setLocalUserMessages:C,resolveConversationByTarget:oe}),s?se?e.jsxs("div",{className:"ide-page",children:[e.jsx(Ga,{ideName:p,workspaceName:h,connState:f,machineName:I,viewMode:m,onChangeView:N,onOpenHistory:()=>y(!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 ${m==="chat"?"full":""} ${m==="remote"?"hidden":""}`,children:[e.jsx(Xa,{hasExtensions:ee,ideName:p,activeChatTab:J,extensionTabs:te,onSelectTab:W=>{G(W);const q=X.find(U=>U.tabKey===W);(q==null?void 0:q.streamSource)==="agent-stream"&&u(q.ideId,"focus_session",{agentType:q.agentType,...q.sessionId&&{targetSessionId:q.sessionId}}).catch(()=>{})}}),e.jsx(Ps,{activeConv:se,onModalButton:B.handleModalButton}),e.jsx(Ws,{activeConv:se,ideEntry:o.find(W=>W.id===se.ideId),handleSendChat:B.handleSendChat,isSendingChat:B.isSendingChat,handleFocusAgent:B.handleFocusAgent,isFocusingAgent:B.isFocusingAgent,actionLogs:S,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${m==="remote"?"full":""} ${m==="chat"?"hidden":""}`,children:e.jsx(sr,{addLog:()=>{},connState:f,connScreenshot:O,screenshotUsage:$,transportType:j,onAction:E})})]}),e.jsx(Ja,{toasts:A,onDismiss:D}),w&&e.jsx(zs,{activeConv:se,ides:o,isCreatingChat:F,isRefreshingHistory:V,onClose:()=>y(!1),onNewChat:ie,onSwitchSession:le,onRefreshHistory:re})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function no({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:o}){const[c,i]=a.useState([]),[u,l]=a.useState(null),[x,d]=a.useState(null),[p,g]=a.useState(!1),[f,j]=a.useState(!1),[k,I]=a.useState(!1),[h,b]=a.useState([]),[v,T]=a.useState([]),[m,N]=a.useState(null),[w,y]=a.useState(!1),[A,R]=a.useState(""),D=a.useRef(null),L=a.useCallback(E=>{D.current=E},[]),S=a.useCallback((E,_,B=!1)=>{i(F=>[...F.slice(-100),{timestamp:Date.now(),level:E,message:_}]),setTimeout(()=>{var F;return(F=o.current)==null?void 0:F.scrollIntoView({behavior:"smooth"})},100),B&&_e.showToast(_,E==="error"||E==="warn"?"warning":"success")},[o]),P=a.useCallback(async(E,_)=>{var B;if(!t||u)return!1;l(E),S("info",`Launching ${xe(E)}${_!=null&&_.workspace?` in ${_.workspace}`:""}...`);try{const F={ideType:E,enableCdp:!0};(B=_==null?void 0:_.workspace)!=null&&B.trim()?F.workspace=_.workspace.trim():_!=null&&_.useDefaultWorkspace&&(F.useDefaultWorkspace=!0);const V=await n(t,"launch_ide",F);return S(V!=null&&V.success?"info":"error",V!=null&&V.success?`${xe(E)} launched`:`Failed: ${V==null?void 0:V.error}`,!0),!!(V!=null&&V.success)}catch(F){return S("error",`Launch error: ${F.message}`,!0),!1}finally{l(null)}},[t,u,S,n]),K=a.useCallback(async E=>{if(!t)return{success:!1};const{cliType:_,dir:B,workspaceId:F,useDefaultWorkspace:V,useHome:re,argsStr:le,model:ie}=E;if(!_)return S("warn","Select a CLI or ACP provider first",!0),{success:!1};const de=le?le.split(/\s+/).filter(Boolean):void 0,W=(B==null?void 0:B.trim())||(F?"(saved id)":V?"(default workspace)":re?"(home)":"");S("info",`Launching ${_}${W?` in ${W}`:""}${ie?` (model: ${ie})`:""}...`),d(_);try{const q={cliType:_,cliArgs:de,initialModel:ie||void 0};B!=null&&B.trim()?q.dir=B.trim():F?q.workspaceId=F:V?q.useDefaultWorkspace=!0:re&&(q.useHome=!0);const U=await n(t,"launch_cli",q),M=(U==null?void 0:U.result)||U;return U!=null&&U.success?(S("info",`${_} launched`,!0),(M==null?void 0:M.launchSource)==="home"?S("info","📂 Running in home directory (explicit choice)"):(M==null?void 0:M.launchSource)==="defaultWorkspace"&&S("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:M==null?void 0:M.sessionId}):(S("error",`Failed: ${(U==null?void 0:U.error)||(M==null?void 0:M.error)}`,!0),(U==null?void 0:U.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&N({cliType:_,argsStr:le,model:ie}),{success:!1,sessionId:M==null?void 0:M.sessionId})}catch(q){return S("error",`Launch error: ${q.message}`,!0),{success:!1}}finally{d(null)}},[t,S,n]),C=a.useCallback(async(E,_,B,F)=>t?E?_.trim()?K({cliType:E,dir:_,argsStr:B,model:F}):(N({cliType:E,argsStr:B,model:F}),{success:!1}):(S("warn","Select a provider",!0),{success:!1}):{success:!1},[t,S,K]),H=a.useCallback(async(E,_,B)=>{if(t&&window.confirm(`Stop ${E}?
60
- This will terminate the process.`))try{const F=await n(t,"stop_cli",{cliType:E,dir:_,targetSessionId:B});F!=null&&F.success?S("info",`${E} stopped`,!0):S("error",`Stop failed: ${(F==null?void 0:F.error)||"Unknown error"}`,!0)}catch(F){S("error",`Stop failed: ${F.message}`,!0)}},[t,S,n]),Q=a.useCallback(async E=>{try{await n(E.daemonId,"restart_ide",{ideType:E.type}),S("info",`${xe(E.type)} restart initiated`,!0)}catch(_){S("error",`Restart failed: ${_.message}`,!0)}},[S,n]),J=a.useCallback(async E=>{if(window.confirm(`Stop ${xe(E.type)}?
61
- This will disconnect CDP and optionally kill the process.`))try{const _=await n(E.daemonId,"stop_ide",{ideType:E.type,killProcess:!0});_!=null&&_.success?S("info",`${xe(E.type)} stopped`,!0):S("error",`Stop failed: ${(_==null?void 0:_.error)||"Unknown error"}`,!0)}catch(_){S("error",`Stop failed: ${_.message}`,!0)}},[S,n]),G=a.useCallback(async()=>{if(t)try{const E=await n(t,"detect_ides",{});S("info",`Found ${((E==null?void 0:E.result)||[]).length} IDE(s)`,!0)}catch(E){S("error",`Detection failed: ${E.message}`,!0)}},[t,S,n]),se=a.useCallback(async()=>{if(t){g(!0);try{const E=await n(t,"get_recent_workspaces",{});E!=null&&E.success&&Array.isArray(E==null?void 0:E.result)&&T(E.result)}catch(E){S("error",`Failed: ${E.message}`)}finally{g(!1)}}},[t,S,n]),X=a.useCallback(async E=>{if(!(!t||!E.trim())){j(!0);try{const _=await n(t,"workspace_add",{path:E.trim()});_!=null&&_.success?S("info",`Workspace added: ${E.trim()}`):S("error",(_==null?void 0:_.error)||"workspace_add failed")}catch(_){S("error",_.message)}finally{j(!1)}return!0}},[t,S,n]),te=a.useCallback(async E=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){j(!0);try{const _=await n(t,"workspace_remove",{id:E});_!=null&&_.success?S("info","Workspace removed",!0):S("error",(_==null?void 0:_.error)||"workspace_remove failed",!0)}catch(_){S("error",_.message,!0)}finally{j(!1)}}},[t,S,n]),ee=a.useCallback(async E=>{var _;if(t){j(!0);try{const B=await n(t,"workspace_set_default",E===null?{clear:!0}:{id:E});if(B!=null&&B.success){S("info",E?"Default workspace updated":"Default workspace cleared",!0);const F=typeof B.defaultWorkspacePath=="string"?B.defaultWorkspacePath:"";F&&((_=D.current)==null||_.call(D,F))}else S("error",(B==null?void 0:B.error)||"workspace_set_default failed",!0)}catch(B){S("error",B.message,!0)}finally{j(!1)}}},[t,S,n]),oe=a.useCallback(async E=>{var B;if(!t||!E.trim())return;const _=E.trim();j(!0);try{const F=await n(t,"workspace_set_default",{path:_});F!=null&&F.success?(S("info","Default workspace set from history"),(B=D.current)==null||B.call(D,_)):S("error",(F==null?void 0:F.error)||"Could not set default (path missing on disk?)")}catch(F){S("error",F.message)}finally{j(!1)}},[t,S,n]),O=a.useCallback(async()=>{var E;if(t){I(!0);try{const _=await n(t,"get_cli_history",{}),B=(_==null?void 0:_.history)??((E=_==null?void 0:_.result)==null?void 0:E.history);_!=null&&_.success&&Array.isArray(B)&&b(B)}catch{}I(!1)}},[t,n]),$=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:A}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:A})}catch(E){S("warn",`Live nickname updated, but account sync failed: ${E.message}`)}S("info",`Nickname set to "${A||"(cleared)"}"`),y(!1)}catch(E){S("error",`Failed: ${E.message}`)}},[t,A,s,S,r,n]);return{logs:c,launchingIde:u,launchingAgentType:x,loadingWorkspaces:p,workspaceBusy:f,loadingHistory:k,cliHistory:h,recentWorkspaces:v,launchPick:m,setLaunchPick:N,editingNickname:w,setEditingNickname:y,nicknameInput:A,setNicknameInput:R,addLog:S,handleLaunchIde:P,runLaunchCliCore:K,handleLaunchCli:C,handleStopCli:H,handleRestartIde:Q,handleStopIde:J,handleDetectIdes:G,handleLoadRecentWorkspaces:se,handleWorkspaceAdd:X,handleWorkspaceRemove:te,handleWorkspaceSetDefault:ee,handleWorkspaceResumePath:oe,loadCliHistory:O,handleSaveNickname:$,setOnDefaultWorkspaceChanged:L}}function ro(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 ao({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:o,isDashboardHidden:c,onToggleDashboardVisibility:i}){const{workspaceBusy:u,handleWorkspaceAdd:l,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=o,[p,g]=a.useState(""),f=t.availableMem??t.freeMem,j=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-f)/t.totalMem*100))):0,k=t.loadavg[0]||0,I=[...t.workspaceActivity||[]].sort((b,v)=>v.lastUsedAt-b.lastUsedAt).slice(0,5),h=[...s.map(b=>({id:b.id,label:`IDE · ${b.type}`,workspace:b.workspace||""})),...n.map(b=>({id:b.id,label:`CLI · ${b.cliName}`,workspace:b.workspace||""})),...r.map(b=>({id:b.id,label:`ACP · ${b.acpName}`,workspace:b.workspace||""}))].filter(b=>c==null?void 0:c(b.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(ut,{icon:e.jsx(As,{size:16}),label:"Uptime",value:cr(t.uptime)}),e.jsx(ut,{icon:e.jsx(Re,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ut,{icon:e.jsx(Ft,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(ut,{icon:e.jsx(Rs,{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(Jt,{value:Math.min(Math.round(k/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${k.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Jt,{value:j,max:100,label:"Memory",color:"#3b82f6",detail:`${Qt(t.totalMem-f)} / ${Qt(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Pt,{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:u,value:t.defaultWorkspaceId||"",onChange:b=>void d(b.target.value===""?null:b.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(b=>e.jsx("option",{value:b.id,children:b.label||b.path},b.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:p,disabled:u,onChange:b=>g(b.target.value),onKeyDown:b=>b.key==="Enter"&&void(async()=>{await l(p)&&g("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:u,onClick:async()=>{await l(p)&&g("")},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(b=>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:[b.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Bt(b.path,b.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:b.path,children:b.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:u,onClick:()=>void x(b.id),children:"Remove"})]},b.id))}),I.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:I.map(b=>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:Bt(b.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:b.path,children:b.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[b.kind?`${b.kind} · `:"",ro(b.lastUsedAt)]})]},`${b.path}:${b.lastUsedAt}`))})]})]}),h.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:h.map(b=>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:b.label}),b.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:b.workspace,children:b.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(b.id),children:"Show"})]},b.id))})]})]})}function oo(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 $t({category:t,machine:s,machineId:n,providers:r,managedEntries:o,getIcon:c,actions:i,sendDaemonCommand:u,isDashboardHidden:l,onToggleDashboardVisibility:x}){const d=it(),{handleLaunchIde:p,handleLaunchCli:g,handleStopCli:f,handleRestartIde:j,handleStopIde:k,handleDetectIdes:I,cliHistory:h,loadingHistory:b,loadCliHistory:v,launchingIde:T,launchingAgentType:m}=i,[N,w]=a.useState(null),y=a.useCallback(M=>{M&&d({pathname:"/",search:`?activeTab=${encodeURIComponent(M)}`})},[d]),A=io[t],R=t==="ide",D=t==="acp",L=r.filter(M=>M.category===t),S=new Map(L.map(M=>[M.type,M.displayName||M.type])),[P,K]=a.useState(""),[C,H]=a.useState(""),[Q,J]=a.useState(""),[G,se]=a.useState(s.defaultWorkspaceId||""),[X,te]=a.useState(""),[ee,oe]=a.useState([]),O=ee.filter(M=>!o.some(Y=>Y.type===M&&me(Y.status)!=="stopped")),$=a.useRef({});a.useEffect(()=>{!P&&L.length>0&&K(L[0].type)},[P,L.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!G&&se(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const E=(()=>{if(G==="__custom__")return X.trim();if(!G)return"";const M=(s.workspaces||[]).find(Y=>Y.id===G);return(M==null?void 0:M.path)||""})(),_=a.useCallback(M=>{const Y=$.current[M];Y&&(clearTimeout(Y),delete $.current[M]),oe(z=>z.filter(ne=>ne!==M))},[]),B=a.useCallback(M=>{if(!M)return;oe(z=>z.includes(M)?z:[...z,M]);const Y=$.current[M];Y&&clearTimeout(Y),$.current[M]=setTimeout(()=>{oe(z=>z.filter(ne=>ne!==M)),delete $.current[M]},2e4)},[]);a.useEffect(()=>{for(const M of o)me(M.status)!=="stopped"&&_(M.type)},[o,_]),a.useEffect(()=>()=>{Object.values($.current).forEach(clearTimeout),$.current={}},[]);const[F,V]=a.useState({}),[re,le]=a.useState(null);a.useEffect(()=>{if(!R||!n||!u)return;(async()=>{try{const Y=await u(n,"get_ide_extensions",{}),z=(Y==null?void 0:Y.result)||Y;z!=null&&z.success&&(z!=null&&z.ideExtensions)&&V(z.ideExtensions)}catch{}})()},[R,n,u]);const ie=M=>R?xe(M.type):t==="cli"?M.cliName:M.acpName,de=R?s.detectedIdes||[]:[],W=()=>{(async()=>{if(R){await p(P,E?{workspace:E}:void 0)&&B(P);return}const M=await g(P,E,C||void 0,D&&Q||void 0);M.success&&(B(P),M.sessionId&&y(M.sessionId))})()},q=M=>{R?k(M):f(M.type,M.workspace,M.id)},U=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:M=>{se(M.target.value),M.target.value!=="__custom__"&&te("")},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(M=>e.jsxs("option",{value:M.id,children:[M.id===s.defaultWorkspaceId?"⭐ ":"",Bt(M.path,M.label)]},M.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:X,onChange:M=>te(M.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__"?E?e.jsx("span",{className:"font-mono truncate block",title:E,children:E}):"Enter an absolute path to launch there.":E?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:E,children:E})]}):"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 ${A.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",A.label]}),U,R?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[de.map(M=>{const Y=o.find(be=>(be.type||"").toLowerCase()===(M.type||"").toLowerCase()&&me(be.status)!=="stopped"),z=M.running||!!Y,ne=!!Y&&Y.cdpConnected,Z=ee.includes(M.type||M.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&Y){d(`/ide/${Y.id}`);return}Z||(async()=>await p(M.type||M.id||"",E?{workspace:E}:void 0)&&B(M.type||M.id||""))()},disabled:!!T||Z,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:T&&T!==M.type?.4:1},children:[e.jsx("span",{children:c(M.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)]"}),Z?`⏳ Waiting for ${M.name||xe(M.type)}...`:ne?`Open ${M.name||xe(M.type)}`:T===M.type?"⏳ Launching...":`▶ ${M.name||xe(M.type)}`,z&&ne&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},M.type)}),de.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:I,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Dn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:P,onChange:M=>K(M.target.value),className:"machine-input",children:L.length>0?L.map(M=>e.jsxs("option",{value:M.type,children:[M.icon," ",M.displayName]},M.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),D&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Q,onChange:M=>J(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:C,onChange:M=>H(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:W,disabled:!!m,className:"machine-btn-primary",children:m===P?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",o.length+ee.filter(M=>!o.some(Y=>Y.type===M&&me(Y.status)!=="stopped")).length,")"]}),o.length===0&&O.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 ",A.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[O.map(M=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-amber-500/20",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(M)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:R?xe(M):S.get(M)||M}),e.jsx("div",{className:"text-[11px] text-text-muted",children:m===M?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold bg-amber-500/[0.08] text-amber-400",children:"starting"})]})},`pending:${M}`)),o.map(M=>{const Y=R?M:null,z=D?M:null,ne=!R&&!D?M:null,Z=me(M.status),be=(l==null?void 0:l(M.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(M.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(M),(Y==null?void 0:Y.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",Y.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:M.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",z.currentPlan]})]}),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 ae;(ae=navigator.clipboard)==null||ae.writeText(`adhdev attach ${ne.runtimeKey}`),w(ne.runtimeKey||null),window.setTimeout(()=>{w(Me=>Me===ne.runtimeKey?null:Me)},1200)},children:N===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{className:ne.runtimeWriteOwner.ownerType==="user"?"text-amber-500":"text-violet-400",children:oo(ne.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[x&&e.jsx("button",{onClick:()=>x(M.id),className:`machine-btn ${be?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:be?"Show on Dashboard":"Hide from Dashboard",children:be?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Z==="stopped"?"bg-red-500/[0.08] text-red-500":Z==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Z}),R&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(Re,{size:13})," Control"]}),e.jsx("button",{onClick:()=>j(M),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),D&&e.jsx("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn",title:"View chat",children:e.jsx(Ye,{size:14})}),ne&&Z!=="stopped"&&e.jsxs("button",{onClick:()=>y(M.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Re,{size:13})," Open"]}),Z==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(R){await p(M.type,M.workspace?{workspace:M.workspace}:void 0)&&B(M.type);return}const ae=await g(M.type,M.workspace);ae.success&&(B(M.type),ae.sessionId&&y(ae.sessionId))})()},disabled:ee.includes(M.type),className:"machine-btn text-green-500 border-green-500/30",children:ee.includes(M.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>q(M),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),Y&&Y.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:Y.aiAgents.map(ae=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Ds(ae.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[ae.name," · ",me(ae.status)]},ae.id))}),Y&&(F[Y.type]||[]).length>0&&u&&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:(F[Y.type]||[]).map(ae=>e.jsxs("button",{disabled:re===`${Y.type}.${ae.type}`,onClick:async()=>{const Me=`${Y.type}.${ae.type}`;le(Me);try{await u(n,"set_ide_extension",{ideType:Y.type,extensionType:ae.type,enabled:!ae.enabled}),V(Se=>({...Se,[Y.type]:(Se[Y.type]||[]).map(Ce=>Ce.type===ae.type?{...Ce,enabled:!Ce.enabled}:Ce)}))}catch(Se){console.error("Extension toggle failed:",Se)}finally{le(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 ${ae.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 ${ae.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),ae.name,e.jsx("span",{className:"text-[9px] font-normal",children:ae.enabled?"ON":"OFF"})]},ae.type))})]})]},M.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:v,disabled:b,className:"machine-btn",children:b?"⏳":"↻ Load"})]}),(()=>{const M=new Set(L.map(z=>z.type)),Y=h.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:M.has(z.cliType));return Y.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:Y.map((z,ne)=>{var Z,be;return e.jsxs("div",{onClick:()=>{K(z.cliType),(z.workspace||z.dir)&&(se("__custom__"),te(z.workspace||z.dir)),H((z.cliArgs||[]).join(" ")),J(z.model||""),R&&(async()=>await p(z.cliType,z.workspace?{workspace:z.workspace}:void 0)&&B(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:((Z=z.workspace||z.dir)==null?void 0:Z.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"}),((be=z.cliArgs)==null?void 0:be.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 ",A.label," launch history yet."]})})()]})]})}const us=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],co=[{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 lo({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[o,c]=a.useState("config"),[i,u]=a.useState("codex-cli"),[l,x]=a.useState([]),[d,p]=a.useState(""),[g,f]=a.useState([]),[j,k]=a.useState(""),I=a.useRef(null),h=a.useRef(null),b=y=>{x(A=>A.includes(y)?A.filter(R=>R!==y):[...A,y])},v=()=>x([...us]),T=()=>x([]);a.useEffect(()=>{var y;(y=I.current)==null||y.scrollIntoView({behavior:"smooth"})},[g]),a.useEffect(()=>()=>{h.current&&clearInterval(h.current)},[]);const m=a.useCallback(()=>{h.current&&clearInterval(h.current),h.current=setInterval(async()=>{try{const y=await n(t,"provider_auto_fix_status",{providerType:s.type});(y==null?void 0:y.running)===!1&&o==="running"&&(c("done"),f(A=>[...A,`
62
- ✅ Auto-fix completed!`]),h.current&&clearInterval(h.current))}catch{}},3e3)},[t,s.type,n,o]),N=async()=>{if(l.length!==0){c("running"),f(["🚀 Starting auto-fix...",`Agent: ${i}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),k("");try{const y=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:i,...d?{comment:d}:{}});y!=null&&y.success&&(y!=null&&y.started||y!=null&&y.running)?(f(A=>[...A,"✅ Agent started. Monitoring progress..."]),m()):(c("error"),k((y==null?void 0:y.error)||"Failed to start auto-fix"))}catch(y){c("error"),k((y==null?void 0:y.message)||"Connection failed")}}},w=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),f(y=>[...y,`
63
- ⚠️ Auto-fix cancelled.`]),c("done"),h.current&&clearInterval(h.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:y=>y.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:[o==="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:co.map(y=>e.jsxs("button",{onClick:()=>u(y.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:i===y.value?y.color+"66":"var(--border-subtle)",background:i===y.value?y.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:i===y.value?y.color:"var(--text-primary)"},children:y.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:y.desc})]},y.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:v,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:us.map(y=>e.jsxs("button",{onClick:()=>b(y),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(y)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(y)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(y)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(y)?"☑ ":"☐ ",y]},y))})]}),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:y=>p(y.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"})]})]}),(o==="running"||o==="done"||o==="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:[g.map((y,A)=>e.jsx("div",{className:y.startsWith("✅")?"text-green-400":y.startsWith("❌")||y.startsWith("⚠")?"text-amber-400":"",children:y},A)),o==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:I})]}),j&&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:j})]})]}),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:[o==="config"&&l.length>0&&`${l.length} script(s) selected`,o==="running"&&"Agent is generating...",o==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[o==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:N,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"})]}),o==="running"&&e.jsx("button",{onClick:w,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(o==="done"||o==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("config"),f([]),k("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function uo({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:o}){var m;const c=s.filter(N=>N.category==="ide"),[i,u]=a.useState(((m=c[0])==null?void 0:m.type)||""),[l,x]=a.useState(""),[d,p]=a.useState(""),[g,f]=a.useState(!1),[j,k]=a.useState(""),[I,h]=a.useState(!1),b=N=>{const w=N.toLowerCase().replace(/[^a-z0-9-]/g,"");x(w),(!d||d===v(l))&&p(v(w))},v=N=>N.split("-").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" "),T=async()=>{if(!(!l||!d||!i)){f(!0),k("");try{const N=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:i});N!=null&&N.success||N!=null&&N.created?(h(!0),o==null||o(l)):k((N==null?void 0:N.error)||"Failed to create provider")}catch(N){k((N==null?void 0:N.message)||"Connection failed")}f(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick: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:N=>N.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:I?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(N=>e.jsxs("button",{onClick:()=>u(N.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:i===N.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:i===N.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:N.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:i===N.type?"#a78bfa":"var(--text-secondary)"},children:N.displayName})]},N.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:N=>b(N.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:N=>p(N.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"})]}),j&&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:j})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:I?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||g,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||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function xo({machineId:t,providers:s,sendDaemonCommand:n}){const[r,o]=a.useState([]),[c,i]=a.useState(!1),[u,l]=a.useState(null),[x,d]=a.useState("all"),[p,g]=a.useState(null),[f,j]=a.useState(!1),k=a.useCallback(async()=>{var h;if(t){i(!0);try{const b=await n(t,"get_provider_settings",{}),v=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&(v!=null&&v.settings)){const T=[];for(const[m,N]of Object.entries(v.settings)){const w=s.find(y=>y.type===m);T.push({type:m,displayName:(w==null?void 0:w.displayName)||m,icon:(w==null?void 0:w.icon)||"",category:(w==null?void 0:w.category)||"unknown",schema:N,values:((h=v.values)==null?void 0:h[m])||{}})}T.sort((m,N)=>m.category.localeCompare(N.category)||m.displayName.localeCompare(N.displayName)),o(T)}}catch{}i(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&k()},[]);const I=async(h,b,v)=>{l(`${h}.${b}`),o(T=>T.map(m=>m.type===h?{...m,values:{...m.values,[b]:v}}:m));try{const T=await n(t,"set_provider_setting",{providerType:h,key:b,value:v});T!=null&&T.success||k()}catch{k()}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(h=>e.jsx("button",{onClick:()=>d(h),className:`machine-btn text-[10px] px-2 py-0.5 ${x===h?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:h.toUpperCase()},h))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>j(!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:k,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(h=>h.category===x).length>1&&(()=>{const h=r.filter(m=>m.category===x),b=new Map;for(const m of h)for(const N of m.schema){if(N.type!=="boolean")continue;const w=b.get(N.key),y=!!(m.values[N.key]??N.default);w?(w.onCount+=y?1:0,w.total+=1):b.set(N.key,{label:N.label||N.key,onCount:y?1:0,total:1})}const v=[...b.entries()].filter(([,m])=>m.total===h.length);if(v.length===0)return null;const T=async(m,N)=>{for(const w of h)await I(w.type,m,N)};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 (",h.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:v.map(([m,N])=>{const w=N.onCount===N.total,y=N.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:N.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",N.onCount,"/",N.total,")"]}),e.jsx("button",{onClick:()=>void T(m,!0),disabled:w,className:`machine-btn text-[9px] px-1.5 py-px ${w?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(m,!1),disabled:y,className:`machine-btn text-[9px] px-1.5 py-px ${y?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},m)})})]})})(),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(h=>x==="all"||h.category===x).map(h=>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:h.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:h.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:h.category==="acp"?"rgba(139,92,246,0.08)":h.category==="cli"?"rgba(59,130,246,0.08)":h.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:h.category==="acp"?"#a78bfa":h.category==="cli"?"#60a5fa":h.category==="ide"?"#86efac":"#fbbf24"},children:h.category}),h.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(b=>b.type===h.type)||{type:h.type,displayName:h.displayName,icon:h.icon,category:h.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:h.schema.map(b=>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:[b.label||b.key,u===`${h.type}.${b.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),b.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:b.description})]}),e.jsx("div",{className:"shrink-0",children:b.type==="boolean"?e.jsx("button",{onClick:()=>I(h.type,b.key,!(h.values[b.key]??b.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:h.values[b.key]??b.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:h.values[b.key]??b.default?21:3}})}):b.type==="number"?e.jsx("input",{type:"number",value:h.values[b.key]??b.default??0,min:b.min,max:b.max,onChange:v=>{const T=parseInt(v.target.value)||0;b.min!==void 0&&T<b.min||b.max!==void 0&&T>b.max||I(h.type,b.key,T)},className:"machine-input w-20 text-center text-[11px]"}):b.type==="select"&&b.options?e.jsx("select",{value:h.values[b.key]??b.default??"",onChange:v=>I(h.type,b.key,v.target.value),className:"machine-input text-[11px]",children:b.options.map(v=>e.jsx("option",{value:v,children:v},v))}):e.jsx("input",{type:"text",value:h.values[b.key]??b.default??"",onBlur:v=>I(h.type,b.key,v.target.value),className:"machine-input w-[120px] text-[11px]"})})]},b.key))})]},h.type))}),p&&e.jsx(lo,{machineId:t,provider:p,sendDaemonCommand:n,onClose:()=>g(null)}),f&&e.jsx(uo,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>j(!1),onCreated:()=>{j(!1),k()}})]})}function ho({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[o,c]=a.useState(0),[i,u]=a.useState(!0),[l,x]=a.useState("debug"),d=a.useRef(null),p=a.useRef(!1);return a.useEffect(()=>{if(!t||!i)return;const g=async()=>{try{const j=await s(t,"get_logs",{count:200,minLevel:l,since:o}),k=(j==null?void 0:j.result)||j;if(j!=null&&j.success&&Array.isArray(k==null?void 0:k.logs)&&k.logs.length>0){r(h=>[...h,...k.logs.map(v=>({timestamp:v.ts,level:v.level,message:`[${v.category}] ${v.message}`}))].slice(-300));const I=Math.max(...k.logs.map(h=>h.ts));c(I)}}catch{}};g();const f=setInterval(g,3e3);return()=>clearInterval(f)},[t,i,o,l,s]),a.useEffect(()=>{if(i&&n.length>0){const g=p.current?"smooth":"instant";setTimeout(()=>{var f;(f=d.current)==null||f.scrollIntoView({behavior:g}),p.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(g=>e.jsx("button",{onClick:()=>{x(g),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),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:()=>u(!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((g,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},f)),e.jsx("div",{ref:d})]})]})}function po({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:o}=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:()=>{o(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:()=>{o(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:()=>{o(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:()=>o(null),children:"Cancel"})]})]})})}function mo({onNicknameSynced:t}={}){var w,y,A,R,D,L,S,P,K;const{id:s}=bs(),n=it(),{sendCommand:r}=Pe(),o=It(),c=o.ides||[],i=o.initialLoaded??!0,{isHidden:u,toggleTab:l}=tn(),x=c.find(C=>C.id===s&&C.daemonMode),[d,p]=a.useState("overview"),g=a.useRef(null),f=no({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:g});a.useEffect(()=>_e.onToast(H=>{o.setToasts(J=>{if(J.some(X=>X.message===H.message&&H.timestamp-X.timestamp<3e3))return J;const se={id:H.id,message:H.message,type:H.type,timestamp:H.timestamp,targetKey:H.targetKey,actions:H.actions};return[...J.slice(-4),se]});const Q=H.duration||5e3;setTimeout(()=>o.setToasts(J=>J.filter(G=>G.id!==H.id)),Q)}),[o]);const j=((x==null?void 0:x.availableProviders)||[]).map(C=>({type:C.type,displayName:C.displayName,icon:C.icon,category:C.category})),k={};for(const C of j)k[C.type]=C.icon;const I=C=>k[C]||"",h=x?{id:x.id,hostname:Bs(x,{fallbackId:x.id}),platform:((w=x.machine)==null?void 0:w.platform)||"unknown",arch:((y=x.machine)==null?void 0:y.arch)||"",cpus:((A=x.machine)==null?void 0:A.cpus)||0,totalMem:((R=x.machine)==null?void 0:R.totalMem)||0,freeMem:((D=x.machine)==null?void 0:D.freeMem)||0,availableMem:(L=x.machine)==null?void 0:L.availableMem,loadavg:((S=x.machine)==null?void 0:S.loadavg)||[],uptime:((P=x.machine)==null?void 0:P.uptime)||0,release:((K=x.machine)==null?void 0:K.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,b=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!es(C)&&!ts(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:pr(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],agentStreams:C.agentStreams||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),v=c.filter(C=>C.daemonId===s&&es(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&&ts(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(!h)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 m=Xe(x,{fallbackId:h.id}),N=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Re,{size:14})," IDEs"]}),count:b.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:14})," CLIs"]}),count:v.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{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(Pn,{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:[f.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:f.nicknameInput,onChange:C=>f.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&f.handleSaveNickname(),C.key==="Escape"&&f.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:f.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>f.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{f.setEditingNickname(!0),f.setNicknameInput(h.machineNickname||"")},title:"Click to set nickname",children:m}),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:[h.platform," · ",h.arch," · ",h.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 bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",x.serverVersion]}),h.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:h.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:h.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",h.p2p.state==="connected"?`● ${h.p2p.peers}`:"○"]}),h.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 ●"}),h.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",h.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:N.map(C=>e.jsxs("button",{onClick:()=>p(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(ao,{machine:h,ideSessions:b,cliSessions:v,acpSessions:T,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="ides"&&e.jsx($t,{category:"ide",machine:h,machineId:s,providers:j,managedEntries:b,getIcon:I,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l,sendDaemonCommand:r}),d==="clis"&&e.jsx($t,{category:"cli",machine:h,machineId:s,providers:j,managedEntries:v,getIcon:I,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="acps"&&e.jsx($t,{category:"acp",machine:h,machineId:s,providers:j,managedEntries:T,getIcon:I,actions:f,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="providers"&&e.jsx(xo,{machineId:s,providers:j,sendDaemonCommand:r}),d==="logs"&&e.jsx(ho,{machineId:s,sendDaemonCommand:r})]}),f.launchPick&&h&&e.jsx(po,{machine:h,launchPick:f.launchPick,actions:f}),e.jsx(Hs,{toasts:o.toasts||[],onDismiss:C=>o.setToasts(H=>H.filter(Q=>Q.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
59
+ `}),e.jsx(Hs,{toasts:h,onDismiss:je=>g(ve=>ve.filter(Ue=>Ue.id!==je)),onClickToast:je=>{if(je.targetKey){const ve=re(je.targetKey);ve&&T(ie.get(ve.tabKey)??0)}}}),x&&e.jsx(qa,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function Xa({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:o}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>o("native"),children:s}),r.map(c=>{const i=n===c.tabKey,u=c.status==="waiting_approval",l=c.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${i?"active":""}`,onClick:()=>o(c.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:u?"#f59e0b":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),c.title,u&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},c.tabKey)})]}):null}function Ga({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:o,onChangeView:c,onOpenHistory:i,headerActions:u,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(qe,{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:o===x?"1px solid var(--accent-primary)":"none",background:o===x?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:o===x?"var(--accent-primary)":void 0},onClick:()=>c(x),children:x==="chat"?e.jsx(qe,{size:14}):x==="split"?"⊞":e.jsx(Le,{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(Ms,{size:14})}),u,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 Ja({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 Za({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:o,updateIdeChats:c,pushToast:i}){const[u,l]=a.useState(!1),[x,d]=a.useState(!1),[h,g]=a.useState(!1),m=a.useRef(!1),b=a.useCallback(async y=>{const v=y.trim();if(!(!v||!t||h||!s)){g(!0);try{await o(t,"send_chat",{message:v,text:v,waitForResponse:!0,...Re(s)})}catch(T){console.error("[IDE] Send failed:",T)}finally{g(!1)}}},[t,h,o,s]),k=a.useCallback(async()=>{var y;if(!(!t||x||!s)){d(!0);try{const v=await o(t,"list_chats",{forceExpand:!0,...Re(s)}),T=(v==null?void 0:v.chats)||((y=v==null?void 0:v.result)==null?void 0:y.chats);v!=null&&v.success&&Array.isArray(T)&&c(t,T)}catch(v){console.error("[IDE] Refresh history failed:",v),i("히스토리 새로고침에 실패했습니다.","warning")}finally{d(!1)}}},[t,x,o,s,c,i]),I=a.useCallback(async(y,v)=>{if(!(!t||!s))try{const T=await o(t,"switch_chat",{id:v,sessionId:v,...Re(s)}),f=T==null?void 0:T.result;if((T==null?void 0:T.success)===!0||f==="switched"||f==="switched-by-title")return;f===!1||f==="not_found"?i("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof f=="string"&&f.startsWith("error:")?i(`세션 전환 오류: ${f}`,"warning"):i("세션 전환에 실패했습니다.","warning")}catch(T){console.error("[IDE] Switch session failed:",T),i(`세션 전환 실패: ${(T==null?void 0:T.message)||"connection error"}`,"warning")}},[t,o,s,i]),p=a.useCallback(async()=>{if(!(!t||u||!s)){l(!0);try{await o(t,"new_chat",{...Re(s)})}catch(y){console.error("[IDE] New chat failed:",y),i("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,u,o,s,i]);return a.useEffect(()=>{if(!n){m.current=!1;return}m.current||x||(!r||r.length===0)&&(m.current=!0,k())},[n,r,x,k]),{isSendingChat:h,isCreatingChat:u,isRefreshingHistory:x,handleSendAgent:b,handleRefreshHistory:k,handleSwitchSession:I,handleNewChat:p}}function Qa({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:o}){const[c,i]=a.useState("native"),u=a.useMemo(()=>Fs(s),[s]),l=a.useMemo(()=>{var k;if(!t)return[];const b=t.daemonId||((k=t.id)==null?void 0:k.split(":")[0])||t.id;return Us(t,r,{machineName:t.daemonId&&u[t.daemonId]||void 0,connectionState:n[b]||"new"})},[t,r,u,n]),x=a.useMemo(()=>l.find(b=>b.streamSource==="native"),[l]),d=a.useMemo(()=>l.filter(b=>b.streamSource==="agent-stream"),[l]);a.useEffect(()=>{var b;c!=="native"&&(d.some(k=>k.tabKey===c)||i(((b=d[0])==null?void 0:b.tabKey)||"native"))},[c,d]),a.useEffect(()=>{c==="native"&&(x||d[0]&&i(d[0].tabKey))},[c,x,d]);const h=a.useMemo(()=>c==="native"&&x?x:d.find(b=>b.tabKey===c)||x||d[0],[c,x,d]),g=a.useMemo(()=>d.map(b=>({tabKey:b.tabKey,title:b.title||b.agentName||o,status:b.status})),[d,o]),m=a.useCallback(b=>{if(b)return l.find(k=>k.sessionId===b||k.ideId===b||k.tabKey===b||k.ideType===b||k.agentType===b)},[l]);return{activeChatTab:c,setActiveChatTab:i,activeConv:h,conversations:l,extensionTabs:g,hasExtensions:g.length>0,resolveConversationByTarget:m}}function eo({doId:t,ideId:s,ideType:n,connState:r,viewMode:o,instanceId:c}){const[i,u]=a.useState(null),[l,x]=a.useState(null),d=a.useMemo(()=>{if(!s)return n;const g=s.split(":");return g.length>=3&&g[1]==="ide"?g.slice(2).join(":"):n},[s,n]);a.useEffect(()=>t?pe.onScreenshot("ide-page",(m,b)=>{if(m!==t)return;const k=new FileReader;k.onload=()=>u(k.result),k.readAsDataURL(b)}):void 0,[t]),a.useEffect(()=>{r!=="connected"&&u(null)},[r]),a.useEffect(()=>{var m;return t?((m=pe.onStatus)==null?void 0:m.call(pe,(b,k)=>{b===t&&k!=null&&k.screenshotUsage&&x(k.screenshotUsage)}))||(()=>{}):void 0},[t]),a.useEffect(()=>{u(null)},[t,s,d]),a.useEffect(()=>{const g=t?pe.get(t):null;if(!(!g||r!=="connected"))return o!=="chat"&&d?g.startScreenshots(d):g.stopScreenshots(d),()=>{g.stopScreenshots(d)}},[o,r,d,t]);const h=a.useCallback(async(g,m)=>{const b=t?pe.get(t):null;return!b||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):b.sendInput(g,m,c||d)},[t,r,c,d]);return{connScreenshot:i,screenshotUsage:l,handleRemoteAction:h}}function to(){const[t,s]=a.useState([]),n=a.useCallback(o=>{s(c=>c.filter(i=>i.id!==o))},[]),r=a.useCallback((o,c="warning")=>{const i=Date.now()+Math.floor(Math.random()*1e3);s(u=>[...u,{id:i,message:o,type:c}]),window.setTimeout(()=>{s(u=>u.filter(l=>l.id!==i))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function so({renderHeaderActions:t}={}){var de;const{id:s}=bs(),n=it(),r=It(),o=r.ides||[],c=r.updateIdeChats||(()=>{}),i=r.connectionStates||{},{sendCommand:u}=Pe(),l=a.useMemo(()=>Vs(s||"").daemonId,[s]),x=a.useMemo(()=>o.find(W=>W.id===s),[o,s]),d=(x==null?void 0:x.type)||void 0,h=d?d.charAt(0).toUpperCase()+d.slice(1):"IDE",g=r.isConnected??!0,m=i[l]||(g?"connected":"new"),b=((de=r.connectionTransports)==null?void 0:de[l])||"unknown",k=a.useMemo(()=>o.find(W=>W.id===l||W.daemonId===l),[o,l]),I=k?Xe(k,{fallbackId:l}):"",p=(x==null?void 0:x.workspace)||"",[y]=gs(),v=typeof window<"u"&&window.innerWidth<=768,T=y.get("view")||(v?"chat":"split"),[f,N]=a.useState(T),[w,j]=a.useState(!1),{toasts:A,setToasts:L,dismissToast:D,pushToast:R}=to(),[S,P]=a.useState([]),[K,C]=a.useState({}),[H,Q]=a.useState({}),{activeChatTab:J,setActiveChatTab:G,activeConv:se,conversations:X,extensionTabs:te,hasExtensions:ee,resolveConversationByTarget:oe}=Qa({ideData:x,allIdes:o,connectionStates:i,localUserMessages:K,ideName:h});sn({conversations:X,visibleConversations:X,clearedTabs:H,setClearedTabs:Q,setActionLogs:P});const{connScreenshot:O,screenshotUsage:$,handleRemoteAction:E}=eo({doId:l,ideId:s||"",ideType:d,connState:m,viewMode:f,instanceId:x==null?void 0:x.instanceId}),_=!!o.find(W=>W.type==="adhdev-daemon"),B=an({sendDaemonCommand:u,activeConv:se,setLocalUserMessages:C,setActionLogs:P,isStandalone:_}),{isCreatingChat:U,isRefreshingHistory:V,handleRefreshHistory:re,handleSwitchSession:le,handleNewChat:ie}=Za({ideId:s||"",activeConv:se,historyModalOpen:w,chats:x==null?void 0:x.chats,sendDaemonCommand:u,updateIdeChats:c,pushToast:R});return nn({ides:o,sendDaemonCommand:u,setToasts:L,setLocalUserMessages:C,resolveConversationByTarget:oe}),s?se?e.jsxs("div",{className:"ide-page",children:[e.jsx(Ga,{ideName:h,workspaceName:p,connState:m,machineName:I,viewMode:f,onChangeView:N,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 ${f==="chat"?"full":""} ${f==="remote"?"hidden":""}`,children:[e.jsx(Xa,{hasExtensions:ee,ideName:h,activeChatTab:J,extensionTabs:te,onSelectTab:W=>{G(W);const Y=X.find(F=>F.tabKey===W);(Y==null?void 0:Y.streamSource)==="agent-stream"&&u(Y.ideId,"focus_session",{agentType:Y.agentType,...Y.sessionId&&{targetSessionId:Y.sessionId}}).catch(()=>{})}}),e.jsx(Ps,{activeConv:se,onModalButton:B.handleModalButton}),e.jsx(Ws,{activeConv:se,ideEntry:o.find(W=>W.id===se.ideId),handleSendChat:B.handleSendChat,isSendingChat:B.isSendingChat,handleFocusAgent:B.handleFocusAgent,isFocusingAgent:B.isFocusingAgent,actionLogs:S,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${f==="remote"?"full":""} ${f==="chat"?"hidden":""}`,children:e.jsx(sr,{addLog:()=>{},connState:m,connScreenshot:O,screenshotUsage:$,transportType:b,onAction:E})})]}),e.jsx(Ja,{toasts:A,onDismiss:D}),w&&e.jsx(zs,{activeConv:se,ides:o,isCreatingChat:U,isRefreshingHistory:V,onClose:()=>j(!1),onNewChat:ie,onSwitchSession:le,onRefreshHistory:re})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function no({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:o}){const[c,i]=a.useState([]),[u,l]=a.useState(null),[x,d]=a.useState(null),[h,g]=a.useState(!1),[m,b]=a.useState(!1),[k,I]=a.useState(!1),[p,y]=a.useState([]),[v,T]=a.useState([]),[f,N]=a.useState(null),[w,j]=a.useState(!1),[A,L]=a.useState(""),D=a.useRef(null),R=a.useCallback(E=>{D.current=E},[]),S=a.useCallback((E,_,B=!1)=>{i(U=>[...U.slice(-100),{timestamp:Date.now(),level:E,message:_}]),setTimeout(()=>{var U;return(U=o.current)==null?void 0:U.scrollIntoView({behavior:"smooth"})},100),B&&_e.showToast(_,E==="error"||E==="warn"?"warning":"success")},[o]),P=a.useCallback(async(E,_)=>{var B;if(!t||u)return!1;l(E),S("info",`Launching ${xe(E)}${_!=null&&_.workspace?` in ${_.workspace}`:""}...`);try{const U={ideType:E,enableCdp:!0};(B=_==null?void 0:_.workspace)!=null&&B.trim()?U.workspace=_.workspace.trim():_!=null&&_.useDefaultWorkspace&&(U.useDefaultWorkspace=!0);const V=await n(t,"launch_ide",U);return S(V!=null&&V.success?"info":"error",V!=null&&V.success?`${xe(E)} launched`:`Failed: ${V==null?void 0:V.error}`,!0),!!(V!=null&&V.success)}catch(U){return S("error",`Launch error: ${U.message}`,!0),!1}finally{l(null)}},[t,u,S,n]),K=a.useCallback(async E=>{if(!t)return{success:!1};const{cliType:_,dir:B,workspaceId:U,useDefaultWorkspace:V,useHome:re,argsStr:le,model:ie}=E;if(!_)return S("warn","Select a CLI or ACP provider first",!0),{success:!1};const de=le?le.split(/\s+/).filter(Boolean):void 0,W=(B==null?void 0:B.trim())||(U?"(saved id)":V?"(default workspace)":re?"(home)":"");S("info",`Launching ${_}${W?` in ${W}`:""}${ie?` (model: ${ie})`:""}...`),d(_);try{const Y={cliType:_,cliArgs:de,initialModel:ie||void 0};B!=null&&B.trim()?Y.dir=B.trim():U?Y.workspaceId=U:V?Y.useDefaultWorkspace=!0:re&&(Y.useHome=!0);const F=await n(t,"launch_cli",Y),M=(F==null?void 0:F.result)||F;return F!=null&&F.success?(S("info",`${_} launched`,!0),(M==null?void 0:M.launchSource)==="home"?S("info","📂 Running in home directory (explicit choice)"):(M==null?void 0:M.launchSource)==="defaultWorkspace"&&S("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:M==null?void 0:M.sessionId}):(S("error",`Failed: ${(F==null?void 0:F.error)||(M==null?void 0:M.error)}`,!0),(F==null?void 0:F.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&N({cliType:_,argsStr:le,model:ie}),{success:!1,sessionId:M==null?void 0:M.sessionId})}catch(Y){return S("error",`Launch error: ${Y.message}`,!0),{success:!1}}finally{d(null)}},[t,S,n]),C=a.useCallback(async(E,_,B,U)=>t?E?_.trim()?K({cliType:E,dir:_,argsStr:B,model:U}):(N({cliType:E,argsStr:B,model:U}),{success:!1}):(S("warn","Select a provider",!0),{success:!1}):{success:!1},[t,S,K]),H=a.useCallback(async(E,_,B)=>{if(t&&window.confirm(`Stop ${E}?
60
+ This will terminate the process.`))try{const U=await n(t,"stop_cli",{cliType:E,dir:_,targetSessionId:B});U!=null&&U.success?S("info",`${E} stopped`,!0):S("error",`Stop failed: ${(U==null?void 0:U.error)||"Unknown error"}`,!0)}catch(U){S("error",`Stop failed: ${U.message}`,!0)}},[t,S,n]),Q=a.useCallback(async E=>{try{await n(E.daemonId,"restart_ide",{ideType:E.type}),S("info",`${xe(E.type)} restart initiated`,!0)}catch(_){S("error",`Restart failed: ${_.message}`,!0)}},[S,n]),J=a.useCallback(async E=>{if(window.confirm(`Stop ${xe(E.type)}?
61
+ This will disconnect CDP and optionally kill the process.`))try{const _=await n(E.daemonId,"stop_ide",{ideType:E.type,killProcess:!0});_!=null&&_.success?S("info",`${xe(E.type)} stopped`,!0):S("error",`Stop failed: ${(_==null?void 0:_.error)||"Unknown error"}`,!0)}catch(_){S("error",`Stop failed: ${_.message}`,!0)}},[S,n]),G=a.useCallback(async()=>{if(t)try{const E=await n(t,"detect_ides",{});S("info",`Found ${((E==null?void 0:E.result)||[]).length} IDE(s)`,!0)}catch(E){S("error",`Detection failed: ${E.message}`,!0)}},[t,S,n]),se=a.useCallback(async()=>{if(t){g(!0);try{const E=await n(t,"get_recent_workspaces",{});E!=null&&E.success&&Array.isArray(E==null?void 0:E.result)&&T(E.result)}catch(E){S("error",`Failed: ${E.message}`)}finally{g(!1)}}},[t,S,n]),X=a.useCallback(async E=>{if(!(!t||!E.trim())){b(!0);try{const _=await n(t,"workspace_add",{path:E.trim()});_!=null&&_.success?S("info",`Workspace added: ${E.trim()}`):S("error",(_==null?void 0:_.error)||"workspace_add failed")}catch(_){S("error",_.message)}finally{b(!1)}return!0}},[t,S,n]),te=a.useCallback(async E=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){b(!0);try{const _=await n(t,"workspace_remove",{id:E});_!=null&&_.success?S("info","Workspace removed",!0):S("error",(_==null?void 0:_.error)||"workspace_remove failed",!0)}catch(_){S("error",_.message,!0)}finally{b(!1)}}},[t,S,n]),ee=a.useCallback(async E=>{var _;if(t){b(!0);try{const B=await n(t,"workspace_set_default",E===null?{clear:!0}:{id:E});if(B!=null&&B.success){S("info",E?"Default workspace updated":"Default workspace cleared",!0);const U=typeof B.defaultWorkspacePath=="string"?B.defaultWorkspacePath:"";U&&((_=D.current)==null||_.call(D,U))}else S("error",(B==null?void 0:B.error)||"workspace_set_default failed",!0)}catch(B){S("error",B.message,!0)}finally{b(!1)}}},[t,S,n]),oe=a.useCallback(async E=>{var B;if(!t||!E.trim())return;const _=E.trim();b(!0);try{const U=await n(t,"workspace_set_default",{path:_});U!=null&&U.success?(S("info","Default workspace set from history"),(B=D.current)==null||B.call(D,_)):S("error",(U==null?void 0:U.error)||"Could not set default (path missing on disk?)")}catch(U){S("error",U.message)}finally{b(!1)}},[t,S,n]),O=a.useCallback(async()=>{var E;if(t){I(!0);try{const _=await n(t,"get_cli_history",{}),B=(_==null?void 0:_.history)??((E=_==null?void 0:_.result)==null?void 0:E.history);_!=null&&_.success&&Array.isArray(B)&&y(B)}catch{}I(!1)}},[t,n]),$=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:A}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:A})}catch(E){S("warn",`Live nickname updated, but account sync failed: ${E.message}`)}S("info",`Nickname set to "${A||"(cleared)"}"`),j(!1)}catch(E){S("error",`Failed: ${E.message}`)}},[t,A,s,S,r,n]);return{logs:c,launchingIde:u,launchingAgentType:x,loadingWorkspaces:h,workspaceBusy:m,loadingHistory:k,cliHistory:p,recentWorkspaces:v,launchPick:f,setLaunchPick:N,editingNickname:w,setEditingNickname:j,nicknameInput:A,setNicknameInput:L,addLog:S,handleLaunchIde:P,runLaunchCliCore:K,handleLaunchCli:C,handleStopCli:H,handleRestartIde:Q,handleStopIde:J,handleDetectIdes:G,handleLoadRecentWorkspaces:se,handleWorkspaceAdd:X,handleWorkspaceRemove:te,handleWorkspaceSetDefault:ee,handleWorkspaceResumePath:oe,loadCliHistory:O,handleSaveNickname:$,setOnDefaultWorkspaceChanged:R}}function ro(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 ao({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:o,isDashboardHidden:c,onToggleDashboardVisibility:i}){const{workspaceBusy:u,handleWorkspaceAdd:l,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=o,[h,g]=a.useState(""),m=t.availableMem??t.freeMem,b=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-m)/t.totalMem*100))):0,k=t.loadavg[0]||0,I=[...t.workspaceActivity||[]].sort((y,v)=>v.lastUsedAt-y.lastUsedAt).slice(0,5),p=[...s.map(y=>({id:y.id,label:`IDE · ${y.type}`,workspace:y.workspace||""})),...n.map(y=>({id:y.id,label:`CLI · ${y.cliName}`,workspace:y.workspace||""})),...r.map(y=>({id:y.id,label:`ACP · ${y.acpName}`,workspace:y.workspace||""}))].filter(y=>c==null?void 0:c(y.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(ut,{icon:e.jsx(As,{size:16}),label:"Uptime",value:cr(t.uptime)}),e.jsx(ut,{icon:e.jsx(Le,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ut,{icon:e.jsx(Ut,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(ut,{icon:e.jsx(Ls,{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(Jt,{value:Math.min(Math.round(k/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${k.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Jt,{value:b,max:100,label:"Memory",color:"#3b82f6",detail:`${Qt(t.totalMem-m)} / ${Qt(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Pt,{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:u,value:t.defaultWorkspaceId||"",onChange:y=>void d(y.target.value===""?null:y.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(y=>e.jsx("option",{value:y.id,children:y.label||y.path},y.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:u,onChange:y=>g(y.target.value),onKeyDown:y=>y.key==="Enter"&&void(async()=>{await l(h)&&g("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:u,onClick:async()=>{await l(h)&&g("")},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(y=>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:[y.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Bt(y.path,y.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:y.path,children:y.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:u,onClick:()=>void x(y.id),children:"Remove"})]},y.id))}),I.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:I.map(y=>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:Bt(y.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:y.path,children:y.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[y.kind?`${y.kind} · `:"",ro(y.lastUsedAt)]})]},`${y.path}:${y.lastUsedAt}`))})]})]}),p.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:p.map(y=>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:y.label}),y.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:y.workspace,children:y.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(y.id),children:"Show"})]},y.id))})]})]})}function oo(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 $t({category:t,machine:s,machineId:n,providers:r,managedEntries:o,getIcon:c,actions:i,sendDaemonCommand:u,isDashboardHidden:l,onToggleDashboardVisibility:x}){const d=it(),{handleLaunchIde:h,handleLaunchCli:g,handleStopCli:m,handleRestartIde:b,handleStopIde:k,handleDetectIdes:I,cliHistory:p,loadingHistory:y,loadCliHistory:v,launchingIde:T,launchingAgentType:f}=i,[N,w]=a.useState(null),j=a.useCallback(M=>{M&&d({pathname:"/",search:`?activeTab=${encodeURIComponent(M)}`})},[d]),A=io[t],L=t==="ide",D=t==="acp",R=r.filter(M=>M.category===t),S=new Map(R.map(M=>[M.type,M.displayName||M.type])),[P,K]=a.useState(""),[C,H]=a.useState(""),[Q,J]=a.useState(""),[G,se]=a.useState(s.defaultWorkspaceId||""),[X,te]=a.useState(""),[ee,oe]=a.useState([]),O=ee.filter(M=>!o.some(q=>q.type===M&&me(q.status)!=="stopped")),$=a.useRef({});a.useEffect(()=>{!P&&R.length>0&&K(R[0].type)},[P,R.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!G&&se(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const E=(()=>{if(G==="__custom__")return X.trim();if(!G)return"";const M=(s.workspaces||[]).find(q=>q.id===G);return(M==null?void 0:M.path)||""})(),_=a.useCallback(M=>{const q=$.current[M];q&&(clearTimeout(q),delete $.current[M]),oe(z=>z.filter(ne=>ne!==M))},[]),B=a.useCallback(M=>{if(!M)return;oe(z=>z.includes(M)?z:[...z,M]);const q=$.current[M];q&&clearTimeout(q),$.current[M]=setTimeout(()=>{oe(z=>z.filter(ne=>ne!==M)),delete $.current[M]},2e4)},[]);a.useEffect(()=>{for(const M of o)me(M.status)!=="stopped"&&_(M.type)},[o,_]),a.useEffect(()=>()=>{Object.values($.current).forEach(clearTimeout),$.current={}},[]);const[U,V]=a.useState({}),[re,le]=a.useState(null);a.useEffect(()=>{if(!L||!n||!u)return;(async()=>{try{const q=await u(n,"get_ide_extensions",{}),z=(q==null?void 0:q.result)||q;z!=null&&z.success&&(z!=null&&z.ideExtensions)&&V(z.ideExtensions)}catch{}})()},[L,n,u]);const ie=M=>L?xe(M.type):t==="cli"?M.cliName:M.acpName,de=L?s.detectedIdes||[]:[],W=()=>{(async()=>{if(L){await h(P,E?{workspace:E}:void 0)&&B(P);return}const M=await g(P,E,C||void 0,D&&Q||void 0);M.success&&(B(P),M.sessionId&&j(M.sessionId))})()},Y=M=>{L?k(M):m(M.type,M.workspace,M.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:M=>{se(M.target.value),M.target.value!=="__custom__"&&te("")},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(M=>e.jsxs("option",{value:M.id,children:[M.id===s.defaultWorkspaceId?"⭐ ":"",Bt(M.path,M.label)]},M.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:X,onChange:M=>te(M.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__"?E?e.jsx("span",{className:"font-mono truncate block",title:E,children:E}):"Enter an absolute path to launch there.":E?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:E,children:E})]}):"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 ${A.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",A.label]}),F,L?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[de.map(M=>{const q=o.find(be=>(be.type||"").toLowerCase()===(M.type||"").toLowerCase()&&me(be.status)!=="stopped"),z=M.running||!!q,ne=!!q&&q.cdpConnected,Z=ee.includes(M.type||M.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&q){d(`/ide/${q.id}`);return}Z||(async()=>await h(M.type||M.id||"",E?{workspace:E}:void 0)&&B(M.type||M.id||""))()},disabled:!!T||Z,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:T&&T!==M.type?.4:1},children:[e.jsx("span",{children:c(M.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)]"}),Z?`⏳ Waiting for ${M.name||xe(M.type)}...`:ne?`Open ${M.name||xe(M.type)}`:T===M.type?"⏳ Launching...":`▶ ${M.name||xe(M.type)}`,z&&ne&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},M.type)}),de.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:I,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Dn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:P,onChange:M=>K(M.target.value),className:"machine-input",children:R.length>0?R.map(M=>e.jsxs("option",{value:M.type,children:[M.icon," ",M.displayName]},M.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),D&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Q,onChange:M=>J(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:C,onChange:M=>H(M.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:W,disabled:!!f,className:"machine-btn-primary",children:f===P?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",o.length+ee.filter(M=>!o.some(q=>q.type===M&&me(q.status)!=="stopped")).length,")"]}),o.length===0&&O.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 ",A.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[O.map(M=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-amber-500/20",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(M)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:L?xe(M):S.get(M)||M}),e.jsx("div",{className:"text-[11px] text-text-muted",children:f===M?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold bg-amber-500/[0.08] text-amber-400",children:"starting"})]})},`pending:${M}`)),o.map(M=>{const q=L?M:null,z=D?M:null,ne=!L&&!D?M:null,Z=me(M.status),be=(l==null?void 0:l(M.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(M.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(M),(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:M.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",z.currentPlan]})]}),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 ae;(ae=navigator.clipboard)==null||ae.writeText(`adhdev attach ${ne.runtimeKey}`),w(ne.runtimeKey||null),window.setTimeout(()=>{w(Me=>Me===ne.runtimeKey?null:Me)},1200)},children:N===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{className:ne.runtimeWriteOwner.ownerType==="user"?"text-amber-500":"text-violet-400",children:oo(ne.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[x&&e.jsx("button",{onClick:()=>x(M.id),className:`machine-btn ${be?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:be?"Show on Dashboard":"Hide from Dashboard",children:be?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${Z==="stopped"?"bg-red-500/[0.08] text-red-500":Z==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:Z}),L&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(Le,{size:13})," Control"]}),e.jsx("button",{onClick:()=>b(M),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),D&&e.jsx("button",{onClick:()=>d(`/ide/${M.id}`),className:"machine-btn",title:"View chat",children:e.jsx(qe,{size:14})}),ne&&Z!=="stopped"&&e.jsxs("button",{onClick:()=>j(M.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Le,{size:13})," Open"]}),Z==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(L){await h(M.type,M.workspace?{workspace:M.workspace}:void 0)&&B(M.type);return}const ae=await g(M.type,M.workspace);ae.success&&(B(M.type),ae.sessionId&&j(ae.sessionId))})()},disabled:ee.includes(M.type),className:"machine-btn text-green-500 border-green-500/30",children:ee.includes(M.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>Y(M),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(ae=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Ds(ae.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[ae.name," · ",me(ae.status)]},ae.id))}),q&&(U[q.type]||[]).length>0&&u&&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(ae=>e.jsxs("button",{disabled:re===`${q.type}.${ae.type}`,onClick:async()=>{const Me=`${q.type}.${ae.type}`;le(Me);try{await u(n,"set_ide_extension",{ideType:q.type,extensionType:ae.type,enabled:!ae.enabled}),V(Se=>({...Se,[q.type]:(Se[q.type]||[]).map(Ce=>Ce.type===ae.type?{...Ce,enabled:!Ce.enabled}:Ce)}))}catch(Se){console.error("Extension toggle failed:",Se)}finally{le(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 ${ae.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 ${ae.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),ae.name,e.jsx("span",{className:"text-[9px] font-normal",children:ae.enabled?"ON":"OFF"})]},ae.type))})]})]},M.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:v,disabled:y,className:"machine-btn",children:y?"⏳":"↻ Load"})]}),(()=>{const M=new Set(R.map(z=>z.type)),q=p.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:M.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 Z,be;return e.jsxs("div",{onClick:()=>{K(z.cliType),(z.workspace||z.dir)&&(se("__custom__"),te(z.workspace||z.dir)),H((z.cliArgs||[]).join(" ")),J(z.model||""),L&&(async()=>await h(z.cliType,z.workspace?{workspace:z.workspace}:void 0)&&B(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:((Z=z.workspace||z.dir)==null?void 0:Z.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"}),((be=z.cliArgs)==null?void 0:be.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 ",A.label," launch history yet."]})})()]})]})}const us=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],co=[{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 lo({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[o,c]=a.useState("config"),[i,u]=a.useState("codex-cli"),[l,x]=a.useState([]),[d,h]=a.useState(""),[g,m]=a.useState([]),[b,k]=a.useState(""),I=a.useRef(null),p=a.useRef(null),y=j=>{x(A=>A.includes(j)?A.filter(L=>L!==j):[...A,j])},v=()=>x([...us]),T=()=>x([]);a.useEffect(()=>{var j;(j=I.current)==null||j.scrollIntoView({behavior:"smooth"})},[g]),a.useEffect(()=>()=>{p.current&&clearInterval(p.current)},[]);const f=a.useCallback(()=>{p.current&&clearInterval(p.current),p.current=setInterval(async()=>{try{const j=await n(t,"provider_auto_fix_status",{providerType:s.type});(j==null?void 0:j.running)===!1&&o==="running"&&(c("done"),m(A=>[...A,`
62
+ ✅ Auto-fix completed!`]),p.current&&clearInterval(p.current))}catch{}},3e3)},[t,s.type,n,o]),N=async()=>{if(l.length!==0){c("running"),m(["🚀 Starting auto-fix...",`Agent: ${i}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),k("");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)?(m(A=>[...A,"✅ Agent started. Monitoring progress..."]),f()):(c("error"),k((j==null?void 0:j.error)||"Failed to start auto-fix"))}catch(j){c("error"),k((j==null?void 0:j.message)||"Connection failed")}}},w=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),m(j=>[...j,`
63
+ ⚠️ Auto-fix cancelled.`]),c("done"),p.current&&clearInterval(p.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:[o==="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:co.map(j=>e.jsxs("button",{onClick:()=>u(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:v,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:us.map(j=>e.jsxs("button",{onClick:()=>y(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=>h(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"})]})]}),(o==="running"||o==="done"||o==="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:[g.map((j,A)=>e.jsx("div",{className:j.startsWith("✅")?"text-green-400":j.startsWith("❌")||j.startsWith("⚠")?"text-amber-400":"",children:j},A)),o==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:I})]}),b&&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:b})]})]}),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:[o==="config"&&l.length>0&&`${l.length} script(s) selected`,o==="running"&&"Agent is generating...",o==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[o==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:N,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"})]}),o==="running"&&e.jsx("button",{onClick:w,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(o==="done"||o==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{c("config"),m([]),k("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function uo({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:o}){var f;const c=s.filter(N=>N.category==="ide"),[i,u]=a.useState(((f=c[0])==null?void 0:f.type)||""),[l,x]=a.useState(""),[d,h]=a.useState(""),[g,m]=a.useState(!1),[b,k]=a.useState(""),[I,p]=a.useState(!1),y=N=>{const w=N.toLowerCase().replace(/[^a-z0-9-]/g,"");x(w),(!d||d===v(l))&&h(v(w))},v=N=>N.split("-").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" "),T=async()=>{if(!(!l||!d||!i)){m(!0),k("");try{const N=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:i});N!=null&&N.success||N!=null&&N.created?(p(!0),o==null||o(l)):k((N==null?void 0:N.error)||"Failed to create provider")}catch(N){k((N==null?void 0:N.message)||"Connection failed")}m(!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:N=>N.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:I?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(N=>e.jsxs("button",{onClick:()=>u(N.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:i===N.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:i===N.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:N.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:i===N.type?"#a78bfa":"var(--text-secondary)"},children:N.displayName})]},N.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:N=>y(N.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:N=>h(N.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"})]}),b&&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:b})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:I?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||g,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||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function xo({machineId:t,providers:s,sendDaemonCommand:n}){const[r,o]=a.useState([]),[c,i]=a.useState(!1),[u,l]=a.useState(null),[x,d]=a.useState("all"),[h,g]=a.useState(null),[m,b]=a.useState(!1),k=a.useCallback(async()=>{var p;if(t){i(!0);try{const y=await n(t,"get_provider_settings",{}),v=(y==null?void 0:y.result)||y;if(y!=null&&y.success&&(v!=null&&v.settings)){const T=[];for(const[f,N]of Object.entries(v.settings)){const w=s.find(j=>j.type===f);T.push({type:f,displayName:(w==null?void 0:w.displayName)||f,icon:(w==null?void 0:w.icon)||"",category:(w==null?void 0:w.category)||"unknown",schema:N,values:((p=v.values)==null?void 0:p[f])||{}})}T.sort((f,N)=>f.category.localeCompare(N.category)||f.displayName.localeCompare(N.displayName)),o(T)}}catch{}i(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&k()},[]);const I=async(p,y,v)=>{l(`${p}.${y}`),o(T=>T.map(f=>f.type===p?{...f,values:{...f.values,[y]:v}}:f));try{const T=await n(t,"set_provider_setting",{providerType:p,key:y,value:v});T!=null&&T.success||k()}catch{k()}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(p=>e.jsx("button",{onClick:()=>d(p),className:`machine-btn text-[10px] px-2 py-0.5 ${x===p?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:p.toUpperCase()},p))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>b(!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:k,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(p=>p.category===x).length>1&&(()=>{const p=r.filter(f=>f.category===x),y=new Map;for(const f of p)for(const N of f.schema){if(N.type!=="boolean")continue;const w=y.get(N.key),j=!!(f.values[N.key]??N.default);w?(w.onCount+=j?1:0,w.total+=1):y.set(N.key,{label:N.label||N.key,onCount:j?1:0,total:1})}const v=[...y.entries()].filter(([,f])=>f.total===p.length);if(v.length===0)return null;const T=async(f,N)=>{for(const w of p)await I(w.type,f,N)};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 (",p.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:v.map(([f,N])=>{const w=N.onCount===N.total,j=N.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:N.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",N.onCount,"/",N.total,")"]}),e.jsx("button",{onClick:()=>void T(f,!0),disabled:w,className:`machine-btn text-[9px] px-1.5 py-px ${w?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(f,!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"})]},f)})})]})})(),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(p=>x==="all"||p.category===x).map(p=>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:p.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:p.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.category==="acp"?"rgba(139,92,246,0.08)":p.category==="cli"?"rgba(59,130,246,0.08)":p.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:p.category==="acp"?"#a78bfa":p.category==="cli"?"#60a5fa":p.category==="ide"?"#86efac":"#fbbf24"},children:p.category}),p.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(y=>y.type===p.type)||{type:p.type,displayName:p.displayName,icon:p.icon,category:p.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:p.schema.map(y=>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:[y.label||y.key,u===`${p.type}.${y.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),y.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:y.description})]}),e.jsx("div",{className:"shrink-0",children:y.type==="boolean"?e.jsx("button",{onClick:()=>I(p.type,y.key,!(p.values[y.key]??y.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:p.values[y.key]??y.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:p.values[y.key]??y.default?21:3}})}):y.type==="number"?e.jsx("input",{type:"number",value:p.values[y.key]??y.default??0,min:y.min,max:y.max,onChange:v=>{const T=parseInt(v.target.value)||0;y.min!==void 0&&T<y.min||y.max!==void 0&&T>y.max||I(p.type,y.key,T)},className:"machine-input w-20 text-center text-[11px]"}):y.type==="select"&&y.options?e.jsx("select",{value:p.values[y.key]??y.default??"",onChange:v=>I(p.type,y.key,v.target.value),className:"machine-input text-[11px]",children:y.options.map(v=>e.jsx("option",{value:v,children:v},v))}):e.jsx("input",{type:"text",value:p.values[y.key]??y.default??"",onBlur:v=>I(p.type,y.key,v.target.value),className:"machine-input w-[120px] text-[11px]"})})]},y.key))})]},p.type))}),h&&e.jsx(lo,{machineId:t,provider:h,sendDaemonCommand:n,onClose:()=>g(null)}),m&&e.jsx(uo,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>b(!1),onCreated:()=>{b(!1),k()}})]})}function po({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[o,c]=a.useState(0),[i,u]=a.useState(!0),[l,x]=a.useState("debug"),d=a.useRef(null),h=a.useRef(!1);return a.useEffect(()=>{if(!t||!i)return;const g=async()=>{try{const b=await s(t,"get_logs",{count:200,minLevel:l,since:o}),k=(b==null?void 0:b.result)||b;if(b!=null&&b.success&&Array.isArray(k==null?void 0:k.logs)&&k.logs.length>0){r(p=>[...p,...k.logs.map(v=>({timestamp:v.ts,level:v.level,message:`[${v.category}] ${v.message}`}))].slice(-300));const I=Math.max(...k.logs.map(p=>p.ts));c(I)}}catch{}};g();const m=setInterval(g,3e3);return()=>clearInterval(m)},[t,i,o,l,s]),a.useEffect(()=>{if(i&&n.length>0){const g=h.current?"smooth":"instant";setTimeout(()=>{var m;(m=d.current)==null||m.scrollIntoView({behavior:g}),h.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(g=>e.jsx("button",{onClick:()=>{x(g),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),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:()=>u(!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((g,m)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},m)),e.jsx("div",{ref:d})]})]})}function ho({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:o}=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:()=>{o(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:()=>{o(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:()=>{o(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:()=>o(null),children:"Cancel"})]})]})})}function mo({onNicknameSynced:t}={}){var w,j,A,L,D,R,S,P,K;const{id:s}=bs(),n=it(),{sendCommand:r}=Pe(),o=It(),c=o.ides||[],i=o.initialLoaded??!0,{isHidden:u,toggleTab:l}=tn(),x=c.find(C=>C.id===s&&C.daemonMode),[d,h]=a.useState("overview"),g=a.useRef(null),m=no({machineId:s,registeredMachineId:(x==null?void 0:x.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:g});a.useEffect(()=>_e.onToast(H=>{o.setToasts(J=>{if(J.some(X=>X.message===H.message&&H.timestamp-X.timestamp<3e3))return J;const se={id:H.id,message:H.message,type:H.type,timestamp:H.timestamp,targetKey:H.targetKey,actions:H.actions};return[...J.slice(-4),se]});const Q=H.duration||5e3;setTimeout(()=>o.setToasts(J=>J.filter(G=>G.id!==H.id)),Q)}),[o]);const b=((x==null?void 0:x.availableProviders)||[]).map(C=>({type:C.type,displayName:C.displayName,icon:C.icon,category:C.category})),k={};for(const C of b)k[C.type]=C.icon;const I=C=>k[C]||"",p=x?{id:x.id,hostname:Bs(x,{fallbackId:x.id}),platform:((w=x.machine)==null?void 0:w.platform)||"unknown",arch:((j=x.machine)==null?void 0:j.arch)||"",cpus:((A=x.machine)==null?void 0:A.cpus)||0,totalMem:((L=x.machine)==null?void 0:L.totalMem)||0,freeMem:((D=x.machine)==null?void 0:D.freeMem)||0,availableMem:(R=x.machine)==null?void 0:R.availableMem,loadavg:((S=x.machine)==null?void 0:S.loadavg)||[],uptime:((P=x.machine)==null?void 0:P.uptime)||0,release:((K=x.machine)==null?void 0:K.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,y=c.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!es(C)&&!ts(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:hr(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],agentStreams:C.agentStreams||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),v=c.filter(C=>C.daemonId===s&&es(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&&ts(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(!p)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 f=Xe(x,{fallbackId:p.id}),N=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:14})," IDEs"]}),count:y.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:14})," CLIs"]}),count:v.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ls,{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(Pn,{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:[m.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:m.nicknameInput,onChange:C=>m.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&m.handleSaveNickname(),C.key==="Escape"&&m.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:m.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>m.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{m.setEditingNickname(!0),m.setNicknameInput(p.machineNickname||"")},title:"Click to set nickname",children:f}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[p.platform," · ",p.arch," · ",p.cpus," cores"]}),(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 bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",x.serverVersion]}),p.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:p.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",p.p2p.state==="connected"?`● ${p.p2p.peers}`:"○"]}),p.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),p.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",p.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:N.map(C=>e.jsxs("button",{onClick:()=>h(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(ao,{machine:p,ideSessions:y,cliSessions:v,acpSessions:T,actions:m,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="ides"&&e.jsx($t,{category:"ide",machine:p,machineId:s,providers:b,managedEntries:y,getIcon:I,actions:m,isDashboardHidden:u,onToggleDashboardVisibility:l,sendDaemonCommand:r}),d==="clis"&&e.jsx($t,{category:"cli",machine:p,machineId:s,providers:b,managedEntries:v,getIcon:I,actions:m,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="acps"&&e.jsx($t,{category:"acp",machine:p,machineId:s,providers:b,managedEntries:T,getIcon:I,actions:m,isDashboardHidden:u,onToggleDashboardVisibility:l}),d==="providers"&&e.jsx(xo,{machineId:s,providers:b,sendDaemonCommand:r}),d==="logs"&&e.jsx(po,{machineId:s,sendDaemonCommand:r})]}),m.launchPick&&p&&e.jsx(ho,{machine:p,launchPick:m.launchPick,actions:m}),e.jsx(Hs,{toasts:o.toasts||[],onDismiss:C=>o.setToasts(H=>H.filter(Q=>Q.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
64
64
  @keyframes toast-in {
65
65
  from { opacity: 0; transform: translateX(40px); }
66
66
  to { opacity: 1; transform: translateX(0); }
67
67
  }
68
- `})]})}function fo(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(i=>i.json()).then(i=>{const u=[],l=[],x=[],d=[];Object.values(i.providers||{}).forEach(g=>{const f={name:g.name||"Unknown",status:g.status||"Stable",details:g.details||"Community Provider"};g.category==="ide"?u.push(f):g.category==="cli"?l.push(f):g.category==="extension"?x.push(f):g.category==="acp"&&d.push(f)});const p=(g,f)=>{const j={Stable:1,Beta:2,WIP:3},k=j[g.status]||99,I=j[f.status]||99;return k!==I?k-I:g.name.localeCompare(f.name)};s({ide:u.sort(p),cli:l.sort(p),ext:x.sort(p),acp:d.sort(p)})}).catch(i=>console.error("Failed to load capabilities:",i)).finally(()=>r(!1))},[]);const o=i=>i==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Is,{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(As,{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((u,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:u.name}),e.jsx("td",{className:"py-3 px-4",children:o(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},l))})]})});return n?e.jsx(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",children:e.jsx(Vt,{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(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(fe,{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(fe,{title:"IDE support",icon:e.jsx(Re,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:c(t.ide)}),e.jsx(fe,{title:"Standalone CLI agents",icon:e.jsx(Ft,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:c(t.cli)}),e.jsx(fe,{title:"AI extensions",icon:e.jsx(qe,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:c(t.ext)}),e.jsx(fe,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(qe,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:c(t.acp)})]})}class go{constructor(){ue(this,"adapters",new Map);ue(this,"states",new Map);ue(this,"ptyCallbacks",new Set);ue(this,"screenshotCallbacks",new Map);ue(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,o){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){this.ptyCallbacks.forEach(r=>r(s,n))}}const $e=new go;function bo(){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 xs=bo(),hs=3e3,yo=3e4;let Ae=null,jo=0;const Ct=new Map;let Be=null,at=null;function vo(t){return t==="connected"?"connected":t}async function vt(t,s,n){const r=Mr(t,n||{}),o=Ae;if(o&&o.readyState===WebSocket.OPEN){const i=`req_${++jo}_${Date.now()}`;return new Promise((u,l)=>{const x=setTimeout(()=>{Ct.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);Ct.set(i,{resolve:d=>{clearTimeout(x),u(d)},reject:d=>{clearTimeout(x),l(d)}}),o.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 wo{constructor(s){ue(this,"daemonId");ue(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ae==null?void 0:Ae.readyState)===WebSocket.OPEN}get connectionState(){return(Ae==null?void 0:Ae.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return vt(this.daemonId,s,n)}async sendInput(s,n){return vt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Be&&(clearInterval(Be),Be=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await vt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const o=await fetch(`data:image/jpeg;base64,${r.base64}`).then(c=>c.blob());$e.emitScreenshot(this.daemonId,o)}}catch{}};n(),Be=setInterval(n,2e3)}stopScreenshots(s){Be&&(clearInterval(Be),Be=null)}}let ke=null;function No(t){return(!ke||ke.daemonId!==t)&&(ke=new wo(t)),ke}function ko({children:t}){const s=a.useRef(Xt()),n=Xt();s.current=n;const{setUserName:r}=ot(),o=a.useRef(r);o.current=r;const[,c]=a.useState("disconnected"),i=a.useCallback((g,f)=>{c(g),at==null||at(g,f)},[]),u=a.useRef(null),l=a.useRef(),x=a.useRef(hs),d=a.useRef(!0),p=a.useRef(!1);return a.useEffect(()=>{d.current=!0,p.current=!1;function g(){var k,I;if(!d.current||((k=u.current)==null?void 0:k.readyState)===WebSocket.OPEN||((I=u.current)==null?void 0:I.readyState)===WebSocket.CONNECTING)return;i("connecting"),console.log(`[Standalone WS] Connecting to ${xs}...`);let j;try{j=new WebSocket(xs)}catch(h){console.error("[Standalone WS] Failed to create WebSocket:",h),f();return}u.current=j,j.onopen=()=>{if(!d.current){j.close();return}i("connected"),x.current=hs,console.log("[Standalone WS] Connected")},Ae=j,j.onmessage=h=>{var b;try{const v=JSON.parse(h.data);if((v.type==="command_result"||v.type==="error")&&v.requestId){const T=Ct.get(v.requestId);T&&(Ct.delete(v.requestId),v.type==="error"?T.reject(new Error(((b=v.data)==null?void 0:b.message)||"Command failed")):T.resolve(v.data));return}if(v.type==="pty_output"){$e.emitPtyOutput(v.cliId,v.data);return}if(v.type==="status"||v.type==="initial_state"){const T=v.data;if(!T)return;const{injectEntries:m,markLoaded:N}=s.current,w=T.id||"standalone",y=No(w);$e.register(w,y),$e.setState(w,"connected"),i("connected",w),$e.emitStatus(w,T);const A=Ir(T,{daemonId:w});A.length>0&&m(A),N(),T.userName&&o.current&&o.current(T.userName)}}catch(v){console.error("[Standalone WS] Parse error:",v)}},j.onclose=()=>{d.current&&(ke==null||ke.stopScreenshots(),ke&&$e.setState(ke.daemonId,"disconnected"),i("disconnected"),u.current=null,f())},j.onerror=h=>{p.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",h)}}function f(){if(!d.current)return;clearTimeout(l.current);const j=x.current;console.log(`[Standalone WS] Reconnecting in ${j}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,yo),g()},j)}return g(),()=>{d.current=!1,p.current=!0,clearTimeout(l.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Ae=null),ke&&(ke.stopScreenshots(),$e.unregister(ke.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function So({children:t}){const[s,n]=a.useState("disconnected"),[r,o]=a.useState(null);a.useEffect(()=>(at=(i,u)=>{n(i),u&&o(u)},()=>{at=null}),[]);const c=a.useMemo(()=>{const i=s==="connected",u=vo(s),l={};return r&&(l[r]=u),l.standalone=u,{wsStatus:s,isConnected:i,connectionStates:l}},[s,r]);return e.jsx(In,{connectionOverrides:c,children:e.jsx(ko,{children:t})})}const Co=[{id:"dashboard",path:"/dashboard",icon:e.jsx(ks,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ss,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Ht,{}),label:"Settings"}];function Io({children:t}){const s=it(),n=jn(),[r,o]=a.useState(!1),[c,i]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=d=>{s(d),o(!1)},l=()=>{i(d=>{const p=!d;try{localStorage.setItem("sidebar-collapsed",p?"1":"0")}catch{}return p})},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:()=>o(!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:()=>o(!1),onKeyDown:d=>d.key==="Escape"&&o(!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:()=>o(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Co.map(d=>e.jsxs("div",{className:x(d.path),id:`nav-${d.id}`,onClick:()=>u(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(wt,{})}),!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(Cs,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.14"]}),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 Mo=[{icon:e.jsx(Ss,{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(Es,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Re,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(qe,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(wt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],To=[{icon:e.jsx(Ls,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(ks,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(_s,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx($n,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Rn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Is,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Eo=[{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 Ao(){return e.jsxs(Nt,{icon:e.jsx(Cs,{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.14"]}),children:[e.jsx(fe,{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(fe,{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:Mo.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(fe,{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:Ys.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Xs.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(fe,{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:To.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(fe,{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:Eo.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(Vt,{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(Un,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Lo(){const{ides:t}=ot(),s=t.find(p=>p.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Pe(),{userName:o}=ot(),[c,i]=a.useState(o||"");a.useEffect(()=>{o!==void 0&&i(o)},[o]);const u=p=>{const g=p.target.value.trim();s!=null&&s.id&&g!==o&&r(s.id,"set_user_name",{userName:g}).catch(console.error)},[l,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=p=>{x(p);try{localStorage.setItem("adhdev_sound",p?"1":"0")}catch{}};return e.jsxs(Nt,{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(Hr,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(fe,{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.14"]}),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(fe,{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(p=>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 ${p.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:p.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:p.type})]},p.type))})}),e.jsx(fe,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Jr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(fe,{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(ta,{})]}),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(ia,{})]})]})}),e.jsx(fe,{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(Gr,{}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Hn,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(fe,{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(_n,{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:p=>i(p.target.value),onBlur:u,onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()}})]})})})]})}qr();aa();const Ro=vs({baseUrl:""});function ps(){const{ides:t}=ot(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(gt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(gt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(gt,{to:"/dashboard",replace:!0})}function _o(){return e.jsx(vn,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Tn,{client:Ro,children:e.jsx(So,{children:e.jsx(Ln,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Io,{children:e.jsxs(wn,{children:[e.jsx(Ee,{path:"/dashboard",element:e.jsx(qa,{})}),e.jsx(Ee,{path:"/ide/:id",element:e.jsx(so,{})}),e.jsx(Ee,{path:"/machine",element:e.jsx(ps,{})}),e.jsx(Ee,{path:"/machines/:id",element:e.jsx(mo,{})}),e.jsx(Ee,{path:"/machines",element:e.jsx(ps,{})}),e.jsx(Ee,{path:"/capabilities",element:e.jsx(fo,{})}),e.jsx(Ee,{path:"/about",element:e.jsx(Ao,{})}),e.jsx(Ee,{path:"/settings",element:e.jsx(Lo,{})}),e.jsx(Ee,{path:"*",element:e.jsx(gt,{to:"/dashboard",replace:!0})})]})})})})})})}yr({connectionManager:$e});Nn(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(_o,{})}));
68
+ `})]})}function fo(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(i=>i.json()).then(i=>{const u=[],l=[],x=[],d=[];Object.values(i.providers||{}).forEach(g=>{const m={name:g.name||"Unknown",status:g.status||"Stable",details:g.details||"Community Provider"};g.category==="ide"?u.push(m):g.category==="cli"?l.push(m):g.category==="extension"?x.push(m):g.category==="acp"&&d.push(m)});const h=(g,m)=>{const b={Stable:1,Beta:2,WIP:3},k=b[g.status]||99,I=b[m.status]||99;return k!==I?k-I:g.name.localeCompare(m.name)};s({ide:u.sort(h),cli:l.sort(h),ext:x.sort(h),acp:d.sort(h)})}).catch(i=>console.error("Failed to load capabilities:",i)).finally(()=>r(!1))},[]);const o=i=>i==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Is,{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(Ft,{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(As,{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((u,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:u.name}),e.jsx("td",{className:"py-3 px-4",children:o(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},l))})]})});return n?e.jsx(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",children:e.jsx(Vt,{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(Nt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(wt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(fe,{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(fe,{title:"IDE support",icon:e.jsx(Le,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:c(t.ide)}),e.jsx(fe,{title:"Standalone CLI agents",icon:e.jsx(Ut,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:c(t.cli)}),e.jsx(fe,{title:"AI extensions",icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:c(t.ext)}),e.jsx(fe,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:c(t.acp)})]})}class go{constructor(){ue(this,"adapters",new Map);ue(this,"states",new Map);ue(this,"ptyCallbacks",new Set);ue(this,"screenshotCallbacks",new Map);ue(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,o){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){this.ptyCallbacks.forEach(r=>r(s,n))}}const $e=new go;function bo(){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 xs=bo(),ps=3e3,yo=3e4;let Ae=null,jo=0;const Ct=new Map;let Be=null,at=null;function vo(t){return t==="connected"?"connected":t}async function vt(t,s,n){const r=Mr(t,n||{}),o=Ae;if(o&&o.readyState===WebSocket.OPEN){const i=`req_${++jo}_${Date.now()}`;return new Promise((u,l)=>{const x=setTimeout(()=>{Ct.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);Ct.set(i,{resolve:d=>{clearTimeout(x),u(d)},reject:d=>{clearTimeout(x),l(d)}}),o.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 wo{constructor(s){ue(this,"daemonId");ue(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ae==null?void 0:Ae.readyState)===WebSocket.OPEN}get connectionState(){return(Ae==null?void 0:Ae.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return vt(this.daemonId,s,n)}async sendInput(s,n){return vt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Be&&(clearInterval(Be),Be=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await vt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const o=await fetch(`data:image/jpeg;base64,${r.base64}`).then(c=>c.blob());$e.emitScreenshot(this.daemonId,o)}}catch{}};n(),Be=setInterval(n,2e3)}stopScreenshots(s){Be&&(clearInterval(Be),Be=null)}}let ke=null;function No(t){return(!ke||ke.daemonId!==t)&&(ke=new wo(t)),ke}function ko({children:t}){const s=a.useRef(Xt()),n=Xt();s.current=n;const{setUserName:r}=ot(),o=a.useRef(r);o.current=r;const[,c]=a.useState("disconnected"),i=a.useCallback((g,m)=>{c(g),at==null||at(g,m)},[]),u=a.useRef(null),l=a.useRef(),x=a.useRef(ps),d=a.useRef(!0),h=a.useRef(!1);return a.useEffect(()=>{d.current=!0,h.current=!1;function g(){var k,I;if(!d.current||((k=u.current)==null?void 0:k.readyState)===WebSocket.OPEN||((I=u.current)==null?void 0:I.readyState)===WebSocket.CONNECTING)return;i("connecting"),console.log(`[Standalone WS] Connecting to ${xs}...`);let b;try{b=new WebSocket(xs)}catch(p){console.error("[Standalone WS] Failed to create WebSocket:",p),m();return}u.current=b,b.onopen=()=>{if(!d.current){b.close();return}i("connected"),x.current=ps,console.log("[Standalone WS] Connected")},Ae=b,b.onmessage=p=>{var y;try{const v=JSON.parse(p.data);if((v.type==="command_result"||v.type==="error")&&v.requestId){const T=Ct.get(v.requestId);T&&(Ct.delete(v.requestId),v.type==="error"?T.reject(new Error(((y=v.data)==null?void 0:y.message)||"Command failed")):T.resolve(v.data));return}if(v.type==="pty_output"){$e.emitPtyOutput(v.cliId,v.data);return}if(v.type==="status"||v.type==="initial_state"){const T=v.data;if(!T)return;const{injectEntries:f,markLoaded:N}=s.current,w=T.id||"standalone",j=No(w);$e.register(w,j),$e.setState(w,"connected"),i("connected",w),$e.emitStatus(w,T);const A=Ir(T,{daemonId:w});A.length>0&&f(A),N(),T.userName&&o.current&&o.current(T.userName)}}catch(v){console.error("[Standalone WS] Parse error:",v)}},b.onclose=()=>{d.current&&(ke==null||ke.stopScreenshots(),ke&&$e.setState(ke.daemonId,"disconnected"),i("disconnected"),u.current=null,m())},b.onerror=p=>{h.current||!d.current||console.warn("[Standalone WS] Error, will reconnect:",p)}}function m(){if(!d.current)return;clearTimeout(l.current);const b=x.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,yo),g()},b)}return g(),()=>{d.current=!1,h.current=!0,clearTimeout(l.current),u.current&&(u.current.onerror=null,u.current.onclose=null,u.current.close(),u.current=null,Ae=null),ke&&(ke.stopScreenshots(),$e.unregister(ke.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function So({children:t}){const[s,n]=a.useState("disconnected"),[r,o]=a.useState(null);a.useEffect(()=>(at=(i,u)=>{n(i),u&&o(u)},()=>{at=null}),[]);const c=a.useMemo(()=>{const i=s==="connected",u=vo(s),l={};return r&&(l[r]=u),l.standalone=u,{wsStatus:s,isConnected:i,connectionStates:l}},[s,r]);return e.jsx(In,{connectionOverrides:c,children:e.jsx(ko,{children:t})})}const Co=[{id:"dashboard",path:"/dashboard",icon:e.jsx(ks,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ss,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Ht,{}),label:"Settings"}];function Io({children:t}){const s=it(),n=jn(),[r,o]=a.useState(!1),[c,i]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=d=>{s(d),o(!1)},l=()=>{i(d=>{const h=!d;try{localStorage.setItem("sidebar-collapsed",h?"1":"0")}catch{}return h})},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:()=>o(!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:()=>o(!1),onKeyDown:d=>d.key==="Escape"&&o(!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:()=>o(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Co.map(d=>e.jsxs("div",{className:x(d.path),id:`nav-${d.id}`,onClick:()=>u(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(wt,{})}),!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(Cs,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.15"]}),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 Mo=[{icon:e.jsx(Ss,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(qe,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Es,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Le,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ye,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(wt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],To=[{icon:e.jsx(Rs,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(ks,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(_s,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx($n,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Ln,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Is,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Eo=[{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 Ao(){return e.jsxs(Nt,{icon:e.jsx(Cs,{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.15"]}),children:[e.jsx(fe,{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(fe,{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:Mo.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(fe,{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:qs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Xs.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Ys.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(fe,{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:To.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(fe,{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:Eo.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(Vt,{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(Fn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Ro(){const{ides:t}=ot(),s=t.find(h=>h.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Pe(),{userName:o}=ot(),[c,i]=a.useState(o||"");a.useEffect(()=>{o!==void 0&&i(o)},[o]);const u=h=>{const g=h.target.value.trim();s!=null&&s.id&&g!==o&&r(s.id,"set_user_name",{userName:g}).catch(console.error)},[l,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=h=>{x(h);try{localStorage.setItem("adhdev_sound",h?"1":"0")}catch{}};return e.jsxs(Nt,{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(Hr,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(fe,{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.15"]}),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(fe,{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(h=>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 ${h.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:h.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:h.type})]},h.type))})}),e.jsx(fe,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Jr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(fe,{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(ta,{})]}),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(ia,{})]})]})}),e.jsx(fe,{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(Gr,{}),e.jsx(We,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Hn,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:d})]})}),e.jsx(fe,{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(_n,{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:h=>i(h.target.value),onBlur:u,onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()}})]})})})]})}Yr();aa();const Lo=vs({baseUrl:""});function hs(){const{ides:t}=ot(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(gt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(gt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(gt,{to:"/dashboard",replace:!0})}function _o(){return e.jsx(vn,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Tn,{client:Lo,children:e.jsx(So,{children:e.jsx(Rn,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Io,{children:e.jsxs(wn,{children:[e.jsx(Ee,{path:"/dashboard",element:e.jsx(Ya,{})}),e.jsx(Ee,{path:"/ide/:id",element:e.jsx(so,{})}),e.jsx(Ee,{path:"/machine",element:e.jsx(hs,{})}),e.jsx(Ee,{path:"/machines/:id",element:e.jsx(mo,{})}),e.jsx(Ee,{path:"/machines",element:e.jsx(hs,{})}),e.jsx(Ee,{path:"/capabilities",element:e.jsx(fo,{})}),e.jsx(Ee,{path:"/about",element:e.jsx(Ao,{})}),e.jsx(Ee,{path:"/settings",element:e.jsx(Ro,{})}),e.jsx(Ee,{path:"*",element:e.jsx(gt,{to:"/dashboard",replace:!0})})]})})})})})})}yr({connectionManager:$e});Nn(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(_o,{})}));